org-agenda.el 445 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; URL: https://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'cl-lib)
  42. (require 'ol)
  43. (require 'org-fold-core)
  44. (require 'org)
  45. (require 'org-macs)
  46. (require 'org-refile)
  47. (declare-function diary-add-to-list "diary-lib"
  48. (date string specifier &optional marker globcolor literal))
  49. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  50. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  51. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  52. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  53. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  54. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  55. (declare-function calendar-french-date-string "cal-french" (&optional date))
  56. (declare-function calendar-goto-date "cal-move" (date))
  57. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  58. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  59. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  60. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  61. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  62. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  63. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  64. (declare-function calendar-check-holidays "holidays" (date))
  65. (declare-function org-columns-remove-overlays "org-colview" ())
  66. (declare-function org-datetree-find-date-create "org-datetree"
  67. (date &optional keep-restriction))
  68. (declare-function org-columns-quit "org-colview" ())
  69. (declare-function diary-date-display-form "diary-lib" (&optional type))
  70. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  71. (declare-function org-element-property "org-element" (property element))
  72. (declare-function org-element--cache-active-p "org-element"
  73. (&optional called-from-cache-change-func-p))
  74. (declare-function org-habit-insert-consistency-graphs
  75. "org-habit" (&optional line))
  76. (declare-function org-is-habit-p "org-habit" (&optional pom))
  77. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  78. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  79. (declare-function org-agenda-columns "org-colview" ())
  80. (declare-function org-add-archive-files "org-archive" (files))
  81. (declare-function org-capture "org-capture" (&optional goto keys))
  82. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  83. (declare-function org-element-type "org-element" (&optional element))
  84. (defvar calendar-mode-map)
  85. (defvar org-clock-current-task)
  86. (defvar org-current-tag-alist)
  87. (defvar org-mobile-force-id-on-agenda-items)
  88. (defvar org-habit-show-habits)
  89. (defvar org-habit-show-habits-only-for-today)
  90. (defvar org-habit-show-all-today)
  91. (defvar org-habit-scheduled-past-days)
  92. ;; Defined somewhere in this file, but used before definition.
  93. (defvar org-agenda-buffer-name "*Org Agenda*")
  94. (defvar org-agenda-title-append nil)
  95. (defvar org-agenda-overriding-header)
  96. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  97. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  98. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  99. (defvar org-agenda-undo-list nil
  100. "List of undoable operations in the agenda since last refresh.")
  101. (defvar org-agenda-pending-undo-list nil
  102. "In a series of undo commands, this is the list of remaining undo items.")
  103. (defcustom org-agenda-confirm-kill 1
  104. "When set, remote killing from the agenda buffer needs confirmation.
  105. When t, a confirmation is always needed. When a number N, confirmation is
  106. only needed when the text to be killed contains more than N non-white lines."
  107. :group 'org-agenda
  108. :type '(choice
  109. (const :tag "Never" nil)
  110. (const :tag "Always" t)
  111. (integer :tag "When more than N lines")))
  112. (defcustom org-agenda-compact-blocks nil
  113. "Non-nil means make the block agenda more compact.
  114. This is done globally by leaving out lines like the agenda span
  115. name and week number or the separator lines."
  116. :group 'org-agenda
  117. :type 'boolean)
  118. (defcustom org-agenda-block-separator ?=
  119. "The separator between blocks in the agenda.
  120. If this is a string, it will be used as the separator, with a newline added.
  121. If it is a character, it will be repeated to fill the window width.
  122. If nil the separator is disabled. In `org-agenda-custom-commands' this
  123. addresses the separator between the current and the previous block."
  124. :group 'org-agenda
  125. :type '(choice
  126. (const :tag "Disabled" nil)
  127. (character)
  128. (string)))
  129. (defgroup org-agenda-export nil
  130. "Options concerning exporting agenda views in Org mode."
  131. :tag "Org Agenda Export"
  132. :group 'org-agenda)
  133. (defcustom org-agenda-with-colors t
  134. "Non-nil means use colors in agenda views."
  135. :group 'org-agenda-export
  136. :type 'boolean)
  137. (defcustom org-agenda-exporter-settings nil
  138. ;; FIXME: Do we really want to evaluate those settings and thus force
  139. ;; the user to use `quote' all the time?
  140. "Alist of variable/value pairs that should be active during agenda export.
  141. This is a good place to set options for ps-print and for htmlize.
  142. Note that the way this is implemented, the values will be evaluated
  143. before assigned to the variables. So make sure to quote values you do
  144. *not* want evaluated, for example
  145. (setq org-agenda-exporter-settings
  146. \\='((ps-print-color-p \\='black-white)))"
  147. :group 'org-agenda-export
  148. :type '(repeat
  149. (list
  150. (variable)
  151. (sexp :tag "Value"))))
  152. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  153. "Hook run in a temporary buffer before writing the agenda to an export file.
  154. A useful function for this hook is `org-agenda-add-entry-text'."
  155. :group 'org-agenda-export
  156. :type 'hook
  157. :options '(org-agenda-add-entry-text))
  158. (defcustom org-agenda-add-entry-text-maxlines 0
  159. "Maximum number of entry text lines to be added to agenda.
  160. This is only relevant when `org-agenda-add-entry-text' is part of
  161. `org-agenda-before-write-hook', which is the default.
  162. When this is 0, nothing will happen. When it is greater than 0, it
  163. specifies the maximum number of lines that will be added for each entry
  164. that is listed in the agenda view.
  165. Note that this variable is not used during display, only when exporting
  166. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  167. and `org-agenda-entry-text-maxlines'."
  168. :group 'org-agenda
  169. :type 'integer)
  170. (defcustom org-agenda-add-entry-text-descriptive-links t
  171. "Non-nil means export org-links as descriptive links in agenda added text.
  172. This variable applies to the text added to the agenda when
  173. `org-agenda-add-entry-text-maxlines' is larger than 0.
  174. When this variable is nil, the URL will (also) be shown."
  175. :group 'org-agenda
  176. :type 'boolean)
  177. (defcustom org-agenda-export-html-style nil
  178. "The style specification for exported HTML Agenda files.
  179. If this variable contains a string, it will replace the default <style>
  180. section as produced by `htmlize'.
  181. Since there are different ways of setting style information, this variable
  182. needs to contain the full HTML structure to provide a style, including the
  183. surrounding HTML tags. The style specifications should include definitions
  184. the fonts used by the agenda, here is an example:
  185. <style type=\"text/css\">
  186. p { font-weight: normal; color: gray; }
  187. .org-agenda-structure {
  188. font-size: 110%;
  189. color: #003399;
  190. font-weight: 600;
  191. }
  192. .org-todo {
  193. color: #cc6666;
  194. font-weight: bold;
  195. }
  196. .org-agenda-done {
  197. color: #339933;
  198. }
  199. .org-done {
  200. color: #339933;
  201. }
  202. .title { text-align: center; }
  203. .todo, .deadline { color: red; }
  204. .done { color: green; }
  205. </style>
  206. or, if you want to keep the style in a file,
  207. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  208. As the value of this option simply gets inserted into the HTML <head> header,
  209. you can \"misuse\" it to also add other text to the header."
  210. :group 'org-agenda-export
  211. :group 'org-export-html
  212. :type '(choice
  213. (const nil)
  214. (string)))
  215. (defcustom org-agenda-persistent-filter nil
  216. "When set, keep filters from one agenda view to the next."
  217. :group 'org-agenda
  218. :type 'boolean)
  219. (defgroup org-agenda-custom-commands nil
  220. "Options concerning agenda views in Org mode."
  221. :tag "Org Agenda Custom Commands"
  222. :group 'org-agenda)
  223. (defconst org-sorting-choice
  224. '(choice
  225. (const time-up) (const time-down)
  226. (const timestamp-up) (const timestamp-down)
  227. (const scheduled-up) (const scheduled-down)
  228. (const deadline-up) (const deadline-down)
  229. (const ts-up) (const ts-down)
  230. (const tsia-up) (const tsia-down)
  231. (const category-keep) (const category-up) (const category-down)
  232. (const tag-down) (const tag-up)
  233. (const priority-up) (const priority-down)
  234. (const todo-state-up) (const todo-state-down)
  235. (const effort-up) (const effort-down)
  236. (const habit-up) (const habit-down)
  237. (const alpha-up) (const alpha-down)
  238. (const user-defined-up) (const user-defined-down))
  239. "Sorting choices.")
  240. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  241. ;; the new variable `org-agenda-tag-filter-preset'.
  242. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  243. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  244. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  245. "List of types searched for when creating the daily/weekly agenda.
  246. This variable is a list of symbols that controls the types of
  247. items that appear in the daily/weekly agenda. Allowed symbols in this
  248. list are
  249. :timestamp List items containing a date stamp or date range matching
  250. the selected date. This includes sexp entries in angular
  251. brackets.
  252. :sexp List entries resulting from plain diary-like sexps.
  253. :deadline List deadline due on that date. When the date is today,
  254. also list any deadlines past due, or due within
  255. `org-deadline-warning-days'.
  256. :deadline* Same as above, but only include the deadline if it has an
  257. hour specification as [h]h:mm.
  258. :scheduled List all items which are scheduled for the given date.
  259. The diary for *today* also contains items which were
  260. scheduled earlier and are not yet marked DONE.
  261. :scheduled* Same as above, but only include the scheduled item if it
  262. has an hour specification as [h]h:mm.
  263. By default, all four non-starred types are turned on.
  264. When :scheduled* or :deadline* are included, :schedule or :deadline
  265. will be ignored.
  266. Never set this variable globally using `setq', because then it
  267. will apply to all future agenda commands. Instead, bind it with
  268. `let' to scope it dynamically into the agenda-constructing
  269. command. A good way to set it is through options in
  270. `org-agenda-custom-commands'. For a more flexible (though
  271. somewhat less efficient) way of determining what is included in
  272. the daily/weekly agenda, see `org-agenda-skip-function'.")
  273. (defconst org-agenda-custom-commands-local-options
  274. `(repeat :tag "Local settings for this command. Remember to quote values"
  275. (choice :tag "Setting"
  276. (list :tag "Heading for this block"
  277. (const org-agenda-overriding-header)
  278. (string :tag "Headline"))
  279. (list :tag "Files to be searched"
  280. (const org-agenda-files)
  281. (list
  282. (const :format "" quote)
  283. (repeat (file))))
  284. (list :tag "Sorting strategy"
  285. (const org-agenda-sorting-strategy)
  286. (list
  287. (const :format "" quote)
  288. (repeat
  289. ,org-sorting-choice)))
  290. (list :tag "Prefix format"
  291. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  292. (string))
  293. (list :tag "Number of days in agenda"
  294. (const org-agenda-span)
  295. (list
  296. (const :format "" quote)
  297. (choice (const :tag "Day" day)
  298. (const :tag "Week" week)
  299. (const :tag "Fortnight" fortnight)
  300. (const :tag "Month" month)
  301. (const :tag "Year" year)
  302. (integer :tag "Custom"))))
  303. (list :tag "Fixed starting date"
  304. (const org-agenda-start-day)
  305. (string :value "2007-11-01"))
  306. (list :tag "Start on day of week"
  307. (const org-agenda-start-on-weekday)
  308. (choice :value 1
  309. (const :tag "Today" nil)
  310. (integer :tag "Weekday No.")))
  311. (list :tag "Include data from diary"
  312. (const org-agenda-include-diary)
  313. (boolean))
  314. (list :tag "Deadline Warning days"
  315. (const org-deadline-warning-days)
  316. (integer :value 1))
  317. (list :tag "Category filter preset"
  318. (const org-agenda-category-filter-preset)
  319. (list
  320. (const :format "" quote)
  321. (repeat
  322. (string :tag "+category or -category"))))
  323. (list :tag "Tags filter preset"
  324. (const org-agenda-tag-filter-preset)
  325. (list
  326. (const :format "" quote)
  327. (repeat
  328. (string :tag "+tag or -tag"))))
  329. (list :tag "Effort filter preset"
  330. (const org-agenda-effort-filter-preset)
  331. (list
  332. (const :format "" quote)
  333. (repeat
  334. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  335. (list :tag "Regexp filter preset"
  336. (const org-agenda-regexp-filter-preset)
  337. (list
  338. (const :format "" quote)
  339. (repeat
  340. (string :tag "+regexp or -regexp"))))
  341. (list :tag "Set daily/weekly entry types"
  342. (const org-agenda-entry-types)
  343. (list
  344. (const :format "" quote)
  345. (set :greedy t :value ,org-agenda-entry-types
  346. (const :deadline)
  347. (const :scheduled)
  348. (const :deadline*)
  349. (const :scheduled*)
  350. (const :timestamp)
  351. (const :sexp))))
  352. (list :tag "Columns format"
  353. (const org-overriding-columns-format)
  354. (string :tag "Format"))
  355. (list :tag "Standard skipping condition"
  356. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  357. (const org-agenda-skip-function)
  358. (list
  359. (const :format "" quote)
  360. (list
  361. (choice
  362. :tag "Skipping range"
  363. (const :tag "Skip entry" org-agenda-skip-entry-if)
  364. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  365. (repeat :inline t :tag "Conditions for skipping"
  366. (choice
  367. :tag "Condition type"
  368. (list :tag "Regexp matches" :inline t
  369. (const :format "" regexp)
  370. (regexp))
  371. (list :tag "Regexp does not match" :inline t
  372. (const :format "" notregexp)
  373. (regexp))
  374. (list :tag "TODO state is" :inline t
  375. (const todo)
  376. (choice
  377. (const :tag "Any not-done state" todo)
  378. (const :tag "Any done state" done)
  379. (const :tag "Any state" any)
  380. (list :tag "Keyword list"
  381. (const :format "" quote)
  382. (repeat (string :tag "Keyword")))))
  383. (list :tag "TODO state is not" :inline t
  384. (const nottodo)
  385. (choice
  386. (const :tag "Any not-done state" todo)
  387. (const :tag "Any done state" done)
  388. (const :tag "Any state" any)
  389. (list :tag "Keyword list"
  390. (const :format "" quote)
  391. (repeat (string :tag "Keyword")))))
  392. (const :tag "scheduled" scheduled)
  393. (const :tag "not scheduled" notscheduled)
  394. (const :tag "deadline" deadline)
  395. (const :tag "no deadline" notdeadline)
  396. (const :tag "timestamp" timestamp)
  397. (const :tag "no timestamp" nottimestamp))))))
  398. (list :tag "Non-standard skipping condition"
  399. :value (org-agenda-skip-function)
  400. (const org-agenda-skip-function)
  401. (sexp :tag "Function or form (quoted!)"))
  402. (list :tag "Any variable"
  403. (variable :tag "Variable")
  404. (sexp :tag "Value (sexp)"))))
  405. "Selection of examples for agenda command settings.
  406. This will be spliced into the custom type of
  407. `org-agenda-custom-commands'.")
  408. (defcustom org-agenda-custom-commands
  409. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  410. "Custom commands for the agenda.
  411. \\<org-mode-map>
  412. These commands will be offered on the splash screen displayed by the
  413. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  414. (key desc type match settings files)
  415. key The key (one or more characters as a string) to be associated
  416. with the command.
  417. desc A description of the command. When omitted or nil, a default
  418. description is built using MATCH.
  419. type The command type, any of the following symbols:
  420. agenda The daily/weekly agenda.
  421. agenda* Appointments for current week/day.
  422. todo Entries with a specific TODO keyword, in all agenda files.
  423. search Entries containing search words entry or headline.
  424. tags Tags/Property/TODO match in all agenda files.
  425. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  426. todo-tree Sparse tree of specific TODO keyword in *current* file.
  427. tags-tree Sparse tree with all tags matches in *current* file.
  428. occur-tree Occur sparse tree for *current* file.
  429. alltodo The global TODO list.
  430. stuck Stuck projects.
  431. ... A user-defined function.
  432. match What to search for:
  433. - a single keyword for TODO keyword searches
  434. - a tags/property/todo match expression for searches
  435. - a word search expression for text searches.
  436. - a regular expression for occur searches
  437. For all other commands, this should be the empty string.
  438. settings A list of option settings, similar to that in a let form, so like
  439. this: ((opt1 val1) (opt2 val2) ...). The values will be
  440. evaluated at the moment of execution, so quote them when needed.
  441. files A list of files to write the produced agenda buffer to with
  442. the command `org-store-agenda-views'.
  443. If a file name ends in \".html\", an HTML version of the buffer
  444. is written out. If it ends in \".ps\", a PostScript version is
  445. produced. Otherwise, only the plain text is written to the file.
  446. You can also define a set of commands, to create a composite agenda buffer.
  447. In this case, an entry looks like this:
  448. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  449. where
  450. desc A description string to be displayed in the dispatcher menu.
  451. cmd An agenda command, similar to the above. However, tree commands
  452. are not allowed. Valid commands for a set are:
  453. (agenda \"\" settings)
  454. (agenda* \"\" settings)
  455. (alltodo \"\" settings)
  456. (stuck \"\" settings)
  457. (todo \"match\" settings files)
  458. (search \"match\" settings files)
  459. (tags \"match\" settings files)
  460. (tags-todo \"match\" settings files)
  461. Each command can carry a list of options, and another set of options can be
  462. given for the whole set of commands. Individual command options take
  463. precedence over the general options.
  464. When using several characters as key to a command, the first characters
  465. are prefix commands. For the dispatcher to display useful information, you
  466. should provide a description for the prefix, like
  467. (setq org-agenda-custom-commands
  468. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  469. (\"hl\" tags \"+HOME+Lisa\")
  470. (\"hp\" tags \"+HOME+Peter\")
  471. (\"hk\" tags \"+HOME+Kim\")))
  472. See also Info node `(org) Custom Agenda Views'."
  473. :group 'org-agenda-custom-commands
  474. :type `(repeat
  475. (choice :value ("x" "Describe command here" tags "" nil)
  476. (list :tag "Single command"
  477. (string :tag "Access Key(s) ")
  478. (option (string :tag "Description"))
  479. (choice
  480. (const :tag "Agenda" agenda)
  481. (const :tag "TODO list" alltodo)
  482. (const :tag "Search words" search)
  483. (const :tag "Stuck projects" stuck)
  484. (const :tag "Tags/Property match (all agenda files)" tags)
  485. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  486. (const :tag "TODO keyword search (all agenda files)" todo)
  487. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  488. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  489. (const :tag "Occur tree (current buffer)" occur-tree)
  490. (sexp :tag "Other, user-defined function"))
  491. (string :tag "Match (only for some commands)")
  492. ,org-agenda-custom-commands-local-options
  493. (option (repeat :tag "Export" (file :tag "Export to"))))
  494. (list :tag "Command series, all agenda files"
  495. (string :tag "Access Key(s)")
  496. (string :tag "Description ")
  497. (repeat :tag "Component"
  498. (choice
  499. (list :tag "Agenda"
  500. (const :format "" agenda)
  501. (const :tag "" :format "" "")
  502. ,org-agenda-custom-commands-local-options)
  503. (list :tag "TODO list (all keywords)"
  504. (const :format "" alltodo)
  505. (const :tag "" :format "" "")
  506. ,org-agenda-custom-commands-local-options)
  507. (list :tag "Search words"
  508. (const :format "" search)
  509. (string :tag "Match")
  510. ,org-agenda-custom-commands-local-options)
  511. (list :tag "Stuck projects"
  512. (const :format "" stuck)
  513. (const :tag "" :format "" "")
  514. ,org-agenda-custom-commands-local-options)
  515. (list :tag "Tags/Property match (all agenda files)"
  516. (const :format "" tags)
  517. (string :tag "Match")
  518. ,org-agenda-custom-commands-local-options)
  519. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  520. (const :format "" tags-todo)
  521. (string :tag "Match")
  522. ,org-agenda-custom-commands-local-options)
  523. (list :tag "TODO keyword search"
  524. (const :format "" todo)
  525. (string :tag "Match")
  526. ,org-agenda-custom-commands-local-options)
  527. (list :tag "Other, user-defined function"
  528. (symbol :tag "function")
  529. (string :tag "Match")
  530. ,org-agenda-custom-commands-local-options)))
  531. (repeat :tag "Settings for entire command set"
  532. (list (variable :tag "Any variable")
  533. (sexp :tag "Value")))
  534. (option (repeat :tag "Export" (file :tag "Export to"))))
  535. (cons :tag "Prefix key documentation"
  536. (string :tag "Access Key(s)")
  537. (string :tag "Description ")))))
  538. (defcustom org-agenda-query-register ?o
  539. "The register holding the current query string.
  540. The purpose of this is that if you construct a query string interactively,
  541. you can then use it to define a custom command."
  542. :group 'org-agenda-custom-commands
  543. :type 'character)
  544. (defcustom org-stuck-projects
  545. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  546. "How to identify stuck projects.
  547. This is a list of four items:
  548. 1. A tags/todo/property matcher string that is used to identify a project.
  549. See the manual for a description of tag and property searches.
  550. The entire tree below a headline matched by this is considered one project.
  551. 2. A list of TODO keywords identifying non-stuck projects.
  552. If the project subtree contains any headline with one of these todo
  553. keywords, the project is considered to be not stuck. If you specify
  554. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  555. 3. A list of tags identifying non-stuck projects.
  556. If the project subtree contains any headline with one of these tags,
  557. the project is considered to be not stuck. If you specify \"*\" as
  558. a tag, any tag will mark the project unstuck. Note that this is about
  559. the explicit presence of a tag somewhere in the subtree, inherited
  560. tags do not count here. If inherited tags make a project not stuck,
  561. use \"-TAG\" in the tags part of the matcher under (1.) above.
  562. 4. An arbitrary regular expression matching non-stuck projects.
  563. If the project turns out to be not stuck, search continues also in the
  564. subtree to see if any of the subtasks have project status.
  565. See also the variable `org-tags-match-list-sublevels' which applies
  566. to projects matched by this search as well.
  567. After defining this variable, you may use `org-agenda-list-stuck-projects'
  568. \(bound to `\\[org-agenda] #') to produce the list."
  569. :group 'org-agenda-custom-commands
  570. :type '(list
  571. (string :tag "Tags/TODO match to identify a project")
  572. (repeat :tag "Projects are *not* stuck if they have an entry with \
  573. TODO keyword any of" (string))
  574. (repeat :tag "Projects are *not* stuck if they have an entry with \
  575. TAG being any of" (string))
  576. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  577. the subtree")))
  578. (defgroup org-agenda-skip nil
  579. "Options concerning skipping parts of agenda files."
  580. :tag "Org Agenda Skip"
  581. :group 'org-agenda)
  582. (defcustom org-agenda-skip-function-global nil
  583. "Function to be called at each match during agenda construction.
  584. If this function returns nil, the current match should not be skipped.
  585. If the function decided to skip an agenda match, is must return the
  586. buffer position from which the search should be continued.
  587. This may also be a Lisp form, which will be evaluated.
  588. This variable will be applied to every agenda match, including
  589. tags/property searches and TODO lists. So try to make the test function
  590. do its checking as efficiently as possible. To implement a skipping
  591. condition just for specific agenda commands, use the variable
  592. `org-agenda-skip-function' which can be set in the options section
  593. of custom agenda commands."
  594. :group 'org-agenda-skip
  595. :type 'sexp)
  596. (defgroup org-agenda-daily/weekly nil
  597. "Options concerning the daily/weekly agenda."
  598. :tag "Org Agenda Daily/Weekly"
  599. :group 'org-agenda)
  600. (defgroup org-agenda-todo-list nil
  601. "Options concerning the global todo list agenda view."
  602. :tag "Org Agenda Todo List"
  603. :group 'org-agenda)
  604. (defgroup org-agenda-match-view nil
  605. "Options concerning the general tags/property/todo match agenda view."
  606. :tag "Org Agenda Match View"
  607. :group 'org-agenda)
  608. (defgroup org-agenda-search-view nil
  609. "Options concerning the search agenda view."
  610. :tag "Org Agenda Search View"
  611. :group 'org-agenda)
  612. (defvar org-agenda-archives-mode nil
  613. "Non-nil means the agenda will include archived items.
  614. If this is the symbol `trees', trees in the selected agenda scope
  615. that are marked with the ARCHIVE tag will be included anyway. When this is
  616. t, also all archive files associated with the current selection of agenda
  617. files will be included.")
  618. (defcustom org-agenda-restriction-lock-highlight-subtree t
  619. "Non-nil means highlight the whole subtree when restriction is active.
  620. Otherwise only highlight the headline. Highlighting the whole subtree is
  621. useful to ensure no edits happen beyond the restricted region."
  622. :group 'org-agenda
  623. :type 'boolean)
  624. (defcustom org-agenda-skip-comment-trees t
  625. "Non-nil means skip trees that start with the COMMENT keyword.
  626. When nil, these trees are also scanned by agenda commands."
  627. :group 'org-agenda-skip
  628. :type 'boolean)
  629. (defcustom org-agenda-todo-list-sublevels t
  630. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  631. When nil, the sublevels of a TODO entry are not checked, resulting in
  632. potentially much shorter TODO lists."
  633. :group 'org-agenda-skip
  634. :group 'org-agenda-todo-list
  635. :type 'boolean)
  636. (defcustom org-agenda-todo-ignore-with-date nil
  637. "Non-nil means don't show entries with a date in the global todo list.
  638. You can use this if you prefer to mark mere appointments with a TODO keyword,
  639. but don't want them to show up in the TODO list.
  640. When this is set, it also covers deadlines and scheduled items, the settings
  641. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  642. will be ignored.
  643. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  644. :group 'org-agenda-skip
  645. :group 'org-agenda-todo-list
  646. :type 'boolean)
  647. (defcustom org-agenda-todo-ignore-timestamp nil
  648. "Non-nil means don't show entries with a timestamp.
  649. This applies when creating the global todo list.
  650. Valid values are:
  651. past Don't show entries for today or in the past.
  652. future Don't show entries with a timestamp in the future.
  653. The idea behind this is that if it has a future
  654. timestamp, you don't want to think about it until the
  655. date.
  656. all Don't show any entries with a timestamp in the global todo list.
  657. The idea behind this is that by setting a timestamp, you
  658. have already \"taken care\" of this item.
  659. This variable can also have an integer as a value. If positive (N),
  660. todos with a timestamp N or more days in the future will be ignored. If
  661. negative (-N), todos with a timestamp N or more days in the past will be
  662. ignored. If 0, todos with a timestamp either today or in the future will
  663. be ignored. For example, a value of -1 will exclude todos with a
  664. timestamp in the past (yesterday or earlier), while a value of 7 will
  665. exclude todos with a timestamp a week or more in the future.
  666. See also `org-agenda-todo-ignore-with-date'.
  667. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  668. to make his option also apply to the tags-todo list."
  669. :group 'org-agenda-skip
  670. :group 'org-agenda-todo-list
  671. :version "24.1"
  672. :type '(choice
  673. (const :tag "Ignore future timestamp todos" future)
  674. (const :tag "Ignore past or present timestamp todos" past)
  675. (const :tag "Ignore all timestamp todos" all)
  676. (const :tag "Show timestamp todos" nil)
  677. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  678. (defcustom org-agenda-todo-ignore-scheduled nil
  679. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  680. This applies when creating the global todo list.
  681. Valid values are:
  682. past Don't show entries scheduled today or in the past.
  683. future Don't show entries scheduled in the future.
  684. The idea behind this is that by scheduling it, you don't want to
  685. think about it until the scheduled date.
  686. all Don't show any scheduled entries in the global todo list.
  687. The idea behind this is that by scheduling it, you have already
  688. \"taken care\" of this item.
  689. t Same as `all', for backward compatibility.
  690. This variable can also have an integer as a value. See
  691. `org-agenda-todo-ignore-timestamp' for more details.
  692. See also `org-agenda-todo-ignore-with-date'.
  693. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  694. to make his option also apply to the tags-todo list."
  695. :group 'org-agenda-skip
  696. :group 'org-agenda-todo-list
  697. :type '(choice
  698. (const :tag "Ignore future-scheduled todos" future)
  699. (const :tag "Ignore past- or present-scheduled todos" past)
  700. (const :tag "Ignore all scheduled todos" all)
  701. (const :tag "Ignore all scheduled todos (compatibility)" t)
  702. (const :tag "Show scheduled todos" nil)
  703. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  704. (defcustom org-agenda-todo-ignore-deadlines nil
  705. "Non-nil means ignore some deadline TODO items when making TODO list.
  706. There are different motivations for using different values, please think
  707. carefully when configuring this variable.
  708. This applies when creating the global TODO list.
  709. Valid values are:
  710. near Don't show near deadline entries. A deadline is near when it is
  711. closer than `org-deadline-warning-days' days. The idea behind this
  712. is that such items will appear in the agenda anyway.
  713. far Don't show TODO entries where a deadline has been defined, but
  714. is not going to happen anytime soon. This is useful if you want to use
  715. the TODO list to figure out what to do now.
  716. past Don't show entries with a deadline timestamp for today or in the past.
  717. future Don't show entries with a deadline timestamp in the future, not even
  718. when they become `near' ones. Use it with caution.
  719. all Ignore all TODO entries that do have a deadline.
  720. t Same as `near', for backward compatibility.
  721. This variable can also have an integer as a value. See
  722. `org-agenda-todo-ignore-timestamp' for more details.
  723. See also `org-agenda-todo-ignore-with-date'.
  724. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  725. to make his option also apply to the tags-todo list."
  726. :group 'org-agenda-skip
  727. :group 'org-agenda-todo-list
  728. :type '(choice
  729. (const :tag "Ignore near deadlines" near)
  730. (const :tag "Ignore near deadlines (compatibility)" t)
  731. (const :tag "Ignore far deadlines" far)
  732. (const :tag "Ignore all TODOs with a deadlines" all)
  733. (const :tag "Show all TODOs, even if they have a deadline" nil)
  734. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  735. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  736. "Time unit to use when possibly ignoring an agenda item.
  737. See the docstring of various `org-agenda-todo-ignore-*' options.
  738. The default is to compare time stamps using days. An item is thus
  739. considered to be in the future if it is at least one day after today.
  740. Non-nil means to compare time stamps using seconds. An item is then
  741. considered future if it has a time value later than current time."
  742. :group 'org-agenda-skip
  743. :group 'org-agenda-todo-list
  744. :version "24.4"
  745. :package-version '(Org . "8.0")
  746. :type '(choice
  747. (const :tag "Compare time with days" nil)
  748. (const :tag "Compare time with seconds" t)))
  749. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  750. "Non-nil means honor todo-list ignores options also in tags-todo search.
  751. The variables
  752. `org-agenda-todo-ignore-with-date',
  753. `org-agenda-todo-ignore-timestamp',
  754. `org-agenda-todo-ignore-scheduled',
  755. `org-agenda-todo-ignore-deadlines'
  756. make the global TODO list skip entries that have time stamps of certain
  757. kinds. If this option is set, the same options will also apply for the
  758. tags-todo search, which is the general tags/property matcher
  759. restricted to unfinished TODO entries only."
  760. :group 'org-agenda-skip
  761. :group 'org-agenda-todo-list
  762. :group 'org-agenda-match-view
  763. :type 'boolean)
  764. (defcustom org-agenda-skip-scheduled-if-done nil
  765. "Non-nil means don't show scheduled items in agenda when they are done.
  766. This is relevant for the daily/weekly agenda, not for the TODO list. It
  767. applies only to the actual date of the scheduling. Warnings about an item
  768. with a past scheduling dates are always turned off when the item is DONE."
  769. :group 'org-agenda-skip
  770. :group 'org-agenda-daily/weekly
  771. :type 'boolean)
  772. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  773. "Non-nil means skip scheduling line if same entry shows because of deadline.
  774. In the agenda of today, an entry can show up multiple times
  775. because it is both scheduled and has a nearby deadline, and maybe
  776. a plain time stamp as well.
  777. When this variable is nil, the entry will be shown several times.
  778. When set to t, then only the deadline is shown and the fact that
  779. the entry is scheduled today or was scheduled previously is not
  780. shown.
  781. When set to the symbol `not-today', skip scheduled previously,
  782. but not scheduled today.
  783. When set to the symbol `repeated-after-deadline', skip scheduled
  784. items if they are repeated beyond the current deadline."
  785. :group 'org-agenda-skip
  786. :group 'org-agenda-daily/weekly
  787. :type '(choice
  788. (const :tag "Never" nil)
  789. (const :tag "Always" t)
  790. (const :tag "Not when scheduled today" not-today)
  791. (const :tag "When repeated past deadline" repeated-after-deadline)))
  792. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  793. "Non-nil means skip timestamp line if same entry shows because of deadline.
  794. In the agenda of today, an entry can show up multiple times
  795. because it has both a plain timestamp and has a nearby deadline.
  796. When this variable is t, then only the deadline is shown and the
  797. fact that the entry has a timestamp for or including today is not
  798. shown. When this variable is nil, the entry will be shown
  799. several times."
  800. :group 'org-agenda-skip
  801. :group 'org-agenda-daily/weekly
  802. :version "24.1"
  803. :type '(choice
  804. (const :tag "Never" nil)
  805. (const :tag "Always" t)))
  806. (defcustom org-agenda-skip-deadline-if-done nil
  807. "Non-nil means don't show deadlines when the corresponding item is done.
  808. When nil, the deadline is still shown and should give you a happy feeling.
  809. This is relevant for the daily/weekly agenda. It applies only to the
  810. actual date of the deadline. Warnings about approaching and past-due
  811. deadlines are always turned off when the item is DONE."
  812. :group 'org-agenda-skip
  813. :group 'org-agenda-daily/weekly
  814. :type 'boolean)
  815. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  816. "Non-nil means skip deadline prewarning when entry is also scheduled.
  817. This will apply on all days where a prewarning for the deadline would
  818. be shown, but not at the day when the entry is actually due. On that day,
  819. the deadline will be shown anyway.
  820. This variable may be set to nil, t, the symbol `pre-scheduled',
  821. or a number which will then give the number of days before the actual
  822. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  823. eliminates the deadline prewarning only prior to the scheduled date.
  824. This can be used in a workflow where the first showing of the deadline will
  825. trigger you to schedule it, and then you don't want to be reminded of it
  826. because you will take care of it on the day when scheduled."
  827. :group 'org-agenda-skip
  828. :group 'org-agenda-daily/weekly
  829. :version "24.1"
  830. :type '(choice
  831. (const :tag "Always show prewarning" nil)
  832. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  833. (const :tag "Remove prewarning if entry is scheduled" t)
  834. (integer :tag "Restart prewarning N days before deadline")))
  835. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  836. "Non-nil means skip scheduled delay when entry also has a deadline.
  837. This variable may be set to nil, t, the symbol `post-deadline',
  838. or a number which will then give the number of days after the actual
  839. scheduled date when the delay should expire. The symbol `post-deadline'
  840. eliminates the schedule delay when the date is posterior to the deadline."
  841. :group 'org-agenda-skip
  842. :group 'org-agenda-daily/weekly
  843. :version "24.4"
  844. :package-version '(Org . "8.0")
  845. :type '(choice
  846. (const :tag "Always honor delay" nil)
  847. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  848. (const :tag "Ignore delay if entry has a deadline" t)
  849. (integer :tag "Honor delay up until N days after the scheduled date")))
  850. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  851. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  852. When non-nil, after the search for timestamps has matched once in an
  853. entry, the rest of the entry will not be searched."
  854. :group 'org-agenda-skip
  855. :type 'boolean)
  856. (defcustom org-agenda-skip-timestamp-if-done nil
  857. "Non-nil means don't select item by timestamp or -range if it is DONE."
  858. :group 'org-agenda-skip
  859. :group 'org-agenda-daily/weekly
  860. :type 'boolean)
  861. (defcustom org-agenda-dim-blocked-tasks t
  862. "Non-nil means dim blocked tasks in the agenda display.
  863. This causes some overhead during agenda construction, but if you
  864. have turned on `org-enforce-todo-dependencies',
  865. `org-enforce-todo-checkbox-dependencies', or any other blocking
  866. mechanism, this will create useful feedback in the agenda.
  867. Instead of t, this variable can also have the value `invisible'.
  868. Then blocked tasks will be invisible and only become visible when
  869. they become unblocked. An exemption to this behavior is when a task is
  870. blocked because of unchecked checkboxes below it. Since checkboxes do
  871. not show up in the agenda views, making this task invisible you remove any
  872. trace from agenda views that there is something to do. Therefore, a task
  873. that is blocked because of checkboxes will never be made invisible, it
  874. will only be dimmed."
  875. :group 'org-agenda-daily/weekly
  876. :group 'org-agenda-todo-list
  877. :version "24.3"
  878. :type '(choice
  879. (const :tag "Do not dim" nil)
  880. (const :tag "Dim to a gray face" t)
  881. (const :tag "Make invisible" invisible)))
  882. (defgroup org-agenda-startup nil
  883. "Options concerning initial settings in the Agenda in Org Mode."
  884. :tag "Org Agenda Startup"
  885. :group 'org-agenda)
  886. (defcustom org-agenda-menu-show-matcher t
  887. "Non-nil means show the match string in the agenda dispatcher menu.
  888. When nil, the matcher string is not shown, but is put into the help-echo
  889. property so than moving the mouse over the command shows it.
  890. Setting it to nil is good if matcher strings are very long and/or if
  891. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  892. :group 'org-agenda
  893. :version "24.1"
  894. :type 'boolean)
  895. (defcustom org-agenda-menu-two-columns nil
  896. "Non-nil means, use two columns to show custom commands in the dispatcher.
  897. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  898. to nil."
  899. :group 'org-agenda
  900. :version "24.1"
  901. :type 'boolean)
  902. (defcustom org-agenda-finalize-hook nil
  903. "Hook run just before displaying an agenda buffer.
  904. The buffer is still writable when the hook is called.
  905. You can modify some of the buffer substrings but you should be
  906. extra careful not to modify the text properties of the agenda
  907. headlines as the agenda display heavily relies on them."
  908. :group 'org-agenda-startup
  909. :type 'hook)
  910. (defcustom org-agenda-filter-hook nil
  911. "Hook run just after filtering with `org-agenda-filter'."
  912. :group 'org-agenda-startup
  913. :package-version '(Org . "9.4")
  914. :type 'hook)
  915. (defcustom org-agenda-mouse-1-follows-link nil
  916. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  917. A longer mouse click will still set point. Needs to be set
  918. before org.el is loaded."
  919. :group 'org-agenda-startup
  920. :type 'boolean)
  921. (defcustom org-agenda-start-with-follow-mode nil
  922. "The initial value of follow mode in a newly created agenda window."
  923. :group 'org-agenda-startup
  924. :type 'boolean)
  925. (defcustom org-agenda-follow-indirect nil
  926. "Non-nil means `org-agenda-follow-mode' displays only the
  927. current item's tree, in an indirect buffer."
  928. :group 'org-agenda
  929. :version "24.1"
  930. :type 'boolean)
  931. (defcustom org-agenda-show-outline-path t
  932. "Non-nil means show outline path in echo area after line motion."
  933. :group 'org-agenda-startup
  934. :type 'boolean)
  935. (defcustom org-agenda-start-with-entry-text-mode nil
  936. "The initial value of entry-text-mode in a newly created agenda window."
  937. :group 'org-agenda-startup
  938. :type 'boolean)
  939. (defcustom org-agenda-entry-text-maxlines 5
  940. "Number of text lines to be added when `E' is pressed in the agenda.
  941. Note that this variable only used during agenda display. To add entry text
  942. when exporting the agenda, configure the variable
  943. `org-agenda-add-entry-text-maxlines'."
  944. :group 'org-agenda
  945. :type 'integer)
  946. (defcustom org-agenda-entry-text-exclude-regexps nil
  947. "List of regular expressions to clean up entry text.
  948. The complete matches of all regular expressions in this list will be
  949. removed from entry text before it is shown in the agenda."
  950. :group 'org-agenda
  951. :type '(repeat (regexp)))
  952. (defcustom org-agenda-entry-text-leaders " > "
  953. "Text prepended to the entry text in agenda buffers."
  954. :version "24.4"
  955. :package-version '(Org . "8.0")
  956. :group 'org-agenda
  957. :type 'string)
  958. (defvar org-agenda-entry-text-cleanup-hook nil
  959. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  960. This cleanup is done in a temporary buffer, so the function may inspect and
  961. change the entire buffer.
  962. Some default stuff like drawers and scheduling/deadline dates will already
  963. have been removed when this is called, as will any matches for regular
  964. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  965. (defvar org-agenda-include-inactive-timestamps nil
  966. "Non-nil means include inactive time stamps in agenda.
  967. Dynamically scoped.")
  968. (defgroup org-agenda-windows nil
  969. "Options concerning the windows used by the Agenda in Org Mode."
  970. :tag "Org Agenda Windows"
  971. :group 'org-agenda)
  972. (defcustom org-agenda-window-setup 'reorganize-frame
  973. "How the agenda buffer should be displayed.
  974. Possible values for this option are:
  975. current-window Show agenda in the current window, keeping all other windows.
  976. other-window Use `switch-to-buffer-other-window' to display agenda.
  977. only-window Show agenda, deleting all other windows.
  978. reorganize-frame Show only two windows on the current frame, the current
  979. window and the agenda.
  980. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  981. Also, when exiting the agenda, kill that frame.
  982. other-tab Use `switch-to-buffer-other-tab' to display the
  983. agenda, making use of the `tab-bar-mode' introduced
  984. in Emacs version 27.1. Also, kill that tab when
  985. exiting the agenda view.
  986. See also the variable `org-agenda-restore-windows-after-quit'."
  987. :group 'org-agenda-windows
  988. :type '(choice
  989. (const current-window)
  990. (const other-frame)
  991. (const other-tab)
  992. (const other-window)
  993. (const only-window)
  994. (const reorganize-frame))
  995. :package-version '(Org . "9.4"))
  996. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  997. "The min and max height of the agenda window as a fraction of frame height.
  998. The value of the variable is a cons cell with two numbers between 0 and 1.
  999. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  1000. :group 'org-agenda-windows
  1001. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  1002. (defcustom org-agenda-restore-windows-after-quit nil
  1003. "Non-nil means restore window configuration upon exiting agenda.
  1004. Before the window configuration is changed for displaying the
  1005. agenda, the current status is recorded. When the agenda is
  1006. exited with `q' or `x' and this option is set, the old state is
  1007. restored. If `org-agenda-window-setup' is `other-frame' or
  1008. `other-tab', the value of this option will be ignored."
  1009. :group 'org-agenda-windows
  1010. :type 'boolean)
  1011. (defcustom org-agenda-span 'week
  1012. "Number of days to include in overview display.
  1013. Can be day, week, month, year, or any number of days.
  1014. Custom commands can set this variable in the options section."
  1015. :group 'org-agenda-daily/weekly
  1016. :type '(choice (const :tag "Day" day)
  1017. (const :tag "Week" week)
  1018. (const :tag "Fortnight" fortnight)
  1019. (const :tag "Month" month)
  1020. (const :tag "Year" year)
  1021. (integer :tag "Custom")))
  1022. (defcustom org-agenda-start-on-weekday 1
  1023. "Non-nil means start the overview always on the specified weekday.
  1024. 0 denotes Sunday, 1 denotes Monday, etc.
  1025. When nil, always start on the current day.
  1026. Custom commands can set this variable in the options section."
  1027. :group 'org-agenda-daily/weekly
  1028. :type '(choice (const :tag "Today" nil)
  1029. (integer :tag "Weekday No.")))
  1030. (defcustom org-agenda-show-all-dates t
  1031. "Non-nil means `org-agenda' shows every day in the selected range.
  1032. When nil, only the days which actually have entries are shown."
  1033. :group 'org-agenda-daily/weekly
  1034. :type 'boolean)
  1035. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1036. "Format string for displaying dates in the agenda.
  1037. Used by the daily/weekly agenda. This should be a format string
  1038. understood by `format-time-string', or a function returning the
  1039. formatted date as a string. The function must take a single
  1040. argument, a calendar-style date list like (month day year)."
  1041. :group 'org-agenda-daily/weekly
  1042. :type '(choice
  1043. (string :tag "Format string")
  1044. (function :tag "Function")))
  1045. (defun org-agenda-end-of-line ()
  1046. "Go to the end of visible line."
  1047. (interactive)
  1048. (goto-char (line-end-position)))
  1049. (defun org-agenda-format-date-aligned (date)
  1050. "Format a DATE string for display in the daily/weekly agenda.
  1051. This function makes sure that dates are aligned for easy reading."
  1052. (require 'cal-iso)
  1053. (let* ((dayname (calendar-day-name date))
  1054. (day (cadr date))
  1055. (day-of-week (calendar-day-of-week date))
  1056. (month (car date))
  1057. (monthname (calendar-month-name month))
  1058. (year (nth 2 date))
  1059. (iso-week (org-days-to-iso-week
  1060. (calendar-absolute-from-gregorian date)))
  1061. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1062. ;; (1- year))
  1063. ;; ((and (= month 12) (<= iso-week 1))
  1064. ;; (1+ year))
  1065. ;; (t year)))
  1066. (weekstring (if (= day-of-week 1)
  1067. (format " W%02d" iso-week)
  1068. "")))
  1069. (format "%-10s %2d %s %4d%s"
  1070. dayname day monthname year weekstring)))
  1071. (defcustom org-agenda-time-leading-zero nil
  1072. "Non-nil means use leading zero for military times in agenda.
  1073. For example, 9:30am would become 09:30 rather than 9:30."
  1074. :group 'org-agenda-daily/weekly
  1075. :version "24.1"
  1076. :type 'boolean)
  1077. (defcustom org-agenda-timegrid-use-ampm nil
  1078. "When set, show AM/PM style timestamps on the timegrid."
  1079. :group 'org-agenda
  1080. :version "24.1"
  1081. :type 'boolean)
  1082. (defcustom org-agenda-clock-report-header nil
  1083. "Header for org agenda clock report mode"
  1084. :group 'org-agenda
  1085. :type '(choice
  1086. (string :tag "Header")
  1087. (const :tag "No header" nil))
  1088. :safe #'stringp
  1089. :package-version '(Org . "9.6"))
  1090. (defun org-agenda-time-of-day-to-ampm (time)
  1091. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1092. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1093. (minute (substring time -2))
  1094. (ampm "am"))
  1095. (cond
  1096. ((equal hour-number 12)
  1097. (setq ampm "pm"))
  1098. ((> hour-number 12)
  1099. (setq ampm "pm")
  1100. (setq hour-number (- hour-number 12))))
  1101. (concat
  1102. (if org-agenda-time-leading-zero
  1103. (format "%02d" hour-number)
  1104. (format "%02s" (number-to-string hour-number)))
  1105. ":" minute ampm)))
  1106. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1107. "Conditionally convert TIME to AM/PM format.
  1108. This is based on `org-agenda-timegrid-use-ampm'."
  1109. (if org-agenda-timegrid-use-ampm
  1110. (org-agenda-time-of-day-to-ampm time)
  1111. time))
  1112. (defcustom org-agenda-weekend-days '(6 0)
  1113. "Which days are weekend?
  1114. These days get the special face `org-agenda-date-weekend' in the agenda."
  1115. :group 'org-agenda-daily/weekly
  1116. :type '(set :greedy t
  1117. (const :tag "Monday" 1)
  1118. (const :tag "Tuesday" 2)
  1119. (const :tag "Wednesday" 3)
  1120. (const :tag "Thursday" 4)
  1121. (const :tag "Friday" 5)
  1122. (const :tag "Saturday" 6)
  1123. (const :tag "Sunday" 0)))
  1124. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1125. "Non-nil means jump to today when moving a past date forward in time.
  1126. When using S-right in the agenda to move a date forward, and the date
  1127. stamp currently points to the past, the first key press will move it
  1128. to today. When nil, just move one day forward even if the date stays
  1129. in the past."
  1130. :group 'org-agenda-daily/weekly
  1131. :version "24.1"
  1132. :type 'boolean)
  1133. (defcustom org-agenda-diary-file 'diary-file
  1134. "File to which to add new entries with the `i' key in agenda and calendar.
  1135. When this is the symbol `diary-file', the functionality in the Emacs
  1136. calendar will be used to add entries to the `diary-file'. But when this
  1137. points to a file, `org-agenda-diary-entry' will be used instead."
  1138. :group 'org-agenda
  1139. :type '(choice
  1140. (const :tag "The standard Emacs diary file" diary-file)
  1141. (file :tag "Special Org file diary entries")))
  1142. (defcustom org-agenda-include-diary nil
  1143. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1144. Custom commands can set this variable in the options section."
  1145. :group 'org-agenda-daily/weekly
  1146. :type 'boolean)
  1147. (defcustom org-agenda-include-deadlines t
  1148. "If non-nil, include entries within their deadline warning period.
  1149. Custom commands can set this variable in the options section."
  1150. :group 'org-agenda-daily/weekly
  1151. :version "24.1"
  1152. :type 'boolean)
  1153. (defcustom org-agenda-show-future-repeats t
  1154. "Non-nil shows repeated entries in the future part of the agenda.
  1155. When set to the symbol `next' only the first future repeat is shown."
  1156. :group 'org-agenda-daily/weekly
  1157. :type '(choice
  1158. (const :tag "Show all repeated entries" t)
  1159. (const :tag "Show next repeated entry" next)
  1160. (const :tag "Do not show repeated entries" nil))
  1161. :version "26.1"
  1162. :package-version '(Org . "9.1")
  1163. :safe #'symbolp)
  1164. (defcustom org-agenda-prefer-last-repeat nil
  1165. "Non-nil sets date for repeated entries to their last repeat.
  1166. When nil, display SCHEDULED and DEADLINE dates at their base
  1167. date, and in today's agenda, as a reminder. Display plain
  1168. time-stamps, on the other hand, at every repeat date in the past
  1169. in addition to the base date.
  1170. When non-nil, show a repeated entry at its latest repeat date,
  1171. possibly being today even if it wasn't marked as done. This
  1172. setting is useful if you do not always mark repeated entries as
  1173. done and, yet, consider that reaching repeat date starts the task
  1174. anew.
  1175. When set to a list of strings, prefer last repeats only for
  1176. entries with these TODO keywords."
  1177. :group 'org-agenda-daily/weekly
  1178. :type '(choice
  1179. (const :tag "Prefer last repeat" t)
  1180. (const :tag "Prefer base date" nil)
  1181. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1182. (string :tag "TODO keyword")))
  1183. :version "26.1"
  1184. :package-version '(Org . "9.1")
  1185. :safe (lambda (x) (or (booleanp x) (consp x))))
  1186. (defcustom org-scheduled-past-days 10000
  1187. "Number of days to continue listing scheduled items not marked DONE.
  1188. When an item is scheduled on a date, it shows up in the agenda on
  1189. this day and will be listed until it is marked done or for the
  1190. number of days given here."
  1191. :group 'org-agenda-daily/weekly
  1192. :type 'integer
  1193. :safe 'integerp)
  1194. (defcustom org-deadline-past-days 10000
  1195. "Number of days to warn about missed deadlines.
  1196. When an item has deadline on a date, it shows up in the agenda on
  1197. this day and will appear as a reminder until it is marked DONE or
  1198. for the number of days given here."
  1199. :group 'org-agenda-daily/weekly
  1200. :type 'integer
  1201. :version "26.1"
  1202. :package-version '(Org . "9.1")
  1203. :safe 'integerp)
  1204. (defcustom org-agenda-log-mode-items '(closed clock)
  1205. "List of items that should be shown in agenda log mode.
  1206. \\<org-agenda-mode-map>\
  1207. This list may contain the following symbols:
  1208. closed Show entries that have been closed on that day.
  1209. clock Show entries that have received clocked time on that day.
  1210. state Show all logged state changes.
  1211. Note that instead of changing this variable, you can also press \
  1212. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1213. the agenda to display all available LOG items temporarily."
  1214. :group 'org-agenda-daily/weekly
  1215. :type '(set :greedy t (const closed) (const clock) (const state)))
  1216. (defcustom org-agenda-clock-consistency-checks
  1217. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1218. :gap-ok-around ("4:00")
  1219. :default-face ((:background "DarkRed") (:foreground "white"))
  1220. :overlap-face nil :gap-face nil :no-end-time-face nil
  1221. :long-face nil :short-face nil)
  1222. "This is a property list, with the following keys:
  1223. :max-duration Mark clocking chunks that are longer than this time.
  1224. This is a time string like \"HH:MM\", or the number
  1225. of minutes as an integer.
  1226. :min-duration Mark clocking chunks that are shorter that this.
  1227. This is a time string like \"HH:MM\", or the number
  1228. of minutes as an integer.
  1229. :max-gap Mark gaps between clocking chunks that are longer than
  1230. this duration. A number of minutes, or a string
  1231. like \"HH:MM\".
  1232. :gap-ok-around List of times during the day which are usually not working
  1233. times. When a gap is detected, but the gap contains any
  1234. of these times, the gap is *not* reported. For example,
  1235. if this is (\"4:00\" \"13:00\") then gaps that contain
  1236. 4:00 in the morning (i.e. the night) and 13:00
  1237. (i.e. a typical lunch time) do not cause a warning.
  1238. You should have at least one time during the night in this
  1239. list, or otherwise the first task each morning will trigger
  1240. a warning because it follows a long gap.
  1241. Furthermore, the following properties can be used to define faces for
  1242. issue display.
  1243. :default-face the default face, if the specific face is undefined
  1244. :overlap-face face for overlapping clocks
  1245. :gap-face face for gaps between clocks
  1246. :no-end-time-face face for incomplete clocks
  1247. :long-face face for clock intervals that are too long
  1248. :short-face face for clock intervals that are too short"
  1249. :group 'org-agenda-daily/weekly
  1250. :group 'org-clock
  1251. :version "24.1"
  1252. :type 'plist)
  1253. (defcustom org-agenda-log-mode-add-notes t
  1254. "Non-nil means add first line of notes to log entries in agenda views.
  1255. If a log item like a state change or a clock entry is associated with
  1256. notes, the first line of these notes will be added to the entry in the
  1257. agenda display."
  1258. :group 'org-agenda-daily/weekly
  1259. :type 'boolean)
  1260. (defcustom org-agenda-start-with-log-mode nil
  1261. "The initial value of log-mode in a newly created agenda window.
  1262. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1263. explanations on the possible values."
  1264. :group 'org-agenda-startup
  1265. :group 'org-agenda-daily/weekly
  1266. :type '(choice (const :tag "Don't show log items" nil)
  1267. (const :tag "Show only log items" only)
  1268. (const :tag "Show all possible log items" clockcheck)
  1269. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1270. (choice (const :tag "Show closed log items" closed)
  1271. (const :tag "Show clocked log items" clock)
  1272. (const :tag "Show all logged state changes" state)))))
  1273. (defcustom org-agenda-start-with-clockreport-mode nil
  1274. "The initial value of clockreport-mode in a newly created agenda window."
  1275. :group 'org-agenda-startup
  1276. :group 'org-agenda-daily/weekly
  1277. :type 'boolean)
  1278. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1279. "Property list with parameters for the clocktable in clockreport mode.
  1280. This is the display mode that shows a clock table in the daily/weekly
  1281. agenda, the properties for this dynamic block can be set here.
  1282. The usual clocktable parameters are allowed here, but you cannot set
  1283. the properties :name, :tstart, :tend, :block, and :scope - these will
  1284. be overwritten to make sure the content accurately reflects the
  1285. current display in the agenda."
  1286. :group 'org-agenda-daily/weekly
  1287. :type 'plist)
  1288. (defvaralias 'org-agenda-search-view-search-words-only
  1289. 'org-agenda-search-view-always-boolean)
  1290. (defcustom org-agenda-search-view-always-boolean nil
  1291. "Non-nil means the search string is interpreted as individual parts.
  1292. The search string for search view can either be interpreted as a phrase,
  1293. or as a list of snippets that define a boolean search for a number of
  1294. strings.
  1295. When this is non-nil, the string will be split on whitespace, and each
  1296. snippet will be searched individually, and all must match in order to
  1297. select an entry. A snippet is then a single string of non-white
  1298. characters, or a string in double quotes, or a regexp in {} braces.
  1299. If a snippet is preceded by \"-\", the snippet must *not* match.
  1300. \"+\" is syntactic sugar for positive selection. Each snippet may
  1301. be found as a full word or a partial word, but see the variable
  1302. `org-agenda-search-view-force-full-words'.
  1303. When this is nil, search will look for the entire search phrase as one,
  1304. with each space character matching any amount of whitespace, including
  1305. line breaks.
  1306. Even when this is nil, you can still switch to Boolean search dynamically
  1307. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1308. is a regexp marked with braces like \"{abc}\", this will also switch to
  1309. boolean search."
  1310. :group 'org-agenda-search-view
  1311. :version "24.1"
  1312. :type 'boolean)
  1313. (defcustom org-agenda-search-view-force-full-words nil
  1314. "Non-nil means, search words must be matches as complete words.
  1315. When nil, they may also match part of a word."
  1316. :group 'org-agenda-search-view
  1317. :version "24.1"
  1318. :type 'boolean)
  1319. (defcustom org-agenda-search-view-max-outline-level 0
  1320. "Maximum outline level to display in search view.
  1321. E.g. when this is set to 1, the search view will only
  1322. show headlines of level 1. When set to 0, the default
  1323. value, don't limit agenda view by outline level."
  1324. :group 'org-agenda-search-view
  1325. :version "26.1"
  1326. :package-version '(Org . "8.3")
  1327. :type 'integer)
  1328. (defgroup org-agenda-time-grid nil
  1329. "Options concerning the time grid in the Org Agenda."
  1330. :tag "Org Agenda Time Grid"
  1331. :group 'org-agenda)
  1332. (defcustom org-agenda-search-headline-for-time t
  1333. "Non-nil means search headline for a time-of-day.
  1334. If the headline contains a time-of-day in one format or another, it will
  1335. be used to sort the entry into the time sequence of items for a day.
  1336. Some people have time stamps in the headline that refer to the creation
  1337. time or so, and then this produces an unwanted side effect. If this is
  1338. the case for your, use this variable to turn off searching the headline
  1339. for a time."
  1340. :group 'org-agenda-time-grid
  1341. :type 'boolean)
  1342. (defcustom org-agenda-use-time-grid t
  1343. "Non-nil means show a time grid in the agenda schedule.
  1344. A time grid is a set of lines for specific times (like every two hours between
  1345. 8:00 and 20:00). The items scheduled for a day at specific times are
  1346. sorted in between these lines.
  1347. For details about when the grid will be shown, and what it will look like, see
  1348. the variable `org-agenda-time-grid'."
  1349. :group 'org-agenda-time-grid
  1350. :type 'boolean)
  1351. (defcustom org-agenda-time-grid
  1352. '((daily today require-timed)
  1353. (800 1000 1200 1400 1600 1800 2000)
  1354. "......"
  1355. "----------------")
  1356. "The settings for time grid for agenda display.
  1357. This is a list of four items. The first item is again a list. It contains
  1358. symbols specifying conditions when the grid should be displayed:
  1359. daily if the agenda shows a single day
  1360. weekly if the agenda shows an entire week
  1361. today show grid on current date, independent of daily/weekly display
  1362. require-timed show grid only if at least one item has a time specification
  1363. remove-match skip grid times already present in an entry
  1364. The second item is a list of integers, indicating the times that
  1365. should have a grid line.
  1366. The third item is a string which will be placed right after the
  1367. times that have a grid line.
  1368. The fourth item is a string placed after the grid times. This
  1369. will align with agenda items."
  1370. :group 'org-agenda-time-grid
  1371. :type
  1372. '(list
  1373. (set :greedy t :tag "Grid Display Options"
  1374. (const :tag "Show grid in single day agenda display" daily)
  1375. (const :tag "Show grid in weekly agenda display" weekly)
  1376. (const :tag "Always show grid for today" today)
  1377. (const :tag "Show grid only if any timed entries are present"
  1378. require-timed)
  1379. (const :tag "Skip grid times already present in an entry"
  1380. remove-match))
  1381. (repeat :tag "Grid Times" (integer :tag "Time"))
  1382. (string :tag "Grid String (after agenda times)")
  1383. (string :tag "Grid String (aligns with agenda items)")))
  1384. (defcustom org-agenda-show-current-time-in-grid t
  1385. "Non-nil means show the current time in the time grid."
  1386. :group 'org-agenda-time-grid
  1387. :version "24.1"
  1388. :type 'boolean)
  1389. (defcustom org-agenda-current-time-string
  1390. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1391. "The string for the current time marker in the agenda."
  1392. :group 'org-agenda-time-grid
  1393. :version "24.1"
  1394. :type 'string)
  1395. (defgroup org-agenda-sorting nil
  1396. "Options concerning sorting in the Org Agenda."
  1397. :tag "Org Agenda Sorting"
  1398. :group 'org-agenda)
  1399. (defcustom org-agenda-sorting-strategy
  1400. '((agenda habit-down time-up priority-down category-keep)
  1401. (todo priority-down category-keep)
  1402. (tags priority-down category-keep)
  1403. (search category-keep))
  1404. "Sorting structure for the agenda items of a single day.
  1405. This is a list of symbols which will be used in sequence to determine
  1406. if an entry should be listed before another entry. The following
  1407. symbols are recognized:
  1408. time-up Put entries with time-of-day indications first, early first.
  1409. time-down Put entries with time-of-day indications first, late first.
  1410. timestamp-up Sort by any timestamp, early first.
  1411. timestamp-down Sort by any timestamp, late first.
  1412. scheduled-up Sort by scheduled timestamp, early first.
  1413. scheduled-down Sort by scheduled timestamp, late first.
  1414. deadline-up Sort by deadline timestamp, early first.
  1415. deadline-down Sort by deadline timestamp, late first.
  1416. ts-up Sort by active timestamp, early first.
  1417. ts-down Sort by active timestamp, late first.
  1418. tsia-up Sort by inactive timestamp, early first.
  1419. tsia-down Sort by inactive timestamp, late first.
  1420. category-keep Keep the default order of categories, corresponding to the
  1421. sequence in `org-agenda-files'.
  1422. category-up Sort alphabetically by category, A-Z.
  1423. category-down Sort alphabetically by category, Z-A.
  1424. tag-up Sort alphabetically by last tag, A-Z.
  1425. tag-down Sort alphabetically by last tag, Z-A.
  1426. priority-up Sort numerically by priority, high priority last.
  1427. priority-down Sort numerically by priority, high priority first.
  1428. todo-state-up Sort by todo state, tasks that are done last.
  1429. todo-state-down Sort by todo state, tasks that are done first.
  1430. effort-up Sort numerically by estimated effort, high effort last.
  1431. effort-down Sort numerically by estimated effort, high effort first.
  1432. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1433. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1434. habit-up Put entries that are habits first.
  1435. habit-down Put entries that are habits last.
  1436. alpha-up Sort headlines alphabetically.
  1437. alpha-down Sort headlines alphabetically, reversed.
  1438. The different possibilities will be tried in sequence, and testing stops
  1439. if one comparison returns a \"not-equal\". For example, the default
  1440. \\='(time-up category-keep priority-down)
  1441. means: Pull out all entries having a specified time of day and sort them,
  1442. in order to make a time schedule for the current day the first thing in the
  1443. agenda listing for the day. Of the entries without a time indication, keep
  1444. the grouped in categories, don't sort the categories, but keep them in
  1445. the sequence given in `org-agenda-files'. Within each category sort by
  1446. priority.
  1447. Leaving out `category-keep' would mean that items will be sorted across
  1448. categories by priority.
  1449. Instead of a single list, this can also be a set of list for specific
  1450. contents, with a context symbol in the car of the list, any of
  1451. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1452. Custom commands can bind this variable in the options section."
  1453. :group 'org-agenda-sorting
  1454. :type `(choice
  1455. (repeat :tag "General" ,org-sorting-choice)
  1456. (list :tag "Individually"
  1457. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1458. (repeat ,org-sorting-choice))
  1459. (cons (const :tag "Strategy for TODO lists" todo)
  1460. (repeat ,org-sorting-choice))
  1461. (cons (const :tag "Strategy for Tags matches" tags)
  1462. (repeat ,org-sorting-choice))
  1463. (cons (const :tag "Strategy for search matches" search)
  1464. (repeat ,org-sorting-choice)))))
  1465. (defcustom org-agenda-cmp-user-defined nil
  1466. "A function to define the comparison `user-defined'.
  1467. This function must receive two arguments, agenda entry a and b.
  1468. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1469. the user comparison, return nil.
  1470. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1471. part of an agenda sorting strategy."
  1472. :group 'org-agenda-sorting
  1473. :type 'symbol)
  1474. (defcustom org-agenda-sort-notime-is-late t
  1475. "Non-nil means items without time are considered late.
  1476. This is only relevant for sorting. When t, items which have no explicit
  1477. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1478. do have a time. When nil, the default time is before 0:00. You can use this
  1479. option to decide if the schedule for today should come before or after timeless
  1480. agenda entries."
  1481. :group 'org-agenda-sorting
  1482. :type 'boolean)
  1483. (defcustom org-agenda-sort-noeffort-is-high t
  1484. "Non-nil means items without effort estimate are sorted as high effort.
  1485. This also applies when filtering an agenda view with respect to the
  1486. < or > effort operator. Then, tasks with no effort defined will be treated
  1487. as tasks with high effort.
  1488. When nil, such items are sorted as 0 minutes effort."
  1489. :group 'org-agenda-sorting
  1490. :type 'boolean)
  1491. (defgroup org-agenda-line-format nil
  1492. "Options concerning the entry prefix in the Org agenda display."
  1493. :tag "Org Agenda Line Format"
  1494. :group 'org-agenda)
  1495. (defcustom org-agenda-prefix-format
  1496. '((agenda . " %i %-12:c%?-12t% s")
  1497. (todo . " %i %-12:c")
  1498. (tags . " %i %-12:c")
  1499. (search . " %i %-12:c"))
  1500. "Format specifications for the prefix of items in the agenda views.
  1501. An alist with one entry per agenda type. The keys of the
  1502. sublists are `agenda', `todo', `search' and `tags'. The values
  1503. are format strings.
  1504. This format works similar to a printf format, with the following meaning:
  1505. %c the category of the item, \"Diary\" for entries from the diary,
  1506. or as given by the CATEGORY keyword or derived from the file name
  1507. %e the effort required by the item
  1508. %l the level of the item (insert X space(s) if item is of level X)
  1509. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1510. %T the last tag of the item (ignore inherited tags, which come first)
  1511. %t the HH:MM time-of-day specification if one applies to the entry
  1512. %s Scheduling/Deadline information, a short string
  1513. %b show breadcrumbs, i.e., the names of the higher levels
  1514. %(expression) Eval EXPRESSION and replace the control string
  1515. by the result
  1516. All specifiers work basically like the standard `%s' of printf, but may
  1517. contain two additional characters: a question mark just after the `%'
  1518. and a whitespace/punctuation character just before the final letter.
  1519. If the first character after `%' is a question mark, the entire field
  1520. will only be included if the corresponding value applies to the current
  1521. entry. This is useful for fields which should have fixed width when
  1522. present, but zero width when absent. For example, \"%?-12t\" will
  1523. result in a 12 character time field if a time of the day is specified,
  1524. but will completely disappear in entries which do not contain a time.
  1525. If there is punctuation or whitespace character just before the
  1526. final format letter, this character will be appended to the field
  1527. value if the value is not empty. For example, the format
  1528. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1529. the category is empty, no additional colon is inserted.
  1530. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1531. which means:
  1532. - Indent the line with two space characters
  1533. - Give the category a 12 chars wide field, padded with whitespace on
  1534. the right (because of `-'). Append a colon if there is a category
  1535. (because of `:').
  1536. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1537. time, don't put in an empty field, just skip it (because of '?').
  1538. - Finally, put the scheduling information.
  1539. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1540. `org-agenda-remove-tags'.
  1541. Custom commands can set this variable in the options section."
  1542. :type '(choice
  1543. (string :tag "General format")
  1544. (list :greedy t :tag "View dependent"
  1545. (cons (const agenda) (string :tag "Format"))
  1546. (cons (const todo) (string :tag "Format"))
  1547. (cons (const tags) (string :tag "Format"))
  1548. (cons (const search) (string :tag "Format"))))
  1549. :group 'org-agenda-line-format
  1550. :version "26.1"
  1551. :package-version '(Org . "9.1"))
  1552. (defcustom org-agenda-breadcrumbs-separator "->"
  1553. "The separator of breadcrumbs in agenda lines."
  1554. :group 'org-agenda-line-format
  1555. :package-version '(Org . "9.3")
  1556. :type 'string
  1557. :safe #'stringp)
  1558. (defvar org-prefix-format-compiled nil
  1559. "The compiled prefix format and associated variables.
  1560. This is a list where first element is a list of variable bindings, and second
  1561. element is the compiled format expression. See the variable
  1562. `org-agenda-prefix-format'.")
  1563. (defcustom org-agenda-todo-keyword-format "%-1s"
  1564. "Format for the TODO keyword in agenda lines.
  1565. Set this to something like \"%-12s\" if you want all TODO keywords
  1566. to occupy a fixed space in the agenda display."
  1567. :group 'org-agenda-line-format
  1568. :type 'string)
  1569. (defcustom org-agenda-diary-sexp-prefix nil
  1570. "A regexp that matches part of a diary sexp entry
  1571. which should be treated as scheduling/deadline information in
  1572. `org-agenda'.
  1573. For example, you can use this to extract the `diary-remind-message' from
  1574. `diary-remind' entries."
  1575. :group 'org-agenda-line-format
  1576. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1577. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1578. "Text preceding timerange entries in the agenda view.
  1579. This is a list with two strings. The first applies when the range
  1580. is entirely on one day. The second applies if the range spans several days.
  1581. The strings may have two \"%d\" format specifiers which will be filled
  1582. with the sequence number of the days, and the total number of days in the
  1583. range, respectively."
  1584. :group 'org-agenda-line-format
  1585. :type '(list
  1586. (string :tag "Deadline today ")
  1587. (choice :tag "Deadline relative"
  1588. (string :tag "Format string")
  1589. (function))))
  1590. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1591. "Text preceding scheduled items in the agenda view.
  1592. This is a list with two strings. The first applies when the item is
  1593. scheduled on the current day. The second applies when it has been scheduled
  1594. previously, it may contain a %d indicating that this is the nth time that
  1595. this item is scheduled, due to automatic rescheduling of unfinished items
  1596. for the following day. So this number is one larger than the number of days
  1597. that passed since this item was scheduled first."
  1598. :group 'org-agenda-line-format
  1599. :version "24.4"
  1600. :package-version '(Org . "8.0")
  1601. :type '(list
  1602. (string :tag "Scheduled today ")
  1603. (string :tag "Scheduled previously")))
  1604. (defcustom org-agenda-inactive-leader "["
  1605. "Text preceding item pulled into the agenda by inactive time stamps.
  1606. These entries are added to the agenda when pressing \"[\"."
  1607. :group 'org-agenda-line-format
  1608. :version "24.1"
  1609. :type 'string)
  1610. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1611. "Text preceding deadline items in the agenda view.
  1612. This is a list with three strings. The first applies when the item has its
  1613. deadline on the current day. The second applies when the deadline is in the
  1614. future, the third one when it is in the past. The strings may contain %d
  1615. to capture the number of days."
  1616. :group 'org-agenda-line-format
  1617. :version "24.4"
  1618. :package-version '(Org . "8.0")
  1619. :type '(list
  1620. (string :tag "Deadline today ")
  1621. (string :tag "Deadline in the future ")
  1622. (string :tag "Deadline in the past ")))
  1623. (defcustom org-agenda-remove-times-when-in-prefix t
  1624. "Non-nil means remove duplicate time specifications in agenda items.
  1625. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1626. time-of-day specification in a headline or diary entry is extracted and
  1627. placed into the prefix. If this option is non-nil, the original specification
  1628. \(a timestamp or -range, or just a plain time(range) specification like
  1629. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1630. cluttered.
  1631. The option can be t or nil. It may also be the symbol `beg', indicating
  1632. that the time should only be removed when it is located at the beginning of
  1633. the headline/diary entry."
  1634. :group 'org-agenda-line-format
  1635. :type '(choice
  1636. (const :tag "Always" t)
  1637. (const :tag "Never" nil)
  1638. (const :tag "When at beginning of entry" beg)))
  1639. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1640. "Non-nil means remove time ranges specifications in agenda
  1641. items that span on several days."
  1642. :group 'org-agenda-line-format
  1643. :version "24.1"
  1644. :type 'boolean)
  1645. (defcustom org-agenda-default-appointment-duration nil
  1646. "Default duration for appointments that only have a starting time.
  1647. When nil, no duration is specified in such cases.
  1648. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1649. :group 'org-agenda-line-format
  1650. :type '(choice
  1651. (integer :tag "Minutes")
  1652. (const :tag "No default duration")))
  1653. (defcustom org-agenda-show-inherited-tags t
  1654. "Non-nil means show inherited tags in each agenda line.
  1655. When this option is set to `always', it takes precedence over
  1656. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1657. in every agenda.
  1658. When this option is set to t (the default), inherited tags are
  1659. shown when they are available, i.e. when the value of
  1660. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1661. given agenda type.
  1662. This can be set to a list of agenda types in which the agenda
  1663. must display the inherited tags. Available types are `todo',
  1664. `agenda' and `search'.
  1665. When set to nil, never show inherited tags in agenda lines."
  1666. :group 'org-agenda-line-format
  1667. :group 'org-agenda
  1668. :version "24.3"
  1669. :type '(choice
  1670. (const :tag "Show inherited tags when available" t)
  1671. (const :tag "Always show inherited tags" always)
  1672. (repeat :tag "Show inherited tags only in selected agenda types"
  1673. (symbol :tag "Agenda type"))))
  1674. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1675. "List of agenda view types where to use tag inheritance.
  1676. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1677. controlled by `org-use-tag-inheritance'. In other agenda types,
  1678. `org-use-tag-inheritance' is not used for the selection of the
  1679. agenda entries. Still, you may want the agenda to be aware of
  1680. the inherited tags anyway, e.g. for later tag filtering.
  1681. Allowed value are `todo', `search' and `agenda'.
  1682. This variable has no effect if `org-agenda-show-inherited-tags'
  1683. is set to `always'. In that case, the agenda is aware of those
  1684. tags.
  1685. The default value sets tags in every agenda type. Setting this
  1686. option to nil will speed up non-tags agenda view a lot."
  1687. :group 'org-agenda
  1688. :version "26.1"
  1689. :package-version '(Org . "9.1")
  1690. :type '(choice
  1691. (const :tag "Use tag inheritance in all agenda types" t)
  1692. (repeat :tag "Use tag inheritance in selected agenda types"
  1693. (symbol :tag "Agenda type"))))
  1694. (defcustom org-agenda-hide-tags-regexp nil
  1695. "Regular expression used to filter away specific tags in agenda views.
  1696. This means that these tags will be present, but not be shown in the agenda
  1697. line. Secondary filtering will still work on the hidden tags.
  1698. Nil means don't hide any tags."
  1699. :group 'org-agenda-line-format
  1700. :type '(choice
  1701. (const :tag "Hide none" nil)
  1702. (regexp :tag "Regexp ")))
  1703. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1704. 'org-agenda-remove-tags)
  1705. (defcustom org-agenda-remove-tags nil
  1706. "Non-nil means remove the tags from the headline copy in the agenda.
  1707. When this is the symbol `prefix', only remove tags when
  1708. `org-agenda-prefix-format' contains a `%T' specifier."
  1709. :group 'org-agenda-line-format
  1710. :type '(choice
  1711. (const :tag "Always" t)
  1712. (const :tag "Never" nil)
  1713. (const :tag "When prefix format contains %T" prefix)))
  1714. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1715. (defcustom org-agenda-tags-column 'auto
  1716. "Shift tags in agenda items to this column.
  1717. If set to `auto', tags will be automatically aligned to the right
  1718. edge of the window.
  1719. If set to a positive number, tags will be left-aligned to that
  1720. column. If set to a negative number, tags will be right-aligned
  1721. to that column. For example, -80 works well for a normal 80
  1722. character screen."
  1723. :group 'org-agenda-line-format
  1724. :type '(choice
  1725. (const :tag "Automatically align to right edge of window" auto)
  1726. (integer :tag "Specific column" -80))
  1727. :package-version '(Org . "9.1")
  1728. :version "26.1")
  1729. (defcustom org-agenda-fontify-priorities 'cookies
  1730. "Non-nil means highlight low and high priorities in agenda.
  1731. When t, the highest priority entries are bold, lowest priority italic.
  1732. However, settings in `org-priority-faces' will overrule these faces.
  1733. When this variable is the symbol `cookies', only fontify the
  1734. cookies, not the entire task.
  1735. This may also be an association list of priority faces, whose
  1736. keys are the character values of `org-priority-highest',
  1737. `org-priority-default', and `org-priority-lowest' (the default values
  1738. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1739. color as a string, or a list like `(:background \"Red\")'.
  1740. If it is a color, the variable `org-faces-easy-properties'
  1741. determines if it is a foreground or a background color."
  1742. :group 'org-agenda-line-format
  1743. :type '(choice
  1744. (const :tag "Never" nil)
  1745. (const :tag "Defaults" t)
  1746. (const :tag "Cookies only" cookies)
  1747. (repeat :tag "Specify"
  1748. (list (character :tag "Priority" :value ?A)
  1749. (choice :tag "Face "
  1750. (string :tag "Color")
  1751. (sexp :tag "Face"))))))
  1752. (defcustom org-agenda-day-face-function nil
  1753. "Function called to determine what face should be used to display a day.
  1754. The only argument passed to that function is the day. It should
  1755. returns a face, or nil if does not want to specify a face and let
  1756. the normal rules apply."
  1757. :group 'org-agenda-line-format
  1758. :version "24.1"
  1759. :type '(choice (const nil) (function)))
  1760. (defcustom org-agenda-category-icon-alist nil
  1761. "Alist of category icon to be displayed in agenda views.
  1762. Each entry should have the following format:
  1763. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1764. Where CATEGORY-REGEXP is a regexp matching the categories where
  1765. the icon should be displayed.
  1766. FILE-OR-DATA either a file path or a string containing image data.
  1767. The other fields can be omitted safely if not needed:
  1768. TYPE indicates the image type.
  1769. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1770. image data.
  1771. PROPS are additional image attributes to assign to the image,
  1772. like, e.g. `:ascent center'.
  1773. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1774. If you want to set the display properties yourself, just put a
  1775. list as second element:
  1776. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1777. For example, to display a 16px horizontal space for Emacs
  1778. category, you can use:
  1779. (\"Emacs\" \\='(space . (:width (16))))"
  1780. :group 'org-agenda-line-format
  1781. :version "24.1"
  1782. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1783. :value-type (choice (list :tag "Icon"
  1784. (string :tag "File or data")
  1785. (symbol :tag "Type")
  1786. (boolean :tag "Data?")
  1787. (repeat :tag "Extra image properties" :inline t sexp))
  1788. (list :tag "Display properties" sexp))))
  1789. (defgroup org-agenda-column-view nil
  1790. "Options concerning column view in the agenda."
  1791. :tag "Org Agenda Column View"
  1792. :group 'org-agenda)
  1793. (defcustom org-agenda-view-columns-initially nil
  1794. "When non-nil, switch to columns view right after creating the agenda."
  1795. :group 'org-agenda-column-view
  1796. :type 'boolean
  1797. :version "26.1"
  1798. :package-version '(Org . "9.0")
  1799. :safe #'booleanp)
  1800. (defcustom org-agenda-columns-show-summaries t
  1801. "Non-nil means show summaries for columns displayed in the agenda view."
  1802. :group 'org-agenda-column-view
  1803. :type 'boolean)
  1804. (defcustom org-agenda-columns-compute-summary-properties t
  1805. "Non-nil means recompute all summary properties before column view.
  1806. When column view in the agenda is listing properties that have a summary
  1807. operator, it can go to all relevant buffers and recompute the summaries
  1808. there. This can mean overhead for the agenda column view, but is necessary
  1809. to have thing up to date.
  1810. As a special case, a CLOCKSUM property also makes sure that the clock
  1811. computations are current."
  1812. :group 'org-agenda-column-view
  1813. :type 'boolean)
  1814. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1815. "Non-nil means the duration of an appointment will add to day effort.
  1816. The property to which appointment durations will be added is the one given
  1817. in the option `org-effort-property'. If an appointment does not have
  1818. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1819. is not set, an appointment without end time will not contribute to the time
  1820. estimate."
  1821. :group 'org-agenda-column-view
  1822. :type 'boolean)
  1823. (defcustom org-agenda-auto-exclude-function nil
  1824. "A function called with a tag to decide if it is filtered on \
  1825. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1826. The sole argument to the function, which is called once for each
  1827. possible tag, is a string giving the name of the tag. The
  1828. function should return either nil if the tag should be included
  1829. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1830. lines not carrying this tag.
  1831. Note that for the purpose of tag filtering, only the lower-case version of
  1832. all tags will be considered, so that this function will only ever see
  1833. the lower-case version of all tags."
  1834. :group 'org-agenda
  1835. :type '(choice (const nil) (function)))
  1836. (defcustom org-agenda-bulk-custom-functions nil
  1837. "Alist of characters and custom functions for bulk actions.
  1838. For example, this value makes those two functions available:
  1839. \\='((?R set-category)
  1840. (?C bulk-cut))
  1841. With selected entries in an agenda buffer, `B R' will call
  1842. the custom function `set-category' on the selected entries.
  1843. Note that functions in this alist don't need to be quoted.
  1844. You can also specify a function which collects arguments to be
  1845. used for each call to your bulk custom function. The argument
  1846. collecting function will be run once and should return a list of
  1847. arguments to pass to the bulk function. For example:
  1848. \\='((?R set-category get-category))
  1849. Now, `B R' will call the custom `get-category' which would prompt
  1850. the user once for a category. That category is then passed as an
  1851. argument to `set-category' for each entry it's called against."
  1852. :type
  1853. '(alist :key-type character
  1854. :value-type
  1855. (group (function :tag "Bulk Custom Function")
  1856. (choice (function :tag "Bulk Custom Argument Function")
  1857. (const :tag "No Bulk Custom Argument Function" nil))))
  1858. :package-version '(Org . "9.5")
  1859. :group 'org-agenda)
  1860. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1861. "Execute BODY with point at location given by `org-hd-marker' property.
  1862. If STRING is non-nil, the text property will be fetched from position 0
  1863. in that string. If STRING is nil, it will be fetched from the beginning
  1864. of the current line."
  1865. (declare (debug t))
  1866. (org-with-gensyms (marker)
  1867. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1868. 'org-hd-marker ,string)))
  1869. (with-current-buffer (marker-buffer ,marker)
  1870. (save-excursion
  1871. (goto-char ,marker)
  1872. ,@body)))))
  1873. (defun org-add-agenda-custom-command (entry)
  1874. "Replace or add a command in `org-agenda-custom-commands'.
  1875. This is mostly for hacking and trying a new command - once the command
  1876. works you probably want to add it to `org-agenda-custom-commands' for good."
  1877. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1878. (if ass
  1879. (setcdr ass (cdr entry))
  1880. (push entry org-agenda-custom-commands))))
  1881. (defmacro org-agenda--insert-overriding-header (default)
  1882. "Insert header into agenda view.
  1883. The inserted header depends on `org-agenda-overriding-header'.
  1884. If the empty string, don't insert a header. If any other string,
  1885. insert it as a header. If nil, insert DEFAULT, which should
  1886. evaluate to a string. If a function, call it and insert the
  1887. string that it returns."
  1888. (declare (debug (form)) (indent defun))
  1889. `(cond
  1890. ((not org-agenda-overriding-header) (insert ,default))
  1891. ((equal org-agenda-overriding-header "") nil)
  1892. ((stringp org-agenda-overriding-header)
  1893. (insert (propertize org-agenda-overriding-header
  1894. 'face 'org-agenda-structure)
  1895. "\n"))
  1896. ((functionp org-agenda-overriding-header)
  1897. (insert (funcall org-agenda-overriding-header)))
  1898. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1899. org-agenda-overriding-header))))
  1900. ;;; Define the org-agenda-mode
  1901. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1902. (defvar org-agenda-mode-map (make-sparse-keymap)
  1903. "Keymap for `org-agenda-mode'.")
  1904. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1905. (defvar org-agenda-menu) ; defined later in this file.
  1906. (defvar org-agenda-restrict nil)
  1907. (defvar org-agenda-follow-mode nil)
  1908. (defvar org-agenda-entry-text-mode nil)
  1909. (defvar org-agenda-clockreport-mode nil)
  1910. (defvar org-agenda-show-log nil
  1911. "When non-nil, show the log in the agenda.
  1912. Do not set this directly; instead use
  1913. `org-agenda-start-with-log-mode', which see.")
  1914. (defvar org-agenda-redo-command nil)
  1915. (defvar org-agenda-query-string nil)
  1916. (defvar org-agenda-mode-hook nil
  1917. "Hook run after `org-agenda-mode' is turned on.
  1918. The buffer is still writable when this hook is called.")
  1919. (defvar org-agenda-type nil)
  1920. (defvar org-agenda-force-single-file nil)
  1921. (defvar org-agenda-bulk-marked-entries nil
  1922. "List of markers that refer to marked entries in the agenda.")
  1923. (defvar org-agenda-current-date nil
  1924. "Active date when building the agenda.")
  1925. ;;; Multiple agenda buffers support
  1926. (defcustom org-agenda-sticky nil
  1927. "Non-nil means agenda q key will bury agenda buffers.
  1928. Agenda commands will then show existing buffer instead of generating new ones.
  1929. When nil, `q' will kill the single agenda buffer."
  1930. :group 'org-agenda
  1931. :version "24.3"
  1932. :type 'boolean)
  1933. ;;;###autoload
  1934. (defun org-toggle-sticky-agenda (&optional arg)
  1935. "Toggle `org-agenda-sticky'."
  1936. (interactive "P")
  1937. (let ((new-value (if arg
  1938. (> (prefix-numeric-value arg) 0)
  1939. (not org-agenda-sticky))))
  1940. (if (equal new-value org-agenda-sticky)
  1941. (and (called-interactively-p 'interactive)
  1942. (message "Sticky agenda was already %s"
  1943. (if org-agenda-sticky "enabled" "disabled")))
  1944. (setq org-agenda-sticky new-value)
  1945. (org-agenda-kill-all-agenda-buffers)
  1946. (and (called-interactively-p 'interactive)
  1947. (message "Sticky agenda %s"
  1948. (if org-agenda-sticky "enabled" "disabled"))))))
  1949. (defvar org-agenda-buffer nil
  1950. "Agenda buffer currently being generated.")
  1951. (defvar org-agenda-last-prefix-arg nil)
  1952. (defvar org-agenda-this-buffer-name nil)
  1953. (defvar org-agenda-doing-sticky-redo nil)
  1954. (defvar org-agenda-this-buffer-is-sticky nil)
  1955. (defvar org-agenda-last-indirect-buffer nil
  1956. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1957. (defconst org-agenda-local-vars
  1958. '(org-agenda-this-buffer-name
  1959. org-agenda-undo-list
  1960. org-agenda-pending-undo-list
  1961. org-agenda-follow-mode
  1962. org-agenda-entry-text-mode
  1963. org-agenda-clockreport-mode
  1964. org-agenda-show-log
  1965. org-agenda-redo-command
  1966. org-agenda-query-string
  1967. org-agenda-type
  1968. org-agenda-bulk-marked-entries
  1969. org-agenda-undo-has-started-in
  1970. org-agenda-info
  1971. org-agenda-pre-window-conf
  1972. org-agenda-columns-active
  1973. org-agenda-tag-filter
  1974. org-agenda-category-filter
  1975. org-agenda-top-headline-filter
  1976. org-agenda-regexp-filter
  1977. org-agenda-effort-filter
  1978. org-agenda-markers
  1979. org-agenda-last-search-view-search-was-boolean
  1980. org-agenda-last-indirect-buffer
  1981. org-agenda-filtered-by-category
  1982. org-agenda-filter-form
  1983. org-agenda-cycle-counter
  1984. org-agenda-last-prefix-arg)
  1985. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1986. (defun org-agenda-mode ()
  1987. "Mode for time-sorted view on action items in Org files.
  1988. The following commands are available:
  1989. \\{org-agenda-mode-map}"
  1990. (interactive)
  1991. (ignore-errors (require 'face-remap))
  1992. (let ((agenda-local-vars-to-keep
  1993. '(text-scale-mode-amount
  1994. text-scale-mode
  1995. text-scale-mode-lighter
  1996. face-remapping-alist))
  1997. (save (buffer-local-variables)))
  1998. (kill-all-local-variables)
  1999. (cl-flet ((reset-saved (var-set)
  2000. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2001. (dolist (elem save)
  2002. (pcase elem
  2003. (`(,var . ,val) ;ignore unbound variables
  2004. (when (and val (memq var var-set))
  2005. (set var val)))))))
  2006. (cond (org-agenda-doing-sticky-redo
  2007. ;; Refreshing sticky agenda-buffer
  2008. ;;
  2009. ;; Preserve the value of `org-agenda-local-vars' variables.
  2010. (mapc #'make-local-variable org-agenda-local-vars)
  2011. (reset-saved org-agenda-local-vars)
  2012. (setq-local org-agenda-this-buffer-is-sticky t))
  2013. (org-agenda-sticky
  2014. ;; Creating a sticky Agenda buffer for the first time
  2015. (mapc #'make-local-variable org-agenda-local-vars)
  2016. (setq-local org-agenda-this-buffer-is-sticky t))
  2017. (t
  2018. ;; Creating a non-sticky agenda buffer
  2019. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2020. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2021. (reset-saved agenda-local-vars-to-keep)))
  2022. (setq org-agenda-undo-list nil
  2023. org-agenda-pending-undo-list nil
  2024. org-agenda-bulk-marked-entries nil)
  2025. (setq major-mode 'org-agenda-mode)
  2026. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2027. (setq-local font-lock-global-modes (list 'not major-mode))
  2028. (setq mode-name "Org-Agenda")
  2029. (setq indent-tabs-mode nil)
  2030. (use-local-map org-agenda-mode-map)
  2031. (when org-startup-truncated (setq truncate-lines t))
  2032. (setq-local line-move-visual nil)
  2033. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2034. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2035. ;; Make sure properties are removed when copying text
  2036. (if (boundp 'filter-buffer-substring-functions)
  2037. (add-hook 'filter-buffer-substring-functions
  2038. (lambda (fun start end delete)
  2039. (substring-no-properties (funcall fun start end delete)))
  2040. nil t)
  2041. ;; Emacs >= 24.4.
  2042. (add-function :filter-return (local 'filter-buffer-substring-function)
  2043. #'substring-no-properties))
  2044. (unless org-agenda-keep-modes
  2045. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2046. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2047. org-agenda-show-log org-agenda-start-with-log-mode
  2048. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2049. (add-to-invisibility-spec '(org-filtered))
  2050. (org-fold-core-initialize `(,org-link--description-folding-spec
  2051. ,org-link--link-folding-spec))
  2052. (easy-menu-change
  2053. '("Agenda") "Agenda Files"
  2054. (append
  2055. (list
  2056. (vector
  2057. (if (get 'org-agenda-files 'org-restrict)
  2058. "Restricted to single file"
  2059. "Edit File List")
  2060. '(org-edit-agenda-file-list)
  2061. (not (get 'org-agenda-files 'org-restrict)))
  2062. "--")
  2063. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2064. (org-agenda-set-mode-name)
  2065. (run-mode-hooks 'org-agenda-mode-hook))
  2066. (substitute-key-definition #'undo #'org-agenda-undo
  2067. org-agenda-mode-map global-map)
  2068. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2069. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2070. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2071. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2072. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2073. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2074. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2075. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2076. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2077. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2078. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2079. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2080. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2081. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2082. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2083. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2084. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2085. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2086. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2087. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2088. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2089. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2090. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2091. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2092. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2093. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2094. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2095. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2096. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2097. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2098. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2099. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2100. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2101. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2102. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2103. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2104. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2105. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2106. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2107. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2108. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2109. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2110. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2111. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2112. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2113. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2114. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2115. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2116. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2117. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2118. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2119. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2120. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2121. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2122. (while l (org-defkey org-agenda-mode-map
  2123. (number-to-string (pop l)) #'digit-argument)))
  2124. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2125. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2126. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2127. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2128. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2129. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2130. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2131. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2132. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2133. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2134. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2135. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2136. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2137. #'org-clock-modify-effort-estimate)
  2138. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2139. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2140. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2141. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2142. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2143. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2144. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2145. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2146. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2147. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2148. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2149. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2150. (substitute-key-definition #'next-line #'org-agenda-next-line
  2151. org-agenda-mode-map global-map)
  2152. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2153. org-agenda-mode-map global-map)
  2154. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2155. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2156. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2157. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2158. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2159. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2160. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2161. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2162. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2163. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2164. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2165. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2167. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2168. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2169. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2170. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2171. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2172. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2173. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2174. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2175. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2176. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2177. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2178. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2179. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2180. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2181. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2182. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2183. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2185. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2186. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2187. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2188. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2189. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2190. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2191. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2192. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2193. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2194. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2195. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2196. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2197. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2198. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2199. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2200. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2201. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2202. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2203. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2204. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2205. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2206. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2207. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2208. (when org-agenda-mouse-1-follows-link
  2209. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2210. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2211. '("Agenda"
  2212. ("Agenda Files")
  2213. "--"
  2214. ("Agenda Dates"
  2215. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2216. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2217. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2218. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2219. "--"
  2220. ("View"
  2221. ["Day View" org-agenda-day-view
  2222. :active (org-agenda-check-type nil 'agenda)
  2223. :style radio :selected (eq org-agenda-current-span 'day)
  2224. :keys "v d (or just d)"]
  2225. ["Week View" org-agenda-week-view
  2226. :active (org-agenda-check-type nil 'agenda)
  2227. :style radio :selected (eq org-agenda-current-span 'week)
  2228. :keys "v w"]
  2229. ["Fortnight View" org-agenda-fortnight-view
  2230. :active (org-agenda-check-type nil 'agenda)
  2231. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2232. :keys "v t"]
  2233. ["Month View" org-agenda-month-view
  2234. :active (org-agenda-check-type nil 'agenda)
  2235. :style radio :selected (eq org-agenda-current-span 'month)
  2236. :keys "v m"]
  2237. ["Year View" org-agenda-year-view
  2238. :active (org-agenda-check-type nil 'agenda)
  2239. :style radio :selected (eq org-agenda-current-span 'year)
  2240. :keys "v y"]
  2241. "--"
  2242. ["Include Diary" org-agenda-toggle-diary
  2243. :style toggle :selected org-agenda-include-diary
  2244. :active (org-agenda-check-type nil 'agenda)]
  2245. ["Include Deadlines" org-agenda-toggle-deadlines
  2246. :style toggle :selected org-agenda-include-deadlines
  2247. :active (org-agenda-check-type nil 'agenda)]
  2248. ["Use Time Grid" org-agenda-toggle-time-grid
  2249. :style toggle :selected org-agenda-use-time-grid
  2250. :active (org-agenda-check-type nil 'agenda)]
  2251. "--"
  2252. ["Show clock report" org-agenda-clockreport-mode
  2253. :style toggle :selected org-agenda-clockreport-mode
  2254. :active (org-agenda-check-type nil 'agenda)]
  2255. ["Show some entry text" org-agenda-entry-text-mode
  2256. :style toggle :selected org-agenda-entry-text-mode
  2257. :active t]
  2258. "--"
  2259. ["Show Logbook entries" org-agenda-log-mode
  2260. :style toggle :selected org-agenda-show-log
  2261. :active (org-agenda-check-type nil 'agenda)
  2262. :keys "v l (or just l)"]
  2263. ["Include archived trees" org-agenda-archives-mode
  2264. :style toggle :selected org-agenda-archives-mode :active t
  2265. :keys "v a"]
  2266. ["Include archive files" (org-agenda-archives-mode t)
  2267. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2268. :keys "v A"]
  2269. "--"
  2270. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2271. ("Filter current view"
  2272. ["with generic interface" org-agenda-filter t]
  2273. "--"
  2274. ["by category at cursor" org-agenda-filter-by-category t]
  2275. ["by tag" org-agenda-filter-by-tag t]
  2276. ["by effort" org-agenda-filter-by-effort t]
  2277. ["by regexp" org-agenda-filter-by-regexp t]
  2278. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2279. "--"
  2280. ["Remove all filtering" org-agenda-filter-remove-all t]
  2281. "--"
  2282. ["limit" org-agenda-limit-interactively t])
  2283. ["Rebuild buffer" org-agenda-redo t]
  2284. ["Write view to file" org-agenda-write t]
  2285. ["Save all Org buffers" org-save-all-org-buffers t]
  2286. "--"
  2287. ["Show original entry" org-agenda-show t]
  2288. ["Go To (other window)" org-agenda-goto t]
  2289. ["Go To (this window)" org-agenda-switch-to t]
  2290. ["Capture with cursor date" org-agenda-capture t]
  2291. ["Follow Mode" org-agenda-follow-mode
  2292. :style toggle :selected org-agenda-follow-mode :active t]
  2293. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2294. "--"
  2295. ("TODO"
  2296. ["Cycle TODO" org-agenda-todo t]
  2297. ["Next TODO set" org-agenda-todo-nextset t]
  2298. ["Previous TODO set" org-agenda-todo-previousset t]
  2299. ["Add note" org-agenda-add-note t])
  2300. ("Archive/Refile/Delete"
  2301. ["Archive default" org-agenda-archive-default t]
  2302. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2303. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2304. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2305. ["Archive subtree" org-agenda-archive t]
  2306. "--"
  2307. ["Refile" org-agenda-refile t]
  2308. "--"
  2309. ["Delete subtree" org-agenda-kill t])
  2310. ("Bulk action"
  2311. ["Mark entry" org-agenda-bulk-mark t]
  2312. ["Mark all" org-agenda-bulk-mark-all t]
  2313. ["Unmark entry" org-agenda-bulk-unmark t]
  2314. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2315. ["Toggle mark" org-agenda-bulk-toggle t]
  2316. ["Toggle all" org-agenda-bulk-toggle-all t]
  2317. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2318. ["Act on all marked" org-agenda-bulk-action t]
  2319. "--"
  2320. ("Tags and Properties"
  2321. ["Show all Tags" org-agenda-show-tags t]
  2322. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2323. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2324. "--"
  2325. ["Column View" org-columns t])
  2326. ("Deadline/Schedule"
  2327. ["Schedule" org-agenda-schedule t]
  2328. ["Set Deadline" org-agenda-deadline t]
  2329. "--"
  2330. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2331. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2332. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2333. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2334. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2335. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2336. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2337. ("Clock and Effort"
  2338. ["Clock in" org-agenda-clock-in t]
  2339. ["Clock out" org-agenda-clock-out t]
  2340. ["Clock cancel" org-agenda-clock-cancel t]
  2341. ["Goto running clock" org-clock-goto t]
  2342. "--"
  2343. ["Set Effort" org-agenda-set-effort t]
  2344. ["Change clocked effort" org-clock-modify-effort-estimate
  2345. (org-clock-is-active)])
  2346. ("Priority"
  2347. ["Set Priority" org-agenda-priority t]
  2348. ["Increase Priority" org-agenda-priority-up t]
  2349. ["Decrease Priority" org-agenda-priority-down t]
  2350. ["Show Priority" org-priority-show t])
  2351. ("Calendar/Diary"
  2352. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2353. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2354. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2355. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2356. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2357. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2358. "--"
  2359. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2360. "--"
  2361. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2362. "--"
  2363. ("MobileOrg"
  2364. ["Push Files and Views" org-mobile-push t]
  2365. ["Get Captured and Flagged" org-mobile-pull t]
  2366. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2367. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2368. "--"
  2369. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2370. "--"
  2371. ["Quit" org-agenda-quit t]
  2372. ["Exit and Release Buffers" org-agenda-exit t]
  2373. ))
  2374. ;;; Agenda undo
  2375. (defvar org-agenda-allow-remote-undo t
  2376. "Non-nil means allow remote undo from the agenda buffer.")
  2377. (defvar org-agenda-undo-has-started-in nil
  2378. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2379. (defun org-agenda-undo ()
  2380. "Undo a remote editing step in the agenda.
  2381. This undoes changes both in the agenda buffer and in the remote buffer
  2382. that have been changed along."
  2383. (interactive)
  2384. (or org-agenda-allow-remote-undo
  2385. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2386. (when (not (eq this-command last-command))
  2387. (setq org-agenda-undo-has-started-in nil
  2388. org-agenda-pending-undo-list org-agenda-undo-list))
  2389. (when (not org-agenda-pending-undo-list)
  2390. (user-error "No further undo information"))
  2391. (let* ((entry (pop org-agenda-pending-undo-list))
  2392. buf line cmd rembuf)
  2393. (setq cmd (pop entry) line (pop entry))
  2394. (setq rembuf (nth 2 entry))
  2395. (org-with-remote-undo rembuf
  2396. (while (bufferp (setq buf (pop entry)))
  2397. (when (pop entry)
  2398. (with-current-buffer buf
  2399. (let (;; (last-undo-buffer buf)
  2400. (inhibit-read-only t))
  2401. (unless (memq buf org-agenda-undo-has-started-in)
  2402. (push buf org-agenda-undo-has-started-in)
  2403. (make-local-variable 'pending-undo-list)
  2404. (undo-start))
  2405. (while (and pending-undo-list
  2406. (listp pending-undo-list)
  2407. (not (car pending-undo-list)))
  2408. (pop pending-undo-list))
  2409. (undo-more 1))))))
  2410. (org-goto-line line)
  2411. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2412. (defun org-verify-change-for-undo (l1 l2)
  2413. "Verify that a real change occurred between the undo lists L1 and L2."
  2414. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2415. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2416. (not (eq l1 l2)))
  2417. ;;; Agenda dispatch
  2418. (defvar org-agenda-restrict-begin (make-marker))
  2419. (defvar org-agenda-restrict-end (make-marker))
  2420. (defvar org-agenda-last-dispatch-buffer nil)
  2421. (defvar org-agenda-overriding-restriction nil)
  2422. (defcustom org-agenda-custom-commands-contexts nil
  2423. "Alist of custom agenda keys and contextual rules.
  2424. For example, if you have a custom agenda command \"p\" and you
  2425. want this command to be accessible only from plain text files,
  2426. use this:
  2427. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2428. Here are the available contexts definitions:
  2429. in-file: command displayed only in matching files
  2430. in-mode: command displayed only in matching modes
  2431. not-in-file: command not displayed in matching files
  2432. not-in-mode: command not displayed in matching modes
  2433. in-buffer: command displayed only in matching buffers
  2434. not-in-buffer: command not displayed in matching buffers
  2435. [function]: a custom function taking no argument
  2436. If you define several checks, the agenda command will be
  2437. accessible if there is at least one valid check.
  2438. You can also bind a key to another agenda custom command
  2439. depending on contextual rules.
  2440. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2441. Here it means: in .txt files, use \"p\" as the key for the
  2442. agenda command otherwise associated with \"q\". (The command
  2443. originally associated with \"q\" is not displayed to avoid
  2444. duplicates.)"
  2445. :version "24.3"
  2446. :group 'org-agenda-custom-commands
  2447. :type '(repeat (list :tag "Rule"
  2448. (string :tag " Agenda key")
  2449. (string :tag "Replace by command")
  2450. (repeat :tag "Available when"
  2451. (choice
  2452. (cons :tag "Condition"
  2453. (choice
  2454. (const :tag "In file" in-file)
  2455. (const :tag "Not in file" not-in-file)
  2456. (const :tag "In buffer" in-buffer)
  2457. (const :tag "Not in buffer" not-in-buffer)
  2458. (const :tag "In mode" in-mode)
  2459. (const :tag "Not in mode" not-in-mode))
  2460. (regexp))
  2461. (function :tag "Custom function"))))))
  2462. (defcustom org-agenda-max-entries nil
  2463. "Maximum number of entries to display in an agenda.
  2464. This can be nil (no limit) or an integer or an alist of agenda
  2465. types with an associated number of entries to display in this
  2466. type."
  2467. :version "24.4"
  2468. :package-version '(Org . "8.0")
  2469. :group 'org-agenda-custom-commands
  2470. :type '(choice (symbol :tag "No limit" nil)
  2471. (integer :tag "Max number of entries")
  2472. (repeat
  2473. (cons (choice :tag "Agenda type"
  2474. (const agenda)
  2475. (const todo)
  2476. (const tags)
  2477. (const search))
  2478. (integer :tag "Max number of entries")))))
  2479. (defcustom org-agenda-max-todos nil
  2480. "Maximum number of TODOs to display in an agenda.
  2481. This can be nil (no limit) or an integer or an alist of agenda
  2482. types with an associated number of entries to display in this
  2483. type."
  2484. :version "24.4"
  2485. :package-version '(Org . "8.0")
  2486. :group 'org-agenda-custom-commands
  2487. :type '(choice (symbol :tag "No limit" nil)
  2488. (integer :tag "Max number of TODOs")
  2489. (repeat
  2490. (cons (choice :tag "Agenda type"
  2491. (const agenda)
  2492. (const todo)
  2493. (const tags)
  2494. (const search))
  2495. (integer :tag "Max number of TODOs")))))
  2496. (defcustom org-agenda-max-tags nil
  2497. "Maximum number of tagged entries to display in an agenda.
  2498. This can be nil (no limit) or an integer or an alist of agenda
  2499. types with an associated number of entries to display in this
  2500. type."
  2501. :version "24.4"
  2502. :package-version '(Org . "8.0")
  2503. :group 'org-agenda-custom-commands
  2504. :type '(choice (symbol :tag "No limit" nil)
  2505. (integer :tag "Max number of tagged entries")
  2506. (repeat
  2507. (cons (choice :tag "Agenda type"
  2508. (const agenda)
  2509. (const todo)
  2510. (const tags)
  2511. (const search))
  2512. (integer :tag "Max number of tagged entries")))))
  2513. (defcustom org-agenda-max-effort nil
  2514. "Maximum cumulated effort duration for the agenda.
  2515. This can be nil (no limit) or a number of minutes (as an integer)
  2516. or an alist of agenda types with an associated number of minutes
  2517. to limit entries to in this type."
  2518. :version "24.4"
  2519. :package-version '(Org . "8.0")
  2520. :group 'org-agenda-custom-commands
  2521. :type '(choice (symbol :tag "No limit" nil)
  2522. (integer :tag "Max number of minutes")
  2523. (repeat
  2524. (cons (choice :tag "Agenda type"
  2525. (const agenda)
  2526. (const todo)
  2527. (const tags)
  2528. (const search))
  2529. (integer :tag "Max number of minutes")))))
  2530. (defvar org-agenda-keep-restricted-file-list nil)
  2531. (defvar org-keys nil)
  2532. (defvar org-match nil)
  2533. ;;;###autoload
  2534. (defun org-agenda (&optional arg keys restriction)
  2535. "Dispatch agenda commands to collect entries to the agenda buffer.
  2536. Prompts for a command to execute. Any prefix arg will be passed
  2537. on to the selected command. The default selections are:
  2538. a Call `org-agenda-list' to display the agenda for current day or week.
  2539. t Call `org-todo-list' to display the global todo list.
  2540. T Call `org-todo-list' to display the global todo list, select only
  2541. entries with a specific TODO keyword (the user gets a prompt).
  2542. m Call `org-tags-view' to display headlines with tags matching
  2543. a condition (the user is prompted for the condition).
  2544. M Like `m', but select only TODO entries, no ordinary headlines.
  2545. e Export views to associated files.
  2546. s Search entries for keywords.
  2547. S Search entries for keywords, only with TODO keywords.
  2548. / Multi occur across all agenda files and also files listed
  2549. in `org-agenda-text-search-extra-files'.
  2550. < Restrict agenda commands to buffer, subtree, or region.
  2551. Press several times to get the desired effect.
  2552. > Remove a previous restriction.
  2553. # List \"stuck\" projects.
  2554. ! Configure what \"stuck\" means.
  2555. C Configure custom agenda commands.
  2556. More commands can be added by configuring the variable
  2557. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2558. searches can be pre-defined in this way.
  2559. If the current buffer is in Org mode and visiting a file, you can also
  2560. first press `<' once to indicate that the agenda should be temporarily
  2561. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2562. Pressing `<' twice means to restrict to the current subtree or region
  2563. \(if active)."
  2564. (interactive "P")
  2565. (catch 'exit
  2566. (let* ((org-keys keys)
  2567. (prefix-descriptions nil)
  2568. (org-agenda-buffer-name org-agenda-buffer-name)
  2569. (org-agenda-window-setup (if (equal (buffer-name)
  2570. org-agenda-buffer-name)
  2571. 'current-window
  2572. org-agenda-window-setup))
  2573. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2574. (org-agenda-custom-commands
  2575. ;; normalize different versions
  2576. (delq nil
  2577. (mapcar
  2578. (lambda (x)
  2579. (cond ((stringp (cdr x))
  2580. (push x prefix-descriptions)
  2581. nil)
  2582. ((stringp (nth 1 x)) x)
  2583. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2584. (t (cons (car x) (cons "" (cdr x))))))
  2585. org-agenda-custom-commands)))
  2586. (org-agenda-custom-commands
  2587. (org-contextualize-keys
  2588. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2589. ;; (buf (current-buffer))
  2590. (bfn (buffer-file-name (buffer-base-buffer)))
  2591. entry type org-match lprops ans) ;; key
  2592. ;; Turn off restriction unless there is an overriding one,
  2593. (unless org-agenda-overriding-restriction
  2594. (unless org-agenda-keep-restricted-file-list
  2595. ;; There is a request to keep the file list in place
  2596. (put 'org-agenda-files 'org-restrict nil))
  2597. (setq org-agenda-restrict nil)
  2598. (move-marker org-agenda-restrict-begin nil)
  2599. (move-marker org-agenda-restrict-end nil))
  2600. ;; Delete old local properties
  2601. (put 'org-agenda-redo-command 'org-lprops nil)
  2602. ;; Delete previously set last-arguments
  2603. (put 'org-agenda-redo-command 'last-args nil)
  2604. ;; Remember where this call originated
  2605. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2606. (unless org-keys
  2607. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2608. org-keys (car ans)
  2609. restriction (cdr ans)))
  2610. ;; If we have sticky agenda buffers, set a name for the buffer,
  2611. ;; depending on the invoking keys. The user may still set this
  2612. ;; as a command option, which will overwrite what we do here.
  2613. (when org-agenda-sticky
  2614. (setq org-agenda-buffer-name
  2615. (format "*Org Agenda(%s)*" org-keys)))
  2616. ;; Establish the restriction, if any
  2617. (when (and (not org-agenda-overriding-restriction) restriction)
  2618. (put 'org-agenda-files 'org-restrict (list bfn))
  2619. (cond
  2620. ((eq restriction 'region)
  2621. (setq org-agenda-restrict (current-buffer))
  2622. (move-marker org-agenda-restrict-begin (region-beginning))
  2623. (move-marker org-agenda-restrict-end (region-end)))
  2624. ((eq restriction 'subtree)
  2625. (save-excursion
  2626. (setq org-agenda-restrict (current-buffer))
  2627. (org-back-to-heading t)
  2628. (move-marker org-agenda-restrict-begin (point))
  2629. (move-marker org-agenda-restrict-end
  2630. (progn (org-end-of-subtree t)))))
  2631. ((and (eq restriction 'buffer)
  2632. (or (< 1 (point-min))
  2633. (< (point-max) (1+ (buffer-size)))))
  2634. (setq org-agenda-restrict (current-buffer))
  2635. (move-marker org-agenda-restrict-begin (point-min))
  2636. (move-marker org-agenda-restrict-end (point-max)))))
  2637. ;; For example the todo list should not need it (but does...)
  2638. (cond
  2639. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2640. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2641. (progn
  2642. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2643. ;; to some of the local variables? There's no doc about
  2644. ;; that for `org-agenda-custom-commands'.
  2645. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2646. lprops (nth 4 entry))
  2647. (when org-agenda-sticky
  2648. (setq org-agenda-buffer-name
  2649. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2650. (format "*Org Agenda(%s)*" org-keys))))
  2651. (put 'org-agenda-redo-command 'org-lprops lprops)
  2652. (cl-progv
  2653. (mapcar #'car lprops)
  2654. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2655. (pcase type
  2656. (`agenda
  2657. (org-agenda-list current-prefix-arg))
  2658. (`agenda*
  2659. (org-agenda-list current-prefix-arg nil nil t))
  2660. (`alltodo
  2661. (org-todo-list current-prefix-arg))
  2662. (`search
  2663. (org-search-view current-prefix-arg org-match nil))
  2664. (`stuck
  2665. (org-agenda-list-stuck-projects current-prefix-arg))
  2666. (`tags
  2667. (org-tags-view current-prefix-arg org-match))
  2668. (`tags-todo
  2669. (org-tags-view '(4) org-match))
  2670. (`todo
  2671. (org-todo-list org-match))
  2672. (`tags-tree
  2673. (org-check-for-org-mode)
  2674. (org-match-sparse-tree current-prefix-arg org-match))
  2675. (`todo-tree
  2676. (org-check-for-org-mode)
  2677. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2678. (regexp-quote org-match) "\\>")))
  2679. (`occur-tree
  2680. (org-check-for-org-mode)
  2681. (org-occur org-match))
  2682. ((pred functionp)
  2683. (funcall type org-match))
  2684. ;; FIXME: Will signal an error since it's not `functionp'!
  2685. ((pred fboundp) (funcall type org-match))
  2686. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2687. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2688. ((equal org-keys "C")
  2689. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2690. (customize-variable 'org-agenda-custom-commands))
  2691. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2692. ((equal org-keys "s") (call-interactively 'org-search-view))
  2693. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2694. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2695. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2696. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2697. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2698. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2699. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2700. (add-hook
  2701. 'post-command-hook
  2702. (lambda ()
  2703. (unless (current-message)
  2704. (let* ((m (org-agenda-get-any-marker))
  2705. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2706. (when note
  2707. (message "FLAGGING-NOTE ([?] for more info): %s"
  2708. (org-add-props
  2709. (replace-regexp-in-string
  2710. "\\\\n" "//"
  2711. (copy-sequence note))
  2712. nil 'face 'org-warning))))))
  2713. t t))
  2714. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2715. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2716. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2717. (t (user-error "Invalid agenda key"))))))
  2718. (defvar org-agenda-multi)
  2719. (defun org-agenda-append-agenda ()
  2720. "Append another agenda view to the current one.
  2721. This function allows interactive building of block agendas.
  2722. Agenda views are separated by `org-agenda-block-separator'."
  2723. (interactive)
  2724. (unless (derived-mode-p 'org-agenda-mode)
  2725. (user-error "Can only append from within agenda buffer"))
  2726. (let ((org-agenda-multi t))
  2727. (org-agenda)
  2728. (widen)
  2729. (org-agenda-finalize)
  2730. (setq buffer-read-only t)
  2731. (org-agenda-fit-window-to-buffer)))
  2732. (defun org-agenda-normalize-custom-commands (cmds)
  2733. "Normalize custom commands CMDS."
  2734. (delq nil
  2735. (mapcar
  2736. (lambda (x)
  2737. (cond ((stringp (cdr x)) nil)
  2738. ((stringp (nth 1 x)) x)
  2739. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2740. (t (cons (car x) (cons "" (cdr x))))))
  2741. cmds)))
  2742. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2743. "The user interface for selecting an agenda command."
  2744. (catch 'exit
  2745. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2746. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2747. (region-p (org-region-active-p))
  2748. (custom org-agenda-custom-commands)
  2749. (selstring "")
  2750. restriction second-time
  2751. c entry key type match prefixes rmheader header-end custom1 desc
  2752. line lines left right n n1)
  2753. (save-window-excursion
  2754. (delete-other-windows)
  2755. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2756. (erase-buffer)
  2757. (insert (eval-when-compile
  2758. (let ((header
  2759. (copy-sequence
  2760. "Press key for an agenda command:
  2761. -------------------------------- < Buffer, subtree/region restriction
  2762. a Agenda for current week or day > Remove restriction
  2763. t List of all TODO entries e Export agenda views
  2764. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2765. s Search for keywords M Like m, but only TODO entries
  2766. / Multi-occur S Like s, but only TODO entries
  2767. ? Find :FLAGGED: entries C Configure custom agenda commands
  2768. * Toggle sticky agenda views # List stuck projects (!=configure)
  2769. "))
  2770. (start 0))
  2771. (while (string-match
  2772. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2773. header start)
  2774. (setq start (match-end 0))
  2775. (add-text-properties (match-beginning 2) (match-end 2)
  2776. '(face bold) header))
  2777. header)))
  2778. (setq header-end (point-marker))
  2779. (while t
  2780. (setq custom1 custom)
  2781. (when (eq rmheader t)
  2782. (org-goto-line 1)
  2783. (re-search-forward ":" nil t)
  2784. (delete-region (match-end 0) (point-at-eol))
  2785. (forward-char 1)
  2786. (looking-at "-+")
  2787. (delete-region (match-end 0) (point-at-eol))
  2788. (move-marker header-end (match-end 0)))
  2789. (goto-char header-end)
  2790. (delete-region (point) (point-max))
  2791. ;; Produce all the lines that describe custom commands and prefixes
  2792. (setq lines nil)
  2793. (while (setq entry (pop custom1))
  2794. (setq key (car entry) desc (nth 1 entry)
  2795. type (nth 2 entry)
  2796. match (nth 3 entry))
  2797. (if (> (length key) 1)
  2798. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2799. (setq line
  2800. (format
  2801. "%-4s%-14s"
  2802. (org-add-props (copy-sequence key)
  2803. '(face bold))
  2804. (cond
  2805. ((string-match "\\S-" desc) desc)
  2806. ((eq type 'agenda) "Agenda for current week or day")
  2807. ((eq type 'agenda*) "Appointments for current week or day")
  2808. ((eq type 'alltodo) "List of all TODO entries")
  2809. ((eq type 'search) "Word search")
  2810. ((eq type 'stuck) "List of stuck projects")
  2811. ((eq type 'todo) "TODO keyword")
  2812. ((eq type 'tags) "Tags query")
  2813. ((eq type 'tags-todo) "Tags (TODO)")
  2814. ((eq type 'tags-tree) "Tags tree")
  2815. ((eq type 'todo-tree) "TODO kwd tree")
  2816. ((eq type 'occur-tree) "Occur tree")
  2817. ((functionp type) (if (symbolp type)
  2818. (symbol-name type)
  2819. "Lambda expression"))
  2820. (t "???"))))
  2821. (cond
  2822. ((not (org-string-nw-p match)) nil)
  2823. (org-agenda-menu-show-matcher
  2824. (setq line
  2825. (concat line ": "
  2826. (cond
  2827. ((stringp match)
  2828. (propertize match 'face 'org-warning))
  2829. ((listp type)
  2830. (format "set of %d commands" (length type)))))))
  2831. (t
  2832. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2833. (push line lines)))
  2834. (setq lines (nreverse lines))
  2835. (when prefixes
  2836. (mapc (lambda (x)
  2837. (push
  2838. (format "%s %s"
  2839. (org-add-props (char-to-string x)
  2840. nil 'face 'bold)
  2841. (or (cdr (assoc (concat selstring
  2842. (char-to-string x))
  2843. prefix-descriptions))
  2844. "Prefix key"))
  2845. lines))
  2846. prefixes))
  2847. ;; Check if we should display in two columns
  2848. (if org-agenda-menu-two-columns
  2849. (progn
  2850. (setq n (length lines)
  2851. n1 (+ (/ n 2) (mod n 2))
  2852. right (nthcdr n1 lines)
  2853. left (copy-sequence lines))
  2854. (setcdr (nthcdr (1- n1) left) nil))
  2855. (setq left lines right nil))
  2856. (while left
  2857. (insert "\n" (pop left))
  2858. (when right
  2859. (if (< (current-column) 40)
  2860. (move-to-column 40 t)
  2861. (insert " "))
  2862. (insert (pop right))))
  2863. ;; Make the window the right size
  2864. (goto-char (point-min))
  2865. (if second-time
  2866. (when (not (pos-visible-in-window-p (point-max)))
  2867. (org-fit-window-to-buffer))
  2868. (setq second-time t)
  2869. (org-fit-window-to-buffer))
  2870. ;; Hint to navigation if window too small for all information
  2871. (setq header-line-format
  2872. (when (not (pos-visible-in-window-p (point-max)))
  2873. "Use C-v, M-v, C-n or C-p to navigate."))
  2874. ;; Ask for selection
  2875. (cl-loop
  2876. do (progn
  2877. (message "Press key for agenda command%s:"
  2878. (if (or restrict-ok org-agenda-overriding-restriction)
  2879. (if org-agenda-overriding-restriction
  2880. " (restriction lock active)"
  2881. (if restriction
  2882. (format " (restricted to %s)" restriction)
  2883. " (unrestricted)"))
  2884. ""))
  2885. (setq c (read-char-exclusive)))
  2886. until (not (memq c '(14 16 22 134217846)))
  2887. do (org-scroll c))
  2888. (message "")
  2889. (cond
  2890. ((assoc (char-to-string c) custom)
  2891. (setq selstring (concat selstring (char-to-string c)))
  2892. (throw 'exit (cons selstring restriction)))
  2893. ((memq c prefixes)
  2894. (setq selstring (concat selstring (char-to-string c))
  2895. prefixes nil
  2896. rmheader (or rmheader t)
  2897. custom (delq nil (mapcar
  2898. (lambda (x)
  2899. (if (or (= (length (car x)) 1)
  2900. (/= (string-to-char (car x)) c))
  2901. nil
  2902. (cons (substring (car x) 1) (cdr x))))
  2903. custom))))
  2904. ((eq c ?*)
  2905. (call-interactively 'org-toggle-sticky-agenda)
  2906. (sit-for 2))
  2907. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2908. (message "Restriction is only possible in Org buffers")
  2909. (ding) (sit-for 1))
  2910. ((eq c ?1)
  2911. (org-agenda-remove-restriction-lock 'noupdate)
  2912. (setq restriction 'buffer))
  2913. ((eq c ?0)
  2914. (org-agenda-remove-restriction-lock 'noupdate)
  2915. (setq restriction (if region-p 'region 'subtree)))
  2916. ((eq c ?<)
  2917. (org-agenda-remove-restriction-lock 'noupdate)
  2918. (setq restriction
  2919. (cond
  2920. ((eq restriction 'buffer)
  2921. (if region-p 'region 'subtree))
  2922. ((memq restriction '(subtree region))
  2923. nil)
  2924. (t 'buffer))))
  2925. ((eq c ?>)
  2926. (org-agenda-remove-restriction-lock 'noupdate)
  2927. (setq restriction nil))
  2928. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2929. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2930. ((and (> (length selstring) 0) (eq c ?\d))
  2931. (delete-window)
  2932. (org-agenda-get-restriction-and-command prefix-descriptions))
  2933. ((equal c ?q) (user-error "Abort"))
  2934. (t (user-error "Invalid key %c" c))))))))
  2935. (defun org-agenda-fit-window-to-buffer ()
  2936. "Fit the window to the buffer size."
  2937. (and (memq org-agenda-window-setup '(reorganize-frame))
  2938. (fboundp 'fit-window-to-buffer)
  2939. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2940. (= (car org-agenda-window-frame-fractions) 1.0))
  2941. (delete-other-windows)
  2942. (org-fit-window-to-buffer
  2943. nil
  2944. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2945. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2946. (defvar org-cmd nil)
  2947. (defvar org-agenda-overriding-cmd nil)
  2948. (defvar org-agenda-overriding-arguments nil)
  2949. (defvar org-agenda-overriding-cmd-arguments nil)
  2950. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2951. (declare (indent 1) (obsolete cl-progv "2021"))
  2952. (eval (cons 'let (cons list body))))
  2953. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2954. (declare (indent 2) (obsolete cl-progv "2021"))
  2955. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2956. (defun org-agenda-run-series (name series)
  2957. "Run agenda NAME as a SERIES of agenda commands."
  2958. (let* ((gprops (nth 1 series))
  2959. (gvars (mapcar #'car gprops))
  2960. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2961. (cl-progv gvars gvals (org-agenda-prepare name))
  2962. ;; We need to reset agenda markers here, because when constructing a
  2963. ;; block agenda, the individual blocks do not do that.
  2964. (org-agenda-reset-markers)
  2965. (with-no-warnings
  2966. (defvar match)) ;Used via the `eval' below.
  2967. (let* ((org-agenda-multi t)
  2968. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2969. ;; than expressions, so you don't need to `quote' the args
  2970. ;; and you just need to `apply' instead of `eval' when using it.
  2971. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2972. (cmds (car series))
  2973. match
  2974. org-cmd type lprops)
  2975. (while (setq org-cmd (pop cmds))
  2976. (setq type (car org-cmd))
  2977. (setq match (eval (nth 1 org-cmd) t))
  2978. (setq lprops (nth 2 org-cmd))
  2979. (let ((org-agenda-overriding-arguments
  2980. (if (eq org-agenda-overriding-cmd org-cmd)
  2981. (or org-agenda-overriding-arguments
  2982. org-agenda-overriding-cmd-arguments)))
  2983. (lvars (mapcar #'car lprops))
  2984. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  2985. (cl-progv (append gvars lvars) (append gvals lvals)
  2986. (pcase type
  2987. (`agenda
  2988. (call-interactively 'org-agenda-list))
  2989. (`agenda*
  2990. (funcall 'org-agenda-list nil nil t))
  2991. (`alltodo
  2992. (call-interactively 'org-todo-list))
  2993. (`search
  2994. (org-search-view current-prefix-arg match nil))
  2995. (`stuck
  2996. (call-interactively 'org-agenda-list-stuck-projects))
  2997. (`tags
  2998. (org-tags-view current-prefix-arg match))
  2999. (`tags-todo
  3000. (org-tags-view '(4) match))
  3001. (`todo
  3002. (org-todo-list match))
  3003. ((pred fboundp)
  3004. (funcall type match))
  3005. (_ (error "Invalid type in command series"))))))
  3006. (widen)
  3007. (let ((inhibit-read-only t))
  3008. (add-text-properties (point-min) (point-max)
  3009. `(org-series t org-series-redo-cmd ,redo)))
  3010. (setq org-agenda-redo-command redo)
  3011. (goto-char (point-min)))
  3012. (org-agenda-fit-window-to-buffer)
  3013. (cl-progv gvars gvals (org-agenda-finalize))))
  3014. (defun org-agenda--split-plist (plist)
  3015. ;; We could/should arguably use `map-keys' and `map-values'.
  3016. (let (keys vals)
  3017. (while plist
  3018. (push (pop plist) keys)
  3019. (push (pop plist) vals))
  3020. (cons (nreverse keys) (nreverse vals))))
  3021. ;;;###autoload
  3022. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3023. "Run an agenda command in batch mode and send the result to STDOUT.
  3024. If CMD-KEY is a string of length 1, it is used as a key in
  3025. `org-agenda-custom-commands' and triggers this command. If it is a
  3026. longer string it is used as a tags/todo match string.
  3027. Parameters are alternating variable names and values that will be bound
  3028. before running the agenda command."
  3029. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3030. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3031. (defun org--batch-agenda (cmd-key vars vals)
  3032. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3033. ;; a variable name rather than an expression to evaluate. Yuck!
  3034. (cl-progv vars vals
  3035. (let (org-agenda-sticky)
  3036. (if (> (length cmd-key) 1)
  3037. (org-tags-view nil cmd-key)
  3038. (org-agenda nil cmd-key))))
  3039. (set-buffer org-agenda-buffer-name)
  3040. (princ (buffer-string)))
  3041. (defvar org-agenda-info nil)
  3042. ;;;###autoload
  3043. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3044. "Run an agenda command in batch mode and send the result to STDOUT.
  3045. If CMD-KEY is a string of length 1, it is used as a key in
  3046. `org-agenda-custom-commands' and triggers this command. If it is a
  3047. longer string it is used as a tags/todo match string.
  3048. Parameters are alternating variable names and values that will be bound
  3049. before running the agenda command.
  3050. The output gives a line for each selected agenda item. Each
  3051. item is a list of comma-separated values, like this:
  3052. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3053. category The category of the item
  3054. head The headline, without TODO kwd, TAGS and PRIORITY
  3055. type The type of the agenda entry, can be
  3056. todo selected in TODO match
  3057. tagsmatch selected in tags match
  3058. diary imported from diary
  3059. deadline a deadline on given date
  3060. scheduled scheduled on given date
  3061. timestamp entry has timestamp on given date
  3062. closed entry was closed on given date
  3063. upcoming-deadline warning about deadline
  3064. past-scheduled forwarded scheduled item
  3065. block entry has date block including g. date
  3066. todo The todo keyword, if any
  3067. tags All tags including inherited ones, separated by colons
  3068. date The relevant date, like 2007-2-14
  3069. time The time, like 15:00-16:50
  3070. extra String with extra planning info
  3071. priority-l The priority letter if any was given
  3072. priority-n The computed numerical priority
  3073. agenda-day The day in the agenda where this is listed"
  3074. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3075. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3076. (defun org--batch-agenda-csv (cmd-key vars vals)
  3077. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3078. ;; a variable name rather than an expression to evaluate. Yuck!
  3079. (let ((org-agenda-remove-tags t))
  3080. (cl-progv vars vals
  3081. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3082. (if (> (length cmd-key) 2)
  3083. (org-tags-view nil cmd-key)
  3084. (org-agenda nil cmd-key))))
  3085. (set-buffer org-agenda-buffer-name)
  3086. (let ((lines (org-split-string (buffer-string) "\n")))
  3087. (dolist (line lines)
  3088. (when (get-text-property 0 'org-category line)
  3089. (setq org-agenda-info
  3090. (org-fix-agenda-info (text-properties-at 0 line)))
  3091. (princ
  3092. (mapconcat #'org-agenda-export-csv-mapper
  3093. '(org-category txt type todo tags date time extra
  3094. priority-letter priority agenda-day)
  3095. ","))
  3096. (princ "\n")))))
  3097. (defun org-fix-agenda-info (props)
  3098. "Make sure all properties on an agenda item have a canonical form.
  3099. This ensures the export commands can easily use it."
  3100. (let (tmp re)
  3101. (when (setq tmp (plist-get props 'tags))
  3102. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3103. (when (setq tmp (plist-get props 'date))
  3104. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3105. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3106. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3107. (setq tmp (calendar-date-string tmp)))
  3108. (setq props (plist-put props 'date tmp)))
  3109. (when (setq tmp (plist-get props 'day))
  3110. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3111. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3112. (setq tmp (calendar-date-string tmp)))
  3113. (setq props (plist-put props 'day tmp))
  3114. (setq props (plist-put props 'agenda-day tmp)))
  3115. (when (setq tmp (plist-get props 'txt))
  3116. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3117. (plist-put props 'priority-letter (match-string 1 tmp))
  3118. (setq tmp (replace-match "" t t tmp)))
  3119. (when (and (setq re (plist-get props 'org-todo-regexp))
  3120. (setq re (concat "\\`\\.*" re " ?"))
  3121. (let ((case-fold-search nil)) (string-match re tmp)))
  3122. (plist-put props 'todo (match-string 1 tmp))
  3123. (setq tmp (replace-match "" t t tmp)))
  3124. (plist-put props 'txt tmp)))
  3125. props)
  3126. (defun org-agenda-export-csv-mapper (prop)
  3127. (let ((res (plist-get org-agenda-info prop)))
  3128. (setq res
  3129. (cond
  3130. ((not res) "")
  3131. ((stringp res) res)
  3132. (t (prin1-to-string res))))
  3133. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3134. ;;;###autoload
  3135. (defun org-store-agenda-views (&rest _parameters)
  3136. "Store agenda views."
  3137. (interactive)
  3138. (org--batch-store-agenda-views nil nil))
  3139. ;;;###autoload
  3140. (defmacro org-batch-store-agenda-views (&rest parameters)
  3141. "Run all custom agenda commands that have a file argument."
  3142. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3143. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3144. (defun org--batch-store-agenda-views (vars vals)
  3145. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3146. (pop-up-frames nil)
  3147. (dir default-directory)
  3148. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3149. (save-window-excursion
  3150. (while cmds
  3151. (setq cmd (pop cmds)
  3152. thiscmdkey (car cmd)
  3153. thiscmdcmd (cdr cmd)
  3154. match (nth 2 thiscmdcmd)
  3155. bufname (if org-agenda-sticky
  3156. (or (and (stringp match)
  3157. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3158. (format "*Org Agenda(%s)*" thiscmdkey))
  3159. org-agenda-buffer-name)
  3160. cmd-or-set (nth 2 cmd)
  3161. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3162. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3163. (if (stringp files) (setq files (list files)))
  3164. (when files
  3165. (let* ((opts (append org-agenda-exporter-settings opts))
  3166. (vars (append (mapcar #'car opts) vars))
  3167. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3168. opts)
  3169. vals)))
  3170. (cl-progv vars vals
  3171. (org-agenda nil thiscmdkey))
  3172. (set-buffer bufname)
  3173. (while files
  3174. (cl-progv vars vals
  3175. (org-agenda-write (expand-file-name (pop files) dir)
  3176. nil t bufname))))
  3177. (and (get-buffer bufname)
  3178. (kill-buffer bufname)))))))
  3179. (defvar org-agenda-current-span nil
  3180. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3181. (defun org-agenda-mark-header-line (pos)
  3182. "Mark the line at POS as an agenda structure header."
  3183. (save-excursion
  3184. (goto-char pos)
  3185. (put-text-property (point-at-bol) (point-at-eol)
  3186. 'org-agenda-structural-header t)
  3187. (when org-agenda-title-append
  3188. (put-text-property (point-at-bol) (point-at-eol)
  3189. 'org-agenda-title-append org-agenda-title-append))))
  3190. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3191. (defvar org-agenda-write-buffer-name "Agenda View")
  3192. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3193. "Write the current buffer (an agenda view) as a file.
  3194. Depending on the extension of the file name, plain text (.txt),
  3195. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3196. If the extension is .ics, translate visible agenda into iCalendar
  3197. format. If the extension is .org, collect all subtrees
  3198. corresponding to the agenda entries and add them in an .org file.
  3199. With prefix argument OPEN, open the new file immediately. If
  3200. NOSETTINGS is given, do not scope the settings of
  3201. `org-agenda-exporter-settings' into the export commands. This is
  3202. used when the settings have already been scoped and we do not
  3203. wish to overrule other, higher priority settings. If
  3204. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3205. the agenda to write."
  3206. (interactive "FWrite agenda to file: \nP")
  3207. (if (or (not (file-writable-p file))
  3208. (and (file-exists-p file)
  3209. (if (called-interactively-p 'any)
  3210. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3211. (user-error "Cannot write agenda to file %s" file))
  3212. (cl-progv
  3213. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3214. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3215. org-agenda-exporter-settings))
  3216. (save-excursion
  3217. (save-window-excursion
  3218. (let ((bs (copy-sequence (buffer-string)))
  3219. (extension (file-name-extension file))
  3220. (default-directory (file-name-directory file))
  3221. ) ;; beg content
  3222. (with-temp-buffer
  3223. (rename-buffer org-agenda-write-buffer-name t)
  3224. (set-buffer-modified-p nil)
  3225. (insert bs)
  3226. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3227. (run-hooks 'org-agenda-before-write-hook)
  3228. (cond
  3229. ((bound-and-true-p org-mobile-creating-agendas)
  3230. (org-mobile-write-agenda-for-mobile file))
  3231. ((string= "org" extension)
  3232. (let (content p m message-log-max)
  3233. (goto-char (point-min))
  3234. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3235. (goto-char p)
  3236. (setq m (get-text-property (point) 'org-hd-marker))
  3237. (when m
  3238. (push (with-current-buffer (marker-buffer m)
  3239. (goto-char m)
  3240. (org-copy-subtree 1 nil t t)
  3241. org-subtree-clip)
  3242. content)))
  3243. (find-file file)
  3244. (erase-buffer)
  3245. (dolist (s content) (org-paste-subtree 1 s))
  3246. (write-file file)
  3247. (kill-buffer (current-buffer))
  3248. (message "Org file written to %s" file)))
  3249. ((member extension '("html" "htm"))
  3250. (or (require 'htmlize nil t)
  3251. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3252. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3253. (set-buffer (htmlize-buffer (current-buffer)))
  3254. (when org-agenda-export-html-style
  3255. ;; replace <style> section with org-agenda-export-html-style
  3256. (goto-char (point-min))
  3257. (kill-region (- (search-forward "<style") 6)
  3258. (search-forward "</style>"))
  3259. (insert org-agenda-export-html-style))
  3260. (write-file file)
  3261. (kill-buffer (current-buffer))
  3262. (message "HTML written to %s" file))
  3263. ((string= "ps" extension)
  3264. (require 'ps-print)
  3265. (ps-print-buffer-with-faces file)
  3266. (message "Postscript written to %s" file))
  3267. ((string= "pdf" extension)
  3268. (require 'ps-print)
  3269. (ps-print-buffer-with-faces
  3270. (concat (file-name-sans-extension file) ".ps"))
  3271. (call-process "ps2pdf" nil nil nil
  3272. (expand-file-name
  3273. (concat (file-name-sans-extension file) ".ps"))
  3274. (expand-file-name file))
  3275. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3276. (message "PDF written to %s" file))
  3277. ((string= "ics" extension)
  3278. (require 'ox-icalendar)
  3279. (declare-function org-icalendar-export-current-agenda
  3280. "ox-icalendar" (file))
  3281. (org-icalendar-export-current-agenda (expand-file-name file)))
  3282. (t
  3283. (let ((bs (buffer-string)))
  3284. (find-file file)
  3285. (erase-buffer)
  3286. (insert bs)
  3287. (save-buffer 0)
  3288. (kill-buffer (current-buffer))
  3289. (message "Plain text written to %s" file))))))))
  3290. (set-buffer (or agenda-bufname
  3291. ;; FIXME: I'm pretty sure called-interactively-p
  3292. ;; doesn't do what we want here!
  3293. (and (called-interactively-p 'any) (buffer-name))
  3294. org-agenda-buffer-name)))
  3295. (when open (org-open-file file)))
  3296. (defun org-agenda-remove-marked-text (property &optional value)
  3297. "Delete all text marked with VALUE of PROPERTY.
  3298. VALUE defaults to t."
  3299. (let (beg)
  3300. (setq value (or value t))
  3301. (while (setq beg (text-property-any (point-min) (point-max)
  3302. property value))
  3303. (delete-region
  3304. beg (or (next-single-property-change beg property)
  3305. (point-max))))))
  3306. (defun org-agenda-add-entry-text ()
  3307. "Add entry text to agenda lines.
  3308. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3309. entry text following headings shown in the agenda.
  3310. Drawers will be excluded, also the line with scheduling/deadline info."
  3311. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3312. (not (bound-and-true-p org-mobile-creating-agendas)))
  3313. (let (m txt)
  3314. (goto-char (point-min))
  3315. (while (not (eobp))
  3316. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3317. (beginning-of-line 2)
  3318. (setq txt (org-agenda-get-some-entry-text
  3319. m org-agenda-add-entry-text-maxlines " > "))
  3320. (end-of-line 1)
  3321. (if (string-match "\\S-" txt)
  3322. (insert "\n" txt)
  3323. (or (eobp) (forward-char 1))))))))
  3324. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3325. &rest keep)
  3326. "Extract entry text from MARKER, at most N-LINES lines.
  3327. This will ignore drawers etc, just get the text.
  3328. If INDENT is given, prefix every line with this string. If KEEP is
  3329. given, it is a list of symbols, defining stuff that should not be
  3330. removed from the entry content. Currently only `planning' is allowed here."
  3331. (let (txt drawer-re kwd-time-re ind)
  3332. (save-excursion
  3333. (with-current-buffer (marker-buffer marker)
  3334. (if (not (derived-mode-p 'org-mode))
  3335. (setq txt "")
  3336. (org-with-wide-buffer
  3337. (goto-char marker)
  3338. (end-of-line 1)
  3339. (setq txt (buffer-substring
  3340. (min (1+ (point)) (point-max))
  3341. (progn (outline-next-heading) (point)))
  3342. drawer-re org-drawer-regexp
  3343. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3344. ".*\n?"))
  3345. (with-temp-buffer
  3346. (insert txt)
  3347. (when org-agenda-add-entry-text-descriptive-links
  3348. (goto-char (point-min))
  3349. (while (org-activate-links (point-max))
  3350. (goto-char (match-end 0))))
  3351. (goto-char (point-min))
  3352. (while (re-search-forward org-link-bracket-re (point-max) t)
  3353. (set-text-properties (match-beginning 0) (match-end 0)
  3354. nil))
  3355. (goto-char (point-min))
  3356. (while (re-search-forward drawer-re nil t)
  3357. (delete-region
  3358. (match-beginning 0)
  3359. (progn (re-search-forward
  3360. "^[ \t]*:END:.*\n?" nil 'move)
  3361. (point))))
  3362. (unless (member 'planning keep)
  3363. (goto-char (point-min))
  3364. (while (re-search-forward kwd-time-re nil t)
  3365. (replace-match "")))
  3366. (goto-char (point-min))
  3367. (when org-agenda-entry-text-exclude-regexps
  3368. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3369. (while (setq re (pop re-list))
  3370. (goto-char (point-min))
  3371. (while (re-search-forward re nil t)
  3372. (replace-match "")))))
  3373. (goto-char (point-max))
  3374. (skip-chars-backward " \t\n")
  3375. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3376. ;; find and remove min common indentation
  3377. (goto-char (point-min))
  3378. (untabify (point-min) (point-max))
  3379. (setq ind (current-indentation))
  3380. (while (not (eobp))
  3381. (unless (looking-at "[ \t]*$")
  3382. (setq ind (min ind (current-indentation))))
  3383. (beginning-of-line 2))
  3384. (goto-char (point-min))
  3385. (while (not (eobp))
  3386. (unless (looking-at "[ \t]*$")
  3387. (move-to-column ind)
  3388. (delete-region (point-at-bol) (point)))
  3389. (beginning-of-line 2))
  3390. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3391. (goto-char (point-min))
  3392. (when indent
  3393. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3394. (replace-match indent t t)))
  3395. (goto-char (point-min))
  3396. (while (looking-at "[ \t]*\n") (replace-match ""))
  3397. (goto-char (point-max))
  3398. (when (> (org-current-line)
  3399. n-lines)
  3400. (org-goto-line (1+ n-lines))
  3401. (backward-char 1))
  3402. (setq txt (buffer-substring (point-min) (point))))))))
  3403. txt))
  3404. (defun org-check-for-org-mode ()
  3405. "Make sure current buffer is in Org mode. Error if not."
  3406. (or (derived-mode-p 'org-mode)
  3407. (error "Cannot execute Org agenda command on buffer in %s"
  3408. major-mode)))
  3409. ;;; Agenda prepare and finalize
  3410. (defvar org-agenda-multi nil) ; dynamically scoped
  3411. (defvar org-agenda-pre-window-conf nil)
  3412. (defvar org-agenda-columns-active nil)
  3413. (defvar org-agenda-name nil)
  3414. (defvar org-agenda-tag-filter nil)
  3415. (defvar org-agenda-category-filter nil)
  3416. (defvar org-agenda-regexp-filter nil)
  3417. (defvar org-agenda-effort-filter nil)
  3418. (defvar org-agenda-top-headline-filter nil)
  3419. (defvar org-agenda-represented-categories nil
  3420. "Cache for the list of all categories in the agenda.")
  3421. (defvar org-agenda-represented-tags nil
  3422. "Cache for the list of all categories in the agenda.")
  3423. (defvar org-agenda-tag-filter-preset nil
  3424. "A preset of the tags filter used for secondary agenda filtering.
  3425. This must be a list of strings, each string must be a single tag preceded
  3426. by \"+\" or \"-\".
  3427. This variable should not be set directly, but agenda custom commands can
  3428. bind it in the options section. The preset filter is a global property of
  3429. the entire agenda view. In a block agenda, it will not work reliably to
  3430. define a filter for one of the individual blocks. You need to set it in
  3431. the global options and expect it to be applied to the entire view.")
  3432. (defconst org-agenda-filter-variables
  3433. '((category . org-agenda-category-filter)
  3434. (tag . org-agenda-tag-filter)
  3435. (effort . org-agenda-effort-filter)
  3436. (regexp . org-agenda-regexp-filter))
  3437. "Alist of filter types and associated variables.")
  3438. (defun org-agenda-filter-any ()
  3439. "Is any filter active?"
  3440. (cl-some (lambda (x)
  3441. (or (symbol-value (cdr x))
  3442. (get :preset-filter x)))
  3443. org-agenda-filter-variables))
  3444. (defvar org-agenda-category-filter-preset nil
  3445. "A preset of the category filter used for secondary agenda filtering.
  3446. This must be a list of strings, each string must be a single category
  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. (defvar org-agenda-regexp-filter-preset nil
  3454. "A preset of the regexp filter used for secondary agenda filtering.
  3455. This must be a list of strings, each string must be a single regexp
  3456. preceded by \"+\" or \"-\".
  3457. This variable should not be set directly, but agenda custom commands can
  3458. bind it in the options section. The preset filter is a global property of
  3459. the entire agenda view. In a block agenda, it will not work reliably to
  3460. define a filter for one of the individual blocks. You need to set it in
  3461. the global options and expect it to be applied to the entire view.")
  3462. (defvar org-agenda-effort-filter-preset nil
  3463. "A preset of the effort condition used for secondary agenda filtering.
  3464. This must be a list of strings, each string must be a single regexp
  3465. preceded by \"+\" or \"-\".
  3466. This variable should not be set directly, but agenda custom commands can
  3467. bind it in the options section. The preset filter is a global property of
  3468. the entire agenda view. In a block agenda, it will not work reliably to
  3469. define a filter for one of the individual blocks. You need to set it in
  3470. the global options and expect it to be applied to the entire view.")
  3471. (defun org-agenda-use-sticky-p ()
  3472. "Return non-nil if an agenda buffer named
  3473. `org-agenda-buffer-name' exists and should be shown instead of
  3474. generating a new one."
  3475. (and
  3476. ;; turned off by user
  3477. org-agenda-sticky
  3478. ;; For multi-agenda buffer already exists
  3479. (not org-agenda-multi)
  3480. ;; buffer found
  3481. (get-buffer org-agenda-buffer-name)
  3482. ;; C-u parameter is same as last call
  3483. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3484. (and
  3485. (equal current-prefix-arg
  3486. org-agenda-last-prefix-arg)
  3487. ;; In case user turned stickiness on, while having existing
  3488. ;; Agenda buffer active, don't reuse that buffer, because it
  3489. ;; does not have org variables local
  3490. org-agenda-this-buffer-is-sticky))))
  3491. (defvar org-agenda-buffer-tmp-name nil)
  3492. (defun org-agenda--get-buffer-name (sticky-name)
  3493. (or org-agenda-buffer-tmp-name
  3494. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3495. sticky-name
  3496. "*Org Agenda*"))
  3497. (defun org-agenda-prepare-window (abuf filter-alist)
  3498. "Setup agenda buffer in the window.
  3499. ABUF is the buffer for the agenda window.
  3500. FILTER-ALIST is an alist of filters we need to apply when
  3501. `org-agenda-persistent-filter' is non-nil."
  3502. (let* ((awin (get-buffer-window abuf)) wconf)
  3503. (cond
  3504. ((equal (current-buffer) abuf) nil)
  3505. (awin (select-window awin))
  3506. ((not (setq wconf (current-window-configuration))))
  3507. ((eq org-agenda-window-setup 'current-window)
  3508. (pop-to-buffer-same-window abuf))
  3509. ((eq org-agenda-window-setup 'other-window)
  3510. (org-switch-to-buffer-other-window abuf))
  3511. ((eq org-agenda-window-setup 'other-frame)
  3512. (switch-to-buffer-other-frame abuf))
  3513. ((eq org-agenda-window-setup 'other-tab)
  3514. (if (fboundp 'switch-to-buffer-other-tab)
  3515. (switch-to-buffer-other-tab abuf)
  3516. (user-error "Your version of Emacs does not have tab bar support")))
  3517. ((eq org-agenda-window-setup 'only-window)
  3518. (delete-other-windows)
  3519. (pop-to-buffer-same-window abuf))
  3520. ((eq org-agenda-window-setup 'reorganize-frame)
  3521. (delete-other-windows)
  3522. (org-switch-to-buffer-other-window abuf)))
  3523. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3524. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3525. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3526. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3527. ;; Additional test in case agenda is invoked from within agenda
  3528. ;; buffer via elisp link.
  3529. (unless (equal (current-buffer) abuf)
  3530. (pop-to-buffer-same-window abuf))
  3531. (setq org-agenda-pre-window-conf
  3532. (or wconf org-agenda-pre-window-conf))))
  3533. (defun org-agenda-prepare (&optional name)
  3534. (let ((filter-alist (when org-agenda-persistent-filter
  3535. (with-current-buffer
  3536. (get-buffer-create org-agenda-buffer-name)
  3537. `((tag . ,org-agenda-tag-filter)
  3538. (re . ,org-agenda-regexp-filter)
  3539. (effort . ,org-agenda-effort-filter)
  3540. (cat . ,org-agenda-category-filter))))))
  3541. (if (org-agenda-use-sticky-p)
  3542. (progn
  3543. (put 'org-agenda-tag-filter :preset-filter nil)
  3544. (put 'org-agenda-category-filter :preset-filter nil)
  3545. (put 'org-agenda-regexp-filter :preset-filter nil)
  3546. (put 'org-agenda-effort-filter :preset-filter nil)
  3547. ;; Popup existing buffer
  3548. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3549. filter-alist)
  3550. (message "Sticky Agenda buffer, use `r' to refresh")
  3551. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3552. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3553. (setq org-todo-keywords-for-agenda nil)
  3554. (put 'org-agenda-tag-filter :preset-filter
  3555. org-agenda-tag-filter-preset)
  3556. (put 'org-agenda-category-filter :preset-filter
  3557. org-agenda-category-filter-preset)
  3558. (put 'org-agenda-regexp-filter :preset-filter
  3559. org-agenda-regexp-filter-preset)
  3560. (put 'org-agenda-effort-filter :preset-filter
  3561. org-agenda-effort-filter-preset)
  3562. (if org-agenda-multi
  3563. (progn
  3564. (setq buffer-read-only nil)
  3565. (goto-char (point-max))
  3566. (unless (or (bobp) org-agenda-compact-blocks
  3567. (not org-agenda-block-separator))
  3568. (insert "\n"
  3569. (if (stringp org-agenda-block-separator)
  3570. org-agenda-block-separator
  3571. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3572. "\n"))
  3573. (narrow-to-region (point) (point-max)))
  3574. (setq org-done-keywords-for-agenda nil)
  3575. ;; Setting any org variables that are in org-agenda-local-vars
  3576. ;; list need to be done after the prepare call
  3577. (org-agenda-prepare-window
  3578. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3579. (setq buffer-read-only nil)
  3580. (org-agenda-reset-markers)
  3581. (let ((inhibit-read-only t)) (erase-buffer))
  3582. (org-agenda-mode)
  3583. (setq org-agenda-buffer (current-buffer))
  3584. (setq org-agenda-contributing-files nil)
  3585. (setq org-agenda-columns-active nil)
  3586. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3587. (setq org-todo-keywords-for-agenda
  3588. (org-uniquify org-todo-keywords-for-agenda))
  3589. (setq org-done-keywords-for-agenda
  3590. (org-uniquify org-done-keywords-for-agenda))
  3591. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3592. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3593. (and name (not org-agenda-name)
  3594. (setq-local org-agenda-name name)))
  3595. (setq buffer-read-only nil))))
  3596. (defvar org-overriding-columns-format)
  3597. (defvar org-local-columns-format)
  3598. (defun org-agenda-finalize ()
  3599. "Finishing touch for the agenda buffer.
  3600. This function is called just before displaying the agenda. If
  3601. you want to add your own functions to the finalization of the
  3602. agenda display, configure `org-agenda-finalize-hook'."
  3603. (unless org-agenda-multi
  3604. (let ((inhibit-read-only t))
  3605. (save-excursion
  3606. (goto-char (point-min))
  3607. (save-excursion
  3608. (while (org-activate-links (point-max))
  3609. (goto-char (match-end 0))))
  3610. (unless (eq org-agenda-remove-tags t)
  3611. (org-agenda-align-tags))
  3612. (unless org-agenda-with-colors
  3613. (remove-text-properties (point-min) (point-max) '(face nil)))
  3614. (when (bound-and-true-p org-overriding-columns-format)
  3615. (setq-local org-local-columns-format
  3616. org-overriding-columns-format))
  3617. (when org-agenda-view-columns-initially
  3618. (org-agenda-columns))
  3619. (when org-agenda-fontify-priorities
  3620. (org-agenda-fontify-priorities))
  3621. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3622. (org-agenda-dim-blocked-tasks))
  3623. (org-agenda-mark-clocking-task)
  3624. (when org-agenda-entry-text-mode
  3625. (org-agenda-entry-text-hide)
  3626. (org-agenda-entry-text-show))
  3627. (when (and (featurep 'org-habit)
  3628. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3629. (org-habit-insert-consistency-graphs))
  3630. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3631. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3632. (and (listp org-agenda-show-inherited-tags)
  3633. (memq org-agenda-type org-agenda-show-inherited-tags))
  3634. (and (eq org-agenda-show-inherited-tags t)
  3635. (or (eq org-agenda-use-tag-inheritance t)
  3636. (and (listp org-agenda-use-tag-inheritance)
  3637. (not (memq org-agenda-type
  3638. org-agenda-use-tag-inheritance))))))
  3639. (let (mrk)
  3640. (save-excursion
  3641. (goto-char (point-min))
  3642. (while (equal (forward-line) 0)
  3643. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3644. (put-text-property (point-at-bol) (point-at-eol)
  3645. 'tags
  3646. (org-with-point-at mrk
  3647. (org-get-tags))))))))
  3648. (setq org-agenda-represented-tags nil
  3649. org-agenda-represented-categories nil)
  3650. (when org-agenda-top-headline-filter
  3651. (org-agenda-filter-top-headline-apply
  3652. org-agenda-top-headline-filter))
  3653. (when org-agenda-tag-filter
  3654. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3655. (when (get 'org-agenda-tag-filter :preset-filter)
  3656. (org-agenda-filter-apply
  3657. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3658. (when org-agenda-category-filter
  3659. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3660. (when (get 'org-agenda-category-filter :preset-filter)
  3661. (org-agenda-filter-apply
  3662. (get 'org-agenda-category-filter :preset-filter) 'category))
  3663. (when org-agenda-regexp-filter
  3664. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3665. (when (get 'org-agenda-regexp-filter :preset-filter)
  3666. (org-agenda-filter-apply
  3667. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3668. (when org-agenda-effort-filter
  3669. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3670. (when (get 'org-agenda-effort-filter :preset-filter)
  3671. (org-agenda-filter-apply
  3672. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3673. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3674. (run-hooks 'org-agenda-finalize-hook))))
  3675. (defun org-agenda-mark-clocking-task ()
  3676. "Mark the current clock entry in the agenda if it is present."
  3677. ;; We need to widen when `org-agenda-finalize' is called from
  3678. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3679. (when (bound-and-true-p org-clock-current-task)
  3680. (save-restriction
  3681. (widen)
  3682. (org-agenda-unmark-clocking-task)
  3683. (when (marker-buffer org-clock-hd-marker)
  3684. (save-excursion
  3685. (goto-char (point-min))
  3686. (let (s ov)
  3687. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3688. (goto-char s)
  3689. (when (equal (org-get-at-bol 'org-hd-marker)
  3690. org-clock-hd-marker)
  3691. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3692. (overlay-put ov 'type 'org-agenda-clocking)
  3693. (overlay-put ov 'face 'org-agenda-clocking)
  3694. (overlay-put ov 'help-echo
  3695. "The clock is running in this item")))))))))
  3696. (defun org-agenda-unmark-clocking-task ()
  3697. "Unmark the current clocking task."
  3698. (mapc (lambda (o)
  3699. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3700. (delete-overlay o)))
  3701. (overlays-in (point-min) (point-max))))
  3702. (defun org-agenda-fontify-priorities ()
  3703. "Make highest priority lines bold, and lowest italic."
  3704. (interactive)
  3705. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3706. (delete-overlay o)))
  3707. (overlays-in (point-min) (point-max)))
  3708. (save-excursion
  3709. (let (b e p ov h l)
  3710. (goto-char (point-min))
  3711. (while (re-search-forward org-priority-regexp nil t)
  3712. (setq h (or (get-char-property (point) 'org-priority-highest)
  3713. org-priority-highest)
  3714. l (or (get-char-property (point) 'org-priority-lowest)
  3715. org-priority-lowest)
  3716. p (string-to-char (match-string 2))
  3717. b (match-beginning 1)
  3718. e (if (eq org-agenda-fontify-priorities 'cookies)
  3719. (1+ (match-end 2))
  3720. (point-at-eol))
  3721. ov (make-overlay b e))
  3722. (overlay-put
  3723. ov 'face
  3724. (let ((special-face
  3725. (cond ((org-face-from-face-or-color
  3726. 'priority 'org-priority
  3727. (cdr (assoc p org-priority-faces))))
  3728. ((and (listp org-agenda-fontify-priorities)
  3729. (org-face-from-face-or-color
  3730. 'priority 'org-priority
  3731. (cdr (assoc p org-agenda-fontify-priorities)))))
  3732. ((equal p l) 'italic)
  3733. ((equal p h) 'bold))))
  3734. (if special-face (list special-face 'org-priority) 'org-priority)))
  3735. (overlay-put ov 'org-type 'org-priority)))))
  3736. (defvar org-depend-tag-blocked)
  3737. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3738. "Dim currently blocked TODOs in the agenda display.
  3739. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3740. dimming them." ;FIXME: The arg isn't used, actually!
  3741. (interactive "P")
  3742. (when (called-interactively-p 'interactive)
  3743. (message "Dim or hide blocked tasks..."))
  3744. (dolist (o (overlays-in (point-min) (point-max)))
  3745. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3746. (delete-overlay o)))
  3747. (save-excursion
  3748. (let ((inhibit-read-only t))
  3749. (goto-char (point-min))
  3750. (while (let ((pos (text-property-not-all
  3751. (point) (point-max) 'org-todo-blocked nil)))
  3752. (when pos (goto-char pos)))
  3753. (let* ((invisible
  3754. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3755. (todo-blocked
  3756. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3757. (ov (make-overlay (if invisible
  3758. (line-end-position 0)
  3759. (line-beginning-position))
  3760. (line-end-position))))
  3761. (when todo-blocked
  3762. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3763. (when invisible
  3764. (org-agenda-filter-hide-line 'todo-blocked)))
  3765. (if (= (point-max) (line-end-position))
  3766. (goto-char (point-max))
  3767. (move-beginning-of-line 2)))))
  3768. (when (called-interactively-p 'interactive)
  3769. (message "Dim or hide blocked tasks...done")))
  3770. (defun org-agenda--mark-blocked-entry (entry)
  3771. "If ENTRY is blocked, mark it for fontification or invisibility.
  3772. If the header at `org-hd-marker' is blocked according to
  3773. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3774. \\='invisible and the header is not blocked by checkboxes, set the
  3775. text property `org-todo-blocked' to `invisible', otherwise set it
  3776. to t."
  3777. (when (get-text-property 0 'todo-state entry)
  3778. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3779. (org-blocked-by-checkboxes nil)
  3780. ;; Necessary so that `org-entry-blocked-p' does not change
  3781. ;; the buffer.
  3782. (org-depend-tag-blocked nil))
  3783. (when entry-marker
  3784. (let ((blocked
  3785. (with-current-buffer (marker-buffer entry-marker)
  3786. (save-excursion
  3787. (goto-char entry-marker)
  3788. (org-entry-blocked-p)))))
  3789. (when blocked
  3790. (let ((really-invisible
  3791. (and (not org-blocked-by-checkboxes)
  3792. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3793. (put-text-property
  3794. 0 (length entry) 'org-todo-blocked
  3795. (if really-invisible 'invisible t)
  3796. entry)
  3797. (put-text-property
  3798. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3799. entry)
  3800. (defvar org-agenda-skip-function nil
  3801. "Function to be called at each match during agenda construction.
  3802. If this function returns nil, the current match should not be skipped.
  3803. Otherwise, the function must return a position from where the search
  3804. should be continued.
  3805. This may also be a Lisp form, it will be evaluated.
  3806. Never set this variable using `setq' or so, because then it will apply
  3807. to all future agenda commands. If you do want a global skipping condition,
  3808. use the option `org-agenda-skip-function-global' instead.
  3809. The correct usage for `org-agenda-skip-function' is to bind it with
  3810. `let' to scope it dynamically into the agenda-constructing command.
  3811. A good way to set it is through options in `org-agenda-custom-commands'.")
  3812. (defun org-agenda-skip (&optional element)
  3813. "Throw to `:skip' in places that should be skipped.
  3814. Also moves point to the end of the skipped region, so that search can
  3815. continue from there.
  3816. Optional argument ELEMENT contains element at point."
  3817. (let ((p (point-at-bol)) to)
  3818. (when (or
  3819. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3820. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3821. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3822. (org-end-of-subtree t element))
  3823. (and (member org-archive-tag org-file-tags)
  3824. (goto-char (point-max)))))
  3825. (and org-agenda-skip-comment-trees
  3826. (org-in-commented-heading-p nil element)
  3827. (org-end-of-subtree t element))
  3828. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3829. (org-agenda-skip-eval org-agenda-skip-function)))
  3830. (goto-char to))
  3831. (org-in-src-block-p t))
  3832. (throw :skip t))))
  3833. (defun org-agenda-skip-eval (form)
  3834. "If FORM is a function or a list, call (or eval) it and return the result.
  3835. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3836. and match data are returned to the previous state no matter what these
  3837. functions do."
  3838. (let (fp)
  3839. (and form
  3840. (or (setq fp (functionp form))
  3841. (consp form))
  3842. (save-excursion
  3843. (save-match-data
  3844. (if fp
  3845. (funcall form)
  3846. (eval form t)))))))
  3847. (defvar org-agenda-markers nil
  3848. "List of all currently active markers created by `org-agenda'.")
  3849. (defvar org-agenda-last-marker-time (float-time)
  3850. "Creation time of the last agenda marker.")
  3851. (defun org-agenda-new-marker (&optional pos)
  3852. "Return a new agenda marker.
  3853. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3854. of these markers and resets them when they are no longer in use."
  3855. (let ((m (copy-marker (or pos (point)) t)))
  3856. (setq org-agenda-last-marker-time (float-time))
  3857. (if org-agenda-buffer
  3858. (with-current-buffer org-agenda-buffer
  3859. (push m org-agenda-markers))
  3860. (push m org-agenda-markers))
  3861. m))
  3862. (defun org-agenda-reset-markers ()
  3863. "Reset markers created by `org-agenda'."
  3864. (while org-agenda-markers
  3865. (move-marker (pop org-agenda-markers) nil)))
  3866. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3867. "Save relative positions of markers in region.
  3868. This check for agenda markers in all agenda buffers currently active."
  3869. (dolist (buf (buffer-list))
  3870. (with-current-buffer buf
  3871. (when (eq major-mode 'org-agenda-mode)
  3872. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3873. org-agenda-markers)))))
  3874. ;;; Entry text mode
  3875. (defun org-agenda-entry-text-show-here ()
  3876. "Add some text from the entry as context to the current line."
  3877. (let (m txt o)
  3878. (setq m (org-get-at-bol 'org-hd-marker))
  3879. (unless (marker-buffer m)
  3880. (error "No marker points to an entry here"))
  3881. (setq txt (concat "\n" (org-no-properties
  3882. (org-agenda-get-some-entry-text
  3883. m org-agenda-entry-text-maxlines
  3884. org-agenda-entry-text-leaders))))
  3885. (when (string-match "\\S-" txt)
  3886. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3887. (overlay-put o 'evaporate t)
  3888. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3889. (overlay-put o 'after-string txt))))
  3890. (defun org-agenda-entry-text-show ()
  3891. "Add entry context for all agenda lines."
  3892. (interactive)
  3893. (save-excursion
  3894. (goto-char (point-max))
  3895. (beginning-of-line 1)
  3896. (while (not (bobp))
  3897. (when (org-get-at-bol 'org-hd-marker)
  3898. (org-agenda-entry-text-show-here))
  3899. (beginning-of-line 0))))
  3900. (defun org-agenda-entry-text-hide ()
  3901. "Remove any shown entry context."
  3902. (mapc (lambda (o)
  3903. (when (eq (overlay-get o 'org-overlay-type)
  3904. 'agenda-entry-content)
  3905. (delete-overlay o)))
  3906. (overlays-in (point-min) (point-max))))
  3907. (defun org-agenda-get-day-face (date)
  3908. "Return the face DATE should be displayed with."
  3909. (cond ((and (functionp org-agenda-day-face-function)
  3910. (funcall org-agenda-day-face-function date)))
  3911. ((and (org-agenda-today-p date)
  3912. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3913. 'org-agenda-date-weekend-today)
  3914. ((org-agenda-today-p date) 'org-agenda-date-today)
  3915. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3916. 'org-agenda-date-weekend)
  3917. (t 'org-agenda-date)))
  3918. (defvar org-agenda-show-log-scoped)
  3919. ;;; Agenda Daily/Weekly
  3920. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3921. "Start day for the agenda view.
  3922. Custom commands can set this variable in the options section.
  3923. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3924. input allowed when reading a date through the Org calendar.
  3925. See the docstring of `org-read-date' for details.")
  3926. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3927. (defvar org-arg-loc nil) ; local variable
  3928. ;;;###autoload
  3929. (defun org-agenda-list (&optional arg start-day span with-hour)
  3930. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3931. The view will be for the current day or week, but from the overview buffer
  3932. you will be able to go to other days/weeks.
  3933. With a numeric prefix argument in an interactive call, the agenda will
  3934. span ARG days. Lisp programs should instead specify SPAN to change
  3935. the number of days. SPAN defaults to `org-agenda-span'.
  3936. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3937. given in `org-agenda-start-on-weekday'.
  3938. When WITH-HOUR is non-nil, only include scheduled and deadline
  3939. items if they have an hour specification like [h]h:mm."
  3940. (interactive "P")
  3941. (when org-agenda-overriding-arguments
  3942. (setq arg (car org-agenda-overriding-arguments)
  3943. start-day (nth 1 org-agenda-overriding-arguments)
  3944. span (nth 2 org-agenda-overriding-arguments)))
  3945. (when (and (integerp arg) (> arg 0))
  3946. (setq span arg arg nil))
  3947. (when (numberp span)
  3948. (unless (< 0 span)
  3949. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3950. (catch 'exit
  3951. (setq org-agenda-buffer-name
  3952. (org-agenda--get-buffer-name
  3953. (and org-agenda-sticky
  3954. (cond ((and org-keys (stringp org-match))
  3955. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3956. (org-keys
  3957. (format "*Org Agenda(%s)*" org-keys))
  3958. (t "*Org Agenda(a)*")))))
  3959. (org-agenda-prepare "Day/Week")
  3960. (setq start-day (or start-day org-agenda-start-day))
  3961. (when (stringp start-day)
  3962. ;; Convert to an absolute day number
  3963. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3964. (org-compile-prefix-format 'agenda)
  3965. (org-set-sorting-strategy 'agenda)
  3966. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3967. (today (org-today))
  3968. (sd (or start-day today))
  3969. (ndays (org-agenda-span-to-ndays span sd))
  3970. (org-agenda-start-on-weekday
  3971. (and (or (eq ndays 7) (eq ndays 14))
  3972. org-agenda-start-on-weekday))
  3973. (thefiles (org-agenda-files nil 'ifmode))
  3974. (files thefiles)
  3975. (start (if (or (null org-agenda-start-on-weekday)
  3976. (< ndays 7))
  3977. sd
  3978. (let* ((nt (calendar-day-of-week
  3979. (calendar-gregorian-from-absolute sd)))
  3980. (n1 org-agenda-start-on-weekday)
  3981. (d (- nt n1)))
  3982. (- sd (+ (if (< d 0) 7 0) d)))))
  3983. (day-numbers (list start))
  3984. (day-cnt 0)
  3985. (inhibit-redisplay (not debug-on-error))
  3986. (org-agenda-show-log-scoped org-agenda-show-log)
  3987. s rtn rtnall file date d start-pos end-pos todayp ;; e
  3988. clocktable-start clocktable-end) ;; filter
  3989. (setq org-agenda-redo-command
  3990. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3991. (dotimes (_ (1- ndays))
  3992. (push (1+ (car day-numbers)) day-numbers))
  3993. (setq day-numbers (nreverse day-numbers))
  3994. (setq clocktable-start (car day-numbers)
  3995. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3996. (setq-local org-starting-day (car day-numbers))
  3997. (setq-local org-arg-loc arg)
  3998. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3999. (unless org-agenda-compact-blocks
  4000. (let* ((d1 (car day-numbers))
  4001. (d2 (org-last day-numbers))
  4002. (w1 (org-days-to-iso-week d1))
  4003. (w2 (org-days-to-iso-week d2)))
  4004. (setq s (point))
  4005. (org-agenda--insert-overriding-header
  4006. (concat (org-agenda-span-name span)
  4007. "-agenda"
  4008. (cond ((<= 350 (- d2 d1)) "")
  4009. ((= w1 w2) (format " (W%02d)" w1))
  4010. (t (format " (W%02d-W%02d)" w1 w2)))
  4011. ":\n")))
  4012. ;; Add properties if we actually inserted a header.
  4013. (when (> (point) s)
  4014. (add-text-properties s (1- (point))
  4015. (list 'face 'org-agenda-structure
  4016. 'org-date-line t))
  4017. (org-agenda-mark-header-line s)))
  4018. (while (setq d (pop day-numbers))
  4019. (setq date (calendar-gregorian-from-absolute d)
  4020. s (point))
  4021. (if (or (setq todayp (= d today))
  4022. (and (not start-pos) (= d sd)))
  4023. (setq start-pos (point))
  4024. (when (and start-pos (not end-pos))
  4025. (setq end-pos (point))))
  4026. (setq files thefiles
  4027. rtnall nil)
  4028. (while (setq file (pop files))
  4029. (catch 'nextfile
  4030. (org-check-agenda-file file)
  4031. (let ((org-agenda-entry-types org-agenda-entry-types))
  4032. ;; Starred types override non-starred equivalents
  4033. (when (member :deadline* org-agenda-entry-types)
  4034. (setq org-agenda-entry-types
  4035. (delq :deadline org-agenda-entry-types)))
  4036. (when (member :scheduled* org-agenda-entry-types)
  4037. (setq org-agenda-entry-types
  4038. (delq :scheduled org-agenda-entry-types)))
  4039. ;; Honor with-hour
  4040. (when with-hour
  4041. (when (member :deadline org-agenda-entry-types)
  4042. (setq org-agenda-entry-types
  4043. (delq :deadline org-agenda-entry-types))
  4044. (push :deadline* org-agenda-entry-types))
  4045. (when (member :scheduled org-agenda-entry-types)
  4046. (setq org-agenda-entry-types
  4047. (delq :scheduled org-agenda-entry-types))
  4048. (push :scheduled* org-agenda-entry-types)))
  4049. (unless org-agenda-include-deadlines
  4050. (setq org-agenda-entry-types
  4051. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4052. (cond
  4053. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4054. (setq rtn (org-agenda-get-day-entries
  4055. file date :closed)))
  4056. (org-agenda-show-log-scoped
  4057. (setq rtn (apply #'org-agenda-get-day-entries
  4058. file date
  4059. (append '(:closed) org-agenda-entry-types))))
  4060. (t
  4061. (setq rtn (apply #'org-agenda-get-day-entries
  4062. file date
  4063. org-agenda-entry-types)))))
  4064. (setq rtnall (append rtnall rtn)))) ;; all entries
  4065. (when org-agenda-include-diary
  4066. (let ((org-agenda-search-headline-for-time t))
  4067. (require 'diary-lib)
  4068. (setq rtn (org-get-entries-from-diary date))
  4069. (setq rtnall (append rtnall rtn))))
  4070. (when (or rtnall org-agenda-show-all-dates)
  4071. (setq day-cnt (1+ day-cnt))
  4072. (insert
  4073. (if (stringp org-agenda-format-date)
  4074. (format-time-string org-agenda-format-date
  4075. (org-time-from-absolute date))
  4076. (funcall org-agenda-format-date date))
  4077. "\n")
  4078. (put-text-property s (1- (point)) 'face
  4079. (org-agenda-get-day-face date))
  4080. (put-text-property s (1- (point)) 'org-date-line t)
  4081. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4082. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4083. (when todayp
  4084. (put-text-property s (1- (point)) 'org-today t))
  4085. (setq rtnall
  4086. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4087. (when rtnall (insert ;; all entries
  4088. (org-agenda-finalize-entries rtnall 'agenda)
  4089. "\n"))
  4090. (put-text-property s (1- (point)) 'day d)
  4091. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4092. (when (and org-agenda-clockreport-mode clocktable-start)
  4093. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4094. ;; the above line is to ensure the restricted range!
  4095. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4096. tbl)
  4097. (setq p (org-plist-delete p :block))
  4098. (setq p (plist-put p :tstart clocktable-start))
  4099. (setq p (plist-put p :tend clocktable-end))
  4100. (setq p (plist-put p :scope 'agenda))
  4101. (setq tbl (apply #'org-clock-get-clocktable p))
  4102. (when org-agenda-clock-report-header
  4103. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure)))
  4104. (insert tbl)))
  4105. (goto-char (point-min))
  4106. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4107. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4108. (and (pos-visible-in-window-p (point-min))
  4109. (pos-visible-in-window-p (point-max))))
  4110. (goto-char (1- (point-max)))
  4111. (recenter -1)
  4112. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4113. (goto-char (or start-pos 1))
  4114. (recenter 1)))
  4115. (goto-char (or start-pos 1))
  4116. (add-text-properties (point-min) (point-max)
  4117. `(org-agenda-type agenda
  4118. org-last-args (,arg ,start-day ,span)
  4119. org-redo-cmd ,org-agenda-redo-command
  4120. org-series-cmd ,org-cmd))
  4121. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4122. (org-agenda-show-clocking-issues))
  4123. (org-agenda-finalize)
  4124. (setq buffer-read-only t)
  4125. (message ""))))
  4126. (defun org-agenda-ndays-to-span (n)
  4127. "Return a span symbol for a span of N days, or N if none matches."
  4128. (cond ((symbolp n) n)
  4129. ((= n 1) 'day)
  4130. ((= n 7) 'week)
  4131. ((= n 14) 'fortnight)
  4132. (t n)))
  4133. (defun org-agenda-span-to-ndays (span &optional start-day)
  4134. "Return ndays from SPAN, possibly starting at START-DAY.
  4135. START-DAY is an absolute time value."
  4136. (cond ((numberp span) span)
  4137. ((eq span 'day) 1)
  4138. ((eq span 'week) 7)
  4139. ((eq span 'fortnight) 14)
  4140. ((eq span 'month)
  4141. (let ((date (calendar-gregorian-from-absolute start-day)))
  4142. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4143. ((eq span 'year)
  4144. (let ((date (calendar-gregorian-from-absolute start-day)))
  4145. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4146. (defun org-agenda-span-name (span)
  4147. "Return a SPAN name."
  4148. (if (null span)
  4149. ""
  4150. (if (symbolp span)
  4151. (capitalize (symbol-name span))
  4152. (format "%d days" span))))
  4153. ;;; Agenda word search
  4154. (defvar org-agenda-search-history nil)
  4155. (defvar org-search-syntax-table nil
  4156. "Special syntax table for Org search.
  4157. In this table, we have single quotes not as word constituents, to
  4158. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4159. (defvar org-mode-syntax-table) ; From org.el
  4160. (defun org-search-syntax-table ()
  4161. (unless org-search-syntax-table
  4162. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4163. (modify-syntax-entry ?' "." org-search-syntax-table)
  4164. (modify-syntax-entry ?` "." org-search-syntax-table))
  4165. org-search-syntax-table)
  4166. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4167. ;;;###autoload
  4168. (defun org-search-view (&optional todo-only string edit-at)
  4169. "Show all entries that contain a phrase or words or regular expressions.
  4170. With optional prefix argument TODO-ONLY, only consider entries that are
  4171. TODO entries. The argument STRING can be used to pass a default search
  4172. string into this function. If EDIT-AT is non-nil, it means that the
  4173. user should get a chance to edit this string, with cursor at position
  4174. EDIT-AT.
  4175. The search string can be viewed either as a phrase that should be found as
  4176. is, or it can be broken into a number of snippets, each of which must match
  4177. in a Boolean way to select an entry. The default depends on the variable
  4178. `org-agenda-search-view-always-boolean'.
  4179. Even if this is turned off (the default) you can always switch to
  4180. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4181. The default is a direct search of the whole phrase, where each space in
  4182. the search string can expand to an arbitrary amount of whitespace,
  4183. including newlines.
  4184. If using a Boolean search, the search string is split on whitespace and
  4185. each snippet is searched separately, with logical AND to select an entry.
  4186. Words prefixed with a minus must *not* occur in the entry. Words without
  4187. a prefix or prefixed with a plus must occur in the entry. Matching is
  4188. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4189. match whole words, not parts of a word) if
  4190. `org-agenda-search-view-force-full-words' is set (default is nil).
  4191. Boolean search snippets enclosed by curly braces are interpreted as
  4192. regular expressions that must or (when preceded with \"-\") must not
  4193. match in the entry. Snippets enclosed into double quotes will be taken
  4194. as a whole, to include whitespace.
  4195. - If the search string starts with an asterisk, search only in headlines.
  4196. - If (possibly after the leading star) the search string starts with an
  4197. exclamation mark, this also means to look at TODO entries only, an effect
  4198. that can also be achieved with a prefix argument.
  4199. - If (possibly after star and exclamation mark) the search string starts
  4200. with a colon, this will mean that the (non-regexp) snippets of the
  4201. Boolean search must match as full words.
  4202. This command searches the agenda files, and in addition the files
  4203. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4204. is active."
  4205. (interactive "P")
  4206. (when org-agenda-overriding-arguments
  4207. (setq todo-only (car org-agenda-overriding-arguments)
  4208. string (nth 1 org-agenda-overriding-arguments)
  4209. edit-at (nth 2 org-agenda-overriding-arguments)))
  4210. (let* ((props (list 'face nil
  4211. 'done-face 'org-agenda-done
  4212. 'org-not-done-regexp org-not-done-regexp
  4213. 'org-todo-regexp org-todo-regexp
  4214. 'org-complex-heading-regexp org-complex-heading-regexp
  4215. 'mouse-face 'highlight
  4216. 'help-echo "mouse-2 or RET jump to location"))
  4217. (full-words org-agenda-search-view-force-full-words)
  4218. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4219. regexp rtn rtnall files file pos inherited-tags
  4220. marker category level tags c neg re boolean
  4221. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4222. (unless (and (not edit-at)
  4223. (stringp string)
  4224. (string-match "\\S-" string))
  4225. (setq string (read-string
  4226. (if org-agenda-search-view-always-boolean
  4227. "[+-]Word/{Regexp} ...: "
  4228. "Phrase or [+-]Word/{Regexp} ...: ")
  4229. (cond
  4230. ((integerp edit-at) (cons string edit-at))
  4231. (edit-at string))
  4232. 'org-agenda-search-history)))
  4233. (catch 'exit
  4234. (setq org-agenda-buffer-name
  4235. (org-agenda--get-buffer-name
  4236. (and org-agenda-sticky
  4237. (if (stringp string)
  4238. (format "*Org Agenda(%s:%s)*"
  4239. (or org-keys (or (and todo-only "S") "s"))
  4240. string)
  4241. (format "*Org Agenda(%s)*"
  4242. (or (and todo-only "S") "s"))))))
  4243. (org-agenda-prepare "SEARCH")
  4244. (org-compile-prefix-format 'search)
  4245. (org-set-sorting-strategy 'search)
  4246. (setq org-agenda-redo-command
  4247. (list 'org-search-view (if todo-only t nil)
  4248. (list 'if 'current-prefix-arg nil string)))
  4249. (setq org-agenda-query-string string)
  4250. (if (equal (string-to-char string) ?*)
  4251. (setq hdl-only t
  4252. words (substring string 1))
  4253. (setq words string))
  4254. (when (equal (string-to-char words) ?!)
  4255. (setq todo-only t
  4256. words (substring words 1)))
  4257. (when (equal (string-to-char words) ?:)
  4258. (setq full-words t
  4259. words (substring words 1)))
  4260. (when (or org-agenda-search-view-always-boolean
  4261. (member (string-to-char words) '(?- ?+ ?\{)))
  4262. (setq boolean t))
  4263. (setq words (split-string words))
  4264. (let (www w)
  4265. (while (setq w (pop words))
  4266. (while (and (string-match "\\\\\\'" w) words)
  4267. (setq w (concat (substring w 0 -1) " " (pop words))))
  4268. (push w www))
  4269. (setq words (nreverse www) www nil)
  4270. (while (setq w (pop words))
  4271. (when (and (string-match "\\`[-+]?{" w)
  4272. (not (string-match "}\\'" w)))
  4273. (while (and words (not (string-match "}\\'" (car words))))
  4274. (setq w (concat w " " (pop words))))
  4275. (setq w (concat w " " (pop words))))
  4276. (push w www))
  4277. (setq words (nreverse www)))
  4278. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4279. (when boolean
  4280. (let (wds w)
  4281. (while (setq w (pop words))
  4282. (when (or (equal (substring w 0 1) "\"")
  4283. (and (> (length w) 1)
  4284. (member (substring w 0 1) '("+" "-"))
  4285. (equal (substring w 1 2) "\"")))
  4286. (while (and words (not (equal (substring w -1) "\"")))
  4287. (setq w (concat w " " (pop words)))))
  4288. (and (string-match "\\`\\([-+]?\\)\"" w)
  4289. (setq w (replace-match "\\1" nil nil w)))
  4290. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4291. (push w wds))
  4292. (setq words (nreverse wds))))
  4293. (if boolean
  4294. (mapc (lambda (w)
  4295. (setq c (string-to-char w))
  4296. (if (equal c ?-)
  4297. (setq neg t w (substring w 1))
  4298. (if (equal c ?+)
  4299. (setq neg nil w (substring w 1))
  4300. (setq neg nil)))
  4301. (if (string-match "\\`{.*}\\'" w)
  4302. (setq re (substring w 1 -1))
  4303. (if full-words
  4304. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4305. (setq re (regexp-quote (downcase w)))))
  4306. (if neg (push re regexps-) (push re regexps+)))
  4307. words)
  4308. (push (mapconcat #'regexp-quote words "\\s-+")
  4309. regexps+))
  4310. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4311. (if (not regexps+)
  4312. (setq regexp org-outline-regexp-bol)
  4313. (setq regexp (pop regexps+))
  4314. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4315. regexp))))
  4316. (setq files (org-agenda-files nil 'ifmode))
  4317. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4318. ;; restriction.
  4319. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4320. (pop org-agenda-text-search-extra-files)
  4321. (unless (get 'org-agenda-files 'org-restrict)
  4322. (setq files (org-add-archive-files files))))
  4323. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4324. ;; non-existent ones.
  4325. (setq files (cl-remove-duplicates
  4326. (append files org-agenda-text-search-extra-files)
  4327. :test (lambda (a b)
  4328. (and (file-exists-p a)
  4329. (file-exists-p b)
  4330. (file-equal-p a b))))
  4331. rtnall nil)
  4332. (while (setq file (pop files))
  4333. (setq ee nil)
  4334. (catch 'nextfile
  4335. (org-check-agenda-file file)
  4336. (setq buffer (if (file-exists-p file)
  4337. (org-get-agenda-file-buffer file)
  4338. (error "No such file %s" file)))
  4339. (unless buffer
  4340. ;; If file does not exist, make sure an error message is sent
  4341. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4342. file))))
  4343. (with-current-buffer buffer
  4344. (with-syntax-table (org-search-syntax-table)
  4345. (unless (derived-mode-p 'org-mode)
  4346. (error "Agenda file %s is not in Org mode" file))
  4347. (let ((case-fold-search t))
  4348. (save-excursion
  4349. (save-restriction
  4350. (if (eq buffer org-agenda-restrict)
  4351. (narrow-to-region org-agenda-restrict-begin
  4352. org-agenda-restrict-end)
  4353. (widen))
  4354. (goto-char (point-min))
  4355. (unless (or (org-at-heading-p)
  4356. (outline-next-heading))
  4357. (throw 'nextfile t))
  4358. (goto-char (max (point-min) (1- (point))))
  4359. (while (re-search-forward regexp nil t)
  4360. (org-back-to-heading t)
  4361. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4362. (> (org-reduced-level (org-outline-level))
  4363. org-agenda-search-view-max-outline-level)
  4364. (forward-line -1)
  4365. (org-back-to-heading t)))
  4366. (skip-chars-forward "* ")
  4367. (setq beg (point-at-bol)
  4368. beg1 (point)
  4369. end (progn
  4370. (outline-next-heading)
  4371. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4372. (> (org-reduced-level (org-outline-level))
  4373. org-agenda-search-view-max-outline-level)
  4374. (forward-line 1)
  4375. (outline-next-heading)))
  4376. (point)))
  4377. (catch :skip
  4378. (goto-char beg)
  4379. (org-agenda-skip)
  4380. (setq str (buffer-substring-no-properties
  4381. (point-at-bol)
  4382. (if hdl-only (point-at-eol) end)))
  4383. (mapc (lambda (wr) (when (string-match wr str)
  4384. (goto-char (1- end))
  4385. (throw :skip t)))
  4386. regexps-)
  4387. (mapc (lambda (wr) (unless (string-match wr str)
  4388. (goto-char (1- end))
  4389. (throw :skip t)))
  4390. (if todo-only
  4391. (cons (concat "^\\*+[ \t]+"
  4392. org-not-done-regexp)
  4393. regexps+)
  4394. regexps+))
  4395. (goto-char beg)
  4396. (setq marker (org-agenda-new-marker (point))
  4397. category (org-get-category)
  4398. level (make-string (org-reduced-level (org-outline-level)) ? )
  4399. inherited-tags
  4400. (or (eq org-agenda-show-inherited-tags 'always)
  4401. (and (listp org-agenda-show-inherited-tags)
  4402. (memq 'todo org-agenda-show-inherited-tags))
  4403. (and (eq org-agenda-show-inherited-tags t)
  4404. (or (eq org-agenda-use-tag-inheritance t)
  4405. (memq 'todo org-agenda-use-tag-inheritance))))
  4406. tags (org-get-tags nil (not inherited-tags))
  4407. txt (org-agenda-format-item
  4408. ""
  4409. (buffer-substring-no-properties
  4410. beg1 (point-at-eol))
  4411. level category tags t))
  4412. (org-add-props txt props
  4413. 'org-marker marker 'org-hd-marker marker
  4414. 'org-todo-regexp org-todo-regexp
  4415. 'level level
  4416. 'org-complex-heading-regexp org-complex-heading-regexp
  4417. 'priority 1000
  4418. 'type "search")
  4419. (push txt ee)
  4420. (goto-char (1- end))))))))))
  4421. (setq rtn (nreverse ee))
  4422. (setq rtnall (append rtnall rtn)))
  4423. (org-agenda--insert-overriding-header
  4424. (with-temp-buffer
  4425. (insert "Search words: ")
  4426. (add-text-properties (point-min) (1- (point))
  4427. (list 'face 'org-agenda-structure))
  4428. (setq pos (point))
  4429. (insert string "\n")
  4430. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4431. (setq pos (point))
  4432. (unless org-agenda-multi
  4433. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4434. Press `\\[org-agenda-manipulate-query-add]', \
  4435. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4436. `\\[org-agenda-manipulate-query-add-re]', \
  4437. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4438. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4439. (add-text-properties pos (1- (point))
  4440. (list 'face 'org-agenda-structure-secondary)))
  4441. (buffer-string)))
  4442. (org-agenda-mark-header-line (point-min))
  4443. (when rtnall
  4444. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4445. (goto-char (point-min))
  4446. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4447. (add-text-properties (point-min) (point-max)
  4448. `(org-agenda-type search
  4449. org-last-args (,todo-only ,string ,edit-at)
  4450. org-redo-cmd ,org-agenda-redo-command
  4451. org-series-cmd ,org-cmd))
  4452. (org-agenda-finalize)
  4453. (setq buffer-read-only t))))
  4454. ;;; Agenda TODO list
  4455. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4456. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4457. (concat
  4458. (if (or (equal keywords "ALL") (not keywords))
  4459. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4460. (mapconcat
  4461. (lambda (kw)
  4462. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4463. (org-split-string keywords "|")
  4464. "|"))
  4465. "\n"))
  4466. (defvar org-select-this-todo-keyword nil)
  4467. (defvar org-last-arg nil)
  4468. (defvar crm-separator)
  4469. ;;;###autoload
  4470. (defun org-todo-list (&optional arg)
  4471. "Show all (not done) TODO entries from all agenda files in a single list.
  4472. The prefix arg can be used to select a specific TODO keyword and limit
  4473. the list to these. When using `\\[universal-argument]', you will be prompted
  4474. for a keyword. A numeric prefix directly selects the Nth keyword in
  4475. `org-todo-keywords-1'."
  4476. (interactive "P")
  4477. (when org-agenda-overriding-arguments
  4478. (setq arg org-agenda-overriding-arguments))
  4479. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4480. (let* ((today (org-today))
  4481. (date (calendar-gregorian-from-absolute today))
  4482. (completion-ignore-case t)
  4483. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4484. (catch 'exit
  4485. (setq org-agenda-buffer-name
  4486. (org-agenda--get-buffer-name
  4487. (and org-agenda-sticky
  4488. (if (stringp org-select-this-todo-keyword)
  4489. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4490. org-select-this-todo-keyword)
  4491. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4492. (org-agenda-prepare "TODO")
  4493. (setq kwds org-todo-keywords-for-agenda
  4494. org-select-this-todo-keyword (if (stringp arg) arg
  4495. (and (integerp arg)
  4496. (> arg 0)
  4497. (nth (1- arg) kwds))))
  4498. (when (equal arg '(4))
  4499. (setq org-select-this-todo-keyword
  4500. (mapconcat #'identity
  4501. (let ((crm-separator "|"))
  4502. (completing-read-multiple
  4503. "Keyword (or KWD1|KWD2|...): "
  4504. (mapcar #'list kwds) nil nil))
  4505. "|")))
  4506. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4507. (org-compile-prefix-format 'todo)
  4508. (org-set-sorting-strategy 'todo)
  4509. (setq org-agenda-redo-command
  4510. `(org-todo-list (or (and (numberp current-prefix-arg)
  4511. current-prefix-arg)
  4512. ,org-select-this-todo-keyword
  4513. current-prefix-arg ,arg)))
  4514. (setq files (org-agenda-files nil 'ifmode)
  4515. rtnall nil)
  4516. (while (setq file (pop files))
  4517. (catch 'nextfile
  4518. (org-check-agenda-file file)
  4519. (setq rtn (org-agenda-get-day-entries file date :todo))
  4520. (setq rtnall (append rtnall rtn))))
  4521. (org-agenda--insert-overriding-header
  4522. (with-temp-buffer
  4523. (insert "Global list of TODO items of type: ")
  4524. (add-text-properties (point-min) (1- (point))
  4525. (list 'face 'org-agenda-structure
  4526. 'short-heading
  4527. (concat "ToDo: "
  4528. (or org-select-this-todo-keyword "ALL"))))
  4529. (org-agenda-mark-header-line (point-min))
  4530. (insert (org-agenda-propertize-selected-todo-keywords
  4531. org-select-this-todo-keyword))
  4532. (setq pos (point))
  4533. (unless org-agenda-multi
  4534. (insert (substitute-command-keys "Press \
  4535. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4536. to search again: (0)[ALL]"))
  4537. (let ((n 0))
  4538. (dolist (k kwds)
  4539. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4540. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4541. (insert "\n "))
  4542. (insert " " s))))
  4543. (insert "\n"))
  4544. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4545. (buffer-string)))
  4546. (org-agenda-mark-header-line (point-min))
  4547. (when rtnall
  4548. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4549. (goto-char (point-min))
  4550. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4551. (add-text-properties (point-min) (point-max)
  4552. `(org-agenda-type todo
  4553. org-last-args ,arg
  4554. org-redo-cmd ,org-agenda-redo-command
  4555. org-series-cmd ,org-cmd))
  4556. (org-agenda-finalize)
  4557. (setq buffer-read-only t))))
  4558. ;;; Agenda tags match
  4559. ;;;###autoload
  4560. (defun org-tags-view (&optional todo-only match)
  4561. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4562. The prefix arg TODO-ONLY limits the search to TODO entries."
  4563. (interactive "P")
  4564. (when org-agenda-overriding-arguments
  4565. (setq todo-only (car org-agenda-overriding-arguments)
  4566. match (nth 1 org-agenda-overriding-arguments)))
  4567. (let* ((org-tags-match-list-sublevels
  4568. org-tags-match-list-sublevels)
  4569. (completion-ignore-case t)
  4570. (org--matcher-tags-todo-only todo-only)
  4571. rtn rtnall files file pos matcher
  4572. buffer)
  4573. (when (and (stringp match) (not (string-match "\\S-" match)))
  4574. (setq match nil))
  4575. (catch 'exit
  4576. (setq org-agenda-buffer-name
  4577. (org-agenda--get-buffer-name
  4578. (and org-agenda-sticky
  4579. (if (stringp match)
  4580. (format "*Org Agenda(%s:%s)*"
  4581. (or org-keys (or (and todo-only "M") "m"))
  4582. match)
  4583. (format "*Org Agenda(%s)*"
  4584. (or (and todo-only "M") "m"))))))
  4585. (setq matcher (org-make-tags-matcher match))
  4586. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4587. ;; expanding tags within `org-make-tags-matcher'
  4588. (org-agenda-prepare (concat "TAGS " match))
  4589. (setq match (car matcher)
  4590. matcher (cdr matcher))
  4591. (org-compile-prefix-format 'tags)
  4592. (org-set-sorting-strategy 'tags)
  4593. (setq org-agenda-query-string match)
  4594. (setq org-agenda-redo-command
  4595. (list 'org-tags-view
  4596. `(quote ,org--matcher-tags-todo-only)
  4597. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4598. (setq files (org-agenda-files nil 'ifmode)
  4599. rtnall nil)
  4600. (while (setq file (pop files))
  4601. (catch 'nextfile
  4602. (org-check-agenda-file file)
  4603. (setq buffer (if (file-exists-p file)
  4604. (org-get-agenda-file-buffer file)
  4605. (error "No such file %s" file)))
  4606. (if (not buffer)
  4607. ;; If file does not exist, error message to agenda
  4608. (setq rtn (list
  4609. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4610. rtnall (append rtnall rtn))
  4611. (with-current-buffer buffer
  4612. (unless (derived-mode-p 'org-mode)
  4613. (error "Agenda file %s is not in Org mode" file))
  4614. (save-excursion
  4615. (save-restriction
  4616. (if (eq buffer org-agenda-restrict)
  4617. (narrow-to-region org-agenda-restrict-begin
  4618. org-agenda-restrict-end)
  4619. (widen))
  4620. (setq rtn (org-scan-tags 'agenda
  4621. matcher
  4622. org--matcher-tags-todo-only))
  4623. (setq rtnall (append rtnall rtn))))))))
  4624. (org-agenda--insert-overriding-header
  4625. (with-temp-buffer
  4626. (insert "Headlines with TAGS match: ")
  4627. (add-text-properties (point-min) (1- (point))
  4628. (list 'face 'org-agenda-structure
  4629. 'short-heading
  4630. (concat "Match: " match)))
  4631. (setq pos (point))
  4632. (insert match "\n")
  4633. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4634. (setq pos (point))
  4635. (unless org-agenda-multi
  4636. (insert (substitute-command-keys
  4637. "Press \
  4638. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4639. to search again\n")))
  4640. (add-text-properties pos (1- (point))
  4641. (list 'face 'org-agenda-structure-secondary))
  4642. (buffer-string)))
  4643. (org-agenda-mark-header-line (point-min))
  4644. (when rtnall
  4645. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4646. (goto-char (point-min))
  4647. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4648. (add-text-properties
  4649. (point-min) (point-max)
  4650. `(org-agenda-type tags
  4651. org-last-args (,org--matcher-tags-todo-only ,match)
  4652. org-redo-cmd ,org-agenda-redo-command
  4653. org-series-cmd ,org-cmd))
  4654. (org-agenda-finalize)
  4655. (setq buffer-read-only t))))
  4656. ;;; Agenda Finding stuck projects
  4657. (defvar org-agenda-skip-regexp nil
  4658. "Regular expression used in skipping subtrees for the agenda.
  4659. This is basically a temporary global variable that can be set and then
  4660. used by user-defined selections using `org-agenda-skip-function'.")
  4661. (defvar org-agenda-overriding-header nil
  4662. "When set during agenda, todo and tags searches it replaces the header.
  4663. If an empty string, no header will be inserted. If any other
  4664. string, it will be inserted as a header. If a function, insert
  4665. the string returned by the function as a header. If nil, a
  4666. header will be generated automatically according to the command.
  4667. This variable should not be set directly, but custom commands can
  4668. bind it in the options section.")
  4669. (defun org-agenda-skip-entry-if (&rest conditions)
  4670. "Skip entry if any of CONDITIONS is true.
  4671. See `org-agenda-skip-if' for details."
  4672. (org-agenda-skip-if nil conditions))
  4673. (defun org-agenda-skip-subtree-if (&rest conditions)
  4674. "Skip subtree if any of CONDITIONS is true.
  4675. See `org-agenda-skip-if' for details."
  4676. (org-agenda-skip-if t conditions))
  4677. (defun org-agenda-skip-if (subtree conditions)
  4678. "Check current entity for CONDITIONS.
  4679. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4680. the entry (i.e. the text before the next heading) is checked.
  4681. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4682. from different tests. Valid conditions are:
  4683. scheduled Check if there is a scheduled cookie
  4684. notscheduled Check if there is no scheduled cookie
  4685. deadline Check if there is a deadline
  4686. notdeadline Check if there is no deadline
  4687. timestamp Check if there is a timestamp (also deadline or scheduled)
  4688. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4689. regexp Check if regexp matches
  4690. notregexp Check if regexp does not match.
  4691. todo Check if TODO keyword matches
  4692. nottodo Check if TODO keyword does not match
  4693. The regexp is taken from the conditions list, it must come right after
  4694. the `regexp' or `notregexp' element.
  4695. `todo' and `nottodo' accept as an argument a list of todo
  4696. keywords, which may include \"*\" to match any todo keyword.
  4697. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4698. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4699. Instead of a list, a keyword class may be given. For example:
  4700. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4701. would skip entries that haven't been marked with any of \"DONE\"
  4702. keywords. Possible classes are: `todo', `done', `any'.
  4703. If any of these conditions is met, this function returns the end point of
  4704. the entity, causing the search to continue from there. This is a function
  4705. that can be put into `org-agenda-skip-function' for the duration of a command."
  4706. (org-back-to-heading t)
  4707. (let* (;; (beg (point))
  4708. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4709. (org-entry-end-position)))
  4710. (planning-end (if subtree end (line-end-position 2)))
  4711. m)
  4712. (and
  4713. (or (and (memq 'scheduled conditions)
  4714. (re-search-forward org-scheduled-time-regexp planning-end t))
  4715. (and (memq 'notscheduled conditions)
  4716. (not
  4717. (save-excursion
  4718. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4719. (and (memq 'deadline conditions)
  4720. (re-search-forward org-deadline-time-regexp planning-end t))
  4721. (and (memq 'notdeadline conditions)
  4722. (not
  4723. (save-excursion
  4724. (re-search-forward org-deadline-time-regexp planning-end t))))
  4725. (and (memq 'timestamp conditions)
  4726. (re-search-forward org-ts-regexp end t))
  4727. (and (memq 'nottimestamp conditions)
  4728. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4729. (and (setq m (memq 'regexp conditions))
  4730. (stringp (nth 1 m))
  4731. (re-search-forward (nth 1 m) end t))
  4732. (and (setq m (memq 'notregexp conditions))
  4733. (stringp (nth 1 m))
  4734. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4735. (and (or
  4736. (setq m (memq 'nottodo conditions))
  4737. (setq m (memq 'todo-unblocked conditions))
  4738. (setq m (memq 'nottodo-unblocked conditions))
  4739. (setq m (memq 'todo conditions)))
  4740. (org-agenda-skip-if-todo m end)))
  4741. end)))
  4742. (defun org-agenda-skip-if-todo (args end)
  4743. "Helper function for `org-agenda-skip-if', do not use it directly.
  4744. ARGS is a list with first element either `todo', `nottodo',
  4745. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4746. a list of TODO keywords, or a state symbol `todo' or `done' or
  4747. `any'."
  4748. (let ((todo-re
  4749. (concat "^\\*+[ \t]+"
  4750. (regexp-opt
  4751. (pcase args
  4752. (`(,_ todo)
  4753. (org-delete-all org-done-keywords
  4754. (copy-sequence org-todo-keywords-1)))
  4755. (`(,_ done) org-done-keywords)
  4756. (`(,_ any) org-todo-keywords-1)
  4757. (`(,_ ,(pred atom))
  4758. (error "Invalid TODO class or type: %S" args))
  4759. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4760. (`(,_ ,todo-list) todo-list))
  4761. 'words))))
  4762. (pcase args
  4763. (`(todo . ,_)
  4764. (let (case-fold-search) (re-search-forward todo-re end t)))
  4765. (`(nottodo . ,_)
  4766. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4767. (`(todo-unblocked . ,_)
  4768. (catch :unblocked
  4769. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4770. (when (org-entry-blocked-p) (throw :unblocked t)))
  4771. nil))
  4772. (`(nottodo-unblocked . ,_)
  4773. (catch :unblocked
  4774. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4775. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4776. t))
  4777. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4778. ;;;###autoload
  4779. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4780. "Create agenda view for projects that are stuck.
  4781. Stuck projects are project that have no next actions. For the definitions
  4782. of what a project is and how to check if it stuck, customize the variable
  4783. `org-stuck-projects'."
  4784. (interactive)
  4785. (let* ((org-agenda-overriding-header
  4786. (or org-agenda-overriding-header "List of stuck projects: "))
  4787. (matcher (nth 0 org-stuck-projects))
  4788. (todo (nth 1 org-stuck-projects))
  4789. (tags (nth 2 org-stuck-projects))
  4790. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4791. (todo-wds
  4792. (if (not (member "*" todo)) todo
  4793. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4794. (org-delete-all org-done-keywords-for-agenda
  4795. (copy-sequence org-todo-keywords-for-agenda))))
  4796. (todo-re (and todo
  4797. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4798. (mapconcat #'identity todo-wds "\\|"))))
  4799. (tags-re (cond ((null tags) nil)
  4800. ((member "*" tags) org-tag-line-re)
  4801. (tags
  4802. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4803. (concat org-outline-regexp-bol
  4804. ".*?[ \t]:"
  4805. other-tags
  4806. (regexp-opt tags t)
  4807. ":" other-tags "[ \t]*$")))
  4808. (t nil)))
  4809. (re-list (delq nil (list todo-re tags-re gen-re)))
  4810. (skip-re
  4811. (if (null re-list)
  4812. (error "Missing information to identify unstuck projects")
  4813. (mapconcat #'identity re-list "\\|")))
  4814. (org-agenda-skip-function
  4815. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4816. ;; in the subtree.
  4817. (lambda ()
  4818. (and (save-excursion
  4819. (let ((case-fold-search nil))
  4820. (re-search-forward
  4821. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4822. (progn (outline-next-heading) (point))))))
  4823. (org-tags-view nil matcher)
  4824. (setq org-agenda-buffer-name (buffer-name))
  4825. (with-current-buffer org-agenda-buffer-name
  4826. (setq org-agenda-redo-command
  4827. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4828. (let ((inhibit-read-only t))
  4829. (add-text-properties
  4830. (point-min) (point-max)
  4831. `(org-redo-cmd ,org-agenda-redo-command))))))
  4832. ;;; Diary integration
  4833. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4834. (defvar diary-list-entries-hook)
  4835. (defvar diary-time-regexp)
  4836. (defvar diary-modify-entry-list-string-function)
  4837. (defvar diary-file-name-prefix)
  4838. (defvar diary-display-function)
  4839. (defun org-get-entries-from-diary (date)
  4840. "Get the (Emacs Calendar) diary entries for DATE."
  4841. (require 'diary-lib)
  4842. (declare-function diary-fancy-display "diary-lib" ())
  4843. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4844. (diary-display-function #'diary-fancy-display)
  4845. (pop-up-frames nil)
  4846. (diary-list-entries-hook
  4847. (cons 'org-diary-default-entry diary-list-entries-hook))
  4848. (diary-file-name-prefix nil) ; turn this feature off
  4849. (diary-modify-entry-list-string-function
  4850. #'org-modify-diary-entry-string)
  4851. (diary-time-regexp (concat "^" diary-time-regexp))
  4852. entries
  4853. (org-disable-agenda-to-diary t))
  4854. (save-excursion
  4855. (save-window-excursion
  4856. (diary-list-entries date 1)))
  4857. (if (not (get-buffer diary-fancy-buffer))
  4858. (setq entries nil)
  4859. (with-current-buffer diary-fancy-buffer
  4860. (setq buffer-read-only nil)
  4861. (if (zerop (buffer-size))
  4862. ;; No entries
  4863. (setq entries nil)
  4864. ;; Omit the date and other unnecessary stuff
  4865. (org-agenda-cleanup-fancy-diary)
  4866. ;; Add prefix to each line and extend the text properties
  4867. (if (zerop (buffer-size))
  4868. (setq entries nil)
  4869. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4870. (setq entries
  4871. (with-temp-buffer
  4872. (insert entries) (goto-char (point-min))
  4873. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4874. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4875. (replace-match (concat "; " (match-string 1)))))
  4876. (buffer-string)))))
  4877. (set-buffer-modified-p nil)
  4878. (kill-buffer diary-fancy-buffer)))
  4879. (when entries
  4880. (setq entries (org-split-string entries "\n"))
  4881. (setq entries
  4882. (mapcar
  4883. (lambda (x)
  4884. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4885. ;; Extend the text properties to the beginning of the line
  4886. (org-add-props x (text-properties-at (1- (length x)) x)
  4887. 'type "diary" 'date date 'face 'org-agenda-diary))
  4888. entries)))))
  4889. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4890. "Hook run when the fancy diary buffer is cleaned up.")
  4891. (defun org-agenda-cleanup-fancy-diary ()
  4892. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4893. This gets rid of the date, the underline under the date, and the
  4894. dummy entry installed by Org mode to ensure non-empty diary for
  4895. each date. It also removes lines that contain only whitespace."
  4896. (goto-char (point-min))
  4897. (if (looking-at ".*?:[ \t]*")
  4898. (progn
  4899. (replace-match "")
  4900. (re-search-forward "\n=+$" nil t)
  4901. (replace-match "")
  4902. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4903. (re-search-forward "\n=+$" nil t)
  4904. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4905. (goto-char (point-min))
  4906. (while (re-search-forward "^ +\n" nil t)
  4907. (replace-match ""))
  4908. (goto-char (point-min))
  4909. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4910. (replace-match ""))
  4911. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4912. (defun org-modify-diary-entry-string (string)
  4913. "Add text properties to string, allowing Org to act on it."
  4914. (org-add-props string nil
  4915. 'mouse-face 'highlight
  4916. 'help-echo (if buffer-file-name
  4917. (format "mouse-2 or RET jump to diary file %s"
  4918. (abbreviate-file-name buffer-file-name))
  4919. "")
  4920. 'org-agenda-diary-link t
  4921. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4922. (defun org-diary-default-entry ()
  4923. "Add a dummy entry to the diary.
  4924. Needed to avoid empty dates which mess up holiday display."
  4925. ;; Catch the error if dealing with the new add-to-diary-alist
  4926. (when org-disable-agenda-to-diary
  4927. (diary-add-to-list original-date "Org mode dummy" "")))
  4928. (defvar org-diary-last-run-time nil)
  4929. ;;;###autoload
  4930. (defun org-diary (&rest args)
  4931. "Return diary information from org files.
  4932. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4933. It accesses org files and extracts information from those files to be
  4934. listed in the diary. The function accepts arguments specifying what
  4935. items should be listed. For a list of arguments allowed here, see the
  4936. variable `org-agenda-entry-types'.
  4937. The call in the diary file should look like this:
  4938. &%%(org-diary) ~/path/to/some/orgfile.org
  4939. Use a separate line for each org file to check. Or, if you omit the file name,
  4940. all files listed in `org-agenda-files' will be checked automatically:
  4941. &%%(org-diary)
  4942. If you don't give any arguments (as in the example above), the default value
  4943. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4944. So the example above may also be written as
  4945. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4946. The function expects the lisp variables `entry' and `date' to be provided
  4947. by the caller, because this is how the calendar works. Don't use this
  4948. function from a program - use `org-agenda-get-day-entries' instead."
  4949. (with-no-warnings (defvar date) (defvar entry))
  4950. (when (> (- (float-time)
  4951. org-agenda-last-marker-time)
  4952. 5)
  4953. ;; I am not sure if this works with sticky agendas, because the marker
  4954. ;; list is then no longer a global variable.
  4955. (org-agenda-reset-markers))
  4956. (org-compile-prefix-format 'agenda)
  4957. (org-set-sorting-strategy 'agenda)
  4958. (setq args (or args org-agenda-entry-types))
  4959. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4960. (list entry)
  4961. (org-agenda-files t)))
  4962. (time (float-time))
  4963. file rtn results)
  4964. (when (or (not org-diary-last-run-time)
  4965. (> (- time
  4966. org-diary-last-run-time)
  4967. 3))
  4968. (org-agenda-prepare-buffers files))
  4969. (setq org-diary-last-run-time time)
  4970. ;; If this is called during org-agenda, don't return any entries to
  4971. ;; the calendar. Org Agenda will list these entries itself.
  4972. (when org-disable-agenda-to-diary (setq files nil))
  4973. (while (setq file (pop files))
  4974. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4975. (setq results (append results rtn)))
  4976. (when results
  4977. (setq results
  4978. (mapcar (lambda (i) (replace-regexp-in-string
  4979. org-link-bracket-re "\\2" i))
  4980. results))
  4981. (concat (org-agenda-finalize-entries results) "\n"))))
  4982. ;;; Agenda entry finders
  4983. (defun org-agenda--timestamp-to-absolute (&rest args)
  4984. "Call `org-time-string-to-absolute' with ARGS.
  4985. However, throw `:skip' whenever an error is raised."
  4986. (condition-case e
  4987. (apply #'org-time-string-to-absolute args)
  4988. (org-diary-sexp-no-match (throw :skip nil))
  4989. (error
  4990. (message "%s; Skipping entry" (error-message-string e))
  4991. (throw :skip nil))))
  4992. (defun org-agenda-get-day-entries (file date &rest args)
  4993. "Does the work for `org-diary' and `org-agenda'.
  4994. FILE is the path to a file to be checked for entries. DATE is date like
  4995. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4996. which kind of entries should be extracted. For details about these, see
  4997. the documentation of `org-diary'."
  4998. (let* ((org-startup-folded nil)
  4999. (org-startup-align-all-tables nil)
  5000. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5001. (error "No such file %s" file))))
  5002. (if (not buffer)
  5003. ;; If file does not exist, signal it in diary nonetheless.
  5004. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5005. (with-current-buffer buffer
  5006. (unless (derived-mode-p 'org-mode)
  5007. (error "Agenda file %s is not in Org mode" file))
  5008. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5009. (setf org-agenda-current-date date)
  5010. (save-excursion
  5011. (save-restriction
  5012. (if (eq buffer org-agenda-restrict)
  5013. (narrow-to-region org-agenda-restrict-begin
  5014. org-agenda-restrict-end)
  5015. (widen))
  5016. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5017. ;; first in order to populate DEADLINES before passing it.
  5018. ;;
  5019. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5020. ;; guarding us from modifying `org-agenda-entry-types'.
  5021. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5022. (when (and (memq :scheduled args) (memq :scheduled* args))
  5023. (setf args (delq :scheduled* args)))
  5024. (cond
  5025. ((memq :deadline args)
  5026. (setf args (cons :deadline
  5027. (delq :deadline (delq :deadline* args)))))
  5028. ((memq :deadline* args)
  5029. (setf args (cons :deadline* (delq :deadline* args)))))
  5030. ;; Collect list of headlines. Return them flattened.
  5031. (let ((case-fold-search nil) results deadlines)
  5032. (org-dlet
  5033. ((date date))
  5034. (dolist (arg args (apply #'nconc (nreverse results)))
  5035. (pcase arg
  5036. ((and :todo (guard (org-agenda-today-p date)))
  5037. (push (org-agenda-get-todos) results))
  5038. (:timestamp
  5039. (push (org-agenda-get-blocks) results)
  5040. (push (org-agenda-get-timestamps deadlines) results))
  5041. (:sexp
  5042. (push (org-agenda-get-sexps) results))
  5043. (:scheduled
  5044. (push (org-agenda-get-scheduled deadlines) results))
  5045. (:scheduled*
  5046. (push (org-agenda-get-scheduled deadlines t) results))
  5047. (:closed
  5048. (push (org-agenda-get-progress) results))
  5049. (:deadline
  5050. (setf deadlines (org-agenda-get-deadlines))
  5051. (push deadlines results))
  5052. (:deadline*
  5053. (setf deadlines (org-agenda-get-deadlines t))
  5054. (push deadlines results))))))))))))
  5055. (defsubst org-em (x y list)
  5056. "Is X or Y a member of LIST?"
  5057. (or (memq x list) (memq y list)))
  5058. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5059. (defvar org-agenda-sorting-strategy-selected nil)
  5060. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5061. "Retrieve timestamp information for sorting agenda views.
  5062. Given a point or marker POM, returns a cons cell of the timestamp
  5063. and the timestamp type relevant for the sorting strategy in
  5064. `org-agenda-sorting-strategy-selected'."
  5065. (let (ts ts-date-type)
  5066. (save-match-data
  5067. (cond ((org-em 'scheduled-up 'scheduled-down
  5068. org-agenda-sorting-strategy-selected)
  5069. (setq ts (org-entry-get pom "SCHEDULED")
  5070. ts-date-type " scheduled"))
  5071. ((org-em 'deadline-up 'deadline-down
  5072. org-agenda-sorting-strategy-selected)
  5073. (setq ts (org-entry-get pom "DEADLINE")
  5074. ts-date-type " deadline"))
  5075. ((org-em 'ts-up 'ts-down
  5076. org-agenda-sorting-strategy-selected)
  5077. (setq ts (org-entry-get pom "TIMESTAMP")
  5078. ts-date-type " timestamp"))
  5079. ((org-em 'tsia-up 'tsia-down
  5080. org-agenda-sorting-strategy-selected)
  5081. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5082. ts-date-type " timestamp_ia"))
  5083. ((org-em 'timestamp-up 'timestamp-down
  5084. org-agenda-sorting-strategy-selected)
  5085. (setq ts (or (org-entry-get pom "SCHEDULED")
  5086. (org-entry-get pom "DEADLINE")
  5087. (org-entry-get pom "TIMESTAMP")
  5088. (org-entry-get pom "TIMESTAMP_IA"))
  5089. ts-date-type ""))
  5090. (t (setq ts-date-type "")))
  5091. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5092. ts-date-type))))
  5093. (defun org-agenda-get-todos ()
  5094. "Return the TODO information for agenda display."
  5095. (let* ((props (list 'face nil
  5096. 'done-face 'org-agenda-done
  5097. 'org-not-done-regexp org-not-done-regexp
  5098. 'org-todo-regexp org-todo-regexp
  5099. 'org-complex-heading-regexp org-complex-heading-regexp
  5100. 'mouse-face 'highlight
  5101. 'help-echo
  5102. (format "mouse-2 or RET jump to org file %s"
  5103. (abbreviate-file-name buffer-file-name))))
  5104. (case-fold-search nil)
  5105. (regexp (format org-heading-keyword-regexp-format
  5106. (cond
  5107. ((and org-select-this-todo-keyword
  5108. (equal org-select-this-todo-keyword "*"))
  5109. org-todo-regexp)
  5110. (org-select-this-todo-keyword
  5111. (concat "\\("
  5112. (mapconcat #'identity
  5113. (org-split-string
  5114. org-select-this-todo-keyword
  5115. "|")
  5116. "\\|")
  5117. "\\)"))
  5118. (t org-not-done-regexp))))
  5119. marker priority category level tags todo-state
  5120. ts-date ts-date-type ts-date-pair
  5121. ee txt beg end inherited-tags todo-state-end-pos
  5122. effort effort-minutes)
  5123. (goto-char (point-min))
  5124. (while (re-search-forward regexp nil t)
  5125. (catch :skip
  5126. (save-match-data
  5127. (beginning-of-line)
  5128. (org-agenda-skip)
  5129. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5130. (unless (and (setq todo-state (org-get-todo-state))
  5131. (setq todo-state-end-pos (match-end 2)))
  5132. (goto-char end)
  5133. (throw :skip nil))
  5134. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5135. (goto-char (1+ beg))
  5136. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5137. (throw :skip nil)))
  5138. (goto-char (match-beginning 2))
  5139. (setq marker (org-agenda-new-marker (match-beginning 0))
  5140. category (org-get-category)
  5141. effort (save-match-data (or (get-text-property (point) 'effort)
  5142. (org-entry-get (point) org-effort-property)))
  5143. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5144. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5145. ts-date (car ts-date-pair)
  5146. ts-date-type (cdr ts-date-pair)
  5147. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5148. inherited-tags
  5149. (or (eq org-agenda-show-inherited-tags 'always)
  5150. (and (listp org-agenda-show-inherited-tags)
  5151. (memq 'todo org-agenda-show-inherited-tags))
  5152. (and (eq org-agenda-show-inherited-tags t)
  5153. (or (eq org-agenda-use-tag-inheritance t)
  5154. (memq 'todo org-agenda-use-tag-inheritance))))
  5155. tags (org-get-tags nil (not inherited-tags))
  5156. level (make-string (org-reduced-level (org-outline-level)) ? )
  5157. txt (org-agenda-format-item ""
  5158. (org-add-props txt nil
  5159. 'effort effort
  5160. 'effort-minutes effort-minutes)
  5161. level category tags t)
  5162. priority (1+ (org-get-priority txt)))
  5163. (org-add-props txt props
  5164. 'org-marker marker 'org-hd-marker marker
  5165. 'priority priority
  5166. 'effort effort 'effort-minutes effort-minutes
  5167. 'level level
  5168. 'ts-date ts-date
  5169. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5170. (push txt ee)
  5171. (if org-agenda-todo-list-sublevels
  5172. (goto-char todo-state-end-pos)
  5173. (org-end-of-subtree 'invisible))))
  5174. (nreverse ee)))
  5175. (defun org-agenda-todo-custom-ignore-p (time n)
  5176. "Check whether timestamp is farther away than n number of days.
  5177. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5178. `org-agenda-todo-ignore-scheduled' or
  5179. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5180. (let ((days (org-time-stamp-to-now
  5181. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5182. (if (>= n 0)
  5183. (>= days n)
  5184. (<= days n))))
  5185. ;;;###autoload
  5186. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5187. (&optional end)
  5188. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5189. (when (or org-agenda-todo-ignore-with-date
  5190. org-agenda-todo-ignore-scheduled
  5191. org-agenda-todo-ignore-deadlines
  5192. org-agenda-todo-ignore-timestamp)
  5193. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5194. (save-excursion
  5195. (or (and org-agenda-todo-ignore-with-date
  5196. (re-search-forward org-ts-regexp end t))
  5197. (and org-agenda-todo-ignore-scheduled
  5198. (re-search-forward org-scheduled-time-regexp end t)
  5199. (cond
  5200. ((eq org-agenda-todo-ignore-scheduled 'future)
  5201. (> (org-time-stamp-to-now
  5202. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5203. 0))
  5204. ((eq org-agenda-todo-ignore-scheduled 'past)
  5205. (<= (org-time-stamp-to-now
  5206. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5207. 0))
  5208. ((numberp org-agenda-todo-ignore-scheduled)
  5209. (org-agenda-todo-custom-ignore-p
  5210. (match-string 1) org-agenda-todo-ignore-scheduled))
  5211. (t)))
  5212. (and org-agenda-todo-ignore-deadlines
  5213. (re-search-forward org-deadline-time-regexp end t)
  5214. (cond
  5215. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5216. ((eq org-agenda-todo-ignore-deadlines 'far)
  5217. (not (org-deadline-close-p (match-string 1))))
  5218. ((eq org-agenda-todo-ignore-deadlines 'future)
  5219. (> (org-time-stamp-to-now
  5220. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5221. 0))
  5222. ((eq org-agenda-todo-ignore-deadlines 'past)
  5223. (<= (org-time-stamp-to-now
  5224. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5225. 0))
  5226. ((numberp org-agenda-todo-ignore-deadlines)
  5227. (org-agenda-todo-custom-ignore-p
  5228. (match-string 1) org-agenda-todo-ignore-deadlines))
  5229. (t (org-deadline-close-p (match-string 1)))))
  5230. (and org-agenda-todo-ignore-timestamp
  5231. (let ((buffer (current-buffer))
  5232. (regexp
  5233. (concat
  5234. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5235. (start (point)))
  5236. ;; Copy current buffer into a temporary one
  5237. (with-temp-buffer
  5238. (insert-buffer-substring buffer start end)
  5239. (goto-char (point-min))
  5240. ;; Delete SCHEDULED and DEADLINE items
  5241. (while (re-search-forward regexp end t)
  5242. (delete-region (match-beginning 0) (match-end 0)))
  5243. (goto-char (point-min))
  5244. ;; No search for timestamp left
  5245. (when (re-search-forward org-ts-regexp nil t)
  5246. (cond
  5247. ((eq org-agenda-todo-ignore-timestamp 'future)
  5248. (> (org-time-stamp-to-now
  5249. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5250. 0))
  5251. ((eq org-agenda-todo-ignore-timestamp 'past)
  5252. (<= (org-time-stamp-to-now
  5253. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5254. 0))
  5255. ((numberp org-agenda-todo-ignore-timestamp)
  5256. (org-agenda-todo-custom-ignore-p
  5257. (match-string 1) org-agenda-todo-ignore-timestamp))
  5258. (t))))))))))
  5259. (defun org-agenda-get-timestamps (&optional deadlines)
  5260. "Return the date stamp information for agenda display.
  5261. Optional argument DEADLINES is a list of deadline items to be
  5262. displayed in agenda view."
  5263. (with-no-warnings (defvar date))
  5264. (let* ((props (list 'face 'org-agenda-calendar-event
  5265. 'org-not-done-regexp org-not-done-regexp
  5266. 'org-todo-regexp org-todo-regexp
  5267. 'org-complex-heading-regexp org-complex-heading-regexp
  5268. 'mouse-face 'highlight
  5269. 'help-echo
  5270. (format "mouse-2 or RET jump to Org file %s"
  5271. (abbreviate-file-name buffer-file-name))))
  5272. (current (calendar-absolute-from-gregorian date))
  5273. (today (org-today))
  5274. (deadline-position-alist
  5275. (mapcar (lambda (d)
  5276. (let ((m (get-text-property 0 'org-hd-marker d)))
  5277. (and m (marker-position m))))
  5278. deadlines))
  5279. ;; Match time-stamps set to current date, time-stamps with
  5280. ;; a repeater, and S-exp time-stamps.
  5281. (regexp
  5282. (concat
  5283. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5284. (regexp-quote
  5285. (substring
  5286. (format-time-string
  5287. (car org-time-stamp-formats)
  5288. (encode-time ; DATE bound by calendar
  5289. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5290. 1 11))
  5291. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5292. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5293. timestamp-items)
  5294. (goto-char (point-min))
  5295. (while (re-search-forward regexp nil t)
  5296. ;; Skip date ranges, scheduled and deadlines, which are handled
  5297. ;; specially. Also skip time-stamps before first headline as
  5298. ;; there would be no entry to add to the agenda. Eventually,
  5299. ;; ignore clock entries.
  5300. (catch :skip
  5301. (save-match-data
  5302. (when (or (org-at-date-range-p)
  5303. (org-at-planning-p)
  5304. (org-before-first-heading-p)
  5305. (and org-agenda-include-inactive-timestamps
  5306. (org-at-clock-log-p))
  5307. (not (org-at-timestamp-p 'agenda)))
  5308. (throw :skip nil))
  5309. (org-agenda-skip))
  5310. (let* ((pos (match-beginning 0))
  5311. (repeat (match-string 1))
  5312. (sexp-entry (match-string 3))
  5313. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5314. (save-excursion
  5315. (goto-char pos)
  5316. (looking-at org-ts-regexp-both)
  5317. (match-string 0))))
  5318. (todo-state (org-get-todo-state))
  5319. (warntime (get-text-property (point) 'org-appt-warntime))
  5320. (done? (member todo-state org-done-keywords)))
  5321. ;; Possibly skip done tasks.
  5322. (when (and done? org-agenda-skip-timestamp-if-done)
  5323. (throw :skip t))
  5324. ;; S-exp entry doesn't match current day: skip it.
  5325. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5326. (throw :skip nil))
  5327. (when repeat
  5328. (let* ((past
  5329. ;; A repeating time stamp is shown at its base
  5330. ;; date and every repeated date up to TODAY. If
  5331. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5332. ;; however, only the last repeat before today
  5333. ;; (inclusive) is shown.
  5334. (org-agenda--timestamp-to-absolute
  5335. repeat
  5336. (if (or (> current today)
  5337. (eq org-agenda-prefer-last-repeat t)
  5338. (member todo-state org-agenda-prefer-last-repeat))
  5339. today
  5340. current)
  5341. 'past (current-buffer) pos))
  5342. (future
  5343. ;; Display every repeated date past TODAY
  5344. ;; (exclusive) unless
  5345. ;; `org-agenda-show-future-repeats' is nil. If
  5346. ;; this variable is set to `next', only display
  5347. ;; the first repeated date after TODAY
  5348. ;; (exclusive).
  5349. (cond
  5350. ((<= current today) past)
  5351. ((not org-agenda-show-future-repeats) past)
  5352. (t
  5353. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5354. (1+ today)
  5355. current)))
  5356. (org-agenda--timestamp-to-absolute
  5357. repeat base 'future (current-buffer) pos))))))
  5358. (when (and (/= current past) (/= current future))
  5359. (throw :skip nil))))
  5360. (save-excursion
  5361. (re-search-backward org-outline-regexp-bol nil t)
  5362. ;; Possibly skip time-stamp when a deadline is set.
  5363. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5364. (assq (point) deadline-position-alist))
  5365. (throw :skip nil))
  5366. (let* ((category (org-get-category pos))
  5367. (effort (org-entry-get pos org-effort-property))
  5368. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5369. (inherited-tags
  5370. (or (eq org-agenda-show-inherited-tags 'always)
  5371. (and (consp org-agenda-show-inherited-tags)
  5372. (memq 'agenda org-agenda-show-inherited-tags))
  5373. (and (eq org-agenda-show-inherited-tags t)
  5374. (or (eq org-agenda-use-tag-inheritance t)
  5375. (memq 'agenda
  5376. org-agenda-use-tag-inheritance)))))
  5377. (tags (org-get-tags nil (not inherited-tags)))
  5378. (level (make-string (org-reduced-level (org-outline-level))
  5379. ?\s))
  5380. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5381. (match-string 1)))
  5382. (inactive? (= (char-after pos) ?\[))
  5383. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5384. (item
  5385. (org-agenda-format-item
  5386. (and inactive? org-agenda-inactive-leader)
  5387. (org-add-props head nil
  5388. 'effort effort
  5389. 'effort-minutes effort-minutes)
  5390. level category tags time-stamp org-ts-regexp habit?)))
  5391. (org-add-props item props
  5392. 'priority (if habit?
  5393. (org-habit-get-priority (org-habit-parse-todo))
  5394. (org-get-priority item))
  5395. 'org-marker (org-agenda-new-marker pos)
  5396. 'org-hd-marker (org-agenda-new-marker)
  5397. 'date date
  5398. 'level level
  5399. 'effort effort 'effort-minutes effort-minutes
  5400. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5401. current)
  5402. 'todo-state todo-state
  5403. 'warntime warntime
  5404. 'type "timestamp")
  5405. (push item timestamp-items))))
  5406. (when org-agenda-skip-additional-timestamps-same-entry
  5407. (outline-next-heading))))
  5408. (nreverse timestamp-items)))
  5409. (defun org-agenda-get-sexps ()
  5410. "Return the sexp information for agenda display."
  5411. (require 'diary-lib)
  5412. (with-no-warnings (defvar date) (defvar entry))
  5413. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5414. 'mouse-face 'highlight
  5415. 'help-echo
  5416. (format "mouse-2 or RET jump to org file %s"
  5417. (abbreviate-file-name buffer-file-name))))
  5418. (regexp "^&?%%(")
  5419. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5420. ;; so as to "hide" any current binding for it?
  5421. marker category extra level ee txt tags entry
  5422. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5423. effort effort-minutes)
  5424. (goto-char (point-min))
  5425. (while (re-search-forward regexp nil t)
  5426. (catch :skip
  5427. (org-agenda-skip)
  5428. (setq beg (match-beginning 0))
  5429. (goto-char (1- (match-end 0)))
  5430. (setq b (point))
  5431. (forward-sexp 1)
  5432. (setq sexp (buffer-substring b (point)))
  5433. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5434. (org-trim (match-string 1))
  5435. ""))
  5436. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5437. (when result
  5438. (setq marker (org-agenda-new-marker beg)
  5439. level (make-string (org-reduced-level (org-outline-level)) ? )
  5440. category (org-get-category beg)
  5441. effort (save-match-data (or (get-text-property (point) 'effort)
  5442. (org-entry-get (point) org-effort-property)))
  5443. inherited-tags
  5444. (or (eq org-agenda-show-inherited-tags 'always)
  5445. (and (listp org-agenda-show-inherited-tags)
  5446. (memq 'agenda org-agenda-show-inherited-tags))
  5447. (and (eq org-agenda-show-inherited-tags t)
  5448. (or (eq org-agenda-use-tag-inheritance t)
  5449. (memq 'agenda org-agenda-use-tag-inheritance))))
  5450. tags (org-get-tags nil (not inherited-tags))
  5451. todo-state (org-get-todo-state)
  5452. warntime (get-text-property (point) 'org-appt-warntime)
  5453. extra nil)
  5454. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5455. (dolist (r (if (stringp result)
  5456. (list result)
  5457. result)) ;; we expect a list here
  5458. (when (and org-agenda-diary-sexp-prefix
  5459. (string-match org-agenda-diary-sexp-prefix r))
  5460. (setq extra (match-string 0 r)
  5461. r (replace-match "" nil nil r)))
  5462. (if (string-match "\\S-" r)
  5463. (setq txt r)
  5464. (setq txt "SEXP entry returned empty string"))
  5465. (setq txt (org-agenda-format-item extra
  5466. (org-add-props txt nil
  5467. 'effort effort
  5468. 'effort-minutes effort-minutes)
  5469. level category tags 'time))
  5470. (org-add-props txt props 'org-marker marker
  5471. 'date date 'todo-state todo-state
  5472. 'effort effort 'effort-minutes effort-minutes
  5473. 'level level 'type "sexp" 'warntime warntime)
  5474. (push txt ee)))))
  5475. (nreverse ee)))
  5476. ;; Calendar sanity: define some functions that are independent of
  5477. ;; `calendar-date-style'.
  5478. (defun org-anniversary (year month day &optional mark)
  5479. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5480. (with-no-warnings
  5481. (let ((calendar-date-style 'iso))
  5482. (diary-anniversary year month day mark))))
  5483. (defun org-cyclic (N year month day &optional mark)
  5484. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5485. (with-no-warnings
  5486. (let ((calendar-date-style 'iso))
  5487. (diary-cyclic N year month day mark))))
  5488. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5489. "Like `diary-block', but with fixed (ISO) order of arguments."
  5490. (with-no-warnings
  5491. (let ((calendar-date-style 'iso))
  5492. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5493. (defun org-date (year month day &optional mark)
  5494. "Like `diary-date', but with fixed (ISO) order of arguments."
  5495. (with-no-warnings
  5496. (let ((calendar-date-style 'iso))
  5497. (diary-date year month day mark))))
  5498. ;; Define the `org-class' function
  5499. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5500. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5501. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5502. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5503. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5504. `holidays', then any date that is known by the Emacs calendar to be a
  5505. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5506. then those holidays will be skipped."
  5507. (with-no-warnings (defvar date) (defvar entry))
  5508. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5509. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5510. (d (calendar-absolute-from-gregorian date))
  5511. (h (when skip-weeks (calendar-check-holidays date))))
  5512. (and
  5513. (<= date1 d)
  5514. (<= d date2)
  5515. (= (calendar-day-of-week date) dayname)
  5516. (or (not skip-weeks)
  5517. (progn
  5518. (require 'cal-iso)
  5519. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5520. (not (or (and h (memq 'holidays skip-weeks))
  5521. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5522. entry)))
  5523. (defalias 'org-get-closed #'org-agenda-get-progress)
  5524. (defun org-agenda-get-progress ()
  5525. "Return the logged TODO entries for agenda display."
  5526. (with-no-warnings (defvar date))
  5527. (let* ((props (list 'mouse-face 'highlight
  5528. 'org-not-done-regexp org-not-done-regexp
  5529. 'org-todo-regexp org-todo-regexp
  5530. 'org-complex-heading-regexp org-complex-heading-regexp
  5531. 'help-echo
  5532. (format "mouse-2 or RET jump to org file %s"
  5533. (abbreviate-file-name buffer-file-name))))
  5534. (items (if (consp org-agenda-show-log-scoped)
  5535. org-agenda-show-log-scoped
  5536. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5537. '(clock)
  5538. org-agenda-log-mode-items)))
  5539. (parts
  5540. (delq nil
  5541. (list
  5542. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5543. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5544. (when (memq 'state items)
  5545. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5546. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5547. (error "`org-agenda-log-mode-items' is empty")))
  5548. (regexp (concat
  5549. "\\(" parts-re "\\)"
  5550. " *\\["
  5551. (regexp-quote
  5552. (substring
  5553. (format-time-string
  5554. (car org-time-stamp-formats)
  5555. (encode-time ; DATE bound by calendar
  5556. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5557. 1 11))))
  5558. (org-agenda-search-headline-for-time nil)
  5559. marker hdmarker priority category level tags closedp type
  5560. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5561. effort effort-minutes)
  5562. (goto-char (point-min))
  5563. (while (re-search-forward regexp nil t)
  5564. (catch :skip
  5565. (org-agenda-skip)
  5566. (setq marker (org-agenda-new-marker (match-beginning 0))
  5567. closedp (equal (match-string 1) org-closed-string)
  5568. statep (equal (string-to-char (match-string 1)) ?-)
  5569. clockp (not (or closedp statep))
  5570. state (and statep (match-string 2))
  5571. category (org-get-category (match-beginning 0))
  5572. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  5573. effort (save-match-data (or (get-text-property (point) 'effort)
  5574. (org-entry-get (point) org-effort-property))))
  5575. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5576. (when (string-match "\\]" timestr)
  5577. ;; substring should only run to end of time stamp
  5578. (setq rest (substring timestr (match-end 0))
  5579. timestr (substring timestr 0 (match-end 0)))
  5580. (if (and (not closedp) (not statep)
  5581. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5582. rest))
  5583. (progn (setq timestr (concat (substring timestr 0 -1)
  5584. "-" (match-string 1 rest) "]"))
  5585. (setq clocked (match-string 2 rest)))
  5586. (setq clocked "-")))
  5587. (save-excursion
  5588. (setq extra
  5589. (cond
  5590. ((not org-agenda-log-mode-add-notes) nil)
  5591. (statep
  5592. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5593. (match-string 1)))
  5594. (clockp
  5595. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5596. (match-string 1)))))
  5597. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5598. (throw :skip nil)
  5599. (goto-char (match-beginning 0))
  5600. (setq hdmarker (org-agenda-new-marker)
  5601. inherited-tags
  5602. (or (eq org-agenda-show-inherited-tags 'always)
  5603. (and (listp org-agenda-show-inherited-tags)
  5604. (memq 'todo org-agenda-show-inherited-tags))
  5605. (and (eq org-agenda-show-inherited-tags t)
  5606. (or (eq org-agenda-use-tag-inheritance t)
  5607. (memq 'todo org-agenda-use-tag-inheritance))))
  5608. tags (org-get-tags nil (not inherited-tags))
  5609. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5610. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5611. (setq txt (match-string 1))
  5612. (when extra
  5613. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5614. (setq txt (concat (substring txt 0 (match-beginning 1))
  5615. " - " extra " " (match-string 2 txt)))
  5616. (setq txt (concat txt " - " extra))))
  5617. (setq txt (org-agenda-format-item
  5618. (cond
  5619. (closedp "Closed: ")
  5620. (statep (concat "State: (" state ")"))
  5621. (t (concat "Clocked: (" clocked ")")))
  5622. (org-add-props txt nil
  5623. 'effort effort
  5624. 'effort-minutes effort-minutes)
  5625. level category tags timestr)))
  5626. (setq type (cond (closedp "closed")
  5627. (statep "state")
  5628. (t "clock")))
  5629. (setq priority 100000)
  5630. (org-add-props txt props
  5631. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5632. 'priority priority 'level level
  5633. 'effort effort 'effort-minutes effort-minutes
  5634. 'type type 'date date
  5635. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5636. (push txt ee))
  5637. (goto-char (point-at-eol))))
  5638. (nreverse ee)))
  5639. (defun org-agenda-show-clocking-issues ()
  5640. "Add overlays, showing issues with clocking.
  5641. See also the user option `org-agenda-clock-consistency-checks'."
  5642. (interactive)
  5643. (let* ((pl org-agenda-clock-consistency-checks)
  5644. (re (concat "^[ \t]*"
  5645. org-clock-string
  5646. "[ \t]+"
  5647. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5648. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5649. (tlstart 0.)
  5650. (tlend 0.)
  5651. (maxtime (org-duration-to-minutes
  5652. (or (plist-get pl :max-duration) "24:00")))
  5653. (mintime (org-duration-to-minutes
  5654. (or (plist-get pl :min-duration) 0)))
  5655. (maxgap (org-duration-to-minutes
  5656. ;; default 30:00 means never complain
  5657. (or (plist-get pl :max-gap) "30:00")))
  5658. (gapok (mapcar #'org-duration-to-minutes
  5659. (plist-get pl :gap-ok-around)))
  5660. (def-face (or (plist-get pl :default-face)
  5661. '((:background "DarkRed") (:foreground "white"))))
  5662. issue face m te ts dt ov)
  5663. (goto-char (point-min))
  5664. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5665. (setq issue nil face def-face)
  5666. (catch 'next
  5667. (setq m (org-get-at-bol 'org-marker)
  5668. te nil ts nil)
  5669. (unless (and m (markerp m))
  5670. (setq issue "No valid clock line") (throw 'next t))
  5671. (org-with-point-at m
  5672. (save-excursion
  5673. (goto-char (point-at-bol))
  5674. (unless (looking-at re)
  5675. (error "No valid Clock line")
  5676. (throw 'next t))
  5677. (unless (match-end 3)
  5678. (setq issue
  5679. (format
  5680. "No end time: (%s)"
  5681. (org-duration-from-minutes
  5682. (floor
  5683. (- (float-time (org-current-time))
  5684. (float-time (org-time-string-to-time (match-string 1))))
  5685. 60)))
  5686. face (or (plist-get pl :no-end-time-face) face))
  5687. (throw 'next t))
  5688. (setq ts (match-string 1)
  5689. te (match-string 3)
  5690. ts (float-time (org-time-string-to-time ts))
  5691. te (float-time (org-time-string-to-time te))
  5692. dt (- te ts))))
  5693. (cond
  5694. ((> dt (* 60 maxtime))
  5695. ;; a very long clocking chunk
  5696. (setq issue (format "Clocking interval is very long: %s"
  5697. (org-duration-from-minutes (floor dt 60)))
  5698. face (or (plist-get pl :long-face) face)))
  5699. ((< dt (* 60 mintime))
  5700. ;; a very short clocking chunk
  5701. (setq issue (format "Clocking interval is very short: %s"
  5702. (org-duration-from-minutes (floor dt 60)))
  5703. face (or (plist-get pl :short-face) face)))
  5704. ((and (> tlend 0) (< ts tlend))
  5705. ;; Two clock entries are overlapping
  5706. (setq issue (format "Clocking overlap: %d minutes"
  5707. (/ (- tlend ts) 60))
  5708. face (or (plist-get pl :overlap-face) face)))
  5709. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5710. ;; There is a gap, lets see if we need to report it
  5711. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5712. (setq issue (format "Clocking gap: %d minutes"
  5713. (/ (- ts tlend) 60))
  5714. face (or (plist-get pl :gap-face) face))))
  5715. (t nil)))
  5716. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5717. (when issue
  5718. ;; OK, there was some issue, add an overlay to show the issue
  5719. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5720. (overlay-put ov 'before-string
  5721. (concat
  5722. (org-add-props
  5723. (format "%-43s" (concat " " issue))
  5724. nil
  5725. 'face face)
  5726. "\n"))
  5727. (overlay-put ov 'evaporate t)))))
  5728. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5729. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5730. (catch 'exit
  5731. (unless ok-list
  5732. ;; there are no OK times for gaps...
  5733. (throw 'exit nil))
  5734. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5735. ;; This is more than 24 hours, so it is OK.
  5736. ;; because we have at least one OK time, that must be in the
  5737. ;; 24 hour interval.
  5738. (throw 'exit t))
  5739. ;; We have a shorter gap.
  5740. ;; Now we have to get the minute of the day when these times are
  5741. (let* ((t1dec (decode-time t1))
  5742. (t2dec (decode-time t2))
  5743. ;; compute the minute on the day
  5744. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5745. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5746. (when (< min2 min1)
  5747. ;; if min2 is smaller than min1, this means it is on the next day.
  5748. ;; Wrap it to after midnight.
  5749. (setq min2 (+ min2 1440)))
  5750. ;; Now check if any of the OK times is in the gap
  5751. (mapc (lambda (x)
  5752. ;; Wrap the time to after midnight if necessary
  5753. (when (< x min1) (setq x (+ x 1440)))
  5754. ;; Check if in interval
  5755. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5756. ok-list)
  5757. ;; Nope, this gap is not OK
  5758. nil)))
  5759. (defun org-agenda-get-deadlines (&optional with-hour)
  5760. "Return the deadline information for agenda display.
  5761. When WITH-HOUR is non-nil, only return deadlines with an hour
  5762. specification like [h]h:mm."
  5763. (with-no-warnings (defvar date))
  5764. (let* ((props (list 'mouse-face 'highlight
  5765. 'org-not-done-regexp org-not-done-regexp
  5766. 'org-todo-regexp org-todo-regexp
  5767. 'org-complex-heading-regexp org-complex-heading-regexp
  5768. 'help-echo
  5769. (format "mouse-2 or RET jump to org file %s"
  5770. (abbreviate-file-name buffer-file-name))))
  5771. (regexp (if with-hour
  5772. org-deadline-time-hour-regexp
  5773. org-deadline-time-regexp))
  5774. (today (org-today))
  5775. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5776. (current (calendar-absolute-from-gregorian date))
  5777. deadline-items)
  5778. (goto-char (point-min))
  5779. (if (org-element--cache-active-p)
  5780. (org-element-cache-map
  5781. (lambda (el)
  5782. (when (and (org-element-property :deadline el)
  5783. (or (not with-hour)
  5784. (org-element-property
  5785. :hour-start
  5786. (org-element-property :deadline el))
  5787. (org-element-property
  5788. :hour-end
  5789. (org-element-property :deadline el))))
  5790. (goto-char (org-element-property :contents-begin el))
  5791. (catch :skip
  5792. (org-agenda-skip el)
  5793. (let* ((s (substring (org-element-property
  5794. :raw-value
  5795. (org-element-property :deadline el))
  5796. 1 -1))
  5797. (pos (save-excursion
  5798. (goto-char (org-element-property :contents-begin el))
  5799. ;; We intentionally leave NOERROR
  5800. ;; argument in `re-search-forward' nil. If
  5801. ;; the search fails here, something went
  5802. ;; wrong and we are looking at
  5803. ;; non-matching headline.
  5804. (re-search-forward regexp (line-end-position))
  5805. (1- (match-beginning 1))))
  5806. (todo-state (org-element-property :todo-keyword el))
  5807. (done? (eq 'done (org-element-property :todo-type el)))
  5808. (sexp? (eq 'diary
  5809. (org-element-property
  5810. :type (org-element-property :deadline el))))
  5811. ;; DEADLINE is the deadline date for the entry. It is
  5812. ;; either the base date or the last repeat, according
  5813. ;; to `org-agenda-prefer-last-repeat'.
  5814. (deadline
  5815. (cond
  5816. (sexp? (org-agenda--timestamp-to-absolute s current))
  5817. ((or (eq org-agenda-prefer-last-repeat t)
  5818. (member todo-state org-agenda-prefer-last-repeat))
  5819. (org-agenda--timestamp-to-absolute
  5820. s today 'past (current-buffer) pos))
  5821. (t (org-agenda--timestamp-to-absolute s))))
  5822. ;; REPEAT is the future repeat closest from CURRENT,
  5823. ;; according to `org-agenda-show-future-repeats'. If
  5824. ;; the latter is nil, or if the time stamp has no
  5825. ;; repeat part, default to DEADLINE.
  5826. (repeat
  5827. (cond
  5828. (sexp? deadline)
  5829. ((<= current today) deadline)
  5830. ((not org-agenda-show-future-repeats) deadline)
  5831. (t
  5832. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5833. (1+ today)
  5834. current)))
  5835. (org-agenda--timestamp-to-absolute
  5836. s base 'future (current-buffer) pos)))))
  5837. (diff (- deadline current))
  5838. (suppress-prewarning
  5839. (let ((scheduled
  5840. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5841. (org-element-property
  5842. :raw-value
  5843. (org-element-property :scheduled el)))))
  5844. (cond
  5845. ((not scheduled) nil)
  5846. ;; The current item has a scheduled date, so
  5847. ;; evaluate its prewarning lead time.
  5848. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5849. ;; Use global prewarning-restart lead time.
  5850. org-agenda-skip-deadline-prewarning-if-scheduled)
  5851. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5852. 'pre-scheduled)
  5853. ;; Set pre-warning to no earlier than SCHEDULED.
  5854. (min (- deadline
  5855. (org-agenda--timestamp-to-absolute scheduled))
  5856. org-deadline-warning-days))
  5857. ;; Set pre-warning to deadline.
  5858. (t 0))))
  5859. (wdays (or suppress-prewarning (org-get-wdays s))))
  5860. (cond
  5861. ;; Only display deadlines at their base date, at future
  5862. ;; repeat occurrences or in today agenda.
  5863. ((= current deadline) nil)
  5864. ((= current repeat) nil)
  5865. ((not today?) (throw :skip nil))
  5866. ;; Upcoming deadline: display within warning period WDAYS.
  5867. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5868. ;; Overdue deadline: warn about it for
  5869. ;; `org-deadline-past-days' duration.
  5870. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5871. ;; Possibly skip done tasks.
  5872. (when (and done?
  5873. (or org-agenda-skip-deadline-if-done
  5874. (/= deadline current)))
  5875. (throw :skip nil))
  5876. (save-excursion
  5877. (goto-char (org-element-property :begin el))
  5878. (let* ((category (org-get-category))
  5879. (effort (save-match-data (or (get-text-property (point) 'effort)
  5880. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5881. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5882. (level (make-string (org-element-property :level el)
  5883. ?\s))
  5884. (head (save-excursion
  5885. (goto-char (org-element-property :begin el))
  5886. (re-search-forward org-outline-regexp-bol)
  5887. (buffer-substring-no-properties (point) (line-end-position))))
  5888. (inherited-tags
  5889. (or (eq org-agenda-show-inherited-tags 'always)
  5890. (and (listp org-agenda-show-inherited-tags)
  5891. (memq 'agenda org-agenda-show-inherited-tags))
  5892. (and (eq org-agenda-show-inherited-tags t)
  5893. (or (eq org-agenda-use-tag-inheritance t)
  5894. (memq 'agenda
  5895. org-agenda-use-tag-inheritance)))))
  5896. (tags (org-get-tags el (not inherited-tags)))
  5897. (time
  5898. (cond
  5899. ;; No time of day designation if it is only
  5900. ;; a reminder.
  5901. ((and (/= current deadline) (/= current repeat)) nil)
  5902. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5903. (concat (substring s (match-beginning 1)) " "))
  5904. (t 'time)))
  5905. (item
  5906. (org-agenda-format-item
  5907. ;; Insert appropriate suffixes before deadlines.
  5908. ;; Those only apply to today agenda.
  5909. (pcase-let ((`(,now ,future ,past)
  5910. org-agenda-deadline-leaders))
  5911. (cond
  5912. ((and today? (< deadline today)) (format past (- diff)))
  5913. ((and today? (> deadline today)) (format future diff))
  5914. (t now)))
  5915. (org-add-props head nil
  5916. 'effort effort
  5917. 'effort-minutes effort-minutes)
  5918. level category tags time))
  5919. (face (org-agenda-deadline-face
  5920. (- 1 (/ (float diff) (max wdays 1)))))
  5921. (upcoming? (and today? (> deadline today)))
  5922. (warntime (get-text-property (point) 'org-appt-warntime)))
  5923. (org-add-props item props
  5924. 'org-marker (org-agenda-new-marker pos)
  5925. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5926. 'warntime warntime
  5927. 'level level
  5928. 'effort effort 'effort-minutes effort-minutes
  5929. 'ts-date deadline
  5930. 'priority
  5931. ;; Adjust priority to today reminders about deadlines.
  5932. ;; Overdue deadlines get the highest priority
  5933. ;; increase, then imminent deadlines and eventually
  5934. ;; more distant deadlines.
  5935. (let ((adjust (if today? (- diff) 0)))
  5936. (+ adjust (org-get-priority item)))
  5937. 'todo-state todo-state
  5938. 'type (if upcoming? "upcoming-deadline" "deadline")
  5939. 'date (if upcoming? date deadline)
  5940. 'face (if done? 'org-agenda-done face)
  5941. 'undone-face face
  5942. 'done-face 'org-agenda-done)
  5943. (push item deadline-items)))))))
  5944. :next-re regexp
  5945. :fail-re regexp
  5946. :narrow t)
  5947. (while (re-search-forward regexp nil t)
  5948. (catch :skip
  5949. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5950. (org-agenda-skip)
  5951. (let* ((s (match-string 1))
  5952. (pos (1- (match-beginning 1)))
  5953. (todo-state (save-match-data (org-get-todo-state)))
  5954. (done? (member todo-state org-done-keywords))
  5955. (sexp? (string-prefix-p "%%" s))
  5956. ;; DEADLINE is the deadline date for the entry. It is
  5957. ;; either the base date or the last repeat, according
  5958. ;; to `org-agenda-prefer-last-repeat'.
  5959. (deadline
  5960. (cond
  5961. (sexp? (org-agenda--timestamp-to-absolute s current))
  5962. ((or (eq org-agenda-prefer-last-repeat t)
  5963. (member todo-state org-agenda-prefer-last-repeat))
  5964. (org-agenda--timestamp-to-absolute
  5965. s today 'past (current-buffer) pos))
  5966. (t (org-agenda--timestamp-to-absolute s))))
  5967. ;; REPEAT is the future repeat closest from CURRENT,
  5968. ;; according to `org-agenda-show-future-repeats'. If
  5969. ;; the latter is nil, or if the time stamp has no
  5970. ;; repeat part, default to DEADLINE.
  5971. (repeat
  5972. (cond
  5973. (sexp? deadline)
  5974. ((<= current today) deadline)
  5975. ((not org-agenda-show-future-repeats) deadline)
  5976. (t
  5977. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5978. (1+ today)
  5979. current)))
  5980. (org-agenda--timestamp-to-absolute
  5981. s base 'future (current-buffer) pos)))))
  5982. (diff (- deadline current))
  5983. (suppress-prewarning
  5984. (let ((scheduled
  5985. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5986. (org-entry-get nil "SCHEDULED"))))
  5987. (cond
  5988. ((not scheduled) nil)
  5989. ;; The current item has a scheduled date, so
  5990. ;; evaluate its prewarning lead time.
  5991. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5992. ;; Use global prewarning-restart lead time.
  5993. org-agenda-skip-deadline-prewarning-if-scheduled)
  5994. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5995. 'pre-scheduled)
  5996. ;; Set pre-warning to no earlier than SCHEDULED.
  5997. (min (- deadline
  5998. (org-agenda--timestamp-to-absolute scheduled))
  5999. org-deadline-warning-days))
  6000. ;; Set pre-warning to deadline.
  6001. (t 0))))
  6002. (wdays (or suppress-prewarning (org-get-wdays s))))
  6003. (cond
  6004. ;; Only display deadlines at their base date, at future
  6005. ;; repeat occurrences or in today agenda.
  6006. ((= current deadline) nil)
  6007. ((= current repeat) nil)
  6008. ((not today?) (throw :skip nil))
  6009. ;; Upcoming deadline: display within warning period WDAYS.
  6010. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6011. ;; Overdue deadline: warn about it for
  6012. ;; `org-deadline-past-days' duration.
  6013. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6014. ;; Possibly skip done tasks.
  6015. (when (and done?
  6016. (or org-agenda-skip-deadline-if-done
  6017. (/= deadline current)))
  6018. (throw :skip nil))
  6019. (save-excursion
  6020. (re-search-backward "^\\*+[ \t]+" nil t)
  6021. (goto-char (match-end 0))
  6022. (let* ((category (org-get-category))
  6023. (effort (save-match-data (or (get-text-property (point) 'effort)
  6024. (org-entry-get (point) org-effort-property))))
  6025. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6026. (level (make-string (org-reduced-level (org-outline-level))
  6027. ?\s))
  6028. (head (buffer-substring-no-properties
  6029. (point) (line-end-position)))
  6030. (inherited-tags
  6031. (or (eq org-agenda-show-inherited-tags 'always)
  6032. (and (listp org-agenda-show-inherited-tags)
  6033. (memq 'agenda org-agenda-show-inherited-tags))
  6034. (and (eq org-agenda-show-inherited-tags t)
  6035. (or (eq org-agenda-use-tag-inheritance t)
  6036. (memq 'agenda
  6037. org-agenda-use-tag-inheritance)))))
  6038. (tags (org-get-tags nil (not inherited-tags)))
  6039. (time
  6040. (cond
  6041. ;; No time of day designation if it is only
  6042. ;; a reminder.
  6043. ((and (/= current deadline) (/= current repeat)) nil)
  6044. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6045. (concat (substring s (match-beginning 1)) " "))
  6046. (t 'time)))
  6047. (item
  6048. (org-agenda-format-item
  6049. ;; Insert appropriate suffixes before deadlines.
  6050. ;; Those only apply to today agenda.
  6051. (pcase-let ((`(,now ,future ,past)
  6052. org-agenda-deadline-leaders))
  6053. (cond
  6054. ((and today? (< deadline today)) (format past (- diff)))
  6055. ((and today? (> deadline today)) (format future diff))
  6056. (t now)))
  6057. (org-add-props head nil
  6058. 'effort effort
  6059. 'effort-minutes effort-minutes)
  6060. level category tags time))
  6061. (face (org-agenda-deadline-face
  6062. (- 1 (/ (float diff) (max wdays 1)))))
  6063. (upcoming? (and today? (> deadline today)))
  6064. (warntime (get-text-property (point) 'org-appt-warntime)))
  6065. (org-add-props item props
  6066. 'org-marker (org-agenda-new-marker pos)
  6067. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6068. 'warntime warntime
  6069. 'level level
  6070. 'effort effort 'effort-minutes effort-minutes
  6071. 'ts-date deadline
  6072. 'priority
  6073. ;; Adjust priority to today reminders about deadlines.
  6074. ;; Overdue deadlines get the highest priority
  6075. ;; increase, then imminent deadlines and eventually
  6076. ;; more distant deadlines.
  6077. (let ((adjust (if today? (- diff) 0)))
  6078. (+ adjust (org-get-priority item)))
  6079. 'todo-state todo-state
  6080. 'type (if upcoming? "upcoming-deadline" "deadline")
  6081. 'date (if upcoming? date deadline)
  6082. 'face (if done? 'org-agenda-done face)
  6083. 'undone-face face
  6084. 'done-face 'org-agenda-done)
  6085. (push item deadline-items)))))))
  6086. (nreverse deadline-items)))
  6087. (defun org-agenda-deadline-face (fraction)
  6088. "Return the face to displaying a deadline item.
  6089. FRACTION is what fraction of the head-warning time has passed."
  6090. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6091. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6092. "Return the scheduled information for agenda display.
  6093. Optional argument DEADLINES is a list of deadline items to be
  6094. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6095. scheduled items with an hour specification like [h]h:mm."
  6096. (with-no-warnings (defvar date))
  6097. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6098. 'org-todo-regexp org-todo-regexp
  6099. 'org-complex-heading-regexp org-complex-heading-regexp
  6100. 'done-face 'org-agenda-done
  6101. 'mouse-face 'highlight
  6102. 'help-echo
  6103. (format "mouse-2 or RET jump to Org file %s"
  6104. (abbreviate-file-name buffer-file-name))))
  6105. (regexp (if with-hour
  6106. org-scheduled-time-hour-regexp
  6107. org-scheduled-time-regexp))
  6108. (today (org-today))
  6109. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6110. (current (calendar-absolute-from-gregorian date))
  6111. (deadline-pos
  6112. (mapcar (lambda (d)
  6113. (let ((m (get-text-property 0 'org-hd-marker d)))
  6114. (and m (marker-position m))))
  6115. deadlines))
  6116. scheduled-items)
  6117. (goto-char (point-min))
  6118. (if (org-element--cache-active-p)
  6119. (org-element-cache-map
  6120. (lambda (el)
  6121. (when (and (org-element-property :scheduled el)
  6122. (or (not with-hour)
  6123. (org-element-property
  6124. :hour-start
  6125. (org-element-property :scheduled el))
  6126. (org-element-property
  6127. :hour-end
  6128. (org-element-property :scheduled el))))
  6129. (goto-char (org-element-property :contents-begin el))
  6130. (catch :skip
  6131. (org-agenda-skip el)
  6132. (let* ((s (substring (org-element-property
  6133. :raw-value
  6134. (org-element-property :scheduled el))
  6135. 1 -1))
  6136. (pos (save-excursion
  6137. (goto-char (org-element-property :contents-begin el))
  6138. ;; We intentionally leave NOERROR
  6139. ;; argument in `re-search-forward' nil. If
  6140. ;; the search fails here, something went
  6141. ;; wrong and we are looking at
  6142. ;; non-matching headline.
  6143. (re-search-forward regexp (line-end-position))
  6144. (1- (match-beginning 1))))
  6145. (todo-state (org-element-property :todo-keyword el))
  6146. (donep (eq 'done (org-element-property :todo-type el)))
  6147. (sexp? (eq 'diary
  6148. (org-element-property
  6149. :type (org-element-property :scheduled el))))
  6150. ;; SCHEDULE is the scheduled date for the entry. It is
  6151. ;; either the bare date or the last repeat, according
  6152. ;; to `org-agenda-prefer-last-repeat'.
  6153. (schedule
  6154. (cond
  6155. (sexp? (org-agenda--timestamp-to-absolute s current))
  6156. ((or (eq org-agenda-prefer-last-repeat t)
  6157. (member todo-state org-agenda-prefer-last-repeat))
  6158. (org-agenda--timestamp-to-absolute
  6159. s today 'past (current-buffer) pos))
  6160. (t (org-agenda--timestamp-to-absolute s))))
  6161. ;; REPEAT is the future repeat closest from CURRENT,
  6162. ;; according to `org-agenda-show-future-repeats'. If
  6163. ;; the latter is nil, or if the time stamp has no
  6164. ;; repeat part, default to SCHEDULE.
  6165. (repeat
  6166. (cond
  6167. (sexp? schedule)
  6168. ((<= current today) schedule)
  6169. ((not org-agenda-show-future-repeats) schedule)
  6170. (t
  6171. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6172. (1+ today)
  6173. current)))
  6174. (org-agenda--timestamp-to-absolute
  6175. s base 'future (current-buffer) pos)))))
  6176. (diff (- current schedule))
  6177. (warntime (get-text-property (point) 'org-appt-warntime))
  6178. (pastschedp (< schedule today))
  6179. (futureschedp (> schedule today))
  6180. (habitp (and (fboundp 'org-is-habit-p)
  6181. (string= "habit" (org-element-property :STYLE el))))
  6182. (suppress-delay
  6183. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6184. (org-element-property
  6185. :raw-value
  6186. (org-element-property :deadline el)))))
  6187. (cond
  6188. ((not deadline) nil)
  6189. ;; The current item has a deadline date, so
  6190. ;; evaluate its delay time.
  6191. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6192. ;; Use global delay time.
  6193. (- org-agenda-skip-scheduled-delay-if-deadline))
  6194. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6195. 'post-deadline)
  6196. ;; Set delay to no later than DEADLINE.
  6197. (min (- schedule
  6198. (org-agenda--timestamp-to-absolute deadline))
  6199. org-scheduled-delay-days))
  6200. (t 0))))
  6201. (ddays
  6202. (cond
  6203. ;; Nullify delay when a repeater triggered already
  6204. ;; and the delay is of the form --Xd.
  6205. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6206. (> schedule (org-agenda--timestamp-to-absolute s)))
  6207. 0)
  6208. (suppress-delay
  6209. (let ((org-scheduled-delay-days suppress-delay))
  6210. (org-get-wdays s t t)))
  6211. (t (org-get-wdays s t)))))
  6212. ;; Display scheduled items at base date (SCHEDULE), today if
  6213. ;; scheduled before the current date, and at any repeat past
  6214. ;; today. However, skip delayed items and items that have
  6215. ;; been displayed for more than `org-scheduled-past-days'.
  6216. (unless (and todayp
  6217. habitp
  6218. (bound-and-true-p org-habit-show-all-today))
  6219. (when (or (and (> ddays 0) (< diff ddays))
  6220. (> diff (or (and habitp org-habit-scheduled-past-days)
  6221. org-scheduled-past-days))
  6222. (> schedule current)
  6223. (and (/= current schedule)
  6224. (/= current today)
  6225. (/= current repeat)))
  6226. (throw :skip nil)))
  6227. ;; Possibly skip done tasks.
  6228. (when (and donep
  6229. (or org-agenda-skip-scheduled-if-done
  6230. (/= schedule current)))
  6231. (throw :skip nil))
  6232. ;; Skip entry if it already appears as a deadline, per
  6233. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6234. ;; doesn't apply to habits.
  6235. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6236. ((guard
  6237. (or (not (memq (line-beginning-position 0) deadline-pos))
  6238. habitp))
  6239. nil)
  6240. (`repeated-after-deadline
  6241. (let ((deadline (time-to-days
  6242. (when (org-element-property :deadline el)
  6243. (org-time-string-to-time
  6244. (org-element-property :deadline el))))))
  6245. (and (<= schedule deadline) (> current deadline))))
  6246. (`not-today pastschedp)
  6247. (`t t)
  6248. (_ nil))
  6249. (throw :skip nil))
  6250. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6251. ;; only show them for today. Also skip done habits.
  6252. (when (and habitp
  6253. (or donep
  6254. (not (bound-and-true-p org-habit-show-habits))
  6255. (and (not todayp)
  6256. (bound-and-true-p
  6257. org-habit-show-habits-only-for-today))))
  6258. (throw :skip nil))
  6259. (save-excursion
  6260. (goto-char (org-element-property :begin el))
  6261. (let* ((category (org-get-category))
  6262. (effort (save-match-data
  6263. (or (get-text-property (point) 'effort)
  6264. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6265. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6266. (inherited-tags
  6267. (or (eq org-agenda-show-inherited-tags 'always)
  6268. (and (listp org-agenda-show-inherited-tags)
  6269. (memq 'agenda org-agenda-show-inherited-tags))
  6270. (and (eq org-agenda-show-inherited-tags t)
  6271. (or (eq org-agenda-use-tag-inheritance t)
  6272. (memq 'agenda
  6273. org-agenda-use-tag-inheritance)))))
  6274. (tags (org-get-tags el (not inherited-tags)))
  6275. (level (make-string (org-element-property :level el)
  6276. ?\s))
  6277. (head (save-excursion
  6278. (goto-char (org-element-property :begin el))
  6279. (re-search-forward org-outline-regexp-bol)
  6280. (buffer-substring (point) (line-end-position))))
  6281. (time
  6282. (cond
  6283. ;; No time of day designation if it is only a
  6284. ;; reminder, except for habits, which always show
  6285. ;; the time of day. Habits are an exception
  6286. ;; because if there is a time of day, that is
  6287. ;; interpreted to mean they should usually happen
  6288. ;; then, even if doing the habit was missed.
  6289. ((and
  6290. (not habitp)
  6291. (/= current schedule)
  6292. (/= current repeat))
  6293. nil)
  6294. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6295. (concat (substring s (match-beginning 1)) " "))
  6296. (t 'time)))
  6297. (item
  6298. (org-agenda-format-item
  6299. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6300. ;; Show a reminder of a past scheduled today.
  6301. (if (and todayp pastschedp)
  6302. (format past diff)
  6303. first))
  6304. (org-add-props head nil
  6305. 'effort effort
  6306. 'effort-minutes effort-minutes)
  6307. level category tags time nil habitp))
  6308. (face (cond ((and (not habitp) pastschedp)
  6309. 'org-scheduled-previously)
  6310. ((and habitp futureschedp)
  6311. 'org-agenda-done)
  6312. (todayp 'org-scheduled-today)
  6313. (t 'org-scheduled)))
  6314. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6315. (org-add-props item props
  6316. 'undone-face face
  6317. 'face (if donep 'org-agenda-done face)
  6318. 'org-marker (org-agenda-new-marker pos)
  6319. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6320. 'type (if pastschedp "past-scheduled" "scheduled")
  6321. 'date (if pastschedp schedule date)
  6322. 'ts-date schedule
  6323. 'warntime warntime
  6324. 'level level
  6325. 'effort effort 'effort-minutes effort-minutes
  6326. 'priority (if habitp (org-habit-get-priority habitp)
  6327. (+ 99 diff (org-get-priority item)))
  6328. 'org-habit-p habitp
  6329. 'todo-state todo-state)
  6330. (push item scheduled-items)))))))
  6331. :next-re regexp
  6332. :fail-re regexp
  6333. :narrow t)
  6334. (while (re-search-forward regexp nil t)
  6335. (catch :skip
  6336. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6337. (org-agenda-skip)
  6338. (let* ((s (match-string 1))
  6339. (pos (1- (match-beginning 1)))
  6340. (todo-state (save-match-data (org-get-todo-state)))
  6341. (donep (member todo-state org-done-keywords))
  6342. (sexp? (string-prefix-p "%%" s))
  6343. ;; SCHEDULE is the scheduled date for the entry. It is
  6344. ;; either the bare date or the last repeat, according
  6345. ;; to `org-agenda-prefer-last-repeat'.
  6346. (schedule
  6347. (cond
  6348. (sexp? (org-agenda--timestamp-to-absolute s current))
  6349. ((or (eq org-agenda-prefer-last-repeat t)
  6350. (member todo-state org-agenda-prefer-last-repeat))
  6351. (org-agenda--timestamp-to-absolute
  6352. s today 'past (current-buffer) pos))
  6353. (t (org-agenda--timestamp-to-absolute s))))
  6354. ;; REPEAT is the future repeat closest from CURRENT,
  6355. ;; according to `org-agenda-show-future-repeats'. If
  6356. ;; the latter is nil, or if the time stamp has no
  6357. ;; repeat part, default to SCHEDULE.
  6358. (repeat
  6359. (cond
  6360. (sexp? schedule)
  6361. ((<= current today) schedule)
  6362. ((not org-agenda-show-future-repeats) schedule)
  6363. (t
  6364. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6365. (1+ today)
  6366. current)))
  6367. (org-agenda--timestamp-to-absolute
  6368. s base 'future (current-buffer) pos)))))
  6369. (diff (- current schedule))
  6370. (warntime (get-text-property (point) 'org-appt-warntime))
  6371. (pastschedp (< schedule today))
  6372. (futureschedp (> schedule today))
  6373. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6374. (suppress-delay
  6375. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6376. (org-entry-get nil "DEADLINE"))))
  6377. (cond
  6378. ((not deadline) nil)
  6379. ;; The current item has a deadline date, so
  6380. ;; evaluate its delay time.
  6381. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6382. ;; Use global delay time.
  6383. (- org-agenda-skip-scheduled-delay-if-deadline))
  6384. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6385. 'post-deadline)
  6386. ;; Set delay to no later than DEADLINE.
  6387. (min (- schedule
  6388. (org-agenda--timestamp-to-absolute deadline))
  6389. org-scheduled-delay-days))
  6390. (t 0))))
  6391. (ddays
  6392. (cond
  6393. ;; Nullify delay when a repeater triggered already
  6394. ;; and the delay is of the form --Xd.
  6395. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6396. (> schedule (org-agenda--timestamp-to-absolute s)))
  6397. 0)
  6398. (suppress-delay
  6399. (let ((org-scheduled-delay-days suppress-delay))
  6400. (org-get-wdays s t t)))
  6401. (t (org-get-wdays s t)))))
  6402. ;; Display scheduled items at base date (SCHEDULE), today if
  6403. ;; scheduled before the current date, and at any repeat past
  6404. ;; today. However, skip delayed items and items that have
  6405. ;; been displayed for more than `org-scheduled-past-days'.
  6406. (unless (and todayp
  6407. habitp
  6408. (bound-and-true-p org-habit-show-all-today))
  6409. (when (or (and (> ddays 0) (< diff ddays))
  6410. (> diff (or (and habitp org-habit-scheduled-past-days)
  6411. org-scheduled-past-days))
  6412. (> schedule current)
  6413. (and (/= current schedule)
  6414. (/= current today)
  6415. (/= current repeat)))
  6416. (throw :skip nil)))
  6417. ;; Possibly skip done tasks.
  6418. (when (and donep
  6419. (or org-agenda-skip-scheduled-if-done
  6420. (/= schedule current)))
  6421. (throw :skip nil))
  6422. ;; Skip entry if it already appears as a deadline, per
  6423. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6424. ;; doesn't apply to habits.
  6425. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6426. ((guard
  6427. (or (not (memq (line-beginning-position 0) deadline-pos))
  6428. habitp))
  6429. nil)
  6430. (`repeated-after-deadline
  6431. (let ((deadline (time-to-days
  6432. (org-get-deadline-time (point)))))
  6433. (and (<= schedule deadline) (> current deadline))))
  6434. (`not-today pastschedp)
  6435. (`t t)
  6436. (_ nil))
  6437. (throw :skip nil))
  6438. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6439. ;; only show them for today. Also skip done habits.
  6440. (when (and habitp
  6441. (or donep
  6442. (not (bound-and-true-p org-habit-show-habits))
  6443. (and (not todayp)
  6444. (bound-and-true-p
  6445. org-habit-show-habits-only-for-today))))
  6446. (throw :skip nil))
  6447. (save-excursion
  6448. (re-search-backward "^\\*+[ \t]+" nil t)
  6449. (goto-char (match-end 0))
  6450. (let* ((category (org-get-category))
  6451. (effort (save-match-data (or (get-text-property (point) 'effort)
  6452. (org-entry-get (point) org-effort-property))))
  6453. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6454. (inherited-tags
  6455. (or (eq org-agenda-show-inherited-tags 'always)
  6456. (and (listp org-agenda-show-inherited-tags)
  6457. (memq 'agenda org-agenda-show-inherited-tags))
  6458. (and (eq org-agenda-show-inherited-tags t)
  6459. (or (eq org-agenda-use-tag-inheritance t)
  6460. (memq 'agenda
  6461. org-agenda-use-tag-inheritance)))))
  6462. (tags (org-get-tags nil (not inherited-tags)))
  6463. (level (make-string (org-reduced-level (org-outline-level))
  6464. ?\s))
  6465. (head (buffer-substring (point) (line-end-position)))
  6466. (time
  6467. (cond
  6468. ;; No time of day designation if it is only a
  6469. ;; reminder, except for habits, which always show
  6470. ;; the time of day. Habits are an exception
  6471. ;; because if there is a time of day, that is
  6472. ;; interpreted to mean they should usually happen
  6473. ;; then, even if doing the habit was missed.
  6474. ((and
  6475. (not habitp)
  6476. (/= current schedule)
  6477. (/= current repeat))
  6478. nil)
  6479. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6480. (concat (substring s (match-beginning 1)) " "))
  6481. (t 'time)))
  6482. (item
  6483. (org-agenda-format-item
  6484. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6485. ;; Show a reminder of a past scheduled today.
  6486. (if (and todayp pastschedp)
  6487. (format past diff)
  6488. first))
  6489. (org-add-props head nil
  6490. 'effort effort
  6491. 'effort-minutes effort-minutes)
  6492. level category tags time nil habitp))
  6493. (face (cond ((and (not habitp) pastschedp)
  6494. 'org-scheduled-previously)
  6495. ((and habitp futureschedp)
  6496. 'org-agenda-done)
  6497. (todayp 'org-scheduled-today)
  6498. (t 'org-scheduled)))
  6499. (habitp (and habitp (org-habit-parse-todo))))
  6500. (org-add-props item props
  6501. 'undone-face face
  6502. 'face (if donep 'org-agenda-done face)
  6503. 'org-marker (org-agenda-new-marker pos)
  6504. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6505. 'type (if pastschedp "past-scheduled" "scheduled")
  6506. 'date (if pastschedp schedule date)
  6507. 'ts-date schedule
  6508. 'warntime warntime
  6509. 'level level
  6510. 'effort effort 'effort-minutes effort-minutes
  6511. 'priority (if habitp (org-habit-get-priority habitp)
  6512. (+ 99 diff (org-get-priority item)))
  6513. 'org-habit-p habitp
  6514. 'todo-state todo-state)
  6515. (push item scheduled-items)))))))
  6516. (nreverse scheduled-items)))
  6517. (defun org-agenda-get-blocks ()
  6518. "Return the date-range information for agenda display."
  6519. (with-no-warnings (defvar date))
  6520. (let* ((props (list 'face nil
  6521. 'org-not-done-regexp org-not-done-regexp
  6522. 'org-todo-regexp org-todo-regexp
  6523. 'org-complex-heading-regexp org-complex-heading-regexp
  6524. 'mouse-face 'highlight
  6525. 'help-echo
  6526. (format "mouse-2 or RET jump to org file %s"
  6527. (abbreviate-file-name buffer-file-name))))
  6528. (regexp org-tr-regexp)
  6529. (d0 (calendar-absolute-from-gregorian date))
  6530. marker hdmarker ee txt d1 d2 s1 s2 category
  6531. level todo-state tags pos head donep inherited-tags
  6532. effort effort-minutes)
  6533. (goto-char (point-min))
  6534. (while (re-search-forward regexp nil t)
  6535. (catch :skip
  6536. (org-agenda-skip)
  6537. (setq pos (point))
  6538. (let ((start-time (match-string 1))
  6539. (end-time (match-string 2)))
  6540. (setq s1 (match-string 1)
  6541. s2 (match-string 2)
  6542. d1 (time-to-days
  6543. (condition-case err
  6544. (org-time-string-to-time s1)
  6545. (error
  6546. (error
  6547. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6548. s1
  6549. pos
  6550. (current-buffer)
  6551. (error-message-string err)))))
  6552. d2 (time-to-days
  6553. (condition-case err
  6554. (org-time-string-to-time s2)
  6555. (error
  6556. (error
  6557. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6558. s2
  6559. pos
  6560. (current-buffer)
  6561. (error-message-string err))))))
  6562. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6563. ;; Only allow days between the limits, because the normal
  6564. ;; date stamps will catch the limits.
  6565. (save-excursion
  6566. (setq todo-state (org-get-todo-state))
  6567. (setq donep (member todo-state org-done-keywords))
  6568. (when (and donep org-agenda-skip-timestamp-if-done)
  6569. (throw :skip t))
  6570. (setq marker (org-agenda-new-marker (point))
  6571. category (org-get-category))
  6572. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6573. (org-entry-get (point) org-effort-property))))
  6574. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6575. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6576. (throw :skip nil)
  6577. (goto-char (match-beginning 0))
  6578. (setq hdmarker (org-agenda-new-marker (point))
  6579. inherited-tags
  6580. (or (eq org-agenda-show-inherited-tags 'always)
  6581. (and (listp org-agenda-show-inherited-tags)
  6582. (memq 'agenda org-agenda-show-inherited-tags))
  6583. (and (eq org-agenda-show-inherited-tags t)
  6584. (or (eq org-agenda-use-tag-inheritance t)
  6585. (memq 'agenda org-agenda-use-tag-inheritance))))
  6586. tags (org-get-tags nil (not inherited-tags)))
  6587. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6588. (looking-at "\\*+[ \t]+\\(.*\\)")
  6589. (setq head (match-string 1))
  6590. (let ((remove-re
  6591. (if org-agenda-remove-timeranges-from-blocks
  6592. (concat
  6593. "<" (regexp-quote s1) ".*?>"
  6594. "--"
  6595. "<" (regexp-quote s2) ".*?>")
  6596. nil)))
  6597. (setq txt (org-agenda-format-item
  6598. (format
  6599. (nth (if (= d1 d2) 0 1)
  6600. org-agenda-timerange-leaders)
  6601. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6602. (org-add-props head nil
  6603. 'effort effort
  6604. 'effort-minutes effort-minutes)
  6605. level category tags
  6606. (save-match-data
  6607. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6608. (match-string 6 s1)))
  6609. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6610. (match-string 6 s2))))
  6611. (cond ((string= hhmm1 hhmm2)
  6612. (concat "<" start-time ">--<" end-time ">"))
  6613. ((and (= d1 d0) (= d2 d0))
  6614. (concat "<" start-time ">--<" end-time ">"))
  6615. ((= d1 d0)
  6616. (concat "<" start-time ">"))
  6617. ((= d2 d0)
  6618. (concat "<" end-time ">")))))
  6619. remove-re))))
  6620. (org-add-props txt props
  6621. 'org-marker marker 'org-hd-marker hdmarker
  6622. 'type "block" 'date date
  6623. 'level level
  6624. 'effort effort 'effort-minutes effort-minutes
  6625. 'todo-state todo-state
  6626. 'priority (org-get-priority txt))
  6627. (push txt ee))))
  6628. (goto-char pos)))
  6629. ;; Sort the entries by expiration date.
  6630. (nreverse ee)))
  6631. ;;; Agenda presentation and sorting
  6632. (defvar org-prefix-has-time nil
  6633. "A flag, set by `org-compile-prefix-format'.
  6634. The flag is set if the currently compiled format contains a `%t'.")
  6635. (defvar org-prefix-has-tag nil
  6636. "A flag, set by `org-compile-prefix-format'.
  6637. The flag is set if the currently compiled format contains a `%T'.")
  6638. (defvar org-prefix-has-effort nil
  6639. "A flag, set by `org-compile-prefix-format'.
  6640. The flag is set if the currently compiled format contains a `%e'.")
  6641. (defvar org-prefix-has-breadcrumbs nil
  6642. "A flag, set by `org-compile-prefix-format'.
  6643. The flag is set if the currently compiled format contains a `%b'.")
  6644. (defvar org-prefix-category-length nil
  6645. "Used by `org-compile-prefix-format' to remember the category field width.")
  6646. (defvar org-prefix-category-max-length nil
  6647. "Used by `org-compile-prefix-format' to remember the category field width.")
  6648. (defun org-agenda-get-category-icon (category)
  6649. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6650. (cl-dolist (entry org-agenda-category-icon-alist)
  6651. (when (string-match-p (car entry) category)
  6652. (if (listp (cadr entry))
  6653. (cl-return (cadr entry))
  6654. (cl-return (apply #'create-image (cdr entry)))))))
  6655. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6656. remove-re habitp)
  6657. "Format TXT to be inserted into the agenda buffer.
  6658. In particular, add the prefix and corresponding text properties.
  6659. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6660. WITH-LEVEL may be a string to replace the `%l' specifier.
  6661. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6662. category taken from local variable or file name. It will replace the `%c'
  6663. specifier in the format.
  6664. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6665. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6666. When DOTIME is a string, this string is searched for a time before TXT is.
  6667. TAGS can be the tags of the headline.
  6668. Any match of REMOVE-RE will be removed from TXT."
  6669. ;; We keep the org-prefix-* variable values along with a compiled
  6670. ;; formatter, so that multiple agendas existing at the same time do
  6671. ;; not step on each other toes.
  6672. ;;
  6673. ;; It was inconvenient to make these variables buffer local in
  6674. ;; Agenda buffers, because this function expects to be called with
  6675. ;; the buffer where item comes from being current, and not agenda
  6676. ;; buffer
  6677. (let* ((bindings (car org-prefix-format-compiled))
  6678. (formatter (cadr org-prefix-format-compiled)))
  6679. (cl-loop for (var value) in bindings
  6680. do (set var value))
  6681. (save-match-data
  6682. ;; Diary entries sometimes have extra whitespace at the beginning
  6683. (setq txt (org-trim txt))
  6684. ;; Fix the tags part in txt
  6685. (setq txt (org-agenda-fix-displayed-tags
  6686. txt tags
  6687. org-agenda-show-inherited-tags
  6688. org-agenda-hide-tags-regexp))
  6689. (with-no-warnings
  6690. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6691. ;; Based on what I see in `org-compile-prefix-format', I added
  6692. ;; a few more.
  6693. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6694. (defvar effort) (defvar extra)
  6695. (defvar level) (defvar tag) (defvar time))
  6696. (let* ((category (or with-category
  6697. (if buffer-file-name
  6698. (file-name-sans-extension
  6699. (file-name-nondirectory buffer-file-name))
  6700. "")))
  6701. (category-icon (org-agenda-get-category-icon category))
  6702. (category-icon (if category-icon
  6703. (propertize " " 'display category-icon)
  6704. ""))
  6705. (effort (and (not (string= txt ""))
  6706. (get-text-property 1 'effort txt)))
  6707. (tag (if tags (nth (1- (length tags)) tags) ""))
  6708. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6709. (extra (or (and (not habitp) extra) ""))
  6710. time
  6711. (ts (when dotime (concat
  6712. (if (stringp dotime) dotime "")
  6713. (and org-agenda-search-headline-for-time txt))))
  6714. (time-of-day (and dotime (org-get-time-of-day ts)))
  6715. stamp plain s0 s1 s2 rtn srp l
  6716. duration breadcrumbs)
  6717. (and (derived-mode-p 'org-mode) buffer-file-name
  6718. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6719. (when (and dotime time-of-day)
  6720. ;; Extract starting and ending time and move them to prefix
  6721. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6722. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6723. (setq s0 (match-string 0 ts)
  6724. srp (and stamp (match-end 3))
  6725. s1 (match-string (if plain 1 2) ts)
  6726. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6727. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6728. ;; them, we might want to remove them there to avoid duplication.
  6729. ;; The user can turn this off with a variable.
  6730. (when (and org-prefix-has-time
  6731. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6732. (string-match (concat (regexp-quote s0) " *") txt)
  6733. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6734. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6735. (= (match-beginning 0) 0)
  6736. t))
  6737. (setq txt (replace-match "" nil nil txt))))
  6738. ;; Normalize the time(s) to 24 hour.
  6739. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6740. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6741. ;; Try to set s2 if s1 and
  6742. ;; `org-agenda-default-appointment-duration' are set
  6743. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6744. (setq s2
  6745. (org-duration-from-minutes
  6746. (+ (org-duration-to-minutes s1 t)
  6747. org-agenda-default-appointment-duration)
  6748. nil t)))
  6749. ;; Compute the duration
  6750. (when s2
  6751. (setq duration (- (org-duration-to-minutes s2)
  6752. (org-duration-to-minutes s1))))
  6753. ;; Format S1 and S2 for display.
  6754. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6755. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6756. (when (string-match org-tag-group-re txt)
  6757. ;; Tags are in the string
  6758. (if (or (eq org-agenda-remove-tags t)
  6759. (and org-agenda-remove-tags
  6760. org-prefix-has-tag))
  6761. (setq txt (replace-match "" t t txt))
  6762. (setq txt (replace-match
  6763. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6764. (match-string 1 txt))
  6765. t t txt))))
  6766. (when remove-re
  6767. (while (string-match remove-re txt)
  6768. (setq txt (replace-match "" t t txt))))
  6769. ;; Set org-heading property on `txt' to mark the start of the
  6770. ;; heading.
  6771. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6772. ;; Prepare the variables needed in the eval of the compiled format
  6773. (when org-prefix-has-breadcrumbs
  6774. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6775. (let ((s (org-format-outline-path (org-get-outline-path)
  6776. (1- (frame-width))
  6777. nil org-agenda-breadcrumbs-separator)))
  6778. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6779. (setq time (cond (s2 (concat
  6780. (org-agenda-time-of-day-to-ampm-maybe s1)
  6781. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6782. (when org-agenda-timegrid-use-ampm " ")))
  6783. (s1 (concat
  6784. (org-agenda-time-of-day-to-ampm-maybe s1)
  6785. (if org-agenda-timegrid-use-ampm
  6786. (concat time-grid-trailing-characters " ")
  6787. time-grid-trailing-characters)))
  6788. (t ""))
  6789. category (if (symbolp category) (symbol-name category) category)
  6790. level (or with-level ""))
  6791. (if (string-match org-link-bracket-re category)
  6792. (progn
  6793. (setq l (string-width (or (match-string 2) (match-string 1))))
  6794. (when (< l (or org-prefix-category-length 0))
  6795. (setq category (copy-sequence category))
  6796. (org-add-props category nil
  6797. 'extra-space (make-string
  6798. (- org-prefix-category-length l 1) ?\ ))))
  6799. (when (and org-prefix-category-max-length
  6800. (>= (length category) org-prefix-category-max-length))
  6801. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6802. ;; Evaluate the compiled format
  6803. (setq rtn (concat (eval formatter t) txt))
  6804. ;; And finally add the text properties
  6805. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6806. (org-add-props rtn nil
  6807. 'org-category category
  6808. 'tags tags
  6809. 'org-priority-highest org-priority-highest
  6810. 'org-priority-lowest org-priority-lowest
  6811. 'time-of-day time-of-day
  6812. 'duration duration
  6813. 'breadcrumbs breadcrumbs
  6814. 'txt txt
  6815. 'level level
  6816. 'time time
  6817. 'extra extra
  6818. 'format org-prefix-format-compiled
  6819. 'dotime dotime)))))
  6820. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6821. "Remove tags string from TXT, and add a modified list of tags.
  6822. The modified list may contain inherited tags, and tags matched by
  6823. `org-agenda-hide-tags-regexp' will be removed."
  6824. (when (or add-inherited hide-re)
  6825. (when (string-match org-tag-group-re txt)
  6826. (setq txt (substring txt 0 (match-beginning 0))))
  6827. (setq tags
  6828. (delq nil
  6829. (mapcar (lambda (tg)
  6830. (if (or (and hide-re (string-match hide-re tg))
  6831. (and (not add-inherited)
  6832. (get-text-property 0 'inherited tg)))
  6833. nil
  6834. tg))
  6835. tags)))
  6836. (when tags
  6837. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6838. i)
  6839. (setq txt (concat txt " :"
  6840. (mapconcat
  6841. (lambda (x)
  6842. (setq i (get-text-property 0 'inherited x))
  6843. (if (and have-i (not i))
  6844. (progn
  6845. (setq have-i nil)
  6846. (concat ":" x))
  6847. x))
  6848. tags ":")
  6849. (if have-i "::" ":"))))))
  6850. txt)
  6851. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6852. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6853. "Add a time-grid for agenda items which need it.
  6854. LIST is the list of agenda items formatted by `org-agenda-list'.
  6855. NDAYS is the span of the current agenda view.
  6856. TODAYP is t when the current agenda view is on today."
  6857. (catch 'exit
  6858. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6859. ((and todayp (member 'today (car org-agenda-time-grid))))
  6860. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6861. ((member 'weekly (car org-agenda-time-grid)))
  6862. (t (throw 'exit list)))
  6863. (let* ((have (delq nil (mapcar
  6864. (lambda (x) (get-text-property 1 'time-of-day x))
  6865. list)))
  6866. (string (nth 3 org-agenda-time-grid))
  6867. (gridtimes (nth 1 org-agenda-time-grid))
  6868. (req (car org-agenda-time-grid))
  6869. (remove (member 'remove-match req))
  6870. new time)
  6871. (when (and (member 'require-timed req) (not have))
  6872. ;; don't show empty grid
  6873. (throw 'exit list))
  6874. (while (setq time (pop gridtimes))
  6875. (unless (and remove (member time have))
  6876. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6877. (push (org-agenda-format-item
  6878. nil string nil "" nil
  6879. (concat (substring time 0 -2) ":" (substring time -2)))
  6880. new)
  6881. (put-text-property
  6882. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6883. (when (and todayp org-agenda-show-current-time-in-grid)
  6884. (push (org-agenda-format-item
  6885. nil org-agenda-current-time-string nil "" nil
  6886. (format-time-string "%H:%M "))
  6887. new)
  6888. (put-text-property
  6889. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6890. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6891. (append new list)
  6892. (append list new)))))
  6893. (defun org-compile-prefix-format (key)
  6894. "Compile the prefix format into a Lisp form that can be evaluated.
  6895. KEY is the agenda type (see `org-agenda-prefix-format').
  6896. The resulting form and associated variable bindings is returned
  6897. and stored in the variable `org-prefix-format-compiled'."
  6898. (setq org-prefix-has-time nil
  6899. org-prefix-has-tag nil
  6900. org-prefix-category-length nil
  6901. org-prefix-has-effort nil
  6902. org-prefix-has-breadcrumbs nil)
  6903. (let ((s (cond
  6904. ((stringp org-agenda-prefix-format)
  6905. org-agenda-prefix-format)
  6906. ((assq key org-agenda-prefix-format)
  6907. (cdr (assq key org-agenda-prefix-format)))
  6908. (t " %-12:c%?-12t% s")))
  6909. (start 0)
  6910. varform vars var c f opt) ;; e
  6911. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6912. s start)
  6913. (setq var (or (cdr (assoc (match-string 4 s)
  6914. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6915. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6916. 'eval)
  6917. c (or (match-string 3 s) "")
  6918. opt (match-beginning 1)
  6919. start (1+ (match-beginning 0)))
  6920. (cl-case var
  6921. (time (setq org-prefix-has-time t))
  6922. (tag (setq org-prefix-has-tag t))
  6923. (effort (setq org-prefix-has-effort t))
  6924. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6925. (setq f (concat "%" (match-string 2 s) "s"))
  6926. (when (eq var 'category)
  6927. (setq org-prefix-category-length
  6928. (floor (abs (string-to-number (match-string 2 s)))))
  6929. (setq org-prefix-category-max-length
  6930. (let ((x (match-string 2 s)))
  6931. (save-match-data
  6932. (and (string-match "\\.[0-9]+" x)
  6933. (string-to-number (substring (match-string 0 x) 1)))))))
  6934. (if (eq var 'eval)
  6935. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6936. (if opt
  6937. (setq varform
  6938. `(if (member ,var '("" nil))
  6939. ""
  6940. (format ,f (concat ,var ,c))))
  6941. (setq varform
  6942. `(format ,f (if (member ,var '("" nil)) ""
  6943. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6944. (if (eq var 'eval)
  6945. (setf (substring s (match-beginning 0)
  6946. (+ (match-beginning 4)
  6947. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6948. "%s")
  6949. (setq s (replace-match "%s" t nil s)))
  6950. (push varform vars))
  6951. (setq vars (nreverse vars))
  6952. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6953. (setq org-prefix-format-compiled
  6954. (list
  6955. `((org-prefix-has-time ,org-prefix-has-time)
  6956. (org-prefix-has-tag ,org-prefix-has-tag)
  6957. (org-prefix-category-length ,org-prefix-category-length)
  6958. (org-prefix-has-effort ,org-prefix-has-effort)
  6959. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6960. `(format ,s ,@vars))))))
  6961. (defun org-set-sorting-strategy (key)
  6962. (setq org-agenda-sorting-strategy-selected
  6963. (if (symbolp (car org-agenda-sorting-strategy))
  6964. ;; the old format
  6965. org-agenda-sorting-strategy
  6966. (or (cdr (assq key org-agenda-sorting-strategy))
  6967. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6968. '(time-up category-keep priority-down)))))
  6969. (defun org-get-time-of-day (s &optional string)
  6970. "Check string S for a time of day.
  6971. If found, return it as a military time number between 0 and 2400.
  6972. If not found, return nil.
  6973. The optional STRING argument forces conversion into a 5 character wide string
  6974. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6975. where H:MM is the duration above midnight."
  6976. (let ((case-fold-search t)
  6977. (time-regexp
  6978. (rx word-start
  6979. (group (opt (any "012")) digit) ;group 1: hours
  6980. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  6981. (opt (group (or "am" "pm")))) ;group 3: am/pm
  6982. ;; Special "HHam/pm" case.
  6983. (group-n 3 (or "am" "pm")))
  6984. word-end)))
  6985. (save-match-data
  6986. (when (and (string-match time-regexp s)
  6987. (not (eq 'org-link (get-text-property 1 'face s))))
  6988. (let ((hours
  6989. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  6990. (am-p (equal ampm "am")))
  6991. (pcase (string-to-number (match-string 1 s))
  6992. ((and (guard (not ampm)) h) h)
  6993. (12 (if am-p 0 12))
  6994. (h (+ h (if am-p 0 12))))))
  6995. (minutes
  6996. (if (match-end 2)
  6997. (string-to-number (match-string 2 s))
  6998. 0)))
  6999. (pcase string
  7000. (`nil (+ minutes (* hours 100)))
  7001. ((and `overtime
  7002. (guard (or (> hours 24)
  7003. (and (= hours 24)
  7004. (> minutes 0)))))
  7005. (format "+%d:%02d" (- hours 24) minutes))
  7006. ((guard org-agenda-time-leading-zero)
  7007. (format "%02d:%02d" hours minutes))
  7008. (_
  7009. (format "%d:%02d" hours minutes))))))))
  7010. (defvar org-agenda-before-sorting-filter-function nil
  7011. "Function to be applied to agenda items prior to sorting.
  7012. Prior to sorting also means just before they are inserted into the agenda.
  7013. To aid sorting, you may revisit the original entries and add more text
  7014. properties which will later be used by the sorting functions.
  7015. The function should take a string argument, an agenda line.
  7016. It has access to the text properties in that line, which contain among
  7017. other things, the property `org-hd-marker' that points to the entry
  7018. where the line comes from. Note that not all lines going into the agenda
  7019. have this property, only most.
  7020. The function should return the modified string. It is probably best
  7021. to ONLY change text properties.
  7022. You can also use this function as a filter, by returning nil for lines
  7023. you don't want to have in the agenda at all. For this application, you
  7024. could bind the variable in the options section of a custom command.")
  7025. (defun org-agenda-finalize-entries (list &optional type)
  7026. "Sort, limit and concatenate the LIST of agenda items.
  7027. The optional argument TYPE tells the agenda type."
  7028. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7029. (cdr (assoc type org-agenda-max-effort)))
  7030. (t org-agenda-max-effort)))
  7031. (max-todo (cond ((listp org-agenda-max-todos)
  7032. (cdr (assoc type org-agenda-max-todos)))
  7033. (t org-agenda-max-todos)))
  7034. (max-tags (cond ((listp org-agenda-max-tags)
  7035. (cdr (assoc type org-agenda-max-tags)))
  7036. (t org-agenda-max-tags)))
  7037. (max-entries (cond ((listp org-agenda-max-entries)
  7038. (cdr (assoc type org-agenda-max-entries)))
  7039. (t org-agenda-max-entries))))
  7040. (when org-agenda-before-sorting-filter-function
  7041. (setq list
  7042. (delq nil
  7043. (mapcar
  7044. org-agenda-before-sorting-filter-function list))))
  7045. (setq list (mapcar #'org-agenda-highlight-todo list)
  7046. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7047. (when max-effort
  7048. (setq list (org-agenda-limit-entries
  7049. list 'effort-minutes max-effort
  7050. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7051. 32767 -1))))))
  7052. (when max-todo
  7053. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7054. (when max-tags
  7055. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7056. (when max-entries
  7057. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7058. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7059. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7060. (mapconcat #'identity list "\n")))
  7061. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7062. "Limit the number of agenda entries."
  7063. (let ((include (and limit (< limit 0))))
  7064. (if limit
  7065. (let ((fun (or fn (lambda (p) (when p 1))))
  7066. (lim 0))
  7067. (delq nil
  7068. (mapcar
  7069. (lambda (e)
  7070. (let ((pval (funcall
  7071. fun (get-text-property (1- (length e))
  7072. prop e))))
  7073. (when pval (setq lim (+ lim pval)))
  7074. (cond ((and pval (<= lim (abs limit))) e)
  7075. ((and include (not pval)) e))))
  7076. list)))
  7077. list)))
  7078. (defun org-agenda-limit-interactively (remove)
  7079. "In agenda, interactively limit entries to various maximums."
  7080. (interactive "P")
  7081. (if remove
  7082. (progn (setq org-agenda-max-entries nil
  7083. org-agenda-max-todos nil
  7084. org-agenda-max-tags nil
  7085. org-agenda-max-effort nil)
  7086. (org-agenda-redo))
  7087. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7088. (msg (cond ((= max ?E) "How many minutes? ")
  7089. ((= max ?e) "How many entries? ")
  7090. ((= max ?t) "How many TODO entries? ")
  7091. ((= max ?T) "How many tagged entries? ")
  7092. (t (user-error "Wrong input"))))
  7093. (num (string-to-number (read-from-minibuffer msg))))
  7094. (cond ((equal max ?e)
  7095. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7096. ((equal max ?t)
  7097. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7098. ((equal max ?T)
  7099. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7100. ((equal max ?E)
  7101. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7102. (org-agenda-fit-window-to-buffer))
  7103. (defun org-agenda-highlight-todo (x)
  7104. (let ((org-done-keywords org-done-keywords-for-agenda)
  7105. (case-fold-search nil)
  7106. re)
  7107. (if (eq x 'line)
  7108. (save-excursion
  7109. (beginning-of-line 1)
  7110. (setq re (org-get-at-bol 'org-todo-regexp))
  7111. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  7112. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7113. (add-text-properties (match-beginning 0) (match-end 1)
  7114. (list 'face (org-get-todo-face 1)))
  7115. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7116. (delete-region (match-beginning 1) (1- (match-end 0)))
  7117. (goto-char (match-beginning 1))
  7118. (insert (format org-agenda-todo-keyword-format s)))))
  7119. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7120. (setq re (get-text-property 0 'org-todo-regexp x))
  7121. (when (and re
  7122. ;; Test `pl' because if there's no heading content,
  7123. ;; there's no point matching to highlight. Note
  7124. ;; that if we didn't test `pl' first, and there
  7125. ;; happened to be no keyword from `org-todo-regexp'
  7126. ;; on this heading line, then the `equal' comparison
  7127. ;; afterwards would spuriously succeed in the case
  7128. ;; where `pl' is nil -- causing an args-out-of-range
  7129. ;; error when we try to add text properties to text
  7130. ;; that isn't there.
  7131. pl
  7132. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7133. x pl)
  7134. pl))
  7135. (add-text-properties
  7136. (or (match-end 1) (match-end 0)) (match-end 0)
  7137. (list 'face (org-get-todo-face (match-string 2 x)))
  7138. x)
  7139. (when (match-end 1)
  7140. (setq x
  7141. (concat
  7142. (substring x 0 (match-end 1))
  7143. (unless (string= org-agenda-todo-keyword-format "")
  7144. (format org-agenda-todo-keyword-format
  7145. (match-string 2 x)))
  7146. (unless (string= org-agenda-todo-keyword-format "")
  7147. ;; Remove `display' property as the icon could leak
  7148. ;; on the white space.
  7149. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7150. 'display)))
  7151. (substring x (match-end 3)))))))
  7152. x)))
  7153. (defsubst org-cmp-values (a b property)
  7154. "Compare the numeric value of text PROPERTY for string A and B."
  7155. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7156. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7157. (cond ((> pa pb) +1)
  7158. ((< pa pb) -1))))
  7159. (defsubst org-cmp-effort (a b)
  7160. "Compare the effort values of string A and B."
  7161. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7162. ;; `effort-minutes' property is not directly accessible from
  7163. ;; the strings, but is stored as a property in `txt'.
  7164. (ea (or (get-text-property
  7165. 0 'effort-minutes (get-text-property 0 'txt a))
  7166. def))
  7167. (eb (or (get-text-property
  7168. 0 'effort-minutes (get-text-property 0 'txt b))
  7169. def)))
  7170. (cond ((> ea eb) +1)
  7171. ((< ea eb) -1))))
  7172. (defsubst org-cmp-category (a b)
  7173. "Compare the string values of categories of strings A and B."
  7174. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7175. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7176. (cond ((string-lessp ca cb) -1)
  7177. ((string-lessp cb ca) +1))))
  7178. (defsubst org-cmp-todo-state (a b)
  7179. "Compare the todo states of strings A and B."
  7180. (let* ((ma (or (get-text-property 1 'org-marker a)
  7181. (get-text-property 1 'org-hd-marker a)))
  7182. (mb (or (get-text-property 1 'org-marker b)
  7183. (get-text-property 1 'org-hd-marker b)))
  7184. (fa (and ma (marker-buffer ma)))
  7185. (fb (and mb (marker-buffer mb)))
  7186. (todo-kwds
  7187. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7188. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7189. (ta (or (get-text-property 1 'todo-state a) ""))
  7190. (tb (or (get-text-property 1 'todo-state b) ""))
  7191. (la (- (length (member ta todo-kwds))))
  7192. (lb (- (length (member tb todo-kwds))))
  7193. (donepa (member ta org-done-keywords-for-agenda))
  7194. (donepb (member tb org-done-keywords-for-agenda)))
  7195. (cond ((and donepa (not donepb)) -1)
  7196. ((and (not donepa) donepb) +1)
  7197. ((< la lb) -1)
  7198. ((< lb la) +1))))
  7199. (defsubst org-cmp-alpha (a b)
  7200. "Compare the headlines, alphabetically."
  7201. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7202. (plb (text-property-any 0 (length b) 'org-heading t b))
  7203. (ta (and pla (substring a pla)))
  7204. (tb (and plb (substring b plb)))
  7205. (case-fold-search nil))
  7206. (when pla
  7207. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7208. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7209. ta)
  7210. (setq ta (substring ta (match-end 0))))
  7211. (setq ta (downcase ta)))
  7212. (when plb
  7213. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7214. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7215. tb)
  7216. (setq tb (substring tb (match-end 0))))
  7217. (setq tb (downcase tb)))
  7218. (cond ((not (or ta tb)) nil)
  7219. ((not ta) +1)
  7220. ((not tb) -1)
  7221. ((string-lessp ta tb) -1)
  7222. ((string-lessp tb ta) +1))))
  7223. (defsubst org-cmp-tag (a b)
  7224. "Compare the string values of the first tags of A and B."
  7225. (let ((ta (car (last (get-text-property 1 'tags a))))
  7226. (tb (car (last (get-text-property 1 'tags b)))))
  7227. (cond ((not (or ta tb)) nil)
  7228. ((not ta) +1)
  7229. ((not tb) -1)
  7230. ((string-lessp ta tb) -1)
  7231. ((string-lessp tb ta) +1))))
  7232. (defsubst org-cmp-time (a b)
  7233. "Compare the time-of-day values of strings A and B."
  7234. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7235. (ta (or (get-text-property 1 'time-of-day a) def))
  7236. (tb (or (get-text-property 1 'time-of-day b) def)))
  7237. (cond ((< ta tb) -1)
  7238. ((< tb ta) +1))))
  7239. (defsubst org-cmp-ts (a b type)
  7240. "Compare the timestamps values of entries A and B.
  7241. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7242. \"timestamp_ia\", compare within each of these type. When TYPE
  7243. is the empty string, compare all timestamps without respect of
  7244. their type."
  7245. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7246. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7247. (get-text-property 1 'ts-date a))
  7248. def))
  7249. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7250. (get-text-property 1 'ts-date b))
  7251. def)))
  7252. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7253. ((if tb (and ta (< tb ta)) ta) +1))))
  7254. (defsubst org-cmp-habit-p (a b)
  7255. "Compare the todo states of strings A and B."
  7256. (let ((ha (get-text-property 1 'org-habit-p a))
  7257. (hb (get-text-property 1 'org-habit-p b)))
  7258. (cond ((and ha (not hb)) -1)
  7259. ((and (not ha) hb) +1))))
  7260. (defun org-entries-lessp (a b)
  7261. "Predicate for sorting agenda entries."
  7262. ;; The following variables will be used when the form is evaluated.
  7263. ;; So even though the compiler complains, keep them.
  7264. (let ((ss org-agenda-sorting-strategy-selected))
  7265. (org-dlet
  7266. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7267. (org-cmp-ts a b "")))
  7268. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7269. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7270. (org-cmp-ts a b "scheduled")))
  7271. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7272. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7273. (org-cmp-ts a b "deadline")))
  7274. (deadline-down (if deadline-up (- deadline-up) nil))
  7275. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7276. (org-cmp-ts a b "timestamp_ia")))
  7277. (tsia-down (if tsia-up (- tsia-up) nil))
  7278. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7279. (org-cmp-ts a b "timestamp")))
  7280. (ts-down (if ts-up (- ts-up) nil))
  7281. (time-up (and (org-em 'time-up 'time-down ss)
  7282. (org-cmp-time a b)))
  7283. (time-down (if time-up (- time-up) nil))
  7284. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7285. (org-cmp-values a b 'org-stats)))
  7286. (stats-down (if stats-up (- stats-up) nil))
  7287. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7288. (org-cmp-values a b 'priority)))
  7289. (priority-down (if priority-up (- priority-up) nil))
  7290. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7291. (org-cmp-effort a b)))
  7292. (effort-down (if effort-up (- effort-up) nil))
  7293. (category-up (and (or (org-em 'category-up 'category-down ss)
  7294. (memq 'category-keep ss))
  7295. (org-cmp-category a b)))
  7296. (category-down (if category-up (- category-up) nil))
  7297. (category-keep (if category-up +1 nil))
  7298. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7299. (org-cmp-tag a b)))
  7300. (tag-down (if tag-up (- tag-up) nil))
  7301. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7302. (org-cmp-todo-state a b)))
  7303. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7304. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7305. (org-cmp-habit-p a b)))
  7306. (habit-down (if habit-up (- habit-up) nil))
  7307. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7308. (org-cmp-alpha a b)))
  7309. (alpha-down (if alpha-up (- alpha-up) nil))
  7310. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7311. user-defined-up user-defined-down)
  7312. (when (and need-user-cmp org-agenda-cmp-user-defined
  7313. (functionp org-agenda-cmp-user-defined))
  7314. (setq user-defined-up
  7315. (funcall org-agenda-cmp-user-defined a b)
  7316. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7317. (cdr (assoc
  7318. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7319. '((-1 . t) (1 . nil) (nil . nil)))))))
  7320. ;;; Agenda restriction lock
  7321. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7322. "Overlay to mark the headline to which agenda commands are restricted.")
  7323. (overlay-put org-agenda-restriction-lock-overlay
  7324. 'face 'org-agenda-restriction-lock)
  7325. (overlay-put org-agenda-restriction-lock-overlay
  7326. 'help-echo "Agendas are currently limited to this subtree.")
  7327. (delete-overlay org-agenda-restriction-lock-overlay)
  7328. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7329. "Set the restriction lock to the agenda item at point from within the agenda.
  7330. When called with a `\\[universal-argument]' prefix, restrict to
  7331. the file which contains the item.
  7332. Argument ARG is the prefix argument."
  7333. (interactive "P")
  7334. (unless (derived-mode-p 'org-agenda-mode)
  7335. (user-error "Not in an Org agenda buffer"))
  7336. (let* ((marker (or (org-get-at-bol 'org-marker)
  7337. (org-agenda-error)))
  7338. (buffer (marker-buffer marker))
  7339. (pos (marker-position marker)))
  7340. (with-current-buffer buffer
  7341. (goto-char pos)
  7342. (org-agenda-set-restriction-lock arg))))
  7343. ;;;###autoload
  7344. (defun org-agenda-set-restriction-lock (&optional type)
  7345. "Set restriction lock for agenda to current subtree or file.
  7346. When in a restricted subtree, remove it.
  7347. The restriction will span over the entire file if TYPE is `file',
  7348. or if type is \\='(4), or if the cursor is before the first headline
  7349. in the file. Otherwise, only apply the restriction to the current
  7350. subtree."
  7351. (interactive "P")
  7352. (if (and org-agenda-overriding-restriction
  7353. (member org-agenda-restriction-lock-overlay
  7354. (overlays-at (point)))
  7355. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7356. (point)))
  7357. (org-agenda-remove-restriction-lock 'noupdate)
  7358. (org-agenda-remove-restriction-lock 'noupdate)
  7359. (and (equal type '(4)) (setq type 'file))
  7360. (setq type (cond
  7361. (type type)
  7362. ((org-at-heading-p) 'subtree)
  7363. ((condition-case nil (org-back-to-heading t) (error nil))
  7364. 'subtree)
  7365. (t 'file)))
  7366. (if (eq type 'subtree)
  7367. (progn
  7368. (setq org-agenda-restrict (current-buffer))
  7369. (setq org-agenda-overriding-restriction 'subtree)
  7370. (put 'org-agenda-files 'org-restrict
  7371. (list (buffer-file-name (buffer-base-buffer))))
  7372. (org-back-to-heading t)
  7373. (move-overlay org-agenda-restriction-lock-overlay
  7374. (point)
  7375. (if org-agenda-restriction-lock-highlight-subtree
  7376. (save-excursion (org-end-of-subtree t t) (point))
  7377. (point-at-eol)))
  7378. (move-marker org-agenda-restrict-begin (point))
  7379. (move-marker org-agenda-restrict-end
  7380. (save-excursion (org-end-of-subtree t t)))
  7381. (message "Locking agenda restriction to subtree"))
  7382. (put 'org-agenda-files 'org-restrict
  7383. (list (buffer-file-name (buffer-base-buffer))))
  7384. (setq org-agenda-restrict nil)
  7385. (setq org-agenda-overriding-restriction 'file)
  7386. (move-marker org-agenda-restrict-begin nil)
  7387. (move-marker org-agenda-restrict-end nil)
  7388. (message "Locking agenda restriction to file"))
  7389. (setq current-prefix-arg nil))
  7390. (org-agenda-maybe-redo))
  7391. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7392. "Remove agenda restriction lock."
  7393. (interactive "P")
  7394. (if (not org-agenda-restrict)
  7395. (message "No agenda restriction to remove.")
  7396. (delete-overlay org-agenda-restriction-lock-overlay)
  7397. (delete-overlay org-speedbar-restriction-lock-overlay)
  7398. (setq org-agenda-overriding-restriction nil)
  7399. (setq org-agenda-restrict nil)
  7400. (put 'org-agenda-files 'org-restrict nil)
  7401. (move-marker org-agenda-restrict-begin nil)
  7402. (move-marker org-agenda-restrict-end nil)
  7403. (setq current-prefix-arg nil)
  7404. (message "Agenda restriction lock removed")
  7405. (or noupdate (org-agenda-maybe-redo))))
  7406. (defun org-agenda-maybe-redo ()
  7407. "If there is any window showing the agenda view, update it."
  7408. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7409. org-agenda-buffer-name)
  7410. t))
  7411. (w0 (selected-window)))
  7412. (when w
  7413. (select-window w)
  7414. (org-agenda-redo)
  7415. (select-window w0)
  7416. (if org-agenda-overriding-restriction
  7417. (message "Agenda view shifted to new %s restriction"
  7418. org-agenda-overriding-restriction)
  7419. (message "Agenda restriction lock removed")))))
  7420. ;;; Agenda commands
  7421. (defun org-agenda-check-type (error &rest types)
  7422. "Check if agenda buffer or component is of allowed type.
  7423. If ERROR is non-nil, throw an error, otherwise just return nil.
  7424. Allowed types are `agenda' `todo' `tags' `search'."
  7425. (cond ((not org-agenda-type)
  7426. (error "No Org agenda currently displayed"))
  7427. ((memq org-agenda-type types) t)
  7428. (error
  7429. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7430. (t nil)))
  7431. (defun org-agenda-Quit ()
  7432. "Exit the agenda, killing the agenda buffer.
  7433. Like `org-agenda-quit', but kill the buffer even when
  7434. `org-agenda-sticky' is non-nil."
  7435. (interactive)
  7436. (org-agenda--quit))
  7437. (defun org-agenda-quit ()
  7438. "Exit the agenda.
  7439. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7440. instead of killing it.
  7441. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7442. the pre-agenda window configuration.
  7443. When column view is active, exit column view instead of the
  7444. agenda."
  7445. (interactive)
  7446. (org-agenda--quit org-agenda-sticky))
  7447. (defun org-agenda--quit (&optional bury)
  7448. (if org-agenda-columns-active
  7449. (org-columns-quit)
  7450. (let ((wconf org-agenda-pre-window-conf)
  7451. (buf (current-buffer))
  7452. (org-agenda-last-indirect-window
  7453. (and (eq org-indirect-buffer-display 'other-window)
  7454. org-agenda-last-indirect-buffer
  7455. (get-buffer-window org-agenda-last-indirect-buffer))))
  7456. (cond
  7457. ((eq org-agenda-window-setup 'other-frame)
  7458. (delete-frame))
  7459. ((eq org-agenda-window-setup 'other-tab)
  7460. (if (fboundp 'tab-bar-close-tab)
  7461. (tab-bar-close-tab)
  7462. (user-error "Your version of Emacs does not have tab bar mode support")))
  7463. ((and org-agenda-restore-windows-after-quit
  7464. wconf)
  7465. ;; Maybe restore the pre-agenda window configuration. Reset
  7466. ;; `org-agenda-pre-window-conf' before running
  7467. ;; `set-window-configuration', which loses the current buffer.
  7468. (setq org-agenda-pre-window-conf nil)
  7469. (set-window-configuration wconf))
  7470. (t
  7471. (when org-agenda-last-indirect-window
  7472. (delete-window org-agenda-last-indirect-window))
  7473. (and (not (eq org-agenda-window-setup 'current-window))
  7474. (not (one-window-p))
  7475. (delete-window))))
  7476. (if bury
  7477. ;; Set the agenda buffer as the current buffer instead of
  7478. ;; passing it as an argument to `bury-buffer' so that
  7479. ;; `bury-buffer' removes it from the window.
  7480. (with-current-buffer buf
  7481. (bury-buffer))
  7482. (kill-buffer buf)
  7483. (setq org-agenda-archives-mode nil
  7484. org-agenda-buffer nil)))))
  7485. (defun org-agenda-exit ()
  7486. "Exit the agenda, killing Org buffers loaded by the agenda.
  7487. Like `org-agenda-Quit', but kill any buffers that were created by
  7488. the agenda. Org buffers visited directly by the user will not be
  7489. touched. Also, exit the agenda even if it is in column view."
  7490. (interactive)
  7491. (when org-agenda-columns-active
  7492. (org-columns-quit))
  7493. (org-release-buffers org-agenda-new-buffers)
  7494. (setq org-agenda-new-buffers nil)
  7495. (org-agenda-Quit))
  7496. (defun org-agenda-kill-all-agenda-buffers ()
  7497. "Kill all buffers in `org-agenda-mode'.
  7498. This is used when toggling sticky agendas."
  7499. (interactive)
  7500. (let (blist)
  7501. (dolist (buf (buffer-list))
  7502. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7503. (push buf blist)))
  7504. (mapc #'kill-buffer blist)))
  7505. (defun org-agenda-execute (arg)
  7506. "Execute another agenda command, keeping same window.
  7507. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7508. in the agenda."
  7509. (interactive "P")
  7510. (let ((org-agenda-window-setup 'current-window))
  7511. (org-agenda arg)))
  7512. (defun org-agenda-redo (&optional all)
  7513. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7514. (interactive "P")
  7515. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7516. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7517. (cpa (unless (eq all t) current-prefix-arg))
  7518. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7519. (org-agenda-sticky nil)
  7520. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7521. org-agenda-buffer-name))
  7522. (org-agenda-keep-modes t)
  7523. (tag-filter org-agenda-tag-filter)
  7524. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7525. (top-hl-filter org-agenda-top-headline-filter)
  7526. (cat-filter org-agenda-category-filter)
  7527. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7528. (re-filter org-agenda-regexp-filter)
  7529. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7530. (effort-filter org-agenda-effort-filter)
  7531. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7532. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7533. (cols org-agenda-columns-active)
  7534. (line (org-current-line))
  7535. (window-line (- line (org-current-line (window-start))))
  7536. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7537. (redo-cmd (get-text-property p 'org-redo-cmd))
  7538. (last-args (get-text-property p 'org-last-args))
  7539. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7540. (org-agenda-overriding-cmd-arguments
  7541. (unless (eq all t)
  7542. (cond ((listp last-args)
  7543. (cons (or cpa (car last-args)) (cdr last-args)))
  7544. ((stringp last-args)
  7545. last-args))))
  7546. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7547. (put 'org-agenda-tag-filter :preset-filter nil)
  7548. (put 'org-agenda-category-filter :preset-filter nil)
  7549. (put 'org-agenda-regexp-filter :preset-filter nil)
  7550. (put 'org-agenda-effort-filter :preset-filter nil)
  7551. (and cols (org-columns-quit))
  7552. (message "Rebuilding agenda buffer...")
  7553. (if series-redo-cmd
  7554. (eval series-redo-cmd t)
  7555. (cl-progv
  7556. (mapcar #'car lprops)
  7557. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7558. (eval redo-cmd t)))
  7559. (setq org-agenda-undo-list nil
  7560. org-agenda-pending-undo-list nil
  7561. org-agenda-tag-filter tag-filter
  7562. org-agenda-category-filter cat-filter
  7563. org-agenda-regexp-filter re-filter
  7564. org-agenda-effort-filter effort-filter
  7565. org-agenda-top-headline-filter top-hl-filter)
  7566. (message "Rebuilding agenda buffer...done")
  7567. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7568. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7569. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7570. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7571. (let ((tag (or tag-filter tag-preset))
  7572. (cat (or cat-filter cat-preset))
  7573. (effort (or effort-filter effort-preset))
  7574. (re (or re-filter re-preset)))
  7575. (when tag (org-agenda-filter-apply tag 'tag t))
  7576. (when cat (org-agenda-filter-apply cat 'category))
  7577. (when effort (org-agenda-filter-apply effort 'effort))
  7578. (when re (org-agenda-filter-apply re 'regexp)))
  7579. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7580. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7581. (org-goto-line line)
  7582. (when (called-interactively-p 'any) (recenter window-line))))
  7583. (defun org-agenda-redo-all (&optional exhaustive)
  7584. "Rebuild all agenda views in the current buffer.
  7585. With a prefix argument, do so in all agenda buffers."
  7586. (interactive "P")
  7587. (if exhaustive
  7588. (dolist (buffer (buffer-list))
  7589. (with-current-buffer buffer
  7590. (when (derived-mode-p 'org-agenda-mode)
  7591. (org-agenda-redo t))))
  7592. (org-agenda-redo t)))
  7593. (defvar org-global-tags-completion-table nil)
  7594. (defvar org-agenda-filter-form nil)
  7595. (defvar org-agenda-filtered-by-category nil)
  7596. (defsubst org-agenda-get-category ()
  7597. "Return the category of the agenda line."
  7598. (org-get-at-bol 'org-category))
  7599. (defun org-agenda-filter-by-category (strip)
  7600. "Filter lines in the agenda buffer that have a specific category.
  7601. The category is that of the current line.
  7602. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7603. When there is already a category filter in place, this command removes the
  7604. filter."
  7605. (interactive "P")
  7606. (if (and org-agenda-filtered-by-category
  7607. org-agenda-category-filter)
  7608. (org-agenda-filter-show-all-cat)
  7609. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7610. (cond
  7611. ((and cat strip)
  7612. (org-agenda-filter-apply
  7613. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7614. (cat
  7615. (org-agenda-filter-apply
  7616. (setq org-agenda-category-filter
  7617. (list (concat "+" cat)))
  7618. 'category))
  7619. (t (error "No category at point"))))))
  7620. (defun org-find-top-headline (&optional pos)
  7621. "Find the topmost parent headline and return it.
  7622. POS when non-nil is the marker or buffer position to start the
  7623. search from."
  7624. (save-excursion
  7625. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7626. (when pos (goto-char pos))
  7627. ;; Skip up to the topmost parent.
  7628. (while (org-up-heading-safe))
  7629. (ignore-errors
  7630. (replace-regexp-in-string
  7631. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7632. (nth 4 (org-heading-components)))))))
  7633. (defvar org-agenda-filtered-by-top-headline nil)
  7634. (defun org-agenda-filter-by-top-headline (strip)
  7635. "Keep only those lines that are descendants from the same top headline.
  7636. The top headline is that of the current line. With prefix arg STRIP, hide
  7637. all lines of the category at point."
  7638. (interactive "P")
  7639. (if org-agenda-filtered-by-top-headline
  7640. (progn
  7641. (setq org-agenda-filtered-by-top-headline nil
  7642. org-agenda-top-headline-filter nil)
  7643. (org-agenda-filter-show-all-top-filter))
  7644. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7645. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7646. (error "No top-level headline at point")))))
  7647. (defvar org-agenda-regexp-filter nil)
  7648. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7649. "Filter agenda entries by a regular expressions.
  7650. You will be prompted for the regular expression, and the agenda
  7651. view will only show entries that are matched by that expression.
  7652. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7653. When there is already a regexp filter active, this command removed the
  7654. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7655. an already existing regexp filter."
  7656. (interactive "P")
  7657. (let* ((strip (equal strip-or-accumulate '(4)))
  7658. (accumulate (equal strip-or-accumulate '(16))))
  7659. (cond
  7660. ((and org-agenda-regexp-filter (not accumulate))
  7661. (org-agenda-filter-show-all-re)
  7662. (message "Regexp filter removed"))
  7663. (t (let ((flt (concat (if strip "-" "+")
  7664. (read-from-minibuffer
  7665. (if strip
  7666. "Hide entries matching regexp: "
  7667. "Narrow to entries matching regexp: ")))))
  7668. (push flt org-agenda-regexp-filter)
  7669. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7670. (defvar org-agenda-effort-filter nil)
  7671. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7672. "Filter agenda entries by effort.
  7673. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7674. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7675. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7676. This last option is in practice not very useful, but it is available for
  7677. consistency with the other filter commands."
  7678. (interactive "P")
  7679. (let* ((efforts (split-string
  7680. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7681. org-global-properties
  7682. t))
  7683. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7684. ;; XXX: the following handles only up to 10 different
  7685. ;; effort values.
  7686. (allowed-keys (if (null efforts) nil
  7687. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7688. (number-sequence 1 (length efforts)))))
  7689. (keep (equal strip-or-accumulate '(16)))
  7690. (negative (equal strip-or-accumulate '(4)))
  7691. (current org-agenda-effort-filter)
  7692. (op nil))
  7693. (while (not (memq op '(?< ?> ?= ?_)))
  7694. (setq op (read-char-exclusive
  7695. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7696. ;; Select appropriate duration. Ignore non-digit characters.
  7697. (if (eq op ?_)
  7698. (progn
  7699. (org-agenda-filter-show-all-effort)
  7700. (message "Effort filter removed"))
  7701. (let ((prompt
  7702. (apply #'format
  7703. (concat "Effort %c "
  7704. (mapconcat (lambda (s) (concat "[%d]" s))
  7705. efforts
  7706. " "))
  7707. op allowed-keys))
  7708. (eff -1))
  7709. (while (not (memq eff allowed-keys))
  7710. (message prompt)
  7711. (setq eff (- (read-char-exclusive) 48)))
  7712. (org-agenda-filter-show-all-effort)
  7713. (setq org-agenda-effort-filter
  7714. (append
  7715. (list (concat (if negative "-" "+")
  7716. (char-to-string op)
  7717. ;; Numbering is 1 2 3 ... 9 0, but we want
  7718. ;; 0 1 2 ... 8 9.
  7719. (nth (mod (1- eff) 10) efforts)))
  7720. (if keep current nil)))
  7721. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7722. (defun org-agenda-filter (&optional strip-or-accumulate)
  7723. "Prompt for a general filter string and apply it to the agenda.
  7724. The string may contain filter elements like
  7725. +category
  7726. +tag
  7727. +<effort > and = are also allowed as effort operators
  7728. +/regexp/
  7729. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7730. `+' is optional if it is not required to separate two string parts.
  7731. Multiple filter elements can be concatenated without spaces, for example
  7732. +work-John<0:10-/plot/
  7733. selects entries with category `work' and effort estimates below 10 minutes,
  7734. and deselects entries with tag `John' or matching the regexp `plot'.
  7735. During entry of the filter, completion for tags, categories and effort
  7736. values is offered. Since the syntax for categories and tags is identical
  7737. there should be no overlap between categories and tags. If there is, tags
  7738. get priority.
  7739. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7740. entire filter, which can be useful in connection with the prompt history.
  7741. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7742. existing ones. A shortcut for this is to add an additional `+' at the
  7743. beginning of the string, like `+-John'.
  7744. With a triple prefix argument, execute the computed filtering defined in
  7745. the variable `org-agenda-auto-exclude-function'."
  7746. (interactive "P")
  7747. (if (equal strip-or-accumulate '(64))
  7748. ;; Execute the auto-exclude action
  7749. (if (not org-agenda-auto-exclude-function)
  7750. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7751. (org-agenda-filter-show-all-tag)
  7752. (setq org-agenda-tag-filter nil)
  7753. (dolist (tag (org-agenda-get-represented-tags))
  7754. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7755. (when modifier
  7756. (push modifier org-agenda-tag-filter))))
  7757. (unless (null org-agenda-tag-filter)
  7758. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7759. ;; Prompt for a filter and act
  7760. (let* ((tag-list (org-agenda-get-represented-tags))
  7761. (category-list (org-agenda-get-represented-categories))
  7762. (negate (equal strip-or-accumulate '(4)))
  7763. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7764. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7765. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7766. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7767. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7768. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7769. (f-string (completing-read
  7770. (concat
  7771. (if negate "Negative filter" "Filter")
  7772. " [+cat-tag<0:10-/regexp/]: ")
  7773. #'org-agenda-filter-completion-function
  7774. nil nil ff))
  7775. (keep (or (if (string-match "^\\+[+-]" f-string)
  7776. (progn (setq f-string (substring f-string 1)) t))
  7777. (equal strip-or-accumulate '(16))))
  7778. (fc (if keep org-agenda-category-filter))
  7779. (ft (if keep org-agenda-tag-filter))
  7780. (fe (if keep org-agenda-effort-filter))
  7781. (fr (if keep org-agenda-regexp-filter))
  7782. pm s)
  7783. ;; If the filter contains a double-quoted string, replace a
  7784. ;; single hyphen by the arbitrary and temporary string "~~~"
  7785. ;; to disambiguate such hyphens from syntactic ones.
  7786. (setq f-string (replace-regexp-in-string
  7787. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7788. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7789. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7790. (when negate
  7791. (setq pm (if (equal pm "+") "-" "+")))
  7792. (cond
  7793. ((match-beginning 3)
  7794. ;; category or tag
  7795. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7796. "~~~" "-" (match-string 3 f-string)))
  7797. (cond
  7798. ((member s tag-list)
  7799. (org-pushnew-to-end (concat pm s) ft))
  7800. ((member s category-list)
  7801. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7802. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7803. fc))
  7804. (t (message
  7805. "`%s%s' filter ignored because tag/category is not represented"
  7806. pm s))))
  7807. ((match-beginning 4)
  7808. ;; effort
  7809. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7810. ((match-beginning 5)
  7811. ;; regexp
  7812. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7813. (setq f-string (substring f-string (match-end 0))))
  7814. (org-agenda-filter-remove-all)
  7815. (and fc (org-agenda-filter-apply
  7816. (setq org-agenda-category-filter fc) 'category))
  7817. (and ft (org-agenda-filter-apply
  7818. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7819. (and fe (org-agenda-filter-apply
  7820. (setq org-agenda-effort-filter fe) 'effort))
  7821. (and fr (org-agenda-filter-apply
  7822. (setq org-agenda-regexp-filter fr) 'regexp))
  7823. (run-hooks 'org-agenda-filter-hook))))
  7824. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7825. "Complete a complex filter string.
  7826. FLAG specifies the type of completion operation to perform. This
  7827. function is passed as a collection function to `completing-read',
  7828. which see."
  7829. (let ((completion-ignore-case t) ;tags are case-sensitive
  7830. (confirm (lambda (x) (stringp x)))
  7831. (prefix "")
  7832. (operator "")
  7833. table)
  7834. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7835. (setq prefix (match-string 1 string)
  7836. operator (match-string 2 string)
  7837. string (match-string 3 string)))
  7838. (cond
  7839. ((member operator '("+" "-" "" nil))
  7840. (setq table (append (org-agenda-get-represented-categories)
  7841. (org-agenda-get-represented-tags))))
  7842. ((member operator '("<" ">" "="))
  7843. (setq table (split-string
  7844. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7845. org-global-properties
  7846. t))
  7847. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7848. " +")))
  7849. (t (setq table nil)))
  7850. (pcase flag
  7851. (`t (all-completions string table confirm))
  7852. (`lambda (assoc string table)) ;exact match?
  7853. (`nil
  7854. (pcase (try-completion string table confirm)
  7855. ((and completion (pred stringp))
  7856. (concat prefix completion))
  7857. (completion completion)))
  7858. (_ nil))))
  7859. (defun org-agenda-filter-remove-all ()
  7860. "Remove all filters from the current agenda buffer."
  7861. (interactive)
  7862. (when org-agenda-tag-filter
  7863. (org-agenda-filter-show-all-tag))
  7864. (when org-agenda-category-filter
  7865. (org-agenda-filter-show-all-cat))
  7866. (when org-agenda-regexp-filter
  7867. (org-agenda-filter-show-all-re))
  7868. (when org-agenda-top-headline-filter
  7869. (org-agenda-filter-show-all-top-filter))
  7870. (when org-agenda-effort-filter
  7871. (org-agenda-filter-show-all-effort))
  7872. (org-agenda-finalize)
  7873. (when (called-interactively-p 'interactive)
  7874. (message "All agenda filters removed")))
  7875. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7876. "Keep only those lines in the agenda buffer that have a specific tag.
  7877. The tag is selected with its fast selection letter, as configured.
  7878. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7879. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7880. instead of replacing it.
  7881. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7882. i.e. don't
  7883. filter on all its group members.
  7884. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7885. should be used to exclude the search - the interactive user can
  7886. also press `-' or `+' to switch between filtering and excluding."
  7887. (interactive "P")
  7888. (let* ((alist org-tag-alist-for-agenda)
  7889. (seen-chars nil)
  7890. (tag-chars (mapconcat
  7891. (lambda (x) (if (and (not (symbolp (car x)))
  7892. (cdr x)
  7893. (not (member (cdr x) seen-chars)))
  7894. (progn
  7895. (push (cdr x) seen-chars)
  7896. (char-to-string (cdr x)))
  7897. ""))
  7898. org-tag-alist-for-agenda ""))
  7899. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7900. (string-to-list tag-chars)))
  7901. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7902. (accumulate (equal strip-or-accumulate '(16)))
  7903. (expand (not (equal strip-or-accumulate '(64))))
  7904. (inhibit-read-only t)
  7905. (current org-agenda-tag-filter)
  7906. a tag) ;; n
  7907. (unless char
  7908. (while (not (memq char valid-char-list))
  7909. (org-unlogged-message
  7910. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7911. (if exclude "Exclude[+]" "Filter[-]")
  7912. (if expand "" " (no grouptag expand)")
  7913. tag-chars
  7914. (if org-agenda-auto-exclude-function "[RET] " ""))
  7915. (setq char (read-char-exclusive))
  7916. ;; Excluding or filtering down
  7917. (cond ((eq char ?-) (setq exclude t))
  7918. ((eq char ?+) (setq exclude nil)))))
  7919. (when (eq char ?\t)
  7920. (unless (local-variable-p 'org-global-tags-completion-table)
  7921. (setq-local org-global-tags-completion-table
  7922. (org-global-tags-completion-table)))
  7923. (let ((completion-ignore-case t))
  7924. (setq tag (completing-read
  7925. "Tag: " org-global-tags-completion-table nil t))))
  7926. (cond
  7927. ((eq char ?\r)
  7928. (org-agenda-filter-show-all-tag)
  7929. (when org-agenda-auto-exclude-function
  7930. (setq org-agenda-tag-filter nil)
  7931. (dolist (tag (org-agenda-get-represented-tags))
  7932. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7933. (when modifier
  7934. (push modifier org-agenda-tag-filter))))
  7935. (unless (null org-agenda-tag-filter)
  7936. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7937. ((eq char ?\\)
  7938. (org-agenda-filter-show-all-tag)
  7939. (when (get 'org-agenda-tag-filter :preset-filter)
  7940. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7941. ((eq char ?.)
  7942. (setq org-agenda-tag-filter
  7943. (mapcar (lambda(tag) (concat "+" tag))
  7944. (org-get-at-bol 'tags)))
  7945. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7946. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7947. ((or (eq char ?\s)
  7948. (setq a (rassoc char alist))
  7949. (and tag (setq a (cons tag nil))))
  7950. (org-agenda-filter-show-all-tag)
  7951. (setq tag (car a))
  7952. (setq org-agenda-tag-filter
  7953. (cons (concat (if exclude "-" "+") tag)
  7954. (if accumulate current nil)))
  7955. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7956. (t (error "Invalid tag selection character %c" char)))))
  7957. (defun org-agenda-get-represented-categories ()
  7958. "Return a list of all categories used in this agenda buffer."
  7959. (or org-agenda-represented-categories
  7960. (when (derived-mode-p 'org-agenda-mode)
  7961. (let ((pos (point-min)) categories)
  7962. (while (and (< pos (point-max))
  7963. (setq pos (next-single-property-change
  7964. pos 'org-category nil (point-max))))
  7965. (push (get-text-property pos 'org-category) categories))
  7966. (setq org-agenda-represented-categories
  7967. ;; Enclose category names with a hyphen in double
  7968. ;; quotes to process them specially in `org-agenda-filter'.
  7969. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7970. (nreverse (org-uniquify (delq nil categories)))))))))
  7971. (defvar org-tag-groups-alist-for-agenda)
  7972. (defun org-agenda-get-represented-tags ()
  7973. "Return a list of all tags used in this agenda buffer.
  7974. These will be lower-case, for filtering."
  7975. (or org-agenda-represented-tags
  7976. (when (derived-mode-p 'org-agenda-mode)
  7977. (let ((pos (point-min)) tags-lists tt)
  7978. (while (and (< pos (point-max))
  7979. (setq pos (next-single-property-change
  7980. pos 'tags nil (point-max))))
  7981. (setq tt (get-text-property pos 'tags))
  7982. (if tt (push tt tags-lists)))
  7983. (setq tags-lists
  7984. (nreverse (org-uniquify
  7985. (delq nil (apply #'append tags-lists)))))
  7986. (dolist (tag tags-lists)
  7987. (mapc
  7988. (lambda (group)
  7989. (when (member tag group)
  7990. (push (car group) tags-lists)))
  7991. org-tag-groups-alist-for-agenda))
  7992. (setq org-agenda-represented-tags tags-lists)))))
  7993. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7994. "Create the form that tests a line for agenda filter.
  7995. Optional argument EXPAND can be used for the TYPE tag and will
  7996. expand the tags in the FILTER if any of the tags in FILTER are
  7997. grouptags."
  7998. (let ((multi-pos-cats
  7999. (and (eq type 'category)
  8000. (string-match-p "\\+.*\\+"
  8001. (mapconcat (lambda (cat) (substring cat 0 1))
  8002. filter ""))))
  8003. f f1)
  8004. (cond
  8005. ;; Tag filter
  8006. ((eq type 'tag)
  8007. (setq filter
  8008. (delete-dups
  8009. (append (get 'org-agenda-tag-filter :preset-filter)
  8010. filter)))
  8011. (dolist (x filter)
  8012. (let ((op (string-to-char x)))
  8013. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8014. (setq x (list x)))
  8015. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8016. (push f1 f))))
  8017. ;; Category filter
  8018. ((eq type 'category)
  8019. (setq filter
  8020. (delete-dups
  8021. (append (get 'org-agenda-category-filter :preset-filter)
  8022. filter)))
  8023. (dolist (x filter)
  8024. (if (equal "-" (substring x 0 1))
  8025. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8026. (setq f1 (list 'equal (substring x 1) 'cat)))
  8027. (push f1 f)))
  8028. ;; Regexp filter
  8029. ((eq type 'regexp)
  8030. (setq filter
  8031. (delete-dups
  8032. (append (get 'org-agenda-regexp-filter :preset-filter)
  8033. filter)))
  8034. (dolist (x filter)
  8035. (if (equal "-" (substring x 0 1))
  8036. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8037. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8038. (push f1 f)))
  8039. ;; Effort filter
  8040. ((eq type 'effort)
  8041. (setq filter
  8042. (delete-dups
  8043. (append (get 'org-agenda-effort-filter :preset-filter)
  8044. filter)))
  8045. (dolist (x filter)
  8046. (push (org-agenda-filter-effort-form x) f))))
  8047. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8048. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8049. "Return a form associated to tag-expression TAGS.
  8050. Build a form testing a line for agenda filter for
  8051. tag-expressions. OP is an operator of type CHAR that allows the
  8052. function to set the right switches in the returned form."
  8053. (let (form)
  8054. ;; Any of the expressions can match if OP is +, all must match if
  8055. ;; the operator is -.
  8056. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8057. (let* ((tag (substring x 1))
  8058. (f (cond
  8059. ((string= "" tag) 'tags)
  8060. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8061. ;; TAG is a regexp.
  8062. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8063. (t (list 'member tag 'tags)))))
  8064. (push (if (eq op ?-) (list 'not f) f) form)))))
  8065. (defun org-agenda-filter-effort-form (e)
  8066. "Return the form to compare the effort of the current line with what E says.
  8067. E looks like \"+<2:25\"."
  8068. (let (op)
  8069. (setq e (substring e 1))
  8070. (setq op (string-to-char e) e (substring e 1))
  8071. (setq op (cond ((equal op ?<) '<=)
  8072. ((equal op ?>) '>=)
  8073. ((equal op ??) op)
  8074. (t '=)))
  8075. (list 'org-agenda-compare-effort (list 'quote op)
  8076. (org-duration-to-minutes e))))
  8077. (defun org-agenda-compare-effort (op value)
  8078. "Compare the effort of the current line with VALUE, using OP.
  8079. If the line does not have an effort defined, return nil."
  8080. ;; `effort-minutes' property cannot be extracted directly from
  8081. ;; current line but is stored as a property in `txt'.
  8082. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8083. (funcall op
  8084. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8085. value)))
  8086. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8087. "Expand group tags in FILTER for the agenda.
  8088. When NO-OPERATOR is non-nil, do not add the + operator to
  8089. returned tags."
  8090. (if org-group-tags
  8091. (let (case-fold-search rtn)
  8092. (mapc
  8093. (lambda (f)
  8094. (let (f0 dir)
  8095. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8096. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8097. (setq dir (if no-operator "" "+") f0 f))
  8098. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8099. (org-tags-expand f0 t))
  8100. rtn))))
  8101. filter)
  8102. (reverse rtn))
  8103. filter))
  8104. (defun org-agenda-filter-apply (filter type &optional expand)
  8105. "Set FILTER as the new agenda filter and apply it.
  8106. Optional argument EXPAND can be used for the TYPE tag and will
  8107. expand the tags in the FILTER if any of the tags in FILTER are
  8108. grouptags."
  8109. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8110. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8111. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8112. filter type expand))
  8113. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8114. ;; category is used as the filter:
  8115. (setq org-agenda-filtered-by-category
  8116. (and (eq type 'category)
  8117. (not (equal (substring (car filter) 0 1) "-"))))
  8118. (org-agenda-set-mode-name)
  8119. (save-excursion
  8120. (goto-char (point-min))
  8121. (while (not (eobp))
  8122. (when (or (org-get-at-bol 'org-hd-marker)
  8123. (org-get-at-bol 'org-marker))
  8124. (org-dlet
  8125. ((tags (org-get-at-bol 'tags))
  8126. (cat (org-agenda-get-category))
  8127. (txt (or (org-get-at-bol 'txt) "")))
  8128. (unless (eval org-agenda-filter-form t)
  8129. (org-agenda-filter-hide-line type))))
  8130. (beginning-of-line 2)))
  8131. (when (get-char-property (point) 'invisible)
  8132. (ignore-errors (org-agenda-previous-line))))
  8133. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8134. "Filter by top headline HL."
  8135. (org-agenda-set-mode-name)
  8136. (save-excursion
  8137. (goto-char (point-min))
  8138. (while (not (eobp))
  8139. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8140. (tophl (and pos (org-find-top-headline pos))))
  8141. (when (and tophl (funcall (if negative 'identity 'not)
  8142. (string= hl tophl)))
  8143. (org-agenda-filter-hide-line 'top-headline)))
  8144. (beginning-of-line 2)))
  8145. (when (get-char-property (point) 'invisible)
  8146. (org-agenda-previous-line))
  8147. (setq org-agenda-top-headline-filter hl
  8148. org-agenda-filtered-by-top-headline t))
  8149. (defun org-agenda-filter-hide-line (type)
  8150. "If current line is TYPE, hide it in the agenda buffer."
  8151. (let* (buffer-invisibility-spec
  8152. (beg (max (point-min) (1- (point-at-bol))))
  8153. (end (point-at-eol)))
  8154. (let ((inhibit-read-only t))
  8155. (add-text-properties
  8156. beg end `(invisible org-filtered org-filter-type ,type)))))
  8157. (defun org-agenda-remove-filter (type)
  8158. "Remove filter of type TYPE from the agenda buffer."
  8159. (interactive)
  8160. (save-excursion
  8161. (goto-char (point-min))
  8162. (let ((inhibit-read-only t) pos)
  8163. (while (setq pos (text-property-any (point) (point-max)
  8164. 'org-filter-type type))
  8165. (goto-char pos)
  8166. (remove-text-properties
  8167. (point) (next-single-property-change (point) 'org-filter-type)
  8168. `(invisible org-filtered org-filter-type ,type))))
  8169. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8170. (setq org-agenda-filter-form nil)
  8171. (org-agenda-set-mode-name)
  8172. (org-agenda-finalize)))
  8173. (defun org-agenda-filter-show-all-tag nil
  8174. (org-agenda-remove-filter 'tag))
  8175. (defun org-agenda-filter-show-all-re nil
  8176. (org-agenda-remove-filter 'regexp))
  8177. (defun org-agenda-filter-show-all-effort nil
  8178. (org-agenda-remove-filter 'effort))
  8179. (defun org-agenda-filter-show-all-cat nil
  8180. (org-agenda-remove-filter 'category))
  8181. (defun org-agenda-filter-show-all-top-filter nil
  8182. (org-agenda-remove-filter 'top-headline))
  8183. (defun org-agenda-manipulate-query-add ()
  8184. "Manipulate the query by adding a search term with positive selection.
  8185. Positive selection means the term must be matched for selection of an entry."
  8186. (interactive)
  8187. (org-agenda-manipulate-query ?\[))
  8188. (defun org-agenda-manipulate-query-subtract ()
  8189. "Manipulate the query by adding a search term with negative selection.
  8190. Negative selection means term must not be matched for selection of an entry."
  8191. (interactive)
  8192. (org-agenda-manipulate-query ?\]))
  8193. (defun org-agenda-manipulate-query-add-re ()
  8194. "Manipulate the query by adding a search regexp with positive selection.
  8195. Positive selection means the regexp must match for selection of an entry."
  8196. (interactive)
  8197. (org-agenda-manipulate-query ?\{))
  8198. (defun org-agenda-manipulate-query-subtract-re ()
  8199. "Manipulate the query by adding a search regexp with negative selection.
  8200. Negative selection means regexp must not match for selection of an entry."
  8201. (interactive)
  8202. (org-agenda-manipulate-query ?\}))
  8203. (defun org-agenda-manipulate-query (char)
  8204. (cond
  8205. ((eq org-agenda-type 'agenda)
  8206. (let ((org-agenda-include-inactive-timestamps t))
  8207. (org-agenda-redo))
  8208. (message "Display now includes inactive timestamps as well"))
  8209. ((eq org-agenda-type 'search)
  8210. (org-add-to-string
  8211. 'org-agenda-query-string
  8212. (if org-agenda-last-search-view-search-was-boolean
  8213. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8214. (?\{ . " +{}") (?\} . " -{}"))))
  8215. " "))
  8216. (setq org-agenda-redo-command
  8217. (list 'org-search-view
  8218. (car (get-text-property (min (1- (point-max)) (point))
  8219. 'org-last-args))
  8220. org-agenda-query-string
  8221. (+ (length org-agenda-query-string)
  8222. (if (member char '(?\{ ?\})) 0 1))))
  8223. (set-register org-agenda-query-register org-agenda-query-string)
  8224. (let ((org-agenda-overriding-arguments
  8225. (cdr org-agenda-redo-command)))
  8226. (org-agenda-redo)))
  8227. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8228. org-agenda-type))))
  8229. (defun org-add-to-string (var string)
  8230. (set var (concat (symbol-value var) string)))
  8231. (defun org-agenda-goto-date (date)
  8232. "Jump to DATE in the agenda buffer.
  8233. When called interactively, prompt for the date.
  8234. When called from Lisp, DATE should be a date as returned by
  8235. `org-read-date'.
  8236. See also:
  8237. `org-agenda-earlier' (\\[org-agenda-earlier])
  8238. `org-agenda-later' (\\[org-agenda-later])
  8239. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8240. (interactive
  8241. (list
  8242. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8243. (org-read-date))))
  8244. (let* ((day (time-to-days (org-time-string-to-time date)))
  8245. (org-agenda-sticky-orig org-agenda-sticky)
  8246. (org-agenda-buffer-tmp-name (buffer-name))
  8247. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8248. (0-arg (or current-prefix-arg (car args)))
  8249. (2-arg (nth 2 args))
  8250. (with-hour-p (nth 4 org-agenda-redo-command))
  8251. (newcmd (list 'org-agenda-list 0-arg date
  8252. (org-agenda-span-to-ndays
  8253. 2-arg (org-time-string-to-absolute date))
  8254. with-hour-p))
  8255. (newargs (cdr newcmd))
  8256. (inhibit-read-only t)
  8257. org-agenda-sticky)
  8258. (if (not (org-agenda-check-type t 'agenda))
  8259. (error "Not available in non-agenda views")
  8260. (add-text-properties (point-min) (point-max)
  8261. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8262. (org-agenda-redo)
  8263. (goto-char (point-min))
  8264. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8265. (save-excursion (move-beginning-of-line 2) (eobp))))
  8266. (move-beginning-of-line 2))
  8267. (setq org-agenda-sticky org-agenda-sticky-orig
  8268. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8269. (defun org-agenda-goto-today ()
  8270. "Go to today's date in the agenda buffer.
  8271. See also:
  8272. `org-agenda-later' (\\[org-agenda-later])
  8273. `org-agenda-earlier' (\\[org-agenda-earlier])
  8274. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8275. (interactive)
  8276. (org-agenda-check-type t 'agenda)
  8277. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8278. (curspan (nth 2 args))
  8279. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8280. (cond
  8281. (tdpos (goto-char tdpos))
  8282. ((eq org-agenda-type 'agenda)
  8283. (let* ((sd (org-agenda-compute-starting-span
  8284. (org-today) (or curspan org-agenda-span)))
  8285. (org-agenda-overriding-arguments args))
  8286. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8287. (org-agenda-redo)
  8288. (org-agenda-find-same-or-today-or-agenda)))
  8289. (t (error "Cannot find today")))))
  8290. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8291. (goto-char
  8292. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8293. (text-property-any (point-min) (point-max) 'org-today t)
  8294. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8295. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8296. (org-agenda-backward-block))
  8297. (point-min))))
  8298. (defun org-agenda-backward-block ()
  8299. "Move backward by one agenda block."
  8300. (interactive)
  8301. (org-agenda-forward-block 'backward))
  8302. (defun org-agenda-forward-block (&optional backward)
  8303. "Move forward by one agenda block.
  8304. When optional argument BACKWARD is set, go backward."
  8305. (interactive)
  8306. (cond ((not (derived-mode-p 'org-agenda-mode))
  8307. (user-error
  8308. "Cannot execute this command outside of org-agenda-mode buffers"))
  8309. ((looking-at (if backward "\\`" "\\'"))
  8310. (message "Already at the %s block" (if backward "first" "last")))
  8311. (t (let ((_pos (prog1 (point)
  8312. (ignore-errors (if backward (backward-char 1)
  8313. (move-end-of-line 1)))))
  8314. (f (if backward
  8315. #'previous-single-property-change
  8316. #'next-single-property-change))
  8317. moved dest)
  8318. (while (and (setq dest (funcall
  8319. f (point) 'org-agenda-structural-header))
  8320. (not (get-text-property
  8321. (point) 'org-agenda-structural-header)))
  8322. (setq moved t)
  8323. (goto-char dest))
  8324. (if moved (move-beginning-of-line 1)
  8325. (goto-char (if backward (point-min) (point-max)))
  8326. (move-beginning-of-line 1)
  8327. (message "No %s block" (if backward "previous" "further")))))))
  8328. (defun org-agenda-later (arg)
  8329. "Go forward in time by the current span in the agenda buffer.
  8330. With prefix ARG, go forward that many times the current span.
  8331. See also:
  8332. `org-agenda-earlier' (\\[org-agenda-earlier])
  8333. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8334. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8335. (interactive "p")
  8336. (org-agenda-check-type t 'agenda)
  8337. (let* ((wstart (window-start))
  8338. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8339. (span (or (nth 2 args) org-agenda-current-span))
  8340. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8341. (greg (calendar-gregorian-from-absolute sd))
  8342. (cnt (org-get-at-bol 'org-day-cnt))
  8343. greg2)
  8344. (cond
  8345. ((numberp span)
  8346. (setq sd (+ (* span arg) sd)))
  8347. ((eq span 'day)
  8348. (setq sd (+ arg sd)))
  8349. ((eq span 'week)
  8350. (setq sd (+ (* 7 arg) sd)))
  8351. ((eq span 'fortnight)
  8352. (setq sd (+ (* 14 arg) sd)))
  8353. ((eq span 'month)
  8354. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8355. sd (calendar-absolute-from-gregorian greg2))
  8356. (setcar greg2 (1+ (car greg2))))
  8357. ((eq span 'year)
  8358. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8359. sd (calendar-absolute-from-gregorian greg2))
  8360. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8361. (t
  8362. (setq sd (+ (* span arg) sd))))
  8363. (let ((org-agenda-overriding-cmd
  8364. ;; `cmd' may have been set by `org-agenda-run-series' which
  8365. ;; uses `org-agenda-overriding-cmd' to decide whether
  8366. ;; overriding is allowed for `cmd'
  8367. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8368. (org-agenda-overriding-arguments
  8369. (list (car args) sd span)))
  8370. (org-agenda-redo)
  8371. (org-agenda-find-same-or-today-or-agenda cnt))
  8372. (set-window-start nil wstart)))
  8373. (defun org-agenda-earlier (arg)
  8374. "Go backward in time by the current span in the agenda buffer.
  8375. With prefix ARG, go backward that many times the current span.
  8376. See also:
  8377. `org-agenda-later' (\\[org-agenda-later])
  8378. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8379. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8380. (interactive "p")
  8381. (org-agenda-later (- arg)))
  8382. (defun org-agenda-view-mode-dispatch ()
  8383. "Call one of the view mode commands."
  8384. (interactive)
  8385. (org-unlogged-message
  8386. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8387. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8388. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8389. (pcase (read-char-exclusive)
  8390. (?\ (call-interactively 'org-agenda-reset-view))
  8391. (?d (call-interactively 'org-agenda-day-view))
  8392. (?w (call-interactively 'org-agenda-week-view))
  8393. (?t (call-interactively 'org-agenda-fortnight-view))
  8394. (?m (call-interactively 'org-agenda-month-view))
  8395. (?y (call-interactively 'org-agenda-year-view))
  8396. (?l (call-interactively 'org-agenda-log-mode))
  8397. (?L (org-agenda-log-mode '(4)))
  8398. (?c (org-agenda-log-mode 'clockcheck))
  8399. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8400. (?a (call-interactively 'org-agenda-archives-mode))
  8401. (?A (org-agenda-archives-mode 'files))
  8402. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8403. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8404. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8405. (?D (call-interactively 'org-agenda-toggle-diary))
  8406. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8407. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8408. (org-agenda-check-type t 'agenda)
  8409. (org-agenda-redo))
  8410. (message "Display now includes inactive timestamps as well"))
  8411. (?q (message "Abort"))
  8412. (key (user-error "Invalid key: %s" key))))
  8413. (defun org-agenda-reset-view ()
  8414. "Switch to default view for agenda."
  8415. (interactive)
  8416. (org-agenda-change-time-span org-agenda-span))
  8417. (defun org-agenda-day-view (&optional day-of-month)
  8418. "Switch to daily view for agenda.
  8419. With argument DAY-OF-MONTH, switch to that day of the month."
  8420. (interactive "P")
  8421. (org-agenda-change-time-span 'day day-of-month))
  8422. (defun org-agenda-week-view (&optional iso-week)
  8423. "Switch to weekly view for agenda.
  8424. With argument ISO-WEEK, switch to the corresponding ISO week.
  8425. If ISO-WEEK has more then 2 digits, only the last two encode
  8426. the week. Any digits before this encode a year. So 200712
  8427. means week 12 of year 2007. Years ranging from 70 years ago
  8428. to 30 years in the future can also be written as 2-digit years."
  8429. (interactive "P")
  8430. (org-agenda-change-time-span 'week iso-week))
  8431. (defun org-agenda-fortnight-view (&optional iso-week)
  8432. "Switch to fortnightly view for agenda.
  8433. With argument ISO-WEEK, switch to the corresponding ISO week.
  8434. If ISO-WEEK has more then 2 digits, only the last two encode
  8435. the week. Any digits before this encode a year. So 200712
  8436. means week 12 of year 2007. Years ranging from 70 years ago
  8437. to 30 years in the future can also be written as 2-digit years."
  8438. (interactive "P")
  8439. (org-agenda-change-time-span 'fortnight iso-week))
  8440. (defun org-agenda-month-view (&optional month)
  8441. "Switch to monthly view for agenda.
  8442. With argument MONTH, switch to that month. If MONTH has more
  8443. then 2 digits, only the last two encode the month. Any digits
  8444. before this encode a year. So 200712 means December year 2007.
  8445. Years ranging from 70 years ago to 30 years in the future can
  8446. also be written as 2-digit years."
  8447. (interactive "P")
  8448. (org-agenda-change-time-span 'month month))
  8449. (defun org-agenda-year-view (&optional year)
  8450. "Switch to yearly view for agenda.
  8451. With argument YEAR, switch to that year. Years ranging from 70
  8452. years ago to 30 years in the future can also be written as
  8453. 2-digit years."
  8454. (interactive "P")
  8455. (when year
  8456. (setq year (org-small-year-to-year year)))
  8457. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8458. (org-agenda-change-time-span 'year year)
  8459. (error "Abort")))
  8460. (defun org-agenda-change-time-span (span &optional n)
  8461. "Change the agenda view to SPAN.
  8462. SPAN may be `day', `week', `fortnight', `month', `year'."
  8463. (org-agenda-check-type t 'agenda)
  8464. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8465. (curspan (nth 2 args)))
  8466. (when (and (not n) (equal curspan span))
  8467. (error "Viewing span is already \"%s\"" span))
  8468. (let* ((sd (or (org-get-at-bol 'day)
  8469. (nth 1 args)
  8470. org-starting-day))
  8471. (sd (org-agenda-compute-starting-span sd span n))
  8472. (org-agenda-overriding-cmd
  8473. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8474. (org-agenda-overriding-arguments
  8475. (list (car args) sd span)))
  8476. (org-agenda-redo)
  8477. (org-agenda-find-same-or-today-or-agenda))
  8478. (org-agenda-set-mode-name)
  8479. (message "Switched to %s view" span)))
  8480. (defun org-agenda-compute-starting-span (sd span &optional n)
  8481. "Compute starting date for agenda.
  8482. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8483. is a cons cell with the starting date and the number of days,
  8484. so that the date SD will be in that range."
  8485. (let* ((greg (calendar-gregorian-from-absolute sd))
  8486. ;; (dg (nth 1 greg))
  8487. (mg (car greg))
  8488. (yg (nth 2 greg)))
  8489. (cond
  8490. ((eq span 'day)
  8491. (when n
  8492. (setq sd (+ (calendar-absolute-from-gregorian
  8493. (list mg 1 yg))
  8494. n -1))))
  8495. ((or (eq span 'week) (eq span 'fortnight))
  8496. (let* ((nt (calendar-day-of-week
  8497. (calendar-gregorian-from-absolute sd)))
  8498. (d (if org-agenda-start-on-weekday
  8499. (- nt org-agenda-start-on-weekday)
  8500. 0))
  8501. y1)
  8502. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8503. (when n
  8504. (require 'cal-iso)
  8505. (when (> n 99)
  8506. (setq y1 (org-small-year-to-year (/ n 100))
  8507. n (mod n 100)))
  8508. (setq sd
  8509. (calendar-iso-to-absolute
  8510. (list n 1
  8511. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8512. ((eq span 'month)
  8513. (let (y1)
  8514. (when (and n (> n 99))
  8515. (setq y1 (org-small-year-to-year (/ n 100))
  8516. n (mod n 100)))
  8517. (setq sd (calendar-absolute-from-gregorian
  8518. (list (or n mg) 1 (or y1 yg))))))
  8519. ((eq span 'year)
  8520. (setq sd (calendar-absolute-from-gregorian
  8521. (list 1 1 (or n yg))))))
  8522. sd))
  8523. (defun org-agenda-next-date-line (&optional arg)
  8524. "Jump to the next line indicating a date in agenda buffer."
  8525. (interactive "p")
  8526. (org-agenda-check-type t 'agenda)
  8527. (beginning-of-line 1)
  8528. ;; This does not work if user makes date format that starts with a blank
  8529. (when (looking-at-p "^\\S-") (forward-char 1))
  8530. (unless (re-search-forward "^\\S-" nil t arg)
  8531. (backward-char 1)
  8532. (error "No next date after this line in this buffer"))
  8533. (goto-char (match-beginning 0)))
  8534. (defun org-agenda-previous-date-line (&optional arg)
  8535. "Jump to the previous line indicating a date in agenda buffer."
  8536. (interactive "p")
  8537. (org-agenda-check-type t 'agenda)
  8538. (beginning-of-line 1)
  8539. (unless (re-search-backward "^\\S-" nil t arg)
  8540. (error "No previous date before this line in this buffer")))
  8541. ;; Initialize the highlight
  8542. (defvar org-hl (make-overlay 1 1))
  8543. (overlay-put org-hl 'face 'highlight)
  8544. (defun org-highlight (begin end &optional buffer)
  8545. "Highlight a region with overlay."
  8546. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8547. (defun org-unhighlight ()
  8548. "Detach overlay INDEX."
  8549. (delete-overlay org-hl))
  8550. (defun org-unhighlight-once ()
  8551. "Remove the highlight from its position, and this function from the hook."
  8552. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8553. (org-unhighlight))
  8554. (defvar org-agenda-pre-follow-window-conf nil)
  8555. (defun org-agenda-follow-mode ()
  8556. "Toggle follow mode in an agenda buffer."
  8557. (interactive)
  8558. (unless org-agenda-follow-mode
  8559. (setq org-agenda-pre-follow-window-conf
  8560. (current-window-configuration)))
  8561. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8562. (unless org-agenda-follow-mode
  8563. (set-window-configuration org-agenda-pre-follow-window-conf))
  8564. (org-agenda-set-mode-name)
  8565. (org-agenda-do-context-action)
  8566. (message "Follow mode is %s"
  8567. (if org-agenda-follow-mode "on" "off")))
  8568. (defun org-agenda-entry-text-mode (&optional arg)
  8569. "Toggle entry text mode in an agenda buffer."
  8570. (interactive "P")
  8571. (if (or org-agenda-tag-filter
  8572. org-agenda-category-filter
  8573. org-agenda-regexp-filter
  8574. org-agenda-top-headline-filter)
  8575. (user-error "Can't show entry text in filtered views")
  8576. (setq org-agenda-entry-text-mode (or (integerp arg)
  8577. (not org-agenda-entry-text-mode)))
  8578. (org-agenda-entry-text-hide)
  8579. (and org-agenda-entry-text-mode
  8580. (let ((org-agenda-entry-text-maxlines
  8581. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8582. (org-agenda-entry-text-show)))
  8583. (org-agenda-set-mode-name)
  8584. (message "Entry text mode is %s%s"
  8585. (if org-agenda-entry-text-mode "on" "off")
  8586. (if (not org-agenda-entry-text-mode) ""
  8587. (format " (maximum number of lines is %d)"
  8588. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8589. (defun org-agenda-clockreport-mode ()
  8590. "Toggle clocktable mode in an agenda buffer."
  8591. (interactive)
  8592. (org-agenda-check-type t 'agenda)
  8593. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8594. (org-agenda-set-mode-name)
  8595. (org-agenda-redo)
  8596. (message "Clocktable mode is %s"
  8597. (if org-agenda-clockreport-mode "on" "off")))
  8598. (defun org-agenda-log-mode (&optional special)
  8599. "Toggle log mode in an agenda buffer.
  8600. With argument SPECIAL, show all possible log items, not only the ones
  8601. configured in `org-agenda-log-mode-items'.
  8602. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8603. log items, nothing else."
  8604. (interactive "P")
  8605. (org-agenda-check-type t 'agenda)
  8606. (setq org-agenda-show-log
  8607. (cond
  8608. ((equal special '(16)) 'only)
  8609. ((eq special 'clockcheck)
  8610. (if (eq org-agenda-show-log 'clockcheck)
  8611. nil 'clockcheck))
  8612. (special '(closed clock state))
  8613. (t (not org-agenda-show-log))))
  8614. (org-agenda-set-mode-name)
  8615. (org-agenda-redo)
  8616. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8617. (defun org-agenda-archives-mode (&optional with-files)
  8618. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8619. When called with a prefix argument, include all archive files as well."
  8620. (interactive "P")
  8621. (setq org-agenda-archives-mode
  8622. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8623. (with-files t)
  8624. (org-agenda-archives-mode nil)
  8625. (t 'trees)))
  8626. (org-agenda-set-mode-name)
  8627. (org-agenda-redo)
  8628. (message
  8629. "%s"
  8630. (cond
  8631. ((eq org-agenda-archives-mode nil)
  8632. "No archives are included")
  8633. ((eq org-agenda-archives-mode 'trees)
  8634. (format "Trees with :%s: tag are included" org-archive-tag))
  8635. ((eq org-agenda-archives-mode t)
  8636. (format "Trees with :%s: tag and all active archive files are included"
  8637. org-archive-tag)))))
  8638. (defun org-agenda-toggle-diary ()
  8639. "Toggle diary inclusion in an agenda buffer."
  8640. (interactive)
  8641. (org-agenda-check-type t 'agenda)
  8642. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8643. (org-agenda-redo)
  8644. (org-agenda-set-mode-name)
  8645. (message "Diary inclusion turned %s"
  8646. (if org-agenda-include-diary "on" "off")))
  8647. (defun org-agenda-toggle-deadlines ()
  8648. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8649. (interactive)
  8650. (org-agenda-check-type t 'agenda)
  8651. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8652. (org-agenda-redo)
  8653. (org-agenda-set-mode-name)
  8654. (message "Deadlines inclusion turned %s"
  8655. (if org-agenda-include-deadlines "on" "off")))
  8656. (defun org-agenda-toggle-time-grid ()
  8657. "Toggle time grid in an agenda buffer."
  8658. (interactive)
  8659. (org-agenda-check-type t 'agenda)
  8660. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8661. (org-agenda-redo)
  8662. (org-agenda-set-mode-name)
  8663. (message "Time-grid turned %s"
  8664. (if org-agenda-use-time-grid "on" "off")))
  8665. (defun org-agenda-set-mode-name ()
  8666. "Set the mode name to indicate all the small mode settings."
  8667. (setq mode-name
  8668. (list "Org-Agenda"
  8669. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8670. " "
  8671. '(:eval (org-agenda-span-name org-agenda-current-span))
  8672. (if org-agenda-follow-mode " Follow" "")
  8673. (if org-agenda-entry-text-mode " ETxt" "")
  8674. (if org-agenda-include-diary " Diary" "")
  8675. (if org-agenda-include-deadlines " Ddl" "")
  8676. (if org-agenda-use-time-grid " Grid" "")
  8677. (if (and (boundp 'org-habit-show-habits)
  8678. org-habit-show-habits)
  8679. " Habit" "")
  8680. (cond
  8681. ((consp org-agenda-show-log) " LogAll")
  8682. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8683. (org-agenda-show-log " Log")
  8684. (t ""))
  8685. (if (org-agenda-filter-any) " " "")
  8686. (if (or org-agenda-category-filter
  8687. (get 'org-agenda-category-filter :preset-filter))
  8688. '(:eval (propertize
  8689. (concat "["
  8690. (mapconcat
  8691. #'identity
  8692. (append
  8693. (get 'org-agenda-category-filter :preset-filter)
  8694. org-agenda-category-filter)
  8695. "")
  8696. "]")
  8697. 'face 'org-agenda-filter-category
  8698. 'help-echo "Category used in filtering"))
  8699. "")
  8700. (if (or org-agenda-tag-filter
  8701. (get 'org-agenda-tag-filter :preset-filter))
  8702. '(:eval (propertize
  8703. (concat (mapconcat
  8704. #'identity
  8705. (append
  8706. (get 'org-agenda-tag-filter :preset-filter)
  8707. org-agenda-tag-filter)
  8708. ""))
  8709. 'face 'org-agenda-filter-tags
  8710. 'help-echo "Tags used in filtering"))
  8711. "")
  8712. (if (or org-agenda-effort-filter
  8713. (get 'org-agenda-effort-filter :preset-filter))
  8714. '(:eval (propertize
  8715. (concat (mapconcat
  8716. #'identity
  8717. (append
  8718. (get 'org-agenda-effort-filter :preset-filter)
  8719. org-agenda-effort-filter)
  8720. ""))
  8721. 'face 'org-agenda-filter-effort
  8722. 'help-echo "Effort conditions used in filtering"))
  8723. "")
  8724. (if (or org-agenda-regexp-filter
  8725. (get 'org-agenda-regexp-filter :preset-filter))
  8726. '(:eval (propertize
  8727. (concat (mapconcat
  8728. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8729. (append
  8730. (get 'org-agenda-regexp-filter :preset-filter)
  8731. org-agenda-regexp-filter)
  8732. ""))
  8733. 'face 'org-agenda-filter-regexp
  8734. 'help-echo "Regexp used in filtering"))
  8735. "")
  8736. (if org-agenda-archives-mode
  8737. (if (eq org-agenda-archives-mode t)
  8738. " Archives"
  8739. (format " :%s:" org-archive-tag))
  8740. "")
  8741. (if org-agenda-clockreport-mode " Clock" "")))
  8742. (force-mode-line-update))
  8743. (defun org-agenda-update-agenda-type ()
  8744. "Update the agenda type after each command."
  8745. (setq org-agenda-type
  8746. (or (get-text-property (point) 'org-agenda-type)
  8747. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8748. (defun org-agenda-next-line ()
  8749. "Move cursor to the next line, and show if follow mode is active."
  8750. (interactive)
  8751. (call-interactively 'next-line)
  8752. (org-agenda-do-context-action))
  8753. (defun org-agenda-previous-line ()
  8754. "Move cursor to the previous line, and show if follow-mode is active."
  8755. (interactive)
  8756. (call-interactively 'previous-line)
  8757. (org-agenda-do-context-action))
  8758. (defun org-agenda-next-item (n)
  8759. "Move cursor to next agenda item."
  8760. (interactive "p")
  8761. (let ((col (current-column)))
  8762. (dotimes (_ n)
  8763. (when (next-single-property-change (point-at-eol) 'org-marker)
  8764. (move-end-of-line 1)
  8765. (goto-char (next-single-property-change (point) 'org-marker))))
  8766. (org-move-to-column col))
  8767. (org-agenda-do-context-action))
  8768. (defun org-agenda-previous-item (n)
  8769. "Move cursor to next agenda item."
  8770. (interactive "p")
  8771. (dotimes (_ n)
  8772. (let ((col (current-column))
  8773. (goto (save-excursion
  8774. (move-end-of-line 0)
  8775. (previous-single-property-change (point) 'org-marker))))
  8776. (when goto (goto-char goto))
  8777. (org-move-to-column col)))
  8778. (org-agenda-do-context-action))
  8779. (defun org-agenda-do-context-action ()
  8780. "Show outline path and, maybe, follow mode window."
  8781. (let ((m (org-get-at-bol 'org-marker)))
  8782. (when (and (markerp m) (marker-buffer m))
  8783. (and org-agenda-follow-mode
  8784. (if org-agenda-follow-indirect
  8785. (org-agenda-tree-to-indirect-buffer nil)
  8786. (org-agenda-show)))
  8787. (and org-agenda-show-outline-path
  8788. (org-with-point-at m (org-display-outline-path t))))))
  8789. (defun org-agenda-show-tags ()
  8790. "Show the tags applicable to the current item."
  8791. (interactive)
  8792. (let* ((tags (org-get-at-bol 'tags)))
  8793. (if tags
  8794. (message "Tags are :%s:"
  8795. (org-no-properties (mapconcat #'identity tags ":")))
  8796. (message "No tags associated with this line"))))
  8797. (defun org-agenda-goto (&optional highlight)
  8798. "Go to the entry at point in the corresponding Org file."
  8799. (interactive)
  8800. (let* ((marker (or (org-get-at-bol 'org-marker)
  8801. (org-agenda-error)))
  8802. (buffer (marker-buffer marker))
  8803. (pos (marker-position marker)))
  8804. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8805. (switch-to-buffer-other-window buffer)
  8806. (widen)
  8807. (push-mark)
  8808. (goto-char pos)
  8809. (when (derived-mode-p 'org-mode)
  8810. (org-fold-show-context 'agenda)
  8811. (recenter (/ (window-height) 2))
  8812. (org-back-to-heading t)
  8813. (let ((case-fold-search nil))
  8814. (when (re-search-forward org-complex-heading-regexp nil t)
  8815. (goto-char (match-beginning 4)))))
  8816. (run-hooks 'org-agenda-after-show-hook)
  8817. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8818. (defvar org-agenda-after-show-hook nil
  8819. "Normal hook run after an item has been shown from the agenda.
  8820. Point is in the buffer where the item originated.")
  8821. ;; Defined later in org-agenda.el
  8822. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8823. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8824. "Between region BEG and END, call agenda command CMD.
  8825. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8826. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8827. deletes the agenda entry and don't move to the next entry."
  8828. (save-excursion
  8829. (goto-char beg)
  8830. (let ((mend (move-marker (make-marker) end))
  8831. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8832. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8833. org-agenda-loop-over-headlines-in-active-region))
  8834. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8835. (org-get-at-bol 'level))))
  8836. (while (< (point) mend)
  8837. (let ((ov (make-overlay (point) (point-at-eol))))
  8838. (if (not (or all
  8839. (and match (looking-at-p match))
  8840. (eq level (org-get-at-bol 'level))))
  8841. (org-agenda-next-item 1)
  8842. (overlay-put ov 'face 'region)
  8843. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8844. (when (not delete) (org-agenda-next-item 1))
  8845. (delete-overlay ov)))))))
  8846. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8847. ;; kill,set-property,set-effort] commands may loop over agenda
  8848. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8849. ;; use their own mechanisms on active regions.
  8850. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8851. "Maybe loop over agenda entries and perform CMD.
  8852. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8853. (declare (debug t))
  8854. `(if (and (called-interactively-p 'any)
  8855. org-agenda-loop-over-headlines-in-active-region
  8856. (org-region-active-p))
  8857. (org-agenda-do-in-region
  8858. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8859. ,@body))
  8860. (defun org-agenda-kill ()
  8861. "Kill the entry or subtree belonging to the current agenda entry."
  8862. (interactive)
  8863. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8864. (org-agenda-maybe-loop
  8865. #'org-agenda-kill nil nil t
  8866. (let* ((bufname-orig (buffer-name))
  8867. (marker (or (org-get-at-bol 'org-marker)
  8868. (org-agenda-error)))
  8869. (buffer (marker-buffer marker))
  8870. (pos (marker-position marker))
  8871. (type (org-get-at-bol 'type))
  8872. dbeg dend (n 0))
  8873. (org-with-remote-undo buffer
  8874. (with-current-buffer buffer
  8875. (save-excursion
  8876. (goto-char pos)
  8877. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8878. (setq dbeg (progn (org-back-to-heading t) (point))
  8879. dend (org-end-of-subtree t t))
  8880. (setq dbeg (point-at-bol)
  8881. dend (min (point-max) (1+ (point-at-eol)))))
  8882. (goto-char dbeg)
  8883. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8884. (when (or (eq t org-agenda-confirm-kill)
  8885. (and (numberp org-agenda-confirm-kill)
  8886. (> n org-agenda-confirm-kill)))
  8887. (let ((win-conf (current-window-configuration)))
  8888. (unwind-protect
  8889. (and
  8890. (prog2
  8891. (org-agenda-tree-to-indirect-buffer nil)
  8892. (not (y-or-n-p
  8893. (format "Delete entry with %d lines in buffer \"%s\"? "
  8894. n (buffer-name buffer))))
  8895. (kill-buffer org-last-indirect-buffer))
  8896. (error "Abort"))
  8897. (set-window-configuration win-conf))))
  8898. (let ((org-agenda-buffer-name bufname-orig))
  8899. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8900. (with-current-buffer buffer (delete-region dbeg dend))
  8901. (message "Agenda item and source killed")))))
  8902. (defvar org-archive-default-command) ; defined in org-archive.el
  8903. (defun org-agenda-archive-default ()
  8904. "Archive the entry or subtree belonging to the current agenda entry."
  8905. (interactive)
  8906. (require 'org-archive)
  8907. (funcall-interactively
  8908. #'org-agenda-archive-with org-archive-default-command))
  8909. (defun org-agenda-archive-default-with-confirmation ()
  8910. "Archive the entry or subtree belonging to the current agenda entry."
  8911. (interactive)
  8912. (require 'org-archive)
  8913. (funcall-interactively
  8914. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8915. (defun org-agenda-archive ()
  8916. "Archive the entry or subtree belonging to the current agenda entry."
  8917. (interactive)
  8918. (funcall-interactively
  8919. #'org-agenda-archive-with 'org-archive-subtree))
  8920. (defun org-agenda-archive-to-archive-sibling ()
  8921. "Move the entry to the archive sibling."
  8922. (interactive)
  8923. (funcall-interactively
  8924. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8925. (defvar org-archive-from-agenda)
  8926. (defun org-agenda-archive-with (cmd &optional confirm)
  8927. "Move the entry to the archive sibling."
  8928. (interactive)
  8929. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8930. (org-agenda-maybe-loop
  8931. #'org-agenda-archive-with cmd nil t
  8932. (let* ((bufname-orig (buffer-name))
  8933. (marker (or (org-get-at-bol 'org-marker)
  8934. (org-agenda-error)))
  8935. (buffer (marker-buffer marker))
  8936. (pos (marker-position marker)))
  8937. (org-with-remote-undo buffer
  8938. (with-current-buffer buffer
  8939. (if (derived-mode-p 'org-mode)
  8940. (if (and confirm
  8941. (not (y-or-n-p "Archive this subtree or entry? ")))
  8942. (error "Abort")
  8943. (save-window-excursion
  8944. (goto-char pos)
  8945. (let ((org-agenda-buffer-name bufname-orig))
  8946. (org-remove-subtree-entries-from-agenda))
  8947. (org-back-to-heading t)
  8948. (let ((org-archive-from-agenda t))
  8949. (funcall cmd))))
  8950. (error "Archiving works only in Org files")))))))
  8951. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8952. "Remove all lines in the agenda that correspond to a given subtree.
  8953. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8954. If this information is not given, the function uses the tree at point."
  8955. (let ((buf (or buf (current-buffer))) m p)
  8956. (save-excursion
  8957. (unless (and beg end)
  8958. (org-back-to-heading t)
  8959. (setq beg (point))
  8960. (org-end-of-subtree t)
  8961. (setq end (point)))
  8962. (set-buffer (get-buffer org-agenda-buffer-name))
  8963. (save-excursion
  8964. (goto-char (point-max))
  8965. (beginning-of-line 1)
  8966. (while (not (bobp))
  8967. (when (and (setq m (org-get-at-bol 'org-marker))
  8968. (equal buf (marker-buffer m))
  8969. (setq p (marker-position m))
  8970. (>= p beg)
  8971. (< p end))
  8972. (let ((inhibit-read-only t))
  8973. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8974. (beginning-of-line 0))))))
  8975. (defun org-agenda-refile (&optional goto rfloc no-update)
  8976. "Refile the item at point.
  8977. When called with `\\[universal-argument] \\[universal-argument]', \
  8978. go to the location of the last
  8979. refiled item.
  8980. When called with `\\[universal-argument] \\[universal-argument] \
  8981. \\[universal-argument]' prefix or when GOTO is 0, clear
  8982. the refile cache.
  8983. RFLOC can be a refile location obtained in a different way.
  8984. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8985. (interactive "P")
  8986. (cond
  8987. ((member goto '(0 (64)))
  8988. (org-refile-cache-clear))
  8989. ((equal goto '(16))
  8990. (org-refile-goto-last-stored))
  8991. (t
  8992. (let* ((buffer-orig (buffer-name))
  8993. (marker (or (org-get-at-bol 'org-hd-marker)
  8994. (org-agenda-error)))
  8995. (buffer (marker-buffer marker))
  8996. ;; (pos (marker-position marker))
  8997. (rfloc (or rfloc
  8998. (org-refile-get-location
  8999. (if goto "Goto" "Refile to") buffer
  9000. org-refile-allow-creating-parent-nodes))))
  9001. (with-current-buffer buffer
  9002. (org-with-wide-buffer
  9003. (goto-char marker)
  9004. (let ((org-agenda-buffer-name buffer-orig))
  9005. (org-remove-subtree-entries-from-agenda))
  9006. (org-refile goto buffer rfloc))))
  9007. (unless no-update (org-agenda-redo)))))
  9008. (defun org-agenda-open-link (&optional arg)
  9009. "Open the link(s) in the current entry, if any.
  9010. This looks for a link in the displayed line in the agenda.
  9011. It also looks at the text of the entry itself."
  9012. (interactive "P")
  9013. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9014. (org-get-at-bol 'org-marker)))
  9015. (buffer (and marker (marker-buffer marker)))
  9016. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  9017. (lkall (and buffer (org-offer-links-in-entry
  9018. buffer marker arg prefix)))
  9019. (lk0 (car lkall))
  9020. (lk (if (stringp lk0) (list lk0) lk0))
  9021. (lkend (cdr lkall))
  9022. trg)
  9023. (cond
  9024. ((and buffer lk)
  9025. (mapcar (lambda(l)
  9026. (with-current-buffer buffer
  9027. (setq trg (and (string-match org-link-bracket-re l)
  9028. (match-string 1 l)))
  9029. (if (or (not trg) (string-match org-link-any-re trg))
  9030. ;; Don't use `org-with-wide-buffer' here as
  9031. ;; opening the link may result in moving the point
  9032. (save-restriction
  9033. (widen)
  9034. (goto-char marker)
  9035. (when (search-forward l nil lkend)
  9036. (goto-char (match-beginning 0))
  9037. (org-open-at-point)))
  9038. ;; This is an internal link, widen the buffer
  9039. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9040. (switch-to-buffer-other-window buffer)
  9041. (widen)
  9042. (goto-char marker)
  9043. (when (search-forward l nil lkend)
  9044. (goto-char (match-beginning 0))
  9045. (org-open-at-point)))))
  9046. lk))
  9047. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9048. (save-excursion
  9049. (beginning-of-line 1)
  9050. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9051. (org-link-open-from-string (match-string 1)))
  9052. (t (message "No link to open here")))))
  9053. (defun org-agenda-copy-local-variable (var)
  9054. "Get a variable from a referenced buffer and install it here."
  9055. (let ((m (org-get-at-bol 'org-marker)))
  9056. (when (and m (buffer-live-p (marker-buffer m)))
  9057. (set (make-local-variable var)
  9058. (with-current-buffer (marker-buffer m)
  9059. (symbol-value var))))))
  9060. (defun org-agenda-switch-to (&optional delete-other-windows)
  9061. "Go to the Org mode file which contains the item at point.
  9062. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9063. displayed Org file fills the frame."
  9064. (interactive)
  9065. (if (and org-return-follows-link
  9066. (not (org-get-at-bol 'org-marker))
  9067. (org-in-regexp org-link-bracket-re))
  9068. (org-link-open-from-string (match-string 0))
  9069. (let* ((marker (or (org-get-at-bol 'org-marker)
  9070. (org-agenda-error)))
  9071. (buffer (marker-buffer marker))
  9072. (pos (marker-position marker)))
  9073. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9074. (pop-to-buffer-same-window buffer)
  9075. (when delete-other-windows (delete-other-windows))
  9076. (widen)
  9077. (goto-char pos)
  9078. (when (derived-mode-p 'org-mode)
  9079. (org-fold-show-context 'agenda)
  9080. (run-hooks 'org-agenda-after-show-hook)))))
  9081. (defun org-agenda-goto-mouse (ev)
  9082. "Go to the Org file which contains the item at the mouse click."
  9083. (interactive "e")
  9084. (mouse-set-point ev)
  9085. (org-agenda-goto))
  9086. (defun org-agenda-show (&optional full-entry)
  9087. "Display the Org file which contains the item at point.
  9088. With prefix argument FULL-ENTRY, make the entire entry visible
  9089. if it was hidden in the outline."
  9090. (interactive "P")
  9091. (let ((win (selected-window)))
  9092. (org-agenda-goto t)
  9093. (when full-entry (org-fold-show-entry))
  9094. (select-window win)))
  9095. (defvar org-agenda-show-window nil)
  9096. (defun org-agenda-show-and-scroll-up (&optional arg)
  9097. "Display the Org file which contains the item at point.
  9098. When called repeatedly, scroll the window that is displaying the buffer.
  9099. With a `\\[universal-argument]' prefix argument, display the item, but \
  9100. fold drawers."
  9101. (interactive "P")
  9102. (let ((win (selected-window)))
  9103. (if (and (window-live-p org-agenda-show-window)
  9104. (eq this-command last-command))
  9105. (progn
  9106. (select-window org-agenda-show-window)
  9107. (ignore-errors (scroll-up)))
  9108. (org-agenda-goto t)
  9109. (org-fold-show-entry)
  9110. (if arg (org-cycle-hide-drawers 'children)
  9111. (org-with-wide-buffer
  9112. (narrow-to-region (org-entry-beginning-position)
  9113. (org-entry-end-position))
  9114. (org-fold-show-all '(drawers))))
  9115. (setq org-agenda-show-window (selected-window)))
  9116. (select-window win)))
  9117. (defun org-agenda-show-scroll-down ()
  9118. "Scroll down the window showing the agenda."
  9119. (interactive)
  9120. (let ((win (selected-window)))
  9121. (when (window-live-p org-agenda-show-window)
  9122. (select-window org-agenda-show-window)
  9123. (ignore-errors (scroll-down))
  9124. (select-window win))))
  9125. (defun org-agenda-show-1 (&optional more)
  9126. "Display the Org file which contains the item at point.
  9127. The prefix arg selects the amount of information to display:
  9128. 0 hide the subtree
  9129. 1 just show the entry according to defaults.
  9130. 2 show the children view
  9131. 3 show the subtree view
  9132. 4 show the entire subtree and any drawers
  9133. With prefix argument FULL-ENTRY, make the entire entry visible
  9134. if it was hidden in the outline."
  9135. (interactive "p")
  9136. (let ((win (selected-window)))
  9137. (org-agenda-goto t)
  9138. (org-back-to-heading)
  9139. (set-window-start (selected-window) (point-at-bol))
  9140. (cond
  9141. ((= more 0)
  9142. (org-fold-subtree t)
  9143. (save-excursion
  9144. (org-back-to-heading)
  9145. (run-hook-with-args 'org-cycle-hook 'folded))
  9146. (message "Remote: FOLDED"))
  9147. ((and (called-interactively-p 'any) (= more 1))
  9148. (message "Remote: show with default settings"))
  9149. ((= more 2)
  9150. (org-fold-show-entry)
  9151. (org-fold-show-children)
  9152. (save-excursion
  9153. (org-back-to-heading)
  9154. (run-hook-with-args 'org-cycle-hook 'children))
  9155. (message "Remote: CHILDREN"))
  9156. ((= more 3)
  9157. (org-fold-show-subtree)
  9158. (save-excursion
  9159. (org-back-to-heading)
  9160. (run-hook-with-args 'org-cycle-hook 'subtree))
  9161. (message "Remote: SUBTREE"))
  9162. ((> more 3)
  9163. (org-fold-show-subtree)
  9164. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9165. (select-window win)))
  9166. (defvar org-agenda-cycle-counter nil)
  9167. (defun org-agenda-cycle-show (&optional n)
  9168. "Show the current entry in another window, with default settings.
  9169. Default settings are taken from `org-show-context-detail'. When
  9170. use repeatedly in immediate succession, the remote entry will
  9171. cycle through visibility
  9172. children -> subtree -> folded
  9173. When called with a numeric prefix arg, that arg will be passed through to
  9174. `org-agenda-show-1'. For the interpretation of that argument, see the
  9175. docstring of `org-agenda-show-1'."
  9176. (interactive "P")
  9177. (if (integerp n)
  9178. (setq org-agenda-cycle-counter n)
  9179. (if (not (eq last-command this-command))
  9180. (setq org-agenda-cycle-counter 1)
  9181. (if (equal org-agenda-cycle-counter 0)
  9182. (setq org-agenda-cycle-counter 2)
  9183. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9184. (when (> org-agenda-cycle-counter 3)
  9185. (setq org-agenda-cycle-counter 0)))))
  9186. (org-agenda-show-1 org-agenda-cycle-counter))
  9187. (defun org-agenda-recenter (arg)
  9188. "Display the Org file which contains the item at point and recenter."
  9189. (interactive "P")
  9190. (let ((win (selected-window)))
  9191. (org-agenda-goto t)
  9192. (recenter arg)
  9193. (select-window win)))
  9194. (defun org-agenda-show-mouse (ev)
  9195. "Display the Org file which contains the item at the mouse click."
  9196. (interactive "e")
  9197. (mouse-set-point ev)
  9198. (org-agenda-show))
  9199. (defun org-agenda-check-no-diary ()
  9200. "Check if the entry is a diary link and abort if yes."
  9201. (when (org-get-at-bol 'org-agenda-diary-link)
  9202. (org-agenda-error)))
  9203. (defun org-agenda-error ()
  9204. "Throw an error when a command is not allowed in the agenda."
  9205. (user-error "Command not allowed in this line"))
  9206. (defun org-agenda-tree-to-indirect-buffer (arg)
  9207. "Show the subtree corresponding to the current entry in an indirect buffer.
  9208. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9209. With a numerical prefix ARG, go up to this level and then take that tree.
  9210. With a negative numeric ARG, go up by this number of levels.
  9211. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9212. i.e. don't use
  9213. the dedicated frame."
  9214. (interactive "P")
  9215. (if current-prefix-arg
  9216. (org-agenda-do-tree-to-indirect-buffer arg)
  9217. (let ((agenda-buffer (buffer-name))
  9218. (agenda-window (selected-window))
  9219. (indirect-window
  9220. (and org-last-indirect-buffer
  9221. (get-buffer-window org-last-indirect-buffer))))
  9222. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9223. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9224. (eq org-indirect-buffer-display 'dedicated-frame))
  9225. (unwind-protect
  9226. (unless (and indirect-window (window-live-p indirect-window))
  9227. (setq indirect-window (split-window agenda-window)))
  9228. (and indirect-window (select-window indirect-window))
  9229. (switch-to-buffer org-last-indirect-buffer :norecord)
  9230. (fit-window-to-buffer indirect-window)))
  9231. (select-window (get-buffer-window agenda-buffer))
  9232. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9233. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9234. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9235. (org-agenda-check-no-diary)
  9236. (let* ((marker (or (org-get-at-bol 'org-marker)
  9237. (org-agenda-error)))
  9238. (buffer (marker-buffer marker))
  9239. (pos (marker-position marker)))
  9240. (with-current-buffer buffer
  9241. (save-excursion
  9242. (goto-char pos)
  9243. (org-tree-to-indirect-buffer arg)))))
  9244. (defvar org-last-heading-marker (make-marker)
  9245. "Marker pointing to the headline that last changed its TODO state
  9246. by a remote command from the agenda.")
  9247. (defun org-agenda-todo-nextset ()
  9248. "Switch TODO entry to next sequence."
  9249. (interactive)
  9250. (org-agenda-todo 'nextset))
  9251. (defun org-agenda-todo-previousset ()
  9252. "Switch TODO entry to previous sequence."
  9253. (interactive)
  9254. (org-agenda-todo 'previousset))
  9255. (defvar org-agenda-headline-snapshot-before-repeat)
  9256. (defun org-agenda-todo (&optional arg)
  9257. "Cycle TODO state of line at point, also in Org file.
  9258. This changes the line at point, all other lines in the agenda referring to
  9259. the same tree node, and the headline of the tree node in the Org file."
  9260. (interactive "P")
  9261. (org-agenda-check-no-diary)
  9262. (org-agenda-maybe-loop
  9263. #'org-agenda-todo arg nil nil
  9264. (let* ((col (current-column))
  9265. (marker (or (org-get-at-bol 'org-marker)
  9266. (org-agenda-error)))
  9267. (buffer (marker-buffer marker))
  9268. (pos (marker-position marker))
  9269. (hdmarker (org-get-at-bol 'org-hd-marker))
  9270. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9271. (inhibit-read-only t)
  9272. org-loop-over-headlines-in-active-region
  9273. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9274. (org-with-remote-undo buffer
  9275. (with-current-buffer buffer
  9276. (widen)
  9277. (goto-char pos)
  9278. (org-fold-show-context 'agenda)
  9279. (let ((current-prefix-arg arg))
  9280. (call-interactively 'org-todo)
  9281. ;; Make sure that log is recorded in current undo.
  9282. (when (and org-log-setup
  9283. (not (eq org-log-note-how 'note)))
  9284. (org-add-log-note)))
  9285. (and (bolp) (forward-char 1))
  9286. (setq newhead (org-get-heading))
  9287. (when (and org-agenda-headline-snapshot-before-repeat
  9288. (not (equal org-agenda-headline-snapshot-before-repeat
  9289. newhead))
  9290. todayp)
  9291. (setq newhead org-agenda-headline-snapshot-before-repeat
  9292. just-one t))
  9293. (save-excursion
  9294. (org-back-to-heading)
  9295. (move-marker org-last-heading-marker (point))))
  9296. (beginning-of-line 1)
  9297. (save-window-excursion
  9298. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9299. (when (bound-and-true-p org-clock-out-when-done)
  9300. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9301. newhead)
  9302. (org-agenda-unmark-clocking-task))
  9303. (org-move-to-column col)
  9304. (org-agenda-mark-clocking-task)))))
  9305. (defun org-agenda-add-note (&optional _arg)
  9306. "Add a time-stamped note to the entry at point."
  9307. (interactive) ;; "P"
  9308. (org-agenda-check-no-diary)
  9309. (let* ((marker (or (org-get-at-bol 'org-marker)
  9310. (org-agenda-error)))
  9311. (buffer (marker-buffer marker))
  9312. (pos (marker-position marker))
  9313. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9314. (inhibit-read-only t))
  9315. (with-current-buffer buffer
  9316. (widen)
  9317. (goto-char pos)
  9318. (org-fold-show-context 'agenda)
  9319. (org-add-note))))
  9320. (defun org-agenda-change-all-lines (newhead hdmarker
  9321. &optional fixface just-this)
  9322. "Change all lines in the agenda buffer which match HDMARKER.
  9323. The new content of the line will be NEWHEAD (as modified by
  9324. `org-agenda-format-item'). HDMARKER is checked with
  9325. `equal' against all `org-hd-marker' text properties in the file.
  9326. If FIXFACE is non-nil, the face of each item is modified according to
  9327. the new TODO state.
  9328. If JUST-THIS is non-nil, change just the current line, not all.
  9329. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9330. (let* ((inhibit-read-only t)
  9331. (line (org-current-line))
  9332. (org-agenda-buffer (current-buffer))
  9333. (thetags (with-current-buffer (marker-buffer hdmarker)
  9334. (org-get-tags hdmarker)))
  9335. props m undone-face done-face finish new dotime level cat tags
  9336. effort effort-minutes) ;; pl
  9337. (save-excursion
  9338. (goto-char (point-max))
  9339. (beginning-of-line 1)
  9340. (while (not finish)
  9341. (setq finish (bobp))
  9342. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9343. (or (not just-this) (= (org-current-line) line))
  9344. (equal m hdmarker))
  9345. (setq props (text-properties-at (point))
  9346. dotime (org-get-at-bol 'dotime)
  9347. cat (org-agenda-get-category)
  9348. level (org-get-at-bol 'level)
  9349. tags thetags
  9350. effort (org-get-at-bol 'effort)
  9351. effort-minutes (org-get-at-bol 'effort-minutes)
  9352. new
  9353. (let ((org-prefix-format-compiled
  9354. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9355. org-prefix-format-compiled))
  9356. (extra (org-get-at-bol 'extra)))
  9357. (with-current-buffer (marker-buffer hdmarker)
  9358. (org-with-wide-buffer
  9359. (org-agenda-format-item extra
  9360. (org-add-props newhead nil
  9361. 'effort effort
  9362. 'effort-minutes effort-minutes)
  9363. level cat tags dotime))))
  9364. ;; pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  9365. undone-face (org-get-at-bol 'undone-face)
  9366. done-face (org-get-at-bol 'done-face))
  9367. (beginning-of-line 1)
  9368. (cond
  9369. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9370. ((looking-at ".*")
  9371. ;; When replacing the whole line, preserve bulk mark
  9372. ;; overlay, if any.
  9373. (let ((mark (catch :overlay
  9374. (dolist (o (overlays-in (point) (+ 2 (point))))
  9375. (when (eq (overlay-get o 'type)
  9376. 'org-marked-entry-overlay)
  9377. (throw :overlay o))))))
  9378. (replace-match new t t)
  9379. (beginning-of-line)
  9380. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9381. (add-text-properties (point-at-bol) (point-at-eol) props)
  9382. (when fixface
  9383. (add-text-properties
  9384. (point-at-bol) (point-at-eol)
  9385. (list 'face
  9386. (if org-last-todo-state-is-todo
  9387. undone-face done-face))))
  9388. (org-agenda-highlight-todo 'line)
  9389. (beginning-of-line 1))
  9390. (t (error "Line update did not work")))
  9391. (save-restriction
  9392. (narrow-to-region (point-at-bol) (point-at-eol))
  9393. (org-agenda-finalize)))
  9394. (beginning-of-line 0)))))
  9395. (defun org-agenda-align-tags (&optional line)
  9396. "Align all tags in agenda items to `org-agenda-tags-column'.
  9397. When optional argument LINE is non-nil, align tags only on the
  9398. current line."
  9399. (let ((inhibit-read-only t)
  9400. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9401. (- (window-max-chars-per-line))
  9402. org-agenda-tags-column))
  9403. (end (and line (line-end-position)))
  9404. l c)
  9405. (save-excursion
  9406. (goto-char (if line (line-beginning-position) (point-min)))
  9407. (while (re-search-forward org-tag-group-re end t)
  9408. (add-text-properties
  9409. (match-beginning 1) (match-end 1)
  9410. (list 'face (delq nil (let ((prop (get-text-property
  9411. (match-beginning 1) 'face)))
  9412. (or (listp prop) (setq prop (list prop)))
  9413. (if (memq 'org-tag prop)
  9414. prop
  9415. (cons 'org-tag prop))))))
  9416. (setq l (string-width (match-string 1))
  9417. c (if (< org-agenda-tags-column 0)
  9418. (- (abs org-agenda-tags-column) l)
  9419. org-agenda-tags-column))
  9420. (goto-char (match-beginning 1))
  9421. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9422. (point))
  9423. (insert (org-add-props
  9424. (make-string (max 1 (- c (current-column))) ?\s)
  9425. (plist-put (copy-sequence (text-properties-at (point)))
  9426. 'face nil))))
  9427. (goto-char (point-min))
  9428. (org-font-lock-add-tag-faces (point-max)))))
  9429. (defun org-agenda-priority-up ()
  9430. "Increase the priority of line at point, also in Org file."
  9431. (interactive)
  9432. (org-agenda-priority 'up))
  9433. (defun org-agenda-priority-down ()
  9434. "Decrease the priority of line at point, also in Org file."
  9435. (interactive)
  9436. (org-agenda-priority 'down))
  9437. (defun org-agenda-priority (&optional force-direction)
  9438. "Set the priority of line at point, also in Org file.
  9439. This changes the line at point, all other lines in the agenda
  9440. referring to the same tree node, and the headline of the tree
  9441. node in the Org file.
  9442. Called with one universal prefix arg, show the priority instead
  9443. of setting it.
  9444. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9445. `down', or a character."
  9446. (interactive "P")
  9447. (unless org-priority-enable-commands
  9448. (user-error "Priority commands are disabled"))
  9449. (org-agenda-check-no-diary)
  9450. (let* ((col (current-column))
  9451. (hdmarker (org-get-at-bol 'org-hd-marker))
  9452. (buffer (marker-buffer hdmarker))
  9453. (pos (marker-position hdmarker))
  9454. (inhibit-read-only t)
  9455. newhead)
  9456. (org-with-remote-undo buffer
  9457. (with-current-buffer buffer
  9458. (widen)
  9459. (goto-char pos)
  9460. (org-fold-show-context 'agenda)
  9461. (org-priority force-direction)
  9462. (end-of-line 1)
  9463. (setq newhead (org-get-heading)))
  9464. (org-agenda-change-all-lines newhead hdmarker)
  9465. (org-move-to-column col))))
  9466. ;; FIXME: should fix the tags property of the agenda line.
  9467. (defun org-agenda-set-tags (&optional tag onoff)
  9468. "Set tags for the current headline."
  9469. (interactive)
  9470. (org-agenda-check-no-diary)
  9471. (if (and (org-region-active-p) (called-interactively-p 'any))
  9472. (call-interactively 'org-change-tag-in-region)
  9473. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9474. (org-agenda-error)))
  9475. (buffer (marker-buffer hdmarker))
  9476. (pos (marker-position hdmarker))
  9477. (inhibit-read-only t)
  9478. newhead)
  9479. (org-with-remote-undo buffer
  9480. (with-current-buffer buffer
  9481. (widen)
  9482. (goto-char pos)
  9483. (org-fold-show-context 'agenda)
  9484. (if tag
  9485. (org-toggle-tag tag onoff)
  9486. (call-interactively #'org-set-tags-command))
  9487. (end-of-line 1)
  9488. (setq newhead (org-get-heading)))
  9489. (org-agenda-change-all-lines newhead hdmarker)
  9490. (beginning-of-line 1)))))
  9491. (defun org-agenda-set-property ()
  9492. "Set a property for the current headline."
  9493. (interactive)
  9494. (org-agenda-check-no-diary)
  9495. (org-agenda-maybe-loop
  9496. #'org-agenda-set-property nil nil nil
  9497. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9498. (org-agenda-error)))
  9499. (buffer (marker-buffer hdmarker))
  9500. (pos (marker-position hdmarker))
  9501. (inhibit-read-only t)
  9502. ) ;; newhead
  9503. (org-with-remote-undo buffer
  9504. (with-current-buffer buffer
  9505. (widen)
  9506. (goto-char pos)
  9507. (org-fold-show-context 'agenda)
  9508. (call-interactively 'org-set-property))))))
  9509. (defun org-agenda-set-effort ()
  9510. "Set the effort property for the current headline."
  9511. (interactive)
  9512. (org-agenda-check-no-diary)
  9513. (org-agenda-maybe-loop
  9514. #'org-agenda-set-effort nil nil nil
  9515. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9516. (org-agenda-error)))
  9517. (buffer (marker-buffer hdmarker))
  9518. (pos (marker-position hdmarker))
  9519. (inhibit-read-only t)
  9520. newhead)
  9521. (org-with-remote-undo buffer
  9522. (with-current-buffer buffer
  9523. (widen)
  9524. (goto-char pos)
  9525. (org-fold-show-context 'agenda)
  9526. (call-interactively 'org-set-effort)
  9527. (end-of-line 1)
  9528. (setq newhead (org-get-heading)))
  9529. (org-agenda-change-all-lines newhead hdmarker)))))
  9530. (defun org-agenda-toggle-archive-tag ()
  9531. "Toggle the archive tag for the current entry."
  9532. (interactive)
  9533. (org-agenda-check-no-diary)
  9534. (org-agenda-maybe-loop
  9535. #'org-agenda-toggle-archive-tag nil nil nil
  9536. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9537. (org-agenda-error)))
  9538. (buffer (marker-buffer hdmarker))
  9539. (pos (marker-position hdmarker))
  9540. (inhibit-read-only t)
  9541. newhead)
  9542. (org-with-remote-undo buffer
  9543. (with-current-buffer buffer
  9544. (widen)
  9545. (goto-char pos)
  9546. (org-fold-show-context 'agenda)
  9547. (call-interactively 'org-toggle-archive-tag)
  9548. (end-of-line 1)
  9549. (setq newhead (org-get-heading)))
  9550. (org-agenda-change-all-lines newhead hdmarker)
  9551. (beginning-of-line 1)))))
  9552. (defun org-agenda-do-date-later (arg)
  9553. (interactive "P")
  9554. (cond
  9555. ((or (equal arg '(16))
  9556. (memq last-command
  9557. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9558. (setq this-command 'org-agenda-date-later-minutes)
  9559. (org-agenda-date-later-minutes 1))
  9560. ((or (equal arg '(4))
  9561. (memq last-command
  9562. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9563. (setq this-command 'org-agenda-date-later-hours)
  9564. (org-agenda-date-later-hours 1))
  9565. (t
  9566. (org-agenda-date-later (prefix-numeric-value arg)))))
  9567. (defun org-agenda-do-date-earlier (arg)
  9568. (interactive "P")
  9569. (cond
  9570. ((or (equal arg '(16))
  9571. (memq last-command
  9572. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9573. (setq this-command 'org-agenda-date-earlier-minutes)
  9574. (org-agenda-date-earlier-minutes 1))
  9575. ((or (equal arg '(4))
  9576. (memq last-command
  9577. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9578. (setq this-command 'org-agenda-date-earlier-hours)
  9579. (org-agenda-date-earlier-hours 1))
  9580. (t
  9581. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9582. (defun org-agenda-date-later (arg &optional what)
  9583. "Change the date of this item to ARG day(s) later."
  9584. (interactive "p")
  9585. (org-agenda-check-type t 'agenda)
  9586. (org-agenda-check-no-diary)
  9587. (let* ((marker (or (org-get-at-bol 'org-marker)
  9588. (org-agenda-error)))
  9589. (buffer (marker-buffer marker))
  9590. (pos (marker-position marker))
  9591. cdate today)
  9592. (org-with-remote-undo buffer
  9593. (with-current-buffer buffer
  9594. (widen)
  9595. (goto-char pos)
  9596. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9597. (when (and org-agenda-move-date-from-past-immediately-to-today
  9598. (equal arg 1)
  9599. (or (not what) (eq what 'day))
  9600. (not (save-match-data (org-at-date-range-p))))
  9601. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9602. cdate (calendar-absolute-from-gregorian
  9603. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9604. today (org-today))
  9605. (when (> today cdate)
  9606. ;; immediately shift to today
  9607. (setq arg (- today cdate))))
  9608. (org-timestamp-change arg (or what 'day))
  9609. (when (and (org-at-date-range-p)
  9610. (re-search-backward org-tr-regexp-both (point-at-bol)))
  9611. (let ((end org-last-changed-timestamp))
  9612. (org-timestamp-change arg (or what 'day))
  9613. (setq org-last-changed-timestamp
  9614. (concat org-last-changed-timestamp "--" end)))))
  9615. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9616. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9617. (defun org-agenda-date-earlier (arg &optional what)
  9618. "Change the date of this item to ARG day(s) earlier."
  9619. (interactive "p")
  9620. (org-agenda-date-later (- arg) what))
  9621. (defun org-agenda-date-later-minutes (arg)
  9622. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9623. (interactive "p")
  9624. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9625. (org-agenda-date-later arg 'minute))
  9626. (defun org-agenda-date-earlier-minutes (arg)
  9627. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9628. (interactive "p")
  9629. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9630. (org-agenda-date-earlier arg 'minute))
  9631. (defun org-agenda-date-later-hours (arg)
  9632. "Change the time of this item, in hour steps."
  9633. (interactive "p")
  9634. (org-agenda-date-later arg 'hour))
  9635. (defun org-agenda-date-earlier-hours (arg)
  9636. "Change the time of this item, in hour steps."
  9637. (interactive "p")
  9638. (org-agenda-date-earlier arg 'hour))
  9639. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9640. "Show new date stamp via text properties."
  9641. ;; We use text properties to make this undoable
  9642. (let ((inhibit-read-only t))
  9643. (setq stamp (concat prefix " => " stamp " "))
  9644. (save-excursion
  9645. (goto-char (point-max))
  9646. (while (not (bobp))
  9647. (when (equal marker (org-get-at-bol 'org-marker))
  9648. (remove-text-properties (line-beginning-position)
  9649. (line-end-position)
  9650. '(display nil))
  9651. (org-move-to-column
  9652. (- (window-max-chars-per-line)
  9653. (length stamp))
  9654. t)
  9655. (add-text-properties
  9656. (1- (point)) (point-at-eol)
  9657. (list 'display (org-add-props stamp nil
  9658. 'face '(secondary-selection default))))
  9659. (beginning-of-line 1))
  9660. (beginning-of-line 0)))))
  9661. (defun org-agenda-date-prompt (arg)
  9662. "Change the date of this item. Date is prompted for, with default today.
  9663. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9664. be used to request time specification in the time stamp."
  9665. (interactive "P")
  9666. (org-agenda-check-type t 'agenda)
  9667. (org-agenda-check-no-diary)
  9668. (org-agenda-maybe-loop
  9669. #'org-agenda-date-prompt arg t nil
  9670. (let* ((marker (or (org-get-at-bol 'org-marker)
  9671. (org-agenda-error)))
  9672. (buffer (marker-buffer marker))
  9673. (pos (marker-position marker)))
  9674. (org-with-remote-undo buffer
  9675. (with-current-buffer buffer
  9676. (widen)
  9677. (goto-char pos)
  9678. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9679. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9680. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9681. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9682. (defun org-agenda-schedule (arg &optional time)
  9683. "Schedule the item at point.
  9684. ARG is passed through to `org-schedule'."
  9685. (interactive "P")
  9686. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9687. (org-agenda-check-no-diary)
  9688. (org-agenda-maybe-loop
  9689. #'org-agenda-schedule arg t nil
  9690. (let* ((marker (or (org-get-at-bol 'org-marker)
  9691. (org-agenda-error)))
  9692. ;; (type (marker-insertion-type marker))
  9693. (buffer (marker-buffer marker))
  9694. (pos (marker-position marker))
  9695. ts)
  9696. (set-marker-insertion-type marker t)
  9697. (org-with-remote-undo buffer
  9698. (with-current-buffer buffer
  9699. (widen)
  9700. (goto-char pos)
  9701. (setq ts (org-schedule arg time)))
  9702. (org-agenda-show-new-time marker ts " S"))
  9703. (message "%s" ts))))
  9704. (defun org-agenda-deadline (arg &optional time)
  9705. "Schedule the item at point.
  9706. ARG is passed through to `org-deadline'."
  9707. (interactive "P")
  9708. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9709. (org-agenda-check-no-diary)
  9710. (org-agenda-maybe-loop
  9711. #'org-agenda-deadline arg t nil
  9712. (let* ((marker (or (org-get-at-bol 'org-marker)
  9713. (org-agenda-error)))
  9714. (buffer (marker-buffer marker))
  9715. (pos (marker-position marker))
  9716. ts)
  9717. (org-with-remote-undo buffer
  9718. (with-current-buffer buffer
  9719. (widen)
  9720. (goto-char pos)
  9721. (setq ts (org-deadline arg time)))
  9722. (org-agenda-show-new-time marker ts " D"))
  9723. (message "%s" ts))))
  9724. (defun org-agenda-clock-in (&optional arg)
  9725. "Start the clock on the currently selected item."
  9726. (interactive "P")
  9727. (org-agenda-check-no-diary)
  9728. (if (equal arg '(4))
  9729. (org-clock-in arg)
  9730. (let* ((marker (or (org-get-at-bol 'org-marker)
  9731. (org-agenda-error)))
  9732. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9733. (pos (marker-position marker))
  9734. (col (current-column))
  9735. newhead)
  9736. (org-with-remote-undo (marker-buffer marker)
  9737. (with-current-buffer (marker-buffer marker)
  9738. (widen)
  9739. (goto-char pos)
  9740. (org-fold-show-context 'agenda)
  9741. (org-clock-in arg)
  9742. (setq newhead (org-get-heading)))
  9743. (org-agenda-change-all-lines newhead hdmarker))
  9744. (org-move-to-column col))))
  9745. (defun org-agenda-clock-out ()
  9746. "Stop the currently running clock."
  9747. (interactive)
  9748. (unless (marker-buffer org-clock-marker)
  9749. (user-error "No running clock"))
  9750. (let ((marker (make-marker)) (col (current-column)) newhead)
  9751. (org-with-remote-undo (marker-buffer org-clock-marker)
  9752. (with-current-buffer (marker-buffer org-clock-marker)
  9753. (org-with-wide-buffer
  9754. (goto-char org-clock-marker)
  9755. (org-back-to-heading t)
  9756. (move-marker marker (point))
  9757. (org-clock-out)
  9758. (setq newhead (org-get-heading)))))
  9759. (org-agenda-change-all-lines newhead marker)
  9760. (move-marker marker nil)
  9761. (org-move-to-column col)
  9762. (org-agenda-unmark-clocking-task)))
  9763. (defun org-agenda-clock-cancel (&optional _arg)
  9764. "Cancel the currently running clock."
  9765. (interactive) ;; "P"
  9766. (unless (marker-buffer org-clock-marker)
  9767. (user-error "No running clock"))
  9768. (org-with-remote-undo (marker-buffer org-clock-marker)
  9769. (org-clock-cancel)))
  9770. (defun org-agenda-clock-goto ()
  9771. "Jump to the currently clocked in task within the agenda.
  9772. If the currently clocked in task is not listed in the agenda
  9773. buffer, display it in another window."
  9774. (interactive)
  9775. (let (pos)
  9776. (mapc (lambda (o)
  9777. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9778. (setq pos (overlay-start o))))
  9779. (overlays-in (point-min) (point-max)))
  9780. (cond (pos (goto-char pos))
  9781. ;; If the currently clocked entry is not in the agenda
  9782. ;; buffer, we visit it in another window:
  9783. ((bound-and-true-p org-clock-current-task)
  9784. (org-switch-to-buffer-other-window (org-clock-goto)))
  9785. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9786. (defun org-agenda-diary-entry-in-org-file ()
  9787. "Make a diary entry in the file `org-agenda-diary-file'."
  9788. (let (d1 d2 char (text "") dp1 dp2)
  9789. (if (equal (buffer-name) "*Calendar*")
  9790. (setq d1 (calendar-cursor-to-date t)
  9791. d2 (car calendar-mark-ring))
  9792. (setq dp1 (get-text-property (point-at-bol) 'day))
  9793. (unless dp1 (user-error "No date defined in current line"))
  9794. (setq d1 (calendar-gregorian-from-absolute dp1)
  9795. d2 (and (ignore-errors (mark))
  9796. (save-excursion
  9797. (goto-char (mark))
  9798. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9799. (calendar-gregorian-from-absolute dp2))))
  9800. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9801. (setq char (read-char-exclusive))
  9802. (cond
  9803. ((equal char ?d)
  9804. (setq text (read-string "Day entry: "))
  9805. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9806. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9807. ((equal char ?a)
  9808. (setq d1 (list (car d1) (nth 1 d1)
  9809. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9810. (nth 2 d1))))
  9811. (setq text (read-string "Anniversary (use %d to show years): "))
  9812. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9813. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9814. ((equal char ?b)
  9815. (setq text (read-string "Block entry: "))
  9816. (unless (and d1 d2 (not (equal d1 d2)))
  9817. (user-error "No block of days selected"))
  9818. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9819. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9820. ((equal char ?j)
  9821. (org-switch-to-buffer-other-window
  9822. (find-file-noselect org-agenda-diary-file))
  9823. (require 'org-datetree)
  9824. (org-datetree-find-date-create d1)
  9825. (org-fold-reveal t))
  9826. (t (user-error "Invalid selection character `%c'" char)))))
  9827. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9828. "Where in `org-agenda-diary-file' should new entries be added?
  9829. Valid values:
  9830. date-tree in the date tree, as first child of the date
  9831. date-tree-last in the date tree, as last child of the date
  9832. top-level as top-level entries at the end of the file."
  9833. :group 'org-agenda
  9834. :type '(choice
  9835. (const :tag "first in a date tree" date-tree)
  9836. (const :tag "last in a date tree" date-tree-last)
  9837. (const :tag "as top level at end of file" top-level)))
  9838. (defcustom org-agenda-insert-diary-extract-time nil
  9839. "Non-nil means extract any time specification from the diary entry."
  9840. :group 'org-agenda
  9841. :version "24.1"
  9842. :type 'boolean)
  9843. (defcustom org-agenda-bulk-mark-char ">"
  9844. "A single-character string to be used as the bulk mark."
  9845. :group 'org-agenda
  9846. :version "24.1"
  9847. :type 'string)
  9848. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9849. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9850. If TEXT is not empty, it will become the headline of the new entry, and
  9851. the resulting entry will not be shown. When TEXT is empty, switch to
  9852. `org-agenda-diary-file' and let the user finish the entry there."
  9853. (let ((cw (current-window-configuration)))
  9854. (org-switch-to-buffer-other-window
  9855. (find-file-noselect org-agenda-diary-file))
  9856. (widen)
  9857. (goto-char (point-min))
  9858. (cl-case type
  9859. (anniversary
  9860. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9861. (progn
  9862. (or (org-at-heading-p)
  9863. (progn
  9864. (outline-next-heading)
  9865. (insert "* Anniversaries\n\n")
  9866. (beginning-of-line -1)))))
  9867. (outline-next-heading)
  9868. (org-back-over-empty-lines)
  9869. (backward-char 1)
  9870. (insert "\n")
  9871. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9872. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9873. (day
  9874. (let ((org-prefix-has-time t)
  9875. (org-agenda-time-leading-zero t)
  9876. fmt time time2)
  9877. (when org-agenda-insert-diary-extract-time
  9878. ;; Use org-agenda-format-item to parse text for a time-range and
  9879. ;; remove it. FIXME: This is a hack, we should refactor
  9880. ;; that function to make time extraction available separately
  9881. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9882. time (get-text-property 0 'time fmt)
  9883. time2 (if (> (length time) 0)
  9884. ;; split-string removes trailing ...... if
  9885. ;; no end time given. First space
  9886. ;; separates time from date.
  9887. (concat " " (car (split-string time "\\.")))
  9888. nil)
  9889. text (get-text-property 0 'txt fmt)))
  9890. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9891. (org-agenda-insert-diary-as-top-level text)
  9892. (require 'org-datetree)
  9893. (org-datetree-find-date-create d1)
  9894. (org-agenda-insert-diary-make-new-entry text))
  9895. (org-insert-time-stamp (org-time-from-absolute
  9896. (calendar-absolute-from-gregorian d1))
  9897. nil nil nil nil time2))
  9898. (end-of-line 0))
  9899. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9900. ;; otherwise the indentation gets confused by the
  9901. ;; special meaning of 'block
  9902. (when (> (calendar-absolute-from-gregorian d1)
  9903. (calendar-absolute-from-gregorian d2))
  9904. (setq d1 (prog1 d2 (setq d2 d1))))
  9905. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9906. (org-agenda-insert-diary-as-top-level text)
  9907. (require 'org-datetree)
  9908. (org-datetree-find-date-create d1)
  9909. (org-agenda-insert-diary-make-new-entry text))
  9910. (org-insert-time-stamp (org-time-from-absolute
  9911. (calendar-absolute-from-gregorian d1)))
  9912. (insert "--")
  9913. (org-insert-time-stamp (org-time-from-absolute
  9914. (calendar-absolute-from-gregorian d2)))
  9915. (end-of-line 0)))
  9916. (if (string-match "\\S-" text)
  9917. (progn
  9918. (set-window-configuration cw)
  9919. (message "%s entry added to %s"
  9920. (capitalize (symbol-name type))
  9921. (abbreviate-file-name org-agenda-diary-file)))
  9922. (org-fold-reveal t)
  9923. (message "Please finish entry here"))))
  9924. (defun org-agenda-insert-diary-as-top-level (text)
  9925. "Make new entry as a top-level entry at the end of the file.
  9926. Add TEXT as headline, and position the cursor in the second line so that
  9927. a timestamp can be added there."
  9928. (widen)
  9929. (goto-char (point-max))
  9930. (unless (bolp) (insert "\n"))
  9931. (org-insert-heading nil t t)
  9932. (insert text)
  9933. (org-end-of-meta-data)
  9934. (unless (bolp) (insert "\n"))
  9935. (when org-adapt-indentation (indent-to-column 2)))
  9936. (defun org-agenda-insert-diary-make-new-entry (text)
  9937. "Make a new entry with TEXT as a child of the current subtree.
  9938. Position the point in the heading's first body line so that
  9939. a timestamp can be added there."
  9940. (cond
  9941. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9942. (end-of-line)
  9943. (org-insert-heading '(4) t)
  9944. (org-do-demote))
  9945. (t
  9946. (outline-next-heading)
  9947. (org-back-over-empty-lines)
  9948. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9949. (org-insert-heading nil t)
  9950. (org-do-demote)))
  9951. (let ((col (current-column)))
  9952. (insert text)
  9953. (org-end-of-meta-data)
  9954. ;; Ensure point is left on a blank line, at proper indentation.
  9955. (unless (bolp) (insert "\n"))
  9956. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9957. (when org-adapt-indentation (indent-to-column col)))
  9958. (org-fold-show-set-visibility 'lineage))
  9959. (defun org-agenda-diary-entry ()
  9960. "Make a diary entry, like the `i' command from the calendar.
  9961. All the standard commands work: block, weekly etc.
  9962. When `org-agenda-diary-file' points to a file,
  9963. `org-agenda-diary-entry-in-org-file' is called instead to create
  9964. entries in that Org file."
  9965. (interactive)
  9966. (if (not (eq org-agenda-diary-file 'diary-file))
  9967. (org-agenda-diary-entry-in-org-file)
  9968. (require 'diary-lib)
  9969. (let* ((char (read-char-exclusive
  9970. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9971. [a]nniversary [b]lock [c]yclic"))
  9972. (cmd (cdr (assoc char
  9973. '((?d . diary-insert-entry)
  9974. (?w . diary-insert-weekly-entry)
  9975. (?m . diary-insert-monthly-entry)
  9976. (?y . diary-insert-yearly-entry)
  9977. (?a . diary-insert-anniversary-entry)
  9978. (?b . diary-insert-block-entry)
  9979. (?c . diary-insert-cyclic-entry)))))
  9980. (oldf (symbol-function 'calendar-cursor-to-date))
  9981. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9982. (point (point))
  9983. (mark (or (mark t) (point))))
  9984. (unless cmd
  9985. (user-error "No command associated with <%c>" char))
  9986. (unless (and (get-text-property point 'day)
  9987. (or (not (equal ?b char))
  9988. (get-text-property mark 'day)))
  9989. (user-error "Don't know which date to use for diary entry"))
  9990. ;; We implement this by hacking the `calendar-cursor-to-date' function
  9991. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  9992. (let ((calendar-mark-ring
  9993. (list (calendar-gregorian-from-absolute
  9994. (or (get-text-property mark 'day)
  9995. (get-text-property point 'day))))))
  9996. (unwind-protect
  9997. (progn
  9998. (fset 'calendar-cursor-to-date
  9999. (lambda (&optional _error _dummy)
  10000. (calendar-gregorian-from-absolute
  10001. (get-text-property point 'day))))
  10002. (call-interactively cmd))
  10003. (fset 'calendar-cursor-to-date oldf))))))
  10004. (defun org-agenda-execute-calendar-command (cmd)
  10005. "Execute a calendar command from the agenda with date from cursor."
  10006. (org-agenda-check-type t 'agenda)
  10007. (require 'diary-lib)
  10008. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10009. (user-error "Don't know which date to use for the calendar command"))
  10010. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10011. (point (point))
  10012. (date (calendar-gregorian-from-absolute
  10013. (get-text-property point 'day))))
  10014. ;; the following 2 vars are needed in the calendar
  10015. (org-dlet
  10016. ((displayed-month (car date))
  10017. (displayed-year (nth 2 date)))
  10018. (unwind-protect
  10019. (progn
  10020. (fset 'calendar-cursor-to-date
  10021. (lambda (&optional _error _dummy)
  10022. (calendar-gregorian-from-absolute
  10023. (get-text-property point 'day))))
  10024. (call-interactively cmd))
  10025. (fset 'calendar-cursor-to-date oldf)))))
  10026. (defun org-agenda-phases-of-moon ()
  10027. "Display the phases of the moon for the 3 months around the cursor date."
  10028. (interactive)
  10029. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10030. (defun org-agenda-holidays ()
  10031. "Display the holidays for the 3 months around the cursor date."
  10032. (interactive)
  10033. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10034. (defvar calendar-longitude) ; defined in calendar.el
  10035. (defvar calendar-latitude) ; defined in calendar.el
  10036. (defvar calendar-location-name) ; defined in calendar.el
  10037. (defun org-agenda-sunrise-sunset (arg)
  10038. "Display sunrise and sunset for the cursor date.
  10039. Latitude and longitude can be specified with the variables
  10040. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10041. argument, latitude and longitude will be prompted for."
  10042. (interactive "P")
  10043. (require 'solar)
  10044. (let ((calendar-longitude (if arg nil calendar-longitude))
  10045. (calendar-latitude (if arg nil calendar-latitude))
  10046. (calendar-location-name
  10047. (if arg "the given coordinates" calendar-location-name)))
  10048. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10049. (defun org-agenda-goto-calendar ()
  10050. "Open the Emacs calendar with the date at the cursor."
  10051. (interactive)
  10052. (org-agenda-check-type t 'agenda)
  10053. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10054. (user-error "Don't know which date to open in calendar")))
  10055. (date (calendar-gregorian-from-absolute day))
  10056. (calendar-move-hook nil)
  10057. (calendar-view-holidays-initially-flag nil)
  10058. (calendar-view-diary-initially-flag nil))
  10059. (calendar)
  10060. (calendar-goto-date date)))
  10061. ;;;###autoload
  10062. (defun org-calendar-goto-agenda ()
  10063. "Compute the Org agenda for the calendar date displayed at the cursor.
  10064. This is a command that has to be installed in `calendar-mode-map'."
  10065. (interactive)
  10066. ;; Temporarily disable sticky agenda since user clearly wants to
  10067. ;; refresh view anyway.
  10068. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10069. (org-agenda-sticky nil))
  10070. (org-agenda-list nil (calendar-absolute-from-gregorian
  10071. (calendar-cursor-to-date))
  10072. nil)))
  10073. (defun org-agenda-convert-date ()
  10074. (interactive)
  10075. (org-agenda-check-type t 'agenda)
  10076. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10077. date s)
  10078. (unless day
  10079. (user-error "Don't know which date to convert"))
  10080. (setq date (calendar-gregorian-from-absolute day))
  10081. (setq s (concat
  10082. "Gregorian: " (calendar-date-string date) "\n"
  10083. "ISO: " (calendar-iso-date-string date) "\n"
  10084. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10085. "Julian: " (calendar-julian-date-string date) "\n"
  10086. "Astron. JD: " (calendar-astro-date-string date)
  10087. " (Julian date number at noon UTC)\n"
  10088. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10089. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10090. "French: " (calendar-french-date-string date) "\n"
  10091. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10092. "Mayan: " (calendar-mayan-date-string date) "\n"
  10093. "Coptic: " (calendar-coptic-date-string date) "\n"
  10094. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10095. "Persian: " (calendar-persian-date-string date) "\n"
  10096. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10097. (with-output-to-temp-buffer "*Dates*"
  10098. (princ s))
  10099. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10100. ;;; Bulk commands
  10101. (defun org-agenda-bulk-marked-p ()
  10102. "Non-nil when current entry is marked for bulk action."
  10103. (eq (get-char-property (point-at-bol) 'type)
  10104. 'org-marked-entry-overlay))
  10105. (defun org-agenda-bulk-mark (&optional arg)
  10106. "Mark entries for future bulk action.
  10107. When ARG is nil or one and region is not active then mark the
  10108. entry at point.
  10109. When ARG is nil or one and region is active then mark the entries
  10110. in the region.
  10111. When ARG is greater than one mark ARG lines."
  10112. (interactive "p")
  10113. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10114. (setq arg (count-lines (region-beginning) (region-end)))
  10115. (goto-char (region-beginning))
  10116. (deactivate-mark))
  10117. (dotimes (_ (or arg 1))
  10118. (unless (org-get-at-bol 'org-agenda-diary-link)
  10119. (let* ((m (org-get-at-bol 'org-hd-marker))
  10120. ov)
  10121. (unless (org-agenda-bulk-marked-p)
  10122. (unless m (user-error "Nothing to mark at point"))
  10123. (push m org-agenda-bulk-marked-entries)
  10124. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  10125. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10126. (org-get-todo-face "TODO")
  10127. 'evaporate)
  10128. (overlay-put ov 'type 'org-marked-entry-overlay))
  10129. (end-of-line 1)
  10130. (or (ignore-errors
  10131. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10132. (beginning-of-line 2))
  10133. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10134. (beginning-of-line 2)))))
  10135. (message "%d entries marked for bulk action"
  10136. (length org-agenda-bulk-marked-entries)))
  10137. (defun org-agenda-bulk-mark-all ()
  10138. "Mark all entries for future agenda bulk action."
  10139. (interactive)
  10140. (org-agenda-bulk-mark-regexp "."))
  10141. (defun org-agenda-bulk-mark-regexp (regexp)
  10142. "Mark entries matching REGEXP for future agenda bulk action."
  10143. (interactive "sMark entries matching regexp: ")
  10144. (let ((entries-marked 0) txt-at-point)
  10145. (save-excursion
  10146. (goto-char (point-min))
  10147. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10148. (while (and (re-search-forward regexp nil t)
  10149. (setq txt-at-point
  10150. (get-text-property (match-beginning 0) 'txt)))
  10151. (if (get-char-property (point) 'invisible)
  10152. (beginning-of-line 2)
  10153. (when (string-match-p regexp txt-at-point)
  10154. (setq entries-marked (1+ entries-marked))
  10155. (call-interactively 'org-agenda-bulk-mark)))))
  10156. (unless entries-marked
  10157. (message "No entry matching this regexp."))))
  10158. (defun org-agenda-bulk-unmark (&optional arg)
  10159. "Unmark the entry at point for future bulk action."
  10160. (interactive "P")
  10161. (if arg
  10162. (org-agenda-bulk-unmark-all)
  10163. (cond ((org-agenda-bulk-marked-p)
  10164. (org-agenda-bulk-remove-overlays
  10165. (point-at-bol) (+ 2 (point-at-bol)))
  10166. (setq org-agenda-bulk-marked-entries
  10167. (delete (org-get-at-bol 'org-hd-marker)
  10168. org-agenda-bulk-marked-entries))
  10169. (end-of-line 1)
  10170. (or (ignore-errors
  10171. (goto-char (next-single-property-change (point) 'txt)))
  10172. (beginning-of-line 2))
  10173. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10174. (beginning-of-line 2))
  10175. (message "%d entries left marked for bulk action"
  10176. (length org-agenda-bulk-marked-entries)))
  10177. (t (message "No entry to unmark here")))))
  10178. (defun org-agenda-bulk-toggle-all ()
  10179. "Toggle all marks for bulk action."
  10180. (interactive)
  10181. (save-excursion
  10182. (goto-char (point-min))
  10183. (while (ignore-errors
  10184. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10185. (org-agenda-bulk-toggle))))
  10186. (defun org-agenda-bulk-toggle ()
  10187. "Toggle the mark at point for bulk action."
  10188. (interactive)
  10189. (if (org-agenda-bulk-marked-p)
  10190. (org-agenda-bulk-unmark)
  10191. (org-agenda-bulk-mark)))
  10192. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10193. "Remove the mark overlays between BEG and END in the agenda buffer.
  10194. BEG and END default to the buffer limits.
  10195. This only removes the overlays, it does not remove the markers
  10196. from the list in `org-agenda-bulk-marked-entries'."
  10197. (interactive)
  10198. (mapc (lambda (ov)
  10199. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10200. (delete-overlay ov)))
  10201. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10202. (defun org-agenda-bulk-unmark-all ()
  10203. "Remove all marks in the agenda buffer.
  10204. This will remove the markers and the overlays."
  10205. (interactive)
  10206. (if (null org-agenda-bulk-marked-entries)
  10207. (message "No entry to unmark")
  10208. (setq org-agenda-bulk-marked-entries nil)
  10209. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10210. (defcustom org-agenda-persistent-marks nil
  10211. "Non-nil means marked items will stay marked after a bulk action.
  10212. You can toggle this interactively by typing `p' when prompted for a
  10213. bulk action."
  10214. :group 'org-agenda
  10215. :version "24.1"
  10216. :type 'boolean)
  10217. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10218. "Shall some commands act upon headlines in the active region?
  10219. When set to t, some commands will be performed in all headlines
  10220. within the active region.
  10221. When set to `start-level', some commands will be performed in all
  10222. headlines within the active region, provided that these headlines
  10223. are of the same level than the first one.
  10224. When set to a regular expression, those commands will be
  10225. performed on the matching headlines within the active region.
  10226. The list of commands is: `org-agenda-schedule',
  10227. `org-agenda-deadline', `org-agenda-date-prompt',
  10228. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10229. See `org-loop-over-headlines-in-active-region' for the equivalent
  10230. option for Org buffers."
  10231. :type '(choice (const :tag "Don't loop" nil)
  10232. (const :tag "All headlines in active region" t)
  10233. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10234. (regexp :tag "Regular expression matcher"))
  10235. :version "27.1"
  10236. :package-version '(Org . "9.4")
  10237. :group 'org-agenda)
  10238. (defun org-agenda-bulk-action (&optional arg)
  10239. "Execute an remote-editing action on all marked entries.
  10240. The prefix arg is passed through to the command if possible."
  10241. (interactive "P")
  10242. ;; When there is no mark, act on the agenda entry at point.
  10243. (if (not org-agenda-bulk-marked-entries)
  10244. (save-excursion (org-agenda-bulk-mark)))
  10245. (dolist (m org-agenda-bulk-marked-entries)
  10246. (unless (and (markerp m)
  10247. (marker-buffer m)
  10248. (buffer-live-p (marker-buffer m))
  10249. (marker-position m))
  10250. (user-error "Marker %s for bulk command is invalid" m)))
  10251. ;; Prompt for the bulk command.
  10252. (org-unlogged-message
  10253. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10254. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10255. "[S]catter [f]unction "
  10256. (and org-agenda-bulk-custom-functions
  10257. (format " Custom: [%s]"
  10258. (mapconcat (lambda (f) (char-to-string (car f)))
  10259. org-agenda-bulk-custom-functions
  10260. "")))))
  10261. (catch 'exit
  10262. (let* ((org-log-refile (if org-log-refile 'time nil))
  10263. (entries (reverse org-agenda-bulk-marked-entries))
  10264. (org-overriding-default-time
  10265. (and (get-text-property (point) 'org-agenda-date-header)
  10266. (org-get-cursor-date)))
  10267. redo-at-end
  10268. cmd)
  10269. (pcase (read-char-exclusive)
  10270. (?p
  10271. (let ((org-agenda-persistent-marks
  10272. (not org-agenda-persistent-marks)))
  10273. (org-agenda-bulk-action)
  10274. (throw 'exit nil)))
  10275. (?$
  10276. (setq cmd #'org-agenda-archive))
  10277. (?A
  10278. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10279. ((or ?r ?w)
  10280. (let ((refile-location
  10281. (org-refile-get-location
  10282. "Refile to"
  10283. (marker-buffer (car entries))
  10284. org-refile-allow-creating-parent-nodes)))
  10285. (when (nth 3 refile-location)
  10286. (setcar (nthcdr 3 refile-location)
  10287. (move-marker
  10288. (make-marker)
  10289. (nth 3 refile-location)
  10290. (or (get-file-buffer (nth 1 refile-location))
  10291. (find-buffer-visiting (nth 1 refile-location))
  10292. (error "This should not happen")))))
  10293. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10294. (setq redo-at-end t)))
  10295. (?t
  10296. (let ((state (completing-read
  10297. "Todo state: "
  10298. (with-current-buffer (marker-buffer (car entries))
  10299. (mapcar #'list org-todo-keywords-1)))))
  10300. (setq cmd (lambda ()
  10301. (let ((org-inhibit-blocking t)
  10302. (org-inhibit-logging 'note))
  10303. (org-agenda-todo state))))))
  10304. ((and (or ?- ?+) action)
  10305. (let ((tag (completing-read
  10306. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10307. (with-current-buffer (marker-buffer (car entries))
  10308. (delq nil
  10309. (mapcar (lambda (x) (and (stringp (car x)) x))
  10310. org-current-tag-alist))))))
  10311. (setq cmd
  10312. (lambda ()
  10313. (org-agenda-set-tags tag
  10314. (if (eq action ?+) 'on 'off))))))
  10315. ((and (or ?s ?d) c)
  10316. (let* ((schedule? (eq c ?s))
  10317. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10318. (time
  10319. (and (not arg)
  10320. (let ((new (org-read-date
  10321. nil nil nil prompt org-overriding-default-time)))
  10322. ;; A "double plus" answer applies to every
  10323. ;; scheduled time. Do not turn it into
  10324. ;; a fixed date yet.
  10325. (if (string-match-p "\\`[ \t]*\\+\\+"
  10326. org-read-date-final-answer)
  10327. org-read-date-final-answer
  10328. new)))))
  10329. ;; Make sure to not prompt for a note when bulk
  10330. ;; rescheduling/resetting deadline as Org cannot cope with
  10331. ;; simultaneous notes. Besides, it could be annoying
  10332. ;; depending on the number of marked items.
  10333. (setq cmd
  10334. (if schedule?
  10335. (lambda ()
  10336. (let ((org-log-reschedule
  10337. (and org-log-reschedule 'time)))
  10338. (org-agenda-schedule arg time)))
  10339. (lambda ()
  10340. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10341. (org-agenda-deadline arg time)))))))
  10342. (?S
  10343. (unless (org-agenda-check-type nil 'agenda 'todo)
  10344. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10345. (let ((days (read-number
  10346. (format "Scatter tasks across how many %sdays: "
  10347. (if arg "week" ""))
  10348. 7)))
  10349. (setq cmd
  10350. (lambda ()
  10351. (let ((distance (1+ (random days))))
  10352. (when arg
  10353. (let ((dist distance)
  10354. (day-of-week
  10355. (calendar-day-of-week
  10356. (calendar-gregorian-from-absolute (org-today)))))
  10357. (dotimes (_ (1+ dist))
  10358. (while (member day-of-week org-agenda-weekend-days)
  10359. (cl-incf distance)
  10360. (cl-incf day-of-week)
  10361. (when (= day-of-week 7)
  10362. (setq day-of-week 0)))
  10363. (cl-incf day-of-week)
  10364. (when (= day-of-week 7)
  10365. (setq day-of-week 0)))))
  10366. ;; Silently fail when try to replan a sexp entry.
  10367. (ignore-errors
  10368. (let* ((date (calendar-gregorian-from-absolute
  10369. (+ (org-today) distance)))
  10370. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  10371. (nth 2 date))))
  10372. (org-agenda-schedule nil time))))))))
  10373. (?f
  10374. (setq cmd
  10375. (intern
  10376. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10377. (action
  10378. (setq cmd
  10379. (pcase (assoc action org-agenda-bulk-custom-functions)
  10380. (`(,_ ,fn)
  10381. fn)
  10382. (`(,_ ,fn ,arg-fn)
  10383. (apply #'apply-partially fn (funcall arg-fn)))
  10384. (_
  10385. (user-error "Invalid bulk action: %c" action))))
  10386. (setq redo-at-end t)))
  10387. ;; Sort the markers, to make sure that parents are handled
  10388. ;; before children.
  10389. (setq entries (sort entries
  10390. (lambda (a b)
  10391. (cond
  10392. ((eq (marker-buffer a) (marker-buffer b))
  10393. (< (marker-position a) (marker-position b)))
  10394. (t
  10395. (string< (buffer-name (marker-buffer a))
  10396. (buffer-name (marker-buffer b))))))))
  10397. ;; Now loop over all markers and apply CMD.
  10398. (let ((processed 0)
  10399. (skipped 0))
  10400. (dolist (e entries)
  10401. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10402. (if (not pos)
  10403. (progn (message "Skipping removed entry at %s" e)
  10404. (cl-incf skipped))
  10405. (goto-char pos)
  10406. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10407. ;; `post-command-hook' is not run yet. We make sure any
  10408. ;; pending log note is processed.
  10409. (when org-log-setup (org-add-log-note))
  10410. (cl-incf processed))))
  10411. (when redo-at-end (org-agenda-redo))
  10412. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10413. (message "Acted on %d entries%s%s"
  10414. processed
  10415. (if (= skipped 0)
  10416. ""
  10417. (format ", skipped %d (disappeared before their turn)"
  10418. skipped))
  10419. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10420. (defun org-agenda-capture (&optional with-time)
  10421. "Call `org-capture' with the date at point.
  10422. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10423. current HH:MM time."
  10424. (interactive "P")
  10425. (if (not (eq major-mode 'org-agenda-mode))
  10426. (user-error "You cannot do this outside of agenda buffers")
  10427. (let ((org-overriding-default-time
  10428. (org-get-cursor-date (equal with-time 1))))
  10429. (call-interactively 'org-capture))))
  10430. ;;; Dragging agenda lines forward/backward
  10431. (defun org-agenda-reapply-filters ()
  10432. "Re-apply all agenda filters."
  10433. (mapcar
  10434. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10435. `((,org-agenda-tag-filter tag)
  10436. (,org-agenda-category-filter category)
  10437. (,org-agenda-regexp-filter regexp)
  10438. (,org-agenda-effort-filter effort)
  10439. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10440. (,(get 'org-agenda-category-filter :preset-filter) category)
  10441. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10442. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10443. (defun org-agenda-drag-line-forward (arg &optional backward)
  10444. "Drag an agenda line forward by ARG lines.
  10445. When the optional argument `backward' is non-nil, move backward."
  10446. (interactive "p")
  10447. (let ((inhibit-read-only t) lst line)
  10448. (if (or (not (get-text-property (point) 'txt))
  10449. (save-excursion
  10450. (dotimes (_ arg)
  10451. (move-beginning-of-line (if backward 0 2))
  10452. (push (not (get-text-property (point) 'txt)) lst))
  10453. (delq nil lst)))
  10454. (message "Cannot move line forward")
  10455. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10456. (move-beginning-of-line 1)
  10457. (setq line (buffer-substring (point) end))
  10458. (delete-region (point) end)
  10459. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10460. (insert line)
  10461. (org-agenda-reapply-filters)
  10462. (org-agenda-mark-clocking-task)
  10463. (move-beginning-of-line 0)))))
  10464. (defun org-agenda-drag-line-backward (arg)
  10465. "Drag an agenda line backward by ARG lines."
  10466. (interactive "p")
  10467. (org-agenda-drag-line-forward arg t))
  10468. ;;; Flagging notes
  10469. (defun org-agenda-show-the-flagging-note ()
  10470. "Display the flagging note in the other window.
  10471. When called a second time in direct sequence, offer to remove the FLAGGING
  10472. tag and (if present) the flagging note."
  10473. (interactive)
  10474. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10475. (win (selected-window))
  10476. note) ;; heading newhead
  10477. (unless hdmarker
  10478. (user-error "No linked entry at point"))
  10479. (if (and (eq this-command last-command)
  10480. (y-or-n-p "Unflag and remove any flagging note? "))
  10481. (progn
  10482. (org-agenda-remove-flag hdmarker)
  10483. (let ((win (get-buffer-window "*Flagging Note*")))
  10484. (and win (delete-window win)))
  10485. (message "Entry unflagged"))
  10486. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10487. (unless note
  10488. (user-error "No flagging note"))
  10489. (org-kill-new note)
  10490. (org-switch-to-buffer-other-window "*Flagging Note*")
  10491. (erase-buffer)
  10492. (insert note)
  10493. (goto-char (point-min))
  10494. (while (re-search-forward "\\\\n" nil t)
  10495. (replace-match "\n" t t))
  10496. (goto-char (point-min))
  10497. (select-window win)
  10498. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10499. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10500. tag and note")))))
  10501. (defun org-agenda-remove-flag (marker)
  10502. "Remove the FLAGGED tag and any flagging note in the entry."
  10503. (let ((newhead
  10504. (org-with-point-at marker
  10505. (org-toggle-tag "FLAGGED" 'off)
  10506. (org-entry-delete nil "THEFLAGGINGNOTE")
  10507. (org-get-heading))))
  10508. (org-agenda-change-all-lines newhead marker)
  10509. (message "Entry unflagged")))
  10510. (defun org-agenda-get-any-marker (&optional pos)
  10511. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  10512. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  10513. ;;; Appointment reminders
  10514. (defvar appt-time-msg-list) ; defined in appt.el
  10515. ;;;###autoload
  10516. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10517. "Activate appointments found in `org-agenda-files'.
  10518. With a `\\[universal-argument]' prefix, refresh the list of \
  10519. appointments.
  10520. If FILTER is t, interactively prompt the user for a regular
  10521. expression, and filter out entries that don't match it.
  10522. If FILTER is a string, use this string as a regular expression
  10523. for filtering entries out.
  10524. If FILTER is a function, filter out entries against which
  10525. calling the function returns nil. This function takes one
  10526. argument: an entry from `org-agenda-get-day-entries'.
  10527. FILTER can also be an alist with the car of each cell being
  10528. either `headline' or `category'. For example:
  10529. \\='((headline \"IMPORTANT\")
  10530. (category \"Work\"))
  10531. will only add headlines containing IMPORTANT or headlines
  10532. belonging to the \"Work\" category.
  10533. ARGS are symbols indicating what kind of entries to consider.
  10534. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10535. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10536. and :timestamp entries. See the docstring of `org-diary' for
  10537. details and examples.
  10538. If an entry has a APPT_WARNTIME property, its value will be used
  10539. to override `appt-message-warning-time'."
  10540. (interactive "P")
  10541. (when refresh (setq appt-time-msg-list nil))
  10542. (when (eq filter t)
  10543. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10544. (let* ((cnt 0) ; count added events
  10545. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10546. (org-agenda-new-buffers nil)
  10547. (org-deadline-warning-days 0)
  10548. ;; Do not use `org-today' here because appt only takes
  10549. ;; time and without date as argument, so it may pass wrong
  10550. ;; information otherwise
  10551. (today (org-date-to-gregorian
  10552. (time-to-days nil)))
  10553. (org-agenda-restrict nil)
  10554. (files (org-agenda-files 'unrestricted)) entries file
  10555. (org-agenda-buffer nil))
  10556. ;; Get all entries which may contain an appt
  10557. (org-agenda-prepare-buffers files)
  10558. (while (setq file (pop files))
  10559. (setq entries
  10560. (delq nil
  10561. (append entries
  10562. (apply #'org-agenda-get-day-entries
  10563. file today scope)))))
  10564. ;; Map through entries and find if we should filter them out
  10565. (mapc
  10566. (lambda (x)
  10567. (let* ((evt (org-trim
  10568. (replace-regexp-in-string
  10569. org-link-bracket-re "\\2"
  10570. (or (get-text-property 1 'txt x) ""))))
  10571. (cat (get-text-property (1- (length x)) 'org-category x))
  10572. (tod (get-text-property 1 'time-of-day x))
  10573. (ok (or (null filter)
  10574. (and (stringp filter) (string-match filter evt))
  10575. (and (functionp filter) (funcall filter x))
  10576. (and (listp filter)
  10577. (let ((cat-filter (cadr (assq 'category filter)))
  10578. (evt-filter (cadr (assq 'headline filter))))
  10579. (or (and (stringp cat-filter)
  10580. (string-match cat-filter cat))
  10581. (and (stringp evt-filter)
  10582. (string-match evt-filter evt)))))))
  10583. (wrn (get-text-property 1 'warntime x)))
  10584. ;; FIXME: Shall we remove text-properties for the appt text?
  10585. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10586. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10587. (setq tod (concat "00" (number-to-string tod)))
  10588. (setq tod (when (string-match
  10589. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10590. (concat (match-string 1 tod) ":"
  10591. (match-string 2 tod))))
  10592. (when (appt-add tod evt wrn)
  10593. (setq cnt (1+ cnt))))))
  10594. entries)
  10595. (org-release-buffers org-agenda-new-buffers)
  10596. (if (eq cnt 0)
  10597. (message "No event to add")
  10598. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10599. (defun org-agenda-today-p (date)
  10600. "Non-nil when DATE means today.
  10601. DATE is either a list of the form (month day year) or a number of
  10602. days as returned by `calendar-absolute-from-gregorian' or
  10603. `org-today'. This function considers `org-extend-today-until'
  10604. when defining today."
  10605. (eq (org-today)
  10606. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10607. (defun org-agenda-todo-yesterday (&optional arg)
  10608. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10609. (interactive "P")
  10610. (let* ((org-use-effective-time t)
  10611. (hour (nth 2 (decode-time (org-current-time))))
  10612. (org-extend-today-until (1+ hour)))
  10613. (org-agenda-todo arg)))
  10614. (defun org-agenda-ctrl-c-ctrl-c ()
  10615. "Set tags in agenda buffer."
  10616. (interactive)
  10617. (org-agenda-set-tags))
  10618. (provide 'org-agenda)
  10619. ;;; org-agenda.el ends here