org-agenda.el 422 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907
  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. ;; Homepage: https://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'cl-lib)
  42. (require 'ol)
  43. (require 'org)
  44. (require 'org-macs)
  45. (require 'org-refile)
  46. (declare-function diary-add-to-list "diary-lib"
  47. (date string specifier &optional marker globcolor literal))
  48. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  49. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  50. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  51. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  52. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  54. (declare-function calendar-french-date-string "cal-french" (&optional date))
  55. (declare-function calendar-goto-date "cal-move" (date))
  56. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  57. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  58. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  59. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  60. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  61. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  62. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  63. (declare-function calendar-check-holidays "holidays" (date))
  64. (declare-function org-columns-remove-overlays "org-colview" ())
  65. (declare-function org-datetree-find-date-create "org-datetree"
  66. (date &optional keep-restriction))
  67. (declare-function org-columns-quit "org-colview" ())
  68. (declare-function diary-date-display-form "diary-lib" (&optional type))
  69. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  70. (declare-function org-habit-insert-consistency-graphs
  71. "org-habit" (&optional line))
  72. (declare-function org-is-habit-p "org-habit" (&optional pom))
  73. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  74. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  79. (declare-function org-element-type "org-element" (&optional element))
  80. (defvar calendar-mode-map)
  81. (defvar org-clock-current-task)
  82. (defvar org-current-tag-alist)
  83. (defvar org-mobile-force-id-on-agenda-items)
  84. (defvar org-habit-show-habits)
  85. (defvar org-habit-show-habits-only-for-today)
  86. (defvar org-habit-show-all-today)
  87. (defvar org-habit-scheduled-past-days)
  88. ;; Defined somewhere in this file, but used before definition.
  89. (defvar org-agenda-buffer-name "*Org Agenda*")
  90. (defvar org-agenda-title-append nil)
  91. (defvar org-agenda-overriding-header)
  92. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  93. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  94. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  95. (defvar org-agenda-undo-list nil
  96. "List of undoable operations in the agenda since last refresh.")
  97. (defvar org-agenda-pending-undo-list nil
  98. "In a series of undo commands, this is the list of remaining undo items.")
  99. (defcustom org-agenda-confirm-kill 1
  100. "When set, remote killing from the agenda buffer needs confirmation.
  101. When t, a confirmation is always needed. When a number N, confirmation is
  102. only needed when the text to be killed contains more than N non-white lines."
  103. :group 'org-agenda
  104. :type '(choice
  105. (const :tag "Never" nil)
  106. (const :tag "Always" t)
  107. (integer :tag "When more than N lines")))
  108. (defcustom org-agenda-compact-blocks nil
  109. "Non-nil means make the block agenda more compact.
  110. This is done globally by leaving out lines like the agenda span
  111. name and week number or the separator lines."
  112. :group 'org-agenda
  113. :type 'boolean)
  114. (defcustom org-agenda-block-separator ?=
  115. "The separator between blocks in the agenda.
  116. If this is a string, it will be used as the separator, with a newline added.
  117. If it is a character, it will be repeated to fill the window width.
  118. If nil the separator is disabled. In `org-agenda-custom-commands' this
  119. addresses the separator between the current and the previous block."
  120. :group 'org-agenda
  121. :type '(choice
  122. (const :tag "Disabled" nil)
  123. (character)
  124. (string)))
  125. (defgroup org-agenda-export nil
  126. "Options concerning exporting agenda views in Org mode."
  127. :tag "Org Agenda Export"
  128. :group 'org-agenda)
  129. (defcustom org-agenda-with-colors t
  130. "Non-nil means use colors in agenda views."
  131. :group 'org-agenda-export
  132. :type 'boolean)
  133. (defcustom org-agenda-exporter-settings nil
  134. ;; FIXME: Do we really want to evaluate those settings and thus force
  135. ;; the user to use `quote' all the time?
  136. "Alist of variable/value pairs that should be active during agenda export.
  137. This is a good place to set options for ps-print and for htmlize.
  138. Note that the way this is implemented, the values will be evaluated
  139. before assigned to the variables. So make sure to quote values you do
  140. *not* want evaluated, for example
  141. (setq org-agenda-exporter-settings
  142. \\='((ps-print-color-p \\='black-white)))"
  143. :group 'org-agenda-export
  144. :type '(repeat
  145. (list
  146. (variable)
  147. (sexp :tag "Value"))))
  148. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  149. "Hook run in a temporary buffer before writing the agenda to an export file.
  150. A useful function for this hook is `org-agenda-add-entry-text'."
  151. :group 'org-agenda-export
  152. :type 'hook
  153. :options '(org-agenda-add-entry-text))
  154. (defcustom org-agenda-add-entry-text-maxlines 0
  155. "Maximum number of entry text lines to be added to agenda.
  156. This is only relevant when `org-agenda-add-entry-text' is part of
  157. `org-agenda-before-write-hook', which is the default.
  158. When this is 0, nothing will happen. When it is greater than 0, it
  159. specifies the maximum number of lines that will be added for each entry
  160. that is listed in the agenda view.
  161. Note that this variable is not used during display, only when exporting
  162. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  163. and `org-agenda-entry-text-maxlines'."
  164. :group 'org-agenda
  165. :type 'integer)
  166. (defcustom org-agenda-add-entry-text-descriptive-links t
  167. "Non-nil means export org-links as descriptive links in agenda added text.
  168. This variable applies to the text added to the agenda when
  169. `org-agenda-add-entry-text-maxlines' is larger than 0.
  170. When this variable is nil, the URL will (also) be shown."
  171. :group 'org-agenda
  172. :type 'boolean)
  173. (defcustom org-agenda-export-html-style nil
  174. "The style specification for exported HTML Agenda files.
  175. If this variable contains a string, it will replace the default <style>
  176. section as produced by `htmlize'.
  177. Since there are different ways of setting style information, this variable
  178. needs to contain the full HTML structure to provide a style, including the
  179. surrounding HTML tags. The style specifications should include definitions
  180. the fonts used by the agenda, here is an example:
  181. <style type=\"text/css\">
  182. p { font-weight: normal; color: gray; }
  183. .org-agenda-structure {
  184. font-size: 110%;
  185. color: #003399;
  186. font-weight: 600;
  187. }
  188. .org-todo {
  189. color: #cc6666;
  190. font-weight: bold;
  191. }
  192. .org-agenda-done {
  193. color: #339933;
  194. }
  195. .org-done {
  196. color: #339933;
  197. }
  198. .title { text-align: center; }
  199. .todo, .deadline { color: red; }
  200. .done { color: green; }
  201. </style>
  202. or, if you want to keep the style in a file,
  203. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  204. As the value of this option simply gets inserted into the HTML <head> header,
  205. you can \"misuse\" it to also add other text to the header."
  206. :group 'org-agenda-export
  207. :group 'org-export-html
  208. :type '(choice
  209. (const nil)
  210. (string)))
  211. (defcustom org-agenda-persistent-filter nil
  212. "When set, keep filters from one agenda view to the next."
  213. :group 'org-agenda
  214. :type 'boolean)
  215. (defgroup org-agenda-custom-commands nil
  216. "Options concerning agenda views in Org mode."
  217. :tag "Org Agenda Custom Commands"
  218. :group 'org-agenda)
  219. (defconst org-sorting-choice
  220. '(choice
  221. (const time-up) (const time-down)
  222. (const timestamp-up) (const timestamp-down)
  223. (const scheduled-up) (const scheduled-down)
  224. (const deadline-up) (const deadline-down)
  225. (const ts-up) (const ts-down)
  226. (const tsia-up) (const tsia-down)
  227. (const category-keep) (const category-up) (const category-down)
  228. (const tag-down) (const tag-up)
  229. (const priority-up) (const priority-down)
  230. (const todo-state-up) (const todo-state-down)
  231. (const effort-up) (const effort-down)
  232. (const habit-up) (const habit-down)
  233. (const alpha-up) (const alpha-down)
  234. (const user-defined-up) (const user-defined-down))
  235. "Sorting choices.")
  236. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  237. ;; the new variable `org-agenda-tag-filter-preset'.
  238. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  239. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  240. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  241. "List of types searched for when creating the daily/weekly agenda.
  242. This variable is a list of symbols that controls the types of
  243. items that appear in the daily/weekly agenda. Allowed symbols in this
  244. list are
  245. :timestamp List items containing a date stamp or date range matching
  246. the selected date. This includes sexp entries in angular
  247. brackets.
  248. :sexp List entries resulting from plain diary-like sexps.
  249. :deadline List deadline due on that date. When the date is today,
  250. also list any deadlines past due, or due within
  251. `org-deadline-warning-days'.
  252. :deadline* Same as above, but only include the deadline if it has an
  253. hour specification as [h]h:mm.
  254. :scheduled List all items which are scheduled for the given date.
  255. The diary for *today* also contains items which were
  256. scheduled earlier and are not yet marked DONE.
  257. :scheduled* Same as above, but only include the scheduled item if it
  258. has an hour specification as [h]h:mm.
  259. By default, all four non-starred types are turned on.
  260. When :scheduled* or :deadline* are included, :schedule or :deadline
  261. will be ignored.
  262. Never set this variable globally using `setq', because then it
  263. will apply to all future agenda commands. Instead, bind it with
  264. `let' to scope it dynamically into the agenda-constructing
  265. command. A good way to set it is through options in
  266. `org-agenda-custom-commands'. For a more flexible (though
  267. somewhat less efficient) way of determining what is included in
  268. the daily/weekly agenda, see `org-agenda-skip-function'.")
  269. (defconst org-agenda-custom-commands-local-options
  270. `(repeat :tag "Local settings for this command. Remember to quote values"
  271. (choice :tag "Setting"
  272. (list :tag "Heading for this block"
  273. (const org-agenda-overriding-header)
  274. (string :tag "Headline"))
  275. (list :tag "Files to be searched"
  276. (const org-agenda-files)
  277. (list
  278. (const :format "" quote)
  279. (repeat (file))))
  280. (list :tag "Sorting strategy"
  281. (const org-agenda-sorting-strategy)
  282. (list
  283. (const :format "" quote)
  284. (repeat
  285. ,org-sorting-choice)))
  286. (list :tag "Prefix format"
  287. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  288. (string))
  289. (list :tag "Number of days in agenda"
  290. (const org-agenda-span)
  291. (list
  292. (const :format "" quote)
  293. (choice (const :tag "Day" day)
  294. (const :tag "Week" week)
  295. (const :tag "Fortnight" fortnight)
  296. (const :tag "Month" month)
  297. (const :tag "Year" year)
  298. (integer :tag "Custom"))))
  299. (list :tag "Fixed starting date"
  300. (const org-agenda-start-day)
  301. (string :value "2007-11-01"))
  302. (list :tag "Start on day of week"
  303. (const org-agenda-start-on-weekday)
  304. (choice :value 1
  305. (const :tag "Today" nil)
  306. (integer :tag "Weekday No.")))
  307. (list :tag "Include data from diary"
  308. (const org-agenda-include-diary)
  309. (boolean))
  310. (list :tag "Deadline Warning days"
  311. (const org-deadline-warning-days)
  312. (integer :value 1))
  313. (list :tag "Category filter preset"
  314. (const org-agenda-category-filter-preset)
  315. (list
  316. (const :format "" quote)
  317. (repeat
  318. (string :tag "+category or -category"))))
  319. (list :tag "Tags filter preset"
  320. (const org-agenda-tag-filter-preset)
  321. (list
  322. (const :format "" quote)
  323. (repeat
  324. (string :tag "+tag or -tag"))))
  325. (list :tag "Effort filter preset"
  326. (const org-agenda-effort-filter-preset)
  327. (list
  328. (const :format "" quote)
  329. (repeat
  330. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  331. (list :tag "Regexp filter preset"
  332. (const org-agenda-regexp-filter-preset)
  333. (list
  334. (const :format "" quote)
  335. (repeat
  336. (string :tag "+regexp or -regexp"))))
  337. (list :tag "Set daily/weekly entry types"
  338. (const org-agenda-entry-types)
  339. (list
  340. (const :format "" quote)
  341. (set :greedy t :value ,org-agenda-entry-types
  342. (const :deadline)
  343. (const :scheduled)
  344. (const :deadline*)
  345. (const :scheduled*)
  346. (const :timestamp)
  347. (const :sexp))))
  348. (list :tag "Columns format"
  349. (const org-overriding-columns-format)
  350. (string :tag "Format"))
  351. (list :tag "Standard skipping condition"
  352. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  353. (const org-agenda-skip-function)
  354. (list
  355. (const :format "" quote)
  356. (list
  357. (choice
  358. :tag "Skipping range"
  359. (const :tag "Skip entry" org-agenda-skip-entry-if)
  360. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  361. (repeat :inline t :tag "Conditions for skipping"
  362. (choice
  363. :tag "Condition type"
  364. (list :tag "Regexp matches" :inline t
  365. (const :format "" regexp)
  366. (regexp))
  367. (list :tag "Regexp does not match" :inline t
  368. (const :format "" notregexp)
  369. (regexp))
  370. (list :tag "TODO state is" :inline t
  371. (const todo)
  372. (choice
  373. (const :tag "Any not-done state" todo)
  374. (const :tag "Any done state" done)
  375. (const :tag "Any state" any)
  376. (list :tag "Keyword list"
  377. (const :format "" quote)
  378. (repeat (string :tag "Keyword")))))
  379. (list :tag "TODO state is not" :inline t
  380. (const nottodo)
  381. (choice
  382. (const :tag "Any not-done state" todo)
  383. (const :tag "Any done state" done)
  384. (const :tag "Any state" any)
  385. (list :tag "Keyword list"
  386. (const :format "" quote)
  387. (repeat (string :tag "Keyword")))))
  388. (const :tag "scheduled" scheduled)
  389. (const :tag "not scheduled" notscheduled)
  390. (const :tag "deadline" deadline)
  391. (const :tag "no deadline" notdeadline)
  392. (const :tag "timestamp" timestamp)
  393. (const :tag "no timestamp" nottimestamp))))))
  394. (list :tag "Non-standard skipping condition"
  395. :value (org-agenda-skip-function)
  396. (const org-agenda-skip-function)
  397. (sexp :tag "Function or form (quoted!)"))
  398. (list :tag "Any variable"
  399. (variable :tag "Variable")
  400. (sexp :tag "Value (sexp)"))))
  401. "Selection of examples for agenda command settings.
  402. This will be spliced into the custom type of
  403. `org-agenda-custom-commands'.")
  404. (defcustom org-agenda-custom-commands
  405. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  406. "Custom commands for the agenda.
  407. \\<org-mode-map>
  408. These commands will be offered on the splash screen displayed by the
  409. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  410. (key desc type match settings files)
  411. key The key (one or more characters as a string) to be associated
  412. with the command.
  413. desc A description of the command, when omitted or nil, a default
  414. description is built using MATCH.
  415. type The command type, any of the following symbols:
  416. agenda The daily/weekly agenda.
  417. todo Entries with a specific TODO keyword, in all agenda files.
  418. search Entries containing search words entry or headline.
  419. tags Tags/Property/TODO match in all agenda files.
  420. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  421. todo-tree Sparse tree of specific TODO keyword in *current* file.
  422. tags-tree Sparse tree with all tags matches in *current* file.
  423. occur-tree Occur sparse tree for *current* file.
  424. ... A user-defined function.
  425. match What to search for:
  426. - a single keyword for TODO keyword searches
  427. - a tags/property/todo match expression for searches
  428. - a word search expression for text searches.
  429. - a regular expression for occur searches
  430. For all other commands, this should be the empty string.
  431. settings A list of option settings, similar to that in a let form, so like
  432. this: ((opt1 val1) (opt2 val2) ...). The values will be
  433. evaluated at the moment of execution, so quote them when needed.
  434. files A list of files to write the produced agenda buffer to with
  435. the command `org-store-agenda-views'.
  436. If a file name ends in \".html\", an HTML version of the buffer
  437. is written out. If it ends in \".ps\", a postscript version is
  438. produced. Otherwise, only the plain text is written to the file.
  439. You can also define a set of commands, to create a composite agenda buffer.
  440. In this case, an entry looks like this:
  441. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  442. where
  443. desc A description string to be displayed in the dispatcher menu.
  444. cmd An agenda command, similar to the above. However, tree commands
  445. are not allowed, but instead you can get agenda and global todo list.
  446. So valid commands for a set are:
  447. (agenda \"\" settings)
  448. (alltodo \"\" settings)
  449. (stuck \"\" settings)
  450. (todo \"match\" settings files)
  451. (search \"match\" settings files)
  452. (tags \"match\" settings files)
  453. (tags-todo \"match\" settings files)
  454. Each command can carry a list of options, and another set of options can be
  455. given for the whole set of commands. Individual command options take
  456. precedence over the general options.
  457. When using several characters as key to a command, the first characters
  458. are prefix commands. For the dispatcher to display useful information, you
  459. should provide a description for the prefix, like
  460. (setq org-agenda-custom-commands
  461. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  462. (\"hl\" tags \"+HOME+Lisa\")
  463. (\"hp\" tags \"+HOME+Peter\")
  464. (\"hk\" tags \"+HOME+Kim\")))"
  465. :group 'org-agenda-custom-commands
  466. :type `(repeat
  467. (choice :value ("x" "Describe command here" tags "" nil)
  468. (list :tag "Single command"
  469. (string :tag "Access Key(s) ")
  470. (option (string :tag "Description"))
  471. (choice
  472. (const :tag "Agenda" agenda)
  473. (const :tag "TODO list" alltodo)
  474. (const :tag "Search words" search)
  475. (const :tag "Stuck projects" stuck)
  476. (const :tag "Tags/Property match (all agenda files)" tags)
  477. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  478. (const :tag "TODO keyword search (all agenda files)" todo)
  479. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  480. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  481. (const :tag "Occur tree (current buffer)" occur-tree)
  482. (sexp :tag "Other, user-defined function"))
  483. (string :tag "Match (only for some commands)")
  484. ,org-agenda-custom-commands-local-options
  485. (option (repeat :tag "Export" (file :tag "Export to"))))
  486. (list :tag "Command series, all agenda files"
  487. (string :tag "Access Key(s)")
  488. (string :tag "Description ")
  489. (repeat :tag "Component"
  490. (choice
  491. (list :tag "Agenda"
  492. (const :format "" agenda)
  493. (const :tag "" :format "" "")
  494. ,org-agenda-custom-commands-local-options)
  495. (list :tag "TODO list (all keywords)"
  496. (const :format "" alltodo)
  497. (const :tag "" :format "" "")
  498. ,org-agenda-custom-commands-local-options)
  499. (list :tag "Search words"
  500. (const :format "" search)
  501. (string :tag "Match")
  502. ,org-agenda-custom-commands-local-options)
  503. (list :tag "Stuck projects"
  504. (const :format "" stuck)
  505. (const :tag "" :format "" "")
  506. ,org-agenda-custom-commands-local-options)
  507. (list :tag "Tags/Property match (all agenda files)"
  508. (const :format "" tags)
  509. (string :tag "Match")
  510. ,org-agenda-custom-commands-local-options)
  511. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  512. (const :format "" tags-todo)
  513. (string :tag "Match")
  514. ,org-agenda-custom-commands-local-options)
  515. (list :tag "TODO keyword search"
  516. (const :format "" todo)
  517. (string :tag "Match")
  518. ,org-agenda-custom-commands-local-options)
  519. (list :tag "Other, user-defined function"
  520. (symbol :tag "function")
  521. (string :tag "Match")
  522. ,org-agenda-custom-commands-local-options)))
  523. (repeat :tag "Settings for entire command set"
  524. (list (variable :tag "Any variable")
  525. (sexp :tag "Value")))
  526. (option (repeat :tag "Export" (file :tag "Export to"))))
  527. (cons :tag "Prefix key documentation"
  528. (string :tag "Access Key(s)")
  529. (string :tag "Description ")))))
  530. (defcustom org-agenda-query-register ?o
  531. "The register holding the current query string.
  532. The purpose of this is that if you construct a query string interactively,
  533. you can then use it to define a custom command."
  534. :group 'org-agenda-custom-commands
  535. :type 'character)
  536. (defcustom org-stuck-projects
  537. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  538. "How to identify stuck projects.
  539. This is a list of four items:
  540. 1. A tags/todo/property matcher string that is used to identify a project.
  541. See the manual for a description of tag and property searches.
  542. The entire tree below a headline matched by this is considered one project.
  543. 2. A list of TODO keywords identifying non-stuck projects.
  544. If the project subtree contains any headline with one of these todo
  545. keywords, the project is considered to be not stuck. If you specify
  546. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  547. 3. A list of tags identifying non-stuck projects.
  548. If the project subtree contains any headline with one of these tags,
  549. the project is considered to be not stuck. If you specify \"*\" as
  550. a tag, any tag will mark the project unstuck. Note that this is about
  551. the explicit presence of a tag somewhere in the subtree, inherited
  552. tags do not count here. If inherited tags make a project not stuck,
  553. use \"-TAG\" in the tags part of the matcher under (1.) above.
  554. 4. An arbitrary regular expression matching non-stuck projects.
  555. If the project turns out to be not stuck, search continues also in the
  556. subtree to see if any of the subtasks have project status.
  557. See also the variable `org-tags-match-list-sublevels' which applies
  558. to projects matched by this search as well.
  559. After defining this variable, you may use `org-agenda-list-stuck-projects'
  560. \(bound to `\\[org-agenda] #') to produce the list."
  561. :group 'org-agenda-custom-commands
  562. :type '(list
  563. (string :tag "Tags/TODO match to identify a project")
  564. (repeat :tag "Projects are *not* stuck if they have an entry with \
  565. TODO keyword any of" (string))
  566. (repeat :tag "Projects are *not* stuck if they have an entry with \
  567. TAG being any of" (string))
  568. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  569. the subtree")))
  570. (defgroup org-agenda-skip nil
  571. "Options concerning skipping parts of agenda files."
  572. :tag "Org Agenda Skip"
  573. :group 'org-agenda)
  574. (defcustom org-agenda-skip-function-global nil
  575. "Function to be called at each match during agenda construction.
  576. If this function returns nil, the current match should not be skipped.
  577. If the function decided to skip an agenda match, is must return the
  578. buffer position from which the search should be continued.
  579. This may also be a Lisp form, which will be evaluated.
  580. This variable will be applied to every agenda match, including
  581. tags/property searches and TODO lists. So try to make the test function
  582. do its checking as efficiently as possible. To implement a skipping
  583. condition just for specific agenda commands, use the variable
  584. `org-agenda-skip-function' which can be set in the options section
  585. of custom agenda commands."
  586. :group 'org-agenda-skip
  587. :type 'sexp)
  588. (defgroup org-agenda-daily/weekly nil
  589. "Options concerning the daily/weekly agenda."
  590. :tag "Org Agenda Daily/Weekly"
  591. :group 'org-agenda)
  592. (defgroup org-agenda-todo-list nil
  593. "Options concerning the global todo list agenda view."
  594. :tag "Org Agenda Todo List"
  595. :group 'org-agenda)
  596. (defgroup org-agenda-match-view nil
  597. "Options concerning the general tags/property/todo match agenda view."
  598. :tag "Org Agenda Match View"
  599. :group 'org-agenda)
  600. (defgroup org-agenda-search-view nil
  601. "Options concerning the search agenda view."
  602. :tag "Org Agenda Search View"
  603. :group 'org-agenda)
  604. (defvar org-agenda-archives-mode nil
  605. "Non-nil means the agenda will include archived items.
  606. If this is the symbol `trees', trees in the selected agenda scope
  607. that are marked with the ARCHIVE tag will be included anyway. When this is
  608. t, also all archive files associated with the current selection of agenda
  609. files will be included.")
  610. (defcustom org-agenda-restriction-lock-highlight-subtree t
  611. "Non-nil means highlight the whole subtree when restriction is active.
  612. Otherwise only highlight the headline. Highlighting the whole subtree is
  613. useful to ensure no edits happen beyond the restricted region."
  614. :group 'org-agenda
  615. :type 'boolean)
  616. (defcustom org-agenda-skip-comment-trees t
  617. "Non-nil means skip trees that start with the COMMENT keyword.
  618. When nil, these trees are also scanned by agenda commands."
  619. :group 'org-agenda-skip
  620. :type 'boolean)
  621. (defcustom org-agenda-todo-list-sublevels t
  622. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  623. When nil, the sublevels of a TODO entry are not checked, resulting in
  624. potentially much shorter TODO lists."
  625. :group 'org-agenda-skip
  626. :group 'org-agenda-todo-list
  627. :type 'boolean)
  628. (defcustom org-agenda-todo-ignore-with-date nil
  629. "Non-nil means don't show entries with a date in the global todo list.
  630. You can use this if you prefer to mark mere appointments with a TODO keyword,
  631. but don't want them to show up in the TODO list.
  632. When this is set, it also covers deadlines and scheduled items, the settings
  633. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  634. will be ignored.
  635. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  636. :group 'org-agenda-skip
  637. :group 'org-agenda-todo-list
  638. :type 'boolean)
  639. (defcustom org-agenda-todo-ignore-timestamp nil
  640. "Non-nil means don't show entries with a timestamp.
  641. This applies when creating the global todo list.
  642. Valid values are:
  643. past Don't show entries for today or in the past.
  644. future Don't show entries with a timestamp in the future.
  645. The idea behind this is that if it has a future
  646. timestamp, you don't want to think about it until the
  647. date.
  648. all Don't show any entries with a timestamp in the global todo list.
  649. The idea behind this is that by setting a timestamp, you
  650. have already \"taken care\" of this item.
  651. This variable can also have an integer as a value. If positive (N),
  652. todos with a timestamp N or more days in the future will be ignored. If
  653. negative (-N), todos with a timestamp N or more days in the past will be
  654. ignored. If 0, todos with a timestamp either today or in the future will
  655. be ignored. For example, a value of -1 will exclude todos with a
  656. timestamp in the past (yesterday or earlier), while a value of 7 will
  657. exclude todos with a timestamp a week or more in the future.
  658. See also `org-agenda-todo-ignore-with-date'.
  659. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  660. to make his option also apply to the tags-todo list."
  661. :group 'org-agenda-skip
  662. :group 'org-agenda-todo-list
  663. :version "24.1"
  664. :type '(choice
  665. (const :tag "Ignore future timestamp todos" future)
  666. (const :tag "Ignore past or present timestamp todos" past)
  667. (const :tag "Ignore all timestamp todos" all)
  668. (const :tag "Show timestamp todos" nil)
  669. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  670. (defcustom org-agenda-todo-ignore-scheduled nil
  671. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  672. This applies when creating the global todo list.
  673. Valid values are:
  674. past Don't show entries scheduled today or in the past.
  675. future Don't show entries scheduled in the future.
  676. The idea behind this is that by scheduling it, you don't want to
  677. think about it until the scheduled date.
  678. all Don't show any scheduled entries in the global todo list.
  679. The idea behind this is that by scheduling it, you have already
  680. \"taken care\" of this item.
  681. t Same as `all', for backward compatibility.
  682. This variable can also have an integer as a value. See
  683. `org-agenda-todo-ignore-timestamp' for more details.
  684. See also `org-agenda-todo-ignore-with-date'.
  685. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  686. to make his option also apply to the tags-todo list."
  687. :group 'org-agenda-skip
  688. :group 'org-agenda-todo-list
  689. :type '(choice
  690. (const :tag "Ignore future-scheduled todos" future)
  691. (const :tag "Ignore past- or present-scheduled todos" past)
  692. (const :tag "Ignore all scheduled todos" all)
  693. (const :tag "Ignore all scheduled todos (compatibility)" t)
  694. (const :tag "Show scheduled todos" nil)
  695. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  696. (defcustom org-agenda-todo-ignore-deadlines nil
  697. "Non-nil means ignore some deadline TODO items when making TODO list.
  698. There are different motivations for using different values, please think
  699. carefully when configuring this variable.
  700. This applies when creating the global TODO list.
  701. Valid values are:
  702. near Don't show near deadline entries. A deadline is near when it is
  703. closer than `org-deadline-warning-days' days. The idea behind this
  704. is that such items will appear in the agenda anyway.
  705. far Don't show TODO entries where a deadline has been defined, but
  706. is not going to happen anytime soon. This is useful if you want to use
  707. the TODO list to figure out what to do now.
  708. past Don't show entries with a deadline timestamp for today or in the past.
  709. future Don't show entries with a deadline timestamp in the future, not even
  710. when they become `near' ones. Use it with caution.
  711. all Ignore all TODO entries that do have a deadline.
  712. t Same as `near', for backward compatibility.
  713. This variable can also have an integer as a value. See
  714. `org-agenda-todo-ignore-timestamp' for more details.
  715. See also `org-agenda-todo-ignore-with-date'.
  716. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  717. to make his option also apply to the tags-todo list."
  718. :group 'org-agenda-skip
  719. :group 'org-agenda-todo-list
  720. :type '(choice
  721. (const :tag "Ignore near deadlines" near)
  722. (const :tag "Ignore near deadlines (compatibility)" t)
  723. (const :tag "Ignore far deadlines" far)
  724. (const :tag "Ignore all TODOs with a deadlines" all)
  725. (const :tag "Show all TODOs, even if they have a deadline" nil)
  726. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  727. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  728. "Time unit to use when possibly ignoring an agenda item.
  729. See the docstring of various `org-agenda-todo-ignore-*' options.
  730. The default is to compare time stamps using days. An item is thus
  731. considered to be in the future if it is at least one day after today.
  732. Non-nil means to compare time stamps using seconds. An item is then
  733. considered future if it has a time value later than current time."
  734. :group 'org-agenda-skip
  735. :group 'org-agenda-todo-list
  736. :version "24.4"
  737. :package-version '(Org . "8.0")
  738. :type '(choice
  739. (const :tag "Compare time with days" nil)
  740. (const :tag "Compare time with seconds" t)))
  741. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  742. "Non-nil means honor todo-list ignores options also in tags-todo search.
  743. The variables
  744. `org-agenda-todo-ignore-with-date',
  745. `org-agenda-todo-ignore-timestamp',
  746. `org-agenda-todo-ignore-scheduled',
  747. `org-agenda-todo-ignore-deadlines'
  748. make the global TODO list skip entries that have time stamps of certain
  749. kinds. If this option is set, the same options will also apply for the
  750. tags-todo search, which is the general tags/property matcher
  751. restricted to unfinished TODO entries only."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-todo-list
  754. :group 'org-agenda-match-view
  755. :type 'boolean)
  756. (defcustom org-agenda-skip-scheduled-if-done nil
  757. "Non-nil means don't show scheduled items in agenda when they are done.
  758. This is relevant for the daily/weekly agenda, not for the TODO list. It
  759. applies only to the actual date of the scheduling. Warnings about an item
  760. with a past scheduling dates are always turned off when the item is DONE."
  761. :group 'org-agenda-skip
  762. :group 'org-agenda-daily/weekly
  763. :type 'boolean)
  764. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  765. "Non-nil means skip scheduling line if same entry shows because of deadline.
  766. In the agenda of today, an entry can show up multiple times
  767. because it is both scheduled and has a nearby deadline, and maybe
  768. a plain time stamp as well.
  769. When this variable is nil, the entry will be shown several times.
  770. When set to t, then only the deadline is shown and the fact that
  771. the entry is scheduled today or was scheduled previously is not
  772. shown.
  773. When set to the symbol `not-today', skip scheduled previously,
  774. but not scheduled today.
  775. When set to the symbol `repeated-after-deadline', skip scheduled
  776. items if they are repeated beyond the current deadline."
  777. :group 'org-agenda-skip
  778. :group 'org-agenda-daily/weekly
  779. :type '(choice
  780. (const :tag "Never" nil)
  781. (const :tag "Always" t)
  782. (const :tag "Not when scheduled today" not-today)
  783. (const :tag "When repeated past deadline" repeated-after-deadline)))
  784. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  785. "Non-nil means skip timestamp line if same entry shows because of deadline.
  786. In the agenda of today, an entry can show up multiple times
  787. because it has both a plain timestamp and has a nearby deadline.
  788. When this variable is t, then only the deadline is shown and the
  789. fact that the entry has a timestamp for or including today is not
  790. shown. When this variable is nil, the entry will be shown
  791. several times."
  792. :group 'org-agenda-skip
  793. :group 'org-agenda-daily/weekly
  794. :version "24.1"
  795. :type '(choice
  796. (const :tag "Never" nil)
  797. (const :tag "Always" t)))
  798. (defcustom org-agenda-skip-deadline-if-done nil
  799. "Non-nil means don't show deadlines when the corresponding item is done.
  800. When nil, the deadline is still shown and should give you a happy feeling.
  801. This is relevant for the daily/weekly agenda. It applies only to the
  802. actual date of the deadline. Warnings about approaching and past-due
  803. deadlines are always turned off when the item is DONE."
  804. :group 'org-agenda-skip
  805. :group 'org-agenda-daily/weekly
  806. :type 'boolean)
  807. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  808. "Non-nil means skip deadline prewarning when entry is also scheduled.
  809. This will apply on all days where a prewarning for the deadline would
  810. be shown, but not at the day when the entry is actually due. On that day,
  811. the deadline will be shown anyway.
  812. This variable may be set to nil, t, the symbol `pre-scheduled',
  813. or a number which will then give the number of days before the actual
  814. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  815. eliminates the deadline prewarning only prior to the scheduled date.
  816. This can be used in a workflow where the first showing of the deadline will
  817. trigger you to schedule it, and then you don't want to be reminded of it
  818. because you will take care of it on the day when scheduled."
  819. :group 'org-agenda-skip
  820. :group 'org-agenda-daily/weekly
  821. :version "24.1"
  822. :type '(choice
  823. (const :tag "Always show prewarning" nil)
  824. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  825. (const :tag "Remove prewarning if entry is scheduled" t)
  826. (integer :tag "Restart prewarning N days before deadline")))
  827. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  828. "Non-nil means skip scheduled delay when entry also has a deadline.
  829. This variable may be set to nil, t, the symbol `post-deadline',
  830. or a number which will then give the number of days after the actual
  831. scheduled date when the delay should expire. The symbol `post-deadline'
  832. eliminates the schedule delay when the date is posterior to the deadline."
  833. :group 'org-agenda-skip
  834. :group 'org-agenda-daily/weekly
  835. :version "24.4"
  836. :package-version '(Org . "8.0")
  837. :type '(choice
  838. (const :tag "Always honor delay" nil)
  839. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  840. (const :tag "Ignore delay if entry has a deadline" t)
  841. (integer :tag "Honor delay up until N days after the scheduled date")))
  842. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  843. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  844. When non-nil, after the search for timestamps has matched once in an
  845. entry, the rest of the entry will not be searched."
  846. :group 'org-agenda-skip
  847. :type 'boolean)
  848. (defcustom org-agenda-skip-timestamp-if-done nil
  849. "Non-nil means don't select item by timestamp or -range if it is DONE."
  850. :group 'org-agenda-skip
  851. :group 'org-agenda-daily/weekly
  852. :type 'boolean)
  853. (defcustom org-agenda-dim-blocked-tasks t
  854. "Non-nil means dim blocked tasks in the agenda display.
  855. This causes some overhead during agenda construction, but if you
  856. have turned on `org-enforce-todo-dependencies',
  857. `org-enforce-todo-checkbox-dependencies', or any other blocking
  858. mechanism, this will create useful feedback in the agenda.
  859. Instead of t, this variable can also have the value `invisible'.
  860. Then blocked tasks will be invisible and only become visible when
  861. they become unblocked. An exemption to this behavior is when a task is
  862. blocked because of unchecked checkboxes below it. Since checkboxes do
  863. not show up in the agenda views, making this task invisible you remove any
  864. trace from agenda views that there is something to do. Therefore, a task
  865. that is blocked because of checkboxes will never be made invisible, it
  866. will only be dimmed."
  867. :group 'org-agenda-daily/weekly
  868. :group 'org-agenda-todo-list
  869. :version "24.3"
  870. :type '(choice
  871. (const :tag "Do not dim" nil)
  872. (const :tag "Dim to a gray face" t)
  873. (const :tag "Make invisible" invisible)))
  874. (defgroup org-agenda-startup nil
  875. "Options concerning initial settings in the Agenda in Org Mode."
  876. :tag "Org Agenda Startup"
  877. :group 'org-agenda)
  878. (defcustom org-agenda-menu-show-matcher t
  879. "Non-nil means show the match string in the agenda dispatcher menu.
  880. When nil, the matcher string is not shown, but is put into the help-echo
  881. property so than moving the mouse over the command shows it.
  882. Setting it to nil is good if matcher strings are very long and/or if
  883. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  884. :group 'org-agenda
  885. :version "24.1"
  886. :type 'boolean)
  887. (defcustom org-agenda-menu-two-columns nil
  888. "Non-nil means, use two columns to show custom commands in the dispatcher.
  889. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  890. to nil."
  891. :group 'org-agenda
  892. :version "24.1"
  893. :type 'boolean)
  894. (defcustom org-agenda-finalize-hook nil
  895. "Hook run just before displaying an agenda buffer.
  896. The buffer is still writable when the hook is called.
  897. You can modify some of the buffer substrings but you should be
  898. extra careful not to modify the text properties of the agenda
  899. headlines as the agenda display heavily relies on them."
  900. :group 'org-agenda-startup
  901. :type 'hook)
  902. (defcustom org-agenda-filter-hook nil
  903. "Hook run just after filtering with `org-agenda-filter'."
  904. :group 'org-agenda-startup
  905. :package-version '(Org . "9.4")
  906. :type 'hook)
  907. (defcustom org-agenda-mouse-1-follows-link nil
  908. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  909. A longer mouse click will still set point. Needs to be set
  910. before org.el is loaded."
  911. :group 'org-agenda-startup
  912. :type 'boolean)
  913. (defcustom org-agenda-start-with-follow-mode nil
  914. "The initial value of follow mode in a newly created agenda window."
  915. :group 'org-agenda-startup
  916. :type 'boolean)
  917. (defcustom org-agenda-follow-indirect nil
  918. "Non-nil means `org-agenda-follow-mode' displays only the
  919. current item's tree, in an indirect buffer."
  920. :group 'org-agenda
  921. :version "24.1"
  922. :type 'boolean)
  923. (defcustom org-agenda-show-outline-path t
  924. "Non-nil means show outline path in echo area after line motion."
  925. :group 'org-agenda-startup
  926. :type 'boolean)
  927. (defcustom org-agenda-start-with-entry-text-mode nil
  928. "The initial value of entry-text-mode in a newly created agenda window."
  929. :group 'org-agenda-startup
  930. :type 'boolean)
  931. (defcustom org-agenda-entry-text-maxlines 5
  932. "Number of text lines to be added when `E' is pressed in the agenda.
  933. Note that this variable only used during agenda display. To add entry text
  934. when exporting the agenda, configure the variable
  935. `org-agenda-add-entry-text-maxlines'."
  936. :group 'org-agenda
  937. :type 'integer)
  938. (defcustom org-agenda-entry-text-exclude-regexps nil
  939. "List of regular expressions to clean up entry text.
  940. The complete matches of all regular expressions in this list will be
  941. removed from entry text before it is shown in the agenda."
  942. :group 'org-agenda
  943. :type '(repeat (regexp)))
  944. (defcustom org-agenda-entry-text-leaders " > "
  945. "Text prepended to the entry text in agenda buffers."
  946. :version "24.4"
  947. :package-version '(Org . "8.0")
  948. :group 'org-agenda
  949. :type 'string)
  950. (defvar org-agenda-entry-text-cleanup-hook nil
  951. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  952. This cleanup is done in a temporary buffer, so the function may inspect and
  953. change the entire buffer.
  954. Some default stuff like drawers and scheduling/deadline dates will already
  955. have been removed when this is called, as will any matches for regular
  956. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  957. (defvar org-agenda-include-inactive-timestamps nil
  958. "Non-nil means include inactive time stamps in agenda.
  959. Dynamically scoped.")
  960. (defgroup org-agenda-windows nil
  961. "Options concerning the windows used by the Agenda in Org Mode."
  962. :tag "Org Agenda Windows"
  963. :group 'org-agenda)
  964. (defcustom org-agenda-window-setup 'reorganize-frame
  965. "How the agenda buffer should be displayed.
  966. Possible values for this option are:
  967. current-window Show agenda in the current window, keeping all other windows.
  968. other-window Use `switch-to-buffer-other-window' to display agenda.
  969. only-window Show agenda, deleting all other windows.
  970. reorganize-frame Show only two windows on the current frame, the current
  971. window and the agenda.
  972. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  973. Also, when exiting the agenda, kill that frame.
  974. other-tab Use `switch-to-buffer-other-tab' to display the
  975. agenda, making use of the `tab-bar-mode' introduced
  976. in Emacs version 27.1. Also, kill that tab when
  977. exiting the agenda view.
  978. See also the variable `org-agenda-restore-windows-after-quit'."
  979. :group 'org-agenda-windows
  980. :type '(choice
  981. (const current-window)
  982. (const other-frame)
  983. (const other-tab)
  984. (const other-window)
  985. (const only-window)
  986. (const reorganize-frame))
  987. :package-version '(Org . "9.4"))
  988. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  989. "The min and max height of the agenda window as a fraction of frame height.
  990. The value of the variable is a cons cell with two numbers between 0 and 1.
  991. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  992. :group 'org-agenda-windows
  993. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  994. (defcustom org-agenda-restore-windows-after-quit nil
  995. "Non-nil means restore window configuration upon exiting agenda.
  996. Before the window configuration is changed for displaying the
  997. agenda, the current status is recorded. When the agenda is
  998. exited with `q' or `x' and this option is set, the old state is
  999. restored. If `org-agenda-window-setup' is `other-frame' or
  1000. `other-tab', the value of this option will be ignored."
  1001. :group 'org-agenda-windows
  1002. :type 'boolean)
  1003. (defcustom org-agenda-span 'week
  1004. "Number of days to include in overview display.
  1005. Can be day, week, month, year, or any number of days.
  1006. Custom commands can set this variable in the options section."
  1007. :group 'org-agenda-daily/weekly
  1008. :type '(choice (const :tag "Day" day)
  1009. (const :tag "Week" week)
  1010. (const :tag "Fortnight" fortnight)
  1011. (const :tag "Month" month)
  1012. (const :tag "Year" year)
  1013. (integer :tag "Custom")))
  1014. (defcustom org-agenda-start-on-weekday 1
  1015. "Non-nil means start the overview always on the specified weekday.
  1016. 0 denotes Sunday, 1 denotes Monday, etc.
  1017. When nil, always start on the current day.
  1018. Custom commands can set this variable in the options section."
  1019. :group 'org-agenda-daily/weekly
  1020. :type '(choice (const :tag "Today" nil)
  1021. (integer :tag "Weekday No.")))
  1022. (defcustom org-agenda-show-all-dates t
  1023. "Non-nil means `org-agenda' shows every day in the selected range.
  1024. When nil, only the days which actually have entries are shown."
  1025. :group 'org-agenda-daily/weekly
  1026. :type 'boolean)
  1027. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1028. "Format string for displaying dates in the agenda.
  1029. Used by the daily/weekly agenda. This should be a format string
  1030. understood by `format-time-string', or a function returning the
  1031. formatted date as a string. The function must take a single
  1032. argument, a calendar-style date list like (month day year)."
  1033. :group 'org-agenda-daily/weekly
  1034. :type '(choice
  1035. (string :tag "Format string")
  1036. (function :tag "Function")))
  1037. (defun org-agenda-end-of-line ()
  1038. "Go to the end of visible line."
  1039. (interactive)
  1040. (goto-char (line-end-position)))
  1041. (defun org-agenda-format-date-aligned (date)
  1042. "Format a DATE string for display in the daily/weekly agenda.
  1043. This function makes sure that dates are aligned for easy reading."
  1044. (require 'cal-iso)
  1045. (let* ((dayname (calendar-day-name date))
  1046. (day (cadr date))
  1047. (day-of-week (calendar-day-of-week date))
  1048. (month (car date))
  1049. (monthname (calendar-month-name month))
  1050. (year (nth 2 date))
  1051. (iso-week (org-days-to-iso-week
  1052. (calendar-absolute-from-gregorian date)))
  1053. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1054. ;; (1- year))
  1055. ;; ((and (= month 12) (<= iso-week 1))
  1056. ;; (1+ year))
  1057. ;; (t year)))
  1058. (weekstring (if (= day-of-week 1)
  1059. (format " W%02d" iso-week)
  1060. "")))
  1061. (format "%-10s %2d %s %4d%s"
  1062. dayname day monthname year weekstring)))
  1063. (defcustom org-agenda-time-leading-zero nil
  1064. "Non-nil means use leading zero for military times in agenda.
  1065. For example, 9:30am would become 09:30 rather than 9:30."
  1066. :group 'org-agenda-daily/weekly
  1067. :version "24.1"
  1068. :type 'boolean)
  1069. (defcustom org-agenda-timegrid-use-ampm nil
  1070. "When set, show AM/PM style timestamps on the timegrid."
  1071. :group 'org-agenda
  1072. :version "24.1"
  1073. :type 'boolean)
  1074. (defun org-agenda-time-of-day-to-ampm (time)
  1075. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1076. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1077. (minute (substring time -2))
  1078. (ampm "am"))
  1079. (cond
  1080. ((equal hour-number 12)
  1081. (setq ampm "pm"))
  1082. ((> hour-number 12)
  1083. (setq ampm "pm")
  1084. (setq hour-number (- hour-number 12))))
  1085. (concat
  1086. (if org-agenda-time-leading-zero
  1087. (format "%02d" hour-number)
  1088. (format "%02s" (number-to-string hour-number)))
  1089. ":" minute ampm)))
  1090. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1091. "Conditionally convert TIME to AM/PM format.
  1092. This is based on `org-agenda-timegrid-use-ampm'."
  1093. (if org-agenda-timegrid-use-ampm
  1094. (org-agenda-time-of-day-to-ampm time)
  1095. time))
  1096. (defcustom org-agenda-weekend-days '(6 0)
  1097. "Which days are weekend?
  1098. These days get the special face `org-agenda-date-weekend' in the agenda."
  1099. :group 'org-agenda-daily/weekly
  1100. :type '(set :greedy t
  1101. (const :tag "Monday" 1)
  1102. (const :tag "Tuesday" 2)
  1103. (const :tag "Wednesday" 3)
  1104. (const :tag "Thursday" 4)
  1105. (const :tag "Friday" 5)
  1106. (const :tag "Saturday" 6)
  1107. (const :tag "Sunday" 0)))
  1108. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1109. "Non-nil means jump to today when moving a past date forward in time.
  1110. When using S-right in the agenda to move a date forward, and the date
  1111. stamp currently points to the past, the first key press will move it
  1112. to today. When nil, just move one day forward even if the date stays
  1113. in the past."
  1114. :group 'org-agenda-daily/weekly
  1115. :version "24.1"
  1116. :type 'boolean)
  1117. (defcustom org-agenda-diary-file 'diary-file
  1118. "File to which to add new entries with the `i' key in agenda and calendar.
  1119. When this is the symbol `diary-file', the functionality in the Emacs
  1120. calendar will be used to add entries to the `diary-file'. But when this
  1121. points to a file, `org-agenda-diary-entry' will be used instead."
  1122. :group 'org-agenda
  1123. :type '(choice
  1124. (const :tag "The standard Emacs diary file" diary-file)
  1125. (file :tag "Special Org file diary entries")))
  1126. (defcustom org-agenda-include-diary nil
  1127. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1128. Custom commands can set this variable in the options section."
  1129. :group 'org-agenda-daily/weekly
  1130. :type 'boolean)
  1131. (defcustom org-agenda-include-deadlines t
  1132. "If non-nil, include entries within their deadline warning period.
  1133. Custom commands can set this variable in the options section."
  1134. :group 'org-agenda-daily/weekly
  1135. :version "24.1"
  1136. :type 'boolean)
  1137. (defcustom org-agenda-show-future-repeats t
  1138. "Non-nil shows repeated entries in the future part of the agenda.
  1139. When set to the symbol `next' only the first future repeat is shown."
  1140. :group 'org-agenda-daily/weekly
  1141. :type '(choice
  1142. (const :tag "Show all repeated entries" t)
  1143. (const :tag "Show next repeated entry" next)
  1144. (const :tag "Do not show repeated entries" nil))
  1145. :version "26.1"
  1146. :package-version '(Org . "9.1")
  1147. :safe #'symbolp)
  1148. (defcustom org-agenda-prefer-last-repeat nil
  1149. "Non-nil sets date for repeated entries to their last repeat.
  1150. When nil, display SCHEDULED and DEADLINE dates at their base
  1151. date, and in today's agenda, as a reminder. Display plain
  1152. time-stamps, on the other hand, at every repeat date in the past
  1153. in addition to the base date.
  1154. When non-nil, show a repeated entry at its latest repeat date,
  1155. possibly being today even if it wasn't marked as done. This
  1156. setting is useful if you do not always mark repeated entries as
  1157. done and, yet, consider that reaching repeat date starts the task
  1158. anew.
  1159. When set to a list of strings, prefer last repeats only for
  1160. entries with these TODO keywords."
  1161. :group 'org-agenda-daily/weekly
  1162. :type '(choice
  1163. (const :tag "Prefer last repeat" t)
  1164. (const :tag "Prefer base date" nil)
  1165. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1166. (string :tag "TODO keyword")))
  1167. :version "26.1"
  1168. :package-version '(Org . "9.1")
  1169. :safe (lambda (x) (or (booleanp x) (consp x))))
  1170. (defcustom org-scheduled-past-days 10000
  1171. "Number of days to continue listing scheduled items not marked DONE.
  1172. When an item is scheduled on a date, it shows up in the agenda on
  1173. this day and will be listed until it is marked done or for the
  1174. number of days given here."
  1175. :group 'org-agenda-daily/weekly
  1176. :type 'integer
  1177. :safe 'integerp)
  1178. (defcustom org-deadline-past-days 10000
  1179. "Number of days to warn about missed deadlines.
  1180. When an item has deadline on a date, it shows up in the agenda on
  1181. this day and will appear as a reminder until it is marked DONE or
  1182. for the number of days given here."
  1183. :group 'org-agenda-daily/weekly
  1184. :type 'integer
  1185. :version "26.1"
  1186. :package-version '(Org . "9.1")
  1187. :safe 'integerp)
  1188. (defcustom org-agenda-log-mode-items '(closed clock)
  1189. "List of items that should be shown in agenda log mode.
  1190. \\<org-agenda-mode-map>\
  1191. This list may contain the following symbols:
  1192. closed Show entries that have been closed on that day.
  1193. clock Show entries that have received clocked time on that day.
  1194. state Show all logged state changes.
  1195. Note that instead of changing this variable, you can also press \
  1196. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1197. the agenda to display all available LOG items temporarily."
  1198. :group 'org-agenda-daily/weekly
  1199. :type '(set :greedy t (const closed) (const clock) (const state)))
  1200. (defcustom org-agenda-clock-consistency-checks
  1201. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1202. :gap-ok-around ("4:00")
  1203. :default-face ((:background "DarkRed") (:foreground "white"))
  1204. :overlap-face nil :gap-face nil :no-end-time-face nil
  1205. :long-face nil :short-face nil)
  1206. "This is a property list, with the following keys:
  1207. :max-duration Mark clocking chunks that are longer than this time.
  1208. This is a time string like \"HH:MM\", or the number
  1209. of minutes as an integer.
  1210. :min-duration Mark clocking chunks that are shorter that this.
  1211. This is a time string like \"HH:MM\", or the number
  1212. of minutes as an integer.
  1213. :max-gap Mark gaps between clocking chunks that are longer than
  1214. this duration. A number of minutes, or a string
  1215. like \"HH:MM\".
  1216. :gap-ok-around List of times during the day which are usually not working
  1217. times. When a gap is detected, but the gap contains any
  1218. of these times, the gap is *not* reported. For example,
  1219. if this is (\"4:00\" \"13:00\") then gaps that contain
  1220. 4:00 in the morning (i.e. the night) and 13:00
  1221. (i.e. a typical lunch time) do not cause a warning.
  1222. You should have at least one time during the night in this
  1223. list, or otherwise the first task each morning will trigger
  1224. a warning because it follows a long gap.
  1225. Furthermore, the following properties can be used to define faces for
  1226. issue display.
  1227. :default-face the default face, if the specific face is undefined
  1228. :overlap-face face for overlapping clocks
  1229. :gap-face face for gaps between clocks
  1230. :no-end-time-face face for incomplete clocks
  1231. :long-face face for clock intervals that are too long
  1232. :short-face face for clock intervals that are too short"
  1233. :group 'org-agenda-daily/weekly
  1234. :group 'org-clock
  1235. :version "24.1"
  1236. :type 'plist)
  1237. (defcustom org-agenda-log-mode-add-notes t
  1238. "Non-nil means add first line of notes to log entries in agenda views.
  1239. If a log item like a state change or a clock entry is associated with
  1240. notes, the first line of these notes will be added to the entry in the
  1241. agenda display."
  1242. :group 'org-agenda-daily/weekly
  1243. :type 'boolean)
  1244. (defcustom org-agenda-start-with-log-mode nil
  1245. "The initial value of log-mode in a newly created agenda window.
  1246. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1247. explanations on the possible values."
  1248. :group 'org-agenda-startup
  1249. :group 'org-agenda-daily/weekly
  1250. :type '(choice (const :tag "Don't show log items" nil)
  1251. (const :tag "Show only log items" only)
  1252. (const :tag "Show all possible log items" clockcheck)
  1253. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1254. (choice (const :tag "Show closed log items" closed)
  1255. (const :tag "Show clocked log items" clock)
  1256. (const :tag "Show all logged state changes" state)))))
  1257. (defcustom org-agenda-start-with-clockreport-mode nil
  1258. "The initial value of clockreport-mode in a newly created agenda window."
  1259. :group 'org-agenda-startup
  1260. :group 'org-agenda-daily/weekly
  1261. :type 'boolean)
  1262. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1263. "Property list with parameters for the clocktable in clockreport mode.
  1264. This is the display mode that shows a clock table in the daily/weekly
  1265. agenda, the properties for this dynamic block can be set here.
  1266. The usual clocktable parameters are allowed here, but you cannot set
  1267. the properties :name, :tstart, :tend, :block, and :scope - these will
  1268. be overwritten to make sure the content accurately reflects the
  1269. current display in the agenda."
  1270. :group 'org-agenda-daily/weekly
  1271. :type 'plist)
  1272. (defvaralias 'org-agenda-search-view-search-words-only
  1273. 'org-agenda-search-view-always-boolean)
  1274. (defcustom org-agenda-search-view-always-boolean nil
  1275. "Non-nil means the search string is interpreted as individual parts.
  1276. The search string for search view can either be interpreted as a phrase,
  1277. or as a list of snippets that define a boolean search for a number of
  1278. strings.
  1279. When this is non-nil, the string will be split on whitespace, and each
  1280. snippet will be searched individually, and all must match in order to
  1281. select an entry. A snippet is then a single string of non-white
  1282. characters, or a string in double quotes, or a regexp in {} braces.
  1283. If a snippet is preceded by \"-\", the snippet must *not* match.
  1284. \"+\" is syntactic sugar for positive selection. Each snippet may
  1285. be found as a full word or a partial word, but see the variable
  1286. `org-agenda-search-view-force-full-words'.
  1287. When this is nil, search will look for the entire search phrase as one,
  1288. with each space character matching any amount of whitespace, including
  1289. line breaks.
  1290. Even when this is nil, you can still switch to Boolean search dynamically
  1291. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1292. is a regexp marked with braces like \"{abc}\", this will also switch to
  1293. boolean search."
  1294. :group 'org-agenda-search-view
  1295. :version "24.1"
  1296. :type 'boolean)
  1297. (defcustom org-agenda-search-view-force-full-words nil
  1298. "Non-nil means, search words must be matches as complete words.
  1299. When nil, they may also match part of a word."
  1300. :group 'org-agenda-search-view
  1301. :version "24.1"
  1302. :type 'boolean)
  1303. (defcustom org-agenda-search-view-max-outline-level 0
  1304. "Maximum outline level to display in search view.
  1305. E.g. when this is set to 1, the search view will only
  1306. show headlines of level 1. When set to 0, the default
  1307. value, don't limit agenda view by outline level."
  1308. :group 'org-agenda-search-view
  1309. :version "26.1"
  1310. :package-version '(Org . "8.3")
  1311. :type 'integer)
  1312. (defgroup org-agenda-time-grid nil
  1313. "Options concerning the time grid in the Org Agenda."
  1314. :tag "Org Agenda Time Grid"
  1315. :group 'org-agenda)
  1316. (defcustom org-agenda-search-headline-for-time t
  1317. "Non-nil means search headline for a time-of-day.
  1318. If the headline contains a time-of-day in one format or another, it will
  1319. be used to sort the entry into the time sequence of items for a day.
  1320. Some people have time stamps in the headline that refer to the creation
  1321. time or so, and then this produces an unwanted side effect. If this is
  1322. the case for your, use this variable to turn off searching the headline
  1323. for a time."
  1324. :group 'org-agenda-time-grid
  1325. :type 'boolean)
  1326. (defcustom org-agenda-use-time-grid t
  1327. "Non-nil means show a time grid in the agenda schedule.
  1328. A time grid is a set of lines for specific times (like every two hours between
  1329. 8:00 and 20:00). The items scheduled for a day at specific times are
  1330. sorted in between these lines.
  1331. For details about when the grid will be shown, and what it will look like, see
  1332. the variable `org-agenda-time-grid'."
  1333. :group 'org-agenda-time-grid
  1334. :type 'boolean)
  1335. (defcustom org-agenda-time-grid
  1336. '((daily today require-timed)
  1337. (800 1000 1200 1400 1600 1800 2000)
  1338. "......"
  1339. "----------------")
  1340. "The settings for time grid for agenda display.
  1341. This is a list of four items. The first item is again a list. It contains
  1342. symbols specifying conditions when the grid should be displayed:
  1343. daily if the agenda shows a single day
  1344. weekly if the agenda shows an entire week
  1345. today show grid on current date, independent of daily/weekly display
  1346. require-timed show grid only if at least one item has a time specification
  1347. remove-match skip grid times already present in an entry
  1348. The second item is a list of integers, indicating the times that
  1349. should have a grid line.
  1350. The third item is a string which will be placed right after the
  1351. times that have a grid line.
  1352. The fourth item is a string placed after the grid times. This
  1353. will align with agenda items."
  1354. :group 'org-agenda-time-grid
  1355. :type
  1356. '(list
  1357. (set :greedy t :tag "Grid Display Options"
  1358. (const :tag "Show grid in single day agenda display" daily)
  1359. (const :tag "Show grid in weekly agenda display" weekly)
  1360. (const :tag "Always show grid for today" today)
  1361. (const :tag "Show grid only if any timed entries are present"
  1362. require-timed)
  1363. (const :tag "Skip grid times already present in an entry"
  1364. remove-match))
  1365. (repeat :tag "Grid Times" (integer :tag "Time"))
  1366. (string :tag "Grid String (after agenda times)")
  1367. (string :tag "Grid String (aligns with agenda items)")))
  1368. (defcustom org-agenda-show-current-time-in-grid t
  1369. "Non-nil means show the current time in the time grid."
  1370. :group 'org-agenda-time-grid
  1371. :version "24.1"
  1372. :type 'boolean)
  1373. (defcustom org-agenda-current-time-string
  1374. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1375. "The string for the current time marker in the agenda."
  1376. :group 'org-agenda-time-grid
  1377. :version "24.1"
  1378. :type 'string)
  1379. (defgroup org-agenda-sorting nil
  1380. "Options concerning sorting in the Org Agenda."
  1381. :tag "Org Agenda Sorting"
  1382. :group 'org-agenda)
  1383. (defcustom org-agenda-sorting-strategy
  1384. '((agenda habit-down time-up priority-down category-keep)
  1385. (todo priority-down category-keep)
  1386. (tags priority-down category-keep)
  1387. (search category-keep))
  1388. "Sorting structure for the agenda items of a single day.
  1389. This is a list of symbols which will be used in sequence to determine
  1390. if an entry should be listed before another entry. The following
  1391. symbols are recognized:
  1392. time-up Put entries with time-of-day indications first, early first.
  1393. time-down Put entries with time-of-day indications first, late first.
  1394. timestamp-up Sort by any timestamp, early first.
  1395. timestamp-down Sort by any timestamp, late first.
  1396. scheduled-up Sort by scheduled timestamp, early first.
  1397. scheduled-down Sort by scheduled timestamp, late first.
  1398. deadline-up Sort by deadline timestamp, early first.
  1399. deadline-down Sort by deadline timestamp, late first.
  1400. ts-up Sort by active timestamp, early first.
  1401. ts-down Sort by active timestamp, late first.
  1402. tsia-up Sort by inactive timestamp, early first.
  1403. tsia-down Sort by inactive timestamp, late first.
  1404. category-keep Keep the default order of categories, corresponding to the
  1405. sequence in `org-agenda-files'.
  1406. category-up Sort alphabetically by category, A-Z.
  1407. category-down Sort alphabetically by category, Z-A.
  1408. tag-up Sort alphabetically by last tag, A-Z.
  1409. tag-down Sort alphabetically by last tag, Z-A.
  1410. priority-up Sort numerically by priority, high priority last.
  1411. priority-down Sort numerically by priority, high priority first.
  1412. todo-state-up Sort by todo state, tasks that are done last.
  1413. todo-state-down Sort by todo state, tasks that are done first.
  1414. effort-up Sort numerically by estimated effort, high effort last.
  1415. effort-down Sort numerically by estimated effort, high effort first.
  1416. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1417. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1418. habit-up Put entries that are habits first.
  1419. habit-down Put entries that are habits last.
  1420. alpha-up Sort headlines alphabetically.
  1421. alpha-down Sort headlines alphabetically, reversed.
  1422. The different possibilities will be tried in sequence, and testing stops
  1423. if one comparison returns a \"not-equal\". For example, the default
  1424. `(time-up category-keep priority-down)'
  1425. means: Pull out all entries having a specified time of day and sort them,
  1426. in order to make a time schedule for the current day the first thing in the
  1427. agenda listing for the day. Of the entries without a time indication, keep
  1428. the grouped in categories, don't sort the categories, but keep them in
  1429. the sequence given in `org-agenda-files'. Within each category sort by
  1430. priority.
  1431. Leaving out `category-keep' would mean that items will be sorted across
  1432. categories by priority.
  1433. Instead of a single list, this can also be a set of list for specific
  1434. contents, with a context symbol in the car of the list, any of
  1435. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1436. Custom commands can bind this variable in the options section."
  1437. :group 'org-agenda-sorting
  1438. :type `(choice
  1439. (repeat :tag "General" ,org-sorting-choice)
  1440. (list :tag "Individually"
  1441. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1442. (repeat ,org-sorting-choice))
  1443. (cons (const :tag "Strategy for TODO lists" todo)
  1444. (repeat ,org-sorting-choice))
  1445. (cons (const :tag "Strategy for Tags matches" tags)
  1446. (repeat ,org-sorting-choice))
  1447. (cons (const :tag "Strategy for search matches" search)
  1448. (repeat ,org-sorting-choice)))))
  1449. (defcustom org-agenda-cmp-user-defined nil
  1450. "A function to define the comparison `user-defined'.
  1451. This function must receive two arguments, agenda entry a and b.
  1452. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1453. the user comparison, return nil.
  1454. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1455. part of an agenda sorting strategy."
  1456. :group 'org-agenda-sorting
  1457. :type 'symbol)
  1458. (defcustom org-agenda-sort-notime-is-late t
  1459. "Non-nil means items without time are considered late.
  1460. This is only relevant for sorting. When t, items which have no explicit
  1461. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1462. do have a time. When nil, the default time is before 0:00. You can use this
  1463. option to decide if the schedule for today should come before or after timeless
  1464. agenda entries."
  1465. :group 'org-agenda-sorting
  1466. :type 'boolean)
  1467. (defcustom org-agenda-sort-noeffort-is-high t
  1468. "Non-nil means items without effort estimate are sorted as high effort.
  1469. This also applies when filtering an agenda view with respect to the
  1470. < or > effort operator. Then, tasks with no effort defined will be treated
  1471. as tasks with high effort.
  1472. When nil, such items are sorted as 0 minutes effort."
  1473. :group 'org-agenda-sorting
  1474. :type 'boolean)
  1475. (defgroup org-agenda-line-format nil
  1476. "Options concerning the entry prefix in the Org agenda display."
  1477. :tag "Org Agenda Line Format"
  1478. :group 'org-agenda)
  1479. (defcustom org-agenda-prefix-format
  1480. '((agenda . " %i %-12:c%?-12t% s")
  1481. (todo . " %i %-12:c")
  1482. (tags . " %i %-12:c")
  1483. (search . " %i %-12:c"))
  1484. "Format specifications for the prefix of items in the agenda views.
  1485. An alist with one entry per agenda type. The keys of the
  1486. sublists are `agenda', `todo', `search' and `tags'. The values
  1487. are format strings.
  1488. This format works similar to a printf format, with the following meaning:
  1489. %c the category of the item, \"Diary\" for entries from the diary,
  1490. or as given by the CATEGORY keyword or derived from the file name
  1491. %e the effort required by the item
  1492. %l the level of the item (insert X space(s) if item is of level X)
  1493. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1494. %T the last tag of the item (ignore inherited tags, which come first)
  1495. %t the HH:MM time-of-day specification if one applies to the entry
  1496. %s Scheduling/Deadline information, a short string
  1497. %b show breadcrumbs, i.e., the names of the higher levels
  1498. %(expression) Eval EXPRESSION and replace the control string
  1499. by the result
  1500. All specifiers work basically like the standard `%s' of printf, but may
  1501. contain two additional characters: a question mark just after the `%'
  1502. and a whitespace/punctuation character just before the final letter.
  1503. If the first character after `%' is a question mark, the entire field
  1504. will only be included if the corresponding value applies to the current
  1505. entry. This is useful for fields which should have fixed width when
  1506. present, but zero width when absent. For example, \"%?-12t\" will
  1507. result in a 12 character time field if a time of the day is specified,
  1508. but will completely disappear in entries which do not contain a time.
  1509. If there is punctuation or whitespace character just before the
  1510. final format letter, this character will be appended to the field
  1511. value if the value is not empty. For example, the format
  1512. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1513. the category is empty, no additional colon is inserted.
  1514. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1515. which means:
  1516. - Indent the line with two space characters
  1517. - Give the category a 12 chars wide field, padded with whitespace on
  1518. the right (because of `-'). Append a colon if there is a category
  1519. (because of `:').
  1520. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1521. time, don't put in an empty field, just skip it (because of '?').
  1522. - Finally, put the scheduling information.
  1523. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1524. `org-agenda-remove-tags'.
  1525. Custom commands can set this variable in the options section."
  1526. :type '(choice
  1527. (string :tag "General format")
  1528. (list :greedy t :tag "View dependent"
  1529. (cons (const agenda) (string :tag "Format"))
  1530. (cons (const todo) (string :tag "Format"))
  1531. (cons (const tags) (string :tag "Format"))
  1532. (cons (const search) (string :tag "Format"))))
  1533. :group 'org-agenda-line-format
  1534. :version "26.1"
  1535. :package-version '(Org . "9.1"))
  1536. (defcustom org-agenda-breadcrumbs-separator "->"
  1537. "The separator of breadcrumbs in agenda lines."
  1538. :group 'org-agenda-line-format
  1539. :package-version '(Org . "9.3")
  1540. :type 'string
  1541. :safe #'stringp)
  1542. (defvar org-prefix-format-compiled nil
  1543. "The compiled prefix format and associated variables.
  1544. This is a list where first element is a list of variable bindings, and second
  1545. element is the compiled format expression. See the variable
  1546. `org-agenda-prefix-format'.")
  1547. (defcustom org-agenda-todo-keyword-format "%-1s"
  1548. "Format for the TODO keyword in agenda lines.
  1549. Set this to something like \"%-12s\" if you want all TODO keywords
  1550. to occupy a fixed space in the agenda display."
  1551. :group 'org-agenda-line-format
  1552. :type 'string)
  1553. (defcustom org-agenda-diary-sexp-prefix nil
  1554. "A regexp that matches part of a diary sexp entry
  1555. which should be treated as scheduling/deadline information in
  1556. `org-agenda'.
  1557. For example, you can use this to extract the `diary-remind-message' from
  1558. `diary-remind' entries."
  1559. :group 'org-agenda-line-format
  1560. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1561. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1562. "Text preceding timerange entries in the agenda view.
  1563. This is a list with two strings. The first applies when the range
  1564. is entirely on one day. The second applies if the range spans several days.
  1565. The strings may have two \"%d\" format specifiers which will be filled
  1566. with the sequence number of the days, and the total number of days in the
  1567. range, respectively."
  1568. :group 'org-agenda-line-format
  1569. :type '(list
  1570. (string :tag "Deadline today ")
  1571. (choice :tag "Deadline relative"
  1572. (string :tag "Format string")
  1573. (function))))
  1574. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1575. "Text preceding scheduled items in the agenda view.
  1576. This is a list with two strings. The first applies when the item is
  1577. scheduled on the current day. The second applies when it has been scheduled
  1578. previously, it may contain a %d indicating that this is the nth time that
  1579. this item is scheduled, due to automatic rescheduling of unfinished items
  1580. for the following day. So this number is one larger than the number of days
  1581. that passed since this item was scheduled first."
  1582. :group 'org-agenda-line-format
  1583. :version "24.4"
  1584. :package-version '(Org . "8.0")
  1585. :type '(list
  1586. (string :tag "Scheduled today ")
  1587. (string :tag "Scheduled previously")))
  1588. (defcustom org-agenda-inactive-leader "["
  1589. "Text preceding item pulled into the agenda by inactive time stamps.
  1590. These entries are added to the agenda when pressing \"[\"."
  1591. :group 'org-agenda-line-format
  1592. :version "24.1"
  1593. :type 'string)
  1594. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1595. "Text preceding deadline items in the agenda view.
  1596. This is a list with three strings. The first applies when the item has its
  1597. deadline on the current day. The second applies when the deadline is in the
  1598. future, the third one when it is in the past. The strings may contain %d
  1599. to capture the number of days."
  1600. :group 'org-agenda-line-format
  1601. :version "24.4"
  1602. :package-version '(Org . "8.0")
  1603. :type '(list
  1604. (string :tag "Deadline today ")
  1605. (string :tag "Deadline in the future ")
  1606. (string :tag "Deadline in the past ")))
  1607. (defcustom org-agenda-remove-times-when-in-prefix t
  1608. "Non-nil means remove duplicate time specifications in agenda items.
  1609. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1610. time-of-day specification in a headline or diary entry is extracted and
  1611. placed into the prefix. If this option is non-nil, the original specification
  1612. \(a timestamp or -range, or just a plain time(range) specification like
  1613. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1614. cluttered.
  1615. The option can be t or nil. It may also be the symbol `beg', indicating
  1616. that the time should only be removed when it is located at the beginning of
  1617. the headline/diary entry."
  1618. :group 'org-agenda-line-format
  1619. :type '(choice
  1620. (const :tag "Always" t)
  1621. (const :tag "Never" nil)
  1622. (const :tag "When at beginning of entry" beg)))
  1623. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1624. "Non-nil means remove time ranges specifications in agenda
  1625. items that span on several days."
  1626. :group 'org-agenda-line-format
  1627. :version "24.1"
  1628. :type 'boolean)
  1629. (defcustom org-agenda-default-appointment-duration nil
  1630. "Default duration for appointments that only have a starting time.
  1631. When nil, no duration is specified in such cases.
  1632. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1633. :group 'org-agenda-line-format
  1634. :type '(choice
  1635. (integer :tag "Minutes")
  1636. (const :tag "No default duration")))
  1637. (defcustom org-agenda-show-inherited-tags t
  1638. "Non-nil means show inherited tags in each agenda line.
  1639. When this option is set to `always', it takes precedence over
  1640. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1641. in every agenda.
  1642. When this option is set to t (the default), inherited tags are
  1643. shown when they are available, i.e. when the value of
  1644. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1645. given agenda type.
  1646. This can be set to a list of agenda types in which the agenda
  1647. must display the inherited tags. Available types are `todo',
  1648. `agenda' and `search'.
  1649. When set to nil, never show inherited tags in agenda lines."
  1650. :group 'org-agenda-line-format
  1651. :group 'org-agenda
  1652. :version "24.3"
  1653. :type '(choice
  1654. (const :tag "Show inherited tags when available" t)
  1655. (const :tag "Always show inherited tags" always)
  1656. (repeat :tag "Show inherited tags only in selected agenda types"
  1657. (symbol :tag "Agenda type"))))
  1658. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1659. "List of agenda view types where to use tag inheritance.
  1660. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1661. controlled by `org-use-tag-inheritance'. In other agenda types,
  1662. `org-use-tag-inheritance' is not used for the selection of the
  1663. agenda entries. Still, you may want the agenda to be aware of
  1664. the inherited tags anyway, e.g. for later tag filtering.
  1665. Allowed value are `todo', `search' and `agenda'.
  1666. This variable has no effect if `org-agenda-show-inherited-tags'
  1667. is set to `always'. In that case, the agenda is aware of those
  1668. tags.
  1669. The default value sets tags in every agenda type. Setting this
  1670. option to nil will speed up non-tags agenda view a lot."
  1671. :group 'org-agenda
  1672. :version "26.1"
  1673. :package-version '(Org . "9.1")
  1674. :type '(choice
  1675. (const :tag "Use tag inheritance in all agenda types" t)
  1676. (repeat :tag "Use tag inheritance in selected agenda types"
  1677. (symbol :tag "Agenda type"))))
  1678. (defcustom org-agenda-hide-tags-regexp nil
  1679. "Regular expression used to filter away specific tags in agenda views.
  1680. This means that these tags will be present, but not be shown in the agenda
  1681. line. Secondary filtering will still work on the hidden tags.
  1682. Nil means don't hide any tags."
  1683. :group 'org-agenda-line-format
  1684. :type '(choice
  1685. (const :tag "Hide none" nil)
  1686. (regexp :tag "Regexp ")))
  1687. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1688. 'org-agenda-remove-tags)
  1689. (defcustom org-agenda-remove-tags nil
  1690. "Non-nil means remove the tags from the headline copy in the agenda.
  1691. When this is the symbol `prefix', only remove tags when
  1692. `org-agenda-prefix-format' contains a `%T' specifier."
  1693. :group 'org-agenda-line-format
  1694. :type '(choice
  1695. (const :tag "Always" t)
  1696. (const :tag "Never" nil)
  1697. (const :tag "When prefix format contains %T" prefix)))
  1698. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1699. (defcustom org-agenda-tags-column 'auto
  1700. "Shift tags in agenda items to this column.
  1701. If set to `auto', tags will be automatically aligned to the right
  1702. edge of the window.
  1703. If set to a positive number, tags will be left-aligned to that
  1704. column. If set to a negative number, tags will be right-aligned
  1705. to that column. For example, -80 works well for a normal 80
  1706. character screen."
  1707. :group 'org-agenda-line-format
  1708. :type '(choice
  1709. (const :tag "Automatically align to right edge of window" auto)
  1710. (integer :tag "Specific column" -80))
  1711. :package-version '(Org . "9.1")
  1712. :version "26.1")
  1713. (defcustom org-agenda-fontify-priorities 'cookies
  1714. "Non-nil means highlight low and high priorities in agenda.
  1715. When t, the highest priority entries are bold, lowest priority italic.
  1716. However, settings in `org-priority-faces' will overrule these faces.
  1717. When this variable is the symbol `cookies', only fontify the
  1718. cookies, not the entire task.
  1719. This may also be an association list of priority faces, whose
  1720. keys are the character values of `org-priority-highest',
  1721. `org-priority-default', and `org-priority-lowest' (the default values
  1722. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1723. color as a string, or a list like `(:background \"Red\")'.
  1724. If it is a color, the variable `org-faces-easy-properties'
  1725. determines if it is a foreground or a background color."
  1726. :group 'org-agenda-line-format
  1727. :type '(choice
  1728. (const :tag "Never" nil)
  1729. (const :tag "Defaults" t)
  1730. (const :tag "Cookies only" cookies)
  1731. (repeat :tag "Specify"
  1732. (list (character :tag "Priority" :value ?A)
  1733. (choice :tag "Face "
  1734. (string :tag "Color")
  1735. (sexp :tag "Face"))))))
  1736. (defcustom org-agenda-day-face-function nil
  1737. "Function called to determine what face should be used to display a day.
  1738. The only argument passed to that function is the day. It should
  1739. returns a face, or nil if does not want to specify a face and let
  1740. the normal rules apply."
  1741. :group 'org-agenda-line-format
  1742. :version "24.1"
  1743. :type '(choice (const nil) (function)))
  1744. (defcustom org-agenda-category-icon-alist nil
  1745. "Alist of category icon to be displayed in agenda views.
  1746. Each entry should have the following format:
  1747. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1748. Where CATEGORY-REGEXP is a regexp matching the categories where
  1749. the icon should be displayed.
  1750. FILE-OR-DATA either a file path or a string containing image data.
  1751. The other fields can be omitted safely if not needed:
  1752. TYPE indicates the image type.
  1753. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1754. image data.
  1755. PROPS are additional image attributes to assign to the image,
  1756. like, e.g. `:ascent center'.
  1757. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1758. If you want to set the display properties yourself, just put a
  1759. list as second element:
  1760. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1761. For example, to display a 16px horizontal space for Emacs
  1762. category, you can use:
  1763. (\"Emacs\" \\='(space . (:width (16))))"
  1764. :group 'org-agenda-line-format
  1765. :version "24.1"
  1766. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1767. :value-type (choice (list :tag "Icon"
  1768. (string :tag "File or data")
  1769. (symbol :tag "Type")
  1770. (boolean :tag "Data?")
  1771. (repeat :tag "Extra image properties" :inline t sexp))
  1772. (list :tag "Display properties" sexp))))
  1773. (defgroup org-agenda-column-view nil
  1774. "Options concerning column view in the agenda."
  1775. :tag "Org Agenda Column View"
  1776. :group 'org-agenda)
  1777. (defcustom org-agenda-view-columns-initially nil
  1778. "When non-nil, switch to columns view right after creating the agenda."
  1779. :group 'org-agenda-column-view
  1780. :type 'boolean
  1781. :version "26.1"
  1782. :package-version '(Org . "9.0")
  1783. :safe #'booleanp)
  1784. (defcustom org-agenda-columns-show-summaries t
  1785. "Non-nil means show summaries for columns displayed in the agenda view."
  1786. :group 'org-agenda-column-view
  1787. :type 'boolean)
  1788. (defcustom org-agenda-columns-compute-summary-properties t
  1789. "Non-nil means recompute all summary properties before column view.
  1790. When column view in the agenda is listing properties that have a summary
  1791. operator, it can go to all relevant buffers and recompute the summaries
  1792. there. This can mean overhead for the agenda column view, but is necessary
  1793. to have thing up to date.
  1794. As a special case, a CLOCKSUM property also makes sure that the clock
  1795. computations are current."
  1796. :group 'org-agenda-column-view
  1797. :type 'boolean)
  1798. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1799. "Non-nil means the duration of an appointment will add to day effort.
  1800. The property to which appointment durations will be added is the one given
  1801. in the option `org-effort-property'. If an appointment does not have
  1802. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1803. is not set, an appointment without end time will not contribute to the time
  1804. estimate."
  1805. :group 'org-agenda-column-view
  1806. :type 'boolean)
  1807. (defcustom org-agenda-auto-exclude-function nil
  1808. "A function called with a tag to decide if it is filtered on \
  1809. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1810. The sole argument to the function, which is called once for each
  1811. possible tag, is a string giving the name of the tag. The
  1812. function should return either nil if the tag should be included
  1813. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1814. lines not carrying this tag.
  1815. Note that for the purpose of tag filtering, only the lower-case version of
  1816. all tags will be considered, so that this function will only ever see
  1817. the lower-case version of all tags."
  1818. :group 'org-agenda
  1819. :type '(choice (const nil) (function)))
  1820. (defcustom org-agenda-bulk-custom-functions nil
  1821. "Alist of characters and custom functions for bulk actions.
  1822. For example, this value makes those two functions available:
  1823. \\='((?R set-category)
  1824. (?C bulk-cut))
  1825. With selected entries in an agenda buffer, `B R' will call
  1826. the custom function `set-category' on the selected entries.
  1827. Note that functions in this alist don't need to be quoted.
  1828. You can also specify a function which collects arguments to be
  1829. used for each call to your bulk custom function. The argument
  1830. collecting function will be run once and should return a list of
  1831. arguments to pass to the bulk function. For example:
  1832. \\='((?R set-category get-category))
  1833. Now, `B R' will call the custom `get-category' which would prompt
  1834. the user once for a category. That category is then passed as an
  1835. argument to `set-category' for each entry it's called against."
  1836. :type
  1837. '(alist :key-type character
  1838. :value-type
  1839. (group (function :tag "Bulk Custom Function")
  1840. (choice (function :tag "Bulk Custom Argument Function")
  1841. (const :tag "No Bulk Custom Argument Function" nil))))
  1842. :package-version '(Org . "9.5")
  1843. :group 'org-agenda)
  1844. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1845. "Execute BODY with point at location given by `org-hd-marker' property.
  1846. If STRING is non-nil, the text property will be fetched from position 0
  1847. in that string. If STRING is nil, it will be fetched from the beginning
  1848. of the current line."
  1849. (declare (debug t))
  1850. (org-with-gensyms (marker)
  1851. `(let ((,marker (get-text-property (if ,string 0 (line-beginning-position))
  1852. 'org-hd-marker ,string)))
  1853. (with-current-buffer (marker-buffer ,marker)
  1854. (save-excursion
  1855. (goto-char ,marker)
  1856. ,@body)))))
  1857. (defun org-add-agenda-custom-command (entry)
  1858. "Replace or add a command in `org-agenda-custom-commands'.
  1859. This is mostly for hacking and trying a new command - once the command
  1860. works you probably want to add it to `org-agenda-custom-commands' for good."
  1861. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1862. (if ass
  1863. (setcdr ass (cdr entry))
  1864. (push entry org-agenda-custom-commands))))
  1865. (defmacro org-agenda--insert-overriding-header (default)
  1866. "Insert header into agenda view.
  1867. The inserted header depends on `org-agenda-overriding-header'.
  1868. If the empty string, don't insert a header. If any other string,
  1869. insert it as a header. If nil, insert DEFAULT, which should
  1870. evaluate to a string. If a function, call it and insert the
  1871. string that it returns."
  1872. (declare (debug (form)) (indent defun))
  1873. `(cond
  1874. ((not org-agenda-overriding-header) (insert ,default))
  1875. ((equal org-agenda-overriding-header "") nil)
  1876. ((stringp org-agenda-overriding-header)
  1877. (insert (propertize org-agenda-overriding-header
  1878. 'face 'org-agenda-structure)
  1879. "\n"))
  1880. ((functionp org-agenda-overriding-header)
  1881. (insert (funcall org-agenda-overriding-header)))
  1882. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1883. org-agenda-overriding-header))))
  1884. ;;; Define the org-agenda-mode
  1885. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1886. (defvar org-agenda-mode-map (make-sparse-keymap)
  1887. "Keymap for `org-agenda-mode'.")
  1888. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1889. (defvar org-agenda-menu) ; defined later in this file.
  1890. (defvar org-agenda-restrict nil)
  1891. (defvar org-agenda-follow-mode nil)
  1892. (defvar org-agenda-entry-text-mode nil)
  1893. (defvar org-agenda-clockreport-mode nil)
  1894. (defvar org-agenda-show-log nil
  1895. "When non-nil, show the log in the agenda.
  1896. Do not set this directly; instead use
  1897. `org-agenda-start-with-log-mode', which see.")
  1898. (defvar org-agenda-redo-command nil)
  1899. (defvar org-agenda-query-string nil)
  1900. (defvar org-agenda-mode-hook nil
  1901. "Hook run after `org-agenda-mode' is turned on.
  1902. The buffer is still writable when this hook is called.")
  1903. (defvar org-agenda-type nil)
  1904. (defvar org-agenda-force-single-file nil)
  1905. (defvar org-agenda-bulk-marked-entries nil
  1906. "List of markers that refer to marked entries in the agenda.")
  1907. (defvar org-agenda-current-date nil
  1908. "Active date when building the agenda.")
  1909. ;;; Multiple agenda buffers support
  1910. (defcustom org-agenda-sticky nil
  1911. "Non-nil means agenda q key will bury agenda buffers.
  1912. Agenda commands will then show existing buffer instead of generating new ones.
  1913. When nil, `q' will kill the single agenda buffer."
  1914. :group 'org-agenda
  1915. :version "24.3"
  1916. :type 'boolean)
  1917. ;;;###autoload
  1918. (defun org-toggle-sticky-agenda (&optional arg)
  1919. "Toggle `org-agenda-sticky'."
  1920. (interactive "P")
  1921. (let ((new-value (if arg
  1922. (> (prefix-numeric-value arg) 0)
  1923. (not org-agenda-sticky))))
  1924. (if (equal new-value org-agenda-sticky)
  1925. (and (called-interactively-p 'interactive)
  1926. (message "Sticky agenda was already %s"
  1927. (if org-agenda-sticky "enabled" "disabled")))
  1928. (setq org-agenda-sticky new-value)
  1929. (org-agenda-kill-all-agenda-buffers)
  1930. (and (called-interactively-p 'interactive)
  1931. (message "Sticky agenda %s"
  1932. (if org-agenda-sticky "enabled" "disabled"))))))
  1933. (defvar org-agenda-buffer nil
  1934. "Agenda buffer currently being generated.")
  1935. (defvar org-agenda-last-prefix-arg nil)
  1936. (defvar org-agenda-this-buffer-name nil)
  1937. (defvar org-agenda-doing-sticky-redo nil)
  1938. (defvar org-agenda-this-buffer-is-sticky nil)
  1939. (defvar org-agenda-last-indirect-buffer nil
  1940. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1941. (defconst org-agenda-local-vars
  1942. '(org-agenda-this-buffer-name
  1943. org-agenda-undo-list
  1944. org-agenda-pending-undo-list
  1945. org-agenda-follow-mode
  1946. org-agenda-entry-text-mode
  1947. org-agenda-clockreport-mode
  1948. org-agenda-show-log
  1949. org-agenda-redo-command
  1950. org-agenda-query-string
  1951. org-agenda-type
  1952. org-agenda-bulk-marked-entries
  1953. org-agenda-undo-has-started-in
  1954. org-agenda-info
  1955. org-agenda-pre-window-conf
  1956. org-agenda-columns-active
  1957. org-agenda-tag-filter
  1958. org-agenda-category-filter
  1959. org-agenda-top-headline-filter
  1960. org-agenda-regexp-filter
  1961. org-agenda-effort-filter
  1962. org-agenda-markers
  1963. org-agenda-last-search-view-search-was-boolean
  1964. org-agenda-last-indirect-buffer
  1965. org-agenda-filtered-by-category
  1966. org-agenda-filter-form
  1967. org-agenda-cycle-counter
  1968. org-agenda-last-prefix-arg)
  1969. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1970. (defun org-agenda-mode ()
  1971. "Mode for time-sorted view on action items in Org files.
  1972. The following commands are available:
  1973. \\{org-agenda-mode-map}"
  1974. (interactive)
  1975. (ignore-errors (require 'face-remap))
  1976. (let ((agenda-local-vars-to-keep
  1977. '(text-scale-mode-amount
  1978. text-scale-mode
  1979. text-scale-mode-lighter
  1980. face-remapping-alist))
  1981. (save (buffer-local-variables)))
  1982. (kill-all-local-variables)
  1983. (cl-flet ((reset-saved (var-set)
  1984. "Reset variables in VAR-SET to possibly stored value in SAVE."
  1985. (dolist (elem save)
  1986. (pcase elem
  1987. (`(,var . ,val) ;ignore unbound variables
  1988. (when (and val (memq var var-set))
  1989. (set var val)))))))
  1990. (cond (org-agenda-doing-sticky-redo
  1991. ;; Refreshing sticky agenda-buffer
  1992. ;;
  1993. ;; Preserve the value of `org-agenda-local-vars' variables.
  1994. (mapc #'make-local-variable org-agenda-local-vars)
  1995. (reset-saved org-agenda-local-vars)
  1996. (setq-local org-agenda-this-buffer-is-sticky t))
  1997. (org-agenda-sticky
  1998. ;; Creating a sticky Agenda buffer for the first time
  1999. (mapc #'make-local-variable org-agenda-local-vars)
  2000. (setq-local org-agenda-this-buffer-is-sticky t))
  2001. (t
  2002. ;; Creating a non-sticky agenda buffer
  2003. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2004. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2005. (reset-saved agenda-local-vars-to-keep)))
  2006. (setq org-agenda-undo-list nil
  2007. org-agenda-pending-undo-list nil
  2008. org-agenda-bulk-marked-entries nil)
  2009. (setq major-mode 'org-agenda-mode)
  2010. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2011. (setq-local font-lock-global-modes (list 'not major-mode))
  2012. (setq mode-name "Org-Agenda")
  2013. (setq indent-tabs-mode nil)
  2014. (use-local-map org-agenda-mode-map)
  2015. (when org-startup-truncated (setq truncate-lines t))
  2016. (setq-local line-move-visual nil)
  2017. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2018. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2019. ;; Make sure properties are removed when copying text
  2020. (if (boundp 'filter-buffer-substring-functions)
  2021. (add-hook 'filter-buffer-substring-functions
  2022. (lambda (fun start end delete)
  2023. (substring-no-properties (funcall fun start end delete)))
  2024. nil t)
  2025. ;; Emacs >= 24.4.
  2026. (add-function :filter-return (local 'filter-buffer-substring-function)
  2027. #'substring-no-properties))
  2028. (unless org-agenda-keep-modes
  2029. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2030. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2031. org-agenda-show-log org-agenda-start-with-log-mode
  2032. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2033. (add-to-invisibility-spec '(org-filtered))
  2034. (add-to-invisibility-spec '(org-link))
  2035. (easy-menu-change
  2036. '("Agenda") "Agenda Files"
  2037. (append
  2038. (list
  2039. (vector
  2040. (if (get 'org-agenda-files 'org-restrict)
  2041. "Restricted to single file"
  2042. "Edit File List")
  2043. '(org-edit-agenda-file-list)
  2044. (not (get 'org-agenda-files 'org-restrict)))
  2045. "--")
  2046. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2047. (org-agenda-set-mode-name)
  2048. (run-mode-hooks 'org-agenda-mode-hook))
  2049. (substitute-key-definition #'undo #'org-agenda-undo
  2050. org-agenda-mode-map global-map)
  2051. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2052. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2053. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2054. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2055. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2056. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2057. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2058. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2059. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2060. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2061. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2062. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2063. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2064. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2065. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2066. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2067. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2068. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2069. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2070. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2071. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2072. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2073. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2074. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2075. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2076. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2077. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2078. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2079. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2080. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2081. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2082. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2083. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2084. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2085. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2086. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2087. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2088. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2089. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2090. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2091. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2092. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2093. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2094. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2095. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2096. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2097. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2098. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2099. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2100. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2101. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2102. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2103. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2104. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2105. (while l (org-defkey org-agenda-mode-map
  2106. (number-to-string (pop l)) #'digit-argument)))
  2107. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2108. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2109. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2110. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2111. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2112. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2113. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2114. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2115. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2116. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2117. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2118. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2119. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2120. #'org-clock-modify-effort-estimate)
  2121. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2122. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2123. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2124. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2125. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2126. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2127. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2128. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2129. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2130. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2131. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2132. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2133. (substitute-key-definition #'next-line #'org-agenda-next-line
  2134. org-agenda-mode-map global-map)
  2135. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2136. org-agenda-mode-map global-map)
  2137. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2138. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2139. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2140. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2141. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2142. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2143. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2144. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2145. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2146. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2147. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2148. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2149. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2150. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2151. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2152. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2153. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2154. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2155. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2156. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2157. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2158. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2159. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2160. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2161. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2162. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2163. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2164. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2165. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2167. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2168. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2169. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2170. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2171. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2172. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2173. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2174. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2175. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2176. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2177. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2178. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2179. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2180. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2181. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2182. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2183. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2185. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2186. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2187. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2188. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2189. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2190. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2191. (when org-agenda-mouse-1-follows-link
  2192. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2193. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2194. '("Agenda"
  2195. ("Agenda Files")
  2196. "--"
  2197. ("Agenda Dates"
  2198. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2199. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2200. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2201. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2202. "--"
  2203. ("View"
  2204. ["Day View" org-agenda-day-view
  2205. :active (org-agenda-check-type nil 'agenda)
  2206. :style radio :selected (eq org-agenda-current-span 'day)
  2207. :keys "v d (or just d)"]
  2208. ["Week View" org-agenda-week-view
  2209. :active (org-agenda-check-type nil 'agenda)
  2210. :style radio :selected (eq org-agenda-current-span 'week)
  2211. :keys "v w"]
  2212. ["Fortnight View" org-agenda-fortnight-view
  2213. :active (org-agenda-check-type nil 'agenda)
  2214. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2215. :keys "v t"]
  2216. ["Month View" org-agenda-month-view
  2217. :active (org-agenda-check-type nil 'agenda)
  2218. :style radio :selected (eq org-agenda-current-span 'month)
  2219. :keys "v m"]
  2220. ["Year View" org-agenda-year-view
  2221. :active (org-agenda-check-type nil 'agenda)
  2222. :style radio :selected (eq org-agenda-current-span 'year)
  2223. :keys "v y"]
  2224. "--"
  2225. ["Include Diary" org-agenda-toggle-diary
  2226. :style toggle :selected org-agenda-include-diary
  2227. :active (org-agenda-check-type nil 'agenda)]
  2228. ["Include Deadlines" org-agenda-toggle-deadlines
  2229. :style toggle :selected org-agenda-include-deadlines
  2230. :active (org-agenda-check-type nil 'agenda)]
  2231. ["Use Time Grid" org-agenda-toggle-time-grid
  2232. :style toggle :selected org-agenda-use-time-grid
  2233. :active (org-agenda-check-type nil 'agenda)]
  2234. "--"
  2235. ["Show clock report" org-agenda-clockreport-mode
  2236. :style toggle :selected org-agenda-clockreport-mode
  2237. :active (org-agenda-check-type nil 'agenda)]
  2238. ["Show some entry text" org-agenda-entry-text-mode
  2239. :style toggle :selected org-agenda-entry-text-mode
  2240. :active t]
  2241. "--"
  2242. ["Show Logbook entries" org-agenda-log-mode
  2243. :style toggle :selected org-agenda-show-log
  2244. :active (org-agenda-check-type nil 'agenda)
  2245. :keys "v l (or just l)"]
  2246. ["Include archived trees" org-agenda-archives-mode
  2247. :style toggle :selected org-agenda-archives-mode :active t
  2248. :keys "v a"]
  2249. ["Include archive files" (org-agenda-archives-mode t)
  2250. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2251. :keys "v A"]
  2252. "--"
  2253. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2254. ("Filter current view"
  2255. ["with generic interface" org-agenda-filter t]
  2256. "--"
  2257. ["by category at cursor" org-agenda-filter-by-category t]
  2258. ["by tag" org-agenda-filter-by-tag t]
  2259. ["by effort" org-agenda-filter-by-effort t]
  2260. ["by regexp" org-agenda-filter-by-regexp t]
  2261. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2262. "--"
  2263. ["Remove all filtering" org-agenda-filter-remove-all t]
  2264. "--"
  2265. ["limit" org-agenda-limit-interactively t])
  2266. ["Rebuild buffer" org-agenda-redo t]
  2267. ["Write view to file" org-agenda-write t]
  2268. ["Save all Org buffers" org-save-all-org-buffers t]
  2269. "--"
  2270. ["Show original entry" org-agenda-show t]
  2271. ["Go To (other window)" org-agenda-goto t]
  2272. ["Go To (this window)" org-agenda-switch-to t]
  2273. ["Capture with cursor date" org-agenda-capture t]
  2274. ["Follow Mode" org-agenda-follow-mode
  2275. :style toggle :selected org-agenda-follow-mode :active t]
  2276. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2277. "--"
  2278. ("TODO"
  2279. ["Cycle TODO" org-agenda-todo t]
  2280. ["Next TODO set" org-agenda-todo-nextset t]
  2281. ["Previous TODO set" org-agenda-todo-previousset t]
  2282. ["Add note" org-agenda-add-note t])
  2283. ("Archive/Refile/Delete"
  2284. ["Archive default" org-agenda-archive-default t]
  2285. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2286. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2287. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2288. ["Archive subtree" org-agenda-archive t]
  2289. "--"
  2290. ["Refile" org-agenda-refile t]
  2291. "--"
  2292. ["Delete subtree" org-agenda-kill t])
  2293. ("Bulk action"
  2294. ["Mark entry" org-agenda-bulk-mark t]
  2295. ["Mark all" org-agenda-bulk-mark-all t]
  2296. ["Unmark entry" org-agenda-bulk-unmark t]
  2297. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2298. ["Toggle mark" org-agenda-bulk-toggle t]
  2299. ["Toggle all" org-agenda-bulk-toggle-all t]
  2300. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2301. ["Act on all marked" org-agenda-bulk-action t]
  2302. "--"
  2303. ("Tags and Properties"
  2304. ["Show all Tags" org-agenda-show-tags t]
  2305. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2306. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2307. "--"
  2308. ["Column View" org-columns t])
  2309. ("Deadline/Schedule"
  2310. ["Schedule" org-agenda-schedule t]
  2311. ["Set Deadline" org-agenda-deadline t]
  2312. "--"
  2313. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2314. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2315. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2316. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2317. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2318. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2319. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2320. ("Clock and Effort"
  2321. ["Clock in" org-agenda-clock-in t]
  2322. ["Clock out" org-agenda-clock-out t]
  2323. ["Clock cancel" org-agenda-clock-cancel t]
  2324. ["Goto running clock" org-clock-goto t]
  2325. "--"
  2326. ["Set Effort" org-agenda-set-effort t]
  2327. ["Change clocked effort" org-clock-modify-effort-estimate
  2328. (org-clock-is-active)])
  2329. ("Priority"
  2330. ["Set Priority" org-agenda-priority t]
  2331. ["Increase Priority" org-agenda-priority-up t]
  2332. ["Decrease Priority" org-agenda-priority-down t]
  2333. ["Show Priority" org-priority-show t])
  2334. ("Calendar/Diary"
  2335. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2336. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2337. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2338. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2339. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2340. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2341. "--"
  2342. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2343. "--"
  2344. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2345. "--"
  2346. ("MobileOrg"
  2347. ["Push Files and Views" org-mobile-push t]
  2348. ["Get Captured and Flagged" org-mobile-pull t]
  2349. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2350. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2351. "--"
  2352. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2353. "--"
  2354. ["Quit" org-agenda-quit t]
  2355. ["Exit and Release Buffers" org-agenda-exit t]
  2356. ))
  2357. ;;; Agenda undo
  2358. (defvar org-agenda-allow-remote-undo t
  2359. "Non-nil means allow remote undo from the agenda buffer.")
  2360. (defvar org-agenda-undo-has-started-in nil
  2361. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2362. (defun org-agenda-undo ()
  2363. "Undo a remote editing step in the agenda.
  2364. This undoes changes both in the agenda buffer and in the remote buffer
  2365. that have been changed along."
  2366. (interactive)
  2367. (or org-agenda-allow-remote-undo
  2368. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2369. (when (not (eq this-command last-command))
  2370. (setq org-agenda-undo-has-started-in nil
  2371. org-agenda-pending-undo-list org-agenda-undo-list))
  2372. (when (not org-agenda-pending-undo-list)
  2373. (user-error "No further undo information"))
  2374. (let* ((entry (pop org-agenda-pending-undo-list))
  2375. buf line cmd rembuf)
  2376. (setq cmd (pop entry) line (pop entry))
  2377. (setq rembuf (nth 2 entry))
  2378. (org-with-remote-undo rembuf
  2379. (while (bufferp (setq buf (pop entry)))
  2380. (when (pop entry)
  2381. (with-current-buffer buf
  2382. (let (;; (last-undo-buffer buf)
  2383. (inhibit-read-only t))
  2384. (unless (memq buf org-agenda-undo-has-started-in)
  2385. (push buf org-agenda-undo-has-started-in)
  2386. (make-local-variable 'pending-undo-list)
  2387. (undo-start))
  2388. (while (and pending-undo-list
  2389. (listp pending-undo-list)
  2390. (not (car pending-undo-list)))
  2391. (pop pending-undo-list))
  2392. (undo-more 1))))))
  2393. (org-goto-line line)
  2394. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2395. (defun org-verify-change-for-undo (l1 l2)
  2396. "Verify that a real change occurred between the undo lists L1 and L2."
  2397. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2398. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2399. (not (eq l1 l2)))
  2400. ;;; Agenda dispatch
  2401. (defvar org-agenda-restrict-begin (make-marker))
  2402. (defvar org-agenda-restrict-end (make-marker))
  2403. (defvar org-agenda-last-dispatch-buffer nil)
  2404. (defvar org-agenda-overriding-restriction nil)
  2405. (defcustom org-agenda-custom-commands-contexts nil
  2406. "Alist of custom agenda keys and contextual rules.
  2407. For example, if you have a custom agenda command \"p\" and you
  2408. want this command to be accessible only from plain text files,
  2409. use this:
  2410. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2411. Here are the available contexts definitions:
  2412. in-file: command displayed only in matching files
  2413. in-mode: command displayed only in matching modes
  2414. not-in-file: command not displayed in matching files
  2415. not-in-mode: command not displayed in matching modes
  2416. in-buffer: command displayed only in matching buffers
  2417. not-in-buffer: command not displayed in matching buffers
  2418. [function]: a custom function taking no argument
  2419. If you define several checks, the agenda command will be
  2420. accessible if there is at least one valid check.
  2421. You can also bind a key to another agenda custom command
  2422. depending on contextual rules.
  2423. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2424. Here it means: in .txt files, use \"p\" as the key for the
  2425. agenda command otherwise associated with \"q\". (The command
  2426. originally associated with \"q\" is not displayed to avoid
  2427. duplicates.)"
  2428. :version "24.3"
  2429. :group 'org-agenda-custom-commands
  2430. :type '(repeat (list :tag "Rule"
  2431. (string :tag " Agenda key")
  2432. (string :tag "Replace by command")
  2433. (repeat :tag "Available when"
  2434. (choice
  2435. (cons :tag "Condition"
  2436. (choice
  2437. (const :tag "In file" in-file)
  2438. (const :tag "Not in file" not-in-file)
  2439. (const :tag "In buffer" in-buffer)
  2440. (const :tag "Not in buffer" not-in-buffer)
  2441. (const :tag "In mode" in-mode)
  2442. (const :tag "Not in mode" not-in-mode))
  2443. (regexp))
  2444. (function :tag "Custom function"))))))
  2445. (defcustom org-agenda-max-entries nil
  2446. "Maximum number of entries to display in an agenda.
  2447. This can be nil (no limit) or an integer or an alist of agenda
  2448. types with an associated number of entries to display in this
  2449. type."
  2450. :version "24.4"
  2451. :package-version '(Org . "8.0")
  2452. :group 'org-agenda-custom-commands
  2453. :type '(choice (symbol :tag "No limit" nil)
  2454. (integer :tag "Max number of entries")
  2455. (repeat
  2456. (cons (choice :tag "Agenda type"
  2457. (const agenda)
  2458. (const todo)
  2459. (const tags)
  2460. (const search))
  2461. (integer :tag "Max number of entries")))))
  2462. (defcustom org-agenda-max-todos nil
  2463. "Maximum number of TODOs 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 TODOs")
  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 TODOs")))))
  2479. (defcustom org-agenda-max-tags nil
  2480. "Maximum number of tagged entries 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 tagged entries")
  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 tagged entries")))))
  2496. (defcustom org-agenda-max-effort nil
  2497. "Maximum cumulated effort duration for the agenda.
  2498. This can be nil (no limit) or a number of minutes (as an integer)
  2499. or an alist of agenda types with an associated number of minutes
  2500. to limit entries to in this 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 minutes")
  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 minutes")))))
  2513. (defvar org-agenda-keep-restricted-file-list nil)
  2514. (defvar org-keys nil)
  2515. (defvar org-match nil)
  2516. ;;;###autoload
  2517. (defun org-agenda (&optional arg keys restriction)
  2518. "Dispatch agenda commands to collect entries to the agenda buffer.
  2519. Prompts for a command to execute. Any prefix arg will be passed
  2520. on to the selected command. The default selections are:
  2521. a Call `org-agenda-list' to display the agenda for current day or week.
  2522. t Call `org-todo-list' to display the global todo list.
  2523. T Call `org-todo-list' to display the global todo list, select only
  2524. entries with a specific TODO keyword (the user gets a prompt).
  2525. m Call `org-tags-view' to display headlines with tags matching
  2526. a condition (the user is prompted for the condition).
  2527. M Like `m', but select only TODO entries, no ordinary headlines.
  2528. e Export views to associated files.
  2529. s Search entries for keywords.
  2530. S Search entries for keywords, only with TODO keywords.
  2531. / Multi occur across all agenda files and also files listed
  2532. in `org-agenda-text-search-extra-files'.
  2533. < Restrict agenda commands to buffer, subtree, or region.
  2534. Press several times to get the desired effect.
  2535. > Remove a previous restriction.
  2536. # List \"stuck\" projects.
  2537. ! Configure what \"stuck\" means.
  2538. C Configure custom agenda commands.
  2539. More commands can be added by configuring the variable
  2540. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2541. searches can be pre-defined in this way.
  2542. If the current buffer is in Org mode and visiting a file, you can also
  2543. first press `<' once to indicate that the agenda should be temporarily
  2544. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2545. Pressing `<' twice means to restrict to the current subtree or region
  2546. \(if active)."
  2547. (interactive "P")
  2548. (catch 'exit
  2549. (let* ((org-keys keys)
  2550. (prefix-descriptions nil)
  2551. (org-agenda-buffer-name org-agenda-buffer-name)
  2552. (org-agenda-window-setup (if (equal (buffer-name)
  2553. org-agenda-buffer-name)
  2554. 'current-window
  2555. org-agenda-window-setup))
  2556. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2557. (org-agenda-custom-commands
  2558. ;; normalize different versions
  2559. (delq nil
  2560. (mapcar
  2561. (lambda (x)
  2562. (cond ((stringp (cdr x))
  2563. (push x prefix-descriptions)
  2564. nil)
  2565. ((stringp (nth 1 x)) x)
  2566. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2567. (t (cons (car x) (cons "" (cdr x))))))
  2568. org-agenda-custom-commands)))
  2569. (org-agenda-custom-commands
  2570. (org-contextualize-keys
  2571. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2572. ;; (buf (current-buffer))
  2573. (bfn (buffer-file-name (buffer-base-buffer)))
  2574. entry type org-match lprops ans) ;; key
  2575. ;; Turn off restriction unless there is an overriding one,
  2576. (unless org-agenda-overriding-restriction
  2577. (unless org-agenda-keep-restricted-file-list
  2578. ;; There is a request to keep the file list in place
  2579. (put 'org-agenda-files 'org-restrict nil))
  2580. (setq org-agenda-restrict nil)
  2581. (move-marker org-agenda-restrict-begin nil)
  2582. (move-marker org-agenda-restrict-end nil))
  2583. ;; Delete old local properties
  2584. (put 'org-agenda-redo-command 'org-lprops nil)
  2585. ;; Delete previously set last-arguments
  2586. (put 'org-agenda-redo-command 'last-args nil)
  2587. ;; Remember where this call originated
  2588. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2589. (unless org-keys
  2590. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2591. org-keys (car ans)
  2592. restriction (cdr ans)))
  2593. ;; If we have sticky agenda buffers, set a name for the buffer,
  2594. ;; depending on the invoking keys. The user may still set this
  2595. ;; as a command option, which will overwrite what we do here.
  2596. (when org-agenda-sticky
  2597. (setq org-agenda-buffer-name
  2598. (format "*Org Agenda(%s)*" org-keys)))
  2599. ;; Establish the restriction, if any
  2600. (when (and (not org-agenda-overriding-restriction) restriction)
  2601. (put 'org-agenda-files 'org-restrict (list bfn))
  2602. (cond
  2603. ((eq restriction 'region)
  2604. (setq org-agenda-restrict (current-buffer))
  2605. (move-marker org-agenda-restrict-begin (region-beginning))
  2606. (move-marker org-agenda-restrict-end (region-end)))
  2607. ((eq restriction 'subtree)
  2608. (save-excursion
  2609. (setq org-agenda-restrict (current-buffer))
  2610. (org-back-to-heading t)
  2611. (move-marker org-agenda-restrict-begin (point))
  2612. (move-marker org-agenda-restrict-end
  2613. (progn (org-end-of-subtree t)))))
  2614. ((and (eq restriction 'buffer)
  2615. (or (< 1 (point-min))
  2616. (< (point-max) (1+ (buffer-size)))))
  2617. (setq org-agenda-restrict (current-buffer))
  2618. (move-marker org-agenda-restrict-begin (point-min))
  2619. (move-marker org-agenda-restrict-end (point-max)))))
  2620. ;; For example the todo list should not need it (but does...)
  2621. (cond
  2622. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2623. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2624. (progn
  2625. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2626. ;; to some of the local variables? There's no doc about
  2627. ;; that for `org-agenda-custom-commands'.
  2628. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2629. lprops (nth 4 entry))
  2630. (when org-agenda-sticky
  2631. (setq org-agenda-buffer-name
  2632. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2633. (format "*Org Agenda(%s)*" org-keys))))
  2634. (put 'org-agenda-redo-command 'org-lprops lprops)
  2635. (cl-progv
  2636. (mapcar #'car lprops)
  2637. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2638. (pcase type
  2639. (`agenda
  2640. (org-agenda-list current-prefix-arg))
  2641. (`agenda*
  2642. (org-agenda-list current-prefix-arg nil nil t))
  2643. (`alltodo
  2644. (org-todo-list current-prefix-arg))
  2645. (`search
  2646. (org-search-view current-prefix-arg org-match nil))
  2647. (`stuck
  2648. (org-agenda-list-stuck-projects current-prefix-arg))
  2649. (`tags
  2650. (org-tags-view current-prefix-arg org-match))
  2651. (`tags-todo
  2652. (org-tags-view '(4) org-match))
  2653. (`todo
  2654. (org-todo-list org-match))
  2655. (`tags-tree
  2656. (org-check-for-org-mode)
  2657. (org-match-sparse-tree current-prefix-arg org-match))
  2658. (`todo-tree
  2659. (org-check-for-org-mode)
  2660. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2661. (regexp-quote org-match) "\\>")))
  2662. (`occur-tree
  2663. (org-check-for-org-mode)
  2664. (org-occur org-match))
  2665. ((pred functionp)
  2666. (funcall type org-match))
  2667. ;; FIXME: Will signal an error since it's not `functionp'!
  2668. ((pred fboundp) (funcall type org-match))
  2669. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2670. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2671. ((equal org-keys "C")
  2672. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2673. (customize-variable 'org-agenda-custom-commands))
  2674. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2675. ((equal org-keys "s") (call-interactively 'org-search-view))
  2676. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2677. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2678. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2679. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2680. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2681. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2682. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2683. (add-hook
  2684. 'post-command-hook
  2685. (lambda ()
  2686. (unless (current-message)
  2687. (let* ((m (org-agenda-get-any-marker))
  2688. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2689. (when note
  2690. (message "FLAGGING-NOTE ([?] for more info): %s"
  2691. (org-add-props
  2692. (replace-regexp-in-string
  2693. "\\\\n" "//"
  2694. (copy-sequence note))
  2695. nil 'face 'org-warning))))))
  2696. t t))
  2697. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2698. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2699. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2700. (t (user-error "Invalid agenda key"))))))
  2701. (defvar org-agenda-multi)
  2702. (defun org-agenda-append-agenda ()
  2703. "Append another agenda view to the current one.
  2704. This function allows interactive building of block agendas.
  2705. Agenda views are separated by `org-agenda-block-separator'."
  2706. (interactive)
  2707. (unless (derived-mode-p 'org-agenda-mode)
  2708. (user-error "Can only append from within agenda buffer"))
  2709. (let ((org-agenda-multi t))
  2710. (org-agenda)
  2711. (widen)
  2712. (org-agenda-finalize)
  2713. (setq buffer-read-only t)
  2714. (org-agenda-fit-window-to-buffer)))
  2715. (defun org-agenda-normalize-custom-commands (cmds)
  2716. "Normalize custom commands CMDS."
  2717. (delq nil
  2718. (mapcar
  2719. (lambda (x)
  2720. (cond ((stringp (cdr x)) nil)
  2721. ((stringp (nth 1 x)) x)
  2722. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2723. (t (cons (car x) (cons "" (cdr x))))))
  2724. cmds)))
  2725. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2726. "The user interface for selecting an agenda command."
  2727. (catch 'exit
  2728. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2729. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2730. (region-p (org-region-active-p))
  2731. (custom org-agenda-custom-commands)
  2732. (selstring "")
  2733. restriction second-time
  2734. c entry key type match prefixes rmheader header-end custom1 desc
  2735. line lines left right n n1)
  2736. (save-window-excursion
  2737. (delete-other-windows)
  2738. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2739. (erase-buffer)
  2740. (insert (eval-when-compile
  2741. (let ((header
  2742. (copy-sequence
  2743. "Press key for an agenda command:
  2744. -------------------------------- < Buffer, subtree/region restriction
  2745. a Agenda for current week or day > Remove restriction
  2746. t List of all TODO entries e Export agenda views
  2747. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2748. s Search for keywords M Like m, but only TODO entries
  2749. / Multi-occur S Like s, but only TODO entries
  2750. ? Find :FLAGGED: entries C Configure custom agenda commands
  2751. * Toggle sticky agenda views # List stuck projects (!=configure)
  2752. "))
  2753. (start 0))
  2754. (while (string-match
  2755. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2756. header start)
  2757. (setq start (match-end 0))
  2758. (add-text-properties (match-beginning 2) (match-end 2)
  2759. '(face bold) header))
  2760. header)))
  2761. (setq header-end (point-marker))
  2762. (while t
  2763. (setq custom1 custom)
  2764. (when (eq rmheader t)
  2765. (org-goto-line 1)
  2766. (re-search-forward ":" nil t)
  2767. (delete-region (match-end 0) (line-end-position))
  2768. (forward-char 1)
  2769. (looking-at "-+")
  2770. (delete-region (match-end 0) (line-end-position))
  2771. (move-marker header-end (match-end 0)))
  2772. (goto-char header-end)
  2773. (delete-region (point) (point-max))
  2774. ;; Produce all the lines that describe custom commands and prefixes
  2775. (setq lines nil)
  2776. (while (setq entry (pop custom1))
  2777. (setq key (car entry) desc (nth 1 entry)
  2778. type (nth 2 entry)
  2779. match (nth 3 entry))
  2780. (if (> (length key) 1)
  2781. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2782. (setq line
  2783. (format
  2784. "%-4s%-14s"
  2785. (org-add-props (copy-sequence key)
  2786. '(face bold))
  2787. (cond
  2788. ((string-match "\\S-" desc) desc)
  2789. ((eq type 'agenda) "Agenda for current week or day")
  2790. ((eq type 'agenda*) "Appointments for current week or day")
  2791. ((eq type 'alltodo) "List of all TODO entries")
  2792. ((eq type 'search) "Word search")
  2793. ((eq type 'stuck) "List of stuck projects")
  2794. ((eq type 'todo) "TODO keyword")
  2795. ((eq type 'tags) "Tags query")
  2796. ((eq type 'tags-todo) "Tags (TODO)")
  2797. ((eq type 'tags-tree) "Tags tree")
  2798. ((eq type 'todo-tree) "TODO kwd tree")
  2799. ((eq type 'occur-tree) "Occur tree")
  2800. ((functionp type) (if (symbolp type)
  2801. (symbol-name type)
  2802. "Lambda expression"))
  2803. (t "???"))))
  2804. (cond
  2805. ((not (org-string-nw-p match)) nil)
  2806. (org-agenda-menu-show-matcher
  2807. (setq line
  2808. (concat line ": "
  2809. (cond
  2810. ((stringp match)
  2811. (propertize match 'face 'org-warning))
  2812. ((listp type)
  2813. (format "set of %d commands" (length type)))))))
  2814. (t
  2815. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2816. (push line lines)))
  2817. (setq lines (nreverse lines))
  2818. (when prefixes
  2819. (mapc (lambda (x)
  2820. (push
  2821. (format "%s %s"
  2822. (org-add-props (char-to-string x)
  2823. nil 'face 'bold)
  2824. (or (cdr (assoc (concat selstring
  2825. (char-to-string x))
  2826. prefix-descriptions))
  2827. "Prefix key"))
  2828. lines))
  2829. prefixes))
  2830. ;; Check if we should display in two columns
  2831. (if org-agenda-menu-two-columns
  2832. (progn
  2833. (setq n (length lines)
  2834. n1 (+ (/ n 2) (mod n 2))
  2835. right (nthcdr n1 lines)
  2836. left (copy-sequence lines))
  2837. (setcdr (nthcdr (1- n1) left) nil))
  2838. (setq left lines right nil))
  2839. (while left
  2840. (insert "\n" (pop left))
  2841. (when right
  2842. (if (< (current-column) 40)
  2843. (move-to-column 40 t)
  2844. (insert " "))
  2845. (insert (pop right))))
  2846. ;; Make the window the right size
  2847. (goto-char (point-min))
  2848. (if second-time
  2849. (when (not (pos-visible-in-window-p (point-max)))
  2850. (org-fit-window-to-buffer))
  2851. (setq second-time t)
  2852. (org-fit-window-to-buffer))
  2853. ;; Hint to navigation if window too small for all information
  2854. (setq header-line-format
  2855. (when (not (pos-visible-in-window-p (point-max)))
  2856. "Use C-v, M-v, C-n or C-p to navigate."))
  2857. ;; Ask for selection
  2858. (cl-loop
  2859. do (progn
  2860. (message "Press key for agenda command%s:"
  2861. (if (or restrict-ok org-agenda-overriding-restriction)
  2862. (if org-agenda-overriding-restriction
  2863. " (restriction lock active)"
  2864. (if restriction
  2865. (format " (restricted to %s)" restriction)
  2866. " (unrestricted)"))
  2867. ""))
  2868. (setq c (read-char-exclusive)))
  2869. until (not (memq c '(14 16 22 134217846)))
  2870. do (org-scroll c))
  2871. (message "")
  2872. (cond
  2873. ((assoc (char-to-string c) custom)
  2874. (setq selstring (concat selstring (char-to-string c)))
  2875. (throw 'exit (cons selstring restriction)))
  2876. ((memq c prefixes)
  2877. (setq selstring (concat selstring (char-to-string c))
  2878. prefixes nil
  2879. rmheader (or rmheader t)
  2880. custom (delq nil (mapcar
  2881. (lambda (x)
  2882. (if (or (= (length (car x)) 1)
  2883. (/= (string-to-char (car x)) c))
  2884. nil
  2885. (cons (substring (car x) 1) (cdr x))))
  2886. custom))))
  2887. ((eq c ?*)
  2888. (call-interactively 'org-toggle-sticky-agenda)
  2889. (sit-for 2))
  2890. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2891. (message "Restriction is only possible in Org buffers")
  2892. (ding) (sit-for 1))
  2893. ((eq c ?1)
  2894. (org-agenda-remove-restriction-lock 'noupdate)
  2895. (setq restriction 'buffer))
  2896. ((eq c ?0)
  2897. (org-agenda-remove-restriction-lock 'noupdate)
  2898. (setq restriction (if region-p 'region 'subtree)))
  2899. ((eq c ?<)
  2900. (org-agenda-remove-restriction-lock 'noupdate)
  2901. (setq restriction
  2902. (cond
  2903. ((eq restriction 'buffer)
  2904. (if region-p 'region 'subtree))
  2905. ((memq restriction '(subtree region))
  2906. nil)
  2907. (t 'buffer))))
  2908. ((eq c ?>)
  2909. (org-agenda-remove-restriction-lock 'noupdate)
  2910. (setq restriction nil))
  2911. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2912. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2913. ((and (> (length selstring) 0) (eq c ?\d))
  2914. (delete-window)
  2915. (org-agenda-get-restriction-and-command prefix-descriptions))
  2916. ((equal c ?q) (user-error "Abort"))
  2917. (t (user-error "Invalid key %c" c))))))))
  2918. (defun org-agenda-fit-window-to-buffer ()
  2919. "Fit the window to the buffer size."
  2920. (and (memq org-agenda-window-setup '(reorganize-frame))
  2921. (fboundp 'fit-window-to-buffer)
  2922. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2923. (= (car org-agenda-window-frame-fractions) 1.0))
  2924. (delete-other-windows)
  2925. (org-fit-window-to-buffer
  2926. nil
  2927. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2928. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2929. (defvar org-cmd nil)
  2930. (defvar org-agenda-overriding-cmd nil)
  2931. (defvar org-agenda-overriding-arguments nil)
  2932. (defvar org-agenda-overriding-cmd-arguments nil)
  2933. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2934. (declare (indent 1) (obsolete cl-progv "2021"))
  2935. (eval (cons 'let (cons list body))))
  2936. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2937. (declare (indent 2) (obsolete cl-progv "2021"))
  2938. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2939. (defun org-agenda-run-series (name series)
  2940. "Run agenda NAME as a SERIES of agenda commands."
  2941. (let* ((gprops (nth 1 series))
  2942. (gvars (mapcar #'car gprops))
  2943. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2944. (cl-progv gvars gvals (org-agenda-prepare name))
  2945. ;; We need to reset agenda markers here, because when constructing a
  2946. ;; block agenda, the individual blocks do not do that.
  2947. (org-agenda-reset-markers)
  2948. (with-no-warnings
  2949. (defvar match)) ;Used via the `eval' below.
  2950. (let* ((org-agenda-multi t)
  2951. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2952. ;; than expressions, so you don't need to `quote' the args
  2953. ;; and you just need to `apply' instead of `eval' when using it.
  2954. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2955. (cmds (car series))
  2956. match
  2957. org-cmd type lprops)
  2958. (while (setq org-cmd (pop cmds))
  2959. (setq type (car org-cmd))
  2960. (setq match (eval (nth 1 org-cmd) t))
  2961. (setq lprops (nth 2 org-cmd))
  2962. (let ((org-agenda-overriding-arguments
  2963. (if (eq org-agenda-overriding-cmd org-cmd)
  2964. (or org-agenda-overriding-arguments
  2965. org-agenda-overriding-cmd-arguments)))
  2966. (lvars (mapcar #'car lprops))
  2967. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  2968. (cl-progv (append gvars lvars) (append gvals lvals)
  2969. (pcase type
  2970. (`agenda
  2971. (call-interactively 'org-agenda-list))
  2972. (`agenda*
  2973. (funcall 'org-agenda-list nil nil t))
  2974. (`alltodo
  2975. (call-interactively 'org-todo-list))
  2976. (`search
  2977. (org-search-view current-prefix-arg match nil))
  2978. (`stuck
  2979. (call-interactively 'org-agenda-list-stuck-projects))
  2980. (`tags
  2981. (org-tags-view current-prefix-arg match))
  2982. (`tags-todo
  2983. (org-tags-view '(4) match))
  2984. (`todo
  2985. (org-todo-list match))
  2986. ((pred fboundp)
  2987. (funcall type match))
  2988. (_ (error "Invalid type in command series"))))))
  2989. (widen)
  2990. (let ((inhibit-read-only t))
  2991. (add-text-properties (point-min) (point-max)
  2992. `(org-series t org-series-redo-cmd ,redo)))
  2993. (setq org-agenda-redo-command redo)
  2994. (goto-char (point-min)))
  2995. (org-agenda-fit-window-to-buffer)
  2996. (cl-progv gvars gvals (org-agenda-finalize))))
  2997. (defun org-agenda--split-plist (plist)
  2998. ;; We could/should arguably use `map-keys' and `map-values'.
  2999. (let (keys vals)
  3000. (while plist
  3001. (push (pop plist) keys)
  3002. (push (pop plist) vals))
  3003. (cons (nreverse keys) (nreverse vals))))
  3004. ;;;###autoload
  3005. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3006. "Run an agenda command in batch mode and send the result to STDOUT.
  3007. If CMD-KEY is a string of length 1, it is used as a key in
  3008. `org-agenda-custom-commands' and triggers this command. If it is a
  3009. longer string it is used as a tags/todo match string.
  3010. Parameters are alternating variable names and values that will be bound
  3011. before running the agenda command."
  3012. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3013. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3014. (defun org--batch-agenda (cmd-key vars vals)
  3015. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3016. ;; a variable name rather than an expression to evaluate. Yuck!
  3017. (cl-progv vars vals
  3018. (let (org-agenda-sticky)
  3019. (if (> (length cmd-key) 1)
  3020. (org-tags-view nil cmd-key)
  3021. (org-agenda nil cmd-key))))
  3022. (set-buffer org-agenda-buffer-name)
  3023. (princ (buffer-string)))
  3024. (defvar org-agenda-info nil)
  3025. ;;;###autoload
  3026. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3027. "Run an agenda command in batch mode and send the result to STDOUT.
  3028. If CMD-KEY is a string of length 1, it is used as a key in
  3029. `org-agenda-custom-commands' and triggers this command. If it is a
  3030. longer string it is used as a tags/todo match string.
  3031. Parameters are alternating variable names and values that will be bound
  3032. before running the agenda command.
  3033. The output gives a line for each selected agenda item. Each
  3034. item is a list of comma-separated values, like this:
  3035. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3036. category The category of the item
  3037. head The headline, without TODO kwd, TAGS and PRIORITY
  3038. type The type of the agenda entry, can be
  3039. todo selected in TODO match
  3040. tagsmatch selected in tags match
  3041. diary imported from diary
  3042. deadline a deadline on given date
  3043. scheduled scheduled on given date
  3044. timestamp entry has timestamp on given date
  3045. closed entry was closed on given date
  3046. upcoming-deadline warning about deadline
  3047. past-scheduled forwarded scheduled item
  3048. block entry has date block including g. date
  3049. todo The todo keyword, if any
  3050. tags All tags including inherited ones, separated by colons
  3051. date The relevant date, like 2007-2-14
  3052. time The time, like 15:00-16:50
  3053. extra String with extra planning info
  3054. priority-l The priority letter if any was given
  3055. priority-n The computed numerical priority
  3056. agenda-day The day in the agenda where this is listed"
  3057. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3058. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3059. (defun org--batch-agenda-csv (cmd-key vars vals)
  3060. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3061. ;; a variable name rather than an expression to evaluate. Yuck!
  3062. (let ((org-agenda-remove-tags t))
  3063. (cl-progv vars vals
  3064. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3065. (if (> (length cmd-key) 2)
  3066. (org-tags-view nil cmd-key)
  3067. (org-agenda nil cmd-key))))
  3068. (set-buffer org-agenda-buffer-name)
  3069. (let ((lines (org-split-string (buffer-string) "\n")))
  3070. (dolist (line lines)
  3071. (when (get-text-property 0 'org-category line)
  3072. (setq org-agenda-info
  3073. (org-fix-agenda-info (text-properties-at 0 line)))
  3074. (princ
  3075. (mapconcat #'org-agenda-export-csv-mapper
  3076. '(org-category txt type todo tags date time extra
  3077. priority-letter priority agenda-day)
  3078. ","))
  3079. (princ "\n")))))
  3080. (defun org-fix-agenda-info (props)
  3081. "Make sure all properties on an agenda item have a canonical form.
  3082. This ensures the export commands can easily use it."
  3083. (let (tmp re)
  3084. (when (setq tmp (plist-get props 'tags))
  3085. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3086. (when (setq tmp (plist-get props 'date))
  3087. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3088. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3089. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3090. (setq tmp (calendar-date-string tmp)))
  3091. (setq props (plist-put props 'date tmp)))
  3092. (when (setq tmp (plist-get props 'day))
  3093. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3094. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3095. (setq tmp (calendar-date-string tmp)))
  3096. (setq props (plist-put props 'day tmp))
  3097. (setq props (plist-put props 'agenda-day tmp)))
  3098. (when (setq tmp (plist-get props 'txt))
  3099. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3100. (plist-put props 'priority-letter (match-string 1 tmp))
  3101. (setq tmp (replace-match "" t t tmp)))
  3102. (when (and (setq re (plist-get props 'org-todo-regexp))
  3103. (setq re (concat "\\`\\.*" re " ?"))
  3104. (let ((case-fold-search nil)) (string-match re tmp)))
  3105. (plist-put props 'todo (match-string 1 tmp))
  3106. (setq tmp (replace-match "" t t tmp)))
  3107. (plist-put props 'txt tmp)))
  3108. props)
  3109. (defun org-agenda-export-csv-mapper (prop)
  3110. (let ((res (plist-get org-agenda-info prop)))
  3111. (setq res
  3112. (cond
  3113. ((not res) "")
  3114. ((stringp res) res)
  3115. (t (prin1-to-string res))))
  3116. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3117. ;;;###autoload
  3118. (defun org-store-agenda-views (&rest _parameters)
  3119. "Store agenda views."
  3120. (interactive)
  3121. (org--batch-store-agenda-views nil nil))
  3122. ;;;###autoload
  3123. (defmacro org-batch-store-agenda-views (&rest parameters)
  3124. "Run all custom agenda commands that have a file argument."
  3125. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3126. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3127. (defun org--batch-store-agenda-views (vars vals)
  3128. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3129. (pop-up-frames nil)
  3130. (dir default-directory)
  3131. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3132. (save-window-excursion
  3133. (while cmds
  3134. (setq cmd (pop cmds)
  3135. thiscmdkey (car cmd)
  3136. thiscmdcmd (cdr cmd)
  3137. match (nth 2 thiscmdcmd)
  3138. bufname (if org-agenda-sticky
  3139. (or (and (stringp match)
  3140. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3141. (format "*Org Agenda(%s)*" thiscmdkey))
  3142. org-agenda-buffer-name)
  3143. cmd-or-set (nth 2 cmd)
  3144. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3145. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3146. (if (stringp files) (setq files (list files)))
  3147. (when files
  3148. (let* ((opts (append org-agenda-exporter-settings opts))
  3149. (vars (append (mapcar #'car opts) vars))
  3150. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3151. opts)
  3152. vals)))
  3153. (cl-progv vars vals
  3154. (org-agenda nil thiscmdkey))
  3155. (set-buffer bufname)
  3156. (while files
  3157. (cl-progv vars vals
  3158. (org-agenda-write (expand-file-name (pop files) dir)
  3159. nil t bufname))))
  3160. (and (get-buffer bufname)
  3161. (kill-buffer bufname)))))))
  3162. (defvar org-agenda-current-span nil
  3163. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3164. (defun org-agenda-mark-header-line (pos)
  3165. "Mark the line at POS as an agenda structure header."
  3166. (save-excursion
  3167. (goto-char pos)
  3168. (put-text-property (line-beginning-position) (line-end-position)
  3169. 'org-agenda-structural-header t)
  3170. (when org-agenda-title-append
  3171. (put-text-property (line-beginning-position) (line-end-position)
  3172. 'org-agenda-title-append org-agenda-title-append))))
  3173. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3174. (defvar org-agenda-write-buffer-name "Agenda View")
  3175. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3176. "Write the current buffer (an agenda view) as a file.
  3177. Depending on the extension of the file name, plain text (.txt),
  3178. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3179. If the extension is .ics, translate visible agenda into iCalendar
  3180. format. If the extension is .org, collect all subtrees
  3181. corresponding to the agenda entries and add them in an .org file.
  3182. With prefix argument OPEN, open the new file immediately. If
  3183. NOSETTINGS is given, do not scope the settings of
  3184. `org-agenda-exporter-settings' into the export commands. This is
  3185. used when the settings have already been scoped and we do not
  3186. wish to overrule other, higher priority settings. If
  3187. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3188. the agenda to write."
  3189. (interactive "FWrite agenda to file: \nP")
  3190. (if (or (not (file-writable-p file))
  3191. (and (file-exists-p file)
  3192. (if (called-interactively-p 'any)
  3193. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3194. (user-error "Cannot write agenda to file %s" file))
  3195. (cl-progv
  3196. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3197. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3198. org-agenda-exporter-settings))
  3199. (save-excursion
  3200. (save-window-excursion
  3201. (let ((bs (copy-sequence (buffer-string)))
  3202. (extension (file-name-extension file))
  3203. (default-directory (file-name-directory file))
  3204. ) ;; beg content
  3205. (with-temp-buffer
  3206. (rename-buffer org-agenda-write-buffer-name t)
  3207. (set-buffer-modified-p nil)
  3208. (insert bs)
  3209. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3210. (run-hooks 'org-agenda-before-write-hook)
  3211. (cond
  3212. ((bound-and-true-p org-mobile-creating-agendas)
  3213. (org-mobile-write-agenda-for-mobile file))
  3214. ((string= "org" extension)
  3215. (let (content p m message-log-max)
  3216. (goto-char (point-min))
  3217. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3218. (goto-char p)
  3219. (setq m (get-text-property (point) 'org-hd-marker))
  3220. (when m
  3221. (push (with-current-buffer (marker-buffer m)
  3222. (goto-char m)
  3223. (org-copy-subtree 1 nil t t)
  3224. org-subtree-clip)
  3225. content)))
  3226. (find-file file)
  3227. (erase-buffer)
  3228. (dolist (s content) (org-paste-subtree 1 s))
  3229. (write-file file)
  3230. (kill-buffer (current-buffer))
  3231. (message "Org file written to %s" file)))
  3232. ((member extension '("html" "htm"))
  3233. (or (require 'htmlize nil t)
  3234. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3235. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3236. (set-buffer (htmlize-buffer (current-buffer)))
  3237. (when org-agenda-export-html-style
  3238. ;; replace <style> section with org-agenda-export-html-style
  3239. (goto-char (point-min))
  3240. (kill-region (- (search-forward "<style") 6)
  3241. (search-forward "</style>"))
  3242. (insert org-agenda-export-html-style))
  3243. (write-file file)
  3244. (kill-buffer (current-buffer))
  3245. (message "HTML written to %s" file))
  3246. ((string= "ps" extension)
  3247. (require 'ps-print)
  3248. (ps-print-buffer-with-faces file)
  3249. (message "Postscript written to %s" file))
  3250. ((string= "pdf" extension)
  3251. (require 'ps-print)
  3252. (ps-print-buffer-with-faces
  3253. (concat (file-name-sans-extension file) ".ps"))
  3254. (call-process "ps2pdf" nil nil nil
  3255. (expand-file-name
  3256. (concat (file-name-sans-extension file) ".ps"))
  3257. (expand-file-name file))
  3258. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3259. (message "PDF written to %s" file))
  3260. ((string= "ics" extension)
  3261. (require 'ox-icalendar)
  3262. (declare-function org-icalendar-export-current-agenda
  3263. "ox-icalendar" (file))
  3264. (org-icalendar-export-current-agenda (expand-file-name file)))
  3265. (t
  3266. (let ((bs (buffer-string)))
  3267. (find-file file)
  3268. (erase-buffer)
  3269. (insert bs)
  3270. (save-buffer 0)
  3271. (kill-buffer (current-buffer))
  3272. (message "Plain text written to %s" file))))))))
  3273. (set-buffer (or agenda-bufname
  3274. ;; FIXME: I'm pretty sure called-interactively-p
  3275. ;; doesn't do what we want here!
  3276. (and (called-interactively-p 'any) (buffer-name))
  3277. org-agenda-buffer-name)))
  3278. (when open (org-open-file file)))
  3279. (defun org-agenda-remove-marked-text (property &optional value)
  3280. "Delete all text marked with VALUE of PROPERTY.
  3281. VALUE defaults to t."
  3282. (let (beg)
  3283. (setq value (or value t))
  3284. (while (setq beg (text-property-any (point-min) (point-max)
  3285. property value))
  3286. (delete-region
  3287. beg (or (next-single-property-change beg property)
  3288. (point-max))))))
  3289. (defun org-agenda-add-entry-text ()
  3290. "Add entry text to agenda lines.
  3291. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3292. entry text following headings shown in the agenda.
  3293. Drawers will be excluded, also the line with scheduling/deadline info."
  3294. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3295. (not (bound-and-true-p org-mobile-creating-agendas)))
  3296. (let (m txt)
  3297. (goto-char (point-min))
  3298. (while (not (eobp))
  3299. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3300. (beginning-of-line 2)
  3301. (setq txt (org-agenda-get-some-entry-text
  3302. m org-agenda-add-entry-text-maxlines " > "))
  3303. (end-of-line 1)
  3304. (if (string-match "\\S-" txt)
  3305. (insert "\n" txt)
  3306. (or (eobp) (forward-char 1))))))))
  3307. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3308. &rest keep)
  3309. "Extract entry text from MARKER, at most N-LINES lines.
  3310. This will ignore drawers etc, just get the text.
  3311. If INDENT is given, prefix every line with this string. If KEEP is
  3312. given, it is a list of symbols, defining stuff that should not be
  3313. removed from the entry content. Currently only `planning' is allowed here."
  3314. (let (txt drawer-re kwd-time-re ind)
  3315. (save-excursion
  3316. (with-current-buffer (marker-buffer marker)
  3317. (if (not (derived-mode-p 'org-mode))
  3318. (setq txt "")
  3319. (org-with-wide-buffer
  3320. (goto-char marker)
  3321. (end-of-line 1)
  3322. (setq txt (buffer-substring
  3323. (min (1+ (point)) (point-max))
  3324. (progn (outline-next-heading) (point)))
  3325. drawer-re org-drawer-regexp
  3326. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3327. ".*\n?"))
  3328. (with-temp-buffer
  3329. (insert txt)
  3330. (when org-agenda-add-entry-text-descriptive-links
  3331. (goto-char (point-min))
  3332. (while (org-activate-links (point-max))
  3333. (goto-char (match-end 0))))
  3334. (goto-char (point-min))
  3335. (while (re-search-forward org-link-bracket-re (point-max) t)
  3336. (set-text-properties (match-beginning 0) (match-end 0)
  3337. nil))
  3338. (goto-char (point-min))
  3339. (while (re-search-forward drawer-re nil t)
  3340. (delete-region
  3341. (match-beginning 0)
  3342. (progn (re-search-forward
  3343. "^[ \t]*:END:.*\n?" nil 'move)
  3344. (point))))
  3345. (unless (member 'planning keep)
  3346. (goto-char (point-min))
  3347. (while (re-search-forward kwd-time-re nil t)
  3348. (replace-match "")))
  3349. (goto-char (point-min))
  3350. (when org-agenda-entry-text-exclude-regexps
  3351. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3352. (while (setq re (pop re-list))
  3353. (goto-char (point-min))
  3354. (while (re-search-forward re nil t)
  3355. (replace-match "")))))
  3356. (goto-char (point-max))
  3357. (skip-chars-backward " \t\n")
  3358. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3359. ;; find and remove min common indentation
  3360. (goto-char (point-min))
  3361. (untabify (point-min) (point-max))
  3362. (setq ind (current-indentation))
  3363. (while (not (eobp))
  3364. (unless (looking-at "[ \t]*$")
  3365. (setq ind (min ind (current-indentation))))
  3366. (beginning-of-line 2))
  3367. (goto-char (point-min))
  3368. (while (not (eobp))
  3369. (unless (looking-at "[ \t]*$")
  3370. (move-to-column ind)
  3371. (delete-region (line-beginning-position) (point)))
  3372. (beginning-of-line 2))
  3373. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3374. (goto-char (point-min))
  3375. (when indent
  3376. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3377. (replace-match indent t t)))
  3378. (goto-char (point-min))
  3379. (while (looking-at "[ \t]*\n") (replace-match ""))
  3380. (goto-char (point-max))
  3381. (when (> (org-current-line)
  3382. n-lines)
  3383. (org-goto-line (1+ n-lines))
  3384. (backward-char 1))
  3385. (setq txt (buffer-substring (point-min) (point))))))))
  3386. txt))
  3387. (defun org-check-for-org-mode ()
  3388. "Make sure current buffer is in Org mode. Error if not."
  3389. (or (derived-mode-p 'org-mode)
  3390. (error "Cannot execute Org agenda command on buffer in %s"
  3391. major-mode)))
  3392. ;;; Agenda prepare and finalize
  3393. (defvar org-agenda-multi nil) ; dynamically scoped
  3394. (defvar org-agenda-pre-window-conf nil)
  3395. (defvar org-agenda-columns-active nil)
  3396. (defvar org-agenda-name nil)
  3397. (defvar org-agenda-tag-filter nil)
  3398. (defvar org-agenda-category-filter nil)
  3399. (defvar org-agenda-regexp-filter nil)
  3400. (defvar org-agenda-effort-filter nil)
  3401. (defvar org-agenda-top-headline-filter nil)
  3402. (defvar org-agenda-represented-categories nil
  3403. "Cache for the list of all categories in the agenda.")
  3404. (defvar org-agenda-represented-tags nil
  3405. "Cache for the list of all categories in the agenda.")
  3406. (defvar org-agenda-tag-filter-preset nil
  3407. "A preset of the tags filter used for secondary agenda filtering.
  3408. This must be a list of strings, each string must be a single tag preceded
  3409. by \"+\" or \"-\".
  3410. This variable should not be set directly, but agenda custom commands can
  3411. bind it in the options section. The preset filter is a global property of
  3412. the entire agenda view. In a block agenda, it will not work reliably to
  3413. define a filter for one of the individual blocks. You need to set it in
  3414. the global options and expect it to be applied to the entire view.")
  3415. (defconst org-agenda-filter-variables
  3416. '((category . org-agenda-category-filter)
  3417. (tag . org-agenda-tag-filter)
  3418. (effort . org-agenda-effort-filter)
  3419. (regexp . org-agenda-regexp-filter))
  3420. "Alist of filter types and associated variables.")
  3421. (defun org-agenda-filter-any ()
  3422. "Is any filter active?"
  3423. (cl-some (lambda (x)
  3424. (or (symbol-value (cdr x))
  3425. (get :preset-filter x)))
  3426. org-agenda-filter-variables))
  3427. (defvar org-agenda-category-filter-preset nil
  3428. "A preset of the category filter used for secondary agenda filtering.
  3429. This must be a list of strings, each string must be a single category
  3430. preceded by \"+\" or \"-\".
  3431. This variable should not be set directly, but agenda custom commands can
  3432. bind it in the options section. The preset filter is a global property of
  3433. the entire agenda view. In a block agenda, it will not work reliably to
  3434. define a filter for one of the individual blocks. You need to set it in
  3435. the global options and expect it to be applied to the entire view.")
  3436. (defvar org-agenda-regexp-filter-preset nil
  3437. "A preset of the regexp filter used for secondary agenda filtering.
  3438. This must be a list of strings, each string must be a single regexp
  3439. preceded by \"+\" or \"-\".
  3440. This variable should not be set directly, but agenda custom commands can
  3441. bind it in the options section. The preset filter is a global property of
  3442. the entire agenda view. In a block agenda, it will not work reliably to
  3443. define a filter for one of the individual blocks. You need to set it in
  3444. the global options and expect it to be applied to the entire view.")
  3445. (defvar org-agenda-effort-filter-preset nil
  3446. "A preset of the effort condition used for secondary agenda filtering.
  3447. This must be a list of strings, each string must be a single regexp
  3448. preceded by \"+\" or \"-\".
  3449. This variable should not be set directly, but agenda custom commands can
  3450. bind it in the options section. The preset filter is a global property of
  3451. the entire agenda view. In a block agenda, it will not work reliably to
  3452. define a filter for one of the individual blocks. You need to set it in
  3453. the global options and expect it to be applied to the entire view.")
  3454. (defun org-agenda-use-sticky-p ()
  3455. "Return non-nil if an agenda buffer named
  3456. `org-agenda-buffer-name' exists and should be shown instead of
  3457. generating a new one."
  3458. (and
  3459. ;; turned off by user
  3460. org-agenda-sticky
  3461. ;; For multi-agenda buffer already exists
  3462. (not org-agenda-multi)
  3463. ;; buffer found
  3464. (get-buffer org-agenda-buffer-name)
  3465. ;; C-u parameter is same as last call
  3466. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3467. (and
  3468. (equal current-prefix-arg
  3469. org-agenda-last-prefix-arg)
  3470. ;; In case user turned stickiness on, while having existing
  3471. ;; Agenda buffer active, don't reuse that buffer, because it
  3472. ;; does not have org variables local
  3473. org-agenda-this-buffer-is-sticky))))
  3474. (defvar org-agenda-buffer-tmp-name nil)
  3475. (defun org-agenda--get-buffer-name (sticky-name)
  3476. (or org-agenda-buffer-tmp-name
  3477. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3478. sticky-name
  3479. "*Org Agenda*"))
  3480. (defun org-agenda-prepare-window (abuf filter-alist)
  3481. "Setup agenda buffer in the window.
  3482. ABUF is the buffer for the agenda window.
  3483. FILTER-ALIST is an alist of filters we need to apply when
  3484. `org-agenda-persistent-filter' is non-nil."
  3485. (let* ((awin (get-buffer-window abuf)) wconf)
  3486. (cond
  3487. ((equal (current-buffer) abuf) nil)
  3488. (awin (select-window awin))
  3489. ((not (setq wconf (current-window-configuration))))
  3490. ((eq org-agenda-window-setup 'current-window)
  3491. (pop-to-buffer-same-window abuf))
  3492. ((eq org-agenda-window-setup 'other-window)
  3493. (org-switch-to-buffer-other-window abuf))
  3494. ((eq org-agenda-window-setup 'other-frame)
  3495. (switch-to-buffer-other-frame abuf))
  3496. ((eq org-agenda-window-setup 'other-tab)
  3497. (if (fboundp 'switch-to-buffer-other-tab)
  3498. (switch-to-buffer-other-tab abuf)
  3499. (user-error "Your version of Emacs does not have tab bar support")))
  3500. ((eq org-agenda-window-setup 'only-window)
  3501. (delete-other-windows)
  3502. (pop-to-buffer-same-window abuf))
  3503. ((eq org-agenda-window-setup 'reorganize-frame)
  3504. (delete-other-windows)
  3505. (org-switch-to-buffer-other-window abuf)))
  3506. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3507. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3508. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3509. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3510. ;; Additional test in case agenda is invoked from within agenda
  3511. ;; buffer via elisp link.
  3512. (unless (equal (current-buffer) abuf)
  3513. (pop-to-buffer-same-window abuf))
  3514. (setq org-agenda-pre-window-conf
  3515. (or wconf org-agenda-pre-window-conf))))
  3516. (defun org-agenda-prepare (&optional name)
  3517. (let ((filter-alist (when org-agenda-persistent-filter
  3518. (with-current-buffer
  3519. (get-buffer-create org-agenda-buffer-name)
  3520. `((tag . ,org-agenda-tag-filter)
  3521. (re . ,org-agenda-regexp-filter)
  3522. (effort . ,org-agenda-effort-filter)
  3523. (cat . ,org-agenda-category-filter))))))
  3524. (if (org-agenda-use-sticky-p)
  3525. (progn
  3526. (put 'org-agenda-tag-filter :preset-filter nil)
  3527. (put 'org-agenda-category-filter :preset-filter nil)
  3528. (put 'org-agenda-regexp-filter :preset-filter nil)
  3529. (put 'org-agenda-effort-filter :preset-filter nil)
  3530. ;; Popup existing buffer
  3531. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3532. filter-alist)
  3533. (message "Sticky Agenda buffer, use `r' to refresh")
  3534. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3535. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3536. (setq org-todo-keywords-for-agenda nil)
  3537. (put 'org-agenda-tag-filter :preset-filter
  3538. org-agenda-tag-filter-preset)
  3539. (put 'org-agenda-category-filter :preset-filter
  3540. org-agenda-category-filter-preset)
  3541. (put 'org-agenda-regexp-filter :preset-filter
  3542. org-agenda-regexp-filter-preset)
  3543. (put 'org-agenda-effort-filter :preset-filter
  3544. org-agenda-effort-filter-preset)
  3545. (if org-agenda-multi
  3546. (progn
  3547. (setq buffer-read-only nil)
  3548. (goto-char (point-max))
  3549. (unless (or (bobp) org-agenda-compact-blocks
  3550. (not org-agenda-block-separator))
  3551. (insert "\n"
  3552. (if (stringp org-agenda-block-separator)
  3553. org-agenda-block-separator
  3554. (make-string (window-width) org-agenda-block-separator))
  3555. "\n"))
  3556. (narrow-to-region (point) (point-max)))
  3557. (setq org-done-keywords-for-agenda nil)
  3558. ;; Setting any org variables that are in org-agenda-local-vars
  3559. ;; list need to be done after the prepare call
  3560. (org-agenda-prepare-window
  3561. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3562. (setq buffer-read-only nil)
  3563. (org-agenda-reset-markers)
  3564. (let ((inhibit-read-only t)) (erase-buffer))
  3565. (org-agenda-mode)
  3566. (setq org-agenda-buffer (current-buffer))
  3567. (setq org-agenda-contributing-files nil)
  3568. (setq org-agenda-columns-active nil)
  3569. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3570. (setq org-todo-keywords-for-agenda
  3571. (org-uniquify org-todo-keywords-for-agenda))
  3572. (setq org-done-keywords-for-agenda
  3573. (org-uniquify org-done-keywords-for-agenda))
  3574. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3575. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3576. (and name (not org-agenda-name)
  3577. (setq-local org-agenda-name name)))
  3578. (setq buffer-read-only nil))))
  3579. (defvar org-overriding-columns-format)
  3580. (defvar org-local-columns-format)
  3581. (defun org-agenda-finalize ()
  3582. "Finishing touch for the agenda buffer.
  3583. This function is called just before displaying the agenda. If
  3584. you want to add your own functions to the finalization of the
  3585. agenda display, configure `org-agenda-finalize-hook'."
  3586. (unless org-agenda-multi
  3587. (let ((inhibit-read-only t))
  3588. (save-excursion
  3589. (goto-char (point-min))
  3590. (save-excursion
  3591. (while (org-activate-links (point-max))
  3592. (goto-char (match-end 0))))
  3593. (unless (eq org-agenda-remove-tags t)
  3594. (org-agenda-align-tags))
  3595. (unless org-agenda-with-colors
  3596. (remove-text-properties (point-min) (point-max) '(face nil)))
  3597. (when (bound-and-true-p org-overriding-columns-format)
  3598. (setq-local org-local-columns-format
  3599. org-overriding-columns-format))
  3600. (when org-agenda-view-columns-initially
  3601. (org-agenda-columns))
  3602. (when org-agenda-fontify-priorities
  3603. (org-agenda-fontify-priorities))
  3604. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3605. (org-agenda-dim-blocked-tasks))
  3606. (org-agenda-mark-clocking-task)
  3607. (when org-agenda-entry-text-mode
  3608. (org-agenda-entry-text-hide)
  3609. (org-agenda-entry-text-show))
  3610. (when (and (featurep 'org-habit)
  3611. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3612. (org-habit-insert-consistency-graphs))
  3613. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3614. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3615. (and (listp org-agenda-show-inherited-tags)
  3616. (memq org-agenda-type org-agenda-show-inherited-tags))
  3617. (and (eq org-agenda-show-inherited-tags t)
  3618. (or (eq org-agenda-use-tag-inheritance t)
  3619. (and (listp org-agenda-use-tag-inheritance)
  3620. (not (memq org-agenda-type
  3621. org-agenda-use-tag-inheritance))))))
  3622. (let (mrk)
  3623. (save-excursion
  3624. (goto-char (point-min))
  3625. (while (equal (forward-line) 0)
  3626. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3627. (put-text-property (line-beginning-position) (line-end-position)
  3628. 'tags
  3629. (org-with-point-at mrk
  3630. (org-get-tags))))))))
  3631. (setq org-agenda-represented-tags nil
  3632. org-agenda-represented-categories nil)
  3633. (when org-agenda-top-headline-filter
  3634. (org-agenda-filter-top-headline-apply
  3635. org-agenda-top-headline-filter))
  3636. (when org-agenda-tag-filter
  3637. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3638. (when (get 'org-agenda-tag-filter :preset-filter)
  3639. (org-agenda-filter-apply
  3640. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3641. (when org-agenda-category-filter
  3642. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3643. (when (get 'org-agenda-category-filter :preset-filter)
  3644. (org-agenda-filter-apply
  3645. (get 'org-agenda-category-filter :preset-filter) 'category))
  3646. (when org-agenda-regexp-filter
  3647. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3648. (when (get 'org-agenda-regexp-filter :preset-filter)
  3649. (org-agenda-filter-apply
  3650. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3651. (when org-agenda-effort-filter
  3652. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3653. (when (get 'org-agenda-effort-filter :preset-filter)
  3654. (org-agenda-filter-apply
  3655. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3656. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3657. (run-hooks 'org-agenda-finalize-hook))))
  3658. (defun org-agenda-mark-clocking-task ()
  3659. "Mark the current clock entry in the agenda if it is present."
  3660. ;; We need to widen when `org-agenda-finalize' is called from
  3661. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3662. (when (bound-and-true-p org-clock-current-task)
  3663. (save-restriction
  3664. (widen)
  3665. (org-agenda-unmark-clocking-task)
  3666. (when (marker-buffer org-clock-hd-marker)
  3667. (save-excursion
  3668. (goto-char (point-min))
  3669. (let (s ov)
  3670. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3671. (goto-char s)
  3672. (when (equal (org-get-at-bol 'org-hd-marker)
  3673. org-clock-hd-marker)
  3674. (setq ov (make-overlay (line-beginning-position)
  3675. (1+ (line-end-position))))
  3676. (overlay-put ov 'type 'org-agenda-clocking)
  3677. (overlay-put ov 'face 'org-agenda-clocking)
  3678. (overlay-put ov 'help-echo
  3679. "The clock is running in this item")))))))))
  3680. (defun org-agenda-unmark-clocking-task ()
  3681. "Unmark the current clocking task."
  3682. (mapc (lambda (o)
  3683. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3684. (delete-overlay o)))
  3685. (overlays-in (point-min) (point-max))))
  3686. (defun org-agenda-fontify-priorities ()
  3687. "Make highest priority lines bold, and lowest italic."
  3688. (interactive)
  3689. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3690. (delete-overlay o)))
  3691. (overlays-in (point-min) (point-max)))
  3692. (save-excursion
  3693. (let (b e p ov h l)
  3694. (goto-char (point-min))
  3695. (while (re-search-forward org-priority-regexp nil t)
  3696. (setq h (or (get-char-property (point) 'org-priority-highest)
  3697. org-priority-highest)
  3698. l (or (get-char-property (point) 'org-priority-lowest)
  3699. org-priority-lowest)
  3700. p (string-to-char (match-string 2))
  3701. b (match-beginning 1)
  3702. e (if (eq org-agenda-fontify-priorities 'cookies)
  3703. (1+ (match-end 2))
  3704. (line-end-position))
  3705. ov (make-overlay b e))
  3706. (overlay-put
  3707. ov 'face
  3708. (let ((special-face
  3709. (cond ((org-face-from-face-or-color
  3710. 'priority 'org-priority
  3711. (cdr (assoc p org-priority-faces))))
  3712. ((and (listp org-agenda-fontify-priorities)
  3713. (org-face-from-face-or-color
  3714. 'priority 'org-priority
  3715. (cdr (assoc p org-agenda-fontify-priorities)))))
  3716. ((equal p l) 'italic)
  3717. ((equal p h) 'bold))))
  3718. (if special-face (list special-face 'org-priority) 'org-priority)))
  3719. (overlay-put ov 'org-type 'org-priority)))))
  3720. (defvar org-depend-tag-blocked)
  3721. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3722. "Dim currently blocked TODOs in the agenda display.
  3723. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3724. dimming them." ;FIXME: The arg isn't used, actually!
  3725. (interactive "P")
  3726. (when (called-interactively-p 'interactive)
  3727. (message "Dim or hide blocked tasks..."))
  3728. (dolist (o (overlays-in (point-min) (point-max)))
  3729. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3730. (delete-overlay o)))
  3731. (save-excursion
  3732. (let ((inhibit-read-only t))
  3733. (goto-char (point-min))
  3734. (while (let ((pos (text-property-not-all
  3735. (point) (point-max) 'org-todo-blocked nil)))
  3736. (when pos (goto-char pos)))
  3737. (let* ((invisible
  3738. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3739. (todo-blocked
  3740. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3741. (ov (make-overlay (if invisible
  3742. (line-end-position 0)
  3743. (line-beginning-position))
  3744. (line-end-position))))
  3745. (when todo-blocked
  3746. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3747. (when invisible
  3748. (org-agenda-filter-hide-line 'todo-blocked)))
  3749. (if (= (point-max) (line-end-position))
  3750. (goto-char (point-max))
  3751. (move-beginning-of-line 2)))))
  3752. (when (called-interactively-p 'interactive)
  3753. (message "Dim or hide blocked tasks...done")))
  3754. (defun org-agenda--mark-blocked-entry (entry)
  3755. "If ENTRY is blocked, mark it for fontification or invisibility.
  3756. If the header at `org-hd-marker' is blocked according to
  3757. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3758. `invisible' and the header is not blocked by checkboxes, set the
  3759. text property `org-todo-blocked' to `invisible', otherwise set it
  3760. to t."
  3761. (when (get-text-property 0 'todo-state entry)
  3762. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3763. (org-blocked-by-checkboxes nil)
  3764. ;; Necessary so that `org-entry-blocked-p' does not change
  3765. ;; the buffer.
  3766. (org-depend-tag-blocked nil))
  3767. (when entry-marker
  3768. (let ((blocked
  3769. (with-current-buffer (marker-buffer entry-marker)
  3770. (save-excursion
  3771. (goto-char entry-marker)
  3772. (org-entry-blocked-p)))))
  3773. (when blocked
  3774. (let ((really-invisible
  3775. (and (not org-blocked-by-checkboxes)
  3776. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3777. (put-text-property
  3778. 0 (length entry) 'org-todo-blocked
  3779. (if really-invisible 'invisible t)
  3780. entry)
  3781. (put-text-property
  3782. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3783. entry)
  3784. (defvar org-agenda-skip-function nil
  3785. "Function to be called at each match during agenda construction.
  3786. If this function returns nil, the current match should not be skipped.
  3787. Otherwise, the function must return a position from where the search
  3788. should be continued.
  3789. This may also be a Lisp form, it will be evaluated.
  3790. Never set this variable using `setq' or so, because then it will apply
  3791. to all future agenda commands. If you do want a global skipping condition,
  3792. use the option `org-agenda-skip-function-global' instead.
  3793. The correct usage for `org-agenda-skip-function' is to bind it with
  3794. `let' to scope it dynamically into the agenda-constructing command.
  3795. A good way to set it is through options in `org-agenda-custom-commands'.")
  3796. (defun org-agenda-skip ()
  3797. "Throw to `:skip' in places that should be skipped.
  3798. Also moves point to the end of the skipped region, so that search can
  3799. continue from there."
  3800. (let ((p (line-beginning-position)) to)
  3801. (when (or
  3802. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3803. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3804. (or (and (get-text-property p :org-archived)
  3805. (org-end-of-subtree t))
  3806. (and (member org-archive-tag org-file-tags)
  3807. (goto-char (point-max)))))
  3808. (and org-agenda-skip-comment-trees
  3809. (get-text-property p :org-comment)
  3810. (org-end-of-subtree t))
  3811. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3812. (org-agenda-skip-eval org-agenda-skip-function)))
  3813. (goto-char to))
  3814. (org-in-src-block-p t))
  3815. (throw :skip t))))
  3816. (defun org-agenda-skip-eval (form)
  3817. "If FORM is a function or a list, call (or eval) it and return the result.
  3818. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3819. and match data are returned to the previous state no matter what these
  3820. functions do."
  3821. (let (fp)
  3822. (and form
  3823. (or (setq fp (functionp form))
  3824. (consp form))
  3825. (save-excursion
  3826. (save-match-data
  3827. (if fp
  3828. (funcall form)
  3829. (eval form t)))))))
  3830. (defvar org-agenda-markers nil
  3831. "List of all currently active markers created by `org-agenda'.")
  3832. (defvar org-agenda-last-marker-time (float-time)
  3833. "Creation time of the last agenda marker.")
  3834. (defun org-agenda-new-marker (&optional pos)
  3835. "Return a new agenda marker.
  3836. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3837. of these markers and resets them when they are no longer in use."
  3838. (let ((m (copy-marker (or pos (point)) t)))
  3839. (setq org-agenda-last-marker-time (float-time))
  3840. (if org-agenda-buffer
  3841. (with-current-buffer org-agenda-buffer
  3842. (push m org-agenda-markers))
  3843. (push m org-agenda-markers))
  3844. m))
  3845. (defun org-agenda-reset-markers ()
  3846. "Reset markers created by `org-agenda'."
  3847. (while org-agenda-markers
  3848. (move-marker (pop org-agenda-markers) nil)))
  3849. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3850. "Save relative positions of markers in region.
  3851. This check for agenda markers in all agenda buffers currently active."
  3852. (dolist (buf (buffer-list))
  3853. (with-current-buffer buf
  3854. (when (eq major-mode 'org-agenda-mode)
  3855. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3856. org-agenda-markers)))))
  3857. ;;; Entry text mode
  3858. (defun org-agenda-entry-text-show-here ()
  3859. "Add some text from the entry as context to the current line."
  3860. (let (m txt o)
  3861. (setq m (org-get-at-bol 'org-hd-marker))
  3862. (unless (marker-buffer m)
  3863. (error "No marker points to an entry here"))
  3864. (setq txt (concat "\n" (org-no-properties
  3865. (org-agenda-get-some-entry-text
  3866. m org-agenda-entry-text-maxlines
  3867. org-agenda-entry-text-leaders))))
  3868. (when (string-match "\\S-" txt)
  3869. (setq o (make-overlay (line-beginning-position) (line-end-position)))
  3870. (overlay-put o 'evaporate t)
  3871. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3872. (overlay-put o 'after-string txt))))
  3873. (defun org-agenda-entry-text-show ()
  3874. "Add entry context for all agenda lines."
  3875. (interactive)
  3876. (save-excursion
  3877. (goto-char (point-max))
  3878. (beginning-of-line 1)
  3879. (while (not (bobp))
  3880. (when (org-get-at-bol 'org-hd-marker)
  3881. (org-agenda-entry-text-show-here))
  3882. (beginning-of-line 0))))
  3883. (defun org-agenda-entry-text-hide ()
  3884. "Remove any shown entry context."
  3885. (mapc (lambda (o)
  3886. (when (eq (overlay-get o 'org-overlay-type)
  3887. 'agenda-entry-content)
  3888. (delete-overlay o)))
  3889. (overlays-in (point-min) (point-max))))
  3890. (defun org-agenda-get-day-face (date)
  3891. "Return the face DATE should be displayed with."
  3892. (cond ((and (functionp org-agenda-day-face-function)
  3893. (funcall org-agenda-day-face-function date)))
  3894. ((and (org-agenda-today-p date)
  3895. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3896. 'org-agenda-date-weekend-today)
  3897. ((org-agenda-today-p date) 'org-agenda-date-today)
  3898. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3899. 'org-agenda-date-weekend)
  3900. (t 'org-agenda-date)))
  3901. (defvar org-agenda-show-log-scoped)
  3902. ;;; Agenda Daily/Weekly
  3903. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3904. "Start day for the agenda view.
  3905. Custom commands can set this variable in the options section.
  3906. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3907. input allowed when reading a date through the Org calendar.
  3908. See the docstring of `org-read-date' for details.")
  3909. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3910. (defvar org-arg-loc nil) ; local variable
  3911. ;;;###autoload
  3912. (defun org-agenda-list (&optional arg start-day span with-hour)
  3913. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3914. The view will be for the current day or week, but from the overview buffer
  3915. you will be able to go to other days/weeks.
  3916. With a numeric prefix argument in an interactive call, the agenda will
  3917. span ARG days. Lisp programs should instead specify SPAN to change
  3918. the number of days. SPAN defaults to `org-agenda-span'.
  3919. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3920. given in `org-agenda-start-on-weekday'.
  3921. When WITH-HOUR is non-nil, only include scheduled and deadline
  3922. items if they have an hour specification like [h]h:mm."
  3923. (interactive "P")
  3924. (when org-agenda-overriding-arguments
  3925. (setq arg (car org-agenda-overriding-arguments)
  3926. start-day (nth 1 org-agenda-overriding-arguments)
  3927. span (nth 2 org-agenda-overriding-arguments)))
  3928. (when (and (integerp arg) (> arg 0))
  3929. (setq span arg arg nil))
  3930. (when (numberp span)
  3931. (unless (< 0 span)
  3932. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3933. (catch 'exit
  3934. (setq org-agenda-buffer-name
  3935. (org-agenda--get-buffer-name
  3936. (and org-agenda-sticky
  3937. (cond ((and org-keys (stringp org-match))
  3938. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3939. (org-keys
  3940. (format "*Org Agenda(%s)*" org-keys))
  3941. (t "*Org Agenda(a)*")))))
  3942. (org-agenda-prepare "Day/Week")
  3943. (setq start-day (or start-day org-agenda-start-day))
  3944. (when (stringp start-day)
  3945. ;; Convert to an absolute day number
  3946. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3947. (org-compile-prefix-format 'agenda)
  3948. (org-set-sorting-strategy 'agenda)
  3949. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3950. (today (org-today))
  3951. (sd (or start-day today))
  3952. (ndays (org-agenda-span-to-ndays span sd))
  3953. (org-agenda-start-on-weekday
  3954. (and (or (eq ndays 7) (eq ndays 14))
  3955. org-agenda-start-on-weekday))
  3956. (thefiles (org-agenda-files nil 'ifmode))
  3957. (files thefiles)
  3958. (start (if (or (null org-agenda-start-on-weekday)
  3959. (< ndays 7))
  3960. sd
  3961. (let* ((nt (calendar-day-of-week
  3962. (calendar-gregorian-from-absolute sd)))
  3963. (n1 org-agenda-start-on-weekday)
  3964. (d (- nt n1)))
  3965. (- sd (+ (if (< d 0) 7 0) d)))))
  3966. (day-numbers (list start))
  3967. (day-cnt 0)
  3968. (inhibit-redisplay (not debug-on-error))
  3969. (org-agenda-show-log-scoped org-agenda-show-log)
  3970. s rtn rtnall file date d start-pos end-pos todayp ;; e
  3971. clocktable-start clocktable-end) ;; filter
  3972. (setq org-agenda-redo-command
  3973. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3974. (dotimes (_ (1- ndays))
  3975. (push (1+ (car day-numbers)) day-numbers))
  3976. (setq day-numbers (nreverse day-numbers))
  3977. (setq clocktable-start (car day-numbers)
  3978. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3979. (setq-local org-starting-day (car day-numbers))
  3980. (setq-local org-arg-loc arg)
  3981. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3982. (unless org-agenda-compact-blocks
  3983. (let* ((d1 (car day-numbers))
  3984. (d2 (org-last day-numbers))
  3985. (w1 (org-days-to-iso-week d1))
  3986. (w2 (org-days-to-iso-week d2)))
  3987. (setq s (point))
  3988. (org-agenda--insert-overriding-header
  3989. (concat (org-agenda-span-name span)
  3990. "-agenda"
  3991. (cond ((<= 350 (- d2 d1)) "")
  3992. ((= w1 w2) (format " (W%02d)" w1))
  3993. (t (format " (W%02d-W%02d)" w1 w2)))
  3994. ":\n")))
  3995. ;; Add properties if we actually inserted a header.
  3996. (when (> (point) s)
  3997. (add-text-properties s (1- (point))
  3998. (list 'face 'org-agenda-structure
  3999. 'org-date-line t))
  4000. (org-agenda-mark-header-line s)))
  4001. (while (setq d (pop day-numbers))
  4002. (setq date (calendar-gregorian-from-absolute d)
  4003. s (point))
  4004. (if (or (setq todayp (= d today))
  4005. (and (not start-pos) (= d sd)))
  4006. (setq start-pos (point))
  4007. (when (and start-pos (not end-pos))
  4008. (setq end-pos (point))))
  4009. (setq files thefiles
  4010. rtnall nil)
  4011. (while (setq file (pop files))
  4012. (catch 'nextfile
  4013. (org-check-agenda-file file)
  4014. (let ((org-agenda-entry-types org-agenda-entry-types))
  4015. ;; Starred types override non-starred equivalents
  4016. (when (member :deadline* org-agenda-entry-types)
  4017. (setq org-agenda-entry-types
  4018. (delq :deadline org-agenda-entry-types)))
  4019. (when (member :scheduled* org-agenda-entry-types)
  4020. (setq org-agenda-entry-types
  4021. (delq :scheduled org-agenda-entry-types)))
  4022. ;; Honor with-hour
  4023. (when with-hour
  4024. (when (member :deadline org-agenda-entry-types)
  4025. (setq org-agenda-entry-types
  4026. (delq :deadline org-agenda-entry-types))
  4027. (push :deadline* org-agenda-entry-types))
  4028. (when (member :scheduled org-agenda-entry-types)
  4029. (setq org-agenda-entry-types
  4030. (delq :scheduled org-agenda-entry-types))
  4031. (push :scheduled* org-agenda-entry-types)))
  4032. (unless org-agenda-include-deadlines
  4033. (setq org-agenda-entry-types
  4034. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4035. (cond
  4036. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4037. (setq rtn (org-agenda-get-day-entries
  4038. file date :closed)))
  4039. (org-agenda-show-log-scoped
  4040. (setq rtn (apply #'org-agenda-get-day-entries
  4041. file date
  4042. (append '(:closed) org-agenda-entry-types))))
  4043. (t
  4044. (setq rtn (apply #'org-agenda-get-day-entries
  4045. file date
  4046. org-agenda-entry-types)))))
  4047. (setq rtnall (append rtnall rtn)))) ;; all entries
  4048. (when org-agenda-include-diary
  4049. (let ((org-agenda-search-headline-for-time t))
  4050. (require 'diary-lib)
  4051. (setq rtn (org-get-entries-from-diary date))
  4052. (setq rtnall (append rtnall rtn))))
  4053. (when (or rtnall org-agenda-show-all-dates)
  4054. (setq day-cnt (1+ day-cnt))
  4055. (insert
  4056. (if (stringp org-agenda-format-date)
  4057. (format-time-string org-agenda-format-date
  4058. (org-time-from-absolute date))
  4059. (funcall org-agenda-format-date date))
  4060. "\n")
  4061. (put-text-property s (1- (point)) 'face
  4062. (org-agenda-get-day-face date))
  4063. (put-text-property s (1- (point)) 'org-date-line t)
  4064. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4065. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4066. (when todayp
  4067. (put-text-property s (1- (point)) 'org-today t))
  4068. (setq rtnall
  4069. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4070. (when rtnall (insert ;; all entries
  4071. (org-agenda-finalize-entries rtnall 'agenda)
  4072. "\n"))
  4073. (put-text-property s (1- (point)) 'day d)
  4074. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4075. (when (and org-agenda-clockreport-mode clocktable-start)
  4076. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4077. ;; the above line is to ensure the restricted range!
  4078. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4079. tbl)
  4080. (setq p (org-plist-delete p :block))
  4081. (setq p (plist-put p :tstart clocktable-start))
  4082. (setq p (plist-put p :tend clocktable-end))
  4083. (setq p (plist-put p :scope 'agenda))
  4084. (setq tbl (apply #'org-clock-get-clocktable p))
  4085. (insert tbl)))
  4086. (goto-char (point-min))
  4087. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4088. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4089. (and (pos-visible-in-window-p (point-min))
  4090. (pos-visible-in-window-p (point-max))))
  4091. (goto-char (1- (point-max)))
  4092. (recenter -1)
  4093. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4094. (goto-char (or start-pos 1))
  4095. (recenter 1)))
  4096. (goto-char (or start-pos 1))
  4097. (add-text-properties (point-min) (point-max)
  4098. `(org-agenda-type agenda
  4099. org-last-args (,arg ,start-day ,span)
  4100. org-redo-cmd ,org-agenda-redo-command
  4101. org-series-cmd ,org-cmd))
  4102. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4103. (org-agenda-show-clocking-issues))
  4104. (org-agenda-finalize)
  4105. (setq buffer-read-only t)
  4106. (message ""))))
  4107. (defun org-agenda-ndays-to-span (n)
  4108. "Return a span symbol for a span of N days, or N if none matches."
  4109. (cond ((symbolp n) n)
  4110. ((= n 1) 'day)
  4111. ((= n 7) 'week)
  4112. ((= n 14) 'fortnight)
  4113. (t n)))
  4114. (defun org-agenda-span-to-ndays (span &optional start-day)
  4115. "Return ndays from SPAN, possibly starting at START-DAY.
  4116. START-DAY is an absolute time value."
  4117. (cond ((numberp span) span)
  4118. ((eq span 'day) 1)
  4119. ((eq span 'week) 7)
  4120. ((eq span 'fortnight) 14)
  4121. ((eq span 'month)
  4122. (let ((date (calendar-gregorian-from-absolute start-day)))
  4123. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4124. ((eq span 'year)
  4125. (let ((date (calendar-gregorian-from-absolute start-day)))
  4126. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4127. (defun org-agenda-span-name (span)
  4128. "Return a SPAN name."
  4129. (if (null span)
  4130. ""
  4131. (if (symbolp span)
  4132. (capitalize (symbol-name span))
  4133. (format "%d days" span))))
  4134. ;;; Agenda word search
  4135. (defvar org-agenda-search-history nil)
  4136. (defvar org-search-syntax-table nil
  4137. "Special syntax table for Org search.
  4138. In this table, we have single quotes not as word constituents, to
  4139. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4140. (defvar org-mode-syntax-table) ; From org.el
  4141. (defun org-search-syntax-table ()
  4142. (unless org-search-syntax-table
  4143. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4144. (modify-syntax-entry ?' "." org-search-syntax-table)
  4145. (modify-syntax-entry ?` "." org-search-syntax-table))
  4146. org-search-syntax-table)
  4147. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4148. ;;;###autoload
  4149. (defun org-search-view (&optional todo-only string edit-at)
  4150. "Show all entries that contain a phrase or words or regular expressions.
  4151. With optional prefix argument TODO-ONLY, only consider entries that are
  4152. TODO entries. The argument STRING can be used to pass a default search
  4153. string into this function. If EDIT-AT is non-nil, it means that the
  4154. user should get a chance to edit this string, with cursor at position
  4155. EDIT-AT.
  4156. The search string can be viewed either as a phrase that should be found as
  4157. is, or it can be broken into a number of snippets, each of which must match
  4158. in a Boolean way to select an entry. The default depends on the variable
  4159. `org-agenda-search-view-always-boolean'.
  4160. Even if this is turned off (the default) you can always switch to
  4161. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4162. The default is a direct search of the whole phrase, where each space in
  4163. the search string can expand to an arbitrary amount of whitespace,
  4164. including newlines.
  4165. If using a Boolean search, the search string is split on whitespace and
  4166. each snippet is searched separately, with logical AND to select an entry.
  4167. Words prefixed with a minus must *not* occur in the entry. Words without
  4168. a prefix or prefixed with a plus must occur in the entry. Matching is
  4169. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4170. match whole words, not parts of a word) if
  4171. `org-agenda-search-view-force-full-words' is set (default is nil).
  4172. Boolean search snippets enclosed by curly braces are interpreted as
  4173. regular expressions that must or (when preceded with \"-\") must not
  4174. match in the entry. Snippets enclosed into double quotes will be taken
  4175. as a whole, to include whitespace.
  4176. - If the search string starts with an asterisk, search only in headlines.
  4177. - If (possibly after the leading star) the search string starts with an
  4178. exclamation mark, this also means to look at TODO entries only, an effect
  4179. that can also be achieved with a prefix argument.
  4180. - If (possibly after star and exclamation mark) the search string starts
  4181. with a colon, this will mean that the (non-regexp) snippets of the
  4182. Boolean search must match as full words.
  4183. This command searches the agenda files, and in addition the files
  4184. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4185. is active."
  4186. (interactive "P")
  4187. (when org-agenda-overriding-arguments
  4188. (setq todo-only (car org-agenda-overriding-arguments)
  4189. string (nth 1 org-agenda-overriding-arguments)
  4190. edit-at (nth 2 org-agenda-overriding-arguments)))
  4191. (let* ((props (list 'face nil
  4192. 'done-face 'org-agenda-done
  4193. 'org-not-done-regexp org-not-done-regexp
  4194. 'org-todo-regexp org-todo-regexp
  4195. 'org-complex-heading-regexp org-complex-heading-regexp
  4196. 'mouse-face 'highlight
  4197. 'help-echo "mouse-2 or RET jump to location"))
  4198. (full-words org-agenda-search-view-force-full-words)
  4199. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4200. regexp rtn rtnall files file pos inherited-tags
  4201. marker category level tags c neg re boolean
  4202. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4203. (unless (and (not edit-at)
  4204. (stringp string)
  4205. (string-match "\\S-" string))
  4206. (setq string (read-string
  4207. (if org-agenda-search-view-always-boolean
  4208. "[+-]Word/{Regexp} ...: "
  4209. "Phrase or [+-]Word/{Regexp} ...: ")
  4210. (cond
  4211. ((integerp edit-at) (cons string edit-at))
  4212. (edit-at string))
  4213. 'org-agenda-search-history)))
  4214. (catch 'exit
  4215. (setq org-agenda-buffer-name
  4216. (org-agenda--get-buffer-name
  4217. (and org-agenda-sticky
  4218. (if (stringp string)
  4219. (format "*Org Agenda(%s:%s)*"
  4220. (or org-keys (or (and todo-only "S") "s"))
  4221. string)
  4222. (format "*Org Agenda(%s)*"
  4223. (or (and todo-only "S") "s"))))))
  4224. (org-agenda-prepare "SEARCH")
  4225. (org-compile-prefix-format 'search)
  4226. (org-set-sorting-strategy 'search)
  4227. (setq org-agenda-redo-command
  4228. (list 'org-search-view (if todo-only t nil)
  4229. (list 'if 'current-prefix-arg nil string)))
  4230. (setq org-agenda-query-string string)
  4231. (if (equal (string-to-char string) ?*)
  4232. (setq hdl-only t
  4233. words (substring string 1))
  4234. (setq words string))
  4235. (when (equal (string-to-char words) ?!)
  4236. (setq todo-only t
  4237. words (substring words 1)))
  4238. (when (equal (string-to-char words) ?:)
  4239. (setq full-words t
  4240. words (substring words 1)))
  4241. (when (or org-agenda-search-view-always-boolean
  4242. (member (string-to-char words) '(?- ?+ ?\{)))
  4243. (setq boolean t))
  4244. (setq words (split-string words))
  4245. (let (www w)
  4246. (while (setq w (pop words))
  4247. (while (and (string-match "\\\\\\'" w) words)
  4248. (setq w (concat (substring w 0 -1) " " (pop words))))
  4249. (push w www))
  4250. (setq words (nreverse www) www nil)
  4251. (while (setq w (pop words))
  4252. (when (and (string-match "\\`[-+]?{" w)
  4253. (not (string-match "}\\'" w)))
  4254. (while (and words (not (string-match "}\\'" (car words))))
  4255. (setq w (concat w " " (pop words))))
  4256. (setq w (concat w " " (pop words))))
  4257. (push w www))
  4258. (setq words (nreverse www)))
  4259. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4260. (when boolean
  4261. (let (wds w)
  4262. (while (setq w (pop words))
  4263. (when (or (equal (substring w 0 1) "\"")
  4264. (and (> (length w) 1)
  4265. (member (substring w 0 1) '("+" "-"))
  4266. (equal (substring w 1 2) "\"")))
  4267. (while (and words (not (equal (substring w -1) "\"")))
  4268. (setq w (concat w " " (pop words)))))
  4269. (and (string-match "\\`\\([-+]?\\)\"" w)
  4270. (setq w (replace-match "\\1" nil nil w)))
  4271. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4272. (push w wds))
  4273. (setq words (nreverse wds))))
  4274. (if boolean
  4275. (mapc (lambda (w)
  4276. (setq c (string-to-char w))
  4277. (if (equal c ?-)
  4278. (setq neg t w (substring w 1))
  4279. (if (equal c ?+)
  4280. (setq neg nil w (substring w 1))
  4281. (setq neg nil)))
  4282. (if (string-match "\\`{.*}\\'" w)
  4283. (setq re (substring w 1 -1))
  4284. (if full-words
  4285. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4286. (setq re (regexp-quote (downcase w)))))
  4287. (if neg (push re regexps-) (push re regexps+)))
  4288. words)
  4289. (push (mapconcat #'regexp-quote words "\\s-+")
  4290. regexps+))
  4291. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4292. (if (not regexps+)
  4293. (setq regexp org-outline-regexp-bol)
  4294. (setq regexp (pop regexps+))
  4295. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4296. regexp))))
  4297. (setq files (org-agenda-files nil 'ifmode))
  4298. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4299. ;; restriction.
  4300. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4301. (pop org-agenda-text-search-extra-files)
  4302. (unless (get 'org-agenda-files 'org-restrict)
  4303. (setq files (org-add-archive-files files))))
  4304. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4305. ;; non-existent ones.
  4306. (setq files (cl-remove-duplicates
  4307. (append files org-agenda-text-search-extra-files)
  4308. :test (lambda (a b)
  4309. (and (file-exists-p a)
  4310. (file-exists-p b)
  4311. (file-equal-p a b))))
  4312. rtnall nil)
  4313. (while (setq file (pop files))
  4314. (setq ee nil)
  4315. (catch 'nextfile
  4316. (org-check-agenda-file file)
  4317. (setq buffer (if (file-exists-p file)
  4318. (org-get-agenda-file-buffer file)
  4319. (error "No such file %s" file)))
  4320. (unless buffer
  4321. ;; If file does not exist, make sure an error message is sent
  4322. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4323. file))))
  4324. (with-current-buffer buffer
  4325. (with-syntax-table (org-search-syntax-table)
  4326. (unless (derived-mode-p 'org-mode)
  4327. (error "Agenda file %s is not in Org mode" file))
  4328. (let ((case-fold-search t))
  4329. (save-excursion
  4330. (save-restriction
  4331. (if (eq buffer org-agenda-restrict)
  4332. (narrow-to-region org-agenda-restrict-begin
  4333. org-agenda-restrict-end)
  4334. (widen))
  4335. (goto-char (point-min))
  4336. (unless (or (org-at-heading-p)
  4337. (outline-next-heading))
  4338. (throw 'nextfile t))
  4339. (goto-char (max (point-min) (1- (point))))
  4340. (while (re-search-forward regexp nil t)
  4341. (org-back-to-heading t)
  4342. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4343. (> (org-reduced-level (org-outline-level))
  4344. org-agenda-search-view-max-outline-level)
  4345. (forward-line -1)
  4346. (org-back-to-heading t)))
  4347. (skip-chars-forward "* ")
  4348. (setq beg (line-beginning-position)
  4349. beg1 (point)
  4350. end (progn
  4351. (outline-next-heading)
  4352. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4353. (> (org-reduced-level (org-outline-level))
  4354. org-agenda-search-view-max-outline-level)
  4355. (forward-line 1)
  4356. (outline-next-heading)))
  4357. (point)))
  4358. (catch :skip
  4359. (goto-char beg)
  4360. (org-agenda-skip)
  4361. (setq str (buffer-substring-no-properties
  4362. (line-beginning-position)
  4363. (if hdl-only (line-end-position) end)))
  4364. (mapc (lambda (wr) (when (string-match wr str)
  4365. (goto-char (1- end))
  4366. (throw :skip t)))
  4367. regexps-)
  4368. (mapc (lambda (wr) (unless (string-match wr str)
  4369. (goto-char (1- end))
  4370. (throw :skip t)))
  4371. (if todo-only
  4372. (cons (concat "^\\*+[ \t]+"
  4373. org-not-done-regexp)
  4374. regexps+)
  4375. regexps+))
  4376. (goto-char beg)
  4377. (setq marker (org-agenda-new-marker (point))
  4378. category (org-get-category)
  4379. level (make-string (org-reduced-level (org-outline-level)) ? )
  4380. inherited-tags
  4381. (or (eq org-agenda-show-inherited-tags 'always)
  4382. (and (listp org-agenda-show-inherited-tags)
  4383. (memq 'todo org-agenda-show-inherited-tags))
  4384. (and (eq org-agenda-show-inherited-tags t)
  4385. (or (eq org-agenda-use-tag-inheritance t)
  4386. (memq 'todo org-agenda-use-tag-inheritance))))
  4387. tags (org-get-tags nil (not inherited-tags))
  4388. txt (org-agenda-format-item
  4389. ""
  4390. (buffer-substring-no-properties
  4391. beg1 (line-end-position))
  4392. level category tags t))
  4393. (org-add-props txt props
  4394. 'org-marker marker 'org-hd-marker marker
  4395. 'org-todo-regexp org-todo-regexp
  4396. 'level level
  4397. 'org-complex-heading-regexp org-complex-heading-regexp
  4398. 'priority 1000
  4399. 'type "search")
  4400. (push txt ee)
  4401. (goto-char (1- end))))))))))
  4402. (setq rtn (nreverse ee))
  4403. (setq rtnall (append rtnall rtn)))
  4404. (org-agenda--insert-overriding-header
  4405. (with-temp-buffer
  4406. (insert "Search words: ")
  4407. (add-text-properties (point-min) (1- (point))
  4408. (list 'face 'org-agenda-structure))
  4409. (setq pos (point))
  4410. (insert string "\n")
  4411. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4412. (setq pos (point))
  4413. (unless org-agenda-multi
  4414. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4415. Press `\\[org-agenda-manipulate-query-add]', \
  4416. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4417. `\\[org-agenda-manipulate-query-add-re]', \
  4418. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4419. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4420. (add-text-properties pos (1- (point))
  4421. (list 'face 'org-agenda-structure-secondary)))
  4422. (buffer-string)))
  4423. (org-agenda-mark-header-line (point-min))
  4424. (when rtnall
  4425. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4426. (goto-char (point-min))
  4427. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4428. (add-text-properties (point-min) (point-max)
  4429. `(org-agenda-type search
  4430. org-last-args (,todo-only ,string ,edit-at)
  4431. org-redo-cmd ,org-agenda-redo-command
  4432. org-series-cmd ,org-cmd))
  4433. (org-agenda-finalize)
  4434. (setq buffer-read-only t))))
  4435. ;;; Agenda TODO list
  4436. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4437. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4438. (concat
  4439. (if (or (equal keywords "ALL") (not keywords))
  4440. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4441. (mapconcat
  4442. (lambda (kw)
  4443. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4444. (org-split-string keywords "|")
  4445. "|"))
  4446. "\n"))
  4447. (defvar org-select-this-todo-keyword nil)
  4448. (defvar org-last-arg nil)
  4449. (defvar crm-separator)
  4450. ;;;###autoload
  4451. (defun org-todo-list (&optional arg)
  4452. "Show all (not done) TODO entries from all agenda files in a single list.
  4453. The prefix arg can be used to select a specific TODO keyword and limit
  4454. the list to these. When using `\\[universal-argument]', you will be prompted
  4455. for a keyword. A numeric prefix directly selects the Nth keyword in
  4456. `org-todo-keywords-1'."
  4457. (interactive "P")
  4458. (when org-agenda-overriding-arguments
  4459. (setq arg org-agenda-overriding-arguments))
  4460. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4461. (let* ((today (org-today))
  4462. (date (calendar-gregorian-from-absolute today))
  4463. (completion-ignore-case t)
  4464. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4465. (catch 'exit
  4466. (setq org-agenda-buffer-name
  4467. (org-agenda--get-buffer-name
  4468. (and org-agenda-sticky
  4469. (if (stringp org-select-this-todo-keyword)
  4470. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4471. org-select-this-todo-keyword)
  4472. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4473. (org-agenda-prepare "TODO")
  4474. (setq kwds org-todo-keywords-for-agenda
  4475. org-select-this-todo-keyword (if (stringp arg) arg
  4476. (and (integerp arg)
  4477. (> arg 0)
  4478. (nth (1- arg) kwds))))
  4479. (when (equal arg '(4))
  4480. (setq org-select-this-todo-keyword
  4481. (mapconcat #'identity
  4482. (let ((crm-separator "|"))
  4483. (completing-read-multiple
  4484. "Keyword (or KWD1|KWD2|...): "
  4485. (mapcar #'list kwds) nil nil))
  4486. "|")))
  4487. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4488. (org-compile-prefix-format 'todo)
  4489. (org-set-sorting-strategy 'todo)
  4490. (setq org-agenda-redo-command
  4491. `(org-todo-list (or (and (numberp current-prefix-arg)
  4492. current-prefix-arg)
  4493. ,org-select-this-todo-keyword
  4494. current-prefix-arg ,arg)))
  4495. (setq files (org-agenda-files nil 'ifmode)
  4496. rtnall nil)
  4497. (while (setq file (pop files))
  4498. (catch 'nextfile
  4499. (org-check-agenda-file file)
  4500. (setq rtn (org-agenda-get-day-entries file date :todo))
  4501. (setq rtnall (append rtnall rtn))))
  4502. (org-agenda--insert-overriding-header
  4503. (with-temp-buffer
  4504. (insert "Global list of TODO items of type: ")
  4505. (add-text-properties (point-min) (1- (point))
  4506. (list 'face 'org-agenda-structure
  4507. 'short-heading
  4508. (concat "ToDo: "
  4509. (or org-select-this-todo-keyword "ALL"))))
  4510. (org-agenda-mark-header-line (point-min))
  4511. (insert (org-agenda-propertize-selected-todo-keywords
  4512. org-select-this-todo-keyword))
  4513. (setq pos (point))
  4514. (unless org-agenda-multi
  4515. (insert (substitute-command-keys "Press \
  4516. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4517. to search again: (0)[ALL]"))
  4518. (let ((n 0))
  4519. (dolist (k kwds)
  4520. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4521. (when (> (+ (current-column) (string-width s) 1) (window-width))
  4522. (insert "\n "))
  4523. (insert " " s))))
  4524. (insert "\n"))
  4525. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4526. (buffer-string)))
  4527. (org-agenda-mark-header-line (point-min))
  4528. (when rtnall
  4529. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4530. (goto-char (point-min))
  4531. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4532. (add-text-properties (point-min) (point-max)
  4533. `(org-agenda-type todo
  4534. org-last-args ,arg
  4535. org-redo-cmd ,org-agenda-redo-command
  4536. org-series-cmd ,org-cmd))
  4537. (org-agenda-finalize)
  4538. (setq buffer-read-only t))))
  4539. ;;; Agenda tags match
  4540. ;;;###autoload
  4541. (defun org-tags-view (&optional todo-only match)
  4542. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4543. The prefix arg TODO-ONLY limits the search to TODO entries."
  4544. (interactive "P")
  4545. (when org-agenda-overriding-arguments
  4546. (setq todo-only (car org-agenda-overriding-arguments)
  4547. match (nth 1 org-agenda-overriding-arguments)))
  4548. (let* ((org-tags-match-list-sublevels
  4549. org-tags-match-list-sublevels)
  4550. (completion-ignore-case t)
  4551. (org--matcher-tags-todo-only todo-only)
  4552. rtn rtnall files file pos matcher
  4553. buffer)
  4554. (when (and (stringp match) (not (string-match "\\S-" match)))
  4555. (setq match nil))
  4556. (catch 'exit
  4557. (setq org-agenda-buffer-name
  4558. (org-agenda--get-buffer-name
  4559. (and org-agenda-sticky
  4560. (if (stringp match)
  4561. (format "*Org Agenda(%s:%s)*"
  4562. (or org-keys (or (and todo-only "M") "m"))
  4563. match)
  4564. (format "*Org Agenda(%s)*"
  4565. (or (and todo-only "M") "m"))))))
  4566. (setq matcher (org-make-tags-matcher match))
  4567. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4568. ;; expanding tags within `org-make-tags-matcher'
  4569. (org-agenda-prepare (concat "TAGS " match))
  4570. (setq match (car matcher)
  4571. matcher (cdr matcher))
  4572. (org-compile-prefix-format 'tags)
  4573. (org-set-sorting-strategy 'tags)
  4574. (setq org-agenda-query-string match)
  4575. (setq org-agenda-redo-command
  4576. (list 'org-tags-view
  4577. `(quote ,org--matcher-tags-todo-only)
  4578. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4579. (setq files (org-agenda-files nil 'ifmode)
  4580. rtnall nil)
  4581. (while (setq file (pop files))
  4582. (catch 'nextfile
  4583. (org-check-agenda-file file)
  4584. (setq buffer (if (file-exists-p file)
  4585. (org-get-agenda-file-buffer file)
  4586. (error "No such file %s" file)))
  4587. (if (not buffer)
  4588. ;; If file does not exist, error message to agenda
  4589. (setq rtn (list
  4590. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4591. rtnall (append rtnall rtn))
  4592. (with-current-buffer buffer
  4593. (unless (derived-mode-p 'org-mode)
  4594. (error "Agenda file %s is not in Org mode" file))
  4595. (save-excursion
  4596. (save-restriction
  4597. (if (eq buffer org-agenda-restrict)
  4598. (narrow-to-region org-agenda-restrict-begin
  4599. org-agenda-restrict-end)
  4600. (widen))
  4601. (setq rtn (org-scan-tags 'agenda
  4602. matcher
  4603. org--matcher-tags-todo-only))
  4604. (setq rtnall (append rtnall rtn))))))))
  4605. (org-agenda--insert-overriding-header
  4606. (with-temp-buffer
  4607. (insert "Headlines with TAGS match: ")
  4608. (add-text-properties (point-min) (1- (point))
  4609. (list 'face 'org-agenda-structure
  4610. 'short-heading
  4611. (concat "Match: " match)))
  4612. (setq pos (point))
  4613. (insert match "\n")
  4614. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4615. (setq pos (point))
  4616. (unless org-agenda-multi
  4617. (insert (substitute-command-keys
  4618. "Press \
  4619. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4620. to search again\n")))
  4621. (add-text-properties pos (1- (point))
  4622. (list 'face 'org-agenda-structure-secondary))
  4623. (buffer-string)))
  4624. (org-agenda-mark-header-line (point-min))
  4625. (when rtnall
  4626. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4627. (goto-char (point-min))
  4628. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4629. (add-text-properties
  4630. (point-min) (point-max)
  4631. `(org-agenda-type tags
  4632. org-last-args (,org--matcher-tags-todo-only ,match)
  4633. org-redo-cmd ,org-agenda-redo-command
  4634. org-series-cmd ,org-cmd))
  4635. (org-agenda-finalize)
  4636. (setq buffer-read-only t))))
  4637. ;;; Agenda Finding stuck projects
  4638. (defvar org-agenda-skip-regexp nil
  4639. "Regular expression used in skipping subtrees for the agenda.
  4640. This is basically a temporary global variable that can be set and then
  4641. used by user-defined selections using `org-agenda-skip-function'.")
  4642. (defvar org-agenda-overriding-header nil
  4643. "When set during agenda, todo and tags searches it replaces the header.
  4644. If an empty string, no header will be inserted. If any other
  4645. string, it will be inserted as a header. If a function, insert
  4646. the string returned by the function as a header. If nil, a
  4647. header will be generated automatically according to the command.
  4648. This variable should not be set directly, but custom commands can
  4649. bind it in the options section.")
  4650. (defun org-agenda-skip-entry-if (&rest conditions)
  4651. "Skip entry if any of CONDITIONS is true.
  4652. See `org-agenda-skip-if' for details."
  4653. (org-agenda-skip-if nil conditions))
  4654. (defun org-agenda-skip-subtree-if (&rest conditions)
  4655. "Skip subtree if any of CONDITIONS is true.
  4656. See `org-agenda-skip-if' for details."
  4657. (org-agenda-skip-if t conditions))
  4658. (defun org-agenda-skip-if (subtree conditions)
  4659. "Check current entity for CONDITIONS.
  4660. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4661. the entry (i.e. the text before the next heading) is checked.
  4662. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4663. from different tests. Valid conditions are:
  4664. scheduled Check if there is a scheduled cookie
  4665. notscheduled Check if there is no scheduled cookie
  4666. deadline Check if there is a deadline
  4667. notdeadline Check if there is no deadline
  4668. timestamp Check if there is a timestamp (also deadline or scheduled)
  4669. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4670. regexp Check if regexp matches
  4671. notregexp Check if regexp does not match.
  4672. todo Check if TODO keyword matches
  4673. nottodo Check if TODO keyword does not match
  4674. The regexp is taken from the conditions list, it must come right after
  4675. the `regexp' or `notregexp' element.
  4676. `todo' and `nottodo' accept as an argument a list of todo
  4677. keywords, which may include \"*\" to match any todo keyword.
  4678. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4679. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4680. Instead of a list, a keyword class may be given. For example:
  4681. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4682. would skip entries that haven't been marked with any of \"DONE\"
  4683. keywords. Possible classes are: `todo', `done', `any'.
  4684. If any of these conditions is met, this function returns the end point of
  4685. the entity, causing the search to continue from there. This is a function
  4686. that can be put into `org-agenda-skip-function' for the duration of a command."
  4687. (org-back-to-heading t)
  4688. (let* (;; (beg (point))
  4689. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4690. (org-entry-end-position)))
  4691. (planning-end (if subtree end (line-end-position 2)))
  4692. m)
  4693. (and
  4694. (or (and (memq 'scheduled conditions)
  4695. (re-search-forward org-scheduled-time-regexp planning-end t))
  4696. (and (memq 'notscheduled conditions)
  4697. (not
  4698. (save-excursion
  4699. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4700. (and (memq 'deadline conditions)
  4701. (re-search-forward org-deadline-time-regexp planning-end t))
  4702. (and (memq 'notdeadline conditions)
  4703. (not
  4704. (save-excursion
  4705. (re-search-forward org-deadline-time-regexp planning-end t))))
  4706. (and (memq 'timestamp conditions)
  4707. (re-search-forward org-ts-regexp end t))
  4708. (and (memq 'nottimestamp conditions)
  4709. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4710. (and (setq m (memq 'regexp conditions))
  4711. (stringp (nth 1 m))
  4712. (re-search-forward (nth 1 m) end t))
  4713. (and (setq m (memq 'notregexp conditions))
  4714. (stringp (nth 1 m))
  4715. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4716. (and (or
  4717. (setq m (memq 'nottodo conditions))
  4718. (setq m (memq 'todo-unblocked conditions))
  4719. (setq m (memq 'nottodo-unblocked conditions))
  4720. (setq m (memq 'todo conditions)))
  4721. (org-agenda-skip-if-todo m end)))
  4722. end)))
  4723. (defun org-agenda-skip-if-todo (args end)
  4724. "Helper function for `org-agenda-skip-if', do not use it directly.
  4725. ARGS is a list with first element either `todo', `nottodo',
  4726. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4727. a list of TODO keywords, or a state symbol `todo' or `done' or
  4728. `any'."
  4729. (let ((todo-re
  4730. (concat "^\\*+[ \t]+"
  4731. (regexp-opt
  4732. (pcase args
  4733. (`(,_ todo)
  4734. (org-delete-all org-done-keywords
  4735. (copy-sequence org-todo-keywords-1)))
  4736. (`(,_ done) org-done-keywords)
  4737. (`(,_ any) org-todo-keywords-1)
  4738. (`(,_ ,(pred atom))
  4739. (error "Invalid TODO class or type: %S" args))
  4740. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4741. (`(,_ ,todo-list) todo-list))
  4742. 'words))))
  4743. (pcase args
  4744. (`(todo . ,_)
  4745. (let (case-fold-search) (re-search-forward todo-re end t)))
  4746. (`(nottodo . ,_)
  4747. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4748. (`(todo-unblocked . ,_)
  4749. (catch :unblocked
  4750. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4751. (when (org-entry-blocked-p) (throw :unblocked t)))
  4752. nil))
  4753. (`(nottodo-unblocked . ,_)
  4754. (catch :unblocked
  4755. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4756. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4757. t))
  4758. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4759. ;;;###autoload
  4760. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4761. "Create agenda view for projects that are stuck.
  4762. Stuck projects are project that have no next actions. For the definitions
  4763. of what a project is and how to check if it stuck, customize the variable
  4764. `org-stuck-projects'."
  4765. (interactive)
  4766. (let* ((org-agenda-overriding-header
  4767. (or org-agenda-overriding-header "List of stuck projects: "))
  4768. (matcher (nth 0 org-stuck-projects))
  4769. (todo (nth 1 org-stuck-projects))
  4770. (tags (nth 2 org-stuck-projects))
  4771. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4772. (todo-wds
  4773. (if (not (member "*" todo)) todo
  4774. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4775. (org-delete-all org-done-keywords-for-agenda
  4776. (copy-sequence org-todo-keywords-for-agenda))))
  4777. (todo-re (and todo
  4778. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4779. (mapconcat #'identity todo-wds "\\|"))))
  4780. (tags-re (cond ((null tags) nil)
  4781. ((member "*" tags) org-tag-line-re)
  4782. (tags
  4783. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4784. (concat org-outline-regexp-bol
  4785. ".*?[ \t]:"
  4786. other-tags
  4787. (regexp-opt tags t)
  4788. ":" other-tags "[ \t]*$")))
  4789. (t nil)))
  4790. (re-list (delq nil (list todo-re tags-re gen-re)))
  4791. (skip-re
  4792. (if (null re-list)
  4793. (error "Missing information to identify unstuck projects")
  4794. (mapconcat #'identity re-list "\\|")))
  4795. (org-agenda-skip-function
  4796. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4797. ;; in the subtree.
  4798. (lambda ()
  4799. (and (save-excursion
  4800. (let ((case-fold-search nil))
  4801. (re-search-forward
  4802. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4803. (progn (outline-next-heading) (point))))))
  4804. (org-tags-view nil matcher)
  4805. (setq org-agenda-buffer-name (buffer-name))
  4806. (with-current-buffer org-agenda-buffer-name
  4807. (setq org-agenda-redo-command
  4808. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4809. (let ((inhibit-read-only t))
  4810. (add-text-properties
  4811. (point-min) (point-max)
  4812. `(org-redo-cmd ,org-agenda-redo-command))))))
  4813. ;;; Diary integration
  4814. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4815. (defvar diary-list-entries-hook)
  4816. (defvar diary-time-regexp)
  4817. (defvar diary-modify-entry-list-string-function)
  4818. (defvar diary-file-name-prefix)
  4819. (defvar diary-display-function)
  4820. (defun org-get-entries-from-diary (date)
  4821. "Get the (Emacs Calendar) diary entries for DATE."
  4822. (require 'diary-lib)
  4823. (declare-function diary-fancy-display "diary-lib" ())
  4824. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4825. (diary-display-function #'diary-fancy-display)
  4826. (pop-up-frames nil)
  4827. (diary-list-entries-hook
  4828. (cons 'org-diary-default-entry diary-list-entries-hook))
  4829. (diary-file-name-prefix nil) ; turn this feature off
  4830. (diary-modify-entry-list-string-function
  4831. #'org-modify-diary-entry-string)
  4832. (diary-time-regexp (concat "^" diary-time-regexp))
  4833. entries
  4834. (org-disable-agenda-to-diary t))
  4835. (save-excursion
  4836. (save-window-excursion
  4837. (diary-list-entries date 1)))
  4838. (if (not (get-buffer diary-fancy-buffer))
  4839. (setq entries nil)
  4840. (with-current-buffer diary-fancy-buffer
  4841. (setq buffer-read-only nil)
  4842. (if (zerop (buffer-size))
  4843. ;; No entries
  4844. (setq entries nil)
  4845. ;; Omit the date and other unnecessary stuff
  4846. (org-agenda-cleanup-fancy-diary)
  4847. ;; Add prefix to each line and extend the text properties
  4848. (if (zerop (buffer-size))
  4849. (setq entries nil)
  4850. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4851. (setq entries
  4852. (with-temp-buffer
  4853. (insert entries) (goto-char (point-min))
  4854. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4855. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4856. (replace-match (concat "; " (match-string 1)))))
  4857. (buffer-string)))))
  4858. (set-buffer-modified-p nil)
  4859. (kill-buffer diary-fancy-buffer)))
  4860. (when entries
  4861. (setq entries (org-split-string entries "\n"))
  4862. (setq entries
  4863. (mapcar
  4864. (lambda (x)
  4865. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4866. ;; Extend the text properties to the beginning of the line
  4867. (org-add-props x (text-properties-at (1- (length x)) x)
  4868. 'type "diary" 'date date 'face 'org-agenda-diary))
  4869. entries)))))
  4870. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4871. "Hook run when the fancy diary buffer is cleaned up.")
  4872. (defun org-agenda-cleanup-fancy-diary ()
  4873. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4874. This gets rid of the date, the underline under the date, and the
  4875. dummy entry installed by Org mode to ensure non-empty diary for
  4876. each date. It also removes lines that contain only whitespace."
  4877. (goto-char (point-min))
  4878. (if (looking-at ".*?:[ \t]*")
  4879. (progn
  4880. (replace-match "")
  4881. (re-search-forward "\n=+$" nil t)
  4882. (replace-match "")
  4883. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4884. (re-search-forward "\n=+$" nil t)
  4885. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4886. (goto-char (point-min))
  4887. (while (re-search-forward "^ +\n" nil t)
  4888. (replace-match ""))
  4889. (goto-char (point-min))
  4890. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4891. (replace-match ""))
  4892. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4893. (defun org-modify-diary-entry-string (string)
  4894. "Add text properties to string, allowing Org to act on it."
  4895. (org-add-props string nil
  4896. 'mouse-face 'highlight
  4897. 'help-echo (if buffer-file-name
  4898. (format "mouse-2 or RET jump to diary file %s"
  4899. (abbreviate-file-name buffer-file-name))
  4900. "")
  4901. 'org-agenda-diary-link t
  4902. 'org-marker (org-agenda-new-marker (line-beginning-position))))
  4903. (defun org-diary-default-entry ()
  4904. "Add a dummy entry to the diary.
  4905. Needed to avoid empty dates which mess up holiday display."
  4906. ;; Catch the error if dealing with the new add-to-diary-alist
  4907. (when org-disable-agenda-to-diary
  4908. (diary-add-to-list original-date "Org mode dummy" "")))
  4909. (defvar org-diary-last-run-time nil)
  4910. ;;;###autoload
  4911. (defun org-diary (&rest args)
  4912. "Return diary information from org files.
  4913. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4914. It accesses org files and extracts information from those files to be
  4915. listed in the diary. The function accepts arguments specifying what
  4916. items should be listed. For a list of arguments allowed here, see the
  4917. variable `org-agenda-entry-types'.
  4918. The call in the diary file should look like this:
  4919. &%%(org-diary) ~/path/to/some/orgfile.org
  4920. Use a separate line for each org file to check. Or, if you omit the file name,
  4921. all files listed in `org-agenda-files' will be checked automatically:
  4922. &%%(org-diary)
  4923. If you don't give any arguments (as in the example above), the default value
  4924. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4925. So the example above may also be written as
  4926. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4927. The function expects the lisp variables `entry' and `date' to be provided
  4928. by the caller, because this is how the calendar works. Don't use this
  4929. function from a program - use `org-agenda-get-day-entries' instead."
  4930. (with-no-warnings (defvar date) (defvar entry))
  4931. (when (> (- (float-time)
  4932. org-agenda-last-marker-time)
  4933. 5)
  4934. ;; I am not sure if this works with sticky agendas, because the marker
  4935. ;; list is then no longer a global variable.
  4936. (org-agenda-reset-markers))
  4937. (org-compile-prefix-format 'agenda)
  4938. (org-set-sorting-strategy 'agenda)
  4939. (setq args (or args org-agenda-entry-types))
  4940. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4941. (list entry)
  4942. (org-agenda-files t)))
  4943. (time (float-time))
  4944. file rtn results)
  4945. (when (or (not org-diary-last-run-time)
  4946. (> (- time
  4947. org-diary-last-run-time)
  4948. 3))
  4949. (org-agenda-prepare-buffers files))
  4950. (setq org-diary-last-run-time time)
  4951. ;; If this is called during org-agenda, don't return any entries to
  4952. ;; the calendar. Org Agenda will list these entries itself.
  4953. (when org-disable-agenda-to-diary (setq files nil))
  4954. (while (setq file (pop files))
  4955. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4956. (setq results (append results rtn)))
  4957. (when results
  4958. (setq results
  4959. (mapcar (lambda (i) (replace-regexp-in-string
  4960. org-link-bracket-re "\\2" i))
  4961. results))
  4962. (concat (org-agenda-finalize-entries results) "\n"))))
  4963. ;;; Agenda entry finders
  4964. (defun org-agenda--timestamp-to-absolute (&rest args)
  4965. "Call `org-time-string-to-absolute' with ARGS.
  4966. However, throw `:skip' whenever an error is raised."
  4967. (condition-case e
  4968. (apply #'org-time-string-to-absolute args)
  4969. (org-diary-sexp-no-match (throw :skip nil))
  4970. (error
  4971. (message "%s; Skipping entry" (error-message-string e))
  4972. (throw :skip nil))))
  4973. (defun org-agenda-get-day-entries (file date &rest args)
  4974. "Does the work for `org-diary' and `org-agenda'.
  4975. FILE is the path to a file to be checked for entries. DATE is date like
  4976. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4977. which kind of entries should be extracted. For details about these, see
  4978. the documentation of `org-diary'."
  4979. (let* ((org-startup-folded nil)
  4980. (org-startup-align-all-tables nil)
  4981. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4982. (error "No such file %s" file))))
  4983. (if (not buffer)
  4984. ;; If file does not exist, signal it in diary nonetheless.
  4985. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4986. (with-current-buffer buffer
  4987. (unless (derived-mode-p 'org-mode)
  4988. (error "Agenda file %s is not in Org mode" file))
  4989. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4990. (setf org-agenda-current-date date)
  4991. (save-excursion
  4992. (save-restriction
  4993. (if (eq buffer org-agenda-restrict)
  4994. (narrow-to-region org-agenda-restrict-begin
  4995. org-agenda-restrict-end)
  4996. (widen))
  4997. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4998. ;; first in order to populate DEADLINES before passing it.
  4999. ;;
  5000. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5001. ;; guarding us from modifying `org-agenda-entry-types'.
  5002. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5003. (when (and (memq :scheduled args) (memq :scheduled* args))
  5004. (setf args (delq :scheduled* args)))
  5005. (cond
  5006. ((memq :deadline args)
  5007. (setf args (cons :deadline
  5008. (delq :deadline (delq :deadline* args)))))
  5009. ((memq :deadline* args)
  5010. (setf args (cons :deadline* (delq :deadline* args)))))
  5011. ;; Collect list of headlines. Return them flattened.
  5012. (let ((case-fold-search nil) results deadlines)
  5013. (org-dlet
  5014. ((date date))
  5015. (dolist (arg args (apply #'nconc (nreverse results)))
  5016. (pcase arg
  5017. ((and :todo (guard (org-agenda-today-p date)))
  5018. (push (org-agenda-get-todos) results))
  5019. (:timestamp
  5020. (push (org-agenda-get-blocks) results)
  5021. (push (org-agenda-get-timestamps deadlines) results))
  5022. (:sexp
  5023. (push (org-agenda-get-sexps) results))
  5024. (:scheduled
  5025. (push (org-agenda-get-scheduled deadlines) results))
  5026. (:scheduled*
  5027. (push (org-agenda-get-scheduled deadlines t) results))
  5028. (:closed
  5029. (push (org-agenda-get-progress) results))
  5030. (:deadline
  5031. (setf deadlines (org-agenda-get-deadlines))
  5032. (push deadlines results))
  5033. (:deadline*
  5034. (setf deadlines (org-agenda-get-deadlines t))
  5035. (push deadlines results))))))))))))
  5036. (defsubst org-em (x y list)
  5037. "Is X or Y a member of LIST?"
  5038. (or (memq x list) (memq y list)))
  5039. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5040. (defvar org-agenda-sorting-strategy-selected nil)
  5041. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5042. "Retrieve timestamp information for sorting agenda views.
  5043. Given a point or marker POM, returns a cons cell of the timestamp
  5044. and the timestamp type relevant for the sorting strategy in
  5045. `org-agenda-sorting-strategy-selected'."
  5046. (let (ts ts-date-type)
  5047. (save-match-data
  5048. (cond ((org-em 'scheduled-up 'scheduled-down
  5049. org-agenda-sorting-strategy-selected)
  5050. (setq ts (org-entry-get pom "SCHEDULED")
  5051. ts-date-type " scheduled"))
  5052. ((org-em 'deadline-up 'deadline-down
  5053. org-agenda-sorting-strategy-selected)
  5054. (setq ts (org-entry-get pom "DEADLINE")
  5055. ts-date-type " deadline"))
  5056. ((org-em 'ts-up 'ts-down
  5057. org-agenda-sorting-strategy-selected)
  5058. (setq ts (org-entry-get pom "TIMESTAMP")
  5059. ts-date-type " timestamp"))
  5060. ((org-em 'tsia-up 'tsia-down
  5061. org-agenda-sorting-strategy-selected)
  5062. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5063. ts-date-type " timestamp_ia"))
  5064. ((org-em 'timestamp-up 'timestamp-down
  5065. org-agenda-sorting-strategy-selected)
  5066. (setq ts (or (org-entry-get pom "SCHEDULED")
  5067. (org-entry-get pom "DEADLINE")
  5068. (org-entry-get pom "TIMESTAMP")
  5069. (org-entry-get pom "TIMESTAMP_IA"))
  5070. ts-date-type ""))
  5071. (t (setq ts-date-type "")))
  5072. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5073. ts-date-type))))
  5074. (defun org-agenda-get-todos ()
  5075. "Return the TODO information for agenda display."
  5076. (let* ((props (list 'face nil
  5077. 'done-face 'org-agenda-done
  5078. 'org-not-done-regexp org-not-done-regexp
  5079. 'org-todo-regexp org-todo-regexp
  5080. 'org-complex-heading-regexp org-complex-heading-regexp
  5081. 'mouse-face 'highlight
  5082. 'help-echo
  5083. (format "mouse-2 or RET jump to org file %s"
  5084. (abbreviate-file-name buffer-file-name))))
  5085. (case-fold-search nil)
  5086. (regexp (format org-heading-keyword-regexp-format
  5087. (cond
  5088. ((and org-select-this-todo-keyword
  5089. (equal org-select-this-todo-keyword "*"))
  5090. org-todo-regexp)
  5091. (org-select-this-todo-keyword
  5092. (concat "\\("
  5093. (mapconcat #'identity
  5094. (org-split-string
  5095. org-select-this-todo-keyword
  5096. "|")
  5097. "\\|")
  5098. "\\)"))
  5099. (t org-not-done-regexp))))
  5100. marker priority category level tags todo-state
  5101. ts-date ts-date-type ts-date-pair
  5102. ee txt beg end inherited-tags todo-state-end-pos)
  5103. (goto-char (point-min))
  5104. (while (re-search-forward regexp nil t)
  5105. (catch :skip
  5106. (save-match-data
  5107. (beginning-of-line)
  5108. (org-agenda-skip)
  5109. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5110. (unless (and (setq todo-state (org-get-todo-state))
  5111. (setq todo-state-end-pos (match-end 2)))
  5112. (goto-char end)
  5113. (throw :skip nil))
  5114. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5115. (goto-char (1+ beg))
  5116. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5117. (throw :skip nil)))
  5118. (goto-char (match-beginning 2))
  5119. (setq marker (org-agenda-new-marker (match-beginning 0))
  5120. category (org-get-category)
  5121. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5122. ts-date (car ts-date-pair)
  5123. ts-date-type (cdr ts-date-pair)
  5124. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5125. inherited-tags
  5126. (or (eq org-agenda-show-inherited-tags 'always)
  5127. (and (listp org-agenda-show-inherited-tags)
  5128. (memq 'todo org-agenda-show-inherited-tags))
  5129. (and (eq org-agenda-show-inherited-tags t)
  5130. (or (eq org-agenda-use-tag-inheritance t)
  5131. (memq 'todo org-agenda-use-tag-inheritance))))
  5132. tags (org-get-tags nil (not inherited-tags))
  5133. level (make-string (org-reduced-level (org-outline-level)) ? )
  5134. txt (org-agenda-format-item "" txt level category tags t)
  5135. priority (1+ (org-get-priority txt)))
  5136. (org-add-props txt props
  5137. 'org-marker marker 'org-hd-marker marker
  5138. 'priority priority
  5139. 'level level
  5140. 'ts-date ts-date
  5141. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5142. (push txt ee)
  5143. (if org-agenda-todo-list-sublevels
  5144. (goto-char todo-state-end-pos)
  5145. (org-end-of-subtree 'invisible))))
  5146. (nreverse ee)))
  5147. (defun org-agenda-todo-custom-ignore-p (time n)
  5148. "Check whether timestamp is farther away than n number of days.
  5149. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5150. `org-agenda-todo-ignore-scheduled' or
  5151. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5152. (let ((days (org-time-stamp-to-now
  5153. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5154. (if (>= n 0)
  5155. (>= days n)
  5156. (<= days n))))
  5157. ;;;###autoload
  5158. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5159. (&optional end)
  5160. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5161. (when (or org-agenda-todo-ignore-with-date
  5162. org-agenda-todo-ignore-scheduled
  5163. org-agenda-todo-ignore-deadlines
  5164. org-agenda-todo-ignore-timestamp)
  5165. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5166. (save-excursion
  5167. (or (and org-agenda-todo-ignore-with-date
  5168. (re-search-forward org-ts-regexp end t))
  5169. (and org-agenda-todo-ignore-scheduled
  5170. (re-search-forward org-scheduled-time-regexp end t)
  5171. (cond
  5172. ((eq org-agenda-todo-ignore-scheduled 'future)
  5173. (> (org-time-stamp-to-now
  5174. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5175. 0))
  5176. ((eq org-agenda-todo-ignore-scheduled 'past)
  5177. (<= (org-time-stamp-to-now
  5178. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5179. 0))
  5180. ((numberp org-agenda-todo-ignore-scheduled)
  5181. (org-agenda-todo-custom-ignore-p
  5182. (match-string 1) org-agenda-todo-ignore-scheduled))
  5183. (t)))
  5184. (and org-agenda-todo-ignore-deadlines
  5185. (re-search-forward org-deadline-time-regexp end t)
  5186. (cond
  5187. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5188. ((eq org-agenda-todo-ignore-deadlines 'far)
  5189. (not (org-deadline-close-p (match-string 1))))
  5190. ((eq org-agenda-todo-ignore-deadlines 'future)
  5191. (> (org-time-stamp-to-now
  5192. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5193. 0))
  5194. ((eq org-agenda-todo-ignore-deadlines 'past)
  5195. (<= (org-time-stamp-to-now
  5196. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5197. 0))
  5198. ((numberp org-agenda-todo-ignore-deadlines)
  5199. (org-agenda-todo-custom-ignore-p
  5200. (match-string 1) org-agenda-todo-ignore-deadlines))
  5201. (t (org-deadline-close-p (match-string 1)))))
  5202. (and org-agenda-todo-ignore-timestamp
  5203. (let ((buffer (current-buffer))
  5204. (regexp
  5205. (concat
  5206. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5207. (start (point)))
  5208. ;; Copy current buffer into a temporary one
  5209. (with-temp-buffer
  5210. (insert-buffer-substring buffer start end)
  5211. (goto-char (point-min))
  5212. ;; Delete SCHEDULED and DEADLINE items
  5213. (while (re-search-forward regexp end t)
  5214. (delete-region (match-beginning 0) (match-end 0)))
  5215. (goto-char (point-min))
  5216. ;; No search for timestamp left
  5217. (when (re-search-forward org-ts-regexp nil t)
  5218. (cond
  5219. ((eq org-agenda-todo-ignore-timestamp 'future)
  5220. (> (org-time-stamp-to-now
  5221. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5222. 0))
  5223. ((eq org-agenda-todo-ignore-timestamp 'past)
  5224. (<= (org-time-stamp-to-now
  5225. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5226. 0))
  5227. ((numberp org-agenda-todo-ignore-timestamp)
  5228. (org-agenda-todo-custom-ignore-p
  5229. (match-string 1) org-agenda-todo-ignore-timestamp))
  5230. (t))))))))))
  5231. (defun org-agenda-get-timestamps (&optional deadlines)
  5232. "Return the date stamp information for agenda display.
  5233. Optional argument DEADLINES is a list of deadline items to be
  5234. displayed in agenda view."
  5235. (with-no-warnings (defvar date))
  5236. (let* ((props (list 'face 'org-agenda-calendar-event
  5237. 'org-not-done-regexp org-not-done-regexp
  5238. 'org-todo-regexp org-todo-regexp
  5239. 'org-complex-heading-regexp org-complex-heading-regexp
  5240. 'mouse-face 'highlight
  5241. 'help-echo
  5242. (format "mouse-2 or RET jump to Org file %s"
  5243. (abbreviate-file-name buffer-file-name))))
  5244. (current (calendar-absolute-from-gregorian date))
  5245. (today (org-today))
  5246. (deadline-position-alist
  5247. (mapcar (lambda (d)
  5248. (let ((m (get-text-property 0 'org-hd-marker d)))
  5249. (and m (marker-position m))))
  5250. deadlines))
  5251. ;; Match time-stamps set to current date, time-stamps with
  5252. ;; a repeater, and S-exp time-stamps.
  5253. (regexp
  5254. (concat
  5255. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5256. (regexp-quote
  5257. (substring
  5258. (format-time-string
  5259. (car org-time-stamp-formats)
  5260. (encode-time ; DATE bound by calendar
  5261. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5262. 1 11))
  5263. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5264. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5265. timestamp-items)
  5266. (goto-char (point-min))
  5267. (while (re-search-forward regexp nil t)
  5268. ;; Skip date ranges, scheduled and deadlines, which are handled
  5269. ;; specially. Also skip time-stamps before first headline as
  5270. ;; there would be no entry to add to the agenda. Eventually,
  5271. ;; ignore clock entries.
  5272. (catch :skip
  5273. (save-match-data
  5274. (when (or (org-at-date-range-p)
  5275. (org-at-planning-p)
  5276. (org-before-first-heading-p)
  5277. (and org-agenda-include-inactive-timestamps
  5278. (org-at-clock-log-p))
  5279. (not (org-at-timestamp-p 'agenda)))
  5280. (throw :skip nil))
  5281. (org-agenda-skip))
  5282. (let* ((pos (match-beginning 0))
  5283. (repeat (match-string 1))
  5284. (sexp-entry (match-string 3))
  5285. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5286. (save-excursion
  5287. (goto-char pos)
  5288. (looking-at org-ts-regexp-both)
  5289. (match-string 0))))
  5290. (todo-state (org-get-todo-state))
  5291. (warntime (get-text-property (point) 'org-appt-warntime))
  5292. (done? (member todo-state org-done-keywords)))
  5293. ;; Possibly skip done tasks.
  5294. (when (and done? org-agenda-skip-timestamp-if-done)
  5295. (throw :skip t))
  5296. ;; S-exp entry doesn't match current day: skip it.
  5297. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5298. (throw :skip nil))
  5299. (when repeat
  5300. (let* ((past
  5301. ;; A repeating time stamp is shown at its base
  5302. ;; date and every repeated date up to TODAY. If
  5303. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5304. ;; however, only the last repeat before today
  5305. ;; (inclusive) is shown.
  5306. (org-agenda--timestamp-to-absolute
  5307. repeat
  5308. (if (or (> current today)
  5309. (eq org-agenda-prefer-last-repeat t)
  5310. (member todo-state org-agenda-prefer-last-repeat))
  5311. today
  5312. current)
  5313. 'past (current-buffer) pos))
  5314. (future
  5315. ;; Display every repeated date past TODAY
  5316. ;; (exclusive) unless
  5317. ;; `org-agenda-show-future-repeats' is nil. If
  5318. ;; this variable is set to `next', only display
  5319. ;; the first repeated date after TODAY
  5320. ;; (exclusive).
  5321. (cond
  5322. ((<= current today) past)
  5323. ((not org-agenda-show-future-repeats) past)
  5324. (t
  5325. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5326. (1+ today)
  5327. current)))
  5328. (org-agenda--timestamp-to-absolute
  5329. repeat base 'future (current-buffer) pos))))))
  5330. (when (and (/= current past) (/= current future))
  5331. (throw :skip nil))))
  5332. (save-excursion
  5333. (re-search-backward org-outline-regexp-bol nil t)
  5334. ;; Possibly skip time-stamp when a deadline is set.
  5335. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5336. (assq (point) deadline-position-alist))
  5337. (throw :skip nil))
  5338. (let* ((category (org-get-category pos))
  5339. (inherited-tags
  5340. (or (eq org-agenda-show-inherited-tags 'always)
  5341. (and (consp org-agenda-show-inherited-tags)
  5342. (memq 'agenda org-agenda-show-inherited-tags))
  5343. (and (eq org-agenda-show-inherited-tags t)
  5344. (or (eq org-agenda-use-tag-inheritance t)
  5345. (memq 'agenda
  5346. org-agenda-use-tag-inheritance)))))
  5347. (tags (org-get-tags nil (not inherited-tags)))
  5348. (level (make-string (org-reduced-level (org-outline-level))
  5349. ?\s))
  5350. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5351. (match-string 1)))
  5352. (inactive? (= (char-after pos) ?\[))
  5353. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5354. (item
  5355. (org-agenda-format-item
  5356. (and inactive? org-agenda-inactive-leader)
  5357. head level category tags time-stamp org-ts-regexp habit?)))
  5358. (org-add-props item props
  5359. 'priority (if habit?
  5360. (org-habit-get-priority (org-habit-parse-todo))
  5361. (org-get-priority item))
  5362. 'org-marker (org-agenda-new-marker pos)
  5363. 'org-hd-marker (org-agenda-new-marker)
  5364. 'date date
  5365. 'level level
  5366. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5367. current)
  5368. 'todo-state todo-state
  5369. 'warntime warntime
  5370. 'type "timestamp")
  5371. (push item timestamp-items))))
  5372. (when org-agenda-skip-additional-timestamps-same-entry
  5373. (outline-next-heading))))
  5374. (nreverse timestamp-items)))
  5375. (defun org-agenda-get-sexps ()
  5376. "Return the sexp information for agenda display."
  5377. (require 'diary-lib)
  5378. (with-no-warnings (defvar date) (defvar entry))
  5379. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5380. 'mouse-face 'highlight
  5381. 'help-echo
  5382. (format "mouse-2 or RET jump to org file %s"
  5383. (abbreviate-file-name buffer-file-name))))
  5384. (regexp "^&?%%(")
  5385. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5386. ;; so as to "hide" any current binding for it?
  5387. marker category extra level ee txt tags entry
  5388. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5389. (goto-char (point-min))
  5390. (while (re-search-forward regexp nil t)
  5391. (catch :skip
  5392. (org-agenda-skip)
  5393. (setq beg (match-beginning 0))
  5394. (goto-char (1- (match-end 0)))
  5395. (setq b (point))
  5396. (forward-sexp 1)
  5397. (setq sexp (buffer-substring b (point)))
  5398. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5399. (org-trim (match-string 1))
  5400. ""))
  5401. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5402. (when result
  5403. (setq marker (org-agenda-new-marker beg)
  5404. level (make-string (org-reduced-level (org-outline-level)) ? )
  5405. category (org-get-category beg)
  5406. inherited-tags
  5407. (or (eq org-agenda-show-inherited-tags 'always)
  5408. (and (listp org-agenda-show-inherited-tags)
  5409. (memq 'agenda org-agenda-show-inherited-tags))
  5410. (and (eq org-agenda-show-inherited-tags t)
  5411. (or (eq org-agenda-use-tag-inheritance t)
  5412. (memq 'agenda org-agenda-use-tag-inheritance))))
  5413. tags (org-get-tags nil (not inherited-tags))
  5414. todo-state (org-get-todo-state)
  5415. warntime (get-text-property (point) 'org-appt-warntime)
  5416. extra nil)
  5417. (dolist (r (if (stringp result)
  5418. (list result)
  5419. result)) ;; we expect a list here
  5420. (when (and org-agenda-diary-sexp-prefix
  5421. (string-match org-agenda-diary-sexp-prefix r))
  5422. (setq extra (match-string 0 r)
  5423. r (replace-match "" nil nil r)))
  5424. (if (string-match "\\S-" r)
  5425. (setq txt r)
  5426. (setq txt "SEXP entry returned empty string"))
  5427. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5428. (org-add-props txt props 'org-marker marker
  5429. 'date date 'todo-state todo-state
  5430. 'level level 'type "sexp" 'warntime warntime)
  5431. (push txt ee)))))
  5432. (nreverse ee)))
  5433. ;; Calendar sanity: define some functions that are independent of
  5434. ;; `calendar-date-style'.
  5435. (defun org-anniversary (year month day &optional mark)
  5436. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5437. (with-no-warnings
  5438. (let ((calendar-date-style 'iso))
  5439. (diary-anniversary year month day mark))))
  5440. (defun org-cyclic (N year month day &optional mark)
  5441. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5442. (with-no-warnings
  5443. (let ((calendar-date-style 'iso))
  5444. (diary-cyclic N year month day mark))))
  5445. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5446. "Like `diary-block', but with fixed (ISO) order of arguments."
  5447. (with-no-warnings
  5448. (let ((calendar-date-style 'iso))
  5449. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5450. (defun org-date (year month day &optional mark)
  5451. "Like `diary-date', but with fixed (ISO) order of arguments."
  5452. (with-no-warnings
  5453. (let ((calendar-date-style 'iso))
  5454. (diary-date year month day mark))))
  5455. ;; Define the `org-class' function
  5456. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5457. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5458. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5459. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5460. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5461. `holidays', then any date that is known by the Emacs calendar to be a
  5462. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5463. then those holidays will be skipped."
  5464. (with-no-warnings (defvar date) (defvar entry))
  5465. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5466. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5467. (d (calendar-absolute-from-gregorian date))
  5468. (h (when skip-weeks (calendar-check-holidays date))))
  5469. (and
  5470. (<= date1 d)
  5471. (<= d date2)
  5472. (= (calendar-day-of-week date) dayname)
  5473. (or (not skip-weeks)
  5474. (progn
  5475. (require 'cal-iso)
  5476. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5477. (not (or (and h (memq 'holidays skip-weeks))
  5478. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5479. entry)))
  5480. (defalias 'org-get-closed #'org-agenda-get-progress)
  5481. (defun org-agenda-get-progress ()
  5482. "Return the logged TODO entries for agenda display."
  5483. (with-no-warnings (defvar date))
  5484. (let* ((props (list 'mouse-face 'highlight
  5485. 'org-not-done-regexp org-not-done-regexp
  5486. 'org-todo-regexp org-todo-regexp
  5487. 'org-complex-heading-regexp org-complex-heading-regexp
  5488. 'help-echo
  5489. (format "mouse-2 or RET jump to org file %s"
  5490. (abbreviate-file-name buffer-file-name))))
  5491. (items (if (consp org-agenda-show-log-scoped)
  5492. org-agenda-show-log-scoped
  5493. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5494. '(clock)
  5495. org-agenda-log-mode-items)))
  5496. (parts
  5497. (delq nil
  5498. (list
  5499. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5500. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5501. (when (memq 'state items)
  5502. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5503. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5504. (error "`org-agenda-log-mode-items' is empty")))
  5505. (regexp (concat
  5506. "\\(" parts-re "\\)"
  5507. " *\\["
  5508. (regexp-quote
  5509. (substring
  5510. (format-time-string
  5511. (car org-time-stamp-formats)
  5512. (encode-time ; DATE bound by calendar
  5513. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5514. 1 11))))
  5515. (org-agenda-search-headline-for-time nil)
  5516. marker hdmarker priority category level tags closedp type
  5517. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5518. (goto-char (point-min))
  5519. (while (re-search-forward regexp nil t)
  5520. (catch :skip
  5521. (org-agenda-skip)
  5522. (setq marker (org-agenda-new-marker (match-beginning 0))
  5523. closedp (equal (match-string 1) org-closed-string)
  5524. statep (equal (string-to-char (match-string 1)) ?-)
  5525. clockp (not (or closedp statep))
  5526. state (and statep (match-string 2))
  5527. category (org-get-category (match-beginning 0))
  5528. timestr (buffer-substring (match-beginning 0) (line-end-position)))
  5529. (when (string-match "\\]" timestr)
  5530. ;; substring should only run to end of time stamp
  5531. (setq rest (substring timestr (match-end 0))
  5532. timestr (substring timestr 0 (match-end 0)))
  5533. (if (and (not closedp) (not statep)
  5534. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5535. rest))
  5536. (progn (setq timestr (concat (substring timestr 0 -1)
  5537. "-" (match-string 1 rest) "]"))
  5538. (setq clocked (match-string 2 rest)))
  5539. (setq clocked "-")))
  5540. (save-excursion
  5541. (setq extra
  5542. (cond
  5543. ((not org-agenda-log-mode-add-notes) nil)
  5544. (statep
  5545. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5546. (match-string 1)))
  5547. (clockp
  5548. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5549. (match-string 1)))))
  5550. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5551. (throw :skip nil)
  5552. (goto-char (match-beginning 0))
  5553. (setq hdmarker (org-agenda-new-marker)
  5554. inherited-tags
  5555. (or (eq org-agenda-show-inherited-tags 'always)
  5556. (and (listp org-agenda-show-inherited-tags)
  5557. (memq 'todo org-agenda-show-inherited-tags))
  5558. (and (eq org-agenda-show-inherited-tags t)
  5559. (or (eq org-agenda-use-tag-inheritance t)
  5560. (memq 'todo org-agenda-use-tag-inheritance))))
  5561. tags (org-get-tags nil (not inherited-tags))
  5562. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5563. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5564. (setq txt (match-string 1))
  5565. (when extra
  5566. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5567. (setq txt (concat (substring txt 0 (match-beginning 1))
  5568. " - " extra " " (match-string 2 txt)))
  5569. (setq txt (concat txt " - " extra))))
  5570. (setq txt (org-agenda-format-item
  5571. (cond
  5572. (closedp "Closed: ")
  5573. (statep (concat "State: (" state ")"))
  5574. (t (concat "Clocked: (" clocked ")")))
  5575. txt level category tags timestr)))
  5576. (setq type (cond (closedp "closed")
  5577. (statep "state")
  5578. (t "clock")))
  5579. (setq priority 100000)
  5580. (org-add-props txt props
  5581. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5582. 'priority priority 'level level
  5583. 'type type 'date date
  5584. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5585. (push txt ee))
  5586. (goto-char (line-end-position))))
  5587. (nreverse ee)))
  5588. (defun org-agenda-show-clocking-issues ()
  5589. "Add overlays, showing issues with clocking.
  5590. See also the user option `org-agenda-clock-consistency-checks'."
  5591. (interactive)
  5592. (let* ((pl org-agenda-clock-consistency-checks)
  5593. (re (concat "^[ \t]*"
  5594. org-clock-string
  5595. "[ \t]+"
  5596. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5597. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5598. (tlstart 0.)
  5599. (tlend 0.)
  5600. (maxtime (org-duration-to-minutes
  5601. (or (plist-get pl :max-duration) "24:00")))
  5602. (mintime (org-duration-to-minutes
  5603. (or (plist-get pl :min-duration) 0)))
  5604. (maxgap (org-duration-to-minutes
  5605. ;; default 30:00 means never complain
  5606. (or (plist-get pl :max-gap) "30:00")))
  5607. (gapok (mapcar #'org-duration-to-minutes
  5608. (plist-get pl :gap-ok-around)))
  5609. (def-face (or (plist-get pl :default-face)
  5610. '((:background "DarkRed") (:foreground "white"))))
  5611. issue face m te ts dt ov)
  5612. (goto-char (point-min))
  5613. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5614. (setq issue nil face def-face)
  5615. (catch 'next
  5616. (setq m (org-get-at-bol 'org-marker)
  5617. te nil ts nil)
  5618. (unless (and m (markerp m))
  5619. (setq issue "No valid clock line") (throw 'next t))
  5620. (org-with-point-at m
  5621. (save-excursion
  5622. (goto-char (line-beginning-position))
  5623. (unless (looking-at re)
  5624. (error "No valid Clock line")
  5625. (throw 'next t))
  5626. (unless (match-end 3)
  5627. (setq issue
  5628. (format
  5629. "No end time: (%s)"
  5630. (org-duration-from-minutes
  5631. (floor
  5632. (- (float-time (org-current-time))
  5633. (float-time (org-time-string-to-time (match-string 1))))
  5634. 60)))
  5635. face (or (plist-get pl :no-end-time-face) face))
  5636. (throw 'next t))
  5637. (setq ts (match-string 1)
  5638. te (match-string 3)
  5639. ts (float-time (org-time-string-to-time ts))
  5640. te (float-time (org-time-string-to-time te))
  5641. dt (- te ts))))
  5642. (cond
  5643. ((> dt (* 60 maxtime))
  5644. ;; a very long clocking chunk
  5645. (setq issue (format "Clocking interval is very long: %s"
  5646. (org-duration-from-minutes (floor dt 60)))
  5647. face (or (plist-get pl :long-face) face)))
  5648. ((< dt (* 60 mintime))
  5649. ;; a very short clocking chunk
  5650. (setq issue (format "Clocking interval is very short: %s"
  5651. (org-duration-from-minutes (floor dt 60)))
  5652. face (or (plist-get pl :short-face) face)))
  5653. ((and (> tlend 0) (< ts tlend))
  5654. ;; Two clock entries are overlapping
  5655. (setq issue (format "Clocking overlap: %d minutes"
  5656. (/ (- tlend ts) 60))
  5657. face (or (plist-get pl :overlap-face) face)))
  5658. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5659. ;; There is a gap, lets see if we need to report it
  5660. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5661. (setq issue (format "Clocking gap: %d minutes"
  5662. (/ (- ts tlend) 60))
  5663. face (or (plist-get pl :gap-face) face))))
  5664. (t nil)))
  5665. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5666. (when issue
  5667. ;; OK, there was some issue, add an overlay to show the issue
  5668. (setq ov (make-overlay (line-beginning-position) (line-end-position)))
  5669. (overlay-put ov 'before-string
  5670. (concat
  5671. (org-add-props
  5672. (format "%-43s" (concat " " issue))
  5673. nil
  5674. 'face face)
  5675. "\n"))
  5676. (overlay-put ov 'evaporate t)))))
  5677. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5678. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5679. (catch 'exit
  5680. (unless ok-list
  5681. ;; there are no OK times for gaps...
  5682. (throw 'exit nil))
  5683. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5684. ;; This is more than 24 hours, so it is OK.
  5685. ;; because we have at least one OK time, that must be in the
  5686. ;; 24 hour interval.
  5687. (throw 'exit t))
  5688. ;; We have a shorter gap.
  5689. ;; Now we have to get the minute of the day when these times are
  5690. (let* ((t1dec (org-decode-time t1))
  5691. (t2dec (org-decode-time t2))
  5692. ;; compute the minute on the day
  5693. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5694. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5695. (when (< min2 min1)
  5696. ;; if min2 is smaller than min1, this means it is on the next day.
  5697. ;; Wrap it to after midnight.
  5698. (setq min2 (+ min2 1440)))
  5699. ;; Now check if any of the OK times is in the gap
  5700. (mapc (lambda (x)
  5701. ;; Wrap the time to after midnight if necessary
  5702. (when (< x min1) (setq x (+ x 1440)))
  5703. ;; Check if in interval
  5704. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5705. ok-list)
  5706. ;; Nope, this gap is not OK
  5707. nil)))
  5708. (defun org-agenda-get-deadlines (&optional with-hour)
  5709. "Return the deadline information for agenda display.
  5710. When WITH-HOUR is non-nil, only return deadlines with an hour
  5711. specification like [h]h:mm."
  5712. (with-no-warnings (defvar date))
  5713. (let* ((props (list 'mouse-face 'highlight
  5714. 'org-not-done-regexp org-not-done-regexp
  5715. 'org-todo-regexp org-todo-regexp
  5716. 'org-complex-heading-regexp org-complex-heading-regexp
  5717. 'help-echo
  5718. (format "mouse-2 or RET jump to org file %s"
  5719. (abbreviate-file-name buffer-file-name))))
  5720. (regexp (if with-hour
  5721. org-deadline-time-hour-regexp
  5722. org-deadline-time-regexp))
  5723. (today (org-today))
  5724. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5725. (current (calendar-absolute-from-gregorian date))
  5726. deadline-items)
  5727. (goto-char (point-min))
  5728. (while (re-search-forward regexp nil t)
  5729. (catch :skip
  5730. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5731. (org-agenda-skip)
  5732. (let* ((s (match-string 1))
  5733. (pos (1- (match-beginning 1)))
  5734. (todo-state (save-match-data (org-get-todo-state)))
  5735. (done? (member todo-state org-done-keywords))
  5736. (sexp? (string-prefix-p "%%" s))
  5737. ;; DEADLINE is the deadline date for the entry. It is
  5738. ;; either the base date or the last repeat, according
  5739. ;; to `org-agenda-prefer-last-repeat'.
  5740. (deadline
  5741. (cond
  5742. (sexp? (org-agenda--timestamp-to-absolute s current))
  5743. ((or (eq org-agenda-prefer-last-repeat t)
  5744. (member todo-state org-agenda-prefer-last-repeat))
  5745. (org-agenda--timestamp-to-absolute
  5746. s today 'past (current-buffer) pos))
  5747. (t (org-agenda--timestamp-to-absolute s))))
  5748. ;; REPEAT is the future repeat closest from CURRENT,
  5749. ;; according to `org-agenda-show-future-repeats'. If
  5750. ;; the latter is nil, or if the time stamp has no
  5751. ;; repeat part, default to DEADLINE.
  5752. (repeat
  5753. (cond
  5754. (sexp? deadline)
  5755. ((<= current today) deadline)
  5756. ((not org-agenda-show-future-repeats) deadline)
  5757. (t
  5758. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5759. (1+ today)
  5760. current)))
  5761. (org-agenda--timestamp-to-absolute
  5762. s base 'future (current-buffer) pos)))))
  5763. (diff (- deadline current))
  5764. (suppress-prewarning
  5765. (let ((scheduled
  5766. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5767. (org-entry-get nil "SCHEDULED"))))
  5768. (cond
  5769. ((not scheduled) nil)
  5770. ;; The current item has a scheduled date, so
  5771. ;; evaluate its prewarning lead time.
  5772. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5773. ;; Use global prewarning-restart lead time.
  5774. org-agenda-skip-deadline-prewarning-if-scheduled)
  5775. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5776. 'pre-scheduled)
  5777. ;; Set pre-warning to no earlier than SCHEDULED.
  5778. (min (- deadline
  5779. (org-agenda--timestamp-to-absolute scheduled))
  5780. org-deadline-warning-days))
  5781. ;; Set pre-warning to deadline.
  5782. (t 0))))
  5783. (wdays (or suppress-prewarning (org-get-wdays s))))
  5784. (cond
  5785. ;; Only display deadlines at their base date, at future
  5786. ;; repeat occurrences or in today agenda.
  5787. ((= current deadline) nil)
  5788. ((= current repeat) nil)
  5789. ((not today?) (throw :skip nil))
  5790. ;; Upcoming deadline: display within warning period WDAYS.
  5791. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5792. ;; Overdue deadline: warn about it for
  5793. ;; `org-deadline-past-days' duration.
  5794. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5795. ;; Possibly skip done tasks.
  5796. (when (and done?
  5797. (or org-agenda-skip-deadline-if-done
  5798. (/= deadline current)))
  5799. (throw :skip nil))
  5800. (save-excursion
  5801. (re-search-backward "^\\*+[ \t]+" nil t)
  5802. (goto-char (match-end 0))
  5803. (let* ((category (org-get-category))
  5804. (level (make-string (org-reduced-level (org-outline-level))
  5805. ?\s))
  5806. (head (buffer-substring (point) (line-end-position)))
  5807. (inherited-tags
  5808. (or (eq org-agenda-show-inherited-tags 'always)
  5809. (and (listp org-agenda-show-inherited-tags)
  5810. (memq 'agenda org-agenda-show-inherited-tags))
  5811. (and (eq org-agenda-show-inherited-tags t)
  5812. (or (eq org-agenda-use-tag-inheritance t)
  5813. (memq 'agenda
  5814. org-agenda-use-tag-inheritance)))))
  5815. (tags (org-get-tags nil (not inherited-tags)))
  5816. (time
  5817. (cond
  5818. ;; No time of day designation if it is only
  5819. ;; a reminder.
  5820. ((and (/= current deadline) (/= current repeat)) nil)
  5821. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5822. (concat (substring s (match-beginning 1)) " "))
  5823. (t 'time)))
  5824. (item
  5825. (org-agenda-format-item
  5826. ;; Insert appropriate suffixes before deadlines.
  5827. ;; Those only apply to today agenda.
  5828. (pcase-let ((`(,now ,future ,past)
  5829. org-agenda-deadline-leaders))
  5830. (cond
  5831. ((and today? (< deadline today)) (format past (- diff)))
  5832. ((and today? (> deadline today)) (format future diff))
  5833. (t now)))
  5834. head level category tags time))
  5835. (face (org-agenda-deadline-face
  5836. (- 1 (/ (float diff) (max wdays 1)))))
  5837. (upcoming? (and today? (> deadline today)))
  5838. (warntime (get-text-property (point) 'org-appt-warntime)))
  5839. (org-add-props item props
  5840. 'org-marker (org-agenda-new-marker pos)
  5841. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5842. 'warntime warntime
  5843. 'level level
  5844. 'ts-date deadline
  5845. 'priority
  5846. ;; Adjust priority to today reminders about deadlines.
  5847. ;; Overdue deadlines get the highest priority
  5848. ;; increase, then imminent deadlines and eventually
  5849. ;; more distant deadlines.
  5850. (let ((adjust (if today? (- diff) 0)))
  5851. (+ adjust (org-get-priority item)))
  5852. 'todo-state todo-state
  5853. 'type (if upcoming? "upcoming-deadline" "deadline")
  5854. 'date (if upcoming? date deadline)
  5855. 'face (if done? 'org-agenda-done face)
  5856. 'undone-face face
  5857. 'done-face 'org-agenda-done)
  5858. (push item deadline-items))))))
  5859. (nreverse deadline-items)))
  5860. (defun org-agenda-deadline-face (fraction)
  5861. "Return the face to displaying a deadline item.
  5862. FRACTION is what fraction of the head-warning time has passed."
  5863. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5864. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5865. "Return the scheduled information for agenda display.
  5866. Optional argument DEADLINES is a list of deadline items to be
  5867. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5868. scheduled items with an hour specification like [h]h:mm."
  5869. (with-no-warnings (defvar date))
  5870. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5871. 'org-todo-regexp org-todo-regexp
  5872. 'org-complex-heading-regexp org-complex-heading-regexp
  5873. 'done-face 'org-agenda-done
  5874. 'mouse-face 'highlight
  5875. 'help-echo
  5876. (format "mouse-2 or RET jump to Org file %s"
  5877. (abbreviate-file-name buffer-file-name))))
  5878. (regexp (if with-hour
  5879. org-scheduled-time-hour-regexp
  5880. org-scheduled-time-regexp))
  5881. (today (org-today))
  5882. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5883. (current (calendar-absolute-from-gregorian date))
  5884. (deadline-pos
  5885. (mapcar (lambda (d)
  5886. (let ((m (get-text-property 0 'org-hd-marker d)))
  5887. (and m (marker-position m))))
  5888. deadlines))
  5889. scheduled-items)
  5890. (goto-char (point-min))
  5891. (while (re-search-forward regexp nil t)
  5892. (catch :skip
  5893. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5894. (org-agenda-skip)
  5895. (let* ((s (match-string 1))
  5896. (pos (1- (match-beginning 1)))
  5897. (todo-state (save-match-data (org-get-todo-state)))
  5898. (donep (member todo-state org-done-keywords))
  5899. (sexp? (string-prefix-p "%%" s))
  5900. ;; SCHEDULE is the scheduled date for the entry. It is
  5901. ;; either the bare date or the last repeat, according
  5902. ;; to `org-agenda-prefer-last-repeat'.
  5903. (schedule
  5904. (cond
  5905. (sexp? (org-agenda--timestamp-to-absolute s current))
  5906. ((or (eq org-agenda-prefer-last-repeat t)
  5907. (member todo-state org-agenda-prefer-last-repeat))
  5908. (org-agenda--timestamp-to-absolute
  5909. s today 'past (current-buffer) pos))
  5910. (t (org-agenda--timestamp-to-absolute s))))
  5911. ;; REPEAT is the future repeat closest from CURRENT,
  5912. ;; according to `org-agenda-show-future-repeats'. If
  5913. ;; the latter is nil, or if the time stamp has no
  5914. ;; repeat part, default to SCHEDULE.
  5915. (repeat
  5916. (cond
  5917. (sexp? schedule)
  5918. ((<= current today) schedule)
  5919. ((not org-agenda-show-future-repeats) schedule)
  5920. (t
  5921. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5922. (1+ today)
  5923. current)))
  5924. (org-agenda--timestamp-to-absolute
  5925. s base 'future (current-buffer) pos)))))
  5926. (diff (- current schedule))
  5927. (warntime (get-text-property (point) 'org-appt-warntime))
  5928. (pastschedp (< schedule today))
  5929. (futureschedp (> schedule today))
  5930. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5931. (suppress-delay
  5932. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5933. (org-entry-get nil "DEADLINE"))))
  5934. (cond
  5935. ((not deadline) nil)
  5936. ;; The current item has a deadline date, so
  5937. ;; evaluate its delay time.
  5938. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5939. ;; Use global delay time.
  5940. (- org-agenda-skip-scheduled-delay-if-deadline))
  5941. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5942. 'post-deadline)
  5943. ;; Set delay to no later than DEADLINE.
  5944. (min (- schedule
  5945. (org-agenda--timestamp-to-absolute deadline))
  5946. org-scheduled-delay-days))
  5947. (t 0))))
  5948. (ddays
  5949. (cond
  5950. ;; Nullify delay when a repeater triggered already
  5951. ;; and the delay is of the form --Xd.
  5952. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5953. (> schedule (org-agenda--timestamp-to-absolute s)))
  5954. 0)
  5955. (suppress-delay
  5956. (let ((org-scheduled-delay-days suppress-delay))
  5957. (org-get-wdays s t t)))
  5958. (t (org-get-wdays s t)))))
  5959. ;; Display scheduled items at base date (SCHEDULE), today if
  5960. ;; scheduled before the current date, and at any repeat past
  5961. ;; today. However, skip delayed items and items that have
  5962. ;; been displayed for more than `org-scheduled-past-days'.
  5963. (unless (and todayp
  5964. habitp
  5965. (bound-and-true-p org-habit-show-all-today))
  5966. (when (or (and (> ddays 0) (< diff ddays))
  5967. (> diff (or (and habitp org-habit-scheduled-past-days)
  5968. org-scheduled-past-days))
  5969. (> schedule current)
  5970. (and (/= current schedule)
  5971. (/= current today)
  5972. (/= current repeat)))
  5973. (throw :skip nil)))
  5974. ;; Possibly skip done tasks.
  5975. (when (and donep
  5976. (or org-agenda-skip-scheduled-if-done
  5977. (/= schedule current)))
  5978. (throw :skip nil))
  5979. ;; Skip entry if it already appears as a deadline, per
  5980. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5981. ;; doesn't apply to habits.
  5982. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5983. ((guard
  5984. (or (not (memq (line-beginning-position 0) deadline-pos))
  5985. habitp))
  5986. nil)
  5987. (`repeated-after-deadline
  5988. (let ((deadline (time-to-days
  5989. (org-get-deadline-time (point)))))
  5990. (and (<= schedule deadline) (> current deadline))))
  5991. (`not-today pastschedp)
  5992. (`t t)
  5993. (_ nil))
  5994. (throw :skip nil))
  5995. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5996. ;; only show them for today. Also skip done habits.
  5997. (when (and habitp
  5998. (or donep
  5999. (not (bound-and-true-p org-habit-show-habits))
  6000. (and (not todayp)
  6001. (bound-and-true-p
  6002. org-habit-show-habits-only-for-today))))
  6003. (throw :skip nil))
  6004. (save-excursion
  6005. (re-search-backward "^\\*+[ \t]+" nil t)
  6006. (goto-char (match-end 0))
  6007. (let* ((category (org-get-category))
  6008. (inherited-tags
  6009. (or (eq org-agenda-show-inherited-tags 'always)
  6010. (and (listp org-agenda-show-inherited-tags)
  6011. (memq 'agenda org-agenda-show-inherited-tags))
  6012. (and (eq org-agenda-show-inherited-tags t)
  6013. (or (eq org-agenda-use-tag-inheritance t)
  6014. (memq 'agenda
  6015. org-agenda-use-tag-inheritance)))))
  6016. (tags (org-get-tags nil (not inherited-tags)))
  6017. (level (make-string (org-reduced-level (org-outline-level))
  6018. ?\s))
  6019. (head (buffer-substring (point) (line-end-position)))
  6020. (time
  6021. (cond
  6022. ;; No time of day designation if it is only a
  6023. ;; reminder, except for habits, which always show
  6024. ;; the time of day. Habits are an exception
  6025. ;; because if there is a time of day, that is
  6026. ;; interpreted to mean they should usually happen
  6027. ;; then, even if doing the habit was missed.
  6028. ((and
  6029. (not habitp)
  6030. (/= current schedule)
  6031. (/= current repeat))
  6032. nil)
  6033. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6034. (concat (substring s (match-beginning 1)) " "))
  6035. (t 'time)))
  6036. (item
  6037. (org-agenda-format-item
  6038. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6039. ;; Show a reminder of a past scheduled today.
  6040. (if (and todayp pastschedp)
  6041. (format past diff)
  6042. first))
  6043. head level category tags time nil habitp))
  6044. (face (cond ((and (not habitp) pastschedp)
  6045. 'org-scheduled-previously)
  6046. ((and habitp futureschedp)
  6047. 'org-agenda-done)
  6048. (todayp 'org-scheduled-today)
  6049. (t 'org-scheduled)))
  6050. (habitp (and habitp (org-habit-parse-todo))))
  6051. (org-add-props item props
  6052. 'undone-face face
  6053. 'face (if donep 'org-agenda-done face)
  6054. 'org-marker (org-agenda-new-marker pos)
  6055. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6056. 'type (if pastschedp "past-scheduled" "scheduled")
  6057. 'date (if pastschedp schedule date)
  6058. 'ts-date schedule
  6059. 'warntime warntime
  6060. 'level level
  6061. 'priority (if habitp (org-habit-get-priority habitp)
  6062. (+ 99 diff (org-get-priority item)))
  6063. 'org-habit-p habitp
  6064. 'todo-state todo-state)
  6065. (push item scheduled-items))))))
  6066. (nreverse scheduled-items)))
  6067. (defun org-agenda-get-blocks ()
  6068. "Return the date-range information for agenda display."
  6069. (with-no-warnings (defvar date))
  6070. (let* ((props (list 'face nil
  6071. 'org-not-done-regexp org-not-done-regexp
  6072. 'org-todo-regexp org-todo-regexp
  6073. 'org-complex-heading-regexp org-complex-heading-regexp
  6074. 'mouse-face 'highlight
  6075. 'help-echo
  6076. (format "mouse-2 or RET jump to org file %s"
  6077. (abbreviate-file-name buffer-file-name))))
  6078. (regexp org-tr-regexp)
  6079. (d0 (calendar-absolute-from-gregorian date))
  6080. marker hdmarker ee txt d1 d2 s1 s2 category
  6081. level todo-state tags pos head donep inherited-tags)
  6082. (goto-char (point-min))
  6083. (while (re-search-forward regexp nil t)
  6084. (catch :skip
  6085. (org-agenda-skip)
  6086. (setq pos (point))
  6087. (let ((start-time (match-string 1))
  6088. (end-time (match-string 2)))
  6089. (setq s1 (match-string 1)
  6090. s2 (match-string 2)
  6091. d1 (time-to-days
  6092. (condition-case err
  6093. (org-time-string-to-time s1)
  6094. (error
  6095. (error
  6096. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6097. s1
  6098. pos
  6099. (current-buffer)
  6100. (error-message-string err)))))
  6101. d2 (time-to-days
  6102. (condition-case err
  6103. (org-time-string-to-time s2)
  6104. (error
  6105. (error
  6106. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6107. s2
  6108. pos
  6109. (current-buffer)
  6110. (error-message-string err))))))
  6111. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6112. ;; Only allow days between the limits, because the normal
  6113. ;; date stamps will catch the limits.
  6114. (save-excursion
  6115. (setq todo-state (org-get-todo-state))
  6116. (setq donep (member todo-state org-done-keywords))
  6117. (when (and donep org-agenda-skip-timestamp-if-done)
  6118. (throw :skip t))
  6119. (setq marker (org-agenda-new-marker (point))
  6120. category (org-get-category))
  6121. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6122. (throw :skip nil)
  6123. (goto-char (match-beginning 0))
  6124. (setq hdmarker (org-agenda-new-marker (point))
  6125. inherited-tags
  6126. (or (eq org-agenda-show-inherited-tags 'always)
  6127. (and (listp org-agenda-show-inherited-tags)
  6128. (memq 'agenda org-agenda-show-inherited-tags))
  6129. (and (eq org-agenda-show-inherited-tags t)
  6130. (or (eq org-agenda-use-tag-inheritance t)
  6131. (memq 'agenda org-agenda-use-tag-inheritance))))
  6132. tags (org-get-tags nil (not inherited-tags)))
  6133. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6134. (looking-at "\\*+[ \t]+\\(.*\\)")
  6135. (setq head (match-string 1))
  6136. (let ((remove-re
  6137. (if org-agenda-remove-timeranges-from-blocks
  6138. (concat
  6139. "<" (regexp-quote s1) ".*?>"
  6140. "--"
  6141. "<" (regexp-quote s2) ".*?>")
  6142. nil)))
  6143. (setq txt (org-agenda-format-item
  6144. (format
  6145. (nth (if (= d1 d2) 0 1)
  6146. org-agenda-timerange-leaders)
  6147. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6148. head level category tags
  6149. (save-match-data
  6150. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6151. (match-string 6 s1)))
  6152. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6153. (match-string 6 s2))))
  6154. (cond ((string= hhmm1 hhmm2)
  6155. (concat "<" start-time ">--<" end-time ">"))
  6156. ((and (= d1 d0) (= d2 d0))
  6157. (concat "<" start-time ">--<" end-time ">"))
  6158. ((= d1 d0)
  6159. (concat "<" start-time ">"))
  6160. ((= d2 d0)
  6161. (concat "<" end-time ">")))))
  6162. remove-re))))
  6163. (org-add-props txt props
  6164. 'org-marker marker 'org-hd-marker hdmarker
  6165. 'type "block" 'date date
  6166. 'level level
  6167. 'todo-state todo-state
  6168. 'priority (org-get-priority txt))
  6169. (push txt ee))))
  6170. (goto-char pos)))
  6171. ;; Sort the entries by expiration date.
  6172. (nreverse ee)))
  6173. ;;; Agenda presentation and sorting
  6174. (defvar org-prefix-has-time nil
  6175. "A flag, set by `org-compile-prefix-format'.
  6176. The flag is set if the currently compiled format contains a `%t'.")
  6177. (defvar org-prefix-has-tag nil
  6178. "A flag, set by `org-compile-prefix-format'.
  6179. The flag is set if the currently compiled format contains a `%T'.")
  6180. (defvar org-prefix-has-effort nil
  6181. "A flag, set by `org-compile-prefix-format'.
  6182. The flag is set if the currently compiled format contains a `%e'.")
  6183. (defvar org-prefix-has-breadcrumbs nil
  6184. "A flag, set by `org-compile-prefix-format'.
  6185. The flag is set if the currently compiled format contains a `%b'.")
  6186. (defvar org-prefix-category-length nil
  6187. "Used by `org-compile-prefix-format' to remember the category field width.")
  6188. (defvar org-prefix-category-max-length nil
  6189. "Used by `org-compile-prefix-format' to remember the category field width.")
  6190. (defun org-agenda-get-category-icon (category)
  6191. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6192. (cl-dolist (entry org-agenda-category-icon-alist)
  6193. (when (string-match-p (car entry) category)
  6194. (if (listp (cadr entry))
  6195. (cl-return (cadr entry))
  6196. (cl-return (apply #'create-image (cdr entry)))))))
  6197. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6198. remove-re habitp)
  6199. "Format TXT to be inserted into the agenda buffer.
  6200. In particular, add the prefix and corresponding text properties.
  6201. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6202. WITH-LEVEL may be a string to replace the `%l' specifier.
  6203. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6204. category taken from local variable or file name. It will replace the `%c'
  6205. specifier in the format.
  6206. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6207. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6208. When DOTIME is a string, this string is searched for a time before TXT is.
  6209. TAGS can be the tags of the headline.
  6210. Any match of REMOVE-RE will be removed from TXT."
  6211. ;; We keep the org-prefix-* variable values along with a compiled
  6212. ;; formatter, so that multiple agendas existing at the same time do
  6213. ;; not step on each other toes.
  6214. ;;
  6215. ;; It was inconvenient to make these variables buffer local in
  6216. ;; Agenda buffers, because this function expects to be called with
  6217. ;; the buffer where item comes from being current, and not agenda
  6218. ;; buffer
  6219. (let* ((bindings (car org-prefix-format-compiled))
  6220. (formatter (cadr org-prefix-format-compiled)))
  6221. (cl-loop for (var value) in bindings
  6222. do (set var value))
  6223. (save-match-data
  6224. ;; Diary entries sometimes have extra whitespace at the beginning
  6225. (setq txt (org-trim txt))
  6226. ;; Fix the tags part in txt
  6227. (setq txt (org-agenda-fix-displayed-tags
  6228. txt tags
  6229. org-agenda-show-inherited-tags
  6230. org-agenda-hide-tags-regexp))
  6231. (with-no-warnings
  6232. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6233. ;; Based on what I see in `org-compile-prefix-format', I added
  6234. ;; a few more.
  6235. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6236. (defvar effort) (defvar extra)
  6237. (defvar level) (defvar tag) (defvar time))
  6238. (let* ((category (or with-category
  6239. (if buffer-file-name
  6240. (file-name-sans-extension
  6241. (file-name-nondirectory buffer-file-name))
  6242. "")))
  6243. (category-icon (org-agenda-get-category-icon category))
  6244. (category-icon (if category-icon
  6245. (propertize " " 'display category-icon)
  6246. ""))
  6247. (effort (and (not (string= txt ""))
  6248. (get-text-property 1 'effort txt)))
  6249. (tag (if tags (nth (1- (length tags)) tags) ""))
  6250. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6251. (extra (or (and (not habitp) extra) ""))
  6252. time
  6253. (ts (when dotime (concat
  6254. (if (stringp dotime) dotime "")
  6255. (and org-agenda-search-headline-for-time txt))))
  6256. (time-of-day (and dotime (org-get-time-of-day ts)))
  6257. stamp plain s0 s1 s2 rtn srp l
  6258. duration breadcrumbs)
  6259. (and (derived-mode-p 'org-mode) buffer-file-name
  6260. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6261. (when (and dotime time-of-day)
  6262. ;; Extract starting and ending time and move them to prefix
  6263. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6264. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6265. (setq s0 (match-string 0 ts)
  6266. srp (and stamp (match-end 3))
  6267. s1 (match-string (if plain 1 2) ts)
  6268. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6269. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6270. ;; them, we might want to remove them there to avoid duplication.
  6271. ;; The user can turn this off with a variable.
  6272. (when (and org-prefix-has-time
  6273. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6274. (string-match (concat (regexp-quote s0) " *") txt)
  6275. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6276. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6277. (= (match-beginning 0) 0)
  6278. t))
  6279. (setq txt (replace-match "" nil nil txt))))
  6280. ;; Normalize the time(s) to 24 hour.
  6281. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6282. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6283. ;; Try to set s2 if s1 and
  6284. ;; `org-agenda-default-appointment-duration' are set
  6285. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6286. (setq s2
  6287. (org-duration-from-minutes
  6288. (+ (org-duration-to-minutes s1 t)
  6289. org-agenda-default-appointment-duration)
  6290. nil t)))
  6291. ;; Compute the duration
  6292. (when s2
  6293. (setq duration (- (org-duration-to-minutes s2)
  6294. (org-duration-to-minutes s1))))
  6295. ;; Format S1 and S2 for display.
  6296. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6297. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6298. (when (string-match org-tag-group-re txt)
  6299. ;; Tags are in the string
  6300. (if (or (eq org-agenda-remove-tags t)
  6301. (and org-agenda-remove-tags
  6302. org-prefix-has-tag))
  6303. (setq txt (replace-match "" t t txt))
  6304. (setq txt (replace-match
  6305. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6306. (match-string 1 txt))
  6307. t t txt))))
  6308. (when remove-re
  6309. (while (string-match remove-re txt)
  6310. (setq txt (replace-match "" t t txt))))
  6311. ;; Set org-heading property on `txt' to mark the start of the
  6312. ;; heading.
  6313. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6314. ;; Prepare the variables needed in the eval of the compiled format
  6315. (when org-prefix-has-breadcrumbs
  6316. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6317. (let ((s (org-format-outline-path (org-get-outline-path)
  6318. (1- (frame-width))
  6319. nil org-agenda-breadcrumbs-separator)))
  6320. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6321. (setq time (cond (s2 (concat
  6322. (org-agenda-time-of-day-to-ampm-maybe s1)
  6323. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6324. (when org-agenda-timegrid-use-ampm " ")))
  6325. (s1 (concat
  6326. (org-agenda-time-of-day-to-ampm-maybe s1)
  6327. (if org-agenda-timegrid-use-ampm
  6328. (concat time-grid-trailing-characters " ")
  6329. time-grid-trailing-characters)))
  6330. (t ""))
  6331. category (if (symbolp category) (symbol-name category) category)
  6332. level (or with-level ""))
  6333. (if (string-match org-link-bracket-re category)
  6334. (progn
  6335. (setq l (string-width (or (match-string 2) (match-string 1))))
  6336. (when (< l (or org-prefix-category-length 0))
  6337. (setq category (copy-sequence category))
  6338. (org-add-props category nil
  6339. 'extra-space (make-string
  6340. (- org-prefix-category-length l 1) ?\ ))))
  6341. (when (and org-prefix-category-max-length
  6342. (>= (length category) org-prefix-category-max-length))
  6343. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6344. ;; Evaluate the compiled format
  6345. (setq rtn (concat (eval formatter t) txt))
  6346. ;; And finally add the text properties
  6347. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6348. (org-add-props rtn nil
  6349. 'org-category category
  6350. 'tags tags
  6351. 'org-priority-highest org-priority-highest
  6352. 'org-priority-lowest org-priority-lowest
  6353. 'time-of-day time-of-day
  6354. 'duration duration
  6355. 'breadcrumbs breadcrumbs
  6356. 'txt txt
  6357. 'level level
  6358. 'time time
  6359. 'extra extra
  6360. 'format org-prefix-format-compiled
  6361. 'dotime dotime)))))
  6362. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6363. "Remove tags string from TXT, and add a modified list of tags.
  6364. The modified list may contain inherited tags, and tags matched by
  6365. `org-agenda-hide-tags-regexp' will be removed."
  6366. (when (or add-inherited hide-re)
  6367. (when (string-match org-tag-group-re txt)
  6368. (setq txt (substring txt 0 (match-beginning 0))))
  6369. (setq tags
  6370. (delq nil
  6371. (mapcar (lambda (tg)
  6372. (if (or (and hide-re (string-match hide-re tg))
  6373. (and (not add-inherited)
  6374. (get-text-property 0 'inherited tg)))
  6375. nil
  6376. tg))
  6377. tags)))
  6378. (when tags
  6379. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6380. i)
  6381. (setq txt (concat txt " :"
  6382. (mapconcat
  6383. (lambda (x)
  6384. (setq i (get-text-property 0 'inherited x))
  6385. (if (and have-i (not i))
  6386. (progn
  6387. (setq have-i nil)
  6388. (concat ":" x))
  6389. x))
  6390. tags ":")
  6391. (if have-i "::" ":"))))))
  6392. txt)
  6393. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6394. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6395. "Add a time-grid for agenda items which need it.
  6396. LIST is the list of agenda items formatted by `org-agenda-list'.
  6397. NDAYS is the span of the current agenda view.
  6398. TODAYP is t when the current agenda view is on today."
  6399. (catch 'exit
  6400. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6401. ((and todayp (member 'today (car org-agenda-time-grid))))
  6402. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6403. ((member 'weekly (car org-agenda-time-grid)))
  6404. (t (throw 'exit list)))
  6405. (let* ((have (delq nil (mapcar
  6406. (lambda (x) (get-text-property 1 'time-of-day x))
  6407. list)))
  6408. (string (nth 3 org-agenda-time-grid))
  6409. (gridtimes (nth 1 org-agenda-time-grid))
  6410. (req (car org-agenda-time-grid))
  6411. (remove (member 'remove-match req))
  6412. new time)
  6413. (when (and (member 'require-timed req) (not have))
  6414. ;; don't show empty grid
  6415. (throw 'exit list))
  6416. (while (setq time (pop gridtimes))
  6417. (unless (and remove (member time have))
  6418. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6419. (push (org-agenda-format-item
  6420. nil string nil "" nil
  6421. (concat (substring time 0 -2) ":" (substring time -2)))
  6422. new)
  6423. (put-text-property
  6424. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6425. (when (and todayp org-agenda-show-current-time-in-grid)
  6426. (push (org-agenda-format-item
  6427. nil org-agenda-current-time-string nil "" nil
  6428. (format-time-string "%H:%M "))
  6429. new)
  6430. (put-text-property
  6431. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6432. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6433. (append new list)
  6434. (append list new)))))
  6435. (defun org-compile-prefix-format (key)
  6436. "Compile the prefix format into a Lisp form that can be evaluated.
  6437. The resulting form and associated variable bindings is returned
  6438. and stored in the variable `org-prefix-format-compiled'."
  6439. (setq org-prefix-has-time nil
  6440. org-prefix-has-tag nil
  6441. org-prefix-category-length nil
  6442. org-prefix-has-effort nil
  6443. org-prefix-has-breadcrumbs nil)
  6444. (let ((s (cond
  6445. ((stringp org-agenda-prefix-format)
  6446. org-agenda-prefix-format)
  6447. ((assq key org-agenda-prefix-format)
  6448. (cdr (assq key org-agenda-prefix-format)))
  6449. (t " %-12:c%?-12t% s")))
  6450. (start 0)
  6451. varform vars var c f opt) ;; e
  6452. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6453. s start)
  6454. (setq var (or (cdr (assoc (match-string 4 s)
  6455. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6456. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6457. 'eval)
  6458. c (or (match-string 3 s) "")
  6459. opt (match-beginning 1)
  6460. start (1+ (match-beginning 0)))
  6461. (cl-case var
  6462. (time (setq org-prefix-has-time t))
  6463. (tag (setq org-prefix-has-tag t))
  6464. (effort (setq org-prefix-has-effort t))
  6465. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6466. (setq f (concat "%" (match-string 2 s) "s"))
  6467. (when (eq var 'category)
  6468. (setq org-prefix-category-length
  6469. (floor (abs (string-to-number (match-string 2 s)))))
  6470. (setq org-prefix-category-max-length
  6471. (let ((x (match-string 2 s)))
  6472. (save-match-data
  6473. (and (string-match "\\.[0-9]+" x)
  6474. (string-to-number (substring (match-string 0 x) 1)))))))
  6475. (if (eq var 'eval)
  6476. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6477. (if opt
  6478. (setq varform
  6479. `(if (member ,var '("" nil))
  6480. ""
  6481. (format ,f (concat ,var ,c))))
  6482. (setq varform
  6483. `(format ,f (if (member ,var '("" nil)) ""
  6484. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6485. (if (eq var 'eval)
  6486. (setf (substring s (match-beginning 0)
  6487. (+ (match-beginning 4)
  6488. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6489. "%s")
  6490. (setq s (replace-match "%s" t nil s)))
  6491. (push varform vars))
  6492. (setq vars (nreverse vars))
  6493. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6494. (setq org-prefix-format-compiled
  6495. (list
  6496. `((org-prefix-has-time ,org-prefix-has-time)
  6497. (org-prefix-has-tag ,org-prefix-has-tag)
  6498. (org-prefix-category-length ,org-prefix-category-length)
  6499. (org-prefix-has-effort ,org-prefix-has-effort)
  6500. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6501. `(format ,s ,@vars))))))
  6502. (defun org-set-sorting-strategy (key)
  6503. (setq org-agenda-sorting-strategy-selected
  6504. (if (symbolp (car org-agenda-sorting-strategy))
  6505. ;; the old format
  6506. org-agenda-sorting-strategy
  6507. (or (cdr (assq key org-agenda-sorting-strategy))
  6508. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6509. '(time-up category-keep priority-down)))))
  6510. (defun org-get-time-of-day (s &optional string)
  6511. "Check string S for a time of day.
  6512. If found, return it as a military time number between 0 and 2400.
  6513. If not found, return nil.
  6514. The optional STRING argument forces conversion into a 5 character wide string
  6515. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6516. where H:MM is the duration above midnight."
  6517. (let ((case-fold-search t)
  6518. (time-regexp
  6519. (rx word-start
  6520. (group (opt (any "012")) digit) ;group 1: hours
  6521. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  6522. (opt (group (or "am" "pm")))) ;group 3: am/pm
  6523. ;; Special "HHam/pm" case.
  6524. (group-n 3 (or "am" "pm")))
  6525. word-end)))
  6526. (save-match-data
  6527. (when (and (string-match time-regexp s)
  6528. (not (eq 'org-link (get-text-property 1 'face s))))
  6529. (let ((hours
  6530. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  6531. (am-p (equal ampm "am")))
  6532. (pcase (string-to-number (match-string 1 s))
  6533. ((and (guard (not ampm)) h) h)
  6534. (12 (if am-p 0 12))
  6535. (h (+ h (if am-p 0 12))))))
  6536. (minutes
  6537. (if (match-end 2)
  6538. (string-to-number (match-string 2 s))
  6539. 0)))
  6540. (pcase string
  6541. (`nil (+ minutes (* hours 100)))
  6542. ((and `overtime
  6543. (guard (or (> hours 24)
  6544. (and (= hours 24)
  6545. (> minutes 0)))))
  6546. (format "+%d:%02d" (- hours 24) minutes))
  6547. ((guard org-agenda-time-leading-zero)
  6548. (format "%02d:%02d" hours minutes))
  6549. (_
  6550. (format "%d:%02d" hours minutes))))))))
  6551. (defvar org-agenda-before-sorting-filter-function nil
  6552. "Function to be applied to agenda items prior to sorting.
  6553. Prior to sorting also means just before they are inserted into the agenda.
  6554. To aid sorting, you may revisit the original entries and add more text
  6555. properties which will later be used by the sorting functions.
  6556. The function should take a string argument, an agenda line.
  6557. It has access to the text properties in that line, which contain among
  6558. other things, the property `org-hd-marker' that points to the entry
  6559. where the line comes from. Note that not all lines going into the agenda
  6560. have this property, only most.
  6561. The function should return the modified string. It is probably best
  6562. to ONLY change text properties.
  6563. You can also use this function as a filter, by returning nil for lines
  6564. you don't want to have in the agenda at all. For this application, you
  6565. could bind the variable in the options section of a custom command.")
  6566. (defun org-agenda-finalize-entries (list &optional type)
  6567. "Sort, limit and concatenate the LIST of agenda items.
  6568. The optional argument TYPE tells the agenda type."
  6569. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6570. (cdr (assoc type org-agenda-max-effort)))
  6571. (t org-agenda-max-effort)))
  6572. (max-todo (cond ((listp org-agenda-max-todos)
  6573. (cdr (assoc type org-agenda-max-todos)))
  6574. (t org-agenda-max-todos)))
  6575. (max-tags (cond ((listp org-agenda-max-tags)
  6576. (cdr (assoc type org-agenda-max-tags)))
  6577. (t org-agenda-max-tags)))
  6578. (max-entries (cond ((listp org-agenda-max-entries)
  6579. (cdr (assoc type org-agenda-max-entries)))
  6580. (t org-agenda-max-entries))))
  6581. (when org-agenda-before-sorting-filter-function
  6582. (setq list
  6583. (delq nil
  6584. (mapcar
  6585. org-agenda-before-sorting-filter-function list))))
  6586. (setq list (mapcar #'org-agenda-highlight-todo list)
  6587. list (mapcar #'identity (sort list #'org-entries-lessp)))
  6588. (when max-effort
  6589. (setq list (org-agenda-limit-entries
  6590. list 'effort-minutes max-effort
  6591. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  6592. 32767 -1))))))
  6593. (when max-todo
  6594. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6595. (when max-tags
  6596. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6597. (when max-entries
  6598. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6599. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6600. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6601. (mapconcat #'identity list "\n")))
  6602. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6603. "Limit the number of agenda entries."
  6604. (let ((include (and limit (< limit 0))))
  6605. (if limit
  6606. (let ((fun (or fn (lambda (p) (when p 1))))
  6607. (lim 0))
  6608. (delq nil
  6609. (mapcar
  6610. (lambda (e)
  6611. (let ((pval (funcall
  6612. fun (get-text-property (1- (length e))
  6613. prop e))))
  6614. (when pval (setq lim (+ lim pval)))
  6615. (cond ((and pval (<= lim (abs limit))) e)
  6616. ((and include (not pval)) e))))
  6617. list)))
  6618. list)))
  6619. (defun org-agenda-limit-interactively (remove)
  6620. "In agenda, interactively limit entries to various maximums."
  6621. (interactive "P")
  6622. (if remove
  6623. (progn (setq org-agenda-max-entries nil
  6624. org-agenda-max-todos nil
  6625. org-agenda-max-tags nil
  6626. org-agenda-max-effort nil)
  6627. (org-agenda-redo))
  6628. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6629. (msg (cond ((= max ?E) "How many minutes? ")
  6630. ((= max ?e) "How many entries? ")
  6631. ((= max ?t) "How many TODO entries? ")
  6632. ((= max ?T) "How many tagged entries? ")
  6633. (t (user-error "Wrong input"))))
  6634. (num (string-to-number (read-from-minibuffer msg))))
  6635. (cond ((equal max ?e)
  6636. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6637. ((equal max ?t)
  6638. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6639. ((equal max ?T)
  6640. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6641. ((equal max ?E)
  6642. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6643. (org-agenda-fit-window-to-buffer))
  6644. (defun org-agenda-highlight-todo (x)
  6645. (let ((org-done-keywords org-done-keywords-for-agenda)
  6646. (case-fold-search nil)
  6647. re)
  6648. (if (eq x 'line)
  6649. (save-excursion
  6650. (beginning-of-line 1)
  6651. (setq re (org-get-at-bol 'org-todo-regexp))
  6652. (goto-char (or (text-property-any (line-beginning-position)
  6653. (line-end-position)
  6654. 'org-heading t)
  6655. (point)))
  6656. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6657. (add-text-properties (match-beginning 0) (match-end 1)
  6658. (list 'face (org-get-todo-face 1)))
  6659. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6660. (delete-region (match-beginning 1) (1- (match-end 0)))
  6661. (goto-char (match-beginning 1))
  6662. (insert (format org-agenda-todo-keyword-format s)))))
  6663. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6664. (setq re (get-text-property 0 'org-todo-regexp x))
  6665. (when (and re
  6666. ;; Test `pl' because if there's no heading content,
  6667. ;; there's no point matching to highlight. Note
  6668. ;; that if we didn't test `pl' first, and there
  6669. ;; happened to be no keyword from `org-todo-regexp'
  6670. ;; on this heading line, then the `equal' comparison
  6671. ;; afterwards would spuriously succeed in the case
  6672. ;; where `pl' is nil -- causing an args-out-of-range
  6673. ;; error when we try to add text properties to text
  6674. ;; that isn't there.
  6675. pl
  6676. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6677. x pl)
  6678. pl))
  6679. (add-text-properties
  6680. (or (match-end 1) (match-end 0)) (match-end 0)
  6681. (list 'face (org-get-todo-face (match-string 2 x)))
  6682. x)
  6683. (when (match-end 1)
  6684. (setq x
  6685. (concat
  6686. (substring x 0 (match-end 1))
  6687. (unless (string= org-agenda-todo-keyword-format "")
  6688. (format org-agenda-todo-keyword-format
  6689. (match-string 2 x)))
  6690. (unless (string= org-agenda-todo-keyword-format "")
  6691. ;; Remove `display' property as the icon could leak
  6692. ;; on the white space.
  6693. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6694. 'display)))
  6695. (substring x (match-end 3)))))))
  6696. x)))
  6697. (defsubst org-cmp-values (a b property)
  6698. "Compare the numeric value of text PROPERTY for string A and B."
  6699. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6700. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6701. (cond ((> pa pb) +1)
  6702. ((< pa pb) -1))))
  6703. (defsubst org-cmp-effort (a b)
  6704. "Compare the effort values of string A and B."
  6705. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  6706. ;; `effort-minutes' property is not directly accessible from
  6707. ;; the strings, but is stored as a property in `txt'.
  6708. (ea (or (get-text-property
  6709. 0 'effort-minutes (get-text-property 0 'txt a))
  6710. def))
  6711. (eb (or (get-text-property
  6712. 0 'effort-minutes (get-text-property 0 'txt b))
  6713. def)))
  6714. (cond ((> ea eb) +1)
  6715. ((< ea eb) -1))))
  6716. (defsubst org-cmp-category (a b)
  6717. "Compare the string values of categories of strings A and B."
  6718. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6719. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6720. (cond ((string-lessp ca cb) -1)
  6721. ((string-lessp cb ca) +1))))
  6722. (defsubst org-cmp-todo-state (a b)
  6723. "Compare the todo states of strings A and B."
  6724. (let* ((ma (or (get-text-property 1 'org-marker a)
  6725. (get-text-property 1 'org-hd-marker a)))
  6726. (mb (or (get-text-property 1 'org-marker b)
  6727. (get-text-property 1 'org-hd-marker b)))
  6728. (fa (and ma (marker-buffer ma)))
  6729. (fb (and mb (marker-buffer mb)))
  6730. (todo-kwds
  6731. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6732. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6733. (ta (or (get-text-property 1 'todo-state a) ""))
  6734. (tb (or (get-text-property 1 'todo-state b) ""))
  6735. (la (- (length (member ta todo-kwds))))
  6736. (lb (- (length (member tb todo-kwds))))
  6737. (donepa (member ta org-done-keywords-for-agenda))
  6738. (donepb (member tb org-done-keywords-for-agenda)))
  6739. (cond ((and donepa (not donepb)) -1)
  6740. ((and (not donepa) donepb) +1)
  6741. ((< la lb) -1)
  6742. ((< lb la) +1))))
  6743. (defsubst org-cmp-alpha (a b)
  6744. "Compare the headlines, alphabetically."
  6745. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6746. (plb (text-property-any 0 (length b) 'org-heading t b))
  6747. (ta (and pla (substring a pla)))
  6748. (tb (and plb (substring b plb)))
  6749. (case-fold-search nil))
  6750. (when pla
  6751. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6752. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  6753. ta)
  6754. (setq ta (substring ta (match-end 0))))
  6755. (setq ta (downcase ta)))
  6756. (when plb
  6757. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6758. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  6759. tb)
  6760. (setq tb (substring tb (match-end 0))))
  6761. (setq tb (downcase tb)))
  6762. (cond ((not (or ta tb)) nil)
  6763. ((not ta) +1)
  6764. ((not tb) -1)
  6765. ((string-lessp ta tb) -1)
  6766. ((string-lessp tb ta) +1))))
  6767. (defsubst org-cmp-tag (a b)
  6768. "Compare the string values of the first tags of A and B."
  6769. (let ((ta (car (last (get-text-property 1 'tags a))))
  6770. (tb (car (last (get-text-property 1 'tags b)))))
  6771. (cond ((not (or ta tb)) nil)
  6772. ((not ta) +1)
  6773. ((not tb) -1)
  6774. ((string-lessp ta tb) -1)
  6775. ((string-lessp tb ta) +1))))
  6776. (defsubst org-cmp-time (a b)
  6777. "Compare the time-of-day values of strings A and B."
  6778. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  6779. (ta (or (get-text-property 1 'time-of-day a) def))
  6780. (tb (or (get-text-property 1 'time-of-day b) def)))
  6781. (cond ((< ta tb) -1)
  6782. ((< tb ta) +1))))
  6783. (defsubst org-cmp-ts (a b type)
  6784. "Compare the timestamps values of entries A and B.
  6785. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6786. \"timestamp_ia\", compare within each of these type. When TYPE
  6787. is the empty string, compare all timestamps without respect of
  6788. their type."
  6789. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  6790. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6791. (get-text-property 1 'ts-date a))
  6792. def))
  6793. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6794. (get-text-property 1 'ts-date b))
  6795. def)))
  6796. (cond ((if ta (and tb (< ta tb)) tb) -1)
  6797. ((if tb (and ta (< tb ta)) ta) +1))))
  6798. (defsubst org-cmp-habit-p (a b)
  6799. "Compare the todo states of strings A and B."
  6800. (let ((ha (get-text-property 1 'org-habit-p a))
  6801. (hb (get-text-property 1 'org-habit-p b)))
  6802. (cond ((and ha (not hb)) -1)
  6803. ((and (not ha) hb) +1))))
  6804. (defun org-entries-lessp (a b)
  6805. "Predicate for sorting agenda entries."
  6806. ;; The following variables will be used when the form is evaluated.
  6807. ;; So even though the compiler complains, keep them.
  6808. (let ((ss org-agenda-sorting-strategy-selected))
  6809. (org-dlet
  6810. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6811. (org-cmp-ts a b "")))
  6812. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6813. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6814. (org-cmp-ts a b "scheduled")))
  6815. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6816. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6817. (org-cmp-ts a b "deadline")))
  6818. (deadline-down (if deadline-up (- deadline-up) nil))
  6819. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6820. (org-cmp-ts a b "timestamp_ia")))
  6821. (tsia-down (if tsia-up (- tsia-up) nil))
  6822. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6823. (org-cmp-ts a b "timestamp")))
  6824. (ts-down (if ts-up (- ts-up) nil))
  6825. (time-up (and (org-em 'time-up 'time-down ss)
  6826. (org-cmp-time a b)))
  6827. (time-down (if time-up (- time-up) nil))
  6828. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6829. (org-cmp-values a b 'org-stats)))
  6830. (stats-down (if stats-up (- stats-up) nil))
  6831. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6832. (org-cmp-values a b 'priority)))
  6833. (priority-down (if priority-up (- priority-up) nil))
  6834. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6835. (org-cmp-effort a b)))
  6836. (effort-down (if effort-up (- effort-up) nil))
  6837. (category-up (and (or (org-em 'category-up 'category-down ss)
  6838. (memq 'category-keep ss))
  6839. (org-cmp-category a b)))
  6840. (category-down (if category-up (- category-up) nil))
  6841. (category-keep (if category-up +1 nil))
  6842. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6843. (org-cmp-tag a b)))
  6844. (tag-down (if tag-up (- tag-up) nil))
  6845. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6846. (org-cmp-todo-state a b)))
  6847. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6848. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6849. (org-cmp-habit-p a b)))
  6850. (habit-down (if habit-up (- habit-up) nil))
  6851. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6852. (org-cmp-alpha a b)))
  6853. (alpha-down (if alpha-up (- alpha-up) nil))
  6854. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6855. user-defined-up user-defined-down)
  6856. (when (and need-user-cmp org-agenda-cmp-user-defined
  6857. (functionp org-agenda-cmp-user-defined))
  6858. (setq user-defined-up
  6859. (funcall org-agenda-cmp-user-defined a b)
  6860. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6861. (cdr (assoc
  6862. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  6863. '((-1 . t) (1 . nil) (nil . nil)))))))
  6864. ;;; Agenda restriction lock
  6865. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6866. "Overlay to mark the headline to which agenda commands are restricted.")
  6867. (overlay-put org-agenda-restriction-lock-overlay
  6868. 'face 'org-agenda-restriction-lock)
  6869. (overlay-put org-agenda-restriction-lock-overlay
  6870. 'help-echo "Agendas are currently limited to this subtree.")
  6871. (delete-overlay org-agenda-restriction-lock-overlay)
  6872. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6873. "Set the restriction lock to the agenda item at point from within the agenda.
  6874. When called with a `\\[universal-argument]' prefix, restrict to
  6875. the file which contains the item.
  6876. Argument ARG is the prefix argument."
  6877. (interactive "P")
  6878. (unless (derived-mode-p 'org-agenda-mode)
  6879. (user-error "Not in an Org agenda buffer"))
  6880. (let* ((marker (or (org-get-at-bol 'org-marker)
  6881. (org-agenda-error)))
  6882. (buffer (marker-buffer marker))
  6883. (pos (marker-position marker)))
  6884. (with-current-buffer buffer
  6885. (goto-char pos)
  6886. (org-agenda-set-restriction-lock arg))))
  6887. ;;;###autoload
  6888. (defun org-agenda-set-restriction-lock (&optional type)
  6889. "Set restriction lock for agenda to current subtree or file.
  6890. When in a restricted subtree, remove it.
  6891. The restriction will span over the entire file if TYPE is `file',
  6892. or if type is \\='(4), or if the cursor is before the first headline
  6893. in the file. Otherwise, only apply the restriction to the current
  6894. subtree."
  6895. (interactive "P")
  6896. (if (and org-agenda-overriding-restriction
  6897. (member org-agenda-restriction-lock-overlay
  6898. (overlays-at (point)))
  6899. (equal (overlay-start org-agenda-restriction-lock-overlay)
  6900. (point)))
  6901. (org-agenda-remove-restriction-lock 'noupdate)
  6902. (org-agenda-remove-restriction-lock 'noupdate)
  6903. (and (equal type '(4)) (setq type 'file))
  6904. (setq type (cond
  6905. (type type)
  6906. ((org-at-heading-p) 'subtree)
  6907. ((condition-case nil (org-back-to-heading t) (error nil))
  6908. 'subtree)
  6909. (t 'file)))
  6910. (if (eq type 'subtree)
  6911. (progn
  6912. (setq org-agenda-restrict (current-buffer))
  6913. (setq org-agenda-overriding-restriction 'subtree)
  6914. (put 'org-agenda-files 'org-restrict
  6915. (list (buffer-file-name (buffer-base-buffer))))
  6916. (org-back-to-heading t)
  6917. (move-overlay org-agenda-restriction-lock-overlay
  6918. (point)
  6919. (if org-agenda-restriction-lock-highlight-subtree
  6920. (save-excursion (org-end-of-subtree t t) (point))
  6921. (line-end-position)))
  6922. (move-marker org-agenda-restrict-begin (point))
  6923. (move-marker org-agenda-restrict-end
  6924. (save-excursion (org-end-of-subtree t t)))
  6925. (message "Locking agenda restriction to subtree"))
  6926. (put 'org-agenda-files 'org-restrict
  6927. (list (buffer-file-name (buffer-base-buffer))))
  6928. (setq org-agenda-restrict nil)
  6929. (setq org-agenda-overriding-restriction 'file)
  6930. (move-marker org-agenda-restrict-begin nil)
  6931. (move-marker org-agenda-restrict-end nil)
  6932. (message "Locking agenda restriction to file"))
  6933. (setq current-prefix-arg nil))
  6934. (org-agenda-maybe-redo))
  6935. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6936. "Remove agenda restriction lock."
  6937. (interactive "P")
  6938. (if (not org-agenda-restrict)
  6939. (message "No agenda restriction to remove.")
  6940. (delete-overlay org-agenda-restriction-lock-overlay)
  6941. (delete-overlay org-speedbar-restriction-lock-overlay)
  6942. (setq org-agenda-overriding-restriction nil)
  6943. (setq org-agenda-restrict nil)
  6944. (put 'org-agenda-files 'org-restrict nil)
  6945. (move-marker org-agenda-restrict-begin nil)
  6946. (move-marker org-agenda-restrict-end nil)
  6947. (setq current-prefix-arg nil)
  6948. (message "Agenda restriction lock removed")
  6949. (or noupdate (org-agenda-maybe-redo))))
  6950. (defun org-agenda-maybe-redo ()
  6951. "If there is any window showing the agenda view, update it."
  6952. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6953. org-agenda-buffer-name)
  6954. t))
  6955. (w0 (selected-window)))
  6956. (when w
  6957. (select-window w)
  6958. (org-agenda-redo)
  6959. (select-window w0)
  6960. (if org-agenda-overriding-restriction
  6961. (message "Agenda view shifted to new %s restriction"
  6962. org-agenda-overriding-restriction)
  6963. (message "Agenda restriction lock removed")))))
  6964. ;;; Agenda commands
  6965. (defun org-agenda-check-type (error &rest types)
  6966. "Check if agenda buffer or component is of allowed type.
  6967. If ERROR is non-nil, throw an error, otherwise just return nil.
  6968. Allowed types are `agenda' `todo' `tags' `search'."
  6969. (cond ((not org-agenda-type)
  6970. (error "No Org agenda currently displayed"))
  6971. ((memq org-agenda-type types) t)
  6972. (error
  6973. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  6974. (t nil)))
  6975. (defun org-agenda-Quit ()
  6976. "Exit the agenda, killing the agenda buffer.
  6977. Like `org-agenda-quit', but kill the buffer even when
  6978. `org-agenda-sticky' is non-nil."
  6979. (interactive)
  6980. (org-agenda--quit))
  6981. (defun org-agenda-quit ()
  6982. "Exit the agenda.
  6983. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6984. instead of killing it.
  6985. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6986. the pre-agenda window configuration.
  6987. When column view is active, exit column view instead of the
  6988. agenda."
  6989. (interactive)
  6990. (org-agenda--quit org-agenda-sticky))
  6991. (defun org-agenda--quit (&optional bury)
  6992. (if org-agenda-columns-active
  6993. (org-columns-quit)
  6994. (let ((wconf org-agenda-pre-window-conf)
  6995. (buf (current-buffer))
  6996. (org-agenda-last-indirect-window
  6997. (and (eq org-indirect-buffer-display 'other-window)
  6998. org-agenda-last-indirect-buffer
  6999. (get-buffer-window org-agenda-last-indirect-buffer))))
  7000. (cond
  7001. ((eq org-agenda-window-setup 'other-frame)
  7002. (delete-frame))
  7003. ((eq org-agenda-window-setup 'other-tab)
  7004. (if (fboundp 'tab-bar-close-tab)
  7005. (tab-bar-close-tab)
  7006. (user-error "Your version of Emacs does not have tab bar mode support")))
  7007. ((and org-agenda-restore-windows-after-quit
  7008. wconf)
  7009. ;; Maybe restore the pre-agenda window configuration. Reset
  7010. ;; `org-agenda-pre-window-conf' before running
  7011. ;; `set-window-configuration', which loses the current buffer.
  7012. (setq org-agenda-pre-window-conf nil)
  7013. (set-window-configuration wconf))
  7014. (t
  7015. (when org-agenda-last-indirect-window
  7016. (delete-window org-agenda-last-indirect-window))
  7017. (and (not (eq org-agenda-window-setup 'current-window))
  7018. (not (one-window-p))
  7019. (delete-window))))
  7020. (if bury
  7021. ;; Set the agenda buffer as the current buffer instead of
  7022. ;; passing it as an argument to `bury-buffer' so that
  7023. ;; `bury-buffer' removes it from the window.
  7024. (with-current-buffer buf
  7025. (bury-buffer))
  7026. (kill-buffer buf)
  7027. (setq org-agenda-archives-mode nil
  7028. org-agenda-buffer nil)))))
  7029. (defun org-agenda-exit ()
  7030. "Exit the agenda, killing Org buffers loaded by the agenda.
  7031. Like `org-agenda-Quit', but kill any buffers that were created by
  7032. the agenda. Org buffers visited directly by the user will not be
  7033. touched. Also, exit the agenda even if it is in column view."
  7034. (interactive)
  7035. (when org-agenda-columns-active
  7036. (org-columns-quit))
  7037. (org-release-buffers org-agenda-new-buffers)
  7038. (setq org-agenda-new-buffers nil)
  7039. (org-agenda-Quit))
  7040. (defun org-agenda-kill-all-agenda-buffers ()
  7041. "Kill all buffers in `org-agenda-mode'.
  7042. This is used when toggling sticky agendas."
  7043. (interactive)
  7044. (let (blist)
  7045. (dolist (buf (buffer-list))
  7046. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7047. (push buf blist)))
  7048. (mapc #'kill-buffer blist)))
  7049. (defun org-agenda-execute (arg)
  7050. "Execute another agenda command, keeping same window.
  7051. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7052. in the agenda."
  7053. (interactive "P")
  7054. (let ((org-agenda-window-setup 'current-window))
  7055. (org-agenda arg)))
  7056. (defun org-agenda-redo (&optional all)
  7057. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7058. (interactive "P")
  7059. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7060. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7061. (cpa (unless (eq all t) current-prefix-arg))
  7062. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7063. (org-agenda-sticky nil)
  7064. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7065. org-agenda-buffer-name))
  7066. (org-agenda-keep-modes t)
  7067. (tag-filter org-agenda-tag-filter)
  7068. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7069. (top-hl-filter org-agenda-top-headline-filter)
  7070. (cat-filter org-agenda-category-filter)
  7071. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7072. (re-filter org-agenda-regexp-filter)
  7073. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7074. (effort-filter org-agenda-effort-filter)
  7075. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7076. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7077. (cols org-agenda-columns-active)
  7078. (line (org-current-line))
  7079. (window-line (- line (org-current-line (window-start))))
  7080. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7081. (redo-cmd (get-text-property p 'org-redo-cmd))
  7082. (last-args (get-text-property p 'org-last-args))
  7083. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7084. (org-agenda-overriding-cmd-arguments
  7085. (unless (eq all t)
  7086. (cond ((listp last-args)
  7087. (cons (or cpa (car last-args)) (cdr last-args)))
  7088. ((stringp last-args)
  7089. last-args))))
  7090. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7091. (put 'org-agenda-tag-filter :preset-filter nil)
  7092. (put 'org-agenda-category-filter :preset-filter nil)
  7093. (put 'org-agenda-regexp-filter :preset-filter nil)
  7094. (put 'org-agenda-effort-filter :preset-filter nil)
  7095. (and cols (org-columns-quit))
  7096. (message "Rebuilding agenda buffer...")
  7097. (if series-redo-cmd
  7098. (eval series-redo-cmd t)
  7099. (cl-progv
  7100. (mapcar #'car lprops)
  7101. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7102. (eval redo-cmd t)))
  7103. (setq org-agenda-undo-list nil
  7104. org-agenda-pending-undo-list nil
  7105. org-agenda-tag-filter tag-filter
  7106. org-agenda-category-filter cat-filter
  7107. org-agenda-regexp-filter re-filter
  7108. org-agenda-effort-filter effort-filter
  7109. org-agenda-top-headline-filter top-hl-filter)
  7110. (message "Rebuilding agenda buffer...done")
  7111. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7112. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7113. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7114. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7115. (let ((tag (or tag-filter tag-preset))
  7116. (cat (or cat-filter cat-preset))
  7117. (effort (or effort-filter effort-preset))
  7118. (re (or re-filter re-preset)))
  7119. (when tag (org-agenda-filter-apply tag 'tag t))
  7120. (when cat (org-agenda-filter-apply cat 'category))
  7121. (when effort (org-agenda-filter-apply effort 'effort))
  7122. (when re (org-agenda-filter-apply re 'regexp)))
  7123. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7124. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7125. (org-goto-line line)
  7126. (when (called-interactively-p 'any) (recenter window-line))))
  7127. (defun org-agenda-redo-all (&optional exhaustive)
  7128. "Rebuild all agenda views in the current buffer.
  7129. With a prefix argument, do so in all agenda buffers."
  7130. (interactive "P")
  7131. (if exhaustive
  7132. (dolist (buffer (buffer-list))
  7133. (with-current-buffer buffer
  7134. (when (derived-mode-p 'org-agenda-mode)
  7135. (org-agenda-redo t))))
  7136. (org-agenda-redo t)))
  7137. (defvar org-global-tags-completion-table nil)
  7138. (defvar org-agenda-filter-form nil)
  7139. (defvar org-agenda-filtered-by-category nil)
  7140. (defsubst org-agenda-get-category ()
  7141. "Return the category of the agenda line."
  7142. (org-get-at-bol 'org-category))
  7143. (defun org-agenda-filter-by-category (strip)
  7144. "Filter lines in the agenda buffer that have a specific category.
  7145. The category is that of the current line.
  7146. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7147. When there is already a category filter in place, this command removes the
  7148. filter."
  7149. (interactive "P")
  7150. (if (and org-agenda-filtered-by-category
  7151. org-agenda-category-filter)
  7152. (org-agenda-filter-show-all-cat)
  7153. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7154. (cond
  7155. ((and cat strip)
  7156. (org-agenda-filter-apply
  7157. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7158. (cat
  7159. (org-agenda-filter-apply
  7160. (setq org-agenda-category-filter
  7161. (list (concat "+" cat)))
  7162. 'category))
  7163. (t (error "No category at point"))))))
  7164. (defun org-find-top-headline (&optional pos)
  7165. "Find the topmost parent headline and return it.
  7166. POS when non-nil is the marker or buffer position to start the
  7167. search from."
  7168. (save-excursion
  7169. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7170. (when pos (goto-char pos))
  7171. ;; Skip up to the topmost parent.
  7172. (while (org-up-heading-safe))
  7173. (ignore-errors
  7174. (replace-regexp-in-string
  7175. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7176. (nth 4 (org-heading-components)))))))
  7177. (defvar org-agenda-filtered-by-top-headline nil)
  7178. (defun org-agenda-filter-by-top-headline (strip)
  7179. "Keep only those lines that are descendants from the same top headline.
  7180. The top headline is that of the current line. With prefix arg STRIP, hide
  7181. all lines of the category at point."
  7182. (interactive "P")
  7183. (if org-agenda-filtered-by-top-headline
  7184. (progn
  7185. (setq org-agenda-filtered-by-top-headline nil
  7186. org-agenda-top-headline-filter nil)
  7187. (org-agenda-filter-show-all-top-filter))
  7188. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7189. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7190. (error "No top-level headline at point")))))
  7191. (defvar org-agenda-regexp-filter nil)
  7192. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7193. "Filter agenda entries by a regular expressions.
  7194. You will be prompted for the regular expression, and the agenda
  7195. view will only show entries that are matched by that expression.
  7196. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7197. When there is already a regexp filter active, this command removed the
  7198. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7199. an already existing regexp filter."
  7200. (interactive "P")
  7201. (let* ((strip (equal strip-or-accumulate '(4)))
  7202. (accumulate (equal strip-or-accumulate '(16))))
  7203. (cond
  7204. ((and org-agenda-regexp-filter (not accumulate))
  7205. (org-agenda-filter-show-all-re)
  7206. (message "Regexp filter removed"))
  7207. (t (let ((flt (concat (if strip "-" "+")
  7208. (read-from-minibuffer
  7209. (if strip
  7210. "Hide entries matching regexp: "
  7211. "Narrow to entries matching regexp: ")))))
  7212. (push flt org-agenda-regexp-filter)
  7213. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7214. (defvar org-agenda-effort-filter nil)
  7215. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7216. "Filter agenda entries by effort.
  7217. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7218. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7219. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7220. This last option is in practice not very useful, but it is available for
  7221. consistency with the other filter commands."
  7222. (interactive "P")
  7223. (let* ((efforts (split-string
  7224. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7225. org-global-properties
  7226. t))
  7227. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7228. ;; XXX: the following handles only up to 10 different
  7229. ;; effort values.
  7230. (allowed-keys (if (null efforts) nil
  7231. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7232. (number-sequence 1 (length efforts)))))
  7233. (keep (equal strip-or-accumulate '(16)))
  7234. (negative (equal strip-or-accumulate '(4)))
  7235. (current org-agenda-effort-filter)
  7236. (op nil))
  7237. (while (not (memq op '(?< ?> ?= ?_)))
  7238. (setq op (read-char-exclusive
  7239. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7240. ;; Select appropriate duration. Ignore non-digit characters.
  7241. (if (eq op ?_)
  7242. (progn
  7243. (org-agenda-filter-show-all-effort)
  7244. (message "Effort filter removed"))
  7245. (let ((prompt
  7246. (apply #'format
  7247. (concat "Effort %c "
  7248. (mapconcat (lambda (s) (concat "[%d]" s))
  7249. efforts
  7250. " "))
  7251. op allowed-keys))
  7252. (eff -1))
  7253. (while (not (memq eff allowed-keys))
  7254. (message prompt)
  7255. (setq eff (- (read-char-exclusive) 48)))
  7256. (org-agenda-filter-show-all-effort)
  7257. (setq org-agenda-effort-filter
  7258. (append
  7259. (list (concat (if negative "-" "+")
  7260. (char-to-string op)
  7261. ;; Numbering is 1 2 3 ... 9 0, but we want
  7262. ;; 0 1 2 ... 8 9.
  7263. (nth (mod (1- eff) 10) efforts)))
  7264. (if keep current nil)))
  7265. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7266. (defun org-agenda-filter (&optional strip-or-accumulate)
  7267. "Prompt for a general filter string and apply it to the agenda.
  7268. The string may contain filter elements like
  7269. +category
  7270. +tag
  7271. +<effort > and = are also allowed as effort operators
  7272. +/regexp/
  7273. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7274. `+' is optional if it is not required to separate two string parts.
  7275. Multiple filter elements can be concatenated without spaces, for example
  7276. +work-John<0:10-/plot/
  7277. selects entries with category `work' and effort estimates below 10 minutes,
  7278. and deselects entries with tag `John' or matching the regexp `plot'.
  7279. During entry of the filter, completion for tags, categories and effort
  7280. values is offered. Since the syntax for categories and tags is identical
  7281. there should be no overlap between categories and tags. If there is, tags
  7282. get priority.
  7283. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7284. entire filter, which can be useful in connection with the prompt history.
  7285. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7286. existing ones. A shortcut for this is to add an additional `+' at the
  7287. beginning of the string, like `+-John'.
  7288. With a triple prefix argument, execute the computed filtering defined in
  7289. the variable `org-agenda-auto-exclude-function'."
  7290. (interactive "P")
  7291. (if (equal strip-or-accumulate '(64))
  7292. ;; Execute the auto-exclude action
  7293. (if (not org-agenda-auto-exclude-function)
  7294. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7295. (org-agenda-filter-show-all-tag)
  7296. (setq org-agenda-tag-filter nil)
  7297. (dolist (tag (org-agenda-get-represented-tags))
  7298. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7299. (when modifier
  7300. (push modifier org-agenda-tag-filter))))
  7301. (unless (null org-agenda-tag-filter)
  7302. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7303. ;; Prompt for a filter and act
  7304. (let* ((tag-list (org-agenda-get-represented-tags))
  7305. (category-list (org-agenda-get-represented-categories))
  7306. (negate (equal strip-or-accumulate '(4)))
  7307. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7308. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7309. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7310. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7311. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7312. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7313. (f-string (completing-read
  7314. (concat
  7315. (if negate "Negative filter" "Filter")
  7316. " [+cat-tag<0:10-/regexp/]: ")
  7317. #'org-agenda-filter-completion-function
  7318. nil nil ff))
  7319. (keep (or (if (string-match "^\\+[+-]" f-string)
  7320. (progn (setq f-string (substring f-string 1)) t))
  7321. (equal strip-or-accumulate '(16))))
  7322. (fc (if keep org-agenda-category-filter))
  7323. (ft (if keep org-agenda-tag-filter))
  7324. (fe (if keep org-agenda-effort-filter))
  7325. (fr (if keep org-agenda-regexp-filter))
  7326. pm s)
  7327. ;; If the filter contains a double-quoted string, replace a
  7328. ;; single hyphen by the arbitrary and temporary string "~~~"
  7329. ;; to disambiguate such hyphens from syntactic ones.
  7330. (setq f-string (replace-regexp-in-string
  7331. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7332. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7333. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7334. (when negate
  7335. (setq pm (if (equal pm "+") "-" "+")))
  7336. (cond
  7337. ((match-beginning 3)
  7338. ;; category or tag
  7339. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7340. "~~~" "-" (match-string 3 f-string)))
  7341. (cond
  7342. ((member s tag-list)
  7343. (org-pushnew-to-end (concat pm s) ft))
  7344. ((member s category-list)
  7345. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7346. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7347. fc))
  7348. (t (message
  7349. "`%s%s' filter ignored because tag/category is not represented"
  7350. pm s))))
  7351. ((match-beginning 4)
  7352. ;; effort
  7353. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7354. ((match-beginning 5)
  7355. ;; regexp
  7356. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7357. (setq f-string (substring f-string (match-end 0))))
  7358. (org-agenda-filter-remove-all)
  7359. (and fc (org-agenda-filter-apply
  7360. (setq org-agenda-category-filter fc) 'category))
  7361. (and ft (org-agenda-filter-apply
  7362. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7363. (and fe (org-agenda-filter-apply
  7364. (setq org-agenda-effort-filter fe) 'effort))
  7365. (and fr (org-agenda-filter-apply
  7366. (setq org-agenda-regexp-filter fr) 'regexp))
  7367. (run-hooks 'org-agenda-filter-hook))))
  7368. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7369. "Complete a complex filter string.
  7370. FLAG specifies the type of completion operation to perform. This
  7371. function is passed as a collection function to `completing-read',
  7372. which see."
  7373. (let ((completion-ignore-case t) ;tags are case-sensitive
  7374. (confirm (lambda (x) (stringp x)))
  7375. (prefix "")
  7376. (operator "")
  7377. table)
  7378. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7379. (setq prefix (match-string 1 string)
  7380. operator (match-string 2 string)
  7381. string (match-string 3 string)))
  7382. (cond
  7383. ((member operator '("+" "-" "" nil))
  7384. (setq table (append (org-agenda-get-represented-categories)
  7385. (org-agenda-get-represented-tags))))
  7386. ((member operator '("<" ">" "="))
  7387. (setq table (split-string
  7388. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7389. org-global-properties
  7390. t))
  7391. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7392. " +")))
  7393. (t (setq table nil)))
  7394. (pcase flag
  7395. (`t (all-completions string table confirm))
  7396. (`lambda (assoc string table)) ;exact match?
  7397. (`nil
  7398. (pcase (try-completion string table confirm)
  7399. ((and completion (pred stringp))
  7400. (concat prefix completion))
  7401. (completion completion)))
  7402. (_ nil))))
  7403. (defun org-agenda-filter-remove-all ()
  7404. "Remove all filters from the current agenda buffer."
  7405. (interactive)
  7406. (when org-agenda-tag-filter
  7407. (org-agenda-filter-show-all-tag))
  7408. (when org-agenda-category-filter
  7409. (org-agenda-filter-show-all-cat))
  7410. (when org-agenda-regexp-filter
  7411. (org-agenda-filter-show-all-re))
  7412. (when org-agenda-top-headline-filter
  7413. (org-agenda-filter-show-all-top-filter))
  7414. (when org-agenda-effort-filter
  7415. (org-agenda-filter-show-all-effort))
  7416. (org-agenda-finalize)
  7417. (when (called-interactively-p 'interactive)
  7418. (message "All agenda filters removed")))
  7419. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7420. "Keep only those lines in the agenda buffer that have a specific tag.
  7421. The tag is selected with its fast selection letter, as configured.
  7422. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7423. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7424. instead of replacing it.
  7425. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7426. i.e. don't
  7427. filter on all its group members.
  7428. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7429. should be used to exclude the search - the interactive user can
  7430. also press `-' or `+' to switch between filtering and excluding."
  7431. (interactive "P")
  7432. (let* ((alist org-tag-alist-for-agenda)
  7433. (seen-chars nil)
  7434. (tag-chars (mapconcat
  7435. (lambda (x) (if (and (not (symbolp (car x)))
  7436. (cdr x)
  7437. (not (member (cdr x) seen-chars)))
  7438. (progn
  7439. (push (cdr x) seen-chars)
  7440. (char-to-string (cdr x)))
  7441. ""))
  7442. org-tag-alist-for-agenda ""))
  7443. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7444. (string-to-list tag-chars)))
  7445. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7446. (accumulate (equal strip-or-accumulate '(16)))
  7447. (expand (not (equal strip-or-accumulate '(64))))
  7448. (inhibit-read-only t)
  7449. (current org-agenda-tag-filter)
  7450. a tag) ;; n
  7451. (unless char
  7452. (while (not (memq char valid-char-list))
  7453. (org-unlogged-message
  7454. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7455. (if exclude "Exclude[+]" "Filter[-]")
  7456. (if expand "" " (no grouptag expand)")
  7457. tag-chars
  7458. (if org-agenda-auto-exclude-function "[RET] " ""))
  7459. (setq char (read-char-exclusive))
  7460. ;; Excluding or filtering down
  7461. (cond ((eq char ?-) (setq exclude t))
  7462. ((eq char ?+) (setq exclude nil)))))
  7463. (when (eq char ?\t)
  7464. (unless (local-variable-p 'org-global-tags-completion-table)
  7465. (setq-local org-global-tags-completion-table
  7466. (org-global-tags-completion-table)))
  7467. (let ((completion-ignore-case t))
  7468. (setq tag (completing-read
  7469. "Tag: " org-global-tags-completion-table nil t))))
  7470. (cond
  7471. ((eq char ?\r)
  7472. (org-agenda-filter-show-all-tag)
  7473. (when org-agenda-auto-exclude-function
  7474. (setq org-agenda-tag-filter nil)
  7475. (dolist (tag (org-agenda-get-represented-tags))
  7476. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7477. (when modifier
  7478. (push modifier org-agenda-tag-filter))))
  7479. (unless (null org-agenda-tag-filter)
  7480. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7481. ((eq char ?\\)
  7482. (org-agenda-filter-show-all-tag)
  7483. (when (get 'org-agenda-tag-filter :preset-filter)
  7484. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7485. ((eq char ?.)
  7486. (setq org-agenda-tag-filter
  7487. (mapcar (lambda(tag) (concat "+" tag))
  7488. (org-get-at-bol 'tags)))
  7489. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7490. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7491. ((or (eq char ?\s)
  7492. (setq a (rassoc char alist))
  7493. (and tag (setq a (cons tag nil))))
  7494. (org-agenda-filter-show-all-tag)
  7495. (setq tag (car a))
  7496. (setq org-agenda-tag-filter
  7497. (cons (concat (if exclude "-" "+") tag)
  7498. (if accumulate current nil)))
  7499. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7500. (t (error "Invalid tag selection character %c" char)))))
  7501. (defun org-agenda-get-represented-categories ()
  7502. "Return a list of all categories used in this agenda buffer."
  7503. (or org-agenda-represented-categories
  7504. (when (derived-mode-p 'org-agenda-mode)
  7505. (let ((pos (point-min)) categories)
  7506. (while (and (< pos (point-max))
  7507. (setq pos (next-single-property-change
  7508. pos 'org-category nil (point-max))))
  7509. (push (get-text-property pos 'org-category) categories))
  7510. (setq org-agenda-represented-categories
  7511. ;; Enclose category names with a hyphen in double
  7512. ;; quotes to process them specially in `org-agenda-filter'.
  7513. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7514. (nreverse (org-uniquify (delq nil categories)))))))))
  7515. (defvar org-tag-groups-alist-for-agenda)
  7516. (defun org-agenda-get-represented-tags ()
  7517. "Return a list of all tags used in this agenda buffer.
  7518. These will be lower-case, for filtering."
  7519. (or org-agenda-represented-tags
  7520. (when (derived-mode-p 'org-agenda-mode)
  7521. (let ((pos (point-min)) tags-lists tt)
  7522. (while (and (< pos (point-max))
  7523. (setq pos (next-single-property-change
  7524. pos 'tags nil (point-max))))
  7525. (setq tt (get-text-property pos 'tags))
  7526. (if tt (push tt tags-lists)))
  7527. (setq tags-lists
  7528. (nreverse (org-uniquify
  7529. (delq nil (apply #'append tags-lists)))))
  7530. (dolist (tag tags-lists)
  7531. (mapc
  7532. (lambda (group)
  7533. (when (member tag group)
  7534. (push (car group) tags-lists)))
  7535. org-tag-groups-alist-for-agenda))
  7536. (setq org-agenda-represented-tags tags-lists)))))
  7537. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7538. "Create the form that tests a line for agenda filter.
  7539. Optional argument EXPAND can be used for the TYPE tag and will
  7540. expand the tags in the FILTER if any of the tags in FILTER are
  7541. grouptags."
  7542. (let ((multi-pos-cats
  7543. (and (eq type 'category)
  7544. (string-match-p "\\+.*\\+"
  7545. (mapconcat (lambda (cat) (substring cat 0 1))
  7546. filter ""))))
  7547. f f1)
  7548. (cond
  7549. ;; Tag filter
  7550. ((eq type 'tag)
  7551. (setq filter
  7552. (delete-dups
  7553. (append (get 'org-agenda-tag-filter :preset-filter)
  7554. filter)))
  7555. (dolist (x filter)
  7556. (let ((op (string-to-char x)))
  7557. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7558. (setq x (list x)))
  7559. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7560. (push f1 f))))
  7561. ;; Category filter
  7562. ((eq type 'category)
  7563. (setq filter
  7564. (delete-dups
  7565. (append (get 'org-agenda-category-filter :preset-filter)
  7566. filter)))
  7567. (dolist (x filter)
  7568. (if (equal "-" (substring x 0 1))
  7569. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7570. (setq f1 (list 'equal (substring x 1) 'cat)))
  7571. (push f1 f)))
  7572. ;; Regexp filter
  7573. ((eq type 'regexp)
  7574. (setq filter
  7575. (delete-dups
  7576. (append (get 'org-agenda-regexp-filter :preset-filter)
  7577. filter)))
  7578. (dolist (x filter)
  7579. (if (equal "-" (substring x 0 1))
  7580. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7581. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7582. (push f1 f)))
  7583. ;; Effort filter
  7584. ((eq type 'effort)
  7585. (setq filter
  7586. (delete-dups
  7587. (append (get 'org-agenda-effort-filter :preset-filter)
  7588. filter)))
  7589. (dolist (x filter)
  7590. (push (org-agenda-filter-effort-form x) f))))
  7591. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  7592. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7593. "Return a form associated to tag-expression TAGS.
  7594. Build a form testing a line for agenda filter for
  7595. tag-expressions. OP is an operator of type CHAR that allows the
  7596. function to set the right switches in the returned form."
  7597. (let (form)
  7598. ;; Any of the expressions can match if OP is +, all must match if
  7599. ;; the operator is -.
  7600. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7601. (let* ((tag (substring x 1))
  7602. (f (cond
  7603. ((string= "" tag) 'tags)
  7604. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7605. ;; TAG is a regexp.
  7606. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7607. (t (list 'member tag 'tags)))))
  7608. (push (if (eq op ?-) (list 'not f) f) form)))))
  7609. (defun org-agenda-filter-effort-form (e)
  7610. "Return the form to compare the effort of the current line with what E says.
  7611. E looks like \"+<2:25\"."
  7612. (let (op)
  7613. (setq e (substring e 1))
  7614. (setq op (string-to-char e) e (substring e 1))
  7615. (setq op (cond ((equal op ?<) '<=)
  7616. ((equal op ?>) '>=)
  7617. ((equal op ??) op)
  7618. (t '=)))
  7619. (list 'org-agenda-compare-effort (list 'quote op)
  7620. (org-duration-to-minutes e))))
  7621. (defun org-agenda-compare-effort (op value)
  7622. "Compare the effort of the current line with VALUE, using OP.
  7623. If the line does not have an effort defined, return nil."
  7624. ;; `effort-minutes' property cannot be extracted directly from
  7625. ;; current line but is stored as a property in `txt'.
  7626. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7627. (funcall op
  7628. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  7629. value)))
  7630. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7631. "Expand group tags in FILTER for the agenda.
  7632. When NO-OPERATOR is non-nil, do not add the + operator to
  7633. returned tags."
  7634. (if org-group-tags
  7635. (let (case-fold-search rtn)
  7636. (mapc
  7637. (lambda (f)
  7638. (let (f0 dir)
  7639. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7640. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7641. (setq dir (if no-operator "" "+") f0 f))
  7642. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7643. (org-tags-expand f0 t))
  7644. rtn))))
  7645. filter)
  7646. (reverse rtn))
  7647. filter))
  7648. (defun org-agenda-filter-apply (filter type &optional expand)
  7649. "Set FILTER as the new agenda filter and apply it.
  7650. Optional argument EXPAND can be used for the TYPE tag and will
  7651. expand the tags in the FILTER if any of the tags in FILTER are
  7652. grouptags."
  7653. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7654. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7655. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  7656. filter type expand))
  7657. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7658. ;; category is used as the filter:
  7659. (setq org-agenda-filtered-by-category
  7660. (and (eq type 'category)
  7661. (not (equal (substring (car filter) 0 1) "-"))))
  7662. (org-agenda-set-mode-name)
  7663. (save-excursion
  7664. (goto-char (point-min))
  7665. (while (not (eobp))
  7666. (when (or (org-get-at-bol 'org-hd-marker)
  7667. (org-get-at-bol 'org-marker))
  7668. (org-dlet
  7669. ((tags (org-get-at-bol 'tags))
  7670. (cat (org-agenda-get-category))
  7671. (txt (or (org-get-at-bol 'txt) "")))
  7672. (unless (eval org-agenda-filter-form t)
  7673. (org-agenda-filter-hide-line type))))
  7674. (beginning-of-line 2)))
  7675. (when (get-char-property (point) 'invisible)
  7676. (ignore-errors (org-agenda-previous-line))))
  7677. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7678. "Filter by top headline HL."
  7679. (org-agenda-set-mode-name)
  7680. (save-excursion
  7681. (goto-char (point-min))
  7682. (while (not (eobp))
  7683. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7684. (tophl (and pos (org-find-top-headline pos))))
  7685. (when (and tophl (funcall (if negative 'identity 'not)
  7686. (string= hl tophl)))
  7687. (org-agenda-filter-hide-line 'top-headline)))
  7688. (beginning-of-line 2)))
  7689. (when (get-char-property (point) 'invisible)
  7690. (org-agenda-previous-line))
  7691. (setq org-agenda-top-headline-filter hl
  7692. org-agenda-filtered-by-top-headline t))
  7693. (defun org-agenda-filter-hide-line (type)
  7694. "If current line is TYPE, hide it in the agenda buffer."
  7695. (let* (buffer-invisibility-spec
  7696. (beg (max (point-min) (1- (line-beginning-position))))
  7697. (end (line-end-position)))
  7698. (let ((inhibit-read-only t))
  7699. (add-text-properties
  7700. beg end `(invisible org-filtered org-filter-type ,type)))))
  7701. (defun org-agenda-remove-filter (type)
  7702. "Remove filter of type TYPE from the agenda buffer."
  7703. (interactive)
  7704. (save-excursion
  7705. (goto-char (point-min))
  7706. (let ((inhibit-read-only t) pos)
  7707. (while (setq pos (text-property-any (point) (point-max)
  7708. 'org-filter-type type))
  7709. (goto-char pos)
  7710. (remove-text-properties
  7711. (point) (next-single-property-change (point) 'org-filter-type)
  7712. `(invisible org-filtered org-filter-type ,type))))
  7713. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7714. (setq org-agenda-filter-form nil)
  7715. (org-agenda-set-mode-name)
  7716. (org-agenda-finalize)))
  7717. (defun org-agenda-filter-show-all-tag nil
  7718. (org-agenda-remove-filter 'tag))
  7719. (defun org-agenda-filter-show-all-re nil
  7720. (org-agenda-remove-filter 'regexp))
  7721. (defun org-agenda-filter-show-all-effort nil
  7722. (org-agenda-remove-filter 'effort))
  7723. (defun org-agenda-filter-show-all-cat nil
  7724. (org-agenda-remove-filter 'category))
  7725. (defun org-agenda-filter-show-all-top-filter nil
  7726. (org-agenda-remove-filter 'top-headline))
  7727. (defun org-agenda-manipulate-query-add ()
  7728. "Manipulate the query by adding a search term with positive selection.
  7729. Positive selection means the term must be matched for selection of an entry."
  7730. (interactive)
  7731. (org-agenda-manipulate-query ?\[))
  7732. (defun org-agenda-manipulate-query-subtract ()
  7733. "Manipulate the query by adding a search term with negative selection.
  7734. Negative selection means term must not be matched for selection of an entry."
  7735. (interactive)
  7736. (org-agenda-manipulate-query ?\]))
  7737. (defun org-agenda-manipulate-query-add-re ()
  7738. "Manipulate the query by adding a search regexp with positive selection.
  7739. Positive selection means the regexp must match for selection of an entry."
  7740. (interactive)
  7741. (org-agenda-manipulate-query ?\{))
  7742. (defun org-agenda-manipulate-query-subtract-re ()
  7743. "Manipulate the query by adding a search regexp with negative selection.
  7744. Negative selection means regexp must not match for selection of an entry."
  7745. (interactive)
  7746. (org-agenda-manipulate-query ?\}))
  7747. (defun org-agenda-manipulate-query (char)
  7748. (cond
  7749. ((eq org-agenda-type 'agenda)
  7750. (let ((org-agenda-include-inactive-timestamps t))
  7751. (org-agenda-redo))
  7752. (message "Display now includes inactive timestamps as well"))
  7753. ((eq org-agenda-type 'search)
  7754. (org-add-to-string
  7755. 'org-agenda-query-string
  7756. (if org-agenda-last-search-view-search-was-boolean
  7757. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7758. (?\{ . " +{}") (?\} . " -{}"))))
  7759. " "))
  7760. (setq org-agenda-redo-command
  7761. (list 'org-search-view
  7762. (car (get-text-property (min (1- (point-max)) (point))
  7763. 'org-last-args))
  7764. org-agenda-query-string
  7765. (+ (length org-agenda-query-string)
  7766. (if (member char '(?\{ ?\})) 0 1))))
  7767. (set-register org-agenda-query-register org-agenda-query-string)
  7768. (let ((org-agenda-overriding-arguments
  7769. (cdr org-agenda-redo-command)))
  7770. (org-agenda-redo)))
  7771. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7772. org-agenda-type))))
  7773. (defun org-add-to-string (var string)
  7774. (set var (concat (symbol-value var) string)))
  7775. (defun org-agenda-goto-date (date)
  7776. "Jump to DATE in agenda."
  7777. (interactive
  7778. (list
  7779. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  7780. (org-read-date))))
  7781. (let* ((day (time-to-days (org-time-string-to-time date)))
  7782. (org-agenda-sticky-orig org-agenda-sticky)
  7783. (org-agenda-buffer-tmp-name (buffer-name))
  7784. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7785. (0-arg (or current-prefix-arg (car args)))
  7786. (2-arg (nth 2 args))
  7787. (with-hour-p (nth 4 org-agenda-redo-command))
  7788. (newcmd (list 'org-agenda-list 0-arg date
  7789. (org-agenda-span-to-ndays
  7790. 2-arg (org-time-string-to-absolute date))
  7791. with-hour-p))
  7792. (newargs (cdr newcmd))
  7793. (inhibit-read-only t)
  7794. org-agenda-sticky)
  7795. (if (not (org-agenda-check-type t 'agenda))
  7796. (error "Not available in non-agenda views")
  7797. (add-text-properties (point-min) (point-max)
  7798. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7799. (org-agenda-redo)
  7800. (goto-char (point-min))
  7801. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7802. (save-excursion (move-beginning-of-line 2) (eobp))))
  7803. (move-beginning-of-line 2))
  7804. (setq org-agenda-sticky org-agenda-sticky-orig
  7805. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7806. (defun org-agenda-goto-today ()
  7807. "Go to today."
  7808. (interactive)
  7809. (org-agenda-check-type t 'agenda)
  7810. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7811. (curspan (nth 2 args))
  7812. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7813. (cond
  7814. (tdpos (goto-char tdpos))
  7815. ((eq org-agenda-type 'agenda)
  7816. (let* ((sd (org-agenda-compute-starting-span
  7817. (org-today) (or curspan org-agenda-span)))
  7818. (org-agenda-overriding-arguments args))
  7819. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7820. (org-agenda-redo)
  7821. (org-agenda-find-same-or-today-or-agenda)))
  7822. (t (error "Cannot find today")))))
  7823. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7824. (goto-char
  7825. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7826. (text-property-any (point-min) (point-max) 'org-today t)
  7827. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7828. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7829. (org-agenda-backward-block))
  7830. (point-min))))
  7831. (defun org-agenda-backward-block ()
  7832. "Move backward by one agenda block."
  7833. (interactive)
  7834. (org-agenda-forward-block 'backward))
  7835. (defun org-agenda-forward-block (&optional backward)
  7836. "Move forward by one agenda block.
  7837. When optional argument BACKWARD is set, go backward."
  7838. (interactive)
  7839. (cond ((not (derived-mode-p 'org-agenda-mode))
  7840. (user-error
  7841. "Cannot execute this command outside of org-agenda-mode buffers"))
  7842. ((looking-at (if backward "\\`" "\\'"))
  7843. (message "Already at the %s block" (if backward "first" "last")))
  7844. (t (let ((_pos (prog1 (point)
  7845. (ignore-errors (if backward (backward-char 1)
  7846. (move-end-of-line 1)))))
  7847. (f (if backward
  7848. #'previous-single-property-change
  7849. #'next-single-property-change))
  7850. moved dest)
  7851. (while (and (setq dest (funcall
  7852. f (point) 'org-agenda-structural-header))
  7853. (not (get-text-property
  7854. (point) 'org-agenda-structural-header)))
  7855. (setq moved t)
  7856. (goto-char dest))
  7857. (if moved (move-beginning-of-line 1)
  7858. (goto-char (if backward (point-min) (point-max)))
  7859. (move-beginning-of-line 1)
  7860. (message "No %s block" (if backward "previous" "further")))))))
  7861. (defun org-agenda-later (arg)
  7862. "Go forward in time by the current span.
  7863. With prefix ARG, go forward that many times the current span."
  7864. (interactive "p")
  7865. (org-agenda-check-type t 'agenda)
  7866. (let* ((wstart (window-start))
  7867. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7868. (span (or (nth 2 args) org-agenda-current-span))
  7869. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7870. (greg (calendar-gregorian-from-absolute sd))
  7871. (cnt (org-get-at-bol 'org-day-cnt))
  7872. greg2)
  7873. (cond
  7874. ((numberp span)
  7875. (setq sd (+ (* span arg) sd)))
  7876. ((eq span 'day)
  7877. (setq sd (+ arg sd)))
  7878. ((eq span 'week)
  7879. (setq sd (+ (* 7 arg) sd)))
  7880. ((eq span 'fortnight)
  7881. (setq sd (+ (* 14 arg) sd)))
  7882. ((eq span 'month)
  7883. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7884. sd (calendar-absolute-from-gregorian greg2))
  7885. (setcar greg2 (1+ (car greg2))))
  7886. ((eq span 'year)
  7887. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7888. sd (calendar-absolute-from-gregorian greg2))
  7889. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7890. (t
  7891. (setq sd (+ (* span arg) sd))))
  7892. (let ((org-agenda-overriding-cmd
  7893. ;; `cmd' may have been set by `org-agenda-run-series' which
  7894. ;; uses `org-agenda-overriding-cmd' to decide whether
  7895. ;; overriding is allowed for `cmd'
  7896. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7897. (org-agenda-overriding-arguments
  7898. (list (car args) sd span)))
  7899. (org-agenda-redo)
  7900. (org-agenda-find-same-or-today-or-agenda cnt))
  7901. (set-window-start nil wstart)))
  7902. (defun org-agenda-earlier (arg)
  7903. "Go backward in time by the current span.
  7904. With prefix ARG, go backward that many times the current span."
  7905. (interactive "p")
  7906. (org-agenda-later (- arg)))
  7907. (defun org-agenda-view-mode-dispatch ()
  7908. "Call one of the view mode commands."
  7909. (interactive)
  7910. (org-unlogged-message
  7911. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7912. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7913. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7914. (pcase (read-char-exclusive)
  7915. (?\ (call-interactively 'org-agenda-reset-view))
  7916. (?d (call-interactively 'org-agenda-day-view))
  7917. (?w (call-interactively 'org-agenda-week-view))
  7918. (?t (call-interactively 'org-agenda-fortnight-view))
  7919. (?m (call-interactively 'org-agenda-month-view))
  7920. (?y (call-interactively 'org-agenda-year-view))
  7921. (?l (call-interactively 'org-agenda-log-mode))
  7922. (?L (org-agenda-log-mode '(4)))
  7923. (?c (org-agenda-log-mode 'clockcheck))
  7924. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7925. (?a (call-interactively 'org-agenda-archives-mode))
  7926. (?A (org-agenda-archives-mode 'files))
  7927. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7928. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7929. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7930. (?D (call-interactively 'org-agenda-toggle-diary))
  7931. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7932. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7933. (org-agenda-check-type t 'agenda)
  7934. (org-agenda-redo))
  7935. (message "Display now includes inactive timestamps as well"))
  7936. (?q (message "Abort"))
  7937. (key (user-error "Invalid key: %s" key))))
  7938. (defun org-agenda-reset-view ()
  7939. "Switch to default view for agenda."
  7940. (interactive)
  7941. (org-agenda-change-time-span org-agenda-span))
  7942. (defun org-agenda-day-view (&optional day-of-month)
  7943. "Switch to daily view for agenda.
  7944. With argument DAY-OF-MONTH, switch to that day of the month."
  7945. (interactive "P")
  7946. (org-agenda-change-time-span 'day day-of-month))
  7947. (defun org-agenda-week-view (&optional iso-week)
  7948. "Switch to weekly view for agenda.
  7949. With argument ISO-WEEK, switch to the corresponding ISO week.
  7950. If ISO-WEEK has more then 2 digits, only the last two encode
  7951. the week. Any digits before this encode a year. So 200712
  7952. means week 12 of year 2007. Years ranging from 70 years ago
  7953. to 30 years in the future can also be written as 2-digit years."
  7954. (interactive "P")
  7955. (org-agenda-change-time-span 'week iso-week))
  7956. (defun org-agenda-fortnight-view (&optional iso-week)
  7957. "Switch to fortnightly view for agenda.
  7958. With argument ISO-WEEK, switch to the corresponding ISO week.
  7959. If ISO-WEEK has more then 2 digits, only the last two encode
  7960. the week. Any digits before this encode a year. So 200712
  7961. means week 12 of year 2007. Years ranging from 70 years ago
  7962. to 30 years in the future can also be written as 2-digit years."
  7963. (interactive "P")
  7964. (org-agenda-change-time-span 'fortnight iso-week))
  7965. (defun org-agenda-month-view (&optional month)
  7966. "Switch to monthly view for agenda.
  7967. With argument MONTH, switch to that month. If MONTH has more
  7968. then 2 digits, only the last two encode the month. Any digits
  7969. before this encode a year. So 200712 means December year 2007.
  7970. Years ranging from 70 years ago to 30 years in the future can
  7971. also be written as 2-digit years."
  7972. (interactive "P")
  7973. (org-agenda-change-time-span 'month month))
  7974. (defun org-agenda-year-view (&optional year)
  7975. "Switch to yearly view for agenda.
  7976. With argument YEAR, switch to that year. Years ranging from 70
  7977. years ago to 30 years in the future can also be written as
  7978. 2-digit years."
  7979. (interactive "P")
  7980. (when year
  7981. (setq year (org-small-year-to-year year)))
  7982. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7983. (org-agenda-change-time-span 'year year)
  7984. (error "Abort")))
  7985. (defun org-agenda-change-time-span (span &optional n)
  7986. "Change the agenda view to SPAN.
  7987. SPAN may be `day', `week', `fortnight', `month', `year'."
  7988. (org-agenda-check-type t 'agenda)
  7989. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7990. (curspan (nth 2 args)))
  7991. (when (and (not n) (equal curspan span))
  7992. (error "Viewing span is already \"%s\"" span))
  7993. (let* ((sd (or (org-get-at-bol 'day)
  7994. (nth 1 args)
  7995. org-starting-day))
  7996. (sd (org-agenda-compute-starting-span sd span n))
  7997. (org-agenda-overriding-cmd
  7998. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7999. (org-agenda-overriding-arguments
  8000. (list (car args) sd span)))
  8001. (org-agenda-redo)
  8002. (org-agenda-find-same-or-today-or-agenda))
  8003. (org-agenda-set-mode-name)
  8004. (message "Switched to %s view" span)))
  8005. (defun org-agenda-compute-starting-span (sd span &optional n)
  8006. "Compute starting date for agenda.
  8007. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8008. is a cons cell with the starting date and the number of days,
  8009. so that the date SD will be in that range."
  8010. (let* ((greg (calendar-gregorian-from-absolute sd))
  8011. ;; (dg (nth 1 greg))
  8012. (mg (car greg))
  8013. (yg (nth 2 greg)))
  8014. (cond
  8015. ((eq span 'day)
  8016. (when n
  8017. (setq sd (+ (calendar-absolute-from-gregorian
  8018. (list mg 1 yg))
  8019. n -1))))
  8020. ((or (eq span 'week) (eq span 'fortnight))
  8021. (let* ((nt (calendar-day-of-week
  8022. (calendar-gregorian-from-absolute sd)))
  8023. (d (if org-agenda-start-on-weekday
  8024. (- nt org-agenda-start-on-weekday)
  8025. 0))
  8026. y1)
  8027. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8028. (when n
  8029. (require 'cal-iso)
  8030. (when (> n 99)
  8031. (setq y1 (org-small-year-to-year (/ n 100))
  8032. n (mod n 100)))
  8033. (setq sd
  8034. (calendar-iso-to-absolute
  8035. (list n 1
  8036. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8037. ((eq span 'month)
  8038. (let (y1)
  8039. (when (and n (> n 99))
  8040. (setq y1 (org-small-year-to-year (/ n 100))
  8041. n (mod n 100)))
  8042. (setq sd (calendar-absolute-from-gregorian
  8043. (list (or n mg) 1 (or y1 yg))))))
  8044. ((eq span 'year)
  8045. (setq sd (calendar-absolute-from-gregorian
  8046. (list 1 1 (or n yg))))))
  8047. sd))
  8048. (defun org-agenda-next-date-line (&optional arg)
  8049. "Jump to the next line indicating a date in agenda buffer."
  8050. (interactive "p")
  8051. (org-agenda-check-type t 'agenda)
  8052. (beginning-of-line 1)
  8053. ;; This does not work if user makes date format that starts with a blank
  8054. (when (looking-at-p "^\\S-") (forward-char 1))
  8055. (unless (re-search-forward "^\\S-" nil t arg)
  8056. (backward-char 1)
  8057. (error "No next date after this line in this buffer"))
  8058. (goto-char (match-beginning 0)))
  8059. (defun org-agenda-previous-date-line (&optional arg)
  8060. "Jump to the previous line indicating a date in agenda buffer."
  8061. (interactive "p")
  8062. (org-agenda-check-type t 'agenda)
  8063. (beginning-of-line 1)
  8064. (unless (re-search-backward "^\\S-" nil t arg)
  8065. (error "No previous date before this line in this buffer")))
  8066. ;; Initialize the highlight
  8067. (defvar org-hl (make-overlay 1 1))
  8068. (overlay-put org-hl 'face 'highlight)
  8069. (defun org-highlight (begin end &optional buffer)
  8070. "Highlight a region with overlay."
  8071. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8072. (defun org-unhighlight ()
  8073. "Detach overlay INDEX."
  8074. (delete-overlay org-hl))
  8075. (defun org-unhighlight-once ()
  8076. "Remove the highlight from its position, and this function from the hook."
  8077. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8078. (org-unhighlight))
  8079. (defvar org-agenda-pre-follow-window-conf nil)
  8080. (defun org-agenda-follow-mode ()
  8081. "Toggle follow mode in an agenda buffer."
  8082. (interactive)
  8083. (unless org-agenda-follow-mode
  8084. (setq org-agenda-pre-follow-window-conf
  8085. (current-window-configuration)))
  8086. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8087. (unless org-agenda-follow-mode
  8088. (set-window-configuration org-agenda-pre-follow-window-conf))
  8089. (org-agenda-set-mode-name)
  8090. (org-agenda-do-context-action)
  8091. (message "Follow mode is %s"
  8092. (if org-agenda-follow-mode "on" "off")))
  8093. (defun org-agenda-entry-text-mode (&optional arg)
  8094. "Toggle entry text mode in an agenda buffer."
  8095. (interactive "P")
  8096. (if (or org-agenda-tag-filter
  8097. org-agenda-category-filter
  8098. org-agenda-regexp-filter
  8099. org-agenda-top-headline-filter)
  8100. (user-error "Can't show entry text in filtered views")
  8101. (setq org-agenda-entry-text-mode (or (integerp arg)
  8102. (not org-agenda-entry-text-mode)))
  8103. (org-agenda-entry-text-hide)
  8104. (and org-agenda-entry-text-mode
  8105. (let ((org-agenda-entry-text-maxlines
  8106. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8107. (org-agenda-entry-text-show)))
  8108. (org-agenda-set-mode-name)
  8109. (message "Entry text mode is %s%s"
  8110. (if org-agenda-entry-text-mode "on" "off")
  8111. (if (not org-agenda-entry-text-mode) ""
  8112. (format " (maximum number of lines is %d)"
  8113. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8114. (defun org-agenda-clockreport-mode ()
  8115. "Toggle clocktable mode in an agenda buffer."
  8116. (interactive)
  8117. (org-agenda-check-type t 'agenda)
  8118. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8119. (org-agenda-set-mode-name)
  8120. (org-agenda-redo)
  8121. (message "Clocktable mode is %s"
  8122. (if org-agenda-clockreport-mode "on" "off")))
  8123. (defun org-agenda-log-mode (&optional special)
  8124. "Toggle log mode in an agenda buffer.
  8125. With argument SPECIAL, show all possible log items, not only the ones
  8126. configured in `org-agenda-log-mode-items'.
  8127. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8128. log items, nothing else."
  8129. (interactive "P")
  8130. (org-agenda-check-type t 'agenda)
  8131. (setq org-agenda-show-log
  8132. (cond
  8133. ((equal special '(16)) 'only)
  8134. ((eq special 'clockcheck)
  8135. (if (eq org-agenda-show-log 'clockcheck)
  8136. nil 'clockcheck))
  8137. (special '(closed clock state))
  8138. (t (not org-agenda-show-log))))
  8139. (org-agenda-set-mode-name)
  8140. (org-agenda-redo)
  8141. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8142. (defun org-agenda-archives-mode (&optional with-files)
  8143. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8144. When called with a prefix argument, include all archive files as well."
  8145. (interactive "P")
  8146. (setq org-agenda-archives-mode
  8147. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8148. (with-files t)
  8149. (org-agenda-archives-mode nil)
  8150. (t 'trees)))
  8151. (org-agenda-set-mode-name)
  8152. (org-agenda-redo)
  8153. (message
  8154. "%s"
  8155. (cond
  8156. ((eq org-agenda-archives-mode nil)
  8157. "No archives are included")
  8158. ((eq org-agenda-archives-mode 'trees)
  8159. (format "Trees with :%s: tag are included" org-archive-tag))
  8160. ((eq org-agenda-archives-mode t)
  8161. (format "Trees with :%s: tag and all active archive files are included"
  8162. org-archive-tag)))))
  8163. (defun org-agenda-toggle-diary ()
  8164. "Toggle diary inclusion in an agenda buffer."
  8165. (interactive)
  8166. (org-agenda-check-type t 'agenda)
  8167. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8168. (org-agenda-redo)
  8169. (org-agenda-set-mode-name)
  8170. (message "Diary inclusion turned %s"
  8171. (if org-agenda-include-diary "on" "off")))
  8172. (defun org-agenda-toggle-deadlines ()
  8173. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8174. (interactive)
  8175. (org-agenda-check-type t 'agenda)
  8176. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8177. (org-agenda-redo)
  8178. (org-agenda-set-mode-name)
  8179. (message "Deadlines inclusion turned %s"
  8180. (if org-agenda-include-deadlines "on" "off")))
  8181. (defun org-agenda-toggle-time-grid ()
  8182. "Toggle time grid in an agenda buffer."
  8183. (interactive)
  8184. (org-agenda-check-type t 'agenda)
  8185. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8186. (org-agenda-redo)
  8187. (org-agenda-set-mode-name)
  8188. (message "Time-grid turned %s"
  8189. (if org-agenda-use-time-grid "on" "off")))
  8190. (defun org-agenda-set-mode-name ()
  8191. "Set the mode name to indicate all the small mode settings."
  8192. (setq mode-name
  8193. (list "Org-Agenda"
  8194. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8195. " "
  8196. '(:eval (org-agenda-span-name org-agenda-current-span))
  8197. (if org-agenda-follow-mode " Follow" "")
  8198. (if org-agenda-entry-text-mode " ETxt" "")
  8199. (if org-agenda-include-diary " Diary" "")
  8200. (if org-agenda-include-deadlines " Ddl" "")
  8201. (if org-agenda-use-time-grid " Grid" "")
  8202. (if (and (boundp 'org-habit-show-habits)
  8203. org-habit-show-habits)
  8204. " Habit" "")
  8205. (cond
  8206. ((consp org-agenda-show-log) " LogAll")
  8207. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8208. (org-agenda-show-log " Log")
  8209. (t ""))
  8210. (if (org-agenda-filter-any) " " "")
  8211. (if (or org-agenda-category-filter
  8212. (get 'org-agenda-category-filter :preset-filter))
  8213. '(:eval (propertize
  8214. (concat "["
  8215. (mapconcat
  8216. #'identity
  8217. (append
  8218. (get 'org-agenda-category-filter :preset-filter)
  8219. org-agenda-category-filter)
  8220. "")
  8221. "]")
  8222. 'face 'org-agenda-filter-category
  8223. 'help-echo "Category used in filtering"))
  8224. "")
  8225. (if (or org-agenda-tag-filter
  8226. (get 'org-agenda-tag-filter :preset-filter))
  8227. '(:eval (propertize
  8228. (concat (mapconcat
  8229. #'identity
  8230. (append
  8231. (get 'org-agenda-tag-filter :preset-filter)
  8232. org-agenda-tag-filter)
  8233. ""))
  8234. 'face 'org-agenda-filter-tags
  8235. 'help-echo "Tags used in filtering"))
  8236. "")
  8237. (if (or org-agenda-effort-filter
  8238. (get 'org-agenda-effort-filter :preset-filter))
  8239. '(:eval (propertize
  8240. (concat (mapconcat
  8241. #'identity
  8242. (append
  8243. (get 'org-agenda-effort-filter :preset-filter)
  8244. org-agenda-effort-filter)
  8245. ""))
  8246. 'face 'org-agenda-filter-effort
  8247. 'help-echo "Effort conditions used in filtering"))
  8248. "")
  8249. (if (or org-agenda-regexp-filter
  8250. (get 'org-agenda-regexp-filter :preset-filter))
  8251. '(:eval (propertize
  8252. (concat (mapconcat
  8253. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8254. (append
  8255. (get 'org-agenda-regexp-filter :preset-filter)
  8256. org-agenda-regexp-filter)
  8257. ""))
  8258. 'face 'org-agenda-filter-regexp
  8259. 'help-echo "Regexp used in filtering"))
  8260. "")
  8261. (if org-agenda-archives-mode
  8262. (if (eq org-agenda-archives-mode t)
  8263. " Archives"
  8264. (format " :%s:" org-archive-tag))
  8265. "")
  8266. (if org-agenda-clockreport-mode " Clock" "")))
  8267. (force-mode-line-update))
  8268. (defun org-agenda-update-agenda-type ()
  8269. "Update the agenda type after each command."
  8270. (setq org-agenda-type
  8271. (or (get-text-property (point) 'org-agenda-type)
  8272. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8273. (defun org-agenda-next-line ()
  8274. "Move cursor to the next line, and show if follow mode is active."
  8275. (interactive)
  8276. (call-interactively 'next-line)
  8277. (org-agenda-do-context-action))
  8278. (defun org-agenda-previous-line ()
  8279. "Move cursor to the previous line, and show if follow-mode is active."
  8280. (interactive)
  8281. (call-interactively 'previous-line)
  8282. (org-agenda-do-context-action))
  8283. (defun org-agenda-next-item (n)
  8284. "Move cursor to next agenda item."
  8285. (interactive "p")
  8286. (let ((col (current-column)))
  8287. (dotimes (_ n)
  8288. (when (next-single-property-change (line-end-position) 'org-marker)
  8289. (move-end-of-line 1)
  8290. (goto-char (next-single-property-change (point) 'org-marker))))
  8291. (org-move-to-column col))
  8292. (org-agenda-do-context-action))
  8293. (defun org-agenda-previous-item (n)
  8294. "Move cursor to next agenda item."
  8295. (interactive "p")
  8296. (dotimes (_ n)
  8297. (let ((col (current-column))
  8298. (goto (save-excursion
  8299. (move-end-of-line 0)
  8300. (previous-single-property-change (point) 'org-marker))))
  8301. (when goto (goto-char goto))
  8302. (org-move-to-column col)))
  8303. (org-agenda-do-context-action))
  8304. (defun org-agenda-do-context-action ()
  8305. "Show outline path and, maybe, follow mode window."
  8306. (let ((m (org-get-at-bol 'org-marker)))
  8307. (when (and (markerp m) (marker-buffer m))
  8308. (and org-agenda-follow-mode
  8309. (if org-agenda-follow-indirect
  8310. (org-agenda-tree-to-indirect-buffer nil)
  8311. (org-agenda-show)))
  8312. (and org-agenda-show-outline-path
  8313. (org-with-point-at m (org-display-outline-path t))))))
  8314. (defun org-agenda-show-tags ()
  8315. "Show the tags applicable to the current item."
  8316. (interactive)
  8317. (let* ((tags (org-get-at-bol 'tags)))
  8318. (if tags
  8319. (message "Tags are :%s:"
  8320. (org-no-properties (mapconcat #'identity tags ":")))
  8321. (message "No tags associated with this line"))))
  8322. (defun org-agenda-goto (&optional highlight)
  8323. "Go to the entry at point in the corresponding Org file."
  8324. (interactive)
  8325. (let* ((marker (or (org-get-at-bol 'org-marker)
  8326. (org-agenda-error)))
  8327. (buffer (marker-buffer marker))
  8328. (pos (marker-position marker)))
  8329. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8330. (switch-to-buffer-other-window buffer)
  8331. (widen)
  8332. (push-mark)
  8333. (goto-char pos)
  8334. (when (derived-mode-p 'org-mode)
  8335. (org-show-context 'agenda)
  8336. (recenter (/ (window-height) 2))
  8337. (org-back-to-heading t)
  8338. (let ((case-fold-search nil))
  8339. (when (re-search-forward org-complex-heading-regexp nil t)
  8340. (goto-char (match-beginning 4)))))
  8341. (run-hooks 'org-agenda-after-show-hook)
  8342. (and highlight (org-highlight (line-beginning-position)
  8343. (line-end-position)))))
  8344. (defvar org-agenda-after-show-hook nil
  8345. "Normal hook run after an item has been shown from the agenda.
  8346. Point is in the buffer where the item originated.")
  8347. ;; Defined later in org-agenda.el
  8348. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8349. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8350. "Between region BEG and END, call agenda command CMD.
  8351. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8352. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8353. deletes the agenda entry and don't move to the next entry."
  8354. (save-excursion
  8355. (goto-char beg)
  8356. (let ((mend (move-marker (make-marker) end))
  8357. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8358. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8359. org-agenda-loop-over-headlines-in-active-region))
  8360. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8361. (org-get-at-bol 'level))))
  8362. (while (< (point) mend)
  8363. (let ((ov (make-overlay (point) (line-end-position))))
  8364. (if (not (or all
  8365. (and match (looking-at-p match))
  8366. (eq level (org-get-at-bol 'level))))
  8367. (org-agenda-next-item 1)
  8368. (overlay-put ov 'face 'region)
  8369. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8370. (when (not delete) (org-agenda-next-item 1))
  8371. (delete-overlay ov)))))))
  8372. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8373. ;; kill,set-property,set-effort] commands may loop over agenda
  8374. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8375. ;; use their own mechanisms on active regions.
  8376. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8377. "Maybe loop over agenda entries and perform CMD.
  8378. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8379. (declare (debug t))
  8380. `(if (and (called-interactively-p 'any)
  8381. org-agenda-loop-over-headlines-in-active-region
  8382. (org-region-active-p))
  8383. (org-agenda-do-in-region
  8384. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8385. ,@body))
  8386. (defun org-agenda-kill ()
  8387. "Kill the entry or subtree belonging to the current agenda entry."
  8388. (interactive)
  8389. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8390. (org-agenda-maybe-loop
  8391. #'org-agenda-kill nil nil t
  8392. (let* ((bufname-orig (buffer-name))
  8393. (marker (or (org-get-at-bol 'org-marker)
  8394. (org-agenda-error)))
  8395. (buffer (marker-buffer marker))
  8396. (pos (marker-position marker))
  8397. (type (org-get-at-bol 'type))
  8398. dbeg dend (n 0))
  8399. (org-with-remote-undo buffer
  8400. (with-current-buffer buffer
  8401. (save-excursion
  8402. (goto-char pos)
  8403. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8404. (setq dbeg (progn (org-back-to-heading t) (point))
  8405. dend (org-end-of-subtree t t))
  8406. (setq dbeg (line-beginning-position)
  8407. dend (min (point-max) (1+ (line-end-position)))))
  8408. (goto-char dbeg)
  8409. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8410. (when (or (eq t org-agenda-confirm-kill)
  8411. (and (numberp org-agenda-confirm-kill)
  8412. (> n org-agenda-confirm-kill)))
  8413. (let ((win-conf (current-window-configuration)))
  8414. (unwind-protect
  8415. (and
  8416. (prog2
  8417. (org-agenda-tree-to-indirect-buffer nil)
  8418. (not (y-or-n-p
  8419. (format "Delete entry with %d lines in buffer \"%s\"? "
  8420. n (buffer-name buffer))))
  8421. (kill-buffer org-last-indirect-buffer))
  8422. (error "Abort"))
  8423. (set-window-configuration win-conf))))
  8424. (let ((org-agenda-buffer-name bufname-orig))
  8425. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8426. (with-current-buffer buffer (delete-region dbeg dend))
  8427. (message "Agenda item and source killed")))))
  8428. (defvar org-archive-default-command) ; defined in org-archive.el
  8429. (defun org-agenda-archive-default ()
  8430. "Archive the entry or subtree belonging to the current agenda entry."
  8431. (interactive)
  8432. (require 'org-archive)
  8433. (funcall-interactively
  8434. #'org-agenda-archive-with org-archive-default-command))
  8435. (defun org-agenda-archive-default-with-confirmation ()
  8436. "Archive the entry or subtree belonging to the current agenda entry."
  8437. (interactive)
  8438. (require 'org-archive)
  8439. (funcall-interactively
  8440. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8441. (defun org-agenda-archive ()
  8442. "Archive the entry or subtree belonging to the current agenda entry."
  8443. (interactive)
  8444. (funcall-interactively
  8445. #'org-agenda-archive-with 'org-archive-subtree))
  8446. (defun org-agenda-archive-to-archive-sibling ()
  8447. "Move the entry to the archive sibling."
  8448. (interactive)
  8449. (funcall-interactively
  8450. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8451. (defvar org-archive-from-agenda)
  8452. (defun org-agenda-archive-with (cmd &optional confirm)
  8453. "Move the entry to the archive sibling."
  8454. (interactive)
  8455. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8456. (org-agenda-maybe-loop
  8457. #'org-agenda-archive-with cmd nil t
  8458. (let* ((bufname-orig (buffer-name))
  8459. (marker (or (org-get-at-bol 'org-marker)
  8460. (org-agenda-error)))
  8461. (buffer (marker-buffer marker))
  8462. (pos (marker-position marker)))
  8463. (org-with-remote-undo buffer
  8464. (with-current-buffer buffer
  8465. (if (derived-mode-p 'org-mode)
  8466. (if (and confirm
  8467. (not (y-or-n-p "Archive this subtree or entry? ")))
  8468. (error "Abort")
  8469. (save-window-excursion
  8470. (goto-char pos)
  8471. (let ((org-agenda-buffer-name bufname-orig))
  8472. (org-remove-subtree-entries-from-agenda))
  8473. (org-back-to-heading t)
  8474. (let ((org-archive-from-agenda t))
  8475. (funcall cmd))))
  8476. (error "Archiving works only in Org files")))))))
  8477. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8478. "Remove all lines in the agenda that correspond to a given subtree.
  8479. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8480. If this information is not given, the function uses the tree at point."
  8481. (let ((buf (or buf (current-buffer))) m p)
  8482. (save-excursion
  8483. (unless (and beg end)
  8484. (org-back-to-heading t)
  8485. (setq beg (point))
  8486. (org-end-of-subtree t)
  8487. (setq end (point)))
  8488. (set-buffer (get-buffer org-agenda-buffer-name))
  8489. (save-excursion
  8490. (goto-char (point-max))
  8491. (beginning-of-line 1)
  8492. (while (not (bobp))
  8493. (when (and (setq m (org-get-at-bol 'org-marker))
  8494. (equal buf (marker-buffer m))
  8495. (setq p (marker-position m))
  8496. (>= p beg)
  8497. (< p end))
  8498. (let ((inhibit-read-only t))
  8499. (delete-region (line-beginning-position)
  8500. (1+ (line-end-position)))))
  8501. (beginning-of-line 0))))))
  8502. (defun org-agenda-refile (&optional goto rfloc no-update)
  8503. "Refile the item at point.
  8504. When called with `\\[universal-argument] \\[universal-argument]', \
  8505. go to the location of the last
  8506. refiled item.
  8507. When called with `\\[universal-argument] \\[universal-argument] \
  8508. \\[universal-argument]' prefix or when GOTO is 0, clear
  8509. the refile cache.
  8510. RFLOC can be a refile location obtained in a different way.
  8511. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8512. (interactive "P")
  8513. (cond
  8514. ((member goto '(0 (64)))
  8515. (org-refile-cache-clear))
  8516. ((equal goto '(16))
  8517. (org-refile-goto-last-stored))
  8518. (t
  8519. (let* ((buffer-orig (buffer-name))
  8520. (marker (or (org-get-at-bol 'org-hd-marker)
  8521. (org-agenda-error)))
  8522. (buffer (marker-buffer marker))
  8523. ;; (pos (marker-position marker))
  8524. (rfloc (or rfloc
  8525. (org-refile-get-location
  8526. (if goto "Goto" "Refile to") buffer
  8527. org-refile-allow-creating-parent-nodes))))
  8528. (with-current-buffer buffer
  8529. (org-with-wide-buffer
  8530. (goto-char marker)
  8531. (let ((org-agenda-buffer-name buffer-orig))
  8532. (org-remove-subtree-entries-from-agenda))
  8533. (org-refile goto buffer rfloc))))
  8534. (unless no-update (org-agenda-redo)))))
  8535. (defun org-agenda-open-link (&optional arg)
  8536. "Open the link(s) in the current entry, if any.
  8537. This looks for a link in the displayed line in the agenda.
  8538. It also looks at the text of the entry itself."
  8539. (interactive "P")
  8540. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8541. (org-get-at-bol 'org-marker)))
  8542. (buffer (and marker (marker-buffer marker)))
  8543. (prefix (buffer-substring (line-beginning-position)
  8544. (line-end-position)))
  8545. (lkall (and buffer (org-offer-links-in-entry
  8546. buffer marker arg prefix)))
  8547. (lk0 (car lkall))
  8548. (lk (if (stringp lk0) (list lk0) lk0))
  8549. (lkend (cdr lkall))
  8550. trg)
  8551. (cond
  8552. ((and buffer lk)
  8553. (mapcar (lambda(l)
  8554. (with-current-buffer buffer
  8555. (setq trg (and (string-match org-link-bracket-re l)
  8556. (match-string 1 l)))
  8557. (if (or (not trg) (string-match org-link-any-re trg))
  8558. ;; Don't use `org-with-wide-buffer' here as
  8559. ;; opening the link may result in moving the point
  8560. (save-restriction
  8561. (widen)
  8562. (goto-char marker)
  8563. (when (search-forward l nil lkend)
  8564. (goto-char (match-beginning 0))
  8565. (org-open-at-point)))
  8566. ;; This is an internal link, widen the buffer
  8567. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8568. (switch-to-buffer-other-window buffer)
  8569. (widen)
  8570. (goto-char marker)
  8571. (when (search-forward l nil lkend)
  8572. (goto-char (match-beginning 0))
  8573. (org-open-at-point)))))
  8574. lk))
  8575. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  8576. (save-excursion
  8577. (beginning-of-line 1)
  8578. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  8579. (org-link-open-from-string (match-string 1)))
  8580. (t (message "No link to open here")))))
  8581. (defun org-agenda-copy-local-variable (var)
  8582. "Get a variable from a referenced buffer and install it here."
  8583. (let ((m (org-get-at-bol 'org-marker)))
  8584. (when (and m (buffer-live-p (marker-buffer m)))
  8585. (set (make-local-variable var)
  8586. (with-current-buffer (marker-buffer m)
  8587. (symbol-value var))))))
  8588. (defun org-agenda-switch-to (&optional delete-other-windows)
  8589. "Go to the Org mode file which contains the item at point.
  8590. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8591. displayed Org file fills the frame."
  8592. (interactive)
  8593. (if (and org-return-follows-link
  8594. (not (org-get-at-bol 'org-marker))
  8595. (org-in-regexp org-link-bracket-re))
  8596. (org-link-open-from-string (match-string 0))
  8597. (let* ((marker (or (org-get-at-bol 'org-marker)
  8598. (org-agenda-error)))
  8599. (buffer (marker-buffer marker))
  8600. (pos (marker-position marker)))
  8601. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8602. (pop-to-buffer-same-window buffer)
  8603. (when delete-other-windows (delete-other-windows))
  8604. (widen)
  8605. (goto-char pos)
  8606. (when (derived-mode-p 'org-mode)
  8607. (org-show-context 'agenda)
  8608. (run-hooks 'org-agenda-after-show-hook)))))
  8609. (defun org-agenda-goto-mouse (ev)
  8610. "Go to the Org file which contains the item at the mouse click."
  8611. (interactive "e")
  8612. (mouse-set-point ev)
  8613. (org-agenda-goto))
  8614. (defun org-agenda-show (&optional full-entry)
  8615. "Display the Org file which contains the item at point.
  8616. With prefix argument FULL-ENTRY, make the entire entry visible
  8617. if it was hidden in the outline."
  8618. (interactive "P")
  8619. (let ((win (selected-window)))
  8620. (org-agenda-goto t)
  8621. (when full-entry (org-show-entry))
  8622. (select-window win)))
  8623. (defvar org-agenda-show-window nil)
  8624. (defun org-agenda-show-and-scroll-up (&optional arg)
  8625. "Display the Org file which contains the item at point.
  8626. When called repeatedly, scroll the window that is displaying the buffer.
  8627. With a `\\[universal-argument]' prefix argument, display the item, but \
  8628. fold drawers."
  8629. (interactive "P")
  8630. (let ((win (selected-window)))
  8631. (if (and (window-live-p org-agenda-show-window)
  8632. (eq this-command last-command))
  8633. (progn
  8634. (select-window org-agenda-show-window)
  8635. (ignore-errors (scroll-up)))
  8636. (org-agenda-goto t)
  8637. (org-show-entry)
  8638. (if arg (org-cycle-hide-drawers 'children)
  8639. (org-with-wide-buffer
  8640. (narrow-to-region (org-entry-beginning-position)
  8641. (org-entry-end-position))
  8642. (org-show-all '(drawers))))
  8643. (setq org-agenda-show-window (selected-window)))
  8644. (select-window win)))
  8645. (defun org-agenda-show-scroll-down ()
  8646. "Scroll down the window showing the agenda."
  8647. (interactive)
  8648. (let ((win (selected-window)))
  8649. (when (window-live-p org-agenda-show-window)
  8650. (select-window org-agenda-show-window)
  8651. (ignore-errors (scroll-down))
  8652. (select-window win))))
  8653. (defun org-agenda-show-1 (&optional more)
  8654. "Display the Org file which contains the item at point.
  8655. The prefix arg selects the amount of information to display:
  8656. 0 hide the subtree
  8657. 1 just show the entry according to defaults.
  8658. 2 show the children view
  8659. 3 show the subtree view
  8660. 4 show the entire subtree and any drawers
  8661. With prefix argument FULL-ENTRY, make the entire entry visible
  8662. if it was hidden in the outline."
  8663. (interactive "p")
  8664. (let ((win (selected-window)))
  8665. (org-agenda-goto t)
  8666. (org-back-to-heading)
  8667. (set-window-start (selected-window) (line-beginning-position))
  8668. (cond
  8669. ((= more 0)
  8670. (org-flag-subtree t)
  8671. (save-excursion
  8672. (org-back-to-heading)
  8673. (run-hook-with-args 'org-cycle-hook 'folded))
  8674. (message "Remote: FOLDED"))
  8675. ((and (called-interactively-p 'any) (= more 1))
  8676. (message "Remote: show with default settings"))
  8677. ((= more 2)
  8678. (outline-show-entry)
  8679. (org-show-children)
  8680. (save-excursion
  8681. (org-back-to-heading)
  8682. (run-hook-with-args 'org-cycle-hook 'children))
  8683. (message "Remote: CHILDREN"))
  8684. ((= more 3)
  8685. (outline-show-subtree)
  8686. (save-excursion
  8687. (org-back-to-heading)
  8688. (run-hook-with-args 'org-cycle-hook 'subtree))
  8689. (message "Remote: SUBTREE"))
  8690. ((> more 3)
  8691. (outline-show-subtree)
  8692. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8693. (select-window win)))
  8694. (defvar org-agenda-cycle-counter nil)
  8695. (defun org-agenda-cycle-show (&optional n)
  8696. "Show the current entry in another window, with default settings.
  8697. Default settings are taken from `org-show-context-detail'. When
  8698. use repeatedly in immediate succession, the remote entry will
  8699. cycle through visibility
  8700. children -> subtree -> folded
  8701. When called with a numeric prefix arg, that arg will be passed through to
  8702. `org-agenda-show-1'. For the interpretation of that argument, see the
  8703. docstring of `org-agenda-show-1'."
  8704. (interactive "P")
  8705. (if (integerp n)
  8706. (setq org-agenda-cycle-counter n)
  8707. (if (not (eq last-command this-command))
  8708. (setq org-agenda-cycle-counter 1)
  8709. (if (equal org-agenda-cycle-counter 0)
  8710. (setq org-agenda-cycle-counter 2)
  8711. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8712. (when (> org-agenda-cycle-counter 3)
  8713. (setq org-agenda-cycle-counter 0)))))
  8714. (org-agenda-show-1 org-agenda-cycle-counter))
  8715. (defun org-agenda-recenter (arg)
  8716. "Display the Org file which contains the item at point and recenter."
  8717. (interactive "P")
  8718. (let ((win (selected-window)))
  8719. (org-agenda-goto t)
  8720. (recenter arg)
  8721. (select-window win)))
  8722. (defun org-agenda-show-mouse (ev)
  8723. "Display the Org file which contains the item at the mouse click."
  8724. (interactive "e")
  8725. (mouse-set-point ev)
  8726. (org-agenda-show))
  8727. (defun org-agenda-check-no-diary ()
  8728. "Check if the entry is a diary link and abort if yes."
  8729. (when (org-get-at-bol 'org-agenda-diary-link)
  8730. (org-agenda-error)))
  8731. (defun org-agenda-error ()
  8732. "Throw an error when a command is not allowed in the agenda."
  8733. (user-error "Command not allowed in this line"))
  8734. (defun org-agenda-tree-to-indirect-buffer (arg)
  8735. "Show the subtree corresponding to the current entry in an indirect buffer.
  8736. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8737. With a numerical prefix ARG, go up to this level and then take that tree.
  8738. With a negative numeric ARG, go up by this number of levels.
  8739. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8740. i.e. don't use
  8741. the dedicated frame."
  8742. (interactive "P")
  8743. (if current-prefix-arg
  8744. (org-agenda-do-tree-to-indirect-buffer arg)
  8745. (let ((agenda-buffer (buffer-name))
  8746. (agenda-window (selected-window))
  8747. (indirect-window
  8748. (and org-last-indirect-buffer
  8749. (get-buffer-window org-last-indirect-buffer))))
  8750. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8751. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8752. (eq org-indirect-buffer-display 'dedicated-frame))
  8753. (unwind-protect
  8754. (unless (and indirect-window (window-live-p indirect-window))
  8755. (setq indirect-window (split-window agenda-window)))
  8756. (and indirect-window (select-window indirect-window))
  8757. (switch-to-buffer org-last-indirect-buffer :norecord)
  8758. (fit-window-to-buffer indirect-window)))
  8759. (select-window (get-buffer-window agenda-buffer))
  8760. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8761. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8762. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8763. (org-agenda-check-no-diary)
  8764. (let* ((marker (or (org-get-at-bol 'org-marker)
  8765. (org-agenda-error)))
  8766. (buffer (marker-buffer marker))
  8767. (pos (marker-position marker)))
  8768. (with-current-buffer buffer
  8769. (save-excursion
  8770. (goto-char pos)
  8771. (org-tree-to-indirect-buffer arg)))))
  8772. (defvar org-last-heading-marker (make-marker)
  8773. "Marker pointing to the headline that last changed its TODO state
  8774. by a remote command from the agenda.")
  8775. (defun org-agenda-todo-nextset ()
  8776. "Switch TODO entry to next sequence."
  8777. (interactive)
  8778. (org-agenda-todo 'nextset))
  8779. (defun org-agenda-todo-previousset ()
  8780. "Switch TODO entry to previous sequence."
  8781. (interactive)
  8782. (org-agenda-todo 'previousset))
  8783. (defvar org-agenda-headline-snapshot-before-repeat)
  8784. (defun org-agenda-todo (&optional arg)
  8785. "Cycle TODO state of line at point, also in Org file.
  8786. This changes the line at point, all other lines in the agenda referring to
  8787. the same tree node, and the headline of the tree node in the Org file."
  8788. (interactive "P")
  8789. (org-agenda-check-no-diary)
  8790. (org-agenda-maybe-loop
  8791. #'org-agenda-todo arg nil nil
  8792. (let* ((col (current-column))
  8793. (marker (or (org-get-at-bol 'org-marker)
  8794. (org-agenda-error)))
  8795. (buffer (marker-buffer marker))
  8796. (pos (marker-position marker))
  8797. (hdmarker (org-get-at-bol 'org-hd-marker))
  8798. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8799. (inhibit-read-only t)
  8800. org-loop-over-headlines-in-active-region
  8801. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8802. (org-with-remote-undo buffer
  8803. (with-current-buffer buffer
  8804. (widen)
  8805. (goto-char pos)
  8806. (org-show-context 'agenda)
  8807. (let ((current-prefix-arg arg))
  8808. (call-interactively 'org-todo)
  8809. ;; Make sure that log is recorded in current undo.
  8810. (when (and org-log-setup
  8811. (not (eq org-log-note-how 'note)))
  8812. (org-add-log-note)))
  8813. (and (bolp) (forward-char 1))
  8814. (setq newhead (org-get-heading))
  8815. (when (and org-agenda-headline-snapshot-before-repeat
  8816. (not (equal org-agenda-headline-snapshot-before-repeat
  8817. newhead))
  8818. todayp)
  8819. (setq newhead org-agenda-headline-snapshot-before-repeat
  8820. just-one t))
  8821. (save-excursion
  8822. (org-back-to-heading)
  8823. (move-marker org-last-heading-marker (point))))
  8824. (beginning-of-line 1)
  8825. (save-window-excursion
  8826. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8827. (when (bound-and-true-p org-clock-out-when-done)
  8828. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8829. newhead)
  8830. (org-agenda-unmark-clocking-task))
  8831. (org-move-to-column col)
  8832. (org-agenda-mark-clocking-task)))))
  8833. (defun org-agenda-add-note (&optional _arg)
  8834. "Add a time-stamped note to the entry at point."
  8835. (interactive) ;; "P"
  8836. (org-agenda-check-no-diary)
  8837. (let* ((marker (or (org-get-at-bol 'org-marker)
  8838. (org-agenda-error)))
  8839. (buffer (marker-buffer marker))
  8840. (pos (marker-position marker))
  8841. (_hdmarker (org-get-at-bol 'org-hd-marker))
  8842. (inhibit-read-only t))
  8843. (with-current-buffer buffer
  8844. (widen)
  8845. (goto-char pos)
  8846. (org-show-context 'agenda)
  8847. (org-add-note))))
  8848. (defun org-agenda-change-all-lines (newhead hdmarker
  8849. &optional fixface just-this)
  8850. "Change all lines in the agenda buffer which match HDMARKER.
  8851. The new content of the line will be NEWHEAD (as modified by
  8852. `org-agenda-format-item'). HDMARKER is checked with
  8853. `equal' against all `org-hd-marker' text properties in the file.
  8854. If FIXFACE is non-nil, the face of each item is modified according to
  8855. the new TODO state.
  8856. If JUST-THIS is non-nil, change just the current line, not all.
  8857. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  8858. (let* ((inhibit-read-only t)
  8859. (line (org-current-line))
  8860. (org-agenda-buffer (current-buffer))
  8861. (thetags (with-current-buffer (marker-buffer hdmarker)
  8862. (org-get-tags hdmarker)))
  8863. props m undone-face done-face finish new dotime level cat tags) ;; pl
  8864. (save-excursion
  8865. (goto-char (point-max))
  8866. (beginning-of-line 1)
  8867. (while (not finish)
  8868. (setq finish (bobp))
  8869. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8870. (or (not just-this) (= (org-current-line) line))
  8871. (equal m hdmarker))
  8872. (setq props (text-properties-at (point))
  8873. dotime (org-get-at-bol 'dotime)
  8874. cat (org-agenda-get-category)
  8875. level (org-get-at-bol 'level)
  8876. tags thetags
  8877. new
  8878. (let ((org-prefix-format-compiled
  8879. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8880. org-prefix-format-compiled))
  8881. (extra (org-get-at-bol 'extra)))
  8882. (with-current-buffer (marker-buffer hdmarker)
  8883. (org-with-wide-buffer
  8884. (org-agenda-format-item extra newhead level cat tags dotime))))
  8885. ;; pl (text-property-any (line-beginning-position)
  8886. ;; (line-end-position) 'org-heading t)
  8887. undone-face (org-get-at-bol 'undone-face)
  8888. done-face (org-get-at-bol 'done-face))
  8889. (beginning-of-line 1)
  8890. (cond
  8891. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8892. ((looking-at ".*")
  8893. ;; When replacing the whole line, preserve bulk mark
  8894. ;; overlay, if any.
  8895. (let ((mark (catch :overlay
  8896. (dolist (o (overlays-in (point) (+ 2 (point))))
  8897. (when (eq (overlay-get o 'type)
  8898. 'org-marked-entry-overlay)
  8899. (throw :overlay o))))))
  8900. (replace-match new t t)
  8901. (beginning-of-line)
  8902. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8903. (add-text-properties (line-beginning-position)
  8904. (line-end-position) props)
  8905. (when fixface
  8906. (add-text-properties
  8907. (line-beginning-position) (line-end-position)
  8908. (list 'face
  8909. (if org-last-todo-state-is-todo
  8910. undone-face done-face))))
  8911. (org-agenda-highlight-todo 'line)
  8912. (beginning-of-line 1))
  8913. (t (error "Line update did not work")))
  8914. (save-restriction
  8915. (narrow-to-region (line-beginning-position) (line-end-position))
  8916. (org-agenda-finalize)))
  8917. (beginning-of-line 0)))))
  8918. (defun org-agenda-align-tags (&optional line)
  8919. "Align all tags in agenda items to `org-agenda-tags-column'.
  8920. When optional argument LINE is non-nil, align tags only on the
  8921. current line."
  8922. (let ((inhibit-read-only t)
  8923. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8924. (- (window-text-width))
  8925. org-agenda-tags-column))
  8926. (end (and line (line-end-position)))
  8927. l c)
  8928. (save-excursion
  8929. (goto-char (if line (line-beginning-position) (point-min)))
  8930. (while (re-search-forward org-tag-group-re end t)
  8931. (add-text-properties
  8932. (match-beginning 1) (match-end 1)
  8933. (list 'face (delq nil (let ((prop (get-text-property
  8934. (match-beginning 1) 'face)))
  8935. (or (listp prop) (setq prop (list prop)))
  8936. (if (memq 'org-tag prop)
  8937. prop
  8938. (cons 'org-tag prop))))))
  8939. (setq l (string-width (match-string 1))
  8940. c (if (< org-agenda-tags-column 0)
  8941. (- (abs org-agenda-tags-column) l)
  8942. org-agenda-tags-column))
  8943. (goto-char (match-beginning 1))
  8944. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  8945. (point))
  8946. (insert (org-add-props
  8947. (make-string (max 1 (- c (current-column))) ?\s)
  8948. (plist-put (copy-sequence (text-properties-at (point)))
  8949. 'face nil))))
  8950. (goto-char (point-min))
  8951. (org-font-lock-add-tag-faces (point-max)))))
  8952. (defun org-agenda-priority-up ()
  8953. "Increase the priority of line at point, also in Org file."
  8954. (interactive)
  8955. (org-agenda-priority 'up))
  8956. (defun org-agenda-priority-down ()
  8957. "Decrease the priority of line at point, also in Org file."
  8958. (interactive)
  8959. (org-agenda-priority 'down))
  8960. (defun org-agenda-priority (&optional force-direction)
  8961. "Set the priority of line at point, also in Org file.
  8962. This changes the line at point, all other lines in the agenda
  8963. referring to the same tree node, and the headline of the tree
  8964. node in the Org file.
  8965. Called with one universal prefix arg, show the priority instead
  8966. of setting it.
  8967. When called programmatically, FORCE-DIRECTION can be `set', `up',
  8968. `down', or a character."
  8969. (interactive "P")
  8970. (unless org-priority-enable-commands
  8971. (user-error "Priority commands are disabled"))
  8972. (org-agenda-check-no-diary)
  8973. (let* ((col (current-column))
  8974. (hdmarker (org-get-at-bol 'org-hd-marker))
  8975. (buffer (marker-buffer hdmarker))
  8976. (pos (marker-position hdmarker))
  8977. (inhibit-read-only t)
  8978. newhead)
  8979. (org-with-remote-undo buffer
  8980. (with-current-buffer buffer
  8981. (widen)
  8982. (goto-char pos)
  8983. (org-show-context 'agenda)
  8984. (org-priority force-direction)
  8985. (end-of-line 1)
  8986. (setq newhead (org-get-heading)))
  8987. (org-agenda-change-all-lines newhead hdmarker)
  8988. (org-move-to-column col))))
  8989. ;; FIXME: should fix the tags property of the agenda line.
  8990. (defun org-agenda-set-tags (&optional tag onoff)
  8991. "Set tags for the current headline."
  8992. (interactive)
  8993. (org-agenda-check-no-diary)
  8994. (if (and (org-region-active-p) (called-interactively-p 'any))
  8995. (call-interactively 'org-change-tag-in-region)
  8996. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8997. (org-agenda-error)))
  8998. (buffer (marker-buffer hdmarker))
  8999. (pos (marker-position hdmarker))
  9000. (inhibit-read-only t)
  9001. newhead)
  9002. (org-with-remote-undo buffer
  9003. (with-current-buffer buffer
  9004. (widen)
  9005. (goto-char pos)
  9006. (org-show-context 'agenda)
  9007. (if tag
  9008. (org-toggle-tag tag onoff)
  9009. (call-interactively #'org-set-tags-command))
  9010. (end-of-line 1)
  9011. (setq newhead (org-get-heading)))
  9012. (org-agenda-change-all-lines newhead hdmarker)
  9013. (beginning-of-line 1)))))
  9014. (defun org-agenda-set-property ()
  9015. "Set a property for the current headline."
  9016. (interactive)
  9017. (org-agenda-check-no-diary)
  9018. (org-agenda-maybe-loop
  9019. #'org-agenda-set-property nil nil nil
  9020. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9021. (org-agenda-error)))
  9022. (buffer (marker-buffer hdmarker))
  9023. (pos (marker-position hdmarker))
  9024. (inhibit-read-only t)
  9025. ) ;; newhead
  9026. (org-with-remote-undo buffer
  9027. (with-current-buffer buffer
  9028. (widen)
  9029. (goto-char pos)
  9030. (org-show-context 'agenda)
  9031. (call-interactively 'org-set-property))))))
  9032. (defun org-agenda-set-effort ()
  9033. "Set the effort property for the current headline."
  9034. (interactive)
  9035. (org-agenda-check-no-diary)
  9036. (org-agenda-maybe-loop
  9037. #'org-agenda-set-effort nil nil nil
  9038. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9039. (org-agenda-error)))
  9040. (buffer (marker-buffer hdmarker))
  9041. (pos (marker-position hdmarker))
  9042. (inhibit-read-only t)
  9043. newhead)
  9044. (org-with-remote-undo buffer
  9045. (with-current-buffer buffer
  9046. (widen)
  9047. (goto-char pos)
  9048. (org-show-context 'agenda)
  9049. (call-interactively 'org-set-effort)
  9050. (end-of-line 1)
  9051. (setq newhead (org-get-heading)))
  9052. (org-agenda-change-all-lines newhead hdmarker)))))
  9053. (defun org-agenda-toggle-archive-tag ()
  9054. "Toggle the archive tag for the current entry."
  9055. (interactive)
  9056. (org-agenda-check-no-diary)
  9057. (org-agenda-maybe-loop
  9058. #'org-agenda-toggle-archive-tag nil nil nil
  9059. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9060. (org-agenda-error)))
  9061. (buffer (marker-buffer hdmarker))
  9062. (pos (marker-position hdmarker))
  9063. (inhibit-read-only t)
  9064. newhead)
  9065. (org-with-remote-undo buffer
  9066. (with-current-buffer buffer
  9067. (widen)
  9068. (goto-char pos)
  9069. (org-show-context 'agenda)
  9070. (call-interactively 'org-toggle-archive-tag)
  9071. (end-of-line 1)
  9072. (setq newhead (org-get-heading)))
  9073. (org-agenda-change-all-lines newhead hdmarker)
  9074. (beginning-of-line 1)))))
  9075. (defun org-agenda-do-date-later (arg)
  9076. (interactive "P")
  9077. (cond
  9078. ((or (equal arg '(16))
  9079. (memq last-command
  9080. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9081. (setq this-command 'org-agenda-date-later-minutes)
  9082. (org-agenda-date-later-minutes 1))
  9083. ((or (equal arg '(4))
  9084. (memq last-command
  9085. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9086. (setq this-command 'org-agenda-date-later-hours)
  9087. (org-agenda-date-later-hours 1))
  9088. (t
  9089. (org-agenda-date-later (prefix-numeric-value arg)))))
  9090. (defun org-agenda-do-date-earlier (arg)
  9091. (interactive "P")
  9092. (cond
  9093. ((or (equal arg '(16))
  9094. (memq last-command
  9095. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9096. (setq this-command 'org-agenda-date-earlier-minutes)
  9097. (org-agenda-date-earlier-minutes 1))
  9098. ((or (equal arg '(4))
  9099. (memq last-command
  9100. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9101. (setq this-command 'org-agenda-date-earlier-hours)
  9102. (org-agenda-date-earlier-hours 1))
  9103. (t
  9104. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9105. (defun org-agenda-date-later (arg &optional what)
  9106. "Change the date of this item to ARG day(s) later."
  9107. (interactive "p")
  9108. (org-agenda-check-type t 'agenda)
  9109. (org-agenda-check-no-diary)
  9110. (let* ((marker (or (org-get-at-bol 'org-marker)
  9111. (org-agenda-error)))
  9112. (buffer (marker-buffer marker))
  9113. (pos (marker-position marker))
  9114. cdate today)
  9115. (org-with-remote-undo buffer
  9116. (with-current-buffer buffer
  9117. (widen)
  9118. (goto-char pos)
  9119. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9120. (when (and org-agenda-move-date-from-past-immediately-to-today
  9121. (equal arg 1)
  9122. (or (not what) (eq what 'day))
  9123. (not (save-match-data (org-at-date-range-p))))
  9124. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9125. cdate (calendar-absolute-from-gregorian
  9126. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9127. today (org-today))
  9128. (when (> today cdate)
  9129. ;; immediately shift to today
  9130. (setq arg (- today cdate))))
  9131. (org-timestamp-change arg (or what 'day))
  9132. (when (and (org-at-date-range-p)
  9133. (re-search-backward org-tr-regexp-both
  9134. (line-beginning-position)))
  9135. (let ((end org-last-changed-timestamp))
  9136. (org-timestamp-change arg (or what 'day))
  9137. (setq org-last-changed-timestamp
  9138. (concat org-last-changed-timestamp "--" end)))))
  9139. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9140. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9141. (defun org-agenda-date-earlier (arg &optional what)
  9142. "Change the date of this item to ARG day(s) earlier."
  9143. (interactive "p")
  9144. (org-agenda-date-later (- arg) what))
  9145. (defun org-agenda-date-later-minutes (arg)
  9146. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9147. (interactive "p")
  9148. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9149. (org-agenda-date-later arg 'minute))
  9150. (defun org-agenda-date-earlier-minutes (arg)
  9151. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9152. (interactive "p")
  9153. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9154. (org-agenda-date-earlier arg 'minute))
  9155. (defun org-agenda-date-later-hours (arg)
  9156. "Change the time of this item, in hour steps."
  9157. (interactive "p")
  9158. (org-agenda-date-later arg 'hour))
  9159. (defun org-agenda-date-earlier-hours (arg)
  9160. "Change the time of this item, in hour steps."
  9161. (interactive "p")
  9162. (org-agenda-date-earlier arg 'hour))
  9163. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9164. "Show new date stamp via text properties."
  9165. ;; We use text properties to make this undoable
  9166. (let ((inhibit-read-only t))
  9167. (setq stamp (concat prefix " => " stamp " "))
  9168. (save-excursion
  9169. (goto-char (point-max))
  9170. (while (not (bobp))
  9171. (when (equal marker (org-get-at-bol 'org-marker))
  9172. (remove-text-properties (line-beginning-position)
  9173. (line-end-position)
  9174. '(display nil))
  9175. (org-move-to-column
  9176. (- (if (fboundp 'window-font-width)
  9177. (/ (window-width nil t) (window-font-width))
  9178. ;; Fall back to pre-9.3.3 behavior on Emacs <25.
  9179. (window-width))
  9180. (length stamp))
  9181. t)
  9182. (add-text-properties
  9183. (1- (point)) (line-end-position)
  9184. (list 'display (org-add-props stamp nil
  9185. 'face '(secondary-selection default))))
  9186. (beginning-of-line 1))
  9187. (beginning-of-line 0)))))
  9188. (defun org-agenda-date-prompt (arg)
  9189. "Change the date of this item. Date is prompted for, with default today.
  9190. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9191. be used to request time specification in the time stamp."
  9192. (interactive "P")
  9193. (org-agenda-check-type t 'agenda)
  9194. (org-agenda-check-no-diary)
  9195. (org-agenda-maybe-loop
  9196. #'org-agenda-date-prompt arg t nil
  9197. (let* ((marker (or (org-get-at-bol 'org-marker)
  9198. (org-agenda-error)))
  9199. (buffer (marker-buffer marker))
  9200. (pos (marker-position marker)))
  9201. (org-with-remote-undo buffer
  9202. (with-current-buffer buffer
  9203. (widen)
  9204. (goto-char pos)
  9205. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9206. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9207. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9208. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9209. (defun org-agenda-schedule (arg &optional time)
  9210. "Schedule the item at point.
  9211. ARG is passed through to `org-schedule'."
  9212. (interactive "P")
  9213. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9214. (org-agenda-check-no-diary)
  9215. (org-agenda-maybe-loop
  9216. #'org-agenda-schedule arg t nil
  9217. (let* ((marker (or (org-get-at-bol 'org-marker)
  9218. (org-agenda-error)))
  9219. ;; (type (marker-insertion-type marker))
  9220. (buffer (marker-buffer marker))
  9221. (pos (marker-position marker))
  9222. ts)
  9223. (set-marker-insertion-type marker t)
  9224. (org-with-remote-undo buffer
  9225. (with-current-buffer buffer
  9226. (widen)
  9227. (goto-char pos)
  9228. (setq ts (org-schedule arg time)))
  9229. (org-agenda-show-new-time marker ts " S"))
  9230. (message "%s" ts))))
  9231. (defun org-agenda-deadline (arg &optional time)
  9232. "Schedule the item at point.
  9233. ARG is passed through to `org-deadline'."
  9234. (interactive "P")
  9235. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9236. (org-agenda-check-no-diary)
  9237. (org-agenda-maybe-loop
  9238. #'org-agenda-deadline arg t nil
  9239. (let* ((marker (or (org-get-at-bol 'org-marker)
  9240. (org-agenda-error)))
  9241. (buffer (marker-buffer marker))
  9242. (pos (marker-position marker))
  9243. ts)
  9244. (org-with-remote-undo buffer
  9245. (with-current-buffer buffer
  9246. (widen)
  9247. (goto-char pos)
  9248. (setq ts (org-deadline arg time)))
  9249. (org-agenda-show-new-time marker ts " D"))
  9250. (message "%s" ts))))
  9251. (defun org-agenda-clock-in (&optional arg)
  9252. "Start the clock on the currently selected item."
  9253. (interactive "P")
  9254. (org-agenda-check-no-diary)
  9255. (if (equal arg '(4))
  9256. (org-clock-in arg)
  9257. (let* ((marker (or (org-get-at-bol 'org-marker)
  9258. (org-agenda-error)))
  9259. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9260. (pos (marker-position marker))
  9261. (col (current-column))
  9262. newhead)
  9263. (org-with-remote-undo (marker-buffer marker)
  9264. (with-current-buffer (marker-buffer marker)
  9265. (widen)
  9266. (goto-char pos)
  9267. (org-show-context 'agenda)
  9268. (org-clock-in arg)
  9269. (setq newhead (org-get-heading)))
  9270. (org-agenda-change-all-lines newhead hdmarker))
  9271. (org-move-to-column col))))
  9272. (defun org-agenda-clock-out ()
  9273. "Stop the currently running clock."
  9274. (interactive)
  9275. (unless (marker-buffer org-clock-marker)
  9276. (user-error "No running clock"))
  9277. (let ((marker (make-marker)) (col (current-column)) newhead)
  9278. (org-with-remote-undo (marker-buffer org-clock-marker)
  9279. (with-current-buffer (marker-buffer org-clock-marker)
  9280. (org-with-wide-buffer
  9281. (goto-char org-clock-marker)
  9282. (org-back-to-heading t)
  9283. (move-marker marker (point))
  9284. (org-clock-out)
  9285. (setq newhead (org-get-heading)))))
  9286. (org-agenda-change-all-lines newhead marker)
  9287. (move-marker marker nil)
  9288. (org-move-to-column col)
  9289. (org-agenda-unmark-clocking-task)))
  9290. (defun org-agenda-clock-cancel (&optional _arg)
  9291. "Cancel the currently running clock."
  9292. (interactive) ;; "P"
  9293. (unless (marker-buffer org-clock-marker)
  9294. (user-error "No running clock"))
  9295. (org-with-remote-undo (marker-buffer org-clock-marker)
  9296. (org-clock-cancel)))
  9297. (defun org-agenda-clock-goto ()
  9298. "Jump to the currently clocked in task within the agenda.
  9299. If the currently clocked in task is not listed in the agenda
  9300. buffer, display it in another window."
  9301. (interactive)
  9302. (let (pos)
  9303. (mapc (lambda (o)
  9304. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9305. (setq pos (overlay-start o))))
  9306. (overlays-in (point-min) (point-max)))
  9307. (cond (pos (goto-char pos))
  9308. ;; If the currently clocked entry is not in the agenda
  9309. ;; buffer, we visit it in another window:
  9310. ((bound-and-true-p org-clock-current-task)
  9311. (org-switch-to-buffer-other-window (org-clock-goto)))
  9312. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9313. (defun org-agenda-diary-entry-in-org-file ()
  9314. "Make a diary entry in the file `org-agenda-diary-file'."
  9315. (let (d1 d2 char (text "") dp1 dp2)
  9316. (if (equal (buffer-name) "*Calendar*")
  9317. (setq d1 (calendar-cursor-to-date t)
  9318. d2 (car calendar-mark-ring))
  9319. (setq dp1 (get-text-property (line-beginning-position) 'day))
  9320. (unless dp1 (user-error "No date defined in current line"))
  9321. (setq d1 (calendar-gregorian-from-absolute dp1)
  9322. d2 (and (ignore-errors (mark))
  9323. (save-excursion
  9324. (goto-char (mark))
  9325. (setq dp2 (get-text-property (line-beginning-position) 'day)))
  9326. (calendar-gregorian-from-absolute dp2))))
  9327. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9328. (setq char (read-char-exclusive))
  9329. (cond
  9330. ((equal char ?d)
  9331. (setq text (read-string "Day entry: "))
  9332. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9333. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9334. ((equal char ?a)
  9335. (setq d1 (list (car d1) (nth 1 d1)
  9336. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9337. (nth 2 d1))))
  9338. (setq text (read-string "Anniversary (use %d to show years): "))
  9339. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9340. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9341. ((equal char ?b)
  9342. (setq text (read-string "Block entry: "))
  9343. (unless (and d1 d2 (not (equal d1 d2)))
  9344. (user-error "No block of days selected"))
  9345. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9346. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9347. ((equal char ?j)
  9348. (org-switch-to-buffer-other-window
  9349. (find-file-noselect org-agenda-diary-file))
  9350. (require 'org-datetree)
  9351. (org-datetree-find-date-create d1)
  9352. (org-reveal t))
  9353. (t (user-error "Invalid selection character `%c'" char)))))
  9354. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9355. "Where in `org-agenda-diary-file' should new entries be added?
  9356. Valid values:
  9357. date-tree in the date tree, as first child of the date
  9358. date-tree-last in the date tree, as last child of the date
  9359. top-level as top-level entries at the end of the file."
  9360. :group 'org-agenda
  9361. :type '(choice
  9362. (const :tag "first in a date tree" date-tree)
  9363. (const :tag "last in a date tree" date-tree-last)
  9364. (const :tag "as top level at end of file" top-level)))
  9365. (defcustom org-agenda-insert-diary-extract-time nil
  9366. "Non-nil means extract any time specification from the diary entry."
  9367. :group 'org-agenda
  9368. :version "24.1"
  9369. :type 'boolean)
  9370. (defcustom org-agenda-bulk-mark-char ">"
  9371. "A single-character string to be used as the bulk mark."
  9372. :group 'org-agenda
  9373. :version "24.1"
  9374. :type 'string)
  9375. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9376. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9377. If TEXT is not empty, it will become the headline of the new entry, and
  9378. the resulting entry will not be shown. When TEXT is empty, switch to
  9379. `org-agenda-diary-file' and let the user finish the entry there."
  9380. (let ((cw (current-window-configuration)))
  9381. (org-switch-to-buffer-other-window
  9382. (find-file-noselect org-agenda-diary-file))
  9383. (widen)
  9384. (goto-char (point-min))
  9385. (cl-case type
  9386. (anniversary
  9387. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9388. (progn
  9389. (or (org-at-heading-p t)
  9390. (progn
  9391. (outline-next-heading)
  9392. (insert "* Anniversaries\n\n")
  9393. (beginning-of-line -1)))))
  9394. (outline-next-heading)
  9395. (org-back-over-empty-lines)
  9396. (backward-char 1)
  9397. (insert "\n")
  9398. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9399. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9400. (day
  9401. (let ((org-prefix-has-time t)
  9402. (org-agenda-time-leading-zero t)
  9403. fmt time time2)
  9404. (when org-agenda-insert-diary-extract-time
  9405. ;; Use org-agenda-format-item to parse text for a time-range and
  9406. ;; remove it. FIXME: This is a hack, we should refactor
  9407. ;; that function to make time extraction available separately
  9408. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9409. time (get-text-property 0 'time fmt)
  9410. time2 (if (> (length time) 0)
  9411. ;; split-string removes trailing ...... if
  9412. ;; no end time given. First space
  9413. ;; separates time from date.
  9414. (concat " " (car (split-string time "\\.")))
  9415. nil)
  9416. text (get-text-property 0 'txt fmt)))
  9417. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9418. (org-agenda-insert-diary-as-top-level text)
  9419. (require 'org-datetree)
  9420. (org-datetree-find-date-create d1)
  9421. (org-agenda-insert-diary-make-new-entry text))
  9422. (org-insert-time-stamp (org-time-from-absolute
  9423. (calendar-absolute-from-gregorian d1))
  9424. nil nil nil nil time2))
  9425. (end-of-line 0))
  9426. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9427. ;; otherwise the indentation gets confused by the
  9428. ;; special meaning of 'block
  9429. (when (> (calendar-absolute-from-gregorian d1)
  9430. (calendar-absolute-from-gregorian d2))
  9431. (setq d1 (prog1 d2 (setq d2 d1))))
  9432. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9433. (org-agenda-insert-diary-as-top-level text)
  9434. (require 'org-datetree)
  9435. (org-datetree-find-date-create d1)
  9436. (org-agenda-insert-diary-make-new-entry text))
  9437. (org-insert-time-stamp (org-time-from-absolute
  9438. (calendar-absolute-from-gregorian d1)))
  9439. (insert "--")
  9440. (org-insert-time-stamp (org-time-from-absolute
  9441. (calendar-absolute-from-gregorian d2)))
  9442. (end-of-line 0)))
  9443. (if (string-match "\\S-" text)
  9444. (progn
  9445. (set-window-configuration cw)
  9446. (message "%s entry added to %s"
  9447. (capitalize (symbol-name type))
  9448. (abbreviate-file-name org-agenda-diary-file)))
  9449. (org-reveal t)
  9450. (message "Please finish entry here"))))
  9451. (defun org-agenda-insert-diary-as-top-level (text)
  9452. "Make new entry as a top-level entry at the end of the file.
  9453. Add TEXT as headline, and position the cursor in the second line so that
  9454. a timestamp can be added there."
  9455. (widen)
  9456. (goto-char (point-max))
  9457. (unless (bolp) (insert "\n"))
  9458. (org-insert-heading nil t t)
  9459. (insert text)
  9460. (org-end-of-meta-data)
  9461. (unless (bolp) (insert "\n"))
  9462. (when org-adapt-indentation (indent-to-column 2)))
  9463. (defun org-agenda-insert-diary-make-new-entry (text)
  9464. "Make a new entry with TEXT as a child of the current subtree.
  9465. Position the point in the heading's first body line so that
  9466. a timestamp can be added there."
  9467. (cond
  9468. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9469. (end-of-line)
  9470. (org-insert-heading '(4) t)
  9471. (org-do-demote))
  9472. (t
  9473. (outline-next-heading)
  9474. (org-back-over-empty-lines)
  9475. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9476. (org-insert-heading nil t)
  9477. (org-do-demote)))
  9478. (let ((col (current-column)))
  9479. (insert text)
  9480. (org-end-of-meta-data)
  9481. ;; Ensure point is left on a blank line, at proper indentation.
  9482. (unless (bolp) (insert "\n"))
  9483. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9484. (when org-adapt-indentation (indent-to-column col)))
  9485. (org-show-set-visibility 'lineage))
  9486. (defun org-agenda-diary-entry ()
  9487. "Make a diary entry, like the `i' command from the calendar.
  9488. All the standard commands work: block, weekly etc.
  9489. When `org-agenda-diary-file' points to a file,
  9490. `org-agenda-diary-entry-in-org-file' is called instead to create
  9491. entries in that Org file."
  9492. (interactive)
  9493. (if (not (eq org-agenda-diary-file 'diary-file))
  9494. (org-agenda-diary-entry-in-org-file)
  9495. (require 'diary-lib)
  9496. (let* ((char (read-char-exclusive
  9497. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9498. [a]nniversary [b]lock [c]yclic"))
  9499. (cmd (cdr (assoc char
  9500. '((?d . diary-insert-entry)
  9501. (?w . diary-insert-weekly-entry)
  9502. (?m . diary-insert-monthly-entry)
  9503. (?y . diary-insert-yearly-entry)
  9504. (?a . diary-insert-anniversary-entry)
  9505. (?b . diary-insert-block-entry)
  9506. (?c . diary-insert-cyclic-entry)))))
  9507. (oldf (symbol-function 'calendar-cursor-to-date))
  9508. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9509. (point (point))
  9510. (mark (or (mark t) (point))))
  9511. (unless cmd
  9512. (user-error "No command associated with <%c>" char))
  9513. (unless (and (get-text-property point 'day)
  9514. (or (not (equal ?b char))
  9515. (get-text-property mark 'day)))
  9516. (user-error "Don't know which date to use for diary entry"))
  9517. ;; We implement this by hacking the `calendar-cursor-to-date' function
  9518. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  9519. (let ((calendar-mark-ring
  9520. (list (calendar-gregorian-from-absolute
  9521. (or (get-text-property mark 'day)
  9522. (get-text-property point 'day))))))
  9523. (unwind-protect
  9524. (progn
  9525. (fset 'calendar-cursor-to-date
  9526. (lambda (&optional _error _dummy)
  9527. (calendar-gregorian-from-absolute
  9528. (get-text-property point 'day))))
  9529. (call-interactively cmd))
  9530. (fset 'calendar-cursor-to-date oldf))))))
  9531. (defun org-agenda-execute-calendar-command (cmd)
  9532. "Execute a calendar command from the agenda with date from cursor."
  9533. (org-agenda-check-type t 'agenda)
  9534. (require 'diary-lib)
  9535. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  9536. (user-error "Don't know which date to use for the calendar command"))
  9537. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  9538. (point (point))
  9539. (date (calendar-gregorian-from-absolute
  9540. (get-text-property point 'day))))
  9541. ;; the following 2 vars are needed in the calendar
  9542. (org-dlet
  9543. ((displayed-month (car date))
  9544. (displayed-year (nth 2 date)))
  9545. (unwind-protect
  9546. (progn
  9547. (fset 'calendar-cursor-to-date
  9548. (lambda (&optional _error _dummy)
  9549. (calendar-gregorian-from-absolute
  9550. (get-text-property point 'day))))
  9551. (call-interactively cmd))
  9552. (fset 'calendar-cursor-to-date oldf)))))
  9553. (defun org-agenda-phases-of-moon ()
  9554. "Display the phases of the moon for the 3 months around the cursor date."
  9555. (interactive)
  9556. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  9557. (defun org-agenda-holidays ()
  9558. "Display the holidays for the 3 months around the cursor date."
  9559. (interactive)
  9560. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  9561. (defvar calendar-longitude) ; defined in calendar.el
  9562. (defvar calendar-latitude) ; defined in calendar.el
  9563. (defvar calendar-location-name) ; defined in calendar.el
  9564. (defun org-agenda-sunrise-sunset (arg)
  9565. "Display sunrise and sunset for the cursor date.
  9566. Latitude and longitude can be specified with the variables
  9567. `calendar-latitude' and `calendar-longitude'. When called with prefix
  9568. argument, latitude and longitude will be prompted for."
  9569. (interactive "P")
  9570. (require 'solar)
  9571. (let ((calendar-longitude (if arg nil calendar-longitude))
  9572. (calendar-latitude (if arg nil calendar-latitude))
  9573. (calendar-location-name
  9574. (if arg "the given coordinates" calendar-location-name)))
  9575. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  9576. (defun org-agenda-goto-calendar ()
  9577. "Open the Emacs calendar with the date at the cursor."
  9578. (interactive)
  9579. (org-agenda-check-type t 'agenda)
  9580. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  9581. (user-error "Don't know which date to open in calendar")))
  9582. (date (calendar-gregorian-from-absolute day))
  9583. (calendar-move-hook nil)
  9584. (calendar-view-holidays-initially-flag nil)
  9585. (calendar-view-diary-initially-flag nil))
  9586. (calendar)
  9587. (calendar-goto-date date)))
  9588. ;;;###autoload
  9589. (defun org-calendar-goto-agenda ()
  9590. "Compute the Org agenda for the calendar date displayed at the cursor.
  9591. This is a command that has to be installed in `calendar-mode-map'."
  9592. (interactive)
  9593. ;; Temporarily disable sticky agenda since user clearly wants to
  9594. ;; refresh view anyway.
  9595. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  9596. (org-agenda-sticky nil))
  9597. (org-agenda-list nil (calendar-absolute-from-gregorian
  9598. (calendar-cursor-to-date))
  9599. nil)))
  9600. (defun org-agenda-convert-date ()
  9601. (interactive)
  9602. (org-agenda-check-type t 'agenda)
  9603. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9604. date s)
  9605. (unless day
  9606. (user-error "Don't know which date to convert"))
  9607. (setq date (calendar-gregorian-from-absolute day))
  9608. (setq s (concat
  9609. "Gregorian: " (calendar-date-string date) "\n"
  9610. "ISO: " (calendar-iso-date-string date) "\n"
  9611. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9612. "Julian: " (calendar-julian-date-string date) "\n"
  9613. "Astron. JD: " (calendar-astro-date-string date)
  9614. " (Julian date number at noon UTC)\n"
  9615. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9616. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9617. "French: " (calendar-french-date-string date) "\n"
  9618. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9619. "Mayan: " (calendar-mayan-date-string date) "\n"
  9620. "Coptic: " (calendar-coptic-date-string date) "\n"
  9621. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9622. "Persian: " (calendar-persian-date-string date) "\n"
  9623. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9624. (with-output-to-temp-buffer "*Dates*"
  9625. (princ s))
  9626. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9627. ;;; Bulk commands
  9628. (defun org-agenda-bulk-marked-p ()
  9629. "Non-nil when current entry is marked for bulk action."
  9630. (eq (get-char-property (line-beginning-position) 'type)
  9631. 'org-marked-entry-overlay))
  9632. (defun org-agenda-bulk-mark (&optional arg)
  9633. "Mark entries for future bulk action.
  9634. When ARG is nil or one and region is not active then mark the
  9635. entry at point.
  9636. When ARG is nil or one and region is active then mark the entries
  9637. in the region.
  9638. When ARG is greater than one mark ARG lines."
  9639. (interactive "p")
  9640. (when (and (or (not arg) (= arg 1)) (use-region-p))
  9641. (setq arg (count-lines (region-beginning) (region-end)))
  9642. (goto-char (region-beginning))
  9643. (deactivate-mark))
  9644. (dotimes (_ (or arg 1))
  9645. (unless (org-get-at-bol 'org-agenda-diary-link)
  9646. (let* ((m (org-get-at-bol 'org-hd-marker))
  9647. ov)
  9648. (unless (org-agenda-bulk-marked-p)
  9649. (unless m (user-error "Nothing to mark at point"))
  9650. (push m org-agenda-bulk-marked-entries)
  9651. (setq ov (make-overlay (line-beginning-position)
  9652. (+ 2 (line-beginning-position))))
  9653. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9654. (org-get-todo-face "TODO")
  9655. 'evaporate)
  9656. (overlay-put ov 'type 'org-marked-entry-overlay))
  9657. (end-of-line 1)
  9658. (or (ignore-errors
  9659. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9660. (beginning-of-line 2))
  9661. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9662. (beginning-of-line 2)))))
  9663. (message "%d entries marked for bulk action"
  9664. (length org-agenda-bulk-marked-entries)))
  9665. (defun org-agenda-bulk-mark-all ()
  9666. "Mark all entries for future agenda bulk action."
  9667. (interactive)
  9668. (org-agenda-bulk-mark-regexp "."))
  9669. (defun org-agenda-bulk-mark-regexp (regexp)
  9670. "Mark entries matching REGEXP for future agenda bulk action."
  9671. (interactive "sMark entries matching regexp: ")
  9672. (let ((entries-marked 0) txt-at-point)
  9673. (save-excursion
  9674. (goto-char (point-min))
  9675. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9676. (while (and (re-search-forward regexp nil t)
  9677. (setq txt-at-point
  9678. (get-text-property (match-beginning 0) 'txt)))
  9679. (if (get-char-property (point) 'invisible)
  9680. (beginning-of-line 2)
  9681. (when (string-match-p regexp txt-at-point)
  9682. (setq entries-marked (1+ entries-marked))
  9683. (call-interactively 'org-agenda-bulk-mark)))))
  9684. (unless entries-marked
  9685. (message "No entry matching this regexp."))))
  9686. (defun org-agenda-bulk-unmark (&optional arg)
  9687. "Unmark the entry at point for future bulk action."
  9688. (interactive "P")
  9689. (if arg
  9690. (org-agenda-bulk-unmark-all)
  9691. (cond ((org-agenda-bulk-marked-p)
  9692. (org-agenda-bulk-remove-overlays
  9693. (line-beginning-position) (+ 2 (line-beginning-position)))
  9694. (setq org-agenda-bulk-marked-entries
  9695. (delete (org-get-at-bol 'org-hd-marker)
  9696. org-agenda-bulk-marked-entries))
  9697. (end-of-line 1)
  9698. (or (ignore-errors
  9699. (goto-char (next-single-property-change (point) 'txt)))
  9700. (beginning-of-line 2))
  9701. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9702. (beginning-of-line 2))
  9703. (message "%d entries left marked for bulk action"
  9704. (length org-agenda-bulk-marked-entries)))
  9705. (t (message "No entry to unmark here")))))
  9706. (defun org-agenda-bulk-toggle-all ()
  9707. "Toggle all marks for bulk action."
  9708. (interactive)
  9709. (save-excursion
  9710. (goto-char (point-min))
  9711. (while (ignore-errors
  9712. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9713. (org-agenda-bulk-toggle))))
  9714. (defun org-agenda-bulk-toggle ()
  9715. "Toggle the mark at point for bulk action."
  9716. (interactive)
  9717. (if (org-agenda-bulk-marked-p)
  9718. (org-agenda-bulk-unmark)
  9719. (org-agenda-bulk-mark)))
  9720. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9721. "Remove the mark overlays between BEG and END in the agenda buffer.
  9722. BEG and END default to the buffer limits.
  9723. This only removes the overlays, it does not remove the markers
  9724. from the list in `org-agenda-bulk-marked-entries'."
  9725. (interactive)
  9726. (mapc (lambda (ov)
  9727. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9728. (delete-overlay ov)))
  9729. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9730. (defun org-agenda-bulk-unmark-all ()
  9731. "Remove all marks in the agenda buffer.
  9732. This will remove the markers and the overlays."
  9733. (interactive)
  9734. (if (null org-agenda-bulk-marked-entries)
  9735. (message "No entry to unmark")
  9736. (setq org-agenda-bulk-marked-entries nil)
  9737. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9738. (defcustom org-agenda-persistent-marks nil
  9739. "Non-nil means marked items will stay marked after a bulk action.
  9740. You can toggle this interactively by typing `p' when prompted for a
  9741. bulk action."
  9742. :group 'org-agenda
  9743. :version "24.1"
  9744. :type 'boolean)
  9745. (defcustom org-agenda-loop-over-headlines-in-active-region t
  9746. "Shall some commands act upon headlines in the active region?
  9747. When set to t, some commands will be performed in all headlines
  9748. within the active region.
  9749. When set to `start-level', some commands will be performed in all
  9750. headlines within the active region, provided that these headlines
  9751. are of the same level than the first one.
  9752. When set to a regular expression, those commands will be
  9753. performed on the matching headlines within the active region.
  9754. The list of commands is: `org-agenda-schedule',
  9755. `org-agenda-deadline', `org-agenda-date-prompt',
  9756. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  9757. See `org-loop-over-headlines-in-active-region' for the equivalent
  9758. option for Org buffers."
  9759. :type '(choice (const :tag "Don't loop" nil)
  9760. (const :tag "All headlines in active region" t)
  9761. (const :tag "In active region, headlines at the same level than the first one" start-level)
  9762. (regexp :tag "Regular expression matcher"))
  9763. :version "27.1"
  9764. :package-version '(Org . "9.4")
  9765. :group 'org-agenda)
  9766. (defun org-agenda-bulk-action (&optional arg)
  9767. "Execute an remote-editing action on all marked entries.
  9768. The prefix arg is passed through to the command if possible."
  9769. (interactive "P")
  9770. ;; When there is no mark, act on the agenda entry at point.
  9771. (if (not org-agenda-bulk-marked-entries)
  9772. (save-excursion (org-agenda-bulk-mark)))
  9773. (dolist (m org-agenda-bulk-marked-entries)
  9774. (unless (and (markerp m)
  9775. (marker-buffer m)
  9776. (buffer-live-p (marker-buffer m))
  9777. (marker-position m))
  9778. (user-error "Marker %s for bulk command is invalid" m)))
  9779. ;; Prompt for the bulk command.
  9780. (org-unlogged-message
  9781. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  9782. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9783. "[S]catter [f]unction "
  9784. (and org-agenda-bulk-custom-functions
  9785. (format " Custom: [%s]"
  9786. (mapconcat (lambda (f) (char-to-string (car f)))
  9787. org-agenda-bulk-custom-functions
  9788. "")))))
  9789. (catch 'exit
  9790. (let* ((org-log-refile (if org-log-refile 'time nil))
  9791. (entries (reverse org-agenda-bulk-marked-entries))
  9792. (org-overriding-default-time
  9793. (and (get-text-property (point) 'org-agenda-date-header)
  9794. (org-get-cursor-date)))
  9795. redo-at-end
  9796. cmd)
  9797. (pcase (read-char-exclusive)
  9798. (?p
  9799. (let ((org-agenda-persistent-marks
  9800. (not org-agenda-persistent-marks)))
  9801. (org-agenda-bulk-action)
  9802. (throw 'exit nil)))
  9803. (?$
  9804. (setq cmd #'org-agenda-archive))
  9805. (?A
  9806. (setq cmd #'org-agenda-archive-to-archive-sibling))
  9807. ((or ?r ?w)
  9808. (let ((refile-location
  9809. (org-refile-get-location
  9810. "Refile to"
  9811. (marker-buffer (car entries))
  9812. org-refile-allow-creating-parent-nodes)))
  9813. (when (nth 3 refile-location)
  9814. (setcar (nthcdr 3 refile-location)
  9815. (move-marker
  9816. (make-marker)
  9817. (nth 3 refile-location)
  9818. (or (get-file-buffer (nth 1 refile-location))
  9819. (find-buffer-visiting (nth 1 refile-location))
  9820. (error "This should not happen")))))
  9821. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  9822. (setq redo-at-end t)))
  9823. (?t
  9824. (let ((state (completing-read
  9825. "Todo state: "
  9826. (with-current-buffer (marker-buffer (car entries))
  9827. (mapcar #'list org-todo-keywords-1)))))
  9828. (setq cmd (lambda ()
  9829. (let ((org-inhibit-blocking t)
  9830. (org-inhibit-logging 'note))
  9831. (org-agenda-todo state))))))
  9832. ((and (or ?- ?+) action)
  9833. (let ((tag (completing-read
  9834. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9835. (with-current-buffer (marker-buffer (car entries))
  9836. (delq nil
  9837. (mapcar (lambda (x) (and (stringp (car x)) x))
  9838. org-current-tag-alist))))))
  9839. (setq cmd
  9840. (lambda ()
  9841. (org-agenda-set-tags tag
  9842. (if (eq action ?+) 'on 'off))))))
  9843. ((and (or ?s ?d) c)
  9844. (let* ((schedule? (eq c ?s))
  9845. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  9846. (time
  9847. (and (not arg)
  9848. (let ((new (org-read-date
  9849. nil nil nil prompt org-overriding-default-time)))
  9850. ;; A "double plus" answer applies to every
  9851. ;; scheduled time. Do not turn it into
  9852. ;; a fixed date yet.
  9853. (if (string-match-p "\\`[ \t]*\\+\\+"
  9854. org-read-date-final-answer)
  9855. org-read-date-final-answer
  9856. new)))))
  9857. ;; Make sure to not prompt for a note when bulk
  9858. ;; rescheduling/resetting deadline as Org cannot cope with
  9859. ;; simultaneous notes. Besides, it could be annoying
  9860. ;; depending on the number of marked items.
  9861. (setq cmd
  9862. (if schedule?
  9863. (lambda ()
  9864. (let ((org-log-reschedule
  9865. (and org-log-reschedule 'time)))
  9866. (org-agenda-schedule arg time)))
  9867. (lambda ()
  9868. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  9869. (org-agenda-deadline arg time)))))))
  9870. (?S
  9871. (unless (org-agenda-check-type nil 'agenda 'todo)
  9872. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  9873. (let ((days (read-number
  9874. (format "Scatter tasks across how many %sdays: "
  9875. (if arg "week" ""))
  9876. 7)))
  9877. (setq cmd
  9878. (lambda ()
  9879. (let ((distance (1+ (random days))))
  9880. (when arg
  9881. (let ((dist distance)
  9882. (day-of-week
  9883. (calendar-day-of-week
  9884. (calendar-gregorian-from-absolute (org-today)))))
  9885. (dotimes (_ (1+ dist))
  9886. (while (member day-of-week org-agenda-weekend-days)
  9887. (cl-incf distance)
  9888. (cl-incf day-of-week)
  9889. (when (= day-of-week 7)
  9890. (setq day-of-week 0)))
  9891. (cl-incf day-of-week)
  9892. (when (= day-of-week 7)
  9893. (setq day-of-week 0)))))
  9894. ;; Silently fail when try to replan a sexp entry.
  9895. (ignore-errors
  9896. (let* ((date (calendar-gregorian-from-absolute
  9897. (+ (org-today) distance)))
  9898. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9899. (nth 2 date))))
  9900. (org-agenda-schedule nil time))))))))
  9901. (?f
  9902. (setq cmd
  9903. (intern
  9904. (completing-read "Function: " obarray #'fboundp t nil nil))))
  9905. (action
  9906. (setq cmd
  9907. (pcase (assoc action org-agenda-bulk-custom-functions)
  9908. (`(,_ ,fn)
  9909. fn)
  9910. (`(,_ ,fn ,arg-fn)
  9911. (apply #'apply-partially fn (funcall arg-fn)))
  9912. (_
  9913. (user-error "Invalid bulk action: %c" action))))
  9914. (setq redo-at-end t)))
  9915. ;; Sort the markers, to make sure that parents are handled
  9916. ;; before children.
  9917. (setq entries (sort entries
  9918. (lambda (a b)
  9919. (cond
  9920. ((eq (marker-buffer a) (marker-buffer b))
  9921. (< (marker-position a) (marker-position b)))
  9922. (t
  9923. (string< (buffer-name (marker-buffer a))
  9924. (buffer-name (marker-buffer b))))))))
  9925. ;; Now loop over all markers and apply CMD.
  9926. (let ((processed 0)
  9927. (skipped 0))
  9928. (dolist (e entries)
  9929. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  9930. (if (not pos)
  9931. (progn (message "Skipping removed entry at %s" e)
  9932. (cl-incf skipped))
  9933. (goto-char pos)
  9934. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  9935. ;; `post-command-hook' is not run yet. We make sure any
  9936. ;; pending log note is processed.
  9937. (when org-log-setup (org-add-log-note))
  9938. (cl-incf processed))))
  9939. (when redo-at-end (org-agenda-redo))
  9940. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  9941. (message "Acted on %d entries%s%s"
  9942. processed
  9943. (if (= skipped 0)
  9944. ""
  9945. (format ", skipped %d (disappeared before their turn)"
  9946. skipped))
  9947. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  9948. (defun org-agenda-capture (&optional with-time)
  9949. "Call `org-capture' with the date at point.
  9950. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9951. current HH:MM time."
  9952. (interactive "P")
  9953. (if (not (eq major-mode 'org-agenda-mode))
  9954. (user-error "You cannot do this outside of agenda buffers")
  9955. (let ((org-overriding-default-time
  9956. (org-get-cursor-date (equal with-time 1))))
  9957. (call-interactively 'org-capture))))
  9958. ;;; Dragging agenda lines forward/backward
  9959. (defun org-agenda-reapply-filters ()
  9960. "Re-apply all agenda filters."
  9961. (mapcar
  9962. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9963. `((,org-agenda-tag-filter tag)
  9964. (,org-agenda-category-filter category)
  9965. (,org-agenda-regexp-filter regexp)
  9966. (,org-agenda-effort-filter effort)
  9967. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9968. (,(get 'org-agenda-category-filter :preset-filter) category)
  9969. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9970. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9971. (defun org-agenda-drag-line-forward (arg &optional backward)
  9972. "Drag an agenda line forward by ARG lines.
  9973. When the optional argument `backward' is non-nil, move backward."
  9974. (interactive "p")
  9975. (let ((inhibit-read-only t) lst line)
  9976. (if (or (not (get-text-property (point) 'txt))
  9977. (save-excursion
  9978. (dotimes (_ arg)
  9979. (move-beginning-of-line (if backward 0 2))
  9980. (push (not (get-text-property (point) 'txt)) lst))
  9981. (delq nil lst)))
  9982. (message "Cannot move line forward")
  9983. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9984. (move-beginning-of-line 1)
  9985. (setq line (buffer-substring (point) end))
  9986. (delete-region (point) end)
  9987. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9988. (insert line)
  9989. (org-agenda-reapply-filters)
  9990. (org-agenda-mark-clocking-task)
  9991. (move-beginning-of-line 0)))))
  9992. (defun org-agenda-drag-line-backward (arg)
  9993. "Drag an agenda line backward by ARG lines."
  9994. (interactive "p")
  9995. (org-agenda-drag-line-forward arg t))
  9996. ;;; Flagging notes
  9997. (defun org-agenda-show-the-flagging-note ()
  9998. "Display the flagging note in the other window.
  9999. When called a second time in direct sequence, offer to remove the FLAGGING
  10000. tag and (if present) the flagging note."
  10001. (interactive)
  10002. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10003. (win (selected-window))
  10004. note) ;; heading newhead
  10005. (unless hdmarker
  10006. (user-error "No linked entry at point"))
  10007. (if (and (eq this-command last-command)
  10008. (y-or-n-p "Unflag and remove any flagging note? "))
  10009. (progn
  10010. (org-agenda-remove-flag hdmarker)
  10011. (let ((win (get-buffer-window "*Flagging Note*")))
  10012. (and win (delete-window win)))
  10013. (message "Entry unflagged"))
  10014. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10015. (unless note
  10016. (user-error "No flagging note"))
  10017. (org-kill-new note)
  10018. (org-switch-to-buffer-other-window "*Flagging Note*")
  10019. (erase-buffer)
  10020. (insert note)
  10021. (goto-char (point-min))
  10022. (while (re-search-forward "\\\\n" nil t)
  10023. (replace-match "\n" t t))
  10024. (goto-char (point-min))
  10025. (select-window win)
  10026. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10027. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10028. tag and note")))))
  10029. (defun org-agenda-remove-flag (marker)
  10030. "Remove the FLAGGED tag and any flagging note in the entry."
  10031. (let ((newhead
  10032. (org-with-point-at marker
  10033. (org-toggle-tag "FLAGGED" 'off)
  10034. (org-entry-delete nil "THEFLAGGINGNOTE")
  10035. (org-get-heading))))
  10036. (org-agenda-change-all-lines newhead marker)
  10037. (message "Entry unflagged")))
  10038. (defun org-agenda-get-any-marker (&optional pos)
  10039. (or (get-text-property (or pos (line-beginning-position)) 'org-hd-marker)
  10040. (get-text-property (or pos (line-beginning-position)) 'org-marker)))
  10041. ;;; Appointment reminders
  10042. (defvar appt-time-msg-list) ; defined in appt.el
  10043. ;;;###autoload
  10044. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10045. "Activate appointments found in `org-agenda-files'.
  10046. With a `\\[universal-argument]' prefix, refresh the list of \
  10047. appointments.
  10048. If FILTER is t, interactively prompt the user for a regular
  10049. expression, and filter out entries that don't match it.
  10050. If FILTER is a string, use this string as a regular expression
  10051. for filtering entries out.
  10052. If FILTER is a function, filter out entries against which
  10053. calling the function returns nil. This function takes one
  10054. argument: an entry from `org-agenda-get-day-entries'.
  10055. FILTER can also be an alist with the car of each cell being
  10056. either `headline' or `category'. For example:
  10057. \\='((headline \"IMPORTANT\")
  10058. (category \"Work\"))
  10059. will only add headlines containing IMPORTANT or headlines
  10060. belonging to the \"Work\" category.
  10061. ARGS are symbols indicating what kind of entries to consider.
  10062. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10063. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10064. and :timestamp entries. See the docstring of `org-diary' for
  10065. details and examples.
  10066. If an entry has a APPT_WARNTIME property, its value will be used
  10067. to override `appt-message-warning-time'."
  10068. (interactive "P")
  10069. (when refresh (setq appt-time-msg-list nil))
  10070. (when (eq filter t)
  10071. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10072. (let* ((cnt 0) ; count added events
  10073. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10074. (org-agenda-new-buffers nil)
  10075. (org-deadline-warning-days 0)
  10076. ;; Do not use `org-today' here because appt only takes
  10077. ;; time and without date as argument, so it may pass wrong
  10078. ;; information otherwise
  10079. (today (org-date-to-gregorian
  10080. (time-to-days nil)))
  10081. (org-agenda-restrict nil)
  10082. (files (org-agenda-files 'unrestricted)) entries file
  10083. (org-agenda-buffer nil))
  10084. ;; Get all entries which may contain an appt
  10085. (org-agenda-prepare-buffers files)
  10086. (while (setq file (pop files))
  10087. (setq entries
  10088. (delq nil
  10089. (append entries
  10090. (apply #'org-agenda-get-day-entries
  10091. file today scope)))))
  10092. ;; Map through entries and find if we should filter them out
  10093. (mapc
  10094. (lambda (x)
  10095. (let* ((evt (org-trim
  10096. (replace-regexp-in-string
  10097. org-link-bracket-re "\\2"
  10098. (or (get-text-property 1 'txt x) ""))))
  10099. (cat (get-text-property (1- (length x)) 'org-category x))
  10100. (tod (get-text-property 1 'time-of-day x))
  10101. (ok (or (null filter)
  10102. (and (stringp filter) (string-match filter evt))
  10103. (and (functionp filter) (funcall filter x))
  10104. (and (listp filter)
  10105. (let ((cat-filter (cadr (assq 'category filter)))
  10106. (evt-filter (cadr (assq 'headline filter))))
  10107. (or (and (stringp cat-filter)
  10108. (string-match cat-filter cat))
  10109. (and (stringp evt-filter)
  10110. (string-match evt-filter evt)))))))
  10111. (wrn (get-text-property 1 'warntime x)))
  10112. ;; FIXME: Shall we remove text-properties for the appt text?
  10113. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10114. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10115. (setq tod (concat "00" (number-to-string tod)))
  10116. (setq tod (when (string-match
  10117. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10118. (concat (match-string 1 tod) ":"
  10119. (match-string 2 tod))))
  10120. (when (appt-add tod evt wrn)
  10121. (setq cnt (1+ cnt))))))
  10122. entries)
  10123. (org-release-buffers org-agenda-new-buffers)
  10124. (if (eq cnt 0)
  10125. (message "No event to add")
  10126. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10127. (defun org-agenda-today-p (date)
  10128. "Non-nil when DATE means today.
  10129. DATE is either a list of the form (month day year) or a number of
  10130. days as returned by `calendar-absolute-from-gregorian' or
  10131. `org-today'. This function considers `org-extend-today-until'
  10132. when defining today."
  10133. (eq (org-today)
  10134. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10135. (defun org-agenda-todo-yesterday (&optional arg)
  10136. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10137. (interactive "P")
  10138. (let* ((org-use-effective-time t)
  10139. (hour (nth 2 (decode-time (org-current-time))))
  10140. (org-extend-today-until (1+ hour)))
  10141. (org-agenda-todo arg)))
  10142. (defun org-agenda-ctrl-c-ctrl-c ()
  10143. "Set tags in agenda buffer."
  10144. (interactive)
  10145. (org-agenda-set-tags))
  10146. (provide 'org-agenda)
  10147. ;;; org-agenda.el ends here