org-agenda.el 397 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277
  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 to write the produced agenda buffer to with
  426. 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 takes precedence 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 "26.1"
  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 t"]
  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-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-links (point-max))
  3381. (add-text-properties (match-beginning 0) (match-end 0)
  3382. '(face org-link))))
  3383. (unless (eq org-agenda-remove-tags t)
  3384. (org-agenda-align-tags))
  3385. (unless org-agenda-with-colors
  3386. (remove-text-properties (point-min) (point-max) '(face nil)))
  3387. (if (and (boundp 'org-agenda-overriding-columns-format)
  3388. org-agenda-overriding-columns-format)
  3389. (setq-local org-agenda-overriding-columns-format
  3390. org-agenda-overriding-columns-format))
  3391. (if (and (boundp 'org-agenda-view-columns-initially)
  3392. org-agenda-view-columns-initially)
  3393. (org-agenda-columns))
  3394. (when org-agenda-fontify-priorities
  3395. (org-agenda-fontify-priorities))
  3396. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3397. (org-agenda-dim-blocked-tasks))
  3398. (org-agenda-mark-clocking-task)
  3399. (when org-agenda-entry-text-mode
  3400. (org-agenda-entry-text-hide)
  3401. (org-agenda-entry-text-show))
  3402. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3403. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3404. (org-habit-insert-consistency-graphs))
  3405. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3406. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3407. (and (listp org-agenda-show-inherited-tags)
  3408. (memq org-agenda-type org-agenda-show-inherited-tags))
  3409. (and (eq org-agenda-show-inherited-tags t)
  3410. (or (eq org-agenda-use-tag-inheritance t)
  3411. (and (listp org-agenda-use-tag-inheritance)
  3412. (not (memq org-agenda-type
  3413. org-agenda-use-tag-inheritance))))))
  3414. (let (mrk)
  3415. (save-excursion
  3416. (goto-char (point-min))
  3417. (while (equal (forward-line) 0)
  3418. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3419. (put-text-property (point-at-bol) (point-at-eol)
  3420. 'tags (org-with-point-at mrk
  3421. (delete-dups
  3422. (mapcar 'downcase (org-get-tags-at))))))))))
  3423. (run-hooks 'org-agenda-finalize-hook)
  3424. (when org-agenda-top-headline-filter
  3425. (org-agenda-filter-top-headline-apply
  3426. org-agenda-top-headline-filter))
  3427. (when org-agenda-tag-filter
  3428. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3429. (when (get 'org-agenda-tag-filter :preset-filter)
  3430. (org-agenda-filter-apply
  3431. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3432. (when org-agenda-category-filter
  3433. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3434. (when (get 'org-agenda-category-filter :preset-filter)
  3435. (org-agenda-filter-apply
  3436. (get 'org-agenda-category-filter :preset-filter) 'category))
  3437. (when org-agenda-regexp-filter
  3438. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3439. (when (get 'org-agenda-regexp-filter :preset-filter)
  3440. (org-agenda-filter-apply
  3441. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3442. (when org-agenda-effort-filter
  3443. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3444. (when (get 'org-agenda-effort-filter :preset-filter)
  3445. (org-agenda-filter-apply
  3446. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3447. (add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3448. (defun org-agenda-mark-clocking-task ()
  3449. "Mark the current clock entry in the agenda if it is present."
  3450. ;; We need to widen when `org-agenda-finalize' is called from
  3451. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3452. (when (bound-and-true-p org-clock-current-task)
  3453. (save-restriction
  3454. (widen)
  3455. (org-agenda-unmark-clocking-task)
  3456. (when (marker-buffer org-clock-hd-marker)
  3457. (save-excursion
  3458. (goto-char (point-min))
  3459. (let (s ov)
  3460. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3461. (goto-char s)
  3462. (when (equal (org-get-at-bol 'org-hd-marker)
  3463. org-clock-hd-marker)
  3464. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3465. (overlay-put ov 'type 'org-agenda-clocking)
  3466. (overlay-put ov 'face 'org-agenda-clocking)
  3467. (overlay-put ov 'help-echo
  3468. "The clock is running in this item")))))))))
  3469. (defun org-agenda-unmark-clocking-task ()
  3470. "Unmark the current clocking task."
  3471. (mapc (lambda (o)
  3472. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3473. (delete-overlay o)))
  3474. (overlays-in (point-min) (point-max))))
  3475. (defun org-agenda-fontify-priorities ()
  3476. "Make highest priority lines bold, and lowest italic."
  3477. (interactive)
  3478. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3479. (delete-overlay o)))
  3480. (overlays-in (point-min) (point-max)))
  3481. (save-excursion
  3482. (let (b e p ov h l)
  3483. (goto-char (point-min))
  3484. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3485. (setq h (or (get-char-property (point) 'org-highest-priority)
  3486. org-highest-priority)
  3487. l (or (get-char-property (point) 'org-lowest-priority)
  3488. org-lowest-priority)
  3489. p (string-to-char (match-string 1))
  3490. b (match-beginning 0)
  3491. e (if (eq org-agenda-fontify-priorities 'cookies)
  3492. (match-end 0)
  3493. (point-at-eol))
  3494. ov (make-overlay b e))
  3495. (overlay-put
  3496. ov 'face
  3497. (let ((special-face
  3498. (cond ((org-face-from-face-or-color
  3499. 'priority 'org-priority
  3500. (cdr (assoc p org-priority-faces))))
  3501. ((and (listp org-agenda-fontify-priorities)
  3502. (org-face-from-face-or-color
  3503. 'priority 'org-priority
  3504. (cdr (assoc p org-agenda-fontify-priorities)))))
  3505. ((equal p l) 'italic)
  3506. ((equal p h) 'bold))))
  3507. (if special-face (list special-face 'org-priority) 'org-priority)))
  3508. (overlay-put ov 'org-type 'org-priority)))))
  3509. (defvar org-depend-tag-blocked)
  3510. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3511. "Dim currently blocked TODOs in the agenda display.
  3512. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3513. dimming them."
  3514. (interactive "P")
  3515. (when (called-interactively-p 'interactive)
  3516. (message "Dim or hide blocked tasks..."))
  3517. (dolist (o (overlays-in (point-min) (point-max)))
  3518. (when (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3519. (delete-overlay o)))
  3520. (save-excursion
  3521. (let ((inhibit-read-only t)
  3522. (org-depend-tag-blocked nil)
  3523. org-blocked-by-checkboxes)
  3524. (goto-char (point-min))
  3525. (while (let ((pos (text-property-not-all
  3526. (point) (point-max) 'todo-state nil)))
  3527. (when pos (goto-char pos)))
  3528. (setq org-blocked-by-checkboxes nil)
  3529. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3530. (when (and (markerp marker)
  3531. (with-current-buffer (marker-buffer marker)
  3532. (save-excursion (goto-char marker)
  3533. (org-entry-blocked-p))))
  3534. ;; Entries blocked by checkboxes cannot be made invisible.
  3535. ;; See `org-agenda-dim-blocked-tasks' for details.
  3536. (let* ((really-invisible
  3537. (and (not org-blocked-by-checkboxes)
  3538. (or invisible (eq org-agenda-dim-blocked-tasks
  3539. 'invisible))))
  3540. (ov (make-overlay (if really-invisible (line-end-position 0)
  3541. (line-beginning-position))
  3542. (line-end-position))))
  3543. (if really-invisible (overlay-put ov 'invisible t)
  3544. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3545. (overlay-put ov 'org-type 'org-blocked-todo))))
  3546. (forward-line))))
  3547. (when (called-interactively-p 'interactive)
  3548. (message "Dim or hide blocked tasks...done")))
  3549. (defvar org-agenda-skip-function nil
  3550. "Function to be called at each match during agenda construction.
  3551. If this function returns nil, the current match should not be skipped.
  3552. Otherwise, the function must return a position from where the search
  3553. should be continued.
  3554. This may also be a Lisp form, it will be evaluated.
  3555. Never set this variable using `setq' or so, because then it will apply
  3556. to all future agenda commands. If you do want a global skipping condition,
  3557. use the option `org-agenda-skip-function-global' instead.
  3558. The correct usage for `org-agenda-skip-function' is to bind it with
  3559. `let' to scope it dynamically into the agenda-constructing command.
  3560. A good way to set it is through options in `org-agenda-custom-commands'.")
  3561. (defun org-agenda-skip ()
  3562. "Throw to `:skip' in places that should be skipped.
  3563. Also moves point to the end of the skipped region, so that search can
  3564. continue from there."
  3565. (let ((p (point-at-bol)) to)
  3566. (when (or
  3567. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3568. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3569. (get-text-property p :org-archived)
  3570. (org-end-of-subtree t))
  3571. (and org-agenda-skip-comment-trees
  3572. (get-text-property p :org-comment)
  3573. (org-end-of-subtree t))
  3574. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3575. (org-agenda-skip-eval org-agenda-skip-function)))
  3576. (goto-char to))
  3577. (org-in-src-block-p t))
  3578. (throw :skip t))))
  3579. (defun org-agenda-skip-eval (form)
  3580. "If FORM is a function or a list, call (or eval) it and return the result.
  3581. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3582. and match data are returned to the previous state no matter what these
  3583. functions do."
  3584. (let (fp)
  3585. (and form
  3586. (or (setq fp (functionp form))
  3587. (consp form))
  3588. (save-excursion
  3589. (save-match-data
  3590. (if fp
  3591. (funcall form)
  3592. (eval form)))))))
  3593. (defvar org-agenda-markers nil
  3594. "List of all currently active markers created by `org-agenda'.")
  3595. (defvar org-agenda-last-marker-time (float-time)
  3596. "Creation time of the last agenda marker.")
  3597. (defun org-agenda-new-marker (&optional pos)
  3598. "Return a new agenda marker.
  3599. Maker is at point, or at POS if non-nil. Org mode keeps a list of
  3600. these markers and resets them when they are no longer in use."
  3601. (let ((m (copy-marker (or pos (point)) t)))
  3602. (setq org-agenda-last-marker-time (float-time))
  3603. (if org-agenda-buffer
  3604. (with-current-buffer org-agenda-buffer
  3605. (push m org-agenda-markers))
  3606. (push m org-agenda-markers))
  3607. m))
  3608. (defun org-agenda-reset-markers ()
  3609. "Reset markers created by `org-agenda'."
  3610. (while org-agenda-markers
  3611. (move-marker (pop org-agenda-markers) nil)))
  3612. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3613. "Save relative positions of markers in region.
  3614. This check for agenda markers in all agenda buffers currently active."
  3615. (dolist (buf (buffer-list))
  3616. (with-current-buffer buf
  3617. (when (eq major-mode 'org-agenda-mode)
  3618. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3619. org-agenda-markers)))))
  3620. ;;; Entry text mode
  3621. (defun org-agenda-entry-text-show-here ()
  3622. "Add some text from the entry as context to the current line."
  3623. (let (m txt o)
  3624. (setq m (org-get-at-bol 'org-hd-marker))
  3625. (unless (marker-buffer m)
  3626. (error "No marker points to an entry here"))
  3627. (setq txt (concat "\n" (org-no-properties
  3628. (org-agenda-get-some-entry-text
  3629. m org-agenda-entry-text-maxlines
  3630. org-agenda-entry-text-leaders))))
  3631. (when (string-match "\\S-" txt)
  3632. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3633. (overlay-put o 'evaporate t)
  3634. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3635. (overlay-put o 'after-string txt))))
  3636. (defun org-agenda-entry-text-show ()
  3637. "Add entry context for all agenda lines."
  3638. (interactive)
  3639. (save-excursion
  3640. (goto-char (point-max))
  3641. (beginning-of-line 1)
  3642. (while (not (bobp))
  3643. (when (org-get-at-bol 'org-hd-marker)
  3644. (org-agenda-entry-text-show-here))
  3645. (beginning-of-line 0))))
  3646. (defun org-agenda-entry-text-hide ()
  3647. "Remove any shown entry context."
  3648. (delq nil
  3649. (mapcar (lambda (o)
  3650. (if (eq (overlay-get o 'org-overlay-type)
  3651. 'agenda-entry-content)
  3652. (progn (delete-overlay o) t)))
  3653. (overlays-in (point-min) (point-max)))))
  3654. (defun org-agenda-get-day-face (date)
  3655. "Return the face DATE should be displayed with."
  3656. (cond ((and (functionp org-agenda-day-face-function)
  3657. (funcall org-agenda-day-face-function date)))
  3658. ((org-agenda-today-p date) 'org-agenda-date-today)
  3659. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3660. 'org-agenda-date-weekend)
  3661. (t 'org-agenda-date)))
  3662. ;;; Agenda timeline
  3663. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3664. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3665. (defun org-timeline (&optional dotodo)
  3666. "Show a time-sorted view of the entries in the current Org file.
  3667. Only entries with a time stamp of today or later will be listed.
  3668. With `\\[universal-argument]' prefix, all unfinished TODO items will also be \
  3669. shown,
  3670. under the current date.
  3671. If the buffer contains an active region, only check the region
  3672. for dates."
  3673. (interactive "P")
  3674. (let* ((dopast t)
  3675. (org-agenda-show-log-scoped org-agenda-show-log)
  3676. (org-agenda-show-log org-agenda-show-log-scoped)
  3677. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3678. (current-buffer))))
  3679. (date (calendar-current-date))
  3680. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3681. (end (if (org-region-active-p) (region-end) (point-max)))
  3682. (day-numbers (org-get-all-dates
  3683. beg end 'no-ranges
  3684. t org-agenda-show-log-scoped ; always include today
  3685. org-timeline-show-empty-dates))
  3686. (org-deadline-warning-days 0)
  3687. (org-agenda-only-exact-dates t)
  3688. (today (org-today))
  3689. (past t)
  3690. args
  3691. s e rtn d emptyp)
  3692. (setq org-agenda-redo-command
  3693. (list 'let
  3694. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3695. (list 'org-switch-to-buffer-other-window (current-buffer))
  3696. (list 'org-timeline (list 'quote dotodo))))
  3697. (put 'org-agenda-redo-command 'org-lprops nil)
  3698. (if (not dopast)
  3699. ;; Remove past dates from the list of dates.
  3700. (setq day-numbers (delq nil (mapcar (lambda(x)
  3701. (if (>= x today) x nil))
  3702. day-numbers))))
  3703. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3704. (org-compile-prefix-format 'timeline)
  3705. (org-set-sorting-strategy 'timeline)
  3706. (if org-agenda-show-log-scoped (push :closed args))
  3707. (push :timestamp args)
  3708. (push :deadline args)
  3709. (push :scheduled args)
  3710. (push :sexp args)
  3711. (if dotodo (push :todo args))
  3712. (insert "Timeline of file " entry "\n")
  3713. (add-text-properties (point-min) (point)
  3714. (list 'face 'org-agenda-structure))
  3715. (org-agenda-mark-header-line (point-min))
  3716. (while (setq d (pop day-numbers))
  3717. (if (and (listp d) (eq (car d) :omitted))
  3718. (progn
  3719. (setq s (point))
  3720. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3721. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3722. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3723. (if (and (>= d today)
  3724. dopast
  3725. past)
  3726. (progn
  3727. (setq past nil)
  3728. (insert (make-string 79 ?-) "\n")))
  3729. (setq date (calendar-gregorian-from-absolute d))
  3730. (setq s (point))
  3731. (setq rtn (and (not emptyp)
  3732. (apply 'org-agenda-get-day-entries entry
  3733. date args)))
  3734. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3735. (progn
  3736. (insert
  3737. (if (stringp org-agenda-format-date)
  3738. (format-time-string org-agenda-format-date
  3739. (org-time-from-absolute date))
  3740. (funcall org-agenda-format-date date))
  3741. "\n")
  3742. (put-text-property s (1- (point)) 'face
  3743. (org-agenda-get-day-face date))
  3744. (put-text-property s (1- (point)) 'org-date-line t)
  3745. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3746. (if (equal d today)
  3747. (put-text-property s (1- (point)) 'org-today t))
  3748. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3749. (put-text-property s (1- (point)) 'day d)))))
  3750. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3751. (point-min)))
  3752. (add-text-properties
  3753. (point-min) (point-max)
  3754. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3755. (org-agenda-finalize)
  3756. (setq buffer-read-only t)))
  3757. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3758. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3759. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3760. not every single day in the range. If FORCE-TODAY is non-nil, make
  3761. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3762. inactive time stamps (those in square brackets) are included.
  3763. When EMPTY is non-nil, also include days without any entries."
  3764. (let ((re (concat
  3765. (if pre-re pre-re "")
  3766. (if inactive org-ts-regexp-both org-ts-regexp)))
  3767. dates dates1 date day day1 day2 ts1 ts2 pos)
  3768. (if force-today
  3769. (setq dates (list (org-today))))
  3770. (save-excursion
  3771. (goto-char beg)
  3772. (while (re-search-forward re end t)
  3773. (setq day (time-to-days (org-time-string-to-time
  3774. (substring (match-string 1) 0 10)
  3775. (current-buffer) (match-beginning 0))))
  3776. (or (memq day dates) (push day dates)))
  3777. (unless no-ranges
  3778. (goto-char beg)
  3779. (while (re-search-forward org-tr-regexp end t)
  3780. (setq pos (match-beginning 0))
  3781. (setq ts1 (substring (match-string 1) 0 10)
  3782. ts2 (substring (match-string 2) 0 10)
  3783. day1 (time-to-days (org-time-string-to-time
  3784. ts1 (current-buffer) pos))
  3785. day2 (time-to-days (org-time-string-to-time
  3786. ts2 (current-buffer) pos)))
  3787. (while (< (setq day1 (1+ day1)) day2)
  3788. (or (memq day1 dates) (push day1 dates)))))
  3789. (setq dates (sort dates '<))
  3790. (when empty
  3791. (while (setq day (pop dates))
  3792. (setq day2 (car dates))
  3793. (push day dates1)
  3794. (when (and day2 empty)
  3795. (if (or (eq empty t)
  3796. (and (numberp empty) (<= (- day2 day) empty)))
  3797. (while (< (setq day (1+ day)) day2)
  3798. (push (list day) dates1))
  3799. (push (cons :omitted (- day2 day)) dates1))))
  3800. (setq dates (nreverse dates1)))
  3801. dates)))
  3802. ;;; Agenda Daily/Weekly
  3803. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3804. "Start day for the agenda view.
  3805. Custom commands can set this variable in the options section.
  3806. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3807. input allowed when reading a date through the Org calendar.
  3808. See the docstring of `org-read-date' for details.")
  3809. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3810. (defvar org-arg-loc nil) ; local variable
  3811. (defvar org-agenda-buffer-tmp-name nil)
  3812. ;;;###autoload
  3813. (defun org-agenda-list (&optional arg start-day span with-hour)
  3814. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3815. The view will be for the current day or week, but from the overview buffer
  3816. you will be able to go to other days/weeks.
  3817. With a numeric prefix argument in an interactive call, the agenda will
  3818. span ARG days. Lisp programs should instead specify SPAN to change
  3819. the number of days. SPAN defaults to `org-agenda-span'.
  3820. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3821. given in `org-agenda-start-on-weekday'.
  3822. When WITH-HOUR is non-nil, only include scheduled and deadline
  3823. items if they have an hour specification like [h]h:mm."
  3824. (interactive "P")
  3825. (if org-agenda-overriding-arguments
  3826. (setq arg (car org-agenda-overriding-arguments)
  3827. start-day (nth 1 org-agenda-overriding-arguments)
  3828. span (nth 2 org-agenda-overriding-arguments)))
  3829. (if (and (integerp arg) (> arg 0))
  3830. (setq span arg arg nil))
  3831. (catch 'exit
  3832. (setq org-agenda-buffer-name
  3833. (or org-agenda-buffer-tmp-name
  3834. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3835. (if org-agenda-sticky
  3836. (cond ((and org-keys (stringp org-match))
  3837. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3838. (org-keys
  3839. (format "*Org Agenda(%s)*" org-keys))
  3840. (t "*Org Agenda(a)*")))
  3841. "*Org Agenda*"))
  3842. (org-agenda-prepare "Day/Week")
  3843. (setq start-day (or start-day org-agenda-start-day))
  3844. (if (stringp start-day)
  3845. ;; Convert to an absolute day number
  3846. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3847. (org-compile-prefix-format 'agenda)
  3848. (org-set-sorting-strategy 'agenda)
  3849. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3850. (today (org-today))
  3851. (sd (or start-day today))
  3852. (ndays (org-agenda-span-to-ndays span sd))
  3853. (org-agenda-start-on-weekday
  3854. (if (or (eq ndays 7) (eq ndays 14))
  3855. org-agenda-start-on-weekday))
  3856. (thefiles (org-agenda-files nil 'ifmode))
  3857. (files thefiles)
  3858. (start (if (or (null org-agenda-start-on-weekday)
  3859. (< ndays 7))
  3860. sd
  3861. (let* ((nt (calendar-day-of-week
  3862. (calendar-gregorian-from-absolute sd)))
  3863. (n1 org-agenda-start-on-weekday)
  3864. (d (- nt n1)))
  3865. (- sd (+ (if (< d 0) 7 0) d)))))
  3866. (day-numbers (list start))
  3867. (day-cnt 0)
  3868. (inhibit-redisplay (not debug-on-error))
  3869. (org-agenda-show-log-scoped org-agenda-show-log)
  3870. s e rtn rtnall file date d start-pos end-pos todayp
  3871. clocktable-start clocktable-end filter)
  3872. (setq org-agenda-redo-command
  3873. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3874. (dotimes (n (1- ndays))
  3875. (push (1+ (car day-numbers)) day-numbers))
  3876. (setq day-numbers (nreverse day-numbers))
  3877. (setq clocktable-start (car day-numbers)
  3878. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3879. (setq-local org-starting-day (car day-numbers))
  3880. (setq-local org-arg-loc arg)
  3881. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  3882. (unless org-agenda-compact-blocks
  3883. (let* ((d1 (car day-numbers))
  3884. (d2 (org-last day-numbers))
  3885. (w1 (org-days-to-iso-week d1))
  3886. (w2 (org-days-to-iso-week d2)))
  3887. (setq s (point))
  3888. (if org-agenda-overriding-header
  3889. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3890. nil 'face 'org-agenda-structure) "\n")
  3891. (insert (org-agenda-span-name span)
  3892. "-agenda"
  3893. (if (< (- d2 d1) 350)
  3894. (if (= w1 w2)
  3895. (format " (W%02d)" w1)
  3896. (format " (W%02d-W%02d)" w1 w2))
  3897. "")
  3898. ":\n")))
  3899. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3900. 'org-date-line t))
  3901. (org-agenda-mark-header-line s))
  3902. (while (setq d (pop day-numbers))
  3903. (setq date (calendar-gregorian-from-absolute d)
  3904. s (point))
  3905. (if (or (setq todayp (= d today))
  3906. (and (not start-pos) (= d sd)))
  3907. (setq start-pos (point))
  3908. (if (and start-pos (not end-pos))
  3909. (setq end-pos (point))))
  3910. (setq files thefiles
  3911. rtnall nil)
  3912. (while (setq file (pop files))
  3913. (catch 'nextfile
  3914. (org-check-agenda-file file)
  3915. (let ((org-agenda-entry-types org-agenda-entry-types))
  3916. ;; Starred types override non-starred equivalents
  3917. (when (member :deadline* org-agenda-entry-types)
  3918. (setq org-agenda-entry-types
  3919. (delq :deadline org-agenda-entry-types)))
  3920. (when (member :scheduled* org-agenda-entry-types)
  3921. (setq org-agenda-entry-types
  3922. (delq :scheduled org-agenda-entry-types)))
  3923. ;; Honor with-hour
  3924. (when with-hour
  3925. (when (member :deadline org-agenda-entry-types)
  3926. (setq org-agenda-entry-types
  3927. (delq :deadline org-agenda-entry-types))
  3928. (push :deadline* org-agenda-entry-types))
  3929. (when (member :scheduled org-agenda-entry-types)
  3930. (setq org-agenda-entry-types
  3931. (delq :scheduled org-agenda-entry-types))
  3932. (push :scheduled* org-agenda-entry-types)))
  3933. (unless org-agenda-include-deadlines
  3934. (setq org-agenda-entry-types
  3935. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3936. (cond
  3937. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3938. (setq rtn (org-agenda-get-day-entries
  3939. file date :closed)))
  3940. (org-agenda-show-log-scoped
  3941. (setq rtn (apply 'org-agenda-get-day-entries
  3942. file date
  3943. (append '(:closed) org-agenda-entry-types))))
  3944. (t
  3945. (setq rtn (apply 'org-agenda-get-day-entries
  3946. file date
  3947. org-agenda-entry-types)))))
  3948. (setq rtnall (append rtnall rtn)))) ;; all entries
  3949. (if org-agenda-include-diary
  3950. (let ((org-agenda-search-headline-for-time t))
  3951. (require 'diary-lib)
  3952. (setq rtn (org-get-entries-from-diary date))
  3953. (setq rtnall (append rtnall rtn))))
  3954. (if (or rtnall org-agenda-show-all-dates)
  3955. (progn
  3956. (setq day-cnt (1+ day-cnt))
  3957. (insert
  3958. (if (stringp org-agenda-format-date)
  3959. (format-time-string org-agenda-format-date
  3960. (org-time-from-absolute date))
  3961. (funcall org-agenda-format-date date))
  3962. "\n")
  3963. (put-text-property s (1- (point)) 'face
  3964. (org-agenda-get-day-face date))
  3965. (put-text-property s (1- (point)) 'org-date-line t)
  3966. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3967. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3968. (when todayp
  3969. (put-text-property s (1- (point)) 'org-today t))
  3970. (setq rtnall
  3971. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3972. (if rtnall (insert ;; all entries
  3973. (org-agenda-finalize-entries rtnall 'agenda)
  3974. "\n"))
  3975. (put-text-property s (1- (point)) 'day d)
  3976. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3977. (when (and org-agenda-clockreport-mode clocktable-start)
  3978. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3979. ;; the above line is to ensure the restricted range!
  3980. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3981. tbl)
  3982. (setq p (org-plist-delete p :block))
  3983. (setq p (plist-put p :tstart clocktable-start))
  3984. (setq p (plist-put p :tend clocktable-end))
  3985. (setq p (plist-put p :scope 'agenda))
  3986. (setq tbl (apply 'org-clock-get-clocktable p))
  3987. (insert tbl)))
  3988. (goto-char (point-min))
  3989. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3990. (unless (and (pos-visible-in-window-p (point-min))
  3991. (pos-visible-in-window-p (point-max)))
  3992. (goto-char (1- (point-max)))
  3993. (recenter -1)
  3994. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3995. (progn
  3996. (goto-char (or start-pos 1))
  3997. (recenter 1))))
  3998. (goto-char (or start-pos 1))
  3999. (add-text-properties (point-min) (point-max)
  4000. `(org-agenda-type agenda
  4001. org-last-args (,arg ,start-day ,span)
  4002. org-redo-cmd ,org-agenda-redo-command
  4003. org-series-cmd ,org-cmd))
  4004. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4005. (org-agenda-show-clocking-issues))
  4006. (org-agenda-finalize)
  4007. (setq buffer-read-only t)
  4008. (message ""))))
  4009. (defun org-agenda-ndays-to-span (n)
  4010. "Return a span symbol for a span of N days, or N if none matches."
  4011. (cond ((symbolp n) n)
  4012. ((= n 1) 'day)
  4013. ((= n 7) 'week)
  4014. ((= n 14) 'fortnight)
  4015. (t n)))
  4016. (defun org-agenda-span-to-ndays (span &optional start-day)
  4017. "Return ndays from SPAN, possibly starting at START-DAY.
  4018. START-DAY is an absolute time value."
  4019. (cond ((numberp span) span)
  4020. ((eq span 'day) 1)
  4021. ((eq span 'week) 7)
  4022. ((eq span 'fortnight) 14)
  4023. ((eq span 'month)
  4024. (let ((date (calendar-gregorian-from-absolute start-day)))
  4025. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4026. ((eq span 'year)
  4027. (let ((date (calendar-gregorian-from-absolute start-day)))
  4028. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4029. (defun org-agenda-span-name (span)
  4030. "Return a SPAN name."
  4031. (if (null span)
  4032. ""
  4033. (if (symbolp span)
  4034. (capitalize (symbol-name span))
  4035. (format "%d days" span))))
  4036. ;;; Agenda word search
  4037. (defvar org-agenda-search-history nil)
  4038. (defvar org-search-syntax-table nil
  4039. "Special syntax table for Org search.
  4040. In this table, we have single quotes not as word constituents, to
  4041. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4042. (defvar org-mode-syntax-table) ; From org.el
  4043. (defun org-search-syntax-table ()
  4044. (unless org-search-syntax-table
  4045. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4046. (modify-syntax-entry ?' "." org-search-syntax-table)
  4047. (modify-syntax-entry ?` "." org-search-syntax-table))
  4048. org-search-syntax-table)
  4049. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4050. ;;;###autoload
  4051. (defun org-search-view (&optional todo-only string edit-at)
  4052. "Show all entries that contain a phrase or words or regular expressions.
  4053. With optional prefix argument TODO-ONLY, only consider entries that are
  4054. TODO entries. The argument STRING can be used to pass a default search
  4055. string into this function. If EDIT-AT is non-nil, it means that the
  4056. user should get a chance to edit this string, with cursor at position
  4057. EDIT-AT.
  4058. The search string can be viewed either as a phrase that should be found as
  4059. is, or it can be broken into a number of snippets, each of which must match
  4060. in a Boolean way to select an entry. The default depends on the variable
  4061. `org-agenda-search-view-always-boolean'.
  4062. Even if this is turned off (the default) you can always switch to
  4063. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4064. The default is a direct search of the whole phrase, where each space in
  4065. the search string can expand to an arbitrary amount of whitespace,
  4066. including newlines.
  4067. If using a Boolean search, the search string is split on whitespace and
  4068. each snippet is searched separately, with logical AND to select an entry.
  4069. Words prefixed with a minus must *not* occur in the entry. Words without
  4070. a prefix or prefixed with a plus must occur in the entry. Matching is
  4071. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4072. match whole words, not parts of a word) if
  4073. `org-agenda-search-view-force-full-words' is set (default is nil).
  4074. Boolean search snippets enclosed by curly braces are interpreted as
  4075. regular expressions that must or (when preceded with \"-\") must not
  4076. match in the entry. Snippets enclosed into double quotes will be taken
  4077. as a whole, to include whitespace.
  4078. - If the search string starts with an asterisk, search only in headlines.
  4079. - If (possibly after the leading star) the search string starts with an
  4080. exclamation mark, this also means to look at TODO entries only, an effect
  4081. that can also be achieved with a prefix argument.
  4082. - If (possibly after star and exclamation mark) the search string starts
  4083. with a colon, this will mean that the (non-regexp) snippets of the
  4084. Boolean search must match as full words.
  4085. This command searches the agenda files, and in addition the files listed
  4086. in `org-agenda-text-search-extra-files'."
  4087. (interactive "P")
  4088. (if org-agenda-overriding-arguments
  4089. (setq todo-only (car org-agenda-overriding-arguments)
  4090. string (nth 1 org-agenda-overriding-arguments)
  4091. edit-at (nth 2 org-agenda-overriding-arguments)))
  4092. (let* ((props (list 'face nil
  4093. 'done-face 'org-agenda-done
  4094. 'org-not-done-regexp org-not-done-regexp
  4095. 'org-todo-regexp org-todo-regexp
  4096. 'org-complex-heading-regexp org-complex-heading-regexp
  4097. 'mouse-face 'highlight
  4098. 'help-echo (format "mouse-2 or RET jump to location")))
  4099. (full-words org-agenda-search-view-force-full-words)
  4100. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4101. regexp rtn rtnall files file pos inherited-tags
  4102. marker category level tags c neg re boolean
  4103. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4104. (unless (and (not edit-at)
  4105. (stringp string)
  4106. (string-match "\\S-" string))
  4107. (setq string (read-string
  4108. (if org-agenda-search-view-always-boolean
  4109. "[+-]Word/{Regexp} ...: "
  4110. "Phrase or [+-]Word/{Regexp} ...: ")
  4111. (cond
  4112. ((integerp edit-at) (cons string edit-at))
  4113. (edit-at string))
  4114. 'org-agenda-search-history)))
  4115. (catch 'exit
  4116. (if org-agenda-sticky
  4117. (setq org-agenda-buffer-name
  4118. (if (stringp string)
  4119. (format "*Org Agenda(%s:%s)*"
  4120. (or org-keys (or (and todo-only "S") "s")) string)
  4121. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4122. (org-agenda-prepare "SEARCH")
  4123. (org-compile-prefix-format 'search)
  4124. (org-set-sorting-strategy 'search)
  4125. (setq org-agenda-redo-command
  4126. (list 'org-search-view (if todo-only t nil)
  4127. (list 'if 'current-prefix-arg nil string)))
  4128. (setq org-agenda-query-string string)
  4129. (if (equal (string-to-char string) ?*)
  4130. (setq hdl-only t
  4131. words (substring string 1))
  4132. (setq words string))
  4133. (when (equal (string-to-char words) ?!)
  4134. (setq todo-only t
  4135. words (substring words 1)))
  4136. (when (equal (string-to-char words) ?:)
  4137. (setq full-words t
  4138. words (substring words 1)))
  4139. (if (or org-agenda-search-view-always-boolean
  4140. (member (string-to-char words) '(?- ?+ ?\{)))
  4141. (setq boolean t))
  4142. (setq words (org-split-string words))
  4143. (let (www w)
  4144. (while (setq w (pop words))
  4145. (while (and (string-match "\\\\\\'" w) words)
  4146. (setq w (concat (substring w 0 -1) " " (pop words))))
  4147. (push w www))
  4148. (setq words (nreverse www) www nil)
  4149. (while (setq w (pop words))
  4150. (when (and (string-match "\\`[-+]?{" w)
  4151. (not (string-match "}\\'" w)))
  4152. (while (and words (not (string-match "}\\'" (car words))))
  4153. (setq w (concat w " " (pop words))))
  4154. (setq w (concat w " " (pop words))))
  4155. (push w www))
  4156. (setq words (nreverse www)))
  4157. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4158. (when boolean
  4159. (let (wds w)
  4160. (while (setq w (pop words))
  4161. (if (or (equal (substring w 0 1) "\"")
  4162. (and (> (length w) 1)
  4163. (member (substring w 0 1) '("+" "-"))
  4164. (equal (substring w 1 2) "\"")))
  4165. (while (and words (not (equal (substring w -1) "\"")))
  4166. (setq w (concat w " " (pop words)))))
  4167. (and (string-match "\\`\\([-+]?\\)\"" w)
  4168. (setq w (replace-match "\\1" nil nil w)))
  4169. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4170. (push w wds))
  4171. (setq words (nreverse wds))))
  4172. (if boolean
  4173. (mapc (lambda (w)
  4174. (setq c (string-to-char w))
  4175. (if (equal c ?-)
  4176. (setq neg t w (substring w 1))
  4177. (if (equal c ?+)
  4178. (setq neg nil w (substring w 1))
  4179. (setq neg nil)))
  4180. (if (string-match "\\`{.*}\\'" w)
  4181. (setq re (substring w 1 -1))
  4182. (if full-words
  4183. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4184. (setq re (regexp-quote (downcase w)))))
  4185. (if neg (push re regexps-) (push re regexps+)))
  4186. words)
  4187. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4188. regexps+))
  4189. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4190. (if (not regexps+)
  4191. (setq regexp org-outline-regexp-bol)
  4192. (setq regexp (pop regexps+))
  4193. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4194. regexp))))
  4195. (setq files (org-agenda-files nil 'ifmode))
  4196. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4197. (pop org-agenda-text-search-extra-files)
  4198. (setq files (org-add-archive-files files)))
  4199. (setq files (append files org-agenda-text-search-extra-files)
  4200. rtnall nil)
  4201. (while (setq file (pop files))
  4202. (setq ee nil)
  4203. (catch 'nextfile
  4204. (org-check-agenda-file file)
  4205. (setq buffer (if (file-exists-p file)
  4206. (org-get-agenda-file-buffer file)
  4207. (error "No such file %s" file)))
  4208. (if (not buffer)
  4209. ;; If file does not exist, make sure an error message is sent
  4210. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4211. file))))
  4212. (with-current-buffer buffer
  4213. (with-syntax-table (org-search-syntax-table)
  4214. (unless (derived-mode-p 'org-mode)
  4215. (error "Agenda file %s is not in `org-mode'" file))
  4216. (let ((case-fold-search t))
  4217. (save-excursion
  4218. (save-restriction
  4219. (if (eq buffer org-agenda-restrict)
  4220. (narrow-to-region org-agenda-restrict-begin
  4221. org-agenda-restrict-end)
  4222. (widen))
  4223. (goto-char (point-min))
  4224. (unless (or (org-at-heading-p)
  4225. (outline-next-heading))
  4226. (throw 'nextfile t))
  4227. (goto-char (max (point-min) (1- (point))))
  4228. (while (re-search-forward regexp nil t)
  4229. (org-back-to-heading t)
  4230. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4231. (> (org-reduced-level (org-outline-level))
  4232. org-agenda-search-view-max-outline-level)
  4233. (forward-line -1)
  4234. (org-back-to-heading t)))
  4235. (skip-chars-forward "* ")
  4236. (setq beg (point-at-bol)
  4237. beg1 (point)
  4238. end (progn
  4239. (outline-next-heading)
  4240. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4241. (> (org-reduced-level (org-outline-level))
  4242. org-agenda-search-view-max-outline-level)
  4243. (forward-line 1)
  4244. (outline-next-heading)))
  4245. (point)))
  4246. (catch :skip
  4247. (goto-char beg)
  4248. (org-agenda-skip)
  4249. (setq str (buffer-substring-no-properties
  4250. (point-at-bol)
  4251. (if hdl-only (point-at-eol) end)))
  4252. (mapc (lambda (wr) (when (string-match wr str)
  4253. (goto-char (1- end))
  4254. (throw :skip t)))
  4255. regexps-)
  4256. (mapc (lambda (wr) (unless (string-match wr str)
  4257. (goto-char (1- end))
  4258. (throw :skip t)))
  4259. (if todo-only
  4260. (cons (concat "^\\*+[ \t]+"
  4261. org-not-done-regexp)
  4262. regexps+)
  4263. regexps+))
  4264. (goto-char beg)
  4265. (setq marker (org-agenda-new-marker (point))
  4266. category (org-get-category)
  4267. level (make-string (org-reduced-level (org-outline-level)) ? )
  4268. inherited-tags
  4269. (or (eq org-agenda-show-inherited-tags 'always)
  4270. (and (listp org-agenda-show-inherited-tags)
  4271. (memq 'todo org-agenda-show-inherited-tags))
  4272. (and (eq org-agenda-show-inherited-tags t)
  4273. (or (eq org-agenda-use-tag-inheritance t)
  4274. (memq 'todo org-agenda-use-tag-inheritance))))
  4275. tags (org-get-tags-at nil (not inherited-tags))
  4276. txt (org-agenda-format-item
  4277. ""
  4278. (buffer-substring-no-properties
  4279. beg1 (point-at-eol))
  4280. level category tags t))
  4281. (org-add-props txt props
  4282. 'org-marker marker 'org-hd-marker marker
  4283. 'org-todo-regexp org-todo-regexp
  4284. 'level level
  4285. 'org-complex-heading-regexp org-complex-heading-regexp
  4286. 'priority 1000
  4287. 'type "search")
  4288. (push txt ee)
  4289. (goto-char (1- end))))))))))
  4290. (setq rtn (nreverse ee))
  4291. (setq rtnall (append rtnall rtn)))
  4292. (if org-agenda-overriding-header
  4293. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4294. nil 'face 'org-agenda-structure) "\n")
  4295. (insert "Search words: ")
  4296. (add-text-properties (point-min) (1- (point))
  4297. (list 'face 'org-agenda-structure))
  4298. (setq pos (point))
  4299. (insert string "\n")
  4300. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4301. (setq pos (point))
  4302. (unless org-agenda-multi
  4303. (insert (substitute-command-keys "\
  4304. Press `\\[org-agenda-manipulate-query-add]', \
  4305. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4306. `\\[org-agenda-manipulate-query-add-re]', \
  4307. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4308. `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
  4309. (add-text-properties pos (1- (point))
  4310. (list 'face 'org-agenda-structure))))
  4311. (org-agenda-mark-header-line (point-min))
  4312. (when rtnall
  4313. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4314. (goto-char (point-min))
  4315. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4316. (add-text-properties (point-min) (point-max)
  4317. `(org-agenda-type search
  4318. org-last-args (,todo-only ,string ,edit-at)
  4319. org-redo-cmd ,org-agenda-redo-command
  4320. org-series-cmd ,org-cmd))
  4321. (org-agenda-finalize)
  4322. (setq buffer-read-only t))))
  4323. ;;; Agenda TODO list
  4324. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4325. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4326. (concat
  4327. (if (or (equal keywords "ALL") (not keywords))
  4328. (propertize "ALL" 'face 'warning)
  4329. (mapconcat
  4330. (lambda (kw)
  4331. (propertize kw 'face (org-get-todo-face kw)))
  4332. (org-split-string keywords "|")
  4333. "|"))
  4334. "\n"))
  4335. (defvar org-select-this-todo-keyword nil)
  4336. (defvar org-last-arg nil)
  4337. ;;;###autoload
  4338. (defun org-todo-list (&optional arg)
  4339. "Show all (not done) TODO entries from all agenda file in a single list.
  4340. The prefix arg can be used to select a specific TODO keyword and limit
  4341. the list to these. When using `\\[universal-argument]', you will be prompted
  4342. for a keyword. A numeric prefix directly selects the Nth keyword in
  4343. `org-todo-keywords-1'."
  4344. (interactive "P")
  4345. (if org-agenda-overriding-arguments
  4346. (setq arg org-agenda-overriding-arguments))
  4347. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4348. (let* ((today (org-today))
  4349. (date (calendar-gregorian-from-absolute today))
  4350. (kwds org-todo-keywords-for-agenda)
  4351. (completion-ignore-case t)
  4352. (org-select-this-todo-keyword
  4353. (if (stringp arg) arg
  4354. (and arg (integerp arg) (> arg 0)
  4355. (nth (1- arg) kwds))))
  4356. rtn rtnall files file pos)
  4357. (when (equal arg '(4))
  4358. (setq org-select-this-todo-keyword
  4359. (completing-read "Keyword (or KWD1|K2D2|...): "
  4360. (mapcar #'list kwds) nil nil)))
  4361. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4362. (catch 'exit
  4363. (if org-agenda-sticky
  4364. (setq org-agenda-buffer-name
  4365. (if (stringp org-select-this-todo-keyword)
  4366. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4367. org-select-this-todo-keyword)
  4368. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4369. (org-agenda-prepare "TODO")
  4370. (org-compile-prefix-format 'todo)
  4371. (org-set-sorting-strategy 'todo)
  4372. (setq org-agenda-redo-command
  4373. `(org-todo-list (or (and (numberp current-prefix-arg)
  4374. current-prefix-arg)
  4375. ,org-select-this-todo-keyword
  4376. current-prefix-arg ,arg)))
  4377. (setq files (org-agenda-files nil 'ifmode)
  4378. rtnall nil)
  4379. (while (setq file (pop files))
  4380. (catch 'nextfile
  4381. (org-check-agenda-file file)
  4382. (setq rtn (org-agenda-get-day-entries file date :todo))
  4383. (setq rtnall (append rtnall rtn))))
  4384. (if org-agenda-overriding-header
  4385. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4386. nil 'face 'org-agenda-structure) "\n")
  4387. (insert "Global list of TODO items of type: ")
  4388. (add-text-properties (point-min) (1- (point))
  4389. (list 'face 'org-agenda-structure
  4390. 'short-heading
  4391. (concat "ToDo: "
  4392. (or org-select-this-todo-keyword "ALL"))))
  4393. (org-agenda-mark-header-line (point-min))
  4394. (insert (org-agenda-propertize-selected-todo-keywords
  4395. org-select-this-todo-keyword))
  4396. (setq pos (point))
  4397. (unless org-agenda-multi
  4398. (insert (substitute-command-keys "Available with \
  4399. `N \\[org-agenda-redo]': (0)[ALL]"))
  4400. (let ((n 0) s)
  4401. (mapc (lambda (x)
  4402. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4403. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4404. (insert "\n "))
  4405. (insert " " s))
  4406. kwds))
  4407. (insert "\n"))
  4408. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4409. (org-agenda-mark-header-line (point-min))
  4410. (when rtnall
  4411. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4412. (goto-char (point-min))
  4413. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4414. (add-text-properties (point-min) (point-max)
  4415. `(org-agenda-type todo
  4416. org-last-args ,arg
  4417. org-redo-cmd ,org-agenda-redo-command
  4418. org-series-cmd ,org-cmd))
  4419. (org-agenda-finalize)
  4420. (setq buffer-read-only t))))
  4421. ;;; Agenda tags match
  4422. ;;;###autoload
  4423. (defun org-tags-view (&optional todo-only match)
  4424. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4425. The prefix arg TODO-ONLY limits the search to TODO entries."
  4426. (interactive "P")
  4427. (if org-agenda-overriding-arguments
  4428. (setq todo-only (car org-agenda-overriding-arguments)
  4429. match (nth 1 org-agenda-overriding-arguments)))
  4430. (let* ((org-tags-match-list-sublevels
  4431. org-tags-match-list-sublevels)
  4432. (completion-ignore-case t)
  4433. rtn rtnall files file pos matcher
  4434. buffer)
  4435. (when (and (stringp match) (not (string-match "\\S-" match)))
  4436. (setq match nil))
  4437. (catch 'exit
  4438. (if org-agenda-sticky
  4439. (setq org-agenda-buffer-name
  4440. (if (stringp match)
  4441. (format "*Org Agenda(%s:%s)*"
  4442. (or org-keys (or (and todo-only "M") "m")) match)
  4443. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4444. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4445. ;; expanding tags within `org-make-tags-matcher'
  4446. (org-agenda-prepare (concat "TAGS " match))
  4447. (setq org--matcher-tags-todo-only todo-only
  4448. matcher (org-make-tags-matcher match)
  4449. match (car matcher)
  4450. matcher (cdr matcher))
  4451. (org-compile-prefix-format 'tags)
  4452. (org-set-sorting-strategy 'tags)
  4453. (setq org-agenda-query-string match)
  4454. (setq org-agenda-redo-command
  4455. (list 'org-tags-view
  4456. `(quote ,org--matcher-tags-todo-only)
  4457. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4458. (setq files (org-agenda-files nil 'ifmode)
  4459. rtnall nil)
  4460. (while (setq file (pop files))
  4461. (catch 'nextfile
  4462. (org-check-agenda-file file)
  4463. (setq buffer (if (file-exists-p file)
  4464. (org-get-agenda-file-buffer file)
  4465. (error "No such file %s" file)))
  4466. (if (not buffer)
  4467. ;; If file does not exist, error message to agenda
  4468. (setq rtn (list
  4469. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4470. rtnall (append rtnall rtn))
  4471. (with-current-buffer buffer
  4472. (unless (derived-mode-p 'org-mode)
  4473. (error "Agenda file %s is not in `org-mode'" file))
  4474. (save-excursion
  4475. (save-restriction
  4476. (if (eq buffer org-agenda-restrict)
  4477. (narrow-to-region org-agenda-restrict-begin
  4478. org-agenda-restrict-end)
  4479. (widen))
  4480. (setq rtn (org-scan-tags 'agenda
  4481. matcher
  4482. org--matcher-tags-todo-only))
  4483. (setq rtnall (append rtnall rtn))))))))
  4484. (if org-agenda-overriding-header
  4485. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4486. nil 'face 'org-agenda-structure) "\n")
  4487. (insert "Headlines with TAGS match: ")
  4488. (add-text-properties (point-min) (1- (point))
  4489. (list 'face 'org-agenda-structure
  4490. 'short-heading
  4491. (concat "Match: " match)))
  4492. (setq pos (point))
  4493. (insert match "\n")
  4494. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4495. (setq pos (point))
  4496. (unless org-agenda-multi
  4497. (insert (substitute-command-keys
  4498. "Press `\\[universal-argument] \\[org-agenda-redo]' \
  4499. to search again with new search string\n")))
  4500. (add-text-properties pos (1- (point))
  4501. (list 'face 'org-agenda-structure)))
  4502. (org-agenda-mark-header-line (point-min))
  4503. (when rtnall
  4504. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4505. (goto-char (point-min))
  4506. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4507. (add-text-properties
  4508. (point-min) (point-max)
  4509. `(org-agenda-type tags
  4510. org-last-args (,org--matcher-tags-todo-only ,match)
  4511. org-redo-cmd ,org-agenda-redo-command
  4512. org-series-cmd ,org-cmd))
  4513. (org-agenda-finalize)
  4514. (setq buffer-read-only t))))
  4515. ;;; Agenda Finding stuck projects
  4516. (defvar org-agenda-skip-regexp nil
  4517. "Regular expression used in skipping subtrees for the agenda.
  4518. This is basically a temporary global variable that can be set and then
  4519. used by user-defined selections using `org-agenda-skip-function'.")
  4520. (defvar org-agenda-overriding-header nil
  4521. "When set during agenda, todo and tags searches it replaces the header.
  4522. This variable should not be set directly, but custom commands can bind it
  4523. in the options section.")
  4524. (defun org-agenda-skip-entry-when-regexp-matches ()
  4525. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4526. If yes, it returns the end position of this entry, causing agenda commands
  4527. to skip the entry but continuing the search in the subtree. This is a
  4528. function that can be put into `org-agenda-skip-function' for the duration
  4529. of a command."
  4530. (let ((end (save-excursion (org-end-of-subtree t)))
  4531. skip)
  4532. (save-excursion
  4533. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4534. (and skip end)))
  4535. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4536. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4537. If yes, it returns the end position of this tree, causing agenda commands
  4538. to skip this subtree. This is a function that can be put into
  4539. `org-agenda-skip-function' for the duration of a command."
  4540. (let ((end (save-excursion (org-end-of-subtree t)))
  4541. skip)
  4542. (save-excursion
  4543. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4544. (and skip end)))
  4545. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4546. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4547. If yes, it returns the end position of the current entry (NOT the tree),
  4548. causing agenda commands to skip the entry but continuing the search in
  4549. the subtree. This is a function that can be put into
  4550. `org-agenda-skip-function' for the duration of a command. An important
  4551. use of this function is for the stuck project list."
  4552. (let ((end (save-excursion (org-end-of-subtree t)))
  4553. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4554. skip)
  4555. (save-excursion
  4556. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4557. (and skip entry-end)))
  4558. (defun org-agenda-skip-entry-if (&rest conditions)
  4559. "Skip entry if any of CONDITIONS is true.
  4560. See `org-agenda-skip-if' for details."
  4561. (org-agenda-skip-if nil conditions))
  4562. (defun org-agenda-skip-subtree-if (&rest conditions)
  4563. "Skip subtree if any of CONDITIONS is true.
  4564. See `org-agenda-skip-if' for details."
  4565. (org-agenda-skip-if t conditions))
  4566. (defun org-agenda-skip-if (subtree conditions)
  4567. "Checks current entity for CONDITIONS.
  4568. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4569. the entry (i.e. the text before the next heading) is checked.
  4570. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4571. from different tests. Valid conditions are:
  4572. scheduled Check if there is a scheduled cookie
  4573. notscheduled Check if there is no scheduled cookie
  4574. deadline Check if there is a deadline
  4575. notdeadline Check if there is no deadline
  4576. timestamp Check if there is a timestamp (also deadline or scheduled)
  4577. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4578. regexp Check if regexp matches
  4579. notregexp Check if regexp does not match.
  4580. todo Check if TODO keyword matches
  4581. nottodo Check if TODO keyword does not match
  4582. The regexp is taken from the conditions list, it must come right after
  4583. the `regexp' or `notregexp' element.
  4584. `todo' and `nottodo' accept as an argument a list of todo
  4585. keywords, which may include \"*\" to match any todo keyword.
  4586. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4587. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4588. Instead of a list, a keyword class may be given. For example:
  4589. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4590. would skip entries that haven't been marked with any of \"DONE\"
  4591. keywords. Possible classes are: `todo', `done', `any'.
  4592. If any of these conditions is met, this function returns the end point of
  4593. the entity, causing the search to continue from there. This is a function
  4594. that can be put into `org-agenda-skip-function' for the duration of a command."
  4595. (let (beg end m)
  4596. (org-back-to-heading t)
  4597. (setq beg (point)
  4598. end (if subtree
  4599. (progn (org-end-of-subtree t) (point))
  4600. (progn (outline-next-heading) (1- (point)))))
  4601. (goto-char beg)
  4602. (and
  4603. (or
  4604. (and (memq 'scheduled conditions)
  4605. (re-search-forward org-scheduled-time-regexp end t))
  4606. (and (memq 'notscheduled conditions)
  4607. (not (re-search-forward org-scheduled-time-regexp end t)))
  4608. (and (memq 'deadline conditions)
  4609. (re-search-forward org-deadline-time-regexp end t))
  4610. (and (memq 'notdeadline conditions)
  4611. (not (re-search-forward org-deadline-time-regexp end t)))
  4612. (and (memq 'timestamp conditions)
  4613. (re-search-forward org-ts-regexp end t))
  4614. (and (memq 'nottimestamp conditions)
  4615. (not (re-search-forward org-ts-regexp end t)))
  4616. (and (setq m (memq 'regexp conditions))
  4617. (stringp (nth 1 m))
  4618. (re-search-forward (nth 1 m) end t))
  4619. (and (setq m (memq 'notregexp conditions))
  4620. (stringp (nth 1 m))
  4621. (not (re-search-forward (nth 1 m) end t)))
  4622. (and (or
  4623. (setq m (memq 'nottodo conditions))
  4624. (setq m (memq 'todo-unblocked conditions))
  4625. (setq m (memq 'nottodo-unblocked conditions))
  4626. (setq m (memq 'todo conditions)))
  4627. (org-agenda-skip-if-todo m end)))
  4628. end)))
  4629. (defun org-agenda-skip-if-todo (args end)
  4630. "Helper function for `org-agenda-skip-if', do not use it directly.
  4631. ARGS is a list with first element either `todo', `nottodo',
  4632. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4633. a list of TODO keywords, or a state symbol `todo' or `done' or
  4634. `any'."
  4635. (let ((kw (car args))
  4636. (arg (cadr args))
  4637. todo-wds todo-re)
  4638. (setq todo-wds
  4639. (org-uniquify
  4640. (cond
  4641. ((listp arg) ;; list of keywords
  4642. (if (member "*" arg)
  4643. (mapcar 'substring-no-properties org-todo-keywords-1)
  4644. arg))
  4645. ((symbolp arg) ;; keyword class name
  4646. (cond
  4647. ((eq arg 'todo)
  4648. (org-delete-all org-done-keywords
  4649. (mapcar 'substring-no-properties
  4650. org-todo-keywords-1)))
  4651. ((eq arg 'done) org-done-keywords)
  4652. ((eq arg 'any)
  4653. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4654. (setq todo-re
  4655. (concat "^\\*+[ \t]+\\<\\("
  4656. (mapconcat 'identity todo-wds "\\|")
  4657. "\\)\\>"))
  4658. (cond
  4659. ((eq kw 'todo) (re-search-forward todo-re end t))
  4660. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4661. ((eq kw 'todo-unblocked)
  4662. (catch 'unblocked
  4663. (while (re-search-forward todo-re end t)
  4664. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4665. nil))
  4666. ((eq kw 'nottodo-unblocked)
  4667. (catch 'unblocked
  4668. (while (re-search-forward todo-re end t)
  4669. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4670. t))
  4671. )))
  4672. ;;;###autoload
  4673. (defun org-agenda-list-stuck-projects (&rest ignore)
  4674. "Create agenda view for projects that are stuck.
  4675. Stuck projects are project that have no next actions. For the definitions
  4676. of what a project is and how to check if it stuck, customize the variable
  4677. `org-stuck-projects'."
  4678. (interactive)
  4679. (let* ((org-agenda-overriding-header
  4680. (or org-agenda-overriding-header "List of stuck projects: "))
  4681. (matcher (nth 0 org-stuck-projects))
  4682. (todo (nth 1 org-stuck-projects))
  4683. (tags (nth 2 org-stuck-projects))
  4684. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4685. (todo-wds
  4686. (if (not (member "*" todo)) todo
  4687. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4688. (org-delete-all org-done-keywords-for-agenda
  4689. (copy-sequence org-todo-keywords-for-agenda))))
  4690. (todo-re (and todo
  4691. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4692. (mapconcat #'identity todo-wds "\\|"))))
  4693. (tags-re (cond ((null tags) nil)
  4694. ((member "*" tags)
  4695. (eval-when-compile
  4696. (concat org-outline-regexp-bol
  4697. ".*:[[:alnum:]_@#%]+:[ \t]*$")))
  4698. (tags (concat org-outline-regexp-bol
  4699. ".*:\\("
  4700. (mapconcat #'identity tags "\\|")
  4701. "\\):[[:alnum:]_@#%:]*[ \t]*$"))
  4702. (t nil)))
  4703. (re-list (delq nil (list todo-re tags-re gen-re)))
  4704. (skip-re
  4705. (if (null re-list)
  4706. (error "Missing information to identify unstuck projects")
  4707. (mapconcat #'identity re-list "\\|")))
  4708. (org-agenda-skip-function
  4709. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4710. ;; in the subtree.
  4711. `(lambda ()
  4712. (and (save-excursion
  4713. (let ((case-fold-search nil))
  4714. (re-search-forward
  4715. ,skip-re (save-excursion (org-end-of-subtree t)) t)))
  4716. (progn (outline-next-heading) (point))))))
  4717. (org-tags-view nil matcher)
  4718. (setq org-agenda-buffer-name (buffer-name))
  4719. (with-current-buffer org-agenda-buffer-name
  4720. (setq org-agenda-redo-command
  4721. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4722. (let ((inhibit-read-only t))
  4723. (add-text-properties
  4724. (point-min) (point-max)
  4725. `(org-redo-cmd ,org-agenda-redo-command))))))
  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. (sexp? (string-prefix-p "%%" s))
  5629. ;; DEADLINE is the bare deadline date, i.e., without
  5630. ;; any repeater, or the last repeat if SHOW-ALL is
  5631. ;; non-nil. REPEAT is closest repeat after CURRENT, if
  5632. ;; all repeated time stamps are to be shown, or after
  5633. ;; TODAY otherwise. REPEAT only applies to future
  5634. ;; dates.
  5635. (deadline (cond
  5636. (sexp? (org-agenda--timestamp-to-absolute s current))
  5637. (show-all (org-agenda--timestamp-to-absolute s))
  5638. (t (org-agenda--timestamp-to-absolute
  5639. s today 'past (current-buffer) pos))))
  5640. (repeat (cond (sexp? deadline)
  5641. ((< current today) deadline)
  5642. (t
  5643. (org-agenda--timestamp-to-absolute
  5644. s (if show-all current today) 'future
  5645. (current-buffer) pos))))
  5646. (diff (- deadline current))
  5647. (suppress-prewarning
  5648. (let ((scheduled
  5649. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5650. (org-entry-get nil "SCHEDULED"))))
  5651. (cond
  5652. ((not scheduled) nil)
  5653. ;; The current item has a scheduled date, so
  5654. ;; evaluate its prewarning lead time.
  5655. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5656. ;; Use global prewarning-restart lead time.
  5657. org-agenda-skip-deadline-prewarning-if-scheduled)
  5658. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5659. 'pre-scheduled)
  5660. ;; Set pre-warning to no earlier than SCHEDULED.
  5661. (min (- deadline
  5662. (org-agenda--timestamp-to-absolute scheduled))
  5663. org-deadline-warning-days))
  5664. ;; Set pre-warning to deadline.
  5665. (t 0))))
  5666. (wdays (if suppress-prewarning
  5667. (let ((org-deadline-warning-days suppress-prewarning))
  5668. (org-get-wdays s))
  5669. (org-get-wdays s))))
  5670. ;; When to show a deadline in the calendar: if the
  5671. ;; expiration is within WDAYS warning time. Past-due
  5672. ;; deadlines are only shown on today agenda.
  5673. (when (cond ((= current deadline) nil)
  5674. ((< deadline today)
  5675. (and (not today?)
  5676. (or (< current today) (/= repeat current))))
  5677. ((> deadline current)
  5678. (or (not today?) (> diff wdays)))
  5679. (t (/= repeat current)))
  5680. (throw :skip nil))
  5681. ;; Possibly skip done tasks.
  5682. (when (and done?
  5683. (or org-agenda-skip-deadline-if-done
  5684. (/= deadline current)))
  5685. (throw :skip nil))
  5686. (save-excursion
  5687. (re-search-backward "^\\*+[ \t]+" nil t)
  5688. (goto-char (match-end 0))
  5689. (let* ((category (org-get-category))
  5690. (level
  5691. (make-string (org-reduced-level (org-outline-level)) ?\s))
  5692. (head (buffer-substring (point) (line-end-position)))
  5693. (inherited-tags
  5694. (or (eq org-agenda-show-inherited-tags 'always)
  5695. (and (listp org-agenda-show-inherited-tags)
  5696. (memq 'agenda org-agenda-show-inherited-tags))
  5697. (and (eq org-agenda-show-inherited-tags t)
  5698. (or (eq org-agenda-use-tag-inheritance t)
  5699. (memq 'agenda
  5700. org-agenda-use-tag-inheritance)))))
  5701. (tags (org-get-tags-at nil (not inherited-tags)))
  5702. (time
  5703. (cond
  5704. ;; No time of day designation if it is only
  5705. ;; a reminder.
  5706. ((and (/= current deadline) (/= current repeat)) nil)
  5707. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5708. (concat (substring s (match-beginning 1)) " "))
  5709. (t 'time)))
  5710. (item
  5711. (org-agenda-format-item
  5712. ;; Insert appropriate suffixes before deadlines.
  5713. (pcase-let ((`(,now ,future ,past)
  5714. org-agenda-deadline-leaders))
  5715. (cond
  5716. ;; Future (i.e., repeated) deadlines are
  5717. ;; displayed as new headlines.
  5718. ((> current today) now)
  5719. ;; When SHOW-ALL is nil, prefer repeated
  5720. ;; deadlines over reminders of past deadlines.
  5721. ((and (not show-all) (= repeat today)) now)
  5722. ((= deadline current) now)
  5723. ((< deadline current) (format past (- diff)))
  5724. (t (format future diff))))
  5725. head level category tags
  5726. (and (or (= repeat current) (= deadline current))
  5727. time)))
  5728. (face (org-agenda-deadline-face
  5729. (- 1 (/ (float (- deadline current)) (max wdays 1)))))
  5730. (upcoming? (and today? (> deadline today)))
  5731. (warntime (get-text-property (point) 'org-appt-warntime)))
  5732. (org-add-props item props
  5733. 'org-marker (org-agenda-new-marker pos)
  5734. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5735. 'warntime warntime
  5736. 'level level
  5737. 'ts-date deadline
  5738. 'priority
  5739. ;; Adjust priority to today reminders about deadlines.
  5740. ;; Overdue deadlines get the highest priority
  5741. ;; increase, then imminent deadlines and eventually
  5742. ;; more distant deadlines.
  5743. (let ((adjust (cond ((not today?) 0)
  5744. ((and (not show-all) (= repeat current)) 0)
  5745. (t (- diff)))))
  5746. (+ adjust (org-get-priority item)))
  5747. 'todo-state todo-state
  5748. 'type (if upcoming? "upcoming-deadline" "deadline")
  5749. 'date (if upcoming? date deadline)
  5750. 'face (if done? 'org-agenda-done face)
  5751. 'undone-face face
  5752. 'done-face 'org-agenda-done)
  5753. (push item deadline-items))))))
  5754. (nreverse deadline-items)))
  5755. (defun org-agenda-deadline-face (fraction)
  5756. "Return the face to displaying a deadline item.
  5757. FRACTION is what fraction of the head-warning time has passed."
  5758. (assoc-default fraction org-agenda-deadline-faces #'<=))
  5759. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  5760. "Return the scheduled information for agenda display.
  5761. Optional argument DEADLINES is a list of deadline items to be
  5762. displayed in agenda view. When WITH-HOUR is non-nil, only return
  5763. scheduled items with an hour specification like [h]h:mm."
  5764. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5765. 'org-todo-regexp org-todo-regexp
  5766. 'org-complex-heading-regexp org-complex-heading-regexp
  5767. 'done-face 'org-agenda-done
  5768. 'mouse-face 'highlight
  5769. 'help-echo
  5770. (format "mouse-2 or RET jump to Org file %s"
  5771. (abbreviate-file-name buffer-file-name))))
  5772. (regexp (if with-hour
  5773. org-scheduled-time-hour-regexp
  5774. org-scheduled-time-regexp))
  5775. (today (org-today))
  5776. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  5777. (current (calendar-absolute-from-gregorian date))
  5778. (deadline-pos
  5779. (mapcar (lambda (d)
  5780. (let ((m (get-text-property 0 'org-hd-marker d)))
  5781. (and m (marker-position m))))
  5782. deadlines))
  5783. scheduled-items)
  5784. (goto-char (point-min))
  5785. (while (re-search-forward regexp nil t)
  5786. (catch :skip
  5787. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5788. (org-agenda-skip)
  5789. (let* ((s (match-string 1))
  5790. (pos (1- (match-beginning 1)))
  5791. (todo-state (save-match-data (org-get-todo-state)))
  5792. (donep (member todo-state org-done-keywords))
  5793. (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5794. (member todo-state
  5795. org-agenda-repeating-timestamp-show-all)))
  5796. (sexp? (string-prefix-p "%%" s))
  5797. ;; SCHEDULE is the bare scheduled date, i.e., without
  5798. ;; any repeater if non-nil, or last repeat if SHOW-ALL
  5799. ;; is nil. REPEAT is the closest repeat after CURRENT,
  5800. ;; if all repeated time stamps are to be shown, or
  5801. ;; after TODAY otherwise. REPEAT only applies to
  5802. ;; future dates.
  5803. (schedule (cond
  5804. (sexp? (org-agenda--timestamp-to-absolute s current))
  5805. (show-all (org-agenda--timestamp-to-absolute s))
  5806. (t (org-agenda--timestamp-to-absolute
  5807. s today 'past (current-buffer) pos))))
  5808. (repeat (cond
  5809. (sexp? schedule)
  5810. ((< current today) schedule)
  5811. (t
  5812. (org-agenda--timestamp-to-absolute
  5813. s (if show-all current today) 'future
  5814. (current-buffer) pos))))
  5815. (diff (- current schedule))
  5816. (warntime (get-text-property (point) 'org-appt-warntime))
  5817. (pastschedp (< schedule today))
  5818. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5819. (suppress-delay
  5820. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  5821. (org-entry-get nil "DEADLINE"))))
  5822. (cond
  5823. ((not deadline) nil)
  5824. ;; The current item has a deadline date, so
  5825. ;; evaluate its delay time.
  5826. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5827. ;; Use global delay time.
  5828. (- org-agenda-skip-scheduled-delay-if-deadline))
  5829. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5830. 'post-deadline)
  5831. ;; Set delay to no later than DEADLINE.
  5832. (min (- schedule
  5833. (org-agenda--timestamp-to-absolute deadline))
  5834. org-scheduled-delay-days))
  5835. (t 0))))
  5836. (ddays
  5837. (cond
  5838. ;; Nullify delay when a repeater triggered already
  5839. ;; and the delay is of the form --Xd.
  5840. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  5841. (> current schedule))
  5842. 0)
  5843. (suppress-delay
  5844. (let ((org-scheduled-delay-days suppress-delay))
  5845. (org-get-wdays s t t)))
  5846. (t (org-get-wdays s t)))))
  5847. ;; Display scheduled items at base date (SCHEDULE), today if
  5848. ;; scheduled before the current date, and at any repeat past
  5849. ;; today. However, skip delayed items and items that have
  5850. ;; been displayed for more than `org-scheduled-past-days'.
  5851. (unless (and todayp
  5852. habitp
  5853. (bound-and-true-p org-habit-show-all-today))
  5854. (when (or (and (> ddays 0) (< diff ddays))
  5855. (> diff org-scheduled-past-days)
  5856. (> schedule current)
  5857. (and (< schedule current)
  5858. (not todayp)
  5859. (/= repeat current)))
  5860. (throw :skip nil)))
  5861. ;; Possibly skip done tasks.
  5862. (when (and donep
  5863. (or org-agenda-skip-scheduled-if-done
  5864. (/= schedule current)))
  5865. (throw :skip nil))
  5866. ;; Skip entry if it already appears as a deadline, per
  5867. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  5868. ;; doesn't apply to habits.
  5869. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  5870. ((guard
  5871. (or (not (memq (line-beginning-position 0) deadline-pos))
  5872. habitp))
  5873. nil)
  5874. (`repeated-after-deadline
  5875. (>= repeat (time-to-days (org-get-deadline-time (point)))))
  5876. (`not-today pastschedp)
  5877. (`t t)
  5878. (_ nil))
  5879. (throw :skip nil))
  5880. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  5881. ;; only show them for today. Also skip done habits.
  5882. (when (and habitp
  5883. (or donep
  5884. (not (bound-and-true-p org-habit-show-habits))
  5885. (and (not todayp)
  5886. (bound-and-true-p
  5887. org-habit-show-habits-only-for-today))))
  5888. (throw :skip nil))
  5889. (save-excursion
  5890. (re-search-backward "^\\*+[ \t]+" nil t)
  5891. (goto-char (match-end 0))
  5892. (let* ((category (org-get-category))
  5893. (inherited-tags
  5894. (or (eq org-agenda-show-inherited-tags 'always)
  5895. (and (listp org-agenda-show-inherited-tags)
  5896. (memq 'agenda org-agenda-show-inherited-tags))
  5897. (and (eq org-agenda-show-inherited-tags t)
  5898. (or (eq org-agenda-use-tag-inheritance t)
  5899. (memq 'agenda
  5900. org-agenda-use-tag-inheritance)))))
  5901. (tags (org-get-tags-at nil (not inherited-tags)))
  5902. (level
  5903. (make-string (org-reduced-level (org-outline-level)) ?\s))
  5904. (head (buffer-substring (point) (line-end-position)))
  5905. (time
  5906. (cond
  5907. ;; No time of day designation if it is only
  5908. ;; a reminder.
  5909. ((and (/= current schedule) (/= current repeat)) nil)
  5910. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5911. (concat (substring s (match-beginning 1)) " "))
  5912. (t 'time)))
  5913. (item
  5914. (org-agenda-format-item
  5915. (pcase-let ((`(,first ,next) org-agenda-scheduled-leaders))
  5916. (cond
  5917. ;; If CURRENT is in the future, don't use past
  5918. ;; scheduled prefix.
  5919. ((> current today) first)
  5920. ;; SHOW-ALL focuses on future repeats. If one
  5921. ;; such repeat happens today, ignore late
  5922. ;; schedule reminder. However, still report
  5923. ;; such reminders when repeat happens later.
  5924. ((and (not show-all) (= repeat today)) first)
  5925. ;; Initial report.
  5926. ((= schedule current) first)
  5927. ;; Subsequent reminders. Count from base
  5928. ;; schedule.
  5929. (t (format next diff))))
  5930. head level category tags time nil habitp))
  5931. (face (cond ((and (not habitp) pastschedp)
  5932. 'org-scheduled-previously)
  5933. (todayp 'org-scheduled-today)
  5934. (t 'org-scheduled)))
  5935. (habitp (and habitp (org-habit-parse-todo))))
  5936. (org-add-props item props
  5937. 'undone-face face
  5938. 'face (if donep 'org-agenda-done face)
  5939. 'org-marker (org-agenda-new-marker pos)
  5940. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5941. 'type (if pastschedp "past-scheduled" "scheduled")
  5942. 'date (if pastschedp schedule date)
  5943. 'ts-date schedule
  5944. 'warntime warntime
  5945. 'level level
  5946. 'priority (if habitp (org-habit-get-priority habitp)
  5947. (+ 99 diff (org-get-priority item)))
  5948. 'org-habit-p habitp
  5949. 'todo-state todo-state)
  5950. (push item scheduled-items))))))
  5951. (nreverse scheduled-items)))
  5952. (defun org-agenda-get-blocks ()
  5953. "Return the date-range information for agenda display."
  5954. (let* ((props (list 'face nil
  5955. 'org-not-done-regexp org-not-done-regexp
  5956. 'org-todo-regexp org-todo-regexp
  5957. 'org-complex-heading-regexp org-complex-heading-regexp
  5958. 'mouse-face 'highlight
  5959. 'help-echo
  5960. (format "mouse-2 or RET jump to org file %s"
  5961. (abbreviate-file-name buffer-file-name))))
  5962. (regexp org-tr-regexp)
  5963. (d0 (calendar-absolute-from-gregorian date))
  5964. marker hdmarker ee txt d1 d2 s1 s2 category
  5965. level todo-state tags pos head donep inherited-tags)
  5966. (goto-char (point-min))
  5967. (while (re-search-forward regexp nil t)
  5968. (catch :skip
  5969. (org-agenda-skip)
  5970. (setq pos (point))
  5971. (let ((start-time (match-string 1))
  5972. (end-time (match-string 2)))
  5973. (setq s1 (match-string 1)
  5974. s2 (match-string 2)
  5975. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5976. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5977. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5978. ;; Only allow days between the limits, because the normal
  5979. ;; date stamps will catch the limits.
  5980. (save-excursion
  5981. (setq todo-state (org-get-todo-state))
  5982. (setq donep (member todo-state org-done-keywords))
  5983. (if (and donep org-agenda-skip-timestamp-if-done)
  5984. (throw :skip t))
  5985. (setq marker (org-agenda-new-marker (point))
  5986. category (org-get-category))
  5987. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5988. (throw :skip nil)
  5989. (goto-char (match-beginning 0))
  5990. (setq hdmarker (org-agenda-new-marker (point))
  5991. inherited-tags
  5992. (or (eq org-agenda-show-inherited-tags 'always)
  5993. (and (listp org-agenda-show-inherited-tags)
  5994. (memq 'agenda org-agenda-show-inherited-tags))
  5995. (and (eq org-agenda-show-inherited-tags t)
  5996. (or (eq org-agenda-use-tag-inheritance t)
  5997. (memq 'agenda org-agenda-use-tag-inheritance))))
  5998. tags (org-get-tags-at nil (not inherited-tags)))
  5999. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6000. (looking-at "\\*+[ \t]+\\(.*\\)")
  6001. (setq head (match-string 1))
  6002. (let ((remove-re
  6003. (if org-agenda-remove-timeranges-from-blocks
  6004. (concat
  6005. "<" (regexp-quote s1) ".*?>"
  6006. "--"
  6007. "<" (regexp-quote s2) ".*?>")
  6008. nil)))
  6009. (setq txt (org-agenda-format-item
  6010. (format
  6011. (nth (if (= d1 d2) 0 1)
  6012. org-agenda-timerange-leaders)
  6013. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6014. head level category tags
  6015. (cond ((and (= d1 d0) (= d2 d0))
  6016. (concat "<" start-time ">--<" end-time ">"))
  6017. ((= d1 d0)
  6018. (concat "<" start-time ">"))
  6019. ((= d2 d0)
  6020. (concat "<" end-time ">")))
  6021. remove-re))))
  6022. (org-add-props txt props
  6023. 'org-marker marker 'org-hd-marker hdmarker
  6024. 'type "block" 'date date
  6025. 'level level
  6026. 'todo-state todo-state
  6027. 'priority (org-get-priority txt))
  6028. (push txt ee))))
  6029. (goto-char pos)))
  6030. ;; Sort the entries by expiration date.
  6031. (nreverse ee)))
  6032. ;;; Agenda presentation and sorting
  6033. (defvar org-prefix-has-time nil
  6034. "A flag, set by `org-compile-prefix-format'.
  6035. The flag is set if the currently compiled format contains a `%t'.")
  6036. (defvar org-prefix-has-tag nil
  6037. "A flag, set by `org-compile-prefix-format'.
  6038. The flag is set if the currently compiled format contains a `%T'.")
  6039. (defvar org-prefix-has-effort nil
  6040. "A flag, set by `org-compile-prefix-format'.
  6041. The flag is set if the currently compiled format contains a `%e'.")
  6042. (defvar org-prefix-has-breadcrumbs nil
  6043. "A flag, set by `org-compile-prefix-format'.
  6044. The flag is set if the currently compiled format contains a `%b'.")
  6045. (defvar org-prefix-category-length nil
  6046. "Used by `org-compile-prefix-format' to remember the category field width.")
  6047. (defvar org-prefix-category-max-length nil
  6048. "Used by `org-compile-prefix-format' to remember the category field width.")
  6049. (defun org-agenda-get-category-icon (category)
  6050. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6051. (cl-dolist (entry org-agenda-category-icon-alist)
  6052. (when (string-match-p (car entry) category)
  6053. (if (listp (cadr entry))
  6054. (cl-return (cadr entry))
  6055. (cl-return (apply #'create-image (cdr entry)))))))
  6056. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  6057. remove-re habitp)
  6058. "Format TXT to be inserted into the agenda buffer.
  6059. In particular, add the prefix and corresponding text properties.
  6060. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6061. LEVEL may be a string to replace the `%l' specifier.
  6062. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6063. category taken from local variable or file name. It will replace the `%c'
  6064. specifier in the format.
  6065. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6066. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6067. When DOTIME is a string, this string is searched for a time before TXT is.
  6068. TAGS can be the tags of the headline.
  6069. Any match of REMOVE-RE will be removed from TXT."
  6070. ;; We keep the org-prefix-* variable values along with a compiled
  6071. ;; formatter, so that multiple agendas existing at the same time do
  6072. ;; not step on each other toes.
  6073. ;;
  6074. ;; It was inconvenient to make these variables buffer local in
  6075. ;; Agenda buffers, because this function expects to be called with
  6076. ;; the buffer where item comes from being current, and not agenda
  6077. ;; buffer
  6078. (let* ((bindings (car org-prefix-format-compiled))
  6079. (formatter (cadr org-prefix-format-compiled)))
  6080. (cl-loop for (var value) in bindings
  6081. do (set var value))
  6082. (save-match-data
  6083. ;; Diary entries sometimes have extra whitespace at the beginning
  6084. (setq txt (org-trim txt))
  6085. ;; Fix the tags part in txt
  6086. (setq txt (org-agenda-fix-displayed-tags
  6087. txt tags
  6088. org-agenda-show-inherited-tags
  6089. org-agenda-hide-tags-regexp))
  6090. (let* ((category (or category
  6091. (if buffer-file-name
  6092. (file-name-sans-extension
  6093. (file-name-nondirectory buffer-file-name))
  6094. "")))
  6095. (category-icon (org-agenda-get-category-icon category))
  6096. (category-icon (if category-icon
  6097. (propertize " " 'display category-icon)
  6098. ""))
  6099. (effort (and (not (string= txt ""))
  6100. (get-text-property 1 'effort txt)))
  6101. ;; time, tag, effort are needed for the eval of the prefix format
  6102. (tag (if tags (nth (1- (length tags)) tags) ""))
  6103. time
  6104. (ts (if dotime (concat
  6105. (if (stringp dotime) dotime "")
  6106. (and org-agenda-search-headline-for-time txt))))
  6107. (time-of-day (and dotime (org-get-time-of-day ts)))
  6108. stamp plain s0 s1 s2 rtn srp l
  6109. duration breadcrumbs)
  6110. (and (derived-mode-p 'org-mode) buffer-file-name
  6111. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6112. (when (and dotime time-of-day)
  6113. ;; Extract starting and ending time and move them to prefix
  6114. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6115. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6116. (setq s0 (match-string 0 ts)
  6117. srp (and stamp (match-end 3))
  6118. s1 (match-string (if plain 1 2) ts)
  6119. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6120. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6121. ;; them, we might want to remove them there to avoid duplication.
  6122. ;; The user can turn this off with a variable.
  6123. (if (and org-prefix-has-time
  6124. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6125. (string-match (concat (regexp-quote s0) " *") txt)
  6126. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6127. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6128. (= (match-beginning 0) 0)
  6129. t))
  6130. (setq txt (replace-match "" nil nil txt))))
  6131. ;; Normalize the time(s) to 24 hour
  6132. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6133. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6134. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6135. (let (org-time-clocksum-use-effort-durations)
  6136. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6137. (setq s2
  6138. (org-minutes-to-clocksum-string
  6139. (+ (org-hh:mm-string-to-minutes s1)
  6140. org-agenda-default-appointment-duration)))))
  6141. ;; Compute the duration
  6142. (when s2
  6143. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6144. (org-hh:mm-string-to-minutes s1)))))
  6145. (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6146. ;; Tags are in the string
  6147. (if (or (eq org-agenda-remove-tags t)
  6148. (and org-agenda-remove-tags
  6149. org-prefix-has-tag))
  6150. (setq txt (replace-match "" t t txt))
  6151. (setq txt (replace-match
  6152. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6153. (match-string 2 txt))
  6154. t t txt))))
  6155. (when remove-re
  6156. (while (string-match remove-re txt)
  6157. (setq txt (replace-match "" t t txt))))
  6158. ;; Set org-heading property on `txt' to mark the start of the
  6159. ;; heading.
  6160. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6161. ;; Prepare the variables needed in the eval of the compiled format
  6162. (if org-prefix-has-breadcrumbs
  6163. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6164. (let ((s (org-display-outline-path nil nil "->" t)))
  6165. (if (eq "" s) "" (concat s "->"))))))
  6166. (setq time (cond (s2 (concat
  6167. (org-agenda-time-of-day-to-ampm-maybe s1)
  6168. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6169. (if org-agenda-timegrid-use-ampm " ")))
  6170. (s1 (concat
  6171. (org-agenda-time-of-day-to-ampm-maybe s1)
  6172. (if org-agenda-timegrid-use-ampm
  6173. "........ "
  6174. "......")))
  6175. (t ""))
  6176. extra (or (and (not habitp) extra) "")
  6177. category (if (symbolp category) (symbol-name category) category)
  6178. level (or level ""))
  6179. (if (string-match org-bracket-link-regexp category)
  6180. (progn
  6181. (setq l (if (match-end 3)
  6182. (- (match-end 3) (match-beginning 3))
  6183. (- (match-end 1) (match-beginning 1))))
  6184. (when (< l (or org-prefix-category-length 0))
  6185. (setq category (copy-sequence category))
  6186. (org-add-props category nil
  6187. 'extra-space (make-string
  6188. (- org-prefix-category-length l 1) ?\ ))))
  6189. (if (and org-prefix-category-max-length
  6190. (>= (length category) org-prefix-category-max-length))
  6191. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6192. ;; Evaluate the compiled format
  6193. (setq rtn (concat (eval formatter) txt))
  6194. ;; And finally add the text properties
  6195. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6196. (org-add-props rtn nil
  6197. 'org-category category
  6198. 'tags (mapcar 'org-downcase-keep-props tags)
  6199. 'org-highest-priority org-highest-priority
  6200. 'org-lowest-priority org-lowest-priority
  6201. 'time-of-day time-of-day
  6202. 'duration duration
  6203. 'breadcrumbs breadcrumbs
  6204. 'txt txt
  6205. 'level level
  6206. 'time time
  6207. 'extra extra
  6208. 'format org-prefix-format-compiled
  6209. 'dotime dotime)))))
  6210. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6211. "Remove tags string from TXT, and add a modified list of tags.
  6212. The modified list may contain inherited tags, and tags matched by
  6213. `org-agenda-hide-tags-regexp' will be removed."
  6214. (when (or add-inherited hide-re)
  6215. (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
  6216. (setq txt (substring txt 0 (match-beginning 0))))
  6217. (setq tags
  6218. (delq nil
  6219. (mapcar (lambda (tg)
  6220. (if (or (and hide-re (string-match hide-re tg))
  6221. (and (not add-inherited)
  6222. (get-text-property 0 'inherited tg)))
  6223. nil
  6224. tg))
  6225. tags)))
  6226. (when tags
  6227. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6228. i)
  6229. (setq txt (concat txt " :"
  6230. (mapconcat
  6231. (lambda (x)
  6232. (setq i (get-text-property 0 'inherited x))
  6233. (if (and have-i (not i))
  6234. (progn
  6235. (setq have-i nil)
  6236. (concat ":" x))
  6237. x))
  6238. tags ":")
  6239. (if have-i "::" ":"))))))
  6240. txt)
  6241. (defun org-downcase-keep-props (s)
  6242. (let ((props (text-properties-at 0 s)))
  6243. (setq s (downcase s))
  6244. (add-text-properties 0 (length s) props s)
  6245. s))
  6246. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6247. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6248. "Add a time-grid for agenda items which need it.
  6249. LIST is the list of agenda items formatted by `org-agenda-list'.
  6250. NDAYS is the span of the current agenda view.
  6251. TODAYP is t when the current agenda view is on today."
  6252. (catch 'exit
  6253. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6254. ((and todayp (member 'today (car org-agenda-time-grid))))
  6255. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6256. ((member 'weekly (car org-agenda-time-grid)))
  6257. (t (throw 'exit list)))
  6258. (let* ((have (delq nil (mapcar
  6259. (lambda (x) (get-text-property 1 'time-of-day x))
  6260. list)))
  6261. (string (nth 1 org-agenda-time-grid))
  6262. (gridtimes (nth 2 org-agenda-time-grid))
  6263. (req (car org-agenda-time-grid))
  6264. (remove (member 'remove-match req))
  6265. new time)
  6266. (if (and (member 'require-timed req) (not have))
  6267. ;; don't show empty grid
  6268. (throw 'exit list))
  6269. (while (setq time (pop gridtimes))
  6270. (unless (and remove (member time have))
  6271. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6272. (push (org-agenda-format-item
  6273. nil string nil "" nil
  6274. (concat (substring time 0 -2) ":" (substring time -2)))
  6275. new)
  6276. (put-text-property
  6277. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6278. (when (and todayp org-agenda-show-current-time-in-grid)
  6279. (push (org-agenda-format-item
  6280. nil org-agenda-current-time-string nil "" nil
  6281. (format-time-string "%H:%M "))
  6282. new)
  6283. (put-text-property
  6284. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6285. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6286. (append new list)
  6287. (append list new)))))
  6288. (defun org-compile-prefix-format (key)
  6289. "Compile the prefix format into a Lisp form that can be evaluated.
  6290. The resulting form and associated variable bindings is returned
  6291. and stored in the variable `org-prefix-format-compiled'."
  6292. (setq org-prefix-has-time nil
  6293. org-prefix-has-tag nil
  6294. org-prefix-category-length nil
  6295. org-prefix-has-effort nil
  6296. org-prefix-has-breadcrumbs nil)
  6297. (let ((s (cond
  6298. ((stringp org-agenda-prefix-format)
  6299. org-agenda-prefix-format)
  6300. ((assq key org-agenda-prefix-format)
  6301. (cdr (assq key org-agenda-prefix-format)))
  6302. (t " %-12:c%?-12t% s")))
  6303. (start 0)
  6304. varform vars var e c f opt)
  6305. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6306. s start)
  6307. (setq var (or (cdr (assoc (match-string 4 s)
  6308. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6309. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6310. 'eval)
  6311. c (or (match-string 3 s) "")
  6312. opt (match-beginning 1)
  6313. start (1+ (match-beginning 0)))
  6314. (if (eq var 'time) (setq org-prefix-has-time t))
  6315. (if (eq var 'tag) (setq org-prefix-has-tag t))
  6316. (if (eq var 'effort) (setq org-prefix-has-effort t))
  6317. (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6318. (setq f (concat "%" (match-string 2 s) "s"))
  6319. (when (eq var 'category)
  6320. (setq org-prefix-category-length
  6321. (floor (abs (string-to-number (match-string 2 s)))))
  6322. (setq org-prefix-category-max-length
  6323. (let ((x (match-string 2 s)))
  6324. (save-match-data
  6325. (if (string-match "\\.[0-9]+" x)
  6326. (string-to-number (substring (match-string 0 x) 1)))))))
  6327. (if (eq var 'eval)
  6328. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6329. (if opt
  6330. (setq varform
  6331. `(if (or (equal "" ,var) (equal nil ,var))
  6332. ""
  6333. (format ,f (concat ,var ,c))))
  6334. (setq varform
  6335. `(format ,f (if (or (equal ,var "")
  6336. (equal ,var nil)) ""
  6337. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6338. (setq s (replace-match "%s" t nil s))
  6339. (push varform vars))
  6340. (setq vars (nreverse vars))
  6341. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6342. (setq org-prefix-format-compiled
  6343. (list
  6344. `((org-prefix-has-time ,org-prefix-has-time)
  6345. (org-prefix-has-tag ,org-prefix-has-tag)
  6346. (org-prefix-category-length ,org-prefix-category-length)
  6347. (org-prefix-has-effort ,org-prefix-has-effort)
  6348. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6349. `(format ,s ,@vars))))))
  6350. (defun org-set-sorting-strategy (key)
  6351. (if (symbolp (car org-agenda-sorting-strategy))
  6352. ;; the old format
  6353. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6354. (setq org-agenda-sorting-strategy-selected
  6355. (or (cdr (assq key org-agenda-sorting-strategy))
  6356. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6357. '(time-up category-keep priority-down)))))
  6358. (defun org-get-time-of-day (s &optional string mod24)
  6359. "Check string S for a time of day.
  6360. If found, return it as a military time number between 0 and 2400.
  6361. If not found, return nil.
  6362. The optional STRING argument forces conversion into a 5 character wide string
  6363. HH:MM."
  6364. (save-match-data
  6365. (when
  6366. (and
  6367. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6368. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6369. (not (eq (get-text-property 1 'face s) 'org-link)))
  6370. (let* ((h (string-to-number (match-string 1 s)))
  6371. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6372. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6373. (am-p (equal ampm "am"))
  6374. (h1 (cond ((not ampm) h)
  6375. ((= h 12) (if am-p 0 12))
  6376. (t (+ h (if am-p 0 12)))))
  6377. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6378. (mod h1 24) h1))
  6379. (t0 (+ (* 100 h2) m))
  6380. (t1 (concat (if (>= h1 24) "+" " ")
  6381. (if (and org-agenda-time-leading-zero
  6382. (< t0 1000)) "0" "")
  6383. (if (< t0 100) "0" "")
  6384. (if (< t0 10) "0" "")
  6385. (int-to-string t0))))
  6386. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6387. (defvar org-agenda-before-sorting-filter-function nil
  6388. "Function to be applied to agenda items prior to sorting.
  6389. Prior to sorting also means just before they are inserted into the agenda.
  6390. To aid sorting, you may revisit the original entries and add more text
  6391. properties which will later be used by the sorting functions.
  6392. The function should take a string argument, an agenda line.
  6393. It has access to the text properties in that line, which contain among
  6394. other things, the property `org-hd-marker' that points to the entry
  6395. where the line comes from. Note that not all lines going into the agenda
  6396. have this property, only most.
  6397. The function should return the modified string. It is probably best
  6398. to ONLY change text properties.
  6399. You can also use this function as a filter, by returning nil for lines
  6400. you don't want to have in the agenda at all. For this application, you
  6401. could bind the variable in the options section of a custom command.")
  6402. (defun org-agenda-finalize-entries (list &optional type)
  6403. "Sort, limit and concatenate the LIST of agenda items.
  6404. The optional argument TYPE tells the agenda type."
  6405. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6406. (cdr (assoc type org-agenda-max-effort)))
  6407. (t org-agenda-max-effort)))
  6408. (max-todo (cond ((listp org-agenda-max-todos)
  6409. (cdr (assoc type org-agenda-max-todos)))
  6410. (t org-agenda-max-todos)))
  6411. (max-tags (cond ((listp org-agenda-max-tags)
  6412. (cdr (assoc type org-agenda-max-tags)))
  6413. (t org-agenda-max-tags)))
  6414. (max-entries (cond ((listp org-agenda-max-entries)
  6415. (cdr (assoc type org-agenda-max-entries)))
  6416. (t org-agenda-max-entries))))
  6417. (when org-agenda-before-sorting-filter-function
  6418. (setq list
  6419. (delq nil
  6420. (mapcar
  6421. org-agenda-before-sorting-filter-function list))))
  6422. (setq list (mapcar 'org-agenda-highlight-todo list)
  6423. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6424. (when max-effort
  6425. (setq list (org-agenda-limit-entries
  6426. list 'effort-minutes max-effort
  6427. (lambda (e) (or e (if org-sort-agenda-noeffort-is-high
  6428. 32767 -1))))))
  6429. (when max-todo
  6430. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6431. (when max-tags
  6432. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6433. (when max-entries
  6434. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6435. (mapconcat 'identity list "\n")))
  6436. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6437. "Limit the number of agenda entries."
  6438. (let ((include (and limit (< limit 0))))
  6439. (if limit
  6440. (let ((fun (or fn (lambda (p) (if p 1))))
  6441. (lim 0))
  6442. (delq nil
  6443. (mapcar
  6444. (lambda (e)
  6445. (let ((pval (funcall
  6446. fun (get-text-property (1- (length e))
  6447. prop e))))
  6448. (if pval (setq lim (+ lim pval)))
  6449. (cond ((and pval (<= lim (abs limit))) e)
  6450. ((and include (not pval)) e))))
  6451. list)))
  6452. list)))
  6453. (defun org-agenda-limit-interactively (remove)
  6454. "In agenda, interactively limit entries to various maximums."
  6455. (interactive "P")
  6456. (if remove
  6457. (progn (setq org-agenda-max-entries nil
  6458. org-agenda-max-todos nil
  6459. org-agenda-max-tags nil
  6460. org-agenda-max-effort nil)
  6461. (org-agenda-redo))
  6462. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6463. (msg (cond ((= max ?E) "How many minutes? ")
  6464. ((= max ?e) "How many entries? ")
  6465. ((= max ?t) "How many TODO entries? ")
  6466. ((= max ?T) "How many tagged entries? ")
  6467. (t (user-error "Wrong input"))))
  6468. (num (string-to-number (read-from-minibuffer msg))))
  6469. (cond ((equal max ?e)
  6470. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6471. ((equal max ?t)
  6472. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6473. ((equal max ?T)
  6474. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6475. ((equal max ?E)
  6476. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  6477. (org-agenda-fit-window-to-buffer))
  6478. (defun org-agenda-highlight-todo (x)
  6479. (let ((org-done-keywords org-done-keywords-for-agenda)
  6480. (case-fold-search nil)
  6481. re)
  6482. (if (eq x 'line)
  6483. (save-excursion
  6484. (beginning-of-line 1)
  6485. (setq re (org-get-at-bol 'org-todo-regexp))
  6486. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6487. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6488. (add-text-properties (match-beginning 0) (match-end 1)
  6489. (list 'face (org-get-todo-face 1)))
  6490. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6491. (delete-region (match-beginning 1) (1- (match-end 0)))
  6492. (goto-char (match-beginning 1))
  6493. (insert (format org-agenda-todo-keyword-format s)))))
  6494. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6495. (setq re (get-text-property 0 'org-todo-regexp x))
  6496. (when (and re
  6497. ;; Test `pl' because if there's no heading content,
  6498. ;; there's no point matching to highlight. Note
  6499. ;; that if we didn't test `pl' first, and there
  6500. ;; happened to be no keyword from `org-todo-regexp'
  6501. ;; on this heading line, then the `equal' comparison
  6502. ;; afterwards would spuriously succeed in the case
  6503. ;; where `pl' is nil -- causing an args-out-of-range
  6504. ;; error when we try to add text properties to text
  6505. ;; that isn't there.
  6506. pl
  6507. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6508. x pl) pl))
  6509. (add-text-properties
  6510. (or (match-end 1) (match-end 0)) (match-end 0)
  6511. (list 'face (org-get-todo-face (match-string 2 x)))
  6512. x)
  6513. (when (match-end 1)
  6514. (setq x (concat (substring x 0 (match-end 1))
  6515. (format org-agenda-todo-keyword-format
  6516. (match-string 2 x))
  6517. (org-add-props " " (text-properties-at 0 x))
  6518. (substring x (match-end 3)))))))
  6519. x)))
  6520. (defsubst org-cmp-values (a b property)
  6521. "Compare the numeric value of text PROPERTY for string A and B."
  6522. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6523. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6524. (cond ((> pa pb) +1)
  6525. ((< pa pb) -1))))
  6526. (defsubst org-cmp-effort (a b)
  6527. "Compare the effort values of string A and B."
  6528. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6529. ;; `effort-minutes' property is not directly accessible from
  6530. ;; the strings, but is stored as a property in `txt'.
  6531. (ea (or (get-text-property
  6532. 0 'effort-minutes (get-text-property 0 'txt a))
  6533. def))
  6534. (eb (or (get-text-property
  6535. 0 'effort-minutes (get-text-property 0 'txt b))
  6536. def)))
  6537. (cond ((> ea eb) +1)
  6538. ((< ea eb) -1))))
  6539. (defsubst org-cmp-category (a b)
  6540. "Compare the string values of categories of strings A and B."
  6541. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6542. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6543. (cond ((string-lessp ca cb) -1)
  6544. ((string-lessp cb ca) +1))))
  6545. (defsubst org-cmp-todo-state (a b)
  6546. "Compare the todo states of strings A and B."
  6547. (let* ((ma (or (get-text-property 1 'org-marker a)
  6548. (get-text-property 1 'org-hd-marker a)))
  6549. (mb (or (get-text-property 1 'org-marker b)
  6550. (get-text-property 1 'org-hd-marker b)))
  6551. (fa (and ma (marker-buffer ma)))
  6552. (fb (and mb (marker-buffer mb)))
  6553. (todo-kwds
  6554. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6555. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6556. (ta (or (get-text-property 1 'todo-state a) ""))
  6557. (tb (or (get-text-property 1 'todo-state b) ""))
  6558. (la (- (length (member ta todo-kwds))))
  6559. (lb (- (length (member tb todo-kwds))))
  6560. (donepa (member ta org-done-keywords-for-agenda))
  6561. (donepb (member tb org-done-keywords-for-agenda)))
  6562. (cond ((and donepa (not donepb)) -1)
  6563. ((and (not donepa) donepb) +1)
  6564. ((< la lb) -1)
  6565. ((< lb la) +1))))
  6566. (defsubst org-cmp-alpha (a b)
  6567. "Compare the headlines, alphabetically."
  6568. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6569. (plb (text-property-any 0 (length b) 'org-heading t b))
  6570. (ta (and pla (substring a pla)))
  6571. (tb (and plb (substring b plb)))
  6572. (case-fold-search nil))
  6573. (when pla
  6574. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6575. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6576. (setq ta (substring ta (match-end 0))))
  6577. (setq ta (downcase ta)))
  6578. (when plb
  6579. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6580. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6581. (setq tb (substring tb (match-end 0))))
  6582. (setq tb (downcase tb)))
  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-tag (a b)
  6588. "Compare the string values of the first tags of A and B."
  6589. (let ((ta (car (last (get-text-property 1 'tags a))))
  6590. (tb (car (last (get-text-property 1 'tags b)))))
  6591. (cond ((not ta) +1)
  6592. ((not tb) -1)
  6593. ((string-lessp ta tb) -1)
  6594. ((string-lessp tb ta) +1))))
  6595. (defsubst org-cmp-time (a b)
  6596. "Compare the time-of-day values of strings A and B."
  6597. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6598. (ta (or (get-text-property 1 'time-of-day a) def))
  6599. (tb (or (get-text-property 1 'time-of-day b) def)))
  6600. (cond ((< ta tb) -1)
  6601. ((< tb ta) +1))))
  6602. (defsubst org-cmp-ts (a b type)
  6603. "Compare the timestamps values of entries A and B.
  6604. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6605. \"timestamp_ia\", compare within each of these type. When TYPE
  6606. is the empty string, compare all timestamps without respect of
  6607. their type."
  6608. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6609. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6610. (get-text-property 1 'ts-date a))
  6611. def))
  6612. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6613. (get-text-property 1 'ts-date b))
  6614. def)))
  6615. (cond ((< ta tb) -1)
  6616. ((< tb ta) +1))))
  6617. (defsubst org-cmp-habit-p (a b)
  6618. "Compare the todo states of strings A and B."
  6619. (let ((ha (get-text-property 1 'org-habit-p a))
  6620. (hb (get-text-property 1 'org-habit-p b)))
  6621. (cond ((and ha (not hb)) -1)
  6622. ((and (not ha) hb) +1))))
  6623. (defun org-entries-lessp (a b)
  6624. "Predicate for sorting agenda entries."
  6625. ;; The following variables will be used when the form is evaluated.
  6626. ;; So even though the compiler complains, keep them.
  6627. (let* ((ss org-agenda-sorting-strategy-selected)
  6628. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6629. (org-cmp-ts a b "")))
  6630. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6631. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6632. (org-cmp-ts a b "scheduled")))
  6633. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6634. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6635. (org-cmp-ts a b "deadline")))
  6636. (deadline-down (if deadline-up (- deadline-up) nil))
  6637. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6638. (org-cmp-ts a b "timestamp_ia")))
  6639. (tsia-down (if tsia-up (- tsia-up) nil))
  6640. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6641. (org-cmp-ts a b "timestamp")))
  6642. (ts-down (if ts-up (- ts-up) nil))
  6643. (time-up (and (org-em 'time-up 'time-down ss)
  6644. (org-cmp-time a b)))
  6645. (time-down (if time-up (- time-up) nil))
  6646. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6647. (org-cmp-values a b 'org-stats)))
  6648. (stats-down (if stats-up (- stats-up) nil))
  6649. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6650. (org-cmp-values a b 'priority)))
  6651. (priority-down (if priority-up (- priority-up) nil))
  6652. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6653. (org-cmp-effort a b)))
  6654. (effort-down (if effort-up (- effort-up) nil))
  6655. (category-up (and (or (org-em 'category-up 'category-down ss)
  6656. (memq 'category-keep ss))
  6657. (org-cmp-category a b)))
  6658. (category-down (if category-up (- category-up) nil))
  6659. (category-keep (if category-up +1 nil))
  6660. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6661. (org-cmp-tag a b)))
  6662. (tag-down (if tag-up (- tag-up) nil))
  6663. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6664. (org-cmp-todo-state a b)))
  6665. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6666. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6667. (org-cmp-habit-p a b)))
  6668. (habit-down (if habit-up (- habit-up) nil))
  6669. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6670. (org-cmp-alpha a b)))
  6671. (alpha-down (if alpha-up (- alpha-up) nil))
  6672. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6673. user-defined-up user-defined-down)
  6674. (if (and need-user-cmp org-agenda-cmp-user-defined
  6675. (functionp org-agenda-cmp-user-defined))
  6676. (setq user-defined-up
  6677. (funcall org-agenda-cmp-user-defined a b)
  6678. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6679. (cdr (assoc
  6680. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6681. '((-1 . t) (1 . nil) (nil . nil))))))
  6682. ;;; Agenda restriction lock
  6683. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6684. "Overlay to mark the headline to which agenda commands are restricted.")
  6685. (overlay-put org-agenda-restriction-lock-overlay
  6686. 'face 'org-agenda-restriction-lock)
  6687. (overlay-put org-agenda-restriction-lock-overlay
  6688. 'help-echo "Agendas are currently limited to this subtree.")
  6689. (delete-overlay org-agenda-restriction-lock-overlay)
  6690. ;;;###autoload
  6691. (defun org-agenda-set-restriction-lock (&optional type)
  6692. "Set restriction lock for agenda, to current subtree or file.
  6693. Restriction will be the file if TYPE is `file', or if type is the
  6694. universal prefix \\='(4), or if the cursor is before the first headline
  6695. in the file. Otherwise, restriction will be to the current subtree."
  6696. (interactive "P")
  6697. (org-agenda-remove-restriction-lock 'noupdate)
  6698. (and (equal type '(4)) (setq type 'file))
  6699. (setq type (cond
  6700. (type type)
  6701. ((org-at-heading-p) 'subtree)
  6702. ((condition-case nil (org-back-to-heading t) (error nil))
  6703. 'subtree)
  6704. (t 'file)))
  6705. (if (eq type 'subtree)
  6706. (progn
  6707. (setq org-agenda-restrict (current-buffer))
  6708. (setq org-agenda-overriding-restriction 'subtree)
  6709. (put 'org-agenda-files 'org-restrict
  6710. (list (buffer-file-name (buffer-base-buffer))))
  6711. (org-back-to-heading t)
  6712. (move-overlay org-agenda-restriction-lock-overlay
  6713. (point)
  6714. (if org-agenda-restriction-lock-highlight-subtree
  6715. (save-excursion (org-end-of-subtree t t) (point))
  6716. (point-at-eol)))
  6717. (move-marker org-agenda-restrict-begin (point))
  6718. (move-marker org-agenda-restrict-end
  6719. (save-excursion (org-end-of-subtree t t)))
  6720. (message "Locking agenda restriction to subtree"))
  6721. (put 'org-agenda-files 'org-restrict
  6722. (list (buffer-file-name (buffer-base-buffer))))
  6723. (setq org-agenda-restrict nil)
  6724. (setq org-agenda-overriding-restriction 'file)
  6725. (move-marker org-agenda-restrict-begin nil)
  6726. (move-marker org-agenda-restrict-end nil)
  6727. (message "Locking agenda restriction to file"))
  6728. (setq current-prefix-arg nil)
  6729. (org-agenda-maybe-redo))
  6730. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6731. "Remove the agenda restriction lock."
  6732. (interactive "P")
  6733. (delete-overlay org-agenda-restriction-lock-overlay)
  6734. (delete-overlay org-speedbar-restriction-lock-overlay)
  6735. (setq org-agenda-overriding-restriction nil)
  6736. (setq org-agenda-restrict nil)
  6737. (put 'org-agenda-files 'org-restrict nil)
  6738. (move-marker org-agenda-restrict-begin nil)
  6739. (move-marker org-agenda-restrict-end nil)
  6740. (setq current-prefix-arg nil)
  6741. (message "Agenda restriction lock removed")
  6742. (or noupdate (org-agenda-maybe-redo)))
  6743. (defun org-agenda-maybe-redo ()
  6744. "If there is any window showing the agenda view, update it."
  6745. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  6746. org-agenda-buffer-name)
  6747. t))
  6748. (w0 (selected-window)))
  6749. (when w
  6750. (select-window w)
  6751. (org-agenda-redo)
  6752. (select-window w0)
  6753. (if org-agenda-overriding-restriction
  6754. (message "Agenda view shifted to new %s restriction"
  6755. org-agenda-overriding-restriction)
  6756. (message "Agenda restriction lock removed")))))
  6757. ;;; Agenda commands
  6758. (defun org-agenda-check-type (error &rest types)
  6759. "Check if agenda buffer is of allowed type.
  6760. If ERROR is non-nil, throw an error, otherwise just return nil.
  6761. Allowed types are `agenda' `timeline' `todo' `tags' `search'."
  6762. (if (not org-agenda-type)
  6763. (error "No Org agenda currently displayed")
  6764. (if (memq org-agenda-type types)
  6765. t
  6766. (if error
  6767. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6768. nil))))
  6769. (defun org-agenda-Quit ()
  6770. "Exit the agenda, killing the agenda buffer.
  6771. Like `org-agenda-quit', but kill the buffer even when
  6772. `org-agenda-sticky' is non-nil."
  6773. (interactive)
  6774. (org-agenda--quit))
  6775. (defun org-agenda-quit ()
  6776. "Exit the agenda.
  6777. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  6778. instead of killing it.
  6779. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  6780. the pre-agenda window configuration.
  6781. When column view is active, exit column view instead of the
  6782. agenda."
  6783. (interactive)
  6784. (org-agenda--quit org-agenda-sticky))
  6785. (defun org-agenda--quit (&optional bury)
  6786. (if org-agenda-columns-active
  6787. (org-columns-quit)
  6788. (let ((wconf org-agenda-pre-window-conf)
  6789. (buf (current-buffer))
  6790. (org-agenda-last-indirect-window
  6791. (and (eq org-indirect-buffer-display 'other-window)
  6792. org-agenda-last-indirect-buffer
  6793. (get-buffer-window org-agenda-last-indirect-buffer))))
  6794. (cond
  6795. ((eq org-agenda-window-setup 'other-frame)
  6796. (delete-frame))
  6797. ((and org-agenda-restore-windows-after-quit
  6798. wconf)
  6799. ;; Maybe restore the pre-agenda window configuration. Reset
  6800. ;; `org-agenda-pre-window-conf' before running
  6801. ;; `set-window-configuration', which loses the current buffer.
  6802. (setq org-agenda-pre-window-conf nil)
  6803. (set-window-configuration wconf))
  6804. (t
  6805. (when org-agenda-last-indirect-window
  6806. (delete-window org-agenda-last-indirect-window))
  6807. (and (not (eq org-agenda-window-setup 'current-window))
  6808. (not (one-window-p))
  6809. (delete-window))))
  6810. (if bury
  6811. ;; Set the agenda buffer as the current buffer instead of
  6812. ;; passing it as an argument to `bury-buffer' so that
  6813. ;; `bury-buffer' removes it from the window.
  6814. (with-current-buffer buf
  6815. (bury-buffer))
  6816. (kill-buffer buf)
  6817. (setq org-agenda-archives-mode nil
  6818. org-agenda-buffer nil)))))
  6819. (defun org-agenda-exit ()
  6820. "Exit the agenda, killing Org buffers loaded by the agenda.
  6821. Like `org-agenda-Quit', but kill any buffers that were created by
  6822. the agenda. Org buffers visited directly by the user will not be
  6823. touched. Also, exit the agenda even if it is in column view."
  6824. (interactive)
  6825. (when org-agenda-columns-active
  6826. (org-columns-quit))
  6827. (org-release-buffers org-agenda-new-buffers)
  6828. (setq org-agenda-new-buffers nil)
  6829. (org-agenda-Quit))
  6830. (defun org-agenda-kill-all-agenda-buffers ()
  6831. "Kill all buffers in `org-agenda-mode'.
  6832. This is used when toggling sticky agendas."
  6833. (interactive)
  6834. (let (blist)
  6835. (dolist (buf (buffer-list))
  6836. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6837. (push buf blist)))
  6838. (mapc 'kill-buffer blist)))
  6839. (defun org-agenda-execute (arg)
  6840. "Execute another agenda command, keeping same window.
  6841. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6842. in the agenda."
  6843. (interactive "P")
  6844. (let ((org-agenda-window-setup 'current-window))
  6845. (org-agenda arg)))
  6846. (defun org-agenda-redo (&optional all)
  6847. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6848. (interactive "P")
  6849. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6850. (cpa (unless (eq all t) current-prefix-arg))
  6851. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6852. (org-agenda-sticky nil)
  6853. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6854. org-agenda-buffer-name))
  6855. (org-agenda-keep-modes t)
  6856. (tag-filter org-agenda-tag-filter)
  6857. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6858. (top-hl-filter org-agenda-top-headline-filter)
  6859. (cat-filter org-agenda-category-filter)
  6860. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6861. (re-filter org-agenda-regexp-filter)
  6862. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6863. (effort-filter org-agenda-effort-filter)
  6864. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  6865. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6866. (cols org-agenda-columns-active)
  6867. (line (org-current-line))
  6868. (window-line (- line (org-current-line (window-start))))
  6869. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6870. (redo-cmd (get-text-property p 'org-redo-cmd))
  6871. (last-args (get-text-property p 'org-last-args))
  6872. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6873. (org-agenda-overriding-cmd-arguments
  6874. (unless (eq all t)
  6875. (cond ((listp last-args)
  6876. (cons (or cpa (car last-args)) (cdr last-args)))
  6877. ((stringp last-args)
  6878. last-args))))
  6879. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6880. (put 'org-agenda-tag-filter :preset-filter nil)
  6881. (put 'org-agenda-category-filter :preset-filter nil)
  6882. (put 'org-agenda-regexp-filter :preset-filter nil)
  6883. (put 'org-agenda-effort-filter :preset-filter nil)
  6884. (and cols (org-columns-quit))
  6885. (message "Rebuilding agenda buffer...")
  6886. (if series-redo-cmd
  6887. (eval series-redo-cmd)
  6888. (org-let lprops redo-cmd))
  6889. (setq org-agenda-undo-list nil
  6890. org-agenda-pending-undo-list nil
  6891. org-agenda-tag-filter tag-filter
  6892. org-agenda-category-filter cat-filter
  6893. org-agenda-regexp-filter re-filter
  6894. org-agenda-effort-filter effort-filter
  6895. org-agenda-top-headline-filter top-hl-filter)
  6896. (message "Rebuilding agenda buffer...done")
  6897. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6898. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6899. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6900. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  6901. (let ((tag (or tag-filter tag-preset))
  6902. (cat (or cat-filter cat-preset))
  6903. (effort (or effort-filter effort-preset))
  6904. (re (or re-filter re-preset)))
  6905. (when tag (org-agenda-filter-apply tag 'tag t))
  6906. (when cat (org-agenda-filter-apply cat 'category))
  6907. (when effort (org-agenda-filter-apply effort 'effort))
  6908. (when re (org-agenda-filter-apply re 'regexp)))
  6909. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6910. (and cols (called-interactively-p 'any) (org-agenda-columns))
  6911. (org-goto-line line)
  6912. (recenter window-line)))
  6913. (defvar org-global-tags-completion-table nil)
  6914. (defvar org-agenda-filter-form nil)
  6915. (defvar org-agenda-filtered-by-category nil)
  6916. (defun org-agenda-filter-by-category (strip)
  6917. "Filter lines in the agenda buffer that have a specific category.
  6918. The category is that of the current line.
  6919. Without prefix argument, keep only the lines of that category.
  6920. With a prefix argument, exclude the lines of that category.
  6921. "
  6922. (interactive "P")
  6923. (if (and org-agenda-filtered-by-category
  6924. org-agenda-category-filter)
  6925. (org-agenda-filter-show-all-cat)
  6926. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6927. (cond
  6928. ((and cat strip)
  6929. (org-agenda-filter-apply
  6930. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6931. (cat
  6932. (org-agenda-filter-apply
  6933. (setq org-agenda-category-filter
  6934. (list (concat "+" cat))) 'category))
  6935. (t (error "No category at point"))))))
  6936. (defun org-find-top-headline (&optional pos)
  6937. "Find the topmost parent headline and return it.
  6938. POS when non-nil is the marker or buffer position to start the
  6939. search from."
  6940. (save-excursion
  6941. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  6942. (when pos (goto-char pos))
  6943. ;; Skip up to the topmost parent.
  6944. (while (org-up-heading-safe))
  6945. (ignore-errors (nth 4 (org-heading-components))))))
  6946. (defvar org-agenda-filtered-by-top-headline nil)
  6947. (defun org-agenda-filter-by-top-headline (strip)
  6948. "Keep only those lines that are descendants from the same top headline.
  6949. The top headline is that of the current line."
  6950. (interactive "P")
  6951. (if org-agenda-filtered-by-top-headline
  6952. (progn
  6953. (setq org-agenda-filtered-by-top-headline nil
  6954. org-agenda-top-headline-filter nil)
  6955. (org-agenda-filter-show-all-top-filter))
  6956. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6957. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6958. (error "No top-level headline at point")))))
  6959. (defvar org-agenda-regexp-filter nil)
  6960. (defun org-agenda-filter-by-regexp (strip)
  6961. "Filter agenda entries by a regular expression.
  6962. Regexp filters are cumulative.
  6963. With no prefix argument, keep entries matching the regexp.
  6964. With one prefix argument, filter out entries matching the regexp.
  6965. With two prefix arguments, remove the regexp filters."
  6966. (interactive "P")
  6967. (if (not (equal strip '(16)))
  6968. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6969. (read-from-minibuffer
  6970. (if (equal strip '(4))
  6971. "Filter out entries matching regexp: "
  6972. "Narrow to entries matching regexp: ")))))
  6973. (push flt org-agenda-regexp-filter)
  6974. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6975. (org-agenda-filter-show-all-re)
  6976. (message "Regexp filter removed")))
  6977. (defvar org-agenda-effort-filter nil)
  6978. (defun org-agenda-filter-by-effort (strip)
  6979. "Filter agenda entries by effort.
  6980. With no prefix argument, keep entries matching the effort condition.
  6981. With one prefix argument, filter out entries matching the condition.
  6982. With two prefix arguments, remove the effort filters."
  6983. (interactive "P")
  6984. (cond
  6985. ((member strip '(nil 4))
  6986. (let* ((efforts (split-string
  6987. (or (cdr (assoc (concat org-effort-property "_ALL")
  6988. org-global-properties))
  6989. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  6990. ;; XXX: the following handles only up to 10 different
  6991. ;; effort values.
  6992. (allowed-keys (if (null efforts) nil
  6993. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  6994. (number-sequence 1 (length efforts)))))
  6995. (op nil))
  6996. (while (not (memq op '(?< ?> ?=)))
  6997. (setq op (read-char-exclusive "Effort operator? (> = or <)")))
  6998. ;; Select appropriate duration. Ignore non-digit characters.
  6999. (let ((prompt
  7000. (apply #'format
  7001. (concat "Effort %c "
  7002. (mapconcat (lambda (s) (concat "[%d]" s))
  7003. efforts
  7004. " "))
  7005. op allowed-keys))
  7006. (eff -1))
  7007. (while (not (memq eff allowed-keys))
  7008. (message prompt)
  7009. (setq eff (- (read-char-exclusive) 48)))
  7010. (setq org-agenda-effort-filter
  7011. (list (concat (if strip "-" "+")
  7012. (char-to-string op)
  7013. ;; Numbering is 1 2 3 ... 9 0, but we want
  7014. ;; 0 1 2 ... 8 9.
  7015. (nth (mod (1- eff) 10) efforts)))))
  7016. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
  7017. (t (org-agenda-filter-show-all-effort)
  7018. (message "Effort filter removed"))))
  7019. (defun org-agenda-filter-remove-all ()
  7020. "Remove all filters from the current agenda buffer."
  7021. (interactive)
  7022. (when org-agenda-tag-filter
  7023. (org-agenda-filter-show-all-tag))
  7024. (when org-agenda-category-filter
  7025. (org-agenda-filter-show-all-cat))
  7026. (when org-agenda-regexp-filter
  7027. (org-agenda-filter-show-all-re))
  7028. (when org-agenda-top-headline-filter
  7029. (org-agenda-filter-show-all-top-filter))
  7030. (when org-agenda-effort-filter
  7031. (org-agenda-filter-show-all-effort))
  7032. (org-agenda-finalize))
  7033. (defun org-agenda-filter-by-tag (arg &optional char exclude)
  7034. "Keep only those lines in the agenda buffer that have a specific tag.
  7035. The tag is selected with its fast selection letter, as configured.
  7036. With a `\\[universal-argument]' prefix, exclude the agenda search.
  7037. With a `\\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7038. i.e. don't
  7039. filter on all its group members.
  7040. A lisp caller can specify CHAR. EXCLUDE means that the new tag
  7041. should be used to exclude the search - the interactive user can
  7042. also press `-' or `+' to switch between filtering and excluding."
  7043. (interactive "P")
  7044. (let* ((alist org-tag-alist-for-agenda)
  7045. (tag-chars (mapconcat
  7046. (lambda (x) (if (and (not (symbolp (car x)))
  7047. (cdr x))
  7048. (char-to-string (cdr x))
  7049. ""))
  7050. org-tag-alist-for-agenda ""))
  7051. (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
  7052. (string-to-list tag-chars)))
  7053. (exclude (or exclude (equal arg '(4))))
  7054. (expand (not (equal arg '(16))))
  7055. (inhibit-read-only t)
  7056. (current org-agenda-tag-filter)
  7057. a n tag)
  7058. (unless char
  7059. (while (not (memq char valid-char-list))
  7060. (message
  7061. "%s by tag [%s ], [TAB], %s[/]:off, [+/-]:filter/exclude%s, [q]:quit"
  7062. (if exclude "Exclude" "Filter") tag-chars
  7063. (if org-agenda-auto-exclude-function "[RET], " "")
  7064. (if expand "" ", no grouptag expand"))
  7065. (setq char (read-char-exclusive))
  7066. ;; Excluding or filtering down
  7067. (cond ((eq char ?-) (setq exclude t))
  7068. ((eq char ?+) (setq exclude nil)))))
  7069. (when (eq char ?\t)
  7070. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  7071. (setq-local org-global-tags-completion-table
  7072. (org-global-tags-completion-table)))
  7073. (let ((completion-ignore-case t))
  7074. (setq tag (completing-read
  7075. "Tag: " org-global-tags-completion-table))))
  7076. (cond
  7077. ((eq char ?\r)
  7078. (org-agenda-filter-show-all-tag)
  7079. (when org-agenda-auto-exclude-function
  7080. (setq org-agenda-tag-filter nil)
  7081. (dolist (tag (org-agenda-get-represented-tags))
  7082. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7083. (if modifier
  7084. (push modifier org-agenda-tag-filter))))
  7085. (if (not (null org-agenda-tag-filter))
  7086. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7087. ((eq char ?/)
  7088. (org-agenda-filter-show-all-tag)
  7089. (when (get 'org-agenda-tag-filter :preset-filter)
  7090. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7091. ((eq char ?.)
  7092. (setq org-agenda-tag-filter
  7093. (mapcar (lambda(tag) (concat "+" tag))
  7094. (org-get-at-bol 'tags)))
  7095. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7096. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7097. ((or (eq char ?\s)
  7098. (setq a (rassoc char alist))
  7099. (and tag (setq a (cons tag nil))))
  7100. (org-agenda-filter-show-all-tag)
  7101. (setq tag (car a))
  7102. (setq org-agenda-tag-filter
  7103. (cons (concat (if exclude "-" "+") tag)
  7104. current))
  7105. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7106. (t (error "Invalid tag selection character %c" char)))))
  7107. (defun org-agenda-get-represented-tags ()
  7108. "Get a list of all tags currently represented in the agenda."
  7109. (let (p tags)
  7110. (save-excursion
  7111. (goto-char (point-min))
  7112. (while (setq p (next-single-property-change (point) 'tags))
  7113. (goto-char p)
  7114. (mapc (lambda (x) (add-to-list 'tags x))
  7115. (get-text-property (point) 'tags))))
  7116. tags))
  7117. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  7118. "Create the form that tests a line for agenda filter. Optional
  7119. argument EXPAND can be used for the TYPE tag and will expand the
  7120. tags in the FILTER if any of the tags in FILTER are grouptags."
  7121. (let (f f1)
  7122. (cond
  7123. ;; Tag filter
  7124. ((eq type 'tag)
  7125. (setq filter
  7126. (delete-dups
  7127. (append (get 'org-agenda-tag-filter :preset-filter)
  7128. filter)))
  7129. (dolist (x filter)
  7130. (let ((op (string-to-char x)))
  7131. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  7132. (setq x (list x)))
  7133. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  7134. (push f1 f))))
  7135. ;; Category filter
  7136. ((eq type 'category)
  7137. (setq filter
  7138. (delete-dups
  7139. (append (get 'org-agenda-category-filter :preset-filter)
  7140. filter)))
  7141. (dolist (x filter)
  7142. (if (equal "-" (substring x 0 1))
  7143. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7144. (setq f1 (list 'equal (substring x 1) 'cat)))
  7145. (push f1 f)))
  7146. ;; Regexp filter
  7147. ((eq type 'regexp)
  7148. (setq filter
  7149. (delete-dups
  7150. (append (get 'org-agenda-regexp-filter :preset-filter)
  7151. filter)))
  7152. (dolist (x filter)
  7153. (if (equal "-" (substring x 0 1))
  7154. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7155. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7156. (push f1 f)))
  7157. ;; Effort filter
  7158. ((eq type 'effort)
  7159. (setq filter
  7160. (delete-dups
  7161. (append (get 'org-agenda-effort-filter :preset-filter)
  7162. filter)))
  7163. (dolist (x filter)
  7164. (push (org-agenda-filter-effort-form x) f))))
  7165. (cons 'and (nreverse f))))
  7166. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  7167. "Return a form associated to tag-expression TAGS.
  7168. Build a form testing a line for agenda filter for
  7169. tag-expressions. OP is an operator of type CHAR that allows the
  7170. function to set the right switches in the returned form."
  7171. (let (form)
  7172. ;; Any of the expressions can match if OP is +, all must match if
  7173. ;; the operator is -.
  7174. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  7175. (let* ((tag (substring x 1))
  7176. (f (cond
  7177. ((string= "" tag) '(not tags))
  7178. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  7179. ;; TAG is a regexp.
  7180. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  7181. (t (list 'member (downcase tag) 'tags)))))
  7182. (push (if (eq op ?-) (list 'not f) f) form)))))
  7183. (defun org-agenda-filter-effort-form (e)
  7184. "Return the form to compare the effort of the current line with what E says.
  7185. E looks like \"+<2:25\"."
  7186. (let (op)
  7187. (setq e (substring e 1))
  7188. (setq op (string-to-char e) e (substring e 1))
  7189. (setq op (cond ((equal op ?<) '<=)
  7190. ((equal op ?>) '>=)
  7191. ((equal op ??) op)
  7192. (t '=)))
  7193. (list 'org-agenda-compare-effort (list 'quote op)
  7194. (org-duration-string-to-minutes e))))
  7195. (defun org-agenda-compare-effort (op value)
  7196. "Compare the effort of the current line with VALUE, using OP.
  7197. If the line does not have an effort defined, return nil."
  7198. ;; `effort-minutes' property cannot be extracted directly from
  7199. ;; current line but is stored as a property in `txt'.
  7200. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  7201. (funcall op
  7202. (or effort (if org-sort-agenda-noeffort-is-high 32767 -1))
  7203. value)))
  7204. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7205. "Expand group tags in FILTER for the agenda.
  7206. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7207. (if org-group-tags
  7208. (let ((case-fold-search t) rtn)
  7209. (mapc
  7210. (lambda (f)
  7211. (let (f0 dir)
  7212. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7213. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7214. (setq dir (if no-operator "" "+") f0 f))
  7215. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7216. (org-tags-expand f0 t t))
  7217. rtn))))
  7218. filter)
  7219. (reverse rtn))
  7220. filter))
  7221. (defun org-agenda-filter-apply (filter type &optional expand)
  7222. "Set FILTER as the new agenda filter and apply it. Optional
  7223. argument EXPAND can be used for the TYPE tag and will expand the
  7224. tags in the FILTER if any of the tags in FILTER are grouptags."
  7225. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7226. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7227. (let (tags cat txt)
  7228. (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type expand))
  7229. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  7230. ;; category is used as the filter:
  7231. (setq org-agenda-filtered-by-category
  7232. (and (eq type 'category)
  7233. (not (equal (substring (car filter) 0 1) "-"))))
  7234. (org-agenda-set-mode-name)
  7235. (save-excursion
  7236. (goto-char (point-min))
  7237. (while (not (eobp))
  7238. (if (org-get-at-bol 'org-marker)
  7239. (progn
  7240. (setq tags (org-get-at-bol 'tags)
  7241. cat (org-get-at-eol 'org-category 1)
  7242. txt (org-get-at-bol 'txt))
  7243. (if (not (eval org-agenda-filter-form))
  7244. (org-agenda-filter-hide-line type))
  7245. (beginning-of-line 2))
  7246. (beginning-of-line 2))))
  7247. (if (get-char-property (point) 'invisible)
  7248. (ignore-errors (org-agenda-previous-line)))))
  7249. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7250. "Filter by top headline HL."
  7251. (org-agenda-set-mode-name)
  7252. (save-excursion
  7253. (goto-char (point-min))
  7254. (while (not (eobp))
  7255. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7256. (tophl (and pos (org-find-top-headline pos))))
  7257. (if (and tophl (funcall (if negative 'identity 'not)
  7258. (string= hl tophl)))
  7259. (org-agenda-filter-hide-line 'top-headline)))
  7260. (beginning-of-line 2)))
  7261. (if (get-char-property (point) 'invisible)
  7262. (org-agenda-previous-line))
  7263. (setq org-agenda-top-headline-filter hl
  7264. org-agenda-filtered-by-top-headline t))
  7265. (defun org-agenda-filter-hide-line (type)
  7266. "Hide lines with TYPE in the agenda buffer."
  7267. (let* ((b (max (point-min) (1- (point-at-bol))))
  7268. (e (point-at-eol)))
  7269. (let ((inhibit-read-only t))
  7270. (add-text-properties
  7271. b e `(invisible org-filtered org-filter-type ,type)))))
  7272. (defun org-agenda-remove-filter (type)
  7273. (interactive)
  7274. "Remove filter of type TYPE from the agenda buffer."
  7275. (save-excursion
  7276. (goto-char (point-min))
  7277. (let ((inhibit-read-only t) pos)
  7278. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7279. (goto-char pos)
  7280. (remove-text-properties
  7281. (point) (next-single-property-change (point) 'org-filter-type)
  7282. `(invisible org-filtered org-filter-type ,type))))
  7283. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7284. (setq org-agenda-filter-form nil)
  7285. (org-agenda-set-mode-name)
  7286. (org-agenda-finalize)))
  7287. (defun org-agenda-filter-show-all-tag nil
  7288. (org-agenda-remove-filter 'tag))
  7289. (defun org-agenda-filter-show-all-re nil
  7290. (org-agenda-remove-filter 'regexp))
  7291. (defun org-agenda-filter-show-all-effort nil
  7292. (org-agenda-remove-filter 'effort))
  7293. (defun org-agenda-filter-show-all-cat nil
  7294. (org-agenda-remove-filter 'category))
  7295. (defun org-agenda-filter-show-all-top-filter nil
  7296. (org-agenda-remove-filter 'top-headline))
  7297. (defun org-agenda-manipulate-query-add ()
  7298. "Manipulate the query by adding a search term with positive selection.
  7299. Positive selection means the term must be matched for selection of an entry."
  7300. (interactive)
  7301. (org-agenda-manipulate-query ?\[))
  7302. (defun org-agenda-manipulate-query-subtract ()
  7303. "Manipulate the query by adding a search term with negative selection.
  7304. Negative selection means term must not be matched for selection of an entry."
  7305. (interactive)
  7306. (org-agenda-manipulate-query ?\]))
  7307. (defun org-agenda-manipulate-query-add-re ()
  7308. "Manipulate the query by adding a search regexp with positive selection.
  7309. Positive selection means the regexp must match for selection of an entry."
  7310. (interactive)
  7311. (org-agenda-manipulate-query ?\{))
  7312. (defun org-agenda-manipulate-query-subtract-re ()
  7313. "Manipulate the query by adding a search regexp with negative selection.
  7314. Negative selection means regexp must not match for selection of an entry."
  7315. (interactive)
  7316. (org-agenda-manipulate-query ?\}))
  7317. (defun org-agenda-manipulate-query (char)
  7318. (cond
  7319. ((memq org-agenda-type '(timeline agenda))
  7320. (let ((org-agenda-include-inactive-timestamps t))
  7321. (org-agenda-redo))
  7322. (message "Display now includes inactive timestamps as well"))
  7323. ((eq org-agenda-type 'search)
  7324. (org-add-to-string
  7325. 'org-agenda-query-string
  7326. (if org-agenda-last-search-view-search-was-boolean
  7327. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7328. (?\{ . " +{}") (?\} . " -{}"))))
  7329. " "))
  7330. (setq org-agenda-redo-command
  7331. (list 'org-search-view
  7332. (car (get-text-property (min (1- (point-max)) (point))
  7333. 'org-last-args))
  7334. org-agenda-query-string
  7335. (+ (length org-agenda-query-string)
  7336. (if (member char '(?\{ ?\})) 0 1))))
  7337. (set-register org-agenda-query-register org-agenda-query-string)
  7338. (let ((org-agenda-overriding-arguments
  7339. (cdr org-agenda-redo-command)))
  7340. (org-agenda-redo)))
  7341. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7342. org-agenda-type))))
  7343. (defun org-add-to-string (var string)
  7344. (set var (concat (symbol-value var) string)))
  7345. (defun org-agenda-goto-date (span)
  7346. "Jump to DATE in agenda."
  7347. (interactive "P")
  7348. (let* ((org-read-date-prefer-future
  7349. (eval org-agenda-jump-prefer-future))
  7350. (date (org-read-date))
  7351. (day (time-to-days (org-time-string-to-time date)))
  7352. (org-agenda-sticky-orig org-agenda-sticky)
  7353. (org-agenda-buffer-tmp-name (buffer-name))
  7354. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7355. (0-arg (or current-prefix-arg (car args)))
  7356. (2-arg (nth 2 args))
  7357. (with-hour-p (nth 4 org-agenda-redo-command))
  7358. (newcmd (list 'org-agenda-list 0-arg date
  7359. (org-agenda-span-to-ndays
  7360. 2-arg (org-time-string-to-absolute date))
  7361. with-hour-p))
  7362. (newargs (cdr newcmd))
  7363. (inhibit-read-only t)
  7364. org-agenda-sticky)
  7365. (if (not (org-agenda-check-type t 'agenda))
  7366. (error "Not available in non-agenda views")
  7367. (add-text-properties (point-min) (point-max)
  7368. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7369. (org-agenda-redo)
  7370. (goto-char (point-min))
  7371. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7372. (save-excursion (move-beginning-of-line 2) (eobp))))
  7373. (move-beginning-of-line 2))
  7374. (setq org-agenda-sticky org-agenda-sticky-orig
  7375. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7376. (defun org-agenda-goto-today ()
  7377. "Go to today."
  7378. (interactive)
  7379. (org-agenda-check-type t 'timeline 'agenda)
  7380. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7381. (curspan (nth 2 args))
  7382. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7383. (cond
  7384. (tdpos (goto-char tdpos))
  7385. ((eq org-agenda-type 'agenda)
  7386. (let* ((sd (org-agenda-compute-starting-span
  7387. (org-today) (or curspan org-agenda-span)))
  7388. (org-agenda-overriding-arguments args))
  7389. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7390. (org-agenda-redo)
  7391. (org-agenda-find-same-or-today-or-agenda)))
  7392. (t (error "Cannot find today")))))
  7393. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7394. (goto-char
  7395. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7396. (text-property-any (point-min) (point-max) 'org-today t)
  7397. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7398. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7399. (org-agenda-backward-block))
  7400. (point-min))))
  7401. (defun org-agenda-backward-block ()
  7402. "Move backward by one agenda block."
  7403. (interactive)
  7404. (org-agenda-forward-block 'backward))
  7405. (defun org-agenda-forward-block (&optional backward)
  7406. "Move forward by one agenda block.
  7407. When optional argument BACKWARD is set, go backward"
  7408. (interactive)
  7409. (cond ((not (derived-mode-p 'org-agenda-mode))
  7410. (user-error
  7411. "Cannot execute this command outside of org-agenda-mode buffers"))
  7412. ((looking-at (if backward "\\`" "\\'"))
  7413. (message "Already at the %s block" (if backward "first" "last")))
  7414. (t (let ((pos (prog1 (point)
  7415. (ignore-errors (if backward (backward-char 1)
  7416. (move-end-of-line 1)))))
  7417. (f (if backward
  7418. 'previous-single-property-change
  7419. 'next-single-property-change))
  7420. moved dest)
  7421. (while (and (setq dest (funcall
  7422. f (point) 'org-agenda-structural-header))
  7423. (not (get-text-property
  7424. (point) 'org-agenda-structural-header)))
  7425. (setq moved t)
  7426. (goto-char dest))
  7427. (if moved (move-beginning-of-line 1)
  7428. (goto-char (if backward (point-min) (point-max)))
  7429. (move-beginning-of-line 1)
  7430. (message "No %s block" (if backward "previous" "further")))))))
  7431. (defun org-agenda-later (arg)
  7432. "Go forward in time by the current span.
  7433. With prefix ARG, go forward that many times the current span."
  7434. (interactive "p")
  7435. (org-agenda-check-type t 'agenda)
  7436. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7437. (span (or (nth 2 args) org-agenda-current-span))
  7438. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7439. (greg (calendar-gregorian-from-absolute sd))
  7440. (cnt (org-get-at-bol 'org-day-cnt))
  7441. greg2)
  7442. (cond
  7443. ((numberp span)
  7444. (setq sd (+ (* span arg) sd)))
  7445. ((eq span 'day)
  7446. (setq sd (+ arg sd)))
  7447. ((eq span 'week)
  7448. (setq sd (+ (* 7 arg) sd)))
  7449. ((eq span 'fortnight)
  7450. (setq sd (+ (* 14 arg) sd)))
  7451. ((eq span 'month)
  7452. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7453. sd (calendar-absolute-from-gregorian greg2))
  7454. (setcar greg2 (1+ (car greg2))))
  7455. ((eq span 'year)
  7456. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7457. sd (calendar-absolute-from-gregorian greg2))
  7458. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7459. (t
  7460. (setq sd (+ (* span arg) sd))))
  7461. (let ((org-agenda-overriding-cmd
  7462. ;; `cmd' may have been set by `org-agenda-run-series' which
  7463. ;; uses `org-agenda-overriding-cmd' to decide whether
  7464. ;; overriding is allowed for `cmd'
  7465. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7466. (org-agenda-overriding-arguments
  7467. (list (car args) sd span)))
  7468. (org-agenda-redo)
  7469. (org-agenda-find-same-or-today-or-agenda cnt))))
  7470. (defun org-agenda-earlier (arg)
  7471. "Go backward in time by the current span.
  7472. With prefix ARG, go backward that many times the current span."
  7473. (interactive "p")
  7474. (org-agenda-later (- arg)))
  7475. (defun org-agenda-view-mode-dispatch ()
  7476. "Call one of the view mode commands."
  7477. (interactive)
  7478. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7479. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7480. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7481. (pcase (read-char-exclusive)
  7482. (?\ (call-interactively 'org-agenda-reset-view))
  7483. (?d (call-interactively 'org-agenda-day-view))
  7484. (?w (call-interactively 'org-agenda-week-view))
  7485. (?t (call-interactively 'org-agenda-fortnight-view))
  7486. (?m (call-interactively 'org-agenda-month-view))
  7487. (?y (call-interactively 'org-agenda-year-view))
  7488. (?l (call-interactively 'org-agenda-log-mode))
  7489. (?L (org-agenda-log-mode '(4)))
  7490. (?c (org-agenda-log-mode 'clockcheck))
  7491. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  7492. (?a (call-interactively 'org-agenda-archives-mode))
  7493. (?A (org-agenda-archives-mode 'files))
  7494. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7495. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7496. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7497. (?D (call-interactively 'org-agenda-toggle-diary))
  7498. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7499. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7500. (org-agenda-check-type t 'timeline 'agenda)
  7501. (org-agenda-redo))
  7502. (message "Display now includes inactive timestamps as well"))
  7503. (?q (message "Abort"))
  7504. (key (user-error "Invalid key: %s" key))))
  7505. (defun org-agenda-reset-view ()
  7506. "Switch to default view for agenda."
  7507. (interactive)
  7508. (org-agenda-change-time-span org-agenda-span))
  7509. (defun org-agenda-day-view (&optional day-of-month)
  7510. "Switch to daily view for agenda.
  7511. With argument DAY-OF-MONTH, switch to that day of the month."
  7512. (interactive "P")
  7513. (org-agenda-change-time-span 'day day-of-month))
  7514. (defun org-agenda-week-view (&optional iso-week)
  7515. "Switch to weekly 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 'week iso-week))
  7523. (defun org-agenda-fortnight-view (&optional iso-week)
  7524. "Switch to fortnightly view for agenda.
  7525. With argument ISO-WEEK, switch to the corresponding ISO week.
  7526. If ISO-WEEK has more then 2 digits, only the last two encode
  7527. the week. Any digits before this encode a year. So 200712
  7528. means week 12 of year 2007. Years ranging from 70 years ago
  7529. to 30 years in the future can also be written as 2-digit years."
  7530. (interactive "P")
  7531. (org-agenda-change-time-span 'fortnight iso-week))
  7532. (defun org-agenda-month-view (&optional month)
  7533. "Switch to monthly view for agenda.
  7534. With argument MONTH, switch to that month. If MONTH has more
  7535. then 2 digits, only the last two encode the month. Any digits
  7536. before this encode a year. So 200712 means December year 2007.
  7537. Years ranging from 70 years ago to 30 years in the future can
  7538. also be written as 2-digit years."
  7539. (interactive "P")
  7540. (org-agenda-change-time-span 'month month))
  7541. (defun org-agenda-year-view (&optional year)
  7542. "Switch to yearly view for agenda.
  7543. With argument YEAR, switch to that year. Years ranging from 70
  7544. years ago to 30 years in the future can also be written as
  7545. 2-digit years."
  7546. (interactive "P")
  7547. (when year
  7548. (setq year (org-small-year-to-year year)))
  7549. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7550. (org-agenda-change-time-span 'year year)
  7551. (error "Abort")))
  7552. (defun org-agenda-change-time-span (span &optional n)
  7553. "Change the agenda view to SPAN.
  7554. SPAN may be `day', `week', `fortnight', `month', `year'."
  7555. (org-agenda-check-type t 'agenda)
  7556. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7557. (curspan (nth 2 args)))
  7558. (if (and (not n) (equal curspan span))
  7559. (error "Viewing span is already \"%s\"" span))
  7560. (let* ((sd (or (org-get-at-bol 'day)
  7561. (nth 1 args)
  7562. org-starting-day))
  7563. (sd (org-agenda-compute-starting-span sd span n))
  7564. (org-agenda-overriding-cmd
  7565. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7566. (org-agenda-overriding-arguments
  7567. (list (car args) sd span)))
  7568. (org-agenda-redo)
  7569. (org-agenda-find-same-or-today-or-agenda))
  7570. (org-agenda-set-mode-name)
  7571. (message "Switched to %s view" span)))
  7572. (defun org-agenda-compute-starting-span (sd span &optional n)
  7573. "Compute starting date for agenda.
  7574. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7575. is a cons cell with the starting date and the number of days,
  7576. so that the date SD will be in that range."
  7577. (let* ((greg (calendar-gregorian-from-absolute sd))
  7578. (dg (nth 1 greg))
  7579. (mg (car greg))
  7580. (yg (nth 2 greg)))
  7581. (cond
  7582. ((eq span 'day)
  7583. (when n
  7584. (setq sd (+ (calendar-absolute-from-gregorian
  7585. (list mg 1 yg))
  7586. n -1))))
  7587. ((or (eq span 'week) (eq span 'fortnight))
  7588. (let* ((nt (calendar-day-of-week
  7589. (calendar-gregorian-from-absolute sd)))
  7590. (d (if org-agenda-start-on-weekday
  7591. (- nt org-agenda-start-on-weekday)
  7592. 0))
  7593. y1)
  7594. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7595. (when n
  7596. (require 'cal-iso)
  7597. (when (> n 99)
  7598. (setq y1 (org-small-year-to-year (/ n 100))
  7599. n (mod n 100)))
  7600. (setq sd
  7601. (calendar-iso-to-absolute
  7602. (list n 1
  7603. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7604. ((eq span 'month)
  7605. (let (y1)
  7606. (when (and n (> n 99))
  7607. (setq y1 (org-small-year-to-year (/ n 100))
  7608. n (mod n 100)))
  7609. (setq sd (calendar-absolute-from-gregorian
  7610. (list (or n mg) 1 (or y1 yg))))))
  7611. ((eq span 'year)
  7612. (setq sd (calendar-absolute-from-gregorian
  7613. (list 1 1 (or n yg))))))
  7614. sd))
  7615. (defun org-agenda-next-date-line (&optional arg)
  7616. "Jump to the next line indicating a date in agenda buffer."
  7617. (interactive "p")
  7618. (org-agenda-check-type t 'agenda 'timeline)
  7619. (beginning-of-line 1)
  7620. ;; This does not work if user makes date format that starts with a blank
  7621. (if (looking-at "^\\S-") (forward-char 1))
  7622. (if (not (re-search-forward "^\\S-" nil t arg))
  7623. (progn
  7624. (backward-char 1)
  7625. (error "No next date after this line in this buffer")))
  7626. (goto-char (match-beginning 0)))
  7627. (defun org-agenda-previous-date-line (&optional arg)
  7628. "Jump to the previous line indicating a date in agenda buffer."
  7629. (interactive "p")
  7630. (org-agenda-check-type t 'agenda 'timeline)
  7631. (beginning-of-line 1)
  7632. (if (not (re-search-backward "^\\S-" nil t arg))
  7633. (error "No previous date before this line in this buffer")))
  7634. ;; Initialize the highlight
  7635. (defvar org-hl (make-overlay 1 1))
  7636. (overlay-put org-hl 'face 'highlight)
  7637. (defun org-highlight (begin end &optional buffer)
  7638. "Highlight a region with overlay."
  7639. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7640. (defun org-unhighlight ()
  7641. "Detach overlay INDEX."
  7642. (delete-overlay org-hl))
  7643. (defun org-unhighlight-once ()
  7644. "Remove the highlight from its position, and this function from the hook."
  7645. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7646. (org-unhighlight))
  7647. (defvar org-agenda-pre-follow-window-conf nil)
  7648. (defun org-agenda-follow-mode ()
  7649. "Toggle follow mode in an agenda buffer."
  7650. (interactive)
  7651. (unless org-agenda-follow-mode
  7652. (setq org-agenda-pre-follow-window-conf
  7653. (current-window-configuration)))
  7654. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7655. (unless org-agenda-follow-mode
  7656. (set-window-configuration org-agenda-pre-follow-window-conf))
  7657. (org-agenda-set-mode-name)
  7658. (org-agenda-do-context-action)
  7659. (message "Follow mode is %s"
  7660. (if org-agenda-follow-mode "on" "off")))
  7661. (defun org-agenda-entry-text-mode (&optional arg)
  7662. "Toggle entry text mode in an agenda buffer."
  7663. (interactive "P")
  7664. (if (or org-agenda-tag-filter
  7665. org-agenda-category-filter
  7666. org-agenda-regexp-filter
  7667. org-agenda-top-headline-filter)
  7668. (user-error "Can't show entry text in filtered views")
  7669. (setq org-agenda-entry-text-mode (or (integerp arg)
  7670. (not org-agenda-entry-text-mode)))
  7671. (org-agenda-entry-text-hide)
  7672. (and org-agenda-entry-text-mode
  7673. (let ((org-agenda-entry-text-maxlines
  7674. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7675. (org-agenda-entry-text-show)))
  7676. (org-agenda-set-mode-name)
  7677. (message "Entry text mode is %s%s"
  7678. (if org-agenda-entry-text-mode "on" "off")
  7679. (if (not org-agenda-entry-text-mode) ""
  7680. (format " (maximum number of lines is %d)"
  7681. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7682. (defun org-agenda-clockreport-mode ()
  7683. "Toggle clocktable mode in an agenda buffer."
  7684. (interactive)
  7685. (org-agenda-check-type t 'agenda)
  7686. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7687. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7688. (org-agenda-set-mode-name)
  7689. (org-agenda-redo)
  7690. (message "Clocktable mode is %s"
  7691. (if org-agenda-clockreport-mode "on" "off")))
  7692. (defun org-agenda-log-mode (&optional special)
  7693. "Toggle log mode in an agenda buffer.
  7694. With argument SPECIAL, show all possible log items, not only the ones
  7695. configured in `org-agenda-log-mode-items'.
  7696. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  7697. log items, nothing else."
  7698. (interactive "P")
  7699. (org-agenda-check-type t 'agenda 'timeline)
  7700. (setq org-agenda-show-log
  7701. (cond
  7702. ((equal special '(16)) 'only)
  7703. ((eq special 'clockcheck)
  7704. (if (eq org-agenda-show-log 'clockcheck)
  7705. nil 'clockcheck))
  7706. (special '(closed clock state))
  7707. (t (not org-agenda-show-log))))
  7708. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7709. (org-agenda-set-mode-name)
  7710. (org-agenda-redo)
  7711. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  7712. (defun org-agenda-archives-mode (&optional with-files)
  7713. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7714. When called with a prefix argument, include all archive files as well."
  7715. (interactive "P")
  7716. (setq org-agenda-archives-mode
  7717. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7718. (org-agenda-set-mode-name)
  7719. (org-agenda-redo)
  7720. (message
  7721. "%s"
  7722. (cond
  7723. ((eq org-agenda-archives-mode nil)
  7724. "No archives are included")
  7725. ((eq org-agenda-archives-mode 'trees)
  7726. (format "Trees with :%s: tag are included" org-archive-tag))
  7727. ((eq org-agenda-archives-mode t)
  7728. (format "Trees with :%s: tag and all active archive files are included"
  7729. org-archive-tag)))))
  7730. (defun org-agenda-toggle-diary ()
  7731. "Toggle diary inclusion in an agenda buffer."
  7732. (interactive)
  7733. (org-agenda-check-type t 'agenda)
  7734. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7735. (org-agenda-redo)
  7736. (org-agenda-set-mode-name)
  7737. (message "Diary inclusion turned %s"
  7738. (if org-agenda-include-diary "on" "off")))
  7739. (defun org-agenda-toggle-deadlines ()
  7740. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7741. (interactive)
  7742. (org-agenda-check-type t 'agenda)
  7743. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7744. (org-agenda-redo)
  7745. (org-agenda-set-mode-name)
  7746. (message "Deadlines inclusion turned %s"
  7747. (if org-agenda-include-deadlines "on" "off")))
  7748. (defun org-agenda-toggle-time-grid ()
  7749. "Toggle time grid in an agenda buffer."
  7750. (interactive)
  7751. (org-agenda-check-type t 'agenda)
  7752. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7753. (org-agenda-redo)
  7754. (org-agenda-set-mode-name)
  7755. (message "Time-grid turned %s"
  7756. (if org-agenda-use-time-grid "on" "off")))
  7757. (defun org-agenda-set-mode-name ()
  7758. "Set the mode name to indicate all the small mode settings."
  7759. (setq mode-name
  7760. (list "Org-Agenda"
  7761. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7762. " "
  7763. '(:eval (org-agenda-span-name org-agenda-current-span))
  7764. (if org-agenda-follow-mode " Follow" "")
  7765. (if org-agenda-entry-text-mode " ETxt" "")
  7766. (if org-agenda-include-diary " Diary" "")
  7767. (if org-agenda-include-deadlines " Ddl" "")
  7768. (if org-agenda-use-time-grid " Grid" "")
  7769. (if (and (boundp 'org-habit-show-habits)
  7770. org-habit-show-habits) " Habit" "")
  7771. (cond
  7772. ((consp org-agenda-show-log) " LogAll")
  7773. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7774. (org-agenda-show-log " Log")
  7775. (t ""))
  7776. (if (or org-agenda-category-filter
  7777. (get 'org-agenda-category-filter :preset-filter))
  7778. '(:eval (propertize
  7779. (concat " <"
  7780. (mapconcat
  7781. 'identity
  7782. (append
  7783. (get 'org-agenda-category-filter :preset-filter)
  7784. org-agenda-category-filter)
  7785. "")
  7786. ">")
  7787. 'face 'org-agenda-filter-category
  7788. 'help-echo "Category used in filtering")) "")
  7789. (if (or org-agenda-tag-filter
  7790. (get 'org-agenda-tag-filter :preset-filter))
  7791. '(:eval (propertize
  7792. (concat " {"
  7793. (mapconcat
  7794. 'identity
  7795. (append
  7796. (get 'org-agenda-tag-filter :preset-filter)
  7797. org-agenda-tag-filter)
  7798. "")
  7799. "}")
  7800. 'face 'org-agenda-filter-tags
  7801. 'help-echo "Tags used in filtering")) "")
  7802. (if (or org-agenda-effort-filter
  7803. (get 'org-agenda-effort-filter :preset-filter))
  7804. '(:eval (propertize
  7805. (concat " {"
  7806. (mapconcat
  7807. 'identity
  7808. (append
  7809. (get 'org-agenda-effort-filter :preset-filter)
  7810. org-agenda-effort-filter)
  7811. "")
  7812. "}")
  7813. 'face 'org-agenda-filter-effort
  7814. 'help-echo "Effort conditions used in filtering")) "")
  7815. (if (or org-agenda-regexp-filter
  7816. (get 'org-agenda-regexp-filter :preset-filter))
  7817. '(:eval (propertize
  7818. (concat " ["
  7819. (mapconcat
  7820. 'identity
  7821. (append
  7822. (get 'org-agenda-regexp-filter :preset-filter)
  7823. org-agenda-regexp-filter)
  7824. "")
  7825. "]")
  7826. 'face 'org-agenda-filter-regexp
  7827. 'help-echo "Regexp used in filtering")) "")
  7828. (if org-agenda-archives-mode
  7829. (if (eq org-agenda-archives-mode t)
  7830. " Archives"
  7831. (format " :%s:" org-archive-tag))
  7832. "")
  7833. (if org-agenda-clockreport-mode " Clock" "")))
  7834. (force-mode-line-update))
  7835. (defun org-agenda-update-agenda-type ()
  7836. "Update the agenda type after each command."
  7837. (setq org-agenda-type
  7838. (or (get-text-property (point) 'org-agenda-type)
  7839. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7840. (defun org-agenda-next-line ()
  7841. "Move cursor to the next line, and show if follow mode is active."
  7842. (interactive)
  7843. (call-interactively 'next-line)
  7844. (org-agenda-do-context-action))
  7845. (defun org-agenda-previous-line ()
  7846. "Move cursor to the previous line, and show if follow-mode is active."
  7847. (interactive)
  7848. (call-interactively 'previous-line)
  7849. (org-agenda-do-context-action))
  7850. (defun org-agenda-next-item (n)
  7851. "Move cursor to next agenda item."
  7852. (interactive "p")
  7853. (let ((col (current-column)))
  7854. (dotimes (c n)
  7855. (when (next-single-property-change (point-at-eol) 'org-marker)
  7856. (move-end-of-line 1)
  7857. (goto-char (next-single-property-change (point) 'org-marker))))
  7858. (org-move-to-column col))
  7859. (org-agenda-do-context-action))
  7860. (defun org-agenda-previous-item (n)
  7861. "Move cursor to next agenda item."
  7862. (interactive "p")
  7863. (dotimes (c n)
  7864. (let ((col (current-column))
  7865. (goto (save-excursion
  7866. (move-end-of-line 0)
  7867. (previous-single-property-change (point) 'org-marker))))
  7868. (if goto (goto-char goto))
  7869. (org-move-to-column col)))
  7870. (org-agenda-do-context-action))
  7871. (defun org-agenda-do-context-action ()
  7872. "Show outline path and, maybe, follow mode window."
  7873. (let ((m (org-get-at-bol 'org-marker)))
  7874. (when (and (markerp m) (marker-buffer m))
  7875. (and org-agenda-follow-mode
  7876. (if org-agenda-follow-indirect
  7877. (org-agenda-tree-to-indirect-buffer nil)
  7878. (org-agenda-show)))
  7879. (and org-agenda-show-outline-path
  7880. (org-with-point-at m (org-display-outline-path t))))))
  7881. (defun org-agenda-show-tags ()
  7882. "Show the tags applicable to the current item."
  7883. (interactive)
  7884. (let* ((tags (org-get-at-bol 'tags)))
  7885. (if tags
  7886. (message "Tags are :%s:"
  7887. (org-no-properties (mapconcat 'identity tags ":")))
  7888. (message "No tags associated with this line"))))
  7889. (defun org-agenda-goto (&optional highlight)
  7890. "Go to the entry at point in the corresponding Org file."
  7891. (interactive)
  7892. (let* ((marker (or (org-get-at-bol 'org-marker)
  7893. (org-agenda-error)))
  7894. (buffer (marker-buffer marker))
  7895. (pos (marker-position marker)))
  7896. (switch-to-buffer-other-window buffer)
  7897. (widen)
  7898. (push-mark)
  7899. (goto-char pos)
  7900. (when (derived-mode-p 'org-mode)
  7901. (org-show-context 'agenda)
  7902. (recenter (/ (window-height) 2))
  7903. (org-back-to-heading t)
  7904. (let ((case-fold-search nil))
  7905. (when (re-search-forward org-complex-heading-regexp nil t)
  7906. (goto-char (match-beginning 4)))))
  7907. (run-hooks 'org-agenda-after-show-hook)
  7908. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7909. (defvar org-agenda-after-show-hook nil
  7910. "Normal hook run after an item has been shown from the agenda.
  7911. Point is in the buffer where the item originated.")
  7912. (defun org-agenda-kill ()
  7913. "Kill the entry or subtree belonging to the current agenda entry."
  7914. (interactive)
  7915. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7916. (let* ((bufname-orig (buffer-name))
  7917. (marker (or (org-get-at-bol 'org-marker)
  7918. (org-agenda-error)))
  7919. (buffer (marker-buffer marker))
  7920. (pos (marker-position marker))
  7921. (type (org-get-at-bol 'type))
  7922. dbeg dend (n 0) conf)
  7923. (org-with-remote-undo buffer
  7924. (with-current-buffer buffer
  7925. (save-excursion
  7926. (goto-char pos)
  7927. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7928. (setq dbeg (progn (org-back-to-heading t) (point))
  7929. dend (org-end-of-subtree t t))
  7930. (setq dbeg (point-at-bol)
  7931. dend (min (point-max) (1+ (point-at-eol)))))
  7932. (goto-char dbeg)
  7933. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7934. (setq conf (or (eq t org-agenda-confirm-kill)
  7935. (and (numberp org-agenda-confirm-kill)
  7936. (> n org-agenda-confirm-kill))))
  7937. (and conf
  7938. (not (y-or-n-p
  7939. (format "Delete entry with %d lines in buffer \"%s\"? "
  7940. n (buffer-name buffer))))
  7941. (error "Abort"))
  7942. (let ((org-agenda-buffer-name bufname-orig))
  7943. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7944. (with-current-buffer buffer (delete-region dbeg dend))
  7945. (message "Agenda item and source killed"))))
  7946. (defvar org-archive-default-command) ; defined in org-archive.el
  7947. (defun org-agenda-archive-default ()
  7948. "Archive the entry or subtree belonging to the current agenda entry."
  7949. (interactive)
  7950. (require 'org-archive)
  7951. (org-agenda-archive-with org-archive-default-command))
  7952. (defun org-agenda-archive-default-with-confirmation ()
  7953. "Archive the entry or subtree belonging to the current agenda entry."
  7954. (interactive)
  7955. (require 'org-archive)
  7956. (org-agenda-archive-with org-archive-default-command 'confirm))
  7957. (defun org-agenda-archive ()
  7958. "Archive the entry or subtree belonging to the current agenda entry."
  7959. (interactive)
  7960. (org-agenda-archive-with 'org-archive-subtree))
  7961. (defun org-agenda-archive-to-archive-sibling ()
  7962. "Move the entry to the archive sibling."
  7963. (interactive)
  7964. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7965. (defun org-agenda-archive-with (cmd &optional confirm)
  7966. "Move the entry to the archive sibling."
  7967. (interactive)
  7968. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7969. (let* ((bufname-orig (buffer-name))
  7970. (marker (or (org-get-at-bol 'org-marker)
  7971. (org-agenda-error)))
  7972. (buffer (marker-buffer marker))
  7973. (pos (marker-position marker)))
  7974. (org-with-remote-undo buffer
  7975. (with-current-buffer buffer
  7976. (if (derived-mode-p 'org-mode)
  7977. (if (and confirm
  7978. (not (y-or-n-p "Archive this subtree or entry? ")))
  7979. (error "Abort")
  7980. (save-window-excursion
  7981. (goto-char pos)
  7982. (let ((org-agenda-buffer-name bufname-orig))
  7983. (org-remove-subtree-entries-from-agenda))
  7984. (org-back-to-heading t)
  7985. (funcall cmd)))
  7986. (error "Archiving works only in Org files"))))))
  7987. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7988. "Remove all lines in the agenda that correspond to a given subtree.
  7989. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7990. If this information is not given, the function uses the tree at point."
  7991. (let ((buf (or buf (current-buffer))) m p)
  7992. (save-excursion
  7993. (unless (and beg end)
  7994. (org-back-to-heading t)
  7995. (setq beg (point))
  7996. (org-end-of-subtree t)
  7997. (setq end (point)))
  7998. (set-buffer (get-buffer org-agenda-buffer-name))
  7999. (save-excursion
  8000. (goto-char (point-max))
  8001. (beginning-of-line 1)
  8002. (while (not (bobp))
  8003. (when (and (setq m (org-get-at-bol 'org-marker))
  8004. (equal buf (marker-buffer m))
  8005. (setq p (marker-position m))
  8006. (>= p beg)
  8007. (< p end))
  8008. (let ((inhibit-read-only t))
  8009. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8010. (beginning-of-line 0))))))
  8011. (defun org-agenda-refile (&optional goto rfloc no-update)
  8012. "Refile the item at point.
  8013. When called with `\\[universal-argument] \\[universal-argument]', \
  8014. go to the location of the last
  8015. refiled item.
  8016. When called with `\\[universal-argument] \\[universal-argument] \
  8017. \\[universal-argument]' prefix or when GOTO is 0, clear
  8018. the refile cache.
  8019. RFLOC can be a refile location obtained in a different way.
  8020. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8021. (interactive "P")
  8022. (cond
  8023. ((member goto '(0 (64)))
  8024. (org-refile-cache-clear))
  8025. ((equal goto '(16))
  8026. (org-refile-goto-last-stored))
  8027. (t
  8028. (let* ((buffer-orig (buffer-name))
  8029. (marker (or (org-get-at-bol 'org-hd-marker)
  8030. (org-agenda-error)))
  8031. (buffer (marker-buffer marker))
  8032. (pos (marker-position marker))
  8033. (rfloc (or rfloc
  8034. (org-refile-get-location
  8035. (if goto "Goto" "Refile to") buffer
  8036. org-refile-allow-creating-parent-nodes))))
  8037. (with-current-buffer buffer
  8038. (org-with-wide-buffer
  8039. (goto-char marker)
  8040. (let ((org-agenda-buffer-name buffer-orig))
  8041. (org-remove-subtree-entries-from-agenda))
  8042. (org-refile goto buffer rfloc))))
  8043. (unless no-update (org-agenda-redo)))))
  8044. (defun org-agenda-open-link (&optional arg)
  8045. "Open the link(s) in the current entry, if any.
  8046. This looks for a link in the displayed line in the agenda.
  8047. It also looks at the text of the entry itself."
  8048. (interactive "P")
  8049. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  8050. (org-get-at-bol 'org-marker)))
  8051. (buffer (and marker (marker-buffer marker)))
  8052. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  8053. (lkall (and buffer (org-offer-links-in-entry
  8054. buffer marker arg prefix)))
  8055. (lk0 (car lkall))
  8056. (lk (if (stringp lk0) (list lk0) lk0))
  8057. (lkend (cdr lkall))
  8058. trg)
  8059. (cond
  8060. ((and buffer lk)
  8061. (mapcar (lambda(l)
  8062. (with-current-buffer buffer
  8063. (setq trg (and (string-match org-bracket-link-regexp l)
  8064. (match-string 1 l)))
  8065. (if (or (not trg) (string-match org-any-link-re trg))
  8066. (org-with-wide-buffer
  8067. (goto-char marker)
  8068. (when (search-forward l nil lkend)
  8069. (goto-char (match-beginning 0))
  8070. (org-open-at-point)))
  8071. ;; This is an internal link, widen the buffer
  8072. (switch-to-buffer-other-window buffer)
  8073. (widen)
  8074. (goto-char marker)
  8075. (when (search-forward l nil lkend)
  8076. (goto-char (match-beginning 0))
  8077. (org-open-at-point)))))
  8078. lk))
  8079. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  8080. (save-excursion
  8081. (beginning-of-line 1)
  8082. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  8083. (org-open-link-from-string (match-string 1)))
  8084. (t (message "No link to open here")))))
  8085. (defun org-agenda-copy-local-variable (var)
  8086. "Get a variable from a referenced buffer and install it here."
  8087. (let ((m (org-get-at-bol 'org-marker)))
  8088. (when (and m (buffer-live-p (marker-buffer m)))
  8089. (set (make-local-variable var)
  8090. (with-current-buffer (marker-buffer m)
  8091. (symbol-value var))))))
  8092. (defun org-agenda-switch-to (&optional delete-other-windows)
  8093. "Go to the Org mode file which contains the item at point.
  8094. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  8095. displayed Org file fills the frame."
  8096. (interactive)
  8097. (if (and org-return-follows-link
  8098. (not (org-get-at-bol 'org-marker))
  8099. (org-in-regexp org-bracket-link-regexp))
  8100. (org-open-link-from-string (match-string 0))
  8101. (let* ((marker (or (org-get-at-bol 'org-marker)
  8102. (org-agenda-error)))
  8103. (buffer (marker-buffer marker))
  8104. (pos (marker-position marker)))
  8105. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  8106. (pop-to-buffer-same-window buffer)
  8107. (when delete-other-windows (delete-other-windows))
  8108. (widen)
  8109. (goto-char pos)
  8110. (when (derived-mode-p 'org-mode)
  8111. (org-show-context 'agenda)
  8112. (run-hooks 'org-agenda-after-show-hook)))))
  8113. (defun org-agenda-goto-mouse (ev)
  8114. "Go to the Org file which contains the item at the mouse click."
  8115. (interactive "e")
  8116. (mouse-set-point ev)
  8117. (org-agenda-goto))
  8118. (defun org-agenda-show (&optional full-entry)
  8119. "Display the Org file which contains the item at point.
  8120. With prefix argument FULL-ENTRY, make the entire entry visible
  8121. if it was hidden in the outline."
  8122. (interactive "P")
  8123. (let ((win (selected-window)))
  8124. (org-agenda-goto t)
  8125. (when full-entry (org-show-entry))
  8126. (select-window win)))
  8127. (defvar org-agenda-show-window nil)
  8128. (defun org-agenda-show-and-scroll-up (&optional arg)
  8129. "Display the Org file which contains the item at point.
  8130. When called repeatedly, scroll the window that is displaying the buffer.
  8131. With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
  8132. `outline-show-subtree'
  8133. to display the item, so that drawers and logbooks stay folded."
  8134. (interactive "P")
  8135. (let ((win (selected-window)))
  8136. (if (and (window-live-p org-agenda-show-window)
  8137. (eq this-command last-command))
  8138. (progn
  8139. (select-window org-agenda-show-window)
  8140. (ignore-errors (scroll-up)))
  8141. (org-agenda-goto t)
  8142. (if arg (org-show-entry) (outline-show-subtree))
  8143. (setq org-agenda-show-window (selected-window)))
  8144. (select-window win)))
  8145. (defun org-agenda-show-scroll-down ()
  8146. "Scroll down the window showing the agenda."
  8147. (interactive)
  8148. (let ((win (selected-window)))
  8149. (when (window-live-p org-agenda-show-window)
  8150. (select-window org-agenda-show-window)
  8151. (ignore-errors (scroll-down))
  8152. (select-window win))))
  8153. (defun org-agenda-show-1 (&optional more)
  8154. "Display the Org file which contains the item at point.
  8155. The prefix arg selects the amount of information to display:
  8156. 0 hide the subtree
  8157. 1 just show the entry according to defaults.
  8158. 2 show the children view
  8159. 3 show the subtree view
  8160. 4 show the entire subtree and any LOGBOOK drawers
  8161. 5 show the entire subtree and any drawers
  8162. With prefix argument FULL-ENTRY, make the entire entry visible
  8163. if it was hidden in the outline."
  8164. (interactive "p")
  8165. (let ((win (selected-window)))
  8166. (org-agenda-goto t)
  8167. (org-back-to-heading)
  8168. (set-window-start (selected-window) (point-at-bol))
  8169. (cond
  8170. ((= more 0)
  8171. (outline-hide-subtree)
  8172. (save-excursion
  8173. (org-back-to-heading)
  8174. (run-hook-with-args 'org-cycle-hook 'folded))
  8175. (message "Remote: FOLDED"))
  8176. ((and (called-interactively-p 'any) (= more 1))
  8177. (message "Remote: show with default settings"))
  8178. ((= more 2)
  8179. (outline-show-entry)
  8180. (org-show-children)
  8181. (save-excursion
  8182. (org-back-to-heading)
  8183. (run-hook-with-args 'org-cycle-hook 'children))
  8184. (message "Remote: CHILDREN"))
  8185. ((= more 3)
  8186. (outline-show-subtree)
  8187. (save-excursion
  8188. (org-back-to-heading)
  8189. (run-hook-with-args 'org-cycle-hook 'subtree))
  8190. (message "Remote: SUBTREE"))
  8191. ((= more 4)
  8192. (outline-show-subtree)
  8193. (save-excursion
  8194. (org-back-to-heading)
  8195. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8196. (message "Remote: SUBTREE AND LOGBOOK"))
  8197. ((> more 4)
  8198. (outline-show-subtree)
  8199. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8200. (select-window win)))
  8201. (defvar org-agenda-cycle-counter nil)
  8202. (defun org-agenda-cycle-show (&optional n)
  8203. "Show the current entry in another window, with default settings.
  8204. Default settings are taken from `org-show-context-detail'. When
  8205. use repeatedly in immediate succession, the remote entry will
  8206. cycle through visibility
  8207. children -> subtree -> folded
  8208. When called with a numeric prefix arg, that arg will be passed through to
  8209. `org-agenda-show-1'. For the interpretation of that argument, see the
  8210. docstring of `org-agenda-show-1'."
  8211. (interactive "P")
  8212. (if (integerp n)
  8213. (setq org-agenda-cycle-counter n)
  8214. (if (not (eq last-command this-command))
  8215. (setq org-agenda-cycle-counter 1)
  8216. (if (equal org-agenda-cycle-counter 0)
  8217. (setq org-agenda-cycle-counter 2)
  8218. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8219. (if (> org-agenda-cycle-counter 3)
  8220. (setq org-agenda-cycle-counter 0)))))
  8221. (org-agenda-show-1 org-agenda-cycle-counter))
  8222. (defun org-agenda-recenter (arg)
  8223. "Display the Org file which contains the item at point and recenter."
  8224. (interactive "P")
  8225. (let ((win (selected-window)))
  8226. (org-agenda-goto t)
  8227. (recenter arg)
  8228. (select-window win)))
  8229. (defun org-agenda-show-mouse (ev)
  8230. "Display the Org file which contains the item at the mouse click."
  8231. (interactive "e")
  8232. (mouse-set-point ev)
  8233. (org-agenda-show))
  8234. (defun org-agenda-check-no-diary ()
  8235. "Check if the entry is a diary link and abort if yes."
  8236. (if (org-get-at-bol 'org-agenda-diary-link)
  8237. (org-agenda-error)))
  8238. (defun org-agenda-error ()
  8239. "Throw an error when a command is not allowed in the agenda."
  8240. (user-error "Command not allowed in this line"))
  8241. (defun org-agenda-tree-to-indirect-buffer (arg)
  8242. "Show the subtree corresponding to the current entry in an indirect buffer.
  8243. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8244. With a numerical prefix ARG, go up to this level and then take that tree.
  8245. With a negative numeric ARG, go up by this number of levels.
  8246. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  8247. i.e. don't use
  8248. the dedicated frame."
  8249. (interactive "P")
  8250. (if current-prefix-arg
  8251. (org-agenda-do-tree-to-indirect-buffer arg)
  8252. (let ((agenda-buffer (buffer-name))
  8253. (agenda-window (selected-window))
  8254. (indirect-window
  8255. (and org-last-indirect-buffer
  8256. (get-buffer-window org-last-indirect-buffer))))
  8257. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8258. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8259. (eq org-indirect-buffer-display 'dedicated-frame))
  8260. (unwind-protect
  8261. (unless (and indirect-window (window-live-p indirect-window))
  8262. (setq indirect-window (split-window agenda-window)))
  8263. (and indirect-window (select-window indirect-window))
  8264. (switch-to-buffer org-last-indirect-buffer :norecord)
  8265. (fit-window-to-buffer indirect-window)))
  8266. (select-window (get-buffer-window agenda-buffer))
  8267. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  8268. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8269. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8270. (org-agenda-check-no-diary)
  8271. (let* ((marker (or (org-get-at-bol 'org-marker)
  8272. (org-agenda-error)))
  8273. (buffer (marker-buffer marker))
  8274. (pos (marker-position marker)))
  8275. (with-current-buffer buffer
  8276. (save-excursion
  8277. (goto-char pos)
  8278. (funcall 'org-tree-to-indirect-buffer arg)))))
  8279. (defvar org-last-heading-marker (make-marker)
  8280. "Marker pointing to the headline that last changed its TODO state
  8281. by a remote command from the agenda.")
  8282. (defun org-agenda-todo-nextset ()
  8283. "Switch TODO entry to next sequence."
  8284. (interactive)
  8285. (org-agenda-todo 'nextset))
  8286. (defun org-agenda-todo-previousset ()
  8287. "Switch TODO entry to previous sequence."
  8288. (interactive)
  8289. (org-agenda-todo 'previousset))
  8290. (defun org-agenda-todo (&optional arg)
  8291. "Cycle TODO state of line at point, also in Org file.
  8292. This changes the line at point, all other lines in the agenda referring to
  8293. the same tree node, and the headline of the tree node in the Org file."
  8294. (interactive "P")
  8295. (org-agenda-check-no-diary)
  8296. (let* ((col (current-column))
  8297. (marker (or (org-get-at-bol 'org-marker)
  8298. (org-agenda-error)))
  8299. (buffer (marker-buffer marker))
  8300. (pos (marker-position marker))
  8301. (hdmarker (org-get-at-bol 'org-hd-marker))
  8302. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  8303. (inhibit-read-only t)
  8304. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8305. (org-with-remote-undo buffer
  8306. (with-current-buffer buffer
  8307. (widen)
  8308. (goto-char pos)
  8309. (org-show-context 'agenda)
  8310. (let ((current-prefix-arg arg))
  8311. (call-interactively 'org-todo))
  8312. (and (bolp) (forward-char 1))
  8313. (setq newhead (org-get-heading))
  8314. (when (and (bound-and-true-p
  8315. org-agenda-headline-snapshot-before-repeat)
  8316. (not (equal org-agenda-headline-snapshot-before-repeat
  8317. newhead))
  8318. todayp)
  8319. (setq newhead org-agenda-headline-snapshot-before-repeat
  8320. just-one t))
  8321. (save-excursion
  8322. (org-back-to-heading)
  8323. (move-marker org-last-heading-marker (point))))
  8324. (beginning-of-line 1)
  8325. (save-window-excursion
  8326. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8327. (when (bound-and-true-p org-clock-out-when-done)
  8328. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8329. newhead)
  8330. (org-agenda-unmark-clocking-task))
  8331. (org-move-to-column col)
  8332. (org-agenda-mark-clocking-task))))
  8333. (defun org-agenda-add-note (&optional arg)
  8334. "Add a time-stamped note to the entry at point."
  8335. (interactive "P")
  8336. (org-agenda-check-no-diary)
  8337. (let* ((marker (or (org-get-at-bol 'org-marker)
  8338. (org-agenda-error)))
  8339. (buffer (marker-buffer marker))
  8340. (pos (marker-position marker))
  8341. (hdmarker (org-get-at-bol 'org-hd-marker))
  8342. (inhibit-read-only t))
  8343. (with-current-buffer buffer
  8344. (widen)
  8345. (goto-char pos)
  8346. (org-show-context 'agenda)
  8347. (org-add-note))))
  8348. (defun org-agenda-change-all-lines (newhead hdmarker
  8349. &optional fixface just-this)
  8350. "Change all lines in the agenda buffer which match HDMARKER.
  8351. The new content of the line will be NEWHEAD (as modified by
  8352. `org-agenda-format-item'). HDMARKER is checked with
  8353. `equal' against all `org-hd-marker' text properties in the file.
  8354. If FIXFACE is non-nil, the face of each item is modified according to
  8355. the new TODO state.
  8356. If JUST-THIS is non-nil, change just the current line, not all.
  8357. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8358. (let* ((inhibit-read-only t)
  8359. (line (org-current-line))
  8360. (org-agenda-buffer (current-buffer))
  8361. (thetags (with-current-buffer (marker-buffer hdmarker)
  8362. (org-with-wide-buffer
  8363. (goto-char hdmarker)
  8364. (org-get-tags-at))))
  8365. props m pl undone-face done-face finish new dotime level cat tags)
  8366. (save-excursion
  8367. (goto-char (point-max))
  8368. (beginning-of-line 1)
  8369. (while (not finish)
  8370. (setq finish (bobp))
  8371. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8372. (or (not just-this) (= (org-current-line) line))
  8373. (equal m hdmarker))
  8374. (setq props (text-properties-at (point))
  8375. dotime (org-get-at-bol 'dotime)
  8376. cat (org-get-at-eol 'org-category 1)
  8377. level (org-get-at-bol 'level)
  8378. tags thetags
  8379. new
  8380. (let ((org-prefix-format-compiled
  8381. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8382. org-prefix-format-compiled))
  8383. (extra (org-get-at-bol 'extra)))
  8384. (with-current-buffer (marker-buffer hdmarker)
  8385. (org-with-wide-buffer
  8386. (org-agenda-format-item extra newhead level cat tags dotime))))
  8387. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8388. undone-face (org-get-at-bol 'undone-face)
  8389. done-face (org-get-at-bol 'done-face))
  8390. (beginning-of-line 1)
  8391. (cond
  8392. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  8393. ((looking-at ".*")
  8394. ;; When replacing the whole line, preserve bulk mark
  8395. ;; overlay, if any.
  8396. (let ((mark (catch :overlay
  8397. (dolist (o (overlays-in (point) (+ 2 (point))))
  8398. (when (eq (overlay-get o 'type)
  8399. 'org-marked-entry-overlay)
  8400. (throw :overlay o))))))
  8401. (replace-match new t t)
  8402. (beginning-of-line)
  8403. (when mark (move-overlay mark (point) (+ 2 (point)))))
  8404. (add-text-properties (point-at-bol) (point-at-eol) props)
  8405. (when fixface
  8406. (add-text-properties
  8407. (point-at-bol) (point-at-eol)
  8408. (list 'face
  8409. (if org-last-todo-state-is-todo
  8410. undone-face done-face))))
  8411. (org-agenda-highlight-todo 'line)
  8412. (beginning-of-line 1))
  8413. (t (error "Line update did not work")))
  8414. (save-restriction
  8415. (narrow-to-region (point-at-bol) (point-at-eol))
  8416. (org-agenda-finalize)))
  8417. (beginning-of-line 0)))))
  8418. (defun org-agenda-align-tags (&optional line)
  8419. "Align all tags in agenda items to `org-agenda-tags-column'."
  8420. (let ((inhibit-read-only t) l c)
  8421. (save-excursion
  8422. (goto-char (if line (point-at-bol) (point-min)))
  8423. (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
  8424. (if line (point-at-eol) nil) t)
  8425. (add-text-properties
  8426. (match-beginning 2) (match-end 2)
  8427. (list 'face (delq nil (let ((prop (get-text-property
  8428. (match-beginning 2) 'face)))
  8429. (or (listp prop) (setq prop (list prop)))
  8430. (if (memq 'org-tag prop)
  8431. prop
  8432. (cons 'org-tag prop))))))
  8433. (setq l (- (match-end 2) (match-beginning 2))
  8434. c (if (< org-agenda-tags-column 0)
  8435. (- (abs org-agenda-tags-column) l)
  8436. org-agenda-tags-column))
  8437. (delete-region (match-beginning 1) (match-end 1))
  8438. (goto-char (match-beginning 1))
  8439. (insert (org-add-props
  8440. (make-string (max 1 (- c (current-column))) ?\ )
  8441. (plist-put (copy-sequence (text-properties-at (point)))
  8442. 'face nil))))
  8443. (goto-char (point-min))
  8444. (org-font-lock-add-tag-faces (point-max)))))
  8445. (defun org-agenda-priority-up ()
  8446. "Increase the priority of line at point, also in Org file."
  8447. (interactive)
  8448. (org-agenda-priority 'up))
  8449. (defun org-agenda-priority-down ()
  8450. "Decrease the priority of line at point, also in Org file."
  8451. (interactive)
  8452. (org-agenda-priority 'down))
  8453. (defun org-agenda-priority (&optional force-direction)
  8454. "Set the priority of line at point, also in Org file.
  8455. This changes the line at point, all other lines in the agenda referring to
  8456. the same tree node, and the headline of the tree node in the Org file.
  8457. Called with a universal prefix arg, show the priority instead of setting it."
  8458. (interactive "P")
  8459. (if (equal force-direction '(4))
  8460. (org-show-priority)
  8461. (unless org-enable-priority-commands
  8462. (error "Priority commands are disabled"))
  8463. (org-agenda-check-no-diary)
  8464. (let* ((col (current-column))
  8465. (marker (or (org-get-at-bol 'org-marker)
  8466. (org-agenda-error)))
  8467. (hdmarker (org-get-at-bol 'org-hd-marker))
  8468. (buffer (marker-buffer hdmarker))
  8469. (pos (marker-position hdmarker))
  8470. (inhibit-read-only t)
  8471. newhead)
  8472. (org-with-remote-undo buffer
  8473. (with-current-buffer buffer
  8474. (widen)
  8475. (goto-char pos)
  8476. (org-show-context 'agenda)
  8477. (funcall 'org-priority force-direction)
  8478. (end-of-line 1)
  8479. (setq newhead (org-get-heading)))
  8480. (org-agenda-change-all-lines newhead hdmarker)
  8481. (org-move-to-column col)))))
  8482. ;; FIXME: should fix the tags property of the agenda line.
  8483. (defun org-agenda-set-tags (&optional tag onoff)
  8484. "Set tags for the current headline."
  8485. (interactive)
  8486. (org-agenda-check-no-diary)
  8487. (if (and (org-region-active-p) (called-interactively-p 'any))
  8488. (call-interactively 'org-change-tag-in-region)
  8489. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8490. (org-agenda-error)))
  8491. (buffer (marker-buffer hdmarker))
  8492. (pos (marker-position hdmarker))
  8493. (inhibit-read-only t)
  8494. newhead)
  8495. (org-with-remote-undo buffer
  8496. (with-current-buffer buffer
  8497. (widen)
  8498. (goto-char pos)
  8499. (org-show-context 'agenda)
  8500. (if tag
  8501. (org-toggle-tag tag onoff)
  8502. (call-interactively 'org-set-tags))
  8503. (end-of-line 1)
  8504. (setq newhead (org-get-heading)))
  8505. (org-agenda-change-all-lines newhead hdmarker)
  8506. (beginning-of-line 1)))))
  8507. (defun org-agenda-set-property ()
  8508. "Set a property for the current headline."
  8509. (interactive)
  8510. (org-agenda-check-no-diary)
  8511. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8512. (org-agenda-error)))
  8513. (buffer (marker-buffer hdmarker))
  8514. (pos (marker-position hdmarker))
  8515. (inhibit-read-only t)
  8516. newhead)
  8517. (org-with-remote-undo buffer
  8518. (with-current-buffer buffer
  8519. (widen)
  8520. (goto-char pos)
  8521. (org-show-context 'agenda)
  8522. (call-interactively 'org-set-property)))))
  8523. (defun org-agenda-set-effort ()
  8524. "Set the effort property for the current headline."
  8525. (interactive)
  8526. (org-agenda-check-no-diary)
  8527. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8528. (org-agenda-error)))
  8529. (buffer (marker-buffer hdmarker))
  8530. (pos (marker-position hdmarker))
  8531. (inhibit-read-only t)
  8532. newhead)
  8533. (org-with-remote-undo buffer
  8534. (with-current-buffer buffer
  8535. (widen)
  8536. (goto-char pos)
  8537. (org-show-context 'agenda)
  8538. (call-interactively 'org-set-effort)
  8539. (end-of-line 1)
  8540. (setq newhead (org-get-heading)))
  8541. (org-agenda-change-all-lines newhead hdmarker))))
  8542. (defun org-agenda-toggle-archive-tag ()
  8543. "Toggle the archive tag for the current entry."
  8544. (interactive)
  8545. (org-agenda-check-no-diary)
  8546. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8547. (org-agenda-error)))
  8548. (buffer (marker-buffer hdmarker))
  8549. (pos (marker-position hdmarker))
  8550. (inhibit-read-only t)
  8551. newhead)
  8552. (org-with-remote-undo buffer
  8553. (with-current-buffer buffer
  8554. (widen)
  8555. (goto-char pos)
  8556. (org-show-context 'agenda)
  8557. (call-interactively 'org-toggle-archive-tag)
  8558. (end-of-line 1)
  8559. (setq newhead (org-get-heading)))
  8560. (org-agenda-change-all-lines newhead hdmarker)
  8561. (beginning-of-line 1))))
  8562. (defun org-agenda-do-date-later (arg)
  8563. (interactive "P")
  8564. (cond
  8565. ((or (equal arg '(16))
  8566. (memq last-command
  8567. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8568. (setq this-command 'org-agenda-date-later-minutes)
  8569. (org-agenda-date-later-minutes 1))
  8570. ((or (equal arg '(4))
  8571. (memq last-command
  8572. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8573. (setq this-command 'org-agenda-date-later-hours)
  8574. (org-agenda-date-later-hours 1))
  8575. (t
  8576. (org-agenda-date-later (prefix-numeric-value arg)))))
  8577. (defun org-agenda-do-date-earlier (arg)
  8578. (interactive "P")
  8579. (cond
  8580. ((or (equal arg '(16))
  8581. (memq last-command
  8582. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8583. (setq this-command 'org-agenda-date-earlier-minutes)
  8584. (org-agenda-date-earlier-minutes 1))
  8585. ((or (equal arg '(4))
  8586. (memq last-command
  8587. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8588. (setq this-command 'org-agenda-date-earlier-hours)
  8589. (org-agenda-date-earlier-hours 1))
  8590. (t
  8591. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8592. (defun org-agenda-date-later (arg &optional what)
  8593. "Change the date of this item to ARG day(s) later."
  8594. (interactive "p")
  8595. (org-agenda-check-type t 'agenda 'timeline)
  8596. (org-agenda-check-no-diary)
  8597. (let* ((marker (or (org-get-at-bol 'org-marker)
  8598. (org-agenda-error)))
  8599. (buffer (marker-buffer marker))
  8600. (pos (marker-position marker))
  8601. cdate today)
  8602. (org-with-remote-undo buffer
  8603. (with-current-buffer buffer
  8604. (widen)
  8605. (goto-char pos)
  8606. (if (not (org-at-timestamp-p))
  8607. (error "Cannot find time stamp"))
  8608. (when (and org-agenda-move-date-from-past-immediately-to-today
  8609. (equal arg 1)
  8610. (or (not what) (eq what 'day))
  8611. (not (save-match-data (org-at-date-range-p))))
  8612. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8613. cdate (calendar-absolute-from-gregorian
  8614. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8615. today (org-today))
  8616. (if (> today cdate)
  8617. ;; immediately shift to today
  8618. (setq arg (- today cdate))))
  8619. (org-timestamp-change arg (or what 'day))
  8620. (when (and (org-at-date-range-p)
  8621. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8622. (let ((end org-last-changed-timestamp))
  8623. (org-timestamp-change arg (or what 'day))
  8624. (setq org-last-changed-timestamp
  8625. (concat org-last-changed-timestamp "--" end)))))
  8626. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8627. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8628. (defun org-agenda-date-earlier (arg &optional what)
  8629. "Change the date of this item to ARG day(s) earlier."
  8630. (interactive "p")
  8631. (org-agenda-date-later (- arg) what))
  8632. (defun org-agenda-date-later-minutes (arg)
  8633. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8634. (interactive "p")
  8635. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8636. (org-agenda-date-later arg 'minute))
  8637. (defun org-agenda-date-earlier-minutes (arg)
  8638. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8639. (interactive "p")
  8640. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8641. (org-agenda-date-earlier arg 'minute))
  8642. (defun org-agenda-date-later-hours (arg)
  8643. "Change the time of this item, in hour steps."
  8644. (interactive "p")
  8645. (org-agenda-date-later arg 'hour))
  8646. (defun org-agenda-date-earlier-hours (arg)
  8647. "Change the time of this item, in hour steps."
  8648. (interactive "p")
  8649. (org-agenda-date-earlier arg 'hour))
  8650. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8651. "Show new date stamp via text properties."
  8652. ;; We use text properties to make this undoable
  8653. (let ((inhibit-read-only t))
  8654. (setq stamp (concat prefix " => " stamp " "))
  8655. (save-excursion
  8656. (goto-char (point-max))
  8657. (while (not (bobp))
  8658. (when (equal marker (org-get-at-bol 'org-marker))
  8659. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8660. (org-move-to-column (- (window-width) (length stamp)) t)
  8661. (add-text-properties
  8662. (1- (point)) (point-at-eol)
  8663. (list 'display (org-add-props stamp nil
  8664. 'face '(secondary-selection default))))
  8665. (beginning-of-line 1))
  8666. (beginning-of-line 0)))))
  8667. (defun org-agenda-date-prompt (arg)
  8668. "Change the date of this item. Date is prompted for, with default today.
  8669. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8670. be used to request time specification in the time stamp."
  8671. (interactive "P")
  8672. (org-agenda-check-type t 'agenda 'timeline)
  8673. (org-agenda-check-no-diary)
  8674. (let* ((marker (or (org-get-at-bol 'org-marker)
  8675. (org-agenda-error)))
  8676. (buffer (marker-buffer marker))
  8677. (pos (marker-position marker)))
  8678. (org-with-remote-undo buffer
  8679. (with-current-buffer buffer
  8680. (widen)
  8681. (goto-char pos)
  8682. (if (not (org-at-timestamp-p t))
  8683. (error "Cannot find time stamp"))
  8684. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8685. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8686. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8687. (defun org-agenda-schedule (arg &optional time)
  8688. "Schedule the item at point.
  8689. ARG is passed through to `org-schedule'."
  8690. (interactive "P")
  8691. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8692. (org-agenda-check-no-diary)
  8693. (let* ((marker (or (org-get-at-bol 'org-marker)
  8694. (org-agenda-error)))
  8695. (type (marker-insertion-type marker))
  8696. (buffer (marker-buffer marker))
  8697. (pos (marker-position marker))
  8698. ts)
  8699. (set-marker-insertion-type marker t)
  8700. (org-with-remote-undo buffer
  8701. (with-current-buffer buffer
  8702. (widen)
  8703. (goto-char pos)
  8704. (setq ts (org-schedule arg time)))
  8705. (org-agenda-show-new-time marker ts " S"))
  8706. (message "%s" ts)))
  8707. (defun org-agenda-deadline (arg &optional time)
  8708. "Schedule the item at point.
  8709. ARG is passed through to `org-deadline'."
  8710. (interactive "P")
  8711. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8712. (org-agenda-check-no-diary)
  8713. (let* ((marker (or (org-get-at-bol 'org-marker)
  8714. (org-agenda-error)))
  8715. (buffer (marker-buffer marker))
  8716. (pos (marker-position marker))
  8717. ts)
  8718. (org-with-remote-undo buffer
  8719. (with-current-buffer buffer
  8720. (widen)
  8721. (goto-char pos)
  8722. (setq ts (org-deadline arg time)))
  8723. (org-agenda-show-new-time marker ts " D"))
  8724. (message "%s" ts)))
  8725. (defun org-agenda-clock-in (&optional arg)
  8726. "Start the clock on the currently selected item."
  8727. (interactive "P")
  8728. (org-agenda-check-no-diary)
  8729. (if (equal arg '(4))
  8730. (org-clock-in arg)
  8731. (let* ((marker (or (org-get-at-bol 'org-marker)
  8732. (org-agenda-error)))
  8733. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8734. (pos (marker-position marker))
  8735. (col (current-column))
  8736. newhead)
  8737. (org-with-remote-undo (marker-buffer marker)
  8738. (with-current-buffer (marker-buffer marker)
  8739. (widen)
  8740. (goto-char pos)
  8741. (org-show-context 'agenda)
  8742. (org-cycle-hide-drawers 'children)
  8743. (org-clock-in arg)
  8744. (setq newhead (org-get-heading)))
  8745. (org-agenda-change-all-lines newhead hdmarker))
  8746. (org-move-to-column col))))
  8747. (defun org-agenda-clock-out ()
  8748. "Stop the currently running clock."
  8749. (interactive)
  8750. (unless (marker-buffer org-clock-marker)
  8751. (error "No running clock"))
  8752. (let ((marker (make-marker)) (col (current-column)) newhead)
  8753. (org-with-remote-undo (marker-buffer org-clock-marker)
  8754. (with-current-buffer (marker-buffer org-clock-marker)
  8755. (org-with-wide-buffer
  8756. (goto-char org-clock-marker)
  8757. (org-back-to-heading t)
  8758. (move-marker marker (point))
  8759. (org-clock-out)
  8760. (setq newhead (org-get-heading)))))
  8761. (org-agenda-change-all-lines newhead marker)
  8762. (move-marker marker nil)
  8763. (org-move-to-column col)
  8764. (org-agenda-unmark-clocking-task)))
  8765. (defun org-agenda-clock-cancel (&optional arg)
  8766. "Cancel the currently running clock."
  8767. (interactive "P")
  8768. (unless (marker-buffer org-clock-marker)
  8769. (user-error "No running clock"))
  8770. (org-with-remote-undo (marker-buffer org-clock-marker)
  8771. (org-clock-cancel)))
  8772. (defun org-agenda-clock-goto ()
  8773. "Jump to the currently clocked in task within the agenda.
  8774. If the currently clocked in task is not listed in the agenda
  8775. buffer, display it in another window."
  8776. (interactive)
  8777. (let (pos)
  8778. (mapc (lambda (o)
  8779. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8780. (setq pos (overlay-start o))))
  8781. (overlays-in (point-min) (point-max)))
  8782. (cond (pos (goto-char pos))
  8783. ;; If the currently clocked entry is not in the agenda
  8784. ;; buffer, we visit it in another window:
  8785. ((bound-and-true-p org-clock-current-task)
  8786. (org-switch-to-buffer-other-window (org-clock-goto)))
  8787. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8788. (defun org-agenda-diary-entry-in-org-file ()
  8789. "Make a diary entry in the file `org-agenda-diary-file'."
  8790. (let (d1 d2 char (text "") dp1 dp2)
  8791. (if (equal (buffer-name) "*Calendar*")
  8792. (setq d1 (calendar-cursor-to-date t)
  8793. d2 (car calendar-mark-ring))
  8794. (setq dp1 (get-text-property (point-at-bol) 'day))
  8795. (unless dp1 (user-error "No date defined in current line"))
  8796. (setq d1 (calendar-gregorian-from-absolute dp1)
  8797. d2 (and (ignore-errors (mark))
  8798. (save-excursion
  8799. (goto-char (mark))
  8800. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8801. (calendar-gregorian-from-absolute dp2))))
  8802. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8803. (setq char (read-char-exclusive))
  8804. (cond
  8805. ((equal char ?d)
  8806. (setq text (read-string "Day entry: "))
  8807. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8808. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8809. ((equal char ?a)
  8810. (setq d1 (list (car d1) (nth 1 d1)
  8811. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8812. (nth 2 d1))))
  8813. (setq text (read-string "Anniversary (use %d to show years): "))
  8814. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8815. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8816. ((equal char ?b)
  8817. (setq text (read-string "Block entry: "))
  8818. (unless (and d1 d2 (not (equal d1 d2)))
  8819. (user-error "No block of days selected"))
  8820. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8821. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8822. ((equal char ?j)
  8823. (org-switch-to-buffer-other-window
  8824. (find-file-noselect org-agenda-diary-file))
  8825. (require 'org-datetree)
  8826. (org-datetree-find-date-create d1)
  8827. (org-reveal t))
  8828. (t (user-error "Invalid selection character `%c'" char)))))
  8829. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8830. "Where in `org-agenda-diary-file' should new entries be added?
  8831. Valid values:
  8832. date-tree in the date tree, as first child of the date
  8833. date-tree-last in the date tree, as last child of the date
  8834. top-level as top-level entries at the end of the file."
  8835. :group 'org-agenda
  8836. :type '(choice
  8837. (const :tag "first in a date tree" date-tree)
  8838. (const :tag "last in a date tree" date-tree-last)
  8839. (const :tag "as top level at end of file" top-level)))
  8840. (defcustom org-agenda-insert-diary-extract-time nil
  8841. "Non-nil means extract any time specification from the diary entry."
  8842. :group 'org-agenda
  8843. :version "24.1"
  8844. :type 'boolean)
  8845. (defcustom org-agenda-bulk-mark-char ">"
  8846. "A single-character string to be used as the bulk mark."
  8847. :group 'org-agenda
  8848. :version "24.1"
  8849. :type 'string)
  8850. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8851. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8852. If TEXT is not empty, it will become the headline of the new entry, and
  8853. the resulting entry will not be shown. When TEXT is empty, switch to
  8854. `org-agenda-diary-file' and let the user finish the entry there."
  8855. (let ((cw (current-window-configuration)))
  8856. (org-switch-to-buffer-other-window
  8857. (find-file-noselect org-agenda-diary-file))
  8858. (widen)
  8859. (goto-char (point-min))
  8860. (cond
  8861. ((eq type 'anniversary)
  8862. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8863. (progn
  8864. (or (org-at-heading-p t)
  8865. (progn
  8866. (outline-next-heading)
  8867. (insert "* Anniversaries\n\n")
  8868. (beginning-of-line -1)))))
  8869. (outline-next-heading)
  8870. (org-back-over-empty-lines)
  8871. (backward-char 1)
  8872. (insert "\n")
  8873. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8874. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8875. ((eq type 'day)
  8876. (let ((org-prefix-has-time t)
  8877. (org-agenda-time-leading-zero t)
  8878. fmt time time2)
  8879. (if org-agenda-insert-diary-extract-time
  8880. ;; Use org-agenda-format-item to parse text for a time-range and
  8881. ;; remove it. FIXME: This is a hack, we should refactor
  8882. ;; that function to make time extraction available separately
  8883. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8884. time (get-text-property 0 'time fmt)
  8885. time2 (if (> (length time) 0)
  8886. ;; split-string removes trailing ...... if
  8887. ;; no end time given. First space
  8888. ;; separates time from date.
  8889. (concat " " (car (split-string time "\\.")))
  8890. nil)
  8891. text (get-text-property 0 'txt fmt)))
  8892. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8893. (org-agenda-insert-diary-as-top-level text)
  8894. (require 'org-datetree)
  8895. (org-datetree-find-date-create d1)
  8896. (org-agenda-insert-diary-make-new-entry text))
  8897. (org-insert-time-stamp (org-time-from-absolute
  8898. (calendar-absolute-from-gregorian d1))
  8899. nil nil nil nil time2))
  8900. (end-of-line 0))
  8901. ((eq type 'block)
  8902. (if (> (calendar-absolute-from-gregorian d1)
  8903. (calendar-absolute-from-gregorian d2))
  8904. (setq d1 (prog1 d2 (setq d2 d1))))
  8905. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8906. (org-agenda-insert-diary-as-top-level text)
  8907. (require 'org-datetree)
  8908. (org-datetree-find-date-create d1)
  8909. (org-agenda-insert-diary-make-new-entry text))
  8910. (org-insert-time-stamp (org-time-from-absolute
  8911. (calendar-absolute-from-gregorian d1)))
  8912. (insert "--")
  8913. (org-insert-time-stamp (org-time-from-absolute
  8914. (calendar-absolute-from-gregorian d2)))
  8915. (end-of-line 0)))
  8916. (if (string-match "\\S-" text)
  8917. (progn
  8918. (set-window-configuration cw)
  8919. (message "%s entry added to %s"
  8920. (capitalize (symbol-name type))
  8921. (abbreviate-file-name org-agenda-diary-file)))
  8922. (org-reveal t)
  8923. (message "Please finish entry here"))))
  8924. (defun org-agenda-insert-diary-as-top-level (text)
  8925. "Make new entry as a top-level entry at the end of the file.
  8926. Add TEXT as headline, and position the cursor in the second line so that
  8927. a timestamp can be added there."
  8928. (widen)
  8929. (goto-char (point-max))
  8930. (unless (bolp) (insert "\n"))
  8931. (org-insert-heading nil t t)
  8932. (insert text)
  8933. (org-end-of-meta-data)
  8934. (unless (bolp) (insert "\n"))
  8935. (when org-adapt-indentation (indent-to-column 2)))
  8936. (defun org-agenda-insert-diary-make-new-entry (text)
  8937. "Make a new entry with TEXT as a child of the current subtree.
  8938. Position the point in the heading's first body line so that
  8939. a timestamp can be added there."
  8940. (cond
  8941. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  8942. (end-of-line)
  8943. (org-insert-heading '(4) t)
  8944. (org-do-demote))
  8945. (t
  8946. (outline-next-heading)
  8947. (org-back-over-empty-lines)
  8948. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  8949. (org-insert-heading nil t)
  8950. (org-do-demote)))
  8951. (let ((col (current-column)))
  8952. (insert text)
  8953. (org-end-of-meta-data)
  8954. ;; Ensure point is left on a blank line, at proper indentation.
  8955. (unless (bolp) (insert "\n"))
  8956. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  8957. (when org-adapt-indentation (indent-to-column col)))
  8958. (org-show-set-visibility 'lineage))
  8959. (defun org-agenda-diary-entry ()
  8960. "Make a diary entry, like the `i' command from the calendar.
  8961. All the standard commands work: block, weekly etc.
  8962. When `org-agenda-diary-file' points to a file,
  8963. `org-agenda-diary-entry-in-org-file' is called instead to create
  8964. entries in that Org file."
  8965. (interactive)
  8966. (if (not (eq org-agenda-diary-file 'diary-file))
  8967. (org-agenda-diary-entry-in-org-file)
  8968. (require 'diary-lib)
  8969. (let* ((char (progn
  8970. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8971. (read-char-exclusive)))
  8972. (cmd (cdr (assoc char
  8973. '((?d . diary-insert-entry)
  8974. (?w . diary-insert-weekly-entry)
  8975. (?m . diary-insert-monthly-entry)
  8976. (?y . diary-insert-yearly-entry)
  8977. (?a . diary-insert-anniversary-entry)
  8978. (?b . diary-insert-block-entry)
  8979. (?c . diary-insert-cyclic-entry)))))
  8980. (oldf (symbol-function 'calendar-cursor-to-date))
  8981. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8982. (point (point))
  8983. (mark (or (mark t) (point))))
  8984. (unless cmd
  8985. (user-error "No command associated with <%c>" char))
  8986. (unless (and (get-text-property point 'day)
  8987. (or (not (equal ?b char))
  8988. (get-text-property mark 'day)))
  8989. (user-error "Don't know which date to use for diary entry"))
  8990. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8991. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8992. (let ((calendar-mark-ring
  8993. (list (calendar-gregorian-from-absolute
  8994. (or (get-text-property mark 'day)
  8995. (get-text-property point 'day))))))
  8996. (unwind-protect
  8997. (progn
  8998. (fset 'calendar-cursor-to-date
  8999. (lambda (&optional error dummy)
  9000. (calendar-gregorian-from-absolute
  9001. (get-text-property point 'day))))
  9002. (call-interactively cmd))
  9003. (fset 'calendar-cursor-to-date oldf))))))
  9004. (defun org-agenda-execute-calendar-command (cmd)
  9005. "Execute a calendar command from the agenda with date from cursor."
  9006. (org-agenda-check-type t 'agenda 'timeline)
  9007. (require 'diary-lib)
  9008. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  9009. (user-error "Don't know which date to use for the calendar command"))
  9010. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  9011. (point (point))
  9012. (date (calendar-gregorian-from-absolute
  9013. (get-text-property point 'day)))
  9014. ;; the following 2 vars are needed in the calendar
  9015. (displayed-month (car date))
  9016. (displayed-year (nth 2 date)))
  9017. (unwind-protect
  9018. (progn
  9019. (fset 'calendar-cursor-to-date
  9020. (lambda (&optional error dummy)
  9021. (calendar-gregorian-from-absolute
  9022. (get-text-property point 'day))))
  9023. (call-interactively cmd))
  9024. (fset 'calendar-cursor-to-date oldf))))
  9025. (defun org-agenda-phases-of-moon ()
  9026. "Display the phases of the moon for the 3 months around the cursor date."
  9027. (interactive)
  9028. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  9029. (defun org-agenda-holidays ()
  9030. "Display the holidays for the 3 months around the cursor date."
  9031. (interactive)
  9032. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  9033. (defvar calendar-longitude) ; defined in calendar.el
  9034. (defvar calendar-latitude) ; defined in calendar.el
  9035. (defvar calendar-location-name) ; defined in calendar.el
  9036. (defun org-agenda-sunrise-sunset (arg)
  9037. "Display sunrise and sunset for the cursor date.
  9038. Latitude and longitude can be specified with the variables
  9039. `calendar-latitude' and `calendar-longitude'. When called with prefix
  9040. argument, latitude and longitude will be prompted for."
  9041. (interactive "P")
  9042. (require 'solar)
  9043. (let ((calendar-longitude (if arg nil calendar-longitude))
  9044. (calendar-latitude (if arg nil calendar-latitude))
  9045. (calendar-location-name
  9046. (if arg "the given coordinates" calendar-location-name)))
  9047. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  9048. (defun org-agenda-goto-calendar ()
  9049. "Open the Emacs calendar with the date at the cursor."
  9050. (interactive)
  9051. (org-agenda-check-type t 'agenda 'timeline)
  9052. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  9053. (user-error "Don't know which date to open in calendar")))
  9054. (date (calendar-gregorian-from-absolute day))
  9055. (calendar-move-hook nil)
  9056. (calendar-view-holidays-initially-flag nil)
  9057. (calendar-view-diary-initially-flag nil))
  9058. (calendar)
  9059. (calendar-goto-date date)))
  9060. ;;;###autoload
  9061. (defun org-calendar-goto-agenda ()
  9062. "Compute the Org agenda for the calendar date displayed at the cursor.
  9063. This is a command that has to be installed in `calendar-mode-map'."
  9064. (interactive)
  9065. ;; Temporarily disable sticky agenda since user clearly wants to
  9066. ;; refresh view anyway.
  9067. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  9068. (org-agenda-sticky nil))
  9069. (org-agenda-list nil (calendar-absolute-from-gregorian
  9070. (calendar-cursor-to-date))
  9071. nil)))
  9072. (defun org-agenda-convert-date ()
  9073. (interactive)
  9074. (org-agenda-check-type t 'agenda 'timeline)
  9075. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  9076. date s)
  9077. (unless day
  9078. (user-error "Don't know which date to convert"))
  9079. (setq date (calendar-gregorian-from-absolute day))
  9080. (setq s (concat
  9081. "Gregorian: " (calendar-date-string date) "\n"
  9082. "ISO: " (calendar-iso-date-string date) "\n"
  9083. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  9084. "Julian: " (calendar-julian-date-string date) "\n"
  9085. "Astron. JD: " (calendar-astro-date-string date)
  9086. " (Julian date number at noon UTC)\n"
  9087. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9088. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9089. "French: " (calendar-french-date-string date) "\n"
  9090. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  9091. "Mayan: " (calendar-mayan-date-string date) "\n"
  9092. "Coptic: " (calendar-coptic-date-string date) "\n"
  9093. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9094. "Persian: " (calendar-persian-date-string date) "\n"
  9095. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9096. (with-output-to-temp-buffer "*Dates*"
  9097. (princ s))
  9098. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9099. ;;; Bulk commands
  9100. (defun org-agenda-bulk-marked-p ()
  9101. "Non-nil when current entry is marked for bulk action."
  9102. (eq (get-char-property (point-at-bol) 'type)
  9103. 'org-marked-entry-overlay))
  9104. (defun org-agenda-bulk-mark (&optional arg)
  9105. "Mark the entry at point for future bulk action."
  9106. (interactive "p")
  9107. (dotimes (i (or arg 1))
  9108. (unless (org-get-at-bol 'org-agenda-diary-link)
  9109. (let* ((m (org-get-at-bol 'org-hd-marker))
  9110. ov)
  9111. (unless (org-agenda-bulk-marked-p)
  9112. (unless m (user-error "Nothing to mark at point"))
  9113. (push m org-agenda-bulk-marked-entries)
  9114. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9115. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9116. (org-get-todo-face "TODO")
  9117. 'evaporate)
  9118. (overlay-put ov 'type 'org-marked-entry-overlay))
  9119. (end-of-line 1)
  9120. (or (ignore-errors
  9121. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9122. (beginning-of-line 2))
  9123. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9124. (beginning-of-line 2))
  9125. (message "%d entries marked for bulk action"
  9126. (length org-agenda-bulk-marked-entries))))))
  9127. (defun org-agenda-bulk-mark-all ()
  9128. "Mark all entries for future agenda bulk action."
  9129. (interactive)
  9130. (org-agenda-bulk-mark-regexp "."))
  9131. (defun org-agenda-bulk-mark-regexp (regexp)
  9132. "Mark entries matching REGEXP for future agenda bulk action."
  9133. (interactive "sMark entries matching regexp: ")
  9134. (let ((entries-marked 0) txt-at-point)
  9135. (save-excursion
  9136. (goto-char (point-min))
  9137. (goto-char (next-single-property-change (point) 'org-hd-marker))
  9138. (while (and (re-search-forward regexp nil t)
  9139. (setq txt-at-point (get-text-property (point) 'txt)))
  9140. (if (get-char-property (point) 'invisible)
  9141. (beginning-of-line 2)
  9142. (when (string-match regexp txt-at-point)
  9143. (setq entries-marked (1+ entries-marked))
  9144. (call-interactively 'org-agenda-bulk-mark)))))
  9145. (if (not entries-marked)
  9146. (message "No entry matching this regexp."))))
  9147. (defun org-agenda-bulk-unmark (&optional arg)
  9148. "Unmark the entry at point for future bulk action."
  9149. (interactive "P")
  9150. (if arg
  9151. (org-agenda-bulk-unmark-all)
  9152. (cond ((org-agenda-bulk-marked-p)
  9153. (org-agenda-bulk-remove-overlays
  9154. (point-at-bol) (+ 2 (point-at-bol)))
  9155. (setq org-agenda-bulk-marked-entries
  9156. (delete (org-get-at-bol 'org-hd-marker)
  9157. org-agenda-bulk-marked-entries))
  9158. (end-of-line 1)
  9159. (or (ignore-errors
  9160. (goto-char (next-single-property-change (point) 'txt)))
  9161. (beginning-of-line 2))
  9162. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9163. (beginning-of-line 2))
  9164. (message "%d entries left marked for bulk action"
  9165. (length org-agenda-bulk-marked-entries)))
  9166. (t (message "No entry to unmark here")))))
  9167. (defun org-agenda-bulk-toggle-all ()
  9168. "Toggle all marks for bulk action."
  9169. (interactive)
  9170. (save-excursion
  9171. (goto-char (point-min))
  9172. (while (ignore-errors
  9173. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  9174. (org-agenda-bulk-toggle))))
  9175. (defun org-agenda-bulk-toggle ()
  9176. "Toggle the mark at point for bulk action."
  9177. (interactive)
  9178. (if (org-agenda-bulk-marked-p)
  9179. (org-agenda-bulk-unmark)
  9180. (org-agenda-bulk-mark)))
  9181. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9182. "Remove the mark overlays between BEG and END in the agenda buffer.
  9183. BEG and END default to the buffer limits.
  9184. This only removes the overlays, it does not remove the markers
  9185. from the list in `org-agenda-bulk-marked-entries'."
  9186. (interactive)
  9187. (mapc (lambda (ov)
  9188. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9189. (delete-overlay ov)))
  9190. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9191. (defun org-agenda-bulk-unmark-all ()
  9192. "Remove all marks in the agenda buffer.
  9193. This will remove the markers and the overlays."
  9194. (interactive)
  9195. (if (null org-agenda-bulk-marked-entries)
  9196. (message "No entry to unmark")
  9197. (setq org-agenda-bulk-marked-entries nil)
  9198. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9199. (defcustom org-agenda-persistent-marks nil
  9200. "Non-nil means marked items will stay marked after a bulk action.
  9201. You can toggle this interactively by typing `p' when prompted for a
  9202. bulk action."
  9203. :group 'org-agenda
  9204. :version "24.1"
  9205. :type 'boolean)
  9206. (defun org-agenda-bulk-action (&optional arg)
  9207. "Execute an remote-editing action on all marked entries.
  9208. The prefix arg is passed through to the command if possible."
  9209. (interactive "P")
  9210. ;; Make sure we have markers, and only valid ones
  9211. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9212. (mapc
  9213. (lambda (m)
  9214. (unless (and (markerp m)
  9215. (marker-buffer m)
  9216. (buffer-live-p (marker-buffer m))
  9217. (marker-position m))
  9218. (user-error "Marker %s for bulk command is invalid" m)))
  9219. org-agenda-bulk-marked-entries)
  9220. ;; Prompt for the bulk command
  9221. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9222. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9223. "[S]catter [f]unction "
  9224. (when org-agenda-bulk-custom-functions
  9225. (concat " Custom: ["
  9226. (mapconcat (lambda(f) (char-to-string (car f)))
  9227. org-agenda-bulk-custom-functions "")
  9228. "]"))))
  9229. (catch 'exit
  9230. (let* ((action (read-char-exclusive))
  9231. (org-log-refile (if org-log-refile 'time nil))
  9232. (entries (reverse org-agenda-bulk-marked-entries))
  9233. (org-overriding-default-time
  9234. (if (get-text-property (point) 'org-agenda-date-header)
  9235. (org-get-cursor-date)))
  9236. redo-at-end
  9237. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9238. (cond
  9239. ((equal action ?p)
  9240. (let ((org-agenda-persistent-marks
  9241. (not org-agenda-persistent-marks)))
  9242. (org-agenda-bulk-action)
  9243. (throw 'exit nil)))
  9244. ((equal action ?$)
  9245. (setq cmd '(org-agenda-archive)))
  9246. ((equal action ?A)
  9247. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9248. ((member action '(?r ?w))
  9249. (setq rfloc (org-refile-get-location
  9250. "Refile to"
  9251. (marker-buffer (car entries))
  9252. org-refile-allow-creating-parent-nodes))
  9253. (if (nth 3 rfloc)
  9254. (setcar (nthcdr 3 rfloc)
  9255. (move-marker (make-marker) (nth 3 rfloc)
  9256. (or (get-file-buffer (nth 1 rfloc))
  9257. (find-buffer-visiting (nth 1 rfloc))
  9258. (error "This should not happen")))))
  9259. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9260. redo-at-end t))
  9261. ((equal action ?t)
  9262. (setq state (completing-read
  9263. "Todo state: "
  9264. (with-current-buffer (marker-buffer (car entries))
  9265. (mapcar #'list org-todo-keywords-1))))
  9266. (setq cmd `(let ((org-inhibit-blocking t)
  9267. (org-inhibit-logging 'note))
  9268. (org-agenda-todo ,state))))
  9269. ((memq action '(?- ?+))
  9270. (setq tag (completing-read
  9271. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9272. (with-current-buffer (marker-buffer (car entries))
  9273. (delq nil
  9274. (mapcar (lambda (x) (and (stringp (car x)) x))
  9275. org-current-tag-alist)))))
  9276. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9277. ((memq action '(?s ?d))
  9278. (let* ((time
  9279. (unless arg
  9280. (org-read-date
  9281. nil nil nil
  9282. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9283. org-overriding-default-time)))
  9284. (c1 (if (eq action ?s) 'org-agenda-schedule
  9285. 'org-agenda-deadline)))
  9286. ;; Make sure to not prompt for a note when bulk
  9287. ;; rescheduling as Org cannot cope with simultaneous
  9288. ;; notes. Besides, it could be annoying depending on the
  9289. ;; number of items re-scheduled.
  9290. (setq cmd `(eval '(let ((org-log-reschedule
  9291. (and org-log-reschedule 'time))
  9292. (org-log-redeadline
  9293. (and org-log-redeadline 'time)))
  9294. (,c1 arg ,time))))))
  9295. ((equal action ?S)
  9296. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9297. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9298. (let ((days (read-number
  9299. (format "Scatter tasks across how many %sdays: "
  9300. (if arg "week" "")) 7)))
  9301. (setq cmd
  9302. `(let ((distance (1+ (random ,days))))
  9303. (if arg
  9304. (let ((dist distance)
  9305. (day-of-week
  9306. (calendar-day-of-week
  9307. (calendar-gregorian-from-absolute (org-today)))))
  9308. (dotimes (i (1+ dist))
  9309. (while (member day-of-week org-agenda-weekend-days)
  9310. (cl-incf distance)
  9311. (cl-incf day-of-week)
  9312. (when (= day-of-week 7)
  9313. (setq day-of-week 0)))
  9314. (cl-incf day-of-week)
  9315. (when (= day-of-week 7)
  9316. (setq day-of-week 0)))))
  9317. ;; silently fail when try to replan a sexp entry
  9318. (condition-case nil
  9319. (let* ((date (calendar-gregorian-from-absolute
  9320. (+ (org-today) distance)))
  9321. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9322. (nth 2 date))))
  9323. (org-agenda-schedule nil time))
  9324. (error nil)))))))
  9325. ((assoc action org-agenda-bulk-custom-functions)
  9326. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9327. redo-at-end t))
  9328. ((equal action ?f)
  9329. (setq cmd (list (intern
  9330. (completing-read "Function: "
  9331. obarray 'fboundp t nil nil)))))
  9332. (t (user-error "Invalid bulk action")))
  9333. ;; Sort the markers, to make sure that parents are handled before children
  9334. (setq entries (sort entries
  9335. (lambda (a b)
  9336. (cond
  9337. ((equal (marker-buffer a) (marker-buffer b))
  9338. (< (marker-position a) (marker-position b)))
  9339. (t
  9340. (string< (buffer-name (marker-buffer a))
  9341. (buffer-name (marker-buffer b))))))))
  9342. ;; Now loop over all markers and apply cmd
  9343. (while (setq e (pop entries))
  9344. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9345. (if (not pos)
  9346. (progn (message "Skipping removed entry at %s" e)
  9347. (setq cntskip (1+ cntskip)))
  9348. (goto-char pos)
  9349. (let (org-loop-over-headlines-in-active-region)
  9350. (eval cmd))
  9351. ;; `post-command-hook' is not run yet. We make sure any
  9352. ;; pending log note is processed.
  9353. (when (or (memq 'org-add-log-note (default-value 'post-command-hook))
  9354. (memq 'org-add-log-note post-command-hook))
  9355. (org-add-log-note))
  9356. (setq cnt (1+ cnt))))
  9357. (when redo-at-end (org-agenda-redo))
  9358. (unless org-agenda-persistent-marks
  9359. (org-agenda-bulk-unmark-all))
  9360. (message "Acted on %d entries%s%s"
  9361. cnt
  9362. (if (= cntskip 0)
  9363. ""
  9364. (format ", skipped %d (disappeared before their turn)"
  9365. cntskip))
  9366. (if (not org-agenda-persistent-marks)
  9367. "" " (kept marked)"))))))
  9368. (defun org-agenda-capture (&optional with-time)
  9369. "Call `org-capture' with the date at point.
  9370. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9371. current HH:MM time."
  9372. (interactive "P")
  9373. (if (not (eq major-mode 'org-agenda-mode))
  9374. (user-error "You cannot do this outside of agenda buffers")
  9375. (let ((org-overriding-default-time
  9376. (org-get-cursor-date (equal with-time 1))))
  9377. (call-interactively 'org-capture))))
  9378. ;;; Dragging agenda lines forward/backward
  9379. (defun org-agenda-reapply-filters ()
  9380. "Re-apply all agenda filters."
  9381. (mapcar
  9382. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  9383. `((,org-agenda-tag-filter tag)
  9384. (,org-agenda-category-filter category)
  9385. (,org-agenda-regexp-filter regexp)
  9386. (,org-agenda-effort-filter effort)
  9387. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9388. (,(get 'org-agenda-category-filter :preset-filter) category)
  9389. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  9390. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9391. (defun org-agenda-drag-line-forward (arg &optional backward)
  9392. "Drag an agenda line forward by ARG lines.
  9393. When the optional argument `backward' is non-nil, move backward."
  9394. (interactive "p")
  9395. (let ((inhibit-read-only t) lst line)
  9396. (if (or (not (get-text-property (point) 'txt))
  9397. (save-excursion
  9398. (dotimes (n arg)
  9399. (move-beginning-of-line (if backward 0 2))
  9400. (push (not (get-text-property (point) 'txt)) lst))
  9401. (delq nil lst)))
  9402. (message "Cannot move line forward")
  9403. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9404. (move-beginning-of-line 1)
  9405. (setq line (buffer-substring (point) end))
  9406. (delete-region (point) end)
  9407. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9408. (insert line)
  9409. (org-agenda-reapply-filters)
  9410. (org-agenda-mark-clocking-task)
  9411. (move-beginning-of-line 0)))))
  9412. (defun org-agenda-drag-line-backward (arg)
  9413. "Drag an agenda line backward by ARG lines."
  9414. (interactive "p")
  9415. (org-agenda-drag-line-forward arg t))
  9416. ;;; Flagging notes
  9417. (defun org-agenda-show-the-flagging-note ()
  9418. "Display the flagging note in the other window.
  9419. When called a second time in direct sequence, offer to remove the FLAGGING
  9420. tag and (if present) the flagging note."
  9421. (interactive)
  9422. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9423. (win (selected-window))
  9424. note heading newhead)
  9425. (unless hdmarker
  9426. (user-error "No linked entry at point"))
  9427. (if (and (eq this-command last-command)
  9428. (y-or-n-p "Unflag and remove any flagging note? "))
  9429. (progn
  9430. (org-agenda-remove-flag hdmarker)
  9431. (let ((win (get-buffer-window "*Flagging Note*")))
  9432. (and win (delete-window win)))
  9433. (message "Entry unflagged"))
  9434. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9435. (unless note
  9436. (user-error "No flagging note"))
  9437. (org-kill-new note)
  9438. (org-switch-to-buffer-other-window "*Flagging Note*")
  9439. (erase-buffer)
  9440. (insert note)
  9441. (goto-char (point-min))
  9442. (while (re-search-forward "\\\\n" nil t)
  9443. (replace-match "\n" t t))
  9444. (goto-char (point-min))
  9445. (select-window win)
  9446. (message "%s" (substitute-command-keys "Flagging note pushed to \
  9447. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  9448. tag and note")))))
  9449. (defun org-agenda-remove-flag (marker)
  9450. "Remove the FLAGGED tag and any flagging note in the entry."
  9451. (let (newhead)
  9452. (org-with-point-at marker
  9453. (org-toggle-tag "FLAGGED" 'off)
  9454. (org-entry-delete nil "THEFLAGGINGNOTE")
  9455. (setq newhead (org-get-heading)))
  9456. (org-agenda-change-all-lines newhead marker)
  9457. (message "Entry unflagged")))
  9458. (defun org-agenda-get-any-marker (&optional pos)
  9459. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9460. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9461. ;;; Appointment reminders
  9462. (defvar appt-time-msg-list) ; defined in appt.el
  9463. ;;;###autoload
  9464. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9465. "Activate appointments found in `org-agenda-files'.
  9466. With a `\\[universal-argument]' prefix, refresh the list of \
  9467. appointments.
  9468. If FILTER is t, interactively prompt the user for a regular
  9469. expression, and filter out entries that don't match it.
  9470. If FILTER is a string, use this string as a regular expression
  9471. for filtering entries out.
  9472. If FILTER is a function, filter out entries against which
  9473. calling the function returns nil. This function takes one
  9474. argument: an entry from `org-agenda-get-day-entries'.
  9475. FILTER can also be an alist with the car of each cell being
  9476. either `headline' or `category'. For example:
  9477. \\='((headline \"IMPORTANT\")
  9478. (category \"Work\"))
  9479. will only add headlines containing IMPORTANT or headlines
  9480. belonging to the \"Work\" category.
  9481. ARGS are symbols indicating what kind of entries to consider.
  9482. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9483. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9484. and :timestamp entries. See the docstring of `org-diary' for
  9485. details and examples.
  9486. If an entry has a APPT_WARNTIME property, its value will be used
  9487. to override `appt-message-warning-time'."
  9488. (interactive "P")
  9489. (if refresh (setq appt-time-msg-list nil))
  9490. (if (eq filter t)
  9491. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9492. (let* ((cnt 0) ; count added events
  9493. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9494. (org-agenda-new-buffers nil)
  9495. (org-deadline-warning-days 0)
  9496. ;; Do not use `org-today' here because appt only takes
  9497. ;; time and without date as argument, so it may pass wrong
  9498. ;; information otherwise
  9499. (today (org-date-to-gregorian
  9500. (time-to-days (current-time))))
  9501. (org-agenda-restrict nil)
  9502. (files (org-agenda-files 'unrestricted)) entries file
  9503. (org-agenda-buffer nil))
  9504. ;; Get all entries which may contain an appt
  9505. (org-agenda-prepare-buffers files)
  9506. (while (setq file (pop files))
  9507. (setq entries
  9508. (delq nil
  9509. (append entries
  9510. (apply 'org-agenda-get-day-entries
  9511. file today scope)))))
  9512. ;; Map thru entries and find if we should filter them out
  9513. (mapc
  9514. (lambda (x)
  9515. (let* ((evt (org-trim
  9516. (replace-regexp-in-string
  9517. org-bracket-link-regexp "\\3"
  9518. (or (get-text-property 1 'txt x) ""))))
  9519. (cat (get-text-property (1- (length x)) 'org-category x))
  9520. (tod (get-text-property 1 'time-of-day x))
  9521. (ok (or (null filter)
  9522. (and (stringp filter) (string-match filter evt))
  9523. (and (functionp filter) (funcall filter x))
  9524. (and (listp filter)
  9525. (let ((cat-filter (cadr (assq 'category filter)))
  9526. (evt-filter (cadr (assq 'headline filter))))
  9527. (or (and (stringp cat-filter)
  9528. (string-match cat-filter cat))
  9529. (and (stringp evt-filter)
  9530. (string-match evt-filter evt)))))))
  9531. (wrn (get-text-property 1 'warntime x)))
  9532. ;; FIXME: Shall we remove text-properties for the appt text?
  9533. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9534. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  9535. (setq tod (concat "00" (number-to-string tod)))
  9536. (setq tod (when (string-match
  9537. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9538. (concat (match-string 1 tod) ":"
  9539. (match-string 2 tod))))
  9540. (when (if (version< emacs-version "23.3")
  9541. (appt-add tod evt)
  9542. (appt-add tod evt wrn))
  9543. (setq cnt (1+ cnt))))))
  9544. entries)
  9545. (org-release-buffers org-agenda-new-buffers)
  9546. (if (eq cnt 0)
  9547. (message "No event to add")
  9548. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9549. (defun org-agenda-today-p (date)
  9550. "Non nil when DATE means today.
  9551. DATE is either a list of the form (month day year) or a number of
  9552. days as returned by `calendar-absolute-from-gregorian' or
  9553. `org-today'. This function considers `org-extend-today-until'
  9554. when defining today."
  9555. (eq (org-today)
  9556. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  9557. (defun org-agenda-todo-yesterday (&optional arg)
  9558. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9559. (interactive "P")
  9560. (let* ((org-use-effective-time t)
  9561. (hour (nth 2 (decode-time (org-current-time))))
  9562. (org-extend-today-until (1+ hour)))
  9563. (org-agenda-todo arg)))
  9564. (provide 'org-agenda)
  9565. ;;; org-agenda.el ends here