org-agenda.el 396 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  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. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-columns-remove-overlays "org-colview" ())
  64. (declare-function org-datetree-find-date-create "org-datetree"
  65. (date &optional keep-restriction))
  66. (declare-function org-columns-quit "org-colview" ())
  67. (declare-function diary-date-display-form "diary-lib" (&optional type))
  68. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  69. (declare-function org-habit-insert-consistency-graphs
  70. "org-habit" (&optional line))
  71. (declare-function org-is-habit-p "org-habit" (&optional pom))
  72. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  73. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  74. (declare-function org-agenda-columns "org-colview" ())
  75. (declare-function org-add-archive-files "org-archive" (files))
  76. (declare-function org-capture "org-capture" (&optional goto keys))
  77. (defvar calendar-mode-map)
  78. (defvar org-clock-current-task)
  79. (defvar org-current-tag-alist)
  80. (defvar org-mobile-force-id-on-agenda-items)
  81. (defvar org-habit-show-habits)
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. (defvar org-habit-scheduled-past-days)
  85. ;; Defined somewhere in this file, but used before definition.
  86. (defvar org-agenda-buffer-name "*Org Agenda*")
  87. (defvar org-agenda-overriding-header nil)
  88. (defvar org-agenda-title-append nil)
  89. (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  90. (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  91. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  92. (defvar org-agenda-undo-list nil
  93. "List of undoable operations in the agenda since last refresh.")
  94. (defvar org-agenda-pending-undo-list nil
  95. "In a series of undo commands, this is the list of remaining undo items.")
  96. (defcustom org-agenda-confirm-kill 1
  97. "When set, remote killing from the agenda buffer needs confirmation.
  98. When t, a confirmation is always needed. When a number N, confirmation is
  99. only needed when the text to be killed contains more than N non-white lines."
  100. :group 'org-agenda
  101. :type '(choice
  102. (const :tag "Never" nil)
  103. (const :tag "Always" t)
  104. (integer :tag "When more than N lines")))
  105. (defcustom org-agenda-compact-blocks nil
  106. "Non-nil means make the block agenda more compact.
  107. This is done globally by leaving out lines like the agenda span
  108. name and week number or the separator lines."
  109. :group 'org-agenda
  110. :type 'boolean)
  111. (defcustom org-agenda-block-separator ?=
  112. "The separator between blocks in the agenda.
  113. If this is a string, it will be used as the separator, with a newline added.
  114. If it is a character, it will be repeated to fill the window width.
  115. If nil the separator is disabled. In `org-agenda-custom-commands' this
  116. addresses the separator between the current and the previous block."
  117. :group 'org-agenda
  118. :type '(choice
  119. (const :tag "Disabled" nil)
  120. (character)
  121. (string)))
  122. (defgroup org-agenda-export nil
  123. "Options concerning exporting agenda views in Org mode."
  124. :tag "Org Agenda Export"
  125. :group 'org-agenda)
  126. (defcustom org-agenda-with-colors t
  127. "Non-nil means use colors in agenda views."
  128. :group 'org-agenda-export
  129. :type 'boolean)
  130. (defcustom org-agenda-exporter-settings nil
  131. "Alist of variable/value pairs that should be active during agenda export.
  132. This is a good place to set options for ps-print and for htmlize.
  133. Note that the way this is implemented, the values will be evaluated
  134. before assigned to the variables. So make sure to quote values you do
  135. *not* want evaluated, for example
  136. (setq org-agenda-exporter-settings
  137. \\='((ps-print-color-p \\='black-white)))"
  138. :group 'org-agenda-export
  139. :type '(repeat
  140. (list
  141. (variable)
  142. (sexp :tag "Value"))))
  143. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  144. "Hook run in a temporary buffer before writing the agenda to an export file.
  145. A useful function for this hook is `org-agenda-add-entry-text'."
  146. :group 'org-agenda-export
  147. :type 'hook
  148. :options '(org-agenda-add-entry-text))
  149. (defcustom org-agenda-add-entry-text-maxlines 0
  150. "Maximum number of entry text lines to be added to agenda.
  151. This is only relevant when `org-agenda-add-entry-text' is part of
  152. `org-agenda-before-write-hook', which is the default.
  153. When this is 0, nothing will happen. When it is greater than 0, it
  154. specifies the maximum number of lines that will be added for each entry
  155. that is listed in the agenda view.
  156. Note that this variable is not used during display, only when exporting
  157. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  158. and `org-agenda-entry-text-maxlines'."
  159. :group 'org-agenda
  160. :type 'integer)
  161. (defcustom org-agenda-add-entry-text-descriptive-links t
  162. "Non-nil means export org-links as descriptive links in agenda added text.
  163. This variable applies to the text added to the agenda when
  164. `org-agenda-add-entry-text-maxlines' is larger than 0.
  165. When this variable nil, the URL will (also) be shown."
  166. :group 'org-agenda
  167. :type 'boolean)
  168. (defcustom org-agenda-export-html-style nil
  169. "The style specification for exported HTML Agenda files.
  170. If this variable contains a string, it will replace the default <style>
  171. section as produced by `htmlize'.
  172. Since there are different ways of setting style information, this variable
  173. needs to contain the full HTML structure to provide a style, including the
  174. surrounding HTML tags. The style specifications should include definitions
  175. the fonts used by the agenda, here is an example:
  176. <style type=\"text/css\">
  177. p { font-weight: normal; color: gray; }
  178. .org-agenda-structure {
  179. font-size: 110%;
  180. color: #003399;
  181. font-weight: 600;
  182. }
  183. .org-todo {
  184. color: #cc6666;
  185. font-weight: bold;
  186. }
  187. .org-agenda-done {
  188. color: #339933;
  189. }
  190. .org-done {
  191. color: #339933;
  192. }
  193. .title { text-align: center; }
  194. .todo, .deadline { color: red; }
  195. .done { color: green; }
  196. </style>
  197. or, if you want to keep the style in a file,
  198. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  199. As the value of this option simply gets inserted into the HTML <head> header,
  200. you can \"misuse\" it to also add other text to the header."
  201. :group 'org-agenda-export
  202. :group 'org-export-html
  203. :type '(choice
  204. (const nil)
  205. (string)))
  206. (defcustom org-agenda-persistent-filter nil
  207. "When set, keep filters from one agenda view to the next."
  208. :group 'org-agenda
  209. :type 'boolean)
  210. (defgroup org-agenda-custom-commands nil
  211. "Options concerning agenda views in Org mode."
  212. :tag "Org Agenda Custom Commands"
  213. :group 'org-agenda)
  214. (defconst org-sorting-choice
  215. '(choice
  216. (const time-up) (const time-down)
  217. (const timestamp-up) (const timestamp-down)
  218. (const scheduled-up) (const scheduled-down)
  219. (const deadline-up) (const deadline-down)
  220. (const ts-up) (const ts-down)
  221. (const tsia-up) (const tsia-down)
  222. (const category-keep) (const category-up) (const category-down)
  223. (const tag-down) (const tag-up)
  224. (const priority-up) (const priority-down)
  225. (const todo-state-up) (const todo-state-down)
  226. (const effort-up) (const effort-down)
  227. (const habit-up) (const habit-down)
  228. (const alpha-up) (const alpha-down)
  229. (const user-defined-up) (const user-defined-down))
  230. "Sorting choices.")
  231. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  232. ;; the new variable `org-agenda-tag-filter-preset'.
  233. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  234. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  235. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  236. "List of types searched for when creating the daily/weekly agenda.
  237. This variable is a list of symbols that controls the types of
  238. items that appear in the daily/weekly agenda. Allowed symbols in this
  239. list are are
  240. :timestamp List items containing a date stamp or date range matching
  241. the selected date. This includes sexp entries in angular
  242. brackets.
  243. :sexp List entries resulting from plain diary-like sexps.
  244. :deadline List deadline due on that date. When the date is today,
  245. also list any deadlines past due, or due within
  246. `org-deadline-warning-days'.
  247. :deadline* Same as above, but only include the deadline if it has an
  248. hour specification as [h]h:mm.
  249. :scheduled List all items which are scheduled for the given date.
  250. The diary for *today* also contains items which were
  251. scheduled earlier and are not yet marked DONE.
  252. :scheduled* Same as above, but only include the scheduled item if it
  253. has an hour specification as [h]h:mm.
  254. By default, all four non-starred types are turned on.
  255. When :scheduled* or :deadline* are included, :schedule or :deadline
  256. will be ignored.
  257. Never set this variable globally using `setq', because then it
  258. will apply to all future agenda commands. Instead, bind it with
  259. `let' to scope it dynamically into the agenda-constructing
  260. command. A good way to set it is through options in
  261. `org-agenda-custom-commands'. For a more flexible (though
  262. somewhat less efficient) way of determining what is included in
  263. the daily/weekly agenda, see `org-agenda-skip-function'.")
  264. (defconst org-agenda-custom-commands-local-options
  265. `(repeat :tag "Local settings for this command. Remember to quote values"
  266. (choice :tag "Setting"
  267. (list :tag "Heading for this block"
  268. (const org-agenda-overriding-header)
  269. (string :tag "Headline"))
  270. (list :tag "Files to be searched"
  271. (const org-agenda-files)
  272. (list
  273. (const :format "" quote)
  274. (repeat (file))))
  275. (list :tag "Sorting strategy"
  276. (const org-agenda-sorting-strategy)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. ,org-sorting-choice)))
  281. (list :tag "Prefix format"
  282. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  283. (string))
  284. (list :tag "Number of days in agenda"
  285. (const org-agenda-span)
  286. (list
  287. (const :format "" quote)
  288. (choice (const :tag "Day" day)
  289. (const :tag "Week" week)
  290. (const :tag "Fortnight" fortnight)
  291. (const :tag "Month" month)
  292. (const :tag "Year" year)
  293. (integer :tag "Custom"))))
  294. (list :tag "Fixed starting date"
  295. (const org-agenda-start-day)
  296. (string :value "2007-11-01"))
  297. (list :tag "Start on day of week"
  298. (const org-agenda-start-on-weekday)
  299. (choice :value 1
  300. (const :tag "Today" nil)
  301. (integer :tag "Weekday No.")))
  302. (list :tag "Include data from diary"
  303. (const org-agenda-include-diary)
  304. (boolean))
  305. (list :tag "Deadline Warning days"
  306. (const org-deadline-warning-days)
  307. (integer :value 1))
  308. (list :tag "Category filter preset"
  309. (const org-agenda-category-filter-preset)
  310. (list
  311. (const :format "" quote)
  312. (repeat
  313. (string :tag "+category or -category"))))
  314. (list :tag "Tags filter preset"
  315. (const org-agenda-tag-filter-preset)
  316. (list
  317. (const :format "" quote)
  318. (repeat
  319. (string :tag "+tag or -tag"))))
  320. (list :tag "Effort filter preset"
  321. (const org-agenda-effort-filter-preset)
  322. (list
  323. (const :format "" quote)
  324. (repeat
  325. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  326. (list :tag "Regexp filter preset"
  327. (const org-agenda-regexp-filter-preset)
  328. (list
  329. (const :format "" quote)
  330. (repeat
  331. (string :tag "+regexp or -regexp"))))
  332. (list :tag "Set daily/weekly entry types"
  333. (const org-agenda-entry-types)
  334. (list
  335. (const :format "" quote)
  336. (set :greedy t :value ,org-agenda-entry-types
  337. (const :deadline)
  338. (const :scheduled)
  339. (const :deadline*)
  340. (const :scheduled*)
  341. (const :timestamp)
  342. (const :sexp))))
  343. (list :tag "Standard skipping condition"
  344. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  345. (const org-agenda-skip-function)
  346. (list
  347. (const :format "" quote)
  348. (list
  349. (choice
  350. :tag "Skipping range"
  351. (const :tag "Skip entry" org-agenda-skip-entry-if)
  352. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  353. (repeat :inline t :tag "Conditions for skipping"
  354. (choice
  355. :tag "Condition type"
  356. (list :tag "Regexp matches" :inline t
  357. (const :format "" regexp)
  358. (regexp))
  359. (list :tag "Regexp does not match" :inline t
  360. (const :format "" notregexp)
  361. (regexp))
  362. (list :tag "TODO state is" :inline t
  363. (const todo)
  364. (choice
  365. (const :tag "Any not-done state" todo)
  366. (const :tag "Any done state" done)
  367. (const :tag "Any state" any)
  368. (list :tag "Keyword list"
  369. (const :format "" quote)
  370. (repeat (string :tag "Keyword")))))
  371. (list :tag "TODO state is not" :inline t
  372. (const nottodo)
  373. (choice
  374. (const :tag "Any not-done state" todo)
  375. (const :tag "Any done state" done)
  376. (const :tag "Any state" any)
  377. (list :tag "Keyword list"
  378. (const :format "" quote)
  379. (repeat (string :tag "Keyword")))))
  380. (const :tag "scheduled" scheduled)
  381. (const :tag "not scheduled" notscheduled)
  382. (const :tag "deadline" deadline)
  383. (const :tag "no deadline" notdeadline)
  384. (const :tag "timestamp" timestamp)
  385. (const :tag "no timestamp" nottimestamp))))))
  386. (list :tag "Non-standard skipping condition"
  387. :value (org-agenda-skip-function)
  388. (const org-agenda-skip-function)
  389. (sexp :tag "Function or form (quoted!)"))
  390. (list :tag "Any variable"
  391. (variable :tag "Variable")
  392. (sexp :tag "Value (sexp)"))))
  393. "Selection of examples for agenda command settings.
  394. This will be spliced into the custom type of
  395. `org-agenda-custom-commands'.")
  396. (defcustom org-agenda-custom-commands
  397. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  398. "Custom commands for the agenda.
  399. \\<org-mode-map>
  400. These commands will be offered on the splash screen displayed by the
  401. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  402. (key desc type match settings files)
  403. key The key (one or more characters as a string) to be associated
  404. with the command.
  405. desc A description of the command, when omitted or nil, a default
  406. description is built using MATCH.
  407. type The command type, any of the following symbols:
  408. agenda The daily/weekly agenda.
  409. todo Entries with a specific TODO keyword, in all agenda files.
  410. search Entries containing search words entry or headline.
  411. tags Tags/Property/TODO match in all agenda files.
  412. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  413. todo-tree Sparse tree of specific TODO keyword in *current* file.
  414. tags-tree Sparse tree with all tags matches in *current* file.
  415. occur-tree Occur sparse tree for *current* file.
  416. ... A user-defined function.
  417. match What to search for:
  418. - a single keyword for TODO keyword searches
  419. - a tags match expression for tags searches
  420. - a word search expression for text searches.
  421. - a regular expression for occur searches
  422. For all other commands, this should be the empty string.
  423. settings A list of option settings, similar to that in a let form, so like
  424. this: ((opt1 val1) (opt2 val2) ...). The values will be
  425. evaluated at the moment of execution, so quote them when needed.
  426. files A list of files to write the produced agenda buffer to with
  427. the command `org-store-agenda-views'.
  428. If a file name ends in \".html\", an HTML version of the buffer
  429. is written out. If it ends in \".ps\", a postscript version is
  430. produced. Otherwise, only the plain text is written to the file.
  431. You can also define a set of commands, to create a composite agenda buffer.
  432. In this case, an entry looks like this:
  433. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  434. where
  435. desc A description string to be displayed in the dispatcher menu.
  436. cmd An agenda command, similar to the above. However, tree commands
  437. are not allowed, but instead you can get agenda and global todo list.
  438. So valid commands for a set are:
  439. (agenda \"\" settings)
  440. (alltodo \"\" settings)
  441. (stuck \"\" settings)
  442. (todo \"match\" settings files)
  443. (search \"match\" settings files)
  444. (tags \"match\" settings files)
  445. (tags-todo \"match\" settings files)
  446. Each command can carry a list of options, and another set of options can be
  447. given for the whole set of commands. Individual command options take
  448. precedence over the general options.
  449. When using several characters as key to a command, the first characters
  450. are prefix commands. For the dispatcher to display useful information, you
  451. should provide a description for the prefix, like
  452. (setq org-agenda-custom-commands
  453. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  454. (\"hl\" tags \"+HOME+Lisa\")
  455. (\"hp\" tags \"+HOME+Peter\")
  456. (\"hk\" tags \"+HOME+Kim\")))"
  457. :group 'org-agenda-custom-commands
  458. :type `(repeat
  459. (choice :value ("x" "Describe command here" tags "" nil)
  460. (list :tag "Single command"
  461. (string :tag "Access Key(s) ")
  462. (option (string :tag "Description"))
  463. (choice
  464. (const :tag "Agenda" agenda)
  465. (const :tag "TODO list" alltodo)
  466. (const :tag "Search words" search)
  467. (const :tag "Stuck projects" stuck)
  468. (const :tag "Tags/Property match (all agenda files)" tags)
  469. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  470. (const :tag "TODO keyword search (all agenda files)" todo)
  471. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  472. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  473. (const :tag "Occur tree (current buffer)" occur-tree)
  474. (sexp :tag "Other, user-defined function"))
  475. (string :tag "Match (only for some commands)")
  476. ,org-agenda-custom-commands-local-options
  477. (option (repeat :tag "Export" (file :tag "Export to"))))
  478. (list :tag "Command series, all agenda files"
  479. (string :tag "Access Key(s)")
  480. (string :tag "Description ")
  481. (repeat :tag "Component"
  482. (choice
  483. (list :tag "Agenda"
  484. (const :format "" agenda)
  485. (const :tag "" :format "" "")
  486. ,org-agenda-custom-commands-local-options)
  487. (list :tag "TODO list (all keywords)"
  488. (const :format "" alltodo)
  489. (const :tag "" :format "" "")
  490. ,org-agenda-custom-commands-local-options)
  491. (list :tag "Search words"
  492. (const :format "" search)
  493. (string :tag "Match")
  494. ,org-agenda-custom-commands-local-options)
  495. (list :tag "Stuck projects"
  496. (const :format "" stuck)
  497. (const :tag "" :format "" "")
  498. ,org-agenda-custom-commands-local-options)
  499. (list :tag "Tags search"
  500. (const :format "" tags)
  501. (string :tag "Match")
  502. ,org-agenda-custom-commands-local-options)
  503. (list :tag "Tags search, TODO entries only"
  504. (const :format "" tags-todo)
  505. (string :tag "Match")
  506. ,org-agenda-custom-commands-local-options)
  507. (list :tag "TODO keyword search"
  508. (const :format "" todo)
  509. (string :tag "Match")
  510. ,org-agenda-custom-commands-local-options)
  511. (list :tag "Other, user-defined function"
  512. (symbol :tag "function")
  513. (string :tag "Match")
  514. ,org-agenda-custom-commands-local-options)))
  515. (repeat :tag "Settings for entire command set"
  516. (list (variable :tag "Any variable")
  517. (sexp :tag "Value")))
  518. (option (repeat :tag "Export" (file :tag "Export to"))))
  519. (cons :tag "Prefix key documentation"
  520. (string :tag "Access Key(s)")
  521. (string :tag "Description ")))))
  522. (defcustom org-agenda-query-register ?o
  523. "The register holding the current query string.
  524. The purpose of this is that if you construct a query string interactively,
  525. you can then use it to define a custom command."
  526. :group 'org-agenda-custom-commands
  527. :type 'character)
  528. (defcustom org-stuck-projects
  529. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  530. "How to identify stuck projects.
  531. This is a list of four items:
  532. 1. A tags/todo/property matcher string that is used to identify a project.
  533. See the manual for a description of tag and property searches.
  534. The entire tree below a headline matched by this is considered one project.
  535. 2. A list of TODO keywords identifying non-stuck projects.
  536. If the project subtree contains any headline with one of these todo
  537. keywords, the project is considered to be not stuck. If you specify
  538. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  539. 3. A list of tags identifying non-stuck projects.
  540. If the project subtree contains any headline with one of these tags,
  541. the project is considered to be not stuck. If you specify \"*\" as
  542. a tag, any tag will mark the project unstuck. Note that this is about
  543. the explicit presence of a tag somewhere in the subtree, inherited
  544. tags do not count here. If inherited tags make a project not stuck,
  545. use \"-TAG\" in the tags part of the matcher under (1.) above.
  546. 4. An arbitrary regular expression matching non-stuck projects.
  547. If the project turns out to be not stuck, search continues also in the
  548. subtree to see if any of the subtasks have project status.
  549. See also the variable `org-tags-match-list-sublevels' which applies
  550. to projects matched by this search as well.
  551. After defining this variable, you may use `org-agenda-list-stuck-projects'
  552. \(bound to `\\[org-agenda] #') to produce the list."
  553. :group 'org-agenda-custom-commands
  554. :type '(list
  555. (string :tag "Tags/TODO match to identify a project")
  556. (repeat :tag "Projects are *not* stuck if they have an entry with \
  557. TODO keyword any of" (string))
  558. (repeat :tag "Projects are *not* stuck if they have an entry with \
  559. TAG being any of" (string))
  560. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  561. the subtree")))
  562. (defgroup org-agenda-skip nil
  563. "Options concerning skipping parts of agenda files."
  564. :tag "Org Agenda Skip"
  565. :group 'org-agenda)
  566. (defcustom org-agenda-skip-function-global nil
  567. "Function to be called at each match during agenda construction.
  568. If this function returns nil, the current match should not be skipped.
  569. If the function decided to skip an agenda match, is must return the
  570. buffer position from which the search should be continued.
  571. This may also be a Lisp form, which will be evaluated.
  572. This variable will be applied to every agenda match, including
  573. tags/property searches and TODO lists. So try to make the test function
  574. do its checking as efficiently as possible. To implement a skipping
  575. condition just for specific agenda commands, use the variable
  576. `org-agenda-skip-function' which can be set in the options section
  577. of custom agenda commands."
  578. :group 'org-agenda-skip
  579. :type 'sexp)
  580. (defgroup org-agenda-daily/weekly nil
  581. "Options concerning the daily/weekly agenda."
  582. :tag "Org Agenda Daily/Weekly"
  583. :group 'org-agenda)
  584. (defgroup org-agenda-todo-list nil
  585. "Options concerning the global todo list agenda view."
  586. :tag "Org Agenda Todo List"
  587. :group 'org-agenda)
  588. (defgroup org-agenda-match-view nil
  589. "Options concerning the general tags/property/todo match agenda view."
  590. :tag "Org Agenda Match View"
  591. :group 'org-agenda)
  592. (defgroup org-agenda-search-view nil
  593. "Options concerning the search agenda view."
  594. :tag "Org Agenda Search View"
  595. :group 'org-agenda)
  596. (defvar org-agenda-archives-mode nil
  597. "Non-nil means the agenda will include archived items.
  598. If this is the symbol `trees', trees in the selected agenda scope
  599. that are marked with the ARCHIVE tag will be included anyway. When this is
  600. t, also all archive files associated with the current selection of agenda
  601. files will be included.")
  602. (defcustom org-agenda-restriction-lock-highlight-subtree t
  603. "Non-nil means highlight the whole subtree when restriction is active.
  604. Otherwise only highlight the headline. Highlighting the whole subtree is
  605. useful to ensure no edits happen beyond the restricted region."
  606. :group 'org-agenda
  607. :type 'boolean)
  608. (defcustom org-agenda-skip-comment-trees t
  609. "Non-nil means skip trees that start with the COMMENT keyword.
  610. When nil, these trees are also scanned by agenda commands."
  611. :group 'org-agenda-skip
  612. :type 'boolean)
  613. (defcustom org-agenda-todo-list-sublevels t
  614. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  615. When nil, the sublevels of a TODO entry are not checked, resulting in
  616. potentially much shorter TODO lists."
  617. :group 'org-agenda-skip
  618. :group 'org-agenda-todo-list
  619. :type 'boolean)
  620. (defcustom org-agenda-todo-ignore-with-date nil
  621. "Non-nil means don't show entries with a date in the global todo list.
  622. You can use this if you prefer to mark mere appointments with a TODO keyword,
  623. but don't want them to show up in the TODO list.
  624. When this is set, it also covers deadlines and scheduled items, the settings
  625. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  626. will be ignored.
  627. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  628. :group 'org-agenda-skip
  629. :group 'org-agenda-todo-list
  630. :type 'boolean)
  631. (defcustom org-agenda-todo-ignore-timestamp nil
  632. "Non-nil means don't show entries with a timestamp.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. past Don't show entries for today or in the past.
  636. future Don't show entries with a timestamp in the future.
  637. The idea behind this is that if it has a future
  638. timestamp, you don't want to think about it until the
  639. date.
  640. all Don't show any entries with a timestamp in the global todo list.
  641. The idea behind this is that by setting a timestamp, you
  642. have already \"taken care\" of this item.
  643. This variable can also have an integer as a value. If positive (N),
  644. todos with a timestamp N or more days in the future will be ignored. If
  645. negative (-N), todos with a timestamp N or more days in the past will be
  646. ignored. If 0, todos with a timestamp either today or in the future will
  647. be ignored. For example, a value of -1 will exclude todos with a
  648. timestamp in the past (yesterday or earlier), while a value of 7 will
  649. exclude todos with a timestamp a week or more in the future.
  650. See also `org-agenda-todo-ignore-with-date'.
  651. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  652. to make his option also apply to the tags-todo list."
  653. :group 'org-agenda-skip
  654. :group 'org-agenda-todo-list
  655. :version "24.1"
  656. :type '(choice
  657. (const :tag "Ignore future timestamp todos" future)
  658. (const :tag "Ignore past or present timestamp todos" past)
  659. (const :tag "Ignore all timestamp todos" all)
  660. (const :tag "Show timestamp todos" nil)
  661. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  662. (defcustom org-agenda-todo-ignore-scheduled nil
  663. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  664. This applies when creating the global todo list.
  665. Valid values are:
  666. past Don't show entries scheduled today or in the past.
  667. future Don't show entries scheduled in the future.
  668. The idea behind this is that by scheduling it, you don't want to
  669. think about it until the scheduled date.
  670. all Don't show any scheduled entries in the global todo list.
  671. The idea behind this is that by scheduling it, you have already
  672. \"taken care\" of this item.
  673. t Same as `all', for backward compatibility.
  674. This variable can also have an integer as a value. See
  675. `org-agenda-todo-ignore-timestamp' for more details.
  676. See also `org-agenda-todo-ignore-with-date'.
  677. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  678. to make his option also apply to the tags-todo list."
  679. :group 'org-agenda-skip
  680. :group 'org-agenda-todo-list
  681. :type '(choice
  682. (const :tag "Ignore future-scheduled todos" future)
  683. (const :tag "Ignore past- or present-scheduled todos" past)
  684. (const :tag "Ignore all scheduled todos" all)
  685. (const :tag "Ignore all scheduled todos (compatibility)" t)
  686. (const :tag "Show scheduled todos" nil)
  687. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  688. (defcustom org-agenda-todo-ignore-deadlines nil
  689. "Non-nil means ignore some deadline TODO items when making TODO list.
  690. There are different motivations for using different values, please think
  691. carefully when configuring this variable.
  692. This applies when creating the global TODO list.
  693. Valid values are:
  694. near Don't show near deadline entries. A deadline is near when it is
  695. closer than `org-deadline-warning-days' days. The idea behind this
  696. is that such items will appear in the agenda anyway.
  697. far Don't show TODO entries where a deadline has been defined, but
  698. is not going to happen anytime soon. This is useful if you want to use
  699. the TODO list to figure out what to do now.
  700. past Don't show entries with a deadline timestamp for today or in the past.
  701. future Don't show entries with a deadline timestamp in the future, not even
  702. when they become `near' ones. Use it with caution.
  703. all Ignore all TODO entries that do have a deadline.
  704. t Same as `near', for backward compatibility.
  705. This variable can also have an integer as a value. See
  706. `org-agenda-todo-ignore-timestamp' for more details.
  707. See also `org-agenda-todo-ignore-with-date'.
  708. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  709. to make his option also apply to the tags-todo list."
  710. :group 'org-agenda-skip
  711. :group 'org-agenda-todo-list
  712. :type '(choice
  713. (const :tag "Ignore near deadlines" near)
  714. (const :tag "Ignore near deadlines (compatibility)" t)
  715. (const :tag "Ignore far deadlines" far)
  716. (const :tag "Ignore all TODOs with a deadlines" all)
  717. (const :tag "Show all TODOs, even if they have a deadline" nil)
  718. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  719. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  720. "Time unit to use when possibly ignoring an agenda item.
  721. See the docstring of various `org-agenda-todo-ignore-*' options.
  722. The default is to compare time stamps using days. An item is thus
  723. considered to be in the future if it is at least one day after today.
  724. Non-nil means to compare time stamps using seconds. An item is then
  725. considered future if it has a time value later than current time."
  726. :group 'org-agenda-skip
  727. :group 'org-agenda-todo-list
  728. :version "24.4"
  729. :package-version '(Org . "8.0")
  730. :type '(choice
  731. (const :tag "Compare time with days" nil)
  732. (const :tag "Compare time with seconds" t)))
  733. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  734. "Non-nil means honor todo-list ignores options also in tags-todo search.
  735. The variables
  736. `org-agenda-todo-ignore-with-date',
  737. `org-agenda-todo-ignore-timestamp',
  738. `org-agenda-todo-ignore-scheduled',
  739. `org-agenda-todo-ignore-deadlines'
  740. make the global TODO list skip entries that have time stamps of certain
  741. kinds. If this option is set, the same options will also apply for the
  742. tags-todo search, which is the general tags/property matcher
  743. restricted to unfinished TODO entries only."
  744. :group 'org-agenda-skip
  745. :group 'org-agenda-todo-list
  746. :group 'org-agenda-match-view
  747. :type 'boolean)
  748. (defcustom org-agenda-skip-scheduled-if-done nil
  749. "Non-nil means don't show scheduled items in agenda when they are done.
  750. This is relevant for the daily/weekly agenda, not for the TODO list. It
  751. applies only to the actual date of the scheduling. Warnings about an item
  752. with a past scheduling dates are always turned off when the item is DONE."
  753. :group 'org-agenda-skip
  754. :group 'org-agenda-daily/weekly
  755. :type 'boolean)
  756. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  757. "Non-nil means skip scheduling line if same entry shows because of deadline.
  758. In the agenda of today, an entry can show up multiple times
  759. because it is both scheduled and has a nearby deadline, and maybe
  760. a plain time stamp as well.
  761. When this variable is nil, the entry will be shown several times.
  762. When set to t, then only the deadline is shown and the fact that
  763. the entry is scheduled today or was scheduled previously is not
  764. shown.
  765. When set to the symbol `not-today', skip scheduled previously,
  766. but not scheduled today.
  767. When set to the symbol `repeated-after-deadline', skip scheduled
  768. items if they are repeated beyond the current deadline."
  769. :group 'org-agenda-skip
  770. :group 'org-agenda-daily/weekly
  771. :type '(choice
  772. (const :tag "Never" nil)
  773. (const :tag "Always" t)
  774. (const :tag "Not when scheduled today" not-today)
  775. (const :tag "When repeated past deadline" repeated-after-deadline)))
  776. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  777. "Non-nil means skip timestamp line if same entry shows because of deadline.
  778. In the agenda of today, an entry can show up multiple times
  779. because it has both a plain timestamp and has a nearby deadline.
  780. When this variable is t, then only the deadline is shown and the
  781. fact that the entry has a timestamp for or including today is not
  782. shown. When this variable is nil, the entry will be shown
  783. several times."
  784. :group 'org-agenda-skip
  785. :group 'org-agenda-daily/weekly
  786. :version "24.1"
  787. :type '(choice
  788. (const :tag "Never" nil)
  789. (const :tag "Always" t)))
  790. (defcustom org-agenda-skip-deadline-if-done nil
  791. "Non-nil means don't show deadlines when the corresponding item is done.
  792. When nil, the deadline is still shown and should give you a happy feeling.
  793. This is relevant for the daily/weekly agenda. It applies only to the
  794. actual date of the deadline. Warnings about approaching and past-due
  795. deadlines are always turned off when the item is DONE."
  796. :group 'org-agenda-skip
  797. :group 'org-agenda-daily/weekly
  798. :type 'boolean)
  799. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  800. "Non-nil means skip deadline prewarning when entry is also scheduled.
  801. This will apply on all days where a prewarning for the deadline would
  802. be shown, but not at the day when the entry is actually due. On that day,
  803. the deadline will be shown anyway.
  804. This variable may be set to nil, t, the symbol `pre-scheduled',
  805. or a number which will then give the number of days before the actual
  806. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  807. eliminates the deadline prewarning only prior to the scheduled date.
  808. This can be used in a workflow where the first showing of the deadline will
  809. trigger you to schedule it, and then you don't want to be reminded of it
  810. because you will take care of it on the day when scheduled."
  811. :group 'org-agenda-skip
  812. :group 'org-agenda-daily/weekly
  813. :version "24.1"
  814. :type '(choice
  815. (const :tag "Always show prewarning" nil)
  816. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  817. (const :tag "Remove prewarning if entry is scheduled" t)
  818. (integer :tag "Restart prewarning N days before deadline")))
  819. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  820. "Non-nil means skip scheduled delay when entry also has a deadline.
  821. This variable may be set to nil, t, the symbol `post-deadline',
  822. or a number which will then give the number of days after the actual
  823. scheduled date when the delay should expire. The symbol `post-deadline'
  824. eliminates the schedule delay when the date is posterior to the deadline."
  825. :group 'org-agenda-skip
  826. :group 'org-agenda-daily/weekly
  827. :version "24.4"
  828. :package-version '(Org . "8.0")
  829. :type '(choice
  830. (const :tag "Always honor delay" nil)
  831. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  832. (const :tag "Ignore delay if entry has a deadline" t)
  833. (integer :tag "Honor delay up until N days after the scheduled date")))
  834. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  835. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  836. When non-nil, after the search for timestamps has matched once in an
  837. entry, the rest of the entry will not be searched."
  838. :group 'org-agenda-skip
  839. :type 'boolean)
  840. (defcustom org-agenda-skip-timestamp-if-done nil
  841. "Non-nil means don't select item by timestamp or -range if it is DONE."
  842. :group 'org-agenda-skip
  843. :group 'org-agenda-daily/weekly
  844. :type 'boolean)
  845. (defcustom org-agenda-dim-blocked-tasks t
  846. "Non-nil means dim blocked tasks in the agenda display.
  847. This causes some overhead during agenda construction, but if you
  848. have turned on `org-enforce-todo-dependencies',
  849. `org-enforce-todo-checkbox-dependencies', or any other blocking
  850. mechanism, this will create useful feedback in the agenda.
  851. Instead of t, this variable can also have the value `invisible'.
  852. Then blocked tasks will be invisible and only become visible when
  853. they become unblocked. An exemption to this behavior is when a task is
  854. blocked because of unchecked checkboxes below it. Since checkboxes do
  855. not show up in the agenda views, making this task invisible you remove any
  856. trace from agenda views that there is something to do. Therefore, a task
  857. that is blocked because of checkboxes will never be made invisible, it
  858. will only be dimmed."
  859. :group 'org-agenda-daily/weekly
  860. :group 'org-agenda-todo-list
  861. :version "24.3"
  862. :type '(choice
  863. (const :tag "Do not dim" nil)
  864. (const :tag "Dim to a gray face" t)
  865. (const :tag "Make invisible" invisible)))
  866. (defgroup org-agenda-startup nil
  867. "Options concerning initial settings in the Agenda in Org Mode."
  868. :tag "Org Agenda Startup"
  869. :group 'org-agenda)
  870. (defcustom org-agenda-menu-show-matcher t
  871. "Non-nil means show the match string in the agenda dispatcher menu.
  872. When nil, the matcher string is not shown, but is put into the help-echo
  873. property so than moving the mouse over the command shows it.
  874. Setting it to nil is good if matcher strings are very long and/or if
  875. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  876. :group 'org-agenda
  877. :version "24.1"
  878. :type 'boolean)
  879. (defcustom org-agenda-menu-two-columns nil
  880. "Non-nil means, use two columns to show custom commands in the dispatcher.
  881. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  882. to nil."
  883. :group 'org-agenda
  884. :version "24.1"
  885. :type 'boolean)
  886. (defcustom org-agenda-finalize-hook nil
  887. "Hook run just before displaying an agenda buffer.
  888. The buffer is still writable when the hook is called.
  889. You can modify some of the buffer substrings but you should be
  890. extra careful not to modify the text properties of the agenda
  891. headlines as the agenda display heavily relies on them."
  892. :group 'org-agenda-startup
  893. :type 'hook)
  894. (defcustom org-agenda-mouse-1-follows-link nil
  895. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  896. A longer mouse click will still set point. Needs to be set
  897. before org.el is loaded."
  898. :group 'org-agenda-startup
  899. :type 'boolean)
  900. (defcustom org-agenda-start-with-follow-mode nil
  901. "The initial value of follow mode in a newly created agenda window."
  902. :group 'org-agenda-startup
  903. :type 'boolean)
  904. (defcustom org-agenda-follow-indirect nil
  905. "Non-nil means `org-agenda-follow-mode' displays only the
  906. current item's tree, in an indirect buffer."
  907. :group 'org-agenda
  908. :version "24.1"
  909. :type 'boolean)
  910. (defcustom org-agenda-show-outline-path t
  911. "Non-nil means show outline path in echo area after line motion."
  912. :group 'org-agenda-startup
  913. :type 'boolean)
  914. (defcustom org-agenda-start-with-entry-text-mode nil
  915. "The initial value of entry-text-mode in a newly created agenda window."
  916. :group 'org-agenda-startup
  917. :type 'boolean)
  918. (defcustom org-agenda-entry-text-maxlines 5
  919. "Number of text lines to be added when `E' is pressed in the agenda.
  920. Note that this variable only used during agenda display. To add entry text
  921. when exporting the agenda, configure the variable
  922. `org-agenda-add-entry-text-maxlines'."
  923. :group 'org-agenda
  924. :type 'integer)
  925. (defcustom org-agenda-entry-text-exclude-regexps nil
  926. "List of regular expressions to clean up entry text.
  927. The complete matches of all regular expressions in this list will be
  928. removed from entry text before it is shown in the agenda."
  929. :group 'org-agenda
  930. :type '(repeat (regexp)))
  931. (defcustom org-agenda-entry-text-leaders " > "
  932. "Text prepended to the entry text in agenda buffers."
  933. :version "24.4"
  934. :package-version '(Org . "8.0")
  935. :group 'org-agenda
  936. :type 'string)
  937. (defvar org-agenda-entry-text-cleanup-hook nil
  938. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  939. This cleanup is done in a temporary buffer, so the function may inspect and
  940. change the entire buffer.
  941. Some default stuff like drawers and scheduling/deadline dates will already
  942. have been removed when this is called, as will any matches for regular
  943. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  944. (defvar org-agenda-include-inactive-timestamps nil
  945. "Non-nil means include inactive time stamps in agenda.
  946. Dynamically scoped.")
  947. (defgroup org-agenda-windows nil
  948. "Options concerning the windows used by the Agenda in Org Mode."
  949. :tag "Org Agenda Windows"
  950. :group 'org-agenda)
  951. (defcustom org-agenda-window-setup 'reorganize-frame
  952. "How the agenda buffer should be displayed.
  953. Possible values for this option are:
  954. current-window Show agenda in the current window, keeping all other windows.
  955. other-window Use `switch-to-buffer-other-window' to display agenda.
  956. only-window Show agenda, deleting all other windows.
  957. reorganize-frame Show only two windows on the current frame, the current
  958. window and the agenda.
  959. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  960. Also, when exiting the agenda, kill that frame.
  961. See also the variable `org-agenda-restore-windows-after-quit'."
  962. :group 'org-agenda-windows
  963. :type '(choice
  964. (const current-window)
  965. (const other-frame)
  966. (const other-window)
  967. (const only-window)
  968. (const reorganize-frame)))
  969. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  970. "The min and max height of the agenda window as a fraction of frame height.
  971. The value of the variable is a cons cell with two numbers between 0 and 1.
  972. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  973. :group 'org-agenda-windows
  974. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  975. (defcustom org-agenda-restore-windows-after-quit nil
  976. "Non-nil means restore window configuration upon exiting agenda.
  977. Before the window configuration is changed for displaying the agenda,
  978. the current status is recorded. When the agenda is exited with
  979. `q' or `x' and this option is set, the old state is restored. If
  980. `org-agenda-window-setup' is `other-frame', the value of this
  981. option will be ignored."
  982. :group 'org-agenda-windows
  983. :type 'boolean)
  984. (defcustom org-agenda-span 'week
  985. "Number of days to include in overview display.
  986. Can be day, week, month, year, or any number of days.
  987. Custom commands can set this variable in the options section."
  988. :group 'org-agenda-daily/weekly
  989. :type '(choice (const :tag "Day" day)
  990. (const :tag "Week" week)
  991. (const :tag "Fortnight" fortnight)
  992. (const :tag "Month" month)
  993. (const :tag "Year" year)
  994. (integer :tag "Custom")))
  995. (defcustom org-agenda-start-on-weekday 1
  996. "Non-nil means start the overview always on the specified weekday.
  997. 0 denotes Sunday, 1 denotes Monday, etc.
  998. When nil, always start on the current day.
  999. Custom commands can set this variable in the options section."
  1000. :group 'org-agenda-daily/weekly
  1001. :type '(choice (const :tag "Today" nil)
  1002. (integer :tag "Weekday No.")))
  1003. (defcustom org-agenda-show-all-dates t
  1004. "Non-nil means `org-agenda' shows every day in the selected range.
  1005. When nil, only the days which actually have entries are shown."
  1006. :group 'org-agenda-daily/weekly
  1007. :type 'boolean)
  1008. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1009. "Format string for displaying dates in the agenda.
  1010. Used by the daily/weekly agenda. This should be a format string
  1011. understood by `format-time-string', or a function returning the
  1012. formatted date as a string. The function must take a single
  1013. argument, a calendar-style date list like (month day year)."
  1014. :group 'org-agenda-daily/weekly
  1015. :type '(choice
  1016. (string :tag "Format string")
  1017. (function :tag "Function")))
  1018. (defun org-agenda-format-date-aligned (date)
  1019. "Format a DATE string for display in the daily/weekly agenda.
  1020. This function makes sure that dates are aligned for easy reading."
  1021. (require 'cal-iso)
  1022. (let* ((dayname (calendar-day-name date))
  1023. (day (cadr date))
  1024. (day-of-week (calendar-day-of-week date))
  1025. (month (car date))
  1026. (monthname (calendar-month-name month))
  1027. (year (nth 2 date))
  1028. (iso-week (org-days-to-iso-week
  1029. (calendar-absolute-from-gregorian date)))
  1030. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1031. (1- year))
  1032. ((and (= month 12) (<= iso-week 1))
  1033. (1+ year))
  1034. (t year)))
  1035. (weekstring (if (= day-of-week 1)
  1036. (format " W%02d" iso-week)
  1037. "")))
  1038. (format "%-10s %2d %s %4d%s"
  1039. dayname day monthname year weekstring)))
  1040. (defcustom org-agenda-time-leading-zero nil
  1041. "Non-nil means use leading zero for military times in agenda.
  1042. For example, 9:30am would become 09:30 rather than 9:30."
  1043. :group 'org-agenda-daily/weekly
  1044. :version "24.1"
  1045. :type 'boolean)
  1046. (defcustom org-agenda-timegrid-use-ampm nil
  1047. "When set, show AM/PM style timestamps on the timegrid."
  1048. :group 'org-agenda
  1049. :version "24.1"
  1050. :type 'boolean)
  1051. (defun org-agenda-time-of-day-to-ampm (time)
  1052. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1053. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1054. (minute (substring time -2))
  1055. (ampm "am"))
  1056. (cond
  1057. ((equal hour-number 12)
  1058. (setq ampm "pm"))
  1059. ((> hour-number 12)
  1060. (setq ampm "pm")
  1061. (setq hour-number (- hour-number 12))))
  1062. (concat
  1063. (if org-agenda-time-leading-zero
  1064. (format "%02d" hour-number)
  1065. (format "%02s" (number-to-string hour-number)))
  1066. ":" minute ampm)))
  1067. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1068. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1069. (if org-agenda-timegrid-use-ampm
  1070. (org-agenda-time-of-day-to-ampm time)
  1071. time))
  1072. (defcustom org-agenda-weekend-days '(6 0)
  1073. "Which days are weekend?
  1074. These days get the special face `org-agenda-date-weekend' in the agenda."
  1075. :group 'org-agenda-daily/weekly
  1076. :type '(set :greedy t
  1077. (const :tag "Monday" 1)
  1078. (const :tag "Tuesday" 2)
  1079. (const :tag "Wednesday" 3)
  1080. (const :tag "Thursday" 4)
  1081. (const :tag "Friday" 5)
  1082. (const :tag "Saturday" 6)
  1083. (const :tag "Sunday" 0)))
  1084. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1085. "Non-nil means jump to today when moving a past date forward in time.
  1086. When using S-right in the agenda to move a a date forward, and the date
  1087. stamp currently points to the past, the first key press will move it
  1088. to today. When nil, just move one day forward even if the date stays
  1089. in the past."
  1090. :group 'org-agenda-daily/weekly
  1091. :version "24.1"
  1092. :type 'boolean)
  1093. (defcustom org-agenda-include-diary nil
  1094. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1095. Custom commands can set this variable in the options section."
  1096. :group 'org-agenda-daily/weekly
  1097. :type 'boolean)
  1098. (defcustom org-agenda-include-deadlines t
  1099. "If non-nil, include entries within their deadline warning period.
  1100. Custom commands can set this variable in the options section."
  1101. :group 'org-agenda-daily/weekly
  1102. :version "24.1"
  1103. :type 'boolean)
  1104. (defcustom org-agenda-show-future-repeats t
  1105. "Non-nil shows repeated entries in the future part of the agenda.
  1106. When set to the symbol `next' only the first future repeat is shown."
  1107. :group 'org-agenda-daily/weekly
  1108. :type '(choice
  1109. (const :tag "Show all repeated entries" t)
  1110. (const :tag "Show next repeated entry" next)
  1111. (const :tag "Do not show repeated entries" nil))
  1112. :version "26.1"
  1113. :package-version '(Org . "9.1")
  1114. :safe #'symbolp)
  1115. (defcustom org-agenda-prefer-last-repeat nil
  1116. "Non-nil sets date for repeated entries to their last repeat.
  1117. When nil, display SCHEDULED and DEADLINE dates at their base
  1118. date, and in today's agenda, as a reminder. Display plain
  1119. time-stamps, on the other hand, at every repeat date in the past
  1120. in addition to the base date.
  1121. When non-nil, show a repeated entry at its latest repeat date,
  1122. possibly being today even if it wasn't marked as done. This
  1123. setting is useful if you do not always mark repeated entries as
  1124. done and, yet, consider that reaching repeat date starts the task
  1125. anew.
  1126. When set to a list of strings, prefer last repeats only for
  1127. entries with these TODO keywords."
  1128. :group 'org-agenda-daily/weekly
  1129. :type '(choice
  1130. (const :tag "Prefer last repeat" t)
  1131. (const :tag "Prefer base date" nil)
  1132. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1133. (string :tag "TODO keyword")))
  1134. :version "26.1"
  1135. :package-version '(Org . "9.1")
  1136. :safe (lambda (x) (or (booleanp x) (consp x))))
  1137. (defcustom org-scheduled-past-days 10000
  1138. "Number of days to continue listing scheduled items not marked DONE.
  1139. When an item is scheduled on a date, it shows up in the agenda on
  1140. this day and will be listed until it is marked done or for the
  1141. number of days given here."
  1142. :group 'org-agenda-daily/weekly
  1143. :type 'integer
  1144. :safe 'integerp)
  1145. (defcustom org-deadline-past-days 10000
  1146. "Number of days to warn about missed deadlines.
  1147. When an item has deadline on a date, it shows up in the agenda on
  1148. this day and will appear as a reminder until it is marked DONE or
  1149. for the number of days given here."
  1150. :group 'org-agenda-daily/weekly
  1151. :type 'integer
  1152. :version "26.1"
  1153. :package-version '(Org . "9.1")
  1154. :safe 'integerp)
  1155. (defcustom org-agenda-log-mode-items '(closed clock)
  1156. "List of items that should be shown in agenda log mode.
  1157. \\<org-agenda-mode-map>\
  1158. This list may contain the following symbols:
  1159. closed Show entries that have been closed on that day.
  1160. clock Show entries that have received clocked time on that day.
  1161. state Show all logged state changes.
  1162. Note that instead of changing this variable, you can also press \
  1163. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1164. the agenda to display all available LOG items temporarily."
  1165. :group 'org-agenda-daily/weekly
  1166. :type '(set :greedy t (const closed) (const clock) (const state)))
  1167. (defcustom org-agenda-clock-consistency-checks
  1168. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1169. :gap-ok-around ("4:00")
  1170. :default-face ((:background "DarkRed") (:foreground "white"))
  1171. :overlap-face nil :gap-face nil :no-end-time-face nil
  1172. :long-face nil :short-face nil)
  1173. "This is a property list, with the following keys:
  1174. :max-duration Mark clocking chunks that are longer than this time.
  1175. This is a time string like \"HH:MM\", or the number
  1176. of minutes as an integer.
  1177. :min-duration Mark clocking chunks that are shorter that this.
  1178. This is a time string like \"HH:MM\", or the number
  1179. of minutes as an integer.
  1180. :max-gap Mark gaps between clocking chunks that are longer than
  1181. this duration. A number of minutes, or a string
  1182. like \"HH:MM\".
  1183. :gap-ok-around List of times during the day which are usually not working
  1184. times. When a gap is detected, but the gap contains any
  1185. of these times, the gap is *not* reported. For example,
  1186. if this is (\"4:00\" \"13:00\") then gaps that contain
  1187. 4:00 in the morning (i.e. the night) and 13:00
  1188. (i.e. a typical lunch time) do not cause a warning.
  1189. You should have at least one time during the night in this
  1190. list, or otherwise the first task each morning will trigger
  1191. a warning because it follows a long gap.
  1192. Furthermore, the following properties can be used to define faces for
  1193. issue display.
  1194. :default-face the default face, if the specific face is undefined
  1195. :overlap-face face for overlapping clocks
  1196. :gap-face face for gaps between clocks
  1197. :no-end-time-face face for incomplete clocks
  1198. :long-face face for clock intervals that are too long
  1199. :short-face face for clock intervals that are too short"
  1200. :group 'org-agenda-daily/weekly
  1201. :group 'org-clock
  1202. :version "24.1"
  1203. :type 'plist)
  1204. (defcustom org-agenda-log-mode-add-notes t
  1205. "Non-nil means add first line of notes to log entries in agenda views.
  1206. If a log item like a state change or a clock entry is associated with
  1207. notes, the first line of these notes will be added to the entry in the
  1208. agenda display."
  1209. :group 'org-agenda-daily/weekly
  1210. :type 'boolean)
  1211. (defcustom org-agenda-start-with-log-mode nil
  1212. "The initial value of log-mode in a newly created agenda window.
  1213. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1214. explanations on the possible values."
  1215. :group 'org-agenda-startup
  1216. :group 'org-agenda-daily/weekly
  1217. :type '(choice (const :tag "Don't show log items" nil)
  1218. (const :tag "Show only log items" only)
  1219. (const :tag "Show all possible log items" clockcheck)
  1220. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1221. (choice (const :tag "Show closed log items" closed)
  1222. (const :tag "Show clocked log items" clock)
  1223. (const :tag "Show all logged state changes" state)))))
  1224. (defcustom org-agenda-start-with-clockreport-mode nil
  1225. "The initial value of clockreport-mode in a newly created agenda window."
  1226. :group 'org-agenda-startup
  1227. :group 'org-agenda-daily/weekly
  1228. :type 'boolean)
  1229. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1230. "Property list with parameters for the clocktable in clockreport mode.
  1231. This is the display mode that shows a clock table in the daily/weekly
  1232. agenda, the properties for this dynamic block can be set here.
  1233. The usual clocktable parameters are allowed here, but you cannot set
  1234. the properties :name, :tstart, :tend, :block, and :scope - these will
  1235. be overwritten to make sure the content accurately reflects the
  1236. current display in the agenda."
  1237. :group 'org-agenda-daily/weekly
  1238. :type 'plist)
  1239. (defvaralias 'org-agenda-search-view-search-words-only
  1240. 'org-agenda-search-view-always-boolean)
  1241. (defcustom org-agenda-search-view-always-boolean nil
  1242. "Non-nil means the search string is interpreted as individual parts.
  1243. The search string for search view can either be interpreted as a phrase,
  1244. or as a list of snippets that define a boolean search for a number of
  1245. strings.
  1246. When this is non-nil, the string will be split on whitespace, and each
  1247. snippet will be searched individually, and all must match in order to
  1248. select an entry. A snippet is then a single string of non-white
  1249. characters, or a string in double quotes, or a regexp in {} braces.
  1250. If a snippet is preceded by \"-\", the snippet must *not* match.
  1251. \"+\" is syntactic sugar for positive selection. Each snippet may
  1252. be found as a full word or a partial word, but see the variable
  1253. `org-agenda-search-view-force-full-words'.
  1254. When this is nil, search will look for the entire search phrase as one,
  1255. with each space character matching any amount of whitespace, including
  1256. line breaks.
  1257. Even when this is nil, you can still switch to Boolean search dynamically
  1258. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1259. is a regexp marked with braces like \"{abc}\", this will also switch to
  1260. boolean search."
  1261. :group 'org-agenda-search-view
  1262. :version "24.1"
  1263. :type 'boolean)
  1264. (defcustom org-agenda-search-view-force-full-words nil
  1265. "Non-nil means, search words must be matches as complete words.
  1266. When nil, they may also match part of a word."
  1267. :group 'org-agenda-search-view
  1268. :version "24.1"
  1269. :type 'boolean)
  1270. (defcustom org-agenda-search-view-max-outline-level 0
  1271. "Maximum outline level to display in search view.
  1272. E.g. when this is set to 1, the search view will only
  1273. show headlines of level 1. When set to 0, the default
  1274. value, don't limit agenda view by outline level."
  1275. :group 'org-agenda-search-view
  1276. :version "26.1"
  1277. :package-version '(Org . "8.3")
  1278. :type 'integer)
  1279. (defgroup org-agenda-time-grid nil
  1280. "Options concerning the time grid in the Org Agenda."
  1281. :tag "Org Agenda Time Grid"
  1282. :group 'org-agenda)
  1283. (defcustom org-agenda-search-headline-for-time t
  1284. "Non-nil means search headline for a time-of-day.
  1285. If the headline contains a time-of-day in one format or another, it will
  1286. be used to sort the entry into the time sequence of items for a day.
  1287. Some people have time stamps in the headline that refer to the creation
  1288. time or so, and then this produces an unwanted side effect. If this is
  1289. the case for your, use this variable to turn off searching the headline
  1290. for a time."
  1291. :group 'org-agenda-time-grid
  1292. :type 'boolean)
  1293. (defcustom org-agenda-use-time-grid t
  1294. "Non-nil means show a time grid in the agenda schedule.
  1295. A time grid is a set of lines for specific times (like every two hours between
  1296. 8:00 and 20:00). The items scheduled for a day at specific times are
  1297. sorted in between these lines.
  1298. For details about when the grid will be shown, and what it will look like, see
  1299. the variable `org-agenda-time-grid'."
  1300. :group 'org-agenda-time-grid
  1301. :type 'boolean)
  1302. (defcustom org-agenda-time-grid
  1303. '((daily today require-timed)
  1304. (800 1000 1200 1400 1600 1800 2000)
  1305. "......"
  1306. "----------------")
  1307. "The settings for time grid for agenda display.
  1308. This is a list of four items. The first item is again a list. It contains
  1309. symbols specifying conditions when the grid should be displayed:
  1310. daily if the agenda shows a single day
  1311. weekly if the agenda shows an entire week
  1312. today show grid on current date, independent of daily/weekly display
  1313. require-timed show grid only if at least one item has a time specification
  1314. remove-match skip grid times already present in an entry
  1315. The second item is a list of integers, indicating the times that
  1316. should have a grid line.
  1317. The third item is a string which will be placed right after the
  1318. times that have a grid line.
  1319. The fourth item is a string placed after the grid times. This
  1320. will align with agenda items"
  1321. :group 'org-agenda-time-grid
  1322. :type
  1323. '(list
  1324. (set :greedy t :tag "Grid Display Options"
  1325. (const :tag "Show grid in single day agenda display" daily)
  1326. (const :tag "Show grid in weekly agenda display" weekly)
  1327. (const :tag "Always show grid for today" today)
  1328. (const :tag "Show grid only if any timed entries are present"
  1329. require-timed)
  1330. (const :tag "Skip grid times already present in an entry"
  1331. remove-match))
  1332. (repeat :tag "Grid Times" (integer :tag "Time"))
  1333. (string :tag "Grid String (after agenda times)")
  1334. (string :tag "Grid String (aligns with agenda items)")))
  1335. (defcustom org-agenda-show-current-time-in-grid t
  1336. "Non-nil means show the current time in the time grid."
  1337. :group 'org-agenda-time-grid
  1338. :version "24.1"
  1339. :type 'boolean)
  1340. (defcustom org-agenda-current-time-string
  1341. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1342. "The string for the current time marker in the agenda."
  1343. :group 'org-agenda-time-grid
  1344. :version "24.1"
  1345. :type 'string)
  1346. (defgroup org-agenda-sorting nil
  1347. "Options concerning sorting in the Org Agenda."
  1348. :tag "Org Agenda Sorting"
  1349. :group 'org-agenda)
  1350. (defcustom org-agenda-sorting-strategy
  1351. '((agenda habit-down time-up priority-down category-keep)
  1352. (todo priority-down category-keep)
  1353. (tags priority-down category-keep)
  1354. (search category-keep))
  1355. "Sorting structure for the agenda items of a single day.
  1356. This is a list of symbols which will be used in sequence to determine
  1357. if an entry should be listed before another entry. The following
  1358. symbols are recognized:
  1359. time-up Put entries with time-of-day indications first, early first
  1360. time-down Put entries with time-of-day indications first, late first
  1361. timestamp-up Sort by any timestamp, early first
  1362. timestamp-down Sort by any timestamp, late first
  1363. scheduled-up Sort by scheduled timestamp, early first
  1364. scheduled-down Sort by scheduled timestamp, late first
  1365. deadline-up Sort by deadline timestamp, early first
  1366. deadline-down Sort by deadline timestamp, late first
  1367. ts-up Sort by active timestamp, early first
  1368. ts-down Sort by active timestamp, late first
  1369. tsia-up Sort by inactive timestamp, early first
  1370. tsia-down Sort by inactive timestamp, late first
  1371. category-keep Keep the default order of categories, corresponding to the
  1372. sequence in `org-agenda-files'.
  1373. category-up Sort alphabetically by category, A-Z.
  1374. category-down Sort alphabetically by category, Z-A.
  1375. tag-up Sort alphabetically by last tag, A-Z.
  1376. tag-down Sort alphabetically by last tag, Z-A.
  1377. priority-up Sort numerically by priority, high priority last.
  1378. priority-down Sort numerically by priority, high priority first.
  1379. todo-state-up Sort by todo state, tasks that are done last.
  1380. todo-state-down Sort by todo state, tasks that are done first.
  1381. effort-up Sort numerically by estimated effort, high effort last.
  1382. effort-down Sort numerically by estimated effort, high effort first.
  1383. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1384. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1385. habit-up Put entries that are habits first
  1386. habit-down Put entries that are habits last
  1387. alpha-up Sort headlines alphabetically
  1388. alpha-down Sort headlines alphabetically, reversed
  1389. The different possibilities will be tried in sequence, and testing stops
  1390. if one comparison returns a \"not-equal\". For example, the default
  1391. '(time-up category-keep priority-down)
  1392. means: Pull out all entries having a specified time of day and sort them,
  1393. in order to make a time schedule for the current day the first thing in the
  1394. agenda listing for the day. Of the entries without a time indication, keep
  1395. the grouped in categories, don't sort the categories, but keep them in
  1396. the sequence given in `org-agenda-files'. Within each category sort by
  1397. priority.
  1398. Leaving out `category-keep' would mean that items will be sorted across
  1399. categories by priority.
  1400. Instead of a single list, this can also be a set of list for specific
  1401. contents, with a context symbol in the car of the list, any of
  1402. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1403. Custom commands can bind this variable in the options section."
  1404. :group 'org-agenda-sorting
  1405. :type `(choice
  1406. (repeat :tag "General" ,org-sorting-choice)
  1407. (list :tag "Individually"
  1408. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1409. (repeat ,org-sorting-choice))
  1410. (cons (const :tag "Strategy for TODO lists" todo)
  1411. (repeat ,org-sorting-choice))
  1412. (cons (const :tag "Strategy for Tags matches" tags)
  1413. (repeat ,org-sorting-choice))
  1414. (cons (const :tag "Strategy for search matches" search)
  1415. (repeat ,org-sorting-choice)))))
  1416. (defcustom org-agenda-cmp-user-defined nil
  1417. "A function to define the comparison `user-defined'.
  1418. This function must receive two arguments, agenda entry a and b.
  1419. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1420. the user comparison, return nil.
  1421. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1422. part of an agenda sorting strategy."
  1423. :group 'org-agenda-sorting
  1424. :type 'symbol)
  1425. (defcustom org-sort-agenda-notime-is-late t
  1426. "Non-nil means items without time are considered late.
  1427. This is only relevant for sorting. When t, items which have no explicit
  1428. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1429. do have a time. When nil, the default time is before 0:00. You can use this
  1430. option to decide if the schedule for today should come before or after timeless
  1431. agenda entries."
  1432. :group 'org-agenda-sorting
  1433. :type 'boolean)
  1434. (defcustom org-sort-agenda-noeffort-is-high t
  1435. "Non-nil means items without effort estimate are sorted as high effort.
  1436. This also applies when filtering an agenda view with respect to the
  1437. < or > effort operator. Then, tasks with no effort defined will be treated
  1438. as tasks with high effort.
  1439. When nil, such items are sorted as 0 minutes effort."
  1440. :group 'org-agenda-sorting
  1441. :type 'boolean)
  1442. (defgroup org-agenda-line-format nil
  1443. "Options concerning the entry prefix in the Org agenda display."
  1444. :tag "Org Agenda Line Format"
  1445. :group 'org-agenda)
  1446. (defcustom org-agenda-prefix-format
  1447. '((agenda . " %i %-12:c%?-12t% s")
  1448. (todo . " %i %-12:c")
  1449. (tags . " %i %-12:c")
  1450. (search . " %i %-12:c"))
  1451. "Format specifications for the prefix of items in the agenda views.
  1452. An alist with one entry per agenda type. The keys of the
  1453. sublists are `agenda', `todo', `search' and `tags'. The values
  1454. are format strings.
  1455. This format works similar to a printf format, with the following meaning:
  1456. %c the category of the item, \"Diary\" for entries from the diary,
  1457. or as given by the CATEGORY keyword or derived from the file name
  1458. %e the effort required by the item
  1459. %l the level of the item (insert X space(s) if item is of level X)
  1460. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1461. %T the last tag of the item (ignore inherited tags, which come first)
  1462. %t the HH:MM time-of-day specification if one applies to the entry
  1463. %s Scheduling/Deadline information, a short string
  1464. %b show breadcrumbs, i.e., the names of the higher levels
  1465. %(expression) Eval EXPRESSION and replace the control string
  1466. by the result
  1467. All specifiers work basically like the standard `%s' of printf, but may
  1468. contain two additional characters: a question mark just after the `%'
  1469. and a whitespace/punctuation character just before the final letter.
  1470. If the first character after `%' is a question mark, the entire field
  1471. will only be included if the corresponding value applies to the current
  1472. entry. This is useful for fields which should have fixed width when
  1473. present, but zero width when absent. For example, \"%?-12t\" will
  1474. result in a 12 character time field if a time of the day is specified,
  1475. but will completely disappear in entries which do not contain a time.
  1476. If there is punctuation or whitespace character just before the
  1477. final format letter, this character will be appended to the field
  1478. value if the value is not empty. For example, the format
  1479. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1480. the category is empty, no additional colon is inserted.
  1481. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1482. which means:
  1483. - Indent the line with two space characters
  1484. - Give the category a 12 chars wide field, padded with whitespace on
  1485. the right (because of `-'). Append a colon if there is a category
  1486. (because of `:').
  1487. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1488. time, don't put in an empty field, just skip it (because of '?').
  1489. - Finally, put the scheduling information.
  1490. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1491. `org-agenda-remove-tags'.
  1492. Custom commands can set this variable in the options section."
  1493. :type '(choice
  1494. (string :tag "General format")
  1495. (list :greedy t :tag "View dependent"
  1496. (cons (const agenda) (string :tag "Format"))
  1497. (cons (const todo) (string :tag "Format"))
  1498. (cons (const tags) (string :tag "Format"))
  1499. (cons (const search) (string :tag "Format"))))
  1500. :group 'org-agenda-line-format
  1501. :version "26.1"
  1502. :package-version '(Org . "9.1"))
  1503. (defvar org-prefix-format-compiled nil
  1504. "The compiled prefix format and associated variables.
  1505. This is a list where first element is a list of variable bindings, and second
  1506. element is the compiled format expression. See the variable
  1507. `org-agenda-prefix-format'.")
  1508. (defcustom org-agenda-todo-keyword-format "%-1s"
  1509. "Format for the TODO keyword in agenda lines.
  1510. Set this to something like \"%-12s\" if you want all TODO keywords
  1511. to occupy a fixed space in the agenda display."
  1512. :group 'org-agenda-line-format
  1513. :type 'string)
  1514. (defcustom org-agenda-diary-sexp-prefix nil
  1515. "A regexp that matches part of a diary sexp entry
  1516. which should be treated as scheduling/deadline information in
  1517. `org-agenda'.
  1518. For example, you can use this to extract the `diary-remind-message' from
  1519. `diary-remind' entries."
  1520. :group 'org-agenda-line-format
  1521. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1522. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1523. "Text preceding timerange entries in the agenda view.
  1524. This is a list with two strings. The first applies when the range
  1525. is entirely on one day. The second applies if the range spans several days.
  1526. The strings may have two \"%d\" format specifiers which will be filled
  1527. with the sequence number of the days, and the total number of days in the
  1528. range, respectively."
  1529. :group 'org-agenda-line-format
  1530. :type '(list
  1531. (string :tag "Deadline today ")
  1532. (choice :tag "Deadline relative"
  1533. (string :tag "Format string")
  1534. (function))))
  1535. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1536. "Text preceding scheduled items in the agenda view.
  1537. This is a list with two strings. The first applies when the item is
  1538. scheduled on the current day. The second applies when it has been scheduled
  1539. previously, it may contain a %d indicating that this is the nth time that
  1540. this item is scheduled, due to automatic rescheduling of unfinished items
  1541. for the following day. So this number is one larger than the number of days
  1542. that passed since this item was scheduled first."
  1543. :group 'org-agenda-line-format
  1544. :version "24.4"
  1545. :package-version '(Org . "8.0")
  1546. :type '(list
  1547. (string :tag "Scheduled today ")
  1548. (string :tag "Scheduled previously")))
  1549. (defcustom org-agenda-inactive-leader "["
  1550. "Text preceding item pulled into the agenda by inactive time stamps.
  1551. These entries are added to the agenda when pressing \"[\"."
  1552. :group 'org-agenda-line-format
  1553. :version "24.1"
  1554. :type 'string)
  1555. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1556. "Text preceding deadline items in the agenda view.
  1557. This is a list with three strings. The first applies when the item has its
  1558. deadline on the current day. The second applies when the deadline is in the
  1559. future, the third one when it is in the past. The strings may contain %d
  1560. to capture the number of days."
  1561. :group 'org-agenda-line-format
  1562. :version "24.4"
  1563. :package-version '(Org . "8.0")
  1564. :type '(list
  1565. (string :tag "Deadline today ")
  1566. (string :tag "Deadline in the future ")
  1567. (string :tag "Deadline in the past ")))
  1568. (defcustom org-agenda-remove-times-when-in-prefix t
  1569. "Non-nil means remove duplicate time specifications in agenda items.
  1570. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1571. time-of-day specification in a headline or diary entry is extracted and
  1572. placed into the prefix. If this option is non-nil, the original specification
  1573. \(a timestamp or -range, or just a plain time(range) specification like
  1574. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1575. cluttered.
  1576. The option can be t or nil. It may also be the symbol `beg', indicating
  1577. that the time should only be removed when it is located at the beginning of
  1578. the headline/diary entry."
  1579. :group 'org-agenda-line-format
  1580. :type '(choice
  1581. (const :tag "Always" t)
  1582. (const :tag "Never" nil)
  1583. (const :tag "When at beginning of entry" beg)))
  1584. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1585. "Non-nil means remove time ranges specifications in agenda
  1586. items that span on several days."
  1587. :group 'org-agenda-line-format
  1588. :version "24.1"
  1589. :type 'boolean)
  1590. (defcustom org-agenda-default-appointment-duration nil
  1591. "Default duration for appointments that only have a starting time.
  1592. When nil, no duration is specified in such cases.
  1593. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1594. :group 'org-agenda-line-format
  1595. :type '(choice
  1596. (integer :tag "Minutes")
  1597. (const :tag "No default duration")))
  1598. (defcustom org-agenda-show-inherited-tags t
  1599. "Non-nil means show inherited tags in each agenda line.
  1600. When this option is set to `always', it takes precedence over
  1601. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1602. in every agenda.
  1603. When this option is set to t (the default), inherited tags are
  1604. shown when they are available, i.e. when the value of
  1605. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1606. given agenda type.
  1607. This can be set to a list of agenda types in which the agenda
  1608. must display the inherited tags. Available types are `todo',
  1609. `agenda' and `search'.
  1610. When set to nil, never show inherited tags in agenda lines."
  1611. :group 'org-agenda-line-format
  1612. :group 'org-agenda
  1613. :version "24.3"
  1614. :type '(choice
  1615. (const :tag "Show inherited tags when available" t)
  1616. (const :tag "Always show inherited tags" always)
  1617. (repeat :tag "Show inherited tags only in selected agenda types"
  1618. (symbol :tag "Agenda type"))))
  1619. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1620. "List of agenda view types where to use tag inheritance.
  1621. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1622. controlled by `org-use-tag-inheritance'. In other agenda types,
  1623. `org-use-tag-inheritance' is not used for the selection of the
  1624. agenda entries. Still, you may want the agenda to be aware of
  1625. the inherited tags anyway, e.g. for later tag filtering.
  1626. Allowed value are `todo', `search' and `agenda'.
  1627. This variable has no effect if `org-agenda-show-inherited-tags'
  1628. is set to `always'. In that case, the agenda is aware of those
  1629. tags.
  1630. The default value sets tags in every agenda type. Setting this
  1631. option to nil will speed up non-tags agenda view a lot."
  1632. :group 'org-agenda
  1633. :version "26.1"
  1634. :package-version '(Org . "9.1")
  1635. :type '(choice
  1636. (const :tag "Use tag inheritance in all agenda types" t)
  1637. (repeat :tag "Use tag inheritance in selected agenda types"
  1638. (symbol :tag "Agenda type"))))
  1639. (defcustom org-agenda-hide-tags-regexp nil
  1640. "Regular expression used to filter away specific tags in agenda views.
  1641. This means that these tags will be present, but not be shown in the agenda
  1642. line. Secondary filtering will still work on the hidden tags.
  1643. Nil means don't hide any tags."
  1644. :group 'org-agenda-line-format
  1645. :type '(choice
  1646. (const :tag "Hide none" nil)
  1647. (string :tag "Regexp ")))
  1648. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1649. 'org-agenda-remove-tags)
  1650. (defcustom org-agenda-remove-tags nil
  1651. "Non-nil means remove the tags from the headline copy in the agenda.
  1652. When this is the symbol `prefix', only remove tags when
  1653. `org-agenda-prefix-format' contains a `%T' specifier."
  1654. :group 'org-agenda-line-format
  1655. :type '(choice
  1656. (const :tag "Always" t)
  1657. (const :tag "Never" nil)
  1658. (const :tag "When prefix format contains %T" prefix)))
  1659. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1660. (defcustom org-agenda-tags-column 'auto
  1661. "Shift tags in agenda items to this column.
  1662. If set to `auto', tags will be automatically aligned to the right
  1663. edge of the window.
  1664. If set to a positive number, tags will be left-aligned to that
  1665. column. If set to a negative number, tags will be right-aligned
  1666. to that column. For example, -80 works well for a normal 80
  1667. character screen."
  1668. :group 'org-agenda-line-format
  1669. :type '(choice
  1670. (const :tag "Automatically align to right edge of window" auto)
  1671. (integer :tag "Specific column" -80))
  1672. :package-version '(Org . "9.1")
  1673. :version "26.1")
  1674. (defcustom org-agenda-fontify-priorities 'cookies
  1675. "Non-nil means highlight low and high priorities in agenda.
  1676. When t, the highest priority entries are bold, lowest priority italic.
  1677. However, settings in `org-priority-faces' will overrule these faces.
  1678. When this variable is the symbol `cookies', only fontify the
  1679. cookies, not the entire task.
  1680. This may also be an association list of priority faces, whose
  1681. keys are the character values of `org-highest-priority',
  1682. `org-default-priority', and `org-lowest-priority' (the default values
  1683. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1684. color as a string, or a list like `(:background \"Red\")'.
  1685. If it is a color, the variable `org-faces-easy-properties'
  1686. determines if it is a foreground or a background color."
  1687. :group 'org-agenda-line-format
  1688. :type '(choice
  1689. (const :tag "Never" nil)
  1690. (const :tag "Defaults" t)
  1691. (const :tag "Cookies only" cookies)
  1692. (repeat :tag "Specify"
  1693. (list (character :tag "Priority" :value ?A)
  1694. (choice :tag "Face "
  1695. (string :tag "Color")
  1696. (sexp :tag "Face"))))))
  1697. (defcustom org-agenda-day-face-function nil
  1698. "Function called to determine what face should be used to display a day.
  1699. The only argument passed to that function is the day. It should
  1700. returns a face, or nil if does not want to specify a face and let
  1701. the normal rules apply."
  1702. :group 'org-agenda-line-format
  1703. :version "24.1"
  1704. :type '(choice (const nil) (function)))
  1705. (defcustom org-agenda-category-icon-alist nil
  1706. "Alist of category icon to be displayed in agenda views.
  1707. Each entry should have the following format:
  1708. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1709. Where CATEGORY-REGEXP is a regexp matching the categories where
  1710. the icon should be displayed.
  1711. FILE-OR-DATA either a file path or a string containing image data.
  1712. The other fields can be omitted safely if not needed:
  1713. TYPE indicates the image type.
  1714. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1715. image data.
  1716. PROPS are additional image attributes to assign to the image,
  1717. like, e.g. `:ascent center'.
  1718. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1719. If you want to set the display properties yourself, just put a
  1720. list as second element:
  1721. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1722. For example, to display a 16px horizontal space for Emacs
  1723. category, you can use:
  1724. (\"Emacs\" \\='(space . (:width (16))))"
  1725. :group 'org-agenda-line-format
  1726. :version "24.1"
  1727. :type '(alist :key-type (string :tag "Regexp matching category")
  1728. :value-type (choice (list :tag "Icon"
  1729. (string :tag "File or data")
  1730. (symbol :tag "Type")
  1731. (boolean :tag "Data?")
  1732. (repeat :tag "Extra image properties" :inline t symbol))
  1733. (list :tag "Display properties" sexp))))
  1734. (defgroup org-agenda-column-view nil
  1735. "Options concerning column view in the agenda."
  1736. :tag "Org Agenda Column View"
  1737. :group 'org-agenda)
  1738. (defcustom org-agenda-view-columns-initially nil
  1739. "When non-nil, switch to columns view right after creating the agenda."
  1740. :group 'org-agenda-column-view
  1741. :type 'boolean
  1742. :version "26.1"
  1743. :package-version '(Org . "9.0")
  1744. :safe #'booleanp)
  1745. (defcustom org-agenda-columns-show-summaries t
  1746. "Non-nil means show summaries for columns displayed in the agenda view."
  1747. :group 'org-agenda-column-view
  1748. :type 'boolean)
  1749. (defcustom org-agenda-columns-compute-summary-properties t
  1750. "Non-nil means recompute all summary properties before column view.
  1751. When column view in the agenda is listing properties that have a summary
  1752. operator, it can go to all relevant buffers and recompute the summaries
  1753. there. This can mean overhead for the agenda column view, but is necessary
  1754. to have thing up to date.
  1755. As a special case, a CLOCKSUM property also makes sure that the clock
  1756. computations are current."
  1757. :group 'org-agenda-column-view
  1758. :type 'boolean)
  1759. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1760. "Non-nil means the duration of an appointment will add to day effort.
  1761. The property to which appointment durations will be added is the one given
  1762. in the option `org-effort-property'. If an appointment does not have
  1763. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1764. is not set, an appointment without end time will not contribute to the time
  1765. estimate."
  1766. :group 'org-agenda-column-view
  1767. :type 'boolean)
  1768. (defcustom org-agenda-auto-exclude-function nil
  1769. "A function called with a tag to decide if it is filtered on \
  1770. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1771. The sole argument to the function, which is called once for each
  1772. possible tag, is a string giving the name of the tag. The
  1773. function should return either nil if the tag should be included
  1774. as normal, or \"-<TAG>\" to exclude the tag.
  1775. Note that for the purpose of tag filtering, only the lower-case version of
  1776. all tags will be considered, so that this function will only ever see
  1777. the lower-case version of all tags."
  1778. :group 'org-agenda
  1779. :type '(choice (const nil) (function)))
  1780. (defcustom org-agenda-bulk-custom-functions nil
  1781. "Alist of characters and custom functions for bulk actions.
  1782. For example, this value makes those two functions available:
  1783. \\='((?R set-category)
  1784. (?C bulk-cut))
  1785. With selected entries in an agenda buffer, `B R' will call
  1786. the custom function `set-category' on the selected entries.
  1787. Note that functions in this alist don't need to be quoted."
  1788. :type '(alist :key-type character :value-type (group function))
  1789. :version "24.1"
  1790. :group 'org-agenda)
  1791. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1792. "Execute BODY with point at location given by `org-hd-marker' property.
  1793. If STRING is non-nil, the text property will be fetched from position 0
  1794. in that string. If STRING is nil, it will be fetched from the beginning
  1795. of the current line."
  1796. (org-with-gensyms (marker)
  1797. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1798. 'org-hd-marker ,string)))
  1799. (with-current-buffer (marker-buffer ,marker)
  1800. (save-excursion
  1801. (goto-char ,marker)
  1802. ,@body)))))
  1803. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1804. (defun org-add-agenda-custom-command (entry)
  1805. "Replace or add a command in `org-agenda-custom-commands'.
  1806. This is mostly for hacking and trying a new command - once the command
  1807. works you probably want to add it to `org-agenda-custom-commands' for good."
  1808. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1809. (if ass
  1810. (setcdr ass (cdr entry))
  1811. (push entry org-agenda-custom-commands))))
  1812. (defmacro org-agenda--insert-overriding-header (default)
  1813. "Insert header into agenda view.
  1814. The inserted header depends on `org-agenda-overriding-header'.
  1815. If the empty string, don't insert a header. If any other string,
  1816. insert it as a header. If nil, insert DEFAULT, which should
  1817. evaluate to a string."
  1818. (declare (debug (form)) (indent defun))
  1819. `(cond
  1820. ((not org-agenda-overriding-header) (insert ,default))
  1821. ((equal org-agenda-overriding-header "") nil)
  1822. ((stringp org-agenda-overriding-header)
  1823. (insert (propertize org-agenda-overriding-header
  1824. 'face 'org-agenda-structure)
  1825. "\n"))
  1826. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1827. org-agenda-overriding-header))))
  1828. ;;; Define the org-agenda-mode
  1829. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1830. (defvar org-agenda-mode-map (make-sparse-keymap)
  1831. "Keymap for `org-agenda-mode'.")
  1832. (defvar org-agenda-menu) ; defined later in this file.
  1833. (defvar org-agenda-restrict nil) ; defined later in this file.
  1834. (defvar org-agenda-follow-mode nil)
  1835. (defvar org-agenda-entry-text-mode nil)
  1836. (defvar org-agenda-clockreport-mode nil)
  1837. (defvar org-agenda-show-log nil
  1838. "When non-nil, show the log in the agenda.
  1839. Do not set this directly; instead use
  1840. `org-agenda-start-with-log-mode', which see.")
  1841. (defvar org-agenda-redo-command nil)
  1842. (defvar org-agenda-query-string nil)
  1843. (defvar org-agenda-mode-hook nil
  1844. "Hook run after `org-agenda-mode' is turned on.
  1845. The buffer is still writable when this hook is called.")
  1846. (defvar org-agenda-type nil)
  1847. (defvar org-agenda-force-single-file nil)
  1848. (defvar org-agenda-bulk-marked-entries nil
  1849. "List of markers that refer to marked entries in the agenda.")
  1850. (defvar org-agenda-current-date nil
  1851. "Active date when building the agenda.")
  1852. ;;; Multiple agenda buffers support
  1853. (defcustom org-agenda-sticky nil
  1854. "Non-nil means agenda q key will bury agenda buffers.
  1855. Agenda commands will then show existing buffer instead of generating new ones.
  1856. When nil, `q' will kill the single agenda buffer."
  1857. :group 'org-agenda
  1858. :version "24.3"
  1859. :type 'boolean)
  1860. ;;;###autoload
  1861. (defun org-toggle-sticky-agenda (&optional arg)
  1862. "Toggle `org-agenda-sticky'."
  1863. (interactive "P")
  1864. (let ((new-value (if arg
  1865. (> (prefix-numeric-value arg) 0)
  1866. (not org-agenda-sticky))))
  1867. (if (equal new-value org-agenda-sticky)
  1868. (and (called-interactively-p 'interactive)
  1869. (message "Sticky agenda was already %s"
  1870. (if org-agenda-sticky "enabled" "disabled")))
  1871. (setq org-agenda-sticky new-value)
  1872. (org-agenda-kill-all-agenda-buffers)
  1873. (and (called-interactively-p 'interactive)
  1874. (message "Sticky agenda %s"
  1875. (if org-agenda-sticky "enabled" "disabled"))))))
  1876. (defvar org-agenda-buffer nil
  1877. "Agenda buffer currently being generated.")
  1878. (defvar org-agenda-last-prefix-arg nil)
  1879. (defvar org-agenda-this-buffer-name nil)
  1880. (defvar org-agenda-doing-sticky-redo nil)
  1881. (defvar org-agenda-this-buffer-is-sticky nil)
  1882. (defvar org-agenda-last-indirect-buffer nil
  1883. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1884. (defconst org-agenda-local-vars
  1885. '(org-agenda-this-buffer-name
  1886. org-agenda-undo-list
  1887. org-agenda-pending-undo-list
  1888. org-agenda-follow-mode
  1889. org-agenda-entry-text-mode
  1890. org-agenda-clockreport-mode
  1891. org-agenda-show-log
  1892. org-agenda-redo-command
  1893. org-agenda-query-string
  1894. org-agenda-type
  1895. org-agenda-bulk-marked-entries
  1896. org-agenda-undo-has-started-in
  1897. org-agenda-info
  1898. org-agenda-pre-window-conf
  1899. org-agenda-columns-active
  1900. org-agenda-tag-filter
  1901. org-agenda-category-filter
  1902. org-agenda-top-headline-filter
  1903. org-agenda-regexp-filter
  1904. org-agenda-effort-filter
  1905. org-agenda-markers
  1906. org-agenda-last-search-view-search-was-boolean
  1907. org-agenda-last-indirect-buffer
  1908. org-agenda-filtered-by-category
  1909. org-agenda-filter-form
  1910. org-agenda-cycle-counter
  1911. org-agenda-last-prefix-arg)
  1912. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1913. (defun org-agenda-mode ()
  1914. "Mode for time-sorted view on action items in Org files.
  1915. The following commands are available:
  1916. \\{org-agenda-mode-map}"
  1917. (interactive)
  1918. (let ((agenda-local-vars-to-keep
  1919. '(text-scale-mode-amount
  1920. text-scale-mode
  1921. text-scale-mode-lighter
  1922. face-remapping-alist))
  1923. (save (buffer-local-variables)))
  1924. (kill-all-local-variables)
  1925. (cl-flet ((reset-saved (var-set)
  1926. "Reset variables in VAR-SET to possibly stored value in SAVE."
  1927. (dolist (elem save)
  1928. (pcase elem
  1929. (`(,var . ,val) ;ignore unbound variables
  1930. (when (and val (memq var var-set))
  1931. (set var val)))))))
  1932. (cond (org-agenda-doing-sticky-redo
  1933. ;; Refreshing sticky agenda-buffer
  1934. ;;
  1935. ;; Preserve the value of `org-agenda-local-vars' variables.
  1936. (mapc #'make-local-variable org-agenda-local-vars)
  1937. (reset-saved org-agenda-local-vars)
  1938. (setq-local org-agenda-this-buffer-is-sticky t))
  1939. (org-agenda-sticky
  1940. ;; Creating a sticky Agenda buffer for the first time
  1941. (mapc 'make-local-variable org-agenda-local-vars)
  1942. (setq-local org-agenda-this-buffer-is-sticky t))
  1943. (t
  1944. ;; Creating a non-sticky agenda buffer
  1945. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1946. (mapc #'make-local-variable agenda-local-vars-to-keep)
  1947. (reset-saved agenda-local-vars-to-keep)))
  1948. (setq org-agenda-undo-list nil
  1949. org-agenda-pending-undo-list nil
  1950. org-agenda-bulk-marked-entries nil)
  1951. (setq major-mode 'org-agenda-mode)
  1952. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1953. (setq-local font-lock-global-modes (list 'not major-mode))
  1954. (setq mode-name "Org-Agenda")
  1955. (setq indent-tabs-mode nil)
  1956. (use-local-map org-agenda-mode-map)
  1957. (easy-menu-add org-agenda-menu)
  1958. (when org-startup-truncated (setq truncate-lines t))
  1959. (setq-local line-move-visual nil)
  1960. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1961. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1962. ;; Make sure properties are removed when copying text
  1963. (if (boundp 'filter-buffer-substring-functions)
  1964. (add-hook 'filter-buffer-substring-functions
  1965. (lambda (fun start end delete)
  1966. (substring-no-properties (funcall fun start end delete)))
  1967. nil t)
  1968. ;; Emacs >= 24.4.
  1969. (add-function :filter-return (local 'filter-buffer-substring-function)
  1970. #'substring-no-properties))
  1971. (unless org-agenda-keep-modes
  1972. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1973. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1974. org-agenda-show-log org-agenda-start-with-log-mode
  1975. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  1976. (add-to-invisibility-spec '(org-filtered))
  1977. (add-to-invisibility-spec '(org-link))
  1978. (easy-menu-change
  1979. '("Agenda") "Agenda Files"
  1980. (append
  1981. (list
  1982. (vector
  1983. (if (get 'org-agenda-files 'org-restrict)
  1984. "Restricted to single file"
  1985. "Edit File List")
  1986. '(org-edit-agenda-file-list)
  1987. (not (get 'org-agenda-files 'org-restrict)))
  1988. "--")
  1989. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1990. (org-agenda-set-mode-name)
  1991. (apply
  1992. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1993. (list 'org-agenda-mode-hook)))
  1994. (substitute-key-definition 'undo 'org-agenda-undo
  1995. org-agenda-mode-map global-map)
  1996. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1997. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1998. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1999. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  2000. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  2001. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  2002. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  2003. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  2004. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  2005. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  2006. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  2007. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  2008. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  2009. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  2010. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  2011. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  2012. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  2013. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  2014. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  2015. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  2016. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  2017. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  2018. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  2019. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  2020. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  2021. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  2022. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  2023. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  2024. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  2025. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  2026. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  2027. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  2028. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  2029. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  2030. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  2031. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  2032. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  2033. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  2034. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  2035. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  2036. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  2037. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  2038. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  2039. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  2040. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  2041. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  2042. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  2043. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  2044. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  2045. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  2046. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  2048. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  2049. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2050. (while l (org-defkey org-agenda-mode-map
  2051. (int-to-string (pop l)) 'digit-argument)))
  2052. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  2053. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  2054. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2055. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2056. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2057. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2058. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2059. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2060. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2061. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo-all)
  2062. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2063. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2064. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2065. 'org-clock-modify-effort-estimate)
  2066. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2067. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2068. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2069. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2070. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2071. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2072. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2073. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2074. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2075. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2076. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2077. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2078. (substitute-key-definition 'next-line 'org-agenda-next-line
  2079. org-agenda-mode-map global-map)
  2080. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2081. org-agenda-mode-map global-map)
  2082. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2083. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2084. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2085. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2086. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2087. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2088. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2089. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2090. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2091. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2092. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2093. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2094. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2095. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2096. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2097. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2099. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2100. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2101. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2102. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2103. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2104. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2105. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2106. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2107. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2108. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2109. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2110. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2111. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2112. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2113. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2114. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2115. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2116. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2117. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2118. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2119. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2120. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2121. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2122. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2123. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2124. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2125. (org-defkey org-agenda-mode-map "\C-c\C-x_" 'org-timer-stop)
  2126. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2127. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2128. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2129. (org-defkey org-agenda-mode-map "\C-c\C-xI" 'org-info-find-node)
  2130. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2131. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2132. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2133. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2134. (when org-agenda-mouse-1-follows-link
  2135. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2136. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2137. '("Agenda"
  2138. ("Agenda Files")
  2139. "--"
  2140. ("Agenda Dates"
  2141. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2142. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2143. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2144. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2145. "--"
  2146. ("View"
  2147. ["Day View" org-agenda-day-view
  2148. :active (org-agenda-check-type nil 'agenda)
  2149. :style radio :selected (eq org-agenda-current-span 'day)
  2150. :keys "v d (or just d)"]
  2151. ["Week View" org-agenda-week-view
  2152. :active (org-agenda-check-type nil 'agenda)
  2153. :style radio :selected (eq org-agenda-current-span 'week)
  2154. :keys "v w"]
  2155. ["Fortnight View" org-agenda-fortnight-view
  2156. :active (org-agenda-check-type nil 'agenda)
  2157. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2158. :keys "v t"]
  2159. ["Month View" org-agenda-month-view
  2160. :active (org-agenda-check-type nil 'agenda)
  2161. :style radio :selected (eq org-agenda-current-span 'month)
  2162. :keys "v m"]
  2163. ["Year View" org-agenda-year-view
  2164. :active (org-agenda-check-type nil 'agenda)
  2165. :style radio :selected (eq org-agenda-current-span 'year)
  2166. :keys "v y"]
  2167. "--"
  2168. ["Include Diary" org-agenda-toggle-diary
  2169. :style toggle :selected org-agenda-include-diary
  2170. :active (org-agenda-check-type nil 'agenda)]
  2171. ["Include Deadlines" org-agenda-toggle-deadlines
  2172. :style toggle :selected org-agenda-include-deadlines
  2173. :active (org-agenda-check-type nil 'agenda)]
  2174. ["Use Time Grid" org-agenda-toggle-time-grid
  2175. :style toggle :selected org-agenda-use-time-grid
  2176. :active (org-agenda-check-type nil 'agenda)]
  2177. "--"
  2178. ["Show clock report" org-agenda-clockreport-mode
  2179. :style toggle :selected org-agenda-clockreport-mode
  2180. :active (org-agenda-check-type nil 'agenda)]
  2181. ["Show some entry text" org-agenda-entry-text-mode
  2182. :style toggle :selected org-agenda-entry-text-mode
  2183. :active t]
  2184. "--"
  2185. ["Show Logbook entries" org-agenda-log-mode
  2186. :style toggle :selected org-agenda-show-log
  2187. :active (org-agenda-check-type nil 'agenda)
  2188. :keys "v l (or just l)"]
  2189. ["Include archived trees" org-agenda-archives-mode
  2190. :style toggle :selected org-agenda-archives-mode :active t
  2191. :keys "v a"]
  2192. ["Include archive files" (org-agenda-archives-mode t)
  2193. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2194. :keys "v A"]
  2195. "--"
  2196. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2197. ["Write view to file" org-agenda-write t]
  2198. ["Rebuild buffer" org-agenda-redo t]
  2199. ["Save all Org buffers" org-save-all-org-buffers t]
  2200. "--"
  2201. ["Show original entry" org-agenda-show t]
  2202. ["Go To (other window)" org-agenda-goto t]
  2203. ["Go To (this window)" org-agenda-switch-to t]
  2204. ["Capture with cursor date" org-agenda-capture t]
  2205. ["Follow Mode" org-agenda-follow-mode
  2206. :style toggle :selected org-agenda-follow-mode :active t]
  2207. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2208. "--"
  2209. ("TODO"
  2210. ["Cycle TODO" org-agenda-todo t]
  2211. ["Next TODO set" org-agenda-todo-nextset t]
  2212. ["Previous TODO set" org-agenda-todo-previousset t]
  2213. ["Add note" org-agenda-add-note t])
  2214. ("Archive/Refile/Delete"
  2215. ["Archive default" org-agenda-archive-default t]
  2216. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2217. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2218. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2219. ["Archive subtree" org-agenda-archive t]
  2220. "--"
  2221. ["Refile" org-agenda-refile t]
  2222. "--"
  2223. ["Delete subtree" org-agenda-kill t])
  2224. ("Bulk action"
  2225. ["Mark entry" org-agenda-bulk-mark t]
  2226. ["Mark all" org-agenda-bulk-mark-all t]
  2227. ["Unmark entry" org-agenda-bulk-unmark t]
  2228. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2229. ["Toggle mark" org-agenda-bulk-toggle t]
  2230. ["Toggle all" org-agenda-bulk-toggle-all t]
  2231. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2232. ["Act on all marked" org-agenda-bulk-action t]
  2233. "--"
  2234. ("Tags and Properties"
  2235. ["Show all Tags" org-agenda-show-tags t]
  2236. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2237. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2238. "--"
  2239. ["Column View" org-columns t])
  2240. ("Deadline/Schedule"
  2241. ["Schedule" org-agenda-schedule t]
  2242. ["Set Deadline" org-agenda-deadline t]
  2243. "--"
  2244. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2245. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2246. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2247. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2248. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2249. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2250. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2251. ("Clock and Effort"
  2252. ["Clock in" org-agenda-clock-in t]
  2253. ["Clock out" org-agenda-clock-out t]
  2254. ["Clock cancel" org-agenda-clock-cancel t]
  2255. ["Goto running clock" org-clock-goto t]
  2256. "--"
  2257. ["Set Effort" org-agenda-set-effort t]
  2258. ["Change clocked effort" org-clock-modify-effort-estimate
  2259. (org-clock-is-active)])
  2260. ("Priority"
  2261. ["Set Priority" org-agenda-priority t]
  2262. ["Increase Priority" org-agenda-priority-up t]
  2263. ["Decrease Priority" org-agenda-priority-down t]
  2264. ["Show Priority" org-show-priority t])
  2265. ("Calendar/Diary"
  2266. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2267. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2268. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2269. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2270. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2271. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2272. "--"
  2273. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2274. "--"
  2275. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2276. "--"
  2277. ("MobileOrg"
  2278. ["Push Files and Views" org-mobile-push t]
  2279. ["Get Captured and Flagged" org-mobile-pull t]
  2280. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2281. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2282. "--"
  2283. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2284. "--"
  2285. ["Quit" org-agenda-quit t]
  2286. ["Exit and Release Buffers" org-agenda-exit t]
  2287. ))
  2288. ;;; Agenda undo
  2289. (defvar org-agenda-allow-remote-undo t
  2290. "Non-nil means allow remote undo from the agenda buffer.")
  2291. (defvar org-agenda-undo-has-started-in nil
  2292. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2293. (defun org-agenda-undo ()
  2294. "Undo a remote editing step in the agenda.
  2295. This undoes changes both in the agenda buffer and in the remote buffer
  2296. that have been changed along."
  2297. (interactive)
  2298. (or org-agenda-allow-remote-undo
  2299. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2300. (when (not (eq this-command last-command))
  2301. (setq org-agenda-undo-has-started-in nil
  2302. org-agenda-pending-undo-list org-agenda-undo-list))
  2303. (when (not org-agenda-pending-undo-list)
  2304. (user-error "No further undo information"))
  2305. (let* ((entry (pop org-agenda-pending-undo-list))
  2306. buf line cmd rembuf)
  2307. (setq cmd (pop entry) line (pop entry))
  2308. (setq rembuf (nth 2 entry))
  2309. (org-with-remote-undo rembuf
  2310. (while (bufferp (setq buf (pop entry)))
  2311. (when (pop entry)
  2312. (with-current-buffer buf
  2313. (let ((last-undo-buffer buf)
  2314. (inhibit-read-only t))
  2315. (unless (memq buf org-agenda-undo-has-started-in)
  2316. (push buf org-agenda-undo-has-started-in)
  2317. (make-local-variable 'pending-undo-list)
  2318. (undo-start))
  2319. (while (and pending-undo-list
  2320. (listp pending-undo-list)
  2321. (not (car pending-undo-list)))
  2322. (pop pending-undo-list))
  2323. (undo-more 1))))))
  2324. (org-goto-line line)
  2325. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2326. (defun org-verify-change-for-undo (l1 l2)
  2327. "Verify that a real change occurred between the undo lists L1 and L2."
  2328. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2329. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2330. (not (eq l1 l2)))
  2331. ;;; Agenda dispatch
  2332. (defvar org-agenda-restrict-begin (make-marker))
  2333. (defvar org-agenda-restrict-end (make-marker))
  2334. (defvar org-agenda-last-dispatch-buffer nil)
  2335. (defvar org-agenda-overriding-restriction nil)
  2336. (defcustom org-agenda-custom-commands-contexts nil
  2337. "Alist of custom agenda keys and contextual rules.
  2338. For example, if you have a custom agenda command \"p\" and you
  2339. want this command to be accessible only from plain text files,
  2340. use this:
  2341. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2342. Here are the available contexts definitions:
  2343. in-file: command displayed only in matching files
  2344. in-mode: command displayed only in matching modes
  2345. not-in-file: command not displayed in matching files
  2346. not-in-mode: command not displayed in matching modes
  2347. in-buffer: command displayed only in matching buffers
  2348. not-in-buffer: command not displayed in matching buffers
  2349. [function]: a custom function taking no argument
  2350. If you define several checks, the agenda command will be
  2351. accessible if there is at least one valid check.
  2352. You can also bind a key to another agenda custom command
  2353. depending on contextual rules.
  2354. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2355. Here it means: in .txt files, use \"p\" as the key for the
  2356. agenda command otherwise associated with \"q\". (The command
  2357. originally associated with \"q\" is not displayed to avoid
  2358. duplicates.)"
  2359. :version "24.3"
  2360. :group 'org-agenda-custom-commands
  2361. :type '(repeat (list :tag "Rule"
  2362. (string :tag " Agenda key")
  2363. (string :tag "Replace by command")
  2364. (repeat :tag "Available when"
  2365. (choice
  2366. (cons :tag "Condition"
  2367. (choice
  2368. (const :tag "In file" in-file)
  2369. (const :tag "Not in file" not-in-file)
  2370. (const :tag "In buffer" in-buffer)
  2371. (const :tag "Not in buffer" not-in-buffer)
  2372. (const :tag "In mode" in-mode)
  2373. (const :tag "Not in mode" not-in-mode))
  2374. (regexp))
  2375. (function :tag "Custom function"))))))
  2376. (defcustom org-agenda-max-entries nil
  2377. "Maximum number of entries to display in an agenda.
  2378. This can be nil (no limit) or an integer or an alist of agenda
  2379. types with an associated number of entries to display in this
  2380. type."
  2381. :version "24.4"
  2382. :package-version '(Org . "8.0")
  2383. :group 'org-agenda-custom-commands
  2384. :type '(choice (symbol :tag "No limit" nil)
  2385. (integer :tag "Max number of entries")
  2386. (repeat
  2387. (cons (choice :tag "Agenda type"
  2388. (const agenda)
  2389. (const todo)
  2390. (const tags)
  2391. (const search))
  2392. (integer :tag "Max number of entries")))))
  2393. (defcustom org-agenda-max-todos nil
  2394. "Maximum number of TODOs to display in an agenda.
  2395. This can be nil (no limit) or an integer or an alist of agenda
  2396. types with an associated number of entries to display in this
  2397. type."
  2398. :version "24.4"
  2399. :package-version '(Org . "8.0")
  2400. :group 'org-agenda-custom-commands
  2401. :type '(choice (symbol :tag "No limit" nil)
  2402. (integer :tag "Max number of TODOs")
  2403. (repeat
  2404. (cons (choice :tag "Agenda type"
  2405. (const agenda)
  2406. (const todo)
  2407. (const tags)
  2408. (const search))
  2409. (integer :tag "Max number of TODOs")))))
  2410. (defcustom org-agenda-max-tags nil
  2411. "Maximum number of tagged entries to display in an agenda.
  2412. This can be nil (no limit) or an integer or an alist of agenda
  2413. types with an associated number of entries to display in this
  2414. type."
  2415. :version "24.4"
  2416. :package-version '(Org . "8.0")
  2417. :group 'org-agenda-custom-commands
  2418. :type '(choice (symbol :tag "No limit" nil)
  2419. (integer :tag "Max number of tagged entries")
  2420. (repeat
  2421. (cons (choice :tag "Agenda type"
  2422. (const agenda)
  2423. (const todo)
  2424. (const tags)
  2425. (const search))
  2426. (integer :tag "Max number of tagged entries")))))
  2427. (defcustom org-agenda-max-effort nil
  2428. "Maximum cumulated effort duration for the agenda.
  2429. This can be nil (no limit) or a number of minutes (as an integer)
  2430. or an alist of agenda types with an associated number of minutes
  2431. to limit entries to in this type."
  2432. :version "24.4"
  2433. :package-version '(Org . "8.0")
  2434. :group 'org-agenda-custom-commands
  2435. :type '(choice (symbol :tag "No limit" nil)
  2436. (integer :tag "Max number of minutes")
  2437. (repeat
  2438. (cons (choice :tag "Agenda type"
  2439. (const agenda)
  2440. (const todo)
  2441. (const tags)
  2442. (const search))
  2443. (integer :tag "Max number of minutes")))))
  2444. (defvar org-agenda-keep-restricted-file-list nil)
  2445. (defvar org-keys nil)
  2446. (defvar org-match nil)
  2447. ;;;###autoload
  2448. (defun org-agenda (&optional arg org-keys restriction)
  2449. "Dispatch agenda commands to collect entries to the agenda buffer.
  2450. Prompts for a command to execute. Any prefix arg will be passed
  2451. on to the selected command. The default selections are:
  2452. a Call `org-agenda-list' to display the agenda for current day or week.
  2453. t Call `org-todo-list' to display the global todo list.
  2454. T Call `org-todo-list' to display the global todo list, select only
  2455. entries with a specific TODO keyword (the user gets a prompt).
  2456. m Call `org-tags-view' to display headlines with tags matching
  2457. a condition (the user is prompted for the condition).
  2458. M Like `m', but select only TODO entries, no ordinary headlines.
  2459. e Export views to associated files.
  2460. s Search entries for keywords.
  2461. S Search entries for keywords, only with TODO keywords.
  2462. / Multi occur across all agenda files and also files listed
  2463. in `org-agenda-text-search-extra-files'.
  2464. < Restrict agenda commands to buffer, subtree, or region.
  2465. Press several times to get the desired effect.
  2466. > Remove a previous restriction.
  2467. # List \"stuck\" projects.
  2468. ! Configure what \"stuck\" means.
  2469. C Configure custom agenda commands.
  2470. More commands can be added by configuring the variable
  2471. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2472. searches can be pre-defined in this way.
  2473. If the current buffer is in Org mode and visiting a file, you can also
  2474. first press `<' once to indicate that the agenda should be temporarily
  2475. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2476. Pressing `<' twice means to restrict to the current subtree or region
  2477. \(if active)."
  2478. (interactive "P")
  2479. (catch 'exit
  2480. (let* ((prefix-descriptions nil)
  2481. (org-agenda-buffer-name org-agenda-buffer-name)
  2482. (org-agenda-window-setup (if (equal (buffer-name)
  2483. org-agenda-buffer-name)
  2484. 'current-window
  2485. org-agenda-window-setup))
  2486. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2487. (org-agenda-custom-commands
  2488. ;; normalize different versions
  2489. (delq nil
  2490. (mapcar
  2491. (lambda (x)
  2492. (cond ((stringp (cdr x))
  2493. (push x prefix-descriptions)
  2494. nil)
  2495. ((stringp (nth 1 x)) x)
  2496. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2497. (t (cons (car x) (cons "" (cdr x))))))
  2498. org-agenda-custom-commands)))
  2499. (org-agenda-custom-commands
  2500. (org-contextualize-keys
  2501. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2502. (buf (current-buffer))
  2503. (bfn (buffer-file-name (buffer-base-buffer)))
  2504. entry key type org-match lprops ans)
  2505. ;; Turn off restriction unless there is an overriding one,
  2506. (unless org-agenda-overriding-restriction
  2507. (unless org-agenda-keep-restricted-file-list
  2508. ;; There is a request to keep the file list in place
  2509. (put 'org-agenda-files 'org-restrict nil))
  2510. (setq org-agenda-restrict nil)
  2511. (move-marker org-agenda-restrict-begin nil)
  2512. (move-marker org-agenda-restrict-end nil))
  2513. ;; Delete old local properties
  2514. (put 'org-agenda-redo-command 'org-lprops nil)
  2515. ;; Delete previously set last-arguments
  2516. (put 'org-agenda-redo-command 'last-args nil)
  2517. ;; Remember where this call originated
  2518. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2519. (unless org-keys
  2520. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2521. org-keys (car ans)
  2522. restriction (cdr ans)))
  2523. ;; If we have sticky agenda buffers, set a name for the buffer,
  2524. ;; depending on the invoking keys. The user may still set this
  2525. ;; as a command option, which will overwrite what we do here.
  2526. (when org-agenda-sticky
  2527. (setq org-agenda-buffer-name
  2528. (format "*Org Agenda(%s)*" org-keys)))
  2529. ;; Establish the restriction, if any
  2530. (when (and (not org-agenda-overriding-restriction) restriction)
  2531. (put 'org-agenda-files 'org-restrict (list bfn))
  2532. (cond
  2533. ((eq restriction 'region)
  2534. (setq org-agenda-restrict (current-buffer))
  2535. (move-marker org-agenda-restrict-begin (region-beginning))
  2536. (move-marker org-agenda-restrict-end (region-end)))
  2537. ((eq restriction 'subtree)
  2538. (save-excursion
  2539. (setq org-agenda-restrict (current-buffer))
  2540. (org-back-to-heading t)
  2541. (move-marker org-agenda-restrict-begin (point))
  2542. (move-marker org-agenda-restrict-end
  2543. (progn (org-end-of-subtree t)))))))
  2544. ;; For example the todo list should not need it (but does...)
  2545. (cond
  2546. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2547. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2548. (progn
  2549. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2550. lprops (nth 4 entry))
  2551. (when org-agenda-sticky
  2552. (setq org-agenda-buffer-name
  2553. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2554. (format "*Org Agenda(%s)*" org-keys))))
  2555. (put 'org-agenda-redo-command 'org-lprops lprops)
  2556. (cond
  2557. ((eq type 'agenda)
  2558. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2559. ((eq type 'agenda*)
  2560. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2561. ((eq type 'alltodo)
  2562. (org-let lprops '(org-todo-list current-prefix-arg)))
  2563. ((eq type 'search)
  2564. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2565. ((eq type 'stuck)
  2566. (org-let lprops '(org-agenda-list-stuck-projects
  2567. current-prefix-arg)))
  2568. ((eq type 'tags)
  2569. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2570. ((eq type 'tags-todo)
  2571. (org-let lprops '(org-tags-view '(4) org-match)))
  2572. ((eq type 'todo)
  2573. (org-let lprops '(org-todo-list org-match)))
  2574. ((eq type 'tags-tree)
  2575. (org-check-for-org-mode)
  2576. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2577. ((eq type 'todo-tree)
  2578. (org-check-for-org-mode)
  2579. (org-let lprops
  2580. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2581. (regexp-quote org-match) "\\>"))))
  2582. ((eq type 'occur-tree)
  2583. (org-check-for-org-mode)
  2584. (org-let lprops '(org-occur org-match)))
  2585. ((functionp type)
  2586. (org-let lprops '(funcall type org-match)))
  2587. ((fboundp type)
  2588. (org-let lprops '(funcall type org-match)))
  2589. (t (user-error "Invalid custom agenda command type %s" type))))
  2590. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2591. ((equal org-keys "C")
  2592. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2593. (customize-variable 'org-agenda-custom-commands))
  2594. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2595. ((equal org-keys "s") (call-interactively 'org-search-view))
  2596. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2597. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2598. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2599. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2600. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2601. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2602. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2603. (add-hook
  2604. 'post-command-hook
  2605. (lambda ()
  2606. (unless (current-message)
  2607. (let* ((m (org-agenda-get-any-marker))
  2608. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2609. (when note
  2610. (message "FLAGGING-NOTE ([?] for more info): %s"
  2611. (org-add-props
  2612. (replace-regexp-in-string
  2613. "\\\\n" "//"
  2614. (copy-sequence note))
  2615. nil 'face 'org-warning))))))
  2616. t t))
  2617. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2618. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2619. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2620. (t (user-error "Invalid agenda key"))))))
  2621. (defvar org-agenda-multi)
  2622. (defun org-agenda-append-agenda ()
  2623. "Append another agenda view to the current one.
  2624. This function allows interactive building of block agendas.
  2625. Agenda views are separated by `org-agenda-block-separator'."
  2626. (interactive)
  2627. (unless (derived-mode-p 'org-agenda-mode)
  2628. (user-error "Can only append from within agenda buffer"))
  2629. (let ((org-agenda-multi t))
  2630. (org-agenda)
  2631. (widen)
  2632. (org-agenda-finalize)
  2633. (setq buffer-read-only t)
  2634. (org-agenda-fit-window-to-buffer)))
  2635. (defun org-agenda-normalize-custom-commands (cmds)
  2636. "Normalize custom commands CMDS."
  2637. (delq nil
  2638. (mapcar
  2639. (lambda (x)
  2640. (cond ((stringp (cdr x)) nil)
  2641. ((stringp (nth 1 x)) x)
  2642. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2643. (t (cons (car x) (cons "" (cdr x))))))
  2644. cmds)))
  2645. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2646. "The user interface for selecting an agenda command."
  2647. (catch 'exit
  2648. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2649. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2650. (region-p (org-region-active-p))
  2651. (custom org-agenda-custom-commands)
  2652. (selstring "")
  2653. restriction second-time
  2654. c entry key type match prefixes rmheader header-end custom1 desc
  2655. line lines left right n n1)
  2656. (save-window-excursion
  2657. (delete-other-windows)
  2658. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2659. (erase-buffer)
  2660. (insert (eval-when-compile
  2661. (let ((header
  2662. "Press key for an agenda command:
  2663. -------------------------------- < Buffer, subtree/region restriction
  2664. a Agenda for current week or day > Remove restriction
  2665. t List of all TODO entries e Export agenda views
  2666. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2667. s Search for keywords M Like m, but only TODO entries
  2668. / Multi-occur S Like s, but only TODO entries
  2669. ? Find :FLAGGED: entries C Configure custom agenda commands
  2670. * Toggle sticky agenda views # List stuck projects (!=configure)
  2671. ")
  2672. (start 0))
  2673. (while (string-match
  2674. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2675. header start)
  2676. (setq start (match-end 0))
  2677. (add-text-properties (match-beginning 2) (match-end 2)
  2678. '(face bold) header))
  2679. header)))
  2680. (setq header-end (point-marker))
  2681. (while t
  2682. (setq custom1 custom)
  2683. (when (eq rmheader t)
  2684. (org-goto-line 1)
  2685. (re-search-forward ":" nil t)
  2686. (delete-region (match-end 0) (point-at-eol))
  2687. (forward-char 1)
  2688. (looking-at "-+")
  2689. (delete-region (match-end 0) (point-at-eol))
  2690. (move-marker header-end (match-end 0)))
  2691. (goto-char header-end)
  2692. (delete-region (point) (point-max))
  2693. ;; Produce all the lines that describe custom commands and prefixes
  2694. (setq lines nil)
  2695. (while (setq entry (pop custom1))
  2696. (setq key (car entry) desc (nth 1 entry)
  2697. type (nth 2 entry)
  2698. match (nth 3 entry))
  2699. (if (> (length key) 1)
  2700. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2701. (setq line
  2702. (format
  2703. "%-4s%-14s"
  2704. (org-add-props (copy-sequence key)
  2705. '(face bold))
  2706. (cond
  2707. ((string-match "\\S-" desc) desc)
  2708. ((eq type 'agenda) "Agenda for current week or day")
  2709. ((eq type 'agenda*) "Appointments for current week or day")
  2710. ((eq type 'alltodo) "List of all TODO entries")
  2711. ((eq type 'search) "Word search")
  2712. ((eq type 'stuck) "List of stuck projects")
  2713. ((eq type 'todo) "TODO keyword")
  2714. ((eq type 'tags) "Tags query")
  2715. ((eq type 'tags-todo) "Tags (TODO)")
  2716. ((eq type 'tags-tree) "Tags tree")
  2717. ((eq type 'todo-tree) "TODO kwd tree")
  2718. ((eq type 'occur-tree) "Occur tree")
  2719. ((functionp type) (if (symbolp type)
  2720. (symbol-name type)
  2721. "Lambda expression"))
  2722. (t "???"))))
  2723. (cond
  2724. ((not (org-string-nw-p match)) nil)
  2725. (org-agenda-menu-show-matcher
  2726. (setq line
  2727. (concat line ": "
  2728. (cond
  2729. ((stringp match)
  2730. (propertize match 'face 'org-warning))
  2731. ((listp type)
  2732. (format "set of %d commands" (length type)))))))
  2733. (t
  2734. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2735. (push line lines)))
  2736. (setq lines (nreverse lines))
  2737. (when prefixes
  2738. (mapc (lambda (x)
  2739. (push
  2740. (format "%s %s"
  2741. (org-add-props (char-to-string x)
  2742. nil 'face 'bold)
  2743. (or (cdr (assoc (concat selstring
  2744. (char-to-string x))
  2745. prefix-descriptions))
  2746. "Prefix key"))
  2747. lines))
  2748. prefixes))
  2749. ;; Check if we should display in two columns
  2750. (if org-agenda-menu-two-columns
  2751. (progn
  2752. (setq n (length lines)
  2753. n1 (+ (/ n 2) (mod n 2))
  2754. right (nthcdr n1 lines)
  2755. left (copy-sequence lines))
  2756. (setcdr (nthcdr (1- n1) left) nil))
  2757. (setq left lines right nil))
  2758. (while left
  2759. (insert "\n" (pop left))
  2760. (when right
  2761. (if (< (current-column) 40)
  2762. (move-to-column 40 t)
  2763. (insert " "))
  2764. (insert (pop right))))
  2765. ;; Make the window the right size
  2766. (goto-char (point-min))
  2767. (if second-time
  2768. (when (not (pos-visible-in-window-p (point-max)))
  2769. (org-fit-window-to-buffer))
  2770. (setq second-time t)
  2771. (org-fit-window-to-buffer))
  2772. ;; Ask for selection
  2773. (message "Press key for agenda command%s:"
  2774. (if (or restrict-ok org-agenda-overriding-restriction)
  2775. (if org-agenda-overriding-restriction
  2776. " (restriction lock active)"
  2777. (if restriction
  2778. (format " (restricted to %s)" restriction)
  2779. " (unrestricted)"))
  2780. ""))
  2781. (setq c (read-char-exclusive))
  2782. (message "")
  2783. (cond
  2784. ((assoc (char-to-string c) custom)
  2785. (setq selstring (concat selstring (char-to-string c)))
  2786. (throw 'exit (cons selstring restriction)))
  2787. ((memq c prefixes)
  2788. (setq selstring (concat selstring (char-to-string c))
  2789. prefixes nil
  2790. rmheader (or rmheader t)
  2791. custom (delq nil (mapcar
  2792. (lambda (x)
  2793. (if (or (= (length (car x)) 1)
  2794. (/= (string-to-char (car x)) c))
  2795. nil
  2796. (cons (substring (car x) 1) (cdr x))))
  2797. custom))))
  2798. ((eq c ?*)
  2799. (call-interactively 'org-toggle-sticky-agenda)
  2800. (sit-for 2))
  2801. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2802. (message "Restriction is only possible in Org buffers")
  2803. (ding) (sit-for 1))
  2804. ((eq c ?1)
  2805. (org-agenda-remove-restriction-lock 'noupdate)
  2806. (setq restriction 'buffer))
  2807. ((eq c ?0)
  2808. (org-agenda-remove-restriction-lock 'noupdate)
  2809. (setq restriction (if region-p 'region 'subtree)))
  2810. ((eq c ?<)
  2811. (org-agenda-remove-restriction-lock 'noupdate)
  2812. (setq restriction
  2813. (cond
  2814. ((eq restriction 'buffer)
  2815. (if region-p 'region 'subtree))
  2816. ((memq restriction '(subtree region))
  2817. nil)
  2818. (t 'buffer))))
  2819. ((eq c ?>)
  2820. (org-agenda-remove-restriction-lock 'noupdate)
  2821. (setq restriction nil))
  2822. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2823. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2824. ((and (> (length selstring) 0) (eq c ?\d))
  2825. (delete-window)
  2826. (org-agenda-get-restriction-and-command prefix-descriptions))
  2827. ((equal c ?q) (error "Abort"))
  2828. (t (user-error "Invalid key %c" c))))))))
  2829. (defun org-agenda-fit-window-to-buffer ()
  2830. "Fit the window to the buffer size."
  2831. (and (memq org-agenda-window-setup '(reorganize-frame))
  2832. (fboundp 'fit-window-to-buffer)
  2833. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2834. (= (car org-agenda-window-frame-fractions) 1.0))
  2835. (delete-other-windows)
  2836. (org-fit-window-to-buffer
  2837. nil
  2838. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2839. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2840. (defvar org-cmd nil)
  2841. (defvar org-agenda-overriding-cmd nil)
  2842. (defvar org-agenda-overriding-arguments nil)
  2843. (defvar org-agenda-overriding-cmd-arguments nil)
  2844. (defun org-agenda-run-series (name series)
  2845. "Run agenda NAME as a SERIES of agenda commands."
  2846. (org-let (nth 1 series) '(org-agenda-prepare name))
  2847. ;; We need to reset agenda markers here, because when constructing a
  2848. ;; block agenda, the individual blocks do not do that.
  2849. (org-agenda-reset-markers)
  2850. (let* ((org-agenda-multi t)
  2851. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2852. (cmds (car series))
  2853. (gprops (nth 1 series))
  2854. match ;; The byte compiler incorrectly complains about this. Keep it!
  2855. org-cmd type lprops)
  2856. (while (setq org-cmd (pop cmds))
  2857. (setq type (car org-cmd))
  2858. (setq match (eval (nth 1 org-cmd)))
  2859. (setq lprops (nth 2 org-cmd))
  2860. (let ((org-agenda-overriding-arguments
  2861. (if (eq org-agenda-overriding-cmd org-cmd)
  2862. (or org-agenda-overriding-arguments
  2863. org-agenda-overriding-cmd-arguments))))
  2864. (cond
  2865. ((eq type 'agenda)
  2866. (org-let2 gprops lprops
  2867. '(call-interactively 'org-agenda-list)))
  2868. ((eq type 'agenda*)
  2869. (org-let2 gprops lprops
  2870. '(funcall 'org-agenda-list nil nil t)))
  2871. ((eq type 'alltodo)
  2872. (org-let2 gprops lprops
  2873. '(call-interactively 'org-todo-list)))
  2874. ((eq type 'search)
  2875. (org-let2 gprops lprops
  2876. '(org-search-view current-prefix-arg match nil)))
  2877. ((eq type 'stuck)
  2878. (org-let2 gprops lprops
  2879. '(call-interactively 'org-agenda-list-stuck-projects)))
  2880. ((eq type 'tags)
  2881. (org-let2 gprops lprops
  2882. '(org-tags-view current-prefix-arg match)))
  2883. ((eq type 'tags-todo)
  2884. (org-let2 gprops lprops
  2885. '(org-tags-view '(4) match)))
  2886. ((eq type 'todo)
  2887. (org-let2 gprops lprops
  2888. '(org-todo-list match)))
  2889. ((fboundp type)
  2890. (org-let2 gprops lprops
  2891. '(funcall type match)))
  2892. (t (error "Invalid type in command series")))))
  2893. (widen)
  2894. (let ((inhibit-read-only t))
  2895. (add-text-properties (point-min) (point-max)
  2896. `(org-series t org-series-redo-cmd ,redo)))
  2897. (setq org-agenda-redo-command redo)
  2898. (goto-char (point-min)))
  2899. (org-agenda-fit-window-to-buffer)
  2900. (org-let (nth 1 series) '(org-agenda-finalize)))
  2901. ;;;###autoload
  2902. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2903. "Run an agenda command in batch mode and send the result to STDOUT.
  2904. If CMD-KEY is a string of length 1, it is used as a key in
  2905. `org-agenda-custom-commands' and triggers this command. If it is a
  2906. longer string it is used as a tags/todo match string.
  2907. Parameters are alternating variable names and values that will be bound
  2908. before running the agenda command."
  2909. (org-eval-in-environment (org-make-parameter-alist parameters)
  2910. (let (org-agenda-sticky)
  2911. (if (> (length cmd-key) 1)
  2912. (org-tags-view nil cmd-key)
  2913. (org-agenda nil cmd-key))))
  2914. (set-buffer org-agenda-buffer-name)
  2915. (princ (buffer-string)))
  2916. (defvar org-agenda-info nil)
  2917. ;;;###autoload
  2918. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2919. "Run an agenda command in batch mode and send the result to STDOUT.
  2920. If CMD-KEY is a string of length 1, it is used as a key in
  2921. `org-agenda-custom-commands' and triggers this command. If it is a
  2922. longer string it is used as a tags/todo match string.
  2923. Parameters are alternating variable names and values that will be bound
  2924. before running the agenda command.
  2925. The output gives a line for each selected agenda item. Each
  2926. item is a list of comma-separated values, like this:
  2927. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2928. category The category of the item
  2929. head The headline, without TODO kwd, TAGS and PRIORITY
  2930. type The type of the agenda entry, can be
  2931. todo selected in TODO match
  2932. tagsmatch selected in tags match
  2933. diary imported from diary
  2934. deadline a deadline on given date
  2935. scheduled scheduled on given date
  2936. timestamp entry has timestamp on given date
  2937. closed entry was closed on given date
  2938. upcoming-deadline warning about deadline
  2939. past-scheduled forwarded scheduled item
  2940. block entry has date block including g. date
  2941. todo The todo keyword, if any
  2942. tags All tags including inherited ones, separated by colons
  2943. date The relevant date, like 2007-2-14
  2944. time The time, like 15:00-16:50
  2945. extra Sting with extra planning info
  2946. priority-l The priority letter if any was given
  2947. priority-n The computed numerical priority
  2948. agenda-day The day in the agenda where this is listed"
  2949. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2950. (org-make-parameter-alist parameters))
  2951. (if (> (length cmd-key) 2)
  2952. (org-tags-view nil cmd-key)
  2953. (org-agenda nil cmd-key)))
  2954. (set-buffer org-agenda-buffer-name)
  2955. (let ((lines (org-split-string (buffer-string) "\n")))
  2956. (dolist (line lines)
  2957. (when (get-text-property 0 'org-category line)
  2958. (setq org-agenda-info
  2959. (org-fix-agenda-info (text-properties-at 0 line)))
  2960. (princ
  2961. (mapconcat 'org-agenda-export-csv-mapper
  2962. '(org-category txt type todo tags date time extra
  2963. priority-letter priority agenda-day)
  2964. ","))
  2965. (princ "\n")))))
  2966. (defun org-fix-agenda-info (props)
  2967. "Make sure all properties on an agenda item have a canonical form.
  2968. This ensures the export commands can easily use it."
  2969. (let (tmp re)
  2970. (when (setq tmp (plist-get props 'tags))
  2971. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2972. (when (setq tmp (plist-get props 'date))
  2973. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2974. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2975. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2976. (setq tmp (calendar-date-string tmp)))
  2977. (setq props (plist-put props 'date tmp)))
  2978. (when (setq tmp (plist-get props 'day))
  2979. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2980. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2981. (setq tmp (calendar-date-string tmp)))
  2982. (setq props (plist-put props 'day tmp))
  2983. (setq props (plist-put props 'agenda-day tmp)))
  2984. (when (setq tmp (plist-get props 'txt))
  2985. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2986. (plist-put props 'priority-letter (match-string 1 tmp))
  2987. (setq tmp (replace-match "" t t tmp)))
  2988. (when (and (setq re (plist-get props 'org-todo-regexp))
  2989. (setq re (concat "\\`\\.*" re " ?"))
  2990. (let ((case-fold-search nil)) (string-match re tmp)))
  2991. (plist-put props 'todo (match-string 1 tmp))
  2992. (setq tmp (replace-match "" t t tmp)))
  2993. (plist-put props 'txt tmp)))
  2994. props)
  2995. (defun org-agenda-export-csv-mapper (prop)
  2996. (let ((res (plist-get org-agenda-info prop)))
  2997. (setq res
  2998. (cond
  2999. ((not res) "")
  3000. ((stringp res) res)
  3001. (t (prin1-to-string res))))
  3002. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3003. ;;;###autoload
  3004. (defun org-store-agenda-views (&rest parameters)
  3005. "Store agenda views."
  3006. (interactive)
  3007. (eval (list 'org-batch-store-agenda-views)))
  3008. ;;;###autoload
  3009. (defmacro org-batch-store-agenda-views (&rest parameters)
  3010. "Run all custom agenda commands that have a file argument."
  3011. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3012. (pop-up-frames nil)
  3013. (dir default-directory)
  3014. (pars (org-make-parameter-alist parameters))
  3015. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3016. (save-window-excursion
  3017. (while cmds
  3018. (setq cmd (pop cmds)
  3019. thiscmdkey (car cmd)
  3020. thiscmdcmd (cdr cmd)
  3021. match (nth 2 thiscmdcmd)
  3022. bufname (if org-agenda-sticky
  3023. (or (and (stringp match)
  3024. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3025. (format "*Org Agenda(%s)*" thiscmdkey))
  3026. org-agenda-buffer-name)
  3027. cmd-or-set (nth 2 cmd)
  3028. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3029. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3030. (if (stringp files) (setq files (list files)))
  3031. (when files
  3032. (org-eval-in-environment (append org-agenda-exporter-settings
  3033. opts pars)
  3034. (org-agenda nil thiscmdkey))
  3035. (set-buffer bufname)
  3036. (while files
  3037. (org-eval-in-environment (append org-agenda-exporter-settings
  3038. opts pars)
  3039. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  3040. (and (get-buffer bufname)
  3041. (kill-buffer bufname)))))))
  3042. (defvar org-agenda-current-span nil
  3043. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3044. (defun org-agenda-mark-header-line (pos)
  3045. "Mark the line at POS as an agenda structure header."
  3046. (save-excursion
  3047. (goto-char pos)
  3048. (put-text-property (point-at-bol) (point-at-eol)
  3049. 'org-agenda-structural-header t)
  3050. (when org-agenda-title-append
  3051. (put-text-property (point-at-bol) (point-at-eol)
  3052. 'org-agenda-title-append org-agenda-title-append))))
  3053. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3054. (defvar org-agenda-write-buffer-name "Agenda View")
  3055. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3056. "Write the current buffer (an agenda view) as a file.
  3057. Depending on the extension of the file name, plain text (.txt),
  3058. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3059. If the extension is .ics, translate visible agenda into iCalendar
  3060. format. If the extension is .org, collect all subtrees
  3061. corresponding to the agenda entries and add them in an .org file.
  3062. With prefix argument OPEN, open the new file immediately. If
  3063. NOSETTINGS is given, do not scope the settings of
  3064. `org-agenda-exporter-settings' into the export commands. This is
  3065. used when the settings have already been scoped and we do not
  3066. wish to overrule other, higher priority settings. If
  3067. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3068. the agenda to write."
  3069. (interactive "FWrite agenda to file: \nP")
  3070. (if (or (not (file-writable-p file))
  3071. (and (file-exists-p file)
  3072. (if (called-interactively-p 'any)
  3073. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3074. (user-error "Cannot write agenda to file %s" file))
  3075. (org-let (if nosettings nil org-agenda-exporter-settings)
  3076. '(save-excursion
  3077. (save-window-excursion
  3078. (let ((bs (copy-sequence (buffer-string)))
  3079. (extension (file-name-extension file))
  3080. (default-directory (file-name-directory file))
  3081. beg content)
  3082. (with-temp-buffer
  3083. (rename-buffer org-agenda-write-buffer-name t)
  3084. (set-buffer-modified-p nil)
  3085. (insert bs)
  3086. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3087. (run-hooks 'org-agenda-before-write-hook)
  3088. (cond
  3089. ((bound-and-true-p org-mobile-creating-agendas)
  3090. (org-mobile-write-agenda-for-mobile file))
  3091. ((string= "org" extension)
  3092. (let (content p m message-log-max)
  3093. (goto-char (point-min))
  3094. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3095. (goto-char p)
  3096. (setq m (get-text-property (point) 'org-hd-marker))
  3097. (when m
  3098. (push (save-excursion
  3099. (set-buffer (marker-buffer m))
  3100. (goto-char m)
  3101. (org-copy-subtree 1 nil t t)
  3102. org-subtree-clip)
  3103. content)))
  3104. (find-file file)
  3105. (erase-buffer)
  3106. (dolist (s content) (org-paste-subtree 1 s))
  3107. (write-file file)
  3108. (kill-buffer (current-buffer))
  3109. (message "Org file written to %s" file)))
  3110. ((member extension '("html" "htm"))
  3111. (or (require 'htmlize nil t)
  3112. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3113. (set-buffer (htmlize-buffer (current-buffer)))
  3114. (when org-agenda-export-html-style
  3115. ;; replace <style> section with org-agenda-export-html-style
  3116. (goto-char (point-min))
  3117. (kill-region (- (search-forward "<style") 6)
  3118. (search-forward "</style>"))
  3119. (insert org-agenda-export-html-style))
  3120. (write-file file)
  3121. (kill-buffer (current-buffer))
  3122. (message "HTML written to %s" file))
  3123. ((string= "ps" extension)
  3124. (require 'ps-print)
  3125. (ps-print-buffer-with-faces file)
  3126. (message "Postscript written to %s" file))
  3127. ((string= "pdf" extension)
  3128. (require 'ps-print)
  3129. (ps-print-buffer-with-faces
  3130. (concat (file-name-sans-extension file) ".ps"))
  3131. (call-process "ps2pdf" nil nil nil
  3132. (expand-file-name
  3133. (concat (file-name-sans-extension file) ".ps"))
  3134. (expand-file-name file))
  3135. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3136. (message "PDF written to %s" file))
  3137. ((string= "ics" extension)
  3138. (require 'ox-icalendar)
  3139. (org-icalendar-export-current-agenda (expand-file-name file)))
  3140. (t
  3141. (let ((bs (buffer-string)))
  3142. (find-file file)
  3143. (erase-buffer)
  3144. (insert bs)
  3145. (save-buffer 0)
  3146. (kill-buffer (current-buffer))
  3147. (message "Plain text written to %s" file))))))))
  3148. (set-buffer (or agenda-bufname
  3149. (and (called-interactively-p 'any) (buffer-name))
  3150. org-agenda-buffer-name)))
  3151. (when open (org-open-file file)))
  3152. (defun org-agenda-remove-marked-text (property &optional value)
  3153. "Delete all text marked with VALUE of PROPERTY.
  3154. VALUE defaults to t."
  3155. (let (beg)
  3156. (setq value (or value t))
  3157. (while (setq beg (text-property-any (point-min) (point-max)
  3158. property value))
  3159. (delete-region
  3160. beg (or (next-single-property-change beg property)
  3161. (point-max))))))
  3162. (defun org-agenda-add-entry-text ()
  3163. "Add entry text to agenda lines.
  3164. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3165. entry text following headings shown in the agenda.
  3166. Drawers will be excluded, also the line with scheduling/deadline info."
  3167. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3168. (not (bound-and-true-p org-mobile-creating-agendas)))
  3169. (let (m txt)
  3170. (goto-char (point-min))
  3171. (while (not (eobp))
  3172. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3173. (beginning-of-line 2)
  3174. (setq txt (org-agenda-get-some-entry-text
  3175. m org-agenda-add-entry-text-maxlines " > "))
  3176. (end-of-line 1)
  3177. (if (string-match "\\S-" txt)
  3178. (insert "\n" txt)
  3179. (or (eobp) (forward-char 1))))))))
  3180. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3181. &rest keep)
  3182. "Extract entry text from MARKER, at most N-LINES lines.
  3183. This will ignore drawers etc, just get the text.
  3184. If INDENT is given, prefix every line with this string. If KEEP is
  3185. given, it is a list of symbols, defining stuff that should not be
  3186. removed from the entry content. Currently only `planning' is allowed here."
  3187. (let (txt drawer-re kwd-time-re ind)
  3188. (save-excursion
  3189. (with-current-buffer (marker-buffer marker)
  3190. (if (not (derived-mode-p 'org-mode))
  3191. (setq txt "")
  3192. (org-with-wide-buffer
  3193. (goto-char marker)
  3194. (end-of-line 1)
  3195. (setq txt (buffer-substring
  3196. (min (1+ (point)) (point-max))
  3197. (progn (outline-next-heading) (point)))
  3198. drawer-re org-drawer-regexp
  3199. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3200. ".*\n?"))
  3201. (with-temp-buffer
  3202. (insert txt)
  3203. (when org-agenda-add-entry-text-descriptive-links
  3204. (goto-char (point-min))
  3205. (while (org-activate-links (point-max))
  3206. (add-text-properties (match-beginning 0) (match-end 0)
  3207. '(face org-link))))
  3208. (goto-char (point-min))
  3209. (while (re-search-forward org-link-bracket-re (point-max) t)
  3210. (set-text-properties (match-beginning 0) (match-end 0)
  3211. nil))
  3212. (goto-char (point-min))
  3213. (while (re-search-forward drawer-re nil t)
  3214. (delete-region
  3215. (match-beginning 0)
  3216. (progn (re-search-forward
  3217. "^[ \t]*:END:.*\n?" nil 'move)
  3218. (point))))
  3219. (unless (member 'planning keep)
  3220. (goto-char (point-min))
  3221. (while (re-search-forward kwd-time-re nil t)
  3222. (replace-match "")))
  3223. (goto-char (point-min))
  3224. (when org-agenda-entry-text-exclude-regexps
  3225. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3226. (while (setq re (pop re-list))
  3227. (goto-char (point-min))
  3228. (while (re-search-forward re nil t)
  3229. (replace-match "")))))
  3230. (goto-char (point-max))
  3231. (skip-chars-backward " \t\n")
  3232. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3233. ;; find and remove min common indentation
  3234. (goto-char (point-min))
  3235. (untabify (point-min) (point-max))
  3236. (setq ind (current-indentation))
  3237. (while (not (eobp))
  3238. (unless (looking-at "[ \t]*$")
  3239. (setq ind (min ind (current-indentation))))
  3240. (beginning-of-line 2))
  3241. (goto-char (point-min))
  3242. (while (not (eobp))
  3243. (unless (looking-at "[ \t]*$")
  3244. (move-to-column ind)
  3245. (delete-region (point-at-bol) (point)))
  3246. (beginning-of-line 2))
  3247. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3248. (goto-char (point-min))
  3249. (when indent
  3250. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3251. (replace-match indent t t)))
  3252. (goto-char (point-min))
  3253. (while (looking-at "[ \t]*\n") (replace-match ""))
  3254. (goto-char (point-max))
  3255. (when (> (org-current-line)
  3256. n-lines)
  3257. (org-goto-line (1+ n-lines))
  3258. (backward-char 1))
  3259. (setq txt (buffer-substring (point-min) (point))))))))
  3260. txt))
  3261. (defun org-check-for-org-mode ()
  3262. "Make sure current buffer is in Org mode. Error if not."
  3263. (or (derived-mode-p 'org-mode)
  3264. (error "Cannot execute Org agenda command on buffer in %s"
  3265. major-mode)))
  3266. ;;; Agenda prepare and finalize
  3267. (defvar org-agenda-multi nil) ; dynamically scoped
  3268. (defvar org-agenda-pre-window-conf nil)
  3269. (defvar org-agenda-columns-active nil)
  3270. (defvar org-agenda-name nil)
  3271. (defvar org-agenda-tag-filter nil)
  3272. (defvar org-agenda-category-filter nil)
  3273. (defvar org-agenda-regexp-filter nil)
  3274. (defvar org-agenda-effort-filter nil)
  3275. (defvar org-agenda-top-headline-filter nil)
  3276. (defvar org-agenda-tag-filter-preset nil
  3277. "A preset of the tags filter used for secondary agenda filtering.
  3278. This must be a list of strings, each string must be a single tag preceded
  3279. by \"+\" or \"-\".
  3280. This variable should not be set directly, but agenda custom commands can
  3281. bind it in the options section. The preset filter is a global property of
  3282. the entire agenda view. In a block agenda, it will not work reliably to
  3283. define a filter for one of the individual blocks. You need to set it in
  3284. the global options and expect it to be applied to the entire view.")
  3285. (defvar org-agenda-category-filter-preset nil
  3286. "A preset of the category filter used for secondary agenda filtering.
  3287. This must be a list of strings, each string must be a single category
  3288. preceded by \"+\" or \"-\".
  3289. This variable should not be set directly, but agenda custom commands can
  3290. bind it in the options section. The preset filter is a global property of
  3291. the entire agenda view. In a block agenda, it will not work reliably to
  3292. define a filter for one of the individual blocks. You need to set it in
  3293. the global options and expect it to be applied to the entire view.")
  3294. (defvar org-agenda-regexp-filter-preset nil
  3295. "A preset of the regexp filter used for secondary agenda filtering.
  3296. This must be a list of strings, each string must be a single regexp
  3297. preceded by \"+\" or \"-\".
  3298. This variable should not be set directly, but agenda custom commands can
  3299. bind it in the options section. The preset filter is a global property of
  3300. the entire agenda view. In a block agenda, it will not work reliably to
  3301. define a filter for one of the individual blocks. You need to set it in
  3302. the global options and expect it to be applied to the entire view.")
  3303. (defvar org-agenda-effort-filter-preset nil
  3304. "A preset of the effort condition used for secondary agenda filtering.
  3305. This must be a list of strings, each string must be a single regexp
  3306. preceded by \"+\" or \"-\".
  3307. This variable should not be set directly, but agenda custom commands can
  3308. bind it in the options section. The preset filter is a global property of
  3309. the entire agenda view. In a block agenda, it will not work reliably to
  3310. define a filter for one of the individual blocks. You need to set it in
  3311. the global options and expect it to be applied to the entire view.")
  3312. (defun org-agenda-use-sticky-p ()
  3313. "Return non-nil if an agenda buffer named
  3314. `org-agenda-buffer-name' exists and should be shown instead of
  3315. generating a new one."
  3316. (and
  3317. ;; turned off by user
  3318. org-agenda-sticky
  3319. ;; For multi-agenda buffer already exists
  3320. (not org-agenda-multi)
  3321. ;; buffer found
  3322. (get-buffer org-agenda-buffer-name)
  3323. ;; C-u parameter is same as last call
  3324. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3325. (and
  3326. (equal current-prefix-arg
  3327. org-agenda-last-prefix-arg)
  3328. ;; In case user turned stickiness on, while having existing
  3329. ;; Agenda buffer active, don't reuse that buffer, because it
  3330. ;; does not have org variables local
  3331. org-agenda-this-buffer-is-sticky))))
  3332. (defun org-agenda-prepare-window (abuf filter-alist)
  3333. "Setup agenda buffer in the window.
  3334. ABUF is the buffer for the agenda window.
  3335. FILTER-ALIST is an alist of filters we need to apply when
  3336. `org-agenda-persistent-filter' is non-nil."
  3337. (let* ((awin (get-buffer-window abuf)) wconf)
  3338. (cond
  3339. ((equal (current-buffer) abuf) nil)
  3340. (awin (select-window awin))
  3341. ((not (setq wconf (current-window-configuration))))
  3342. ((eq org-agenda-window-setup 'current-window)
  3343. (pop-to-buffer-same-window abuf))
  3344. ((eq org-agenda-window-setup 'other-window)
  3345. (org-switch-to-buffer-other-window abuf))
  3346. ((eq org-agenda-window-setup 'other-frame)
  3347. (switch-to-buffer-other-frame abuf))
  3348. ((eq org-agenda-window-setup 'only-window)
  3349. (delete-other-windows)
  3350. (pop-to-buffer-same-window abuf))
  3351. ((eq org-agenda-window-setup 'reorganize-frame)
  3352. (delete-other-windows)
  3353. (org-switch-to-buffer-other-window abuf)))
  3354. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3355. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3356. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3357. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3358. ;; Additional test in case agenda is invoked from within agenda
  3359. ;; buffer via elisp link.
  3360. (unless (equal (current-buffer) abuf)
  3361. (pop-to-buffer-same-window abuf))
  3362. (setq org-agenda-pre-window-conf
  3363. (or wconf org-agenda-pre-window-conf))))
  3364. (defun org-agenda-prepare (&optional name)
  3365. (let ((filter-alist (when org-agenda-persistent-filter
  3366. (with-current-buffer
  3367. (get-buffer-create org-agenda-buffer-name)
  3368. `((tag . ,org-agenda-tag-filter)
  3369. (re . ,org-agenda-regexp-filter)
  3370. (effort . ,org-agenda-effort-filter)
  3371. (cat . ,org-agenda-category-filter))))))
  3372. (if (org-agenda-use-sticky-p)
  3373. (progn
  3374. (put 'org-agenda-tag-filter :preset-filter nil)
  3375. (put 'org-agenda-category-filter :preset-filter nil)
  3376. (put 'org-agenda-regexp-filter :preset-filter nil)
  3377. ;; Popup existing buffer
  3378. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3379. filter-alist)
  3380. (message "Sticky Agenda buffer, use `r' to refresh")
  3381. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3382. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3383. (setq org-todo-keywords-for-agenda nil)
  3384. (put 'org-agenda-tag-filter :preset-filter
  3385. org-agenda-tag-filter-preset)
  3386. (put 'org-agenda-category-filter :preset-filter
  3387. org-agenda-category-filter-preset)
  3388. (put 'org-agenda-regexp-filter :preset-filter
  3389. org-agenda-regexp-filter-preset)
  3390. (put 'org-agenda-effort-filter :preset-filter
  3391. org-agenda-effort-filter-preset)
  3392. (if org-agenda-multi
  3393. (progn
  3394. (setq buffer-read-only nil)
  3395. (goto-char (point-max))
  3396. (unless (or (bobp) org-agenda-compact-blocks
  3397. (not org-agenda-block-separator))
  3398. (insert "\n"
  3399. (if (stringp org-agenda-block-separator)
  3400. org-agenda-block-separator
  3401. (make-string (window-width) org-agenda-block-separator))
  3402. "\n"))
  3403. (narrow-to-region (point) (point-max)))
  3404. (setq org-done-keywords-for-agenda nil)
  3405. ;; Setting any org variables that are in org-agenda-local-vars
  3406. ;; list need to be done after the prepare call
  3407. (org-agenda-prepare-window
  3408. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3409. (setq buffer-read-only nil)
  3410. (org-agenda-reset-markers)
  3411. (let ((inhibit-read-only t)) (erase-buffer))
  3412. (org-agenda-mode)
  3413. (setq org-agenda-buffer (current-buffer))
  3414. (setq org-agenda-contributing-files nil)
  3415. (setq org-agenda-columns-active nil)
  3416. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3417. (setq org-todo-keywords-for-agenda
  3418. (org-uniquify org-todo-keywords-for-agenda))
  3419. (setq org-done-keywords-for-agenda
  3420. (org-uniquify org-done-keywords-for-agenda))
  3421. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3422. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3423. (and name (not org-agenda-name)
  3424. (setq-local org-agenda-name name)))
  3425. (setq buffer-read-only nil))))
  3426. (defvar org-overriding-columns-format)
  3427. (defvar org-local-columns-format)
  3428. (defun org-agenda-finalize ()
  3429. "Finishing touch for the agenda buffer, called just before displaying it."
  3430. (unless org-agenda-multi
  3431. (save-excursion
  3432. (let ((inhibit-read-only t))
  3433. (goto-char (point-min))
  3434. (save-excursion
  3435. (while (org-activate-links (point-max))
  3436. (add-text-properties (match-beginning 0) (match-end 0)
  3437. '(face org-link))))
  3438. (unless (eq org-agenda-remove-tags t)
  3439. (org-agenda-align-tags))
  3440. (unless org-agenda-with-colors
  3441. (remove-text-properties (point-min) (point-max) '(face nil)))
  3442. (when (bound-and-true-p org-overriding-columns-format)
  3443. (setq-local org-local-columns-format
  3444. org-overriding-columns-format))
  3445. (when org-agenda-view-columns-initially
  3446. (org-agenda-columns))
  3447. (when org-agenda-fontify-priorities
  3448. (org-agenda-fontify-priorities))
  3449. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3450. (org-agenda-dim-blocked-tasks))
  3451. (org-agenda-mark-clocking-task)
  3452. (when org-agenda-entry-text-mode
  3453. (org-agenda-entry-text-hide)
  3454. (org-agenda-entry-text-show))
  3455. (when (and (featurep 'org-habit)
  3456. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3457. (org-habit-insert-consistency-graphs))
  3458. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3459. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3460. (and (listp org-agenda-show-inherited-tags)
  3461. (memq org-agenda-type org-agenda-show-inherited-tags))
  3462. (and (eq org-agenda-show-inherited-tags t)
  3463. (or (eq org-agenda-use-tag-inheritance t)
  3464. (and (listp org-agenda-use-tag-inheritance)
  3465. (not (memq org-agenda-type
  3466. org-agenda-use-tag-inheritance))))))
  3467. (let (mrk)
  3468. (save-excursion
  3469. (goto-char (point-min))
  3470. (while (equal (forward-line) 0)
  3471. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3472. (put-text-property (point-at-bol) (point-at-eol)
  3473. 'tags
  3474. (org-with-point-at mrk
  3475. (mapcar #'downcase (org-get-tags)))))))))
  3476. (run-hooks 'org-agenda-finalize-hook)
  3477. (when org-agenda-top-headline-filter
  3478. (org-agenda-filter-top-headline-apply
  3479. org-agenda-top-headline-filter))
  3480. (when org-agenda-tag-filter
  3481. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3482. (when (get 'org-agenda-tag-filter :preset-filter)
  3483. (org-agenda-filter-apply
  3484. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3485. (when org-agenda-category-filter
  3486. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3487. (when (get 'org-agenda-category-filter :preset-filter)
  3488. (org-agenda-filter-apply
  3489. (get 'org-agenda-category-filter :preset-filter) 'category))
  3490. (when org-agenda-regexp-filter
  3491. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3492. (when (get 'org-agenda-regexp-filter :preset-filter)
  3493. (org-agenda-filter-apply
  3494. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3495. (when org-agenda-effort-filter
  3496. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3497. (when (get 'org-agenda-effort-filter :preset-filter)
  3498. (org-agenda-filter-apply
  3499. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3500. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3501. (defun org-agenda-mark-clocking-task ()
  3502. "Mark the current clock entry in the agenda if it is present."
  3503. ;; We need to widen when `org-agenda-finalize' is called from
  3504. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3505. (when (bound-and-true-p org-clock-current-task)
  3506. (save-restriction
  3507. (widen)
  3508. (org-agenda-unmark-clocking-task)
  3509. (when (marker-buffer org-clock-hd-marker)
  3510. (save-excursion
  3511. (goto-char (point-min))
  3512. (let (s ov)
  3513. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3514. (goto-char s)
  3515. (when (equal (org-get-at-bol 'org-hd-marker)
  3516. org-clock-hd-marker)
  3517. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3518. (overlay-put ov 'type 'org-agenda-clocking)
  3519. (overlay-put ov 'face 'org-agenda-clocking)
  3520. (overlay-put ov 'help-echo
  3521. "The clock is running in this item")))))))))
  3522. (defun org-agenda-unmark-clocking-task ()
  3523. "Unmark the current clocking task."
  3524. (mapc (lambda (o)
  3525. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3526. (delete-overlay o)))
  3527. (overlays-in (point-min) (point-max))))
  3528. (defun org-agenda-fontify-priorities ()
  3529. "Make highest priority lines bold, and lowest italic."
  3530. (interactive)
  3531. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3532. (delete-overlay o)))
  3533. (overlays-in (point-min) (point-max)))
  3534. (save-excursion
  3535. (let (b e p ov h l)
  3536. (goto-char (point-min))
  3537. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3538. (setq h (or (get-char-property (point) 'org-highest-priority)
  3539. org-highest-priority)
  3540. l (or (get-char-property (point) 'org-lowest-priority)
  3541. org-lowest-priority)
  3542. p (string-to-char (match-string 1))
  3543. b (match-beginning 0)
  3544. e (if (eq org-agenda-fontify-priorities 'cookies)
  3545. (match-end 0)
  3546. (point-at-eol))
  3547. ov (make-overlay b e))
  3548. (overlay-put
  3549. ov 'face
  3550. (let ((special-face
  3551. (cond ((org-face-from-face-or-color
  3552. 'priority 'org-priority
  3553. (cdr (assoc p org-priority-faces))))
  3554. ((and (listp org-agenda-fontify-priorities)
  3555. (org-face-from-face-or-color
  3556. 'priority 'org-priority
  3557. (cdr (assoc p org-agenda-fontify-priorities)))))
  3558. ((equal p l) 'italic)
  3559. ((equal p h) 'bold))))
  3560. (if special-face (list special-face 'org-priority) 'org-priority)))
  3561. (overlay-put ov 'org-type 'org-priority)))))
  3562. (defvar org-depend-tag-blocked)
  3563. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3564. "Dim currently blocked TODOs in the agenda display.
  3565. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3566. dimming them."
  3567. (interactive "P")
  3568. (when (called-interactively-p 'interactive)
  3569. (message "Dim or hide blocked tasks..."))
  3570. (dolist (o (overlays-in (point-min) (point-max)))
  3571. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3572. (delete-overlay o)))
  3573. (save-excursion
  3574. (let ((inhibit-read-only t))
  3575. (goto-char (point-min))
  3576. (while (let ((pos (text-property-not-all
  3577. (point) (point-max) 'org-todo-blocked nil)))
  3578. (when pos (goto-char pos)))
  3579. (let* ((invisible (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3580. (ov (make-overlay (if invisible
  3581. (line-end-position 0)
  3582. (line-beginning-position))
  3583. (line-end-position))))
  3584. (if invisible
  3585. (overlay-put ov 'invisible t)
  3586. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3587. (overlay-put ov 'org-type 'org-blocked-todo))
  3588. (forward-line))))
  3589. (when (called-interactively-p 'interactive)
  3590. (message "Dim or hide blocked tasks...done")))
  3591. (defun org-agenda--mark-blocked-entry (entry)
  3592. "For ENTRY a string with the text property `org-hd-marker', if
  3593. the header at `org-hd-marker' is blocked according to
  3594. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3595. 'invisible and the header is not blocked by checkboxes, set the
  3596. text property `org-todo-blocked' to 'invisible, otherwise set it
  3597. to t."
  3598. (when (get-text-property 0 'todo-state entry)
  3599. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3600. (org-blocked-by-checkboxes nil)
  3601. ;; Necessary so that `org-entry-blocked-p' does not change
  3602. ;; the buffer.
  3603. (org-depend-tag-blocked nil))
  3604. (when entry-marker
  3605. (let ((blocked
  3606. (with-current-buffer (marker-buffer entry-marker)
  3607. (save-excursion
  3608. (goto-char entry-marker)
  3609. (org-entry-blocked-p)))))
  3610. (when blocked
  3611. (let ((really-invisible
  3612. (and (not org-blocked-by-checkboxes)
  3613. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3614. (put-text-property
  3615. 0 (length entry) 'org-todo-blocked
  3616. (if really-invisible 'invisible t)
  3617. entry)))))))
  3618. entry)
  3619. (defvar org-agenda-skip-function nil
  3620. "Function to be called at each match during agenda construction.
  3621. If this function returns nil, the current match should not be skipped.
  3622. Otherwise, the function must return a position from where the search
  3623. should be continued.
  3624. This may also be a Lisp form, it will be evaluated.
  3625. Never set this variable using `setq' or so, because then it will apply
  3626. to all future agenda commands. If you do want a global skipping condition,
  3627. use the option `org-agenda-skip-function-global' instead.
  3628. The correct usage for `org-agenda-skip-function' is to bind it with
  3629. `let' to scope it dynamically into the agenda-constructing command.
  3630. A good way to set it is through options in `org-agenda-custom-commands'.")
  3631. (defun org-agenda-skip ()
  3632. "Throw to `:skip' in places that should be skipped.
  3633. Also moves point to the end of the skipped region, so that search can
  3634. continue from there."
  3635. (let ((p (point-at-bol)) to)
  3636. (when (or
  3637. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3638. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3639. (get-text-property p :org-archived)
  3640. (org-end-of-subtree t))
  3641. (and org-agenda-skip-comment-trees
  3642. (get-text-property p :org-comment)
  3643. (org-end-of-subtree t))
  3644. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3645. (org-agenda-skip-eval org-agenda-skip-function)))
  3646. (goto-char to))
  3647. (org-in-src-block-p t))
  3648. (throw :skip t))))
  3649. (defun org-agenda-skip-eval (form)
  3650. "If FORM is a function or a list, call (or eval) it and return the result.
  3651. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3652. and match data are returned to the previous state no matter what these
  3653. functions do."
  3654. (let (fp)
  3655. (and form
  3656. (or (setq fp (functionp form))
  3657. (consp form))
  3658. (save-excursion
  3659. (save-match-data
  3660. (if fp
  3661. (funcall form)
  3662. (eval form)))))))
  3663. (defvar org-agenda-markers nil
  3664. "List of all currently active markers created by `org-agenda'.")
  3665. (defvar org-agenda-last-marker-time (float-time)
  3666. "Creation time of the last agenda marker.")
  3667. (defun org-agenda-new-marker (&optional pos)
  3668. "Return a new agenda marker.
  3669. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3670. these markers and resets them when they are no longer in use."
  3671. (let ((m (copy-marker (or pos (point)) t)))
  3672. (setq org-agenda-last-marker-time (float-time))
  3673. (if org-agenda-buffer
  3674. (with-current-buffer org-agenda-buffer
  3675. (push m org-agenda-markers))
  3676. (push m org-agenda-markers))
  3677. m))
  3678. (defun org-agenda-reset-markers ()
  3679. "Reset markers created by `org-agenda'."
  3680. (while org-agenda-markers
  3681. (move-marker (pop org-agenda-markers) nil)))
  3682. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3683. "Save relative positions of markers in region.
  3684. This check for agenda markers in all agenda buffers currently active."
  3685. (dolist (buf (buffer-list))
  3686. (with-current-buffer buf
  3687. (when (eq major-mode 'org-agenda-mode)
  3688. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3689. org-agenda-markers)))))
  3690. ;;; Entry text mode
  3691. (defun org-agenda-entry-text-show-here ()
  3692. "Add some text from the entry as context to the current line."
  3693. (let (m txt o)
  3694. (setq m (org-get-at-bol 'org-hd-marker))
  3695. (unless (marker-buffer m)
  3696. (error "No marker points to an entry here"))
  3697. (setq txt (concat "\n" (org-no-properties
  3698. (org-agenda-get-some-entry-text
  3699. m org-agenda-entry-text-maxlines
  3700. org-agenda-entry-text-leaders))))
  3701. (when (string-match "\\S-" txt)
  3702. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3703. (overlay-put o 'evaporate t)
  3704. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3705. (overlay-put o 'after-string txt))))
  3706. (defun org-agenda-entry-text-show ()
  3707. "Add entry context for all agenda lines."
  3708. (interactive)
  3709. (save-excursion
  3710. (goto-char (point-max))
  3711. (beginning-of-line 1)
  3712. (while (not (bobp))
  3713. (when (org-get-at-bol 'org-hd-marker)
  3714. (org-agenda-entry-text-show-here))
  3715. (beginning-of-line 0))))
  3716. (defun org-agenda-entry-text-hide ()
  3717. "Remove any shown entry context."
  3718. (mapc (lambda (o)
  3719. (when (eq (overlay-get o 'org-overlay-type)
  3720. 'agenda-entry-content)
  3721. (delete-overlay o)))
  3722. (overlays-in (point-min) (point-max))))
  3723. (defun org-agenda-get-day-face (date)
  3724. "Return the face DATE should be displayed with."
  3725. (cond ((and (functionp org-agenda-day-face-function)
  3726. (funcall org-agenda-day-face-function date)))
  3727. ((org-agenda-today-p date) 'org-agenda-date-today)
  3728. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3729. 'org-agenda-date-weekend)
  3730. (t 'org-agenda-date)))
  3731. (defvar org-agenda-show-log-scoped)
  3732. ;;; Agenda Daily/Weekly
  3733. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3734. "Start day for the agenda view.
  3735. Custom commands can set this variable in the options section.
  3736. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3737. input allowed when reading a date through the Org calendar.
  3738. See the docstring of `org-read-date' for details.")
  3739. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3740. (defvar org-arg-loc nil) ; local variable
  3741. (defvar org-agenda-buffer-tmp-name nil)
  3742. ;;;###autoload
  3743. (defun org-agenda-list (&optional arg start-day span with-hour)
  3744. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3745. The view will be for the current day or week, but from the overview buffer
  3746. you will be able to go to other days/weeks.
  3747. With a numeric prefix argument in an interactive call, the agenda will
  3748. span ARG days. Lisp programs should instead specify SPAN to change
  3749. the number of days. SPAN defaults to `org-agenda-span'.
  3750. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3751. given in `org-agenda-start-on-weekday'.
  3752. When WITH-HOUR is non-nil, only include scheduled and deadline
  3753. items if they have an hour specification like [h]h:mm."
  3754. (interactive "P")
  3755. (when org-agenda-overriding-arguments
  3756. (setq arg (car org-agenda-overriding-arguments)
  3757. start-day (nth 1 org-agenda-overriding-arguments)
  3758. span (nth 2 org-agenda-overriding-arguments)))
  3759. (when (and (integerp arg) (> arg 0))
  3760. (setq span arg arg nil))
  3761. (when (numberp span)
  3762. (unless (< 0 span)
  3763. (user-error "Agenda creation impossible for this span(=%d days)." span)))
  3764. (catch 'exit
  3765. (setq org-agenda-buffer-name
  3766. (or org-agenda-buffer-tmp-name
  3767. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3768. (when org-agenda-sticky
  3769. (cond ((and org-keys (stringp org-match))
  3770. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3771. (org-keys
  3772. (format "*Org Agenda(%s)*" org-keys))
  3773. (t "*Org Agenda(a)*")))
  3774. "*Org Agenda*"))
  3775. (org-agenda-prepare "Day/Week")
  3776. (setq start-day (or start-day org-agenda-start-day))
  3777. (when (stringp start-day)
  3778. ;; Convert to an absolute day number
  3779. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3780. (org-compile-prefix-format 'agenda)
  3781. (org-set-sorting-strategy 'agenda)
  3782. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3783. (today (org-today))
  3784. (sd (or start-day today))
  3785. (ndays (org-agenda-span-to-ndays span sd))
  3786. (org-agenda-start-on-weekday
  3787. (and (or (eq ndays 7) (eq ndays 14))
  3788. org-agenda-start-on-weekday))
  3789. (thefiles (org-agenda-files nil 'ifmode))
  3790. (files thefiles)
  3791. (start (if (or (null org-agenda-start-on-weekday)
  3792. (< ndays 7))
  3793. sd
  3794. (let* ((nt (calendar-day-of-week
  3795. (calendar-gregorian-from-absolute sd)))
  3796. (n1 org-agenda-start-on-weekday)
  3797. (d (- nt n1)))
  3798. (- sd (+ (if (< d 0) 7 0) d)))))
  3799. (day-numbers (list start))
  3800. (day-cnt 0)
  3801. (inhibit-redisplay (not debug-on-error))
  3802. (org-agenda-show-log-scoped org-agenda-show-log)
  3803. s e rtn rtnall file date d start-pos end-pos todayp
  3804. clocktable-start clocktable-end filter)
  3805. (setq org-agenda-redo-command
  3806. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3807. (dotimes (n (1- ndays))
  3808. (push (1+ (car day-numbers)) day-numbers))
  3809. (setq day-numbers (nreverse day-numbers))
  3810. (setq clocktable-start (car day-numbers)
  3811. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3812. (setq-local org-starting-day (car day-numbers))
  3813. (setq-local org-arg-loc arg)
  3814. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3815. (unless org-agenda-compact-blocks
  3816. (let* ((d1 (car day-numbers))
  3817. (d2 (org-last day-numbers))
  3818. (w1 (org-days-to-iso-week d1))
  3819. (w2 (org-days-to-iso-week d2)))
  3820. (setq s (point))
  3821. (org-agenda--insert-overriding-header
  3822. (concat (org-agenda-span-name span)
  3823. "-agenda"
  3824. (cond ((<= 350 (- d2 d1)) "")
  3825. ((= w1 w2) (format " (W%02d)" w1))
  3826. (t (format " (W%02d-W%02d)" w1 w2)))
  3827. ":\n")))
  3828. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3829. 'org-date-line t))
  3830. (org-agenda-mark-header-line s))
  3831. (while (setq d (pop day-numbers))
  3832. (setq date (calendar-gregorian-from-absolute d)
  3833. s (point))
  3834. (if (or (setq todayp (= d today))
  3835. (and (not start-pos) (= d sd)))
  3836. (setq start-pos (point))
  3837. (when (and start-pos (not end-pos))
  3838. (setq end-pos (point))))
  3839. (setq files thefiles
  3840. rtnall nil)
  3841. (while (setq file (pop files))
  3842. (catch 'nextfile
  3843. (org-check-agenda-file file)
  3844. (let ((org-agenda-entry-types org-agenda-entry-types))
  3845. ;; Starred types override non-starred equivalents
  3846. (when (member :deadline* org-agenda-entry-types)
  3847. (setq org-agenda-entry-types
  3848. (delq :deadline org-agenda-entry-types)))
  3849. (when (member :scheduled* org-agenda-entry-types)
  3850. (setq org-agenda-entry-types
  3851. (delq :scheduled org-agenda-entry-types)))
  3852. ;; Honor with-hour
  3853. (when with-hour
  3854. (when (member :deadline org-agenda-entry-types)
  3855. (setq org-agenda-entry-types
  3856. (delq :deadline org-agenda-entry-types))
  3857. (push :deadline* org-agenda-entry-types))
  3858. (when (member :scheduled org-agenda-entry-types)
  3859. (setq org-agenda-entry-types
  3860. (delq :scheduled org-agenda-entry-types))
  3861. (push :scheduled* org-agenda-entry-types)))
  3862. (unless org-agenda-include-deadlines
  3863. (setq org-agenda-entry-types
  3864. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3865. (cond
  3866. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3867. (setq rtn (org-agenda-get-day-entries
  3868. file date :closed)))
  3869. (org-agenda-show-log-scoped
  3870. (setq rtn (apply 'org-agenda-get-day-entries
  3871. file date
  3872. (append '(:closed) org-agenda-entry-types))))
  3873. (t
  3874. (setq rtn (apply 'org-agenda-get-day-entries
  3875. file date
  3876. org-agenda-entry-types)))))
  3877. (setq rtnall (append rtnall rtn)))) ;; all entries
  3878. (when org-agenda-include-diary
  3879. (let ((org-agenda-search-headline-for-time t))
  3880. (require 'diary-lib)
  3881. (setq rtn (org-get-entries-from-diary date))
  3882. (setq rtnall (append rtnall rtn))))
  3883. (when (or rtnall org-agenda-show-all-dates)
  3884. (setq day-cnt (1+ day-cnt))
  3885. (insert
  3886. (if (stringp org-agenda-format-date)
  3887. (format-time-string org-agenda-format-date
  3888. (org-time-from-absolute date))
  3889. (funcall org-agenda-format-date date))
  3890. "\n")
  3891. (put-text-property s (1- (point)) 'face
  3892. (org-agenda-get-day-face date))
  3893. (put-text-property s (1- (point)) 'org-date-line t)
  3894. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3895. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3896. (when todayp
  3897. (put-text-property s (1- (point)) 'org-today t))
  3898. (setq rtnall
  3899. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3900. (when rtnall (insert ;; all entries
  3901. (org-agenda-finalize-entries rtnall 'agenda)
  3902. "\n"))
  3903. (put-text-property s (1- (point)) 'day d)
  3904. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  3905. (when (and org-agenda-clockreport-mode clocktable-start)
  3906. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3907. ;; the above line is to ensure the restricted range!
  3908. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3909. tbl)
  3910. (setq p (org-plist-delete p :block))
  3911. (setq p (plist-put p :tstart clocktable-start))
  3912. (setq p (plist-put p :tend clocktable-end))
  3913. (setq p (plist-put p :scope 'agenda))
  3914. (setq tbl (apply 'org-clock-get-clocktable p))
  3915. (insert tbl)))
  3916. (goto-char (point-min))
  3917. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3918. (unless (or (not (get-buffer-window))
  3919. (and (pos-visible-in-window-p (point-min))
  3920. (pos-visible-in-window-p (point-max))))
  3921. (goto-char (1- (point-max)))
  3922. (recenter -1)
  3923. (when (not (pos-visible-in-window-p (or start-pos 1)))
  3924. (goto-char (or start-pos 1))
  3925. (recenter 1)))
  3926. (goto-char (or start-pos 1))
  3927. (add-text-properties (point-min) (point-max)
  3928. `(org-agenda-type agenda
  3929. org-last-args (,arg ,start-day ,span)
  3930. org-redo-cmd ,org-agenda-redo-command
  3931. org-series-cmd ,org-cmd))
  3932. (when (eq org-agenda-show-log-scoped 'clockcheck)
  3933. (org-agenda-show-clocking-issues))
  3934. (org-agenda-finalize)
  3935. (setq buffer-read-only t)
  3936. (message ""))))
  3937. (defun org-agenda-ndays-to-span (n)
  3938. "Return a span symbol for a span of N days, or N if none matches."
  3939. (cond ((symbolp n) n)
  3940. ((= n 1) 'day)
  3941. ((= n 7) 'week)
  3942. ((= n 14) 'fortnight)
  3943. (t n)))
  3944. (defun org-agenda-span-to-ndays (span &optional start-day)
  3945. "Return ndays from SPAN, possibly starting at START-DAY.
  3946. START-DAY is an absolute time value."
  3947. (cond ((numberp span) span)
  3948. ((eq span 'day) 1)
  3949. ((eq span 'week) 7)
  3950. ((eq span 'fortnight) 14)
  3951. ((eq span 'month)
  3952. (let ((date (calendar-gregorian-from-absolute start-day)))
  3953. (calendar-last-day-of-month (car date) (cl-caddr date))))
  3954. ((eq span 'year)
  3955. (let ((date (calendar-gregorian-from-absolute start-day)))
  3956. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  3957. (defun org-agenda-span-name (span)
  3958. "Return a SPAN name."
  3959. (if (null span)
  3960. ""
  3961. (if (symbolp span)
  3962. (capitalize (symbol-name span))
  3963. (format "%d days" span))))
  3964. ;;; Agenda word search
  3965. (defvar org-agenda-search-history nil)
  3966. (defvar org-search-syntax-table nil
  3967. "Special syntax table for Org search.
  3968. In this table, we have single quotes not as word constituents, to
  3969. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3970. (defvar org-mode-syntax-table) ; From org.el
  3971. (defun org-search-syntax-table ()
  3972. (unless org-search-syntax-table
  3973. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3974. (modify-syntax-entry ?' "." org-search-syntax-table)
  3975. (modify-syntax-entry ?` "." org-search-syntax-table))
  3976. org-search-syntax-table)
  3977. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3978. ;;;###autoload
  3979. (defun org-search-view (&optional todo-only string edit-at)
  3980. "Show all entries that contain a phrase or words or regular expressions.
  3981. With optional prefix argument TODO-ONLY, only consider entries that are
  3982. TODO entries. The argument STRING can be used to pass a default search
  3983. string into this function. If EDIT-AT is non-nil, it means that the
  3984. user should get a chance to edit this string, with cursor at position
  3985. EDIT-AT.
  3986. The search string can be viewed either as a phrase that should be found as
  3987. is, or it can be broken into a number of snippets, each of which must match
  3988. in a Boolean way to select an entry. The default depends on the variable
  3989. `org-agenda-search-view-always-boolean'.
  3990. Even if this is turned off (the default) you can always switch to
  3991. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3992. The default is a direct search of the whole phrase, where each space in
  3993. the search string can expand to an arbitrary amount of whitespace,
  3994. including newlines.
  3995. If using a Boolean search, the search string is split on whitespace and
  3996. each snippet is searched separately, with logical AND to select an entry.
  3997. Words prefixed with a minus must *not* occur in the entry. Words without
  3998. a prefix or prefixed with a plus must occur in the entry. Matching is
  3999. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4000. match whole words, not parts of a word) if
  4001. `org-agenda-search-view-force-full-words' is set (default is nil).
  4002. Boolean search snippets enclosed by curly braces are interpreted as
  4003. regular expressions that must or (when preceded with \"-\") must not
  4004. match in the entry. Snippets enclosed into double quotes will be taken
  4005. as a whole, to include whitespace.
  4006. - If the search string starts with an asterisk, search only in headlines.
  4007. - If (possibly after the leading star) the search string starts with an
  4008. exclamation mark, this also means to look at TODO entries only, an effect
  4009. that can also be achieved with a prefix argument.
  4010. - If (possibly after star and exclamation mark) the search string starts
  4011. with a colon, this will mean that the (non-regexp) snippets of the
  4012. Boolean search must match as full words.
  4013. This command searches the agenda files, and in addition the files
  4014. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4015. is active."
  4016. (interactive "P")
  4017. (when org-agenda-overriding-arguments
  4018. (setq todo-only (car org-agenda-overriding-arguments)
  4019. string (nth 1 org-agenda-overriding-arguments)
  4020. edit-at (nth 2 org-agenda-overriding-arguments)))
  4021. (let* ((props (list 'face nil
  4022. 'done-face 'org-agenda-done
  4023. 'org-not-done-regexp org-not-done-regexp
  4024. 'org-todo-regexp org-todo-regexp
  4025. 'org-complex-heading-regexp org-complex-heading-regexp
  4026. 'mouse-face 'highlight
  4027. 'help-echo (format "mouse-2 or RET jump to location")))
  4028. (full-words org-agenda-search-view-force-full-words)
  4029. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4030. regexp rtn rtnall files file pos inherited-tags
  4031. marker category level tags c neg re boolean
  4032. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4033. (unless (and (not edit-at)
  4034. (stringp string)
  4035. (string-match "\\S-" string))
  4036. (setq string (read-string
  4037. (if org-agenda-search-view-always-boolean
  4038. "[+-]Word/{Regexp} ...: "
  4039. "Phrase or [+-]Word/{Regexp} ...: ")
  4040. (cond
  4041. ((integerp edit-at) (cons string edit-at))
  4042. (edit-at string))
  4043. 'org-agenda-search-history)))
  4044. (catch 'exit
  4045. (when org-agenda-sticky
  4046. (setq org-agenda-buffer-name
  4047. (if (stringp string)
  4048. (format "*Org Agenda(%s:%s)*"
  4049. (or org-keys (or (and todo-only "S") "s")) string)
  4050. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4051. (org-agenda-prepare "SEARCH")
  4052. (org-compile-prefix-format 'search)
  4053. (org-set-sorting-strategy 'search)
  4054. (setq org-agenda-redo-command
  4055. (list 'org-search-view (if todo-only t nil)
  4056. (list 'if 'current-prefix-arg nil string)))
  4057. (setq org-agenda-query-string string)
  4058. (if (equal (string-to-char string) ?*)
  4059. (setq hdl-only t
  4060. words (substring string 1))
  4061. (setq words string))
  4062. (when (equal (string-to-char words) ?!)
  4063. (setq todo-only t
  4064. words (substring words 1)))
  4065. (when (equal (string-to-char words) ?:)
  4066. (setq full-words t
  4067. words (substring words 1)))
  4068. (when (or org-agenda-search-view-always-boolean
  4069. (member (string-to-char words) '(?- ?+ ?\{)))
  4070. (setq boolean t))
  4071. (setq words (split-string words))
  4072. (let (www w)
  4073. (while (setq w (pop words))
  4074. (while (and (string-match "\\\\\\'" w) words)
  4075. (setq w (concat (substring w 0 -1) " " (pop words))))
  4076. (push w www))
  4077. (setq words (nreverse www) www nil)
  4078. (while (setq w (pop words))
  4079. (when (and (string-match "\\`[-+]?{" w)
  4080. (not (string-match "}\\'" w)))
  4081. (while (and words (not (string-match "}\\'" (car words))))
  4082. (setq w (concat w " " (pop words))))
  4083. (setq w (concat w " " (pop words))))
  4084. (push w www))
  4085. (setq words (nreverse www)))
  4086. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4087. (when boolean
  4088. (let (wds w)
  4089. (while (setq w (pop words))
  4090. (when (or (equal (substring w 0 1) "\"")
  4091. (and (> (length w) 1)
  4092. (member (substring w 0 1) '("+" "-"))
  4093. (equal (substring w 1 2) "\"")))
  4094. (while (and words (not (equal (substring w -1) "\"")))
  4095. (setq w (concat w " " (pop words)))))
  4096. (and (string-match "\\`\\([-+]?\\)\"" w)
  4097. (setq w (replace-match "\\1" nil nil w)))
  4098. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4099. (push w wds))
  4100. (setq words (nreverse wds))))
  4101. (if boolean
  4102. (mapc (lambda (w)
  4103. (setq c (string-to-char w))
  4104. (if (equal c ?-)
  4105. (setq neg t w (substring w 1))
  4106. (if (equal c ?+)
  4107. (setq neg nil w (substring w 1))
  4108. (setq neg nil)))
  4109. (if (string-match "\\`{.*}\\'" w)
  4110. (setq re (substring w 1 -1))
  4111. (if full-words
  4112. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4113. (setq re (regexp-quote (downcase w)))))
  4114. (if neg (push re regexps-) (push re regexps+)))
  4115. words)
  4116. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4117. regexps+))
  4118. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4119. (if (not regexps+)
  4120. (setq regexp org-outline-regexp-bol)
  4121. (setq regexp (pop regexps+))
  4122. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4123. regexp))))
  4124. (setq files (org-agenda-files nil 'ifmode))
  4125. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4126. ;; restriction.
  4127. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4128. (pop org-agenda-text-search-extra-files)
  4129. (unless (get 'org-agenda-files 'org-restrict)
  4130. (setq files (org-add-archive-files files))))
  4131. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4132. ;; non-existent ones.
  4133. (setq files (cl-remove-duplicates
  4134. (append files org-agenda-text-search-extra-files)
  4135. :test (lambda (a b)
  4136. (and (file-exists-p a)
  4137. (file-exists-p b)
  4138. (file-equal-p a b))))
  4139. rtnall nil)
  4140. (while (setq file (pop files))
  4141. (setq ee nil)
  4142. (catch 'nextfile
  4143. (org-check-agenda-file file)
  4144. (setq buffer (if (file-exists-p file)
  4145. (org-get-agenda-file-buffer file)
  4146. (error "No such file %s" file)))
  4147. (unless buffer
  4148. ;; If file does not exist, make sure an error message is sent
  4149. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4150. file))))
  4151. (with-current-buffer buffer
  4152. (with-syntax-table (org-search-syntax-table)
  4153. (unless (derived-mode-p 'org-mode)
  4154. (error "Agenda file %s is not in Org mode" file))
  4155. (let ((case-fold-search t))
  4156. (save-excursion
  4157. (save-restriction
  4158. (if (eq buffer org-agenda-restrict)
  4159. (narrow-to-region org-agenda-restrict-begin
  4160. org-agenda-restrict-end)
  4161. (widen))
  4162. (goto-char (point-min))
  4163. (unless (or (org-at-heading-p)
  4164. (outline-next-heading))
  4165. (throw 'nextfile t))
  4166. (goto-char (max (point-min) (1- (point))))
  4167. (while (re-search-forward regexp nil t)
  4168. (org-back-to-heading t)
  4169. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4170. (> (org-reduced-level (org-outline-level))
  4171. org-agenda-search-view-max-outline-level)
  4172. (forward-line -1)
  4173. (org-back-to-heading t)))
  4174. (skip-chars-forward "* ")
  4175. (setq beg (point-at-bol)
  4176. beg1 (point)
  4177. end (progn
  4178. (outline-next-heading)
  4179. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4180. (> (org-reduced-level (org-outline-level))
  4181. org-agenda-search-view-max-outline-level)
  4182. (forward-line 1)
  4183. (outline-next-heading)))
  4184. (point)))
  4185. (catch :skip
  4186. (goto-char beg)
  4187. (org-agenda-skip)
  4188. (setq str (buffer-substring-no-properties
  4189. (point-at-bol)
  4190. (if hdl-only (point-at-eol) end)))
  4191. (mapc (lambda (wr) (when (string-match wr str)
  4192. (goto-char (1- end))
  4193. (throw :skip t)))
  4194. regexps-)
  4195. (mapc (lambda (wr) (unless (string-match wr str)
  4196. (goto-char (1- end))
  4197. (throw :skip t)))
  4198. (if todo-only
  4199. (cons (concat "^\\*+[ \t]+"
  4200. org-not-done-regexp)
  4201. regexps+)
  4202. regexps+))
  4203. (goto-char beg)
  4204. (setq marker (org-agenda-new-marker (point))
  4205. category (org-get-category)
  4206. level (make-string (org-reduced-level (org-outline-level)) ? )
  4207. inherited-tags
  4208. (or (eq org-agenda-show-inherited-tags 'always)
  4209. (and (listp org-agenda-show-inherited-tags)
  4210. (memq 'todo org-agenda-show-inherited-tags))
  4211. (and (eq org-agenda-show-inherited-tags t)
  4212. (or (eq org-agenda-use-tag-inheritance t)
  4213. (memq 'todo org-agenda-use-tag-inheritance))))
  4214. tags (org-get-tags nil (not inherited-tags))
  4215. txt (org-agenda-format-item
  4216. ""
  4217. (buffer-substring-no-properties
  4218. beg1 (point-at-eol))
  4219. level category tags t))
  4220. (org-add-props txt props
  4221. 'org-marker marker 'org-hd-marker marker
  4222. 'org-todo-regexp org-todo-regexp
  4223. 'level level
  4224. 'org-complex-heading-regexp org-complex-heading-regexp
  4225. 'priority 1000
  4226. 'type "search")
  4227. (push txt ee)
  4228. (goto-char (1- end))))))))))
  4229. (setq rtn (nreverse ee))
  4230. (setq rtnall (append rtnall rtn)))
  4231. (org-agenda--insert-overriding-header
  4232. (with-temp-buffer
  4233. (insert "Search words: ")
  4234. (add-text-properties (point-min) (1- (point))
  4235. (list 'face 'org-agenda-structure))
  4236. (setq pos (point))
  4237. (insert string "\n")
  4238. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4239. (setq pos (point))
  4240. (unless org-agenda-multi
  4241. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4242. Press `\\[org-agenda-manipulate-query-add]', \
  4243. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4244. `\\[org-agenda-manipulate-query-add-re]', \
  4245. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4246. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4247. (add-text-properties pos (1- (point))
  4248. (list 'face 'org-agenda-structure)))
  4249. (buffer-string)))
  4250. (org-agenda-mark-header-line (point-min))
  4251. (when rtnall
  4252. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4253. (goto-char (point-min))
  4254. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4255. (add-text-properties (point-min) (point-max)
  4256. `(org-agenda-type search
  4257. org-last-args (,todo-only ,string ,edit-at)
  4258. org-redo-cmd ,org-agenda-redo-command
  4259. org-series-cmd ,org-cmd))
  4260. (org-agenda-finalize)
  4261. (setq buffer-read-only t))))
  4262. ;;; Agenda TODO list
  4263. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4264. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4265. (concat
  4266. (if (or (equal keywords "ALL") (not keywords))
  4267. (propertize "ALL" 'face 'warning)
  4268. (mapconcat
  4269. (lambda (kw)
  4270. (propertize kw 'face (org-get-todo-face kw)))
  4271. (org-split-string keywords "|")
  4272. "|"))
  4273. "\n"))
  4274. (defvar org-select-this-todo-keyword nil)
  4275. (defvar org-last-arg nil)
  4276. ;;;###autoload
  4277. (defun org-todo-list (&optional arg)
  4278. "Show all (not done) TODO entries from all agenda file in a single list.
  4279. The prefix arg can be used to select a specific TODO keyword and limit
  4280. the list to these. When using `\\[universal-argument]', you will be prompted
  4281. for a keyword. A numeric prefix directly selects the Nth keyword in
  4282. `org-todo-keywords-1'."
  4283. (interactive "P")
  4284. (when org-agenda-overriding-arguments
  4285. (setq arg org-agenda-overriding-arguments))
  4286. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4287. (let* ((today (org-today))
  4288. (date (calendar-gregorian-from-absolute today))
  4289. (completion-ignore-case t)
  4290. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4291. (catch 'exit
  4292. (when org-agenda-sticky
  4293. (setq org-agenda-buffer-name
  4294. (if (stringp org-select-this-todo-keyword)
  4295. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4296. org-select-this-todo-keyword)
  4297. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4298. (org-agenda-prepare "TODO")
  4299. (setq kwds org-todo-keywords-for-agenda
  4300. org-select-this-todo-keyword (if (stringp arg) arg
  4301. (and (integerp arg)
  4302. (> arg 0)
  4303. (nth (1- arg) kwds))))
  4304. (when (equal arg '(4))
  4305. (setq org-select-this-todo-keyword
  4306. (completing-read "Keyword (or KWD1|K2D2|...): "
  4307. (mapcar #'list kwds) nil nil)))
  4308. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4309. (org-compile-prefix-format 'todo)
  4310. (org-set-sorting-strategy 'todo)
  4311. (setq org-agenda-redo-command
  4312. `(org-todo-list (or (and (numberp current-prefix-arg)
  4313. current-prefix-arg)
  4314. ,org-select-this-todo-keyword
  4315. current-prefix-arg ,arg)))
  4316. (setq files (org-agenda-files nil 'ifmode)
  4317. rtnall nil)
  4318. (while (setq file (pop files))
  4319. (catch 'nextfile
  4320. (org-check-agenda-file file)
  4321. (setq rtn (org-agenda-get-day-entries file date :todo))
  4322. (setq rtnall (append rtnall rtn))))
  4323. (org-agenda--insert-overriding-header
  4324. (with-temp-buffer
  4325. (insert "Global list of TODO items of type: ")
  4326. (add-text-properties (point-min) (1- (point))
  4327. (list 'face 'org-agenda-structure
  4328. 'short-heading
  4329. (concat "ToDo: "
  4330. (or org-select-this-todo-keyword "ALL"))))
  4331. (org-agenda-mark-header-line (point-min))
  4332. (insert (org-agenda-propertize-selected-todo-keywords
  4333. org-select-this-todo-keyword))
  4334. (setq pos (point))
  4335. (unless org-agenda-multi
  4336. (insert (substitute-command-keys "Press \
  4337. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4338. to search again: (0)[ALL]"))
  4339. (let ((n 0))
  4340. (dolist (k kwds)
  4341. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4342. (when (> (+ (current-column) (string-width s) 1) (window-width))
  4343. (insert "\n "))
  4344. (insert " " s))))
  4345. (insert "\n"))
  4346. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure))
  4347. (buffer-string)))
  4348. (org-agenda-mark-header-line (point-min))
  4349. (when rtnall
  4350. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4351. (goto-char (point-min))
  4352. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4353. (add-text-properties (point-min) (point-max)
  4354. `(org-agenda-type todo
  4355. org-last-args ,arg
  4356. org-redo-cmd ,org-agenda-redo-command
  4357. org-series-cmd ,org-cmd))
  4358. (org-agenda-finalize)
  4359. (setq buffer-read-only t))))
  4360. ;;; Agenda tags match
  4361. ;;;###autoload
  4362. (defun org-tags-view (&optional todo-only match)
  4363. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4364. The prefix arg TODO-ONLY limits the search to TODO entries."
  4365. (interactive "P")
  4366. (when org-agenda-overriding-arguments
  4367. (setq todo-only (car org-agenda-overriding-arguments)
  4368. match (nth 1 org-agenda-overriding-arguments)))
  4369. (let* ((org-tags-match-list-sublevels
  4370. org-tags-match-list-sublevels)
  4371. (completion-ignore-case t)
  4372. (org--matcher-tags-todo-only todo-only)
  4373. rtn rtnall files file pos matcher
  4374. buffer)
  4375. (when (and (stringp match) (not (string-match "\\S-" match)))
  4376. (setq match nil))
  4377. (catch 'exit
  4378. ;; TODO: this code is repeated a lot...
  4379. (when org-agenda-sticky
  4380. (setq org-agenda-buffer-name
  4381. (if (stringp match)
  4382. (format "*Org Agenda(%s:%s)*"
  4383. (or org-keys (or (and todo-only "M") "m")) match)
  4384. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4385. (setq matcher (org-make-tags-matcher match))
  4386. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4387. ;; expanding tags within `org-make-tags-matcher'
  4388. (org-agenda-prepare (concat "TAGS " match))
  4389. (setq match (car matcher)
  4390. matcher (cdr matcher))
  4391. (org-compile-prefix-format 'tags)
  4392. (org-set-sorting-strategy 'tags)
  4393. (setq org-agenda-query-string match)
  4394. (setq org-agenda-redo-command
  4395. (list 'org-tags-view
  4396. `(quote ,org--matcher-tags-todo-only)
  4397. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4398. (setq files (org-agenda-files nil 'ifmode)
  4399. rtnall nil)
  4400. (while (setq file (pop files))
  4401. (catch 'nextfile
  4402. (org-check-agenda-file file)
  4403. (setq buffer (if (file-exists-p file)
  4404. (org-get-agenda-file-buffer file)
  4405. (error "No such file %s" file)))
  4406. (if (not buffer)
  4407. ;; If file does not exist, error message to agenda
  4408. (setq rtn (list
  4409. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4410. rtnall (append rtnall rtn))
  4411. (with-current-buffer buffer
  4412. (unless (derived-mode-p 'org-mode)
  4413. (error "Agenda file %s is not in Org mode" file))
  4414. (save-excursion
  4415. (save-restriction
  4416. (if (eq buffer org-agenda-restrict)
  4417. (narrow-to-region org-agenda-restrict-begin
  4418. org-agenda-restrict-end)
  4419. (widen))
  4420. (setq rtn (org-scan-tags 'agenda
  4421. matcher
  4422. org--matcher-tags-todo-only))
  4423. (setq rtnall (append rtnall rtn))))))))
  4424. (org-agenda--insert-overriding-header
  4425. (with-temp-buffer
  4426. (insert "Headlines with TAGS match: ")
  4427. (add-text-properties (point-min) (1- (point))
  4428. (list 'face 'org-agenda-structure
  4429. 'short-heading
  4430. (concat "Match: " match)))
  4431. (setq pos (point))
  4432. (insert match "\n")
  4433. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4434. (setq pos (point))
  4435. (unless org-agenda-multi
  4436. (insert (substitute-command-keys
  4437. "Press \
  4438. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4439. to search again\n")))
  4440. (add-text-properties pos (1- (point))
  4441. (list 'face 'org-agenda-structure))
  4442. (buffer-string)))
  4443. (org-agenda-mark-header-line (point-min))
  4444. (when rtnall
  4445. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4446. (goto-char (point-min))
  4447. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4448. (add-text-properties
  4449. (point-min) (point-max)
  4450. `(org-agenda-type tags
  4451. org-last-args (,org--matcher-tags-todo-only ,match)
  4452. org-redo-cmd ,org-agenda-redo-command
  4453. org-series-cmd ,org-cmd))
  4454. (org-agenda-finalize)
  4455. (setq buffer-read-only t))))
  4456. ;;; Agenda Finding stuck projects
  4457. (defvar org-agenda-skip-regexp nil
  4458. "Regular expression used in skipping subtrees for the agenda.
  4459. This is basically a temporary global variable that can be set and then
  4460. used by user-defined selections using `org-agenda-skip-function'.")
  4461. (defvar org-agenda-overriding-header nil
  4462. "When set during agenda, todo and tags searches it replaces the header.
  4463. If an empty string, no header will be inserted. If any other
  4464. string, it will be inserted as a header. If nil, a header will
  4465. be generated automatically according to the command. This
  4466. variable should not be set directly, but custom commands can bind
  4467. it in the options section.")
  4468. (defun org-agenda-skip-entry-if (&rest conditions)
  4469. "Skip entry if any of CONDITIONS is true.
  4470. See `org-agenda-skip-if' for details."
  4471. (org-agenda-skip-if nil conditions))
  4472. (defun org-agenda-skip-subtree-if (&rest conditions)
  4473. "Skip subtree if any of CONDITIONS is true.
  4474. See `org-agenda-skip-if' for details."
  4475. (org-agenda-skip-if t conditions))
  4476. (defun org-agenda-skip-if (subtree conditions)
  4477. "Checks current entity for CONDITIONS.
  4478. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4479. the entry (i.e. the text before the next heading) is checked.
  4480. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4481. from different tests. Valid conditions are:
  4482. scheduled Check if there is a scheduled cookie
  4483. notscheduled Check if there is no scheduled cookie
  4484. deadline Check if there is a deadline
  4485. notdeadline Check if there is no deadline
  4486. timestamp Check if there is a timestamp (also deadline or scheduled)
  4487. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4488. regexp Check if regexp matches
  4489. notregexp Check if regexp does not match.
  4490. todo Check if TODO keyword matches
  4491. nottodo Check if TODO keyword does not match
  4492. The regexp is taken from the conditions list, it must come right after
  4493. the `regexp' or `notregexp' element.
  4494. `todo' and `nottodo' accept as an argument a list of todo
  4495. keywords, which may include \"*\" to match any todo keyword.
  4496. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4497. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4498. Instead of a list, a keyword class may be given. For example:
  4499. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4500. would skip entries that haven't been marked with any of \"DONE\"
  4501. keywords. Possible classes are: `todo', `done', `any'.
  4502. If any of these conditions is met, this function returns the end point of
  4503. the entity, causing the search to continue from there. This is a function
  4504. that can be put into `org-agenda-skip-function' for the duration of a command."
  4505. (org-back-to-heading t)
  4506. (let* ((beg (point))
  4507. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4508. (org-entry-end-position)))
  4509. (planning-end (if subtree end (line-end-position 2)))
  4510. m)
  4511. (and
  4512. (or (and (memq 'scheduled conditions)
  4513. (re-search-forward org-scheduled-time-regexp planning-end t))
  4514. (and (memq 'notscheduled conditions)
  4515. (not
  4516. (save-excursion
  4517. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4518. (and (memq 'deadline conditions)
  4519. (re-search-forward org-deadline-time-regexp planning-end t))
  4520. (and (memq 'notdeadline conditions)
  4521. (not
  4522. (save-excursion
  4523. (re-search-forward org-deadline-time-regexp planning-end t))))
  4524. (and (memq 'timestamp conditions)
  4525. (re-search-forward org-ts-regexp end t))
  4526. (and (memq 'nottimestamp conditions)
  4527. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4528. (and (setq m (memq 'regexp conditions))
  4529. (stringp (nth 1 m))
  4530. (re-search-forward (nth 1 m) end t))
  4531. (and (setq m (memq 'notregexp conditions))
  4532. (stringp (nth 1 m))
  4533. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4534. (and (or
  4535. (setq m (memq 'nottodo conditions))
  4536. (setq m (memq 'todo-unblocked conditions))
  4537. (setq m (memq 'nottodo-unblocked conditions))
  4538. (setq m (memq 'todo conditions)))
  4539. (org-agenda-skip-if-todo m end)))
  4540. end)))
  4541. (defun org-agenda-skip-if-todo (args end)
  4542. "Helper function for `org-agenda-skip-if', do not use it directly.
  4543. ARGS is a list with first element either `todo', `nottodo',
  4544. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4545. a list of TODO keywords, or a state symbol `todo' or `done' or
  4546. `any'."
  4547. (let ((todo-re
  4548. (concat "^\\*+[ \t]+"
  4549. (regexp-opt
  4550. (pcase args
  4551. (`(,_ todo)
  4552. (org-delete-all org-done-keywords
  4553. (copy-sequence org-todo-keywords-1)))
  4554. (`(,_ done) org-done-keywords)
  4555. (`(,_ any) org-todo-keywords-1)
  4556. (`(,_ ,(pred atom))
  4557. (error "Invalid TODO class or type: %S" args))
  4558. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4559. (`(,_ ,todo-list) todo-list))
  4560. 'words))))
  4561. (pcase args
  4562. (`(todo . ,_)
  4563. (let (case-fold-search) (re-search-forward todo-re end t)))
  4564. (`(nottodo . ,_)
  4565. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4566. (`(todo-unblocked . ,_)
  4567. (catch :unblocked
  4568. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4569. (when (org-entry-blocked-p) (throw :unblocked t)))
  4570. nil))
  4571. (`(nottodo-unblocked . ,_)
  4572. (catch :unblocked
  4573. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4574. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4575. t))
  4576. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4577. ;;;###autoload
  4578. (defun org-agenda-list-stuck-projects (&rest ignore)
  4579. "Create agenda view for projects that are stuck.
  4580. Stuck projects are project that have no next actions. For the definitions
  4581. of what a project is and how to check if it stuck, customize the variable
  4582. `org-stuck-projects'."
  4583. (interactive)
  4584. (let* ((org-agenda-overriding-header
  4585. (or org-agenda-overriding-header "List of stuck projects: "))
  4586. (matcher (nth 0 org-stuck-projects))
  4587. (todo (nth 1 org-stuck-projects))
  4588. (tags (nth 2 org-stuck-projects))
  4589. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4590. (todo-wds
  4591. (if (not (member "*" todo)) todo
  4592. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4593. (org-delete-all org-done-keywords-for-agenda
  4594. (copy-sequence org-todo-keywords-for-agenda))))
  4595. (todo-re (and todo
  4596. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4597. (mapconcat #'identity todo-wds "\\|"))))
  4598. (tags-re (cond ((null tags) nil)
  4599. ((member "*" tags) org-tag-line-re)
  4600. (tags
  4601. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4602. (concat org-outline-regexp-bol
  4603. ".*?[ \t]:"
  4604. other-tags
  4605. (regexp-opt tags t)
  4606. ":" other-tags "[ \t]*$")))
  4607. (t nil)))
  4608. (re-list (delq nil (list todo-re tags-re gen-re)))
  4609. (skip-re
  4610. (if (null re-list)
  4611. (error "Missing information to identify unstuck projects")
  4612. (mapconcat #'identity re-list "\\|")))
  4613. (org-agenda-skip-function
  4614. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4615. ;; in the subtree.
  4616. `(lambda ()
  4617. (and (save-excursion
  4618. (let ((case-fold-search nil))
  4619. (re-search-forward
  4620. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4621. (progn (outline-next-heading) (point))))))
  4622. (org-tags-view nil matcher)
  4623. (setq org-agenda-buffer-name (buffer-name))
  4624. (with-current-buffer org-agenda-buffer-name
  4625. (setq org-agenda-redo-command
  4626. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4627. (let ((inhibit-read-only t))
  4628. (add-text-properties
  4629. (point-min) (point-max)
  4630. `(org-redo-cmd ,org-agenda-redo-command))))))
  4631. ;;; Diary integration
  4632. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4633. (defvar diary-list-entries-hook)
  4634. (defvar diary-time-regexp)
  4635. (defun org-get-entries-from-diary (date)
  4636. "Get the (Emacs Calendar) diary entries for DATE."
  4637. (require 'diary-lib)
  4638. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4639. (diary-display-function 'diary-fancy-display)
  4640. (pop-up-frames nil)
  4641. (diary-list-entries-hook
  4642. (cons 'org-diary-default-entry diary-list-entries-hook))
  4643. (diary-file-name-prefix nil) ; turn this feature off
  4644. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4645. entries
  4646. (org-disable-agenda-to-diary t))
  4647. (save-excursion
  4648. (save-window-excursion
  4649. (funcall (if (fboundp 'diary-list-entries)
  4650. 'diary-list-entries 'list-diary-entries)
  4651. date 1)))
  4652. (if (not (get-buffer diary-fancy-buffer))
  4653. (setq entries nil)
  4654. (with-current-buffer diary-fancy-buffer
  4655. (setq buffer-read-only nil)
  4656. (if (zerop (buffer-size))
  4657. ;; No entries
  4658. (setq entries nil)
  4659. ;; Omit the date and other unnecessary stuff
  4660. (org-agenda-cleanup-fancy-diary)
  4661. ;; Add prefix to each line and extend the text properties
  4662. (if (zerop (buffer-size))
  4663. (setq entries nil)
  4664. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4665. (setq entries
  4666. (with-temp-buffer
  4667. (insert entries) (goto-char (point-min))
  4668. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4669. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4670. (replace-match (concat "; " (match-string 1)))))
  4671. (buffer-string)))))
  4672. (set-buffer-modified-p nil)
  4673. (kill-buffer diary-fancy-buffer)))
  4674. (when entries
  4675. (setq entries (org-split-string entries "\n"))
  4676. (setq entries
  4677. (mapcar
  4678. (lambda (x)
  4679. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4680. ;; Extend the text properties to the beginning of the line
  4681. (org-add-props x (text-properties-at (1- (length x)) x)
  4682. 'type "diary" 'date date 'face 'org-agenda-diary))
  4683. entries)))))
  4684. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4685. "Hook run when the fancy diary buffer is cleaned up.")
  4686. (defun org-agenda-cleanup-fancy-diary ()
  4687. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4688. This gets rid of the date, the underline under the date, and the
  4689. dummy entry installed by Org mode to ensure non-empty diary for
  4690. each date. It also removes lines that contain only whitespace."
  4691. (goto-char (point-min))
  4692. (if (looking-at ".*?:[ \t]*")
  4693. (progn
  4694. (replace-match "")
  4695. (re-search-forward "\n=+$" nil t)
  4696. (replace-match "")
  4697. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4698. (re-search-forward "\n=+$" nil t)
  4699. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4700. (goto-char (point-min))
  4701. (while (re-search-forward "^ +\n" nil t)
  4702. (replace-match ""))
  4703. (goto-char (point-min))
  4704. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4705. (replace-match ""))
  4706. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4707. (defun org-modify-diary-entry-string (string)
  4708. "Add text properties to string, allowing Org to act on it."
  4709. (org-add-props string nil
  4710. 'mouse-face 'highlight
  4711. 'help-echo (if buffer-file-name
  4712. (format "mouse-2 or RET jump to diary file %s"
  4713. (abbreviate-file-name buffer-file-name))
  4714. "")
  4715. 'org-agenda-diary-link t
  4716. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4717. (defun org-diary-default-entry ()
  4718. "Add a dummy entry to the diary.
  4719. Needed to avoid empty dates which mess up holiday display."
  4720. ;; Catch the error if dealing with the new add-to-diary-alist
  4721. (when org-disable-agenda-to-diary
  4722. (condition-case nil
  4723. (org-add-to-diary-list original-date "Org mode dummy" "")
  4724. (error
  4725. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4726. (defun org-add-to-diary-list (&rest args)
  4727. (if (fboundp 'diary-add-to-list)
  4728. (apply 'diary-add-to-list args)
  4729. (apply 'add-to-diary-list args)))
  4730. (defvar org-diary-last-run-time nil)
  4731. ;;;###autoload
  4732. (defun org-diary (&rest args)
  4733. "Return diary information from org files.
  4734. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4735. It accesses org files and extracts information from those files to be
  4736. listed in the diary. The function accepts arguments specifying what
  4737. items should be listed. For a list of arguments allowed here, see the
  4738. variable `org-agenda-entry-types'.
  4739. The call in the diary file should look like this:
  4740. &%%(org-diary) ~/path/to/some/orgfile.org
  4741. Use a separate line for each org file to check. Or, if you omit the file name,
  4742. all files listed in `org-agenda-files' will be checked automatically:
  4743. &%%(org-diary)
  4744. If you don't give any arguments (as in the example above), the default value
  4745. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4746. So the example above may also be written as
  4747. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4748. The function expects the lisp variables `entry' and `date' to be provided
  4749. by the caller, because this is how the calendar works. Don't use this
  4750. function from a program - use `org-agenda-get-day-entries' instead."
  4751. (when (> (- (float-time)
  4752. org-agenda-last-marker-time)
  4753. 5)
  4754. ;; I am not sure if this works with sticky agendas, because the marker
  4755. ;; list is then no longer a global variable.
  4756. (org-agenda-reset-markers))
  4757. (org-compile-prefix-format 'agenda)
  4758. (org-set-sorting-strategy 'agenda)
  4759. (setq args (or args org-agenda-entry-types))
  4760. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4761. (list entry)
  4762. (org-agenda-files t)))
  4763. (time (float-time))
  4764. file rtn results)
  4765. (when (or (not org-diary-last-run-time)
  4766. (> (- time
  4767. org-diary-last-run-time)
  4768. 3))
  4769. (org-agenda-prepare-buffers files))
  4770. (setq org-diary-last-run-time time)
  4771. ;; If this is called during org-agenda, don't return any entries to
  4772. ;; the calendar. Org Agenda will list these entries itself.
  4773. (when org-disable-agenda-to-diary (setq files nil))
  4774. (while (setq file (pop files))
  4775. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4776. (setq results (append results rtn)))
  4777. (when results
  4778. (setq results
  4779. (mapcar (lambda (i) (replace-regexp-in-string
  4780. org-link-bracket-re "\\2" i)) results))
  4781. (concat (org-agenda-finalize-entries results) "\n"))))
  4782. ;;; Agenda entry finders
  4783. (defun org-agenda--timestamp-to-absolute (&rest args)
  4784. "Call `org-time-string-to-absolute' with ARGS.
  4785. However, throw `:skip' whenever an error is raised."
  4786. (condition-case e
  4787. (apply #'org-time-string-to-absolute args)
  4788. (org-diary-sexp-no-match (throw :skip nil))
  4789. (error
  4790. (message "%s; Skipping entry" (error-message-string e))
  4791. (throw :skip nil))))
  4792. (defun org-agenda-get-day-entries (file date &rest args)
  4793. "Does the work for `org-diary' and `org-agenda'.
  4794. FILE is the path to a file to be checked for entries. DATE is date like
  4795. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4796. which kind of entries should be extracted. For details about these, see
  4797. the documentation of `org-diary'."
  4798. (let* ((org-startup-folded nil)
  4799. (org-startup-align-all-tables nil)
  4800. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4801. (error "No such file %s" file))))
  4802. (if (not buffer)
  4803. ;; If file does not exist, signal it in diary nonetheless.
  4804. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4805. (with-current-buffer buffer
  4806. (unless (derived-mode-p 'org-mode)
  4807. (error "Agenda file %s is not in Org mode" file))
  4808. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4809. (setf org-agenda-current-date date)
  4810. (save-excursion
  4811. (save-restriction
  4812. (if (eq buffer org-agenda-restrict)
  4813. (narrow-to-region org-agenda-restrict-begin
  4814. org-agenda-restrict-end)
  4815. (widen))
  4816. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4817. ;; first in order to populate DEADLINES before passing it.
  4818. ;;
  4819. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4820. ;; guarding us from modifying `org-agenda-entry-types'.
  4821. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4822. (when (and (memq :scheduled args) (memq :scheduled* args))
  4823. (setf args (delq :scheduled* args)))
  4824. (cond
  4825. ((memq :deadline args)
  4826. (setf args (cons :deadline
  4827. (delq :deadline (delq :deadline* args)))))
  4828. ((memq :deadline* args)
  4829. (setf args (cons :deadline* (delq :deadline* args)))))
  4830. ;; Collect list of headlines. Return them flattened.
  4831. (let ((case-fold-search nil) results deadlines)
  4832. (dolist (arg args (apply #'nconc (nreverse results)))
  4833. (pcase arg
  4834. ((and :todo (guard (org-agenda-today-p date)))
  4835. (push (org-agenda-get-todos) results))
  4836. (:timestamp
  4837. (push (org-agenda-get-blocks) results)
  4838. (push (org-agenda-get-timestamps deadlines) results))
  4839. (:sexp
  4840. (push (org-agenda-get-sexps) results))
  4841. (:scheduled
  4842. (push (org-agenda-get-scheduled deadlines) results))
  4843. (:scheduled*
  4844. (push (org-agenda-get-scheduled deadlines t) results))
  4845. (:closed
  4846. (push (org-agenda-get-progress) results))
  4847. (:deadline
  4848. (setf deadlines (org-agenda-get-deadlines))
  4849. (push deadlines results))
  4850. (:deadline*
  4851. (setf deadlines (org-agenda-get-deadlines t))
  4852. (push deadlines results)))))))))))
  4853. (defsubst org-em (x y list)
  4854. "Is X or Y a member of LIST?"
  4855. (or (memq x list) (memq y list)))
  4856. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4857. (defvar org-agenda-sorting-strategy-selected nil)
  4858. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4859. "Retrieve timestamp information for sorting agenda views.
  4860. Given a point or marker POM, returns a cons cell of the timestamp
  4861. and the timestamp type relevant for the sorting strategy in
  4862. `org-agenda-sorting-strategy-selected'."
  4863. (let (ts ts-date-type)
  4864. (save-match-data
  4865. (cond ((org-em 'scheduled-up 'scheduled-down
  4866. org-agenda-sorting-strategy-selected)
  4867. (setq ts (org-entry-get pom "SCHEDULED")
  4868. ts-date-type " scheduled"))
  4869. ((org-em 'deadline-up 'deadline-down
  4870. org-agenda-sorting-strategy-selected)
  4871. (setq ts (org-entry-get pom "DEADLINE")
  4872. ts-date-type " deadline"))
  4873. ((org-em 'ts-up 'ts-down
  4874. org-agenda-sorting-strategy-selected)
  4875. (setq ts (org-entry-get pom "TIMESTAMP")
  4876. ts-date-type " timestamp"))
  4877. ((org-em 'tsia-up 'tsia-down
  4878. org-agenda-sorting-strategy-selected)
  4879. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4880. ts-date-type " timestamp_ia"))
  4881. ((org-em 'timestamp-up 'timestamp-down
  4882. org-agenda-sorting-strategy-selected)
  4883. (setq ts (or (org-entry-get pom "SCHEDULED")
  4884. (org-entry-get pom "DEADLINE")
  4885. (org-entry-get pom "TIMESTAMP")
  4886. (org-entry-get pom "TIMESTAMP_IA"))
  4887. ts-date-type ""))
  4888. (t (setq ts-date-type "")))
  4889. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4890. ts-date-type))))
  4891. (defun org-agenda-get-todos ()
  4892. "Return the TODO information for agenda display."
  4893. (let* ((props (list 'face nil
  4894. 'done-face 'org-agenda-done
  4895. 'org-not-done-regexp org-not-done-regexp
  4896. 'org-todo-regexp org-todo-regexp
  4897. 'org-complex-heading-regexp org-complex-heading-regexp
  4898. 'mouse-face 'highlight
  4899. 'help-echo
  4900. (format "mouse-2 or RET jump to org file %s"
  4901. (abbreviate-file-name buffer-file-name))))
  4902. (case-fold-search nil)
  4903. (regexp (format org-heading-keyword-regexp-format
  4904. (cond
  4905. ((and org-select-this-todo-keyword
  4906. (equal org-select-this-todo-keyword "*"))
  4907. org-todo-regexp)
  4908. (org-select-this-todo-keyword
  4909. (concat "\\("
  4910. (mapconcat 'identity
  4911. (org-split-string
  4912. org-select-this-todo-keyword
  4913. "|")
  4914. "\\|") "\\)"))
  4915. (t org-not-done-regexp))))
  4916. marker priority category level tags todo-state
  4917. ts-date ts-date-type ts-date-pair
  4918. ee txt beg end inherited-tags todo-state-end-pos)
  4919. (goto-char (point-min))
  4920. (while (re-search-forward regexp nil t)
  4921. (catch :skip
  4922. (save-match-data
  4923. (beginning-of-line)
  4924. (org-agenda-skip)
  4925. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4926. (unless (and (setq todo-state (org-get-todo-state))
  4927. (setq todo-state-end-pos (match-end 2)))
  4928. (goto-char end)
  4929. (throw :skip nil))
  4930. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4931. (goto-char (1+ beg))
  4932. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4933. (throw :skip nil)))
  4934. (goto-char (match-beginning 2))
  4935. (setq marker (org-agenda-new-marker (match-beginning 0))
  4936. category (org-get-category)
  4937. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  4938. ts-date (car ts-date-pair)
  4939. ts-date-type (cdr ts-date-pair)
  4940. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  4941. inherited-tags
  4942. (or (eq org-agenda-show-inherited-tags 'always)
  4943. (and (listp org-agenda-show-inherited-tags)
  4944. (memq 'todo org-agenda-show-inherited-tags))
  4945. (and (eq org-agenda-show-inherited-tags t)
  4946. (or (eq org-agenda-use-tag-inheritance t)
  4947. (memq 'todo org-agenda-use-tag-inheritance))))
  4948. tags (org-get-tags nil (not inherited-tags))
  4949. level (make-string (org-reduced-level (org-outline-level)) ? )
  4950. txt (org-agenda-format-item "" txt level category tags t)
  4951. priority (1+ (org-get-priority txt)))
  4952. (org-add-props txt props
  4953. 'org-marker marker 'org-hd-marker marker
  4954. 'priority priority
  4955. 'level level
  4956. 'ts-date ts-date
  4957. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4958. (push txt ee)
  4959. (if org-agenda-todo-list-sublevels
  4960. (goto-char todo-state-end-pos)
  4961. (org-end-of-subtree 'invisible))))
  4962. (nreverse ee)))
  4963. (defun org-agenda-todo-custom-ignore-p (time n)
  4964. "Check whether timestamp is farther away than n number of days.
  4965. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4966. `org-agenda-todo-ignore-scheduled' or
  4967. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4968. (let ((days (org-time-stamp-to-now
  4969. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4970. (if (>= n 0)
  4971. (>= days n)
  4972. (<= days n))))
  4973. ;;;###autoload
  4974. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4975. (&optional end)
  4976. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4977. (when (or org-agenda-todo-ignore-with-date
  4978. org-agenda-todo-ignore-scheduled
  4979. org-agenda-todo-ignore-deadlines
  4980. org-agenda-todo-ignore-timestamp)
  4981. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4982. (save-excursion
  4983. (or (and org-agenda-todo-ignore-with-date
  4984. (re-search-forward org-ts-regexp end t))
  4985. (and org-agenda-todo-ignore-scheduled
  4986. (re-search-forward org-scheduled-time-regexp end t)
  4987. (cond
  4988. ((eq org-agenda-todo-ignore-scheduled 'future)
  4989. (> (org-time-stamp-to-now
  4990. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4991. ((eq org-agenda-todo-ignore-scheduled 'past)
  4992. (<= (org-time-stamp-to-now
  4993. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4994. ((numberp org-agenda-todo-ignore-scheduled)
  4995. (org-agenda-todo-custom-ignore-p
  4996. (match-string 1) org-agenda-todo-ignore-scheduled))
  4997. (t)))
  4998. (and org-agenda-todo-ignore-deadlines
  4999. (re-search-forward org-deadline-time-regexp end t)
  5000. (cond
  5001. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5002. ((eq org-agenda-todo-ignore-deadlines 'far)
  5003. (not (org-deadline-close-p (match-string 1))))
  5004. ((eq org-agenda-todo-ignore-deadlines 'future)
  5005. (> (org-time-stamp-to-now
  5006. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5007. ((eq org-agenda-todo-ignore-deadlines 'past)
  5008. (<= (org-time-stamp-to-now
  5009. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5010. ((numberp org-agenda-todo-ignore-deadlines)
  5011. (org-agenda-todo-custom-ignore-p
  5012. (match-string 1) org-agenda-todo-ignore-deadlines))
  5013. (t (org-deadline-close-p (match-string 1)))))
  5014. (and org-agenda-todo-ignore-timestamp
  5015. (let ((buffer (current-buffer))
  5016. (regexp
  5017. (concat
  5018. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5019. (start (point)))
  5020. ;; Copy current buffer into a temporary one
  5021. (with-temp-buffer
  5022. (insert-buffer-substring buffer start end)
  5023. (goto-char (point-min))
  5024. ;; Delete SCHEDULED and DEADLINE items
  5025. (while (re-search-forward regexp end t)
  5026. (delete-region (match-beginning 0) (match-end 0)))
  5027. (goto-char (point-min))
  5028. ;; No search for timestamp left
  5029. (when (re-search-forward org-ts-regexp nil t)
  5030. (cond
  5031. ((eq org-agenda-todo-ignore-timestamp 'future)
  5032. (> (org-time-stamp-to-now
  5033. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5034. ((eq org-agenda-todo-ignore-timestamp 'past)
  5035. (<= (org-time-stamp-to-now
  5036. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5037. ((numberp org-agenda-todo-ignore-timestamp)
  5038. (org-agenda-todo-custom-ignore-p
  5039. (match-string 1) org-agenda-todo-ignore-timestamp))
  5040. (t))))))))))
  5041. (defun org-agenda-get-timestamps (&optional deadlines)
  5042. "Return the date stamp information for agenda display.
  5043. Optional argument DEADLINES is a list of deadline items to be
  5044. displayed in agenda view."
  5045. (let* ((props (list 'face 'org-agenda-calendar-event
  5046. 'org-not-done-regexp org-not-done-regexp
  5047. 'org-todo-regexp org-todo-regexp
  5048. 'org-complex-heading-regexp org-complex-heading-regexp
  5049. 'mouse-face 'highlight
  5050. 'help-echo
  5051. (format "mouse-2 or RET jump to Org file %s"
  5052. (abbreviate-file-name buffer-file-name))))
  5053. (current (calendar-absolute-from-gregorian date))
  5054. (today (org-today))
  5055. (deadline-position-alist
  5056. (mapcar (lambda (d)
  5057. (let ((m (get-text-property 0 'org-hd-marker d)))
  5058. (and m (marker-position m))))
  5059. deadlines))
  5060. ;; Match time-stamps set to current date, time-stamps with
  5061. ;; a repeater, and S-exp time-stamps.
  5062. (regexp
  5063. (concat
  5064. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5065. (regexp-quote
  5066. (substring
  5067. (format-time-string
  5068. (car org-time-stamp-formats)
  5069. (apply #'encode-time ; DATE bound by calendar
  5070. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5071. 1 11))
  5072. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5073. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5074. timestamp-items)
  5075. (goto-char (point-min))
  5076. (while (re-search-forward regexp nil t)
  5077. ;; Skip date ranges, scheduled and deadlines, which are handled
  5078. ;; specially. Also skip time-stamps before first headline as
  5079. ;; there would be no entry to add to the agenda. Eventually,
  5080. ;; ignore clock entries.
  5081. (catch :skip
  5082. (save-match-data
  5083. (when (or (org-at-date-range-p)
  5084. (org-at-planning-p)
  5085. (org-before-first-heading-p)
  5086. (and org-agenda-include-inactive-timestamps
  5087. (org-at-clock-log-p)))
  5088. (throw :skip nil))
  5089. (org-agenda-skip))
  5090. (let* ((pos (match-beginning 0))
  5091. (repeat (match-string 1))
  5092. (sexp-entry (match-string 3))
  5093. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5094. (save-excursion
  5095. (goto-char pos)
  5096. (looking-at org-ts-regexp-both)
  5097. (match-string 0))))
  5098. (todo-state (org-get-todo-state))
  5099. (warntime (get-text-property (point) 'org-appt-warntime))
  5100. (done? (member todo-state org-done-keywords)))
  5101. ;; Possibly skip done tasks.
  5102. (when (and done? org-agenda-skip-timestamp-if-done)
  5103. (throw :skip t))
  5104. ;; S-exp entry doesn't match current day: skip it.
  5105. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5106. (throw :skip nil))
  5107. (when repeat
  5108. (let* ((past
  5109. ;; A repeating time stamp is shown at its base
  5110. ;; date and every repeated date up to TODAY. If
  5111. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5112. ;; however, only the last repeat before today
  5113. ;; (inclusive) is shown.
  5114. (org-agenda--timestamp-to-absolute
  5115. repeat
  5116. (if (or (> current today)
  5117. (eq org-agenda-prefer-last-repeat t)
  5118. (member todo-state org-agenda-prefer-last-repeat))
  5119. today
  5120. current)
  5121. 'past (current-buffer) pos))
  5122. (future
  5123. ;; Display every repeated date past TODAY
  5124. ;; (exclusive) unless
  5125. ;; `org-agenda-show-future-repeats' is nil. If
  5126. ;; this variable is set to `next', only display
  5127. ;; the first repeated date after TODAY
  5128. ;; (exclusive).
  5129. (cond
  5130. ((<= current today) past)
  5131. ((not org-agenda-show-future-repeats) past)
  5132. (t
  5133. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5134. (1+ today)
  5135. current)))
  5136. (org-agenda--timestamp-to-absolute
  5137. repeat base 'future (current-buffer) pos))))))
  5138. (when (and (/= current past) (/= current future))
  5139. (throw :skip nil))))
  5140. (save-excursion
  5141. (re-search-backward org-outline-regexp-bol nil t)
  5142. ;; Possibly skip time-stamp when a deadline is set.
  5143. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5144. (assq (point) deadline-position-alist))
  5145. (throw :skip nil))
  5146. (let* ((category (org-get-category pos))
  5147. (inherited-tags
  5148. (or (eq org-agenda-show-inherited-tags 'always)
  5149. (and (consp org-agenda-show-inherited-tags)
  5150. (memq 'agenda org-agenda-show-inherited-tags))
  5151. (and (eq org-agenda-show-inherited-tags t)
  5152. (or (eq org-agenda-use-tag-inheritance t)
  5153. (memq 'agenda
  5154. org-agenda-use-tag-inheritance)))))
  5155. (tags (org-get-tags nil (not inherited-tags)))
  5156. (level (make-string (org-reduced-level (org-outline-level))
  5157. ?\s))
  5158. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5159. (match-string 1)))
  5160. (inactive? (= (char-after pos) ?\[))
  5161. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5162. (item
  5163. (org-agenda-format-item
  5164. (and inactive? org-agenda-inactive-leader)
  5165. head level category tags time-stamp org-ts-regexp habit?)))
  5166. (org-add-props item props
  5167. 'priority (if habit?
  5168. (org-habit-get-priority (org-habit-parse-todo))
  5169. (org-get-priority item))
  5170. 'org-marker (org-agenda-new-marker pos)
  5171. 'org-hd-marker (org-agenda-new-marker)
  5172. 'date date
  5173. 'level level
  5174. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5175. current)
  5176. 'todo-state todo-state
  5177. 'warntime warntime
  5178. 'type "timestamp")
  5179. (push item timestamp-items))))
  5180. (when org-agenda-skip-additional-timestamps-same-entry
  5181. (outline-next-heading))))
  5182. (nreverse timestamp-items)))
  5183. (defun org-agenda-get-sexps ()
  5184. "Return the sexp information for agenda display."
  5185. (require 'diary-lib)
  5186. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5187. 'mouse-face 'highlight
  5188. 'help-echo
  5189. (format "mouse-2 or RET jump to org file %s"
  5190. (abbreviate-file-name buffer-file-name))))
  5191. (regexp "^&?%%(")
  5192. marker category extra level ee txt tags entry
  5193. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5194. (goto-char (point-min))
  5195. (while (re-search-forward regexp nil t)
  5196. (catch :skip
  5197. (org-agenda-skip)
  5198. (setq beg (match-beginning 0))
  5199. (goto-char (1- (match-end 0)))
  5200. (setq b (point))
  5201. (forward-sexp 1)
  5202. (setq sexp (buffer-substring b (point)))
  5203. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5204. (org-trim (match-string 1))
  5205. ""))
  5206. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5207. (when result
  5208. (setq marker (org-agenda-new-marker beg)
  5209. level (make-string (org-reduced-level (org-outline-level)) ? )
  5210. category (org-get-category beg)
  5211. inherited-tags
  5212. (or (eq org-agenda-show-inherited-tags 'always)
  5213. (and (listp org-agenda-show-inherited-tags)
  5214. (memq 'agenda org-agenda-show-inherited-tags))
  5215. (and (eq org-agenda-show-inherited-tags t)
  5216. (or (eq org-agenda-use-tag-inheritance t)
  5217. (memq 'agenda org-agenda-use-tag-inheritance))))
  5218. tags (org-get-tags nil (not inherited-tags))
  5219. todo-state (org-get-todo-state)
  5220. warntime (get-text-property (point) 'org-appt-warntime)
  5221. extra nil)
  5222. (dolist (r (if (stringp result)
  5223. (list result)
  5224. result)) ;; we expect a list here
  5225. (when (and org-agenda-diary-sexp-prefix
  5226. (string-match org-agenda-diary-sexp-prefix r))
  5227. (setq extra (match-string 0 r)
  5228. r (replace-match "" nil nil r)))
  5229. (if (string-match "\\S-" r)
  5230. (setq txt r)
  5231. (setq txt "SEXP entry returned empty string"))
  5232. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5233. (org-add-props txt props 'org-marker marker
  5234. 'date date 'todo-state todo-state
  5235. 'level level 'type "sexp" 'warntime warntime)
  5236. (push txt ee)))))
  5237. (nreverse ee)))
  5238. ;; Calendar sanity: define some functions that are independent of
  5239. ;; `calendar-date-style'.
  5240. (defun org-anniversary (year month day &optional mark)
  5241. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5242. (with-no-warnings
  5243. (let ((calendar-date-style 'iso))
  5244. (diary-anniversary year month day mark))))
  5245. (defun org-cyclic (N year month day &optional mark)
  5246. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5247. (with-no-warnings
  5248. (let ((calendar-date-style 'iso))
  5249. (diary-cyclic N year month day mark))))
  5250. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5251. "Like `diary-block', but with fixed (ISO) order of arguments."
  5252. (with-no-warnings
  5253. (let ((calendar-date-style 'iso))
  5254. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5255. (defun org-date (year month day &optional mark)
  5256. "Like `diary-date', but with fixed (ISO) order of arguments."
  5257. (with-no-warnings
  5258. (let ((calendar-date-style 'iso))
  5259. (diary-date year month day mark))))
  5260. ;; Define the `org-class' function
  5261. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5262. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5263. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5264. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5265. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5266. `holidays', then any date that is known by the Emacs calendar to be a
  5267. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5268. then those holidays will be skipped."
  5269. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5270. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5271. (d (calendar-absolute-from-gregorian date))
  5272. (h (when skip-weeks (calendar-check-holidays date))))
  5273. (and
  5274. (<= date1 d)
  5275. (<= d date2)
  5276. (= (calendar-day-of-week date) dayname)
  5277. (or (not skip-weeks)
  5278. (progn
  5279. (require 'cal-iso)
  5280. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5281. (not (or (and h (memq 'holidays skip-weeks))
  5282. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5283. entry)))
  5284. (defalias 'org-get-closed 'org-agenda-get-progress)
  5285. (defun org-agenda-get-progress ()
  5286. "Return the logged TODO entries for agenda display."
  5287. (let* ((props (list 'mouse-face 'highlight
  5288. 'org-not-done-regexp org-not-done-regexp
  5289. 'org-todo-regexp org-todo-regexp
  5290. 'org-complex-heading-regexp org-complex-heading-regexp
  5291. 'help-echo
  5292. (format "mouse-2 or RET jump to org file %s"
  5293. (abbreviate-file-name buffer-file-name))))
  5294. (items (if (consp org-agenda-show-log-scoped)
  5295. org-agenda-show-log-scoped
  5296. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5297. '(clock)
  5298. org-agenda-log-mode-items)))
  5299. (parts
  5300. (delq nil
  5301. (list
  5302. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5303. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5304. (when (memq 'state items)
  5305. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5306. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5307. (error "`org-agenda-log-mode-items' is empty")))
  5308. (regexp (concat
  5309. "\\(" parts-re "\\)"
  5310. " *\\["
  5311. (regexp-quote
  5312. (substring
  5313. (format-time-string
  5314. (car org-time-stamp-formats)
  5315. (apply 'encode-time ; DATE bound by calendar
  5316. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5317. 1 11))))
  5318. (org-agenda-search-headline-for-time nil)
  5319. marker hdmarker priority category level tags closedp type
  5320. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5321. (goto-char (point-min))
  5322. (while (re-search-forward regexp nil t)
  5323. (catch :skip
  5324. (org-agenda-skip)
  5325. (setq marker (org-agenda-new-marker (match-beginning 0))
  5326. closedp (equal (match-string 1) org-closed-string)
  5327. statep (equal (string-to-char (match-string 1)) ?-)
  5328. clockp (not (or closedp statep))
  5329. state (and statep (match-string 2))
  5330. category (org-get-category (match-beginning 0))
  5331. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5332. (when (string-match "\\]" timestr)
  5333. ;; substring should only run to end of time stamp
  5334. (setq rest (substring timestr (match-end 0))
  5335. timestr (substring timestr 0 (match-end 0)))
  5336. (if (and (not closedp) (not statep)
  5337. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5338. rest))
  5339. (progn (setq timestr (concat (substring timestr 0 -1)
  5340. "-" (match-string 1 rest) "]"))
  5341. (setq clocked (match-string 2 rest)))
  5342. (setq clocked "-")))
  5343. (save-excursion
  5344. (setq extra
  5345. (cond
  5346. ((not org-agenda-log-mode-add-notes) nil)
  5347. (statep
  5348. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5349. (match-string 1)))
  5350. (clockp
  5351. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5352. (match-string 1)))))
  5353. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5354. (throw :skip nil)
  5355. (goto-char (match-beginning 0))
  5356. (setq hdmarker (org-agenda-new-marker)
  5357. inherited-tags
  5358. (or (eq org-agenda-show-inherited-tags 'always)
  5359. (and (listp org-agenda-show-inherited-tags)
  5360. (memq 'todo org-agenda-show-inherited-tags))
  5361. (and (eq org-agenda-show-inherited-tags t)
  5362. (or (eq org-agenda-use-tag-inheritance t)
  5363. (memq 'todo org-agenda-use-tag-inheritance))))
  5364. tags (org-get-tags nil (not inherited-tags))
  5365. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5366. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5367. (setq txt (match-string 1))
  5368. (when extra
  5369. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5370. (setq txt (concat (substring txt 0 (match-beginning 1))
  5371. " - " extra " " (match-string 2 txt)))
  5372. (setq txt (concat txt " - " extra))))
  5373. (setq txt (org-agenda-format-item
  5374. (cond
  5375. (closedp "Closed: ")
  5376. (statep (concat "State: (" state ")"))
  5377. (t (concat "Clocked: (" clocked ")")))
  5378. txt level category tags timestr)))
  5379. (setq type (cond (closedp "closed")
  5380. (statep "state")
  5381. (t "clock")))
  5382. (setq priority 100000)
  5383. (org-add-props txt props
  5384. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5385. 'priority priority 'level level
  5386. 'type type 'date date
  5387. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5388. (push txt ee))
  5389. (goto-char (point-at-eol))))
  5390. (nreverse ee)))
  5391. (defun org-agenda-show-clocking-issues ()
  5392. "Add overlays, showing issues with clocking.
  5393. See also the user option `org-agenda-clock-consistency-checks'."
  5394. (interactive)
  5395. (let* ((pl org-agenda-clock-consistency-checks)
  5396. (re (concat "^[ \t]*"
  5397. org-clock-string
  5398. "[ \t]+"
  5399. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5400. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5401. (tlstart 0.)
  5402. (tlend 0.)
  5403. (maxtime (org-duration-to-minutes
  5404. (or (plist-get pl :max-duration) "24:00")))
  5405. (mintime (org-duration-to-minutes
  5406. (or (plist-get pl :min-duration) 0)))
  5407. (maxgap (org-duration-to-minutes
  5408. ;; default 30:00 means never complain
  5409. (or (plist-get pl :max-gap) "30:00")))
  5410. (gapok (mapcar #'org-duration-to-minutes
  5411. (plist-get pl :gap-ok-around)))
  5412. (def-face (or (plist-get pl :default-face)
  5413. '((:background "DarkRed") (:foreground "white"))))
  5414. issue face m te ts dt ov)
  5415. (goto-char (point-min))
  5416. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5417. (setq issue nil face def-face)
  5418. (catch 'next
  5419. (setq m (org-get-at-bol 'org-marker)
  5420. te nil ts nil)
  5421. (unless (and m (markerp m))
  5422. (setq issue "No valid clock line") (throw 'next t))
  5423. (org-with-point-at m
  5424. (save-excursion
  5425. (goto-char (point-at-bol))
  5426. (unless (looking-at re)
  5427. (error "No valid Clock line")
  5428. (throw 'next t))
  5429. (unless (match-end 3)
  5430. (setq issue "No end time"
  5431. face (or (plist-get pl :no-end-time-face) face))
  5432. (throw 'next t))
  5433. (setq ts (match-string 1)
  5434. te (match-string 3)
  5435. ts (float-time
  5436. (apply #'encode-time (org-parse-time-string ts)))
  5437. te (float-time
  5438. (apply #'encode-time (org-parse-time-string te)))
  5439. dt (- te ts))))
  5440. (cond
  5441. ((> dt (* 60 maxtime))
  5442. ;; a very long clocking chunk
  5443. (setq issue (format "Clocking interval is very long: %s"
  5444. (org-duration-from-minutes (floor dt 60)))
  5445. face (or (plist-get pl :long-face) face)))
  5446. ((< dt (* 60 mintime))
  5447. ;; a very short clocking chunk
  5448. (setq issue (format "Clocking interval is very short: %s"
  5449. (org-duration-from-minutes (floor dt 60)))
  5450. face (or (plist-get pl :short-face) face)))
  5451. ((and (> tlend 0) (< ts tlend))
  5452. ;; Two clock entries are overlapping
  5453. (setq issue (format "Clocking overlap: %d minutes"
  5454. (/ (- tlend ts) 60))
  5455. face (or (plist-get pl :overlap-face) face)))
  5456. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5457. ;; There is a gap, lets see if we need to report it
  5458. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5459. (setq issue (format "Clocking gap: %d minutes"
  5460. (/ (- ts tlend) 60))
  5461. face (or (plist-get pl :gap-face) face))))
  5462. (t nil)))
  5463. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5464. (when issue
  5465. ;; OK, there was some issue, add an overlay to show the issue
  5466. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5467. (overlay-put ov 'before-string
  5468. (concat
  5469. (org-add-props
  5470. (format "%-43s" (concat " " issue))
  5471. nil
  5472. 'face face)
  5473. "\n"))
  5474. (overlay-put ov 'evaporate t)))))
  5475. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5476. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5477. (catch 'exit
  5478. (unless ok-list
  5479. ;; there are no OK times for gaps...
  5480. (throw 'exit nil))
  5481. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5482. ;; This is more than 24 hours, so it is OK.
  5483. ;; because we have at least one OK time, that must be in the
  5484. ;; 24 hour interval.
  5485. (throw 'exit t))
  5486. ;; We have a shorter gap.
  5487. ;; Now we have to get the minute of the day when these times are
  5488. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5489. (t2dec (decode-time (seconds-to-time t2)))
  5490. ;; compute the minute on the day
  5491. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5492. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5493. (when (< min2 min1)
  5494. ;; if min2 is smaller than min1, this means it is on the next day.
  5495. ;; Wrap it to after midnight.
  5496. (setq min2 (+ min2 1440)))
  5497. ;; Now check if any of the OK times is in the gap
  5498. (mapc (lambda (x)
  5499. ;; Wrap the time to after midnight if necessary
  5500. (when (< x min1) (setq x (+ x 1440)))
  5501. ;; Check if in interval
  5502. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5503. ok-list)
  5504. ;; Nope, this gap is not OK
  5505. nil)))
  5506. (defun org-agenda-get-deadlines (&optional with-hour)
  5507. "Return the deadline information for agenda display.
  5508. When WITH-HOUR is non-nil, only return deadlines with an hour
  5509. specification like [h]h:mm."
  5510. (let* ((props (list 'mouse-face 'highlight
  5511. 'org-not-done-regexp org-not-done-regexp
  5512. 'org-todo-regexp org-todo-regexp
  5513. 'org-complex-heading-regexp org-complex-heading-regexp
  5514. 'help-echo
  5515. (format "mouse-2 or RET jump to org file %s"
  5516. (abbreviate-file-name buffer-file-name))))
  5517. (regexp (if with-hour
  5518. org-deadline-time-hour-regexp
  5519. org-deadline-time-regexp))
  5520. (today (org-today))
  5521. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5522. (current (calendar-absolute-from-gregorian date))
  5523. deadline-items)
  5524. (goto-char (point-min))
  5525. (while (re-search-forward regexp nil t)
  5526. (catch :skip
  5527. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5528. (org-agenda-skip)
  5529. (let* ((s (match-string 1))
  5530. (pos (1- (match-beginning 1)))
  5531. (todo-state (save-match-data (org-get-todo-state)))
  5532. (done? (member todo-state org-done-keywords))
  5533. (sexp? (string-prefix-p "%%" s))
  5534. ;; DEADLINE is the deadline date for the entry. It is
  5535. ;; either the base date or the last repeat, according
  5536. ;; to `org-agenda-prefer-last-repeat'.
  5537. (deadline
  5538. (cond
  5539. (sexp? (org-agenda--timestamp-to-absolute s current))
  5540. ((or (eq org-agenda-prefer-last-repeat t)
  5541. (member todo-state org-agenda-prefer-last-repeat))
  5542. (org-agenda--timestamp-to-absolute
  5543. s today 'past (current-buffer) pos))
  5544. (t (org-agenda--timestamp-to-absolute s))))
  5545. ;; REPEAT is the future repeat closest from CURRENT,
  5546. ;; according to `org-agenda-show-future-repeats'. If
  5547. ;; the latter is nil, or if the time stamp has no
  5548. ;; repeat part, default to DEADLINE.
  5549. (repeat
  5550. (cond
  5551. (sexp? deadline)
  5552. ((<= current today) deadline)
  5553. ((not org-agenda-show-future-repeats) deadline)
  5554. (t
  5555. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5556. (1+ today)
  5557. current)))
  5558. (org-agenda--timestamp-to-absolute
  5559. s base 'future (current-buffer) pos)))))
  5560. (diff (- deadline current))
  5561. (suppress-prewarning
  5562. (let ((scheduled
  5563. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5564. (org-entry-get nil "SCHEDULED"))))
  5565. (cond
  5566. ((not scheduled) nil)
  5567. ;; The current item has a scheduled date, so
  5568. ;; evaluate its prewarning lead time.
  5569. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5570. ;; Use global prewarning-restart lead time.
  5571. org-agenda-skip-deadline-prewarning-if-scheduled)
  5572. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5573. 'pre-scheduled)
  5574. ;; Set pre-warning to no earlier than SCHEDULED.
  5575. (min (- deadline
  5576. (org-agenda--timestamp-to-absolute scheduled))
  5577. org-deadline-warning-days))
  5578. ;; Set pre-warning to deadline.
  5579. (t 0))))
  5580. (wdays (or suppress-prewarning (org-get-wdays s))))
  5581. (cond
  5582. ;; Only display deadlines at their base date, at future
  5583. ;; repeat occurrences or in today agenda.
  5584. ((= current deadline) nil)
  5585. ((= current repeat) nil)
  5586. ((not today?) (throw :skip nil))
  5587. ;; Upcoming deadline: display within warning period WDAYS.
  5588. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5589. ;; Overdue deadline: warn about it for
  5590. ;; `org-deadline-past-days' duration.
  5591. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5592. ;; Possibly skip done tasks.
  5593. (when (and done?
  5594. (or org-agenda-skip-deadline-if-done
  5595. (/= deadline current)))
  5596. (throw :skip nil))
  5597. (save-excursion
  5598. (re-search-backward "^\\*+[ \t]+" nil t)
  5599. (goto-char (match-end 0))
  5600. (let* ((category (org-get-category))
  5601. (level (make-string (org-reduced-level (org-outline-level))
  5602. ?\s))
  5603. (head (buffer-substring (point) (line-end-position)))
  5604. (inherited-tags
  5605. (or (eq org-agenda-show-inherited-tags 'always)
  5606. (and (listp org-agenda-show-inherited-tags)
  5607. (memq 'agenda org-agenda-show-inherited-tags))
  5608. (and (eq org-agenda-show-inherited-tags t)
  5609. (or (eq org-agenda-use-tag-inheritance t)
  5610. (memq 'agenda
  5611. org-agenda-use-tag-inheritance)))))
  5612. (tags (org-get-tags nil (not inherited-tags)))
  5613. (time
  5614. (cond
  5615. ;; No time of day designation if it is only
  5616. ;; a reminder.
  5617. ((and (/= current deadline) (/= current repeat)) nil)
  5618. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5619. (concat (substring s (match-beginning 1)) " "))
  5620. (t 'time)))
  5621. (item
  5622. (org-agenda-format-item
  5623. ;; Insert appropriate suffixes before deadlines.
  5624. ;; Those only apply to today agenda.
  5625. (pcase-let ((`(,now ,future ,past)
  5626. org-agenda-deadline-leaders))
  5627. (cond
  5628. ((and today? (< deadline today)) (format past (- diff)))
  5629. ((and today? (> deadline today)) (format future diff))
  5630. (t now)))
  5631. head level category tags time))
  5632. (face (org-agenda-deadline-face
  5633. (- 1 (/ (float diff) (max wdays 1)))))
  5634. (upcoming? (and today? (> deadline today)))
  5635. (warntime (get-text-property (point) 'org-appt-warntime)))
  5636. (org-add-props item props
  5637. 'org-marker (org-agenda-new-marker pos)
  5638. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5639. 'warntime warntime
  5640. 'level level
  5641. 'ts-date deadline
  5642. 'priority
  5643. ;; Adjust priority to today reminders about deadlines.
  5644. ;; Overdue deadlines get the highest priority
  5645. ;; increase, then imminent deadlines and eventually
  5646. ;; more distant deadlines.
  5647. (let ((adjust (if today? (- diff) 0)))
  5648. (+ adjust (org-get-priority item)))
  5649. 'todo-state todo-state
  5650. 'type (if upcoming? "upcoming-deadline" "deadline")
  5651. 'date (if upcoming? date deadline)
  5652. 'face (if done? 'org-agenda-done face)
  5653. 'undone-face face
  5654. 'done-face 'org-agenda-done)
  5655. (push item deadline-items))))))
  5656. (nreverse deadline-items)))
  5657. (defun org-agenda-deadline-face (fraction)
  5658. "Return the face to displaying a deadline item.
  5659. FRACTION is what fraction of the head-warning time has passed."
  5660. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5661. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5662. "Return the scheduled information for agenda display.
  5663. Optional argument DEADLINES is a list of deadline items to be
  5664. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5665. scheduled items with an hour specification like [h]h:mm."
  5666. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5667. 'org-todo-regexp org-todo-regexp
  5668. 'org-complex-heading-regexp org-complex-heading-regexp
  5669. 'done-face 'org-agenda-done
  5670. 'mouse-face 'highlight
  5671. 'help-echo
  5672. (format "mouse-2 or RET jump to Org file %s"
  5673. (abbreviate-file-name buffer-file-name))))
  5674. (regexp (if with-hour
  5675. org-scheduled-time-hour-regexp
  5676. org-scheduled-time-regexp))
  5677. (today (org-today))
  5678. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5679. (current (calendar-absolute-from-gregorian date))
  5680. (deadline-pos
  5681. (mapcar (lambda (d)
  5682. (let ((m (get-text-property 0 'org-hd-marker d)))
  5683. (and m (marker-position m))))
  5684. deadlines))
  5685. scheduled-items)
  5686. (goto-char (point-min))
  5687. (while (re-search-forward regexp nil t)
  5688. (catch :skip
  5689. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5690. (org-agenda-skip)
  5691. (let* ((s (match-string 1))
  5692. (pos (1- (match-beginning 1)))
  5693. (todo-state (save-match-data (org-get-todo-state)))
  5694. (donep (member todo-state org-done-keywords))
  5695. (sexp? (string-prefix-p "%%" s))
  5696. ;; SCHEDULE is the scheduled date for the entry. It is
  5697. ;; either the bare date or the last repeat, according
  5698. ;; to `org-agenda-prefer-last-repeat'.
  5699. (schedule
  5700. (cond
  5701. (sexp? (org-agenda--timestamp-to-absolute s current))
  5702. ((or (eq org-agenda-prefer-last-repeat t)
  5703. (member todo-state org-agenda-prefer-last-repeat))
  5704. (org-agenda--timestamp-to-absolute
  5705. s today 'past (current-buffer) pos))
  5706. (t (org-agenda--timestamp-to-absolute s))))
  5707. ;; REPEAT is the future repeat closest from CURRENT,
  5708. ;; according to `org-agenda-show-future-repeats'. If
  5709. ;; the latter is nil, or if the time stamp has no
  5710. ;; repeat part, default to SCHEDULE.
  5711. (repeat
  5712. (cond
  5713. (sexp? schedule)
  5714. ((<= current today) schedule)
  5715. ((not org-agenda-show-future-repeats) schedule)
  5716. (t
  5717. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5718. (1+ today)
  5719. current)))
  5720. (org-agenda--timestamp-to-absolute
  5721. s base 'future (current-buffer) pos)))))
  5722. (diff (- current schedule))
  5723. (warntime (get-text-property (point) 'org-appt-warntime))
  5724. (pastschedp (< schedule today))
  5725. (futureschedp (> schedule today))
  5726. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5727. (suppress-delay
  5728. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5729. (org-entry-get nil "DEADLINE"))))
  5730. (cond
  5731. ((not deadline) nil)
  5732. ;; The current item has a deadline date, so
  5733. ;; evaluate its delay time.
  5734. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5735. ;; Use global delay time.
  5736. (- org-agenda-skip-scheduled-delay-if-deadline))
  5737. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5738. 'post-deadline)
  5739. ;; Set delay to no later than DEADLINE.
  5740. (min (- schedule
  5741. (org-agenda--timestamp-to-absolute deadline))
  5742. org-scheduled-delay-days))
  5743. (t 0))))
  5744. (ddays
  5745. (cond
  5746. ;; Nullify delay when a repeater triggered already
  5747. ;; and the delay is of the form --Xd.
  5748. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5749. (> schedule (org-agenda--timestamp-to-absolute s)))
  5750. 0)
  5751. (suppress-delay
  5752. (let ((org-scheduled-delay-days suppress-delay))
  5753. (org-get-wdays s t t)))
  5754. (t (org-get-wdays s t)))))
  5755. ;; Display scheduled items at base date (SCHEDULE), today if
  5756. ;; scheduled before the current date, and at any repeat past
  5757. ;; today. However, skip delayed items and items that have
  5758. ;; been displayed for more than `org-scheduled-past-days'.
  5759. (unless (and todayp
  5760. habitp
  5761. (bound-and-true-p org-habit-show-all-today))
  5762. (when (or (and (> ddays 0) (< diff ddays))
  5763. (> diff (or (and habitp org-habit-scheduled-past-days)
  5764. org-scheduled-past-days))
  5765. (> schedule current)
  5766. (and (/= current schedule)
  5767. (/= current today)
  5768. (/= current repeat)))
  5769. (throw :skip nil)))
  5770. ;; Possibly skip done tasks.
  5771. (when (and donep
  5772. (or org-agenda-skip-scheduled-if-done
  5773. (/= schedule current)))
  5774. (throw :skip nil))
  5775. ;; Skip entry if it already appears as a deadline, per
  5776. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5777. ;; doesn't apply to habits.
  5778. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5779. ((guard
  5780. (or (not (memq (line-beginning-position 0) deadline-pos))
  5781. habitp))
  5782. nil)
  5783. (`repeated-after-deadline
  5784. (let ((deadline (time-to-days
  5785. (org-get-deadline-time (point)))))
  5786. (and (<= schedule deadline) (> current deadline))))
  5787. (`not-today pastschedp)
  5788. (`t t)
  5789. (_ nil))
  5790. (throw :skip nil))
  5791. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5792. ;; only show them for today. Also skip done habits.
  5793. (when (and habitp
  5794. (or donep
  5795. (not (bound-and-true-p org-habit-show-habits))
  5796. (and (not todayp)
  5797. (bound-and-true-p
  5798. org-habit-show-habits-only-for-today))))
  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. (inherited-tags
  5805. (or (eq org-agenda-show-inherited-tags 'always)
  5806. (and (listp org-agenda-show-inherited-tags)
  5807. (memq 'agenda org-agenda-show-inherited-tags))
  5808. (and (eq org-agenda-show-inherited-tags t)
  5809. (or (eq org-agenda-use-tag-inheritance t)
  5810. (memq 'agenda
  5811. org-agenda-use-tag-inheritance)))))
  5812. (tags (org-get-tags nil (not inherited-tags)))
  5813. (level (make-string (org-reduced-level (org-outline-level))
  5814. ?\s))
  5815. (head (buffer-substring (point) (line-end-position)))
  5816. (time
  5817. (cond
  5818. ;; No time of day designation if it is only a
  5819. ;; reminder, except for habits, which always show
  5820. ;; the time of day. Habits are an exception
  5821. ;; because if there is a time of day, that is
  5822. ;; interpreted to mean they should usually happen
  5823. ;; then, even if doing the habit was missed.
  5824. ((and
  5825. (not habitp)
  5826. (/= current schedule)
  5827. (/= current repeat))
  5828. nil)
  5829. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5830. (concat (substring s (match-beginning 1)) " "))
  5831. (t 'time)))
  5832. (item
  5833. (org-agenda-format-item
  5834. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5835. ;; Show a reminder of a past scheduled today.
  5836. (if (and todayp pastschedp)
  5837. (format past diff)
  5838. first))
  5839. head level category tags time nil habitp))
  5840. (face (cond ((and (not habitp) pastschedp)
  5841. 'org-scheduled-previously)
  5842. ((and habitp futureschedp)
  5843. 'org-agenda-done)
  5844. (todayp 'org-scheduled-today)
  5845. (t 'org-scheduled)))
  5846. (habitp (and habitp (org-habit-parse-todo))))
  5847. (org-add-props item props
  5848. 'undone-face face
  5849. 'face (if donep 'org-agenda-done face)
  5850. 'org-marker (org-agenda-new-marker pos)
  5851. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5852. 'type (if pastschedp "past-scheduled" "scheduled")
  5853. 'date (if pastschedp schedule date)
  5854. 'ts-date schedule
  5855. 'warntime warntime
  5856. 'level level
  5857. 'priority (if habitp (org-habit-get-priority habitp)
  5858. (+ 99 diff (org-get-priority item)))
  5859. 'org-habit-p habitp
  5860. 'todo-state todo-state)
  5861. (push item scheduled-items))))))
  5862. (nreverse scheduled-items)))
  5863. (defun org-agenda-get-blocks ()
  5864. "Return the date-range information for agenda display."
  5865. (let* ((props (list 'face nil
  5866. 'org-not-done-regexp org-not-done-regexp
  5867. 'org-todo-regexp org-todo-regexp
  5868. 'org-complex-heading-regexp org-complex-heading-regexp
  5869. 'mouse-face 'highlight
  5870. 'help-echo
  5871. (format "mouse-2 or RET jump to org file %s"
  5872. (abbreviate-file-name buffer-file-name))))
  5873. (regexp org-tr-regexp)
  5874. (d0 (calendar-absolute-from-gregorian date))
  5875. marker hdmarker ee txt d1 d2 s1 s2 category
  5876. level todo-state tags pos head donep inherited-tags)
  5877. (goto-char (point-min))
  5878. (while (re-search-forward regexp nil t)
  5879. (catch :skip
  5880. (org-agenda-skip)
  5881. (setq pos (point))
  5882. (let ((start-time (match-string 1))
  5883. (end-time (match-string 2)))
  5884. (setq s1 (match-string 1)
  5885. s2 (match-string 2)
  5886. d1 (time-to-days
  5887. (condition-case err
  5888. (org-time-string-to-time s1)
  5889. (error
  5890. (error
  5891. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5892. s1
  5893. pos
  5894. (current-buffer)
  5895. (error-message-string err)))))
  5896. d2 (time-to-days
  5897. (condition-case err
  5898. (org-time-string-to-time s2)
  5899. (error
  5900. (error
  5901. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5902. s2
  5903. pos
  5904. (current-buffer)
  5905. (error-message-string err))))))
  5906. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5907. ;; Only allow days between the limits, because the normal
  5908. ;; date stamps will catch the limits.
  5909. (save-excursion
  5910. (setq todo-state (org-get-todo-state))
  5911. (setq donep (member todo-state org-done-keywords))
  5912. (when (and donep org-agenda-skip-timestamp-if-done)
  5913. (throw :skip t))
  5914. (setq marker (org-agenda-new-marker (point))
  5915. category (org-get-category))
  5916. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5917. (throw :skip nil)
  5918. (goto-char (match-beginning 0))
  5919. (setq hdmarker (org-agenda-new-marker (point))
  5920. inherited-tags
  5921. (or (eq org-agenda-show-inherited-tags 'always)
  5922. (and (listp org-agenda-show-inherited-tags)
  5923. (memq 'agenda org-agenda-show-inherited-tags))
  5924. (and (eq org-agenda-show-inherited-tags t)
  5925. (or (eq org-agenda-use-tag-inheritance t)
  5926. (memq 'agenda org-agenda-use-tag-inheritance))))
  5927. tags (org-get-tags nil (not inherited-tags)))
  5928. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5929. (looking-at "\\*+[ \t]+\\(.*\\)")
  5930. (setq head (match-string 1))
  5931. (let ((remove-re
  5932. (if org-agenda-remove-timeranges-from-blocks
  5933. (concat
  5934. "<" (regexp-quote s1) ".*?>"
  5935. "--"
  5936. "<" (regexp-quote s2) ".*?>")
  5937. nil)))
  5938. (setq txt (org-agenda-format-item
  5939. (format
  5940. (nth (if (= d1 d2) 0 1)
  5941. org-agenda-timerange-leaders)
  5942. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5943. head level category tags
  5944. (cond ((and (= d1 d0) (= d2 d0))
  5945. (concat "<" start-time ">--<" end-time ">"))
  5946. ((= d1 d0)
  5947. (concat "<" start-time ">"))
  5948. ((= d2 d0)
  5949. (concat "<" end-time ">")))
  5950. remove-re))))
  5951. (org-add-props txt props
  5952. 'org-marker marker 'org-hd-marker hdmarker
  5953. 'type "block" 'date date
  5954. 'level level
  5955. 'todo-state todo-state
  5956. 'priority (org-get-priority txt))
  5957. (push txt ee))))
  5958. (goto-char pos)))
  5959. ;; Sort the entries by expiration date.
  5960. (nreverse ee)))
  5961. ;;; Agenda presentation and sorting
  5962. (defvar org-prefix-has-time nil
  5963. "A flag, set by `org-compile-prefix-format'.
  5964. The flag is set if the currently compiled format contains a `%t'.")
  5965. (defvar org-prefix-has-tag nil
  5966. "A flag, set by `org-compile-prefix-format'.
  5967. The flag is set if the currently compiled format contains a `%T'.")
  5968. (defvar org-prefix-has-effort nil
  5969. "A flag, set by `org-compile-prefix-format'.
  5970. The flag is set if the currently compiled format contains a `%e'.")
  5971. (defvar org-prefix-has-breadcrumbs nil
  5972. "A flag, set by `org-compile-prefix-format'.
  5973. The flag is set if the currently compiled format contains a `%b'.")
  5974. (defvar org-prefix-category-length nil
  5975. "Used by `org-compile-prefix-format' to remember the category field width.")
  5976. (defvar org-prefix-category-max-length nil
  5977. "Used by `org-compile-prefix-format' to remember the category field width.")
  5978. (defun org-agenda-get-category-icon (category)
  5979. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5980. (cl-dolist (entry org-agenda-category-icon-alist)
  5981. (when (string-match-p (car entry) category)
  5982. (if (listp (cadr entry))
  5983. (cl-return (cadr entry))
  5984. (cl-return (apply #'create-image (cdr entry)))))))
  5985. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5986. remove-re habitp)
  5987. "Format TXT to be inserted into the agenda buffer.
  5988. In particular, add the prefix and corresponding text properties.
  5989. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5990. LEVEL may be a string to replace the `%l' specifier.
  5991. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5992. category taken from local variable or file name. It will replace the `%c'
  5993. specifier in the format.
  5994. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5995. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5996. When DOTIME is a string, this string is searched for a time before TXT is.
  5997. TAGS can be the tags of the headline.
  5998. Any match of REMOVE-RE will be removed from TXT."
  5999. ;; We keep the org-prefix-* variable values along with a compiled
  6000. ;; formatter, so that multiple agendas existing at the same time do
  6001. ;; not step on each other toes.
  6002. ;;
  6003. ;; It was inconvenient to make these variables buffer local in
  6004. ;; Agenda buffers, because this function expects to be called with
  6005. ;; the buffer where item comes from being current, and not agenda
  6006. ;; buffer
  6007. (let* ((bindings (car org-prefix-format-compiled))
  6008. (formatter (cadr org-prefix-format-compiled)))
  6009. (cl-loop for (var value) in bindings
  6010. do (set var value))
  6011. (save-match-data
  6012. ;; Diary entries sometimes have extra whitespace at the beginning
  6013. (setq txt (org-trim txt))
  6014. ;; Fix the tags part in txt
  6015. (setq txt (org-agenda-fix-displayed-tags
  6016. txt tags
  6017. org-agenda-show-inherited-tags
  6018. org-agenda-hide-tags-regexp))
  6019. (let* ((category (or category
  6020. (if buffer-file-name
  6021. (file-name-sans-extension
  6022. (file-name-nondirectory buffer-file-name))
  6023. "")))
  6024. (category-icon (org-agenda-get-category-icon category))
  6025. (category-icon (if category-icon
  6026. (propertize " " 'display category-icon)
  6027. ""))
  6028. (effort (and (not (string= txt ""))
  6029. (get-text-property 1 'effort txt)))
  6030. ;; time, tag, effort are needed for the eval of the prefix format
  6031. (tag (if tags (nth (1- (length tags)) tags) ""))
  6032. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6033. time
  6034. (ts (when dotime (concat
  6035. (if (stringp dotime) dotime "")
  6036. (and org-agenda-search-headline-for-time txt))))
  6037. (time-of-day (and dotime (org-get-time-of-day ts)))
  6038. stamp plain s0 s1 s2 rtn srp l
  6039. duration breadcrumbs)
  6040. (and (derived-mode-p 'org-mode) buffer-file-name
  6041. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6042. (when (and dotime time-of-day)
  6043. ;; Extract starting and ending time and move them to prefix
  6044. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6045. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6046. (setq s0 (match-string 0 ts)
  6047. srp (and stamp (match-end 3))
  6048. s1 (match-string (if plain 1 2) ts)
  6049. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6050. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6051. ;; them, we might want to remove them there to avoid duplication.
  6052. ;; The user can turn this off with a variable.
  6053. (when (and org-prefix-has-time
  6054. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6055. (string-match (concat (regexp-quote s0) " *") txt)
  6056. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6057. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6058. (= (match-beginning 0) 0)
  6059. t))
  6060. (setq txt (replace-match "" nil nil txt))))
  6061. ;; Normalize the time(s) to 24 hour
  6062. (when s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6063. (when s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6064. ;; Try to set s2 if s1 and
  6065. ;; `org-agenda-default-appointment-duration' are set
  6066. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6067. (setq s2
  6068. (org-duration-from-minutes
  6069. (+ (org-duration-to-minutes s1 t)
  6070. org-agenda-default-appointment-duration)
  6071. nil t)))
  6072. ;; Compute the duration
  6073. (when s2
  6074. (setq duration (- (org-duration-to-minutes s2)
  6075. (org-duration-to-minutes s1)))))
  6076. (when (string-match org-tag-group-re txt)
  6077. ;; Tags are in the string
  6078. (if (or (eq org-agenda-remove-tags t)
  6079. (and org-agenda-remove-tags
  6080. org-prefix-has-tag))
  6081. (setq txt (replace-match "" t t txt))
  6082. (setq txt (replace-match
  6083. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6084. (match-string 1 txt))
  6085. t t txt))))
  6086. (when remove-re
  6087. (while (string-match remove-re txt)
  6088. (setq txt (replace-match "" t t txt))))
  6089. ;; Set org-heading property on `txt' to mark the start of the
  6090. ;; heading.
  6091. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6092. ;; Prepare the variables needed in the eval of the compiled format
  6093. (when org-prefix-has-breadcrumbs
  6094. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6095. (let ((s (org-format-outline-path (org-get-outline-path)
  6096. (1- (frame-width))
  6097. nil "->")))
  6098. (if (eq "" s) "" (concat s "->"))))))
  6099. (setq time (cond (s2 (concat
  6100. (org-agenda-time-of-day-to-ampm-maybe s1)
  6101. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6102. (when org-agenda-timegrid-use-ampm " ")))
  6103. (s1 (concat
  6104. (org-agenda-time-of-day-to-ampm-maybe s1)
  6105. (if org-agenda-timegrid-use-ampm
  6106. (concat time-grid-trailing-characters " ")
  6107. time-grid-trailing-characters)))
  6108. (t ""))
  6109. extra (or (and (not habitp) extra) "")
  6110. category (if (symbolp category) (symbol-name category) category)
  6111. level (or level ""))
  6112. (if (string-match org-link-bracket-re category)
  6113. (progn
  6114. (setq l (string-width (or (match-string 2) (match-string 1))))
  6115. (when (< l (or org-prefix-category-length 0))
  6116. (setq category (copy-sequence category))
  6117. (org-add-props category nil
  6118. 'extra-space (make-string
  6119. (- org-prefix-category-length l 1) ?\ ))))
  6120. (when (and org-prefix-category-max-length
  6121. (>= (length category) org-prefix-category-max-length))
  6122. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6123. ;; Evaluate the compiled format
  6124. (setq rtn (concat (eval formatter) txt))
  6125. ;; And finally add the text properties
  6126. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6127. (org-add-props rtn nil
  6128. 'org-category category
  6129. 'tags (mapcar 'org-downcase-keep-props tags)
  6130. 'org-highest-priority org-highest-priority
  6131. 'org-lowest-priority org-lowest-priority
  6132. 'time-of-day time-of-day
  6133. 'duration duration
  6134. 'breadcrumbs breadcrumbs
  6135. 'txt txt
  6136. 'level level
  6137. 'time time
  6138. 'extra extra
  6139. 'format org-prefix-format-compiled
  6140. 'dotime dotime)))))
  6141. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6142. "Remove tags string from TXT, and add a modified list of tags.
  6143. The modified list may contain inherited tags, and tags matched by
  6144. `org-agenda-hide-tags-regexp' will be removed."
  6145. (when (or add-inherited hide-re)
  6146. (when (string-match org-tag-group-re txt)
  6147. (setq txt (substring txt 0 (match-beginning 0))))
  6148. (setq tags
  6149. (delq nil
  6150. (mapcar (lambda (tg)
  6151. (if (or (and hide-re (string-match hide-re tg))
  6152. (and (not add-inherited)
  6153. (get-text-property 0 'inherited tg)))
  6154. nil
  6155. tg))
  6156. tags)))
  6157. (when tags
  6158. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6159. i)
  6160. (setq txt (concat txt " :"
  6161. (mapconcat
  6162. (lambda (x)
  6163. (setq i (get-text-property 0 'inherited x))
  6164. (if (and have-i (not i))
  6165. (progn
  6166. (setq have-i nil)
  6167. (concat ":" x))
  6168. x))
  6169. tags ":")
  6170. (if have-i "::" ":"))))))
  6171. txt)
  6172. (defun org-downcase-keep-props (s)
  6173. (let ((props (text-properties-at 0 s)))
  6174. (setq s (downcase s))
  6175. (add-text-properties 0 (length s) props s)
  6176. s))
  6177. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6178. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6179. "Add a time-grid for agenda items which need it.
  6180. LIST is the list of agenda items formatted by `org-agenda-list'.
  6181. NDAYS is the span of the current agenda view.
  6182. TODAYP is t when the current agenda view is on today."
  6183. (catch 'exit
  6184. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6185. ((and todayp (member 'today (car org-agenda-time-grid))))
  6186. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6187. ((member 'weekly (car org-agenda-time-grid)))
  6188. (t (throw 'exit list)))
  6189. (let* ((have (delq nil (mapcar
  6190. (lambda (x) (get-text-property 1 'time-of-day x))
  6191. list)))
  6192. (string (nth 3 org-agenda-time-grid))
  6193. (gridtimes (nth 1 org-agenda-time-grid))
  6194. (req (car org-agenda-time-grid))
  6195. (remove (member 'remove-match req))
  6196. new time)
  6197. (when (and (member 'require-timed req) (not have))
  6198. ;; don't show empty grid
  6199. (throw 'exit list))
  6200. (while (setq time (pop gridtimes))
  6201. (unless (and remove (member time have))
  6202. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6203. (push (org-agenda-format-item
  6204. nil string nil "" nil
  6205. (concat (substring time 0 -2) ":" (substring time -2)))
  6206. new)
  6207. (put-text-property
  6208. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6209. (when (and todayp org-agenda-show-current-time-in-grid)
  6210. (push (org-agenda-format-item
  6211. nil org-agenda-current-time-string nil "" nil
  6212. (format-time-string "%H:%M "))
  6213. new)
  6214. (put-text-property
  6215. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6216. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6217. (append new list)
  6218. (append list new)))))
  6219. (defun org-compile-prefix-format (key)
  6220. "Compile the prefix format into a Lisp form that can be evaluated.
  6221. The resulting form and associated variable bindings is returned
  6222. and stored in the variable `org-prefix-format-compiled'."
  6223. (setq org-prefix-has-time nil
  6224. org-prefix-has-tag nil
  6225. org-prefix-category-length nil
  6226. org-prefix-has-effort nil
  6227. org-prefix-has-breadcrumbs nil)
  6228. (let ((s (cond
  6229. ((stringp org-agenda-prefix-format)
  6230. org-agenda-prefix-format)
  6231. ((assq key org-agenda-prefix-format)
  6232. (cdr (assq key org-agenda-prefix-format)))
  6233. (t " %-12:c%?-12t% s")))
  6234. (start 0)
  6235. varform vars var e c f opt)
  6236. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6237. s start)
  6238. (setq var (or (cdr (assoc (match-string 4 s)
  6239. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6240. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6241. 'eval)
  6242. c (or (match-string 3 s) "")
  6243. opt (match-beginning 1)
  6244. start (1+ (match-beginning 0)))
  6245. (cl-case var
  6246. (time (setq org-prefix-has-time t))
  6247. (tag (setq org-prefix-has-tag t))
  6248. (effort (setq org-prefix-has-effort t))
  6249. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6250. (setq f (concat "%" (match-string 2 s) "s"))
  6251. (when (eq var 'category)
  6252. (setq org-prefix-category-length
  6253. (floor (abs (string-to-number (match-string 2 s)))))
  6254. (setq org-prefix-category-max-length
  6255. (let ((x (match-string 2 s)))
  6256. (when (string-match-p "\\.[0-9]+" x)
  6257. (string-to-number (substring (match-string 0 x) 1))))))
  6258. (if (eq var 'eval)
  6259. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6260. (if opt
  6261. (setq varform
  6262. `(if (or (equal "" ,var) (equal nil ,var))
  6263. ""
  6264. (format ,f (concat ,var ,c))))
  6265. (setq varform
  6266. `(format ,f (if (or (equal ,var "")
  6267. (equal ,var nil)) ""
  6268. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6269. (setq s (replace-match "%s" t nil s))
  6270. (push varform vars))
  6271. (setq vars (nreverse vars))
  6272. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6273. (setq org-prefix-format-compiled
  6274. (list
  6275. `((org-prefix-has-time ,org-prefix-has-time)
  6276. (org-prefix-has-tag ,org-prefix-has-tag)
  6277. (org-prefix-category-length ,org-prefix-category-length)
  6278. (org-prefix-has-effort ,org-prefix-has-effort)
  6279. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6280. `(format ,s ,@vars))))))
  6281. (defun org-set-sorting-strategy (key)
  6282. (if (symbolp (car org-agenda-sorting-strategy))
  6283. ;; the old format
  6284. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6285. (setq org-agenda-sorting-strategy-selected
  6286. (or (cdr (assq key org-agenda-sorting-strategy))
  6287. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6288. '(time-up category-keep priority-down)))))
  6289. (defun org-get-time-of-day (s &optional string mod24)
  6290. "Check string S for a time of day.
  6291. If found, return it as a military time number between 0 and 2400.
  6292. If not found, return nil.
  6293. The optional STRING argument forces conversion into a 5 character wide string
  6294. HH:MM."
  6295. (save-match-data
  6296. (when
  6297. (and
  6298. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6299. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6300. (not (eq (get-text-property 1 'face s) 'org-link)))
  6301. (let* ((h (string-to-number (match-string 1 s)))
  6302. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6303. (ampm (when (match-end 4) (downcase (match-string 4 s))))
  6304. (am-p (equal ampm "am"))
  6305. (h1 (cond ((not ampm) h)
  6306. ((= h 12) (if am-p 0 12))
  6307. (t (+ h (if am-p 0 12)))))
  6308. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6309. (mod h1 24) h1))
  6310. (t0 (+ (* 100 h2) m))
  6311. (t1 (concat (if (>= h1 24) "+" " ")
  6312. (if (and org-agenda-time-leading-zero
  6313. (< t0 1000)) "0" "")
  6314. (if (< t0 100) "0" "")
  6315. (if (< t0 10) "0" "")
  6316. (int-to-string t0))))
  6317. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6318. (defvar org-agenda-before-sorting-filter-function nil
  6319. "Function to be applied to agenda items prior to sorting.
  6320. Prior to sorting also means just before they are inserted into the agenda.
  6321. To aid sorting, you may revisit the original entries and add more text
  6322. properties which will later be used by the sorting functions.
  6323. The function should take a string argument, an agenda line.
  6324. It has access to the text properties in that line, which contain among
  6325. other things, the property `org-hd-marker' that points to the entry
  6326. where the line comes from. Note that not all lines going into the agenda
  6327. have this property, only most.
  6328. The function should return the modified string. It is probably best
  6329. to ONLY change text properties.
  6330. You can also use this function as a filter, by returning nil for lines
  6331. you don't want to have in the agenda at all. For this application, you
  6332. could bind the variable in the options section of a custom command.")
  6333. (defun org-agenda-finalize-entries (list &optional type)
  6334. "Sort, limit and concatenate the LIST of agenda items.
  6335. The optional argument TYPE tells the agenda type."
  6336. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6337. (cdr (assoc type org-agenda-max-effort)))
  6338. (t org-agenda-max-effort)))
  6339. (max-todo (cond ((listp org-agenda-max-todos)
  6340. (cdr (assoc type org-agenda-max-todos)))
  6341. (t org-agenda-max-todos)))
  6342. (max-tags (cond ((listp org-agenda-max-tags)
  6343. (cdr (assoc type org-agenda-max-tags)))
  6344. (t org-agenda-max-tags)))
  6345. (max-entries (cond ((listp org-agenda-max-entries)
  6346. (cdr (assoc type org-agenda-max-entries)))
  6347. (t org-agenda-max-entries))))
  6348. (when org-agenda-before-sorting-filter-function
  6349. (setq list
  6350. (delq nil
  6351. (mapcar
  6352. org-agenda-before-sorting-filter-function list))))
  6353. (setq list (mapcar 'org-agenda-highlight-todo list)
  6354. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6355. (when max-effort
  6356. (setq list (org-agenda-limit-entries
  6357. list 'effort-minutes max-effort
  6358. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6359. 32767 -1))))))
  6360. (when max-todo
  6361. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6362. (when max-tags
  6363. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6364. (when max-entries
  6365. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6366. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6367. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6368. (mapconcat 'identity list "\n")))
  6369. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6370. "Limit the number of agenda entries."
  6371. (let ((include (and limit (< limit 0))))
  6372. (if limit
  6373. (let ((fun (or fn (lambda (p) (when p 1))))
  6374. (lim 0))
  6375. (delq nil
  6376. (mapcar
  6377. (lambda (e)
  6378. (let ((pval (funcall
  6379. fun (get-text-property (1- (length e))
  6380. prop e))))
  6381. (when pval (setq lim (+ lim pval)))
  6382. (cond ((and pval (<= lim (abs limit))) e)
  6383. ((and include (not pval)) e))))
  6384. list)))
  6385. list)))
  6386. (defun org-agenda-limit-interactively (remove)
  6387. "In agenda, interactively limit entries to various maximums."
  6388. (interactive "P")
  6389. (if remove
  6390. (progn (setq org-agenda-max-entries nil
  6391. org-agenda-max-todos nil
  6392. org-agenda-max-tags nil
  6393. org-agenda-max-effort nil)
  6394. (org-agenda-redo))
  6395. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6396. (msg (cond ((= max ?E) "How many minutes? ")
  6397. ((= max ?e) "How many entries? ")
  6398. ((= max ?t) "How many TODO entries? ")
  6399. ((= max ?T) "How many tagged entries? ")
  6400. (t (user-error "Wrong input"))))
  6401. (num (string-to-number (read-from-minibuffer msg))))
  6402. (cond ((equal max ?e)
  6403. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6404. ((equal max ?t)
  6405. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6406. ((equal max ?T)
  6407. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6408. ((equal max ?E)
  6409. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6410. (org-agenda-fit-window-to-buffer))
  6411. (defun org-agenda-highlight-todo (x)
  6412. (let ((org-done-keywords org-done-keywords-for-agenda)
  6413. (case-fold-search nil)
  6414. re)
  6415. (if (eq x 'line)
  6416. (save-excursion
  6417. (beginning-of-line 1)
  6418. (setq re (org-get-at-bol 'org-todo-regexp))
  6419. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6420. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6421. (add-text-properties (match-beginning 0) (match-end 1)
  6422. (list 'face (org-get-todo-face 1)))
  6423. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6424. (delete-region (match-beginning 1) (1- (match-end 0)))
  6425. (goto-char (match-beginning 1))
  6426. (insert (format org-agenda-todo-keyword-format s)))))
  6427. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6428. (setq re (get-text-property 0 'org-todo-regexp x))
  6429. (when (and re
  6430. ;; Test `pl' because if there's no heading content,
  6431. ;; there's no point matching to highlight. Note
  6432. ;; that if we didn't test `pl' first, and there
  6433. ;; happened to be no keyword from `org-todo-regexp'
  6434. ;; on this heading line, then the `equal' comparison
  6435. ;; afterwards would spuriously succeed in the case
  6436. ;; where `pl' is nil -- causing an args-out-of-range
  6437. ;; error when we try to add text properties to text
  6438. ;; that isn't there.
  6439. pl
  6440. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6441. x pl) pl))
  6442. (add-text-properties
  6443. (or (match-end 1) (match-end 0)) (match-end 0)
  6444. (list 'face (org-get-todo-face (match-string 2 x)))
  6445. x)
  6446. (when (match-end 1)
  6447. (setq x
  6448. (concat
  6449. (substring x 0 (match-end 1))
  6450. (format org-agenda-todo-keyword-format
  6451. (match-string 2 x))
  6452. ;; Remove `display' property as the icon could leak
  6453. ;; on the white space.
  6454. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6455. 'display))
  6456. (substring x (match-end 3)))))))
  6457. x)))
  6458. (defsubst org-cmp-values (a b property)
  6459. "Compare the numeric value of text PROPERTY for string A and B."
  6460. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6461. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6462. (cond ((> pa pb) +1)
  6463. ((< pa pb) -1))))
  6464. (defsubst org-cmp-effort (a b)
  6465. "Compare the effort values of string A and B."
  6466. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6467. ;; `effort-minutes' property is not directly accessible from
  6468. ;; the strings, but is stored as a property in `txt'.
  6469. (ea (or (get-text-property
  6470. 0 'effort-minutes (get-text-property 0 'txt a))
  6471. def))
  6472. (eb (or (get-text-property
  6473. 0 'effort-minutes (get-text-property 0 'txt b))
  6474. def)))
  6475. (cond ((> ea eb) +1)
  6476. ((< ea eb) -1))))
  6477. (defsubst org-cmp-category (a b)
  6478. "Compare the string values of categories of strings A and B."
  6479. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6480. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6481. (cond ((string-lessp ca cb) -1)
  6482. ((string-lessp cb ca) +1))))
  6483. (defsubst org-cmp-todo-state (a b)
  6484. "Compare the todo states of strings A and B."
  6485. (let* ((ma (or (get-text-property 1 'org-marker a)
  6486. (get-text-property 1 'org-hd-marker a)))
  6487. (mb (or (get-text-property 1 'org-marker b)
  6488. (get-text-property 1 'org-hd-marker b)))
  6489. (fa (and ma (marker-buffer ma)))
  6490. (fb (and mb (marker-buffer mb)))
  6491. (todo-kwds
  6492. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6493. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6494. (ta (or (get-text-property 1 'todo-state a) ""))
  6495. (tb (or (get-text-property 1 'todo-state b) ""))
  6496. (la (- (length (member ta todo-kwds))))
  6497. (lb (- (length (member tb todo-kwds))))
  6498. (donepa (member ta org-done-keywords-for-agenda))
  6499. (donepb (member tb org-done-keywords-for-agenda)))
  6500. (cond ((and donepa (not donepb)) -1)
  6501. ((and (not donepa) donepb) +1)
  6502. ((< la lb) -1)
  6503. ((< lb la) +1))))
  6504. (defsubst org-cmp-alpha (a b)
  6505. "Compare the headlines, alphabetically."
  6506. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6507. (plb (text-property-any 0 (length b) 'org-heading t b))
  6508. (ta (and pla (substring a pla)))
  6509. (tb (and plb (substring b plb)))
  6510. (case-fold-search nil))
  6511. (when pla
  6512. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6513. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6514. (setq ta (substring ta (match-end 0))))
  6515. (setq ta (downcase ta)))
  6516. (when plb
  6517. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6518. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6519. (setq tb (substring tb (match-end 0))))
  6520. (setq tb (downcase tb)))
  6521. (cond ((not (or ta tb)) nil)
  6522. ((not ta) +1)
  6523. ((not tb) -1)
  6524. ((string-lessp ta tb) -1)
  6525. ((string-lessp tb ta) +1))))
  6526. (defsubst org-cmp-tag (a b)
  6527. "Compare the string values of the first tags of A and B."
  6528. (let ((ta (car (last (get-text-property 1 'tags a))))
  6529. (tb (car (last (get-text-property 1 'tags b)))))
  6530. (cond ((not (or ta tb)) nil)
  6531. ((not ta) +1)
  6532. ((not tb) -1)
  6533. ((string-lessp ta tb) -1)
  6534. ((string-lessp tb ta) +1))))
  6535. (defsubst org-cmp-time (a b)
  6536. "Compare the time-of-day values of strings A and B."
  6537. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6538. (ta (or (get-text-property 1 'time-of-day a) def))
  6539. (tb (or (get-text-property 1 'time-of-day b) def)))
  6540. (cond ((< ta tb) -1)
  6541. ((< tb ta) +1))))
  6542. (defsubst org-cmp-ts (a b type)
  6543. "Compare the timestamps values of entries A and B.
  6544. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6545. \"timestamp_ia\", compare within each of these type. When TYPE
  6546. is the empty string, compare all timestamps without respect of
  6547. their type."
  6548. (let* ((def (and (not org-sort-agenda-notime-is-late) -1))
  6549. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6550. (get-text-property 1 'ts-date a))
  6551. def))
  6552. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6553. (get-text-property 1 'ts-date b))
  6554. def)))
  6555. (cond ((if ta (and tb (< ta tb)) tb) -1)
  6556. ((if tb (and ta (< tb ta)) ta) +1))))
  6557. (defsubst org-cmp-habit-p (a b)
  6558. "Compare the todo states of strings A and B."
  6559. (let ((ha (get-text-property 1 'org-habit-p a))
  6560. (hb (get-text-property 1 'org-habit-p b)))
  6561. (cond ((and ha (not hb)) -1)
  6562. ((and (not ha) hb) +1))))
  6563. (defun org-entries-lessp (a b)
  6564. "Predicate for sorting agenda entries."
  6565. ;; The following variables will be used when the form is evaluated.
  6566. ;; So even though the compiler complains, keep them.
  6567. (let* ((ss org-agenda-sorting-strategy-selected)
  6568. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6569. (org-cmp-ts a b "")))
  6570. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6571. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6572. (org-cmp-ts a b "scheduled")))
  6573. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6574. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6575. (org-cmp-ts a b "deadline")))
  6576. (deadline-down (if deadline-up (- deadline-up) nil))
  6577. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6578. (org-cmp-ts a b "timestamp_ia")))
  6579. (tsia-down (if tsia-up (- tsia-up) nil))
  6580. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6581. (org-cmp-ts a b "timestamp")))
  6582. (ts-down (if ts-up (- ts-up) nil))
  6583. (time-up (and (org-em 'time-up 'time-down ss)
  6584. (org-cmp-time a b)))
  6585. (time-down (if time-up (- time-up) nil))
  6586. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6587. (org-cmp-values a b 'org-stats)))
  6588. (stats-down (if stats-up (- stats-up) nil))
  6589. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6590. (org-cmp-values a b 'priority)))
  6591. (priority-down (if priority-up (- priority-up) nil))
  6592. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6593. (org-cmp-effort a b)))
  6594. (effort-down (if effort-up (- effort-up) nil))
  6595. (category-up (and (or (org-em 'category-up 'category-down ss)
  6596. (memq 'category-keep ss))
  6597. (org-cmp-category a b)))
  6598. (category-down (if category-up (- category-up) nil))
  6599. (category-keep (if category-up +1 nil))
  6600. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6601. (org-cmp-tag a b)))
  6602. (tag-down (if tag-up (- tag-up) nil))
  6603. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6604. (org-cmp-todo-state a b)))
  6605. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6606. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6607. (org-cmp-habit-p a b)))
  6608. (habit-down (if habit-up (- habit-up) nil))
  6609. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6610. (org-cmp-alpha a b)))
  6611. (alpha-down (if alpha-up (- alpha-up) nil))
  6612. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6613. user-defined-up user-defined-down)
  6614. (when (and need-user-cmp org-agenda-cmp-user-defined
  6615. (functionp org-agenda-cmp-user-defined))
  6616. (setq user-defined-up
  6617. (funcall org-agenda-cmp-user-defined a b)
  6618. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6619. (cdr (assoc
  6620. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6621. '((-1 . t) (1 . nil) (nil . nil))))))
  6622. ;;; Agenda restriction lock
  6623. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6624. "Overlay to mark the headline to which agenda commands are restricted.")
  6625. (overlay-put org-agenda-restriction-lock-overlay
  6626. 'face 'org-agenda-restriction-lock)
  6627. (overlay-put org-agenda-restriction-lock-overlay
  6628. 'help-echo "Agendas are currently limited to this subtree.")
  6629. (delete-overlay org-agenda-restriction-lock-overlay)
  6630. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6631. "Set the restriction lock to the agenda item at point from within the agenda.
  6632. When called with a `\\[universal-argument]' prefix, restrict to
  6633. the file which contains the item.
  6634. Argument ARG is the prefix argument."
  6635. (interactive "P")
  6636. (unless (derived-mode-p 'org-agenda-mode)
  6637. (user-error "Not in an Org agenda buffer"))
  6638. (let* ((marker (or (org-get-at-bol 'org-marker)
  6639. (org-agenda-error)))
  6640. (buffer (marker-buffer marker))
  6641. (pos (marker-position marker)))
  6642. (with-current-buffer buffer
  6643. (goto-char pos)
  6644. (org-agenda-set-restriction-lock arg))))
  6645. ;;;###autoload
  6646. (defun org-agenda-set-restriction-lock (&optional type)
  6647. "Set restriction lock for agenda to current subtree or file.
  6648. When in a restricted subtree, remove it.
  6649. The restriction will span over the entire file if TYPE is `file',
  6650. or if type is '(4), or if the cursor is before the first headline
  6651. in the file. Otherwise, only apply the restriction to the current
  6652. subtree."
  6653. (interactive "P")
  6654. (if (and org-agenda-overriding-restriction
  6655. (member org-agenda-restriction-lock-overlay
  6656. (overlays-at (point)))
  6657. (equal (overlay-start org-agenda-restriction-lock-overlay)
  6658. (point)))
  6659. (org-agenda-remove-restriction-lock 'noupdate)
  6660. (org-agenda-remove-restriction-lock 'noupdate)
  6661. (and (equal type '(4)) (setq type 'file))
  6662. (setq type (cond
  6663. (type type)
  6664. ((org-at-heading-p) 'subtree)
  6665. ((condition-case nil (org-back-to-heading t) (error nil))
  6666. 'subtree)
  6667. (t 'file)))
  6668. (if (eq type 'subtree)
  6669. (progn
  6670. (setq org-agenda-restrict (current-buffer))
  6671. (setq org-agenda-overriding-restriction 'subtree)
  6672. (put 'org-agenda-files 'org-restrict
  6673. (list (buffer-file-name (buffer-base-buffer))))
  6674. (org-back-to-heading t)
  6675. (move-overlay org-agenda-restriction-lock-overlay
  6676. (point)
  6677. (if org-agenda-restriction-lock-highlight-subtree
  6678. (save-excursion (org-end-of-subtree t t) (point))
  6679. (point-at-eol)))
  6680. (move-marker org-agenda-restrict-begin (point))
  6681. (move-marker org-agenda-restrict-end
  6682. (save-excursion (org-end-of-subtree t t)))
  6683. (message "Locking agenda restriction to subtree"))
  6684. (put 'org-agenda-files 'org-restrict
  6685. (list (buffer-file-name (buffer-base-buffer))))
  6686. (setq org-agenda-restrict nil)
  6687. (setq org-agenda-overriding-restriction 'file)
  6688. (move-marker org-agenda-restrict-begin nil)
  6689. (move-marker org-agenda-restrict-end nil)
  6690. (message "Locking agenda restriction to file"))
  6691. (setq current-prefix-arg nil))
  6692. (org-agenda-maybe-redo))
  6693. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6694. "Remove agenda restriction lock."
  6695. (interactive "P")
  6696. (if (not org-agenda-restrict)
  6697. (message "No agenda restriction to remove.")
  6698. (delete-overlay org-agenda-restriction-lock-overlay)
  6699. (delete-overlay org-speedbar-restriction-lock-overlay)
  6700. (setq org-agenda-overriding-restriction nil)
  6701. (setq org-agenda-restrict nil)
  6702. (put 'org-agenda-files 'org-restrict nil)
  6703. (move-marker org-agenda-restrict-begin nil)
  6704. (move-marker org-agenda-restrict-end nil)
  6705. (setq current-prefix-arg nil)
  6706. (message "Agenda restriction lock removed")
  6707. (or noupdate (org-agenda-maybe-redo))))
  6708. (defun org-agenda-maybe-redo ()
  6709. "If there is any window showing the agenda view, update it."
  6710. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6711. org-agenda-buffer-name)
  6712. t))
  6713. (w0 (selected-window)))
  6714. (when w
  6715. (select-window w)
  6716. (org-agenda-redo)
  6717. (select-window w0)
  6718. (if org-agenda-overriding-restriction
  6719. (message "Agenda view shifted to new %s restriction"
  6720. org-agenda-overriding-restriction)
  6721. (message "Agenda restriction lock removed")))))
  6722. ;;; Agenda commands
  6723. (defun org-agenda-check-type (error &rest types)
  6724. "Check if agenda buffer is of allowed type.
  6725. If ERROR is non-nil, throw an error, otherwise just return nil.
  6726. Allowed types are `agenda' `todo' `tags' `search'."
  6727. (cond ((not org-agenda-type)
  6728. (error "No Org agenda currently displayed"))
  6729. ((memq org-agenda-type types) t)
  6730. (error
  6731. (error "Not allowed in %s-type agenda buffers" org-agenda-type))
  6732. (t nil)))
  6733. (defun org-agenda-Quit ()
  6734. "Exit the agenda, killing the agenda buffer.
  6735. Like `org-agenda-quit', but kill the buffer even when
  6736. `org-agenda-sticky' is non-nil."
  6737. (interactive)
  6738. (org-agenda--quit))
  6739. (defun org-agenda-quit ()
  6740. "Exit the agenda.
  6741. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6742. instead of killing it.
  6743. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6744. the pre-agenda window configuration.
  6745. When column view is active, exit column view instead of the
  6746. agenda."
  6747. (interactive)
  6748. (org-agenda--quit org-agenda-sticky))
  6749. (defun org-agenda--quit (&optional bury)
  6750. (if org-agenda-columns-active
  6751. (org-columns-quit)
  6752. (let ((wconf org-agenda-pre-window-conf)
  6753. (buf (current-buffer))
  6754. (org-agenda-last-indirect-window
  6755. (and (eq org-indirect-buffer-display 'other-window)
  6756. org-agenda-last-indirect-buffer
  6757. (get-buffer-window org-agenda-last-indirect-buffer))))
  6758. (cond
  6759. ((eq org-agenda-window-setup 'other-frame)
  6760. (delete-frame))
  6761. ((and org-agenda-restore-windows-after-quit
  6762. wconf)
  6763. ;; Maybe restore the pre-agenda window configuration. Reset
  6764. ;; `org-agenda-pre-window-conf' before running
  6765. ;; `set-window-configuration', which loses the current buffer.
  6766. (setq org-agenda-pre-window-conf nil)
  6767. (set-window-configuration wconf))
  6768. (t
  6769. (when org-agenda-last-indirect-window
  6770. (delete-window org-agenda-last-indirect-window))
  6771. (and (not (eq org-agenda-window-setup 'current-window))
  6772. (not (one-window-p))
  6773. (delete-window))))
  6774. (if bury
  6775. ;; Set the agenda buffer as the current buffer instead of
  6776. ;; passing it as an argument to `bury-buffer' so that
  6777. ;; `bury-buffer' removes it from the window.
  6778. (with-current-buffer buf
  6779. (bury-buffer))
  6780. (kill-buffer buf)
  6781. (setq org-agenda-archives-mode nil
  6782. org-agenda-buffer nil)))))
  6783. (defun org-agenda-exit ()
  6784. "Exit the agenda, killing Org buffers loaded by the agenda.
  6785. Like `org-agenda-Quit', but kill any buffers that were created by
  6786. the agenda. Org buffers visited directly by the user will not be
  6787. touched. Also, exit the agenda even if it is in column view."
  6788. (interactive)
  6789. (when org-agenda-columns-active
  6790. (org-columns-quit))
  6791. (org-release-buffers org-agenda-new-buffers)
  6792. (setq org-agenda-new-buffers nil)
  6793. (org-agenda-Quit))
  6794. (defun org-agenda-kill-all-agenda-buffers ()
  6795. "Kill all buffers in `org-agenda-mode'.
  6796. This is used when toggling sticky agendas."
  6797. (interactive)
  6798. (let (blist)
  6799. (dolist (buf (buffer-list))
  6800. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6801. (push buf blist)))
  6802. (mapc 'kill-buffer blist)))
  6803. (defun org-agenda-execute (arg)
  6804. "Execute another agenda command, keeping same window.
  6805. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6806. in the agenda."
  6807. (interactive "P")
  6808. (let ((org-agenda-window-setup 'current-window))
  6809. (org-agenda arg)))
  6810. (defun org-agenda-redo (&optional all)
  6811. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6812. (interactive "P")
  6813. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6814. (cpa (unless (eq all t) current-prefix-arg))
  6815. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6816. (org-agenda-sticky nil)
  6817. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6818. org-agenda-buffer-name))
  6819. (org-agenda-keep-modes t)
  6820. (tag-filter org-agenda-tag-filter)
  6821. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6822. (top-hl-filter org-agenda-top-headline-filter)
  6823. (cat-filter org-agenda-category-filter)
  6824. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6825. (re-filter org-agenda-regexp-filter)
  6826. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6827. (effort-filter org-agenda-effort-filter)
  6828. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6829. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6830. (cols org-agenda-columns-active)
  6831. (line (org-current-line))
  6832. (window-line (- line (org-current-line (window-start))))
  6833. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6834. (redo-cmd (get-text-property p 'org-redo-cmd))
  6835. (last-args (get-text-property p 'org-last-args))
  6836. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6837. (org-agenda-overriding-cmd-arguments
  6838. (unless (eq all t)
  6839. (cond ((listp last-args)
  6840. (cons (or cpa (car last-args)) (cdr last-args)))
  6841. ((stringp last-args)
  6842. last-args))))
  6843. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6844. (put 'org-agenda-tag-filter :preset-filter nil)
  6845. (put 'org-agenda-category-filter :preset-filter nil)
  6846. (put 'org-agenda-regexp-filter :preset-filter nil)
  6847. (put 'org-agenda-effort-filter :preset-filter nil)
  6848. (and cols (org-columns-quit))
  6849. (message "Rebuilding agenda buffer...")
  6850. (if series-redo-cmd
  6851. (eval series-redo-cmd)
  6852. (org-let lprops redo-cmd))
  6853. (setq org-agenda-undo-list nil
  6854. org-agenda-pending-undo-list nil
  6855. org-agenda-tag-filter tag-filter
  6856. org-agenda-category-filter cat-filter
  6857. org-agenda-regexp-filter re-filter
  6858. org-agenda-effort-filter effort-filter
  6859. org-agenda-top-headline-filter top-hl-filter)
  6860. (message "Rebuilding agenda buffer...done")
  6861. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6862. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6863. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6864. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6865. (let ((tag (or tag-filter tag-preset))
  6866. (cat (or cat-filter cat-preset))
  6867. (effort (or effort-filter effort-preset))
  6868. (re (or re-filter re-preset)))
  6869. (when tag (org-agenda-filter-apply tag 'tag t))
  6870. (when cat (org-agenda-filter-apply cat 'category))
  6871. (when effort (org-agenda-filter-apply effort 'effort))
  6872. (when re (org-agenda-filter-apply re 'regexp)))
  6873. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6874. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6875. (org-goto-line line)
  6876. (recenter window-line)))
  6877. (defun org-agenda-redo-all (&optional exhaustive)
  6878. "Rebuild all agenda views in the current buffer.
  6879. With a prefix argument, do so in all agenda buffers."
  6880. (interactive "P")
  6881. (if exhaustive
  6882. (dolist (buffer (buffer-list))
  6883. (with-current-buffer buffer
  6884. (when (derived-mode-p 'org-agenda-mode)
  6885. (org-agenda-redo t))))
  6886. (org-agenda-redo t)))
  6887. (defvar org-global-tags-completion-table nil)
  6888. (defvar org-agenda-filter-form nil)
  6889. (defvar org-agenda-filtered-by-category nil)
  6890. (defsubst org-agenda-get-category ()
  6891. "Return the category of the agenda line."
  6892. (org-get-at-bol 'org-category))
  6893. (defun org-agenda-filter-by-category (strip)
  6894. "Filter lines in the agenda buffer that have a specific category.
  6895. The category is that of the current line.
  6896. Without prefix argument, keep only the lines of that category.
  6897. With a prefix argument, exclude the lines of that category.
  6898. "
  6899. (interactive "P")
  6900. (if (and org-agenda-filtered-by-category
  6901. org-agenda-category-filter)
  6902. (org-agenda-filter-show-all-cat)
  6903. (let ((cat (org-no-properties (org-agenda-get-category))))
  6904. (cond
  6905. ((and cat strip)
  6906. (org-agenda-filter-apply
  6907. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6908. (cat
  6909. (org-agenda-filter-apply
  6910. (setq org-agenda-category-filter
  6911. (list (concat "+" cat))) 'category))
  6912. (t (error "No category at point"))))))
  6913. (defun org-find-top-headline (&optional pos)
  6914. "Find the topmost parent headline and return it.
  6915. POS when non-nil is the marker or buffer position to start the
  6916. search from."
  6917. (save-excursion
  6918. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  6919. (when pos (goto-char pos))
  6920. ;; Skip up to the topmost parent.
  6921. (while (org-up-heading-safe))
  6922. (ignore-errors (nth 4 (org-heading-components))))))
  6923. (defvar org-agenda-filtered-by-top-headline nil)
  6924. (defun org-agenda-filter-by-top-headline (strip)
  6925. "Keep only those lines that are descendants from the same top headline.
  6926. The top headline is that of the current line."
  6927. (interactive "P")
  6928. (if org-agenda-filtered-by-top-headline
  6929. (progn
  6930. (setq org-agenda-filtered-by-top-headline nil
  6931. org-agenda-top-headline-filter nil)
  6932. (org-agenda-filter-show-all-top-filter))
  6933. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6934. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6935. (error "No top-level headline at point")))))
  6936. (defvar org-agenda-regexp-filter nil)
  6937. (defun org-agenda-filter-by-regexp (strip)
  6938. "Filter agenda entries by regular expressions.
  6939. With one prefix argument, filter out entries matching the regexp.
  6940. If there is already a regexp filter, remove it unless called with
  6941. two prefix arguments."
  6942. (interactive "P")
  6943. (cond
  6944. ((and org-agenda-regexp-filter (not (equal strip '(16))))
  6945. (org-agenda-filter-show-all-re)
  6946. (message "Regexp filter removed"))
  6947. (t (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6948. (read-from-minibuffer
  6949. (if (equal strip '(4))
  6950. "Filter out entries matching regexp: "
  6951. "Narrow to entries matching regexp: ")))))
  6952. (push flt org-agenda-regexp-filter)
  6953. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp)))))
  6954. (defvar org-agenda-effort-filter nil)
  6955. (defun org-agenda-filter-by-effort (strip)
  6956. "Filter agenda entries by effort.
  6957. With no prefix argument, keep entries matching the effort condition.
  6958. With one prefix argument, filter out entries matching the condition.
  6959. With two prefix arguments, remove the effort filters."
  6960. (interactive "P")
  6961. (cond
  6962. ((member strip '(nil 4))
  6963. (let* ((efforts (split-string
  6964. (or (cdr (assoc (concat org-effort-property "_ALL")
  6965. org-global-properties))
  6966. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6967. ;; XXX: the following handles only up to 10 different
  6968. ;; effort values.
  6969. (allowed-keys (if (null efforts) nil
  6970. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6971. (number-sequence 1 (length efforts)))))
  6972. (op nil))
  6973. (while (not (memq op '(?< ?> ?=)))
  6974. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6975. ;; Select appropriate duration. Ignore non-digit characters.
  6976. (let ((prompt
  6977. (apply #'format
  6978. (concat "Effort %c "
  6979. (mapconcat (lambda (s) (concat "[%d]" s))
  6980. efforts
  6981. " "))
  6982. op allowed-keys))
  6983. (eff -1))
  6984. (while (not (memq eff allowed-keys))
  6985. (message prompt)
  6986. (setq eff (- (read-char-exclusive) 48)))
  6987. (setq org-agenda-effort-filter
  6988. (list (concat (if strip "-" "+")
  6989. (char-to-string op)
  6990. ;; Numbering is 1 2 3 ... 9 0, but we want
  6991. ;; 0 1 2 ... 8 9.
  6992. (nth (mod (1- eff) 10) efforts)))))
  6993. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6994. (t (org-agenda-filter-show-all-effort)
  6995. (message "Effort filter removed"))))
  6996. (defun org-agenda-filter-remove-all ()
  6997. "Remove all filters from the current agenda buffer."
  6998. (interactive)
  6999. (when org-agenda-tag-filter
  7000. (org-agenda-filter-show-all-tag))
  7001. (when org-agenda-category-filter
  7002. (org-agenda-filter-show-all-cat))
  7003. (when org-agenda-regexp-filter
  7004. (org-agenda-filter-show-all-re))
  7005. (when org-agenda-top-headline-filter
  7006. (org-agenda-filter-show-all-top-filter))
  7007. (when org-agenda-effort-filter
  7008. (org-agenda-filter-show-all-effort))
  7009. (org-agenda-finalize))
  7010. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  7011. "Keep only those lines in the agenda buffer that have a specific tag.
  7012. The tag is selected with its fast selection letter, as configured.
  7013. With a `\\[universal-argument]' prefix, exclude the agenda search.
  7014. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7015. i.e. don't
  7016. filter on all its group members.
  7017. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  7018. should be used to exclude the search - the interactive user can
  7019. also press `-' or `+' to switch between filtering and excluding."
  7020. (interactive "P")
  7021. (let* ((alist org-tag-alist-for-agenda)
  7022. (tag-chars (mapconcat
  7023. (lambda (x) (if (and (not (symbolp (car x)))
  7024. (cdr x))
  7025. (char-to-string (cdr x))
  7026. ""))
  7027. org-tag-alist-for-agenda ""))
  7028. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  7029. (string-to-list tag-chars)))
  7030. (exclude (or exclude (equal arg '(4))))
  7031. (expand (not (equal arg '(16))))
  7032. (inhibit-read-only t)
  7033. (current org-agenda-tag-filter)
  7034. a n tag)
  7035. (unless char
  7036. (while (not (memq char valid-char-list))
  7037. (org-unlogged-message
  7038. "%s by tag [%s ]:tag-char, [TAB]:tag, %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  7039. (if exclude "Exclude" "Filter")
  7040. tag-chars
  7041. (if org-agenda-auto-exclude-function "[RET], " "")
  7042. (if expand "" ", no grouptag expand"))
  7043. (setq char (read-char-exclusive))
  7044. ;; Excluding or filtering down
  7045. (cond ((eq char ?-) (setq exclude t))
  7046. ((eq char ?+) (setq exclude nil)))))
  7047. (when (eq char ?\t)
  7048. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  7049. (setq-local org-global-tags-completion-table
  7050. (org-global-tags-completion-table)))
  7051. (let ((completion-ignore-case t))
  7052. (setq tag (completing-read
  7053. "Tag: " org-global-tags-completion-table nil t))))
  7054. (cond
  7055. ((eq char ?\r)
  7056. (org-agenda-filter-show-all-tag)
  7057. (when org-agenda-auto-exclude-function
  7058. (setq org-agenda-tag-filter nil)
  7059. (dolist (tag (org-agenda-get-represented-tags))
  7060. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7061. (when modifier
  7062. (push modifier org-agenda-tag-filter))))
  7063. (unless (null org-agenda-tag-filter)
  7064. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7065. ((eq char ?/)
  7066. (org-agenda-filter-show-all-tag)
  7067. (when (get 'org-agenda-tag-filter :preset-filter)
  7068. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7069. ((eq char ?.)
  7070. (setq org-agenda-tag-filter
  7071. (mapcar (lambda(tag) (concat "+" tag))
  7072. (org-get-at-bol 'tags)))
  7073. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7074. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7075. ((or (eq char ?\s)
  7076. (setq a (rassoc char alist))
  7077. (and tag (setq a (cons tag nil))))
  7078. (org-agenda-filter-show-all-tag)
  7079. (setq tag (car a))
  7080. (setq org-agenda-tag-filter
  7081. (cons (concat (if exclude "-" "+") tag)
  7082. current))
  7083. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7084. (t (error "Invalid tag selection character %c" char)))))
  7085. (defun org-agenda-get-represented-tags ()
  7086. "Get a list of all tags currently represented in the agenda."
  7087. (let (p tags)
  7088. (save-excursion
  7089. (goto-char (point-min))
  7090. (while (setq p (next-single-property-change (point) 'tags))
  7091. (goto-char p)
  7092. (mapc (lambda (x) (add-to-list 'tags x))
  7093. (get-text-property (point) 'tags))))
  7094. tags))
  7095. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7096. "Create the form that tests a line for agenda filter. Optional
  7097. argument EXPAND can be used for the TYPE tag and will expand the
  7098. tags in the FILTER if any of the tags in FILTER are grouptags."
  7099. (let (f f1)
  7100. (cond
  7101. ;; Tag filter
  7102. ((eq type 'tag)
  7103. (setq filter
  7104. (delete-dups
  7105. (append (get 'org-agenda-tag-filter :preset-filter)
  7106. filter)))
  7107. (dolist (x filter)
  7108. (let ((op (string-to-char x)))
  7109. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7110. (setq x (list x)))
  7111. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7112. (push f1 f))))
  7113. ;; Category filter
  7114. ((eq type 'category)
  7115. (setq filter
  7116. (delete-dups
  7117. (append (get 'org-agenda-category-filter :preset-filter)
  7118. filter)))
  7119. (dolist (x filter)
  7120. (if (equal "-" (substring x 0 1))
  7121. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7122. (setq f1 (list 'equal (substring x 1) 'cat)))
  7123. (push f1 f)))
  7124. ;; Regexp filter
  7125. ((eq type 'regexp)
  7126. (setq filter
  7127. (delete-dups
  7128. (append (get 'org-agenda-regexp-filter :preset-filter)
  7129. filter)))
  7130. (dolist (x filter)
  7131. (if (equal "-" (substring x 0 1))
  7132. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7133. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7134. (push f1 f)))
  7135. ;; Effort filter
  7136. ((eq type 'effort)
  7137. (setq filter
  7138. (delete-dups
  7139. (append (get 'org-agenda-effort-filter :preset-filter)
  7140. filter)))
  7141. (dolist (x filter)
  7142. (push (org-agenda-filter-effort-form x) f))))
  7143. (cons 'and (nreverse f))))
  7144. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7145. "Return a form associated to tag-expression TAGS.
  7146. Build a form testing a line for agenda filter for
  7147. tag-expressions. OP is an operator of type CHAR that allows the
  7148. function to set the right switches in the returned form."
  7149. (let (form)
  7150. ;; Any of the expressions can match if OP is +, all must match if
  7151. ;; the operator is -.
  7152. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7153. (let* ((tag (substring x 1))
  7154. (f (cond
  7155. ((string= "" tag) '(not tags))
  7156. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7157. ;; TAG is a regexp.
  7158. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7159. (t (list 'member (downcase tag) 'tags)))))
  7160. (push (if (eq op ?-) (list 'not f) f) form)))))
  7161. (defun org-agenda-filter-effort-form (e)
  7162. "Return the form to compare the effort of the current line with what E says.
  7163. E looks like \"+<2:25\"."
  7164. (let (op)
  7165. (setq e (substring e 1))
  7166. (setq op (string-to-char e) e (substring e 1))
  7167. (setq op (cond ((equal op ?<) '<=)
  7168. ((equal op ?>) '>=)
  7169. ((equal op ??) op)
  7170. (t '=)))
  7171. (list 'org-agenda-compare-effort (list 'quote op)
  7172. (org-duration-to-minutes e))))
  7173. (defun org-agenda-compare-effort (op value)
  7174. "Compare the effort of the current line with VALUE, using OP.
  7175. If the line does not have an effort defined, return nil."
  7176. ;; `effort-minutes' property cannot be extracted directly from
  7177. ;; current line but is stored as a property in `txt'.
  7178. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7179. (funcall op
  7180. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7181. value)))
  7182. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7183. "Expand group tags in FILTER for the agenda.
  7184. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7185. (if org-group-tags
  7186. (let ((case-fold-search t) rtn)
  7187. (mapc
  7188. (lambda (f)
  7189. (let (f0 dir)
  7190. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7191. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7192. (setq dir (if no-operator "" "+") f0 f))
  7193. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7194. (org-tags-expand f0 t t))
  7195. rtn))))
  7196. filter)
  7197. (reverse rtn))
  7198. filter))
  7199. (defun org-agenda-filter-apply (filter type &optional expand)
  7200. "Set FILTER as the new agenda filter and apply it. Optional
  7201. argument EXPAND can be used for the TYPE tag and will expand the
  7202. tags in the FILTER if any of the tags in FILTER are grouptags."
  7203. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7204. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7205. (let (tags cat txt)
  7206. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7207. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7208. ;; category is used as the filter:
  7209. (setq org-agenda-filtered-by-category
  7210. (and (eq type 'category)
  7211. (not (equal (substring (car filter) 0 1) "-"))))
  7212. (org-agenda-set-mode-name)
  7213. (save-excursion
  7214. (goto-char (point-min))
  7215. (while (not (eobp))
  7216. (if (org-get-at-bol 'org-marker)
  7217. (progn
  7218. (setq tags (org-get-at-bol 'tags)
  7219. cat (org-agenda-get-category)
  7220. txt (org-get-at-bol 'txt))
  7221. (unless (eval org-agenda-filter-form)
  7222. (org-agenda-filter-hide-line type))
  7223. (beginning-of-line 2))
  7224. (beginning-of-line 2))))
  7225. (when (get-char-property (point) 'invisible)
  7226. (ignore-errors (org-agenda-previous-line)))))
  7227. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7228. "Filter by top headline HL."
  7229. (org-agenda-set-mode-name)
  7230. (save-excursion
  7231. (goto-char (point-min))
  7232. (while (not (eobp))
  7233. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7234. (tophl (and pos (org-find-top-headline pos))))
  7235. (when (and tophl (funcall (if negative 'identity 'not)
  7236. (string= hl tophl)))
  7237. (org-agenda-filter-hide-line 'top-headline)))
  7238. (beginning-of-line 2)))
  7239. (when (get-char-property (point) 'invisible)
  7240. (org-agenda-previous-line))
  7241. (setq org-agenda-top-headline-filter hl
  7242. org-agenda-filtered-by-top-headline t))
  7243. (defun org-agenda-filter-hide-line (type)
  7244. "Hide lines with TYPE in the agenda buffer."
  7245. (let* ((b (max (point-min) (1- (point-at-bol))))
  7246. (e (point-at-eol)))
  7247. (let ((inhibit-read-only t))
  7248. (add-text-properties
  7249. b e `(invisible org-filtered org-filter-type ,type)))))
  7250. (defun org-agenda-remove-filter (type)
  7251. (interactive)
  7252. "Remove filter of type TYPE from the agenda buffer."
  7253. (save-excursion
  7254. (goto-char (point-min))
  7255. (let ((inhibit-read-only t) pos)
  7256. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7257. (goto-char pos)
  7258. (remove-text-properties
  7259. (point) (next-single-property-change (point) 'org-filter-type)
  7260. `(invisible org-filtered org-filter-type ,type))))
  7261. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7262. (setq org-agenda-filter-form nil)
  7263. (org-agenda-set-mode-name)
  7264. (org-agenda-finalize)))
  7265. (defun org-agenda-filter-show-all-tag nil
  7266. (org-agenda-remove-filter 'tag))
  7267. (defun org-agenda-filter-show-all-re nil
  7268. (org-agenda-remove-filter 'regexp))
  7269. (defun org-agenda-filter-show-all-effort nil
  7270. (org-agenda-remove-filter 'effort))
  7271. (defun org-agenda-filter-show-all-cat nil
  7272. (org-agenda-remove-filter 'category))
  7273. (defun org-agenda-filter-show-all-top-filter nil
  7274. (org-agenda-remove-filter 'top-headline))
  7275. (defun org-agenda-manipulate-query-add ()
  7276. "Manipulate the query by adding a search term with positive selection.
  7277. Positive selection means the term must be matched for selection of an entry."
  7278. (interactive)
  7279. (org-agenda-manipulate-query ?\[))
  7280. (defun org-agenda-manipulate-query-subtract ()
  7281. "Manipulate the query by adding a search term with negative selection.
  7282. Negative selection means term must not be matched for selection of an entry."
  7283. (interactive)
  7284. (org-agenda-manipulate-query ?\]))
  7285. (defun org-agenda-manipulate-query-add-re ()
  7286. "Manipulate the query by adding a search regexp with positive selection.
  7287. Positive selection means the regexp must match for selection of an entry."
  7288. (interactive)
  7289. (org-agenda-manipulate-query ?\{))
  7290. (defun org-agenda-manipulate-query-subtract-re ()
  7291. "Manipulate the query by adding a search regexp with negative selection.
  7292. Negative selection means regexp must not match for selection of an entry."
  7293. (interactive)
  7294. (org-agenda-manipulate-query ?\}))
  7295. (defun org-agenda-manipulate-query (char)
  7296. (cond
  7297. ((eq org-agenda-type 'agenda)
  7298. (let ((org-agenda-include-inactive-timestamps t))
  7299. (org-agenda-redo))
  7300. (message "Display now includes inactive timestamps as well"))
  7301. ((eq org-agenda-type 'search)
  7302. (org-add-to-string
  7303. 'org-agenda-query-string
  7304. (if org-agenda-last-search-view-search-was-boolean
  7305. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7306. (?\{ . " +{}") (?\} . " -{}"))))
  7307. " "))
  7308. (setq org-agenda-redo-command
  7309. (list 'org-search-view
  7310. (car (get-text-property (min (1- (point-max)) (point))
  7311. 'org-last-args))
  7312. org-agenda-query-string
  7313. (+ (length org-agenda-query-string)
  7314. (if (member char '(?\{ ?\})) 0 1))))
  7315. (set-register org-agenda-query-register org-agenda-query-string)
  7316. (let ((org-agenda-overriding-arguments
  7317. (cdr org-agenda-redo-command)))
  7318. (org-agenda-redo)))
  7319. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7320. org-agenda-type))))
  7321. (defun org-add-to-string (var string)
  7322. (set var (concat (symbol-value var) string)))
  7323. (defun org-agenda-goto-date (span)
  7324. "Jump to DATE in agenda."
  7325. (interactive "P")
  7326. (let* ((org-read-date-prefer-future
  7327. (eval org-agenda-jump-prefer-future))
  7328. (date (org-read-date))
  7329. (day (time-to-days (org-time-string-to-time date)))
  7330. (org-agenda-sticky-orig org-agenda-sticky)
  7331. (org-agenda-buffer-tmp-name (buffer-name))
  7332. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7333. (0-arg (or current-prefix-arg (car args)))
  7334. (2-arg (nth 2 args))
  7335. (with-hour-p (nth 4 org-agenda-redo-command))
  7336. (newcmd (list 'org-agenda-list 0-arg date
  7337. (org-agenda-span-to-ndays
  7338. 2-arg (org-time-string-to-absolute date))
  7339. with-hour-p))
  7340. (newargs (cdr newcmd))
  7341. (inhibit-read-only t)
  7342. org-agenda-sticky)
  7343. (if (not (org-agenda-check-type t 'agenda))
  7344. (error "Not available in non-agenda views")
  7345. (add-text-properties (point-min) (point-max)
  7346. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7347. (org-agenda-redo)
  7348. (goto-char (point-min))
  7349. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7350. (save-excursion (move-beginning-of-line 2) (eobp))))
  7351. (move-beginning-of-line 2))
  7352. (setq org-agenda-sticky org-agenda-sticky-orig
  7353. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7354. (defun org-agenda-goto-today ()
  7355. "Go to today."
  7356. (interactive)
  7357. (org-agenda-check-type t 'agenda)
  7358. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7359. (curspan (nth 2 args))
  7360. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7361. (cond
  7362. (tdpos (goto-char tdpos))
  7363. ((eq org-agenda-type 'agenda)
  7364. (let* ((sd (org-agenda-compute-starting-span
  7365. (org-today) (or curspan org-agenda-span)))
  7366. (org-agenda-overriding-arguments args))
  7367. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7368. (org-agenda-redo)
  7369. (org-agenda-find-same-or-today-or-agenda)))
  7370. (t (error "Cannot find today")))))
  7371. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7372. (goto-char
  7373. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7374. (text-property-any (point-min) (point-max) 'org-today t)
  7375. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7376. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7377. (org-agenda-backward-block))
  7378. (point-min))))
  7379. (defun org-agenda-backward-block ()
  7380. "Move backward by one agenda block."
  7381. (interactive)
  7382. (org-agenda-forward-block 'backward))
  7383. (defun org-agenda-forward-block (&optional backward)
  7384. "Move forward by one agenda block.
  7385. When optional argument BACKWARD is set, go backward"
  7386. (interactive)
  7387. (cond ((not (derived-mode-p 'org-agenda-mode))
  7388. (user-error
  7389. "Cannot execute this command outside of org-agenda-mode buffers"))
  7390. ((looking-at (if backward "\\`" "\\'"))
  7391. (message "Already at the %s block" (if backward "first" "last")))
  7392. (t (let ((pos (prog1 (point)
  7393. (ignore-errors (if backward (backward-char 1)
  7394. (move-end-of-line 1)))))
  7395. (f (if backward
  7396. 'previous-single-property-change
  7397. 'next-single-property-change))
  7398. moved dest)
  7399. (while (and (setq dest (funcall
  7400. f (point) 'org-agenda-structural-header))
  7401. (not (get-text-property
  7402. (point) 'org-agenda-structural-header)))
  7403. (setq moved t)
  7404. (goto-char dest))
  7405. (if moved (move-beginning-of-line 1)
  7406. (goto-char (if backward (point-min) (point-max)))
  7407. (move-beginning-of-line 1)
  7408. (message "No %s block" (if backward "previous" "further")))))))
  7409. (defun org-agenda-later (arg)
  7410. "Go forward in time by the current span.
  7411. With prefix ARG, go forward that many times the current span."
  7412. (interactive "p")
  7413. (org-agenda-check-type t 'agenda)
  7414. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7415. (span (or (nth 2 args) org-agenda-current-span))
  7416. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7417. (greg (calendar-gregorian-from-absolute sd))
  7418. (cnt (org-get-at-bol 'org-day-cnt))
  7419. greg2)
  7420. (cond
  7421. ((numberp span)
  7422. (setq sd (+ (* span arg) sd)))
  7423. ((eq span 'day)
  7424. (setq sd (+ arg sd)))
  7425. ((eq span 'week)
  7426. (setq sd (+ (* 7 arg) sd)))
  7427. ((eq span 'fortnight)
  7428. (setq sd (+ (* 14 arg) sd)))
  7429. ((eq span 'month)
  7430. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7431. sd (calendar-absolute-from-gregorian greg2))
  7432. (setcar greg2 (1+ (car greg2))))
  7433. ((eq span 'year)
  7434. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7435. sd (calendar-absolute-from-gregorian greg2))
  7436. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7437. (t
  7438. (setq sd (+ (* span arg) sd))))
  7439. (let ((org-agenda-overriding-cmd
  7440. ;; `cmd' may have been set by `org-agenda-run-series' which
  7441. ;; uses `org-agenda-overriding-cmd' to decide whether
  7442. ;; overriding is allowed for `cmd'
  7443. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7444. (org-agenda-overriding-arguments
  7445. (list (car args) sd span)))
  7446. (org-agenda-redo)
  7447. (org-agenda-find-same-or-today-or-agenda cnt))))
  7448. (defun org-agenda-earlier (arg)
  7449. "Go backward in time by the current span.
  7450. With prefix ARG, go backward that many times the current span."
  7451. (interactive "p")
  7452. (org-agenda-later (- arg)))
  7453. (defun org-agenda-view-mode-dispatch ()
  7454. "Call one of the view mode commands."
  7455. (interactive)
  7456. (org-unlogged-message
  7457. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7458. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7459. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7460. (pcase (read-char-exclusive)
  7461. (?\ (call-interactively 'org-agenda-reset-view))
  7462. (?d (call-interactively 'org-agenda-day-view))
  7463. (?w (call-interactively 'org-agenda-week-view))
  7464. (?t (call-interactively 'org-agenda-fortnight-view))
  7465. (?m (call-interactively 'org-agenda-month-view))
  7466. (?y (call-interactively 'org-agenda-year-view))
  7467. (?l (call-interactively 'org-agenda-log-mode))
  7468. (?L (org-agenda-log-mode '(4)))
  7469. (?c (org-agenda-log-mode 'clockcheck))
  7470. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7471. (?a (call-interactively 'org-agenda-archives-mode))
  7472. (?A (org-agenda-archives-mode 'files))
  7473. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7474. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7475. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7476. (?D (call-interactively 'org-agenda-toggle-diary))
  7477. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7478. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7479. (org-agenda-check-type t 'agenda)
  7480. (org-agenda-redo))
  7481. (message "Display now includes inactive timestamps as well"))
  7482. (?q (message "Abort"))
  7483. (key (user-error "Invalid key: %s" key))))
  7484. (defun org-agenda-reset-view ()
  7485. "Switch to default view for agenda."
  7486. (interactive)
  7487. (org-agenda-change-time-span org-agenda-span))
  7488. (defun org-agenda-day-view (&optional day-of-month)
  7489. "Switch to daily view for agenda.
  7490. With argument DAY-OF-MONTH, switch to that day of the month."
  7491. (interactive "P")
  7492. (org-agenda-change-time-span 'day day-of-month))
  7493. (defun org-agenda-week-view (&optional iso-week)
  7494. "Switch to weekly view for agenda.
  7495. With argument ISO-WEEK, switch to the corresponding ISO week.
  7496. If ISO-WEEK has more then 2 digits, only the last two encode
  7497. the week. Any digits before this encode a year. So 200712
  7498. means week 12 of year 2007. Years ranging from 70 years ago
  7499. to 30 years in the future can also be written as 2-digit years."
  7500. (interactive "P")
  7501. (org-agenda-change-time-span 'week iso-week))
  7502. (defun org-agenda-fortnight-view (&optional iso-week)
  7503. "Switch to fortnightly view for agenda.
  7504. With argument ISO-WEEK, switch to the corresponding ISO week.
  7505. If ISO-WEEK has more then 2 digits, only the last two encode
  7506. the week. Any digits before this encode a year. So 200712
  7507. means week 12 of year 2007. Years ranging from 70 years ago
  7508. to 30 years in the future can also be written as 2-digit years."
  7509. (interactive "P")
  7510. (org-agenda-change-time-span 'fortnight iso-week))
  7511. (defun org-agenda-month-view (&optional month)
  7512. "Switch to monthly view for agenda.
  7513. With argument MONTH, switch to that month. If MONTH has more
  7514. then 2 digits, only the last two encode the month. Any digits
  7515. before this encode a year. So 200712 means December year 2007.
  7516. Years ranging from 70 years ago to 30 years in the future can
  7517. also be written as 2-digit years."
  7518. (interactive "P")
  7519. (org-agenda-change-time-span 'month month))
  7520. (defun org-agenda-year-view (&optional year)
  7521. "Switch to yearly view for agenda.
  7522. With argument YEAR, switch to that year. Years ranging from 70
  7523. years ago to 30 years in the future can also be written as
  7524. 2-digit years."
  7525. (interactive "P")
  7526. (when year
  7527. (setq year (org-small-year-to-year year)))
  7528. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7529. (org-agenda-change-time-span 'year year)
  7530. (error "Abort")))
  7531. (defun org-agenda-change-time-span (span &optional n)
  7532. "Change the agenda view to SPAN.
  7533. SPAN may be `day', `week', `fortnight', `month', `year'."
  7534. (org-agenda-check-type t 'agenda)
  7535. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7536. (curspan (nth 2 args)))
  7537. (when (and (not n) (equal curspan span))
  7538. (error "Viewing span is already \"%s\"" span))
  7539. (let* ((sd (or (org-get-at-bol 'day)
  7540. (nth 1 args)
  7541. org-starting-day))
  7542. (sd (org-agenda-compute-starting-span sd span n))
  7543. (org-agenda-overriding-cmd
  7544. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7545. (org-agenda-overriding-arguments
  7546. (list (car args) sd span)))
  7547. (org-agenda-redo)
  7548. (org-agenda-find-same-or-today-or-agenda))
  7549. (org-agenda-set-mode-name)
  7550. (message "Switched to %s view" span)))
  7551. (defun org-agenda-compute-starting-span (sd span &optional n)
  7552. "Compute starting date for agenda.
  7553. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7554. is a cons cell with the starting date and the number of days,
  7555. so that the date SD will be in that range."
  7556. (let* ((greg (calendar-gregorian-from-absolute sd))
  7557. (dg (nth 1 greg))
  7558. (mg (car greg))
  7559. (yg (nth 2 greg)))
  7560. (cond
  7561. ((eq span 'day)
  7562. (when n
  7563. (setq sd (+ (calendar-absolute-from-gregorian
  7564. (list mg 1 yg))
  7565. n -1))))
  7566. ((or (eq span 'week) (eq span 'fortnight))
  7567. (let* ((nt (calendar-day-of-week
  7568. (calendar-gregorian-from-absolute sd)))
  7569. (d (if org-agenda-start-on-weekday
  7570. (- nt org-agenda-start-on-weekday)
  7571. 0))
  7572. y1)
  7573. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7574. (when n
  7575. (require 'cal-iso)
  7576. (when (> n 99)
  7577. (setq y1 (org-small-year-to-year (/ n 100))
  7578. n (mod n 100)))
  7579. (setq sd
  7580. (calendar-iso-to-absolute
  7581. (list n 1
  7582. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7583. ((eq span 'month)
  7584. (let (y1)
  7585. (when (and n (> n 99))
  7586. (setq y1 (org-small-year-to-year (/ n 100))
  7587. n (mod n 100)))
  7588. (setq sd (calendar-absolute-from-gregorian
  7589. (list (or n mg) 1 (or y1 yg))))))
  7590. ((eq span 'year)
  7591. (setq sd (calendar-absolute-from-gregorian
  7592. (list 1 1 (or n yg))))))
  7593. sd))
  7594. (defun org-agenda-next-date-line (&optional arg)
  7595. "Jump to the next line indicating a date in agenda buffer."
  7596. (interactive "p")
  7597. (org-agenda-check-type t 'agenda)
  7598. (beginning-of-line 1)
  7599. ;; This does not work if user makes date format that starts with a blank
  7600. (when (looking-at-p "^\\S-") (forward-char 1))
  7601. (unless (re-search-forward "^\\S-" nil t arg)
  7602. (backward-char 1)
  7603. (error "No next date after this line in this buffer"))
  7604. (goto-char (match-beginning 0)))
  7605. (defun org-agenda-previous-date-line (&optional arg)
  7606. "Jump to the previous line indicating a date in agenda buffer."
  7607. (interactive "p")
  7608. (org-agenda-check-type t 'agenda)
  7609. (beginning-of-line 1)
  7610. (unless (re-search-backward "^\\S-" nil t arg)
  7611. (error "No previous date before this line in this buffer")))
  7612. ;; Initialize the highlight
  7613. (defvar org-hl (make-overlay 1 1))
  7614. (overlay-put org-hl 'face 'highlight)
  7615. (defun org-highlight (begin end &optional buffer)
  7616. "Highlight a region with overlay."
  7617. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7618. (defun org-unhighlight ()
  7619. "Detach overlay INDEX."
  7620. (delete-overlay org-hl))
  7621. (defun org-unhighlight-once ()
  7622. "Remove the highlight from its position, and this function from the hook."
  7623. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7624. (org-unhighlight))
  7625. (defvar org-agenda-pre-follow-window-conf nil)
  7626. (defun org-agenda-follow-mode ()
  7627. "Toggle follow mode in an agenda buffer."
  7628. (interactive)
  7629. (unless org-agenda-follow-mode
  7630. (setq org-agenda-pre-follow-window-conf
  7631. (current-window-configuration)))
  7632. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7633. (unless org-agenda-follow-mode
  7634. (set-window-configuration org-agenda-pre-follow-window-conf))
  7635. (org-agenda-set-mode-name)
  7636. (org-agenda-do-context-action)
  7637. (message "Follow mode is %s"
  7638. (if org-agenda-follow-mode "on" "off")))
  7639. (defun org-agenda-entry-text-mode (&optional arg)
  7640. "Toggle entry text mode in an agenda buffer."
  7641. (interactive "P")
  7642. (if (or org-agenda-tag-filter
  7643. org-agenda-category-filter
  7644. org-agenda-regexp-filter
  7645. org-agenda-top-headline-filter)
  7646. (user-error "Can't show entry text in filtered views")
  7647. (setq org-agenda-entry-text-mode (or (integerp arg)
  7648. (not org-agenda-entry-text-mode)))
  7649. (org-agenda-entry-text-hide)
  7650. (and org-agenda-entry-text-mode
  7651. (let ((org-agenda-entry-text-maxlines
  7652. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7653. (org-agenda-entry-text-show)))
  7654. (org-agenda-set-mode-name)
  7655. (message "Entry text mode is %s%s"
  7656. (if org-agenda-entry-text-mode "on" "off")
  7657. (if (not org-agenda-entry-text-mode) ""
  7658. (format " (maximum number of lines is %d)"
  7659. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7660. (defun org-agenda-clockreport-mode ()
  7661. "Toggle clocktable mode in an agenda buffer."
  7662. (interactive)
  7663. (org-agenda-check-type t 'agenda)
  7664. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7665. (org-agenda-set-mode-name)
  7666. (org-agenda-redo)
  7667. (message "Clocktable mode is %s"
  7668. (if org-agenda-clockreport-mode "on" "off")))
  7669. (defun org-agenda-log-mode (&optional special)
  7670. "Toggle log mode in an agenda buffer.
  7671. With argument SPECIAL, show all possible log items, not only the ones
  7672. configured in `org-agenda-log-mode-items'.
  7673. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7674. log items, nothing else."
  7675. (interactive "P")
  7676. (org-agenda-check-type t 'agenda)
  7677. (setq org-agenda-show-log
  7678. (cond
  7679. ((equal special '(16)) 'only)
  7680. ((eq special 'clockcheck)
  7681. (if (eq org-agenda-show-log 'clockcheck)
  7682. nil 'clockcheck))
  7683. (special '(closed clock state))
  7684. (t (not org-agenda-show-log))))
  7685. (org-agenda-set-mode-name)
  7686. (org-agenda-redo)
  7687. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7688. (defun org-agenda-archives-mode (&optional with-files)
  7689. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7690. When called with a prefix argument, include all archive files as well."
  7691. (interactive "P")
  7692. (setq org-agenda-archives-mode
  7693. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7694. (org-agenda-set-mode-name)
  7695. (org-agenda-redo)
  7696. (message
  7697. "%s"
  7698. (cond
  7699. ((eq org-agenda-archives-mode nil)
  7700. "No archives are included")
  7701. ((eq org-agenda-archives-mode 'trees)
  7702. (format "Trees with :%s: tag are included" org-archive-tag))
  7703. ((eq org-agenda-archives-mode t)
  7704. (format "Trees with :%s: tag and all active archive files are included"
  7705. org-archive-tag)))))
  7706. (defun org-agenda-toggle-diary ()
  7707. "Toggle diary inclusion in an agenda buffer."
  7708. (interactive)
  7709. (org-agenda-check-type t 'agenda)
  7710. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7711. (org-agenda-redo)
  7712. (org-agenda-set-mode-name)
  7713. (message "Diary inclusion turned %s"
  7714. (if org-agenda-include-diary "on" "off")))
  7715. (defun org-agenda-toggle-deadlines ()
  7716. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7717. (interactive)
  7718. (org-agenda-check-type t 'agenda)
  7719. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7720. (org-agenda-redo)
  7721. (org-agenda-set-mode-name)
  7722. (message "Deadlines inclusion turned %s"
  7723. (if org-agenda-include-deadlines "on" "off")))
  7724. (defun org-agenda-toggle-time-grid ()
  7725. "Toggle time grid in an agenda buffer."
  7726. (interactive)
  7727. (org-agenda-check-type t 'agenda)
  7728. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7729. (org-agenda-redo)
  7730. (org-agenda-set-mode-name)
  7731. (message "Time-grid turned %s"
  7732. (if org-agenda-use-time-grid "on" "off")))
  7733. (defun org-agenda-set-mode-name ()
  7734. "Set the mode name to indicate all the small mode settings."
  7735. (setq mode-name
  7736. (list "Org-Agenda"
  7737. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7738. " "
  7739. '(:eval (org-agenda-span-name org-agenda-current-span))
  7740. (if org-agenda-follow-mode " Follow" "")
  7741. (if org-agenda-entry-text-mode " ETxt" "")
  7742. (if org-agenda-include-diary " Diary" "")
  7743. (if org-agenda-include-deadlines " Ddl" "")
  7744. (if org-agenda-use-time-grid " Grid" "")
  7745. (if (and (boundp 'org-habit-show-habits)
  7746. org-habit-show-habits) " Habit" "")
  7747. (cond
  7748. ((consp org-agenda-show-log) " LogAll")
  7749. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7750. (org-agenda-show-log " Log")
  7751. (t ""))
  7752. (if (or org-agenda-category-filter
  7753. (get 'org-agenda-category-filter :preset-filter))
  7754. '(:eval (propertize
  7755. (concat " <"
  7756. (mapconcat
  7757. 'identity
  7758. (append
  7759. (get 'org-agenda-category-filter :preset-filter)
  7760. org-agenda-category-filter)
  7761. "")
  7762. ">")
  7763. 'face 'org-agenda-filter-category
  7764. 'help-echo "Category used in filtering")) "")
  7765. (if (or org-agenda-tag-filter
  7766. (get 'org-agenda-tag-filter :preset-filter))
  7767. '(:eval (propertize
  7768. (concat " {"
  7769. (mapconcat
  7770. 'identity
  7771. (append
  7772. (get 'org-agenda-tag-filter :preset-filter)
  7773. org-agenda-tag-filter)
  7774. "")
  7775. "}")
  7776. 'face 'org-agenda-filter-tags
  7777. 'help-echo "Tags used in filtering")) "")
  7778. (if (or org-agenda-effort-filter
  7779. (get 'org-agenda-effort-filter :preset-filter))
  7780. '(:eval (propertize
  7781. (concat " {"
  7782. (mapconcat
  7783. 'identity
  7784. (append
  7785. (get 'org-agenda-effort-filter :preset-filter)
  7786. org-agenda-effort-filter)
  7787. "")
  7788. "}")
  7789. 'face 'org-agenda-filter-effort
  7790. 'help-echo "Effort conditions used in filtering")) "")
  7791. (if (or org-agenda-regexp-filter
  7792. (get 'org-agenda-regexp-filter :preset-filter))
  7793. '(:eval (propertize
  7794. (concat " ["
  7795. (mapconcat
  7796. 'identity
  7797. (append
  7798. (get 'org-agenda-regexp-filter :preset-filter)
  7799. org-agenda-regexp-filter)
  7800. "")
  7801. "]")
  7802. 'face 'org-agenda-filter-regexp
  7803. 'help-echo "Regexp used in filtering")) "")
  7804. (if org-agenda-archives-mode
  7805. (if (eq org-agenda-archives-mode t)
  7806. " Archives"
  7807. (format " :%s:" org-archive-tag))
  7808. "")
  7809. (if org-agenda-clockreport-mode " Clock" "")))
  7810. (force-mode-line-update))
  7811. (defun org-agenda-update-agenda-type ()
  7812. "Update the agenda type after each command."
  7813. (setq org-agenda-type
  7814. (or (get-text-property (point) 'org-agenda-type)
  7815. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7816. (defun org-agenda-next-line ()
  7817. "Move cursor to the next line, and show if follow mode is active."
  7818. (interactive)
  7819. (call-interactively 'next-line)
  7820. (org-agenda-do-context-action))
  7821. (defun org-agenda-previous-line ()
  7822. "Move cursor to the previous line, and show if follow-mode is active."
  7823. (interactive)
  7824. (call-interactively 'previous-line)
  7825. (org-agenda-do-context-action))
  7826. (defun org-agenda-next-item (n)
  7827. "Move cursor to next agenda item."
  7828. (interactive "p")
  7829. (let ((col (current-column)))
  7830. (dotimes (c n)
  7831. (when (next-single-property-change (point-at-eol) 'org-marker)
  7832. (move-end-of-line 1)
  7833. (goto-char (next-single-property-change (point) 'org-marker))))
  7834. (org-move-to-column col))
  7835. (org-agenda-do-context-action))
  7836. (defun org-agenda-previous-item (n)
  7837. "Move cursor to next agenda item."
  7838. (interactive "p")
  7839. (dotimes (c n)
  7840. (let ((col (current-column))
  7841. (goto (save-excursion
  7842. (move-end-of-line 0)
  7843. (previous-single-property-change (point) 'org-marker))))
  7844. (when goto (goto-char goto))
  7845. (org-move-to-column col)))
  7846. (org-agenda-do-context-action))
  7847. (defun org-agenda-do-context-action ()
  7848. "Show outline path and, maybe, follow mode window."
  7849. (let ((m (org-get-at-bol 'org-marker)))
  7850. (when (and (markerp m) (marker-buffer m))
  7851. (and org-agenda-follow-mode
  7852. (if org-agenda-follow-indirect
  7853. (org-agenda-tree-to-indirect-buffer nil)
  7854. (org-agenda-show)))
  7855. (and org-agenda-show-outline-path
  7856. (org-with-point-at m (org-display-outline-path t))))))
  7857. (defun org-agenda-show-tags ()
  7858. "Show the tags applicable to the current item."
  7859. (interactive)
  7860. (let* ((tags (org-get-at-bol 'tags)))
  7861. (if tags
  7862. (message "Tags are :%s:"
  7863. (org-no-properties (mapconcat 'identity tags ":")))
  7864. (message "No tags associated with this line"))))
  7865. (defun org-agenda-goto (&optional highlight)
  7866. "Go to the entry at point in the corresponding Org file."
  7867. (interactive)
  7868. (let* ((marker (or (org-get-at-bol 'org-marker)
  7869. (org-agenda-error)))
  7870. (buffer (marker-buffer marker))
  7871. (pos (marker-position marker)))
  7872. (switch-to-buffer-other-window buffer)
  7873. (widen)
  7874. (push-mark)
  7875. (goto-char pos)
  7876. (when (derived-mode-p 'org-mode)
  7877. (org-show-context 'agenda)
  7878. (recenter (/ (window-height) 2))
  7879. (org-back-to-heading t)
  7880. (let ((case-fold-search nil))
  7881. (when (re-search-forward org-complex-heading-regexp nil t)
  7882. (goto-char (match-beginning 4)))))
  7883. (run-hooks 'org-agenda-after-show-hook)
  7884. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7885. (defvar org-agenda-after-show-hook nil
  7886. "Normal hook run after an item has been shown from the agenda.
  7887. Point is in the buffer where the item originated.")
  7888. (defun org-agenda-kill ()
  7889. "Kill the entry or subtree belonging to the current agenda entry."
  7890. (interactive)
  7891. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7892. (let* ((bufname-orig (buffer-name))
  7893. (marker (or (org-get-at-bol 'org-marker)
  7894. (org-agenda-error)))
  7895. (buffer (marker-buffer marker))
  7896. (pos (marker-position marker))
  7897. (type (org-get-at-bol 'type))
  7898. dbeg dend (n 0) conf)
  7899. (org-with-remote-undo buffer
  7900. (with-current-buffer buffer
  7901. (save-excursion
  7902. (goto-char pos)
  7903. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7904. (setq dbeg (progn (org-back-to-heading t) (point))
  7905. dend (org-end-of-subtree t t))
  7906. (setq dbeg (point-at-bol)
  7907. dend (min (point-max) (1+ (point-at-eol)))))
  7908. (goto-char dbeg)
  7909. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7910. (setq conf (or (eq t org-agenda-confirm-kill)
  7911. (and (numberp org-agenda-confirm-kill)
  7912. (> n org-agenda-confirm-kill))))
  7913. (and conf
  7914. (not (y-or-n-p
  7915. (format "Delete entry with %d lines in buffer \"%s\"? "
  7916. n (buffer-name buffer))))
  7917. (error "Abort"))
  7918. (let ((org-agenda-buffer-name bufname-orig))
  7919. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7920. (with-current-buffer buffer (delete-region dbeg dend))
  7921. (message "Agenda item and source killed"))))
  7922. (defvar org-archive-default-command) ; defined in org-archive.el
  7923. (defun org-agenda-archive-default ()
  7924. "Archive the entry or subtree belonging to the current agenda entry."
  7925. (interactive)
  7926. (require 'org-archive)
  7927. (org-agenda-archive-with org-archive-default-command))
  7928. (defun org-agenda-archive-default-with-confirmation ()
  7929. "Archive the entry or subtree belonging to the current agenda entry."
  7930. (interactive)
  7931. (require 'org-archive)
  7932. (org-agenda-archive-with org-archive-default-command 'confirm))
  7933. (defun org-agenda-archive ()
  7934. "Archive the entry or subtree belonging to the current agenda entry."
  7935. (interactive)
  7936. (org-agenda-archive-with 'org-archive-subtree))
  7937. (defun org-agenda-archive-to-archive-sibling ()
  7938. "Move the entry to the archive sibling."
  7939. (interactive)
  7940. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7941. (defun org-agenda-archive-with (cmd &optional confirm)
  7942. "Move the entry to the archive sibling."
  7943. (interactive)
  7944. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7945. (let* ((bufname-orig (buffer-name))
  7946. (marker (or (org-get-at-bol 'org-marker)
  7947. (org-agenda-error)))
  7948. (buffer (marker-buffer marker))
  7949. (pos (marker-position marker)))
  7950. (org-with-remote-undo buffer
  7951. (with-current-buffer buffer
  7952. (if (derived-mode-p 'org-mode)
  7953. (if (and confirm
  7954. (not (y-or-n-p "Archive this subtree or entry? ")))
  7955. (error "Abort")
  7956. (save-window-excursion
  7957. (goto-char pos)
  7958. (let ((org-agenda-buffer-name bufname-orig))
  7959. (org-remove-subtree-entries-from-agenda))
  7960. (org-back-to-heading t)
  7961. (funcall cmd)))
  7962. (error "Archiving works only in Org files"))))))
  7963. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7964. "Remove all lines in the agenda that correspond to a given subtree.
  7965. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7966. If this information is not given, the function uses the tree at point."
  7967. (let ((buf (or buf (current-buffer))) m p)
  7968. (save-excursion
  7969. (unless (and beg end)
  7970. (org-back-to-heading t)
  7971. (setq beg (point))
  7972. (org-end-of-subtree t)
  7973. (setq end (point)))
  7974. (set-buffer (get-buffer org-agenda-buffer-name))
  7975. (save-excursion
  7976. (goto-char (point-max))
  7977. (beginning-of-line 1)
  7978. (while (not (bobp))
  7979. (when (and (setq m (org-get-at-bol 'org-marker))
  7980. (equal buf (marker-buffer m))
  7981. (setq p (marker-position m))
  7982. (>= p beg)
  7983. (< p end))
  7984. (let ((inhibit-read-only t))
  7985. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7986. (beginning-of-line 0))))))
  7987. (defun org-agenda-refile (&optional goto rfloc no-update)
  7988. "Refile the item at point.
  7989. When called with `\\[universal-argument] \\[universal-argument]', \
  7990. go to the location of the last
  7991. refiled item.
  7992. When called with `\\[universal-argument] \\[universal-argument] \
  7993. \\[universal-argument]' prefix or when GOTO is 0, clear
  7994. the refile cache.
  7995. RFLOC can be a refile location obtained in a different way.
  7996. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7997. (interactive "P")
  7998. (cond
  7999. ((member goto '(0 (64)))
  8000. (org-refile-cache-clear))
  8001. ((equal goto '(16))
  8002. (org-refile-goto-last-stored))
  8003. (t
  8004. (let* ((buffer-orig (buffer-name))
  8005. (marker (or (org-get-at-bol 'org-hd-marker)
  8006. (org-agenda-error)))
  8007. (buffer (marker-buffer marker))
  8008. (pos (marker-position marker))
  8009. (rfloc (or rfloc
  8010. (org-refile-get-location
  8011. (if goto "Goto" "Refile to") buffer
  8012. org-refile-allow-creating-parent-nodes))))
  8013. (with-current-buffer buffer
  8014. (org-with-wide-buffer
  8015. (goto-char marker)
  8016. (let ((org-agenda-buffer-name buffer-orig))
  8017. (org-remove-subtree-entries-from-agenda))
  8018. (org-refile goto buffer rfloc))))
  8019. (unless no-update (org-agenda-redo)))))
  8020. (defun org-agenda-open-link (&optional arg)
  8021. "Open the link(s) in the current entry, if any.
  8022. This looks for a link in the displayed line in the agenda.
  8023. It also looks at the text of the entry itself."
  8024. (interactive "P")
  8025. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8026. (org-get-at-bol 'org-marker)))
  8027. (buffer (and marker (marker-buffer marker)))
  8028. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8029. (lkall (and buffer (org-offer-links-in-entry
  8030. buffer marker arg prefix)))
  8031. (lk0 (car lkall))
  8032. (lk (if (stringp lk0) (list lk0) lk0))
  8033. (lkend (cdr lkall))
  8034. trg)
  8035. (cond
  8036. ((and buffer lk)
  8037. (mapcar (lambda(l)
  8038. (with-current-buffer buffer
  8039. (setq trg (and (string-match org-link-bracket-re l)
  8040. (match-string 1 l)))
  8041. (if (or (not trg) (string-match org-link-any-re trg))
  8042. (org-with-wide-buffer
  8043. (goto-char marker)
  8044. (when (search-forward l nil lkend)
  8045. (goto-char (match-beginning 0))
  8046. (org-open-at-point)))
  8047. ;; This is an internal link, widen the buffer
  8048. (switch-to-buffer-other-window buffer)
  8049. (widen)
  8050. (goto-char marker)
  8051. (when (search-forward l nil lkend)
  8052. (goto-char (match-beginning 0))
  8053. (org-open-at-point)))))
  8054. lk))
  8055. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  8056. (save-excursion
  8057. (beginning-of-line 1)
  8058. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  8059. (org-link-open-from-string (match-string 1)))
  8060. (t (message "No link to open here")))))
  8061. (defun org-agenda-copy-local-variable (var)
  8062. "Get a variable from a referenced buffer and install it here."
  8063. (let ((m (org-get-at-bol 'org-marker)))
  8064. (when (and m (buffer-live-p (marker-buffer m)))
  8065. (set (make-local-variable var)
  8066. (with-current-buffer (marker-buffer m)
  8067. (symbol-value var))))))
  8068. (defun org-agenda-switch-to (&optional delete-other-windows)
  8069. "Go to the Org mode file which contains the item at point.
  8070. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8071. displayed Org file fills the frame."
  8072. (interactive)
  8073. (if (and org-return-follows-link
  8074. (not (org-get-at-bol 'org-marker))
  8075. (org-in-regexp org-link-bracket-re))
  8076. (org-link-open-from-string (match-string 0))
  8077. (let* ((marker (or (org-get-at-bol 'org-marker)
  8078. (org-agenda-error)))
  8079. (buffer (marker-buffer marker))
  8080. (pos (marker-position marker)))
  8081. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8082. (pop-to-buffer-same-window buffer)
  8083. (when delete-other-windows (delete-other-windows))
  8084. (widen)
  8085. (goto-char pos)
  8086. (when (derived-mode-p 'org-mode)
  8087. (org-show-context 'agenda)
  8088. (run-hooks 'org-agenda-after-show-hook)))))
  8089. (defun org-agenda-goto-mouse (ev)
  8090. "Go to the Org file which contains the item at the mouse click."
  8091. (interactive "e")
  8092. (mouse-set-point ev)
  8093. (org-agenda-goto))
  8094. (defun org-agenda-show (&optional full-entry)
  8095. "Display the Org file which contains the item at point.
  8096. With prefix argument FULL-ENTRY, make the entire entry visible
  8097. if it was hidden in the outline."
  8098. (interactive "P")
  8099. (let ((win (selected-window)))
  8100. (org-agenda-goto t)
  8101. (when full-entry (org-show-entry))
  8102. (select-window win)))
  8103. (defvar org-agenda-show-window nil)
  8104. (defun org-agenda-show-and-scroll-up (&optional arg)
  8105. "Display the Org file which contains the item at point.
  8106. When called repeatedly, scroll the window that is displaying the buffer.
  8107. With a `\\[universal-argument]' prefix argument, display the item, but \
  8108. fold drawers."
  8109. (interactive "P")
  8110. (let ((win (selected-window)))
  8111. (if (and (window-live-p org-agenda-show-window)
  8112. (eq this-command last-command))
  8113. (progn
  8114. (select-window org-agenda-show-window)
  8115. (ignore-errors (scroll-up)))
  8116. (org-agenda-goto t)
  8117. (org-show-entry)
  8118. (if arg (org-cycle-hide-drawers 'children)
  8119. (org-with-wide-buffer
  8120. (narrow-to-region (org-entry-beginning-position)
  8121. (org-entry-end-position))
  8122. (org-show-all '(drawers))))
  8123. (when arg )
  8124. (setq org-agenda-show-window (selected-window)))
  8125. (select-window win)))
  8126. (defun org-agenda-show-scroll-down ()
  8127. "Scroll down the window showing the agenda."
  8128. (interactive)
  8129. (let ((win (selected-window)))
  8130. (when (window-live-p org-agenda-show-window)
  8131. (select-window org-agenda-show-window)
  8132. (ignore-errors (scroll-down))
  8133. (select-window win))))
  8134. (defun org-agenda-show-1 (&optional more)
  8135. "Display the Org file which contains the item at point.
  8136. The prefix arg selects the amount of information to display:
  8137. 0 hide the subtree
  8138. 1 just show the entry according to defaults.
  8139. 2 show the children view
  8140. 3 show the subtree view
  8141. 4 show the entire subtree and any LOGBOOK drawers
  8142. 5 show the entire subtree and any drawers
  8143. With prefix argument FULL-ENTRY, make the entire entry visible
  8144. if it was hidden in the outline."
  8145. (interactive "p")
  8146. (let ((win (selected-window)))
  8147. (org-agenda-goto t)
  8148. (org-back-to-heading)
  8149. (set-window-start (selected-window) (point-at-bol))
  8150. (cond
  8151. ((= more 0)
  8152. (outline-hide-subtree)
  8153. (save-excursion
  8154. (org-back-to-heading)
  8155. (run-hook-with-args 'org-cycle-hook 'folded))
  8156. (message "Remote: FOLDED"))
  8157. ((and (called-interactively-p 'any) (= more 1))
  8158. (message "Remote: show with default settings"))
  8159. ((= more 2)
  8160. (outline-show-entry)
  8161. (org-show-children)
  8162. (save-excursion
  8163. (org-back-to-heading)
  8164. (run-hook-with-args 'org-cycle-hook 'children))
  8165. (message "Remote: CHILDREN"))
  8166. ((= more 3)
  8167. (outline-show-subtree)
  8168. (save-excursion
  8169. (org-back-to-heading)
  8170. (run-hook-with-args 'org-cycle-hook 'subtree))
  8171. (message "Remote: SUBTREE"))
  8172. ((= more 4)
  8173. (outline-show-subtree)
  8174. (save-excursion
  8175. (org-back-to-heading)
  8176. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8177. (message "Remote: SUBTREE AND LOGBOOK"))
  8178. ((> more 4)
  8179. (outline-show-subtree)
  8180. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8181. (select-window win)))
  8182. (defvar org-agenda-cycle-counter nil)
  8183. (defun org-agenda-cycle-show (&optional n)
  8184. "Show the current entry in another window, with default settings.
  8185. Default settings are taken from `org-show-context-detail'. When
  8186. use repeatedly in immediate succession, the remote entry will
  8187. cycle through visibility
  8188. children -> subtree -> folded
  8189. When called with a numeric prefix arg, that arg will be passed through to
  8190. `org-agenda-show-1'. For the interpretation of that argument, see the
  8191. docstring of `org-agenda-show-1'."
  8192. (interactive "P")
  8193. (if (integerp n)
  8194. (setq org-agenda-cycle-counter n)
  8195. (if (not (eq last-command this-command))
  8196. (setq org-agenda-cycle-counter 1)
  8197. (if (equal org-agenda-cycle-counter 0)
  8198. (setq org-agenda-cycle-counter 2)
  8199. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8200. (when (> org-agenda-cycle-counter 3)
  8201. (setq org-agenda-cycle-counter 0)))))
  8202. (org-agenda-show-1 org-agenda-cycle-counter))
  8203. (defun org-agenda-recenter (arg)
  8204. "Display the Org file which contains the item at point and recenter."
  8205. (interactive "P")
  8206. (let ((win (selected-window)))
  8207. (org-agenda-goto t)
  8208. (recenter arg)
  8209. (select-window win)))
  8210. (defun org-agenda-show-mouse (ev)
  8211. "Display the Org file which contains the item at the mouse click."
  8212. (interactive "e")
  8213. (mouse-set-point ev)
  8214. (org-agenda-show))
  8215. (defun org-agenda-check-no-diary ()
  8216. "Check if the entry is a diary link and abort if yes."
  8217. (when (org-get-at-bol 'org-agenda-diary-link)
  8218. (org-agenda-error)))
  8219. (defun org-agenda-error ()
  8220. "Throw an error when a command is not allowed in the agenda."
  8221. (user-error "Command not allowed in this line"))
  8222. (defun org-agenda-tree-to-indirect-buffer (arg)
  8223. "Show the subtree corresponding to the current entry in an indirect buffer.
  8224. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8225. With a numerical prefix ARG, go up to this level and then take that tree.
  8226. With a negative numeric ARG, go up by this number of levels.
  8227. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8228. i.e. don't use
  8229. the dedicated frame."
  8230. (interactive "P")
  8231. (if current-prefix-arg
  8232. (org-agenda-do-tree-to-indirect-buffer arg)
  8233. (let ((agenda-buffer (buffer-name))
  8234. (agenda-window (selected-window))
  8235. (indirect-window
  8236. (and org-last-indirect-buffer
  8237. (get-buffer-window org-last-indirect-buffer))))
  8238. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8239. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8240. (eq org-indirect-buffer-display 'dedicated-frame))
  8241. (unwind-protect
  8242. (unless (and indirect-window (window-live-p indirect-window))
  8243. (setq indirect-window (split-window agenda-window)))
  8244. (and indirect-window (select-window indirect-window))
  8245. (switch-to-buffer org-last-indirect-buffer :norecord)
  8246. (fit-window-to-buffer indirect-window)))
  8247. (select-window (get-buffer-window agenda-buffer))
  8248. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8249. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8250. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8251. (org-agenda-check-no-diary)
  8252. (let* ((marker (or (org-get-at-bol 'org-marker)
  8253. (org-agenda-error)))
  8254. (buffer (marker-buffer marker))
  8255. (pos (marker-position marker)))
  8256. (with-current-buffer buffer
  8257. (save-excursion
  8258. (goto-char pos)
  8259. (org-tree-to-indirect-buffer arg)))))
  8260. (defvar org-last-heading-marker (make-marker)
  8261. "Marker pointing to the headline that last changed its TODO state
  8262. by a remote command from the agenda.")
  8263. (defun org-agenda-todo-nextset ()
  8264. "Switch TODO entry to next sequence."
  8265. (interactive)
  8266. (org-agenda-todo 'nextset))
  8267. (defun org-agenda-todo-previousset ()
  8268. "Switch TODO entry to previous sequence."
  8269. (interactive)
  8270. (org-agenda-todo 'previousset))
  8271. (defun org-agenda-todo (&optional arg)
  8272. "Cycle TODO state of line at point, also in Org file.
  8273. This changes the line at point, all other lines in the agenda referring to
  8274. the same tree node, and the headline of the tree node in the Org file."
  8275. (interactive "P")
  8276. (org-agenda-check-no-diary)
  8277. (let* ((col (current-column))
  8278. (marker (or (org-get-at-bol 'org-marker)
  8279. (org-agenda-error)))
  8280. (buffer (marker-buffer marker))
  8281. (pos (marker-position marker))
  8282. (hdmarker (org-get-at-bol 'org-hd-marker))
  8283. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8284. (inhibit-read-only t)
  8285. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8286. (org-with-remote-undo buffer
  8287. (with-current-buffer buffer
  8288. (widen)
  8289. (goto-char pos)
  8290. (org-show-context 'agenda)
  8291. (let ((current-prefix-arg arg))
  8292. (call-interactively 'org-todo))
  8293. (and (bolp) (forward-char 1))
  8294. (setq newhead (org-get-heading))
  8295. (when (and (bound-and-true-p
  8296. org-agenda-headline-snapshot-before-repeat)
  8297. (not (equal org-agenda-headline-snapshot-before-repeat
  8298. newhead))
  8299. todayp)
  8300. (setq newhead org-agenda-headline-snapshot-before-repeat
  8301. just-one t))
  8302. (save-excursion
  8303. (org-back-to-heading)
  8304. (move-marker org-last-heading-marker (point))))
  8305. (beginning-of-line 1)
  8306. (save-window-excursion
  8307. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8308. (when (bound-and-true-p org-clock-out-when-done)
  8309. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8310. newhead)
  8311. (org-agenda-unmark-clocking-task))
  8312. (org-move-to-column col)
  8313. (org-agenda-mark-clocking-task))))
  8314. (defun org-agenda-add-note (&optional arg)
  8315. "Add a time-stamped note to the entry at point."
  8316. (interactive "P")
  8317. (org-agenda-check-no-diary)
  8318. (let* ((marker (or (org-get-at-bol 'org-marker)
  8319. (org-agenda-error)))
  8320. (buffer (marker-buffer marker))
  8321. (pos (marker-position marker))
  8322. (hdmarker (org-get-at-bol 'org-hd-marker))
  8323. (inhibit-read-only t))
  8324. (with-current-buffer buffer
  8325. (widen)
  8326. (goto-char pos)
  8327. (org-show-context 'agenda)
  8328. (org-add-note))))
  8329. (defun org-agenda-change-all-lines (newhead hdmarker
  8330. &optional fixface just-this)
  8331. "Change all lines in the agenda buffer which match HDMARKER.
  8332. The new content of the line will be NEWHEAD (as modified by
  8333. `org-agenda-format-item'). HDMARKER is checked with
  8334. `equal' against all `org-hd-marker' text properties in the file.
  8335. If FIXFACE is non-nil, the face of each item is modified according to
  8336. the new TODO state.
  8337. If JUST-THIS is non-nil, change just the current line, not all.
  8338. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8339. (let* ((inhibit-read-only t)
  8340. (line (org-current-line))
  8341. (org-agenda-buffer (current-buffer))
  8342. (thetags (with-current-buffer (marker-buffer hdmarker)
  8343. (org-get-tags hdmarker)))
  8344. props m pl undone-face done-face finish new dotime level cat tags)
  8345. (save-excursion
  8346. (goto-char (point-max))
  8347. (beginning-of-line 1)
  8348. (while (not finish)
  8349. (setq finish (bobp))
  8350. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8351. (or (not just-this) (= (org-current-line) line))
  8352. (equal m hdmarker))
  8353. (setq props (text-properties-at (point))
  8354. dotime (org-get-at-bol 'dotime)
  8355. cat (org-agenda-get-category)
  8356. level (org-get-at-bol 'level)
  8357. tags thetags
  8358. new
  8359. (let ((org-prefix-format-compiled
  8360. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8361. org-prefix-format-compiled))
  8362. (extra (org-get-at-bol 'extra)))
  8363. (with-current-buffer (marker-buffer hdmarker)
  8364. (org-with-wide-buffer
  8365. (org-agenda-format-item extra newhead level cat tags dotime))))
  8366. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8367. undone-face (org-get-at-bol 'undone-face)
  8368. done-face (org-get-at-bol 'done-face))
  8369. (beginning-of-line 1)
  8370. (cond
  8371. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8372. ((looking-at ".*")
  8373. ;; When replacing the whole line, preserve bulk mark
  8374. ;; overlay, if any.
  8375. (let ((mark (catch :overlay
  8376. (dolist (o (overlays-in (point) (+ 2 (point))))
  8377. (when (eq (overlay-get o 'type)
  8378. 'org-marked-entry-overlay)
  8379. (throw :overlay o))))))
  8380. (replace-match new t t)
  8381. (beginning-of-line)
  8382. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8383. (add-text-properties (point-at-bol) (point-at-eol) props)
  8384. (when fixface
  8385. (add-text-properties
  8386. (point-at-bol) (point-at-eol)
  8387. (list 'face
  8388. (if org-last-todo-state-is-todo
  8389. undone-face done-face))))
  8390. (org-agenda-highlight-todo 'line)
  8391. (beginning-of-line 1))
  8392. (t (error "Line update did not work")))
  8393. (save-restriction
  8394. (narrow-to-region (point-at-bol) (point-at-eol))
  8395. (org-agenda-finalize)))
  8396. (beginning-of-line 0)))))
  8397. (defun org-agenda-align-tags (&optional line)
  8398. "Align all tags in agenda items to `org-agenda-tags-column'.
  8399. When optional argument LINE is non-nil, align tags only on the
  8400. current line."
  8401. (let ((inhibit-read-only t)
  8402. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8403. (- (window-text-width))
  8404. org-agenda-tags-column))
  8405. (end (and line (line-end-position)))
  8406. l c)
  8407. (save-excursion
  8408. (goto-char (if line (line-beginning-position) (point-min)))
  8409. (while (re-search-forward org-tag-group-re end t)
  8410. (add-text-properties
  8411. (match-beginning 1) (match-end 1)
  8412. (list 'face (delq nil (let ((prop (get-text-property
  8413. (match-beginning 1) 'face)))
  8414. (or (listp prop) (setq prop (list prop)))
  8415. (if (memq 'org-tag prop)
  8416. prop
  8417. (cons 'org-tag prop))))))
  8418. (setq l (string-width (match-string 1))
  8419. c (if (< org-agenda-tags-column 0)
  8420. (- (abs org-agenda-tags-column) l)
  8421. org-agenda-tags-column))
  8422. (goto-char (match-beginning 1))
  8423. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  8424. (point))
  8425. (insert (org-add-props
  8426. (make-string (max 1 (- c (current-column))) ?\s)
  8427. (plist-put (copy-sequence (text-properties-at (point)))
  8428. 'face nil))))
  8429. (goto-char (point-min))
  8430. (org-font-lock-add-tag-faces (point-max)))))
  8431. (defun org-agenda-priority-up ()
  8432. "Increase the priority of line at point, also in Org file."
  8433. (interactive)
  8434. (org-agenda-priority 'up))
  8435. (defun org-agenda-priority-down ()
  8436. "Decrease the priority of line at point, also in Org file."
  8437. (interactive)
  8438. (org-agenda-priority 'down))
  8439. (defun org-agenda-priority (&optional force-direction)
  8440. "Set the priority of line at point, also in Org file.
  8441. This changes the line at point, all other lines in the agenda referring to
  8442. the same tree node, and the headline of the tree node in the Org file.
  8443. Called with a universal prefix arg, show the priority instead of setting it."
  8444. (interactive "P")
  8445. (if (equal force-direction '(4))
  8446. (org-show-priority)
  8447. (unless org-enable-priority-commands
  8448. (error "Priority commands are disabled"))
  8449. (org-agenda-check-no-diary)
  8450. (let* ((col (current-column))
  8451. (marker (or (org-get-at-bol 'org-marker)
  8452. (org-agenda-error)))
  8453. (hdmarker (org-get-at-bol 'org-hd-marker))
  8454. (buffer (marker-buffer hdmarker))
  8455. (pos (marker-position hdmarker))
  8456. (inhibit-read-only t)
  8457. newhead)
  8458. (org-with-remote-undo buffer
  8459. (with-current-buffer buffer
  8460. (widen)
  8461. (goto-char pos)
  8462. (org-show-context 'agenda)
  8463. (org-priority force-direction)
  8464. (end-of-line 1)
  8465. (setq newhead (org-get-heading)))
  8466. (org-agenda-change-all-lines newhead hdmarker)
  8467. (org-move-to-column col)))))
  8468. ;; FIXME: should fix the tags property of the agenda line.
  8469. (defun org-agenda-set-tags (&optional tag onoff)
  8470. "Set tags for the current headline."
  8471. (interactive)
  8472. (org-agenda-check-no-diary)
  8473. (if (and (org-region-active-p) (called-interactively-p 'any))
  8474. (call-interactively 'org-change-tag-in-region)
  8475. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8476. (org-agenda-error)))
  8477. (buffer (marker-buffer hdmarker))
  8478. (pos (marker-position hdmarker))
  8479. (inhibit-read-only t)
  8480. newhead)
  8481. (org-with-remote-undo buffer
  8482. (with-current-buffer buffer
  8483. (widen)
  8484. (goto-char pos)
  8485. (org-show-context 'agenda)
  8486. (if tag
  8487. (org-toggle-tag tag onoff)
  8488. (call-interactively #'org-set-tags-command))
  8489. (end-of-line 1)
  8490. (setq newhead (org-get-heading)))
  8491. (org-agenda-change-all-lines newhead hdmarker)
  8492. (beginning-of-line 1)))))
  8493. (defun org-agenda-set-property ()
  8494. "Set a property for the current headline."
  8495. (interactive)
  8496. (org-agenda-check-no-diary)
  8497. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8498. (org-agenda-error)))
  8499. (buffer (marker-buffer hdmarker))
  8500. (pos (marker-position hdmarker))
  8501. (inhibit-read-only t)
  8502. newhead)
  8503. (org-with-remote-undo buffer
  8504. (with-current-buffer buffer
  8505. (widen)
  8506. (goto-char pos)
  8507. (org-show-context 'agenda)
  8508. (call-interactively 'org-set-property)))))
  8509. (defun org-agenda-set-effort ()
  8510. "Set the effort property for the current headline."
  8511. (interactive)
  8512. (org-agenda-check-no-diary)
  8513. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8514. (org-agenda-error)))
  8515. (buffer (marker-buffer hdmarker))
  8516. (pos (marker-position hdmarker))
  8517. (inhibit-read-only t)
  8518. newhead)
  8519. (org-with-remote-undo buffer
  8520. (with-current-buffer buffer
  8521. (widen)
  8522. (goto-char pos)
  8523. (org-show-context 'agenda)
  8524. (call-interactively 'org-set-effort)
  8525. (end-of-line 1)
  8526. (setq newhead (org-get-heading)))
  8527. (org-agenda-change-all-lines newhead hdmarker))))
  8528. (defun org-agenda-toggle-archive-tag ()
  8529. "Toggle the archive tag for the current entry."
  8530. (interactive)
  8531. (org-agenda-check-no-diary)
  8532. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8533. (org-agenda-error)))
  8534. (buffer (marker-buffer hdmarker))
  8535. (pos (marker-position hdmarker))
  8536. (inhibit-read-only t)
  8537. newhead)
  8538. (org-with-remote-undo buffer
  8539. (with-current-buffer buffer
  8540. (widen)
  8541. (goto-char pos)
  8542. (org-show-context 'agenda)
  8543. (call-interactively 'org-toggle-archive-tag)
  8544. (end-of-line 1)
  8545. (setq newhead (org-get-heading)))
  8546. (org-agenda-change-all-lines newhead hdmarker)
  8547. (beginning-of-line 1))))
  8548. (defun org-agenda-do-date-later (arg)
  8549. (interactive "P")
  8550. (cond
  8551. ((or (equal arg '(16))
  8552. (memq last-command
  8553. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8554. (setq this-command 'org-agenda-date-later-minutes)
  8555. (org-agenda-date-later-minutes 1))
  8556. ((or (equal arg '(4))
  8557. (memq last-command
  8558. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8559. (setq this-command 'org-agenda-date-later-hours)
  8560. (org-agenda-date-later-hours 1))
  8561. (t
  8562. (org-agenda-date-later (prefix-numeric-value arg)))))
  8563. (defun org-agenda-do-date-earlier (arg)
  8564. (interactive "P")
  8565. (cond
  8566. ((or (equal arg '(16))
  8567. (memq last-command
  8568. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8569. (setq this-command 'org-agenda-date-earlier-minutes)
  8570. (org-agenda-date-earlier-minutes 1))
  8571. ((or (equal arg '(4))
  8572. (memq last-command
  8573. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8574. (setq this-command 'org-agenda-date-earlier-hours)
  8575. (org-agenda-date-earlier-hours 1))
  8576. (t
  8577. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8578. (defun org-agenda-date-later (arg &optional what)
  8579. "Change the date of this item to ARG day(s) later."
  8580. (interactive "p")
  8581. (org-agenda-check-type t 'agenda)
  8582. (org-agenda-check-no-diary)
  8583. (let* ((marker (or (org-get-at-bol 'org-marker)
  8584. (org-agenda-error)))
  8585. (buffer (marker-buffer marker))
  8586. (pos (marker-position marker))
  8587. cdate today)
  8588. (org-with-remote-undo buffer
  8589. (with-current-buffer buffer
  8590. (widen)
  8591. (goto-char pos)
  8592. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8593. (when (and org-agenda-move-date-from-past-immediately-to-today
  8594. (equal arg 1)
  8595. (or (not what) (eq what 'day))
  8596. (not (save-match-data (org-at-date-range-p))))
  8597. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8598. cdate (calendar-absolute-from-gregorian
  8599. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8600. today (org-today))
  8601. (when (> today cdate)
  8602. ;; immediately shift to today
  8603. (setq arg (- today cdate))))
  8604. (org-timestamp-change arg (or what 'day))
  8605. (when (and (org-at-date-range-p)
  8606. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8607. (let ((end org-last-changed-timestamp))
  8608. (org-timestamp-change arg (or what 'day))
  8609. (setq org-last-changed-timestamp
  8610. (concat org-last-changed-timestamp "--" end)))))
  8611. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8612. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8613. (defun org-agenda-date-earlier (arg &optional what)
  8614. "Change the date of this item to ARG day(s) earlier."
  8615. (interactive "p")
  8616. (org-agenda-date-later (- arg) what))
  8617. (defun org-agenda-date-later-minutes (arg)
  8618. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8619. (interactive "p")
  8620. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8621. (org-agenda-date-later arg 'minute))
  8622. (defun org-agenda-date-earlier-minutes (arg)