org-agenda.el 395 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: https://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'cl-lib)
  42. (require 'org)
  43. (require 'org-macs)
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-columns-remove-overlays "org-colview" ())
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-agenda-columns "org-colview" ())
  74. (declare-function org-add-archive-files "org-archive" (files))
  75. (declare-function org-capture "org-capture" (&optional goto keys))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task)
  78. (defvar org-current-tag-alist)
  79. (defvar org-mobile-force-id-on-agenda-items)
  80. (defvar org-habit-show-habits)
  81. (defvar org-habit-show-habits-only-for-today)
  82. (defvar org-habit-show-all-today)
  83. ;; Defined somewhere in this file, but used before definition.
  84. (defvar org-agenda-buffer-name "*Org Agenda*")
  85. (defvar org-agenda-overriding-header nil)
  86. (defvar org-agenda-title-append nil)
  87. (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  88. (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defvar org-agenda-undo-list nil
  91. "List of undoable operations in the agenda since last refresh.")
  92. (defvar org-agenda-pending-undo-list nil
  93. "In a series of undo commands, this is the list of remaining undo items.")
  94. (defcustom org-agenda-confirm-kill 1
  95. "When set, remote killing from the agenda buffer needs confirmation.
  96. When t, a confirmation is always needed. When a number N, confirmation is
  97. only needed when the text to be killed contains more than N non-white lines."
  98. :group 'org-agenda
  99. :type '(choice
  100. (const :tag "Never" nil)
  101. (const :tag "Always" t)
  102. (integer :tag "When more than N lines")))
  103. (defcustom org-agenda-compact-blocks nil
  104. "Non-nil means make the block agenda more compact.
  105. This is done globally by leaving out lines like the agenda span
  106. name and week number or the separator lines."
  107. :group 'org-agenda
  108. :type 'boolean)
  109. (defcustom org-agenda-block-separator ?=
  110. "The separator between blocks in the agenda.
  111. If this is a string, it will be used as the separator, with a newline added.
  112. If it is a character, it will be repeated to fill the window width.
  113. If nil the separator is disabled. In `org-agenda-custom-commands' this
  114. addresses the separator between the current and the previous block."
  115. :group 'org-agenda
  116. :type '(choice
  117. (const :tag "Disabled" nil)
  118. (character)
  119. (string)))
  120. (defgroup org-agenda-export nil
  121. "Options concerning exporting agenda views in Org mode."
  122. :tag "Org Agenda Export"
  123. :group 'org-agenda)
  124. (defcustom org-agenda-with-colors t
  125. "Non-nil means use colors in agenda views."
  126. :group 'org-agenda-export
  127. :type 'boolean)
  128. (defcustom org-agenda-exporter-settings nil
  129. "Alist of variable/value pairs that should be active during agenda export.
  130. This is a good place to set options for ps-print and for htmlize.
  131. Note that the way this is implemented, the values will be evaluated
  132. before assigned to the variables. So make sure to quote values you do
  133. *not* want evaluated, for example
  134. (setq org-agenda-exporter-settings
  135. \\='((ps-print-color-p \\='black-white)))"
  136. :group 'org-agenda-export
  137. :type '(repeat
  138. (list
  139. (variable)
  140. (sexp :tag "Value"))))
  141. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  142. "Hook run in a temporary buffer before writing the agenda to an export file.
  143. A useful function for this hook is `org-agenda-add-entry-text'."
  144. :group 'org-agenda-export
  145. :type 'hook
  146. :options '(org-agenda-add-entry-text))
  147. (defcustom org-agenda-add-entry-text-maxlines 0
  148. "Maximum number of entry text lines to be added to agenda.
  149. This is only relevant when `org-agenda-add-entry-text' is part of
  150. `org-agenda-before-write-hook', which is the default.
  151. When this is 0, nothing will happen. When it is greater than 0, it
  152. specifies the maximum number of lines that will be added for each entry
  153. that is listed in the agenda view.
  154. Note that this variable is not used during display, only when exporting
  155. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  156. and `org-agenda-entry-text-maxlines'."
  157. :group 'org-agenda
  158. :type 'integer)
  159. (defcustom org-agenda-add-entry-text-descriptive-links t
  160. "Non-nil means export org-links as descriptive links in agenda added text.
  161. This variable applies to the text added to the agenda when
  162. `org-agenda-add-entry-text-maxlines' is larger than 0.
  163. When this variable nil, the URL will (also) be shown."
  164. :group 'org-agenda
  165. :type 'boolean)
  166. (defcustom org-agenda-export-html-style nil
  167. "The style specification for exported HTML Agenda files.
  168. If this variable contains a string, it will replace the default <style>
  169. section as produced by `htmlize'.
  170. Since there are different ways of setting style information, this variable
  171. needs to contain the full HTML structure to provide a style, including the
  172. surrounding HTML tags. The style specifications should include definitions
  173. the fonts used by the agenda, here is an example:
  174. <style type=\"text/css\">
  175. p { font-weight: normal; color: gray; }
  176. .org-agenda-structure {
  177. font-size: 110%;
  178. color: #003399;
  179. font-weight: 600;
  180. }
  181. .org-todo {
  182. color: #cc6666;
  183. font-weight: bold;
  184. }
  185. .org-agenda-done {
  186. color: #339933;
  187. }
  188. .org-done {
  189. color: #339933;
  190. }
  191. .title { text-align: center; }
  192. .todo, .deadline { color: red; }
  193. .done { color: green; }
  194. </style>
  195. or, if you want to keep the style in a file,
  196. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  197. As the value of this option simply gets inserted into the HTML <head> header,
  198. you can \"misuse\" it to also add other text to the header."
  199. :group 'org-agenda-export
  200. :group 'org-export-html
  201. :type '(choice
  202. (const nil)
  203. (string)))
  204. (defcustom org-agenda-persistent-filter nil
  205. "When set, keep filters from one agenda view to the next."
  206. :group 'org-agenda
  207. :type 'boolean)
  208. (defgroup org-agenda-custom-commands nil
  209. "Options concerning agenda views in Org mode."
  210. :tag "Org Agenda Custom Commands"
  211. :group 'org-agenda)
  212. (defconst org-sorting-choice
  213. '(choice
  214. (const time-up) (const time-down)
  215. (const timestamp-up) (const timestamp-down)
  216. (const scheduled-up) (const scheduled-down)
  217. (const deadline-up) (const deadline-down)
  218. (const ts-up) (const ts-down)
  219. (const tsia-up) (const tsia-down)
  220. (const category-keep) (const category-up) (const category-down)
  221. (const tag-down) (const tag-up)
  222. (const priority-up) (const priority-down)
  223. (const todo-state-up) (const todo-state-down)
  224. (const effort-up) (const effort-down)
  225. (const habit-up) (const habit-down)
  226. (const alpha-up) (const alpha-down)
  227. (const user-defined-up) (const user-defined-down))
  228. "Sorting choices.")
  229. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  230. ;; the new variable `org-agenda-tag-filter-preset'.
  231. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  232. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  233. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  234. "List of types searched for when creating the daily/weekly agenda.
  235. This variable is a list of symbols that controls the types of
  236. items that appear in the daily/weekly agenda. Allowed symbols in this
  237. list are are
  238. :timestamp List items containing a date stamp or date range matching
  239. the selected date. This includes sexp entries in angular
  240. brackets.
  241. :sexp List entries resulting from plain diary-like sexps.
  242. :deadline List deadline due on that date. When the date is today,
  243. also list any deadlines past due, or due within
  244. `org-deadline-warning-days'.
  245. :deadline* Same as above, but only include the deadline if it has an
  246. hour specification as [h]h:mm.
  247. :scheduled List all items which are scheduled for the given date.
  248. The diary for *today* also contains items which were
  249. scheduled earlier and are not yet marked DONE.
  250. :scheduled* Same as above, but only include the scheduled item if it
  251. has an hour specification as [h]h:mm.
  252. By default, all four non-starred types are turned on.
  253. When :scheduled* or :deadline* are included, :schedule or :deadline
  254. will be ignored.
  255. Never set this variable globally using `setq', because then it
  256. will apply to all future agenda commands. Instead, bind it with
  257. `let' to scope it dynamically into the agenda-constructing
  258. command. A good way to set it is through options in
  259. `org-agenda-custom-commands'. For a more flexible (though
  260. somewhat less efficient) way of determining what is included in
  261. the daily/weekly agenda, see `org-agenda-skip-function'.")
  262. (defconst org-agenda-custom-commands-local-options
  263. `(repeat :tag "Local settings for this command. Remember to quote values"
  264. (choice :tag "Setting"
  265. (list :tag "Heading for this block"
  266. (const org-agenda-overriding-header)
  267. (string :tag "Headline"))
  268. (list :tag "Files to be searched"
  269. (const org-agenda-files)
  270. (list
  271. (const :format "" quote)
  272. (repeat (file))))
  273. (list :tag "Sorting strategy"
  274. (const org-agenda-sorting-strategy)
  275. (list
  276. (const :format "" quote)
  277. (repeat
  278. ,org-sorting-choice)))
  279. (list :tag "Prefix format"
  280. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  281. (string))
  282. (list :tag "Number of days in agenda"
  283. (const org-agenda-span)
  284. (list
  285. (const :format "" quote)
  286. (choice (const :tag "Day" day)
  287. (const :tag "Week" week)
  288. (const :tag "Fortnight" fortnight)
  289. (const :tag "Month" month)
  290. (const :tag "Year" year)
  291. (integer :tag "Custom"))))
  292. (list :tag "Fixed starting date"
  293. (const org-agenda-start-day)
  294. (string :value "2007-11-01"))
  295. (list :tag "Start on day of week"
  296. (const org-agenda-start-on-weekday)
  297. (choice :value 1
  298. (const :tag "Today" nil)
  299. (integer :tag "Weekday No.")))
  300. (list :tag "Include data from diary"
  301. (const org-agenda-include-diary)
  302. (boolean))
  303. (list :tag "Deadline Warning days"
  304. (const org-deadline-warning-days)
  305. (integer :value 1))
  306. (list :tag "Category filter preset"
  307. (const org-agenda-category-filter-preset)
  308. (list
  309. (const :format "" quote)
  310. (repeat
  311. (string :tag "+category or -category"))))
  312. (list :tag "Tags filter preset"
  313. (const org-agenda-tag-filter-preset)
  314. (list
  315. (const :format "" quote)
  316. (repeat
  317. (string :tag "+tag or -tag"))))
  318. (list :tag "Effort filter preset"
  319. (const org-agenda-effort-filter-preset)
  320. (list
  321. (const :format "" quote)
  322. (repeat
  323. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  324. (list :tag "Regexp filter preset"
  325. (const org-agenda-regexp-filter-preset)
  326. (list
  327. (const :format "" quote)
  328. (repeat
  329. (string :tag "+regexp or -regexp"))))
  330. (list :tag "Set daily/weekly entry types"
  331. (const org-agenda-entry-types)
  332. (list
  333. (const :format "" quote)
  334. (set :greedy t :value ,org-agenda-entry-types
  335. (const :deadline)
  336. (const :scheduled)
  337. (const :deadline*)
  338. (const :scheduled*)
  339. (const :timestamp)
  340. (const :sexp))))
  341. (list :tag "Standard skipping condition"
  342. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  343. (const org-agenda-skip-function)
  344. (list
  345. (const :format "" quote)
  346. (list
  347. (choice
  348. :tag "Skipping range"
  349. (const :tag "Skip entry" org-agenda-skip-entry-if)
  350. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  351. (repeat :inline t :tag "Conditions for skipping"
  352. (choice
  353. :tag "Condition type"
  354. (list :tag "Regexp matches" :inline t
  355. (const :format "" regexp)
  356. (regexp))
  357. (list :tag "Regexp does not match" :inline t
  358. (const :format "" notregexp)
  359. (regexp))
  360. (list :tag "TODO state is" :inline t
  361. (const todo)
  362. (choice
  363. (const :tag "Any not-done state" todo)
  364. (const :tag "Any done state" done)
  365. (const :tag "Any state" any)
  366. (list :tag "Keyword list"
  367. (const :format "" quote)
  368. (repeat (string :tag "Keyword")))))
  369. (list :tag "TODO state is not" :inline t
  370. (const nottodo)
  371. (choice
  372. (const :tag "Any not-done state" todo)
  373. (const :tag "Any done state" done)
  374. (const :tag "Any state" any)
  375. (list :tag "Keyword list"
  376. (const :format "" quote)
  377. (repeat (string :tag "Keyword")))))
  378. (const :tag "scheduled" scheduled)
  379. (const :tag "not scheduled" notscheduled)
  380. (const :tag "deadline" deadline)
  381. (const :tag "no deadline" notdeadline)
  382. (const :tag "timestamp" timestamp)
  383. (const :tag "no timestamp" nottimestamp))))))
  384. (list :tag "Non-standard skipping condition"
  385. :value (org-agenda-skip-function)
  386. (const org-agenda-skip-function)
  387. (sexp :tag "Function or form (quoted!)"))
  388. (list :tag "Any variable"
  389. (variable :tag "Variable")
  390. (sexp :tag "Value (sexp)"))))
  391. "Selection of examples for agenda command settings.
  392. This will be spliced into the custom type of
  393. `org-agenda-custom-commands'.")
  394. (defcustom org-agenda-custom-commands
  395. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  396. "Custom commands for the agenda.
  397. \\<org-mode-map>
  398. These commands will be offered on the splash screen displayed by the
  399. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  400. (key desc type match settings files)
  401. key The key (one or more characters as a string) to be associated
  402. with the command.
  403. desc A description of the command, when omitted or nil, a default
  404. description is built using MATCH.
  405. type The command type, any of the following symbols:
  406. agenda The daily/weekly agenda.
  407. todo Entries with a specific TODO keyword, in all agenda files.
  408. search Entries containing search words entry or headline.
  409. tags Tags/Property/TODO match in all agenda files.
  410. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  411. todo-tree Sparse tree of specific TODO keyword in *current* file.
  412. tags-tree Sparse tree with all tags matches in *current* file.
  413. occur-tree Occur sparse tree for *current* file.
  414. ... A user-defined function.
  415. match What to search for:
  416. - a single keyword for TODO keyword searches
  417. - a tags match expression for tags searches
  418. - a word search expression for text searches.
  419. - a regular expression for occur searches
  420. For all other commands, this should be the empty string.
  421. settings A list of option settings, similar to that in a let form, so like
  422. this: ((opt1 val1) (opt2 val2) ...). The values will be
  423. evaluated at the moment of execution, so quote them when needed.
  424. files A list of files to write the produced agenda buffer to with
  425. the command `org-store-agenda-views'.
  426. If a file name ends in \".html\", an HTML version of the buffer
  427. is written out. If it ends in \".ps\", a postscript version is
  428. produced. Otherwise, only the plain text is written to the file.
  429. You can also define a set of commands, to create a composite agenda buffer.
  430. In this case, an entry looks like this:
  431. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  432. where
  433. desc A description string to be displayed in the dispatcher menu.
  434. cmd An agenda command, similar to the above. However, tree commands
  435. are not allowed, but instead you can get agenda and global todo list.
  436. So valid commands for a set are:
  437. (agenda \"\" settings)
  438. (alltodo \"\" settings)
  439. (stuck \"\" settings)
  440. (todo \"match\" settings files)
  441. (search \"match\" settings files)
  442. (tags \"match\" settings files)
  443. (tags-todo \"match\" settings files)
  444. Each command can carry a list of options, and another set of options can be
  445. given for the whole set of commands. Individual command options take
  446. precedence over the general options.
  447. When using several characters as key to a command, the first characters
  448. are prefix commands. For the dispatcher to display useful information, you
  449. should provide a description for the prefix, like
  450. (setq org-agenda-custom-commands
  451. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  452. (\"hl\" tags \"+HOME+Lisa\")
  453. (\"hp\" tags \"+HOME+Peter\")
  454. (\"hk\" tags \"+HOME+Kim\")))"
  455. :group 'org-agenda-custom-commands
  456. :type `(repeat
  457. (choice :value ("x" "Describe command here" tags "" nil)
  458. (list :tag "Single command"
  459. (string :tag "Access Key(s) ")
  460. (option (string :tag "Description"))
  461. (choice
  462. (const :tag "Agenda" agenda)
  463. (const :tag "TODO list" alltodo)
  464. (const :tag "Search words" search)
  465. (const :tag "Stuck projects" stuck)
  466. (const :tag "Tags/Property match (all agenda files)" tags)
  467. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  468. (const :tag "TODO keyword search (all agenda files)" todo)
  469. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  470. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  471. (const :tag "Occur tree (current buffer)" occur-tree)
  472. (sexp :tag "Other, user-defined function"))
  473. (string :tag "Match (only for some commands)")
  474. ,org-agenda-custom-commands-local-options
  475. (option (repeat :tag "Export" (file :tag "Export to"))))
  476. (list :tag "Command series, all agenda files"
  477. (string :tag "Access Key(s)")
  478. (string :tag "Description ")
  479. (repeat :tag "Component"
  480. (choice
  481. (list :tag "Agenda"
  482. (const :format "" agenda)
  483. (const :tag "" :format "" "")
  484. ,org-agenda-custom-commands-local-options)
  485. (list :tag "TODO list (all keywords)"
  486. (const :format "" alltodo)
  487. (const :tag "" :format "" "")
  488. ,org-agenda-custom-commands-local-options)
  489. (list :tag "Search words"
  490. (const :format "" search)
  491. (string :tag "Match")
  492. ,org-agenda-custom-commands-local-options)
  493. (list :tag "Stuck projects"
  494. (const :format "" stuck)
  495. (const :tag "" :format "" "")
  496. ,org-agenda-custom-commands-local-options)
  497. (list :tag "Tags search"
  498. (const :format "" tags)
  499. (string :tag "Match")
  500. ,org-agenda-custom-commands-local-options)
  501. (list :tag "Tags search, TODO entries only"
  502. (const :format "" tags-todo)
  503. (string :tag "Match")
  504. ,org-agenda-custom-commands-local-options)
  505. (list :tag "TODO keyword search"
  506. (const :format "" todo)
  507. (string :tag "Match")
  508. ,org-agenda-custom-commands-local-options)
  509. (list :tag "Other, user-defined function"
  510. (symbol :tag "function")
  511. (string :tag "Match")
  512. ,org-agenda-custom-commands-local-options)))
  513. (repeat :tag "Settings for entire command set"
  514. (list (variable :tag "Any variable")
  515. (sexp :tag "Value")))
  516. (option (repeat :tag "Export" (file :tag "Export to"))))
  517. (cons :tag "Prefix key documentation"
  518. (string :tag "Access Key(s)")
  519. (string :tag "Description ")))))
  520. (defcustom org-agenda-query-register ?o
  521. "The register holding the current query string.
  522. The purpose of this is that if you construct a query string interactively,
  523. you can then use it to define a custom command."
  524. :group 'org-agenda-custom-commands
  525. :type 'character)
  526. (defcustom org-stuck-projects
  527. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  528. "How to identify stuck projects.
  529. This is a list of four items:
  530. 1. A tags/todo/property matcher string that is used to identify a project.
  531. See the manual for a description of tag and property searches.
  532. The entire tree below a headline matched by this is considered one project.
  533. 2. A list of TODO keywords identifying non-stuck projects.
  534. If the project subtree contains any headline with one of these todo
  535. keywords, the project is considered to be not stuck. If you specify
  536. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  537. 3. A list of tags identifying non-stuck projects.
  538. If the project subtree contains any headline with one of these tags,
  539. the project is considered to be not stuck. If you specify \"*\" as
  540. a tag, any tag will mark the project unstuck. Note that this is about
  541. the explicit presence of a tag somewhere in the subtree, inherited
  542. tags do not count here. If inherited tags make a project not stuck,
  543. use \"-TAG\" in the tags part of the matcher under (1.) above.
  544. 4. An arbitrary regular expression matching non-stuck projects.
  545. If the project turns out to be not stuck, search continues also in the
  546. subtree to see if any of the subtasks have project status.
  547. See also the variable `org-tags-match-list-sublevels' which applies
  548. to projects matched by this search as well.
  549. After defining this variable, you may use `org-agenda-list-stuck-projects'
  550. \(bound to `\\[org-agenda] #') to produce the list."
  551. :group 'org-agenda-custom-commands
  552. :type '(list
  553. (string :tag "Tags/TODO match to identify a project")
  554. (repeat :tag "Projects are *not* stuck if they have an entry with \
  555. TODO keyword any of" (string))
  556. (repeat :tag "Projects are *not* stuck if they have an entry with \
  557. TAG being any of" (string))
  558. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  559. the subtree")))
  560. (defgroup org-agenda-skip nil
  561. "Options concerning skipping parts of agenda files."
  562. :tag "Org Agenda Skip"
  563. :group 'org-agenda)
  564. (defcustom org-agenda-skip-function-global nil
  565. "Function to be called at each match during agenda construction.
  566. If this function returns nil, the current match should not be skipped.
  567. If the function decided to skip an agenda match, is must return the
  568. buffer position from which the search should be continued.
  569. This may also be a Lisp form, which will be evaluated.
  570. This variable will be applied to every agenda match, including
  571. tags/property searches and TODO lists. So try to make the test function
  572. do its checking as efficiently as possible. To implement a skipping
  573. condition just for specific agenda commands, use the variable
  574. `org-agenda-skip-function' which can be set in the options section
  575. of custom agenda commands."
  576. :group 'org-agenda-skip
  577. :type 'sexp)
  578. (defgroup org-agenda-daily/weekly nil
  579. "Options concerning the daily/weekly agenda."
  580. :tag "Org Agenda Daily/Weekly"
  581. :group 'org-agenda)
  582. (defgroup org-agenda-todo-list nil
  583. "Options concerning the global todo list agenda view."
  584. :tag "Org Agenda Todo List"
  585. :group 'org-agenda)
  586. (defgroup org-agenda-match-view nil
  587. "Options concerning the general tags/property/todo match agenda view."
  588. :tag "Org Agenda Match View"
  589. :group 'org-agenda)
  590. (defgroup org-agenda-search-view nil
  591. "Options concerning the search agenda view."
  592. :tag "Org Agenda Search View"
  593. :group 'org-agenda)
  594. (defvar org-agenda-archives-mode nil
  595. "Non-nil means the agenda will include archived items.
  596. If this is the symbol `trees', trees in the selected agenda scope
  597. that are marked with the ARCHIVE tag will be included anyway. When this is
  598. t, also all archive files associated with the current selection of agenda
  599. files will be included.")
  600. (defcustom org-agenda-restriction-lock-highlight-subtree t
  601. "Non-nil means highlight the whole subtree when restriction is active.
  602. Otherwise only highlight the headline. Highlighting the whole subtree is
  603. useful to ensure no edits happen beyond the restricted region."
  604. :group 'org-agenda
  605. :type 'boolean)
  606. (defcustom org-agenda-skip-comment-trees t
  607. "Non-nil means skip trees that start with the COMMENT keyword.
  608. When nil, these trees are also scanned by agenda commands."
  609. :group 'org-agenda-skip
  610. :type 'boolean)
  611. (defcustom org-agenda-todo-list-sublevels t
  612. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  613. When nil, the sublevels of a TODO entry are not checked, resulting in
  614. potentially much shorter TODO lists."
  615. :group 'org-agenda-skip
  616. :group 'org-agenda-todo-list
  617. :type 'boolean)
  618. (defcustom org-agenda-todo-ignore-with-date nil
  619. "Non-nil means don't show entries with a date in the global todo list.
  620. You can use this if you prefer to mark mere appointments with a TODO keyword,
  621. but don't want them to show up in the TODO list.
  622. When this is set, it also covers deadlines and scheduled items, the settings
  623. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  624. will be ignored.
  625. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  626. :group 'org-agenda-skip
  627. :group 'org-agenda-todo-list
  628. :type 'boolean)
  629. (defcustom org-agenda-todo-ignore-timestamp nil
  630. "Non-nil means don't show entries with a timestamp.
  631. This applies when creating the global todo list.
  632. Valid values are:
  633. past Don't show entries for today or in the past.
  634. future Don't show entries with a timestamp in the future.
  635. The idea behind this is that if it has a future
  636. timestamp, you don't want to think about it until the
  637. date.
  638. all Don't show any entries with a timestamp in the global todo list.
  639. The idea behind this is that by setting a timestamp, you
  640. have already \"taken care\" of this item.
  641. This variable can also have an integer as a value. If positive (N),
  642. todos with a timestamp N or more days in the future will be ignored. If
  643. negative (-N), todos with a timestamp N or more days in the past will be
  644. ignored. If 0, todos with a timestamp either today or in the future will
  645. be ignored. For example, a value of -1 will exclude todos with a
  646. timestamp in the past (yesterday or earlier), while a value of 7 will
  647. exclude todos with a timestamp a week or more in the future.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :version "24.1"
  654. :type '(choice
  655. (const :tag "Ignore future timestamp todos" future)
  656. (const :tag "Ignore past or present timestamp todos" past)
  657. (const :tag "Ignore all timestamp todos" all)
  658. (const :tag "Show timestamp todos" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-scheduled nil
  661. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  662. This applies when creating the global todo list.
  663. Valid values are:
  664. past Don't show entries scheduled today or in the past.
  665. future Don't show entries scheduled in the future.
  666. The idea behind this is that by scheduling it, you don't want to
  667. think about it until the scheduled date.
  668. all Don't show any scheduled entries in the global todo list.
  669. The idea behind this is that by scheduling it, you have already
  670. \"taken care\" of this item.
  671. t Same as `all', for backward compatibility.
  672. This variable can also have an integer as a value. See
  673. `org-agenda-todo-ignore-timestamp' for more details.
  674. See also `org-agenda-todo-ignore-with-date'.
  675. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  676. to make his option also apply to the tags-todo list."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-todo-list
  679. :type '(choice
  680. (const :tag "Ignore future-scheduled todos" future)
  681. (const :tag "Ignore past- or present-scheduled todos" past)
  682. (const :tag "Ignore all scheduled todos" all)
  683. (const :tag "Ignore all scheduled todos (compatibility)" t)
  684. (const :tag "Show scheduled todos" nil)
  685. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  686. (defcustom org-agenda-todo-ignore-deadlines nil
  687. "Non-nil means ignore some deadline TODO items when making TODO list.
  688. There are different motivations for using different values, please think
  689. carefully when configuring this variable.
  690. This applies when creating the global TODO list.
  691. Valid values are:
  692. near Don't show near deadline entries. A deadline is near when it is
  693. closer than `org-deadline-warning-days' days. The idea behind this
  694. is that such items will appear in the agenda anyway.
  695. far Don't show TODO entries where a deadline has been defined, but
  696. is not going to happen anytime soon. This is useful if you want to use
  697. the TODO list to figure out what to do now.
  698. past Don't show entries with a deadline timestamp for today or in the past.
  699. future Don't show entries with a deadline timestamp in the future, not even
  700. when they become `near' ones. Use it with caution.
  701. all Ignore all TODO entries that do have a deadline.
  702. t Same as `near', for backward compatibility.
  703. This variable can also have an integer as a value. See
  704. `org-agenda-todo-ignore-timestamp' for more details.
  705. See also `org-agenda-todo-ignore-with-date'.
  706. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  707. to make his option also apply to the tags-todo list."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Ignore near deadlines" near)
  712. (const :tag "Ignore near deadlines (compatibility)" t)
  713. (const :tag "Ignore far deadlines" far)
  714. (const :tag "Ignore all TODOs with a deadlines" all)
  715. (const :tag "Show all TODOs, even if they have a deadline" nil)
  716. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  717. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  718. "Time unit to use when possibly ignoring an agenda item.
  719. See the docstring of various `org-agenda-todo-ignore-*' options.
  720. The default is to compare time stamps using days. An item is thus
  721. considered to be in the future if it is at least one day after today.
  722. Non-nil means to compare time stamps using seconds. An item is then
  723. considered future if it has a time value later than current time."
  724. :group 'org-agenda-skip
  725. :group 'org-agenda-todo-list
  726. :version "24.4"
  727. :package-version '(Org . "8.0")
  728. :type '(choice
  729. (const :tag "Compare time with days" nil)
  730. (const :tag "Compare time with seconds" t)))
  731. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  732. "Non-nil means honor todo-list ignores options also in tags-todo search.
  733. The variables
  734. `org-agenda-todo-ignore-with-date',
  735. `org-agenda-todo-ignore-timestamp',
  736. `org-agenda-todo-ignore-scheduled',
  737. `org-agenda-todo-ignore-deadlines'
  738. make the global TODO list skip entries that have time stamps of certain
  739. kinds. If this option is set, the same options will also apply for the
  740. tags-todo search, which is the general tags/property matcher
  741. restricted to unfinished TODO entries only."
  742. :group 'org-agenda-skip
  743. :group 'org-agenda-todo-list
  744. :group 'org-agenda-match-view
  745. :type 'boolean)
  746. (defcustom org-agenda-skip-scheduled-if-done nil
  747. "Non-nil means don't show scheduled items in agenda when they are done.
  748. This is relevant for the daily/weekly agenda, not for the TODO list. It
  749. applies only to the actual date of the scheduling. Warnings about an item
  750. with a past scheduling dates are always turned off when the item is DONE."
  751. :group 'org-agenda-skip
  752. :group 'org-agenda-daily/weekly
  753. :type 'boolean)
  754. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  755. "Non-nil means skip scheduling line if same entry shows because of deadline.
  756. In the agenda of today, an entry can show up multiple times
  757. because it is both scheduled and has a nearby deadline, and maybe
  758. a plain time stamp as well.
  759. When this variable is nil, the entry will be shown several times.
  760. When set to t, then only the deadline is shown and the fact that
  761. the entry is scheduled today or was scheduled previously is not
  762. shown.
  763. When set to the symbol `not-today', skip scheduled previously,
  764. but not scheduled today.
  765. When set to the symbol `repeated-after-deadline', skip scheduled
  766. items if they are repeated beyond the current deadline."
  767. :group 'org-agenda-skip
  768. :group 'org-agenda-daily/weekly
  769. :type '(choice
  770. (const :tag "Never" nil)
  771. (const :tag "Always" t)
  772. (const :tag "Not when scheduled today" not-today)
  773. (const :tag "When repeated past deadline" repeated-after-deadline)))
  774. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  775. "Non-nil means skip timestamp line if same entry shows because of deadline.
  776. In the agenda of today, an entry can show up multiple times
  777. because it has both a plain timestamp and has a nearby deadline.
  778. When this variable is t, then only the deadline is shown and the
  779. fact that the entry has a timestamp for or including today is not
  780. shown. When this variable is nil, the entry will be shown
  781. several times."
  782. :group 'org-agenda-skip
  783. :group 'org-agenda-daily/weekly
  784. :version "24.1"
  785. :type '(choice
  786. (const :tag "Never" nil)
  787. (const :tag "Always" t)))
  788. (defcustom org-agenda-skip-deadline-if-done nil
  789. "Non-nil means don't show deadlines when the corresponding item is done.
  790. When nil, the deadline is still shown and should give you a happy feeling.
  791. This is relevant for the daily/weekly agenda. It applies only to the
  792. actual date of the deadline. Warnings about approaching and past-due
  793. deadlines are always turned off when the item is DONE."
  794. :group 'org-agenda-skip
  795. :group 'org-agenda-daily/weekly
  796. :type 'boolean)
  797. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  798. "Non-nil means skip deadline prewarning when entry is also scheduled.
  799. This will apply on all days where a prewarning for the deadline would
  800. be shown, but not at the day when the entry is actually due. On that day,
  801. the deadline will be shown anyway.
  802. This variable may be set to nil, t, the symbol `pre-scheduled',
  803. or a number which will then give the number of days before the actual
  804. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  805. eliminates the deadline prewarning only prior to the scheduled date.
  806. This can be used in a workflow where the first showing of the deadline will
  807. trigger you to schedule it, and then you don't want to be reminded of it
  808. because you will take care of it on the day when scheduled."
  809. :group 'org-agenda-skip
  810. :group 'org-agenda-daily/weekly
  811. :version "24.1"
  812. :type '(choice
  813. (const :tag "Always show prewarning" nil)
  814. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  815. (const :tag "Remove prewarning if entry is scheduled" t)
  816. (integer :tag "Restart prewarning N days before deadline")))
  817. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  818. "Non-nil means skip scheduled delay when entry also has a deadline.
  819. This variable may be set to nil, t, the symbol `post-deadline',
  820. or a number which will then give the number of days after the actual
  821. scheduled date when the delay should expire. The symbol `post-deadline'
  822. eliminates the schedule delay when the date is posterior to the deadline."
  823. :group 'org-agenda-skip
  824. :group 'org-agenda-daily/weekly
  825. :version "24.4"
  826. :package-version '(Org . "8.0")
  827. :type '(choice
  828. (const :tag "Always honor delay" nil)
  829. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  830. (const :tag "Ignore delay if entry has a deadline" t)
  831. (integer :tag "Honor delay up until N days after the scheduled date")))
  832. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  833. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  834. When non-nil, after the search for timestamps has matched once in an
  835. entry, the rest of the entry will not be searched."
  836. :group 'org-agenda-skip
  837. :type 'boolean)
  838. (defcustom org-agenda-skip-timestamp-if-done nil
  839. "Non-nil means don't select item by timestamp or -range if it is DONE."
  840. :group 'org-agenda-skip
  841. :group 'org-agenda-daily/weekly
  842. :type 'boolean)
  843. (defcustom org-agenda-dim-blocked-tasks t
  844. "Non-nil means dim blocked tasks in the agenda display.
  845. This causes some overhead during agenda construction, but if you
  846. have turned on `org-enforce-todo-dependencies',
  847. `org-enforce-todo-checkbox-dependencies', or any other blocking
  848. mechanism, this will create useful feedback in the agenda.
  849. Instead of t, this variable can also have the value `invisible'.
  850. Then blocked tasks will be invisible and only become visible when
  851. they become unblocked. An exemption to this behavior is when a task is
  852. blocked because of unchecked checkboxes below it. Since checkboxes do
  853. not show up in the agenda views, making this task invisible you remove any
  854. trace from agenda views that there is something to do. Therefore, a task
  855. that is blocked because of checkboxes will never be made invisible, it
  856. will only be dimmed."
  857. :group 'org-agenda-daily/weekly
  858. :group 'org-agenda-todo-list
  859. :version "24.3"
  860. :type '(choice
  861. (const :tag "Do not dim" nil)
  862. (const :tag "Dim to a gray face" t)
  863. (const :tag "Make invisible" invisible)))
  864. (defgroup org-agenda-startup nil
  865. "Options concerning initial settings in the Agenda in Org Mode."
  866. :tag "Org Agenda Startup"
  867. :group 'org-agenda)
  868. (defcustom org-agenda-menu-show-matcher t
  869. "Non-nil means show the match string in the agenda dispatcher menu.
  870. When nil, the matcher string is not shown, but is put into the help-echo
  871. property so than moving the mouse over the command shows it.
  872. Setting it to nil is good if matcher strings are very long and/or if
  873. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  874. :group 'org-agenda
  875. :version "24.1"
  876. :type 'boolean)
  877. (defcustom org-agenda-menu-two-columns nil
  878. "Non-nil means, use two columns to show custom commands in the dispatcher.
  879. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  880. to nil."
  881. :group 'org-agenda
  882. :version "24.1"
  883. :type 'boolean)
  884. (defcustom org-agenda-finalize-hook nil
  885. "Hook run just before displaying an agenda buffer.
  886. The buffer is still writable when the hook is called.
  887. You can modify some of the buffer substrings but you should be
  888. extra careful not to modify the text properties of the agenda
  889. headlines as the agenda display heavily relies on them."
  890. :group 'org-agenda-startup
  891. :type 'hook)
  892. (defcustom org-agenda-mouse-1-follows-link nil
  893. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  894. A longer mouse click will still set point. Needs to be set
  895. before org.el is loaded."
  896. :group 'org-agenda-startup
  897. :type 'boolean)
  898. (defcustom org-agenda-start-with-follow-mode nil
  899. "The initial value of follow mode in a newly created agenda window."
  900. :group 'org-agenda-startup
  901. :type 'boolean)
  902. (defcustom org-agenda-follow-indirect nil
  903. "Non-nil means `org-agenda-follow-mode' displays only the
  904. current item's tree, in an indirect buffer."
  905. :group 'org-agenda
  906. :version "24.1"
  907. :type 'boolean)
  908. (defcustom org-agenda-show-outline-path t
  909. "Non-nil means show outline path in echo area after line motion."
  910. :group 'org-agenda-startup
  911. :type 'boolean)
  912. (defcustom org-agenda-start-with-entry-text-mode nil
  913. "The initial value of entry-text-mode in a newly created agenda window."
  914. :group 'org-agenda-startup
  915. :type 'boolean)
  916. (defcustom org-agenda-entry-text-maxlines 5
  917. "Number of text lines to be added when `E' is pressed in the agenda.
  918. Note that this variable only used during agenda display. To add entry text
  919. when exporting the agenda, configure the variable
  920. `org-agenda-add-entry-text-maxlines'."
  921. :group 'org-agenda
  922. :type 'integer)
  923. (defcustom org-agenda-entry-text-exclude-regexps nil
  924. "List of regular expressions to clean up entry text.
  925. The complete matches of all regular expressions in this list will be
  926. removed from entry text before it is shown in the agenda."
  927. :group 'org-agenda
  928. :type '(repeat (regexp)))
  929. (defcustom org-agenda-entry-text-leaders " > "
  930. "Text prepended to the entry text in agenda buffers."
  931. :version "24.4"
  932. :package-version '(Org . "8.0")
  933. :group 'org-agenda
  934. :type 'string)
  935. (defvar org-agenda-entry-text-cleanup-hook nil
  936. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  937. This cleanup is done in a temporary buffer, so the function may inspect and
  938. change the entire buffer.
  939. Some default stuff like drawers and scheduling/deadline dates will already
  940. have been removed when this is called, as will any matches for regular
  941. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  942. (defvar org-agenda-include-inactive-timestamps nil
  943. "Non-nil means include inactive time stamps in agenda.
  944. Dynamically scoped.")
  945. (defgroup org-agenda-windows nil
  946. "Options concerning the windows used by the Agenda in Org Mode."
  947. :tag "Org Agenda Windows"
  948. :group 'org-agenda)
  949. (defcustom org-agenda-window-setup 'reorganize-frame
  950. "How the agenda buffer should be displayed.
  951. Possible values for this option are:
  952. current-window Show agenda in the current window, keeping all other windows.
  953. other-window Use `switch-to-buffer-other-window' to display agenda.
  954. only-window Show agenda, deleting all other windows.
  955. reorganize-frame Show only two windows on the current frame, the current
  956. window and the agenda.
  957. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  958. Also, when exiting the agenda, kill that frame.
  959. See also the variable `org-agenda-restore-windows-after-quit'."
  960. :group 'org-agenda-windows
  961. :type '(choice
  962. (const current-window)
  963. (const other-frame)
  964. (const other-window)
  965. (const only-window)
  966. (const reorganize-frame)))
  967. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  968. "The min and max height of the agenda window as a fraction of frame height.
  969. The value of the variable is a cons cell with two numbers between 0 and 1.
  970. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  971. :group 'org-agenda-windows
  972. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  973. (defcustom org-agenda-restore-windows-after-quit nil
  974. "Non-nil means restore window configuration upon exiting agenda.
  975. Before the window configuration is changed for displaying the agenda,
  976. the current status is recorded. When the agenda is exited with
  977. `q' or `x' and this option is set, the old state is restored. If
  978. `org-agenda-window-setup' is `other-frame', the value of this
  979. option will be ignored."
  980. :group 'org-agenda-windows
  981. :type 'boolean)
  982. (defcustom org-agenda-span 'week
  983. "Number of days to include in overview display.
  984. Can be day, week, month, year, or any number of days.
  985. Custom commands can set this variable in the options section."
  986. :group 'org-agenda-daily/weekly
  987. :type '(choice (const :tag "Day" day)
  988. (const :tag "Week" week)
  989. (const :tag "Fortnight" fortnight)
  990. (const :tag "Month" month)
  991. (const :tag "Year" year)
  992. (integer :tag "Custom")))
  993. (defcustom org-agenda-start-on-weekday 1
  994. "Non-nil means start the overview always on the specified weekday.
  995. 0 denotes Sunday, 1 denotes Monday, etc.
  996. When nil, always start on the current day.
  997. Custom commands can set this variable in the options section."
  998. :group 'org-agenda-daily/weekly
  999. :type '(choice (const :tag "Today" nil)
  1000. (integer :tag "Weekday No.")))
  1001. (defcustom org-agenda-show-all-dates t
  1002. "Non-nil means `org-agenda' shows every day in the selected range.
  1003. When nil, only the days which actually have entries are shown."
  1004. :group 'org-agenda-daily/weekly
  1005. :type 'boolean)
  1006. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1007. "Format string for displaying dates in the agenda.
  1008. Used by the daily/weekly agenda. This should be a format string
  1009. understood by `format-time-string', or a function returning the
  1010. formatted date as a string. The function must take a single
  1011. argument, a calendar-style date list like (month day year)."
  1012. :group 'org-agenda-daily/weekly
  1013. :type '(choice
  1014. (string :tag "Format string")
  1015. (function :tag "Function")))
  1016. (defun org-agenda-format-date-aligned (date)
  1017. "Format a DATE string for display in the daily/weekly agenda.
  1018. This function makes sure that dates are aligned for easy reading."
  1019. (require 'cal-iso)
  1020. (let* ((dayname (calendar-day-name date))
  1021. (day (cadr date))
  1022. (day-of-week (calendar-day-of-week date))
  1023. (month (car date))
  1024. (monthname (calendar-month-name month))
  1025. (year (nth 2 date))
  1026. (iso-week (org-days-to-iso-week
  1027. (calendar-absolute-from-gregorian date)))
  1028. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1029. (1- year))
  1030. ((and (= month 12) (<= iso-week 1))
  1031. (1+ year))
  1032. (t year)))
  1033. (weekstring (if (= day-of-week 1)
  1034. (format " W%02d" iso-week)
  1035. "")))
  1036. (format "%-10s %2d %s %4d%s"
  1037. dayname day monthname year weekstring)))
  1038. (defcustom org-agenda-time-leading-zero nil
  1039. "Non-nil means use leading zero for military times in agenda.
  1040. For example, 9:30am would become 09:30 rather than 9:30."
  1041. :group 'org-agenda-daily/weekly
  1042. :version "24.1"
  1043. :type 'boolean)
  1044. (defcustom org-agenda-timegrid-use-ampm nil
  1045. "When set, show AM/PM style timestamps on the timegrid."
  1046. :group 'org-agenda
  1047. :version "24.1"
  1048. :type 'boolean)
  1049. (defun org-agenda-time-of-day-to-ampm (time)
  1050. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1051. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1052. (minute (substring time -2))
  1053. (ampm "am"))
  1054. (cond
  1055. ((equal hour-number 12)
  1056. (setq ampm "pm"))
  1057. ((> hour-number 12)
  1058. (setq ampm "pm")
  1059. (setq hour-number (- hour-number 12))))
  1060. (concat
  1061. (if org-agenda-time-leading-zero
  1062. (format "%02d" hour-number)
  1063. (format "%02s" (number-to-string hour-number)))
  1064. ":" minute ampm)))
  1065. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1066. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1067. (if org-agenda-timegrid-use-ampm
  1068. (org-agenda-time-of-day-to-ampm time)
  1069. time))
  1070. (defcustom org-agenda-weekend-days '(6 0)
  1071. "Which days are weekend?
  1072. These days get the special face `org-agenda-date-weekend' in the agenda."
  1073. :group 'org-agenda-daily/weekly
  1074. :type '(set :greedy t
  1075. (const :tag "Monday" 1)
  1076. (const :tag "Tuesday" 2)
  1077. (const :tag "Wednesday" 3)
  1078. (const :tag "Thursday" 4)
  1079. (const :tag "Friday" 5)
  1080. (const :tag "Saturday" 6)
  1081. (const :tag "Sunday" 0)))
  1082. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1083. "Non-nil means jump to today when moving a past date forward in time.
  1084. When using S-right in the agenda to move a a date forward, and the date
  1085. stamp currently points to the past, the first key press will move it
  1086. to today. When nil, just move one day forward even if the date stays
  1087. in the past."
  1088. :group 'org-agenda-daily/weekly
  1089. :version "24.1"
  1090. :type 'boolean)
  1091. (defcustom org-agenda-include-diary nil
  1092. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1093. Custom commands can set this variable in the options section."
  1094. :group 'org-agenda-daily/weekly
  1095. :type 'boolean)
  1096. (defcustom org-agenda-include-deadlines t
  1097. "If non-nil, include entries within their deadline warning period.
  1098. Custom commands can set this variable in the options section."
  1099. :group 'org-agenda-daily/weekly
  1100. :version "24.1"
  1101. :type 'boolean)
  1102. (defcustom org-agenda-show-future-repeats t
  1103. "Non-nil shows repeated entries in the future part of the agenda.
  1104. When set to the symbol `next' only the first future repeat is shown."
  1105. :group 'org-agenda-daily/weekly
  1106. :type '(choice
  1107. (const :tag "Show all repeated entries" t)
  1108. (const :tag "Show next repeated entry" next)
  1109. (const :tag "Do not show repeated entries" nil))
  1110. :version "26.1"
  1111. :package-version '(Org . "9.1")
  1112. :safe #'symbolp)
  1113. (defcustom org-agenda-prefer-last-repeat nil
  1114. "Non-nil sets date for repeated entries to their last repeat.
  1115. When nil, display SCHEDULED and DEADLINE dates at their base
  1116. date, and in today's agenda, as a reminder. Display plain
  1117. time-stamps, on the other hand, at every repeat date in the past
  1118. in addition to the base date.
  1119. When non-nil, show a repeated entry at its latest repeat date,
  1120. possibly being today even if it wasn't marked as done. This
  1121. setting is useful if you do not always mark repeated entries as
  1122. done and, yet, consider that reaching repeat date starts the task
  1123. anew.
  1124. When set to a list of strings, prefer last repeats only for
  1125. entries with these TODO keywords."
  1126. :group 'org-agenda-daily/weekly
  1127. :type '(choice
  1128. (const :tag "Prefer last repeat" t)
  1129. (const :tag "Prefer base date" nil)
  1130. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1131. (string :tag "TODO keyword")))
  1132. :version "26.1"
  1133. :package-version '(Org . "9.1")
  1134. :safe (lambda (x) (or (booleanp x) (consp x))))
  1135. (defcustom org-scheduled-past-days 10000
  1136. "Number of days to continue listing scheduled items not marked DONE.
  1137. When an item is scheduled on a date, it shows up in the agenda on
  1138. this day and will be listed until it is marked done or for the
  1139. number of days given here."
  1140. :group 'org-agenda-daily/weekly
  1141. :type 'integer
  1142. :safe 'integerp)
  1143. (defcustom org-deadline-past-days 10000
  1144. "Number of days to warn about missed deadlines.
  1145. When an item has deadline on a date, it shows up in the agenda on
  1146. this day and will appear as a reminder until it is marked DONE or
  1147. for the number of days given here."
  1148. :group 'org-agenda-daily/weekly
  1149. :type 'integer
  1150. :version "26.1"
  1151. :package-version '(Org . "9.1")
  1152. :safe 'integerp)
  1153. (defcustom org-agenda-log-mode-items '(closed clock)
  1154. "List of items that should be shown in agenda log mode.
  1155. \\<org-agenda-mode-map>\
  1156. This list may contain the following symbols:
  1157. closed Show entries that have been closed on that day.
  1158. clock Show entries that have received clocked time on that day.
  1159. state Show all logged state changes.
  1160. Note that instead of changing this variable, you can also press \
  1161. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1162. the agenda to display all available LOG items temporarily."
  1163. :group 'org-agenda-daily/weekly
  1164. :type '(set :greedy t (const closed) (const clock) (const state)))
  1165. (defcustom org-agenda-clock-consistency-checks
  1166. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1167. :gap-ok-around ("4:00")
  1168. :default-face ((:background "DarkRed") (:foreground "white"))
  1169. :overlap-face nil :gap-face nil :no-end-time-face nil
  1170. :long-face nil :short-face nil)
  1171. "This is a property list, with the following keys:
  1172. :max-duration Mark clocking chunks that are longer than this time.
  1173. This is a time string like \"HH:MM\", or the number
  1174. of minutes as an integer.
  1175. :min-duration Mark clocking chunks that are shorter that this.
  1176. This is a time string like \"HH:MM\", or the number
  1177. of minutes as an integer.
  1178. :max-gap Mark gaps between clocking chunks that are longer than
  1179. this duration. A number of minutes, or a string
  1180. like \"HH:MM\".
  1181. :gap-ok-around List of times during the day which are usually not working
  1182. times. When a gap is detected, but the gap contains any
  1183. of these times, the gap is *not* reported. For example,
  1184. if this is (\"4:00\" \"13:00\") then gaps that contain
  1185. 4:00 in the morning (i.e. the night) and 13:00
  1186. (i.e. a typical lunch time) do not cause a warning.
  1187. You should have at least one time during the night in this
  1188. list, or otherwise the first task each morning will trigger
  1189. a warning because it follows a long gap.
  1190. Furthermore, the following properties can be used to define faces for
  1191. issue display.
  1192. :default-face the default face, if the specific face is undefined
  1193. :overlap-face face for overlapping clocks
  1194. :gap-face face for gaps between clocks
  1195. :no-end-time-face face for incomplete clocks
  1196. :long-face face for clock intervals that are too long
  1197. :short-face face for clock intervals that are too short"
  1198. :group 'org-agenda-daily/weekly
  1199. :group 'org-clock
  1200. :version "24.1"
  1201. :type 'plist)
  1202. (defcustom org-agenda-log-mode-add-notes t
  1203. "Non-nil means add first line of notes to log entries in agenda views.
  1204. If a log item like a state change or a clock entry is associated with
  1205. notes, the first line of these notes will be added to the entry in the
  1206. agenda display."
  1207. :group 'org-agenda-daily/weekly
  1208. :type 'boolean)
  1209. (defcustom org-agenda-start-with-log-mode nil
  1210. "The initial value of log-mode in a newly created agenda window.
  1211. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1212. explanations on the possible values."
  1213. :group 'org-agenda-startup
  1214. :group 'org-agenda-daily/weekly
  1215. :type '(choice (const :tag "Don't show log items" nil)
  1216. (const :tag "Show only log items" only)
  1217. (const :tag "Show all possible log items" clockcheck)
  1218. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1219. (choice (const :tag "Show closed log items" closed)
  1220. (const :tag "Show clocked log items" clock)
  1221. (const :tag "Show all logged state changes" state)))))
  1222. (defcustom org-agenda-start-with-clockreport-mode nil
  1223. "The initial value of clockreport-mode in a newly created agenda window."
  1224. :group 'org-agenda-startup
  1225. :group 'org-agenda-daily/weekly
  1226. :type 'boolean)
  1227. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1228. "Property list with parameters for the clocktable in clockreport mode.
  1229. This is the display mode that shows a clock table in the daily/weekly
  1230. agenda, the properties for this dynamic block can be set here.
  1231. The usual clocktable parameters are allowed here, but you cannot set
  1232. the properties :name, :tstart, :tend, :block, and :scope - these will
  1233. be overwritten to make sure the content accurately reflects the
  1234. current display in the agenda."
  1235. :group 'org-agenda-daily/weekly
  1236. :type 'plist)
  1237. (defvaralias 'org-agenda-search-view-search-words-only
  1238. 'org-agenda-search-view-always-boolean)
  1239. (defcustom org-agenda-search-view-always-boolean nil
  1240. "Non-nil means the search string is interpreted as individual parts.
  1241. The search string for search view can either be interpreted as a phrase,
  1242. or as a list of snippets that define a boolean search for a number of
  1243. strings.
  1244. When this is non-nil, the string will be split on whitespace, and each
  1245. snippet will be searched individually, and all must match in order to
  1246. select an entry. A snippet is then a single string of non-white
  1247. characters, or a string in double quotes, or a regexp in {} braces.
  1248. If a snippet is preceded by \"-\", the snippet must *not* match.
  1249. \"+\" is syntactic sugar for positive selection. Each snippet may
  1250. be found as a full word or a partial word, but see the variable
  1251. `org-agenda-search-view-force-full-words'.
  1252. When this is nil, search will look for the entire search phrase as one,
  1253. with each space character matching any amount of whitespace, including
  1254. line breaks.
  1255. Even when this is nil, you can still switch to Boolean search dynamically
  1256. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1257. is a regexp marked with braces like \"{abc}\", this will also switch to
  1258. boolean search."
  1259. :group 'org-agenda-search-view
  1260. :version "24.1"
  1261. :type 'boolean)
  1262. (defcustom org-agenda-search-view-force-full-words nil
  1263. "Non-nil means, search words must be matches as complete words.
  1264. When nil, they may also match part of a word."
  1265. :group 'org-agenda-search-view
  1266. :version "24.1"
  1267. :type 'boolean)
  1268. (defcustom org-agenda-search-view-max-outline-level 0
  1269. "Maximum outline level to display in search view.
  1270. E.g. when this is set to 1, the search view will only
  1271. show headlines of level 1. When set to 0, the default
  1272. value, don't limit agenda view by outline level."
  1273. :group 'org-agenda-search-view
  1274. :version "26.1"
  1275. :package-version '(Org . "8.3")
  1276. :type 'integer)
  1277. (defgroup org-agenda-time-grid nil
  1278. "Options concerning the time grid in the Org Agenda."
  1279. :tag "Org Agenda Time Grid"
  1280. :group 'org-agenda)
  1281. (defcustom org-agenda-search-headline-for-time t
  1282. "Non-nil means search headline for a time-of-day.
  1283. If the headline contains a time-of-day in one format or another, it will
  1284. be used to sort the entry into the time sequence of items for a day.
  1285. Some people have time stamps in the headline that refer to the creation
  1286. time or so, and then this produces an unwanted side effect. If this is
  1287. the case for your, use this variable to turn off searching the headline
  1288. for a time."
  1289. :group 'org-agenda-time-grid
  1290. :type 'boolean)
  1291. (defcustom org-agenda-use-time-grid t
  1292. "Non-nil means show a time grid in the agenda schedule.
  1293. A time grid is a set of lines for specific times (like every two hours between
  1294. 8:00 and 20:00). The items scheduled for a day at specific times are
  1295. sorted in between these lines.
  1296. For details about when the grid will be shown, and what it will look like, see
  1297. the variable `org-agenda-time-grid'."
  1298. :group 'org-agenda-time-grid
  1299. :type 'boolean)
  1300. (defcustom org-agenda-time-grid
  1301. '((daily today require-timed)
  1302. (800 1000 1200 1400 1600 1800 2000)
  1303. "......"
  1304. "----------------")
  1305. "The settings for time grid for agenda display.
  1306. This is a list of four items. The first item is again a list. It contains
  1307. symbols specifying conditions when the grid should be displayed:
  1308. daily if the agenda shows a single day
  1309. weekly if the agenda shows an entire week
  1310. today show grid on current date, independent of daily/weekly display
  1311. require-timed show grid only if at least one item has a time specification
  1312. remove-match skip grid times already present in an entry
  1313. The second item is a list of integers, indicating the times that
  1314. should have a grid line.
  1315. The third item is a string which will be placed right after the
  1316. times that have a grid line.
  1317. The fourth item is a string placed after the grid times. This
  1318. will align with agenda items"
  1319. :group 'org-agenda-time-grid
  1320. :type
  1321. '(list
  1322. (set :greedy t :tag "Grid Display Options"
  1323. (const :tag "Show grid in single day agenda display" daily)
  1324. (const :tag "Show grid in weekly agenda display" weekly)
  1325. (const :tag "Always show grid for today" today)
  1326. (const :tag "Show grid only if any timed entries are present"
  1327. require-timed)
  1328. (const :tag "Skip grid times already present in an entry"
  1329. remove-match))
  1330. (repeat :tag "Grid Times" (integer :tag "Time"))
  1331. (string :tag "Grid String (after agenda times)")
  1332. (string :tag "Grid String (aligns with agenda items)")))
  1333. (defcustom org-agenda-show-current-time-in-grid t
  1334. "Non-nil means show the current time in the time grid."
  1335. :group 'org-agenda-time-grid
  1336. :version "24.1"
  1337. :type 'boolean)
  1338. (defcustom org-agenda-current-time-string
  1339. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1340. "The string for the current time marker in the agenda."
  1341. :group 'org-agenda-time-grid
  1342. :version "24.1"
  1343. :type 'string)
  1344. (defgroup org-agenda-sorting nil
  1345. "Options concerning sorting in the Org Agenda."
  1346. :tag "Org Agenda Sorting"
  1347. :group 'org-agenda)
  1348. (defcustom org-agenda-sorting-strategy
  1349. '((agenda habit-down time-up priority-down category-keep)
  1350. (todo priority-down category-keep)
  1351. (tags priority-down category-keep)
  1352. (search category-keep))
  1353. "Sorting structure for the agenda items of a single day.
  1354. This is a list of symbols which will be used in sequence to determine
  1355. if an entry should be listed before another entry. The following
  1356. symbols are recognized:
  1357. time-up Put entries with time-of-day indications first, early first
  1358. time-down Put entries with time-of-day indications first, late first
  1359. timestamp-up Sort by any timestamp, early first
  1360. timestamp-down Sort by any timestamp, late first
  1361. scheduled-up Sort by scheduled timestamp, early first
  1362. scheduled-down Sort by scheduled timestamp, late first
  1363. deadline-up Sort by deadline timestamp, early first
  1364. deadline-down Sort by deadline timestamp, late first
  1365. ts-up Sort by active timestamp, early first
  1366. ts-down Sort by active timestamp, late first
  1367. tsia-up Sort by inactive timestamp, early first
  1368. tsia-down Sort by inactive timestamp, late first
  1369. category-keep Keep the default order of categories, corresponding to the
  1370. sequence in `org-agenda-files'.
  1371. category-up Sort alphabetically by category, A-Z.
  1372. category-down Sort alphabetically by category, Z-A.
  1373. tag-up Sort alphabetically by last tag, A-Z.
  1374. tag-down Sort alphabetically by last tag, Z-A.
  1375. priority-up Sort numerically by priority, high priority last.
  1376. priority-down Sort numerically by priority, high priority first.
  1377. todo-state-up Sort by todo state, tasks that are done last.
  1378. todo-state-down Sort by todo state, tasks that are done first.
  1379. effort-up Sort numerically by estimated effort, high effort last.
  1380. effort-down Sort numerically by estimated effort, high effort first.
  1381. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1382. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1383. habit-up Put entries that are habits first
  1384. habit-down Put entries that are habits last
  1385. alpha-up Sort headlines alphabetically
  1386. alpha-down Sort headlines alphabetically, reversed
  1387. The different possibilities will be tried in sequence, and testing stops
  1388. if one comparison returns a \"not-equal\". For example, the default
  1389. '(time-up category-keep priority-down)
  1390. means: Pull out all entries having a specified time of day and sort them,
  1391. in order to make a time schedule for the current day the first thing in the
  1392. agenda listing for the day. Of the entries without a time indication, keep
  1393. the grouped in categories, don't sort the categories, but keep them in
  1394. the sequence given in `org-agenda-files'. Within each category sort by
  1395. priority.
  1396. Leaving out `category-keep' would mean that items will be sorted across
  1397. categories by priority.
  1398. Instead of a single list, this can also be a set of list for specific
  1399. contents, with a context symbol in the car of the list, any of
  1400. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1401. Custom commands can bind this variable in the options section."
  1402. :group 'org-agenda-sorting
  1403. :type `(choice
  1404. (repeat :tag "General" ,org-sorting-choice)
  1405. (list :tag "Individually"
  1406. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1407. (repeat ,org-sorting-choice))
  1408. (cons (const :tag "Strategy for TODO lists" todo)
  1409. (repeat ,org-sorting-choice))
  1410. (cons (const :tag "Strategy for Tags matches" tags)
  1411. (repeat ,org-sorting-choice))
  1412. (cons (const :tag "Strategy for search matches" search)
  1413. (repeat ,org-sorting-choice)))))
  1414. (defcustom org-agenda-cmp-user-defined nil
  1415. "A function to define the comparison `user-defined'.
  1416. This function must receive two arguments, agenda entry a and b.
  1417. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1418. the user comparison, return nil.
  1419. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1420. part of an agenda sorting strategy."
  1421. :group 'org-agenda-sorting
  1422. :type 'symbol)
  1423. (defcustom org-sort-agenda-notime-is-late t
  1424. "Non-nil means items without time are considered late.
  1425. This is only relevant for sorting. When t, items which have no explicit
  1426. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1427. do have a time. When nil, the default time is before 0:00. You can use this
  1428. option to decide if the schedule for today should come before or after timeless
  1429. agenda entries."
  1430. :group 'org-agenda-sorting
  1431. :type 'boolean)
  1432. (defcustom org-sort-agenda-noeffort-is-high t
  1433. "Non-nil means items without effort estimate are sorted as high effort.
  1434. This also applies when filtering an agenda view with respect to the
  1435. < or > effort operator. Then, tasks with no effort defined will be treated
  1436. as tasks with high effort.
  1437. When nil, such items are sorted as 0 minutes effort."
  1438. :group 'org-agenda-sorting
  1439. :type 'boolean)
  1440. (defgroup org-agenda-line-format nil
  1441. "Options concerning the entry prefix in the Org agenda display."
  1442. :tag "Org Agenda Line Format"
  1443. :group 'org-agenda)
  1444. (defcustom org-agenda-prefix-format
  1445. '((agenda . " %i %-12:c%?-12t% s")
  1446. (todo . " %i %-12:c")
  1447. (tags . " %i %-12:c")
  1448. (search . " %i %-12:c"))
  1449. "Format specifications for the prefix of items in the agenda views.
  1450. An alist with one entry per agenda type. The keys of the
  1451. sublists are `agenda', `todo', `search' and `tags'. The values
  1452. are format strings.
  1453. This format works similar to a printf format, with the following meaning:
  1454. %c the category of the item, \"Diary\" for entries from the diary,
  1455. or as given by the CATEGORY keyword or derived from the file name
  1456. %e the effort required by the item
  1457. %l the level of the item (insert X space(s) if item is of level X)
  1458. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1459. %T the last tag of the item (ignore inherited tags, which come first)
  1460. %t the HH:MM time-of-day specification if one applies to the entry
  1461. %s Scheduling/Deadline information, a short string
  1462. %b show breadcrumbs, i.e., the names of the higher levels
  1463. %(expression) Eval EXPRESSION and replace the control string
  1464. by the result
  1465. All specifiers work basically like the standard `%s' of printf, but may
  1466. contain two additional characters: a question mark just after the `%'
  1467. and a whitespace/punctuation character just before the final letter.
  1468. If the first character after `%' is a question mark, the entire field
  1469. will only be included if the corresponding value applies to the current
  1470. entry. This is useful for fields which should have fixed width when
  1471. present, but zero width when absent. For example, \"%?-12t\" will
  1472. result in a 12 character time field if a time of the day is specified,
  1473. but will completely disappear in entries which do not contain a time.
  1474. If there is punctuation or whitespace character just before the
  1475. final format letter, this character will be appended to the field
  1476. value if the value is not empty. For example, the format
  1477. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1478. the category is empty, no additional colon is inserted.
  1479. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1480. which means:
  1481. - Indent the line with two space characters
  1482. - Give the category a 12 chars wide field, padded with whitespace on
  1483. the right (because of `-'). Append a colon if there is a category
  1484. (because of `:').
  1485. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1486. time, don't put in an empty field, just skip it (because of '?').
  1487. - Finally, put the scheduling information.
  1488. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1489. `org-agenda-remove-tags'.
  1490. Custom commands can set this variable in the options section."
  1491. :type '(choice
  1492. (string :tag "General format")
  1493. (list :greedy t :tag "View dependent"
  1494. (cons (const agenda) (string :tag "Format"))
  1495. (cons (const todo) (string :tag "Format"))
  1496. (cons (const tags) (string :tag "Format"))
  1497. (cons (const search) (string :tag "Format"))))
  1498. :group 'org-agenda-line-format
  1499. :version "26.1"
  1500. :package-version '(Org . "9.1"))
  1501. (defvar org-prefix-format-compiled nil
  1502. "The compiled prefix format and associated variables.
  1503. This is a list where first element is a list of variable bindings, and second
  1504. element is the compiled format expression. See the variable
  1505. `org-agenda-prefix-format'.")
  1506. (defcustom org-agenda-todo-keyword-format "%-1s"
  1507. "Format for the TODO keyword in agenda lines.
  1508. Set this to something like \"%-12s\" if you want all TODO keywords
  1509. to occupy a fixed space in the agenda display."
  1510. :group 'org-agenda-line-format
  1511. :type 'string)
  1512. (defcustom org-agenda-diary-sexp-prefix nil
  1513. "A regexp that matches part of a diary sexp entry
  1514. which should be treated as scheduling/deadline information in
  1515. `org-agenda'.
  1516. For example, you can use this to extract the `diary-remind-message' from
  1517. `diary-remind' entries."
  1518. :group 'org-agenda-line-format
  1519. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1520. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1521. "Text preceding timerange entries in the agenda view.
  1522. This is a list with two strings. The first applies when the range
  1523. is entirely on one day. The second applies if the range spans several days.
  1524. The strings may have two \"%d\" format specifiers which will be filled
  1525. with the sequence number of the days, and the total number of days in the
  1526. range, respectively."
  1527. :group 'org-agenda-line-format
  1528. :type '(list
  1529. (string :tag "Deadline today ")
  1530. (choice :tag "Deadline relative"
  1531. (string :tag "Format string")
  1532. (function))))
  1533. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1534. "Text preceding scheduled items in the agenda view.
  1535. This is a list with two strings. The first applies when the item is
  1536. scheduled on the current day. The second applies when it has been scheduled
  1537. previously, it may contain a %d indicating that this is the nth time that
  1538. this item is scheduled, due to automatic rescheduling of unfinished items
  1539. for the following day. So this number is one larger than the number of days
  1540. that passed since this item was scheduled first."
  1541. :group 'org-agenda-line-format
  1542. :version "24.4"
  1543. :package-version '(Org . "8.0")
  1544. :type '(list
  1545. (string :tag "Scheduled today ")
  1546. (string :tag "Scheduled previously")))
  1547. (defcustom org-agenda-inactive-leader "["
  1548. "Text preceding item pulled into the agenda by inactive time stamps.
  1549. These entries are added to the agenda when pressing \"[\"."
  1550. :group 'org-agenda-line-format
  1551. :version "24.1"
  1552. :type 'string)
  1553. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1554. "Text preceding deadline items in the agenda view.
  1555. This is a list with three strings. The first applies when the item has its
  1556. deadline on the current day. The second applies when the deadline is in the
  1557. future, the third one when it is in the past. The strings may contain %d
  1558. to capture the number of days."
  1559. :group 'org-agenda-line-format
  1560. :version "24.4"
  1561. :package-version '(Org . "8.0")
  1562. :type '(list
  1563. (string :tag "Deadline today ")
  1564. (string :tag "Deadline in the future ")
  1565. (string :tag "Deadline in the past ")))
  1566. (defcustom org-agenda-remove-times-when-in-prefix t
  1567. "Non-nil means remove duplicate time specifications in agenda items.
  1568. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1569. time-of-day specification in a headline or diary entry is extracted and
  1570. placed into the prefix. If this option is non-nil, the original specification
  1571. \(a timestamp or -range, or just a plain time(range) specification like
  1572. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1573. cluttered.
  1574. The option can be t or nil. It may also be the symbol `beg', indicating
  1575. that the time should only be removed when it is located at the beginning of
  1576. the headline/diary entry."
  1577. :group 'org-agenda-line-format
  1578. :type '(choice
  1579. (const :tag "Always" t)
  1580. (const :tag "Never" nil)
  1581. (const :tag "When at beginning of entry" beg)))
  1582. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1583. "Non-nil means remove time ranges specifications in agenda
  1584. items that span on several days."
  1585. :group 'org-agenda-line-format
  1586. :version "24.1"
  1587. :type 'boolean)
  1588. (defcustom org-agenda-default-appointment-duration nil
  1589. "Default duration for appointments that only have a starting time.
  1590. When nil, no duration is specified in such cases.
  1591. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1592. :group 'org-agenda-line-format
  1593. :type '(choice
  1594. (integer :tag "Minutes")
  1595. (const :tag "No default duration")))
  1596. (defcustom org-agenda-show-inherited-tags t
  1597. "Non-nil means show inherited tags in each agenda line.
  1598. When this option is set to `always', it takes precedence over
  1599. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1600. in every agenda.
  1601. When this option is set to t (the default), inherited tags are
  1602. shown when they are available, i.e. when the value of
  1603. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1604. given agenda type.
  1605. This can be set to a list of agenda types in which the agenda
  1606. must display the inherited tags. Available types are `todo',
  1607. `agenda' and `search'.
  1608. When set to nil, never show inherited tags in agenda lines."
  1609. :group 'org-agenda-line-format
  1610. :group 'org-agenda
  1611. :version "24.3"
  1612. :type '(choice
  1613. (const :tag "Show inherited tags when available" t)
  1614. (const :tag "Always show inherited tags" always)
  1615. (repeat :tag "Show inherited tags only in selected agenda types"
  1616. (symbol :tag "Agenda type"))))
  1617. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1618. "List of agenda view types where to use tag inheritance.
  1619. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1620. controlled by `org-use-tag-inheritance'. In other agenda types,
  1621. `org-use-tag-inheritance' is not used for the selection of the
  1622. agenda entries. Still, you may want the agenda to be aware of
  1623. the inherited tags anyway, e.g. for later tag filtering.
  1624. Allowed value are `todo', `search' and `agenda'.
  1625. This variable has no effect if `org-agenda-show-inherited-tags'
  1626. is set to `always'. In that case, the agenda is aware of those
  1627. tags.
  1628. The default value sets tags in every agenda type. Setting this
  1629. option to nil will speed up non-tags agenda view a lot."
  1630. :group 'org-agenda
  1631. :version "26.1"
  1632. :package-version '(Org . "9.1")
  1633. :type '(choice
  1634. (const :tag "Use tag inheritance in all agenda types" t)
  1635. (repeat :tag "Use tag inheritance in selected agenda types"
  1636. (symbol :tag "Agenda type"))))
  1637. (defcustom org-agenda-hide-tags-regexp nil
  1638. "Regular expression used to filter away specific tags in agenda views.
  1639. This means that these tags will be present, but not be shown in the agenda
  1640. line. Secondary filtering will still work on the hidden tags.
  1641. Nil means don't hide any tags."
  1642. :group 'org-agenda-line-format
  1643. :type '(choice
  1644. (const :tag "Hide none" nil)
  1645. (string :tag "Regexp ")))
  1646. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1647. 'org-agenda-remove-tags)
  1648. (defcustom org-agenda-remove-tags nil
  1649. "Non-nil means remove the tags from the headline copy in the agenda.
  1650. When this is the symbol `prefix', only remove tags when
  1651. `org-agenda-prefix-format' contains a `%T' specifier."
  1652. :group 'org-agenda-line-format
  1653. :type '(choice
  1654. (const :tag "Always" t)
  1655. (const :tag "Never" nil)
  1656. (const :tag "When prefix format contains %T" prefix)))
  1657. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1658. (defcustom org-agenda-tags-column 'auto
  1659. "Shift tags in agenda items to this column.
  1660. If set to `auto', tags will be automatically aligned to the right
  1661. edge of the window.
  1662. If set to a positive number, tags will be left-aligned to that
  1663. column. If set to a negative number, tags will be right-aligned
  1664. to that column. For example, -80 works well for a normal 80
  1665. character screen."
  1666. :group 'org-agenda-line-format
  1667. :type '(choice
  1668. (const :tag "Automatically align to right edge of window" auto)
  1669. (integer :tag "Specific column" -80))
  1670. :package-version '(Org . "9.1")
  1671. :version "26.1")
  1672. (defcustom org-agenda-fontify-priorities 'cookies
  1673. "Non-nil means highlight low and high priorities in agenda.
  1674. When t, the highest priority entries are bold, lowest priority italic.
  1675. However, settings in `org-priority-faces' will overrule these faces.
  1676. When this variable is the symbol `cookies', only fontify the
  1677. cookies, not the entire task.
  1678. This may also be an association list of priority faces, whose
  1679. keys are the character values of `org-highest-priority',
  1680. `org-default-priority', and `org-lowest-priority' (the default values
  1681. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1682. color as a string, or a list like `(:background \"Red\")'.
  1683. If it is a color, the variable `org-faces-easy-properties'
  1684. determines if it is a foreground or a background color."
  1685. :group 'org-agenda-line-format
  1686. :type '(choice
  1687. (const :tag "Never" nil)
  1688. (const :tag "Defaults" t)
  1689. (const :tag "Cookies only" cookies)
  1690. (repeat :tag "Specify"
  1691. (list (character :tag "Priority" :value ?A)
  1692. (choice :tag "Face "
  1693. (string :tag "Color")
  1694. (sexp :tag "Face"))))))
  1695. (defcustom org-agenda-day-face-function nil
  1696. "Function called to determine what face should be used to display a day.
  1697. The only argument passed to that function is the day. It should
  1698. returns a face, or nil if does not want to specify a face and let
  1699. the normal rules apply."
  1700. :group 'org-agenda-line-format
  1701. :version "24.1"
  1702. :type '(choice (const nil) (function)))
  1703. (defcustom org-agenda-category-icon-alist nil
  1704. "Alist of category icon to be displayed in agenda views.
  1705. Each entry should have the following format:
  1706. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1707. Where CATEGORY-REGEXP is a regexp matching the categories where
  1708. the icon should be displayed.
  1709. FILE-OR-DATA either a file path or a string containing image data.
  1710. The other fields can be omitted safely if not needed:
  1711. TYPE indicates the image type.
  1712. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1713. image data.
  1714. PROPS are additional image attributes to assign to the image,
  1715. like, e.g. `:ascent center'.
  1716. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1717. If you want to set the display properties yourself, just put a
  1718. list as second element:
  1719. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1720. For example, to display a 16px horizontal space for Emacs
  1721. category, you can use:
  1722. (\"Emacs\" \\='(space . (:width (16))))"
  1723. :group 'org-agenda-line-format
  1724. :version "24.1"
  1725. :type '(alist :key-type (string :tag "Regexp matching category")
  1726. :value-type (choice (list :tag "Icon"
  1727. (string :tag "File or data")
  1728. (symbol :tag "Type")
  1729. (boolean :tag "Data?")
  1730. (repeat :tag "Extra image properties" :inline t symbol))
  1731. (list :tag "Display properties" sexp))))
  1732. (defgroup org-agenda-column-view nil
  1733. "Options concerning column view in the agenda."
  1734. :tag "Org Agenda Column View"
  1735. :group 'org-agenda)
  1736. (defcustom org-agenda-view-columns-initially nil
  1737. "When non-nil, switch to columns view right after creating the agenda."
  1738. :group 'org-agenda-column-view
  1739. :type 'boolean
  1740. :version "26.1"
  1741. :package-version '(Org . "9.0")
  1742. :safe #'booleanp)
  1743. (defcustom org-agenda-columns-show-summaries t
  1744. "Non-nil means show summaries for columns displayed in the agenda view."
  1745. :group 'org-agenda-column-view
  1746. :type 'boolean)
  1747. (defcustom org-agenda-columns-compute-summary-properties t
  1748. "Non-nil means recompute all summary properties before column view.
  1749. When column view in the agenda is listing properties that have a summary
  1750. operator, it can go to all relevant buffers and recompute the summaries
  1751. there. This can mean overhead for the agenda column view, but is necessary
  1752. to have thing up to date.
  1753. As a special case, a CLOCKSUM property also makes sure that the clock
  1754. computations are current."
  1755. :group 'org-agenda-column-view
  1756. :type 'boolean)
  1757. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1758. "Non-nil means the duration of an appointment will add to day effort.
  1759. The property to which appointment durations will be added is the one given
  1760. in the option `org-effort-property'. If an appointment does not have
  1761. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1762. is not set, an appointment without end time will not contribute to the time
  1763. estimate."
  1764. :group 'org-agenda-column-view
  1765. :type 'boolean)
  1766. (defcustom org-agenda-auto-exclude-function nil
  1767. "A function called with a tag to decide if it is filtered on \
  1768. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1769. The sole argument to the function, which is called once for each
  1770. possible tag, is a string giving the name of the tag. The
  1771. function should return either nil if the tag should be included
  1772. as normal, or \"-<TAG>\" to exclude the tag.
  1773. Note that for the purpose of tag filtering, only the lower-case version of
  1774. all tags will be considered, so that this function will only ever see
  1775. the lower-case version of all tags."
  1776. :group 'org-agenda
  1777. :type '(choice (const nil) (function)))
  1778. (defcustom org-agenda-bulk-custom-functions nil
  1779. "Alist of characters and custom functions for bulk actions.
  1780. For example, this value makes those two functions available:
  1781. \\='((?R set-category)
  1782. (?C bulk-cut))
  1783. With selected entries in an agenda buffer, `B R' will call
  1784. the custom function `set-category' on the selected entries.
  1785. Note that functions in this alist don't need to be quoted."
  1786. :type '(alist :key-type character :value-type (group function))
  1787. :version "24.1"
  1788. :group 'org-agenda)
  1789. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1790. "Execute BODY with point at location given by `org-hd-marker' property.
  1791. If STRING is non-nil, the text property will be fetched from position 0
  1792. in that string. If STRING is nil, it will be fetched from the beginning
  1793. of the current line."
  1794. (org-with-gensyms (marker)
  1795. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1796. 'org-hd-marker ,string)))
  1797. (with-current-buffer (marker-buffer ,marker)
  1798. (save-excursion
  1799. (goto-char ,marker)
  1800. ,@body)))))
  1801. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1802. (defun org-add-agenda-custom-command (entry)
  1803. "Replace or add a command in `org-agenda-custom-commands'.
  1804. This is mostly for hacking and trying a new command - once the command
  1805. works you probably want to add it to `org-agenda-custom-commands' for good."
  1806. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1807. (if ass
  1808. (setcdr ass (cdr entry))
  1809. (push entry org-agenda-custom-commands))))
  1810. (defmacro org-agenda--insert-overriding-header (default)
  1811. "Insert header into agenda view.
  1812. The inserted header depends on `org-agenda-overriding-header'.
  1813. If the empty string, don't insert a header. If any other string,
  1814. insert it as a header. If nil, insert DEFAULT, which should
  1815. evaluate to a string."
  1816. (declare (debug (form)) (indent defun))
  1817. `(cond
  1818. ((not org-agenda-overriding-header) (insert ,default))
  1819. ((equal org-agenda-overriding-header "") nil)
  1820. ((stringp org-agenda-overriding-header)
  1821. (insert (propertize org-agenda-overriding-header
  1822. 'face 'org-agenda-structure)
  1823. "\n"))
  1824. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1825. org-agenda-overriding-header))))
  1826. ;;; Define the org-agenda-mode
  1827. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1828. (defvar org-agenda-mode-map (make-sparse-keymap)
  1829. "Keymap for `org-agenda-mode'.")
  1830. (defvar org-agenda-menu) ; defined later in this file.
  1831. (defvar org-agenda-restrict nil) ; defined later in this file.
  1832. (defvar org-agenda-follow-mode nil)
  1833. (defvar org-agenda-entry-text-mode nil)
  1834. (defvar org-agenda-clockreport-mode nil)
  1835. (defvar org-agenda-show-log nil
  1836. "When non-nil, show the log in the agenda.
  1837. Do not set this directly; instead use
  1838. `org-agenda-start-with-log-mode', which see.")
  1839. (defvar org-agenda-redo-command nil)
  1840. (defvar org-agenda-query-string nil)
  1841. (defvar org-agenda-mode-hook nil
  1842. "Hook run after `org-agenda-mode' is turned on.
  1843. The buffer is still writable when this hook is called.")
  1844. (defvar org-agenda-type nil)
  1845. (defvar org-agenda-force-single-file nil)
  1846. (defvar org-agenda-bulk-marked-entries nil
  1847. "List of markers that refer to marked entries in the agenda.")
  1848. (defvar org-agenda-current-date nil
  1849. "Active date when building the agenda.")
  1850. ;;; Multiple agenda buffers support
  1851. (defcustom org-agenda-sticky nil
  1852. "Non-nil means agenda q key will bury agenda buffers.
  1853. Agenda commands will then show existing buffer instead of generating new ones.
  1854. When nil, `q' will kill the single agenda buffer."
  1855. :group 'org-agenda
  1856. :version "24.3"
  1857. :type 'boolean)
  1858. ;;;###autoload
  1859. (defun org-toggle-sticky-agenda (&optional arg)
  1860. "Toggle `org-agenda-sticky'."
  1861. (interactive "P")
  1862. (let ((new-value (if arg
  1863. (> (prefix-numeric-value arg) 0)
  1864. (not org-agenda-sticky))))
  1865. (if (equal new-value org-agenda-sticky)
  1866. (and (called-interactively-p 'interactive)
  1867. (message "Sticky agenda was already %s"
  1868. (if org-agenda-sticky "enabled" "disabled")))
  1869. (setq org-agenda-sticky new-value)
  1870. (org-agenda-kill-all-agenda-buffers)
  1871. (and (called-interactively-p 'interactive)
  1872. (message "Sticky agenda %s"
  1873. (if org-agenda-sticky "enabled" "disabled"))))))
  1874. (defvar org-agenda-buffer nil
  1875. "Agenda buffer currently being generated.")
  1876. (defvar org-agenda-last-prefix-arg nil)
  1877. (defvar org-agenda-this-buffer-name nil)
  1878. (defvar org-agenda-doing-sticky-redo nil)
  1879. (defvar org-agenda-this-buffer-is-sticky nil)
  1880. (defvar org-agenda-last-indirect-buffer nil
  1881. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1882. (defconst org-agenda-local-vars
  1883. '(org-agenda-this-buffer-name
  1884. org-agenda-undo-list
  1885. org-agenda-pending-undo-list
  1886. org-agenda-follow-mode
  1887. org-agenda-entry-text-mode
  1888. org-agenda-clockreport-mode
  1889. org-agenda-show-log
  1890. org-agenda-redo-command
  1891. org-agenda-query-string
  1892. org-agenda-type
  1893. org-agenda-bulk-marked-entries
  1894. org-agenda-undo-has-started-in
  1895. org-agenda-info
  1896. org-agenda-pre-window-conf
  1897. org-agenda-columns-active
  1898. org-agenda-tag-filter
  1899. org-agenda-category-filter
  1900. org-agenda-top-headline-filter
  1901. org-agenda-regexp-filter
  1902. org-agenda-effort-filter
  1903. org-agenda-markers
  1904. org-agenda-last-search-view-search-was-boolean
  1905. org-agenda-last-indirect-buffer
  1906. org-agenda-filtered-by-category
  1907. org-agenda-filter-form
  1908. org-agenda-cycle-counter
  1909. org-agenda-last-prefix-arg)
  1910. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1911. (defun org-agenda-mode ()
  1912. "Mode for time-sorted view on action items in Org files.
  1913. The following commands are available:
  1914. \\{org-agenda-mode-map}"
  1915. (interactive)
  1916. (let ((agenda-local-vars-to-keep
  1917. '(text-scale-mode-amount
  1918. text-scale-mode
  1919. text-scale-mode-lighter
  1920. face-remapping-alist))
  1921. (save (buffer-local-variables)))
  1922. (kill-all-local-variables)
  1923. (cl-flet ((reset-saved (var-set)
  1924. "Reset variables in VAR-SET to possibly stored value in SAVE."
  1925. (dolist (elem save)
  1926. (pcase elem
  1927. (`(,var . ,val) ;ignore unbound variables
  1928. (when (and val (memq var var-set))
  1929. (set var val)))))))
  1930. (cond (org-agenda-doing-sticky-redo
  1931. ;; Refreshing sticky agenda-buffer
  1932. ;;
  1933. ;; Preserve the value of `org-agenda-local-vars' variables.
  1934. (mapc #'make-local-variable org-agenda-local-vars)
  1935. (reset-saved org-agenda-local-vars)
  1936. (setq-local org-agenda-this-buffer-is-sticky t))
  1937. (org-agenda-sticky
  1938. ;; Creating a sticky Agenda buffer for the first time
  1939. (mapc 'make-local-variable org-agenda-local-vars)
  1940. (setq-local org-agenda-this-buffer-is-sticky t))
  1941. (t
  1942. ;; Creating a non-sticky agenda buffer
  1943. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1944. (mapc #'make-local-variable agenda-local-vars-to-keep)
  1945. (reset-saved agenda-local-vars-to-keep)))
  1946. (setq org-agenda-undo-list nil
  1947. org-agenda-pending-undo-list nil
  1948. org-agenda-bulk-marked-entries nil)
  1949. (setq major-mode 'org-agenda-mode)
  1950. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1951. (setq-local font-lock-global-modes (list 'not major-mode))
  1952. (setq mode-name "Org-Agenda")
  1953. (setq indent-tabs-mode nil)
  1954. (use-local-map org-agenda-mode-map)
  1955. (easy-menu-add org-agenda-menu)
  1956. (when org-startup-truncated (setq truncate-lines t))
  1957. (setq-local line-move-visual nil)
  1958. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1959. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1960. ;; Make sure properties are removed when copying text
  1961. (if (boundp 'filter-buffer-substring-functions)
  1962. (add-hook 'filter-buffer-substring-functions
  1963. (lambda (fun start end delete)
  1964. (substring-no-properties (funcall fun start end delete)))
  1965. nil t)
  1966. ;; Emacs >= 24.4.
  1967. (add-function :filter-return (local 'filter-buffer-substring-function)
  1968. #'substring-no-properties))
  1969. (unless org-agenda-keep-modes
  1970. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1971. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1972. org-agenda-show-log org-agenda-start-with-log-mode
  1973. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  1974. (add-to-invisibility-spec '(org-filtered))
  1975. (add-to-invisibility-spec '(org-link))
  1976. (easy-menu-change
  1977. '("Agenda") "Agenda Files"
  1978. (append
  1979. (list
  1980. (vector
  1981. (if (get 'org-agenda-files 'org-restrict)
  1982. "Restricted to single file"
  1983. "Edit File List")
  1984. '(org-edit-agenda-file-list)
  1985. (not (get 'org-agenda-files 'org-restrict)))
  1986. "--")
  1987. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1988. (org-agenda-set-mode-name)
  1989. (apply
  1990. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1991. (list 'org-agenda-mode-hook)))
  1992. (substitute-key-definition 'undo 'org-agenda-undo
  1993. org-agenda-mode-map global-map)
  1994. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1995. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1996. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1997. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1998. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1999. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  2000. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  2001. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  2002. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  2003. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  2004. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  2005. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  2006. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  2007. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  2008. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  2009. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  2010. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  2011. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  2012. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  2013. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  2014. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  2015. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  2016. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  2017. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  2018. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  2019. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  2020. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  2021. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  2022. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  2023. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  2024. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  2025. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  2026. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  2027. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  2028. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  2029. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  2030. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  2031. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  2033. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  2034. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  2035. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  2036. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  2037. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  2038. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  2039. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  2040. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  2041. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  2042. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  2043. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  2044. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  2045. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  2046. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  2047. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2048. (while l (org-defkey org-agenda-mode-map
  2049. (int-to-string (pop l)) 'digit-argument)))
  2050. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  2051. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  2052. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2053. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2054. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2055. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2056. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2057. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2058. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2059. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo-all)
  2060. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2061. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2062. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2063. 'org-clock-modify-effort-estimate)
  2064. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2065. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2066. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2067. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2068. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2069. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2070. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2071. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2072. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2073. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2074. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2075. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2076. (substitute-key-definition 'next-line 'org-agenda-next-line
  2077. org-agenda-mode-map global-map)
  2078. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2079. org-agenda-mode-map global-map)
  2080. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2081. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2082. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2083. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2084. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2085. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2086. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2087. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2088. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2089. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2090. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2091. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2092. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2093. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2094. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2095. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2096. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2097. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2099. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2100. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2101. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2102. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2103. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2104. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2105. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2106. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2107. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2108. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2109. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2110. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2111. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2112. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2113. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2114. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2115. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2116. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2117. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2118. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2119. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2120. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2121. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2122. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2123. (org-defkey org-agenda-mode-map "\C-c\C-x_" 'org-timer-stop)
  2124. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2125. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2126. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2127. (org-defkey org-agenda-mode-map "\C-c\C-xI" 'org-info-find-node)
  2128. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2129. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2130. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2131. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2132. (when org-agenda-mouse-1-follows-link
  2133. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2134. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2135. '("Agenda"
  2136. ("Agenda Files")
  2137. "--"
  2138. ("Agenda Dates"
  2139. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2140. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2141. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2142. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2143. "--"
  2144. ("View"
  2145. ["Day View" org-agenda-day-view
  2146. :active (org-agenda-check-type nil 'agenda)
  2147. :style radio :selected (eq org-agenda-current-span 'day)
  2148. :keys "v d (or just d)"]
  2149. ["Week View" org-agenda-week-view
  2150. :active (org-agenda-check-type nil 'agenda)
  2151. :style radio :selected (eq org-agenda-current-span 'week)
  2152. :keys "v w"]
  2153. ["Fortnight View" org-agenda-fortnight-view
  2154. :active (org-agenda-check-type nil 'agenda)
  2155. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2156. :keys "v t"]
  2157. ["Month View" org-agenda-month-view
  2158. :active (org-agenda-check-type nil 'agenda)
  2159. :style radio :selected (eq org-agenda-current-span 'month)
  2160. :keys "v m"]
  2161. ["Year View" org-agenda-year-view
  2162. :active (org-agenda-check-type nil 'agenda)
  2163. :style radio :selected (eq org-agenda-current-span 'year)
  2164. :keys "v y"]
  2165. "--"
  2166. ["Include Diary" org-agenda-toggle-diary
  2167. :style toggle :selected org-agenda-include-diary
  2168. :active (org-agenda-check-type nil 'agenda)]
  2169. ["Include Deadlines" org-agenda-toggle-deadlines
  2170. :style toggle :selected org-agenda-include-deadlines
  2171. :active (org-agenda-check-type nil 'agenda)]
  2172. ["Use Time Grid" org-agenda-toggle-time-grid
  2173. :style toggle :selected org-agenda-use-time-grid
  2174. :active (org-agenda-check-type nil 'agenda)]
  2175. "--"
  2176. ["Show clock report" org-agenda-clockreport-mode
  2177. :style toggle :selected org-agenda-clockreport-mode
  2178. :active (org-agenda-check-type nil 'agenda)]
  2179. ["Show some entry text" org-agenda-entry-text-mode
  2180. :style toggle :selected org-agenda-entry-text-mode
  2181. :active t]
  2182. "--"
  2183. ["Show Logbook entries" org-agenda-log-mode
  2184. :style toggle :selected org-agenda-show-log
  2185. :active (org-agenda-check-type nil 'agenda)
  2186. :keys "v l (or just l)"]
  2187. ["Include archived trees" org-agenda-archives-mode
  2188. :style toggle :selected org-agenda-archives-mode :active t
  2189. :keys "v a"]
  2190. ["Include archive files" (org-agenda-archives-mode t)
  2191. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2192. :keys "v A"]
  2193. "--"
  2194. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2195. ["Write view to file" org-agenda-write t]
  2196. ["Rebuild buffer" org-agenda-redo t]
  2197. ["Save all Org buffers" org-save-all-org-buffers t]
  2198. "--"
  2199. ["Show original entry" org-agenda-show t]
  2200. ["Go To (other window)" org-agenda-goto t]
  2201. ["Go To (this window)" org-agenda-switch-to t]
  2202. ["Capture with cursor date" org-agenda-capture t]
  2203. ["Follow Mode" org-agenda-follow-mode
  2204. :style toggle :selected org-agenda-follow-mode :active t]
  2205. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2206. "--"
  2207. ("TODO"
  2208. ["Cycle TODO" org-agenda-todo t]
  2209. ["Next TODO set" org-agenda-todo-nextset t]
  2210. ["Previous TODO set" org-agenda-todo-previousset t]
  2211. ["Add note" org-agenda-add-note t])
  2212. ("Archive/Refile/Delete"
  2213. ["Archive default" org-agenda-archive-default t]
  2214. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2215. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2216. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2217. ["Archive subtree" org-agenda-archive t]
  2218. "--"
  2219. ["Refile" org-agenda-refile t]
  2220. "--"
  2221. ["Delete subtree" org-agenda-kill t])
  2222. ("Bulk action"
  2223. ["Mark entry" org-agenda-bulk-mark t]
  2224. ["Mark all" org-agenda-bulk-mark-all t]
  2225. ["Unmark entry" org-agenda-bulk-unmark t]
  2226. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2227. ["Toggle mark" org-agenda-bulk-toggle t]
  2228. ["Toggle all" org-agenda-bulk-toggle-all t]
  2229. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2230. ["Act on all marked" org-agenda-bulk-action t]
  2231. "--"
  2232. ("Tags and Properties"
  2233. ["Show all Tags" org-agenda-show-tags t]
  2234. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2235. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2236. "--"
  2237. ["Column View" org-columns t])
  2238. ("Deadline/Schedule"
  2239. ["Schedule" org-agenda-schedule t]
  2240. ["Set Deadline" org-agenda-deadline t]
  2241. "--"
  2242. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2243. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2244. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2245. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2246. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2247. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2248. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2249. ("Clock and Effort"
  2250. ["Clock in" org-agenda-clock-in t]
  2251. ["Clock out" org-agenda-clock-out t]
  2252. ["Clock cancel" org-agenda-clock-cancel t]
  2253. ["Goto running clock" org-clock-goto t]
  2254. "--"
  2255. ["Set Effort" org-agenda-set-effort t]
  2256. ["Change clocked effort" org-clock-modify-effort-estimate
  2257. (org-clock-is-active)])
  2258. ("Priority"
  2259. ["Set Priority" org-agenda-priority t]
  2260. ["Increase Priority" org-agenda-priority-up t]
  2261. ["Decrease Priority" org-agenda-priority-down t]
  2262. ["Show Priority" org-show-priority t])
  2263. ("Calendar/Diary"
  2264. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2265. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2266. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2267. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2268. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2269. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2270. "--"
  2271. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2272. "--"
  2273. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2274. "--"
  2275. ("MobileOrg"
  2276. ["Push Files and Views" org-mobile-push t]
  2277. ["Get Captured and Flagged" org-mobile-pull t]
  2278. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2279. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2280. "--"
  2281. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2282. "--"
  2283. ["Quit" org-agenda-quit t]
  2284. ["Exit and Release Buffers" org-agenda-exit t]
  2285. ))
  2286. ;;; Agenda undo
  2287. (defvar org-agenda-allow-remote-undo t
  2288. "Non-nil means allow remote undo from the agenda buffer.")
  2289. (defvar org-agenda-undo-has-started-in nil
  2290. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2291. (defun org-agenda-undo ()
  2292. "Undo a remote editing step in the agenda.
  2293. This undoes changes both in the agenda buffer and in the remote buffer
  2294. that have been changed along."
  2295. (interactive)
  2296. (or org-agenda-allow-remote-undo
  2297. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2298. (when (not (eq this-command last-command))
  2299. (setq org-agenda-undo-has-started-in nil
  2300. org-agenda-pending-undo-list org-agenda-undo-list))
  2301. (when (not org-agenda-pending-undo-list)
  2302. (user-error "No further undo information"))
  2303. (let* ((entry (pop org-agenda-pending-undo-list))
  2304. buf line cmd rembuf)
  2305. (setq cmd (pop entry) line (pop entry))
  2306. (setq rembuf (nth 2 entry))
  2307. (org-with-remote-undo rembuf
  2308. (while (bufferp (setq buf (pop entry)))
  2309. (when (pop entry)
  2310. (with-current-buffer buf
  2311. (let ((last-undo-buffer buf)
  2312. (inhibit-read-only t))
  2313. (unless (memq buf org-agenda-undo-has-started-in)
  2314. (push buf org-agenda-undo-has-started-in)
  2315. (make-local-variable 'pending-undo-list)
  2316. (undo-start))
  2317. (while (and pending-undo-list
  2318. (listp pending-undo-list)
  2319. (not (car pending-undo-list)))
  2320. (pop pending-undo-list))
  2321. (undo-more 1))))))
  2322. (org-goto-line line)
  2323. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2324. (defun org-verify-change-for-undo (l1 l2)
  2325. "Verify that a real change occurred between the undo lists L1 and L2."
  2326. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2327. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2328. (not (eq l1 l2)))
  2329. ;;; Agenda dispatch
  2330. (defvar org-agenda-restrict-begin (make-marker))
  2331. (defvar org-agenda-restrict-end (make-marker))
  2332. (defvar org-agenda-last-dispatch-buffer nil)
  2333. (defvar org-agenda-overriding-restriction nil)
  2334. (defcustom org-agenda-custom-commands-contexts nil
  2335. "Alist of custom agenda keys and contextual rules.
  2336. For example, if you have a custom agenda command \"p\" and you
  2337. want this command to be accessible only from plain text files,
  2338. use this:
  2339. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2340. Here are the available contexts definitions:
  2341. in-file: command displayed only in matching files
  2342. in-mode: command displayed only in matching modes
  2343. not-in-file: command not displayed in matching files
  2344. not-in-mode: command not displayed in matching modes
  2345. in-buffer: command displayed only in matching buffers
  2346. not-in-buffer: command not displayed in matching buffers
  2347. [function]: a custom function taking no argument
  2348. If you define several checks, the agenda command will be
  2349. accessible if there is at least one valid check.
  2350. You can also bind a key to another agenda custom command
  2351. depending on contextual rules.
  2352. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2353. Here it means: in .txt files, use \"p\" as the key for the
  2354. agenda command otherwise associated with \"q\". (The command
  2355. originally associated with \"q\" is not displayed to avoid
  2356. duplicates.)"
  2357. :version "24.3"
  2358. :group 'org-agenda-custom-commands
  2359. :type '(repeat (list :tag "Rule"
  2360. (string :tag " Agenda key")
  2361. (string :tag "Replace by command")
  2362. (repeat :tag "Available when"
  2363. (choice
  2364. (cons :tag "Condition"
  2365. (choice
  2366. (const :tag "In file" in-file)
  2367. (const :tag "Not in file" not-in-file)
  2368. (const :tag "In buffer" in-buffer)
  2369. (const :tag "Not in buffer" not-in-buffer)
  2370. (const :tag "In mode" in-mode)
  2371. (const :tag "Not in mode" not-in-mode))
  2372. (regexp))
  2373. (function :tag "Custom function"))))))
  2374. (defcustom org-agenda-max-entries nil
  2375. "Maximum number of entries to display in an agenda.
  2376. This can be nil (no limit) or an integer or an alist of agenda
  2377. types with an associated number of entries to display in this
  2378. type."
  2379. :version "24.4"
  2380. :package-version '(Org . "8.0")
  2381. :group 'org-agenda-custom-commands
  2382. :type '(choice (symbol :tag "No limit" nil)
  2383. (integer :tag "Max number of entries")
  2384. (repeat
  2385. (cons (choice :tag "Agenda type"
  2386. (const agenda)
  2387. (const todo)
  2388. (const tags)
  2389. (const search))
  2390. (integer :tag "Max number of entries")))))
  2391. (defcustom org-agenda-max-todos nil
  2392. "Maximum number of TODOs to display in an agenda.
  2393. This can be nil (no limit) or an integer or an alist of agenda
  2394. types with an associated number of entries to display in this
  2395. type."
  2396. :version "24.4"
  2397. :package-version '(Org . "8.0")
  2398. :group 'org-agenda-custom-commands
  2399. :type '(choice (symbol :tag "No limit" nil)
  2400. (integer :tag "Max number of TODOs")
  2401. (repeat
  2402. (cons (choice :tag "Agenda type"
  2403. (const agenda)
  2404. (const todo)
  2405. (const tags)
  2406. (const search))
  2407. (integer :tag "Max number of TODOs")))))
  2408. (defcustom org-agenda-max-tags nil
  2409. "Maximum number of tagged entries to display in an agenda.
  2410. This can be nil (no limit) or an integer or an alist of agenda
  2411. types with an associated number of entries to display in this
  2412. type."
  2413. :version "24.4"
  2414. :package-version '(Org . "8.0")
  2415. :group 'org-agenda-custom-commands
  2416. :type '(choice (symbol :tag "No limit" nil)
  2417. (integer :tag "Max number of tagged entries")
  2418. (repeat
  2419. (cons (choice :tag "Agenda type"
  2420. (const agenda)
  2421. (const todo)
  2422. (const tags)
  2423. (const search))
  2424. (integer :tag "Max number of tagged entries")))))
  2425. (defcustom org-agenda-max-effort nil
  2426. "Maximum cumulated effort duration for the agenda.
  2427. This can be nil (no limit) or a number of minutes (as an integer)
  2428. or an alist of agenda types with an associated number of minutes
  2429. to limit entries to in this type."
  2430. :version "24.4"
  2431. :package-version '(Org . "8.0")
  2432. :group 'org-agenda-custom-commands
  2433. :type '(choice (symbol :tag "No limit" nil)
  2434. (integer :tag "Max number of minutes")
  2435. (repeat
  2436. (cons (choice :tag "Agenda type"
  2437. (const agenda)
  2438. (const todo)
  2439. (const tags)
  2440. (const search))
  2441. (integer :tag "Max number of minutes")))))
  2442. (defvar org-agenda-keep-restricted-file-list nil)
  2443. (defvar org-keys nil)
  2444. (defvar org-match nil)
  2445. ;;;###autoload
  2446. (defun org-agenda (&optional arg org-keys restriction)
  2447. "Dispatch agenda commands to collect entries to the agenda buffer.
  2448. Prompts for a command to execute. Any prefix arg will be passed
  2449. on to the selected command. The default selections are:
  2450. a Call `org-agenda-list' to display the agenda for current day or week.
  2451. t Call `org-todo-list' to display the global todo list.
  2452. T Call `org-todo-list' to display the global todo list, select only
  2453. entries with a specific TODO keyword (the user gets a prompt).
  2454. m Call `org-tags-view' to display headlines with tags matching
  2455. a condition (the user is prompted for the condition).
  2456. M Like `m', but select only TODO entries, no ordinary headlines.
  2457. e Export views to associated files.
  2458. s Search entries for keywords.
  2459. S Search entries for keywords, only with TODO keywords.
  2460. / Multi occur across all agenda files and also files listed
  2461. in `org-agenda-text-search-extra-files'.
  2462. < Restrict agenda commands to buffer, subtree, or region.
  2463. Press several times to get the desired effect.
  2464. > Remove a previous restriction.
  2465. # List \"stuck\" projects.
  2466. ! Configure what \"stuck\" means.
  2467. C Configure custom agenda commands.
  2468. More commands can be added by configuring the variable
  2469. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2470. searches can be pre-defined in this way.
  2471. If the current buffer is in Org mode and visiting a file, you can also
  2472. first press `<' once to indicate that the agenda should be temporarily
  2473. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2474. Pressing `<' twice means to restrict to the current subtree or region
  2475. \(if active)."
  2476. (interactive "P")
  2477. (catch 'exit
  2478. (let* ((prefix-descriptions nil)
  2479. (org-agenda-buffer-name org-agenda-buffer-name)
  2480. (org-agenda-window-setup (if (equal (buffer-name)
  2481. org-agenda-buffer-name)
  2482. 'current-window
  2483. org-agenda-window-setup))
  2484. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2485. (org-agenda-custom-commands
  2486. ;; normalize different versions
  2487. (delq nil
  2488. (mapcar
  2489. (lambda (x)
  2490. (cond ((stringp (cdr x))
  2491. (push x prefix-descriptions)
  2492. nil)
  2493. ((stringp (nth 1 x)) x)
  2494. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2495. (t (cons (car x) (cons "" (cdr x))))))
  2496. org-agenda-custom-commands)))
  2497. (org-agenda-custom-commands
  2498. (org-contextualize-keys
  2499. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2500. (buf (current-buffer))
  2501. (bfn (buffer-file-name (buffer-base-buffer)))
  2502. entry key type org-match lprops ans)
  2503. ;; Turn off restriction unless there is an overriding one,
  2504. (unless org-agenda-overriding-restriction
  2505. (unless org-agenda-keep-restricted-file-list
  2506. ;; There is a request to keep the file list in place
  2507. (put 'org-agenda-files 'org-restrict nil))
  2508. (setq org-agenda-restrict nil)
  2509. (move-marker org-agenda-restrict-begin nil)
  2510. (move-marker org-agenda-restrict-end nil))
  2511. ;; Delete old local properties
  2512. (put 'org-agenda-redo-command 'org-lprops nil)
  2513. ;; Delete previously set last-arguments
  2514. (put 'org-agenda-redo-command 'last-args nil)
  2515. ;; Remember where this call originated
  2516. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2517. (unless org-keys
  2518. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2519. org-keys (car ans)
  2520. restriction (cdr ans)))
  2521. ;; If we have sticky agenda buffers, set a name for the buffer,
  2522. ;; depending on the invoking keys. The user may still set this
  2523. ;; as a command option, which will overwrite what we do here.
  2524. (when org-agenda-sticky
  2525. (setq org-agenda-buffer-name
  2526. (format "*Org Agenda(%s)*" org-keys)))
  2527. ;; Establish the restriction, if any
  2528. (when (and (not org-agenda-overriding-restriction) restriction)
  2529. (put 'org-agenda-files 'org-restrict (list bfn))
  2530. (cond
  2531. ((eq restriction 'region)
  2532. (setq org-agenda-restrict (current-buffer))
  2533. (move-marker org-agenda-restrict-begin (region-beginning))
  2534. (move-marker org-agenda-restrict-end (region-end)))
  2535. ((eq restriction 'subtree)
  2536. (save-excursion
  2537. (setq org-agenda-restrict (current-buffer))
  2538. (org-back-to-heading t)
  2539. (move-marker org-agenda-restrict-begin (point))
  2540. (move-marker org-agenda-restrict-end
  2541. (progn (org-end-of-subtree t)))))))
  2542. ;; For example the todo list should not need it (but does...)
  2543. (cond
  2544. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2545. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2546. (progn
  2547. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2548. lprops (nth 4 entry))
  2549. (when org-agenda-sticky
  2550. (setq org-agenda-buffer-name
  2551. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2552. (format "*Org Agenda(%s)*" org-keys))))
  2553. (put 'org-agenda-redo-command 'org-lprops lprops)
  2554. (cond
  2555. ((eq type 'agenda)
  2556. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2557. ((eq type 'agenda*)
  2558. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2559. ((eq type 'alltodo)
  2560. (org-let lprops '(org-todo-list current-prefix-arg)))
  2561. ((eq type 'search)
  2562. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2563. ((eq type 'stuck)
  2564. (org-let lprops '(org-agenda-list-stuck-projects
  2565. current-prefix-arg)))
  2566. ((eq type 'tags)
  2567. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2568. ((eq type 'tags-todo)
  2569. (org-let lprops '(org-tags-view '(4) org-match)))
  2570. ((eq type 'todo)
  2571. (org-let lprops '(org-todo-list org-match)))
  2572. ((eq type 'tags-tree)
  2573. (org-check-for-org-mode)
  2574. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2575. ((eq type 'todo-tree)
  2576. (org-check-for-org-mode)
  2577. (org-let lprops
  2578. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2579. (regexp-quote org-match) "\\>"))))
  2580. ((eq type 'occur-tree)
  2581. (org-check-for-org-mode)
  2582. (org-let lprops '(org-occur org-match)))
  2583. ((functionp type)
  2584. (org-let lprops '(funcall type org-match)))
  2585. ((fboundp type)
  2586. (org-let lprops '(funcall type org-match)))
  2587. (t (user-error "Invalid custom agenda command type %s" type))))
  2588. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2589. ((equal org-keys "C")
  2590. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2591. (customize-variable 'org-agenda-custom-commands))
  2592. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2593. ((equal org-keys "s") (call-interactively 'org-search-view))
  2594. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2595. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2596. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2597. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2598. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2599. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2600. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2601. (add-hook
  2602. 'post-command-hook
  2603. (lambda ()
  2604. (unless (current-message)
  2605. (let* ((m (org-agenda-get-any-marker))
  2606. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2607. (when note
  2608. (message "FLAGGING-NOTE ([?] for more info): %s"
  2609. (org-add-props
  2610. (replace-regexp-in-string
  2611. "\\\\n" "//"
  2612. (copy-sequence note))
  2613. nil 'face 'org-warning))))))
  2614. t t))
  2615. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2616. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2617. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2618. (t (user-error "Invalid agenda key"))))))
  2619. (defvar org-agenda-multi)
  2620. (defun org-agenda-append-agenda ()
  2621. "Append another agenda view to the current one.
  2622. This function allows interactive building of block agendas.
  2623. Agenda views are separated by `org-agenda-block-separator'."
  2624. (interactive)
  2625. (unless (derived-mode-p 'org-agenda-mode)
  2626. (user-error "Can only append from within agenda buffer"))
  2627. (let ((org-agenda-multi t))
  2628. (org-agenda)
  2629. (widen)
  2630. (org-agenda-finalize)
  2631. (setq buffer-read-only t)
  2632. (org-agenda-fit-window-to-buffer)))
  2633. (defun org-agenda-normalize-custom-commands (cmds)
  2634. "Normalize custom commands CMDS."
  2635. (delq nil
  2636. (mapcar
  2637. (lambda (x)
  2638. (cond ((stringp (cdr x)) nil)
  2639. ((stringp (nth 1 x)) x)
  2640. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2641. (t (cons (car x) (cons "" (cdr x))))))
  2642. cmds)))
  2643. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2644. "The user interface for selecting an agenda command."
  2645. (catch 'exit
  2646. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2647. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2648. (region-p (org-region-active-p))
  2649. (custom org-agenda-custom-commands)
  2650. (selstring "")
  2651. restriction second-time
  2652. c entry key type match prefixes rmheader header-end custom1 desc
  2653. line lines left right n n1)
  2654. (save-window-excursion
  2655. (delete-other-windows)
  2656. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2657. (erase-buffer)
  2658. (insert (eval-when-compile
  2659. (let ((header
  2660. "Press key for an agenda command:
  2661. -------------------------------- < Buffer, subtree/region restriction
  2662. a Agenda for current week or day > Remove restriction
  2663. t List of all TODO entries e Export agenda views
  2664. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2665. s Search for keywords M Like m, but only TODO entries
  2666. / Multi-occur S Like s, but only TODO entries
  2667. ? Find :FLAGGED: entries C Configure custom agenda commands
  2668. * Toggle sticky agenda views # List stuck projects (!=configure)
  2669. ")
  2670. (start 0))
  2671. (while (string-match
  2672. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2673. header start)
  2674. (setq start (match-end 0))
  2675. (add-text-properties (match-beginning 2) (match-end 2)
  2676. '(face bold) header))
  2677. header)))
  2678. (setq header-end (point-marker))
  2679. (while t
  2680. (setq custom1 custom)
  2681. (when (eq rmheader t)
  2682. (org-goto-line 1)
  2683. (re-search-forward ":" nil t)
  2684. (delete-region (match-end 0) (point-at-eol))
  2685. (forward-char 1)
  2686. (looking-at "-+")
  2687. (delete-region (match-end 0) (point-at-eol))
  2688. (move-marker header-end (match-end 0)))
  2689. (goto-char header-end)
  2690. (delete-region (point) (point-max))
  2691. ;; Produce all the lines that describe custom commands and prefixes
  2692. (setq lines nil)
  2693. (while (setq entry (pop custom1))
  2694. (setq key (car entry) desc (nth 1 entry)
  2695. type (nth 2 entry)
  2696. match (nth 3 entry))
  2697. (if (> (length key) 1)
  2698. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2699. (setq line
  2700. (format
  2701. "%-4s%-14s"
  2702. (org-add-props (copy-sequence key)
  2703. '(face bold))
  2704. (cond
  2705. ((string-match "\\S-" desc) desc)
  2706. ((eq type 'agenda) "Agenda for current week or day")
  2707. ((eq type 'agenda*) "Appointments for current week or day")
  2708. ((eq type 'alltodo) "List of all TODO entries")
  2709. ((eq type 'search) "Word search")
  2710. ((eq type 'stuck) "List of stuck projects")
  2711. ((eq type 'todo) "TODO keyword")
  2712. ((eq type 'tags) "Tags query")
  2713. ((eq type 'tags-todo) "Tags (TODO)")
  2714. ((eq type 'tags-tree) "Tags tree")
  2715. ((eq type 'todo-tree) "TODO kwd tree")
  2716. ((eq type 'occur-tree) "Occur tree")
  2717. ((functionp type) (if (symbolp type)
  2718. (symbol-name type)
  2719. "Lambda expression"))
  2720. (t "???"))))
  2721. (cond
  2722. ((not (org-string-nw-p match)) nil)
  2723. (org-agenda-menu-show-matcher
  2724. (setq line
  2725. (concat line ": "
  2726. (cond
  2727. ((stringp match)
  2728. (propertize match 'face 'org-warning))
  2729. ((listp type)
  2730. (format "set of %d commands" (length type)))))))
  2731. (t
  2732. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2733. (push line lines)))
  2734. (setq lines (nreverse lines))
  2735. (when prefixes
  2736. (mapc (lambda (x)
  2737. (push
  2738. (format "%s %s"
  2739. (org-add-props (char-to-string x)
  2740. nil 'face 'bold)
  2741. (or (cdr (assoc (concat selstring
  2742. (char-to-string x))
  2743. prefix-descriptions))
  2744. "Prefix key"))
  2745. lines))
  2746. prefixes))
  2747. ;; Check if we should display in two columns
  2748. (if org-agenda-menu-two-columns
  2749. (progn
  2750. (setq n (length lines)
  2751. n1 (+ (/ n 2) (mod n 2))
  2752. right (nthcdr n1 lines)
  2753. left (copy-sequence lines))
  2754. (setcdr (nthcdr (1- n1) left) nil))
  2755. (setq left lines right nil))
  2756. (while left
  2757. (insert "\n" (pop left))
  2758. (when right
  2759. (if (< (current-column) 40)
  2760. (move-to-column 40 t)
  2761. (insert " "))
  2762. (insert (pop right))))
  2763. ;; Make the window the right size
  2764. (goto-char (point-min))
  2765. (if second-time
  2766. (when (not (pos-visible-in-window-p (point-max)))
  2767. (org-fit-window-to-buffer))
  2768. (setq second-time t)
  2769. (org-fit-window-to-buffer))
  2770. ;; Ask for selection
  2771. (message "Press key for agenda command%s:"
  2772. (if (or restrict-ok org-agenda-overriding-restriction)
  2773. (if org-agenda-overriding-restriction
  2774. " (restriction lock active)"
  2775. (if restriction
  2776. (format " (restricted to %s)" restriction)
  2777. " (unrestricted)"))
  2778. ""))
  2779. (setq c (read-char-exclusive))
  2780. (message "")
  2781. (cond
  2782. ((assoc (char-to-string c) custom)
  2783. (setq selstring (concat selstring (char-to-string c)))
  2784. (throw 'exit (cons selstring restriction)))
  2785. ((memq c prefixes)
  2786. (setq selstring (concat selstring (char-to-string c))
  2787. prefixes nil
  2788. rmheader (or rmheader t)
  2789. custom (delq nil (mapcar
  2790. (lambda (x)
  2791. (if (or (= (length (car x)) 1)
  2792. (/= (string-to-char (car x)) c))
  2793. nil
  2794. (cons (substring (car x) 1) (cdr x))))
  2795. custom))))
  2796. ((eq c ?*)
  2797. (call-interactively 'org-toggle-sticky-agenda)
  2798. (sit-for 2))
  2799. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2800. (message "Restriction is only possible in Org buffers")
  2801. (ding) (sit-for 1))
  2802. ((eq c ?1)
  2803. (org-agenda-remove-restriction-lock 'noupdate)
  2804. (setq restriction 'buffer))
  2805. ((eq c ?0)
  2806. (org-agenda-remove-restriction-lock 'noupdate)
  2807. (setq restriction (if region-p 'region 'subtree)))
  2808. ((eq c ?<)
  2809. (org-agenda-remove-restriction-lock 'noupdate)
  2810. (setq restriction
  2811. (cond
  2812. ((eq restriction 'buffer)
  2813. (if region-p 'region 'subtree))
  2814. ((memq restriction '(subtree region))
  2815. nil)
  2816. (t 'buffer))))
  2817. ((eq c ?>)
  2818. (org-agenda-remove-restriction-lock 'noupdate)
  2819. (setq restriction nil))
  2820. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2821. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2822. ((and (> (length selstring) 0) (eq c ?\d))
  2823. (delete-window)
  2824. (org-agenda-get-restriction-and-command prefix-descriptions))
  2825. ((equal c ?q) (error "Abort"))
  2826. (t (user-error "Invalid key %c" c))))))))
  2827. (defun org-agenda-fit-window-to-buffer ()
  2828. "Fit the window to the buffer size."
  2829. (and (memq org-agenda-window-setup '(reorganize-frame))
  2830. (fboundp 'fit-window-to-buffer)
  2831. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2832. (= (car org-agenda-window-frame-fractions) 1.0))
  2833. (delete-other-windows)
  2834. (org-fit-window-to-buffer
  2835. nil
  2836. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2837. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2838. (defvar org-cmd nil)
  2839. (defvar org-agenda-overriding-cmd nil)
  2840. (defvar org-agenda-overriding-arguments nil)
  2841. (defvar org-agenda-overriding-cmd-arguments nil)
  2842. (defun org-agenda-run-series (name series)
  2843. "Run agenda NAME as a SERIES of agenda commands."
  2844. (org-let (nth 1 series) '(org-agenda-prepare name))
  2845. ;; We need to reset agenda markers here, because when constructing a
  2846. ;; block agenda, the individual blocks do not do that.
  2847. (org-agenda-reset-markers)
  2848. (let* ((org-agenda-multi t)
  2849. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2850. (cmds (car series))
  2851. (gprops (nth 1 series))
  2852. match ;; The byte compiler incorrectly complains about this. Keep it!
  2853. org-cmd type lprops)
  2854. (while (setq org-cmd (pop cmds))
  2855. (setq type (car org-cmd))
  2856. (setq match (eval (nth 1 org-cmd)))
  2857. (setq lprops (nth 2 org-cmd))
  2858. (let ((org-agenda-overriding-arguments
  2859. (if (eq org-agenda-overriding-cmd org-cmd)
  2860. (or org-agenda-overriding-arguments
  2861. org-agenda-overriding-cmd-arguments))))
  2862. (cond
  2863. ((eq type 'agenda)
  2864. (org-let2 gprops lprops
  2865. '(call-interactively 'org-agenda-list)))
  2866. ((eq type 'agenda*)
  2867. (org-let2 gprops lprops
  2868. '(funcall 'org-agenda-list nil nil t)))
  2869. ((eq type 'alltodo)
  2870. (org-let2 gprops lprops
  2871. '(call-interactively 'org-todo-list)))
  2872. ((eq type 'search)
  2873. (org-let2 gprops lprops
  2874. '(org-search-view current-prefix-arg match nil)))
  2875. ((eq type 'stuck)
  2876. (org-let2 gprops lprops
  2877. '(call-interactively 'org-agenda-list-stuck-projects)))
  2878. ((eq type 'tags)
  2879. (org-let2 gprops lprops
  2880. '(org-tags-view current-prefix-arg match)))
  2881. ((eq type 'tags-todo)
  2882. (org-let2 gprops lprops
  2883. '(org-tags-view '(4) match)))
  2884. ((eq type 'todo)
  2885. (org-let2 gprops lprops
  2886. '(org-todo-list match)))
  2887. ((fboundp type)
  2888. (org-let2 gprops lprops
  2889. '(funcall type match)))
  2890. (t (error "Invalid type in command series")))))
  2891. (widen)
  2892. (let ((inhibit-read-only t))
  2893. (add-text-properties (point-min) (point-max)
  2894. `(org-series t org-series-redo-cmd ,redo)))
  2895. (setq org-agenda-redo-command redo)
  2896. (goto-char (point-min)))
  2897. (org-agenda-fit-window-to-buffer)
  2898. (org-let (nth 1 series) '(org-agenda-finalize)))
  2899. ;;;###autoload
  2900. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2901. "Run an agenda command in batch mode and send the result to STDOUT.
  2902. If CMD-KEY is a string of length 1, it is used as a key in
  2903. `org-agenda-custom-commands' and triggers this command. If it is a
  2904. longer string it is used as a tags/todo match string.
  2905. Parameters are alternating variable names and values that will be bound
  2906. before running the agenda command."
  2907. (org-eval-in-environment (org-make-parameter-alist parameters)
  2908. (let (org-agenda-sticky)
  2909. (if (> (length cmd-key) 1)
  2910. (org-tags-view nil cmd-key)
  2911. (org-agenda nil cmd-key))))
  2912. (set-buffer org-agenda-buffer-name)
  2913. (princ (buffer-string)))
  2914. (defvar org-agenda-info nil)
  2915. ;;;###autoload
  2916. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2917. "Run an agenda command in batch mode and send the result to STDOUT.
  2918. If CMD-KEY is a string of length 1, it is used as a key in
  2919. `org-agenda-custom-commands' and triggers this command. If it is a
  2920. longer string it is used as a tags/todo match string.
  2921. Parameters are alternating variable names and values that will be bound
  2922. before running the agenda command.
  2923. The output gives a line for each selected agenda item. Each
  2924. item is a list of comma-separated values, like this:
  2925. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2926. category The category of the item
  2927. head The headline, without TODO kwd, TAGS and PRIORITY
  2928. type The type of the agenda entry, can be
  2929. todo selected in TODO match
  2930. tagsmatch selected in tags match
  2931. diary imported from diary
  2932. deadline a deadline on given date
  2933. scheduled scheduled on given date
  2934. timestamp entry has timestamp on given date
  2935. closed entry was closed on given date
  2936. upcoming-deadline warning about deadline
  2937. past-scheduled forwarded scheduled item
  2938. block entry has date block including g. date
  2939. todo The todo keyword, if any
  2940. tags All tags including inherited ones, separated by colons
  2941. date The relevant date, like 2007-2-14
  2942. time The time, like 15:00-16:50
  2943. extra Sting with extra planning info
  2944. priority-l The priority letter if any was given
  2945. priority-n The computed numerical priority
  2946. agenda-day The day in the agenda where this is listed"
  2947. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2948. (org-make-parameter-alist parameters))
  2949. (if (> (length cmd-key) 2)
  2950. (org-tags-view nil cmd-key)
  2951. (org-agenda nil cmd-key)))
  2952. (set-buffer org-agenda-buffer-name)
  2953. (let ((lines (org-split-string (buffer-string) "\n")))
  2954. (dolist (line lines)
  2955. (when (get-text-property 0 'org-category line)
  2956. (setq org-agenda-info
  2957. (org-fix-agenda-info (text-properties-at 0 line)))
  2958. (princ
  2959. (mapconcat 'org-agenda-export-csv-mapper
  2960. '(org-category txt type todo tags date time extra
  2961. priority-letter priority agenda-day)
  2962. ","))
  2963. (princ "\n")))))
  2964. (defun org-fix-agenda-info (props)
  2965. "Make sure all properties on an agenda item have a canonical form.
  2966. This ensures the export commands can easily use it."
  2967. (let (tmp re)
  2968. (when (setq tmp (plist-get props 'tags))
  2969. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2970. (when (setq tmp (plist-get props 'date))
  2971. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2972. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2973. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2974. (setq tmp (calendar-date-string tmp)))
  2975. (setq props (plist-put props 'date tmp)))
  2976. (when (setq tmp (plist-get props 'day))
  2977. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2978. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2979. (setq tmp (calendar-date-string tmp)))
  2980. (setq props (plist-put props 'day tmp))
  2981. (setq props (plist-put props 'agenda-day tmp)))
  2982. (when (setq tmp (plist-get props 'txt))
  2983. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2984. (plist-put props 'priority-letter (match-string 1 tmp))
  2985. (setq tmp (replace-match "" t t tmp)))
  2986. (when (and (setq re (plist-get props 'org-todo-regexp))
  2987. (setq re (concat "\\`\\.*" re " ?"))
  2988. (let ((case-fold-search nil)) (string-match re tmp)))
  2989. (plist-put props 'todo (match-string 1 tmp))
  2990. (setq tmp (replace-match "" t t tmp)))
  2991. (plist-put props 'txt tmp)))
  2992. props)
  2993. (defun org-agenda-export-csv-mapper (prop)
  2994. (let ((res (plist-get org-agenda-info prop)))
  2995. (setq res
  2996. (cond
  2997. ((not res) "")
  2998. ((stringp res) res)
  2999. (t (prin1-to-string res))))
  3000. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3001. ;;;###autoload
  3002. (defun org-store-agenda-views (&rest parameters)
  3003. "Store agenda views."
  3004. (interactive)
  3005. (eval (list 'org-batch-store-agenda-views)))
  3006. ;;;###autoload
  3007. (defmacro org-batch-store-agenda-views (&rest parameters)
  3008. "Run all custom agenda commands that have a file argument."
  3009. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3010. (pop-up-frames nil)
  3011. (dir default-directory)
  3012. (pars (org-make-parameter-alist parameters))
  3013. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3014. (save-window-excursion
  3015. (while cmds
  3016. (setq cmd (pop cmds)
  3017. thiscmdkey (car cmd)
  3018. thiscmdcmd (cdr cmd)
  3019. match (nth 2 thiscmdcmd)
  3020. bufname (if org-agenda-sticky
  3021. (or (and (stringp match)
  3022. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3023. (format "*Org Agenda(%s)*" thiscmdkey))
  3024. org-agenda-buffer-name)
  3025. cmd-or-set (nth 2 cmd)
  3026. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3027. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3028. (if (stringp files) (setq files (list files)))
  3029. (when files
  3030. (org-eval-in-environment (append org-agenda-exporter-settings
  3031. opts pars)
  3032. (org-agenda nil thiscmdkey))
  3033. (set-buffer bufname)
  3034. (while files
  3035. (org-eval-in-environment (append org-agenda-exporter-settings
  3036. opts pars)
  3037. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  3038. (and (get-buffer bufname)
  3039. (kill-buffer bufname)))))))
  3040. (defvar org-agenda-current-span nil
  3041. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3042. (defun org-agenda-mark-header-line (pos)
  3043. "Mark the line at POS as an agenda structure header."
  3044. (save-excursion
  3045. (goto-char pos)
  3046. (put-text-property (point-at-bol) (point-at-eol)
  3047. 'org-agenda-structural-header t)
  3048. (when org-agenda-title-append
  3049. (put-text-property (point-at-bol) (point-at-eol)
  3050. 'org-agenda-title-append org-agenda-title-append))))
  3051. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3052. (defvar org-agenda-write-buffer-name "Agenda View")
  3053. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3054. "Write the current buffer (an agenda view) as a file.
  3055. Depending on the extension of the file name, plain text (.txt),
  3056. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3057. If the extension is .ics, translate visible agenda into iCalendar
  3058. format. If the extension is .org, collect all subtrees
  3059. corresponding to the agenda entries and add them in an .org file.
  3060. With prefix argument OPEN, open the new file immediately. If
  3061. NOSETTINGS is given, do not scope the settings of
  3062. `org-agenda-exporter-settings' into the export commands. This is
  3063. used when the settings have already been scoped and we do not
  3064. wish to overrule other, higher priority settings. If
  3065. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3066. the agenda to write."
  3067. (interactive "FWrite agenda to file: \nP")
  3068. (if (or (not (file-writable-p file))
  3069. (and (file-exists-p file)
  3070. (if (called-interactively-p 'any)
  3071. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3072. (user-error "Cannot write agenda to file %s" file))
  3073. (org-let (if nosettings nil org-agenda-exporter-settings)
  3074. '(save-excursion
  3075. (save-window-excursion
  3076. (let ((bs (copy-sequence (buffer-string)))
  3077. (extension (file-name-extension file))
  3078. (default-directory (file-name-directory file))
  3079. beg content)
  3080. (with-temp-buffer
  3081. (rename-buffer org-agenda-write-buffer-name t)
  3082. (set-buffer-modified-p nil)
  3083. (insert bs)
  3084. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3085. (run-hooks 'org-agenda-before-write-hook)
  3086. (cond
  3087. ((bound-and-true-p org-mobile-creating-agendas)
  3088. (org-mobile-write-agenda-for-mobile file))
  3089. ((string= "org" extension)
  3090. (let (content p m message-log-max)
  3091. (goto-char (point-min))
  3092. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3093. (goto-char p)
  3094. (setq m (get-text-property (point) 'org-hd-marker))
  3095. (when m
  3096. (push (save-excursion
  3097. (set-buffer (marker-buffer m))
  3098. (goto-char m)
  3099. (org-copy-subtree 1 nil t t)
  3100. org-subtree-clip)
  3101. content)))
  3102. (find-file file)
  3103. (erase-buffer)
  3104. (dolist (s content) (org-paste-subtree 1 s))
  3105. (write-file file)
  3106. (kill-buffer (current-buffer))
  3107. (message "Org file written to %s" file)))
  3108. ((member extension '("html" "htm"))
  3109. (or (require 'htmlize nil t)
  3110. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3111. (set-buffer (htmlize-buffer (current-buffer)))
  3112. (when org-agenda-export-html-style
  3113. ;; replace <style> section with org-agenda-export-html-style
  3114. (goto-char (point-min))
  3115. (kill-region (- (search-forward "<style") 6)
  3116. (search-forward "</style>"))
  3117. (insert org-agenda-export-html-style))
  3118. (write-file file)
  3119. (kill-buffer (current-buffer))
  3120. (message "HTML written to %s" file))
  3121. ((string= "ps" extension)
  3122. (require 'ps-print)
  3123. (ps-print-buffer-with-faces file)
  3124. (message "Postscript written to %s" file))
  3125. ((string= "pdf" extension)
  3126. (require 'ps-print)
  3127. (ps-print-buffer-with-faces
  3128. (concat (file-name-sans-extension file) ".ps"))
  3129. (call-process "ps2pdf" nil nil nil
  3130. (expand-file-name
  3131. (concat (file-name-sans-extension file) ".ps"))
  3132. (expand-file-name file))
  3133. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3134. (message "PDF written to %s" file))
  3135. ((string= "ics" extension)
  3136. (require 'ox-icalendar)
  3137. (org-icalendar-export-current-agenda (expand-file-name file)))
  3138. (t
  3139. (let ((bs (buffer-string)))
  3140. (find-file file)
  3141. (erase-buffer)
  3142. (insert bs)
  3143. (save-buffer 0)
  3144. (kill-buffer (current-buffer))
  3145. (message "Plain text written to %s" file))))))))
  3146. (set-buffer (or agenda-bufname
  3147. (and (called-interactively-p 'any) (buffer-name))
  3148. org-agenda-buffer-name)))
  3149. (when open (org-open-file file)))
  3150. (defun org-agenda-remove-marked-text (property &optional value)
  3151. "Delete all text marked with VALUE of PROPERTY.
  3152. VALUE defaults to t."
  3153. (let (beg)
  3154. (setq value (or value t))
  3155. (while (setq beg (text-property-any (point-min) (point-max)
  3156. property value))
  3157. (delete-region
  3158. beg (or (next-single-property-change beg property)
  3159. (point-max))))))
  3160. (defun org-agenda-add-entry-text ()
  3161. "Add entry text to agenda lines.
  3162. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3163. entry text following headings shown in the agenda.
  3164. Drawers will be excluded, also the line with scheduling/deadline info."
  3165. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3166. (not (bound-and-true-p org-mobile-creating-agendas)))
  3167. (let (m txt)
  3168. (goto-char (point-min))
  3169. (while (not (eobp))
  3170. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3171. (beginning-of-line 2)
  3172. (setq txt (org-agenda-get-some-entry-text
  3173. m org-agenda-add-entry-text-maxlines " > "))
  3174. (end-of-line 1)
  3175. (if (string-match "\\S-" txt)
  3176. (insert "\n" txt)
  3177. (or (eobp) (forward-char 1))))))))
  3178. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3179. &rest keep)
  3180. "Extract entry text from MARKER, at most N-LINES lines.
  3181. This will ignore drawers etc, just get the text.
  3182. If INDENT is given, prefix every line with this string. If KEEP is
  3183. given, it is a list of symbols, defining stuff that should not be
  3184. removed from the entry content. Currently only `planning' is allowed here."
  3185. (let (txt drawer-re kwd-time-re ind)
  3186. (save-excursion
  3187. (with-current-buffer (marker-buffer marker)
  3188. (if (not (derived-mode-p 'org-mode))
  3189. (setq txt "")
  3190. (org-with-wide-buffer
  3191. (goto-char marker)
  3192. (end-of-line 1)
  3193. (setq txt (buffer-substring
  3194. (min (1+ (point)) (point-max))
  3195. (progn (outline-next-heading) (point)))
  3196. drawer-re org-drawer-regexp
  3197. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3198. ".*\n?"))
  3199. (with-temp-buffer
  3200. (insert txt)
  3201. (when org-agenda-add-entry-text-descriptive-links
  3202. (goto-char (point-min))
  3203. (while (org-activate-links (point-max))
  3204. (add-text-properties (match-beginning 0) (match-end 0)
  3205. '(face org-link))))
  3206. (goto-char (point-min))
  3207. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3208. (set-text-properties (match-beginning 0) (match-end 0)
  3209. nil))
  3210. (goto-char (point-min))
  3211. (while (re-search-forward drawer-re nil t)
  3212. (delete-region
  3213. (match-beginning 0)
  3214. (progn (re-search-forward
  3215. "^[ \t]*:END:.*\n?" nil 'move)
  3216. (point))))
  3217. (unless (member 'planning keep)
  3218. (goto-char (point-min))
  3219. (while (re-search-forward kwd-time-re nil t)
  3220. (replace-match "")))
  3221. (goto-char (point-min))
  3222. (when org-agenda-entry-text-exclude-regexps
  3223. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3224. (while (setq re (pop re-list))
  3225. (goto-char (point-min))
  3226. (while (re-search-forward re nil t)
  3227. (replace-match "")))))
  3228. (goto-char (point-max))
  3229. (skip-chars-backward " \t\n")
  3230. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3231. ;; find and remove min common indentation
  3232. (goto-char (point-min))
  3233. (untabify (point-min) (point-max))
  3234. (setq ind (current-indentation))
  3235. (while (not (eobp))
  3236. (unless (looking-at "[ \t]*$")
  3237. (setq ind (min ind (current-indentation))))
  3238. (beginning-of-line 2))
  3239. (goto-char (point-min))
  3240. (while (not (eobp))
  3241. (unless (looking-at "[ \t]*$")
  3242. (move-to-column ind)
  3243. (delete-region (point-at-bol) (point)))
  3244. (beginning-of-line 2))
  3245. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3246. (goto-char (point-min))
  3247. (when indent
  3248. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3249. (replace-match indent t t)))
  3250. (goto-char (point-min))
  3251. (while (looking-at "[ \t]*\n") (replace-match ""))
  3252. (goto-char (point-max))
  3253. (when (> (org-current-line)
  3254. n-lines)
  3255. (org-goto-line (1+ n-lines))
  3256. (backward-char 1))
  3257. (setq txt (buffer-substring (point-min) (point))))))))
  3258. txt))
  3259. (defun org-check-for-org-mode ()
  3260. "Make sure current buffer is in Org mode. Error if not."
  3261. (or (derived-mode-p 'org-mode)
  3262. (error "Cannot execute Org agenda command on buffer in %s"
  3263. major-mode)))
  3264. ;;; Agenda prepare and finalize
  3265. (defvar org-agenda-multi nil) ; dynamically scoped
  3266. (defvar org-agenda-pre-window-conf nil)
  3267. (defvar org-agenda-columns-active nil)
  3268. (defvar org-agenda-name nil)
  3269. (defvar org-agenda-tag-filter nil)
  3270. (defvar org-agenda-category-filter nil)
  3271. (defvar org-agenda-regexp-filter nil)
  3272. (defvar org-agenda-effort-filter nil)
  3273. (defvar org-agenda-top-headline-filter nil)
  3274. (defvar org-agenda-tag-filter-preset nil
  3275. "A preset of the tags filter used for secondary agenda filtering.
  3276. This must be a list of strings, each string must be a single tag preceded
  3277. by \"+\" or \"-\".
  3278. This variable should not be set directly, but agenda custom commands can
  3279. bind it in the options section. The preset filter is a global property of
  3280. the entire agenda view. In a block agenda, it will not work reliably to
  3281. define a filter for one of the individual blocks. You need to set it in
  3282. the global options and expect it to be applied to the entire view.")
  3283. (defvar org-agenda-category-filter-preset nil
  3284. "A preset of the category filter used for secondary agenda filtering.
  3285. This must be a list of strings, each string must be a single category
  3286. preceded by \"+\" or \"-\".
  3287. This variable should not be set directly, but agenda custom commands can
  3288. bind it in the options section. The preset filter is a global property of
  3289. the entire agenda view. In a block agenda, it will not work reliably to
  3290. define a filter for one of the individual blocks. You need to set it in
  3291. the global options and expect it to be applied to the entire view.")
  3292. (defvar org-agenda-regexp-filter-preset nil
  3293. "A preset of the regexp filter used for secondary agenda filtering.
  3294. This must be a list of strings, each string must be a single regexp
  3295. preceded by \"+\" or \"-\".
  3296. This variable should not be set directly, but agenda custom commands can
  3297. bind it in the options section. The preset filter is a global property of
  3298. the entire agenda view. In a block agenda, it will not work reliably to
  3299. define a filter for one of the individual blocks. You need to set it in
  3300. the global options and expect it to be applied to the entire view.")
  3301. (defvar org-agenda-effort-filter-preset nil
  3302. "A preset of the effort condition used for secondary agenda filtering.
  3303. This must be a list of strings, each string must be a single regexp
  3304. preceded by \"+\" or \"-\".
  3305. This variable should not be set directly, but agenda custom commands can
  3306. bind it in the options section. The preset filter is a global property of
  3307. the entire agenda view. In a block agenda, it will not work reliably to
  3308. define a filter for one of the individual blocks. You need to set it in
  3309. the global options and expect it to be applied to the entire view.")
  3310. (defun org-agenda-use-sticky-p ()
  3311. "Return non-nil if an agenda buffer named
  3312. `org-agenda-buffer-name' exists and should be shown instead of
  3313. generating a new one."
  3314. (and
  3315. ;; turned off by user
  3316. org-agenda-sticky
  3317. ;; For multi-agenda buffer already exists
  3318. (not org-agenda-multi)
  3319. ;; buffer found
  3320. (get-buffer org-agenda-buffer-name)
  3321. ;; C-u parameter is same as last call
  3322. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3323. (and
  3324. (equal current-prefix-arg
  3325. org-agenda-last-prefix-arg)
  3326. ;; In case user turned stickiness on, while having existing
  3327. ;; Agenda buffer active, don't reuse that buffer, because it
  3328. ;; does not have org variables local
  3329. org-agenda-this-buffer-is-sticky))))
  3330. (defun org-agenda-prepare-window (abuf filter-alist)
  3331. "Setup agenda buffer in the window.
  3332. ABUF is the buffer for the agenda window.
  3333. FILTER-ALIST is an alist of filters we need to apply when
  3334. `org-agenda-persistent-filter' is non-nil."
  3335. (let* ((awin (get-buffer-window abuf)) wconf)
  3336. (cond
  3337. ((equal (current-buffer) abuf) nil)
  3338. (awin (select-window awin))
  3339. ((not (setq wconf (current-window-configuration))))
  3340. ((eq org-agenda-window-setup 'current-window)
  3341. (pop-to-buffer-same-window abuf))
  3342. ((eq org-agenda-window-setup 'other-window)
  3343. (org-switch-to-buffer-other-window abuf))
  3344. ((eq org-agenda-window-setup 'other-frame)
  3345. (switch-to-buffer-other-frame abuf))
  3346. ((eq org-agenda-window-setup 'only-window)
  3347. (delete-other-windows)
  3348. (pop-to-buffer-same-window abuf))
  3349. ((eq org-agenda-window-setup 'reorganize-frame)
  3350. (delete-other-windows)
  3351. (org-switch-to-buffer-other-window abuf)))
  3352. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3353. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3354. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3355. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3356. ;; Additional test in case agenda is invoked from within agenda
  3357. ;; buffer via elisp link.
  3358. (unless (equal (current-buffer) abuf)
  3359. (pop-to-buffer-same-window abuf))
  3360. (setq org-agenda-pre-window-conf
  3361. (or wconf org-agenda-pre-window-conf))))
  3362. (defun org-agenda-prepare (&optional name)
  3363. (let ((filter-alist (when org-agenda-persistent-filter
  3364. (with-current-buffer
  3365. (get-buffer-create org-agenda-buffer-name)
  3366. `((tag . ,org-agenda-tag-filter)
  3367. (re . ,org-agenda-regexp-filter)
  3368. (effort . ,org-agenda-effort-filter)
  3369. (cat . ,org-agenda-category-filter))))))
  3370. (if (org-agenda-use-sticky-p)
  3371. (progn
  3372. (put 'org-agenda-tag-filter :preset-filter nil)
  3373. (put 'org-agenda-category-filter :preset-filter nil)
  3374. (put 'org-agenda-regexp-filter :preset-filter nil)
  3375. ;; Popup existing buffer
  3376. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3377. filter-alist)
  3378. (message "Sticky Agenda buffer, use `r' to refresh")
  3379. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3380. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3381. (setq org-todo-keywords-for-agenda nil)
  3382. (put 'org-agenda-tag-filter :preset-filter
  3383. org-agenda-tag-filter-preset)
  3384. (put 'org-agenda-category-filter :preset-filter
  3385. org-agenda-category-filter-preset)
  3386. (put 'org-agenda-regexp-filter :preset-filter
  3387. org-agenda-regexp-filter-preset)
  3388. (put 'org-agenda-effort-filter :preset-filter
  3389. org-agenda-effort-filter-preset)
  3390. (if org-agenda-multi
  3391. (progn
  3392. (setq buffer-read-only nil)
  3393. (goto-char (point-max))
  3394. (unless (or (bobp) org-agenda-compact-blocks
  3395. (not org-agenda-block-separator))
  3396. (insert "\n"
  3397. (if (stringp org-agenda-block-separator)
  3398. org-agenda-block-separator
  3399. (make-string (window-width) org-agenda-block-separator))
  3400. "\n"))
  3401. (narrow-to-region (point) (point-max)))
  3402. (setq org-done-keywords-for-agenda nil)
  3403. ;; Setting any org variables that are in org-agenda-local-vars
  3404. ;; list need to be done after the prepare call
  3405. (org-agenda-prepare-window
  3406. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3407. (setq buffer-read-only nil)
  3408. (org-agenda-reset-markers)
  3409. (let ((inhibit-read-only t)) (erase-buffer))
  3410. (org-agenda-mode)
  3411. (setq org-agenda-buffer (current-buffer))
  3412. (setq org-agenda-contributing-files nil)
  3413. (setq org-agenda-columns-active nil)
  3414. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3415. (setq org-todo-keywords-for-agenda
  3416. (org-uniquify org-todo-keywords-for-agenda))
  3417. (setq org-done-keywords-for-agenda
  3418. (org-uniquify org-done-keywords-for-agenda))
  3419. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3420. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3421. (and name (not org-agenda-name)
  3422. (setq-local org-agenda-name name)))
  3423. (setq buffer-read-only nil))))
  3424. (defvar org-overriding-columns-format)
  3425. (defvar org-local-columns-format)
  3426. (defun org-agenda-finalize ()
  3427. "Finishing touch for the agenda buffer, called just before displaying it."
  3428. (unless org-agenda-multi
  3429. (save-excursion
  3430. (let ((inhibit-read-only t))
  3431. (goto-char (point-min))
  3432. (save-excursion
  3433. (while (org-activate-links (point-max))
  3434. (add-text-properties (match-beginning 0) (match-end 0)
  3435. '(face org-link))))
  3436. (unless (eq org-agenda-remove-tags t)
  3437. (org-agenda-align-tags))
  3438. (unless org-agenda-with-colors
  3439. (remove-text-properties (point-min) (point-max) '(face nil)))
  3440. (when (bound-and-true-p org-overriding-columns-format)
  3441. (setq-local org-local-columns-format
  3442. org-overriding-columns-format))
  3443. (when org-agenda-view-columns-initially
  3444. (org-agenda-columns))
  3445. (when org-agenda-fontify-priorities
  3446. (org-agenda-fontify-priorities))
  3447. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3448. (org-agenda-dim-blocked-tasks))
  3449. (org-agenda-mark-clocking-task)
  3450. (when org-agenda-entry-text-mode
  3451. (org-agenda-entry-text-hide)
  3452. (org-agenda-entry-text-show))
  3453. (when (and (featurep 'org-habit)
  3454. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3455. (org-habit-insert-consistency-graphs))
  3456. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3457. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3458. (and (listp org-agenda-show-inherited-tags)
  3459. (memq org-agenda-type org-agenda-show-inherited-tags))
  3460. (and (eq org-agenda-show-inherited-tags t)
  3461. (or (eq org-agenda-use-tag-inheritance t)
  3462. (and (listp org-agenda-use-tag-inheritance)
  3463. (not (memq org-agenda-type
  3464. org-agenda-use-tag-inheritance))))))
  3465. (let (mrk)
  3466. (save-excursion
  3467. (goto-char (point-min))
  3468. (while (equal (forward-line) 0)
  3469. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3470. (put-text-property (point-at-bol) (point-at-eol)
  3471. 'tags
  3472. (org-with-point-at mrk
  3473. (mapcar #'downcase (org-get-tags)))))))))
  3474. (run-hooks 'org-agenda-finalize-hook)
  3475. (when org-agenda-top-headline-filter
  3476. (org-agenda-filter-top-headline-apply
  3477. org-agenda-top-headline-filter))
  3478. (when org-agenda-tag-filter
  3479. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3480. (when (get 'org-agenda-tag-filter :preset-filter)
  3481. (org-agenda-filter-apply
  3482. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3483. (when org-agenda-category-filter
  3484. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3485. (when (get 'org-agenda-category-filter :preset-filter)
  3486. (org-agenda-filter-apply
  3487. (get 'org-agenda-category-filter :preset-filter) 'category))
  3488. (when org-agenda-regexp-filter
  3489. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3490. (when (get 'org-agenda-regexp-filter :preset-filter)
  3491. (org-agenda-filter-apply
  3492. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3493. (when org-agenda-effort-filter
  3494. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3495. (when (get 'org-agenda-effort-filter :preset-filter)
  3496. (org-agenda-filter-apply
  3497. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3498. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3499. (defun org-agenda-mark-clocking-task ()
  3500. "Mark the current clock entry in the agenda if it is present."
  3501. ;; We need to widen when `org-agenda-finalize' is called from
  3502. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3503. (when (bound-and-true-p org-clock-current-task)
  3504. (save-restriction
  3505. (widen)
  3506. (org-agenda-unmark-clocking-task)
  3507. (when (marker-buffer org-clock-hd-marker)
  3508. (save-excursion
  3509. (goto-char (point-min))
  3510. (let (s ov)
  3511. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3512. (goto-char s)
  3513. (when (equal (org-get-at-bol 'org-hd-marker)
  3514. org-clock-hd-marker)
  3515. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3516. (overlay-put ov 'type 'org-agenda-clocking)
  3517. (overlay-put ov 'face 'org-agenda-clocking)
  3518. (overlay-put ov 'help-echo
  3519. "The clock is running in this item")))))))))
  3520. (defun org-agenda-unmark-clocking-task ()
  3521. "Unmark the current clocking task."
  3522. (mapc (lambda (o)
  3523. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3524. (delete-overlay o)))
  3525. (overlays-in (point-min) (point-max))))
  3526. (defun org-agenda-fontify-priorities ()
  3527. "Make highest priority lines bold, and lowest italic."
  3528. (interactive)
  3529. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3530. (delete-overlay o)))
  3531. (overlays-in (point-min) (point-max)))
  3532. (save-excursion
  3533. (let (b e p ov h l)
  3534. (goto-char (point-min))
  3535. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3536. (setq h (or (get-char-property (point) 'org-highest-priority)
  3537. org-highest-priority)
  3538. l (or (get-char-property (point) 'org-lowest-priority)
  3539. org-lowest-priority)
  3540. p (string-to-char (match-string 1))
  3541. b (match-beginning 0)
  3542. e (if (eq org-agenda-fontify-priorities 'cookies)
  3543. (match-end 0)
  3544. (point-at-eol))
  3545. ov (make-overlay b e))
  3546. (overlay-put
  3547. ov 'face
  3548. (let ((special-face
  3549. (cond ((org-face-from-face-or-color
  3550. 'priority 'org-priority
  3551. (cdr (assoc p org-priority-faces))))
  3552. ((and (listp org-agenda-fontify-priorities)
  3553. (org-face-from-face-or-color
  3554. 'priority 'org-priority
  3555. (cdr (assoc p org-agenda-fontify-priorities)))))
  3556. ((equal p l) 'italic)
  3557. ((equal p h) 'bold))))
  3558. (if special-face (list special-face 'org-priority) 'org-priority)))
  3559. (overlay-put ov 'org-type 'org-priority)))))
  3560. (defvar org-depend-tag-blocked)
  3561. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3562. "Dim currently blocked TODOs in the agenda display.
  3563. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3564. dimming them."
  3565. (interactive "P")
  3566. (when (called-interactively-p 'interactive)
  3567. (message "Dim or hide blocked tasks..."))
  3568. (dolist (o (overlays-in (point-min) (point-max)))
  3569. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3570. (delete-overlay o)))
  3571. (save-excursion
  3572. (let ((inhibit-read-only t))
  3573. (goto-char (point-min))
  3574. (while (let ((pos (text-property-not-all
  3575. (point) (point-max) 'org-todo-blocked nil)))
  3576. (when pos (goto-char pos)))
  3577. (let* ((invisible (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3578. (ov (make-overlay (if invisible
  3579. (line-end-position 0)
  3580. (line-beginning-position))
  3581. (line-end-position))))
  3582. (if invisible
  3583. (overlay-put ov 'invisible t)
  3584. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3585. (overlay-put ov 'org-type 'org-blocked-todo))
  3586. (forward-line))))
  3587. (when (called-interactively-p 'interactive)
  3588. (message "Dim or hide blocked tasks...done")))
  3589. (defun org-agenda--mark-blocked-entry (entry)
  3590. "For ENTRY a string with the text property `org-hd-marker', if
  3591. the header at `org-hd-marker' is blocked according to
  3592. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3593. 'invisible and the header is not blocked by checkboxes, set the
  3594. text property `org-todo-blocked' to 'invisible, otherwise set it
  3595. to t."
  3596. (when (get-text-property 0 'todo-state entry)
  3597. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3598. (org-blocked-by-checkboxes nil)
  3599. ;; Necessary so that `org-entry-blocked-p' does not change
  3600. ;; the buffer.
  3601. (org-depend-tag-blocked nil))
  3602. (when entry-marker
  3603. (let ((blocked
  3604. (with-current-buffer (marker-buffer entry-marker)
  3605. (save-excursion
  3606. (goto-char entry-marker)
  3607. (org-entry-blocked-p)))))
  3608. (when blocked
  3609. (let ((really-invisible
  3610. (and (not org-blocked-by-checkboxes)
  3611. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3612. (put-text-property
  3613. 0 (length entry) 'org-todo-blocked
  3614. (if really-invisible 'invisible t)
  3615. entry)))))))
  3616. entry)
  3617. (defvar org-agenda-skip-function nil
  3618. "Function to be called at each match during agenda construction.
  3619. If this function returns nil, the current match should not be skipped.
  3620. Otherwise, the function must return a position from where the search
  3621. should be continued.
  3622. This may also be a Lisp form, it will be evaluated.
  3623. Never set this variable using `setq' or so, because then it will apply
  3624. to all future agenda commands. If you do want a global skipping condition,
  3625. use the option `org-agenda-skip-function-global' instead.
  3626. The correct usage for `org-agenda-skip-function' is to bind it with
  3627. `let' to scope it dynamically into the agenda-constructing command.
  3628. A good way to set it is through options in `org-agenda-custom-commands'.")
  3629. (defun org-agenda-skip ()
  3630. "Throw to `:skip' in places that should be skipped.
  3631. Also moves point to the end of the skipped region, so that search can
  3632. continue from there."
  3633. (let ((p (point-at-bol)) to)
  3634. (when (or
  3635. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3636. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3637. (get-text-property p :org-archived)
  3638. (org-end-of-subtree t))
  3639. (and org-agenda-skip-comment-trees
  3640. (get-text-property p :org-comment)
  3641. (org-end-of-subtree t))
  3642. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3643. (org-agenda-skip-eval org-agenda-skip-function)))
  3644. (goto-char to))
  3645. (org-in-src-block-p t))
  3646. (throw :skip t))))
  3647. (defun org-agenda-skip-eval (form)
  3648. "If FORM is a function or a list, call (or eval) it and return the result.
  3649. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3650. and match data are returned to the previous state no matter what these
  3651. functions do."
  3652. (let (fp)
  3653. (and form
  3654. (or (setq fp (functionp form))
  3655. (consp form))
  3656. (save-excursion
  3657. (save-match-data
  3658. (if fp
  3659. (funcall form)
  3660. (eval form)))))))
  3661. (defvar org-agenda-markers nil
  3662. "List of all currently active markers created by `org-agenda'.")
  3663. (defvar org-agenda-last-marker-time (float-time)
  3664. "Creation time of the last agenda marker.")
  3665. (defun org-agenda-new-marker (&optional pos)
  3666. "Return a new agenda marker.
  3667. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3668. these markers and resets them when they are no longer in use."
  3669. (let ((m (copy-marker (or pos (point)) t)))
  3670. (setq org-agenda-last-marker-time (float-time))
  3671. (if org-agenda-buffer
  3672. (with-current-buffer org-agenda-buffer
  3673. (push m org-agenda-markers))
  3674. (push m org-agenda-markers))
  3675. m))
  3676. (defun org-agenda-reset-markers ()
  3677. "Reset markers created by `org-agenda'."
  3678. (while org-agenda-markers
  3679. (move-marker (pop org-agenda-markers) nil)))
  3680. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3681. "Save relative positions of markers in region.
  3682. This check for agenda markers in all agenda buffers currently active."
  3683. (dolist (buf (buffer-list))
  3684. (with-current-buffer buf
  3685. (when (eq major-mode 'org-agenda-mode)
  3686. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3687. org-agenda-markers)))))
  3688. ;;; Entry text mode
  3689. (defun org-agenda-entry-text-show-here ()
  3690. "Add some text from the entry as context to the current line."
  3691. (let (m txt o)
  3692. (setq m (org-get-at-bol 'org-hd-marker))
  3693. (unless (marker-buffer m)
  3694. (error "No marker points to an entry here"))
  3695. (setq txt (concat "\n" (org-no-properties
  3696. (org-agenda-get-some-entry-text
  3697. m org-agenda-entry-text-maxlines
  3698. org-agenda-entry-text-leaders))))
  3699. (when (string-match "\\S-" txt)
  3700. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3701. (overlay-put o 'evaporate t)
  3702. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3703. (overlay-put o 'after-string txt))))
  3704. (defun org-agenda-entry-text-show ()
  3705. "Add entry context for all agenda lines."
  3706. (interactive)
  3707. (save-excursion
  3708. (goto-char (point-max))
  3709. (beginning-of-line 1)
  3710. (while (not (bobp))
  3711. (when (org-get-at-bol 'org-hd-marker)
  3712. (org-agenda-entry-text-show-here))
  3713. (beginning-of-line 0))))
  3714. (defun org-agenda-entry-text-hide ()
  3715. "Remove any shown entry context."
  3716. (mapc (lambda (o)
  3717. (when (eq (overlay-get o 'org-overlay-type)
  3718. 'agenda-entry-content)
  3719. (delete-overlay o)))
  3720. (overlays-in (point-min) (point-max))))
  3721. (defun org-agenda-get-day-face (date)
  3722. "Return the face DATE should be displayed with."
  3723. (cond ((and (functionp org-agenda-day-face-function)
  3724. (funcall org-agenda-day-face-function date)))
  3725. ((org-agenda-today-p date) 'org-agenda-date-today)
  3726. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3727. 'org-agenda-date-weekend)
  3728. (t 'org-agenda-date)))
  3729. (defvar org-agenda-show-log-scoped)
  3730. ;;; Agenda Daily/Weekly
  3731. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3732. "Start day for the agenda view.
  3733. Custom commands can set this variable in the options section.
  3734. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3735. input allowed when reading a date through the Org calendar.
  3736. See the docstring of `org-read-date' for details.")
  3737. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3738. (defvar org-arg-loc nil) ; local variable
  3739. (defvar org-agenda-buffer-tmp-name nil)
  3740. ;;;###autoload
  3741. (defun org-agenda-list (&optional arg start-day span with-hour)
  3742. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3743. The view will be for the current day or week, but from the overview buffer
  3744. you will be able to go to other days/weeks.
  3745. With a numeric prefix argument in an interactive call, the agenda will
  3746. span ARG days. Lisp programs should instead specify SPAN to change
  3747. the number of days. SPAN defaults to `org-agenda-span'.
  3748. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3749. given in `org-agenda-start-on-weekday'.
  3750. When WITH-HOUR is non-nil, only include scheduled and deadline
  3751. items if they have an hour specification like [h]h:mm."
  3752. (interactive "P")
  3753. (when org-agenda-overriding-arguments
  3754. (setq arg (car org-agenda-overriding-arguments)
  3755. start-day (nth 1 org-agenda-overriding-arguments)
  3756. span (nth 2 org-agenda-overriding-arguments)))
  3757. (when (and (integerp arg) (> arg 0))
  3758. (setq span arg arg nil))
  3759. (catch 'exit
  3760. (setq org-agenda-buffer-name
  3761. (or org-agenda-buffer-tmp-name
  3762. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3763. (when org-agenda-sticky
  3764. (cond ((and org-keys (stringp org-match))
  3765. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3766. (org-keys
  3767. (format "*Org Agenda(%s)*" org-keys))
  3768. (t "*Org Agenda(a)*")))
  3769. "*Org Agenda*"))
  3770. (org-agenda-prepare "Day/Week")
  3771. (setq start-day (or start-day org-agenda-start-day))
  3772. (when (stringp start-day)
  3773. ;; Convert to an absolute day number
  3774. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3775. (org-compile-prefix-format 'agenda)
  3776. (org-set-sorting-strategy 'agenda)
  3777. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3778. (today (org-today))
  3779. (sd (or start-day today))
  3780. (ndays (org-agenda-span-to-ndays span sd))
  3781. (org-agenda-start-on-weekday
  3782. (and (or (eq ndays 7) (eq ndays 14))
  3783. org-agenda-start-on-weekday))
  3784. (thefiles (org-agenda-files nil 'ifmode))
  3785. (files thefiles)
  3786. (start (if (or (null org-agenda-start-on-weekday)
  3787. (< ndays 7))
  3788. sd
  3789. (let* ((nt (calendar-day-of-week
  3790. (calendar-gregorian-from-absolute sd)))
  3791. (n1 org-agenda-start-on-weekday)
  3792. (d (- nt n1)))
  3793. (- sd (+ (if (< d 0) 7 0) d)))))
  3794. (day-numbers (list start))
  3795. (day-cnt 0)
  3796. (inhibit-redisplay (not debug-on-error))
  3797. (org-agenda-show-log-scoped org-agenda-show-log)
  3798. s e rtn rtnall file date d start-pos end-pos todayp
  3799. clocktable-start clocktable-end filter)
  3800. (setq org-agenda-redo-command
  3801. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3802. (dotimes (n (1- ndays))
  3803. (push (1+ (car day-numbers)) day-numbers))
  3804. (setq day-numbers (nreverse day-numbers))
  3805. (setq clocktable-start (car day-numbers)
  3806. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3807. (setq-local org-starting-day (car day-numbers))
  3808. (setq-local org-arg-loc arg)
  3809. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3810. (unless org-agenda-compact-blocks
  3811. (let* ((d1 (car day-numbers))
  3812. (d2 (org-last day-numbers))
  3813. (w1 (org-days-to-iso-week d1))
  3814. (w2 (org-days-to-iso-week d2)))
  3815. (setq s (point))
  3816. (org-agenda--insert-overriding-header
  3817. (concat (org-agenda-span-name span)
  3818. "-agenda"
  3819. (cond ((<= 350 (- d2 d1)) "")
  3820. ((= w1 w2) (format " (W%02d)" w1))
  3821. (t (format " (W%02d-W%02d)" w1 w2)))
  3822. ":\n")))
  3823. ;; Add properties if we actually inserted a header.
  3824. (when (> (point) s)
  3825. (add-text-properties s (1- (point))
  3826. (list 'face 'org-agenda-structure
  3827. 'org-date-line t))
  3828. (org-agenda-mark-header-line s)))
  3829. (while (setq d (pop day-numbers))
  3830. (setq date (calendar-gregorian-from-absolute d)
  3831. s (point))
  3832. (if (or (setq todayp (= d today))
  3833. (and (not start-pos) (= d sd)))
  3834. (setq start-pos (point))
  3835. (when (and start-pos (not end-pos))
  3836. (setq end-pos (point))))
  3837. (setq files thefiles
  3838. rtnall nil)
  3839. (while (setq file (pop files))
  3840. (catch 'nextfile
  3841. (org-check-agenda-file file)
  3842. (let ((org-agenda-entry-types org-agenda-entry-types))
  3843. ;; Starred types override non-starred equivalents
  3844. (when (member :deadline* org-agenda-entry-types)
  3845. (setq org-agenda-entry-types
  3846. (delq :deadline org-agenda-entry-types)))
  3847. (when (member :scheduled* org-agenda-entry-types)
  3848. (setq org-agenda-entry-types
  3849. (delq :scheduled org-agenda-entry-types)))
  3850. ;; Honor with-hour
  3851. (when with-hour
  3852. (when (member :deadline org-agenda-entry-types)
  3853. (setq org-agenda-entry-types
  3854. (delq :deadline org-agenda-entry-types))
  3855. (push :deadline* org-agenda-entry-types))
  3856. (when (member :scheduled org-agenda-entry-types)
  3857. (setq org-agenda-entry-types
  3858. (delq :scheduled org-agenda-entry-types))
  3859. (push :scheduled* org-agenda-entry-types)))
  3860. (unless org-agenda-include-deadlines
  3861. (setq org-agenda-entry-types
  3862. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3863. (cond
  3864. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3865. (setq rtn (org-agenda-get-day-entries
  3866. file date :closed)))
  3867. (org-agenda-show-log-scoped
  3868. (setq rtn (apply 'org-agenda-get-day-entries
  3869. file date
  3870. (append '(:closed) org-agenda-entry-types))))
  3871. (t
  3872. (setq rtn (apply 'org-agenda-get-day-entries
  3873. file date
  3874. org-agenda-entry-types)))))
  3875. (setq rtnall (append rtnall rtn)))) ;; all entries
  3876. (when org-agenda-include-diary
  3877. (let ((org-agenda-search-headline-for-time t))
  3878. (require 'diary-lib)
  3879. (setq rtn (org-get-entries-from-diary date))
  3880. (setq rtnall (append rtnall rtn))))
  3881. (when (or rtnall org-agenda-show-all-dates)
  3882. (setq day-cnt (1+ day-cnt))
  3883. (insert
  3884. (if (stringp org-agenda-format-date)
  3885. (format-time-string org-agenda-format-date
  3886. (org-time-from-absolute date))
  3887. (funcall org-agenda-format-date date))
  3888. "\n")
  3889. (put-text-property s (1- (point)) 'face
  3890. (org-agenda-get-day-face date))
  3891. (put-text-property s (1- (point)) 'org-date-line t)
  3892. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3893. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3894. (when todayp
  3895. (put-text-property s (1- (point)) 'org-today t))
  3896. (setq rtnall
  3897. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3898. (when rtnall (insert ;; all entries
  3899. (org-agenda-finalize-entries rtnall 'agenda)
  3900. "\n"))
  3901. (put-text-property s (1- (point)) 'day d)
  3902. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  3903. (when (and org-agenda-clockreport-mode clocktable-start)
  3904. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3905. ;; the above line is to ensure the restricted range!
  3906. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3907. tbl)
  3908. (setq p (org-plist-delete p :block))
  3909. (setq p (plist-put p :tstart clocktable-start))
  3910. (setq p (plist-put p :tend clocktable-end))
  3911. (setq p (plist-put p :scope 'agenda))
  3912. (setq tbl (apply 'org-clock-get-clocktable p))
  3913. (insert tbl)))
  3914. (goto-char (point-min))
  3915. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3916. (unless (or (not (get-buffer-window))
  3917. (and (pos-visible-in-window-p (point-min))
  3918. (pos-visible-in-window-p (point-max))))
  3919. (goto-char (1- (point-max)))
  3920. (recenter -1)
  3921. (when (not (pos-visible-in-window-p (or start-pos 1)))
  3922. (goto-char (or start-pos 1))
  3923. (recenter 1)))
  3924. (goto-char (or start-pos 1))
  3925. (add-text-properties (point-min) (point-max)
  3926. `(org-agenda-type agenda
  3927. org-last-args (,arg ,start-day ,span)
  3928. org-redo-cmd ,org-agenda-redo-command
  3929. org-series-cmd ,org-cmd))
  3930. (when (eq org-agenda-show-log-scoped 'clockcheck)
  3931. (org-agenda-show-clocking-issues))
  3932. (org-agenda-finalize)
  3933. (setq buffer-read-only t)
  3934. (message ""))))
  3935. (defun org-agenda-ndays-to-span (n)
  3936. "Return a span symbol for a span of N days, or N if none matches."
  3937. (cond ((symbolp n) n)
  3938. ((= n 1) 'day)
  3939. ((= n 7) 'week)
  3940. ((= n 14) 'fortnight)
  3941. (t n)))
  3942. (defun org-agenda-span-to-ndays (span &optional start-day)
  3943. "Return ndays from SPAN, possibly starting at START-DAY.
  3944. START-DAY is an absolute time value."
  3945. (cond ((numberp span) span)
  3946. ((eq span 'day) 1)
  3947. ((eq span 'week) 7)
  3948. ((eq span 'fortnight) 14)
  3949. ((eq span 'month)
  3950. (let ((date (calendar-gregorian-from-absolute start-day)))
  3951. (calendar-last-day-of-month (car date) (cl-caddr date))))
  3952. ((eq span 'year)
  3953. (let ((date (calendar-gregorian-from-absolute start-day)))
  3954. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  3955. (defun org-agenda-span-name (span)
  3956. "Return a SPAN name."
  3957. (if (null span)
  3958. ""
  3959. (if (symbolp span)
  3960. (capitalize (symbol-name span))
  3961. (format "%d days" span))))
  3962. ;;; Agenda word search
  3963. (defvar org-agenda-search-history nil)
  3964. (defvar org-search-syntax-table nil
  3965. "Special syntax table for Org search.
  3966. In this table, we have single quotes not as word constituents, to
  3967. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3968. (defvar org-mode-syntax-table) ; From org.el
  3969. (defun org-search-syntax-table ()
  3970. (unless org-search-syntax-table
  3971. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3972. (modify-syntax-entry ?' "." org-search-syntax-table)
  3973. (modify-syntax-entry ?` "." org-search-syntax-table))
  3974. org-search-syntax-table)
  3975. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3976. ;;;###autoload
  3977. (defun org-search-view (&optional todo-only string edit-at)
  3978. "Show all entries that contain a phrase or words or regular expressions.
  3979. With optional prefix argument TODO-ONLY, only consider entries that are
  3980. TODO entries. The argument STRING can be used to pass a default search
  3981. string into this function. If EDIT-AT is non-nil, it means that the
  3982. user should get a chance to edit this string, with cursor at position
  3983. EDIT-AT.
  3984. The search string can be viewed either as a phrase that should be found as
  3985. is, or it can be broken into a number of snippets, each of which must match
  3986. in a Boolean way to select an entry. The default depends on the variable
  3987. `org-agenda-search-view-always-boolean'.
  3988. Even if this is turned off (the default) you can always switch to
  3989. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3990. The default is a direct search of the whole phrase, where each space in
  3991. the search string can expand to an arbitrary amount of whitespace,
  3992. including newlines.
  3993. If using a Boolean search, the search string is split on whitespace and
  3994. each snippet is searched separately, with logical AND to select an entry.
  3995. Words prefixed with a minus must *not* occur in the entry. Words without
  3996. a prefix or prefixed with a plus must occur in the entry. Matching is
  3997. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3998. match whole words, not parts of a word) if
  3999. `org-agenda-search-view-force-full-words' is set (default is nil).
  4000. Boolean search snippets enclosed by curly braces are interpreted as
  4001. regular expressions that must or (when preceded with \"-\") must not
  4002. match in the entry. Snippets enclosed into double quotes will be taken
  4003. as a whole, to include whitespace.
  4004. - If the search string starts with an asterisk, search only in headlines.
  4005. - If (possibly after the leading star) the search string starts with an
  4006. exclamation mark, this also means to look at TODO entries only, an effect
  4007. that can also be achieved with a prefix argument.
  4008. - If (possibly after star and exclamation mark) the search string starts
  4009. with a colon, this will mean that the (non-regexp) snippets of the
  4010. Boolean search must match as full words.
  4011. This command searches the agenda files, and in addition the files
  4012. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4013. is active."
  4014. (interactive "P")
  4015. (when org-agenda-overriding-arguments
  4016. (setq todo-only (car org-agenda-overriding-arguments)
  4017. string (nth 1 org-agenda-overriding-arguments)
  4018. edit-at (nth 2 org-agenda-overriding-arguments)))
  4019. (let* ((props (list 'face nil
  4020. 'done-face 'org-agenda-done
  4021. 'org-not-done-regexp org-not-done-regexp
  4022. 'org-todo-regexp org-todo-regexp
  4023. 'org-complex-heading-regexp org-complex-heading-regexp
  4024. 'mouse-face 'highlight
  4025. 'help-echo (format "mouse-2 or RET jump to location")))
  4026. (full-words org-agenda-search-view-force-full-words)
  4027. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4028. regexp rtn rtnall files file pos inherited-tags
  4029. marker category level tags c neg re boolean
  4030. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4031. (unless (and (not edit-at)
  4032. (stringp string)
  4033. (string-match "\\S-" string))
  4034. (setq string (read-string
  4035. (if org-agenda-search-view-always-boolean
  4036. "[+-]Word/{Regexp} ...: "
  4037. "Phrase or [+-]Word/{Regexp} ...: ")
  4038. (cond
  4039. ((integerp edit-at) (cons string edit-at))
  4040. (edit-at string))
  4041. 'org-agenda-search-history)))
  4042. (catch 'exit
  4043. (when org-agenda-sticky
  4044. (setq org-agenda-buffer-name
  4045. (if (stringp string)
  4046. (format "*Org Agenda(%s:%s)*"
  4047. (or org-keys (or (and todo-only "S") "s")) string)
  4048. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4049. (org-agenda-prepare "SEARCH")
  4050. (org-compile-prefix-format 'search)
  4051. (org-set-sorting-strategy 'search)
  4052. (setq org-agenda-redo-command
  4053. (list 'org-search-view (if todo-only t nil)
  4054. (list 'if 'current-prefix-arg nil string)))
  4055. (setq org-agenda-query-string string)
  4056. (if (equal (string-to-char string) ?*)
  4057. (setq hdl-only t
  4058. words (substring string 1))
  4059. (setq words string))
  4060. (when (equal (string-to-char words) ?!)
  4061. (setq todo-only t
  4062. words (substring words 1)))
  4063. (when (equal (string-to-char words) ?:)
  4064. (setq full-words t
  4065. words (substring words 1)))
  4066. (when (or org-agenda-search-view-always-boolean
  4067. (member (string-to-char words) '(?- ?+ ?\{)))
  4068. (setq boolean t))
  4069. (setq words (split-string words))
  4070. (let (www w)
  4071. (while (setq w (pop words))
  4072. (while (and (string-match "\\\\\\'" w) words)
  4073. (setq w (concat (substring w 0 -1) " " (pop words))))
  4074. (push w www))
  4075. (setq words (nreverse www) www nil)
  4076. (while (setq w (pop words))
  4077. (when (and (string-match "\\`[-+]?{" w)
  4078. (not (string-match "}\\'" w)))
  4079. (while (and words (not (string-match "}\\'" (car words))))
  4080. (setq w (concat w " " (pop words))))
  4081. (setq w (concat w " " (pop words))))
  4082. (push w www))
  4083. (setq words (nreverse www)))
  4084. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4085. (when boolean
  4086. (let (wds w)
  4087. (while (setq w (pop words))
  4088. (when (or (equal (substring w 0 1) "\"")
  4089. (and (> (length w) 1)
  4090. (member (substring w 0 1) '("+" "-"))
  4091. (equal (substring w 1 2) "\"")))
  4092. (while (and words (not (equal (substring w -1) "\"")))
  4093. (setq w (concat w " " (pop words)))))
  4094. (and (string-match "\\`\\([-+]?\\)\"" w)
  4095. (setq w (replace-match "\\1" nil nil w)))
  4096. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4097. (push w wds))
  4098. (setq words (nreverse wds))))
  4099. (if boolean
  4100. (mapc (lambda (w)
  4101. (setq c (string-to-char w))
  4102. (if (equal c ?-)
  4103. (setq neg t w (substring w 1))
  4104. (if (equal c ?+)
  4105. (setq neg nil w (substring w 1))
  4106. (setq neg nil)))
  4107. (if (string-match "\\`{.*}\\'" w)
  4108. (setq re (substring w 1 -1))
  4109. (if full-words
  4110. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4111. (setq re (regexp-quote (downcase w)))))
  4112. (if neg (push re regexps-) (push re regexps+)))
  4113. words)
  4114. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4115. regexps+))
  4116. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4117. (if (not regexps+)
  4118. (setq regexp org-outline-regexp-bol)
  4119. (setq regexp (pop regexps+))
  4120. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4121. regexp))))
  4122. (setq files (org-agenda-files nil 'ifmode))
  4123. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4124. ;; restriction.
  4125. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4126. (pop org-agenda-text-search-extra-files)
  4127. (unless (get 'org-agenda-files 'org-restrict)
  4128. (setq files (org-add-archive-files files))))
  4129. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4130. ;; non-existent ones.
  4131. (setq files (cl-remove-duplicates
  4132. (append files org-agenda-text-search-extra-files)
  4133. :test (lambda (a b)
  4134. (and (file-exists-p a)
  4135. (file-exists-p b)
  4136. (file-equal-p a b))))
  4137. rtnall nil)
  4138. (while (setq file (pop files))
  4139. (setq ee nil)
  4140. (catch 'nextfile
  4141. (org-check-agenda-file file)
  4142. (setq buffer (if (file-exists-p file)
  4143. (org-get-agenda-file-buffer file)
  4144. (error "No such file %s" file)))
  4145. (unless buffer
  4146. ;; If file does not exist, make sure an error message is sent
  4147. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4148. file))))
  4149. (with-current-buffer buffer
  4150. (with-syntax-table (org-search-syntax-table)
  4151. (unless (derived-mode-p 'org-mode)
  4152. (error "Agenda file %s is not in Org mode" file))
  4153. (let ((case-fold-search t))
  4154. (save-excursion
  4155. (save-restriction
  4156. (if (eq buffer org-agenda-restrict)
  4157. (narrow-to-region org-agenda-restrict-begin
  4158. org-agenda-restrict-end)
  4159. (widen))
  4160. (goto-char (point-min))
  4161. (unless (or (org-at-heading-p)
  4162. (outline-next-heading))
  4163. (throw 'nextfile t))
  4164. (goto-char (max (point-min) (1- (point))))
  4165. (while (re-search-forward regexp nil t)
  4166. (org-back-to-heading t)
  4167. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4168. (> (org-reduced-level (org-outline-level))
  4169. org-agenda-search-view-max-outline-level)
  4170. (forward-line -1)
  4171. (org-back-to-heading t)))
  4172. (skip-chars-forward "* ")
  4173. (setq beg (point-at-bol)
  4174. beg1 (point)
  4175. end (progn
  4176. (outline-next-heading)
  4177. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4178. (> (org-reduced-level (org-outline-level))
  4179. org-agenda-search-view-max-outline-level)
  4180. (forward-line 1)
  4181. (outline-next-heading)))
  4182. (point)))
  4183. (catch :skip
  4184. (goto-char beg)
  4185. (org-agenda-skip)
  4186. (setq str (buffer-substring-no-properties
  4187. (point-at-bol)
  4188. (if hdl-only (point-at-eol) end)))
  4189. (mapc (lambda (wr) (when (string-match wr str)
  4190. (goto-char (1- end))
  4191. (throw :skip t)))
  4192. regexps-)
  4193. (mapc (lambda (wr) (unless (string-match wr str)
  4194. (goto-char (1- end))
  4195. (throw :skip t)))
  4196. (if todo-only
  4197. (cons (concat "^\\*+[ \t]+"
  4198. org-not-done-regexp)
  4199. regexps+)
  4200. regexps+))
  4201. (goto-char beg)
  4202. (setq marker (org-agenda-new-marker (point))
  4203. category (org-get-category)
  4204. level (make-string (org-reduced-level (org-outline-level)) ? )
  4205. inherited-tags
  4206. (or (eq org-agenda-show-inherited-tags 'always)
  4207. (and (listp org-agenda-show-inherited-tags)
  4208. (memq 'todo org-agenda-show-inherited-tags))
  4209. (and (eq org-agenda-show-inherited-tags t)
  4210. (or (eq org-agenda-use-tag-inheritance t)
  4211. (memq 'todo org-agenda-use-tag-inheritance))))
  4212. tags (org-get-tags nil (not inherited-tags))
  4213. txt (org-agenda-format-item
  4214. ""
  4215. (buffer-substring-no-properties
  4216. beg1 (point-at-eol))
  4217. level category tags t))
  4218. (org-add-props txt props
  4219. 'org-marker marker 'org-hd-marker marker
  4220. 'org-todo-regexp org-todo-regexp
  4221. 'level level
  4222. 'org-complex-heading-regexp org-complex-heading-regexp
  4223. 'priority 1000
  4224. 'type "search")
  4225. (push txt ee)
  4226. (goto-char (1- end))))))))))
  4227. (setq rtn (nreverse ee))
  4228. (setq rtnall (append rtnall rtn)))
  4229. (org-agenda--insert-overriding-header
  4230. (with-temp-buffer
  4231. (insert "Search words: ")
  4232. (add-text-properties (point-min) (1- (point))
  4233. (list 'face 'org-agenda-structure))
  4234. (setq pos (point))
  4235. (insert string "\n")
  4236. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4237. (setq pos (point))
  4238. (unless org-agenda-multi
  4239. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4240. Press `\\[org-agenda-manipulate-query-add]', \
  4241. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4242. `\\[org-agenda-manipulate-query-add-re]', \
  4243. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4244. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4245. (add-text-properties pos (1- (point))
  4246. (list 'face 'org-agenda-structure)))
  4247. (buffer-string)))
  4248. (org-agenda-mark-header-line (point-min))
  4249. (when rtnall
  4250. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4251. (goto-char (point-min))
  4252. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4253. (add-text-properties (point-min) (point-max)
  4254. `(org-agenda-type search
  4255. org-last-args (,todo-only ,string ,edit-at)
  4256. org-redo-cmd ,org-agenda-redo-command
  4257. org-series-cmd ,org-cmd))
  4258. (org-agenda-finalize)
  4259. (setq buffer-read-only t))))
  4260. ;;; Agenda TODO list
  4261. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4262. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4263. (concat
  4264. (if (or (equal keywords "ALL") (not keywords))
  4265. (propertize "ALL" 'face 'warning)
  4266. (mapconcat
  4267. (lambda (kw)
  4268. (propertize kw 'face (org-get-todo-face kw)))
  4269. (org-split-string keywords "|")
  4270. "|"))
  4271. "\n"))
  4272. (defvar org-select-this-todo-keyword nil)
  4273. (defvar org-last-arg nil)
  4274. ;;;###autoload
  4275. (defun org-todo-list (&optional arg)
  4276. "Show all (not done) TODO entries from all agenda file in a single list.
  4277. The prefix arg can be used to select a specific TODO keyword and limit
  4278. the list to these. When using `\\[universal-argument]', you will be prompted
  4279. for a keyword. A numeric prefix directly selects the Nth keyword in
  4280. `org-todo-keywords-1'."
  4281. (interactive "P")
  4282. (when org-agenda-overriding-arguments
  4283. (setq arg org-agenda-overriding-arguments))
  4284. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4285. (let* ((today (org-today))
  4286. (date (calendar-gregorian-from-absolute today))
  4287. (completion-ignore-case t)
  4288. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4289. (catch 'exit
  4290. (when org-agenda-sticky
  4291. (setq org-agenda-buffer-name
  4292. (if (stringp org-select-this-todo-keyword)
  4293. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4294. org-select-this-todo-keyword)
  4295. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4296. (org-agenda-prepare "TODO")
  4297. (setq kwds org-todo-keywords-for-agenda
  4298. org-select-this-todo-keyword (if (stringp arg) arg
  4299. (and (integerp arg)
  4300. (> arg 0)
  4301. (nth (1- arg) kwds))))
  4302. (when (equal arg '(4))
  4303. (setq org-select-this-todo-keyword
  4304. (completing-read "Keyword (or KWD1|K2D2|...): "
  4305. (mapcar #'list kwds) nil nil)))
  4306. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4307. (org-compile-prefix-format 'todo)
  4308. (org-set-sorting-strategy 'todo)
  4309. (setq org-agenda-redo-command
  4310. `(org-todo-list (or (and (numberp current-prefix-arg)
  4311. current-prefix-arg)
  4312. ,org-select-this-todo-keyword
  4313. current-prefix-arg ,arg)))
  4314. (setq files (org-agenda-files nil 'ifmode)
  4315. rtnall nil)
  4316. (while (setq file (pop files))
  4317. (catch 'nextfile
  4318. (org-check-agenda-file file)
  4319. (setq rtn (org-agenda-get-day-entries file date :todo))
  4320. (setq rtnall (append rtnall rtn))))
  4321. (org-agenda--insert-overriding-header
  4322. (with-temp-buffer
  4323. (insert "Global list of TODO items of type: ")
  4324. (add-text-properties (point-min) (1- (point))
  4325. (list 'face 'org-agenda-structure
  4326. 'short-heading
  4327. (concat "ToDo: "
  4328. (or org-select-this-todo-keyword "ALL"))))
  4329. (org-agenda-mark-header-line (point-min))
  4330. (insert (org-agenda-propertize-selected-todo-keywords
  4331. org-select-this-todo-keyword))
  4332. (setq pos (point))
  4333. (unless org-agenda-multi
  4334. (insert (substitute-command-keys "Press \
  4335. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4336. to search again: (0)[ALL]"))
  4337. (let ((n 0))
  4338. (dolist (k kwds)
  4339. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4340. (when (> (+ (current-column) (string-width s) 1) (window-width))
  4341. (insert "\n "))
  4342. (insert " " s))))
  4343. (insert "\n"))
  4344. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure))
  4345. (buffer-string)))
  4346. (org-agenda-mark-header-line (point-min))
  4347. (when rtnall
  4348. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4349. (goto-char (point-min))
  4350. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4351. (add-text-properties (point-min) (point-max)
  4352. `(org-agenda-type todo
  4353. org-last-args ,arg
  4354. org-redo-cmd ,org-agenda-redo-command
  4355. org-series-cmd ,org-cmd))
  4356. (org-agenda-finalize)
  4357. (setq buffer-read-only t))))
  4358. ;;; Agenda tags match
  4359. ;;;###autoload
  4360. (defun org-tags-view (&optional todo-only match)
  4361. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4362. The prefix arg TODO-ONLY limits the search to TODO entries."
  4363. (interactive "P")
  4364. (when org-agenda-overriding-arguments
  4365. (setq todo-only (car org-agenda-overriding-arguments)
  4366. match (nth 1 org-agenda-overriding-arguments)))
  4367. (let* ((org-tags-match-list-sublevels
  4368. org-tags-match-list-sublevels)
  4369. (completion-ignore-case t)
  4370. (org--matcher-tags-todo-only todo-only)
  4371. rtn rtnall files file pos matcher
  4372. buffer)
  4373. (when (and (stringp match) (not (string-match "\\S-" match)))
  4374. (setq match nil))
  4375. (catch 'exit
  4376. ;; TODO: this code is repeated a lot...
  4377. (when org-agenda-sticky
  4378. (setq org-agenda-buffer-name
  4379. (if (stringp match)
  4380. (format "*Org Agenda(%s:%s)*"
  4381. (or org-keys (or (and todo-only "M") "m")) match)
  4382. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4383. (setq matcher (org-make-tags-matcher match))
  4384. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4385. ;; expanding tags within `org-make-tags-matcher'
  4386. (org-agenda-prepare (concat "TAGS " match))
  4387. (setq match (car matcher)
  4388. matcher (cdr matcher))
  4389. (org-compile-prefix-format 'tags)
  4390. (org-set-sorting-strategy 'tags)
  4391. (setq org-agenda-query-string match)
  4392. (setq org-agenda-redo-command
  4393. (list 'org-tags-view
  4394. `(quote ,org--matcher-tags-todo-only)
  4395. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4396. (setq files (org-agenda-files nil 'ifmode)
  4397. rtnall nil)
  4398. (while (setq file (pop files))
  4399. (catch 'nextfile
  4400. (org-check-agenda-file file)
  4401. (setq buffer (if (file-exists-p file)
  4402. (org-get-agenda-file-buffer file)
  4403. (error "No such file %s" file)))
  4404. (if (not buffer)
  4405. ;; If file does not exist, error message to agenda
  4406. (setq rtn (list
  4407. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4408. rtnall (append rtnall rtn))
  4409. (with-current-buffer buffer
  4410. (unless (derived-mode-p 'org-mode)
  4411. (error "Agenda file %s is not in Org mode" file))
  4412. (save-excursion
  4413. (save-restriction
  4414. (if (eq buffer org-agenda-restrict)
  4415. (narrow-to-region org-agenda-restrict-begin
  4416. org-agenda-restrict-end)
  4417. (widen))
  4418. (setq rtn (org-scan-tags 'agenda
  4419. matcher
  4420. org--matcher-tags-todo-only))
  4421. (setq rtnall (append rtnall rtn))))))))
  4422. (org-agenda--insert-overriding-header
  4423. (with-temp-buffer
  4424. (insert "Headlines with TAGS match: ")
  4425. (add-text-properties (point-min) (1- (point))
  4426. (list 'face 'org-agenda-structure
  4427. 'short-heading
  4428. (concat "Match: " match)))
  4429. (setq pos (point))
  4430. (insert match "\n")
  4431. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4432. (setq pos (point))
  4433. (unless org-agenda-multi
  4434. (insert (substitute-command-keys
  4435. "Press \
  4436. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4437. to search again\n")))
  4438. (add-text-properties pos (1- (point))
  4439. (list 'face 'org-agenda-structure))
  4440. (buffer-string)))
  4441. (org-agenda-mark-header-line (point-min))
  4442. (when rtnall
  4443. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4444. (goto-char (point-min))
  4445. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4446. (add-text-properties
  4447. (point-min) (point-max)
  4448. `(org-agenda-type tags
  4449. org-last-args (,org--matcher-tags-todo-only ,match)
  4450. org-redo-cmd ,org-agenda-redo-command
  4451. org-series-cmd ,org-cmd))
  4452. (org-agenda-finalize)
  4453. (setq buffer-read-only t))))
  4454. ;;; Agenda Finding stuck projects
  4455. (defvar org-agenda-skip-regexp nil
  4456. "Regular expression used in skipping subtrees for the agenda.
  4457. This is basically a temporary global variable that can be set and then
  4458. used by user-defined selections using `org-agenda-skip-function'.")
  4459. (defvar org-agenda-overriding-header nil
  4460. "When set during agenda, todo and tags searches it replaces the header.
  4461. If an empty string, no header will be inserted. If any other
  4462. string, it will be inserted as a header. If nil, a header will
  4463. be generated automatically according to the command. This
  4464. variable should not be set directly, but custom commands can bind
  4465. it in the options section.")
  4466. (defun org-agenda-skip-entry-if (&rest conditions)
  4467. "Skip entry if any of CONDITIONS is true.
  4468. See `org-agenda-skip-if' for details."
  4469. (org-agenda-skip-if nil conditions))
  4470. (defun org-agenda-skip-subtree-if (&rest conditions)
  4471. "Skip subtree if any of CONDITIONS is true.
  4472. See `org-agenda-skip-if' for details."
  4473. (org-agenda-skip-if t conditions))
  4474. (defun org-agenda-skip-if (subtree conditions)
  4475. "Checks current entity for CONDITIONS.
  4476. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4477. the entry (i.e. the text before the next heading) is checked.
  4478. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4479. from different tests. Valid conditions are:
  4480. scheduled Check if there is a scheduled cookie
  4481. notscheduled Check if there is no scheduled cookie
  4482. deadline Check if there is a deadline
  4483. notdeadline Check if there is no deadline
  4484. timestamp Check if there is a timestamp (also deadline or scheduled)
  4485. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4486. regexp Check if regexp matches
  4487. notregexp Check if regexp does not match.
  4488. todo Check if TODO keyword matches
  4489. nottodo Check if TODO keyword does not match
  4490. The regexp is taken from the conditions list, it must come right after
  4491. the `regexp' or `notregexp' element.
  4492. `todo' and `nottodo' accept as an argument a list of todo
  4493. keywords, which may include \"*\" to match any todo keyword.
  4494. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4495. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4496. Instead of a list, a keyword class may be given. For example:
  4497. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4498. would skip entries that haven't been marked with any of \"DONE\"
  4499. keywords. Possible classes are: `todo', `done', `any'.
  4500. If any of these conditions is met, this function returns the end point of
  4501. the entity, causing the search to continue from there. This is a function
  4502. that can be put into `org-agenda-skip-function' for the duration of a command."
  4503. (org-back-to-heading t)
  4504. (let* ((beg (point))
  4505. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4506. (org-entry-end-position)))
  4507. (planning-end (if subtree end (line-end-position 2)))
  4508. m)
  4509. (and
  4510. (or (and (memq 'scheduled conditions)
  4511. (re-search-forward org-scheduled-time-regexp planning-end t))
  4512. (and (memq 'notscheduled conditions)
  4513. (not
  4514. (save-excursion
  4515. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4516. (and (memq 'deadline conditions)
  4517. (re-search-forward org-deadline-time-regexp planning-end t))
  4518. (and (memq 'notdeadline conditions)
  4519. (not
  4520. (save-excursion
  4521. (re-search-forward org-deadline-time-regexp planning-end t))))
  4522. (and (memq 'timestamp conditions)
  4523. (re-search-forward org-ts-regexp end t))
  4524. (and (memq 'nottimestamp conditions)
  4525. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4526. (and (setq m (memq 'regexp conditions))
  4527. (stringp (nth 1 m))
  4528. (re-search-forward (nth 1 m) end t))
  4529. (and (setq m (memq 'notregexp conditions))
  4530. (stringp (nth 1 m))
  4531. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4532. (and (or
  4533. (setq m (memq 'nottodo conditions))
  4534. (setq m (memq 'todo-unblocked conditions))
  4535. (setq m (memq 'nottodo-unblocked conditions))
  4536. (setq m (memq 'todo conditions)))
  4537. (org-agenda-skip-if-todo m end)))
  4538. end)))
  4539. (defun org-agenda-skip-if-todo (args end)
  4540. "Helper function for `org-agenda-skip-if', do not use it directly.
  4541. ARGS is a list with first element either `todo', `nottodo',
  4542. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4543. a list of TODO keywords, or a state symbol `todo' or `done' or
  4544. `any'."
  4545. (let ((todo-re
  4546. (concat "^\\*+[ \t]+"
  4547. (regexp-opt
  4548. (pcase args
  4549. (`(,_ todo)
  4550. (org-delete-all org-done-keywords
  4551. (copy-sequence org-todo-keywords-1)))
  4552. (`(,_ done) org-done-keywords)
  4553. (`(,_ any) org-todo-keywords-1)
  4554. (`(,_ ,(pred atom))
  4555. (error "Invalid TODO class or type: %S" args))
  4556. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4557. (`(,_ ,todo-list) todo-list))
  4558. 'words))))
  4559. (pcase args
  4560. (`(todo . ,_)
  4561. (let (case-fold-search) (re-search-forward todo-re end t)))
  4562. (`(nottodo . ,_)
  4563. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4564. (`(todo-unblocked . ,_)
  4565. (catch :unblocked
  4566. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4567. (when (org-entry-blocked-p) (throw :unblocked t)))
  4568. nil))
  4569. (`(nottodo-unblocked . ,_)
  4570. (catch :unblocked
  4571. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4572. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4573. t))
  4574. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4575. ;;;###autoload
  4576. (defun org-agenda-list-stuck-projects (&rest ignore)
  4577. "Create agenda view for projects that are stuck.
  4578. Stuck projects are project that have no next actions. For the definitions
  4579. of what a project is and how to check if it stuck, customize the variable
  4580. `org-stuck-projects'."
  4581. (interactive)
  4582. (let* ((org-agenda-overriding-header
  4583. (or org-agenda-overriding-header "List of stuck projects: "))
  4584. (matcher (nth 0 org-stuck-projects))
  4585. (todo (nth 1 org-stuck-projects))
  4586. (tags (nth 2 org-stuck-projects))
  4587. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4588. (todo-wds
  4589. (if (not (member "*" todo)) todo
  4590. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4591. (org-delete-all org-done-keywords-for-agenda
  4592. (copy-sequence org-todo-keywords-for-agenda))))
  4593. (todo-re (and todo
  4594. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4595. (mapconcat #'identity todo-wds "\\|"))))
  4596. (tags-re (cond ((null tags) nil)
  4597. ((member "*" tags) org-tag-line-re)
  4598. (tags
  4599. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4600. (concat org-outline-regexp-bol
  4601. ".*?[ \t]:"
  4602. other-tags
  4603. (regexp-opt tags t)
  4604. ":" other-tags "[ \t]*$")))
  4605. (t nil)))
  4606. (re-list (delq nil (list todo-re tags-re gen-re)))
  4607. (skip-re
  4608. (if (null re-list)
  4609. (error "Missing information to identify unstuck projects")
  4610. (mapconcat #'identity re-list "\\|")))
  4611. (org-agenda-skip-function
  4612. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4613. ;; in the subtree.
  4614. `(lambda ()
  4615. (and (save-excursion
  4616. (let ((case-fold-search nil))
  4617. (re-search-forward
  4618. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4619. (progn (outline-next-heading) (point))))))
  4620. (org-tags-view nil matcher)
  4621. (setq org-agenda-buffer-name (buffer-name))
  4622. (with-current-buffer org-agenda-buffer-name
  4623. (setq org-agenda-redo-command
  4624. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4625. (let ((inhibit-read-only t))
  4626. (add-text-properties
  4627. (point-min) (point-max)
  4628. `(org-redo-cmd ,org-agenda-redo-command))))))
  4629. ;;; Diary integration
  4630. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4631. (defvar diary-list-entries-hook)
  4632. (defvar diary-time-regexp)
  4633. (defun org-get-entries-from-diary (date)
  4634. "Get the (Emacs Calendar) diary entries for DATE."
  4635. (require 'diary-lib)
  4636. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4637. (diary-display-function 'diary-fancy-display)
  4638. (pop-up-frames nil)
  4639. (diary-list-entries-hook
  4640. (cons 'org-diary-default-entry diary-list-entries-hook))
  4641. (diary-file-name-prefix nil) ; turn this feature off
  4642. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4643. entries
  4644. (org-disable-agenda-to-diary t))
  4645. (save-excursion
  4646. (save-window-excursion
  4647. (funcall (if (fboundp 'diary-list-entries)
  4648. 'diary-list-entries 'list-diary-entries)
  4649. date 1)))
  4650. (if (not (get-buffer diary-fancy-buffer))
  4651. (setq entries nil)
  4652. (with-current-buffer diary-fancy-buffer
  4653. (setq buffer-read-only nil)
  4654. (if (zerop (buffer-size))
  4655. ;; No entries
  4656. (setq entries nil)
  4657. ;; Omit the date and other unnecessary stuff
  4658. (org-agenda-cleanup-fancy-diary)
  4659. ;; Add prefix to each line and extend the text properties
  4660. (if (zerop (buffer-size))
  4661. (setq entries nil)
  4662. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4663. (setq entries
  4664. (with-temp-buffer
  4665. (insert entries) (goto-char (point-min))
  4666. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4667. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4668. (replace-match (concat "; " (match-string 1)))))
  4669. (buffer-string)))))
  4670. (set-buffer-modified-p nil)
  4671. (kill-buffer diary-fancy-buffer)))
  4672. (when entries
  4673. (setq entries (org-split-string entries "\n"))
  4674. (setq entries
  4675. (mapcar
  4676. (lambda (x)
  4677. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4678. ;; Extend the text properties to the beginning of the line
  4679. (org-add-props x (text-properties-at (1- (length x)) x)
  4680. 'type "diary" 'date date 'face 'org-agenda-diary))
  4681. entries)))))
  4682. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4683. "Hook run when the fancy diary buffer is cleaned up.")
  4684. (defun org-agenda-cleanup-fancy-diary ()
  4685. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4686. This gets rid of the date, the underline under the date, and the
  4687. dummy entry installed by Org mode to ensure non-empty diary for
  4688. each date. It also removes lines that contain only whitespace."
  4689. (goto-char (point-min))
  4690. (if (looking-at ".*?:[ \t]*")
  4691. (progn
  4692. (replace-match "")
  4693. (re-search-forward "\n=+$" nil t)
  4694. (replace-match "")
  4695. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4696. (re-search-forward "\n=+$" nil t)
  4697. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4698. (goto-char (point-min))
  4699. (while (re-search-forward "^ +\n" nil t)
  4700. (replace-match ""))
  4701. (goto-char (point-min))
  4702. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4703. (replace-match ""))
  4704. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4705. (defun org-modify-diary-entry-string (string)
  4706. "Add text properties to string, allowing Org to act on it."
  4707. (org-add-props string nil
  4708. 'mouse-face 'highlight
  4709. 'help-echo (if buffer-file-name
  4710. (format "mouse-2 or RET jump to diary file %s"
  4711. (abbreviate-file-name buffer-file-name))
  4712. "")
  4713. 'org-agenda-diary-link t
  4714. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4715. (defun org-diary-default-entry ()
  4716. "Add a dummy entry to the diary.
  4717. Needed to avoid empty dates which mess up holiday display."
  4718. ;; Catch the error if dealing with the new add-to-diary-alist
  4719. (when org-disable-agenda-to-diary
  4720. (condition-case nil
  4721. (org-add-to-diary-list original-date "Org mode dummy" "")
  4722. (error
  4723. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4724. (defun org-add-to-diary-list (&rest args)
  4725. (if (fboundp 'diary-add-to-list)
  4726. (apply 'diary-add-to-list args)
  4727. (apply 'add-to-diary-list args)))
  4728. (defvar org-diary-last-run-time nil)
  4729. ;;;###autoload
  4730. (defun org-diary (&rest args)
  4731. "Return diary information from org files.
  4732. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4733. It accesses org files and extracts information from those files to be
  4734. listed in the diary. The function accepts arguments specifying what
  4735. items should be listed. For a list of arguments allowed here, see the
  4736. variable `org-agenda-entry-types'.
  4737. The call in the diary file should look like this:
  4738. &%%(org-diary) ~/path/to/some/orgfile.org
  4739. Use a separate line for each org file to check. Or, if you omit the file name,
  4740. all files listed in `org-agenda-files' will be checked automatically:
  4741. &%%(org-diary)
  4742. If you don't give any arguments (as in the example above), the default value
  4743. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4744. So the example above may also be written as
  4745. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4746. The function expects the lisp variables `entry' and `date' to be provided
  4747. by the caller, because this is how the calendar works. Don't use this
  4748. function from a program - use `org-agenda-get-day-entries' instead."
  4749. (when (> (- (float-time)
  4750. org-agenda-last-marker-time)
  4751. 5)
  4752. ;; I am not sure if this works with sticky agendas, because the marker
  4753. ;; list is then no longer a global variable.
  4754. (org-agenda-reset-markers))
  4755. (org-compile-prefix-format 'agenda)
  4756. (org-set-sorting-strategy 'agenda)
  4757. (setq args (or args org-agenda-entry-types))
  4758. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4759. (list entry)
  4760. (org-agenda-files t)))
  4761. (time (float-time))
  4762. file rtn results)
  4763. (when (or (not org-diary-last-run-time)
  4764. (> (- time
  4765. org-diary-last-run-time)
  4766. 3))
  4767. (org-agenda-prepare-buffers files))
  4768. (setq org-diary-last-run-time time)
  4769. ;; If this is called during org-agenda, don't return any entries to
  4770. ;; the calendar. Org Agenda will list these entries itself.
  4771. (when org-disable-agenda-to-diary (setq files nil))
  4772. (while (setq file (pop files))
  4773. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4774. (setq results (append results rtn)))
  4775. (when results
  4776. (setq results
  4777. (mapcar (lambda (i) (replace-regexp-in-string
  4778. org-bracket-link-regexp "\\3" i)) results))
  4779. (concat (org-agenda-finalize-entries results) "\n"))))
  4780. ;;; Agenda entry finders
  4781. (defun org-agenda--timestamp-to-absolute (&rest args)
  4782. "Call `org-time-string-to-absolute' with ARGS.
  4783. However, throw `:skip' whenever an error is raised."
  4784. (condition-case e
  4785. (apply #'org-time-string-to-absolute args)
  4786. (org-diary-sexp-no-match (throw :skip nil))
  4787. (error
  4788. (message "%s; Skipping entry" (error-message-string e))
  4789. (throw :skip nil))))
  4790. (defun org-agenda-get-day-entries (file date &rest args)
  4791. "Does the work for `org-diary' and `org-agenda'.
  4792. FILE is the path to a file to be checked for entries. DATE is date like
  4793. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4794. which kind of entries should be extracted. For details about these, see
  4795. the documentation of `org-diary'."
  4796. (let* ((org-startup-folded nil)
  4797. (org-startup-align-all-tables nil)
  4798. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4799. (error "No such file %s" file))))
  4800. (if (not buffer)
  4801. ;; If file does not exist, signal it in diary nonetheless.
  4802. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4803. (with-current-buffer buffer
  4804. (unless (derived-mode-p 'org-mode)
  4805. (error "Agenda file %s is not in Org mode" file))
  4806. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4807. (setf org-agenda-current-date date)
  4808. (save-excursion
  4809. (save-restriction
  4810. (if (eq buffer org-agenda-restrict)
  4811. (narrow-to-region org-agenda-restrict-begin
  4812. org-agenda-restrict-end)
  4813. (widen))
  4814. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4815. ;; first in order to populate DEADLINES before passing it.
  4816. ;;
  4817. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4818. ;; guarding us from modifying `org-agenda-entry-types'.
  4819. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4820. (when (and (memq :scheduled args) (memq :scheduled* args))
  4821. (setf args (delq :scheduled* args)))
  4822. (cond
  4823. ((memq :deadline args)
  4824. (setf args (cons :deadline
  4825. (delq :deadline (delq :deadline* args)))))
  4826. ((memq :deadline* args)
  4827. (setf args (cons :deadline* (delq :deadline* args)))))
  4828. ;; Collect list of headlines. Return them flattened.
  4829. (let ((case-fold-search nil) results deadlines)
  4830. (dolist (arg args (apply #'nconc (nreverse results)))
  4831. (pcase arg
  4832. ((and :todo (guard (org-agenda-today-p date)))
  4833. (push (org-agenda-get-todos) results))
  4834. (:timestamp
  4835. (push (org-agenda-get-blocks) results)
  4836. (push (org-agenda-get-timestamps deadlines) results))
  4837. (:sexp
  4838. (push (org-agenda-get-sexps) results))
  4839. (:scheduled
  4840. (push (org-agenda-get-scheduled deadlines) results))
  4841. (:scheduled*
  4842. (push (org-agenda-get-scheduled deadlines t) results))
  4843. (:closed
  4844. (push (org-agenda-get-progress) results))
  4845. (:deadline
  4846. (setf deadlines (org-agenda-get-deadlines))
  4847. (push deadlines results))
  4848. (:deadline*
  4849. (setf deadlines (org-agenda-get-deadlines t))
  4850. (push deadlines results)))))))))))
  4851. (defsubst org-em (x y list)
  4852. "Is X or Y a member of LIST?"
  4853. (or (memq x list) (memq y list)))
  4854. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4855. (defvar org-agenda-sorting-strategy-selected nil)
  4856. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4857. "Retrieve timestamp information for sorting agenda views.
  4858. Given a point or marker POM, returns a cons cell of the timestamp
  4859. and the timestamp type relevant for the sorting strategy in
  4860. `org-agenda-sorting-strategy-selected'."
  4861. (let (ts ts-date-type)
  4862. (save-match-data
  4863. (cond ((org-em 'scheduled-up 'scheduled-down
  4864. org-agenda-sorting-strategy-selected)
  4865. (setq ts (org-entry-get pom "SCHEDULED")
  4866. ts-date-type " scheduled"))
  4867. ((org-em 'deadline-up 'deadline-down
  4868. org-agenda-sorting-strategy-selected)
  4869. (setq ts (org-entry-get pom "DEADLINE")
  4870. ts-date-type " deadline"))
  4871. ((org-em 'ts-up 'ts-down
  4872. org-agenda-sorting-strategy-selected)
  4873. (setq ts (org-entry-get pom "TIMESTAMP")
  4874. ts-date-type " timestamp"))
  4875. ((org-em 'tsia-up 'tsia-down
  4876. org-agenda-sorting-strategy-selected)
  4877. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4878. ts-date-type " timestamp_ia"))
  4879. ((org-em 'timestamp-up 'timestamp-down
  4880. org-agenda-sorting-strategy-selected)
  4881. (setq ts (or (org-entry-get pom "SCHEDULED")
  4882. (org-entry-get pom "DEADLINE")
  4883. (org-entry-get pom "TIMESTAMP")
  4884. (org-entry-get pom "TIMESTAMP_IA"))
  4885. ts-date-type ""))
  4886. (t (setq ts-date-type "")))
  4887. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4888. ts-date-type))))
  4889. (defun org-agenda-get-todos ()
  4890. "Return the TODO information for agenda display."
  4891. (let* ((props (list 'face nil
  4892. 'done-face 'org-agenda-done
  4893. 'org-not-done-regexp org-not-done-regexp
  4894. 'org-todo-regexp org-todo-regexp
  4895. 'org-complex-heading-regexp org-complex-heading-regexp
  4896. 'mouse-face 'highlight
  4897. 'help-echo
  4898. (format "mouse-2 or RET jump to org file %s"
  4899. (abbreviate-file-name buffer-file-name))))
  4900. (case-fold-search nil)
  4901. (regexp (format org-heading-keyword-regexp-format
  4902. (cond
  4903. ((and org-select-this-todo-keyword
  4904. (equal org-select-this-todo-keyword "*"))
  4905. org-todo-regexp)
  4906. (org-select-this-todo-keyword
  4907. (concat "\\("
  4908. (mapconcat 'identity
  4909. (org-split-string
  4910. org-select-this-todo-keyword
  4911. "|")
  4912. "\\|") "\\)"))
  4913. (t org-not-done-regexp))))
  4914. marker priority category level tags todo-state
  4915. ts-date ts-date-type ts-date-pair
  4916. ee txt beg end inherited-tags todo-state-end-pos)
  4917. (goto-char (point-min))
  4918. (while (re-search-forward regexp nil t)
  4919. (catch :skip
  4920. (save-match-data
  4921. (beginning-of-line)
  4922. (org-agenda-skip)
  4923. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4924. (unless (and (setq todo-state (org-get-todo-state))
  4925. (setq todo-state-end-pos (match-end 2)))
  4926. (goto-char end)
  4927. (throw :skip nil))
  4928. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4929. (goto-char (1+ beg))
  4930. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4931. (throw :skip nil)))
  4932. (goto-char (match-beginning 2))
  4933. (setq marker (org-agenda-new-marker (match-beginning 0))
  4934. category (org-get-category)
  4935. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  4936. ts-date (car ts-date-pair)
  4937. ts-date-type (cdr ts-date-pair)
  4938. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  4939. inherited-tags
  4940. (or (eq org-agenda-show-inherited-tags 'always)
  4941. (and (listp org-agenda-show-inherited-tags)
  4942. (memq 'todo org-agenda-show-inherited-tags))
  4943. (and (eq org-agenda-show-inherited-tags t)
  4944. (or (eq org-agenda-use-tag-inheritance t)
  4945. (memq 'todo org-agenda-use-tag-inheritance))))
  4946. tags (org-get-tags nil (not inherited-tags))
  4947. level (make-string (org-reduced-level (org-outline-level)) ? )
  4948. txt (org-agenda-format-item "" txt level category tags t)
  4949. priority (1+ (org-get-priority txt)))
  4950. (org-add-props txt props
  4951. 'org-marker marker 'org-hd-marker marker
  4952. 'priority priority
  4953. 'level level
  4954. 'ts-date ts-date
  4955. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4956. (push txt ee)
  4957. (if org-agenda-todo-list-sublevels
  4958. (goto-char todo-state-end-pos)
  4959. (org-end-of-subtree 'invisible))))
  4960. (nreverse ee)))
  4961. (defun org-agenda-todo-custom-ignore-p (time n)
  4962. "Check whether timestamp is farther away than n number of days.
  4963. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4964. `org-agenda-todo-ignore-scheduled' or
  4965. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4966. (let ((days (org-time-stamp-to-now
  4967. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4968. (if (>= n 0)
  4969. (>= days n)
  4970. (<= days n))))
  4971. ;;;###autoload
  4972. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4973. (&optional end)
  4974. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4975. (when (or org-agenda-todo-ignore-with-date
  4976. org-agenda-todo-ignore-scheduled
  4977. org-agenda-todo-ignore-deadlines
  4978. org-agenda-todo-ignore-timestamp)
  4979. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4980. (save-excursion
  4981. (or (and org-agenda-todo-ignore-with-date
  4982. (re-search-forward org-ts-regexp end t))
  4983. (and org-agenda-todo-ignore-scheduled
  4984. (re-search-forward org-scheduled-time-regexp end t)
  4985. (cond
  4986. ((eq org-agenda-todo-ignore-scheduled 'future)
  4987. (> (org-time-stamp-to-now
  4988. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4989. ((eq org-agenda-todo-ignore-scheduled 'past)
  4990. (<= (org-time-stamp-to-now
  4991. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4992. ((numberp org-agenda-todo-ignore-scheduled)
  4993. (org-agenda-todo-custom-ignore-p
  4994. (match-string 1) org-agenda-todo-ignore-scheduled))
  4995. (t)))
  4996. (and org-agenda-todo-ignore-deadlines
  4997. (re-search-forward org-deadline-time-regexp end t)
  4998. (cond
  4999. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5000. ((eq org-agenda-todo-ignore-deadlines 'far)
  5001. (not (org-deadline-close-p (match-string 1))))
  5002. ((eq org-agenda-todo-ignore-deadlines 'future)
  5003. (> (org-time-stamp-to-now
  5004. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5005. ((eq org-agenda-todo-ignore-deadlines 'past)
  5006. (<= (org-time-stamp-to-now
  5007. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5008. ((numberp org-agenda-todo-ignore-deadlines)
  5009. (org-agenda-todo-custom-ignore-p
  5010. (match-string 1) org-agenda-todo-ignore-deadlines))
  5011. (t (org-deadline-close-p (match-string 1)))))
  5012. (and org-agenda-todo-ignore-timestamp
  5013. (let ((buffer (current-buffer))
  5014. (regexp
  5015. (concat
  5016. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5017. (start (point)))
  5018. ;; Copy current buffer into a temporary one
  5019. (with-temp-buffer
  5020. (insert-buffer-substring buffer start end)
  5021. (goto-char (point-min))
  5022. ;; Delete SCHEDULED and DEADLINE items
  5023. (while (re-search-forward regexp end t)
  5024. (delete-region (match-beginning 0) (match-end 0)))
  5025. (goto-char (point-min))
  5026. ;; No search for timestamp left
  5027. (when (re-search-forward org-ts-regexp nil t)
  5028. (cond
  5029. ((eq org-agenda-todo-ignore-timestamp 'future)
  5030. (> (org-time-stamp-to-now
  5031. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5032. ((eq org-agenda-todo-ignore-timestamp 'past)
  5033. (<= (org-time-stamp-to-now
  5034. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5035. ((numberp org-agenda-todo-ignore-timestamp)
  5036. (org-agenda-todo-custom-ignore-p
  5037. (match-string 1) org-agenda-todo-ignore-timestamp))
  5038. (t))))))))))
  5039. (defun org-agenda-get-timestamps (&optional deadlines)
  5040. "Return the date stamp information for agenda display.
  5041. Optional argument DEADLINES is a list of deadline items to be
  5042. displayed in agenda view."
  5043. (let* ((props (list 'face 'org-agenda-calendar-event
  5044. 'org-not-done-regexp org-not-done-regexp
  5045. 'org-todo-regexp org-todo-regexp
  5046. 'org-complex-heading-regexp org-complex-heading-regexp
  5047. 'mouse-face 'highlight
  5048. 'help-echo
  5049. (format "mouse-2 or RET jump to Org file %s"
  5050. (abbreviate-file-name buffer-file-name))))
  5051. (current (calendar-absolute-from-gregorian date))
  5052. (today (org-today))
  5053. (deadline-position-alist
  5054. (mapcar (lambda (d)
  5055. (let ((m (get-text-property 0 'org-hd-marker d)))
  5056. (and m (marker-position m))))
  5057. deadlines))
  5058. ;; Match time-stamps set to current date, time-stamps with
  5059. ;; a repeater, and S-exp time-stamps.
  5060. (regexp
  5061. (concat
  5062. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5063. (regexp-quote
  5064. (substring
  5065. (format-time-string
  5066. (car org-time-stamp-formats)
  5067. (encode-time ; DATE bound by calendar
  5068. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5069. 1 11))
  5070. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5071. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5072. timestamp-items)
  5073. (goto-char (point-min))
  5074. (while (re-search-forward regexp nil t)
  5075. ;; Skip date ranges, scheduled and deadlines, which are handled
  5076. ;; specially. Also skip time-stamps before first headline as
  5077. ;; there would be no entry to add to the agenda. Eventually,
  5078. ;; ignore clock entries.
  5079. (catch :skip
  5080. (save-match-data
  5081. (when (or (org-at-date-range-p)
  5082. (org-at-planning-p)
  5083. (org-before-first-heading-p)
  5084. (and org-agenda-include-inactive-timestamps
  5085. (org-at-clock-log-p)))
  5086. (throw :skip nil))
  5087. (org-agenda-skip))
  5088. (let* ((pos (match-beginning 0))
  5089. (repeat (match-string 1))
  5090. (sexp-entry (match-string 3))
  5091. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5092. (save-excursion
  5093. (goto-char pos)
  5094. (looking-at org-ts-regexp-both)
  5095. (match-string 0))))
  5096. (todo-state (org-get-todo-state))
  5097. (warntime (get-text-property (point) 'org-appt-warntime))
  5098. (done? (member todo-state org-done-keywords)))
  5099. ;; Possibly skip done tasks.
  5100. (when (and done? org-agenda-skip-timestamp-if-done)
  5101. (throw :skip t))
  5102. ;; S-exp entry doesn't match current day: skip it.
  5103. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5104. (throw :skip nil))
  5105. (when repeat
  5106. (let* ((past
  5107. ;; A repeating time stamp is shown at its base
  5108. ;; date and every repeated date up to TODAY. If
  5109. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5110. ;; however, only the last repeat before today
  5111. ;; (inclusive) is shown.
  5112. (org-agenda--timestamp-to-absolute
  5113. repeat
  5114. (if (or (> current today)
  5115. (eq org-agenda-prefer-last-repeat t)
  5116. (member todo-state org-agenda-prefer-last-repeat))
  5117. today
  5118. current)
  5119. 'past (current-buffer) pos))
  5120. (future
  5121. ;; Display every repeated date past TODAY
  5122. ;; (exclusive) unless
  5123. ;; `org-agenda-show-future-repeats' is nil. If
  5124. ;; this variable is set to `next', only display
  5125. ;; the first repeated date after TODAY
  5126. ;; (exclusive).
  5127. (cond
  5128. ((<= current today) past)
  5129. ((not org-agenda-show-future-repeats) past)
  5130. (t
  5131. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5132. (1+ today)
  5133. current)))
  5134. (org-agenda--timestamp-to-absolute
  5135. repeat base 'future (current-buffer) pos))))))
  5136. (when (and (/= current past) (/= current future))
  5137. (throw :skip nil))))
  5138. (save-excursion
  5139. (re-search-backward org-outline-regexp-bol nil t)
  5140. ;; Possibly skip time-stamp when a deadline is set.
  5141. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5142. (assq (point) deadline-position-alist))
  5143. (throw :skip nil))
  5144. (let* ((category (org-get-category pos))
  5145. (inherited-tags
  5146. (or (eq org-agenda-show-inherited-tags 'always)
  5147. (and (consp org-agenda-show-inherited-tags)
  5148. (memq 'agenda org-agenda-show-inherited-tags))
  5149. (and (eq org-agenda-show-inherited-tags t)
  5150. (or (eq org-agenda-use-tag-inheritance t)
  5151. (memq 'agenda
  5152. org-agenda-use-tag-inheritance)))))
  5153. (tags (org-get-tags nil (not inherited-tags)))
  5154. (level (make-string (org-reduced-level (org-outline-level))
  5155. ?\s))
  5156. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5157. (match-string 1)))
  5158. (inactive? (= (char-after pos) ?\[))
  5159. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5160. (item
  5161. (org-agenda-format-item
  5162. (and inactive? org-agenda-inactive-leader)
  5163. head level category tags time-stamp org-ts-regexp habit?)))
  5164. (org-add-props item props
  5165. 'priority (if habit?
  5166. (org-habit-get-priority (org-habit-parse-todo))
  5167. (org-get-priority item))
  5168. 'org-marker (org-agenda-new-marker pos)
  5169. 'org-hd-marker (org-agenda-new-marker)
  5170. 'date date
  5171. 'level level
  5172. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5173. current)
  5174. 'todo-state todo-state
  5175. 'warntime warntime
  5176. 'type "timestamp")
  5177. (push item timestamp-items))))
  5178. (when org-agenda-skip-additional-timestamps-same-entry
  5179. (outline-next-heading))))
  5180. (nreverse timestamp-items)))
  5181. (defun org-agenda-get-sexps ()
  5182. "Return the sexp information for agenda display."
  5183. (require 'diary-lib)
  5184. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5185. 'mouse-face 'highlight
  5186. 'help-echo
  5187. (format "mouse-2 or RET jump to org file %s"
  5188. (abbreviate-file-name buffer-file-name))))
  5189. (regexp "^&?%%(")
  5190. marker category extra level ee txt tags entry
  5191. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5192. (goto-char (point-min))
  5193. (while (re-search-forward regexp nil t)
  5194. (catch :skip
  5195. (org-agenda-skip)
  5196. (setq beg (match-beginning 0))
  5197. (goto-char (1- (match-end 0)))
  5198. (setq b (point))
  5199. (forward-sexp 1)
  5200. (setq sexp (buffer-substring b (point)))
  5201. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5202. (org-trim (match-string 1))
  5203. ""))
  5204. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5205. (when result
  5206. (setq marker (org-agenda-new-marker beg)
  5207. level (make-string (org-reduced-level (org-outline-level)) ? )
  5208. category (org-get-category beg)
  5209. inherited-tags
  5210. (or (eq org-agenda-show-inherited-tags 'always)
  5211. (and (listp org-agenda-show-inherited-tags)
  5212. (memq 'agenda org-agenda-show-inherited-tags))
  5213. (and (eq org-agenda-show-inherited-tags t)
  5214. (or (eq org-agenda-use-tag-inheritance t)
  5215. (memq 'agenda org-agenda-use-tag-inheritance))))
  5216. tags (org-get-tags nil (not inherited-tags))
  5217. todo-state (org-get-todo-state)
  5218. warntime (get-text-property (point) 'org-appt-warntime)
  5219. extra nil)
  5220. (dolist (r (if (stringp result)
  5221. (list result)
  5222. result)) ;; we expect a list here
  5223. (when (and org-agenda-diary-sexp-prefix
  5224. (string-match org-agenda-diary-sexp-prefix r))
  5225. (setq extra (match-string 0 r)
  5226. r (replace-match "" nil nil r)))
  5227. (if (string-match "\\S-" r)
  5228. (setq txt r)
  5229. (setq txt "SEXP entry returned empty string"))
  5230. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5231. (org-add-props txt props 'org-marker marker
  5232. 'date date 'todo-state todo-state
  5233. 'level level 'type "sexp" 'warntime warntime)
  5234. (push txt ee)))))
  5235. (nreverse ee)))
  5236. ;; Calendar sanity: define some functions that are independent of
  5237. ;; `calendar-date-style'.
  5238. (defun org-anniversary (year month day &optional mark)
  5239. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5240. (with-no-warnings
  5241. (let ((calendar-date-style 'iso))
  5242. (diary-anniversary year month day mark))))
  5243. (defun org-cyclic (N year month day &optional mark)
  5244. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5245. (with-no-warnings
  5246. (let ((calendar-date-style 'iso))
  5247. (diary-cyclic N year month day mark))))
  5248. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5249. "Like `diary-block', but with fixed (ISO) order of arguments."
  5250. (with-no-warnings
  5251. (let ((calendar-date-style 'iso))
  5252. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5253. (defun org-date (year month day &optional mark)
  5254. "Like `diary-date', but with fixed (ISO) order of arguments."
  5255. (with-no-warnings
  5256. (let ((calendar-date-style 'iso))
  5257. (diary-date year month day mark))))
  5258. ;; Define the `org-class' function
  5259. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5260. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5261. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5262. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5263. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5264. `holidays', then any date that is known by the Emacs calendar to be a
  5265. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5266. then those holidays will be skipped."
  5267. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5268. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5269. (d (calendar-absolute-from-gregorian date))
  5270. (h (when skip-weeks (calendar-check-holidays date))))
  5271. (and
  5272. (<= date1 d)
  5273. (<= d date2)
  5274. (= (calendar-day-of-week date) dayname)
  5275. (or (not skip-weeks)
  5276. (progn
  5277. (require 'cal-iso)
  5278. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5279. (not (or (and h (memq 'holidays skip-weeks))
  5280. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5281. entry)))
  5282. (defalias 'org-get-closed 'org-agenda-get-progress)
  5283. (defun org-agenda-get-progress ()
  5284. "Return the logged TODO entries for agenda display."
  5285. (let* ((props (list 'mouse-face 'highlight
  5286. 'org-not-done-regexp org-not-done-regexp
  5287. 'org-todo-regexp org-todo-regexp
  5288. 'org-complex-heading-regexp org-complex-heading-regexp
  5289. 'help-echo
  5290. (format "mouse-2 or RET jump to org file %s"
  5291. (abbreviate-file-name buffer-file-name))))
  5292. (items (if (consp org-agenda-show-log-scoped)
  5293. org-agenda-show-log-scoped
  5294. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5295. '(clock)
  5296. org-agenda-log-mode-items)))
  5297. (parts
  5298. (delq nil
  5299. (list
  5300. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5301. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5302. (when (memq 'state items)
  5303. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5304. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5305. (error "`org-agenda-log-mode-items' is empty")))
  5306. (regexp (concat
  5307. "\\(" parts-re "\\)"
  5308. " *\\["
  5309. (regexp-quote
  5310. (substring
  5311. (format-time-string
  5312. (car org-time-stamp-formats)
  5313. (encode-time ; DATE bound by calendar
  5314. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5315. 1 11))))
  5316. (org-agenda-search-headline-for-time nil)
  5317. marker hdmarker priority category level tags closedp type
  5318. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5319. (goto-char (point-min))
  5320. (while (re-search-forward regexp nil t)
  5321. (catch :skip
  5322. (org-agenda-skip)
  5323. (setq marker (org-agenda-new-marker (match-beginning 0))
  5324. closedp (equal (match-string 1) org-closed-string)
  5325. statep (equal (string-to-char (match-string 1)) ?-)
  5326. clockp (not (or closedp statep))
  5327. state (and statep (match-string 2))
  5328. category (org-get-category (match-beginning 0))
  5329. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5330. (when (string-match "\\]" timestr)
  5331. ;; substring should only run to end of time stamp
  5332. (setq rest (substring timestr (match-end 0))
  5333. timestr (substring timestr 0 (match-end 0)))
  5334. (if (and (not closedp) (not statep)
  5335. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5336. rest))
  5337. (progn (setq timestr (concat (substring timestr 0 -1)
  5338. "-" (match-string 1 rest) "]"))
  5339. (setq clocked (match-string 2 rest)))
  5340. (setq clocked "-")))
  5341. (save-excursion
  5342. (setq extra
  5343. (cond
  5344. ((not org-agenda-log-mode-add-notes) nil)
  5345. (statep
  5346. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5347. (match-string 1)))
  5348. (clockp
  5349. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5350. (match-string 1)))))
  5351. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5352. (throw :skip nil)
  5353. (goto-char (match-beginning 0))
  5354. (setq hdmarker (org-agenda-new-marker)
  5355. inherited-tags
  5356. (or (eq org-agenda-show-inherited-tags 'always)
  5357. (and (listp org-agenda-show-inherited-tags)
  5358. (memq 'todo org-agenda-show-inherited-tags))
  5359. (and (eq org-agenda-show-inherited-tags t)
  5360. (or (eq org-agenda-use-tag-inheritance t)
  5361. (memq 'todo org-agenda-use-tag-inheritance))))
  5362. tags (org-get-tags nil (not inherited-tags))
  5363. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5364. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5365. (setq txt (match-string 1))
  5366. (when extra
  5367. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5368. (setq txt (concat (substring txt 0 (match-beginning 1))
  5369. " - " extra " " (match-string 2 txt)))
  5370. (setq txt (concat txt " - " extra))))
  5371. (setq txt (org-agenda-format-item
  5372. (cond
  5373. (closedp "Closed: ")
  5374. (statep (concat "State: (" state ")"))
  5375. (t (concat "Clocked: (" clocked ")")))
  5376. txt level category tags timestr)))
  5377. (setq type (cond (closedp "closed")
  5378. (statep "state")
  5379. (t "clock")))
  5380. (setq priority 100000)
  5381. (org-add-props txt props
  5382. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5383. 'priority priority 'level level
  5384. 'type type 'date date
  5385. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5386. (push txt ee))
  5387. (goto-char (point-at-eol))))
  5388. (nreverse ee)))
  5389. (defun org-agenda-show-clocking-issues ()
  5390. "Add overlays, showing issues with clocking.
  5391. See also the user option `org-agenda-clock-consistency-checks'."
  5392. (interactive)
  5393. (let* ((pl org-agenda-clock-consistency-checks)
  5394. (re (concat "^[ \t]*"
  5395. org-clock-string
  5396. "[ \t]+"
  5397. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5398. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5399. (tlstart 0.)
  5400. (tlend 0.)
  5401. (maxtime (org-duration-to-minutes
  5402. (or (plist-get pl :max-duration) "24:00")))
  5403. (mintime (org-duration-to-minutes
  5404. (or (plist-get pl :min-duration) 0)))
  5405. (maxgap (org-duration-to-minutes
  5406. ;; default 30:00 means never complain
  5407. (or (plist-get pl :max-gap) "30:00")))
  5408. (gapok (mapcar #'org-duration-to-minutes
  5409. (plist-get pl :gap-ok-around)))
  5410. (def-face (or (plist-get pl :default-face)
  5411. '((:background "DarkRed") (:foreground "white"))))
  5412. issue face m te ts dt ov)
  5413. (goto-char (point-min))
  5414. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5415. (setq issue nil face def-face)
  5416. (catch 'next
  5417. (setq m (org-get-at-bol 'org-marker)
  5418. te nil ts nil)
  5419. (unless (and m (markerp m))
  5420. (setq issue "No valid clock line") (throw 'next t))
  5421. (org-with-point-at m
  5422. (save-excursion
  5423. (goto-char (point-at-bol))
  5424. (unless (looking-at re)
  5425. (error "No valid Clock line")
  5426. (throw 'next t))
  5427. (unless (match-end 3)
  5428. (setq issue "No end time"
  5429. face (or (plist-get pl :no-end-time-face) face))
  5430. (throw 'next t))
  5431. (setq ts (match-string 1)
  5432. te (match-string 3)
  5433. ts (float-time (org-time-string-to-time ts))
  5434. te (float-time (org-time-string-to-time te))
  5435. dt (- te ts))))
  5436. (cond
  5437. ((> dt (* 60 maxtime))
  5438. ;; a very long clocking chunk
  5439. (setq issue (format "Clocking interval is very long: %s"
  5440. (org-duration-from-minutes (floor dt 60)))
  5441. face (or (plist-get pl :long-face) face)))
  5442. ((< dt (* 60 mintime))
  5443. ;; a very short clocking chunk
  5444. (setq issue (format "Clocking interval is very short: %s"
  5445. (org-duration-from-minutes (floor dt 60)))
  5446. face (or (plist-get pl :short-face) face)))
  5447. ((and (> tlend 0) (< ts tlend))
  5448. ;; Two clock entries are overlapping
  5449. (setq issue (format "Clocking overlap: %d minutes"
  5450. (/ (- tlend ts) 60))
  5451. face (or (plist-get pl :overlap-face) face)))
  5452. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5453. ;; There is a gap, lets see if we need to report it
  5454. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5455. (setq issue (format "Clocking gap: %d minutes"
  5456. (/ (- ts tlend) 60))
  5457. face (or (plist-get pl :gap-face) face))))
  5458. (t nil)))
  5459. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5460. (when issue
  5461. ;; OK, there was some issue, add an overlay to show the issue
  5462. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5463. (overlay-put ov 'before-string
  5464. (concat
  5465. (org-add-props
  5466. (format "%-43s" (concat " " issue))
  5467. nil
  5468. 'face face)
  5469. "\n"))
  5470. (overlay-put ov 'evaporate t)))))
  5471. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5472. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5473. (catch 'exit
  5474. (unless ok-list
  5475. ;; there are no OK times for gaps...
  5476. (throw 'exit nil))
  5477. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5478. ;; This is more than 24 hours, so it is OK.
  5479. ;; because we have at least one OK time, that must be in the
  5480. ;; 24 hour interval.
  5481. (throw 'exit t))
  5482. ;; We have a shorter gap.
  5483. ;; Now we have to get the minute of the day when these times are
  5484. (let* ((t1dec (org-decode-time t1))
  5485. (t2dec (org-decode-time t2))
  5486. ;; compute the minute on the day
  5487. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5488. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5489. (when (< min2 min1)
  5490. ;; if min2 is smaller than min1, this means it is on the next day.
  5491. ;; Wrap it to after midnight.
  5492. (setq min2 (+ min2 1440)))
  5493. ;; Now check if any of the OK times is in the gap
  5494. (mapc (lambda (x)
  5495. ;; Wrap the time to after midnight if necessary
  5496. (when (< x min1) (setq x (+ x 1440)))
  5497. ;; Check if in interval
  5498. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5499. ok-list)
  5500. ;; Nope, this gap is not OK
  5501. nil)))
  5502. (defun org-agenda-get-deadlines (&optional with-hour)
  5503. "Return the deadline information for agenda display.
  5504. When WITH-HOUR is non-nil, only return deadlines with an hour
  5505. specification like [h]h:mm."
  5506. (let* ((props (list 'mouse-face 'highlight
  5507. 'org-not-done-regexp org-not-done-regexp
  5508. 'org-todo-regexp org-todo-regexp
  5509. 'org-complex-heading-regexp org-complex-heading-regexp
  5510. 'help-echo
  5511. (format "mouse-2 or RET jump to org file %s"
  5512. (abbreviate-file-name buffer-file-name))))
  5513. (regexp (if with-hour
  5514. org-deadline-time-hour-regexp
  5515. org-deadline-time-regexp))
  5516. (today (org-today))
  5517. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5518. (current (calendar-absolute-from-gregorian date))
  5519. deadline-items)
  5520. (goto-char (point-min))
  5521. (while (re-search-forward regexp nil t)
  5522. (catch :skip
  5523. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5524. (org-agenda-skip)
  5525. (let* ((s (match-string 1))
  5526. (pos (1- (match-beginning 1)))
  5527. (todo-state (save-match-data (org-get-todo-state)))
  5528. (done? (member todo-state org-done-keywords))
  5529. (sexp? (string-prefix-p "%%" s))
  5530. ;; DEADLINE is the deadline date for the entry. It is
  5531. ;; either the base date or the last repeat, according
  5532. ;; to `org-agenda-prefer-last-repeat'.
  5533. (deadline
  5534. (cond
  5535. (sexp? (org-agenda--timestamp-to-absolute s current))
  5536. ((or (eq org-agenda-prefer-last-repeat t)
  5537. (member todo-state org-agenda-prefer-last-repeat))
  5538. (org-agenda--timestamp-to-absolute
  5539. s today 'past (current-buffer) pos))
  5540. (t (org-agenda--timestamp-to-absolute s))))
  5541. ;; REPEAT is the future repeat closest from CURRENT,
  5542. ;; according to `org-agenda-show-future-repeats'. If
  5543. ;; the latter is nil, or if the time stamp has no
  5544. ;; repeat part, default to DEADLINE.
  5545. (repeat
  5546. (cond
  5547. (sexp? deadline)
  5548. ((<= current today) deadline)
  5549. ((not org-agenda-show-future-repeats) deadline)
  5550. (t
  5551. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5552. (1+ today)
  5553. current)))
  5554. (org-agenda--timestamp-to-absolute
  5555. s base 'future (current-buffer) pos)))))
  5556. (diff (- deadline current))
  5557. (suppress-prewarning
  5558. (let ((scheduled
  5559. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5560. (org-entry-get nil "SCHEDULED"))))
  5561. (cond
  5562. ((not scheduled) nil)
  5563. ;; The current item has a scheduled date, so
  5564. ;; evaluate its prewarning lead time.
  5565. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5566. ;; Use global prewarning-restart lead time.
  5567. org-agenda-skip-deadline-prewarning-if-scheduled)
  5568. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5569. 'pre-scheduled)
  5570. ;; Set pre-warning to no earlier than SCHEDULED.
  5571. (min (- deadline
  5572. (org-agenda--timestamp-to-absolute scheduled))
  5573. org-deadline-warning-days))
  5574. ;; Set pre-warning to deadline.
  5575. (t 0))))
  5576. (wdays (or suppress-prewarning (org-get-wdays s))))
  5577. (cond
  5578. ;; Only display deadlines at their base date, at future
  5579. ;; repeat occurrences or in today agenda.
  5580. ((= current deadline) nil)
  5581. ((= current repeat) nil)
  5582. ((not today?) (throw :skip nil))
  5583. ;; Upcoming deadline: display within warning period WDAYS.
  5584. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5585. ;; Overdue deadline: warn about it for
  5586. ;; `org-deadline-past-days' duration.
  5587. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5588. ;; Possibly skip done tasks.
  5589. (when (and done?
  5590. (or org-agenda-skip-deadline-if-done
  5591. (/= deadline current)))
  5592. (throw :skip nil))
  5593. (save-excursion
  5594. (re-search-backward "^\\*+[ \t]+" nil t)
  5595. (goto-char (match-end 0))
  5596. (let* ((category (org-get-category))
  5597. (level (make-string (org-reduced-level (org-outline-level))
  5598. ?\s))
  5599. (head (buffer-substring (point) (line-end-position)))
  5600. (inherited-tags
  5601. (or (eq org-agenda-show-inherited-tags 'always)
  5602. (and (listp org-agenda-show-inherited-tags)
  5603. (memq 'agenda org-agenda-show-inherited-tags))
  5604. (and (eq org-agenda-show-inherited-tags t)
  5605. (or (eq org-agenda-use-tag-inheritance t)
  5606. (memq 'agenda
  5607. org-agenda-use-tag-inheritance)))))
  5608. (tags (org-get-tags nil (not inherited-tags)))
  5609. (time
  5610. (cond
  5611. ;; No time of day designation if it is only
  5612. ;; a reminder.
  5613. ((and (/= current deadline) (/= current repeat)) nil)
  5614. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5615. (concat (substring s (match-beginning 1)) " "))
  5616. (t 'time)))
  5617. (item
  5618. (org-agenda-format-item
  5619. ;; Insert appropriate suffixes before deadlines.
  5620. ;; Those only apply to today agenda.
  5621. (pcase-let ((`(,now ,future ,past)
  5622. org-agenda-deadline-leaders))
  5623. (cond
  5624. ((and today? (< deadline today)) (format past (- diff)))
  5625. ((and today? (> deadline today)) (format future diff))
  5626. (t now)))
  5627. head level category tags time))
  5628. (face (org-agenda-deadline-face
  5629. (- 1 (/ (float diff) (max wdays 1)))))
  5630. (upcoming? (and today? (> deadline today)))
  5631. (warntime (get-text-property (point) 'org-appt-warntime)))
  5632. (org-add-props item props
  5633. 'org-marker (org-agenda-new-marker pos)
  5634. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5635. 'warntime warntime
  5636. 'level level
  5637. 'ts-date deadline
  5638. 'priority
  5639. ;; Adjust priority to today reminders about deadlines.
  5640. ;; Overdue deadlines get the highest priority
  5641. ;; increase, then imminent deadlines and eventually
  5642. ;; more distant deadlines.
  5643. (let ((adjust (if today? (- diff) 0)))
  5644. (+ adjust (org-get-priority item)))
  5645. 'todo-state todo-state
  5646. 'type (if upcoming? "upcoming-deadline" "deadline")
  5647. 'date (if upcoming? date deadline)
  5648. 'face (if done? 'org-agenda-done face)
  5649. 'undone-face face
  5650. 'done-face 'org-agenda-done)
  5651. (push item deadline-items))))))
  5652. (nreverse deadline-items)))
  5653. (defun org-agenda-deadline-face (fraction)
  5654. "Return the face to displaying a deadline item.
  5655. FRACTION is what fraction of the head-warning time has passed."
  5656. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5657. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5658. "Return the scheduled information for agenda display.
  5659. Optional argument DEADLINES is a list of deadline items to be
  5660. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5661. scheduled items with an hour specification like [h]h:mm."
  5662. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5663. 'org-todo-regexp org-todo-regexp
  5664. 'org-complex-heading-regexp org-complex-heading-regexp
  5665. 'done-face 'org-agenda-done
  5666. 'mouse-face 'highlight
  5667. 'help-echo
  5668. (format "mouse-2 or RET jump to Org file %s"
  5669. (abbreviate-file-name buffer-file-name))))
  5670. (regexp (if with-hour
  5671. org-scheduled-time-hour-regexp
  5672. org-scheduled-time-regexp))
  5673. (today (org-today))
  5674. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5675. (current (calendar-absolute-from-gregorian date))
  5676. (deadline-pos
  5677. (mapcar (lambda (d)
  5678. (let ((m (get-text-property 0 'org-hd-marker d)))
  5679. (and m (marker-position m))))
  5680. deadlines))
  5681. scheduled-items)
  5682. (goto-char (point-min))
  5683. (while (re-search-forward regexp nil t)
  5684. (catch :skip
  5685. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5686. (org-agenda-skip)
  5687. (let* ((s (match-string 1))
  5688. (pos (1- (match-beginning 1)))
  5689. (todo-state (save-match-data (org-get-todo-state)))
  5690. (donep (member todo-state org-done-keywords))
  5691. (sexp? (string-prefix-p "%%" s))
  5692. ;; SCHEDULE is the scheduled date for the entry. It is
  5693. ;; either the bare date or the last repeat, according
  5694. ;; to `org-agenda-prefer-last-repeat'.
  5695. (schedule
  5696. (cond
  5697. (sexp? (org-agenda--timestamp-to-absolute s current))
  5698. ((or (eq org-agenda-prefer-last-repeat t)
  5699. (member todo-state org-agenda-prefer-last-repeat))
  5700. (org-agenda--timestamp-to-absolute
  5701. s today 'past (current-buffer) pos))
  5702. (t (org-agenda--timestamp-to-absolute s))))
  5703. ;; REPEAT is the future repeat closest from CURRENT,
  5704. ;; according to `org-agenda-show-future-repeats'. If
  5705. ;; the latter is nil, or if the time stamp has no
  5706. ;; repeat part, default to SCHEDULE.
  5707. (repeat
  5708. (cond
  5709. (sexp? schedule)
  5710. ((<= current today) schedule)
  5711. ((not org-agenda-show-future-repeats) schedule)
  5712. (t
  5713. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5714. (1+ today)
  5715. current)))
  5716. (org-agenda--timestamp-to-absolute
  5717. s base 'future (current-buffer) pos)))))
  5718. (diff (- current schedule))
  5719. (warntime (get-text-property (point) 'org-appt-warntime))
  5720. (pastschedp (< schedule today))
  5721. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5722. (suppress-delay
  5723. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5724. (org-entry-get nil "DEADLINE"))))
  5725. (cond
  5726. ((not deadline) nil)
  5727. ;; The current item has a deadline date, so
  5728. ;; evaluate its delay time.
  5729. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5730. ;; Use global delay time.
  5731. (- org-agenda-skip-scheduled-delay-if-deadline))
  5732. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5733. 'post-deadline)
  5734. ;; Set delay to no later than DEADLINE.
  5735. (min (- schedule
  5736. (org-agenda--timestamp-to-absolute deadline))
  5737. org-scheduled-delay-days))
  5738. (t 0))))
  5739. (ddays
  5740. (cond
  5741. ;; Nullify delay when a repeater triggered already
  5742. ;; and the delay is of the form --Xd.
  5743. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5744. (> schedule (org-agenda--timestamp-to-absolute s)))
  5745. 0)
  5746. (suppress-delay
  5747. (let ((org-scheduled-delay-days suppress-delay))
  5748. (org-get-wdays s t t)))
  5749. (t (org-get-wdays s t)))))
  5750. ;; Display scheduled items at base date (SCHEDULE), today if
  5751. ;; scheduled before the current date, and at any repeat past
  5752. ;; today. However, skip delayed items and items that have
  5753. ;; been displayed for more than `org-scheduled-past-days'.
  5754. (unless (and todayp
  5755. habitp
  5756. (bound-and-true-p org-habit-show-all-today))
  5757. (when (or (and (> ddays 0) (< diff ddays))
  5758. (> diff org-scheduled-past-days)
  5759. (> schedule current)
  5760. (and (/= current schedule)
  5761. (/= current today)
  5762. (/= current repeat)))
  5763. (throw :skip nil)))
  5764. ;; Possibly skip done tasks.
  5765. (when (and donep
  5766. (or org-agenda-skip-scheduled-if-done
  5767. (/= schedule current)))
  5768. (throw :skip nil))
  5769. ;; Skip entry if it already appears as a deadline, per
  5770. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5771. ;; doesn't apply to habits.
  5772. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5773. ((guard
  5774. (or (not (memq (line-beginning-position 0) deadline-pos))
  5775. habitp))
  5776. nil)
  5777. (`repeated-after-deadline
  5778. (let ((deadline (time-to-days
  5779. (org-get-deadline-time (point)))))
  5780. (and (<= schedule deadline) (> current deadline))))
  5781. (`not-today pastschedp)
  5782. (`t t)
  5783. (_ nil))
  5784. (throw :skip nil))
  5785. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5786. ;; only show them for today. Also skip done habits.
  5787. (when (and habitp
  5788. (or donep
  5789. (not (bound-and-true-p org-habit-show-habits))
  5790. (and (not todayp)
  5791. (bound-and-true-p
  5792. org-habit-show-habits-only-for-today))))
  5793. (throw :skip nil))
  5794. (save-excursion
  5795. (re-search-backward "^\\*+[ \t]+" nil t)
  5796. (goto-char (match-end 0))
  5797. (let* ((category (org-get-category))
  5798. (inherited-tags
  5799. (or (eq org-agenda-show-inherited-tags 'always)
  5800. (and (listp org-agenda-show-inherited-tags)
  5801. (memq 'agenda org-agenda-show-inherited-tags))
  5802. (and (eq org-agenda-show-inherited-tags t)
  5803. (or (eq org-agenda-use-tag-inheritance t)
  5804. (memq 'agenda
  5805. org-agenda-use-tag-inheritance)))))
  5806. (tags (org-get-tags nil (not inherited-tags)))
  5807. (level (make-string (org-reduced-level (org-outline-level))
  5808. ?\s))
  5809. (head (buffer-substring (point) (line-end-position)))
  5810. (time
  5811. (cond
  5812. ;; No time of day designation if it is only
  5813. ;; a reminder.
  5814. ((and (/= current schedule) (/= current repeat)) nil)
  5815. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5816. (concat (substring s (match-beginning 1)) " "))
  5817. (t 'time)))
  5818. (item
  5819. (org-agenda-format-item
  5820. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5821. ;; Show a reminder of a past scheduled today.
  5822. (if (and todayp pastschedp)
  5823. (format past diff)
  5824. first))
  5825. head level category tags time nil habitp))
  5826. (face (cond ((and (not habitp) pastschedp)
  5827. 'org-scheduled-previously)
  5828. (todayp 'org-scheduled-today)
  5829. (t 'org-scheduled)))
  5830. (habitp (and habitp (org-habit-parse-todo))))
  5831. (org-add-props item props
  5832. 'undone-face face
  5833. 'face (if donep 'org-agenda-done face)
  5834. 'org-marker (org-agenda-new-marker pos)
  5835. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5836. 'type (if pastschedp "past-scheduled" "scheduled")
  5837. 'date (if pastschedp schedule date)
  5838. 'ts-date schedule
  5839. 'warntime warntime
  5840. 'level level
  5841. 'priority (if habitp (org-habit-get-priority habitp)
  5842. (+ 99 diff (org-get-priority item)))
  5843. 'org-habit-p habitp
  5844. 'todo-state todo-state)
  5845. (push item scheduled-items))))))
  5846. (nreverse scheduled-items)))
  5847. (defun org-agenda-get-blocks ()
  5848. "Return the date-range information for agenda display."
  5849. (let* ((props (list 'face nil
  5850. 'org-not-done-regexp org-not-done-regexp
  5851. 'org-todo-regexp org-todo-regexp
  5852. 'org-complex-heading-regexp org-complex-heading-regexp
  5853. 'mouse-face 'highlight
  5854. 'help-echo
  5855. (format "mouse-2 or RET jump to org file %s"
  5856. (abbreviate-file-name buffer-file-name))))
  5857. (regexp org-tr-regexp)
  5858. (d0 (calendar-absolute-from-gregorian date))
  5859. marker hdmarker ee txt d1 d2 s1 s2 category
  5860. level todo-state tags pos head donep inherited-tags)
  5861. (goto-char (point-min))
  5862. (while (re-search-forward regexp nil t)
  5863. (catch :skip
  5864. (org-agenda-skip)
  5865. (setq pos (point))
  5866. (let ((start-time (match-string 1))
  5867. (end-time (match-string 2)))
  5868. (setq s1 (match-string 1)
  5869. s2 (match-string 2)
  5870. d1 (time-to-days
  5871. (condition-case err
  5872. (org-time-string-to-time s1)
  5873. (error
  5874. (error
  5875. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5876. s1
  5877. pos
  5878. (current-buffer)
  5879. (error-message-string err)))))
  5880. d2 (time-to-days
  5881. (condition-case err
  5882. (org-time-string-to-time s2)
  5883. (error
  5884. (error
  5885. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5886. s2
  5887. pos
  5888. (current-buffer)
  5889. (error-message-string err))))))
  5890. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5891. ;; Only allow days between the limits, because the normal
  5892. ;; date stamps will catch the limits.
  5893. (save-excursion
  5894. (setq todo-state (org-get-todo-state))
  5895. (setq donep (member todo-state org-done-keywords))
  5896. (when (and donep org-agenda-skip-timestamp-if-done)
  5897. (throw :skip t))
  5898. (setq marker (org-agenda-new-marker (point))
  5899. category (org-get-category))
  5900. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5901. (throw :skip nil)
  5902. (goto-char (match-beginning 0))
  5903. (setq hdmarker (org-agenda-new-marker (point))
  5904. inherited-tags
  5905. (or (eq org-agenda-show-inherited-tags 'always)
  5906. (and (listp org-agenda-show-inherited-tags)
  5907. (memq 'agenda org-agenda-show-inherited-tags))
  5908. (and (eq org-agenda-show-inherited-tags t)
  5909. (or (eq org-agenda-use-tag-inheritance t)
  5910. (memq 'agenda org-agenda-use-tag-inheritance))))
  5911. tags (org-get-tags nil (not inherited-tags)))
  5912. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5913. (looking-at "\\*+[ \t]+\\(.*\\)")
  5914. (setq head (match-string 1))
  5915. (let ((remove-re
  5916. (if org-agenda-remove-timeranges-from-blocks
  5917. (concat
  5918. "<" (regexp-quote s1) ".*?>"
  5919. "--"
  5920. "<" (regexp-quote s2) ".*?>")
  5921. nil)))
  5922. (setq txt (org-agenda-format-item
  5923. (format
  5924. (nth (if (= d1 d2) 0 1)
  5925. org-agenda-timerange-leaders)
  5926. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5927. head level category tags
  5928. (cond ((and (= d1 d0) (= d2 d0))
  5929. (concat "<" start-time ">--<" end-time ">"))
  5930. ((= d1 d0)
  5931. (concat "<" start-time ">"))
  5932. ((= d2 d0)
  5933. (concat "<" end-time ">")))
  5934. remove-re))))
  5935. (org-add-props txt props
  5936. 'org-marker marker 'org-hd-marker hdmarker
  5937. 'type "block" 'date date
  5938. 'level level
  5939. 'todo-state todo-state
  5940. 'priority (org-get-priority txt))
  5941. (push txt ee))))
  5942. (goto-char pos)))
  5943. ;; Sort the entries by expiration date.
  5944. (nreverse ee)))
  5945. ;;; Agenda presentation and sorting
  5946. (defvar org-prefix-has-time nil
  5947. "A flag, set by `org-compile-prefix-format'.
  5948. The flag is set if the currently compiled format contains a `%t'.")
  5949. (defvar org-prefix-has-tag nil
  5950. "A flag, set by `org-compile-prefix-format'.
  5951. The flag is set if the currently compiled format contains a `%T'.")
  5952. (defvar org-prefix-has-effort nil
  5953. "A flag, set by `org-compile-prefix-format'.
  5954. The flag is set if the currently compiled format contains a `%e'.")
  5955. (defvar org-prefix-has-breadcrumbs nil
  5956. "A flag, set by `org-compile-prefix-format'.
  5957. The flag is set if the currently compiled format contains a `%b'.")
  5958. (defvar org-prefix-category-length nil
  5959. "Used by `org-compile-prefix-format' to remember the category field width.")
  5960. (defvar org-prefix-category-max-length nil
  5961. "Used by `org-compile-prefix-format' to remember the category field width.")
  5962. (defun org-agenda-get-category-icon (category)
  5963. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5964. (cl-dolist (entry org-agenda-category-icon-alist)
  5965. (when (string-match-p (car entry) category)
  5966. (if (listp (cadr entry))
  5967. (cl-return (cadr entry))
  5968. (cl-return (apply #'create-image (cdr entry)))))))
  5969. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5970. remove-re habitp)
  5971. "Format TXT to be inserted into the agenda buffer.
  5972. In particular, add the prefix and corresponding text properties.
  5973. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5974. LEVEL may be a string to replace the `%l' specifier.
  5975. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5976. category taken from local variable or file name. It will replace the `%c'
  5977. specifier in the format.
  5978. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5979. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5980. When DOTIME is a string, this string is searched for a time before TXT is.
  5981. TAGS can be the tags of the headline.
  5982. Any match of REMOVE-RE will be removed from TXT."
  5983. ;; We keep the org-prefix-* variable values along with a compiled
  5984. ;; formatter, so that multiple agendas existing at the same time do
  5985. ;; not step on each other toes.
  5986. ;;
  5987. ;; It was inconvenient to make these variables buffer local in
  5988. ;; Agenda buffers, because this function expects to be called with
  5989. ;; the buffer where item comes from being current, and not agenda
  5990. ;; buffer
  5991. (let* ((bindings (car org-prefix-format-compiled))
  5992. (formatter (cadr org-prefix-format-compiled)))
  5993. (cl-loop for (var value) in bindings
  5994. do (set var value))
  5995. (save-match-data
  5996. ;; Diary entries sometimes have extra whitespace at the beginning
  5997. (setq txt (org-trim txt))
  5998. ;; Fix the tags part in txt
  5999. (setq txt (org-agenda-fix-displayed-tags
  6000. txt tags
  6001. org-agenda-show-inherited-tags
  6002. org-agenda-hide-tags-regexp))
  6003. (let* ((category (or category
  6004. (if buffer-file-name
  6005. (file-name-sans-extension
  6006. (file-name-nondirectory buffer-file-name))
  6007. "")))
  6008. (category-icon (org-agenda-get-category-icon category))
  6009. (category-icon (if category-icon
  6010. (propertize " " 'display category-icon)
  6011. ""))
  6012. (effort (and (not (string= txt ""))
  6013. (get-text-property 1 'effort txt)))
  6014. ;; time, tag, effort are needed for the eval of the prefix format
  6015. (tag (if tags (nth (1- (length tags)) tags) ""))
  6016. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6017. time
  6018. (ts (when dotime (concat
  6019. (if (stringp dotime) dotime "")
  6020. (and org-agenda-search-headline-for-time txt))))
  6021. (time-of-day (and dotime (org-get-time-of-day ts)))
  6022. stamp plain s0 s1 s2 rtn srp l
  6023. duration breadcrumbs)
  6024. (and (derived-mode-p 'org-mode) buffer-file-name
  6025. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6026. (when (and dotime time-of-day)
  6027. ;; Extract starting and ending time and move them to prefix
  6028. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6029. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6030. (setq s0 (match-string 0 ts)
  6031. srp (and stamp (match-end 3))
  6032. s1 (match-string (if plain 1 2) ts)
  6033. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6034. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6035. ;; them, we might want to remove them there to avoid duplication.
  6036. ;; The user can turn this off with a variable.
  6037. (when (and org-prefix-has-time
  6038. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6039. (string-match (concat (regexp-quote s0) " *") txt)
  6040. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6041. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6042. (= (match-beginning 0) 0)
  6043. t))
  6044. (setq txt (replace-match "" nil nil txt))))
  6045. ;; Normalize the time(s) to 24 hour
  6046. (when s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6047. (when s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6048. ;; Try to set s2 if s1 and
  6049. ;; `org-agenda-default-appointment-duration' are set
  6050. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6051. (setq s2
  6052. (org-duration-from-minutes
  6053. (+ (org-duration-to-minutes s1 t)
  6054. org-agenda-default-appointment-duration)
  6055. nil t)))
  6056. ;; Compute the duration
  6057. (when s2
  6058. (setq duration (- (org-duration-to-minutes s2)
  6059. (org-duration-to-minutes s1)))))
  6060. (when (string-match org-tag-group-re txt)
  6061. ;; Tags are in the string
  6062. (if (or (eq org-agenda-remove-tags t)
  6063. (and org-agenda-remove-tags
  6064. org-prefix-has-tag))
  6065. (setq txt (replace-match "" t t txt))
  6066. (setq txt (replace-match
  6067. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6068. (match-string 1 txt))
  6069. t t txt))))
  6070. (when remove-re
  6071. (while (string-match remove-re txt)
  6072. (setq txt (replace-match "" t t txt))))
  6073. ;; Set org-heading property on `txt' to mark the start of the
  6074. ;; heading.
  6075. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6076. ;; Prepare the variables needed in the eval of the compiled format
  6077. (when org-prefix-has-breadcrumbs
  6078. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6079. (let ((s (org-format-outline-path (org-get-outline-path)
  6080. (1- (frame-width))
  6081. nil "->")))
  6082. (if (eq "" s) "" (concat s "->"))))))
  6083. (setq time (cond (s2 (concat
  6084. (org-agenda-time-of-day-to-ampm-maybe s1)
  6085. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6086. (when org-agenda-timegrid-use-ampm " ")))
  6087. (s1 (concat
  6088. (org-agenda-time-of-day-to-ampm-maybe s1)
  6089. (if org-agenda-timegrid-use-ampm
  6090. (concat time-grid-trailing-characters " ")
  6091. time-grid-trailing-characters)))
  6092. (t ""))
  6093. extra (or (and (not habitp) extra) "")
  6094. category (if (symbolp category) (symbol-name category) category)
  6095. level (or level ""))
  6096. (if (string-match org-bracket-link-regexp category)
  6097. (progn
  6098. (setq l (if (match-end 3)
  6099. (- (match-end 3) (match-beginning 3))
  6100. (- (match-end 1) (match-beginning 1))))
  6101. (when (< l (or org-prefix-category-length 0))
  6102. (setq category (copy-sequence category))
  6103. (org-add-props category nil
  6104. 'extra-space (make-string
  6105. (- org-prefix-category-length l 1) ?\ ))))
  6106. (when (and org-prefix-category-max-length
  6107. (>= (length category) org-prefix-category-max-length))
  6108. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6109. ;; Evaluate the compiled format
  6110. (setq rtn (concat (eval formatter) txt))
  6111. ;; And finally add the text properties
  6112. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6113. (org-add-props rtn nil
  6114. 'org-category category
  6115. 'tags (mapcar 'org-downcase-keep-props tags)
  6116. 'org-highest-priority org-highest-priority
  6117. 'org-lowest-priority org-lowest-priority
  6118. 'time-of-day time-of-day
  6119. 'duration duration
  6120. 'breadcrumbs breadcrumbs
  6121. 'txt txt
  6122. 'level level
  6123. 'time time
  6124. 'extra extra
  6125. 'format org-prefix-format-compiled
  6126. 'dotime dotime)))))
  6127. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6128. "Remove tags string from TXT, and add a modified list of tags.
  6129. The modified list may contain inherited tags, and tags matched by
  6130. `org-agenda-hide-tags-regexp' will be removed."
  6131. (when (or add-inherited hide-re)
  6132. (when (string-match org-tag-group-re txt)
  6133. (setq txt (substring txt 0 (match-beginning 0))))
  6134. (setq tags
  6135. (delq nil
  6136. (mapcar (lambda (tg)
  6137. (if (or (and hide-re (string-match hide-re tg))
  6138. (and (not add-inherited)
  6139. (get-text-property 0 'inherited tg)))
  6140. nil
  6141. tg))
  6142. tags)))
  6143. (when tags
  6144. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6145. i)
  6146. (setq txt (concat txt " :"
  6147. (mapconcat
  6148. (lambda (x)
  6149. (setq i (get-text-property 0 'inherited x))
  6150. (if (and have-i (not i))
  6151. (progn
  6152. (setq have-i nil)
  6153. (concat ":" x))
  6154. x))
  6155. tags ":")
  6156. (if have-i "::" ":"))))))
  6157. txt)
  6158. (defun org-downcase-keep-props (s)
  6159. (let ((props (text-properties-at 0 s)))
  6160. (setq s (downcase s))
  6161. (add-text-properties 0 (length s) props s)
  6162. s))
  6163. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6164. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6165. "Add a time-grid for agenda items which need it.
  6166. LIST is the list of agenda items formatted by `org-agenda-list'.
  6167. NDAYS is the span of the current agenda view.
  6168. TODAYP is t when the current agenda view is on today."
  6169. (catch 'exit
  6170. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6171. ((and todayp (member 'today (car org-agenda-time-grid))))
  6172. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6173. ((member 'weekly (car org-agenda-time-grid)))
  6174. (t (throw 'exit list)))
  6175. (let* ((have (delq nil (mapcar
  6176. (lambda (x) (get-text-property 1 'time-of-day x))
  6177. list)))
  6178. (string (nth 3 org-agenda-time-grid))
  6179. (gridtimes (nth 1 org-agenda-time-grid))
  6180. (req (car org-agenda-time-grid))
  6181. (remove (member 'remove-match req))
  6182. new time)
  6183. (when (and (member 'require-timed req) (not have))
  6184. ;; don't show empty grid
  6185. (throw 'exit list))
  6186. (while (setq time (pop gridtimes))
  6187. (unless (and remove (member time have))
  6188. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6189. (push (org-agenda-format-item
  6190. nil string nil "" nil
  6191. (concat (substring time 0 -2) ":" (substring time -2)))
  6192. new)
  6193. (put-text-property
  6194. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6195. (when (and todayp org-agenda-show-current-time-in-grid)
  6196. (push (org-agenda-format-item
  6197. nil org-agenda-current-time-string nil "" nil
  6198. (format-time-string "%H:%M "))
  6199. new)
  6200. (put-text-property
  6201. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6202. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6203. (append new list)
  6204. (append list new)))))
  6205. (defun org-compile-prefix-format (key)
  6206. "Compile the prefix format into a Lisp form that can be evaluated.
  6207. The resulting form and associated variable bindings is returned
  6208. and stored in the variable `org-prefix-format-compiled'."
  6209. (setq org-prefix-has-time nil
  6210. org-prefix-has-tag nil
  6211. org-prefix-category-length nil
  6212. org-prefix-has-effort nil
  6213. org-prefix-has-breadcrumbs nil)
  6214. (let ((s (cond
  6215. ((stringp org-agenda-prefix-format)
  6216. org-agenda-prefix-format)
  6217. ((assq key org-agenda-prefix-format)
  6218. (cdr (assq key org-agenda-prefix-format)))
  6219. (t " %-12:c%?-12t% s")))
  6220. (start 0)
  6221. varform vars var e c f opt)
  6222. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6223. s start)
  6224. (setq var (or (cdr (assoc (match-string 4 s)
  6225. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6226. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6227. 'eval)
  6228. c (or (match-string 3 s) "")
  6229. opt (match-beginning 1)
  6230. start (1+ (match-beginning 0)))
  6231. (cl-case var
  6232. (time (setq org-prefix-has-time t))
  6233. (tag (setq org-prefix-has-tag t))
  6234. (effort (setq org-prefix-has-effort t))
  6235. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6236. (setq f (concat "%" (match-string 2 s) "s"))
  6237. (when (eq var 'category)
  6238. (setq org-prefix-category-length
  6239. (floor (abs (string-to-number (match-string 2 s)))))
  6240. (setq org-prefix-category-max-length
  6241. (let ((x (match-string 2 s)))
  6242. (when (string-match-p "\\.[0-9]+" x)
  6243. (string-to-number (substring (match-string 0 x) 1))))))
  6244. (if (eq var 'eval)
  6245. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6246. (if opt
  6247. (setq varform
  6248. `(if (or (equal "" ,var) (equal nil ,var))
  6249. ""
  6250. (format ,f (concat ,var ,c))))
  6251. (setq varform
  6252. `(format ,f (if (or (equal ,var "")
  6253. (equal ,var nil)) ""
  6254. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6255. (setq s (replace-match "%s" t nil s))
  6256. (push varform vars))
  6257. (setq vars (nreverse vars))
  6258. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6259. (setq org-prefix-format-compiled
  6260. (list
  6261. `((org-prefix-has-time ,org-prefix-has-time)
  6262. (org-prefix-has-tag ,org-prefix-has-tag)
  6263. (org-prefix-category-length ,org-prefix-category-length)
  6264. (org-prefix-has-effort ,org-prefix-has-effort)
  6265. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6266. `(format ,s ,@vars))))))
  6267. (defun org-set-sorting-strategy (key)
  6268. (if (symbolp (car org-agenda-sorting-strategy))
  6269. ;; the old format
  6270. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6271. (setq org-agenda-sorting-strategy-selected
  6272. (or (cdr (assq key org-agenda-sorting-strategy))
  6273. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6274. '(time-up category-keep priority-down)))))
  6275. (defun org-get-time-of-day (s &optional string mod24)
  6276. "Check string S for a time of day.
  6277. If found, return it as a military time number between 0 and 2400.
  6278. If not found, return nil.
  6279. The optional STRING argument forces conversion into a 5 character wide string
  6280. HH:MM."
  6281. (save-match-data
  6282. (when
  6283. (and
  6284. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6285. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6286. (not (eq (get-text-property 1 'face s) 'org-link)))
  6287. (let* ((h (string-to-number (match-string 1 s)))
  6288. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6289. (ampm (when (match-end 4) (downcase (match-string 4 s))))
  6290. (am-p (equal ampm "am"))
  6291. (h1 (cond ((not ampm) h)
  6292. ((= h 12) (if am-p 0 12))
  6293. (t (+ h (if am-p 0 12)))))
  6294. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6295. (mod h1 24) h1))
  6296. (t0 (+ (* 100 h2) m))
  6297. (t1 (concat (if (>= h1 24) "+" " ")
  6298. (if (and org-agenda-time-leading-zero
  6299. (< t0 1000)) "0" "")
  6300. (if (< t0 100) "0" "")
  6301. (if (< t0 10) "0" "")
  6302. (int-to-string t0))))
  6303. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6304. (defvar org-agenda-before-sorting-filter-function nil
  6305. "Function to be applied to agenda items prior to sorting.
  6306. Prior to sorting also means just before they are inserted into the agenda.
  6307. To aid sorting, you may revisit the original entries and add more text
  6308. properties which will later be used by the sorting functions.
  6309. The function should take a string argument, an agenda line.
  6310. It has access to the text properties in that line, which contain among
  6311. other things, the property `org-hd-marker' that points to the entry
  6312. where the line comes from. Note that not all lines going into the agenda
  6313. have this property, only most.
  6314. The function should return the modified string. It is probably best
  6315. to ONLY change text properties.
  6316. You can also use this function as a filter, by returning nil for lines
  6317. you don't want to have in the agenda at all. For this application, you
  6318. could bind the variable in the options section of a custom command.")
  6319. (defun org-agenda-finalize-entries (list &optional type)
  6320. "Sort, limit and concatenate the LIST of agenda items.
  6321. The optional argument TYPE tells the agenda type."
  6322. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6323. (cdr (assoc type org-agenda-max-effort)))
  6324. (t org-agenda-max-effort)))
  6325. (max-todo (cond ((listp org-agenda-max-todos)
  6326. (cdr (assoc type org-agenda-max-todos)))
  6327. (t org-agenda-max-todos)))
  6328. (max-tags (cond ((listp org-agenda-max-tags)
  6329. (cdr (assoc type org-agenda-max-tags)))
  6330. (t org-agenda-max-tags)))
  6331. (max-entries (cond ((listp org-agenda-max-entries)
  6332. (cdr (assoc type org-agenda-max-entries)))
  6333. (t org-agenda-max-entries))))
  6334. (when org-agenda-before-sorting-filter-function
  6335. (setq list
  6336. (delq nil
  6337. (mapcar
  6338. org-agenda-before-sorting-filter-function list))))
  6339. (setq list (mapcar 'org-agenda-highlight-todo list)
  6340. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6341. (when max-effort
  6342. (setq list (org-agenda-limit-entries
  6343. list 'effort-minutes max-effort
  6344. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6345. 32767 -1))))))
  6346. (when max-todo
  6347. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6348. (when max-tags
  6349. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6350. (when max-entries
  6351. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6352. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6353. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6354. (mapconcat 'identity list "\n")))
  6355. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6356. "Limit the number of agenda entries."
  6357. (let ((include (and limit (< limit 0))))
  6358. (if limit
  6359. (let ((fun (or fn (lambda (p) (when p 1))))
  6360. (lim 0))
  6361. (delq nil
  6362. (mapcar
  6363. (lambda (e)
  6364. (let ((pval (funcall
  6365. fun (get-text-property (1- (length e))
  6366. prop e))))
  6367. (when pval (setq lim (+ lim pval)))
  6368. (cond ((and pval (<= lim (abs limit))) e)
  6369. ((and include (not pval)) e))))
  6370. list)))
  6371. list)))
  6372. (defun org-agenda-limit-interactively (remove)
  6373. "In agenda, interactively limit entries to various maximums."
  6374. (interactive "P")
  6375. (if remove
  6376. (progn (setq org-agenda-max-entries nil
  6377. org-agenda-max-todos nil
  6378. org-agenda-max-tags nil
  6379. org-agenda-max-effort nil)
  6380. (org-agenda-redo))
  6381. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6382. (msg (cond ((= max ?E) "How many minutes? ")
  6383. ((= max ?e) "How many entries? ")
  6384. ((= max ?t) "How many TODO entries? ")
  6385. ((= max ?T) "How many tagged entries? ")
  6386. (t (user-error "Wrong input"))))
  6387. (num (string-to-number (read-from-minibuffer msg))))
  6388. (cond ((equal max ?e)
  6389. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6390. ((equal max ?t)
  6391. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6392. ((equal max ?T)
  6393. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6394. ((equal max ?E)
  6395. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6396. (org-agenda-fit-window-to-buffer))
  6397. (defun org-agenda-highlight-todo (x)
  6398. (let ((org-done-keywords org-done-keywords-for-agenda)
  6399. (case-fold-search nil)
  6400. re)
  6401. (if (eq x 'line)
  6402. (save-excursion
  6403. (beginning-of-line 1)
  6404. (setq re (org-get-at-bol 'org-todo-regexp))
  6405. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6406. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6407. (add-text-properties (match-beginning 0) (match-end 1)
  6408. (list 'face (org-get-todo-face 1)))
  6409. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6410. (delete-region (match-beginning 1) (1- (match-end 0)))
  6411. (goto-char (match-beginning 1))
  6412. (insert (format org-agenda-todo-keyword-format s)))))
  6413. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6414. (setq re (get-text-property 0 'org-todo-regexp x))
  6415. (when (and re
  6416. ;; Test `pl' because if there's no heading content,
  6417. ;; there's no point matching to highlight. Note
  6418. ;; that if we didn't test `pl' first, and there
  6419. ;; happened to be no keyword from `org-todo-regexp'
  6420. ;; on this heading line, then the `equal' comparison
  6421. ;; afterwards would spuriously succeed in the case
  6422. ;; where `pl' is nil -- causing an args-out-of-range
  6423. ;; error when we try to add text properties to text
  6424. ;; that isn't there.
  6425. pl
  6426. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6427. x pl) pl))
  6428. (add-text-properties
  6429. (or (match-end 1) (match-end 0)) (match-end 0)
  6430. (list 'face (org-get-todo-face (match-string 2 x)))
  6431. x)
  6432. (when (match-end 1)
  6433. (setq x
  6434. (concat
  6435. (substring x 0 (match-end 1))
  6436. (format org-agenda-todo-keyword-format
  6437. (match-string 2 x))
  6438. ;; Remove `display' property as the icon could leak
  6439. ;; on the white space.
  6440. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6441. 'display))
  6442. (substring x (match-end 3)))))))
  6443. x)))
  6444. (defsubst org-cmp-values (a b property)
  6445. "Compare the numeric value of text PROPERTY for string A and B."
  6446. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6447. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6448. (cond ((> pa pb) +1)
  6449. ((< pa pb) -1))))
  6450. (defsubst org-cmp-effort (a b)
  6451. "Compare the effort values of string A and B."
  6452. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6453. ;; `effort-minutes' property is not directly accessible from
  6454. ;; the strings, but is stored as a property in `txt'.
  6455. (ea (or (get-text-property
  6456. 0 'effort-minutes (get-text-property 0 'txt a))
  6457. def))
  6458. (eb (or (get-text-property
  6459. 0 'effort-minutes (get-text-property 0 'txt b))
  6460. def)))
  6461. (cond ((> ea eb) +1)
  6462. ((< ea eb) -1))))
  6463. (defsubst org-cmp-category (a b)
  6464. "Compare the string values of categories of strings A and B."
  6465. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6466. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6467. (cond ((string-lessp ca cb) -1)
  6468. ((string-lessp cb ca) +1))))
  6469. (defsubst org-cmp-todo-state (a b)
  6470. "Compare the todo states of strings A and B."
  6471. (let* ((ma (or (get-text-property 1 'org-marker a)
  6472. (get-text-property 1 'org-hd-marker a)))
  6473. (mb (or (get-text-property 1 'org-marker b)
  6474. (get-text-property 1 'org-hd-marker b)))
  6475. (fa (and ma (marker-buffer ma)))
  6476. (fb (and mb (marker-buffer mb)))
  6477. (todo-kwds
  6478. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6479. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6480. (ta (or (get-text-property 1 'todo-state a) ""))
  6481. (tb (or (get-text-property 1 'todo-state b) ""))
  6482. (la (- (length (member ta todo-kwds))))
  6483. (lb (- (length (member tb todo-kwds))))
  6484. (donepa (member ta org-done-keywords-for-agenda))
  6485. (donepb (member tb org-done-keywords-for-agenda)))
  6486. (cond ((and donepa (not donepb)) -1)
  6487. ((and (not donepa) donepb) +1)
  6488. ((< la lb) -1)
  6489. ((< lb la) +1))))
  6490. (defsubst org-cmp-alpha (a b)
  6491. "Compare the headlines, alphabetically."
  6492. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6493. (plb (text-property-any 0 (length b) 'org-heading t b))
  6494. (ta (and pla (substring a pla)))
  6495. (tb (and plb (substring b plb)))
  6496. (case-fold-search nil))
  6497. (when pla
  6498. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6499. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6500. (setq ta (substring ta (match-end 0))))
  6501. (setq ta (downcase ta)))
  6502. (when plb
  6503. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6504. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6505. (setq tb (substring tb (match-end 0))))
  6506. (setq tb (downcase tb)))
  6507. (cond ((not (or ta tb)) nil)
  6508. ((not ta) +1)
  6509. ((not tb) -1)
  6510. ((string-lessp ta tb) -1)
  6511. ((string-lessp tb ta) +1))))
  6512. (defsubst org-cmp-tag (a b)
  6513. "Compare the string values of the first tags of A and B."
  6514. (let ((ta (car (last (get-text-property 1 'tags a))))
  6515. (tb (car (last (get-text-property 1 'tags b)))))
  6516. (cond ((not (or ta tb)) nil)
  6517. ((not ta) +1)
  6518. ((not tb) -1)
  6519. ((string-lessp ta tb) -1)
  6520. ((string-lessp tb ta) +1))))
  6521. (defsubst org-cmp-time (a b)
  6522. "Compare the time-of-day values of strings A and B."
  6523. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6524. (ta (or (get-text-property 1 'time-of-day a) def))
  6525. (tb (or (get-text-property 1 'time-of-day b) def)))
  6526. (cond ((< ta tb) -1)
  6527. ((< tb ta) +1))))
  6528. (defsubst org-cmp-ts (a b type)
  6529. "Compare the timestamps values of entries A and B.
  6530. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6531. \"timestamp_ia\", compare within each of these type. When TYPE
  6532. is the empty string, compare all timestamps without respect of
  6533. their type."
  6534. (let* ((def (and (not org-sort-agenda-notime-is-late) -1))
  6535. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6536. (get-text-property 1 'ts-date a))
  6537. def))
  6538. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6539. (get-text-property 1 'ts-date b))
  6540. def)))
  6541. (cond ((if ta (and tb (< ta tb)) tb) -1)
  6542. ((if tb (and ta (< tb ta)) ta) +1))))
  6543. (defsubst org-cmp-habit-p (a b)
  6544. "Compare the todo states of strings A and B."
  6545. (let ((ha (get-text-property 1 'org-habit-p a))
  6546. (hb (get-text-property 1 'org-habit-p b)))
  6547. (cond ((and ha (not hb)) -1)
  6548. ((and (not ha) hb) +1))))
  6549. (defun org-entries-lessp (a b)
  6550. "Predicate for sorting agenda entries."
  6551. ;; The following variables will be used when the form is evaluated.
  6552. ;; So even though the compiler complains, keep them.
  6553. (let* ((ss org-agenda-sorting-strategy-selected)
  6554. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6555. (org-cmp-ts a b "")))
  6556. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6557. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6558. (org-cmp-ts a b "scheduled")))
  6559. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6560. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6561. (org-cmp-ts a b "deadline")))
  6562. (deadline-down (if deadline-up (- deadline-up) nil))
  6563. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6564. (org-cmp-ts a b "timestamp_ia")))
  6565. (tsia-down (if tsia-up (- tsia-up) nil))
  6566. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6567. (org-cmp-ts a b "timestamp")))
  6568. (ts-down (if ts-up (- ts-up) nil))
  6569. (time-up (and (org-em 'time-up 'time-down ss)
  6570. (org-cmp-time a b)))
  6571. (time-down (if time-up (- time-up) nil))
  6572. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6573. (org-cmp-values a b 'org-stats)))
  6574. (stats-down (if stats-up (- stats-up) nil))
  6575. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6576. (org-cmp-values a b 'priority)))
  6577. (priority-down (if priority-up (- priority-up) nil))
  6578. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6579. (org-cmp-effort a b)))
  6580. (effort-down (if effort-up (- effort-up) nil))
  6581. (category-up (and (or (org-em 'category-up 'category-down ss)
  6582. (memq 'category-keep ss))
  6583. (org-cmp-category a b)))
  6584. (category-down (if category-up (- category-up) nil))
  6585. (category-keep (if category-up +1 nil))
  6586. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6587. (org-cmp-tag a b)))
  6588. (tag-down (if tag-up (- tag-up) nil))
  6589. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6590. (org-cmp-todo-state a b)))
  6591. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6592. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6593. (org-cmp-habit-p a b)))
  6594. (habit-down (if habit-up (- habit-up) nil))
  6595. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6596. (org-cmp-alpha a b)))
  6597. (alpha-down (if alpha-up (- alpha-up) nil))
  6598. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6599. user-defined-up user-defined-down)
  6600. (when (and need-user-cmp org-agenda-cmp-user-defined
  6601. (functionp org-agenda-cmp-user-defined))
  6602. (setq user-defined-up
  6603. (funcall org-agenda-cmp-user-defined a b)
  6604. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6605. (cdr (assoc
  6606. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6607. '((-1 . t) (1 . nil) (nil . nil))))))
  6608. ;;; Agenda restriction lock
  6609. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6610. "Overlay to mark the headline to which agenda commands are restricted.")
  6611. (overlay-put org-agenda-restriction-lock-overlay
  6612. 'face 'org-agenda-restriction-lock)
  6613. (overlay-put org-agenda-restriction-lock-overlay
  6614. 'help-echo "Agendas are currently limited to this subtree.")
  6615. (delete-overlay org-agenda-restriction-lock-overlay)
  6616. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6617. "Set the restriction lock to the agenda item at point from within the agenda.
  6618. When called with a `\\[universal-argument]' prefix, restrict to
  6619. the file which contains the item.
  6620. Argument ARG is the prefix argument."
  6621. (interactive "P")
  6622. (unless (derived-mode-p 'org-agenda-mode)
  6623. (user-error "Not in an Org agenda buffer"))
  6624. (let* ((marker (or (org-get-at-bol 'org-marker)
  6625. (org-agenda-error)))
  6626. (buffer (marker-buffer marker))
  6627. (pos (marker-position marker)))
  6628. (with-current-buffer buffer
  6629. (goto-char pos)
  6630. (org-agenda-set-restriction-lock arg))))
  6631. ;;;###autoload
  6632. (defun org-agenda-set-restriction-lock (&optional type)
  6633. "Set restriction lock for agenda to current subtree or file.
  6634. When in a restricted subtree, remove it.
  6635. The restriction will span over the entire file if TYPE is `file',
  6636. or if type is '(4), or if the cursor is before the first headline
  6637. in the file. Otherwise, only apply the restriction to the current
  6638. subtree."
  6639. (interactive "P")
  6640. (if (and org-agenda-overriding-restriction
  6641. (member org-agenda-restriction-lock-overlay
  6642. (overlays-at (point)))
  6643. (equal (overlay-start org-agenda-restriction-lock-overlay)
  6644. (point)))
  6645. (org-agenda-remove-restriction-lock 'noupdate)
  6646. (org-agenda-remove-restriction-lock 'noupdate)
  6647. (and (equal type '(4)) (setq type 'file))
  6648. (setq type (cond
  6649. (type type)
  6650. ((org-at-heading-p) 'subtree)
  6651. ((condition-case nil (org-back-to-heading t) (error nil))
  6652. 'subtree)
  6653. (t 'file)))
  6654. (if (eq type 'subtree)
  6655. (progn
  6656. (setq org-agenda-restrict (current-buffer))
  6657. (setq org-agenda-overriding-restriction 'subtree)
  6658. (put 'org-agenda-files 'org-restrict
  6659. (list (buffer-file-name (buffer-base-buffer))))
  6660. (org-back-to-heading t)
  6661. (move-overlay org-agenda-restriction-lock-overlay
  6662. (point)
  6663. (if org-agenda-restriction-lock-highlight-subtree
  6664. (save-excursion (org-end-of-subtree t t) (point))
  6665. (point-at-eol)))
  6666. (move-marker org-agenda-restrict-begin (point))
  6667. (move-marker org-agenda-restrict-end
  6668. (save-excursion (org-end-of-subtree t t)))
  6669. (message "Locking agenda restriction to subtree"))
  6670. (put 'org-agenda-files 'org-restrict
  6671. (list (buffer-file-name (buffer-base-buffer))))
  6672. (setq org-agenda-restrict nil)
  6673. (setq org-agenda-overriding-restriction 'file)
  6674. (move-marker org-agenda-restrict-begin nil)
  6675. (move-marker org-agenda-restrict-end nil)
  6676. (message "Locking agenda restriction to file"))
  6677. (setq current-prefix-arg nil))
  6678. (org-agenda-maybe-redo))
  6679. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6680. "Remove agenda restriction lock."
  6681. (interactive "P")
  6682. (if (not org-agenda-restrict)
  6683. (message "No agenda restriction to remove.")
  6684. (delete-overlay org-agenda-restriction-lock-overlay)
  6685. (delete-overlay org-speedbar-restriction-lock-overlay)
  6686. (setq org-agenda-overriding-restriction nil)
  6687. (setq org-agenda-restrict nil)
  6688. (put 'org-agenda-files 'org-restrict nil)
  6689. (move-marker org-agenda-restrict-begin nil)
  6690. (move-marker org-agenda-restrict-end nil)
  6691. (setq current-prefix-arg nil)
  6692. (message "Agenda restriction lock removed")
  6693. (or noupdate (org-agenda-maybe-redo))))
  6694. (defun org-agenda-maybe-redo ()
  6695. "If there is any window showing the agenda view, update it."
  6696. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6697. org-agenda-buffer-name)
  6698. t))
  6699. (w0 (selected-window)))
  6700. (when w
  6701. (select-window w)
  6702. (org-agenda-redo)
  6703. (select-window w0)
  6704. (if org-agenda-overriding-restriction
  6705. (message "Agenda view shifted to new %s restriction"
  6706. org-agenda-overriding-restriction)
  6707. (message "Agenda restriction lock removed")))))
  6708. ;;; Agenda commands
  6709. (defun org-agenda-check-type (error &rest types)
  6710. "Check if agenda buffer is of allowed type.
  6711. If ERROR is non-nil, throw an error, otherwise just return nil.
  6712. Allowed types are `agenda' `todo' `tags' `search'."
  6713. (cond ((not org-agenda-type)
  6714. (error "No Org agenda currently displayed"))
  6715. ((memq org-agenda-type types) t)
  6716. (error
  6717. (error "Not allowed in %s-type agenda buffers" org-agenda-type))
  6718. (t nil)))
  6719. (defun org-agenda-Quit ()
  6720. "Exit the agenda, killing the agenda buffer.
  6721. Like `org-agenda-quit', but kill the buffer even when
  6722. `org-agenda-sticky' is non-nil."
  6723. (interactive)
  6724. (org-agenda--quit))
  6725. (defun org-agenda-quit ()
  6726. "Exit the agenda.
  6727. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6728. instead of killing it.
  6729. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6730. the pre-agenda window configuration.
  6731. When column view is active, exit column view instead of the
  6732. agenda."
  6733. (interactive)
  6734. (org-agenda--quit org-agenda-sticky))
  6735. (defun org-agenda--quit (&optional bury)
  6736. (if org-agenda-columns-active
  6737. (org-columns-quit)
  6738. (let ((wconf org-agenda-pre-window-conf)
  6739. (buf (current-buffer))
  6740. (org-agenda-last-indirect-window
  6741. (and (eq org-indirect-buffer-display 'other-window)
  6742. org-agenda-last-indirect-buffer
  6743. (get-buffer-window org-agenda-last-indirect-buffer))))
  6744. (cond
  6745. ((eq org-agenda-window-setup 'other-frame)
  6746. (delete-frame))
  6747. ((and org-agenda-restore-windows-after-quit
  6748. wconf)
  6749. ;; Maybe restore the pre-agenda window configuration. Reset
  6750. ;; `org-agenda-pre-window-conf' before running
  6751. ;; `set-window-configuration', which loses the current buffer.
  6752. (setq org-agenda-pre-window-conf nil)
  6753. (set-window-configuration wconf))
  6754. (t
  6755. (when org-agenda-last-indirect-window
  6756. (delete-window org-agenda-last-indirect-window))
  6757. (and (not (eq org-agenda-window-setup 'current-window))
  6758. (not (one-window-p))
  6759. (delete-window))))
  6760. (if bury
  6761. ;; Set the agenda buffer as the current buffer instead of
  6762. ;; passing it as an argument to `bury-buffer' so that
  6763. ;; `bury-buffer' removes it from the window.
  6764. (with-current-buffer buf
  6765. (bury-buffer))
  6766. (kill-buffer buf)
  6767. (setq org-agenda-archives-mode nil
  6768. org-agenda-buffer nil)))))
  6769. (defun org-agenda-exit ()
  6770. "Exit the agenda, killing Org buffers loaded by the agenda.
  6771. Like `org-agenda-Quit', but kill any buffers that were created by
  6772. the agenda. Org buffers visited directly by the user will not be
  6773. touched. Also, exit the agenda even if it is in column view."
  6774. (interactive)
  6775. (when org-agenda-columns-active
  6776. (org-columns-quit))
  6777. (org-release-buffers org-agenda-new-buffers)
  6778. (setq org-agenda-new-buffers nil)
  6779. (org-agenda-Quit))
  6780. (defun org-agenda-kill-all-agenda-buffers ()
  6781. "Kill all buffers in `org-agenda-mode'.
  6782. This is used when toggling sticky agendas."
  6783. (interactive)
  6784. (let (blist)
  6785. (dolist (buf (buffer-list))
  6786. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6787. (push buf blist)))
  6788. (mapc 'kill-buffer blist)))
  6789. (defun org-agenda-execute (arg)
  6790. "Execute another agenda command, keeping same window.
  6791. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6792. in the agenda."
  6793. (interactive "P")
  6794. (let ((org-agenda-window-setup 'current-window))
  6795. (org-agenda arg)))
  6796. (defun org-agenda-redo (&optional all)
  6797. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6798. (interactive "P")
  6799. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6800. (cpa (unless (eq all t) current-prefix-arg))
  6801. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6802. (org-agenda-sticky nil)
  6803. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6804. org-agenda-buffer-name))
  6805. (org-agenda-keep-modes t)
  6806. (tag-filter org-agenda-tag-filter)
  6807. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6808. (top-hl-filter org-agenda-top-headline-filter)
  6809. (cat-filter org-agenda-category-filter)
  6810. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6811. (re-filter org-agenda-regexp-filter)
  6812. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6813. (effort-filter org-agenda-effort-filter)
  6814. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6815. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6816. (cols org-agenda-columns-active)
  6817. (line (org-current-line))
  6818. (window-line (- line (org-current-line (window-start))))
  6819. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6820. (redo-cmd (get-text-property p 'org-redo-cmd))
  6821. (last-args (get-text-property p 'org-last-args))
  6822. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6823. (org-agenda-overriding-cmd-arguments
  6824. (unless (eq all t)
  6825. (cond ((listp last-args)
  6826. (cons (or cpa (car last-args)) (cdr last-args)))
  6827. ((stringp last-args)
  6828. last-args))))
  6829. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6830. (put 'org-agenda-tag-filter :preset-filter nil)
  6831. (put 'org-agenda-category-filter :preset-filter nil)
  6832. (put 'org-agenda-regexp-filter :preset-filter nil)
  6833. (put 'org-agenda-effort-filter :preset-filter nil)
  6834. (and cols (org-columns-quit))
  6835. (message "Rebuilding agenda buffer...")
  6836. (if series-redo-cmd
  6837. (eval series-redo-cmd)
  6838. (org-let lprops redo-cmd))
  6839. (setq org-agenda-undo-list nil
  6840. org-agenda-pending-undo-list nil
  6841. org-agenda-tag-filter tag-filter
  6842. org-agenda-category-filter cat-filter
  6843. org-agenda-regexp-filter re-filter
  6844. org-agenda-effort-filter effort-filter
  6845. org-agenda-top-headline-filter top-hl-filter)
  6846. (message "Rebuilding agenda buffer...done")
  6847. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6848. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6849. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6850. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6851. (let ((tag (or tag-filter tag-preset))
  6852. (cat (or cat-filter cat-preset))
  6853. (effort (or effort-filter effort-preset))
  6854. (re (or re-filter re-preset)))
  6855. (when tag (org-agenda-filter-apply tag 'tag t))
  6856. (when cat (org-agenda-filter-apply cat 'category))
  6857. (when effort (org-agenda-filter-apply effort 'effort))
  6858. (when re (org-agenda-filter-apply re 'regexp)))
  6859. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6860. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6861. (org-goto-line line)
  6862. (recenter window-line)))
  6863. (defun org-agenda-redo-all (&optional exhaustive)
  6864. "Rebuild all agenda views in the current buffer.
  6865. With a prefix argument, do so in all agenda buffers."
  6866. (interactive "P")
  6867. (if exhaustive
  6868. (dolist (buffer (buffer-list))
  6869. (with-current-buffer buffer
  6870. (when (derived-mode-p 'org-agenda-mode)
  6871. (org-agenda-redo t))))
  6872. (org-agenda-redo t)))
  6873. (defvar org-global-tags-completion-table nil)
  6874. (defvar org-agenda-filter-form nil)
  6875. (defvar org-agenda-filtered-by-category nil)
  6876. (defsubst org-agenda-get-category ()
  6877. "Return the category of the agenda line."
  6878. (org-get-at-bol 'org-category))
  6879. (defun org-agenda-filter-by-category (strip)
  6880. "Filter lines in the agenda buffer that have a specific category.
  6881. The category is that of the current line.
  6882. Without prefix argument, keep only the lines of that category.
  6883. With a prefix argument, exclude the lines of that category.
  6884. "
  6885. (interactive "P")
  6886. (if (and org-agenda-filtered-by-category
  6887. org-agenda-category-filter)
  6888. (org-agenda-filter-show-all-cat)
  6889. (let ((cat (org-no-properties (org-agenda-get-category))))
  6890. (cond
  6891. ((and cat strip)
  6892. (org-agenda-filter-apply
  6893. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6894. (cat
  6895. (org-agenda-filter-apply
  6896. (setq org-agenda-category-filter
  6897. (list (concat "+" cat))) 'category))
  6898. (t (error "No category at point"))))))
  6899. (defun org-find-top-headline (&optional pos)
  6900. "Find the topmost parent headline and return it.
  6901. POS when non-nil is the marker or buffer position to start the
  6902. search from."
  6903. (save-excursion
  6904. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  6905. (when pos (goto-char pos))
  6906. ;; Skip up to the topmost parent.
  6907. (while (org-up-heading-safe))
  6908. (ignore-errors (nth 4 (org-heading-components))))))
  6909. (defvar org-agenda-filtered-by-top-headline nil)
  6910. (defun org-agenda-filter-by-top-headline (strip)
  6911. "Keep only those lines that are descendants from the same top headline.
  6912. The top headline is that of the current line."
  6913. (interactive "P")
  6914. (if org-agenda-filtered-by-top-headline
  6915. (progn
  6916. (setq org-agenda-filtered-by-top-headline nil
  6917. org-agenda-top-headline-filter nil)
  6918. (org-agenda-filter-show-all-top-filter))
  6919. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6920. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6921. (error "No top-level headline at point")))))
  6922. (defvar org-agenda-regexp-filter nil)
  6923. (defun org-agenda-filter-by-regexp (strip)
  6924. "Filter agenda entries by regular expressions.
  6925. With one prefix argument, filter out entries matching the regexp.
  6926. If there is already a regexp filter, remove it unless called with
  6927. two prefix arguments."
  6928. (interactive "P")
  6929. (cond
  6930. ((and org-agenda-regexp-filter (not (equal strip '(16))))
  6931. (org-agenda-filter-show-all-re)
  6932. (message "Regexp filter removed"))
  6933. (t (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6934. (read-from-minibuffer
  6935. (if (equal strip '(4))
  6936. "Filter out entries matching regexp: "
  6937. "Narrow to entries matching regexp: ")))))
  6938. (push flt org-agenda-regexp-filter)
  6939. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp)))))
  6940. (defvar org-agenda-effort-filter nil)
  6941. (defun org-agenda-filter-by-effort (strip)
  6942. "Filter agenda entries by effort.
  6943. With no prefix argument, keep entries matching the effort condition.
  6944. With one prefix argument, filter out entries matching the condition.
  6945. With two prefix arguments, remove the effort filters."
  6946. (interactive "P")
  6947. (cond
  6948. ((member strip '(nil 4))
  6949. (let* ((efforts (split-string
  6950. (or (cdr (assoc (concat org-effort-property "_ALL")
  6951. org-global-properties))
  6952. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6953. ;; XXX: the following handles only up to 10 different
  6954. ;; effort values.
  6955. (allowed-keys (if (null efforts) nil
  6956. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6957. (number-sequence 1 (length efforts)))))
  6958. (op nil))
  6959. (while (not (memq op '(?< ?> ?=)))
  6960. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6961. ;; Select appropriate duration. Ignore non-digit characters.
  6962. (let ((prompt
  6963. (apply #'format
  6964. (concat "Effort %c "
  6965. (mapconcat (lambda (s) (concat "[%d]" s))
  6966. efforts
  6967. " "))
  6968. op allowed-keys))
  6969. (eff -1))
  6970. (while (not (memq eff allowed-keys))
  6971. (message prompt)
  6972. (setq eff (- (read-char-exclusive) 48)))
  6973. (setq org-agenda-effort-filter
  6974. (list (concat (if strip "-" "+")
  6975. (char-to-string op)
  6976. ;; Numbering is 1 2 3 ... 9 0, but we want
  6977. ;; 0 1 2 ... 8 9.
  6978. (nth (mod (1- eff) 10) efforts)))))
  6979. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6980. (t (org-agenda-filter-show-all-effort)
  6981. (message "Effort filter removed"))))
  6982. (defun org-agenda-filter-remove-all ()
  6983. "Remove all filters from the current agenda buffer."
  6984. (interactive)
  6985. (when org-agenda-tag-filter
  6986. (org-agenda-filter-show-all-tag))
  6987. (when org-agenda-category-filter
  6988. (org-agenda-filter-show-all-cat))
  6989. (when org-agenda-regexp-filter
  6990. (org-agenda-filter-show-all-re))
  6991. (when org-agenda-top-headline-filter
  6992. (org-agenda-filter-show-all-top-filter))
  6993. (when org-agenda-effort-filter
  6994. (org-agenda-filter-show-all-effort))
  6995. (org-agenda-finalize))
  6996. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  6997. "Keep only those lines in the agenda buffer that have a specific tag.
  6998. The tag is selected with its fast selection letter, as configured.
  6999. With a `\\[universal-argument]' prefix, exclude the agenda search.
  7000. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7001. i.e. don't
  7002. filter on all its group members.
  7003. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  7004. should be used to exclude the search - the interactive user can
  7005. also press `-' or `+' to switch between filtering and excluding."
  7006. (interactive "P")
  7007. (let* ((alist org-tag-alist-for-agenda)
  7008. (tag-chars (mapconcat
  7009. (lambda (x) (if (and (not (symbolp (car x)))
  7010. (cdr x))
  7011. (char-to-string (cdr x))
  7012. ""))
  7013. org-tag-alist-for-agenda ""))
  7014. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  7015. (string-to-list tag-chars)))
  7016. (exclude (or exclude (equal arg '(4))))
  7017. (expand (not (equal arg '(16))))
  7018. (inhibit-read-only t)
  7019. (current org-agenda-tag-filter)
  7020. a n tag)
  7021. (unless char
  7022. (while (not (memq char valid-char-list))
  7023. (org-unlogged-message
  7024. "%s by tag [%s ]:tag-char, [TAB]:tag, %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  7025. (if exclude "Exclude" "Filter")
  7026. tag-chars
  7027. (if org-agenda-auto-exclude-function "[RET], " "")
  7028. (if expand "" ", no grouptag expand"))
  7029. (setq char (read-char-exclusive))
  7030. ;; Excluding or filtering down
  7031. (cond ((eq char ?-) (setq exclude t))
  7032. ((eq char ?+) (setq exclude nil)))))
  7033. (when (eq char ?\t)
  7034. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  7035. (setq-local org-global-tags-completion-table
  7036. (org-global-tags-completion-table)))
  7037. (let ((completion-ignore-case t))
  7038. (setq tag (completing-read
  7039. "Tag: " org-global-tags-completion-table nil t))))
  7040. (cond
  7041. ((eq char ?\r)
  7042. (org-agenda-filter-show-all-tag)
  7043. (when org-agenda-auto-exclude-function
  7044. (setq org-agenda-tag-filter nil)
  7045. (dolist (tag (org-agenda-get-represented-tags))
  7046. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7047. (when modifier
  7048. (push modifier org-agenda-tag-filter))))
  7049. (unless (null org-agenda-tag-filter)
  7050. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7051. ((eq char ?/)
  7052. (org-agenda-filter-show-all-tag)
  7053. (when (get 'org-agenda-tag-filter :preset-filter)
  7054. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7055. ((eq char ?.)
  7056. (setq org-agenda-tag-filter
  7057. (mapcar (lambda(tag) (concat "+" tag))
  7058. (org-get-at-bol 'tags)))
  7059. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7060. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7061. ((or (eq char ?\s)
  7062. (setq a (rassoc char alist))
  7063. (and tag (setq a (cons tag nil))))
  7064. (org-agenda-filter-show-all-tag)
  7065. (setq tag (car a))
  7066. (setq org-agenda-tag-filter
  7067. (cons (concat (if exclude "-" "+") tag)
  7068. current))
  7069. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7070. (t (error "Invalid tag selection character %c" char)))))
  7071. (defun org-agenda-get-represented-tags ()
  7072. "Get a list of all tags currently represented in the agenda."
  7073. (let (p tags)
  7074. (save-excursion
  7075. (goto-char (point-min))
  7076. (while (setq p (next-single-property-change (point) 'tags))
  7077. (goto-char p)
  7078. (mapc (lambda (x) (add-to-list 'tags x))
  7079. (get-text-property (point) 'tags))))
  7080. tags))
  7081. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7082. "Create the form that tests a line for agenda filter. Optional
  7083. argument EXPAND can be used for the TYPE tag and will expand the
  7084. tags in the FILTER if any of the tags in FILTER are grouptags."
  7085. (let (f f1)
  7086. (cond
  7087. ;; Tag filter
  7088. ((eq type 'tag)
  7089. (setq filter
  7090. (delete-dups
  7091. (append (get 'org-agenda-tag-filter :preset-filter)
  7092. filter)))
  7093. (dolist (x filter)
  7094. (let ((op (string-to-char x)))
  7095. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7096. (setq x (list x)))
  7097. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7098. (push f1 f))))
  7099. ;; Category filter
  7100. ((eq type 'category)
  7101. (setq filter
  7102. (delete-dups
  7103. (append (get 'org-agenda-category-filter :preset-filter)
  7104. filter)))
  7105. (dolist (x filter)
  7106. (if (equal "-" (substring x 0 1))
  7107. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7108. (setq f1 (list 'equal (substring x 1) 'cat)))
  7109. (push f1 f)))
  7110. ;; Regexp filter
  7111. ((eq type 'regexp)
  7112. (setq filter
  7113. (delete-dups
  7114. (append (get 'org-agenda-regexp-filter :preset-filter)
  7115. filter)))
  7116. (dolist (x filter)
  7117. (if (equal "-" (substring x 0 1))
  7118. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7119. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7120. (push f1 f)))
  7121. ;; Effort filter
  7122. ((eq type 'effort)
  7123. (setq filter
  7124. (delete-dups
  7125. (append (get 'org-agenda-effort-filter :preset-filter)
  7126. filter)))
  7127. (dolist (x filter)
  7128. (push (org-agenda-filter-effort-form x) f))))
  7129. (cons 'and (nreverse f))))
  7130. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7131. "Return a form associated to tag-expression TAGS.
  7132. Build a form testing a line for agenda filter for
  7133. tag-expressions. OP is an operator of type CHAR that allows the
  7134. function to set the right switches in the returned form."
  7135. (let (form)
  7136. ;; Any of the expressions can match if OP is +, all must match if
  7137. ;; the operator is -.
  7138. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7139. (let* ((tag (substring x 1))
  7140. (f (cond
  7141. ((string= "" tag) '(not tags))
  7142. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7143. ;; TAG is a regexp.
  7144. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7145. (t (list 'member (downcase tag) 'tags)))))
  7146. (push (if (eq op ?-) (list 'not f) f) form)))))
  7147. (defun org-agenda-filter-effort-form (e)
  7148. "Return the form to compare the effort of the current line with what E says.
  7149. E looks like \"+<2:25\"."
  7150. (let (op)
  7151. (setq e (substring e 1))
  7152. (setq op (string-to-char e) e (substring e 1))
  7153. (setq op (cond ((equal op ?<) '<=)
  7154. ((equal op ?>) '>=)
  7155. ((equal op ??) op)
  7156. (t '=)))
  7157. (list 'org-agenda-compare-effort (list 'quote op)
  7158. (org-duration-to-minutes e))))
  7159. (defun org-agenda-compare-effort (op value)
  7160. "Compare the effort of the current line with VALUE, using OP.
  7161. If the line does not have an effort defined, return nil."
  7162. ;; `effort-minutes' property cannot be extracted directly from
  7163. ;; current line but is stored as a property in `txt'.
  7164. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7165. (funcall op
  7166. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7167. value)))
  7168. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7169. "Expand group tags in FILTER for the agenda.
  7170. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7171. (if org-group-tags
  7172. (let ((case-fold-search t) rtn)
  7173. (mapc
  7174. (lambda (f)
  7175. (let (f0 dir)
  7176. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7177. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7178. (setq dir (if no-operator "" "+") f0 f))
  7179. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7180. (org-tags-expand f0 t t))
  7181. rtn))))
  7182. filter)
  7183. (reverse rtn))
  7184. filter))
  7185. (defun org-agenda-filter-apply (filter type &optional expand)
  7186. "Set FILTER as the new agenda filter and apply it. Optional
  7187. argument EXPAND can be used for the TYPE tag and will expand the
  7188. tags in the FILTER if any of the tags in FILTER are grouptags."
  7189. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7190. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7191. (let (tags cat txt)
  7192. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7193. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7194. ;; category is used as the filter:
  7195. (setq org-agenda-filtered-by-category
  7196. (and (eq type 'category)
  7197. (not (equal (substring (car filter) 0 1) "-"))))
  7198. (org-agenda-set-mode-name)
  7199. (save-excursion
  7200. (goto-char (point-min))
  7201. (while (not (eobp))
  7202. (if (org-get-at-bol 'org-marker)
  7203. (progn
  7204. (setq tags (org-get-at-bol 'tags)
  7205. cat (org-agenda-get-category)
  7206. txt (org-get-at-bol 'txt))
  7207. (unless (eval org-agenda-filter-form)
  7208. (org-agenda-filter-hide-line type))
  7209. (beginning-of-line 2))
  7210. (beginning-of-line 2))))
  7211. (when (get-char-property (point) 'invisible)
  7212. (ignore-errors (org-agenda-previous-line)))))
  7213. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7214. "Filter by top headline HL."
  7215. (org-agenda-set-mode-name)
  7216. (save-excursion
  7217. (goto-char (point-min))
  7218. (while (not (eobp))
  7219. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7220. (tophl (and pos (org-find-top-headline pos))))
  7221. (when (and tophl (funcall (if negative 'identity 'not)
  7222. (string= hl tophl)))
  7223. (org-agenda-filter-hide-line 'top-headline)))
  7224. (beginning-of-line 2)))
  7225. (when (get-char-property (point) 'invisible)
  7226. (org-agenda-previous-line))
  7227. (setq org-agenda-top-headline-filter hl
  7228. org-agenda-filtered-by-top-headline t))
  7229. (defun org-agenda-filter-hide-line (type)
  7230. "Hide lines with TYPE in the agenda buffer."
  7231. (let* ((b (max (point-min) (1- (point-at-bol))))
  7232. (e (point-at-eol)))
  7233. (let ((inhibit-read-only t))
  7234. (add-text-properties
  7235. b e `(invisible org-filtered org-filter-type ,type)))))
  7236. (defun org-agenda-remove-filter (type)
  7237. (interactive)
  7238. "Remove filter of type TYPE from the agenda buffer."
  7239. (save-excursion
  7240. (goto-char (point-min))
  7241. (let ((inhibit-read-only t) pos)
  7242. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7243. (goto-char pos)
  7244. (remove-text-properties
  7245. (point) (next-single-property-change (point) 'org-filter-type)
  7246. `(invisible org-filtered org-filter-type ,type))))
  7247. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7248. (setq org-agenda-filter-form nil)
  7249. (org-agenda-set-mode-name)
  7250. (org-agenda-finalize)))
  7251. (defun org-agenda-filter-show-all-tag nil
  7252. (org-agenda-remove-filter 'tag))
  7253. (defun org-agenda-filter-show-all-re nil
  7254. (org-agenda-remove-filter 'regexp))
  7255. (defun org-agenda-filter-show-all-effort nil
  7256. (org-agenda-remove-filter 'effort))
  7257. (defun org-agenda-filter-show-all-cat nil
  7258. (org-agenda-remove-filter 'category))
  7259. (defun org-agenda-filter-show-all-top-filter nil
  7260. (org-agenda-remove-filter 'top-headline))
  7261. (defun org-agenda-manipulate-query-add ()
  7262. "Manipulate the query by adding a search term with positive selection.
  7263. Positive selection means the term must be matched for selection of an entry."
  7264. (interactive)
  7265. (org-agenda-manipulate-query ?\[))
  7266. (defun org-agenda-manipulate-query-subtract ()
  7267. "Manipulate the query by adding a search term with negative selection.
  7268. Negative selection means term must not be matched for selection of an entry."
  7269. (interactive)
  7270. (org-agenda-manipulate-query ?\]))
  7271. (defun org-agenda-manipulate-query-add-re ()
  7272. "Manipulate the query by adding a search regexp with positive selection.
  7273. Positive selection means the regexp must match for selection of an entry."
  7274. (interactive)
  7275. (org-agenda-manipulate-query ?\{))
  7276. (defun org-agenda-manipulate-query-subtract-re ()
  7277. "Manipulate the query by adding a search regexp with negative selection.
  7278. Negative selection means regexp must not match for selection of an entry."
  7279. (interactive)
  7280. (org-agenda-manipulate-query ?\}))
  7281. (defun org-agenda-manipulate-query (char)
  7282. (cond
  7283. ((eq org-agenda-type 'agenda)
  7284. (let ((org-agenda-include-inactive-timestamps t))
  7285. (org-agenda-redo))
  7286. (message "Display now includes inactive timestamps as well"))
  7287. ((eq org-agenda-type 'search)
  7288. (org-add-to-string
  7289. 'org-agenda-query-string
  7290. (if org-agenda-last-search-view-search-was-boolean
  7291. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7292. (?\{ . " +{}") (?\} . " -{}"))))
  7293. " "))
  7294. (setq org-agenda-redo-command
  7295. (list 'org-search-view
  7296. (car (get-text-property (min (1- (point-max)) (point))
  7297. 'org-last-args))
  7298. org-agenda-query-string
  7299. (+ (length org-agenda-query-string)
  7300. (if (member char '(?\{ ?\})) 0 1))))
  7301. (set-register org-agenda-query-register org-agenda-query-string)
  7302. (let ((org-agenda-overriding-arguments
  7303. (cdr org-agenda-redo-command)))
  7304. (org-agenda-redo)))
  7305. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7306. org-agenda-type))))
  7307. (defun org-add-to-string (var string)
  7308. (set var (concat (symbol-value var) string)))
  7309. (defun org-agenda-goto-date (span)
  7310. "Jump to DATE in agenda."
  7311. (interactive "P")
  7312. (let* ((org-read-date-prefer-future
  7313. (eval org-agenda-jump-prefer-future))
  7314. (date (org-read-date))
  7315. (day (time-to-days (org-time-string-to-time date)))
  7316. (org-agenda-sticky-orig org-agenda-sticky)
  7317. (org-agenda-buffer-tmp-name (buffer-name))
  7318. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7319. (0-arg (or current-prefix-arg (car args)))
  7320. (2-arg (nth 2 args))
  7321. (with-hour-p (nth 4 org-agenda-redo-command))
  7322. (newcmd (list 'org-agenda-list 0-arg date
  7323. (org-agenda-span-to-ndays
  7324. 2-arg (org-time-string-to-absolute date))
  7325. with-hour-p))
  7326. (newargs (cdr newcmd))
  7327. (inhibit-read-only t)
  7328. org-agenda-sticky)
  7329. (if (not (org-agenda-check-type t 'agenda))
  7330. (error "Not available in non-agenda views")
  7331. (add-text-properties (point-min) (point-max)
  7332. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7333. (org-agenda-redo)
  7334. (goto-char (point-min))
  7335. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7336. (save-excursion (move-beginning-of-line 2) (eobp))))
  7337. (move-beginning-of-line 2))
  7338. (setq org-agenda-sticky org-agenda-sticky-orig
  7339. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7340. (defun org-agenda-goto-today ()
  7341. "Go to today."
  7342. (interactive)
  7343. (org-agenda-check-type t 'agenda)
  7344. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7345. (curspan (nth 2 args))
  7346. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7347. (cond
  7348. (tdpos (goto-char tdpos))
  7349. ((eq org-agenda-type 'agenda)
  7350. (let* ((sd (org-agenda-compute-starting-span
  7351. (org-today) (or curspan org-agenda-span)))
  7352. (org-agenda-overriding-arguments args))
  7353. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7354. (org-agenda-redo)
  7355. (org-agenda-find-same-or-today-or-agenda)))
  7356. (t (error "Cannot find today")))))
  7357. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7358. (goto-char
  7359. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7360. (text-property-any (point-min) (point-max) 'org-today t)
  7361. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7362. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7363. (org-agenda-backward-block))
  7364. (point-min))))
  7365. (defun org-agenda-backward-block ()
  7366. "Move backward by one agenda block."
  7367. (interactive)
  7368. (org-agenda-forward-block 'backward))
  7369. (defun org-agenda-forward-block (&optional backward)
  7370. "Move forward by one agenda block.
  7371. When optional argument BACKWARD is set, go backward"
  7372. (interactive)
  7373. (cond ((not (derived-mode-p 'org-agenda-mode))
  7374. (user-error
  7375. "Cannot execute this command outside of org-agenda-mode buffers"))
  7376. ((looking-at (if backward "\\`" "\\'"))
  7377. (message "Already at the %s block" (if backward "first" "last")))
  7378. (t (let ((pos (prog1 (point)
  7379. (ignore-errors (if backward (backward-char 1)
  7380. (move-end-of-line 1)))))
  7381. (f (if backward
  7382. 'previous-single-property-change
  7383. 'next-single-property-change))
  7384. moved dest)
  7385. (while (and (setq dest (funcall
  7386. f (point) 'org-agenda-structural-header))
  7387. (not (get-text-property
  7388. (point) 'org-agenda-structural-header)))
  7389. (setq moved t)
  7390. (goto-char dest))
  7391. (if moved (move-beginning-of-line 1)
  7392. (goto-char (if backward (point-min) (point-max)))
  7393. (move-beginning-of-line 1)
  7394. (message "No %s block" (if backward "previous" "further")))))))
  7395. (defun org-agenda-later (arg)
  7396. "Go forward in time by the current span.
  7397. With prefix ARG, go forward that many times the current span."
  7398. (interactive "p")
  7399. (org-agenda-check-type t 'agenda)
  7400. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7401. (span (or (nth 2 args) org-agenda-current-span))
  7402. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7403. (greg (calendar-gregorian-from-absolute sd))
  7404. (cnt (org-get-at-bol 'org-day-cnt))
  7405. greg2)
  7406. (cond
  7407. ((numberp span)
  7408. (setq sd (+ (* span arg) sd)))
  7409. ((eq span 'day)
  7410. (setq sd (+ arg sd)))
  7411. ((eq span 'week)
  7412. (setq sd (+ (* 7 arg) sd)))
  7413. ((eq span 'fortnight)
  7414. (setq sd (+ (* 14 arg) sd)))
  7415. ((eq span 'month)
  7416. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7417. sd (calendar-absolute-from-gregorian greg2))
  7418. (setcar greg2 (1+ (car greg2))))
  7419. ((eq span 'year)
  7420. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7421. sd (calendar-absolute-from-gregorian greg2))
  7422. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7423. (t
  7424. (setq sd (+ (* span arg) sd))))
  7425. (let ((org-agenda-overriding-cmd
  7426. ;; `cmd' may have been set by `org-agenda-run-series' which
  7427. ;; uses `org-agenda-overriding-cmd' to decide whether
  7428. ;; overriding is allowed for `cmd'
  7429. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7430. (org-agenda-overriding-arguments
  7431. (list (car args) sd span)))
  7432. (org-agenda-redo)
  7433. (org-agenda-find-same-or-today-or-agenda cnt))))
  7434. (defun org-agenda-earlier (arg)
  7435. "Go backward in time by the current span.
  7436. With prefix ARG, go backward that many times the current span."
  7437. (interactive "p")
  7438. (org-agenda-later (- arg)))
  7439. (defun org-agenda-view-mode-dispatch ()
  7440. "Call one of the view mode commands."
  7441. (interactive)
  7442. (org-unlogged-message
  7443. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7444. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7445. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7446. (pcase (read-char-exclusive)
  7447. (?\ (call-interactively 'org-agenda-reset-view))
  7448. (?d (call-interactively 'org-agenda-day-view))
  7449. (?w (call-interactively 'org-agenda-week-view))
  7450. (?t (call-interactively 'org-agenda-fortnight-view))
  7451. (?m (call-interactively 'org-agenda-month-view))
  7452. (?y (call-interactively 'org-agenda-year-view))
  7453. (?l (call-interactively 'org-agenda-log-mode))
  7454. (?L (org-agenda-log-mode '(4)))
  7455. (?c (org-agenda-log-mode 'clockcheck))
  7456. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7457. (?a (call-interactively 'org-agenda-archives-mode))
  7458. (?A (org-agenda-archives-mode 'files))
  7459. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7460. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7461. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7462. (?D (call-interactively 'org-agenda-toggle-diary))
  7463. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7464. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7465. (org-agenda-check-type t 'agenda)
  7466. (org-agenda-redo))
  7467. (message "Display now includes inactive timestamps as well"))
  7468. (?q (message "Abort"))
  7469. (key (user-error "Invalid key: %s" key))))
  7470. (defun org-agenda-reset-view ()
  7471. "Switch to default view for agenda."
  7472. (interactive)
  7473. (org-agenda-change-time-span org-agenda-span))
  7474. (defun org-agenda-day-view (&optional day-of-month)
  7475. "Switch to daily view for agenda.
  7476. With argument DAY-OF-MONTH, switch to that day of the month."
  7477. (interactive "P")
  7478. (org-agenda-change-time-span 'day day-of-month))
  7479. (defun org-agenda-week-view (&optional iso-week)
  7480. "Switch to weekly view for agenda.
  7481. With argument ISO-WEEK, switch to the corresponding ISO week.
  7482. If ISO-WEEK has more then 2 digits, only the last two encode
  7483. the week. Any digits before this encode a year. So 200712
  7484. means week 12 of year 2007. Years ranging from 70 years ago
  7485. to 30 years in the future can also be written as 2-digit years."
  7486. (interactive "P")
  7487. (org-agenda-change-time-span 'week iso-week))
  7488. (defun org-agenda-fortnight-view (&optional iso-week)
  7489. "Switch to fortnightly view for agenda.
  7490. With argument ISO-WEEK, switch to the corresponding ISO week.
  7491. If ISO-WEEK has more then 2 digits, only the last two encode
  7492. the week. Any digits before this encode a year. So 200712
  7493. means week 12 of year 2007. Years ranging from 70 years ago
  7494. to 30 years in the future can also be written as 2-digit years."
  7495. (interactive "P")
  7496. (org-agenda-change-time-span 'fortnight iso-week))
  7497. (defun org-agenda-month-view (&optional month)
  7498. "Switch to monthly view for agenda.
  7499. With argument MONTH, switch to that month. If MONTH has more
  7500. then 2 digits, only the last two encode the month. Any digits
  7501. before this encode a year. So 200712 means December year 2007.
  7502. Years ranging from 70 years ago to 30 years in the future can
  7503. also be written as 2-digit years."
  7504. (interactive "P")
  7505. (org-agenda-change-time-span 'month month))
  7506. (defun org-agenda-year-view (&optional year)
  7507. "Switch to yearly view for agenda.
  7508. With argument YEAR, switch to that year. Years ranging from 70
  7509. years ago to 30 years in the future can also be written as
  7510. 2-digit years."
  7511. (interactive "P")
  7512. (when year
  7513. (setq year (org-small-year-to-year year)))
  7514. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7515. (org-agenda-change-time-span 'year year)
  7516. (error "Abort")))
  7517. (defun org-agenda-change-time-span (span &optional n)
  7518. "Change the agenda view to SPAN.
  7519. SPAN may be `day', `week', `fortnight', `month', `year'."
  7520. (org-agenda-check-type t 'agenda)
  7521. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7522. (curspan (nth 2 args)))
  7523. (when (and (not n) (equal curspan span))
  7524. (error "Viewing span is already \"%s\"" span))
  7525. (let* ((sd (or (org-get-at-bol 'day)
  7526. (nth 1 args)
  7527. org-starting-day))
  7528. (sd (org-agenda-compute-starting-span sd span n))
  7529. (org-agenda-overriding-cmd
  7530. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7531. (org-agenda-overriding-arguments
  7532. (list (car args) sd span)))
  7533. (org-agenda-redo)
  7534. (org-agenda-find-same-or-today-or-agenda))
  7535. (org-agenda-set-mode-name)
  7536. (message "Switched to %s view" span)))
  7537. (defun org-agenda-compute-starting-span (sd span &optional n)
  7538. "Compute starting date for agenda.
  7539. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7540. is a cons cell with the starting date and the number of days,
  7541. so that the date SD will be in that range."
  7542. (let* ((greg (calendar-gregorian-from-absolute sd))
  7543. (dg (nth 1 greg))
  7544. (mg (car greg))
  7545. (yg (nth 2 greg)))
  7546. (cond
  7547. ((eq span 'day)
  7548. (when n
  7549. (setq sd (+ (calendar-absolute-from-gregorian
  7550. (list mg 1 yg))
  7551. n -1))))
  7552. ((or (eq span 'week) (eq span 'fortnight))
  7553. (let* ((nt (calendar-day-of-week
  7554. (calendar-gregorian-from-absolute sd)))
  7555. (d (if org-agenda-start-on-weekday
  7556. (- nt org-agenda-start-on-weekday)
  7557. 0))
  7558. y1)
  7559. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7560. (when n
  7561. (require 'cal-iso)
  7562. (when (> n 99)
  7563. (setq y1 (org-small-year-to-year (/ n 100))
  7564. n (mod n 100)))
  7565. (setq sd
  7566. (calendar-iso-to-absolute
  7567. (list n 1
  7568. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7569. ((eq span 'month)
  7570. (let (y1)
  7571. (when (and n (> n 99))
  7572. (setq y1 (org-small-year-to-year (/ n 100))
  7573. n (mod n 100)))
  7574. (setq sd (calendar-absolute-from-gregorian
  7575. (list (or n mg) 1 (or y1 yg))))))
  7576. ((eq span 'year)
  7577. (setq sd (calendar-absolute-from-gregorian
  7578. (list 1 1 (or n yg))))))
  7579. sd))
  7580. (defun org-agenda-next-date-line (&optional arg)
  7581. "Jump to the next line indicating a date in agenda buffer."
  7582. (interactive "p")
  7583. (org-agenda-check-type t 'agenda)
  7584. (beginning-of-line 1)
  7585. ;; This does not work if user makes date format that starts with a blank
  7586. (when (looking-at-p "^\\S-") (forward-char 1))
  7587. (unless (re-search-forward "^\\S-" nil t arg)
  7588. (backward-char 1)
  7589. (error "No next date after this line in this buffer"))
  7590. (goto-char (match-beginning 0)))
  7591. (defun org-agenda-previous-date-line (&optional arg)
  7592. "Jump to the previous line indicating a date in agenda buffer."
  7593. (interactive "p")
  7594. (org-agenda-check-type t 'agenda)
  7595. (beginning-of-line 1)
  7596. (unless (re-search-backward "^\\S-" nil t arg)
  7597. (error "No previous date before this line in this buffer")))
  7598. ;; Initialize the highlight
  7599. (defvar org-hl (make-overlay 1 1))
  7600. (overlay-put org-hl 'face 'highlight)
  7601. (defun org-highlight (begin end &optional buffer)
  7602. "Highlight a region with overlay."
  7603. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7604. (defun org-unhighlight ()
  7605. "Detach overlay INDEX."
  7606. (delete-overlay org-hl))
  7607. (defun org-unhighlight-once ()
  7608. "Remove the highlight from its position, and this function from the hook."
  7609. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7610. (org-unhighlight))
  7611. (defvar org-agenda-pre-follow-window-conf nil)
  7612. (defun org-agenda-follow-mode ()
  7613. "Toggle follow mode in an agenda buffer."
  7614. (interactive)
  7615. (unless org-agenda-follow-mode
  7616. (setq org-agenda-pre-follow-window-conf
  7617. (current-window-configuration)))
  7618. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7619. (unless org-agenda-follow-mode
  7620. (set-window-configuration org-agenda-pre-follow-window-conf))
  7621. (org-agenda-set-mode-name)
  7622. (org-agenda-do-context-action)
  7623. (message "Follow mode is %s"
  7624. (if org-agenda-follow-mode "on" "off")))
  7625. (defun org-agenda-entry-text-mode (&optional arg)
  7626. "Toggle entry text mode in an agenda buffer."
  7627. (interactive "P")
  7628. (if (or org-agenda-tag-filter
  7629. org-agenda-category-filter
  7630. org-agenda-regexp-filter
  7631. org-agenda-top-headline-filter)
  7632. (user-error "Can't show entry text in filtered views")
  7633. (setq org-agenda-entry-text-mode (or (integerp arg)
  7634. (not org-agenda-entry-text-mode)))
  7635. (org-agenda-entry-text-hide)
  7636. (and org-agenda-entry-text-mode
  7637. (let ((org-agenda-entry-text-maxlines
  7638. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7639. (org-agenda-entry-text-show)))
  7640. (org-agenda-set-mode-name)
  7641. (message "Entry text mode is %s%s"
  7642. (if org-agenda-entry-text-mode "on" "off")
  7643. (if (not org-agenda-entry-text-mode) ""
  7644. (format " (maximum number of lines is %d)"
  7645. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7646. (defun org-agenda-clockreport-mode ()
  7647. "Toggle clocktable mode in an agenda buffer."
  7648. (interactive)
  7649. (org-agenda-check-type t 'agenda)
  7650. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7651. (org-agenda-set-mode-name)
  7652. (org-agenda-redo)
  7653. (message "Clocktable mode is %s"
  7654. (if org-agenda-clockreport-mode "on" "off")))
  7655. (defun org-agenda-log-mode (&optional special)
  7656. "Toggle log mode in an agenda buffer.
  7657. With argument SPECIAL, show all possible log items, not only the ones
  7658. configured in `org-agenda-log-mode-items'.
  7659. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7660. log items, nothing else."
  7661. (interactive "P")
  7662. (org-agenda-check-type t 'agenda)
  7663. (setq org-agenda-show-log
  7664. (cond
  7665. ((equal special '(16)) 'only)
  7666. ((eq special 'clockcheck)
  7667. (if (eq org-agenda-show-log 'clockcheck)
  7668. nil 'clockcheck))
  7669. (special '(closed clock state))
  7670. (t (not org-agenda-show-log))))
  7671. (org-agenda-set-mode-name)
  7672. (org-agenda-redo)
  7673. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7674. (defun org-agenda-archives-mode (&optional with-files)
  7675. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7676. When called with a prefix argument, include all archive files as well."
  7677. (interactive "P")
  7678. (setq org-agenda-archives-mode
  7679. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7680. (org-agenda-set-mode-name)
  7681. (org-agenda-redo)
  7682. (message
  7683. "%s"
  7684. (cond
  7685. ((eq org-agenda-archives-mode nil)
  7686. "No archives are included")
  7687. ((eq org-agenda-archives-mode 'trees)
  7688. (format "Trees with :%s: tag are included" org-archive-tag))
  7689. ((eq org-agenda-archives-mode t)
  7690. (format "Trees with :%s: tag and all active archive files are included"
  7691. org-archive-tag)))))
  7692. (defun org-agenda-toggle-diary ()
  7693. "Toggle diary inclusion in an agenda buffer."
  7694. (interactive)
  7695. (org-agenda-check-type t 'agenda)
  7696. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7697. (org-agenda-redo)
  7698. (org-agenda-set-mode-name)
  7699. (message "Diary inclusion turned %s"
  7700. (if org-agenda-include-diary "on" "off")))
  7701. (defun org-agenda-toggle-deadlines ()
  7702. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7703. (interactive)
  7704. (org-agenda-check-type t 'agenda)
  7705. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7706. (org-agenda-redo)
  7707. (org-agenda-set-mode-name)
  7708. (message "Deadlines inclusion turned %s"
  7709. (if org-agenda-include-deadlines "on" "off")))
  7710. (defun org-agenda-toggle-time-grid ()
  7711. "Toggle time grid in an agenda buffer."
  7712. (interactive)
  7713. (org-agenda-check-type t 'agenda)
  7714. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7715. (org-agenda-redo)
  7716. (org-agenda-set-mode-name)
  7717. (message "Time-grid turned %s"
  7718. (if org-agenda-use-time-grid "on" "off")))
  7719. (defun org-agenda-set-mode-name ()
  7720. "Set the mode name to indicate all the small mode settings."
  7721. (setq mode-name
  7722. (list "Org-Agenda"
  7723. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7724. " "
  7725. '(:eval (org-agenda-span-name org-agenda-current-span))
  7726. (if org-agenda-follow-mode " Follow" "")
  7727. (if org-agenda-entry-text-mode " ETxt" "")
  7728. (if org-agenda-include-diary " Diary" "")
  7729. (if org-agenda-include-deadlines " Ddl" "")
  7730. (if org-agenda-use-time-grid " Grid" "")
  7731. (if (and (boundp 'org-habit-show-habits)
  7732. org-habit-show-habits) " Habit" "")
  7733. (cond
  7734. ((consp org-agenda-show-log) " LogAll")
  7735. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7736. (org-agenda-show-log " Log")
  7737. (t ""))
  7738. (if (or org-agenda-category-filter
  7739. (get 'org-agenda-category-filter :preset-filter))
  7740. '(:eval (propertize
  7741. (concat " <"
  7742. (mapconcat
  7743. 'identity
  7744. (append
  7745. (get 'org-agenda-category-filter :preset-filter)
  7746. org-agenda-category-filter)
  7747. "")
  7748. ">")
  7749. 'face 'org-agenda-filter-category
  7750. 'help-echo "Category used in filtering")) "")
  7751. (if (or org-agenda-tag-filter
  7752. (get 'org-agenda-tag-filter :preset-filter))
  7753. '(:eval (propertize
  7754. (concat " {"
  7755. (mapconcat
  7756. 'identity
  7757. (append
  7758. (get 'org-agenda-tag-filter :preset-filter)
  7759. org-agenda-tag-filter)
  7760. "")
  7761. "}")
  7762. 'face 'org-agenda-filter-tags
  7763. 'help-echo "Tags used in filtering")) "")
  7764. (if (or org-agenda-effort-filter
  7765. (get 'org-agenda-effort-filter :preset-filter))
  7766. '(:eval (propertize
  7767. (concat " {"
  7768. (mapconcat
  7769. 'identity
  7770. (append
  7771. (get 'org-agenda-effort-filter :preset-filter)
  7772. org-agenda-effort-filter)
  7773. "")
  7774. "}")
  7775. 'face 'org-agenda-filter-effort
  7776. 'help-echo "Effort conditions used in filtering")) "")
  7777. (if (or org-agenda-regexp-filter
  7778. (get 'org-agenda-regexp-filter :preset-filter))
  7779. '(:eval (propertize
  7780. (concat " ["
  7781. (mapconcat
  7782. 'identity
  7783. (append
  7784. (get 'org-agenda-regexp-filter :preset-filter)
  7785. org-agenda-regexp-filter)
  7786. "")
  7787. "]")
  7788. 'face 'org-agenda-filter-regexp
  7789. 'help-echo "Regexp used in filtering")) "")
  7790. (if org-agenda-archives-mode
  7791. (if (eq org-agenda-archives-mode t)
  7792. " Archives"
  7793. (format " :%s:" org-archive-tag))
  7794. "")
  7795. (if org-agenda-clockreport-mode " Clock" "")))
  7796. (force-mode-line-update))
  7797. (defun org-agenda-update-agenda-type ()
  7798. "Update the agenda type after each command."
  7799. (setq org-agenda-type
  7800. (or (get-text-property (point) 'org-agenda-type)
  7801. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7802. (defun org-agenda-next-line ()
  7803. "Move cursor to the next line, and show if follow mode is active."
  7804. (interactive)
  7805. (call-interactively 'next-line)
  7806. (org-agenda-do-context-action))
  7807. (defun org-agenda-previous-line ()
  7808. "Move cursor to the previous line, and show if follow-mode is active."
  7809. (interactive)
  7810. (call-interactively 'previous-line)
  7811. (org-agenda-do-context-action))
  7812. (defun org-agenda-next-item (n)
  7813. "Move cursor to next agenda item."
  7814. (interactive "p")
  7815. (let ((col (current-column)))
  7816. (dotimes (c n)
  7817. (when (next-single-property-change (point-at-eol) 'org-marker)
  7818. (move-end-of-line 1)
  7819. (goto-char (next-single-property-change (point) 'org-marker))))
  7820. (org-move-to-column col))
  7821. (org-agenda-do-context-action))
  7822. (defun org-agenda-previous-item (n)
  7823. "Move cursor to next agenda item."
  7824. (interactive "p")
  7825. (dotimes (c n)
  7826. (let ((col (current-column))
  7827. (goto (save-excursion
  7828. (move-end-of-line 0)
  7829. (previous-single-property-change (point) 'org-marker))))
  7830. (when goto (goto-char goto))
  7831. (org-move-to-column col)))
  7832. (org-agenda-do-context-action))
  7833. (defun org-agenda-do-context-action ()
  7834. "Show outline path and, maybe, follow mode window."
  7835. (let ((m (org-get-at-bol 'org-marker)))
  7836. (when (and (markerp m) (marker-buffer m))
  7837. (and org-agenda-follow-mode
  7838. (if org-agenda-follow-indirect
  7839. (org-agenda-tree-to-indirect-buffer nil)
  7840. (org-agenda-show)))
  7841. (and org-agenda-show-outline-path
  7842. (org-with-point-at m (org-display-outline-path t))))))
  7843. (defun org-agenda-show-tags ()
  7844. "Show the tags applicable to the current item."
  7845. (interactive)
  7846. (let* ((tags (org-get-at-bol 'tags)))
  7847. (if tags
  7848. (message "Tags are :%s:"
  7849. (org-no-properties (mapconcat 'identity tags ":")))
  7850. (message "No tags associated with this line"))))
  7851. (defun org-agenda-goto (&optional highlight)
  7852. "Go to the entry at point in the corresponding Org file."
  7853. (interactive)
  7854. (let* ((marker (or (org-get-at-bol 'org-marker)
  7855. (org-agenda-error)))
  7856. (buffer (marker-buffer marker))
  7857. (pos (marker-position marker)))
  7858. (switch-to-buffer-other-window buffer)
  7859. (widen)
  7860. (push-mark)
  7861. (goto-char pos)
  7862. (when (derived-mode-p 'org-mode)
  7863. (org-show-context 'agenda)
  7864. (recenter (/ (window-height) 2))
  7865. (org-back-to-heading t)
  7866. (let ((case-fold-search nil))
  7867. (when (re-search-forward org-complex-heading-regexp nil t)
  7868. (goto-char (match-beginning 4)))))
  7869. (run-hooks 'org-agenda-after-show-hook)
  7870. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7871. (defvar org-agenda-after-show-hook nil
  7872. "Normal hook run after an item has been shown from the agenda.
  7873. Point is in the buffer where the item originated.")
  7874. (defun org-agenda-kill ()
  7875. "Kill the entry or subtree belonging to the current agenda entry."
  7876. (interactive)
  7877. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7878. (let* ((bufname-orig (buffer-name))
  7879. (marker (or (org-get-at-bol 'org-marker)
  7880. (org-agenda-error)))
  7881. (buffer (marker-buffer marker))
  7882. (pos (marker-position marker))
  7883. (type (org-get-at-bol 'type))
  7884. dbeg dend (n 0) conf)
  7885. (org-with-remote-undo buffer
  7886. (with-current-buffer buffer
  7887. (save-excursion
  7888. (goto-char pos)
  7889. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7890. (setq dbeg (progn (org-back-to-heading t) (point))
  7891. dend (org-end-of-subtree t t))
  7892. (setq dbeg (point-at-bol)
  7893. dend (min (point-max) (1+ (point-at-eol)))))
  7894. (goto-char dbeg)
  7895. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7896. (setq conf (or (eq t org-agenda-confirm-kill)
  7897. (and (numberp org-agenda-confirm-kill)
  7898. (> n org-agenda-confirm-kill))))
  7899. (and conf
  7900. (not (y-or-n-p
  7901. (format "Delete entry with %d lines in buffer \"%s\"? "
  7902. n (buffer-name buffer))))
  7903. (error "Abort"))
  7904. (let ((org-agenda-buffer-name bufname-orig))
  7905. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7906. (with-current-buffer buffer (delete-region dbeg dend))
  7907. (message "Agenda item and source killed"))))
  7908. (defvar org-archive-default-command) ; defined in org-archive.el
  7909. (defun org-agenda-archive-default ()
  7910. "Archive the entry or subtree belonging to the current agenda entry."
  7911. (interactive)
  7912. (require 'org-archive)
  7913. (org-agenda-archive-with org-archive-default-command))
  7914. (defun org-agenda-archive-default-with-confirmation ()
  7915. "Archive the entry or subtree belonging to the current agenda entry."
  7916. (interactive)
  7917. (require 'org-archive)
  7918. (org-agenda-archive-with org-archive-default-command 'confirm))
  7919. (defun org-agenda-archive ()
  7920. "Archive the entry or subtree belonging to the current agenda entry."
  7921. (interactive)
  7922. (org-agenda-archive-with 'org-archive-subtree))
  7923. (defun org-agenda-archive-to-archive-sibling ()
  7924. "Move the entry to the archive sibling."
  7925. (interactive)
  7926. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7927. (defun org-agenda-archive-with (cmd &optional confirm)
  7928. "Move the entry to the archive sibling."
  7929. (interactive)
  7930. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7931. (let* ((bufname-orig (buffer-name))
  7932. (marker (or (org-get-at-bol 'org-marker)
  7933. (org-agenda-error)))
  7934. (buffer (marker-buffer marker))
  7935. (pos (marker-position marker)))
  7936. (org-with-remote-undo buffer
  7937. (with-current-buffer buffer
  7938. (if (derived-mode-p 'org-mode)
  7939. (if (and confirm
  7940. (not (y-or-n-p "Archive this subtree or entry? ")))
  7941. (error "Abort")
  7942. (save-window-excursion
  7943. (goto-char pos)
  7944. (let ((org-agenda-buffer-name bufname-orig))
  7945. (org-remove-subtree-entries-from-agenda))
  7946. (org-back-to-heading t)
  7947. (funcall cmd)))
  7948. (error "Archiving works only in Org files"))))))
  7949. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7950. "Remove all lines in the agenda that correspond to a given subtree.
  7951. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7952. If this information is not given, the function uses the tree at point."
  7953. (let ((buf (or buf (current-buffer))) m p)
  7954. (save-excursion
  7955. (unless (and beg end)
  7956. (org-back-to-heading t)
  7957. (setq beg (point))
  7958. (org-end-of-subtree t)
  7959. (setq end (point)))
  7960. (set-buffer (get-buffer org-agenda-buffer-name))
  7961. (save-excursion
  7962. (goto-char (point-max))
  7963. (beginning-of-line 1)
  7964. (while (not (bobp))
  7965. (when (and (setq m (org-get-at-bol 'org-marker))
  7966. (equal buf (marker-buffer m))
  7967. (setq p (marker-position m))
  7968. (>= p beg)
  7969. (< p end))
  7970. (let ((inhibit-read-only t))
  7971. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7972. (beginning-of-line 0))))))
  7973. (defun org-agenda-refile (&optional goto rfloc no-update)
  7974. "Refile the item at point.
  7975. When called with `\\[universal-argument] \\[universal-argument]', \
  7976. go to the location of the last
  7977. refiled item.
  7978. When called with `\\[universal-argument] \\[universal-argument] \
  7979. \\[universal-argument]' prefix or when GOTO is 0, clear
  7980. the refile cache.
  7981. RFLOC can be a refile location obtained in a different way.
  7982. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7983. (interactive "P")
  7984. (cond
  7985. ((member goto '(0 (64)))
  7986. (org-refile-cache-clear))
  7987. ((equal goto '(16))
  7988. (org-refile-goto-last-stored))
  7989. (t
  7990. (let* ((buffer-orig (buffer-name))
  7991. (marker (or (org-get-at-bol 'org-hd-marker)
  7992. (org-agenda-error)))
  7993. (buffer (marker-buffer marker))
  7994. (pos (marker-position marker))
  7995. (rfloc (or rfloc
  7996. (org-refile-get-location
  7997. (if goto "Goto" "Refile to") buffer
  7998. org-refile-allow-creating-parent-nodes))))
  7999. (with-current-buffer buffer
  8000. (org-with-wide-buffer
  8001. (goto-char marker)
  8002. (let ((org-agenda-buffer-name buffer-orig))
  8003. (org-remove-subtree-entries-from-agenda))
  8004. (org-refile goto buffer rfloc))))
  8005. (unless no-update (org-agenda-redo)))))
  8006. (defun org-agenda-open-link (&optional arg)
  8007. "Open the link(s) in the current entry, if any.
  8008. This looks for a link in the displayed line in the agenda.
  8009. It also looks at the text of the entry itself."
  8010. (interactive "P")
  8011. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8012. (org-get-at-bol 'org-marker)))
  8013. (buffer (and marker (marker-buffer marker)))
  8014. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8015. (lkall (and buffer (org-offer-links-in-entry
  8016. buffer marker arg prefix)))
  8017. (lk0 (car lkall))
  8018. (lk (if (stringp lk0) (list lk0) lk0))
  8019. (lkend (cdr lkall))
  8020. trg)
  8021. (cond
  8022. ((and buffer lk)
  8023. (mapcar (lambda(l)
  8024. (with-current-buffer buffer
  8025. (setq trg (and (string-match org-bracket-link-regexp l)
  8026. (match-string 1 l)))
  8027. (if (or (not trg) (string-match org-any-link-re trg))
  8028. (org-with-wide-buffer
  8029. (goto-char marker)
  8030. (when (search-forward l nil lkend)
  8031. (goto-char (match-beginning 0))
  8032. (org-open-at-point)))
  8033. ;; This is an internal link, widen the buffer
  8034. (switch-to-buffer-other-window buffer)
  8035. (widen)
  8036. (goto-char marker)
  8037. (when (search-forward l nil lkend)
  8038. (goto-char (match-beginning 0))
  8039. (org-open-at-point)))))
  8040. lk))
  8041. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  8042. (save-excursion
  8043. (beginning-of-line 1)
  8044. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  8045. (org-open-link-from-string (match-string 1)))
  8046. (t (message "No link to open here")))))
  8047. (defun org-agenda-copy-local-variable (var)
  8048. "Get a variable from a referenced buffer and install it here."
  8049. (let ((m (org-get-at-bol 'org-marker)))
  8050. (when (and m (buffer-live-p (marker-buffer m)))
  8051. (set (make-local-variable var)
  8052. (with-current-buffer (marker-buffer m)
  8053. (symbol-value var))))))
  8054. (defun org-agenda-switch-to (&optional delete-other-windows)
  8055. "Go to the Org mode file which contains the item at point.
  8056. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8057. displayed Org file fills the frame."
  8058. (interactive)
  8059. (if (and org-return-follows-link
  8060. (not (org-get-at-bol 'org-marker))
  8061. (org-in-regexp org-bracket-link-regexp))
  8062. (org-open-link-from-string (match-string 0))
  8063. (let* ((marker (or (org-get-at-bol 'org-marker)
  8064. (org-agenda-error)))
  8065. (buffer (marker-buffer marker))
  8066. (pos (marker-position marker)))
  8067. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8068. (pop-to-buffer-same-window buffer)
  8069. (when delete-other-windows (delete-other-windows))
  8070. (widen)
  8071. (goto-char pos)
  8072. (when (derived-mode-p 'org-mode)
  8073. (org-show-context 'agenda)
  8074. (run-hooks 'org-agenda-after-show-hook)))))
  8075. (defun org-agenda-goto-mouse (ev)
  8076. "Go to the Org file which contains the item at the mouse click."
  8077. (interactive "e")
  8078. (mouse-set-point ev)
  8079. (org-agenda-goto))
  8080. (defun org-agenda-show (&optional full-entry)
  8081. "Display the Org file which contains the item at point.
  8082. With prefix argument FULL-ENTRY, make the entire entry visible
  8083. if it was hidden in the outline."
  8084. (interactive "P")
  8085. (let ((win (selected-window)))
  8086. (org-agenda-goto t)
  8087. (when full-entry (org-show-entry))
  8088. (select-window win)))
  8089. (defvar org-agenda-show-window nil)
  8090. (defun org-agenda-show-and-scroll-up (&optional arg)
  8091. "Display the Org file which contains the item at point.
  8092. When called repeatedly, scroll the window that is displaying the buffer.
  8093. With a `\\[universal-argument]' prefix argument, display the item, but \
  8094. fold drawers."
  8095. (interactive "P")
  8096. (let ((win (selected-window)))
  8097. (if (and (window-live-p org-agenda-show-window)
  8098. (eq this-command last-command))
  8099. (progn
  8100. (select-window org-agenda-show-window)
  8101. (ignore-errors (scroll-up)))
  8102. (org-agenda-goto t)
  8103. (org-show-entry)
  8104. (if arg (org-cycle-hide-drawers 'children)
  8105. (org-with-wide-buffer
  8106. (narrow-to-region (org-entry-beginning-position)
  8107. (org-entry-end-position))
  8108. (org-show-all '(drawers))))
  8109. (when arg )
  8110. (setq org-agenda-show-window (selected-window)))
  8111. (select-window win)))
  8112. (defun org-agenda-show-scroll-down ()
  8113. "Scroll down the window showing the agenda."
  8114. (interactive)
  8115. (let ((win (selected-window)))
  8116. (when (window-live-p org-agenda-show-window)
  8117. (select-window org-agenda-show-window)
  8118. (ignore-errors (scroll-down))
  8119. (select-window win))))
  8120. (defun org-agenda-show-1 (&optional more)
  8121. "Display the Org file which contains the item at point.
  8122. The prefix arg selects the amount of information to display:
  8123. 0 hide the subtree
  8124. 1 just show the entry according to defaults.
  8125. 2 show the children view
  8126. 3 show the subtree view
  8127. 4 show the entire subtree and any LOGBOOK drawers
  8128. 5 show the entire subtree and any drawers
  8129. With prefix argument FULL-ENTRY, make the entire entry visible
  8130. if it was hidden in the outline."
  8131. (interactive "p")
  8132. (let ((win (selected-window)))
  8133. (org-agenda-goto t)
  8134. (org-back-to-heading)
  8135. (set-window-start (selected-window) (point-at-bol))
  8136. (cond
  8137. ((= more 0)
  8138. (outline-hide-subtree)
  8139. (save-excursion
  8140. (org-back-to-heading)
  8141. (run-hook-with-args 'org-cycle-hook 'folded))
  8142. (message "Remote: FOLDED"))
  8143. ((and (called-interactively-p 'any) (= more 1))
  8144. (message "Remote: show with default settings"))
  8145. ((= more 2)
  8146. (outline-show-entry)
  8147. (org-show-children)
  8148. (save-excursion
  8149. (org-back-to-heading)
  8150. (run-hook-with-args 'org-cycle-hook 'children))
  8151. (message "Remote: CHILDREN"))
  8152. ((= more 3)
  8153. (outline-show-subtree)
  8154. (save-excursion
  8155. (org-back-to-heading)
  8156. (run-hook-with-args 'org-cycle-hook 'subtree))
  8157. (message "Remote: SUBTREE"))
  8158. ((= more 4)
  8159. (outline-show-subtree)
  8160. (save-excursion
  8161. (org-back-to-heading)
  8162. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8163. (message "Remote: SUBTREE AND LOGBOOK"))
  8164. ((> more 4)
  8165. (outline-show-subtree)
  8166. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8167. (select-window win)))
  8168. (defvar org-agenda-cycle-counter nil)
  8169. (defun org-agenda-cycle-show (&optional n)
  8170. "Show the current entry in another window, with default settings.
  8171. Default settings are taken from `org-show-context-detail'. When
  8172. use repeatedly in immediate succession, the remote entry will
  8173. cycle through visibility
  8174. children -> subtree -> folded
  8175. When called with a numeric prefix arg, that arg will be passed through to
  8176. `org-agenda-show-1'. For the interpretation of that argument, see the
  8177. docstring of `org-agenda-show-1'."
  8178. (interactive "P")
  8179. (if (integerp n)
  8180. (setq org-agenda-cycle-counter n)
  8181. (if (not (eq last-command this-command))
  8182. (setq org-agenda-cycle-counter 1)
  8183. (if (equal org-agenda-cycle-counter 0)
  8184. (setq org-agenda-cycle-counter 2)
  8185. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8186. (when (> org-agenda-cycle-counter 3)
  8187. (setq org-agenda-cycle-counter 0)))))
  8188. (org-agenda-show-1 org-agenda-cycle-counter))
  8189. (defun org-agenda-recenter (arg)
  8190. "Display the Org file which contains the item at point and recenter."
  8191. (interactive "P")
  8192. (let ((win (selected-window)))
  8193. (org-agenda-goto t)
  8194. (recenter arg)
  8195. (select-window win)))
  8196. (defun org-agenda-show-mouse (ev)
  8197. "Display the Org file which contains the item at the mouse click."
  8198. (interactive "e")
  8199. (mouse-set-point ev)
  8200. (org-agenda-show))
  8201. (defun org-agenda-check-no-diary ()
  8202. "Check if the entry is a diary link and abort if yes."
  8203. (when (org-get-at-bol 'org-agenda-diary-link)
  8204. (org-agenda-error)))
  8205. (defun org-agenda-error ()
  8206. "Throw an error when a command is not allowed in the agenda."
  8207. (user-error "Command not allowed in this line"))
  8208. (defun org-agenda-tree-to-indirect-buffer (arg)
  8209. "Show the subtree corresponding to the current entry in an indirect buffer.
  8210. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8211. With a numerical prefix ARG, go up to this level and then take that tree.
  8212. With a negative numeric ARG, go up by this number of levels.
  8213. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8214. i.e. don't use
  8215. the dedicated frame."
  8216. (interactive "P")
  8217. (if current-prefix-arg
  8218. (org-agenda-do-tree-to-indirect-buffer arg)
  8219. (let ((agenda-buffer (buffer-name))
  8220. (agenda-window (selected-window))
  8221. (indirect-window
  8222. (and org-last-indirect-buffer
  8223. (get-buffer-window org-last-indirect-buffer))))
  8224. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8225. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8226. (eq org-indirect-buffer-display 'dedicated-frame))
  8227. (unwind-protect
  8228. (unless (and indirect-window (window-live-p indirect-window))
  8229. (setq indirect-window (split-window agenda-window)))
  8230. (and indirect-window (select-window indirect-window))
  8231. (switch-to-buffer org-last-indirect-buffer :norecord)
  8232. (fit-window-to-buffer indirect-window)))
  8233. (select-window (get-buffer-window agenda-buffer))
  8234. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8235. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8236. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8237. (org-agenda-check-no-diary)
  8238. (let* ((marker (or (org-get-at-bol 'org-marker)
  8239. (org-agenda-error)))
  8240. (buffer (marker-buffer marker))
  8241. (pos (marker-position marker)))
  8242. (with-current-buffer buffer
  8243. (save-excursion
  8244. (goto-char pos)
  8245. (org-tree-to-indirect-buffer arg)))))
  8246. (defvar org-last-heading-marker (make-marker)
  8247. "Marker pointing to the headline that last changed its TODO state
  8248. by a remote command from the agenda.")
  8249. (defun org-agenda-todo-nextset ()
  8250. "Switch TODO entry to next sequence."
  8251. (interactive)
  8252. (org-agenda-todo 'nextset))
  8253. (defun org-agenda-todo-previousset ()
  8254. "Switch TODO entry to previous sequence."
  8255. (interactive)
  8256. (org-agenda-todo 'previousset))
  8257. (defun org-agenda-todo (&optional arg)
  8258. "Cycle TODO state of line at point, also in Org file.
  8259. This changes the line at point, all other lines in the agenda referring to
  8260. the same tree node, and the headline of the tree node in the Org file."
  8261. (interactive "P")
  8262. (org-agenda-check-no-diary)
  8263. (let* ((col (current-column))
  8264. (marker (or (org-get-at-bol 'org-marker)
  8265. (org-agenda-error)))
  8266. (buffer (marker-buffer marker))
  8267. (pos (marker-position marker))
  8268. (hdmarker (org-get-at-bol 'org-hd-marker))
  8269. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8270. (inhibit-read-only t)
  8271. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8272. (org-with-remote-undo buffer
  8273. (with-current-buffer buffer
  8274. (widen)
  8275. (goto-char pos)
  8276. (org-show-context 'agenda)
  8277. (let ((current-prefix-arg arg))
  8278. (call-interactively 'org-todo))
  8279. (and (bolp) (forward-char 1))
  8280. (setq newhead (org-get-heading))
  8281. (when (and (bound-and-true-p
  8282. org-agenda-headline-snapshot-before-repeat)
  8283. (not (equal org-agenda-headline-snapshot-before-repeat
  8284. newhead))
  8285. todayp)
  8286. (setq newhead org-agenda-headline-snapshot-before-repeat
  8287. just-one t))
  8288. (save-excursion
  8289. (org-back-to-heading)
  8290. (move-marker org-last-heading-marker (point))))
  8291. (beginning-of-line 1)
  8292. (save-window-excursion
  8293. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8294. (when (bound-and-true-p org-clock-out-when-done)
  8295. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8296. newhead)
  8297. (org-agenda-unmark-clocking-task))
  8298. (org-move-to-column col)
  8299. (org-agenda-mark-clocking-task))))
  8300. (defun org-agenda-add-note (&optional arg)
  8301. "Add a time-stamped note to the entry at point."
  8302. (interactive "P")
  8303. (org-agenda-check-no-diary)
  8304. (let* ((marker (or (org-get-at-bol 'org-marker)
  8305. (org-agenda-error)))
  8306. (buffer (marker-buffer marker))
  8307. (pos (marker-position marker))
  8308. (hdmarker (org-get-at-bol 'org-hd-marker))
  8309. (inhibit-read-only t))
  8310. (with-current-buffer buffer
  8311. (widen)
  8312. (goto-char pos)
  8313. (org-show-context 'agenda)
  8314. (org-add-note))))
  8315. (defun org-agenda-change-all-lines (newhead hdmarker
  8316. &optional fixface just-this)
  8317. "Change all lines in the agenda buffer which match HDMARKER.
  8318. The new content of the line will be NEWHEAD (as modified by
  8319. `org-agenda-format-item'). HDMARKER is checked with
  8320. `equal' against all `org-hd-marker' text properties in the file.
  8321. If FIXFACE is non-nil, the face of each item is modified according to
  8322. the new TODO state.
  8323. If JUST-THIS is non-nil, change just the current line, not all.
  8324. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8325. (let* ((inhibit-read-only t)
  8326. (line (org-current-line))
  8327. (org-agenda-buffer (current-buffer))
  8328. (thetags (with-current-buffer (marker-buffer hdmarker)
  8329. (org-get-tags hdmarker)))
  8330. props m pl undone-face done-face finish new dotime level cat tags)
  8331. (save-excursion
  8332. (goto-char (point-max))
  8333. (beginning-of-line 1)
  8334. (while (not finish)
  8335. (setq finish (bobp))
  8336. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8337. (or (not just-this) (= (org-current-line) line))
  8338. (equal m hdmarker))
  8339. (setq props (text-properties-at (point))
  8340. dotime (org-get-at-bol 'dotime)
  8341. cat (org-agenda-get-category)
  8342. level (org-get-at-bol 'level)
  8343. tags thetags
  8344. new
  8345. (let ((org-prefix-format-compiled
  8346. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8347. org-prefix-format-compiled))
  8348. (extra (org-get-at-bol 'extra)))
  8349. (with-current-buffer (marker-buffer hdmarker)
  8350. (org-with-wide-buffer
  8351. (org-agenda-format-item extra newhead level cat tags dotime))))
  8352. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8353. undone-face (org-get-at-bol 'undone-face)
  8354. done-face (org-get-at-bol 'done-face))
  8355. (beginning-of-line 1)
  8356. (cond
  8357. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8358. ((looking-at ".*")
  8359. ;; When replacing the whole line, preserve bulk mark
  8360. ;; overlay, if any.
  8361. (let ((mark (catch :overlay
  8362. (dolist (o (overlays-in (point) (+ 2 (point))))
  8363. (when (eq (overlay-get o 'type)
  8364. 'org-marked-entry-overlay)
  8365. (throw :overlay o))))))
  8366. (replace-match new t t)
  8367. (beginning-of-line)
  8368. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8369. (add-text-properties (point-at-bol) (point-at-eol) props)
  8370. (when fixface
  8371. (add-text-properties
  8372. (point-at-bol) (point-at-eol)
  8373. (list 'face
  8374. (if org-last-todo-state-is-todo
  8375. undone-face done-face))))
  8376. (org-agenda-highlight-todo 'line)
  8377. (beginning-of-line 1))
  8378. (t (error "Line update did not work")))
  8379. (save-restriction
  8380. (narrow-to-region (point-at-bol) (point-at-eol))
  8381. (org-agenda-finalize)))
  8382. (beginning-of-line 0)))))
  8383. (defun org-agenda-align-tags (&optional line)
  8384. "Align all tags in agenda items to `org-agenda-tags-column'.
  8385. When optional argument LINE is non-nil, align tags only on the
  8386. current line."
  8387. (let ((inhibit-read-only t)
  8388. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8389. (- (window-text-width))
  8390. org-agenda-tags-column))
  8391. (end (and line (line-end-position)))
  8392. l c)
  8393. (save-excursion
  8394. (goto-char (if line (line-beginning-position) (point-min)))
  8395. (while (re-search-forward org-tag-group-re end t)
  8396. (add-text-properties
  8397. (match-beginning 1) (match-end 1)
  8398. (list 'face (delq nil (let ((prop (get-text-property
  8399. (match-beginning 1) 'face)))
  8400. (or (listp prop) (setq prop (list prop)))
  8401. (if (memq 'org-tag prop)
  8402. prop
  8403. (cons 'org-tag prop))))))
  8404. (setq l (string-width (match-string 1))
  8405. c (if (< org-agenda-tags-column 0)
  8406. (- (abs org-agenda-tags-column) l)
  8407. org-agenda-tags-column))
  8408. (goto-char (match-beginning 1))
  8409. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  8410. (point))
  8411. (insert (org-add-props
  8412. (make-string (max 1 (- c (current-column))) ?\s)
  8413. (plist-put (copy-sequence (text-properties-at (point)))
  8414. 'face nil))))
  8415. (goto-char (point-min))
  8416. (org-font-lock-add-tag-faces (point-max)))))
  8417. (defun org-agenda-priority-up ()
  8418. "Increase the priority of line at point, also in Org file."
  8419. (interactive)
  8420. (org-agenda-priority 'up))
  8421. (defun org-agenda-priority-down ()
  8422. "Decrease the priority of line at point, also in Org file."
  8423. (interactive)
  8424. (org-agenda-priority 'down))
  8425. (defun org-agenda-priority (&optional force-direction)
  8426. "Set the priority of line at point, also in Org file.
  8427. This changes the line at point, all other lines in the agenda referring to
  8428. the same tree node, and the headline of the tree node in the Org file.
  8429. Called with a universal prefix arg, show the priority instead of setting it."
  8430. (interactive "P")
  8431. (if (equal force-direction '(4))
  8432. (org-show-priority)
  8433. (unless org-enable-priority-commands
  8434. (error "Priority commands are disabled"))
  8435. (org-agenda-check-no-diary)
  8436. (let* ((col (current-column))
  8437. (marker (or (org-get-at-bol 'org-marker)
  8438. (org-agenda-error)))
  8439. (hdmarker (org-get-at-bol 'org-hd-marker))
  8440. (buffer (marker-buffer hdmarker))
  8441. (pos (marker-position hdmarker))
  8442. (inhibit-read-only t)
  8443. newhead)
  8444. (org-with-remote-undo buffer
  8445. (with-current-buffer buffer
  8446. (widen)
  8447. (goto-char pos)
  8448. (org-show-context 'agenda)
  8449. (org-priority force-direction)
  8450. (end-of-line 1)
  8451. (setq newhead (org-get-heading)))
  8452. (org-agenda-change-all-lines newhead hdmarker)
  8453. (org-move-to-column col)))))
  8454. ;; FIXME: should fix the tags property of the agenda line.
  8455. (defun org-agenda-set-tags (&optional tag onoff)
  8456. "Set tags for the current headline."
  8457. (interactive)
  8458. (org-agenda-check-no-diary)
  8459. (if (and (org-region-active-p) (called-interactively-p 'any))
  8460. (call-interactively 'org-change-tag-in-region)
  8461. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8462. (org-agenda-error)))
  8463. (buffer (marker-buffer hdmarker))
  8464. (pos (marker-position hdmarker))
  8465. (inhibit-read-only t)
  8466. newhead)
  8467. (org-with-remote-undo buffer
  8468. (with-current-buffer buffer
  8469. (widen)
  8470. (goto-char pos)
  8471. (org-show-context 'agenda)
  8472. (if tag
  8473. (org-toggle-tag tag onoff)
  8474. (call-interactively #'org-set-tags-command))
  8475. (end-of-line 1)
  8476. (setq newhead (org-get-heading)))
  8477. (org-agenda-change-all-lines newhead hdmarker)
  8478. (beginning-of-line 1)))))
  8479. (defun org-agenda-set-property ()
  8480. "Set a property for the current headline."
  8481. (interactive)
  8482. (org-agenda-check-no-diary)
  8483. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8484. (org-agenda-error)))
  8485. (buffer (marker-buffer hdmarker))
  8486. (pos (marker-position hdmarker))
  8487. (inhibit-read-only t)
  8488. newhead)
  8489. (org-with-remote-undo buffer
  8490. (with-current-buffer buffer
  8491. (widen)
  8492. (goto-char pos)
  8493. (org-show-context 'agenda)
  8494. (call-interactively 'org-set-property)))))
  8495. (defun org-agenda-set-effort ()
  8496. "Set the effort property for the current headline."
  8497. (interactive)
  8498. (org-agenda-check-no-diary)
  8499. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8500. (org-agenda-error)))
  8501. (buffer (marker-buffer hdmarker))
  8502. (pos (marker-position hdmarker))
  8503. (inhibit-read-only t)
  8504. newhead)
  8505. (org-with-remote-undo buffer
  8506. (with-current-buffer buffer
  8507. (widen)
  8508. (goto-char pos)
  8509. (org-show-context 'agenda)
  8510. (call-interactively 'org-set-effort)
  8511. (end-of-line 1)
  8512. (setq newhead (org-get-heading)))
  8513. (org-agenda-change-all-lines newhead hdmarker))))
  8514. (defun org-agenda-toggle-archive-tag ()
  8515. "Toggle the archive tag for the current entry."
  8516. (interactive)
  8517. (org-agenda-check-no-diary)
  8518. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8519. (org-agenda-error)))
  8520. (buffer (marker-buffer hdmarker))
  8521. (pos (marker-position hdmarker))
  8522. (inhibit-read-only t)
  8523. newhead)
  8524. (org-with-remote-undo buffer
  8525. (with-current-buffer buffer
  8526. (widen)
  8527. (goto-char pos)
  8528. (org-show-context 'agenda)
  8529. (call-interactively 'org-toggle-archive-tag)
  8530. (end-of-line 1)
  8531. (setq newhead (org-get-heading)))
  8532. (org-agenda-change-all-lines newhead hdmarker)
  8533. (beginning-of-line 1))))
  8534. (defun org-agenda-do-date-later (arg)
  8535. (interactive "P")
  8536. (cond
  8537. ((or (equal arg '(16))
  8538. (memq last-command
  8539. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8540. (setq this-command 'org-agenda-date-later-minutes)
  8541. (org-agenda-date-later-minutes 1))
  8542. ((or (equal arg '(4))
  8543. (memq last-command
  8544. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8545. (setq this-command 'org-agenda-date-later-hours)
  8546. (org-agenda-date-later-hours 1))
  8547. (t
  8548. (org-agenda-date-later (prefix-numeric-value arg)))))
  8549. (defun org-agenda-do-date-earlier (arg)
  8550. (interactive "P")
  8551. (cond
  8552. ((or (equal arg '(16))
  8553. (memq last-command
  8554. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8555. (setq this-command 'org-agenda-date-earlier-minutes)
  8556. (org-agenda-date-earlier-minutes 1))
  8557. ((or (equal arg '(4))
  8558. (memq last-command
  8559. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8560. (setq this-command 'org-agenda-date-earlier-hours)
  8561. (org-agenda-date-earlier-hours 1))
  8562. (t
  8563. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8564. (defun org-agenda-date-later (arg &optional what)
  8565. "Change the date of this item to ARG day(s) later."
  8566. (interactive "p")
  8567. (org-agenda-check-type t 'agenda)
  8568. (org-agenda-check-no-diary)
  8569. (let* ((marker (or (org-get-at-bol 'org-marker)
  8570. (org-agenda-error)))
  8571. (buffer (marker-buffer marker))
  8572. (pos (marker-position marker))
  8573. cdate today)
  8574. (org-with-remote-undo buffer
  8575. (with-current-buffer buffer
  8576. (widen)
  8577. (goto-char pos)
  8578. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8579. (when (and org-agenda-move-date-from-past-immediately-to-today
  8580. (equal arg 1)
  8581. (or (not what) (eq what 'day))
  8582. (not (save-match-data (org-at-date-range-p))))
  8583. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8584. cdate (calendar-absolute-from-gregorian
  8585. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8586. today (org-today))
  8587. (when (> today cdate)
  8588. ;; immediately shift to today
  8589. (setq arg (- today cdate))))
  8590. (org-timestamp-change arg (or what 'day))
  8591. (when (and (org-at-date-range-p)
  8592. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8593. (let ((end org-last-changed-timestamp))
  8594. (org-timestamp-change arg (or what 'day))
  8595. (setq org-last-changed-timestamp
  8596. (concat org-last-changed-timestamp "--" end)))))
  8597. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8598. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8599. (defun org-agenda-date-earlier (arg &optional what)
  8600. "Change the date of this item to ARG day(s) earlier."
  8601. (interactive "p")
  8602. (org-agenda-date-later (- arg) what))
  8603. (defun org-agenda-date-later-minutes (arg)
  8604. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8605. (interactive "p")
  8606. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8607. (org-agenda-date-later arg 'minute))
  8608. (defun org-agenda-date-earlier-minutes (arg)
  8609. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8610. (interactive "p")
  8611. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8612. (org-agenda-date-earlier arg 'minute))
  8613. (defun org-agenda-date-later-hours (arg)
  8614. "Change the time of this item, in hour steps."
  8615. (interactive "p")
  8616. (org-agenda-date-later arg 'hour))
  8617. (defun org-agenda-date-earlier-hours (arg)
  8618. "Change the time of this item, in hour steps."
  8619. (interactive "p")
  8620. (org-agenda-date-earlier arg 'hour))
  8621. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8622. "Show new date stamp via text properties."
  8623. ;; We use text properties to make this undoable
  8624. (let ((inhibit-read-only t))
  8625. (setq stamp (concat prefix " => " stamp " "))
  8626. (save-excursion
  8627. (goto-char (point-max))
  8628. (while (not (bobp))
  8629. (when (equal marker (org-get-at-bol 'org-marker))
  8630. (remove-text-properties (point-at-bol) (point-at-eol) '(display nil))
  8631. (org-move-to-column (- (window-width) (length stamp)) t)
  8632. (add-text-properties
  8633. (1- (point)) (point-at-eol)
  8634. (list 'display (org-add-props stamp nil
  8635. 'face '(secondary-selection default))))
  8636. (beginning-of-line 1))
  8637. (beginning-of-line 0)))))
  8638. (defun org-agenda-date-prompt (arg)
  8639. "Change the date of this item. Date is prompted for, with default today.
  8640. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8641. be used to request time specification in the time stamp."
  8642. (interactive "P")
  8643. (org-agenda-check-type t 'agenda)
  8644. (org-agenda-check-no-diary)
  8645. (let* ((marker (or (org-get-at-bol 'org-marker)
  8646. (org-agenda-error)))
  8647. (buffer (marker-buffer marker))
  8648. (pos (marker-position marker)))
  8649. (org-with-remote-undo buffer
  8650. (with-current-buffer buffer
  8651. (widen)
  8652. (goto-char pos)
  8653. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8654. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8655. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8656. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8657. (defun org-agenda-schedule (arg &optional time)
  8658. "Schedule the item at point.
  8659. ARG is passed through to `org-schedule'."
  8660. (interactive "P")
  8661. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8662. (org-agenda-check-no-diary)
  8663. (let* ((marker (or (org-get-at-bol 'org-marker)
  8664. (org-agenda-error)))
  8665. (type (marker-insertion-type marker))
  8666. (buffer (marker-buffer marker))
  8667. (pos (marker-position marker))
  8668. ts)
  8669. (set-marker-insertion-type marker t)
  8670. (org-with-remote-undo buffer
  8671. (with-current-buffer buffer
  8672. (widen)
  8673. (goto-char pos)
  8674. (setq ts (org-schedule arg time)))
  8675. (org-agenda-show-new-time marker ts " S"))
  8676. (message "%s" ts)))
  8677. (defun org-agenda-deadline (arg &optional time)
  8678. "Schedule the item at point.
  8679. ARG is passed through to `org-deadline'."
  8680. (interactive "P")
  8681. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8682. (org-agenda-check-no-diary)
  8683. (let* ((marker (or (org-get-at-bol 'org-marker)
  8684. (org-agenda-error)))
  8685. (buffer (marker-buffer marker))
  8686. (pos (marker-position marker))
  8687. ts)
  8688. (org-with-remote-undo buffer
  8689. (with-current-buffer buffer
  8690. (widen)
  8691. (goto-char pos)
  8692. (setq ts (org-deadline arg time)))
  8693. (org-agenda-show-new-time marker ts " D"))
  8694. (message "%s" ts)))
  8695. (defun org-agenda-clock-in (&optional arg)
  8696. "Start the clock on the currently selected item."
  8697. (interactive "P")
  8698. (org-agenda-check-no-diary)
  8699. (if (equal arg '(4))
  8700. (org-clock-in arg)
  8701. (let* ((marker (or (org-get-at-bol 'org-marker)
  8702. (org-agenda-error)))
  8703. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8704. (pos (marker-position marker))
  8705. (col (current-column))
  8706. newhead)
  8707. (org-with-remote-undo (marker-buffer marker)
  8708. (with-current-buffer (marker-buffer marker)
  8709. (widen)
  8710. (goto-char pos)
  8711. (org-show-context 'agenda)
  8712. (org-clock-in arg)
  8713. (setq newhead (org-get-heading)))
  8714. (org-agenda-change-all-lines newhead hdmarker))
  8715. (org-move-to-column col))))
  8716. (defun org-agenda-clock-out ()
  8717. "Stop the currently running clock."
  8718. (interactive)
  8719. (unless (marker-buffer org-clock-marker)
  8720. (error "No running clock"))
  8721. (let ((marker (make-marker)) (col (current-column)) newhead)
  8722. (org-with-remote-undo (marker-buffer org-clock-marker)
  8723. (with-current-buffer (marker-buffer org-clock-marker)
  8724. (org-with-wide-buffer
  8725. (goto-char org-clock-marker)
  8726. (org-back-to-heading t)
  8727. (move-marker marker (point))
  8728. (org-clock-out)
  8729. (setq newhead (org-get-heading)))))
  8730. (org-agenda-change-all-lines newhead marker)
  8731. (move-marker marker nil)
  8732. (org-move-to-column col)
  8733. (org-agenda-unmark-clocking-task)))
  8734. (defun org-agenda-clock-cancel (&optional arg)
  8735. "Cancel the currently running clock."
  8736. (interactive "P")
  8737. (unless (marker-buffer org-clock-marker)
  8738. (user-error "No running clock"))
  8739. (org-with-remote-undo (marker-buffer org-clock-marker)
  8740. (org-clock-cancel)))
  8741. (defun org-agenda-clock-goto ()
  8742. "Jump to the currently clocked in task within the agenda.
  8743. If the currently clocked in task is not listed in the agenda
  8744. buffer, display it in another window."
  8745. (interactive)
  8746. (let (pos)
  8747. (mapc (lambda (o)
  8748. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  8749. (setq pos (overlay-start o))))
  8750. (overlays-in (point-min) (point-max)))
  8751. (cond (pos (goto-char pos))
  8752. ;; If the currently clocked entry is not in the agenda
  8753. ;; buffer, we visit it in another window:
  8754. ((bound-and-true-p org-clock-current-task)
  8755. (org-switch-to-buffer-other-window (org-clock-goto)))
  8756. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8757. (defun org-agenda-diary-entry-in-org-file ()
  8758. "Make a diary entry in the file `org-agenda-diary-file'."
  8759. (let (d1 d2 char (text "") dp1 dp2)
  8760. (if (equal (buffer-name) "*Calendar*")
  8761. (setq d1 (calendar-cursor-to-date t)
  8762. d2 (car calendar-mark-ring))
  8763. (setq dp1 (get-text-property (point-at-bol) 'day))
  8764. (unless dp1 (user-error "No date defined in current line"))
  8765. (setq d1 (calendar-gregorian-from-absolute dp1)
  8766. d2 (and (ignore-errors (mark))
  8767. (save-excursion
  8768. (goto-char (mark))
  8769. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8770. (calendar-gregorian-from-absolute dp2))))
  8771. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8772. (setq char (read-char-exclusive))
  8773. (cond
  8774. ((equal char ?d)
  8775. (setq text (read-string "Day entry: "))
  8776. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8777. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8778. ((equal char ?a)
  8779. (setq d1 (list (car d1) (nth 1 d1)
  8780. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8781. (nth 2 d1))))
  8782. (setq text (read-string "Anniversary (use %d to show years): "))
  8783. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8784. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8785. ((equal char ?b)
  8786. (setq text (read-string "Block entry: "))
  8787. (unless (and d1 d2 (not (equal d1 d2)))
  8788. (user-error "No block of days selected"))
  8789. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8790. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8791. ((equal char ?j)
  8792. (org-switch-to-buffer-other-window
  8793. (find-file-noselect org-agenda-diary-file))
  8794. (require 'org-datetree)
  8795. (org-datetree-find-date-create d1)
  8796. (org-reveal t))
  8797. (t (user-error "Invalid selection character `%c'" char)))))
  8798. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8799. "Where in `org-agenda-diary-file' should new entries be added?
  8800. Valid values:
  8801. date-tree in the date tree, as first child of the date
  8802. date-tree-last in the date tree, as last child of the date
  8803. top-level as top-level entries at the end of the file."
  8804. :group 'org-agenda
  8805. :type '(choice
  8806. (const :tag "first in a date tree" date-tree)
  8807. (const :tag "last in a date tree" date-tree-last)
  8808. (const :tag "as top level at end of file" top-level)))
  8809. (defcustom org-agenda-insert-diary-extract-time nil
  8810. "Non-nil means extract any time specification from the diary entry."
  8811. :group 'org-agenda
  8812. :version "24.1"
  8813. :type 'boolean)
  8814. (defcustom org-agenda-bulk-mark-char ">"
  8815. "A single-character string to be used as the bulk mark."
  8816. :group 'org-agenda
  8817. :version "24.1"
  8818. :type 'string)
  8819. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8820. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8821. If TEXT is not empty, it will become the headline of the new entry, and
  8822. the resulting entry will not be shown. When TEXT is empty, switch to
  8823. `org-agenda-diary-file' and let the user finish the entry there."
  8824. (let ((cw (current-window-configuration)))
  8825. (org-switch-to-buffer-other-window
  8826. (find-file-noselect org-agenda-diary-file))
  8827. (widen)
  8828. (goto-char (point-min))
  8829. (cl-case type
  8830. (anniversary
  8831. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  8832. (progn
  8833. (or (org-at-heading-p t)
  8834. (progn
  8835. (outline-next-heading)
  8836. (insert "* Anniversaries\n\n")
  8837. (beginning-of-line -1)))))
  8838. (outline-next-heading)
  8839. (org-back-over-empty-lines)
  8840. (backward-char 1)
  8841. (insert "\n")
  8842. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8843. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8844. (day
  8845. (let ((org-prefix-has-time t)
  8846. (org-agenda-time-leading-zero t)
  8847. fmt time time2)
  8848. (when org-agenda-insert-diary-extract-time
  8849. ;; Use org-agenda-format-item to parse text for a time-range and
  8850. ;; remove it. FIXME: This is a hack, we should refactor
  8851. ;; that function to make time extraction available separately
  8852. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8853. time (get-text-property 0 'time fmt)
  8854. time2 (if (> (length time) 0)
  8855. ;; split-string removes trailing ...... if
  8856. ;; no end time given. First space
  8857. ;; separates time from date.
  8858. (concat " " (car (split-string time "\\.")))
  8859. nil)
  8860. text (get-text-property 0 'txt fmt)))
  8861. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8862. (org-agenda-insert-diary-as-top-level text)
  8863. (require 'org-datetree)
  8864. (org-datetree-find-date-create d1)
  8865. (org-agenda-insert-diary-make-new-entry text))
  8866. (org-insert-time-stamp (org-time-from-absolute
  8867. (calendar-absolute-from-gregorian d1))
  8868. nil nil nil nil time2))
  8869. (end-of-line 0))
  8870. ((block) ;; Wrap this in (strictly unnecessary) parens because
  8871. ;; otherwise the indentation gets confused by the
  8872. ;; special meaning of 'block
  8873. (when (> (calendar-absolute-from-gregorian d1)
  8874. (calendar-absolute-from-gregorian d2))
  8875. (setq d1 (prog1 d2 (setq d2 d1))))
  8876. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8877. (org-agenda-insert-diary-as-top-level text)
  8878. (require 'org-datetree)
  8879. (org-datetree-find-date-create d1)
  8880. (org-agenda-insert-diary-make-new-entry text))
  8881. (org-insert-time-stamp (org-time-from-absolute
  8882. (calendar-absolute-from-gregorian d1)))
  8883. (insert "--")
  8884. (org-insert-time-stamp (org-time-from-absolute
  8885. (calendar-absolute-from-gregorian d2)))
  8886. (end-of-line 0)))
  8887. (if (string-match "\\S-" text)
  8888. (progn
  8889. (set-window-configuration cw)
  8890. (message "%s entry added to %s"
  8891. (capitalize (symbol-name type))
  8892. (abbreviate-file-name org-agenda-diary-file)))
  8893. (org-reveal t)
  8894. (message "Please finish entry here"))))
  8895. (defun org-agenda-insert-diary-as-top-level (text)
  8896. "Make new entry as a top-level entry at the end of the file.
  8897. Add TEXT as headline, and position the cursor in the second line so that
  8898. a timestamp can be added there."
  8899. (widen)
  8900. (goto-char (point-max))
  8901. (unless (bolp) (insert "\n"))
  8902. (org-insert-heading nil t t)
  8903. (insert text)
  8904. (org-end-of-meta-data)
  8905. (unless (bolp) (insert "\n"))
  8906. (when org-adapt-indentation (indent-to-column 2)))
  8907. (defun org-agenda-insert-diary-make-new-entry (text)
  8908. "Make a new entry with TEXT as a child of the current subtree.
  8909. Position the point in the heading's first body line so that
  8910. a timestamp can be added there."
  8911. (cond
  8912. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  8913. (end-of-line)
  8914. (org-insert-heading '(4) t)
  8915. (org-do-demote))
  8916. (t
  8917. (outline-next-heading)
  8918. (org-back-over-empty-lines)
  8919. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  8920. (org-insert-heading nil t)
  8921. (org-do-demote)))
  8922. (let ((col (current-column)))
  8923. (insert text)
  8924. (org-end-of-meta-data)
  8925. ;; Ensure point is left on a blank line, at proper indentation.
  8926. (unless (bolp) (insert "\n"))
  8927. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  8928. (when org-adapt-indentation (indent-to-column col)))
  8929. (org-show-set-visibility 'lineage))
  8930. (defun org-agenda-diary-entry ()
  8931. "Make a diary entry, like the `i' command from the calendar.
  8932. All the standard commands work: block, weekly etc.
  8933. When `org-agenda-diary-file' points to a file,
  8934. `org-agenda-diary-entry-in-org-file' is called instead to create
  8935. entries in that Org file."
  8936. (interactive)
  8937. (if (not (eq org-agenda-diary-file 'diary-file))
  8938. (org-agenda-diary-entry-in-org-file)
  8939. (require 'diary-lib)
  8940. (let* ((char (read-char-exclusive
  8941. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  8942. [a]nniversary [b]lock [c]yclic"))
  8943. (cmd (cdr (assoc char
  8944. '((?d . diary-insert-entry)
  8945. (?w . diary-insert-weekly-entry)
  8946. (?m . diary-insert-monthly-entry)
  8947. (?y . diary-insert-yearly-entry)
  8948. (?a . diary-insert-anniversary-entry)
  8949. (?b . diary-insert-block-entry)
  8950. (?c . diary-insert-cyclic-entry)))))
  8951. (oldf (symbol-function 'calendar-cursor-to-date))
  8952. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8953. (point (point))
  8954. (mark (or (mark t) (point))))
  8955. (unless cmd
  8956. (user-error "No command associated with <%c>" char))
  8957. (unless (and (get-text-property point 'day)
  8958. (or (not (equal ?b char))
  8959. (get-text-property mark 'day)))
  8960. (user-error "Don't know which date to use for diary entry"))
  8961. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8962. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8963. (let ((calendar-mark-ring
  8964. (list (calendar-gregorian-from-absolute
  8965. (or (get-text-property mark 'day)
  8966. (get-text-property point 'day))))))
  8967. (unwind-protect
  8968. (progn
  8969. (fset 'calendar-cursor-to-date
  8970. (lambda (&optional error dummy)
  8971. (calendar-gregorian-from-absolute
  8972. (get-text-property point 'day))))
  8973. (call-interactively cmd))
  8974. (fset 'calendar-cursor-to-date oldf))))))
  8975. (defun org-agenda-execute-calendar-command (cmd)
  8976. "Execute a calendar command from the agenda with date from cursor."
  8977. (org-agenda-check-type t 'agenda)
  8978. (require 'diary-lib)
  8979. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8980. (user-error "Don't know which date to use for the calendar command"))
  8981. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8982. (point (point))
  8983. (date (calendar-gregorian-from-absolute
  8984. (get-text-property point 'day)))
  8985. ;; the following 2 vars are needed in the calendar
  8986. (displayed-month (car date))
  8987. (displayed-year (nth 2 date)))
  8988. (unwind-protect
  8989. (progn
  8990. (fset 'calendar-cursor-to-date
  8991. (lambda (&optional error dummy)
  8992. (calendar-gregorian-from-absolute
  8993. (get-text-property point 'day))))
  8994. (call-interactively cmd))
  8995. (fset 'calendar-cursor-to-date oldf))))
  8996. (defun org-agenda-phases-of-moon ()
  8997. "Display the phases of the moon for the 3 months around the cursor date."
  8998. (interactive)
  8999. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  9000. (defun org-agenda-holidays ()
  9001. "Display the holidays for the 3 months around the cursor date."
  9002. (interactive)
  9003. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  9004. (defvar calendar-longitude) ; defined in calendar.el
  9005. (defvar calendar-latitude) ; defined in calendar.el
  9006. (defvar calendar-location-name) ; defined in calendar.el
  9007. (defun org-agenda-sunrise-sunset (arg)
  9008. "Display sunrise and sunset for the cursor date.
  9009. Latitude and longitude can be specified with the variables
  9010. `calendar-latitude' and `calendar-longitude'. When called with prefix
  9011. argument, latitude and longitude will be prompted for."
  9012. (interactive "P")
  9013. (require 'solar)
  9014. (let ((calendar-longitude (if arg nil calendar-longitude))
  9015. (calendar-latitude (if arg nil calendar-latitude))
  9016. (calendar-location-name
  9017. (if arg "the given coordinates" calendar-location-name)))
  9018. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  9019. (defun org-agenda-goto-calendar ()
  9020. "Open the Emacs calendar with the date at the cursor."
  9021. (interactive)
  9022. (org-agenda-check-type t 'agenda)
  9023. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  9024. (user-error "Don't know which date to open in calendar")))
  9025. (date (calendar-gregorian-from-absolute day))
  9026. (calendar-move-hook nil)
  9027. (calendar-view-holidays-initially-flag nil)
  9028. (calendar-view-diary-initially-flag nil))
  9029. (calendar)
  9030. (calendar-goto-date date)))
  9031. ;;;###autoload
  9032. (defun org-calendar-goto-agenda ()
  9033. "Compute the Org agenda for the calendar date displayed at the cursor.
  9034. This is a command that has to be installed in `calendar-mode-map'."
  9035. (interactive)
  9036. ;; Temporarily disable sticky agenda since user clearly wants to
  9037. ;; refresh view anyway.
  9038. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  9039. (org-agenda-sticky nil))
  9040. (org-agenda-list nil (calendar-absolute-from-gregorian
  9041. (calendar-cursor-to-date))
  9042. nil)))
  9043. (defun org-agenda-convert-date ()
  9044. (interactive)
  9045. (org-agenda-check-type t 'agenda)
  9046. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9047. date s)
  9048. (unless day
  9049. (user-error "Don't know which date to convert"))
  9050. (setq date (calendar-gregorian-from-absolute day))
  9051. (setq s (concat
  9052. "Gregorian: " (calendar-date-string date) "\n"
  9053. "ISO: " (calendar-iso-date-string date) "\n"
  9054. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9055. "Julian: " (calendar-julian-date-string date) "\n"
  9056. "Astron. JD: " (calendar-astro-date-string date)
  9057. " (Julian date number at noon UTC)\n"
  9058. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9059. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9060. "French: " (calendar-french-date-string date) "\n"
  9061. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9062. "Mayan: " (calendar-mayan-date-string date) "\n"
  9063. "Coptic: " (calendar-coptic-date-string date) "\n"
  9064. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9065. "Persian: " (calendar-persian-date-string date) "\n"
  9066. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9067. (with-output-to-temp-buffer "*Dates*"
  9068. (princ s))
  9069. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9070. ;;; Bulk commands
  9071. (defun org-agenda-bulk-marked-p ()
  9072. "Non-nil when current entry is marked for bulk action."
  9073. (eq (get-char-property (point-at-bol) 'type)
  9074. 'org-marked-entry-overlay))
  9075. (defun org-agenda-bulk-mark (&optional arg)
  9076. "Mark entries for future bulk action.
  9077. When ARG is nil or one and region is not active then mark the
  9078. entry at point.
  9079. When ARG is nil or one and region is active then mark the entries
  9080. in the region.
  9081. When ARG is greater than one mark ARG lines."
  9082. (interactive "p")
  9083. (when (and (or (not arg) (= arg 1)) (use-region-p))
  9084. (setq arg (count-lines (region-beginning) (region-end)))
  9085. (goto-char (region-beginning))
  9086. (deactivate-mark))
  9087. (dotimes (i (or arg 1))
  9088. (unless (org-get-at-bol 'org-agenda-diary-link)
  9089. (let* ((m (org-get-at-bol 'org-hd-marker))
  9090. ov)
  9091. (unless (org-agenda-bulk-marked-p)
  9092. (unless m (user-error "Nothing to mark at point"))
  9093. (push m org-agenda-bulk-marked-entries)
  9094. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9095. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9096. (org-get-todo-face "TODO")
  9097. 'evaporate)
  9098. (overlay-put ov 'type 'org-marked-entry-overlay))
  9099. (end-of-line 1)
  9100. (or (ignore-errors
  9101. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9102. (beginning-of-line 2))
  9103. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9104. (beginning-of-line 2)))))
  9105. (message "%d entries marked for bulk action"
  9106. (length org-agenda-bulk-marked-entries)))
  9107. (defun org-agenda-bulk-mark-all ()
  9108. "Mark all entries for future agenda bulk action."
  9109. (interactive)
  9110. (org-agenda-bulk-mark-regexp "."))
  9111. (defun org-agenda-bulk-mark-regexp (regexp)
  9112. "Mark entries matching REGEXP for future agenda bulk action."
  9113. (interactive "sMark entries matching regexp: ")
  9114. (let ((entries-marked 0) txt-at-point)
  9115. (save-excursion
  9116. (goto-char (point-min))
  9117. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9118. (while (and (re-search-forward regexp nil t)
  9119. (setq txt-at-point (get-text-property (point) 'txt)))
  9120. (if (get-char-property (point) 'invisible)
  9121. (beginning-of-line 2)
  9122. (when (string-match regexp txt-at-point)
  9123. (setq entries-marked (1+ entries-marked))
  9124. (call-interactively 'org-agenda-bulk-mark)))))
  9125. (unless entries-marked
  9126. (message "No entry matching this regexp."))))
  9127. (defun org-agenda-bulk-unmark (&optional arg)
  9128. "Unmark the entry at point for future bulk action."
  9129. (interactive "P")
  9130. (if arg
  9131. (org-agenda-bulk-unmark-all)
  9132. (cond ((org-agenda-bulk-marked-p)
  9133. (org-agenda-bulk-remove-overlays
  9134. (point-at-bol) (+ 2 (point-at-bol)))
  9135. (setq org-agenda-bulk-marked-entries
  9136. (delete (org-get-at-bol 'org-hd-marker)
  9137. org-agenda-bulk-marked-entries))
  9138. (end-of-line 1)
  9139. (or (ignore-errors
  9140. (goto-char (next-single-property-change (point) 'txt)))
  9141. (beginning-of-line 2))
  9142. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9143. (beginning-of-line 2))
  9144. (message "%d entries left marked for bulk action"
  9145. (length org-agenda-bulk-marked-entries)))
  9146. (t (message "No entry to unmark here")))))
  9147. (defun org-agenda-bulk-toggle-all ()
  9148. "Toggle all marks for bulk action."
  9149. (interactive)
  9150. (save-excursion
  9151. (goto-char (point-min))
  9152. (while (ignore-errors
  9153. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9154. (org-agenda-bulk-toggle))))
  9155. (defun org-agenda-bulk-toggle ()
  9156. "Toggle the mark at point for bulk action."
  9157. (interactive)
  9158. (if (org-agenda-bulk-marked-p)
  9159. (org-agenda-bulk-unmark)
  9160. (org-agenda-bulk-mark)))
  9161. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9162. "Remove the mark overlays between BEG and END in the agenda buffer.
  9163. BEG and END default to the buffer limits.
  9164. This only removes the overlays, it does not remove the markers
  9165. from the list in `org-agenda-bulk-marked-entries'."
  9166. (interactive)
  9167. (mapc (lambda (ov)
  9168. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9169. (delete-overlay ov)))
  9170. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9171. (defun org-agenda-bulk-unmark-all ()
  9172. "Remove all marks in the agenda buffer.
  9173. This will remove the markers and the overlays."
  9174. (interactive)
  9175. (if (null org-agenda-bulk-marked-entries)
  9176. (message "No entry to unmark")
  9177. (setq org-agenda-bulk-marked-entries nil)
  9178. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9179. (defcustom org-agenda-persistent-marks nil
  9180. "Non-nil means marked items will stay marked after a bulk action.
  9181. You can toggle this interactively by typing `p' when prompted for a
  9182. bulk action."
  9183. :group 'org-agenda
  9184. :version "24.1"
  9185. :type 'boolean)
  9186. (defun org-agenda-bulk-action (&optional arg)
  9187. "Execute an remote-editing action on all marked entries.
  9188. The prefix arg is passed through to the command if possible."
  9189. (interactive "P")
  9190. ;; When there is no mark, act on the agenda entry at point.
  9191. (if (not org-agenda-bulk-marked-entries)
  9192. (save-excursion (org-agenda-bulk-mark)))
  9193. (dolist (m org-agenda-bulk-marked-entries)
  9194. (unless (and (markerp m)
  9195. (marker-buffer m)
  9196. (buffer-live-p (marker-buffer m))
  9197. (marker-position m))
  9198. (user-error "Marker %s for bulk command is invalid" m)))
  9199. ;; Prompt for the bulk command.
  9200. (org-unlogged-message
  9201. (concat (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")
  9202. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9203. "[S]catter [f]unction [p]ersist-toggle "
  9204. (and org-agenda-bulk-custom-functions
  9205. (format " Custom: [%s]"
  9206. (mapconcat (lambda (f) (char-to-string (car f)))
  9207. org-agenda-bulk-custom-functions
  9208. "")))))
  9209. (catch 'exit
  9210. (let* ((org-log-refile (if org-log-refile 'time nil))
  9211. (entries (reverse org-agenda-bulk-marked-entries))
  9212. (org-overriding-default-time
  9213. (and (get-text-property (point) 'org-agenda-date-header)
  9214. (org-get-cursor-date)))
  9215. redo-at-end
  9216. cmd)
  9217. (pcase (read-char-exclusive)
  9218. (?p
  9219. (let ((org-agenda-persistent-marks
  9220. (not org-agenda-persistent-marks)))
  9221. (org-agenda-bulk-action)
  9222. (throw 'exit nil)))
  9223. (?$
  9224. (setq cmd #'org-agenda-archive))
  9225. (?A
  9226. (setq cmd #'org-agenda-archive-to-archive-sibling))
  9227. ((or ?r ?w)
  9228. (let ((refile-location
  9229. (org-refile-get-location
  9230. "Refile to"
  9231. (marker-buffer (car entries))
  9232. org-refile-allow-creating-parent-nodes)))
  9233. (when (nth 3 refile-location)
  9234. (setcar (nthcdr 3 refile-location)
  9235. (move-marker
  9236. (make-marker)
  9237. (nth 3 refile-location)
  9238. (or (get-file-buffer (nth 1 refile-location))
  9239. (find-buffer-visiting (nth 1 refile-location))
  9240. (error "This should not happen")))))
  9241. (setq cmd `(lambda () (org-agenda-refile nil ',refile-location t)))
  9242. (setq redo-at-end t)))
  9243. (?t
  9244. (let ((state (completing-read
  9245. "Todo state: "
  9246. (with-current-buffer (marker-buffer (car entries))
  9247. (mapcar #'list org-todo-keywords-1)))))
  9248. (setq cmd `(lambda ()
  9249. (let ((org-inhibit-blocking t)
  9250. (org-inhibit-logging 'note))
  9251. (org-agenda-todo ,state))))))
  9252. ((and (or ?- ?+) action)
  9253. (let ((tag (completing-read
  9254. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9255. (with-current-buffer (marker-buffer (car entries))
  9256. (delq nil
  9257. (mapcar (lambda (x) (and (stringp (car x)) x))
  9258. org-current-tag-alist))))))
  9259. (setq cmd
  9260. `(lambda ()
  9261. (org-agenda-set-tags ,tag
  9262. ,(if (eq action ?+) ''on ''off))))))
  9263. ((and (or ?s ?d) c)
  9264. (let* ((schedule? (eq c ?s))
  9265. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  9266. (time
  9267. (and (not arg)
  9268. (let ((new (org-read-date
  9269. nil nil nil prompt org-overriding-default-time)))
  9270. ;; A "double plus" answer applies to every
  9271. ;; scheduled time. Do not turn it into
  9272. ;; a fixed date yet.
  9273. (if (string-match-p "\\`[ \t]*\\+\\+"
  9274. org-read-date-final-answer)
  9275. org-read-date-final-answer
  9276. new)))))
  9277. ;; Make sure to not prompt for a note when bulk
  9278. ;; rescheduling/resetting deadline as Org cannot cope with
  9279. ;; simultaneous notes. Besides, it could be annoying
  9280. ;; depending on the number of marked items.
  9281. (setq cmd
  9282. (if schedule?
  9283. `(lambda ()
  9284. (let ((org-log-reschedule
  9285. (and org-log-reschedule 'time)))
  9286. (org-agenda-schedule arg ,time)))
  9287. `(lambda ()
  9288. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  9289. (org-agenda-deadline arg ,time)))))))
  9290. (?S
  9291. (unless (org-agenda-check-type nil 'agenda 'todo)
  9292. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  9293. (let ((days (read-number
  9294. (format "Scatter tasks across how many %sdays: "
  9295. (if arg "week" ""))
  9296. 7)))
  9297. (setq cmd
  9298. `(lambda ()
  9299. (let ((distance (1+ (random ,days))))
  9300. (when arg
  9301. (let ((dist distance)
  9302. (day-of-week
  9303. (calendar-day-of-week
  9304. (calendar-gregorian-from-absolute (org-today)))))
  9305. (dotimes (i (1+ dist))
  9306. (while (member day-of-week org-agenda-weekend-days)
  9307. (cl-incf distance)
  9308. (cl-incf day-of-week)
  9309. (when (= day-of-week 7)
  9310. (setq day-of-week 0)))
  9311. (cl-incf day-of-week)
  9312. (when (= day-of-week 7)
  9313. (setq day-of-week 0)))))
  9314. ;; Silently fail when try to replan a sexp entry.
  9315. (ignore-errors
  9316. (let* ((date (calendar-gregorian-from-absolute
  9317. (+ (org-today) distance)))
  9318. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9319. (nth 2 date))))
  9320. (org-agenda-schedule nil time))))))))
  9321. (?f
  9322. (setq cmd
  9323. (intern
  9324. (completing-read "Function: " obarray #'fboundp t nil nil))))
  9325. (action
  9326. (pcase (assoc action org-agenda-bulk-custom-functions)
  9327. (`(,_ ,f) (setq cmd f) (setq redo-at-end t))
  9328. (_ (user-error "Invalid bulk action: %c" action)))))
  9329. ;; Sort the markers, to make sure that parents are handled
  9330. ;; before children.
  9331. (setq entries (sort entries
  9332. (lambda (a b)
  9333. (cond
  9334. ((eq (marker-buffer a) (marker-buffer b))
  9335. (< (marker-position a) (marker-position b)))
  9336. (t
  9337. (string< (buffer-name (marker-buffer a))
  9338. (buffer-name (marker-buffer b))))))))
  9339. ;; Now loop over all markers and apply CMD.
  9340. (let ((processed 0)
  9341. (skipped 0))
  9342. (dolist (e entries)
  9343. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  9344. (if (not pos)
  9345. (progn (message "Skipping removed entry at %s" e)
  9346. (cl-incf skipped))
  9347. (goto-char pos)
  9348. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  9349. ;; `post-command-hook' is not run yet. We make sure any
  9350. ;; pending log note is processed.
  9351. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9352. (memq 'org-add-log-note post-command-hook))
  9353. (org-add-log-note))
  9354. (cl-incf processed))))
  9355. (when redo-at-end (org-agenda-redo))
  9356. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  9357. (message "Acted on %d entries%s%s"
  9358. processed
  9359. (if (= skipped 0)
  9360. ""
  9361. (format ", skipped %d (disappeared before their turn)"
  9362. skipped))
  9363. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  9364. (defun org-agenda-capture (&optional with-time)
  9365. "Call `org-capture' with the date at point.
  9366. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9367. current HH:MM time."
  9368. (interactive "P")
  9369. (if (not (eq major-mode 'org-agenda-mode))
  9370. (user-error "You cannot do this outside of agenda buffers")
  9371. (let ((org-overriding-default-time
  9372. (org-get-cursor-date (equal with-time 1))))
  9373. (call-interactively 'org-capture))))
  9374. ;;; Dragging agenda lines forward/backward
  9375. (defun org-agenda-reapply-filters ()
  9376. "Re-apply all agenda filters."
  9377. (mapcar
  9378. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9379. `((,org-agenda-tag-filter tag)
  9380. (,org-agenda-category-filter category)
  9381. (,org-agenda-regexp-filter regexp)
  9382. (,org-agenda-effort-filter effort)
  9383. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9384. (,(get 'org-agenda-category-filter :preset-filter) category)
  9385. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9386. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9387. (defun org-agenda-drag-line-forward (arg &optional backward)
  9388. "Drag an agenda line forward by ARG lines.
  9389. When the optional argument `backward' is non-nil, move backward."
  9390. (interactive "p")
  9391. (let ((inhibit-read-only t) lst line)
  9392. (if (or (not (get-text-property (point) 'txt))
  9393. (save-excursion
  9394. (dotimes (n arg)
  9395. (move-beginning-of-line (if backward 0 2))
  9396. (push (not (get-text-property (point) 'txt)) lst))
  9397. (delq nil lst)))
  9398. (message "Cannot move line forward")
  9399. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9400. (move-beginning-of-line 1)
  9401. (setq line (buffer-substring (point) end))
  9402. (delete-region (point) end)
  9403. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9404. (insert line)
  9405. (org-agenda-reapply-filters)
  9406. (org-agenda-mark-clocking-task)
  9407. (move-beginning-of-line 0)))))
  9408. (defun org-agenda-drag-line-backward (arg)
  9409. "Drag an agenda line backward by ARG lines."
  9410. (interactive "p")
  9411. (org-agenda-drag-line-forward arg t))
  9412. ;;; Flagging notes
  9413. (defun org-agenda-show-the-flagging-note ()
  9414. "Display the flagging note in the other window.
  9415. When called a second time in direct sequence, offer to remove the FLAGGING
  9416. tag and (if present) the flagging note."
  9417. (interactive)
  9418. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9419. (win (selected-window))
  9420. note heading newhead)
  9421. (unless hdmarker
  9422. (user-error "No linked entry at point"))
  9423. (if (and (eq this-command last-command)
  9424. (y-or-n-p "Unflag and remove any flagging note? "))
  9425. (progn
  9426. (org-agenda-remove-flag hdmarker)
  9427. (let ((win (get-buffer-window "*Flagging Note*")))
  9428. (and win (delete-window win)))
  9429. (message "Entry unflagged"))
  9430. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9431. (unless note
  9432. (user-error "No flagging note"))
  9433. (org-kill-new note)
  9434. (org-switch-to-buffer-other-window "*Flagging Note*")
  9435. (erase-buffer)
  9436. (insert note)
  9437. (goto-char (point-min))
  9438. (while (re-search-forward "\\\\n" nil t)
  9439. (replace-match "\n" t t))
  9440. (goto-char (point-min))
  9441. (select-window win)
  9442. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9443. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  9444. tag and note")))))
  9445. (defun org-agenda-remove-flag (marker)
  9446. "Remove the FLAGGED tag and any flagging note in the entry."
  9447. (let (newhead)
  9448. (org-with-point-at marker
  9449. (org-toggle-tag "FLAGGED" 'off)
  9450. (org-entry-delete nil "THEFLAGGINGNOTE")
  9451. (setq newhead (org-get-heading)))
  9452. (org-agenda-change-all-lines newhead marker)
  9453. (message "Entry unflagged")))
  9454. (defun org-agenda-get-any-marker (&optional pos)
  9455. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9456. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9457. ;;; Appointment reminders
  9458. (defvar appt-time-msg-list) ; defined in appt.el
  9459. ;;;###autoload
  9460. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9461. "Activate appointments found in `org-agenda-files'.
  9462. With a `\\[universal-argument]' prefix, refresh the list of \
  9463. appointments.
  9464. If FILTER is t, interactively prompt the user for a regular
  9465. expression, and filter out entries that don't match it.
  9466. If FILTER is a string, use this string as a regular expression
  9467. for filtering entries out.
  9468. If FILTER is a function, filter out entries against which
  9469. calling the function returns nil. This function takes one
  9470. argument: an entry from `org-agenda-get-day-entries'.
  9471. FILTER can also be an alist with the car of each cell being
  9472. either `headline' or `category'. For example:
  9473. \\='((headline \"IMPORTANT\")
  9474. (category \"Work\"))
  9475. will only add headlines containing IMPORTANT or headlines
  9476. belonging to the \"Work\" category.
  9477. ARGS are symbols indicating what kind of entries to consider.
  9478. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9479. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9480. and :timestamp entries. See the docstring of `org-diary' for
  9481. details and examples.
  9482. If an entry has a APPT_WARNTIME property, its value will be used
  9483. to override `appt-message-warning-time'."
  9484. (interactive "P")
  9485. (when refresh (setq appt-time-msg-list nil))
  9486. (when (eq filter t)
  9487. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9488. (let* ((cnt 0) ; count added events
  9489. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9490. (org-agenda-new-buffers nil)
  9491. (org-deadline-warning-days 0)
  9492. ;; Do not use `org-today' here because appt only takes
  9493. ;; time and without date as argument, so it may pass wrong
  9494. ;; information otherwise
  9495. (today (org-date-to-gregorian
  9496. (time-to-days nil)))
  9497. (org-agenda-restrict nil)
  9498. (files (org-agenda-files 'unrestricted)) entries file
  9499. (org-agenda-buffer nil))
  9500. ;; Get all entries which may contain an appt
  9501. (org-agenda-prepare-buffers files)
  9502. (while (setq file (pop files))
  9503. (setq entries
  9504. (delq nil
  9505. (append entries
  9506. (apply 'org-agenda-get-day-entries
  9507. file today scope)))))
  9508. ;; Map thru entries and find if we should filter them out
  9509. (mapc
  9510. (lambda (x)
  9511. (let* ((evt (org-trim
  9512. (replace-regexp-in-string
  9513. org-bracket-link-regexp "\\3"
  9514. (or (get-text-property 1 'txt x) ""))))
  9515. (cat (get-text-property (1- (length x)) 'org-category x))
  9516. (tod (get-text-property 1 'time-of-day x))
  9517. (ok (or (null filter)
  9518. (and (stringp filter) (string-match filter evt))
  9519. (and (functionp filter) (funcall filter x))
  9520. (and (listp filter)
  9521. (let ((cat-filter (cadr (assq 'category filter)))
  9522. (evt-filter (cadr (assq 'headline filter))))
  9523. (or (and (stringp cat-filter)
  9524. (string-match cat-filter cat))
  9525. (and (stringp evt-filter)
  9526. (string-match evt-filter evt)))))))
  9527. (wrn (get-text-property 1 'warntime x)))
  9528. ;; FIXME: Shall we remove text-properties for the appt text?
  9529. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9530. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9531. (setq tod (concat "00" (number-to-string tod)))
  9532. (setq tod (when (string-match
  9533. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9534. (concat (match-string 1 tod) ":"
  9535. (match-string 2 tod))))
  9536. (when (appt-add tod evt wrn)
  9537. (setq cnt (1+ cnt))))))
  9538. entries)
  9539. (org-release-buffers org-agenda-new-buffers)
  9540. (if (eq cnt 0)
  9541. (message "No event to add")
  9542. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9543. (defun org-agenda-today-p (date)
  9544. "Non nil when DATE means today.
  9545. DATE is either a list of the form (month day year) or a number of
  9546. days as returned by `calendar-absolute-from-gregorian' or
  9547. `org-today'. This function considers `org-extend-today-until'
  9548. when defining today."
  9549. (eq (org-today)
  9550. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9551. (defun org-agenda-todo-yesterday (&optional arg)
  9552. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9553. (interactive "P")
  9554. (let* ((org-use-effective-time t)
  9555. (hour (nth 2 (decode-time (org-current-time))))
  9556. (org-extend-today-until (1+ hour)))
  9557. (org-agenda-todo arg)))
  9558. (provide 'org-agenda)
  9559. ;;; org-agenda.el ends here