org-agenda.el 377 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 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-mode.
  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 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-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-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags do not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  661. "Time unit to use when possibly ignoring an agenda item.
  662. See the docstring of various `org-agenda-todo-ignore-*' options.
  663. The default is to compare time stamps using days. An item is thus
  664. considered to be in the future if it is at least one day after today.
  665. Non-nil means to compare time stamps using seconds. An item is then
  666. considered future if it has a time value later than current time."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-todo-list
  669. :type '(choice
  670. (const :tag "Compare time with days" nil)
  671. (const :tag "Compare time with seconds" t)))
  672. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  673. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  674. The variables
  675. `org-agenda-todo-ignore-with-date',
  676. `org-agenda-todo-ignore-timestamp',
  677. `org-agenda-todo-ignore-scheduled',
  678. `org-agenda-todo-ignore-deadlines'
  679. make the global TODO list skip entries that have time stamps of certain
  680. kinds. If this option is set, the same options will also apply for the
  681. tags-todo search, which is the general tags/property matcher
  682. restricted to unfinished TODO entries only."
  683. :group 'org-agenda-skip
  684. :group 'org-agenda-todo-list
  685. :group 'org-agenda-match-view
  686. :type 'boolean)
  687. (defcustom org-agenda-skip-scheduled-if-done nil
  688. "Non-nil means don't show scheduled items in agenda when they are done.
  689. This is relevant for the daily/weekly agenda, not for the TODO list. And
  690. it applies only to the actual date of the scheduling. Warnings about
  691. an item with a past scheduling dates are always turned off when the item
  692. is DONE."
  693. :group 'org-agenda-skip
  694. :group 'org-agenda-daily/weekly
  695. :type 'boolean)
  696. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  697. "Non-nil means skip scheduling line if same entry shows because of deadline.
  698. In the agenda of today, an entry can show up multiple times because
  699. it is both scheduled and has a nearby deadline, and maybe a plain time
  700. stamp as well.
  701. When this variable is t, then only the deadline is shown and the fact that
  702. the entry is scheduled today or was scheduled previously is not shown.
  703. When this variable is nil, the entry will be shown several times. When
  704. the variable is the symbol `not-today', then skip scheduled previously,
  705. but not scheduled today."
  706. :group 'org-agenda-skip
  707. :group 'org-agenda-daily/weekly
  708. :type '(choice
  709. (const :tag "Never" nil)
  710. (const :tag "Always" t)
  711. (const :tag "Not when scheduled today" not-today)))
  712. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  713. "Non-nil means skip timestamp line if same entry shows because of deadline.
  714. In the agenda of today, an entry can show up multiple times
  715. because it has both a plain timestamp and has a nearby deadline.
  716. When this variable is t, then only the deadline is shown and the
  717. fact that the entry has a timestamp for or including today is not
  718. shown. When this variable is nil, the entry will be shown
  719. several times."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :version "24.1"
  723. :type '(choice
  724. (const :tag "Never" nil)
  725. (const :tag "Always" t)))
  726. (defcustom org-agenda-skip-deadline-if-done nil
  727. "Non-nil means don't show deadlines when the corresponding item is done.
  728. When nil, the deadline is still shown and should give you a happy feeling.
  729. This is relevant for the daily/weekly agenda. And it applied only to the
  730. actually date of the deadline. Warnings about approaching and past-due
  731. deadlines are always turned off when the item is DONE."
  732. :group 'org-agenda-skip
  733. :group 'org-agenda-daily/weekly
  734. :type 'boolean)
  735. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  736. "Non-nil means skip deadline prewarning when entry is also scheduled.
  737. This will apply on all days where a prewarning for the deadline would
  738. be shown, but not at the day when the entry is actually due. On that day,
  739. the deadline will be shown anyway.
  740. This variable may be set to nil, t, the symbol `pre-scheduled',
  741. or a number which will then give the number of days before the actual
  742. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  743. eliminates the deadline prewarning only prior to the scheduled date.
  744. This can be used in a workflow where the first showing of the deadline will
  745. trigger you to schedule it, and then you don't want to be reminded of it
  746. because you will take care of it on the day when scheduled."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-daily/weekly
  749. :version "24.1"
  750. :type '(choice
  751. (const :tag "Always show prewarning" nil)
  752. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  753. (const :tag "Remove prewarning if entry is scheduled" t)
  754. (integer :tag "Restart prewarning N days before deadline")))
  755. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  756. "Non-nil means skip scheduled delay when entry also has a deadline.
  757. This variable may be set to nil, t, the symbol `post-deadline',
  758. or a number which will then give the number of days after the actual
  759. scheduled date when the delay should expire. The symbol `post-deadline'
  760. eliminates the schedule delay when the date is posterior to the deadline."
  761. :group 'org-agenda-skip
  762. :group 'org-agenda-daily/weekly
  763. :version "24.4"
  764. :package-version '(Org . "8.0")
  765. :type '(choice
  766. (const :tag "Always honor delay" nil)
  767. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  768. (const :tag "Ignore delay if entry has a deadline" t)
  769. (integer :tag "Honor delay up until N days after the scheduled date")))
  770. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  771. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  772. When non-nil, after the search for timestamps has matched once in an
  773. entry, the rest of the entry will not be searched."
  774. :group 'org-agenda-skip
  775. :type 'boolean)
  776. (defcustom org-agenda-skip-timestamp-if-done nil
  777. "Non-nil means don't select item by timestamp or -range if it is DONE."
  778. :group 'org-agenda-skip
  779. :group 'org-agenda-daily/weekly
  780. :type 'boolean)
  781. (defcustom org-agenda-dim-blocked-tasks nil
  782. "Non-nil means dim blocked tasks in the agenda display.
  783. This causes some overhead during agenda construction, but if you
  784. have turned on `org-enforce-todo-dependencies',
  785. `org-enforce-todo-checkbox-dependencies', or any other blocking
  786. mechanism, this will create useful feedback in the agenda.
  787. Instead of t, this variable can also have the value `invisible'.
  788. Then blocked tasks will be invisible and only become visible when
  789. they become unblocked. An exemption to this behavior is when a task is
  790. blocked because of unchecked checkboxes below it. Since checkboxes do
  791. not show up in the agenda views, making this task invisible you remove any
  792. trace from agenda views that there is something to do. Therefore, a task
  793. that is blocked because of checkboxes will never be made invisible, it
  794. will only be dimmed."
  795. :group 'org-agenda-daily/weekly
  796. :group 'org-agenda-todo-list
  797. :version "24.3"
  798. :type '(choice
  799. (const :tag "Do not dim" nil)
  800. (const :tag "Dim to a gray face" t)
  801. (const :tag "Make invisible" invisible)))
  802. (defcustom org-timeline-show-empty-dates 3
  803. "Non-nil means `org-timeline' also shows dates without an entry.
  804. When nil, only the days which actually have entries are shown.
  805. When t, all days between the first and the last date are shown.
  806. When an integer, show also empty dates, but if there is a gap of more than
  807. N days, just insert a special line indicating the size of the gap."
  808. :group 'org-agenda-skip
  809. :type '(choice
  810. (const :tag "None" nil)
  811. (const :tag "All" t)
  812. (integer :tag "at most")))
  813. (defgroup org-agenda-startup nil
  814. "Options concerning initial settings in the Agenda in Org Mode."
  815. :tag "Org Agenda Startup"
  816. :group 'org-agenda)
  817. (defcustom org-agenda-menu-show-matcher t
  818. "Non-nil means show the match string in the agenda dispatcher menu.
  819. When nil, the matcher string is not shown, but is put into the help-echo
  820. property so than moving the mouse over the command shows it.
  821. Setting it to nil is good if matcher strings are very long and/or if
  822. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  823. :group 'org-agenda
  824. :version "24.1"
  825. :type 'boolean)
  826. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  827. (defcustom org-agenda-menu-two-columns nil
  828. "Non-nil means, use two columns to show custom commands in the dispatcher.
  829. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  830. to nil."
  831. :group 'org-agenda
  832. :version "24.1"
  833. :type 'boolean)
  834. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  835. (defcustom org-agenda-finalize-hook nil
  836. "Hook run just before displaying an agenda buffer.
  837. The buffer is still writable when the hook is called.
  838. You can modify some of the buffer substrings but you should be
  839. extra careful not to modify the text properties of the agenda
  840. headlines as the agenda display heavily relies on them."
  841. :group 'org-agenda-startup
  842. :type 'hook)
  843. (defcustom org-agenda-mouse-1-follows-link nil
  844. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  845. A longer mouse click will still set point. Does not work on XEmacs.
  846. Needs to be set before org.el is loaded."
  847. :group 'org-agenda-startup
  848. :type 'boolean)
  849. (defcustom org-agenda-start-with-follow-mode nil
  850. "The initial value of follow mode in a newly created agenda window."
  851. :group 'org-agenda-startup
  852. :type 'boolean)
  853. (defcustom org-agenda-follow-indirect nil
  854. "Non-nil means `org-agenda-follow-mode' displays only the
  855. current item's tree, in an indirect buffer."
  856. :group 'org-agenda
  857. :version "24.1"
  858. :type 'boolean)
  859. (defcustom org-agenda-show-outline-path t
  860. "Non-nil means show outline path in echo area after line motion."
  861. :group 'org-agenda-startup
  862. :type 'boolean)
  863. (defcustom org-agenda-start-with-entry-text-mode nil
  864. "The initial value of entry-text-mode in a newly created agenda window."
  865. :group 'org-agenda-startup
  866. :type 'boolean)
  867. (defcustom org-agenda-entry-text-maxlines 5
  868. "Number of text lines to be added when `E' is pressed in the agenda.
  869. Note that this variable only used during agenda display. Add add entry text
  870. when exporting the agenda, configure the variable
  871. `org-agenda-add-entry-ext-maxlines'."
  872. :group 'org-agenda
  873. :type 'integer)
  874. (defcustom org-agenda-entry-text-exclude-regexps nil
  875. "List of regular expressions to clean up entry text.
  876. The complete matches of all regular expressions in this list will be
  877. removed from entry text before it is shown in the agenda."
  878. :group 'org-agenda
  879. :type '(repeat (regexp)))
  880. (defvar org-agenda-entry-text-cleanup-hook nil
  881. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  882. This cleanup is done in a temporary buffer, so the function may inspect and
  883. change the entire buffer.
  884. Some default stuff like drawers and scheduling/deadline dates will already
  885. have been removed when this is called, as will any matches for regular
  886. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  887. (defvar org-agenda-include-inactive-timestamps nil
  888. "Non-nil means include inactive time stamps in agenda and timeline.
  889. Dynamically scoped.")
  890. (defgroup org-agenda-windows nil
  891. "Options concerning the windows used by the Agenda in Org Mode."
  892. :tag "Org Agenda Windows"
  893. :group 'org-agenda)
  894. (defcustom org-agenda-window-setup 'reorganize-frame
  895. "How the agenda buffer should be displayed.
  896. Possible values for this option are:
  897. current-window Show agenda in the current window, keeping all other windows.
  898. other-window Use `switch-to-buffer-other-window' to display agenda.
  899. reorganize-frame Show only two windows on the current frame, the current
  900. window and the agenda.
  901. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  902. Also, when exiting the agenda, kill that frame.
  903. See also the variable `org-agenda-restore-windows-after-quit'."
  904. :group 'org-agenda-windows
  905. :type '(choice
  906. (const current-window)
  907. (const other-frame)
  908. (const other-window)
  909. (const reorganize-frame)))
  910. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  911. "The min and max height of the agenda window as a fraction of frame height.
  912. The value of the variable is a cons cell with two numbers between 0 and 1.
  913. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  914. :group 'org-agenda-windows
  915. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  916. (defcustom org-agenda-restore-windows-after-quit nil
  917. "Non-nil means restore window configuration upon exiting agenda.
  918. Before the window configuration is changed for displaying the agenda,
  919. the current status is recorded. When the agenda is exited with
  920. `q' or `x' and this option is set, the old state is restored. If
  921. `org-agenda-window-setup' is `other-frame', the value of this
  922. option will be ignored."
  923. :group 'org-agenda-windows
  924. :type 'boolean)
  925. (defcustom org-agenda-ndays nil
  926. "Number of days to include in overview display.
  927. Should be 1 or 7.
  928. Obsolete, see `org-agenda-span'."
  929. :group 'org-agenda-daily/weekly
  930. :type 'integer)
  931. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  932. (defcustom org-agenda-span 'week
  933. "Number of days to include in overview display.
  934. Can be day, week, month, year, or any number of days.
  935. Custom commands can set this variable in the options section."
  936. :group 'org-agenda-daily/weekly
  937. :type '(choice (const :tag "Day" day)
  938. (const :tag "Week" week)
  939. (const :tag "Month" month)
  940. (const :tag "Year" year)
  941. (integer :tag "Custom")))
  942. (defcustom org-agenda-start-on-weekday 1
  943. "Non-nil means start the overview always on the specified weekday.
  944. 0 denotes Sunday, 1 denotes Monday etc.
  945. When nil, always start on the current day.
  946. Custom commands can set this variable in the options section."
  947. :group 'org-agenda-daily/weekly
  948. :type '(choice (const :tag "Today" nil)
  949. (integer :tag "Weekday No.")))
  950. (defcustom org-agenda-show-all-dates t
  951. "Non-nil means `org-agenda' shows every day in the selected range.
  952. When nil, only the days which actually have entries are shown."
  953. :group 'org-agenda-daily/weekly
  954. :type 'boolean)
  955. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  956. "Format string for displaying dates in the agenda.
  957. Used by the daily/weekly agenda and by the timeline. This should be
  958. a format string understood by `format-time-string', or a function returning
  959. the formatted date as a string. The function must take a single argument,
  960. a calendar-style date list like (month day year)."
  961. :group 'org-agenda-daily/weekly
  962. :type '(choice
  963. (string :tag "Format string")
  964. (function :tag "Function")))
  965. (defun org-agenda-format-date-aligned (date)
  966. "Format a date string for display in the daily/weekly agenda, or timeline.
  967. This function makes sure that dates are aligned for easy reading."
  968. (require 'cal-iso)
  969. (let* ((dayname (calendar-day-name date))
  970. (day (cadr date))
  971. (day-of-week (calendar-day-of-week date))
  972. (month (car date))
  973. (monthname (calendar-month-name month))
  974. (year (nth 2 date))
  975. (iso-week (org-days-to-iso-week
  976. (calendar-absolute-from-gregorian date)))
  977. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  978. (1- year))
  979. ((and (= month 12) (<= iso-week 1))
  980. (1+ year))
  981. (t year)))
  982. (weekstring (if (= day-of-week 1)
  983. (format " W%02d" iso-week)
  984. "")))
  985. (format "%-10s %2d %s %4d%s"
  986. dayname day monthname year weekstring)))
  987. (defcustom org-agenda-time-leading-zero nil
  988. "Non-nil means use leading zero for military times in agenda.
  989. For example, 9:30am would become 09:30 rather than 9:30."
  990. :group 'org-agenda-daily/weekly
  991. :version "24.1"
  992. :type 'boolean)
  993. (defcustom org-agenda-timegrid-use-ampm nil
  994. "When set, show AM/PM style timestamps on the timegrid."
  995. :group 'org-agenda
  996. :version "24.1"
  997. :type 'boolean)
  998. (defun org-agenda-time-of-day-to-ampm (time)
  999. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1000. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1001. (minute (substring time -2))
  1002. (ampm "am"))
  1003. (cond
  1004. ((equal hour-number 12)
  1005. (setq ampm "pm"))
  1006. ((> hour-number 12)
  1007. (setq ampm "pm")
  1008. (setq hour-number (- hour-number 12))))
  1009. (concat
  1010. (if org-agenda-time-leading-zero
  1011. (format "%02d" hour-number)
  1012. (format "%02s" (number-to-string hour-number)))
  1013. ":" minute ampm)))
  1014. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1015. "Conditionally convert TIME to AM/PM format
  1016. based on `org-agenda-timegrid-use-ampm'"
  1017. (if org-agenda-timegrid-use-ampm
  1018. (org-agenda-time-of-day-to-ampm time)
  1019. time))
  1020. (defcustom org-agenda-weekend-days '(6 0)
  1021. "Which days are weekend?
  1022. These days get the special face `org-agenda-date-weekend' in the agenda
  1023. and timeline buffers."
  1024. :group 'org-agenda-daily/weekly
  1025. :type '(set :greedy t
  1026. (const :tag "Monday" 1)
  1027. (const :tag "Tuesday" 2)
  1028. (const :tag "Wednesday" 3)
  1029. (const :tag "Thursday" 4)
  1030. (const :tag "Friday" 5)
  1031. (const :tag "Saturday" 6)
  1032. (const :tag "Sunday" 0)))
  1033. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1034. "Non-nil means jump to today when moving a past date forward in time.
  1035. When using S-right in the agenda to move a a date forward, and the date
  1036. stamp currently points to the past, the first key press will move it
  1037. to today. WHen nil, just move one day forward even if the date stays
  1038. in the past."
  1039. :group 'org-agenda-daily/weekly
  1040. :version "24.1"
  1041. :type 'boolean)
  1042. (defcustom org-agenda-include-diary nil
  1043. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1044. Custom commands can set this variable in the options section."
  1045. :group 'org-agenda-daily/weekly
  1046. :type 'boolean)
  1047. (defcustom org-agenda-include-deadlines t
  1048. "If non-nil, include entries within their deadline warning period.
  1049. Custom commands can set this variable in the options section."
  1050. :group 'org-agenda-daily/weekly
  1051. :version "24.1"
  1052. :type 'boolean)
  1053. (defcustom org-agenda-repeating-timestamp-show-all t
  1054. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1055. When set to a list of strings, only show occurrences of repeating
  1056. stamps for these TODO keywords. When nil, only one occurrence is
  1057. shown, either today or the nearest into the future."
  1058. :group 'org-agenda-daily/weekly
  1059. :type '(choice
  1060. (const :tag "Show repeating stamps" t)
  1061. (repeat :tag "Show repeating stamps for these TODO keywords"
  1062. (string :tag "TODO Keyword"))
  1063. (const :tag "Don't show repeating stamps" nil)))
  1064. (defcustom org-scheduled-past-days 10000
  1065. "No. of days to continue listing scheduled items that are not marked DONE.
  1066. When an item is scheduled on a date, it shows up in the agenda on this
  1067. day and will be listed until it is marked done for the number of days
  1068. given here."
  1069. :group 'org-agenda-daily/weekly
  1070. :type 'integer)
  1071. (defcustom org-agenda-log-mode-items '(closed clock)
  1072. "List of items that should be shown in agenda log mode.
  1073. This list may contain the following symbols:
  1074. closed Show entries that have been closed on that day.
  1075. clock Show entries that have received clocked time on that day.
  1076. state Show all logged state changes.
  1077. Note that instead of changing this variable, you can also press `C-u l' in
  1078. the agenda to display all available LOG items temporarily."
  1079. :group 'org-agenda-daily/weekly
  1080. :type '(set :greedy t (const closed) (const clock) (const state)))
  1081. (defcustom org-agenda-clock-consistency-checks
  1082. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1083. :gap-ok-around ("4:00")
  1084. :default-face ((:background "DarkRed") (:foreground "white"))
  1085. :overlap-face nil :gap-face nil :no-end-time-face nil
  1086. :long-face nil :short-face nil)
  1087. "This is a property list, with the following keys:
  1088. :max-duration Mark clocking chunks that are longer than this time.
  1089. This is a time string like \"HH:MM\", or the number
  1090. of minutes as an integer.
  1091. :min-duration Mark clocking chunks that are shorter that this.
  1092. This is a time string like \"HH:MM\", or the number
  1093. of minutes as an integer.
  1094. :max-gap Mark gaps between clocking chunks that are longer than
  1095. this duration. A number of minutes, or a string
  1096. like \"HH:MM\".
  1097. :gap-ok-around List of times during the day which are usually not working
  1098. times. When a gap is detected, but the gap contains any
  1099. of these times, the gap is *not* reported. For example,
  1100. if this is (\"4:00\" \"13:00\") then gaps that contain
  1101. 4:00 in the morning (i.e. the night) and 13:00
  1102. (i.e. a typical lunch time) do not cause a warning.
  1103. You should have at least one time during the night in this
  1104. list, or otherwise the first task each morning will trigger
  1105. a warning because it follows a long gap.
  1106. Furthermore, the following properties can be used to define faces for
  1107. issue display.
  1108. :default-face the default face, if the specific face is undefined
  1109. :overlap-face face for overlapping clocks
  1110. :gap-face face for gaps between clocks
  1111. :no-end-time-face face for incomplete clocks
  1112. :long-face face for clock intervals that are too long
  1113. :short-face face for clock intervals that are too short"
  1114. :group 'org-agenda-daily/weekly
  1115. :group 'org-clock
  1116. :version "24.1"
  1117. :type 'plist)
  1118. (defcustom org-agenda-log-mode-add-notes t
  1119. "Non-nil means add first line of notes to log entries in agenda views.
  1120. If a log item like a state change or a clock entry is associated with
  1121. notes, the first line of these notes will be added to the entry in the
  1122. agenda display."
  1123. :group 'org-agenda-daily/weekly
  1124. :type 'boolean)
  1125. (defcustom org-agenda-start-with-log-mode nil
  1126. "The initial value of log-mode in a newly created agenda window.
  1127. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1128. explanations on the possible values."
  1129. :group 'org-agenda-startup
  1130. :group 'org-agenda-daily/weekly
  1131. :type '(choice (const :tag "Don't show log items" nil)
  1132. (const :tag "Show only log items" 'only)
  1133. (const :tag "Show all possible log items" 'clockcheck)
  1134. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1135. (choice (const :tag "Show closed log items" 'closed)
  1136. (const :tag "Show clocked log items" 'clock)
  1137. (const :tag "Show all logged state changes" 'state)))))
  1138. (defcustom org-agenda-start-with-clockreport-mode nil
  1139. "The initial value of clockreport-mode in a newly created agenda window."
  1140. :group 'org-agenda-startup
  1141. :group 'org-agenda-daily/weekly
  1142. :type 'boolean)
  1143. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1144. "Property list with parameters for the clocktable in clockreport mode.
  1145. This is the display mode that shows a clock table in the daily/weekly
  1146. agenda, the properties for this dynamic block can be set here.
  1147. The usual clocktable parameters are allowed here, but you cannot set
  1148. the properties :name, :tstart, :tend, :block, and :scope - these will
  1149. be overwritten to make sure the content accurately reflects the
  1150. current display in the agenda."
  1151. :group 'org-agenda-daily/weekly
  1152. :type 'plist)
  1153. (defcustom org-agenda-search-view-always-boolean nil
  1154. "Non-nil means the search string is interpreted as individual parts.
  1155. The search string for search view can either be interpreted as a phrase,
  1156. or as a list of snippets that define a boolean search for a number of
  1157. strings.
  1158. When this is non-nil, the string will be split on whitespace, and each
  1159. snippet will be searched individually, and all must match in order to
  1160. select an entry. A snippet is then a single string of non-white
  1161. characters, or a string in double quotes, or a regexp in {} braces.
  1162. If a snippet is preceded by \"-\", the snippet must *not* match.
  1163. \"+\" is syntactic sugar for positive selection. Each snippet may
  1164. be found as a full word or a partial word, but see the variable
  1165. `org-agenda-search-view-force-full-words'.
  1166. When this is nil, search will look for the entire search phrase as one,
  1167. with each space character matching any amount of whitespace, including
  1168. line breaks.
  1169. Even when this is nil, you can still switch to Boolean search dynamically
  1170. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1171. is a regexp marked with braces like \"{abc}\", this will also switch to
  1172. boolean search."
  1173. :group 'org-agenda-search-view
  1174. :version "24.1"
  1175. :type 'boolean)
  1176. (if (fboundp 'defvaralias)
  1177. (defvaralias 'org-agenda-search-view-search-words-only
  1178. 'org-agenda-search-view-always-boolean))
  1179. (defcustom org-agenda-search-view-force-full-words nil
  1180. "Non-nil means, search words must be matches as complete words.
  1181. When nil, they may also match part of a word."
  1182. :group 'org-agenda-search-view
  1183. :version "24.1"
  1184. :type 'boolean)
  1185. (defcustom org-agenda-search-view-max-outline-level nil
  1186. "Maximum outline level to display in search view.
  1187. E.g. when this is set to 1, the search view will only
  1188. show headlines of level 1."
  1189. :group 'org-agenda-search-view
  1190. :version "24.4"
  1191. :package-version '(Org . "8.0")
  1192. :type 'integer)
  1193. (defgroup org-agenda-time-grid nil
  1194. "Options concerning the time grid in the Org-mode Agenda."
  1195. :tag "Org Agenda Time Grid"
  1196. :group 'org-agenda)
  1197. (defcustom org-agenda-search-headline-for-time t
  1198. "Non-nil means search headline for a time-of-day.
  1199. If the headline contains a time-of-day in one format or another, it will
  1200. be used to sort the entry into the time sequence of items for a day.
  1201. Some people have time stamps in the headline that refer to the creation
  1202. time or so, and then this produces an unwanted side effect. If this is
  1203. the case for your, use this variable to turn off searching the headline
  1204. for a time."
  1205. :group 'org-agenda-time-grid
  1206. :type 'boolean)
  1207. (defcustom org-agenda-use-time-grid t
  1208. "Non-nil means show a time grid in the agenda schedule.
  1209. A time grid is a set of lines for specific times (like every two hours between
  1210. 8:00 and 20:00). The items scheduled for a day at specific times are
  1211. sorted in between these lines.
  1212. For details about when the grid will be shown, and what it will look like, see
  1213. the variable `org-agenda-time-grid'."
  1214. :group 'org-agenda-time-grid
  1215. :type 'boolean)
  1216. (defcustom org-agenda-time-grid
  1217. '((daily today require-timed)
  1218. "----------------"
  1219. (800 1000 1200 1400 1600 1800 2000))
  1220. "The settings for time grid for agenda display.
  1221. This is a list of three items. The first item is again a list. It contains
  1222. symbols specifying conditions when the grid should be displayed:
  1223. daily if the agenda shows a single day
  1224. weekly if the agenda shows an entire week
  1225. today show grid on current date, independent of daily/weekly display
  1226. require-timed show grid only if at least one item has a time specification
  1227. The second item is a string which will be placed behind the grid time.
  1228. The third item is a list of integers, indicating the times that should have
  1229. a grid line."
  1230. :group 'org-agenda-time-grid
  1231. :type
  1232. '(list
  1233. (set :greedy t :tag "Grid Display Options"
  1234. (const :tag "Show grid in single day agenda display" daily)
  1235. (const :tag "Show grid in weekly agenda display" weekly)
  1236. (const :tag "Always show grid for today" today)
  1237. (const :tag "Show grid only if any timed entries are present"
  1238. require-timed)
  1239. (const :tag "Skip grid times already present in an entry"
  1240. remove-match))
  1241. (string :tag "Grid String")
  1242. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1243. (defcustom org-agenda-show-current-time-in-grid t
  1244. "Non-nil means show the current time in the time grid."
  1245. :group 'org-agenda-time-grid
  1246. :version "24.1"
  1247. :type 'boolean)
  1248. (defcustom org-agenda-current-time-string
  1249. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1250. "The string for the current time marker in the agenda."
  1251. :group 'org-agenda-time-grid
  1252. :version "24.1"
  1253. :type 'string)
  1254. (defgroup org-agenda-sorting nil
  1255. "Options concerning sorting in the Org-mode Agenda."
  1256. :tag "Org Agenda Sorting"
  1257. :group 'org-agenda)
  1258. (defcustom org-agenda-sorting-strategy
  1259. '((agenda habit-down time-up priority-down category-keep)
  1260. (todo priority-down category-keep)
  1261. (tags priority-down category-keep)
  1262. (search category-keep))
  1263. "Sorting structure for the agenda items of a single day.
  1264. This is a list of symbols which will be used in sequence to determine
  1265. if an entry should be listed before another entry. The following
  1266. symbols are recognized:
  1267. time-up Put entries with time-of-day indications first, early first
  1268. time-down Put entries with time-of-day indications first, late first
  1269. timestamp-up Sort by any timestamp, early first
  1270. timestamp-down Sort by any timestamp, late first
  1271. scheduled-up Sort by scheduled timestamp, early first
  1272. scheduled-down Sort by scheduled timestamp, late first
  1273. deadline-up Sort by deadline timestamp, early first
  1274. deadline-down Sort by deadline timestamp, late first
  1275. ts-up Sort by active timestamp, early first
  1276. ts-down Sort by active timestamp, late first
  1277. tsia-up Sort by inactive timestamp, early first
  1278. tsia-down Sort by inactive timestamp, late first
  1279. category-keep Keep the default order of categories, corresponding to the
  1280. sequence in `org-agenda-files'.
  1281. category-up Sort alphabetically by category, A-Z.
  1282. category-down Sort alphabetically by category, Z-A.
  1283. tag-up Sort alphabetically by last tag, A-Z.
  1284. tag-down Sort alphabetically by last tag, Z-A.
  1285. priority-up Sort numerically by priority, high priority last.
  1286. priority-down Sort numerically by priority, high priority first.
  1287. todo-state-up Sort by todo state, tasks that are done last.
  1288. todo-state-down Sort by todo state, tasks that are done first.
  1289. effort-up Sort numerically by estimated effort, high effort last.
  1290. effort-down Sort numerically by estimated effort, high effort first.
  1291. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1292. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1293. habit-up Put entries that are habits first
  1294. habit-down Put entries that are habits last
  1295. alpha-up Sort headlines alphabetically
  1296. alpha-down Sort headlines alphabetically, reversed
  1297. The different possibilities will be tried in sequence, and testing stops
  1298. if one comparison returns a \"not-equal\". For example, the default
  1299. '(time-up category-keep priority-down)
  1300. means: Pull out all entries having a specified time of day and sort them,
  1301. in order to make a time schedule for the current day the first thing in the
  1302. agenda listing for the day. Of the entries without a time indication, keep
  1303. the grouped in categories, don't sort the categories, but keep them in
  1304. the sequence given in `org-agenda-files'. Within each category sort by
  1305. priority.
  1306. Leaving out `category-keep' would mean that items will be sorted across
  1307. categories by priority.
  1308. Instead of a single list, this can also be a set of list for specific
  1309. contents, with a context symbol in the car of the list, any of
  1310. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1311. Custom commands can bind this variable in the options section."
  1312. :group 'org-agenda-sorting
  1313. :type `(choice
  1314. (repeat :tag "General" ,org-sorting-choice)
  1315. (list :tag "Individually"
  1316. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1317. (repeat ,org-sorting-choice))
  1318. (cons (const :tag "Strategy for TODO lists" todo)
  1319. (repeat ,org-sorting-choice))
  1320. (cons (const :tag "Strategy for Tags matches" tags)
  1321. (repeat ,org-sorting-choice))
  1322. (cons (const :tag "Strategy for search matches" search)
  1323. (repeat ,org-sorting-choice)))))
  1324. (defcustom org-agenda-cmp-user-defined nil
  1325. "A function to define the comparison `user-defined'.
  1326. This function must receive two arguments, agenda entry a and b.
  1327. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1328. the user comparison, return nil.
  1329. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1330. part of an agenda sorting strategy."
  1331. :group 'org-agenda-sorting
  1332. :type 'symbol)
  1333. (defcustom org-sort-agenda-notime-is-late t
  1334. "Non-nil means items without time are considered late.
  1335. This is only relevant for sorting. When t, items which have no explicit
  1336. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1337. do have a time. When nil, the default time is before 0:00. You can use this
  1338. option to decide if the schedule for today should come before or after timeless
  1339. agenda entries."
  1340. :group 'org-agenda-sorting
  1341. :type 'boolean)
  1342. (defcustom org-sort-agenda-noeffort-is-high t
  1343. "Non-nil means items without effort estimate are sorted as high effort.
  1344. This also applies when filtering an agenda view with respect to the
  1345. < or > effort operator. Then, tasks with no effort defined will be treated
  1346. as tasks with high effort.
  1347. When nil, such items are sorted as 0 minutes effort."
  1348. :group 'org-agenda-sorting
  1349. :type 'boolean)
  1350. (defgroup org-agenda-line-format nil
  1351. "Options concerning the entry prefix in the Org-mode agenda display."
  1352. :tag "Org Agenda Line Format"
  1353. :group 'org-agenda)
  1354. (defcustom org-agenda-prefix-format
  1355. '((agenda . " %i %-12:c%?-12t% s")
  1356. (timeline . " % s")
  1357. (todo . " %i %-12:c")
  1358. (tags . " %i %-12:c")
  1359. (search . " %i %-12:c"))
  1360. "Format specifications for the prefix of items in the agenda views.
  1361. An alist with five entries, each for the different agenda types. The
  1362. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1363. The values are format strings.
  1364. This format works similar to a printf format, with the following meaning:
  1365. %c the category of the item, \"Diary\" for entries from the diary,
  1366. or as given by the CATEGORY keyword or derived from the file name
  1367. %e the effort required by the item
  1368. %l the level of the item (insert X space(s) if item is of level X)
  1369. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1370. %T the last tag of the item (ignore inherited tags, which come first)
  1371. %t the HH:MM time-of-day specification if one applies to the entry
  1372. %s Scheduling/Deadline information, a short string
  1373. %b show breadcrumbs, i.e., the names of the higher levels
  1374. %(expression) Eval EXPRESSION and replace the control string
  1375. by the result
  1376. All specifiers work basically like the standard `%s' of printf, but may
  1377. contain two additional characters: a question mark just after the `%'
  1378. and a whitespace/punctuation character just before the final letter.
  1379. If the first character after `%' is a question mark, the entire field
  1380. will only be included if the corresponding value applies to the current
  1381. entry. This is useful for fields which should have fixed width when
  1382. present, but zero width when absent. For example, \"%?-12t\" will
  1383. result in a 12 character time field if a time of the day is specified,
  1384. but will completely disappear in entries which do not contain a time.
  1385. If there is punctuation or whitespace character just before the
  1386. final format letter, this character will be appended to the field
  1387. value if the value is not empty. For example, the format
  1388. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1389. the category is empty, no additional colon is inserted.
  1390. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1391. which means:
  1392. - Indent the line with two space characters
  1393. - Give the category a 12 chars wide field, padded with whitespace on
  1394. the right (because of `-'). Append a colon if there is a category
  1395. (because of `:').
  1396. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1397. time, don't put in an empty field, just skip it (because of '?').
  1398. - Finally, put the scheduling information.
  1399. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1400. `org-agenda-remove-tags'.
  1401. Custom commands can set this variable in the options section."
  1402. :type '(choice
  1403. (string :tag "General format")
  1404. (list :greedy t :tag "View dependent"
  1405. (cons (const agenda) (string :tag "Format"))
  1406. (cons (const timeline) (string :tag "Format"))
  1407. (cons (const todo) (string :tag "Format"))
  1408. (cons (const tags) (string :tag "Format"))
  1409. (cons (const search) (string :tag "Format"))))
  1410. :group 'org-agenda-line-format)
  1411. (defvar org-prefix-format-compiled nil
  1412. "The compiled prefix format and associated variables.
  1413. This is a list where first element is a list of variable bindings, and second
  1414. element is the compiled format expression. See the variable
  1415. `org-agenda-prefix-format'.")
  1416. (defcustom org-agenda-todo-keyword-format "%-1s"
  1417. "Format for the TODO keyword in agenda lines.
  1418. Set this to something like \"%-12s\" if you want all TODO keywords
  1419. to occupy a fixed space in the agenda display."
  1420. :group 'org-agenda-line-format
  1421. :type 'string)
  1422. (defcustom org-agenda-diary-sexp-prefix nil
  1423. "A regexp that matches part of a diary sexp entry
  1424. which should be treated as scheduling/deadline information in
  1425. `org-agenda'.
  1426. For example, you can use this to extract the `diary-remind-message' from
  1427. `diary-remind' entries."
  1428. :group 'org-agenda-line-format
  1429. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1430. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1431. "Text preceding timerange entries in the agenda view.
  1432. This is a list with two strings. The first applies when the range
  1433. is entirely on one day. The second applies if the range spans several days.
  1434. The strings may have two \"%d\" format specifiers which will be filled
  1435. with the sequence number of the days, and the total number of days in the
  1436. range, respectively."
  1437. :group 'org-agenda-line-format
  1438. :type '(list
  1439. (string :tag "Deadline today ")
  1440. (choice :tag "Deadline relative"
  1441. (string :tag "Format string")
  1442. (function))))
  1443. (defcustom org-agenda-scheduled-leaders '(" Scheduled: " "Sched.%3dx: ")
  1444. "Text preceding scheduled items in the agenda view.
  1445. This is a list with two strings. The first applies when the item is
  1446. scheduled on the current day. The second applies when it has been scheduled
  1447. previously, it may contain a %d indicating that this is the nth time that
  1448. this item is scheduled, due to automatic rescheduling of unfinished items
  1449. for the following day. So this number is one larger than the number of days
  1450. that passed since this item was scheduled first."
  1451. :group 'org-agenda-line-format
  1452. :version "24.4"
  1453. :package-version '(Org . "8.0")
  1454. :type '(list
  1455. (string :tag "Scheduled today ")
  1456. (string :tag "Scheduled previously")))
  1457. (defcustom org-agenda-inactive-leader "["
  1458. "Text preceding item pulled into the agenda by inactive time stamps.
  1459. These entries are added to the agenda when pressing \"[\"."
  1460. :group 'org-agenda-line-format
  1461. :version "24.1"
  1462. :type '(list
  1463. (string :tag "Scheduled today ")
  1464. (string :tag "Scheduled previously")))
  1465. (defcustom org-agenda-deadline-leaders '(" Deadline: " " In %3d d.: " "%3d d. ago: ")
  1466. "Text preceding deadline items in the agenda view.
  1467. This is a list with three strings. The first applies when the item has its
  1468. deadline on the current day. The second applies when the deadline is in the
  1469. future, the third one when it is in the past. The strings may contain %d
  1470. to capture the number of days."
  1471. :group 'org-agenda-line-format
  1472. :version "24.4"
  1473. :package-version '(Org . "8.0")
  1474. :type '(list
  1475. (string :tag "Deadline today ")
  1476. (choice :tag "Deadline relative"
  1477. (string :tag "Format string")
  1478. (function))))
  1479. (defcustom org-agenda-remove-times-when-in-prefix t
  1480. "Non-nil means remove duplicate time specifications in agenda items.
  1481. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1482. time-of-day specification in a headline or diary entry is extracted and
  1483. placed into the prefix. If this option is non-nil, the original specification
  1484. \(a timestamp or -range, or just a plain time(range) specification like
  1485. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1486. cluttered.
  1487. The option can be t or nil. It may also be the symbol `beg', indicating
  1488. that the time should only be removed when it is located at the beginning of
  1489. the headline/diary entry."
  1490. :group 'org-agenda-line-format
  1491. :type '(choice
  1492. (const :tag "Always" t)
  1493. (const :tag "Never" nil)
  1494. (const :tag "When at beginning of entry" beg)))
  1495. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1496. "Non-nil means remove time ranges specifications in agenda
  1497. items that span on several days."
  1498. :group 'org-agenda-line-format
  1499. :version "24.1"
  1500. :type 'boolean)
  1501. (defcustom org-agenda-default-appointment-duration nil
  1502. "Default duration for appointments that only have a starting time.
  1503. When nil, no duration is specified in such cases.
  1504. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1505. :group 'org-agenda-line-format
  1506. :type '(choice
  1507. (integer :tag "Minutes")
  1508. (const :tag "No default duration")))
  1509. (defcustom org-agenda-show-inherited-tags t
  1510. "Non-nil means show inherited tags in each agenda line.
  1511. When this option is set to 'always, it take precedences over
  1512. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1513. in every agenda.
  1514. When this option is set to t (the default), inherited tags are
  1515. shown when they are available, i.e. when the value of
  1516. `org-agenda-use-tag-inheritance' has been taken into account.
  1517. This can be set to a list of agenda types in which the agenda
  1518. must display the inherited tags. Available types are 'todo,
  1519. 'agenda, 'search and 'timeline.
  1520. When set to nil, never show inherited tags in agenda lines."
  1521. :group 'org-agenda-line-format
  1522. :group 'org-agenda
  1523. :version "24.3"
  1524. :type '(choice
  1525. (const :tag "Show inherited tags when available" t)
  1526. (const :tag "Always show inherited tags" 'always)
  1527. (repeat :tag "Show inherited tags only in selected agenda types"
  1528. (symbol :tag "Agenda type"))))
  1529. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1530. "List of agenda view types where to use tag inheritance.
  1531. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1532. controlled by `org-use-tag-inheritance'. In other agenda types,
  1533. `org-use-tag-inheritance' is not used for the selection of the
  1534. agenda entries. Still, you may want the agenda to be aware of
  1535. the inherited tags anyway, e.g. for later tag filtering.
  1536. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1537. This variable has no effect if `org-agenda-show-inherited-tags'
  1538. is set to 'always. In that case, the agenda is aware of those
  1539. tags.
  1540. The default value sets tags in every agenda type. Setting this
  1541. option to nil will speed up non-tags agenda view a lot."
  1542. :group 'org-agenda
  1543. :version "24.3"
  1544. :type '(choice
  1545. (const :tag "Use tag inheritance in all agenda types" t)
  1546. (repeat :tag "Use tag inheritance in selected agenda types"
  1547. (symbol :tag "Agenda type"))))
  1548. (defcustom org-agenda-hide-tags-regexp nil
  1549. "Regular expression used to filter away specific tags in agenda views.
  1550. This means that these tags will be present, but not be shown in the agenda
  1551. line. Secondary filtering will still work on the hidden tags.
  1552. Nil means don't hide any tags."
  1553. :group 'org-agenda-line-format
  1554. :type '(choice
  1555. (const :tag "Hide none" nil)
  1556. (string :tag "Regexp ")))
  1557. (defcustom org-agenda-remove-tags nil
  1558. "Non-nil means remove the tags from the headline copy in the agenda.
  1559. When this is the symbol `prefix', only remove tags when
  1560. `org-agenda-prefix-format' contains a `%T' specifier."
  1561. :group 'org-agenda-line-format
  1562. :type '(choice
  1563. (const :tag "Always" t)
  1564. (const :tag "Never" nil)
  1565. (const :tag "When prefix format contains %T" prefix)))
  1566. (if (fboundp 'defvaralias)
  1567. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1568. 'org-agenda-remove-tags))
  1569. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1570. "Shift tags in agenda items to this column.
  1571. If this number is positive, it specifies the column. If it is negative,
  1572. it means that the tags should be flushright to that column. For example,
  1573. -80 works well for a normal 80 character screen."
  1574. :group 'org-agenda-line-format
  1575. :type 'integer)
  1576. (if (fboundp 'defvaralias)
  1577. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1578. (defcustom org-agenda-fontify-priorities 'cookies
  1579. "Non-nil means highlight low and high priorities in agenda.
  1580. When t, the highest priority entries are bold, lowest priority italic.
  1581. However, settings in `org-priority-faces' will overrule these faces.
  1582. When this variable is the symbol `cookies', only fontify the
  1583. cookies, not the entire task.
  1584. This may also be an association list of priority faces, whose
  1585. keys are the character values of `org-highest-priority',
  1586. `org-default-priority', and `org-lowest-priority' (the default values
  1587. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1588. color as a string, or a list like `(:background \"Red\")'.
  1589. If it is a color, the variable `org-faces-easy-properties'
  1590. determines if it is a foreground or a background color."
  1591. :group 'org-agenda-line-format
  1592. :type '(choice
  1593. (const :tag "Never" nil)
  1594. (const :tag "Defaults" t)
  1595. (const :tag "Cookies only" cookies)
  1596. (repeat :tag "Specify"
  1597. (list (character :tag "Priority" :value ?A)
  1598. (choice :tag "Face "
  1599. (string :tag "Color")
  1600. (sexp :tag "Face"))))))
  1601. (defcustom org-agenda-day-face-function nil
  1602. "Function called to determine what face should be used to display a day.
  1603. The only argument passed to that function is the day. It should
  1604. returns a face, or nil if does not want to specify a face and let
  1605. the normal rules apply."
  1606. :group 'org-agenda-line-format
  1607. :version "24.1"
  1608. :type 'function)
  1609. (defcustom org-agenda-category-icon-alist nil
  1610. "Alist of category icon to be displayed in agenda views.
  1611. Each entry should have the following format:
  1612. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1613. Where CATEGORY-REGEXP is a regexp matching the categories where
  1614. the icon should be displayed.
  1615. FILE-OR-DATA either a file path or a string containing image data.
  1616. The other fields can be omitted safely if not needed:
  1617. TYPE indicates the image type.
  1618. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1619. image data.
  1620. PROPS are additional image attributes to assign to the image,
  1621. like, e.g. `:ascent center'.
  1622. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1623. If you want to set the display properties yourself, just put a
  1624. list as second element:
  1625. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1626. For example, to display a 16px horizontal space for Emacs
  1627. category, you can use:
  1628. (\"Emacs\" '(space . (:width (16))))"
  1629. :group 'org-agenda-line-format
  1630. :version "24.1"
  1631. :type '(alist :key-type (string :tag "Regexp matching category")
  1632. :value-type (choice (list :tag "Icon"
  1633. (string :tag "File or data")
  1634. (symbol :tag "Type")
  1635. (boolean :tag "Data?")
  1636. (repeat :tag "Extra image properties" :inline t symbol))
  1637. (list :tag "Display properties" sexp))))
  1638. (defgroup org-agenda-column-view nil
  1639. "Options concerning column view in the agenda."
  1640. :tag "Org Agenda Column View"
  1641. :group 'org-agenda)
  1642. (defcustom org-agenda-columns-show-summaries t
  1643. "Non-nil means show summaries for columns displayed in the agenda view."
  1644. :group 'org-agenda-column-view
  1645. :type 'boolean)
  1646. (defcustom org-agenda-columns-compute-summary-properties t
  1647. "Non-nil means recompute all summary properties before column view.
  1648. When column view in the agenda is listing properties that have a summary
  1649. operator, it can go to all relevant buffers and recompute the summaries
  1650. there. This can mean overhead for the agenda column view, but is necessary
  1651. to have thing up to date.
  1652. As a special case, a CLOCKSUM property also makes sure that the clock
  1653. computations are current."
  1654. :group 'org-agenda-column-view
  1655. :type 'boolean)
  1656. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1657. "Non-nil means the duration of an appointment will add to day effort.
  1658. The property to which appointment durations will be added is the one given
  1659. in the option `org-effort-property'. If an appointment does not have
  1660. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1661. is not set, an appointment without end time will not contribute to the time
  1662. estimate."
  1663. :group 'org-agenda-column-view
  1664. :type 'boolean)
  1665. (defcustom org-agenda-auto-exclude-function nil
  1666. "A function called with a tag to decide if it is filtered on '/ RET'.
  1667. The sole argument to the function, which is called once for each
  1668. possible tag, is a string giving the name of the tag. The
  1669. function should return either nil if the tag should be included
  1670. as normal, or \"-<TAG>\" to exclude the tag.
  1671. Note that for the purpose of tag filtering, only the lower-case version of
  1672. all tags will be considered, so that this function will only ever see
  1673. the lower-case version of all tags."
  1674. :group 'org-agenda
  1675. :type 'function)
  1676. (defcustom org-agenda-bulk-custom-functions nil
  1677. "Alist of characters and custom functions for bulk actions.
  1678. For example, this value makes those two functions available:
  1679. '((?R set-category)
  1680. (?C bulk-cut))
  1681. With selected entries in an agenda buffer, `B R' will call
  1682. the custom function `set-category' on the selected entries.
  1683. Note that functions in this alist don't need to be quoted."
  1684. :type 'alist
  1685. :version "24.1"
  1686. :group 'org-agenda)
  1687. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1688. "Execute BODY with point at location given by `org-hd-marker' property.
  1689. If STRING is non-nil, the text property will be fetched from position 0
  1690. in that string. If STRING is nil, it will be fetched from the beginning
  1691. of the current line."
  1692. (org-with-gensyms (marker)
  1693. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1694. 'org-hd-marker ,string)))
  1695. (with-current-buffer (marker-buffer ,marker)
  1696. (save-excursion
  1697. (goto-char ,marker)
  1698. ,@body)))))
  1699. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1700. (defun org-add-agenda-custom-command (entry)
  1701. "Replace or add a command in `org-agenda-custom-commands'.
  1702. This is mostly for hacking and trying a new command - once the command
  1703. works you probably want to add it to `org-agenda-custom-commands' for good."
  1704. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1705. (if ass
  1706. (setcdr ass (cdr entry))
  1707. (push entry org-agenda-custom-commands))))
  1708. ;;; Define the org-agenda-mode
  1709. (defvar org-agenda-mode-map (make-sparse-keymap)
  1710. "Keymap for `org-agenda-mode'.")
  1711. (if (fboundp 'defvaralias)
  1712. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1713. (defvar org-agenda-menu) ; defined later in this file.
  1714. (defvar org-agenda-restrict nil) ; defined later in this file.
  1715. (defvar org-agenda-follow-mode nil)
  1716. (defvar org-agenda-entry-text-mode nil)
  1717. (defvar org-agenda-clockreport-mode nil)
  1718. (defvar org-agenda-show-log nil)
  1719. (defvar org-agenda-redo-command nil)
  1720. (defvar org-agenda-query-string nil)
  1721. (defvar org-agenda-mode-hook nil
  1722. "Hook run after `org-agenda-mode' is turned on.
  1723. The buffer is still writable when this hook is called.")
  1724. (defvar org-agenda-type nil)
  1725. (defvar org-agenda-force-single-file nil)
  1726. (defvar org-agenda-bulk-marked-entries nil
  1727. "List of markers that refer to marked entries in the agenda.")
  1728. ;;; Multiple agenda buffers support
  1729. (defcustom org-agenda-sticky nil
  1730. "Non-nil means agenda q key will bury agenda buffers.
  1731. Agenda commands will then show existing buffer instead of generating new ones.
  1732. When nil, `q' will kill the single agenda buffer."
  1733. :group 'org-agenda
  1734. :version "24.3"
  1735. :type 'boolean)
  1736. ;;;###autoload
  1737. (defun org-toggle-sticky-agenda (&optional arg)
  1738. "Toggle `org-agenda-sticky'."
  1739. (interactive "P")
  1740. (let ((new-value (if arg
  1741. (> (prefix-numeric-value arg) 0)
  1742. (not org-agenda-sticky))))
  1743. (if (equal new-value org-agenda-sticky)
  1744. (and (org-called-interactively-p 'interactive)
  1745. (message "Sticky agenda was already %s"
  1746. (if org-agenda-sticky "enabled" "disabled")))
  1747. (setq org-agenda-sticky new-value)
  1748. (org-agenda-kill-all-agenda-buffers)
  1749. (and (org-called-interactively-p 'interactive)
  1750. (message "Sticky agenda was %s"
  1751. (if org-agenda-sticky "enabled" "disabled"))))))
  1752. (defvar org-agenda-buffer nil
  1753. "Agenda buffer currently being generated.")
  1754. (defvar org-agenda-last-prefix-arg nil)
  1755. (defvar org-agenda-this-buffer-name nil)
  1756. (defvar org-agenda-doing-sticky-redo nil)
  1757. (defvar org-agenda-this-buffer-is-sticky nil)
  1758. (defconst org-agenda-local-vars
  1759. '(org-agenda-this-buffer-name
  1760. org-agenda-undo-list
  1761. org-agenda-pending-undo-list
  1762. org-agenda-follow-mode
  1763. org-agenda-entry-text-mode
  1764. org-agenda-clockreport-mode
  1765. org-agenda-show-log
  1766. org-agenda-redo-command
  1767. org-agenda-query-string
  1768. org-agenda-type
  1769. org-agenda-bulk-marked-entries
  1770. org-agenda-undo-has-started-in
  1771. org-agenda-info
  1772. org-agenda-tag-filter-overlays
  1773. org-agenda-cat-filter-overlays
  1774. org-agenda-pre-window-conf
  1775. org-agenda-columns-active
  1776. org-agenda-tag-filter
  1777. org-agenda-category-filter
  1778. org-agenda-markers
  1779. org-agenda-last-search-view-search-was-boolean
  1780. org-agenda-filtered-by-category
  1781. org-agenda-filter-form
  1782. org-agenda-cycle-counter
  1783. org-agenda-last-prefix-arg)
  1784. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1785. (defun org-agenda-mode ()
  1786. "Mode for time-sorted view on action items in Org-mode files.
  1787. The following commands are available:
  1788. \\{org-agenda-mode-map}"
  1789. (interactive)
  1790. (cond (org-agenda-doing-sticky-redo
  1791. ;; Refreshing sticky agenda-buffer
  1792. ;;
  1793. ;; Preserve the value of `org-agenda-local-vars' variables,
  1794. ;; while letting `kill-all-local-variables' kill the rest
  1795. (let ((save (buffer-local-variables)))
  1796. (kill-all-local-variables)
  1797. (mapc 'make-local-variable org-agenda-local-vars)
  1798. (dolist (elem save)
  1799. (let ((var (car elem))
  1800. (val (cdr elem)))
  1801. (when (and val
  1802. (member var org-agenda-local-vars))
  1803. (set var val)))))
  1804. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1805. (org-agenda-sticky
  1806. ;; Creating a sticky Agenda buffer for the first time
  1807. (kill-all-local-variables)
  1808. (mapc 'make-local-variable org-agenda-local-vars)
  1809. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1810. (t
  1811. ;; Creating a non-sticky agenda buffer
  1812. (kill-all-local-variables)
  1813. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1814. (setq org-agenda-undo-list nil
  1815. org-agenda-pending-undo-list nil
  1816. org-agenda-bulk-marked-entries nil)
  1817. (setq major-mode 'org-agenda-mode)
  1818. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1819. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1820. (setq mode-name "Org-Agenda")
  1821. (use-local-map org-agenda-mode-map)
  1822. (easy-menu-add org-agenda-menu)
  1823. (if org-startup-truncated (setq truncate-lines t))
  1824. (org-set-local 'line-move-visual nil)
  1825. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1826. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1827. ;; Make sure properties are removed when copying text
  1828. (make-local-variable 'filter-buffer-substring-functions)
  1829. (add-hook 'filter-buffer-substring-functions
  1830. (lambda (fun start end delete)
  1831. (substring-no-properties (funcall fun start end delete))))
  1832. (unless org-agenda-keep-modes
  1833. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1834. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1835. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1836. org-agenda-show-log org-agenda-start-with-log-mode))
  1837. (easy-menu-change
  1838. '("Agenda") "Agenda Files"
  1839. (append
  1840. (list
  1841. (vector
  1842. (if (get 'org-agenda-files 'org-restrict)
  1843. "Restricted to single file"
  1844. "Edit File List")
  1845. '(org-edit-agenda-file-list)
  1846. (not (get 'org-agenda-files 'org-restrict)))
  1847. "--")
  1848. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1849. (org-agenda-set-mode-name)
  1850. (apply
  1851. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1852. (list 'org-agenda-mode-hook)))
  1853. (substitute-key-definition 'undo 'org-agenda-undo
  1854. org-agenda-mode-map global-map)
  1855. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1856. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1857. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1858. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1859. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1860. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1861. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1862. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1863. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1864. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1865. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1866. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1867. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1868. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1869. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1870. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1871. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1872. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1873. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1874. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1875. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1877. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1878. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1879. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1880. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1881. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1882. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1883. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1884. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1885. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1886. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1887. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1888. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1889. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1890. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1891. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1892. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1893. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1894. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1895. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1896. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1897. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1898. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1899. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1900. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1901. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1902. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1903. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1904. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1905. (while l (org-defkey org-agenda-mode-map
  1906. (int-to-string (pop l)) 'digit-argument)))
  1907. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1908. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1909. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1910. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1911. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1912. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1913. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1914. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1915. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1916. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1917. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1918. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1919. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1920. 'org-clock-modify-effort-estimate)
  1921. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1922. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1923. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1924. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1925. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1926. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1927. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1928. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1929. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1930. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1931. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1932. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1933. (substitute-key-definition 'next-line 'org-agenda-next-line
  1934. org-agenda-mode-map global-map)
  1935. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1936. org-agenda-mode-map global-map)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1940. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1941. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1942. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1943. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1944. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1945. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1946. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1947. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1948. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1949. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1950. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1951. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1952. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1953. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1954. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1955. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1956. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1957. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1958. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1959. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1960. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1961. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1962. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1963. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1964. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1965. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1966. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1967. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1968. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1969. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1970. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1971. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1972. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1973. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1974. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1975. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1976. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1977. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1978. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1979. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1980. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1981. (when org-agenda-mouse-1-follows-link
  1982. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1983. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1984. '("Agenda"
  1985. ("Agenda Files")
  1986. "--"
  1987. ("Agenda Dates"
  1988. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1989. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1990. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1991. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1992. "--"
  1993. ("View"
  1994. ["Day View" org-agenda-day-view
  1995. :active (org-agenda-check-type nil 'agenda)
  1996. :style radio :selected (eq org-agenda-current-span 'day)
  1997. :keys "v d (or just d)"]
  1998. ["Week View" org-agenda-week-view
  1999. :active (org-agenda-check-type nil 'agenda)
  2000. :style radio :selected (eq org-agenda-current-span 'week)
  2001. :keys "v w (or just w)"]
  2002. ["Month View" org-agenda-month-view
  2003. :active (org-agenda-check-type nil 'agenda)
  2004. :style radio :selected (eq org-agenda-current-span 'month)
  2005. :keys "v m"]
  2006. ["Year View" org-agenda-year-view
  2007. :active (org-agenda-check-type nil 'agenda)
  2008. :style radio :selected (eq org-agenda-current-span 'year)
  2009. :keys "v y"]
  2010. "--"
  2011. ["Include Diary" org-agenda-toggle-diary
  2012. :style toggle :selected org-agenda-include-diary
  2013. :active (org-agenda-check-type nil 'agenda)]
  2014. ["Include Deadlines" org-agenda-toggle-deadlines
  2015. :style toggle :selected org-agenda-include-deadlines
  2016. :active (org-agenda-check-type nil 'agenda)]
  2017. ["Use Time Grid" org-agenda-toggle-time-grid
  2018. :style toggle :selected org-agenda-use-time-grid
  2019. :active (org-agenda-check-type nil 'agenda)]
  2020. "--"
  2021. ["Show clock report" org-agenda-clockreport-mode
  2022. :style toggle :selected org-agenda-clockreport-mode
  2023. :active (org-agenda-check-type nil 'agenda)]
  2024. ["Show some entry text" org-agenda-entry-text-mode
  2025. :style toggle :selected org-agenda-entry-text-mode
  2026. :active t]
  2027. "--"
  2028. ["Show Logbook entries" org-agenda-log-mode
  2029. :style toggle :selected org-agenda-show-log
  2030. :active (org-agenda-check-type nil 'agenda 'timeline)
  2031. :keys "v l (or just l)"]
  2032. ["Include archived trees" org-agenda-archives-mode
  2033. :style toggle :selected org-agenda-archives-mode :active t
  2034. :keys "v a"]
  2035. ["Include archive files" (org-agenda-archives-mode t)
  2036. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2037. :keys "v A"]
  2038. "--"
  2039. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2040. ["Write view to file" org-agenda-write t]
  2041. ["Rebuild buffer" org-agenda-redo t]
  2042. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2043. "--"
  2044. ["Show original entry" org-agenda-show t]
  2045. ["Go To (other window)" org-agenda-goto t]
  2046. ["Go To (this window)" org-agenda-switch-to t]
  2047. ["Capture with cursor date" org-agenda-capture t]
  2048. ["Follow Mode" org-agenda-follow-mode
  2049. :style toggle :selected org-agenda-follow-mode :active t]
  2050. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2051. "--"
  2052. ("TODO"
  2053. ["Cycle TODO" org-agenda-todo t]
  2054. ["Next TODO set" org-agenda-todo-nextset t]
  2055. ["Previous TODO set" org-agenda-todo-previousset t]
  2056. ["Add note" org-agenda-add-note t])
  2057. ("Archive/Refile/Delete"
  2058. ["Archive default" org-agenda-archive-default t]
  2059. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2060. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2061. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2062. ["Archive subtree" org-agenda-archive t]
  2063. "--"
  2064. ["Refile" org-agenda-refile t]
  2065. "--"
  2066. ["Delete subtree" org-agenda-kill t])
  2067. ("Bulk action"
  2068. ["Mark entry" org-agenda-bulk-mark t]
  2069. ["Mark all" org-agenda-bulk-mark-all t]
  2070. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2071. ["Unmark entry" org-agenda-bulk-unmark t]
  2072. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2073. ["Act on all marked" org-agenda-bulk-action t]
  2074. "--"
  2075. ("Tags and Properties"
  2076. ["Show all Tags" org-agenda-show-tags t]
  2077. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2078. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2079. "--"
  2080. ["Column View" org-columns t])
  2081. ("Deadline/Schedule"
  2082. ["Schedule" org-agenda-schedule t]
  2083. ["Set Deadline" org-agenda-deadline t]
  2084. "--"
  2085. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2086. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2087. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2088. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2089. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2090. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2091. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2092. ("Clock and Effort"
  2093. ["Clock in" org-agenda-clock-in t]
  2094. ["Clock out" org-agenda-clock-out t]
  2095. ["Clock cancel" org-agenda-clock-cancel t]
  2096. ["Goto running clock" org-clock-goto t]
  2097. "--"
  2098. ["Set Effort" org-agenda-set-effort t]
  2099. ["Change clocked effort" org-clock-modify-effort-estimate
  2100. (org-clock-is-active)])
  2101. ("Priority"
  2102. ["Set Priority" org-agenda-priority t]
  2103. ["Increase Priority" org-agenda-priority-up t]
  2104. ["Decrease Priority" org-agenda-priority-down t]
  2105. ["Show Priority" org-show-priority t])
  2106. ("Calendar/Diary"
  2107. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2108. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2109. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2110. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2111. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2112. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2113. "--"
  2114. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2115. "--"
  2116. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2117. "--"
  2118. ("MobileOrg"
  2119. ["Push Files and Views" org-mobile-push t]
  2120. ["Get Captured and Flagged" org-mobile-pull t]
  2121. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2122. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2123. "--"
  2124. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2125. "--"
  2126. ["Quit" org-agenda-quit t]
  2127. ["Exit and Release Buffers" org-agenda-exit t]
  2128. ))
  2129. ;;; Agenda undo
  2130. (defvar org-agenda-allow-remote-undo t
  2131. "Non-nil means allow remote undo from the agenda buffer.")
  2132. (defvar org-agenda-undo-has-started-in nil
  2133. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2134. (defun org-agenda-undo ()
  2135. "Undo a remote editing step in the agenda.
  2136. This undoes changes both in the agenda buffer and in the remote buffer
  2137. that have been changed along."
  2138. (interactive)
  2139. (or org-agenda-allow-remote-undo
  2140. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2141. (if (not (eq this-command last-command))
  2142. (setq org-agenda-undo-has-started-in nil
  2143. org-agenda-pending-undo-list org-agenda-undo-list))
  2144. (if (not org-agenda-pending-undo-list)
  2145. (error "No further undo information"))
  2146. (let* ((entry (pop org-agenda-pending-undo-list))
  2147. buf line cmd rembuf)
  2148. (setq cmd (pop entry) line (pop entry))
  2149. (setq rembuf (nth 2 entry))
  2150. (org-with-remote-undo rembuf
  2151. (while (bufferp (setq buf (pop entry)))
  2152. (if (pop entry)
  2153. (with-current-buffer buf
  2154. (let ((last-undo-buffer buf)
  2155. (inhibit-read-only t))
  2156. (unless (memq buf org-agenda-undo-has-started-in)
  2157. (push buf org-agenda-undo-has-started-in)
  2158. (make-local-variable 'pending-undo-list)
  2159. (undo-start))
  2160. (while (and pending-undo-list
  2161. (listp pending-undo-list)
  2162. (not (car pending-undo-list)))
  2163. (pop pending-undo-list))
  2164. (undo-more 1))))))
  2165. (org-goto-line line)
  2166. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2167. (defun org-verify-change-for-undo (l1 l2)
  2168. "Verify that a real change occurred between the undo lists L1 and L2."
  2169. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2170. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2171. (not (eq l1 l2)))
  2172. ;;; Agenda dispatch
  2173. (defvar org-agenda-restrict-begin (make-marker))
  2174. (defvar org-agenda-restrict-end (make-marker))
  2175. (defvar org-agenda-last-dispatch-buffer nil)
  2176. (defvar org-agenda-overriding-restriction nil)
  2177. (defcustom org-agenda-custom-commands-contexts nil
  2178. "Alist of custom agenda keys and contextual rules.
  2179. For example, if you have a custom agenda command \"p\" and you
  2180. want this command to be accessible only from plain text files,
  2181. use this:
  2182. '((\"p\" ((in-file . \"\\.txt\"))))
  2183. Here are the available contexts definitions:
  2184. in-file: command displayed only in matching files
  2185. in-mode: command displayed only in matching modes
  2186. not-in-file: command not displayed in matching files
  2187. not-in-mode: command not displayed in matching modes
  2188. in-buffer: command displayed only in matching buffers
  2189. not-in-buffer: command not displayed in matching buffers
  2190. [function]: a custom function taking no argument
  2191. If you define several checks, the agenda command will be
  2192. accessible if there is at least one valid check.
  2193. You can also bind a key to another agenda custom command
  2194. depending on contextual rules.
  2195. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2196. Here it means: in .txt files, use \"p\" as the key for the
  2197. agenda command otherwise associated with \"q\". (The command
  2198. originally associated with \"q\" is not displayed to avoid
  2199. duplicates.)"
  2200. :version "24.3"
  2201. :group 'org-agenda-custom-commands
  2202. :type '(repeat (list :tag "Rule"
  2203. (string :tag " Agenda key")
  2204. (string :tag "Replace by command")
  2205. (repeat :tag "Available when"
  2206. (choice
  2207. (cons :tag "Condition"
  2208. (choice
  2209. (const :tag "In file" in-file)
  2210. (const :tag "Not in file" not-in-file)
  2211. (const :tag "In buffer" in-buffer)
  2212. (const :tag "Not in buffer" not-in-buffer)
  2213. (const :tag "In mode" in-mode)
  2214. (const :tag "Not in mode" not-in-mode))
  2215. (regexp))
  2216. (function :tag "Custom function"))))))
  2217. (defcustom org-agenda-max-entries nil
  2218. "Maximum number of entries to display in an agenda.
  2219. This can be nil (no limit) or an integer or an alist of agenda
  2220. types with an associated number of entries to display in this
  2221. type."
  2222. :version "24.4"
  2223. :package-version '(Org . "8.0")
  2224. :group 'org-agenda-custom-commands
  2225. :type '(choice (symbol :tag "No limit" nil)
  2226. (integer :tag "Max number of entries")
  2227. (repeat
  2228. (cons (choice :tag "Agenda type"
  2229. (const agenda)
  2230. (const todo)
  2231. (const tags)
  2232. (const search)
  2233. (const timeline))
  2234. (integer :tag "Max number of entries")))))
  2235. (defcustom org-agenda-max-todos nil
  2236. "Maximum number of TODOs to display in an agenda.
  2237. This can be nil (no limit) or an integer or an alist of agenda
  2238. types with an associated number of entries to display in this
  2239. type."
  2240. :version "24.4"
  2241. :package-version '(Org . "8.0")
  2242. :group 'org-agenda-custom-commands
  2243. :type '(choice (symbol :tag "No limit" nil)
  2244. (integer :tag "Max number of entries")
  2245. (repeat
  2246. (cons (choice :tag "Agenda type"
  2247. (const agenda)
  2248. (const todo)
  2249. (const tags)
  2250. (const search)
  2251. (const timeline))
  2252. (integer :tag "Max number of entries")))))
  2253. (defcustom org-agenda-max-tags nil
  2254. "Maximum number of tagged entries to display in an agenda.
  2255. This can be nil (no limit) or an integer or an alist of agenda
  2256. types with an associated number of entries to display in this
  2257. type."
  2258. :version "24.4"
  2259. :package-version '(Org . "8.0")
  2260. :group 'org-agenda-custom-commands
  2261. :type '(choice (symbol :tag "No limit" nil)
  2262. (integer :tag "Max number of entries")
  2263. (repeat
  2264. (cons (choice :tag "Agenda type"
  2265. (const agenda)
  2266. (const todo)
  2267. (const tags)
  2268. (const search)
  2269. (const timeline))
  2270. (integer :tag "Max number of entries")))))
  2271. (defcustom org-agenda-max-effort nil
  2272. "Maximum cumulated effort duration for the agenda.
  2273. This can be nil (no limit) or a number of minutes (as an integer)
  2274. or an alist of agenda types with an associated number of minutes
  2275. to limit entries to in this type."
  2276. :version "24.4"
  2277. :package-version '(Org . "8.0")
  2278. :group 'org-agenda-custom-commands
  2279. :type '(choice (symbol :tag "No limit" nil)
  2280. (integer :tag "Max number of entries")
  2281. (repeat
  2282. (cons (choice :tag "Agenda type"
  2283. (const agenda)
  2284. (const todo)
  2285. (const tags)
  2286. (const search)
  2287. (const timeline))
  2288. (integer :tag "Max number of entries")))))
  2289. (defvar org-keys nil)
  2290. (defvar org-match nil)
  2291. ;;;###autoload
  2292. (defun org-agenda (&optional arg org-keys restriction)
  2293. "Dispatch agenda commands to collect entries to the agenda buffer.
  2294. Prompts for a command to execute. Any prefix arg will be passed
  2295. on to the selected command. The default selections are:
  2296. a Call `org-agenda-list' to display the agenda for current day or week.
  2297. t Call `org-todo-list' to display the global todo list.
  2298. T Call `org-todo-list' to display the global todo list, select only
  2299. entries with a specific TODO keyword (the user gets a prompt).
  2300. m Call `org-tags-view' to display headlines with tags matching
  2301. a condition (the user is prompted for the condition).
  2302. M Like `m', but select only TODO entries, no ordinary headlines.
  2303. L Create a timeline for the current buffer.
  2304. e Export views to associated files.
  2305. s Search entries for keywords.
  2306. S Search entries for keywords, only with TODO keywords.
  2307. / Multi occur across all agenda files and also files listed
  2308. in `org-agenda-text-search-extra-files'.
  2309. < Restrict agenda commands to buffer, subtree, or region.
  2310. Press several times to get the desired effect.
  2311. > Remove a previous restriction.
  2312. # List \"stuck\" projects.
  2313. ! Configure what \"stuck\" means.
  2314. C Configure custom agenda commands.
  2315. More commands can be added by configuring the variable
  2316. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2317. searches can be pre-defined in this way.
  2318. If the current buffer is in Org-mode and visiting a file, you can also
  2319. first press `<' once to indicate that the agenda should be temporarily
  2320. \(until the next use of \\[org-agenda]) restricted to the current file.
  2321. Pressing `<' twice means to restrict to the current subtree or region
  2322. \(if active)."
  2323. (interactive "P")
  2324. (catch 'exit
  2325. (let* ((prefix-descriptions nil)
  2326. (org-agenda-buffer-name org-agenda-buffer-name)
  2327. (org-agenda-window-setup (if (equal (buffer-name)
  2328. org-agenda-buffer-name)
  2329. 'current-window
  2330. org-agenda-window-setup))
  2331. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2332. (org-agenda-custom-commands
  2333. ;; normalize different versions
  2334. (delq nil
  2335. (mapcar
  2336. (lambda (x)
  2337. (cond ((stringp (cdr x))
  2338. (push x prefix-descriptions)
  2339. nil)
  2340. ((stringp (nth 1 x)) x)
  2341. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2342. (t (cons (car x) (cons "" (cdr x))))))
  2343. org-agenda-custom-commands)))
  2344. (org-agenda-custom-commands
  2345. (org-contextualize-keys
  2346. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2347. (buf (current-buffer))
  2348. (bfn (buffer-file-name (buffer-base-buffer)))
  2349. entry key type org-match lprops ans)
  2350. ;; Turn off restriction unless there is an overriding one,
  2351. (unless org-agenda-overriding-restriction
  2352. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2353. ;; There is a request to keep the file list in place
  2354. (put 'org-agenda-files 'org-restrict nil))
  2355. (setq org-agenda-restrict nil)
  2356. (move-marker org-agenda-restrict-begin nil)
  2357. (move-marker org-agenda-restrict-end nil))
  2358. ;; Delete old local properties
  2359. (put 'org-agenda-redo-command 'org-lprops nil)
  2360. ;; Delete previously set last-arguments
  2361. (put 'org-agenda-redo-command 'last-args nil)
  2362. ;; Remember where this call originated
  2363. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2364. (unless org-keys
  2365. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2366. org-keys (car ans)
  2367. restriction (cdr ans)))
  2368. ;; If we have sticky agenda buffers, set a name for the buffer,
  2369. ;; depending on the invoking keys. The user may still set this
  2370. ;; as a command option, which will overwrite what we do here.
  2371. (if org-agenda-sticky
  2372. (setq org-agenda-buffer-name
  2373. (format "*Org Agenda(%s)*" org-keys)))
  2374. ;; Establish the restriction, if any
  2375. (when (and (not org-agenda-overriding-restriction) restriction)
  2376. (put 'org-agenda-files 'org-restrict (list bfn))
  2377. (cond
  2378. ((eq restriction 'region)
  2379. (setq org-agenda-restrict t)
  2380. (move-marker org-agenda-restrict-begin (region-beginning))
  2381. (move-marker org-agenda-restrict-end (region-end)))
  2382. ((eq restriction 'subtree)
  2383. (save-excursion
  2384. (setq org-agenda-restrict t)
  2385. (org-back-to-heading t)
  2386. (move-marker org-agenda-restrict-begin (point))
  2387. (move-marker org-agenda-restrict-end
  2388. (progn (org-end-of-subtree t)))))))
  2389. ;; For example the todo list should not need it (but does...)
  2390. (cond
  2391. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2392. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2393. (progn
  2394. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2395. lprops (nth 4 entry))
  2396. (if org-agenda-sticky
  2397. (setq org-agenda-buffer-name
  2398. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2399. (format "*Org Agenda(%s)*" org-keys))))
  2400. (put 'org-agenda-redo-command 'org-lprops lprops)
  2401. (cond
  2402. ((eq type 'agenda)
  2403. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2404. ((eq type 'alltodo)
  2405. (org-let lprops '(org-todo-list current-prefix-arg)))
  2406. ((eq type 'search)
  2407. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2408. ((eq type 'stuck)
  2409. (org-let lprops '(org-agenda-list-stuck-projects
  2410. current-prefix-arg)))
  2411. ((eq type 'tags)
  2412. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2413. ((eq type 'tags-todo)
  2414. (org-let lprops '(org-tags-view '(4) org-match)))
  2415. ((eq type 'todo)
  2416. (org-let lprops '(org-todo-list org-match)))
  2417. ((eq type 'tags-tree)
  2418. (org-check-for-org-mode)
  2419. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2420. ((eq type 'todo-tree)
  2421. (org-check-for-org-mode)
  2422. (org-let lprops
  2423. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2424. (regexp-quote org-match) "\\>"))))
  2425. ((eq type 'occur-tree)
  2426. (org-check-for-org-mode)
  2427. (org-let lprops '(org-occur org-match)))
  2428. ((functionp type)
  2429. (org-let lprops '(funcall type org-match)))
  2430. ((fboundp type)
  2431. (org-let lprops '(funcall type org-match)))
  2432. (t (error "Invalid custom agenda command type %s" type))))
  2433. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2434. ((equal org-keys "C")
  2435. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2436. (customize-variable 'org-agenda-custom-commands))
  2437. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2438. ((equal org-keys "s") (call-interactively 'org-search-view))
  2439. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2440. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2441. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2442. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2443. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2444. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2445. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2446. (org-add-hook
  2447. 'post-command-hook
  2448. (lambda ()
  2449. (unless (current-message)
  2450. (let* ((m (org-agenda-get-any-marker))
  2451. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2452. (when note
  2453. (message (concat
  2454. "FLAGGING-NOTE ([?] for more info): "
  2455. (org-add-props
  2456. (replace-regexp-in-string
  2457. "\\\\n" "//"
  2458. (copy-sequence note))
  2459. nil 'face 'org-warning)))))))
  2460. t t))
  2461. ((equal org-keys "L")
  2462. (unless (derived-mode-p 'org-mode)
  2463. (error "This is not an Org-mode file"))
  2464. (unless restriction
  2465. (put 'org-agenda-files 'org-restrict (list bfn))
  2466. (org-call-with-arg 'org-timeline arg)))
  2467. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2468. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2469. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2470. (t (error "Invalid agenda key"))))))
  2471. (defun org-agenda-append-agenda ()
  2472. "Append another agenda view to the current one.
  2473. This function allows interactive building of block agendas.
  2474. Agenda views are separated by `org-agenda-block-separator'."
  2475. (interactive)
  2476. (unless (derived-mode-p 'org-agenda-mode)
  2477. (error "Can only append from within agenda buffer"))
  2478. (let ((org-agenda-multi t))
  2479. (org-agenda)
  2480. (widen)
  2481. (org-agenda-finalize)
  2482. (org-agenda-fit-window-to-buffer)))
  2483. (defun org-agenda-normalize-custom-commands (cmds)
  2484. (delq nil
  2485. (mapcar
  2486. (lambda (x)
  2487. (cond ((stringp (cdr x)) nil)
  2488. ((stringp (nth 1 x)) x)
  2489. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2490. (t (cons (car x) (cons "" (cdr x))))))
  2491. cmds)))
  2492. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2493. "The user interface for selecting an agenda command."
  2494. (catch 'exit
  2495. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2496. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2497. (region-p (org-region-active-p))
  2498. (custom org-agenda-custom-commands)
  2499. (selstring "")
  2500. restriction second-time
  2501. c entry key type match prefixes rmheader header-end custom1 desc
  2502. line lines left right n n1)
  2503. (save-window-excursion
  2504. (delete-other-windows)
  2505. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2506. (erase-buffer)
  2507. (insert (eval-when-compile
  2508. (let ((header
  2509. "Press key for an agenda command: < Buffer, subtree/region restriction
  2510. -------------------------------- > Remove restriction
  2511. a Agenda for current week or day e Export agenda views
  2512. t List of all TODO entries T Entries with special TODO kwd
  2513. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2514. s Search for keywords S Like s, but only TODO entries
  2515. L Timeline for current buffer # List stuck projects (!=configure)
  2516. / Multi-occur C Configure custom agenda commands
  2517. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2518. ")
  2519. (start 0))
  2520. (while (string-match
  2521. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2522. header start)
  2523. (setq start (match-end 0))
  2524. (add-text-properties (match-beginning 2) (match-end 2)
  2525. '(face bold) header))
  2526. header)))
  2527. (setq header-end (point-marker))
  2528. (while t
  2529. (setq custom1 custom)
  2530. (when (eq rmheader t)
  2531. (org-goto-line 1)
  2532. (re-search-forward ":" nil t)
  2533. (delete-region (match-end 0) (point-at-eol))
  2534. (forward-char 1)
  2535. (looking-at "-+")
  2536. (delete-region (match-end 0) (point-at-eol))
  2537. (move-marker header-end (match-end 0)))
  2538. (goto-char header-end)
  2539. (delete-region (point) (point-max))
  2540. ;; Produce all the lines that describe custom commands and prefixes
  2541. (setq lines nil)
  2542. (while (setq entry (pop custom1))
  2543. (setq key (car entry) desc (nth 1 entry)
  2544. type (nth 2 entry)
  2545. match (nth 3 entry))
  2546. (if (> (length key) 1)
  2547. (add-to-list 'prefixes (string-to-char key))
  2548. (setq line
  2549. (format
  2550. "%-4s%-14s"
  2551. (org-add-props (copy-sequence key)
  2552. '(face bold))
  2553. (cond
  2554. ((string-match "\\S-" desc) desc)
  2555. ((eq type 'agenda) "Agenda for current week or day")
  2556. ((eq type 'alltodo) "List of all TODO entries")
  2557. ((eq type 'search) "Word search")
  2558. ((eq type 'stuck) "List of stuck projects")
  2559. ((eq type 'todo) "TODO keyword")
  2560. ((eq type 'tags) "Tags query")
  2561. ((eq type 'tags-todo) "Tags (TODO)")
  2562. ((eq type 'tags-tree) "Tags tree")
  2563. ((eq type 'todo-tree) "TODO kwd tree")
  2564. ((eq type 'occur-tree) "Occur tree")
  2565. ((functionp type) (if (symbolp type)
  2566. (symbol-name type)
  2567. "Lambda expression"))
  2568. (t "???"))))
  2569. (if org-agenda-menu-show-matcher
  2570. (setq line
  2571. (concat line ": "
  2572. (cond
  2573. ((stringp match)
  2574. (setq match (copy-sequence match))
  2575. (org-add-props match nil 'face 'org-warning))
  2576. ((listp type)
  2577. (format "set of %d commands" (length type))))))
  2578. (if (org-string-nw-p match)
  2579. (add-text-properties
  2580. 0 (length line) (list 'help-echo
  2581. (concat "Matcher: " match)) line)))
  2582. (push line lines)))
  2583. (setq lines (nreverse lines))
  2584. (when prefixes
  2585. (mapc (lambda (x)
  2586. (push
  2587. (format "%s %s"
  2588. (org-add-props (char-to-string x)
  2589. nil 'face 'bold)
  2590. (or (cdr (assoc (concat selstring
  2591. (char-to-string x))
  2592. prefix-descriptions))
  2593. "Prefix key"))
  2594. lines))
  2595. prefixes))
  2596. ;; Check if we should display in two columns
  2597. (if org-agenda-menu-two-columns
  2598. (progn
  2599. (setq n (length lines)
  2600. n1 (+ (/ n 2) (mod n 2))
  2601. right (nthcdr n1 lines)
  2602. left (copy-sequence lines))
  2603. (setcdr (nthcdr (1- n1) left) nil))
  2604. (setq left lines right nil))
  2605. (while left
  2606. (insert "\n" (pop left))
  2607. (when right
  2608. (if (< (current-column) 40)
  2609. (move-to-column 40 t)
  2610. (insert " "))
  2611. (insert (pop right))))
  2612. ;; Make the window the right size
  2613. (goto-char (point-min))
  2614. (if second-time
  2615. (if (not (pos-visible-in-window-p (point-max)))
  2616. (org-fit-window-to-buffer))
  2617. (setq second-time t)
  2618. (org-fit-window-to-buffer))
  2619. ;; Ask for selection
  2620. (message "Press key for agenda command%s:"
  2621. (if (or restrict-ok org-agenda-overriding-restriction)
  2622. (if org-agenda-overriding-restriction
  2623. " (restriction lock active)"
  2624. (if restriction
  2625. (format " (restricted to %s)" restriction)
  2626. " (unrestricted)"))
  2627. ""))
  2628. (setq c (read-char-exclusive))
  2629. (message "")
  2630. (cond
  2631. ((assoc (char-to-string c) custom)
  2632. (setq selstring (concat selstring (char-to-string c)))
  2633. (throw 'exit (cons selstring restriction)))
  2634. ((memq c prefixes)
  2635. (setq selstring (concat selstring (char-to-string c))
  2636. prefixes nil
  2637. rmheader (or rmheader t)
  2638. custom (delq nil (mapcar
  2639. (lambda (x)
  2640. (if (or (= (length (car x)) 1)
  2641. (/= (string-to-char (car x)) c))
  2642. nil
  2643. (cons (substring (car x) 1) (cdr x))))
  2644. custom))))
  2645. ((eq c ?*)
  2646. (call-interactively 'org-toggle-sticky-agenda)
  2647. (sit-for 2))
  2648. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2649. (message "Restriction is only possible in Org-mode buffers")
  2650. (ding) (sit-for 1))
  2651. ((eq c ?1)
  2652. (org-agenda-remove-restriction-lock 'noupdate)
  2653. (setq restriction 'buffer))
  2654. ((eq c ?0)
  2655. (org-agenda-remove-restriction-lock 'noupdate)
  2656. (setq restriction (if region-p 'region 'subtree)))
  2657. ((eq c ?<)
  2658. (org-agenda-remove-restriction-lock 'noupdate)
  2659. (setq restriction
  2660. (cond
  2661. ((eq restriction 'buffer)
  2662. (if region-p 'region 'subtree))
  2663. ((memq restriction '(subtree region))
  2664. nil)
  2665. (t 'buffer))))
  2666. ((eq c ?>)
  2667. (org-agenda-remove-restriction-lock 'noupdate)
  2668. (setq restriction nil))
  2669. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2670. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2671. ((and (> (length selstring) 0) (eq c ?\d))
  2672. (delete-window)
  2673. (org-agenda-get-restriction-and-command prefix-descriptions))
  2674. ((equal c ?q) (error "Abort"))
  2675. (t (error "Invalid key %c" c))))))))
  2676. (defun org-agenda-fit-window-to-buffer ()
  2677. "Fit the window to the buffer size."
  2678. (and (memq org-agenda-window-setup '(reorganize-frame))
  2679. (fboundp 'fit-window-to-buffer)
  2680. (org-fit-window-to-buffer
  2681. nil
  2682. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2683. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2684. (defvar org-cmd nil)
  2685. (defvar org-agenda-overriding-cmd nil)
  2686. (defvar org-agenda-overriding-arguments nil)
  2687. (defvar org-agenda-overriding-cmd-arguments nil)
  2688. (defun org-agenda-run-series (name series)
  2689. (org-let (nth 1 series) '(org-agenda-prepare name))
  2690. ;; We need to reset agenda markers here, because when constructing a
  2691. ;; block agenda, the individual blocks do not do that.
  2692. (org-agenda-reset-markers)
  2693. (let* ((org-agenda-multi t)
  2694. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2695. (cmds (car series))
  2696. (gprops (nth 1 series))
  2697. match ;; The byte compiler incorrectly complains about this. Keep it!
  2698. org-cmd type lprops)
  2699. (while (setq org-cmd (pop cmds))
  2700. (setq type (car org-cmd)
  2701. match (eval (nth 1 org-cmd))
  2702. lprops (nth 2 org-cmd))
  2703. (let ((org-agenda-overriding-arguments
  2704. (if (eq org-agenda-overriding-cmd org-cmd)
  2705. (or org-agenda-overriding-arguments
  2706. org-agenda-overriding-cmd-arguments))))
  2707. (cond
  2708. ((eq type 'agenda)
  2709. (org-let2 gprops lprops
  2710. '(call-interactively 'org-agenda-list)))
  2711. ((eq type 'alltodo)
  2712. (org-let2 gprops lprops
  2713. '(call-interactively 'org-todo-list)))
  2714. ((eq type 'search)
  2715. (org-let2 gprops lprops
  2716. '(org-search-view current-prefix-arg match nil)))
  2717. ((eq type 'stuck)
  2718. (org-let2 gprops lprops
  2719. '(call-interactively 'org-agenda-list-stuck-projects)))
  2720. ((eq type 'tags)
  2721. (org-let2 gprops lprops
  2722. '(org-tags-view current-prefix-arg match)))
  2723. ((eq type 'tags-todo)
  2724. (org-let2 gprops lprops
  2725. '(org-tags-view '(4) match)))
  2726. ((eq type 'todo)
  2727. (org-let2 gprops lprops
  2728. '(org-todo-list match)))
  2729. ((fboundp type)
  2730. (org-let2 gprops lprops
  2731. '(funcall type match)))
  2732. (t (error "Invalid type in command series")))))
  2733. (widen)
  2734. (let ((inhibit-read-only t))
  2735. (add-text-properties (point-min) (point-max)
  2736. `(org-series t org-series-redo-cmd ,redo)))
  2737. (setq org-agenda-redo-command redo)
  2738. (goto-char (point-min)))
  2739. (org-agenda-fit-window-to-buffer)
  2740. (org-let (nth 1 series) '(org-agenda-finalize)))
  2741. ;;;###autoload
  2742. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2743. "Run an agenda command in batch mode and send the result to STDOUT.
  2744. If CMD-KEY is a string of length 1, it is used as a key in
  2745. `org-agenda-custom-commands' and triggers this command. If it is a
  2746. longer string it is used as a tags/todo match string.
  2747. Parameters are alternating variable names and values that will be bound
  2748. before running the agenda command."
  2749. (org-eval-in-environment (org-make-parameter-alist parameters)
  2750. (if (> (length cmd-key) 2)
  2751. (org-tags-view nil cmd-key)
  2752. (org-agenda nil cmd-key)))
  2753. (set-buffer org-agenda-buffer-name)
  2754. (princ (buffer-string)))
  2755. (defvar org-agenda-info nil)
  2756. ;;;###autoload
  2757. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2758. "Run an agenda command in batch mode and send the result to STDOUT.
  2759. If CMD-KEY is a string of length 1, it is used as a key in
  2760. `org-agenda-custom-commands' and triggers this command. If it is a
  2761. longer string it is used as a tags/todo match string.
  2762. Parameters are alternating variable names and values that will be bound
  2763. before running the agenda command.
  2764. The output gives a line for each selected agenda item. Each
  2765. item is a list of comma-separated values, like this:
  2766. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2767. category The category of the item
  2768. head The headline, without TODO kwd, TAGS and PRIORITY
  2769. type The type of the agenda entry, can be
  2770. todo selected in TODO match
  2771. tagsmatch selected in tags match
  2772. diary imported from diary
  2773. deadline a deadline on given date
  2774. scheduled scheduled on given date
  2775. timestamp entry has timestamp on given date
  2776. closed entry was closed on given date
  2777. upcoming-deadline warning about deadline
  2778. past-scheduled forwarded scheduled item
  2779. block entry has date block including g. date
  2780. todo The todo keyword, if any
  2781. tags All tags including inherited ones, separated by colons
  2782. date The relevant date, like 2007-2-14
  2783. time The time, like 15:00-16:50
  2784. extra Sting with extra planning info
  2785. priority-l The priority letter if any was given
  2786. priority-n The computed numerical priority
  2787. agenda-day The day in the agenda where this is listed"
  2788. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2789. (org-make-parameter-alist parameters))
  2790. (if (> (length cmd-key) 2)
  2791. (org-tags-view nil cmd-key)
  2792. (org-agenda nil cmd-key)))
  2793. (set-buffer org-agenda-buffer-name)
  2794. (let* ((lines (org-split-string (buffer-string) "\n"))
  2795. line)
  2796. (while (setq line (pop lines))
  2797. (catch 'next
  2798. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2799. (setq org-agenda-info
  2800. (org-fix-agenda-info (text-properties-at 0 line)))
  2801. (princ
  2802. (mapconcat 'org-agenda-export-csv-mapper
  2803. '(org-category txt type todo tags date time extra
  2804. priority-letter priority agenda-day)
  2805. ","))
  2806. (princ "\n")))))
  2807. (defun org-fix-agenda-info (props)
  2808. "Make sure all properties on an agenda item have a canonical form.
  2809. This ensures the export commands can easily use it."
  2810. (let (tmp re)
  2811. (when (setq tmp (plist-get props 'tags))
  2812. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2813. (when (setq tmp (plist-get props 'date))
  2814. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2815. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2816. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2817. (setq tmp (calendar-date-string tmp)))
  2818. (setq props (plist-put props 'date tmp)))
  2819. (when (setq tmp (plist-get props 'day))
  2820. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2821. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2822. (setq tmp (calendar-date-string tmp)))
  2823. (setq props (plist-put props 'day tmp))
  2824. (setq props (plist-put props 'agenda-day tmp)))
  2825. (when (setq tmp (plist-get props 'txt))
  2826. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2827. (plist-put props 'priority-letter (match-string 1 tmp))
  2828. (setq tmp (replace-match "" t t tmp)))
  2829. (when (and (setq re (plist-get props 'org-todo-regexp))
  2830. (setq re (concat "\\`\\.*" re " ?"))
  2831. (string-match re tmp))
  2832. (plist-put props 'todo (match-string 1 tmp))
  2833. (setq tmp (replace-match "" t t tmp)))
  2834. (plist-put props 'txt tmp)))
  2835. props)
  2836. (defun org-agenda-export-csv-mapper (prop)
  2837. (let ((res (plist-get org-agenda-info prop)))
  2838. (setq res
  2839. (cond
  2840. ((not res) "")
  2841. ((stringp res) res)
  2842. (t (prin1-to-string res))))
  2843. (while (string-match "," res)
  2844. (setq res (replace-match ";" t t res)))
  2845. (org-trim res)))
  2846. ;;;###autoload
  2847. (defun org-store-agenda-views (&rest parameters)
  2848. (interactive)
  2849. (eval (list 'org-batch-store-agenda-views)))
  2850. ;;;###autoload
  2851. (defmacro org-batch-store-agenda-views (&rest parameters)
  2852. "Run all custom agenda commands that have a file argument."
  2853. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2854. (pop-up-frames nil)
  2855. (dir default-directory)
  2856. (pars (org-make-parameter-alist parameters))
  2857. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2858. (save-window-excursion
  2859. (while cmds
  2860. (setq cmd (pop cmds)
  2861. thiscmdkey (car cmd)
  2862. thiscmdcmd (cdr cmd)
  2863. match (nth 2 thiscmdcmd)
  2864. bufname (if org-agenda-sticky
  2865. (or (and (stringp match)
  2866. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2867. (format "*Org Agenda(%s)*" thiscmdkey))
  2868. org-agenda-buffer-name)
  2869. cmd-or-set (nth 2 cmd)
  2870. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2871. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2872. (if (stringp files) (setq files (list files)))
  2873. (when files
  2874. (org-eval-in-environment (append org-agenda-exporter-settings
  2875. opts pars)
  2876. (org-agenda nil thiscmdkey))
  2877. (set-buffer bufname)
  2878. (while files
  2879. (org-eval-in-environment (append org-agenda-exporter-settings
  2880. opts pars)
  2881. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2882. (and (get-buffer bufname)
  2883. (kill-buffer bufname)))))))
  2884. (defvar org-agenda-current-span nil
  2885. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2886. (defun org-agenda-mark-header-line (pos)
  2887. "Mark the line at POS as an agenda structure header."
  2888. (save-excursion
  2889. (goto-char pos)
  2890. (put-text-property (point-at-bol) (point-at-eol)
  2891. 'org-agenda-structural-header t)
  2892. (when org-agenda-title-append
  2893. (put-text-property (point-at-bol) (point-at-eol)
  2894. 'org-agenda-title-append org-agenda-title-append))))
  2895. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2896. (defvar org-agenda-write-buffer-name "Agenda View")
  2897. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2898. "Write the current buffer (an agenda view) as a file.
  2899. Depending on the extension of the file name, plain text (.txt),
  2900. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2901. If the extension is .ics, run icalendar export over all files used
  2902. to construct the agenda and limit the export to entries listed in the
  2903. agenda now.
  2904. If the extension is .org, collect all subtrees corresponding to the
  2905. agenda entries and add them in an .org file.
  2906. With prefix argument OPEN, open the new file immediately.
  2907. If NOSETTINGS is given, do not scope the settings of
  2908. `org-agenda-exporter-settings' into the export commands. This is used when
  2909. the settings have already been scoped and we do not wish to overrule other,
  2910. higher priority settings.
  2911. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2912. (interactive "FWrite agenda to file: \nP")
  2913. (if (not (file-writable-p file))
  2914. (error "Cannot write agenda to file %s" file))
  2915. (org-let (if nosettings nil org-agenda-exporter-settings)
  2916. '(save-excursion
  2917. (save-window-excursion
  2918. (org-agenda-mark-filtered-text)
  2919. (let ((bs (copy-sequence (buffer-string))) beg content)
  2920. (org-agenda-unmark-filtered-text)
  2921. (with-temp-buffer
  2922. (rename-buffer org-agenda-write-buffer-name t)
  2923. (set-buffer-modified-p nil)
  2924. (insert bs)
  2925. (org-agenda-remove-marked-text 'org-filtered)
  2926. (while (setq beg (text-property-any (point-min) (point-max)
  2927. 'org-filtered t))
  2928. (delete-region
  2929. beg (or (next-single-property-change beg 'org-filtered)
  2930. (point-max))))
  2931. (run-hooks 'org-agenda-before-write-hook)
  2932. (cond
  2933. ((org-bound-and-true-p org-mobile-creating-agendas)
  2934. (org-mobile-write-agenda-for-mobile file))
  2935. ((string-match "\\.org\\'" file)
  2936. (let (content p m message-log-max)
  2937. (goto-char (point-min))
  2938. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  2939. (goto-char p)
  2940. (setq m (get-text-property (point) 'org-hd-marker))
  2941. (when m
  2942. (push (save-excursion
  2943. (set-buffer (marker-buffer m))
  2944. (goto-char m)
  2945. (org-copy-subtree 1 nil t t)
  2946. org-subtree-clip)
  2947. content)))
  2948. (find-file file)
  2949. (erase-buffer)
  2950. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  2951. (write-file file)
  2952. (kill-buffer (current-buffer))
  2953. (message "Org file written to %s" file)))
  2954. ((string-match "\\.html?\\'" file)
  2955. (require 'htmlize)
  2956. (set-buffer (htmlize-buffer (current-buffer)))
  2957. (when org-agenda-export-html-style
  2958. ;; replace <style> section with org-agenda-export-html-style
  2959. (goto-char (point-min))
  2960. (kill-region (- (search-forward "<style") 6)
  2961. (search-forward "</style>"))
  2962. (insert org-agenda-export-html-style))
  2963. (write-file file)
  2964. (kill-buffer (current-buffer))
  2965. (message "HTML written to %s" file))
  2966. ((string-match "\\.ps\\'" file)
  2967. (require 'ps-print)
  2968. (ps-print-buffer-with-faces file)
  2969. (message "Postscript written to %s" file))
  2970. ((string-match "\\.pdf\\'" file)
  2971. (require 'ps-print)
  2972. (ps-print-buffer-with-faces
  2973. (concat (file-name-sans-extension file) ".ps"))
  2974. (call-process "ps2pdf" nil nil nil
  2975. (expand-file-name
  2976. (concat (file-name-sans-extension file) ".ps"))
  2977. (expand-file-name file))
  2978. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2979. (message "PDF written to %s" file))
  2980. ((string-match "\\.ics\\'" file)
  2981. (require 'ox-icalendar)
  2982. (org-icalendar-export-current-agenda (expand-file-name file)))
  2983. (t
  2984. (let ((bs (buffer-string)))
  2985. (find-file file)
  2986. (erase-buffer)
  2987. (insert bs)
  2988. (save-buffer 0)
  2989. (kill-buffer (current-buffer))
  2990. (message "Plain text written to %s" file))))))))
  2991. (set-buffer (or agenda-bufname
  2992. (and (org-called-interactively-p 'any) (buffer-name))
  2993. org-agenda-buffer-name)))
  2994. (when open (org-open-file file)))
  2995. (defvar org-agenda-tag-filter-overlays nil)
  2996. (defvar org-agenda-cat-filter-overlays nil)
  2997. (defun org-agenda-mark-filtered-text ()
  2998. "Mark all text hidden by filtering with a text property."
  2999. (let ((inhibit-read-only t))
  3000. (mapc
  3001. (lambda (o)
  3002. (when (equal (overlay-buffer o) (current-buffer))
  3003. (put-text-property
  3004. (overlay-start o) (overlay-end o)
  3005. 'org-filtered t)))
  3006. (append org-agenda-tag-filter-overlays
  3007. org-agenda-cat-filter-overlays))))
  3008. (defun org-agenda-unmark-filtered-text ()
  3009. "Remove the filtering text property."
  3010. (let ((inhibit-read-only t))
  3011. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3012. (defun org-agenda-remove-marked-text (property &optional value)
  3013. "Delete all text marked with VALUE of PROPERTY.
  3014. VALUE defaults to t."
  3015. (let (beg)
  3016. (setq value (or value t))
  3017. (while (setq beg (text-property-any (point-min) (point-max)
  3018. property value))
  3019. (delete-region
  3020. beg (or (next-single-property-change beg 'org-filtered)
  3021. (point-max))))))
  3022. (defun org-agenda-add-entry-text ()
  3023. "Add entry text to agenda lines.
  3024. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3025. entry text following headings shown in the agenda.
  3026. Drawers will be excluded, also the line with scheduling/deadline info."
  3027. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3028. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3029. (let (m txt)
  3030. (goto-char (point-min))
  3031. (while (not (eobp))
  3032. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3033. (beginning-of-line 2)
  3034. (setq txt (org-agenda-get-some-entry-text
  3035. m org-agenda-add-entry-text-maxlines " > "))
  3036. (end-of-line 1)
  3037. (if (string-match "\\S-" txt)
  3038. (insert "\n" txt)
  3039. (or (eobp) (forward-char 1))))))))
  3040. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3041. &rest keep)
  3042. "Extract entry text from MARKER, at most N-LINES lines.
  3043. This will ignore drawers etc, just get the text.
  3044. If INDENT is given, prefix every line with this string. If KEEP is
  3045. given, it is a list of symbols, defining stuff that should not be
  3046. removed from the entry content. Currently only `planning' is allowed here."
  3047. (let (txt drawer-re kwd-time-re ind)
  3048. (save-excursion
  3049. (with-current-buffer (marker-buffer marker)
  3050. (if (not (derived-mode-p 'org-mode))
  3051. (setq txt "")
  3052. (save-excursion
  3053. (save-restriction
  3054. (widen)
  3055. (goto-char marker)
  3056. (end-of-line 1)
  3057. (setq txt (buffer-substring
  3058. (min (1+ (point)) (point-max))
  3059. (progn (outline-next-heading) (point)))
  3060. drawer-re org-drawer-regexp
  3061. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3062. ".*\n?"))
  3063. (with-temp-buffer
  3064. (insert txt)
  3065. (when org-agenda-add-entry-text-descriptive-links
  3066. (goto-char (point-min))
  3067. (while (org-activate-bracket-links (point-max))
  3068. (add-text-properties (match-beginning 0) (match-end 0)
  3069. '(face org-link))))
  3070. (goto-char (point-min))
  3071. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3072. (set-text-properties (match-beginning 0) (match-end 0)
  3073. nil))
  3074. (goto-char (point-min))
  3075. (while (re-search-forward drawer-re nil t)
  3076. (delete-region
  3077. (match-beginning 0)
  3078. (progn (re-search-forward
  3079. "^[ \t]*:END:.*\n?" nil 'move)
  3080. (point))))
  3081. (unless (member 'planning keep)
  3082. (goto-char (point-min))
  3083. (while (re-search-forward kwd-time-re nil t)
  3084. (replace-match "")))
  3085. (goto-char (point-min))
  3086. (when org-agenda-entry-text-exclude-regexps
  3087. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3088. (while (setq re (pop re-list))
  3089. (goto-char (point-min))
  3090. (while (re-search-forward re nil t)
  3091. (replace-match "")))))
  3092. (goto-char (point-max))
  3093. (skip-chars-backward " \t\n")
  3094. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3095. ;; find and remove min common indentation
  3096. (goto-char (point-min))
  3097. (untabify (point-min) (point-max))
  3098. (setq ind (org-get-indentation))
  3099. (while (not (eobp))
  3100. (unless (looking-at "[ \t]*$")
  3101. (setq ind (min ind (org-get-indentation))))
  3102. (beginning-of-line 2))
  3103. (goto-char (point-min))
  3104. (while (not (eobp))
  3105. (unless (looking-at "[ \t]*$")
  3106. (move-to-column ind)
  3107. (delete-region (point-at-bol) (point)))
  3108. (beginning-of-line 2))
  3109. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3110. (goto-char (point-min))
  3111. (when indent
  3112. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3113. (replace-match indent t t)))
  3114. (goto-char (point-min))
  3115. (while (looking-at "[ \t]*\n") (replace-match ""))
  3116. (goto-char (point-max))
  3117. (when (> (org-current-line)
  3118. n-lines)
  3119. (org-goto-line (1+ n-lines))
  3120. (backward-char 1))
  3121. (setq txt (buffer-substring (point-min) (point)))))))))
  3122. txt))
  3123. (defun org-agenda-collect-markers ()
  3124. "Collect the markers pointing to entries in the agenda buffer."
  3125. (let (m markers)
  3126. (save-excursion
  3127. (goto-char (point-min))
  3128. (while (not (eobp))
  3129. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3130. (org-get-at-bol 'org-marker)))
  3131. (push m markers))
  3132. (beginning-of-line 2)))
  3133. (nreverse markers)))
  3134. (defun org-create-marker-find-array (marker-list)
  3135. "Create a alist of files names with all marker positions in that file."
  3136. (let (f tbl m a p)
  3137. (while (setq m (pop marker-list))
  3138. (setq p (marker-position m)
  3139. f (buffer-file-name (or (buffer-base-buffer
  3140. (marker-buffer m))
  3141. (marker-buffer m))))
  3142. (if (setq a (assoc f tbl))
  3143. (push (marker-position m) (cdr a))
  3144. (push (list f p) tbl)))
  3145. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3146. tbl)))
  3147. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3148. (defun org-check-agenda-marker-table ()
  3149. "Check of the current entry is on the marker list."
  3150. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3151. a)
  3152. (and (setq a (assoc file org-agenda-marker-table))
  3153. (save-match-data
  3154. (save-excursion
  3155. (org-back-to-heading t)
  3156. (member (point) (cdr a)))))))
  3157. (defun org-check-for-org-mode ()
  3158. "Make sure current buffer is in org-mode. Error if not."
  3159. (or (derived-mode-p 'org-mode)
  3160. (error "Cannot execute org-mode agenda command on buffer in %s"
  3161. major-mode)))
  3162. ;;; Agenda prepare and finalize
  3163. (defvar org-agenda-multi nil) ; dynamically scoped
  3164. (defvar org-agenda-pre-window-conf nil)
  3165. (defvar org-agenda-columns-active nil)
  3166. (defvar org-agenda-name nil)
  3167. (defvar org-agenda-tag-filter nil)
  3168. (defvar org-agenda-category-filter nil)
  3169. (defvar org-agenda-top-category-filter nil)
  3170. (defvar org-agenda-tag-filter-while-redo nil)
  3171. (defvar org-agenda-tag-filter-preset nil
  3172. "A preset of the tags filter used for secondary agenda filtering.
  3173. This must be a list of strings, each string must be a single tag preceded
  3174. by \"+\" or \"-\".
  3175. This variable should not be set directly, but agenda custom commands can
  3176. bind it in the options section. The preset filter is a global property of
  3177. the entire agenda view. In a block agenda, it will not work reliably to
  3178. define a filter for one of the individual blocks. You need to set it in
  3179. the global options and expect it to be applied to the entire view.")
  3180. (defvar org-agenda-category-filter-preset nil
  3181. "A preset of the category filter used for secondary agenda filtering.
  3182. This must be a list of strings, each string must be a single category
  3183. preceded by \"+\" or \"-\".
  3184. This variable should not be set directly, but agenda custom commands can
  3185. bind it in the options section. The preset filter is a global property of
  3186. the entire agenda view. In a block agenda, it will not work reliably to
  3187. define a filter for one of the individual blocks. You need to set it in
  3188. the global options and expect it to be applied to the entire view.")
  3189. (defun org-agenda-use-sticky-p ()
  3190. "Return non-nil if an agenda buffer named
  3191. `org-agenda-buffer-name' exists and should be shown instead of
  3192. generating a new one."
  3193. (and
  3194. ;; turned off by user
  3195. org-agenda-sticky
  3196. ;; For multi-agenda buffer already exists
  3197. (not org-agenda-multi)
  3198. ;; buffer found
  3199. (get-buffer org-agenda-buffer-name)
  3200. ;; C-u parameter is same as last call
  3201. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3202. (and
  3203. (equal current-prefix-arg
  3204. org-agenda-last-prefix-arg)
  3205. ;; In case user turned stickiness on, while having existing
  3206. ;; Agenda buffer active, don't reuse that buffer, because it
  3207. ;; does not have org variables local
  3208. org-agenda-this-buffer-is-sticky))))
  3209. (defun org-agenda-prepare-window (abuf)
  3210. "Setup agenda buffer in the window."
  3211. (let* ((awin (get-buffer-window abuf))
  3212. wconf)
  3213. (cond
  3214. ((equal (current-buffer) abuf) nil)
  3215. (awin (select-window awin))
  3216. ((not (setq wconf (current-window-configuration))))
  3217. ((equal org-agenda-window-setup 'current-window)
  3218. (org-pop-to-buffer-same-window abuf))
  3219. ((equal org-agenda-window-setup 'other-window)
  3220. (org-switch-to-buffer-other-window abuf))
  3221. ((equal org-agenda-window-setup 'other-frame)
  3222. (switch-to-buffer-other-frame abuf))
  3223. ((equal org-agenda-window-setup 'reorganize-frame)
  3224. (delete-other-windows)
  3225. (org-switch-to-buffer-other-window abuf)))
  3226. ;; additional test in case agenda is invoked from within agenda
  3227. ;; buffer via elisp link
  3228. (unless (equal (current-buffer) abuf)
  3229. (org-pop-to-buffer-same-window abuf))
  3230. (setq org-agenda-pre-window-conf
  3231. (or org-agenda-pre-window-conf wconf))))
  3232. (defun org-agenda-prepare (&optional name)
  3233. (if (org-agenda-use-sticky-p)
  3234. (progn
  3235. ;; Popup existing buffer
  3236. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3237. (message "Sticky Agenda buffer, use `r' to refresh")
  3238. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3239. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3240. (setq org-todo-keywords-for-agenda nil)
  3241. (setq org-drawers-for-agenda nil)
  3242. (unless org-agenda-persistent-filter
  3243. (setq org-agenda-tag-filter nil
  3244. org-agenda-category-filter nil))
  3245. (put 'org-agenda-tag-filter :preset-filter
  3246. org-agenda-tag-filter-preset)
  3247. (put 'org-agenda-category-filter :preset-filter
  3248. org-agenda-category-filter-preset)
  3249. (if org-agenda-multi
  3250. (progn
  3251. (setq buffer-read-only nil)
  3252. (goto-char (point-max))
  3253. (unless (or (bobp) org-agenda-compact-blocks
  3254. (not org-agenda-block-separator))
  3255. (insert "\n"
  3256. (if (stringp org-agenda-block-separator)
  3257. org-agenda-block-separator
  3258. (make-string (window-width) org-agenda-block-separator))
  3259. "\n"))
  3260. (narrow-to-region (point) (point-max)))
  3261. (setq org-done-keywords-for-agenda nil)
  3262. ;; Setting any org variables that are in org-agenda-local-vars
  3263. ;; list need to be done after the prepare call
  3264. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3265. (setq buffer-read-only nil)
  3266. (org-agenda-reset-markers)
  3267. (let ((inhibit-read-only t)) (erase-buffer))
  3268. (org-agenda-mode)
  3269. (setq org-agenda-buffer (current-buffer))
  3270. (setq org-agenda-contributing-files nil)
  3271. (setq org-agenda-columns-active nil)
  3272. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3273. (setq org-todo-keywords-for-agenda
  3274. (org-uniquify org-todo-keywords-for-agenda))
  3275. (setq org-done-keywords-for-agenda
  3276. (org-uniquify org-done-keywords-for-agenda))
  3277. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3278. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3279. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3280. (and name (not org-agenda-name)
  3281. (org-set-local 'org-agenda-name name)))
  3282. (setq buffer-read-only nil)))
  3283. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3284. (defun org-agenda-finalize ()
  3285. "Finishing touch for the agenda buffer, called just before displaying it."
  3286. (unless org-agenda-multi
  3287. (save-excursion
  3288. (let ((inhibit-read-only t))
  3289. (goto-char (point-min))
  3290. (save-excursion
  3291. (while (org-activate-bracket-links (point-max))
  3292. (add-text-properties (match-beginning 0) (match-end 0)
  3293. '(face org-link))))
  3294. (save-excursion
  3295. (while (org-activate-plain-links (point-max))
  3296. (add-text-properties (match-beginning 0) (match-end 0)
  3297. '(face org-link))))
  3298. (unless (eq org-agenda-remove-tags t)
  3299. (org-agenda-align-tags))
  3300. (unless org-agenda-with-colors
  3301. (remove-text-properties (point-min) (point-max) '(face nil)))
  3302. (if (and (boundp 'org-agenda-overriding-columns-format)
  3303. org-agenda-overriding-columns-format)
  3304. (org-set-local 'org-agenda-overriding-columns-format
  3305. org-agenda-overriding-columns-format))
  3306. (if (and (boundp 'org-agenda-view-columns-initially)
  3307. org-agenda-view-columns-initially)
  3308. (org-agenda-columns))
  3309. (when org-agenda-fontify-priorities
  3310. (org-agenda-fontify-priorities))
  3311. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3312. (org-agenda-dim-blocked-tasks))
  3313. ;; We need to widen when `org-agenda-finalize' is called from
  3314. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3315. (when org-clock-current-task
  3316. (save-restriction
  3317. (widen)
  3318. (org-agenda-mark-clocking-task)))
  3319. (when org-agenda-entry-text-mode
  3320. (org-agenda-entry-text-hide)
  3321. (org-agenda-entry-text-show))
  3322. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3323. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3324. (org-habit-insert-consistency-graphs))
  3325. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3326. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3327. (and (listp org-agenda-show-inherited-tags)
  3328. (memq org-agenda-type org-agenda-show-inherited-tags))
  3329. (and (eq org-agenda-show-inherited-tags t)
  3330. (or (eq org-agenda-use-tag-inheritance t)
  3331. (and (listp org-agenda-use-tag-inheritance)
  3332. (not (memq org-agenda-type
  3333. org-agenda-use-tag-inheritance))))))
  3334. (let (mrk)
  3335. (save-excursion
  3336. (goto-char (point-min))
  3337. (while (equal (forward-line) 0)
  3338. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3339. (get-text-property (point) 'org-hd-marker)))
  3340. (put-text-property (point-at-bol) (point-at-eol)
  3341. 'tags (org-with-point-at mrk
  3342. (delete-dups
  3343. (mapcar 'downcase (org-get-tags-at))))))))))
  3344. (run-hooks 'org-agenda-finalize-hook)
  3345. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3346. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3347. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3348. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3349. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3350. (defun org-agenda-mark-clocking-task ()
  3351. "Mark the current clock entry in the agenda if it is present."
  3352. (org-agenda-unmark-clocking-task)
  3353. (when (marker-buffer org-clock-hd-marker)
  3354. (save-excursion
  3355. (goto-char (point-min))
  3356. (let (s ov)
  3357. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3358. (goto-char s)
  3359. (when (equal (org-get-at-bol 'org-hd-marker)
  3360. org-clock-hd-marker)
  3361. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3362. (overlay-put ov 'type 'org-agenda-clocking)
  3363. (overlay-put ov 'face 'org-agenda-clocking)
  3364. (overlay-put ov 'help-echo
  3365. "The clock is running in this item")))))))
  3366. (defun org-agenda-unmark-clocking-task ()
  3367. "Unmark the current clocking task."
  3368. (mapc (lambda (o)
  3369. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3370. (delete-overlay o)))
  3371. (overlays-in (point-min) (point-max))))
  3372. (defun org-agenda-fontify-priorities ()
  3373. "Make highest priority lines bold, and lowest italic."
  3374. (interactive)
  3375. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3376. (delete-overlay o)))
  3377. (overlays-in (point-min) (point-max)))
  3378. (save-excursion
  3379. (let (b e p ov h l)
  3380. (goto-char (point-min))
  3381. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3382. (setq h (or (get-char-property (point) 'org-highest-priority)
  3383. org-highest-priority)
  3384. l (or (get-char-property (point) 'org-lowest-priority)
  3385. org-lowest-priority)
  3386. p (string-to-char (match-string 1))
  3387. b (match-beginning 0)
  3388. e (if (eq org-agenda-fontify-priorities 'cookies)
  3389. (match-end 0)
  3390. (point-at-eol))
  3391. ov (make-overlay b e))
  3392. (overlay-put
  3393. ov 'face
  3394. (cons (cond ((org-face-from-face-or-color
  3395. 'priority nil
  3396. (cdr (assoc p org-priority-faces))))
  3397. ((and (listp org-agenda-fontify-priorities)
  3398. (org-face-from-face-or-color
  3399. 'priority nil
  3400. (cdr (assoc p org-agenda-fontify-priorities)))))
  3401. ((equal p l) 'italic)
  3402. ((equal p h) 'bold))
  3403. 'org-priority))
  3404. (overlay-put ov 'org-type 'org-priority)))))
  3405. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3406. (interactive "P")
  3407. "Dim currently blocked TODO's in the agenda display."
  3408. (message "Dim or hide blocked tasks...")
  3409. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3410. (delete-overlay o)))
  3411. (overlays-in (point-min) (point-max)))
  3412. (save-excursion
  3413. (let ((inhibit-read-only t)
  3414. (org-depend-tag-blocked nil)
  3415. (invis (or (not (null invisible))
  3416. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3417. org-blocked-by-checkboxes
  3418. invis1 b e p ov h l)
  3419. (goto-char (point-min))
  3420. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3421. (and pos (goto-char (1+ pos))))
  3422. (setq org-blocked-by-checkboxes nil invis1 invis)
  3423. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3424. (when (and marker
  3425. (with-current-buffer (marker-buffer marker)
  3426. (save-excursion (goto-char marker)
  3427. (org-entry-blocked-p))))
  3428. (if org-blocked-by-checkboxes (setq invis1 nil))
  3429. (setq b (if invis1
  3430. (max (point-min) (1- (point-at-bol)))
  3431. (point-at-bol))
  3432. e (point-at-eol)
  3433. ov (make-overlay b e))
  3434. (if invis1
  3435. (overlay-put ov 'invisible t)
  3436. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3437. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3438. (message "Dim or hide blocked tasks...done"))
  3439. (defvar org-agenda-skip-function nil
  3440. "Function to be called at each match during agenda construction.
  3441. If this function returns nil, the current match should not be skipped.
  3442. Otherwise, the function must return a position from where the search
  3443. should be continued.
  3444. This may also be a Lisp form, it will be evaluated.
  3445. Never set this variable using `setq' or so, because then it will apply
  3446. to all future agenda commands. If you do want a global skipping condition,
  3447. use the option `org-agenda-skip-function-global' instead.
  3448. The correct usage for `org-agenda-skip-function' is to bind it with
  3449. `let' to scope it dynamically into the agenda-constructing command.
  3450. A good way to set it is through options in `org-agenda-custom-commands'.")
  3451. (defun org-agenda-skip ()
  3452. "Throw to `:skip' in places that should be skipped.
  3453. Also moves point to the end of the skipped region, so that search can
  3454. continue from there."
  3455. (let ((p (point-at-bol)) to)
  3456. (when (or
  3457. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3458. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3459. (get-text-property p :org-archived)
  3460. (org-end-of-subtree t))
  3461. (and org-agenda-skip-comment-trees
  3462. (get-text-property p :org-comment)
  3463. (org-end-of-subtree t))
  3464. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3465. (org-agenda-skip-eval org-agenda-skip-function)))
  3466. (goto-char to))
  3467. (org-in-src-block-p t))
  3468. (throw :skip t))))
  3469. (defun org-agenda-skip-eval (form)
  3470. "If FORM is a function or a list, call (or eval) is and return result.
  3471. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3472. and match data are returned to the previous state no matter what these
  3473. functions do."
  3474. (let (fp)
  3475. (and form
  3476. (or (setq fp (functionp form))
  3477. (consp form))
  3478. (save-excursion
  3479. (save-match-data
  3480. (if fp
  3481. (funcall form)
  3482. (eval form)))))))
  3483. (defvar org-agenda-markers nil
  3484. "List of all currently active markers created by `org-agenda'.")
  3485. (defvar org-agenda-last-marker-time (org-float-time)
  3486. "Creation time of the last agenda marker.")
  3487. (defun org-agenda-new-marker (&optional pos)
  3488. "Return a new agenda marker.
  3489. Org-mode keeps a list of these markers and resets them when they are
  3490. no longer in use."
  3491. (let ((m (copy-marker (or pos (point)))))
  3492. (setq org-agenda-last-marker-time (org-float-time))
  3493. (if org-agenda-buffer
  3494. (with-current-buffer org-agenda-buffer
  3495. (push m org-agenda-markers))
  3496. (push m org-agenda-markers))
  3497. m))
  3498. (defun org-agenda-reset-markers ()
  3499. "Reset markers created by `org-agenda'."
  3500. (while org-agenda-markers
  3501. (move-marker (pop org-agenda-markers) nil)))
  3502. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3503. "Save relative positions of markers in region.
  3504. This check for agenda markers in all agenda buffers currently active."
  3505. (dolist (buf (buffer-list))
  3506. (with-current-buffer buf
  3507. (when (eq major-mode 'org-agenda-mode)
  3508. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3509. org-agenda-markers)))))
  3510. ;;; Entry text mode
  3511. (defun org-agenda-entry-text-show-here ()
  3512. "Add some text from the entry as context to the current line."
  3513. (let (m txt o)
  3514. (setq m (org-get-at-bol 'org-hd-marker))
  3515. (unless (marker-buffer m)
  3516. (error "No marker points to an entry here"))
  3517. (setq txt (concat "\n" (org-no-properties
  3518. (org-agenda-get-some-entry-text
  3519. m org-agenda-entry-text-maxlines " > "))))
  3520. (when (string-match "\\S-" txt)
  3521. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3522. (overlay-put o 'evaporate t)
  3523. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3524. (overlay-put o 'after-string txt))))
  3525. (defun org-agenda-entry-text-show ()
  3526. "Add entry context for all agenda lines."
  3527. (interactive)
  3528. (save-excursion
  3529. (goto-char (point-max))
  3530. (beginning-of-line 1)
  3531. (while (not (bobp))
  3532. (when (org-get-at-bol 'org-hd-marker)
  3533. (org-agenda-entry-text-show-here))
  3534. (beginning-of-line 0))))
  3535. (defun org-agenda-entry-text-hide ()
  3536. "Remove any shown entry context."
  3537. (delq nil
  3538. (mapcar (lambda (o)
  3539. (if (eq (overlay-get o 'org-overlay-type)
  3540. 'agenda-entry-content)
  3541. (progn (delete-overlay o) t)))
  3542. (overlays-in (point-min) (point-max)))))
  3543. (defun org-agenda-get-day-face (date)
  3544. "Return the face DATE should be displayed with."
  3545. (or (and (functionp org-agenda-day-face-function)
  3546. (funcall org-agenda-day-face-function date))
  3547. (cond ((org-agenda-todayp date)
  3548. 'org-agenda-date-today)
  3549. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3550. 'org-agenda-date-weekend)
  3551. (t 'org-agenda-date))))
  3552. ;;; Agenda timeline
  3553. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3554. (defun org-timeline (&optional dotodo)
  3555. "Show a time-sorted view of the entries in the current org file.
  3556. Only entries with a time stamp of today or later will be listed. With
  3557. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3558. under the current date.
  3559. If the buffer contains an active region, only check the region for
  3560. dates."
  3561. (interactive "P")
  3562. (let* ((dopast t)
  3563. (org-agenda-show-log-scoped org-agenda-show-log)
  3564. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3565. (current-buffer))))
  3566. (date (calendar-current-date))
  3567. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3568. (end (if (org-region-active-p) (region-end) (point-max)))
  3569. (day-numbers (org-get-all-dates
  3570. beg end 'no-ranges
  3571. t org-agenda-show-log-scoped ; always include today
  3572. org-timeline-show-empty-dates))
  3573. (org-deadline-warning-days 0)
  3574. (org-agenda-only-exact-dates t)
  3575. (today (org-today))
  3576. (past t)
  3577. args
  3578. s e rtn d emptyp)
  3579. (setq org-agenda-redo-command
  3580. (list 'progn
  3581. (list 'org-switch-to-buffer-other-window (current-buffer))
  3582. (list 'org-timeline (list 'quote dotodo))))
  3583. (if (not dopast)
  3584. ;; Remove past dates from the list of dates.
  3585. (setq day-numbers (delq nil (mapcar (lambda(x)
  3586. (if (>= x today) x nil))
  3587. day-numbers))))
  3588. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3589. (org-compile-prefix-format 'timeline)
  3590. (org-set-sorting-strategy 'timeline)
  3591. (if org-agenda-show-log-scoped (push :closed args))
  3592. (push :timestamp args)
  3593. (push :deadline args)
  3594. (push :scheduled args)
  3595. (push :sexp args)
  3596. (if dotodo (push :todo args))
  3597. (insert "Timeline of file " entry "\n")
  3598. (add-text-properties (point-min) (point)
  3599. (list 'face 'org-agenda-structure))
  3600. (org-agenda-mark-header-line (point-min))
  3601. (while (setq d (pop day-numbers))
  3602. (if (and (listp d) (eq (car d) :omitted))
  3603. (progn
  3604. (setq s (point))
  3605. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3606. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3607. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3608. (if (and (>= d today)
  3609. dopast
  3610. past)
  3611. (progn
  3612. (setq past nil)
  3613. (insert (make-string 79 ?-) "\n")))
  3614. (setq date (calendar-gregorian-from-absolute d))
  3615. (setq s (point))
  3616. (setq rtn (and (not emptyp)
  3617. (apply 'org-agenda-get-day-entries entry
  3618. date args)))
  3619. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3620. (progn
  3621. (insert
  3622. (if (stringp org-agenda-format-date)
  3623. (format-time-string org-agenda-format-date
  3624. (org-time-from-absolute date))
  3625. (funcall org-agenda-format-date date))
  3626. "\n")
  3627. (put-text-property s (1- (point)) 'face
  3628. (org-agenda-get-day-face date))
  3629. (put-text-property s (1- (point)) 'org-date-line t)
  3630. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3631. (if (equal d today)
  3632. (put-text-property s (1- (point)) 'org-today t))
  3633. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3634. (put-text-property s (1- (point)) 'day d)))))
  3635. (goto-char (point-min))
  3636. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3637. (point-min)))
  3638. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3639. (org-agenda-finalize)
  3640. (setq buffer-read-only t)))
  3641. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3642. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3643. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3644. not every single day in the range. If FORCE-TODAY is non-nil, make
  3645. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3646. inactive time stamps (those in square brackets) are included.
  3647. When EMPTY is non-nil, also include days without any entries."
  3648. (let ((re (concat
  3649. (if pre-re pre-re "")
  3650. (if inactive org-ts-regexp-both org-ts-regexp)))
  3651. dates dates1 date day day1 day2 ts1 ts2 pos)
  3652. (if force-today
  3653. (setq dates (list (org-today))))
  3654. (save-excursion
  3655. (goto-char beg)
  3656. (while (re-search-forward re end t)
  3657. (setq day (time-to-days (org-time-string-to-time
  3658. (substring (match-string 1) 0 10)
  3659. (current-buffer) (match-beginning 0))))
  3660. (or (memq day dates) (push day dates)))
  3661. (unless no-ranges
  3662. (goto-char beg)
  3663. (while (re-search-forward org-tr-regexp end t)
  3664. (setq pos (match-beginning 0))
  3665. (setq ts1 (substring (match-string 1) 0 10)
  3666. ts2 (substring (match-string 2) 0 10)
  3667. day1 (time-to-days (org-time-string-to-time
  3668. ts1 (current-buffer) pos))
  3669. day2 (time-to-days (org-time-string-to-time
  3670. ts2 (current-buffer) pos)))
  3671. (while (< (setq day1 (1+ day1)) day2)
  3672. (or (memq day1 dates) (push day1 dates)))))
  3673. (setq dates (sort dates '<))
  3674. (when empty
  3675. (while (setq day (pop dates))
  3676. (setq day2 (car dates))
  3677. (push day dates1)
  3678. (when (and day2 empty)
  3679. (if (or (eq empty t)
  3680. (and (numberp empty) (<= (- day2 day) empty)))
  3681. (while (< (setq day (1+ day)) day2)
  3682. (push (list day) dates1))
  3683. (push (cons :omitted (- day2 day)) dates1))))
  3684. (setq dates (nreverse dates1)))
  3685. dates)))
  3686. ;;; Agenda Daily/Weekly
  3687. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3688. "Start day for the agenda view.
  3689. Custom commands can set this variable in the options section.
  3690. See the docstring of `org-read-date' on allowed values.")
  3691. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3692. (defvar org-arg-loc nil) ; local variable
  3693. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3694. "List of types searched for when creating the daily/weekly agenda.
  3695. This variable is a list of symbols that controls the types of
  3696. items that appear in the daily/weekly agenda. Allowed symbols in this
  3697. list are are
  3698. :timestamp List items containing a date stamp or date range matching
  3699. the selected date. This includes sexp entries in
  3700. angular brackets.
  3701. :sexp List entries resulting from plain diary-like sexps.
  3702. :deadline List deadline due on that date. When the date is today,
  3703. also list any deadlines past due, or due within
  3704. `org-deadline-warning-days'. `:deadline' must appear before
  3705. `:scheduled' if the setting of
  3706. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3707. any effect.
  3708. :scheduled List all items which are scheduled for the given date.
  3709. The diary for *today* also contains items which were
  3710. scheduled earlier and are not yet marked DONE.
  3711. By default, all four types are turned on.
  3712. Never set this variable globally using `setq', because then it
  3713. will apply to all future agenda commands. Instead, bind it with
  3714. `let' to scope it dynamically into the agenda-constructing
  3715. command. A good way to set it is through options in
  3716. `org-agenda-custom-commands'. For a more flexible (though
  3717. somewhat less efficient) way of determining what is included in
  3718. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3719. (defvar org-agenda-buffer-tmp-name nil)
  3720. ;;;###autoload
  3721. (defun org-agenda-list (&optional arg start-day span)
  3722. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3723. The view will be for the current day or week, but from the overview buffer
  3724. you will be able to go to other days/weeks.
  3725. With a numeric prefix argument in an interactive call, the agenda will
  3726. span ARG days. Lisp programs should instead specify SPAN to change
  3727. the number of days. SPAN defaults to `org-agenda-span'.
  3728. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3729. given in `org-agenda-start-on-weekday'."
  3730. (interactive "P")
  3731. (if org-agenda-overriding-arguments
  3732. (setq arg (car org-agenda-overriding-arguments)
  3733. start-day (nth 1 org-agenda-overriding-arguments)
  3734. span (nth 2 org-agenda-overriding-arguments)))
  3735. (if (and (integerp arg) (> arg 0))
  3736. (setq span arg arg nil))
  3737. (catch 'exit
  3738. (setq org-agenda-buffer-name
  3739. (or org-agenda-buffer-tmp-name
  3740. (if org-agenda-sticky
  3741. (cond ((and org-keys (stringp org-match))
  3742. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3743. (org-keys
  3744. (format "*Org Agenda(%s)*" org-keys))
  3745. (t "*Org Agenda(a)*")))
  3746. org-agenda-buffer-name))
  3747. (org-agenda-prepare "Day/Week")
  3748. (setq start-day (or start-day org-agenda-start-day))
  3749. (if (stringp start-day)
  3750. ;; Convert to an absolute day number
  3751. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3752. (org-compile-prefix-format 'agenda)
  3753. (org-set-sorting-strategy 'agenda)
  3754. (let* ((span (org-agenda-ndays-to-span
  3755. (or span org-agenda-ndays org-agenda-span)))
  3756. (today (org-today))
  3757. (sd (or start-day today))
  3758. (ndays (org-agenda-span-to-ndays span sd))
  3759. (org-agenda-start-on-weekday
  3760. (if (eq ndays 7)
  3761. org-agenda-start-on-weekday))
  3762. (thefiles (org-agenda-files nil 'ifmode))
  3763. (files thefiles)
  3764. (start (if (or (null org-agenda-start-on-weekday)
  3765. (< ndays 7))
  3766. sd
  3767. (let* ((nt (calendar-day-of-week
  3768. (calendar-gregorian-from-absolute sd)))
  3769. (n1 org-agenda-start-on-weekday)
  3770. (d (- nt n1)))
  3771. (- sd (+ (if (< d 0) 7 0) d)))))
  3772. (day-numbers (list start))
  3773. (day-cnt 0)
  3774. (inhibit-redisplay (not debug-on-error))
  3775. (org-agenda-show-log-scoped org-agenda-show-log)
  3776. s e rtn rtnall file date d start-pos end-pos todayp
  3777. clocktable-start clocktable-end filter)
  3778. (setq org-agenda-redo-command
  3779. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3780. (dotimes (n (1- ndays))
  3781. (push (1+ (car day-numbers)) day-numbers))
  3782. (setq day-numbers (nreverse day-numbers))
  3783. (setq clocktable-start (car day-numbers)
  3784. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3785. (org-set-local 'org-starting-day (car day-numbers))
  3786. (org-set-local 'org-arg-loc arg)
  3787. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3788. (unless org-agenda-compact-blocks
  3789. (let* ((d1 (car day-numbers))
  3790. (d2 (org-last day-numbers))
  3791. (w1 (org-days-to-iso-week d1))
  3792. (w2 (org-days-to-iso-week d2)))
  3793. (setq s (point))
  3794. (if org-agenda-overriding-header
  3795. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3796. nil 'face 'org-agenda-structure) "\n")
  3797. (insert (org-agenda-span-name span)
  3798. "-agenda"
  3799. (if (< (- d2 d1) 350)
  3800. (if (= w1 w2)
  3801. (format " (W%02d)" w1)
  3802. (format " (W%02d-W%02d)" w1 w2))
  3803. "")
  3804. ":\n")))
  3805. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3806. 'org-date-line t))
  3807. (org-agenda-mark-header-line s))
  3808. (while (setq d (pop day-numbers))
  3809. (setq date (calendar-gregorian-from-absolute d)
  3810. s (point))
  3811. (if (or (setq todayp (= d today))
  3812. (and (not start-pos) (= d sd)))
  3813. (setq start-pos (point))
  3814. (if (and start-pos (not end-pos))
  3815. (setq end-pos (point))))
  3816. (setq files thefiles
  3817. rtnall nil)
  3818. (while (setq file (pop files))
  3819. (catch 'nextfile
  3820. (org-check-agenda-file file)
  3821. (let ((org-agenda-entry-types org-agenda-entry-types))
  3822. (unless org-agenda-include-deadlines
  3823. (setq org-agenda-entry-types
  3824. (delq :deadline org-agenda-entry-types)))
  3825. (cond
  3826. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3827. (setq rtn (org-agenda-get-day-entries
  3828. file date :closed)))
  3829. (org-agenda-show-log-scoped
  3830. (setq rtn (apply 'org-agenda-get-day-entries
  3831. file date
  3832. (append '(:closed) org-agenda-entry-types))))
  3833. (t
  3834. (setq rtn (apply 'org-agenda-get-day-entries
  3835. file date
  3836. org-agenda-entry-types)))))
  3837. (setq rtnall (append rtnall rtn)))) ;; all entries
  3838. (if org-agenda-include-diary
  3839. (let ((org-agenda-search-headline-for-time t))
  3840. (require 'diary-lib)
  3841. (setq rtn (org-get-entries-from-diary date))
  3842. (setq rtnall (append rtnall rtn))))
  3843. (if (or rtnall org-agenda-show-all-dates)
  3844. (progn
  3845. (setq day-cnt (1+ day-cnt))
  3846. (insert
  3847. (if (stringp org-agenda-format-date)
  3848. (format-time-string org-agenda-format-date
  3849. (org-time-from-absolute date))
  3850. (funcall org-agenda-format-date date))
  3851. "\n")
  3852. (put-text-property s (1- (point)) 'face
  3853. (org-agenda-get-day-face date))
  3854. (put-text-property s (1- (point)) 'org-date-line t)
  3855. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3856. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3857. (when todayp
  3858. (put-text-property s (1- (point)) 'org-today t))
  3859. (setq rtnall
  3860. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3861. (if rtnall (insert ;; all entries
  3862. (org-agenda-finalize-entries rtnall 'agenda)
  3863. "\n"))
  3864. (put-text-property s (1- (point)) 'day d)
  3865. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3866. (when (and org-agenda-clockreport-mode clocktable-start)
  3867. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3868. ;; the above line is to ensure the restricted range!
  3869. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3870. tbl)
  3871. (setq p (org-plist-delete p :block))
  3872. (setq p (plist-put p :tstart clocktable-start))
  3873. (setq p (plist-put p :tend clocktable-end))
  3874. (setq p (plist-put p :scope 'agenda))
  3875. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3876. (setq filter (or org-agenda-tag-filter-while-redo
  3877. (get 'org-agenda-tag-filter :preset-filter))))
  3878. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3879. (if (string-match "[<>=]" x)
  3880. ""
  3881. x))
  3882. filter ""))))
  3883. (setq tbl (apply 'org-clock-get-clocktable p))
  3884. (insert tbl)))
  3885. (goto-char (point-min))
  3886. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3887. (unless (and (pos-visible-in-window-p (point-min))
  3888. (pos-visible-in-window-p (point-max)))
  3889. (goto-char (1- (point-max)))
  3890. (recenter -1)
  3891. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3892. (progn
  3893. (goto-char (or start-pos 1))
  3894. (recenter 1))))
  3895. (goto-char (or start-pos 1))
  3896. (add-text-properties (point-min) (point-max)
  3897. `(org-agenda-type agenda
  3898. org-last-args (,arg ,start-day ,span)
  3899. org-redo-cmd ,org-agenda-redo-command
  3900. org-series-cmd ,org-cmd))
  3901. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3902. (org-agenda-show-clocking-issues))
  3903. (org-agenda-finalize)
  3904. (setq buffer-read-only t)
  3905. (message ""))))
  3906. (defun org-agenda-ndays-to-span (n)
  3907. "Return a span symbol for a span of N days, or N if none matches."
  3908. (cond ((symbolp n) n)
  3909. ((= n 1) 'day)
  3910. ((= n 7) 'week)
  3911. (t n)))
  3912. (defun org-agenda-span-to-ndays (span &optional start-day)
  3913. "Return ndays from SPAN, possibly starting at START-DAY."
  3914. (cond ((numberp span) span)
  3915. ((eq span 'day) 1)
  3916. ((eq span 'week) 7)
  3917. ((eq span 'month)
  3918. (let ((date (calendar-gregorian-from-absolute start-day)))
  3919. (calendar-last-day-of-month (car date) (caddr date))))
  3920. ((eq span 'year)
  3921. (let ((date (calendar-gregorian-from-absolute start-day)))
  3922. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3923. (defun org-agenda-span-name (span)
  3924. "Return a SPAN name."
  3925. (if (null span)
  3926. ""
  3927. (if (symbolp span)
  3928. (capitalize (symbol-name span))
  3929. (format "%d days" span))))
  3930. ;;; Agenda word search
  3931. (defvar org-agenda-search-history nil)
  3932. (defvar org-search-syntax-table nil
  3933. "Special syntax table for org-mode search.
  3934. In this table, we have single quotes not as word constituents, to
  3935. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3936. (defvar org-mode-syntax-table) ; From org.el
  3937. (defun org-search-syntax-table ()
  3938. (unless org-search-syntax-table
  3939. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3940. (modify-syntax-entry ?' "." org-search-syntax-table)
  3941. (modify-syntax-entry ?` "." org-search-syntax-table))
  3942. org-search-syntax-table)
  3943. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3944. ;;;###autoload
  3945. (defun org-search-view (&optional todo-only string edit-at)
  3946. "Show all entries that contain a phrase or words or regular expressions.
  3947. With optional prefix argument TODO-ONLY, only consider entries that are
  3948. TODO entries. The argument STRING can be used to pass a default search
  3949. string into this function. If EDIT-AT is non-nil, it means that the
  3950. user should get a chance to edit this string, with cursor at position
  3951. EDIT-AT.
  3952. The search string can be viewed either as a phrase that should be found as
  3953. is, or it can be broken into a number of snippets, each of which must match
  3954. in a Boolean way to select an entry. The default depends on the variable
  3955. `org-agenda-search-view-always-boolean'.
  3956. Even if this is turned off (the default) you can always switch to
  3957. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3958. The default is a direct search of the whole phrase, where each space in
  3959. the search string can expand to an arbitrary amount of whitespace,
  3960. including newlines.
  3961. If using a Boolean search, the search string is split on whitespace and
  3962. each snippet is searched separately, with logical AND to select an entry.
  3963. Words prefixed with a minus must *not* occur in the entry. Words without
  3964. a prefix or prefixed with a plus must occur in the entry. Matching is
  3965. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3966. match whole words, not parts of a word) if
  3967. `org-agenda-search-view-force-full-words' is set (default is nil).
  3968. Boolean search snippets enclosed by curly braces are interpreted as
  3969. regular expressions that must or (when preceded with \"-\") must not
  3970. match in the entry. Snippets enclosed into double quotes will be taken
  3971. as a whole, to include whitespace.
  3972. - If the search string starts with an asterisk, search only in headlines.
  3973. - If (possibly after the leading star) the search string starts with an
  3974. exclamation mark, this also means to look at TODO entries only, an effect
  3975. that can also be achieved with a prefix argument.
  3976. - If (possibly after star and exclamation mark) the search string starts
  3977. with a colon, this will mean that the (non-regexp) snippets of the
  3978. Boolean search must match as full words.
  3979. This command searches the agenda files, and in addition the files listed
  3980. in `org-agenda-text-search-extra-files'."
  3981. (interactive "P")
  3982. (if org-agenda-overriding-arguments
  3983. (setq todo-only (car org-agenda-overriding-arguments)
  3984. string (nth 1 org-agenda-overriding-arguments)
  3985. edit-at (nth 2 org-agenda-overriding-arguments)))
  3986. (let* ((props (list 'face nil
  3987. 'done-face 'org-agenda-done
  3988. 'org-not-done-regexp org-not-done-regexp
  3989. 'org-todo-regexp org-todo-regexp
  3990. 'org-complex-heading-regexp org-complex-heading-regexp
  3991. 'mouse-face 'highlight
  3992. 'help-echo (format "mouse-2 or RET jump to location")))
  3993. (full-words org-agenda-search-view-force-full-words)
  3994. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3995. regexp rtn rtnall files file pos inherited-tags
  3996. marker category category-pos level tags c neg re boolean
  3997. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3998. (unless (and (not edit-at)
  3999. (stringp string)
  4000. (string-match "\\S-" string))
  4001. (setq string (read-string
  4002. (if org-agenda-search-view-always-boolean
  4003. "[+-]Word/{Regexp} ...: "
  4004. "Phrase or [+-]Word/{Regexp} ...: ")
  4005. (cond
  4006. ((integerp edit-at) (cons string edit-at))
  4007. (edit-at string))
  4008. 'org-agenda-search-history)))
  4009. (catch 'exit
  4010. (if org-agenda-sticky
  4011. (setq org-agenda-buffer-name
  4012. (if (stringp string)
  4013. (format "*Org Agenda(%s:%s)*"
  4014. (or org-keys (or (and todo-only "S") "s")) string)
  4015. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4016. (org-agenda-prepare "SEARCH")
  4017. (org-compile-prefix-format 'search)
  4018. (org-set-sorting-strategy 'search)
  4019. (setq org-agenda-redo-command
  4020. (list 'org-search-view (if todo-only t nil)
  4021. (list 'if 'current-prefix-arg nil string)))
  4022. (setq org-agenda-query-string string)
  4023. (if (equal (string-to-char string) ?*)
  4024. (setq hdl-only t
  4025. words (substring string 1))
  4026. (setq words string))
  4027. (when (equal (string-to-char words) ?!)
  4028. (setq todo-only t
  4029. words (substring words 1)))
  4030. (when (equal (string-to-char words) ?:)
  4031. (setq full-words t
  4032. words (substring words 1)))
  4033. (if (or org-agenda-search-view-always-boolean
  4034. (member (string-to-char words) '(?- ?+ ?\{)))
  4035. (setq boolean t))
  4036. (setq words (org-split-string words))
  4037. (let (www w)
  4038. (while (setq w (pop words))
  4039. (while (and (string-match "\\\\\\'" w) words)
  4040. (setq w (concat (substring w 0 -1) " " (pop words))))
  4041. (push w www))
  4042. (setq words (nreverse www) www nil)
  4043. (while (setq w (pop words))
  4044. (when (and (string-match "\\`[-+]?{" w)
  4045. (not (string-match "}\\'" w)))
  4046. (while (and words (not (string-match "}\\'" (car words))))
  4047. (setq w (concat w " " (pop words))))
  4048. (setq w (concat w " " (pop words))))
  4049. (push w www))
  4050. (setq words (nreverse www)))
  4051. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4052. (when boolean
  4053. (let (wds w)
  4054. (while (setq w (pop words))
  4055. (if (or (equal (substring w 0 1) "\"")
  4056. (and (> (length w) 1)
  4057. (member (substring w 0 1) '("+" "-"))
  4058. (equal (substring w 1 2) "\"")))
  4059. (while (and words (not (equal (substring w -1) "\"")))
  4060. (setq w (concat w " " (pop words)))))
  4061. (and (string-match "\\`\\([-+]?\\)\"" w)
  4062. (setq w (replace-match "\\1" nil nil w)))
  4063. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4064. (push w wds))
  4065. (setq words (nreverse wds))))
  4066. (if boolean
  4067. (mapc (lambda (w)
  4068. (setq c (string-to-char w))
  4069. (if (equal c ?-)
  4070. (setq neg t w (substring w 1))
  4071. (if (equal c ?+)
  4072. (setq neg nil w (substring w 1))
  4073. (setq neg nil)))
  4074. (if (string-match "\\`{.*}\\'" w)
  4075. (setq re (substring w 1 -1))
  4076. (if full-words
  4077. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4078. (setq re (regexp-quote (downcase w)))))
  4079. (if neg (push re regexps-) (push re regexps+)))
  4080. words)
  4081. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4082. regexps+))
  4083. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4084. (if (not regexps+)
  4085. (setq regexp org-outline-regexp-bol)
  4086. (setq regexp (pop regexps+))
  4087. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4088. regexp))))
  4089. (setq files (org-agenda-files nil 'ifmode))
  4090. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4091. (pop org-agenda-text-search-extra-files)
  4092. (setq files (org-add-archive-files files)))
  4093. (setq files (append files org-agenda-text-search-extra-files)
  4094. rtnall nil)
  4095. (while (setq file (pop files))
  4096. (setq ee nil)
  4097. (catch 'nextfile
  4098. (org-check-agenda-file file)
  4099. (setq buffer (if (file-exists-p file)
  4100. (org-get-agenda-file-buffer file)
  4101. (error "No such file %s" file)))
  4102. (if (not buffer)
  4103. ;; If file does not exist, make sure an error message is sent
  4104. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4105. file))))
  4106. (with-current-buffer buffer
  4107. (with-syntax-table (org-search-syntax-table)
  4108. (unless (derived-mode-p 'org-mode)
  4109. (error "Agenda file %s is not in `org-mode'" file))
  4110. (let ((case-fold-search t))
  4111. (save-excursion
  4112. (save-restriction
  4113. (if org-agenda-restrict
  4114. (narrow-to-region org-agenda-restrict-begin
  4115. org-agenda-restrict-end)
  4116. (widen))
  4117. (goto-char (point-min))
  4118. (unless (or (org-at-heading-p)
  4119. (outline-next-heading))
  4120. (throw 'nextfile t))
  4121. (goto-char (max (point-min) (1- (point))))
  4122. (while (re-search-forward regexp nil t)
  4123. (org-back-to-heading t)
  4124. (while (and org-agenda-search-view-max-outline-level
  4125. (> (org-reduced-level (org-outline-level))
  4126. org-agenda-search-view-max-outline-level)
  4127. (forward-line -1)
  4128. (outline-back-to-heading t)))
  4129. (skip-chars-forward "* ")
  4130. (setq beg (point-at-bol)
  4131. beg1 (point)
  4132. end (progn
  4133. (outline-next-heading)
  4134. (while (and org-agenda-search-view-max-outline-level
  4135. (> (org-reduced-level (org-outline-level))
  4136. org-agenda-search-view-max-outline-level)
  4137. (forward-line 1)
  4138. (outline-next-heading)))
  4139. (point)))
  4140. (catch :skip
  4141. (goto-char beg)
  4142. (org-agenda-skip)
  4143. (setq str (buffer-substring-no-properties
  4144. (point-at-bol)
  4145. (if hdl-only (point-at-eol) end)))
  4146. (mapc (lambda (wr) (when (string-match wr str)
  4147. (goto-char (1- end))
  4148. (throw :skip t)))
  4149. regexps-)
  4150. (mapc (lambda (wr) (unless (string-match wr str)
  4151. (goto-char (1- end))
  4152. (throw :skip t)))
  4153. (if todo-only
  4154. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4155. regexps+)
  4156. regexps+))
  4157. (goto-char beg)
  4158. (setq marker (org-agenda-new-marker (point))
  4159. category (org-get-category)
  4160. level (make-string (org-reduced-level (org-outline-level)) ? )
  4161. category-pos (get-text-property (point) 'org-category-position)
  4162. inherited-tags
  4163. (or (eq org-agenda-show-inherited-tags 'always)
  4164. (and (listp org-agenda-show-inherited-tags)
  4165. (memq 'todo org-agenda-show-inherited-tags))
  4166. (and (eq org-agenda-show-inherited-tags t)
  4167. (or (eq org-agenda-use-tag-inheritance t)
  4168. (memq 'todo org-agenda-use-tag-inheritance))))
  4169. tags (org-get-tags-at nil (not inherited-tags))
  4170. txt (org-agenda-format-item
  4171. ""
  4172. (buffer-substring-no-properties
  4173. beg1 (point-at-eol))
  4174. level category tags t))
  4175. (org-add-props txt props
  4176. 'org-marker marker 'org-hd-marker marker
  4177. 'org-todo-regexp org-todo-regexp
  4178. 'level level
  4179. 'org-complex-heading-regexp org-complex-heading-regexp
  4180. 'priority 1000 'org-category category
  4181. 'org-category-position category-pos
  4182. 'type "search")
  4183. (push txt ee)
  4184. (goto-char (1- end))))))))))
  4185. (setq rtn (nreverse ee))
  4186. (setq rtnall (append rtnall rtn)))
  4187. (if org-agenda-overriding-header
  4188. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4189. nil 'face 'org-agenda-structure) "\n")
  4190. (insert "Search words: ")
  4191. (add-text-properties (point-min) (1- (point))
  4192. (list 'face 'org-agenda-structure))
  4193. (setq pos (point))
  4194. (insert string "\n")
  4195. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4196. (setq pos (point))
  4197. (unless org-agenda-multi
  4198. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4199. (add-text-properties pos (1- (point))
  4200. (list 'face 'org-agenda-structure))))
  4201. (org-agenda-mark-header-line (point-min))
  4202. (when rtnall
  4203. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4204. (goto-char (point-min))
  4205. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4206. (add-text-properties (point-min) (point-max)
  4207. `(org-agenda-type search
  4208. org-last-args (,todo-only ,string ,edit-at)
  4209. org-redo-cmd ,org-agenda-redo-command
  4210. org-series-cmd ,org-cmd))
  4211. (org-agenda-finalize)
  4212. (setq buffer-read-only t))))
  4213. ;;; Agenda TODO list
  4214. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4215. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4216. (concat
  4217. (if (or (equal keywords "ALL") (not keywords))
  4218. (propertize "ALL" 'face 'warning)
  4219. (mapconcat
  4220. (lambda (kw)
  4221. (propertize kw 'face (org-get-todo-face kw)))
  4222. (org-split-string keywords "|")
  4223. "|"))
  4224. "\n"))
  4225. (defvar org-select-this-todo-keyword nil)
  4226. (defvar org-last-arg nil)
  4227. ;;;###autoload
  4228. (defun org-todo-list (&optional arg)
  4229. "Show all (not done) TODO entries from all agenda file in a single list.
  4230. The prefix arg can be used to select a specific TODO keyword and limit
  4231. the list to these. When using \\[universal-argument], you will be prompted
  4232. for a keyword. A numeric prefix directly selects the Nth keyword in
  4233. `org-todo-keywords-1'."
  4234. (interactive "P")
  4235. (if org-agenda-overriding-arguments
  4236. (setq arg org-agenda-overriding-arguments))
  4237. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4238. (let* ((today (org-today))
  4239. (date (calendar-gregorian-from-absolute today))
  4240. (kwds org-todo-keywords-for-agenda)
  4241. (completion-ignore-case t)
  4242. (org-select-this-todo-keyword
  4243. (if (stringp arg) arg
  4244. (and arg (integerp arg) (> arg 0)
  4245. (nth (1- arg) kwds))))
  4246. rtn rtnall files file pos)
  4247. (when (equal arg '(4))
  4248. (setq org-select-this-todo-keyword
  4249. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4250. (mapcar 'list kwds) nil nil)))
  4251. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4252. (catch 'exit
  4253. (if org-agenda-sticky
  4254. (setq org-agenda-buffer-name
  4255. (if (stringp org-select-this-todo-keyword)
  4256. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4257. org-select-this-todo-keyword)
  4258. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4259. (org-agenda-prepare "TODO")
  4260. (org-compile-prefix-format 'todo)
  4261. (org-set-sorting-strategy 'todo)
  4262. (setq org-agenda-redo-command
  4263. `(org-todo-list (or (and (numberp current-prefix-arg)
  4264. current-prefix-arg)
  4265. ,org-select-this-todo-keyword
  4266. current-prefix-arg ,arg)))
  4267. (setq files (org-agenda-files nil 'ifmode)
  4268. rtnall nil)
  4269. (while (setq file (pop files))
  4270. (catch 'nextfile
  4271. (org-check-agenda-file file)
  4272. (setq rtn (org-agenda-get-day-entries file date :todo))
  4273. (setq rtnall (append rtnall rtn))))
  4274. (if org-agenda-overriding-header
  4275. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4276. nil 'face 'org-agenda-structure) "\n")
  4277. (insert "Global list of TODO items of type: ")
  4278. (add-text-properties (point-min) (1- (point))
  4279. (list 'face 'org-agenda-structure
  4280. 'short-heading
  4281. (concat "ToDo: "
  4282. (or org-select-this-todo-keyword "ALL"))))
  4283. (org-agenda-mark-header-line (point-min))
  4284. (insert (org-agenda-propertize-selected-todo-keywords
  4285. org-select-this-todo-keyword))
  4286. (setq pos (point))
  4287. (unless org-agenda-multi
  4288. (insert "Available with `N r': (0)[ALL]")
  4289. (let ((n 0) s)
  4290. (mapc (lambda (x)
  4291. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4292. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4293. (insert "\n "))
  4294. (insert " " s))
  4295. kwds))
  4296. (insert "\n"))
  4297. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4298. (org-agenda-mark-header-line (point-min))
  4299. (when rtnall
  4300. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4301. (goto-char (point-min))
  4302. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4303. (add-text-properties (point-min) (point-max)
  4304. `(org-agenda-type todo
  4305. org-last-args ,arg
  4306. org-redo-cmd ,org-agenda-redo-command
  4307. org-series-cmd ,org-cmd))
  4308. (org-agenda-finalize)
  4309. (setq buffer-read-only t))))
  4310. ;;; Agenda tags match
  4311. ;;;###autoload
  4312. (defun org-tags-view (&optional todo-only match)
  4313. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4314. The prefix arg TODO-ONLY limits the search to TODO entries."
  4315. (interactive "P")
  4316. (if org-agenda-overriding-arguments
  4317. (setq todo-only (car org-agenda-overriding-arguments)
  4318. match (nth 1 org-agenda-overriding-arguments)))
  4319. (let* ((org-tags-match-list-sublevels
  4320. org-tags-match-list-sublevels)
  4321. (completion-ignore-case t)
  4322. rtn rtnall files file pos matcher
  4323. buffer)
  4324. (when (and (stringp match) (not (string-match "\\S-" match)))
  4325. (setq match nil))
  4326. (setq matcher (org-make-tags-matcher match)
  4327. match (car matcher) matcher (cdr matcher))
  4328. (catch 'exit
  4329. (if org-agenda-sticky
  4330. (setq org-agenda-buffer-name
  4331. (if (stringp match)
  4332. (format "*Org Agenda(%s:%s)*"
  4333. (or org-keys (or (and todo-only "M") "m")) match)
  4334. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4335. (org-agenda-prepare (concat "TAGS " match))
  4336. (org-compile-prefix-format 'tags)
  4337. (org-set-sorting-strategy 'tags)
  4338. (setq org-agenda-query-string match)
  4339. (setq org-agenda-redo-command
  4340. (list 'org-tags-view `(quote ,todo-only)
  4341. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4342. (setq files (org-agenda-files nil 'ifmode)
  4343. rtnall nil)
  4344. (while (setq file (pop files))
  4345. (catch 'nextfile
  4346. (org-check-agenda-file file)
  4347. (setq buffer (if (file-exists-p file)
  4348. (org-get-agenda-file-buffer file)
  4349. (error "No such file %s" file)))
  4350. (if (not buffer)
  4351. ;; If file does not exist, error message to agenda
  4352. (setq rtn (list
  4353. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4354. rtnall (append rtnall rtn))
  4355. (with-current-buffer buffer
  4356. (unless (derived-mode-p 'org-mode)
  4357. (error "Agenda file %s is not in `org-mode'" file))
  4358. (save-excursion
  4359. (save-restriction
  4360. (if org-agenda-restrict
  4361. (narrow-to-region org-agenda-restrict-begin
  4362. org-agenda-restrict-end)
  4363. (widen))
  4364. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4365. (setq rtnall (append rtnall rtn))))))))
  4366. (if org-agenda-overriding-header
  4367. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4368. nil 'face 'org-agenda-structure) "\n")
  4369. (insert "Headlines with TAGS match: ")
  4370. (add-text-properties (point-min) (1- (point))
  4371. (list 'face 'org-agenda-structure
  4372. 'short-heading
  4373. (concat "Match: " match)))
  4374. (setq pos (point))
  4375. (insert match "\n")
  4376. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4377. (setq pos (point))
  4378. (unless org-agenda-multi
  4379. (insert "Press `C-u r' to search again with new search string\n"))
  4380. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4381. (org-agenda-mark-header-line (point-min))
  4382. (when rtnall
  4383. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4384. (goto-char (point-min))
  4385. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4386. (add-text-properties (point-min) (point-max)
  4387. `(org-agenda-type tags
  4388. org-last-args (,todo-only ,match)
  4389. org-redo-cmd ,org-agenda-redo-command
  4390. org-series-cmd ,org-cmd))
  4391. (org-agenda-finalize)
  4392. (setq buffer-read-only t))))
  4393. ;;; Agenda Finding stuck projects
  4394. (defvar org-agenda-skip-regexp nil
  4395. "Regular expression used in skipping subtrees for the agenda.
  4396. This is basically a temporary global variable that can be set and then
  4397. used by user-defined selections using `org-agenda-skip-function'.")
  4398. (defvar org-agenda-overriding-header nil
  4399. "When set during agenda, todo and tags searches it replaces the header.
  4400. This variable should not be set directly, but custom commands can bind it
  4401. in the options section.")
  4402. (defun org-agenda-skip-entry-when-regexp-matches ()
  4403. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4404. If yes, it returns the end position of this entry, causing agenda commands
  4405. to skip the entry but continuing the search in the subtree. This is a
  4406. function that can be put into `org-agenda-skip-function' for the duration
  4407. of a command."
  4408. (let ((end (save-excursion (org-end-of-subtree t)))
  4409. skip)
  4410. (save-excursion
  4411. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4412. (and skip end)))
  4413. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4414. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4415. If yes, it returns the end position of this tree, causing agenda commands
  4416. to skip this subtree. This is a function that can be put into
  4417. `org-agenda-skip-function' for the duration of a command."
  4418. (let ((end (save-excursion (org-end-of-subtree t)))
  4419. skip)
  4420. (save-excursion
  4421. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4422. (and skip end)))
  4423. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4424. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4425. If yes, it returns the end position of the current entry (NOT the tree),
  4426. causing agenda commands to skip the entry but continuing the search in
  4427. the subtree. This is a function that can be put into
  4428. `org-agenda-skip-function' for the duration of a command. An important
  4429. use of this function is for the stuck project list."
  4430. (let ((end (save-excursion (org-end-of-subtree t)))
  4431. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4432. skip)
  4433. (save-excursion
  4434. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4435. (and skip entry-end)))
  4436. (defun org-agenda-skip-entry-if (&rest conditions)
  4437. "Skip entry if any of CONDITIONS is true.
  4438. See `org-agenda-skip-if' for details."
  4439. (org-agenda-skip-if nil conditions))
  4440. (defun org-agenda-skip-subtree-if (&rest conditions)
  4441. "Skip entry if any of CONDITIONS is true.
  4442. See `org-agenda-skip-if' for details."
  4443. (org-agenda-skip-if t conditions))
  4444. (defun org-agenda-skip-if (subtree conditions)
  4445. "Checks current entity for CONDITIONS.
  4446. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4447. the entry (i.e. the text before the next heading) is checked.
  4448. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4449. from different tests. Valid conditions are:
  4450. scheduled Check if there is a scheduled cookie
  4451. notscheduled Check if there is no scheduled cookie
  4452. deadline Check if there is a deadline
  4453. notdeadline Check if there is no deadline
  4454. timestamp Check if there is a timestamp (also deadline or scheduled)
  4455. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4456. regexp Check if regexp matches
  4457. notregexp Check if regexp does not match.
  4458. todo Check if TODO keyword matches
  4459. nottodo Check if TODO keyword does not match
  4460. The regexp is taken from the conditions list, it must come right after
  4461. the `regexp' or `notregexp' element.
  4462. `todo' and `nottodo' accept as an argument a list of todo
  4463. keywords, which may include \"*\" to match any todo keyword.
  4464. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4465. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4466. Instead of a list, a keyword class may be given. For example:
  4467. (org-agenda-skip-entry-if 'nottodo 'done)
  4468. would skip entries that haven't been marked with any of \"DONE\"
  4469. keywords. Possible classes are: `todo', `done', `any'.
  4470. If any of these conditions is met, this function returns the end point of
  4471. the entity, causing the search to continue from there. This is a function
  4472. that can be put into `org-agenda-skip-function' for the duration of a command."
  4473. (let (beg end m)
  4474. (org-back-to-heading t)
  4475. (setq beg (point)
  4476. end (if subtree
  4477. (progn (org-end-of-subtree t) (point))
  4478. (progn (outline-next-heading) (1- (point)))))
  4479. (goto-char beg)
  4480. (and
  4481. (or
  4482. (and (memq 'scheduled conditions)
  4483. (re-search-forward org-scheduled-time-regexp end t))
  4484. (and (memq 'notscheduled conditions)
  4485. (not (re-search-forward org-scheduled-time-regexp end t)))
  4486. (and (memq 'deadline conditions)
  4487. (re-search-forward org-deadline-time-regexp end t))
  4488. (and (memq 'notdeadline conditions)
  4489. (not (re-search-forward org-deadline-time-regexp end t)))
  4490. (and (memq 'timestamp conditions)
  4491. (re-search-forward org-ts-regexp end t))
  4492. (and (memq 'nottimestamp conditions)
  4493. (not (re-search-forward org-ts-regexp end t)))
  4494. (and (setq m (memq 'regexp conditions))
  4495. (stringp (nth 1 m))
  4496. (re-search-forward (nth 1 m) end t))
  4497. (and (setq m (memq 'notregexp conditions))
  4498. (stringp (nth 1 m))
  4499. (not (re-search-forward (nth 1 m) end t)))
  4500. (and (or
  4501. (setq m (memq 'nottodo conditions))
  4502. (setq m (memq 'todo-unblocked conditions))
  4503. (setq m (memq 'nottodo-unblocked conditions))
  4504. (setq m (memq 'todo conditions)))
  4505. (org-agenda-skip-if-todo m end)))
  4506. end)))
  4507. (defun org-agenda-skip-if-todo (args end)
  4508. "Helper function for `org-agenda-skip-if', do not use it directly.
  4509. ARGS is a list with first element either `todo', `nottodo',
  4510. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4511. a list of TODO keywords, or a state symbol `todo' or `done' or
  4512. `any'."
  4513. (let ((kw (car args))
  4514. (arg (cadr args))
  4515. todo-wds todo-re)
  4516. (setq todo-wds
  4517. (org-uniquify
  4518. (cond
  4519. ((listp arg) ;; list of keywords
  4520. (if (member "*" arg)
  4521. (mapcar 'substring-no-properties org-todo-keywords-1)
  4522. arg))
  4523. ((symbolp arg) ;; keyword class name
  4524. (cond
  4525. ((eq arg 'todo)
  4526. (org-delete-all org-done-keywords
  4527. (mapcar 'substring-no-properties
  4528. org-todo-keywords-1)))
  4529. ((eq arg 'done) org-done-keywords)
  4530. ((eq arg 'any)
  4531. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4532. (setq todo-re
  4533. (concat "^\\*+[ \t]+\\<\\("
  4534. (mapconcat 'identity todo-wds "\\|")
  4535. "\\)\\>"))
  4536. (cond
  4537. ((eq kw 'todo) (re-search-forward todo-re end t))
  4538. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4539. ((eq kw 'todo-unblocked)
  4540. (catch 'unblocked
  4541. (while (re-search-forward todo-re end t)
  4542. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4543. nil))
  4544. ((eq kw 'nottodo-unblocked)
  4545. (catch 'unblocked
  4546. (while (re-search-forward todo-re end t)
  4547. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4548. t))
  4549. )))
  4550. ;;;###autoload
  4551. (defun org-agenda-list-stuck-projects (&rest ignore)
  4552. "Create agenda view for projects that are stuck.
  4553. Stuck projects are project that have no next actions. For the definitions
  4554. of what a project is and how to check if it stuck, customize the variable
  4555. `org-stuck-projects'."
  4556. (interactive)
  4557. (let* ((org-agenda-skip-function
  4558. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4559. ;; We could have used org-agenda-skip-if here.
  4560. (org-agenda-overriding-header
  4561. (or org-agenda-overriding-header "List of stuck projects: "))
  4562. (matcher (nth 0 org-stuck-projects))
  4563. (todo (nth 1 org-stuck-projects))
  4564. (todo-wds (if (member "*" todo)
  4565. (progn
  4566. (org-agenda-prepare-buffers (org-agenda-files
  4567. nil 'ifmode))
  4568. (org-delete-all
  4569. org-done-keywords-for-agenda
  4570. (copy-sequence org-todo-keywords-for-agenda)))
  4571. todo))
  4572. (todo-re (concat "^\\*+[ \t]+\\("
  4573. (mapconcat 'identity todo-wds "\\|")
  4574. "\\)\\>"))
  4575. (tags (nth 2 org-stuck-projects))
  4576. (tags-re (if (member "*" tags)
  4577. (concat org-outline-regexp-bol
  4578. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4579. (if tags
  4580. (concat org-outline-regexp-bol
  4581. ".*:\\("
  4582. (mapconcat 'identity tags "\\|")
  4583. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4584. (gen-re (nth 3 org-stuck-projects))
  4585. (re-list
  4586. (delq nil
  4587. (list
  4588. (if todo todo-re)
  4589. (if tags tags-re)
  4590. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4591. gen-re)))))
  4592. (setq org-agenda-skip-regexp
  4593. (if re-list
  4594. (mapconcat 'identity re-list "\\|")
  4595. (error "No information how to identify unstuck projects")))
  4596. (org-tags-view nil matcher)
  4597. (with-current-buffer org-agenda-buffer-name
  4598. (setq org-agenda-redo-command
  4599. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4600. ;;; Diary integration
  4601. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4602. (defvar diary-list-entries-hook)
  4603. (defvar diary-time-regexp)
  4604. (defun org-get-entries-from-diary (date)
  4605. "Get the (Emacs Calendar) diary entries for DATE."
  4606. (require 'diary-lib)
  4607. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4608. (diary-display-hook '(fancy-diary-display))
  4609. (diary-display-function 'fancy-diary-display)
  4610. (pop-up-frames nil)
  4611. (diary-list-entries-hook
  4612. (cons 'org-diary-default-entry diary-list-entries-hook))
  4613. (diary-file-name-prefix nil) ; turn this feature off
  4614. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4615. entries
  4616. (org-disable-agenda-to-diary t))
  4617. (save-excursion
  4618. (save-window-excursion
  4619. (funcall (if (fboundp 'diary-list-entries)
  4620. 'diary-list-entries 'list-diary-entries)
  4621. date 1)))
  4622. (if (not (get-buffer diary-fancy-buffer))
  4623. (setq entries nil)
  4624. (with-current-buffer diary-fancy-buffer
  4625. (setq buffer-read-only nil)
  4626. (if (zerop (buffer-size))
  4627. ;; No entries
  4628. (setq entries nil)
  4629. ;; Omit the date and other unnecessary stuff
  4630. (org-agenda-cleanup-fancy-diary)
  4631. ;; Add prefix to each line and extend the text properties
  4632. (if (zerop (buffer-size))
  4633. (setq entries nil)
  4634. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4635. (setq entries
  4636. (with-temp-buffer
  4637. (insert entries) (goto-char (point-min))
  4638. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4639. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4640. (replace-match (concat "; " (match-string 1)))))
  4641. (buffer-string)))))
  4642. (set-buffer-modified-p nil)
  4643. (kill-buffer diary-fancy-buffer)))
  4644. (when entries
  4645. (setq entries (org-split-string entries "\n"))
  4646. (setq entries
  4647. (mapcar
  4648. (lambda (x)
  4649. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4650. ;; Extend the text properties to the beginning of the line
  4651. (org-add-props x (text-properties-at (1- (length x)) x)
  4652. 'type "diary" 'date date 'face 'org-agenda-diary))
  4653. entries)))))
  4654. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4655. "Hook run when the fancy diary buffer is cleaned up.")
  4656. (defun org-agenda-cleanup-fancy-diary ()
  4657. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4658. This gets rid of the date, the underline under the date, and
  4659. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4660. date. It also removes lines that contain only whitespace."
  4661. (goto-char (point-min))
  4662. (if (looking-at ".*?:[ \t]*")
  4663. (progn
  4664. (replace-match "")
  4665. (re-search-forward "\n=+$" nil t)
  4666. (replace-match "")
  4667. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4668. (re-search-forward "\n=+$" nil t)
  4669. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4670. (goto-char (point-min))
  4671. (while (re-search-forward "^ +\n" nil t)
  4672. (replace-match ""))
  4673. (goto-char (point-min))
  4674. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4675. (replace-match ""))
  4676. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4677. ;; Make sure entries from the diary have the right text properties.
  4678. (eval-after-load "diary-lib"
  4679. '(if (boundp 'diary-modify-entry-list-string-function)
  4680. ;; We can rely on the hook, nothing to do
  4681. nil
  4682. ;; Hook not available, must use advice to make this work
  4683. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4684. "Make the position visible."
  4685. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4686. (stringp string)
  4687. buffer-file-name)
  4688. (setq string (org-modify-diary-entry-string string))))))
  4689. (defun org-modify-diary-entry-string (string)
  4690. "Add text properties to string, allowing org-mode to act on it."
  4691. (org-add-props string nil
  4692. 'mouse-face 'highlight
  4693. 'help-echo (if buffer-file-name
  4694. (format "mouse-2 or RET jump to diary file %s"
  4695. (abbreviate-file-name buffer-file-name))
  4696. "")
  4697. 'org-agenda-diary-link t
  4698. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4699. (defun org-diary-default-entry ()
  4700. "Add a dummy entry to the diary.
  4701. Needed to avoid empty dates which mess up holiday display."
  4702. ;; Catch the error if dealing with the new add-to-diary-alist
  4703. (when org-disable-agenda-to-diary
  4704. (condition-case nil
  4705. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4706. (error
  4707. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4708. (defun org-add-to-diary-list (&rest args)
  4709. (if (fboundp 'diary-add-to-list)
  4710. (apply 'diary-add-to-list args)
  4711. (apply 'add-to-diary-list args)))
  4712. (defvar org-diary-last-run-time nil)
  4713. ;;;###autoload
  4714. (defun org-diary (&rest args)
  4715. "Return diary information from org files.
  4716. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4717. It accesses org files and extracts information from those files to be
  4718. listed in the diary. The function accepts arguments specifying what
  4719. items should be listed. For a list of arguments allowed here, see the
  4720. variable `org-agenda-entry-types'.
  4721. The call in the diary file should look like this:
  4722. &%%(org-diary) ~/path/to/some/orgfile.org
  4723. Use a separate line for each org file to check. Or, if you omit the file name,
  4724. all files listed in `org-agenda-files' will be checked automatically:
  4725. &%%(org-diary)
  4726. If you don't give any arguments (as in the example above), the default
  4727. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4728. So the example above may also be written as
  4729. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4730. The function expects the lisp variables `entry' and `date' to be provided
  4731. by the caller, because this is how the calendar works. Don't use this
  4732. function from a program - use `org-agenda-get-day-entries' instead."
  4733. (when (> (- (org-float-time)
  4734. org-agenda-last-marker-time)
  4735. 5)
  4736. ;; I am not sure if this works with sticky agendas, because the marker
  4737. ;; list is then no longer a global variable.
  4738. (org-agenda-reset-markers))
  4739. (org-compile-prefix-format 'agenda)
  4740. (org-set-sorting-strategy 'agenda)
  4741. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4742. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4743. (list entry)
  4744. (org-agenda-files t)))
  4745. (time (org-float-time))
  4746. file rtn results)
  4747. (when (or (not org-diary-last-run-time)
  4748. (> (- time
  4749. org-diary-last-run-time)
  4750. 3))
  4751. (org-agenda-prepare-buffers files))
  4752. (setq org-diary-last-run-time time)
  4753. ;; If this is called during org-agenda, don't return any entries to
  4754. ;; the calendar. Org Agenda will list these entries itself.
  4755. (if org-disable-agenda-to-diary (setq files nil))
  4756. (while (setq file (pop files))
  4757. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4758. (setq results (append results rtn)))
  4759. (when results
  4760. (setq results
  4761. (mapcar (lambda (i) (replace-regexp-in-string
  4762. org-bracket-link-regexp "\\3" i)) results))
  4763. (concat (org-agenda-finalize-entries results) "\n"))))
  4764. ;;; Agenda entry finders
  4765. (defun org-agenda-get-day-entries (file date &rest args)
  4766. "Does the work for `org-diary' and `org-agenda'.
  4767. FILE is the path to a file to be checked for entries. DATE is date like
  4768. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4769. which kind of entries should be extracted. For details about these, see
  4770. the documentation of `org-diary'."
  4771. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4772. (let* ((org-startup-folded nil)
  4773. (org-startup-align-all-tables nil)
  4774. (buffer (if (file-exists-p file)
  4775. (org-get-agenda-file-buffer file)
  4776. (error "No such file %s" file)))
  4777. arg results rtn deadline-results)
  4778. (if (not buffer)
  4779. ;; If file does not exist, make sure an error message ends up in diary
  4780. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4781. (with-current-buffer buffer
  4782. (unless (derived-mode-p 'org-mode)
  4783. (error "Agenda file %s is not in `org-mode'" file))
  4784. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4785. (let ((case-fold-search nil))
  4786. (save-excursion
  4787. (save-restriction
  4788. (if org-agenda-restrict
  4789. (narrow-to-region org-agenda-restrict-begin
  4790. org-agenda-restrict-end)
  4791. (widen))
  4792. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4793. (while (setq arg (pop args))
  4794. (cond
  4795. ((and (eq arg :todo)
  4796. (equal date (calendar-gregorian-from-absolute
  4797. (org-today))))
  4798. (setq rtn (org-agenda-get-todos))
  4799. (setq results (append results rtn)))
  4800. ((eq arg :timestamp)
  4801. (setq rtn (org-agenda-get-blocks))
  4802. (setq results (append results rtn))
  4803. (setq rtn (org-agenda-get-timestamps deadline-results))
  4804. (setq results (append results rtn)))
  4805. ((eq arg :sexp)
  4806. (setq rtn (org-agenda-get-sexps))
  4807. (setq results (append results rtn)))
  4808. ((eq arg :scheduled)
  4809. (setq rtn (org-agenda-get-scheduled deadline-results))
  4810. (setq results (append results rtn)))
  4811. ((eq arg :closed)
  4812. (setq rtn (org-agenda-get-progress))
  4813. (setq results (append results rtn)))
  4814. ((eq arg :deadline)
  4815. (setq rtn (org-agenda-get-deadlines))
  4816. (setq deadline-results (copy-sequence rtn))
  4817. (setq results (append results rtn))))))))
  4818. results))))
  4819. (defsubst org-em (x y list)
  4820. "Is X or Y a member of LIST?"
  4821. (or (memq x list) (memq y list)))
  4822. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4823. (defvar org-agenda-sorting-strategy-selected nil)
  4824. (defun org-agenda-get-todos ()
  4825. "Return the TODO information for agenda display."
  4826. (let* ((props (list 'face nil
  4827. 'done-face 'org-agenda-done
  4828. 'org-not-done-regexp org-not-done-regexp
  4829. 'org-todo-regexp org-todo-regexp
  4830. 'org-complex-heading-regexp org-complex-heading-regexp
  4831. 'mouse-face 'highlight
  4832. 'help-echo
  4833. (format "mouse-2 or RET jump to org file %s"
  4834. (abbreviate-file-name buffer-file-name))))
  4835. (regexp (format org-heading-keyword-regexp-format
  4836. (cond
  4837. ((and org-select-this-todo-keyword
  4838. (equal org-select-this-todo-keyword "*"))
  4839. org-todo-regexp)
  4840. (org-select-this-todo-keyword
  4841. (concat "\\("
  4842. (mapconcat 'identity
  4843. (org-split-string
  4844. org-select-this-todo-keyword
  4845. "|")
  4846. "\\|") "\\)"))
  4847. (t org-not-done-regexp))))
  4848. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4849. ee txt beg end inherited-tags)
  4850. (goto-char (point-min))
  4851. (while (re-search-forward regexp nil t)
  4852. (catch :skip
  4853. (save-match-data
  4854. (beginning-of-line)
  4855. (org-agenda-skip)
  4856. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4857. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4858. (goto-char (1+ beg))
  4859. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4860. (throw :skip nil)))
  4861. (goto-char (match-beginning 2))
  4862. (setq marker (org-agenda-new-marker (match-beginning 0))
  4863. category (org-get-category)
  4864. ts-date (let (ts)
  4865. (save-match-data
  4866. (cond ((org-em 'scheduled-up 'scheduled-down
  4867. org-agenda-sorting-strategy-selected)
  4868. (setq ts (org-entry-get (point) "SCHEDULED")
  4869. ts-date-type " scheduled"))
  4870. ((org-em 'deadline-up 'deadline-down
  4871. org-agenda-sorting-strategy-selected)
  4872. (setq ts (org-entry-get (point) "DEADLINE")
  4873. ts-date-type " deadline"))
  4874. ((org-em 'ts-up 'ts-down
  4875. org-agenda-sorting-strategy-selected)
  4876. (setq ts (org-entry-get (point) "TIMESTAMP")
  4877. ts-date-type " timestamp"))
  4878. ((org-em 'tsia-up 'tsia-down
  4879. org-agenda-sorting-strategy-selected)
  4880. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4881. ts-date-type " timestamp_ia"))
  4882. ((org-em 'timestamp-up 'timestamp-down
  4883. org-agenda-sorting-strategy-selected)
  4884. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4885. (org-entry-get (point) "DEADLINE")
  4886. (org-entry-get (point) "TIMESTAMP")
  4887. (org-entry-get (point) "TIMESTAMP_IA"))
  4888. ts-date-type ""))
  4889. (t (setq ts-date-type "")))
  4890. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4891. category-pos (get-text-property (point) 'org-category-position)
  4892. txt (org-trim
  4893. (buffer-substring (match-beginning 2) (match-end 0)))
  4894. inherited-tags
  4895. (or (eq org-agenda-show-inherited-tags 'always)
  4896. (and (listp org-agenda-show-inherited-tags)
  4897. (memq 'todo org-agenda-show-inherited-tags))
  4898. (and (eq org-agenda-show-inherited-tags t)
  4899. (or (eq org-agenda-use-tag-inheritance t)
  4900. (memq 'todo org-agenda-use-tag-inheritance))))
  4901. tags (org-get-tags-at nil (not inherited-tags))
  4902. level (make-string (org-reduced-level (org-outline-level)) ? )
  4903. txt (org-agenda-format-item "" txt level category tags t)
  4904. priority (1+ (org-get-priority txt))
  4905. todo-state (org-get-todo-state))
  4906. (org-add-props txt props
  4907. 'org-marker marker 'org-hd-marker marker
  4908. 'priority priority 'org-category category
  4909. 'level level
  4910. 'ts-date ts-date
  4911. 'org-category-position category-pos
  4912. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4913. (push txt ee)
  4914. (if org-agenda-todo-list-sublevels
  4915. (goto-char (match-end 2))
  4916. (org-end-of-subtree 'invisible))))
  4917. (nreverse ee)))
  4918. (defun org-agenda-todo-custom-ignore-p (time n)
  4919. "Check whether timestamp is farther away than n number of days.
  4920. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4921. `org-agenda-todo-ignore-scheduled' or
  4922. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4923. (let ((days (org-time-stamp-to-now
  4924. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4925. (if (>= n 0)
  4926. (>= days n)
  4927. (<= days n))))
  4928. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4929. (&optional end)
  4930. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4931. (when (or org-agenda-todo-ignore-with-date
  4932. org-agenda-todo-ignore-scheduled
  4933. org-agenda-todo-ignore-deadlines
  4934. org-agenda-todo-ignore-timestamp)
  4935. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4936. (save-excursion
  4937. (or (and org-agenda-todo-ignore-with-date
  4938. (re-search-forward org-ts-regexp end t))
  4939. (and org-agenda-todo-ignore-scheduled
  4940. (re-search-forward org-scheduled-time-regexp end t)
  4941. (cond
  4942. ((eq org-agenda-todo-ignore-scheduled 'future)
  4943. (> (org-time-stamp-to-now
  4944. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4945. ((eq org-agenda-todo-ignore-scheduled 'past)
  4946. (<= (org-time-stamp-to-now
  4947. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4948. ((numberp org-agenda-todo-ignore-scheduled)
  4949. (org-agenda-todo-custom-ignore-p
  4950. (match-string 1) org-agenda-todo-ignore-scheduled))
  4951. (t)))
  4952. (and org-agenda-todo-ignore-deadlines
  4953. (re-search-forward org-deadline-time-regexp end t)
  4954. (cond
  4955. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4956. ((eq org-agenda-todo-ignore-deadlines 'far)
  4957. (not (org-deadline-close (match-string 1))))
  4958. ((eq org-agenda-todo-ignore-deadlines 'future)
  4959. (> (org-time-stamp-to-now
  4960. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4961. ((eq org-agenda-todo-ignore-deadlines 'past)
  4962. (<= (org-time-stamp-to-now
  4963. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4964. ((numberp org-agenda-todo-ignore-deadlines)
  4965. (org-agenda-todo-custom-ignore-p
  4966. (match-string 1) org-agenda-todo-ignore-deadlines))
  4967. (t (org-deadline-close (match-string 1)))))
  4968. (and org-agenda-todo-ignore-timestamp
  4969. (let ((buffer (current-buffer))
  4970. (regexp
  4971. (concat
  4972. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4973. (start (point)))
  4974. ;; Copy current buffer into a temporary one
  4975. (with-temp-buffer
  4976. (insert-buffer-substring buffer start end)
  4977. (goto-char (point-min))
  4978. ;; Delete SCHEDULED and DEADLINE items
  4979. (while (re-search-forward regexp end t)
  4980. (delete-region (match-beginning 0) (match-end 0)))
  4981. (goto-char (point-min))
  4982. ;; No search for timestamp left
  4983. (when (re-search-forward org-ts-regexp nil t)
  4984. (cond
  4985. ((eq org-agenda-todo-ignore-timestamp 'future)
  4986. (> (org-time-stamp-to-now
  4987. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4988. ((eq org-agenda-todo-ignore-timestamp 'past)
  4989. (<= (org-time-stamp-to-now
  4990. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4991. ((numberp org-agenda-todo-ignore-timestamp)
  4992. (org-agenda-todo-custom-ignore-p
  4993. (match-string 1) org-agenda-todo-ignore-timestamp))
  4994. (t))))))))))
  4995. (defun org-agenda-get-timestamps (&optional deadline-results)
  4996. "Return the date stamp information for agenda display."
  4997. (let* ((props (list 'face 'org-agenda-calendar-event
  4998. 'org-not-done-regexp org-not-done-regexp
  4999. 'org-todo-regexp org-todo-regexp
  5000. 'org-complex-heading-regexp org-complex-heading-regexp
  5001. 'mouse-face 'highlight
  5002. 'help-echo
  5003. (format "mouse-2 or RET jump to org file %s"
  5004. (abbreviate-file-name buffer-file-name))))
  5005. (d1 (calendar-absolute-from-gregorian date))
  5006. mm
  5007. (deadline-position-alist
  5008. (mapcar (lambda (a) (and (setq mm (get-text-property
  5009. 0 'org-hd-marker a))
  5010. (cons (marker-position mm) a)))
  5011. deadline-results))
  5012. (remove-re org-ts-regexp)
  5013. (regexp
  5014. (concat
  5015. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5016. (regexp-quote
  5017. (substring
  5018. (format-time-string
  5019. (car org-time-stamp-formats)
  5020. (apply 'encode-time ; DATE bound by calendar
  5021. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5022. 1 11))
  5023. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5024. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5025. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5026. donep tmp priority category category-pos level ee txt timestr tags
  5027. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5028. inherited-tags ts-date)
  5029. (goto-char (point-min))
  5030. (while (setq end-of-match (re-search-forward regexp nil t))
  5031. (setq b0 (match-beginning 0)
  5032. b3 (match-beginning 3) e3 (match-end 3)
  5033. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5034. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5035. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5036. (member todo-state
  5037. org-agenda-repeating-timestamp-show-all)))
  5038. (catch :skip
  5039. (and (org-at-date-range-p) (throw :skip nil))
  5040. (org-agenda-skip)
  5041. (if (and (match-end 1)
  5042. (not (= d1 (org-time-string-to-absolute
  5043. (match-string 1) d1 nil show-all
  5044. (current-buffer) b0))))
  5045. (throw :skip nil))
  5046. (if (and e3
  5047. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5048. (throw :skip nil))
  5049. (setq tmp (buffer-substring (max (point-min)
  5050. (- b0 org-ds-keyword-length))
  5051. b0)
  5052. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5053. inactivep (= (char-after b0) ?\[)
  5054. deadlinep (string-match org-deadline-regexp tmp)
  5055. scheduledp (string-match org-scheduled-regexp tmp)
  5056. closedp (and org-agenda-include-inactive-timestamps
  5057. (string-match org-closed-string tmp))
  5058. clockp (and org-agenda-include-inactive-timestamps
  5059. (or (string-match org-clock-string tmp)
  5060. (string-match "]-+\\'" tmp)))
  5061. warntime (get-text-property (point) 'org-appt-warntime)
  5062. donep (member todo-state org-done-keywords))
  5063. (if (or scheduledp deadlinep closedp clockp
  5064. (and donep org-agenda-skip-timestamp-if-done))
  5065. (throw :skip t))
  5066. (if (string-match ">" timestr)
  5067. ;; substring should only run to end of time stamp
  5068. (setq timestr (substring timestr 0 (match-end 0))))
  5069. (setq marker (org-agenda-new-marker b0)
  5070. category (org-get-category b0)
  5071. category-pos (get-text-property b0 'org-category-position))
  5072. (save-excursion
  5073. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5074. (throw :skip nil)
  5075. (goto-char (match-beginning 0))
  5076. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5077. (assoc (point) deadline-position-alist))
  5078. (throw :skip nil))
  5079. (setq hdmarker (org-agenda-new-marker)
  5080. inherited-tags
  5081. (or (eq org-agenda-show-inherited-tags 'always)
  5082. (and (listp org-agenda-show-inherited-tags)
  5083. (memq 'agenda org-agenda-show-inherited-tags))
  5084. (and (eq org-agenda-show-inherited-tags t)
  5085. (or (eq org-agenda-use-tag-inheritance t)
  5086. (memq 'agenda org-agenda-use-tag-inheritance))))
  5087. tags (org-get-tags-at nil (not inherited-tags))
  5088. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5089. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5090. (setq head (or (match-string 1) ""))
  5091. (setq txt (org-agenda-format-item
  5092. (if inactivep org-agenda-inactive-leader nil)
  5093. head level category tags timestr
  5094. remove-re habitp)))
  5095. (setq priority (org-get-priority txt))
  5096. (org-add-props txt props 'priority priority
  5097. 'org-marker marker 'org-hd-marker hdmarker
  5098. 'org-category category 'date date
  5099. 'level level
  5100. 'ts-date
  5101. (ignore-errors (org-time-string-to-absolute timestr))
  5102. 'org-category-position category-pos
  5103. 'todo-state todo-state
  5104. 'warntime warntime
  5105. 'type "timestamp")
  5106. (push txt ee))
  5107. (if org-agenda-skip-additional-timestamps-same-entry
  5108. (outline-next-heading)
  5109. (goto-char end-of-match))))
  5110. (nreverse ee)))
  5111. (defun org-agenda-get-sexps ()
  5112. "Return the sexp information for agenda display."
  5113. (require 'diary-lib)
  5114. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5115. 'mouse-face 'highlight
  5116. 'help-echo
  5117. (format "mouse-2 or RET jump to org file %s"
  5118. (abbreviate-file-name buffer-file-name))))
  5119. (regexp "^&?%%(")
  5120. marker category extra category-pos level ee txt tags entry
  5121. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5122. (goto-char (point-min))
  5123. (while (re-search-forward regexp nil t)
  5124. (catch :skip
  5125. (org-agenda-skip)
  5126. (setq beg (match-beginning 0))
  5127. (goto-char (1- (match-end 0)))
  5128. (setq b (point))
  5129. (forward-sexp 1)
  5130. (setq sexp (buffer-substring b (point)))
  5131. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5132. (org-trim (match-string 1))
  5133. ""))
  5134. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5135. (when result
  5136. (setq marker (org-agenda-new-marker beg)
  5137. level (make-string (org-reduced-level (org-outline-level)) ? )
  5138. category (org-get-category beg)
  5139. category-pos (get-text-property beg 'org-category-position)
  5140. inherited-tags
  5141. (or (eq org-agenda-show-inherited-tags 'always)
  5142. (and (listp org-agenda-show-inherited-tags)
  5143. (memq 'agenda org-agenda-show-inherited-tags))
  5144. (and (eq org-agenda-show-inherited-tags t)
  5145. (or (eq org-agenda-use-tag-inheritance t)
  5146. (memq 'agenda org-agenda-use-tag-inheritance))))
  5147. tags (org-get-tags-at nil (not inherited-tags))
  5148. todo-state (org-get-todo-state)
  5149. warntime (get-text-property (point) 'org-appt-warntime)
  5150. extra nil)
  5151. (dolist (r (if (stringp result)
  5152. (list result)
  5153. result)) ;; we expect a list here
  5154. (when (and org-agenda-diary-sexp-prefix
  5155. (string-match org-agenda-diary-sexp-prefix r))
  5156. (setq extra (match-string 0 r)
  5157. r (replace-match "" nil nil r)))
  5158. (if (string-match "\\S-" r)
  5159. (setq txt r)
  5160. (setq txt "SEXP entry returned empty string"))
  5161. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5162. (org-add-props txt props 'org-marker marker
  5163. 'org-category category 'date date 'todo-state todo-state
  5164. 'org-category-position category-pos 'tags tags
  5165. 'level level
  5166. 'type "sexp" 'warntime warntime)
  5167. (push txt ee)))))
  5168. (nreverse ee)))
  5169. ;; Calendar sanity: define some functions that are independent of
  5170. ;; `calendar-date-style'.
  5171. ;; Normally I would like to use ISO format when calling the diary functions,
  5172. ;; but to make sure we still have Emacs 22 compatibility we bind
  5173. ;; also `european-calendar-style' and use european format
  5174. (defun org-anniversary (year month day &optional mark)
  5175. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5176. (org-no-warnings
  5177. (let ((calendar-date-style 'european) (european-calendar-style t))
  5178. (diary-anniversary day month year mark))))
  5179. (defun org-cyclic (N year month day &optional mark)
  5180. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5181. (org-no-warnings
  5182. (let ((calendar-date-style 'european) (european-calendar-style t))
  5183. (diary-cyclic N day month year mark))))
  5184. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5185. "Like `diary-block', but with fixed (ISO) order of arguments."
  5186. (org-no-warnings
  5187. (let ((calendar-date-style 'european) (european-calendar-style t))
  5188. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5189. (defun org-date (year month day &optional mark)
  5190. "Like `diary-date', but with fixed (ISO) order of arguments."
  5191. (org-no-warnings
  5192. (let ((calendar-date-style 'european) (european-calendar-style t))
  5193. (diary-date day month year mark))))
  5194. ;; Define the` org-class' function
  5195. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5196. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5197. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5198. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5199. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5200. `holidays', then any date that is known by the Emacs calendar to be a
  5201. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5202. then those holidays will be skipped."
  5203. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5204. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5205. (d (calendar-absolute-from-gregorian date))
  5206. (h (when skip-weeks (calendar-check-holidays date))))
  5207. (and
  5208. (<= date1 d)
  5209. (<= d date2)
  5210. (= (calendar-day-of-week date) dayname)
  5211. (or (not skip-weeks)
  5212. (progn
  5213. (require 'cal-iso)
  5214. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5215. (not (or (and h (memq 'holidays skip-weeks))
  5216. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5217. entry)))
  5218. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5219. "Like `org-class', but honor `calendar-date-style'.
  5220. The order of the first 2 times 3 arguments depends on the variable
  5221. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5222. So for American calendars, give this as MONTH DAY YEAR, for European as
  5223. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5224. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5225. is any number of ISO weeks in the block period for which the item should
  5226. be skipped.
  5227. This function is here only for backward compatibility and it is deprecated,
  5228. please use `org-class' instead."
  5229. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5230. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5231. (org-class
  5232. (nth 2 date1) (car date1) (nth 1 date1)
  5233. (nth 2 date2) (car date2) (nth 1 date2)
  5234. dayname skip-weeks)))
  5235. (make-obsolete 'org-diary-class 'org-class "")
  5236. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5237. (defalias 'org-get-closed 'org-agenda-get-progress)
  5238. (defun org-agenda-get-progress ()
  5239. "Return the logged TODO entries for agenda display."
  5240. (let* ((props (list 'mouse-face 'highlight
  5241. 'org-not-done-regexp org-not-done-regexp
  5242. 'org-todo-regexp org-todo-regexp
  5243. 'org-complex-heading-regexp org-complex-heading-regexp
  5244. 'help-echo
  5245. (format "mouse-2 or RET jump to org file %s"
  5246. (abbreviate-file-name buffer-file-name))))
  5247. (items (if (consp org-agenda-show-log-scoped)
  5248. org-agenda-show-log-scoped
  5249. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5250. '(clock)
  5251. org-agenda-log-mode-items)))
  5252. (parts
  5253. (delq nil
  5254. (list
  5255. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5256. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5257. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5258. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5259. (error "`org-agenda-log-mode-items' is empty")))
  5260. (regexp (concat
  5261. "\\(" parts-re "\\)"
  5262. " *\\["
  5263. (regexp-quote
  5264. (substring
  5265. (format-time-string
  5266. (car org-time-stamp-formats)
  5267. (apply 'encode-time ; DATE bound by calendar
  5268. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5269. 1 11))))
  5270. (org-agenda-search-headline-for-time nil)
  5271. marker hdmarker priority category category-pos level tags closedp
  5272. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5273. (goto-char (point-min))
  5274. (while (re-search-forward regexp nil t)
  5275. (catch :skip
  5276. (org-agenda-skip)
  5277. (setq marker (org-agenda-new-marker (match-beginning 0))
  5278. closedp (equal (match-string 1) org-closed-string)
  5279. statep (equal (string-to-char (match-string 1)) ?-)
  5280. clockp (not (or closedp statep))
  5281. state (and statep (match-string 2))
  5282. category (org-get-category (match-beginning 0))
  5283. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5284. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5285. (when (string-match "\\]" timestr)
  5286. ;; substring should only run to end of time stamp
  5287. (setq rest (substring timestr (match-end 0))
  5288. timestr (substring timestr 0 (match-end 0)))
  5289. (if (and (not closedp) (not statep)
  5290. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5291. rest))
  5292. (progn (setq timestr (concat (substring timestr 0 -1)
  5293. "-" (match-string 1 rest) "]"))
  5294. (setq clocked (match-string 2 rest)))
  5295. (setq clocked "-")))
  5296. (save-excursion
  5297. (setq extra
  5298. (cond
  5299. ((not org-agenda-log-mode-add-notes) nil)
  5300. (statep
  5301. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5302. (match-string 1)))
  5303. (clockp
  5304. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5305. (match-string 1)))))
  5306. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5307. (throw :skip nil)
  5308. (goto-char (match-beginning 0))
  5309. (setq hdmarker (org-agenda-new-marker)
  5310. inherited-tags
  5311. (or (eq org-agenda-show-inherited-tags 'always)
  5312. (and (listp org-agenda-show-inherited-tags)
  5313. (memq 'todo org-agenda-show-inherited-tags))
  5314. (and (eq org-agenda-show-inherited-tags t)
  5315. (or (eq org-agenda-use-tag-inheritance t)
  5316. (memq 'todo org-agenda-use-tag-inheritance))))
  5317. tags (org-get-tags-at nil (not inherited-tags))
  5318. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5319. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5320. (setq txt (match-string 1))
  5321. (when extra
  5322. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5323. (setq txt (concat (substring txt 0 (match-beginning 1))
  5324. " - " extra " " (match-string 2 txt)))
  5325. (setq txt (concat txt " - " extra))))
  5326. (setq txt (org-agenda-format-item
  5327. (cond
  5328. (closedp "Closed: ")
  5329. (statep (concat "State: (" state ")"))
  5330. (t (concat "Clocked: (" clocked ")")))
  5331. txt level category tags timestr)))
  5332. (setq priority 100000)
  5333. (org-add-props txt props
  5334. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5335. 'priority priority 'org-category category
  5336. 'org-category-position category-pos
  5337. 'level level
  5338. 'type "closed" 'date date
  5339. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5340. (push txt ee))
  5341. (goto-char (point-at-eol))))
  5342. (nreverse ee)))
  5343. (defun org-agenda-show-clocking-issues ()
  5344. "Add overlays, showing issues with clocking.
  5345. See also the user option `org-agenda-clock-consistency-checks'."
  5346. (interactive)
  5347. (let* ((org-time-clocksum-use-effort-durations nil)
  5348. (pl org-agenda-clock-consistency-checks)
  5349. (re (concat "^[ \t]*"
  5350. org-clock-string
  5351. "[ \t]+"
  5352. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5353. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5354. (tlstart 0.)
  5355. (tlend 0.)
  5356. (maxtime (org-hh:mm-string-to-minutes
  5357. (or (plist-get pl :max-duration) "24:00")))
  5358. (mintime (org-hh:mm-string-to-minutes
  5359. (or (plist-get pl :min-duration) 0)))
  5360. (maxgap (org-hh:mm-string-to-minutes
  5361. ;; default 30:00 means never complain
  5362. (or (plist-get pl :max-gap) "30:00")))
  5363. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5364. (plist-get pl :gap-ok-around)))
  5365. (def-face (or (plist-get pl :default-face)
  5366. '((:background "DarkRed") (:foreground "white"))))
  5367. issue face m te ts dt ov)
  5368. (goto-char (point-min))
  5369. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5370. (setq issue nil face def-face)
  5371. (catch 'next
  5372. (setq m (org-get-at-bol 'org-marker)
  5373. te nil ts nil)
  5374. (unless (and m (markerp m))
  5375. (setq issue "No valid clock line") (throw 'next t))
  5376. (org-with-point-at m
  5377. (save-excursion
  5378. (goto-char (point-at-bol))
  5379. (unless (looking-at re)
  5380. (error "No valid Clock line")
  5381. (throw 'next t))
  5382. (unless (match-end 3)
  5383. (setq issue "No end time"
  5384. face (or (plist-get pl :no-end-time-face) face))
  5385. (throw 'next t))
  5386. (setq ts (match-string 1)
  5387. te (match-string 3)
  5388. ts (org-float-time
  5389. (apply 'encode-time (org-parse-time-string ts)))
  5390. te (org-float-time
  5391. (apply 'encode-time (org-parse-time-string te)))
  5392. dt (- te ts))))
  5393. (cond
  5394. ((> dt (* 60 maxtime))
  5395. ;; a very long clocking chunk
  5396. (setq issue (format "Clocking interval is very long: %s"
  5397. (org-minutes-to-clocksum-string
  5398. (floor (/ (float dt) 60.))))
  5399. face (or (plist-get pl :long-face) face)))
  5400. ((< dt (* 60 mintime))
  5401. ;; a very short clocking chunk
  5402. (setq issue (format "Clocking interval is very short: %s"
  5403. (org-minutes-to-clocksum-string
  5404. (floor (/ (float dt) 60.))))
  5405. face (or (plist-get pl :short-face) face)))
  5406. ((and (> tlend 0) (< ts tlend))
  5407. ;; Two clock entries are overlapping
  5408. (setq issue (format "Clocking overlap: %d minutes"
  5409. (/ (- tlend ts) 60))
  5410. face (or (plist-get pl :overlap-face) face)))
  5411. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5412. ;; There is a gap, lets see if we need to report it
  5413. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5414. (setq issue (format "Clocking gap: %d minutes"
  5415. (/ (- ts tlend) 60))
  5416. face (or (plist-get pl :gap-face) face))))
  5417. (t nil)))
  5418. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5419. (when issue
  5420. ;; OK, there was some issue, add an overlay to show the issue
  5421. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5422. (overlay-put ov 'before-string
  5423. (concat
  5424. (org-add-props
  5425. (format "%-43s" (concat " " issue))
  5426. nil
  5427. 'face face)
  5428. "\n"))
  5429. (overlay-put ov 'evaporate t)))))
  5430. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5431. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5432. (catch 'exit
  5433. (unless ok-list
  5434. ;; there are no OK times for gaps...
  5435. (throw 'exit nil))
  5436. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5437. ;; This is more than 24 hours, so it is OK.
  5438. ;; because we have at least one OK time, that must be in the
  5439. ;; 24 hour interval.
  5440. (throw 'exit t))
  5441. ;; We have a shorter gap.
  5442. ;; Now we have to get the minute of the day when these times are
  5443. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5444. (t2dec (decode-time (seconds-to-time t2)))
  5445. ;; compute the minute on the day
  5446. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5447. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5448. (when (< min2 min1)
  5449. ;; if min2 is smaller than min1, this means it is on the next day.
  5450. ;; Wrap it to after midnight.
  5451. (setq min2 (+ min2 1440)))
  5452. ;; Now check if any of the OK times is in the gap
  5453. (mapc (lambda (x)
  5454. ;; Wrap the time to after midnight if necessary
  5455. (if (< x min1) (setq x (+ x 1440)))
  5456. ;; Check if in interval
  5457. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5458. ok-list)
  5459. ;; Nope, this gap is not OK
  5460. nil)))
  5461. (defun org-agenda-get-deadlines ()
  5462. "Return the deadline information for agenda display."
  5463. (let* ((props (list 'mouse-face 'highlight
  5464. 'org-not-done-regexp org-not-done-regexp
  5465. 'org-todo-regexp org-todo-regexp
  5466. 'org-complex-heading-regexp org-complex-heading-regexp
  5467. 'help-echo
  5468. (format "mouse-2 or RET jump to org file %s"
  5469. (abbreviate-file-name buffer-file-name))))
  5470. (regexp org-deadline-time-regexp)
  5471. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5472. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5473. (dl0 (car org-agenda-deadline-leaders))
  5474. (dl1 (nth 1 org-agenda-deadline-leaders))
  5475. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5476. d2 diff dfrac wdays pos pos1 category category-pos level
  5477. tags suppress-prewarning ee txt head face s todo-state
  5478. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5479. (goto-char (point-min))
  5480. (while (re-search-forward regexp nil t)
  5481. (catch :skip
  5482. (org-agenda-skip)
  5483. (setq s (match-string 1)
  5484. txt nil
  5485. pos (1- (match-beginning 1))
  5486. todo-state (save-match-data (org-get-todo-state))
  5487. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5488. (member todo-state
  5489. org-agenda-repeating-timestamp-show-all))
  5490. d2 (org-time-string-to-absolute
  5491. s d1 'past show-all (current-buffer) pos)
  5492. diff (- d2 d1))
  5493. (setq suppress-prewarning
  5494. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5495. (let ((item (buffer-substring (point-at-bol)
  5496. (point-at-eol))))
  5497. (save-match-data
  5498. (and (string-match
  5499. org-scheduled-time-regexp item)
  5500. (match-string 1 item)))))))
  5501. (cond
  5502. ((not ds) nil)
  5503. ;; The current item has a scheduled date (in ds), so
  5504. ;; evaluate its prewarning lead time.
  5505. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5506. ;; Use global prewarning-restart lead time.
  5507. org-agenda-skip-deadline-prewarning-if-scheduled)
  5508. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5509. 'pre-scheduled)
  5510. ;; Set prewarning to no earlier than scheduled.
  5511. (min (- d2 (org-time-string-to-absolute
  5512. ds d1 'past show-all (current-buffer) pos))
  5513. org-deadline-warning-days))
  5514. ;; Set prewarning to deadline.
  5515. (t 0))))
  5516. (setq wdays (if suppress-prewarning
  5517. (let ((org-deadline-warning-days suppress-prewarning))
  5518. (org-get-wdays s))
  5519. (org-get-wdays s))
  5520. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5521. upcomingp (and todayp (> diff 0)))
  5522. ;; When to show a deadline in the calendar:
  5523. ;; If the expiration is within wdays warning time.
  5524. ;; Past-due deadlines are only shown on the current date
  5525. (if (and (or (and (<= diff wdays)
  5526. (and todayp (not org-agenda-only-exact-dates)))
  5527. (= diff 0)))
  5528. (save-excursion
  5529. ;; (setq todo-state (org-get-todo-state))
  5530. (setq donep (member todo-state org-done-keywords))
  5531. (if (and donep
  5532. (or org-agenda-skip-deadline-if-done
  5533. (not (= diff 0))))
  5534. (setq txt nil)
  5535. (setq category (org-get-category)
  5536. warntime (get-text-property (point) 'org-appt-warntime)
  5537. category-pos (get-text-property (point) 'org-category-position))
  5538. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5539. (throw :skip nil)
  5540. (goto-char (match-end 0))
  5541. (setq pos1 (match-beginning 0))
  5542. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5543. (setq inherited-tags
  5544. (or (eq org-agenda-show-inherited-tags 'always)
  5545. (and (listp org-agenda-show-inherited-tags)
  5546. (memq 'agenda org-agenda-show-inherited-tags))
  5547. (and (eq org-agenda-show-inherited-tags t)
  5548. (or (eq org-agenda-use-tag-inheritance t)
  5549. (memq 'agenda org-agenda-use-tag-inheritance))))
  5550. tags (org-get-tags-at pos1 (not inherited-tags)))
  5551. (setq head (buffer-substring
  5552. (point)
  5553. (progn (skip-chars-forward "^\r\n")
  5554. (point))))
  5555. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5556. (setq timestr
  5557. (concat (substring s (match-beginning 1)) " "))
  5558. (setq timestr 'time))
  5559. (setq txt (org-agenda-format-item
  5560. (cond ((= diff 0) dl0)
  5561. ((> diff 0)
  5562. (if (functionp dl1)
  5563. (funcall dl1 diff date)
  5564. (format dl1 diff)))
  5565. (t
  5566. (if (functionp dl2)
  5567. (funcall dl2 diff date)
  5568. (format dl2 (if (string= dl2 dl1)
  5569. diff (abs diff))))))
  5570. head level category tags
  5571. (if (not (= diff 0)) nil timestr)))))
  5572. (when txt
  5573. (setq face (org-agenda-deadline-face dfrac))
  5574. (org-add-props txt props
  5575. 'org-marker (org-agenda-new-marker pos)
  5576. 'warntime warntime
  5577. 'level level
  5578. 'ts-date d2
  5579. 'org-hd-marker (org-agenda-new-marker pos1)
  5580. 'priority (+ (- diff)
  5581. (org-get-priority txt))
  5582. 'org-category category
  5583. 'org-category-position category-pos
  5584. 'todo-state todo-state
  5585. 'type (if upcomingp "upcoming-deadline" "deadline")
  5586. 'date (if upcomingp date d2)
  5587. 'face (if donep 'org-agenda-done face)
  5588. 'undone-face face 'done-face 'org-agenda-done)
  5589. (push txt ee))))))
  5590. (nreverse ee)))
  5591. (defun org-agenda-deadline-face (fraction)
  5592. "Return the face to displaying a deadline item.
  5593. FRACTION is what fraction of the head-warning time has passed."
  5594. (let ((faces org-agenda-deadline-faces) f)
  5595. (catch 'exit
  5596. (while (setq f (pop faces))
  5597. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5598. (defun org-agenda-get-scheduled (&optional deadline-results)
  5599. "Return the scheduled information for agenda display."
  5600. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5601. 'org-todo-regexp org-todo-regexp
  5602. 'org-complex-heading-regexp org-complex-heading-regexp
  5603. 'done-face 'org-agenda-done
  5604. 'mouse-face 'highlight
  5605. 'help-echo
  5606. (format "mouse-2 or RET jump to org file %s"
  5607. (abbreviate-file-name buffer-file-name))))
  5608. (regexp org-scheduled-time-regexp)
  5609. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5610. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5611. mm
  5612. (deadline-position-alist
  5613. (mapcar (lambda (a) (and (setq mm (get-text-property
  5614. 0 'org-hd-marker a))
  5615. (cons (marker-position mm) a)))
  5616. deadline-results))
  5617. d2 diff pos pos1 category category-pos level tags donep
  5618. ee txt head pastschedp todo-state face timestr s habitp show-all
  5619. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5620. ddays)
  5621. (goto-char (point-min))
  5622. (while (re-search-forward regexp nil t)
  5623. (catch :skip
  5624. (org-agenda-skip)
  5625. (setq s (match-string 1)
  5626. txt nil
  5627. pos (1- (match-beginning 1))
  5628. todo-state (save-match-data (org-get-todo-state))
  5629. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5630. (member todo-state
  5631. org-agenda-repeating-timestamp-show-all))
  5632. d2 (org-time-string-to-absolute
  5633. s d1 'past show-all (current-buffer) pos)
  5634. diff (- d2 d1)
  5635. warntime (get-text-property (point) 'org-appt-warntime))
  5636. (setq pastschedp (and todayp (< diff 0)))
  5637. (setq did-habit-check-p nil)
  5638. (setq suppress-delay
  5639. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5640. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5641. (save-match-data
  5642. (and (string-match
  5643. org-deadline-time-regexp item)
  5644. (match-string 1 item)))))))
  5645. (cond
  5646. ((not ds) nil)
  5647. ;; The current item has a deadline date (in ds), so
  5648. ;; evaluate its delay time.
  5649. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5650. ;; Use global delay time.
  5651. (- org-agenda-skip-scheduled-delay-if-deadline))
  5652. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5653. 'post-deadline)
  5654. ;; Set delay to no later than deadline.
  5655. (min (- d2 (org-time-string-to-absolute
  5656. ds d1 'past show-all (current-buffer) pos))
  5657. org-scheduled-delay-days))
  5658. (t 0))))
  5659. (setq ddays (if suppress-delay
  5660. (let ((org-scheduled-delay-days suppress-delay))
  5661. (org-get-wdays s t t))
  5662. (org-get-wdays s t)))
  5663. ;; Use a delay of 0 when there is a repeater and the delay is
  5664. ;; of the form --3d
  5665. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5666. (< (org-time-string-to-absolute s)
  5667. (org-time-string-to-absolute
  5668. s d2 'past nil (current-buffer) pos)))
  5669. (setq ddays 0))
  5670. ;; When to show a scheduled item in the calendar:
  5671. ;; If it is on or past the date.
  5672. (when (or (and (> ddays 0) (= diff (- ddays)))
  5673. (and (zerop ddays) (= diff 0))
  5674. (and (< (+ diff ddays) 0)
  5675. (< (abs diff) org-scheduled-past-days)
  5676. (and todayp (not org-agenda-only-exact-dates)))
  5677. ;; org-is-habit-p uses org-entry-get, which is expansive
  5678. ;; so we go extra mile to only call it once
  5679. (and todayp
  5680. (boundp 'org-habit-show-all-today)
  5681. org-habit-show-all-today
  5682. (setq did-habit-check-p t)
  5683. (setq habitp (and (functionp 'org-is-habit-p)
  5684. (org-is-habit-p)))))
  5685. (save-excursion
  5686. (setq donep (member todo-state org-done-keywords))
  5687. (if (and donep
  5688. (or org-agenda-skip-scheduled-if-done
  5689. (not (= diff 0))
  5690. (and (functionp 'org-is-habit-p)
  5691. (org-is-habit-p))))
  5692. (setq txt nil)
  5693. (setq habitp (if did-habit-check-p habitp
  5694. (and (functionp 'org-is-habit-p)
  5695. (org-is-habit-p))))
  5696. (setq category (org-get-category)
  5697. category-pos (get-text-property (point) 'org-category-position))
  5698. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5699. (throw :skip nil)
  5700. (goto-char (match-end 0))
  5701. (setq pos1 (match-beginning 0))
  5702. (if habitp
  5703. (if (or (not org-habit-show-habits)
  5704. (and (not todayp)
  5705. (boundp 'org-habit-show-habits-only-for-today)
  5706. org-habit-show-habits-only-for-today))
  5707. (throw :skip nil))
  5708. (if (and
  5709. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5710. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5711. pastschedp))
  5712. (setq mm (assoc pos1 deadline-position-alist)))
  5713. (throw :skip nil)))
  5714. (setq inherited-tags
  5715. (or (eq org-agenda-show-inherited-tags 'always)
  5716. (and (listp org-agenda-show-inherited-tags)
  5717. (memq 'agenda org-agenda-show-inherited-tags))
  5718. (and (eq org-agenda-show-inherited-tags t)
  5719. (or (eq org-agenda-use-tag-inheritance t)
  5720. (memq 'agenda org-agenda-use-tag-inheritance))))
  5721. tags (org-get-tags-at nil (not inherited-tags)))
  5722. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5723. (setq head (buffer-substring
  5724. (point)
  5725. (progn (skip-chars-forward "^\r\n") (point))))
  5726. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5727. (setq timestr
  5728. (concat (substring s (match-beginning 1)) " "))
  5729. (setq timestr 'time))
  5730. (setq txt (org-agenda-format-item
  5731. (if (= diff 0)
  5732. (car org-agenda-scheduled-leaders)
  5733. (format (nth 1 org-agenda-scheduled-leaders)
  5734. (- 1 diff)))
  5735. head level category tags
  5736. (if (not (= diff 0)) nil timestr)
  5737. nil habitp))))
  5738. (when txt
  5739. (setq face
  5740. (cond
  5741. ((and (not habitp) pastschedp)
  5742. 'org-scheduled-previously)
  5743. (todayp 'org-scheduled-today)
  5744. (t 'org-scheduled))
  5745. habitp (and habitp (org-habit-parse-todo)))
  5746. (org-add-props txt props
  5747. 'undone-face face
  5748. 'face (if donep 'org-agenda-done face)
  5749. 'org-marker (org-agenda-new-marker pos)
  5750. 'org-hd-marker (org-agenda-new-marker pos1)
  5751. 'type (if pastschedp "past-scheduled" "scheduled")
  5752. 'date (if pastschedp d2 date)
  5753. 'ts-date d2
  5754. 'warntime warntime
  5755. 'level level
  5756. 'priority (if habitp
  5757. (org-habit-get-priority habitp)
  5758. (+ 94 (- 5 diff) (org-get-priority txt)))
  5759. 'org-category category
  5760. 'category-position category-pos
  5761. 'org-habit-p habitp
  5762. 'todo-state todo-state)
  5763. (push txt ee))))))
  5764. (nreverse ee)))
  5765. (defun org-agenda-get-blocks ()
  5766. "Return the date-range information for agenda display."
  5767. (let* ((props (list 'face nil
  5768. 'org-not-done-regexp org-not-done-regexp
  5769. 'org-todo-regexp org-todo-regexp
  5770. 'org-complex-heading-regexp org-complex-heading-regexp
  5771. 'mouse-face 'highlight
  5772. 'help-echo
  5773. (format "mouse-2 or RET jump to org file %s"
  5774. (abbreviate-file-name buffer-file-name))))
  5775. (regexp org-tr-regexp)
  5776. (d0 (calendar-absolute-from-gregorian date))
  5777. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5778. level todo-state tags pos head donep inherited-tags)
  5779. (goto-char (point-min))
  5780. (while (re-search-forward regexp nil t)
  5781. (catch :skip
  5782. (org-agenda-skip)
  5783. (setq pos (point))
  5784. (let ((start-time (match-string 1))
  5785. (end-time (match-string 2)))
  5786. (setq s1 (match-string 1)
  5787. s2 (match-string 2)
  5788. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5789. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5790. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5791. ;; Only allow days between the limits, because the normal
  5792. ;; date stamps will catch the limits.
  5793. (save-excursion
  5794. (setq todo-state (org-get-todo-state))
  5795. (setq donep (member todo-state org-done-keywords))
  5796. (if (and donep org-agenda-skip-timestamp-if-done)
  5797. (throw :skip t))
  5798. (setq marker (org-agenda-new-marker (point)))
  5799. (setq category (org-get-category)
  5800. category-pos (get-text-property (point) 'org-category-position))
  5801. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5802. (throw :skip nil)
  5803. (goto-char (match-beginning 0))
  5804. (setq hdmarker (org-agenda-new-marker (point))
  5805. inherited-tags
  5806. (or (eq org-agenda-show-inherited-tags 'always)
  5807. (and (listp org-agenda-show-inherited-tags)
  5808. (memq 'agenda org-agenda-show-inherited-tags))
  5809. (and (eq org-agenda-show-inherited-tags t)
  5810. (or (eq org-agenda-use-tag-inheritance t)
  5811. (memq 'agenda org-agenda-use-tag-inheritance))))
  5812. tags (org-get-tags-at nil (not inherited-tags)))
  5813. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5814. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5815. (setq head (match-string 1))
  5816. (let ((remove-re
  5817. (if org-agenda-remove-timeranges-from-blocks
  5818. (concat
  5819. "<" (regexp-quote s1) ".*?>"
  5820. "--"
  5821. "<" (regexp-quote s2) ".*?>")
  5822. nil)))
  5823. (setq txt (org-agenda-format-item
  5824. (format
  5825. (nth (if (= d1 d2) 0 1)
  5826. org-agenda-timerange-leaders)
  5827. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5828. head level category tags
  5829. (cond ((and (= d1 d0) (= d2 d0))
  5830. (concat "<" start-time ">--<" end-time ">"))
  5831. ((= d1 d0)
  5832. (concat "<" start-time ">"))
  5833. ((= d2 d0)
  5834. (concat "<" end-time ">")))
  5835. remove-re))))
  5836. (org-add-props txt props
  5837. 'org-marker marker 'org-hd-marker hdmarker
  5838. 'type "block" 'date date
  5839. 'level level
  5840. 'todo-state todo-state
  5841. 'priority (org-get-priority txt) 'org-category category
  5842. 'org-category-position category-pos)
  5843. (push txt ee))))
  5844. (goto-char pos)))
  5845. ;; Sort the entries by expiration date.
  5846. (nreverse ee)))
  5847. ;;; Agenda presentation and sorting
  5848. (defvar org-prefix-has-time nil
  5849. "A flag, set by `org-compile-prefix-format'.
  5850. The flag is set if the currently compiled format contains a `%t'.")
  5851. (defvar org-prefix-has-tag nil
  5852. "A flag, set by `org-compile-prefix-format'.
  5853. The flag is set if the currently compiled format contains a `%T'.")
  5854. (defvar org-prefix-has-effort nil
  5855. "A flag, set by `org-compile-prefix-format'.
  5856. The flag is set if the currently compiled format contains a `%e'.")
  5857. (defvar org-prefix-has-breadcrumbs nil
  5858. "A flag, set by `org-compile-prefix-format'.
  5859. The flag is set if the currently compiled format contains a `%b'.")
  5860. (defvar org-prefix-category-length nil
  5861. "Used by `org-compile-prefix-format' to remember the category field width.")
  5862. (defvar org-prefix-category-max-length nil
  5863. "Used by `org-compile-prefix-format' to remember the category field width.")
  5864. (defun org-agenda-get-category-icon (category)
  5865. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5866. (dolist (entry org-agenda-category-icon-alist)
  5867. (when (org-string-match-p (car entry) category)
  5868. (if (listp (cadr entry))
  5869. (return (cadr entry))
  5870. (return (apply 'create-image (cdr entry)))))))
  5871. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5872. remove-re habitp)
  5873. "Format TXT to be inserted into the agenda buffer.
  5874. In particular, add the prefix and corresponding text properties.
  5875. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5876. LEVEL may be a string to replace the `%l' specifier.
  5877. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5878. category taken from local variable or file name. It will replace the `%c'
  5879. specifier in the format.
  5880. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5881. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5882. When DOTIME is a string, this string is searched for a time before TXT is.
  5883. TAGS can be the tags of the headline.
  5884. Any match of REMOVE-RE will be removed from TXT."
  5885. ;; We keep the org-prefix-* variable values along with a compiled
  5886. ;; formatter, so that multiple agendas existing at the same time do
  5887. ;; not step on each other toes.
  5888. ;;
  5889. ;; It was inconvenient to make these variables buffer local in
  5890. ;; Agenda buffers, because this function expects to be called with
  5891. ;; the buffer where item comes from being current, and not agenda
  5892. ;; buffer
  5893. (let* ((bindings (car org-prefix-format-compiled))
  5894. (formatter (cadr org-prefix-format-compiled)))
  5895. (loop for (var value) in bindings
  5896. do (set var value))
  5897. (save-match-data
  5898. ;; Diary entries sometimes have extra whitespace at the beginning
  5899. (setq txt (org-trim txt))
  5900. ;; Fix the tags part in txt
  5901. (setq txt (org-agenda-fix-displayed-tags
  5902. txt tags
  5903. org-agenda-show-inherited-tags
  5904. org-agenda-hide-tags-regexp))
  5905. (let* ((category (or category
  5906. (if (stringp org-category)
  5907. org-category
  5908. (and org-category (symbol-name org-category)))
  5909. (if buffer-file-name
  5910. (file-name-sans-extension
  5911. (file-name-nondirectory buffer-file-name))
  5912. "")))
  5913. (category-icon (org-agenda-get-category-icon category))
  5914. (category-icon (if category-icon
  5915. (propertize " " 'display category-icon)
  5916. ""))
  5917. ;; time, tag, effort are needed for the eval of the prefix format
  5918. (tag (if tags (nth (1- (length tags)) tags) ""))
  5919. time effort neffort
  5920. (ts (if dotime (concat
  5921. (if (stringp dotime) dotime "")
  5922. (and org-agenda-search-headline-for-time txt))))
  5923. (time-of-day (and dotime (org-get-time-of-day ts)))
  5924. stamp plain s0 s1 s2 rtn srp l
  5925. duration thecategory breadcrumbs)
  5926. (and (derived-mode-p 'org-mode) buffer-file-name
  5927. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5928. (when (and dotime time-of-day)
  5929. ;; Extract starting and ending time and move them to prefix
  5930. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5931. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5932. (setq s0 (match-string 0 ts)
  5933. srp (and stamp (match-end 3))
  5934. s1 (match-string (if plain 1 2) ts)
  5935. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5936. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5937. ;; them, we might want to remove them there to avoid duplication.
  5938. ;; The user can turn this off with a variable.
  5939. (if (and org-prefix-has-time
  5940. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5941. (string-match (concat (regexp-quote s0) " *") txt)
  5942. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5943. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5944. (= (match-beginning 0) 0)
  5945. t))
  5946. (setq txt (replace-match "" nil nil txt))))
  5947. ;; Normalize the time(s) to 24 hour
  5948. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5949. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5950. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5951. (let (org-time-clocksum-use-effort-durations)
  5952. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5953. (setq s2
  5954. (org-minutes-to-clocksum-string
  5955. (+ (org-hh:mm-string-to-minutes s1)
  5956. org-agenda-default-appointment-duration)))))
  5957. ;; Compute the duration
  5958. (when s2
  5959. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5960. (org-hh:mm-string-to-minutes s1)))))
  5961. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5962. txt)
  5963. ;; Tags are in the string
  5964. (if (or (eq org-agenda-remove-tags t)
  5965. (and org-agenda-remove-tags
  5966. org-prefix-has-tag))
  5967. (setq txt (replace-match "" t t txt))
  5968. (setq txt (replace-match
  5969. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5970. (match-string 2 txt))
  5971. t t txt))))
  5972. (when (derived-mode-p 'org-mode)
  5973. (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
  5974. (if effort
  5975. (setq neffort (org-duration-string-to-minutes effort)
  5976. effort (setq effort (concat "[" effort "]")))
  5977. ;; prevent erroring out with %e format when there is no effort
  5978. (setq effort "")))
  5979. (when remove-re
  5980. (while (string-match remove-re txt)
  5981. (setq txt (replace-match "" t t txt))))
  5982. ;; Set org-heading property on `txt' to mark the start of the
  5983. ;; heading.
  5984. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5985. ;; Prepare the variables needed in the eval of the compiled format
  5986. (if org-prefix-has-breadcrumbs
  5987. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  5988. (let ((s (org-display-outline-path nil nil "->" t)))
  5989. (if (eq "" s) "" (concat s "->"))))))
  5990. (setq time (cond (s2 (concat
  5991. (org-agenda-time-of-day-to-ampm-maybe s1)
  5992. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5993. (if org-agenda-timegrid-use-ampm " ")))
  5994. (s1 (concat
  5995. (org-agenda-time-of-day-to-ampm-maybe s1)
  5996. (if org-agenda-timegrid-use-ampm
  5997. "........ "
  5998. "......")))
  5999. (t ""))
  6000. extra (or (and (not habitp) extra) "")
  6001. category (if (symbolp category) (symbol-name category) category)
  6002. thecategory (copy-sequence category)
  6003. level (or level ""))
  6004. (if (string-match org-bracket-link-regexp category)
  6005. (progn
  6006. (setq l (if (match-end 3)
  6007. (- (match-end 3) (match-beginning 3))
  6008. (- (match-end 1) (match-beginning 1))))
  6009. (when (< l (or org-prefix-category-length 0))
  6010. (setq category (copy-sequence category))
  6011. (org-add-props category nil
  6012. 'extra-space (make-string
  6013. (- org-prefix-category-length l 1) ?\ ))))
  6014. (if (and org-prefix-category-max-length
  6015. (>= (length category) org-prefix-category-max-length))
  6016. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6017. ;; Evaluate the compiled format
  6018. (setq rtn (concat (eval formatter) txt))
  6019. ;; And finally add the text properties
  6020. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6021. (org-add-props rtn nil
  6022. 'org-category (if thecategory (downcase thecategory) category)
  6023. 'tags (mapcar 'org-downcase-keep-props tags)
  6024. 'org-highest-priority org-highest-priority
  6025. 'org-lowest-priority org-lowest-priority
  6026. 'time-of-day time-of-day
  6027. 'duration duration
  6028. 'effort effort
  6029. 'effort-minutes neffort
  6030. 'breadcrumbs breadcrumbs
  6031. 'txt txt
  6032. 'level level
  6033. 'time time
  6034. 'extra extra
  6035. 'format org-prefix-format-compiled
  6036. 'dotime dotime)))))
  6037. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6038. "Remove tags string from TXT, and add a modified list of tags.
  6039. The modified list may contain inherited tags, and tags matched by
  6040. `org-agenda-hide-tags-regexp' will be removed."
  6041. (when (or add-inherited hide-re)
  6042. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6043. (setq txt (substring txt 0 (match-beginning 0))))
  6044. (setq tags
  6045. (delq nil
  6046. (mapcar (lambda (tg)
  6047. (if (or (and hide-re (string-match hide-re tg))
  6048. (and (not add-inherited)
  6049. (get-text-property 0 'inherited tg)))
  6050. nil
  6051. tg))
  6052. tags)))
  6053. (when tags
  6054. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6055. i)
  6056. (setq txt (concat txt " :"
  6057. (mapconcat
  6058. (lambda (x)
  6059. (setq i (get-text-property 0 'inherited x))
  6060. (if (and have-i (not i))
  6061. (progn
  6062. (setq have-i nil)
  6063. (concat ":" x))
  6064. x))
  6065. tags ":")
  6066. (if have-i "::" ":"))))))
  6067. txt)
  6068. (defun org-downcase-keep-props (s)
  6069. (let ((props (text-properties-at 0 s)))
  6070. (setq s (downcase s))
  6071. (add-text-properties 0 (length s) props s)
  6072. s))
  6073. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6074. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6075. "Add a time-grid for agenda items which need it.
  6076. LIST is the list of agenda items formatted by `org-agenda-list'.
  6077. NDAYS is the span of the current agenda view.
  6078. TODAYP is `t' when the current agenda view is on today."
  6079. (catch 'exit
  6080. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6081. ((and todayp (member 'today (car org-agenda-time-grid))))
  6082. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6083. ((member 'weekly (car org-agenda-time-grid)))
  6084. (t (throw 'exit list)))
  6085. (let* ((have (delq nil (mapcar
  6086. (lambda (x) (get-text-property 1 'time-of-day x))
  6087. list)))
  6088. (string (nth 1 org-agenda-time-grid))
  6089. (gridtimes (nth 2 org-agenda-time-grid))
  6090. (req (car org-agenda-time-grid))
  6091. (remove (member 'remove-match req))
  6092. new time)
  6093. (if (and (member 'require-timed req) (not have))
  6094. ;; don't show empty grid
  6095. (throw 'exit list))
  6096. (while (setq time (pop gridtimes))
  6097. (unless (and remove (member time have))
  6098. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6099. (push (org-agenda-format-item
  6100. nil string nil "" nil
  6101. (concat (substring time 0 -2) ":" (substring time -2)))
  6102. new)
  6103. (put-text-property
  6104. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6105. (when (and todayp org-agenda-show-current-time-in-grid)
  6106. (push (org-agenda-format-item
  6107. nil org-agenda-current-time-string nil "" nil
  6108. (format-time-string "%H:%M "))
  6109. new)
  6110. (put-text-property
  6111. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6112. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6113. (append new list)
  6114. (append list new)))))
  6115. (defun org-compile-prefix-format (key)
  6116. "Compile the prefix format into a Lisp form that can be evaluated.
  6117. The resulting form and associated variable bindings is returned
  6118. and stored in the variable `org-prefix-format-compiled'."
  6119. (setq org-prefix-has-time nil
  6120. org-prefix-has-tag nil
  6121. org-prefix-category-length nil
  6122. org-prefix-has-effort nil
  6123. org-prefix-has-breadcrumbs nil)
  6124. (let ((s (cond
  6125. ((stringp org-agenda-prefix-format)
  6126. org-agenda-prefix-format)
  6127. ((assq key org-agenda-prefix-format)
  6128. (cdr (assq key org-agenda-prefix-format)))
  6129. (t " %-12:c%?-12t% s")))
  6130. (start 0)
  6131. varform vars var e c f opt)
  6132. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6133. s start)
  6134. (setq var (or (cdr (assoc (match-string 4 s)
  6135. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6136. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6137. 'eval)
  6138. c (or (match-string 3 s) "")
  6139. opt (match-beginning 1)
  6140. start (1+ (match-beginning 0)))
  6141. (if (equal var 'time) (setq org-prefix-has-time t))
  6142. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6143. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6144. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6145. (setq f (concat "%" (match-string 2 s) "s"))
  6146. (when (equal var 'category)
  6147. (setq org-prefix-category-length
  6148. (floor (abs (string-to-number (match-string 2 s)))))
  6149. (setq org-prefix-category-max-length
  6150. (let ((x (match-string 2 s)))
  6151. (save-match-data
  6152. (if (string-match "\\.[0-9]+" x)
  6153. (string-to-number (substring (match-string 0 x) 1)))))))
  6154. (if (eq var 'eval)
  6155. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6156. (if opt
  6157. (setq varform
  6158. `(if (equal "" ,var)
  6159. ""
  6160. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6161. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6162. (setq s (replace-match "%s" t nil s))
  6163. (push varform vars))
  6164. (setq vars (nreverse vars))
  6165. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6166. (setq org-prefix-format-compiled
  6167. (list
  6168. `((org-prefix-has-time ,org-prefix-has-time)
  6169. (org-prefix-has-tag ,org-prefix-has-tag)
  6170. (org-prefix-category-length ,org-prefix-category-length)
  6171. (org-prefix-has-effort ,org-prefix-has-effort)
  6172. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6173. `(format ,s ,@vars))))))
  6174. (defun org-set-sorting-strategy (key)
  6175. (if (symbolp (car org-agenda-sorting-strategy))
  6176. ;; the old format
  6177. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6178. (setq org-agenda-sorting-strategy-selected
  6179. (or (cdr (assq key org-agenda-sorting-strategy))
  6180. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6181. '(time-up category-keep priority-down)))))
  6182. (defun org-get-time-of-day (s &optional string mod24)
  6183. "Check string S for a time of day.
  6184. If found, return it as a military time number between 0 and 2400.
  6185. If not found, return nil.
  6186. The optional STRING argument forces conversion into a 5 character wide string
  6187. HH:MM."
  6188. (save-match-data
  6189. (when
  6190. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6191. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6192. (let* ((h (string-to-number (match-string 1 s)))
  6193. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6194. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6195. (am-p (equal ampm "am"))
  6196. (h1 (cond ((not ampm) h)
  6197. ((= h 12) (if am-p 0 12))
  6198. (t (+ h (if am-p 0 12)))))
  6199. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6200. (mod h1 24) h1))
  6201. (t0 (+ (* 100 h2) m))
  6202. (t1 (concat (if (>= h1 24) "+" " ")
  6203. (if (and org-agenda-time-leading-zero
  6204. (< t0 1000)) "0" "")
  6205. (if (< t0 100) "0" "")
  6206. (if (< t0 10) "0" "")
  6207. (int-to-string t0))))
  6208. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6209. (defvar org-agenda-before-sorting-filter-function nil
  6210. "Function to be applied to agenda items prior to sorting.
  6211. Prior to sorting also means just before they are inserted into the agenda.
  6212. To aid sorting, you may revisit the original entries and add more text
  6213. properties which will later be used by the sorting functions.
  6214. The function should take a string argument, an agenda line.
  6215. It has access to the text properties in that line, which contain among
  6216. other things, the property `org-hd-marker' that points to the entry
  6217. where the line comes from. Note that not all lines going into the agenda
  6218. have this property, only most.
  6219. The function should return the modified string. It is probably best
  6220. to ONLY change text properties.
  6221. You can also use this function as a filter, by returning nil for lines
  6222. you don't want to have in the agenda at all. For this application, you
  6223. could bind the variable in the options section of a custom command.")
  6224. (defun org-agenda-finalize-entries (list &optional type)
  6225. "Sort, limit and concatenate the LIST of agenda items.
  6226. The optional argument TYPE tells the agenda type."
  6227. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6228. (cdr (assoc type org-agenda-max-effort)))
  6229. (t org-agenda-max-effort)))
  6230. (max-todo (cond ((listp org-agenda-max-todos)
  6231. (cdr (assoc type org-agenda-max-todos)))
  6232. (t org-agenda-max-todos)))
  6233. (max-tags (cond ((listp org-agenda-max-tags)
  6234. (cdr (assoc type org-agenda-max-tags)))
  6235. (t org-agenda-max-tags)))
  6236. (max-entries (cond ((listp org-agenda-max-entries)
  6237. (cdr (assoc type org-agenda-max-entries)))
  6238. (t org-agenda-max-entries))) l)
  6239. (when org-agenda-before-sorting-filter-function
  6240. (setq list
  6241. (delq nil
  6242. (mapcar
  6243. org-agenda-before-sorting-filter-function list))))
  6244. (setq list (mapcar 'org-agenda-highlight-todo list)
  6245. list (mapcar 'identity (sort list 'org-entries-lessp))
  6246. list (org-agenda-limit-entries
  6247. list 'effort-minutes max-effort 'identity)
  6248. list (org-agenda-limit-entries list 'todo-state max-todo)
  6249. list (org-agenda-limit-entries list 'tags max-tags)
  6250. list (org-agenda-limit-entries list 'org-hd-marker max-entries)
  6251. list (mapconcat 'identity list "\n"))))
  6252. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6253. "Limit the number of agenda entries."
  6254. (if limit
  6255. (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
  6256. (delq nil
  6257. (mapcar
  6258. (lambda (e)
  6259. (let ((pval (funcall f (get-text-property 1 prop e))))
  6260. (if pval (setq lim (+ lim pval)))
  6261. (if (or (not pval) (<= lim limit)) e)))
  6262. list)))
  6263. list))
  6264. (defun org-agenda-highlight-todo (x)
  6265. (let ((org-done-keywords org-done-keywords-for-agenda)
  6266. (case-fold-search nil)
  6267. re)
  6268. (if (eq x 'line)
  6269. (save-excursion
  6270. (beginning-of-line 1)
  6271. (setq re (org-get-at-bol 'org-todo-regexp))
  6272. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6273. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6274. (add-text-properties (match-beginning 0) (match-end 1)
  6275. (list 'face (org-get-todo-face 1)))
  6276. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6277. (delete-region (match-beginning 1) (1- (match-end 0)))
  6278. (goto-char (match-beginning 1))
  6279. (insert (format org-agenda-todo-keyword-format s)))))
  6280. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6281. (setq re (get-text-property 0 'org-todo-regexp x))
  6282. (when (and re
  6283. ;; Test `pl' because if there's no heading content,
  6284. ;; there's no point matching to highlight. Note
  6285. ;; that if we didn't test `pl' first, and there
  6286. ;; happened to be no keyword from `org-todo-regexp'
  6287. ;; on this heading line, then the `equal' comparison
  6288. ;; afterwards would spuriously succeed in the case
  6289. ;; where `pl' is nil -- causing an args-out-of-range
  6290. ;; error when we try to add text properties to text
  6291. ;; that isn't there.
  6292. pl
  6293. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6294. x pl) pl))
  6295. (add-text-properties
  6296. (or (match-end 1) (match-end 0)) (match-end 0)
  6297. (list 'face (org-get-todo-face (match-string 2 x)))
  6298. x)
  6299. (when (match-end 1)
  6300. (setq x (concat (substring x 0 (match-end 1))
  6301. (format org-agenda-todo-keyword-format
  6302. (match-string 2 x))
  6303. (org-add-props " " (text-properties-at 0 x))
  6304. (substring x (match-end 3)))))))
  6305. x)))
  6306. (defsubst org-cmp-priority (a b)
  6307. "Compare the priorities of string A and B."
  6308. (let ((pa (or (get-text-property 1 'priority a) 0))
  6309. (pb (or (get-text-property 1 'priority b) 0)))
  6310. (cond ((> pa pb) +1)
  6311. ((< pa pb) -1))))
  6312. (defsubst org-cmp-effort (a b)
  6313. "Compare the effort values of string A and B."
  6314. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6315. (ea (or (get-text-property 1 'effort-minutes a) def))
  6316. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6317. (cond ((> ea eb) +1)
  6318. ((< ea eb) -1))))
  6319. (defsubst org-cmp-category (a b)
  6320. "Compare the string values of categories of strings A and B."
  6321. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6322. (cb (or (get-text-property 1 'org-category b) "")))
  6323. (cond ((string-lessp ca cb) -1)
  6324. ((string-lessp cb ca) +1))))
  6325. (defsubst org-cmp-todo-state (a b)
  6326. "Compare the todo states of strings A and B."
  6327. (let* ((ma (or (get-text-property 1 'org-marker a)
  6328. (get-text-property 1 'org-hd-marker a)))
  6329. (mb (or (get-text-property 1 'org-marker b)
  6330. (get-text-property 1 'org-hd-marker b)))
  6331. (fa (and ma (marker-buffer ma)))
  6332. (fb (and mb (marker-buffer mb)))
  6333. (todo-kwds
  6334. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6335. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6336. (ta (or (get-text-property 1 'todo-state a) ""))
  6337. (tb (or (get-text-property 1 'todo-state b) ""))
  6338. (la (- (length (member ta todo-kwds))))
  6339. (lb (- (length (member tb todo-kwds))))
  6340. (donepa (member ta org-done-keywords-for-agenda))
  6341. (donepb (member tb org-done-keywords-for-agenda)))
  6342. (cond ((and donepa (not donepb)) -1)
  6343. ((and (not donepa) donepb) +1)
  6344. ((< la lb) -1)
  6345. ((< lb la) +1))))
  6346. (defsubst org-cmp-alpha (a b)
  6347. "Compare the headlines, alphabetically."
  6348. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6349. (plb (text-property-any 0 (length b) 'org-heading t b))
  6350. (ta (and pla (substring a pla)))
  6351. (tb (and plb (substring b plb))))
  6352. (when pla
  6353. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6354. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6355. (setq ta (substring ta (match-end 0))))
  6356. (setq ta (downcase ta)))
  6357. (when plb
  6358. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6359. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6360. (setq tb (substring tb (match-end 0))))
  6361. (setq tb (downcase tb)))
  6362. (cond ((not ta) +1)
  6363. ((not tb) -1)
  6364. ((string-lessp ta tb) -1)
  6365. ((string-lessp tb ta) +1))))
  6366. (defsubst org-cmp-tag (a b)
  6367. "Compare the string values of the first tags of A and B."
  6368. (let ((ta (car (last (get-text-property 1 'tags a))))
  6369. (tb (car (last (get-text-property 1 'tags b)))))
  6370. (cond ((not ta) +1)
  6371. ((not tb) -1)
  6372. ((string-lessp ta tb) -1)
  6373. ((string-lessp tb ta) +1))))
  6374. (defsubst org-cmp-time (a b)
  6375. "Compare the time-of-day values of strings A and B."
  6376. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6377. (ta (or (get-text-property 1 'time-of-day a) def))
  6378. (tb (or (get-text-property 1 'time-of-day b) def)))
  6379. (cond ((< ta tb) -1)
  6380. ((< tb ta) +1))))
  6381. (defsubst org-cmp-ts (a b &optional type)
  6382. "Compare the timestamps values of entries A and B.
  6383. When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
  6384. or \"timestamp_ia\", compare within each of these type.
  6385. When TYPE is the empty string, compare all timestamps
  6386. without respect of their type."
  6387. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6388. (ta (or (and (string-match type (get-text-property 1 'type a))
  6389. (get-text-property 1 'ts-date a)) def))
  6390. (tb (or (and (string-match type (get-text-property 1 'type b))
  6391. (get-text-property 1 'ts-date b)) def)))
  6392. (cond ((< ta tb) -1)
  6393. ((< tb ta) +1))))
  6394. (defsubst org-cmp-habit-p (a b)
  6395. "Compare the todo states of strings A and B."
  6396. (let ((ha (get-text-property 1 'org-habit-p a))
  6397. (hb (get-text-property 1 'org-habit-p b)))
  6398. (cond ((and ha (not hb)) -1)
  6399. ((and (not ha) hb) +1))))
  6400. (defun org-entries-lessp (a b)
  6401. "Predicate for sorting agenda entries."
  6402. ;; The following variables will be used when the form is evaluated.
  6403. ;; So even though the compiler complains, keep them.
  6404. (let* ((ss org-agenda-sorting-strategy-selected)
  6405. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6406. (org-cmp-ts a b "")))
  6407. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6408. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6409. (org-cmp-ts a b "scheduled")))
  6410. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6411. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6412. (org-cmp-ts a b "deadline")))
  6413. (deadline-down (if deadline-up (- deadline-up) nil))
  6414. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6415. (org-cmp-ts a b "iatimestamp_ia")))
  6416. (tsia-down (if tsia-up (- tsia-up) nil))
  6417. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6418. (org-cmp-ts a b "timestamp")))
  6419. (ts-down (if ts-up (- ts-up) nil))
  6420. (time-up (and (org-em 'time-up 'time-down ss)
  6421. (org-cmp-time a b)))
  6422. (time-down (if time-up (- time-up) nil))
  6423. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6424. (org-cmp-priority a b)))
  6425. (priority-down (if priority-up (- priority-up) nil))
  6426. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6427. (org-cmp-effort a b)))
  6428. (effort-down (if effort-up (- effort-up) nil))
  6429. (category-up (and (or (org-em 'category-up 'category-down ss)
  6430. (memq 'category-keep ss))
  6431. (org-cmp-category a b)))
  6432. (category-down (if category-up (- category-up) nil))
  6433. (category-keep (if category-up +1 nil))
  6434. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6435. (org-cmp-tag a b)))
  6436. (tag-down (if tag-up (- tag-up) nil))
  6437. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6438. (org-cmp-todo-state a b)))
  6439. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6440. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6441. (org-cmp-habit-p a b)))
  6442. (habit-down (if habit-up (- habit-up) nil))
  6443. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6444. (org-cmp-alpha a b)))
  6445. (alpha-down (if alpha-up (- alpha-up) nil))
  6446. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6447. user-defined-up user-defined-down)
  6448. (if (and need-user-cmp org-agenda-cmp-user-defined
  6449. (functionp org-agenda-cmp-user-defined))
  6450. (setq user-defined-up
  6451. (funcall org-agenda-cmp-user-defined a b)
  6452. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6453. (cdr (assoc
  6454. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6455. '((-1 . t) (1 . nil) (nil . nil))))))
  6456. ;;; Agenda restriction lock
  6457. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6458. "Overlay to mark the headline to which agenda commands are restricted.")
  6459. (overlay-put org-agenda-restriction-lock-overlay
  6460. 'face 'org-agenda-restriction-lock)
  6461. (overlay-put org-agenda-restriction-lock-overlay
  6462. 'help-echo "Agendas are currently limited to this subtree.")
  6463. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6464. (defun org-agenda-set-restriction-lock (&optional type)
  6465. "Set restriction lock for agenda, to current subtree or file.
  6466. Restriction will be the file if TYPE is `file', or if type is the
  6467. universal prefix '(4), or if the cursor is before the first headline
  6468. in the file. Otherwise, restriction will be to the current subtree."
  6469. (interactive "P")
  6470. (and (equal type '(4)) (setq type 'file))
  6471. (setq type (cond
  6472. (type type)
  6473. ((org-at-heading-p) 'subtree)
  6474. ((condition-case nil (org-back-to-heading t) (error nil))
  6475. 'subtree)
  6476. (t 'file)))
  6477. (if (eq type 'subtree)
  6478. (progn
  6479. (setq org-agenda-restrict t)
  6480. (setq org-agenda-overriding-restriction 'subtree)
  6481. (put 'org-agenda-files 'org-restrict
  6482. (list (buffer-file-name (buffer-base-buffer))))
  6483. (org-back-to-heading t)
  6484. (move-overlay org-agenda-restriction-lock-overlay
  6485. (point) (save-excursion (org-end-of-subtree t t) (point)))
  6486. (move-marker org-agenda-restrict-begin (point))
  6487. (move-marker org-agenda-restrict-end
  6488. (save-excursion (org-end-of-subtree t t)))
  6489. (message "Locking agenda restriction to subtree"))
  6490. (put 'org-agenda-files 'org-restrict
  6491. (list (buffer-file-name (buffer-base-buffer))))
  6492. (setq org-agenda-restrict nil)
  6493. (setq org-agenda-overriding-restriction 'file)
  6494. (move-marker org-agenda-restrict-begin nil)
  6495. (move-marker org-agenda-restrict-end nil)
  6496. (message "Locking agenda restriction to file"))
  6497. (setq current-prefix-arg nil)
  6498. (org-agenda-maybe-redo))
  6499. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6500. "Remove the agenda restriction lock."
  6501. (interactive "P")
  6502. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6503. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6504. (setq org-agenda-overriding-restriction nil)
  6505. (setq org-agenda-restrict nil)
  6506. (put 'org-agenda-files 'org-restrict nil)
  6507. (move-marker org-agenda-restrict-begin nil)
  6508. (move-marker org-agenda-restrict-end nil)
  6509. (setq current-prefix-arg nil)
  6510. (message "Agenda restriction lock removed")
  6511. (or noupdate (org-agenda-maybe-redo)))
  6512. (defun org-agenda-maybe-redo ()
  6513. "If there is any window showing the agenda view, update it."
  6514. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6515. (w0 (selected-window)))
  6516. (when w
  6517. (select-window w)
  6518. (org-agenda-redo)
  6519. (select-window w0)
  6520. (if org-agenda-overriding-restriction
  6521. (message "Agenda view shifted to new %s restriction"
  6522. org-agenda-overriding-restriction)
  6523. (message "Agenda restriction lock removed")))))
  6524. ;;; Agenda commands
  6525. (defun org-agenda-check-type (error &rest types)
  6526. "Check if agenda buffer is of allowed type.
  6527. If ERROR is non-nil, throw an error, otherwise just return nil.
  6528. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6529. (if (not org-agenda-type)
  6530. (error "No Org agenda currently displayed")
  6531. (if (memq org-agenda-type types)
  6532. t
  6533. (if error
  6534. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6535. nil))))
  6536. (defun org-agenda-Quit ()
  6537. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6538. Also restore the window configuration."
  6539. (interactive)
  6540. (if org-agenda-columns-active
  6541. (org-columns-quit)
  6542. (let ((buf (current-buffer)))
  6543. (if (eq org-agenda-window-setup 'other-frame)
  6544. (progn
  6545. (org-agenda-reset-markers)
  6546. (kill-buffer buf)
  6547. (org-columns-remove-overlays)
  6548. (setq org-agenda-archives-mode nil)
  6549. (delete-frame))
  6550. (and (not (eq org-agenda-window-setup 'current-window))
  6551. (not (one-window-p))
  6552. (delete-window))
  6553. (org-agenda-reset-markers)
  6554. (kill-buffer buf)
  6555. (org-columns-remove-overlays)
  6556. (setq org-agenda-archives-mode nil)))
  6557. ;; Maybe restore the pre-agenda window configuration.
  6558. (and org-agenda-restore-windows-after-quit
  6559. (not (eq org-agenda-window-setup 'other-frame))
  6560. org-agenda-pre-window-conf
  6561. (set-window-configuration org-agenda-pre-window-conf)
  6562. (setq org-agenda-pre-window-conf nil))))
  6563. (defun org-agenda-quit ()
  6564. "Exit the agenda and restore the window configuration.
  6565. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6566. (interactive)
  6567. (if (and (eq org-indirect-buffer-display 'other-window)
  6568. org-last-indirect-buffer)
  6569. (let ((org-last-indirect-window
  6570. (get-buffer-window org-last-indirect-buffer)))
  6571. (if org-last-indirect-window
  6572. (delete-window org-last-indirect-window))))
  6573. (if org-agenda-columns-active
  6574. (org-columns-quit)
  6575. (if org-agenda-sticky
  6576. (let ((buf (current-buffer)))
  6577. (if (eq org-agenda-window-setup 'other-frame)
  6578. (progn
  6579. (delete-frame))
  6580. (and (not (eq org-agenda-window-setup 'current-window))
  6581. (not (one-window-p))
  6582. (delete-window)))
  6583. (with-current-buffer buf
  6584. (bury-buffer)
  6585. ;; Maybe restore the pre-agenda window configuration.
  6586. (and org-agenda-restore-windows-after-quit
  6587. (not (eq org-agenda-window-setup 'other-frame))
  6588. org-agenda-pre-window-conf
  6589. (set-window-configuration org-agenda-pre-window-conf)
  6590. (setq org-agenda-pre-window-conf nil))))
  6591. (org-agenda-Quit))))
  6592. (defun org-agenda-exit ()
  6593. "Exit the agenda and restore the window configuration.
  6594. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6595. buffers visited directly by the user will not be touched."
  6596. (interactive)
  6597. (org-release-buffers org-agenda-new-buffers)
  6598. (setq org-agenda-new-buffers nil)
  6599. (org-agenda-Quit))
  6600. (defun org-agenda-kill-all-agenda-buffers ()
  6601. "Kill all buffers in `org-agenda-mode'.
  6602. This is used when toggling sticky agendas.
  6603. You can also explicitly invoke it with `C-c a C-k'."
  6604. (interactive)
  6605. (let (blist)
  6606. (dolist (buf (buffer-list))
  6607. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6608. (push buf blist)))
  6609. (mapc 'kill-buffer blist)))
  6610. (defun org-agenda-execute (arg)
  6611. "Execute another agenda command, keeping same window.
  6612. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6613. in the agenda."
  6614. (interactive "P")
  6615. (let ((org-agenda-window-setup 'current-window))
  6616. (org-agenda arg)))
  6617. (defun org-agenda-redo (&optional all)
  6618. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6619. (interactive "P")
  6620. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6621. (cpa (unless (eq all t) current-prefix-arg))
  6622. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6623. (org-agenda-sticky nil)
  6624. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6625. org-agenda-buffer-name))
  6626. (org-agenda-keep-modes t)
  6627. (tag-filter org-agenda-tag-filter)
  6628. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6629. (top-cat-filter org-agenda-top-category-filter)
  6630. (cat-filter org-agenda-category-filter)
  6631. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6632. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6633. (cols org-agenda-columns-active)
  6634. (line (org-current-line))
  6635. (window-line (- line (org-current-line (window-start))))
  6636. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6637. (redo-cmd (get-text-property p 'org-redo-cmd))
  6638. (last-args (get-text-property p 'org-last-args))
  6639. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6640. (org-agenda-overriding-cmd-arguments
  6641. (unless (eq all t)
  6642. (cond ((listp last-args)
  6643. (cons (or cpa (car last-args)) (cdr last-args)))
  6644. ((stringp last-args)
  6645. last-args))))
  6646. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6647. (put 'org-agenda-tag-filter :preset-filter nil)
  6648. (put 'org-agenda-category-filter :preset-filter nil)
  6649. (and cols (org-columns-quit))
  6650. (message "Rebuilding agenda buffer...")
  6651. (if series-redo-cmd
  6652. (eval series-redo-cmd)
  6653. (org-let lprops '(eval redo-cmd)))
  6654. (setq org-agenda-undo-list nil
  6655. org-agenda-pending-undo-list nil)
  6656. (message "Rebuilding agenda buffer...done")
  6657. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6658. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6659. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6660. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6661. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6662. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6663. (org-goto-line line)
  6664. (recenter window-line)))
  6665. (defvar org-global-tags-completion-table nil)
  6666. (defvar org-agenda-filter-form nil)
  6667. (defvar org-agenda-filtered-by-category nil)
  6668. (defun org-agenda-filter-by-category (strip)
  6669. "Keep only those lines in the agenda buffer that have a specific category.
  6670. The category is that of the current line."
  6671. (interactive "P")
  6672. (if (and org-agenda-filtered-by-category
  6673. org-agenda-category-filter)
  6674. (org-agenda-filter-show-all-cat)
  6675. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6676. (if cat (org-agenda-filter-apply
  6677. (list (concat (if strip "-" "+") cat)) 'category)
  6678. (error "No category at point")))))
  6679. (defun org-find-top-category (&optional pos)
  6680. (save-excursion
  6681. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6682. (if pos (goto-char pos))
  6683. ;; Skip up to the topmost parent
  6684. (while (ignore-errors (outline-up-heading 1) t))
  6685. (ignore-errors
  6686. (nth 4 (org-heading-components))))))
  6687. (defvar org-agenda-filtered-by-top-category nil)
  6688. (defun org-agenda-filter-by-top-category (strip)
  6689. "Keep only those lines in the agenda buffer that have a specific category.
  6690. The category is that of the current line."
  6691. (interactive "P")
  6692. (if org-agenda-filtered-by-top-category
  6693. (progn
  6694. (setq org-agenda-filtered-by-top-category nil
  6695. org-agenda-top-category-filter nil)
  6696. (org-agenda-filter-show-all-cat))
  6697. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6698. (if cat (org-agenda-filter-top-category-apply cat strip)
  6699. (error "No top-level category at point")))))
  6700. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6701. "Keep only those lines in the agenda buffer that have a specific tag.
  6702. The tag is selected with its fast selection letter, as configured.
  6703. With prefix argument STRIP, remove all lines that do have the tag.
  6704. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6705. used to narrow the search - the interactive user can also press `-' or `+'
  6706. to switch to narrowing."
  6707. (interactive "P")
  6708. (let* ((alist org-tag-alist-for-agenda)
  6709. (tag-chars (mapconcat
  6710. (lambda (x) (if (and (not (symbolp (car x)))
  6711. (cdr x))
  6712. (char-to-string (cdr x))
  6713. ""))
  6714. alist ""))
  6715. (efforts (org-split-string
  6716. (or (cdr (assoc (concat org-effort-property "_ALL")
  6717. org-global-properties))
  6718. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6719. "")))
  6720. (effort-op org-agenda-filter-effort-default-operator)
  6721. (effort-prompt "")
  6722. (inhibit-read-only t)
  6723. (current org-agenda-tag-filter)
  6724. maybe-refresh a n tag)
  6725. (unless char
  6726. (message
  6727. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6728. (if narrow "Narrow" "Filter") tag-chars
  6729. (if org-agenda-auto-exclude-function "[RET], " ""))
  6730. (setq char (read-char-exclusive)))
  6731. (when (member char '(?+ ?-))
  6732. ;; Narrowing down
  6733. (cond ((equal char ?-) (setq strip t narrow t))
  6734. ((equal char ?+) (setq strip nil narrow t)))
  6735. (message
  6736. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6737. (setq char (read-char-exclusive)))
  6738. (when (member char '(?< ?> ?= ??))
  6739. ;; An effort operator
  6740. (setq effort-op (char-to-string char))
  6741. (setq alist nil) ; to make sure it will be interpreted as effort.
  6742. (unless (equal char ??)
  6743. (loop for i from 0 to 9 do
  6744. (setq effort-prompt
  6745. (concat
  6746. effort-prompt " ["
  6747. (if (= i 9) "0" (int-to-string (1+ i)))
  6748. "]" (nth i efforts))))
  6749. (message "Effort%s: %s " effort-op effort-prompt)
  6750. (setq char (read-char-exclusive))
  6751. (when (or (< char ?0) (> char ?9))
  6752. (error "Need 1-9,0 to select effort"))))
  6753. (when (equal char ?\t)
  6754. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6755. (org-set-local 'org-global-tags-completion-table
  6756. (org-global-tags-completion-table)))
  6757. (let ((completion-ignore-case t))
  6758. (setq tag (org-icompleting-read
  6759. "Tag: " org-global-tags-completion-table))))
  6760. (cond
  6761. ((equal char ?\r)
  6762. (org-agenda-filter-show-all-tag)
  6763. (when org-agenda-auto-exclude-function
  6764. (setq org-agenda-tag-filter '())
  6765. (dolist (tag (org-agenda-get-represented-tags))
  6766. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6767. (if modifier
  6768. (push modifier org-agenda-tag-filter))))
  6769. (if (not (null org-agenda-tag-filter))
  6770. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6771. (setq maybe-refresh t))
  6772. ((equal char ?/)
  6773. (org-agenda-filter-show-all-tag)
  6774. (when (get 'org-agenda-tag-filter :preset-filter)
  6775. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6776. (setq maybe-refresh t))
  6777. ((equal char ?. )
  6778. (setq org-agenda-tag-filter
  6779. (mapcar (lambda(tag) (concat "+" tag))
  6780. (org-get-at-bol 'tags)))
  6781. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6782. (setq maybe-refresh t))
  6783. ((or (equal char ?\ )
  6784. (setq a (rassoc char alist))
  6785. (and (>= char ?0) (<= char ?9)
  6786. (setq n (if (= char ?0) 9 (- char ?0 1))
  6787. tag (concat effort-op (nth n efforts))
  6788. a (cons tag nil)))
  6789. (and (= char ??)
  6790. (setq tag "?eff")
  6791. a (cons tag nil))
  6792. (and tag (setq a (cons tag nil))))
  6793. (org-agenda-filter-show-all-tag)
  6794. (setq tag (car a))
  6795. (setq org-agenda-tag-filter
  6796. (cons (concat (if strip "-" "+") tag)
  6797. (if narrow current nil)))
  6798. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6799. (setq maybe-refresh t))
  6800. (t (error "Invalid tag selection character %c" char)))
  6801. (when (and maybe-refresh
  6802. (eq org-agenda-clockreport-mode 'with-filter))
  6803. (org-agenda-redo))))
  6804. (defun org-agenda-get-represented-tags ()
  6805. "Get a list of all tags currently represented in the agenda."
  6806. (let (p tags)
  6807. (save-excursion
  6808. (goto-char (point-min))
  6809. (while (setq p (next-single-property-change (point) 'tags))
  6810. (goto-char p)
  6811. (mapc (lambda (x) (add-to-list 'tags x))
  6812. (get-text-property (point) 'tags))))
  6813. tags))
  6814. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6815. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6816. (interactive "P")
  6817. (org-agenda-filter-by-tag strip char 'refine))
  6818. (defun org-agenda-filter-make-matcher ()
  6819. "Create the form that tests a line for agenda filter."
  6820. (let (f f1)
  6821. ;; first compute the tag-filter matcher
  6822. (dolist (x (delete-dups
  6823. (append (get 'org-agenda-tag-filter
  6824. :preset-filter) org-agenda-tag-filter)))
  6825. (if (member x '("-" "+"))
  6826. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6827. (if (string-match "[<=>?]" x)
  6828. (setq f1 (org-agenda-filter-effort-form x))
  6829. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6830. (if (equal (string-to-char x) ?-)
  6831. (setq f1 (list 'not f1))))
  6832. (push f1 f))
  6833. ;; then compute the category-filter matcher
  6834. (dolist (x (delete-dups
  6835. (append (get 'org-agenda-category-filter
  6836. :preset-filter) org-agenda-category-filter)))
  6837. (if (equal "-" (substring x 0 1))
  6838. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6839. (setq f1 (list 'equal (substring x 1) 'cat)))
  6840. (push f1 f))
  6841. (cons 'and (nreverse f))))
  6842. (defun org-agenda-filter-effort-form (e)
  6843. "Return the form to compare the effort of the current line with what E says.
  6844. E looks like \"+<2:25\"."
  6845. (let (op)
  6846. (setq e (substring e 1))
  6847. (setq op (string-to-char e) e (substring e 1))
  6848. (setq op (cond ((equal op ?<) '<=)
  6849. ((equal op ?>) '>=)
  6850. ((equal op ??) op)
  6851. (t '=)))
  6852. (list 'org-agenda-compare-effort (list 'quote op)
  6853. (org-duration-string-to-minutes e))))
  6854. (defun org-agenda-compare-effort (op value)
  6855. "Compare the effort of the current line with VALUE, using OP.
  6856. If the line does not have an effort defined, return nil."
  6857. (let ((eff (org-get-at-bol 'effort-minutes)))
  6858. (if (equal op ??)
  6859. (not eff)
  6860. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6861. value))))
  6862. (defun org-agenda-filter-apply (filter type)
  6863. "Set FILTER as the new agenda filter and apply it."
  6864. (let (tags cat)
  6865. (if (eq type 'tag)
  6866. (setq org-agenda-tag-filter filter)
  6867. (setq org-agenda-category-filter filter))
  6868. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6869. (if (and (eq type 'category)
  6870. (not (equal (substring (car filter) 0 1) "-")))
  6871. ;; Only set `org-agenda-filtered-by-category' to t
  6872. ;; when a unique category is used as the filter
  6873. (setq org-agenda-filtered-by-category t))
  6874. (org-agenda-set-mode-name)
  6875. (save-excursion
  6876. (goto-char (point-min))
  6877. (while (not (eobp))
  6878. (if (org-get-at-bol 'org-marker)
  6879. (progn
  6880. (setq tags (org-get-at-bol 'tags) ; used in eval
  6881. cat (get-text-property (point) 'org-category))
  6882. (if (not (eval org-agenda-filter-form))
  6883. (org-agenda-filter-hide-line type))
  6884. (beginning-of-line 2))
  6885. (beginning-of-line 2))))
  6886. (if (get-char-property (point) 'invisible)
  6887. (ignore-errors (org-agenda-previous-line)))))
  6888. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6889. "Set FILTER as the new agenda filter and apply it."
  6890. (org-agenda-set-mode-name)
  6891. (save-excursion
  6892. (goto-char (point-min))
  6893. (while (not (eobp))
  6894. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6895. (topcat (and pos (org-find-top-category pos))))
  6896. (if (and topcat (funcall (if negative 'identity 'not)
  6897. (string= category topcat)))
  6898. (org-agenda-filter-hide-line 'category)))
  6899. (beginning-of-line 2)))
  6900. (if (get-char-property (point) 'invisible)
  6901. (org-agenda-previous-line))
  6902. (setq org-agenda-top-category-filter category
  6903. org-agenda-filtered-by-top-category t))
  6904. (defun org-agenda-filter-hide-line (type)
  6905. (let (ov)
  6906. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6907. (point-at-eol)))
  6908. (overlay-put ov 'invisible t)
  6909. (overlay-put ov 'type type)
  6910. (if (eq type 'tag)
  6911. (push ov org-agenda-tag-filter-overlays)
  6912. (push ov org-agenda-cat-filter-overlays))))
  6913. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6914. (setq pos (or pos (point)))
  6915. (save-excursion
  6916. (dolist (ov (overlays-at pos))
  6917. (when (and (overlay-get ov 'invisible)
  6918. (eq (overlay-get ov 'type) 'tag))
  6919. (goto-char pos)
  6920. (if (< (overlay-start ov) (point-at-eol))
  6921. (move-overlay ov (point-at-eol)
  6922. (overlay-end ov)))))))
  6923. (defun org-agenda-filter-show-all-tag nil
  6924. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6925. (setq org-agenda-tag-filter-overlays nil
  6926. org-agenda-tag-filter nil
  6927. org-agenda-filter-form nil)
  6928. (org-agenda-set-mode-name))
  6929. (defun org-agenda-filter-show-all-cat nil
  6930. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6931. (setq org-agenda-cat-filter-overlays nil
  6932. org-agenda-filtered-by-category nil
  6933. org-agenda-category-filter nil
  6934. org-agenda-filter-form nil)
  6935. (org-agenda-set-mode-name))
  6936. (defun org-agenda-manipulate-query-add ()
  6937. "Manipulate the query by adding a search term with positive selection.
  6938. Positive selection means the term must be matched for selection of an entry."
  6939. (interactive)
  6940. (org-agenda-manipulate-query ?\[))
  6941. (defun org-agenda-manipulate-query-subtract ()
  6942. "Manipulate the query by adding a search term with negative selection.
  6943. Negative selection means term must not be matched for selection of an entry."
  6944. (interactive)
  6945. (org-agenda-manipulate-query ?\]))
  6946. (defun org-agenda-manipulate-query-add-re ()
  6947. "Manipulate the query by adding a search regexp with positive selection.
  6948. Positive selection means the regexp must match for selection of an entry."
  6949. (interactive)
  6950. (org-agenda-manipulate-query ?\{))
  6951. (defun org-agenda-manipulate-query-subtract-re ()
  6952. "Manipulate the query by adding a search regexp with negative selection.
  6953. Negative selection means regexp must not match for selection of an entry."
  6954. (interactive)
  6955. (org-agenda-manipulate-query ?\}))
  6956. (defun org-agenda-manipulate-query (char)
  6957. (cond
  6958. ((memq org-agenda-type '(timeline agenda))
  6959. (let ((org-agenda-include-inactive-timestamps t))
  6960. (org-agenda-redo))
  6961. (message "Display now includes inactive timestamps as well"))
  6962. ((eq org-agenda-type 'search)
  6963. (org-add-to-string
  6964. 'org-agenda-query-string
  6965. (if org-agenda-last-search-view-search-was-boolean
  6966. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6967. (?\{ . " +{}") (?\} . " -{}"))))
  6968. " "))
  6969. (setq org-agenda-redo-command
  6970. (list 'org-search-view
  6971. (car (get-text-property (min (1- (point-max)) (point))
  6972. 'org-last-args))
  6973. org-agenda-query-string
  6974. (+ (length org-agenda-query-string)
  6975. (if (member char '(?\{ ?\})) 0 1))))
  6976. (set-register org-agenda-query-register org-agenda-query-string)
  6977. (let ((org-agenda-overriding-arguments
  6978. (cdr org-agenda-redo-command)))
  6979. (org-agenda-redo)))
  6980. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6981. org-agenda-type))))
  6982. (defun org-add-to-string (var string)
  6983. (set var (concat (symbol-value var) string)))
  6984. (defun org-agenda-goto-date (span)
  6985. "Jump to DATE in agenda."
  6986. (interactive "P")
  6987. (let* ((org-read-date-prefer-future
  6988. (eval org-agenda-jump-prefer-future))
  6989. (date (org-read-date))
  6990. (org-agenda-sticky-orig org-agenda-sticky)
  6991. (org-agenda-buffer-tmp-name (buffer-name))
  6992. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6993. (0-arg (or current-prefix-arg (car args)))
  6994. (2-arg (nth 2 args))
  6995. (newcmd (list 'org-agenda-list 0-arg date
  6996. (org-agenda-span-to-ndays 2-arg)))
  6997. (newargs (cdr newcmd))
  6998. (inhibit-read-only t)
  6999. org-agenda-sticky)
  7000. (if (not (org-agenda-check-type t 'agenda))
  7001. (error "Not available in non-agenda blocks")
  7002. (add-text-properties (point-min) (point-max)
  7003. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7004. (org-agenda-redo)
  7005. (setq org-agenda-sticky org-agenda-sticky-orig
  7006. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7007. (defun org-agenda-goto-today ()
  7008. "Go to today."
  7009. (interactive)
  7010. (org-agenda-check-type t 'timeline 'agenda)
  7011. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7012. (curspan (nth 2 args))
  7013. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7014. (cond
  7015. (tdpos (goto-char tdpos))
  7016. ((eq org-agenda-type 'agenda)
  7017. (let* ((sd (org-agenda-compute-starting-span
  7018. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7019. (org-agenda-overriding-arguments args))
  7020. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7021. (org-agenda-redo)
  7022. (org-agenda-find-same-or-today-or-agenda)))
  7023. (t (error "Cannot find today")))))
  7024. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7025. (goto-char
  7026. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7027. (text-property-any (point-min) (point-max) 'org-today t)
  7028. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7029. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7030. (org-agenda-goto-block-beginning))
  7031. (point-min))))
  7032. (defun org-agenda-goto-block-beginning ()
  7033. "Go the agenda block beginning."
  7034. (interactive)
  7035. (if (not (derived-mode-p 'org-agenda-mode))
  7036. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7037. (let (dest)
  7038. (save-excursion
  7039. (unless (looking-at "\\'")
  7040. (forward-char))
  7041. (let* ((prop 'org-agenda-structural-header)
  7042. (p (previous-single-property-change (point) prop))
  7043. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7044. (1- (point))) prop)))
  7045. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7046. (if (not dest)
  7047. (error "Cannot find the beginning of the blog")
  7048. (goto-char dest)
  7049. (move-beginning-of-line 1)))))
  7050. (defun org-agenda-later (arg)
  7051. "Go forward in time by the current span.
  7052. With prefix ARG, go forward that many times the current span."
  7053. (interactive "p")
  7054. (org-agenda-check-type t 'agenda)
  7055. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7056. (span (or (nth 2 args) org-agenda-current-span))
  7057. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7058. (greg (calendar-gregorian-from-absolute sd))
  7059. (cnt (org-get-at-bol 'org-day-cnt))
  7060. greg2)
  7061. (cond
  7062. ((numberp span)
  7063. (setq sd (+ (* span arg) sd)))
  7064. ((eq span 'day)
  7065. (setq sd (+ arg sd)))
  7066. ((eq span 'week)
  7067. (setq sd (+ (* 7 arg) sd)))
  7068. ((eq span 'month)
  7069. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7070. sd (calendar-absolute-from-gregorian greg2))
  7071. (setcar greg2 (1+ (car greg2))))
  7072. ((eq span 'year)
  7073. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7074. sd (calendar-absolute-from-gregorian greg2))
  7075. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7076. (t
  7077. (setq sd (+ (* span arg) sd))))
  7078. (let ((org-agenda-overriding-cmd
  7079. ;; `cmd' may have been set by `org-agenda-run-series' which
  7080. ;; uses `org-agenda-overriding-cmd' to decide whether
  7081. ;; overriding is allowed for `cmd'
  7082. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7083. (org-agenda-overriding-arguments
  7084. (list (car args) sd span)))
  7085. (org-agenda-redo)
  7086. (org-agenda-find-same-or-today-or-agenda cnt))))
  7087. (defun org-agenda-earlier (arg)
  7088. "Go backward in time by the current span.
  7089. With prefix ARG, go backward that many times the current span."
  7090. (interactive "p")
  7091. (org-agenda-later (- arg)))
  7092. (defun org-agenda-view-mode-dispatch ()
  7093. "Call one of the view mode commands."
  7094. (interactive)
  7095. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  7096. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7097. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7098. (let ((a (read-char-exclusive)))
  7099. (case a
  7100. (?\ (call-interactively 'org-agenda-reset-view))
  7101. (?d (call-interactively 'org-agenda-day-view))
  7102. (?w (call-interactively 'org-agenda-week-view))
  7103. (?m (call-interactively 'org-agenda-month-view))
  7104. (?y (call-interactively 'org-agenda-year-view))
  7105. (?l (call-interactively 'org-agenda-log-mode))
  7106. (?L (org-agenda-log-mode '(4)))
  7107. (?c (org-agenda-log-mode 'clockcheck))
  7108. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7109. (?a (call-interactively 'org-agenda-archives-mode))
  7110. (?A (org-agenda-archives-mode 'files))
  7111. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7112. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7113. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7114. (?D (call-interactively 'org-agenda-toggle-diary))
  7115. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7116. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7117. (org-agenda-check-type t 'timeline 'agenda)
  7118. (org-agenda-redo))
  7119. (message "Display now includes inactive timestamps as well"))
  7120. (?q (message "Abort"))
  7121. (otherwise (error "Invalid key" )))))
  7122. (defun org-agenda-reset-view ()
  7123. "Switch to default view for agenda."
  7124. (interactive)
  7125. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7126. (defun org-agenda-day-view (&optional day-of-year)
  7127. "Switch to daily view for agenda.
  7128. With argument DAY-OF-YEAR, switch to that day of the year."
  7129. (interactive "P")
  7130. (org-agenda-change-time-span 'day day-of-year))
  7131. (defun org-agenda-week-view (&optional iso-week)
  7132. "Switch to daily view for agenda.
  7133. With argument ISO-WEEK, switch to the corresponding ISO week.
  7134. If ISO-WEEK has more then 2 digits, only the last two encode the
  7135. week. Any digits before this encode a year. So 200712 means
  7136. week 12 of year 2007. Years in the range 1938-2037 can also be
  7137. written as 2-digit years."
  7138. (interactive "P")
  7139. (org-agenda-change-time-span 'week iso-week))
  7140. (defun org-agenda-month-view (&optional month)
  7141. "Switch to monthly view for agenda.
  7142. With argument MONTH, switch to that month."
  7143. (interactive "P")
  7144. (org-agenda-change-time-span 'month month))
  7145. (defun org-agenda-year-view (&optional year)
  7146. "Switch to yearly view for agenda.
  7147. With argument YEAR, switch to that year.
  7148. If MONTH has more then 2 digits, only the last two encode the
  7149. month. Any digits before this encode a year. So 200712 means
  7150. December year 2007. Years in the range 1938-2037 can also be
  7151. written as 2-digit years."
  7152. (interactive "P")
  7153. (when year
  7154. (setq year (org-small-year-to-year year)))
  7155. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7156. (org-agenda-change-time-span 'year year)
  7157. (error "Abort")))
  7158. (defun org-agenda-change-time-span (span &optional n)
  7159. "Change the agenda view to SPAN.
  7160. SPAN may be `day', `week', `month', `year'."
  7161. (org-agenda-check-type t 'agenda)
  7162. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7163. (curspan (nth 2 args)))
  7164. (if (and (not n) (equal curspan span))
  7165. (error "Viewing span is already \"%s\"" span))
  7166. (let* ((sd (or (org-get-at-bol 'day)
  7167. (nth 1 args)
  7168. org-starting-day))
  7169. (sd (org-agenda-compute-starting-span sd span n))
  7170. (org-agenda-overriding-cmd
  7171. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7172. (org-agenda-overriding-arguments
  7173. (list (car args) sd span)))
  7174. (org-agenda-redo)
  7175. (org-agenda-find-same-or-today-or-agenda))
  7176. (org-agenda-set-mode-name)
  7177. (message "Switched to %s view" span)))
  7178. (defun org-agenda-compute-starting-span (sd span &optional n)
  7179. "Compute starting date for agenda.
  7180. SPAN may be `day', `week', `month', `year'. The return value
  7181. is a cons cell with the starting date and the number of days,
  7182. so that the date SD will be in that range."
  7183. (let* ((greg (calendar-gregorian-from-absolute sd))
  7184. (dg (nth 1 greg))
  7185. (mg (car greg))
  7186. (yg (nth 2 greg)))
  7187. (cond
  7188. ((eq span 'day)
  7189. (when n
  7190. (setq sd (+ (calendar-absolute-from-gregorian
  7191. (list mg 1 yg))
  7192. n -1))))
  7193. ((eq span 'week)
  7194. (let* ((nt (calendar-day-of-week
  7195. (calendar-gregorian-from-absolute sd)))
  7196. (d (if org-agenda-start-on-weekday
  7197. (- nt org-agenda-start-on-weekday)
  7198. 0))
  7199. y1)
  7200. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7201. (when n
  7202. (require 'cal-iso)
  7203. (when (> n 99)
  7204. (setq y1 (org-small-year-to-year (/ n 100))
  7205. n (mod n 100)))
  7206. (setq sd
  7207. (calendar-absolute-from-iso
  7208. (list n 1
  7209. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7210. ((eq span 'month)
  7211. (let (y1)
  7212. (when (and n (> n 99))
  7213. (setq y1 (org-small-year-to-year (/ n 100))
  7214. n (mod n 100)))
  7215. (setq sd (calendar-absolute-from-gregorian
  7216. (list (or n mg) 1 (or y1 yg))))))
  7217. ((eq span 'year)
  7218. (setq sd (calendar-absolute-from-gregorian
  7219. (list 1 1 (or n yg))))))
  7220. sd))
  7221. (defun org-agenda-next-date-line (&optional arg)
  7222. "Jump to the next line indicating a date in agenda buffer."
  7223. (interactive "p")
  7224. (org-agenda-check-type t 'agenda 'timeline)
  7225. (beginning-of-line 1)
  7226. ;; This does not work if user makes date format that starts with a blank
  7227. (if (looking-at "^\\S-") (forward-char 1))
  7228. (if (not (re-search-forward "^\\S-" nil t arg))
  7229. (progn
  7230. (backward-char 1)
  7231. (error "No next date after this line in this buffer")))
  7232. (goto-char (match-beginning 0)))
  7233. (defun org-agenda-previous-date-line (&optional arg)
  7234. "Jump to the previous line indicating a date in agenda buffer."
  7235. (interactive "p")
  7236. (org-agenda-check-type t 'agenda 'timeline)
  7237. (beginning-of-line 1)
  7238. (if (not (re-search-backward "^\\S-" nil t arg))
  7239. (error "No previous date before this line in this buffer")))
  7240. ;; Initialize the highlight
  7241. (defvar org-hl (make-overlay 1 1))
  7242. (overlay-put org-hl 'face 'highlight)
  7243. (defun org-highlight (begin end &optional buffer)
  7244. "Highlight a region with overlay."
  7245. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7246. (defun org-unhighlight ()
  7247. "Detach overlay INDEX."
  7248. (org-detach-overlay org-hl))
  7249. (defun org-unhighlight-once ()
  7250. "Remove the highlight from its position, and this function from the hook."
  7251. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7252. (org-unhighlight))
  7253. (defvar org-agenda-pre-follow-window-conf nil)
  7254. (defun org-agenda-follow-mode ()
  7255. "Toggle follow mode in an agenda buffer."
  7256. (interactive)
  7257. (unless org-agenda-follow-mode
  7258. (setq org-agenda-pre-follow-window-conf
  7259. (current-window-configuration)))
  7260. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7261. (unless org-agenda-follow-mode
  7262. (set-window-configuration org-agenda-pre-follow-window-conf))
  7263. (org-agenda-set-mode-name)
  7264. (org-agenda-do-context-action)
  7265. (message "Follow mode is %s"
  7266. (if org-agenda-follow-mode "on" "off")))
  7267. (defun org-agenda-entry-text-mode (&optional arg)
  7268. "Toggle entry text mode in an agenda buffer."
  7269. (interactive "P")
  7270. (setq org-agenda-entry-text-mode (or (integerp arg)
  7271. (not org-agenda-entry-text-mode)))
  7272. (org-agenda-entry-text-hide)
  7273. (and org-agenda-entry-text-mode
  7274. (let ((org-agenda-entry-text-maxlines
  7275. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7276. (org-agenda-entry-text-show)))
  7277. (org-agenda-set-mode-name)
  7278. (message "Entry text mode is %s. Maximum number of lines is %d"
  7279. (if org-agenda-entry-text-mode "on" "off")
  7280. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7281. (defun org-agenda-clockreport-mode (&optional with-filter)
  7282. "Toggle clocktable mode in an agenda buffer.
  7283. With prefix arg WITH-FILTER, make the clocktable respect the current
  7284. agenda filter."
  7285. (interactive "P")
  7286. (org-agenda-check-type t 'agenda)
  7287. (if with-filter
  7288. (setq org-agenda-clockreport-mode 'with-filter)
  7289. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7290. (org-agenda-set-mode-name)
  7291. (org-agenda-redo)
  7292. (message "Clocktable mode is %s"
  7293. (if org-agenda-clockreport-mode "on" "off")))
  7294. (defun org-agenda-log-mode (&optional special)
  7295. "Toggle log mode in an agenda buffer.
  7296. With argument SPECIAL, show all possible log items, not only the ones
  7297. configured in `org-agenda-log-mode-items'.
  7298. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7299. (interactive "P")
  7300. (org-agenda-check-type t 'agenda 'timeline)
  7301. (setq org-agenda-show-log
  7302. (cond
  7303. ((equal special '(16)) 'only)
  7304. ((eq special 'clockcheck)
  7305. (if (eq org-agenda-show-log 'clockcheck)
  7306. nil 'clockcheck))
  7307. (special '(closed clock state))
  7308. (t (not org-agenda-show-log))))
  7309. (org-agenda-set-mode-name)
  7310. (org-agenda-redo)
  7311. (message "Log mode is %s"
  7312. (if org-agenda-show-log "on" "off")))
  7313. (defun org-agenda-archives-mode (&optional with-files)
  7314. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7315. When called with a prefix argument, include all archive files as well."
  7316. (interactive "P")
  7317. (setq org-agenda-archives-mode
  7318. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7319. (org-agenda-set-mode-name)
  7320. (org-agenda-redo)
  7321. (message
  7322. "%s"
  7323. (cond
  7324. ((eq org-agenda-archives-mode nil)
  7325. "No archives are included")
  7326. ((eq org-agenda-archives-mode 'trees)
  7327. (format "Trees with :%s: tag are included" org-archive-tag))
  7328. ((eq org-agenda-archives-mode t)
  7329. (format "Trees with :%s: tag and all active archive files are included"
  7330. org-archive-tag)))))
  7331. (defun org-agenda-toggle-diary ()
  7332. "Toggle diary inclusion in an agenda buffer."
  7333. (interactive)
  7334. (org-agenda-check-type t 'agenda)
  7335. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7336. (org-agenda-redo)
  7337. (org-agenda-set-mode-name)
  7338. (message "Diary inclusion turned %s"
  7339. (if org-agenda-include-diary "on" "off")))
  7340. (defun org-agenda-toggle-deadlines ()
  7341. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7342. (interactive)
  7343. (org-agenda-check-type t 'agenda)
  7344. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7345. (org-agenda-redo)
  7346. (org-agenda-set-mode-name)
  7347. (message "Deadlines inclusion turned %s"
  7348. (if org-agenda-include-deadlines "on" "off")))
  7349. (defun org-agenda-toggle-time-grid ()
  7350. "Toggle time grid in an agenda buffer."
  7351. (interactive)
  7352. (org-agenda-check-type t 'agenda)
  7353. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7354. (org-agenda-redo)
  7355. (org-agenda-set-mode-name)
  7356. (message "Time-grid turned %s"
  7357. (if org-agenda-use-time-grid "on" "off")))
  7358. (defun org-agenda-set-mode-name ()
  7359. "Set the mode name to indicate all the small mode settings."
  7360. (setq mode-name
  7361. (list "Org-Agenda"
  7362. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7363. " "
  7364. '(:eval (org-agenda-span-name org-agenda-current-span))
  7365. (if org-agenda-follow-mode " Follow" "")
  7366. (if org-agenda-entry-text-mode " ETxt" "")
  7367. (if org-agenda-include-diary " Diary" "")
  7368. (if org-agenda-include-deadlines " Ddl" "")
  7369. (if org-agenda-use-time-grid " Grid" "")
  7370. (if (and (boundp 'org-habit-show-habits)
  7371. org-habit-show-habits) " Habit" "")
  7372. (cond
  7373. ((consp org-agenda-show-log) " LogAll")
  7374. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7375. (org-agenda-show-log " Log")
  7376. (t ""))
  7377. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7378. :preset-filter))
  7379. '(:eval (org-propertize
  7380. (concat " <"
  7381. (mapconcat
  7382. 'identity
  7383. (append
  7384. (get 'org-agenda-category-filter :preset-filter)
  7385. org-agenda-category-filter)
  7386. "")
  7387. ">")
  7388. 'face 'org-agenda-filter-category
  7389. 'help-echo "Category used in filtering"))
  7390. "")
  7391. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7392. :preset-filter))
  7393. '(:eval (org-propertize
  7394. (concat " {"
  7395. (mapconcat
  7396. 'identity
  7397. (append
  7398. (get 'org-agenda-tag-filter :preset-filter)
  7399. org-agenda-tag-filter)
  7400. "")
  7401. "}")
  7402. 'face 'org-agenda-filter-tags
  7403. 'help-echo "Tags used in filtering"))
  7404. "")
  7405. (if org-agenda-archives-mode
  7406. (if (eq org-agenda-archives-mode t)
  7407. " Archives"
  7408. (format " :%s:" org-archive-tag))
  7409. "")
  7410. (if org-agenda-clockreport-mode
  7411. (if (eq org-agenda-clockreport-mode 'with-filter)
  7412. " Clock{}" " Clock")
  7413. "")))
  7414. (force-mode-line-update))
  7415. (define-obsolete-function-alias
  7416. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7417. (defun org-agenda-update-agenda-type ()
  7418. "Update the agenda type after each command."
  7419. (setq org-agenda-type
  7420. (or (get-text-property (point) 'org-agenda-type)
  7421. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7422. (defun org-agenda-next-line ()
  7423. "Move cursor to the next line, and show if follow mode is active."
  7424. (interactive)
  7425. (call-interactively 'next-line)
  7426. (org-agenda-do-context-action))
  7427. (defun org-agenda-previous-line ()
  7428. "Move cursor to the previous line, and show if follow-mode is active."
  7429. (interactive)
  7430. (call-interactively 'previous-line)
  7431. (org-agenda-do-context-action))
  7432. (defun org-agenda-next-item (n)
  7433. "Move cursor to next agenda item."
  7434. (interactive "p")
  7435. (let ((col (current-column)))
  7436. (dotimes (c n)
  7437. (when (next-single-property-change (point-at-eol) 'org-marker)
  7438. (move-end-of-line 1)
  7439. (goto-char (next-single-property-change (point) 'org-marker))))
  7440. (org-move-to-column col))
  7441. (org-agenda-do-context-action))
  7442. (defun org-agenda-previous-item (n)
  7443. "Move cursor to next agenda item."
  7444. (interactive "p")
  7445. (dotimes (c n)
  7446. (let ((col (current-column))
  7447. (goto (save-excursion
  7448. (move-end-of-line 0)
  7449. (previous-single-property-change (point) 'org-marker))))
  7450. (if goto (goto-char goto))
  7451. (org-move-to-column col)))
  7452. (org-agenda-do-context-action))
  7453. (defun org-agenda-do-context-action ()
  7454. "Show outline path and, maybe, follow mode window."
  7455. (let ((m (org-get-at-bol 'org-marker)))
  7456. (when (and (markerp m) (marker-buffer m))
  7457. (and org-agenda-follow-mode
  7458. (if org-agenda-follow-indirect
  7459. (org-agenda-tree-to-indirect-buffer nil)
  7460. (org-agenda-show)))
  7461. (and org-agenda-show-outline-path
  7462. (org-with-point-at m (org-display-outline-path t))))))
  7463. (defun org-agenda-show-tags ()
  7464. "Show the tags applicable to the current item."
  7465. (interactive)
  7466. (let* ((tags (org-get-at-bol 'tags)))
  7467. (if tags
  7468. (message "Tags are :%s:"
  7469. (org-no-properties (mapconcat 'identity tags ":")))
  7470. (message "No tags associated with this line"))))
  7471. (defun org-agenda-goto (&optional highlight)
  7472. "Go to the Org-mode file which contains the item at point."
  7473. (interactive)
  7474. (let* ((marker (or (org-get-at-bol 'org-marker)
  7475. (org-agenda-error)))
  7476. (buffer (marker-buffer marker))
  7477. (pos (marker-position marker)))
  7478. (switch-to-buffer-other-window buffer)
  7479. (widen)
  7480. (push-mark)
  7481. (goto-char pos)
  7482. (when (derived-mode-p 'org-mode)
  7483. (org-show-context 'agenda)
  7484. (save-excursion
  7485. (and (outline-next-heading)
  7486. (org-flag-heading nil)))) ; show the next heading
  7487. (when (outline-invisible-p)
  7488. (show-entry)) ; display invisible text
  7489. (recenter (/ (window-height) 2))
  7490. (run-hooks 'org-agenda-after-show-hook)
  7491. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7492. (defvar org-agenda-after-show-hook nil
  7493. "Normal hook run after an item has been shown from the agenda.
  7494. Point is in the buffer where the item originated.")
  7495. (defun org-agenda-kill ()
  7496. "Kill the entry or subtree belonging to the current agenda entry."
  7497. (interactive)
  7498. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7499. (let* ((bufname-orig (buffer-name))
  7500. (marker (or (org-get-at-bol 'org-marker)
  7501. (org-agenda-error)))
  7502. (buffer (marker-buffer marker))
  7503. (pos (marker-position marker))
  7504. (type (org-get-at-bol 'type))
  7505. dbeg dend (n 0) conf)
  7506. (org-with-remote-undo buffer
  7507. (with-current-buffer buffer
  7508. (save-excursion
  7509. (goto-char pos)
  7510. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7511. (setq dbeg (progn (org-back-to-heading t) (point))
  7512. dend (org-end-of-subtree t t))
  7513. (setq dbeg (point-at-bol)
  7514. dend (min (point-max) (1+ (point-at-eol)))))
  7515. (goto-char dbeg)
  7516. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7517. (setq conf (or (eq t org-agenda-confirm-kill)
  7518. (and (numberp org-agenda-confirm-kill)
  7519. (> n org-agenda-confirm-kill))))
  7520. (and conf
  7521. (not (y-or-n-p
  7522. (format "Delete entry with %d lines in buffer \"%s\"? "
  7523. n (buffer-name buffer))))
  7524. (error "Abort"))
  7525. (let ((org-agenda-buffer-name bufname-orig))
  7526. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7527. (with-current-buffer buffer (delete-region dbeg dend))
  7528. (message "Agenda item and source killed"))))
  7529. (defvar org-archive-default-command) ; defined in org-archive.el
  7530. (defun org-agenda-archive-default ()
  7531. "Archive the entry or subtree belonging to the current agenda entry."
  7532. (interactive)
  7533. (require 'org-archive)
  7534. (org-agenda-archive-with org-archive-default-command))
  7535. (defun org-agenda-archive-default-with-confirmation ()
  7536. "Archive the entry or subtree belonging to the current agenda entry."
  7537. (interactive)
  7538. (require 'org-archive)
  7539. (org-agenda-archive-with org-archive-default-command 'confirm))
  7540. (defun org-agenda-archive ()
  7541. "Archive the entry or subtree belonging to the current agenda entry."
  7542. (interactive)
  7543. (org-agenda-archive-with 'org-archive-subtree))
  7544. (defun org-agenda-archive-to-archive-sibling ()
  7545. "Move the entry to the archive sibling."
  7546. (interactive)
  7547. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7548. (defun org-agenda-archive-with (cmd &optional confirm)
  7549. "Move the entry to the archive sibling."
  7550. (interactive)
  7551. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7552. (let* ((bufname-orig (buffer-name))
  7553. (marker (or (org-get-at-bol 'org-marker)
  7554. (org-agenda-error)))
  7555. (buffer (marker-buffer marker))
  7556. (pos (marker-position marker)))
  7557. (org-with-remote-undo buffer
  7558. (with-current-buffer buffer
  7559. (if (derived-mode-p 'org-mode)
  7560. (if (and confirm
  7561. (not (y-or-n-p "Archive this subtree or entry? ")))
  7562. (error "Abort")
  7563. (save-excursion
  7564. (goto-char pos)
  7565. (let ((org-agenda-buffer-name bufname-orig))
  7566. (org-remove-subtree-entries-from-agenda))
  7567. (org-back-to-heading t)
  7568. (funcall cmd)))
  7569. (error "Archiving works only in Org-mode files"))))))
  7570. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7571. "Remove all lines in the agenda that correspond to a given subtree.
  7572. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7573. If this information is not given, the function uses the tree at point."
  7574. (let ((buf (or buf (current-buffer))) m p)
  7575. (save-excursion
  7576. (unless (and beg end)
  7577. (org-back-to-heading t)
  7578. (setq beg (point))
  7579. (org-end-of-subtree t)
  7580. (setq end (point)))
  7581. (set-buffer (get-buffer org-agenda-buffer-name))
  7582. (save-excursion
  7583. (goto-char (point-max))
  7584. (beginning-of-line 1)
  7585. (while (not (bobp))
  7586. (when (and (setq m (org-get-at-bol 'org-marker))
  7587. (equal buf (marker-buffer m))
  7588. (setq p (marker-position m))
  7589. (>= p beg)
  7590. (< p end))
  7591. (let ((inhibit-read-only t))
  7592. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7593. (beginning-of-line 0))))))
  7594. (defun org-agenda-refile (&optional goto rfloc no-update)
  7595. "Refile the item at point."
  7596. (interactive "P")
  7597. (if (equal goto '(16))
  7598. (org-refile-goto-last-stored)
  7599. (let* ((buffer-orig (buffer-name))
  7600. (marker (or (org-get-at-bol 'org-hd-marker)
  7601. (org-agenda-error)))
  7602. (buffer (marker-buffer marker))
  7603. (pos (marker-position marker))
  7604. (rfloc (or rfloc
  7605. (org-refile-get-location
  7606. (if goto "Goto" "Refile to") buffer
  7607. org-refile-allow-creating-parent-nodes))))
  7608. (with-current-buffer buffer
  7609. (save-excursion
  7610. (save-restriction
  7611. (widen)
  7612. (goto-char marker)
  7613. (let ((org-agenda-buffer-name buffer-orig))
  7614. (org-remove-subtree-entries-from-agenda))
  7615. (org-refile goto buffer rfloc)))))
  7616. (unless no-update (org-agenda-redo))))
  7617. (defun org-agenda-open-link (&optional arg)
  7618. "Open the link(s) in the current entry, if any.
  7619. This looks for a link in the displayed line in the agenda.
  7620. It also looks at the text of the entry itself."
  7621. (interactive "P")
  7622. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7623. (org-get-at-bol 'org-marker)))
  7624. (buffer (and marker (marker-buffer marker)))
  7625. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7626. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7627. (lk0 (car lkall))
  7628. (lk (if (stringp lk0) (list lk0) lk0))
  7629. (lkend (cdr lkall))
  7630. trg)
  7631. (cond
  7632. ((and buffer lk)
  7633. (mapcar (lambda(l)
  7634. (with-current-buffer buffer
  7635. (setq trg (and (string-match org-bracket-link-regexp l)
  7636. (match-string 1 l)))
  7637. (if (or (not trg) (string-match org-any-link-re trg))
  7638. (save-excursion
  7639. (save-restriction
  7640. (widen)
  7641. (goto-char marker)
  7642. (when (search-forward l nil lkend)
  7643. (goto-char (match-beginning 0))
  7644. (org-open-at-point))))
  7645. ;; This is an internal link, widen the buffer
  7646. (switch-to-buffer-other-window buffer)
  7647. (widen)
  7648. (goto-char marker)
  7649. (when (search-forward l nil lkend)
  7650. (goto-char (match-beginning 0))
  7651. (org-open-at-point)))))
  7652. lk))
  7653. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7654. (save-excursion
  7655. (beginning-of-line 1)
  7656. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7657. (org-open-link-from-string (match-string 1)))
  7658. (t (message "No link to open here")))))
  7659. (defun org-agenda-copy-local-variable (var)
  7660. "Get a variable from a referenced buffer and install it here."
  7661. (let ((m (org-get-at-bol 'org-marker)))
  7662. (when (and m (buffer-live-p (marker-buffer m)))
  7663. (org-set-local var (with-current-buffer (marker-buffer m)
  7664. (symbol-value var))))))
  7665. (defun org-agenda-switch-to (&optional delete-other-windows)
  7666. "Go to the Org-mode file which contains the item at point."
  7667. (interactive)
  7668. (if (and org-return-follows-link
  7669. (not (org-get-at-bol 'org-marker))
  7670. (org-in-regexp org-bracket-link-regexp))
  7671. (org-open-link-from-string (match-string 0))
  7672. (let* ((marker (or (org-get-at-bol 'org-marker)
  7673. (org-agenda-error)))
  7674. (buffer (marker-buffer marker))
  7675. (pos (marker-position marker)))
  7676. (org-pop-to-buffer-same-window buffer)
  7677. (and delete-other-windows (delete-other-windows))
  7678. (widen)
  7679. (goto-char pos)
  7680. (when (derived-mode-p 'org-mode)
  7681. (org-show-context 'agenda)
  7682. (save-excursion
  7683. (and (outline-next-heading)
  7684. (org-flag-heading nil))) ; show the next heading
  7685. (when (outline-invisible-p)
  7686. (show-entry)) ; display invisible text
  7687. (run-hooks 'org-agenda-after-show-hook)))))
  7688. (defun org-agenda-goto-mouse (ev)
  7689. "Go to the Org-mode file which contains the item at the mouse click."
  7690. (interactive "e")
  7691. (mouse-set-point ev)
  7692. (org-agenda-goto))
  7693. (defun org-agenda-show (&optional full-entry)
  7694. "Display the Org-mode file which contains the item at point.
  7695. With prefix argument FULL-ENTRY, make the entire entry visible
  7696. if it was hidden in the outline."
  7697. (interactive "P")
  7698. (let ((win (selected-window)))
  7699. (if full-entry
  7700. (let ((org-show-entry-below t))
  7701. (org-agenda-goto t))
  7702. (org-agenda-goto t))
  7703. (select-window win)))
  7704. (defvar org-agenda-show-window nil)
  7705. (defun org-agenda-show-and-scroll-up (&optional arg)
  7706. "Display the Org-mode file which contains the item at point.
  7707. When called repeatedly, scroll the window that is displaying the buffer.
  7708. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7709. `show-subtree' to display the item, so that drawers and logbooks stay
  7710. folded."
  7711. (interactive "P")
  7712. (let ((win (selected-window)))
  7713. (if (and (window-live-p org-agenda-show-window)
  7714. (eq this-command last-command))
  7715. (progn
  7716. (select-window org-agenda-show-window)
  7717. (ignore-errors (scroll-up)))
  7718. (org-agenda-goto t)
  7719. (if arg (org-show-entry) (show-subtree))
  7720. (setq org-agenda-show-window (selected-window)))
  7721. (select-window win)))
  7722. (defun org-agenda-show-scroll-down ()
  7723. "Scroll down the window showing the agenda."
  7724. (interactive)
  7725. (let ((win (selected-window)))
  7726. (when (window-live-p org-agenda-show-window)
  7727. (select-window org-agenda-show-window)
  7728. (ignore-errors (scroll-down))
  7729. (select-window win))))
  7730. (defun org-agenda-show-1 (&optional more)
  7731. "Display the Org-mode file which contains the item at point.
  7732. The prefix arg selects the amount of information to display:
  7733. 0 hide the subtree
  7734. 1 just show the entry according to defaults.
  7735. 2 show the children view
  7736. 3 show the subtree view
  7737. 4 show the entire subtree and any LOGBOOK drawers
  7738. 5 show the entire subtree and any drawers
  7739. With prefix argument FULL-ENTRY, make the entire entry visible
  7740. if it was hidden in the outline."
  7741. (interactive "p")
  7742. (let ((win (selected-window)))
  7743. (org-agenda-goto t)
  7744. (org-recenter-heading 1)
  7745. (cond
  7746. ((= more 0)
  7747. (hide-subtree)
  7748. (save-excursion
  7749. (org-back-to-heading)
  7750. (run-hook-with-args 'org-cycle-hook 'folded))
  7751. (message "Remote: FOLDED"))
  7752. ((and (org-called-interactively-p 'any) (= more 1))
  7753. (message "Remote: show with default settings"))
  7754. ((= more 2)
  7755. (show-entry)
  7756. (show-children)
  7757. (save-excursion
  7758. (org-back-to-heading)
  7759. (run-hook-with-args 'org-cycle-hook 'children))
  7760. (message "Remote: CHILDREN"))
  7761. ((= more 3)
  7762. (show-subtree)
  7763. (save-excursion
  7764. (org-back-to-heading)
  7765. (run-hook-with-args 'org-cycle-hook 'subtree))
  7766. (message "Remote: SUBTREE"))
  7767. ((= more 4)
  7768. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7769. (org-drawer-regexp
  7770. (concat "^[ \t]*:\\("
  7771. (mapconcat 'regexp-quote org-drawers "\\|")
  7772. "\\):[ \t]*$")))
  7773. (show-subtree)
  7774. (save-excursion
  7775. (org-back-to-heading)
  7776. (org-cycle-hide-drawers 'subtree)))
  7777. (message "Remote: SUBTREE AND LOGBOOK"))
  7778. ((> more 4)
  7779. (show-subtree)
  7780. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7781. (select-window win)))
  7782. (defun org-recenter-heading (n)
  7783. (save-excursion
  7784. (org-back-to-heading)
  7785. (recenter n)))
  7786. (defvar org-agenda-cycle-counter nil)
  7787. (defun org-agenda-cycle-show (&optional n)
  7788. "Show the current entry in another window, with default settings.
  7789. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7790. When use repeatedly in immediate succession, the remote entry will cycle
  7791. through visibility
  7792. children -> subtree -> folded
  7793. When called with a numeric prefix arg, that arg will be passed through to
  7794. `org-agenda-show-1'. For the interpretation of that argument, see the
  7795. docstring of `org-agenda-show-1'."
  7796. (interactive "P")
  7797. (if (integerp n)
  7798. (setq org-agenda-cycle-counter n)
  7799. (if (not (eq last-command this-command))
  7800. (setq org-agenda-cycle-counter 1)
  7801. (if (equal org-agenda-cycle-counter 0)
  7802. (setq org-agenda-cycle-counter 2)
  7803. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7804. (if (> org-agenda-cycle-counter 3)
  7805. (setq org-agenda-cycle-counter 0)))))
  7806. (org-agenda-show-1 org-agenda-cycle-counter))
  7807. (defun org-agenda-recenter (arg)
  7808. "Display the Org-mode file which contains the item at point and recenter."
  7809. (interactive "P")
  7810. (let ((win (selected-window)))
  7811. (org-agenda-goto t)
  7812. (recenter arg)
  7813. (select-window win)))
  7814. (defun org-agenda-show-mouse (ev)
  7815. "Display the Org-mode file which contains the item at the mouse click."
  7816. (interactive "e")
  7817. (mouse-set-point ev)
  7818. (org-agenda-show))
  7819. (defun org-agenda-check-no-diary ()
  7820. "Check if the entry is a diary link and abort if yes."
  7821. (if (org-get-at-bol 'org-agenda-diary-link)
  7822. (org-agenda-error)))
  7823. (defun org-agenda-error ()
  7824. (error "Command not allowed in this line"))
  7825. (defun org-agenda-tree-to-indirect-buffer (arg)
  7826. "Show the subtree corresponding to the current entry in an indirect buffer.
  7827. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7828. With a numerical prefix ARG, go up to this level and then take that tree.
  7829. With a negative numeric ARG, go up by this number of levels.
  7830. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7831. use the dedicated frame)."
  7832. (interactive "P")
  7833. (if current-prefix-arg
  7834. (org-agenda-do-tree-to-indirect-buffer arg)
  7835. (let ((agenda-buffer (buffer-name))
  7836. (agenda-window (selected-window))
  7837. (indirect-window
  7838. (and org-last-indirect-buffer
  7839. (get-buffer-window org-last-indirect-buffer))))
  7840. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7841. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7842. (eq org-indirect-buffer-display 'dedicated-frame))
  7843. (unwind-protect
  7844. (unless (and indirect-window (window-live-p indirect-window))
  7845. (setq indirect-window (split-window agenda-window)))
  7846. (and indirect-window (select-window indirect-window))
  7847. (switch-to-buffer org-last-indirect-buffer :norecord)
  7848. (fit-window-to-buffer indirect-window)))
  7849. (select-window (get-buffer-window agenda-buffer)))))
  7850. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7851. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7852. (org-agenda-check-no-diary)
  7853. (let* ((marker (or (org-get-at-bol 'org-marker)
  7854. (org-agenda-error)))
  7855. (buffer (marker-buffer marker))
  7856. (pos (marker-position marker)))
  7857. (with-current-buffer buffer
  7858. (save-excursion
  7859. (goto-char pos)
  7860. (funcall 'org-tree-to-indirect-buffer arg)))))
  7861. (defvar org-last-heading-marker (make-marker)
  7862. "Marker pointing to the headline that last changed its TODO state
  7863. by a remote command from the agenda.")
  7864. (defun org-agenda-todo-nextset ()
  7865. "Switch TODO entry to next sequence."
  7866. (interactive)
  7867. (org-agenda-todo 'nextset))
  7868. (defun org-agenda-todo-previousset ()
  7869. "Switch TODO entry to previous sequence."
  7870. (interactive)
  7871. (org-agenda-todo 'previousset))
  7872. (defun org-agenda-todo (&optional arg)
  7873. "Cycle TODO state of line at point, also in Org-mode file.
  7874. This changes the line at point, all other lines in the agenda referring to
  7875. the same tree node, and the headline of the tree node in the Org-mode file."
  7876. (interactive "P")
  7877. (org-agenda-check-no-diary)
  7878. (let* ((col (current-column))
  7879. (marker (or (org-get-at-bol 'org-marker)
  7880. (org-agenda-error)))
  7881. (buffer (marker-buffer marker))
  7882. (pos (marker-position marker))
  7883. (hdmarker (org-get-at-bol 'org-hd-marker))
  7884. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7885. (inhibit-read-only t)
  7886. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7887. (org-with-remote-undo buffer
  7888. (with-current-buffer buffer
  7889. (widen)
  7890. (goto-char pos)
  7891. (org-show-context 'agenda)
  7892. (save-excursion
  7893. (and (outline-next-heading)
  7894. (org-flag-heading nil))) ; show the next heading
  7895. (let ((current-prefix-arg arg))
  7896. (call-interactively 'org-todo))
  7897. (and (bolp) (forward-char 1))
  7898. (setq newhead (org-get-heading))
  7899. (when (and (org-bound-and-true-p
  7900. org-agenda-headline-snapshot-before-repeat)
  7901. (not (equal org-agenda-headline-snapshot-before-repeat
  7902. newhead))
  7903. todayp)
  7904. (setq newhead org-agenda-headline-snapshot-before-repeat
  7905. just-one t))
  7906. (save-excursion
  7907. (org-back-to-heading)
  7908. (move-marker org-last-heading-marker (point))))
  7909. (beginning-of-line 1)
  7910. (save-excursion
  7911. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7912. (org-move-to-column col))))
  7913. (defun org-agenda-add-note (&optional arg)
  7914. "Add a time-stamped note to the entry at point."
  7915. (interactive "P")
  7916. (org-agenda-check-no-diary)
  7917. (let* ((marker (or (org-get-at-bol 'org-marker)
  7918. (org-agenda-error)))
  7919. (buffer (marker-buffer marker))
  7920. (pos (marker-position marker))
  7921. (hdmarker (org-get-at-bol 'org-hd-marker))
  7922. (inhibit-read-only t))
  7923. (with-current-buffer buffer
  7924. (widen)
  7925. (goto-char pos)
  7926. (org-show-context 'agenda)
  7927. (save-excursion
  7928. (and (outline-next-heading)
  7929. (org-flag-heading nil))) ; show the next heading
  7930. (org-add-note))))
  7931. (defun org-agenda-change-all-lines (newhead hdmarker
  7932. &optional fixface just-this)
  7933. "Change all lines in the agenda buffer which match HDMARKER.
  7934. The new content of the line will be NEWHEAD (as modified by
  7935. `org-agenda-format-item'). HDMARKER is checked with
  7936. `equal' against all `org-hd-marker' text properties in the file.
  7937. If FIXFACE is non-nil, the face of each item is modified according to
  7938. the new TODO state.
  7939. If JUST-THIS is non-nil, change just the current line, not all.
  7940. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7941. (let* ((inhibit-read-only t)
  7942. (line (org-current-line))
  7943. (org-agenda-buffer (current-buffer))
  7944. (thetags (with-current-buffer (marker-buffer hdmarker)
  7945. (save-excursion (save-restriction (widen)
  7946. (goto-char hdmarker)
  7947. (org-get-tags-at)))))
  7948. props m pl undone-face done-face finish new dotime level cat tags)
  7949. (save-excursion
  7950. (goto-char (point-max))
  7951. (beginning-of-line 1)
  7952. (while (not finish)
  7953. (setq finish (bobp))
  7954. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7955. (or (not just-this) (= (org-current-line) line))
  7956. (equal m hdmarker))
  7957. (setq props (text-properties-at (point))
  7958. dotime (org-get-at-bol 'dotime)
  7959. cat (org-get-at-bol 'org-category)
  7960. level (org-get-at-bol 'level)
  7961. tags thetags
  7962. new
  7963. (let ((org-prefix-format-compiled
  7964. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7965. org-prefix-format-compiled))
  7966. (extra (org-get-at-bol 'extra)))
  7967. (with-current-buffer (marker-buffer hdmarker)
  7968. (save-excursion
  7969. (save-restriction
  7970. (widen)
  7971. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7972. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7973. undone-face (org-get-at-bol 'undone-face)
  7974. done-face (org-get-at-bol 'done-face))
  7975. (beginning-of-line 1)
  7976. (cond
  7977. ((equal new "")
  7978. (and (looking-at ".*\n?") (replace-match "")))
  7979. ((looking-at ".*")
  7980. (replace-match new t t)
  7981. (beginning-of-line 1)
  7982. (add-text-properties (point-at-bol) (point-at-eol) props)
  7983. (when fixface
  7984. (add-text-properties
  7985. (point-at-bol) (point-at-eol)
  7986. (list 'face
  7987. (if org-last-todo-state-is-todo
  7988. undone-face done-face))))
  7989. (org-agenda-highlight-todo 'line)
  7990. (beginning-of-line 1))
  7991. (t (error "Line update did not work")))
  7992. (save-restriction
  7993. (narrow-to-region (point-at-bol) (point-at-eol))
  7994. (org-agenda-finalize)))
  7995. (beginning-of-line 0)))))
  7996. (defun org-agenda-align-tags (&optional line)
  7997. "Align all tags in agenda items to `org-agenda-tags-column'."
  7998. (let ((inhibit-read-only t) l c)
  7999. (save-excursion
  8000. (goto-char (if line (point-at-bol) (point-min)))
  8001. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8002. (if line (point-at-eol) nil) t)
  8003. (add-text-properties
  8004. (match-beginning 2) (match-end 2)
  8005. (list 'face (delq nil (let ((prop (get-text-property
  8006. (match-beginning 2) 'face)))
  8007. (or (listp prop) (setq prop (list prop)))
  8008. (if (memq 'org-tag prop)
  8009. prop
  8010. (cons 'org-tag prop))))))
  8011. (setq l (- (match-end 2) (match-beginning 2))
  8012. c (if (< org-agenda-tags-column 0)
  8013. (- (abs org-agenda-tags-column) l)
  8014. org-agenda-tags-column))
  8015. (delete-region (match-beginning 1) (match-end 1))
  8016. (goto-char (match-beginning 1))
  8017. (insert (org-add-props
  8018. (make-string (max 1 (- c (current-column))) ?\ )
  8019. (plist-put (copy-sequence (text-properties-at (point)))
  8020. 'face nil))))
  8021. (goto-char (point-min))
  8022. (org-font-lock-add-tag-faces (point-max)))))
  8023. (defun org-agenda-priority-up ()
  8024. "Increase the priority of line at point, also in Org-mode file."
  8025. (interactive)
  8026. (org-agenda-priority 'up))
  8027. (defun org-agenda-priority-down ()
  8028. "Decrease the priority of line at point, also in Org-mode file."
  8029. (interactive)
  8030. (org-agenda-priority 'down))
  8031. (defun org-agenda-priority (&optional force-direction)
  8032. "Set the priority of line at point, also in Org-mode file.
  8033. This changes the line at point, all other lines in the agenda referring to
  8034. the same tree node, and the headline of the tree node in the Org-mode file.
  8035. Called with a universal prefix arg, show the priority instead of setting it."
  8036. (interactive "P")
  8037. (if (equal force-direction '(4))
  8038. (org-show-priority)
  8039. (unless org-enable-priority-commands
  8040. (error "Priority commands are disabled"))
  8041. (org-agenda-check-no-diary)
  8042. (let* ((marker (or (org-get-at-bol 'org-marker)
  8043. (org-agenda-error)))
  8044. (hdmarker (org-get-at-bol 'org-hd-marker))
  8045. (buffer (marker-buffer hdmarker))
  8046. (pos (marker-position hdmarker))
  8047. (inhibit-read-only t)
  8048. newhead)
  8049. (org-with-remote-undo buffer
  8050. (with-current-buffer buffer
  8051. (widen)
  8052. (goto-char pos)
  8053. (org-show-context 'agenda)
  8054. (save-excursion
  8055. (and (outline-next-heading)
  8056. (org-flag-heading nil))) ; show the next heading
  8057. (funcall 'org-priority force-direction)
  8058. (end-of-line 1)
  8059. (setq newhead (org-get-heading)))
  8060. (org-agenda-change-all-lines newhead hdmarker)
  8061. (beginning-of-line 1)))))
  8062. ;; FIXME: should fix the tags property of the agenda line.
  8063. (defun org-agenda-set-tags (&optional tag onoff)
  8064. "Set tags for the current headline."
  8065. (interactive)
  8066. (org-agenda-check-no-diary)
  8067. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8068. (call-interactively 'org-change-tag-in-region)
  8069. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8070. (org-agenda-error)))
  8071. (buffer (marker-buffer hdmarker))
  8072. (pos (marker-position hdmarker))
  8073. (inhibit-read-only t)
  8074. newhead)
  8075. (org-with-remote-undo buffer
  8076. (with-current-buffer buffer
  8077. (widen)
  8078. (goto-char pos)
  8079. (save-excursion
  8080. (org-show-context 'agenda))
  8081. (save-excursion
  8082. (and (outline-next-heading)
  8083. (org-flag-heading nil))) ; show the next heading
  8084. (goto-char pos)
  8085. (if tag
  8086. (org-toggle-tag tag onoff)
  8087. (call-interactively 'org-set-tags))
  8088. (end-of-line 1)
  8089. (setq newhead (org-get-heading)))
  8090. (org-agenda-change-all-lines newhead hdmarker)
  8091. (beginning-of-line 1)))))
  8092. (defun org-agenda-set-property ()
  8093. "Set a property for the current headline."
  8094. (interactive)
  8095. (org-agenda-check-no-diary)
  8096. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8097. (org-agenda-error)))
  8098. (buffer (marker-buffer hdmarker))
  8099. (pos (marker-position hdmarker))
  8100. (inhibit-read-only t)
  8101. newhead)
  8102. (org-with-remote-undo buffer
  8103. (with-current-buffer buffer
  8104. (widen)
  8105. (goto-char pos)
  8106. (save-excursion
  8107. (org-show-context 'agenda))
  8108. (save-excursion
  8109. (and (outline-next-heading)
  8110. (org-flag-heading nil))) ; show the next heading
  8111. (goto-char pos)
  8112. (call-interactively 'org-set-property)))))
  8113. (defun org-agenda-set-effort ()
  8114. "Set the effort property for the current headline."
  8115. (interactive)
  8116. (org-agenda-check-no-diary)
  8117. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8118. (org-agenda-error)))
  8119. (buffer (marker-buffer hdmarker))
  8120. (pos (marker-position hdmarker))
  8121. (inhibit-read-only t)
  8122. newhead)
  8123. (org-with-remote-undo buffer
  8124. (with-current-buffer buffer
  8125. (widen)
  8126. (goto-char pos)
  8127. (save-excursion
  8128. (org-show-context 'agenda))
  8129. (save-excursion
  8130. (and (outline-next-heading)
  8131. (org-flag-heading nil))) ; show the next heading
  8132. (goto-char pos)
  8133. (call-interactively 'org-set-effort)
  8134. (end-of-line 1)
  8135. (setq newhead (org-get-heading)))
  8136. (org-agenda-change-all-lines newhead hdmarker))))
  8137. (defun org-agenda-toggle-archive-tag ()
  8138. "Toggle the archive tag for the current entry."
  8139. (interactive)
  8140. (org-agenda-check-no-diary)
  8141. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8142. (org-agenda-error)))
  8143. (buffer (marker-buffer hdmarker))
  8144. (pos (marker-position hdmarker))
  8145. (inhibit-read-only t)
  8146. newhead)
  8147. (org-with-remote-undo buffer
  8148. (with-current-buffer buffer
  8149. (widen)
  8150. (goto-char pos)
  8151. (org-show-context 'agenda)
  8152. (save-excursion
  8153. (and (outline-next-heading)
  8154. (org-flag-heading nil))) ; show the next heading
  8155. (call-interactively 'org-toggle-archive-tag)
  8156. (end-of-line 1)
  8157. (setq newhead (org-get-heading)))
  8158. (org-agenda-change-all-lines newhead hdmarker)
  8159. (beginning-of-line 1))))
  8160. (defun org-agenda-do-date-later (arg)
  8161. (interactive "P")
  8162. (cond
  8163. ((or (equal arg '(16))
  8164. (memq last-command
  8165. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8166. (setq this-command 'org-agenda-date-later-minutes)
  8167. (org-agenda-date-later-minutes 1))
  8168. ((or (equal arg '(4))
  8169. (memq last-command
  8170. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8171. (setq this-command 'org-agenda-date-later-hours)
  8172. (org-agenda-date-later-hours 1))
  8173. (t
  8174. (org-agenda-date-later (prefix-numeric-value arg)))))
  8175. (defun org-agenda-do-date-earlier (arg)
  8176. (interactive "P")
  8177. (cond
  8178. ((or (equal arg '(16))
  8179. (memq last-command
  8180. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8181. (setq this-command 'org-agenda-date-earlier-minutes)
  8182. (org-agenda-date-earlier-minutes 1))
  8183. ((or (equal arg '(4))
  8184. (memq last-command
  8185. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8186. (setq this-command 'org-agenda-date-earlier-hours)
  8187. (org-agenda-date-earlier-hours 1))
  8188. (t
  8189. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8190. (defun org-agenda-date-later (arg &optional what)
  8191. "Change the date of this item to ARG day(s) later."
  8192. (interactive "p")
  8193. (org-agenda-check-type t 'agenda 'timeline)
  8194. (org-agenda-check-no-diary)
  8195. (let* ((marker (or (org-get-at-bol 'org-marker)
  8196. (org-agenda-error)))
  8197. (buffer (marker-buffer marker))
  8198. (pos (marker-position marker))
  8199. cdate today)
  8200. (org-with-remote-undo buffer
  8201. (with-current-buffer buffer
  8202. (widen)
  8203. (goto-char pos)
  8204. (if (not (org-at-timestamp-p))
  8205. (error "Cannot find time stamp"))
  8206. (when (and org-agenda-move-date-from-past-immediately-to-today
  8207. (equal arg 1)
  8208. (or (not what) (eq what 'day))
  8209. (not (save-match-data (org-at-date-range-p))))
  8210. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8211. cdate (calendar-absolute-from-gregorian
  8212. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8213. today (org-today))
  8214. (if (> today cdate)
  8215. ;; immediately shift to today
  8216. (setq arg (- today cdate))))
  8217. (org-timestamp-change arg (or what 'day))
  8218. (when (and (org-at-date-range-p)
  8219. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8220. (let ((end org-last-changed-timestamp))
  8221. (org-timestamp-change arg (or what 'day))
  8222. (setq org-last-changed-timestamp
  8223. (concat org-last-changed-timestamp "--" end)))))
  8224. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8225. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8226. (defun org-agenda-date-earlier (arg &optional what)
  8227. "Change the date of this item to ARG day(s) earlier."
  8228. (interactive "p")
  8229. (org-agenda-date-later (- arg) what))
  8230. (defun org-agenda-date-later-minutes (arg)
  8231. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8232. (interactive "p")
  8233. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8234. (org-agenda-date-later arg 'minute))
  8235. (defun org-agenda-date-earlier-minutes (arg)
  8236. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8237. (interactive "p")
  8238. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8239. (org-agenda-date-earlier arg 'minute))
  8240. (defun org-agenda-date-later-hours (arg)
  8241. "Change the time of this item, in hour steps."
  8242. (interactive "p")
  8243. (org-agenda-date-later arg 'hour))
  8244. (defun org-agenda-date-earlier-hours (arg)
  8245. "Change the time of this item, in hour steps."
  8246. (interactive "p")
  8247. (org-agenda-date-earlier arg 'hour))
  8248. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8249. "Show new date stamp via text properties."
  8250. ;; We use text properties to make this undoable
  8251. (let ((inhibit-read-only t))
  8252. (setq stamp (concat prefix " => " stamp " "))
  8253. (save-excursion
  8254. (goto-char (point-max))
  8255. (while (not (bobp))
  8256. (when (equal marker (org-get-at-bol 'org-marker))
  8257. (org-move-to-column (- (window-width) (length stamp)) t)
  8258. (org-agenda-fix-tags-filter-overlays-at (point))
  8259. (if (featurep 'xemacs)
  8260. ;; Use `duplicable' property to trigger undo recording
  8261. (let ((ex (make-extent nil nil))
  8262. (gl (make-glyph stamp)))
  8263. (set-glyph-face gl 'secondary-selection)
  8264. (set-extent-properties
  8265. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8266. (insert-extent ex (1- (point)) (point-at-eol)))
  8267. (add-text-properties
  8268. (1- (point)) (point-at-eol)
  8269. (list 'display (org-add-props stamp nil
  8270. 'face 'secondary-selection))))
  8271. (beginning-of-line 1))
  8272. (beginning-of-line 0)))))
  8273. (defun org-agenda-date-prompt (arg)
  8274. "Change the date of this item. Date is prompted for, with default today.
  8275. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8276. be used to request time specification in the time stamp."
  8277. (interactive "P")
  8278. (org-agenda-check-type t 'agenda 'timeline)
  8279. (org-agenda-check-no-diary)
  8280. (let* ((marker (or (org-get-at-bol 'org-marker)
  8281. (org-agenda-error)))
  8282. (buffer (marker-buffer marker))
  8283. (pos (marker-position marker)))
  8284. (org-with-remote-undo buffer
  8285. (with-current-buffer buffer
  8286. (widen)
  8287. (goto-char pos)
  8288. (if (not (org-at-timestamp-p t))
  8289. (error "Cannot find time stamp"))
  8290. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8291. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8292. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8293. (defun org-agenda-schedule (arg &optional time)
  8294. "Schedule the item at point.
  8295. ARG is passed through to `org-schedule'."
  8296. (interactive "P")
  8297. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8298. (org-agenda-check-no-diary)
  8299. (let* ((marker (or (org-get-at-bol 'org-marker)
  8300. (org-agenda-error)))
  8301. (type (marker-insertion-type marker))
  8302. (buffer (marker-buffer marker))
  8303. (pos (marker-position marker))
  8304. (org-insert-labeled-timestamps-at-point nil)
  8305. ts)
  8306. (set-marker-insertion-type marker t)
  8307. (org-with-remote-undo buffer
  8308. (with-current-buffer buffer
  8309. (widen)
  8310. (goto-char pos)
  8311. (setq ts (org-schedule arg time)))
  8312. (org-agenda-show-new-time marker ts " S"))
  8313. (message "%s" ts)))
  8314. (defun org-agenda-deadline (arg &optional time)
  8315. "Schedule the item at point.
  8316. ARG is passed through to `org-deadline'."
  8317. (interactive "P")
  8318. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8319. (org-agenda-check-no-diary)
  8320. (let* ((marker (or (org-get-at-bol 'org-marker)
  8321. (org-agenda-error)))
  8322. (buffer (marker-buffer marker))
  8323. (pos (marker-position marker))
  8324. (org-insert-labeled-timestamps-at-point nil)
  8325. ts)
  8326. (org-with-remote-undo buffer
  8327. (with-current-buffer buffer
  8328. (widen)
  8329. (goto-char pos)
  8330. (setq ts (org-deadline arg time)))
  8331. (org-agenda-show-new-time marker ts " D"))
  8332. (message "%s" ts)))
  8333. (defun org-agenda-clock-in (&optional arg)
  8334. "Start the clock on the currently selected item."
  8335. (interactive "P")
  8336. (org-agenda-check-no-diary)
  8337. (if (equal arg '(4))
  8338. (org-clock-in arg)
  8339. (let* ((marker (or (org-get-at-bol 'org-marker)
  8340. (org-agenda-error)))
  8341. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8342. (pos (marker-position marker))
  8343. (col (current-column))
  8344. newhead)
  8345. (org-with-remote-undo (marker-buffer marker)
  8346. (with-current-buffer (marker-buffer marker)
  8347. (widen)
  8348. (goto-char pos)
  8349. (org-show-context 'agenda)
  8350. (org-show-entry)
  8351. (org-cycle-hide-drawers 'children)
  8352. (org-clock-in arg)
  8353. (setq newhead (org-get-heading)))
  8354. (org-agenda-change-all-lines newhead hdmarker))
  8355. (org-move-to-column col))))
  8356. (defun org-agenda-clock-out ()
  8357. "Stop the currently running clock."
  8358. (interactive)
  8359. (unless (marker-buffer org-clock-marker)
  8360. (error "No running clock"))
  8361. (let ((marker (make-marker)) (col (current-column)) newhead)
  8362. (org-with-remote-undo (marker-buffer org-clock-marker)
  8363. (with-current-buffer (marker-buffer org-clock-marker)
  8364. (save-excursion
  8365. (save-restriction
  8366. (widen)
  8367. (goto-char org-clock-marker)
  8368. (org-back-to-heading t)
  8369. (move-marker marker (point))
  8370. (org-clock-out)
  8371. (setq newhead (org-get-heading))))))
  8372. (org-agenda-change-all-lines newhead marker)
  8373. (move-marker marker nil)
  8374. (org-move-to-column col)
  8375. (org-agenda-unmark-clocking-task)))
  8376. (defun org-agenda-clock-cancel (&optional arg)
  8377. "Cancel the currently running clock."
  8378. (interactive "P")
  8379. (unless (marker-buffer org-clock-marker)
  8380. (error "No running clock"))
  8381. (org-with-remote-undo (marker-buffer org-clock-marker)
  8382. (org-clock-cancel)))
  8383. (defun org-agenda-clock-goto ()
  8384. "Jump to the currently clocked in task within the agenda.
  8385. If the currently clocked in task is not listed in the agenda
  8386. buffer, display it in another window."
  8387. (interactive)
  8388. (let (pos)
  8389. (mapc (lambda (o)
  8390. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8391. (setq pos (overlay-start o))))
  8392. (overlays-in (point-min) (point-max)))
  8393. (cond (pos (goto-char pos))
  8394. ;; If the currently clocked entry is not in the agenda
  8395. ;; buffer, we visit it in another window:
  8396. (org-clock-current-task
  8397. (org-switch-to-buffer-other-window (org-clock-goto)))
  8398. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8399. (defun org-agenda-diary-entry-in-org-file ()
  8400. "Make a diary entry in the file `org-agenda-diary-file'."
  8401. (let (d1 d2 char (text "") dp1 dp2)
  8402. (if (equal (buffer-name) "*Calendar*")
  8403. (setq d1 (calendar-cursor-to-date t)
  8404. d2 (car calendar-mark-ring))
  8405. (setq dp1 (get-text-property (point-at-bol) 'day))
  8406. (unless dp1 (error "No date defined in current line"))
  8407. (setq d1 (calendar-gregorian-from-absolute dp1)
  8408. d2 (and (ignore-errors (mark))
  8409. (save-excursion
  8410. (goto-char (mark))
  8411. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8412. (calendar-gregorian-from-absolute dp2))))
  8413. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8414. (setq char (read-char-exclusive))
  8415. (cond
  8416. ((equal char ?d)
  8417. (setq text (read-string "Day entry: "))
  8418. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8419. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8420. ((equal char ?a)
  8421. (setq d1 (list (car d1) (nth 1 d1)
  8422. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8423. (nth 2 d1))))
  8424. (setq text (read-string "Anniversary (use %d to show years): "))
  8425. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8426. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8427. ((equal char ?b)
  8428. (setq text (read-string "Block entry: "))
  8429. (unless (and d1 d2 (not (equal d1 d2)))
  8430. (error "No block of days selected"))
  8431. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8432. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8433. ((equal char ?j)
  8434. (org-switch-to-buffer-other-window
  8435. (find-file-noselect org-agenda-diary-file))
  8436. (require 'org-datetree)
  8437. (org-datetree-find-date-create d1)
  8438. (org-reveal t))
  8439. (t (error "Invalid selection character `%c'" char)))))
  8440. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8441. "Where in `org-agenda-diary-file' should new entries be added?
  8442. Valid values:
  8443. date-tree in the date tree, as child of the date
  8444. top-level as top-level entries at the end of the file."
  8445. :group 'org-agenda
  8446. :type '(choice
  8447. (const :tag "in a date tree" date-tree)
  8448. (const :tag "as top level at end of file" top-level)))
  8449. (defcustom org-agenda-insert-diary-extract-time nil
  8450. "Non-nil means extract any time specification from the diary entry."
  8451. :group 'org-agenda
  8452. :version "24.1"
  8453. :type 'boolean)
  8454. (defcustom org-agenda-bulk-mark-char ">"
  8455. "A single-character string to be used as the bulk mark."
  8456. :group 'org-agenda
  8457. :version "24.1"
  8458. :type 'string)
  8459. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8460. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8461. If TEXT is not empty, it will become the headline of the new entry, and
  8462. the resulting entry will not be shown. When TEXT is empty, switch to
  8463. `org-agenda-diary-file' and let the user finish the entry there."
  8464. (let ((cw (current-window-configuration)))
  8465. (org-switch-to-buffer-other-window
  8466. (find-file-noselect org-agenda-diary-file))
  8467. (widen)
  8468. (goto-char (point-min))
  8469. (cond
  8470. ((eq type 'anniversary)
  8471. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8472. (progn
  8473. (or (org-at-heading-p t)
  8474. (progn
  8475. (outline-next-heading)
  8476. (insert "* Anniversaries\n\n")
  8477. (beginning-of-line -1)))))
  8478. (outline-next-heading)
  8479. (org-back-over-empty-lines)
  8480. (backward-char 1)
  8481. (insert "\n")
  8482. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8483. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8484. ((eq type 'day)
  8485. (let ((org-prefix-has-time t)
  8486. (org-agenda-time-leading-zero t)
  8487. fmt time time2)
  8488. (if org-agenda-insert-diary-extract-time
  8489. ;; Use org-agenda-format-item to parse text for a time-range and
  8490. ;; remove it. FIXME: This is a hack, we should refactor
  8491. ;; that function to make time extraction available separately
  8492. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8493. time (get-text-property 0 'time fmt)
  8494. time2 (if (> (length time) 0)
  8495. ;; split-string removes trailing ...... if
  8496. ;; no end time given. First space
  8497. ;; separates time from date.
  8498. (concat " " (car (split-string time "\\.")))
  8499. nil)
  8500. text (get-text-property 0 'txt fmt)))
  8501. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8502. (org-agenda-insert-diary-as-top-level text)
  8503. (require 'org-datetree)
  8504. (org-datetree-find-date-create d1)
  8505. (org-agenda-insert-diary-make-new-entry text))
  8506. (org-insert-time-stamp (org-time-from-absolute
  8507. (calendar-absolute-from-gregorian d1))
  8508. nil nil nil nil time2))
  8509. (end-of-line 0))
  8510. ((eq type 'block)
  8511. (if (> (calendar-absolute-from-gregorian d1)
  8512. (calendar-absolute-from-gregorian d2))
  8513. (setq d1 (prog1 d2 (setq d2 d1))))
  8514. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8515. (org-agenda-insert-diary-as-top-level text)
  8516. (require 'org-datetree)
  8517. (org-datetree-find-date-create d1)
  8518. (org-agenda-insert-diary-make-new-entry text))
  8519. (org-insert-time-stamp (org-time-from-absolute
  8520. (calendar-absolute-from-gregorian d1)))
  8521. (insert "--")
  8522. (org-insert-time-stamp (org-time-from-absolute
  8523. (calendar-absolute-from-gregorian d2)))
  8524. (end-of-line 0)))
  8525. (if (string-match "\\S-" text)
  8526. (progn
  8527. (set-window-configuration cw)
  8528. (message "%s entry added to %s"
  8529. (capitalize (symbol-name type))
  8530. (abbreviate-file-name org-agenda-diary-file)))
  8531. (org-reveal t)
  8532. (message "Please finish entry here"))))
  8533. (defun org-agenda-insert-diary-as-top-level (text)
  8534. "Make new entry as a top-level entry at the end of the file.
  8535. Add TEXT as headline, and position the cursor in the second line so that
  8536. a timestamp can be added there."
  8537. (widen)
  8538. (goto-char (point-max))
  8539. (or (bolp) (insert "\n"))
  8540. (insert "* " text "\n")
  8541. (if org-adapt-indentation (org-indent-to-column 2)))
  8542. (defun org-agenda-insert-diary-make-new-entry (text)
  8543. "Make new entry as last child of current entry.
  8544. Add TEXT as headline, and position the cursor in the second line so that
  8545. a timestamp can be added there."
  8546. (let ((org-show-following-heading t)
  8547. (org-show-siblings t)
  8548. (org-show-hierarchy-above t)
  8549. (org-show-entry-below t)
  8550. col)
  8551. (outline-next-heading)
  8552. (org-back-over-empty-lines)
  8553. (or (looking-at "[ \t]*$")
  8554. (progn (insert "\n") (backward-char 1)))
  8555. (org-insert-heading nil t)
  8556. (org-do-demote)
  8557. (setq col (current-column))
  8558. (insert text "\n")
  8559. (if org-adapt-indentation (org-indent-to-column col))
  8560. (let ((org-show-following-heading t)
  8561. (org-show-siblings t)
  8562. (org-show-hierarchy-above t)
  8563. (org-show-entry-below t))
  8564. (org-show-context))))
  8565. (defun org-agenda-diary-entry ()
  8566. "Make a diary entry, like the `i' command from the calendar.
  8567. All the standard commands work: block, weekly etc.
  8568. When `org-agenda-diary-file' points to a file,
  8569. `org-agenda-diary-entry-in-org-file' is called instead to create
  8570. entries in that Org-mode file."
  8571. (interactive)
  8572. (if (not (eq org-agenda-diary-file 'diary-file))
  8573. (org-agenda-diary-entry-in-org-file)
  8574. (require 'diary-lib)
  8575. (let* ((char (progn
  8576. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8577. (read-char-exclusive)))
  8578. (cmd (cdr (assoc char
  8579. '((?d . insert-diary-entry)
  8580. (?w . insert-weekly-diary-entry)
  8581. (?m . insert-monthly-diary-entry)
  8582. (?y . insert-yearly-diary-entry)
  8583. (?a . insert-anniversary-diary-entry)
  8584. (?b . insert-block-diary-entry)
  8585. (?c . insert-cyclic-diary-entry)))))
  8586. (oldf (symbol-function 'calendar-cursor-to-date))
  8587. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8588. (point (point))
  8589. (mark (or (mark t) (point))))
  8590. (unless cmd
  8591. (error "No command associated with <%c>" char))
  8592. (unless (and (get-text-property point 'day)
  8593. (or (not (equal ?b char))
  8594. (get-text-property mark 'day)))
  8595. (error "Don't know which date to use for diary entry"))
  8596. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8597. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8598. (let ((calendar-mark-ring
  8599. (list (calendar-gregorian-from-absolute
  8600. (or (get-text-property mark 'day)
  8601. (get-text-property point 'day))))))
  8602. (unwind-protect
  8603. (progn
  8604. (fset 'calendar-cursor-to-date
  8605. (lambda (&optional error dummy)
  8606. (calendar-gregorian-from-absolute
  8607. (get-text-property point 'day))))
  8608. (call-interactively cmd))
  8609. (fset 'calendar-cursor-to-date oldf))))))
  8610. (defun org-agenda-execute-calendar-command (cmd)
  8611. "Execute a calendar command from the agenda with date from cursor."
  8612. (org-agenda-check-type t 'agenda 'timeline)
  8613. (require 'diary-lib)
  8614. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8615. (error "Don't know which date to use for the calendar command"))
  8616. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8617. (point (point))
  8618. (date (calendar-gregorian-from-absolute
  8619. (get-text-property point 'day)))
  8620. ;; the following 2 vars are needed in the calendar
  8621. (displayed-month (car date))
  8622. (displayed-year (nth 2 date)))
  8623. (unwind-protect
  8624. (progn
  8625. (fset 'calendar-cursor-to-date
  8626. (lambda (&optional error dummy)
  8627. (calendar-gregorian-from-absolute
  8628. (get-text-property point 'day))))
  8629. (call-interactively cmd))
  8630. (fset 'calendar-cursor-to-date oldf))))
  8631. (defun org-agenda-phases-of-moon ()
  8632. "Display the phases of the moon for the 3 months around the cursor date."
  8633. (interactive)
  8634. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8635. (defun org-agenda-holidays ()
  8636. "Display the holidays for the 3 months around the cursor date."
  8637. (interactive)
  8638. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8639. (defvar calendar-longitude) ; defined in calendar.el
  8640. (defvar calendar-latitude) ; defined in calendar.el
  8641. (defvar calendar-location-name) ; defined in calendar.el
  8642. (defun org-agenda-sunrise-sunset (arg)
  8643. "Display sunrise and sunset for the cursor date.
  8644. Latitude and longitude can be specified with the variables
  8645. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8646. argument, latitude and longitude will be prompted for."
  8647. (interactive "P")
  8648. (require 'solar)
  8649. (let ((calendar-longitude (if arg nil calendar-longitude))
  8650. (calendar-latitude (if arg nil calendar-latitude))
  8651. (calendar-location-name
  8652. (if arg "the given coordinates" calendar-location-name)))
  8653. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8654. (defun org-agenda-goto-calendar ()
  8655. "Open the Emacs calendar with the date at the cursor."
  8656. (interactive)
  8657. (org-agenda-check-type t 'agenda 'timeline)
  8658. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8659. (error "Don't know which date to open in calendar")))
  8660. (date (calendar-gregorian-from-absolute day))
  8661. (calendar-move-hook nil)
  8662. (calendar-view-holidays-initially-flag nil)
  8663. (calendar-view-diary-initially-flag nil))
  8664. (calendar)
  8665. (calendar-goto-date date)))
  8666. ;;;###autoload
  8667. (defun org-calendar-goto-agenda ()
  8668. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8669. This is a command that has to be installed in `calendar-mode-map'."
  8670. (interactive)
  8671. (org-agenda-list nil (calendar-absolute-from-gregorian
  8672. (calendar-cursor-to-date))
  8673. nil))
  8674. (defun org-agenda-convert-date ()
  8675. (interactive)
  8676. (org-agenda-check-type t 'agenda 'timeline)
  8677. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8678. date s)
  8679. (unless day
  8680. (error "Don't know which date to convert"))
  8681. (setq date (calendar-gregorian-from-absolute day))
  8682. (setq s (concat
  8683. "Gregorian: " (calendar-date-string date) "\n"
  8684. "ISO: " (calendar-iso-date-string date) "\n"
  8685. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8686. "Julian: " (calendar-julian-date-string date) "\n"
  8687. "Astron. JD: " (calendar-astro-date-string date)
  8688. " (Julian date number at noon UTC)\n"
  8689. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8690. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8691. "French: " (calendar-french-date-string date) "\n"
  8692. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8693. "Mayan: " (calendar-mayan-date-string date) "\n"
  8694. "Coptic: " (calendar-coptic-date-string date) "\n"
  8695. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8696. "Persian: " (calendar-persian-date-string date) "\n"
  8697. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8698. (with-output-to-temp-buffer "*Dates*"
  8699. (princ s))
  8700. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8701. ;;; Bulk commands
  8702. (defun org-agenda-bulk-marked-p ()
  8703. (eq (get-char-property (point-at-bol) 'type)
  8704. 'org-marked-entry-overlay))
  8705. (defun org-agenda-bulk-mark (&optional arg)
  8706. "Mark the entry at point for future bulk action."
  8707. (interactive "p")
  8708. (dotimes (i (or arg 1))
  8709. (unless (org-get-at-bol 'org-agenda-diary-link)
  8710. (let* ((m (org-get-at-bol 'org-hd-marker))
  8711. ov)
  8712. (unless (org-agenda-bulk-marked-p)
  8713. (unless m (error "Nothing to mark at point"))
  8714. (push m org-agenda-bulk-marked-entries)
  8715. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8716. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8717. (org-get-todo-face "TODO")
  8718. 'evaporate)
  8719. (overlay-put ov 'type 'org-marked-entry-overlay))
  8720. (beginning-of-line 2)
  8721. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8722. (beginning-of-line 2))
  8723. (message "%d entries marked for bulk action"
  8724. (length org-agenda-bulk-marked-entries))))))
  8725. (defun org-agenda-bulk-mark-all ()
  8726. "Mark all entries for future agenda bulk action."
  8727. (interactive)
  8728. (org-agenda-bulk-mark-regexp "."))
  8729. (defun org-agenda-bulk-mark-regexp (regexp)
  8730. "Mark entries matching REGEXP for future agenda bulk action."
  8731. (interactive "sMark entries matching regexp: ")
  8732. (let ((entries-marked 0))
  8733. (save-excursion
  8734. (goto-char (point-min))
  8735. (goto-char (next-single-property-change (point) 'txt))
  8736. (while (re-search-forward regexp nil t)
  8737. (when (string-match regexp (get-text-property (point) 'txt))
  8738. (setq entries-marked (1+ entries-marked))
  8739. (call-interactively 'org-agenda-bulk-mark))))
  8740. (if (not entries-marked)
  8741. (message "No entry matching this regexp."))))
  8742. (defun org-agenda-bulk-unmark (&optional arg)
  8743. "Unmark the entry at point for future bulk action."
  8744. (interactive "P")
  8745. (if arg
  8746. (org-agenda-bulk-unmark-all)
  8747. (cond ((org-agenda-bulk-marked-p)
  8748. (org-agenda-bulk-remove-overlays
  8749. (point-at-bol) (+ 2 (point-at-bol)))
  8750. (setq org-agenda-bulk-marked-entries
  8751. (delete (org-get-at-bol 'org-hd-marker)
  8752. org-agenda-bulk-marked-entries))
  8753. (beginning-of-line 2)
  8754. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8755. (beginning-of-line 2))
  8756. (message "%d entries left marked for bulk action"
  8757. (length org-agenda-bulk-marked-entries)))
  8758. (t (message "No entry to unmark here")))))
  8759. (defun org-agenda-bulk-toggle ()
  8760. "Toggle marking the entry at point for bulk action."
  8761. (interactive)
  8762. (if (org-agenda-bulk-marked-p)
  8763. (org-agenda-bulk-unmark)
  8764. (org-agenda-bulk-mark)))
  8765. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8766. "Remove the mark overlays between BEG and END in the agenda buffer.
  8767. BEG and END default to the buffer limits.
  8768. This only removes the overlays, it does not remove the markers
  8769. from the list in `org-agenda-bulk-marked-entries'."
  8770. (interactive)
  8771. (mapc (lambda (ov)
  8772. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8773. (delete-overlay ov)))
  8774. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8775. (defun org-agenda-bulk-unmark-all ()
  8776. "Remove all marks in the agenda buffer.
  8777. This will remove the markers and the overlays."
  8778. (interactive)
  8779. (if (null org-agenda-bulk-marked-entries)
  8780. (message "No entry to unmark")
  8781. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8782. (setq org-agenda-bulk-marked-entries nil)
  8783. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8784. (defcustom org-agenda-persistent-marks nil
  8785. "Non-nil means marked items will stay marked after a bulk action.
  8786. You can toggle this interactively by typing `p' when prompted for a
  8787. bulk action."
  8788. :group 'org-agenda
  8789. :version "24.1"
  8790. :type 'boolean)
  8791. (defun org-agenda-bulk-action (&optional arg)
  8792. "Execute an remote-editing action on all marked entries.
  8793. The prefix arg is passed through to the command if possible."
  8794. (interactive "P")
  8795. ;; Make sure we have markers, and only valid ones
  8796. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8797. (mapc
  8798. (lambda (m)
  8799. (unless (and (markerp m)
  8800. (marker-buffer m)
  8801. (buffer-live-p (marker-buffer m))
  8802. (marker-position m))
  8803. (error "Marker %s for bulk command is invalid" m)))
  8804. org-agenda-bulk-marked-entries)
  8805. ;; Prompt for the bulk command
  8806. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8807. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8808. "[S]catter [f]unction "
  8809. (when org-agenda-bulk-custom-functions
  8810. (concat " Custom: ["
  8811. (mapconcat (lambda(f) (char-to-string (car f)))
  8812. org-agenda-bulk-custom-functions "")
  8813. "]"))))
  8814. (catch 'exit
  8815. (let* ((action (read-char-exclusive))
  8816. (org-log-refile (if org-log-refile 'time nil))
  8817. (entries (reverse org-agenda-bulk-marked-entries))
  8818. (org-overriding-default-time
  8819. (if (get-text-property (point) 'org-agenda-date-header)
  8820. (org-get-cursor-date)))
  8821. redo-at-end
  8822. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8823. (cond
  8824. ((equal action ?p)
  8825. (let ((org-agenda-persistent-marks
  8826. (not org-agenda-persistent-marks)))
  8827. (org-agenda-bulk-action)
  8828. (throw 'exit nil)))
  8829. ((equal action ?$)
  8830. (setq cmd '(org-agenda-archive)))
  8831. ((equal action ?A)
  8832. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8833. ((member action '(?r ?w))
  8834. (setq rfloc (org-refile-get-location
  8835. "Refile to"
  8836. (marker-buffer (car entries))
  8837. org-refile-allow-creating-parent-nodes))
  8838. (if (nth 3 rfloc)
  8839. (setcar (nthcdr 3 rfloc)
  8840. (move-marker (make-marker) (nth 3 rfloc)
  8841. (or (get-file-buffer (nth 1 rfloc))
  8842. (find-buffer-visiting (nth 1 rfloc))
  8843. (error "This should not happen")))))
  8844. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8845. redo-at-end t))
  8846. ((equal action ?t)
  8847. (setq state (org-icompleting-read
  8848. "Todo state: "
  8849. (with-current-buffer (marker-buffer (car entries))
  8850. (mapcar 'list org-todo-keywords-1))))
  8851. (setq cmd `(let ((org-inhibit-blocking t)
  8852. (org-inhibit-logging 'note))
  8853. (org-agenda-todo ,state))))
  8854. ((memq action '(?- ?+))
  8855. (setq tag (org-icompleting-read
  8856. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8857. (with-current-buffer (marker-buffer (car entries))
  8858. (delq nil
  8859. (mapcar (lambda (x)
  8860. (if (stringp (car x)) x)) org-tag-alist)))))
  8861. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8862. ((memq action '(?s ?d))
  8863. (let* ((time
  8864. (unless arg
  8865. (org-read-date
  8866. nil nil nil
  8867. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8868. org-overriding-default-time)))
  8869. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8870. (setq cmd `(eval '(,c1 arg ,time)))))
  8871. ((equal action ?S)
  8872. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8873. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8874. (let ((days (read-number
  8875. (format "Scatter tasks across how many %sdays: "
  8876. (if arg "week" "")) 7)))
  8877. (setq cmd
  8878. `(let ((distance (1+ (random ,days))))
  8879. (if arg
  8880. (let ((dist distance)
  8881. (day-of-week
  8882. (calendar-day-of-week
  8883. (calendar-gregorian-from-absolute (org-today)))))
  8884. (dotimes (i (1+ dist))
  8885. (while (member day-of-week org-agenda-weekend-days)
  8886. (incf distance)
  8887. (incf day-of-week)
  8888. (if (= day-of-week 7)
  8889. (setq day-of-week 0)))
  8890. (incf day-of-week)
  8891. (if (= day-of-week 7)
  8892. (setq day-of-week 0)))))
  8893. ;; silently fail when try to replan a sexp entry
  8894. (condition-case nil
  8895. (let* ((date (calendar-gregorian-from-absolute
  8896. (+ (org-today) distance)))
  8897. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8898. (nth 2 date))))
  8899. (org-agenda-schedule nil time))
  8900. (error nil)))))))
  8901. ((assoc action org-agenda-bulk-custom-functions)
  8902. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8903. redo-at-end t))
  8904. ((equal action ?f)
  8905. (setq cmd (list (intern
  8906. (org-icompleting-read "Function: "
  8907. obarray 'fboundp t nil nil)))))
  8908. (t (error "Invalid bulk action")))
  8909. ;; Sort the markers, to make sure that parents are handled before children
  8910. (setq entries (sort entries
  8911. (lambda (a b)
  8912. (cond
  8913. ((equal (marker-buffer a) (marker-buffer b))
  8914. (< (marker-position a) (marker-position b)))
  8915. (t
  8916. (string< (buffer-name (marker-buffer a))
  8917. (buffer-name (marker-buffer b))))))))
  8918. ;; Now loop over all markers and apply cmd
  8919. (while (setq e (pop entries))
  8920. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8921. (if (not pos)
  8922. (progn (message "Skipping removed entry at %s" e)
  8923. (setq cntskip (1+ cntskip)))
  8924. (goto-char pos)
  8925. (let (org-loop-over-headlines-in-active-region)
  8926. (eval cmd))
  8927. (setq cnt (1+ cnt))))
  8928. (when redo-at-end (org-agenda-redo))
  8929. (unless org-agenda-persistent-marks
  8930. (org-agenda-bulk-unmark-all))
  8931. (message "Acted on %d entries%s%s"
  8932. cnt
  8933. (if (= cntskip 0)
  8934. ""
  8935. (format ", skipped %d (disappeared before their turn)"
  8936. cntskip))
  8937. (if (not org-agenda-persistent-marks)
  8938. "" " (kept marked)"))))))
  8939. (defun org-agenda-capture (&optional with-time)
  8940. "Call `org-capture' with the date at point.
  8941. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  8942. current HH:MM time."
  8943. (interactive "P")
  8944. (if (not (eq major-mode 'org-agenda-mode))
  8945. (user-error "You cannot do this outside of agenda buffers")
  8946. (let ((org-overriding-default-time
  8947. (org-get-cursor-date (equal with-time 1))))
  8948. (call-interactively 'org-capture))))
  8949. ;;; Flagging notes
  8950. (defun org-agenda-show-the-flagging-note ()
  8951. "Display the flagging note in the other window.
  8952. When called a second time in direct sequence, offer to remove the FLAGGING
  8953. tag and (if present) the flagging note."
  8954. (interactive)
  8955. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8956. (win (selected-window))
  8957. note heading newhead)
  8958. (unless hdmarker
  8959. (error "No linked entry at point"))
  8960. (if (and (eq this-command last-command)
  8961. (y-or-n-p "Unflag and remove any flagging note? "))
  8962. (progn
  8963. (org-agenda-remove-flag hdmarker)
  8964. (let ((win (get-buffer-window "*Flagging Note*")))
  8965. (and win (delete-window win)))
  8966. (message "Entry unflagged"))
  8967. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8968. (unless note
  8969. (error "No flagging note"))
  8970. (org-kill-new note)
  8971. (org-switch-to-buffer-other-window "*Flagging Note*")
  8972. (erase-buffer)
  8973. (insert note)
  8974. (goto-char (point-min))
  8975. (while (re-search-forward "\\\\n" nil t)
  8976. (replace-match "\n" t t))
  8977. (goto-char (point-min))
  8978. (select-window win)
  8979. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8980. (defun org-agenda-remove-flag (marker)
  8981. "Remove the FLAGGED tag and any flagging note in the entry."
  8982. (let (newhead)
  8983. (org-with-point-at marker
  8984. (org-toggle-tag "FLAGGED" 'off)
  8985. (org-entry-delete nil "THEFLAGGINGNOTE")
  8986. (setq newhead (org-get-heading)))
  8987. (org-agenda-change-all-lines newhead marker)
  8988. (message "Entry unflagged")))
  8989. (defun org-agenda-get-any-marker (&optional pos)
  8990. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8991. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8992. ;;; Appointment reminders
  8993. (defvar appt-time-msg-list) ; defined in appt.el
  8994. ;;;###autoload
  8995. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8996. "Activate appointments found in `org-agenda-files'.
  8997. With a \\[universal-argument] prefix, refresh the list of
  8998. appointments.
  8999. If FILTER is t, interactively prompt the user for a regular
  9000. expression, and filter out entries that don't match it.
  9001. If FILTER is a string, use this string as a regular expression
  9002. for filtering entries out.
  9003. If FILTER is a function, filter out entries against which
  9004. calling the function returns nil. This function takes one
  9005. argument: an entry from `org-agenda-get-day-entries'.
  9006. FILTER can also be an alist with the car of each cell being
  9007. either 'headline or 'category. For example:
  9008. '((headline \"IMPORTANT\")
  9009. (category \"Work\"))
  9010. will only add headlines containing IMPORTANT or headlines
  9011. belonging to the \"Work\" category.
  9012. ARGS are symbols indicating what kind of entries to consider.
  9013. By default `org-agenda-to-appt' will use :deadline, :scheduled
  9014. and :timestamp entries. See the docstring of `org-diary' for
  9015. details and examples.
  9016. If an entry has a APPT_WARNTIME property, its value will be used
  9017. to override `appt-message-warning-time'."
  9018. (interactive "P")
  9019. (if refresh (setq appt-time-msg-list nil))
  9020. (if (eq filter t)
  9021. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9022. (let* ((cnt 0) ; count added events
  9023. (scope (or args '(:deadline :scheduled :timestamp)))
  9024. (org-agenda-new-buffers nil)
  9025. (org-deadline-warning-days 0)
  9026. ;; Do not use `org-today' here because appt only takes
  9027. ;; time and without date as argument, so it may pass wrong
  9028. ;; information otherwise
  9029. (today (org-date-to-gregorian
  9030. (time-to-days (current-time))))
  9031. (org-agenda-restrict nil)
  9032. (files (org-agenda-files 'unrestricted)) entries file
  9033. (org-agenda-buffer nil))
  9034. ;; Get all entries which may contain an appt
  9035. (org-agenda-prepare-buffers files)
  9036. (while (setq file (pop files))
  9037. (setq entries
  9038. (delq nil
  9039. (append entries
  9040. (apply 'org-agenda-get-day-entries
  9041. file today scope)))))
  9042. ;; Map thru entries and find if we should filter them out
  9043. (mapc
  9044. (lambda(x)
  9045. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  9046. (cat (get-text-property 1 'org-category x))
  9047. (tod (get-text-property 1 'time-of-day x))
  9048. (ok (or (null filter)
  9049. (and (stringp filter) (string-match filter evt))
  9050. (and (functionp filter) (funcall filter x))
  9051. (and (listp filter)
  9052. (let ((cat-filter (cadr (assoc 'category filter)))
  9053. (evt-filter (cadr (assoc 'headline filter))))
  9054. (or (and (stringp cat-filter)
  9055. (string-match cat-filter cat))
  9056. (and (stringp evt-filter)
  9057. (string-match evt-filter evt)))))))
  9058. (wrn (get-text-property 1 'warntime x)))
  9059. ;; FIXME: Shall we remove text-properties for the appt text?
  9060. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9061. (when (and ok tod)
  9062. (setq tod (concat "00" (number-to-string tod))
  9063. tod (when (string-match
  9064. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9065. (concat (match-string 1 tod) ":"
  9066. (match-string 2 tod))))
  9067. (if (version< emacs-version "23.3")
  9068. (appt-add tod evt)
  9069. (appt-add tod evt wrn))
  9070. (setq cnt (1+ cnt))))) entries)
  9071. (org-release-buffers org-agenda-new-buffers)
  9072. (if (eq cnt 0)
  9073. (message "No event to add")
  9074. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9075. (defun org-agenda-todayp (date)
  9076. "Does DATE mean today, when considering `org-extend-today-until'?"
  9077. (let ((today (org-today))
  9078. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9079. date)))
  9080. (eq date today)))
  9081. (defun org-agenda-todo-yesterday (&optional arg)
  9082. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9083. (interactive "P")
  9084. (let* ((hour (third (decode-time
  9085. (org-current-time))))
  9086. (org-extend-today-until (1+ hour)))
  9087. (org-agenda-todo arg)))
  9088. (provide 'org-agenda)
  9089. ;;; org-agenda.el ends here