org-agenda.el 397 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2017 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 <http://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'. `:deadline' must appear before
  245. `:scheduled' if the setting of
  246. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  247. any effect.
  248. :deadline* Same as above, but only include the deadline if it has an
  249. hour specification as [h]h:mm.
  250. :scheduled List all items which are scheduled for the given date.
  251. The diary for *today* also contains items which were
  252. scheduled earlier and are not yet marked DONE.
  253. :scheduled* Same as above, but only include the scheduled item if it
  254. has an hour specification as [h]h:mm.
  255. By default, all four non-starred types are turned on.
  256. When :scheduled* or :deadline* are included, :schedule or :deadline
  257. will be ignored.
  258. Never set this variable globally using `setq', because then it
  259. will apply to all future agenda commands. Instead, bind it with
  260. `let' to scope it dynamically into the agenda-constructing
  261. command. A good way to set it is through options in
  262. `org-agenda-custom-commands'. For a more flexible (though
  263. somewhat less efficient) way of determining what is included in
  264. the daily/weekly agenda, see `org-agenda-skip-function'.")
  265. (defconst org-agenda-custom-commands-local-options
  266. `(repeat :tag "Local settings for this command. Remember to quote values"
  267. (choice :tag "Setting"
  268. (list :tag "Heading for this block"
  269. (const org-agenda-overriding-header)
  270. (string :tag "Headline"))
  271. (list :tag "Files to be searched"
  272. (const org-agenda-files)
  273. (list
  274. (const :format "" quote)
  275. (repeat (file))))
  276. (list :tag "Sorting strategy"
  277. (const org-agenda-sorting-strategy)
  278. (list
  279. (const :format "" quote)
  280. (repeat
  281. ,org-sorting-choice)))
  282. (list :tag "Prefix format"
  283. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  284. (string))
  285. (list :tag "Number of days in agenda"
  286. (const org-agenda-span)
  287. (choice (const :tag "Day" day)
  288. (const :tag "Week" week)
  289. (const :tag "Fortnight" fortnight)
  290. (const :tag "Month" month)
  291. (const :tag "Year" year)
  292. (integer :tag "Custom")))
  293. (list :tag "Fixed starting date"
  294. (const org-agenda-start-day)
  295. (string :value "2007-11-01"))
  296. (list :tag "Start on day of week"
  297. (const org-agenda-start-on-weekday)
  298. (choice :value 1
  299. (const :tag "Today" nil)
  300. (integer :tag "Weekday No.")))
  301. (list :tag "Include data from diary"
  302. (const org-agenda-include-diary)
  303. (boolean))
  304. (list :tag "Deadline Warning days"
  305. (const org-deadline-warning-days)
  306. (integer :value 1))
  307. (list :tag "Category filter preset"
  308. (const org-agenda-category-filter-preset)
  309. (list
  310. (const :format "" quote)
  311. (repeat
  312. (string :tag "+category or -category"))))
  313. (list :tag "Tags filter preset"
  314. (const org-agenda-tag-filter-preset)
  315. (list
  316. (const :format "" quote)
  317. (repeat
  318. (string :tag "+tag or -tag"))))
  319. (list :tag "Effort filter preset"
  320. (const org-agenda-effort-filter-preset)
  321. (list
  322. (const :format "" quote)
  323. (repeat
  324. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  325. (list :tag "Regexp filter preset"
  326. (const org-agenda-regexp-filter-preset)
  327. (list
  328. (const :format "" quote)
  329. (repeat
  330. (string :tag "+regexp or -regexp"))))
  331. (list :tag "Set daily/weekly entry types"
  332. (const org-agenda-entry-types)
  333. (list
  334. (const :format "" quote)
  335. (set :greedy t :value ,org-agenda-entry-types
  336. (const :deadline)
  337. (const :scheduled)
  338. (const :deadline*)
  339. (const :scheduled*)
  340. (const :timestamp)
  341. (const :sexp))))
  342. (list :tag "Standard skipping condition"
  343. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  344. (const org-agenda-skip-function)
  345. (list
  346. (const :format "" quote)
  347. (list
  348. (choice
  349. :tag "Skipping range"
  350. (const :tag "Skip entry" org-agenda-skip-entry-if)
  351. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  352. (repeat :inline t :tag "Conditions for skipping"
  353. (choice
  354. :tag "Condition type"
  355. (list :tag "Regexp matches" :inline t
  356. (const :format "" 'regexp)
  357. (regexp))
  358. (list :tag "Regexp does not match" :inline t
  359. (const :format "" 'notregexp)
  360. (regexp))
  361. (list :tag "TODO state is" :inline t
  362. (const 'todo)
  363. (choice
  364. (const :tag "Any not-done state" 'todo)
  365. (const :tag "Any done state" 'done)
  366. (const :tag "Any state" 'any)
  367. (list :tag "Keyword list"
  368. (const :format "" quote)
  369. (repeat (string :tag "Keyword")))))
  370. (list :tag "TODO state is not" :inline t
  371. (const 'nottodo)
  372. (choice
  373. (const :tag "Any not-done state" 'todo)
  374. (const :tag "Any done state" 'done)
  375. (const :tag "Any state" 'any)
  376. (list :tag "Keyword list"
  377. (const :format "" quote)
  378. (repeat (string :tag "Keyword")))))
  379. (const :tag "scheduled" 'scheduled)
  380. (const :tag "not scheduled" 'notscheduled)
  381. (const :tag "deadline" 'deadline)
  382. (const :tag "no deadline" 'notdeadline)
  383. (const :tag "timestamp" 'timestamp)
  384. (const :tag "no timestamp" 'nottimestamp))))))
  385. (list :tag "Non-standard skipping condition"
  386. :value (org-agenda-skip-function)
  387. (const org-agenda-skip-function)
  388. (sexp :tag "Function or form (quoted!)"))
  389. (list :tag "Any variable"
  390. (variable :tag "Variable")
  391. (sexp :tag "Value (sexp)"))))
  392. "Selection of examples for agenda command settings.
  393. This will be spliced into the custom type of
  394. `org-agenda-custom-commands'.")
  395. (defcustom org-agenda-custom-commands
  396. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  397. "Custom commands for the agenda.
  398. \\<org-mode-map>
  399. These commands will be offered on the splash screen displayed by the
  400. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  401. (key desc type match settings files)
  402. key The key (one or more characters as a string) to be associated
  403. with the command.
  404. desc A description of the command, when omitted or nil, a default
  405. description is built using MATCH.
  406. type The command type, any of the following symbols:
  407. agenda The daily/weekly agenda.
  408. todo Entries with a specific TODO keyword, in all agenda files.
  409. search Entries containing search words entry or headline.
  410. tags Tags/Property/TODO match in all agenda files.
  411. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  412. todo-tree Sparse tree of specific TODO keyword in *current* file.
  413. tags-tree Sparse tree with all tags matches in *current* file.
  414. occur-tree Occur sparse tree for *current* file.
  415. ... A user-defined function.
  416. match What to search for:
  417. - a single keyword for TODO keyword searches
  418. - a tags match expression for tags searches
  419. - a word search expression for text searches.
  420. - a regular expression for occur searches
  421. For all other commands, this should be the empty string.
  422. settings A list of option settings, similar to that in a let form, so like
  423. this: ((opt1 val1) (opt2 val2) ...). The values will be
  424. evaluated at the moment of execution, so quote them when needed.
  425. files A list of files file to write the produced agenda buffer to
  426. with the command `org-store-agenda-views'.
  427. If a file name ends in \".html\", an HTML version of the buffer
  428. is written out. If it ends in \".ps\", a postscript version is
  429. produced. Otherwise, only the plain text is written to the file.
  430. You can also define a set of commands, to create a composite agenda buffer.
  431. In this case, an entry looks like this:
  432. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  433. where
  434. desc A description string to be displayed in the dispatcher menu.
  435. cmd An agenda command, similar to the above. However, tree commands
  436. are not allowed, but instead you can get agenda and global todo list.
  437. So valid commands for a set are:
  438. (agenda \"\" settings)
  439. (alltodo \"\" settings)
  440. (stuck \"\" settings)
  441. (todo \"match\" settings files)
  442. (search \"match\" settings files)
  443. (tags \"match\" settings files)
  444. (tags-todo \"match\" settings files)
  445. Each command can carry a list of options, and another set of options can be
  446. given for the whole set of commands. Individual command options take
  447. precedence over the general options.
  448. When using several characters as key to a command, the first characters
  449. are prefix commands. For the dispatcher to display useful information, you
  450. should provide a description for the prefix, like
  451. (setq org-agenda-custom-commands
  452. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  453. (\"hl\" tags \"+HOME+Lisa\")
  454. (\"hp\" tags \"+HOME+Peter\")
  455. (\"hk\" tags \"+HOME+Kim\")))"
  456. :group 'org-agenda-custom-commands
  457. :type `(repeat
  458. (choice :value ("x" "Describe command here" tags "" nil)
  459. (list :tag "Single command"
  460. (string :tag "Access Key(s) ")
  461. (option (string :tag "Description"))
  462. (choice
  463. (const :tag "Agenda" agenda)
  464. (const :tag "TODO list" alltodo)
  465. (const :tag "Search words" search)
  466. (const :tag "Stuck projects" stuck)
  467. (const :tag "Tags/Property match (all agenda files)" tags)
  468. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  469. (const :tag "TODO keyword search (all agenda files)" todo)
  470. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  471. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  472. (const :tag "Occur tree (current buffer)" occur-tree)
  473. (sexp :tag "Other, user-defined function"))
  474. (string :tag "Match (only for some commands)")
  475. ,org-agenda-custom-commands-local-options
  476. (option (repeat :tag "Export" (file :tag "Export to"))))
  477. (list :tag "Command series, all agenda files"
  478. (string :tag "Access Key(s)")
  479. (string :tag "Description ")
  480. (repeat :tag "Component"
  481. (choice
  482. (list :tag "Agenda"
  483. (const :format "" agenda)
  484. (const :tag "" :format "" "")
  485. ,org-agenda-custom-commands-local-options)
  486. (list :tag "TODO list (all keywords)"
  487. (const :format "" alltodo)
  488. (const :tag "" :format "" "")
  489. ,org-agenda-custom-commands-local-options)
  490. (list :tag "Search words"
  491. (const :format "" search)
  492. (string :tag "Match")
  493. ,org-agenda-custom-commands-local-options)
  494. (list :tag "Stuck projects"
  495. (const :format "" stuck)
  496. (const :tag "" :format "" "")
  497. ,org-agenda-custom-commands-local-options)
  498. (list :tag "Tags search"
  499. (const :format "" tags)
  500. (string :tag "Match")
  501. ,org-agenda-custom-commands-local-options)
  502. (list :tag "Tags search, TODO entries only"
  503. (const :format "" tags-todo)
  504. (string :tag "Match")
  505. ,org-agenda-custom-commands-local-options)
  506. (list :tag "TODO keyword search"
  507. (const :format "" todo)
  508. (string :tag "Match")
  509. ,org-agenda-custom-commands-local-options)
  510. (list :tag "Other, user-defined function"
  511. (symbol :tag "function")
  512. (string :tag "Match")
  513. ,org-agenda-custom-commands-local-options)))
  514. (repeat :tag "Settings for entire command set"
  515. (list (variable :tag "Any variable")
  516. (sexp :tag "Value")))
  517. (option (repeat :tag "Export" (file :tag "Export to"))))
  518. (cons :tag "Prefix key documentation"
  519. (string :tag "Access Key(s)")
  520. (string :tag "Description ")))))
  521. (defcustom org-agenda-query-register ?o
  522. "The register holding the current query string.
  523. The purpose of this is that if you construct a query string interactively,
  524. you can then use it to define a custom command."
  525. :group 'org-agenda-custom-commands
  526. :type 'character)
  527. (defcustom org-stuck-projects
  528. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  529. "How to identify stuck projects.
  530. This is a list of four items:
  531. 1. A tags/todo/property matcher string that is used to identify a project.
  532. See the manual for a description of tag and property searches.
  533. The entire tree below a headline matched by this is considered one project.
  534. 2. A list of TODO keywords identifying non-stuck projects.
  535. If the project subtree contains any headline with one of these todo
  536. keywords, the project is considered to be not stuck. If you specify
  537. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  538. 3. A list of tags identifying non-stuck projects.
  539. If the project subtree contains any headline with one of these tags,
  540. the project is considered to be not stuck. If you specify \"*\" as
  541. a tag, any tag will mark the project unstuck. Note that this is about
  542. the explicit presence of a tag somewhere in the subtree, inherited
  543. tags do not count here. If inherited tags make a project not stuck,
  544. use \"-TAG\" in the tags part of the matcher under (1.) above.
  545. 4. An arbitrary regular expression matching non-stuck projects.
  546. If the project turns out to be not stuck, search continues also in the
  547. subtree to see if any of the subtasks have project status.
  548. See also the variable `org-tags-match-list-sublevels' which applies
  549. to projects matched by this search as well.
  550. After defining this variable, you may use `\\[org-agenda-list-stuck-projects]'
  551. \(bound to `C-c a #') to produce the list."
  552. :group 'org-agenda-custom-commands
  553. :type '(list
  554. (string :tag "Tags/TODO match to identify a project")
  555. (repeat :tag "Projects are *not* stuck if they have an entry with \
  556. TODO keyword any of" (string))
  557. (repeat :tag "Projects are *not* stuck if they have an entry with \
  558. TAG being any of" (string))
  559. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  560. the subtree")))
  561. (defgroup org-agenda-skip nil
  562. "Options concerning skipping parts of agenda files."
  563. :tag "Org Agenda Skip"
  564. :group 'org-agenda)
  565. (defcustom org-agenda-skip-function-global nil
  566. "Function to be called at each match during agenda construction.
  567. If this function returns nil, the current match should not be skipped.
  568. If the function decided to skip an agenda match, is must return the
  569. buffer position from which the search should be continued.
  570. This may also be a Lisp form, which will be evaluated.
  571. This variable will be applied to every agenda match, including
  572. tags/property searches and TODO lists. So try to make the test function
  573. do its checking as efficiently as possible. To implement a skipping
  574. condition just for specific agenda commands, use the variable
  575. `org-agenda-skip-function' which can be set in the options section
  576. of custom agenda commands."
  577. :group 'org-agenda-skip
  578. :type 'sexp)
  579. (defgroup org-agenda-daily/weekly nil
  580. "Options concerning the daily/weekly agenda."
  581. :tag "Org Agenda Daily/Weekly"
  582. :group 'org-agenda)
  583. (defgroup org-agenda-todo-list nil
  584. "Options concerning the global todo list agenda view."
  585. :tag "Org Agenda Todo List"
  586. :group 'org-agenda)
  587. (defgroup org-agenda-match-view nil
  588. "Options concerning the general tags/property/todo match agenda view."
  589. :tag "Org Agenda Match View"
  590. :group 'org-agenda)
  591. (defgroup org-agenda-search-view nil
  592. "Options concerning the search agenda view."
  593. :tag "Org Agenda Search View"
  594. :group 'org-agenda)
  595. (defvar org-agenda-archives-mode nil
  596. "Non-nil means the agenda will include archived items.
  597. If this is the symbol `trees', trees in the selected agenda scope
  598. that are marked with the ARCHIVE tag will be included anyway. When this is
  599. t, also all archive files associated with the current selection of agenda
  600. files will be included.")
  601. (defcustom org-agenda-restriction-lock-highlight-subtree t
  602. "Non-nil means highlight the whole subtree when restriction is active.
  603. Otherwise only highlight the headline. Highlighting the whole subtree is
  604. useful to ensure no edits happen beyond the restricted region."
  605. :group 'org-agenda
  606. :type 'boolean)
  607. (defcustom org-agenda-skip-comment-trees t
  608. "Non-nil means skip trees that start with the COMMENT keyword.
  609. When nil, these trees are also scanned by agenda commands."
  610. :group 'org-agenda-skip
  611. :type 'boolean)
  612. (defcustom org-agenda-todo-list-sublevels t
  613. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  614. When nil, the sublevels of a TODO entry are not checked, resulting in
  615. potentially much shorter TODO lists."
  616. :group 'org-agenda-skip
  617. :group 'org-agenda-todo-list
  618. :type 'boolean)
  619. (defcustom org-agenda-todo-ignore-with-date nil
  620. "Non-nil means don't show entries with a date in the global todo list.
  621. You can use this if you prefer to mark mere appointments with a TODO keyword,
  622. but don't want them to show up in the TODO list.
  623. When this is set, it also covers deadlines and scheduled items, the settings
  624. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  625. will be ignored.
  626. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  627. :group 'org-agenda-skip
  628. :group 'org-agenda-todo-list
  629. :type 'boolean)
  630. (defcustom org-agenda-todo-ignore-timestamp nil
  631. "Non-nil means don't show entries with a timestamp.
  632. This applies when creating the global todo list.
  633. Valid values are:
  634. past Don't show entries for today or in the past.
  635. future Don't show entries with a timestamp in the future.
  636. The idea behind this is that if it has a future
  637. timestamp, you don't want to think about it until the
  638. date.
  639. all Don't show any entries with a timestamp in the global todo list.
  640. The idea behind this is that by setting a timestamp, you
  641. have already \"taken care\" of this item.
  642. This variable can also have an integer as a value. If positive (N),
  643. todos with a timestamp N or more days in the future will be ignored. If
  644. negative (-N), todos with a timestamp N or more days in the past will be
  645. ignored. If 0, todos with a timestamp either today or in the future will
  646. be ignored. For example, a value of -1 will exclude todos with a
  647. timestamp in the past (yesterday or earlier), while a value of 7 will
  648. exclude todos with a timestamp a week or more in the future.
  649. See also `org-agenda-todo-ignore-with-date'.
  650. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  651. to make his option also apply to the tags-todo list."
  652. :group 'org-agenda-skip
  653. :group 'org-agenda-todo-list
  654. :version "24.1"
  655. :type '(choice
  656. (const :tag "Ignore future timestamp todos" future)
  657. (const :tag "Ignore past or present timestamp todos" past)
  658. (const :tag "Ignore all timestamp todos" all)
  659. (const :tag "Show timestamp todos" nil)
  660. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  661. (defcustom org-agenda-todo-ignore-scheduled nil
  662. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  663. This applies when creating the global todo list.
  664. Valid values are:
  665. past Don't show entries scheduled today or in the past.
  666. future Don't show entries scheduled in the future.
  667. The idea behind this is that by scheduling it, you don't want to
  668. think about it until the scheduled date.
  669. all Don't show any scheduled entries in the global todo list.
  670. The idea behind this is that by scheduling it, you have already
  671. \"taken care\" of this item.
  672. t Same as `all', for backward compatibility.
  673. This variable can also have an integer as a value. See
  674. `org-agenda-todo-ignore-timestamp' for more details.
  675. See also `org-agenda-todo-ignore-with-date'.
  676. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  677. to make his option also apply to the tags-todo list."
  678. :group 'org-agenda-skip
  679. :group 'org-agenda-todo-list
  680. :type '(choice
  681. (const :tag "Ignore future-scheduled todos" future)
  682. (const :tag "Ignore past- or present-scheduled todos" past)
  683. (const :tag "Ignore all scheduled todos" all)
  684. (const :tag "Ignore all scheduled todos (compatibility)" t)
  685. (const :tag "Show scheduled todos" nil)
  686. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  687. (defcustom org-agenda-todo-ignore-deadlines nil
  688. "Non-nil means ignore some deadline TODO items when making TODO list.
  689. There are different motivations for using different values, please think
  690. carefully when configuring this variable.
  691. This applies when creating the global TODO list.
  692. Valid values are:
  693. near Don't show near deadline entries. A deadline is near when it is
  694. closer than `org-deadline-warning-days' days. The idea behind this
  695. is that such items will appear in the agenda anyway.
  696. far Don't show TODO entries where a deadline has been defined, but
  697. is not going to happen anytime soon. This is useful if you want to use
  698. the TODO list to figure out what to do now.
  699. past Don't show entries with a deadline timestamp for today or in the past.
  700. future Don't show entries with a deadline timestamp in the future, not even
  701. when they become `near' ones. Use it with caution.
  702. all Ignore all TODO entries that do have a deadline.
  703. t Same as `near', for backward compatibility.
  704. This variable can also have an integer as a value. See
  705. `org-agenda-todo-ignore-timestamp' for more details.
  706. See also `org-agenda-todo-ignore-with-date'.
  707. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  708. to make his option also apply to the tags-todo list."
  709. :group 'org-agenda-skip
  710. :group 'org-agenda-todo-list
  711. :type '(choice
  712. (const :tag "Ignore near deadlines" near)
  713. (const :tag "Ignore near deadlines (compatibility)" t)
  714. (const :tag "Ignore far deadlines" far)
  715. (const :tag "Ignore all TODOs with a deadlines" all)
  716. (const :tag "Show all TODOs, even if they have a deadline" nil)
  717. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  718. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  719. "Time unit to use when possibly ignoring an agenda item.
  720. See the docstring of various `org-agenda-todo-ignore-*' options.
  721. The default is to compare time stamps using days. An item is thus
  722. considered to be in the future if it is at least one day after today.
  723. Non-nil means to compare time stamps using seconds. An item is then
  724. considered future if it has a time value later than current time."
  725. :group 'org-agenda-skip
  726. :group 'org-agenda-todo-list
  727. :version "24.4"
  728. :package-version '(Org . "8.0")
  729. :type '(choice
  730. (const :tag "Compare time with days" nil)
  731. (const :tag "Compare time with seconds" t)))
  732. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  733. "Non-nil means honor todo-list ignores options also in tags-todo search.
  734. The variables
  735. `org-agenda-todo-ignore-with-date',
  736. `org-agenda-todo-ignore-timestamp',
  737. `org-agenda-todo-ignore-scheduled',
  738. `org-agenda-todo-ignore-deadlines'
  739. make the global TODO list skip entries that have time stamps of certain
  740. kinds. If this option is set, the same options will also apply for the
  741. tags-todo search, which is the general tags/property matcher
  742. restricted to unfinished TODO entries only."
  743. :group 'org-agenda-skip
  744. :group 'org-agenda-todo-list
  745. :group 'org-agenda-match-view
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-scheduled-if-done nil
  748. "Non-nil means don't show scheduled items in agenda when they are done.
  749. This is relevant for the daily/weekly agenda, not for the TODO list. It
  750. applies only to the actual date of the scheduling. Warnings about an item
  751. with a past scheduling dates are always turned off when the item is DONE."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-daily/weekly
  754. :type 'boolean)
  755. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  756. "Non-nil means skip scheduling line if same entry shows because of deadline.
  757. In the agenda of today, an entry can show up multiple times
  758. because it is both scheduled and has a nearby deadline, and maybe
  759. a plain time stamp as well.
  760. When this variable is nil, the entry will be shown several times.
  761. When set to t, then only the deadline is shown and the fact that
  762. the entry is scheduled today or was scheduled previously is not
  763. shown.
  764. When set to the symbol `not-today', skip scheduled previously,
  765. but not scheduled today.
  766. When set to the symbol `repeated-after-deadline', skip scheduled
  767. items if they are repeated beyond the current deadline."
  768. :group 'org-agenda-skip
  769. :group 'org-agenda-daily/weekly
  770. :type '(choice
  771. (const :tag "Never" nil)
  772. (const :tag "Always" t)
  773. (const :tag "Not when scheduled today" not-today)
  774. (const :tag "When repeated past deadline" repeated-after-deadline)))
  775. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  776. "Non-nil means skip timestamp line if same entry shows because of deadline.
  777. In the agenda of today, an entry can show up multiple times
  778. because it has both a plain timestamp and has a nearby deadline.
  779. When this variable is t, then only the deadline is shown and the
  780. fact that the entry has a timestamp for or including today is not
  781. shown. When this variable is nil, the entry will be shown
  782. several times."
  783. :group 'org-agenda-skip
  784. :group 'org-agenda-daily/weekly
  785. :version "24.1"
  786. :type '(choice
  787. (const :tag "Never" nil)
  788. (const :tag "Always" t)))
  789. (defcustom org-agenda-skip-deadline-if-done nil
  790. "Non-nil means don't show deadlines when the corresponding item is done.
  791. When nil, the deadline is still shown and should give you a happy feeling.
  792. This is relevant for the daily/weekly agenda. It applies only to the
  793. actual date of the deadline. Warnings about approaching and past-due
  794. deadlines are always turned off when the item is DONE."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :type 'boolean)
  798. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  799. "Non-nil means skip deadline prewarning when entry is also scheduled.
  800. This will apply on all days where a prewarning for the deadline would
  801. be shown, but not at the day when the entry is actually due. On that day,
  802. the deadline will be shown anyway.
  803. This variable may be set to nil, t, the symbol `pre-scheduled',
  804. or a number which will then give the number of days before the actual
  805. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  806. eliminates the deadline prewarning only prior to the scheduled date.
  807. This can be used in a workflow where the first showing of the deadline will
  808. trigger you to schedule it, and then you don't want to be reminded of it
  809. because you will take care of it on the day when scheduled."
  810. :group 'org-agenda-skip
  811. :group 'org-agenda-daily/weekly
  812. :version "24.1"
  813. :type '(choice
  814. (const :tag "Always show prewarning" nil)
  815. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  816. (const :tag "Remove prewarning if entry is scheduled" t)
  817. (integer :tag "Restart prewarning N days before deadline")))
  818. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  819. "Non-nil means skip scheduled delay when entry also has a deadline.
  820. This variable may be set to nil, t, the symbol `post-deadline',
  821. or a number which will then give the number of days after the actual
  822. scheduled date when the delay should expire. The symbol `post-deadline'
  823. eliminates the schedule delay when the date is posterior to the deadline."
  824. :group 'org-agenda-skip
  825. :group 'org-agenda-daily/weekly
  826. :version "24.4"
  827. :package-version '(Org . "8.0")
  828. :type '(choice
  829. (const :tag "Always honor delay" nil)
  830. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  831. (const :tag "Ignore delay if entry has a deadline" t)
  832. (integer :tag "Honor delay up until N days after the scheduled date")))
  833. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  834. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  835. When non-nil, after the search for timestamps has matched once in an
  836. entry, the rest of the entry will not be searched."
  837. :group 'org-agenda-skip
  838. :type 'boolean)
  839. (defcustom org-agenda-skip-timestamp-if-done nil
  840. "Non-nil means don't select item by timestamp or -range if it is DONE."
  841. :group 'org-agenda-skip
  842. :group 'org-agenda-daily/weekly
  843. :type 'boolean)
  844. (defcustom org-agenda-dim-blocked-tasks t
  845. "Non-nil means dim blocked tasks in the agenda display.
  846. This causes some overhead during agenda construction, but if you
  847. have turned on `org-enforce-todo-dependencies',
  848. `org-enforce-todo-checkbox-dependencies', or any other blocking
  849. mechanism, this will create useful feedback in the agenda.
  850. Instead of t, this variable can also have the value `invisible'.
  851. Then blocked tasks will be invisible and only become visible when
  852. they become unblocked. An exemption to this behavior is when a task is
  853. blocked because of unchecked checkboxes below it. Since checkboxes do
  854. not show up in the agenda views, making this task invisible you remove any
  855. trace from agenda views that there is something to do. Therefore, a task
  856. that is blocked because of checkboxes will never be made invisible, it
  857. will only be dimmed."
  858. :group 'org-agenda-daily/weekly
  859. :group 'org-agenda-todo-list
  860. :version "24.3"
  861. :type '(choice
  862. (const :tag "Do not dim" nil)
  863. (const :tag "Dim to a gray face" t)
  864. (const :tag "Make invisible" invisible)))
  865. (defcustom org-timeline-show-empty-dates 3
  866. "Non-nil means `org-timeline' also shows dates without an entry.
  867. When nil, only the days which actually have entries are shown.
  868. When t, all days between the first and the last date are shown.
  869. When an integer, show also empty dates, but if there is a gap of more than
  870. N days, just insert a special line indicating the size of the gap."
  871. :group 'org-agenda-skip
  872. :type '(choice
  873. (const :tag "None" nil)
  874. (const :tag "All" t)
  875. (integer :tag "at most")))
  876. (defgroup org-agenda-startup nil
  877. "Options concerning initial settings in the Agenda in Org Mode."
  878. :tag "Org Agenda Startup"
  879. :group 'org-agenda)
  880. (defcustom org-agenda-menu-show-matcher t
  881. "Non-nil means show the match string in the agenda dispatcher menu.
  882. When nil, the matcher string is not shown, but is put into the help-echo
  883. property so than moving the mouse over the command shows it.
  884. Setting it to nil is good if matcher strings are very long and/or if
  885. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  886. :group 'org-agenda
  887. :version "24.1"
  888. :type 'boolean)
  889. (defcustom org-agenda-menu-two-columns nil
  890. "Non-nil means, use two columns to show custom commands in the dispatcher.
  891. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  892. to nil."
  893. :group 'org-agenda
  894. :version "24.1"
  895. :type 'boolean)
  896. (defcustom org-agenda-finalize-hook nil
  897. "Hook run just before displaying an agenda buffer.
  898. The buffer is still writable when the hook is called.
  899. You can modify some of the buffer substrings but you should be
  900. extra careful not to modify the text properties of the agenda
  901. headlines as the agenda display heavily relies on them."
  902. :group 'org-agenda-startup
  903. :type 'hook)
  904. (defcustom org-agenda-mouse-1-follows-link nil
  905. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  906. A longer mouse click will still set point. Needs to be set
  907. before org.el is loaded."
  908. :group 'org-agenda-startup
  909. :type 'boolean)
  910. (defcustom org-agenda-start-with-follow-mode nil
  911. "The initial value of follow mode in a newly created agenda window."
  912. :group 'org-agenda-startup
  913. :type 'boolean)
  914. (defcustom org-agenda-follow-indirect nil
  915. "Non-nil means `org-agenda-follow-mode' displays only the
  916. current item's tree, in an indirect buffer."
  917. :group 'org-agenda
  918. :version "24.1"
  919. :type 'boolean)
  920. (defcustom org-agenda-show-outline-path t
  921. "Non-nil means show outline path in echo area after line motion."
  922. :group 'org-agenda-startup
  923. :type 'boolean)
  924. (defcustom org-agenda-start-with-entry-text-mode nil
  925. "The initial value of entry-text-mode in a newly created agenda window."
  926. :group 'org-agenda-startup
  927. :type 'boolean)
  928. (defcustom org-agenda-entry-text-maxlines 5
  929. "Number of text lines to be added when `E' is pressed in the agenda.
  930. Note that this variable only used during agenda display. To add entry text
  931. when exporting the agenda, configure the variable
  932. `org-agenda-add-entry-text-maxlines'."
  933. :group 'org-agenda
  934. :type 'integer)
  935. (defcustom org-agenda-entry-text-exclude-regexps nil
  936. "List of regular expressions to clean up entry text.
  937. The complete matches of all regular expressions in this list will be
  938. removed from entry text before it is shown in the agenda."
  939. :group 'org-agenda
  940. :type '(repeat (regexp)))
  941. (defcustom org-agenda-entry-text-leaders " > "
  942. "Text prepended to the entry text in agenda buffers."
  943. :version "24.4"
  944. :package-version '(Org . "8.0")
  945. :group 'org-agenda
  946. :type 'string)
  947. (defvar org-agenda-entry-text-cleanup-hook nil
  948. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  949. This cleanup is done in a temporary buffer, so the function may inspect and
  950. change the entire buffer.
  951. Some default stuff like drawers and scheduling/deadline dates will already
  952. have been removed when this is called, as will any matches for regular
  953. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  954. (defvar org-agenda-include-inactive-timestamps nil
  955. "Non-nil means include inactive time stamps in agenda and timeline.
  956. Dynamically scoped.")
  957. (defgroup org-agenda-windows nil
  958. "Options concerning the windows used by the Agenda in Org Mode."
  959. :tag "Org Agenda Windows"
  960. :group 'org-agenda)
  961. (defcustom org-agenda-window-setup 'reorganize-frame
  962. "How the agenda buffer should be displayed.
  963. Possible values for this option are:
  964. current-window Show agenda in the current window, keeping all other windows.
  965. other-window Use `switch-to-buffer-other-window' to display agenda.
  966. only-window Show agenda, deleting all other windows.
  967. reorganize-frame Show only two windows on the current frame, the current
  968. window and the agenda.
  969. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  970. Also, when exiting the agenda, kill that frame.
  971. See also the variable `org-agenda-restore-windows-after-quit'."
  972. :group 'org-agenda-windows
  973. :type '(choice
  974. (const current-window)
  975. (const other-frame)
  976. (const other-window)
  977. (const only-window)
  978. (const reorganize-frame)))
  979. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  980. "The min and max height of the agenda window as a fraction of frame height.
  981. The value of the variable is a cons cell with two numbers between 0 and 1.
  982. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  983. :group 'org-agenda-windows
  984. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  985. (defcustom org-agenda-restore-windows-after-quit nil
  986. "Non-nil means restore window configuration upon exiting agenda.
  987. Before the window configuration is changed for displaying the agenda,
  988. the current status is recorded. When the agenda is exited with
  989. `q' or `x' and this option is set, the old state is restored. If
  990. `org-agenda-window-setup' is `other-frame', the value of this
  991. option will be ignored."
  992. :group 'org-agenda-windows
  993. :type 'boolean)
  994. (defcustom org-agenda-span 'week
  995. "Number of days to include in overview display.
  996. Can be day, week, month, year, or any number of days.
  997. Custom commands can set this variable in the options section."
  998. :group 'org-agenda-daily/weekly
  999. :type '(choice (const :tag "Day" day)
  1000. (const :tag "Week" week)
  1001. (const :tag "Fortnight" fortnight)
  1002. (const :tag "Month" month)
  1003. (const :tag "Year" year)
  1004. (integer :tag "Custom")))
  1005. (defcustom org-agenda-start-on-weekday 1
  1006. "Non-nil means start the overview always on the specified weekday.
  1007. 0 denotes Sunday, 1 denotes Monday, etc.
  1008. When nil, always start on the current day.
  1009. Custom commands can set this variable in the options section."
  1010. :group 'org-agenda-daily/weekly
  1011. :type '(choice (const :tag "Today" nil)
  1012. (integer :tag "Weekday No.")))
  1013. (defcustom org-agenda-show-all-dates t
  1014. "Non-nil means `org-agenda' shows every day in the selected range.
  1015. When nil, only the days which actually have entries are shown."
  1016. :group 'org-agenda-daily/weekly
  1017. :type 'boolean)
  1018. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1019. "Format string for displaying dates in the agenda.
  1020. Used by the daily/weekly agenda and by the timeline. This should be
  1021. a format string understood by `format-time-string', or a function returning
  1022. the formatted date as a string. The function must take a single argument,
  1023. a calendar-style date list like (month day year)."
  1024. :group 'org-agenda-daily/weekly
  1025. :type '(choice
  1026. (string :tag "Format string")
  1027. (function :tag "Function")))
  1028. (defun org-agenda-format-date-aligned (date)
  1029. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1030. This function makes sure that dates are aligned for easy reading."
  1031. (require 'cal-iso)
  1032. (let* ((dayname (calendar-day-name date))
  1033. (day (cadr date))
  1034. (day-of-week (calendar-day-of-week date))
  1035. (month (car date))
  1036. (monthname (calendar-month-name month))
  1037. (year (nth 2 date))
  1038. (iso-week (org-days-to-iso-week
  1039. (calendar-absolute-from-gregorian date)))
  1040. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1041. (1- year))
  1042. ((and (= month 12) (<= iso-week 1))
  1043. (1+ year))
  1044. (t year)))
  1045. (weekstring (if (= day-of-week 1)
  1046. (format " W%02d" iso-week)
  1047. "")))
  1048. (format "%-10s %2d %s %4d%s"
  1049. dayname day monthname year weekstring)))
  1050. (defcustom org-agenda-time-leading-zero nil
  1051. "Non-nil means use leading zero for military times in agenda.
  1052. For example, 9:30am would become 09:30 rather than 9:30."
  1053. :group 'org-agenda-daily/weekly
  1054. :version "24.1"
  1055. :type 'boolean)
  1056. (defcustom org-agenda-timegrid-use-ampm nil
  1057. "When set, show AM/PM style timestamps on the timegrid."
  1058. :group 'org-agenda
  1059. :version "24.1"
  1060. :type 'boolean)
  1061. (defun org-agenda-time-of-day-to-ampm (time)
  1062. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1063. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1064. (minute (substring time -2))
  1065. (ampm "am"))
  1066. (cond
  1067. ((equal hour-number 12)
  1068. (setq ampm "pm"))
  1069. ((> hour-number 12)
  1070. (setq ampm "pm")
  1071. (setq hour-number (- hour-number 12))))
  1072. (concat
  1073. (if org-agenda-time-leading-zero
  1074. (format "%02d" hour-number)
  1075. (format "%02s" (number-to-string hour-number)))
  1076. ":" minute ampm)))
  1077. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1078. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1079. (if org-agenda-timegrid-use-ampm
  1080. (org-agenda-time-of-day-to-ampm time)
  1081. time))
  1082. (defcustom org-agenda-weekend-days '(6 0)
  1083. "Which days are weekend?
  1084. These days get the special face `org-agenda-date-weekend' in the agenda
  1085. and timeline buffers."
  1086. :group 'org-agenda-daily/weekly
  1087. :type '(set :greedy t
  1088. (const :tag "Monday" 1)
  1089. (const :tag "Tuesday" 2)
  1090. (const :tag "Wednesday" 3)
  1091. (const :tag "Thursday" 4)
  1092. (const :tag "Friday" 5)
  1093. (const :tag "Saturday" 6)
  1094. (const :tag "Sunday" 0)))
  1095. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1096. "Non-nil means jump to today when moving a past date forward in time.
  1097. When using S-right in the agenda to move a a date forward, and the date
  1098. stamp currently points to the past, the first key press will move it
  1099. to today. WHen nil, just move one day forward even if the date stays
  1100. in the past."
  1101. :group 'org-agenda-daily/weekly
  1102. :version "24.1"
  1103. :type 'boolean)
  1104. (defcustom org-agenda-include-diary nil
  1105. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1106. Custom commands can set this variable in the options section."
  1107. :group 'org-agenda-daily/weekly
  1108. :type 'boolean)
  1109. (defcustom org-agenda-include-deadlines t
  1110. "If non-nil, include entries within their deadline warning period.
  1111. Custom commands can set this variable in the options section."
  1112. :group 'org-agenda-daily/weekly
  1113. :version "24.1"
  1114. :type 'boolean)
  1115. (defcustom org-agenda-repeating-timestamp-show-all t
  1116. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1117. When set to a list of strings, only show occurrences of repeating
  1118. stamps for these TODO keywords. When nil, only one occurrence is
  1119. shown, either today or the nearest into the future."
  1120. :group 'org-agenda-daily/weekly
  1121. :type '(choice
  1122. (const :tag "Show repeating stamps" t)
  1123. (repeat :tag "Show repeating stamps for these TODO keywords"
  1124. (string :tag "TODO Keyword"))
  1125. (const :tag "Don't show repeating stamps" nil)))
  1126. (defcustom org-scheduled-past-days 10000
  1127. "Number of days to continue listing scheduled items not marked DONE.
  1128. When an item is scheduled on a date, it shows up in the agenda on
  1129. this day and will be listed until it is marked done or for the
  1130. number of days given here."
  1131. :group 'org-agenda-daily/weekly
  1132. :type 'integer)
  1133. (defcustom org-agenda-log-mode-items '(closed clock)
  1134. "List of items that should be shown in agenda log mode.
  1135. \\<org-agenda-mode-map>\
  1136. This list may contain the following symbols:
  1137. closed Show entries that have been closed on that day.
  1138. clock Show entries that have received clocked time on that day.
  1139. state Show all logged state changes.
  1140. Note that instead of changing this variable, you can also press \
  1141. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1142. the agenda to display all available LOG items temporarily."
  1143. :group 'org-agenda-daily/weekly
  1144. :type '(set :greedy t (const closed) (const clock) (const state)))
  1145. (defcustom org-agenda-clock-consistency-checks
  1146. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1147. :gap-ok-around ("4:00")
  1148. :default-face ((:background "DarkRed") (:foreground "white"))
  1149. :overlap-face nil :gap-face nil :no-end-time-face nil
  1150. :long-face nil :short-face nil)
  1151. "This is a property list, with the following keys:
  1152. :max-duration Mark clocking chunks that are longer than this time.
  1153. This is a time string like \"HH:MM\", or the number
  1154. of minutes as an integer.
  1155. :min-duration Mark clocking chunks that are shorter that this.
  1156. This is a time string like \"HH:MM\", or the number
  1157. of minutes as an integer.
  1158. :max-gap Mark gaps between clocking chunks that are longer than
  1159. this duration. A number of minutes, or a string
  1160. like \"HH:MM\".
  1161. :gap-ok-around List of times during the day which are usually not working
  1162. times. When a gap is detected, but the gap contains any
  1163. of these times, the gap is *not* reported. For example,
  1164. if this is (\"4:00\" \"13:00\") then gaps that contain
  1165. 4:00 in the morning (i.e. the night) and 13:00
  1166. (i.e. a typical lunch time) do not cause a warning.
  1167. You should have at least one time during the night in this
  1168. list, or otherwise the first task each morning will trigger
  1169. a warning because it follows a long gap.
  1170. Furthermore, the following properties can be used to define faces for
  1171. issue display.
  1172. :default-face the default face, if the specific face is undefined
  1173. :overlap-face face for overlapping clocks
  1174. :gap-face face for gaps between clocks
  1175. :no-end-time-face face for incomplete clocks
  1176. :long-face face for clock intervals that are too long
  1177. :short-face face for clock intervals that are too short"
  1178. :group 'org-agenda-daily/weekly
  1179. :group 'org-clock
  1180. :version "24.1"
  1181. :type 'plist)
  1182. (defcustom org-agenda-log-mode-add-notes t
  1183. "Non-nil means add first line of notes to log entries in agenda views.
  1184. If a log item like a state change or a clock entry is associated with
  1185. notes, the first line of these notes will be added to the entry in the
  1186. agenda display."
  1187. :group 'org-agenda-daily/weekly
  1188. :type 'boolean)
  1189. (defcustom org-agenda-start-with-log-mode nil
  1190. "The initial value of log-mode in a newly created agenda window.
  1191. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1192. explanations on the possible values."
  1193. :group 'org-agenda-startup
  1194. :group 'org-agenda-daily/weekly
  1195. :type '(choice (const :tag "Don't show log items" nil)
  1196. (const :tag "Show only log items" only)
  1197. (const :tag "Show all possible log items" clockcheck)
  1198. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1199. (choice (const :tag "Show closed log items" closed)
  1200. (const :tag "Show clocked log items" clock)
  1201. (const :tag "Show all logged state changes" state)))))
  1202. (defcustom org-agenda-start-with-clockreport-mode nil
  1203. "The initial value of clockreport-mode in a newly created agenda window."
  1204. :group 'org-agenda-startup
  1205. :group 'org-agenda-daily/weekly
  1206. :type 'boolean)
  1207. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1208. "Property list with parameters for the clocktable in clockreport mode.
  1209. This is the display mode that shows a clock table in the daily/weekly
  1210. agenda, the properties for this dynamic block can be set here.
  1211. The usual clocktable parameters are allowed here, but you cannot set
  1212. the properties :name, :tstart, :tend, :block, and :scope - these will
  1213. be overwritten to make sure the content accurately reflects the
  1214. current display in the agenda."
  1215. :group 'org-agenda-daily/weekly
  1216. :type 'plist)
  1217. (defcustom org-agenda-search-view-always-boolean nil
  1218. "Non-nil means the search string is interpreted as individual parts.
  1219. The search string for search view can either be interpreted as a phrase,
  1220. or as a list of snippets that define a boolean search for a number of
  1221. strings.
  1222. When this is non-nil, the string will be split on whitespace, and each
  1223. snippet will be searched individually, and all must match in order to
  1224. select an entry. A snippet is then a single string of non-white
  1225. characters, or a string in double quotes, or a regexp in {} braces.
  1226. If a snippet is preceded by \"-\", the snippet must *not* match.
  1227. \"+\" is syntactic sugar for positive selection. Each snippet may
  1228. be found as a full word or a partial word, but see the variable
  1229. `org-agenda-search-view-force-full-words'.
  1230. When this is nil, search will look for the entire search phrase as one,
  1231. with each space character matching any amount of whitespace, including
  1232. line breaks.
  1233. Even when this is nil, you can still switch to Boolean search dynamically
  1234. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1235. is a regexp marked with braces like \"{abc}\", this will also switch to
  1236. boolean search."
  1237. :group 'org-agenda-search-view
  1238. :version "24.1"
  1239. :type 'boolean)
  1240. (defvaralias 'org-agenda-search-view-search-words-only
  1241. 'org-agenda-search-view-always-boolean)
  1242. (defcustom org-agenda-search-view-force-full-words nil
  1243. "Non-nil means, search words must be matches as complete words.
  1244. When nil, they may also match part of a word."
  1245. :group 'org-agenda-search-view
  1246. :version "24.1"
  1247. :type 'boolean)
  1248. (defcustom org-agenda-search-view-max-outline-level 0
  1249. "Maximum outline level to display in search view.
  1250. E.g. when this is set to 1, the search view will only
  1251. show headlines of level 1. When set to 0, the default
  1252. value, don't limit agenda view by outline level."
  1253. :group 'org-agenda-search-view
  1254. :version "24.4"
  1255. :package-version '(Org . "8.3")
  1256. :type 'integer)
  1257. (defgroup org-agenda-time-grid nil
  1258. "Options concerning the time grid in the Org Agenda."
  1259. :tag "Org Agenda Time Grid"
  1260. :group 'org-agenda)
  1261. (defcustom org-agenda-search-headline-for-time t
  1262. "Non-nil means search headline for a time-of-day.
  1263. If the headline contains a time-of-day in one format or another, it will
  1264. be used to sort the entry into the time sequence of items for a day.
  1265. Some people have time stamps in the headline that refer to the creation
  1266. time or so, and then this produces an unwanted side effect. If this is
  1267. the case for your, use this variable to turn off searching the headline
  1268. for a time."
  1269. :group 'org-agenda-time-grid
  1270. :type 'boolean)
  1271. (defcustom org-agenda-use-time-grid t
  1272. "Non-nil means show a time grid in the agenda schedule.
  1273. A time grid is a set of lines for specific times (like every two hours between
  1274. 8:00 and 20:00). The items scheduled for a day at specific times are
  1275. sorted in between these lines.
  1276. For details about when the grid will be shown, and what it will look like, see
  1277. the variable `org-agenda-time-grid'."
  1278. :group 'org-agenda-time-grid
  1279. :type 'boolean)
  1280. (defcustom org-agenda-time-grid
  1281. '((daily today require-timed)
  1282. "----------------"
  1283. (800 1000 1200 1400 1600 1800 2000))
  1284. "The settings for time grid for agenda display.
  1285. This is a list of three items. The first item is again a list. It contains
  1286. symbols specifying conditions when the grid should be displayed:
  1287. daily if the agenda shows a single day
  1288. weekly if the agenda shows an entire week
  1289. today show grid on current date, independent of daily/weekly display
  1290. require-timed show grid only if at least one item has a time specification
  1291. remove-match skip grid times already present in an entry
  1292. The second item is a string which will be placed behind the grid time.
  1293. The third item is a list of integers, indicating the times that should have
  1294. a grid line."
  1295. :group 'org-agenda-time-grid
  1296. :type
  1297. '(list
  1298. (set :greedy t :tag "Grid Display Options"
  1299. (const :tag "Show grid in single day agenda display" daily)
  1300. (const :tag "Show grid in weekly agenda display" weekly)
  1301. (const :tag "Always show grid for today" today)
  1302. (const :tag "Show grid only if any timed entries are present"
  1303. require-timed)
  1304. (const :tag "Skip grid times already present in an entry"
  1305. remove-match))
  1306. (string :tag "Grid String")
  1307. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1308. (defcustom org-agenda-show-current-time-in-grid t
  1309. "Non-nil means show the current time in the time grid."
  1310. :group 'org-agenda-time-grid
  1311. :version "24.1"
  1312. :type 'boolean)
  1313. (defcustom org-agenda-current-time-string
  1314. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1315. "The string for the current time marker in the agenda."
  1316. :group 'org-agenda-time-grid
  1317. :version "24.1"
  1318. :type 'string)
  1319. (defgroup org-agenda-sorting nil
  1320. "Options concerning sorting in the Org Agenda."
  1321. :tag "Org Agenda Sorting"
  1322. :group 'org-agenda)
  1323. (defcustom org-agenda-sorting-strategy
  1324. '((agenda habit-down time-up priority-down category-keep)
  1325. (todo priority-down category-keep)
  1326. (tags priority-down category-keep)
  1327. (search category-keep))
  1328. "Sorting structure for the agenda items of a single day.
  1329. This is a list of symbols which will be used in sequence to determine
  1330. if an entry should be listed before another entry. The following
  1331. symbols are recognized:
  1332. time-up Put entries with time-of-day indications first, early first
  1333. time-down Put entries with time-of-day indications first, late first
  1334. timestamp-up Sort by any timestamp, early first
  1335. timestamp-down Sort by any timestamp, late first
  1336. scheduled-up Sort by scheduled timestamp, early first
  1337. scheduled-down Sort by scheduled timestamp, late first
  1338. deadline-up Sort by deadline timestamp, early first
  1339. deadline-down Sort by deadline timestamp, late first
  1340. ts-up Sort by active timestamp, early first
  1341. ts-down Sort by active timestamp, late first
  1342. tsia-up Sort by inactive timestamp, early first
  1343. tsia-down Sort by inactive timestamp, late first
  1344. category-keep Keep the default order of categories, corresponding to the
  1345. sequence in `org-agenda-files'.
  1346. category-up Sort alphabetically by category, A-Z.
  1347. category-down Sort alphabetically by category, Z-A.
  1348. tag-up Sort alphabetically by last tag, A-Z.
  1349. tag-down Sort alphabetically by last tag, Z-A.
  1350. priority-up Sort numerically by priority, high priority last.
  1351. priority-down Sort numerically by priority, high priority first.
  1352. todo-state-up Sort by todo state, tasks that are done last.
  1353. todo-state-down Sort by todo state, tasks that are done first.
  1354. effort-up Sort numerically by estimated effort, high effort last.
  1355. effort-down Sort numerically by estimated effort, high effort first.
  1356. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1357. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1358. habit-up Put entries that are habits first
  1359. habit-down Put entries that are habits last
  1360. alpha-up Sort headlines alphabetically
  1361. alpha-down Sort headlines alphabetically, reversed
  1362. The different possibilities will be tried in sequence, and testing stops
  1363. if one comparison returns a \"not-equal\". For example, the default
  1364. '(time-up category-keep priority-down)
  1365. means: Pull out all entries having a specified time of day and sort them,
  1366. in order to make a time schedule for the current day the first thing in the
  1367. agenda listing for the day. Of the entries without a time indication, keep
  1368. the grouped in categories, don't sort the categories, but keep them in
  1369. the sequence given in `org-agenda-files'. Within each category sort by
  1370. priority.
  1371. Leaving out `category-keep' would mean that items will be sorted across
  1372. categories by priority.
  1373. Instead of a single list, this can also be a set of list for specific
  1374. contents, with a context symbol in the car of the list, any of
  1375. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1376. Custom commands can bind this variable in the options section."
  1377. :group 'org-agenda-sorting
  1378. :type `(choice
  1379. (repeat :tag "General" ,org-sorting-choice)
  1380. (list :tag "Individually"
  1381. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1382. (repeat ,org-sorting-choice))
  1383. (cons (const :tag "Strategy for TODO lists" todo)
  1384. (repeat ,org-sorting-choice))
  1385. (cons (const :tag "Strategy for Tags matches" tags)
  1386. (repeat ,org-sorting-choice))
  1387. (cons (const :tag "Strategy for search matches" search)
  1388. (repeat ,org-sorting-choice)))))
  1389. (defcustom org-agenda-cmp-user-defined nil
  1390. "A function to define the comparison `user-defined'.
  1391. This function must receive two arguments, agenda entry a and b.
  1392. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1393. the user comparison, return nil.
  1394. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1395. part of an agenda sorting strategy."
  1396. :group 'org-agenda-sorting
  1397. :type 'symbol)
  1398. (defcustom org-sort-agenda-notime-is-late t
  1399. "Non-nil means items without time are considered late.
  1400. This is only relevant for sorting. When t, items which have no explicit
  1401. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1402. do have a time. When nil, the default time is before 0:00. You can use this
  1403. option to decide if the schedule for today should come before or after timeless
  1404. agenda entries."
  1405. :group 'org-agenda-sorting
  1406. :type 'boolean)
  1407. (defcustom org-sort-agenda-noeffort-is-high t
  1408. "Non-nil means items without effort estimate are sorted as high effort.
  1409. This also applies when filtering an agenda view with respect to the
  1410. < or > effort operator. Then, tasks with no effort defined will be treated
  1411. as tasks with high effort.
  1412. When nil, such items are sorted as 0 minutes effort."
  1413. :group 'org-agenda-sorting
  1414. :type 'boolean)
  1415. (defgroup org-agenda-line-format nil
  1416. "Options concerning the entry prefix in the Org agenda display."
  1417. :tag "Org Agenda Line Format"
  1418. :group 'org-agenda)
  1419. (defcustom org-agenda-prefix-format
  1420. '((agenda . " %i %-12:c%?-12t% s")
  1421. (timeline . " % s")
  1422. (todo . " %i %-12:c")
  1423. (tags . " %i %-12:c")
  1424. (search . " %i %-12:c"))
  1425. "Format specifications for the prefix of items in the agenda views.
  1426. An alist with five entries, each for the different agenda types. The
  1427. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1428. The values are format strings.
  1429. This format works similar to a printf format, with the following meaning:
  1430. %c the category of the item, \"Diary\" for entries from the diary,
  1431. or as given by the CATEGORY keyword or derived from the file name
  1432. %e the effort required by the item
  1433. %l the level of the item (insert X space(s) if item is of level X)
  1434. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1435. %T the last tag of the item (ignore inherited tags, which come first)
  1436. %t the HH:MM time-of-day specification if one applies to the entry
  1437. %s Scheduling/Deadline information, a short string
  1438. %b show breadcrumbs, i.e., the names of the higher levels
  1439. %(expression) Eval EXPRESSION and replace the control string
  1440. by the result
  1441. All specifiers work basically like the standard `%s' of printf, but may
  1442. contain two additional characters: a question mark just after the `%'
  1443. and a whitespace/punctuation character just before the final letter.
  1444. If the first character after `%' is a question mark, the entire field
  1445. will only be included if the corresponding value applies to the current
  1446. entry. This is useful for fields which should have fixed width when
  1447. present, but zero width when absent. For example, \"%?-12t\" will
  1448. result in a 12 character time field if a time of the day is specified,
  1449. but will completely disappear in entries which do not contain a time.
  1450. If there is punctuation or whitespace character just before the
  1451. final format letter, this character will be appended to the field
  1452. value if the value is not empty. For example, the format
  1453. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1454. the category is empty, no additional colon is inserted.
  1455. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1456. which means:
  1457. - Indent the line with two space characters
  1458. - Give the category a 12 chars wide field, padded with whitespace on
  1459. the right (because of `-'). Append a colon if there is a category
  1460. (because of `:').
  1461. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1462. time, don't put in an empty field, just skip it (because of '?').
  1463. - Finally, put the scheduling information.
  1464. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1465. `org-agenda-remove-tags'.
  1466. Custom commands can set this variable in the options section."
  1467. :type '(choice
  1468. (string :tag "General format")
  1469. (list :greedy t :tag "View dependent"
  1470. (cons (const agenda) (string :tag "Format"))
  1471. (cons (const timeline) (string :tag "Format"))
  1472. (cons (const todo) (string :tag "Format"))
  1473. (cons (const tags) (string :tag "Format"))
  1474. (cons (const search) (string :tag "Format"))))
  1475. :group 'org-agenda-line-format)
  1476. (defvar org-prefix-format-compiled nil
  1477. "The compiled prefix format and associated variables.
  1478. This is a list where first element is a list of variable bindings, and second
  1479. element is the compiled format expression. See the variable
  1480. `org-agenda-prefix-format'.")
  1481. (defcustom org-agenda-todo-keyword-format "%-1s"
  1482. "Format for the TODO keyword in agenda lines.
  1483. Set this to something like \"%-12s\" if you want all TODO keywords
  1484. to occupy a fixed space in the agenda display."
  1485. :group 'org-agenda-line-format
  1486. :type 'string)
  1487. (defcustom org-agenda-diary-sexp-prefix nil
  1488. "A regexp that matches part of a diary sexp entry
  1489. which should be treated as scheduling/deadline information in
  1490. `org-agenda'.
  1491. For example, you can use this to extract the `diary-remind-message' from
  1492. `diary-remind' entries."
  1493. :group 'org-agenda-line-format
  1494. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1495. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1496. "Text preceding timerange entries in the agenda view.
  1497. This is a list with two strings. The first applies when the range
  1498. is entirely on one day. The second applies if the range spans several days.
  1499. The strings may have two \"%d\" format specifiers which will be filled
  1500. with the sequence number of the days, and the total number of days in the
  1501. range, respectively."
  1502. :group 'org-agenda-line-format
  1503. :type '(list
  1504. (string :tag "Deadline today ")
  1505. (choice :tag "Deadline relative"
  1506. (string :tag "Format string")
  1507. (function))))
  1508. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1509. "Text preceding scheduled items in the agenda view.
  1510. This is a list with two strings. The first applies when the item is
  1511. scheduled on the current day. The second applies when it has been scheduled
  1512. previously, it may contain a %d indicating that this is the nth time that
  1513. this item is scheduled, due to automatic rescheduling of unfinished items
  1514. for the following day. So this number is one larger than the number of days
  1515. that passed since this item was scheduled first."
  1516. :group 'org-agenda-line-format
  1517. :version "24.4"
  1518. :package-version '(Org . "8.0")
  1519. :type '(list
  1520. (string :tag "Scheduled today ")
  1521. (string :tag "Scheduled previously")))
  1522. (defcustom org-agenda-inactive-leader "["
  1523. "Text preceding item pulled into the agenda by inactive time stamps.
  1524. These entries are added to the agenda when pressing \"[\"."
  1525. :group 'org-agenda-line-format
  1526. :version "24.1"
  1527. :type 'string)
  1528. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1529. "Text preceding deadline items in the agenda view.
  1530. This is a list with three strings. The first applies when the item has its
  1531. deadline on the current day. The second applies when the deadline is in the
  1532. future, the third one when it is in the past. The strings may contain %d
  1533. to capture the number of days."
  1534. :group 'org-agenda-line-format
  1535. :version "24.4"
  1536. :package-version '(Org . "8.0")
  1537. :type '(list
  1538. (string :tag "Deadline today ")
  1539. (string :tag "Deadline in the future ")
  1540. (string :tag "Deadline in the past ")))
  1541. (defcustom org-agenda-remove-times-when-in-prefix t
  1542. "Non-nil means remove duplicate time specifications in agenda items.
  1543. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1544. time-of-day specification in a headline or diary entry is extracted and
  1545. placed into the prefix. If this option is non-nil, the original specification
  1546. \(a timestamp or -range, or just a plain time(range) specification like
  1547. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1548. cluttered.
  1549. The option can be t or nil. It may also be the symbol `beg', indicating
  1550. that the time should only be removed when it is located at the beginning of
  1551. the headline/diary entry."
  1552. :group 'org-agenda-line-format
  1553. :type '(choice
  1554. (const :tag "Always" t)
  1555. (const :tag "Never" nil)
  1556. (const :tag "When at beginning of entry" beg)))
  1557. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1558. "Non-nil means remove time ranges specifications in agenda
  1559. items that span on several days."
  1560. :group 'org-agenda-line-format
  1561. :version "24.1"
  1562. :type 'boolean)
  1563. (defcustom org-agenda-default-appointment-duration nil
  1564. "Default duration for appointments that only have a starting time.
  1565. When nil, no duration is specified in such cases.
  1566. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1567. :group 'org-agenda-line-format
  1568. :type '(choice
  1569. (integer :tag "Minutes")
  1570. (const :tag "No default duration")))
  1571. (defcustom org-agenda-show-inherited-tags t
  1572. "Non-nil means show inherited tags in each agenda line.
  1573. When this option is set to `always', it take precedences over
  1574. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1575. in every agenda.
  1576. When this option is set to t (the default), inherited tags are
  1577. shown when they are available, i.e. when the value of
  1578. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1579. given agenda type.
  1580. This can be set to a list of agenda types in which the agenda
  1581. must display the inherited tags. Available types are `todo',
  1582. `agenda', `search' and `timeline'.
  1583. When set to nil, never show inherited tags in agenda lines."
  1584. :group 'org-agenda-line-format
  1585. :group 'org-agenda
  1586. :version "24.3"
  1587. :type '(choice
  1588. (const :tag "Show inherited tags when available" t)
  1589. (const :tag "Always show inherited tags" always)
  1590. (repeat :tag "Show inherited tags only in selected agenda types"
  1591. (symbol :tag "Agenda type"))))
  1592. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1593. "List of agenda view types where to use tag inheritance.
  1594. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1595. controlled by `org-use-tag-inheritance'. In other agenda types,
  1596. `org-use-tag-inheritance' is not used for the selection of the
  1597. agenda entries. Still, you may want the agenda to be aware of
  1598. the inherited tags anyway, e.g. for later tag filtering.
  1599. Allowed value are `todo', `search', `timeline' and `agenda'.
  1600. This variable has no effect if `org-agenda-show-inherited-tags'
  1601. is set to `always'. In that case, the agenda is aware of those
  1602. tags.
  1603. The default value sets tags in every agenda type. Setting this
  1604. option to nil will speed up non-tags agenda view a lot."
  1605. :group 'org-agenda
  1606. :version "24.3"
  1607. :type '(choice
  1608. (const :tag "Use tag inheritance in all agenda types" t)
  1609. (repeat :tag "Use tag inheritance in selected agenda types"
  1610. (symbol :tag "Agenda type"))))
  1611. (defcustom org-agenda-hide-tags-regexp nil
  1612. "Regular expression used to filter away specific tags in agenda views.
  1613. This means that these tags will be present, but not be shown in the agenda
  1614. line. Secondary filtering will still work on the hidden tags.
  1615. Nil means don't hide any tags."
  1616. :group 'org-agenda-line-format
  1617. :type '(choice
  1618. (const :tag "Hide none" nil)
  1619. (string :tag "Regexp ")))
  1620. (defcustom org-agenda-remove-tags nil
  1621. "Non-nil means remove the tags from the headline copy in the agenda.
  1622. When this is the symbol `prefix', only remove tags when
  1623. `org-agenda-prefix-format' contains a `%T' specifier."
  1624. :group 'org-agenda-line-format
  1625. :type '(choice
  1626. (const :tag "Always" t)
  1627. (const :tag "Never" nil)
  1628. (const :tag "When prefix format contains %T" prefix)))
  1629. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1630. 'org-agenda-remove-tags)
  1631. (defcustom org-agenda-tags-column -80
  1632. "Shift tags in agenda items to this column.
  1633. If this number is positive, it specifies the column. If it is negative,
  1634. it means that the tags should be flushright to that column. For example,
  1635. -80 works well for a normal 80 character screen."
  1636. :group 'org-agenda-line-format
  1637. :type 'integer)
  1638. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1639. (defcustom org-agenda-fontify-priorities 'cookies
  1640. "Non-nil means highlight low and high priorities in agenda.
  1641. When t, the highest priority entries are bold, lowest priority italic.
  1642. However, settings in `org-priority-faces' will overrule these faces.
  1643. When this variable is the symbol `cookies', only fontify the
  1644. cookies, not the entire task.
  1645. This may also be an association list of priority faces, whose
  1646. keys are the character values of `org-highest-priority',
  1647. `org-default-priority', and `org-lowest-priority' (the default values
  1648. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1649. color as a string, or a list like `(:background \"Red\")'.
  1650. If it is a color, the variable `org-faces-easy-properties'
  1651. determines if it is a foreground or a background color."
  1652. :group 'org-agenda-line-format
  1653. :type '(choice
  1654. (const :tag "Never" nil)
  1655. (const :tag "Defaults" t)
  1656. (const :tag "Cookies only" cookies)
  1657. (repeat :tag "Specify"
  1658. (list (character :tag "Priority" :value ?A)
  1659. (choice :tag "Face "
  1660. (string :tag "Color")
  1661. (sexp :tag "Face"))))))
  1662. (defcustom org-agenda-day-face-function nil
  1663. "Function called to determine what face should be used to display a day.
  1664. The only argument passed to that function is the day. It should
  1665. returns a face, or nil if does not want to specify a face and let
  1666. the normal rules apply."
  1667. :group 'org-agenda-line-format
  1668. :version "24.1"
  1669. :type '(choice (const nil) (function)))
  1670. (defcustom org-agenda-category-icon-alist nil
  1671. "Alist of category icon to be displayed in agenda views.
  1672. Each entry should have the following format:
  1673. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1674. Where CATEGORY-REGEXP is a regexp matching the categories where
  1675. the icon should be displayed.
  1676. FILE-OR-DATA either a file path or a string containing image data.
  1677. The other fields can be omitted safely if not needed:
  1678. TYPE indicates the image type.
  1679. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1680. image data.
  1681. PROPS are additional image attributes to assign to the image,
  1682. like, e.g. `:ascent center'.
  1683. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1684. If you want to set the display properties yourself, just put a
  1685. list as second element:
  1686. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1687. For example, to display a 16px horizontal space for Emacs
  1688. category, you can use:
  1689. (\"Emacs\" \\='(space . (:width (16))))"
  1690. :group 'org-agenda-line-format
  1691. :version "24.1"
  1692. :type '(alist :key-type (string :tag "Regexp matching category")
  1693. :value-type (choice (list :tag "Icon"
  1694. (string :tag "File or data")
  1695. (symbol :tag "Type")
  1696. (boolean :tag "Data?")
  1697. (repeat :tag "Extra image properties" :inline t symbol))
  1698. (list :tag "Display properties" sexp))))
  1699. (defgroup org-agenda-column-view nil
  1700. "Options concerning column view in the agenda."
  1701. :tag "Org Agenda Column View"
  1702. :group 'org-agenda)
  1703. (defcustom org-agenda-view-columns-initially nil
  1704. "When non-nil, switch to columns view right after creating the agenda."
  1705. :group 'org-agenda-column-view
  1706. :type 'boolean
  1707. :version "25.2"
  1708. :package-version '(Org . "9.0")
  1709. :safe #'booleanp)
  1710. (defcustom org-agenda-columns-show-summaries t
  1711. "Non-nil means show summaries for columns displayed in the agenda view."
  1712. :group 'org-agenda-column-view
  1713. :type 'boolean)
  1714. (defcustom org-agenda-columns-compute-summary-properties t
  1715. "Non-nil means recompute all summary properties before column view.
  1716. When column view in the agenda is listing properties that have a summary
  1717. operator, it can go to all relevant buffers and recompute the summaries
  1718. there. This can mean overhead for the agenda column view, but is necessary
  1719. to have thing up to date.
  1720. As a special case, a CLOCKSUM property also makes sure that the clock
  1721. computations are current."
  1722. :group 'org-agenda-column-view
  1723. :type 'boolean)
  1724. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1725. "Non-nil means the duration of an appointment will add to day effort.
  1726. The property to which appointment durations will be added is the one given
  1727. in the option `org-effort-property'. If an appointment does not have
  1728. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1729. is not set, an appointment without end time will not contribute to the time
  1730. estimate."
  1731. :group 'org-agenda-column-view
  1732. :type 'boolean)
  1733. (defcustom org-agenda-auto-exclude-function nil
  1734. "A function called with a tag to decide if it is filtered on \
  1735. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1736. The sole argument to the function, which is called once for each
  1737. possible tag, is a string giving the name of the tag. The
  1738. function should return either nil if the tag should be included
  1739. as normal, or \"-<TAG>\" to exclude the tag.
  1740. Note that for the purpose of tag filtering, only the lower-case version of
  1741. all tags will be considered, so that this function will only ever see
  1742. the lower-case version of all tags."
  1743. :group 'org-agenda
  1744. :type '(choice (const nil) (function)))
  1745. (defcustom org-agenda-bulk-custom-functions nil
  1746. "Alist of characters and custom functions for bulk actions.
  1747. For example, this value makes those two functions available:
  1748. \\='((?R set-category)
  1749. (?C bulk-cut))
  1750. With selected entries in an agenda buffer, `B R' will call
  1751. the custom function `set-category' on the selected entries.
  1752. Note that functions in this alist don't need to be quoted."
  1753. :type '(alist :key-type character :value-type (group function))
  1754. :version "24.1"
  1755. :group 'org-agenda)
  1756. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1757. "Execute BODY with point at location given by `org-hd-marker' property.
  1758. If STRING is non-nil, the text property will be fetched from position 0
  1759. in that string. If STRING is nil, it will be fetched from the beginning
  1760. of the current line."
  1761. (org-with-gensyms (marker)
  1762. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1763. 'org-hd-marker ,string)))
  1764. (with-current-buffer (marker-buffer ,marker)
  1765. (save-excursion
  1766. (goto-char ,marker)
  1767. ,@body)))))
  1768. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1769. (defun org-add-agenda-custom-command (entry)
  1770. "Replace or add a command in `org-agenda-custom-commands'.
  1771. This is mostly for hacking and trying a new command - once the command
  1772. works you probably want to add it to `org-agenda-custom-commands' for good."
  1773. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1774. (if ass
  1775. (setcdr ass (cdr entry))
  1776. (push entry org-agenda-custom-commands))))
  1777. ;;; Define the org-agenda-mode
  1778. (defvar org-agenda-mode-map (make-sparse-keymap)
  1779. "Keymap for `org-agenda-mode'.")
  1780. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1781. (defvar org-agenda-menu) ; defined later in this file.
  1782. (defvar org-agenda-restrict nil) ; defined later in this file.
  1783. (defvar org-agenda-follow-mode nil)
  1784. (defvar org-agenda-entry-text-mode nil)
  1785. (defvar org-agenda-clockreport-mode nil)
  1786. (defvar org-agenda-show-log nil)
  1787. (defvar org-agenda-redo-command nil)
  1788. (defvar org-agenda-query-string nil)
  1789. (defvar org-agenda-mode-hook nil
  1790. "Hook run after `org-agenda-mode' is turned on.
  1791. The buffer is still writable when this hook is called.")
  1792. (defvar org-agenda-type nil)
  1793. (defvar org-agenda-force-single-file nil)
  1794. (defvar org-agenda-bulk-marked-entries nil
  1795. "List of markers that refer to marked entries in the agenda.")
  1796. (defvar org-agenda-current-date nil
  1797. "Active date when building the agenda.")
  1798. ;;; Multiple agenda buffers support
  1799. (defcustom org-agenda-sticky nil
  1800. "Non-nil means agenda q key will bury agenda buffers.
  1801. Agenda commands will then show existing buffer instead of generating new ones.
  1802. When nil, `q' will kill the single agenda buffer."
  1803. :group 'org-agenda
  1804. :version "24.3"
  1805. :type 'boolean)
  1806. ;;;###autoload
  1807. (defun org-toggle-sticky-agenda (&optional arg)
  1808. "Toggle `org-agenda-sticky'."
  1809. (interactive "P")
  1810. (let ((new-value (if arg
  1811. (> (prefix-numeric-value arg) 0)
  1812. (not org-agenda-sticky))))
  1813. (if (equal new-value org-agenda-sticky)
  1814. (and (called-interactively-p 'interactive)
  1815. (message "Sticky agenda was already %s"
  1816. (if org-agenda-sticky "enabled" "disabled")))
  1817. (setq org-agenda-sticky new-value)
  1818. (org-agenda-kill-all-agenda-buffers)
  1819. (and (called-interactively-p 'interactive)
  1820. (message "Sticky agenda %s"
  1821. (if org-agenda-sticky "enabled" "disabled"))))))
  1822. (defvar org-agenda-buffer nil
  1823. "Agenda buffer currently being generated.")
  1824. (defvar org-agenda-last-prefix-arg nil)
  1825. (defvar org-agenda-this-buffer-name nil)
  1826. (defvar org-agenda-doing-sticky-redo nil)
  1827. (defvar org-agenda-this-buffer-is-sticky nil)
  1828. (defvar org-agenda-last-indirect-buffer nil
  1829. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1830. (defconst org-agenda-local-vars
  1831. '(org-agenda-this-buffer-name
  1832. org-agenda-undo-list
  1833. org-agenda-pending-undo-list
  1834. org-agenda-follow-mode
  1835. org-agenda-entry-text-mode
  1836. org-agenda-clockreport-mode
  1837. org-agenda-show-log
  1838. org-agenda-redo-command
  1839. org-agenda-query-string
  1840. org-agenda-type
  1841. org-agenda-bulk-marked-entries
  1842. org-agenda-undo-has-started-in
  1843. org-agenda-info
  1844. org-agenda-pre-window-conf
  1845. org-agenda-columns-active
  1846. org-agenda-tag-filter
  1847. org-agenda-category-filter
  1848. org-agenda-top-headline-filter
  1849. org-agenda-regexp-filter
  1850. org-agenda-effort-filter
  1851. org-agenda-markers
  1852. org-agenda-last-search-view-search-was-boolean
  1853. org-agenda-last-indirect-buffer
  1854. org-agenda-filtered-by-category
  1855. org-agenda-filter-form
  1856. org-agenda-cycle-counter
  1857. org-agenda-last-prefix-arg)
  1858. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1859. (defun org-agenda-mode ()
  1860. "Mode for time-sorted view on action items in Org files.
  1861. The following commands are available:
  1862. \\{org-agenda-mode-map}"
  1863. (interactive)
  1864. (cond (org-agenda-doing-sticky-redo
  1865. ;; Refreshing sticky agenda-buffer
  1866. ;;
  1867. ;; Preserve the value of `org-agenda-local-vars' variables,
  1868. ;; while letting `kill-all-local-variables' kill the rest
  1869. (let ((save (buffer-local-variables)))
  1870. (kill-all-local-variables)
  1871. (mapc 'make-local-variable org-agenda-local-vars)
  1872. (dolist (elem save)
  1873. (let ((var (car elem))
  1874. (val (cdr elem)))
  1875. (when (and val
  1876. (member var org-agenda-local-vars))
  1877. (set var val)))))
  1878. (setq-local org-agenda-this-buffer-is-sticky t))
  1879. (org-agenda-sticky
  1880. ;; Creating a sticky Agenda buffer for the first time
  1881. (kill-all-local-variables)
  1882. (mapc 'make-local-variable org-agenda-local-vars)
  1883. (setq-local org-agenda-this-buffer-is-sticky t))
  1884. (t
  1885. ;; Creating a non-sticky agenda buffer
  1886. (kill-all-local-variables)
  1887. (setq-local org-agenda-this-buffer-is-sticky nil)))
  1888. (setq org-agenda-undo-list nil
  1889. org-agenda-pending-undo-list nil
  1890. org-agenda-bulk-marked-entries nil)
  1891. (setq major-mode 'org-agenda-mode)
  1892. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1893. (setq-local font-lock-global-modes (list 'not major-mode))
  1894. (setq mode-name "Org-Agenda")
  1895. (setq indent-tabs-mode nil)
  1896. (use-local-map org-agenda-mode-map)
  1897. (easy-menu-add org-agenda-menu)
  1898. (if org-startup-truncated (setq truncate-lines t))
  1899. (setq-local line-move-visual nil)
  1900. (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1901. (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1902. ;; Make sure properties are removed when copying text
  1903. (add-hook 'filter-buffer-substring-functions
  1904. (lambda (fun start end delete)
  1905. (substring-no-properties (funcall fun start end delete)))
  1906. nil t)
  1907. (unless org-agenda-keep-modes
  1908. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1909. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1910. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1911. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1912. (add-to-invisibility-spec '(org-filtered))
  1913. (add-to-invisibility-spec '(org-link))
  1914. (easy-menu-change
  1915. '("Agenda") "Agenda Files"
  1916. (append
  1917. (list
  1918. (vector
  1919. (if (get 'org-agenda-files 'org-restrict)
  1920. "Restricted to single file"
  1921. "Edit File List")
  1922. '(org-edit-agenda-file-list)
  1923. (not (get 'org-agenda-files 'org-restrict)))
  1924. "--")
  1925. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1926. (org-agenda-set-mode-name)
  1927. (apply
  1928. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1929. (list 'org-agenda-mode-hook)))
  1930. (substitute-key-definition 'undo 'org-agenda-undo
  1931. org-agenda-mode-map global-map)
  1932. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1933. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1934. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1935. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1936. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1937. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1938. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1939. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1940. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1941. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1942. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1943. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1944. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1945. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1946. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1947. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1948. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1949. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1950. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1951. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1952. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1953. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1954. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1955. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1956. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1957. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1958. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1959. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1960. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1961. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1962. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1963. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1964. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1965. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1966. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1967. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1968. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1969. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1970. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1971. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1972. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1973. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1974. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1975. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1976. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1977. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1978. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1979. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1980. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1981. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1982. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1983. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1984. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1985. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1986. (while l (org-defkey org-agenda-mode-map
  1987. (int-to-string (pop l)) 'digit-argument)))
  1988. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1989. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1990. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1991. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1992. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1993. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1994. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1995. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1996. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1997. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1998. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1999. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  2000. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2001. 'org-clock-modify-effort-estimate)
  2002. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  2003. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  2004. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  2005. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  2006. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  2007. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  2008. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  2009. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2010. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2011. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2012. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2013. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2014. (substitute-key-definition 'next-line 'org-agenda-next-line
  2015. org-agenda-mode-map global-map)
  2016. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2017. org-agenda-mode-map global-map)
  2018. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2019. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2021. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2022. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2023. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2024. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2025. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2026. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2027. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2028. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2029. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2030. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2031. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2033. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2034. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2035. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2036. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2037. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2038. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2039. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2040. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2041. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2042. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2043. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2044. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2045. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2046. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2048. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2049. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2050. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2051. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2052. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2053. (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
  2054. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2055. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2056. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2057. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2058. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2059. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2060. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2061. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2062. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2063. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2064. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2065. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2066. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2067. (when org-agenda-mouse-1-follows-link
  2068. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2069. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2070. '("Agenda"
  2071. ("Agenda Files")
  2072. "--"
  2073. ("Agenda Dates"
  2074. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2075. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2076. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2077. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2078. "--"
  2079. ("View"
  2080. ["Day View" org-agenda-day-view
  2081. :active (org-agenda-check-type nil 'agenda)
  2082. :style radio :selected (eq org-agenda-current-span 'day)
  2083. :keys "v d (or just d)"]
  2084. ["Week View" org-agenda-week-view
  2085. :active (org-agenda-check-type nil 'agenda)
  2086. :style radio :selected (eq org-agenda-current-span 'week)
  2087. :keys "v w"]
  2088. ["Fortnight View" org-agenda-fortnight-view
  2089. :active (org-agenda-check-type nil 'agenda)
  2090. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2091. :keys "v f"]
  2092. ["Month View" org-agenda-month-view
  2093. :active (org-agenda-check-type nil 'agenda)
  2094. :style radio :selected (eq org-agenda-current-span 'month)
  2095. :keys "v m"]
  2096. ["Year View" org-agenda-year-view
  2097. :active (org-agenda-check-type nil 'agenda)
  2098. :style radio :selected (eq org-agenda-current-span 'year)
  2099. :keys "v y"]
  2100. "--"
  2101. ["Include Diary" org-agenda-toggle-diary
  2102. :style toggle :selected org-agenda-include-diary
  2103. :active (org-agenda-check-type nil 'agenda)]
  2104. ["Include Deadlines" org-agenda-toggle-deadlines
  2105. :style toggle :selected org-agenda-include-deadlines
  2106. :active (org-agenda-check-type nil 'agenda)]
  2107. ["Use Time Grid" org-agenda-toggle-time-grid
  2108. :style toggle :selected org-agenda-use-time-grid
  2109. :active (org-agenda-check-type nil 'agenda)]
  2110. "--"
  2111. ["Show clock report" org-agenda-clockreport-mode
  2112. :style toggle :selected org-agenda-clockreport-mode
  2113. :active (org-agenda-check-type nil 'agenda)]
  2114. ["Show some entry text" org-agenda-entry-text-mode
  2115. :style toggle :selected org-agenda-entry-text-mode
  2116. :active t]
  2117. "--"
  2118. ["Show Logbook entries" org-agenda-log-mode
  2119. :style toggle :selected org-agenda-show-log
  2120. :active (org-agenda-check-type nil 'agenda 'timeline)
  2121. :keys "v l (or just l)"]
  2122. ["Include archived trees" org-agenda-archives-mode
  2123. :style toggle :selected org-agenda-archives-mode :active t
  2124. :keys "v a"]
  2125. ["Include archive files" (org-agenda-archives-mode t)
  2126. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2127. :keys "v A"]
  2128. "--"
  2129. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2130. ["Write view to file" org-agenda-write t]
  2131. ["Rebuild buffer" org-agenda-redo t]
  2132. ["Save all Org buffers" org-save-all-org-buffers t]
  2133. "--"
  2134. ["Show original entry" org-agenda-show t]
  2135. ["Go To (other window)" org-agenda-goto t]
  2136. ["Go To (this window)" org-agenda-switch-to t]
  2137. ["Capture with cursor date" org-agenda-capture t]
  2138. ["Follow Mode" org-agenda-follow-mode
  2139. :style toggle :selected org-agenda-follow-mode :active t]
  2140. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2141. "--"
  2142. ("TODO"
  2143. ["Cycle TODO" org-agenda-todo t]
  2144. ["Next TODO set" org-agenda-todo-nextset t]
  2145. ["Previous TODO set" org-agenda-todo-previousset t]
  2146. ["Add note" org-agenda-add-note t])
  2147. ("Archive/Refile/Delete"
  2148. ["Archive default" org-agenda-archive-default t]
  2149. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2150. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2151. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2152. ["Archive subtree" org-agenda-archive t]
  2153. "--"
  2154. ["Refile" org-agenda-refile t]
  2155. "--"
  2156. ["Delete subtree" org-agenda-kill t])
  2157. ("Bulk action"
  2158. ["Mark entry" org-agenda-bulk-mark t]
  2159. ["Mark all" org-agenda-bulk-mark-all t]
  2160. ["Unmark entry" org-agenda-bulk-unmark t]
  2161. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2162. ["Toggle mark" org-agenda-bulk-toggle t]
  2163. ["Toggle all" org-agenda-bulk-toggle-all t]
  2164. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2165. ["Act on all marked" org-agenda-bulk-action t]
  2166. "--"
  2167. ("Tags and Properties"
  2168. ["Show all Tags" org-agenda-show-tags t]
  2169. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2170. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2171. "--"
  2172. ["Column View" org-columns t])
  2173. ("Deadline/Schedule"
  2174. ["Schedule" org-agenda-schedule t]
  2175. ["Set Deadline" org-agenda-deadline t]
  2176. "--"
  2177. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2178. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2179. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2180. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2181. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2182. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2183. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2184. ("Clock and Effort"
  2185. ["Clock in" org-agenda-clock-in t]
  2186. ["Clock out" org-agenda-clock-out t]
  2187. ["Clock cancel" org-agenda-clock-cancel t]
  2188. ["Goto running clock" org-clock-goto t]
  2189. "--"
  2190. ["Set Effort" org-agenda-set-effort t]
  2191. ["Change clocked effort" org-clock-modify-effort-estimate
  2192. (org-clock-is-active)])
  2193. ("Priority"
  2194. ["Set Priority" org-agenda-priority t]
  2195. ["Increase Priority" org-agenda-priority-up t]
  2196. ["Decrease Priority" org-agenda-priority-down t]
  2197. ["Show Priority" org-show-priority t])
  2198. ("Calendar/Diary"
  2199. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2200. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2201. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2202. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2203. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2204. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2205. "--"
  2206. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2207. "--"
  2208. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2209. "--"
  2210. ("MobileOrg"
  2211. ["Push Files and Views" org-mobile-push t]
  2212. ["Get Captured and Flagged" org-mobile-pull t]
  2213. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2214. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2215. "--"
  2216. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2217. "--"
  2218. ["Quit" org-agenda-quit t]
  2219. ["Exit and Release Buffers" org-agenda-exit t]
  2220. ))
  2221. ;;; Agenda undo
  2222. (defvar org-agenda-allow-remote-undo t
  2223. "Non-nil means allow remote undo from the agenda buffer.")
  2224. (defvar org-agenda-undo-has-started-in nil
  2225. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2226. (defun org-agenda-undo ()
  2227. "Undo a remote editing step in the agenda.
  2228. This undoes changes both in the agenda buffer and in the remote buffer
  2229. that have been changed along."
  2230. (interactive)
  2231. (or org-agenda-allow-remote-undo
  2232. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2233. (if (not (eq this-command last-command))
  2234. (setq org-agenda-undo-has-started-in nil
  2235. org-agenda-pending-undo-list org-agenda-undo-list))
  2236. (if (not org-agenda-pending-undo-list)
  2237. (user-error "No further undo information"))
  2238. (let* ((entry (pop org-agenda-pending-undo-list))
  2239. buf line cmd rembuf)
  2240. (setq cmd (pop entry) line (pop entry))
  2241. (setq rembuf (nth 2 entry))
  2242. (org-with-remote-undo rembuf
  2243. (while (bufferp (setq buf (pop entry)))
  2244. (if (pop entry)
  2245. (with-current-buffer buf
  2246. (let ((last-undo-buffer buf)
  2247. (inhibit-read-only t))
  2248. (unless (memq buf org-agenda-undo-has-started-in)
  2249. (push buf org-agenda-undo-has-started-in)
  2250. (make-local-variable 'pending-undo-list)
  2251. (undo-start))
  2252. (while (and pending-undo-list
  2253. (listp pending-undo-list)
  2254. (not (car pending-undo-list)))
  2255. (pop pending-undo-list))
  2256. (undo-more 1))))))
  2257. (org-goto-line line)
  2258. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2259. (defun org-verify-change-for-undo (l1 l2)
  2260. "Verify that a real change occurred between the undo lists L1 and L2."
  2261. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2262. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2263. (not (eq l1 l2)))
  2264. ;;; Agenda dispatch
  2265. (defvar org-agenda-restrict-begin (make-marker))
  2266. (defvar org-agenda-restrict-end (make-marker))
  2267. (defvar org-agenda-last-dispatch-buffer nil)
  2268. (defvar org-agenda-overriding-restriction nil)
  2269. (defcustom org-agenda-custom-commands-contexts nil
  2270. "Alist of custom agenda keys and contextual rules.
  2271. For example, if you have a custom agenda command \"p\" and you
  2272. want this command to be accessible only from plain text files,
  2273. use this:
  2274. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2275. Here are the available contexts definitions:
  2276. in-file: command displayed only in matching files
  2277. in-mode: command displayed only in matching modes
  2278. not-in-file: command not displayed in matching files
  2279. not-in-mode: command not displayed in matching modes
  2280. in-buffer: command displayed only in matching buffers
  2281. not-in-buffer: command not displayed in matching buffers
  2282. [function]: a custom function taking no argument
  2283. If you define several checks, the agenda command will be
  2284. accessible if there is at least one valid check.
  2285. You can also bind a key to another agenda custom command
  2286. depending on contextual rules.
  2287. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2288. Here it means: in .txt files, use \"p\" as the key for the
  2289. agenda command otherwise associated with \"q\". (The command
  2290. originally associated with \"q\" is not displayed to avoid
  2291. duplicates.)"
  2292. :version "24.3"
  2293. :group 'org-agenda-custom-commands
  2294. :type '(repeat (list :tag "Rule"
  2295. (string :tag " Agenda key")
  2296. (string :tag "Replace by command")
  2297. (repeat :tag "Available when"
  2298. (choice
  2299. (cons :tag "Condition"
  2300. (choice
  2301. (const :tag "In file" in-file)
  2302. (const :tag "Not in file" not-in-file)
  2303. (const :tag "In buffer" in-buffer)
  2304. (const :tag "Not in buffer" not-in-buffer)
  2305. (const :tag "In mode" in-mode)
  2306. (const :tag "Not in mode" not-in-mode))
  2307. (regexp))
  2308. (function :tag "Custom function"))))))
  2309. (defcustom org-agenda-max-entries nil
  2310. "Maximum number of entries to display in an agenda.
  2311. This can be nil (no limit) or an integer or an alist of agenda
  2312. types with an associated number of entries to display in this
  2313. type."
  2314. :version "24.4"
  2315. :package-version '(Org . "8.0")
  2316. :group 'org-agenda-custom-commands
  2317. :type '(choice (symbol :tag "No limit" nil)
  2318. (integer :tag "Max number of entries")
  2319. (repeat
  2320. (cons (choice :tag "Agenda type"
  2321. (const agenda)
  2322. (const todo)
  2323. (const tags)
  2324. (const search)
  2325. (const timeline))
  2326. (integer :tag "Max number of entries")))))
  2327. (defcustom org-agenda-max-todos nil
  2328. "Maximum number of TODOs to display in an agenda.
  2329. This can be nil (no limit) or an integer or an alist of agenda
  2330. types with an associated number of entries to display in this
  2331. type."
  2332. :version "24.4"
  2333. :package-version '(Org . "8.0")
  2334. :group 'org-agenda-custom-commands
  2335. :type '(choice (symbol :tag "No limit" nil)
  2336. (integer :tag "Max number of TODOs")
  2337. (repeat
  2338. (cons (choice :tag "Agenda type"
  2339. (const agenda)
  2340. (const todo)
  2341. (const tags)
  2342. (const search)
  2343. (const timeline))
  2344. (integer :tag "Max number of TODOs")))))
  2345. (defcustom org-agenda-max-tags nil
  2346. "Maximum number of tagged entries to display in an agenda.
  2347. This can be nil (no limit) or an integer or an alist of agenda
  2348. types with an associated number of entries to display in this
  2349. type."
  2350. :version "24.4"
  2351. :package-version '(Org . "8.0")
  2352. :group 'org-agenda-custom-commands
  2353. :type '(choice (symbol :tag "No limit" nil)
  2354. (integer :tag "Max number of tagged entries")
  2355. (repeat
  2356. (cons (choice :tag "Agenda type"
  2357. (const agenda)
  2358. (const todo)
  2359. (const tags)
  2360. (const search)
  2361. (const timeline))
  2362. (integer :tag "Max number of tagged entries")))))
  2363. (defcustom org-agenda-max-effort nil
  2364. "Maximum cumulated effort duration for the agenda.
  2365. This can be nil (no limit) or a number of minutes (as an integer)
  2366. or an alist of agenda types with an associated number of minutes
  2367. to limit entries to in this type."
  2368. :version "24.4"
  2369. :package-version '(Org . "8.0")
  2370. :group 'org-agenda-custom-commands
  2371. :type '(choice (symbol :tag "No limit" nil)
  2372. (integer :tag "Max number of minutes")
  2373. (repeat
  2374. (cons (choice :tag "Agenda type"
  2375. (const agenda)
  2376. (const todo)
  2377. (const tags)
  2378. (const search)
  2379. (const timeline))
  2380. (integer :tag "Max number of minutes")))))
  2381. (defvar org-agenda-keep-restricted-file-list nil)
  2382. (defvar org-keys nil)
  2383. (defvar org-match nil)
  2384. ;;;###autoload
  2385. (defun org-agenda (&optional arg org-keys restriction)
  2386. "Dispatch agenda commands to collect entries to the agenda buffer.
  2387. Prompts for a command to execute. Any prefix arg will be passed
  2388. on to the selected command. The default selections are:
  2389. a Call `org-agenda-list' to display the agenda for current day or week.
  2390. t Call `org-todo-list' to display the global todo list.
  2391. T Call `org-todo-list' to display the global todo list, select only
  2392. entries with a specific TODO keyword (the user gets a prompt).
  2393. m Call `org-tags-view' to display headlines with tags matching
  2394. a condition (the user is prompted for the condition).
  2395. M Like `m', but select only TODO entries, no ordinary headlines.
  2396. L Create a timeline for the current buffer.
  2397. e Export views to associated files.
  2398. s Search entries for keywords.
  2399. S Search entries for keywords, only with TODO keywords.
  2400. / Multi occur across all agenda files and also files listed
  2401. in `org-agenda-text-search-extra-files'.
  2402. < Restrict agenda commands to buffer, subtree, or region.
  2403. Press several times to get the desired effect.
  2404. > Remove a previous restriction.
  2405. # List \"stuck\" projects.
  2406. ! Configure what \"stuck\" means.
  2407. C Configure custom agenda commands.
  2408. More commands can be added by configuring the variable
  2409. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2410. searches can be pre-defined in this way.
  2411. If the current buffer is in Org mode and visiting a file, you can also
  2412. first press `<' once to indicate that the agenda should be temporarily
  2413. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2414. Pressing `<' twice means to restrict to the current subtree or region
  2415. \(if active)."
  2416. (interactive "P")
  2417. (catch 'exit
  2418. (let* ((prefix-descriptions nil)
  2419. (org-agenda-buffer-name org-agenda-buffer-name)
  2420. (org-agenda-window-setup (if (equal (buffer-name)
  2421. org-agenda-buffer-name)
  2422. 'current-window
  2423. org-agenda-window-setup))
  2424. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2425. (org-agenda-custom-commands
  2426. ;; normalize different versions
  2427. (delq nil
  2428. (mapcar
  2429. (lambda (x)
  2430. (cond ((stringp (cdr x))
  2431. (push x prefix-descriptions)
  2432. nil)
  2433. ((stringp (nth 1 x)) x)
  2434. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2435. (t (cons (car x) (cons "" (cdr x))))))
  2436. org-agenda-custom-commands)))
  2437. (org-agenda-custom-commands
  2438. (org-contextualize-keys
  2439. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2440. (buf (current-buffer))
  2441. (bfn (buffer-file-name (buffer-base-buffer)))
  2442. entry key type org-match lprops ans)
  2443. ;; Turn off restriction unless there is an overriding one,
  2444. (unless org-agenda-overriding-restriction
  2445. (unless org-agenda-keep-restricted-file-list
  2446. ;; There is a request to keep the file list in place
  2447. (put 'org-agenda-files 'org-restrict nil))
  2448. (setq org-agenda-restrict nil)
  2449. (move-marker org-agenda-restrict-begin nil)
  2450. (move-marker org-agenda-restrict-end nil))
  2451. ;; Delete old local properties
  2452. (put 'org-agenda-redo-command 'org-lprops nil)
  2453. ;; Delete previously set last-arguments
  2454. (put 'org-agenda-redo-command 'last-args nil)
  2455. ;; Remember where this call originated
  2456. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2457. (unless org-keys
  2458. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2459. org-keys (car ans)
  2460. restriction (cdr ans)))
  2461. ;; If we have sticky agenda buffers, set a name for the buffer,
  2462. ;; depending on the invoking keys. The user may still set this
  2463. ;; as a command option, which will overwrite what we do here.
  2464. (if org-agenda-sticky
  2465. (setq org-agenda-buffer-name
  2466. (format "*Org Agenda(%s)*" org-keys)))
  2467. ;; Establish the restriction, if any
  2468. (when (and (not org-agenda-overriding-restriction) restriction)
  2469. (put 'org-agenda-files 'org-restrict (list bfn))
  2470. (cond
  2471. ((eq restriction 'region)
  2472. (setq org-agenda-restrict (current-buffer))
  2473. (move-marker org-agenda-restrict-begin (region-beginning))
  2474. (move-marker org-agenda-restrict-end (region-end)))
  2475. ((eq restriction 'subtree)
  2476. (save-excursion
  2477. (setq org-agenda-restrict (current-buffer))
  2478. (org-back-to-heading t)
  2479. (move-marker org-agenda-restrict-begin (point))
  2480. (move-marker org-agenda-restrict-end
  2481. (progn (org-end-of-subtree t)))))))
  2482. ;; For example the todo list should not need it (but does...)
  2483. (cond
  2484. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2485. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2486. (progn
  2487. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2488. lprops (nth 4 entry))
  2489. (if org-agenda-sticky
  2490. (setq org-agenda-buffer-name
  2491. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2492. (format "*Org Agenda(%s)*" org-keys))))
  2493. (put 'org-agenda-redo-command 'org-lprops lprops)
  2494. (cond
  2495. ((eq type 'agenda)
  2496. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2497. ((eq type 'agenda*)
  2498. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2499. ((eq type 'alltodo)
  2500. (org-let lprops '(org-todo-list current-prefix-arg)))
  2501. ((eq type 'search)
  2502. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2503. ((eq type 'stuck)
  2504. (org-let lprops '(org-agenda-list-stuck-projects
  2505. current-prefix-arg)))
  2506. ((eq type 'tags)
  2507. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2508. ((eq type 'tags-todo)
  2509. (org-let lprops '(org-tags-view '(4) org-match)))
  2510. ((eq type 'todo)
  2511. (org-let lprops '(org-todo-list org-match)))
  2512. ((eq type 'tags-tree)
  2513. (org-check-for-org-mode)
  2514. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2515. ((eq type 'todo-tree)
  2516. (org-check-for-org-mode)
  2517. (org-let lprops
  2518. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2519. (regexp-quote org-match) "\\>"))))
  2520. ((eq type 'occur-tree)
  2521. (org-check-for-org-mode)
  2522. (org-let lprops '(org-occur org-match)))
  2523. ((functionp type)
  2524. (org-let lprops '(funcall type org-match)))
  2525. ((fboundp type)
  2526. (org-let lprops '(funcall type org-match)))
  2527. (t (user-error "Invalid custom agenda command type %s" type))))
  2528. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2529. ((equal org-keys "C")
  2530. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2531. (customize-variable 'org-agenda-custom-commands))
  2532. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2533. ((equal org-keys "s") (call-interactively 'org-search-view))
  2534. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2535. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2536. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2537. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2538. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2539. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2540. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2541. (add-hook
  2542. 'post-command-hook
  2543. (lambda ()
  2544. (unless (current-message)
  2545. (let* ((m (org-agenda-get-any-marker))
  2546. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2547. (when note
  2548. (message (concat
  2549. "FLAGGING-NOTE ([?] for more info): "
  2550. (org-add-props
  2551. (replace-regexp-in-string
  2552. "\\\\n" "//"
  2553. (copy-sequence note))
  2554. nil 'face 'org-warning)))))))
  2555. t t))
  2556. ((equal org-keys "L")
  2557. (unless (derived-mode-p 'org-mode)
  2558. (user-error "This is not an Org file"))
  2559. (unless restriction
  2560. (put 'org-agenda-files 'org-restrict (list bfn))
  2561. (org-call-with-arg 'org-timeline arg)))
  2562. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2563. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2564. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2565. (t (user-error "Invalid agenda key"))))))
  2566. (defvar org-agenda-multi)
  2567. (defun org-agenda-append-agenda ()
  2568. "Append another agenda view to the current one.
  2569. This function allows interactive building of block agendas.
  2570. Agenda views are separated by `org-agenda-block-separator'."
  2571. (interactive)
  2572. (unless (derived-mode-p 'org-agenda-mode)
  2573. (user-error "Can only append from within agenda buffer"))
  2574. (let ((org-agenda-multi t))
  2575. (org-agenda)
  2576. (widen)
  2577. (org-agenda-finalize)
  2578. (setq buffer-read-only t)
  2579. (org-agenda-fit-window-to-buffer)))
  2580. (defun org-agenda-normalize-custom-commands (cmds)
  2581. "Normalize custom commands CMDS."
  2582. (delq nil
  2583. (mapcar
  2584. (lambda (x)
  2585. (cond ((stringp (cdr x)) nil)
  2586. ((stringp (nth 1 x)) x)
  2587. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2588. (t (cons (car x) (cons "" (cdr x))))))
  2589. cmds)))
  2590. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2591. "The user interface for selecting an agenda command."
  2592. (catch 'exit
  2593. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2594. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2595. (region-p (org-region-active-p))
  2596. (custom org-agenda-custom-commands)
  2597. (selstring "")
  2598. restriction second-time
  2599. c entry key type match prefixes rmheader header-end custom1 desc
  2600. line lines left right n n1)
  2601. (save-window-excursion
  2602. (delete-other-windows)
  2603. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2604. (erase-buffer)
  2605. (insert (eval-when-compile
  2606. (let ((header
  2607. "Press key for an agenda command: < Buffer, subtree/region restriction
  2608. -------------------------------- > Remove restriction
  2609. a Agenda for current week or day e Export agenda views
  2610. t List of all TODO entries T Entries with special TODO kwd
  2611. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2612. s Search for keywords S Like s, but only TODO entries
  2613. L Timeline for current buffer # List stuck projects (!=configure)
  2614. / Multi-occur C Configure custom agenda commands
  2615. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2616. ")
  2617. (start 0))
  2618. (while (string-match
  2619. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2620. header start)
  2621. (setq start (match-end 0))
  2622. (add-text-properties (match-beginning 2) (match-end 2)
  2623. '(face bold) header))
  2624. header)))
  2625. (setq header-end (point-marker))
  2626. (while t
  2627. (setq custom1 custom)
  2628. (when (eq rmheader t)
  2629. (org-goto-line 1)
  2630. (re-search-forward ":" nil t)
  2631. (delete-region (match-end 0) (point-at-eol))
  2632. (forward-char 1)
  2633. (looking-at "-+")
  2634. (delete-region (match-end 0) (point-at-eol))
  2635. (move-marker header-end (match-end 0)))
  2636. (goto-char header-end)
  2637. (delete-region (point) (point-max))
  2638. ;; Produce all the lines that describe custom commands and prefixes
  2639. (setq lines nil)
  2640. (while (setq entry (pop custom1))
  2641. (setq key (car entry) desc (nth 1 entry)
  2642. type (nth 2 entry)
  2643. match (nth 3 entry))
  2644. (if (> (length key) 1)
  2645. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2646. (setq line
  2647. (format
  2648. "%-4s%-14s"
  2649. (org-add-props (copy-sequence key)
  2650. '(face bold))
  2651. (cond
  2652. ((string-match "\\S-" desc) desc)
  2653. ((eq type 'agenda) "Agenda for current week or day")
  2654. ((eq type 'agenda*) "Appointments for current week or day")
  2655. ((eq type 'alltodo) "List of all TODO entries")
  2656. ((eq type 'search) "Word search")
  2657. ((eq type 'stuck) "List of stuck projects")
  2658. ((eq type 'todo) "TODO keyword")
  2659. ((eq type 'tags) "Tags query")
  2660. ((eq type 'tags-todo) "Tags (TODO)")
  2661. ((eq type 'tags-tree) "Tags tree")
  2662. ((eq type 'todo-tree) "TODO kwd tree")
  2663. ((eq type 'occur-tree) "Occur tree")
  2664. ((functionp type) (if (symbolp type)
  2665. (symbol-name type)
  2666. "Lambda expression"))
  2667. (t "???"))))
  2668. (if org-agenda-menu-show-matcher
  2669. (setq line
  2670. (concat line ": "
  2671. (cond
  2672. ((stringp match)
  2673. (setq match (copy-sequence match))
  2674. (org-add-props match nil 'face 'org-warning))
  2675. ((listp type)
  2676. (format "set of %d commands" (length type))))))
  2677. (if (org-string-nw-p match)
  2678. (add-text-properties
  2679. 0 (length line) (list 'help-echo
  2680. (concat "Matcher: " match)) line)))
  2681. (push line lines)))
  2682. (setq lines (nreverse lines))
  2683. (when prefixes
  2684. (mapc (lambda (x)
  2685. (push
  2686. (format "%s %s"
  2687. (org-add-props (char-to-string x)
  2688. nil 'face 'bold)
  2689. (or (cdr (assoc (concat selstring
  2690. (char-to-string x))
  2691. prefix-descriptions))
  2692. "Prefix key"))
  2693. lines))
  2694. prefixes))
  2695. ;; Check if we should display in two columns
  2696. (if org-agenda-menu-two-columns
  2697. (progn
  2698. (setq n (length lines)
  2699. n1 (+ (/ n 2) (mod n 2))
  2700. right (nthcdr n1 lines)
  2701. left (copy-sequence lines))
  2702. (setcdr (nthcdr (1- n1) left) nil))
  2703. (setq left lines right nil))
  2704. (while left
  2705. (insert "\n" (pop left))
  2706. (when right
  2707. (if (< (current-column) 40)
  2708. (move-to-column 40 t)
  2709. (insert " "))
  2710. (insert (pop right))))
  2711. ;; Make the window the right size
  2712. (goto-char (point-min))
  2713. (if second-time
  2714. (if (not (pos-visible-in-window-p (point-max)))
  2715. (org-fit-window-to-buffer))
  2716. (setq second-time t)
  2717. (org-fit-window-to-buffer))
  2718. ;; Ask for selection
  2719. (message "Press key for agenda command%s:"
  2720. (if (or restrict-ok org-agenda-overriding-restriction)
  2721. (if org-agenda-overriding-restriction
  2722. " (restriction lock active)"
  2723. (if restriction
  2724. (format " (restricted to %s)" restriction)
  2725. " (unrestricted)"))
  2726. ""))
  2727. (setq c (read-char-exclusive))
  2728. (message "")
  2729. (cond
  2730. ((assoc (char-to-string c) custom)
  2731. (setq selstring (concat selstring (char-to-string c)))
  2732. (throw 'exit (cons selstring restriction)))
  2733. ((memq c prefixes)
  2734. (setq selstring (concat selstring (char-to-string c))
  2735. prefixes nil
  2736. rmheader (or rmheader t)
  2737. custom (delq nil (mapcar
  2738. (lambda (x)
  2739. (if (or (= (length (car x)) 1)
  2740. (/= (string-to-char (car x)) c))
  2741. nil
  2742. (cons (substring (car x) 1) (cdr x))))
  2743. custom))))
  2744. ((eq c ?*)
  2745. (call-interactively 'org-toggle-sticky-agenda)
  2746. (sit-for 2))
  2747. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2748. (message "Restriction is only possible in Org buffers")
  2749. (ding) (sit-for 1))
  2750. ((eq c ?1)
  2751. (org-agenda-remove-restriction-lock 'noupdate)
  2752. (setq restriction 'buffer))
  2753. ((eq c ?0)
  2754. (org-agenda-remove-restriction-lock 'noupdate)
  2755. (setq restriction (if region-p 'region 'subtree)))
  2756. ((eq c ?<)
  2757. (org-agenda-remove-restriction-lock 'noupdate)
  2758. (setq restriction
  2759. (cond
  2760. ((eq restriction 'buffer)
  2761. (if region-p 'region 'subtree))
  2762. ((memq restriction '(subtree region))
  2763. nil)
  2764. (t 'buffer))))
  2765. ((eq c ?>)
  2766. (org-agenda-remove-restriction-lock 'noupdate)
  2767. (setq restriction nil))
  2768. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2769. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2770. ((and (> (length selstring) 0) (eq c ?\d))
  2771. (delete-window)
  2772. (org-agenda-get-restriction-and-command prefix-descriptions))
  2773. ((equal c ?q) (error "Abort"))
  2774. (t (user-error "Invalid key %c" c))))))))
  2775. (defun org-agenda-fit-window-to-buffer ()
  2776. "Fit the window to the buffer size."
  2777. (and (memq org-agenda-window-setup '(reorganize-frame))
  2778. (fboundp 'fit-window-to-buffer)
  2779. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2780. (= (car org-agenda-window-frame-fractions) 1.0))
  2781. (delete-other-windows)
  2782. (org-fit-window-to-buffer
  2783. nil
  2784. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2785. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2786. (defvar org-cmd nil)
  2787. (defvar org-agenda-overriding-cmd nil)
  2788. (defvar org-agenda-overriding-arguments nil)
  2789. (defvar org-agenda-overriding-cmd-arguments nil)
  2790. (defun org-agenda-run-series (name series)
  2791. "Run agenda NAME as a SERIES of agenda commands."
  2792. (org-let (nth 1 series) '(org-agenda-prepare name))
  2793. ;; We need to reset agenda markers here, because when constructing a
  2794. ;; block agenda, the individual blocks do not do that.
  2795. (org-agenda-reset-markers)
  2796. (let* ((org-agenda-multi t)
  2797. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2798. (cmds (car series))
  2799. (gprops (nth 1 series))
  2800. match ;; The byte compiler incorrectly complains about this. Keep it!
  2801. org-cmd type lprops)
  2802. (while (setq org-cmd (pop cmds))
  2803. (setq type (car org-cmd))
  2804. (setq match (eval (nth 1 org-cmd)))
  2805. (setq lprops (nth 2 org-cmd))
  2806. (let ((org-agenda-overriding-arguments
  2807. (if (eq org-agenda-overriding-cmd org-cmd)
  2808. (or org-agenda-overriding-arguments
  2809. org-agenda-overriding-cmd-arguments))))
  2810. (cond
  2811. ((eq type 'agenda)
  2812. (org-let2 gprops lprops
  2813. '(call-interactively 'org-agenda-list)))
  2814. ((eq type 'agenda*)
  2815. (org-let2 gprops lprops
  2816. '(funcall 'org-agenda-list nil nil t)))
  2817. ((eq type 'alltodo)
  2818. (org-let2 gprops lprops
  2819. '(call-interactively 'org-todo-list)))
  2820. ((eq type 'search)
  2821. (org-let2 gprops lprops
  2822. '(org-search-view current-prefix-arg match nil)))
  2823. ((eq type 'stuck)
  2824. (org-let2 gprops lprops
  2825. '(call-interactively 'org-agenda-list-stuck-projects)))
  2826. ((eq type 'tags)
  2827. (org-let2 gprops lprops
  2828. '(org-tags-view current-prefix-arg match)))
  2829. ((eq type 'tags-todo)
  2830. (org-let2 gprops lprops
  2831. '(org-tags-view '(4) match)))
  2832. ((eq type 'todo)
  2833. (org-let2 gprops lprops
  2834. '(org-todo-list match)))
  2835. ((fboundp type)
  2836. (org-let2 gprops lprops
  2837. '(funcall type match)))
  2838. (t (error "Invalid type in command series")))))
  2839. (widen)
  2840. (let ((inhibit-read-only t))
  2841. (add-text-properties (point-min) (point-max)
  2842. `(org-series t org-series-redo-cmd ,redo)))
  2843. (setq org-agenda-redo-command redo)
  2844. (goto-char (point-min)))
  2845. (org-agenda-fit-window-to-buffer)
  2846. (org-let (nth 1 series) '(org-agenda-finalize)))
  2847. ;;;###autoload
  2848. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2849. "Run an agenda command in batch mode and send the result to STDOUT.
  2850. If CMD-KEY is a string of length 1, it is used as a key in
  2851. `org-agenda-custom-commands' and triggers this command. If it is a
  2852. longer string it is used as a tags/todo match string.
  2853. Parameters are alternating variable names and values that will be bound
  2854. before running the agenda command."
  2855. (org-eval-in-environment (org-make-parameter-alist parameters)
  2856. (let (org-agenda-sticky)
  2857. (if (> (length cmd-key) 1)
  2858. (org-tags-view nil cmd-key)
  2859. (org-agenda nil cmd-key))))
  2860. (set-buffer org-agenda-buffer-name)
  2861. (princ (buffer-string)))
  2862. (defvar org-agenda-info nil)
  2863. ;;;###autoload
  2864. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2865. "Run an agenda command in batch mode and send the result to STDOUT.
  2866. If CMD-KEY is a string of length 1, it is used as a key in
  2867. `org-agenda-custom-commands' and triggers this command. If it is a
  2868. longer string it is used as a tags/todo match string.
  2869. Parameters are alternating variable names and values that will be bound
  2870. before running the agenda command.
  2871. The output gives a line for each selected agenda item. Each
  2872. item is a list of comma-separated values, like this:
  2873. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2874. category The category of the item
  2875. head The headline, without TODO kwd, TAGS and PRIORITY
  2876. type The type of the agenda entry, can be
  2877. todo selected in TODO match
  2878. tagsmatch selected in tags match
  2879. diary imported from diary
  2880. deadline a deadline on given date
  2881. scheduled scheduled on given date
  2882. timestamp entry has timestamp on given date
  2883. closed entry was closed on given date
  2884. upcoming-deadline warning about deadline
  2885. past-scheduled forwarded scheduled item
  2886. block entry has date block including g. date
  2887. todo The todo keyword, if any
  2888. tags All tags including inherited ones, separated by colons
  2889. date The relevant date, like 2007-2-14
  2890. time The time, like 15:00-16:50
  2891. extra Sting with extra planning info
  2892. priority-l The priority letter if any was given
  2893. priority-n The computed numerical priority
  2894. agenda-day The day in the agenda where this is listed"
  2895. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2896. (org-make-parameter-alist parameters))
  2897. (if (> (length cmd-key) 2)
  2898. (org-tags-view nil cmd-key)
  2899. (org-agenda nil cmd-key)))
  2900. (set-buffer org-agenda-buffer-name)
  2901. (let* ((lines (org-split-string (buffer-string) "\n"))
  2902. line)
  2903. (while (setq line (pop lines))
  2904. (catch 'next
  2905. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2906. (setq org-agenda-info
  2907. (org-fix-agenda-info (text-properties-at 0 line)))
  2908. (princ
  2909. (mapconcat 'org-agenda-export-csv-mapper
  2910. '(org-category txt type todo tags date time extra
  2911. priority-letter priority agenda-day)
  2912. ","))
  2913. (princ "\n")))))
  2914. (defun org-fix-agenda-info (props)
  2915. "Make sure all properties on an agenda item have a canonical form.
  2916. This ensures the export commands can easily use it."
  2917. (let (tmp re)
  2918. (when (setq tmp (plist-get props 'tags))
  2919. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2920. (when (setq tmp (plist-get props 'date))
  2921. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2922. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2923. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2924. (setq tmp (calendar-date-string tmp)))
  2925. (setq props (plist-put props 'date tmp)))
  2926. (when (setq tmp (plist-get props 'day))
  2927. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2928. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2929. (setq tmp (calendar-date-string tmp)))
  2930. (setq props (plist-put props 'day tmp))
  2931. (setq props (plist-put props 'agenda-day tmp)))
  2932. (when (setq tmp (plist-get props 'txt))
  2933. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2934. (plist-put props 'priority-letter (match-string 1 tmp))
  2935. (setq tmp (replace-match "" t t tmp)))
  2936. (when (and (setq re (plist-get props 'org-todo-regexp))
  2937. (setq re (concat "\\`\\.*" re " ?"))
  2938. (let ((case-fold-search nil)) (string-match re tmp)))
  2939. (plist-put props 'todo (match-string 1 tmp))
  2940. (setq tmp (replace-match "" t t tmp)))
  2941. (plist-put props 'txt tmp)))
  2942. props)
  2943. (defun org-agenda-export-csv-mapper (prop)
  2944. (let ((res (plist-get org-agenda-info prop)))
  2945. (setq res
  2946. (cond
  2947. ((not res) "")
  2948. ((stringp res) res)
  2949. (t (prin1-to-string res))))
  2950. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  2951. ;;;###autoload
  2952. (defun org-store-agenda-views (&rest parameters)
  2953. "Store agenda views."
  2954. (interactive)
  2955. (eval (list 'org-batch-store-agenda-views)))
  2956. ;;;###autoload
  2957. (defmacro org-batch-store-agenda-views (&rest parameters)
  2958. "Run all custom agenda commands that have a file argument."
  2959. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2960. (pop-up-frames nil)
  2961. (dir default-directory)
  2962. (pars (org-make-parameter-alist parameters))
  2963. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2964. (save-window-excursion
  2965. (while cmds
  2966. (setq cmd (pop cmds)
  2967. thiscmdkey (car cmd)
  2968. thiscmdcmd (cdr cmd)
  2969. match (nth 2 thiscmdcmd)
  2970. bufname (if org-agenda-sticky
  2971. (or (and (stringp match)
  2972. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2973. (format "*Org Agenda(%s)*" thiscmdkey))
  2974. org-agenda-buffer-name)
  2975. cmd-or-set (nth 2 cmd)
  2976. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2977. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2978. (if (stringp files) (setq files (list files)))
  2979. (when files
  2980. (org-eval-in-environment (append org-agenda-exporter-settings
  2981. opts pars)
  2982. (org-agenda nil thiscmdkey))
  2983. (set-buffer bufname)
  2984. (while files
  2985. (org-eval-in-environment (append org-agenda-exporter-settings
  2986. opts pars)
  2987. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2988. (and (get-buffer bufname)
  2989. (kill-buffer bufname)))))))
  2990. (defvar org-agenda-current-span nil
  2991. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2992. (defun org-agenda-mark-header-line (pos)
  2993. "Mark the line at POS as an agenda structure header."
  2994. (save-excursion
  2995. (goto-char pos)
  2996. (put-text-property (point-at-bol) (point-at-eol)
  2997. 'org-agenda-structural-header t)
  2998. (when org-agenda-title-append
  2999. (put-text-property (point-at-bol) (point-at-eol)
  3000. 'org-agenda-title-append org-agenda-title-append))))
  3001. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3002. (defvar org-agenda-write-buffer-name "Agenda View")
  3003. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3004. "Write the current buffer (an agenda view) as a file.
  3005. Depending on the extension of the file name, plain text (.txt),
  3006. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3007. If the extension is .ics, translate visible agenda into iCalendar
  3008. format. If the extension is .org, collect all subtrees
  3009. corresponding to the agenda entries and add them in an .org file.
  3010. With prefix argument OPEN, open the new file immediately. If
  3011. NOSETTINGS is given, do not scope the settings of
  3012. `org-agenda-exporter-settings' into the export commands. This is
  3013. used when the settings have already been scoped and we do not
  3014. wish to overrule other, higher priority settings. If
  3015. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3016. the agenda to write."
  3017. (interactive "FWrite agenda to file: \nP")
  3018. (if (or (not (file-writable-p file))
  3019. (and (file-exists-p file)
  3020. (if (called-interactively-p 'any)
  3021. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3022. (user-error "Cannot write agenda to file %s" file))
  3023. (org-let (if nosettings nil org-agenda-exporter-settings)
  3024. '(save-excursion
  3025. (save-window-excursion
  3026. (let ((bs (copy-sequence (buffer-string)))
  3027. (extension (file-name-extension file))
  3028. beg content)
  3029. (with-temp-buffer
  3030. (rename-buffer org-agenda-write-buffer-name t)
  3031. (set-buffer-modified-p nil)
  3032. (insert bs)
  3033. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3034. (run-hooks 'org-agenda-before-write-hook)
  3035. (cond
  3036. ((bound-and-true-p org-mobile-creating-agendas)
  3037. (org-mobile-write-agenda-for-mobile file))
  3038. ((string= "org" extension)
  3039. (let (content p m message-log-max)
  3040. (goto-char (point-min))
  3041. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3042. (goto-char p)
  3043. (setq m (get-text-property (point) 'org-hd-marker))
  3044. (when m
  3045. (push (save-excursion
  3046. (set-buffer (marker-buffer m))
  3047. (goto-char m)
  3048. (org-copy-subtree 1 nil t t)
  3049. org-subtree-clip)
  3050. content)))
  3051. (find-file file)
  3052. (erase-buffer)
  3053. (dolist (s content) (org-paste-subtree 1 s))
  3054. (write-file file)
  3055. (kill-buffer (current-buffer))
  3056. (message "Org file written to %s" file)))
  3057. ((member extension '("html" "htm"))
  3058. (require 'htmlize)
  3059. (set-buffer (htmlize-buffer (current-buffer)))
  3060. (when org-agenda-export-html-style
  3061. ;; replace <style> section with org-agenda-export-html-style
  3062. (goto-char (point-min))
  3063. (kill-region (- (search-forward "<style") 6)
  3064. (search-forward "</style>"))
  3065. (insert org-agenda-export-html-style))
  3066. (write-file file)
  3067. (kill-buffer (current-buffer))
  3068. (message "HTML written to %s" file))
  3069. ((string= "ps" extension)
  3070. (require 'ps-print)
  3071. (ps-print-buffer-with-faces file)
  3072. (message "Postscript written to %s" file))
  3073. ((string= "pdf" extension)
  3074. (require 'ps-print)
  3075. (ps-print-buffer-with-faces
  3076. (concat (file-name-sans-extension file) ".ps"))
  3077. (call-process "ps2pdf" nil nil nil
  3078. (expand-file-name
  3079. (concat (file-name-sans-extension file) ".ps"))
  3080. (expand-file-name file))
  3081. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3082. (message "PDF written to %s" file))
  3083. ((string= "ics" extension)
  3084. (require 'ox-icalendar)
  3085. (org-icalendar-export-current-agenda (expand-file-name file)))
  3086. (t
  3087. (let ((bs (buffer-string)))
  3088. (find-file file)
  3089. (erase-buffer)
  3090. (insert bs)
  3091. (save-buffer 0)
  3092. (kill-buffer (current-buffer))
  3093. (message "Plain text written to %s" file))))))))
  3094. (set-buffer (or agenda-bufname
  3095. (and (called-interactively-p 'any) (buffer-name))
  3096. org-agenda-buffer-name)))
  3097. (when open (org-open-file file)))
  3098. (defun org-agenda-remove-marked-text (property &optional value)
  3099. "Delete all text marked with VALUE of PROPERTY.
  3100. VALUE defaults to t."
  3101. (let (beg)
  3102. (setq value (or value t))
  3103. (while (setq beg (text-property-any (point-min) (point-max)
  3104. property value))
  3105. (delete-region
  3106. beg (or (next-single-property-change beg property)
  3107. (point-max))))))
  3108. (defun org-agenda-add-entry-text ()
  3109. "Add entry text to agenda lines.
  3110. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3111. entry text following headings shown in the agenda.
  3112. Drawers will be excluded, also the line with scheduling/deadline info."
  3113. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3114. (not (bound-and-true-p org-mobile-creating-agendas)))
  3115. (let (m txt)
  3116. (goto-char (point-min))
  3117. (while (not (eobp))
  3118. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3119. (beginning-of-line 2)
  3120. (setq txt (org-agenda-get-some-entry-text
  3121. m org-agenda-add-entry-text-maxlines " > "))
  3122. (end-of-line 1)
  3123. (if (string-match "\\S-" txt)
  3124. (insert "\n" txt)
  3125. (or (eobp) (forward-char 1))))))))
  3126. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3127. &rest keep)
  3128. "Extract entry text from MARKER, at most N-LINES lines.
  3129. This will ignore drawers etc, just get the text.
  3130. If INDENT is given, prefix every line with this string. If KEEP is
  3131. given, it is a list of symbols, defining stuff that should not be
  3132. removed from the entry content. Currently only `planning' is allowed here."
  3133. (let (txt drawer-re kwd-time-re ind)
  3134. (save-excursion
  3135. (with-current-buffer (marker-buffer marker)
  3136. (if (not (derived-mode-p 'org-mode))
  3137. (setq txt "")
  3138. (org-with-wide-buffer
  3139. (goto-char marker)
  3140. (end-of-line 1)
  3141. (setq txt (buffer-substring
  3142. (min (1+ (point)) (point-max))
  3143. (progn (outline-next-heading) (point)))
  3144. drawer-re org-drawer-regexp
  3145. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3146. ".*\n?"))
  3147. (with-temp-buffer
  3148. (insert txt)
  3149. (when org-agenda-add-entry-text-descriptive-links
  3150. (goto-char (point-min))
  3151. (while (org-activate-bracket-links (point-max))
  3152. (add-text-properties (match-beginning 0) (match-end 0)
  3153. '(face org-link))))
  3154. (goto-char (point-min))
  3155. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3156. (set-text-properties (match-beginning 0) (match-end 0)
  3157. nil))
  3158. (goto-char (point-min))
  3159. (while (re-search-forward drawer-re nil t)
  3160. (delete-region
  3161. (match-beginning 0)
  3162. (progn (re-search-forward
  3163. "^[ \t]*:END:.*\n?" nil 'move)
  3164. (point))))
  3165. (unless (member 'planning keep)
  3166. (goto-char (point-min))
  3167. (while (re-search-forward kwd-time-re nil t)
  3168. (replace-match "")))
  3169. (goto-char (point-min))
  3170. (when org-agenda-entry-text-exclude-regexps
  3171. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3172. (while (setq re (pop re-list))
  3173. (goto-char (point-min))
  3174. (while (re-search-forward re nil t)
  3175. (replace-match "")))))
  3176. (goto-char (point-max))
  3177. (skip-chars-backward " \t\n")
  3178. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3179. ;; find and remove min common indentation
  3180. (goto-char (point-min))
  3181. (untabify (point-min) (point-max))
  3182. (setq ind (org-get-indentation))
  3183. (while (not (eobp))
  3184. (unless (looking-at "[ \t]*$")
  3185. (setq ind (min ind (org-get-indentation))))
  3186. (beginning-of-line 2))
  3187. (goto-char (point-min))
  3188. (while (not (eobp))
  3189. (unless (looking-at "[ \t]*$")
  3190. (move-to-column ind)
  3191. (delete-region (point-at-bol) (point)))
  3192. (beginning-of-line 2))
  3193. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3194. (goto-char (point-min))
  3195. (when indent
  3196. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3197. (replace-match indent t t)))
  3198. (goto-char (point-min))
  3199. (while (looking-at "[ \t]*\n") (replace-match ""))
  3200. (goto-char (point-max))
  3201. (when (> (org-current-line)
  3202. n-lines)
  3203. (org-goto-line (1+ n-lines))
  3204. (backward-char 1))
  3205. (setq txt (buffer-substring (point-min) (point))))))))
  3206. txt))
  3207. (defun org-check-for-org-mode ()
  3208. "Make sure current buffer is in org-mode. Error if not."
  3209. (or (derived-mode-p 'org-mode)
  3210. (error "Cannot execute Org agenda command on buffer in %s"
  3211. major-mode)))
  3212. ;;; Agenda prepare and finalize
  3213. (defvar org-agenda-multi nil) ; dynamically scoped
  3214. (defvar org-agenda-pre-window-conf nil)
  3215. (defvar org-agenda-columns-active nil)
  3216. (defvar org-agenda-name nil)
  3217. (defvar org-agenda-tag-filter nil)
  3218. (defvar org-agenda-category-filter nil)
  3219. (defvar org-agenda-regexp-filter nil)
  3220. (defvar org-agenda-effort-filter nil)
  3221. (defvar org-agenda-top-headline-filter nil)
  3222. (defvar org-agenda-tag-filter-preset nil
  3223. "A preset of the tags filter used for secondary agenda filtering.
  3224. This must be a list of strings, each string must be a single tag preceded
  3225. by \"+\" or \"-\".
  3226. This variable should not be set directly, but agenda custom commands can
  3227. bind it in the options section. The preset filter is a global property of
  3228. the entire agenda view. In a block agenda, it will not work reliably to
  3229. define a filter for one of the individual blocks. You need to set it in
  3230. the global options and expect it to be applied to the entire view.")
  3231. (defvar org-agenda-category-filter-preset nil
  3232. "A preset of the category filter used for secondary agenda filtering.
  3233. This must be a list of strings, each string must be a single category
  3234. preceded by \"+\" or \"-\".
  3235. This variable should not be set directly, but agenda custom commands can
  3236. bind it in the options section. The preset filter is a global property of
  3237. the entire agenda view. In a block agenda, it will not work reliably to
  3238. define a filter for one of the individual blocks. You need to set it in
  3239. the global options and expect it to be applied to the entire view.")
  3240. (defvar org-agenda-regexp-filter-preset nil
  3241. "A preset of the regexp filter used for secondary agenda filtering.
  3242. This must be a list of strings, each string must be a single regexp
  3243. preceded by \"+\" or \"-\".
  3244. This variable should not be set directly, but agenda custom commands can
  3245. bind it in the options section. The preset filter is a global property of
  3246. the entire agenda view. In a block agenda, it will not work reliably to
  3247. define a filter for one of the individual blocks. You need to set it in
  3248. the global options and expect it to be applied to the entire view.")
  3249. (defvar org-agenda-effort-filter-preset nil
  3250. "A preset of the effort condition used for secondary agenda filtering.
  3251. This must be a list of strings, each string must be a single regexp
  3252. preceded by \"+\" or \"-\".
  3253. This variable should not be set directly, but agenda custom commands can
  3254. bind it in the options section. The preset filter is a global property of
  3255. the entire agenda view. In a block agenda, it will not work reliably to
  3256. define a filter for one of the individual blocks. You need to set it in
  3257. the global options and expect it to be applied to the entire view.")
  3258. (defun org-agenda-use-sticky-p ()
  3259. "Return non-nil if an agenda buffer named
  3260. `org-agenda-buffer-name' exists and should be shown instead of
  3261. generating a new one."
  3262. (and
  3263. ;; turned off by user
  3264. org-agenda-sticky
  3265. ;; For multi-agenda buffer already exists
  3266. (not org-agenda-multi)
  3267. ;; buffer found
  3268. (get-buffer org-agenda-buffer-name)
  3269. ;; C-u parameter is same as last call
  3270. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3271. (and
  3272. (equal current-prefix-arg
  3273. org-agenda-last-prefix-arg)
  3274. ;; In case user turned stickiness on, while having existing
  3275. ;; Agenda buffer active, don't reuse that buffer, because it
  3276. ;; does not have org variables local
  3277. org-agenda-this-buffer-is-sticky))))
  3278. (defun org-agenda-prepare-window (abuf filter-alist)
  3279. "Setup agenda buffer in the window.
  3280. ABUF is the buffer for the agenda window.
  3281. FILTER-ALIST is an alist of filters we need to apply when
  3282. `org-agenda-persistent-filter' is non-nil."
  3283. (let* ((awin (get-buffer-window abuf)) wconf)
  3284. (cond
  3285. ((equal (current-buffer) abuf) nil)
  3286. (awin (select-window awin))
  3287. ((not (setq wconf (current-window-configuration))))
  3288. ((eq org-agenda-window-setup 'current-window)
  3289. (pop-to-buffer-same-window abuf))
  3290. ((eq org-agenda-window-setup 'other-window)
  3291. (org-switch-to-buffer-other-window abuf))
  3292. ((eq org-agenda-window-setup 'other-frame)
  3293. (switch-to-buffer-other-frame abuf))
  3294. ((eq org-agenda-window-setup 'only-window)
  3295. (delete-other-windows)
  3296. (pop-to-buffer-same-window abuf))
  3297. ((eq org-agenda-window-setup 'reorganize-frame)
  3298. (delete-other-windows)
  3299. (org-switch-to-buffer-other-window abuf)))
  3300. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3301. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3302. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3303. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3304. ;; Additional test in case agenda is invoked from within agenda
  3305. ;; buffer via elisp link.
  3306. (unless (equal (current-buffer) abuf)
  3307. (pop-to-buffer-same-window abuf))
  3308. (setq org-agenda-pre-window-conf
  3309. (or wconf org-agenda-pre-window-conf))))
  3310. (defun org-agenda-prepare (&optional name)
  3311. (let ((filter-alist (if org-agenda-persistent-filter
  3312. (with-current-buffer
  3313. (get-buffer-create org-agenda-buffer-name)
  3314. (list `(tag . ,org-agenda-tag-filter)
  3315. `(re . ,org-agenda-regexp-filter)
  3316. `(effort . ,org-agenda-effort-filter)
  3317. `(cat . ,org-agenda-category-filter))))))
  3318. (if (org-agenda-use-sticky-p)
  3319. (progn
  3320. (put 'org-agenda-tag-filter :preset-filter nil)
  3321. (put 'org-agenda-category-filter :preset-filter nil)
  3322. (put 'org-agenda-regexp-filter :preset-filter nil)
  3323. ;; Popup existing buffer
  3324. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3325. filter-alist)
  3326. (message "Sticky Agenda buffer, use `r' to refresh")
  3327. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3328. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3329. (setq org-todo-keywords-for-agenda nil)
  3330. (put 'org-agenda-tag-filter :preset-filter
  3331. org-agenda-tag-filter-preset)
  3332. (put 'org-agenda-category-filter :preset-filter
  3333. org-agenda-category-filter-preset)
  3334. (put 'org-agenda-regexp-filter :preset-filter
  3335. org-agenda-regexp-filter-preset)
  3336. (put 'org-agenda-effort-filter :preset-filter
  3337. org-agenda-effort-filter-preset)
  3338. (if org-agenda-multi
  3339. (progn
  3340. (setq buffer-read-only nil)
  3341. (goto-char (point-max))
  3342. (unless (or (bobp) org-agenda-compact-blocks
  3343. (not org-agenda-block-separator))
  3344. (insert "\n"
  3345. (if (stringp org-agenda-block-separator)
  3346. org-agenda-block-separator
  3347. (make-string (window-width) org-agenda-block-separator))
  3348. "\n"))
  3349. (narrow-to-region (point) (point-max)))
  3350. (setq org-done-keywords-for-agenda nil)
  3351. ;; Setting any org variables that are in org-agenda-local-vars
  3352. ;; list need to be done after the prepare call
  3353. (org-agenda-prepare-window
  3354. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3355. (setq buffer-read-only nil)
  3356. (org-agenda-reset-markers)
  3357. (let ((inhibit-read-only t)) (erase-buffer))
  3358. (org-agenda-mode)
  3359. (setq org-agenda-buffer (current-buffer))
  3360. (setq org-agenda-contributing-files nil)
  3361. (setq org-agenda-columns-active nil)
  3362. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3363. (setq org-todo-keywords-for-agenda
  3364. (org-uniquify org-todo-keywords-for-agenda))
  3365. (setq org-done-keywords-for-agenda
  3366. (org-uniquify org-done-keywords-for-agenda))
  3367. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3368. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3369. (and name (not org-agenda-name)
  3370. (setq-local org-agenda-name name)))
  3371. (setq buffer-read-only nil))))
  3372. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3373. (defun org-agenda-finalize ()
  3374. "Finishing touch for the agenda buffer, called just before displaying it."
  3375. (unless org-agenda-multi
  3376. (save-excursion
  3377. (let ((inhibit-read-only t))
  3378. (goto-char (point-min))
  3379. (save-excursion
  3380. (while (org-activate-bracket-links (point-max))
  3381. (add-text-properties (match-beginning 0) (match-end 0)
  3382. '(face org-link))))
  3383. (save-excursion
  3384. (while (org-activate-plain-links (point-max))
  3385. (add-text-properties (match-beginning 0) (match-end 0)
  3386. '(face org-link))))
  3387. (unless (eq org-agenda-remove-tags t)
  3388. (org-agenda-align-tags))
  3389. (unless org-agenda-with-colors
  3390. (remove-text-properties (point-min) (point-max) '(face nil)))
  3391. (if (and (boundp 'org-agenda-overriding-columns-format)
  3392. org-agenda-overriding-columns-format)
  3393. (setq-local org-agenda-overriding-columns-format
  3394. org-agenda-overriding-columns-format))
  3395. (if (and (boundp 'org-agenda-view-columns-initially)
  3396. org-agenda-view-columns-initially)
  3397. (org-agenda-columns))
  3398. (when org-agenda-fontify-priorities
  3399. (org-agenda-fontify-priorities))
  3400. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3401. (org-agenda-dim-blocked-tasks))
  3402. (org-agenda-mark-clocking-task)
  3403. (when org-agenda-entry-text-mode
  3404. (org-agenda-entry-text-hide)
  3405. (org-agenda-entry-text-show))
  3406. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3407. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3408. (org-habit-insert-consistency-graphs))
  3409. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3410. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3411. (and (listp org-agenda-show-inherited-tags)
  3412. (memq org-agenda-type org-agenda-show-inherited-tags))
  3413. (and (eq org-agenda-show-inherited-tags t)
  3414. (or (eq org-agenda-use-tag-inheritance t)
  3415. (and (listp org-agenda-use-tag-inheritance)
  3416. (not (memq org-agenda-type
  3417. org-agenda-use-tag-inheritance))))))
  3418. (let (mrk)
  3419. (save-excursion
  3420. (goto-char (point-min))
  3421. (while (equal (forward-line) 0)
  3422. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3423. (put-text-property (point-at-bol) (point-at-eol)
  3424. 'tags (org-with-point-at mrk
  3425. (delete-dups
  3426. (mapcar 'downcase (org-get-tags-at))))))))))
  3427. (run-hooks 'org-agenda-finalize-hook)
  3428. (when org-agenda-top-headline-filter
  3429. (org-agenda-filter-top-headline-apply
  3430. org-agenda-top-headline-filter))
  3431. (when org-agenda-tag-filter
  3432. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3433. (when (get 'org-agenda-tag-filter :preset-filter)
  3434. (org-agenda-filter-apply
  3435. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3436. (when org-agenda-category-filter
  3437. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3438. (when (get 'org-agenda-category-filter :preset-filter)
  3439. (org-agenda-filter-apply
  3440. (get 'org-agenda-category-filter :preset-filter) 'category))
  3441. (when org-agenda-regexp-filter
  3442. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3443. (when (get 'org-agenda-regexp-filter :preset-filter)
  3444. (org-agenda-filter-apply
  3445. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3446. (when org-agenda-effort-filter
  3447. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3448. (when (get 'org-agenda-effort-filter :preset-filter)
  3449. (org-agenda-filter-apply
  3450. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3451. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3452. (defun org-agenda-mark-clocking-task ()
  3453. "Mark the current clock entry in the agenda if it is present."
  3454. ;; We need to widen when `org-agenda-finalize' is called from
  3455. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3456. (when (bound-and-true-p org-clock-current-task)
  3457. (save-restriction
  3458. (widen)
  3459. (org-agenda-unmark-clocking-task)
  3460. (when (marker-buffer org-clock-hd-marker)
  3461. (save-excursion
  3462. (goto-char (point-min))
  3463. (let (s ov)
  3464. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3465. (goto-char s)
  3466. (when (equal (org-get-at-bol 'org-hd-marker)
  3467. org-clock-hd-marker)
  3468. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3469. (overlay-put ov 'type 'org-agenda-clocking)
  3470. (overlay-put ov 'face 'org-agenda-clocking)
  3471. (overlay-put ov 'help-echo
  3472. "The clock is running in this item")))))))))
  3473. (defun org-agenda-unmark-clocking-task ()
  3474. "Unmark the current clocking task."
  3475. (mapc (lambda (o)
  3476. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3477. (delete-overlay o)))
  3478. (overlays-in (point-min) (point-max))))
  3479. (defun org-agenda-fontify-priorities ()
  3480. "Make highest priority lines bold, and lowest italic."
  3481. (interactive)
  3482. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3483. (delete-overlay o)))
  3484. (overlays-in (point-min) (point-max)))
  3485. (save-excursion
  3486. (let (b e p ov h l)
  3487. (goto-char (point-min))
  3488. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3489. (setq h (or (get-char-property (point) 'org-highest-priority)
  3490. org-highest-priority)
  3491. l (or (get-char-property (point) 'org-lowest-priority)
  3492. org-lowest-priority)
  3493. p (string-to-char (match-string 1))
  3494. b (match-beginning 0)
  3495. e (if (eq org-agenda-fontify-priorities 'cookies)
  3496. (match-end 0)
  3497. (point-at-eol))
  3498. ov (make-overlay b e))
  3499. (overlay-put
  3500. ov 'face
  3501. (let ((special-face
  3502. (cond ((org-face-from-face-or-color
  3503. 'priority 'org-priority
  3504. (cdr (assoc p org-priority-faces))))
  3505. ((and (listp org-agenda-fontify-priorities)
  3506. (org-face-from-face-or-color
  3507. 'priority 'org-priority
  3508. (cdr (assoc p org-agenda-fontify-priorities)))))
  3509. ((equal p l) 'italic)
  3510. ((equal p h) 'bold))))
  3511. (if special-face (list special-face 'org-priority) 'org-priority)))
  3512. (overlay-put ov 'org-type 'org-priority)))))
  3513. (defvar org-depend-tag-blocked)
  3514. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3515. "Dim currently blocked TODOs in the agenda display.
  3516. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3517. dimming them."
  3518. (interactive "P")
  3519. (when (called-interactively-p 'interactive)
  3520. (message "Dim or hide blocked tasks..."))
  3521. (dolist (o (overlays-in (point-min) (point-max)))
  3522. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3523. (delete-overlay o)))
  3524. (save-excursion
  3525. (let ((inhibit-read-only t)
  3526. (org-depend-tag-blocked nil)
  3527. org-blocked-by-checkboxes)
  3528. (goto-char (point-min))
  3529. (while (let ((pos (text-property-not-all
  3530. (point) (point-max) 'todo-state nil)))
  3531. (when pos (goto-char pos)))
  3532. (setq org-blocked-by-checkboxes nil)
  3533. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3534. (when (and (markerp marker)
  3535. (with-current-buffer (marker-buffer marker)
  3536. (save-excursion (goto-char marker)
  3537. (org-entry-blocked-p))))
  3538. ;; Entries blocked by checkboxes cannot be made invisible.
  3539. ;; See `org-agenda-dim-blocked-tasks' for details.
  3540. (let* ((really-invisible
  3541. (and (not org-blocked-by-checkboxes)
  3542. (or invisible (eq org-agenda-dim-blocked-tasks
  3543. 'invisible))))
  3544. (ov (make-overlay (if really-invisible (line-end-position 0)
  3545. (line-beginning-position))
  3546. (line-end-position))))
  3547. (if really-invisible (overlay-put ov 'invisible t)
  3548. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3549. (overlay-put ov 'org-type 'org-blocked-todo))))
  3550. (forward-line))))
  3551. (when (called-interactively-p 'interactive)
  3552. (message "Dim or hide blocked tasks...done")))
  3553. (defvar org-agenda-skip-function nil
  3554. "Function to be called at each match during agenda construction.
  3555. If this function returns nil, the current match should not be skipped.
  3556. Otherwise, the function must return a position from where the search
  3557. should be continued.
  3558. This may also be a Lisp form, it will be evaluated.
  3559. Never set this variable using `setq' or so, because then it will apply
  3560. to all future agenda commands. If you do want a global skipping condition,
  3561. use the option `org-agenda-skip-function-global' instead.
  3562. The correct usage for `org-agenda-skip-function' is to bind it with
  3563. `let' to scope it dynamically into the agenda-constructing command.
  3564. A good way to set it is through options in `org-agenda-custom-commands'.")
  3565. (defun org-agenda-skip ()
  3566. "Throw to `:skip' in places that should be skipped.
  3567. Also moves point to the end of the skipped region, so that search can
  3568. continue from there."
  3569. (let ((p (point-at-bol)) to)
  3570. (when (or
  3571. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3572. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3573. (get-text-property p :org-archived)
  3574. (org-end-of-subtree t))
  3575. (and org-agenda-skip-comment-trees
  3576. (get-text-property p :org-comment)
  3577. (org-end-of-subtree t))
  3578. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3579. (org-agenda-skip-eval org-agenda-skip-function)))
  3580. (goto-char to))
  3581. (org-in-src-block-p t))
  3582. (throw :skip t))))
  3583. (defun org-agenda-skip-eval (form)
  3584. "If FORM is a function or a list, call (or eval) it and return the result.
  3585. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3586. and match data are returned to the previous state no matter what these
  3587. functions do."
  3588. (let (fp)
  3589. (and form
  3590. (or (setq fp (functionp form))
  3591. (consp form))
  3592. (save-excursion
  3593. (save-match-data
  3594. (if fp
  3595. (funcall form)
  3596. (eval form)))))))
  3597. (defvar org-agenda-markers nil
  3598. "List of all currently active markers created by `org-agenda'.")
  3599. (defvar org-agenda-last-marker-time (float-time)
  3600. "Creation time of the last agenda marker.")
  3601. (defun org-agenda-new-marker (&optional pos)
  3602. "Return a new agenda marker.
  3603. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3604. these markers and resets them when they are no longer in use."
  3605. (let ((m (copy-marker (or pos (point)) t)))
  3606. (setq org-agenda-last-marker-time (float-time))
  3607. (if org-agenda-buffer
  3608. (with-current-buffer org-agenda-buffer
  3609. (push m org-agenda-markers))
  3610. (push m org-agenda-markers))
  3611. m))
  3612. (defun org-agenda-reset-markers ()
  3613. "Reset markers created by `org-agenda'."
  3614. (while org-agenda-markers
  3615. (move-marker (pop org-agenda-markers) nil)))
  3616. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3617. "Save relative positions of markers in region.
  3618. This check for agenda markers in all agenda buffers currently active."
  3619. (dolist (buf (buffer-list))
  3620. (with-current-buffer buf
  3621. (when (eq major-mode 'org-agenda-mode)
  3622. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3623. org-agenda-markers)))))
  3624. ;;; Entry text mode
  3625. (defun org-agenda-entry-text-show-here ()
  3626. "Add some text from the entry as context to the current line."
  3627. (let (m txt o)
  3628. (setq m (org-get-at-bol 'org-hd-marker))
  3629. (unless (marker-buffer m)
  3630. (error "No marker points to an entry here"))
  3631. (setq txt (concat "\n" (org-no-properties
  3632. (org-agenda-get-some-entry-text
  3633. m org-agenda-entry-text-maxlines
  3634. org-agenda-entry-text-leaders))))
  3635. (when (string-match "\\S-" txt)
  3636. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3637. (overlay-put o 'evaporate t)
  3638. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3639. (overlay-put o 'after-string txt))))
  3640. (defun org-agenda-entry-text-show ()
  3641. "Add entry context for all agenda lines."
  3642. (interactive)
  3643. (save-excursion
  3644. (goto-char (point-max))
  3645. (beginning-of-line 1)
  3646. (while (not (bobp))
  3647. (when (org-get-at-bol 'org-hd-marker)
  3648. (org-agenda-entry-text-show-here))
  3649. (beginning-of-line 0))))
  3650. (defun org-agenda-entry-text-hide ()
  3651. "Remove any shown entry context."
  3652. (delq nil
  3653. (mapcar (lambda (o)
  3654. (if (eq (overlay-get o 'org-overlay-type)
  3655. 'agenda-entry-content)
  3656. (progn (delete-overlay o) t)))
  3657. (overlays-in (point-min) (point-max)))))
  3658. (defun org-agenda-get-day-face (date)
  3659. "Return the face DATE should be displayed with."
  3660. (cond ((and (functionp org-agenda-day-face-function)
  3661. (funcall org-agenda-day-face-function date)))
  3662. ((org-agenda-today-p date) 'org-agenda-date-today)
  3663. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3664. 'org-agenda-date-weekend)
  3665. (t 'org-agenda-date)))
  3666. ;;; Agenda timeline
  3667. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3668. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3669. (defun org-timeline (&optional dotodo)
  3670. "Show a time-sorted view of the entries in the current Org file.
  3671. Only entries with a time stamp of today or later will be listed.
  3672. With `\\[universal-argument]' prefix, all unfinished TODO items will also be \
  3673. shown,
  3674. under the current date.
  3675. If the buffer contains an active region, only check the region
  3676. for dates."
  3677. (interactive "P")
  3678. (let* ((dopast t)
  3679. (org-agenda-show-log-scoped org-agenda-show-log)
  3680. (org-agenda-show-log org-agenda-show-log-scoped)
  3681. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3682. (current-buffer))))
  3683. (date (calendar-current-date))
  3684. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3685. (end (if (org-region-active-p) (region-end) (point-max)))
  3686. (day-numbers (org-get-all-dates
  3687. beg end 'no-ranges
  3688. t org-agenda-show-log-scoped ; always include today
  3689. org-timeline-show-empty-dates))
  3690. (org-deadline-warning-days 0)
  3691. (org-agenda-only-exact-dates t)
  3692. (today (org-today))
  3693. (past t)
  3694. args
  3695. s e rtn d emptyp)
  3696. (setq org-agenda-redo-command
  3697. (list 'let
  3698. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3699. (list 'org-switch-to-buffer-other-window (current-buffer))
  3700. (list 'org-timeline (list 'quote dotodo))))
  3701. (put 'org-agenda-redo-command 'org-lprops nil)
  3702. (if (not dopast)
  3703. ;; Remove past dates from the list of dates.
  3704. (setq day-numbers (delq nil (mapcar (lambda(x)
  3705. (if (>= x today) x nil))
  3706. day-numbers))))
  3707. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3708. (org-compile-prefix-format 'timeline)
  3709. (org-set-sorting-strategy 'timeline)
  3710. (if org-agenda-show-log-scoped (push :closed args))
  3711. (push :timestamp args)
  3712. (push :deadline args)
  3713. (push :scheduled args)
  3714. (push :sexp args)
  3715. (if dotodo (push :todo args))
  3716. (insert "Timeline of file " entry "\n")
  3717. (add-text-properties (point-min) (point)
  3718. (list 'face 'org-agenda-structure))
  3719. (org-agenda-mark-header-line (point-min))
  3720. (while (setq d (pop day-numbers))
  3721. (if (and (listp d) (eq (car d) :omitted))
  3722. (progn
  3723. (setq s (point))
  3724. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3725. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3726. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3727. (if (and (>= d today)
  3728. dopast
  3729. past)
  3730. (progn
  3731. (setq past nil)
  3732. (insert (make-string 79 ?-) "\n")))
  3733. (setq date (calendar-gregorian-from-absolute d))
  3734. (setq s (point))
  3735. (setq rtn (and (not emptyp)
  3736. (apply 'org-agenda-get-day-entries entry
  3737. date args)))
  3738. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3739. (progn
  3740. (insert
  3741. (if (stringp org-agenda-format-date)
  3742. (format-time-string org-agenda-format-date
  3743. (org-time-from-absolute date))
  3744. (funcall org-agenda-format-date date))
  3745. "\n")
  3746. (put-text-property s (1- (point)) 'face
  3747. (org-agenda-get-day-face date))
  3748. (put-text-property s (1- (point)) 'org-date-line t)
  3749. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3750. (if (equal d today)
  3751. (put-text-property s (1- (point)) 'org-today t))
  3752. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3753. (put-text-property s (1- (point)) 'day d)))))
  3754. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3755. (point-min)))
  3756. (add-text-properties
  3757. (point-min) (point-max)
  3758. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3759. (org-agenda-finalize)
  3760. (setq buffer-read-only t)))
  3761. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3762. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3763. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3764. not every single day in the range. If FORCE-TODAY is non-nil, make
  3765. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3766. inactive time stamps (those in square brackets) are included.
  3767. When EMPTY is non-nil, also include days without any entries."
  3768. (let ((re (concat
  3769. (if pre-re pre-re "")
  3770. (if inactive org-ts-regexp-both org-ts-regexp)))
  3771. dates dates1 date day day1 day2 ts1 ts2 pos)
  3772. (if force-today
  3773. (setq dates (list (org-today))))
  3774. (save-excursion
  3775. (goto-char beg)
  3776. (while (re-search-forward re end t)
  3777. (setq day (time-to-days (org-time-string-to-time
  3778. (substring (match-string 1) 0 10)
  3779. (current-buffer) (match-beginning 0))))
  3780. (or (memq day dates) (push day dates)))
  3781. (unless no-ranges
  3782. (goto-char beg)
  3783. (while (re-search-forward org-tr-regexp end t)
  3784. (setq pos (match-beginning 0))
  3785. (setq ts1 (substring (match-string 1) 0 10)
  3786. ts2 (substring (match-string 2) 0 10)
  3787. day1 (time-to-days (org-time-string-to-time
  3788. ts1 (current-buffer) pos))
  3789. day2 (time-to-days (org-time-string-to-time
  3790. ts2 (current-buffer) pos)))
  3791. (while (< (setq day1 (1+ day1)) day2)
  3792. (or (memq day1 dates) (push day1 dates)))))
  3793. (setq dates (sort dates '<))
  3794. (when empty
  3795. (while (setq day (pop dates))
  3796. (setq day2 (car dates))
  3797. (push day dates1)
  3798. (when (and day2 empty)
  3799. (if (or (eq empty t)
  3800. (and (numberp empty) (<= (- day2 day) empty)))
  3801. (while (< (setq day (1+ day)) day2)
  3802. (push (list day) dates1))
  3803. (push (cons :omitted (- day2 day)) dates1))))
  3804. (setq dates (nreverse dates1)))
  3805. dates)))
  3806. ;;; Agenda Daily/Weekly
  3807. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3808. "Start day for the agenda view.
  3809. Custom commands can set this variable in the options section.
  3810. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3811. input allowed when reading a date through the Org calendar.
  3812. See the docstring of `org-read-date' for details.")
  3813. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3814. (defvar org-arg-loc nil) ; local variable
  3815. (defvar org-agenda-buffer-tmp-name nil)
  3816. ;;;###autoload
  3817. (defun org-agenda-list (&optional arg start-day span with-hour)
  3818. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3819. The view will be for the current day or week, but from the overview buffer
  3820. you will be able to go to other days/weeks.
  3821. With a numeric prefix argument in an interactive call, the agenda will
  3822. span ARG days. Lisp programs should instead specify SPAN to change
  3823. the number of days. SPAN defaults to `org-agenda-span'.
  3824. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3825. given in `org-agenda-start-on-weekday'.
  3826. When WITH-HOUR is non-nil, only include scheduled and deadline
  3827. items if they have an hour specification like [h]h:mm."
  3828. (interactive "P")
  3829. (if org-agenda-overriding-arguments
  3830. (setq arg (car org-agenda-overriding-arguments)
  3831. start-day (nth 1 org-agenda-overriding-arguments)
  3832. span (nth 2 org-agenda-overriding-arguments)))
  3833. (if (and (integerp arg) (> arg 0))
  3834. (setq span arg arg nil))
  3835. (catch 'exit
  3836. (setq org-agenda-buffer-name
  3837. (or org-agenda-buffer-tmp-name
  3838. (if org-agenda-sticky
  3839. (cond ((and org-keys (stringp org-match))
  3840. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3841. (org-keys
  3842. (format "*Org Agenda(%s)*" org-keys))
  3843. (t "*Org Agenda(a)*")))
  3844. org-agenda-buffer-name))
  3845. (org-agenda-prepare "Day/Week")
  3846. (setq start-day (or start-day org-agenda-start-day))
  3847. (if (stringp start-day)
  3848. ;; Convert to an absolute day number
  3849. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3850. (org-compile-prefix-format 'agenda)
  3851. (org-set-sorting-strategy 'agenda)
  3852. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3853. (today (org-today))
  3854. (sd (or start-day today))
  3855. (ndays (org-agenda-span-to-ndays span sd))
  3856. (org-agenda-start-on-weekday
  3857. (if (or (eq ndays 7) (eq ndays 14))
  3858. org-agenda-start-on-weekday))
  3859. (thefiles (org-agenda-files nil 'ifmode))
  3860. (files thefiles)
  3861. (start (if (or (null org-agenda-start-on-weekday)
  3862. (< ndays 7))
  3863. sd
  3864. (let* ((nt (calendar-day-of-week
  3865. (calendar-gregorian-from-absolute sd)))
  3866. (n1 org-agenda-start-on-weekday)
  3867. (d (- nt n1)))
  3868. (- sd (+ (if (< d 0) 7 0) d)))))
  3869. (day-numbers (list start))
  3870. (day-cnt 0)
  3871. (inhibit-redisplay (not debug-on-error))
  3872. (org-agenda-show-log-scoped org-agenda-show-log)
  3873. s e rtn rtnall file date d start-pos end-pos todayp
  3874. clocktable-start clocktable-end filter)
  3875. (setq org-agenda-redo-command
  3876. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3877. (dotimes (n (1- ndays))
  3878. (push (1+ (car day-numbers)) day-numbers))
  3879. (setq day-numbers (nreverse day-numbers))
  3880. (setq clocktable-start (car day-numbers)
  3881. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3882. (setq-local org-starting-day (car day-numbers))
  3883. (setq-local org-arg-loc arg)
  3884. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3885. (unless org-agenda-compact-blocks
  3886. (let* ((d1 (car day-numbers))
  3887. (d2 (org-last day-numbers))
  3888. (w1 (org-days-to-iso-week d1))
  3889. (w2 (org-days-to-iso-week d2)))
  3890. (setq s (point))
  3891. (if org-agenda-overriding-header
  3892. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3893. nil 'face 'org-agenda-structure) "\n")
  3894. (insert (org-agenda-span-name span)
  3895. "-agenda"
  3896. (if (< (- d2 d1) 350)
  3897. (if (= w1 w2)
  3898. (format " (W%02d)" w1)
  3899. (format " (W%02d-W%02d)" w1 w2))
  3900. "")
  3901. ":\n")))
  3902. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3903. 'org-date-line t))
  3904. (org-agenda-mark-header-line s))
  3905. (while (setq d (pop day-numbers))
  3906. (setq date (calendar-gregorian-from-absolute d)
  3907. s (point))
  3908. (if (or (setq todayp (= d today))
  3909. (and (not start-pos) (= d sd)))
  3910. (setq start-pos (point))
  3911. (if (and start-pos (not end-pos))
  3912. (setq end-pos (point))))
  3913. (setq files thefiles
  3914. rtnall nil)
  3915. (while (setq file (pop files))
  3916. (catch 'nextfile
  3917. (org-check-agenda-file file)
  3918. (let ((org-agenda-entry-types org-agenda-entry-types))
  3919. ;; Starred types override non-starred equivalents
  3920. (when (member :deadline* org-agenda-entry-types)
  3921. (setq org-agenda-entry-types
  3922. (delq :deadline org-agenda-entry-types)))
  3923. (when (member :scheduled* org-agenda-entry-types)
  3924. (setq org-agenda-entry-types
  3925. (delq :scheduled org-agenda-entry-types)))
  3926. ;; Honor with-hour
  3927. (when with-hour
  3928. (when (member :deadline org-agenda-entry-types)
  3929. (setq org-agenda-entry-types
  3930. (delq :deadline org-agenda-entry-types))
  3931. (push :deadline* org-agenda-entry-types))
  3932. (when (member :scheduled org-agenda-entry-types)
  3933. (setq org-agenda-entry-types
  3934. (delq :scheduled org-agenda-entry-types))
  3935. (push :scheduled* org-agenda-entry-types)))
  3936. (unless org-agenda-include-deadlines
  3937. (setq org-agenda-entry-types
  3938. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3939. (cond
  3940. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3941. (setq rtn (org-agenda-get-day-entries
  3942. file date :closed)))
  3943. (org-agenda-show-log-scoped
  3944. (setq rtn (apply 'org-agenda-get-day-entries
  3945. file date
  3946. (append '(:closed) org-agenda-entry-types))))
  3947. (t
  3948. (setq rtn (apply 'org-agenda-get-day-entries
  3949. file date
  3950. org-agenda-entry-types)))))
  3951. (setq rtnall (append rtnall rtn)))) ;; all entries
  3952. (if org-agenda-include-diary
  3953. (let ((org-agenda-search-headline-for-time t))
  3954. (require 'diary-lib)
  3955. (setq rtn (org-get-entries-from-diary date))
  3956. (setq rtnall (append rtnall rtn))))
  3957. (if (or rtnall org-agenda-show-all-dates)
  3958. (progn
  3959. (setq day-cnt (1+ day-cnt))
  3960. (insert
  3961. (if (stringp org-agenda-format-date)
  3962. (format-time-string org-agenda-format-date
  3963. (org-time-from-absolute date))
  3964. (funcall org-agenda-format-date date))
  3965. "\n")
  3966. (put-text-property s (1- (point)) 'face
  3967. (org-agenda-get-day-face date))
  3968. (put-text-property s (1- (point)) 'org-date-line t)
  3969. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3970. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3971. (when todayp
  3972. (put-text-property s (1- (point)) 'org-today t))
  3973. (setq rtnall
  3974. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3975. (if rtnall (insert ;; all entries
  3976. (org-agenda-finalize-entries rtnall 'agenda)
  3977. "\n"))
  3978. (put-text-property s (1- (point)) 'day d)
  3979. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3980. (when (and org-agenda-clockreport-mode clocktable-start)
  3981. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3982. ;; the above line is to ensure the restricted range!
  3983. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3984. tbl)
  3985. (setq p (org-plist-delete p :block))
  3986. (setq p (plist-put p :tstart clocktable-start))
  3987. (setq p (plist-put p :tend clocktable-end))
  3988. (setq p (plist-put p :scope 'agenda))
  3989. (setq tbl (apply 'org-clock-get-clocktable p))
  3990. (insert tbl)))
  3991. (goto-char (point-min))
  3992. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3993. (unless (and (pos-visible-in-window-p (point-min))
  3994. (pos-visible-in-window-p (point-max)))
  3995. (goto-char (1- (point-max)))
  3996. (recenter -1)
  3997. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3998. (progn
  3999. (goto-char (or start-pos 1))
  4000. (recenter 1))))
  4001. (goto-char (or start-pos 1))
  4002. (add-text-properties (point-min) (point-max)
  4003. `(org-agenda-type agenda
  4004. org-last-args (,arg ,start-day ,span)
  4005. org-redo-cmd ,org-agenda-redo-command
  4006. org-series-cmd ,org-cmd))
  4007. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4008. (org-agenda-show-clocking-issues))
  4009. (org-agenda-finalize)
  4010. (setq buffer-read-only t)
  4011. (message ""))))
  4012. (defun org-agenda-ndays-to-span (n)
  4013. "Return a span symbol for a span of N days, or N if none matches."
  4014. (cond ((symbolp n) n)
  4015. ((= n 1) 'day)
  4016. ((= n 7) 'week)
  4017. ((= n 14) 'fortnight)
  4018. (t n)))
  4019. (defun org-agenda-span-to-ndays (span &optional start-day)
  4020. "Return ndays from SPAN, possibly starting at START-DAY.
  4021. START-DAY is an absolute time value."
  4022. (cond ((numberp span) span)
  4023. ((eq span 'day) 1)
  4024. ((eq span 'week) 7)
  4025. ((eq span 'fortnight) 14)
  4026. ((eq span 'month)
  4027. (let ((date (calendar-gregorian-from-absolute start-day)))
  4028. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4029. ((eq span 'year)
  4030. (let ((date (calendar-gregorian-from-absolute start-day)))
  4031. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4032. (defun org-agenda-span-name (span)
  4033. "Return a SPAN name."
  4034. (if (null span)
  4035. ""
  4036. (if (symbolp span)
  4037. (capitalize (symbol-name span))
  4038. (format "%d days" span))))
  4039. ;;; Agenda word search
  4040. (defvar org-agenda-search-history nil)
  4041. (defvar org-search-syntax-table nil
  4042. "Special syntax table for Org search.
  4043. In this table, we have single quotes not as word constituents, to
  4044. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4045. (defvar org-mode-syntax-table) ; From org.el
  4046. (defun org-search-syntax-table ()
  4047. (unless org-search-syntax-table
  4048. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4049. (modify-syntax-entry ?' "." org-search-syntax-table)
  4050. (modify-syntax-entry ?` "." org-search-syntax-table))
  4051. org-search-syntax-table)
  4052. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4053. ;;;###autoload
  4054. (defun org-search-view (&optional todo-only string edit-at)
  4055. "Show all entries that contain a phrase or words or regular expressions.
  4056. With optional prefix argument TODO-ONLY, only consider entries that are
  4057. TODO entries. The argument STRING can be used to pass a default search
  4058. string into this function. If EDIT-AT is non-nil, it means that the
  4059. user should get a chance to edit this string, with cursor at position
  4060. EDIT-AT.
  4061. The search string can be viewed either as a phrase that should be found as
  4062. is, or it can be broken into a number of snippets, each of which must match
  4063. in a Boolean way to select an entry. The default depends on the variable
  4064. `org-agenda-search-view-always-boolean'.
  4065. Even if this is turned off (the default) you can always switch to
  4066. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4067. The default is a direct search of the whole phrase, where each space in
  4068. the search string can expand to an arbitrary amount of whitespace,
  4069. including newlines.
  4070. If using a Boolean search, the search string is split on whitespace and
  4071. each snippet is searched separately, with logical AND to select an entry.
  4072. Words prefixed with a minus must *not* occur in the entry. Words without
  4073. a prefix or prefixed with a plus must occur in the entry. Matching is
  4074. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4075. match whole words, not parts of a word) if
  4076. `org-agenda-search-view-force-full-words' is set (default is nil).
  4077. Boolean search snippets enclosed by curly braces are interpreted as
  4078. regular expressions that must or (when preceded with \"-\") must not
  4079. match in the entry. Snippets enclosed into double quotes will be taken
  4080. as a whole, to include whitespace.
  4081. - If the search string starts with an asterisk, search only in headlines.
  4082. - If (possibly after the leading star) the search string starts with an
  4083. exclamation mark, this also means to look at TODO entries only, an effect
  4084. that can also be achieved with a prefix argument.
  4085. - If (possibly after star and exclamation mark) the search string starts
  4086. with a colon, this will mean that the (non-regexp) snippets of the
  4087. Boolean search must match as full words.
  4088. This command searches the agenda files, and in addition the files listed
  4089. in `org-agenda-text-search-extra-files'."
  4090. (interactive "P")
  4091. (if org-agenda-overriding-arguments
  4092. (setq todo-only (car org-agenda-overriding-arguments)
  4093. string (nth 1 org-agenda-overriding-arguments)
  4094. edit-at (nth 2 org-agenda-overriding-arguments)))
  4095. (let* ((props (list 'face nil
  4096. 'done-face 'org-agenda-done
  4097. 'org-not-done-regexp org-not-done-regexp
  4098. 'org-todo-regexp org-todo-regexp
  4099. 'org-complex-heading-regexp org-complex-heading-regexp
  4100. 'mouse-face 'highlight
  4101. 'help-echo (format "mouse-2 or RET jump to location")))
  4102. (full-words org-agenda-search-view-force-full-words)
  4103. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4104. regexp rtn rtnall files file pos inherited-tags
  4105. marker category level tags c neg re boolean
  4106. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4107. (unless (and (not edit-at)
  4108. (stringp string)
  4109. (string-match "\\S-" string))
  4110. (setq string (read-string
  4111. (if org-agenda-search-view-always-boolean
  4112. "[+-]Word/{Regexp} ...: "
  4113. "Phrase or [+-]Word/{Regexp} ...: ")
  4114. (cond
  4115. ((integerp edit-at) (cons string edit-at))
  4116. (edit-at string))
  4117. 'org-agenda-search-history)))
  4118. (catch 'exit
  4119. (if org-agenda-sticky
  4120. (setq org-agenda-buffer-name
  4121. (if (stringp string)
  4122. (format "*Org Agenda(%s:%s)*"
  4123. (or org-keys (or (and todo-only "S") "s")) string)
  4124. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4125. (org-agenda-prepare "SEARCH")
  4126. (org-compile-prefix-format 'search)
  4127. (org-set-sorting-strategy 'search)
  4128. (setq org-agenda-redo-command
  4129. (list 'org-search-view (if todo-only t nil)
  4130. (list 'if 'current-prefix-arg nil string)))
  4131. (setq org-agenda-query-string string)
  4132. (if (equal (string-to-char string) ?*)
  4133. (setq hdl-only t
  4134. words (substring string 1))
  4135. (setq words string))
  4136. (when (equal (string-to-char words) ?!)
  4137. (setq todo-only t
  4138. words (substring words 1)))
  4139. (when (equal (string-to-char words) ?:)
  4140. (setq full-words t
  4141. words (substring words 1)))
  4142. (if (or org-agenda-search-view-always-boolean
  4143. (member (string-to-char words) '(?- ?+ ?\{)))
  4144. (setq boolean t))
  4145. (setq words (org-split-string words))
  4146. (let (www w)
  4147. (while (setq w (pop words))
  4148. (while (and (string-match "\\\\\\'" w) words)
  4149. (setq w (concat (substring w 0 -1) " " (pop words))))
  4150. (push w www))
  4151. (setq words (nreverse www) www nil)
  4152. (while (setq w (pop words))
  4153. (when (and (string-match "\\`[-+]?{" w)
  4154. (not (string-match "}\\'" w)))
  4155. (while (and words (not (string-match "}\\'" (car words))))
  4156. (setq w (concat w " " (pop words))))
  4157. (setq w (concat w " " (pop words))))
  4158. (push w www))
  4159. (setq words (nreverse www)))
  4160. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4161. (when boolean
  4162. (let (wds w)
  4163. (while (setq w (pop words))
  4164. (if (or (equal (substring w 0 1) "\"")
  4165. (and (> (length w) 1)
  4166. (member (substring w 0 1) '("+" "-"))
  4167. (equal (substring w 1 2) "\"")))
  4168. (while (and words (not (equal (substring w -1) "\"")))
  4169. (setq w (concat w " " (pop words)))))
  4170. (and (string-match "\\`\\([-+]?\\)\"" w)
  4171. (setq w (replace-match "\\1" nil nil w)))
  4172. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4173. (push w wds))
  4174. (setq words (nreverse wds))))
  4175. (if boolean
  4176. (mapc (lambda (w)
  4177. (setq c (string-to-char w))
  4178. (if (equal c ?-)
  4179. (setq neg t w (substring w 1))
  4180. (if (equal c ?+)
  4181. (setq neg nil w (substring w 1))
  4182. (setq neg nil)))
  4183. (if (string-match "\\`{.*}\\'" w)
  4184. (setq re (substring w 1 -1))
  4185. (if full-words
  4186. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4187. (setq re (regexp-quote (downcase w)))))
  4188. (if neg (push re regexps-) (push re regexps+)))
  4189. words)
  4190. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4191. regexps+))
  4192. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4193. (if (not regexps+)
  4194. (setq regexp org-outline-regexp-bol)
  4195. (setq regexp (pop regexps+))
  4196. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4197. regexp))))
  4198. (setq files (org-agenda-files nil 'ifmode))
  4199. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4200. (pop org-agenda-text-search-extra-files)
  4201. (setq files (org-add-archive-files files)))
  4202. (setq files (append files org-agenda-text-search-extra-files)
  4203. rtnall nil)
  4204. (while (setq file (pop files))
  4205. (setq ee nil)
  4206. (catch 'nextfile
  4207. (org-check-agenda-file file)
  4208. (setq buffer (if (file-exists-p file)
  4209. (org-get-agenda-file-buffer file)
  4210. (error "No such file %s" file)))
  4211. (if (not buffer)
  4212. ;; If file does not exist, make sure an error message is sent
  4213. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4214. file))))
  4215. (with-current-buffer buffer
  4216. (with-syntax-table (org-search-syntax-table)
  4217. (unless (derived-mode-p 'org-mode)
  4218. (error "Agenda file %s is not in `org-mode'" file))
  4219. (let ((case-fold-search t))
  4220. (save-excursion
  4221. (save-restriction
  4222. (if (eq buffer org-agenda-restrict)
  4223. (narrow-to-region org-agenda-restrict-begin
  4224. org-agenda-restrict-end)
  4225. (widen))
  4226. (goto-char (point-min))
  4227. (unless (or (org-at-heading-p)
  4228. (outline-next-heading))
  4229. (throw 'nextfile t))
  4230. (goto-char (max (point-min) (1- (point))))
  4231. (while (re-search-forward regexp nil t)
  4232. (org-back-to-heading t)
  4233. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4234. (> (org-reduced-level (org-outline-level))
  4235. org-agenda-search-view-max-outline-level)
  4236. (forward-line -1)
  4237. (org-back-to-heading t)))
  4238. (skip-chars-forward "* ")
  4239. (setq beg (point-at-bol)
  4240. beg1 (point)
  4241. end (progn
  4242. (outline-next-heading)
  4243. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4244. (> (org-reduced-level (org-outline-level))
  4245. org-agenda-search-view-max-outline-level)
  4246. (forward-line 1)
  4247. (outline-next-heading)))
  4248. (point)))
  4249. (catch :skip
  4250. (goto-char beg)
  4251. (org-agenda-skip)
  4252. (setq str (buffer-substring-no-properties
  4253. (point-at-bol)
  4254. (if hdl-only (point-at-eol) end)))
  4255. (mapc (lambda (wr) (when (string-match wr str)
  4256. (goto-char (1- end))
  4257. (throw :skip t)))
  4258. regexps-)
  4259. (mapc (lambda (wr) (unless (string-match wr str)
  4260. (goto-char (1- end))
  4261. (throw :skip t)))
  4262. (if todo-only
  4263. (cons (concat "^\\*+[ \t]+"
  4264. org-not-done-regexp)
  4265. regexps+)
  4266. regexps+))
  4267. (goto-char beg)
  4268. (setq marker (org-agenda-new-marker (point))
  4269. category (org-get-category)
  4270. level (make-string (org-reduced-level (org-outline-level)) ? )
  4271. inherited-tags
  4272. (or (eq org-agenda-show-inherited-tags 'always)
  4273. (and (listp org-agenda-show-inherited-tags)
  4274. (memq 'todo org-agenda-show-inherited-tags))
  4275. (and (eq org-agenda-show-inherited-tags t)
  4276. (or (eq org-agenda-use-tag-inheritance t)
  4277. (memq 'todo org-agenda-use-tag-inheritance))))
  4278. tags (org-get-tags-at nil (not inherited-tags))
  4279. txt (org-agenda-format-item
  4280. ""
  4281. (buffer-substring-no-properties
  4282. beg1 (point-at-eol))
  4283. level category tags t))
  4284. (org-add-props txt props
  4285. 'org-marker marker 'org-hd-marker marker
  4286. 'org-todo-regexp org-todo-regexp
  4287. 'level level
  4288. 'org-complex-heading-regexp org-complex-heading-regexp
  4289. 'priority 1000
  4290. 'type "search")
  4291. (push txt ee)
  4292. (goto-char (1- end))))))))))
  4293. (setq rtn (nreverse ee))
  4294. (setq rtnall (append rtnall rtn)))
  4295. (if org-agenda-overriding-header
  4296. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4297. nil 'face 'org-agenda-structure) "\n")
  4298. (insert "Search words: ")
  4299. (add-text-properties (point-min) (1- (point))
  4300. (list 'face 'org-agenda-structure))
  4301. (setq pos (point))
  4302. (insert string "\n")
  4303. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4304. (setq pos (point))
  4305. (unless org-agenda-multi
  4306. (insert (substitute-command-keys "\
  4307. Press `\\[org-agenda-manipulate-query-add]', \
  4308. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4309. `\\[org-agenda-manipulate-query-add-re]', \
  4310. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4311. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4312. (add-text-properties pos (1- (point))
  4313. (list 'face 'org-agenda-structure))))
  4314. (org-agenda-mark-header-line (point-min))
  4315. (when rtnall
  4316. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4317. (goto-char (point-min))
  4318. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4319. (add-text-properties (point-min) (point-max)
  4320. `(org-agenda-type search
  4321. org-last-args (,todo-only ,string ,edit-at)
  4322. org-redo-cmd ,org-agenda-redo-command
  4323. org-series-cmd ,org-cmd))
  4324. (org-agenda-finalize)
  4325. (setq buffer-read-only t))))
  4326. ;;; Agenda TODO list
  4327. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4328. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4329. (concat
  4330. (if (or (equal keywords "ALL") (not keywords))
  4331. (propertize "ALL" 'face 'warning)
  4332. (mapconcat
  4333. (lambda (kw)
  4334. (propertize kw 'face (org-get-todo-face kw)))
  4335. (org-split-string keywords "|")
  4336. "|"))
  4337. "\n"))
  4338. (defvar org-select-this-todo-keyword nil)
  4339. (defvar org-last-arg nil)
  4340. ;;;###autoload
  4341. (defun org-todo-list (&optional arg)
  4342. "Show all (not done) TODO entries from all agenda file in a single list.
  4343. The prefix arg can be used to select a specific TODO keyword and limit
  4344. the list to these. When using `\\[universal-argument]', you will be prompted
  4345. for a keyword. A numeric prefix directly selects the Nth keyword in
  4346. `org-todo-keywords-1'."
  4347. (interactive "P")
  4348. (if org-agenda-overriding-arguments
  4349. (setq arg org-agenda-overriding-arguments))
  4350. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4351. (let* ((today (org-today))
  4352. (date (calendar-gregorian-from-absolute today))
  4353. (kwds org-todo-keywords-for-agenda)
  4354. (completion-ignore-case t)
  4355. (org-select-this-todo-keyword
  4356. (if (stringp arg) arg
  4357. (and arg (integerp arg) (> arg 0)
  4358. (nth (1- arg) kwds))))
  4359. rtn rtnall files file pos)
  4360. (when (equal arg '(4))
  4361. (setq org-select-this-todo-keyword
  4362. (completing-read "Keyword (or KWD1|K2D2|...): "
  4363. (mapcar #'list kwds) nil nil)))
  4364. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4365. (catch 'exit
  4366. (if org-agenda-sticky
  4367. (setq org-agenda-buffer-name
  4368. (if (stringp org-select-this-todo-keyword)
  4369. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4370. org-select-this-todo-keyword)
  4371. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4372. (org-agenda-prepare "TODO")
  4373. (org-compile-prefix-format 'todo)
  4374. (org-set-sorting-strategy 'todo)
  4375. (setq org-agenda-redo-command
  4376. `(org-todo-list (or (and (numberp current-prefix-arg)
  4377. current-prefix-arg)
  4378. ,org-select-this-todo-keyword
  4379. current-prefix-arg ,arg)))
  4380. (setq files (org-agenda-files nil 'ifmode)
  4381. rtnall nil)
  4382. (while (setq file (pop files))
  4383. (catch 'nextfile
  4384. (org-check-agenda-file file)
  4385. (setq rtn (org-agenda-get-day-entries file date :todo))
  4386. (setq rtnall (append rtnall rtn))))
  4387. (if org-agenda-overriding-header
  4388. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4389. nil 'face 'org-agenda-structure) "\n")
  4390. (insert "Global list of TODO items of type: ")
  4391. (add-text-properties (point-min) (1- (point))
  4392. (list 'face 'org-agenda-structure
  4393. 'short-heading
  4394. (concat "ToDo: "
  4395. (or org-select-this-todo-keyword "ALL"))))
  4396. (org-agenda-mark-header-line (point-min))
  4397. (insert (org-agenda-propertize-selected-todo-keywords
  4398. org-select-this-todo-keyword))
  4399. (setq pos (point))
  4400. (unless org-agenda-multi
  4401. (insert (substitute-command-keys "Available with \
  4402. `N \\[org-agenda-redo]': (0)[ALL]"))
  4403. (let ((n 0) s)
  4404. (mapc (lambda (x)
  4405. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4406. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4407. (insert "\n "))
  4408. (insert " " s))
  4409. kwds))
  4410. (insert "\n"))
  4411. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4412. (org-agenda-mark-header-line (point-min))
  4413. (when rtnall
  4414. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4415. (goto-char (point-min))
  4416. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4417. (add-text-properties (point-min) (point-max)
  4418. `(org-agenda-type todo
  4419. org-last-args ,arg
  4420. org-redo-cmd ,org-agenda-redo-command
  4421. org-series-cmd ,org-cmd))
  4422. (org-agenda-finalize)
  4423. (setq buffer-read-only t))))
  4424. ;;; Agenda tags match
  4425. ;;;###autoload
  4426. (defun org-tags-view (&optional todo-only match)
  4427. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4428. The prefix arg TODO-ONLY limits the search to TODO entries."
  4429. (interactive "P")
  4430. (if org-agenda-overriding-arguments
  4431. (setq todo-only (car org-agenda-overriding-arguments)
  4432. match (nth 1 org-agenda-overriding-arguments)))
  4433. (let* ((org-tags-match-list-sublevels
  4434. org-tags-match-list-sublevels)
  4435. (completion-ignore-case t)
  4436. rtn rtnall files file pos matcher
  4437. buffer)
  4438. (when (and (stringp match) (not (string-match "\\S-" match)))
  4439. (setq match nil))
  4440. (catch 'exit
  4441. (if org-agenda-sticky
  4442. (setq org-agenda-buffer-name
  4443. (if (stringp match)
  4444. (format "*Org Agenda(%s:%s)*"
  4445. (or org-keys (or (and todo-only "M") "m")) match)
  4446. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4447. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4448. ;; expanding tags within `org-make-tags-matcher'
  4449. (org-agenda-prepare (concat "TAGS " match))
  4450. (setq org--matcher-tags-todo-only todo-only
  4451. matcher (org-make-tags-matcher match)
  4452. match (car matcher)
  4453. matcher (cdr matcher))
  4454. (org-compile-prefix-format 'tags)
  4455. (org-set-sorting-strategy 'tags)
  4456. (setq org-agenda-query-string match)
  4457. (setq org-agenda-redo-command
  4458. (list 'org-tags-view
  4459. `(quote ,org--matcher-tags-todo-only)
  4460. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4461. (setq files (org-agenda-files nil 'ifmode)
  4462. rtnall nil)
  4463. (while (setq file (pop files))
  4464. (catch 'nextfile
  4465. (org-check-agenda-file file)
  4466. (setq buffer (if (file-exists-p file)
  4467. (org-get-agenda-file-buffer file)
  4468. (error "No such file %s" file)))
  4469. (if (not buffer)
  4470. ;; If file does not exist, error message to agenda
  4471. (setq rtn (list
  4472. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4473. rtnall (append rtnall rtn))
  4474. (with-current-buffer buffer
  4475. (unless (derived-mode-p 'org-mode)
  4476. (error "Agenda file %s is not in `org-mode'" file))
  4477. (save-excursion
  4478. (save-restriction
  4479. (if (eq buffer org-agenda-restrict)
  4480. (narrow-to-region org-agenda-restrict-begin
  4481. org-agenda-restrict-end)
  4482. (widen))
  4483. (setq rtn (org-scan-tags 'agenda
  4484. matcher
  4485. org--matcher-tags-todo-only))
  4486. (setq rtnall (append rtnall rtn))))))))
  4487. (if org-agenda-overriding-header
  4488. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4489. nil 'face 'org-agenda-structure) "\n")
  4490. (insert "Headlines with TAGS match: ")
  4491. (add-text-properties (point-min) (1- (point))
  4492. (list 'face 'org-agenda-structure
  4493. 'short-heading
  4494. (concat "Match: " match)))
  4495. (setq pos (point))
  4496. (insert match "\n")
  4497. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4498. (setq pos (point))
  4499. (unless org-agenda-multi
  4500. (insert (substitute-command-keys
  4501. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4502. to search again with new search string\n")))
  4503. (add-text-properties pos (1- (point))
  4504. (list 'face 'org-agenda-structure)))
  4505. (org-agenda-mark-header-line (point-min))
  4506. (when rtnall
  4507. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4508. (goto-char (point-min))
  4509. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4510. (add-text-properties
  4511. (point-min) (point-max)
  4512. `(org-agenda-type tags
  4513. org-last-args (,org--matcher-tags-todo-only ,match)
  4514. org-redo-cmd ,org-agenda-redo-command
  4515. org-series-cmd ,org-cmd))
  4516. (org-agenda-finalize)
  4517. (setq buffer-read-only t))))
  4518. ;;; Agenda Finding stuck projects
  4519. (defvar org-agenda-skip-regexp nil
  4520. "Regular expression used in skipping subtrees for the agenda.
  4521. This is basically a temporary global variable that can be set and then
  4522. used by user-defined selections using `org-agenda-skip-function'.")
  4523. (defvar org-agenda-overriding-header nil
  4524. "When set during agenda, todo and tags searches it replaces the header.
  4525. This variable should not be set directly, but custom commands can bind it
  4526. in the options section.")
  4527. (defun org-agenda-skip-entry-when-regexp-matches ()
  4528. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4529. If yes, it returns the end position of this entry, causing agenda commands
  4530. to skip the entry but continuing the search in the subtree. This is a
  4531. function that can be put into `org-agenda-skip-function' for the duration
  4532. of a command."
  4533. (let ((end (save-excursion (org-end-of-subtree t)))
  4534. skip)
  4535. (save-excursion
  4536. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4537. (and skip end)))
  4538. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4539. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4540. If yes, it returns the end position of this tree, causing agenda commands
  4541. to skip this subtree. This is a function that can be put into
  4542. `org-agenda-skip-function' for the duration of a command."
  4543. (let ((end (save-excursion (org-end-of-subtree t)))
  4544. skip)
  4545. (save-excursion
  4546. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4547. (and skip end)))
  4548. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4549. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4550. If yes, it returns the end position of the current entry (NOT the tree),
  4551. causing agenda commands to skip the entry but continuing the search in
  4552. the subtree. This is a function that can be put into
  4553. `org-agenda-skip-function' for the duration of a command. An important
  4554. use of this function is for the stuck project list."
  4555. (let ((end (save-excursion (org-end-of-subtree t)))
  4556. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4557. skip)
  4558. (save-excursion
  4559. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4560. (and skip entry-end)))
  4561. (defun org-agenda-skip-entry-if (&rest conditions)
  4562. "Skip entry if any of CONDITIONS is true.
  4563. See `org-agenda-skip-if' for details."
  4564. (org-agenda-skip-if nil conditions))
  4565. (defun org-agenda-skip-subtree-if (&rest conditions)
  4566. "Skip subtree if any of CONDITIONS is true.
  4567. See `org-agenda-skip-if' for details."
  4568. (org-agenda-skip-if t conditions))
  4569. (defun org-agenda-skip-if (subtree conditions)
  4570. "Checks current entity for CONDITIONS.
  4571. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4572. the entry (i.e. the text before the next heading) is checked.
  4573. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4574. from different tests. Valid conditions are:
  4575. scheduled Check if there is a scheduled cookie
  4576. notscheduled Check if there is no scheduled cookie
  4577. deadline Check if there is a deadline
  4578. notdeadline Check if there is no deadline
  4579. timestamp Check if there is a timestamp (also deadline or scheduled)
  4580. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4581. regexp Check if regexp matches
  4582. notregexp Check if regexp does not match.
  4583. todo Check if TODO keyword matches
  4584. nottodo Check if TODO keyword does not match
  4585. The regexp is taken from the conditions list, it must come right after
  4586. the `regexp' or `notregexp' element.
  4587. `todo' and `nottodo' accept as an argument a list of todo
  4588. keywords, which may include \"*\" to match any todo keyword.
  4589. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4590. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4591. Instead of a list, a keyword class may be given. For example:
  4592. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4593. would skip entries that haven't been marked with any of \"DONE\"
  4594. keywords. Possible classes are: `todo', `done', `any'.
  4595. If any of these conditions is met, this function returns the end point of
  4596. the entity, causing the search to continue from there. This is a function
  4597. that can be put into `org-agenda-skip-function' for the duration of a command."
  4598. (let (beg end m)
  4599. (org-back-to-heading t)
  4600. (setq beg (point)
  4601. end (if subtree
  4602. (progn (org-end-of-subtree t) (point))
  4603. (progn (outline-next-heading) (1- (point)))))
  4604. (goto-char beg)
  4605. (and
  4606. (or
  4607. (and (memq 'scheduled conditions)
  4608. (re-search-forward org-scheduled-time-regexp end t))
  4609. (and (memq 'notscheduled conditions)
  4610. (not (re-search-forward org-scheduled-time-regexp end t)))
  4611. (and (memq 'deadline conditions)
  4612. (re-search-forward org-deadline-time-regexp end t))
  4613. (and (memq 'notdeadline conditions)
  4614. (not (re-search-forward org-deadline-time-regexp end t)))
  4615. (and (memq 'timestamp conditions)
  4616. (re-search-forward org-ts-regexp end t))
  4617. (and (memq 'nottimestamp conditions)
  4618. (not (re-search-forward org-ts-regexp end t)))
  4619. (and (setq m (memq 'regexp conditions))
  4620. (stringp (nth 1 m))
  4621. (re-search-forward (nth 1 m) end t))
  4622. (and (setq m (memq 'notregexp conditions))
  4623. (stringp (nth 1 m))
  4624. (not (re-search-forward (nth 1 m) end t)))
  4625. (and (or
  4626. (setq m (memq 'nottodo conditions))
  4627. (setq m (memq 'todo-unblocked conditions))
  4628. (setq m (memq 'nottodo-unblocked conditions))
  4629. (setq m (memq 'todo conditions)))
  4630. (org-agenda-skip-if-todo m end)))
  4631. end)))
  4632. (defun org-agenda-skip-if-todo (args end)
  4633. "Helper function for `org-agenda-skip-if', do not use it directly.
  4634. ARGS is a list with first element either `todo', `nottodo',
  4635. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4636. a list of TODO keywords, or a state symbol `todo' or `done' or
  4637. `any'."
  4638. (let ((kw (car args))
  4639. (arg (cadr args))
  4640. todo-wds todo-re)
  4641. (setq todo-wds
  4642. (org-uniquify
  4643. (cond
  4644. ((listp arg) ;; list of keywords
  4645. (if (member "*" arg)
  4646. (mapcar 'substring-no-properties org-todo-keywords-1)
  4647. arg))
  4648. ((symbolp arg) ;; keyword class name
  4649. (cond
  4650. ((eq arg 'todo)
  4651. (org-delete-all org-done-keywords
  4652. (mapcar 'substring-no-properties
  4653. org-todo-keywords-1)))
  4654. ((eq arg 'done) org-done-keywords)
  4655. ((eq arg 'any)
  4656. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4657. (setq todo-re
  4658. (concat "^\\*+[ \t]+\\<\\("
  4659. (mapconcat 'identity todo-wds "\\|")
  4660. "\\)\\>"))
  4661. (cond
  4662. ((eq kw 'todo) (re-search-forward todo-re end t))
  4663. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4664. ((eq kw 'todo-unblocked)
  4665. (catch 'unblocked
  4666. (while (re-search-forward todo-re end t)
  4667. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4668. nil))
  4669. ((eq kw 'nottodo-unblocked)
  4670. (catch 'unblocked
  4671. (while (re-search-forward todo-re end t)
  4672. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4673. t))
  4674. )))
  4675. ;;;###autoload
  4676. (defun org-agenda-list-stuck-projects (&rest ignore)
  4677. "Create agenda view for projects that are stuck.
  4678. Stuck projects are project that have no next actions. For the definitions
  4679. of what a project is and how to check if it stuck, customize the variable
  4680. `org-stuck-projects'."
  4681. (interactive)
  4682. (let* ((org-agenda-skip-function
  4683. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4684. ;; We could have used org-agenda-skip-if here.
  4685. (org-agenda-overriding-header
  4686. (or org-agenda-overriding-header "List of stuck projects: "))
  4687. (matcher (nth 0 org-stuck-projects))
  4688. (todo (nth 1 org-stuck-projects))
  4689. (todo-wds (if (member "*" todo)
  4690. (progn
  4691. (org-agenda-prepare-buffers (org-agenda-files
  4692. nil 'ifmode))
  4693. (org-delete-all
  4694. org-done-keywords-for-agenda
  4695. (copy-sequence org-todo-keywords-for-agenda)))
  4696. todo))
  4697. (todo-re (concat "^\\*+[ \t]+\\("
  4698. (mapconcat 'identity todo-wds "\\|")
  4699. "\\)\\>"))
  4700. (tags (nth 2 org-stuck-projects))
  4701. (tags-re (if (member "*" tags)
  4702. (concat org-outline-regexp-bol
  4703. ".*:[[:alnum:]_@#%]+:[ \t]*$")
  4704. (if tags
  4705. (concat org-outline-regexp-bol
  4706. ".*:\\("
  4707. (mapconcat #'identity tags "\\|")
  4708. "\\):[[:alnum:]_@#%:]*[ \t]*$"))))
  4709. (gen-re (nth 3 org-stuck-projects))
  4710. (re-list
  4711. (delq nil
  4712. (list
  4713. (if todo todo-re)
  4714. (if tags tags-re)
  4715. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4716. gen-re)))))
  4717. (setq org-agenda-skip-regexp
  4718. (if re-list
  4719. (mapconcat 'identity re-list "\\|")
  4720. (error "No information how to identify unstuck projects")))
  4721. (org-tags-view nil matcher)
  4722. (setq org-agenda-buffer-name (buffer-name))
  4723. (with-current-buffer org-agenda-buffer-name
  4724. (setq org-agenda-redo-command
  4725. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4726. ;;; Diary integration
  4727. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4728. (defvar diary-list-entries-hook)
  4729. (defvar diary-time-regexp)
  4730. (defun org-get-entries-from-diary (date)
  4731. "Get the (Emacs Calendar) diary entries for DATE."
  4732. (require 'diary-lib)
  4733. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4734. (diary-display-function 'diary-fancy-display)
  4735. (pop-up-frames nil)
  4736. (diary-list-entries-hook
  4737. (cons 'org-diary-default-entry diary-list-entries-hook))
  4738. (diary-file-name-prefix nil) ; turn this feature off
  4739. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4740. entries
  4741. (org-disable-agenda-to-diary t))
  4742. (save-excursion
  4743. (save-window-excursion
  4744. (funcall (if (fboundp 'diary-list-entries)
  4745. 'diary-list-entries 'list-diary-entries)
  4746. date 1)))
  4747. (if (not (get-buffer diary-fancy-buffer))
  4748. (setq entries nil)
  4749. (with-current-buffer diary-fancy-buffer
  4750. (setq buffer-read-only nil)
  4751. (if (zerop (buffer-size))
  4752. ;; No entries
  4753. (setq entries nil)
  4754. ;; Omit the date and other unnecessary stuff
  4755. (org-agenda-cleanup-fancy-diary)
  4756. ;; Add prefix to each line and extend the text properties
  4757. (if (zerop (buffer-size))
  4758. (setq entries nil)
  4759. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4760. (setq entries
  4761. (with-temp-buffer
  4762. (insert entries) (goto-char (point-min))
  4763. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4764. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4765. (replace-match (concat "; " (match-string 1)))))
  4766. (buffer-string)))))
  4767. (set-buffer-modified-p nil)
  4768. (kill-buffer diary-fancy-buffer)))
  4769. (when entries
  4770. (setq entries (org-split-string entries "\n"))
  4771. (setq entries
  4772. (mapcar
  4773. (lambda (x)
  4774. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4775. ;; Extend the text properties to the beginning of the line
  4776. (org-add-props x (text-properties-at (1- (length x)) x)
  4777. 'type "diary" 'date date 'face 'org-agenda-diary))
  4778. entries)))))
  4779. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4780. "Hook run when the fancy diary buffer is cleaned up.")
  4781. (defun org-agenda-cleanup-fancy-diary ()
  4782. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4783. This gets rid of the date, the underline under the date, and
  4784. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4785. date. It also removes lines that contain only whitespace."
  4786. (goto-char (point-min))
  4787. (if (looking-at ".*?:[ \t]*")
  4788. (progn
  4789. (replace-match "")
  4790. (re-search-forward "\n=+$" nil t)
  4791. (replace-match "")
  4792. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4793. (re-search-forward "\n=+$" nil t)
  4794. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4795. (goto-char (point-min))
  4796. (while (re-search-forward "^ +\n" nil t)
  4797. (replace-match ""))
  4798. (goto-char (point-min))
  4799. (if (re-search-forward "^Org mode dummy\n?" nil t)
  4800. (replace-match ""))
  4801. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4802. ;; Make sure entries from the diary have the right text properties.
  4803. (eval-after-load "diary-lib"
  4804. '(if (boundp 'diary-modify-entry-list-string-function)
  4805. ;; We can rely on the hook, nothing to do
  4806. nil
  4807. ;; Hook not available, must use advice to make this work
  4808. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4809. "Make the position visible."
  4810. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4811. (stringp string)
  4812. buffer-file-name)
  4813. (setq string (org-modify-diary-entry-string string))))))
  4814. (defun org-modify-diary-entry-string (string)
  4815. "Add text properties to string, allowing Org to act on it."
  4816. (org-add-props string nil
  4817. 'mouse-face 'highlight
  4818. 'help-echo (if buffer-file-name
  4819. (format "mouse-2 or RET jump to diary file %s"
  4820. (abbreviate-file-name buffer-file-name))
  4821. "")
  4822. 'org-agenda-diary-link t
  4823. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4824. (defun org-diary-default-entry ()
  4825. "Add a dummy entry to the diary.
  4826. Needed to avoid empty dates which mess up holiday display."
  4827. ;; Catch the error if dealing with the new add-to-diary-alist
  4828. (when org-disable-agenda-to-diary
  4829. (condition-case nil
  4830. (org-add-to-diary-list original-date "Org mode dummy" "")
  4831. (error
  4832. (org-add-to-diary-list original-date "Org mode dummy" "" nil)))))
  4833. (defun org-add-to-diary-list (&rest args)
  4834. (if (fboundp 'diary-add-to-list)
  4835. (apply 'diary-add-to-list args)
  4836. (apply 'add-to-diary-list args)))
  4837. (defvar org-diary-last-run-time nil)
  4838. ;;;###autoload
  4839. (defun org-diary (&rest args)
  4840. "Return diary information from org files.
  4841. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4842. It accesses org files and extracts information from those files to be
  4843. listed in the diary. The function accepts arguments specifying what
  4844. items should be listed. For a list of arguments allowed here, see the
  4845. variable `org-agenda-entry-types'.
  4846. The call in the diary file should look like this:
  4847. &%%(org-diary) ~/path/to/some/orgfile.org
  4848. Use a separate line for each org file to check. Or, if you omit the file name,
  4849. all files listed in `org-agenda-files' will be checked automatically:
  4850. &%%(org-diary)
  4851. If you don't give any arguments (as in the example above), the default value
  4852. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4853. So the example above may also be written as
  4854. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4855. The function expects the lisp variables `entry' and `date' to be provided
  4856. by the caller, because this is how the calendar works. Don't use this
  4857. function from a program - use `org-agenda-get-day-entries' instead."
  4858. (when (> (- (float-time)
  4859. org-agenda-last-marker-time)
  4860. 5)
  4861. ;; I am not sure if this works with sticky agendas, because the marker
  4862. ;; list is then no longer a global variable.
  4863. (org-agenda-reset-markers))
  4864. (org-compile-prefix-format 'agenda)
  4865. (org-set-sorting-strategy 'agenda)
  4866. (setq args (or args org-agenda-entry-types))
  4867. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4868. (list entry)
  4869. (org-agenda-files t)))
  4870. (time (float-time))
  4871. file rtn results)
  4872. (when (or (not org-diary-last-run-time)
  4873. (> (- time
  4874. org-diary-last-run-time)
  4875. 3))
  4876. (org-agenda-prepare-buffers files))
  4877. (setq org-diary-last-run-time time)
  4878. ;; If this is called during org-agenda, don't return any entries to
  4879. ;; the calendar. Org Agenda will list these entries itself.
  4880. (if org-disable-agenda-to-diary (setq files nil))
  4881. (while (setq file (pop files))
  4882. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4883. (setq results (append results rtn)))
  4884. (when results
  4885. (setq results
  4886. (mapcar (lambda (i) (replace-regexp-in-string
  4887. org-bracket-link-regexp "\\3" i)) results))
  4888. (concat (org-agenda-finalize-entries results) "\n"))))
  4889. ;;; Agenda entry finders
  4890. (defun org-agenda--timestamp-to-absolute (&rest args)
  4891. "Call `org-time-string-to-absolute' with ARGS.
  4892. However, throw `:skip' whenever an error is raised."
  4893. (condition-case e
  4894. (apply #'org-time-string-to-absolute args)
  4895. (org-diary-sexp-no-match (throw :skip nil))
  4896. (error
  4897. (message "%s; Skipping entry" (error-message-string e))
  4898. (throw :skip nil))))
  4899. (defun org-agenda-get-day-entries (file date &rest args)
  4900. "Does the work for `org-diary' and `org-agenda'.
  4901. FILE is the path to a file to be checked for entries. DATE is date like
  4902. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4903. which kind of entries should be extracted. For details about these, see
  4904. the documentation of `org-diary'."
  4905. (let* ((org-startup-folded nil)
  4906. (org-startup-align-all-tables nil)
  4907. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  4908. (error "No such file %s" file))))
  4909. (if (not buffer)
  4910. ;; If file does not exist, signal it in diary nonetheless.
  4911. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4912. (with-current-buffer buffer
  4913. (unless (derived-mode-p 'org-mode)
  4914. (error "Agenda file %s is not in `org-mode'" file))
  4915. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4916. (setf org-agenda-current-date date)
  4917. (save-excursion
  4918. (save-restriction
  4919. (if (eq buffer org-agenda-restrict)
  4920. (narrow-to-region org-agenda-restrict-begin
  4921. org-agenda-restrict-end)
  4922. (widen))
  4923. ;; Rationalize ARGS. Also make sure `:deadline' comes
  4924. ;; first in order to populate DEADLINES before passing it.
  4925. ;;
  4926. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  4927. ;; guarding us from modifying `org-agenda-entry-types'.
  4928. (setf args (org-uniquify (or args org-agenda-entry-types)))
  4929. (when (and (memq :scheduled args) (memq :scheduled* args))
  4930. (setf args (delq :scheduled* args)))
  4931. (cond
  4932. ((memq :deadline args)
  4933. (setf args (cons :deadline
  4934. (delq :deadline (delq :deadline* args)))))
  4935. ((memq :deadline* args)
  4936. (setf args (cons :deadline* (delq :deadline* args)))))
  4937. ;; Collect list of headlines. Return them flattened.
  4938. (let ((case-fold-search nil) results deadlines)
  4939. (dolist (arg args (apply #'nconc (nreverse results)))
  4940. (pcase arg
  4941. ((and :todo (guard (org-agenda-today-p date)))
  4942. (push (org-agenda-get-todos) results))
  4943. (:timestamp
  4944. (push (org-agenda-get-blocks) results)
  4945. (push (org-agenda-get-timestamps deadlines) results))
  4946. (:sexp
  4947. (push (org-agenda-get-sexps) results))
  4948. (:scheduled
  4949. (push (org-agenda-get-scheduled deadlines) results))
  4950. (:scheduled*
  4951. (push (org-agenda-get-scheduled deadlines t) results))
  4952. (:closed
  4953. (push (org-agenda-get-progress) results))
  4954. (:deadline
  4955. (setf deadlines (org-agenda-get-deadlines))
  4956. (push deadlines results))
  4957. (:deadline*
  4958. (setf deadlines (org-agenda-get-deadlines t))
  4959. (push deadlines results)))))))))))
  4960. (defsubst org-em (x y list)
  4961. "Is X or Y a member of LIST?"
  4962. (or (memq x list) (memq y list)))
  4963. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4964. (defvar org-agenda-sorting-strategy-selected nil)
  4965. (defun org-agenda-entry-get-agenda-timestamp (pom)
  4966. "Retrieve timestamp information for sorting agenda views.
  4967. Given a point or marker POM, returns a cons cell of the timestamp
  4968. and the timestamp type relevant for the sorting strategy in
  4969. `org-agenda-sorting-strategy-selected'."
  4970. (let (ts ts-date-type)
  4971. (save-match-data
  4972. (cond ((org-em 'scheduled-up 'scheduled-down
  4973. org-agenda-sorting-strategy-selected)
  4974. (setq ts (org-entry-get pom "SCHEDULED")
  4975. ts-date-type " scheduled"))
  4976. ((org-em 'deadline-up 'deadline-down
  4977. org-agenda-sorting-strategy-selected)
  4978. (setq ts (org-entry-get pom "DEADLINE")
  4979. ts-date-type " deadline"))
  4980. ((org-em 'ts-up 'ts-down
  4981. org-agenda-sorting-strategy-selected)
  4982. (setq ts (org-entry-get pom "TIMESTAMP")
  4983. ts-date-type " timestamp"))
  4984. ((org-em 'tsia-up 'tsia-down
  4985. org-agenda-sorting-strategy-selected)
  4986. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  4987. ts-date-type " timestamp_ia"))
  4988. ((org-em 'timestamp-up 'timestamp-down
  4989. org-agenda-sorting-strategy-selected)
  4990. (setq ts (or (org-entry-get pom "SCHEDULED")
  4991. (org-entry-get pom "DEADLINE")
  4992. (org-entry-get pom "TIMESTAMP")
  4993. (org-entry-get pom "TIMESTAMP_IA"))
  4994. ts-date-type ""))
  4995. (t (setq ts-date-type "")))
  4996. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  4997. ts-date-type))))
  4998. (defun org-agenda-get-todos ()
  4999. "Return the TODO information for agenda display."
  5000. (let* ((props (list 'face nil
  5001. 'done-face 'org-agenda-done
  5002. 'org-not-done-regexp org-not-done-regexp
  5003. 'org-todo-regexp org-todo-regexp
  5004. 'org-complex-heading-regexp org-complex-heading-regexp
  5005. 'mouse-face 'highlight
  5006. 'help-echo
  5007. (format "mouse-2 or RET jump to org file %s"
  5008. (abbreviate-file-name buffer-file-name))))
  5009. (case-fold-search nil)
  5010. (regexp (format org-heading-keyword-regexp-format
  5011. (cond
  5012. ((and org-select-this-todo-keyword
  5013. (equal org-select-this-todo-keyword "*"))
  5014. org-todo-regexp)
  5015. (org-select-this-todo-keyword
  5016. (concat "\\("
  5017. (mapconcat 'identity
  5018. (org-split-string
  5019. org-select-this-todo-keyword
  5020. "|")
  5021. "\\|") "\\)"))
  5022. (t org-not-done-regexp))))
  5023. marker priority category level tags todo-state
  5024. ts-date ts-date-type ts-date-pair
  5025. ee txt beg end inherited-tags todo-state-end-pos)
  5026. (goto-char (point-min))
  5027. (while (re-search-forward regexp nil t)
  5028. (catch :skip
  5029. (save-match-data
  5030. (beginning-of-line)
  5031. (org-agenda-skip)
  5032. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5033. (unless (and (setq todo-state (org-get-todo-state))
  5034. (setq todo-state-end-pos (match-end 2)))
  5035. (goto-char end)
  5036. (throw :skip nil))
  5037. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5038. (goto-char (1+ beg))
  5039. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5040. (throw :skip nil)))
  5041. (goto-char (match-beginning 2))
  5042. (setq marker (org-agenda-new-marker (match-beginning 0))
  5043. category (org-get-category)
  5044. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5045. ts-date (car ts-date-pair)
  5046. ts-date-type (cdr ts-date-pair)
  5047. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5048. inherited-tags
  5049. (or (eq org-agenda-show-inherited-tags 'always)
  5050. (and (listp org-agenda-show-inherited-tags)
  5051. (memq 'todo org-agenda-show-inherited-tags))
  5052. (and (eq org-agenda-show-inherited-tags t)
  5053. (or (eq org-agenda-use-tag-inheritance t)
  5054. (memq 'todo org-agenda-use-tag-inheritance))))
  5055. tags (org-get-tags-at nil (not inherited-tags))
  5056. level (make-string (org-reduced-level (org-outline-level)) ? )
  5057. txt (org-agenda-format-item "" txt level category tags t)
  5058. priority (1+ (org-get-priority txt)))
  5059. (org-add-props txt props
  5060. 'org-marker marker 'org-hd-marker marker
  5061. 'priority priority
  5062. 'level level
  5063. 'ts-date ts-date
  5064. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5065. (push txt ee)
  5066. (if org-agenda-todo-list-sublevels
  5067. (goto-char todo-state-end-pos)
  5068. (org-end-of-subtree 'invisible))))
  5069. (nreverse ee)))
  5070. (defun org-agenda-todo-custom-ignore-p (time n)
  5071. "Check whether timestamp is farther away than n number of days.
  5072. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5073. `org-agenda-todo-ignore-scheduled' or
  5074. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5075. (let ((days (org-time-stamp-to-now
  5076. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5077. (if (>= n 0)
  5078. (>= days n)
  5079. (<= days n))))
  5080. ;;;###autoload
  5081. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5082. (&optional end)
  5083. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5084. (when (or org-agenda-todo-ignore-with-date
  5085. org-agenda-todo-ignore-scheduled
  5086. org-agenda-todo-ignore-deadlines
  5087. org-agenda-todo-ignore-timestamp)
  5088. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5089. (save-excursion
  5090. (or (and org-agenda-todo-ignore-with-date
  5091. (re-search-forward org-ts-regexp end t))
  5092. (and org-agenda-todo-ignore-scheduled
  5093. (re-search-forward org-scheduled-time-regexp end t)
  5094. (cond
  5095. ((eq org-agenda-todo-ignore-scheduled 'future)
  5096. (> (org-time-stamp-to-now
  5097. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5098. ((eq org-agenda-todo-ignore-scheduled 'past)
  5099. (<= (org-time-stamp-to-now
  5100. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5101. ((numberp org-agenda-todo-ignore-scheduled)
  5102. (org-agenda-todo-custom-ignore-p
  5103. (match-string 1) org-agenda-todo-ignore-scheduled))
  5104. (t)))
  5105. (and org-agenda-todo-ignore-deadlines
  5106. (re-search-forward org-deadline-time-regexp end t)
  5107. (cond
  5108. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5109. ((eq org-agenda-todo-ignore-deadlines 'far)
  5110. (not (org-deadline-close-p (match-string 1))))
  5111. ((eq org-agenda-todo-ignore-deadlines 'future)
  5112. (> (org-time-stamp-to-now
  5113. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5114. ((eq org-agenda-todo-ignore-deadlines 'past)
  5115. (<= (org-time-stamp-to-now
  5116. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5117. ((numberp org-agenda-todo-ignore-deadlines)
  5118. (org-agenda-todo-custom-ignore-p
  5119. (match-string 1) org-agenda-todo-ignore-deadlines))
  5120. (t (org-deadline-close-p (match-string 1)))))
  5121. (and org-agenda-todo-ignore-timestamp
  5122. (let ((buffer (current-buffer))
  5123. (regexp
  5124. (concat
  5125. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5126. (start (point)))
  5127. ;; Copy current buffer into a temporary one
  5128. (with-temp-buffer
  5129. (insert-buffer-substring buffer start end)
  5130. (goto-char (point-min))
  5131. ;; Delete SCHEDULED and DEADLINE items
  5132. (while (re-search-forward regexp end t)
  5133. (delete-region (match-beginning 0) (match-end 0)))
  5134. (goto-char (point-min))
  5135. ;; No search for timestamp left
  5136. (when (re-search-forward org-ts-regexp nil t)
  5137. (cond
  5138. ((eq org-agenda-todo-ignore-timestamp 'future)
  5139. (> (org-time-stamp-to-now
  5140. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5141. ((eq org-agenda-todo-ignore-timestamp 'past)
  5142. (<= (org-time-stamp-to-now
  5143. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5144. ((numberp org-agenda-todo-ignore-timestamp)
  5145. (org-agenda-todo-custom-ignore-p
  5146. (match-string 1) org-agenda-todo-ignore-timestamp))
  5147. (t))))))))))
  5148. (defun org-agenda-get-timestamps (&optional deadlines)
  5149. "Return the date stamp information for agenda display.
  5150. Optional argument DEADLINES is a list of deadline items to be
  5151. displayed in agenda view."
  5152. (let* ((props (list 'face 'org-agenda-calendar-event
  5153. 'org-not-done-regexp org-not-done-regexp
  5154. 'org-todo-regexp org-todo-regexp
  5155. 'org-complex-heading-regexp org-complex-heading-regexp
  5156. 'mouse-face 'highlight
  5157. 'help-echo
  5158. (format "mouse-2 or RET jump to Org file %s"
  5159. (abbreviate-file-name buffer-file-name))))
  5160. (current (calendar-absolute-from-gregorian date))
  5161. (today (org-today))
  5162. (deadline-position-alist
  5163. (mapcar (lambda (d)
  5164. (let ((m (get-text-property 0 'org-hd-marker d)))
  5165. (and m (marker-position m))))
  5166. deadlines))
  5167. ;; Match time-stamps set to current date, time-stamps with
  5168. ;; a repeater, and S-exp time-stamps.
  5169. (regexp
  5170. (concat
  5171. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5172. (regexp-quote
  5173. (substring
  5174. (format-time-string
  5175. (car org-time-stamp-formats)
  5176. (apply #'encode-time ; DATE bound by calendar
  5177. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5178. 1 11))
  5179. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5180. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5181. timestamp-items)
  5182. (goto-char (point-min))
  5183. (while (re-search-forward regexp nil t)
  5184. ;; Skip date ranges, scheduled and deadlines, which are handled
  5185. ;; specially. Also skip time-stamps before first headline as
  5186. ;; there would be no entry to add to the agenda. Eventually,
  5187. ;; ignore clock entries.
  5188. (catch :skip
  5189. (save-match-data
  5190. (when (or (org-at-date-range-p)
  5191. (org-at-planning-p)
  5192. (org-before-first-heading-p)
  5193. (and org-agenda-include-inactive-timestamps
  5194. (org-at-clock-log-p)))
  5195. (throw :skip nil))
  5196. (org-agenda-skip))
  5197. (let* ((pos (match-beginning 0))
  5198. (repeat (match-string 1))
  5199. (sexp-entry (match-string 3))
  5200. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5201. (save-excursion
  5202. (goto-char pos)
  5203. (looking-at org-ts-regexp-both)
  5204. (match-string 0))))
  5205. (todo-state (org-get-todo-state))
  5206. (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5207. (member todo-state
  5208. org-agenda-repeating-timestamp-show-all)))
  5209. (warntime (get-text-property (point) 'org-appt-warntime))
  5210. (done? (member todo-state org-done-keywords)))
  5211. ;; Possibly skip done tasks.
  5212. (when (and done? org-agenda-skip-timestamp-if-done)
  5213. (throw :skip t))
  5214. ;; S-exp entry doesn't match current day: skip it.
  5215. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5216. (throw :skip nil))
  5217. ;; When time-stamp doesn't match CURRENT but has a repeater,
  5218. ;; make sure it repeats on CURRENT. Furthermore, if
  5219. ;; SHOW-ALL is nil, ensure that repeats are only the first
  5220. ;; before and the first after today.
  5221. (when (and repeat
  5222. (if show-all
  5223. (/= current
  5224. (org-agenda--timestamp-to-absolute
  5225. repeat current 'future (current-buffer) pos))
  5226. (and (/= current
  5227. (org-agenda--timestamp-to-absolute
  5228. repeat today 'past (current-buffer) pos))
  5229. (/= current
  5230. (org-agenda--timestamp-to-absolute
  5231. repeat today 'future (current-buffer) pos)))))
  5232. (throw :skip nil))
  5233. (save-excursion
  5234. (re-search-backward org-outline-regexp-bol nil t)
  5235. ;; Possibly skip time-stamp when a deadline is set.
  5236. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5237. (assq (point) deadline-position-alist))
  5238. (throw :skip nil))
  5239. (let* ((category (org-get-category pos))
  5240. (inherited-tags
  5241. (or (eq org-agenda-show-inherited-tags 'always)
  5242. (and (consp org-agenda-show-inherited-tags)
  5243. (memq 'agenda org-agenda-show-inherited-tags))
  5244. (and (eq org-agenda-show-inherited-tags t)
  5245. (or (eq org-agenda-use-tag-inheritance t)
  5246. (memq 'agenda
  5247. org-agenda-use-tag-inheritance)))))
  5248. (tags (org-get-tags-at nil (not inherited-tags)))
  5249. (level (make-string (org-reduced-level (org-outline-level))
  5250. ?\s))
  5251. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5252. (match-string 1)))
  5253. (inactive? (= (char-after pos) ?\[))
  5254. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5255. (item
  5256. (org-agenda-format-item
  5257. (and inactive? org-agenda-inactive-leader)
  5258. head level category tags time-stamp org-ts-regexp habit?)))
  5259. (org-add-props item props
  5260. 'priority (if habit?
  5261. (org-habit-get-priority (org-habit-parse-todo))
  5262. (org-get-priority item))
  5263. 'org-marker (org-agenda-new-marker pos)
  5264. 'org-hd-marker (org-agenda-new-marker)
  5265. 'date date
  5266. 'level level
  5267. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5268. current)
  5269. 'todo-state todo-state
  5270. 'warntime warntime
  5271. 'type "timestamp")
  5272. (push item timestamp-items))))
  5273. (when org-agenda-skip-additional-timestamps-same-entry
  5274. (outline-next-heading))))
  5275. (nreverse timestamp-items)))
  5276. (defun org-agenda-get-sexps ()
  5277. "Return the sexp information for agenda display."
  5278. (require 'diary-lib)
  5279. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5280. 'mouse-face 'highlight
  5281. 'help-echo
  5282. (format "mouse-2 or RET jump to org file %s"
  5283. (abbreviate-file-name buffer-file-name))))
  5284. (regexp "^&?%%(")
  5285. marker category extra level ee txt tags entry
  5286. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5287. (goto-char (point-min))
  5288. (while (re-search-forward regexp nil t)
  5289. (catch :skip
  5290. (org-agenda-skip)
  5291. (setq beg (match-beginning 0))
  5292. (goto-char (1- (match-end 0)))
  5293. (setq b (point))
  5294. (forward-sexp 1)
  5295. (setq sexp (buffer-substring b (point)))
  5296. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5297. (org-trim (match-string 1))
  5298. ""))
  5299. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5300. (when result
  5301. (setq marker (org-agenda-new-marker beg)
  5302. level (make-string (org-reduced-level (org-outline-level)) ? )
  5303. category (org-get-category beg)
  5304. inherited-tags
  5305. (or (eq org-agenda-show-inherited-tags 'always)
  5306. (and (listp org-agenda-show-inherited-tags)
  5307. (memq 'agenda org-agenda-show-inherited-tags))
  5308. (and (eq org-agenda-show-inherited-tags t)
  5309. (or (eq org-agenda-use-tag-inheritance t)
  5310. (memq 'agenda org-agenda-use-tag-inheritance))))
  5311. tags (org-get-tags-at nil (not inherited-tags))
  5312. todo-state (org-get-todo-state)
  5313. warntime (get-text-property (point) 'org-appt-warntime)
  5314. extra nil)
  5315. (dolist (r (if (stringp result)
  5316. (list result)
  5317. result)) ;; we expect a list here
  5318. (when (and org-agenda-diary-sexp-prefix
  5319. (string-match org-agenda-diary-sexp-prefix r))
  5320. (setq extra (match-string 0 r)
  5321. r (replace-match "" nil nil r)))
  5322. (if (string-match "\\S-" r)
  5323. (setq txt r)
  5324. (setq txt "SEXP entry returned empty string"))
  5325. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5326. (org-add-props txt props 'org-marker marker
  5327. 'date date 'todo-state todo-state
  5328. 'level level 'type "sexp" 'warntime warntime)
  5329. (push txt ee)))))
  5330. (nreverse ee)))
  5331. ;; Calendar sanity: define some functions that are independent of
  5332. ;; `calendar-date-style'.
  5333. (defun org-anniversary (year month day &optional mark)
  5334. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5335. (with-no-warnings
  5336. (let ((calendar-date-style 'iso))
  5337. (diary-anniversary year month day mark))))
  5338. (defun org-cyclic (N year month day &optional mark)
  5339. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5340. (with-no-warnings
  5341. (let ((calendar-date-style 'iso))
  5342. (diary-cyclic N year month day mark))))
  5343. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5344. "Like `diary-block', but with fixed (ISO) order of arguments."
  5345. (with-no-warnings
  5346. (let ((calendar-date-style 'iso))
  5347. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5348. (defun org-date (year month day &optional mark)
  5349. "Like `diary-date', but with fixed (ISO) order of arguments."
  5350. (with-no-warnings
  5351. (let ((calendar-date-style 'iso))
  5352. (diary-date year month day mark))))
  5353. ;; Define the `org-class' function
  5354. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5355. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5356. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5357. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5358. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5359. `holidays', then any date that is known by the Emacs calendar to be a
  5360. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5361. then those holidays will be skipped."
  5362. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5363. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5364. (d (calendar-absolute-from-gregorian date))
  5365. (h (when skip-weeks (calendar-check-holidays date))))
  5366. (and
  5367. (<= date1 d)
  5368. (<= d date2)
  5369. (= (calendar-day-of-week date) dayname)
  5370. (or (not skip-weeks)
  5371. (progn
  5372. (require 'cal-iso)
  5373. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5374. (not (or (and h (memq 'holidays skip-weeks))
  5375. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5376. entry)))
  5377. (defalias 'org-get-closed 'org-agenda-get-progress)
  5378. (defun org-agenda-get-progress ()
  5379. "Return the logged TODO entries for agenda display."
  5380. (let* ((props (list 'mouse-face 'highlight
  5381. 'org-not-done-regexp org-not-done-regexp
  5382. 'org-todo-regexp org-todo-regexp
  5383. 'org-complex-heading-regexp org-complex-heading-regexp
  5384. 'help-echo
  5385. (format "mouse-2 or RET jump to org file %s"
  5386. (abbreviate-file-name buffer-file-name))))
  5387. (items (if (consp org-agenda-show-log-scoped)
  5388. org-agenda-show-log-scoped
  5389. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5390. '(clock)
  5391. org-agenda-log-mode-items)))
  5392. (parts
  5393. (delq nil
  5394. (list
  5395. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5396. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5397. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5398. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5399. (error "`org-agenda-log-mode-items' is empty")))
  5400. (regexp (concat
  5401. "\\(" parts-re "\\)"
  5402. " *\\["
  5403. (regexp-quote
  5404. (substring
  5405. (format-time-string
  5406. (car org-time-stamp-formats)
  5407. (apply 'encode-time ; DATE bound by calendar
  5408. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5409. 1 11))))
  5410. (org-agenda-search-headline-for-time nil)
  5411. marker hdmarker priority category level tags closedp
  5412. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5413. (goto-char (point-min))
  5414. (while (re-search-forward regexp nil t)
  5415. (catch :skip
  5416. (org-agenda-skip)
  5417. (setq marker (org-agenda-new-marker (match-beginning 0))
  5418. closedp (equal (match-string 1) org-closed-string)
  5419. statep (equal (string-to-char (match-string 1)) ?-)
  5420. clockp (not (or closedp statep))
  5421. state (and statep (match-string 2))
  5422. category (org-get-category (match-beginning 0))
  5423. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5424. (when (string-match "\\]" timestr)
  5425. ;; substring should only run to end of time stamp
  5426. (setq rest (substring timestr (match-end 0))
  5427. timestr (substring timestr 0 (match-end 0)))
  5428. (if (and (not closedp) (not statep)
  5429. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5430. rest))
  5431. (progn (setq timestr (concat (substring timestr 0 -1)
  5432. "-" (match-string 1 rest) "]"))
  5433. (setq clocked (match-string 2 rest)))
  5434. (setq clocked "-")))
  5435. (save-excursion
  5436. (setq extra
  5437. (cond
  5438. ((not org-agenda-log-mode-add-notes) nil)
  5439. (statep
  5440. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5441. (match-string 1)))
  5442. (clockp
  5443. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5444. (match-string 1)))))
  5445. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5446. (throw :skip nil)
  5447. (goto-char (match-beginning 0))
  5448. (setq hdmarker (org-agenda-new-marker)
  5449. inherited-tags
  5450. (or (eq org-agenda-show-inherited-tags 'always)
  5451. (and (listp org-agenda-show-inherited-tags)
  5452. (memq 'todo org-agenda-show-inherited-tags))
  5453. (and (eq org-agenda-show-inherited-tags t)
  5454. (or (eq org-agenda-use-tag-inheritance t)
  5455. (memq 'todo org-agenda-use-tag-inheritance))))
  5456. tags (org-get-tags-at nil (not inherited-tags))
  5457. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5458. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5459. (setq txt (match-string 1))
  5460. (when extra
  5461. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5462. (setq txt (concat (substring txt 0 (match-beginning 1))
  5463. " - " extra " " (match-string 2 txt)))
  5464. (setq txt (concat txt " - " extra))))
  5465. (setq txt (org-agenda-format-item
  5466. (cond
  5467. (closedp "Closed: ")
  5468. (statep (concat "State: (" state ")"))
  5469. (t (concat "Clocked: (" clocked ")")))
  5470. txt level category tags timestr)))
  5471. (setq priority 100000)
  5472. (org-add-props txt props
  5473. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5474. 'priority priority 'level level
  5475. 'type "closed" 'date date
  5476. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5477. (push txt ee))
  5478. (goto-char (point-at-eol))))
  5479. (nreverse ee)))
  5480. (defun org-agenda-show-clocking-issues ()
  5481. "Add overlays, showing issues with clocking.
  5482. See also the user option `org-agenda-clock-consistency-checks'."
  5483. (interactive)
  5484. (let* ((org-time-clocksum-use-effort-durations nil)
  5485. (pl org-agenda-clock-consistency-checks)
  5486. (re (concat "^[ \t]*"
  5487. org-clock-string
  5488. "[ \t]+"
  5489. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5490. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5491. (tlstart 0.)
  5492. (tlend 0.)
  5493. (maxtime (org-hh:mm-string-to-minutes
  5494. (or (plist-get pl :max-duration) "24:00")))
  5495. (mintime (org-hh:mm-string-to-minutes
  5496. (or (plist-get pl :min-duration) 0)))
  5497. (maxgap (org-hh:mm-string-to-minutes
  5498. ;; default 30:00 means never complain
  5499. (or (plist-get pl :max-gap) "30:00")))
  5500. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5501. (plist-get pl :gap-ok-around)))
  5502. (def-face (or (plist-get pl :default-face)
  5503. '((:background "DarkRed") (:foreground "white"))))
  5504. issue face m te ts dt ov)
  5505. (goto-char (point-min))
  5506. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5507. (setq issue nil face def-face)
  5508. (catch 'next
  5509. (setq m (org-get-at-bol 'org-marker)
  5510. te nil ts nil)
  5511. (unless (and m (markerp m))
  5512. (setq issue "No valid clock line") (throw 'next t))
  5513. (org-with-point-at m
  5514. (save-excursion
  5515. (goto-char (point-at-bol))
  5516. (unless (looking-at re)
  5517. (error "No valid Clock line")
  5518. (throw 'next t))
  5519. (unless (match-end 3)
  5520. (setq issue "No end time"
  5521. face (or (plist-get pl :no-end-time-face) face))
  5522. (throw 'next t))
  5523. (setq ts (match-string 1)
  5524. te (match-string 3)
  5525. ts (float-time
  5526. (apply #'encode-time (org-parse-time-string ts)))
  5527. te (float-time
  5528. (apply #'encode-time (org-parse-time-string te)))
  5529. dt (- te ts))))
  5530. (cond
  5531. ((> dt (* 60 maxtime))
  5532. ;; a very long clocking chunk
  5533. (setq issue (format "Clocking interval is very long: %s"
  5534. (org-minutes-to-clocksum-string
  5535. (floor (/ (float dt) 60.))))
  5536. face (or (plist-get pl :long-face) face)))
  5537. ((< dt (* 60 mintime))
  5538. ;; a very short clocking chunk
  5539. (setq issue (format "Clocking interval is very short: %s"
  5540. (org-minutes-to-clocksum-string
  5541. (floor (/ (float dt) 60.))))
  5542. face (or (plist-get pl :short-face) face)))
  5543. ((and (> tlend 0) (< ts tlend))
  5544. ;; Two clock entries are overlapping
  5545. (setq issue (format "Clocking overlap: %d minutes"
  5546. (/ (- tlend ts) 60))
  5547. face (or (plist-get pl :overlap-face) face)))
  5548. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5549. ;; There is a gap, lets see if we need to report it
  5550. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5551. (setq issue (format "Clocking gap: %d minutes"
  5552. (/ (- ts tlend) 60))
  5553. face (or (plist-get pl :gap-face) face))))
  5554. (t nil)))
  5555. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5556. (when issue
  5557. ;; OK, there was some issue, add an overlay to show the issue
  5558. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5559. (overlay-put ov 'before-string
  5560. (concat
  5561. (org-add-props
  5562. (format "%-43s" (concat " " issue))
  5563. nil
  5564. 'face face)
  5565. "\n"))
  5566. (overlay-put ov 'evaporate t)))))
  5567. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5568. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5569. (catch 'exit
  5570. (unless ok-list
  5571. ;; there are no OK times for gaps...
  5572. (throw 'exit nil))
  5573. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5574. ;; This is more than 24 hours, so it is OK.
  5575. ;; because we have at least one OK time, that must be in the
  5576. ;; 24 hour interval.
  5577. (throw 'exit t))
  5578. ;; We have a shorter gap.
  5579. ;; Now we have to get the minute of the day when these times are
  5580. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5581. (t2dec (decode-time (seconds-to-time t2)))
  5582. ;; compute the minute on the day
  5583. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5584. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5585. (when (< min2 min1)
  5586. ;; if min2 is smaller than min1, this means it is on the next day.
  5587. ;; Wrap it to after midnight.
  5588. (setq min2 (+ min2 1440)))
  5589. ;; Now check if any of the OK times is in the gap
  5590. (mapc (lambda (x)
  5591. ;; Wrap the time to after midnight if necessary
  5592. (if (< x min1) (setq x (+ x 1440)))
  5593. ;; Check if in interval
  5594. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5595. ok-list)
  5596. ;; Nope, this gap is not OK
  5597. nil)))
  5598. (defun org-agenda-get-deadlines (&optional with-hour)
  5599. "Return the deadline information for agenda display.
  5600. When WITH-HOUR is non-nil, only return deadlines with an hour
  5601. specification like [h]h:mm."
  5602. (let* ((props (list 'mouse-face 'highlight
  5603. 'org-not-done-regexp org-not-done-regexp
  5604. 'org-todo-regexp org-todo-regexp
  5605. 'org-complex-heading-regexp org-complex-heading-regexp
  5606. 'help-echo
  5607. (format "mouse-2 or RET jump to org file %s"
  5608. (abbreviate-file-name buffer-file-name))))
  5609. (regexp (if with-hour
  5610. org-deadline-time-hour-regexp
  5611. org-deadline-time-regexp))
  5612. (today (org-today))
  5613. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5614. (current (calendar-absolute-from-gregorian date))
  5615. deadline-items)
  5616. (goto-char (point-min))
  5617. (while (re-search-forward regexp nil t)
  5618. (catch :skip
  5619. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5620. (org-agenda-skip)
  5621. (let* ((s (match-string 1))
  5622. (pos (1- (match-beginning 1)))
  5623. (todo-state (save-match-data (org-get-todo-state)))
  5624. (done? (member todo-state org-done-keywords))
  5625. (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5626. (member todo-state
  5627. org-agenda-repeating-timestamp-show-all)))
  5628. ;; DEADLINE is the bare deadline date, i.e., without
  5629. ;; any repeater, or the last repeat if SHOW-ALL is
  5630. ;; non-nil. REPEAT is closest repeat after CURRENT, if
  5631. ;; all repeated time stamps are to be shown, or after
  5632. ;; TODAY otherwise. REPEAT only applies to future
  5633. ;; dates.
  5634. (deadline (if show-all (org-agenda--timestamp-to-absolute s)
  5635. (org-agenda--timestamp-to-absolute
  5636. s today 'past (current-buffer) pos)))
  5637. (repeat
  5638. (if (< current today) deadline
  5639. (org-agenda--timestamp-to-absolute
  5640. s (if show-all current today) 'future (current-buffer) pos)))
  5641. (diff (- deadline current))
  5642. (suppress-prewarning
  5643. (let ((scheduled
  5644. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5645. (org-entry-get nil "SCHEDULED"))))
  5646. (cond
  5647. ((not scheduled) nil)
  5648. ;; The current item has a scheduled date, so
  5649. ;; evaluate its prewarning lead time.
  5650. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5651. ;; Use global prewarning-restart lead time.
  5652. org-agenda-skip-deadline-prewarning-if-scheduled)
  5653. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5654. 'pre-scheduled)
  5655. ;; Set pre-warning to no earlier than SCHEDULED.
  5656. (min (- deadline
  5657. (org-agenda--timestamp-to-absolute scheduled))
  5658. org-deadline-warning-days))
  5659. ;; Set pre-warning to deadline.
  5660. (t 0))))
  5661. (wdays (if suppress-prewarning
  5662. (let ((org-deadline-warning-days suppress-prewarning))
  5663. (org-get-wdays s))
  5664. (org-get-wdays s))))
  5665. ;; When to show a deadline in the calendar: if the
  5666. ;; expiration is within WDAYS warning time. Past-due
  5667. ;; deadlines are only shown on today agenda.
  5668. (when (cond ((= current deadline) nil)
  5669. ((< deadline today)
  5670. (and (not today?)
  5671. (or (< current today) (/= repeat current))))
  5672. ((> deadline current)
  5673. (or (not today?) (> diff wdays)))
  5674. (t (/= repeat current)))
  5675. (throw :skip nil))
  5676. ;; Possibly skip done tasks.
  5677. (when (and done?
  5678. (or org-agenda-skip-deadline-if-done
  5679. (/= deadline current)))
  5680. (throw :skip nil))
  5681. (save-excursion
  5682. (re-search-backward "^\\*+[ \t]+" nil t)
  5683. (goto-char (match-end 0))
  5684. (let* ((category (org-get-category))
  5685. (level
  5686. (make-string (org-reduced-level (org-outline-level)) ?\s))
  5687. (head (buffer-substring (point) (line-end-position)))
  5688. (inherited-tags
  5689. (or (eq org-agenda-show-inherited-tags 'always)
  5690. (and (listp org-agenda-show-inherited-tags)
  5691. (memq 'agenda org-agenda-show-inherited-tags))
  5692. (and (eq org-agenda-show-inherited-tags t)
  5693. (or (eq org-agenda-use-tag-inheritance t)
  5694. (memq 'agenda
  5695. org-agenda-use-tag-inheritance)))))
  5696. (tags (org-get-tags-at nil (not inherited-tags)))
  5697. (time
  5698. (cond
  5699. ;; No time of day designation if it is only
  5700. ;; a reminder.
  5701. ((and (/= current deadline) (/= current repeat)) nil)
  5702. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5703. (concat (substring s (match-beginning 1)) " "))
  5704. (t 'time)))
  5705. (item
  5706. (org-agenda-format-item
  5707. ;; Insert appropriate suffixes before deadlines.
  5708. (pcase-let ((`(,now ,future ,past)
  5709. org-agenda-deadline-leaders))
  5710. (cond
  5711. ;; Future (i.e., repeated) deadlines are
  5712. ;; displayed as new headlines.
  5713. ((> current today) now)
  5714. ;; When SHOW-ALL is nil, prefer repeated
  5715. ;; deadlines over reminders of past deadlines.
  5716. ((and (not show-all) (= repeat today)) now)
  5717. ((= deadline current) now)
  5718. ((< deadline current) (format past (- diff)))
  5719. (t (format future diff))))
  5720. head level category tags
  5721. (and (or (= repeat current) (= deadline current))
  5722. time)))
  5723. (face (org-agenda-deadline-face
  5724. (- 1 (/ (float (- deadline current)) (max wdays 1)))))
  5725. (upcoming? (and today? (> deadline today)))
  5726. (warntime (get-text-property (point) 'org-appt-warntime)))
  5727. (org-add-props item props
  5728. 'org-marker (org-agenda-new-marker pos)
  5729. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5730. 'warntime warntime
  5731. 'level level
  5732. 'ts-date deadline
  5733. 'priority
  5734. ;; Adjust priority to today reminders about deadlines.
  5735. ;; Overdue deadlines get the highest priority
  5736. ;; increase, then imminent deadlines and eventually
  5737. ;; more distant deadlines.
  5738. (let ((adjust (cond ((not today?) 0)
  5739. ((and (not show-all) (= repeat current)) 0)
  5740. (t (- diff)))))
  5741. (+ adjust (org-get-priority item)))
  5742. 'todo-state todo-state
  5743. 'type (if upcoming? "upcoming-deadline" "deadline")
  5744. 'date (if upcoming? date deadline)
  5745. 'face (if done? 'org-agenda-done face)
  5746. 'undone-face face
  5747. 'done-face 'org-agenda-done)
  5748. (push item deadline-items))))))
  5749. (nreverse deadline-items)))
  5750. (defun org-agenda-deadline-face (fraction)
  5751. "Return the face to displaying a deadline item.
  5752. FRACTION is what fraction of the head-warning time has passed."
  5753. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5754. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5755. "Return the scheduled information for agenda display.
  5756. Optional argument DEADLINES is a list of deadline items to be
  5757. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5758. scheduled items with an hour specification like [h]h:mm."
  5759. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5760. 'org-todo-regexp org-todo-regexp
  5761. 'org-complex-heading-regexp org-complex-heading-regexp
  5762. 'done-face 'org-agenda-done
  5763. 'mouse-face 'highlight
  5764. 'help-echo
  5765. (format "mouse-2 or RET jump to Org file %s"
  5766. (abbreviate-file-name buffer-file-name))))
  5767. (regexp (if with-hour
  5768. org-scheduled-time-hour-regexp
  5769. org-scheduled-time-regexp))
  5770. (today (org-today))
  5771. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5772. (current (calendar-absolute-from-gregorian date))
  5773. (deadline-pos
  5774. (mapcar (lambda (d)
  5775. (let ((m (get-text-property 0 'org-hd-marker d)))
  5776. (and m (marker-position m))))
  5777. deadlines))
  5778. scheduled-items)
  5779. (goto-char (point-min))
  5780. (while (re-search-forward regexp nil t)
  5781. (catch :skip
  5782. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5783. (org-agenda-skip)
  5784. (let* ((s (match-string 1))
  5785. (pos (1- (match-beginning 1)))
  5786. (todo-state (save-match-data (org-get-todo-state)))
  5787. (donep (member todo-state org-done-keywords))
  5788. (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5789. (member todo-state
  5790. org-agenda-repeating-timestamp-show-all)))
  5791. ;; SCHEDULE is the bare scheduled date, i.e., without
  5792. ;; any repeater if non-nil, or last repeat if SHOW-ALL
  5793. ;; is nil. REPEAT is the closest repeat after CURRENT,
  5794. ;; if all repeated time stamps are to be shown, or
  5795. ;; after TODAY otherwise. REPEAT only applies to
  5796. ;; future dates.
  5797. (schedule (if show-all (org-agenda--timestamp-to-absolute s)
  5798. (org-agenda--timestamp-to-absolute
  5799. s today 'past (current-buffer) pos)))
  5800. (repeat (cond ((< current today) schedule)
  5801. (show-all
  5802. (org-agenda--timestamp-to-absolute
  5803. s current 'future (current-buffer) pos))
  5804. (t
  5805. (org-agenda--timestamp-to-absolute
  5806. s today 'future (current-buffer) pos))))
  5807. (diff (- current schedule))
  5808. (warntime (get-text-property (point) 'org-appt-warntime))
  5809. (pastschedp (< schedule today))
  5810. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5811. (suppress-delay
  5812. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5813. (org-entry-get nil "DEADLINE"))))
  5814. (cond
  5815. ((not deadline) nil)
  5816. ;; The current item has a deadline date, so
  5817. ;; evaluate its delay time.
  5818. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5819. ;; Use global delay time.
  5820. (- org-agenda-skip-scheduled-delay-if-deadline))
  5821. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5822. 'post-deadline)
  5823. ;; Set delay to no later than DEADLINE.
  5824. (min (- schedule
  5825. (org-agenda--timestamp-to-absolute deadline))
  5826. org-scheduled-delay-days))
  5827. (t 0))))
  5828. (ddays
  5829. (cond
  5830. ;; Nullify delay when a repeater triggered already
  5831. ;; and the delay is of the form --Xd.
  5832. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5833. (> current schedule))
  5834. 0)
  5835. (suppress-delay
  5836. (let ((org-scheduled-delay-days suppress-delay))
  5837. (org-get-wdays s t t)))
  5838. (t (org-get-wdays s t)))))
  5839. ;; Display scheduled items at base date (SCHEDULE), today if
  5840. ;; scheduled before the current date, and at any repeat past
  5841. ;; today. However, skip delayed items and items that have
  5842. ;; been displayed for more than `org-scheduled-past-days'.
  5843. (unless (and todayp
  5844. habitp
  5845. (bound-and-true-p org-habit-show-all-today))
  5846. (when (or (and (> ddays 0) (< diff ddays))
  5847. (> diff org-scheduled-past-days)
  5848. (> schedule current)
  5849. (and (< schedule current)
  5850. (not todayp)
  5851. (/= repeat current)))
  5852. (throw :skip nil)))
  5853. ;; Possibly skip done tasks.
  5854. (when (and donep
  5855. (or org-agenda-skip-scheduled-if-done
  5856. (/= schedule current)))
  5857. (throw :skip nil))
  5858. ;; Skip entry if it already appears as a deadline, per
  5859. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5860. ;; doesn't apply to habits.
  5861. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5862. ((guard
  5863. (or (not (memq (line-beginning-position 0) deadline-pos))
  5864. habitp))
  5865. nil)
  5866. (`repeated-after-deadline
  5867. (>= repeat (time-to-days (org-get-deadline-time (point)))))
  5868. (`not-today pastschedp)
  5869. (`t t)
  5870. (_ nil))
  5871. (throw :skip nil))
  5872. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5873. ;; only show them for today. Also skip done habits.
  5874. (when (and habitp
  5875. (or donep
  5876. (not (bound-and-true-p org-habit-show-habits))
  5877. (and (not todayp)
  5878. (bound-and-true-p
  5879. org-habit-show-habits-only-for-today))))
  5880. (throw :skip nil))
  5881. (save-excursion
  5882. (re-search-backward "^\\*+[ \t]+" nil t)
  5883. (goto-char (match-end 0))
  5884. (let* ((category (org-get-category))
  5885. (inherited-tags
  5886. (or (eq org-agenda-show-inherited-tags 'always)
  5887. (and (listp org-agenda-show-inherited-tags)
  5888. (memq 'agenda org-agenda-show-inherited-tags))
  5889. (and (eq org-agenda-show-inherited-tags t)
  5890. (or (eq org-agenda-use-tag-inheritance t)
  5891. (memq 'agenda
  5892. org-agenda-use-tag-inheritance)))))
  5893. (tags (org-get-tags-at nil (not inherited-tags)))
  5894. (level
  5895. (make-string (org-reduced-level (org-outline-level)) ?\s))
  5896. (head (buffer-substring (point) (line-end-position)))
  5897. (time
  5898. (cond
  5899. ;; No time of day designation if it is only
  5900. ;; a reminder.
  5901. ((and (/= current schedule) (/= current repeat)) nil)
  5902. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5903. (concat (substring s (match-beginning 1)) " "))
  5904. (t 'time)))
  5905. (item
  5906. (org-agenda-format-item
  5907. (pcase-let ((`(,first ,next) org-agenda-scheduled-leaders))
  5908. (cond
  5909. ;; If CURRENT is in the future, don't use past
  5910. ;; scheduled prefix.
  5911. ((> current today) first)
  5912. ;; SHOW-ALL focuses on future repeats. If one
  5913. ;; such repeat happens today, ignore late
  5914. ;; schedule reminder. However, still report
  5915. ;; such reminders when repeat happens later.
  5916. ((and (not show-all) (= repeat today)) first)
  5917. ;; Initial report.
  5918. ((= schedule current) first)
  5919. ;; Subsequent reminders. Count from base
  5920. ;; schedule.
  5921. (t (format next (1+ diff)))))
  5922. head level category tags time nil habitp))
  5923. (face (cond ((and (not habitp) pastschedp)
  5924. 'org-scheduled-previously)
  5925. (todayp 'org-scheduled-today)
  5926. (t 'org-scheduled)))
  5927. (habitp (and habitp (org-habit-parse-todo))))
  5928. (org-add-props item props
  5929. 'undone-face face
  5930. 'face (if donep 'org-agenda-done face)
  5931. 'org-marker (org-agenda-new-marker pos)
  5932. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5933. 'type (if pastschedp "past-scheduled" "scheduled")
  5934. 'date (if pastschedp schedule date)
  5935. 'ts-date schedule
  5936. 'warntime warntime
  5937. 'level level
  5938. 'priority (if habitp (org-habit-get-priority habitp)
  5939. (+ 99 diff (org-get-priority item)))
  5940. 'org-habit-p habitp
  5941. 'todo-state todo-state)
  5942. (push item scheduled-items))))))
  5943. (nreverse scheduled-items)))
  5944. (defun org-agenda-get-blocks ()
  5945. "Return the date-range information for agenda display."
  5946. (let* ((props (list 'face nil
  5947. 'org-not-done-regexp org-not-done-regexp
  5948. 'org-todo-regexp org-todo-regexp
  5949. 'org-complex-heading-regexp org-complex-heading-regexp
  5950. 'mouse-face 'highlight
  5951. 'help-echo
  5952. (format "mouse-2 or RET jump to org file %s"
  5953. (abbreviate-file-name buffer-file-name))))
  5954. (regexp org-tr-regexp)
  5955. (d0 (calendar-absolute-from-gregorian date))
  5956. marker hdmarker ee txt d1 d2 s1 s2 category
  5957. level todo-state tags pos head donep inherited-tags)
  5958. (goto-char (point-min))
  5959. (while (re-search-forward regexp nil t)
  5960. (catch :skip
  5961. (org-agenda-skip)
  5962. (setq pos (point))
  5963. (let ((start-time (match-string 1))
  5964. (end-time (match-string 2)))
  5965. (setq s1 (match-string 1)
  5966. s2 (match-string 2)
  5967. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5968. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5969. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5970. ;; Only allow days between the limits, because the normal
  5971. ;; date stamps will catch the limits.
  5972. (save-excursion
  5973. (setq todo-state (org-get-todo-state))
  5974. (setq donep (member todo-state org-done-keywords))
  5975. (if (and donep org-agenda-skip-timestamp-if-done)
  5976. (throw :skip t))
  5977. (setq marker (org-agenda-new-marker (point))
  5978. category (org-get-category))
  5979. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5980. (throw :skip nil)
  5981. (goto-char (match-beginning 0))
  5982. (setq hdmarker (org-agenda-new-marker (point))
  5983. inherited-tags
  5984. (or (eq org-agenda-show-inherited-tags 'always)
  5985. (and (listp org-agenda-show-inherited-tags)
  5986. (memq 'agenda org-agenda-show-inherited-tags))
  5987. (and (eq org-agenda-show-inherited-tags t)
  5988. (or (eq org-agenda-use-tag-inheritance t)
  5989. (memq 'agenda org-agenda-use-tag-inheritance))))
  5990. tags (org-get-tags-at nil (not inherited-tags)))
  5991. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5992. (looking-at "\\*+[ \t]+\\(.*\\)")
  5993. (setq head (match-string 1))
  5994. (let ((remove-re
  5995. (if org-agenda-remove-timeranges-from-blocks
  5996. (concat
  5997. "<" (regexp-quote s1) ".*?>"
  5998. "--"
  5999. "<" (regexp-quote s2) ".*?>")
  6000. nil)))
  6001. (setq txt (org-agenda-format-item
  6002. (format
  6003. (nth (if (= d1 d2) 0 1)
  6004. org-agenda-timerange-leaders)
  6005. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6006. head level category tags
  6007. (cond ((and (= d1 d0) (= d2 d0))
  6008. (concat "<" start-time ">--<" end-time ">"))
  6009. ((= d1 d0)
  6010. (concat "<" start-time ">"))
  6011. ((= d2 d0)
  6012. (concat "<" end-time ">")))
  6013. remove-re))))
  6014. (org-add-props txt props
  6015. 'org-marker marker 'org-hd-marker hdmarker
  6016. 'type "block" 'date date
  6017. 'level level
  6018. 'todo-state todo-state
  6019. 'priority (org-get-priority txt))
  6020. (push txt ee))))
  6021. (goto-char pos)))
  6022. ;; Sort the entries by expiration date.
  6023. (nreverse ee)))
  6024. ;;; Agenda presentation and sorting
  6025. (defvar org-prefix-has-time nil
  6026. "A flag, set by `org-compile-prefix-format'.
  6027. The flag is set if the currently compiled format contains a `%t'.")
  6028. (defvar org-prefix-has-tag nil
  6029. "A flag, set by `org-compile-prefix-format'.
  6030. The flag is set if the currently compiled format contains a `%T'.")
  6031. (defvar org-prefix-has-effort nil
  6032. "A flag, set by `org-compile-prefix-format'.
  6033. The flag is set if the currently compiled format contains a `%e'.")
  6034. (defvar org-prefix-has-breadcrumbs nil
  6035. "A flag, set by `org-compile-prefix-format'.
  6036. The flag is set if the currently compiled format contains a `%b'.")
  6037. (defvar org-prefix-category-length nil
  6038. "Used by `org-compile-prefix-format' to remember the category field width.")
  6039. (defvar org-prefix-category-max-length nil
  6040. "Used by `org-compile-prefix-format' to remember the category field width.")
  6041. (defun org-agenda-get-category-icon (category)
  6042. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6043. (cl-dolist (entry org-agenda-category-icon-alist)
  6044. (when (string-match-p (car entry) category)
  6045. (if (listp (cadr entry))
  6046. (cl-return (cadr entry))
  6047. (cl-return (apply #'create-image (cdr entry)))))))
  6048. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  6049. remove-re habitp)
  6050. "Format TXT to be inserted into the agenda buffer.
  6051. In particular, add the prefix and corresponding text properties.
  6052. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6053. LEVEL may be a string to replace the `%l' specifier.
  6054. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6055. category taken from local variable or file name. It will replace the `%c'
  6056. specifier in the format.
  6057. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6058. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6059. When DOTIME is a string, this string is searched for a time before TXT is.
  6060. TAGS can be the tags of the headline.
  6061. Any match of REMOVE-RE will be removed from TXT."
  6062. ;; We keep the org-prefix-* variable values along with a compiled
  6063. ;; formatter, so that multiple agendas existing at the same time do
  6064. ;; not step on each other toes.
  6065. ;;
  6066. ;; It was inconvenient to make these variables buffer local in
  6067. ;; Agenda buffers, because this function expects to be called with
  6068. ;; the buffer where item comes from being current, and not agenda
  6069. ;; buffer
  6070. (let* ((bindings (car org-prefix-format-compiled))
  6071. (formatter (cadr org-prefix-format-compiled)))
  6072. (cl-loop for (var value) in bindings
  6073. do (set var value))
  6074. (save-match-data
  6075. ;; Diary entries sometimes have extra whitespace at the beginning
  6076. (setq txt (org-trim txt))
  6077. ;; Fix the tags part in txt
  6078. (setq txt (org-agenda-fix-displayed-tags
  6079. txt tags
  6080. org-agenda-show-inherited-tags
  6081. org-agenda-hide-tags-regexp))
  6082. (let* ((category (or category
  6083. (if buffer-file-name
  6084. (file-name-sans-extension
  6085. (file-name-nondirectory buffer-file-name))
  6086. "")))
  6087. (category-icon (org-agenda-get-category-icon category))
  6088. (category-icon (if category-icon
  6089. (propertize " " 'display category-icon)
  6090. ""))
  6091. (effort (and (not (string= txt ""))
  6092. (get-text-property 1 'effort txt)))
  6093. ;; time, tag, effort are needed for the eval of the prefix format
  6094. (tag (if tags (nth (1- (length tags)) tags) ""))
  6095. time
  6096. (ts (if dotime (concat
  6097. (if (stringp dotime) dotime "")
  6098. (and org-agenda-search-headline-for-time txt))))
  6099. (time-of-day (and dotime (org-get-time-of-day ts)))
  6100. stamp plain s0 s1 s2 rtn srp l
  6101. duration breadcrumbs)
  6102. (and (derived-mode-p 'org-mode) buffer-file-name
  6103. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6104. (when (and dotime time-of-day)
  6105. ;; Extract starting and ending time and move them to prefix
  6106. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6107. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6108. (setq s0 (match-string 0 ts)
  6109. srp (and stamp (match-end 3))
  6110. s1 (match-string (if plain 1 2) ts)
  6111. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6112. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6113. ;; them, we might want to remove them there to avoid duplication.
  6114. ;; The user can turn this off with a variable.
  6115. (if (and org-prefix-has-time
  6116. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6117. (string-match (concat (regexp-quote s0) " *") txt)
  6118. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6119. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6120. (= (match-beginning 0) 0)
  6121. t))
  6122. (setq txt (replace-match "" nil nil txt))))
  6123. ;; Normalize the time(s) to 24 hour
  6124. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6125. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6126. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6127. (let (org-time-clocksum-use-effort-durations)
  6128. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6129. (setq s2
  6130. (org-minutes-to-clocksum-string
  6131. (+ (org-hh:mm-string-to-minutes s1)
  6132. org-agenda-default-appointment-duration)))))
  6133. ;; Compute the duration
  6134. (when s2
  6135. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6136. (org-hh:mm-string-to-minutes s1)))))
  6137. (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6138. ;; Tags are in the string
  6139. (if (or (eq org-agenda-remove-tags t)
  6140. (and org-agenda-remove-tags
  6141. org-prefix-has-tag))
  6142. (setq txt (replace-match "" t t txt))
  6143. (setq txt (replace-match
  6144. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6145. (match-string 2 txt))
  6146. t t txt))))
  6147. (when remove-re
  6148. (while (string-match remove-re txt)
  6149. (setq txt (replace-match "" t t txt))))
  6150. ;; Set org-heading property on `txt' to mark the start of the
  6151. ;; heading.
  6152. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6153. ;; Prepare the variables needed in the eval of the compiled format
  6154. (if org-prefix-has-breadcrumbs
  6155. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6156. (let ((s (org-display-outline-path nil nil "->" t)))
  6157. (if (eq "" s) "" (concat s "->"))))))
  6158. (setq time (cond (s2 (concat
  6159. (org-agenda-time-of-day-to-ampm-maybe s1)
  6160. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6161. (if org-agenda-timegrid-use-ampm " ")))
  6162. (s1 (concat
  6163. (org-agenda-time-of-day-to-ampm-maybe s1)
  6164. (if org-agenda-timegrid-use-ampm
  6165. "........ "
  6166. "......")))
  6167. (t ""))
  6168. extra (or (and (not habitp) extra) "")
  6169. category (if (symbolp category) (symbol-name category) category)
  6170. level (or level ""))
  6171. (if (string-match org-bracket-link-regexp category)
  6172. (progn
  6173. (setq l (if (match-end 3)
  6174. (- (match-end 3) (match-beginning 3))
  6175. (- (match-end 1) (match-beginning 1))))
  6176. (when (< l (or org-prefix-category-length 0))
  6177. (setq category (copy-sequence category))
  6178. (org-add-props category nil
  6179. 'extra-space (make-string
  6180. (- org-prefix-category-length l 1) ?\ ))))
  6181. (if (and org-prefix-category-max-length
  6182. (>= (length category) org-prefix-category-max-length))
  6183. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6184. ;; Evaluate the compiled format
  6185. (setq rtn (concat (eval formatter) txt))
  6186. ;; And finally add the text properties
  6187. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6188. (org-add-props rtn nil
  6189. 'org-category category
  6190. 'tags (mapcar 'org-downcase-keep-props tags)
  6191. 'org-highest-priority org-highest-priority
  6192. 'org-lowest-priority org-lowest-priority
  6193. 'time-of-day time-of-day
  6194. 'duration duration
  6195. 'breadcrumbs breadcrumbs
  6196. 'txt txt
  6197. 'level level
  6198. 'time time
  6199. 'extra extra
  6200. 'format org-prefix-format-compiled
  6201. 'dotime dotime)))))
  6202. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6203. "Remove tags string from TXT, and add a modified list of tags.
  6204. The modified list may contain inherited tags, and tags matched by
  6205. `org-agenda-hide-tags-regexp' will be removed."
  6206. (when (or add-inherited hide-re)
  6207. (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6208. (setq txt (substring txt 0 (match-beginning 0))))
  6209. (setq tags
  6210. (delq nil
  6211. (mapcar (lambda (tg)
  6212. (if (or (and hide-re (string-match hide-re tg))
  6213. (and (not add-inherited)
  6214. (get-text-property 0 'inherited tg)))
  6215. nil
  6216. tg))
  6217. tags)))
  6218. (when tags
  6219. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6220. i)
  6221. (setq txt (concat txt " :"
  6222. (mapconcat
  6223. (lambda (x)
  6224. (setq i (get-text-property 0 'inherited x))
  6225. (if (and have-i (not i))
  6226. (progn
  6227. (setq have-i nil)
  6228. (concat ":" x))
  6229. x))
  6230. tags ":")
  6231. (if have-i "::" ":"))))))
  6232. txt)
  6233. (defun org-downcase-keep-props (s)
  6234. (let ((props (text-properties-at 0 s)))
  6235. (setq s (downcase s))
  6236. (add-text-properties 0 (length s) props s)
  6237. s))
  6238. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6239. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6240. "Add a time-grid for agenda items which need it.
  6241. LIST is the list of agenda items formatted by `org-agenda-list'.
  6242. NDAYS is the span of the current agenda view.
  6243. TODAYP is t when the current agenda view is on today."
  6244. (catch 'exit
  6245. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6246. ((and todayp (member 'today (car org-agenda-time-grid))))
  6247. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6248. ((member 'weekly (car org-agenda-time-grid)))
  6249. (t (throw 'exit list)))
  6250. (let* ((have (delq nil (mapcar
  6251. (lambda (x) (get-text-property 1 'time-of-day x))
  6252. list)))
  6253. (string (nth 1 org-agenda-time-grid))
  6254. (gridtimes (nth 2 org-agenda-time-grid))
  6255. (req (car org-agenda-time-grid))
  6256. (remove (member 'remove-match req))
  6257. new time)
  6258. (if (and (member 'require-timed req) (not have))
  6259. ;; don't show empty grid
  6260. (throw 'exit list))
  6261. (while (setq time (pop gridtimes))
  6262. (unless (and remove (member time have))
  6263. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6264. (push (org-agenda-format-item
  6265. nil string nil "" nil
  6266. (concat (substring time 0 -2) ":" (substring time -2)))
  6267. new)
  6268. (put-text-property
  6269. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6270. (when (and todayp org-agenda-show-current-time-in-grid)
  6271. (push (org-agenda-format-item
  6272. nil org-agenda-current-time-string nil "" nil
  6273. (format-time-string "%H:%M "))
  6274. new)
  6275. (put-text-property
  6276. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6277. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6278. (append new list)
  6279. (append list new)))))
  6280. (defun org-compile-prefix-format (key)
  6281. "Compile the prefix format into a Lisp form that can be evaluated.
  6282. The resulting form and associated variable bindings is returned
  6283. and stored in the variable `org-prefix-format-compiled'."
  6284. (setq org-prefix-has-time nil
  6285. org-prefix-has-tag nil
  6286. org-prefix-category-length nil
  6287. org-prefix-has-effort nil
  6288. org-prefix-has-breadcrumbs nil)
  6289. (let ((s (cond
  6290. ((stringp org-agenda-prefix-format)
  6291. org-agenda-prefix-format)
  6292. ((assq key org-agenda-prefix-format)
  6293. (cdr (assq key org-agenda-prefix-format)))
  6294. (t " %-12:c%?-12t% s")))
  6295. (start 0)
  6296. varform vars var e c f opt)
  6297. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6298. s start)
  6299. (setq var (or (cdr (assoc (match-string 4 s)
  6300. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6301. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6302. 'eval)
  6303. c (or (match-string 3 s) "")
  6304. opt (match-beginning 1)
  6305. start (1+ (match-beginning 0)))
  6306. (if (eq var 'time) (setq org-prefix-has-time t))
  6307. (if (eq var 'tag) (setq org-prefix-has-tag t))
  6308. (if (eq var 'effort) (setq org-prefix-has-effort t))
  6309. (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6310. (setq f (concat "%" (match-string 2 s) "s"))
  6311. (when (eq var 'category)
  6312. (setq org-prefix-category-length
  6313. (floor (abs (string-to-number (match-string 2 s)))))
  6314. (setq org-prefix-category-max-length
  6315. (let ((x (match-string 2 s)))
  6316. (save-match-data
  6317. (if (string-match "\\.[0-9]+" x)
  6318. (string-to-number (substring (match-string 0 x) 1)))))))
  6319. (if (eq var 'eval)
  6320. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6321. (if opt
  6322. (setq varform
  6323. `(if (or (equal "" ,var) (equal nil ,var))
  6324. ""
  6325. (format ,f (concat ,var ,c))))
  6326. (setq varform
  6327. `(format ,f (if (or (equal ,var "")
  6328. (equal ,var nil)) ""
  6329. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6330. (setq s (replace-match "%s" t nil s))
  6331. (push varform vars))
  6332. (setq vars (nreverse vars))
  6333. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6334. (setq org-prefix-format-compiled
  6335. (list
  6336. `((org-prefix-has-time ,org-prefix-has-time)
  6337. (org-prefix-has-tag ,org-prefix-has-tag)
  6338. (org-prefix-category-length ,org-prefix-category-length)
  6339. (org-prefix-has-effort ,org-prefix-has-effort)
  6340. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6341. `(format ,s ,@vars))))))
  6342. (defun org-set-sorting-strategy (key)
  6343. (if (symbolp (car org-agenda-sorting-strategy))
  6344. ;; the old format
  6345. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6346. (setq org-agenda-sorting-strategy-selected
  6347. (or (cdr (assq key org-agenda-sorting-strategy))
  6348. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6349. '(time-up category-keep priority-down)))))
  6350. (defun org-get-time-of-day (s &optional string mod24)
  6351. "Check string S for a time of day.
  6352. If found, return it as a military time number between 0 and 2400.
  6353. If not found, return nil.
  6354. The optional STRING argument forces conversion into a 5 character wide string
  6355. HH:MM."
  6356. (save-match-data
  6357. (when
  6358. (and
  6359. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6360. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6361. (not (eq (get-text-property 1 'face s) 'org-link)))
  6362. (let* ((h (string-to-number (match-string 1 s)))
  6363. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6364. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6365. (am-p (equal ampm "am"))
  6366. (h1 (cond ((not ampm) h)
  6367. ((= h 12) (if am-p 0 12))
  6368. (t (+ h (if am-p 0 12)))))
  6369. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6370. (mod h1 24) h1))
  6371. (t0 (+ (* 100 h2) m))
  6372. (t1 (concat (if (>= h1 24) "+" " ")
  6373. (if (and org-agenda-time-leading-zero
  6374. (< t0 1000)) "0" "")
  6375. (if (< t0 100) "0" "")
  6376. (if (< t0 10) "0" "")
  6377. (int-to-string t0))))
  6378. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6379. (defvar org-agenda-before-sorting-filter-function nil
  6380. "Function to be applied to agenda items prior to sorting.
  6381. Prior to sorting also means just before they are inserted into the agenda.
  6382. To aid sorting, you may revisit the original entries and add more text
  6383. properties which will later be used by the sorting functions.
  6384. The function should take a string argument, an agenda line.
  6385. It has access to the text properties in that line, which contain among
  6386. other things, the property `org-hd-marker' that points to the entry
  6387. where the line comes from. Note that not all lines going into the agenda
  6388. have this property, only most.
  6389. The function should return the modified string. It is probably best
  6390. to ONLY change text properties.
  6391. You can also use this function as a filter, by returning nil for lines
  6392. you don't want to have in the agenda at all. For this application, you
  6393. could bind the variable in the options section of a custom command.")
  6394. (defun org-agenda-finalize-entries (list &optional type)
  6395. "Sort, limit and concatenate the LIST of agenda items.
  6396. The optional argument TYPE tells the agenda type."
  6397. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6398. (cdr (assoc type org-agenda-max-effort)))
  6399. (t org-agenda-max-effort)))
  6400. (max-todo (cond ((listp org-agenda-max-todos)
  6401. (cdr (assoc type org-agenda-max-todos)))
  6402. (t org-agenda-max-todos)))
  6403. (max-tags (cond ((listp org-agenda-max-tags)
  6404. (cdr (assoc type org-agenda-max-tags)))
  6405. (t org-agenda-max-tags)))
  6406. (max-entries (cond ((listp org-agenda-max-entries)
  6407. (cdr (assoc type org-agenda-max-entries)))
  6408. (t org-agenda-max-entries))))
  6409. (when org-agenda-before-sorting-filter-function
  6410. (setq list
  6411. (delq nil
  6412. (mapcar
  6413. org-agenda-before-sorting-filter-function list))))
  6414. (setq list (mapcar 'org-agenda-highlight-todo list)
  6415. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6416. (when max-effort
  6417. (setq list (org-agenda-limit-entries
  6418. list 'effort-minutes max-effort
  6419. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6420. 32767 -1))))))
  6421. (when max-todo
  6422. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6423. (when max-tags
  6424. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6425. (when max-entries
  6426. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6427. (mapconcat 'identity list "\n")))
  6428. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6429. "Limit the number of agenda entries."
  6430. (let ((include (and limit (< limit 0))))
  6431. (if limit
  6432. (let ((fun (or fn (lambda (p) (if p 1))))
  6433. (lim 0))
  6434. (delq nil
  6435. (mapcar
  6436. (lambda (e)
  6437. (let ((pval (funcall
  6438. fun (get-text-property (1- (length e))
  6439. prop e))))
  6440. (if pval (setq lim (+ lim pval)))
  6441. (cond ((and pval (<= lim (abs limit))) e)
  6442. ((and include (not pval)) e))))
  6443. list)))
  6444. list)))
  6445. (defun org-agenda-limit-interactively (remove)
  6446. "In agenda, interactively limit entries to various maximums."
  6447. (interactive "P")
  6448. (if remove
  6449. (progn (setq org-agenda-max-entries nil
  6450. org-agenda-max-todos nil
  6451. org-agenda-max-tags nil
  6452. org-agenda-max-effort nil)
  6453. (org-agenda-redo))
  6454. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6455. (msg (cond ((= max ?E) "How many minutes? ")
  6456. ((= max ?e) "How many entries? ")
  6457. ((= max ?t) "How many TODO entries? ")
  6458. ((= max ?T) "How many tagged entries? ")
  6459. (t (user-error "Wrong input"))))
  6460. (num (string-to-number (read-from-minibuffer msg))))
  6461. (cond ((equal max ?e)
  6462. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6463. ((equal max ?t)
  6464. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6465. ((equal max ?T)
  6466. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6467. ((equal max ?E)
  6468. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6469. (org-agenda-fit-window-to-buffer))
  6470. (defun org-agenda-highlight-todo (x)
  6471. (let ((org-done-keywords org-done-keywords-for-agenda)
  6472. (case-fold-search nil)
  6473. re)
  6474. (if (eq x 'line)
  6475. (save-excursion
  6476. (beginning-of-line 1)
  6477. (setq re (org-get-at-bol 'org-todo-regexp))
  6478. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6479. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6480. (add-text-properties (match-beginning 0) (match-end 1)
  6481. (list 'face (org-get-todo-face 1)))
  6482. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6483. (delete-region (match-beginning 1) (1- (match-end 0)))
  6484. (goto-char (match-beginning 1))
  6485. (insert (format org-agenda-todo-keyword-format s)))))
  6486. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6487. (setq re (get-text-property 0 'org-todo-regexp x))
  6488. (when (and re
  6489. ;; Test `pl' because if there's no heading content,
  6490. ;; there's no point matching to highlight. Note
  6491. ;; that if we didn't test `pl' first, and there
  6492. ;; happened to be no keyword from `org-todo-regexp'
  6493. ;; on this heading line, then the `equal' comparison
  6494. ;; afterwards would spuriously succeed in the case
  6495. ;; where `pl' is nil -- causing an args-out-of-range
  6496. ;; error when we try to add text properties to text
  6497. ;; that isn't there.
  6498. pl
  6499. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6500. x pl) pl))
  6501. (add-text-properties
  6502. (or (match-end 1) (match-end 0)) (match-end 0)
  6503. (list 'face (org-get-todo-face (match-string 2 x)))
  6504. x)
  6505. (when (match-end 1)
  6506. (setq x (concat (substring x 0 (match-end 1))
  6507. (format org-agenda-todo-keyword-format
  6508. (match-string 2 x))
  6509. (org-add-props " " (text-properties-at 0 x))
  6510. (substring x (match-end 3)))))))
  6511. x)))
  6512. (defsubst org-cmp-values (a b property)
  6513. "Compare the numeric value of text PROPERTY for string A and B."
  6514. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6515. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6516. (cond ((> pa pb) +1)
  6517. ((< pa pb) -1))))
  6518. (defsubst org-cmp-effort (a b)
  6519. "Compare the effort values of string A and B."
  6520. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6521. ;; `effort-minutes' property is not directly accessible from
  6522. ;; the strings, but is stored as a property in `txt'.
  6523. (ea (or (get-text-property
  6524. 0 'effort-minutes (get-text-property 0 'txt a))
  6525. def))
  6526. (eb (or (get-text-property
  6527. 0 'effort-minutes (get-text-property 0 'txt b))
  6528. def)))
  6529. (cond ((> ea eb) +1)
  6530. ((< ea eb) -1))))
  6531. (defsubst org-cmp-category (a b)
  6532. "Compare the string values of categories of strings A and B."
  6533. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6534. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6535. (cond ((string-lessp ca cb) -1)
  6536. ((string-lessp cb ca) +1))))
  6537. (defsubst org-cmp-todo-state (a b)
  6538. "Compare the todo states of strings A and B."
  6539. (let* ((ma (or (get-text-property 1 'org-marker a)
  6540. (get-text-property 1 'org-hd-marker a)))
  6541. (mb (or (get-text-property 1 'org-marker b)
  6542. (get-text-property 1 'org-hd-marker b)))
  6543. (fa (and ma (marker-buffer ma)))
  6544. (fb (and mb (marker-buffer mb)))
  6545. (todo-kwds
  6546. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6547. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6548. (ta (or (get-text-property 1 'todo-state a) ""))
  6549. (tb (or (get-text-property 1 'todo-state b) ""))
  6550. (la (- (length (member ta todo-kwds))))
  6551. (lb (- (length (member tb todo-kwds))))
  6552. (donepa (member ta org-done-keywords-for-agenda))
  6553. (donepb (member tb org-done-keywords-for-agenda)))
  6554. (cond ((and donepa (not donepb)) -1)
  6555. ((and (not donepa) donepb) +1)
  6556. ((< la lb) -1)
  6557. ((< lb la) +1))))
  6558. (defsubst org-cmp-alpha (a b)
  6559. "Compare the headlines, alphabetically."
  6560. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6561. (plb (text-property-any 0 (length b) 'org-heading t b))
  6562. (ta (and pla (substring a pla)))
  6563. (tb (and plb (substring b plb)))
  6564. (case-fold-search nil))
  6565. (when pla
  6566. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6567. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6568. (setq ta (substring ta (match-end 0))))
  6569. (setq ta (downcase ta)))
  6570. (when plb
  6571. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6572. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6573. (setq tb (substring tb (match-end 0))))
  6574. (setq tb (downcase tb)))
  6575. (cond ((not ta) +1)
  6576. ((not tb) -1)
  6577. ((string-lessp ta tb) -1)
  6578. ((string-lessp tb ta) +1))))
  6579. (defsubst org-cmp-tag (a b)
  6580. "Compare the string values of the first tags of A and B."
  6581. (let ((ta (car (last (get-text-property 1 'tags a))))
  6582. (tb (car (last (get-text-property 1 'tags b)))))
  6583. (cond ((not ta) +1)
  6584. ((not tb) -1)
  6585. ((string-lessp ta tb) -1)
  6586. ((string-lessp tb ta) +1))))
  6587. (defsubst org-cmp-time (a b)
  6588. "Compare the time-of-day values of strings A and B."
  6589. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6590. (ta (or (get-text-property 1 'time-of-day a) def))
  6591. (tb (or (get-text-property 1 'time-of-day b) def)))
  6592. (cond ((< ta tb) -1)
  6593. ((< tb ta) +1))))
  6594. (defsubst org-cmp-ts (a b type)
  6595. "Compare the timestamps values of entries A and B.
  6596. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6597. \"timestamp_ia\", compare within each of these type. When TYPE
  6598. is the empty string, compare all timestamps without respect of
  6599. their type."
  6600. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6601. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6602. (get-text-property 1 'ts-date a))
  6603. def))
  6604. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6605. (get-text-property 1 'ts-date b))
  6606. def)))
  6607. (cond ((< ta tb) -1)
  6608. ((< tb ta) +1))))
  6609. (defsubst org-cmp-habit-p (a b)
  6610. "Compare the todo states of strings A and B."
  6611. (let ((ha (get-text-property 1 'org-habit-p a))
  6612. (hb (get-text-property 1 'org-habit-p b)))
  6613. (cond ((and ha (not hb)) -1)
  6614. ((and (not ha) hb) +1))))
  6615. (defun org-entries-lessp (a b)
  6616. "Predicate for sorting agenda entries."
  6617. ;; The following variables will be used when the form is evaluated.
  6618. ;; So even though the compiler complains, keep them.
  6619. (let* ((ss org-agenda-sorting-strategy-selected)
  6620. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6621. (org-cmp-ts a b "")))
  6622. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6623. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6624. (org-cmp-ts a b "scheduled")))
  6625. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6626. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6627. (org-cmp-ts a b "deadline")))
  6628. (deadline-down (if deadline-up (- deadline-up) nil))
  6629. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6630. (org-cmp-ts a b "timestamp_ia")))
  6631. (tsia-down (if tsia-up (- tsia-up) nil))
  6632. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6633. (org-cmp-ts a b "timestamp")))
  6634. (ts-down (if ts-up (- ts-up) nil))
  6635. (time-up (and (org-em 'time-up 'time-down ss)
  6636. (org-cmp-time a b)))
  6637. (time-down (if time-up (- time-up) nil))
  6638. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6639. (org-cmp-values a b 'org-stats)))
  6640. (stats-down (if stats-up (- stats-up) nil))
  6641. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6642. (org-cmp-values a b 'priority)))
  6643. (priority-down (if priority-up (- priority-up) nil))
  6644. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6645. (org-cmp-effort a b)))
  6646. (effort-down (if effort-up (- effort-up) nil))
  6647. (category-up (and (or (org-em 'category-up 'category-down ss)
  6648. (memq 'category-keep ss))
  6649. (org-cmp-category a b)))
  6650. (category-down (if category-up (- category-up) nil))
  6651. (category-keep (if category-up +1 nil))
  6652. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6653. (org-cmp-tag a b)))
  6654. (tag-down (if tag-up (- tag-up) nil))
  6655. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6656. (org-cmp-todo-state a b)))
  6657. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6658. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6659. (org-cmp-habit-p a b)))
  6660. (habit-down (if habit-up (- habit-up) nil))
  6661. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6662. (org-cmp-alpha a b)))
  6663. (alpha-down (if alpha-up (- alpha-up) nil))
  6664. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6665. user-defined-up user-defined-down)
  6666. (if (and need-user-cmp org-agenda-cmp-user-defined
  6667. (functionp org-agenda-cmp-user-defined))
  6668. (setq user-defined-up
  6669. (funcall org-agenda-cmp-user-defined a b)
  6670. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6671. (cdr (assoc
  6672. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6673. '((-1 . t) (1 . nil) (nil . nil))))))
  6674. ;;; Agenda restriction lock
  6675. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6676. "Overlay to mark the headline to which agenda commands are restricted.")
  6677. (overlay-put org-agenda-restriction-lock-overlay
  6678. 'face 'org-agenda-restriction-lock)
  6679. (overlay-put org-agenda-restriction-lock-overlay
  6680. 'help-echo "Agendas are currently limited to this subtree.")
  6681. (delete-overlay org-agenda-restriction-lock-overlay)
  6682. ;;;###autoload
  6683. (defun org-agenda-set-restriction-lock (&optional type)
  6684. "Set restriction lock for agenda, to current subtree or file.
  6685. Restriction will be the file if TYPE is `file', or if type is the
  6686. universal prefix \\='(4), or if the cursor is before the first headline
  6687. in the file. Otherwise, restriction will be to the current subtree."
  6688. (interactive "P")
  6689. (org-agenda-remove-restriction-lock 'noupdate)
  6690. (and (equal type '(4)) (setq type 'file))
  6691. (setq type (cond
  6692. (type type)
  6693. ((org-at-heading-p) 'subtree)
  6694. ((condition-case nil (org-back-to-heading t) (error nil))
  6695. 'subtree)
  6696. (t 'file)))
  6697. (if (eq type 'subtree)
  6698. (progn
  6699. (setq org-agenda-restrict (current-buffer))
  6700. (setq org-agenda-overriding-restriction 'subtree)
  6701. (put 'org-agenda-files 'org-restrict
  6702. (list (buffer-file-name (buffer-base-buffer))))
  6703. (org-back-to-heading t)
  6704. (move-overlay org-agenda-restriction-lock-overlay
  6705. (point)
  6706. (if org-agenda-restriction-lock-highlight-subtree
  6707. (save-excursion (org-end-of-subtree t t) (point))
  6708. (point-at-eol)))
  6709. (move-marker org-agenda-restrict-begin (point))
  6710. (move-marker org-agenda-restrict-end
  6711. (save-excursion (org-end-of-subtree t t)))
  6712. (message "Locking agenda restriction to subtree"))
  6713. (put 'org-agenda-files 'org-restrict
  6714. (list (buffer-file-name (buffer-base-buffer))))
  6715. (setq org-agenda-restrict nil)
  6716. (setq org-agenda-overriding-restriction 'file)
  6717. (move-marker org-agenda-restrict-begin nil)
  6718. (move-marker org-agenda-restrict-end nil)
  6719. (message "Locking agenda restriction to file"))
  6720. (setq current-prefix-arg nil)
  6721. (org-agenda-maybe-redo))
  6722. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6723. "Remove the agenda restriction lock."
  6724. (interactive "P")
  6725. (delete-overlay org-agenda-restriction-lock-overlay)
  6726. (delete-overlay org-speedbar-restriction-lock-overlay)
  6727. (setq org-agenda-overriding-restriction nil)
  6728. (setq org-agenda-restrict nil)
  6729. (put 'org-agenda-files 'org-restrict nil)
  6730. (move-marker org-agenda-restrict-begin nil)
  6731. (move-marker org-agenda-restrict-end nil)
  6732. (setq current-prefix-arg nil)
  6733. (message "Agenda restriction lock removed")
  6734. (or noupdate (org-agenda-maybe-redo)))
  6735. (defun org-agenda-maybe-redo ()
  6736. "If there is any window showing the agenda view, update it."
  6737. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6738. org-agenda-buffer-name)
  6739. t))
  6740. (w0 (selected-window)))
  6741. (when w
  6742. (select-window w)
  6743. (org-agenda-redo)
  6744. (select-window w0)
  6745. (if org-agenda-overriding-restriction
  6746. (message "Agenda view shifted to new %s restriction"
  6747. org-agenda-overriding-restriction)
  6748. (message "Agenda restriction lock removed")))))
  6749. ;;; Agenda commands
  6750. (defun org-agenda-check-type (error &rest types)
  6751. "Check if agenda buffer is of allowed type.
  6752. If ERROR is non-nil, throw an error, otherwise just return nil.
  6753. Allowed types are `agenda' `timeline' `todo' `tags' `search'."
  6754. (if (not org-agenda-type)
  6755. (error "No Org agenda currently displayed")
  6756. (if (memq org-agenda-type types)
  6757. t
  6758. (if error
  6759. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6760. nil))))
  6761. (defun org-agenda-Quit ()
  6762. "Exit the agenda, killing the agenda buffer.
  6763. Like `org-agenda-quit', but kill the buffer even when
  6764. `org-agenda-sticky' is non-nil."
  6765. (interactive)
  6766. (org-agenda--quit))
  6767. (defun org-agenda-quit ()
  6768. "Exit the agenda.
  6769. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6770. instead of killing it.
  6771. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6772. the pre-agenda window configuration.
  6773. When column view is active, exit column view instead of the
  6774. agenda."
  6775. (interactive)
  6776. (org-agenda--quit org-agenda-sticky))
  6777. (defun org-agenda--quit (&optional bury)
  6778. (if org-agenda-columns-active
  6779. (org-columns-quit)
  6780. (let ((wconf org-agenda-pre-window-conf)
  6781. (buf (current-buffer))
  6782. (org-agenda-last-indirect-window
  6783. (and (eq org-indirect-buffer-display 'other-window)
  6784. org-agenda-last-indirect-buffer
  6785. (get-buffer-window org-agenda-last-indirect-buffer))))
  6786. (cond
  6787. ((eq org-agenda-window-setup 'other-frame)
  6788. (delete-frame))
  6789. ((and org-agenda-restore-windows-after-quit
  6790. wconf)
  6791. ;; Maybe restore the pre-agenda window configuration. Reset
  6792. ;; `org-agenda-pre-window-conf' before running
  6793. ;; `set-window-configuration', which loses the current buffer.
  6794. (setq org-agenda-pre-window-conf nil)
  6795. (set-window-configuration wconf))
  6796. (t
  6797. (when org-agenda-last-indirect-window
  6798. (delete-window org-agenda-last-indirect-window))
  6799. (and (not (eq org-agenda-window-setup 'current-window))
  6800. (not (one-window-p))
  6801. (delete-window))))
  6802. (if bury
  6803. ;; Set the agenda buffer as the current buffer instead of
  6804. ;; passing it as an argument to `bury-buffer' so that
  6805. ;; `bury-buffer' removes it from the window.
  6806. (with-current-buffer buf
  6807. (bury-buffer))
  6808. (kill-buffer buf)
  6809. (setq org-agenda-archives-mode nil
  6810. org-agenda-buffer nil)))))
  6811. (defun org-agenda-exit ()
  6812. "Exit the agenda, killing Org buffers loaded by the agenda.
  6813. Like `org-agenda-Quit', but kill any buffers that were created by
  6814. the agenda. Org buffers visited directly by the user will not be
  6815. touched. Also, exit the agenda even if it is in column view."
  6816. (interactive)
  6817. (when org-agenda-columns-active
  6818. (org-columns-quit))
  6819. (org-release-buffers org-agenda-new-buffers)
  6820. (setq org-agenda-new-buffers nil)
  6821. (org-agenda-Quit))
  6822. (defun org-agenda-kill-all-agenda-buffers ()
  6823. "Kill all buffers in `org-agenda-mode'.
  6824. This is used when toggling sticky agendas."
  6825. (interactive)
  6826. (let (blist)
  6827. (dolist (buf (buffer-list))
  6828. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6829. (push buf blist)))
  6830. (mapc 'kill-buffer blist)))
  6831. (defun org-agenda-execute (arg)
  6832. "Execute another agenda command, keeping same window.
  6833. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6834. in the agenda."
  6835. (interactive "P")
  6836. (let ((org-agenda-window-setup 'current-window))
  6837. (org-agenda arg)))
  6838. (defun org-agenda-redo (&optional all)
  6839. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6840. (interactive "P")
  6841. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6842. (cpa (unless (eq all t) current-prefix-arg))
  6843. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6844. (org-agenda-sticky nil)
  6845. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6846. org-agenda-buffer-name))
  6847. (org-agenda-keep-modes t)
  6848. (tag-filter org-agenda-tag-filter)
  6849. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6850. (top-hl-filter org-agenda-top-headline-filter)
  6851. (cat-filter org-agenda-category-filter)
  6852. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6853. (re-filter org-agenda-regexp-filter)
  6854. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6855. (effort-filter org-agenda-effort-filter)
  6856. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6857. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6858. (cols org-agenda-columns-active)
  6859. (line (org-current-line))
  6860. (window-line (- line (org-current-line (window-start))))
  6861. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6862. (redo-cmd (get-text-property p 'org-redo-cmd))
  6863. (last-args (get-text-property p 'org-last-args))
  6864. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6865. (org-agenda-overriding-cmd-arguments
  6866. (unless (eq all t)
  6867. (cond ((listp last-args)
  6868. (cons (or cpa (car last-args)) (cdr last-args)))
  6869. ((stringp last-args)
  6870. last-args))))
  6871. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6872. (put 'org-agenda-tag-filter :preset-filter nil)
  6873. (put 'org-agenda-category-filter :preset-filter nil)
  6874. (put 'org-agenda-regexp-filter :preset-filter nil)
  6875. (put 'org-agenda-effort-filter :preset-filter nil)
  6876. (and cols (org-columns-quit))
  6877. (message "Rebuilding agenda buffer...")
  6878. (if series-redo-cmd
  6879. (eval series-redo-cmd)
  6880. (org-let lprops redo-cmd))
  6881. (setq org-agenda-undo-list nil
  6882. org-agenda-pending-undo-list nil
  6883. org-agenda-tag-filter tag-filter
  6884. org-agenda-category-filter cat-filter
  6885. org-agenda-regexp-filter re-filter
  6886. org-agenda-effort-filter effort-filter
  6887. org-agenda-top-headline-filter top-hl-filter)
  6888. (message "Rebuilding agenda buffer...done")
  6889. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6890. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6891. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6892. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6893. (let ((tag (or tag-filter tag-preset))
  6894. (cat (or cat-filter cat-preset))
  6895. (effort (or effort-filter effort-preset))
  6896. (re (or re-filter re-preset)))
  6897. (when tag (org-agenda-filter-apply tag 'tag t))
  6898. (when cat (org-agenda-filter-apply cat 'category))
  6899. (when effort (org-agenda-filter-apply effort 'effort))
  6900. (when re (org-agenda-filter-apply re 'regexp)))
  6901. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6902. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6903. (org-goto-line line)
  6904. (recenter window-line)))
  6905. (defvar org-global-tags-completion-table nil)
  6906. (defvar org-agenda-filter-form nil)
  6907. (defvar org-agenda-filtered-by-category nil)
  6908. (defun org-agenda-filter-by-category (strip)
  6909. "Filter lines in the agenda buffer that have a specific category.
  6910. The category is that of the current line.
  6911. Without prefix argument, keep only the lines of that category.
  6912. With a prefix argument, exclude the lines of that category.
  6913. "
  6914. (interactive "P")
  6915. (if (and org-agenda-filtered-by-category
  6916. org-agenda-category-filter)
  6917. (org-agenda-filter-show-all-cat)
  6918. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6919. (cond
  6920. ((and cat strip)
  6921. (org-agenda-filter-apply
  6922. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6923. (cat
  6924. (org-agenda-filter-apply
  6925. (setq org-agenda-category-filter
  6926. (list (concat "+" cat))) 'category))
  6927. (t (error "No category at point"))))))
  6928. (defun org-find-top-headline (&optional pos)
  6929. "Find the topmost parent headline and return it."
  6930. (save-excursion
  6931. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6932. (if pos (goto-char pos))
  6933. ;; Skip up to the topmost parent
  6934. (while (ignore-errors (outline-up-heading 1) t))
  6935. (ignore-errors
  6936. (nth 4 (org-heading-components))))))
  6937. (defvar org-agenda-filtered-by-top-headline nil)
  6938. (defun org-agenda-filter-by-top-headline (strip)
  6939. "Keep only those lines that are descendants from the same top headline.
  6940. The top headline is that of the current line."
  6941. (interactive "P")
  6942. (if org-agenda-filtered-by-top-headline
  6943. (progn
  6944. (setq org-agenda-filtered-by-top-headline nil
  6945. org-agenda-top-headline-filter nil)
  6946. (org-agenda-filter-show-all-top-filter))
  6947. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6948. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6949. (error "No top-level headline at point")))))
  6950. (defvar org-agenda-regexp-filter nil)
  6951. (defun org-agenda-filter-by-regexp (strip)
  6952. "Filter agenda entries by a regular expression.
  6953. Regexp filters are cumulative.
  6954. With no prefix argument, keep entries matching the regexp.
  6955. With one prefix argument, filter out entries matching the regexp.
  6956. With two prefix arguments, remove the regexp filters."
  6957. (interactive "P")
  6958. (if (not (equal strip '(16)))
  6959. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6960. (read-from-minibuffer
  6961. (if (equal strip '(4))
  6962. "Filter out entries matching regexp: "
  6963. "Narrow to entries matching regexp: ")))))
  6964. (push flt org-agenda-regexp-filter)
  6965. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6966. (org-agenda-filter-show-all-re)
  6967. (message "Regexp filter removed")))
  6968. (defvar org-agenda-effort-filter nil)
  6969. (defun org-agenda-filter-by-effort (strip)
  6970. "Filter agenda entries by effort.
  6971. With no prefix argument, keep entries matching the effort condition.
  6972. With one prefix argument, filter out entries matching the condition.
  6973. With two prefix arguments, remove the effort filters."
  6974. (interactive "P")
  6975. (cond
  6976. ((member strip '(nil 4))
  6977. (let* ((efforts (split-string
  6978. (or (cdr (assoc (concat org-effort-property "_ALL")
  6979. org-global-properties))
  6980. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6981. ;; XXX: the following handles only up to 10 different
  6982. ;; effort values.
  6983. (allowed-keys (if (null efforts) nil
  6984. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6985. (number-sequence 1 (length efforts)))))
  6986. (op nil))
  6987. (while (not (memq op '(?< ?> ?=)))
  6988. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6989. ;; Select appropriate duration. Ignore non-digit characters.
  6990. (let ((prompt
  6991. (apply #'format
  6992. (concat "Effort %c "
  6993. (mapconcat (lambda (s) (concat "[%d]" s))
  6994. efforts
  6995. " "))
  6996. op allowed-keys))
  6997. (eff -1))
  6998. (while (not (memq eff allowed-keys))
  6999. (message prompt)
  7000. (setq eff (- (read-char-exclusive) 48)))
  7001. (setq org-agenda-effort-filter
  7002. (list (concat (if strip "-" "+")
  7003. (char-to-string op)
  7004. ;; Numbering is 1 2 3 ... 9 0, but we want
  7005. ;; 0 1 2 ... 8 9.
  7006. (nth (mod (1- eff) 10) efforts)))))
  7007. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  7008. (t (org-agenda-filter-show-all-effort)
  7009. (message "Effort filter removed"))))
  7010. (defun org-agenda-filter-remove-all ()
  7011. "Remove all filters from the current agenda buffer."
  7012. (interactive)
  7013. (when org-agenda-tag-filter
  7014. (org-agenda-filter-show-all-tag))
  7015. (when org-agenda-category-filter
  7016. (org-agenda-filter-show-all-cat))
  7017. (when org-agenda-regexp-filter
  7018. (org-agenda-filter-show-all-re))
  7019. (when org-agenda-top-headline-filter
  7020. (org-agenda-filter-show-all-top-filter))
  7021. (when org-agenda-effort-filter
  7022. (org-agenda-filter-show-all-effort))
  7023. (org-agenda-finalize))
  7024. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  7025. "Keep only those lines in the agenda buffer that have a specific tag.
  7026. The tag is selected with its fast selection letter, as configured.
  7027. With a `\\[universal-argument]' prefix, exclude the agenda search.
  7028. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7029. i.e. don't
  7030. filter on all its group members.
  7031. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  7032. should be used to exclude the search - the interactive user can
  7033. also press `-' or `+' to switch between filtering and excluding."
  7034. (interactive "P")
  7035. (let* ((alist org-tag-alist-for-agenda)
  7036. (tag-chars (mapconcat
  7037. (lambda (x) (if (and (not (symbolp (car x)))
  7038. (cdr x))
  7039. (char-to-string (cdr x))
  7040. ""))
  7041. org-tag-alist-for-agenda ""))
  7042. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  7043. (string-to-list tag-chars)))
  7044. (exclude (or exclude (equal arg '(4))))
  7045. (expand (not (equal arg '(16))))
  7046. (inhibit-read-only t)
  7047. (current org-agenda-tag-filter)
  7048. a n tag)
  7049. (unless char
  7050. (while (not (memq char valid-char-list))
  7051. (message
  7052. "%s by tag [%s ], [TAB], %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  7053. (if exclude "Exclude" "Filter") tag-chars
  7054. (if org-agenda-auto-exclude-function "[RET], " "")
  7055. (if expand "" ", no grouptag expand"))
  7056. (setq char (read-char-exclusive))
  7057. ;; Excluding or filtering down
  7058. (cond ((eq char ?-) (setq exclude t))
  7059. ((eq char ?+) (setq exclude nil)))))
  7060. (when (eq char ?\t)
  7061. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  7062. (setq-local org-global-tags-completion-table
  7063. (org-global-tags-completion-table)))
  7064. (let ((completion-ignore-case t))
  7065. (setq tag (completing-read
  7066. "Tag: " org-global-tags-completion-table))))
  7067. (cond
  7068. ((eq char ?\r)
  7069. (org-agenda-filter-show-all-tag)
  7070. (when org-agenda-auto-exclude-function
  7071. (setq org-agenda-tag-filter nil)
  7072. (dolist (tag (org-agenda-get-represented-tags))
  7073. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7074. (if modifier
  7075. (push modifier org-agenda-tag-filter))))
  7076. (if (not (null org-agenda-tag-filter))
  7077. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7078. ((eq char ?/)
  7079. (org-agenda-filter-show-all-tag)
  7080. (when (get 'org-agenda-tag-filter :preset-filter)
  7081. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7082. ((eq char ?.)
  7083. (setq org-agenda-tag-filter
  7084. (mapcar (lambda(tag) (concat "+" tag))
  7085. (org-get-at-bol 'tags)))
  7086. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7087. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7088. ((or (eq char ?\s)
  7089. (setq a (rassoc char alist))
  7090. (and tag (setq a (cons tag nil))))
  7091. (org-agenda-filter-show-all-tag)
  7092. (setq tag (car a))
  7093. (setq org-agenda-tag-filter
  7094. (cons (concat (if exclude "-" "+") tag)
  7095. current))
  7096. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7097. (t (error "Invalid tag selection character %c" char)))))
  7098. (defun org-agenda-get-represented-tags ()
  7099. "Get a list of all tags currently represented in the agenda."
  7100. (let (p tags)
  7101. (save-excursion
  7102. (goto-char (point-min))
  7103. (while (setq p (next-single-property-change (point) 'tags))
  7104. (goto-char p)
  7105. (mapc (lambda (x) (add-to-list 'tags x))
  7106. (get-text-property (point) 'tags))))
  7107. tags))
  7108. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7109. "Create the form that tests a line for agenda filter. Optional
  7110. argument EXPAND can be used for the TYPE tag and will expand the
  7111. tags in the FILTER if any of the tags in FILTER are grouptags."
  7112. (let (f f1)
  7113. (cond
  7114. ;; Tag filter
  7115. ((eq type 'tag)
  7116. (setq filter
  7117. (delete-dups
  7118. (append (get 'org-agenda-tag-filter :preset-filter)
  7119. filter)))
  7120. (dolist (x filter)
  7121. (let ((op (string-to-char x)))
  7122. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7123. (setq x (list x)))
  7124. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7125. (push f1 f))))
  7126. ;; Category filter
  7127. ((eq type 'category)
  7128. (setq filter
  7129. (delete-dups
  7130. (append (get 'org-agenda-category-filter :preset-filter)
  7131. filter)))
  7132. (dolist (x filter)
  7133. (if (equal "-" (substring x 0 1))
  7134. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7135. (setq f1 (list 'equal (substring x 1) 'cat)))
  7136. (push f1 f)))
  7137. ;; Regexp filter
  7138. ((eq type 'regexp)
  7139. (setq filter
  7140. (delete-dups
  7141. (append (get 'org-agenda-regexp-filter :preset-filter)
  7142. filter)))
  7143. (dolist (x filter)
  7144. (if (equal "-" (substring x 0 1))
  7145. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7146. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7147. (push f1 f)))
  7148. ;; Effort filter
  7149. ((eq type 'effort)
  7150. (setq filter
  7151. (delete-dups
  7152. (append (get 'org-agenda-effort-filter :preset-filter)
  7153. filter)))
  7154. (dolist (x filter)
  7155. (push (org-agenda-filter-effort-form x) f))))
  7156. (cons 'and (nreverse f))))
  7157. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7158. "Return a form associated to tag-expression TAGS.
  7159. Build a form testing a line for agenda filter for
  7160. tag-expressions. OP is an operator of type CHAR that allows the
  7161. function to set the right switches in the returned form."
  7162. (let (form)
  7163. ;; Any of the expressions can match if OP is +, all must match if
  7164. ;; the operator is -.
  7165. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7166. (let* ((tag (substring x 1))
  7167. (f (cond
  7168. ((string= "" tag) '(not tags))
  7169. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7170. ;; TAG is a regexp.
  7171. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7172. (t (list 'member (downcase tag) 'tags)))))
  7173. (push (if (eq op ?-) (list 'not f) f) form)))))
  7174. (defun org-agenda-filter-effort-form (e)
  7175. "Return the form to compare the effort of the current line with what E says.
  7176. E looks like \"+<2:25\"."
  7177. (let (op)
  7178. (setq e (substring e 1))
  7179. (setq op (string-to-char e) e (substring e 1))
  7180. (setq op (cond ((equal op ?<) '<=)
  7181. ((equal op ?>) '>=)
  7182. ((equal op ??) op)
  7183. (t '=)))
  7184. (list 'org-agenda-compare-effort (list 'quote op)
  7185. (org-duration-string-to-minutes e))))
  7186. (defun org-agenda-compare-effort (op value)
  7187. "Compare the effort of the current line with VALUE, using OP.
  7188. If the line does not have an effort defined, return nil."
  7189. ;; `effort-minutes' property cannot be extracted directly from
  7190. ;; current line but is stored as a property in `txt'.
  7191. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7192. (funcall op
  7193. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7194. value)))
  7195. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7196. "Expand group tags in FILTER for the agenda.
  7197. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7198. (if org-group-tags
  7199. (let ((case-fold-search t) rtn)
  7200. (mapc
  7201. (lambda (f)
  7202. (let (f0 dir)
  7203. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7204. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7205. (setq dir (if no-operator "" "+") f0 f))
  7206. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7207. (org-tags-expand f0 t t))
  7208. rtn))))
  7209. filter)
  7210. (reverse rtn))
  7211. filter))
  7212. (defun org-agenda-filter-apply (filter type &optional expand)
  7213. "Set FILTER as the new agenda filter and apply it. Optional
  7214. argument EXPAND can be used for the TYPE tag and will expand the
  7215. tags in the FILTER if any of the tags in FILTER are grouptags."
  7216. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7217. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7218. (let (tags cat txt)
  7219. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7220. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7221. ;; category is used as the filter:
  7222. (setq org-agenda-filtered-by-category
  7223. (and (eq type 'category)
  7224. (not (equal (substring (car filter) 0 1) "-"))))
  7225. (org-agenda-set-mode-name)
  7226. (save-excursion
  7227. (goto-char (point-min))
  7228. (while (not (eobp))
  7229. (if (org-get-at-bol 'org-marker)
  7230. (progn
  7231. (setq tags (org-get-at-bol 'tags)
  7232. cat (org-get-at-eol 'org-category 1)
  7233. txt (org-get-at-bol 'txt))
  7234. (if (not (eval org-agenda-filter-form))
  7235. (org-agenda-filter-hide-line type))
  7236. (beginning-of-line 2))
  7237. (beginning-of-line 2))))
  7238. (if (get-char-property (point) 'invisible)
  7239. (ignore-errors (org-agenda-previous-line)))))
  7240. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7241. "Filter by top headline HL."
  7242. (org-agenda-set-mode-name)
  7243. (save-excursion
  7244. (goto-char (point-min))
  7245. (while (not (eobp))
  7246. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7247. (tophl (and pos (org-find-top-headline pos))))
  7248. (if (and tophl (funcall (if negative 'identity 'not)
  7249. (string= hl tophl)))
  7250. (org-agenda-filter-hide-line 'top-headline)))
  7251. (beginning-of-line 2)))
  7252. (if (get-char-property (point) 'invisible)
  7253. (org-agenda-previous-line))
  7254. (setq org-agenda-top-headline-filter hl
  7255. org-agenda-filtered-by-top-headline t))
  7256. (defun org-agenda-filter-hide-line (type)
  7257. "Hide lines with TYPE in the agenda buffer."
  7258. (let* ((b (max (point-min) (1- (point-at-bol))))
  7259. (e (point-at-eol)))
  7260. (let ((inhibit-read-only t))
  7261. (add-text-properties
  7262. b e `(invisible org-filtered org-filter-type ,type)))))
  7263. (defun org-agenda-remove-filter (type)
  7264. (interactive)
  7265. "Remove filter of type TYPE from the agenda buffer."
  7266. (save-excursion
  7267. (goto-char (point-min))
  7268. (let ((inhibit-read-only t) pos)
  7269. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7270. (goto-char pos)
  7271. (remove-text-properties
  7272. (point) (next-single-property-change (point) 'org-filter-type)
  7273. `(invisible org-filtered org-filter-type ,type))))
  7274. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7275. (setq org-agenda-filter-form nil)
  7276. (org-agenda-set-mode-name)
  7277. (org-agenda-finalize)))
  7278. (defun org-agenda-filter-show-all-tag nil
  7279. (org-agenda-remove-filter 'tag))
  7280. (defun org-agenda-filter-show-all-re nil
  7281. (org-agenda-remove-filter 'regexp))
  7282. (defun org-agenda-filter-show-all-effort nil
  7283. (org-agenda-remove-filter 'effort))
  7284. (defun org-agenda-filter-show-all-cat nil
  7285. (org-agenda-remove-filter 'category))
  7286. (defun org-agenda-filter-show-all-top-filter nil
  7287. (org-agenda-remove-filter 'top-headline))
  7288. (defun org-agenda-manipulate-query-add ()
  7289. "Manipulate the query by adding a search term with positive selection.
  7290. Positive selection means the term must be matched for selection of an entry."
  7291. (interactive)
  7292. (org-agenda-manipulate-query ?\[))
  7293. (defun org-agenda-manipulate-query-subtract ()
  7294. "Manipulate the query by adding a search term with negative selection.
  7295. Negative selection means term must not be matched for selection of an entry."
  7296. (interactive)
  7297. (org-agenda-manipulate-query ?\]))
  7298. (defun org-agenda-manipulate-query-add-re ()
  7299. "Manipulate the query by adding a search regexp with positive selection.
  7300. Positive selection means the regexp must match for selection of an entry."
  7301. (interactive)
  7302. (org-agenda-manipulate-query ?\{))
  7303. (defun org-agenda-manipulate-query-subtract-re ()
  7304. "Manipulate the query by adding a search regexp with negative selection.
  7305. Negative selection means regexp must not match for selection of an entry."
  7306. (interactive)
  7307. (org-agenda-manipulate-query ?\}))
  7308. (defun org-agenda-manipulate-query (char)
  7309. (cond
  7310. ((memq org-agenda-type '(timeline agenda))
  7311. (let ((org-agenda-include-inactive-timestamps t))
  7312. (org-agenda-redo))
  7313. (message "Display now includes inactive timestamps as well"))
  7314. ((eq org-agenda-type 'search)
  7315. (org-add-to-string
  7316. 'org-agenda-query-string
  7317. (if org-agenda-last-search-view-search-was-boolean
  7318. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7319. (?\{ . " +{}") (?\} . " -{}"))))
  7320. " "))
  7321. (setq org-agenda-redo-command
  7322. (list 'org-search-view
  7323. (car (get-text-property (min (1- (point-max)) (point))
  7324. 'org-last-args))
  7325. org-agenda-query-string
  7326. (+ (length org-agenda-query-string)
  7327. (if (member char '(?\{ ?\})) 0 1))))
  7328. (set-register org-agenda-query-register org-agenda-query-string)
  7329. (let ((org-agenda-overriding-arguments
  7330. (cdr org-agenda-redo-command)))
  7331. (org-agenda-redo)))
  7332. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7333. org-agenda-type))))
  7334. (defun org-add-to-string (var string)
  7335. (set var (concat (symbol-value var) string)))
  7336. (defun org-agenda-goto-date (span)
  7337. "Jump to DATE in agenda."
  7338. (interactive "P")
  7339. (let* ((org-read-date-prefer-future
  7340. (eval org-agenda-jump-prefer-future))
  7341. (date (org-read-date))
  7342. (day (time-to-days (org-time-string-to-time date)))
  7343. (org-agenda-sticky-orig org-agenda-sticky)
  7344. (org-agenda-buffer-tmp-name (buffer-name))
  7345. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7346. (0-arg (or current-prefix-arg (car args)))
  7347. (2-arg (nth 2 args))
  7348. (with-hour-p (nth 4 org-agenda-redo-command))
  7349. (newcmd (list 'org-agenda-list 0-arg date
  7350. (org-agenda-span-to-ndays
  7351. 2-arg (org-time-string-to-absolute date))
  7352. with-hour-p))
  7353. (newargs (cdr newcmd))
  7354. (inhibit-read-only t)
  7355. org-agenda-sticky)
  7356. (if (not (org-agenda-check-type t 'agenda))
  7357. (error "Not available in non-agenda views")
  7358. (add-text-properties (point-min) (point-max)
  7359. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7360. (org-agenda-redo)
  7361. (goto-char (point-min))
  7362. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7363. (save-excursion (move-beginning-of-line 2) (eobp))))
  7364. (move-beginning-of-line 2))
  7365. (setq org-agenda-sticky org-agenda-sticky-orig
  7366. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7367. (defun org-agenda-goto-today ()
  7368. "Go to today."
  7369. (interactive)
  7370. (org-agenda-check-type t 'timeline 'agenda)
  7371. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7372. (curspan (nth 2 args))
  7373. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7374. (cond
  7375. (tdpos (goto-char tdpos))
  7376. ((eq org-agenda-type 'agenda)
  7377. (let* ((sd (org-agenda-compute-starting-span
  7378. (org-today) (or curspan org-agenda-span)))
  7379. (org-agenda-overriding-arguments args))
  7380. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7381. (org-agenda-redo)
  7382. (org-agenda-find-same-or-today-or-agenda)))
  7383. (t (error "Cannot find today")))))
  7384. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7385. (goto-char
  7386. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7387. (text-property-any (point-min) (point-max) 'org-today t)
  7388. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7389. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7390. (org-agenda-backward-block))
  7391. (point-min))))
  7392. (defun org-agenda-backward-block ()
  7393. "Move backward by one agenda block."
  7394. (interactive)
  7395. (org-agenda-forward-block 'backward))
  7396. (defun org-agenda-forward-block (&optional backward)
  7397. "Move forward by one agenda block.
  7398. When optional argument BACKWARD is set, go backward"
  7399. (interactive)
  7400. (cond ((not (derived-mode-p 'org-agenda-mode))
  7401. (user-error
  7402. "Cannot execute this command outside of org-agenda-mode buffers"))
  7403. ((looking-at (if backward "\\`" "\\'"))
  7404. (message "Already at the %s block" (if backward "first" "last")))
  7405. (t (let ((pos (prog1 (point)
  7406. (ignore-errors (if backward (backward-char 1)
  7407. (move-end-of-line 1)))))
  7408. (f (if backward
  7409. 'previous-single-property-change
  7410. 'next-single-property-change))
  7411. moved dest)
  7412. (while (and (setq dest (funcall
  7413. f (point) 'org-agenda-structural-header))
  7414. (not (get-text-property
  7415. (point) 'org-agenda-structural-header)))
  7416. (setq moved t)
  7417. (goto-char dest))
  7418. (if moved (move-beginning-of-line 1)
  7419. (goto-char (if backward (point-min) (point-max)))
  7420. (move-beginning-of-line 1)
  7421. (message "No %s block" (if backward "previous" "further")))))))
  7422. (defun org-agenda-later (arg)
  7423. "Go forward in time by the current span.
  7424. With prefix ARG, go forward that many times the current span."
  7425. (interactive "p")
  7426. (org-agenda-check-type t 'agenda)
  7427. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7428. (span (or (nth 2 args) org-agenda-current-span))
  7429. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7430. (greg (calendar-gregorian-from-absolute sd))
  7431. (cnt (org-get-at-bol 'org-day-cnt))
  7432. greg2)
  7433. (cond
  7434. ((numberp span)
  7435. (setq sd (+ (* span arg) sd)))
  7436. ((eq span 'day)
  7437. (setq sd (+ arg sd)))
  7438. ((eq span 'week)
  7439. (setq sd (+ (* 7 arg) sd)))
  7440. ((eq span 'fortnight)
  7441. (setq sd (+ (* 14 arg) sd)))
  7442. ((eq span 'month)
  7443. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7444. sd (calendar-absolute-from-gregorian greg2))
  7445. (setcar greg2 (1+ (car greg2))))
  7446. ((eq span 'year)
  7447. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7448. sd (calendar-absolute-from-gregorian greg2))
  7449. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7450. (t
  7451. (setq sd (+ (* span arg) sd))))
  7452. (let ((org-agenda-overriding-cmd
  7453. ;; `cmd' may have been set by `org-agenda-run-series' which
  7454. ;; uses `org-agenda-overriding-cmd' to decide whether
  7455. ;; overriding is allowed for `cmd'
  7456. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7457. (org-agenda-overriding-arguments
  7458. (list (car args) sd span)))
  7459. (org-agenda-redo)
  7460. (org-agenda-find-same-or-today-or-agenda cnt))))
  7461. (defun org-agenda-earlier (arg)
  7462. "Go backward in time by the current span.
  7463. With prefix ARG, go backward that many times the current span."
  7464. (interactive "p")
  7465. (org-agenda-later (- arg)))
  7466. (defun org-agenda-view-mode-dispatch ()
  7467. "Call one of the view mode commands."
  7468. (interactive)
  7469. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7470. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7471. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7472. (pcase (read-char-exclusive)
  7473. (?\ (call-interactively 'org-agenda-reset-view))
  7474. (?d (call-interactively 'org-agenda-day-view))
  7475. (?w (call-interactively 'org-agenda-week-view))
  7476. (?t (call-interactively 'org-agenda-fortnight-view))
  7477. (?m (call-interactively 'org-agenda-month-view))
  7478. (?y (call-interactively 'org-agenda-year-view))
  7479. (?l (call-interactively 'org-agenda-log-mode))
  7480. (?L (org-agenda-log-mode '(4)))
  7481. (?c (org-agenda-log-mode 'clockcheck))
  7482. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7483. (?a (call-interactively 'org-agenda-archives-mode))
  7484. (?A (org-agenda-archives-mode 'files))
  7485. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7486. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7487. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7488. (?D (call-interactively 'org-agenda-toggle-diary))
  7489. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7490. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7491. (org-agenda-check-type t 'timeline 'agenda)
  7492. (org-agenda-redo))
  7493. (message "Display now includes inactive timestamps as well"))
  7494. (?q (message "Abort"))
  7495. (key (user-error "Invalid key: %s" key))))
  7496. (defun org-agenda-reset-view ()
  7497. "Switch to default view for agenda."
  7498. (interactive)
  7499. (org-agenda-change-time-span org-agenda-span))
  7500. (defun org-agenda-day-view (&optional day-of-month)
  7501. "Switch to daily view for agenda.
  7502. With argument DAY-OF-MONTH, switch to that day of the month."
  7503. (interactive "P")
  7504. (org-agenda-change-time-span 'day day-of-month))
  7505. (defun org-agenda-week-view (&optional iso-week)
  7506. "Switch to weekly view for agenda.
  7507. With argument ISO-WEEK, switch to the corresponding ISO week.
  7508. If ISO-WEEK has more then 2 digits, only the last two encode
  7509. the week. Any digits before this encode a year. So 200712
  7510. means week 12 of year 2007. Years ranging from 70 years ago
  7511. to 30 years in the future can also be written as 2-digit years."
  7512. (interactive "P")
  7513. (org-agenda-change-time-span 'week iso-week))
  7514. (defun org-agenda-fortnight-view (&optional iso-week)
  7515. "Switch to fortnightly view for agenda.
  7516. With argument ISO-WEEK, switch to the corresponding ISO week.
  7517. If ISO-WEEK has more then 2 digits, only the last two encode
  7518. the week. Any digits before this encode a year. So 200712
  7519. means week 12 of year 2007. Years ranging from 70 years ago
  7520. to 30 years in the future can also be written as 2-digit years."
  7521. (interactive "P")
  7522. (org-agenda-change-time-span 'fortnight iso-week))
  7523. (defun org-agenda-month-view (&optional month)
  7524. "Switch to monthly view for agenda.
  7525. With argument MONTH, switch to that month. If MONTH has more
  7526. then 2 digits, only the last two encode the month. Any digits
  7527. before this encode a year. So 200712 means December year 2007.
  7528. Years ranging from 70 years ago to 30 years in the future can
  7529. also be written as 2-digit years."
  7530. (interactive "P")
  7531. (org-agenda-change-time-span 'month month))
  7532. (defun org-agenda-year-view (&optional year)
  7533. "Switch to yearly view for agenda.
  7534. With argument YEAR, switch to that year. Years ranging from 70
  7535. years ago to 30 years in the future can also be written as
  7536. 2-digit years."
  7537. (interactive "P")
  7538. (when year
  7539. (setq year (org-small-year-to-year year)))
  7540. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7541. (org-agenda-change-time-span 'year year)
  7542. (error "Abort")))
  7543. (defun org-agenda-change-time-span (span &optional n)
  7544. "Change the agenda view to SPAN.
  7545. SPAN may be `day', `week', `fortnight', `month', `year'."
  7546. (org-agenda-check-type t 'agenda)
  7547. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7548. (curspan (nth 2 args)))
  7549. (if (and (not n) (equal curspan span))
  7550. (error "Viewing span is already \"%s\"" span))
  7551. (let* ((sd (or (org-get-at-bol 'day)
  7552. (nth 1 args)
  7553. org-starting-day))
  7554. (sd (org-agenda-compute-starting-span sd span n))
  7555. (org-agenda-overriding-cmd
  7556. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7557. (org-agenda-overriding-arguments
  7558. (list (car args) sd span)))
  7559. (org-agenda-redo)
  7560. (org-agenda-find-same-or-today-or-agenda))
  7561. (org-agenda-set-mode-name)
  7562. (message "Switched to %s view" span)))
  7563. (defun org-agenda-compute-starting-span (sd span &optional n)
  7564. "Compute starting date for agenda.
  7565. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7566. is a cons cell with the starting date and the number of days,
  7567. so that the date SD will be in that range."
  7568. (let* ((greg (calendar-gregorian-from-absolute sd))
  7569. (dg (nth 1 greg))
  7570. (mg (car greg))
  7571. (yg (nth 2 greg)))
  7572. (cond
  7573. ((eq span 'day)
  7574. (when n
  7575. (setq sd (+ (calendar-absolute-from-gregorian
  7576. (list mg 1 yg))
  7577. n -1))))
  7578. ((or (eq span 'week) (eq span 'fortnight))
  7579. (let* ((nt (calendar-day-of-week
  7580. (calendar-gregorian-from-absolute sd)))
  7581. (d (if org-agenda-start-on-weekday
  7582. (- nt org-agenda-start-on-weekday)
  7583. 0))
  7584. y1)
  7585. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7586. (when n
  7587. (require 'cal-iso)
  7588. (when (> n 99)
  7589. (setq y1 (org-small-year-to-year (/ n 100))
  7590. n (mod n 100)))
  7591. (setq sd
  7592. (calendar-iso-to-absolute
  7593. (list n 1
  7594. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7595. ((eq span 'month)
  7596. (let (y1)
  7597. (when (and n (> n 99))
  7598. (setq y1 (org-small-year-to-year (/ n 100))
  7599. n (mod n 100)))
  7600. (setq sd (calendar-absolute-from-gregorian
  7601. (list (or n mg) 1 (or y1 yg))))))
  7602. ((eq span 'year)
  7603. (setq sd (calendar-absolute-from-gregorian
  7604. (list 1 1 (or n yg))))))
  7605. sd))
  7606. (defun org-agenda-next-date-line (&optional arg)
  7607. "Jump to the next line indicating a date in agenda buffer."
  7608. (interactive "p")
  7609. (org-agenda-check-type t 'agenda 'timeline)
  7610. (beginning-of-line 1)
  7611. ;; This does not work if user makes date format that starts with a blank
  7612. (if (looking-at "^\\S-") (forward-char 1))
  7613. (if (not (re-search-forward "^\\S-" nil t arg))
  7614. (progn
  7615. (backward-char 1)
  7616. (error "No next date after this line in this buffer")))
  7617. (goto-char (match-beginning 0)))
  7618. (defun org-agenda-previous-date-line (&optional arg)
  7619. "Jump to the previous line indicating a date in agenda buffer."
  7620. (interactive "p")
  7621. (org-agenda-check-type t 'agenda 'timeline)
  7622. (beginning-of-line 1)
  7623. (if (not (re-search-backward "^\\S-" nil t arg))
  7624. (error "No previous date before this line in this buffer")))
  7625. ;; Initialize the highlight
  7626. (defvar org-hl (make-overlay 1 1))
  7627. (overlay-put org-hl 'face 'highlight)
  7628. (defun org-highlight (begin end &optional buffer)
  7629. "Highlight a region with overlay."
  7630. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7631. (defun org-unhighlight ()
  7632. "Detach overlay INDEX."
  7633. (delete-overlay org-hl))
  7634. (defun org-unhighlight-once ()
  7635. "Remove the highlight from its position, and this function from the hook."
  7636. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7637. (org-unhighlight))
  7638. (defvar org-agenda-pre-follow-window-conf nil)
  7639. (defun org-agenda-follow-mode ()
  7640. "Toggle follow mode in an agenda buffer."
  7641. (interactive)
  7642. (unless org-agenda-follow-mode
  7643. (setq org-agenda-pre-follow-window-conf
  7644. (current-window-configuration)))
  7645. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7646. (unless org-agenda-follow-mode
  7647. (set-window-configuration org-agenda-pre-follow-window-conf))
  7648. (org-agenda-set-mode-name)
  7649. (org-agenda-do-context-action)
  7650. (message "Follow mode is %s"
  7651. (if org-agenda-follow-mode "on" "off")))
  7652. (defun org-agenda-entry-text-mode (&optional arg)
  7653. "Toggle entry text mode in an agenda buffer."
  7654. (interactive "P")
  7655. (if (or org-agenda-tag-filter
  7656. org-agenda-category-filter
  7657. org-agenda-regexp-filter
  7658. org-agenda-top-headline-filter)
  7659. (user-error "Can't show entry text in filtered views")
  7660. (setq org-agenda-entry-text-mode (or (integerp arg)
  7661. (not org-agenda-entry-text-mode)))
  7662. (org-agenda-entry-text-hide)
  7663. (and org-agenda-entry-text-mode
  7664. (let ((org-agenda-entry-text-maxlines
  7665. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7666. (org-agenda-entry-text-show)))
  7667. (org-agenda-set-mode-name)
  7668. (message "Entry text mode is %s%s"
  7669. (if org-agenda-entry-text-mode "on" "off")
  7670. (if (not org-agenda-entry-text-mode) ""
  7671. (format " (maximum number of lines is %d)"
  7672. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7673. (defun org-agenda-clockreport-mode ()
  7674. "Toggle clocktable mode in an agenda buffer."
  7675. (interactive)
  7676. (org-agenda-check-type t 'agenda)
  7677. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7678. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7679. (org-agenda-set-mode-name)
  7680. (org-agenda-redo)
  7681. (message "Clocktable mode is %s"
  7682. (if org-agenda-clockreport-mode "on" "off")))
  7683. (defun org-agenda-log-mode (&optional special)
  7684. "Toggle log mode in an agenda buffer.
  7685. With argument SPECIAL, show all possible log items, not only the ones
  7686. configured in `org-agenda-log-mode-items'.
  7687. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7688. log items, nothing else."
  7689. (interactive "P")
  7690. (org-agenda-check-type t 'agenda 'timeline)
  7691. (setq org-agenda-show-log
  7692. (cond
  7693. ((equal special '(16)) 'only)
  7694. ((eq special 'clockcheck)
  7695. (if (eq org-agenda-show-log 'clockcheck)
  7696. nil 'clockcheck))
  7697. (special '(closed clock state))
  7698. (t (not org-agenda-show-log))))
  7699. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7700. (org-agenda-set-mode-name)
  7701. (org-agenda-redo)
  7702. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7703. (defun org-agenda-archives-mode (&optional with-files)
  7704. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7705. When called with a prefix argument, include all archive files as well."
  7706. (interactive "P")
  7707. (setq org-agenda-archives-mode
  7708. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7709. (org-agenda-set-mode-name)
  7710. (org-agenda-redo)
  7711. (message
  7712. "%s"
  7713. (cond
  7714. ((eq org-agenda-archives-mode nil)
  7715. "No archives are included")
  7716. ((eq org-agenda-archives-mode 'trees)
  7717. (format "Trees with :%s: tag are included" org-archive-tag))
  7718. ((eq org-agenda-archives-mode t)
  7719. (format "Trees with :%s: tag and all active archive files are included"
  7720. org-archive-tag)))))
  7721. (defun org-agenda-toggle-diary ()
  7722. "Toggle diary inclusion in an agenda buffer."
  7723. (interactive)
  7724. (org-agenda-check-type t 'agenda)
  7725. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7726. (org-agenda-redo)
  7727. (org-agenda-set-mode-name)
  7728. (message "Diary inclusion turned %s"
  7729. (if org-agenda-include-diary "on" "off")))
  7730. (defun org-agenda-toggle-deadlines ()
  7731. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7732. (interactive)
  7733. (org-agenda-check-type t 'agenda)
  7734. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7735. (org-agenda-redo)
  7736. (org-agenda-set-mode-name)
  7737. (message "Deadlines inclusion turned %s"
  7738. (if org-agenda-include-deadlines "on" "off")))
  7739. (defun org-agenda-toggle-time-grid ()
  7740. "Toggle time grid in an agenda buffer."
  7741. (interactive)
  7742. (org-agenda-check-type t 'agenda)
  7743. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7744. (org-agenda-redo)
  7745. (org-agenda-set-mode-name)
  7746. (message "Time-grid turned %s"
  7747. (if org-agenda-use-time-grid "on" "off")))
  7748. (defun org-agenda-set-mode-name ()
  7749. "Set the mode name to indicate all the small mode settings."
  7750. (setq mode-name
  7751. (list "Org-Agenda"
  7752. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7753. " "
  7754. '(:eval (org-agenda-span-name org-agenda-current-span))
  7755. (if org-agenda-follow-mode " Follow" "")
  7756. (if org-agenda-entry-text-mode " ETxt" "")
  7757. (if org-agenda-include-diary " Diary" "")
  7758. (if org-agenda-include-deadlines " Ddl" "")
  7759. (if org-agenda-use-time-grid " Grid" "")
  7760. (if (and (boundp 'org-habit-show-habits)
  7761. org-habit-show-habits) " Habit" "")
  7762. (cond
  7763. ((consp org-agenda-show-log) " LogAll")
  7764. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7765. (org-agenda-show-log " Log")
  7766. (t ""))
  7767. (if (or org-agenda-category-filter
  7768. (get 'org-agenda-category-filter :preset-filter))
  7769. '(:eval (propertize
  7770. (concat " <"
  7771. (mapconcat
  7772. 'identity
  7773. (append
  7774. (get 'org-agenda-category-filter :preset-filter)
  7775. org-agenda-category-filter)
  7776. "")
  7777. ">")
  7778. 'face 'org-agenda-filter-category
  7779. 'help-echo "Category used in filtering")) "")
  7780. (if (or org-agenda-tag-filter
  7781. (get 'org-agenda-tag-filter :preset-filter))
  7782. '(:eval (propertize
  7783. (concat " {"
  7784. (mapconcat
  7785. 'identity
  7786. (append
  7787. (get 'org-agenda-tag-filter :preset-filter)
  7788. org-agenda-tag-filter)
  7789. "")
  7790. "}")
  7791. 'face 'org-agenda-filter-tags
  7792. 'help-echo "Tags used in filtering")) "")
  7793. (if (or org-agenda-effort-filter
  7794. (get 'org-agenda-effort-filter :preset-filter))
  7795. '(:eval (propertize
  7796. (concat " {"
  7797. (mapconcat
  7798. 'identity
  7799. (append
  7800. (get 'org-agenda-effort-filter :preset-filter)
  7801. org-agenda-effort-filter)
  7802. "")
  7803. "}")
  7804. 'face 'org-agenda-filter-effort
  7805. 'help-echo "Effort conditions used in filtering")) "")
  7806. (if (or org-agenda-regexp-filter
  7807. (get 'org-agenda-regexp-filter :preset-filter))
  7808. '(:eval (propertize
  7809. (concat " ["
  7810. (mapconcat
  7811. 'identity
  7812. (append
  7813. (get 'org-agenda-regexp-filter :preset-filter)
  7814. org-agenda-regexp-filter)
  7815. "")
  7816. "]")
  7817. 'face 'org-agenda-filter-regexp
  7818. 'help-echo "Regexp used in filtering")) "")
  7819. (if org-agenda-archives-mode
  7820. (if (eq org-agenda-archives-mode t)
  7821. " Archives"
  7822. (format " :%s:" org-archive-tag))
  7823. "")
  7824. (if org-agenda-clockreport-mode " Clock" "")))
  7825. (force-mode-line-update))
  7826. (defun org-agenda-update-agenda-type ()
  7827. "Update the agenda type after each command."
  7828. (setq org-agenda-type
  7829. (or (get-text-property (point) 'org-agenda-type)
  7830. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7831. (defun org-agenda-next-line ()
  7832. "Move cursor to the next line, and show if follow mode is active."
  7833. (interactive)
  7834. (call-interactively 'next-line)
  7835. (org-agenda-do-context-action))
  7836. (defun org-agenda-previous-line ()
  7837. "Move cursor to the previous line, and show if follow-mode is active."
  7838. (interactive)
  7839. (call-interactively 'previous-line)
  7840. (org-agenda-do-context-action))
  7841. (defun org-agenda-next-item (n)
  7842. "Move cursor to next agenda item."
  7843. (interactive "p")
  7844. (let ((col (current-column)))
  7845. (dotimes (c n)
  7846. (when (next-single-property-change (point-at-eol) 'org-marker)
  7847. (move-end-of-line 1)
  7848. (goto-char (next-single-property-change (point) 'org-marker))))
  7849. (org-move-to-column col))
  7850. (org-agenda-do-context-action))
  7851. (defun org-agenda-previous-item (n)
  7852. "Move cursor to next agenda item."
  7853. (interactive "p")
  7854. (dotimes (c n)
  7855. (let ((col (current-column))
  7856. (goto (save-excursion
  7857. (move-end-of-line 0)
  7858. (previous-single-property-change (point) 'org-marker))))
  7859. (if goto (goto-char goto))
  7860. (org-move-to-column col)))
  7861. (org-agenda-do-context-action))
  7862. (defun org-agenda-do-context-action ()
  7863. "Show outline path and, maybe, follow mode window."
  7864. (let ((m (org-get-at-bol 'org-marker)))
  7865. (when (and (markerp m) (marker-buffer m))
  7866. (and org-agenda-follow-mode
  7867. (if org-agenda-follow-indirect
  7868. (org-agenda-tree-to-indirect-buffer nil)
  7869. (org-agenda-show)))
  7870. (and org-agenda-show-outline-path
  7871. (org-with-point-at m (org-display-outline-path t))))))
  7872. (defun org-agenda-show-tags ()
  7873. "Show the tags applicable to the current item."
  7874. (interactive)
  7875. (let* ((tags (org-get-at-bol 'tags)))
  7876. (if tags
  7877. (message "Tags are :%s:"
  7878. (org-no-properties (mapconcat 'identity tags ":")))
  7879. (message "No tags associated with this line"))))
  7880. (defun org-agenda-goto (&optional highlight)
  7881. "Go to the entry at point in the corresponding Org file."
  7882. (interactive)
  7883. (let* ((marker (or (org-get-at-bol 'org-marker)
  7884. (org-agenda-error)))
  7885. (buffer (marker-buffer marker))
  7886. (pos (marker-position marker)))
  7887. (switch-to-buffer-other-window buffer)
  7888. (widen)
  7889. (push-mark)
  7890. (goto-char pos)
  7891. (when (derived-mode-p 'org-mode)
  7892. (org-show-context 'agenda)
  7893. (recenter (/ (window-height) 2))
  7894. (org-back-to-heading t)
  7895. (let ((case-fold-search nil))
  7896. (when (re-search-forward org-complex-heading-regexp nil t)
  7897. (goto-char (match-beginning 4)))))
  7898. (run-hooks 'org-agenda-after-show-hook)
  7899. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7900. (defvar org-agenda-after-show-hook nil
  7901. "Normal hook run after an item has been shown from the agenda.
  7902. Point is in the buffer where the item originated.")
  7903. (defun org-agenda-kill ()
  7904. "Kill the entry or subtree belonging to the current agenda entry."
  7905. (interactive)
  7906. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7907. (let* ((bufname-orig (buffer-name))
  7908. (marker (or (org-get-at-bol 'org-marker)
  7909. (org-agenda-error)))
  7910. (buffer (marker-buffer marker))
  7911. (pos (marker-position marker))
  7912. (type (org-get-at-bol 'type))
  7913. dbeg dend (n 0) conf)
  7914. (org-with-remote-undo buffer
  7915. (with-current-buffer buffer
  7916. (save-excursion
  7917. (goto-char pos)
  7918. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7919. (setq dbeg (progn (org-back-to-heading t) (point))
  7920. dend (org-end-of-subtree t t))
  7921. (setq dbeg (point-at-bol)
  7922. dend (min (point-max) (1+ (point-at-eol)))))
  7923. (goto-char dbeg)
  7924. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7925. (setq conf (or (eq t org-agenda-confirm-kill)
  7926. (and (numberp org-agenda-confirm-kill)
  7927. (> n org-agenda-confirm-kill))))
  7928. (and conf
  7929. (not (y-or-n-p
  7930. (format "Delete entry with %d lines in buffer \"%s\"? "
  7931. n (buffer-name buffer))))
  7932. (error "Abort"))
  7933. (let ((org-agenda-buffer-name bufname-orig))
  7934. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7935. (with-current-buffer buffer (delete-region dbeg dend))
  7936. (message "Agenda item and source killed"))))
  7937. (defvar org-archive-default-command) ; defined in org-archive.el
  7938. (defun org-agenda-archive-default ()
  7939. "Archive the entry or subtree belonging to the current agenda entry."
  7940. (interactive)
  7941. (require 'org-archive)
  7942. (org-agenda-archive-with org-archive-default-command))
  7943. (defun org-agenda-archive-default-with-confirmation ()
  7944. "Archive the entry or subtree belonging to the current agenda entry."
  7945. (interactive)
  7946. (require 'org-archive)
  7947. (org-agenda-archive-with org-archive-default-command 'confirm))
  7948. (defun org-agenda-archive ()
  7949. "Archive the entry or subtree belonging to the current agenda entry."
  7950. (interactive)
  7951. (org-agenda-archive-with 'org-archive-subtree))
  7952. (defun org-agenda-archive-to-archive-sibling ()
  7953. "Move the entry to the archive sibling."
  7954. (interactive)
  7955. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7956. (defun org-agenda-archive-with (cmd &optional confirm)
  7957. "Move the entry to the archive sibling."
  7958. (interactive)
  7959. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7960. (let* ((bufname-orig (buffer-name))
  7961. (marker (or (org-get-at-bol 'org-marker)
  7962. (org-agenda-error)))
  7963. (buffer (marker-buffer marker))
  7964. (pos (marker-position marker)))
  7965. (org-with-remote-undo buffer
  7966. (with-current-buffer buffer
  7967. (if (derived-mode-p 'org-mode)
  7968. (if (and confirm
  7969. (not (y-or-n-p "Archive this subtree or entry? ")))
  7970. (error "Abort")
  7971. (save-window-excursion
  7972. (goto-char pos)
  7973. (let ((org-agenda-buffer-name bufname-orig))
  7974. (org-remove-subtree-entries-from-agenda))
  7975. (org-back-to-heading t)
  7976. (funcall cmd)))
  7977. (error "Archiving works only in Org files"))))))
  7978. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7979. "Remove all lines in the agenda that correspond to a given subtree.
  7980. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7981. If this information is not given, the function uses the tree at point."
  7982. (let ((buf (or buf (current-buffer))) m p)
  7983. (save-excursion
  7984. (unless (and beg end)
  7985. (org-back-to-heading t)
  7986. (setq beg (point))
  7987. (org-end-of-subtree t)
  7988. (setq end (point)))
  7989. (set-buffer (get-buffer org-agenda-buffer-name))
  7990. (save-excursion
  7991. (goto-char (point-max))
  7992. (beginning-of-line 1)
  7993. (while (not (bobp))
  7994. (when (and (setq m (org-get-at-bol 'org-marker))
  7995. (equal buf (marker-buffer m))
  7996. (setq p (marker-position m))
  7997. (>= p beg)
  7998. (< p end))
  7999. (let ((inhibit-read-only t))
  8000. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8001. (beginning-of-line 0))))))
  8002. (defun org-agenda-refile (&optional goto rfloc no-update)
  8003. "Refile the item at point.
  8004. When called with `\\[universal-argument] \\[universal-argument]', \
  8005. go to the location of the last
  8006. refiled item.
  8007. When called with `\\[universal-argument] \\[universal-argument] \
  8008. \\[universal-argument]' prefix or when GOTO is 0, clear
  8009. the refile cache.
  8010. RFLOC can be a refile location obtained in a different way.
  8011. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8012. (interactive "P")
  8013. (cond
  8014. ((member goto '(0 (64)))
  8015. (org-refile-cache-clear))
  8016. ((equal goto '(16))
  8017. (org-refile-goto-last-stored))
  8018. (t
  8019. (let* ((buffer-orig (buffer-name))
  8020. (marker (or (org-get-at-bol 'org-hd-marker)
  8021. (org-agenda-error)))
  8022. (buffer (marker-buffer marker))
  8023. (pos (marker-position marker))
  8024. (rfloc (or rfloc
  8025. (org-refile-get-location
  8026. (if goto "Goto" "Refile to") buffer
  8027. org-refile-allow-creating-parent-nodes))))
  8028. (with-current-buffer buffer
  8029. (org-with-wide-buffer
  8030. (goto-char marker)
  8031. (let ((org-agenda-buffer-name buffer-orig))
  8032. (org-remove-subtree-entries-from-agenda))
  8033. (org-refile goto buffer rfloc))))
  8034. (unless no-update (org-agenda-redo)))))
  8035. (defun org-agenda-open-link (&optional arg)
  8036. "Open the link(s) in the current entry, if any.
  8037. This looks for a link in the displayed line in the agenda.
  8038. It also looks at the text of the entry itself."
  8039. (interactive "P")
  8040. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8041. (org-get-at-bol 'org-marker)))
  8042. (buffer (and marker (marker-buffer marker)))
  8043. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8044. (lkall (and buffer (org-offer-links-in-entry
  8045. buffer marker arg prefix)))
  8046. (lk0 (car lkall))
  8047. (lk (if (stringp lk0) (list lk0) lk0))
  8048. (lkend (cdr lkall))
  8049. trg)
  8050. (cond
  8051. ((and buffer lk)
  8052. (mapcar (lambda(l)
  8053. (with-current-buffer buffer
  8054. (setq trg (and (string-match org-bracket-link-regexp l)
  8055. (match-string 1 l)))
  8056. (if (or (not trg) (string-match org-any-link-re trg))
  8057. (org-with-wide-buffer
  8058. (goto-char marker)
  8059. (when (search-forward l nil lkend)
  8060. (goto-char (match-beginning 0))
  8061. (org-open-at-point)))
  8062. ;; This is an internal link, widen the buffer
  8063. (switch-to-buffer-other-window buffer)
  8064. (widen)
  8065. (goto-char marker)
  8066. (when (search-forward l nil lkend)
  8067. (goto-char (match-beginning 0))
  8068. (org-open-at-point)))))
  8069. lk))
  8070. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  8071. (save-excursion
  8072. (beginning-of-line 1)
  8073. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  8074. (org-open-link-from-string (match-string 1)))
  8075. (t (message "No link to open here")))))
  8076. (defun org-agenda-copy-local-variable (var)
  8077. "Get a variable from a referenced buffer and install it here."
  8078. (let ((m (org-get-at-bol 'org-marker)))
  8079. (when (and m (buffer-live-p (marker-buffer m)))
  8080. (set (make-local-variable var)
  8081. (with-current-buffer (marker-buffer m)
  8082. (symbol-value var))))))
  8083. (defun org-agenda-switch-to (&optional delete-other-windows)
  8084. "Go to the Org mode file which contains the item at point.
  8085. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8086. displayed Org file fills the frame."
  8087. (interactive)
  8088. (if (and org-return-follows-link
  8089. (not (org-get-at-bol 'org-marker))
  8090. (org-in-regexp org-bracket-link-regexp))
  8091. (org-open-link-from-string (match-string 0))
  8092. (let* ((marker (or (org-get-at-bol 'org-marker)
  8093. (org-agenda-error)))
  8094. (buffer (marker-buffer marker))
  8095. (pos (marker-position marker)))
  8096. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8097. (pop-to-buffer-same-window buffer)
  8098. (when delete-other-windows (delete-other-windows))
  8099. (widen)
  8100. (goto-char pos)
  8101. (when (derived-mode-p 'org-mode)
  8102. (org-show-context 'agenda)
  8103. (run-hooks 'org-agenda-after-show-hook)))))
  8104. (defun org-agenda-goto-mouse (ev)
  8105. "Go to the Org file which contains the item at the mouse click."
  8106. (interactive "e")
  8107. (mouse-set-point ev)
  8108. (org-agenda-goto))
  8109. (defun org-agenda-show (&optional full-entry)
  8110. "Display the Org file which contains the item at point.
  8111. With prefix argument FULL-ENTRY, make the entire entry visible
  8112. if it was hidden in the outline."
  8113. (interactive "P")
  8114. (let ((win (selected-window)))
  8115. (org-agenda-goto t)
  8116. (when full-entry (org-show-entry))
  8117. (select-window win)))
  8118. (defvar org-agenda-show-window nil)
  8119. (defun org-agenda-show-and-scroll-up (&optional arg)
  8120. "Display the Org file which contains the item at point.
  8121. When called repeatedly, scroll the window that is displaying the buffer.
  8122. With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
  8123. `outline-show-subtree'
  8124. to display the item, so that drawers and logbooks stay folded."
  8125. (interactive "P")
  8126. (let ((win (selected-window)))
  8127. (if (and (window-live-p org-agenda-show-window)
  8128. (eq this-command last-command))
  8129. (progn
  8130. (select-window org-agenda-show-window)
  8131. (ignore-errors (scroll-up)))
  8132. (org-agenda-goto t)
  8133. (if arg (org-show-entry) (outline-show-subtree))
  8134. (setq org-agenda-show-window (selected-window)))
  8135. (select-window win)))
  8136. (defun org-agenda-show-scroll-down ()
  8137. "Scroll down the window showing the agenda."
  8138. (interactive)
  8139. (let ((win (selected-window)))
  8140. (when (window-live-p org-agenda-show-window)
  8141. (select-window org-agenda-show-window)
  8142. (ignore-errors (scroll-down))
  8143. (select-window win))))
  8144. (defun org-agenda-show-1 (&optional more)
  8145. "Display the Org file which contains the item at point.
  8146. The prefix arg selects the amount of information to display:
  8147. 0 hide the subtree
  8148. 1 just show the entry according to defaults.
  8149. 2 show the children view
  8150. 3 show the subtree view
  8151. 4 show the entire subtree and any LOGBOOK drawers
  8152. 5 show the entire subtree and any drawers
  8153. With prefix argument FULL-ENTRY, make the entire entry visible
  8154. if it was hidden in the outline."
  8155. (interactive "p")
  8156. (let ((win (selected-window)))
  8157. (org-agenda-goto t)
  8158. (org-back-to-heading)
  8159. (set-window-start (selected-window) (point-at-bol))
  8160. (cond
  8161. ((= more 0)
  8162. (outline-hide-subtree)
  8163. (save-excursion
  8164. (org-back-to-heading)
  8165. (run-hook-with-args 'org-cycle-hook 'folded))
  8166. (message "Remote: FOLDED"))
  8167. ((and (called-interactively-p 'any) (= more 1))
  8168. (message "Remote: show with default settings"))
  8169. ((= more 2)
  8170. (outline-show-entry)
  8171. (org-show-children)
  8172. (save-excursion
  8173. (org-back-to-heading)
  8174. (run-hook-with-args 'org-cycle-hook 'children))
  8175. (message "Remote: CHILDREN"))
  8176. ((= more 3)
  8177. (outline-show-subtree)
  8178. (save-excursion
  8179. (org-back-to-heading)
  8180. (run-hook-with-args 'org-cycle-hook 'subtree))
  8181. (message "Remote: SUBTREE"))
  8182. ((= more 4)
  8183. (outline-show-subtree)
  8184. (save-excursion
  8185. (org-back-to-heading)
  8186. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8187. (message "Remote: SUBTREE AND LOGBOOK"))
  8188. ((> more 4)
  8189. (outline-show-subtree)
  8190. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8191. (select-window win)))
  8192. (defvar org-agenda-cycle-counter nil)
  8193. (defun org-agenda-cycle-show (&optional n)
  8194. "Show the current entry in another window, with default settings.
  8195. Default settings are taken from `org-show-context-detail'. When
  8196. use repeatedly in immediate succession, the remote entry will
  8197. cycle through visibility
  8198. children -> subtree -> folded
  8199. When called with a numeric prefix arg, that arg will be passed through to
  8200. `org-agenda-show-1'. For the interpretation of that argument, see the
  8201. docstring of `org-agenda-show-1'."
  8202. (interactive "P")
  8203. (if (integerp n)
  8204. (setq org-agenda-cycle-counter n)
  8205. (if (not (eq last-command this-command))
  8206. (setq org-agenda-cycle-counter 1)
  8207. (if (equal org-agenda-cycle-counter 0)
  8208. (setq org-agenda-cycle-counter 2)
  8209. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8210. (if (> org-agenda-cycle-counter 3)
  8211. (setq org-agenda-cycle-counter 0)))))
  8212. (org-agenda-show-1 org-agenda-cycle-counter))
  8213. (defun org-agenda-recenter (arg)
  8214. "Display the Org file which contains the item at point and recenter."
  8215. (interactive "P")
  8216. (let ((win (selected-window)))
  8217. (org-agenda-goto t)
  8218. (recenter arg)
  8219. (select-window win)))
  8220. (defun org-agenda-show-mouse (ev)
  8221. "Display the Org file which contains the item at the mouse click."
  8222. (interactive "e")
  8223. (mouse-set-point ev)
  8224. (org-agenda-show))
  8225. (defun org-agenda-check-no-diary ()
  8226. "Check if the entry is a diary link and abort if yes."
  8227. (if (org-get-at-bol 'org-agenda-diary-link)
  8228. (org-agenda-error)))
  8229. (defun org-agenda-error ()
  8230. "Throw an error when a command is not allowed in the agenda."
  8231. (user-error "Command not allowed in this line"))
  8232. (defun org-agenda-tree-to-indirect-buffer (arg)
  8233. "Show the subtree corresponding to the current entry in an indirect buffer.
  8234. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8235. With a numerical prefix ARG, go up to this level and then take that tree.
  8236. With a negative numeric ARG, go up by this number of levels.
  8237. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8238. i.e. don't use
  8239. the dedicated frame."
  8240. (interactive "P")
  8241. (if current-prefix-arg
  8242. (org-agenda-do-tree-to-indirect-buffer arg)
  8243. (let ((agenda-buffer (buffer-name))
  8244. (agenda-window (selected-window))
  8245. (indirect-window
  8246. (and org-last-indirect-buffer
  8247. (get-buffer-window org-last-indirect-buffer))))
  8248. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8249. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8250. (eq org-indirect-buffer-display 'dedicated-frame))
  8251. (unwind-protect
  8252. (unless (and indirect-window (window-live-p indirect-window))
  8253. (setq indirect-window (split-window agenda-window)))
  8254. (and indirect-window (select-window indirect-window))
  8255. (switch-to-buffer org-last-indirect-buffer :norecord)
  8256. (fit-window-to-buffer indirect-window)))
  8257. (select-window (get-buffer-window agenda-buffer))
  8258. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8259. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8260. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8261. (org-agenda-check-no-diary)
  8262. (let* ((marker (or (org-get-at-bol 'org-marker)
  8263. (org-agenda-error)))
  8264. (buffer (marker-buffer marker))
  8265. (pos (marker-position marker)))
  8266. (with-current-buffer buffer
  8267. (save-excursion
  8268. (goto-char pos)
  8269. (funcall 'org-tree-to-indirect-buffer arg)))))
  8270. (defvar org-last-heading-marker (make-marker)
  8271. "Marker pointing to the headline that last changed its TODO state
  8272. by a remote command from the agenda.")
  8273. (defun org-agenda-todo-nextset ()
  8274. "Switch TODO entry to next sequence."
  8275. (interactive)
  8276. (org-agenda-todo 'nextset))
  8277. (defun org-agenda-todo-previousset ()
  8278. "Switch TODO entry to previous sequence."
  8279. (interactive)
  8280. (org-agenda-todo 'previousset))
  8281. (defun org-agenda-todo (&optional arg)
  8282. "Cycle TODO state of line at point, also in Org file.
  8283. This changes the line at point, all other lines in the agenda referring to
  8284. the same tree node, and the headline of the tree node in the Org file."
  8285. (interactive "P")
  8286. (org-agenda-check-no-diary)
  8287. (let* ((col (current-column))
  8288. (marker (or (org-get-at-bol 'org-marker)
  8289. (org-agenda-error)))
  8290. (buffer (marker-buffer marker))
  8291. (pos (marker-position marker))
  8292. (hdmarker (org-get-at-bol 'org-hd-marker))
  8293. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8294. (inhibit-read-only t)
  8295. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8296. (org-with-remote-undo buffer
  8297. (with-current-buffer buffer
  8298. (widen)
  8299. (goto-char pos)
  8300. (org-show-context 'agenda)
  8301. (let ((current-prefix-arg arg))
  8302. (call-interactively 'org-todo))
  8303. (and (bolp) (forward-char 1))
  8304. (setq newhead (org-get-heading))
  8305. (when (and (bound-and-true-p
  8306. org-agenda-headline-snapshot-before-repeat)
  8307. (not (equal org-agenda-headline-snapshot-before-repeat
  8308. newhead))
  8309. todayp)
  8310. (setq newhead org-agenda-headline-snapshot-before-repeat
  8311. just-one t))
  8312. (save-excursion
  8313. (org-back-to-heading)
  8314. (move-marker org-last-heading-marker (point))))
  8315. (beginning-of-line 1)
  8316. (save-window-excursion
  8317. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8318. (when (bound-and-true-p org-clock-out-when-done)
  8319. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8320. newhead)
  8321. (org-agenda-unmark-clocking-task))
  8322. (org-move-to-column col)
  8323. (org-agenda-mark-clocking-task))))
  8324. (defun org-agenda-add-note (&optional arg)
  8325. "Add a time-stamped note to the entry at point."
  8326. (interactive "P")
  8327. (org-agenda-check-no-diary)
  8328. (let* ((marker (or (org-get-at-bol 'org-marker)
  8329. (org-agenda-error)))
  8330. (buffer (marker-buffer marker))
  8331. (pos (marker-position marker))
  8332. (hdmarker (org-get-at-bol 'org-hd-marker))
  8333. (inhibit-read-only t))
  8334. (with-current-buffer buffer
  8335. (widen)
  8336. (goto-char pos)
  8337. (org-show-context 'agenda)
  8338. (org-add-note))))
  8339. (defun org-agenda-change-all-lines (newhead hdmarker
  8340. &optional fixface just-this)
  8341. "Change all lines in the agenda buffer which match HDMARKER.
  8342. The new content of the line will be NEWHEAD (as modified by
  8343. `org-agenda-format-item'). HDMARKER is checked with
  8344. `equal' against all `org-hd-marker' text properties in the file.
  8345. If FIXFACE is non-nil, the face of each item is modified according to
  8346. the new TODO state.
  8347. If JUST-THIS is non-nil, change just the current line, not all.
  8348. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8349. (let* ((inhibit-read-only t)
  8350. (line (org-current-line))
  8351. (org-agenda-buffer (current-buffer))
  8352. (thetags (with-current-buffer (marker-buffer hdmarker)
  8353. (org-with-wide-buffer
  8354. (goto-char hdmarker)
  8355. (org-get-tags-at))))
  8356. props m pl undone-face done-face finish new dotime level cat tags)
  8357. (save-excursion
  8358. (goto-char (point-max))
  8359. (beginning-of-line 1)
  8360. (while (not finish)
  8361. (setq finish (bobp))
  8362. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8363. (or (not just-this) (= (org-current-line) line))
  8364. (equal m hdmarker))
  8365. (setq props (text-properties-at (point))
  8366. dotime (org-get-at-bol 'dotime)
  8367. cat (org-get-at-eol 'org-category 1)
  8368. level (org-get-at-bol 'level)
  8369. tags thetags
  8370. new
  8371. (let ((org-prefix-format-compiled
  8372. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8373. org-prefix-format-compiled))
  8374. (extra (org-get-at-bol 'extra)))
  8375. (with-current-buffer (marker-buffer hdmarker)
  8376. (org-with-wide-buffer
  8377. (org-agenda-format-item extra newhead level cat tags dotime))))
  8378. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8379. undone-face (org-get-at-bol 'undone-face)
  8380. done-face (org-get-at-bol 'done-face))
  8381. (beginning-of-line 1)
  8382. (cond
  8383. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8384. ((looking-at ".*")
  8385. ;; When replacing the whole line, preserve bulk mark
  8386. ;; overlay, if any.
  8387. (let ((mark (catch :overlay
  8388. (dolist (o (overlays-in (point) (+ 2 (point))))
  8389. (when (eq (overlay-get o 'type)
  8390. 'org-marked-entry-overlay)
  8391. (throw :overlay o))))))
  8392. (replace-match new t t)
  8393. (beginning-of-line)
  8394. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8395. (add-text-properties (point-at-bol) (point-at-eol) props)
  8396. (when fixface
  8397. (add-text-properties
  8398. (point-at-bol) (point-at-eol)
  8399. (list 'face
  8400. (if org-last-todo-state-is-todo
  8401. undone-face done-face))))
  8402. (org-agenda-highlight-todo 'line)
  8403. (beginning-of-line 1))
  8404. (t (error "Line update did not work")))
  8405. (save-restriction
  8406. (narrow-to-region (point-at-bol) (point-at-eol))
  8407. (org-agenda-finalize)))
  8408. (beginning-of-line 0)))))
  8409. (defun org-agenda-align-tags (&optional line)
  8410. "Align all tags in agenda items to `org-agenda-tags-column'."
  8411. (let ((inhibit-read-only t) l c)
  8412. (save-excursion
  8413. (goto-char (if line (point-at-bol) (point-min)))
  8414. (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
  8415. (if line (point-at-eol) nil) t)
  8416. (add-text-properties
  8417. (match-beginning 2) (match-end 2)
  8418. (list 'face (delq nil (let ((prop (get-text-property
  8419. (match-beginning 2) 'face)))
  8420. (or (listp prop) (setq prop (list prop)))
  8421. (if (memq 'org-tag prop)
  8422. prop
  8423. (cons 'org-tag prop))))))
  8424. (setq l (- (match-end 2) (match-beginning 2))
  8425. c (if (< org-agenda-tags-column 0)
  8426. (- (abs org-agenda-tags-column) l)
  8427. org-agenda-tags-column))
  8428. (delete-region (match-beginning 1) (match-end 1))
  8429. (goto-char (match-beginning 1))
  8430. (insert (org-add-props
  8431. (make-string (max 1 (- c (current-column))) ?\ )
  8432. (plist-put (copy-sequence (text-properties-at (point)))
  8433. 'face nil))))
  8434. (goto-char (point-min))
  8435. (org-font-lock-add-tag-faces (point-max)))))
  8436. (defun org-agenda-priority-up ()
  8437. "Increase the priority of line at point, also in Org file."
  8438. (interactive)
  8439. (org-agenda-priority 'up))
  8440. (defun org-agenda-priority-down ()
  8441. "Decrease the priority of line at point, also in Org file."
  8442. (interactive)
  8443. (org-agenda-priority 'down))
  8444. (defun org-agenda-priority (&optional force-direction)
  8445. "Set the priority of line at point, also in Org file.
  8446. This changes the line at point, all other lines in the agenda referring to
  8447. the same tree node, and the headline of the tree node in the Org file.
  8448. Called with a universal prefix arg, show the priority instead of setting it."
  8449. (interactive "P")
  8450. (if (equal force-direction '(4))
  8451. (org-show-priority)
  8452. (unless org-enable-priority-commands
  8453. (error "Priority commands are disabled"))
  8454. (org-agenda-check-no-diary)
  8455. (let* ((col (current-column))
  8456. (marker (or (org-get-at-bol 'org-marker)
  8457. (org-agenda-error)))
  8458. (hdmarker (org-get-at-bol 'org-hd-marker))
  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. (funcall 'org-priority force-direction)
  8469. (end-of-line 1)
  8470. (setq newhead (org-get-heading)))
  8471. (org-agenda-change-all-lines newhead hdmarker)
  8472. (org-move-to-column col)))))
  8473. ;; FIXME: should fix the tags property of the agenda line.
  8474. (defun org-agenda-set-tags (&optional tag onoff)
  8475. "Set tags for the current headline."
  8476. (interactive)
  8477. (org-agenda-check-no-diary)
  8478. (if (and (org-region-active-p) (called-interactively-p 'any))
  8479. (call-interactively 'org-change-tag-in-region)
  8480. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8481. (org-agenda-error)))
  8482. (buffer (marker-buffer hdmarker))
  8483. (pos (marker-position hdmarker))
  8484. (inhibit-read-only t)
  8485. newhead)
  8486. (org-with-remote-undo buffer
  8487. (with-current-buffer buffer
  8488. (widen)
  8489. (goto-char pos)
  8490. (org-show-context 'agenda)
  8491. (if tag
  8492. (org-toggle-tag tag onoff)
  8493. (call-interactively 'org-set-tags))
  8494. (end-of-line 1)
  8495. (setq newhead (org-get-heading)))
  8496. (org-agenda-change-all-lines newhead hdmarker)
  8497. (beginning-of-line 1)))))
  8498. (defun org-agenda-set-property ()
  8499. "Set a property for the current headline."
  8500. (interactive)
  8501. (org-agenda-check-no-diary)
  8502. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8503. (org-agenda-error)))
  8504. (buffer (marker-buffer hdmarker))
  8505. (pos (marker-position hdmarker))
  8506. (inhibit-read-only t)
  8507. newhead)
  8508. (org-with-remote-undo buffer
  8509. (with-current-buffer buffer
  8510. (widen)
  8511. (goto-char pos)
  8512. (org-show-context 'agenda)
  8513. (call-interactively 'org-set-property)))))
  8514. (defun org-agenda-set-effort ()
  8515. "Set the effort property for the current headline."
  8516. (interactive)
  8517. (org-agenda-check-no-diary)
  8518. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8519. (org-agenda-error)))
  8520. (buffer (marker-buffer hdmarker))
  8521. (pos (marker-position hdmarker))
  8522. (inhibit-read-only t)
  8523. newhead)
  8524. (org-with-remote-undo buffer
  8525. (with-current-buffer buffer
  8526. (widen)
  8527. (goto-char pos)
  8528. (org-show-context 'agenda)
  8529. (call-interactively 'org-set-effort)
  8530. (end-of-line 1)
  8531. (setq newhead (org-get-heading)))
  8532. (org-agenda-change-all-lines newhead hdmarker))))
  8533. (defun org-agenda-toggle-archive-tag ()
  8534. "Toggle the archive tag for the current entry."
  8535. (interactive)
  8536. (org-agenda-check-no-diary)
  8537. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8538. (org-agenda-error)))
  8539. (buffer (marker-buffer hdmarker))
  8540. (pos (marker-position hdmarker))
  8541. (inhibit-read-only t)
  8542. newhead)
  8543. (org-with-remote-undo buffer
  8544. (with-current-buffer buffer
  8545. (widen)
  8546. (goto-char pos)
  8547. (org-show-context 'agenda)
  8548. (call-interactively 'org-toggle-archive-tag)
  8549. (end-of-line 1)
  8550. (setq newhead (org-get-heading)))
  8551. (org-agenda-change-all-lines newhead hdmarker)
  8552. (beginning-of-line 1))))
  8553. (defun org-agenda-do-date-later (arg)
  8554. (interactive "P")
  8555. (cond
  8556. ((or (equal arg '(16))
  8557. (memq last-command
  8558. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8559. (setq this-command 'org-agenda-date-later-minutes)
  8560. (org-agenda-date-later-minutes 1))
  8561. ((or (equal arg '(4))
  8562. (memq last-command
  8563. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8564. (setq this-command 'org-agenda-date-later-hours)
  8565. (org-agenda-date-later-hours 1))
  8566. (t
  8567. (org-agenda-date-later (prefix-numeric-value arg)))))
  8568. (defun org-agenda-do-date-earlier (arg)
  8569. (interactive "P")
  8570. (cond
  8571. ((or (equal arg '(16))
  8572. (memq last-command
  8573. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8574. (setq this-command 'org-agenda-date-earlier-minutes)
  8575. (org-agenda-date-earlier-minutes 1))
  8576. ((or (equal arg '(4))
  8577. (memq last-command
  8578. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8579. (setq this-command 'org-agenda-date-earlier-hours)
  8580. (org-agenda-date-earlier-hours 1))
  8581. (t
  8582. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8583. (defun org-agenda-date-later (arg &optional what)
  8584. "Change the date of this item to ARG day(s) later."
  8585. (interactive "p")
  8586. (org-agenda-check-type t 'agenda 'timeline)
  8587. (org-agenda-check-no-diary)
  8588. (let* ((marker (or (org-get-at-bol 'org-marker)
  8589. (org-agenda-error)))
  8590. (buffer (marker-buffer marker))
  8591. (pos (marker-position marker))
  8592. cdate today)
  8593. (org-with-remote-undo buffer
  8594. (with-current-buffer buffer
  8595. (widen)
  8596. (goto-char pos)
  8597. (if (not (org-at-timestamp-p))
  8598. (error "Cannot find time stamp"))
  8599. (when (and org-agenda-move-date-from-past-immediately-to-today
  8600. (equal arg 1)
  8601. (or (not what) (eq what 'day))
  8602. (not (save-match-data (org-at-date-range-p))))
  8603. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8604. cdate (calendar-absolute-from-gregorian
  8605. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8606. today (org-today))
  8607. (if (> today cdate)
  8608. ;; immediately shift to today
  8609. (setq arg (- today cdate))))
  8610. (org-timestamp-change arg (or what 'day))
  8611. (when (and (org-at-date-range-p)
  8612. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8613. (let ((end org-last-changed-timestamp))
  8614. (org-timestamp-change arg (or what 'day))
  8615. (setq org-last-changed-timestamp
  8616. (concat org-last-changed-timestamp "--" end)))))
  8617. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8618. (message &