org-agenda.el 394 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2018 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://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. (defcustom org-agenda-search-view-always-boolean nil
  1238. "Non-nil means the search string is interpreted as individual parts.
  1239. The search string for search view can either be interpreted as a phrase,
  1240. or as a list of snippets that define a boolean search for a number of
  1241. strings.
  1242. When this is non-nil, the string will be split on whitespace, and each
  1243. snippet will be searched individually, and all must match in order to
  1244. select an entry. A snippet is then a single string of non-white
  1245. characters, or a string in double quotes, or a regexp in {} braces.
  1246. If a snippet is preceded by \"-\", the snippet must *not* match.
  1247. \"+\" is syntactic sugar for positive selection. Each snippet may
  1248. be found as a full word or a partial word, but see the variable
  1249. `org-agenda-search-view-force-full-words'.
  1250. When this is nil, search will look for the entire search phrase as one,
  1251. with each space character matching any amount of whitespace, including
  1252. line breaks.
  1253. Even when this is nil, you can still switch to Boolean search dynamically
  1254. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1255. is a regexp marked with braces like \"{abc}\", this will also switch to
  1256. boolean search."
  1257. :group 'org-agenda-search-view
  1258. :version "24.1"
  1259. :type 'boolean)
  1260. (defvaralias 'org-agenda-search-view-search-words-only
  1261. 'org-agenda-search-view-always-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 five entries, each for the different agenda types. The
  1451. keys of the sublists are `agenda', `todo', `search' and `tags'.
  1452. The values 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. (defcustom org-agenda-remove-tags nil
  1647. "Non-nil means remove the tags from the headline copy in the agenda.
  1648. When this is the symbol `prefix', only remove tags when
  1649. `org-agenda-prefix-format' contains a `%T' specifier."
  1650. :group 'org-agenda-line-format
  1651. :type '(choice
  1652. (const :tag "Always" t)
  1653. (const :tag "Never" nil)
  1654. (const :tag "When prefix format contains %T" prefix)))
  1655. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1656. 'org-agenda-remove-tags)
  1657. (defcustom org-agenda-tags-column 'auto
  1658. "Shift tags in agenda items to this column.
  1659. If set to `auto', tags will be automatically aligned to the right
  1660. edge of the window.
  1661. If set to a positive number, tags will be left-aligned to that
  1662. column. If set to a negative number, tags will be right-aligned
  1663. to that column. For example, -80 works well for a normal 80
  1664. character screen."
  1665. :group 'org-agenda-line-format
  1666. :type '(choice
  1667. (const :tag "Automatically align to right edge of window" auto)
  1668. (integer :tag "Specific column" -80))
  1669. :package-version '(Org . "9.1")
  1670. :version "26.1")
  1671. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  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. ;;; Define the org-agenda-mode
  1811. (defvar org-agenda-mode-map (make-sparse-keymap)
  1812. "Keymap for `org-agenda-mode'.")
  1813. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1814. (defvar org-agenda-menu) ; defined later in this file.
  1815. (defvar org-agenda-restrict nil) ; defined later in this file.
  1816. (defvar org-agenda-follow-mode nil)
  1817. (defvar org-agenda-entry-text-mode nil)
  1818. (defvar org-agenda-clockreport-mode nil)
  1819. (defvar org-agenda-show-log nil
  1820. "When non-nil, show the log in the agenda.
  1821. Do not set this directly; instead use
  1822. `org-agenda-start-with-log-mode', which see.")
  1823. (defvar org-agenda-redo-command nil)
  1824. (defvar org-agenda-query-string nil)
  1825. (defvar org-agenda-mode-hook nil
  1826. "Hook run after `org-agenda-mode' is turned on.
  1827. The buffer is still writable when this hook is called.")
  1828. (defvar org-agenda-type nil)
  1829. (defvar org-agenda-force-single-file nil)
  1830. (defvar org-agenda-bulk-marked-entries nil
  1831. "List of markers that refer to marked entries in the agenda.")
  1832. (defvar org-agenda-current-date nil
  1833. "Active date when building the agenda.")
  1834. ;;; Multiple agenda buffers support
  1835. (defcustom org-agenda-sticky nil
  1836. "Non-nil means agenda q key will bury agenda buffers.
  1837. Agenda commands will then show existing buffer instead of generating new ones.
  1838. When nil, `q' will kill the single agenda buffer."
  1839. :group 'org-agenda
  1840. :version "24.3"
  1841. :type 'boolean)
  1842. ;;;###autoload
  1843. (defun org-toggle-sticky-agenda (&optional arg)
  1844. "Toggle `org-agenda-sticky'."
  1845. (interactive "P")
  1846. (let ((new-value (if arg
  1847. (> (prefix-numeric-value arg) 0)
  1848. (not org-agenda-sticky))))
  1849. (if (equal new-value org-agenda-sticky)
  1850. (and (called-interactively-p 'interactive)
  1851. (message "Sticky agenda was already %s"
  1852. (if org-agenda-sticky "enabled" "disabled")))
  1853. (setq org-agenda-sticky new-value)
  1854. (org-agenda-kill-all-agenda-buffers)
  1855. (and (called-interactively-p 'interactive)
  1856. (message "Sticky agenda %s"
  1857. (if org-agenda-sticky "enabled" "disabled"))))))
  1858. (defvar org-agenda-buffer nil
  1859. "Agenda buffer currently being generated.")
  1860. (defvar org-agenda-last-prefix-arg nil)
  1861. (defvar org-agenda-this-buffer-name nil)
  1862. (defvar org-agenda-doing-sticky-redo nil)
  1863. (defvar org-agenda-this-buffer-is-sticky nil)
  1864. (defvar org-agenda-last-indirect-buffer nil
  1865. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1866. (defvar org-agenda-lprops nil)
  1867. (defconst org-agenda-local-vars
  1868. '(org-agenda-this-buffer-name
  1869. org-agenda-undo-list
  1870. org-agenda-pending-undo-list
  1871. org-agenda-follow-mode
  1872. org-agenda-entry-text-mode
  1873. org-agenda-clockreport-mode
  1874. org-agenda-show-log
  1875. org-agenda-redo-command
  1876. org-agenda-query-string
  1877. org-agenda-type
  1878. org-agenda-bulk-marked-entries
  1879. org-agenda-undo-has-started-in
  1880. org-agenda-info
  1881. org-agenda-pre-window-conf
  1882. org-agenda-columns-active
  1883. org-agenda-tag-filter
  1884. org-agenda-category-filter
  1885. org-agenda-top-headline-filter
  1886. org-agenda-regexp-filter
  1887. org-agenda-effort-filter
  1888. org-agenda-markers
  1889. org-agenda-last-search-view-search-was-boolean
  1890. org-agenda-last-indirect-buffer
  1891. org-agenda-filtered-by-category
  1892. org-agenda-filter-form
  1893. org-agenda-cycle-counter
  1894. org-agenda-lprops
  1895. org-agenda-last-prefix-arg)
  1896. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1897. (defun org-agenda-mode ()
  1898. "Mode for time-sorted view on action items in Org files.
  1899. The following commands are available:
  1900. \\{org-agenda-mode-map}"
  1901. (interactive)
  1902. (cond (org-agenda-doing-sticky-redo
  1903. ;; Refreshing sticky agenda-buffer
  1904. ;;
  1905. ;; Preserve the value of `org-agenda-local-vars' variables,
  1906. ;; while letting `kill-all-local-variables' kill the rest
  1907. (let ((save (buffer-local-variables)))
  1908. (kill-all-local-variables)
  1909. (mapc #'make-local-variable org-agenda-local-vars)
  1910. (dolist (elem save)
  1911. (pcase elem
  1912. (`(,var . ,val) ;ignore unbound variables
  1913. (when (and val (memq var org-agenda-local-vars))
  1914. (set var val))))))
  1915. (setq-local org-agenda-this-buffer-is-sticky t))
  1916. (org-agenda-sticky
  1917. ;; Creating a sticky Agenda buffer for the first time
  1918. (kill-all-local-variables)
  1919. (mapc 'make-local-variable org-agenda-local-vars)
  1920. (setq-local org-agenda-this-buffer-is-sticky t))
  1921. (t
  1922. ;; Creating a non-sticky agenda buffer
  1923. (kill-all-local-variables)
  1924. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1925. (setq org-agenda-undo-list nil
  1926. org-agenda-pending-undo-list nil
  1927. org-agenda-bulk-marked-entries nil)
  1928. (setq major-mode 'org-agenda-mode)
  1929. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1930. (setq-local font-lock-global-modes (list 'not major-mode))
  1931. (setq mode-name "Org-Agenda")
  1932. (setq indent-tabs-mode nil)
  1933. (use-local-map org-agenda-mode-map)
  1934. (easy-menu-add org-agenda-menu)
  1935. (if org-startup-truncated (setq truncate-lines t))
  1936. (setq-local line-move-visual nil)
  1937. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1938. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1939. ;; Make sure properties are removed when copying text
  1940. (add-hook 'filter-buffer-substring-functions
  1941. (lambda (fun start end delete)
  1942. (substring-no-properties (funcall fun start end delete)))
  1943. nil t)
  1944. (unless org-agenda-keep-modes
  1945. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1946. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1947. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1948. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1949. (add-to-invisibility-spec '(org-filtered))
  1950. (add-to-invisibility-spec '(org-link))
  1951. (easy-menu-change
  1952. '("Agenda") "Agenda Files"
  1953. (append
  1954. (list
  1955. (vector
  1956. (if (get 'org-agenda-files 'org-restrict)
  1957. "Restricted to single file"
  1958. "Edit File List")
  1959. '(org-edit-agenda-file-list)
  1960. (not (get 'org-agenda-files 'org-restrict)))
  1961. "--")
  1962. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1963. (org-agenda-set-mode-name)
  1964. (apply
  1965. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1966. (list 'org-agenda-mode-hook)))
  1967. (substitute-key-definition 'undo 'org-agenda-undo
  1968. org-agenda-mode-map global-map)
  1969. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1970. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1971. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1972. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1973. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1974. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1975. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1976. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1977. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1978. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1979. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1980. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1981. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1982. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1983. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1984. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1985. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1986. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1987. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1988. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1989. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1990. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1991. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1992. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1993. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1994. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1995. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1996. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1997. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1998. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1999. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  2000. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  2001. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  2002. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  2003. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  2004. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  2005. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  2006. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  2007. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  2008. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  2009. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  2010. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  2011. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  2012. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  2013. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  2014. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  2015. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  2016. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  2017. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  2018. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  2019. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  2021. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  2022. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2023. (while l (org-defkey org-agenda-mode-map
  2024. (int-to-string (pop l)) 'digit-argument)))
  2025. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  2026. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  2027. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  2028. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  2029. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  2030. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  2031. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  2032. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  2033. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  2034. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo-all)
  2035. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  2036. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2037. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2038. 'org-clock-modify-effort-estimate)
  2039. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2040. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2041. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2042. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2043. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2044. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2045. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2046. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2047. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2048. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2049. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2050. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2051. (substitute-key-definition 'next-line 'org-agenda-next-line
  2052. org-agenda-mode-map global-map)
  2053. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2054. org-agenda-mode-map global-map)
  2055. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2056. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2057. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2058. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2059. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2060. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2061. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2062. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2063. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2064. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2065. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2066. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2067. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2068. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2069. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2070. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2071. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2072. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2073. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2074. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2075. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2076. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2077. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2078. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2079. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2080. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2081. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2082. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2083. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2084. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2085. (org-defkey org-agenda-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock-from-agenda)
  2086. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2087. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2088. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2089. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2090. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2091. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2092. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2093. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2094. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2095. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2096. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2097. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-x_" 'org-timer-stop)
  2099. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2100. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2101. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2102. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2103. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2104. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2105. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2106. (when org-agenda-mouse-1-follows-link
  2107. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2108. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2109. '("Agenda"
  2110. ("Agenda Files")
  2111. "--"
  2112. ("Agenda Dates"
  2113. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2114. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2115. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2116. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2117. "--"
  2118. ("View"
  2119. ["Day View" org-agenda-day-view
  2120. :active (org-agenda-check-type nil 'agenda)
  2121. :style radio :selected (eq org-agenda-current-span 'day)
  2122. :keys "v d (or just d)"]
  2123. ["Week View" org-agenda-week-view
  2124. :active (org-agenda-check-type nil 'agenda)
  2125. :style radio :selected (eq org-agenda-current-span 'week)
  2126. :keys "v w"]
  2127. ["Fortnight View" org-agenda-fortnight-view
  2128. :active (org-agenda-check-type nil 'agenda)
  2129. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2130. :keys "v t"]
  2131. ["Month View" org-agenda-month-view
  2132. :active (org-agenda-check-type nil 'agenda)
  2133. :style radio :selected (eq org-agenda-current-span 'month)
  2134. :keys "v m"]
  2135. ["Year View" org-agenda-year-view
  2136. :active (org-agenda-check-type nil 'agenda)
  2137. :style radio :selected (eq org-agenda-current-span 'year)
  2138. :keys "v y"]
  2139. "--"
  2140. ["Include Diary" org-agenda-toggle-diary
  2141. :style toggle :selected org-agenda-include-diary
  2142. :active (org-agenda-check-type nil 'agenda)]
  2143. ["Include Deadlines" org-agenda-toggle-deadlines
  2144. :style toggle :selected org-agenda-include-deadlines
  2145. :active (org-agenda-check-type nil 'agenda)]
  2146. ["Use Time Grid" org-agenda-toggle-time-grid
  2147. :style toggle :selected org-agenda-use-time-grid
  2148. :active (org-agenda-check-type nil 'agenda)]
  2149. "--"
  2150. ["Show clock report" org-agenda-clockreport-mode
  2151. :style toggle :selected org-agenda-clockreport-mode
  2152. :active (org-agenda-check-type nil 'agenda)]
  2153. ["Show some entry text" org-agenda-entry-text-mode
  2154. :style toggle :selected org-agenda-entry-text-mode
  2155. :active t]
  2156. "--"
  2157. ["Show Logbook entries" org-agenda-log-mode
  2158. :style toggle :selected org-agenda-show-log
  2159. :active (org-agenda-check-type nil 'agenda)
  2160. :keys "v l (or just l)"]
  2161. ["Include archived trees" org-agenda-archives-mode
  2162. :style toggle :selected org-agenda-archives-mode :active t
  2163. :keys "v a"]
  2164. ["Include archive files" (org-agenda-archives-mode t)
  2165. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2166. :keys "v A"]
  2167. "--"
  2168. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2169. ["Write view to file" org-agenda-write t]
  2170. ["Rebuild buffer" org-agenda-redo t]
  2171. ["Save all Org buffers" org-save-all-org-buffers t]
  2172. "--"
  2173. ["Show original entry" org-agenda-show t]
  2174. ["Go To (other window)" org-agenda-goto t]
  2175. ["Go To (this window)" org-agenda-switch-to t]
  2176. ["Capture with cursor date" org-agenda-capture t]
  2177. ["Follow Mode" org-agenda-follow-mode
  2178. :style toggle :selected org-agenda-follow-mode :active t]
  2179. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2180. "--"
  2181. ("TODO"
  2182. ["Cycle TODO" org-agenda-todo t]
  2183. ["Next TODO set" org-agenda-todo-nextset t]
  2184. ["Previous TODO set" org-agenda-todo-previousset t]
  2185. ["Add note" org-agenda-add-note t])
  2186. ("Archive/Refile/Delete"
  2187. ["Archive default" org-agenda-archive-default t]
  2188. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2189. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2190. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2191. ["Archive subtree" org-agenda-archive t]
  2192. "--"
  2193. ["Refile" org-agenda-refile t]
  2194. "--"
  2195. ["Delete subtree" org-agenda-kill t])
  2196. ("Bulk action"
  2197. ["Mark entry" org-agenda-bulk-mark t]
  2198. ["Mark all" org-agenda-bulk-mark-all t]
  2199. ["Unmark entry" org-agenda-bulk-unmark t]
  2200. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2201. ["Toggle mark" org-agenda-bulk-toggle t]
  2202. ["Toggle all" org-agenda-bulk-toggle-all t]
  2203. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2204. ["Act on all marked" org-agenda-bulk-action t]
  2205. "--"
  2206. ("Tags and Properties"
  2207. ["Show all Tags" org-agenda-show-tags t]
  2208. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2209. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2210. "--"
  2211. ["Column View" org-columns t])
  2212. ("Deadline/Schedule"
  2213. ["Schedule" org-agenda-schedule t]
  2214. ["Set Deadline" org-agenda-deadline t]
  2215. "--"
  2216. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2217. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2218. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2219. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2220. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2221. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2222. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2223. ("Clock and Effort"
  2224. ["Clock in" org-agenda-clock-in t]
  2225. ["Clock out" org-agenda-clock-out t]
  2226. ["Clock cancel" org-agenda-clock-cancel t]
  2227. ["Goto running clock" org-clock-goto t]
  2228. "--"
  2229. ["Set Effort" org-agenda-set-effort t]
  2230. ["Change clocked effort" org-clock-modify-effort-estimate
  2231. (org-clock-is-active)])
  2232. ("Priority"
  2233. ["Set Priority" org-agenda-priority t]
  2234. ["Increase Priority" org-agenda-priority-up t]
  2235. ["Decrease Priority" org-agenda-priority-down t]
  2236. ["Show Priority" org-show-priority t])
  2237. ("Calendar/Diary"
  2238. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2239. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2240. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2241. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2242. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2243. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2244. "--"
  2245. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2246. "--"
  2247. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2248. "--"
  2249. ("MobileOrg"
  2250. ["Push Files and Views" org-mobile-push t]
  2251. ["Get Captured and Flagged" org-mobile-pull t]
  2252. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2253. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2254. "--"
  2255. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2256. "--"
  2257. ["Quit" org-agenda-quit t]
  2258. ["Exit and Release Buffers" org-agenda-exit t]
  2259. ))
  2260. ;;; Agenda undo
  2261. (defvar org-agenda-allow-remote-undo t
  2262. "Non-nil means allow remote undo from the agenda buffer.")
  2263. (defvar org-agenda-undo-has-started-in nil
  2264. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2265. (defun org-agenda-undo ()
  2266. "Undo a remote editing step in the agenda.
  2267. This undoes changes both in the agenda buffer and in the remote buffer
  2268. that have been changed along."
  2269. (interactive)
  2270. (or org-agenda-allow-remote-undo
  2271. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2272. (if (not (eq this-command last-command))
  2273. (setq org-agenda-undo-has-started-in nil
  2274. org-agenda-pending-undo-list org-agenda-undo-list))
  2275. (if (not org-agenda-pending-undo-list)
  2276. (user-error "No further undo information"))
  2277. (let* ((entry (pop org-agenda-pending-undo-list))
  2278. buf line cmd rembuf)
  2279. (setq cmd (pop entry) line (pop entry))
  2280. (setq rembuf (nth 2 entry))
  2281. (org-with-remote-undo rembuf
  2282. (while (bufferp (setq buf (pop entry)))
  2283. (if (pop entry)
  2284. (with-current-buffer buf
  2285. (let ((last-undo-buffer buf)
  2286. (inhibit-read-only t))
  2287. (unless (memq buf org-agenda-undo-has-started-in)
  2288. (push buf org-agenda-undo-has-started-in)
  2289. (make-local-variable 'pending-undo-list)
  2290. (undo-start))
  2291. (while (and pending-undo-list
  2292. (listp pending-undo-list)
  2293. (not (car pending-undo-list)))
  2294. (pop pending-undo-list))
  2295. (undo-more 1))))))
  2296. (org-goto-line line)
  2297. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2298. (defun org-verify-change-for-undo (l1 l2)
  2299. "Verify that a real change occurred between the undo lists L1 and L2."
  2300. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2301. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2302. (not (eq l1 l2)))
  2303. ;;; Agenda dispatch
  2304. (defvar org-agenda-restrict-begin (make-marker))
  2305. (defvar org-agenda-restrict-end (make-marker))
  2306. (defvar org-agenda-last-dispatch-buffer nil)
  2307. (defvar org-agenda-overriding-restriction nil)
  2308. (defcustom org-agenda-custom-commands-contexts nil
  2309. "Alist of custom agenda keys and contextual rules.
  2310. For example, if you have a custom agenda command \"p\" and you
  2311. want this command to be accessible only from plain text files,
  2312. use this:
  2313. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2314. Here are the available contexts definitions:
  2315. in-file: command displayed only in matching files
  2316. in-mode: command displayed only in matching modes
  2317. not-in-file: command not displayed in matching files
  2318. not-in-mode: command not displayed in matching modes
  2319. in-buffer: command displayed only in matching buffers
  2320. not-in-buffer: command not displayed in matching buffers
  2321. [function]: a custom function taking no argument
  2322. If you define several checks, the agenda command will be
  2323. accessible if there is at least one valid check.
  2324. You can also bind a key to another agenda custom command
  2325. depending on contextual rules.
  2326. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2327. Here it means: in .txt files, use \"p\" as the key for the
  2328. agenda command otherwise associated with \"q\". (The command
  2329. originally associated with \"q\" is not displayed to avoid
  2330. duplicates.)"
  2331. :version "24.3"
  2332. :group 'org-agenda-custom-commands
  2333. :type '(repeat (list :tag "Rule"
  2334. (string :tag " Agenda key")
  2335. (string :tag "Replace by command")
  2336. (repeat :tag "Available when"
  2337. (choice
  2338. (cons :tag "Condition"
  2339. (choice
  2340. (const :tag "In file" in-file)
  2341. (const :tag "Not in file" not-in-file)
  2342. (const :tag "In buffer" in-buffer)
  2343. (const :tag "Not in buffer" not-in-buffer)
  2344. (const :tag "In mode" in-mode)
  2345. (const :tag "Not in mode" not-in-mode))
  2346. (regexp))
  2347. (function :tag "Custom function"))))))
  2348. (defcustom org-agenda-max-entries nil
  2349. "Maximum number of entries to display in an agenda.
  2350. This can be nil (no limit) or an integer or an alist of agenda
  2351. types with an associated number of entries to display in this
  2352. type."
  2353. :version "24.4"
  2354. :package-version '(Org . "8.0")
  2355. :group 'org-agenda-custom-commands
  2356. :type '(choice (symbol :tag "No limit" nil)
  2357. (integer :tag "Max number of entries")
  2358. (repeat
  2359. (cons (choice :tag "Agenda type"
  2360. (const agenda)
  2361. (const todo)
  2362. (const tags)
  2363. (const search))
  2364. (integer :tag "Max number of entries")))))
  2365. (defcustom org-agenda-max-todos nil
  2366. "Maximum number of TODOs to display in an agenda.
  2367. This can be nil (no limit) or an integer or an alist of agenda
  2368. types with an associated number of entries to display in this
  2369. type."
  2370. :version "24.4"
  2371. :package-version '(Org . "8.0")
  2372. :group 'org-agenda-custom-commands
  2373. :type '(choice (symbol :tag "No limit" nil)
  2374. (integer :tag "Max number of TODOs")
  2375. (repeat
  2376. (cons (choice :tag "Agenda type"
  2377. (const agenda)
  2378. (const todo)
  2379. (const tags)
  2380. (const search))
  2381. (integer :tag "Max number of TODOs")))))
  2382. (defcustom org-agenda-max-tags nil
  2383. "Maximum number of tagged entries to display in an agenda.
  2384. This can be nil (no limit) or an integer or an alist of agenda
  2385. types with an associated number of entries to display in this
  2386. type."
  2387. :version "24.4"
  2388. :package-version '(Org . "8.0")
  2389. :group 'org-agenda-custom-commands
  2390. :type '(choice (symbol :tag "No limit" nil)
  2391. (integer :tag "Max number of tagged entries")
  2392. (repeat
  2393. (cons (choice :tag "Agenda type"
  2394. (const agenda)
  2395. (const todo)
  2396. (const tags)
  2397. (const search))
  2398. (integer :tag "Max number of tagged entries")))))
  2399. (defcustom org-agenda-max-effort nil
  2400. "Maximum cumulated effort duration for the agenda.
  2401. This can be nil (no limit) or a number of minutes (as an integer)
  2402. or an alist of agenda types with an associated number of minutes
  2403. to limit entries to in this type."
  2404. :version "24.4"
  2405. :package-version '(Org . "8.0")
  2406. :group 'org-agenda-custom-commands
  2407. :type '(choice (symbol :tag "No limit" nil)
  2408. (integer :tag "Max number of minutes")
  2409. (repeat
  2410. (cons (choice :tag "Agenda type"
  2411. (const agenda)
  2412. (const todo)
  2413. (const tags)
  2414. (const search))
  2415. (integer :tag "Max number of minutes")))))
  2416. (defvar org-agenda-keep-restricted-file-list nil)
  2417. (defvar org-keys nil)
  2418. (defvar org-match nil)
  2419. ;;;###autoload
  2420. (defun org-agenda (&optional arg org-keys restriction)
  2421. "Dispatch agenda commands to collect entries to the agenda buffer.
  2422. Prompts for a command to execute. Any prefix arg will be passed
  2423. on to the selected command. The default selections are:
  2424. a Call `org-agenda-list' to display the agenda for current day or week.
  2425. t Call `org-todo-list' to display the global todo list.
  2426. T Call `org-todo-list' to display the global todo list, select only
  2427. entries with a specific TODO keyword (the user gets a prompt).
  2428. m Call `org-tags-view' to display headlines with tags matching
  2429. a condition (the user is prompted for the condition).
  2430. M Like `m', but select only TODO entries, no ordinary headlines.
  2431. e Export views to associated files.
  2432. s Search entries for keywords.
  2433. S Search entries for keywords, only with TODO keywords.
  2434. / Multi occur across all agenda files and also files listed
  2435. in `org-agenda-text-search-extra-files'.
  2436. < Restrict agenda commands to buffer, subtree, or region.
  2437. Press several times to get the desired effect.
  2438. > Remove a previous restriction.
  2439. # List \"stuck\" projects.
  2440. ! Configure what \"stuck\" means.
  2441. C Configure custom agenda commands.
  2442. More commands can be added by configuring the variable
  2443. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2444. searches can be pre-defined in this way.
  2445. If the current buffer is in Org mode and visiting a file, you can also
  2446. first press `<' once to indicate that the agenda should be temporarily
  2447. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2448. Pressing `<' twice means to restrict to the current subtree or region
  2449. \(if active)."
  2450. (interactive "P")
  2451. (catch 'exit
  2452. (let* ((prefix-descriptions nil)
  2453. (org-agenda-buffer-name org-agenda-buffer-name)
  2454. (org-agenda-window-setup (if (equal (buffer-name)
  2455. org-agenda-buffer-name)
  2456. 'current-window
  2457. org-agenda-window-setup))
  2458. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2459. (org-agenda-custom-commands
  2460. ;; normalize different versions
  2461. (delq nil
  2462. (mapcar
  2463. (lambda (x)
  2464. (cond ((stringp (cdr x))
  2465. (push x prefix-descriptions)
  2466. nil)
  2467. ((stringp (nth 1 x)) x)
  2468. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2469. (t (cons (car x) (cons "" (cdr x))))))
  2470. org-agenda-custom-commands)))
  2471. (org-agenda-custom-commands
  2472. (org-contextualize-keys
  2473. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2474. (buf (current-buffer))
  2475. (bfn (buffer-file-name (buffer-base-buffer)))
  2476. entry key type org-match lprops ans)
  2477. ;; Turn off restriction unless there is an overriding one,
  2478. (unless org-agenda-overriding-restriction
  2479. (unless org-agenda-keep-restricted-file-list
  2480. ;; There is a request to keep the file list in place
  2481. (put 'org-agenda-files 'org-restrict nil))
  2482. (setq org-agenda-restrict nil)
  2483. (move-marker org-agenda-restrict-begin nil)
  2484. (move-marker org-agenda-restrict-end nil))
  2485. ;; Delete old local properties
  2486. (put 'org-agenda-redo-command 'org-lprops nil)
  2487. ;; Delete previously set last-arguments
  2488. (put 'org-agenda-redo-command 'last-args nil)
  2489. ;; Remember where this call originated
  2490. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2491. (unless org-keys
  2492. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2493. org-keys (car ans)
  2494. restriction (cdr ans)))
  2495. ;; If we have sticky agenda buffers, set a name for the buffer,
  2496. ;; depending on the invoking keys. The user may still set this
  2497. ;; as a command option, which will overwrite what we do here.
  2498. (if org-agenda-sticky
  2499. (setq org-agenda-buffer-name
  2500. (format "*Org Agenda(%s)*" org-keys)))
  2501. ;; Establish the restriction, if any
  2502. (when (and (not org-agenda-overriding-restriction) restriction)
  2503. (put 'org-agenda-files 'org-restrict (list bfn))
  2504. (cond
  2505. ((eq restriction 'region)
  2506. (setq org-agenda-restrict (current-buffer))
  2507. (move-marker org-agenda-restrict-begin (region-beginning))
  2508. (move-marker org-agenda-restrict-end (region-end)))
  2509. ((eq restriction 'subtree)
  2510. (save-excursion
  2511. (setq org-agenda-restrict (current-buffer))
  2512. (org-back-to-heading t)
  2513. (move-marker org-agenda-restrict-begin (point))
  2514. (move-marker org-agenda-restrict-end
  2515. (progn (org-end-of-subtree t)))))))
  2516. ;; For example the todo list should not need it (but does...)
  2517. (cond
  2518. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2519. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2520. (progn
  2521. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2522. lprops (nth 4 entry))
  2523. (if org-agenda-sticky
  2524. (setq org-agenda-buffer-name
  2525. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2526. (format "*Org Agenda(%s)*" org-keys))))
  2527. (put 'org-agenda-redo-command 'org-lprops lprops)
  2528. (cond
  2529. ((eq type 'agenda)
  2530. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2531. ((eq type 'agenda*)
  2532. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2533. ((eq type 'alltodo)
  2534. (org-let lprops '(org-todo-list current-prefix-arg)))
  2535. ((eq type 'search)
  2536. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2537. ((eq type 'stuck)
  2538. (org-let lprops '(org-agenda-list-stuck-projects
  2539. current-prefix-arg)))
  2540. ((eq type 'tags)
  2541. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2542. ((eq type 'tags-todo)
  2543. (org-let lprops '(org-tags-view '(4) org-match)))
  2544. ((eq type 'todo)
  2545. (org-let lprops '(org-todo-list org-match)))
  2546. ((eq type 'tags-tree)
  2547. (org-check-for-org-mode)
  2548. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2549. ((eq type 'todo-tree)
  2550. (org-check-for-org-mode)
  2551. (org-let lprops
  2552. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2553. (regexp-quote org-match) "\\>"))))
  2554. ((eq type 'occur-tree)
  2555. (org-check-for-org-mode)
  2556. (org-let lprops '(org-occur org-match)))
  2557. ((functionp type)
  2558. (org-let lprops '(funcall type org-match)))
  2559. ((fboundp type)
  2560. (org-let lprops '(funcall type org-match)))
  2561. (t (user-error "Invalid custom agenda command type %s" type))))
  2562. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2563. ((equal org-keys "C")
  2564. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2565. (customize-variable 'org-agenda-custom-commands))
  2566. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2567. ((equal org-keys "s") (call-interactively 'org-search-view))
  2568. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2569. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2570. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2571. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2572. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2573. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2574. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2575. (add-hook
  2576. 'post-command-hook
  2577. (lambda ()
  2578. (unless (current-message)
  2579. (let* ((m (org-agenda-get-any-marker))
  2580. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2581. (when note
  2582. (message (concat
  2583. "FLAGGING-NOTE ([?] for more info): "
  2584. (org-add-props
  2585. (replace-regexp-in-string
  2586. "\\\\n" "//"
  2587. (copy-sequence note))
  2588. nil 'face 'org-warning)))))))
  2589. t t))
  2590. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2591. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2592. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2593. (t (user-error "Invalid agenda key"))))))
  2594. (defvar org-agenda-multi)
  2595. (defun org-agenda-append-agenda ()
  2596. "Append another agenda view to the current one.
  2597. This function allows interactive building of block agendas.
  2598. Agenda views are separated by `org-agenda-block-separator'."
  2599. (interactive)
  2600. (unless (derived-mode-p 'org-agenda-mode)
  2601. (user-error "Can only append from within agenda buffer"))
  2602. (let ((org-agenda-multi t))
  2603. (org-agenda)
  2604. (widen)
  2605. (org-agenda-finalize)
  2606. (setq buffer-read-only t)
  2607. (org-agenda-fit-window-to-buffer)))
  2608. (defun org-agenda-normalize-custom-commands (cmds)
  2609. "Normalize custom commands CMDS."
  2610. (delq nil
  2611. (mapcar
  2612. (lambda (x)
  2613. (cond ((stringp (cdr x)) nil)
  2614. ((stringp (nth 1 x)) x)
  2615. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2616. (t (cons (car x) (cons "" (cdr x))))))
  2617. cmds)))
  2618. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2619. "The user interface for selecting an agenda command."
  2620. (catch 'exit
  2621. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2622. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2623. (region-p (org-region-active-p))
  2624. (custom org-agenda-custom-commands)
  2625. (selstring "")
  2626. restriction second-time
  2627. c entry key type match prefixes rmheader header-end custom1 desc
  2628. line lines left right n n1)
  2629. (save-window-excursion
  2630. (delete-other-windows)
  2631. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2632. (erase-buffer)
  2633. (insert (eval-when-compile
  2634. (let ((header
  2635. "Press key for an agenda command:
  2636. -------------------------------- < Buffer, subtree/region restriction
  2637. a Agenda for current week or day > Remove restriction
  2638. t List of all TODO entries e Export agenda views
  2639. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2640. s Search for keywords M Like m, but only TODO entries
  2641. / Multi-occur S Like s, but only TODO entries
  2642. ? Find :FLAGGED: entries C Configure custom agenda commands
  2643. * Toggle sticky agenda views # List stuck projects (!=configure)
  2644. ")
  2645. (start 0))
  2646. (while (string-match
  2647. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2648. header start)
  2649. (setq start (match-end 0))
  2650. (add-text-properties (match-beginning 2) (match-end 2)
  2651. '(face bold) header))
  2652. header)))
  2653. (setq header-end (point-marker))
  2654. (while t
  2655. (setq custom1 custom)
  2656. (when (eq rmheader t)
  2657. (org-goto-line 1)
  2658. (re-search-forward ":" nil t)
  2659. (delete-region (match-end 0) (point-at-eol))
  2660. (forward-char 1)
  2661. (looking-at "-+")
  2662. (delete-region (match-end 0) (point-at-eol))
  2663. (move-marker header-end (match-end 0)))
  2664. (goto-char header-end)
  2665. (delete-region (point) (point-max))
  2666. ;; Produce all the lines that describe custom commands and prefixes
  2667. (setq lines nil)
  2668. (while (setq entry (pop custom1))
  2669. (setq key (car entry) desc (nth 1 entry)
  2670. type (nth 2 entry)
  2671. match (nth 3 entry))
  2672. (if (> (length key) 1)
  2673. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2674. (setq line
  2675. (format
  2676. "%-4s%-14s"
  2677. (org-add-props (copy-sequence key)
  2678. '(face bold))
  2679. (cond
  2680. ((string-match "\\S-" desc) desc)
  2681. ((eq type 'agenda) "Agenda for current week or day")
  2682. ((eq type 'agenda*) "Appointments for current week or day")
  2683. ((eq type 'alltodo) "List of all TODO entries")
  2684. ((eq type 'search) "Word search")
  2685. ((eq type 'stuck) "List of stuck projects")
  2686. ((eq type 'todo) "TODO keyword")
  2687. ((eq type 'tags) "Tags query")
  2688. ((eq type 'tags-todo) "Tags (TODO)")
  2689. ((eq type 'tags-tree) "Tags tree")
  2690. ((eq type 'todo-tree) "TODO kwd tree")
  2691. ((eq type 'occur-tree) "Occur tree")
  2692. ((functionp type) (if (symbolp type)
  2693. (symbol-name type)
  2694. "Lambda expression"))
  2695. (t "???"))))
  2696. (if org-agenda-menu-show-matcher
  2697. (setq line
  2698. (concat line ": "
  2699. (cond
  2700. ((stringp match)
  2701. (setq match (copy-sequence match))
  2702. (org-add-props match nil 'face 'org-warning))
  2703. ((listp type)
  2704. (format "set of %d commands" (length type))))))
  2705. (if (org-string-nw-p match)
  2706. (add-text-properties
  2707. 0 (length line) (list 'help-echo
  2708. (concat "Matcher: " match)) line)))
  2709. (push line lines)))
  2710. (setq lines (nreverse lines))
  2711. (when prefixes
  2712. (mapc (lambda (x)
  2713. (push
  2714. (format "%s %s"
  2715. (org-add-props (char-to-string x)
  2716. nil 'face 'bold)
  2717. (or (cdr (assoc (concat selstring
  2718. (char-to-string x))
  2719. prefix-descriptions))
  2720. "Prefix key"))
  2721. lines))
  2722. prefixes))
  2723. ;; Check if we should display in two columns
  2724. (if org-agenda-menu-two-columns
  2725. (progn
  2726. (setq n (length lines)
  2727. n1 (+ (/ n 2) (mod n 2))
  2728. right (nthcdr n1 lines)
  2729. left (copy-sequence lines))
  2730. (setcdr (nthcdr (1- n1) left) nil))
  2731. (setq left lines right nil))
  2732. (while left
  2733. (insert "\n" (pop left))
  2734. (when right
  2735. (if (< (current-column) 40)
  2736. (move-to-column 40 t)
  2737. (insert " "))
  2738. (insert (pop right))))
  2739. ;; Make the window the right size
  2740. (goto-char (point-min))
  2741. (if second-time
  2742. (if (not (pos-visible-in-window-p (point-max)))
  2743. (org-fit-window-to-buffer))
  2744. (setq second-time t)
  2745. (org-fit-window-to-buffer))
  2746. ;; Ask for selection
  2747. (message "Press key for agenda command%s:"
  2748. (if (or restrict-ok org-agenda-overriding-restriction)
  2749. (if org-agenda-overriding-restriction
  2750. " (restriction lock active)"
  2751. (if restriction
  2752. (format " (restricted to %s)" restriction)
  2753. " (unrestricted)"))
  2754. ""))
  2755. (setq c (read-char-exclusive))
  2756. (message "")
  2757. (cond
  2758. ((assoc (char-to-string c) custom)
  2759. (setq selstring (concat selstring (char-to-string c)))
  2760. (throw 'exit (cons selstring restriction)))
  2761. ((memq c prefixes)
  2762. (setq selstring (concat selstring (char-to-string c))
  2763. prefixes nil
  2764. rmheader (or rmheader t)
  2765. custom (delq nil (mapcar
  2766. (lambda (x)
  2767. (if (or (= (length (car x)) 1)
  2768. (/= (string-to-char (car x)) c))
  2769. nil
  2770. (cons (substring (car x) 1) (cdr x))))
  2771. custom))))
  2772. ((eq c ?*)
  2773. (call-interactively 'org-toggle-sticky-agenda)
  2774. (sit-for 2))
  2775. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2776. (message "Restriction is only possible in Org buffers")
  2777. (ding) (sit-for 1))
  2778. ((eq c ?1)
  2779. (org-agenda-remove-restriction-lock 'noupdate)
  2780. (setq restriction 'buffer))
  2781. ((eq c ?0)
  2782. (org-agenda-remove-restriction-lock 'noupdate)
  2783. (setq restriction (if region-p 'region 'subtree)))
  2784. ((eq c ?<)
  2785. (org-agenda-remove-restriction-lock 'noupdate)
  2786. (setq restriction
  2787. (cond
  2788. ((eq restriction 'buffer)
  2789. (if region-p 'region 'subtree))
  2790. ((memq restriction '(subtree region))
  2791. nil)
  2792. (t 'buffer))))
  2793. ((eq c ?>)
  2794. (org-agenda-remove-restriction-lock 'noupdate)
  2795. (setq restriction nil))
  2796. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2797. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2798. ((and (> (length selstring) 0) (eq c ?\d))
  2799. (delete-window)
  2800. (org-agenda-get-restriction-and-command prefix-descriptions))
  2801. ((equal c ?q) (error "Abort"))
  2802. (t (user-error "Invalid key %c" c))))))))
  2803. (defun org-agenda-fit-window-to-buffer ()
  2804. "Fit the window to the buffer size."
  2805. (and (memq org-agenda-window-setup '(reorganize-frame))
  2806. (fboundp 'fit-window-to-buffer)
  2807. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2808. (= (car org-agenda-window-frame-fractions) 1.0))
  2809. (delete-other-windows)
  2810. (org-fit-window-to-buffer
  2811. nil
  2812. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2813. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2814. (defvar org-cmd nil)
  2815. (defvar org-agenda-overriding-cmd nil)
  2816. (defvar org-agenda-overriding-arguments nil)
  2817. (defvar org-agenda-overriding-cmd-arguments nil)
  2818. (defun org-agenda-run-series (name series)
  2819. "Run agenda NAME as a SERIES of agenda commands."
  2820. (org-let (nth 1 series) '(org-agenda-prepare name))
  2821. ;; We need to reset agenda markers here, because when constructing a
  2822. ;; block agenda, the individual blocks do not do that.
  2823. (org-agenda-reset-markers)
  2824. (let* ((org-agenda-multi t)
  2825. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2826. (cmds (car series))
  2827. (gprops (nth 1 series))
  2828. match ;; The byte compiler incorrectly complains about this. Keep it!
  2829. org-cmd type lprops)
  2830. (while (setq org-cmd (pop cmds))
  2831. (setq type (car org-cmd))
  2832. (setq match (eval (nth 1 org-cmd)))
  2833. (setq lprops (nth 2 org-cmd))
  2834. (let ((org-agenda-overriding-arguments
  2835. (if (eq org-agenda-overriding-cmd org-cmd)
  2836. (or org-agenda-overriding-arguments
  2837. org-agenda-overriding-cmd-arguments))))
  2838. (cond
  2839. ((eq type 'agenda)
  2840. (org-let2 gprops lprops
  2841. '(call-interactively 'org-agenda-list)))
  2842. ((eq type 'agenda*)
  2843. (org-let2 gprops lprops
  2844. '(funcall 'org-agenda-list nil nil t)))
  2845. ((eq type 'alltodo)
  2846. (org-let2 gprops lprops
  2847. '(call-interactively 'org-todo-list)))
  2848. ((eq type 'search)
  2849. (org-let2 gprops lprops
  2850. '(org-search-view current-prefix-arg match nil)))
  2851. ((eq type 'stuck)
  2852. (org-let2 gprops lprops
  2853. '(call-interactively 'org-agenda-list-stuck-projects)))
  2854. ((eq type 'tags)
  2855. (org-let2 gprops lprops
  2856. '(org-tags-view current-prefix-arg match)))
  2857. ((eq type 'tags-todo)
  2858. (org-let2 gprops lprops
  2859. '(org-tags-view '(4) match)))
  2860. ((eq type 'todo)
  2861. (org-let2 gprops lprops
  2862. '(org-todo-list match)))
  2863. ((fboundp type)
  2864. (org-let2 gprops lprops
  2865. '(funcall type match)))
  2866. (t (error "Invalid type in command series")))))
  2867. (widen)
  2868. (let ((inhibit-read-only t))
  2869. (add-text-properties (point-min) (point-max)
  2870. `(org-series t org-series-redo-cmd ,redo)))
  2871. (setq org-agenda-redo-command redo)
  2872. (goto-char (point-min)))
  2873. (org-agenda-fit-window-to-buffer)
  2874. (org-let (nth 1 series) '(org-agenda-finalize)))
  2875. ;;;###autoload
  2876. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2877. "Run an agenda command in batch mode and send the result to STDOUT.
  2878. If CMD-KEY is a string of length 1, it is used as a key in
  2879. `org-agenda-custom-commands' and triggers this command. If it is a
  2880. longer string it is used as a tags/todo match string.
  2881. Parameters are alternating variable names and values that will be bound
  2882. before running the agenda command."
  2883. (org-eval-in-environment (org-make-parameter-alist parameters)
  2884. (let (org-agenda-sticky)
  2885. (if (> (length cmd-key) 1)
  2886. (org-tags-view nil cmd-key)
  2887. (org-agenda nil cmd-key))))
  2888. (set-buffer org-agenda-buffer-name)
  2889. (princ (buffer-string)))
  2890. (defvar org-agenda-info nil)
  2891. ;;;###autoload
  2892. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2893. "Run an agenda command in batch mode and send the result to STDOUT.
  2894. If CMD-KEY is a string of length 1, it is used as a key in
  2895. `org-agenda-custom-commands' and triggers this command. If it is a
  2896. longer string it is used as a tags/todo match string.
  2897. Parameters are alternating variable names and values that will be bound
  2898. before running the agenda command.
  2899. The output gives a line for each selected agenda item. Each
  2900. item is a list of comma-separated values, like this:
  2901. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2902. category The category of the item
  2903. head The headline, without TODO kwd, TAGS and PRIORITY
  2904. type The type of the agenda entry, can be
  2905. todo selected in TODO match
  2906. tagsmatch selected in tags match
  2907. diary imported from diary
  2908. deadline a deadline on given date
  2909. scheduled scheduled on given date
  2910. timestamp entry has timestamp on given date
  2911. closed entry was closed on given date
  2912. upcoming-deadline warning about deadline
  2913. past-scheduled forwarded scheduled item
  2914. block entry has date block including g. date
  2915. todo The todo keyword, if any
  2916. tags All tags including inherited ones, separated by colons
  2917. date The relevant date, like 2007-2-14
  2918. time The time, like 15:00-16:50
  2919. extra Sting with extra planning info
  2920. priority-l The priority letter if any was given
  2921. priority-n The computed numerical priority
  2922. agenda-day The day in the agenda where this is listed"
  2923. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2924. (org-make-parameter-alist parameters))
  2925. (if (> (length cmd-key) 2)
  2926. (org-tags-view nil cmd-key)
  2927. (org-agenda nil cmd-key)))
  2928. (set-buffer org-agenda-buffer-name)
  2929. (let* ((lines (org-split-string (buffer-string) "\n"))
  2930. line)
  2931. (while (setq line (pop lines))
  2932. (catch 'next
  2933. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2934. (setq org-agenda-info
  2935. (org-fix-agenda-info (text-properties-at 0 line)))
  2936. (princ
  2937. (mapconcat 'org-agenda-export-csv-mapper
  2938. '(org-category txt type todo tags date time extra
  2939. priority-letter priority agenda-day)
  2940. ","))
  2941. (princ "\n")))))
  2942. (defun org-fix-agenda-info (props)
  2943. "Make sure all properties on an agenda item have a canonical form.
  2944. This ensures the export commands can easily use it."
  2945. (let (tmp re)
  2946. (when (setq tmp (plist-get props 'tags))
  2947. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2948. (when (setq tmp (plist-get props 'date))
  2949. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2950. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2951. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2952. (setq tmp (calendar-date-string tmp)))
  2953. (setq props (plist-put props 'date tmp)))
  2954. (when (setq tmp (plist-get props 'day))
  2955. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2956. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2957. (setq tmp (calendar-date-string tmp)))
  2958. (setq props (plist-put props 'day tmp))
  2959. (setq props (plist-put props 'agenda-day tmp)))
  2960. (when (setq tmp (plist-get props 'txt))
  2961. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2962. (plist-put props 'priority-letter (match-string 1 tmp))
  2963. (setq tmp (replace-match "" t t tmp)))
  2964. (when (and (setq re (plist-get props 'org-todo-regexp))
  2965. (setq re (concat "\\`\\.*" re " ?"))
  2966. (let ((case-fold-search nil)) (string-match re tmp)))
  2967. (plist-put props 'todo (match-string 1 tmp))
  2968. (setq tmp (replace-match "" t t tmp)))
  2969. (plist-put props 'txt tmp)))
  2970. props)
  2971. (defun org-agenda-export-csv-mapper (prop)
  2972. (let ((res (plist-get org-agenda-info prop)))
  2973. (setq res
  2974. (cond
  2975. ((not res) "")
  2976. ((stringp res) res)
  2977. (t (prin1-to-string res))))
  2978. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  2979. ;;;###autoload
  2980. (defun org-store-agenda-views (&rest parameters)
  2981. "Store agenda views."
  2982. (interactive)
  2983. (eval (list 'org-batch-store-agenda-views)))
  2984. ;;;###autoload
  2985. (defmacro org-batch-store-agenda-views (&rest parameters)
  2986. "Run all custom agenda commands that have a file argument."
  2987. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2988. (pop-up-frames nil)
  2989. (dir default-directory)
  2990. (pars (org-make-parameter-alist parameters))
  2991. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2992. (save-window-excursion
  2993. (while cmds
  2994. (setq cmd (pop cmds)
  2995. thiscmdkey (car cmd)
  2996. thiscmdcmd (cdr cmd)
  2997. match (nth 2 thiscmdcmd)
  2998. bufname (if org-agenda-sticky
  2999. (or (and (stringp match)
  3000. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3001. (format "*Org Agenda(%s)*" thiscmdkey))
  3002. org-agenda-buffer-name)
  3003. cmd-or-set (nth 2 cmd)
  3004. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3005. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3006. (if (stringp files) (setq files (list files)))
  3007. (when files
  3008. (org-eval-in-environment (append org-agenda-exporter-settings
  3009. opts pars)
  3010. (org-agenda nil thiscmdkey))
  3011. (set-buffer bufname)
  3012. (while files
  3013. (org-eval-in-environment (append org-agenda-exporter-settings
  3014. opts pars)
  3015. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  3016. (and (get-buffer bufname)
  3017. (kill-buffer bufname)))))))
  3018. (defvar org-agenda-current-span nil
  3019. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3020. (defun org-agenda-mark-header-line (pos)
  3021. "Mark the line at POS as an agenda structure header."
  3022. (save-excursion
  3023. (goto-char pos)
  3024. (put-text-property (point-at-bol) (point-at-eol)
  3025. 'org-agenda-structural-header t)
  3026. (when org-agenda-title-append
  3027. (put-text-property (point-at-bol) (point-at-eol)
  3028. 'org-agenda-title-append org-agenda-title-append))))
  3029. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3030. (defvar org-agenda-write-buffer-name "Agenda View")
  3031. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3032. "Write the current buffer (an agenda view) as a file.
  3033. Depending on the extension of the file name, plain text (.txt),
  3034. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3035. If the extension is .ics, translate visible agenda into iCalendar
  3036. format. If the extension is .org, collect all subtrees
  3037. corresponding to the agenda entries and add them in an .org file.
  3038. With prefix argument OPEN, open the new file immediately. If
  3039. NOSETTINGS is given, do not scope the settings of
  3040. `org-agenda-exporter-settings' into the export commands. This is
  3041. used when the settings have already been scoped and we do not
  3042. wish to overrule other, higher priority settings. If
  3043. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3044. the agenda to write."
  3045. (interactive "FWrite agenda to file: \nP")
  3046. (if (or (not (file-writable-p file))
  3047. (and (file-exists-p file)
  3048. (if (called-interactively-p 'any)
  3049. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3050. (user-error "Cannot write agenda to file %s" file))
  3051. (org-let (if nosettings nil org-agenda-exporter-settings)
  3052. '(save-excursion
  3053. (save-window-excursion
  3054. (let ((bs (copy-sequence (buffer-string)))
  3055. (extension (file-name-extension file))
  3056. (default-directory (file-name-directory file))
  3057. beg content)
  3058. (with-temp-buffer
  3059. (rename-buffer org-agenda-write-buffer-name t)
  3060. (set-buffer-modified-p nil)
  3061. (insert bs)
  3062. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3063. (run-hooks 'org-agenda-before-write-hook)
  3064. (cond
  3065. ((bound-and-true-p org-mobile-creating-agendas)
  3066. (org-mobile-write-agenda-for-mobile file))
  3067. ((string= "org" extension)
  3068. (let (content p m message-log-max)
  3069. (goto-char (point-min))
  3070. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3071. (goto-char p)
  3072. (setq m (get-text-property (point) 'org-hd-marker))
  3073. (when m
  3074. (push (save-excursion
  3075. (set-buffer (marker-buffer m))
  3076. (goto-char m)
  3077. (org-copy-subtree 1 nil t t)
  3078. org-subtree-clip)
  3079. content)))
  3080. (find-file file)
  3081. (erase-buffer)
  3082. (dolist (s content) (org-paste-subtree 1 s))
  3083. (write-file file)
  3084. (kill-buffer (current-buffer))
  3085. (message "Org file written to %s" file)))
  3086. ((member extension '("html" "htm"))
  3087. (or (require 'htmlize nil t)
  3088. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3089. (set-buffer (htmlize-buffer (current-buffer)))
  3090. (when org-agenda-export-html-style
  3091. ;; replace <style> section with org-agenda-export-html-style
  3092. (goto-char (point-min))
  3093. (kill-region (- (search-forward "<style") 6)
  3094. (search-forward "</style>"))
  3095. (insert org-agenda-export-html-style))
  3096. (write-file file)
  3097. (kill-buffer (current-buffer))
  3098. (message "HTML written to %s" file))
  3099. ((string= "ps" extension)
  3100. (require 'ps-print)
  3101. (ps-print-buffer-with-faces file)
  3102. (message "Postscript written to %s" file))
  3103. ((string= "pdf" extension)
  3104. (require 'ps-print)
  3105. (ps-print-buffer-with-faces
  3106. (concat (file-name-sans-extension file) ".ps"))
  3107. (call-process "ps2pdf" nil nil nil
  3108. (expand-file-name
  3109. (concat (file-name-sans-extension file) ".ps"))
  3110. (expand-file-name file))
  3111. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3112. (message "PDF written to %s" file))
  3113. ((string= "ics" extension)
  3114. (require 'ox-icalendar)
  3115. (org-icalendar-export-current-agenda (expand-file-name file)))
  3116. (t
  3117. (let ((bs (buffer-string)))
  3118. (find-file file)
  3119. (erase-buffer)
  3120. (insert bs)
  3121. (save-buffer 0)
  3122. (kill-buffer (current-buffer))
  3123. (message "Plain text written to %s" file))))))))
  3124. (set-buffer (or agenda-bufname
  3125. (and (called-interactively-p 'any) (buffer-name))
  3126. org-agenda-buffer-name)))
  3127. (when open (org-open-file file)))
  3128. (defun org-agenda-remove-marked-text (property &optional value)
  3129. "Delete all text marked with VALUE of PROPERTY.
  3130. VALUE defaults to t."
  3131. (let (beg)
  3132. (setq value (or value t))
  3133. (while (setq beg (text-property-any (point-min) (point-max)
  3134. property value))
  3135. (delete-region
  3136. beg (or (next-single-property-change beg property)
  3137. (point-max))))))
  3138. (defun org-agenda-add-entry-text ()
  3139. "Add entry text to agenda lines.
  3140. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3141. entry text following headings shown in the agenda.
  3142. Drawers will be excluded, also the line with scheduling/deadline info."
  3143. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3144. (not (bound-and-true-p org-mobile-creating-agendas)))
  3145. (let (m txt)
  3146. (goto-char (point-min))
  3147. (while (not (eobp))
  3148. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3149. (beginning-of-line 2)
  3150. (setq txt (org-agenda-get-some-entry-text
  3151. m org-agenda-add-entry-text-maxlines " > "))
  3152. (end-of-line 1)
  3153. (if (string-match "\\S-" txt)
  3154. (insert "\n" txt)
  3155. (or (eobp) (forward-char 1))))))))
  3156. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3157. &rest keep)
  3158. "Extract entry text from MARKER, at most N-LINES lines.
  3159. This will ignore drawers etc, just get the text.
  3160. If INDENT is given, prefix every line with this string. If KEEP is
  3161. given, it is a list of symbols, defining stuff that should not be
  3162. removed from the entry content. Currently only `planning' is allowed here."
  3163. (let (txt drawer-re kwd-time-re ind)
  3164. (save-excursion
  3165. (with-current-buffer (marker-buffer marker)
  3166. (if (not (derived-mode-p 'org-mode))
  3167. (setq txt "")
  3168. (org-with-wide-buffer
  3169. (goto-char marker)
  3170. (end-of-line 1)
  3171. (setq txt (buffer-substring
  3172. (min (1+ (point)) (point-max))
  3173. (progn (outline-next-heading) (point)))
  3174. drawer-re org-drawer-regexp
  3175. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3176. ".*\n?"))
  3177. (with-temp-buffer
  3178. (insert txt)
  3179. (when org-agenda-add-entry-text-descriptive-links
  3180. (goto-char (point-min))
  3181. (while (org-activate-links (point-max))
  3182. (add-text-properties (match-beginning 0) (match-end 0)
  3183. '(face org-link))))
  3184. (goto-char (point-min))
  3185. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3186. (set-text-properties (match-beginning 0) (match-end 0)
  3187. nil))
  3188. (goto-char (point-min))
  3189. (while (re-search-forward drawer-re nil t)
  3190. (delete-region
  3191. (match-beginning 0)
  3192. (progn (re-search-forward
  3193. "^[ \t]*:END:.*\n?" nil 'move)
  3194. (point))))
  3195. (unless (member 'planning keep)
  3196. (goto-char (point-min))
  3197. (while (re-search-forward kwd-time-re nil t)
  3198. (replace-match "")))
  3199. (goto-char (point-min))
  3200. (when org-agenda-entry-text-exclude-regexps
  3201. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3202. (while (setq re (pop re-list))
  3203. (goto-char (point-min))
  3204. (while (re-search-forward re nil t)
  3205. (replace-match "")))))
  3206. (goto-char (point-max))
  3207. (skip-chars-backward " \t\n")
  3208. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3209. ;; find and remove min common indentation
  3210. (goto-char (point-min))
  3211. (untabify (point-min) (point-max))
  3212. (setq ind (org-get-indentation))
  3213. (while (not (eobp))
  3214. (unless (looking-at "[ \t]*$")
  3215. (setq ind (min ind (org-get-indentation))))
  3216. (beginning-of-line 2))
  3217. (goto-char (point-min))
  3218. (while (not (eobp))
  3219. (unless (looking-at "[ \t]*$")
  3220. (move-to-column ind)
  3221. (delete-region (point-at-bol) (point)))
  3222. (beginning-of-line 2))
  3223. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3224. (goto-char (point-min))
  3225. (when indent
  3226. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3227. (replace-match indent t t)))
  3228. (goto-char (point-min))
  3229. (while (looking-at "[ \t]*\n") (replace-match ""))
  3230. (goto-char (point-max))
  3231. (when (> (org-current-line)
  3232. n-lines)
  3233. (org-goto-line (1+ n-lines))
  3234. (backward-char 1))
  3235. (setq txt (buffer-substring (point-min) (point))))))))
  3236. txt))
  3237. (defun org-check-for-org-mode ()
  3238. "Make sure current buffer is in Org mode. Error if not."
  3239. (or (derived-mode-p 'org-mode)
  3240. (error "Cannot execute Org agenda command on buffer in %s"
  3241. major-mode)))
  3242. ;;; Agenda prepare and finalize
  3243. (defvar org-agenda-multi nil) ; dynamically scoped
  3244. (defvar org-agenda-pre-window-conf nil)
  3245. (defvar org-agenda-columns-active nil)
  3246. (defvar org-agenda-name nil)
  3247. (defvar org-agenda-tag-filter nil)
  3248. (defvar org-agenda-category-filter nil)
  3249. (defvar org-agenda-regexp-filter nil)
  3250. (defvar org-agenda-effort-filter nil)
  3251. (defvar org-agenda-top-headline-filter nil)
  3252. (defvar org-agenda-tag-filter-preset nil
  3253. "A preset of the tags filter used for secondary agenda filtering.
  3254. This must be a list of strings, each string must be a single tag preceded
  3255. by \"+\" or \"-\".
  3256. This variable should not be set directly, but agenda custom commands can
  3257. bind it in the options section. The preset filter is a global property of
  3258. the entire agenda view. In a block agenda, it will not work reliably to
  3259. define a filter for one of the individual blocks. You need to set it in
  3260. the global options and expect it to be applied to the entire view.")
  3261. (defvar org-agenda-category-filter-preset nil
  3262. "A preset of the category filter used for secondary agenda filtering.
  3263. This must be a list of strings, each string must be a single category
  3264. preceded by \"+\" or \"-\".
  3265. This variable should not be set directly, but agenda custom commands can
  3266. bind it in the options section. The preset filter is a global property of
  3267. the entire agenda view. In a block agenda, it will not work reliably to
  3268. define a filter for one of the individual blocks. You need to set it in
  3269. the global options and expect it to be applied to the entire view.")
  3270. (defvar org-agenda-regexp-filter-preset nil
  3271. "A preset of the regexp filter used for secondary agenda filtering.
  3272. This must be a list of strings, each string must be a single regexp
  3273. preceded by \"+\" or \"-\".
  3274. This variable should not be set directly, but agenda custom commands can
  3275. bind it in the options section. The preset filter is a global property of
  3276. the entire agenda view. In a block agenda, it will not work reliably to
  3277. define a filter for one of the individual blocks. You need to set it in
  3278. the global options and expect it to be applied to the entire view.")
  3279. (defvar org-agenda-effort-filter-preset nil
  3280. "A preset of the effort condition used for secondary agenda filtering.
  3281. This must be a list of strings, each string must be a single regexp
  3282. preceded by \"+\" or \"-\".
  3283. This variable should not be set directly, but agenda custom commands can
  3284. bind it in the options section. The preset filter is a global property of
  3285. the entire agenda view. In a block agenda, it will not work reliably to
  3286. define a filter for one of the individual blocks. You need to set it in
  3287. the global options and expect it to be applied to the entire view.")
  3288. (defun org-agenda-use-sticky-p ()
  3289. "Return non-nil if an agenda buffer named
  3290. `org-agenda-buffer-name' exists and should be shown instead of
  3291. generating a new one."
  3292. (and
  3293. ;; turned off by user
  3294. org-agenda-sticky
  3295. ;; For multi-agenda buffer already exists
  3296. (not org-agenda-multi)
  3297. ;; buffer found
  3298. (get-buffer org-agenda-buffer-name)
  3299. ;; C-u parameter is same as last call
  3300. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3301. (and
  3302. (equal current-prefix-arg
  3303. org-agenda-last-prefix-arg)
  3304. ;; In case user turned stickiness on, while having existing
  3305. ;; Agenda buffer active, don't reuse that buffer, because it
  3306. ;; does not have org variables local
  3307. org-agenda-this-buffer-is-sticky))))
  3308. (defun org-agenda-prepare-window (abuf filter-alist)
  3309. "Setup agenda buffer in the window.
  3310. ABUF is the buffer for the agenda window.
  3311. FILTER-ALIST is an alist of filters we need to apply when
  3312. `org-agenda-persistent-filter' is non-nil."
  3313. (let* ((awin (get-buffer-window abuf)) wconf)
  3314. (cond
  3315. ((equal (current-buffer) abuf) nil)
  3316. (awin (select-window awin))
  3317. ((not (setq wconf (current-window-configuration))))
  3318. ((eq org-agenda-window-setup 'current-window)
  3319. (pop-to-buffer-same-window abuf))
  3320. ((eq org-agenda-window-setup 'other-window)
  3321. (org-switch-to-buffer-other-window abuf))
  3322. ((eq org-agenda-window-setup 'other-frame)
  3323. (switch-to-buffer-other-frame abuf))
  3324. ((eq org-agenda-window-setup 'only-window)
  3325. (delete-other-windows)
  3326. (pop-to-buffer-same-window abuf))
  3327. ((eq org-agenda-window-setup 'reorganize-frame)
  3328. (delete-other-windows)
  3329. (org-switch-to-buffer-other-window abuf)))
  3330. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3331. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3332. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3333. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3334. ;; Additional test in case agenda is invoked from within agenda
  3335. ;; buffer via elisp link.
  3336. (unless (equal (current-buffer) abuf)
  3337. (pop-to-buffer-same-window abuf))
  3338. (setq org-agenda-pre-window-conf
  3339. (or wconf org-agenda-pre-window-conf))))
  3340. (defun org-agenda-prepare (&optional name)
  3341. (let ((filter-alist (if org-agenda-persistent-filter
  3342. (with-current-buffer
  3343. (get-buffer-create org-agenda-buffer-name)
  3344. (list `(tag . ,org-agenda-tag-filter)
  3345. `(re . ,org-agenda-regexp-filter)
  3346. `(effort . ,org-agenda-effort-filter)
  3347. `(cat . ,org-agenda-category-filter))))))
  3348. (if (org-agenda-use-sticky-p)
  3349. (progn
  3350. (put 'org-agenda-tag-filter :preset-filter nil)
  3351. (put 'org-agenda-category-filter :preset-filter nil)
  3352. (put 'org-agenda-regexp-filter :preset-filter nil)
  3353. ;; Popup existing buffer
  3354. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3355. filter-alist)
  3356. (message "Sticky Agenda buffer, use `r' to refresh")
  3357. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3358. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3359. (setq org-todo-keywords-for-agenda nil)
  3360. (put 'org-agenda-tag-filter :preset-filter
  3361. org-agenda-tag-filter-preset)
  3362. (put 'org-agenda-category-filter :preset-filter
  3363. org-agenda-category-filter-preset)
  3364. (put 'org-agenda-regexp-filter :preset-filter
  3365. org-agenda-regexp-filter-preset)
  3366. (put 'org-agenda-effort-filter :preset-filter
  3367. org-agenda-effort-filter-preset)
  3368. (if org-agenda-multi
  3369. (progn
  3370. (setq buffer-read-only nil)
  3371. (goto-char (point-max))
  3372. (unless (or (bobp) org-agenda-compact-blocks
  3373. (not org-agenda-block-separator))
  3374. (insert "\n"
  3375. (if (stringp org-agenda-block-separator)
  3376. org-agenda-block-separator
  3377. (make-string (window-width) org-agenda-block-separator))
  3378. "\n"))
  3379. (narrow-to-region (point) (point-max)))
  3380. (setq org-done-keywords-for-agenda nil)
  3381. ;; Setting any org variables that are in org-agenda-local-vars
  3382. ;; list need to be done after the prepare call
  3383. (org-agenda-prepare-window
  3384. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3385. (setq buffer-read-only nil)
  3386. (org-agenda-reset-markers)
  3387. (let ((inhibit-read-only t)) (erase-buffer))
  3388. (org-agenda-mode)
  3389. (setq org-agenda-buffer (current-buffer))
  3390. (setq org-agenda-contributing-files nil)
  3391. (setq org-agenda-columns-active nil)
  3392. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3393. (setq org-todo-keywords-for-agenda
  3394. (org-uniquify org-todo-keywords-for-agenda))
  3395. (setq org-done-keywords-for-agenda
  3396. (org-uniquify org-done-keywords-for-agenda))
  3397. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3398. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3399. ;; Don't set these until we know we're in the agenda buffer,
  3400. ;; and we know they're valid.
  3401. (setq org-agenda-lprops (or org-agenda-lprops
  3402. (get 'org-agenda-redo-command 'org-lprops)))
  3403. (and name (not org-agenda-name)
  3404. (setq-local org-agenda-name name)))
  3405. (setq buffer-read-only nil))))
  3406. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3407. (defun org-agenda-finalize ()
  3408. "Finishing touch for the agenda buffer, called just before displaying it."
  3409. (unless org-agenda-multi
  3410. (save-excursion
  3411. (let ((inhibit-read-only t))
  3412. (goto-char (point-min))
  3413. (save-excursion
  3414. (while (org-activate-links (point-max))
  3415. (add-text-properties (match-beginning 0) (match-end 0)
  3416. '(face org-link))))
  3417. (unless (eq org-agenda-remove-tags t)
  3418. (org-agenda-align-tags))
  3419. (unless org-agenda-with-colors
  3420. (remove-text-properties (point-min) (point-max) '(face nil)))
  3421. (if (and (boundp 'org-agenda-overriding-columns-format)
  3422. org-agenda-overriding-columns-format)
  3423. (setq-local org-agenda-overriding-columns-format
  3424. org-agenda-overriding-columns-format))
  3425. (if (and (boundp 'org-agenda-view-columns-initially)
  3426. org-agenda-view-columns-initially)
  3427. (org-agenda-columns))
  3428. (when org-agenda-fontify-priorities
  3429. (org-agenda-fontify-priorities))
  3430. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3431. (org-agenda-dim-blocked-tasks))
  3432. (org-agenda-mark-clocking-task)
  3433. (when org-agenda-entry-text-mode
  3434. (org-agenda-entry-text-hide)
  3435. (org-agenda-entry-text-show))
  3436. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3437. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3438. (org-habit-insert-consistency-graphs))
  3439. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3440. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3441. (and (listp org-agenda-show-inherited-tags)
  3442. (memq org-agenda-type org-agenda-show-inherited-tags))
  3443. (and (eq org-agenda-show-inherited-tags t)
  3444. (or (eq org-agenda-use-tag-inheritance t)
  3445. (and (listp org-agenda-use-tag-inheritance)
  3446. (not (memq org-agenda-type
  3447. org-agenda-use-tag-inheritance))))))
  3448. (let (mrk)
  3449. (save-excursion
  3450. (goto-char (point-min))
  3451. (while (equal (forward-line) 0)
  3452. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3453. (put-text-property (point-at-bol) (point-at-eol)
  3454. 'tags (org-with-point-at mrk
  3455. (delete-dups
  3456. (mapcar 'downcase (org-get-tags-at))))))))))
  3457. (run-hooks 'org-agenda-finalize-hook)
  3458. (when org-agenda-top-headline-filter
  3459. (org-agenda-filter-top-headline-apply
  3460. org-agenda-top-headline-filter))
  3461. (when org-agenda-tag-filter
  3462. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3463. (when (get 'org-agenda-tag-filter :preset-filter)
  3464. (org-agenda-filter-apply
  3465. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3466. (when org-agenda-category-filter
  3467. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3468. (when (get 'org-agenda-category-filter :preset-filter)
  3469. (org-agenda-filter-apply
  3470. (get 'org-agenda-category-filter :preset-filter) 'category))
  3471. (when org-agenda-regexp-filter
  3472. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3473. (when (get 'org-agenda-regexp-filter :preset-filter)
  3474. (org-agenda-filter-apply
  3475. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3476. (when org-agenda-effort-filter
  3477. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3478. (when (get 'org-agenda-effort-filter :preset-filter)
  3479. (org-agenda-filter-apply
  3480. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3481. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3482. (defun org-agenda-mark-clocking-task ()
  3483. "Mark the current clock entry in the agenda if it is present."
  3484. ;; We need to widen when `org-agenda-finalize' is called from
  3485. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3486. (when (bound-and-true-p org-clock-current-task)
  3487. (save-restriction
  3488. (widen)
  3489. (org-agenda-unmark-clocking-task)
  3490. (when (marker-buffer org-clock-hd-marker)
  3491. (save-excursion
  3492. (goto-char (point-min))
  3493. (let (s ov)
  3494. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3495. (goto-char s)
  3496. (when (equal (org-get-at-bol 'org-hd-marker)
  3497. org-clock-hd-marker)
  3498. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3499. (overlay-put ov 'type 'org-agenda-clocking)
  3500. (overlay-put ov 'face 'org-agenda-clocking)
  3501. (overlay-put ov 'help-echo
  3502. "The clock is running in this item")))))))))
  3503. (defun org-agenda-unmark-clocking-task ()
  3504. "Unmark the current clocking task."
  3505. (mapc (lambda (o)
  3506. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3507. (delete-overlay o)))
  3508. (overlays-in (point-min) (point-max))))
  3509. (defun org-agenda-fontify-priorities ()
  3510. "Make highest priority lines bold, and lowest italic."
  3511. (interactive)
  3512. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3513. (delete-overlay o)))
  3514. (overlays-in (point-min) (point-max)))
  3515. (save-excursion
  3516. (let (b e p ov h l)
  3517. (goto-char (point-min))
  3518. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3519. (setq h (or (get-char-property (point) 'org-highest-priority)
  3520. org-highest-priority)
  3521. l (or (get-char-property (point) 'org-lowest-priority)
  3522. org-lowest-priority)
  3523. p (string-to-char (match-string 1))
  3524. b (match-beginning 0)
  3525. e (if (eq org-agenda-fontify-priorities 'cookies)
  3526. (match-end 0)
  3527. (point-at-eol))
  3528. ov (make-overlay b e))
  3529. (overlay-put
  3530. ov 'face
  3531. (let ((special-face
  3532. (cond ((org-face-from-face-or-color
  3533. 'priority 'org-priority
  3534. (cdr (assoc p org-priority-faces))))
  3535. ((and (listp org-agenda-fontify-priorities)
  3536. (org-face-from-face-or-color
  3537. 'priority 'org-priority
  3538. (cdr (assoc p org-agenda-fontify-priorities)))))
  3539. ((equal p l) 'italic)
  3540. ((equal p h) 'bold))))
  3541. (if special-face (list special-face 'org-priority) 'org-priority)))
  3542. (overlay-put ov 'org-type 'org-priority)))))
  3543. (defvar org-depend-tag-blocked)
  3544. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3545. "Dim currently blocked TODOs in the agenda display.
  3546. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3547. dimming them."
  3548. (interactive "P")
  3549. (when (called-interactively-p 'interactive)
  3550. (message "Dim or hide blocked tasks..."))
  3551. (dolist (o (overlays-in (point-min) (point-max)))
  3552. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3553. (delete-overlay o)))
  3554. (save-excursion
  3555. (let ((inhibit-read-only t))
  3556. (goto-char (point-min))
  3557. (while (let ((pos (text-property-not-all
  3558. (point) (point-max) 'org-todo-blocked nil)))
  3559. (when pos (goto-char pos)))
  3560. (let* ((invisible (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3561. (ov (make-overlay (if invisible
  3562. (line-end-position 0)
  3563. (line-beginning-position))
  3564. (line-end-position))))
  3565. (if invisible
  3566. (overlay-put ov 'invisible t)
  3567. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3568. (overlay-put ov 'org-type 'org-blocked-todo))
  3569. (forward-line))))
  3570. (when (called-interactively-p 'interactive)
  3571. (message "Dim or hide blocked tasks...done")))
  3572. (defun org-agenda--mark-blocked-entry (entry)
  3573. "For ENTRY a string with the text property `org-hd-marker', if
  3574. the header at `org-hd-marker' is blocked according to
  3575. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3576. 'invisible and the header is not blocked by checkboxes, set the
  3577. text property `org-todo-blocked' to 'invisible, otherwise set it
  3578. to t."
  3579. (when (get-text-property 0 'todo-state entry)
  3580. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3581. (org-blocked-by-checkboxes nil)
  3582. ;; Necessary so that `org-entry-blocked-p' does not change
  3583. ;; the buffer.
  3584. (org-depend-tag-blocked nil))
  3585. (when entry-marker
  3586. (let ((blocked
  3587. (with-current-buffer (marker-buffer entry-marker)
  3588. (save-excursion
  3589. (goto-char entry-marker)
  3590. (org-entry-blocked-p)))))
  3591. (when blocked
  3592. (let ((really-invisible
  3593. (and (not org-blocked-by-checkboxes)
  3594. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3595. (put-text-property
  3596. 0 (length entry) 'org-todo-blocked
  3597. (if really-invisible 'invisible t)
  3598. entry)))))))
  3599. entry)
  3600. (defvar org-agenda-skip-function nil
  3601. "Function to be called at each match during agenda construction.
  3602. If this function returns nil, the current match should not be skipped.
  3603. Otherwise, the function must return a position from where the search
  3604. should be continued.
  3605. This may also be a Lisp form, it will be evaluated.
  3606. Never set this variable using `setq' or so, because then it will apply
  3607. to all future agenda commands. If you do want a global skipping condition,
  3608. use the option `org-agenda-skip-function-global' instead.
  3609. The correct usage for `org-agenda-skip-function' is to bind it with
  3610. `let' to scope it dynamically into the agenda-constructing command.
  3611. A good way to set it is through options in `org-agenda-custom-commands'.")
  3612. (defun org-agenda-skip ()
  3613. "Throw to `:skip' in places that should be skipped.
  3614. Also moves point to the end of the skipped region, so that search can
  3615. continue from there."
  3616. (let ((p (point-at-bol)) to)
  3617. (when (or
  3618. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3619. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3620. (get-text-property p :org-archived)
  3621. (org-end-of-subtree t))
  3622. (and org-agenda-skip-comment-trees
  3623. (get-text-property p :org-comment)
  3624. (org-end-of-subtree t))
  3625. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3626. (org-agenda-skip-eval org-agenda-skip-function)))
  3627. (goto-char to))
  3628. (org-in-src-block-p t))
  3629. (throw :skip t))))
  3630. (defun org-agenda-skip-eval (form)
  3631. "If FORM is a function or a list, call (or eval) it and return the result.
  3632. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3633. and match data are returned to the previous state no matter what these
  3634. functions do."
  3635. (let (fp)
  3636. (and form
  3637. (or (setq fp (functionp form))
  3638. (consp form))
  3639. (save-excursion
  3640. (save-match-data
  3641. (if fp
  3642. (funcall form)
  3643. (eval form)))))))
  3644. (defvar org-agenda-markers nil
  3645. "List of all currently active markers created by `org-agenda'.")
  3646. (defvar org-agenda-last-marker-time (float-time)
  3647. "Creation time of the last agenda marker.")
  3648. (defun org-agenda-new-marker (&optional pos)
  3649. "Return a new agenda marker.
  3650. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3651. these markers and resets them when they are no longer in use."
  3652. (let ((m (copy-marker (or pos (point)) t)))
  3653. (setq org-agenda-last-marker-time (float-time))
  3654. (if org-agenda-buffer
  3655. (with-current-buffer org-agenda-buffer
  3656. (push m org-agenda-markers))
  3657. (push m org-agenda-markers))
  3658. m))
  3659. (defun org-agenda-reset-markers ()
  3660. "Reset markers created by `org-agenda'."
  3661. (while org-agenda-markers
  3662. (move-marker (pop org-agenda-markers) nil)))
  3663. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3664. "Save relative positions of markers in region.
  3665. This check for agenda markers in all agenda buffers currently active."
  3666. (dolist (buf (buffer-list))
  3667. (with-current-buffer buf
  3668. (when (eq major-mode 'org-agenda-mode)
  3669. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3670. org-agenda-markers)))))
  3671. ;;; Entry text mode
  3672. (defun org-agenda-entry-text-show-here ()
  3673. "Add some text from the entry as context to the current line."
  3674. (let (m txt o)
  3675. (setq m (org-get-at-bol 'org-hd-marker))
  3676. (unless (marker-buffer m)
  3677. (error "No marker points to an entry here"))
  3678. (setq txt (concat "\n" (org-no-properties
  3679. (org-agenda-get-some-entry-text
  3680. m org-agenda-entry-text-maxlines
  3681. org-agenda-entry-text-leaders))))
  3682. (when (string-match "\\S-" txt)
  3683. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3684. (overlay-put o 'evaporate t)
  3685. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3686. (overlay-put o 'after-string txt))))
  3687. (defun org-agenda-entry-text-show ()
  3688. "Add entry context for all agenda lines."
  3689. (interactive)
  3690. (save-excursion
  3691. (goto-char (point-max))
  3692. (beginning-of-line 1)
  3693. (while (not (bobp))
  3694. (when (org-get-at-bol 'org-hd-marker)
  3695. (org-agenda-entry-text-show-here))
  3696. (beginning-of-line 0))))
  3697. (defun org-agenda-entry-text-hide ()
  3698. "Remove any shown entry context."
  3699. (delq nil
  3700. (mapcar (lambda (o)
  3701. (if (eq (overlay-get o 'org-overlay-type)
  3702. 'agenda-entry-content)
  3703. (progn (delete-overlay o) t)))
  3704. (overlays-in (point-min) (point-max)))))
  3705. (defun org-agenda-get-day-face (date)
  3706. "Return the face DATE should be displayed with."
  3707. (cond ((and (functionp org-agenda-day-face-function)
  3708. (funcall org-agenda-day-face-function date)))
  3709. ((org-agenda-today-p date) 'org-agenda-date-today)
  3710. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3711. 'org-agenda-date-weekend)
  3712. (t 'org-agenda-date)))
  3713. (defvar org-agenda-show-log-scoped)
  3714. ;;; Agenda Daily/Weekly
  3715. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3716. "Start day for the agenda view.
  3717. Custom commands can set this variable in the options section.
  3718. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3719. input allowed when reading a date through the Org calendar.
  3720. See the docstring of `org-read-date' for details.")
  3721. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3722. (defvar org-arg-loc nil) ; local variable
  3723. (defvar org-agenda-buffer-tmp-name nil)
  3724. ;;;###autoload
  3725. (defun org-agenda-list (&optional arg start-day span with-hour)
  3726. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3727. The view will be for the current day or week, but from the overview buffer
  3728. you will be able to go to other days/weeks.
  3729. With a numeric prefix argument in an interactive call, the agenda will
  3730. span ARG days. Lisp programs should instead specify SPAN to change
  3731. the number of days. SPAN defaults to `org-agenda-span'.
  3732. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3733. given in `org-agenda-start-on-weekday'.
  3734. When WITH-HOUR is non-nil, only include scheduled and deadline
  3735. items if they have an hour specification like [h]h:mm."
  3736. (interactive "P")
  3737. (if org-agenda-overriding-arguments
  3738. (setq arg (car org-agenda-overriding-arguments)
  3739. start-day (nth 1 org-agenda-overriding-arguments)
  3740. span (nth 2 org-agenda-overriding-arguments)))
  3741. (if (and (integerp arg) (> arg 0))
  3742. (setq span arg arg nil))
  3743. (catch 'exit
  3744. (setq org-agenda-buffer-name
  3745. (or org-agenda-buffer-tmp-name
  3746. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3747. (if org-agenda-sticky
  3748. (cond ((and org-keys (stringp org-match))
  3749. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3750. (org-keys
  3751. (format "*Org Agenda(%s)*" org-keys))
  3752. (t "*Org Agenda(a)*")))
  3753. "*Org Agenda*"))
  3754. (org-agenda-prepare "Day/Week")
  3755. (setq start-day (or start-day org-agenda-start-day))
  3756. (if (stringp start-day)
  3757. ;; Convert to an absolute day number
  3758. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3759. (org-compile-prefix-format 'agenda)
  3760. (org-set-sorting-strategy 'agenda)
  3761. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3762. (today (org-today))
  3763. (sd (or start-day today))
  3764. (ndays (org-agenda-span-to-ndays span sd))
  3765. (org-agenda-start-on-weekday
  3766. (if (or (eq ndays 7) (eq ndays 14))
  3767. org-agenda-start-on-weekday))
  3768. (thefiles (org-agenda-files nil 'ifmode))
  3769. (files thefiles)
  3770. (start (if (or (null org-agenda-start-on-weekday)
  3771. (< ndays 7))
  3772. sd
  3773. (let* ((nt (calendar-day-of-week
  3774. (calendar-gregorian-from-absolute sd)))
  3775. (n1 org-agenda-start-on-weekday)
  3776. (d (- nt n1)))
  3777. (- sd (+ (if (< d 0) 7 0) d)))))
  3778. (day-numbers (list start))
  3779. (day-cnt 0)
  3780. (inhibit-redisplay (not debug-on-error))
  3781. (org-agenda-show-log-scoped org-agenda-show-log)
  3782. s e rtn rtnall file date d start-pos end-pos todayp
  3783. clocktable-start clocktable-end filter)
  3784. (setq org-agenda-redo-command
  3785. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3786. (dotimes (n (1- ndays))
  3787. (push (1+ (car day-numbers)) day-numbers))
  3788. (setq day-numbers (nreverse day-numbers))
  3789. (setq clocktable-start (car day-numbers)
  3790. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3791. (setq-local org-starting-day (car day-numbers))
  3792. (setq-local org-arg-loc arg)
  3793. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3794. (unless org-agenda-compact-blocks
  3795. (let* ((d1 (car day-numbers))
  3796. (d2 (org-last day-numbers))
  3797. (w1 (org-days-to-iso-week d1))
  3798. (w2 (org-days-to-iso-week d2)))
  3799. (setq s (point))
  3800. (if org-agenda-overriding-header
  3801. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3802. nil 'face 'org-agenda-structure) "\n")
  3803. (insert (org-agenda-span-name span)
  3804. "-agenda"
  3805. (if (< (- d2 d1) 350)
  3806. (if (= w1 w2)
  3807. (format " (W%02d)" w1)
  3808. (format " (W%02d-W%02d)" w1 w2))
  3809. "")
  3810. ":\n")))
  3811. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3812. 'org-date-line t))
  3813. (org-agenda-mark-header-line s))
  3814. (while (setq d (pop day-numbers))
  3815. (setq date (calendar-gregorian-from-absolute d)
  3816. s (point))
  3817. (if (or (setq todayp (= d today))
  3818. (and (not start-pos) (= d sd)))
  3819. (setq start-pos (point))
  3820. (if (and start-pos (not end-pos))
  3821. (setq end-pos (point))))
  3822. (setq files thefiles
  3823. rtnall nil)
  3824. (while (setq file (pop files))
  3825. (catch 'nextfile
  3826. (org-check-agenda-file file)
  3827. (let ((org-agenda-entry-types org-agenda-entry-types))
  3828. ;; Starred types override non-starred equivalents
  3829. (when (member :deadline* org-agenda-entry-types)
  3830. (setq org-agenda-entry-types
  3831. (delq :deadline org-agenda-entry-types)))
  3832. (when (member :scheduled* org-agenda-entry-types)
  3833. (setq org-agenda-entry-types
  3834. (delq :scheduled org-agenda-entry-types)))
  3835. ;; Honor with-hour
  3836. (when with-hour
  3837. (when (member :deadline org-agenda-entry-types)
  3838. (setq org-agenda-entry-types
  3839. (delq :deadline org-agenda-entry-types))
  3840. (push :deadline* org-agenda-entry-types))
  3841. (when (member :scheduled org-agenda-entry-types)
  3842. (setq org-agenda-entry-types
  3843. (delq :scheduled org-agenda-entry-types))
  3844. (push :scheduled* org-agenda-entry-types)))
  3845. (unless org-agenda-include-deadlines
  3846. (setq org-agenda-entry-types
  3847. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3848. (cond
  3849. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3850. (setq rtn (org-agenda-get-day-entries
  3851. file date :closed)))
  3852. (org-agenda-show-log-scoped
  3853. (setq rtn (apply 'org-agenda-get-day-entries
  3854. file date
  3855. (append '(:closed) org-agenda-entry-types))))
  3856. (t
  3857. (setq rtn (apply 'org-agenda-get-day-entries
  3858. file date
  3859. org-agenda-entry-types)))))
  3860. (setq rtnall (append rtnall rtn)))) ;; all entries
  3861. (if org-agenda-include-diary
  3862. (let ((org-agenda-search-headline-for-time t))
  3863. (require 'diary-lib)
  3864. (setq rtn (org-get-entries-from-diary date))
  3865. (setq rtnall (append rtnall rtn))))
  3866. (if (or rtnall org-agenda-show-all-dates)
  3867. (progn
  3868. (setq day-cnt (1+ day-cnt))
  3869. (insert
  3870. (if (stringp org-agenda-format-date)
  3871. (format-time-string org-agenda-format-date
  3872. (org-time-from-absolute date))
  3873. (funcall org-agenda-format-date date))
  3874. "\n")
  3875. (put-text-property s (1- (point)) 'face
  3876. (org-agenda-get-day-face date))
  3877. (put-text-property s (1- (point)) 'org-date-line t)
  3878. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3879. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3880. (when todayp
  3881. (put-text-property s (1- (point)) 'org-today t))
  3882. (setq rtnall
  3883. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3884. (if rtnall (insert ;; all entries
  3885. (org-agenda-finalize-entries rtnall 'agenda)
  3886. "\n"))
  3887. (put-text-property s (1- (point)) 'day d)
  3888. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3889. (when (and org-agenda-clockreport-mode clocktable-start)
  3890. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3891. ;; the above line is to ensure the restricted range!
  3892. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3893. tbl)
  3894. (setq p (org-plist-delete p :block))
  3895. (setq p (plist-put p :tstart clocktable-start))
  3896. (setq p (plist-put p :tend clocktable-end))
  3897. (setq p (plist-put p :scope 'agenda))
  3898. (setq tbl (apply 'org-clock-get-clocktable p))
  3899. (insert tbl)))
  3900. (goto-char (point-min))
  3901. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3902. (unless (and (pos-visible-in-window-p (point-min))
  3903. (pos-visible-in-window-p (point-max)))
  3904. (goto-char (1- (point-max)))
  3905. (recenter -1)
  3906. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3907. (progn
  3908. (goto-char (or start-pos 1))
  3909. (recenter 1))))
  3910. (goto-char (or start-pos 1))
  3911. (add-text-properties (point-min) (point-max)
  3912. `(org-agenda-type agenda
  3913. org-last-args (,arg ,start-day ,span)
  3914. org-redo-cmd ,org-agenda-redo-command
  3915. org-series-cmd ,org-cmd))
  3916. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3917. (org-agenda-show-clocking-issues))
  3918. (org-agenda-finalize)
  3919. (setq buffer-read-only t)
  3920. (message ""))))
  3921. (defun org-agenda-ndays-to-span (n)
  3922. "Return a span symbol for a span of N days, or N if none matches."
  3923. (cond ((symbolp n) n)
  3924. ((= n 1) 'day)
  3925. ((= n 7) 'week)
  3926. ((= n 14) 'fortnight)
  3927. (t n)))
  3928. (defun org-agenda-span-to-ndays (span &optional start-day)
  3929. "Return ndays from SPAN, possibly starting at START-DAY.
  3930. START-DAY is an absolute time value."
  3931. (cond ((numberp span) span)
  3932. ((eq span 'day) 1)
  3933. ((eq span 'week) 7)
  3934. ((eq span 'fortnight) 14)
  3935. ((eq span 'month)
  3936. (let ((date (calendar-gregorian-from-absolute start-day)))
  3937. (calendar-last-day-of-month (car date) (cl-caddr date))))
  3938. ((eq span 'year)
  3939. (let ((date (calendar-gregorian-from-absolute start-day)))
  3940. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  3941. (defun org-agenda-span-name (span)
  3942. "Return a SPAN name."
  3943. (if (null span)
  3944. ""
  3945. (if (symbolp span)
  3946. (capitalize (symbol-name span))
  3947. (format "%d days" span))))
  3948. ;;; Agenda word search
  3949. (defvar org-agenda-search-history nil)
  3950. (defvar org-search-syntax-table nil
  3951. "Special syntax table for Org search.
  3952. In this table, we have single quotes not as word constituents, to
  3953. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3954. (defvar org-mode-syntax-table) ; From org.el
  3955. (defun org-search-syntax-table ()
  3956. (unless org-search-syntax-table
  3957. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3958. (modify-syntax-entry ?' "." org-search-syntax-table)
  3959. (modify-syntax-entry ?` "." org-search-syntax-table))
  3960. org-search-syntax-table)
  3961. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3962. ;;;###autoload
  3963. (defun org-search-view (&optional todo-only string edit-at)
  3964. "Show all entries that contain a phrase or words or regular expressions.
  3965. With optional prefix argument TODO-ONLY, only consider entries that are
  3966. TODO entries. The argument STRING can be used to pass a default search
  3967. string into this function. If EDIT-AT is non-nil, it means that the
  3968. user should get a chance to edit this string, with cursor at position
  3969. EDIT-AT.
  3970. The search string can be viewed either as a phrase that should be found as
  3971. is, or it can be broken into a number of snippets, each of which must match
  3972. in a Boolean way to select an entry. The default depends on the variable
  3973. `org-agenda-search-view-always-boolean'.
  3974. Even if this is turned off (the default) you can always switch to
  3975. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3976. The default is a direct search of the whole phrase, where each space in
  3977. the search string can expand to an arbitrary amount of whitespace,
  3978. including newlines.
  3979. If using a Boolean search, the search string is split on whitespace and
  3980. each snippet is searched separately, with logical AND to select an entry.
  3981. Words prefixed with a minus must *not* occur in the entry. Words without
  3982. a prefix or prefixed with a plus must occur in the entry. Matching is
  3983. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3984. match whole words, not parts of a word) if
  3985. `org-agenda-search-view-force-full-words' is set (default is nil).
  3986. Boolean search snippets enclosed by curly braces are interpreted as
  3987. regular expressions that must or (when preceded with \"-\") must not
  3988. match in the entry. Snippets enclosed into double quotes will be taken
  3989. as a whole, to include whitespace.
  3990. - If the search string starts with an asterisk, search only in headlines.
  3991. - If (possibly after the leading star) the search string starts with an
  3992. exclamation mark, this also means to look at TODO entries only, an effect
  3993. that can also be achieved with a prefix argument.
  3994. - If (possibly after star and exclamation mark) the search string starts
  3995. with a colon, this will mean that the (non-regexp) snippets of the
  3996. Boolean search must match as full words.
  3997. This command searches the agenda files, and in addition the files
  3998. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  3999. is active."
  4000. (interactive "P")
  4001. (if org-agenda-overriding-arguments
  4002. (setq todo-only (car org-agenda-overriding-arguments)
  4003. string (nth 1 org-agenda-overriding-arguments)
  4004. edit-at (nth 2 org-agenda-overriding-arguments)))
  4005. (let* ((props (list 'face nil
  4006. 'done-face 'org-agenda-done
  4007. 'org-not-done-regexp org-not-done-regexp
  4008. 'org-todo-regexp org-todo-regexp
  4009. 'org-complex-heading-regexp org-complex-heading-regexp
  4010. 'mouse-face 'highlight
  4011. 'help-echo (format "mouse-2 or RET jump to location")))
  4012. (full-words org-agenda-search-view-force-full-words)
  4013. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4014. regexp rtn rtnall files file pos inherited-tags
  4015. marker category level tags c neg re boolean
  4016. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4017. (unless (and (not edit-at)
  4018. (stringp string)
  4019. (string-match "\\S-" string))
  4020. (setq string (read-string
  4021. (if org-agenda-search-view-always-boolean
  4022. "[+-]Word/{Regexp} ...: "
  4023. "Phrase or [+-]Word/{Regexp} ...: ")
  4024. (cond
  4025. ((integerp edit-at) (cons string edit-at))
  4026. (edit-at string))
  4027. 'org-agenda-search-history)))
  4028. (catch 'exit
  4029. (if org-agenda-sticky
  4030. (setq org-agenda-buffer-name
  4031. (if (stringp string)
  4032. (format "*Org Agenda(%s:%s)*"
  4033. (or org-keys (or (and todo-only "S") "s")) string)
  4034. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4035. (org-agenda-prepare "SEARCH")
  4036. (org-compile-prefix-format 'search)
  4037. (org-set-sorting-strategy 'search)
  4038. (setq org-agenda-redo-command
  4039. (list 'org-search-view (if todo-only t nil)
  4040. (list 'if 'current-prefix-arg nil string)))
  4041. (setq org-agenda-query-string string)
  4042. (if (equal (string-to-char string) ?*)
  4043. (setq hdl-only t
  4044. words (substring string 1))
  4045. (setq words string))
  4046. (when (equal (string-to-char words) ?!)
  4047. (setq todo-only t
  4048. words (substring words 1)))
  4049. (when (equal (string-to-char words) ?:)
  4050. (setq full-words t
  4051. words (substring words 1)))
  4052. (if (or org-agenda-search-view-always-boolean
  4053. (member (string-to-char words) '(?- ?+ ?\{)))
  4054. (setq boolean t))
  4055. (setq words (split-string words))
  4056. (let (www w)
  4057. (while (setq w (pop words))
  4058. (while (and (string-match "\\\\\\'" w) words)
  4059. (setq w (concat (substring w 0 -1) " " (pop words))))
  4060. (push w www))
  4061. (setq words (nreverse www) www nil)
  4062. (while (setq w (pop words))
  4063. (when (and (string-match "\\`[-+]?{" w)
  4064. (not (string-match "}\\'" w)))
  4065. (while (and words (not (string-match "}\\'" (car words))))
  4066. (setq w (concat w " " (pop words))))
  4067. (setq w (concat w " " (pop words))))
  4068. (push w www))
  4069. (setq words (nreverse www)))
  4070. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4071. (when boolean
  4072. (let (wds w)
  4073. (while (setq w (pop words))
  4074. (if (or (equal (substring w 0 1) "\"")
  4075. (and (> (length w) 1)
  4076. (member (substring w 0 1) '("+" "-"))
  4077. (equal (substring w 1 2) "\"")))
  4078. (while (and words (not (equal (substring w -1) "\"")))
  4079. (setq w (concat w " " (pop words)))))
  4080. (and (string-match "\\`\\([-+]?\\)\"" w)
  4081. (setq w (replace-match "\\1" nil nil w)))
  4082. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4083. (push w wds))
  4084. (setq words (nreverse wds))))
  4085. (if boolean
  4086. (mapc (lambda (w)
  4087. (setq c (string-to-char w))
  4088. (if (equal c ?-)
  4089. (setq neg t w (substring w 1))
  4090. (if (equal c ?+)
  4091. (setq neg nil w (substring w 1))
  4092. (setq neg nil)))
  4093. (if (string-match "\\`{.*}\\'" w)
  4094. (setq re (substring w 1 -1))
  4095. (if full-words
  4096. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4097. (setq re (regexp-quote (downcase w)))))
  4098. (if neg (push re regexps-) (push re regexps+)))
  4099. words)
  4100. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4101. regexps+))
  4102. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4103. (if (not regexps+)
  4104. (setq regexp org-outline-regexp-bol)
  4105. (setq regexp (pop regexps+))
  4106. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4107. regexp))))
  4108. (setq files (org-agenda-files nil 'ifmode))
  4109. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4110. ;; restriction.
  4111. (unless (get 'org-agenda-files 'org-restrict)
  4112. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4113. (pop org-agenda-text-search-extra-files)
  4114. (setq files (org-add-archive-files files))))
  4115. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4116. ;; non-existent ones.
  4117. (setq files (cl-remove-duplicates
  4118. (append files org-agenda-text-search-extra-files)
  4119. :test (lambda (a b)
  4120. (and (file-exists-p a)
  4121. (file-exists-p b)
  4122. (file-equal-p a b))))
  4123. rtnall nil)
  4124. (while (setq file (pop files))
  4125. (setq ee nil)
  4126. (catch 'nextfile
  4127. (org-check-agenda-file file)
  4128. (setq buffer (if (file-exists-p file)
  4129. (org-get-agenda-file-buffer file)
  4130. (error "No such file %s" file)))
  4131. (if (not buffer)
  4132. ;; If file does not exist, make sure an error message is sent
  4133. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4134. file))))
  4135. (with-current-buffer buffer
  4136. (with-syntax-table (org-search-syntax-table)
  4137. (unless (derived-mode-p 'org-mode)
  4138. (error "Agenda file %s is not in Org mode" file))
  4139. (let ((case-fold-search t))
  4140. (save-excursion
  4141. (save-restriction
  4142. (if (eq buffer org-agenda-restrict)
  4143. (narrow-to-region org-agenda-restrict-begin
  4144. org-agenda-restrict-end)
  4145. (widen))
  4146. (goto-char (point-min))
  4147. (unless (or (org-at-heading-p)
  4148. (outline-next-heading))
  4149. (throw 'nextfile t))
  4150. (goto-char (max (point-min) (1- (point))))
  4151. (while (re-search-forward regexp nil t)
  4152. (org-back-to-heading t)
  4153. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4154. (> (org-reduced-level (org-outline-level))
  4155. org-agenda-search-view-max-outline-level)
  4156. (forward-line -1)
  4157. (org-back-to-heading t)))
  4158. (skip-chars-forward "* ")
  4159. (setq beg (point-at-bol)
  4160. beg1 (point)
  4161. end (progn
  4162. (outline-next-heading)
  4163. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4164. (> (org-reduced-level (org-outline-level))
  4165. org-agenda-search-view-max-outline-level)
  4166. (forward-line 1)
  4167. (outline-next-heading)))
  4168. (point)))
  4169. (catch :skip
  4170. (goto-char beg)
  4171. (org-agenda-skip)
  4172. (setq str (buffer-substring-no-properties
  4173. (point-at-bol)
  4174. (if hdl-only (point-at-eol) end)))
  4175. (mapc (lambda (wr) (when (string-match wr str)
  4176. (goto-char (1- end))
  4177. (throw :skip t)))
  4178. regexps-)
  4179. (mapc (lambda (wr) (unless (string-match wr str)
  4180. (goto-char (1- end))
  4181. (throw :skip t)))
  4182. (if todo-only
  4183. (cons (concat "^\\*+[ \t]+"
  4184. org-not-done-regexp)
  4185. regexps+)
  4186. regexps+))
  4187. (goto-char beg)
  4188. (setq marker (org-agenda-new-marker (point))
  4189. category (org-get-category)
  4190. level (make-string (org-reduced-level (org-outline-level)) ? )
  4191. inherited-tags
  4192. (or (eq org-agenda-show-inherited-tags 'always)
  4193. (and (listp org-agenda-show-inherited-tags)
  4194. (memq 'todo org-agenda-show-inherited-tags))
  4195. (and (eq org-agenda-show-inherited-tags t)
  4196. (or (eq org-agenda-use-tag-inheritance t)
  4197. (memq 'todo org-agenda-use-tag-inheritance))))
  4198. tags (org-get-tags-at nil (not inherited-tags))
  4199. txt (org-agenda-format-item
  4200. ""
  4201. (buffer-substring-no-properties
  4202. beg1 (point-at-eol))
  4203. level category tags t))
  4204. (org-add-props txt props
  4205. 'org-marker marker 'org-hd-marker marker
  4206. 'org-todo-regexp org-todo-regexp
  4207. 'level level
  4208. 'org-complex-heading-regexp org-complex-heading-regexp
  4209. 'priority 1000
  4210. 'type "search")
  4211. (push txt ee)
  4212. (goto-char (1- end))))))))))
  4213. (setq rtn (nreverse ee))
  4214. (setq rtnall (append rtnall rtn)))
  4215. (if org-agenda-overriding-header
  4216. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4217. nil 'face 'org-agenda-structure) "\n")
  4218. (insert "Search words: ")
  4219. (add-text-properties (point-min) (1- (point))
  4220. (list 'face 'org-agenda-structure))
  4221. (setq pos (point))
  4222. (insert string "\n")
  4223. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4224. (setq pos (point))
  4225. (unless org-agenda-multi
  4226. (insert (substitute-command-keys "\
  4227. Press `\\[org-agenda-manipulate-query-add]', \
  4228. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4229. `\\[org-agenda-manipulate-query-add-re]', \
  4230. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4231. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4232. (add-text-properties pos (1- (point))
  4233. (list 'face 'org-agenda-structure))))
  4234. (org-agenda-mark-header-line (point-min))
  4235. (when rtnall
  4236. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4237. (goto-char (point-min))
  4238. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4239. (add-text-properties (point-min) (point-max)
  4240. `(org-agenda-type search
  4241. org-last-args (,todo-only ,string ,edit-at)
  4242. org-redo-cmd ,org-agenda-redo-command
  4243. org-series-cmd ,org-cmd))
  4244. (org-agenda-finalize)
  4245. (setq buffer-read-only t))))
  4246. ;;; Agenda TODO list
  4247. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4248. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4249. (concat
  4250. (if (or (equal keywords "ALL") (not keywords))
  4251. (propertize "ALL" 'face 'warning)
  4252. (mapconcat
  4253. (lambda (kw)
  4254. (propertize kw 'face (org-get-todo-face kw)))
  4255. (org-split-string keywords "|")
  4256. "|"))
  4257. "\n"))
  4258. (defvar org-select-this-todo-keyword nil)
  4259. (defvar org-last-arg nil)
  4260. ;;;###autoload
  4261. (defun org-todo-list (&optional arg)
  4262. "Show all (not done) TODO entries from all agenda file in a single list.
  4263. The prefix arg can be used to select a specific TODO keyword and limit
  4264. the list to these. When using `\\[universal-argument]', you will be prompted
  4265. for a keyword. A numeric prefix directly selects the Nth keyword in
  4266. `org-todo-keywords-1'."
  4267. (interactive "P")
  4268. (if org-agenda-overriding-arguments
  4269. (setq arg org-agenda-overriding-arguments))
  4270. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4271. (let* ((today (org-today))
  4272. (date (calendar-gregorian-from-absolute today))
  4273. (kwds org-todo-keywords-for-agenda)
  4274. (completion-ignore-case t)
  4275. (org-select-this-todo-keyword
  4276. (if (stringp arg) arg
  4277. (and arg (integerp arg) (> arg 0)
  4278. (nth (1- arg) kwds))))
  4279. rtn rtnall files file pos)
  4280. (when (equal arg '(4))
  4281. (setq org-select-this-todo-keyword
  4282. (completing-read "Keyword (or KWD1|K2D2|...): "
  4283. (mapcar #'list kwds) nil nil)))
  4284. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4285. (catch 'exit
  4286. (if org-agenda-sticky
  4287. (setq org-agenda-buffer-name
  4288. (if (stringp org-select-this-todo-keyword)
  4289. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4290. org-select-this-todo-keyword)
  4291. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4292. (org-agenda-prepare "TODO")
  4293. (org-compile-prefix-format 'todo)
  4294. (org-set-sorting-strategy 'todo)
  4295. (setq org-agenda-redo-command
  4296. `(org-todo-list (or (and (numberp current-prefix-arg)
  4297. current-prefix-arg)
  4298. ,org-select-this-todo-keyword
  4299. current-prefix-arg ,arg)))
  4300. (setq files (org-agenda-files nil 'ifmode)
  4301. rtnall nil)
  4302. (while (setq file (pop files))
  4303. (catch 'nextfile
  4304. (org-check-agenda-file file)
  4305. (setq rtn (org-agenda-get-day-entries file date :todo))
  4306. (setq rtnall (append rtnall rtn))))
  4307. (if org-agenda-overriding-header
  4308. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4309. nil 'face 'org-agenda-structure) "\n")
  4310. (insert "Global list of TODO items of type: ")
  4311. (add-text-properties (point-min) (1- (point))
  4312. (list 'face 'org-agenda-structure
  4313. 'short-heading
  4314. (concat "ToDo: "
  4315. (or org-select-this-todo-keyword "ALL"))))
  4316. (org-agenda-mark-header-line (point-min))
  4317. (insert (org-agenda-propertize-selected-todo-keywords
  4318. org-select-this-todo-keyword))
  4319. (setq pos (point))
  4320. (unless org-agenda-multi
  4321. (insert (substitute-command-keys "Available with \
  4322. `N \\[org-agenda-redo]': (0)[ALL]"))
  4323. (let ((n 0) s)
  4324. (mapc (lambda (x)
  4325. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4326. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4327. (insert "\n "))
  4328. (insert " " s))
  4329. kwds))
  4330. (insert "\n"))
  4331. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4332. (org-agenda-mark-header-line (point-min))
  4333. (when rtnall
  4334. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4335. (goto-char (point-min))
  4336. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4337. (add-text-properties (point-min) (point-max)
  4338. `(org-agenda-type todo
  4339. org-last-args ,arg
  4340. org-redo-cmd ,org-agenda-redo-command
  4341. org-series-cmd ,org-cmd))
  4342. (org-agenda-finalize)
  4343. (setq buffer-read-only t))))
  4344. ;;; Agenda tags match
  4345. ;;;###autoload
  4346. (defun org-tags-view (&optional todo-only match)
  4347. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4348. The prefix arg TODO-ONLY limits the search to TODO entries."
  4349. (interactive "P")
  4350. (if org-agenda-overriding-arguments
  4351. (setq todo-only (car org-agenda-overriding-arguments)
  4352. match (nth 1 org-agenda-overriding-arguments)))
  4353. (let* ((org-tags-match-list-sublevels
  4354. org-tags-match-list-sublevels)
  4355. (completion-ignore-case t)
  4356. (org--matcher-tags-todo-only todo-only)
  4357. rtn rtnall files file pos matcher
  4358. buffer)
  4359. (when (and (stringp match) (not (string-match "\\S-" match)))
  4360. (setq match nil))
  4361. (catch 'exit
  4362. (if org-agenda-sticky
  4363. (setq org-agenda-buffer-name
  4364. (if (stringp match)
  4365. (format "*Org Agenda(%s:%s)*"
  4366. (or org-keys (or (and todo-only "M") "m")) match)
  4367. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4368. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4369. ;; expanding tags within `org-make-tags-matcher'
  4370. (org-agenda-prepare (concat "TAGS " match))
  4371. (setq matcher (org-make-tags-matcher match)
  4372. match (car matcher)
  4373. matcher (cdr matcher))
  4374. (org-compile-prefix-format 'tags)
  4375. (org-set-sorting-strategy 'tags)
  4376. (setq org-agenda-query-string match)
  4377. (setq org-agenda-redo-command
  4378. (list 'org-tags-view
  4379. `(quote ,org--matcher-tags-todo-only)
  4380. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4381. (setq files (org-agenda-files nil 'ifmode)
  4382. rtnall nil)
  4383. (while (setq file (pop files))
  4384. (catch 'nextfile
  4385. (org-check-agenda-file file)
  4386. (setq buffer (if (file-exists-p file)
  4387. (org-get-agenda-file-buffer file)
  4388. (error "No such file %s" file)))
  4389. (if (not buffer)
  4390. ;; If file does not exist, error message to agenda
  4391. (setq rtn (list
  4392. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4393. rtnall (append rtnall rtn))
  4394. (with-current-buffer buffer
  4395. (unless (derived-mode-p 'org-mode)
  4396. (error "Agenda file %s is not in Org mode" file))
  4397. (save-excursion
  4398. (save-restriction
  4399. (if (eq buffer org-agenda-restrict)
  4400. (narrow-to-region org-agenda-restrict-begin
  4401. org-agenda-restrict-end)
  4402. (widen))
  4403. (setq rtn (org-scan-tags 'agenda
  4404. matcher
  4405. org--matcher-tags-todo-only))
  4406. (setq rtnall (append rtnall rtn))))))))
  4407. (if org-agenda-overriding-header
  4408. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4409. nil 'face 'org-agenda-structure) "\n")
  4410. (insert "Headlines with TAGS match: ")
  4411. (add-text-properties (point-min) (1- (point))
  4412. (list 'face 'org-agenda-structure
  4413. 'short-heading
  4414. (concat "Match: " match)))
  4415. (setq pos (point))
  4416. (insert match "\n")
  4417. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4418. (setq pos (point))
  4419. (unless org-agenda-multi
  4420. (insert (substitute-command-keys
  4421. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4422. to search again with new search string\n")))
  4423. (add-text-properties pos (1- (point))
  4424. (list 'face 'org-agenda-structure)))
  4425. (org-agenda-mark-header-line (point-min))
  4426. (when rtnall
  4427. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4428. (goto-char (point-min))
  4429. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4430. (add-text-properties
  4431. (point-min) (point-max)
  4432. `(org-agenda-type tags
  4433. org-last-args (,org--matcher-tags-todo-only ,match)
  4434. org-redo-cmd ,org-agenda-redo-command
  4435. org-series-cmd ,org-cmd))
  4436. (org-agenda-finalize)
  4437. (setq buffer-read-only t))))
  4438. ;;; Agenda Finding stuck projects
  4439. (defvar org-agenda-skip-regexp nil
  4440. "Regular expression used in skipping subtrees for the agenda.
  4441. This is basically a temporary global variable that can be set and then
  4442. used by user-defined selections using `org-agenda-skip-function'.")
  4443. (defvar org-agenda-overriding-header nil
  4444. "When set during agenda, todo and tags searches it replaces the header.
  4445. This variable should not be set directly, but custom commands can bind it
  4446. in the options section.")
  4447. (defun org-agenda-skip-entry-if (&rest conditions)
  4448. "Skip entry if any of CONDITIONS is true.
  4449. See `org-agenda-skip-if' for details."
  4450. (org-agenda-skip-if nil conditions))
  4451. (defun org-agenda-skip-subtree-if (&rest conditions)
  4452. "Skip subtree if any of CONDITIONS is true.
  4453. See `org-agenda-skip-if' for details."
  4454. (org-agenda-skip-if t conditions))
  4455. (defun org-agenda-skip-if (subtree conditions)
  4456. "Checks current entity for CONDITIONS.
  4457. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4458. the entry (i.e. the text before the next heading) is checked.
  4459. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4460. from different tests. Valid conditions are:
  4461. scheduled Check if there is a scheduled cookie
  4462. notscheduled Check if there is no scheduled cookie
  4463. deadline Check if there is a deadline
  4464. notdeadline Check if there is no deadline
  4465. timestamp Check if there is a timestamp (also deadline or scheduled)
  4466. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4467. regexp Check if regexp matches
  4468. notregexp Check if regexp does not match.
  4469. todo Check if TODO keyword matches
  4470. nottodo Check if TODO keyword does not match
  4471. The regexp is taken from the conditions list, it must come right after
  4472. the `regexp' or `notregexp' element.
  4473. `todo' and `nottodo' accept as an argument a list of todo
  4474. keywords, which may include \"*\" to match any todo keyword.
  4475. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4476. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4477. Instead of a list, a keyword class may be given. For example:
  4478. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4479. would skip entries that haven't been marked with any of \"DONE\"
  4480. keywords. Possible classes are: `todo', `done', `any'.
  4481. If any of these conditions is met, this function returns the end point of
  4482. the entity, causing the search to continue from there. This is a function
  4483. that can be put into `org-agenda-skip-function' for the duration of a command."
  4484. (org-back-to-heading t)
  4485. (let* ((beg (point))
  4486. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4487. (org-entry-end-position)))
  4488. (planning-end (if subtree end (line-end-position 2)))
  4489. m)
  4490. (and
  4491. (or (and (memq 'scheduled conditions)
  4492. (re-search-forward org-scheduled-time-regexp planning-end t))
  4493. (and (memq 'notscheduled conditions)
  4494. (not
  4495. (save-excursion
  4496. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4497. (and (memq 'deadline conditions)
  4498. (re-search-forward org-deadline-time-regexp planning-end t))
  4499. (and (memq 'notdeadline conditions)
  4500. (not
  4501. (save-excursion
  4502. (re-search-forward org-deadline-time-regexp planning-end t))))
  4503. (and (memq 'timestamp conditions)
  4504. (re-search-forward org-ts-regexp end t))
  4505. (and (memq 'nottimestamp conditions)
  4506. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4507. (and (setq m (memq 'regexp conditions))
  4508. (stringp (nth 1 m))
  4509. (re-search-forward (nth 1 m) end t))
  4510. (and (setq m (memq 'notregexp conditions))
  4511. (stringp (nth 1 m))
  4512. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4513. (and (or
  4514. (setq m (memq 'nottodo conditions))
  4515. (setq m (memq 'todo-unblocked conditions))
  4516. (setq m (memq 'nottodo-unblocked conditions))
  4517. (setq m (memq 'todo conditions)))
  4518. (org-agenda-skip-if-todo m end)))
  4519. end)))
  4520. (defun org-agenda-skip-if-todo (args end)
  4521. "Helper function for `org-agenda-skip-if', do not use it directly.
  4522. ARGS is a list with first element either `todo', `nottodo',
  4523. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4524. a list of TODO keywords, or a state symbol `todo' or `done' or
  4525. `any'."
  4526. (let ((todo-re
  4527. (concat "^\\*+[ \t]+"
  4528. (regexp-opt
  4529. (pcase args
  4530. (`(,_ todo)
  4531. (org-delete-all org-done-keywords
  4532. (copy-sequence org-todo-keywords-1)))
  4533. (`(,_ done) org-done-keywords)
  4534. (`(,_ any) org-todo-keywords-1)
  4535. (`(,_ ,(pred atom))
  4536. (error "Invalid TODO class or type: %S" args))
  4537. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4538. (`(,_ ,todo-list) todo-list))
  4539. 'words))))
  4540. (pcase args
  4541. (`(todo . ,_)
  4542. (let (case-fold-search) (re-search-forward todo-re end t)))
  4543. (`(nottodo . ,_)
  4544. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4545. (`(todo-unblocked . ,_)
  4546. (catch :unblocked
  4547. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4548. (when (org-entry-blocked-p) (throw :unblocked t)))
  4549. nil))
  4550. (`(nottodo-unblocked . ,_)
  4551. (catch :unblocked
  4552. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4553. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4554. t))
  4555. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4556. ;;;###autoload
  4557. (defun org-agenda-list-stuck-projects (&rest ignore)
  4558. "Create agenda view for projects that are stuck.
  4559. Stuck projects are project that have no next actions. For the definitions
  4560. of what a project is and how to check if it stuck, customize the variable
  4561. `org-stuck-projects'."
  4562. (interactive)
  4563. (let* ((org-agenda-overriding-header
  4564. (or org-agenda-overriding-header "List of stuck projects: "))
  4565. (matcher (nth 0 org-stuck-projects))
  4566. (todo (nth 1 org-stuck-projects))
  4567. (tags (nth 2 org-stuck-projects))
  4568. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4569. (todo-wds
  4570. (if (not (member "*" todo)) todo
  4571. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4572. (org-delete-all org-done-keywords-for-agenda
  4573. (copy-sequence org-todo-keywords-for-agenda))))
  4574. (todo-re (and todo
  4575. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4576. (mapconcat #'identity todo-wds "\\|"))))
  4577. (tags-re (cond ((null tags) nil)
  4578. ((member "*" tags)
  4579. (eval-when-compile
  4580. (concat org-outline-regexp-bol
  4581. ".*:[[:alnum:]_@#%]+:[ \t]*$")))
  4582. (tags (concat org-outline-regexp-bol
  4583. ".*:\\("
  4584. (mapconcat #'identity tags "\\|")
  4585. "\\):[[:alnum:]_@#%:]*[ \t]*$"))
  4586. (t nil)))
  4587. (re-list (delq nil (list todo-re tags-re gen-re)))
  4588. (skip-re
  4589. (if (null re-list)
  4590. (error "Missing information to identify unstuck projects")
  4591. (mapconcat #'identity re-list "\\|")))
  4592. (org-agenda-skip-function
  4593. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4594. ;; in the subtree.
  4595. `(lambda ()
  4596. (and (save-excursion
  4597. (let ((case-fold-search nil))
  4598. (re-search-forward
  4599. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4600. (progn (outline-next-heading) (point))))))
  4601. (org-tags-view nil matcher)
  4602. (setq org-agenda-buffer-name (buffer-name))
  4603. (with-current-buffer org-agenda-buffer-name
  4604. (setq org-agenda-redo-command
  4605. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4606. (let ((inhibit-read-only t))
  4607. (add-text-properties
  4608. (point-min) (point-max)
  4609. `(org-redo-cmd ,org-agenda-redo-command))))))
  4610. ;;; Diary integration
  4611. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4612. (defvar diary-list-entries-hook)
  4613. (defvar diary-time-regexp)
  4614. (defun org-get-entries-from-diary (date)
  4615. "Get the (Emacs Calendar) diary entries for DATE."
  4616. (require 'diary-lib)
  4617. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4618. (diary-display-function 'diary-fancy-display)
  4619. (pop-up-frames nil)
  4620. (diary-list-entries-hook
  4621. (cons 'org-diary-default-entry diary-list-entries-hook))
  4622. (diary-file-name-prefix nil) ; turn this feature off
  4623. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4624. entries
  4625. (org-disable-agenda-to-diary t))
  4626. (save-excursion
  4627. (save-window-excursion
  4628. (funcall (if (fboundp 'diary-list-entries)
  4629. 'diary-list-entries 'list-diary-entries)
  4630. date 1)))
  4631. (if (not (get-buffer diary-fancy-buffer))
  4632. (setq entries nil)
  4633. (with-current-buffer diary-fancy-buffer
  4634. (setq buffer-read-only nil)
  4635. (if (zerop (buffer-size))
  4636. ;; No entries
  4637. (setq entries nil)
  4638. ;; Omit the date and other unnecessary stuff
  4639. (org-agenda-cleanup-fancy-diary)
  4640. ;; Add prefix to each line and extend the text properties
  4641. (if (zerop (buffer-size))
  4642. (setq entries nil)
  4643. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4644. (setq entries
  4645. (with-temp-buffer
  4646. (insert entries) (goto-char (point-min))
  4647. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4648. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4649. (replace-match (concat "; " (match-string 1)))))
  4650. (buffer-string)))))
  4651. (set-buffer-modified-p nil)
  4652. (kill-buffer diary-fancy-buffer)))
  4653. (when entries
  4654. (setq entries (org-split-string entries "\n"))
  4655. (setq entries
  4656. (mapcar
  4657. (lambda (x)
  4658. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4659. ;; Extend the text properties to the beginning of the line
  4660. (org-add-props x (text-properties-at (1- (length x)) x)
  4661. 'type "diary" 'date date 'face 'org-agenda-diary))
  4662. entries)))))
  4663. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4664. "Hook run when the fancy diary buffer is cleaned up.")
  4665. (defun org-agenda-cleanup-fancy-diary ()
  4666. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4667. This gets rid of the date, the underline under the date, and the
  4668. dummy entry installed by Org mode to ensure non-empty diary for
  4669. each date. It also removes lines that contain only whitespace."
  4670. (goto-char (point-min))
  4671. (if (looking-at ".*?:[ \t]*")
  4672. (progn
  4673. (replace-match "")
  4674. (re-search-forward "\n=+$" nil t)
  4675. (replace-match "")
  4676. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4677. (re-search-forward "\n=+$" nil t)
  4678. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4679. (goto-char (point-min))
  4680. (while (re-search-forward "^ +\n" nil t)
  4681. (replace-match ""))
  4682. (goto-char (point-min))
  4683. (if (re-search-forward "^Org mode dummy\n?" nil t)
  4684. (replace-match ""))
  4685. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4686. ;; Make sure entries from the diary have the right text properties.
  4687. (eval-after-load "diary-lib"
  4688. '(if (boundp 'diary-modify-entry-list-string-function)
  4689. ;; We can rely on the hook, nothing to do
  4690. nil
  4691. ;; Hook not available, must use advice to make this work
  4692. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4693. "Make the position visible."
  4694. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4695. (stringp string)
  4696. buffer-file-name)
  4697. (setq string (org-modify-diary-entry-string string))))))
  4698. (defun org-modify-diary-entry-string (string)
  4699. "Add text properties to string, allowing Org to act on it."
  4700. (org-add-props string nil
  4701. 'mouse-face 'highlight
  4702. 'help-echo (if buffer-file-name
  4703. (format "mouse-2 or RET jump to diary file %s"
  4704. (abbreviate-file-name buffer-file-name))
  4705. "")
  4706. 'org-agenda-diary-link t
  4707. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4708. (defun org-diary-default-entry ()
  4709. "Add a dummy entry to the diary.
  4710. Needed to avoid empty dates which mess up holiday display."
  4711. ;; Catch the error if dealing with the new add-to-diary-alist
  4712. (when org-disable-agenda-to-diary
  4713. (condition-case nil
  4714. (org-add-to-diary-list original-date "Org mode dummy" "")
  4715. (error
  4716. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4717. (defun org-add-to-diary-list (&rest args)
  4718. (if (fboundp 'diary-add-to-list)
  4719. (apply 'diary-add-to-list args)
  4720. (apply 'add-to-diary-list args)))
  4721. (defvar org-diary-last-run-time nil)
  4722. ;;;###autoload
  4723. (defun org-diary (&rest args)
  4724. "Return diary information from org files.
  4725. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4726. It accesses org files and extracts information from those files to be
  4727. listed in the diary. The function accepts arguments specifying what
  4728. items should be listed. For a list of arguments allowed here, see the
  4729. variable `org-agenda-entry-types'.
  4730. The call in the diary file should look like this:
  4731. &%%(org-diary) ~/path/to/some/orgfile.org
  4732. Use a separate line for each org file to check. Or, if you omit the file name,
  4733. all files listed in `org-agenda-files' will be checked automatically:
  4734. &%%(org-diary)
  4735. If you don't give any arguments (as in the example above), the default value
  4736. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4737. So the example above may also be written as
  4738. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4739. The function expects the lisp variables `entry' and `date' to be provided
  4740. by the caller, because this is how the calendar works. Don't use this
  4741. function from a program - use `org-agenda-get-day-entries' instead."
  4742. (when (> (- (float-time)
  4743. org-agenda-last-marker-time)
  4744. 5)
  4745. ;; I am not sure if this works with sticky agendas, because the marker
  4746. ;; list is then no longer a global variable.
  4747. (org-agenda-reset-markers))
  4748. (org-compile-prefix-format 'agenda)
  4749. (org-set-sorting-strategy 'agenda)
  4750. (setq args (or args org-agenda-entry-types))
  4751. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4752. (list entry)
  4753. (org-agenda-files t)))
  4754. (time (float-time))
  4755. file rtn results)
  4756. (when (or (not org-diary-last-run-time)
  4757. (> (- time
  4758. org-diary-last-run-time)
  4759. 3))
  4760. (org-agenda-prepare-buffers files))
  4761. (setq org-diary-last-run-time time)
  4762. ;; If this is called during org-agenda, don't return any entries to
  4763. ;; the calendar. Org Agenda will list these entries itself.
  4764. (if org-disable-agenda-to-diary (setq files nil))
  4765. (while (setq file (pop files))
  4766. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4767. (setq results (append results rtn)))
  4768. (when results
  4769. (setq results
  4770. (mapcar (lambda (i) (replace-regexp-in-string
  4771. org-bracket-link-regexp "\\3" i)) results))
  4772. (concat (org-agenda-finalize-entries results) "\n"))))
  4773. ;;; Agenda entry finders
  4774. (defun org-agenda--timestamp-to-absolute (&rest args)
  4775. "Call `org-time-string-to-absolute' with ARGS.
  4776. However, throw `:skip' whenever an error is raised."
  4777. (condition-case e
  4778. (apply #'org-time-string-to-absolute args)
  4779. (org-diary-sexp-no-match (throw :skip nil))
  4780. (error
  4781. (message "%s; Skipping entry" (error-message-string e))
  4782. (throw :skip nil))))
  4783. (defun org-agenda-get-day-entries (file date &rest args)
  4784. "Does the work for `org-diary' and `org-agenda'.
  4785. FILE is the path to a file to be checked for entries. DATE is date like
  4786. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4787. which kind of entries should be extracted. For details about these, see
  4788. the documentation of `org-diary'."
  4789. (let* ((org-startup-folded nil)
  4790. (org-startup-align-all-tables nil)
  4791. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4792. (error "No such file %s" file))))
  4793. (if (not buffer)
  4794. ;; If file does not exist, signal it in diary nonetheless.
  4795. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4796. (with-current-buffer buffer
  4797. (unless (derived-mode-p 'org-mode)
  4798. (error "Agenda file %s is not in Org mode" file))
  4799. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4800. (setf org-agenda-current-date date)
  4801. (save-excursion
  4802. (save-restriction
  4803. (if (eq buffer org-agenda-restrict)
  4804. (narrow-to-region org-agenda-restrict-begin
  4805. org-agenda-restrict-end)
  4806. (widen))
  4807. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4808. ;; first in order to populate DEADLINES before passing it.
  4809. ;;
  4810. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4811. ;; guarding us from modifying `org-agenda-entry-types'.
  4812. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4813. (when (and (memq :scheduled args) (memq :scheduled* args))
  4814. (setf args (delq :scheduled* args)))
  4815. (cond
  4816. ((memq :deadline args)
  4817. (setf args (cons :deadline
  4818. (delq :deadline (delq :deadline* args)))))
  4819. ((memq :deadline* args)
  4820. (setf args (cons :deadline* (delq :deadline* args)))))
  4821. ;; Collect list of headlines. Return them flattened.
  4822. (let ((case-fold-search nil) results deadlines)
  4823. (dolist (arg args (apply #'nconc (nreverse results)))
  4824. (pcase arg
  4825. ((and :todo (guard (org-agenda-today-p date)))
  4826. (push (org-agenda-get-todos) results))
  4827. (:timestamp
  4828. (push (org-agenda-get-blocks) results)
  4829. (push (org-agenda-get-timestamps deadlines) results))
  4830. (:sexp
  4831. (push (org-agenda-get-sexps) results))
  4832. (:scheduled
  4833. (push (org-agenda-get-scheduled deadlines) results))
  4834. (:scheduled*
  4835. (push (org-agenda-get-scheduled deadlines t) results))
  4836. (:closed
  4837. (push (org-agenda-get-progress) results))
  4838. (:deadline
  4839. (setf deadlines (org-agenda-get-deadlines))
  4840. (push deadlines results))
  4841. (:deadline*
  4842. (setf deadlines (org-agenda-get-deadlines t))
  4843. (push deadlines results)))))))))))
  4844. (defsubst org-em (x y list)
  4845. "Is X or Y a member of LIST?"
  4846. (or (memq x list) (memq y list)))
  4847. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4848. (defvar org-agenda-sorting-strategy-selected nil)
  4849. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4850. "Retrieve timestamp information for sorting agenda views.
  4851. Given a point or marker POM, returns a cons cell of the timestamp
  4852. and the timestamp type relevant for the sorting strategy in
  4853. `org-agenda-sorting-strategy-selected'."
  4854. (let (ts ts-date-type)
  4855. (save-match-data
  4856. (cond ((org-em 'scheduled-up 'scheduled-down
  4857. org-agenda-sorting-strategy-selected)
  4858. (setq ts (org-entry-get pom "SCHEDULED")
  4859. ts-date-type " scheduled"))
  4860. ((org-em 'deadline-up 'deadline-down
  4861. org-agenda-sorting-strategy-selected)
  4862. (setq ts (org-entry-get pom "DEADLINE")
  4863. ts-date-type " deadline"))
  4864. ((org-em 'ts-up 'ts-down
  4865. org-agenda-sorting-strategy-selected)
  4866. (setq ts (org-entry-get pom "TIMESTAMP")
  4867. ts-date-type " timestamp"))
  4868. ((org-em 'tsia-up 'tsia-down
  4869. org-agenda-sorting-strategy-selected)
  4870. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4871. ts-date-type " timestamp_ia"))
  4872. ((org-em 'timestamp-up 'timestamp-down
  4873. org-agenda-sorting-strategy-selected)
  4874. (setq ts (or (org-entry-get pom "SCHEDULED")
  4875. (org-entry-get pom "DEADLINE")
  4876. (org-entry-get pom "TIMESTAMP")
  4877. (org-entry-get pom "TIMESTAMP_IA"))
  4878. ts-date-type ""))
  4879. (t (setq ts-date-type "")))
  4880. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4881. ts-date-type))))
  4882. (defun org-agenda-get-todos ()
  4883. "Return the TODO information for agenda display."
  4884. (let* ((props (list 'face nil
  4885. 'done-face 'org-agenda-done
  4886. 'org-not-done-regexp org-not-done-regexp
  4887. 'org-todo-regexp org-todo-regexp
  4888. 'org-complex-heading-regexp org-complex-heading-regexp
  4889. 'mouse-face 'highlight
  4890. 'help-echo
  4891. (format "mouse-2 or RET jump to org file %s"
  4892. (abbreviate-file-name buffer-file-name))))
  4893. (case-fold-search nil)
  4894. (regexp (format org-heading-keyword-regexp-format
  4895. (cond
  4896. ((and org-select-this-todo-keyword
  4897. (equal org-select-this-todo-keyword "*"))
  4898. org-todo-regexp)
  4899. (org-select-this-todo-keyword
  4900. (concat "\\("
  4901. (mapconcat 'identity
  4902. (org-split-string
  4903. org-select-this-todo-keyword
  4904. "|")
  4905. "\\|") "\\)"))
  4906. (t org-not-done-regexp))))
  4907. marker priority category level tags todo-state
  4908. ts-date ts-date-type ts-date-pair
  4909. ee txt beg end inherited-tags todo-state-end-pos)
  4910. (goto-char (point-min))
  4911. (while (re-search-forward regexp nil t)
  4912. (catch :skip
  4913. (save-match-data
  4914. (beginning-of-line)
  4915. (org-agenda-skip)
  4916. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4917. (unless (and (setq todo-state (org-get-todo-state))
  4918. (setq todo-state-end-pos (match-end 2)))
  4919. (goto-char end)
  4920. (throw :skip nil))
  4921. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4922. (goto-char (1+ beg))
  4923. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4924. (throw :skip nil)))
  4925. (goto-char (match-beginning 2))
  4926. (setq marker (org-agenda-new-marker (match-beginning 0))
  4927. category (org-get-category)
  4928. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  4929. ts-date (car ts-date-pair)
  4930. ts-date-type (cdr ts-date-pair)
  4931. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  4932. inherited-tags
  4933. (or (eq org-agenda-show-inherited-tags 'always)
  4934. (and (listp org-agenda-show-inherited-tags)
  4935. (memq 'todo org-agenda-show-inherited-tags))
  4936. (and (eq org-agenda-show-inherited-tags t)
  4937. (or (eq org-agenda-use-tag-inheritance t)
  4938. (memq 'todo org-agenda-use-tag-inheritance))))
  4939. tags (org-get-tags-at nil (not inherited-tags))
  4940. level (make-string (org-reduced-level (org-outline-level)) ? )
  4941. txt (org-agenda-format-item "" txt level category tags t)
  4942. priority (1+ (org-get-priority txt)))
  4943. (org-add-props txt props
  4944. 'org-marker marker 'org-hd-marker marker
  4945. 'priority priority
  4946. 'level level
  4947. 'ts-date ts-date
  4948. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4949. (push txt ee)
  4950. (if org-agenda-todo-list-sublevels
  4951. (goto-char todo-state-end-pos)
  4952. (org-end-of-subtree 'invisible))))
  4953. (nreverse ee)))
  4954. (defun org-agenda-todo-custom-ignore-p (time n)
  4955. "Check whether timestamp is farther away than n number of days.
  4956. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4957. `org-agenda-todo-ignore-scheduled' or
  4958. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4959. (let ((days (org-time-stamp-to-now
  4960. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4961. (if (>= n 0)
  4962. (>= days n)
  4963. (<= days n))))
  4964. ;;;###autoload
  4965. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4966. (&optional end)
  4967. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4968. (when (or org-agenda-todo-ignore-with-date
  4969. org-agenda-todo-ignore-scheduled
  4970. org-agenda-todo-ignore-deadlines
  4971. org-agenda-todo-ignore-timestamp)
  4972. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4973. (save-excursion
  4974. (or (and org-agenda-todo-ignore-with-date
  4975. (re-search-forward org-ts-regexp end t))
  4976. (and org-agenda-todo-ignore-scheduled
  4977. (re-search-forward org-scheduled-time-regexp end t)
  4978. (cond
  4979. ((eq org-agenda-todo-ignore-scheduled 'future)
  4980. (> (org-time-stamp-to-now
  4981. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4982. ((eq org-agenda-todo-ignore-scheduled 'past)
  4983. (<= (org-time-stamp-to-now
  4984. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4985. ((numberp org-agenda-todo-ignore-scheduled)
  4986. (org-agenda-todo-custom-ignore-p
  4987. (match-string 1) org-agenda-todo-ignore-scheduled))
  4988. (t)))
  4989. (and org-agenda-todo-ignore-deadlines
  4990. (re-search-forward org-deadline-time-regexp end t)
  4991. (cond
  4992. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4993. ((eq org-agenda-todo-ignore-deadlines 'far)
  4994. (not (org-deadline-close-p (match-string 1))))
  4995. ((eq org-agenda-todo-ignore-deadlines 'future)
  4996. (> (org-time-stamp-to-now
  4997. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4998. ((eq org-agenda-todo-ignore-deadlines 'past)
  4999. (<= (org-time-stamp-to-now
  5000. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5001. ((numberp org-agenda-todo-ignore-deadlines)
  5002. (org-agenda-todo-custom-ignore-p
  5003. (match-string 1) org-agenda-todo-ignore-deadlines))
  5004. (t (org-deadline-close-p (match-string 1)))))
  5005. (and org-agenda-todo-ignore-timestamp
  5006. (let ((buffer (current-buffer))
  5007. (regexp
  5008. (concat
  5009. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5010. (start (point)))
  5011. ;; Copy current buffer into a temporary one
  5012. (with-temp-buffer
  5013. (insert-buffer-substring buffer start end)
  5014. (goto-char (point-min))
  5015. ;; Delete SCHEDULED and DEADLINE items
  5016. (while (re-search-forward regexp end t)
  5017. (delete-region (match-beginning 0) (match-end 0)))
  5018. (goto-char (point-min))
  5019. ;; No search for timestamp left
  5020. (when (re-search-forward org-ts-regexp nil t)
  5021. (cond
  5022. ((eq org-agenda-todo-ignore-timestamp 'future)
  5023. (> (org-time-stamp-to-now
  5024. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5025. ((eq org-agenda-todo-ignore-timestamp 'past)
  5026. (<= (org-time-stamp-to-now
  5027. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5028. ((numberp org-agenda-todo-ignore-timestamp)
  5029. (org-agenda-todo-custom-ignore-p
  5030. (match-string 1) org-agenda-todo-ignore-timestamp))
  5031. (t))))))))))
  5032. (defun org-agenda-get-timestamps (&optional deadlines)
  5033. "Return the date stamp information for agenda display.
  5034. Optional argument DEADLINES is a list of deadline items to be
  5035. displayed in agenda view."
  5036. (let* ((props (list 'face 'org-agenda-calendar-event
  5037. 'org-not-done-regexp org-not-done-regexp
  5038. 'org-todo-regexp org-todo-regexp
  5039. 'org-complex-heading-regexp org-complex-heading-regexp
  5040. 'mouse-face 'highlight
  5041. 'help-echo
  5042. (format "mouse-2 or RET jump to Org file %s"
  5043. (abbreviate-file-name buffer-file-name))))
  5044. (current (calendar-absolute-from-gregorian date))
  5045. (today (org-today))
  5046. (deadline-position-alist
  5047. (mapcar (lambda (d)
  5048. (let ((m (get-text-property 0 'org-hd-marker d)))
  5049. (and m (marker-position m))))
  5050. deadlines))
  5051. ;; Match time-stamps set to current date, time-stamps with
  5052. ;; a repeater, and S-exp time-stamps.
  5053. (regexp
  5054. (concat
  5055. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5056. (regexp-quote
  5057. (substring
  5058. (format-time-string
  5059. (car org-time-stamp-formats)
  5060. (apply #'encode-time ; DATE bound by calendar
  5061. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5062. 1 11))
  5063. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5064. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5065. timestamp-items)
  5066. (goto-char (point-min))
  5067. (while (re-search-forward regexp nil t)
  5068. ;; Skip date ranges, scheduled and deadlines, which are handled
  5069. ;; specially. Also skip time-stamps before first headline as
  5070. ;; there would be no entry to add to the agenda. Eventually,
  5071. ;; ignore clock entries.
  5072. (catch :skip
  5073. (save-match-data
  5074. (when (or (org-at-date-range-p)
  5075. (org-at-planning-p)
  5076. (org-before-first-heading-p)
  5077. (and org-agenda-include-inactive-timestamps
  5078. (org-at-clock-log-p)))
  5079. (throw :skip nil))
  5080. (org-agenda-skip))
  5081. (let* ((pos (match-beginning 0))
  5082. (repeat (match-string 1))
  5083. (sexp-entry (match-string 3))
  5084. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5085. (save-excursion
  5086. (goto-char pos)
  5087. (looking-at org-ts-regexp-both)
  5088. (match-string 0))))
  5089. (todo-state (org-get-todo-state))
  5090. (warntime (get-text-property (point) 'org-appt-warntime))
  5091. (done? (member todo-state org-done-keywords)))
  5092. ;; Possibly skip done tasks.
  5093. (when (and done? org-agenda-skip-timestamp-if-done)
  5094. (throw :skip t))
  5095. ;; S-exp entry doesn't match current day: skip it.
  5096. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5097. (throw :skip nil))
  5098. (when repeat
  5099. (let* ((past
  5100. ;; A repeating time stamp is shown at its base
  5101. ;; date and every repeated date up to TODAY. If
  5102. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5103. ;; however, only the last repeat before today
  5104. ;; (inclusive) is shown.
  5105. (org-agenda--timestamp-to-absolute
  5106. repeat
  5107. (if (or (> current today)
  5108. (eq org-agenda-prefer-last-repeat t)
  5109. (member todo-state org-agenda-prefer-last-repeat))
  5110. today
  5111. current)
  5112. 'past (current-buffer) pos))
  5113. (future
  5114. ;; Display every repeated date past TODAY
  5115. ;; (exclusive) unless
  5116. ;; `org-agenda-show-future-repeats' is nil. If
  5117. ;; this variable is set to `next', only display
  5118. ;; the first repeated date after TODAY
  5119. ;; (exclusive).
  5120. (cond
  5121. ((<= current today) past)
  5122. ((not org-agenda-show-future-repeats) past)
  5123. (t
  5124. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5125. (1+ today)
  5126. current)))
  5127. (org-agenda--timestamp-to-absolute
  5128. repeat base 'future (current-buffer) pos))))))
  5129. (when (and (/= current past) (/= current future))
  5130. (throw :skip nil))))
  5131. (save-excursion
  5132. (re-search-backward org-outline-regexp-bol nil t)
  5133. ;; Possibly skip time-stamp when a deadline is set.
  5134. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5135. (assq (point) deadline-position-alist))
  5136. (throw :skip nil))
  5137. (let* ((category (org-get-category pos))
  5138. (inherited-tags
  5139. (or (eq org-agenda-show-inherited-tags 'always)
  5140. (and (consp org-agenda-show-inherited-tags)
  5141. (memq 'agenda org-agenda-show-inherited-tags))
  5142. (and (eq org-agenda-show-inherited-tags t)
  5143. (or (eq org-agenda-use-tag-inheritance t)
  5144. (memq 'agenda
  5145. org-agenda-use-tag-inheritance)))))
  5146. (tags (org-get-tags-at nil (not inherited-tags)))
  5147. (level (make-string (org-reduced-level (org-outline-level))
  5148. ?\s))
  5149. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5150. (match-string 1)))
  5151. (inactive? (= (char-after pos) ?\[))
  5152. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5153. (item
  5154. (org-agenda-format-item
  5155. (and inactive? org-agenda-inactive-leader)
  5156. head level category tags time-stamp org-ts-regexp habit?)))
  5157. (org-add-props item props
  5158. 'priority (if habit?
  5159. (org-habit-get-priority (org-habit-parse-todo))
  5160. (org-get-priority item))
  5161. 'org-marker (org-agenda-new-marker pos)
  5162. 'org-hd-marker (org-agenda-new-marker)
  5163. 'date date
  5164. 'level level
  5165. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5166. current)
  5167. 'todo-state todo-state
  5168. 'warntime warntime
  5169. 'type "timestamp")
  5170. (push item timestamp-items))))
  5171. (when org-agenda-skip-additional-timestamps-same-entry
  5172. (outline-next-heading))))
  5173. (nreverse timestamp-items)))
  5174. (defun org-agenda-get-sexps ()
  5175. "Return the sexp information for agenda display."
  5176. (require 'diary-lib)
  5177. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5178. 'mouse-face 'highlight
  5179. 'help-echo
  5180. (format "mouse-2 or RET jump to org file %s"
  5181. (abbreviate-file-name buffer-file-name))))
  5182. (regexp "^&?%%(")
  5183. marker category extra level ee txt tags entry
  5184. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5185. (goto-char (point-min))
  5186. (while (re-search-forward regexp nil t)
  5187. (catch :skip
  5188. (org-agenda-skip)
  5189. (setq beg (match-beginning 0))
  5190. (goto-char (1- (match-end 0)))
  5191. (setq b (point))
  5192. (forward-sexp 1)
  5193. (setq sexp (buffer-substring b (point)))
  5194. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5195. (org-trim (match-string 1))
  5196. ""))
  5197. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5198. (when result
  5199. (setq marker (org-agenda-new-marker beg)
  5200. level (make-string (org-reduced-level (org-outline-level)) ? )
  5201. category (org-get-category beg)
  5202. inherited-tags
  5203. (or (eq org-agenda-show-inherited-tags 'always)
  5204. (and (listp org-agenda-show-inherited-tags)
  5205. (memq 'agenda org-agenda-show-inherited-tags))
  5206. (and (eq org-agenda-show-inherited-tags t)
  5207. (or (eq org-agenda-use-tag-inheritance t)
  5208. (memq 'agenda org-agenda-use-tag-inheritance))))
  5209. tags (org-get-tags-at nil (not inherited-tags))
  5210. todo-state (org-get-todo-state)
  5211. warntime (get-text-property (point) 'org-appt-warntime)
  5212. extra nil)
  5213. (dolist (r (if (stringp result)
  5214. (list result)
  5215. result)) ;; we expect a list here
  5216. (when (and org-agenda-diary-sexp-prefix
  5217. (string-match org-agenda-diary-sexp-prefix r))
  5218. (setq extra (match-string 0 r)
  5219. r (replace-match "" nil nil r)))
  5220. (if (string-match "\\S-" r)
  5221. (setq txt r)
  5222. (setq txt "SEXP entry returned empty string"))
  5223. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5224. (org-add-props txt props 'org-marker marker
  5225. 'date date 'todo-state todo-state
  5226. 'level level 'type "sexp" 'warntime warntime)
  5227. (push txt ee)))))
  5228. (nreverse ee)))
  5229. ;; Calendar sanity: define some functions that are independent of
  5230. ;; `calendar-date-style'.
  5231. (defun org-anniversary (year month day &optional mark)
  5232. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5233. (with-no-warnings
  5234. (let ((calendar-date-style 'iso))
  5235. (diary-anniversary year month day mark))))
  5236. (defun org-cyclic (N year month day &optional mark)
  5237. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5238. (with-no-warnings
  5239. (let ((calendar-date-style 'iso))
  5240. (diary-cyclic N year month day mark))))
  5241. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5242. "Like `diary-block', but with fixed (ISO) order of arguments."
  5243. (with-no-warnings
  5244. (let ((calendar-date-style 'iso))
  5245. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5246. (defun org-date (year month day &optional mark)
  5247. "Like `diary-date', but with fixed (ISO) order of arguments."
  5248. (with-no-warnings
  5249. (let ((calendar-date-style 'iso))
  5250. (diary-date year month day mark))))
  5251. ;; Define the `org-class' function
  5252. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5253. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5254. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5255. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5256. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5257. `holidays', then any date that is known by the Emacs calendar to be a
  5258. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5259. then those holidays will be skipped."
  5260. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5261. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5262. (d (calendar-absolute-from-gregorian date))
  5263. (h (when skip-weeks (calendar-check-holidays date))))
  5264. (and
  5265. (<= date1 d)
  5266. (<= d date2)
  5267. (= (calendar-day-of-week date) dayname)
  5268. (or (not skip-weeks)
  5269. (progn
  5270. (require 'cal-iso)
  5271. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5272. (not (or (and h (memq 'holidays skip-weeks))
  5273. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5274. entry)))
  5275. (defalias 'org-get-closed 'org-agenda-get-progress)
  5276. (defun org-agenda-get-progress ()
  5277. "Return the logged TODO entries for agenda display."
  5278. (let* ((props (list 'mouse-face 'highlight
  5279. 'org-not-done-regexp org-not-done-regexp
  5280. 'org-todo-regexp org-todo-regexp
  5281. 'org-complex-heading-regexp org-complex-heading-regexp
  5282. 'help-echo
  5283. (format "mouse-2 or RET jump to org file %s"
  5284. (abbreviate-file-name buffer-file-name))))
  5285. (items (if (consp org-agenda-show-log-scoped)
  5286. org-agenda-show-log-scoped
  5287. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5288. '(clock)
  5289. org-agenda-log-mode-items)))
  5290. (parts
  5291. (delq nil
  5292. (list
  5293. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5294. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5295. (if (memq 'state items)
  5296. (format "- State \"%s\".*?" org-todo-regexp)))))
  5297. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5298. (error "`org-agenda-log-mode-items' is empty")))
  5299. (regexp (concat
  5300. "\\(" parts-re "\\)"
  5301. " *\\["
  5302. (regexp-quote
  5303. (substring
  5304. (format-time-string
  5305. (car org-time-stamp-formats)
  5306. (apply 'encode-time ; DATE bound by calendar
  5307. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5308. 1 11))))
  5309. (org-agenda-search-headline-for-time nil)
  5310. marker hdmarker priority category level tags closedp
  5311. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5312. (goto-char (point-min))
  5313. (while (re-search-forward regexp nil t)
  5314. (catch :skip
  5315. (org-agenda-skip)
  5316. (setq marker (org-agenda-new-marker (match-beginning 0))
  5317. closedp (equal (match-string 1) org-closed-string)
  5318. statep (equal (string-to-char (match-string 1)) ?-)
  5319. clockp (not (or closedp statep))
  5320. state (and statep (match-string 2))
  5321. category (org-get-category (match-beginning 0))
  5322. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5323. (when (string-match "\\]" timestr)
  5324. ;; substring should only run to end of time stamp
  5325. (setq rest (substring timestr (match-end 0))
  5326. timestr (substring timestr 0 (match-end 0)))
  5327. (if (and (not closedp) (not statep)
  5328. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5329. rest))
  5330. (progn (setq timestr (concat (substring timestr 0 -1)
  5331. "-" (match-string 1 rest) "]"))
  5332. (setq clocked (match-string 2 rest)))
  5333. (setq clocked "-")))
  5334. (save-excursion
  5335. (setq extra
  5336. (cond
  5337. ((not org-agenda-log-mode-add-notes) nil)
  5338. (statep
  5339. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5340. (match-string 1)))
  5341. (clockp
  5342. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5343. (match-string 1)))))
  5344. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5345. (throw :skip nil)
  5346. (goto-char (match-beginning 0))
  5347. (setq hdmarker (org-agenda-new-marker)
  5348. inherited-tags
  5349. (or (eq org-agenda-show-inherited-tags 'always)
  5350. (and (listp org-agenda-show-inherited-tags)
  5351. (memq 'todo org-agenda-show-inherited-tags))
  5352. (and (eq org-agenda-show-inherited-tags t)
  5353. (or (eq org-agenda-use-tag-inheritance t)
  5354. (memq 'todo org-agenda-use-tag-inheritance))))
  5355. tags (org-get-tags-at nil (not inherited-tags))
  5356. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5357. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5358. (setq txt (match-string 1))
  5359. (when extra
  5360. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5361. (setq txt (concat (substring txt 0 (match-beginning 1))
  5362. " - " extra " " (match-string 2 txt)))
  5363. (setq txt (concat txt " - " extra))))
  5364. (setq txt (org-agenda-format-item
  5365. (cond
  5366. (closedp "Closed: ")
  5367. (statep (concat "State: (" state ")"))
  5368. (t (concat "Clocked: (" clocked ")")))
  5369. txt level category tags timestr)))
  5370. (setq priority 100000)
  5371. (org-add-props txt props
  5372. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5373. 'priority priority 'level level
  5374. 'type "closed" 'date date
  5375. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5376. (push txt ee))
  5377. (goto-char (point-at-eol))))
  5378. (nreverse ee)))
  5379. (defun org-agenda-show-clocking-issues ()
  5380. "Add overlays, showing issues with clocking.
  5381. See also the user option `org-agenda-clock-consistency-checks'."
  5382. (interactive)
  5383. (let* ((pl org-agenda-clock-consistency-checks)
  5384. (re (concat "^[ \t]*"
  5385. org-clock-string
  5386. "[ \t]+"
  5387. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5388. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5389. (tlstart 0.)
  5390. (tlend 0.)
  5391. (maxtime (org-duration-to-minutes
  5392. (or (plist-get pl :max-duration) "24:00")))
  5393. (mintime (org-duration-to-minutes
  5394. (or (plist-get pl :min-duration) 0)))
  5395. (maxgap (org-duration-to-minutes
  5396. ;; default 30:00 means never complain
  5397. (or (plist-get pl :max-gap) "30:00")))
  5398. (gapok (mapcar #'org-duration-to-minutes
  5399. (plist-get pl :gap-ok-around)))
  5400. (def-face (or (plist-get pl :default-face)
  5401. '((:background "DarkRed") (:foreground "white"))))
  5402. issue face m te ts dt ov)
  5403. (goto-char (point-min))
  5404. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5405. (setq issue nil face def-face)
  5406. (catch 'next
  5407. (setq m (org-get-at-bol 'org-marker)
  5408. te nil ts nil)
  5409. (unless (and m (markerp m))
  5410. (setq issue "No valid clock line") (throw 'next t))
  5411. (org-with-point-at m
  5412. (save-excursion
  5413. (goto-char (point-at-bol))
  5414. (unless (looking-at re)
  5415. (error "No valid Clock line")
  5416. (throw 'next t))
  5417. (unless (match-end 3)
  5418. (setq issue "No end time"
  5419. face (or (plist-get pl :no-end-time-face) face))
  5420. (throw 'next t))
  5421. (setq ts (match-string 1)
  5422. te (match-string 3)
  5423. ts (float-time
  5424. (apply #'encode-time (org-parse-time-string ts)))
  5425. te (float-time
  5426. (apply #'encode-time (org-parse-time-string te)))
  5427. dt (- te ts))))
  5428. (cond
  5429. ((> dt (* 60 maxtime))
  5430. ;; a very long clocking chunk
  5431. (setq issue (format "Clocking interval is very long: %s"
  5432. (org-duration-from-minutes (floor (/ dt 60.))))
  5433. face (or (plist-get pl :long-face) face)))
  5434. ((< dt (* 60 mintime))
  5435. ;; a very short clocking chunk
  5436. (setq issue (format "Clocking interval is very short: %s"
  5437. (org-duration-from-minutes (floor (/ dt 60.))))
  5438. face (or (plist-get pl :short-face) face)))
  5439. ((and (> tlend 0) (< ts tlend))
  5440. ;; Two clock entries are overlapping
  5441. (setq issue (format "Clocking overlap: %d minutes"
  5442. (/ (- tlend ts) 60))
  5443. face (or (plist-get pl :overlap-face) face)))
  5444. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5445. ;; There is a gap, lets see if we need to report it
  5446. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5447. (setq issue (format "Clocking gap: %d minutes"
  5448. (/ (- ts tlend) 60))
  5449. face (or (plist-get pl :gap-face) face))))
  5450. (t nil)))
  5451. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5452. (when issue
  5453. ;; OK, there was some issue, add an overlay to show the issue
  5454. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5455. (overlay-put ov 'before-string
  5456. (concat
  5457. (org-add-props
  5458. (format "%-43s" (concat " " issue))
  5459. nil
  5460. 'face face)
  5461. "\n"))
  5462. (overlay-put ov 'evaporate t)))))
  5463. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5464. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5465. (catch 'exit
  5466. (unless ok-list
  5467. ;; there are no OK times for gaps...
  5468. (throw 'exit nil))
  5469. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5470. ;; This is more than 24 hours, so it is OK.
  5471. ;; because we have at least one OK time, that must be in the
  5472. ;; 24 hour interval.
  5473. (throw 'exit t))
  5474. ;; We have a shorter gap.
  5475. ;; Now we have to get the minute of the day when these times are
  5476. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5477. (t2dec (decode-time (seconds-to-time t2)))
  5478. ;; compute the minute on the day
  5479. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5480. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5481. (when (< min2 min1)
  5482. ;; if min2 is smaller than min1, this means it is on the next day.
  5483. ;; Wrap it to after midnight.
  5484. (setq min2 (+ min2 1440)))
  5485. ;; Now check if any of the OK times is in the gap
  5486. (mapc (lambda (x)
  5487. ;; Wrap the time to after midnight if necessary
  5488. (if (< x min1) (setq x (+ x 1440)))
  5489. ;; Check if in interval
  5490. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5491. ok-list)
  5492. ;; Nope, this gap is not OK
  5493. nil)))
  5494. (defun org-agenda-get-deadlines (&optional with-hour)
  5495. "Return the deadline information for agenda display.
  5496. When WITH-HOUR is non-nil, only return deadlines with an hour
  5497. specification like [h]h:mm."
  5498. (let* ((props (list 'mouse-face 'highlight
  5499. 'org-not-done-regexp org-not-done-regexp
  5500. 'org-todo-regexp org-todo-regexp
  5501. 'org-complex-heading-regexp org-complex-heading-regexp
  5502. 'help-echo
  5503. (format "mouse-2 or RET jump to org file %s"
  5504. (abbreviate-file-name buffer-file-name))))
  5505. (regexp (if with-hour
  5506. org-deadline-time-hour-regexp
  5507. org-deadline-time-regexp))
  5508. (today (org-today))
  5509. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5510. (current (calendar-absolute-from-gregorian date))
  5511. deadline-items)
  5512. (goto-char (point-min))
  5513. (while (re-search-forward regexp nil t)
  5514. (catch :skip
  5515. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5516. (org-agenda-skip)
  5517. (let* ((s (match-string 1))
  5518. (pos (1- (match-beginning 1)))
  5519. (todo-state (save-match-data (org-get-todo-state)))
  5520. (done? (member todo-state org-done-keywords))
  5521. (sexp? (string-prefix-p "%%" s))
  5522. ;; DEADLINE is the deadline date for the entry. It is
  5523. ;; either the base date or the last repeat, according
  5524. ;; to `org-agenda-prefer-last-repeat'.
  5525. (deadline
  5526. (cond
  5527. (sexp? (org-agenda--timestamp-to-absolute s current))
  5528. ((or (eq org-agenda-prefer-last-repeat t)
  5529. (member todo-state org-agenda-prefer-last-repeat))
  5530. (org-agenda--timestamp-to-absolute
  5531. s today 'past (current-buffer) pos))
  5532. (t (org-agenda--timestamp-to-absolute s))))
  5533. ;; REPEAT is the future repeat closest from CURRENT,
  5534. ;; according to `org-agenda-show-future-repeats'. If
  5535. ;; the latter is nil, or if the time stamp has no
  5536. ;; repeat part, default to DEADLINE.
  5537. (repeat
  5538. (cond
  5539. (sexp? deadline)
  5540. ((<= current today) deadline)
  5541. ((not org-agenda-show-future-repeats) deadline)
  5542. (t
  5543. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5544. (1+ today)
  5545. current)))
  5546. (org-agenda--timestamp-to-absolute
  5547. s base 'future (current-buffer) pos)))))
  5548. (diff (- deadline current))
  5549. (suppress-prewarning
  5550. (let ((scheduled
  5551. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5552. (org-entry-get nil "SCHEDULED"))))
  5553. (cond
  5554. ((not scheduled) nil)
  5555. ;; The current item has a scheduled date, so
  5556. ;; evaluate its prewarning lead time.
  5557. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5558. ;; Use global prewarning-restart lead time.
  5559. org-agenda-skip-deadline-prewarning-if-scheduled)
  5560. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5561. 'pre-scheduled)
  5562. ;; Set pre-warning to no earlier than SCHEDULED.
  5563. (min (- deadline
  5564. (org-agenda--timestamp-to-absolute scheduled))
  5565. org-deadline-warning-days))
  5566. ;; Set pre-warning to deadline.
  5567. (t 0))))
  5568. (wdays (if suppress-prewarning
  5569. (let ((org-deadline-warning-days suppress-prewarning))
  5570. (org-get-wdays s))
  5571. (org-get-wdays s))))
  5572. (cond
  5573. ;; Only display deadlines at their base date, at future
  5574. ;; repeat occurrences or in today agenda.
  5575. ((= current deadline) nil)
  5576. ((= current repeat) nil)
  5577. ((not today?) (throw :skip nil))
  5578. ;; Upcoming deadline: display within warning period WDAYS.
  5579. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5580. ;; Overdue deadline: warn about it for
  5581. ;; `org-deadline-past-days' duration.
  5582. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5583. ;; Possibly skip done tasks.
  5584. (when (and done?
  5585. (or org-agenda-skip-deadline-if-done
  5586. (/= deadline current)))
  5587. (throw :skip nil))
  5588. (save-excursion
  5589. (re-search-backward "^\\*+[ \t]+" nil t)
  5590. (goto-char (match-end 0))
  5591. (let* ((category (org-get-category))
  5592. (level (make-string (org-reduced-level (org-outline-level))
  5593. ?\s))
  5594. (head (buffer-substring (point) (line-end-position)))
  5595. (inherited-tags
  5596. (or (eq org-agenda-show-inherited-tags 'always)
  5597. (and (listp org-agenda-show-inherited-tags)
  5598. (memq 'agenda org-agenda-show-inherited-tags))
  5599. (and (eq org-agenda-show-inherited-tags t)
  5600. (or (eq org-agenda-use-tag-inheritance t)
  5601. (memq 'agenda
  5602. org-agenda-use-tag-inheritance)))))
  5603. (tags (org-get-tags-at nil (not inherited-tags)))
  5604. (time
  5605. (cond
  5606. ;; No time of day designation if it is only
  5607. ;; a reminder.
  5608. ((and (/= current deadline) (/= current repeat)) nil)
  5609. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5610. (concat (substring s (match-beginning 1)) " "))
  5611. (t 'time)))
  5612. (item
  5613. (org-agenda-format-item
  5614. ;; Insert appropriate suffixes before deadlines.
  5615. ;; Those only apply to today agenda.
  5616. (pcase-let ((`(,now ,future ,past)
  5617. org-agenda-deadline-leaders))
  5618. (cond
  5619. ((and today? (< deadline today)) (format past (- diff)))
  5620. ((and today? (> deadline today)) (format future diff))
  5621. (t now)))
  5622. head level category tags time))
  5623. (face (org-agenda-deadline-face
  5624. (- 1 (/ (float diff) (max wdays 1)))))
  5625. (upcoming? (and today? (> deadline today)))
  5626. (warntime (get-text-property (point) 'org-appt-warntime)))
  5627. (org-add-props item props
  5628. 'org-marker (org-agenda-new-marker pos)
  5629. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5630. 'warntime warntime
  5631. 'level level
  5632. 'ts-date deadline
  5633. 'priority
  5634. ;; Adjust priority to today reminders about deadlines.
  5635. ;; Overdue deadlines get the highest priority
  5636. ;; increase, then imminent deadlines and eventually
  5637. ;; more distant deadlines.
  5638. (let ((adjust (if today? (- diff) 0)))
  5639. (+ adjust (org-get-priority item)))
  5640. 'todo-state todo-state
  5641. 'type (if upcoming? "upcoming-deadline" "deadline")
  5642. 'date (if upcoming? date deadline)
  5643. 'face (if done? 'org-agenda-done face)
  5644. 'undone-face face
  5645. 'done-face 'org-agenda-done)
  5646. (push item deadline-items))))))
  5647. (nreverse deadline-items)))
  5648. (defun org-agenda-deadline-face (fraction)
  5649. "Return the face to displaying a deadline item.
  5650. FRACTION is what fraction of the head-warning time has passed."
  5651. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5652. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5653. "Return the scheduled information for agenda display.
  5654. Optional argument DEADLINES is a list of deadline items to be
  5655. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5656. scheduled items with an hour specification like [h]h:mm."
  5657. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5658. 'org-todo-regexp org-todo-regexp
  5659. 'org-complex-heading-regexp org-complex-heading-regexp
  5660. 'done-face 'org-agenda-done
  5661. 'mouse-face 'highlight
  5662. 'help-echo
  5663. (format "mouse-2 or RET jump to Org file %s"
  5664. (abbreviate-file-name buffer-file-name))))
  5665. (regexp (if with-hour
  5666. org-scheduled-time-hour-regexp
  5667. org-scheduled-time-regexp))
  5668. (today (org-today))
  5669. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5670. (current (calendar-absolute-from-gregorian date))
  5671. (deadline-pos
  5672. (mapcar (lambda (d)
  5673. (let ((m (get-text-property 0 'org-hd-marker d)))
  5674. (and m (marker-position m))))
  5675. deadlines))
  5676. scheduled-items)
  5677. (goto-char (point-min))
  5678. (while (re-search-forward regexp nil t)
  5679. (catch :skip
  5680. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5681. (org-agenda-skip)
  5682. (let* ((s (match-string 1))
  5683. (pos (1- (match-beginning 1)))
  5684. (todo-state (save-match-data (org-get-todo-state)))
  5685. (donep (member todo-state org-done-keywords))
  5686. (sexp? (string-prefix-p "%%" s))
  5687. ;; SCHEDULE is the scheduled date for the entry. It is
  5688. ;; either the bare date or the last repeat, according
  5689. ;; to `org-agenda-prefer-last-repeat'.
  5690. (schedule
  5691. (cond
  5692. (sexp? (org-agenda--timestamp-to-absolute s current))
  5693. ((or (eq org-agenda-prefer-last-repeat t)
  5694. (member todo-state org-agenda-prefer-last-repeat))
  5695. (org-agenda--timestamp-to-absolute
  5696. s today 'past (current-buffer) pos))
  5697. (t (org-agenda--timestamp-to-absolute s))))
  5698. ;; REPEAT is the future repeat closest from CURRENT,
  5699. ;; according to `org-agenda-show-future-repeats'. If
  5700. ;; the latter is nil, or if the time stamp has no
  5701. ;; repeat part, default to SCHEDULE.
  5702. (repeat
  5703. (cond
  5704. (sexp? schedule)
  5705. ((<= current today) schedule)
  5706. ((not org-agenda-show-future-repeats) schedule)
  5707. (t
  5708. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5709. (1+ today)
  5710. current)))
  5711. (org-agenda--timestamp-to-absolute
  5712. s base 'future (current-buffer) pos)))))
  5713. (diff (- current schedule))
  5714. (warntime (get-text-property (point) 'org-appt-warntime))
  5715. (pastschedp (< schedule today))
  5716. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5717. (suppress-delay
  5718. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5719. (org-entry-get nil "DEADLINE"))))
  5720. (cond
  5721. ((not deadline) nil)
  5722. ;; The current item has a deadline date, so
  5723. ;; evaluate its delay time.
  5724. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5725. ;; Use global delay time.
  5726. (- org-agenda-skip-scheduled-delay-if-deadline))
  5727. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5728. 'post-deadline)
  5729. ;; Set delay to no later than DEADLINE.
  5730. (min (- schedule
  5731. (org-agenda--timestamp-to-absolute deadline))
  5732. org-scheduled-delay-days))
  5733. (t 0))))
  5734. (ddays
  5735. (cond
  5736. ;; Nullify delay when a repeater triggered already
  5737. ;; and the delay is of the form --Xd.
  5738. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5739. (> current schedule))
  5740. 0)
  5741. (suppress-delay
  5742. (let ((org-scheduled-delay-days suppress-delay))
  5743. (org-get-wdays s t t)))
  5744. (t (org-get-wdays s t)))))
  5745. ;; Display scheduled items at base date (SCHEDULE), today if
  5746. ;; scheduled before the current date, and at any repeat past
  5747. ;; today. However, skip delayed items and items that have
  5748. ;; been displayed for more than `org-scheduled-past-days'.
  5749. (unless (and todayp
  5750. habitp
  5751. (bound-and-true-p org-habit-show-all-today))
  5752. (when (or (and (> ddays 0) (< diff ddays))
  5753. (> diff org-scheduled-past-days)
  5754. (> schedule current)
  5755. (and (/= current schedule)
  5756. (/= current today)
  5757. (/= current repeat)))
  5758. (throw :skip nil)))
  5759. ;; Possibly skip done tasks.
  5760. (when (and donep
  5761. (or org-agenda-skip-scheduled-if-done
  5762. (/= schedule current)))
  5763. (throw :skip nil))
  5764. ;; Skip entry if it already appears as a deadline, per
  5765. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5766. ;; doesn't apply to habits.
  5767. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5768. ((guard
  5769. (or (not (memq (line-beginning-position 0) deadline-pos))
  5770. habitp))
  5771. nil)
  5772. (`repeated-after-deadline
  5773. (let ((deadline (time-to-days
  5774. (org-get-deadline-time (point)))))
  5775. (and (<= schedule deadline) (> current deadline))))
  5776. (`not-today pastschedp)
  5777. (`t t)
  5778. (_ nil))
  5779. (throw :skip nil))
  5780. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5781. ;; only show them for today. Also skip done habits.
  5782. (when (and habitp
  5783. (or donep
  5784. (not (bound-and-true-p org-habit-show-habits))
  5785. (and (not todayp)
  5786. (bound-and-true-p
  5787. org-habit-show-habits-only-for-today))))
  5788. (throw :skip nil))
  5789. (save-excursion
  5790. (re-search-backward "^\\*+[ \t]+" nil t)
  5791. (goto-char (match-end 0))
  5792. (let* ((category (org-get-category))
  5793. (inherited-tags
  5794. (or (eq org-agenda-show-inherited-tags 'always)
  5795. (and (listp org-agenda-show-inherited-tags)
  5796. (memq 'agenda org-agenda-show-inherited-tags))
  5797. (and (eq org-agenda-show-inherited-tags t)
  5798. (or (eq org-agenda-use-tag-inheritance t)
  5799. (memq 'agenda
  5800. org-agenda-use-tag-inheritance)))))
  5801. (tags (org-get-tags-at nil (not inherited-tags)))
  5802. (level (make-string (org-reduced-level (org-outline-level))
  5803. ?\s))
  5804. (head (buffer-substring (point) (line-end-position)))
  5805. (time
  5806. (cond
  5807. ;; No time of day designation if it is only
  5808. ;; a reminder.
  5809. ((and (/= current schedule) (/= current repeat)) nil)
  5810. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5811. (concat (substring s (match-beginning 1)) " "))
  5812. (t 'time)))
  5813. (item
  5814. (org-agenda-format-item
  5815. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  5816. ;; Show a reminder of a past scheduled today.
  5817. (if (and todayp pastschedp)
  5818. (format past diff)
  5819. first))
  5820. head level category tags time nil habitp))
  5821. (face (cond ((and (not habitp) pastschedp)
  5822. 'org-scheduled-previously)
  5823. (todayp 'org-scheduled-today)
  5824. (t 'org-scheduled)))
  5825. (habitp (and habitp (org-habit-parse-todo))))
  5826. (org-add-props item props
  5827. 'undone-face face
  5828. 'face (if donep 'org-agenda-done face)
  5829. 'org-marker (org-agenda-new-marker pos)
  5830. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5831. 'type (if pastschedp "past-scheduled" "scheduled")
  5832. 'date (if pastschedp schedule date)
  5833. 'ts-date schedule
  5834. 'warntime warntime
  5835. 'level level
  5836. 'priority (if habitp (org-habit-get-priority habitp)
  5837. (+ 99 diff (org-get-priority item)))
  5838. 'org-habit-p habitp
  5839. 'todo-state todo-state)
  5840. (push item scheduled-items))))))
  5841. (nreverse scheduled-items)))
  5842. (defun org-agenda-get-blocks ()
  5843. "Return the date-range information for agenda display."
  5844. (let* ((props (list 'face nil
  5845. 'org-not-done-regexp org-not-done-regexp
  5846. 'org-todo-regexp org-todo-regexp
  5847. 'org-complex-heading-regexp org-complex-heading-regexp
  5848. 'mouse-face 'highlight
  5849. 'help-echo
  5850. (format "mouse-2 or RET jump to org file %s"
  5851. (abbreviate-file-name buffer-file-name))))
  5852. (regexp org-tr-regexp)
  5853. (d0 (calendar-absolute-from-gregorian date))
  5854. marker hdmarker ee txt d1 d2 s1 s2 category
  5855. level todo-state tags pos head donep inherited-tags)
  5856. (goto-char (point-min))
  5857. (while (re-search-forward regexp nil t)
  5858. (catch :skip
  5859. (org-agenda-skip)
  5860. (setq pos (point))
  5861. (let ((start-time (match-string 1))
  5862. (end-time (match-string 2)))
  5863. (setq s1 (match-string 1)
  5864. s2 (match-string 2)
  5865. d1 (time-to-days
  5866. (condition-case err
  5867. (org-time-string-to-time s1)
  5868. (error
  5869. (error
  5870. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5871. s1
  5872. pos
  5873. (current-buffer)
  5874. (error-message-string err)))))
  5875. d2 (time-to-days
  5876. (condition-case err
  5877. (org-time-string-to-time s2)
  5878. (error
  5879. (error
  5880. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  5881. s2
  5882. pos
  5883. (current-buffer)
  5884. (error-message-string err))))))
  5885. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5886. ;; Only allow days between the limits, because the normal
  5887. ;; date stamps will catch the limits.
  5888. (save-excursion
  5889. (setq todo-state (org-get-todo-state))
  5890. (setq donep (member todo-state org-done-keywords))
  5891. (if (and donep org-agenda-skip-timestamp-if-done)
  5892. (throw :skip t))
  5893. (setq marker (org-agenda-new-marker (point))
  5894. category (org-get-category))
  5895. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5896. (throw :skip nil)
  5897. (goto-char (match-beginning 0))
  5898. (setq hdmarker (org-agenda-new-marker (point))
  5899. inherited-tags
  5900. (or (eq org-agenda-show-inherited-tags 'always)
  5901. (and (listp org-agenda-show-inherited-tags)
  5902. (memq 'agenda org-agenda-show-inherited-tags))
  5903. (and (eq org-agenda-show-inherited-tags t)
  5904. (or (eq org-agenda-use-tag-inheritance t)
  5905. (memq 'agenda org-agenda-use-tag-inheritance))))
  5906. tags (org-get-tags-at nil (not inherited-tags)))
  5907. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5908. (looking-at "\\*+[ \t]+\\(.*\\)")
  5909. (setq head (match-string 1))
  5910. (let ((remove-re
  5911. (if org-agenda-remove-timeranges-from-blocks
  5912. (concat
  5913. "<" (regexp-quote s1) ".*?>"
  5914. "--"
  5915. "<" (regexp-quote s2) ".*?>")
  5916. nil)))
  5917. (setq txt (org-agenda-format-item
  5918. (format
  5919. (nth (if (= d1 d2) 0 1)
  5920. org-agenda-timerange-leaders)
  5921. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5922. head level category tags
  5923. (cond ((and (= d1 d0) (= d2 d0))
  5924. (concat "<" start-time ">--<" end-time ">"))
  5925. ((= d1 d0)
  5926. (concat "<" start-time ">"))
  5927. ((= d2 d0)
  5928. (concat "<" end-time ">")))
  5929. remove-re))))
  5930. (org-add-props txt props
  5931. 'org-marker marker 'org-hd-marker hdmarker
  5932. 'type "block" 'date date
  5933. 'level level
  5934. 'todo-state todo-state
  5935. 'priority (org-get-priority txt))
  5936. (push txt ee))))
  5937. (goto-char pos)))
  5938. ;; Sort the entries by expiration date.
  5939. (nreverse ee)))
  5940. ;;; Agenda presentation and sorting
  5941. (defvar org-prefix-has-time nil
  5942. "A flag, set by `org-compile-prefix-format'.
  5943. The flag is set if the currently compiled format contains a `%t'.")
  5944. (defvar org-prefix-has-tag nil
  5945. "A flag, set by `org-compile-prefix-format'.
  5946. The flag is set if the currently compiled format contains a `%T'.")
  5947. (defvar org-prefix-has-effort nil
  5948. "A flag, set by `org-compile-prefix-format'.
  5949. The flag is set if the currently compiled format contains a `%e'.")
  5950. (defvar org-prefix-has-breadcrumbs nil
  5951. "A flag, set by `org-compile-prefix-format'.
  5952. The flag is set if the currently compiled format contains a `%b'.")
  5953. (defvar org-prefix-category-length nil
  5954. "Used by `org-compile-prefix-format' to remember the category field width.")
  5955. (defvar org-prefix-category-max-length nil
  5956. "Used by `org-compile-prefix-format' to remember the category field width.")
  5957. (defun org-agenda-get-category-icon (category)
  5958. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5959. (cl-dolist (entry org-agenda-category-icon-alist)
  5960. (when (string-match-p (car entry) category)
  5961. (if (listp (cadr entry))
  5962. (cl-return (cadr entry))
  5963. (cl-return (apply #'create-image (cdr entry)))))))
  5964. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5965. remove-re habitp)
  5966. "Format TXT to be inserted into the agenda buffer.
  5967. In particular, add the prefix and corresponding text properties.
  5968. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5969. LEVEL may be a string to replace the `%l' specifier.
  5970. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5971. category taken from local variable or file name. It will replace the `%c'
  5972. specifier in the format.
  5973. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5974. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5975. When DOTIME is a string, this string is searched for a time before TXT is.
  5976. TAGS can be the tags of the headline.
  5977. Any match of REMOVE-RE will be removed from TXT."
  5978. ;; We keep the org-prefix-* variable values along with a compiled
  5979. ;; formatter, so that multiple agendas existing at the same time do
  5980. ;; not step on each other toes.
  5981. ;;
  5982. ;; It was inconvenient to make these variables buffer local in
  5983. ;; Agenda buffers, because this function expects to be called with
  5984. ;; the buffer where item comes from being current, and not agenda
  5985. ;; buffer
  5986. (let* ((bindings (car org-prefix-format-compiled))
  5987. (formatter (cadr org-prefix-format-compiled)))
  5988. (cl-loop for (var value) in bindings
  5989. do (set var value))
  5990. (save-match-data
  5991. ;; Diary entries sometimes have extra whitespace at the beginning
  5992. (setq txt (org-trim txt))
  5993. ;; Fix the tags part in txt
  5994. (setq txt (org-agenda-fix-displayed-tags
  5995. txt tags
  5996. org-agenda-show-inherited-tags
  5997. org-agenda-hide-tags-regexp))
  5998. (let* ((category (or category
  5999. (if buffer-file-name
  6000. (file-name-sans-extension
  6001. (file-name-nondirectory buffer-file-name))
  6002. "")))
  6003. (category-icon (org-agenda-get-category-icon category))
  6004. (category-icon (if category-icon
  6005. (propertize " " 'display category-icon)
  6006. ""))
  6007. (effort (and (not (string= txt ""))
  6008. (get-text-property 1 'effort txt)))
  6009. ;; time, tag, effort are needed for the eval of the prefix format
  6010. (tag (if tags (nth (1- (length tags)) tags) ""))
  6011. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6012. time
  6013. (ts (if dotime (concat
  6014. (if (stringp dotime) dotime "")
  6015. (and org-agenda-search-headline-for-time txt))))
  6016. (time-of-day (and dotime (org-get-time-of-day ts)))
  6017. stamp plain s0 s1 s2 rtn srp l
  6018. duration breadcrumbs)
  6019. (and (derived-mode-p 'org-mode) buffer-file-name
  6020. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6021. (when (and dotime time-of-day)
  6022. ;; Extract starting and ending time and move them to prefix
  6023. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6024. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6025. (setq s0 (match-string 0 ts)
  6026. srp (and stamp (match-end 3))
  6027. s1 (match-string (if plain 1 2) ts)
  6028. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6029. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6030. ;; them, we might want to remove them there to avoid duplication.
  6031. ;; The user can turn this off with a variable.
  6032. (if (and org-prefix-has-time
  6033. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6034. (string-match (concat (regexp-quote s0) " *") txt)
  6035. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6036. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6037. (= (match-beginning 0) 0)
  6038. t))
  6039. (setq txt (replace-match "" nil nil txt))))
  6040. ;; Normalize the time(s) to 24 hour
  6041. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6042. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6043. ;; Try to set s2 if s1 and
  6044. ;; `org-agenda-default-appointment-duration' are set
  6045. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6046. (setq s2
  6047. (org-duration-from-minutes
  6048. (+ (org-duration-to-minutes s1 t)
  6049. org-agenda-default-appointment-duration)
  6050. nil t)))
  6051. ;; Compute the duration
  6052. (when s2
  6053. (setq duration (- (org-duration-to-minutes s2)
  6054. (org-duration-to-minutes s1)))))
  6055. (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6056. ;; Tags are in the string
  6057. (if (or (eq org-agenda-remove-tags t)
  6058. (and org-agenda-remove-tags
  6059. org-prefix-has-tag))
  6060. (setq txt (replace-match "" t t txt))
  6061. (setq txt (replace-match
  6062. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6063. (match-string 2 txt))
  6064. t t txt))))
  6065. (when remove-re
  6066. (while (string-match remove-re txt)
  6067. (setq txt (replace-match "" t t txt))))
  6068. ;; Set org-heading property on `txt' to mark the start of the
  6069. ;; heading.
  6070. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6071. ;; Prepare the variables needed in the eval of the compiled format
  6072. (if org-prefix-has-breadcrumbs
  6073. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6074. (let ((s (org-display-outline-path nil nil "->" t)))
  6075. (if (eq "" s) "" (concat s "->"))))))
  6076. (setq time (cond (s2 (concat
  6077. (org-agenda-time-of-day-to-ampm-maybe s1)
  6078. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6079. (if org-agenda-timegrid-use-ampm " ")))
  6080. (s1 (concat
  6081. (org-agenda-time-of-day-to-ampm-maybe s1)
  6082. (if org-agenda-timegrid-use-ampm
  6083. (concat time-grid-trailing-characters " ")
  6084. time-grid-trailing-characters)))
  6085. (t ""))
  6086. extra (or (and (not habitp) extra) "")
  6087. category (if (symbolp category) (symbol-name category) category)
  6088. level (or level ""))
  6089. (if (string-match org-bracket-link-regexp category)
  6090. (progn
  6091. (setq l (if (match-end 3)
  6092. (- (match-end 3) (match-beginning 3))
  6093. (- (match-end 1) (match-beginning 1))))
  6094. (when (< l (or org-prefix-category-length 0))
  6095. (setq category (copy-sequence category))
  6096. (org-add-props category nil
  6097. 'extra-space (make-string
  6098. (- org-prefix-category-length l 1) ?\ ))))
  6099. (if (and org-prefix-category-max-length
  6100. (>= (length category) org-prefix-category-max-length))
  6101. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6102. ;; Evaluate the compiled format
  6103. (setq rtn (concat (eval formatter) txt))
  6104. ;; And finally add the text properties
  6105. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6106. (org-add-props rtn nil
  6107. 'org-category category
  6108. 'tags (mapcar 'org-downcase-keep-props tags)
  6109. 'org-highest-priority org-highest-priority
  6110. 'org-lowest-priority org-lowest-priority
  6111. 'time-of-day time-of-day
  6112. 'duration duration
  6113. 'breadcrumbs breadcrumbs
  6114. 'txt txt
  6115. 'level level
  6116. 'time time
  6117. 'extra extra
  6118. 'format org-prefix-format-compiled
  6119. 'dotime dotime)))))
  6120. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6121. "Remove tags string from TXT, and add a modified list of tags.
  6122. The modified list may contain inherited tags, and tags matched by
  6123. `org-agenda-hide-tags-regexp' will be removed."
  6124. (when (or add-inherited hide-re)
  6125. (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6126. (setq txt (substring txt 0 (match-beginning 0))))
  6127. (setq tags
  6128. (delq nil
  6129. (mapcar (lambda (tg)
  6130. (if (or (and hide-re (string-match hide-re tg))
  6131. (and (not add-inherited)
  6132. (get-text-property 0 'inherited tg)))
  6133. nil
  6134. tg))
  6135. tags)))
  6136. (when tags
  6137. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6138. i)
  6139. (setq txt (concat txt " :"
  6140. (mapconcat
  6141. (lambda (x)
  6142. (setq i (get-text-property 0 'inherited x))
  6143. (if (and have-i (not i))
  6144. (progn
  6145. (setq have-i nil)
  6146. (concat ":" x))
  6147. x))
  6148. tags ":")
  6149. (if have-i "::" ":"))))))
  6150. txt)
  6151. (defun org-downcase-keep-props (s)
  6152. (let ((props (text-properties-at 0 s)))
  6153. (setq s (downcase s))
  6154. (add-text-properties 0 (length s) props s)
  6155. s))
  6156. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6157. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6158. "Add a time-grid for agenda items which need it.
  6159. LIST is the list of agenda items formatted by `org-agenda-list'.
  6160. NDAYS is the span of the current agenda view.
  6161. TODAYP is t when the current agenda view is on today."
  6162. (catch 'exit
  6163. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6164. ((and todayp (member 'today (car org-agenda-time-grid))))
  6165. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6166. ((member 'weekly (car org-agenda-time-grid)))
  6167. (t (throw 'exit list)))
  6168. (let* ((have (delq nil (mapcar
  6169. (lambda (x) (get-text-property 1 'time-of-day x))
  6170. list)))
  6171. (string (nth 3 org-agenda-time-grid))
  6172. (gridtimes (nth 1 org-agenda-time-grid))
  6173. (req (car org-agenda-time-grid))
  6174. (remove (member 'remove-match req))
  6175. new time)
  6176. (if (and (member 'require-timed req) (not have))
  6177. ;; don't show empty grid
  6178. (throw 'exit list))
  6179. (while (setq time (pop gridtimes))
  6180. (unless (and remove (member time have))
  6181. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6182. (push (org-agenda-format-item
  6183. nil string nil "" nil
  6184. (concat (substring time 0 -2) ":" (substring time -2)))
  6185. new)
  6186. (put-text-property
  6187. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6188. (when (and todayp org-agenda-show-current-time-in-grid)
  6189. (push (org-agenda-format-item
  6190. nil org-agenda-current-time-string nil "" nil
  6191. (format-time-string "%H:%M "))
  6192. new)
  6193. (put-text-property
  6194. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6195. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6196. (append new list)
  6197. (append list new)))))
  6198. (defun org-compile-prefix-format (key)
  6199. "Compile the prefix format into a Lisp form that can be evaluated.
  6200. The resulting form and associated variable bindings is returned
  6201. and stored in the variable `org-prefix-format-compiled'."
  6202. (setq org-prefix-has-time nil
  6203. org-prefix-has-tag nil
  6204. org-prefix-category-length nil
  6205. org-prefix-has-effort nil
  6206. org-prefix-has-breadcrumbs nil)
  6207. (let ((s (cond
  6208. ((stringp org-agenda-prefix-format)
  6209. org-agenda-prefix-format)
  6210. ((assq key org-agenda-prefix-format)
  6211. (cdr (assq key org-agenda-prefix-format)))
  6212. (t " %-12:c%?-12t% s")))
  6213. (start 0)
  6214. varform vars var e c f opt)
  6215. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6216. s start)
  6217. (setq var (or (cdr (assoc (match-string 4 s)
  6218. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6219. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6220. 'eval)
  6221. c (or (match-string 3 s) "")
  6222. opt (match-beginning 1)
  6223. start (1+ (match-beginning 0)))
  6224. (if (eq var 'time) (setq org-prefix-has-time t))
  6225. (if (eq var 'tag) (setq org-prefix-has-tag t))
  6226. (if (eq var 'effort) (setq org-prefix-has-effort t))
  6227. (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6228. (setq f (concat "%" (match-string 2 s) "s"))
  6229. (when (eq var 'category)
  6230. (setq org-prefix-category-length
  6231. (floor (abs (string-to-number (match-string 2 s)))))
  6232. (setq org-prefix-category-max-length
  6233. (let ((x (match-string 2 s)))
  6234. (save-match-data
  6235. (if (string-match "\\.[0-9]+" x)
  6236. (string-to-number (substring (match-string 0 x) 1)))))))
  6237. (if (eq var 'eval)
  6238. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6239. (if opt
  6240. (setq varform
  6241. `(if (or (equal "" ,var) (equal nil ,var))
  6242. ""
  6243. (format ,f (concat ,var ,c))))
  6244. (setq varform
  6245. `(format ,f (if (or (equal ,var "")
  6246. (equal ,var nil)) ""
  6247. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6248. (setq s (replace-match "%s" t nil s))
  6249. (push varform vars))
  6250. (setq vars (nreverse vars))
  6251. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6252. (setq org-prefix-format-compiled
  6253. (list
  6254. `((org-prefix-has-time ,org-prefix-has-time)
  6255. (org-prefix-has-tag ,org-prefix-has-tag)
  6256. (org-prefix-category-length ,org-prefix-category-length)
  6257. (org-prefix-has-effort ,org-prefix-has-effort)
  6258. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6259. `(format ,s ,@vars))))))
  6260. (defun org-set-sorting-strategy (key)
  6261. (if (symbolp (car org-agenda-sorting-strategy))
  6262. ;; the old format
  6263. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6264. (setq org-agenda-sorting-strategy-selected
  6265. (or (cdr (assq key org-agenda-sorting-strategy))
  6266. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6267. '(time-up category-keep priority-down)))))
  6268. (defun org-get-time-of-day (s &optional string mod24)
  6269. "Check string S for a time of day.
  6270. If found, return it as a military time number between 0 and 2400.
  6271. If not found, return nil.
  6272. The optional STRING argument forces conversion into a 5 character wide string
  6273. HH:MM."
  6274. (save-match-data
  6275. (when
  6276. (and
  6277. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6278. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6279. (not (eq (get-text-property 1 'face s) 'org-link)))
  6280. (let* ((h (string-to-number (match-string 1 s)))
  6281. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6282. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6283. (am-p (equal ampm "am"))
  6284. (h1 (cond ((not ampm) h)
  6285. ((= h 12) (if am-p 0 12))
  6286. (t (+ h (if am-p 0 12)))))
  6287. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6288. (mod h1 24) h1))
  6289. (t0 (+ (* 100 h2) m))
  6290. (t1 (concat (if (>= h1 24) "+" " ")
  6291. (if (and org-agenda-time-leading-zero
  6292. (< t0 1000)) "0" "")
  6293. (if (< t0 100) "0" "")
  6294. (if (< t0 10) "0" "")
  6295. (int-to-string t0))))
  6296. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6297. (defvar org-agenda-before-sorting-filter-function nil
  6298. "Function to be applied to agenda items prior to sorting.
  6299. Prior to sorting also means just before they are inserted into the agenda.
  6300. To aid sorting, you may revisit the original entries and add more text
  6301. properties which will later be used by the sorting functions.
  6302. The function should take a string argument, an agenda line.
  6303. It has access to the text properties in that line, which contain among
  6304. other things, the property `org-hd-marker' that points to the entry
  6305. where the line comes from. Note that not all lines going into the agenda
  6306. have this property, only most.
  6307. The function should return the modified string. It is probably best
  6308. to ONLY change text properties.
  6309. You can also use this function as a filter, by returning nil for lines
  6310. you don't want to have in the agenda at all. For this application, you
  6311. could bind the variable in the options section of a custom command.")
  6312. (defun org-agenda-finalize-entries (list &optional type)
  6313. "Sort, limit and concatenate the LIST of agenda items.
  6314. The optional argument TYPE tells the agenda type."
  6315. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6316. (cdr (assoc type org-agenda-max-effort)))
  6317. (t org-agenda-max-effort)))
  6318. (max-todo (cond ((listp org-agenda-max-todos)
  6319. (cdr (assoc type org-agenda-max-todos)))
  6320. (t org-agenda-max-todos)))
  6321. (max-tags (cond ((listp org-agenda-max-tags)
  6322. (cdr (assoc type org-agenda-max-tags)))
  6323. (t org-agenda-max-tags)))
  6324. (max-entries (cond ((listp org-agenda-max-entries)
  6325. (cdr (assoc type org-agenda-max-entries)))
  6326. (t org-agenda-max-entries))))
  6327. (when org-agenda-before-sorting-filter-function
  6328. (setq list
  6329. (delq nil
  6330. (mapcar
  6331. org-agenda-before-sorting-filter-function list))))
  6332. (setq list (mapcar 'org-agenda-highlight-todo list)
  6333. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6334. (when max-effort
  6335. (setq list (org-agenda-limit-entries
  6336. list 'effort-minutes max-effort
  6337. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6338. 32767 -1))))))
  6339. (when max-todo
  6340. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6341. (when max-tags
  6342. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6343. (when max-entries
  6344. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6345. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  6346. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  6347. (mapconcat 'identity list "\n")))
  6348. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6349. "Limit the number of agenda entries."
  6350. (let ((include (and limit (< limit 0))))
  6351. (if limit
  6352. (let ((fun (or fn (lambda (p) (if p 1))))
  6353. (lim 0))
  6354. (delq nil
  6355. (mapcar
  6356. (lambda (e)
  6357. (let ((pval (funcall
  6358. fun (get-text-property (1- (length e))
  6359. prop e))))
  6360. (if pval (setq lim (+ lim pval)))
  6361. (cond ((and pval (<= lim (abs limit))) e)
  6362. ((and include (not pval)) e))))
  6363. list)))
  6364. list)))
  6365. (defun org-agenda-limit-interactively (remove)
  6366. "In agenda, interactively limit entries to various maximums."
  6367. (interactive "P")
  6368. (if remove
  6369. (progn (setq org-agenda-max-entries nil
  6370. org-agenda-max-todos nil
  6371. org-agenda-max-tags nil
  6372. org-agenda-max-effort nil)
  6373. (org-agenda-redo))
  6374. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6375. (msg (cond ((= max ?E) "How many minutes? ")
  6376. ((= max ?e) "How many entries? ")
  6377. ((= max ?t) "How many TODO entries? ")
  6378. ((= max ?T) "How many tagged entries? ")
  6379. (t (user-error "Wrong input"))))
  6380. (num (string-to-number (read-from-minibuffer msg))))
  6381. (cond ((equal max ?e)
  6382. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6383. ((equal max ?t)
  6384. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6385. ((equal max ?T)
  6386. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6387. ((equal max ?E)
  6388. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6389. (org-agenda-fit-window-to-buffer))
  6390. (defun org-agenda-highlight-todo (x)
  6391. (let ((org-done-keywords org-done-keywords-for-agenda)
  6392. (case-fold-search nil)
  6393. re)
  6394. (if (eq x 'line)
  6395. (save-excursion
  6396. (beginning-of-line 1)
  6397. (setq re (org-get-at-bol 'org-todo-regexp))
  6398. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6399. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6400. (add-text-properties (match-beginning 0) (match-end 1)
  6401. (list 'face (org-get-todo-face 1)))
  6402. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6403. (delete-region (match-beginning 1) (1- (match-end 0)))
  6404. (goto-char (match-beginning 1))
  6405. (insert (format org-agenda-todo-keyword-format s)))))
  6406. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6407. (setq re (get-text-property 0 'org-todo-regexp x))
  6408. (when (and re
  6409. ;; Test `pl' because if there's no heading content,
  6410. ;; there's no point matching to highlight. Note
  6411. ;; that if we didn't test `pl' first, and there
  6412. ;; happened to be no keyword from `org-todo-regexp'
  6413. ;; on this heading line, then the `equal' comparison
  6414. ;; afterwards would spuriously succeed in the case
  6415. ;; where `pl' is nil -- causing an args-out-of-range
  6416. ;; error when we try to add text properties to text
  6417. ;; that isn't there.
  6418. pl
  6419. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6420. x pl) pl))
  6421. (add-text-properties
  6422. (or (match-end 1) (match-end 0)) (match-end 0)
  6423. (list 'face (org-get-todo-face (match-string 2 x)))
  6424. x)
  6425. (when (match-end 1)
  6426. (setq x
  6427. (concat
  6428. (substring x 0 (match-end 1))
  6429. (format org-agenda-todo-keyword-format
  6430. (match-string 2 x))
  6431. ;; Remove `display' property as the icon could leak
  6432. ;; on the white space.
  6433. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  6434. 'display))
  6435. (substring x (match-end 3)))))))
  6436. x)))
  6437. (defsubst org-cmp-values (a b property)
  6438. "Compare the numeric value of text PROPERTY for string A and B."
  6439. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6440. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6441. (cond ((> pa pb) +1)
  6442. ((< pa pb) -1))))
  6443. (defsubst org-cmp-effort (a b)
  6444. "Compare the effort values of string A and B."
  6445. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6446. ;; `effort-minutes' property is not directly accessible from
  6447. ;; the strings, but is stored as a property in `txt'.
  6448. (ea (or (get-text-property
  6449. 0 'effort-minutes (get-text-property 0 'txt a))
  6450. def))
  6451. (eb (or (get-text-property
  6452. 0 'effort-minutes (get-text-property 0 'txt b))
  6453. def)))
  6454. (cond ((> ea eb) +1)
  6455. ((< ea eb) -1))))
  6456. (defsubst org-cmp-category (a b)
  6457. "Compare the string values of categories of strings A and B."
  6458. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6459. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6460. (cond ((string-lessp ca cb) -1)
  6461. ((string-lessp cb ca) +1))))
  6462. (defsubst org-cmp-todo-state (a b)
  6463. "Compare the todo states of strings A and B."
  6464. (let* ((ma (or (get-text-property 1 'org-marker a)
  6465. (get-text-property 1 'org-hd-marker a)))
  6466. (mb (or (get-text-property 1 'org-marker b)
  6467. (get-text-property 1 'org-hd-marker b)))
  6468. (fa (and ma (marker-buffer ma)))
  6469. (fb (and mb (marker-buffer mb)))
  6470. (todo-kwds
  6471. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6472. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6473. (ta (or (get-text-property 1 'todo-state a) ""))
  6474. (tb (or (get-text-property 1 'todo-state b) ""))
  6475. (la (- (length (member ta todo-kwds))))
  6476. (lb (- (length (member tb todo-kwds))))
  6477. (donepa (member ta org-done-keywords-for-agenda))
  6478. (donepb (member tb org-done-keywords-for-agenda)))
  6479. (cond ((and donepa (not donepb)) -1)
  6480. ((and (not donepa) donepb) +1)
  6481. ((< la lb) -1)
  6482. ((< lb la) +1))))
  6483. (defsubst org-cmp-alpha (a b)
  6484. "Compare the headlines, alphabetically."
  6485. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6486. (plb (text-property-any 0 (length b) 'org-heading t b))
  6487. (ta (and pla (substring a pla)))
  6488. (tb (and plb (substring b plb)))
  6489. (case-fold-search nil))
  6490. (when pla
  6491. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6492. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6493. (setq ta (substring ta (match-end 0))))
  6494. (setq ta (downcase ta)))
  6495. (when plb
  6496. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6497. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6498. (setq tb (substring tb (match-end 0))))
  6499. (setq tb (downcase tb)))
  6500. (cond ((not ta) +1)
  6501. ((not tb) -1)
  6502. ((string-lessp ta tb) -1)
  6503. ((string-lessp tb ta) +1))))
  6504. (defsubst org-cmp-tag (a b)
  6505. "Compare the string values of the first tags of A and B."
  6506. (let ((ta (car (last (get-text-property 1 'tags a))))
  6507. (tb (car (last (get-text-property 1 'tags b)))))
  6508. (cond ((not ta) +1)
  6509. ((not tb) -1)
  6510. ((string-lessp ta tb) -1)
  6511. ((string-lessp tb ta) +1))))
  6512. (defsubst org-cmp-time (a b)
  6513. "Compare the time-of-day values of strings A and B."
  6514. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6515. (ta (or (get-text-property 1 'time-of-day a) def))
  6516. (tb (or (get-text-property 1 'time-of-day b) def)))
  6517. (cond ((< ta tb) -1)
  6518. ((< tb ta) +1))))
  6519. (defsubst org-cmp-ts (a b type)
  6520. "Compare the timestamps values of entries A and B.
  6521. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6522. \"timestamp_ia\", compare within each of these type. When TYPE
  6523. is the empty string, compare all timestamps without respect of
  6524. their type."
  6525. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6526. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6527. (get-text-property 1 'ts-date a))
  6528. def))
  6529. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6530. (get-text-property 1 'ts-date b))
  6531. def)))
  6532. (cond ((< ta tb) -1)
  6533. ((< tb ta) +1))))
  6534. (defsubst org-cmp-habit-p (a b)
  6535. "Compare the todo states of strings A and B."
  6536. (let ((ha (get-text-property 1 'org-habit-p a))
  6537. (hb (get-text-property 1 'org-habit-p b)))
  6538. (cond ((and ha (not hb)) -1)
  6539. ((and (not ha) hb) +1))))
  6540. (defun org-entries-lessp (a b)
  6541. "Predicate for sorting agenda entries."
  6542. ;; The following variables will be used when the form is evaluated.
  6543. ;; So even though the compiler complains, keep them.
  6544. (let* ((ss org-agenda-sorting-strategy-selected)
  6545. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6546. (org-cmp-ts a b "")))
  6547. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6548. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6549. (org-cmp-ts a b "scheduled")))
  6550. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6551. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6552. (org-cmp-ts a b "deadline")))
  6553. (deadline-down (if deadline-up (- deadline-up) nil))
  6554. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6555. (org-cmp-ts a b "timestamp_ia")))
  6556. (tsia-down (if tsia-up (- tsia-up) nil))
  6557. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6558. (org-cmp-ts a b "timestamp")))
  6559. (ts-down (if ts-up (- ts-up) nil))
  6560. (time-up (and (org-em 'time-up 'time-down ss)
  6561. (org-cmp-time a b)))
  6562. (time-down (if time-up (- time-up) nil))
  6563. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6564. (org-cmp-values a b 'org-stats)))
  6565. (stats-down (if stats-up (- stats-up) nil))
  6566. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6567. (org-cmp-values a b 'priority)))
  6568. (priority-down (if priority-up (- priority-up) nil))
  6569. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6570. (org-cmp-effort a b)))
  6571. (effort-down (if effort-up (- effort-up) nil))
  6572. (category-up (and (or (org-em 'category-up 'category-down ss)
  6573. (memq 'category-keep ss))
  6574. (org-cmp-category a b)))
  6575. (category-down (if category-up (- category-up) nil))
  6576. (category-keep (if category-up +1 nil))
  6577. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6578. (org-cmp-tag a b)))
  6579. (tag-down (if tag-up (- tag-up) nil))
  6580. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6581. (org-cmp-todo-state a b)))
  6582. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6583. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6584. (org-cmp-habit-p a b)))
  6585. (habit-down (if habit-up (- habit-up) nil))
  6586. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6587. (org-cmp-alpha a b)))
  6588. (alpha-down (if alpha-up (- alpha-up) nil))
  6589. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6590. user-defined-up user-defined-down)
  6591. (if (and need-user-cmp org-agenda-cmp-user-defined
  6592. (functionp org-agenda-cmp-user-defined))
  6593. (setq user-defined-up
  6594. (funcall org-agenda-cmp-user-defined a b)
  6595. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6596. (cdr (assoc
  6597. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6598. '((-1 . t) (1 . nil) (nil . nil))))))
  6599. ;;; Agenda restriction lock
  6600. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6601. "Overlay to mark the headline to which agenda commands are restricted.")
  6602. (overlay-put org-agenda-restriction-lock-overlay
  6603. 'face 'org-agenda-restriction-lock)
  6604. (overlay-put org-agenda-restriction-lock-overlay
  6605. 'help-echo "Agendas are currently limited to this subtree.")
  6606. (delete-overlay org-agenda-restriction-lock-overlay)
  6607. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  6608. "Set the restriction lock to the agenda item at point from within the agenda.
  6609. When called with a `\\[universal-argument]' prefix, restrict to
  6610. the file which contains the item.
  6611. Argument ARG is the prefix argument."
  6612. (interactive "P")
  6613. (unless (derived-mode-p 'org-agenda-mode)
  6614. (user-error "Not in an Org agenda buffer"))
  6615. (let* ((marker (or (org-get-at-bol 'org-marker)
  6616. (org-agenda-error)))
  6617. (buffer (marker-buffer marker))
  6618. (pos (marker-position marker)))
  6619. (with-current-buffer buffer
  6620. (goto-char pos)
  6621. (org-agenda-set-restriction-lock arg))))
  6622. ;;;###autoload
  6623. (defun org-agenda-set-restriction-lock (&optional type)
  6624. "Set restriction lock for agenda, to current subtree or file.
  6625. Restriction will be the file if TYPE is `file', or if type is the
  6626. universal prefix \\='(4), or if the cursor is before the first headline
  6627. in the file. Otherwise, restriction will be to the current subtree."
  6628. (interactive "P")
  6629. (org-agenda-remove-restriction-lock 'noupdate)
  6630. (and (equal type '(4)) (setq type 'file))
  6631. (setq type (cond
  6632. (type type)
  6633. ((org-at-heading-p) 'subtree)
  6634. ((condition-case nil (org-back-to-heading t) (error nil))
  6635. 'subtree)
  6636. (t 'file)))
  6637. (if (eq type 'subtree)
  6638. (progn
  6639. (setq org-agenda-restrict (current-buffer))
  6640. (setq org-agenda-overriding-restriction 'subtree)
  6641. (put 'org-agenda-files 'org-restrict
  6642. (list (buffer-file-name (buffer-base-buffer))))
  6643. (org-back-to-heading t)
  6644. (move-overlay org-agenda-restriction-lock-overlay
  6645. (point)
  6646. (if org-agenda-restriction-lock-highlight-subtree
  6647. (save-excursion (org-end-of-subtree t t) (point))
  6648. (point-at-eol)))
  6649. (move-marker org-agenda-restrict-begin (point))
  6650. (move-marker org-agenda-restrict-end
  6651. (save-excursion (org-end-of-subtree t t)))
  6652. (message "Locking agenda restriction to subtree"))
  6653. (put 'org-agenda-files 'org-restrict
  6654. (list (buffer-file-name (buffer-base-buffer))))
  6655. (setq org-agenda-restrict nil)
  6656. (setq org-agenda-overriding-restriction 'file)
  6657. (move-marker org-agenda-restrict-begin nil)
  6658. (move-marker org-agenda-restrict-end nil)
  6659. (message "Locking agenda restriction to file"))
  6660. (setq current-prefix-arg nil)
  6661. (org-agenda-maybe-redo))
  6662. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6663. "Remove the agenda restriction lock."
  6664. (interactive "P")
  6665. (delete-overlay org-agenda-restriction-lock-overlay)
  6666. (delete-overlay org-speedbar-restriction-lock-overlay)
  6667. (setq org-agenda-overriding-restriction nil)
  6668. (setq org-agenda-restrict nil)
  6669. (put 'org-agenda-files 'org-restrict nil)
  6670. (move-marker org-agenda-restrict-begin nil)
  6671. (move-marker org-agenda-restrict-end nil)
  6672. (setq current-prefix-arg nil)
  6673. (message "Agenda restriction lock removed")
  6674. (or noupdate (org-agenda-maybe-redo)))
  6675. (defun org-agenda-maybe-redo ()
  6676. "If there is any window showing the agenda view, update it."
  6677. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6678. org-agenda-buffer-name)
  6679. t))
  6680. (w0 (selected-window)))
  6681. (when w
  6682. (select-window w)
  6683. (org-agenda-redo)
  6684. (select-window w0)
  6685. (if org-agenda-overriding-restriction
  6686. (message "Agenda view shifted to new %s restriction"
  6687. org-agenda-overriding-restriction)
  6688. (message "Agenda restriction lock removed")))))
  6689. ;;; Agenda commands
  6690. (defun org-agenda-check-type (error &rest types)
  6691. "Check if agenda buffer is of allowed type.
  6692. If ERROR is non-nil, throw an error, otherwise just return nil.
  6693. Allowed types are `agenda' `todo' `tags' `search'."
  6694. (cond ((not org-agenda-type)
  6695. (error "No Org agenda currently displayed"))
  6696. ((memq org-agenda-type types) t)
  6697. (error
  6698. (error "Not allowed in %s-type agenda buffers" org-agenda-type))
  6699. (t nil)))
  6700. (defun org-agenda-Quit ()
  6701. "Exit the agenda, killing the agenda buffer.
  6702. Like `org-agenda-quit', but kill the buffer even when
  6703. `org-agenda-sticky' is non-nil."
  6704. (interactive)
  6705. (org-agenda--quit))
  6706. (defun org-agenda-quit ()
  6707. "Exit the agenda.
  6708. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6709. instead of killing it.
  6710. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6711. the pre-agenda window configuration.
  6712. When column view is active, exit column view instead of the
  6713. agenda."
  6714. (interactive)
  6715. (org-agenda--quit org-agenda-sticky))
  6716. (defun org-agenda--quit (&optional bury)
  6717. (if org-agenda-columns-active
  6718. (org-columns-quit)
  6719. (let ((wconf org-agenda-pre-window-conf)
  6720. (buf (current-buffer))
  6721. (org-agenda-last-indirect-window
  6722. (and (eq org-indirect-buffer-display 'other-window)
  6723. org-agenda-last-indirect-buffer
  6724. (get-buffer-window org-agenda-last-indirect-buffer))))
  6725. (cond
  6726. ((eq org-agenda-window-setup 'other-frame)
  6727. (delete-frame))
  6728. ((and org-agenda-restore-windows-after-quit
  6729. wconf)
  6730. ;; Maybe restore the pre-agenda window configuration. Reset
  6731. ;; `org-agenda-pre-window-conf' before running
  6732. ;; `set-window-configuration', which loses the current buffer.
  6733. (setq org-agenda-pre-window-conf nil)
  6734. (set-window-configuration wconf))
  6735. (t
  6736. (when org-agenda-last-indirect-window
  6737. (delete-window org-agenda-last-indirect-window))
  6738. (and (not (eq org-agenda-window-setup 'current-window))
  6739. (not (one-window-p))
  6740. (delete-window))))
  6741. (if bury
  6742. ;; Set the agenda buffer as the current buffer instead of
  6743. ;; passing it as an argument to `bury-buffer' so that
  6744. ;; `bury-buffer' removes it from the window.
  6745. (with-current-buffer buf
  6746. (bury-buffer))
  6747. (kill-buffer buf)
  6748. (setq org-agenda-archives-mode nil
  6749. org-agenda-buffer nil)))))
  6750. (defun org-agenda-exit ()
  6751. "Exit the agenda, killing Org buffers loaded by the agenda.
  6752. Like `org-agenda-Quit', but kill any buffers that were created by
  6753. the agenda. Org buffers visited directly by the user will not be
  6754. touched. Also, exit the agenda even if it is in column view."
  6755. (interactive)
  6756. (when org-agenda-columns-active
  6757. (org-columns-quit))
  6758. (org-release-buffers org-agenda-new-buffers)
  6759. (setq org-agenda-new-buffers nil)
  6760. (org-agenda-Quit))
  6761. (defun org-agenda-kill-all-agenda-buffers ()
  6762. "Kill all buffers in `org-agenda-mode'.
  6763. This is used when toggling sticky agendas."
  6764. (interactive)
  6765. (let (blist)
  6766. (dolist (buf (buffer-list))
  6767. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6768. (push buf blist)))
  6769. (mapc 'kill-buffer blist)))
  6770. (defun org-agenda-execute (arg)
  6771. "Execute another agenda command, keeping same window.
  6772. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6773. in the agenda."
  6774. (interactive "P")
  6775. (let ((org-agenda-window-setup 'current-window))
  6776. (org-agenda arg)))
  6777. (defun org-agenda-redo (&optional all)
  6778. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6779. (interactive "P")
  6780. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6781. (cpa (unless (eq all t) current-prefix-arg))
  6782. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6783. (org-agenda-sticky nil)
  6784. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6785. org-agenda-buffer-name))
  6786. (org-agenda-keep-modes t)
  6787. (tag-filter org-agenda-tag-filter)
  6788. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6789. (top-hl-filter org-agenda-top-headline-filter)
  6790. (cat-filter org-agenda-category-filter)
  6791. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6792. (re-filter org-agenda-regexp-filter)
  6793. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6794. (effort-filter org-agenda-effort-filter)
  6795. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6796. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6797. (cols org-agenda-columns-active)
  6798. (line (org-current-line))
  6799. (window-line (- line (org-current-line (window-start))))
  6800. (lprops org-agenda-lprops)
  6801. (redo-cmd (get-text-property p 'org-redo-cmd))
  6802. (last-args (get-text-property p 'org-last-args))
  6803. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6804. (org-agenda-overriding-cmd-arguments
  6805. (unless (eq all t)
  6806. (cond ((listp last-args)
  6807. (cons (or cpa (car last-args)) (cdr last-args)))
  6808. ((stringp last-args)
  6809. last-args))))
  6810. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6811. (put 'org-agenda-tag-filter :preset-filter nil)
  6812. (put 'org-agenda-category-filter :preset-filter nil)
  6813. (put 'org-agenda-regexp-filter :preset-filter nil)
  6814. (put 'org-agenda-effort-filter :preset-filter nil)
  6815. (and cols (org-columns-quit))
  6816. (message "Rebuilding agenda buffer...")
  6817. (if series-redo-cmd
  6818. (eval series-redo-cmd)
  6819. (org-let lprops redo-cmd))
  6820. (setq org-agenda-undo-list nil
  6821. org-agenda-pending-undo-list nil
  6822. org-agenda-tag-filter tag-filter
  6823. org-agenda-category-filter cat-filter
  6824. org-agenda-regexp-filter re-filter
  6825. org-agenda-effort-filter effort-filter
  6826. org-agenda-top-headline-filter top-hl-filter)
  6827. (message "Rebuilding agenda buffer...done")
  6828. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6829. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6830. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6831. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6832. (let ((tag (or tag-filter tag-preset))
  6833. (cat (or cat-filter cat-preset))
  6834. (effort (or effort-filter effort-preset))
  6835. (re (or re-filter re-preset)))
  6836. (when tag (org-agenda-filter-apply tag 'tag t))
  6837. (when cat (org-agenda-filter-apply cat 'category))
  6838. (when effort (org-agenda-filter-apply effort 'effort))
  6839. (when re (org-agenda-filter-apply re 'regexp)))
  6840. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6841. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6842. (org-goto-line line)
  6843. (recenter window-line)))
  6844. (defun org-agenda-redo-all (&optional exhaustive)
  6845. "Rebuild all agenda views in the current buffer.
  6846. With a prefix argument, do so in all agenda buffers."
  6847. (interactive "P")
  6848. (if exhaustive
  6849. (dolist (buffer (buffer-list))
  6850. (with-current-buffer buffer
  6851. (when (derived-mode-p 'org-agenda-mode)
  6852. (org-agenda-redo t))))
  6853. (org-agenda-redo t)))
  6854. (defvar org-global-tags-completion-table nil)
  6855. (defvar org-agenda-filter-form nil)
  6856. (defvar org-agenda-filtered-by-category nil)
  6857. (defun org-agenda-filter-by-category (strip)
  6858. "Filter lines in the agenda buffer that have a specific category.
  6859. The category is that of the current line.
  6860. Without prefix argument, keep only the lines of that category.
  6861. With a prefix argument, exclude the lines of that category.
  6862. "
  6863. (interactive "P")
  6864. (if (and org-agenda-filtered-by-category
  6865. org-agenda-category-filter)
  6866. (org-agenda-filter-show-all-cat)
  6867. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6868. (cond
  6869. ((and cat strip)
  6870. (org-agenda-filter-apply
  6871. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6872. (cat
  6873. (org-agenda-filter-apply
  6874. (setq org-agenda-category-filter
  6875. (list (concat "+" cat))) 'category))
  6876. (t (error "No category at point"))))))
  6877. (defun org-find-top-headline (&optional pos)
  6878. "Find the topmost parent headline and return it.
  6879. POS when non-nil is the marker or buffer position to start the
  6880. search from."
  6881. (save-excursion
  6882. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  6883. (when pos (goto-char pos))
  6884. ;; Skip up to the topmost parent.
  6885. (while (org-up-heading-safe))
  6886. (ignore-errors (nth 4 (org-heading-components))))))
  6887. (defvar org-agenda-filtered-by-top-headline nil)
  6888. (defun org-agenda-filter-by-top-headline (strip)
  6889. "Keep only those lines that are descendants from the same top headline.
  6890. The top headline is that of the current line."
  6891. (interactive "P")
  6892. (if org-agenda-filtered-by-top-headline
  6893. (progn
  6894. (setq org-agenda-filtered-by-top-headline nil
  6895. org-agenda-top-headline-filter nil)
  6896. (org-agenda-filter-show-all-top-filter))
  6897. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6898. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6899. (error "No top-level headline at point")))))
  6900. (defvar org-agenda-regexp-filter nil)
  6901. (defun org-agenda-filter-by-regexp (strip)
  6902. "Filter agenda entries by a regular expression.
  6903. Regexp filters are cumulative.
  6904. With no prefix argument, keep entries matching the regexp.
  6905. With one prefix argument, filter out entries matching the regexp.
  6906. With two prefix arguments, remove the regexp filters."
  6907. (interactive "P")
  6908. (if (not (equal strip '(16)))
  6909. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6910. (read-from-minibuffer
  6911. (if (equal strip '(4))
  6912. "Filter out entries matching regexp: "
  6913. "Narrow to entries matching regexp: ")))))
  6914. (push flt org-agenda-regexp-filter)
  6915. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6916. (org-agenda-filter-show-all-re)
  6917. (message "Regexp filter removed")))
  6918. (defvar org-agenda-effort-filter nil)
  6919. (defun org-agenda-filter-by-effort (strip)
  6920. "Filter agenda entries by effort.
  6921. With no prefix argument, keep entries matching the effort condition.
  6922. With one prefix argument, filter out entries matching the condition.
  6923. With two prefix arguments, remove the effort filters."
  6924. (interactive "P")
  6925. (cond
  6926. ((member strip '(nil 4))
  6927. (let* ((efforts (split-string
  6928. (or (cdr (assoc (concat org-effort-property "_ALL")
  6929. org-global-properties))
  6930. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6931. ;; XXX: the following handles only up to 10 different
  6932. ;; effort values.
  6933. (allowed-keys (if (null efforts) nil
  6934. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6935. (number-sequence 1 (length efforts)))))
  6936. (op nil))
  6937. (while (not (memq op '(?< ?> ?=)))
  6938. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6939. ;; Select appropriate duration. Ignore non-digit characters.
  6940. (let ((prompt
  6941. (apply #'format
  6942. (concat "Effort %c "
  6943. (mapconcat (lambda (s) (concat "[%d]" s))
  6944. efforts
  6945. " "))
  6946. op allowed-keys))
  6947. (eff -1))
  6948. (while (not (memq eff allowed-keys))
  6949. (message prompt)
  6950. (setq eff (- (read-char-exclusive) 48)))
  6951. (setq org-agenda-effort-filter
  6952. (list (concat (if strip "-" "+")
  6953. (char-to-string op)
  6954. ;; Numbering is 1 2 3 ... 9 0, but we want
  6955. ;; 0 1 2 ... 8 9.
  6956. (nth (mod (1- eff) 10) efforts)))))
  6957. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  6958. (t (org-agenda-filter-show-all-effort)
  6959. (message "Effort filter removed"))))
  6960. (defun org-agenda-filter-remove-all ()
  6961. "Remove all filters from the current agenda buffer."
  6962. (interactive)
  6963. (when org-agenda-tag-filter
  6964. (org-agenda-filter-show-all-tag))
  6965. (when org-agenda-category-filter
  6966. (org-agenda-filter-show-all-cat))
  6967. (when org-agenda-regexp-filter
  6968. (org-agenda-filter-show-all-re))
  6969. (when org-agenda-top-headline-filter
  6970. (org-agenda-filter-show-all-top-filter))
  6971. (when org-agenda-effort-filter
  6972. (org-agenda-filter-show-all-effort))
  6973. (org-agenda-finalize))
  6974. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  6975. "Keep only those lines in the agenda buffer that have a specific tag.
  6976. The tag is selected with its fast selection letter, as configured.
  6977. With a `\\[universal-argument]' prefix, exclude the agenda search.
  6978. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  6979. i.e. don't
  6980. filter on all its group members.
  6981. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  6982. should be used to exclude the search - the interactive user can
  6983. also press `-' or `+' to switch between filtering and excluding."
  6984. (interactive "P")
  6985. (let* ((alist org-tag-alist-for-agenda)
  6986. (tag-chars (mapconcat
  6987. (lambda (x) (if (and (not (symbolp (car x)))
  6988. (cdr x))
  6989. (char-to-string (cdr x))
  6990. ""))
  6991. org-tag-alist-for-agenda ""))
  6992. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  6993. (string-to-list tag-chars)))
  6994. (exclude (or exclude (equal arg '(4))))
  6995. (expand (not (equal arg '(16))))
  6996. (inhibit-read-only t)
  6997. (current org-agenda-tag-filter)
  6998. a n tag)
  6999. (unless char
  7000. (while (not (memq char valid-char-list))
  7001. (message
  7002. "%s by tag [%s ]:tag-char, [TAB]:tag, %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  7003. (if exclude "Exclude" "Filter")
  7004. tag-chars
  7005. (if org-agenda-auto-exclude-function "[RET], " "")
  7006. (if expand "" ", no grouptag expand"))
  7007. (setq char (read-char-exclusive))
  7008. ;; Excluding or filtering down
  7009. (cond ((eq char ?-) (setq exclude t))
  7010. ((eq char ?+) (setq exclude nil)))))
  7011. (when (eq char ?\t)
  7012. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  7013. (setq-local org-global-tags-completion-table
  7014. (org-global-tags-completion-table)))
  7015. (let ((completion-ignore-case t))
  7016. (setq tag (completing-read
  7017. "Tag: " org-global-tags-completion-table nil t))))
  7018. (cond
  7019. ((eq char ?\r)
  7020. (org-agenda-filter-show-all-tag)
  7021. (when org-agenda-auto-exclude-function
  7022. (setq org-agenda-tag-filter nil)
  7023. (dolist (tag (org-agenda-get-represented-tags))
  7024. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7025. (if modifier
  7026. (push modifier org-agenda-tag-filter))))
  7027. (if (not (null org-agenda-tag-filter))
  7028. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7029. ((eq char ?/)
  7030. (org-agenda-filter-show-all-tag)
  7031. (when (get 'org-agenda-tag-filter :preset-filter)
  7032. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7033. ((eq char ?.)
  7034. (setq org-agenda-tag-filter
  7035. (mapcar (lambda(tag) (concat "+" tag))
  7036. (org-get-at-bol 'tags)))
  7037. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7038. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7039. ((or (eq char ?\s)
  7040. (setq a (rassoc char alist))
  7041. (and tag (setq a (cons tag nil))))
  7042. (org-agenda-filter-show-all-tag)
  7043. (setq tag (car a))
  7044. (setq org-agenda-tag-filter
  7045. (cons (concat (if exclude "-" "+") tag)
  7046. current))
  7047. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7048. (t (error "Invalid tag selection character %c" char)))))
  7049. (defun org-agenda-get-represented-tags ()
  7050. "Get a list of all tags currently represented in the agenda."
  7051. (let (p tags)
  7052. (save-excursion
  7053. (goto-char (point-min))
  7054. (while (setq p (next-single-property-change (point) 'tags))
  7055. (goto-char p)
  7056. (mapc (lambda (x) (add-to-list 'tags x))
  7057. (get-text-property (point) 'tags))))
  7058. tags))
  7059. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7060. "Create the form that tests a line for agenda filter. Optional
  7061. argument EXPAND can be used for the TYPE tag and will expand the
  7062. tags in the FILTER if any of the tags in FILTER are grouptags."
  7063. (let (f f1)
  7064. (cond
  7065. ;; Tag filter
  7066. ((eq type 'tag)
  7067. (setq filter
  7068. (delete-dups
  7069. (append (get 'org-agenda-tag-filter :preset-filter)
  7070. filter)))
  7071. (dolist (x filter)
  7072. (let ((op (string-to-char x)))
  7073. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7074. (setq x (list x)))
  7075. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7076. (push f1 f))))
  7077. ;; Category filter
  7078. ((eq type 'category)
  7079. (setq filter
  7080. (delete-dups
  7081. (append (get 'org-agenda-category-filter :preset-filter)
  7082. filter)))
  7083. (dolist (x filter)
  7084. (if (equal "-" (substring x 0 1))
  7085. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7086. (setq f1 (list 'equal (substring x 1) 'cat)))
  7087. (push f1 f)))
  7088. ;; Regexp filter
  7089. ((eq type 'regexp)
  7090. (setq filter
  7091. (delete-dups
  7092. (append (get 'org-agenda-regexp-filter :preset-filter)
  7093. filter)))
  7094. (dolist (x filter)
  7095. (if (equal "-" (substring x 0 1))
  7096. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7097. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7098. (push f1 f)))
  7099. ;; Effort filter
  7100. ((eq type 'effort)
  7101. (setq filter
  7102. (delete-dups
  7103. (append (get 'org-agenda-effort-filter :preset-filter)
  7104. filter)))
  7105. (dolist (x filter)
  7106. (push (org-agenda-filter-effort-form x) f))))
  7107. (cons 'and (nreverse f))))
  7108. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7109. "Return a form associated to tag-expression TAGS.
  7110. Build a form testing a line for agenda filter for
  7111. tag-expressions. OP is an operator of type CHAR that allows the
  7112. function to set the right switches in the returned form."
  7113. (let (form)
  7114. ;; Any of the expressions can match if OP is +, all must match if
  7115. ;; the operator is -.
  7116. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7117. (let* ((tag (substring x 1))
  7118. (f (cond
  7119. ((string= "" tag) '(not tags))
  7120. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7121. ;; TAG is a regexp.
  7122. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7123. (t (list 'member (downcase tag) 'tags)))))
  7124. (push (if (eq op ?-) (list 'not f) f) form)))))
  7125. (defun org-agenda-filter-effort-form (e)
  7126. "Return the form to compare the effort of the current line with what E says.
  7127. E looks like \"+<2:25\"."
  7128. (let (op)
  7129. (setq e (substring e 1))
  7130. (setq op (string-to-char e) e (substring e 1))
  7131. (setq op (cond ((equal op ?<) '<=)
  7132. ((equal op ?>) '>=)
  7133. ((equal op ??) op)
  7134. (t '=)))
  7135. (list 'org-agenda-compare-effort (list 'quote op)
  7136. (org-duration-to-minutes e))))
  7137. (defun org-agenda-compare-effort (op value)
  7138. "Compare the effort of the current line with VALUE, using OP.
  7139. If the line does not have an effort defined, return nil."
  7140. ;; `effort-minutes' property cannot be extracted directly from
  7141. ;; current line but is stored as a property in `txt'.
  7142. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7143. (funcall op
  7144. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7145. value)))
  7146. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7147. "Expand group tags in FILTER for the agenda.
  7148. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7149. (if org-group-tags
  7150. (let ((case-fold-search t) rtn)
  7151. (mapc
  7152. (lambda (f)
  7153. (let (f0 dir)
  7154. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7155. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7156. (setq dir (if no-operator "" "+") f0 f))
  7157. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7158. (org-tags-expand f0 t t))
  7159. rtn))))
  7160. filter)
  7161. (reverse rtn))
  7162. filter))
  7163. (defun org-agenda-filter-apply (filter type &optional expand)
  7164. "Set FILTER as the new agenda filter and apply it. Optional
  7165. argument EXPAND can be used for the TYPE tag and will expand the
  7166. tags in the FILTER if any of the tags in FILTER are grouptags."
  7167. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7168. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7169. (let (tags cat txt)
  7170. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7171. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7172. ;; category is used as the filter:
  7173. (setq org-agenda-filtered-by-category
  7174. (and (eq type 'category)
  7175. (not (equal (substring (car filter) 0 1) "-"))))
  7176. (org-agenda-set-mode-name)
  7177. (save-excursion
  7178. (goto-char (point-min))
  7179. (while (not (eobp))
  7180. (if (org-get-at-bol 'org-marker)
  7181. (progn
  7182. (setq tags (org-get-at-bol 'tags)
  7183. cat (org-get-at-eol 'org-category 1)
  7184. txt (org-get-at-bol 'txt))
  7185. (if (not (eval org-agenda-filter-form))
  7186. (org-agenda-filter-hide-line type))
  7187. (beginning-of-line 2))
  7188. (beginning-of-line 2))))
  7189. (if (get-char-property (point) 'invisible)
  7190. (ignore-errors (org-agenda-previous-line)))))
  7191. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7192. "Filter by top headline HL."
  7193. (org-agenda-set-mode-name)
  7194. (save-excursion
  7195. (goto-char (point-min))
  7196. (while (not (eobp))
  7197. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7198. (tophl (and pos (org-find-top-headline pos))))
  7199. (if (and tophl (funcall (if negative 'identity 'not)
  7200. (string= hl tophl)))
  7201. (org-agenda-filter-hide-line 'top-headline)))
  7202. (beginning-of-line 2)))
  7203. (if (get-char-property (point) 'invisible)
  7204. (org-agenda-previous-line))
  7205. (setq org-agenda-top-headline-filter hl
  7206. org-agenda-filtered-by-top-headline t))
  7207. (defun org-agenda-filter-hide-line (type)
  7208. "Hide lines with TYPE in the agenda buffer."
  7209. (let* ((b (max (point-min) (1- (point-at-bol))))
  7210. (e (point-at-eol)))
  7211. (let ((inhibit-read-only t))
  7212. (add-text-properties
  7213. b e `(invisible org-filtered org-filter-type ,type)))))
  7214. (defun org-agenda-remove-filter (type)
  7215. (interactive)
  7216. "Remove filter of type TYPE from the agenda buffer."
  7217. (save-excursion
  7218. (goto-char (point-min))
  7219. (let ((inhibit-read-only t) pos)
  7220. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7221. (goto-char pos)
  7222. (remove-text-properties
  7223. (point) (next-single-property-change (point) 'org-filter-type)
  7224. `(invisible org-filtered org-filter-type ,type))))
  7225. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7226. (setq org-agenda-filter-form nil)
  7227. (org-agenda-set-mode-name)
  7228. (org-agenda-finalize)))
  7229. (defun org-agenda-filter-show-all-tag nil
  7230. (org-agenda-remove-filter 'tag))
  7231. (defun org-agenda-filter-show-all-re nil
  7232. (org-agenda-remove-filter 'regexp))
  7233. (defun org-agenda-filter-show-all-effort nil
  7234. (org-agenda-remove-filter 'effort))
  7235. (defun org-agenda-filter-show-all-cat nil
  7236. (org-agenda-remove-filter 'category))
  7237. (defun org-agenda-filter-show-all-top-filter nil
  7238. (org-agenda-remove-filter 'top-headline))
  7239. (defun org-agenda-manipulate-query-add ()
  7240. "Manipulate the query by adding a search term with positive selection.
  7241. Positive selection means the term must be matched for selection of an entry."
  7242. (interactive)
  7243. (org-agenda-manipulate-query ?\[))
  7244. (defun org-agenda-manipulate-query-subtract ()
  7245. "Manipulate the query by adding a search term with negative selection.
  7246. Negative selection means term must not be matched for selection of an entry."
  7247. (interactive)
  7248. (org-agenda-manipulate-query ?\]))
  7249. (defun org-agenda-manipulate-query-add-re ()
  7250. "Manipulate the query by adding a search regexp with positive selection.
  7251. Positive selection means the regexp must match for selection of an entry."
  7252. (interactive)
  7253. (org-agenda-manipulate-query ?\{))
  7254. (defun org-agenda-manipulate-query-subtract-re ()
  7255. "Manipulate the query by adding a search regexp with negative selection.
  7256. Negative selection means regexp must not match for selection of an entry."
  7257. (interactive)
  7258. (org-agenda-manipulate-query ?\}))
  7259. (defun org-agenda-manipulate-query (char)
  7260. (cond
  7261. ((eq org-agenda-type 'agenda)
  7262. (let ((org-agenda-include-inactive-timestamps t))
  7263. (org-agenda-redo))
  7264. (message "Display now includes inactive timestamps as well"))
  7265. ((eq org-agenda-type 'search)
  7266. (org-add-to-string
  7267. 'org-agenda-query-string
  7268. (if org-agenda-last-search-view-search-was-boolean
  7269. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7270. (?\{ . " +{}") (?\} . " -{}"))))
  7271. " "))
  7272. (setq org-agenda-redo-command
  7273. (list 'org-search-view
  7274. (car (get-text-property (min (1- (point-max)) (point))
  7275. 'org-last-args))
  7276. org-agenda-query-string
  7277. (+ (length org-agenda-query-string)
  7278. (if (member char '(?\{ ?\})) 0 1))))
  7279. (set-register org-agenda-query-register org-agenda-query-string)
  7280. (let ((org-agenda-overriding-arguments
  7281. (cdr org-agenda-redo-command)))
  7282. (org-agenda-redo)))
  7283. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7284. org-agenda-type))))
  7285. (defun org-add-to-string (var string)
  7286. (set var (concat (symbol-value var) string)))
  7287. (defun org-agenda-goto-date (span)
  7288. "Jump to DATE in agenda."
  7289. (interactive "P")
  7290. (let* ((org-read-date-prefer-future
  7291. (eval org-agenda-jump-prefer-future))
  7292. (date (org-read-date))
  7293. (day (time-to-days (org-time-string-to-time date)))
  7294. (org-agenda-sticky-orig org-agenda-sticky)
  7295. (org-agenda-buffer-tmp-name (buffer-name))
  7296. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7297. (0-arg (or current-prefix-arg (car args)))
  7298. (2-arg (nth 2 args))
  7299. (with-hour-p (nth 4 org-agenda-redo-command))
  7300. (newcmd (list 'org-agenda-list 0-arg date
  7301. (org-agenda-span-to-ndays
  7302. 2-arg (org-time-string-to-absolute date))
  7303. with-hour-p))
  7304. (newargs (cdr newcmd))
  7305. (inhibit-read-only t)
  7306. org-agenda-sticky)
  7307. (if (not (org-agenda-check-type t 'agenda))
  7308. (error "Not available in non-agenda views")
  7309. (add-text-properties (point-min) (point-max)
  7310. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7311. (org-agenda-redo)
  7312. (goto-char (point-min))
  7313. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7314. (save-excursion (move-beginning-of-line 2) (eobp))))
  7315. (move-beginning-of-line 2))
  7316. (setq org-agenda-sticky org-agenda-sticky-orig
  7317. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7318. (defun org-agenda-goto-today ()
  7319. "Go to today."
  7320. (interactive)
  7321. (org-agenda-check-type t 'agenda)
  7322. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7323. (curspan (nth 2 args))
  7324. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7325. (cond
  7326. (tdpos (goto-char tdpos))
  7327. ((eq org-agenda-type 'agenda)
  7328. (let* ((sd (org-agenda-compute-starting-span
  7329. (org-today) (or curspan org-agenda-span)))
  7330. (org-agenda-overriding-arguments args))
  7331. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7332. (org-agenda-redo)
  7333. (org-agenda-find-same-or-today-or-agenda)))
  7334. (t (error "Cannot find today")))))
  7335. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7336. (goto-char
  7337. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7338. (text-property-any (point-min) (point-max) 'org-today t)
  7339. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7340. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7341. (org-agenda-backward-block))
  7342. (point-min))))
  7343. (defun org-agenda-backward-block ()
  7344. "Move backward by one agenda block."
  7345. (interactive)
  7346. (org-agenda-forward-block 'backward))
  7347. (defun org-agenda-forward-block (&optional backward)
  7348. "Move forward by one agenda block.
  7349. When optional argument BACKWARD is set, go backward"
  7350. (interactive)
  7351. (cond ((not (derived-mode-p 'org-agenda-mode))
  7352. (user-error
  7353. "Cannot execute this command outside of org-agenda-mode buffers"))
  7354. ((looking-at (if backward "\\`" "\\'"))
  7355. (message "Already at the %s block" (if backward "first" "last")))
  7356. (t (let ((pos (prog1 (point)
  7357. (ignore-errors (if backward (backward-char 1)
  7358. (move-end-of-line 1)))))
  7359. (f (if backward
  7360. 'previous-single-property-change
  7361. 'next-single-property-change))
  7362. moved dest)
  7363. (while (and (setq dest (funcall
  7364. f (point) 'org-agenda-structural-header))
  7365. (not (get-text-property
  7366. (point) 'org-agenda-structural-header)))
  7367. (setq moved t)
  7368. (goto-char dest))
  7369. (if moved (move-beginning-of-line 1)
  7370. (goto-char (if backward (point-min) (point-max)))
  7371. (move-beginning-of-line 1)
  7372. (message "No %s block" (if backward "previous" "further")))))))
  7373. (defun org-agenda-later (arg)
  7374. "Go forward in time by the current span.
  7375. With prefix ARG, go forward that many times the current span."
  7376. (interactive "p")
  7377. (org-agenda-check-type t 'agenda)
  7378. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7379. (span (or (nth 2 args) org-agenda-current-span))
  7380. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7381. (greg (calendar-gregorian-from-absolute sd))
  7382. (cnt (org-get-at-bol 'org-day-cnt))
  7383. greg2)
  7384. (cond
  7385. ((numberp span)
  7386. (setq sd (+ (* span arg) sd)))
  7387. ((eq span 'day)
  7388. (setq sd (+ arg sd)))
  7389. ((eq span 'week)
  7390. (setq sd (+ (* 7 arg) sd)))
  7391. ((eq span 'fortnight)
  7392. (setq sd (+ (* 14 arg) sd)))
  7393. ((eq span 'month)
  7394. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7395. sd (calendar-absolute-from-gregorian greg2))
  7396. (setcar greg2 (1+ (car greg2))))
  7397. ((eq span 'year)
  7398. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7399. sd (calendar-absolute-from-gregorian greg2))
  7400. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7401. (t
  7402. (setq sd (+ (* span arg) sd))))
  7403. (let ((org-agenda-overriding-cmd
  7404. ;; `cmd' may have been set by `org-agenda-run-series' which
  7405. ;; uses `org-agenda-overriding-cmd' to decide whether
  7406. ;; overriding is allowed for `cmd'
  7407. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7408. (org-agenda-overriding-arguments
  7409. (list (car args) sd span)))
  7410. (org-agenda-redo)
  7411. (org-agenda-find-same-or-today-or-agenda cnt))))
  7412. (defun org-agenda-earlier (arg)
  7413. "Go backward in time by the current span.
  7414. With prefix ARG, go backward that many times the current span."
  7415. (interactive "p")
  7416. (org-agenda-later (- arg)))
  7417. (defun org-agenda-view-mode-dispatch ()
  7418. "Call one of the view mode commands."
  7419. (interactive)
  7420. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7421. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7422. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7423. (pcase (read-char-exclusive)
  7424. (?\ (call-interactively 'org-agenda-reset-view))
  7425. (?d (call-interactively 'org-agenda-day-view))
  7426. (?w (call-interactively 'org-agenda-week-view))
  7427. (?t (call-interactively 'org-agenda-fortnight-view))
  7428. (?m (call-interactively 'org-agenda-month-view))
  7429. (?y (call-interactively 'org-agenda-year-view))
  7430. (?l (call-interactively 'org-agenda-log-mode))
  7431. (?L (org-agenda-log-mode '(4)))
  7432. (?c (org-agenda-log-mode 'clockcheck))
  7433. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7434. (?a (call-interactively 'org-agenda-archives-mode))
  7435. (?A (org-agenda-archives-mode 'files))
  7436. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7437. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7438. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7439. (?D (call-interactively 'org-agenda-toggle-diary))
  7440. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7441. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7442. (org-agenda-check-type t 'agenda)
  7443. (org-agenda-redo))
  7444. (message "Display now includes inactive timestamps as well"))
  7445. (?q (message "Abort"))
  7446. (key (user-error "Invalid key: %s" key))))
  7447. (defun org-agenda-reset-view ()
  7448. "Switch to default view for agenda."
  7449. (interactive)
  7450. (org-agenda-change-time-span org-agenda-span))
  7451. (defun org-agenda-day-view (&optional day-of-month)
  7452. "Switch to daily view for agenda.
  7453. With argument DAY-OF-MONTH, switch to that day of the month."
  7454. (interactive "P")
  7455. (org-agenda-change-time-span 'day day-of-month))
  7456. (defun org-agenda-week-view (&optional iso-week)
  7457. "Switch to weekly view for agenda.
  7458. With argument ISO-WEEK, switch to the corresponding ISO week.
  7459. If ISO-WEEK has more then 2 digits, only the last two encode
  7460. the week. Any digits before this encode a year. So 200712
  7461. means week 12 of year 2007. Years ranging from 70 years ago
  7462. to 30 years in the future can also be written as 2-digit years."
  7463. (interactive "P")
  7464. (org-agenda-change-time-span 'week iso-week))
  7465. (defun org-agenda-fortnight-view (&optional iso-week)
  7466. "Switch to fortnightly view for agenda.
  7467. With argument ISO-WEEK, switch to the corresponding ISO week.
  7468. If ISO-WEEK has more then 2 digits, only the last two encode
  7469. the week. Any digits before this encode a year. So 200712
  7470. means week 12 of year 2007. Years ranging from 70 years ago
  7471. to 30 years in the future can also be written as 2-digit years."
  7472. (interactive "P")
  7473. (org-agenda-change-time-span 'fortnight iso-week))
  7474. (defun org-agenda-month-view (&optional month)
  7475. "Switch to monthly view for agenda.
  7476. With argument MONTH, switch to that month. If MONTH has more
  7477. then 2 digits, only the last two encode the month. Any digits
  7478. before this encode a year. So 200712 means December year 2007.
  7479. Years ranging from 70 years ago to 30 years in the future can
  7480. also be written as 2-digit years."
  7481. (interactive "P")
  7482. (org-agenda-change-time-span 'month month))
  7483. (defun org-agenda-year-view (&optional year)
  7484. "Switch to yearly view for agenda.
  7485. With argument YEAR, switch to that year. Years ranging from 70
  7486. years ago to 30 years in the future can also be written as
  7487. 2-digit years."
  7488. (interactive "P")
  7489. (when year
  7490. (setq year (org-small-year-to-year year)))
  7491. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7492. (org-agenda-change-time-span 'year year)
  7493. (error "Abort")))
  7494. (defun org-agenda-change-time-span (span &optional n)
  7495. "Change the agenda view to SPAN.
  7496. SPAN may be `day', `week', `fortnight', `month', `year'."
  7497. (org-agenda-check-type t 'agenda)
  7498. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7499. (curspan (nth 2 args)))
  7500. (if (and (not n) (equal curspan span))
  7501. (error "Viewing span is already \"%s\"" span))
  7502. (let* ((sd (or (org-get-at-bol 'day)
  7503. (nth 1 args)
  7504. org-starting-day))
  7505. (sd (org-agenda-compute-starting-span sd span n))
  7506. (org-agenda-overriding-cmd
  7507. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7508. (org-agenda-overriding-arguments
  7509. (list (car args) sd span)))
  7510. (org-agenda-redo)
  7511. (org-agenda-find-same-or-today-or-agenda))
  7512. (org-agenda-set-mode-name)
  7513. (message "Switched to %s view" span)))
  7514. (defun org-agenda-compute-starting-span (sd span &optional n)
  7515. "Compute starting date for agenda.
  7516. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7517. is a cons cell with the starting date and the number of days,
  7518. so that the date SD will be in that range."
  7519. (let* ((greg (calendar-gregorian-from-absolute sd))
  7520. (dg (nth 1 greg))
  7521. (mg (car greg))
  7522. (yg (nth 2 greg)))
  7523. (cond
  7524. ((eq span 'day)
  7525. (when n
  7526. (setq sd (+ (calendar-absolute-from-gregorian
  7527. (list mg 1 yg))
  7528. n -1))))
  7529. ((or (eq span 'week) (eq span 'fortnight))
  7530. (let* ((nt (calendar-day-of-week
  7531. (calendar-gregorian-from-absolute sd)))
  7532. (d (if org-agenda-start-on-weekday
  7533. (- nt org-agenda-start-on-weekday)
  7534. 0))
  7535. y1)
  7536. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7537. (when n
  7538. (require 'cal-iso)
  7539. (when (> n 99)
  7540. (setq y1 (org-small-year-to-year (/ n 100))
  7541. n (mod n 100)))
  7542. (setq sd
  7543. (calendar-iso-to-absolute
  7544. (list n 1
  7545. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7546. ((eq span 'month)
  7547. (let (y1)
  7548. (when (and n (> n 99))
  7549. (setq y1 (org-small-year-to-year (/ n 100))
  7550. n (mod n 100)))
  7551. (setq sd (calendar-absolute-from-gregorian
  7552. (list (or n mg) 1 (or y1 yg))))))
  7553. ((eq span 'year)
  7554. (setq sd (calendar-absolute-from-gregorian
  7555. (list 1 1 (or n yg))))))
  7556. sd))
  7557. (defun org-agenda-next-date-line (&optional arg)
  7558. "Jump to the next line indicating a date in agenda buffer."
  7559. (interactive "p")
  7560. (org-agenda-check-type t 'agenda)
  7561. (beginning-of-line 1)
  7562. ;; This does not work if user makes date format that starts with a blank
  7563. (if (looking-at "^\\S-") (forward-char 1))
  7564. (if (not (re-search-forward "^\\S-" nil t arg))
  7565. (progn
  7566. (backward-char 1)
  7567. (error "No next date after this line in this buffer")))
  7568. (goto-char (match-beginning 0)))
  7569. (defun org-agenda-previous-date-line (&optional arg)
  7570. "Jump to the previous line indicating a date in agenda buffer."
  7571. (interactive "p")
  7572. (org-agenda-check-type t 'agenda)
  7573. (beginning-of-line 1)
  7574. (if (not (re-search-backward "^\\S-" nil t arg))
  7575. (error "No previous date before this line in this buffer")))
  7576. ;; Initialize the highlight
  7577. (defvar org-hl (make-overlay 1 1))
  7578. (overlay-put org-hl 'face 'highlight)
  7579. (defun org-highlight (begin end &optional buffer)
  7580. "Highlight a region with overlay."
  7581. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7582. (defun org-unhighlight ()
  7583. "Detach overlay INDEX."
  7584. (delete-overlay org-hl))
  7585. (defun org-unhighlight-once ()
  7586. "Remove the highlight from its position, and this function from the hook."
  7587. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7588. (org-unhighlight))
  7589. (defvar org-agenda-pre-follow-window-conf nil)
  7590. (defun org-agenda-follow-mode ()
  7591. "Toggle follow mode in an agenda buffer."
  7592. (interactive)
  7593. (unless org-agenda-follow-mode
  7594. (setq org-agenda-pre-follow-window-conf
  7595. (current-window-configuration)))
  7596. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7597. (unless org-agenda-follow-mode
  7598. (set-window-configuration org-agenda-pre-follow-window-conf))
  7599. (org-agenda-set-mode-name)
  7600. (org-agenda-do-context-action)
  7601. (message "Follow mode is %s"
  7602. (if org-agenda-follow-mode "on" "off")))
  7603. (defun org-agenda-entry-text-mode (&optional arg)
  7604. "Toggle entry text mode in an agenda buffer."
  7605. (interactive "P")
  7606. (if (or org-agenda-tag-filter
  7607. org-agenda-category-filter
  7608. org-agenda-regexp-filter
  7609. org-agenda-top-headline-filter)
  7610. (user-error "Can't show entry text in filtered views")
  7611. (setq org-agenda-entry-text-mode (or (integerp arg)
  7612. (not org-agenda-entry-text-mode)))
  7613. (org-agenda-entry-text-hide)
  7614. (and org-agenda-entry-text-mode
  7615. (let ((org-agenda-entry-text-maxlines
  7616. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7617. (org-agenda-entry-text-show)))
  7618. (org-agenda-set-mode-name)
  7619. (message "Entry text mode is %s%s"
  7620. (if org-agenda-entry-text-mode "on" "off")
  7621. (if (not org-agenda-entry-text-mode) ""
  7622. (format " (maximum number of lines is %d)"
  7623. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7624. (defun org-agenda-clockreport-mode ()
  7625. "Toggle clocktable mode in an agenda buffer."
  7626. (interactive)
  7627. (org-agenda-check-type t 'agenda)
  7628. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7629. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7630. (org-agenda-set-mode-name)
  7631. (org-agenda-redo)
  7632. (message "Clocktable mode is %s"
  7633. (if org-agenda-clockreport-mode "on" "off")))
  7634. (defun org-agenda-log-mode (&optional special)
  7635. "Toggle log mode in an agenda buffer.
  7636. With argument SPECIAL, show all possible log items, not only the ones
  7637. configured in `org-agenda-log-mode-items'.
  7638. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7639. log items, nothing else."
  7640. (interactive "P")
  7641. (org-agenda-check-type t 'agenda)
  7642. (setq org-agenda-show-log
  7643. (cond
  7644. ((equal special '(16)) 'only)
  7645. ((eq special 'clockcheck)
  7646. (if (eq org-agenda-show-log 'clockcheck)
  7647. nil 'clockcheck))
  7648. (special '(closed clock state))
  7649. (t (not org-agenda-show-log))))
  7650. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7651. (org-agenda-set-mode-name)
  7652. (org-agenda-redo)
  7653. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7654. (defun org-agenda-archives-mode (&optional with-files)
  7655. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7656. When called with a prefix argument, include all archive files as well."
  7657. (interactive "P")
  7658. (setq org-agenda-archives-mode
  7659. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7660. (org-agenda-set-mode-name)
  7661. (org-agenda-redo)
  7662. (message
  7663. "%s"
  7664. (cond
  7665. ((eq org-agenda-archives-mode nil)
  7666. "No archives are included")
  7667. ((eq org-agenda-archives-mode 'trees)
  7668. (format "Trees with :%s: tag are included" org-archive-tag))
  7669. ((eq org-agenda-archives-mode t)
  7670. (format "Trees with :%s: tag and all active archive files are included"
  7671. org-archive-tag)))))
  7672. (defun org-agenda-toggle-diary ()
  7673. "Toggle diary inclusion in an agenda buffer."
  7674. (interactive)
  7675. (org-agenda-check-type t 'agenda)
  7676. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7677. (org-agenda-redo)
  7678. (org-agenda-set-mode-name)
  7679. (message "Diary inclusion turned %s"
  7680. (if org-agenda-include-diary "on" "off")))
  7681. (defun org-agenda-toggle-deadlines ()
  7682. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7683. (interactive)
  7684. (org-agenda-check-type t 'agenda)
  7685. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7686. (org-agenda-redo)
  7687. (org-agenda-set-mode-name)
  7688. (message "Deadlines inclusion turned %s"
  7689. (if org-agenda-include-deadlines "on" "off")))
  7690. (defun org-agenda-toggle-time-grid ()
  7691. "Toggle time grid in an agenda buffer."
  7692. (interactive)
  7693. (org-agenda-check-type t 'agenda)
  7694. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7695. (org-agenda-redo)
  7696. (org-agenda-set-mode-name)
  7697. (message "Time-grid turned %s"
  7698. (if org-agenda-use-time-grid "on" "off")))
  7699. (defun org-agenda-set-mode-name ()
  7700. "Set the mode name to indicate all the small mode settings."
  7701. (setq mode-name
  7702. (list "Org-Agenda"
  7703. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7704. " "
  7705. '(:eval (org-agenda-span-name org-agenda-current-span))
  7706. (if org-agenda-follow-mode " Follow" "")
  7707. (if org-agenda-entry-text-mode " ETxt" "")
  7708. (if org-agenda-include-diary " Diary" "")
  7709. (if org-agenda-include-deadlines " Ddl" "")
  7710. (if org-agenda-use-time-grid " Grid" "")
  7711. (if (and (boundp 'org-habit-show-habits)
  7712. org-habit-show-habits) " Habit" "")
  7713. (cond
  7714. ((consp org-agenda-show-log) " LogAll")
  7715. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7716. (org-agenda-show-log " Log")
  7717. (t ""))
  7718. (if (or org-agenda-category-filter
  7719. (get 'org-agenda-category-filter :preset-filter))
  7720. '(:eval (propertize
  7721. (concat " <"
  7722. (mapconcat
  7723. 'identity
  7724. (append
  7725. (get 'org-agenda-category-filter :preset-filter)
  7726. org-agenda-category-filter)
  7727. "")
  7728. ">")
  7729. 'face 'org-agenda-filter-category
  7730. 'help-echo "Category used in filtering")) "")
  7731. (if (or org-agenda-tag-filter
  7732. (get 'org-agenda-tag-filter :preset-filter))
  7733. '(:eval (propertize
  7734. (concat " {"
  7735. (mapconcat
  7736. 'identity
  7737. (append
  7738. (get 'org-agenda-tag-filter :preset-filter)
  7739. org-agenda-tag-filter)
  7740. "")
  7741. "}")
  7742. 'face 'org-agenda-filter-tags
  7743. 'help-echo "Tags used in filtering")) "")
  7744. (if (or org-agenda-effort-filter
  7745. (get 'org-agenda-effort-filter :preset-filter))
  7746. '(:eval (propertize
  7747. (concat " {"
  7748. (mapconcat
  7749. 'identity
  7750. (append
  7751. (get 'org-agenda-effort-filter :preset-filter)
  7752. org-agenda-effort-filter)
  7753. "")
  7754. "}")
  7755. 'face 'org-agenda-filter-effort
  7756. 'help-echo "Effort conditions used in filtering")) "")
  7757. (if (or org-agenda-regexp-filter
  7758. (get 'org-agenda-regexp-filter :preset-filter))
  7759. '(:eval (propertize
  7760. (concat " ["
  7761. (mapconcat
  7762. 'identity
  7763. (append
  7764. (get 'org-agenda-regexp-filter :preset-filter)
  7765. org-agenda-regexp-filter)
  7766. "")
  7767. "]")
  7768. 'face 'org-agenda-filter-regexp
  7769. 'help-echo "Regexp used in filtering")) "")
  7770. (if org-agenda-archives-mode
  7771. (if (eq org-agenda-archives-mode t)
  7772. " Archives"
  7773. (format " :%s:" org-archive-tag))
  7774. "")
  7775. (if org-agenda-clockreport-mode " Clock" "")))
  7776. (force-mode-line-update))
  7777. (defun org-agenda-update-agenda-type ()
  7778. "Update the agenda type after each command."
  7779. (setq org-agenda-type
  7780. (or (get-text-property (point) 'org-agenda-type)
  7781. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7782. (defun org-agenda-next-line ()
  7783. "Move cursor to the next line, and show if follow mode is active."
  7784. (interactive)
  7785. (call-interactively 'next-line)
  7786. (org-agenda-do-context-action))
  7787. (defun org-agenda-previous-line ()
  7788. "Move cursor to the previous line, and show if follow-mode is active."
  7789. (interactive)
  7790. (call-interactively 'previous-line)
  7791. (org-agenda-do-context-action))
  7792. (defun org-agenda-next-item (n)
  7793. "Move cursor to next agenda item."
  7794. (interactive "p")
  7795. (let ((col (current-column)))
  7796. (dotimes (c n)
  7797. (when (next-single-property-change (point-at-eol) 'org-marker)
  7798. (move-end-of-line 1)
  7799. (goto-char (next-single-property-change (point) 'org-marker))))
  7800. (org-move-to-column col))
  7801. (org-agenda-do-context-action))
  7802. (defun org-agenda-previous-item (n)
  7803. "Move cursor to next agenda item."
  7804. (interactive "p")
  7805. (dotimes (c n)
  7806. (let ((col (current-column))
  7807. (goto (save-excursion
  7808. (move-end-of-line 0)
  7809. (previous-single-property-change (point) 'org-marker))))
  7810. (if goto (goto-char goto))
  7811. (org-move-to-column col)))
  7812. (org-agenda-do-context-action))
  7813. (defun org-agenda-do-context-action ()
  7814. "Show outline path and, maybe, follow mode window."
  7815. (let ((m (org-get-at-bol 'org-marker)))
  7816. (when (and (markerp m) (marker-buffer m))
  7817. (and org-agenda-follow-mode
  7818. (if org-agenda-follow-indirect
  7819. (org-agenda-tree-to-indirect-buffer nil)
  7820. (org-agenda-show)))
  7821. (and org-agenda-show-outline-path
  7822. (org-with-point-at m (org-display-outline-path t))))))
  7823. (defun org-agenda-show-tags ()
  7824. "Show the tags applicable to the current item."
  7825. (interactive)
  7826. (let* ((tags (org-get-at-bol 'tags)))
  7827. (if tags
  7828. (message "Tags are :%s:"
  7829. (org-no-properties (mapconcat 'identity tags ":")))
  7830. (message "No tags associated with this line"))))
  7831. (defun org-agenda-goto (&optional highlight)
  7832. "Go to the entry at point in the corresponding Org file."
  7833. (interactive)
  7834. (let* ((marker (or (org-get-at-bol 'org-marker)
  7835. (org-agenda-error)))
  7836. (buffer (marker-buffer marker))
  7837. (pos (marker-position marker)))
  7838. (switch-to-buffer-other-window buffer)
  7839. (widen)
  7840. (push-mark)
  7841. (goto-char pos)
  7842. (when (derived-mode-p 'org-mode)
  7843. (org-show-context 'agenda)
  7844. (recenter (/ (window-height) 2))
  7845. (org-back-to-heading t)
  7846. (let ((case-fold-search nil))
  7847. (when (re-search-forward org-complex-heading-regexp nil t)
  7848. (goto-char (match-beginning 4)))))
  7849. (run-hooks 'org-agenda-after-show-hook)
  7850. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7851. (defvar org-agenda-after-show-hook nil
  7852. "Normal hook run after an item has been shown from the agenda.
  7853. Point is in the buffer where the item originated.")
  7854. (defun org-agenda-kill ()
  7855. "Kill the entry or subtree belonging to the current agenda entry."
  7856. (interactive)
  7857. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7858. (let* ((bufname-orig (buffer-name))
  7859. (marker (or (org-get-at-bol 'org-marker)
  7860. (org-agenda-error)))
  7861. (buffer (marker-buffer marker))
  7862. (pos (marker-position marker))
  7863. (type (org-get-at-bol 'type))
  7864. dbeg dend (n 0) conf)
  7865. (org-with-remote-undo buffer
  7866. (with-current-buffer buffer
  7867. (save-excursion
  7868. (goto-char pos)
  7869. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7870. (setq dbeg (progn (org-back-to-heading t) (point))
  7871. dend (org-end-of-subtree t t))
  7872. (setq dbeg (point-at-bol)
  7873. dend (min (point-max) (1+ (point-at-eol)))))
  7874. (goto-char dbeg)
  7875. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7876. (setq conf (or (eq t org-agenda-confirm-kill)
  7877. (and (numberp org-agenda-confirm-kill)
  7878. (> n org-agenda-confirm-kill))))
  7879. (and conf
  7880. (not (y-or-n-p
  7881. (format "Delete entry with %d lines in buffer \"%s\"? "
  7882. n (buffer-name buffer))))
  7883. (error "Abort"))
  7884. (let ((org-agenda-buffer-name bufname-orig))
  7885. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7886. (with-current-buffer buffer (delete-region dbeg dend))
  7887. (message "Agenda item and source killed"))))
  7888. (defvar org-archive-default-command) ; defined in org-archive.el
  7889. (defun org-agenda-archive-default ()
  7890. "Archive the entry or subtree belonging to the current agenda entry."
  7891. (interactive)
  7892. (require 'org-archive)
  7893. (org-agenda-archive-with org-archive-default-command))
  7894. (defun org-agenda-archive-default-with-confirmation ()
  7895. "Archive the entry or subtree belonging to the current agenda entry."
  7896. (interactive)
  7897. (require 'org-archive)
  7898. (org-agenda-archive-with org-archive-default-command 'confirm))
  7899. (defun org-agenda-archive ()
  7900. "Archive the entry or subtree belonging to the current agenda entry."
  7901. (interactive)
  7902. (org-agenda-archive-with 'org-archive-subtree))
  7903. (defun org-agenda-archive-to-archive-sibling ()
  7904. "Move the entry to the archive sibling."
  7905. (interactive)
  7906. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7907. (defun org-agenda-archive-with (cmd &optional confirm)
  7908. "Move the entry to the archive sibling."
  7909. (interactive)
  7910. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7911. (let* ((bufname-orig (buffer-name))
  7912. (marker (or (org-get-at-bol 'org-marker)
  7913. (org-agenda-error)))
  7914. (buffer (marker-buffer marker))
  7915. (pos (marker-position marker)))
  7916. (org-with-remote-undo buffer
  7917. (with-current-buffer buffer
  7918. (if (derived-mode-p 'org-mode)
  7919. (if (and confirm
  7920. (not (y-or-n-p "Archive this subtree or entry? ")))
  7921. (error "Abort")
  7922. (save-window-excursion
  7923. (goto-char pos)
  7924. (let ((org-agenda-buffer-name bufname-orig))
  7925. (org-remove-subtree-entries-from-agenda))
  7926. (org-back-to-heading t)
  7927. (funcall cmd)))
  7928. (error "Archiving works only in Org files"))))))
  7929. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7930. "Remove all lines in the agenda that correspond to a given subtree.
  7931. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7932. If this information is not given, the function uses the tree at point."
  7933. (let ((buf (or buf (current-buffer))) m p)
  7934. (save-excursion
  7935. (unless (and beg end)
  7936. (org-back-to-heading t)
  7937. (setq beg (point))
  7938. (org-end-of-subtree t)
  7939. (setq end (point)))
  7940. (set-buffer (get-buffer org-agenda-buffer-name))
  7941. (save-excursion
  7942. (goto-char (point-max))
  7943. (beginning-of-line 1)
  7944. (while (not (bobp))
  7945. (when (and (setq m (org-get-at-bol 'org-marker))
  7946. (equal buf (marker-buffer m))
  7947. (setq p (marker-position m))
  7948. (>= p beg)
  7949. (< p end))
  7950. (let ((inhibit-read-only t))
  7951. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7952. (beginning-of-line 0))))))
  7953. (defun org-agenda-refile (&optional goto rfloc no-update)
  7954. "Refile the item at point.
  7955. When called with `\\[universal-argument] \\[universal-argument]', \
  7956. go to the location of the last
  7957. refiled item.
  7958. When called with `\\[universal-argument] \\[universal-argument] \
  7959. \\[universal-argument]' prefix or when GOTO is 0, clear
  7960. the refile cache.
  7961. RFLOC can be a refile location obtained in a different way.
  7962. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7963. (interactive "P")
  7964. (cond
  7965. ((member goto '(0 (64)))
  7966. (org-refile-cache-clear))
  7967. ((equal goto '(16))
  7968. (org-refile-goto-last-stored))
  7969. (t
  7970. (let* ((buffer-orig (buffer-name))
  7971. (marker (or (org-get-at-bol 'org-hd-marker)
  7972. (org-agenda-error)))
  7973. (buffer (marker-buffer marker))
  7974. (pos (marker-position marker))
  7975. (rfloc (or rfloc
  7976. (org-refile-get-location
  7977. (if goto "Goto" "Refile to") buffer
  7978. org-refile-allow-creating-parent-nodes))))
  7979. (with-current-buffer buffer
  7980. (org-with-wide-buffer
  7981. (goto-char marker)
  7982. (let ((org-agenda-buffer-name buffer-orig))
  7983. (org-remove-subtree-entries-from-agenda))
  7984. (org-refile goto buffer rfloc))))
  7985. (unless no-update (org-agenda-redo)))))
  7986. (defun org-agenda-open-link (&optional arg)
  7987. "Open the link(s) in the current entry, if any.
  7988. This looks for a link in the displayed line in the agenda.
  7989. It also looks at the text of the entry itself."
  7990. (interactive "P")
  7991. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7992. (org-get-at-bol 'org-marker)))
  7993. (buffer (and marker (marker-buffer marker)))
  7994. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7995. (lkall (and buffer (org-offer-links-in-entry
  7996. buffer marker arg prefix)))
  7997. (lk0 (car lkall))
  7998. (lk (if (stringp lk0) (list lk0) lk0))
  7999. (lkend (cdr lkall))
  8000. trg)
  8001. (cond
  8002. ((and buffer lk)
  8003. (mapcar (lambda(l)
  8004. (with-current-buffer buffer
  8005. (setq trg (and (string-match org-bracket-link-regexp l)
  8006. (match-string 1 l)))
  8007. (if (or (not trg) (string-match org-any-link-re trg))
  8008. (org-with-wide-buffer
  8009. (goto-char marker)
  8010. (when (search-forward l nil lkend)
  8011. (goto-char (match-beginning 0))
  8012. (org-open-at-point)))
  8013. ;; This is an internal link, widen the buffer
  8014. (switch-to-buffer-other-window buffer)
  8015. (widen)
  8016. (goto-char marker)
  8017. (when (search-forward l nil lkend)
  8018. (goto-char (match-beginning 0))
  8019. (org-open-at-point)))))
  8020. lk))
  8021. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  8022. (save-excursion
  8023. (beginning-of-line 1)
  8024. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  8025. (org-open-link-from-string (match-string 1)))
  8026. (t (message "No link to open here")))))
  8027. (defun org-agenda-copy-local-variable (var)
  8028. "Get a variable from a referenced buffer and install it here."
  8029. (let ((m (org-get-at-bol 'org-marker)))
  8030. (when (and m (buffer-live-p (marker-buffer m)))
  8031. (set (make-local-variable var)
  8032. (with-current-buffer (marker-buffer m)
  8033. (symbol-value var))))))
  8034. (defun org-agenda-switch-to (&optional delete-other-windows)
  8035. "Go to the Org mode file which contains the item at point.
  8036. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8037. displayed Org file fills the frame."
  8038. (interactive)
  8039. (if (and org-return-follows-link
  8040. (not (org-get-at-bol 'org-marker))
  8041. (org-in-regexp org-bracket-link-regexp))
  8042. (org-open-link-from-string (match-string 0))
  8043. (let* ((marker (or (org-get-at-bol 'org-marker)
  8044. (org-agenda-error)))
  8045. (buffer (marker-buffer marker))
  8046. (pos (marker-position marker)))
  8047. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8048. (pop-to-buffer-same-window buffer)
  8049. (when delete-other-windows (delete-other-windows))
  8050. (widen)
  8051. (goto-char pos)
  8052. (when (derived-mode-p 'org-mode)
  8053. (org-show-context 'agenda)
  8054. (run-hooks 'org-agenda-after-show-hook)))))
  8055. (defun org-agenda-goto-mouse (ev)
  8056. "Go to the Org file which contains the item at the mouse click."
  8057. (interactive "e")
  8058. (mouse-set-point ev)
  8059. (org-agenda-goto))
  8060. (defun org-agenda-show (&optional full-entry)
  8061. "Display the Org file which contains the item at point.
  8062. With prefix argument FULL-ENTRY, make the entire entry visible
  8063. if it was hidden in the outline."
  8064. (interactive "P")
  8065. (let ((win (selected-window)))
  8066. (org-agenda-goto t)
  8067. (when full-entry (org-show-entry))
  8068. (select-window win)))
  8069. (defvar org-agenda-show-window nil)
  8070. (defun org-agenda-show-and-scroll-up (&optional arg)
  8071. "Display the Org file which contains the item at point.
  8072. When called repeatedly, scroll the window that is displaying the buffer.
  8073. With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
  8074. `outline-show-subtree'
  8075. to display the item, so that drawers and logbooks stay folded."
  8076. (interactive "P")
  8077. (let ((win (selected-window)))
  8078. (if (and (window-live-p org-agenda-show-window)
  8079. (eq this-command last-command))
  8080. (progn
  8081. (select-window org-agenda-show-window)
  8082. (ignore-errors (scroll-up)))
  8083. (org-agenda-goto t)
  8084. (if arg (org-show-entry) (outline-show-subtree))
  8085. (setq org-agenda-show-window (selected-window)))
  8086. (select-window win)))
  8087. (defun org-agenda-show-scroll-down ()
  8088. "Scroll down the window showing the agenda."
  8089. (interactive)
  8090. (let ((win (selected-window)))
  8091. (when (window-live-p org-agenda-show-window)
  8092. (select-window org-agenda-show-window)
  8093. (ignore-errors (scroll-down))
  8094. (select-window win))))
  8095. (defun org-agenda-show-1 (&optional more)
  8096. "Display the Org file which contains the item at point.
  8097. The prefix arg selects the amount of information to display:
  8098. 0 hide the subtree
  8099. 1 just show the entry according to defaults.
  8100. 2 show the children view
  8101. 3 show the subtree view
  8102. 4 show the entire subtree and any LOGBOOK drawers
  8103. 5 show the entire subtree and any drawers
  8104. With prefix argument FULL-ENTRY, make the entire entry visible
  8105. if it was hidden in the outline."
  8106. (interactive "p")
  8107. (let ((win (selected-window)))
  8108. (org-agenda-goto t)
  8109. (org-back-to-heading)
  8110. (set-window-start (selected-window) (point-at-bol))
  8111. (cond
  8112. ((= more 0)
  8113. (outline-hide-subtree)
  8114. (save-excursion
  8115. (org-back-to-heading)
  8116. (run-hook-with-args 'org-cycle-hook 'folded))
  8117. (message "Remote: FOLDED"))
  8118. ((and (called-interactively-p 'any) (= more 1))
  8119. (message "Remote: show with default settings"))
  8120. ((= more 2)
  8121. (outline-show-entry)
  8122. (org-show-children)
  8123. (save-excursion
  8124. (org-back-to-heading)
  8125. (run-hook-with-args 'org-cycle-hook 'children))
  8126. (message "Remote: CHILDREN"))
  8127. ((= more 3)
  8128. (outline-show-subtree)
  8129. (save-excursion
  8130. (org-back-to-heading)
  8131. (run-hook-with-args 'org-cycle-hook 'subtree))
  8132. (message "Remote: SUBTREE"))
  8133. ((= more 4)
  8134. (outline-show-subtree)
  8135. (save-excursion
  8136. (org-back-to-heading)
  8137. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8138. (message "Remote: SUBTREE AND LOGBOOK"))
  8139. ((> more 4)
  8140. (outline-show-subtree)
  8141. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8142. (select-window win)))
  8143. (defvar org-agenda-cycle-counter nil)
  8144. (defun org-agenda-cycle-show (&optional n)
  8145. "Show the current entry in another window, with default settings.
  8146. Default settings are taken from `org-show-context-detail'. When
  8147. use repeatedly in immediate succession, the remote entry will
  8148. cycle through visibility
  8149. children -> subtree -> folded
  8150. When called with a numeric prefix arg, that arg will be passed through to
  8151. `org-agenda-show-1'. For the interpretation of that argument, see the
  8152. docstring of `org-agenda-show-1'."
  8153. (interactive "P")
  8154. (if (integerp n)
  8155. (setq org-agenda-cycle-counter n)
  8156. (if (not (eq last-command this-command))
  8157. (setq org-agenda-cycle-counter 1)
  8158. (if (equal org-agenda-cycle-counter 0)
  8159. (setq org-agenda-cycle-counter 2)
  8160. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8161. (if (> org-agenda-cycle-counter 3)
  8162. (setq org-agenda-cycle-counter 0)))))
  8163. (org-agenda-show-1 org-agenda-cycle-counter))
  8164. (defun org-agenda-recenter (arg)
  8165. "Display the Org file which contains the item at point and recenter."
  8166. (interactive "P")
  8167. (let ((win (selected-window)))
  8168. (org-agenda-goto t)
  8169. (recenter arg)
  8170. (select-window win)))
  8171. (defun org-agenda-show-mouse (ev)
  8172. "Display the Org file which contains the item at the mouse click."
  8173. (interactive "e")
  8174. (mouse-set-point ev)
  8175. (org-agenda-show))
  8176. (defun org-agenda-check-no-diary ()
  8177. "Check if the entry is a diary link and abort if yes."
  8178. (if (org-get-at-bol 'org-agenda-diary-link)
  8179. (org-agenda-error)))
  8180. (defun org-agenda-error ()
  8181. "Throw an error when a command is not allowed in the agenda."
  8182. (user-error "Command not allowed in this line"))
  8183. (defun org-agenda-tree-to-indirect-buffer (arg)
  8184. "Show the subtree corresponding to the current entry in an indirect buffer.
  8185. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8186. With a numerical prefix ARG, go up to this level and then take that tree.
  8187. With a negative numeric ARG, go up by this number of levels.
  8188. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8189. i.e. don't use
  8190. the dedicated frame."
  8191. (interactive "P")
  8192. (if current-prefix-arg
  8193. (org-agenda-do-tree-to-indirect-buffer arg)
  8194. (let ((agenda-buffer (buffer-name))
  8195. (agenda-window (selected-window))
  8196. (indirect-window
  8197. (and org-last-indirect-buffer
  8198. (get-buffer-window org-last-indirect-buffer))))
  8199. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8200. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8201. (eq org-indirect-buffer-display 'dedicated-frame))
  8202. (unwind-protect
  8203. (unless (and indirect-window (window-live-p indirect-window))
  8204. (setq indirect-window (split-window agenda-window)))
  8205. (and indirect-window (select-window indirect-window))
  8206. (switch-to-buffer org-last-indirect-buffer :norecord)
  8207. (fit-window-to-buffer indirect-window)))
  8208. (select-window (get-buffer-window agenda-buffer))
  8209. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8210. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8211. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8212. (org-agenda-check-no-diary)
  8213. (let* ((marker (or (org-get-at-bol 'org-marker)
  8214. (org-agenda-error)))
  8215. (buffer (marker-buffer marker))
  8216. (pos (marker-position marker)))
  8217. (with-current-buffer buffer
  8218. (save-excursion
  8219. (goto-char pos)
  8220. (funcall 'org-tree-to-indirect-buffer arg)))))
  8221. (defvar org-last-heading-marker (make-marker)
  8222. "Marker pointing to the headline that last changed its TODO state
  8223. by a remote command from the agenda.")
  8224. (defun org-agenda-todo-nextset ()
  8225. "Switch TODO entry to next sequence."
  8226. (interactive)
  8227. (org-agenda-todo 'nextset))
  8228. (defun org-agenda-todo-previousset ()
  8229. "Switch TODO entry to previous sequence."
  8230. (interactive)
  8231. (org-agenda-todo 'previousset))
  8232. (defun org-agenda-todo (&optional arg)
  8233. "Cycle TODO state of line at point, also in Org file.
  8234. This changes the line at point, all other lines in the agenda referring to
  8235. the same tree node, and the headline of the tree node in the Org file."
  8236. (interactive "P")
  8237. (org-agenda-check-no-diary)
  8238. (let* ((col (current-column))
  8239. (marker (or (org-get-at-bol 'org-marker)
  8240. (org-agenda-error)))
  8241. (buffer (marker-buffer marker))
  8242. (pos (marker-position marker))
  8243. (hdmarker (org-get-at-bol 'org-hd-marker))
  8244. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8245. (inhibit-read-only t)
  8246. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8247. (org-with-remote-undo buffer
  8248. (with-current-buffer buffer
  8249. (widen)
  8250. (goto-char pos)
  8251. (org-show-context 'agenda)
  8252. (let ((current-prefix-arg arg))
  8253. (call-interactively 'org-todo))
  8254. (and (bolp) (forward-char 1))
  8255. (setq newhead (org-get-heading))
  8256. (when (and (bound-and-true-p
  8257. org-agenda-headline-snapshot-before-repeat)
  8258. (not (equal org-agenda-headline-snapshot-before-repeat
  8259. newhead))
  8260. todayp)
  8261. (setq newhead org-agenda-headline-snapshot-before-repeat
  8262. just-one t))
  8263. (save-excursion
  8264. (org-back-to-heading)
  8265. (move-marker org-last-heading-marker (point))))
  8266. (beginning-of-line 1)
  8267. (save-window-excursion
  8268. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8269. (when (bound-and-true-p org-clock-out-when-done)
  8270. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8271. newhead)
  8272. (org-agenda-unmark-clocking-task))
  8273. (org-move-to-column col)
  8274. (org-agenda-mark-clocking-task))))
  8275. (defun org-agenda-add-note (&optional arg)
  8276. "Add a time-stamped note to the entry at point."
  8277. (interactive "P")
  8278. (org-agenda-check-no-diary)
  8279. (let* ((marker (or (org-get-at-bol 'org-marker)
  8280. (org-agenda-error)))
  8281. (buffer (marker-buffer marker))
  8282. (pos (marker-position marker))
  8283. (hdmarker (org-get-at-bol 'org-hd-marker))
  8284. (inhibit-read-only t))
  8285. (with-current-buffer buffer
  8286. (widen)
  8287. (goto-char pos)
  8288. (org-show-context 'agenda)
  8289. (org-add-note))))
  8290. (defun org-agenda-change-all-lines (newhead hdmarker
  8291. &optional fixface just-this)
  8292. "Change all lines in the agenda buffer which match HDMARKER.
  8293. The new content of the line will be NEWHEAD (as modified by
  8294. `org-agenda-format-item'). HDMARKER is checked with
  8295. `equal' against all `org-hd-marker' text properties in the file.
  8296. If FIXFACE is non-nil, the face of each item is modified according to
  8297. the new TODO state.
  8298. If JUST-THIS is non-nil, change just the current line, not all.
  8299. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8300. (let* ((inhibit-read-only t)
  8301. (line (org-current-line))
  8302. (org-agenda-buffer (current-buffer))
  8303. (thetags (with-current-buffer (marker-buffer hdmarker)
  8304. (org-with-wide-buffer
  8305. (goto-char hdmarker)
  8306. (org-get-tags-at))))
  8307. props m pl undone-face done-face finish new dotime level cat tags)
  8308. (save-excursion
  8309. (goto-char (point-max))
  8310. (beginning-of-line 1)
  8311. (while (not finish)
  8312. (setq finish (bobp))
  8313. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8314. (or (not just-this) (= (org-current-line) line))
  8315. (equal m hdmarker))
  8316. (setq props (text-properties-at (point))
  8317. dotime (org-get-at-bol 'dotime)
  8318. cat (org-get-at-eol 'org-category 1)
  8319. level (org-get-at-bol 'level)
  8320. tags thetags
  8321. new
  8322. (let ((org-prefix-format-compiled
  8323. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8324. org-prefix-format-compiled))
  8325. (extra (org-get-at-bol 'extra)))
  8326. (with-current-buffer (marker-buffer hdmarker)
  8327. (org-with-wide-buffer
  8328. (org-agenda-format-item extra newhead level cat tags dotime))))
  8329. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8330. undone-face (org-get-at-bol 'undone-face)
  8331. done-face (org-get-at-bol 'done-face))
  8332. (beginning-of-line 1)
  8333. (cond
  8334. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8335. ((looking-at ".*")
  8336. ;; When replacing the whole line, preserve bulk mark
  8337. ;; overlay, if any.
  8338. (let ((mark (catch :overlay
  8339. (dolist (o (overlays-in (point) (+ 2 (point))))
  8340. (when (eq (overlay-get o 'type)
  8341. 'org-marked-entry-overlay)
  8342. (throw :overlay o))))))
  8343. (replace-match new t t)
  8344. (beginning-of-line)
  8345. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8346. (add-text-properties (point-at-bol) (point-at-eol) props)
  8347. (when fixface
  8348. (add-text-properties
  8349. (point-at-bol) (point-at-eol)
  8350. (list 'face
  8351. (if org-last-todo-state-is-todo
  8352. undone-face done-face))))
  8353. (org-agenda-highlight-todo 'line)
  8354. (beginning-of-line 1))
  8355. (t (error "Line update did not work")))
  8356. (save-restriction
  8357. (narrow-to-region (point-at-bol) (point-at-eol))
  8358. (org-agenda-finalize)))
  8359. (beginning-of-line 0)))))
  8360. (defun org-agenda-align-tags (&optional line)
  8361. "Align all tags in agenda items to `org-agenda-tags-column'."
  8362. (let ((inhibit-read-only t)
  8363. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  8364. (- (window-text-width))
  8365. org-agenda-tags-column))
  8366. l c)
  8367. (save-excursion
  8368. (goto-char (if line (point-at-bol) (point-min)))
  8369. (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
  8370. (if line (point-at-eol) nil) t)
  8371. (add-text-properties
  8372. (match-beginning 2) (match-end 2)
  8373. (list 'face (delq nil (let ((prop (get-text-property
  8374. (match-beginning 2) 'face)))
  8375. (or (listp prop) (setq prop (list prop)))
  8376. (if (memq 'org-tag prop)
  8377. prop
  8378. (cons 'org-tag prop))))))
  8379. (setq l (- (match-end 2) (match-beginning 2))
  8380. c (if (< org-agenda-tags-column 0)
  8381. (- (abs org-agenda-tags-column) l)
  8382. org-agenda-tags-column))
  8383. (delete-region (match-beginning 1) (match-end 1))
  8384. (goto-char (match-beginning 1))
  8385. (insert (org-add-props
  8386. (make-string (max 1 (- c (current-column))) ?\ )
  8387. (plist-put (copy-sequence (text-properties-at (point)))
  8388. 'face nil))))
  8389. (goto-char (point-min))
  8390. (org-font-lock-add-tag-faces (point-max)))))
  8391. (defun org-agenda-priority-up ()
  8392. "Increase the priority of line at point, also in Org file."
  8393. (interactive)
  8394. (org-agenda-priority 'up))
  8395. (defun org-agenda-priority-down ()
  8396. "Decrease the priority of line at point, also in Org file."
  8397. (interactive)
  8398. (org-agenda-priority 'down))
  8399. (defun org-agenda-priority (&optional force-direction)
  8400. "Set the priority of line at point, also in Org file.
  8401. This changes the line at point, all other lines in the agenda referring to
  8402. the same tree node, and the headline of the tree node in the Org file.
  8403. Called with a universal prefix arg, show the priority instead of setting it."
  8404. (interactive "P")
  8405. (if (equal force-direction '(4))
  8406. (org-show-priority)
  8407. (unless org-enable-priority-commands
  8408. (error "Priority commands are disabled"))
  8409. (org-agenda-check-no-diary)
  8410. (let* ((col (current-column))
  8411. (marker (or (org-get-at-bol 'org-marker)
  8412. (org-agenda-error)))
  8413. (hdmarker (org-get-at-bol 'org-hd-marker))
  8414. (buffer (marker-buffer hdmarker))
  8415. (pos (marker-position hdmarker))
  8416. (inhibit-read-only t)
  8417. newhead)
  8418. (org-with-remote-undo buffer
  8419. (with-current-buffer buffer
  8420. (widen)
  8421. (goto-char pos)
  8422. (org-show-context 'agenda)
  8423. (funcall 'org-priority force-direction)
  8424. (end-of-line 1)
  8425. (setq newhead (org-get-heading)))
  8426. (org-agenda-change-all-lines newhead hdmarker)
  8427. (org-move-to-column col)))))
  8428. ;; FIXME: should fix the tags property of the agenda line.
  8429. (defun org-agenda-set-tags (&optional tag onoff)
  8430. "Set tags for the current headline."
  8431. (interactive)
  8432. (org-agenda-check-no-diary)
  8433. (if (and (org-region-active-p) (called-interactively-p 'any))
  8434. (call-interactively 'org-change-tag-in-region)
  8435. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8436. (org-agenda-error)))
  8437. (buffer (marker-buffer hdmarker))
  8438. (pos (marker-position hdmarker))
  8439. (inhibit-read-only t)
  8440. newhead)
  8441. (org-with-remote-undo buffer
  8442. (with-current-buffer buffer
  8443. (widen)
  8444. (goto-char pos)
  8445. (org-show-context 'agenda)
  8446. (if tag
  8447. (org-toggle-tag tag onoff)
  8448. (call-interactively 'org-set-tags))
  8449. (end-of-line 1)
  8450. (setq newhead (org-get-heading)))
  8451. (org-agenda-change-all-lines newhead hdmarker)
  8452. (beginning-of-line 1)))))
  8453. (defun org-agenda-set-property ()
  8454. "Set a property for the current headline."
  8455. (interactive)
  8456. (org-agenda-check-no-diary)
  8457. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8458. (org-agenda-error)))
  8459. (buffer (marker-buffer hdmarker))
  8460. (pos (marker-position hdmarker))
  8461. (inhibit-read-only t)
  8462. newhead)
  8463. (org-with-remote-undo buffer
  8464. (with-current-buffer buffer
  8465. (widen)
  8466. (goto-char pos)
  8467. (org-show-context 'agenda)
  8468. (call-interactively 'org-set-property)))))
  8469. (defun org-agenda-set-effort ()
  8470. "Set the effort property for the current headline."
  8471. (interactive)
  8472. (org-agenda-check-no-diary)
  8473. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8474. (org-agenda-error)))
  8475. (buffer (marker-buffer hdmarker))
  8476. (pos (marker-position hdmarker))
  8477. (inhibit-read-only t)
  8478. newhead)
  8479. (org-with-remote-undo buffer
  8480. (with-current-buffer buffer
  8481. (widen)
  8482. (goto-char pos)
  8483. (org-show-context 'agenda)
  8484. (call-interactively 'org-set-effort)
  8485. (end-of-line 1)
  8486. (setq newhead (org-get-heading)))
  8487. (org-agenda-change-all-lines newhead hdmarker))))
  8488. (defun org-agenda-toggle-archive-tag ()
  8489. "Toggle the archive tag for the current entry."
  8490. (interactive)
  8491. (org-agenda-check-no-diary)
  8492. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8493. (org-agenda-error)))
  8494. (buffer (marker-buffer hdmarker))
  8495. (pos (marker-position hdmarker))
  8496. (inhibit-read-only t)
  8497. newhead)
  8498. (org-with-remote-undo buffer
  8499. (with-current-buffer buffer
  8500. (widen)
  8501. (goto-char pos)
  8502. (org-show-context 'agenda)
  8503. (call-interactively 'org-toggle-archive-tag)
  8504. (end-of-line 1)
  8505. (setq newhead (org-get-heading)))
  8506. (org-agenda-change-all-lines newhead hdmarker)
  8507. (beginning-of-line 1))))
  8508. (defun org-agenda-do-date-later (arg)
  8509. (interactive "P")
  8510. (cond
  8511. ((or (equal arg '(16))
  8512. (memq last-command
  8513. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8514. (setq this-command 'org-agenda-date-later-minutes)
  8515. (org-agenda-date-later-minutes 1))
  8516. ((or (equal arg '(4))
  8517. (memq last-command
  8518. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8519. (setq this-command 'org-agenda-date-later-hours)
  8520. (org-agenda-date-later-hours 1))
  8521. (t
  8522. (org-agenda-date-later (prefix-numeric-value arg)))))
  8523. (defun org-agenda-do-date-earlier (arg)
  8524. (interactive "P")
  8525. (cond
  8526. ((or (equal arg '(16))
  8527. (memq last-command
  8528. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8529. (setq this-command 'org-agenda-date-earlier-minutes)
  8530. (org-agenda-date-earlier-minutes 1))
  8531. ((or (equal arg '(4))
  8532. (memq last-command
  8533. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8534. (setq this-command 'org-agenda-date-earlier-hours)
  8535. (org-agenda-date-earlier-hours 1))
  8536. (t
  8537. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8538. (defun org-agenda-date-later (arg &optional what)
  8539. "Change the date of this item to ARG day(s) later."
  8540. (interactive "p")
  8541. (org-agenda-check-type t 'agenda)
  8542. (org-agenda-check-no-diary)
  8543. (let* ((marker (or (org-get-at-bol 'org-marker)
  8544. (org-agenda-error)))
  8545. (buffer (marker-buffer marker))
  8546. (pos (marker-position marker))
  8547. cdate today)
  8548. (org-with-remote-undo buffer
  8549. (with-current-buffer buffer
  8550. (widen)
  8551. (goto-char pos)
  8552. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8553. (when (and org-agenda-move-date-from-past-immediately-to-today
  8554. (equal arg 1)
  8555. (or (not what) (eq what 'day))
  8556. (not (save-match-data (org-at-date-range-p))))
  8557. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8558. cdate (calendar-absolute-from-gregorian
  8559. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8560. today (org-today))
  8561. (if (> today cdate)
  8562. ;; immediately shift to today
  8563. (setq arg (- today cdate))))
  8564. (org-timestamp-change arg (or what 'day))
  8565. (when (and (org-at-date-range-p)
  8566. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8567. (let ((end org-last-changed-timestamp))
  8568. (org-timestamp-change arg (or what 'day))
  8569. (setq org-last-changed-timestamp
  8570. (concat org-last-changed-timestamp "--" end)))))
  8571. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8572. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8573. (defun org-agenda-date-earlier (arg &optional what)
  8574. "Change the date of this item to ARG day(s) earlier."
  8575. (interactive "p")
  8576. (org-agenda-date-later (- arg) what))
  8577. (defun org-agenda-date-later-minutes (arg)
  8578. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8579. (interactive "p")
  8580. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8581. (org-agenda-date-later arg 'minute))
  8582. (defun org-agenda-date-earlier-minutes (arg)
  8583. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8584. (interactive "p")
  8585. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8586. (org-agenda-date-earlier arg 'minute))
  8587. (defun org-agenda-date-later-hours (arg)
  8588. "Change the time of this item, in hour steps."
  8589. (interactive "p")
  8590. (org-agenda-date-later arg 'hour))
  8591. (defun org-agenda-date-earlier-hours (arg)
  8592. "Change the time of this item, in hour steps."
  8593. (interactive "p")
  8594. (org-agenda-date-earlier arg 'hour))
  8595. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8596. "Show new date stamp via text properties."
  8597. ;; We use text properties to make this undoable
  8598. (let ((inhibit-read-only t))
  8599. (setq stamp (concat prefix " => " stamp " "))
  8600. (save-excursion
  8601. (goto-char (point-max))
  8602. (while (not (bobp))
  8603. (when (equal marker (org-get-at-bol 'org-marker))
  8604. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8605. (org-move-to-column (- (window-width) (length stamp)) t)
  8606. (add-text-properties
  8607. (1- (point)) (point-at-eol)
  8608. (list 'display (org-add-props stamp nil
  8609. 'face '(secondary-selection default))))
  8610. (beginning-of-line 1))
  8611. (beginning-of-line 0)))))
  8612. (defun org-agenda-date-prompt (arg)
  8613. "Change the date of this item. Date is prompted for, with default today.
  8614. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8615. be used to request time specification in the time stamp."
  8616. (interactive "P")
  8617. (org-agenda-check-type t 'agenda)
  8618. (org-agenda-check-no-diary)
  8619. (let* ((marker (or (org-get-at-bol 'org-marker)
  8620. (org-agenda-error)))
  8621. (buffer (marker-buffer marker))
  8622. (pos (marker-position marker)))
  8623. (org-with-remote-undo buffer
  8624. (with-current-buffer buffer
  8625. (widen)
  8626. (goto-char pos)
  8627. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  8628. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8629. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8630. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8631. (defun org-agenda-schedule (arg &optional time)
  8632. "Schedule the item at point.
  8633. ARG is passed through to `org-schedule'."
  8634. (interactive "P")
  8635. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8636. (org-agenda-check-no-diary)
  8637. (let* ((marker (or (org-get-at-bol 'org-marker)
  8638. (org-agenda-error)))
  8639. (type (marker-insertion-type marker))
  8640. (buffer (marker-buffer marker))
  8641. (pos (marker-position marker))
  8642. ts)
  8643. (set-marker-insertion-type marker t)
  8644. (org-with-remote-undo buffer
  8645. (with-current-buffer buffer
  8646. (widen)
  8647. (goto-char pos)
  8648. (setq ts (org-schedule arg time)))
  8649. (org-agenda-show-new-time marker ts " S"))
  8650. (message "%s" ts)))
  8651. (defun org-agenda-deadline (arg &optional time)
  8652. "Schedule the item at point.
  8653. ARG is passed through to `org-deadline'."
  8654. (interactive "P")
  8655. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  8656. (org-agenda-check-no-diary)
  8657. (let* ((marker (or (org-get-at-bol 'org-marker)
  8658. (org-agenda-error)))
  8659. (buffer (marker-buffer marker))
  8660. (pos (marker-position marker))
  8661. ts)
  8662. (org-with-remote-undo buffer
  8663. (with-current-buffer buffer
  8664. (widen)
  8665. (goto-char pos)
  8666. (setq ts (org-deadline arg time)))
  8667. (org-agenda-show-new-time marker ts " D"))
  8668. (message "%s" ts)))
  8669. (defun org-agenda-clock-in (&optional arg)
  8670. "Start the clock on the currently selected item."
  8671. (interactive "P")
  8672. (org-agenda-check-no-diary)
  8673. (if (equal arg '(4))
  8674. (org-clock-in arg)
  8675. (let* ((marker (or (org-get-at-bol 'org-marker)
  8676. (org-agenda-error)))
  8677. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8678. (pos (marker-position marker))
  8679. (col (current-column))
  8680. newhead)
  8681. (org-with-remote-undo (marker-buffer marker)
  8682. (with-current-buffer (marker-buffer marker)
  8683. (widen)
  8684. (goto-char pos)
  8685. (org-show-context 'agenda)
  8686. (org-cycle-hide-drawers 'children)
  8687. (org-clock-in arg)
  8688. (setq newhead (org-get-heading)))
  8689. (org-agenda-change-all-lines newhead hdmarker))
  8690. (org-move-to-column col))))
  8691. (defun org-agenda-clock-out ()
  8692. "Stop the currently running clock."
  8693. (interactive)
  8694. (unless (marker-buffer org-clock-marker)
  8695. (error "No running clock"))
  8696. (let ((marker (make-marker)) (col (current-column)) newhead)
  8697. (org-with-remote-undo (marker-buffer org-clock-marker)
  8698. (with-current-buffer (marker-buffer org-clock-marker)
  8699. (org-with-wide-buffer
  8700. (goto-char org-clock-marker)
  8701. (org-back-to-heading t)
  8702. (move-marker marker (point))
  8703. (org-clock-out)
  8704. (setq newhead (org-get-heading)))))
  8705. (org-agenda-change-all-lines newhead marker)
  8706. (move-marker marker nil)
  8707. (org-move-to-column col)
  8708. (org-agenda-unmark-clocking-task)))
  8709. (defun org-agenda-clock-cancel (&optional arg)
  8710. "Cancel the currently running clock."
  8711. (interactive "P")
  8712. (unless (marker-buffer org-clock-marker)
  8713. (user-error "No running clock"))
  8714. (org-with-remote-undo (marker-buffer org-clock-marker)
  8715. (org-clock-cancel)))
  8716. (defun org-agenda-clock-goto ()
  8717. "Jump to the currently clocked in task within the agenda.
  8718. If the currently clocked in task is not listed in the agenda
  8719. buffer, display it in another window."
  8720. (interactive)
  8721. (let (pos)
  8722. (mapc (lambda (o)
  8723. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8724. (setq pos (overlay-start o))))
  8725. (overlays-in (point-min) (point-max)))
  8726. (cond (pos (goto-char pos))
  8727. ;; If the currently clocked entry is not in the agenda
  8728. ;; buffer, we visit it in another window:
  8729. ((bound-and-true-p org-clock-current-task)
  8730. (org-switch-to-buffer-other-window (org-clock-goto)))
  8731. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8732. (defun org-agenda-diary-entry-in-org-file ()
  8733. "Make a diary entry in the file `org-agenda-diary-file'."
  8734. (let (d1 d2 char (text "") dp1 dp2)
  8735. (if (equal (buffer-name) "*Calendar*")
  8736. (setq d1 (calendar-cursor-to-date t)
  8737. d2 (car calendar-mark-ring))
  8738. (setq dp1 (get-text-property (point-at-bol) 'day))
  8739. (unless dp1 (user-error "No date defined in current line"))
  8740. (setq d1 (calendar-gregorian-from-absolute dp1)
  8741. d2 (and (ignore-errors (mark))
  8742. (save-excursion
  8743. (goto-char (mark))
  8744. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8745. (calendar-gregorian-from-absolute dp2))))
  8746. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8747. (setq char (read-char-exclusive))
  8748. (cond
  8749. ((equal char ?d)
  8750. (setq text (read-string "Day entry: "))
  8751. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8752. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8753. ((equal char ?a)
  8754. (setq d1 (list (car d1) (nth 1 d1)
  8755. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8756. (nth 2 d1))))
  8757. (setq text (read-string "Anniversary (use %d to show years): "))
  8758. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8759. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8760. ((equal char ?b)
  8761. (setq text (read-string "Block entry: "))
  8762. (unless (and d1 d2 (not (equal d1 d2)))
  8763. (user-error "No block of days selected"))
  8764. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8765. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8766. ((equal char ?j)
  8767. (org-switch-to-buffer-other-window
  8768. (find-file-noselect org-agenda-diary-file))
  8769. (require 'org-datetree)
  8770. (org-datetree-find-date-create d1)
  8771. (org-reveal t))
  8772. (t (user-error "Invalid selection character `%c'" char)))))
  8773. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8774. "Where in `org-agenda-diary-file' should new entries be added?
  8775. Valid values:
  8776. date-tree in the date tree, as first child of the date
  8777. date-tree-last in the date tree, as last child of the date
  8778. top-level as top-level entries at the end of the file."
  8779. :group 'org-agenda
  8780. :type '(choice
  8781. (const :tag "first in a date tree" date-tree)
  8782. (const :tag "last in a date tree" date-tree-last)
  8783. (const :tag "as top level at end of file" top-level)))
  8784. (defcustom org-agenda-insert-diary-extract-time nil
  8785. "Non-nil means extract any time specification from the diary entry."
  8786. :group 'org-agenda
  8787. :version "24.1"
  8788. :type 'boolean)
  8789. (defcustom org-agenda-bulk-mark-char ">"
  8790. "A single-character string to be used as the bulk mark."
  8791. :group 'org-agenda
  8792. :version "24.1"
  8793. :type 'string)
  8794. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8795. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8796. If TEXT is not empty, it will become the headline of the new entry, and
  8797. the resulting entry will not be shown. When TEXT is empty, switch to
  8798. `org-agenda-diary-file' and let the user finish the entry there."
  8799. (let ((cw (current-window-configuration)))
  8800. (org-switch-to-buffer-other-window
  8801. (find-file-noselect org-agenda-diary-file))
  8802. (widen)
  8803. (goto-char (point-min))
  8804. (cond
  8805. ((eq type 'anniversary)
  8806. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8807. (progn
  8808. (or (org-at-heading-p t)
  8809. (progn
  8810. (outline-next-heading)
  8811. (insert "* Anniversaries\n\n")
  8812. (beginning-of-line -1)))))
  8813. (outline-next-heading)
  8814. (org-back-over-empty-lines)
  8815. (backward-char 1)
  8816. (insert "\n")
  8817. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8818. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8819. ((eq type 'day)
  8820. (let ((org-prefix-has-time t)
  8821. (org-agenda-time-leading-zero t)
  8822. fmt time time2)
  8823. (if org-agenda-insert-diary-extract-time
  8824. ;; Use org-agenda-format-item to parse text for a time-range and
  8825. ;; remove it. FIXME: This is a hack, we should refactor
  8826. ;; that function to make time extraction available separately
  8827. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8828. time (get-text-property 0 'time fmt)
  8829. time2 (if (> (length time) 0)
  8830. ;; split-string removes trailing ...... if
  8831. ;; no end time given. First space
  8832. ;; separates time from date.
  8833. (concat " " (car (split-string time "\\.")))
  8834. nil)
  8835. text (get-text-property 0 'txt fmt)))
  8836. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8837. (org-agenda-insert-diary-as-top-level text)
  8838. (require 'org-datetree)
  8839. (org-datetree-find-date-create d1)
  8840. (org-agenda-insert-diary-make-new-entry text))
  8841. (org-insert-time-stamp (org-time-from-absolute
  8842. (calendar-absolute-from-gregorian d1))
  8843. nil nil nil nil time2))
  8844. (end-of-line 0))
  8845. ((eq type 'block)
  8846. (if (> (calendar-absolute-from-gregorian d1)
  8847. (calendar-absolute-from-gregorian d2))
  8848. (setq d1 (prog1 d2 (setq d2 d1))))
  8849. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8850. (org-agenda-insert-diary-as-top-level text)
  8851. (require 'org-datetree)
  8852. (org-datetree-find-date-create d1)
  8853. (org-agenda-insert-diary-make-new-entry text))
  8854. (org-insert-time-stamp (org-time-from-absolute
  8855. (calendar-absolute-from-gregorian d1)))
  8856. (insert "--")
  8857. (org-insert-time-stamp (org-time-from-absolute
  8858. (calendar-absolute-from-gregorian d2)))
  8859. (end-of-line 0)))
  8860. (if (string-match "\\S-" text)
  8861. (progn
  8862. (set-window-configuration cw)
  8863. (message "%s entry added to %s"
  8864. (capitalize (symbol-name type))
  8865. (abbreviate-file-name org-agenda-diary-file)))
  8866. (org-reveal t)
  8867. (message "Please finish entry here"))))
  8868. (defun org-agenda-insert-diary-as-top-level (text)
  8869. "Make new entry as a top-level entry at the end of the file.
  8870. Add TEXT as headline, and position the cursor in the second line so that
  8871. a timestamp can be added there."
  8872. (widen)
  8873. (goto-char (point-max))
  8874. (unless (bolp) (insert "\n"))
  8875. (org-insert-heading nil t t)
  8876. (insert text)
  8877. (org-end-of-meta-data)
  8878. (unless (bolp) (insert "\n"))
  8879. (when org-adapt-indentation (indent-to-column 2)))
  8880. (defun org-agenda-insert-diary-make-new-entry (text)
  8881. "Make a new entry with TEXT as a child of the current subtree.
  8882. Position the point in the heading's first body line so that
  8883. a timestamp can be added there."
  8884. (cond
  8885. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  8886. (end-of-line)
  8887. (org-insert-heading '(4) t)
  8888. (org-do-demote))
  8889. (t
  8890. (outline-next-heading)
  8891. (org-back-over-empty-lines)
  8892. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  8893. (org-insert-heading nil t)
  8894. (org-do-demote)))
  8895. (let ((col (current-column)))
  8896. (insert text)
  8897. (org-end-of-meta-data)
  8898. ;; Ensure point is left on a blank line, at proper indentation.
  8899. (unless (bolp) (insert "\n"))
  8900. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  8901. (when org-adapt-indentation (indent-to-column col)))
  8902. (org-show-set-visibility 'lineage))
  8903. (defun org-agenda-diary-entry ()
  8904. "Make a diary entry, like the `i' command from the calendar.
  8905. All the standard commands work: block, weekly etc.
  8906. When `org-agenda-diary-file' points to a file,
  8907. `org-agenda-diary-entry-in-org-file' is called instead to create
  8908. entries in that Org file."
  8909. (interactive)
  8910. (if (not (eq org-agenda-diary-file 'diary-file))
  8911. (org-agenda-diary-entry-in-org-file)
  8912. (require 'diary-lib)
  8913. (let* ((char (progn
  8914. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8915. (read-char-exclusive)))
  8916. (cmd (cdr (assoc char
  8917. '((?d . diary-insert-entry)
  8918. (?w . diary-insert-weekly-entry)
  8919. (?m . diary-insert-monthly-entry)
  8920. (?y . diary-insert-yearly-entry)
  8921. (?a . diary-insert-anniversary-entry)
  8922. (?b . diary-insert-block-entry)
  8923. (?c . diary-insert-cyclic-entry)))))
  8924. (oldf (symbol-function 'calendar-cursor-to-date))
  8925. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8926. (point (point))
  8927. (mark (or (mark t) (point))))
  8928. (unless cmd
  8929. (user-error "No command associated with <%c>" char))
  8930. (unless (and (get-text-property point 'day)
  8931. (or (not (equal ?b char))
  8932. (get-text-property mark 'day)))
  8933. (user-error "Don't know which date to use for diary entry"))
  8934. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8935. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8936. (let ((calendar-mark-ring
  8937. (list (calendar-gregorian-from-absolute
  8938. (or (get-text-property mark 'day)
  8939. (get-text-property point 'day))))))
  8940. (unwind-protect
  8941. (progn
  8942. (fset 'calendar-cursor-to-date
  8943. (lambda (&optional error dummy)
  8944. (calendar-gregorian-from-absolute
  8945. (get-text-property point 'day))))
  8946. (call-interactively cmd))
  8947. (fset 'calendar-cursor-to-date oldf))))))
  8948. (defun org-agenda-execute-calendar-command (cmd)
  8949. "Execute a calendar command from the agenda with date from cursor."
  8950. (org-agenda-check-type t 'agenda)
  8951. (require 'diary-lib)
  8952. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8953. (user-error "Don't know which date to use for the calendar command"))
  8954. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8955. (point (point))
  8956. (date (calendar-gregorian-from-absolute
  8957. (get-text-property point 'day)))
  8958. ;; the following 2 vars are needed in the calendar
  8959. (displayed-month (car date))
  8960. (displayed-year (nth 2 date)))
  8961. (unwind-protect
  8962. (progn
  8963. (fset 'calendar-cursor-to-date
  8964. (lambda (&optional error dummy)
  8965. (calendar-gregorian-from-absolute
  8966. (get-text-property point 'day))))
  8967. (call-interactively cmd))
  8968. (fset 'calendar-cursor-to-date oldf))))
  8969. (defun org-agenda-phases-of-moon ()
  8970. "Display the phases of the moon for the 3 months around the cursor date."
  8971. (interactive)
  8972. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  8973. (defun org-agenda-holidays ()
  8974. "Display the holidays for the 3 months around the cursor date."
  8975. (interactive)
  8976. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  8977. (defvar calendar-longitude) ; defined in calendar.el
  8978. (defvar calendar-latitude) ; defined in calendar.el
  8979. (defvar calendar-location-name) ; defined in calendar.el
  8980. (defun org-agenda-sunrise-sunset (arg)
  8981. "Display sunrise and sunset for the cursor date.
  8982. Latitude and longitude can be specified with the variables
  8983. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8984. argument, latitude and longitude will be prompted for."
  8985. (interactive "P")
  8986. (require 'solar)
  8987. (let ((calendar-longitude (if arg nil calendar-longitude))
  8988. (calendar-latitude (if arg nil calendar-latitude))
  8989. (calendar-location-name
  8990. (if arg "the given coordinates" calendar-location-name)))
  8991. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8992. (defun org-agenda-goto-calendar ()
  8993. "Open the Emacs calendar with the date at the cursor."
  8994. (interactive)
  8995. (org-agenda-check-type t 'agenda)
  8996. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8997. (user-error "Don't know which date to open in calendar")))
  8998. (date (calendar-gregorian-from-absolute day))
  8999. (calendar-move-hook nil)
  9000. (calendar-view-holidays-initially-flag nil)
  9001. (calendar-view-diary-initially-flag nil))
  9002. (calendar)
  9003. (calendar-goto-date date)))
  9004. ;;;###autoload
  9005. (defun org-calendar-goto-agenda ()
  9006. "Compute the Org agenda for the calendar date displayed at the cursor.
  9007. This is a command that has to be installed in `calendar-mode-map'."
  9008. (interactive)
  9009. ;; Temporarily disable sticky agenda since user clearly wants to
  9010. ;; refresh view anyway.
  9011. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  9012. (org-agenda-sticky nil))
  9013. (org-agenda-list nil (calendar-absolute-from-gregorian
  9014. (calendar-cursor-to-date))
  9015. nil)))
  9016. (defun org-agenda-convert-date ()
  9017. (interactive)
  9018. (org-agenda-check-type t 'agenda)
  9019. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9020. date s)
  9021. (unless day
  9022. (user-error "Don't know which date to convert"))
  9023. (setq date (calendar-gregorian-from-absolute day))
  9024. (setq s (concat
  9025. "Gregorian: " (calendar-date-string date) "\n"
  9026. "ISO: " (calendar-iso-date-string date) "\n"
  9027. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9028. "Julian: " (calendar-julian-date-string date) "\n"
  9029. "Astron. JD: " (calendar-astro-date-string date)
  9030. " (Julian date number at noon UTC)\n"
  9031. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9032. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9033. "French: " (calendar-french-date-string date) "\n"
  9034. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9035. "Mayan: " (calendar-mayan-date-string date) "\n"
  9036. "Coptic: " (calendar-coptic-date-string date) "\n"
  9037. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9038. "Persian: " (calendar-persian-date-string date) "\n"
  9039. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9040. (with-output-to-temp-buffer "*Dates*"
  9041. (princ s))
  9042. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9043. ;;; Bulk commands
  9044. (defun org-agenda-bulk-marked-p ()
  9045. "Non-nil when current entry is marked for bulk action."
  9046. (eq (get-char-property (point-at-bol) 'type)
  9047. 'org-marked-entry-overlay))
  9048. (defun org-agenda-bulk-mark (&optional arg)
  9049. "Mark the entry at point for future bulk action."
  9050. (interactive "p")
  9051. (dotimes (i (or arg 1))
  9052. (unless (org-get-at-bol 'org-agenda-diary-link)
  9053. (let* ((m (org-get-at-bol 'org-hd-marker))
  9054. ov)
  9055. (unless (org-agenda-bulk-marked-p)
  9056. (unless m (user-error "Nothing to mark at point"))
  9057. (push m org-agenda-bulk-marked-entries)
  9058. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9059. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9060. (org-get-todo-face "TODO")
  9061. 'evaporate)
  9062. (overlay-put ov 'type 'org-marked-entry-overlay))
  9063. (end-of-line 1)
  9064. (or (ignore-errors
  9065. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9066. (beginning-of-line 2))
  9067. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9068. (beginning-of-line 2))
  9069. (message "%d entries marked for bulk action"
  9070. (length org-agenda-bulk-marked-entries))))))
  9071. (defun org-agenda-bulk-mark-all ()
  9072. "Mark all entries for future agenda bulk action."
  9073. (interactive)
  9074. (org-agenda-bulk-mark-regexp "."))
  9075. (defun org-agenda-bulk-mark-regexp (regexp)
  9076. "Mark entries matching REGEXP for future agenda bulk action."
  9077. (interactive "sMark entries matching regexp: ")
  9078. (let ((entries-marked 0) txt-at-point)
  9079. (save-excursion
  9080. (goto-char (point-min))
  9081. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9082. (while (and (re-search-forward regexp nil t)
  9083. (setq txt-at-point (get-text-property (point) 'txt)))
  9084. (if (get-char-property (point) 'invisible)
  9085. (beginning-of-line 2)
  9086. (when (string-match regexp txt-at-point)
  9087. (setq entries-marked (1+ entries-marked))
  9088. (call-interactively 'org-agenda-bulk-mark)))))
  9089. (if (not entries-marked)
  9090. (message "No entry matching this regexp."))))
  9091. (defun org-agenda-bulk-unmark (&optional arg)
  9092. "Unmark the entry at point for future bulk action."
  9093. (interactive "P")
  9094. (if arg
  9095. (org-agenda-bulk-unmark-all)
  9096. (cond ((org-agenda-bulk-marked-p)
  9097. (org-agenda-bulk-remove-overlays
  9098. (point-at-bol) (+ 2 (point-at-bol)))
  9099. (setq org-agenda-bulk-marked-entries
  9100. (delete (org-get-at-bol 'org-hd-marker)
  9101. org-agenda-bulk-marked-entries))
  9102. (end-of-line 1)
  9103. (or (ignore-errors
  9104. (goto-char (next-single-property-change (point) 'txt)))
  9105. (beginning-of-line 2))
  9106. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9107. (beginning-of-line 2))
  9108. (message "%d entries left marked for bulk action"
  9109. (length org-agenda-bulk-marked-entries)))
  9110. (t (message "No entry to unmark here")))))
  9111. (defun org-agenda-bulk-toggle-all ()
  9112. "Toggle all marks for bulk action."
  9113. (interactive)
  9114. (save-excursion
  9115. (goto-char (point-min))
  9116. (while (ignore-errors
  9117. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9118. (org-agenda-bulk-toggle))))
  9119. (defun org-agenda-bulk-toggle ()
  9120. "Toggle the mark at point for bulk action."
  9121. (interactive)
  9122. (if (org-agenda-bulk-marked-p)
  9123. (org-agenda-bulk-unmark)
  9124. (org-agenda-bulk-mark)))
  9125. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9126. "Remove the mark overlays between BEG and END in the agenda buffer.
  9127. BEG and END default to the buffer limits.
  9128. This only removes the overlays, it does not remove the markers
  9129. from the list in `org-agenda-bulk-marked-entries'."
  9130. (interactive)
  9131. (mapc (lambda (ov)
  9132. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9133. (delete-overlay ov)))
  9134. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9135. (defun org-agenda-bulk-unmark-all ()
  9136. "Remove all marks in the agenda buffer.
  9137. This will remove the markers and the overlays."
  9138. (interactive)
  9139. (if (null org-agenda-bulk-marked-entries)
  9140. (message "No entry to unmark")
  9141. (setq org-agenda-bulk-marked-entries nil)
  9142. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9143. (defcustom org-agenda-persistent-marks nil
  9144. "Non-nil means marked items will stay marked after a bulk action.
  9145. You can toggle this interactively by typing `p' when prompted for a
  9146. bulk action."
  9147. :group 'org-agenda
  9148. :version "24.1"
  9149. :type 'boolean)
  9150. (defun org-agenda-bulk-action (&optional arg)
  9151. "Execute an remote-editing action on all marked entries.
  9152. The prefix arg is passed through to the command if possible."
  9153. (interactive "P")
  9154. ;; Make sure we have markers, and only valid ones.
  9155. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9156. (dolist (m org-agenda-bulk-marked-entries)
  9157. (unless (and (markerp m)
  9158. (marker-buffer m)
  9159. (buffer-live-p (marker-buffer m))
  9160. (marker-position m))
  9161. (user-error "Marker %s for bulk command is invalid" m)))
  9162. ;; Prompt for the bulk command.
  9163. (message
  9164. (concat (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")
  9165. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9166. "[S]catter [f]unction "
  9167. (and org-agenda-bulk-custom-functions
  9168. (format " Custom: [%s]"
  9169. (mapconcat (lambda (f) (char-to-string (car f)))
  9170. org-agenda-bulk-custom-functions
  9171. "")))))
  9172. (catch 'exit
  9173. (let* ((org-log-refile (if org-log-refile 'time nil))
  9174. (entries (reverse org-agenda-bulk-marked-entries))
  9175. (org-overriding-default-time
  9176. (and (get-text-property (point) 'org-agenda-date-header)
  9177. (org-get-cursor-date)))
  9178. redo-at-end
  9179. cmd)
  9180. (pcase (read-char-exclusive)
  9181. (?p
  9182. (let ((org-agenda-persistent-marks
  9183. (not org-agenda-persistent-marks)))
  9184. (org-agenda-bulk-action)
  9185. (throw 'exit nil)))
  9186. (?$
  9187. (setq cmd #'org-agenda-archive))
  9188. (?A
  9189. (setq cmd #'org-agenda-archive-to-archive-sibling))
  9190. ((or ?r ?w)
  9191. (let ((refile-location
  9192. (org-refile-get-location
  9193. "Refile to"
  9194. (marker-buffer (car entries))
  9195. org-refile-allow-creating-parent-nodes)))
  9196. (when (nth 3 refile-location)
  9197. (setcar (nthcdr 3 refile-location)
  9198. (move-marker
  9199. (make-marker)
  9200. (nth 3 refile-location)
  9201. (or (get-file-buffer (nth 1 refile-location))
  9202. (find-buffer-visiting (nth 1 refile-location))
  9203. (error "This should not happen")))))
  9204. (setq cmd `(lambda () (org-agenda-refile nil ',refile-location t)))
  9205. (setq redo-at-end t)))
  9206. (?t
  9207. (let ((state (completing-read
  9208. "Todo state: "
  9209. (with-current-buffer (marker-buffer (car entries))
  9210. (mapcar #'list org-todo-keywords-1)))))
  9211. (setq cmd `(lambda ()
  9212. (let ((org-inhibit-blocking t)
  9213. (org-inhibit-logging 'note))
  9214. (org-agenda-todo ,state))))))
  9215. ((and (or ?- ?+) action)
  9216. (let ((tag (completing-read
  9217. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9218. (with-current-buffer (marker-buffer (car entries))
  9219. (delq nil
  9220. (mapcar (lambda (x) (and (stringp (car x)) x))
  9221. org-current-tag-alist))))))
  9222. (setq cmd
  9223. `(lambda ()
  9224. (org-agenda-set-tags ,tag
  9225. ,(if (eq action ?+) ''on ''off))))))
  9226. (?s
  9227. (let ((time
  9228. (and (not arg)
  9229. (org-read-date nil nil nil "(Re)Schedule to"
  9230. org-overriding-default-time))))
  9231. ;; Make sure to not prompt for a note when bulk
  9232. ;; rescheduling as Org cannot cope with simultaneous notes.
  9233. ;; Besides, it could be annoying depending on the number of
  9234. ;; items re-scheduled.
  9235. (setq cmd
  9236. `(lambda ()
  9237. (let ((org-log-reschedule (and org-log-reschedule 'time)))
  9238. (org-agenda-schedule arg ,time))))))
  9239. (?d
  9240. (let ((time
  9241. (and (not arg)
  9242. (org-read-date nil nil nil "(Re)Set Deadline to"
  9243. org-overriding-default-time))))
  9244. ;; Make sure to not prompt for a note when bulk
  9245. ;; rescheduling as Org cannot cope with simultaneous
  9246. ;; notes. Besides, it could be annoying depending on the
  9247. ;; number of items re-scheduled.
  9248. (setq cmd
  9249. `(lambda ()
  9250. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  9251. (org-agenda-deadline arg ,time))))))
  9252. (?S
  9253. (unless (org-agenda-check-type nil 'agenda 'todo)
  9254. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  9255. (let ((days (read-number
  9256. (format "Scatter tasks across how many %sdays: "
  9257. (if arg "week" ""))
  9258. 7)))
  9259. (setq cmd
  9260. `(lambda ()
  9261. (let ((distance (1+ (random ,days))))
  9262. (when arg
  9263. (let ((dist distance)
  9264. (day-of-week
  9265. (calendar-day-of-week
  9266. (calendar-gregorian-from-absolute (org-today)))))
  9267. (dotimes (i (1+ dist))
  9268. (while (member day-of-week org-agenda-weekend-days)
  9269. (cl-incf distance)
  9270. (cl-incf day-of-week)
  9271. (when (= day-of-week 7)
  9272. (setq day-of-week 0)))
  9273. (cl-incf day-of-week)
  9274. (when (= day-of-week 7)
  9275. (setq day-of-week 0)))))
  9276. ;; Silently fail when try to replan a sexp entry.
  9277. (ignore-errors
  9278. (let* ((date (calendar-gregorian-from-absolute
  9279. (+ (org-today) distance)))
  9280. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9281. (nth 2 date))))
  9282. (org-agenda-schedule nil time))))))))
  9283. (?f
  9284. (setq cmd
  9285. (intern
  9286. (completing-read "Function: " obarray #'fboundp t nil nil))))
  9287. (action
  9288. (pcase (assoc action org-agenda-bulk-custom-functions)
  9289. (`(,_ ,f) (setq cmd f) (setq redo-at-end t))
  9290. (_ (user-error "Invalid bulk action: %c" action)))))
  9291. ;; Sort the markers, to make sure that parents are handled
  9292. ;; before children.
  9293. (setq entries (sort entries
  9294. (lambda (a b)
  9295. (cond
  9296. ((eq (marker-buffer a) (marker-buffer b))
  9297. (< (marker-position a) (marker-position b)))
  9298. (t
  9299. (string< (buffer-name (marker-buffer a))
  9300. (buffer-name (marker-buffer b))))))))
  9301. ;; Now loop over all markers and apply CMD.
  9302. (let ((processed 0)
  9303. (skipped 0))
  9304. (dolist (e entries)
  9305. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  9306. (if (not pos)
  9307. (progn (message "Skipping removed entry at %s" e)
  9308. (cl-incf skipped))
  9309. (goto-char pos)
  9310. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  9311. ;; `post-command-hook' is not run yet. We make sure any
  9312. ;; pending log note is processed.
  9313. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9314. (memq 'org-add-log-note post-command-hook))
  9315. (org-add-log-note))
  9316. (cl-incf processed))))
  9317. (when redo-at-end (org-agenda-redo))
  9318. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  9319. (message "Acted on %d entries%s%s"
  9320. processed
  9321. (if (= skipped 0)
  9322. ""
  9323. (format ", skipped %d (disappeared before their turn)"
  9324. skipped))
  9325. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  9326. (defun org-agenda-capture (&optional with-time)
  9327. "Call `org-capture' with the date at point.
  9328. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9329. current HH:MM time."
  9330. (interactive "P")
  9331. (if (not (eq major-mode 'org-agenda-mode))
  9332. (user-error "You cannot do this outside of agenda buffers")
  9333. (let ((org-overriding-default-time
  9334. (org-get-cursor-date (equal with-time 1))))
  9335. (call-interactively 'org-capture))))
  9336. ;;; Dragging agenda lines forward/backward
  9337. (defun org-agenda-reapply-filters ()
  9338. "Re-apply all agenda filters."
  9339. (mapcar
  9340. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9341. `((,org-agenda-tag-filter tag)
  9342. (,org-agenda-category-filter category)
  9343. (,org-agenda-regexp-filter regexp)
  9344. (,org-agenda-effort-filter effort)
  9345. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9346. (,(get 'org-agenda-category-filter :preset-filter) category)
  9347. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9348. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9349. (defun org-agenda-drag-line-forward (arg &optional backward)
  9350. "Drag an agenda line forward by ARG lines.
  9351. When the optional argument `backward' is non-nil, move backward."
  9352. (interactive "p")
  9353. (let ((inhibit-read-only t) lst line)
  9354. (if (or (not (get-text-property (point) 'txt))
  9355. (save-excursion
  9356. (dotimes (n arg)
  9357. (move-beginning-of-line (if backward 0 2))
  9358. (push (not (get-text-property (point) 'txt)) lst))
  9359. (delq nil lst)))
  9360. (message "Cannot move line forward")
  9361. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9362. (move-beginning-of-line 1)
  9363. (setq line (buffer-substring (point) end))
  9364. (delete-region (point) end)
  9365. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9366. (insert line)
  9367. (org-agenda-reapply-filters)
  9368. (org-agenda-mark-clocking-task)
  9369. (move-beginning-of-line 0)))))
  9370. (defun org-agenda-drag-line-backward (arg)
  9371. "Drag an agenda line backward by ARG lines."
  9372. (interactive "p")
  9373. (org-agenda-drag-line-forward arg t))
  9374. ;;; Flagging notes
  9375. (defun org-agenda-show-the-flagging-note ()
  9376. "Display the flagging note in the other window.
  9377. When called a second time in direct sequence, offer to remove the FLAGGING
  9378. tag and (if present) the flagging note."
  9379. (interactive)
  9380. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9381. (win (selected-window))
  9382. note heading newhead)
  9383. (unless hdmarker
  9384. (user-error "No linked entry at point"))
  9385. (if (and (eq this-command last-command)
  9386. (y-or-n-p "Unflag and remove any flagging note? "))
  9387. (progn
  9388. (org-agenda-remove-flag hdmarker)
  9389. (let ((win (get-buffer-window "*Flagging Note*")))
  9390. (and win (delete-window win)))
  9391. (message "Entry unflagged"))
  9392. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9393. (unless note
  9394. (user-error "No flagging note"))
  9395. (org-kill-new note)
  9396. (org-switch-to-buffer-other-window "*Flagging Note*")
  9397. (erase-buffer)
  9398. (insert note)
  9399. (goto-char (point-min))
  9400. (while (re-search-forward "\\\\n" nil t)
  9401. (replace-match "\n" t t))
  9402. (goto-char (point-min))
  9403. (select-window win)
  9404. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9405. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  9406. tag and note")))))
  9407. (defun org-agenda-remove-flag (marker)
  9408. "Remove the FLAGGED tag and any flagging note in the entry."
  9409. (let (newhead)
  9410. (org-with-point-at marker
  9411. (org-toggle-tag "FLAGGED" 'off)
  9412. (org-entry-delete nil "THEFLAGGINGNOTE")
  9413. (setq newhead (org-get-heading)))
  9414. (org-agenda-change-all-lines newhead marker)
  9415. (message "Entry unflagged")))
  9416. (defun org-agenda-get-any-marker (&optional pos)
  9417. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9418. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9419. ;;; Appointment reminders
  9420. (defvar appt-time-msg-list) ; defined in appt.el
  9421. ;;;###autoload
  9422. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9423. "Activate appointments found in `org-agenda-files'.
  9424. With a `\\[universal-argument]' prefix, refresh the list of \
  9425. appointments.
  9426. If FILTER is t, interactively prompt the user for a regular
  9427. expression, and filter out entries that don't match it.
  9428. If FILTER is a string, use this string as a regular expression
  9429. for filtering entries out.
  9430. If FILTER is a function, filter out entries against which
  9431. calling the function returns nil. This function takes one
  9432. argument: an entry from `org-agenda-get-day-entries'.
  9433. FILTER can also be an alist with the car of each cell being
  9434. either `headline' or `category'. For example:
  9435. \\='((headline \"IMPORTANT\")
  9436. (category \"Work\"))
  9437. will only add headlines containing IMPORTANT or headlines
  9438. belonging to the \"Work\" category.
  9439. ARGS are symbols indicating what kind of entries to consider.
  9440. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9441. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9442. and :timestamp entries. See the docstring of `org-diary' for
  9443. details and examples.
  9444. If an entry has a APPT_WARNTIME property, its value will be used
  9445. to override `appt-message-warning-time'."
  9446. (interactive "P")
  9447. (if refresh (setq appt-time-msg-list nil))
  9448. (if (eq filter t)
  9449. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9450. (let* ((cnt 0) ; count added events
  9451. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9452. (org-agenda-new-buffers nil)
  9453. (org-deadline-warning-days 0)
  9454. ;; Do not use `org-today' here because appt only takes
  9455. ;; time and without date as argument, so it may pass wrong
  9456. ;; information otherwise
  9457. (today (org-date-to-gregorian
  9458. (time-to-days (current-time))))
  9459. (org-agenda-restrict nil)
  9460. (files (org-agenda-files 'unrestricted)) entries file
  9461. (org-agenda-buffer nil))
  9462. ;; Get all entries which may contain an appt
  9463. (org-agenda-prepare-buffers files)
  9464. (while (setq file (pop files))
  9465. (setq entries
  9466. (delq nil
  9467. (append entries
  9468. (apply 'org-agenda-get-day-entries
  9469. file today scope)))))
  9470. ;; Map thru entries and find if we should filter them out
  9471. (mapc
  9472. (lambda (x)
  9473. (let* ((evt (org-trim
  9474. (replace-regexp-in-string
  9475. org-bracket-link-regexp "\\3"
  9476. (or (get-text-property 1 'txt x) ""))))
  9477. (cat (get-text-property (1- (length x)) 'org-category x))
  9478. (tod (get-text-property 1 'time-of-day x))
  9479. (ok (or (null filter)
  9480. (and (stringp filter) (string-match filter evt))
  9481. (and (functionp filter) (funcall filter x))
  9482. (and (listp filter)
  9483. (let ((cat-filter (cadr (assq 'category filter)))
  9484. (evt-filter (cadr (assq 'headline filter))))
  9485. (or (and (stringp cat-filter)
  9486. (string-match cat-filter cat))
  9487. (and (stringp evt-filter)
  9488. (string-match evt-filter evt)))))))
  9489. (wrn (get-text-property 1 'warntime x)))
  9490. ;; FIXME: Shall we remove text-properties for the appt text?
  9491. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9492. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9493. (setq tod (concat "00" (number-to-string tod)))
  9494. (setq tod (when (string-match
  9495. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9496. (concat (match-string 1 tod) ":"
  9497. (match-string 2 tod))))
  9498. (when (appt-add tod evt wrn)
  9499. (setq cnt (1+ cnt))))))
  9500. entries)
  9501. (org-release-buffers org-agenda-new-buffers)
  9502. (if (eq cnt 0)
  9503. (message "No event to add")
  9504. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9505. (defun org-agenda-today-p (date)
  9506. "Non nil when DATE means today.
  9507. DATE is either a list of the form (month day year) or a number of
  9508. days as returned by `calendar-absolute-from-gregorian' or
  9509. `org-today'. This function considers `org-extend-today-until'
  9510. when defining today."
  9511. (eq (org-today)
  9512. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9513. (defun org-agenda-todo-yesterday (&optional arg)
  9514. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9515. (interactive "P")
  9516. (let* ((org-use-effective-time t)
  9517. (hour (nth 2 (decode-time (org-current-time))))
  9518. (org-extend-today-until (1+ hour)))
  9519. (org-agenda-todo arg)))
  9520. (provide 'org-agenda)
  9521. ;;; org-agenda.el ends here