org-agenda.el 406 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2020 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
  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 "Columns format"
  344. (const org-overriding-columns-format)
  345. (string :tag "Format"))
  346. (list :tag "Standard skipping condition"
  347. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  348. (const org-agenda-skip-function)
  349. (list
  350. (const :format "" quote)
  351. (list
  352. (choice
  353. :tag "Skipping range"
  354. (const :tag "Skip entry" org-agenda-skip-entry-if)
  355. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  356. (repeat :inline t :tag "Conditions for skipping"
  357. (choice
  358. :tag "Condition type"
  359. (list :tag "Regexp matches" :inline t
  360. (const :format "" regexp)
  361. (regexp))
  362. (list :tag "Regexp does not match" :inline t
  363. (const :format "" notregexp)
  364. (regexp))
  365. (list :tag "TODO state is" :inline t
  366. (const todo)
  367. (choice
  368. (const :tag "Any not-done state" todo)
  369. (const :tag "Any done state" done)
  370. (const :tag "Any state" any)
  371. (list :tag "Keyword list"
  372. (const :format "" quote)
  373. (repeat (string :tag "Keyword")))))
  374. (list :tag "TODO state is not" :inline t
  375. (const nottodo)
  376. (choice
  377. (const :tag "Any not-done state" todo)
  378. (const :tag "Any done state" done)
  379. (const :tag "Any state" any)
  380. (list :tag "Keyword list"
  381. (const :format "" quote)
  382. (repeat (string :tag "Keyword")))))
  383. (const :tag "scheduled" scheduled)
  384. (const :tag "not scheduled" notscheduled)
  385. (const :tag "deadline" deadline)
  386. (const :tag "no deadline" notdeadline)
  387. (const :tag "timestamp" timestamp)
  388. (const :tag "no timestamp" nottimestamp))))))
  389. (list :tag "Non-standard skipping condition"
  390. :value (org-agenda-skip-function)
  391. (const org-agenda-skip-function)
  392. (sexp :tag "Function or form (quoted!)"))
  393. (list :tag "Any variable"
  394. (variable :tag "Variable")
  395. (sexp :tag "Value (sexp)"))))
  396. "Selection of examples for agenda command settings.
  397. This will be spliced into the custom type of
  398. `org-agenda-custom-commands'.")
  399. (defcustom org-agenda-custom-commands
  400. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  401. "Custom commands for the agenda.
  402. \\<org-mode-map>
  403. These commands will be offered on the splash screen displayed by the
  404. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  405. (key desc type match settings files)
  406. key The key (one or more characters as a string) to be associated
  407. with the command.
  408. desc A description of the command, when omitted or nil, a default
  409. description is built using MATCH.
  410. type The command type, any of the following symbols:
  411. agenda The daily/weekly agenda.
  412. todo Entries with a specific TODO keyword, in all agenda files.
  413. search Entries containing search words entry or headline.
  414. tags Tags/Property/TODO match in all agenda files.
  415. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  416. todo-tree Sparse tree of specific TODO keyword in *current* file.
  417. tags-tree Sparse tree with all tags matches in *current* file.
  418. occur-tree Occur sparse tree for *current* file.
  419. ... A user-defined function.
  420. match What to search for:
  421. - a single keyword for TODO keyword searches
  422. - a tags/property/todo match expression for searches
  423. - a word search expression for text searches.
  424. - a regular expression for occur searches
  425. For all other commands, this should be the empty string.
  426. settings A list of option settings, similar to that in a let form, so like
  427. this: ((opt1 val1) (opt2 val2) ...). The values will be
  428. evaluated at the moment of execution, so quote them when needed.
  429. files A list of files to write the produced agenda buffer to with
  430. the command `org-store-agenda-views'.
  431. If a file name ends in \".html\", an HTML version of the buffer
  432. is written out. If it ends in \".ps\", a postscript version is
  433. produced. Otherwise, only the plain text is written to the file.
  434. You can also define a set of commands, to create a composite agenda buffer.
  435. In this case, an entry looks like this:
  436. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  437. where
  438. desc A description string to be displayed in the dispatcher menu.
  439. cmd An agenda command, similar to the above. However, tree commands
  440. are not allowed, but instead you can get agenda and global todo list.
  441. So valid commands for a set are:
  442. (agenda \"\" settings)
  443. (alltodo \"\" settings)
  444. (stuck \"\" settings)
  445. (todo \"match\" settings files)
  446. (search \"match\" settings files)
  447. (tags \"match\" settings files)
  448. (tags-todo \"match\" settings files)
  449. Each command can carry a list of options, and another set of options can be
  450. given for the whole set of commands. Individual command options take
  451. precedence over the general options.
  452. When using several characters as key to a command, the first characters
  453. are prefix commands. For the dispatcher to display useful information, you
  454. should provide a description for the prefix, like
  455. (setq org-agenda-custom-commands
  456. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  457. (\"hl\" tags \"+HOME+Lisa\")
  458. (\"hp\" tags \"+HOME+Peter\")
  459. (\"hk\" tags \"+HOME+Kim\")))"
  460. :group 'org-agenda-custom-commands
  461. :type `(repeat
  462. (choice :value ("x" "Describe command here" tags "" nil)
  463. (list :tag "Single command"
  464. (string :tag "Access Key(s) ")
  465. (option (string :tag "Description"))
  466. (choice
  467. (const :tag "Agenda" agenda)
  468. (const :tag "TODO list" alltodo)
  469. (const :tag "Search words" search)
  470. (const :tag "Stuck projects" stuck)
  471. (const :tag "Tags/Property match (all agenda files)" tags)
  472. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  473. (const :tag "TODO keyword search (all agenda files)" todo)
  474. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  475. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  476. (const :tag "Occur tree (current buffer)" occur-tree)
  477. (sexp :tag "Other, user-defined function"))
  478. (string :tag "Match (only for some commands)")
  479. ,org-agenda-custom-commands-local-options
  480. (option (repeat :tag "Export" (file :tag "Export to"))))
  481. (list :tag "Command series, all agenda files"
  482. (string :tag "Access Key(s)")
  483. (string :tag "Description ")
  484. (repeat :tag "Component"
  485. (choice
  486. (list :tag "Agenda"
  487. (const :format "" agenda)
  488. (const :tag "" :format "" "")
  489. ,org-agenda-custom-commands-local-options)
  490. (list :tag "TODO list (all keywords)"
  491. (const :format "" alltodo)
  492. (const :tag "" :format "" "")
  493. ,org-agenda-custom-commands-local-options)
  494. (list :tag "Search words"
  495. (const :format "" search)
  496. (string :tag "Match")
  497. ,org-agenda-custom-commands-local-options)
  498. (list :tag "Stuck projects"
  499. (const :format "" stuck)
  500. (const :tag "" :format "" "")
  501. ,org-agenda-custom-commands-local-options)
  502. (list :tag "Tags/Property match (all agenda files)"
  503. (const :format "" tags)
  504. (string :tag "Match")
  505. ,org-agenda-custom-commands-local-options)
  506. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  507. (const :format "" tags-todo)
  508. (string :tag "Match")
  509. ,org-agenda-custom-commands-local-options)
  510. (list :tag "TODO keyword search"
  511. (const :format "" todo)
  512. (string :tag "Match")
  513. ,org-agenda-custom-commands-local-options)
  514. (list :tag "Other, user-defined function"
  515. (symbol :tag "function")
  516. (string :tag "Match")
  517. ,org-agenda-custom-commands-local-options)))
  518. (repeat :tag "Settings for entire command set"
  519. (list (variable :tag "Any variable")
  520. (sexp :tag "Value")))
  521. (option (repeat :tag "Export" (file :tag "Export to"))))
  522. (cons :tag "Prefix key documentation"
  523. (string :tag "Access Key(s)")
  524. (string :tag "Description ")))))
  525. (defcustom org-agenda-query-register ?o
  526. "The register holding the current query string.
  527. The purpose of this is that if you construct a query string interactively,
  528. you can then use it to define a custom command."
  529. :group 'org-agenda-custom-commands
  530. :type 'character)
  531. (defcustom org-stuck-projects
  532. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  533. "How to identify stuck projects.
  534. This is a list of four items:
  535. 1. A tags/todo/property matcher string that is used to identify a project.
  536. See the manual for a description of tag and property searches.
  537. The entire tree below a headline matched by this is considered one project.
  538. 2. A list of TODO keywords identifying non-stuck projects.
  539. If the project subtree contains any headline with one of these todo
  540. keywords, the project is considered to be not stuck. If you specify
  541. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  542. 3. A list of tags identifying non-stuck projects.
  543. If the project subtree contains any headline with one of these tags,
  544. the project is considered to be not stuck. If you specify \"*\" as
  545. a tag, any tag will mark the project unstuck. Note that this is about
  546. the explicit presence of a tag somewhere in the subtree, inherited
  547. tags do not count here. If inherited tags make a project not stuck,
  548. use \"-TAG\" in the tags part of the matcher under (1.) above.
  549. 4. An arbitrary regular expression matching non-stuck projects.
  550. If the project turns out to be not stuck, search continues also in the
  551. subtree to see if any of the subtasks have project status.
  552. See also the variable `org-tags-match-list-sublevels' which applies
  553. to projects matched by this search as well.
  554. After defining this variable, you may use `org-agenda-list-stuck-projects'
  555. \(bound to `\\[org-agenda] #') to produce the list."
  556. :group 'org-agenda-custom-commands
  557. :type '(list
  558. (string :tag "Tags/TODO match to identify a project")
  559. (repeat :tag "Projects are *not* stuck if they have an entry with \
  560. TODO keyword any of" (string))
  561. (repeat :tag "Projects are *not* stuck if they have an entry with \
  562. TAG being any of" (string))
  563. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  564. the subtree")))
  565. (defgroup org-agenda-skip nil
  566. "Options concerning skipping parts of agenda files."
  567. :tag "Org Agenda Skip"
  568. :group 'org-agenda)
  569. (defcustom org-agenda-skip-function-global nil
  570. "Function to be called at each match during agenda construction.
  571. If this function returns nil, the current match should not be skipped.
  572. If the function decided to skip an agenda match, is must return the
  573. buffer position from which the search should be continued.
  574. This may also be a Lisp form, which will be evaluated.
  575. This variable will be applied to every agenda match, including
  576. tags/property searches and TODO lists. So try to make the test function
  577. do its checking as efficiently as possible. To implement a skipping
  578. condition just for specific agenda commands, use the variable
  579. `org-agenda-skip-function' which can be set in the options section
  580. of custom agenda commands."
  581. :group 'org-agenda-skip
  582. :type 'sexp)
  583. (defgroup org-agenda-daily/weekly nil
  584. "Options concerning the daily/weekly agenda."
  585. :tag "Org Agenda Daily/Weekly"
  586. :group 'org-agenda)
  587. (defgroup org-agenda-todo-list nil
  588. "Options concerning the global todo list agenda view."
  589. :tag "Org Agenda Todo List"
  590. :group 'org-agenda)
  591. (defgroup org-agenda-match-view nil
  592. "Options concerning the general tags/property/todo match agenda view."
  593. :tag "Org Agenda Match View"
  594. :group 'org-agenda)
  595. (defgroup org-agenda-search-view nil
  596. "Options concerning the search agenda view."
  597. :tag "Org Agenda Search View"
  598. :group 'org-agenda)
  599. (defvar org-agenda-archives-mode nil
  600. "Non-nil means the agenda will include archived items.
  601. If this is the symbol `trees', trees in the selected agenda scope
  602. that are marked with the ARCHIVE tag will be included anyway. When this is
  603. t, also all archive files associated with the current selection of agenda
  604. files will be included.")
  605. (defcustom org-agenda-restriction-lock-highlight-subtree t
  606. "Non-nil means highlight the whole subtree when restriction is active.
  607. Otherwise only highlight the headline. Highlighting the whole subtree is
  608. useful to ensure no edits happen beyond the restricted region."
  609. :group 'org-agenda
  610. :type 'boolean)
  611. (defcustom org-agenda-skip-comment-trees t
  612. "Non-nil means skip trees that start with the COMMENT keyword.
  613. When nil, these trees are also scanned by agenda commands."
  614. :group 'org-agenda-skip
  615. :type 'boolean)
  616. (defcustom org-agenda-todo-list-sublevels t
  617. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  618. When nil, the sublevels of a TODO entry are not checked, resulting in
  619. potentially much shorter TODO lists."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type 'boolean)
  623. (defcustom org-agenda-todo-ignore-with-date nil
  624. "Non-nil means don't show entries with a date in the global todo list.
  625. You can use this if you prefer to mark mere appointments with a TODO keyword,
  626. but don't want them to show up in the TODO list.
  627. When this is set, it also covers deadlines and scheduled items, the settings
  628. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  629. will be ignored.
  630. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  631. :group 'org-agenda-skip
  632. :group 'org-agenda-todo-list
  633. :type 'boolean)
  634. (defcustom org-agenda-todo-ignore-timestamp nil
  635. "Non-nil means don't show entries with a timestamp.
  636. This applies when creating the global todo list.
  637. Valid values are:
  638. past Don't show entries for today or in the past.
  639. future Don't show entries with a timestamp in the future.
  640. The idea behind this is that if it has a future
  641. timestamp, you don't want to think about it until the
  642. date.
  643. all Don't show any entries with a timestamp in the global todo list.
  644. The idea behind this is that by setting a timestamp, you
  645. have already \"taken care\" of this item.
  646. This variable can also have an integer as a value. If positive (N),
  647. todos with a timestamp N or more days in the future will be ignored. If
  648. negative (-N), todos with a timestamp N or more days in the past will be
  649. ignored. If 0, todos with a timestamp either today or in the future will
  650. be ignored. For example, a value of -1 will exclude todos with a
  651. timestamp in the past (yesterday or earlier), while a value of 7 will
  652. exclude todos with a timestamp a week or more in the future.
  653. See also `org-agenda-todo-ignore-with-date'.
  654. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  655. to make his option also apply to the tags-todo list."
  656. :group 'org-agenda-skip
  657. :group 'org-agenda-todo-list
  658. :version "24.1"
  659. :type '(choice
  660. (const :tag "Ignore future timestamp todos" future)
  661. (const :tag "Ignore past or present timestamp todos" past)
  662. (const :tag "Ignore all timestamp todos" all)
  663. (const :tag "Show timestamp todos" nil)
  664. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  665. (defcustom org-agenda-todo-ignore-scheduled nil
  666. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  667. This applies when creating the global todo list.
  668. Valid values are:
  669. past Don't show entries scheduled today or in the past.
  670. future Don't show entries scheduled in the future.
  671. The idea behind this is that by scheduling it, you don't want to
  672. think about it until the scheduled date.
  673. all Don't show any scheduled entries in the global todo list.
  674. The idea behind this is that by scheduling it, you have already
  675. \"taken care\" of this item.
  676. t Same as `all', for backward compatibility.
  677. This variable can also have an integer as a value. See
  678. `org-agenda-todo-ignore-timestamp' for more details.
  679. See also `org-agenda-todo-ignore-with-date'.
  680. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  681. to make his option also apply to the tags-todo list."
  682. :group 'org-agenda-skip
  683. :group 'org-agenda-todo-list
  684. :type '(choice
  685. (const :tag "Ignore future-scheduled todos" future)
  686. (const :tag "Ignore past- or present-scheduled todos" past)
  687. (const :tag "Ignore all scheduled todos" all)
  688. (const :tag "Ignore all scheduled todos (compatibility)" t)
  689. (const :tag "Show scheduled todos" nil)
  690. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  691. (defcustom org-agenda-todo-ignore-deadlines nil
  692. "Non-nil means ignore some deadline TODO items when making TODO list.
  693. There are different motivations for using different values, please think
  694. carefully when configuring this variable.
  695. This applies when creating the global TODO list.
  696. Valid values are:
  697. near Don't show near deadline entries. A deadline is near when it is
  698. closer than `org-deadline-warning-days' days. The idea behind this
  699. is that such items will appear in the agenda anyway.
  700. far Don't show TODO entries where a deadline has been defined, but
  701. is not going to happen anytime soon. This is useful if you want to use
  702. the TODO list to figure out what to do now.
  703. past Don't show entries with a deadline timestamp for today or in the past.
  704. future Don't show entries with a deadline timestamp in the future, not even
  705. when they become `near' ones. Use it with caution.
  706. all Ignore all TODO entries that do have a deadline.
  707. t Same as `near', for backward compatibility.
  708. This variable can also have an integer as a value. See
  709. `org-agenda-todo-ignore-timestamp' for more details.
  710. See also `org-agenda-todo-ignore-with-date'.
  711. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  712. to make his option also apply to the tags-todo list."
  713. :group 'org-agenda-skip
  714. :group 'org-agenda-todo-list
  715. :type '(choice
  716. (const :tag "Ignore near deadlines" near)
  717. (const :tag "Ignore near deadlines (compatibility)" t)
  718. (const :tag "Ignore far deadlines" far)
  719. (const :tag "Ignore all TODOs with a deadlines" all)
  720. (const :tag "Show all TODOs, even if they have a deadline" nil)
  721. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  722. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  723. "Time unit to use when possibly ignoring an agenda item.
  724. See the docstring of various `org-agenda-todo-ignore-*' options.
  725. The default is to compare time stamps using days. An item is thus
  726. considered to be in the future if it is at least one day after today.
  727. Non-nil means to compare time stamps using seconds. An item is then
  728. considered future if it has a time value later than current time."
  729. :group 'org-agenda-skip
  730. :group 'org-agenda-todo-list
  731. :version "24.4"
  732. :package-version '(Org . "8.0")
  733. :type '(choice
  734. (const :tag "Compare time with days" nil)
  735. (const :tag "Compare time with seconds" t)))
  736. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  737. "Non-nil means honor todo-list ignores options also in tags-todo search.
  738. The variables
  739. `org-agenda-todo-ignore-with-date',
  740. `org-agenda-todo-ignore-timestamp',
  741. `org-agenda-todo-ignore-scheduled',
  742. `org-agenda-todo-ignore-deadlines'
  743. make the global TODO list skip entries that have time stamps of certain
  744. kinds. If this option is set, the same options will also apply for the
  745. tags-todo search, which is the general tags/property matcher
  746. restricted to unfinished TODO entries only."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-todo-list
  749. :group 'org-agenda-match-view
  750. :type 'boolean)
  751. (defcustom org-agenda-skip-scheduled-if-done nil
  752. "Non-nil means don't show scheduled items in agenda when they are done.
  753. This is relevant for the daily/weekly agenda, not for the TODO list. It
  754. applies only to the actual date of the scheduling. Warnings about an item
  755. with a past scheduling dates are always turned off when the item is DONE."
  756. :group 'org-agenda-skip
  757. :group 'org-agenda-daily/weekly
  758. :type 'boolean)
  759. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  760. "Non-nil means skip scheduling line if same entry shows because of deadline.
  761. In the agenda of today, an entry can show up multiple times
  762. because it is both scheduled and has a nearby deadline, and maybe
  763. a plain time stamp as well.
  764. When this variable is nil, the entry will be shown several times.
  765. When set to t, then only the deadline is shown and the fact that
  766. the entry is scheduled today or was scheduled previously is not
  767. shown.
  768. When set to the symbol `not-today', skip scheduled previously,
  769. but not scheduled today.
  770. When set to the symbol `repeated-after-deadline', skip scheduled
  771. items if they are repeated beyond the current deadline."
  772. :group 'org-agenda-skip
  773. :group 'org-agenda-daily/weekly
  774. :type '(choice
  775. (const :tag "Never" nil)
  776. (const :tag "Always" t)
  777. (const :tag "Not when scheduled today" not-today)
  778. (const :tag "When repeated past deadline" repeated-after-deadline)))
  779. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  780. "Non-nil means skip timestamp line if same entry shows because of deadline.
  781. In the agenda of today, an entry can show up multiple times
  782. because it has both a plain timestamp and has a nearby deadline.
  783. When this variable is t, then only the deadline is shown and the
  784. fact that the entry has a timestamp for or including today is not
  785. shown. When this variable is nil, the entry will be shown
  786. several times."
  787. :group 'org-agenda-skip
  788. :group 'org-agenda-daily/weekly
  789. :version "24.1"
  790. :type '(choice
  791. (const :tag "Never" nil)
  792. (const :tag "Always" t)))
  793. (defcustom org-agenda-skip-deadline-if-done nil
  794. "Non-nil means don't show deadlines when the corresponding item is done.
  795. When nil, the deadline is still shown and should give you a happy feeling.
  796. This is relevant for the daily/weekly agenda. It applies only to the
  797. actual date of the deadline. Warnings about approaching and past-due
  798. deadlines are always turned off when the item is DONE."
  799. :group 'org-agenda-skip
  800. :group 'org-agenda-daily/weekly
  801. :type 'boolean)
  802. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  803. "Non-nil means skip deadline prewarning when entry is also scheduled.
  804. This will apply on all days where a prewarning for the deadline would
  805. be shown, but not at the day when the entry is actually due. On that day,
  806. the deadline will be shown anyway.
  807. This variable may be set to nil, t, the symbol `pre-scheduled',
  808. or a number which will then give the number of days before the actual
  809. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  810. eliminates the deadline prewarning only prior to the scheduled date.
  811. This can be used in a workflow where the first showing of the deadline will
  812. trigger you to schedule it, and then you don't want to be reminded of it
  813. because you will take care of it on the day when scheduled."
  814. :group 'org-agenda-skip
  815. :group 'org-agenda-daily/weekly
  816. :version "24.1"
  817. :type '(choice
  818. (const :tag "Always show prewarning" nil)
  819. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  820. (const :tag "Remove prewarning if entry is scheduled" t)
  821. (integer :tag "Restart prewarning N days before deadline")))
  822. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  823. "Non-nil means skip scheduled delay when entry also has a deadline.
  824. This variable may be set to nil, t, the symbol `post-deadline',
  825. or a number which will then give the number of days after the actual
  826. scheduled date when the delay should expire. The symbol `post-deadline'
  827. eliminates the schedule delay when the date is posterior to the deadline."
  828. :group 'org-agenda-skip
  829. :group 'org-agenda-daily/weekly
  830. :version "24.4"
  831. :package-version '(Org . "8.0")
  832. :type '(choice
  833. (const :tag "Always honor delay" nil)
  834. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  835. (const :tag "Ignore delay if entry has a deadline" t)
  836. (integer :tag "Honor delay up until N days after the scheduled date")))
  837. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  838. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  839. When non-nil, after the search for timestamps has matched once in an
  840. entry, the rest of the entry will not be searched."
  841. :group 'org-agenda-skip
  842. :type 'boolean)
  843. (defcustom org-agenda-skip-timestamp-if-done nil
  844. "Non-nil means don't select item by timestamp or -range if it is DONE."
  845. :group 'org-agenda-skip
  846. :group 'org-agenda-daily/weekly
  847. :type 'boolean)
  848. (defcustom org-agenda-dim-blocked-tasks t
  849. "Non-nil means dim blocked tasks in the agenda display.
  850. This causes some overhead during agenda construction, but if you
  851. have turned on `org-enforce-todo-dependencies',
  852. `org-enforce-todo-checkbox-dependencies', or any other blocking
  853. mechanism, this will create useful feedback in the agenda.
  854. Instead of t, this variable can also have the value `invisible'.
  855. Then blocked tasks will be invisible and only become visible when
  856. they become unblocked. An exemption to this behavior is when a task is
  857. blocked because of unchecked checkboxes below it. Since checkboxes do
  858. not show up in the agenda views, making this task invisible you remove any
  859. trace from agenda views that there is something to do. Therefore, a task
  860. that is blocked because of checkboxes will never be made invisible, it
  861. will only be dimmed."
  862. :group 'org-agenda-daily/weekly
  863. :group 'org-agenda-todo-list
  864. :version "24.3"
  865. :type '(choice
  866. (const :tag "Do not dim" nil)
  867. (const :tag "Dim to a gray face" t)
  868. (const :tag "Make invisible" invisible)))
  869. (defgroup org-agenda-startup nil
  870. "Options concerning initial settings in the Agenda in Org Mode."
  871. :tag "Org Agenda Startup"
  872. :group 'org-agenda)
  873. (defcustom org-agenda-menu-show-matcher t
  874. "Non-nil means show the match string in the agenda dispatcher menu.
  875. When nil, the matcher string is not shown, but is put into the help-echo
  876. property so than moving the mouse over the command shows it.
  877. Setting it to nil is good if matcher strings are very long and/or if
  878. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  879. :group 'org-agenda
  880. :version "24.1"
  881. :type 'boolean)
  882. (defcustom org-agenda-menu-two-columns nil
  883. "Non-nil means, use two columns to show custom commands in the dispatcher.
  884. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  885. to nil."
  886. :group 'org-agenda
  887. :version "24.1"
  888. :type 'boolean)
  889. (defcustom org-agenda-finalize-hook nil
  890. "Hook run just before displaying an agenda buffer.
  891. The buffer is still writable when the hook is called.
  892. You can modify some of the buffer substrings but you should be
  893. extra careful not to modify the text properties of the agenda
  894. headlines as the agenda display heavily relies on them."
  895. :group 'org-agenda-startup
  896. :type 'hook)
  897. (defcustom org-agenda-mouse-1-follows-link nil
  898. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  899. A longer mouse click will still set point. Needs to be set
  900. before org.el is loaded."
  901. :group 'org-agenda-startup
  902. :type 'boolean)
  903. (defcustom org-agenda-start-with-follow-mode nil
  904. "The initial value of follow mode in a newly created agenda window."
  905. :group 'org-agenda-startup
  906. :type 'boolean)
  907. (defcustom org-agenda-follow-indirect nil
  908. "Non-nil means `org-agenda-follow-mode' displays only the
  909. current item's tree, in an indirect buffer."
  910. :group 'org-agenda
  911. :version "24.1"
  912. :type 'boolean)
  913. (defcustom org-agenda-show-outline-path t
  914. "Non-nil means show outline path in echo area after line motion."
  915. :group 'org-agenda-startup
  916. :type 'boolean)
  917. (defcustom org-agenda-start-with-entry-text-mode nil
  918. "The initial value of entry-text-mode in a newly created agenda window."
  919. :group 'org-agenda-startup
  920. :type 'boolean)
  921. (defcustom org-agenda-entry-text-maxlines 5
  922. "Number of text lines to be added when `E' is pressed in the agenda.
  923. Note that this variable only used during agenda display. To add entry text
  924. when exporting the agenda, configure the variable
  925. `org-agenda-add-entry-text-maxlines'."
  926. :group 'org-agenda
  927. :type 'integer)
  928. (defcustom org-agenda-entry-text-exclude-regexps nil
  929. "List of regular expressions to clean up entry text.
  930. The complete matches of all regular expressions in this list will be
  931. removed from entry text before it is shown in the agenda."
  932. :group 'org-agenda
  933. :type '(repeat (regexp)))
  934. (defcustom org-agenda-entry-text-leaders " > "
  935. "Text prepended to the entry text in agenda buffers."
  936. :version "24.4"
  937. :package-version '(Org . "8.0")
  938. :group 'org-agenda
  939. :type 'string)
  940. (defvar org-agenda-entry-text-cleanup-hook nil
  941. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  942. This cleanup is done in a temporary buffer, so the function may inspect and
  943. change the entire buffer.
  944. Some default stuff like drawers and scheduling/deadline dates will already
  945. have been removed when this is called, as will any matches for regular
  946. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  947. (defvar org-agenda-include-inactive-timestamps nil
  948. "Non-nil means include inactive time stamps in agenda.
  949. Dynamically scoped.")
  950. (defgroup org-agenda-windows nil
  951. "Options concerning the windows used by the Agenda in Org Mode."
  952. :tag "Org Agenda Windows"
  953. :group 'org-agenda)
  954. (defcustom org-agenda-window-setup 'reorganize-frame
  955. "How the agenda buffer should be displayed.
  956. Possible values for this option are:
  957. current-window Show agenda in the current window, keeping all other windows.
  958. other-window Use `switch-to-buffer-other-window' to display agenda.
  959. only-window Show agenda, deleting all other windows.
  960. reorganize-frame Show only two windows on the current frame, the current
  961. window and the agenda.
  962. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  963. Also, when exiting the agenda, kill that frame.
  964. See also the variable `org-agenda-restore-windows-after-quit'."
  965. :group 'org-agenda-windows
  966. :type '(choice
  967. (const current-window)
  968. (const other-frame)
  969. (const other-window)
  970. (const only-window)
  971. (const reorganize-frame)))
  972. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  973. "The min and max height of the agenda window as a fraction of frame height.
  974. The value of the variable is a cons cell with two numbers between 0 and 1.
  975. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  976. :group 'org-agenda-windows
  977. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  978. (defcustom org-agenda-restore-windows-after-quit nil
  979. "Non-nil means restore window configuration upon exiting agenda.
  980. Before the window configuration is changed for displaying the agenda,
  981. the current status is recorded. When the agenda is exited with
  982. `q' or `x' and this option is set, the old state is restored. If
  983. `org-agenda-window-setup' is `other-frame', the value of this
  984. option will be ignored."
  985. :group 'org-agenda-windows
  986. :type 'boolean)
  987. (defcustom org-agenda-span 'week
  988. "Number of days to include in overview display.
  989. Can be day, week, month, year, or any number of days.
  990. Custom commands can set this variable in the options section."
  991. :group 'org-agenda-daily/weekly
  992. :type '(choice (const :tag "Day" day)
  993. (const :tag "Week" week)
  994. (const :tag "Fortnight" fortnight)
  995. (const :tag "Month" month)
  996. (const :tag "Year" year)
  997. (integer :tag "Custom")))
  998. (defcustom org-agenda-start-on-weekday 1
  999. "Non-nil means start the overview always on the specified weekday.
  1000. 0 denotes Sunday, 1 denotes Monday, etc.
  1001. When nil, always start on the current day.
  1002. Custom commands can set this variable in the options section."
  1003. :group 'org-agenda-daily/weekly
  1004. :type '(choice (const :tag "Today" nil)
  1005. (integer :tag "Weekday No.")))
  1006. (defcustom org-agenda-show-all-dates t
  1007. "Non-nil means `org-agenda' shows every day in the selected range.
  1008. When nil, only the days which actually have entries are shown."
  1009. :group 'org-agenda-daily/weekly
  1010. :type 'boolean)
  1011. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1012. "Format string for displaying dates in the agenda.
  1013. Used by the daily/weekly agenda. This should be a format string
  1014. understood by `format-time-string', or a function returning the
  1015. formatted date as a string. The function must take a single
  1016. argument, a calendar-style date list like (month day year)."
  1017. :group 'org-agenda-daily/weekly
  1018. :type '(choice
  1019. (string :tag "Format string")
  1020. (function :tag "Function")))
  1021. (defun org-agenda-format-date-aligned (date)
  1022. "Format a DATE string for display in the daily/weekly agenda.
  1023. This function makes sure that dates are aligned for easy reading."
  1024. (require 'cal-iso)
  1025. (let* ((dayname (calendar-day-name date))
  1026. (day (cadr date))
  1027. (day-of-week (calendar-day-of-week date))
  1028. (month (car date))
  1029. (monthname (calendar-month-name month))
  1030. (year (nth 2 date))
  1031. (iso-week (org-days-to-iso-week
  1032. (calendar-absolute-from-gregorian date)))
  1033. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1034. (1- year))
  1035. ((and (= month 12) (<= iso-week 1))
  1036. (1+ year))
  1037. (t year)))
  1038. (weekstring (if (= day-of-week 1)
  1039. (format " W%02d" iso-week)
  1040. "")))
  1041. (format "%-10s %2d %s %4d%s"
  1042. dayname day monthname year weekstring)))
  1043. (defcustom org-agenda-time-leading-zero nil
  1044. "Non-nil means use leading zero for military times in agenda.
  1045. For example, 9:30am would become 09:30 rather than 9:30."
  1046. :group 'org-agenda-daily/weekly
  1047. :version "24.1"
  1048. :type 'boolean)
  1049. (defcustom org-agenda-timegrid-use-ampm nil
  1050. "When set, show AM/PM style timestamps on the timegrid."
  1051. :group 'org-agenda
  1052. :version "24.1"
  1053. :type 'boolean)
  1054. (defun org-agenda-time-of-day-to-ampm (time)
  1055. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1056. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1057. (minute (substring time -2))
  1058. (ampm "am"))
  1059. (cond
  1060. ((equal hour-number 12)
  1061. (setq ampm "pm"))
  1062. ((> hour-number 12)
  1063. (setq ampm "pm")
  1064. (setq hour-number (- hour-number 12))))
  1065. (concat
  1066. (if org-agenda-time-leading-zero
  1067. (format "%02d" hour-number)
  1068. (format "%02s" (number-to-string hour-number)))
  1069. ":" minute ampm)))
  1070. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1071. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1072. (if org-agenda-timegrid-use-ampm
  1073. (org-agenda-time-of-day-to-ampm time)
  1074. time))
  1075. (defcustom org-agenda-weekend-days '(6 0)
  1076. "Which days are weekend?
  1077. These days get the special face `org-agenda-date-weekend' in the agenda."
  1078. :group 'org-agenda-daily/weekly
  1079. :type '(set :greedy t
  1080. (const :tag "Monday" 1)
  1081. (const :tag "Tuesday" 2)
  1082. (const :tag "Wednesday" 3)
  1083. (const :tag "Thursday" 4)
  1084. (const :tag "Friday" 5)
  1085. (const :tag "Saturday" 6)
  1086. (const :tag "Sunday" 0)))
  1087. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1088. "Non-nil means jump to today when moving a past date forward in time.
  1089. When using S-right in the agenda to move a date forward, and the date
  1090. stamp currently points to the past, the first key press will move it
  1091. to today. When nil, just move one day forward even if the date stays
  1092. in the past."
  1093. :group 'org-agenda-daily/weekly
  1094. :version "24.1"
  1095. :type 'boolean)
  1096. (defcustom org-agenda-include-diary nil
  1097. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1098. Custom commands can set this variable in the options section."
  1099. :group 'org-agenda-daily/weekly
  1100. :type 'boolean)
  1101. (defcustom org-agenda-include-deadlines t
  1102. "If non-nil, include entries within their deadline warning period.
  1103. Custom commands can set this variable in the options section."
  1104. :group 'org-agenda-daily/weekly
  1105. :version "24.1"
  1106. :type 'boolean)
  1107. (defcustom org-agenda-show-future-repeats t
  1108. "Non-nil shows repeated entries in the future part of the agenda.
  1109. When set to the symbol `next' only the first future repeat is shown."
  1110. :group 'org-agenda-daily/weekly
  1111. :type '(choice
  1112. (const :tag "Show all repeated entries" t)
  1113. (const :tag "Show next repeated entry" next)
  1114. (const :tag "Do not show repeated entries" nil))
  1115. :version "26.1"
  1116. :package-version '(Org . "9.1")
  1117. :safe #'symbolp)
  1118. (defcustom org-agenda-prefer-last-repeat nil
  1119. "Non-nil sets date for repeated entries to their last repeat.
  1120. When nil, display SCHEDULED and DEADLINE dates at their base
  1121. date, and in today's agenda, as a reminder. Display plain
  1122. time-stamps, on the other hand, at every repeat date in the past
  1123. in addition to the base date.
  1124. When non-nil, show a repeated entry at its latest repeat date,
  1125. possibly being today even if it wasn't marked as done. This
  1126. setting is useful if you do not always mark repeated entries as
  1127. done and, yet, consider that reaching repeat date starts the task
  1128. anew.
  1129. When set to a list of strings, prefer last repeats only for
  1130. entries with these TODO keywords."
  1131. :group 'org-agenda-daily/weekly
  1132. :type '(choice
  1133. (const :tag "Prefer last repeat" t)
  1134. (const :tag "Prefer base date" nil)
  1135. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1136. (string :tag "TODO keyword")))
  1137. :version "26.1"
  1138. :package-version '(Org . "9.1")
  1139. :safe (lambda (x) (or (booleanp x) (consp x))))
  1140. (defcustom org-scheduled-past-days 10000
  1141. "Number of days to continue listing scheduled items not marked DONE.
  1142. When an item is scheduled on a date, it shows up in the agenda on
  1143. this day and will be listed until it is marked done or for the
  1144. number of days given here."
  1145. :group 'org-agenda-daily/weekly
  1146. :type 'integer
  1147. :safe 'integerp)
  1148. (defcustom org-deadline-past-days 10000
  1149. "Number of days to warn about missed deadlines.
  1150. When an item has deadline on a date, it shows up in the agenda on
  1151. this day and will appear as a reminder until it is marked DONE or
  1152. for the number of days given here."
  1153. :group 'org-agenda-daily/weekly
  1154. :type 'integer
  1155. :version "26.1"
  1156. :package-version '(Org . "9.1")
  1157. :safe 'integerp)
  1158. (defcustom org-agenda-log-mode-items '(closed clock)
  1159. "List of items that should be shown in agenda log mode.
  1160. \\<org-agenda-mode-map>\
  1161. This list may contain the following symbols:
  1162. closed Show entries that have been closed on that day.
  1163. clock Show entries that have received clocked time on that day.
  1164. state Show all logged state changes.
  1165. Note that instead of changing this variable, you can also press \
  1166. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1167. the agenda to display all available LOG items temporarily."
  1168. :group 'org-agenda-daily/weekly
  1169. :type '(set :greedy t (const closed) (const clock) (const state)))
  1170. (defcustom org-agenda-clock-consistency-checks
  1171. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1172. :gap-ok-around ("4:00")
  1173. :default-face ((:background "DarkRed") (:foreground "white"))
  1174. :overlap-face nil :gap-face nil :no-end-time-face nil
  1175. :long-face nil :short-face nil)
  1176. "This is a property list, with the following keys:
  1177. :max-duration Mark clocking chunks that are longer than this time.
  1178. This is a time string like \"HH:MM\", or the number
  1179. of minutes as an integer.
  1180. :min-duration Mark clocking chunks that are shorter that this.
  1181. This is a time string like \"HH:MM\", or the number
  1182. of minutes as an integer.
  1183. :max-gap Mark gaps between clocking chunks that are longer than
  1184. this duration. A number of minutes, or a string
  1185. like \"HH:MM\".
  1186. :gap-ok-around List of times during the day which are usually not working
  1187. times. When a gap is detected, but the gap contains any
  1188. of these times, the gap is *not* reported. For example,
  1189. if this is (\"4:00\" \"13:00\") then gaps that contain
  1190. 4:00 in the morning (i.e. the night) and 13:00
  1191. (i.e. a typical lunch time) do not cause a warning.
  1192. You should have at least one time during the night in this
  1193. list, or otherwise the first task each morning will trigger
  1194. a warning because it follows a long gap.
  1195. Furthermore, the following properties can be used to define faces for
  1196. issue display.
  1197. :default-face the default face, if the specific face is undefined
  1198. :overlap-face face for overlapping clocks
  1199. :gap-face face for gaps between clocks
  1200. :no-end-time-face face for incomplete clocks
  1201. :long-face face for clock intervals that are too long
  1202. :short-face face for clock intervals that are too short"
  1203. :group 'org-agenda-daily/weekly
  1204. :group 'org-clock
  1205. :version "24.1"
  1206. :type 'plist)
  1207. (defcustom org-agenda-log-mode-add-notes t
  1208. "Non-nil means add first line of notes to log entries in agenda views.
  1209. If a log item like a state change or a clock entry is associated with
  1210. notes, the first line of these notes will be added to the entry in the
  1211. agenda display."
  1212. :group 'org-agenda-daily/weekly
  1213. :type 'boolean)
  1214. (defcustom org-agenda-start-with-log-mode nil
  1215. "The initial value of log-mode in a newly created agenda window.
  1216. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1217. explanations on the possible values."
  1218. :group 'org-agenda-startup
  1219. :group 'org-agenda-daily/weekly
  1220. :type '(choice (const :tag "Don't show log items" nil)
  1221. (const :tag "Show only log items" only)
  1222. (const :tag "Show all possible log items" clockcheck)
  1223. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1224. (choice (const :tag "Show closed log items" closed)
  1225. (const :tag "Show clocked log items" clock)
  1226. (const :tag "Show all logged state changes" state)))))
  1227. (defcustom org-agenda-start-with-clockreport-mode nil
  1228. "The initial value of clockreport-mode in a newly created agenda window."
  1229. :group 'org-agenda-startup
  1230. :group 'org-agenda-daily/weekly
  1231. :type 'boolean)
  1232. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1233. "Property list with parameters for the clocktable in clockreport mode.
  1234. This is the display mode that shows a clock table in the daily/weekly
  1235. agenda, the properties for this dynamic block can be set here.
  1236. The usual clocktable parameters are allowed here, but you cannot set
  1237. the properties :name, :tstart, :tend, :block, and :scope - these will
  1238. be overwritten to make sure the content accurately reflects the
  1239. current display in the agenda."
  1240. :group 'org-agenda-daily/weekly
  1241. :type 'plist)
  1242. (defvaralias 'org-agenda-search-view-search-words-only
  1243. 'org-agenda-search-view-always-boolean)
  1244. (defcustom org-agenda-search-view-always-boolean nil
  1245. "Non-nil means the search string is interpreted as individual parts.
  1246. The search string for search view can either be interpreted as a phrase,
  1247. or as a list of snippets that define a boolean search for a number of
  1248. strings.
  1249. When this is non-nil, the string will be split on whitespace, and each
  1250. snippet will be searched individually, and all must match in order to
  1251. select an entry. A snippet is then a single string of non-white
  1252. characters, or a string in double quotes, or a regexp in {} braces.
  1253. If a snippet is preceded by \"-\", the snippet must *not* match.
  1254. \"+\" is syntactic sugar for positive selection. Each snippet may
  1255. be found as a full word or a partial word, but see the variable
  1256. `org-agenda-search-view-force-full-words'.
  1257. When this is nil, search will look for the entire search phrase as one,
  1258. with each space character matching any amount of whitespace, including
  1259. line breaks.
  1260. Even when this is nil, you can still switch to Boolean search dynamically
  1261. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1262. is a regexp marked with braces like \"{abc}\", this will also switch to
  1263. boolean search."
  1264. :group 'org-agenda-search-view
  1265. :version "24.1"
  1266. :type 'boolean)
  1267. (defcustom org-agenda-search-view-force-full-words nil
  1268. "Non-nil means, search words must be matches as complete words.
  1269. When nil, they may also match part of a word."
  1270. :group 'org-agenda-search-view
  1271. :version "24.1"
  1272. :type 'boolean)
  1273. (defcustom org-agenda-search-view-max-outline-level 0
  1274. "Maximum outline level to display in search view.
  1275. E.g. when this is set to 1, the search view will only
  1276. show headlines of level 1. When set to 0, the default
  1277. value, don't limit agenda view by outline level."
  1278. :group 'org-agenda-search-view
  1279. :version "26.1"
  1280. :package-version '(Org . "8.3")
  1281. :type 'integer)
  1282. (defgroup org-agenda-time-grid nil
  1283. "Options concerning the time grid in the Org Agenda."
  1284. :tag "Org Agenda Time Grid"
  1285. :group 'org-agenda)
  1286. (defcustom org-agenda-search-headline-for-time t
  1287. "Non-nil means search headline for a time-of-day.
  1288. If the headline contains a time-of-day in one format or another, it will
  1289. be used to sort the entry into the time sequence of items for a day.
  1290. Some people have time stamps in the headline that refer to the creation
  1291. time or so, and then this produces an unwanted side effect. If this is
  1292. the case for your, use this variable to turn off searching the headline
  1293. for a time."
  1294. :group 'org-agenda-time-grid
  1295. :type 'boolean)
  1296. (defcustom org-agenda-use-time-grid t
  1297. "Non-nil means show a time grid in the agenda schedule.
  1298. A time grid is a set of lines for specific times (like every two hours between
  1299. 8:00 and 20:00). The items scheduled for a day at specific times are
  1300. sorted in between these lines.
  1301. For details about when the grid will be shown, and what it will look like, see
  1302. the variable `org-agenda-time-grid'."
  1303. :group 'org-agenda-time-grid
  1304. :type 'boolean)
  1305. (defcustom org-agenda-time-grid
  1306. '((daily today require-timed)
  1307. (800 1000 1200 1400 1600 1800 2000)
  1308. "......"
  1309. "----------------")
  1310. "The settings for time grid for agenda display.
  1311. This is a list of four items. The first item is again a list. It contains
  1312. symbols specifying conditions when the grid should be displayed:
  1313. daily if the agenda shows a single day
  1314. weekly if the agenda shows an entire week
  1315. today show grid on current date, independent of daily/weekly display
  1316. require-timed show grid only if at least one item has a time specification
  1317. remove-match skip grid times already present in an entry
  1318. The second item is a list of integers, indicating the times that
  1319. should have a grid line.
  1320. The third item is a string which will be placed right after the
  1321. times that have a grid line.
  1322. The fourth item is a string placed after the grid times. This
  1323. will align with agenda items."
  1324. :group 'org-agenda-time-grid
  1325. :type
  1326. '(list
  1327. (set :greedy t :tag "Grid Display Options"
  1328. (const :tag "Show grid in single day agenda display" daily)
  1329. (const :tag "Show grid in weekly agenda display" weekly)
  1330. (const :tag "Always show grid for today" today)
  1331. (const :tag "Show grid only if any timed entries are present"
  1332. require-timed)
  1333. (const :tag "Skip grid times already present in an entry"
  1334. remove-match))
  1335. (repeat :tag "Grid Times" (integer :tag "Time"))
  1336. (string :tag "Grid String (after agenda times)")
  1337. (string :tag "Grid String (aligns with agenda items)")))
  1338. (defcustom org-agenda-show-current-time-in-grid t
  1339. "Non-nil means show the current time in the time grid."
  1340. :group 'org-agenda-time-grid
  1341. :version "24.1"
  1342. :type 'boolean)
  1343. (defcustom org-agenda-current-time-string
  1344. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1345. "The string for the current time marker in the agenda."
  1346. :group 'org-agenda-time-grid
  1347. :version "24.1"
  1348. :type 'string)
  1349. (defgroup org-agenda-sorting nil
  1350. "Options concerning sorting in the Org Agenda."
  1351. :tag "Org Agenda Sorting"
  1352. :group 'org-agenda)
  1353. (defcustom org-agenda-sorting-strategy
  1354. '((agenda habit-down time-up priority-down category-keep)
  1355. (todo priority-down category-keep)
  1356. (tags priority-down category-keep)
  1357. (search category-keep))
  1358. "Sorting structure for the agenda items of a single day.
  1359. This is a list of symbols which will be used in sequence to determine
  1360. if an entry should be listed before another entry. The following
  1361. symbols are recognized:
  1362. time-up Put entries with time-of-day indications first, early first.
  1363. time-down Put entries with time-of-day indications first, late first.
  1364. timestamp-up Sort by any timestamp, early first.
  1365. timestamp-down Sort by any timestamp, late first.
  1366. scheduled-up Sort by scheduled timestamp, early first.
  1367. scheduled-down Sort by scheduled timestamp, late first.
  1368. deadline-up Sort by deadline timestamp, early first.
  1369. deadline-down Sort by deadline timestamp, late first.
  1370. ts-up Sort by active timestamp, early first.
  1371. ts-down Sort by active timestamp, late first.
  1372. tsia-up Sort by inactive timestamp, early first.
  1373. tsia-down Sort by inactive timestamp, late first.
  1374. category-keep Keep the default order of categories, corresponding to the
  1375. sequence in `org-agenda-files'.
  1376. category-up Sort alphabetically by category, A-Z.
  1377. category-down Sort alphabetically by category, Z-A.
  1378. tag-up Sort alphabetically by last tag, A-Z.
  1379. tag-down Sort alphabetically by last tag, Z-A.
  1380. priority-up Sort numerically by priority, high priority last.
  1381. priority-down Sort numerically by priority, high priority first.
  1382. todo-state-up Sort by todo state, tasks that are done last.
  1383. todo-state-down Sort by todo state, tasks that are done first.
  1384. effort-up Sort numerically by estimated effort, high effort last.
  1385. effort-down Sort numerically by estimated effort, high effort first.
  1386. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1387. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1388. habit-up Put entries that are habits first.
  1389. habit-down Put entries that are habits last.
  1390. alpha-up Sort headlines alphabetically.
  1391. alpha-down Sort headlines alphabetically, reversed.
  1392. The different possibilities will be tried in sequence, and testing stops
  1393. if one comparison returns a \"not-equal\". For example, the default
  1394. '(time-up category-keep priority-down)
  1395. means: Pull out all entries having a specified time of day and sort them,
  1396. in order to make a time schedule for the current day the first thing in the
  1397. agenda listing for the day. Of the entries without a time indication, keep
  1398. the grouped in categories, don't sort the categories, but keep them in
  1399. the sequence given in `org-agenda-files'. Within each category sort by
  1400. priority.
  1401. Leaving out `category-keep' would mean that items will be sorted across
  1402. categories by priority.
  1403. Instead of a single list, this can also be a set of list for specific
  1404. contents, with a context symbol in the car of the list, any of
  1405. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1406. Custom commands can bind this variable in the options section."
  1407. :group 'org-agenda-sorting
  1408. :type `(choice
  1409. (repeat :tag "General" ,org-sorting-choice)
  1410. (list :tag "Individually"
  1411. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1412. (repeat ,org-sorting-choice))
  1413. (cons (const :tag "Strategy for TODO lists" todo)
  1414. (repeat ,org-sorting-choice))
  1415. (cons (const :tag "Strategy for Tags matches" tags)
  1416. (repeat ,org-sorting-choice))
  1417. (cons (const :tag "Strategy for search matches" search)
  1418. (repeat ,org-sorting-choice)))))
  1419. (defcustom org-agenda-cmp-user-defined nil
  1420. "A function to define the comparison `user-defined'.
  1421. This function must receive two arguments, agenda entry a and b.
  1422. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1423. the user comparison, return nil.
  1424. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1425. part of an agenda sorting strategy."
  1426. :group 'org-agenda-sorting
  1427. :type 'symbol)
  1428. (defcustom org-sort-agenda-notime-is-late t
  1429. "Non-nil means items without time are considered late.
  1430. This is only relevant for sorting. When t, items which have no explicit
  1431. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1432. do have a time. When nil, the default time is before 0:00. You can use this
  1433. option to decide if the schedule for today should come before or after timeless
  1434. agenda entries."
  1435. :group 'org-agenda-sorting
  1436. :type 'boolean)
  1437. (defcustom org-sort-agenda-noeffort-is-high t
  1438. "Non-nil means items without effort estimate are sorted as high effort.
  1439. This also applies when filtering an agenda view with respect to the
  1440. < or > effort operator. Then, tasks with no effort defined will be treated
  1441. as tasks with high effort.
  1442. When nil, such items are sorted as 0 minutes effort."
  1443. :group 'org-agenda-sorting
  1444. :type 'boolean)
  1445. (defgroup org-agenda-line-format nil
  1446. "Options concerning the entry prefix in the Org agenda display."
  1447. :tag "Org Agenda Line Format"
  1448. :group 'org-agenda)
  1449. (defcustom org-agenda-prefix-format
  1450. '((agenda . " %i %-12:c%?-12t% s")
  1451. (todo . " %i %-12:c")
  1452. (tags . " %i %-12:c")
  1453. (search . " %i %-12:c"))
  1454. "Format specifications for the prefix of items in the agenda views.
  1455. An alist with one entry per agenda type. The keys of the
  1456. sublists are `agenda', `todo', `search' and `tags'. The values
  1457. are format strings.
  1458. This format works similar to a printf format, with the following meaning:
  1459. %c the category of the item, \"Diary\" for entries from the diary,
  1460. or as given by the CATEGORY keyword or derived from the file name
  1461. %e the effort required by the item
  1462. %l the level of the item (insert X space(s) if item is of level X)
  1463. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1464. %T the last tag of the item (ignore inherited tags, which come first)
  1465. %t the HH:MM time-of-day specification if one applies to the entry
  1466. %s Scheduling/Deadline information, a short string
  1467. %b show breadcrumbs, i.e., the names of the higher levels
  1468. %(expression) Eval EXPRESSION and replace the control string
  1469. by the result
  1470. All specifiers work basically like the standard `%s' of printf, but may
  1471. contain two additional characters: a question mark just after the `%'
  1472. and a whitespace/punctuation character just before the final letter.
  1473. If the first character after `%' is a question mark, the entire field
  1474. will only be included if the corresponding value applies to the current
  1475. entry. This is useful for fields which should have fixed width when
  1476. present, but zero width when absent. For example, \"%?-12t\" will
  1477. result in a 12 character time field if a time of the day is specified,
  1478. but will completely disappear in entries which do not contain a time.
  1479. If there is punctuation or whitespace character just before the
  1480. final format letter, this character will be appended to the field
  1481. value if the value is not empty. For example, the format
  1482. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1483. the category is empty, no additional colon is inserted.
  1484. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1485. which means:
  1486. - Indent the line with two space characters
  1487. - Give the category a 12 chars wide field, padded with whitespace on
  1488. the right (because of `-'). Append a colon if there is a category
  1489. (because of `:').
  1490. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1491. time, don't put in an empty field, just skip it (because of '?').
  1492. - Finally, put the scheduling information.
  1493. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1494. `org-agenda-remove-tags'.
  1495. Custom commands can set this variable in the options section."
  1496. :type '(choice
  1497. (string :tag "General format")
  1498. (list :greedy t :tag "View dependent"
  1499. (cons (const agenda) (string :tag "Format"))
  1500. (cons (const todo) (string :tag "Format"))
  1501. (cons (const tags) (string :tag "Format"))
  1502. (cons (const search) (string :tag "Format"))))
  1503. :group 'org-agenda-line-format
  1504. :version "26.1"
  1505. :package-version '(Org . "9.1"))
  1506. (defcustom org-agenda-breadcrumbs-separator "->"
  1507. "The separator of breadcrumbs in agenda lines."
  1508. :group 'org-agenda-line-format
  1509. :package-version '(Org . "9.3")
  1510. :type 'string
  1511. :safe #'stringp)
  1512. (defvar org-prefix-format-compiled nil
  1513. "The compiled prefix format and associated variables.
  1514. This is a list where first element is a list of variable bindings, and second
  1515. element is the compiled format expression. See the variable
  1516. `org-agenda-prefix-format'.")
  1517. (defcustom org-agenda-todo-keyword-format "%-1s"
  1518. "Format for the TODO keyword in agenda lines.
  1519. Set this to something like \"%-12s\" if you want all TODO keywords
  1520. to occupy a fixed space in the agenda display."
  1521. :group 'org-agenda-line-format
  1522. :type 'string)
  1523. (defcustom org-agenda-diary-sexp-prefix nil
  1524. "A regexp that matches part of a diary sexp entry
  1525. which should be treated as scheduling/deadline information in
  1526. `org-agenda'.
  1527. For example, you can use this to extract the `diary-remind-message' from
  1528. `diary-remind' entries."
  1529. :group 'org-agenda-line-format
  1530. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1531. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1532. "Text preceding timerange entries in the agenda view.
  1533. This is a list with two strings. The first applies when the range
  1534. is entirely on one day. The second applies if the range spans several days.
  1535. The strings may have two \"%d\" format specifiers which will be filled
  1536. with the sequence number of the days, and the total number of days in the
  1537. range, respectively."
  1538. :group 'org-agenda-line-format
  1539. :type '(list
  1540. (string :tag "Deadline today ")
  1541. (choice :tag "Deadline relative"
  1542. (string :tag "Format string")
  1543. (function))))
  1544. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1545. "Text preceding scheduled items in the agenda view.
  1546. This is a list with two strings. The first applies when the item is
  1547. scheduled on the current day. The second applies when it has been scheduled
  1548. previously, it may contain a %d indicating that this is the nth time that
  1549. this item is scheduled, due to automatic rescheduling of unfinished items
  1550. for the following day. So this number is one larger than the number of days
  1551. that passed since this item was scheduled first."
  1552. :group 'org-agenda-line-format
  1553. :version "24.4"
  1554. :package-version '(Org . "8.0")
  1555. :type '(list
  1556. (string :tag "Scheduled today ")
  1557. (string :tag "Scheduled previously")))
  1558. (defcustom org-agenda-inactive-leader "["
  1559. "Text preceding item pulled into the agenda by inactive time stamps.
  1560. These entries are added to the agenda when pressing \"[\"."
  1561. :group 'org-agenda-line-format
  1562. :version "24.1"
  1563. :type 'string)
  1564. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1565. "Text preceding deadline items in the agenda view.
  1566. This is a list with three strings. The first applies when the item has its
  1567. deadline on the current day. The second applies when the deadline is in the
  1568. future, the third one when it is in the past. The strings may contain %d
  1569. to capture the number of days."
  1570. :group 'org-agenda-line-format
  1571. :version "24.4"
  1572. :package-version '(Org . "8.0")
  1573. :type '(list
  1574. (string :tag "Deadline today ")
  1575. (string :tag "Deadline in the future ")
  1576. (string :tag "Deadline in the past ")))
  1577. (defcustom org-agenda-remove-times-when-in-prefix t
  1578. "Non-nil means remove duplicate time specifications in agenda items.
  1579. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1580. time-of-day specification in a headline or diary entry is extracted and
  1581. placed into the prefix. If this option is non-nil, the original specification
  1582. \(a timestamp or -range, or just a plain time(range) specification like
  1583. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1584. cluttered.
  1585. The option can be t or nil. It may also be the symbol `beg', indicating
  1586. that the time should only be removed when it is located at the beginning of
  1587. the headline/diary entry."
  1588. :group 'org-agenda-line-format
  1589. :type '(choice
  1590. (const :tag "Always" t)
  1591. (const :tag "Never" nil)
  1592. (const :tag "When at beginning of entry" beg)))
  1593. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1594. "Non-nil means remove time ranges specifications in agenda
  1595. items that span on several days."
  1596. :group 'org-agenda-line-format
  1597. :version "24.1"
  1598. :type 'boolean)
  1599. (defcustom org-agenda-default-appointment-duration nil
  1600. "Default duration for appointments that only have a starting time.
  1601. When nil, no duration is specified in such cases.
  1602. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1603. :group 'org-agenda-line-format
  1604. :type '(choice
  1605. (integer :tag "Minutes")
  1606. (const :tag "No default duration")))
  1607. (defcustom org-agenda-show-inherited-tags t
  1608. "Non-nil means show inherited tags in each agenda line.
  1609. When this option is set to `always', it takes precedence over
  1610. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1611. in every agenda.
  1612. When this option is set to t (the default), inherited tags are
  1613. shown when they are available, i.e. when the value of
  1614. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1615. given agenda type.
  1616. This can be set to a list of agenda types in which the agenda
  1617. must display the inherited tags. Available types are `todo',
  1618. `agenda' and `search'.
  1619. When set to nil, never show inherited tags in agenda lines."
  1620. :group 'org-agenda-line-format
  1621. :group 'org-agenda
  1622. :version "24.3"
  1623. :type '(choice
  1624. (const :tag "Show inherited tags when available" t)
  1625. (const :tag "Always show inherited tags" always)
  1626. (repeat :tag "Show inherited tags only in selected agenda types"
  1627. (symbol :tag "Agenda type"))))
  1628. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1629. "List of agenda view types where to use tag inheritance.
  1630. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1631. controlled by `org-use-tag-inheritance'. In other agenda types,
  1632. `org-use-tag-inheritance' is not used for the selection of the
  1633. agenda entries. Still, you may want the agenda to be aware of
  1634. the inherited tags anyway, e.g. for later tag filtering.
  1635. Allowed value are `todo', `search' and `agenda'.
  1636. This variable has no effect if `org-agenda-show-inherited-tags'
  1637. is set to `always'. In that case, the agenda is aware of those
  1638. tags.
  1639. The default value sets tags in every agenda type. Setting this
  1640. option to nil will speed up non-tags agenda view a lot."
  1641. :group 'org-agenda
  1642. :version "26.1"
  1643. :package-version '(Org . "9.1")
  1644. :type '(choice
  1645. (const :tag "Use tag inheritance in all agenda types" t)
  1646. (repeat :tag "Use tag inheritance in selected agenda types"
  1647. (symbol :tag "Agenda type"))))
  1648. (defcustom org-agenda-hide-tags-regexp nil
  1649. "Regular expression used to filter away specific tags in agenda views.
  1650. This means that these tags will be present, but not be shown in the agenda
  1651. line. Secondary filtering will still work on the hidden tags.
  1652. Nil means don't hide any tags."
  1653. :group 'org-agenda-line-format
  1654. :type '(choice
  1655. (const :tag "Hide none" nil)
  1656. (string :tag "Regexp ")))
  1657. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1658. 'org-agenda-remove-tags)
  1659. (defcustom org-agenda-remove-tags nil
  1660. "Non-nil means remove the tags from the headline copy in the agenda.
  1661. When this is the symbol `prefix', only remove tags when
  1662. `org-agenda-prefix-format' contains a `%T' specifier."
  1663. :group 'org-agenda-line-format
  1664. :type '(choice
  1665. (const :tag "Always" t)
  1666. (const :tag "Never" nil)
  1667. (const :tag "When prefix format contains %T" prefix)))
  1668. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1669. (defcustom org-agenda-tags-column 'auto
  1670. "Shift tags in agenda items to this column.
  1671. If set to `auto', tags will be automatically aligned to the right
  1672. edge of the window.
  1673. If set to a positive number, tags will be left-aligned to that
  1674. column. If set to a negative number, tags will be right-aligned
  1675. to that column. For example, -80 works well for a normal 80
  1676. character screen."
  1677. :group 'org-agenda-line-format
  1678. :type '(choice
  1679. (const :tag "Automatically align to right edge of window" auto)
  1680. (integer :tag "Specific column" -80))
  1681. :package-version '(Org . "9.1")
  1682. :version "26.1")
  1683. (defcustom org-agenda-fontify-priorities 'cookies
  1684. "Non-nil means highlight low and high priorities in agenda.
  1685. When t, the highest priority entries are bold, lowest priority italic.
  1686. However, settings in `org-priority-faces' will overrule these faces.
  1687. When this variable is the symbol `cookies', only fontify the
  1688. cookies, not the entire task.
  1689. This may also be an association list of priority faces, whose
  1690. keys are the character values of `org-highest-priority',
  1691. `org-default-priority', and `org-lowest-priority' (the default values
  1692. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1693. color as a string, or a list like `(:background \"Red\")'.
  1694. If it is a color, the variable `org-faces-easy-properties'
  1695. determines if it is a foreground or a background color."
  1696. :group 'org-agenda-line-format
  1697. :type '(choice
  1698. (const :tag "Never" nil)
  1699. (const :tag "Defaults" t)
  1700. (const :tag "Cookies only" cookies)
  1701. (repeat :tag "Specify"
  1702. (list (character :tag "Priority" :value ?A)
  1703. (choice :tag "Face "
  1704. (string :tag "Color")
  1705. (sexp :tag "Face"))))))
  1706. (defcustom org-agenda-day-face-function nil
  1707. "Function called to determine what face should be used to display a day.
  1708. The only argument passed to that function is the day. It should
  1709. returns a face, or nil if does not want to specify a face and let
  1710. the normal rules apply."
  1711. :group 'org-agenda-line-format
  1712. :version "24.1"
  1713. :type '(choice (const nil) (function)))
  1714. (defcustom org-agenda-category-icon-alist nil
  1715. "Alist of category icon to be displayed in agenda views.
  1716. Each entry should have the following format:
  1717. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1718. Where CATEGORY-REGEXP is a regexp matching the categories where
  1719. the icon should be displayed.
  1720. FILE-OR-DATA either a file path or a string containing image data.
  1721. The other fields can be omitted safely if not needed:
  1722. TYPE indicates the image type.
  1723. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1724. image data.
  1725. PROPS are additional image attributes to assign to the image,
  1726. like, e.g. `:ascent center'.
  1727. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1728. If you want to set the display properties yourself, just put a
  1729. list as second element:
  1730. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1731. For example, to display a 16px horizontal space for Emacs
  1732. category, you can use:
  1733. (\"Emacs\" \\='(space . (:width (16))))"
  1734. :group 'org-agenda-line-format
  1735. :version "24.1"
  1736. :type '(alist :key-type (string :tag "Regexp matching category")
  1737. :value-type (choice (list :tag "Icon"
  1738. (string :tag "File or data")
  1739. (symbol :tag "Type")
  1740. (boolean :tag "Data?")
  1741. (repeat :tag "Extra image properties" :inline t symbol))
  1742. (list :tag "Display properties" sexp))))
  1743. (defgroup org-agenda-column-view nil
  1744. "Options concerning column view in the agenda."
  1745. :tag "Org Agenda Column View"
  1746. :group 'org-agenda)
  1747. (defcustom org-agenda-view-columns-initially nil
  1748. "When non-nil, switch to columns view right after creating the agenda."
  1749. :group 'org-agenda-column-view
  1750. :type 'boolean
  1751. :version "26.1"
  1752. :package-version '(Org . "9.0")
  1753. :safe #'booleanp)
  1754. (defcustom org-agenda-columns-show-summaries t
  1755. "Non-nil means show summaries for columns displayed in the agenda view."
  1756. :group 'org-agenda-column-view
  1757. :type 'boolean)
  1758. (defcustom org-agenda-columns-compute-summary-properties t
  1759. "Non-nil means recompute all summary properties before column view.
  1760. When column view in the agenda is listing properties that have a summary
  1761. operator, it can go to all relevant buffers and recompute the summaries
  1762. there. This can mean overhead for the agenda column view, but is necessary
  1763. to have thing up to date.
  1764. As a special case, a CLOCKSUM property also makes sure that the clock
  1765. computations are current."
  1766. :group 'org-agenda-column-view
  1767. :type 'boolean)
  1768. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1769. "Non-nil means the duration of an appointment will add to day effort.
  1770. The property to which appointment durations will be added is the one given
  1771. in the option `org-effort-property'. If an appointment does not have
  1772. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1773. is not set, an appointment without end time will not contribute to the time
  1774. estimate."
  1775. :group 'org-agenda-column-view
  1776. :type 'boolean)
  1777. (defcustom org-agenda-auto-exclude-function nil
  1778. "A function called with a tag to decide if it is filtered on \
  1779. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1780. The sole argument to the function, which is called once for each
  1781. possible tag, is a string giving the name of the tag. The
  1782. function should return either nil if the tag should be included
  1783. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1784. lines not carrying this tag.
  1785. Note that for the purpose of tag filtering, only the lower-case version of
  1786. all tags will be considered, so that this function will only ever see
  1787. the lower-case version of all tags."
  1788. :group 'org-agenda
  1789. :type '(choice (const nil) (function)))
  1790. (defcustom org-agenda-bulk-custom-functions nil
  1791. "Alist of characters and custom functions for bulk actions.
  1792. For example, this value makes those two functions available:
  1793. \\='((?R set-category)
  1794. (?C bulk-cut))
  1795. With selected entries in an agenda buffer, `B R' will call
  1796. the custom function `set-category' on the selected entries.
  1797. Note that functions in this alist don't need to be quoted."
  1798. :type '(alist :key-type character :value-type (group function))
  1799. :version "24.1"
  1800. :group 'org-agenda)
  1801. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1802. "Execute BODY with point at location given by `org-hd-marker' property.
  1803. If STRING is non-nil, the text property will be fetched from position 0
  1804. in that string. If STRING is nil, it will be fetched from the beginning
  1805. of the current line."
  1806. (org-with-gensyms (marker)
  1807. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1808. 'org-hd-marker ,string)))
  1809. (with-current-buffer (marker-buffer ,marker)
  1810. (save-excursion
  1811. (goto-char ,marker)
  1812. ,@body)))))
  1813. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1814. (defun org-add-agenda-custom-command (entry)
  1815. "Replace or add a command in `org-agenda-custom-commands'.
  1816. This is mostly for hacking and trying a new command - once the command
  1817. works you probably want to add it to `org-agenda-custom-commands' for good."
  1818. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1819. (if ass
  1820. (setcdr ass (cdr entry))
  1821. (push entry org-agenda-custom-commands))))
  1822. (defmacro org-agenda--insert-overriding-header (default)
  1823. "Insert header into agenda view.
  1824. The inserted header depends on `org-agenda-overriding-header'.
  1825. If the empty string, don't insert a header. If any other string,
  1826. insert it as a header. If nil, insert DEFAULT, which should
  1827. evaluate to a string."
  1828. (declare (debug (form)) (indent defun))
  1829. `(cond
  1830. ((not org-agenda-overriding-header) (insert ,default))
  1831. ((equal org-agenda-overriding-header "") nil)
  1832. ((stringp org-agenda-overriding-header)
  1833. (insert (propertize org-agenda-overriding-header
  1834. 'face 'org-agenda-structure)
  1835. "\n"))
  1836. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1837. org-agenda-overriding-header))))
  1838. ;;; Define the org-agenda-mode
  1839. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1840. (defvar org-agenda-mode-map (make-sparse-keymap)
  1841. "Keymap for `org-agenda-mode'.")
  1842. (defvar org-agenda-menu) ; defined later in this file.
  1843. (defvar org-agenda-restrict nil) ; defined later in this file.
  1844. (defvar org-agenda-follow-mode nil)
  1845. (defvar org-agenda-entry-text-mode nil)
  1846. (defvar org-agenda-clockreport-mode nil)
  1847. (defvar org-agenda-show-log nil
  1848. "When non-nil, show the log in the agenda.
  1849. Do not set this directly; instead use
  1850. `org-agenda-start-with-log-mode', which see.")
  1851. (defvar org-agenda-redo-command nil)
  1852. (defvar org-agenda-query-string nil)
  1853. (defvar org-agenda-mode-hook nil
  1854. "Hook run after `org-agenda-mode' is turned on.
  1855. The buffer is still writable when this hook is called.")
  1856. (defvar org-agenda-type nil)
  1857. (defvar org-agenda-force-single-file nil)
  1858. (defvar org-agenda-bulk-marked-entries nil
  1859. "List of markers that refer to marked entries in the agenda.")
  1860. (defvar org-agenda-current-date nil
  1861. "Active date when building the agenda.")
  1862. ;;; Multiple agenda buffers support
  1863. (defcustom org-agenda-sticky nil
  1864. "Non-nil means agenda q key will bury agenda buffers.
  1865. Agenda commands will then show existing buffer instead of generating new ones.
  1866. When nil, `q' will kill the single agenda buffer."
  1867. :group 'org-agenda
  1868. :version "24.3"
  1869. :type 'boolean)
  1870. ;;;###autoload
  1871. (defun org-toggle-sticky-agenda (&optional arg)
  1872. "Toggle `org-agenda-sticky'."
  1873. (interactive "P")
  1874. (let ((new-value (if arg
  1875. (> (prefix-numeric-value arg) 0)
  1876. (not org-agenda-sticky))))
  1877. (if (equal new-value org-agenda-sticky)
  1878. (and (called-interactively-p 'interactive)
  1879. (message "Sticky agenda was already %s"
  1880. (if org-agenda-sticky "enabled" "disabled")))
  1881. (setq org-agenda-sticky new-value)
  1882. (org-agenda-kill-all-agenda-buffers)
  1883. (and (called-interactively-p 'interactive)
  1884. (message "Sticky agenda %s"
  1885. (if org-agenda-sticky "enabled" "disabled"))))))
  1886. (defvar org-agenda-buffer nil
  1887. "Agenda buffer currently being generated.")
  1888. (defvar org-agenda-last-prefix-arg nil)
  1889. (defvar org-agenda-this-buffer-name nil)
  1890. (defvar org-agenda-doing-sticky-redo nil)
  1891. (defvar org-agenda-this-buffer-is-sticky nil)
  1892. (defvar org-agenda-last-indirect-buffer nil
  1893. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1894. (defconst org-agenda-local-vars
  1895. '(org-agenda-this-buffer-name
  1896. org-agenda-undo-list
  1897. org-agenda-pending-undo-list
  1898. org-agenda-follow-mode
  1899. org-agenda-entry-text-mode
  1900. org-agenda-clockreport-mode
  1901. org-agenda-show-log
  1902. org-agenda-redo-command
  1903. org-agenda-query-string
  1904. org-agenda-type
  1905. org-agenda-bulk-marked-entries
  1906. org-agenda-undo-has-started-in
  1907. org-agenda-info
  1908. org-agenda-pre-window-conf
  1909. org-agenda-columns-active
  1910. org-agenda-tag-filter
  1911. org-agenda-category-filter
  1912. org-agenda-top-headline-filter
  1913. org-agenda-regexp-filter
  1914. org-agenda-effort-filter
  1915. org-agenda-markers
  1916. org-agenda-last-search-view-search-was-boolean
  1917. org-agenda-last-indirect-buffer
  1918. org-agenda-filtered-by-category
  1919. org-agenda-filter-form
  1920. org-agenda-cycle-counter
  1921. org-agenda-last-prefix-arg)
  1922. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1923. (defun org-agenda-mode ()
  1924. "Mode for time-sorted view on action items in Org files.
  1925. The following commands are available:
  1926. \\{org-agenda-mode-map}"
  1927. (interactive)
  1928. (let ((agenda-local-vars-to-keep
  1929. '(text-scale-mode-amount
  1930. text-scale-mode
  1931. text-scale-mode-lighter
  1932. face-remapping-alist))
  1933. (save (buffer-local-variables)))
  1934. (kill-all-local-variables)
  1935. (cl-flet ((reset-saved (var-set)
  1936. "Reset variables in VAR-SET to possibly stored value in SAVE."
  1937. (dolist (elem save)
  1938. (pcase elem
  1939. (`(,var . ,val) ;ignore unbound variables
  1940. (when (and val (memq var var-set))
  1941. (set var val)))))))
  1942. (cond (org-agenda-doing-sticky-redo
  1943. ;; Refreshing sticky agenda-buffer
  1944. ;;
  1945. ;; Preserve the value of `org-agenda-local-vars' variables.
  1946. (mapc #'make-local-variable org-agenda-local-vars)
  1947. (reset-saved org-agenda-local-vars)
  1948. (setq-local org-agenda-this-buffer-is-sticky t))
  1949. (org-agenda-sticky
  1950. ;; Creating a sticky Agenda buffer for the first time
  1951. (mapc 'make-local-variable org-agenda-local-vars)
  1952. (setq-local org-agenda-this-buffer-is-sticky t))
  1953. (t
  1954. ;; Creating a non-sticky agenda buffer
  1955. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1956. (mapc #'make-local-variable agenda-local-vars-to-keep)
  1957. (reset-saved agenda-local-vars-to-keep)))
  1958. (setq org-agenda-undo-list nil
  1959. org-agenda-pending-undo-list nil
  1960. org-agenda-bulk-marked-entries nil)
  1961. (setq major-mode 'org-agenda-mode)
  1962. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1963. (setq-local font-lock-global-modes (list 'not major-mode))
  1964. (setq mode-name "Org-Agenda")
  1965. (setq indent-tabs-mode nil)
  1966. (use-local-map org-agenda-mode-map)
  1967. (easy-menu-add org-agenda-menu)
  1968. (when org-startup-truncated (setq truncate-lines t))
  1969. (setq-local line-move-visual nil)
  1970. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1971. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1972. ;; Make sure properties are removed when copying text
  1973. (if (boundp 'filter-buffer-substring-functions)
  1974. (add-hook 'filter-buffer-substring-functions
  1975. (lambda (fun start end delete)
  1976. (substring-no-properties (funcall fun start end delete)))
  1977. nil t)
  1978. ;; Emacs >= 24.4.
  1979. (add-function :filter-return (local 'filter-buffer-substring-function)
  1980. #'substring-no-properties))
  1981. (unless org-agenda-keep-modes
  1982. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1983. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1984. org-agenda-show-log org-agenda-start-with-log-mode
  1985. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  1986. (add-to-invisibility-spec '(org-filtered))
  1987. (add-to-invisibility-spec '(org-link))
  1988. (easy-menu-change
  1989. '("Agenda") "Agenda Files"
  1990. (append
  1991. (list
  1992. (vector
  1993. (if (get 'org-agenda-files 'org-restrict)
  1994. "Restricted to single file"
  1995. "Edit File List")
  1996. '(org-edit-agenda-file-list)
  1997. (not (get 'org-agenda-files 'org-restrict)))
  1998. "--")
  1999. (mapcar 'org-file-menu-entry (org-agenda-files))))
  2000. (org-agenda-set-mode-name)
  2001. (apply
  2002. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  2003. (list 'org-agenda-mode-hook)))
  2004. (substitute-key-definition 'undo 'org-agenda-undo
  2005. org-agenda-mode-map global-map)
  2006. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  2007. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  2008. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  2009. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  2010. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  2011. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  2012. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  2013. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  2014. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  2015. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  2016. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  2017. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  2018. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  2019. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  2020. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  2021. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  2022. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  2023. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  2024. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  2025. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  2026. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  2027. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  2028. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  2029. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  2030. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  2031. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  2032. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  2033. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  2034. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  2035. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  2036. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  2037. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  2038. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  2039. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  2040. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  2041. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  2042. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  2043. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  2044. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  2045. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  2046. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  2047. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  2048. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  2049. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  2050. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  2051. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  2052. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  2053. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  2054. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  2055. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  2056. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  2057. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  2058. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  2059. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2060. (while l (org-defkey org-agenda-mode-map
  2061. (int-to-string (pop l)) 'digit-argument)))
  2062. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  2063. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  2064. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2065. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2066. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2067. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2068. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2069. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2070. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2071. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo-all)
  2072. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2073. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2074. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2075. 'org-clock-modify-effort-estimate)
  2076. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2077. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2078. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2079. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2080. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2081. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2082. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2083. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2084. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2085. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2086. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2087. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2088. (substitute-key-definition 'next-line 'org-agenda-next-line
  2089. org-agenda-mode-map global-map)
  2090. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2091. org-agenda-mode-map global-map)
  2092. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2093. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2094. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2095. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2096. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2097. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2098. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2099. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2100. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2101. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2102. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2103. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2104. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2105. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2106. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2107. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2108. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2109. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2110. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2111. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2112. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2113. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2114. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2115. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2116. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2117. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2118. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2119. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2120. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2121. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2122. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2123. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2124. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2125. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2126. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2127. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag)
  2128. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2129. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2130. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter)
  2131. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2132. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2133. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2134. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2135. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2136. (org-defkey org-agenda-mode-map "\C-c\C-x_" 'org-timer-stop)
  2137. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2138. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2139. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2140. (org-defkey org-agenda-mode-map "\C-c\C-xI" 'org-info-find-node)
  2141. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2142. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2143. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2144. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2145. (when org-agenda-mouse-1-follows-link
  2146. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2147. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2148. '("Agenda"
  2149. ("Agenda Files")
  2150. "--"
  2151. ("Agenda Dates"
  2152. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2153. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2154. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2155. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2156. "--"
  2157. ("View"
  2158. ["Day View" org-agenda-day-view
  2159. :active (org-agenda-check-type nil 'agenda)
  2160. :style radio :selected (eq org-agenda-current-span 'day)
  2161. :keys "v d (or just d)"]
  2162. ["Week View" org-agenda-week-view
  2163. :active (org-agenda-check-type nil 'agenda)
  2164. :style radio :selected (eq org-agenda-current-span 'week)
  2165. :keys "v w"]
  2166. ["Fortnight View" org-agenda-fortnight-view
  2167. :active (org-agenda-check-type nil 'agenda)
  2168. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2169. :keys "v t"]
  2170. ["Month View" org-agenda-month-view
  2171. :active (org-agenda-check-type nil 'agenda)
  2172. :style radio :selected (eq org-agenda-current-span 'month)
  2173. :keys "v m"]
  2174. ["Year View" org-agenda-year-view
  2175. :active (org-agenda-check-type nil 'agenda)
  2176. :style radio :selected (eq org-agenda-current-span 'year)
  2177. :keys "v y"]
  2178. "--"
  2179. ["Include Diary" org-agenda-toggle-diary
  2180. :style toggle :selected org-agenda-include-diary
  2181. :active (org-agenda-check-type nil 'agenda)]
  2182. ["Include Deadlines" org-agenda-toggle-deadlines
  2183. :style toggle :selected org-agenda-include-deadlines
  2184. :active (org-agenda-check-type nil 'agenda)]
  2185. ["Use Time Grid" org-agenda-toggle-time-grid
  2186. :style toggle :selected org-agenda-use-time-grid
  2187. :active (org-agenda-check-type nil 'agenda)]
  2188. "--"
  2189. ["Show clock report" org-agenda-clockreport-mode
  2190. :style toggle :selected org-agenda-clockreport-mode
  2191. :active (org-agenda-check-type nil 'agenda)]
  2192. ["Show some entry text" org-agenda-entry-text-mode
  2193. :style toggle :selected org-agenda-entry-text-mode
  2194. :active t]
  2195. "--"
  2196. ["Show Logbook entries" org-agenda-log-mode
  2197. :style toggle :selected org-agenda-show-log
  2198. :active (org-agenda-check-type nil 'agenda)
  2199. :keys "v l (or just l)"]
  2200. ["Include archived trees" org-agenda-archives-mode
  2201. :style toggle :selected org-agenda-archives-mode :active t
  2202. :keys "v a"]
  2203. ["Include archive files" (org-agenda-archives-mode t)
  2204. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2205. :keys "v A"]
  2206. "--"
  2207. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2208. ("Filter current view"
  2209. ["with generic interface" org-agenda-filter t]
  2210. "--"
  2211. ["by category at cursor" org-agenda-filter-by-category t]
  2212. ["by tag" org-agenda-filter-by-tag t]
  2213. ["by effort" org-agenda-filter-by-effort t]
  2214. ["by regexp" org-agenda-filter-by-regexp t]
  2215. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2216. "--"
  2217. ["Remove all filtering" org-agenda-filter-remove-all t]
  2218. "--"
  2219. ["limit" org-agenda-limit-interactively t])
  2220. ["Rebuild buffer" org-agenda-redo t]
  2221. ["Write view to file" org-agenda-write t]
  2222. ["Save all Org buffers" org-save-all-org-buffers t]
  2223. "--"
  2224. ["Show original entry" org-agenda-show t]
  2225. ["Go To (other window)" org-agenda-goto t]
  2226. ["Go To (this window)" org-agenda-switch-to t]
  2227. ["Capture with cursor date" org-agenda-capture t]
  2228. ["Follow Mode" org-agenda-follow-mode
  2229. :style toggle :selected org-agenda-follow-mode :active t]
  2230. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2231. "--"
  2232. ("TODO"
  2233. ["Cycle TODO" org-agenda-todo t]
  2234. ["Next TODO set" org-agenda-todo-nextset t]
  2235. ["Previous TODO set" org-agenda-todo-previousset t]
  2236. ["Add note" org-agenda-add-note t])
  2237. ("Archive/Refile/Delete"
  2238. ["Archive default" org-agenda-archive-default t]
  2239. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2240. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2241. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2242. ["Archive subtree" org-agenda-archive t]
  2243. "--"
  2244. ["Refile" org-agenda-refile t]
  2245. "--"
  2246. ["Delete subtree" org-agenda-kill t])
  2247. ("Bulk action"
  2248. ["Mark entry" org-agenda-bulk-mark t]
  2249. ["Mark all" org-agenda-bulk-mark-all t]
  2250. ["Unmark entry" org-agenda-bulk-unmark t]
  2251. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2252. ["Toggle mark" org-agenda-bulk-toggle t]
  2253. ["Toggle all" org-agenda-bulk-toggle-all t]
  2254. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2255. ["Act on all marked" org-agenda-bulk-action t]
  2256. "--"
  2257. ("Tags and Properties"
  2258. ["Show all Tags" org-agenda-show-tags t]
  2259. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2260. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2261. "--"
  2262. ["Column View" org-columns t])
  2263. ("Deadline/Schedule"
  2264. ["Schedule" org-agenda-schedule t]
  2265. ["Set Deadline" org-agenda-deadline t]
  2266. "--"
  2267. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2268. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2269. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2270. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2271. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2272. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2273. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2274. ("Clock and Effort"
  2275. ["Clock in" org-agenda-clock-in t]
  2276. ["Clock out" org-agenda-clock-out t]
  2277. ["Clock cancel" org-agenda-clock-cancel t]
  2278. ["Goto running clock" org-clock-goto t]
  2279. "--"
  2280. ["Set Effort" org-agenda-set-effort t]
  2281. ["Change clocked effort" org-clock-modify-effort-estimate
  2282. (org-clock-is-active)])
  2283. ("Priority"
  2284. ["Set Priority" org-agenda-priority t]
  2285. ["Increase Priority" org-agenda-priority-up t]
  2286. ["Decrease Priority" org-agenda-priority-down t]
  2287. ["Show Priority" org-show-priority t])
  2288. ("Calendar/Diary"
  2289. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2290. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2291. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2292. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2293. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2294. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2295. "--"
  2296. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2297. "--"
  2298. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2299. "--"
  2300. ("MobileOrg"
  2301. ["Push Files and Views" org-mobile-push t]
  2302. ["Get Captured and Flagged" org-mobile-pull t]
  2303. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2304. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2305. "--"
  2306. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2307. "--"
  2308. ["Quit" org-agenda-quit t]
  2309. ["Exit and Release Buffers" org-agenda-exit t]
  2310. ))
  2311. ;;; Agenda undo
  2312. (defvar org-agenda-allow-remote-undo t
  2313. "Non-nil means allow remote undo from the agenda buffer.")
  2314. (defvar org-agenda-undo-has-started-in nil
  2315. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2316. (defun org-agenda-undo ()
  2317. "Undo a remote editing step in the agenda.
  2318. This undoes changes both in the agenda buffer and in the remote buffer
  2319. that have been changed along."
  2320. (interactive)
  2321. (or org-agenda-allow-remote-undo
  2322. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2323. (when (not (eq this-command last-command))
  2324. (setq org-agenda-undo-has-started-in nil
  2325. org-agenda-pending-undo-list org-agenda-undo-list))
  2326. (when (not org-agenda-pending-undo-list)
  2327. (user-error "No further undo information"))
  2328. (let* ((entry (pop org-agenda-pending-undo-list))
  2329. buf line cmd rembuf)
  2330. (setq cmd (pop entry) line (pop entry))
  2331. (setq rembuf (nth 2 entry))
  2332. (org-with-remote-undo rembuf
  2333. (while (bufferp (setq buf (pop entry)))
  2334. (when (pop entry)
  2335. (with-current-buffer buf
  2336. (let ((last-undo-buffer buf)
  2337. (inhibit-read-only t))
  2338. (unless (memq buf org-agenda-undo-has-started-in)
  2339. (push buf org-agenda-undo-has-started-in)
  2340. (make-local-variable 'pending-undo-list)
  2341. (undo-start))
  2342. (while (and pending-undo-list
  2343. (listp pending-undo-list)
  2344. (not (car pending-undo-list)))
  2345. (pop pending-undo-list))
  2346. (undo-more 1))))))
  2347. (org-goto-line line)
  2348. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2349. (defun org-verify-change-for-undo (l1 l2)
  2350. "Verify that a real change occurred between the undo lists L1 and L2."
  2351. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2352. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2353. (not (eq l1 l2)))
  2354. ;;; Agenda dispatch
  2355. (defvar org-agenda-restrict-begin (make-marker))
  2356. (defvar org-agenda-restrict-end (make-marker))
  2357. (defvar org-agenda-last-dispatch-buffer nil)
  2358. (defvar org-agenda-overriding-restriction nil)
  2359. (defcustom org-agenda-custom-commands-contexts nil
  2360. "Alist of custom agenda keys and contextual rules.
  2361. For example, if you have a custom agenda command \"p\" and you
  2362. want this command to be accessible only from plain text files,
  2363. use this:
  2364. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2365. Here are the available contexts definitions:
  2366. in-file: command displayed only in matching files
  2367. in-mode: command displayed only in matching modes
  2368. not-in-file: command not displayed in matching files
  2369. not-in-mode: command not displayed in matching modes
  2370. in-buffer: command displayed only in matching buffers
  2371. not-in-buffer: command not displayed in matching buffers
  2372. [function]: a custom function taking no argument
  2373. If you define several checks, the agenda command will be
  2374. accessible if there is at least one valid check.
  2375. You can also bind a key to another agenda custom command
  2376. depending on contextual rules.
  2377. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2378. Here it means: in .txt files, use \"p\" as the key for the
  2379. agenda command otherwise associated with \"q\". (The command
  2380. originally associated with \"q\" is not displayed to avoid
  2381. duplicates.)"
  2382. :version "24.3"
  2383. :group 'org-agenda-custom-commands
  2384. :type '(repeat (list :tag "Rule"
  2385. (string :tag " Agenda key")
  2386. (string :tag "Replace by command")
  2387. (repeat :tag "Available when"
  2388. (choice
  2389. (cons :tag "Condition"
  2390. (choice
  2391. (const :tag "In file" in-file)
  2392. (const :tag "Not in file" not-in-file)
  2393. (const :tag "In buffer" in-buffer)
  2394. (const :tag "Not in buffer" not-in-buffer)
  2395. (const :tag "In mode" in-mode)
  2396. (const :tag "Not in mode" not-in-mode))
  2397. (regexp))
  2398. (function :tag "Custom function"))))))
  2399. (defcustom org-agenda-max-entries nil
  2400. "Maximum number of entries to display in an agenda.
  2401. This can be nil (no limit) or an integer or an alist of agenda
  2402. types with an associated number of entries to display in this
  2403. type."
  2404. :version "24.4"
  2405. :package-version '(Org . "8.0")
  2406. :group 'org-agenda-custom-commands
  2407. :type '(choice (symbol :tag "No limit" nil)
  2408. (integer :tag "Max number of entries")
  2409. (repeat
  2410. (cons (choice :tag "Agenda type"
  2411. (const agenda)
  2412. (const todo)
  2413. (const tags)
  2414. (const search))
  2415. (integer :tag "Max number of entries")))))
  2416. (defcustom org-agenda-max-todos nil
  2417. "Maximum number of TODOs to display in an agenda.
  2418. This can be nil (no limit) or an integer or an alist of agenda
  2419. types with an associated number of entries to display in this
  2420. type."
  2421. :version "24.4"
  2422. :package-version '(Org . "8.0")
  2423. :group 'org-agenda-custom-commands
  2424. :type '(choice (symbol :tag "No limit" nil)
  2425. (integer :tag "Max number of TODOs")
  2426. (repeat
  2427. (cons (choice :tag "Agenda type"
  2428. (const agenda)
  2429. (const todo)
  2430. (const tags)
  2431. (const search))
  2432. (integer :tag "Max number of TODOs")))))
  2433. (defcustom org-agenda-max-tags nil
  2434. "Maximum number of tagged entries to display in an agenda.
  2435. This can be nil (no limit) or an integer or an alist of agenda
  2436. types with an associated number of entries to display in this
  2437. type."
  2438. :version "24.4"
  2439. :package-version '(Org . "8.0")
  2440. :group 'org-agenda-custom-commands
  2441. :type '(choice (symbol :tag "No limit" nil)
  2442. (integer :tag "Max number of tagged entries")
  2443. (repeat
  2444. (cons (choice :tag "Agenda type"
  2445. (const agenda)
  2446. (const todo)
  2447. (const tags)
  2448. (const search))
  2449. (integer :tag "Max number of tagged entries")))))
  2450. (defcustom org-agenda-max-effort nil
  2451. "Maximum cumulated effort duration for the agenda.
  2452. This can be nil (no limit) or a number of minutes (as an integer)
  2453. or an alist of agenda types with an associated number of minutes
  2454. to limit entries to in this type."
  2455. :version "24.4"
  2456. :package-version '(Org . "8.0")
  2457. :group 'org-agenda-custom-commands
  2458. :type '(choice (symbol :tag "No limit" nil)
  2459. (integer :tag "Max number of minutes")
  2460. (repeat
  2461. (cons (choice :tag "Agenda type"
  2462. (const agenda)
  2463. (const todo)
  2464. (const tags)
  2465. (const search))
  2466. (integer :tag "Max number of minutes")))))
  2467. (defvar org-agenda-keep-restricted-file-list nil)
  2468. (defvar org-keys nil)
  2469. (defvar org-match nil)
  2470. ;;;###autoload
  2471. (defun org-agenda (&optional arg org-keys restriction)
  2472. "Dispatch agenda commands to collect entries to the agenda buffer.
  2473. Prompts for a command to execute. Any prefix arg will be passed
  2474. on to the selected command. The default selections are:
  2475. a Call `org-agenda-list' to display the agenda for current day or week.
  2476. t Call `org-todo-list' to display the global todo list.
  2477. T Call `org-todo-list' to display the global todo list, select only
  2478. entries with a specific TODO keyword (the user gets a prompt).
  2479. m Call `org-tags-view' to display headlines with tags matching
  2480. a condition (the user is prompted for the condition).
  2481. M Like `m', but select only TODO entries, no ordinary headlines.
  2482. e Export views to associated files.
  2483. s Search entries for keywords.
  2484. S Search entries for keywords, only with TODO keywords.
  2485. / Multi occur across all agenda files and also files listed
  2486. in `org-agenda-text-search-extra-files'.
  2487. < Restrict agenda commands to buffer, subtree, or region.
  2488. Press several times to get the desired effect.
  2489. > Remove a previous restriction.
  2490. # List \"stuck\" projects.
  2491. ! Configure what \"stuck\" means.
  2492. C Configure custom agenda commands.
  2493. More commands can be added by configuring the variable
  2494. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2495. searches can be pre-defined in this way.
  2496. If the current buffer is in Org mode and visiting a file, you can also
  2497. first press `<' once to indicate that the agenda should be temporarily
  2498. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2499. Pressing `<' twice means to restrict to the current subtree or region
  2500. \(if active)."
  2501. (interactive "P")
  2502. (catch 'exit
  2503. (let* ((prefix-descriptions nil)
  2504. (org-agenda-buffer-name org-agenda-buffer-name)
  2505. (org-agenda-window-setup (if (equal (buffer-name)
  2506. org-agenda-buffer-name)
  2507. 'current-window
  2508. org-agenda-window-setup))
  2509. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2510. (org-agenda-custom-commands
  2511. ;; normalize different versions
  2512. (delq nil
  2513. (mapcar
  2514. (lambda (x)
  2515. (cond ((stringp (cdr x))
  2516. (push x prefix-descriptions)
  2517. nil)
  2518. ((stringp (nth 1 x)) x)
  2519. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2520. (t (cons (car x) (cons "" (cdr x))))))
  2521. org-agenda-custom-commands)))
  2522. (org-agenda-custom-commands
  2523. (org-contextualize-keys
  2524. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2525. (buf (current-buffer))
  2526. (bfn (buffer-file-name (buffer-base-buffer)))
  2527. entry key type org-match lprops ans)
  2528. ;; Turn off restriction unless there is an overriding one,
  2529. (unless org-agenda-overriding-restriction
  2530. (unless org-agenda-keep-restricted-file-list
  2531. ;; There is a request to keep the file list in place
  2532. (put 'org-agenda-files 'org-restrict nil))
  2533. (setq org-agenda-restrict nil)
  2534. (move-marker org-agenda-restrict-begin nil)
  2535. (move-marker org-agenda-restrict-end nil))
  2536. ;; Delete old local properties
  2537. (put 'org-agenda-redo-command 'org-lprops nil)
  2538. ;; Delete previously set last-arguments
  2539. (put 'org-agenda-redo-command 'last-args nil)
  2540. ;; Remember where this call originated
  2541. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2542. (unless org-keys
  2543. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2544. org-keys (car ans)
  2545. restriction (cdr ans)))
  2546. ;; If we have sticky agenda buffers, set a name for the buffer,
  2547. ;; depending on the invoking keys. The user may still set this
  2548. ;; as a command option, which will overwrite what we do here.
  2549. (when org-agenda-sticky
  2550. (setq org-agenda-buffer-name
  2551. (format "*Org Agenda(%s)*" org-keys)))
  2552. ;; Establish the restriction, if any
  2553. (when (and (not org-agenda-overriding-restriction) restriction)
  2554. (put 'org-agenda-files 'org-restrict (list bfn))
  2555. (cond
  2556. ((eq restriction 'region)
  2557. (setq org-agenda-restrict (current-buffer))
  2558. (move-marker org-agenda-restrict-begin (region-beginning))
  2559. (move-marker org-agenda-restrict-end (region-end)))
  2560. ((eq restriction 'subtree)
  2561. (save-excursion
  2562. (setq org-agenda-restrict (current-buffer))
  2563. (org-back-to-heading t)
  2564. (move-marker org-agenda-restrict-begin (point))
  2565. (move-marker org-agenda-restrict-end
  2566. (progn (org-end-of-subtree t)))))
  2567. ((and (eq restriction 'buffer)
  2568. (or (< 1 (point-min))
  2569. (< (point-max) (1+ (buffer-size)))))
  2570. (setq org-agenda-restrict (current-buffer))
  2571. (move-marker org-agenda-restrict-begin (point-min))
  2572. (move-marker org-agenda-restrict-end (point-max)))))
  2573. ;; For example the todo list should not need it (but does...)
  2574. (cond
  2575. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2576. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2577. (progn
  2578. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2579. lprops (nth 4 entry))
  2580. (when org-agenda-sticky
  2581. (setq org-agenda-buffer-name
  2582. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2583. (format "*Org Agenda(%s)*" org-keys))))
  2584. (put 'org-agenda-redo-command 'org-lprops lprops)
  2585. (cond
  2586. ((eq type 'agenda)
  2587. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2588. ((eq type 'agenda*)
  2589. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2590. ((eq type 'alltodo)
  2591. (org-let lprops '(org-todo-list current-prefix-arg)))
  2592. ((eq type 'search)
  2593. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2594. ((eq type 'stuck)
  2595. (org-let lprops '(org-agenda-list-stuck-projects
  2596. current-prefix-arg)))
  2597. ((eq type 'tags)
  2598. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2599. ((eq type 'tags-todo)
  2600. (org-let lprops '(org-tags-view '(4) org-match)))
  2601. ((eq type 'todo)
  2602. (org-let lprops '(org-todo-list org-match)))
  2603. ((eq type 'tags-tree)
  2604. (org-check-for-org-mode)
  2605. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2606. ((eq type 'todo-tree)
  2607. (org-check-for-org-mode)
  2608. (org-let lprops
  2609. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2610. (regexp-quote org-match) "\\>"))))
  2611. ((eq type 'occur-tree)
  2612. (org-check-for-org-mode)
  2613. (org-let lprops '(org-occur org-match)))
  2614. ((functionp type)
  2615. (org-let lprops '(funcall type org-match)))
  2616. ((fboundp type)
  2617. (org-let lprops '(funcall type org-match)))
  2618. (t (user-error "Invalid custom agenda command type %s" type))))
  2619. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2620. ((equal org-keys "C")
  2621. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2622. (customize-variable 'org-agenda-custom-commands))
  2623. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2624. ((equal org-keys "s") (call-interactively 'org-search-view))
  2625. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2626. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2627. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2628. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2629. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2630. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2631. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2632. (add-hook
  2633. 'post-command-hook
  2634. (lambda ()
  2635. (unless (current-message)
  2636. (let* ((m (org-agenda-get-any-marker))
  2637. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2638. (when note
  2639. (message "FLAGGING-NOTE ([?] for more info): %s"
  2640. (org-add-props
  2641. (replace-regexp-in-string
  2642. "\\\\n" "//"
  2643. (copy-sequence note))
  2644. nil 'face 'org-warning))))))
  2645. t t))
  2646. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2647. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2648. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2649. (t (user-error "Invalid agenda key"))))))
  2650. (defvar org-agenda-multi)
  2651. (defun org-agenda-append-agenda ()
  2652. "Append another agenda view to the current one.
  2653. This function allows interactive building of block agendas.
  2654. Agenda views are separated by `org-agenda-block-separator'."
  2655. (interactive)
  2656. (unless (derived-mode-p 'org-agenda-mode)
  2657. (user-error "Can only append from within agenda buffer"))
  2658. (let ((org-agenda-multi t))
  2659. (org-agenda)
  2660. (widen)
  2661. (org-agenda-finalize)
  2662. (setq buffer-read-only t)
  2663. (org-agenda-fit-window-to-buffer)))
  2664. (defun org-agenda-normalize-custom-commands (cmds)
  2665. "Normalize custom commands CMDS."
  2666. (delq nil
  2667. (mapcar
  2668. (lambda (x)
  2669. (cond ((stringp (cdr x)) nil)
  2670. ((stringp (nth 1 x)) x)
  2671. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2672. (t (cons (car x) (cons "" (cdr x))))))
  2673. cmds)))
  2674. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2675. "The user interface for selecting an agenda command."
  2676. (catch 'exit
  2677. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2678. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2679. (region-p (org-region-active-p))
  2680. (custom org-agenda-custom-commands)
  2681. (selstring "")
  2682. restriction second-time
  2683. c entry key type match prefixes rmheader header-end custom1 desc
  2684. line lines left right n n1)
  2685. (save-window-excursion
  2686. (delete-other-windows)
  2687. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2688. (erase-buffer)
  2689. (insert (eval-when-compile
  2690. (let ((header
  2691. "Press key for an agenda command:
  2692. -------------------------------- < Buffer, subtree/region restriction
  2693. a Agenda for current week or day > Remove restriction
  2694. t List of all TODO entries e Export agenda views
  2695. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2696. s Search for keywords M Like m, but only TODO entries
  2697. / Multi-occur S Like s, but only TODO entries
  2698. ? Find :FLAGGED: entries C Configure custom agenda commands
  2699. * Toggle sticky agenda views # List stuck projects (!=configure)
  2700. ")
  2701. (start 0))
  2702. (while (string-match
  2703. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2704. header start)
  2705. (setq start (match-end 0))
  2706. (add-text-properties (match-beginning 2) (match-end 2)
  2707. '(face bold) header))
  2708. header)))
  2709. (setq header-end (point-marker))
  2710. (while t
  2711. (setq custom1 custom)
  2712. (when (eq rmheader t)
  2713. (org-goto-line 1)
  2714. (re-search-forward ":" nil t)
  2715. (delete-region (match-end 0) (point-at-eol))
  2716. (forward-char 1)
  2717. (looking-at "-+")
  2718. (delete-region (match-end 0) (point-at-eol))
  2719. (move-marker header-end (match-end 0)))
  2720. (goto-char header-end)
  2721. (delete-region (point) (point-max))
  2722. ;; Produce all the lines that describe custom commands and prefixes
  2723. (setq lines nil)
  2724. (while (setq entry (pop custom1))
  2725. (setq key (car entry) desc (nth 1 entry)
  2726. type (nth 2 entry)
  2727. match (nth 3 entry))
  2728. (if (> (length key) 1)
  2729. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2730. (setq line
  2731. (format
  2732. "%-4s%-14s"
  2733. (org-add-props (copy-sequence key)
  2734. '(face bold))
  2735. (cond
  2736. ((string-match "\\S-" desc) desc)
  2737. ((eq type 'agenda) "Agenda for current week or day")
  2738. ((eq type 'agenda*) "Appointments for current week or day")
  2739. ((eq type 'alltodo) "List of all TODO entries")
  2740. ((eq type 'search) "Word search")
  2741. ((eq type 'stuck) "List of stuck projects")
  2742. ((eq type 'todo) "TODO keyword")
  2743. ((eq type 'tags) "Tags query")
  2744. ((eq type 'tags-todo) "Tags (TODO)")
  2745. ((eq type 'tags-tree) "Tags tree")
  2746. ((eq type 'todo-tree) "TODO kwd tree")
  2747. ((eq type 'occur-tree) "Occur tree")
  2748. ((functionp type) (if (symbolp type)
  2749. (symbol-name type)
  2750. "Lambda expression"))
  2751. (t "???"))))
  2752. (cond
  2753. ((not (org-string-nw-p match)) nil)
  2754. (org-agenda-menu-show-matcher
  2755. (setq line
  2756. (concat line ": "
  2757. (cond
  2758. ((stringp match)
  2759. (propertize match 'face 'org-warning))
  2760. ((listp type)
  2761. (format "set of %d commands" (length type)))))))
  2762. (t
  2763. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2764. (push line lines)))
  2765. (setq lines (nreverse lines))
  2766. (when prefixes
  2767. (mapc (lambda (x)
  2768. (push
  2769. (format "%s %s"
  2770. (org-add-props (char-to-string x)
  2771. nil 'face 'bold)
  2772. (or (cdr (assoc (concat selstring
  2773. (char-to-string x))
  2774. prefix-descriptions))
  2775. "Prefix key"))
  2776. lines))
  2777. prefixes))
  2778. ;; Check if we should display in two columns
  2779. (if org-agenda-menu-two-columns
  2780. (progn
  2781. (setq n (length lines)
  2782. n1 (+ (/ n 2) (mod n 2))
  2783. right (nthcdr n1 lines)
  2784. left (copy-sequence lines))
  2785. (setcdr (nthcdr (1- n1) left) nil))
  2786. (setq left lines right nil))
  2787. (while left
  2788. (insert "\n" (pop left))
  2789. (when right
  2790. (if (< (current-column) 40)
  2791. (move-to-column 40 t)
  2792. (insert " "))
  2793. (insert (pop right))))
  2794. ;; Make the window the right size
  2795. (goto-char (point-min))
  2796. (if second-time
  2797. (when (not (pos-visible-in-window-p (point-max)))
  2798. (org-fit-window-to-buffer))
  2799. (setq second-time t)
  2800. (org-fit-window-to-buffer))
  2801. ;; Hint to navigation if window too small for all information
  2802. (setq header-line-format
  2803. (when (not (pos-visible-in-window-p (point-max)))
  2804. "Use SPC, DEL, C-n or C-p to navigate."))
  2805. ;; Ask for selection
  2806. (cl-loop
  2807. do (progn
  2808. (message "Press key for agenda command%s:"
  2809. (if (or restrict-ok org-agenda-overriding-restriction)
  2810. (if org-agenda-overriding-restriction
  2811. " (restriction lock active)"
  2812. (if restriction
  2813. (format " (restricted to %s)" restriction)
  2814. " (unrestricted)"))
  2815. ""))
  2816. (setq c (read-char-exclusive)))
  2817. until (not (memq c '(14 16 ?\s ?\d)))
  2818. do (cl-case c
  2819. (14 (if (not (pos-visible-in-window-p (point-max)))
  2820. (ignore-errors (scroll-up 1))
  2821. (message "End of buffer")
  2822. (sit-for 1)))
  2823. (16 (if (not (pos-visible-in-window-p (point-min)))
  2824. (ignore-errors (scroll-down 1))
  2825. (message "Beginning of buffer")
  2826. (sit-for 1)))
  2827. (?\s (if (not (pos-visible-in-window-p (point-max)))
  2828. (scroll-up nil)
  2829. (message "End of buffer")
  2830. (sit-for 1)))
  2831. (?\d (if (not (pos-visible-in-window-p (point-min)))
  2832. (scroll-down nil)
  2833. (message "Beginning of buffer")
  2834. (sit-for 1)))))
  2835. (message "")
  2836. (cond
  2837. ((assoc (char-to-string c) custom)
  2838. (setq selstring (concat selstring (char-to-string c)))
  2839. (throw 'exit (cons selstring restriction)))
  2840. ((memq c prefixes)
  2841. (setq selstring (concat selstring (char-to-string c))
  2842. prefixes nil
  2843. rmheader (or rmheader t)
  2844. custom (delq nil (mapcar
  2845. (lambda (x)
  2846. (if (or (= (length (car x)) 1)
  2847. (/= (string-to-char (car x)) c))
  2848. nil
  2849. (cons (substring (car x) 1) (cdr x))))
  2850. custom))))
  2851. ((eq c ?*)
  2852. (call-interactively 'org-toggle-sticky-agenda)
  2853. (sit-for 2))
  2854. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2855. (message "Restriction is only possible in Org buffers")
  2856. (ding) (sit-for 1))
  2857. ((eq c ?1)
  2858. (org-agenda-remove-restriction-lock 'noupdate)
  2859. (setq restriction 'buffer))
  2860. ((eq c ?0)
  2861. (org-agenda-remove-restriction-lock 'noupdate)
  2862. (setq restriction (if region-p 'region 'subtree)))
  2863. ((eq c ?<)
  2864. (org-agenda-remove-restriction-lock 'noupdate)
  2865. (setq restriction
  2866. (cond
  2867. ((eq restriction 'buffer)
  2868. (if region-p 'region 'subtree))
  2869. ((memq restriction '(subtree region))
  2870. nil)
  2871. (t 'buffer))))
  2872. ((eq c ?>)
  2873. (org-agenda-remove-restriction-lock 'noupdate)
  2874. (setq restriction nil))
  2875. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2876. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2877. ((and (> (length selstring) 0) (eq c ?\d))
  2878. (delete-window)
  2879. (org-agenda-get-restriction-and-command prefix-descriptions))
  2880. ((equal c ?q) (error "Abort"))
  2881. (t (user-error "Invalid key %c" c))))))))
  2882. (defun org-agenda-fit-window-to-buffer ()
  2883. "Fit the window to the buffer size."
  2884. (and (memq org-agenda-window-setup '(reorganize-frame))
  2885. (fboundp 'fit-window-to-buffer)
  2886. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2887. (= (car org-agenda-window-frame-fractions) 1.0))
  2888. (delete-other-windows)
  2889. (org-fit-window-to-buffer
  2890. nil
  2891. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2892. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2893. (defvar org-cmd nil)
  2894. (defvar org-agenda-overriding-cmd nil)
  2895. (defvar org-agenda-overriding-arguments nil)
  2896. (defvar org-agenda-overriding-cmd-arguments nil)
  2897. (defun org-agenda-run-series (name series)
  2898. "Run agenda NAME as a SERIES of agenda commands."
  2899. (org-let (nth 1 series) '(org-agenda-prepare name))
  2900. ;; We need to reset agenda markers here, because when constructing a
  2901. ;; block agenda, the individual blocks do not do that.
  2902. (org-agenda-reset-markers)
  2903. (let* ((org-agenda-multi t)
  2904. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2905. (cmds (car series))
  2906. (gprops (nth 1 series))
  2907. match ;; The byte compiler incorrectly complains about this. Keep it!
  2908. org-cmd type lprops)
  2909. (while (setq org-cmd (pop cmds))
  2910. (setq type (car org-cmd))
  2911. (setq match (eval (nth 1 org-cmd)))
  2912. (setq lprops (nth 2 org-cmd))
  2913. (let ((org-agenda-overriding-arguments
  2914. (if (eq org-agenda-overriding-cmd org-cmd)
  2915. (or org-agenda-overriding-arguments
  2916. org-agenda-overriding-cmd-arguments))))
  2917. (cond
  2918. ((eq type 'agenda)
  2919. (org-let2 gprops lprops
  2920. '(call-interactively 'org-agenda-list)))
  2921. ((eq type 'agenda*)
  2922. (org-let2 gprops lprops
  2923. '(funcall 'org-agenda-list nil nil t)))
  2924. ((eq type 'alltodo)
  2925. (org-let2 gprops lprops
  2926. '(call-interactively 'org-todo-list)))
  2927. ((eq type 'search)
  2928. (org-let2 gprops lprops
  2929. '(org-search-view current-prefix-arg match nil)))
  2930. ((eq type 'stuck)
  2931. (org-let2 gprops lprops
  2932. '(call-interactively 'org-agenda-list-stuck-projects)))
  2933. ((eq type 'tags)
  2934. (org-let2 gprops lprops
  2935. '(org-tags-view current-prefix-arg match)))
  2936. ((eq type 'tags-todo)
  2937. (org-let2 gprops lprops
  2938. '(org-tags-view '(4) match)))
  2939. ((eq type 'todo)
  2940. (org-let2 gprops lprops
  2941. '(org-todo-list match)))
  2942. ((fboundp type)
  2943. (org-let2 gprops lprops
  2944. '(funcall type match)))
  2945. (t (error "Invalid type in command series")))))
  2946. (widen)
  2947. (let ((inhibit-read-only t))
  2948. (add-text-properties (point-min) (point-max)
  2949. `(org-series t org-series-redo-cmd ,redo)))
  2950. (setq org-agenda-redo-command redo)
  2951. (goto-char (point-min)))
  2952. (org-agenda-fit-window-to-buffer)
  2953. (org-let (nth 1 series) '(org-agenda-finalize)))
  2954. ;;;###autoload
  2955. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2956. "Run an agenda command in batch mode and send the result to STDOUT.
  2957. If CMD-KEY is a string of length 1, it is used as a key in
  2958. `org-agenda-custom-commands' and triggers this command. If it is a
  2959. longer string it is used as a tags/todo match string.
  2960. Parameters are alternating variable names and values that will be bound
  2961. before running the agenda command."
  2962. (org-eval-in-environment (org-make-parameter-alist parameters)
  2963. (let (org-agenda-sticky)
  2964. (if (> (length cmd-key) 1)
  2965. (org-tags-view nil cmd-key)
  2966. (org-agenda nil cmd-key))))
  2967. (set-buffer org-agenda-buffer-name)
  2968. (princ (buffer-string)))
  2969. (defvar org-agenda-info nil)
  2970. ;;;###autoload
  2971. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2972. "Run an agenda command in batch mode and send the result to STDOUT.
  2973. If CMD-KEY is a string of length 1, it is used as a key in
  2974. `org-agenda-custom-commands' and triggers this command. If it is a
  2975. longer string it is used as a tags/todo match string.
  2976. Parameters are alternating variable names and values that will be bound
  2977. before running the agenda command.
  2978. The output gives a line for each selected agenda item. Each
  2979. item is a list of comma-separated values, like this:
  2980. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2981. category The category of the item
  2982. head The headline, without TODO kwd, TAGS and PRIORITY
  2983. type The type of the agenda entry, can be
  2984. todo selected in TODO match
  2985. tagsmatch selected in tags match
  2986. diary imported from diary
  2987. deadline a deadline on given date
  2988. scheduled scheduled on given date
  2989. timestamp entry has timestamp on given date
  2990. closed entry was closed on given date
  2991. upcoming-deadline warning about deadline
  2992. past-scheduled forwarded scheduled item
  2993. block entry has date block including g. date
  2994. todo The todo keyword, if any
  2995. tags All tags including inherited ones, separated by colons
  2996. date The relevant date, like 2007-2-14
  2997. time The time, like 15:00-16:50
  2998. extra String with extra planning info
  2999. priority-l The priority letter if any was given
  3000. priority-n The computed numerical priority
  3001. agenda-day The day in the agenda where this is listed"
  3002. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  3003. (org-make-parameter-alist parameters))
  3004. (if (> (length cmd-key) 2)
  3005. (org-tags-view nil cmd-key)
  3006. (org-agenda nil cmd-key)))
  3007. (set-buffer org-agenda-buffer-name)
  3008. (let ((lines (org-split-string (buffer-string) "\n")))
  3009. (dolist (line lines)
  3010. (when (get-text-property 0 'org-category line)
  3011. (setq org-agenda-info
  3012. (org-fix-agenda-info (text-properties-at 0 line)))
  3013. (princ
  3014. (mapconcat 'org-agenda-export-csv-mapper
  3015. '(org-category txt type todo tags date time extra
  3016. priority-letter priority agenda-day)
  3017. ","))
  3018. (princ "\n")))))
  3019. (defun org-fix-agenda-info (props)
  3020. "Make sure all properties on an agenda item have a canonical form.
  3021. This ensures the export commands can easily use it."
  3022. (let (tmp re)
  3023. (when (setq tmp (plist-get props 'tags))
  3024. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  3025. (when (setq tmp (plist-get props 'date))
  3026. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3027. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3028. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3029. (setq tmp (calendar-date-string tmp)))
  3030. (setq props (plist-put props 'date tmp)))
  3031. (when (setq tmp (plist-get props 'day))
  3032. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3033. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3034. (setq tmp (calendar-date-string tmp)))
  3035. (setq props (plist-put props 'day tmp))
  3036. (setq props (plist-put props 'agenda-day tmp)))
  3037. (when (setq tmp (plist-get props 'txt))
  3038. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3039. (plist-put props 'priority-letter (match-string 1 tmp))
  3040. (setq tmp (replace-match "" t t tmp)))
  3041. (when (and (setq re (plist-get props 'org-todo-regexp))
  3042. (setq re (concat "\\`\\.*" re " ?"))
  3043. (let ((case-fold-search nil)) (string-match re tmp)))
  3044. (plist-put props 'todo (match-string 1 tmp))
  3045. (setq tmp (replace-match "" t t tmp)))
  3046. (plist-put props 'txt tmp)))
  3047. props)
  3048. (defun org-agenda-export-csv-mapper (prop)
  3049. (let ((res (plist-get org-agenda-info prop)))
  3050. (setq res
  3051. (cond
  3052. ((not res) "")
  3053. ((stringp res) res)
  3054. (t (prin1-to-string res))))
  3055. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3056. ;;;###autoload
  3057. (defun org-store-agenda-views (&rest parameters)
  3058. "Store agenda views."
  3059. (interactive)
  3060. (eval (list 'org-batch-store-agenda-views)))
  3061. ;;;###autoload
  3062. (defmacro org-batch-store-agenda-views (&rest parameters)
  3063. "Run all custom agenda commands that have a file argument."
  3064. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3065. (pop-up-frames nil)
  3066. (dir default-directory)
  3067. (pars (org-make-parameter-alist parameters))
  3068. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3069. (save-window-excursion
  3070. (while cmds
  3071. (setq cmd (pop cmds)
  3072. thiscmdkey (car cmd)
  3073. thiscmdcmd (cdr cmd)
  3074. match (nth 2 thiscmdcmd)
  3075. bufname (if org-agenda-sticky
  3076. (or (and (stringp match)
  3077. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3078. (format "*Org Agenda(%s)*" thiscmdkey))
  3079. org-agenda-buffer-name)
  3080. cmd-or-set (nth 2 cmd)
  3081. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3082. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3083. (if (stringp files) (setq files (list files)))
  3084. (when files
  3085. (org-eval-in-environment (append org-agenda-exporter-settings
  3086. opts pars)
  3087. (org-agenda nil thiscmdkey))
  3088. (set-buffer bufname)
  3089. (while files
  3090. (org-eval-in-environment (append org-agenda-exporter-settings
  3091. opts pars)
  3092. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  3093. (and (get-buffer bufname)
  3094. (kill-buffer bufname)))))))
  3095. (defvar org-agenda-current-span nil
  3096. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3097. (defun org-agenda-mark-header-line (pos)
  3098. "Mark the line at POS as an agenda structure header."
  3099. (save-excursion
  3100. (goto-char pos)
  3101. (put-text-property (point-at-bol) (point-at-eol)
  3102. 'org-agenda-structural-header t)
  3103. (when org-agenda-title-append
  3104. (put-text-property (point-at-bol) (point-at-eol)
  3105. 'org-agenda-title-append org-agenda-title-append))))
  3106. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3107. (defvar org-agenda-write-buffer-name "Agenda View")
  3108. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3109. "Write the current buffer (an agenda view) as a file.
  3110. Depending on the extension of the file name, plain text (.txt),
  3111. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3112. If the extension is .ics, translate visible agenda into iCalendar
  3113. format. If the extension is .org, collect all subtrees
  3114. corresponding to the agenda entries and add them in an .org file.
  3115. With prefix argument OPEN, open the new file immediately. If
  3116. NOSETTINGS is given, do not scope the settings of
  3117. `org-agenda-exporter-settings' into the export commands. This is
  3118. used when the settings have already been scoped and we do not
  3119. wish to overrule other, higher priority settings. If
  3120. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3121. the agenda to write."
  3122. (interactive "FWrite agenda to file: \nP")
  3123. (if (or (not (file-writable-p file))
  3124. (and (file-exists-p file)
  3125. (if (called-interactively-p 'any)
  3126. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3127. (user-error "Cannot write agenda to file %s" file))
  3128. (org-let (if nosettings nil org-agenda-exporter-settings)
  3129. '(save-excursion
  3130. (save-window-excursion
  3131. (let ((bs (copy-sequence (buffer-string)))
  3132. (extension (file-name-extension file))
  3133. (default-directory (file-name-directory file))
  3134. beg content)
  3135. (with-temp-buffer
  3136. (rename-buffer org-agenda-write-buffer-name t)
  3137. (set-buffer-modified-p nil)
  3138. (insert bs)
  3139. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3140. (run-hooks 'org-agenda-before-write-hook)
  3141. (cond
  3142. ((bound-and-true-p org-mobile-creating-agendas)
  3143. (org-mobile-write-agenda-for-mobile file))
  3144. ((string= "org" extension)
  3145. (let (content p m message-log-max)
  3146. (goto-char (point-min))
  3147. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3148. (goto-char p)
  3149. (setq m (get-text-property (point) 'org-hd-marker))
  3150. (when m
  3151. (push (save-excursion
  3152. (set-buffer (marker-buffer m))
  3153. (goto-char m)
  3154. (org-copy-subtree 1 nil t t)
  3155. org-subtree-clip)
  3156. content)))
  3157. (find-file file)
  3158. (erase-buffer)
  3159. (dolist (s content) (org-paste-subtree 1 s))
  3160. (write-file file)
  3161. (kill-buffer (current-buffer))
  3162. (message "Org file written to %s" file)))
  3163. ((member extension '("html" "htm"))
  3164. (or (require 'htmlize nil t)
  3165. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3166. (set-buffer (htmlize-buffer (current-buffer)))
  3167. (when org-agenda-export-html-style
  3168. ;; replace <style> section with org-agenda-export-html-style
  3169. (goto-char (point-min))
  3170. (kill-region (- (search-forward "<style") 6)
  3171. (search-forward "</style>"))
  3172. (insert org-agenda-export-html-style))
  3173. (write-file file)
  3174. (kill-buffer (current-buffer))
  3175. (message "HTML written to %s" file))
  3176. ((string= "ps" extension)
  3177. (require 'ps-print)
  3178. (ps-print-buffer-with-faces file)
  3179. (message "Postscript written to %s" file))
  3180. ((string= "pdf" extension)
  3181. (require 'ps-print)
  3182. (ps-print-buffer-with-faces
  3183. (concat (file-name-sans-extension file) ".ps"))
  3184. (call-process "ps2pdf" nil nil nil
  3185. (expand-file-name
  3186. (concat (file-name-sans-extension file) ".ps"))
  3187. (expand-file-name file))
  3188. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3189. (message "PDF written to %s" file))
  3190. ((string= "ics" extension)
  3191. (require 'ox-icalendar)
  3192. (org-icalendar-export-current-agenda (expand-file-name file)))
  3193. (t
  3194. (let ((bs (buffer-string)))
  3195. (find-file file)
  3196. (erase-buffer)
  3197. (insert bs)
  3198. (save-buffer 0)
  3199. (kill-buffer (current-buffer))
  3200. (message "Plain text written to %s" file))))))))
  3201. (set-buffer (or agenda-bufname
  3202. (and (called-interactively-p 'any) (buffer-name))
  3203. org-agenda-buffer-name)))
  3204. (when open (org-open-file file)))
  3205. (defun org-agenda-remove-marked-text (property &optional value)
  3206. "Delete all text marked with VALUE of PROPERTY.
  3207. VALUE defaults to t."
  3208. (let (beg)
  3209. (setq value (or value t))
  3210. (while (setq beg (text-property-any (point-min) (point-max)
  3211. property value))
  3212. (delete-region
  3213. beg (or (next-single-property-change beg property)
  3214. (point-max))))))
  3215. (defun org-agenda-add-entry-text ()
  3216. "Add entry text to agenda lines.
  3217. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3218. entry text following headings shown in the agenda.
  3219. Drawers will be excluded, also the line with scheduling/deadline info."
  3220. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3221. (not (bound-and-true-p org-mobile-creating-agendas)))
  3222. (let (m txt)
  3223. (goto-char (point-min))
  3224. (while (not (eobp))
  3225. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3226. (beginning-of-line 2)
  3227. (setq txt (org-agenda-get-some-entry-text
  3228. m org-agenda-add-entry-text-maxlines " > "))
  3229. (end-of-line 1)
  3230. (if (string-match "\\S-" txt)
  3231. (insert "\n" txt)
  3232. (or (eobp) (forward-char 1))))))))
  3233. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3234. &rest keep)
  3235. "Extract entry text from MARKER, at most N-LINES lines.
  3236. This will ignore drawers etc, just get the text.
  3237. If INDENT is given, prefix every line with this string. If KEEP is
  3238. given, it is a list of symbols, defining stuff that should not be
  3239. removed from the entry content. Currently only `planning' is allowed here."
  3240. (let (txt drawer-re kwd-time-re ind)
  3241. (save-excursion
  3242. (with-current-buffer (marker-buffer marker)
  3243. (if (not (derived-mode-p 'org-mode))
  3244. (setq txt "")
  3245. (org-with-wide-buffer
  3246. (goto-char marker)
  3247. (end-of-line 1)
  3248. (setq txt (buffer-substring
  3249. (min (1+ (point)) (point-max))
  3250. (progn (outline-next-heading) (point)))
  3251. drawer-re org-drawer-regexp
  3252. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3253. ".*\n?"))
  3254. (with-temp-buffer
  3255. (insert txt)
  3256. (when org-agenda-add-entry-text-descriptive-links
  3257. (goto-char (point-min))
  3258. (while (org-activate-links (point-max))
  3259. (add-text-properties (match-beginning 0) (match-end 0)
  3260. '(face org-link))))
  3261. (goto-char (point-min))
  3262. (while (re-search-forward org-link-bracket-re (point-max) t)
  3263. (set-text-properties (match-beginning 0) (match-end 0)
  3264. nil))
  3265. (goto-char (point-min))
  3266. (while (re-search-forward drawer-re nil t)
  3267. (delete-region
  3268. (match-beginning 0)
  3269. (progn (re-search-forward
  3270. "^[ \t]*:END:.*\n?" nil 'move)
  3271. (point))))
  3272. (unless (member 'planning keep)
  3273. (goto-char (point-min))
  3274. (while (re-search-forward kwd-time-re nil t)
  3275. (replace-match "")))
  3276. (goto-char (point-min))
  3277. (when org-agenda-entry-text-exclude-regexps
  3278. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3279. (while (setq re (pop re-list))
  3280. (goto-char (point-min))
  3281. (while (re-search-forward re nil t)
  3282. (replace-match "")))))
  3283. (goto-char (point-max))
  3284. (skip-chars-backward " \t\n")
  3285. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3286. ;; find and remove min common indentation
  3287. (goto-char (point-min))
  3288. (untabify (point-min) (point-max))
  3289. (setq ind (current-indentation))
  3290. (while (not (eobp))
  3291. (unless (looking-at "[ \t]*$")
  3292. (setq ind (min ind (current-indentation))))
  3293. (beginning-of-line 2))
  3294. (goto-char (point-min))
  3295. (while (not (eobp))
  3296. (unless (looking-at "[ \t]*$")
  3297. (move-to-column ind)
  3298. (delete-region (point-at-bol) (point)))
  3299. (beginning-of-line 2))
  3300. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3301. (goto-char (point-min))
  3302. (when indent
  3303. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3304. (replace-match indent t t)))
  3305. (goto-char (point-min))
  3306. (while (looking-at "[ \t]*\n") (replace-match ""))
  3307. (goto-char (point-max))
  3308. (when (> (org-current-line)
  3309. n-lines)
  3310. (org-goto-line (1+ n-lines))
  3311. (backward-char 1))
  3312. (setq txt (buffer-substring (point-min) (point))))))))
  3313. txt))
  3314. (defun org-check-for-org-mode ()
  3315. "Make sure current buffer is in Org mode. Error if not."
  3316. (or (derived-mode-p 'org-mode)
  3317. (error "Cannot execute Org agenda command on buffer in %s"
  3318. major-mode)))
  3319. ;;; Agenda prepare and finalize
  3320. (defvar org-agenda-multi nil) ; dynamically scoped
  3321. (defvar org-agenda-pre-window-conf nil)
  3322. (defvar org-agenda-columns-active nil)
  3323. (defvar org-agenda-name nil)
  3324. (defvar org-agenda-tag-filter nil)
  3325. (defvar org-agenda-category-filter nil)
  3326. (defvar org-agenda-regexp-filter nil)
  3327. (defvar org-agenda-effort-filter nil)
  3328. (defvar org-agenda-top-headline-filter nil)
  3329. (defvar org-agenda-represented-categories nil
  3330. "Cache for the list of all categories in the agenda.")
  3331. (defvar org-agenda-represented-tags nil
  3332. "Cache for the list of all categories in the agenda.")
  3333. (defvar org-agenda-tag-filter-preset nil
  3334. "A preset of the tags filter used for secondary agenda filtering.
  3335. This must be a list of strings, each string must be a single tag preceded
  3336. by \"+\" or \"-\".
  3337. This variable should not be set directly, but agenda custom commands can
  3338. bind it in the options section. The preset filter is a global property of
  3339. the entire agenda view. In a block agenda, it will not work reliably to
  3340. define a filter for one of the individual blocks. You need to set it in
  3341. the global options and expect it to be applied to the entire view.")
  3342. (defconst org-agenda-filter-variables
  3343. '((category . org-agenda-category-filter)
  3344. (tag . org-agenda-tag-filter)
  3345. (effort . org-agenda-effort-filter)
  3346. (regexp . org-agenda-regexp-filter))
  3347. "Alist of filter types and associated variables")
  3348. (defun org-agenda-filter-any ()
  3349. "Is any filter active?"
  3350. (let ((form (cons 'or (mapcar (lambda (x)
  3351. (if (or (symbol-value (cdr x))
  3352. (get :preset-filter x))
  3353. t nil))
  3354. org-agenda-filter-variables))))
  3355. (eval form)))
  3356. (defvar org-agenda-category-filter-preset nil
  3357. "A preset of the category filter used for secondary agenda filtering.
  3358. This must be a list of strings, each string must be a single category
  3359. preceded by \"+\" or \"-\".
  3360. This variable should not be set directly, but agenda custom commands can
  3361. bind it in the options section. The preset filter is a global property of
  3362. the entire agenda view. In a block agenda, it will not work reliably to
  3363. define a filter for one of the individual blocks. You need to set it in
  3364. the global options and expect it to be applied to the entire view.")
  3365. (defvar org-agenda-regexp-filter-preset nil
  3366. "A preset of the regexp filter used for secondary agenda filtering.
  3367. This must be a list of strings, each string must be a single regexp
  3368. preceded by \"+\" or \"-\".
  3369. This variable should not be set directly, but agenda custom commands can
  3370. bind it in the options section. The preset filter is a global property of
  3371. the entire agenda view. In a block agenda, it will not work reliably to
  3372. define a filter for one of the individual blocks. You need to set it in
  3373. the global options and expect it to be applied to the entire view.")
  3374. (defvar org-agenda-effort-filter-preset nil
  3375. "A preset of the effort condition used for secondary agenda filtering.
  3376. This must be a list of strings, each string must be a single regexp
  3377. preceded by \"+\" or \"-\".
  3378. This variable should not be set directly, but agenda custom commands can
  3379. bind it in the options section. The preset filter is a global property of
  3380. the entire agenda view. In a block agenda, it will not work reliably to
  3381. define a filter for one of the individual blocks. You need to set it in
  3382. the global options and expect it to be applied to the entire view.")
  3383. (defun org-agenda-use-sticky-p ()
  3384. "Return non-nil if an agenda buffer named
  3385. `org-agenda-buffer-name' exists and should be shown instead of
  3386. generating a new one."
  3387. (and
  3388. ;; turned off by user
  3389. org-agenda-sticky
  3390. ;; For multi-agenda buffer already exists
  3391. (not org-agenda-multi)
  3392. ;; buffer found
  3393. (get-buffer org-agenda-buffer-name)
  3394. ;; C-u parameter is same as last call
  3395. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3396. (and
  3397. (equal current-prefix-arg
  3398. org-agenda-last-prefix-arg)
  3399. ;; In case user turned stickiness on, while having existing
  3400. ;; Agenda buffer active, don't reuse that buffer, because it
  3401. ;; does not have org variables local
  3402. org-agenda-this-buffer-is-sticky))))
  3403. (defun org-agenda-prepare-window (abuf filter-alist)
  3404. "Setup agenda buffer in the window.
  3405. ABUF is the buffer for the agenda window.
  3406. FILTER-ALIST is an alist of filters we need to apply when
  3407. `org-agenda-persistent-filter' is non-nil."
  3408. (let* ((awin (get-buffer-window abuf)) wconf)
  3409. (cond
  3410. ((equal (current-buffer) abuf) nil)
  3411. (awin (select-window awin))
  3412. ((not (setq wconf (current-window-configuration))))
  3413. ((eq org-agenda-window-setup 'current-window)
  3414. (pop-to-buffer-same-window abuf))
  3415. ((eq org-agenda-window-setup 'other-window)
  3416. (org-switch-to-buffer-other-window abuf))
  3417. ((eq org-agenda-window-setup 'other-frame)
  3418. (switch-to-buffer-other-frame abuf))
  3419. ((eq org-agenda-window-setup 'only-window)
  3420. (delete-other-windows)
  3421. (pop-to-buffer-same-window abuf))
  3422. ((eq org-agenda-window-setup 'reorganize-frame)
  3423. (delete-other-windows)
  3424. (org-switch-to-buffer-other-window abuf)))
  3425. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3426. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3427. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3428. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3429. ;; Additional test in case agenda is invoked from within agenda
  3430. ;; buffer via elisp link.
  3431. (unless (equal (current-buffer) abuf)
  3432. (pop-to-buffer-same-window abuf))
  3433. (setq org-agenda-pre-window-conf
  3434. (or wconf org-agenda-pre-window-conf))))
  3435. (defun org-agenda-prepare (&optional name)
  3436. (let ((filter-alist (when org-agenda-persistent-filter
  3437. (with-current-buffer
  3438. (get-buffer-create org-agenda-buffer-name)
  3439. `((tag . ,org-agenda-tag-filter)
  3440. (re . ,org-agenda-regexp-filter)
  3441. (effort . ,org-agenda-effort-filter)
  3442. (cat . ,org-agenda-category-filter))))))
  3443. (if (org-agenda-use-sticky-p)
  3444. (progn
  3445. (put 'org-agenda-tag-filter :preset-filter nil)
  3446. (put 'org-agenda-category-filter :preset-filter nil)
  3447. (put 'org-agenda-regexp-filter :preset-filter nil)
  3448. (put 'org-agenda-effort-filter :preset-filter nil)
  3449. ;; Popup existing buffer
  3450. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3451. filter-alist)
  3452. (message "Sticky Agenda buffer, use `r' to refresh")
  3453. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3454. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3455. (setq org-todo-keywords-for-agenda nil)
  3456. (put 'org-agenda-tag-filter :preset-filter
  3457. org-agenda-tag-filter-preset)
  3458. (put 'org-agenda-category-filter :preset-filter
  3459. org-agenda-category-filter-preset)
  3460. (put 'org-agenda-regexp-filter :preset-filter
  3461. org-agenda-regexp-filter-preset)
  3462. (put 'org-agenda-effort-filter :preset-filter
  3463. org-agenda-effort-filter-preset)
  3464. (if org-agenda-multi
  3465. (progn
  3466. (setq buffer-read-only nil)
  3467. (goto-char (point-max))
  3468. (unless (or (bobp) org-agenda-compact-blocks
  3469. (not org-agenda-block-separator))
  3470. (insert "\n"
  3471. (if (stringp org-agenda-block-separator)
  3472. org-agenda-block-separator
  3473. (make-string (window-width) org-agenda-block-separator))
  3474. "\n"))
  3475. (narrow-to-region (point) (point-max)))
  3476. (setq org-done-keywords-for-agenda nil)
  3477. ;; Setting any org variables that are in org-agenda-local-vars
  3478. ;; list need to be done after the prepare call
  3479. (org-agenda-prepare-window
  3480. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3481. (setq buffer-read-only nil)
  3482. (org-agenda-reset-markers)
  3483. (let ((inhibit-read-only t)) (erase-buffer))
  3484. (org-agenda-mode)
  3485. (setq org-agenda-buffer (current-buffer))
  3486. (setq org-agenda-contributing-files nil)
  3487. (setq org-agenda-columns-active nil)
  3488. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3489. (setq org-todo-keywords-for-agenda
  3490. (org-uniquify org-todo-keywords-for-agenda))
  3491. (setq org-done-keywords-for-agenda
  3492. (org-uniquify org-done-keywords-for-agenda))
  3493. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3494. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3495. (and name (not org-agenda-name)
  3496. (setq-local org-agenda-name name)))
  3497. (setq buffer-read-only nil))))
  3498. (defvar org-overriding-columns-format)
  3499. (defvar org-local-columns-format)
  3500. (defun org-agenda-finalize ()
  3501. "Finishing touch for the agenda buffer, called just before displaying it."
  3502. (unless org-agenda-multi
  3503. (save-excursion
  3504. (let ((inhibit-read-only t))
  3505. (goto-char (point-min))
  3506. (save-excursion
  3507. (while (org-activate-links (point-max))
  3508. (add-text-properties (match-beginning 0) (match-end 0)
  3509. '(face org-link))))
  3510. (unless (eq org-agenda-remove-tags t)
  3511. (org-agenda-align-tags))
  3512. (unless org-agenda-with-colors
  3513. (remove-text-properties (point-min) (point-max) '(face nil)))
  3514. (when (bound-and-true-p org-overriding-columns-format)
  3515. (setq-local org-local-columns-format
  3516. org-overriding-columns-format))
  3517. (when org-agenda-view-columns-initially
  3518. (org-agenda-columns))
  3519. (when org-agenda-fontify-priorities
  3520. (org-agenda-fontify-priorities))
  3521. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3522. (org-agenda-dim-blocked-tasks))
  3523. (org-agenda-mark-clocking-task)
  3524. (when org-agenda-entry-text-mode
  3525. (org-agenda-entry-text-hide)
  3526. (org-agenda-entry-text-show))
  3527. (when (and (featurep 'org-habit)
  3528. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3529. (org-habit-insert-consistency-graphs))
  3530. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3531. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3532. (and (listp org-agenda-show-inherited-tags)
  3533. (memq org-agenda-type org-agenda-show-inherited-tags))
  3534. (and (eq org-agenda-show-inherited-tags t)
  3535. (or (eq org-agenda-use-tag-inheritance t)
  3536. (and (listp org-agenda-use-tag-inheritance)
  3537. (not (memq org-agenda-type
  3538. org-agenda-use-tag-inheritance))))))
  3539. (let (mrk)
  3540. (save-excursion
  3541. (goto-char (point-min))
  3542. (while (equal (forward-line) 0)
  3543. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3544. (put-text-property (point-at-bol) (point-at-eol)
  3545. 'tags
  3546. (org-with-point-at mrk
  3547. (mapcar #'downcase (org-get-tags)))))))))
  3548. (run-hooks 'org-agenda-finalize-hook)
  3549. (setq org-agenda-represented-tags nil
  3550. org-agenda-represented-categories nil)
  3551. (when org-agenda-top-headline-filter
  3552. (org-agenda-filter-top-headline-apply
  3553. org-agenda-top-headline-filter))
  3554. (when org-agenda-tag-filter
  3555. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3556. (when (get 'org-agenda-tag-filter :preset-filter)
  3557. (org-agenda-filter-apply
  3558. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3559. (when org-agenda-category-filter
  3560. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3561. (when (get 'org-agenda-category-filter :preset-filter)
  3562. (org-agenda-filter-apply
  3563. (get 'org-agenda-category-filter :preset-filter) 'category))
  3564. (when org-agenda-regexp-filter
  3565. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3566. (when (get 'org-agenda-regexp-filter :preset-filter)
  3567. (org-agenda-filter-apply
  3568. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3569. (when org-agenda-effort-filter
  3570. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3571. (when (get 'org-agenda-effort-filter :preset-filter)
  3572. (org-agenda-filter-apply
  3573. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3574. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3575. (defun org-agenda-mark-clocking-task ()
  3576. "Mark the current clock entry in the agenda if it is present."
  3577. ;; We need to widen when `org-agenda-finalize' is called from
  3578. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3579. (when (bound-and-true-p org-clock-current-task)
  3580. (save-restriction
  3581. (widen)
  3582. (org-agenda-unmark-clocking-task)
  3583. (when (marker-buffer org-clock-hd-marker)
  3584. (save-excursion
  3585. (goto-char (point-min))
  3586. (let (s ov)
  3587. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3588. (goto-char s)
  3589. (when (equal (org-get-at-bol 'org-hd-marker)
  3590. org-clock-hd-marker)
  3591. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3592. (overlay-put ov 'type 'org-agenda-clocking)
  3593. (overlay-put ov 'face 'org-agenda-clocking)
  3594. (overlay-put ov 'help-echo
  3595. "The clock is running in this item")))))))))
  3596. (defun org-agenda-unmark-clocking-task ()
  3597. "Unmark the current clocking task."
  3598. (mapc (lambda (o)
  3599. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3600. (delete-overlay o)))
  3601. (overlays-in (point-min) (point-max))))
  3602. (defun org-agenda-fontify-priorities ()
  3603. "Make highest priority lines bold, and lowest italic."
  3604. (interactive)
  3605. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3606. (delete-overlay o)))
  3607. (overlays-in (point-min) (point-max)))
  3608. (save-excursion
  3609. (let (b e p ov h l)
  3610. (goto-char (point-min))
  3611. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3612. (setq h (or (get-char-property (point) 'org-highest-priority)
  3613. org-highest-priority)
  3614. l (or (get-char-property (point) 'org-lowest-priority)
  3615. org-lowest-priority)
  3616. p (string-to-char (match-string 1))
  3617. b (match-beginning 0)
  3618. e (if (eq org-agenda-fontify-priorities 'cookies)
  3619. (match-end 0)
  3620. (point-at-eol))
  3621. ov (make-overlay b e))
  3622. (overlay-put
  3623. ov 'face
  3624. (let ((special-face
  3625. (cond ((org-face-from-face-or-color
  3626. 'priority 'org-priority
  3627. (cdr (assoc p org-priority-faces))))
  3628. ((and (listp org-agenda-fontify-priorities)
  3629. (org-face-from-face-or-color
  3630. 'priority 'org-priority
  3631. (cdr (assoc p org-agenda-fontify-priorities)))))
  3632. ((equal p l) 'italic)
  3633. ((equal p h) 'bold))))
  3634. (if special-face (list special-face 'org-priority) 'org-priority)))
  3635. (overlay-put ov 'org-type 'org-priority)))))
  3636. (defvar org-depend-tag-blocked)
  3637. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3638. "Dim currently blocked TODOs in the agenda display.
  3639. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3640. dimming them."
  3641. (interactive "P")
  3642. (when (called-interactively-p 'interactive)
  3643. (message "Dim or hide blocked tasks..."))
  3644. (dolist (o (overlays-in (point-min) (point-max)))
  3645. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3646. (delete-overlay o)))
  3647. (save-excursion
  3648. (let ((inhibit-read-only t))
  3649. (goto-char (point-min))
  3650. (while (let ((pos (text-property-not-all
  3651. (point) (point-max) 'org-todo-blocked nil)))
  3652. (when pos (goto-char pos)))
  3653. (let* ((invisible (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3654. (ov (make-overlay (if invisible
  3655. (line-end-position 0)
  3656. (line-beginning-position))
  3657. (line-end-position))))
  3658. (if invisible
  3659. (overlay-put ov 'invisible t)
  3660. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3661. (overlay-put ov 'org-type 'org-blocked-todo))
  3662. (forward-line))))
  3663. (when (called-interactively-p 'interactive)
  3664. (message "Dim or hide blocked tasks...done")))
  3665. (defun org-agenda--mark-blocked-entry (entry)
  3666. "For ENTRY a string with the text property `org-hd-marker', if
  3667. the header at `org-hd-marker' is blocked according to
  3668. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3669. 'invisible and the header is not blocked by checkboxes, set the
  3670. text property `org-todo-blocked' to `invisible', otherwise set it
  3671. to t."
  3672. (when (get-text-property 0 'todo-state entry)
  3673. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3674. (org-blocked-by-checkboxes nil)
  3675. ;; Necessary so that `org-entry-blocked-p' does not change
  3676. ;; the buffer.
  3677. (org-depend-tag-blocked nil))
  3678. (when entry-marker
  3679. (let ((blocked
  3680. (with-current-buffer (marker-buffer entry-marker)
  3681. (save-excursion
  3682. (goto-char entry-marker)
  3683. (org-entry-blocked-p)))))
  3684. (when blocked
  3685. (let ((really-invisible
  3686. (and (not org-blocked-by-checkboxes)
  3687. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3688. (put-text-property
  3689. 0 (length entry) 'org-todo-blocked
  3690. (if really-invisible 'invisible t)
  3691. entry)))))))
  3692. entry)
  3693. (defvar org-agenda-skip-function nil
  3694. "Function to be called at each match during agenda construction.
  3695. If this function returns nil, the current match should not be skipped.
  3696. Otherwise, the function must return a position from where the search
  3697. should be continued.
  3698. This may also be a Lisp form, it will be evaluated.
  3699. Never set this variable using `setq' or so, because then it will apply
  3700. to all future agenda commands. If you do want a global skipping condition,
  3701. use the option `org-agenda-skip-function-global' instead.
  3702. The correct usage for `org-agenda-skip-function' is to bind it with
  3703. `let' to scope it dynamically into the agenda-constructing command.
  3704. A good way to set it is through options in `org-agenda-custom-commands'.")
  3705. (defun org-agenda-skip ()
  3706. "Throw to `:skip' in places that should be skipped.
  3707. Also moves point to the end of the skipped region, so that search can
  3708. continue from there."
  3709. (let ((p (point-at-bol)) to)
  3710. (when (or
  3711. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3712. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3713. (get-text-property p :org-archived)
  3714. (org-end-of-subtree t))
  3715. (and org-agenda-skip-comment-trees
  3716. (get-text-property p :org-comment)
  3717. (org-end-of-subtree t))
  3718. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3719. (org-agenda-skip-eval org-agenda-skip-function)))
  3720. (goto-char to))
  3721. (org-in-src-block-p t))
  3722. (throw :skip t))))
  3723. (defun org-agenda-skip-eval (form)
  3724. "If FORM is a function or a list, call (or eval) it and return the result.
  3725. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3726. and match data are returned to the previous state no matter what these
  3727. functions do."
  3728. (let (fp)
  3729. (and form
  3730. (or (setq fp (functionp form))
  3731. (consp form))
  3732. (save-excursion
  3733. (save-match-data
  3734. (if fp
  3735. (funcall form)
  3736. (eval form)))))))
  3737. (defvar org-agenda-markers nil
  3738. "List of all currently active markers created by `org-agenda'.")
  3739. (defvar org-agenda-last-marker-time (float-time)
  3740. "Creation time of the last agenda marker.")
  3741. (defun org-agenda-new-marker (&optional pos)
  3742. "Return a new agenda marker.
  3743. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3744. these markers and resets them when they are no longer in use."
  3745. (let ((m (copy-marker (or pos (point)) t)))
  3746. (setq org-agenda-last-marker-time (float-time))
  3747. (if org-agenda-buffer
  3748. (with-current-buffer org-agenda-buffer
  3749. (push m org-agenda-markers))
  3750. (push m org-agenda-markers))
  3751. m))
  3752. (defun org-agenda-reset-markers ()
  3753. "Reset markers created by `org-agenda'."
  3754. (while org-agenda-markers
  3755. (move-marker (pop org-agenda-markers) nil)))
  3756. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3757. "Save relative positions of markers in region.
  3758. This check for agenda markers in all agenda buffers currently active."
  3759. (dolist (buf (buffer-list))
  3760. (with-current-buffer buf
  3761. (when (eq major-mode 'org-agenda-mode)
  3762. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3763. org-agenda-markers)))))
  3764. ;;; Entry text mode
  3765. (defun org-agenda-entry-text-show-here ()
  3766. "Add some text from the entry as context to the current line."
  3767. (let (m txt o)
  3768. (setq m (org-get-at-bol 'org-hd-marker))
  3769. (unless (marker-buffer m)
  3770. (error "No marker points to an entry here"))
  3771. (setq txt (concat "\n" (org-no-properties
  3772. (org-agenda-get-some-entry-text
  3773. m org-agenda-entry-text-maxlines
  3774. org-agenda-entry-text-leaders))))
  3775. (when (string-match "\\S-" txt)
  3776. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3777. (overlay-put o 'evaporate t)
  3778. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3779. (overlay-put o 'after-string txt))))
  3780. (defun org-agenda-entry-text-show ()
  3781. "Add entry context for all agenda lines."
  3782. (interactive)
  3783. (save-excursion
  3784. (goto-char (point-max))
  3785. (beginning-of-line 1)
  3786. (while (not (bobp))
  3787. (when (org-get-at-bol 'org-hd-marker)
  3788. (org-agenda-entry-text-show-here))
  3789. (beginning-of-line 0))))
  3790. (defun org-agenda-entry-text-hide ()
  3791. "Remove any shown entry context."
  3792. (mapc (lambda (o)
  3793. (when (eq (overlay-get o 'org-overlay-type)
  3794. 'agenda-entry-content)
  3795. (delete-overlay o)))
  3796. (overlays-in (point-min) (point-max))))
  3797. (defun org-agenda-get-day-face (date)
  3798. "Return the face DATE should be displayed with."
  3799. (cond ((and (functionp org-agenda-day-face-function)
  3800. (funcall org-agenda-day-face-function date)))
  3801. ((org-agenda-today-p date) 'org-agenda-date-today)
  3802. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3803. 'org-agenda-date-weekend)
  3804. (t 'org-agenda-date)))
  3805. (defvar org-agenda-show-log-scoped)
  3806. ;;; Agenda Daily/Weekly
  3807. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3808. "Start day for the agenda view.
  3809. Custom commands can set this variable in the options section.
  3810. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3811. input allowed when reading a date through the Org calendar.
  3812. See the docstring of `org-read-date' for details.")
  3813. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3814. (defvar org-arg-loc nil) ; local variable
  3815. (defvar org-agenda-buffer-tmp-name nil)
  3816. ;;;###autoload
  3817. (defun org-agenda-list (&optional arg start-day span with-hour)
  3818. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3819. The view will be for the current day or week, but from the overview buffer
  3820. you will be able to go to other days/weeks.
  3821. With a numeric prefix argument in an interactive call, the agenda will
  3822. span ARG days. Lisp programs should instead specify SPAN to change
  3823. the number of days. SPAN defaults to `org-agenda-span'.
  3824. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3825. given in `org-agenda-start-on-weekday'.
  3826. When WITH-HOUR is non-nil, only include scheduled and deadline
  3827. items if they have an hour specification like [h]h:mm."
  3828. (interactive "P")
  3829. (when org-agenda-overriding-arguments
  3830. (setq arg (car org-agenda-overriding-arguments)
  3831. start-day (nth 1 org-agenda-overriding-arguments)
  3832. span (nth 2 org-agenda-overriding-arguments)))
  3833. (when (and (integerp arg) (> arg 0))
  3834. (setq span arg arg nil))
  3835. (when (numberp span)
  3836. (unless (< 0 span)
  3837. (user-error "Agenda creation impossible for this span(=%d days)." span)))
  3838. (catch 'exit
  3839. (setq org-agenda-buffer-name
  3840. (or org-agenda-buffer-tmp-name
  3841. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3842. (when org-agenda-sticky
  3843. (cond ((and org-keys (stringp org-match))
  3844. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3845. (org-keys
  3846. (format "*Org Agenda(%s)*" org-keys))
  3847. (t "*Org Agenda(a)*")))
  3848. "*Org Agenda*"))
  3849. (org-agenda-prepare "Day/Week")
  3850. (setq start-day (or start-day org-agenda-start-day))
  3851. (when (stringp start-day)
  3852. ;; Convert to an absolute day number
  3853. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3854. (org-compile-prefix-format 'agenda)
  3855. (org-set-sorting-strategy 'agenda)
  3856. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3857. (today (org-today))
  3858. (sd (or start-day today))
  3859. (ndays (org-agenda-span-to-ndays span sd))
  3860. (org-agenda-start-on-weekday
  3861. (and (or (eq ndays 7) (eq ndays 14))
  3862. org-agenda-start-on-weekday))
  3863. (thefiles (org-agenda-files nil 'ifmode))
  3864. (files thefiles)
  3865. (start (if (or (null org-agenda-start-on-weekday)
  3866. (< ndays 7))
  3867. sd
  3868. (let* ((nt (calendar-day-of-week
  3869. (calendar-gregorian-from-absolute sd)))
  3870. (n1 org-agenda-start-on-weekday)
  3871. (d (- nt n1)))
  3872. (- sd (+ (if (< d 0) 7 0) d)))))
  3873. (day-numbers (list start))
  3874. (day-cnt 0)
  3875. (inhibit-redisplay (not debug-on-error))
  3876. (org-agenda-show-log-scoped org-agenda-show-log)
  3877. s e rtn rtnall file date d start-pos end-pos todayp
  3878. clocktable-start clocktable-end filter)
  3879. (setq org-agenda-redo-command
  3880. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3881. (dotimes (n (1- ndays))
  3882. (push (1+ (car day-numbers)) day-numbers))
  3883. (setq day-numbers (nreverse day-numbers))
  3884. (setq clocktable-start (car day-numbers)
  3885. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3886. (setq-local org-starting-day (car day-numbers))
  3887. (setq-local org-arg-loc arg)
  3888. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3889. (unless org-agenda-compact-blocks
  3890. (let* ((d1 (car day-numbers))
  3891. (d2 (org-last day-numbers))
  3892. (w1 (org-days-to-iso-week d1))
  3893. (w2 (org-days-to-iso-week d2)))
  3894. (setq s (point))
  3895. (org-agenda--insert-overriding-header
  3896. (concat (org-agenda-span-name span)
  3897. "-agenda"
  3898. (cond ((<= 350 (- d2 d1)) "")
  3899. ((= w1 w2) (format " (W%02d)" w1))
  3900. (t (format " (W%02d-W%02d)" w1 w2)))
  3901. ":\n")))
  3902. ;; Add properties if we actually inserted a header.
  3903. (when (> (point) s)
  3904. (add-text-properties s (1- (point))
  3905. (list 'face 'org-agenda-structure
  3906. 'org-date-line t))
  3907. (org-agenda-mark-header-line s)))
  3908. (while (setq d (pop day-numbers))
  3909. (setq date (calendar-gregorian-from-absolute d)
  3910. s (point))
  3911. (if (or (setq todayp (= d today))
  3912. (and (not start-pos) (= d sd)))
  3913. (setq start-pos (point))
  3914. (when (and start-pos (not end-pos))
  3915. (setq end-pos (point))))
  3916. (setq files thefiles
  3917. rtnall nil)
  3918. (while (setq file (pop files))
  3919. (catch 'nextfile
  3920. (org-check-agenda-file file)
  3921. (let ((org-agenda-entry-types org-agenda-entry-types))
  3922. ;; Starred types override non-starred equivalents
  3923. (when (member :deadline* org-agenda-entry-types)
  3924. (setq org-agenda-entry-types
  3925. (delq :deadline org-agenda-entry-types)))
  3926. (when (member :scheduled* org-agenda-entry-types)
  3927. (setq org-agenda-entry-types
  3928. (delq :scheduled org-agenda-entry-types)))
  3929. ;; Honor with-hour
  3930. (when with-hour
  3931. (when (member :deadline org-agenda-entry-types)
  3932. (setq org-agenda-entry-types
  3933. (delq :deadline org-agenda-entry-types))
  3934. (push :deadline* org-agenda-entry-types))
  3935. (when (member :scheduled org-agenda-entry-types)
  3936. (setq org-agenda-entry-types
  3937. (delq :scheduled org-agenda-entry-types))
  3938. (push :scheduled* org-agenda-entry-types)))
  3939. (unless org-agenda-include-deadlines
  3940. (setq org-agenda-entry-types
  3941. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3942. (cond
  3943. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3944. (setq rtn (org-agenda-get-day-entries
  3945. file date :closed)))
  3946. (org-agenda-show-log-scoped
  3947. (setq rtn (apply 'org-agenda-get-day-entries
  3948. file date
  3949. (append '(:closed) org-agenda-entry-types))))
  3950. (t
  3951. (setq rtn (apply 'org-agenda-get-day-entries
  3952. file date
  3953. org-agenda-entry-types)))))
  3954. (setq rtnall (append rtnall rtn)))) ;; all entries
  3955. (when org-agenda-include-diary
  3956. (let ((org-agenda-search-headline-for-time t))
  3957. (require 'diary-lib)
  3958. (setq rtn (org-get-entries-from-diary date))
  3959. (setq rtnall (append rtnall rtn))))
  3960. (when (or rtnall org-agenda-show-all-dates)
  3961. (setq day-cnt (1+ day-cnt))
  3962. (insert
  3963. (if (stringp org-agenda-format-date)
  3964. (format-time-string org-agenda-format-date
  3965. (org-time-from-absolute date))
  3966. (funcall org-agenda-format-date date))
  3967. "\n")
  3968. (put-text-property s (1- (point)) 'face
  3969. (org-agenda-get-day-face date))
  3970. (put-text-property s (1- (point)) 'org-date-line t)
  3971. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3972. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3973. (when todayp
  3974. (put-text-property s (1- (point)) 'org-today t))
  3975. (setq rtnall
  3976. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3977. (when rtnall (insert ;; all entries
  3978. (org-agenda-finalize-entries rtnall 'agenda)
  3979. "\n"))
  3980. (put-text-property s (1- (point)) 'day d)
  3981. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  3982. (when (and org-agenda-clockreport-mode clocktable-start)
  3983. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3984. ;; the above line is to ensure the restricted range!
  3985. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3986. tbl)
  3987. (setq p (org-plist-delete p :block))
  3988. (setq p (plist-put p :tstart clocktable-start))
  3989. (setq p (plist-put p :tend clocktable-end))
  3990. (setq p (plist-put p :scope 'agenda))
  3991. (setq tbl (apply 'org-clock-get-clocktable p))
  3992. (insert tbl)))
  3993. (goto-char (point-min))
  3994. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3995. (unless (or (not (get-buffer-window))
  3996. (and (pos-visible-in-window-p (point-min))
  3997. (pos-visible-in-window-p (point-max))))
  3998. (goto-char (1- (point-max)))
  3999. (recenter -1)
  4000. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4001. (goto-char (or start-pos 1))
  4002. (recenter 1)))
  4003. (goto-char (or start-pos 1))
  4004. (add-text-properties (point-min) (point-max)
  4005. `(org-agenda-type agenda
  4006. org-last-args (,arg ,start-day ,span)
  4007. org-redo-cmd ,org-agenda-redo-command
  4008. org-series-cmd ,org-cmd))
  4009. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4010. (org-agenda-show-clocking-issues))
  4011. (org-agenda-finalize)
  4012. (setq buffer-read-only t)
  4013. (message ""))))
  4014. (defun org-agenda-ndays-to-span (n)
  4015. "Return a span symbol for a span of N days, or N if none matches."
  4016. (cond ((symbolp n) n)
  4017. ((= n 1) 'day)
  4018. ((= n 7) 'week)
  4019. ((= n 14) 'fortnight)
  4020. (t n)))
  4021. (defun org-agenda-span-to-ndays (span &optional start-day)
  4022. "Return ndays from SPAN, possibly starting at START-DAY.
  4023. START-DAY is an absolute time value."
  4024. (cond ((numberp span) span)
  4025. ((eq span 'day) 1)
  4026. ((eq span 'week) 7)
  4027. ((eq span 'fortnight) 14)
  4028. ((eq span 'month)
  4029. (let ((date (calendar-gregorian-from-absolute start-day)))
  4030. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4031. ((eq span 'year)
  4032. (let ((date (calendar-gregorian-from-absolute start-day)))
  4033. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4034. (defun org-agenda-span-name (span)
  4035. "Return a SPAN name."
  4036. (if (null span)
  4037. ""
  4038. (if (symbolp span)
  4039. (capitalize (symbol-name span))
  4040. (format "%d days" span))))
  4041. ;;; Agenda word search
  4042. (defvar org-agenda-search-history nil)
  4043. (defvar org-search-syntax-table nil
  4044. "Special syntax table for Org search.
  4045. In this table, we have single quotes not as word constituents, to
  4046. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4047. (defvar org-mode-syntax-table) ; From org.el
  4048. (defun org-search-syntax-table ()
  4049. (unless org-search-syntax-table
  4050. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4051. (modify-syntax-entry ?' "." org-search-syntax-table)
  4052. (modify-syntax-entry ?` "." org-search-syntax-table))
  4053. org-search-syntax-table)
  4054. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4055. ;;;###autoload
  4056. (defun org-search-view (&optional todo-only string edit-at)
  4057. "Show all entries that contain a phrase or words or regular expressions.
  4058. With optional prefix argument TODO-ONLY, only consider entries that are
  4059. TODO entries. The argument STRING can be used to pass a default search
  4060. string into this function. If EDIT-AT is non-nil, it means that the
  4061. user should get a chance to edit this string, with cursor at position
  4062. EDIT-AT.
  4063. The search string can be viewed either as a phrase that should be found as
  4064. is, or it can be broken into a number of snippets, each of which must match
  4065. in a Boolean way to select an entry. The default depends on the variable
  4066. `org-agenda-search-view-always-boolean'.
  4067. Even if this is turned off (the default) you can always switch to
  4068. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4069. The default is a direct search of the whole phrase, where each space in
  4070. the search string can expand to an arbitrary amount of whitespace,
  4071. including newlines.
  4072. If using a Boolean search, the search string is split on whitespace and
  4073. each snippet is searched separately, with logical AND to select an entry.
  4074. Words prefixed with a minus must *not* occur in the entry. Words without
  4075. a prefix or prefixed with a plus must occur in the entry. Matching is
  4076. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4077. match whole words, not parts of a word) if
  4078. `org-agenda-search-view-force-full-words' is set (default is nil).
  4079. Boolean search snippets enclosed by curly braces are interpreted as
  4080. regular expressions that must or (when preceded with \"-\") must not
  4081. match in the entry. Snippets enclosed into double quotes will be taken
  4082. as a whole, to include whitespace.
  4083. - If the search string starts with an asterisk, search only in headlines.
  4084. - If (possibly after the leading star) the search string starts with an
  4085. exclamation mark, this also means to look at TODO entries only, an effect
  4086. that can also be achieved with a prefix argument.
  4087. - If (possibly after star and exclamation mark) the search string starts
  4088. with a colon, this will mean that the (non-regexp) snippets of the
  4089. Boolean search must match as full words.
  4090. This command searches the agenda files, and in addition the files
  4091. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4092. is active."
  4093. (interactive "P")
  4094. (when org-agenda-overriding-arguments
  4095. (setq todo-only (car org-agenda-overriding-arguments)
  4096. string (nth 1 org-agenda-overriding-arguments)
  4097. edit-at (nth 2 org-agenda-overriding-arguments)))
  4098. (let* ((props (list 'face nil
  4099. 'done-face 'org-agenda-done
  4100. 'org-not-done-regexp org-not-done-regexp
  4101. 'org-todo-regexp org-todo-regexp
  4102. 'org-complex-heading-regexp org-complex-heading-regexp
  4103. 'mouse-face 'highlight
  4104. 'help-echo (format "mouse-2 or RET jump to location")))
  4105. (full-words org-agenda-search-view-force-full-words)
  4106. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4107. regexp rtn rtnall files file pos inherited-tags
  4108. marker category level tags c neg re boolean
  4109. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4110. (unless (and (not edit-at)
  4111. (stringp string)
  4112. (string-match "\\S-" string))
  4113. (setq string (read-string
  4114. (if org-agenda-search-view-always-boolean
  4115. "[+-]Word/{Regexp} ...: "
  4116. "Phrase or [+-]Word/{Regexp} ...: ")
  4117. (cond
  4118. ((integerp edit-at) (cons string edit-at))
  4119. (edit-at string))
  4120. 'org-agenda-search-history)))
  4121. (catch 'exit
  4122. (when org-agenda-sticky
  4123. (setq org-agenda-buffer-name
  4124. (if (stringp string)
  4125. (format "*Org Agenda(%s:%s)*"
  4126. (or org-keys (or (and todo-only "S") "s")) string)
  4127. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4128. (org-agenda-prepare "SEARCH")
  4129. (org-compile-prefix-format 'search)
  4130. (org-set-sorting-strategy 'search)
  4131. (setq org-agenda-redo-command
  4132. (list 'org-search-view (if todo-only t nil)
  4133. (list 'if 'current-prefix-arg nil string)))
  4134. (setq org-agenda-query-string string)
  4135. (if (equal (string-to-char string) ?*)
  4136. (setq hdl-only t
  4137. words (substring string 1))
  4138. (setq words string))
  4139. (when (equal (string-to-char words) ?!)
  4140. (setq todo-only t
  4141. words (substring words 1)))
  4142. (when (equal (string-to-char words) ?:)
  4143. (setq full-words t
  4144. words (substring words 1)))
  4145. (when (or org-agenda-search-view-always-boolean
  4146. (member (string-to-char words) '(?- ?+ ?\{)))
  4147. (setq boolean t))
  4148. (setq words (split-string words))
  4149. (let (www w)
  4150. (while (setq w (pop words))
  4151. (while (and (string-match "\\\\\\'" w) words)
  4152. (setq w (concat (substring w 0 -1) " " (pop words))))
  4153. (push w www))
  4154. (setq words (nreverse www) www nil)
  4155. (while (setq w (pop words))
  4156. (when (and (string-match "\\`[-+]?{" w)
  4157. (not (string-match "}\\'" w)))
  4158. (while (and words (not (string-match "}\\'" (car words))))
  4159. (setq w (concat w " " (pop words))))
  4160. (setq w (concat w " " (pop words))))
  4161. (push w www))
  4162. (setq words (nreverse www)))
  4163. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4164. (when boolean
  4165. (let (wds w)
  4166. (while (setq w (pop words))
  4167. (when (or (equal (substring w 0 1) "\"")
  4168. (and (> (length w) 1)
  4169. (member (substring w 0 1) '("+" "-"))
  4170. (equal (substring w 1 2) "\"")))
  4171. (while (and words (not (equal (substring w -1) "\"")))
  4172. (setq w (concat w " " (pop words)))))
  4173. (and (string-match "\\`\\([-+]?\\)\"" w)
  4174. (setq w (replace-match "\\1" nil nil w)))
  4175. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4176. (push w wds))
  4177. (setq words (nreverse wds))))
  4178. (if boolean
  4179. (mapc (lambda (w)
  4180. (setq c (string-to-char w))
  4181. (if (equal c ?-)
  4182. (setq neg t w (substring w 1))
  4183. (if (equal c ?+)
  4184. (setq neg nil w (substring w 1))
  4185. (setq neg nil)))
  4186. (if (string-match "\\`{.*}\\'" w)
  4187. (setq re (substring w 1 -1))
  4188. (if full-words
  4189. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4190. (setq re (regexp-quote (downcase w)))))
  4191. (if neg (push re regexps-) (push re regexps+)))
  4192. words)
  4193. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4194. regexps+))
  4195. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4196. (if (not regexps+)
  4197. (setq regexp org-outline-regexp-bol)
  4198. (setq regexp (pop regexps+))
  4199. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4200. regexp))))
  4201. (setq files (org-agenda-files nil 'ifmode))
  4202. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4203. ;; restriction.
  4204. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4205. (pop org-agenda-text-search-extra-files)
  4206. (unless (get 'org-agenda-files 'org-restrict)
  4207. (setq files (org-add-archive-files files))))
  4208. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4209. ;; non-existent ones.
  4210. (setq files (cl-remove-duplicates
  4211. (append files org-agenda-text-search-extra-files)
  4212. :test (lambda (a b)
  4213. (and (file-exists-p a)
  4214. (file-exists-p b)
  4215. (file-equal-p a b))))
  4216. rtnall nil)
  4217. (while (setq file (pop files))
  4218. (setq ee nil)
  4219. (catch 'nextfile
  4220. (org-check-agenda-file file)
  4221. (setq buffer (if (file-exists-p file)
  4222. (org-get-agenda-file-buffer file)
  4223. (error "No such file %s" file)))
  4224. (unless buffer
  4225. ;; If file does not exist, make sure an error message is sent
  4226. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4227. file))))
  4228. (with-current-buffer buffer
  4229. (with-syntax-table (org-search-syntax-table)
  4230. (unless (derived-mode-p 'org-mode)
  4231. (error "Agenda file %s is not in Org mode" file))
  4232. (let ((case-fold-search t))
  4233. (save-excursion
  4234. (save-restriction
  4235. (if (eq buffer org-agenda-restrict)
  4236. (narrow-to-region org-agenda-restrict-begin
  4237. org-agenda-restrict-end)
  4238. (widen))
  4239. (goto-char (point-min))
  4240. (unless (or (org-at-heading-p)
  4241. (outline-next-heading))
  4242. (throw 'nextfile t))
  4243. (goto-char (max (point-min) (1- (point))))
  4244. (while (re-search-forward regexp nil t)
  4245. (org-back-to-heading t)
  4246. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4247. (> (org-reduced-level (org-outline-level))
  4248. org-agenda-search-view-max-outline-level)
  4249. (forward-line -1)
  4250. (org-back-to-heading t)))
  4251. (skip-chars-forward "* ")
  4252. (setq beg (point-at-bol)
  4253. beg1 (point)
  4254. end (progn
  4255. (outline-next-heading)
  4256. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4257. (> (org-reduced-level (org-outline-level))
  4258. org-agenda-search-view-max-outline-level)
  4259. (forward-line 1)
  4260. (outline-next-heading)))
  4261. (point)))
  4262. (catch :skip
  4263. (goto-char beg)
  4264. (org-agenda-skip)
  4265. (setq str (buffer-substring-no-properties
  4266. (point-at-bol)
  4267. (if hdl-only (point-at-eol) end)))
  4268. (mapc (lambda (wr) (when (string-match wr str)
  4269. (goto-char (1- end))
  4270. (throw :skip t)))
  4271. regexps-)
  4272. (mapc (lambda (wr) (unless (string-match wr str)
  4273. (goto-char (1- end))
  4274. (throw :skip t)))
  4275. (if todo-only
  4276. (cons (concat "^\\*+[ \t]+"
  4277. org-not-done-regexp)
  4278. regexps+)
  4279. regexps+))
  4280. (goto-char beg)
  4281. (setq marker (org-agenda-new-marker (point))
  4282. category (org-get-category)
  4283. level (make-string (org-reduced-level (org-outline-level)) ? )
  4284. inherited-tags
  4285. (or (eq org-agenda-show-inherited-tags 'always)
  4286. (and (listp org-agenda-show-inherited-tags)
  4287. (memq 'todo org-agenda-show-inherited-tags))
  4288. (and (eq org-agenda-show-inherited-tags t)
  4289. (or (eq org-agenda-use-tag-inheritance t)
  4290. (memq 'todo org-agenda-use-tag-inheritance))))
  4291. tags (org-get-tags nil (not inherited-tags))
  4292. txt (org-agenda-format-item
  4293. ""
  4294. (buffer-substring-no-properties
  4295. beg1 (point-at-eol))
  4296. level category tags t))
  4297. (org-add-props txt props
  4298. 'org-marker marker 'org-hd-marker marker
  4299. 'org-todo-regexp org-todo-regexp
  4300. 'level level
  4301. 'org-complex-heading-regexp org-complex-heading-regexp
  4302. 'priority 1000
  4303. 'type "search")
  4304. (push txt ee)
  4305. (goto-char (1- end))))))))))
  4306. (setq rtn (nreverse ee))
  4307. (setq rtnall (append rtnall rtn)))
  4308. (org-agenda--insert-overriding-header
  4309. (with-temp-buffer
  4310. (insert "Search words: ")
  4311. (add-text-properties (point-min) (1- (point))
  4312. (list 'face 'org-agenda-structure))
  4313. (setq pos (point))
  4314. (insert string "\n")
  4315. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4316. (setq pos (point))
  4317. (unless org-agenda-multi
  4318. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4319. Press `\\[org-agenda-manipulate-query-add]', \
  4320. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4321. `\\[org-agenda-manipulate-query-add-re]', \
  4322. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4323. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4324. (add-text-properties pos (1- (point))
  4325. (list 'face 'org-agenda-structure)))
  4326. (buffer-string)))
  4327. (org-agenda-mark-header-line (point-min))
  4328. (when rtnall
  4329. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4330. (goto-char (point-min))
  4331. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4332. (add-text-properties (point-min) (point-max)
  4333. `(org-agenda-type search
  4334. org-last-args (,todo-only ,string ,edit-at)
  4335. org-redo-cmd ,org-agenda-redo-command
  4336. org-series-cmd ,org-cmd))
  4337. (org-agenda-finalize)
  4338. (setq buffer-read-only t))))
  4339. ;;; Agenda TODO list
  4340. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4341. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4342. (concat
  4343. (if (or (equal keywords "ALL") (not keywords))
  4344. (propertize "ALL" 'face 'warning)
  4345. (mapconcat
  4346. (lambda (kw)
  4347. (propertize kw 'face (org-get-todo-face kw)))
  4348. (org-split-string keywords "|")
  4349. "|"))
  4350. "\n"))
  4351. (defvar org-select-this-todo-keyword nil)
  4352. (defvar org-last-arg nil)
  4353. ;;;###autoload
  4354. (defun org-todo-list (&optional arg)
  4355. "Show all (not done) TODO entries from all agenda file in a single list.
  4356. The prefix arg can be used to select a specific TODO keyword and limit
  4357. the list to these. When using `\\[universal-argument]', you will be prompted
  4358. for a keyword. A numeric prefix directly selects the Nth keyword in
  4359. `org-todo-keywords-1'."
  4360. (interactive "P")
  4361. (when org-agenda-overriding-arguments
  4362. (setq arg org-agenda-overriding-arguments))
  4363. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4364. (let* ((today (org-today))
  4365. (date (calendar-gregorian-from-absolute today))
  4366. (completion-ignore-case t)
  4367. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4368. (catch 'exit
  4369. (when org-agenda-sticky
  4370. (setq org-agenda-buffer-name
  4371. (if (stringp org-select-this-todo-keyword)
  4372. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4373. org-select-this-todo-keyword)
  4374. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4375. (org-agenda-prepare "TODO")
  4376. (setq kwds org-todo-keywords-for-agenda
  4377. org-select-this-todo-keyword (if (stringp arg) arg
  4378. (and (integerp arg)
  4379. (> arg 0)
  4380. (nth (1- arg) kwds))))
  4381. (when (equal arg '(4))
  4382. (setq org-select-this-todo-keyword
  4383. (completing-read "Keyword (or KWD1|K2D2|...): "
  4384. (mapcar #'list kwds) nil nil)))
  4385. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4386. (org-compile-prefix-format 'todo)
  4387. (org-set-sorting-strategy 'todo)
  4388. (setq org-agenda-redo-command
  4389. `(org-todo-list (or (and (numberp current-prefix-arg)
  4390. current-prefix-arg)
  4391. ,org-select-this-todo-keyword
  4392. current-prefix-arg ,arg)))
  4393. (setq files (org-agenda-files nil 'ifmode)
  4394. rtnall nil)
  4395. (while (setq file (pop files))
  4396. (catch 'nextfile
  4397. (org-check-agenda-file file)
  4398. (setq rtn (org-agenda-get-day-entries file date :todo))
  4399. (setq rtnall (append rtnall rtn))))
  4400. (org-agenda--insert-overriding-header
  4401. (with-temp-buffer
  4402. (insert "Global list of TODO items of type: ")
  4403. (add-text-properties (point-min) (1- (point))
  4404. (list 'face 'org-agenda-structure
  4405. 'short-heading
  4406. (concat "ToDo: "
  4407. (or org-select-this-todo-keyword "ALL"))))
  4408. (org-agenda-mark-header-line (point-min))
  4409. (insert (org-agenda-propertize-selected-todo-keywords
  4410. org-select-this-todo-keyword))
  4411. (setq pos (point))
  4412. (unless org-agenda-multi
  4413. (insert (substitute-command-keys "Press \
  4414. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4415. to search again: (0)[ALL]"))
  4416. (let ((n 0))
  4417. (dolist (k kwds)
  4418. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4419. (when (> (+ (current-column) (string-width s) 1) (window-width))
  4420. (insert "\n "))
  4421. (insert " " s))))
  4422. (insert "\n"))
  4423. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure))
  4424. (buffer-string)))
  4425. (org-agenda-mark-header-line (point-min))
  4426. (when rtnall
  4427. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4428. (goto-char (point-min))
  4429. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4430. (add-text-properties (point-min) (point-max)
  4431. `(org-agenda-type todo
  4432. org-last-args ,arg
  4433. org-redo-cmd ,org-agenda-redo-command
  4434. org-series-cmd ,org-cmd))
  4435. (org-agenda-finalize)
  4436. (setq buffer-read-only t))))
  4437. ;;; Agenda tags match
  4438. ;;;###autoload
  4439. (defun org-tags-view (&optional todo-only match)
  4440. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4441. The prefix arg TODO-ONLY limits the search to TODO entries."
  4442. (interactive "P")
  4443. (when org-agenda-overriding-arguments
  4444. (setq todo-only (car org-agenda-overriding-arguments)
  4445. match (nth 1 org-agenda-overriding-arguments)))
  4446. (let* ((org-tags-match-list-sublevels
  4447. org-tags-match-list-sublevels)
  4448. (completion-ignore-case t)
  4449. (org--matcher-tags-todo-only todo-only)
  4450. rtn rtnall files file pos matcher
  4451. buffer)
  4452. (when (and (stringp match) (not (string-match "\\S-" match)))
  4453. (setq match nil))
  4454. (catch 'exit
  4455. ;; TODO: this code is repeated a lot...
  4456. (when org-agenda-sticky
  4457. (setq org-agenda-buffer-name
  4458. (if (stringp match)
  4459. (format "*Org Agenda(%s:%s)*"
  4460. (or org-keys (or (and todo-only "M") "m")) match)
  4461. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4462. (setq matcher (org-make-tags-matcher match))
  4463. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4464. ;; expanding tags within `org-make-tags-matcher'
  4465. (org-agenda-prepare (concat "TAGS " match))
  4466. (setq match (car matcher)
  4467. matcher (cdr matcher))
  4468. (org-compile-prefix-format 'tags)
  4469. (org-set-sorting-strategy 'tags)
  4470. (setq org-agenda-query-string match)
  4471. (setq org-agenda-redo-command
  4472. (list 'org-tags-view
  4473. `(quote ,org--matcher-tags-todo-only)
  4474. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4475. (setq files (org-agenda-files nil 'ifmode)
  4476. rtnall nil)
  4477. (while (setq file (pop files))
  4478. (catch 'nextfile
  4479. (org-check-agenda-file file)
  4480. (setq buffer (if (file-exists-p file)
  4481. (org-get-agenda-file-buffer file)
  4482. (error "No such file %s" file)))
  4483. (if (not buffer)
  4484. ;; If file does not exist, error message to agenda
  4485. (setq rtn (list
  4486. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4487. rtnall (append rtnall rtn))
  4488. (with-current-buffer buffer
  4489. (unless (derived-mode-p 'org-mode)
  4490. (error "Agenda file %s is not in Org mode" file))
  4491. (save-excursion
  4492. (save-restriction
  4493. (if (eq buffer org-agenda-restrict)
  4494. (narrow-to-region org-agenda-restrict-begin
  4495. org-agenda-restrict-end)
  4496. (widen))
  4497. (setq rtn (org-scan-tags 'agenda
  4498. matcher
  4499. org--matcher-tags-todo-only))
  4500. (setq rtnall (append rtnall rtn))))))))
  4501. (org-agenda--insert-overriding-header
  4502. (with-temp-buffer
  4503. (insert "Headlines with TAGS match: ")
  4504. (add-text-properties (point-min) (1- (point))
  4505. (list 'face 'org-agenda-structure
  4506. 'short-heading
  4507. (concat "Match: " match)))
  4508. (setq pos (point))
  4509. (insert match "\n")
  4510. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4511. (setq pos (point))
  4512. (unless org-agenda-multi
  4513. (insert (substitute-command-keys
  4514. "Press \
  4515. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4516. to search again\n")))
  4517. (add-text-properties pos (1- (point))
  4518. (list 'face 'org-agenda-structure))
  4519. (buffer-string)))
  4520. (org-agenda-mark-header-line (point-min))
  4521. (when rtnall
  4522. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4523. (goto-char (point-min))
  4524. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4525. (add-text-properties
  4526. (point-min) (point-max)
  4527. `(org-agenda-type tags
  4528. org-last-args (,org--matcher-tags-todo-only ,match)
  4529. org-redo-cmd ,org-agenda-redo-command
  4530. org-series-cmd ,org-cmd))
  4531. (org-agenda-finalize)
  4532. (setq buffer-read-only t))))
  4533. ;;; Agenda Finding stuck projects
  4534. (defvar org-agenda-skip-regexp nil
  4535. "Regular expression used in skipping subtrees for the agenda.
  4536. This is basically a temporary global variable that can be set and then
  4537. used by user-defined selections using `org-agenda-skip-function'.")
  4538. (defvar org-agenda-overriding-header nil
  4539. "When set during agenda, todo and tags searches it replaces the header.
  4540. If an empty string, no header will be inserted. If any other
  4541. string, it will be inserted as a header. If nil, a header will
  4542. be generated automatically according to the command. This
  4543. variable should not be set directly, but custom commands can bind
  4544. it in the options section.")
  4545. (defun org-agenda-skip-entry-if (&rest conditions)
  4546. "Skip entry if any of CONDITIONS is true.
  4547. See `org-agenda-skip-if' for details."
  4548. (org-agenda-skip-if nil conditions))
  4549. (defun org-agenda-skip-subtree-if (&rest conditions)
  4550. "Skip subtree if any of CONDITIONS is true.
  4551. See `org-agenda-skip-if' for details."
  4552. (org-agenda-skip-if t conditions))
  4553. (defun org-agenda-skip-if (subtree conditions)
  4554. "Checks current entity for CONDITIONS.
  4555. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4556. the entry (i.e. the text before the next heading) is checked.
  4557. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4558. from different tests. Valid conditions are:
  4559. scheduled Check if there is a scheduled cookie
  4560. notscheduled Check if there is no scheduled cookie
  4561. deadline Check if there is a deadline
  4562. notdeadline Check if there is no deadline
  4563. timestamp Check if there is a timestamp (also deadline or scheduled)
  4564. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4565. regexp Check if regexp matches
  4566. notregexp Check if regexp does not match.
  4567. todo Check if TODO keyword matches
  4568. nottodo Check if TODO keyword does not match
  4569. The regexp is taken from the conditions list, it must come right after
  4570. the `regexp' or `notregexp' element.
  4571. `todo' and `nottodo' accept as an argument a list of todo
  4572. keywords, which may include \"*\" to match any todo keyword.
  4573. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4574. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4575. Instead of a list, a keyword class may be given. For example:
  4576. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4577. would skip entries that haven't been marked with any of \"DONE\"
  4578. keywords. Possible classes are: `todo', `done', `any'.
  4579. If any of these conditions is met, this function returns the end point of
  4580. the entity, causing the search to continue from there. This is a function
  4581. that can be put into `org-agenda-skip-function' for the duration of a command."
  4582. (org-back-to-heading t)
  4583. (let* ((beg (point))
  4584. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4585. (org-entry-end-position)))
  4586. (planning-end (if subtree end (line-end-position 2)))
  4587. m)
  4588. (and
  4589. (or (and (memq 'scheduled conditions)
  4590. (re-search-forward org-scheduled-time-regexp planning-end t))
  4591. (and (memq 'notscheduled conditions)
  4592. (not
  4593. (save-excursion
  4594. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4595. (and (memq 'deadline conditions)
  4596. (re-search-forward org-deadline-time-regexp planning-end t))
  4597. (and (memq 'notdeadline conditions)
  4598. (not
  4599. (save-excursion
  4600. (re-search-forward org-deadline-time-regexp planning-end t))))
  4601. (and (memq 'timestamp conditions)
  4602. (re-search-forward org-ts-regexp end t))
  4603. (and (memq 'nottimestamp conditions)
  4604. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4605. (and (setq m (memq 'regexp conditions))
  4606. (stringp (nth 1 m))
  4607. (re-search-forward (nth 1 m) end t))
  4608. (and (setq m (memq 'notregexp conditions))
  4609. (stringp (nth 1 m))
  4610. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4611. (and (or
  4612. (setq m (memq 'nottodo conditions))
  4613. (setq m (memq 'todo-unblocked conditions))
  4614. (setq m (memq 'nottodo-unblocked conditions))
  4615. (setq m (memq 'todo conditions)))
  4616. (org-agenda-skip-if-todo m end)))
  4617. end)))
  4618. (defun org-agenda-skip-if-todo (args end)
  4619. "Helper function for `org-agenda-skip-if', do not use it directly.
  4620. ARGS is a list with first element either `todo', `nottodo',
  4621. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4622. a list of TODO keywords, or a state symbol `todo' or `done' or
  4623. `any'."
  4624. (let ((todo-re
  4625. (concat "^\\*+[ \t]+"
  4626. (regexp-opt
  4627. (pcase args
  4628. (`(,_ todo)
  4629. (org-delete-all org-done-keywords
  4630. (copy-sequence org-todo-keywords-1)))
  4631. (`(,_ done) org-done-keywords)
  4632. (`(,_ any) org-todo-keywords-1)
  4633. (`(,_ ,(pred atom))
  4634. (error "Invalid TODO class or type: %S" args))
  4635. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4636. (`(,_ ,todo-list) todo-list))
  4637. 'words))))
  4638. (pcase args
  4639. (`(todo . ,_)
  4640. (let (case-fold-search) (re-search-forward todo-re end t)))
  4641. (`(nottodo . ,_)
  4642. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4643. (`(todo-unblocked . ,_)
  4644. (catch :unblocked
  4645. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4646. (when (org-entry-blocked-p) (throw :unblocked t)))
  4647. nil))
  4648. (`(nottodo-unblocked . ,_)
  4649. (catch :unblocked
  4650. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4651. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4652. t))
  4653. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4654. ;;;###autoload
  4655. (defun org-agenda-list-stuck-projects (&rest ignore)
  4656. "Create agenda view for projects that are stuck.
  4657. Stuck projects are project that have no next actions. For the definitions
  4658. of what a project is and how to check if it stuck, customize the variable
  4659. `org-stuck-projects'."
  4660. (interactive)
  4661. (let* ((org-agenda-overriding-header
  4662. (or org-agenda-overriding-header "List of stuck projects: "))
  4663. (matcher (nth 0 org-stuck-projects))
  4664. (todo (nth 1 org-stuck-projects))
  4665. (tags (nth 2 org-stuck-projects))
  4666. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4667. (todo-wds
  4668. (if (not (member "*" todo)) todo
  4669. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4670. (org-delete-all org-done-keywords-for-agenda
  4671. (copy-sequence org-todo-keywords-for-agenda))))
  4672. (todo-re (and todo
  4673. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4674. (mapconcat #'identity todo-wds "\\|"))))
  4675. (tags-re (cond ((null tags) nil)
  4676. ((member "*" tags) org-tag-line-re)
  4677. (tags
  4678. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4679. (concat org-outline-regexp-bol
  4680. ".*?[ \t]:"
  4681. other-tags
  4682. (regexp-opt tags t)
  4683. ":" other-tags "[ \t]*$")))
  4684. (t nil)))
  4685. (re-list (delq nil (list todo-re tags-re gen-re)))
  4686. (skip-re
  4687. (if (null re-list)
  4688. (error "Missing information to identify unstuck projects")
  4689. (mapconcat #'identity re-list "\\|")))
  4690. (org-agenda-skip-function
  4691. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4692. ;; in the subtree.
  4693. `(lambda ()
  4694. (and (save-excursion
  4695. (let ((case-fold-search nil))
  4696. (re-search-forward
  4697. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4698. (progn (outline-next-heading) (point))))))
  4699. (org-tags-view nil matcher)
  4700. (setq org-agenda-buffer-name (buffer-name))
  4701. (with-current-buffer org-agenda-buffer-name
  4702. (setq org-agenda-redo-command
  4703. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4704. (let ((inhibit-read-only t))
  4705. (add-text-properties
  4706. (point-min) (point-max)
  4707. `(org-redo-cmd ,org-agenda-redo-command))))))
  4708. ;;; Diary integration
  4709. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4710. (defvar diary-list-entries-hook)
  4711. (defvar diary-time-regexp)
  4712. (defun org-get-entries-from-diary (date)
  4713. "Get the (Emacs Calendar) diary entries for DATE."
  4714. (require 'diary-lib)
  4715. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4716. (diary-display-function 'diary-fancy-display)
  4717. (pop-up-frames nil)
  4718. (diary-list-entries-hook
  4719. (cons 'org-diary-default-entry diary-list-entries-hook))
  4720. (diary-file-name-prefix nil) ; turn this feature off
  4721. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4722. (diary-time-regexp (concat "^" diary-time-regexp))
  4723. entries
  4724. (org-disable-agenda-to-diary t))
  4725. (save-excursion
  4726. (save-window-excursion
  4727. (funcall (if (fboundp 'diary-list-entries)
  4728. 'diary-list-entries 'list-diary-entries)
  4729. date 1)))
  4730. (if (not (get-buffer diary-fancy-buffer))
  4731. (setq entries nil)
  4732. (with-current-buffer diary-fancy-buffer
  4733. (setq buffer-read-only nil)
  4734. (if (zerop (buffer-size))
  4735. ;; No entries
  4736. (setq entries nil)
  4737. ;; Omit the date and other unnecessary stuff
  4738. (org-agenda-cleanup-fancy-diary)
  4739. ;; Add prefix to each line and extend the text properties
  4740. (if (zerop (buffer-size))
  4741. (setq entries nil)
  4742. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4743. (setq entries
  4744. (with-temp-buffer
  4745. (insert entries) (goto-char (point-min))
  4746. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4747. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4748. (replace-match (concat "; " (match-string 1)))))
  4749. (buffer-string)))))
  4750. (set-buffer-modified-p nil)
  4751. (kill-buffer diary-fancy-buffer)))
  4752. (when entries
  4753. (setq entries (org-split-string entries "\n"))
  4754. (setq entries
  4755. (mapcar
  4756. (lambda (x)
  4757. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4758. ;; Extend the text properties to the beginning of the line
  4759. (org-add-props x (text-properties-at (1- (length x)) x)
  4760. 'type "diary" 'date date 'face 'org-agenda-diary))
  4761. entries)))))
  4762. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4763. "Hook run when the fancy diary buffer is cleaned up.")
  4764. (defun org-agenda-cleanup-fancy-diary ()
  4765. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4766. This gets rid of the date, the underline under the date, and the
  4767. dummy entry installed by Org mode to ensure non-empty diary for
  4768. each date. It also removes lines that contain only whitespace."
  4769. (goto-char (point-min))
  4770. (if (looking-at ".*?:[ \t]*")
  4771. (progn
  4772. (replace-match "")
  4773. (re-search-forward "\n=+$" nil t)
  4774. (replace-match "")
  4775. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4776. (re-search-forward "\n=+$" nil t)
  4777. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4778. (goto-char (point-min))
  4779. (while (re-search-forward "^ +\n" nil t)
  4780. (replace-match ""))
  4781. (goto-char (point-min))
  4782. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4783. (replace-match ""))
  4784. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4785. (defun org-modify-diary-entry-string (string)
  4786. "Add text properties to string, allowing Org to act on it."
  4787. (org-add-props string nil
  4788. 'mouse-face 'highlight
  4789. 'help-echo (if buffer-file-name
  4790. (format "mouse-2 or RET jump to diary file %s"
  4791. (abbreviate-file-name buffer-file-name))
  4792. "")
  4793. 'org-agenda-diary-link t
  4794. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4795. (defun org-diary-default-entry ()
  4796. "Add a dummy entry to the diary.
  4797. Needed to avoid empty dates which mess up holiday display."
  4798. ;; Catch the error if dealing with the new add-to-diary-alist
  4799. (when org-disable-agenda-to-diary
  4800. (condition-case nil
  4801. (org-add-to-diary-list original-date "Org mode dummy" "")
  4802. (error
  4803. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4804. (defun org-add-to-diary-list (&rest args)
  4805. (if (fboundp 'diary-add-to-list)
  4806. (apply 'diary-add-to-list args)
  4807. (apply 'add-to-diary-list args)))
  4808. (defvar org-diary-last-run-time nil)
  4809. ;;;###autoload
  4810. (defun org-diary (&rest args)
  4811. "Return diary information from org files.
  4812. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4813. It accesses org files and extracts information from those files to be
  4814. listed in the diary. The function accepts arguments specifying what
  4815. items should be listed. For a list of arguments allowed here, see the
  4816. variable `org-agenda-entry-types'.
  4817. The call in the diary file should look like this:
  4818. &%%(org-diary) ~/path/to/some/orgfile.org
  4819. Use a separate line for each org file to check. Or, if you omit the file name,
  4820. all files listed in `org-agenda-files' will be checked automatically:
  4821. &%%(org-diary)
  4822. If you don't give any arguments (as in the example above), the default value
  4823. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4824. So the example above may also be written as
  4825. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4826. The function expects the lisp variables `entry' and `date' to be provided
  4827. by the caller, because this is how the calendar works. Don't use this
  4828. function from a program - use `org-agenda-get-day-entries' instead."
  4829. (when (> (- (float-time)
  4830. org-agenda-last-marker-time)
  4831. 5)
  4832. ;; I am not sure if this works with sticky agendas, because the marker
  4833. ;; list is then no longer a global variable.
  4834. (org-agenda-reset-markers))
  4835. (org-compile-prefix-format 'agenda)
  4836. (org-set-sorting-strategy 'agenda)
  4837. (setq args (or args org-agenda-entry-types))
  4838. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4839. (list entry)
  4840. (org-agenda-files t)))
  4841. (time (float-time))
  4842. file rtn results)
  4843. (when (or (not org-diary-last-run-time)
  4844. (> (- time
  4845. org-diary-last-run-time)
  4846. 3))
  4847. (org-agenda-prepare-buffers files))
  4848. (setq org-diary-last-run-time time)
  4849. ;; If this is called during org-agenda, don't return any entries to
  4850. ;; the calendar. Org Agenda will list these entries itself.
  4851. (when org-disable-agenda-to-diary (setq files nil))
  4852. (while (setq file (pop files))
  4853. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4854. (setq results (append results rtn)))
  4855. (when results
  4856. (setq results
  4857. (mapcar (lambda (i) (replace-regexp-in-string
  4858. org-link-bracket-re "\\2" i)) results))
  4859. (concat (org-agenda-finalize-entries results) "\n"))))
  4860. ;;; Agenda entry finders
  4861. (defun org-agenda--timestamp-to-absolute (&rest args)
  4862. "Call `org-time-string-to-absolute' with ARGS.
  4863. However, throw `:skip' whenever an error is raised."
  4864. (condition-case e
  4865. (apply #'org-time-string-to-absolute args)
  4866. (org-diary-sexp-no-match (throw :skip nil))
  4867. (error
  4868. (message "%s; Skipping entry" (error-message-string e))
  4869. (throw :skip nil))))
  4870. (defun org-agenda-get-day-entries (file date &rest args)
  4871. "Does the work for `org-diary' and `org-agenda'.
  4872. FILE is the path to a file to be checked for entries. DATE is date like
  4873. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4874. which kind of entries should be extracted. For details about these, see
  4875. the documentation of `org-diary'."
  4876. (let* ((org-startup-folded nil)
  4877. (org-startup-align-all-tables nil)
  4878. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4879. (error "No such file %s" file))))
  4880. (if (not buffer)
  4881. ;; If file does not exist, signal it in diary nonetheless.
  4882. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4883. (with-current-buffer buffer
  4884. (unless (derived-mode-p 'org-mode)
  4885. (error "Agenda file %s is not in Org mode" file))
  4886. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4887. (setf org-agenda-current-date date)
  4888. (save-excursion
  4889. (save-restriction
  4890. (if (eq buffer org-agenda-restrict)
  4891. (narrow-to-region org-agenda-restrict-begin
  4892. org-agenda-restrict-end)
  4893. (widen))
  4894. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4895. ;; first in order to populate DEADLINES before passing it.
  4896. ;;
  4897. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4898. ;; guarding us from modifying `org-agenda-entry-types'.
  4899. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4900. (when (and (memq :scheduled args) (memq :scheduled* args))
  4901. (setf args (delq :scheduled* args)))
  4902. (cond
  4903. ((memq :deadline args)
  4904. (setf args (cons :deadline
  4905. (delq :deadline (delq :deadline* args)))))
  4906. ((memq :deadline* args)
  4907. (setf args (cons :deadline* (delq :deadline* args)))))
  4908. ;; Collect list of headlines. Return them flattened.
  4909. (let ((case-fold-search nil) results deadlines)
  4910. (dolist (arg args (apply #'nconc (nreverse results)))
  4911. (pcase arg
  4912. ((and :todo (guard (org-agenda-today-p date)))
  4913. (push (org-agenda-get-todos) results))
  4914. (:timestamp
  4915. (push (org-agenda-get-blocks) results)
  4916. (push (org-agenda-get-timestamps deadlines) results))
  4917. (:sexp
  4918. (push (org-agenda-get-sexps) results))
  4919. (:scheduled
  4920. (push (org-agenda-get-scheduled deadlines) results))
  4921. (:scheduled*
  4922. (push (org-agenda-get-scheduled deadlines t) results))
  4923. (:closed
  4924. (push (org-agenda-get-progress) results))
  4925. (:deadline
  4926. (setf deadlines (org-agenda-get-deadlines))
  4927. (push deadlines results))
  4928. (:deadline*
  4929. (setf deadlines (org-agenda-get-deadlines t))
  4930. (push deadlines results)))))))))))
  4931. (defsubst org-em (x y list)
  4932. "Is X or Y a member of LIST?"
  4933. (or (memq x list) (memq y list)))
  4934. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4935. (defvar org-agenda-sorting-strategy-selected nil)
  4936. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4937. "Retrieve timestamp information for sorting agenda views.
  4938. Given a point or marker POM, returns a cons cell of the timestamp
  4939. and the timestamp type relevant for the sorting strategy in
  4940. `org-agenda-sorting-strategy-selected'."
  4941. (let (ts ts-date-type)
  4942. (save-match-data
  4943. (cond ((org-em 'scheduled-up 'scheduled-down
  4944. org-agenda-sorting-strategy-selected)
  4945. (setq ts (org-entry-get pom "SCHEDULED")
  4946. ts-date-type " scheduled"))
  4947. ((org-em 'deadline-up 'deadline-down
  4948. org-agenda-sorting-strategy-selected)
  4949. (setq ts (org-entry-get pom "DEADLINE")
  4950. ts-date-type " deadline"))
  4951. ((org-em 'ts-up 'ts-down
  4952. org-agenda-sorting-strategy-selected)
  4953. (setq ts (org-entry-get pom "TIMESTAMP")
  4954. ts-date-type " timestamp"))
  4955. ((org-em 'tsia-up 'tsia-down
  4956. org-agenda-sorting-strategy-selected)
  4957. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4958. ts-date-type " timestamp_ia"))
  4959. ((org-em 'timestamp-up 'timestamp-down
  4960. org-agenda-sorting-strategy-selected)
  4961. (setq ts (or (org-entry-get pom "SCHEDULED")
  4962. (org-entry-get pom "DEADLINE")
  4963. (org-entry-get pom "TIMESTAMP")
  4964. (org-entry-get pom "TIMESTAMP_IA"))
  4965. ts-date-type ""))
  4966. (t (setq ts-date-type "")))
  4967. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4968. ts-date-type))))
  4969. (defun org-agenda-get-todos ()
  4970. "Return the TODO information for agenda display."
  4971. (let* ((props (list 'face nil
  4972. 'done-face 'org-agenda-done
  4973. 'org-not-done-regexp org-not-done-regexp
  4974. 'org-todo-regexp org-todo-regexp
  4975. 'org-complex-heading-regexp org-complex-heading-regexp
  4976. 'mouse-face 'highlight
  4977. 'help-echo
  4978. (format "mouse-2 or RET jump to org file %s"
  4979. (abbreviate-file-name buffer-file-name))))
  4980. (case-fold-search nil)
  4981. (regexp (format org-heading-keyword-regexp-format
  4982. (cond
  4983. ((and org-select-this-todo-keyword
  4984. (equal org-select-this-todo-keyword "*"))
  4985. org-todo-regexp)
  4986. (org-select-this-todo-keyword
  4987. (concat "\\("
  4988. (mapconcat 'identity
  4989. (org-split-string
  4990. org-select-this-todo-keyword
  4991. "|")
  4992. "\\|") "\\)"))
  4993. (t org-not-done-regexp))))
  4994. marker priority category level tags todo-state
  4995. ts-date ts-date-type ts-date-pair
  4996. ee txt beg end inherited-tags todo-state-end-pos)
  4997. (goto-char (point-min))
  4998. (while (re-search-forward regexp nil t)
  4999. (catch :skip
  5000. (save-match-data
  5001. (beginning-of-line)
  5002. (org-agenda-skip)
  5003. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5004. (unless (and (setq todo-state (org-get-todo-state))
  5005. (setq todo-state-end-pos (match-end 2)))
  5006. (goto-char end)
  5007. (throw :skip nil))
  5008. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5009. (goto-char (1+ beg))
  5010. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5011. (throw :skip nil)))
  5012. (goto-char (match-beginning 2))
  5013. (setq marker (org-agenda-new-marker (match-beginning 0))
  5014. category (org-get-category)
  5015. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5016. ts-date (car ts-date-pair)
  5017. ts-date-type (cdr ts-date-pair)
  5018. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5019. inherited-tags
  5020. (or (eq org-agenda-show-inherited-tags 'always)
  5021. (and (listp org-agenda-show-inherited-tags)
  5022. (memq 'todo org-agenda-show-inherited-tags))
  5023. (and (eq org-agenda-show-inherited-tags t)
  5024. (or (eq org-agenda-use-tag-inheritance t)
  5025. (memq 'todo org-agenda-use-tag-inheritance))))
  5026. tags (org-get-tags nil (not inherited-tags))
  5027. level (make-string (org-reduced-level (org-outline-level)) ? )
  5028. txt (org-agenda-format-item "" txt level category tags t)
  5029. priority (1+ (org-get-priority txt)))
  5030. (org-add-props txt props
  5031. 'org-marker marker 'org-hd-marker marker
  5032. 'priority priority
  5033. 'level level
  5034. 'ts-date ts-date
  5035. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5036. (push txt ee)
  5037. (if org-agenda-todo-list-sublevels
  5038. (goto-char todo-state-end-pos)
  5039. (org-end-of-subtree 'invisible))))
  5040. (nreverse ee)))
  5041. (defun org-agenda-todo-custom-ignore-p (time n)
  5042. "Check whether timestamp is farther away than n number of days.
  5043. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5044. `org-agenda-todo-ignore-scheduled' or
  5045. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5046. (let ((days (org-time-stamp-to-now
  5047. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5048. (if (>= n 0)
  5049. (>= days n)
  5050. (<= days n))))
  5051. ;;;###autoload
  5052. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5053. (&optional end)
  5054. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5055. (when (or org-agenda-todo-ignore-with-date
  5056. org-agenda-todo-ignore-scheduled
  5057. org-agenda-todo-ignore-deadlines
  5058. org-agenda-todo-ignore-timestamp)
  5059. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5060. (save-excursion
  5061. (or (and org-agenda-todo-ignore-with-date
  5062. (re-search-forward org-ts-regexp end t))
  5063. (and org-agenda-todo-ignore-scheduled
  5064. (re-search-forward org-scheduled-time-regexp end t)
  5065. (cond
  5066. ((eq org-agenda-todo-ignore-scheduled 'future)
  5067. (> (org-time-stamp-to-now
  5068. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5069. ((eq org-agenda-todo-ignore-scheduled 'past)
  5070. (<= (org-time-stamp-to-now
  5071. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5072. ((numberp org-agenda-todo-ignore-scheduled)
  5073. (org-agenda-todo-custom-ignore-p
  5074. (match-string 1) org-agenda-todo-ignore-scheduled))
  5075. (t)))
  5076. (and org-agenda-todo-ignore-deadlines
  5077. (re-search-forward org-deadline-time-regexp end t)
  5078. (cond
  5079. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5080. ((eq org-agenda-todo-ignore-deadlines 'far)
  5081. (not (org-deadline-close-p (match-string 1))))
  5082. ((eq org-agenda-todo-ignore-deadlines 'future)
  5083. (> (org-time-stamp-to-now
  5084. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5085. ((eq org-agenda-todo-ignore-deadlines 'past)
  5086. (<= (org-time-stamp-to-now
  5087. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5088. ((numberp org-agenda-todo-ignore-deadlines)
  5089. (org-agenda-todo-custom-ignore-p
  5090. (match-string 1) org-agenda-todo-ignore-deadlines))
  5091. (t (org-deadline-close-p (match-string 1)))))
  5092. (and org-agenda-todo-ignore-timestamp
  5093. (let ((buffer (current-buffer))
  5094. (regexp
  5095. (concat
  5096. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5097. (start (point)))
  5098. ;; Copy current buffer into a temporary one
  5099. (with-temp-buffer
  5100. (insert-buffer-substring buffer start end)
  5101. (goto-char (point-min))
  5102. ;; Delete SCHEDULED and DEADLINE items
  5103. (while (re-search-forward regexp end t)
  5104. (delete-region (match-beginning 0) (match-end 0)))
  5105. (goto-char (point-min))
  5106. ;; No search for timestamp left
  5107. (when (re-search-forward org-ts-regexp nil t)
  5108. (cond
  5109. ((eq org-agenda-todo-ignore-timestamp 'future)
  5110. (> (org-time-stamp-to-now
  5111. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5112. ((eq org-agenda-todo-ignore-timestamp 'past)
  5113. (<= (org-time-stamp-to-now
  5114. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5115. ((numberp org-agenda-todo-ignore-timestamp)
  5116. (org-agenda-todo-custom-ignore-p
  5117. (match-string 1) org-agenda-todo-ignore-timestamp))
  5118. (t))))))))))
  5119. (defun org-agenda-get-timestamps (&optional deadlines)
  5120. "Return the date stamp information for agenda display.
  5121. Optional argument DEADLINES is a list of deadline items to be
  5122. displayed in agenda view."
  5123. (let* ((props (list 'face 'org-agenda-calendar-event
  5124. 'org-not-done-regexp org-not-done-regexp
  5125. 'org-todo-regexp org-todo-regexp
  5126. 'org-complex-heading-regexp org-complex-heading-regexp
  5127. 'mouse-face 'highlight
  5128. 'help-echo
  5129. (format "mouse-2 or RET jump to Org file %s"
  5130. (abbreviate-file-name buffer-file-name))))
  5131. (current (calendar-absolute-from-gregorian date))
  5132. (today (org-today))
  5133. (deadline-position-alist
  5134. (mapcar (lambda (d)
  5135. (let ((m (get-text-property 0 'org-hd-marker d)))
  5136. (and m (marker-position m))))
  5137. deadlines))
  5138. ;; Match time-stamps set to current date, time-stamps with
  5139. ;; a repeater, and S-exp time-stamps.
  5140. (regexp
  5141. (concat
  5142. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5143. (regexp-quote
  5144. (substring
  5145. (format-time-string
  5146. (car org-time-stamp-formats)
  5147. (encode-time ; DATE bound by calendar
  5148. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5149. 1 11))
  5150. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5151. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5152. timestamp-items)
  5153. (goto-char (point-min))
  5154. (while (re-search-forward regexp nil t)
  5155. ;; Skip date ranges, scheduled and deadlines, which are handled
  5156. ;; specially. Also skip time-stamps before first headline as
  5157. ;; there would be no entry to add to the agenda. Eventually,
  5158. ;; ignore clock entries.
  5159. (catch :skip
  5160. (save-match-data
  5161. (when (or (org-at-date-range-p)
  5162. (org-at-planning-p)
  5163. (org-before-first-heading-p)
  5164. (and org-agenda-include-inactive-timestamps
  5165. (org-at-clock-log-p)))
  5166. (throw :skip nil))
  5167. (org-agenda-skip))
  5168. (let* ((pos (match-beginning 0))
  5169. (repeat (match-string 1))
  5170. (sexp-entry (match-string 3))
  5171. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5172. (save-excursion
  5173. (goto-char pos)
  5174. (looking-at org-ts-regexp-both)
  5175. (match-string 0))))
  5176. (todo-state (org-get-todo-state))
  5177. (warntime (get-text-property (point) 'org-appt-warntime))
  5178. (done? (member todo-state org-done-keywords)))
  5179. ;; Possibly skip done tasks.
  5180. (when (and done? org-agenda-skip-timestamp-if-done)
  5181. (throw :skip t))
  5182. ;; S-exp entry doesn't match current day: skip it.
  5183. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5184. (throw :skip nil))
  5185. (when repeat
  5186. (let* ((past
  5187. ;; A repeating time stamp is shown at its base
  5188. ;; date and every repeated date up to TODAY. If
  5189. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5190. ;; however, only the last repeat before today
  5191. ;; (inclusive) is shown.
  5192. (org-agenda--timestamp-to-absolute
  5193. repeat
  5194. (if (or (> current today)
  5195. (eq org-agenda-prefer-last-repeat t)
  5196. (member todo-state org-agenda-prefer-last-repeat))
  5197. today
  5198. current)
  5199. 'past (current-buffer) pos))
  5200. (future
  5201. ;; Display every repeated date past TODAY
  5202. ;; (exclusive) unless
  5203. ;; `org-agenda-show-future-repeats' is nil. If
  5204. ;; this variable is set to `next', only display
  5205. ;; the first repeated date after TODAY
  5206. ;; (exclusive).
  5207. (cond
  5208. ((<= current today) past)
  5209. ((not org-agenda-show-future-repeats) past)
  5210. (t
  5211. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5212. (1+ today)
  5213. current)))
  5214. (org-agenda--timestamp-to-absolute
  5215. repeat base 'future (current-buffer) pos))))))
  5216. (when (and (/= current past) (/= current future))
  5217. (throw :skip nil))))
  5218. (save-excursion
  5219. (re-search-backward org-outline-regexp-bol nil t)
  5220. ;; Possibly skip time-stamp when a deadline is set.
  5221. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5222. (assq (point) deadline-position-alist))
  5223. (throw :skip nil))
  5224. (let* ((category (org-get-category pos))
  5225. (inherited-tags
  5226. (or (eq org-agenda-show-inherited-tags 'always)
  5227. (and (consp org-agenda-show-inherited-tags)
  5228. (memq 'agenda org-agenda-show-inherited-tags))
  5229. (and (eq org-agenda-show-inherited-tags t)
  5230. (or (eq org-agenda-use-tag-inheritance t)
  5231. (memq 'agenda
  5232. org-agenda-use-tag-inheritance)))))
  5233. (tags (org-get-tags nil (not inherited-tags)))
  5234. (level (make-string (org-reduced-level (org-outline-level))
  5235. ?\s))
  5236. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5237. (match-string 1)))
  5238. (inactive? (= (char-after pos) ?\[))
  5239. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5240. (item
  5241. (org-agenda-format-item
  5242. (and inactive? org-agenda-inactive-leader)
  5243. head level category tags time-stamp org-ts-regexp habit?)))
  5244. (org-add-props item props
  5245. 'priority (if habit?
  5246. (org-habit-get-priority (org-habit-parse-todo))
  5247. (org-get-priority item))
  5248. 'org-marker (org-agenda-new-marker pos)
  5249. 'org-hd-marker (org-agenda-new-marker)
  5250. 'date date
  5251. 'level level
  5252. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5253. current)
  5254. 'todo-state todo-state
  5255. 'warntime warntime
  5256. 'type "timestamp")
  5257. (push item timestamp-items))))
  5258. (when org-agenda-skip-additional-timestamps-same-entry
  5259. (outline-next-heading))))
  5260. (nreverse timestamp-items)))
  5261. (defun org-agenda-get-sexps ()
  5262. "Return the sexp information for agenda display."
  5263. (require 'diary-lib)
  5264. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5265. 'mouse-face 'highlight
  5266. 'help-echo
  5267. (format "mouse-2 or RET jump to org file %s"
  5268. (abbreviate-file-name buffer-file-name))))
  5269. (regexp "^&?%%(")
  5270. marker category extra level ee txt tags entry
  5271. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5272. (goto-char (point-min))
  5273. (while (re-search-forward regexp nil t)
  5274. (catch :skip
  5275. (org-agenda-skip)
  5276. (setq beg (match-beginning 0))
  5277. (goto-char (1- (match-end 0)))
  5278. (setq b (point))
  5279. (forward-sexp 1)
  5280. (setq sexp (buffer-substring b (point)))
  5281. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5282. (org-trim (match-string 1))
  5283. ""))
  5284. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5285. (when result
  5286. (setq marker (org-agenda-new-marker beg)
  5287. level (make-string (org-reduced-level (org-outline-level)) ? )
  5288. category (org-get-category beg)
  5289. inherited-tags
  5290. (or (eq org-agenda-show-inherited-tags 'always)
  5291. (and (listp org-agenda-show-inherited-tags)
  5292. (memq 'agenda org-agenda-show-inherited-tags))
  5293. (and (eq org-agenda-show-inherited-tags t)
  5294. (or (eq org-agenda-use-tag-inheritance t)
  5295. (memq 'agenda org-agenda-use-tag-inheritance))))
  5296. tags (org-get-tags nil (not inherited-tags))
  5297. todo-state (org-get-todo-state)
  5298. warntime (get-text-property (point) 'org-appt-warntime)
  5299. extra nil)
  5300. (dolist (r (if (stringp result)
  5301. (list result)
  5302. result)) ;; we expect a list here
  5303. (when (and org-agenda-diary-sexp-prefix
  5304. (string-match org-agenda-diary-sexp-prefix r))
  5305. (setq extra (match-string 0 r)
  5306. r (replace-match "" nil nil r)))
  5307. (if (string-match "\\S-" r)
  5308. (setq txt r)
  5309. (setq txt "SEXP entry returned empty string"))
  5310. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5311. (org-add-props txt props 'org-marker marker
  5312. 'date date 'todo-state todo-state
  5313. 'level level 'type "sexp" 'warntime warntime)
  5314. (push txt ee)))))
  5315. (nreverse ee)))
  5316. ;; Calendar sanity: define some functions that are independent of
  5317. ;; `calendar-date-style'.
  5318. (defun org-anniversary (year month day &optional mark)
  5319. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5320. (with-no-warnings
  5321. (let ((calendar-date-style 'iso))
  5322. (diary-anniversary year month day mark))))
  5323. (defun org-cyclic (N year month day &optional mark)
  5324. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5325. (with-no-warnings
  5326. (let ((calendar-date-style 'iso))
  5327. (diary-cyclic N year month day mark))))
  5328. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5329. "Like `diary-block', but with fixed (ISO) order of arguments."
  5330. (with-no-warnings
  5331. (let ((calendar-date-style 'iso))
  5332. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5333. (defun org-date (year month day &optional mark)
  5334. "Like `diary-date', but with fixed (ISO) order of arguments."
  5335. (with-no-warnings
  5336. (let ((calendar-date-style 'iso))
  5337. (diary-date year month day mark))))
  5338. ;; Define the `org-class' function
  5339. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5340. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5341. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5342. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5343. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5344. `holidays', then any date that is known by the Emacs calendar to be a
  5345. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5346. then those holidays will be skipped."
  5347. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5348. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5349. (d (calendar-absolute-from-gregorian date))
  5350. (h (when skip-weeks (calendar-check-holidays date))))
  5351. (and
  5352. (<= date1 d)
  5353. (<= d date2)
  5354. (= (calendar-day-of-week date) dayname)
  5355. (or (not skip-weeks)
  5356. (progn
  5357. (require 'cal-iso)
  5358. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5359. (not (or (and h (memq 'holidays skip-weeks))
  5360. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5361. entry)))
  5362. (defalias 'org-get-closed 'org-agenda-get-progress)
  5363. (defun org-agenda-get-progress ()
  5364. "Return the logged TODO entries for agenda display."
  5365. (let* ((props (list 'mouse-face 'highlight
  5366. 'org-not-done-regexp org-not-done-regexp
  5367. 'org-todo-regexp org-todo-regexp
  5368. 'org-complex-heading-regexp org-complex-heading-regexp
  5369. 'help-echo
  5370. (format "mouse-2 or RET jump to org file %s"
  5371. (abbreviate-file-name buffer-file-name))))
  5372. (items (if (consp org-agenda-show-log-scoped)
  5373. org-agenda-show-log-scoped
  5374. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5375. '(clock)
  5376. org-agenda-log-mode-items)))
  5377. (parts
  5378. (delq nil
  5379. (list
  5380. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5381. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5382. (when (memq 'state items)
  5383. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5384. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5385. (error "`org-agenda-log-mode-items' is empty")))
  5386. (regexp (concat
  5387. "\\(" parts-re "\\)"
  5388. " *\\["
  5389. (regexp-quote
  5390. (substring
  5391. (format-time-string
  5392. (car org-time-stamp-formats)
  5393. (encode-time ; DATE bound by calendar
  5394. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5395. 1 11))))
  5396. (org-agenda-search-headline-for-time nil)
  5397. marker hdmarker priority category level tags closedp type
  5398. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5399. (goto-char (point-min))
  5400. (while (re-search-forward regexp nil t)
  5401. (catch :skip
  5402. (org-agenda-skip)
  5403. (setq marker (org-agenda-new-marker (match-beginning 0))
  5404. closedp (equal (match-string 1) org-closed-string)
  5405. statep (equal (string-to-char (match-string 1)) ?-)
  5406. clockp (not (or closedp statep))
  5407. state (and statep (match-string 2))
  5408. category (org-get-category (match-beginning 0))
  5409. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5410. (when (string-match "\\]" timestr)
  5411. ;; substring should only run to end of time stamp
  5412. (setq rest (substring timestr (match-end 0))
  5413. timestr (substring timestr 0 (match-end 0)))
  5414. (if (and (not closedp) (not statep)
  5415. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5416. rest))
  5417. (progn (setq timestr (concat (substring timestr 0 -1)
  5418. "-" (match-string 1 rest) "]"))
  5419. (setq clocked (match-string 2 rest)))
  5420. (setq clocked "-")))
  5421. (save-excursion
  5422. (setq extra
  5423. (cond
  5424. ((not org-agenda-log-mode-add-notes) nil)
  5425. (statep
  5426. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5427. (match-string 1)))
  5428. (clockp
  5429. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5430. (match-string 1)))))
  5431. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5432. (throw :skip nil)
  5433. (goto-char (match-beginning 0))
  5434. (setq hdmarker (org-agenda-new-marker)
  5435. inherited-tags
  5436. (or (eq org-agenda-show-inherited-tags 'always)
  5437. (and (listp org-agenda-show-inherited-tags)
  5438. (memq 'todo org-agenda-show-inherited-tags))
  5439. (and (eq org-agenda-show-inherited-tags t)
  5440. (or (eq org-agenda-use-tag-inheritance t)
  5441. (memq 'todo org-agenda-use-tag-inheritance))))
  5442. tags (org-get-tags nil (not inherited-tags))
  5443. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5444. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5445. (setq txt (match-string 1))
  5446. (when extra
  5447. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5448. (setq txt (concat (substring txt 0 (match-beginning 1))
  5449. " - " extra " " (match-string 2 txt)))
  5450. (setq txt (concat txt " - " extra))))
  5451. (setq txt (org-agenda-format-item
  5452. (cond
  5453. (closedp "Closed: ")
  5454. (statep (concat "State: (" state ")"))
  5455. (t (concat "Clocked: (" clocked ")")))
  5456. txt level category tags timestr)))
  5457. (setq type (cond (closedp "closed")
  5458. (statep "state")
  5459. (t "clock")))
  5460. (setq priority 100000)
  5461. (org-add-props txt props
  5462. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5463. 'priority priority 'level level
  5464. 'type type 'date date
  5465. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5466. (push txt ee))
  5467. (goto-char (point-at-eol))))
  5468. (nreverse ee)))
  5469. (defun org-agenda-show-clocking-issues ()
  5470. "Add overlays, showing issues with clocking.
  5471. See also the user option `org-agenda-clock-consistency-checks'."
  5472. (interactive)
  5473. (let* ((pl org-agenda-clock-consistency-checks)
  5474. (re (concat "^[ \t]*"
  5475. org-clock-string
  5476. "[ \t]+"
  5477. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5478. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5479. (tlstart 0.)
  5480. (tlend 0.)
  5481. (maxtime (org-duration-to-minutes
  5482. (or (plist-get pl :max-duration) "24:00")))
  5483. (mintime (org-duration-to-minutes
  5484. (or (plist-get pl :min-duration) 0)))
  5485. (maxgap (org-duration-to-minutes
  5486. ;; default 30:00 means never complain
  5487. (or (plist-get pl :max-gap) "30:00")))
  5488. (gapok (mapcar #'org-duration-to-minutes
  5489. (plist-get pl :gap-ok-around)))
  5490. (def-face (or (plist-get pl :default-face)
  5491. '((:background "DarkRed") (:foreground "white"))))
  5492. issue face m te ts dt ov)
  5493. (goto-char (point-min))
  5494. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5495. (setq issue nil face def-face)
  5496. (catch 'next
  5497. (setq m (org-get-at-bol 'org-marker)
  5498. te nil ts nil)
  5499. (unless (and m (markerp m))
  5500. (setq issue "No valid clock line") (throw 'next t))
  5501. (org-with-point-at m
  5502. (save-excursion
  5503. (goto-char (point-at-bol))
  5504. (unless (looking-at re)
  5505. (error "No valid Clock line")
  5506. (throw 'next t))
  5507. (unless (match-end 3)
  5508. (setq issue
  5509. (format
  5510. "No end time: (%s)"
  5511. (org-duration-from-minutes
  5512. (floor
  5513. (- (float-time (org-current-time))
  5514. (float-time (org-time-string-to-time (match-string 1))))
  5515. 60)))
  5516. face (or (plist-get pl :no-end-time-face) face))
  5517. (throw 'next t))
  5518. (setq ts (match-string 1)
  5519. te (match-string 3)
  5520. ts (float-time (org-time-string-to-time ts))
  5521. te (float-time (org-time-string-to-time te))
  5522. dt (- te ts))))
  5523. (cond
  5524. ((> dt (* 60 maxtime))
  5525. ;; a very long clocking chunk
  5526. (setq issue (format "Clocking interval is very long: %s"
  5527. (org-duration-from-minutes (floor dt 60)))
  5528. face (or (plist-get pl :long-face) face)))
  5529. ((< dt (* 60 mintime))
  5530. ;; a very short clocking chunk
  5531. (setq issue (format "Clocking interval is very short: %s"
  5532. (org-duration-from-minutes (floor dt 60)))
  5533. face (or (plist-get pl :short-face) face)))
  5534. ((and (> tlend 0) (< ts tlend))
  5535. ;; Two clock entries are overlapping
  5536. (setq issue (format "Clocking overlap: %d minutes"
  5537. (/ (- tlend ts) 60))
  5538. face (or (plist-get pl :overlap-face) face)))
  5539. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5540. ;; There is a gap, lets see if we need to report it
  5541. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5542. (setq issue (format "Clocking gap: %d minutes"
  5543. (/ (- ts tlend) 60))
  5544. face (or (plist-get pl :gap-face) face))))
  5545. (t nil)))
  5546. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5547. (when issue
  5548. ;; OK, there was some issue, add an overlay to show the issue
  5549. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5550. (overlay-put ov 'before-string
  5551. (concat
  5552. (org-add-props
  5553. (format "%-43s" (concat " " issue))
  5554. nil
  5555. 'face face)
  5556. "\n"))
  5557. (overlay-put ov 'evaporate t)))))
  5558. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5559. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5560. (catch 'exit
  5561. (unless ok-list
  5562. ;; there are no OK times for gaps...
  5563. (throw 'exit nil))
  5564. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5565. ;; This is more than 24 hours, so it is OK.
  5566. ;; because we have at least one OK time, that must be in the
  5567. ;; 24 hour interval.
  5568. (throw 'exit t))
  5569. ;; We have a shorter gap.
  5570. ;; Now we have to get the minute of the day when these times are
  5571. (let* ((t1dec (org-decode-time t1))
  5572. (t2dec (org-decode-time t2))
  5573. ;; compute the minute on the day
  5574. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5575. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5576. (when (< min2 min1)
  5577. ;; if min2 is smaller than min1, this means it is on the next day.
  5578. ;; Wrap it to after midnight.
  5579. (setq min2 (+ min2 1440)))
  5580. ;; Now check if any of the OK times is in the gap
  5581. (mapc (lambda (x)
  5582. ;; Wrap the time to after midnight if necessary
  5583. (when (< x min1) (setq x (+ x 1440)))
  5584. ;; Check if in interval
  5585. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5586. ok-list)
  5587. ;; Nope, this gap is not OK
  5588. nil)))
  5589. (defun org-agenda-get-deadlines (&optional with-hour)
  5590. "Return the deadline information for agenda display.
  5591. When WITH-HOUR is non-nil, only return deadlines with an hour
  5592. specification like [h]h:mm."
  5593. (let* ((props (list 'mouse-face 'highlight
  5594. 'org-not-done-regexp org-not-done-regexp
  5595. 'org-todo-regexp org-todo-regexp
  5596. 'org-complex-heading-regexp org-complex-heading-regexp
  5597. 'help-echo
  5598. (format "mouse-2 or RET jump to org file %s"
  5599. (abbreviate-file-name buffer-file-name))))
  5600. (regexp (if with-hour
  5601. org-deadline-time-hour-regexp
  5602. org-deadline-time-regexp))
  5603. (today (org-today))
  5604. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5605. (current (calendar-absolute-from-gregorian date))
  5606. deadline-items)
  5607. (goto-char (point-min))
  5608. (while (re-search-forward regexp nil t)
  5609. (catch :skip
  5610. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5611. (org-agenda-skip)
  5612. (let* ((s (match-string 1))
  5613. (pos (1- (match-beginning 1)))
  5614. (todo-state (save-match-data (org-get-todo-state)))
  5615. (done? (member todo-state org-done-keywords))
  5616. (sexp? (string-prefix-p "%%" s))
  5617. ;; DEADLINE is the deadline date for the entry. It is
  5618. ;; either the base date or the last repeat, according
  5619. ;; to `org-agenda-prefer-last-repeat'.
  5620. (deadline
  5621. (cond
  5622. (sexp? (org-agenda--timestamp-to-absolute s current))
  5623. ((or (eq org-agenda-prefer-last-repeat t)
  5624. (member todo-state org-agenda-prefer-last-repeat))
  5625. (org-agenda--timestamp-to-absolute
  5626. s today 'past (current-buffer) pos))
  5627. (t (org-agenda--timestamp-to-absolute s))))
  5628. ;; REPEAT is the future repeat closest from CURRENT,
  5629. ;; according to `org-agenda-show-future-repeats'. If
  5630. ;; the latter is nil, or if the time stamp has no
  5631. ;; repeat part, default to DEADLINE.
  5632. (repeat
  5633. (cond
  5634. (sexp? deadline)
  5635. ((<= current today) deadline)
  5636. ((not org-agenda-show-future-repeats) deadline)
  5637. (t
  5638. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5639. (1+ today)
  5640. current)))
  5641. (org-agenda--timestamp-to-absolute
  5642. s base 'future (current-buffer) pos)))))
  5643. (diff (- deadline current))
  5644. (suppress-prewarning
  5645. (let ((scheduled
  5646. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5647. (org-entry-get nil "SCHEDULED"))))
  5648. (cond
  5649. ((not scheduled) nil)
  5650. ;; The current item has a scheduled date, so
  5651. ;; evaluate its prewarning lead time.
  5652. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5653. ;; Use global prewarning-restart lead time.
  5654. org-agenda-skip-deadline-prewarning-if-scheduled)
  5655. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5656. 'pre-scheduled)
  5657. ;; Set pre-warning to no earlier than SCHEDULED.
  5658. (min (- deadline
  5659. (org-agenda--timestamp-to-absolute scheduled))
  5660. org-deadline-warning-days))
  5661. ;; Set pre-warning to deadline.
  5662. (t 0))))
  5663. (wdays (or suppress-prewarning (org-get-wdays s))))
  5664. (cond
  5665. ;; Only display deadlines at their base date, at future
  5666. ;; repeat occurrences or in today agenda.
  5667. ((= current deadline) nil)
  5668. ((= current repeat) nil)
  5669. ((not today?) (throw :skip nil))
  5670. ;; Upcoming deadline: display within warning period WDAYS.
  5671. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5672. ;; Overdue deadline: warn about it for
  5673. ;; `org-deadline-past-days' duration.
  5674. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5675. ;; Possibly skip done tasks.
  5676. (when (and done?
  5677. (or org-agenda-skip-deadline-if-done
  5678. (/= deadline current)))
  5679. (throw :skip nil))
  5680. (save-excursion
  5681. (re-search-backward "^\\*+[ \t]+" nil t)
  5682. (goto-char (match-end 0))
  5683. (let* ((category (org-get-category))
  5684. (level (make-string (org-reduced-level (org-outline-level))
  5685. ?\s))
  5686. (head (buffer-substring (point) (line-end-position)))
  5687. (inherited-tags
  5688. (or (eq org-agenda-show-inherited-tags 'always)
  5689. (and (listp org-agenda-show-inherited-tags)
  5690. (memq 'agenda org-agenda-show-inherited-tags))
  5691. (and (eq org-agenda-show-inherited-tags t)
  5692. (or (eq org-agenda-use-tag-inheritance t)
  5693. (memq 'agenda
  5694. org-agenda-use-tag-inheritance)))))
  5695. (tags (org-get-tags nil (not inherited-tags)))
  5696. (time
  5697. (cond
  5698. ;; No time of day designation if it is only
  5699. ;; a reminder.
  5700. ((and (/= current deadline) (/= current repeat)) nil)
  5701. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5702. (concat (substring s (match-beginning 1)) " "))
  5703. (t 'time)))
  5704. (item
  5705. (org-agenda-format-item
  5706. ;; Insert appropriate suffixes before deadlines.
  5707. ;; Those only apply to today agenda.
  5708. (pcase-let ((`(,now ,future ,past)
  5709. org-agenda-deadline-leaders))
  5710. (cond
  5711. ((and today? (< deadline today)) (format past (- diff)))
  5712. ((and today? (> deadline today)) (format future diff))
  5713. (t now)))
  5714. head level category tags time))
  5715. (face (org-agenda-deadline-face
  5716. (- 1 (/ (float diff) (max wdays 1)))))
  5717. (upcoming? (and today? (> deadline today)))
  5718. (warntime (get-text-property (point) 'org-appt-warntime)))
  5719. (org-add-props item props
  5720. 'org-marker (org-agenda-new-marker pos)
  5721. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5722. 'warntime warntime
  5723. 'level level
  5724. 'ts-date deadline
  5725. 'priority
  5726. ;; Adjust priority to today reminders about deadlines.
  5727. ;; Overdue deadlines get the highest priority
  5728. ;; increase, then imminent deadlines and eventually
  5729. ;; more distant deadlines.
  5730. (let ((adjust (if today? (- diff) 0)))
  5731. (+ adjust (org-get-priority item)))
  5732. 'todo-state todo-state
  5733. 'type (if upcoming? "upcoming-deadline" "deadline")
  5734. 'date (if upcoming? date deadline)
  5735. 'face (if done? 'org-agenda-done face)
  5736. 'undone-face face
  5737. 'done-face 'org-agenda-done)
  5738. (push item deadline-items))))))
  5739. (nreverse deadline-items)))
  5740. (defun org-agenda-deadline-face (fraction)
  5741. "Return the face to displaying a deadline item.
  5742. FRACTION is what fraction of the head-warning time has passed."
  5743. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5744. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5745. "Return the scheduled information for agenda display.
  5746. Optional argument DEADLINES is a list of deadline items to be
  5747. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5748. scheduled items with an hour specification like [h]h:mm."
  5749. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5750. 'org-todo-regexp org-todo-regexp
  5751. 'org-complex-heading-regexp org-complex-heading-regexp
  5752. 'done-face 'org-agenda-done
  5753. 'mouse-face 'highlight
  5754. 'help-echo
  5755. (format "mouse-2 or RET jump to Org file %s"
  5756. (abbreviate-file-name buffer-file-name))))
  5757. (regexp (if with-hour
  5758. org-scheduled-time-hour-regexp
  5759. org-scheduled-time-regexp))
  5760. (today (org-today))
  5761. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5762. (current (calendar-absolute-from-gregorian date))
  5763. (deadline-pos
  5764. (mapcar (lambda (d)
  5765. (let ((m (get-text-property 0 'org-hd-marker d)))
  5766. (and m (marker-position m))))
  5767. deadlines))
  5768. scheduled-items)
  5769. (goto-char (point-min))
  5770. (while (re-search-forward regexp nil t)
  5771. (catch :skip
  5772. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5773. (org-agenda-skip)
  5774. (let* ((s (match-string 1))
  5775. (pos (1- (match-beginning 1)))
  5776. (todo-state (save-match-data (org-get-todo-state)))
  5777. (donep (member todo-state org-done-keywords))
  5778. (sexp? (string-prefix-p "%%" s))
  5779. ;; SCHEDULE is the scheduled date for the entry. It is
  5780. ;; either the bare date or the last repeat, according
  5781. ;; to `org-agenda-prefer-last-repeat'.
  5782. (schedule
  5783. (cond
  5784. (sexp? (org-agenda--timestamp-to-absolute s current))
  5785. ((or (eq org-agenda-prefer-last-repeat t)
  5786. (member todo-state org-agenda-prefer-last-repeat))
  5787. (org-agenda--timestamp-to-absolute
  5788. s today 'past (current-buffer) pos))
  5789. (t (org-agenda--timestamp-to-absolute s))))
  5790. ;; REPEAT is the future repeat closest from CURRENT,
  5791. ;; according to `org-agenda-show-future-repeats'. If
  5792. ;; the latter is nil, or if the time stamp has no
  5793. ;; repeat part, default to SCHEDULE.
  5794. (repeat
  5795. (cond
  5796. (sexp? schedule)
  5797. ((<= current today) schedule)
  5798. ((not org-agenda-show-future-repeats) schedule)
  5799. (t
  5800. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5801. (1+ today)
  5802. current)))
  5803. (org-agenda--timestamp-to-absolute
  5804. s base 'future (current-buffer) pos)))))
  5805. (diff (- current schedule))
  5806. (warntime (get-text-property (point) 'org-appt-warntime))
  5807. (pastschedp (< schedule today))
  5808. (futureschedp (> schedule today))
  5809. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5810. (suppress-delay
  5811. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5812. (org-entry-get nil "DEADLINE"))))
  5813. (cond
  5814. ((not deadline) nil)
  5815. ;; The current item has a deadline date, so
  5816. ;; evaluate its delay time.
  5817. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5818. ;; Use global delay time.
  5819. (- org-agenda-skip-scheduled-delay-if-deadline))
  5820. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5821. 'post-deadline)
  5822. ;; Set delay to no later than DEADLINE.
  5823. (min (- schedule
  5824. (org-agenda--timestamp-to-absolute deadline))
  5825. org-scheduled-delay-days))
  5826. (t 0))))
  5827. (ddays
  5828. (cond
  5829. ;; Nullify delay when a repeater triggered already
  5830. ;; and the delay is of the form --Xd.
  5831. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5832. (> schedule (org-agenda--timestamp-to-absolute s)))
  5833. 0)
  5834. (suppress-delay
  5835. (let ((org-scheduled-delay-days suppress-delay))
  5836. (org-get-wdays s t t)))
  5837. (t (org-get-wdays s t)))))
  5838. ;; Display scheduled items at base date (SCHEDULE), today if
  5839. ;; scheduled before the current date, and at any repeat past
  5840. ;; today. However, skip delayed items and items that have
  5841. ;; been displayed for more than `org-scheduled-past-days'.
  5842. (unless (and todayp
  5843. habitp
  5844. (bound-and-true-p org-habit-show-all-today))
  5845. (when (or (and (> ddays 0) (< diff ddays))
  5846. (> diff (or (and habitp org-habit-scheduled-past-days)
  5847. org-scheduled-past-days))
  5848. (> schedule current)
  5849. (and (/= current schedule)
  5850. (/= current today)
  5851. (/= current repeat)))
  5852. (throw :skip nil)))
  5853. ;; Possibly skip done tasks.
  5854. (when (and donep
  5855. (or org-agenda-skip-scheduled-if-done
  5856. (/= schedule current)))
  5857. (throw :skip nil))
  5858. ;; Skip entry if it already appears as a deadline, per
  5859. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5860. ;; doesn't apply to habits.
  5861. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5862. ((guard
  5863. (or (not (memq (line-beginning-position 0) deadline-pos))
  5864. habitp))
  5865. nil)
  5866. (`repeated-after-deadline
  5867. (let ((deadline (time-to-days
  5868. (org-get-deadline-time (point)))))
  5869. (and (<= schedule deadline) (> current deadline))))
  5870. (`not-today pastschedp)
  5871. (`t t)
  5872. (_ nil))
  5873. (throw :skip nil))
  5874. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5875. ;; only show them for today. Also skip done habits.
  5876. (when (and habitp
  5877. (or donep
  5878. (not (bound-and-true-p org-habit-show-habits))
  5879. (and (not todayp)
  5880. (bound-and-true-p
  5881. org-habit-show-habits-only-for-today))))
  5882. (throw :skip nil))
  5883. (save-excursion
  5884. (re-search-backward "^\\*+[ \t]+" nil t)
  5885. (goto-char (match-end 0))
  5886. (let* ((category (org-get-category))
  5887. (inherited-tags
  5888. (or (eq org-agenda-show-inherited-tags 'always)
  5889. (and (listp org-agenda-show-inherited-tags)
  5890. (memq 'agenda org-agenda-show-inherited-tags))
  5891. (and (eq org-agenda-show-inherited-tags t)
  5892. (or (eq org-agenda-use-tag-inheritance t)
  5893. (memq 'agenda
  5894. org-agenda-use-tag-inheritance)))))
  5895. (tags (org-get-tags nil (not inherited-tags)))
  5896. (level (make-string (org-reduced-level (org-outline-level))
  5897. ?\s))
  5898. (head (buffer-substring (point) (line-end-position)))
  5899. (time
  5900. (cond
  5901. ;; No time of day designation if it is only a
  5902. ;; reminder, except for habits, which always show
  5903. ;; the time of day. Habits are an exception
  5904. ;; because if there is a time of day, that is
  5905. ;; interpreted to mean they should usually happen
  5906. ;; then, even if doing the habit was missed.
  5907. ((and
  5908. (not habitp)
  5909. (/= current schedule)
  5910. (/= current repeat))
  5911. nil)
  5912. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5913. (concat (substring s (match-beginning 1)) " "))
  5914. (t 'time)))
  5915. (item
  5916. (org-agenda-format-item
  5917. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5918. ;; Show a reminder of a past scheduled today.
  5919. (if (and todayp pastschedp)
  5920. (format past diff)
  5921. first))
  5922. head level category tags time nil habitp))
  5923. (face (cond ((and (not habitp) pastschedp)
  5924. 'org-scheduled-previously)
  5925. ((and habitp futureschedp)
  5926. 'org-agenda-done)
  5927. (todayp 'org-scheduled-today)
  5928. (t 'org-scheduled)))
  5929. (habitp (and habitp (org-habit-parse-todo))))
  5930. (org-add-props item props
  5931. 'undone-face face
  5932. 'face (if donep 'org-agenda-done face)
  5933. 'org-marker (org-agenda-new-marker pos)
  5934. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5935. 'type (if pastschedp "past-scheduled" "scheduled")
  5936. 'date (if pastschedp schedule date)
  5937. 'ts-date schedule
  5938. 'warntime warntime
  5939. 'level level
  5940. 'priority (if habitp (org-habit-get-priority habitp)
  5941. (+ 99 diff (org-get-priority item)))
  5942. 'org-habit-p habitp
  5943. 'todo-state todo-state)
  5944. (push item scheduled-items))))))
  5945. (nreverse scheduled-items)))
  5946. (defun org-agenda-get-blocks ()
  5947. "Return the date-range information for agenda display."
  5948. (let* ((props (list 'face nil
  5949. 'org-not-done-regexp org-not-done-regexp
  5950. 'org-todo-regexp org-todo-regexp
  5951. 'org-complex-heading-regexp org-complex-heading-regexp
  5952. 'mouse-face 'highlight
  5953. 'help-echo
  5954. (format "mouse-2 or RET jump to org file %s"
  5955. (abbreviate-file-name buffer-file-name))))
  5956. (regexp org-tr-regexp)
  5957. (d0 (calendar-absolute-from-gregorian date))
  5958. marker hdmarker ee txt d1 d2 s1 s2 category
  5959. level todo-state tags pos head donep inherited-tags)
  5960. (goto-char (point-min))
  5961. (while (re-search-forward regexp nil t)
  5962. (catch :skip
  5963. (org-agenda-skip)
  5964. (setq pos (point))
  5965. (let ((start-time (match-string 1))
  5966. (end-time (match-string 2)))
  5967. (setq s1 (match-string 1)
  5968. s2 (match-string 2)
  5969. d1 (time-to-days
  5970. (condition-case err
  5971. (org-time-string-to-time s1)
  5972. (error
  5973. (error
  5974. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5975. s1
  5976. pos
  5977. (current-buffer)
  5978. (error-message-string err)))))
  5979. d2 (time-to-days
  5980. (condition-case err
  5981. (org-time-string-to-time s2)
  5982. (error
  5983. (error
  5984. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5985. s2
  5986. pos
  5987. (current-buffer)
  5988. (error-message-string err))))))
  5989. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5990. ;; Only allow days between the limits, because the normal
  5991. ;; date stamps will catch the limits.
  5992. (save-excursion
  5993. (setq todo-state (org-get-todo-state))
  5994. (setq donep (member todo-state org-done-keywords))
  5995. (when (and donep org-agenda-skip-timestamp-if-done)
  5996. (throw :skip t))
  5997. (setq marker (org-agenda-new-marker (point))
  5998. category (org-get-category))
  5999. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6000. (throw :skip nil)
  6001. (goto-char (match-beginning 0))
  6002. (setq hdmarker (org-agenda-new-marker (point))
  6003. inherited-tags
  6004. (or (eq org-agenda-show-inherited-tags 'always)
  6005. (and (listp org-agenda-show-inherited-tags)
  6006. (memq 'agenda org-agenda-show-inherited-tags))
  6007. (and (eq org-agenda-show-inherited-tags t)
  6008. (or (eq org-agenda-use-tag-inheritance t)
  6009. (memq 'agenda org-agenda-use-tag-inheritance))))
  6010. tags (org-get-tags nil (not inherited-tags)))
  6011. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6012. (looking-at "\\*+[ \t]+\\(.*\\)")
  6013. (setq head (match-string 1))
  6014. (let ((remove-re
  6015. (if org-agenda-remove-timeranges-from-blocks
  6016. (concat
  6017. "<" (regexp-quote s1) ".*?>"
  6018. "--"
  6019. "<" (regexp-quote s2) ".*?>")
  6020. nil)))
  6021. (setq txt (org-agenda-format-item
  6022. (format
  6023. (nth (if (= d1 d2) 0 1)
  6024. org-agenda-timerange-leaders)
  6025. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6026. head level category tags
  6027. (cond ((and (= d1 d0) (= d2 d0))
  6028. (concat "<" start-time ">--<" end-time ">"))
  6029. ((= d1 d0)
  6030. (concat "<" start-time ">"))
  6031. ((= d2 d0)
  6032. (concat "<" end-time ">")))
  6033. remove-re))))
  6034. (org-add-props txt props
  6035. 'org-marker marker 'org-hd-marker hdmarker
  6036. 'type "block" 'date date
  6037. 'level level
  6038. 'todo-state todo-state
  6039. 'priority (org-get-priority txt))
  6040. (push txt ee))))
  6041. (goto-char pos)))
  6042. ;; Sort the entries by expiration date.
  6043. (nreverse ee)))
  6044. ;;; Agenda presentation and sorting
  6045. (defvar org-prefix-has-time nil
  6046. "A flag, set by `org-compile-prefix-format'.
  6047. The flag is set if the currently compiled format contains a `%t'.")
  6048. (defvar org-prefix-has-tag nil
  6049. "A flag, set by `org-compile-prefix-format'.
  6050. The flag is set if the currently compiled format contains a `%T'.")
  6051. (defvar org-prefix-has-effort nil
  6052. "A flag, set by `org-compile-prefix-format'.
  6053. The flag is set if the currently compiled format contains a `%e'.")
  6054. (defvar org-prefix-has-breadcrumbs nil
  6055. "A flag, set by `org-compile-prefix-format'.
  6056. The flag is set if the currently compiled format contains a `%b'.")
  6057. (defvar org-prefix-category-length nil
  6058. "Used by `org-compile-prefix-format' to remember the category field width.")
  6059. (defvar org-prefix-category-max-length nil
  6060. "Used by `org-compile-prefix-format' to remember the category field width.")
  6061. (defun org-agenda-get-category-icon (category)
  6062. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6063. (cl-dolist (entry org-agenda-category-icon-alist)
  6064. (when (string-match-p (car entry) category)
  6065. (if (listp (cadr entry))
  6066. (cl-return (cadr entry))
  6067. (cl-return (apply #'create-image (cdr entry)))))))
  6068. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  6069. remove-re habitp)
  6070. "Format TXT to be inserted into the agenda buffer.
  6071. In particular, add the prefix and corresponding text properties.
  6072. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6073. LEVEL may be a string to replace the `%l' specifier.
  6074. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6075. category taken from local variable or file name. It will replace the `%c'
  6076. specifier in the format.
  6077. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6078. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6079. When DOTIME is a string, this string is searched for a time before TXT is.
  6080. TAGS can be the tags of the headline.
  6081. Any match of REMOVE-RE will be removed from TXT."
  6082. ;; We keep the org-prefix-* variable values along with a compiled
  6083. ;; formatter, so that multiple agendas existing at the same time do
  6084. ;; not step on each other toes.
  6085. ;;
  6086. ;; It was inconvenient to make these variables buffer local in
  6087. ;; Agenda buffers, because this function expects to be called with
  6088. ;; the buffer where item comes from being current, and not agenda
  6089. ;; buffer
  6090. (let* ((bindings (car org-prefix-format-compiled))
  6091. (formatter (cadr org-prefix-format-compiled)))
  6092. (cl-loop for (var value) in bindings
  6093. do (set var value))
  6094. (save-match-data
  6095. ;; Diary entries sometimes have extra whitespace at the beginning
  6096. (setq txt (org-trim txt))
  6097. ;; Fix the tags part in txt
  6098. (setq txt (org-agenda-fix-displayed-tags
  6099. txt tags
  6100. org-agenda-show-inherited-tags
  6101. org-agenda-hide-tags-regexp))
  6102. (let* ((category (or category
  6103. (if buffer-file-name
  6104. (file-name-sans-extension
  6105. (file-name-nondirectory buffer-file-name))
  6106. "")))
  6107. (category-icon (org-agenda-get-category-icon category))
  6108. (category-icon (if category-icon
  6109. (propertize " " 'display category-icon)
  6110. ""))
  6111. (effort (and (not (string= txt ""))
  6112. (get-text-property 1 'effort txt)))
  6113. ;; time, tag, effort are needed for the eval of the prefix format
  6114. (tag (if tags (nth (1- (length tags)) tags) ""))
  6115. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6116. time
  6117. (ts (when dotime (concat
  6118. (if (stringp dotime) dotime "")
  6119. (and org-agenda-search-headline-for-time txt))))
  6120. (time-of-day (and dotime (org-get-time-of-day ts)))
  6121. stamp plain s0 s1 s2 rtn srp l
  6122. duration breadcrumbs)
  6123. (and (derived-mode-p 'org-mode) buffer-file-name
  6124. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6125. (when (and dotime time-of-day)
  6126. ;; Extract starting and ending time and move them to prefix
  6127. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6128. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6129. (setq s0 (match-string 0 ts)
  6130. srp (and stamp (match-end 3))
  6131. s1 (match-string (if plain 1 2) ts)
  6132. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6133. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6134. ;; them, we might want to remove them there to avoid duplication.
  6135. ;; The user can turn this off with a variable.
  6136. (when (and org-prefix-has-time
  6137. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6138. (string-match (concat (regexp-quote s0) " *") txt)
  6139. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6140. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6141. (= (match-beginning 0) 0)
  6142. t))
  6143. (setq txt (replace-match "" nil nil txt))))
  6144. ;; Normalize the time(s) to 24 hour
  6145. (when s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6146. (when s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6147. ;; Try to set s2 if s1 and
  6148. ;; `org-agenda-default-appointment-duration' are set
  6149. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6150. (setq s2
  6151. (org-duration-from-minutes
  6152. (+ (org-duration-to-minutes s1 t)
  6153. org-agenda-default-appointment-duration)
  6154. nil t)))
  6155. ;; Compute the duration
  6156. (when s2
  6157. (setq duration (- (org-duration-to-minutes s2)
  6158. (org-duration-to-minutes s1)))))
  6159. (when (string-match org-tag-group-re txt)
  6160. ;; Tags are in the string
  6161. (if (or (eq org-agenda-remove-tags t)
  6162. (and org-agenda-remove-tags
  6163. org-prefix-has-tag))
  6164. (setq txt (replace-match "" t t txt))
  6165. (setq txt (replace-match
  6166. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6167. (match-string 1 txt))
  6168. t t txt))))
  6169. (when remove-re
  6170. (while (string-match remove-re txt)
  6171. (setq txt (replace-match "" t t txt))))
  6172. ;; Set org-heading property on `txt' to mark the start of the
  6173. ;; heading.
  6174. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6175. ;; Prepare the variables needed in the eval of the compiled format
  6176. (when org-prefix-has-breadcrumbs
  6177. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6178. (let ((s (org-format-outline-path (org-get-outline-path)
  6179. (1- (frame-width))
  6180. nil org-agenda-breadcrumbs-separator)))
  6181. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6182. (setq time (cond (s2 (concat
  6183. (org-agenda-time-of-day-to-ampm-maybe s1)
  6184. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6185. (when org-agenda-timegrid-use-ampm " ")))
  6186. (s1 (concat
  6187. (org-agenda-time-of-day-to-ampm-maybe s1)
  6188. (if org-agenda-timegrid-use-ampm
  6189. (concat time-grid-trailing-characters " ")
  6190. time-grid-trailing-characters)))
  6191. (t ""))
  6192. extra (or (and (not habitp) extra) "")
  6193. category (if (symbolp category) (symbol-name category) category)
  6194. level (or level ""))
  6195. (if (string-match org-link-bracket-re category)
  6196. (progn
  6197. (setq l (string-width (or (match-string 2) (match-string 1))))
  6198. (when (< l (or org-prefix-category-length 0))
  6199. (setq category (copy-sequence category))
  6200. (org-add-props category nil
  6201. 'extra-space (make-string
  6202. (- org-prefix-category-length l 1) ?\ ))))
  6203. (when (and org-prefix-category-max-length
  6204. (>= (length category) org-prefix-category-max-length))
  6205. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6206. ;; Evaluate the compiled format
  6207. (setq rtn (concat (eval formatter) txt))
  6208. ;; And finally add the text properties
  6209. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6210. (org-add-props rtn nil
  6211. 'org-category category
  6212. 'tags (mapcar 'org-downcase-keep-props tags)
  6213. 'org-highest-priority org-highest-priority
  6214. 'org-lowest-priority org-lowest-priority
  6215. 'time-of-day time-of-day
  6216. 'duration duration
  6217. 'breadcrumbs breadcrumbs
  6218. 'txt txt
  6219. 'level level
  6220. 'time time
  6221. 'extra extra
  6222. 'format org-prefix-format-compiled
  6223. 'dotime dotime)))))
  6224. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6225. "Remove tags string from TXT, and add a modified list of tags.
  6226. The modified list may contain inherited tags, and tags matched by
  6227. `org-agenda-hide-tags-regexp' will be removed."
  6228. (when (or add-inherited hide-re)
  6229. (when (string-match org-tag-group-re txt)
  6230. (setq txt (substring txt 0 (match-beginning 0))))
  6231. (setq tags
  6232. (delq nil
  6233. (mapcar (lambda (tg)
  6234. (if (or (and hide-re (string-match hide-re tg))
  6235. (and (not add-inherited)
  6236. (get-text-property 0 'inherited tg)))
  6237. nil
  6238. tg))
  6239. tags)))
  6240. (when tags
  6241. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6242. i)
  6243. (setq txt (concat txt " :"
  6244. (mapconcat
  6245. (lambda (x)
  6246. (setq i (get-text-property 0 'inherited x))
  6247. (if (and have-i (not i))
  6248. (progn
  6249. (setq have-i nil)
  6250. (concat ":" x))
  6251. x))
  6252. tags ":")
  6253. (if have-i "::" ":"))))))
  6254. txt)
  6255. (defun org-downcase-keep-props (s)
  6256. (let ((props (text-properties-at 0 s)))
  6257. (setq s (downcase s))
  6258. (add-text-properties 0 (length s) props s)
  6259. s))
  6260. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6261. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6262. "Add a time-grid for agenda items which need it.
  6263. LIST is the list of agenda items formatted by `org-agenda-list'.
  6264. NDAYS is the span of the current agenda view.
  6265. TODAYP is t when the current agenda view is on today."
  6266. (catch 'exit
  6267. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6268. ((and todayp (member 'today (car org-agenda-time-grid))))
  6269. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6270. ((member 'weekly (car org-agenda-time-grid)))
  6271. (t (throw 'exit list)))
  6272. (let* ((have (delq nil (mapcar
  6273. (lambda (x) (get-text-property 1 'time-of-day x))
  6274. list)))
  6275. (string (nth 3 org-agenda-time-grid))
  6276. (gridtimes (nth 1 org-agenda-time-grid))
  6277. (req (car org-agenda-time-grid))
  6278. (remove (member 'remove-match req))
  6279. new time)
  6280. (when (and (member 'require-timed req) (not have))
  6281. ;; don't show empty grid
  6282. (throw 'exit list))
  6283. (while (setq time (pop gridtimes))
  6284. (unless (and remove (member time have))
  6285. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6286. (push (org-agenda-format-item
  6287. nil string nil "" nil
  6288. (concat (substring time 0 -2) ":" (substring time -2)))
  6289. new)
  6290. (put-text-property
  6291. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6292. (when (and todayp org-agenda-show-current-time-in-grid)
  6293. (push (org-agenda-format-item
  6294. nil org-agenda-current-time-string nil "" nil
  6295. (format-time-string "%H:%M "))
  6296. new)
  6297. (put-text-property
  6298. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6299. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6300. (append new list)
  6301. (append list new)))))
  6302. (defun org-compile-prefix-format (key)
  6303. "Compile the prefix format into a Lisp form that can be evaluated.
  6304. The resulting form and associated variable bindings is returned
  6305. and stored in the variable `org-prefix-format-compiled'."
  6306. (setq org-prefix-has-time nil
  6307. org-prefix-has-tag nil
  6308. org-prefix-category-length nil
  6309. org-prefix-has-effort nil
  6310. org-prefix-has-breadcrumbs nil)
  6311. (let ((s (cond
  6312. ((stringp org-agenda-prefix-format)
  6313. org-agenda-prefix-format)
  6314. ((assq key org-agenda-prefix-format)
  6315. (cdr (assq key org-agenda-prefix-format)))
  6316. (t " %-12:c%?-12t% s")))
  6317. (start 0)
  6318. varform vars var e c f opt)
  6319. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6320. s start)
  6321. (setq var (or (cdr (assoc (match-string 4 s)
  6322. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6323. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6324. 'eval)
  6325. c (or (match-string 3 s) "")
  6326. opt (match-beginning 1)
  6327. start (1+ (match-beginning 0)))
  6328. (cl-case var
  6329. (time (setq org-prefix-has-time t))
  6330. (tag (setq org-prefix-has-tag t))
  6331. (effort (setq org-prefix-has-effort t))
  6332. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6333. (setq f (concat "%" (match-string 2 s) "s"))
  6334. (when (eq var 'category)
  6335. (setq org-prefix-category-length
  6336. (floor (abs (string-to-number (match-string 2 s)))))
  6337. (setq org-prefix-category-max-length
  6338. (let ((x (match-string 2 s)))
  6339. (save-match-data
  6340. (and (string-match "\\.[0-9]+" x)
  6341. (string-to-number (substring (match-string 0 x) 1)))))))
  6342. (if (eq var 'eval)
  6343. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6344. (if opt
  6345. (setq varform
  6346. `(if (or (equal "" ,var) (equal nil ,var))
  6347. ""
  6348. (format ,f (concat ,var ,c))))
  6349. (setq varform
  6350. `(format ,f (if (or (equal ,var "")
  6351. (equal ,var nil)) ""
  6352. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6353. (setq s (replace-match "%s" t nil s))
  6354. (push varform vars))
  6355. (setq vars (nreverse vars))
  6356. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6357. (setq org-prefix-format-compiled
  6358. (list
  6359. `((org-prefix-has-time ,org-prefix-has-time)
  6360. (org-prefix-has-tag ,org-prefix-has-tag)
  6361. (org-prefix-category-length ,org-prefix-category-length)
  6362. (org-prefix-has-effort ,org-prefix-has-effort)
  6363. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6364. `(format ,s ,@vars))))))
  6365. (defun org-set-sorting-strategy (key)
  6366. (if (symbolp (car org-agenda-sorting-strategy))
  6367. ;; the old format
  6368. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6369. (setq org-agenda-sorting-strategy-selected
  6370. (or (cdr (assq key org-agenda-sorting-strategy))
  6371. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6372. '(time-up category-keep priority-down)))))
  6373. (defun org-get-time-of-day (s &optional string mod24)
  6374. "Check string S for a time of day.
  6375. If found, return it as a military time number between 0 and 2400.
  6376. If not found, return nil.
  6377. The optional STRING argument forces conversion into a 5 character wide string
  6378. HH:MM."
  6379. (save-match-data
  6380. (when
  6381. (and
  6382. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6383. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6384. (not (eq (get-text-property 1 'face s) 'org-link)))
  6385. (let* ((h (string-to-number (match-string 1 s)))
  6386. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6387. (ampm (when (match-end 4) (downcase (match-string 4 s))))
  6388. (am-p (equal ampm "am"))
  6389. (h1 (cond ((not ampm) h)
  6390. ((= h 12) (if am-p 0 12))
  6391. (t (+ h (if am-p 0 12)))))
  6392. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6393. (mod h1 24) h1))
  6394. (t0 (+ (* 100 h2) m))
  6395. (t1 (concat (if (>= h1 24) "+" " ")
  6396. (if (and org-agenda-time-leading-zero
  6397. (< t0 1000)) "0" "")
  6398. (if (< t0 100) "0" "")
  6399. (if (< t0 10) "0" "")
  6400. (int-to-string t0))))
  6401. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6402. (defvar org-agenda-before-sorting-filter-function nil
  6403. "Function to be applied to agenda items prior to sorting.
  6404. Prior to sorting also means just before they are inserted into the agenda.
  6405. To aid sorting, you may revisit the original entries and add more text
  6406. properties which will later be used by the sorting functions.
  6407. The function should take a string argument, an agenda line.
  6408. It has access to the text properties in that line, which contain among
  6409. other things, the property `org-hd-marker' that points to the entry
  6410. where the line comes from. Note that not all lines going into the agenda
  6411. have this property, only most.
  6412. The function should return the modified string. It is probably best
  6413. to ONLY change text properties.
  6414. You can also use this function as a filter, by returning nil for lines
  6415. you don't want to have in the agenda at all. For this application, you
  6416. could bind the variable in the options section of a custom command.")
  6417. (defun org-agenda-finalize-entries (list &optional type)
  6418. "Sort, limit and concatenate the LIST of agenda items.
  6419. The optional argument TYPE tells the agenda type."
  6420. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6421. (cdr (assoc type org-agenda-max-effort)))
  6422. (t org-agenda-max-effort)))
  6423. (max-todo (cond ((listp org-agenda-max-todos)
  6424. (cdr (assoc type org-agenda-max-todos)))
  6425. (t org-agenda-max-todos)))
  6426. (max-tags (cond ((listp org-agenda-max-tags)
  6427. (cdr (assoc type org-agenda-max-tags)))
  6428. (t org-agenda-max-tags)))
  6429. (max-entries (cond ((listp org-agenda-max-entries)
  6430. (cdr (assoc type org-agenda-max-entries)))
  6431. (t org-agenda-max-entries))))
  6432. (when org-agenda-before-sorting-filter-function
  6433. (setq list
  6434. (delq nil
  6435. (mapcar
  6436. org-agenda-before-sorting-filter-function list))))
  6437. (setq list (mapcar 'org-agenda-highlight-todo list)
  6438. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6439. (when max-effort
  6440. (setq list (org-agenda-limit-entries
  6441. list 'effort-minutes max-effort
  6442. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6443. 32767 -1))))))
  6444. (when max-todo
  6445. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6446. (when max-tags
  6447. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6448. (when max-entries
  6449. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6450. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6451. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6452. (mapconcat 'identity list "\n")))
  6453. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6454. "Limit the number of agenda entries."
  6455. (let ((include (and limit (< limit 0))))
  6456. (if limit
  6457. (let ((fun (or fn (lambda (p) (when p 1))))
  6458. (lim 0))
  6459. (delq nil
  6460. (mapcar
  6461. (lambda (e)
  6462. (let ((pval (funcall
  6463. fun (get-text-property (1- (length e))
  6464. prop e))))
  6465. (when pval (setq lim (+ lim pval)))
  6466. (cond ((and pval (<= lim (abs limit))) e)
  6467. ((and include (not pval)) e))))
  6468. list)))
  6469. list)))
  6470. (defun org-agenda-limit-interactively (remove)
  6471. "In agenda, interactively limit entries to various maximums."
  6472. (interactive "P")
  6473. (if remove
  6474. (progn (setq org-agenda-max-entries nil
  6475. org-agenda-max-todos nil
  6476. org-agenda-max-tags nil
  6477. org-agenda-max-effort nil)
  6478. (org-agenda-redo))
  6479. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6480. (msg (cond ((= max ?E) "How many minutes? ")
  6481. ((= max ?e) "How many entries? ")
  6482. ((= max ?t) "How many TODO entries? ")
  6483. ((= max ?T) "How many tagged entries? ")
  6484. (t (user-error "Wrong input"))))
  6485. (num (string-to-number (read-from-minibuffer msg))))
  6486. (cond ((equal max ?e)
  6487. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6488. ((equal max ?t)
  6489. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6490. ((equal max ?T)
  6491. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6492. ((equal max ?E)
  6493. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6494. (org-agenda-fit-window-to-buffer))
  6495. (defun org-agenda-highlight-todo (x)
  6496. (let ((org-done-keywords org-done-keywords-for-agenda)
  6497. (case-fold-search nil)
  6498. re)
  6499. (if (eq x 'line)
  6500. (save-excursion
  6501. (beginning-of-line 1)
  6502. (setq re (org-get-at-bol 'org-todo-regexp))
  6503. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6504. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6505. (add-text-properties (match-beginning 0) (match-end 1)
  6506. (list 'face (org-get-todo-face 1)))
  6507. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6508. (delete-region (match-beginning 1) (1- (match-end 0)))
  6509. (goto-char (match-beginning 1))
  6510. (insert (format org-agenda-todo-keyword-format s)))))
  6511. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6512. (setq re (get-text-property 0 'org-todo-regexp x))
  6513. (when (and re
  6514. ;; Test `pl' because if there's no heading content,
  6515. ;; there's no point matching to highlight. Note
  6516. ;; that if we didn't test `pl' first, and there
  6517. ;; happened to be no keyword from `org-todo-regexp'
  6518. ;; on this heading line, then the `equal' comparison
  6519. ;; afterwards would spuriously succeed in the case
  6520. ;; where `pl' is nil -- causing an args-out-of-range
  6521. ;; error when we try to add text properties to text
  6522. ;; that isn't there.
  6523. pl
  6524. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6525. x pl) pl))
  6526. (add-text-properties
  6527. (or (match-end 1) (match-end 0)) (match-end 0)
  6528. (list 'face (org-get-todo-face (match-string 2 x)))
  6529. x)
  6530. (when (match-end 1)
  6531. (setq x
  6532. (concat
  6533. (substring x 0 (match-end 1))
  6534. (format org-agenda-todo-keyword-format
  6535. (match-string 2 x))
  6536. ;; Remove `display' property as the icon could leak
  6537. ;; on the white space.
  6538. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6539. 'display))
  6540. (substring x (match-end 3)))))))
  6541. x)))
  6542. (defsubst org-cmp-values (a b property)
  6543. "Compare the numeric value of text PROPERTY for string A and B."
  6544. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6545. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6546. (cond ((> pa pb) +1)
  6547. ((< pa pb) -1))))
  6548. (defsubst org-cmp-effort (a b)
  6549. "Compare the effort values of string A and B."
  6550. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6551. ;; `effort-minutes' property is not directly accessible from
  6552. ;; the strings, but is stored as a property in `txt'.
  6553. (ea (or (get-text-property
  6554. 0 'effort-minutes (get-text-property 0 'txt a))
  6555. def))
  6556. (eb (or (get-text-property
  6557. 0 'effort-minutes (get-text-property 0 'txt b))
  6558. def)))
  6559. (cond ((> ea eb) +1)
  6560. ((< ea eb) -1))))
  6561. (defsubst org-cmp-category (a b)
  6562. "Compare the string values of categories of strings A and B."
  6563. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6564. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6565. (cond ((string-lessp ca cb) -1)
  6566. ((string-lessp cb ca) +1))))
  6567. (defsubst org-cmp-todo-state (a b)
  6568. "Compare the todo states of strings A and B."
  6569. (let* ((ma (or (get-text-property 1 'org-marker a)
  6570. (get-text-property 1 'org-hd-marker a)))
  6571. (mb (or (get-text-property 1 'org-marker b)
  6572. (get-text-property 1 'org-hd-marker b)))
  6573. (fa (and ma (marker-buffer ma)))
  6574. (fb (and mb (marker-buffer mb)))
  6575. (todo-kwds
  6576. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6577. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6578. (ta (or (get-text-property 1 'todo-state a) ""))
  6579. (tb (or (get-text-property 1 'todo-state b) ""))
  6580. (la (- (length (member ta todo-kwds))))
  6581. (lb (- (length (member tb todo-kwds))))
  6582. (donepa (member ta org-done-keywords-for-agenda))
  6583. (donepb (member tb org-done-keywords-for-agenda)))
  6584. (cond ((and donepa (not donepb)) -1)
  6585. ((and (not donepa) donepb) +1)
  6586. ((< la lb) -1)
  6587. ((< lb la) +1))))
  6588. (defsubst org-cmp-alpha (a b)
  6589. "Compare the headlines, alphabetically."
  6590. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6591. (plb (text-property-any 0 (length b) 'org-heading t b))
  6592. (ta (and pla (substring a pla)))
  6593. (tb (and plb (substring b plb)))
  6594. (case-fold-search nil))
  6595. (when pla
  6596. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6597. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6598. (setq ta (substring ta (match-end 0))))
  6599. (setq ta (downcase ta)))
  6600. (when plb
  6601. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6602. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6603. (setq tb (substring tb (match-end 0))))
  6604. (setq tb (downcase tb)))
  6605. (cond ((not (or ta tb)) nil)
  6606. ((not ta) +1)
  6607. ((not tb) -1)
  6608. ((string-lessp ta tb) -1)
  6609. ((string-lessp tb ta) +1))))
  6610. (defsubst org-cmp-tag (a b)
  6611. "Compare the string values of the first tags of A and B."
  6612. (let ((ta (car (last (get-text-property 1 'tags a))))
  6613. (tb (car (last (get-text-property 1 'tags b)))))
  6614. (cond ((not (or ta tb)) nil)
  6615. ((not ta) +1)
  6616. ((not tb) -1)
  6617. ((string-lessp ta tb) -1)
  6618. ((string-lessp tb ta) +1))))
  6619. (defsubst org-cmp-time (a b)
  6620. "Compare the time-of-day values of strings A and B."
  6621. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6622. (ta (or (get-text-property 1 'time-of-day a) def))
  6623. (tb (or (get-text-property 1 'time-of-day b) def)))
  6624. (cond ((< ta tb) -1)
  6625. ((< tb ta) +1))))
  6626. (defsubst org-cmp-ts (a b type)
  6627. "Compare the timestamps values of entries A and B.
  6628. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6629. \"timestamp_ia\", compare within each of these type. When TYPE
  6630. is the empty string, compare all timestamps without respect of
  6631. their type."
  6632. (let* ((def (and (not org-sort-agenda-notime-is-late) -1))
  6633. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6634. (get-text-property 1 'ts-date a))
  6635. def))
  6636. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6637. (get-text-property 1 'ts-date b))
  6638. def)))
  6639. (cond ((if ta (and tb (< ta tb)) tb) -1)
  6640. ((if tb (and ta (< tb ta)) ta) +1))))
  6641. (defsubst org-cmp-habit-p (a b)
  6642. "Compare the todo states of strings A and B."
  6643. (let ((ha (get-text-property 1 'org-habit-p a))
  6644. (hb (get-text-property 1 'org-habit-p b)))
  6645. (cond ((and ha (not hb)) -1)
  6646. ((and (not ha) hb) +1))))
  6647. (defun org-entries-lessp (a b)
  6648. "Predicate for sorting agenda entries."
  6649. ;; The following variables will be used when the form is evaluated.
  6650. ;; So even though the compiler complains, keep them.
  6651. (let* ((ss org-agenda-sorting-strategy-selected)
  6652. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6653. (org-cmp-ts a b "")))
  6654. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6655. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6656. (org-cmp-ts a b "scheduled")))
  6657. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6658. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6659. (org-cmp-ts a b "deadline")))
  6660. (deadline-down (if deadline-up (- deadline-up) nil))
  6661. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6662. (org-cmp-ts a b "timestamp_ia")))
  6663. (tsia-down (if tsia-up (- tsia-up) nil))
  6664. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6665. (org-cmp-ts a b "timestamp")))
  6666. (ts-down (if ts-up (- ts-up) nil))
  6667. (time-up (and (org-em 'time-up 'time-down ss)
  6668. (org-cmp-time a b)))
  6669. (time-down (if time-up (- time-up) nil))
  6670. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6671. (org-cmp-values a b 'org-stats)))
  6672. (stats-down (if stats-up (- stats-up) nil))
  6673. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6674. (org-cmp-values a b 'priority)))
  6675. (priority-down (if priority-up (- priority-up) nil))
  6676. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6677. (org-cmp-effort a b)))
  6678. (effort-down (if effort-up (- effort-up) nil))
  6679. (category-up (and (or (org-em 'category-up 'category-down ss)
  6680. (memq 'category-keep ss))
  6681. (org-cmp-category a b)))
  6682. (category-down (if category-up (- category-up) nil))
  6683. (category-keep (if category-up +1 nil))
  6684. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6685. (org-cmp-tag a b)))
  6686. (tag-down (if tag-up (- tag-up) nil))
  6687. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6688. (org-cmp-todo-state a b)))
  6689. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6690. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6691. (org-cmp-habit-p a b)))
  6692. (habit-down (if habit-up (- habit-up) nil))
  6693. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6694. (org-cmp-alpha a b)))
  6695. (alpha-down (if alpha-up (- alpha-up) nil))
  6696. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6697. user-defined-up user-defined-down)
  6698. (when (and need-user-cmp org-agenda-cmp-user-defined
  6699. (functionp org-agenda-cmp-user-defined))
  6700. (setq user-defined-up
  6701. (funcall org-agenda-cmp-user-defined a b)
  6702. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6703. (cdr (assoc
  6704. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6705. '((-1 . t) (1 . nil) (nil . nil))))))
  6706. ;;; Agenda restriction lock
  6707. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6708. "Overlay to mark the headline to which agenda commands are restricted.")
  6709. (overlay-put org-agenda-restriction-lock-overlay
  6710. 'face 'org-agenda-restriction-lock)
  6711. (overlay-put org-agenda-restriction-lock-overlay
  6712. 'help-echo "Agendas are currently limited to this subtree.")
  6713. (delete-overlay org-agenda-restriction-lock-overlay)
  6714. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6715. "Set the restriction lock to the agenda item at point from within the agenda.
  6716. When called with a `\\[universal-argument]' prefix, restrict to
  6717. the file which contains the item.
  6718. Argument ARG is the prefix argument."
  6719. (interactive "P")
  6720. (unless (derived-mode-p 'org-agenda-mode)
  6721. (user-error "Not in an Org agenda buffer"))
  6722. (let* ((marker (or (org-get-at-bol 'org-marker)
  6723. (org-agenda-error)))
  6724. (buffer (marker-buffer marker))
  6725. (pos (marker-position marker)))
  6726. (with-current-buffer buffer
  6727. (goto-char pos)
  6728. (org-agenda-set-restriction-lock arg))))
  6729. ;;;###autoload
  6730. (defun org-agenda-set-restriction-lock (&optional type)
  6731. "Set restriction lock for agenda to current subtree or file.
  6732. When in a restricted subtree, remove it.
  6733. The restriction will span over the entire file if TYPE is `file',
  6734. or if type is '(4), or if the cursor is before the first headline
  6735. in the file. Otherwise, only apply the restriction to the current
  6736. subtree."
  6737. (interactive "P")
  6738. (if (and org-agenda-overriding-restriction
  6739. (member org-agenda-restriction-lock-overlay
  6740. (overlays-at (point)))
  6741. (equal (overlay-start org-agenda-restriction-lock-overlay)
  6742. (point)))
  6743. (org-agenda-remove-restriction-lock 'noupdate)
  6744. (org-agenda-remove-restriction-lock 'noupdate)
  6745. (and (equal type '(4)) (setq type 'file))
  6746. (setq type (cond
  6747. (type type)
  6748. ((org-at-heading-p) 'subtree)
  6749. ((condition-case nil (org-back-to-heading t) (error nil))
  6750. 'subtree)
  6751. (t 'file)))
  6752. (if (eq type 'subtree)
  6753. (progn
  6754. (setq org-agenda-restrict (current-buffer))
  6755. (setq org-agenda-overriding-restriction 'subtree)
  6756. (put 'org-agenda-files 'org-restrict
  6757. (list (buffer-file-name (buffer-base-buffer))))
  6758. (org-back-to-heading t)
  6759. (move-overlay org-agenda-restriction-lock-overlay
  6760. (point)
  6761. (if org-agenda-restriction-lock-highlight-subtree
  6762. (save-excursion (org-end-of-subtree t t) (point))
  6763. (point-at-eol)))
  6764. (move-marker org-agenda-restrict-begin (point))
  6765. (move-marker org-agenda-restrict-end
  6766. (save-excursion (org-end-of-subtree t t)))
  6767. (message "Locking agenda restriction to subtree"))
  6768. (put 'org-agenda-files 'org-restrict
  6769. (list (buffer-file-name (buffer-base-buffer))))
  6770. (setq org-agenda-restrict nil)
  6771. (setq org-agenda-overriding-restriction 'file)
  6772. (move-marker org-agenda-restrict-begin nil)
  6773. (move-marker org-agenda-restrict-end nil)
  6774. (message "Locking agenda restriction to file"))
  6775. (setq current-prefix-arg nil))
  6776. (org-agenda-maybe-redo))
  6777. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6778. "Remove agenda restriction lock."
  6779. (interactive "P")
  6780. (if (not org-agenda-restrict)
  6781. (message "No agenda restriction to remove.")
  6782. (delete-overlay org-agenda-restriction-lock-overlay)
  6783. (delete-overlay org-speedbar-restriction-lock-overlay)
  6784. (setq org-agenda-overriding-restriction nil)
  6785. (setq org-agenda-restrict nil)
  6786. (put 'org-agenda-files 'org-restrict nil)
  6787. (move-marker org-agenda-restrict-begin nil)
  6788. (move-marker org-agenda-restrict-end nil)
  6789. (setq current-prefix-arg nil)
  6790. (message "Agenda restriction lock removed")
  6791. (or noupdate (org-agenda-maybe-redo))))
  6792. (defun org-agenda-maybe-redo ()
  6793. "If there is any window showing the agenda view, update it."
  6794. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6795. org-agenda-buffer-name)
  6796. t))
  6797. (w0 (selected-window)))
  6798. (when w
  6799. (select-window w)
  6800. (org-agenda-redo)
  6801. (select-window w0)
  6802. (if org-agenda-overriding-restriction
  6803. (message "Agenda view shifted to new %s restriction"
  6804. org-agenda-overriding-restriction)
  6805. (message "Agenda restriction lock removed")))))
  6806. ;;; Agenda commands
  6807. (defun org-agenda-check-type (error &rest types)
  6808. "Check if agenda buffer or component is of allowed type.
  6809. If ERROR is non-nil, throw an error, otherwise just return nil.
  6810. Allowed types are `agenda' `todo' `tags' `search'."
  6811. (cond ((not org-agenda-type)
  6812. (error "No Org agenda currently displayed"))
  6813. ((memq org-agenda-type types) t)
  6814. (error
  6815. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  6816. (t nil)))
  6817. (defun org-agenda-Quit ()
  6818. "Exit the agenda, killing the agenda buffer.
  6819. Like `org-agenda-quit', but kill the buffer even when
  6820. `org-agenda-sticky' is non-nil."
  6821. (interactive)
  6822. (org-agenda--quit))
  6823. (defun org-agenda-quit ()
  6824. "Exit the agenda.
  6825. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6826. instead of killing it.
  6827. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6828. the pre-agenda window configuration.
  6829. When column view is active, exit column view instead of the
  6830. agenda."
  6831. (interactive)
  6832. (org-agenda--quit org-agenda-sticky))
  6833. (defun org-agenda--quit (&optional bury)
  6834. (if org-agenda-columns-active
  6835. (org-columns-quit)
  6836. (let ((wconf org-agenda-pre-window-conf)
  6837. (buf (current-buffer))
  6838. (org-agenda-last-indirect-window
  6839. (and (eq org-indirect-buffer-display 'other-window)
  6840. org-agenda-last-indirect-buffer
  6841. (get-buffer-window org-agenda-last-indirect-buffer))))
  6842. (cond
  6843. ((eq org-agenda-window-setup 'other-frame)
  6844. (delete-frame))
  6845. ((and org-agenda-restore-windows-after-quit
  6846. wconf)
  6847. ;; Maybe restore the pre-agenda window configuration. Reset
  6848. ;; `org-agenda-pre-window-conf' before running
  6849. ;; `set-window-configuration', which loses the current buffer.
  6850. (setq org-agenda-pre-window-conf nil)
  6851. (set-window-configuration wconf))
  6852. (t
  6853. (when org-agenda-last-indirect-window
  6854. (delete-window org-agenda-last-indirect-window))
  6855. (and (not (eq org-agenda-window-setup 'current-window))
  6856. (not (one-window-p))
  6857. (delete-window))))
  6858. (if bury
  6859. ;; Set the agenda buffer as the current buffer instead of
  6860. ;; passing it as an argument to `bury-buffer' so that
  6861. ;; `bury-buffer' removes it from the window.
  6862. (with-current-buffer buf
  6863. (bury-buffer))
  6864. (kill-buffer buf)
  6865. (setq org-agenda-archives-mode nil
  6866. org-agenda-buffer nil)))))
  6867. (defun org-agenda-exit ()
  6868. "Exit the agenda, killing Org buffers loaded by the agenda.
  6869. Like `org-agenda-Quit', but kill any buffers that were created by
  6870. the agenda. Org buffers visited directly by the user will not be
  6871. touched. Also, exit the agenda even if it is in column view."
  6872. (interactive)
  6873. (when org-agenda-columns-active
  6874. (org-columns-quit))
  6875. (org-release-buffers org-agenda-new-buffers)
  6876. (setq org-agenda-new-buffers nil)
  6877. (org-agenda-Quit))
  6878. (defun org-agenda-kill-all-agenda-buffers ()
  6879. "Kill all buffers in `org-agenda-mode'.
  6880. This is used when toggling sticky agendas."
  6881. (interactive)
  6882. (let (blist)
  6883. (dolist (buf (buffer-list))
  6884. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6885. (push buf blist)))
  6886. (mapc 'kill-buffer blist)))
  6887. (defun org-agenda-execute (arg)
  6888. "Execute another agenda command, keeping same window.
  6889. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6890. in the agenda."
  6891. (interactive "P")
  6892. (let ((org-agenda-window-setup 'current-window))
  6893. (org-agenda arg)))
  6894. (defun org-agenda-redo (&optional all)
  6895. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6896. (interactive "P")
  6897. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6898. (cpa (unless (eq all t) current-prefix-arg))
  6899. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6900. (org-agenda-sticky nil)
  6901. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6902. org-agenda-buffer-name))
  6903. (org-agenda-keep-modes t)
  6904. (tag-filter org-agenda-tag-filter)
  6905. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6906. (top-hl-filter org-agenda-top-headline-filter)
  6907. (cat-filter org-agenda-category-filter)
  6908. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6909. (re-filter org-agenda-regexp-filter)
  6910. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6911. (effort-filter org-agenda-effort-filter)
  6912. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6913. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6914. (cols org-agenda-columns-active)
  6915. (line (org-current-line))
  6916. (window-line (- line (org-current-line (window-start))))
  6917. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6918. (redo-cmd (get-text-property p 'org-redo-cmd))
  6919. (last-args (get-text-property p 'org-last-args))
  6920. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6921. (org-agenda-overriding-cmd-arguments
  6922. (unless (eq all t)
  6923. (cond ((listp last-args)
  6924. (cons (or cpa (car last-args)) (cdr last-args)))
  6925. ((stringp last-args)
  6926. last-args))))
  6927. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6928. (put 'org-agenda-tag-filter :preset-filter nil)
  6929. (put 'org-agenda-category-filter :preset-filter nil)
  6930. (put 'org-agenda-regexp-filter :preset-filter nil)
  6931. (put 'org-agenda-effort-filter :preset-filter nil)
  6932. (and cols (org-columns-quit))
  6933. (message "Rebuilding agenda buffer...")
  6934. (if series-redo-cmd
  6935. (eval series-redo-cmd)
  6936. (org-let lprops redo-cmd))
  6937. (setq org-agenda-undo-list nil
  6938. org-agenda-pending-undo-list nil
  6939. org-agenda-tag-filter tag-filter
  6940. org-agenda-category-filter cat-filter
  6941. org-agenda-regexp-filter re-filter
  6942. org-agenda-effort-filter effort-filter
  6943. org-agenda-top-headline-filter top-hl-filter)
  6944. (message "Rebuilding agenda buffer...done")
  6945. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6946. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6947. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6948. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6949. (let ((tag (or tag-filter tag-preset))
  6950. (cat (or cat-filter cat-preset))
  6951. (effort (or effort-filter effort-preset))
  6952. (re (or re-filter re-preset)))
  6953. (when tag (org-agenda-filter-apply tag 'tag t))
  6954. (when cat (org-agenda-filter-apply cat 'category))
  6955. (when effort (org-agenda-filter-apply effort 'effort))
  6956. (when re (org-agenda-filter-apply re 'regexp)))
  6957. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6958. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6959. (org-goto-line line)
  6960. (recenter window-line)))
  6961. (defun org-agenda-redo-all (&optional exhaustive)
  6962. "Rebuild all agenda views in the current buffer.
  6963. With a prefix argument, do so in all agenda buffers."
  6964. (interactive "P")
  6965. (if exhaustive
  6966. (dolist (buffer (buffer-list))
  6967. (with-current-buffer buffer
  6968. (when (derived-mode-p 'org-agenda-mode)
  6969. (org-agenda-redo t))))
  6970. (org-agenda-redo t)))
  6971. (defvar org-global-tags-completion-table nil)
  6972. (defvar org-agenda-filter-form nil)
  6973. (defvar org-agenda-filtered-by-category nil)
  6974. (defsubst org-agenda-get-category ()
  6975. "Return the category of the agenda line."
  6976. (org-get-at-bol 'org-category))
  6977. (defun org-agenda-filter-by-category (strip)
  6978. "Filter lines in the agenda buffer that have a specific category.
  6979. The category is that of the current line.
  6980. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  6981. When there is already a category filter in place, this command removes the filter."
  6982. (interactive "P")
  6983. (if (and org-agenda-filtered-by-category
  6984. org-agenda-category-filter)
  6985. (org-agenda-filter-show-all-cat)
  6986. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6987. (cond
  6988. ((and cat strip)
  6989. (org-agenda-filter-apply
  6990. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6991. (cat
  6992. (org-agenda-filter-apply
  6993. (setq org-agenda-category-filter
  6994. (list (concat "+" cat))) 'category))
  6995. (t (error "No category at point"))))))
  6996. (defun org-find-top-headline (&optional pos)
  6997. "Find the topmost parent headline and return it.
  6998. POS when non-nil is the marker or buffer position to start the
  6999. search from."
  7000. (save-excursion
  7001. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7002. (when pos (goto-char pos))
  7003. ;; Skip up to the topmost parent.
  7004. (while (org-up-heading-safe))
  7005. (ignore-errors (nth 4 (org-heading-components))))))
  7006. (defvar org-agenda-filtered-by-top-headline nil)
  7007. (defun org-agenda-filter-by-top-headline (strip)
  7008. "Keep only those lines that are descendants from the same top headline.
  7009. The top headline is that of the current line. With prefix arg STRIP, hide
  7010. all lines of the category at point."
  7011. (interactive "P")
  7012. (if org-agenda-filtered-by-top-headline
  7013. (progn
  7014. (setq org-agenda-filtered-by-top-headline nil
  7015. org-agenda-top-headline-filter nil)
  7016. (org-agenda-filter-show-all-top-filter))
  7017. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7018. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7019. (error "No top-level headline at point")))))
  7020. (defvar org-agenda-regexp-filter nil)
  7021. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7022. "Filter agenda entries by a regular expressions.
  7023. You will be prompted for the regular expression, and the agenda
  7024. view will only show entries that are matched by that expression.
  7025. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7026. When there is already a regexp filter active, this command removed the
  7027. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7028. an already existing regexp filter."
  7029. (interactive "P")
  7030. (let* ((strip (equal strip-or-accumulate '(4)))
  7031. (accumulate (equal strip-or-accumulate '(16))))
  7032. (cond
  7033. ((and org-agenda-regexp-filter (not accumulate))
  7034. (org-agenda-filter-show-all-re)
  7035. (message "Regexp filter removed"))
  7036. (t (let ((flt (concat (if strip "-" "+")
  7037. (read-from-minibuffer
  7038. (if strip
  7039. "Hide entries matching regexp: "
  7040. "Narrow to entries matching regexp: ")))))
  7041. (push flt org-agenda-regexp-filter)
  7042. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7043. (defvar org-agenda-effort-filter nil)
  7044. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7045. "Filter agenda entries by effort.
  7046. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7047. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7048. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7049. This last option is in practice not very useful, but it is available for
  7050. consistency with the other filter commands."
  7051. (interactive "P")
  7052. (let* ((efforts (split-string
  7053. (or (cdr (assoc (concat org-effort-property "_ALL")
  7054. org-global-properties))
  7055. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7056. ;; XXX: the following handles only up to 10 different
  7057. ;; effort values.
  7058. (allowed-keys (if (null efforts) nil
  7059. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7060. (number-sequence 1 (length efforts)))))
  7061. (keep (equal strip-or-accumulate '(16)))
  7062. (negative (equal strip-or-accumulate '(4)))
  7063. (current org-agenda-effort-filter)
  7064. (op nil))
  7065. (while (not (memq op '(?< ?> ?= ?_)))
  7066. (setq op (read-char-exclusive
  7067. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7068. ;; Select appropriate duration. Ignore non-digit characters.
  7069. (if (eq op ?_)
  7070. (progn
  7071. (org-agenda-filter-show-all-effort)
  7072. (message "Effort filter removed"))
  7073. (let ((prompt
  7074. (apply #'format
  7075. (concat "Effort %c "
  7076. (mapconcat (lambda (s) (concat "[%d]" s))
  7077. efforts
  7078. " "))
  7079. op allowed-keys))
  7080. (eff -1))
  7081. (while (not (memq eff allowed-keys))
  7082. (message prompt)
  7083. (setq eff (- (read-char-exclusive) 48)))
  7084. (org-agenda-filter-show-all-effort)
  7085. (setq org-agenda-effort-filter
  7086. (append
  7087. (list (concat (if negative "-" "+")
  7088. (char-to-string op)
  7089. ;; Numbering is 1 2 3 ... 9 0, but we want
  7090. ;; 0 1 2 ... 8 9.
  7091. (nth (mod (1- eff) 10) efforts)))
  7092. (if keep current nil)))
  7093. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7094. (defun org-agenda-filter (&optional strip-or-accumulate)
  7095. "Prompt for a general filter string and apply it to the agenda.
  7096. The string may contain filter elements like
  7097. +category
  7098. +tag
  7099. +<effort > and = are also allowed as effort operators
  7100. +/regexp/
  7101. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7102. `+' is optional if it is not required to separate two string parts.
  7103. Multiple filter elements can be concatenated without spaces, for example
  7104. +work-John<0:10-/plot/
  7105. selects entries with category `work' and effort estimates below 10 minutes,
  7106. and deselects entries with tag `John' or matching the regexp `plot'.
  7107. During entry of the filter, completion for tags, categories and effort
  7108. values is offered. Since the syntax for categories and tags is identical
  7109. there should be no overlap between categories and tags. If there is, tags
  7110. get priority.
  7111. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7112. entire filter, which can be useful in connection with the prompt history.
  7113. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7114. existing ones. A shortcut for this is to add an additional `+' at the
  7115. beginning of the string, like `+-John'.
  7116. With a triple prefix argument, execute the computed filtering defined in
  7117. the variable `org-agenda-auto-exclude-function'."
  7118. (interactive "P")
  7119. (if (equal strip-or-accumulate '(64))
  7120. ;; Execute the auto-exclude action
  7121. (if (not org-agenda-auto-exclude-function)
  7122. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7123. (org-agenda-filter-show-all-tag)
  7124. (setq org-agenda-tag-filter nil)
  7125. (dolist (tag (org-agenda-get-represented-tags))
  7126. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7127. (when modifier
  7128. (push modifier org-agenda-tag-filter))))
  7129. (unless (null org-agenda-tag-filter)
  7130. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7131. ;; Prompt for a filter and act
  7132. (let* ((tag-list (org-agenda-get-represented-tags))
  7133. (category-list (org-agenda-get-represented-categories))
  7134. (negate (equal strip-or-accumulate '(4)))
  7135. (f-string (completing-read
  7136. (concat
  7137. (if negate "Negative filter" "Filter")
  7138. " [+cat-tag<0:10-/regexp/]: ")
  7139. 'org-agenda-filter-completion-function))
  7140. (keep (or (if (string-match "^\\+[+-]" f-string)
  7141. (progn (setq f-string (substring f-string 1)) t))
  7142. (equal strip-or-accumulate '(16))))
  7143. (fc (if keep org-agenda-category-filter))
  7144. (ft (if keep org-agenda-tag-filter))
  7145. (fe (if keep org-agenda-effort-filter))
  7146. (fr (if keep org-agenda-regexp-filter))
  7147. pm s)
  7148. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7149. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7150. (when negate
  7151. (setq pm (if (equal pm "+") "-" "+")))
  7152. (cond
  7153. ((match-beginning 3)
  7154. ;; category or tag
  7155. (setq s (match-string 3 f-string))
  7156. (cond
  7157. ((member s tag-list)
  7158. (add-to-list 'ft (concat pm s) 'append 'equal))
  7159. ((member s category-list)
  7160. (add-to-list 'fc (concat pm s) 'append 'equal))
  7161. (t (message
  7162. "`%s%s' filter ignored because tag/category is not represented"
  7163. pm s))))
  7164. ((match-beginning 4)
  7165. ;; effort
  7166. (add-to-list 'fe (concat pm (match-string 4 f-string)) t 'equal))
  7167. ((match-beginning 5)
  7168. ;; regexp
  7169. (add-to-list 'fr (concat pm (match-string 6 f-string)) t 'equal)))
  7170. (setq f-string (substring f-string (match-end 0))))
  7171. (org-agenda-filter-remove-all)
  7172. (and fc (org-agenda-filter-apply
  7173. (setq org-agenda-category-filter fc) 'category))
  7174. (and ft (org-agenda-filter-apply
  7175. (setq org-agenda-tag-filter ft) 'tag))
  7176. (and fe (org-agenda-filter-apply
  7177. (setq org-agenda-effort-filter fe) 'effort))
  7178. (and fr (org-agenda-filter-apply
  7179. (setq org-agenda-regexp-filter fr) 'regexp))
  7180. )))
  7181. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7182. "Complete a complex filter string
  7183. FLAG specifies the type of completion operation to perform. This
  7184. function is passed as a collection function to `completing-read',
  7185. which see."
  7186. (let ((completion-ignore-case t) ;tags are case-sensitive
  7187. (confirm (lambda (x) (stringp x)))
  7188. (prefix "")
  7189. (operator "")
  7190. table)
  7191. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7192. (setq prefix (match-string 1 string)
  7193. operator (match-string 2 string)
  7194. string (match-string 3 string)))
  7195. (cond
  7196. ((member operator '("+" "-" "" nil))
  7197. (setq table (append (org-agenda-get-represented-categories)
  7198. (org-agenda-get-represented-tags))))
  7199. ((member operator '("<" ">" "="))
  7200. (setq table (split-string
  7201. (or (cdr (assoc (concat org-effort-property "_ALL")
  7202. org-global-properties))
  7203. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7204. " +")))
  7205. (t (setq table nil)))
  7206. (pcase flag
  7207. (`t (all-completions string table confirm))
  7208. (`lambda (assoc string table)) ;exact match?
  7209. (`nil
  7210. (pcase (try-completion string table confirm)
  7211. ((and completion (pred stringp))
  7212. (concat prefix completion))
  7213. (completion completion)))
  7214. (_ nil))))
  7215. (defun org-agenda-filter-remove-all ()
  7216. "Remove all filters from the current agenda buffer."
  7217. (interactive)
  7218. (when org-agenda-tag-filter
  7219. (org-agenda-filter-show-all-tag))
  7220. (when org-agenda-category-filter
  7221. (org-agenda-filter-show-all-cat))
  7222. (when org-agenda-regexp-filter
  7223. (org-agenda-filter-show-all-re))
  7224. (when org-agenda-top-headline-filter
  7225. (org-agenda-filter-show-all-top-filter))
  7226. (when org-agenda-effort-filter
  7227. (org-agenda-filter-show-all-effort))
  7228. (org-agenda-finalize))
  7229. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7230. "Keep only those lines in the agenda buffer that have a specific tag.
  7231. The tag is selected with its fast selection letter, as configured.
  7232. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7233. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7234. instead of replacing it.
  7235. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7236. i.e. don't
  7237. filter on all its group members.
  7238. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  7239. should be used to exclude the search - the interactive user can
  7240. also press `-' or `+' to switch between filtering and excluding."
  7241. (interactive "P")
  7242. (let* ((alist org-tag-alist-for-agenda)
  7243. (seen-chars nil)
  7244. (tag-chars (mapconcat
  7245. (lambda (x) (if (and (not (symbolp (car x)))
  7246. (cdr x)
  7247. (not (member (cdr x) seen-chars)))
  7248. (progn
  7249. (push (cdr x) seen-chars)
  7250. (char-to-string (cdr x)))
  7251. ""))
  7252. org-tag-alist-for-agenda ""))
  7253. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7254. (string-to-list tag-chars)))
  7255. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7256. (accumulate (equal strip-or-accumulate '(16)))
  7257. (expand (not (equal strip-or-accumulate '(64))))
  7258. (inhibit-read-only t)
  7259. (current org-agenda-tag-filter)
  7260. a n tag)
  7261. (unless char
  7262. (while (not (memq char valid-char-list))
  7263. (org-unlogged-message
  7264. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7265. (if exclude "Exclude[+]" "Filter[-]")
  7266. (if expand "" " (no grouptag expand)")
  7267. tag-chars
  7268. (if org-agenda-auto-exclude-function "[RET] " ""))
  7269. (setq char (read-char-exclusive))
  7270. ;; Excluding or filtering down
  7271. (cond ((eq char ?-) (setq exclude t))
  7272. ((eq char ?+) (setq exclude nil)))))
  7273. (when (eq char ?\t)
  7274. (unless (local-variable-p 'org-global-tags-completion-table)
  7275. (setq-local org-global-tags-completion-table
  7276. (org-global-tags-completion-table)))
  7277. (let ((completion-ignore-case t))
  7278. (setq tag (completing-read
  7279. "Tag: " org-global-tags-completion-table nil t))))
  7280. (cond
  7281. ((eq char ?\r)
  7282. (org-agenda-filter-show-all-tag)
  7283. (when org-agenda-auto-exclude-function
  7284. (setq org-agenda-tag-filter nil)
  7285. (dolist (tag (org-agenda-get-represented-tags))
  7286. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7287. (when modifier
  7288. (push modifier org-agenda-tag-filter))))
  7289. (unless (null org-agenda-tag-filter)
  7290. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7291. ((eq char ?\\)
  7292. (org-agenda-filter-show-all-tag)
  7293. (when (get 'org-agenda-tag-filter :preset-filter)
  7294. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7295. ((eq char ?.)
  7296. (setq org-agenda-tag-filter
  7297. (mapcar (lambda(tag) (concat "+" tag))
  7298. (org-get-at-bol 'tags)))
  7299. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7300. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7301. ((or (eq char ?\s)
  7302. (setq a (rassoc char alist))
  7303. (and tag (setq a (cons tag nil))))
  7304. (org-agenda-filter-show-all-tag)
  7305. (setq tag (car a))
  7306. (setq org-agenda-tag-filter
  7307. (cons (concat (if exclude "-" "+") tag)
  7308. (if accumulate current nil)))
  7309. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7310. (t (error "Invalid tag selection character %c" char)))))
  7311. (defun org-agenda-get-represented-categories ()
  7312. "Return a list of all categories used in this agenda buffer."
  7313. (or org-agenda-represented-categories
  7314. (when (derived-mode-p 'org-agenda-mode)
  7315. (let ((pos (point-min)) categories)
  7316. (while (and (< pos (point-max))
  7317. (setq pos (next-single-property-change
  7318. pos 'org-category nil (point-max))))
  7319. (push (get-text-property pos 'org-category) categories))
  7320. (setq org-agenda-represented-categories
  7321. (nreverse (org-uniquify (delq nil categories))))))))
  7322. (defun org-agenda-get-represented-tags ()
  7323. "Return a list of all tags used in this agenda buffer.
  7324. These will be lower-case, for filtering."
  7325. (or org-agenda-represented-tags
  7326. (when (derived-mode-p 'org-agenda-mode)
  7327. (let ((pos (point-min)) tags-lists tt)
  7328. (while (and (< pos (point-max))
  7329. (setq pos (next-single-property-change
  7330. pos 'tags nil (point-max))))
  7331. (setq tt (get-text-property pos 'tags))
  7332. (if tt (push tt tags-lists)))
  7333. (setq org-agenda-represented-tags
  7334. (nreverse (org-uniquify
  7335. (delq nil (apply 'append tags-lists)))))))))
  7336. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7337. "Create the form that tests a line for agenda filter. Optional
  7338. argument EXPAND can be used for the TYPE tag and will expand the
  7339. tags in the FILTER if any of the tags in FILTER are grouptags."
  7340. (let (f f1)
  7341. (cond
  7342. ;; Tag filter
  7343. ((eq type 'tag)
  7344. (setq filter
  7345. (delete-dups
  7346. (append (get 'org-agenda-tag-filter :preset-filter)
  7347. filter)))
  7348. (dolist (x filter)
  7349. (let ((op (string-to-char x)))
  7350. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7351. (setq x (list x)))
  7352. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7353. (push f1 f))))
  7354. ;; Category filter
  7355. ((eq type 'category)
  7356. (setq filter
  7357. (delete-dups
  7358. (append (get 'org-agenda-category-filter :preset-filter)
  7359. filter)))
  7360. (dolist (x filter)
  7361. (if (equal "-" (substring x 0 1))
  7362. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7363. (setq f1 (list 'equal (substring x 1) 'cat)))
  7364. (push f1 f)))
  7365. ;; Regexp filter
  7366. ((eq type 'regexp)
  7367. (setq filter
  7368. (delete-dups
  7369. (append (get 'org-agenda-regexp-filter :preset-filter)
  7370. filter)))
  7371. (dolist (x filter)
  7372. (if (equal "-" (substring x 0 1))
  7373. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7374. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7375. (push f1 f)))
  7376. ;; Effort filter
  7377. ((eq type 'effort)
  7378. (setq filter
  7379. (delete-dups
  7380. (append (get 'org-agenda-effort-filter :preset-filter)
  7381. filter)))
  7382. (dolist (x filter)
  7383. (push (org-agenda-filter-effort-form x) f))))
  7384. (cons (if (eq type 'category) 'or 'and) (nreverse f))))
  7385. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7386. "Return a form associated to tag-expression TAGS.
  7387. Build a form testing a line for agenda filter for
  7388. tag-expressions. OP is an operator of type CHAR that allows the
  7389. function to set the right switches in the returned form."
  7390. (let (form)
  7391. ;; Any of the expressions can match if OP is +, all must match if
  7392. ;; the operator is -.
  7393. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7394. (let* ((tag (substring x 1))
  7395. (f (cond
  7396. ((string= "" tag) 'tags)
  7397. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7398. ;; TAG is a regexp.
  7399. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7400. (t (list 'member (downcase tag) 'tags)))))
  7401. (push (if (eq op ?-) (list 'not f) f) form)))))
  7402. (defun org-agenda-filter-effort-form (e)
  7403. "Return the form to compare the effort of the current line with what E says.
  7404. E looks like \"+<2:25\"."
  7405. (let (op)
  7406. (setq e (substring e 1))
  7407. (setq op (string-to-char e) e (substring e 1))
  7408. (setq op (cond ((equal op ?<) '<=)
  7409. ((equal op ?>) '>=)
  7410. ((equal op ??) op)
  7411. (t '=)))
  7412. (list 'org-agenda-compare-effort (list 'quote op)
  7413. (org-duration-to-minutes e))))
  7414. (defun org-agenda-compare-effort (op value)
  7415. "Compare the effort of the current line with VALUE, using OP.
  7416. If the line does not have an effort defined, return nil."
  7417. ;; `effort-minutes' property cannot be extracted directly from
  7418. ;; current line but is stored as a property in `txt'.
  7419. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7420. (funcall op
  7421. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7422. value)))
  7423. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7424. "Expand group tags in FILTER for the agenda.
  7425. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7426. (if org-group-tags
  7427. (let ((case-fold-search t) rtn)
  7428. (mapc
  7429. (lambda (f)
  7430. (let (f0 dir)
  7431. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7432. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7433. (setq dir (if no-operator "" "+") f0 f))
  7434. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7435. (org-tags-expand f0 t t))
  7436. rtn))))
  7437. filter)
  7438. (reverse rtn))
  7439. filter))
  7440. (defun org-agenda-filter-apply (filter type &optional expand)
  7441. "Set FILTER as the new agenda filter and apply it. Optional
  7442. argument EXPAND can be used for the TYPE tag and will expand the
  7443. tags in the FILTER if any of the tags in FILTER are grouptags."
  7444. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7445. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7446. (let (tags cat txt)
  7447. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  7448. filter type expand))
  7449. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7450. ;; category is used as the filter:
  7451. (setq org-agenda-filtered-by-category
  7452. (and (eq type 'category)
  7453. (not (equal (substring (car filter) 0 1) "-"))))
  7454. (org-agenda-set-mode-name)
  7455. (save-excursion
  7456. (goto-char (point-min))
  7457. (while (not (eobp))
  7458. (if (org-get-at-bol 'org-hd-marker)
  7459. (progn
  7460. (setq tags (org-get-at-bol 'tags)
  7461. cat (org-agenda-get-category)
  7462. txt (org-get-at-bol 'txt))
  7463. (unless (eval org-agenda-filter-form)
  7464. (org-agenda-filter-hide-line type))
  7465. (beginning-of-line 2))
  7466. (beginning-of-line 2))))
  7467. (when (get-char-property (point) 'invisible)
  7468. (ignore-errors (org-agenda-previous-line)))))
  7469. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7470. "Filter by top headline HL."
  7471. (org-agenda-set-mode-name)
  7472. (save-excursion
  7473. (goto-char (point-min))
  7474. (while (not (eobp))
  7475. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7476. (tophl (and pos (org-find-top-headline pos))))
  7477. (when (and tophl (funcall (if negative 'identity 'not)
  7478. (string= hl tophl)))
  7479. (org-agenda-filter-hide-line 'top-headline)))
  7480. (beginning-of-line 2)))
  7481. (when (get-char-property (point) 'invisible)
  7482. (org-agenda-previous-line))
  7483. (setq org-agenda-top-headline-filter hl
  7484. org-agenda-filtered-by-top-headline t))
  7485. (defun org-agenda-filter-hide-line (type)
  7486. "Hide lines with TYPE in the agenda buffer."
  7487. (let* ((b (max (point-min) (1- (point-at-bol))))
  7488. (e (point-at-eol)))
  7489. (let ((inhibit-read-only t))
  7490. (add-text-properties
  7491. b e `(invisible org-filtered org-filter-type ,type)))))
  7492. (defun org-agenda-remove-filter (type)
  7493. (interactive)
  7494. "Remove filter of type TYPE from the agenda buffer."
  7495. (save-excursion
  7496. (goto-char (point-min))
  7497. (let ((inhibit-read-only t) pos)
  7498. (while (setq pos (text-property-any (point) (point-max)
  7499. 'org-filter-type type))
  7500. (goto-char pos)
  7501. (remove-text-properties
  7502. (point) (next-single-property-change (point) 'org-filter-type)
  7503. `(invisible org-filtered org-filter-type ,type))))
  7504. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7505. (setq org-agenda-filter-form nil)
  7506. (org-agenda-set-mode-name)
  7507. (org-agenda-finalize)))
  7508. (defun org-agenda-filter-show-all-tag nil
  7509. (org-agenda-remove-filter 'tag))
  7510. (defun org-agenda-filter-show-all-re nil
  7511. (org-agenda-remove-filter 'regexp))
  7512. (defun org-agenda-filter-show-all-effort nil
  7513. (org-agenda-remove-filter 'effort))
  7514. (defun org-agenda-filter-show-all-cat nil
  7515. (org-agenda-remove-filter 'category))
  7516. (defun org-agenda-filter-show-all-top-filter nil
  7517. (org-agenda-remove-filter 'top-headline))
  7518. (defun org-agenda-manipulate-query-add ()
  7519. "Manipulate the query by adding a search term with positive selection.
  7520. Positive selection means the term must be matched for selection of an entry."
  7521. (interactive)
  7522. (org-agenda-manipulate-query ?\[))
  7523. (defun org-agenda-manipulate-query-subtract ()
  7524. "Manipulate the query by adding a search term with negative selection.
  7525. Negative selection means term must not be matched for selection of an entry."
  7526. (interactive)
  7527. (org-agenda-manipulate-query ?\]))
  7528. (defun org-agenda-manipulate-query-add-re ()
  7529. "Manipulate the query by adding a search regexp with positive selection.
  7530. Positive selection means the regexp must match for selection of an entry."
  7531. (interactive)
  7532. (org-agenda-manipulate-query ?\{))
  7533. (defun org-agenda-manipulate-query-subtract-re ()
  7534. "Manipulate the query by adding a search regexp with negative selection.
  7535. Negative selection means regexp must not match for selection of an entry."
  7536. (interactive)
  7537. (org-agenda-manipulate-query ?\}))
  7538. (defun org-agenda-manipulate-query (char)
  7539. (cond
  7540. ((eq org-agenda-type 'agenda)
  7541. (let ((org-agenda-include-inactive-timestamps t))
  7542. (org-agenda-redo))
  7543. (message "Display now includes inactive timestamps as well"))
  7544. ((eq org-agenda-type 'search)
  7545. (org-add-to-string
  7546. 'org-agenda-query-string
  7547. (if org-agenda-last-search-view-search-was-boolean
  7548. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7549. (?\{ . " +{}") (?\} . " -{}"))))
  7550. " "))
  7551. (setq org-agenda-redo-command
  7552. (list 'org-search-view
  7553. (car (get-text-property (min (1- (point-max)) (point))
  7554. 'org-last-args))
  7555. org-agenda-query-string
  7556. (+ (length org-agenda-query-string)
  7557. (if (member char '(?\{ ?\})) 0 1))))
  7558. (set-register org-agenda-query-register org-agenda-query-string)
  7559. (let ((org-agenda-overriding-arguments
  7560. (cdr org-agenda-redo-command)))
  7561. (org-agenda-redo)))
  7562. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7563. org-agenda-type))))
  7564. (defun org-add-to-string (var string)
  7565. (set var (concat (symbol-value var) string)))
  7566. (defun org-agenda-goto-date (span)
  7567. "Jump to DATE in agenda."
  7568. (interactive "P")
  7569. (let* ((org-read-date-prefer-future
  7570. (eval org-agenda-jump-prefer-future))
  7571. (date (org-read-date))
  7572. (day (time-to-days (org-time-string-to-time date)))
  7573. (org-agenda-sticky-orig org-agenda-sticky)
  7574. (org-agenda-buffer-tmp-name (buffer-name))
  7575. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7576. (0-arg (or current-prefix-arg (car args)))
  7577. (2-arg (nth 2 args))
  7578. (with-hour-p (nth 4 org-agenda-redo-command))
  7579. (newcmd (list 'org-agenda-list 0-arg date
  7580. (org-agenda-span-to-ndays
  7581. 2-arg (org-time-string-to-absolute date))
  7582. with-hour-p))
  7583. (newargs (cdr newcmd))
  7584. (inhibit-read-only t)
  7585. org-agenda-sticky)
  7586. (if (not (org-agenda-check-type t 'agenda))
  7587. (error "Not available in non-agenda views")
  7588. (add-text-properties (point-min) (point-max)
  7589. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7590. (org-agenda-redo)
  7591. (goto-char (point-min))
  7592. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7593. (save-excursion (move-beginning-of-line 2) (eobp))))
  7594. (move-beginning-of-line 2))
  7595. (setq org-agenda-sticky org-agenda-sticky-orig
  7596. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7597. (defun org-agenda-goto-today ()
  7598. "Go to today."
  7599. (interactive)
  7600. (org-agenda-check-type t 'agenda)
  7601. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7602. (curspan (nth 2 args))
  7603. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7604. (cond
  7605. (tdpos (goto-char tdpos))
  7606. ((eq org-agenda-type 'agenda)
  7607. (let* ((sd (org-agenda-compute-starting-span
  7608. (org-today) (or curspan org-agenda-span)))
  7609. (org-agenda-overriding-arguments args))
  7610. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7611. (org-agenda-redo)
  7612. (org-agenda-find-same-or-today-or-agenda)))
  7613. (t (error "Cannot find today")))))
  7614. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7615. (goto-char
  7616. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7617. (text-property-any (point-min) (point-max) 'org-today t)
  7618. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7619. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7620. (org-agenda-backward-block))
  7621. (point-min))))
  7622. (defun org-agenda-backward-block ()
  7623. "Move backward by one agenda block."
  7624. (interactive)
  7625. (org-agenda-forward-block 'backward))
  7626. (defun org-agenda-forward-block (&optional backward)
  7627. "Move forward by one agenda block.
  7628. When optional argument BACKWARD is set, go backward."
  7629. (interactive)
  7630. (cond ((not (derived-mode-p 'org-agenda-mode))
  7631. (user-error
  7632. "Cannot execute this command outside of org-agenda-mode buffers"))
  7633. ((looking-at (if backward "\\`" "\\'"))
  7634. (message "Already at the %s block" (if backward "first" "last")))
  7635. (t (let ((pos (prog1 (point)
  7636. (ignore-errors (if backward (backward-char 1)
  7637. (move-end-of-line 1)))))
  7638. (f (if backward
  7639. 'previous-single-property-change
  7640. 'next-single-property-change))
  7641. moved dest)
  7642. (while (and (setq dest (funcall
  7643. f (point) 'org-agenda-structural-header))
  7644. (not (get-text-property
  7645. (point) 'org-agenda-structural-header)))
  7646. (setq moved t)
  7647. (goto-char dest))
  7648. (if moved (move-beginning-of-line 1)
  7649. (goto-char (if backward (point-min) (point-max)))
  7650. (move-beginning-of-line 1)
  7651. (message "No %s block" (if backward "previous" "further")))))))
  7652. (defun org-agenda-later (arg)
  7653. "Go forward in time by the current span.
  7654. With prefix ARG, go forward that many times the current span."
  7655. (interactive "p")
  7656. (org-agenda-check-type t 'agenda)
  7657. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7658. (span (or (nth 2 args) org-agenda-current-span))
  7659. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7660. (greg (calendar-gregorian-from-absolute sd))
  7661. (cnt (org-get-at-bol 'org-day-cnt))
  7662. greg2)
  7663. (cond
  7664. ((numberp span)
  7665. (setq sd (+ (* span arg) sd)))
  7666. ((eq span 'day)
  7667. (setq sd (+ arg sd)))
  7668. ((eq span 'week)
  7669. (setq sd (+ (* 7 arg) sd)))
  7670. ((eq span 'fortnight)
  7671. (setq sd (+ (* 14 arg) sd)))
  7672. ((eq span 'month)
  7673. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7674. sd (calendar-absolute-from-gregorian greg2))
  7675. (setcar greg2 (1+ (car greg2))))
  7676. ((eq span 'year)
  7677. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7678. sd (calendar-absolute-from-gregorian greg2))
  7679. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7680. (t
  7681. (setq sd (+ (* span arg) sd))))
  7682. (let ((org-agenda-overriding-cmd
  7683. ;; `cmd' may have been set by `org-agenda-run-series' which
  7684. ;; uses `org-agenda-overriding-cmd' to decide whether
  7685. ;; overriding is allowed for `cmd'
  7686. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7687. (org-agenda-overriding-arguments
  7688. (list (car args) sd span)))
  7689. (org-agenda-redo)
  7690. (org-agenda-find-same-or-today-or-agenda cnt))))
  7691. (defun org-agenda-earlier (arg)
  7692. "Go backward in time by the current span.
  7693. With prefix ARG, go backward that many times the current span."
  7694. (interactive "p")
  7695. (org-agenda-later (- arg)))
  7696. (defun org-agenda-view-mode-dispatch ()
  7697. "Call one of the view mode commands."
  7698. (interactive)
  7699. (org-unlogged-message
  7700. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7701. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7702. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7703. (pcase (read-char-exclusive)
  7704. (?\ (call-interactively 'org-agenda-reset-view))
  7705. (?d (call-interactively 'org-agenda-day-view))
  7706. (?w (call-interactively 'org-agenda-week-view))
  7707. (?t (call-interactively 'org-agenda-fortnight-view))
  7708. (?m (call-interactively 'org-agenda-month-view))
  7709. (?y (call-interactively 'org-agenda-year-view))
  7710. (?l (call-interactively 'org-agenda-log-mode))
  7711. (?L (org-agenda-log-mode '(4)))
  7712. (?c (org-agenda-log-mode 'clockcheck))
  7713. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7714. (?a (call-interactively 'org-agenda-archives-mode))
  7715. (?A (org-agenda-archives-mode 'files))
  7716. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7717. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7718. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7719. (?D (call-interactively 'org-agenda-toggle-diary))
  7720. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7721. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7722. (org-agenda-check-type t 'agenda)
  7723. (org-agenda-redo))
  7724. (message "Display now includes inactive timestamps as well"))
  7725. (?q (message "Abort"))
  7726. (key (user-error "Invalid key: %s" key))))
  7727. (defun org-agenda-reset-view ()
  7728. "Switch to default view for agenda."
  7729. (interactive)
  7730. (org-agenda-change-time-span org-agenda-span))
  7731. (defun org-agenda-day-view (&optional day-of-month)
  7732. "Switch to daily view for agenda.
  7733. With argument DAY-OF-MONTH, switch to that day of the month."
  7734. (interactive "P")
  7735. (org-agenda-change-time-span 'day day-of-month))
  7736. (defun org-agenda-week-view (&optional iso-week)
  7737. "Switch to weekly view for agenda.
  7738. With argument ISO-WEEK, switch to the corresponding ISO week.
  7739. If ISO-WEEK has more then 2 digits, only the last two encode
  7740. the week. Any digits before this encode a year. So 200712
  7741. means week 12 of year 2007. Years ranging from 70 years ago
  7742. to 30 years in the future can also be written as 2-digit years."
  7743. (interactive "P")
  7744. (org-agenda-change-time-span 'week iso-week))
  7745. (defun org-agenda-fortnight-view (&optional iso-week)
  7746. "Switch to fortnightly view for agenda.
  7747. With argument ISO-WEEK, switch to the corresponding ISO week.
  7748. If ISO-WEEK has more then 2 digits, only the last two encode
  7749. the week. Any digits before this encode a year. So 200712
  7750. means week 12 of year 2007. Years ranging from 70 years ago
  7751. to 30 years in the future can also be written as 2-digit years."
  7752. (interactive "P")
  7753. (org-agenda-change-time-span 'fortnight iso-week))
  7754. (defun org-agenda-month-view (&optional month)
  7755. "Switch to monthly view for agenda.
  7756. With argument MONTH, switch to that month. If MONTH has more
  7757. then 2 digits, only the last two encode the month. Any digits
  7758. before this encode a year. So 200712 means December year 2007.
  7759. Years ranging from 70 years ago to 30 years in the future can
  7760. also be written as 2-digit years."
  7761. (interactive "P")
  7762. (org-agenda-change-time-span 'month month))
  7763. (defun org-agenda-year-view (&optional year)
  7764. "Switch to yearly view for agenda.
  7765. With argument YEAR, switch to that year. Years ranging from 70
  7766. years ago to 30 years in the future can also be written as
  7767. 2-digit years."
  7768. (interactive "P")
  7769. (when year
  7770. (setq year (org-small-year-to-year year)))
  7771. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7772. (org-agenda-change-time-span 'year year)
  7773. (error "Abort")))
  7774. (defun org-agenda-change-time-span (span &optional n)
  7775. "Change the agenda view to SPAN.
  7776. SPAN may be `day', `week', `fortnight', `month', `year'."
  7777. (org-agenda-check-type t 'agenda)
  7778. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7779. (curspan (nth 2 args)))
  7780. (when (and (not n) (equal curspan span))
  7781. (error "Viewing span is already \"%s\"" span))
  7782. (let* ((sd (or (org-get-at-bol 'day)
  7783. (nth 1 args)
  7784. org-starting-day))
  7785. (sd (org-agenda-compute-starting-span sd span n))
  7786. (org-agenda-overriding-cmd
  7787. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7788. (org-agenda-overriding-arguments
  7789. (list (car args) sd span)))
  7790. (org-agenda-redo)
  7791. (org-agenda-find-same-or-today-or-agenda))
  7792. (org-agenda-set-mode-name)
  7793. (message "Switched to %s view" span)))
  7794. (defun org-agenda-compute-starting-span (sd span &optional n)
  7795. "Compute starting date for agenda.
  7796. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7797. is a cons cell with the starting date and the number of days,
  7798. so that the date SD will be in that range."
  7799. (let* ((greg (calendar-gregorian-from-absolute sd))
  7800. (dg (nth 1 greg))
  7801. (mg (car greg))
  7802. (yg (nth 2 greg)))
  7803. (cond
  7804. ((eq span 'day)
  7805. (when n
  7806. (setq sd (+ (calendar-absolute-from-gregorian
  7807. (list mg 1 yg))
  7808. n -1))))
  7809. ((or (eq span 'week) (eq span 'fortnight))
  7810. (let* ((nt (calendar-day-of-week
  7811. (calendar-gregorian-from-absolute sd)))
  7812. (d (if org-agenda-start-on-weekday
  7813. (- nt org-agenda-start-on-weekday)
  7814. 0))
  7815. y1)
  7816. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7817. (when n
  7818. (require 'cal-iso)
  7819. (when (> n 99)
  7820. (setq y1 (org-small-year-to-year (/ n 100))
  7821. n (mod n 100)))
  7822. (setq sd
  7823. (calendar-iso-to-absolute
  7824. (list n 1
  7825. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7826. ((eq span 'month)
  7827. (let (y1)
  7828. (when (and n (> n 99))
  7829. (setq y1 (org-small-year-to-year (/ n 100))
  7830. n (mod n 100)))
  7831. (setq sd (calendar-absolute-from-gregorian
  7832. (list (or n mg) 1 (or y1 yg))))))
  7833. ((eq span 'year)
  7834. (setq sd (calendar-absolute-from-gregorian
  7835. (list 1 1 (or n yg))))))
  7836. sd))
  7837. (defun org-agenda-next-date-line (&optional arg)
  7838. "Jump to the next line indicating a date in agenda buffer."
  7839. (interactive "p")
  7840. (org-agenda-check-type t 'agenda)
  7841. (beginning-of-line 1)
  7842. ;; This does not work if user makes date format that starts with a blank
  7843. (when (looking-at-p "^\\S-") (forward-char 1))
  7844. (unless (re-search-forward "^\\S-" nil t arg)
  7845. (backward-char 1)
  7846. (error "No next date after this line in this buffer"))
  7847. (goto-char (match-beginning 0)))
  7848. (defun org-agenda-previous-date-line (&optional arg)
  7849. "Jump to the previous line indicating a date in agenda buffer."
  7850. (interactive "p")
  7851. (org-agenda-check-type t 'agenda)
  7852. (beginning-of-line 1)
  7853. (unless (re-search-backward "^\\S-" nil t arg)
  7854. (error "No previous date before this line in this buffer")))
  7855. ;; Initialize the highlight
  7856. (defvar org-hl (make-overlay 1 1))
  7857. (overlay-put org-hl 'face 'highlight)
  7858. (defun org-highlight (begin end &optional buffer)
  7859. "Highlight a region with overlay."
  7860. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7861. (defun org-unhighlight ()
  7862. "Detach overlay INDEX."
  7863. (delete-overlay org-hl))
  7864. (defun org-unhighlight-once ()
  7865. "Remove the highlight from its position, and this function from the hook."
  7866. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7867. (org-unhighlight))
  7868. (defvar org-agenda-pre-follow-window-conf nil)
  7869. (defun org-agenda-follow-mode ()
  7870. "Toggle follow mode in an agenda buffer."
  7871. (interactive)
  7872. (unless org-agenda-follow-mode
  7873. (setq org-agenda-pre-follow-window-conf
  7874. (current-window-configuration)))
  7875. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7876. (unless org-agenda-follow-mode
  7877. (set-window-configuration org-agenda-pre-follow-window-conf))
  7878. (org-agenda-set-mode-name)
  7879. (org-agenda-do-context-action)
  7880. (message "Follow mode is %s"
  7881. (if org-agenda-follow-mode "on" "off")))
  7882. (defun org-agenda-entry-text-mode (&optional arg)
  7883. "Toggle entry text mode in an agenda buffer."
  7884. (interactive "P")
  7885. (if (or org-agenda-tag-filter
  7886. org-agenda-category-filter
  7887. org-agenda-regexp-filter
  7888. org-agenda-top-headline-filter)
  7889. (user-error "Can't show entry text in filtered views")
  7890. (setq org-agenda-entry-text-mode (or (integerp arg)
  7891. (not org-agenda-entry-text-mode)))
  7892. (org-agenda-entry-text-hide)
  7893. (and org-agenda-entry-text-mode
  7894. (let ((org-agenda-entry-text-maxlines
  7895. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7896. (org-agenda-entry-text-show)))
  7897. (org-agenda-set-mode-name)
  7898. (message "Entry text mode is %s%s"
  7899. (if org-agenda-entry-text-mode "on" "off")
  7900. (if (not org-agenda-entry-text-mode) ""
  7901. (format " (maximum number of lines is %d)"
  7902. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7903. (defun org-agenda-clockreport-mode ()
  7904. "Toggle clocktable mode in an agenda buffer."
  7905. (interactive)
  7906. (org-agenda-check-type t 'agenda)
  7907. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7908. (org-agenda-set-mode-name)
  7909. (org-agenda-redo)
  7910. (message "Clocktable mode is %s"
  7911. (if org-agenda-clockreport-mode "on" "off")))
  7912. (defun org-agenda-log-mode (&optional special)
  7913. "Toggle log mode in an agenda buffer.
  7914. With argument SPECIAL, show all possible log items, not only the ones
  7915. configured in `org-agenda-log-mode-items'.
  7916. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7917. log items, nothing else."
  7918. (interactive "P")
  7919. (org-agenda-check-type t 'agenda)
  7920. (setq org-agenda-show-log
  7921. (cond
  7922. ((equal special '(16)) 'only)
  7923. ((eq special 'clockcheck)
  7924. (if (eq org-agenda-show-log 'clockcheck)
  7925. nil 'clockcheck))
  7926. (special '(closed clock state))
  7927. (t (not org-agenda-show-log))))
  7928. (org-agenda-set-mode-name)
  7929. (org-agenda-redo)
  7930. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7931. (defun org-agenda-archives-mode (&optional with-files)
  7932. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7933. When called with a prefix argument, include all archive files as well."
  7934. (interactive "P")
  7935. (setq org-agenda-archives-mode
  7936. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7937. (org-agenda-set-mode-name)
  7938. (org-agenda-redo)
  7939. (message
  7940. "%s"
  7941. (cond
  7942. ((eq org-agenda-archives-mode nil)
  7943. "No archives are included")
  7944. ((eq org-agenda-archives-mode 'trees)
  7945. (format "Trees with :%s: tag are included" org-archive-tag))
  7946. ((eq org-agenda-archives-mode t)
  7947. (format "Trees with :%s: tag and all active archive files are included"
  7948. org-archive-tag)))))
  7949. (defun org-agenda-toggle-diary ()
  7950. "Toggle diary inclusion in an agenda buffer."
  7951. (interactive)
  7952. (org-agenda-check-type t 'agenda)
  7953. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7954. (org-agenda-redo)
  7955. (org-agenda-set-mode-name)
  7956. (message "Diary inclusion turned %s"
  7957. (if org-agenda-include-diary "on" "off")))
  7958. (defun org-agenda-toggle-deadlines ()
  7959. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7960. (interactive)
  7961. (org-agenda-check-type t 'agenda)
  7962. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7963. (org-agenda-redo)
  7964. (org-agenda-set-mode-name)
  7965. (message "Deadlines inclusion turned %s"
  7966. (if org-agenda-include-deadlines "on" "off")))
  7967. (defun org-agenda-toggle-time-grid ()
  7968. "Toggle time grid in an agenda buffer."
  7969. (interactive)
  7970. (org-agenda-check-type t 'agenda)
  7971. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7972. (org-agenda-redo)
  7973. (org-agenda-set-mode-name)
  7974. (message "Time-grid turned %s"
  7975. (if org-agenda-use-time-grid "on" "off")))
  7976. (defun org-agenda-set-mode-name ()
  7977. "Set the mode name to indicate all the small mode settings."
  7978. (setq mode-name
  7979. (list "Org-Agenda"
  7980. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7981. " "
  7982. '(:eval (org-agenda-span-name org-agenda-current-span))
  7983. (if org-agenda-follow-mode " Follow" "")
  7984. (if org-agenda-entry-text-mode " ETxt" "")
  7985. (if org-agenda-include-diary " Diary" "")
  7986. (if org-agenda-include-deadlines " Ddl" "")
  7987. (if org-agenda-use-time-grid " Grid" "")
  7988. (if (and (boundp 'org-habit-show-habits)
  7989. org-habit-show-habits) " Habit" "")
  7990. (cond
  7991. ((consp org-agenda-show-log) " LogAll")
  7992. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7993. (org-agenda-show-log " Log")
  7994. (t ""))
  7995. (if (org-agenda-filter-any) " " "")
  7996. (if (or org-agenda-category-filter
  7997. (get 'org-agenda-category-filter :preset-filter))
  7998. '(:eval (propertize
  7999. (concat "["
  8000. (mapconcat
  8001. 'identity
  8002. (append
  8003. (get 'org-agenda-category-filter :preset-filter)
  8004. org-agenda-category-filter)
  8005. "")
  8006. "]")
  8007. 'face 'org-agenda-filter-category
  8008. 'help-echo "Category used in filtering")) "")
  8009. (if (or org-agenda-tag-filter
  8010. (get 'org-agenda-tag-filter :preset-filter))
  8011. '(:eval (propertize
  8012. (concat (mapconcat
  8013. 'identity
  8014. (append
  8015. (get 'org-agenda-tag-filter :preset-filter)
  8016. org-agenda-tag-filter)
  8017. ""))
  8018. 'face 'org-agenda-filter-tags
  8019. 'help-echo "Tags used in filtering")) "")
  8020. (if (or org-agenda-effort-filter
  8021. (get 'org-agenda-effort-filter :preset-filter))
  8022. '(:eval (propertize
  8023. (concat (mapconcat
  8024. 'identity
  8025. (append
  8026. (get 'org-agenda-effort-filter :preset-filter)
  8027. org-agenda-effort-filter)
  8028. ""))
  8029. 'face 'org-agenda-filter-effort
  8030. 'help-echo "Effort conditions used in filtering")) "")
  8031. (if (or org-agenda-regexp-filter
  8032. (get 'org-agenda-regexp-filter :preset-filter))
  8033. '(:eval (propertize
  8034. (concat (mapconcat
  8035. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8036. (append
  8037. (get 'org-agenda-regexp-filter :preset-filter)
  8038. org-agenda-regexp-filter)
  8039. ""))
  8040. 'face 'org-agenda-filter-regexp
  8041. 'help-echo "Regexp used in filtering")) "")
  8042. (if org-agenda-archives-mode
  8043. (if (eq org-agenda-archives-mode t)
  8044. " Archives"
  8045. (format " :%s:" org-archive-tag))
  8046. "")
  8047. (if org-agenda-clockreport-mode " Clock" "")))
  8048. (force-mode-line-update))
  8049. (defun org-agenda-update-agenda-type ()
  8050. "Update the agenda type after each command."
  8051. (setq org-agenda-type
  8052. (or (get-text-property (point) 'org-agenda-type)
  8053. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8054. (defun org-agenda-next-line ()
  8055. "Move cursor to the next line, and show if follow mode is active."
  8056. (interactive)
  8057. (call-interactively 'next-line)
  8058. (org-agenda-do-context-action))
  8059. (defun org-agenda-previous-line ()
  8060. "Move cursor to the previous line, and show if follow-mode is active."
  8061. (interactive)
  8062. (call-interactively 'previous-line)
  8063. (org-agenda-do-context-action))
  8064. (defun org-agenda-next-item (n)
  8065. "Move cursor to next agenda item."
  8066. (interactive "p")
  8067. (let ((col (current-column)))
  8068. (dotimes (c n)
  8069. (when (next-single-property-change (point-at-eol) 'org-marker)
  8070. (move-end-of-line 1)
  8071. (goto-char (next-single-property-change (point) 'org-marker))))
  8072. (org-move-to-column col))
  8073. (org-agenda-do-context-action))
  8074. (defun org-agenda-previous-item (n)
  8075. "Move cursor to next agenda item."
  8076. (interactive "p")
  8077. (dotimes (c n)
  8078. (let ((col (current-column))
  8079. (goto (save-excursion
  8080. (move-end-of-line 0)
  8081. (previous-single-property-change (point) 'org-marker))))
  8082. (when goto (goto-char goto))
  8083. (org-move-to-column col)))
  8084. (org-agenda-do-context-action))
  8085. (defun org-agenda-do-context-action ()
  8086. "Show outline path and, maybe, follow mode window."
  8087. (let ((m (org-get-at-bol 'org-marker)))
  8088. (when (and (markerp m) (marker-buffer m))
  8089. (and org-agenda-follow-mode
  8090. (if org-agenda-follow-indirect
  8091. (org-agenda-tree-to-indirect-buffer nil)
  8092. (org-agenda-show)))
  8093. (and org-agenda-show-outline-path
  8094. (org-with-point-at m (org-display-outline-path t))))))
  8095. (defun org-agenda-show-tags ()
  8096. "Show the tags applicable to the current item."
  8097. (interactive)
  8098. (let* ((tags (org-get-at-bol 'tags)))
  8099. (if tags
  8100. (message "Tags are :%s:"
  8101. (org-no-properties (mapconcat 'identity tags ":")))
  8102. (message "No tags associated with this line"))))
  8103. (defun org-agenda-goto (&optional highlight)
  8104. "Go to the entry at point in the corresponding Org file."
  8105. (interactive)
  8106. (let* ((marker (or (org-get-at-bol 'org-marker)
  8107. (org-agenda-error)))
  8108. (buffer (marker-buffer marker))
  8109. (pos (marker-position marker)))
  8110. (switch-to-buffer-other-window buffer)
  8111. (widen)
  8112. (push-mark)
  8113. (goto-char pos)
  8114. (when (derived-mode-p 'org-mode)
  8115. (org-show-context 'agenda)
  8116. (recenter (/ (window-height) 2))
  8117. (org-back-to-heading t)
  8118. (let ((case-fold-search nil))
  8119. (when (re-search-forward org-complex-heading-regexp nil t)
  8120. (goto-char (match-beginning 4)))))
  8121. (run-hooks 'org-agenda-after-show-hook)
  8122. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8123. (defvar org-agenda-after-show-hook nil
  8124. "Normal hook run after an item has been shown from the agenda.
  8125. Point is in the buffer where the item originated.")
  8126. (defun org-agenda-kill ()
  8127. "Kill the entry or subtree belonging to the current agenda entry."
  8128. (interactive)
  8129. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  8130. (let* ((bufname-orig (buffer-name))
  8131. (marker (or (org-get-at-bol 'org-marker)
  8132. (org-agenda-error)))
  8133. (buffer (marker-buffer marker))
  8134. (pos (marker-position marker))
  8135. (type (org-get-at-bol 'type))
  8136. dbeg dend (n 0))
  8137. (org-with-remote-undo buffer
  8138. (with-current-buffer buffer
  8139. (save-excursion
  8140. (goto-char pos)
  8141. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8142. (setq dbeg (progn (org-back-to-heading t) (point))
  8143. dend (org-end-of-subtree t t))
  8144. (setq dbeg (point-at-bol)
  8145. dend (min (point-max) (1+ (point-at-eol)))))
  8146. (goto-char dbeg)
  8147. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8148. (when (or (eq t org-agenda-confirm-kill)
  8149. (and (numberp org-agenda-confirm-kill)
  8150. (> n org-agenda-confirm-kill)))
  8151. (let ((win-conf (current-window-configuration)))
  8152. (unwind-protect
  8153. (and
  8154. (prog2
  8155. (org-agenda-tree-to-indirect-buffer nil)
  8156. (not (y-or-n-p
  8157. (format "Delete entry with %d lines in buffer \"%s\"? "
  8158. n (buffer-name buffer))))
  8159. (kill-buffer org-last-indirect-buffer))
  8160. (error "Abort"))
  8161. (set-window-configuration win-conf))))
  8162. (let ((org-agenda-buffer-name bufname-orig))
  8163. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8164. (with-current-buffer buffer (delete-region dbeg dend))
  8165. (message "Agenda item and source killed"))))
  8166. (defvar org-archive-default-command) ; defined in org-archive.el
  8167. (defun org-agenda-archive-default ()
  8168. "Archive the entry or subtree belonging to the current agenda entry."
  8169. (interactive)
  8170. (require 'org-archive)
  8171. (org-agenda-archive-with org-archive-default-command))
  8172. (defun org-agenda-archive-default-with-confirmation ()
  8173. "Archive the entry or subtree belonging to the current agenda entry."
  8174. (interactive)
  8175. (require 'org-archive)
  8176. (org-agenda-archive-with org-archive-default-command 'confirm))
  8177. (defun org-agenda-archive ()
  8178. "Archive the entry or subtree belonging to the current agenda entry."
  8179. (interactive)
  8180. (org-agenda-archive-with 'org-archive-subtree))
  8181. (defun org-agenda-archive-to-archive-sibling ()
  8182. "Move the entry to the archive sibling."
  8183. (interactive)
  8184. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  8185. (defun org-agenda-archive-with (cmd &optional confirm)
  8186. "Move the entry to the archive sibling."
  8187. (interactive)
  8188. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  8189. (let* ((bufname-orig (buffer-name))
  8190. (marker (or (org-get-at-bol 'org-marker)
  8191. (org-agenda-error)))
  8192. (buffer (marker-buffer marker))
  8193. (pos (marker-position marker)))
  8194. (org-with-remote-undo buffer
  8195. (with-current-buffer buffer
  8196. (if (derived-mode-p 'org-mode)
  8197. (if (and confirm
  8198. (not (y-or-n-p "Archive this subtree or entry? ")))
  8199. (error "Abort")
  8200. (save-window-excursion
  8201. (goto-char pos)
  8202. (let ((org-agenda-buffer-name bufname-orig))
  8203. (org-remove-subtree-entries-from-agenda))
  8204. (org-back-to-heading t)
  8205. (funcall cmd)))
  8206. (error "Archiving works only in Org files"))))))
  8207. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8208. "Remove all lines in the agenda that correspond to a given subtree.
  8209. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8210. If this information is not given, the function uses the tree at point."
  8211. (let ((buf (or buf (current-buffer))) m p)
  8212. (save-excursion
  8213. (unless (and beg end)
  8214. (org-back-to-heading t)
  8215. (setq beg (point))
  8216. (org-end-of-subtree t)
  8217. (setq end (point)))
  8218. (set-buffer (get-buffer org-agenda-buffer-name))
  8219. (save-excursion
  8220. (goto-char (point-max))
  8221. (beginning-of-line 1)
  8222. (while (not (bobp))
  8223. (when (and (setq m (org-get-at-bol 'org-marker))
  8224. (equal buf (marker-buffer m))
  8225. (setq p (marker-position m))
  8226. (>= p beg)
  8227. (< p end))
  8228. (let ((inhibit-read-only t))
  8229. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8230. (beginning-of-line 0))))))
  8231. (defun org-agenda-refile (&optional goto rfloc no-update)
  8232. "Refile the item at point.
  8233. When called with `\\[universal-argument] \\[universal-argument]', \
  8234. go to the location of the last
  8235. refiled item.
  8236. When called with `\\[universal-argument] \\[universal-argument] \
  8237. \\[universal-argument]' prefix or when GOTO is 0, clear
  8238. the refile cache.
  8239. RFLOC can be a refile location obtained in a different way.
  8240. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8241. (interactive "P")
  8242. (cond
  8243. ((member goto '(0 (64)))
  8244. (org-refile-cache-clear))
  8245. ((equal goto '(16))
  8246. (org-refile-goto-last-stored))
  8247. (t
  8248. (let* ((buffer-orig (buffer-name))
  8249. (marker (or (org-get-at-bol 'org-hd-marker)
  8250. (org-agenda-error)))
  8251. (buffer (marker-buffer marker))
  8252. (pos (marker-position marker))
  8253. (rfloc (or rfloc
  8254. (org-refile-get-location
  8255. (if goto "Goto" "Refile to") buffer
  8256. org-refile-allow-creating-parent-nodes))))
  8257. (with-current-buffer buffer
  8258. (org-with-wide-buffer
  8259. (goto-char marker)
  8260. (let ((org-agenda-buffer-name buffer-orig))
  8261. (org-remove-subtree-entries-from-agenda))
  8262. (org-refile goto buffer rfloc))))
  8263. (unless no-update (org-agenda-redo)))))
  8264. (defun org-agenda-open-link (&optional arg)
  8265. "Open the link(s) in the current entry, if any.
  8266. This looks for a link in the displayed line in the agenda.
  8267. It also looks at the text of the entry itself."
  8268. (interactive "P")
  8269. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8270. (org-get-at-bol 'org-marker)))
  8271. (buffer (and marker (marker-buffer marker)))
  8272. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8273. (lkall (and buffer (org-offer-links-in-entry
  8274. buffer marker arg prefix)))
  8275. (lk0 (car lkall))
  8276. (lk (if (stringp lk0) (list lk0) lk0))
  8277. (lkend (cdr lkall))
  8278. trg)
  8279. (cond
  8280. ((and buffer lk)
  8281. (mapcar (lambda(l)
  8282. (with-current-buffer buffer
  8283. (setq trg (and (string-match org-link-bracket-re l)
  8284. (match-string 1 l)))
  8285. (if (or (not trg) (string-match org-link-any-re trg))
  8286. (org-with-wide-buffer
  8287. (goto-char marker)
  8288. (when (search-forward l nil lkend)
  8289. (goto-char (match-beginning 0))
  8290. (org-open-at-point)))
  8291. ;; This is an internal link, widen the buffer
  8292. (switch-to-buffer-other-window buffer)
  8293. (widen)
  8294. (goto-char marker)
  8295. (when (search-forward l nil lkend)
  8296. (goto-char (match-beginning 0))
  8297. (org-open-at-point)))))
  8298. lk))
  8299. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  8300. (save-excursion
  8301. (beginning-of-line 1)
  8302. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  8303. (org-link-open-from-string (match-string 1)))
  8304. (t (message "No link to open here")))))
  8305. (defun org-agenda-copy-local-variable (var)
  8306. "Get a variable from a referenced buffer and install it here."
  8307. (let ((m (org-get-at-bol 'org-marker)))
  8308. (when (and m (buffer-live-p (marker-buffer m)))
  8309. (set (make-local-variable var)
  8310. (with-current-buffer (marker-buffer m)
  8311. (symbol-value var))))))
  8312. (defun org-agenda-switch-to (&optional delete-other-windows)
  8313. "Go to the Org mode file which contains the item at point.
  8314. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8315. displayed Org file fills the frame."
  8316. (interactive)
  8317. (if (and org-return-follows-link
  8318. (not (org-get-at-bol 'org-marker))
  8319. (org-in-regexp org-link-bracket-re))
  8320. (org-link-open-from-string (match-string 0))
  8321. (let* ((marker (or (org-get-at-bol 'org-marker)
  8322. (org-agenda-error)))
  8323. (buffer (marker-buffer marker))
  8324. (pos (marker-position marker)))
  8325. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8326. (pop-to-buffer-same-window buffer)
  8327. (when delete-other-windows (delete-other-windows))
  8328. (widen)
  8329. (goto-char pos)
  8330. (when (derived-mode-p 'org-mode)
  8331. (org-show-context 'agenda)
  8332. (run-hooks 'org-agenda-after-show-hook)))))
  8333. (defun org-agenda-goto-mouse (ev)
  8334. "Go to the Org file which contains the item at the mouse click."
  8335. (interactive "e")
  8336. (mouse-set-point ev)
  8337. (org-agenda-goto))
  8338. (defun org-agenda-show (&optional full-entry)
  8339. "Display the Org file which contains the item at point.
  8340. With prefix argument FULL-ENTRY, make the entire entry visible
  8341. if it was hidden in the outline."
  8342. (interactive "P")
  8343. (let ((win (selected-window)))
  8344. (org-agenda-goto t)
  8345. (when full-entry (org-show-entry))
  8346. (select-window win)))
  8347. (defvar org-agenda-show-window nil)
  8348. (defun org-agenda-show-and-scroll-up (&optional arg)
  8349. "Display the Org file which contains the item at point.
  8350. When called repeatedly, scroll the window that is displaying the buffer.
  8351. With a `\\[universal-argument]' prefix argument, display the item, but \
  8352. fold drawers."
  8353. (interactive "P")
  8354. (let ((win (selected-window)))
  8355. (if (and (window-live-p org-agenda-show-window)
  8356. (eq this-command last-command))
  8357. (progn
  8358. (select-window org-agenda-show-window)
  8359. (ignore-errors (scroll-up)))
  8360. (org-agenda-goto t)
  8361. (org-show-entry)
  8362. (if arg (org-cycle-hide-drawers 'children)
  8363. (org-with-wide-buffer
  8364. (narrow-to-region (org-entry-beginning-position)
  8365. (org-entry-end-position))
  8366. (org-show-all '(drawers))))
  8367. (when arg )
  8368. (setq org-agenda-show-window (selected-window)))
  8369. (select-window win)))
  8370. (defun org-agenda-show-scroll-down ()
  8371. "Scroll down the window showing the agenda."
  8372. (interactive)
  8373. (let ((win (selected-window)))
  8374. (when (window-live-p org-agenda-show-window)
  8375. (select-window org-agenda-show-window)
  8376. (ignore-errors (scroll-down))
  8377. (select-window win))))
  8378. (defun org-agenda-show-1 (&optional more)
  8379. "Display the Org file which contains the item at point.
  8380. The prefix arg selects the amount of information to display:
  8381. 0 hide the subtree
  8382. 1 just show the entry according to defaults.
  8383. 2 show the children view
  8384. 3 show the subtree view
  8385. 4 show the entire subtree and any LOGBOOK drawers
  8386. 5 show the entire subtree and any drawers
  8387. With prefix argument FULL-ENTRY, make the entire entry visible
  8388. if it was hidden in the outline."
  8389. (interactive "p")
  8390. (let ((win (selected-window)))
  8391. (org-agenda-goto t)
  8392. (org-back-to-heading)
  8393. (set-window-start (selected-window) (point-at-bol))
  8394. (cond
  8395. ((= more 0)
  8396. (org-flag-subtree t)
  8397. (save-excursion
  8398. (org-back-to-heading)
  8399. (run-hook-with-args 'org-cycle-hook 'folded))
  8400. (message "Remote: FOLDED"))
  8401. ((and (called-interactively-p 'any) (= more 1))
  8402. (message "Remote: show with default settings"))
  8403. ((= more 2)
  8404. (outline-show-entry)
  8405. (org-show-children)
  8406. (save-excursion
  8407. (org-back-to-heading)
  8408. (run-hook-with-args 'org-cycle-hook 'children))
  8409. (message "Remote: CHILDREN"))
  8410. ((= more 3)
  8411. (outline-show-subtree)
  8412. (save-excursion
  8413. (org-back-to-heading)
  8414. (run-hook-with-args 'org-cycle-hook 'subtree))
  8415. (message "Remote: SUBTREE"))
  8416. ((= more 4)
  8417. (outline-show-subtree)
  8418. (save-excursion
  8419. (org-back-to-heading)
  8420. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8421. (message "Remote: SUBTREE AND LOGBOOK"))
  8422. ((> more 4)
  8423. (outline-show-subtree)
  8424. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8425. (select-window win)))
  8426. (defvar org-agenda-cycle-counter nil)
  8427. (defun org-agenda-cycle-show (&optional n)
  8428. "Show the current entry in another window, with default settings.
  8429. Default settings are taken from `org-show-context-detail'. When
  8430. use repeatedly in immediate succession, the remote entry will
  8431. cycle through visibility
  8432. children -> subtree -> folded
  8433. When called with a numeric prefix arg, that arg will be passed through to
  8434. `org-agenda-show-1'. For the interpretation of that argument, see the
  8435. docstring of `org-agenda-show-1'."
  8436. (interactive "P")
  8437. (if (integerp n)
  8438. (setq org-agenda-cycle-counter n)
  8439. (if (not (eq last-command this-command))
  8440. (setq org-agenda-cycle-counter 1)
  8441. (if (equal org-agenda-cycle-counter 0)
  8442. (setq org-agenda-cycle-counter 2)
  8443. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8444. (when (> org-agenda-cycle-counter 3)
  8445. (setq org-agenda-cycle-counter 0)))))
  8446. (org-agenda-show-1 org-agenda-cycle-counter))
  8447. (defun org-agenda-recenter (arg)
  8448. "Display the Org file which contains the item at point and recenter."
  8449. (interactive "P")
  8450. (let ((win (selected-window)))
  8451. (org-agenda-goto t)
  8452. (recenter arg)
  8453. (select-window win)))
  8454. (defun org-agenda-show-mouse (ev)
  8455. "Display the Org file which contains the item at the mouse click."
  8456. (interactive "e")
  8457. (mouse-set-point ev)
  8458. (org-agenda-show))
  8459. (defun org-agenda-check-no-diary ()
  8460. "Check if the entry is a diary link and abort if yes."
  8461. (when (org-get-at-bol 'org-agenda-diary-link)
  8462. (org-agenda-error)))
  8463. (defun org-agenda-error ()
  8464. "Throw an error when a command is not allowed in the agenda."
  8465. (user-error "Command not allowed in this line"))
  8466. (defun org-agenda-tree-to-indirect-buffer (arg)
  8467. "Show the subtree corresponding to the current entry in an indirect buffer.
  8468. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8469. With a numerical prefix ARG, go up to this level and then take that tree.
  8470. With a negative numeric ARG, go up by this number of levels.
  8471. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8472. i.e. don't use
  8473. the dedicated frame."
  8474. (interactive "P")
  8475. (if current-prefix-arg
  8476. (org-agenda-do-tree-to-indirect-buffer arg)
  8477. (let ((agenda-buffer (buffer-name))
  8478. (agenda-window (selected-window))
  8479. (indirect-window
  8480. (and org-last-indirect-buffer
  8481. (get-buffer-window org-last-indirect-buffer))))
  8482. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8483. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8484. (eq org-indirect-buffer-display 'dedicated-frame))
  8485. (unwind-protect
  8486. (unless (and indirect-window (window-live-p indirect-window))
  8487. (setq indirect-window (split-window agenda-window)))
  8488. (and indirect-window (select-window indirect-window))
  8489. (switch-to-buffer org-last-indirect-buffer :norecord)
  8490. (fit-window-to-buffer indirect-window)))
  8491. (select-window (get-buffer-window agenda-buffer))
  8492. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8493. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8494. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8495. (org-agenda-check-no-diary)
  8496. (let* ((marker (or (org-get-at-bol 'org-marker)
  8497. (org-agenda-error)))
  8498. (buffer (marker-buffer marker))
  8499. (pos (marker-position marker)))
  8500. (with-current-buffer buffer
  8501. (save-excursion
  8502. (goto-char pos)
  8503. (org-tree-to-indirect-buffer arg)))))
  8504. (defvar org-last-heading-marker (make-marker)
  8505. "Marker pointing to the headline that last changed its TODO state
  8506. by a remote command from the agenda.")
  8507. (defun org-agenda-todo-nextset ()
  8508. "Switch TODO entry to next sequence."
  8509. (interactive)
  8510. (org-agenda-todo 'nextset))
  8511. (defun org-agenda-todo-previousset ()
  8512. "Switch TODO entry to previous sequence."
  8513. (interactive)
  8514. (org-agenda-todo 'previousset))
  8515. (defun org-agenda-todo (&optional arg)
  8516. "Cycle TODO state of line at point, also in Org file.
  8517. This changes the line at point, all other lines in the agenda referring to
  8518. the same tree node, and the headline of the tree node in the Org file."
  8519. (interactive "P")
  8520. (org-agenda-check-no-diary)
  8521. (let* ((col (current-column))
  8522. (marker (or (org-get-at-bol 'org-marker)
  8523. (org-agenda-error)))
  8524. (buffer (marker-buffer marker))
  8525. (pos (marker-position marker))
  8526. (hdmarker (org-get-at-bol 'org-hd-marker))
  8527. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8528. (inhibit-read-only t)
  8529. org-loop-over-headlines-in-active-region
  8530. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8531. (org-with-remote-undo buffer
  8532. (with-current-buffer buffer
  8533. (widen)
  8534. (goto-char pos)
  8535. (org-show-context 'agenda)
  8536. (let ((current-prefix-arg arg))
  8537. (call-interactively 'org-todo))
  8538. (and (bolp) (forward-char 1))
  8539. (setq newhead (org-get-heading))
  8540. (when (and (bound-and-true-p
  8541. org-agenda-headline-snapshot-before-repeat)
  8542. (not (equal org-agenda-headline-snapshot-before-repeat
  8543. newhead))
  8544. todayp)
  8545. (setq newhead org-agenda-headline-snapshot-before-repeat
  8546. just-one t))
  8547. (save-excursion
  8548. (org-back-to-heading)
  8549. (move-marker org-last-heading-marker (point))))
  8550. (beginning-of-line 1)
  8551. (save-window-excursion
  8552. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8553. (when (bound-and-true-p org-clock-out-when-done)
  8554. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8555. newhead)
  8556. (org-agenda-unmark-clocking-task))
  8557. (org-move-to-column col)
  8558. (org-agenda-mark-clocking-task))))
  8559. (defun org-agenda-add-note (&optional arg)
  8560. "Add a time-stamped note to the entry at point."
  8561. (interactive "P")
  8562. (org-agenda-check-no-diary)
  8563. (let* ((marker (or (org-get-at-bol 'org-marker)
  8564. (org-agenda-error)))
  8565. (buffer (marker-buffer marker))
  8566. (pos (marker-position marker))
  8567. (hdmarker (org-get-at-bol 'org-hd-marker))
  8568. (inhibit-read-only t))
  8569. (with-current-buffer buffer
  8570. (widen)
  8571. (goto-char pos)
  8572. (org-show-context 'agenda)
  8573. (org-add-note))))
  8574. (defun org-agenda-change-all-lines (newhead hdmarker
  8575. &optional fixface just-this)
  8576. "Change all lines in the agenda buffer which match HDMARKER.
  8577. The new content of the line will be NEWHEAD (as modified by
  8578. `org-agenda-format-item'). HDMARKER is checked with
  8579. `equal' against all `org-hd-marker' text properties in the file.
  8580. If FIXFACE is non-nil, the face of each item is modified according to
  8581. the new TODO state.
  8582. If JUST-THIS is non-nil, change just the current line, not all.
  8583. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  8584. (let* ((inhibit-read-only t)
  8585. (line (org-current-line))
  8586. (org-agenda-buffer (current-buffer))
  8587. (thetags (with-current-buffer (marker-buffer hdmarker)
  8588. (org-get-tags hdmarker)))
  8589. props m pl undone-face done-face finish new dotime level cat tags)
  8590. (save-excursion
  8591. (goto-char (point-max))
  8592. (beginning-of-line 1)
  8593. (while (not finish)
  8594. (setq finish (bobp))
  8595. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8596. (or (not just-this) (= (org-current-line) line))
  8597. (equal m hdmarker))
  8598. (setq props (text-properties-at (point))
  8599. dotime (org-get-at-bol 'dotime)
  8600. cat (org-agenda-get-category)
  8601. level (org-get-at-bol 'level)
  8602. tags thetags
  8603. new
  8604. (let ((org-prefix-format-compiled
  8605. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8606. org-prefix-format-compiled))
  8607. (extra (org-get-at-bol 'extra)))
  8608. (with-current-buffer (marker-buffer hdmarker)
  8609. (org-with-wide-buffer
  8610. (org-agenda-format-item extra newhead level cat tags dotime))))
  8611. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8612. undone-face (org-get-at-bol 'undone-face)
  8613. done-face (org-get-at-bol 'done-face))
  8614. (beginning-of-line 1)
  8615. (cond
  8616. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8617. ((looking-at ".*")
  8618. ;; When replacing the whole line, preserve bulk mark
  8619. ;; overlay, if any.
  8620. (let ((mark (catch :overlay
  8621. (dolist (o (overlays-in (point) (+ 2 (point))))
  8622. (when (eq (overlay-get o 'type)
  8623. 'org-marked-entry-overlay)
  8624. (throw :overlay o))))))
  8625. (replace-match new t t)
  8626. (beginning-of-line)
  8627. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8628. (add-text-properties (point-at-bol) (point-at-eol) props)
  8629. (when fixface
  8630. (add-text-properties
  8631. (point-at-bol) (point-at-eol)
  8632. (list 'face
  8633. (if org-last-todo-state-is-todo
  8634. undone-face done-face))))
  8635. (org-agenda-highlight-todo 'line)
  8636. (beginning-of-line 1))
  8637. (t (error "Line update did not work")))
  8638. (save-restriction
  8639. (narrow-to-region (point-at-bol) (point-at-eol))
  8640. (org-agenda-finalize)))
  8641. (beginning-of-line 0)))))
  8642. (defun org-agenda-align-tags (&optional line)
  8643. "Align all tags in agenda items to `org-agenda-tags-column'.
  8644. When optional argument LINE is non-nil, align tags only on the
  8645. current line."
  8646. (let ((inhibit-read-only t)
  8647. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8648. (- (window-text-width))
  8649. org-agenda-tags-column))
  8650. (end (and line (line-end-position)))
  8651. l c)
  8652. (save-excursion
  8653. (goto-char (if line (line-beginning-position) (point-min)))
  8654. (while (re-search-forward org-tag-group-re end t)
  8655. (add-text-properties
  8656. (match-beginning 1) (match-end 1)
  8657. (list 'face (delq nil (let ((prop (get-text-property
  8658. (match-beginning 1) 'face)))
  8659. (or (listp prop) (setq prop (list prop)))
  8660. (if (memq 'org-tag prop)
  8661. prop
  8662. (cons 'org-tag prop))))))
  8663. (setq l (string-width (match-string 1))
  8664. c (if (< org-agenda-tags-column 0)
  8665. (- (abs org-agenda-tags-column) l)
  8666. org-agenda-tags-column))
  8667. (goto-char (match-beginning 1))
  8668. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  8669. (point))
  8670. (insert (org-add-props
  8671. (make-string (max 1 (- c (current-column))) ?\s)
  8672. (plist-put (copy-sequence (text-properties-at (point)))
  8673. 'face nil))))
  8674. (goto-char (point-min))
  8675. (org-font-lock-add-tag-faces (point-max)))))
  8676. (defun org-agenda-priority-up ()
  8677. "Increase the priority of line at point, also in Org file."
  8678. (interactive)
  8679. (org-agenda-priority 'up))
  8680. (defun org-agenda-priority-down ()
  8681. "Decrease the priority of line at point, also in Org file."
  8682. (interactive)
  8683. (org-agenda-priority 'down))
  8684. (defun org-agenda-priority (&optional force-direction)
  8685. "Set the priority of line at point, also in Org file.
  8686. This changes the line at point, all other lines in the agenda referring to
  8687. the same tree node, and the headline of the tree node in the Org file.
  8688. Called with a universal prefix arg, show the priority instead of setting it."
  8689. (interactive "P")
  8690. (if (equal force-direction '(4))
  8691. (org-show-priority)
  8692. (unless org-enable-priority-commands
  8693. (error "Priority commands are disabled"))
  8694. (org-agenda-check-no-diary)
  8695. (let* ((col (current-column))
  8696. (marker (or (org-get-at-bol 'org-marker)
  8697. (org-agenda-error)))
  8698. (hdmarker (org-get-at-bol 'org-hd-marker))
  8699. (buffer (marker-buffer hdmarker))
  8700. (pos (marker-position hdmarker))
  8701. (inhibit-read-only t)
  8702. newhead)
  8703. (org-with-remote-undo buffer
  8704. (with-current-buffer buffer
  8705. (widen)
  8706. (goto-char pos)
  8707. (org-show-context 'agenda)
  8708. (org-priority force-direction)
  8709. (end-of-line 1)
  8710. (setq newhead (org-get-heading)))
  8711. (org-agenda-change-all-lines newhead hdmarker)
  8712. (org-move-to-column col)))))
  8713. ;; FIXME: should fix the tags property of the agenda line.
  8714. (defun org-agenda-set-tags (&optional tag onoff)
  8715. "Set tags for the current headline."
  8716. (interactive)
  8717. (org-agenda-check-no-diary)
  8718. (if (and (org-region-active-p) (called-interactively-p 'any))
  8719. (call-interactively 'org-change-tag-in-region)
  8720. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8721. (org-agenda-error)))
  8722. (buffer (marker-buffer hdmarker))
  8723. (pos (marker-position hdmarker))
  8724. (inhibit-read-only t)
  8725. newhead)
  8726. (org-with-remote-undo buffer
  8727. (with-current-buffer buffer
  8728. (widen)
  8729. (goto-char pos)
  8730. (org-show-context 'agenda)
  8731. (if tag
  8732. (org-toggle-tag tag onoff)
  8733. (call-interactively #'org-set-tags-command))
  8734. (end-of-line 1)
  8735. (setq newhead (org-get-heading)))
  8736. (org-agenda-change-all-lines newhead hdmarker)
  8737. (beginning-of-line 1)))))
  8738. (defun org-agenda-set-property ()
  8739. "Set a property for the current headline."
  8740. (interactive)
  8741. (org-agenda-check-no-diary)
  8742. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8743. (org-agenda-error)))
  8744. (buffer (marker-buffer hdmarker))
  8745. (pos (marker-position hdmarker))
  8746. (inhibit-read-only t)
  8747. newhead)
  8748. (org-with-remote-undo buffer
  8749. (with-current-buffer buffer
  8750. (widen)
  8751. (goto-char pos)
  8752. (org-show-context 'agenda)
  8753. (call-interactively 'org-set-property)))))
  8754. (defun org-agenda-set-effort ()
  8755. "Set the effort property for the current headline."
  8756. (interactive)
  8757. (org-agenda-check-no-diary)
  8758. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8759. (org-agenda-error)))
  8760. (buffer (marker-buffer hdmarker))
  8761. (pos (marker-position hdmarker))
  8762. (inhibit-read-only t)
  8763. newhead)
  8764. (org-with-remote-undo buffer
  8765. (with-current-buffer buffer
  8766. (widen)
  8767. (goto-char pos)
  8768. (org-show-context 'agenda)
  8769. (call-interactively 'org-set-effort)
  8770. (end-of-line 1)
  8771. (setq newhead (org-get-heading)))
  8772. (org-agenda-change-all-lines newhead hdmarker))))
  8773. (defun org-agenda-toggle-archive-tag ()
  8774. "Toggle the archive tag for the current entry."
  8775. (interactive)
  8776. (org-agenda-check-no-diary)
  8777. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8778. (org-agenda-error)))
  8779. (buffer (marker-buffer hdmarker))
  8780. (pos (marker-position hdmarker))
  8781. (inhibit-read-only t)
  8782. newhead)
  8783. (org-with-remote-undo buffer
  8784. (with-current-buffer buffer
  8785. (widen)
  8786. (goto-char pos)
  8787. (org-show-context 'agenda)
  8788. (call-interactively 'org-toggle-archive-tag)
  8789. (end-of-line 1)
  8790. (setq newhead (org-get-heading)))
  8791. (org-agenda-change-all-lines newhead hdmarker)
  8792. (beginning-of-line 1))))
  8793. (defun org-agenda-do-date-later (arg)
  8794. (interactive "P")
  8795. (cond
  8796. ((or (equal arg '(16))
  8797. (memq last-command
  8798. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8799. (setq this-command 'org-agenda-date-later-minutes)
  8800. (org-agenda-date-later-minutes 1))
  8801. ((or (equal arg '(4))
  8802. (memq last-command
  8803. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8804. (setq this-command 'org-agenda-date-later-hours)
  8805. (org-agenda-date-later-hours 1))
  8806. (t
  8807. (org-agenda-date-later (prefix-numeric-value arg)))))
  8808. (defun org-agenda-do-date-earlier (arg)
  8809. (interactive "P")
  8810. (cond
  8811. ((or (equal arg '(16))
  8812. (memq last-command
  8813. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8814. (setq this-command 'org-agenda-date-earlier-minutes)
  8815. (org-agenda-date-earlier-minutes 1))
  8816. ((or (equal arg '(4))
  8817. (memq last-command
  8818. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8819. (setq this-command 'org-agenda-date-earlier-hours)
  8820. (org-agenda-date-earlier-hours 1))
  8821. (t
  8822. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8823. (defun org-agenda-date-later (arg &optional what)
  8824. "Change the date of this item to ARG day(s) later."
  8825. (interactive "p")
  8826. (org-agenda-check-type t 'agenda)
  8827. (org-agenda-check-no-diary)
  8828. (let* ((marker (or (org-get-at-bol 'org-marker)
  8829. (org-agenda-error)))
  8830. (buffer (marker-buffer marker))
  8831. (pos (marker-position marker))
  8832. cdate today)
  8833. (org-with-remote-undo buffer
  8834. (with-current-buffer buffer
  8835. (widen)
  8836. (goto-char pos)
  8837. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8838. (when (and org-agenda-move-date-from-past-immediately-to-today
  8839. (equal arg 1)
  8840. (or (not what) (eq what 'day))
  8841. (not (save-match-data (org-at-date-range-p))))
  8842. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8843. cdate (calendar-absolute-from-gregorian
  8844. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8845. today (org-today))
  8846. (when (> today cdate)
  8847. ;; immediately shift to today
  8848. (setq arg (- today cdate))))
  8849. (org-timestamp-change arg (or what 'day))
  8850. (when (and (org-at-date-range-p)
  8851. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8852. (let ((end org-last-changed-timestamp))
  8853. (org-timestamp-change arg (or what 'day))
  8854. (setq org-last-changed-timestamp
  8855. (concat org-last-changed-timestamp "--" end)))))
  8856. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8857. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8858. (defun org-agenda-date-earlier (arg &optional what)
  8859. "Change the date of this item to ARG day(s) earlier."
  8860. (interactive "p")
  8861. (org-agenda-date-later (- arg) what))
  8862. (defun org-agenda-date-later-minutes (arg)
  8863. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8864. (interactive "p")
  8865. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8866. (org-agenda-date-later arg 'minute))
  8867. (defun org-agenda-date-earlier-minutes (arg)
  8868. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8869. (interactive "p")
  8870. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8871. (org-agenda-date-earlier arg 'minute))
  8872. (defun org-agenda-date-later-hours (arg)
  8873. "Change the time of this item, in hour steps."
  8874. (interactive "p")
  8875. (org-agenda-date-later arg 'hour))
  8876. (defun org-agenda-date-earlier-hours (arg)
  8877. "Change the time of this item, in hour steps."
  8878. (interactive "p")
  8879. (org-agenda-date-earlier arg 'hour))
  8880. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8881. "Show new date stamp via text properties."
  8882. ;; We use text properties to make this undoable
  8883. (let ((inhibit-read-only t))
  8884. (setq stamp (concat prefix " => " stamp " "))
  8885. (save-excursion
  8886. (goto-char (point-max))
  8887. (while (not (bobp))
  8888. (when (equal marker (org-get-at-bol 'org-marker))
  8889. (remove-text-properties (point-at-bol) (point-at-eol) '(display nil))
  8890. (org-move-to-column (- (window-width) (length stamp)) t)
  8891. (add-text-properties
  8892. (1- (point)) (point-at-eol)
  8893. (list 'display (org-add-props stamp nil
  8894. 'face '(secondary-selection default))))
  8895. (beginning-of-line 1))
  8896. (beginning-of-line 0)))))
  8897. (defun org-agenda-date-prompt (arg)
  8898. "Change the date of this item. Date is prompted for, with default today.
  8899. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8900. be used to request time specification in the time stamp."
  8901. (interactive "P")
  8902. (org-agenda-check-type t 'agenda)
  8903. (org-agenda-check-no-diary)
  8904. (let* ((marker (or (org-get-at-bol 'org-marker)
  8905. (org-agenda-error)))
  8906. (buffer (marker-buffer marker))
  8907. (pos (marker-position marker)))
  8908. (org-with-remote-undo buffer
  8909. (with-current-buffer buffer
  8910. (widen)
  8911. (goto-char pos)
  8912. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8913. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8914. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8915. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8916. (defun org-agenda-schedule (arg &optional time)
  8917. "Schedule the item at point.
  8918. ARG is passed through to `org-schedule'."
  8919. (interactive "P")
  8920. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8921. (org-agenda-check-no-diary)
  8922. (let* ((marker (or (org-get-at-bol 'org-marker)
  8923. (org-agenda-error)))
  8924. (type (marker-insertion-type marker))
  8925. (buffer (marker-buffer marker))
  8926. (pos (marker-position marker))
  8927. ts)
  8928. (set-marker-insertion-type marker t)
  8929. (org-with-remote-undo buffer
  8930. (with-current-buffer buffer
  8931. (widen)
  8932. (goto-char pos)
  8933. (setq ts (org-schedule arg time)))
  8934. (org-agenda-show-new-time marker ts " S"))
  8935. (message "%s" ts)))
  8936. (defun org-agenda-deadline (arg &optional time)
  8937. "Schedule the item at point.
  8938. ARG is passed through to `org-deadline'."
  8939. (interactive "P")
  8940. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8941. (org-agenda-check-no-diary)
  8942. (let* ((marker (or (org-get-at-bol 'org-marker)
  8943. (org-agenda-error)))
  8944. (buffer (marker-buffer marker))
  8945. (pos (marker-position marker))
  8946. ts)
  8947. (org-with-remote-undo buffer
  8948. (with-current-buffer buffer
  8949. (widen)
  8950. (goto-char pos)
  8951. (setq ts (org-deadline arg time)))
  8952. (org-agenda-show-new-time marker ts " D"))
  8953. (message "%s" ts)))
  8954. (defun org-agenda-clock-in (&optional arg)
  8955. "Start the clock on the currently selected item."
  8956. (interactive "P")
  8957. (org-agenda-check-no-diary)
  8958. (if (equal arg '(4))
  8959. (org-clock-in arg)
  8960. (let* ((marker (or (org-get-at-bol 'org-marker)
  8961. (org-agenda-error)))
  8962. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8963. (pos (marker-position marker))
  8964. (col (current-column))
  8965. newhead)
  8966. (org-with-remote-undo (marker-buffer marker)
  8967. (with-current-buffer (marker-buffer marker)
  8968. (widen)
  8969. (goto-char pos)
  8970. (org-show-context 'agenda)
  8971. (org-clock-in arg)
  8972. (setq newhead (org-get-heading)))
  8973. (org-agenda-change-all-lines newhead hdmarker))
  8974. (org-move-to-column col))))
  8975. (defun org-agenda-clock-out ()
  8976. "Stop the currently running clock."
  8977. (interactive)
  8978. (unless (marker-buffer org-clock-marker)
  8979. (error "No running clock"))
  8980. (let ((marker (make-marker)) (col (current-column)) newhead)
  8981. (org-with-remote-undo (marker-buffer org-clock-marker)
  8982. (with-current-buffer (marker-buffer org-clock-marker)
  8983. (org-with-wide-buffer
  8984. (goto-char org-clock-marker)
  8985. (org-back-to-heading t)
  8986. (move-marker marker (point))
  8987. (org-clock-out)
  8988. (setq newhead (org-get-heading)))))
  8989. (org-agenda-change-all-lines newhead marker)
  8990. (move-marker marker nil)
  8991. (org-move-to-column col)
  8992. (org-agenda-unmark-clocking-task)))
  8993. (defun org-agenda-clock-cancel (&optional arg)
  8994. "Cancel the currently running clock."
  8995. (interactive "P")
  8996. (unless (marker-buffer org-clock-marker)
  8997. (user-error "No running clock"))
  8998. (org-with-remote-undo (marker-buffer org-clock-marker)
  8999. (org-clock-cancel)))
  9000. (defun org-agenda-clock-goto ()
  9001. "Jump to the currently clocked in task within the agenda.
  9002. If the currently clocked in task is not listed in the agenda
  9003. buffer, display it in another window."
  9004. (interactive)
  9005. (let (pos)
  9006. (mapc (lambda (o)
  9007. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9008. (setq pos (overlay-start o))))
  9009. (overlays-in (point-min) (point-max)))
  9010. (cond (pos (goto-char pos))
  9011. ;; If the currently clocked entry is not in the agenda
  9012. ;; buffer, we visit it in another window:
  9013. ((bound-and-true-p org-clock-current-task)
  9014. (org-switch-to-buffer-other-window (org-clock-goto)))
  9015. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9016. (defun org-agenda-diary-entry-in-org-file ()
  9017. "Make a diary entry in the file `org-agenda-diary-file'."
  9018. (let (d1 d2 char (text "") dp1 dp2)
  9019. (if (equal (buffer-name) "*Calendar*")
  9020. (setq d1 (calendar-cursor-to-date t)
  9021. d2 (car calendar-mark-ring))
  9022. (setq dp1 (get-text-property (point-at-bol) 'day))
  9023. (unless dp1 (user-error "No date defined in current line"))
  9024. (setq d1 (calendar-gregorian-from-absolute dp1)
  9025. d2 (and (ignore-errors (mark))
  9026. (save-excursion
  9027. (goto-char (mark))
  9028. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9029. (calendar-gregorian-from-absolute dp2))))
  9030. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9031. (setq char (read-char-exclusive))
  9032. (cond
  9033. ((equal char ?d)
  9034. (setq text (read-string "Day entry: "))
  9035. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9036. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9037. ((equal char ?a)
  9038. (setq d1 (list (car d1) (nth 1 d1)
  9039. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9040. (nth 2 d1))))
  9041. (setq text (read-string "Anniversary (use %d to show years): "))
  9042. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9043. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9044. ((equal char ?b)
  9045. (setq text (read-string "Block entry: "))
  9046. (unless (and d1 d2 (not (equal d1 d2)))
  9047. (user-error "No block of days selected"))
  9048. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9049. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9050. ((equal char ?j)
  9051. (org-switch-to-buffer-other-window
  9052. (find-file-noselect org-agenda-diary-file))
  9053. (require 'org-datetree)
  9054. (org-datetree-find-date-create d1)
  9055. (org-reveal t))
  9056. (t (user-error "Invalid selection character `%c'" char)))))
  9057. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9058. "Where in `org-agenda-diary-file' should new entries be added?
  9059. Valid values:
  9060. date-tree in the date tree, as first child of the date
  9061. date-tree-last in the date tree, as last child of the date
  9062. top-level as top-level entries at the end of the file."
  9063. :group 'org-agenda
  9064. :type '(choice
  9065. (const :tag "first in a date tree" date-tree)
  9066. (const :tag "last in a date tree" date-tree-last)
  9067. (const :tag "as top level at end of file" top-level)))
  9068. (defcustom org-agenda-insert-diary-extract-time nil
  9069. "Non-nil means extract any time specification from the diary entry."
  9070. :group 'org-agenda
  9071. :version "24.1"
  9072. :type 'boolean)
  9073. (defcustom org-agenda-bulk-mark-char ">"
  9074. "A single-character string to be used as the bulk mark."
  9075. :group 'org-agenda
  9076. :version "24.1"
  9077. :type 'string)
  9078. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9079. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9080. If TEXT is not empty, it will become the headline of the new entry, and
  9081. the resulting entry will not be shown. When TEXT is empty, switch to
  9082. `org-agenda-diary-file' and let the user finish the entry there."
  9083. (let ((cw (current-window-configuration)))
  9084. (org-switch-to-buffer-other-window
  9085. (find-file-noselect org-agenda-diary-file))
  9086. (widen)
  9087. (goto-char (point-min))
  9088. (cl-case type
  9089. (anniversary
  9090. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9091. (progn
  9092. (or (org-at-heading-p t)
  9093. (progn
  9094. (outline-next-heading)
  9095. (insert "* Anniversaries\n\n")
  9096. (beginning-of-line -1)))))
  9097. (outline-next-heading)
  9098. (org-back-over-empty-lines)
  9099. (backward-char 1)
  9100. (insert "\n")
  9101. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9102. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9103. (day
  9104. (let ((org-prefix-has-time t)
  9105. (org-agenda-time-leading-zero t)
  9106. fmt time time2)
  9107. (when org-agenda-insert-diary-extract-time
  9108. ;; Use org-agenda-format-item to parse text for a time-range and
  9109. ;; remove it. FIXME: This is a hack, we should refactor
  9110. ;; that function to make time extraction available separately
  9111. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9112. time (get-text-property 0 'time fmt)
  9113. time2 (if (> (length time) 0)
  9114. ;; split-string removes trailing ...... if
  9115. ;; no end time given. First space
  9116. ;; separates time from date.
  9117. (concat " " (car (split-string time "\\.")))
  9118. nil)
  9119. text (get-text-property 0 'txt fmt)))
  9120. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9121. (org-agenda-insert-diary-as-top-level text)
  9122. (require 'org-datetree)
  9123. (org-datetree-find-date-create d1)
  9124. (org-agenda-insert-diary-make-new-entry text))
  9125. (org-insert-time-stamp (org-time-from-absolute
  9126. (calendar-absolute-from-gregorian d1))
  9127. nil nil nil nil time2))
  9128. (end-of-line 0))
  9129. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9130. ;; otherwise the indentation gets confused by the
  9131. ;; special meaning of 'block
  9132. (when (> (calendar-absolute-from-gregorian d1)
  9133. (calendar-absolute-from-gregorian d2))
  9134. (setq d1 (prog1 d2 (setq d2 d1))))
  9135. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9136. (org-agenda-insert-diary-as-top-level text)
  9137. (require 'org-datetree)
  9138. (org-datetree-find-date-create d1)
  9139. (org-agenda-insert-diary-make-new-entry text))
  9140. (org-insert-time-stamp (org-time-from-absolute
  9141. (calendar-absolute-from-gregorian d1)))
  9142. (insert "--")
  9143. (org-insert-time-stamp (org-time-from-absolute
  9144. (calendar-absolute-from-gregorian d2)))
  9145. (end-of-line 0)))
  9146. (if (string-match "\\S-" text)
  9147. (progn
  9148. (set-window-configuration cw)
  9149. (message "%s entry added to %s"
  9150. (capitalize (symbol-name type))
  9151. (abbreviate-file-name org-agenda-diary-file)))
  9152. (org-reveal t)
  9153. (message "Please finish entry here"))))
  9154. (defun org-agenda-insert-diary-as-top-level (text)
  9155. "Make new entry as a top-level entry at the end of the file.
  9156. Add TEXT as headline, and position the cursor in the second line so that
  9157. a timestamp can be added there."
  9158. (widen)
  9159. (goto-char (point-max))
  9160. (unless (bolp) (insert "\n"))
  9161. (org-insert-heading nil t t)
  9162. (insert text)
  9163. (org-end-of-meta-data)
  9164. (unless (bolp) (insert "\n"))
  9165. (when org-adapt-indentation (indent-to-column 2)))
  9166. (defun org-agenda-insert-diary-make-new-entry (text)
  9167. "Make a new entry with TEXT as a child of the current subtree.
  9168. Position the point in the heading's first body line so that
  9169. a timestamp can be added there."
  9170. (cond
  9171. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9172. (end-of-line)
  9173. (org-insert-heading '(4) t)
  9174. (org-do-demote))
  9175. (t
  9176. (outline-next-heading)
  9177. (org-back-over-empty-lines)
  9178. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9179. (org-insert-heading nil t)
  9180. (org-do-demote)))
  9181. (let ((col (current-column)))
  9182. (insert text)
  9183. (org-end-of-meta-data)
  9184. ;; Ensure point is left on a blank line, at proper indentation.
  9185. (unless (bolp) (insert "\n"))
  9186. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9187. (when org-adapt-indentation (indent-to-column col)))
  9188. (org-show-set-visibility 'lineage))
  9189. (defun org-agenda-diary-entry ()
  9190. "Make a diary entry, like the `i' command from the calendar.
  9191. All the standard commands work: block, weekly etc.
  9192. When `org-agenda-diary-file' points to a file,
  9193. `org-agenda-diary-entry-in-org-file' is called instead to create
  9194. entries in that Org file."
  9195. (interactive)
  9196. (if (not (eq org-agenda-diary-file 'diary-file))
  9197. (org-agenda-diary-entry-in-org-file)
  9198. (require 'diary-lib)
  9199. (let* ((char (read-char-exclusive
  9200. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9201. [a]nniversary [b]lock [c]yclic"))
  9202. (cmd (cdr (assoc char
  9203. '((?d . diary-insert-entry)
  9204. (?w . diary-insert-weekly-entry)
  9205. (?m . diary-insert-monthly-entry)
  9206. (?y . diary-insert-yearly-entry)
  9207. (?a . diary-insert-anniversary-entry)
  9208. (?b . diary-insert-block-entry)
  9209. (?c . diary-insert-cyclic-entry)))))
  9210. (oldf (symbol-function 'calendar-cursor-to-date))
  9211. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9212. (point (point))
  9213. (mark (or (mark t) (point))))
  9214. (unless cmd
  9215. (user-error "No command associated with <%c>" char))
  9216. (unless (and (get-text-property point 'day)
  9217. (or (not (equal ?b char))
  9218. (get-text-property mark 'day)))
  9219. (user-error "Don't know which date to use for diary entry"))
  9220. ;; We implement this by hacking the `calendar-cursor-to-date' function
  9221. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  9222. (let ((calendar-mark-ring
  9223. (list (calendar-gregorian-from-absolute
  9224. (or (get-text-property mark 'day)
  9225. (get-text-property point 'day))))))
  9226. (unwind-protect
  9227. (progn
  9228. (fset 'calendar-cursor-to-date
  9229. (lambda (&optional error dummy)
  9230. (calendar-gregorian-from-absolute
  9231. (get-text-property point 'day))))
  9232. (call-interactively cmd))
  9233. (fset 'calendar-cursor-to-date oldf))))))
  9234. (defun org-agenda-execute-calendar-command (cmd)
  9235. "Execute a calendar command from the agenda with date from cursor."
  9236. (org-agenda-check-type t 'agenda)
  9237. (require 'diary-lib)
  9238. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  9239. (user-error "Don't know which date to use for the calendar command"))
  9240. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  9241. (point (point))
  9242. (date (calendar-gregorian-from-absolute
  9243. (get-text-property point 'day)))
  9244. ;; the following 2 vars are needed in the calendar
  9245. (displayed-month (car date))
  9246. (displayed-year (nth 2 date)))
  9247. (unwind-protect
  9248. (progn
  9249. (fset 'calendar-cursor-to-date
  9250. (lambda (&optional error dummy)
  9251. (calendar-gregorian-from-absolute
  9252. (get-text-property point 'day))))
  9253. (call-interactively cmd))
  9254. (fset 'calendar-cursor-to-date oldf))))
  9255. (defun org-agenda-phases-of-moon ()
  9256. "Display the phases of the moon for the 3 months around the cursor date."
  9257. (interactive)
  9258. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  9259. (defun org-agenda-holidays ()
  9260. "Display the holidays for the 3 months around the cursor date."
  9261. (interactive)
  9262. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  9263. (defvar calendar-longitude) ; defined in calendar.el
  9264. (defvar calendar-latitude) ; defined in calendar.el
  9265. (defvar calendar-location-name) ; defined in calendar.el
  9266. (defun org-agenda-sunrise-sunset (arg)
  9267. "Display sunrise and sunset for the cursor date.
  9268. Latitude and longitude can be specified with the variables
  9269. `calendar-latitude' and `calendar-longitude'. When called with prefix
  9270. argument, latitude and longitude will be prompted for."
  9271. (interactive "P")
  9272. (require 'solar)
  9273. (let ((calendar-longitude (if arg nil calendar-longitude))
  9274. (calendar-latitude (if arg nil calendar-latitude))
  9275. (calendar-location-name
  9276. (if arg "the given coordinates" calendar-location-name)))
  9277. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  9278. (defun org-agenda-goto-calendar ()
  9279. "Open the Emacs calendar with the date at the cursor."
  9280. (interactive)
  9281. (org-agenda-check-type t 'agenda)
  9282. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  9283. (user-error "Don't know which date to open in calendar")))
  9284. (date (calendar-gregorian-from-absolute day))
  9285. (calendar-move-hook nil)
  9286. (calendar-view-holidays-initially-flag nil)
  9287. (calendar-view-diary-initially-flag nil))
  9288. (calendar)
  9289. (calendar-goto-date date)))
  9290. ;;;###autoload
  9291. (defun org-calendar-goto-agenda ()
  9292. "Compute the Org agenda for the calendar date displayed at the cursor.
  9293. This is a command that has to be installed in `calendar-mode-map'."
  9294. (interactive)
  9295. ;; Temporarily disable sticky agenda since user clearly wants to
  9296. ;; refresh view anyway.
  9297. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  9298. (org-agenda-sticky nil))
  9299. (org-agenda-list nil (calendar-absolute-from-gregorian
  9300. (calendar-cursor-to-date))
  9301. nil)))
  9302. (defun org-agenda-convert-date ()
  9303. (interactive)
  9304. (org-agenda-check-type t 'agenda)
  9305. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9306. date s)
  9307. (unless day
  9308. (user-error "Don't know which date to convert"))
  9309. (setq date (calendar-gregorian-from-absolute day))
  9310. (setq s (concat
  9311. "Gregorian: " (calendar-date-string date) "\n"
  9312. "ISO: " (calendar-iso-date-string date) "\n"
  9313. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9314. "Julian: " (calendar-julian-date-string date) "\n"
  9315. "Astron. JD: " (calendar-astro-date-string date)
  9316. " (Julian date number at noon UTC)\n"
  9317. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9318. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9319. "French: " (calendar-french-date-string date) "\n"
  9320. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9321. "Mayan: " (calendar-mayan-date-string date) "\n"
  9322. "Coptic: " (calendar-coptic-date-string date) "\n"
  9323. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9324. "Persian: " (calendar-persian-date-string date) "\n"
  9325. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9326. (with-output-to-temp-buffer "*Dates*"
  9327. (princ s))
  9328. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9329. ;;; Bulk commands
  9330. (defun org-agenda-bulk-marked-p ()
  9331. "Non-nil when current entry is marked for bulk action."
  9332. (eq (get-char-property (point-at-bol) 'type)
  9333. 'org-marked-entry-overlay))
  9334. (defun org-agenda-bulk-mark (&optional arg)
  9335. "Mark entries for future bulk action.
  9336. When ARG is nil or one and region is not active then mark the
  9337. entry at point.
  9338. When ARG is nil or one and region is active then mark the entries
  9339. in the region.
  9340. When ARG is greater than one mark ARG lines."
  9341. (interactive "p")
  9342. (when (and (or (not arg) (= arg 1)) (use-region-p))
  9343. (setq arg (count-lines (region-beginning) (region-end)))
  9344. (goto-char (region-beginning))
  9345. (deactivate-mark))
  9346. (dotimes (i (or arg 1))
  9347. (unless (org-get-at-bol 'org-agenda-diary-link)
  9348. (let* ((m (org-get-at-bol 'org-hd-marker))
  9349. ov)
  9350. (unless (org-agenda-bulk-marked-p)
  9351. (unless m (user-error "Nothing to mark at point"))
  9352. (push m org-agenda-bulk-marked-entries)
  9353. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9354. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9355. (org-get-todo-face "TODO")
  9356. 'evaporate)
  9357. (overlay-put ov 'type 'org-marked-entry-overlay))
  9358. (end-of-line 1)
  9359. (or (ignore-errors
  9360. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9361. (beginning-of-line 2))
  9362. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9363. (beginning-of-line 2)))))
  9364. (message "%d entries marked for bulk action"
  9365. (length org-agenda-bulk-marked-entries)))
  9366. (defun org-agenda-bulk-mark-all ()
  9367. "Mark all entries for future agenda bulk action."
  9368. (interactive)
  9369. (org-agenda-bulk-mark-regexp "."))
  9370. (defun org-agenda-bulk-mark-regexp (regexp)
  9371. "Mark entries matching REGEXP for future agenda bulk action."
  9372. (interactive "sMark entries matching regexp: ")
  9373. (let ((entries-marked 0) txt-at-point)
  9374. (save-excursion
  9375. (goto-char (point-min))
  9376. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9377. (while (and (re-search-forward regexp nil t)
  9378. (setq txt-at-point (get-text-property (point) 'txt)))
  9379. (if (get-char-property (point) 'invisible)
  9380. (beginning-of-line 2)
  9381. (when (string-match regexp txt-at-point)
  9382. (setq entries-marked (1+ entries-marked))
  9383. (call-interactively 'org-agenda-bulk-mark)))))
  9384. (unless entries-marked
  9385. (message "No entry matching this regexp."))))
  9386. (defun org-agenda-bulk-unmark (&optional arg)
  9387. "Unmark the entry at point for future bulk action."
  9388. (interactive "P")
  9389. (if arg
  9390. (org-agenda-bulk-unmark-all)
  9391. (cond ((org-agenda-bulk-marked-p)
  9392. (org-agenda-bulk-remove-overlays
  9393. (point-at-bol) (+ 2 (point-at-bol)))
  9394. (setq org-agenda-bulk-marked-entries
  9395. (delete (org-get-at-bol 'org-hd-marker)
  9396. org-agenda-bulk-marked-entries))
  9397. (end-of-line 1)
  9398. (or (ignore-errors
  9399. (goto-char (next-single-property-change (point) 'txt)))
  9400. (beginning-of-line 2))
  9401. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9402. (beginning-of-line 2))
  9403. (message "%d entries left marked for bulk action"
  9404. (length org-agenda-bulk-marked-entries)))
  9405. (t (message "No entry to unmark here")))))
  9406. (defun org-agenda-bulk-toggle-all ()
  9407. "Toggle all marks for bulk action."
  9408. (interactive)
  9409. (save-excursion
  9410. (goto-char (point-min))
  9411. (while (ignore-errors
  9412. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9413. (org-agenda-bulk-toggle))))
  9414. (defun org-agenda-bulk-toggle ()
  9415. "Toggle the mark at point for bulk action."
  9416. (interactive)
  9417. (if (org-agenda-bulk-marked-p)
  9418. (org-agenda-bulk-unmark)
  9419. (org-agenda-bulk-mark)))
  9420. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9421. "Remove the mark overlays between BEG and END in the agenda buffer.
  9422. BEG and END default to the buffer limits.
  9423. This only removes the overlays, it does not remove the markers
  9424. from the list in `org-agenda-bulk-marked-entries'."
  9425. (interactive)
  9426. (mapc (lambda (ov)
  9427. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9428. (delete-overlay ov)))
  9429. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9430. (defun org-agenda-bulk-unmark-all ()
  9431. "Remove all marks in the agenda buffer.
  9432. This will remove the markers and the overlays."
  9433. (interactive)
  9434. (if (null org-agenda-bulk-marked-entries)
  9435. (message "No entry to unmark")
  9436. (setq org-agenda-bulk-marked-entries nil)
  9437. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9438. (defcustom org-agenda-persistent-marks nil
  9439. "Non-nil means marked items will stay marked after a bulk action.
  9440. You can toggle this interactively by typing `p' when prompted for a
  9441. bulk action."
  9442. :group 'org-agenda
  9443. :version "24.1"
  9444. :type 'boolean)
  9445. (defun org-agenda-bulk-action (&optional arg)
  9446. "Execute an remote-editing action on all marked entries.
  9447. The prefix arg is passed through to the command if possible."
  9448. (interactive "P")
  9449. ;; When there is no mark, act on the agenda entry at point.
  9450. (if (not org-agenda-bulk-marked-entries)
  9451. (save-excursion (org-agenda-bulk-mark)))
  9452. (dolist (m org-agenda-bulk-marked-entries)
  9453. (unless (and (markerp m)
  9454. (marker-buffer m)
  9455. (buffer-live-p (marker-buffer m))
  9456. (marker-position m))
  9457. (user-error "Marker %s for bulk command is invalid" m)))
  9458. ;; Prompt for the bulk command.
  9459. (org-unlogged-message
  9460. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  9461. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9462. "[S]catter [f]unction "
  9463. (and org-agenda-bulk-custom-functions
  9464. (format " Custom: [%s]"
  9465. (mapconcat (lambda (f) (char-to-string (car f)))
  9466. org-agenda-bulk-custom-functions
  9467. "")))))
  9468. (catch 'exit
  9469. (let* ((org-log-refile (if org-log-refile 'time nil))
  9470. (entries (reverse org-agenda-bulk-marked-entries))
  9471. (org-overriding-default-time
  9472. (and (get-text-property (point) 'org-agenda-date-header)
  9473. (org-get-cursor-date)))
  9474. redo-at-end
  9475. cmd)
  9476. (pcase (read-char-exclusive)
  9477. (?p
  9478. (let ((org-agenda-persistent-marks
  9479. (not org-agenda-persistent-marks)))
  9480. (org-agenda-bulk-action)
  9481. (throw 'exit nil)))
  9482. (?$
  9483. (setq cmd #'org-agenda-archive))
  9484. (?A
  9485. (setq cmd #'org-agenda-archive-to-archive-sibling))
  9486. ((or ?r ?w)
  9487. (let ((refile-location
  9488. (org-refile-get-location
  9489. "Refile to"
  9490. (marker-buffer (car entries))
  9491. org-refile-allow-creating-parent-nodes)))
  9492. (when (nth 3 refile-location)
  9493. (setcar (nthcdr 3 refile-location)
  9494. (move-marker
  9495. (make-marker)
  9496. (nth 3 refile-location)
  9497. (or (get-file-buffer (nth 1 refile-location))
  9498. (find-buffer-visiting (nth 1 refile-location))
  9499. (error "This should not happen")))))
  9500. (setq cmd `(lambda () (org-agenda-refile nil ',refile-location t)))
  9501. (setq redo-at-end t)))
  9502. (?t
  9503. (let ((state (completing-read
  9504. "Todo state: "
  9505. (with-current-buffer (marker-buffer (car entries))
  9506. (mapcar #'list org-todo-keywords-1)))))
  9507. (setq cmd `(lambda ()
  9508. (let ((org-inhibit-blocking t)
  9509. (org-inhibit-logging 'note))
  9510. (org-agenda-todo ,state))))))
  9511. ((and (or ?- ?+) action)
  9512. (let ((tag (completing-read
  9513. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9514. (with-current-buffer (marker-buffer (car entries))
  9515. (delq nil
  9516. (mapcar (lambda (x) (and (stringp (car x)) x))
  9517. org-current-tag-alist))))))
  9518. (setq cmd
  9519. `(lambda ()
  9520. (org-agenda-set-tags ,tag
  9521. ,(if (eq action ?+) ''on ''off))))))
  9522. ((and (or ?s ?d) c)
  9523. (let* ((schedule? (eq c ?s))
  9524. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  9525. (time
  9526. (and (not arg)
  9527. (let ((new (org-read-date
  9528. nil nil nil prompt org-overriding-default-time)))
  9529. ;; A "double plus" answer applies to every
  9530. ;; scheduled time. Do not turn it into
  9531. ;; a fixed date yet.
  9532. (if (string-match-p "\\`[ \t]*\\+\\+"
  9533. org-read-date-final-answer)
  9534. org-read-date-final-answer
  9535. new)))))
  9536. ;; Make sure to not prompt for a note when bulk
  9537. ;; rescheduling/resetting deadline as Org cannot cope with
  9538. ;; simultaneous notes. Besides, it could be annoying
  9539. ;; depending on the number of marked items.
  9540. (setq cmd
  9541. (if schedule?
  9542. `(lambda ()
  9543. (let ((org-log-reschedule
  9544. (and org-log-reschedule 'time)))
  9545. (org-agenda-schedule arg ,time)))
  9546. `(lambda ()
  9547. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  9548. (org-agenda-deadline arg ,time)))))))
  9549. (?S
  9550. (unless (org-agenda-check-type nil 'agenda 'todo)
  9551. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  9552. (let ((days (read-number
  9553. (format "Scatter tasks across how many %sdays: "
  9554. (if arg "week" ""))
  9555. 7)))
  9556. (setq cmd
  9557. `(lambda ()
  9558. (let ((distance (1+ (random ,days))))
  9559. (when arg
  9560. (let ((dist distance)
  9561. (day-of-week
  9562. (calendar-day-of-week
  9563. (calendar-gregorian-from-absolute (org-today)))))
  9564. (dotimes (i (1+ dist))
  9565. (while (member day-of-week org-agenda-weekend-days)
  9566. (cl-incf distance)
  9567. (cl-incf day-of-week)
  9568. (when (= day-of-week 7)
  9569. (setq day-of-week 0)))
  9570. (cl-incf day-of-week)
  9571. (when (= day-of-week 7)
  9572. (setq day-of-week 0)))))
  9573. ;; Silently fail when try to replan a sexp entry.
  9574. (ignore-errors
  9575. (let* ((date (calendar-gregorian-from-absolute
  9576. (+ (org-today) distance)))
  9577. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9578. (nth 2 date))))
  9579. (org-agenda-schedule nil time))))))))
  9580. (?f
  9581. (setq cmd
  9582. (intern
  9583. (completing-read "Function: " obarray #'fboundp t nil nil))))
  9584. (action
  9585. (pcase (assoc action org-agenda-bulk-custom-functions)
  9586. (`(,_ ,f) (setq cmd f) (setq redo-at-end t))
  9587. (_ (user-error "Invalid bulk action: %c" action)))))
  9588. ;; Sort the markers, to make sure that parents are handled
  9589. ;; before children.
  9590. (setq entries (sort entries
  9591. (lambda (a b)
  9592. (cond
  9593. ((eq (marker-buffer a) (marker-buffer b))
  9594. (< (marker-position a) (marker-position b)))
  9595. (t
  9596. (string< (buffer-name (marker-buffer a))
  9597. (buffer-name (marker-buffer b))))))))
  9598. ;; Now loop over all markers and apply CMD.
  9599. (let ((processed 0)
  9600. (skipped 0))
  9601. (dolist (e entries)
  9602. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  9603. (if (not pos)
  9604. (progn (message "Skipping removed entry at %s" e)
  9605. (cl-incf skipped))
  9606. (goto-char pos)
  9607. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  9608. ;; `post-command-hook' is not run yet. We make sure any
  9609. ;; pending log note is processed.
  9610. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9611. (memq 'org-add-log-note post-command-hook))
  9612. (org-add-log-note))
  9613. (cl-incf processed))))
  9614. (when redo-at-end (org-agenda-redo))
  9615. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  9616. (message "Acted on %d entries%s%s"
  9617. processed
  9618. (if (= skipped 0)
  9619. ""
  9620. (format ", skipped %d (disappeared before their turn)"
  9621. skipped))
  9622. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  9623. (defun org-agenda-capture (&optional with-time)
  9624. "Call `org-capture' with the date at point.
  9625. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9626. current HH:MM time."
  9627. (interactive "P")
  9628. (if (not (eq major-mode 'org-agenda-mode))
  9629. (user-error "You cannot do this outside of agenda buffers")
  9630. (let ((org-overriding-default-time
  9631. (org-get-cursor-date (equal with-time 1))))
  9632. (call-interactively 'org-capture))))
  9633. ;;; Dragging agenda lines forward/backward
  9634. (defun org-agenda-reapply-filters ()
  9635. "Re-apply all agenda filters."
  9636. (mapcar
  9637. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9638. `((,org-agenda-tag-filter tag)
  9639. (,org-agenda-category-filter category)
  9640. (,org-agenda-regexp-filter regexp)
  9641. (,org-agenda-effort-filter effort)
  9642. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9643. (,(get 'org-agenda-category-filter :preset-filter) category)
  9644. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9645. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9646. (defun org-agenda-drag-line-forward (arg &optional backward)
  9647. "Drag an agenda line forward by ARG lines.
  9648. When the optional argument `backward' is non-nil, move backward."
  9649. (interactive "p")
  9650. (let ((inhibit-read-only t) lst line)
  9651. (if (or (not (get-text-property (point) 'txt))
  9652. (save-excursion
  9653. (dotimes (n arg)
  9654. (move-beginning-of-line (if backward 0 2))
  9655. (push (not (get-text-property (point) 'txt)) lst))
  9656. (delq nil lst)))
  9657. (message "Cannot move line forward")
  9658. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9659. (move-beginning-of-line 1)
  9660. (setq line (buffer-substring (point) end))
  9661. (delete-region (point) end)
  9662. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9663. (insert line)
  9664. (org-agenda-reapply-filters)
  9665. (org-agenda-mark-clocking-task)
  9666. (move-beginning-of-line 0)))))
  9667. (defun org-agenda-drag-line-backward (arg)
  9668. "Drag an agenda line backward by ARG lines."
  9669. (interactive "p")
  9670. (org-agenda-drag-line-forward arg t))
  9671. ;;; Flagging notes
  9672. (defun org-agenda-show-the-flagging-note ()
  9673. "Display the flagging note in the other window.
  9674. When called a second time in direct sequence, offer to remove the FLAGGING
  9675. tag and (if present) the flagging note."
  9676. (interactive)
  9677. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9678. (win (selected-window))
  9679. note heading newhead)
  9680. (unless hdmarker
  9681. (user-error "No linked entry at point"))
  9682. (if (and (eq this-command last-command)
  9683. (y-or-n-p "Unflag and remove any flagging note? "))
  9684. (progn
  9685. (org-agenda-remove-flag hdmarker)
  9686. (let ((win (get-buffer-window "*Flagging Note*")))
  9687. (and win (delete-window win)))
  9688. (message "Entry unflagged"))
  9689. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9690. (unless note
  9691. (user-error "No flagging note"))
  9692. (org-kill-new note)
  9693. (org-switch-to-buffer-other-window "*Flagging Note*")
  9694. (erase-buffer)
  9695. (insert note)
  9696. (goto-char (point-min))
  9697. (while (re-search-forward "\\\\n" nil t)
  9698. (replace-match "\n" t t))
  9699. (goto-char (point-min))
  9700. (select-window win)
  9701. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9702. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  9703. tag and note")))))
  9704. (defun org-agenda-remove-flag (marker)
  9705. "Remove the FLAGGED tag and any flagging note in the entry."
  9706. (let (newhead)
  9707. (org-with-point-at marker
  9708. (org-toggle-tag "FLAGGED" 'off)
  9709. (org-entry-delete nil "THEFLAGGINGNOTE")
  9710. (setq newhead (org-get-heading)))
  9711. (org-agenda-change-all-lines newhead marker)
  9712. (message "Entry unflagged")))
  9713. (defun org-agenda-get-any-marker (&optional pos)
  9714. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9715. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9716. ;;; Appointment reminders
  9717. (defvar appt-time-msg-list) ; defined in appt.el
  9718. ;;;###autoload
  9719. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9720. "Activate appointments found in `org-agenda-files'.
  9721. With a `\\[universal-argument]' prefix, refresh the list of \
  9722. appointments.
  9723. If FILTER is t, interactively prompt the user for a regular
  9724. expression, and filter out entries that don't match it.
  9725. If FILTER is a string, use this string as a regular expression
  9726. for filtering entries out.
  9727. If FILTER is a function, filter out entries against which
  9728. calling the function returns nil. This function takes one
  9729. argument: an entry from `org-agenda-get-day-entries'.
  9730. FILTER can also be an alist with the car of each cell being
  9731. either `headline' or `category'. For example:
  9732. \\='((headline \"IMPORTANT\")
  9733. (category \"Work\"))
  9734. will only add headlines containing IMPORTANT or headlines
  9735. belonging to the \"Work\" category.
  9736. ARGS are symbols indicating what kind of entries to consider.
  9737. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9738. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9739. and :timestamp entries. See the docstring of `org-diary' for
  9740. details and examples.
  9741. If an entry has a APPT_WARNTIME property, its value will be used
  9742. to override `appt-message-warning-time'."
  9743. (interactive "P")
  9744. (when refresh (setq appt-time-msg-list nil))
  9745. (when (eq filter t)
  9746. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9747. (let* ((cnt 0) ; count added events
  9748. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9749. (org-agenda-new-buffers nil)
  9750. (org-deadline-warning-days 0)
  9751. ;; Do not use `org-today' here because appt only takes
  9752. ;; time and without date as argument, so it may pass wrong
  9753. ;; information otherwise
  9754. (today (org-date-to-gregorian
  9755. (time-to-days nil)))
  9756. (org-agenda-restrict nil)
  9757. (files (org-agenda-files 'unrestricted)) entries file
  9758. (org-agenda-buffer nil))
  9759. ;; Get all entries which may contain an appt
  9760. (org-agenda-prepare-buffers files)
  9761. (while (setq file (pop files))
  9762. (setq entries
  9763. (delq nil
  9764. (append entries
  9765. (apply 'org-agenda-get-day-entries
  9766. file today scope)))))
  9767. ;; Map through entries and find if we should filter them out
  9768. (mapc
  9769. (lambda (x)
  9770. (let* ((evt (org-trim
  9771. (replace-regexp-in-string
  9772. org-link-bracket-re "\\2"
  9773. (or (get-text-property 1 'txt x) ""))))
  9774. (cat (get-text-property (1- (length x)) 'org-category x))
  9775. (tod (get-text-property 1 'time-of-day x))
  9776. (ok (or (null filter)
  9777. (and (stringp filter) (string-match filter evt))
  9778. (and (functionp filter) (funcall filter x))
  9779. (and (listp filter)
  9780. (let ((cat-filter (cadr (assq 'category filter)))
  9781. (evt-filter (cadr (assq 'headline filter))))
  9782. (or (and (stringp cat-filter)
  9783. (string-match cat-filter cat))
  9784. (and (stringp evt-filter)
  9785. (string-match evt-filter evt)))))))
  9786. (wrn (get-text-property 1 'warntime x)))
  9787. ;; FIXME: Shall we remove text-properties for the appt text?
  9788. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9789. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9790. (setq tod (concat "00" (number-to-string tod)))
  9791. (setq tod (when (string-match
  9792. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9793. (concat (match-string 1 tod) ":"
  9794. (match-string 2 tod))))
  9795. (when (appt-add tod evt wrn)
  9796. (setq cnt (1+ cnt))))))
  9797. entries)
  9798. (org-release-buffers org-agenda-new-buffers)
  9799. (if (eq cnt 0)
  9800. (message "No event to add")
  9801. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9802. (defun org-agenda-today-p (date)
  9803. "Non-nil when DATE means today.
  9804. DATE is either a list of the form (month day year) or a number of
  9805. days as returned by `calendar-absolute-from-gregorian' or
  9806. `org-today'. This function considers `org-extend-today-until'
  9807. when defining today."
  9808. (eq (org-today)
  9809. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9810. (defun org-agenda-todo-yesterday (&optional arg)
  9811. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9812. (interactive "P")
  9813. (let* ((org-use-effective-time t)
  9814. (hour (nth 2 (decode-time (org-current-time))))
  9815. (org-extend-today-until (1+ hour)))
  9816. (org-agenda-todo arg)))
  9817. (provide 'org-agenda)
  9818. ;;; org-agenda.el ends here