org-agenda.el 323 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2011 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 conveniant 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. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function org-datetree-find-date-create "org-datetree"
  62. (date &optional keep-restriction))
  63. (declare-function org-columns-quit "org-colview" ())
  64. (declare-function diary-date-display-form "diary-lib" (&optional type))
  65. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  66. (declare-function org-habit-insert-consistency-graphs
  67. "org-habit" (&optional line))
  68. (declare-function org-is-habit-p "org-habit" (&optional pom))
  69. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  70. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  71. (declare-function org-pop-to-buffer-same-window "org-compat"
  72. (&optional buffer-or-name norecord label))
  73. (declare-function org-duration-string-to-minutes "org-clock" (s))
  74. (declare-function org-hh:mm-string-to-minutes "org-clock" (s))
  75. (declare-function org-minutes-to-hh:mm-string "org-clock" (m))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task) ; defined in org-clock.el
  78. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  79. (defvar org-habit-show-habits)
  80. (defvar org-habit-show-habits-only-for-today)
  81. ;; Defined somewhere in this file, but used before definition.
  82. (defvar org-agenda-buffer-name)
  83. (defvar org-agenda-overriding-header)
  84. (defvar org-agenda-title-append nil)
  85. (defvar entry)
  86. (defvar date)
  87. (defvar org-agenda-undo-list)
  88. (defvar org-agenda-pending-undo-list)
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defcustom org-agenda-confirm-kill 1
  91. "When set, remote killing from the agenda buffer needs confirmation.
  92. When t, a confirmation is always needed. When a number N, confirmation is
  93. only needed when the text to be killed contains more than N non-white lines."
  94. :group 'org-agenda
  95. :type '(choice
  96. (const :tag "Never" nil)
  97. (const :tag "Always" t)
  98. (integer :tag "When more than N lines")))
  99. (defcustom org-agenda-compact-blocks nil
  100. "Non-nil means make the block agenda more compact.
  101. This is done globally by leaving out lines like the agenda span
  102. name and week number or the separator lines."
  103. :group 'org-agenda
  104. :type 'boolean)
  105. (defcustom org-agenda-block-separator ?=
  106. "The separator between blocks in the agenda.
  107. If this is a string, it will be used as the separator, with a newline added.
  108. If it is a character, it will be repeated to fill the window width.
  109. If nil the separator is disabled. In `org-agenda-custom-commands' this
  110. addresses the separator between the current and the previous block."
  111. :group 'org-agenda
  112. :type '(choice
  113. (const :tag "Disabled" nil)
  114. (character)
  115. (string)))
  116. (defgroup org-agenda-export nil
  117. "Options concerning exporting agenda views in Org-mode."
  118. :tag "Org Agenda Export"
  119. :group 'org-agenda)
  120. (defcustom org-agenda-with-colors t
  121. "Non-nil means use colors in agenda views."
  122. :group 'org-agenda-export
  123. :type 'boolean)
  124. (defcustom org-agenda-exporter-settings nil
  125. "Alist of variable/value pairs that should be active during agenda export.
  126. This is a good place to set options for ps-print and for htmlize.
  127. Note that the way this is implemented, the values will be evaluated
  128. before assigned to the variables. So make sure to quote values you do
  129. *not* want evaluated, for example
  130. (setq org-agenda-exporter-settings
  131. '((ps-print-color-p 'black-white)))"
  132. :group 'org-agenda-export
  133. :type '(repeat
  134. (list
  135. (variable)
  136. (sexp :tag "Value"))))
  137. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  138. "Hook run in temporary buffer before writing it to an export file.
  139. A useful function is `org-agenda-add-entry-text'."
  140. :group 'org-agenda-export
  141. :type 'hook
  142. :options '(org-agenda-add-entry-text))
  143. (defcustom org-agenda-add-entry-text-maxlines 0
  144. "Maximum number of entry text lines to be added to agenda.
  145. This is only relevant when `org-agenda-add-entry-text' is part of
  146. `org-agenda-before-write-hook', which it is by default.
  147. When this is 0, nothing will happen. When it is greater than 0, it
  148. specifies the maximum number of lines that will be added for each entry
  149. that is listed in the agenda view.
  150. Note that this variable is not used during display, only when exporting
  151. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  152. and `org-agenda-entry-text-maxlines'."
  153. :group 'org-agenda
  154. :type 'integer)
  155. (defcustom org-agenda-add-entry-text-descriptive-links t
  156. "Non-nil means export org-links as descriptive links in agenda added text.
  157. This variable applies to the text added to the agenda when
  158. `org-agenda-add-entry-text-maxlines' is larger than 0.
  159. When this variable nil, the URL will (also) be shown."
  160. :group 'org-agenda
  161. :type 'boolean)
  162. (defcustom org-agenda-export-html-style ""
  163. "The style specification for exported HTML Agenda files.
  164. If this variable contains a string, it will replace the default <style>
  165. section as produced by `htmlize'.
  166. Since there are different ways of setting style information, this variable
  167. needs to contain the full HTML structure to provide a style, including the
  168. surrounding HTML tags. The style specifications should include definitions
  169. the fonts used by the agenda, here is an example:
  170. <style type=\"text/css\">
  171. p { font-weight: normal; color: gray; }
  172. .org-agenda-structure {
  173. font-size: 110%;
  174. color: #003399;
  175. font-weight: 600;
  176. }
  177. .org-todo {
  178. color: #cc6666;
  179. font-weight: bold;
  180. }
  181. .org-agenda-done {
  182. color: #339933;
  183. }
  184. .org-done {
  185. color: #339933;
  186. }
  187. .title { text-align: center; }
  188. .todo, .deadline { color: red; }
  189. .done { color: green; }
  190. </style>
  191. or, if you want to keep the style in a file,
  192. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  193. As the value of this option simply gets inserted into the HTML <head> header,
  194. you can \"misuse\" it to also add other text to the header. However,
  195. <style>...</style> is required, if not present the variable will be ignored."
  196. :group 'org-agenda-export
  197. :group 'org-export-html
  198. :type 'string)
  199. (defcustom org-agenda-persistent-filter nil
  200. "When set, keep filters from one agenda view to the next."
  201. :group 'org-agenda
  202. :type 'boolean)
  203. (defgroup org-agenda-custom-commands nil
  204. "Options concerning agenda views in Org-mode."
  205. :tag "Org Agenda Custom Commands"
  206. :group 'org-agenda)
  207. (defconst org-sorting-choice
  208. '(choice
  209. (const time-up) (const time-down)
  210. (const category-keep) (const category-up) (const category-down)
  211. (const tag-down) (const tag-up)
  212. (const priority-up) (const priority-down)
  213. (const todo-state-up) (const todo-state-down)
  214. (const effort-up) (const effort-down)
  215. (const habit-up) (const habit-down)
  216. (const alpha-up) (const alpha-down)
  217. (const user-defined-up) (const user-defined-down))
  218. "Sorting choices.")
  219. (defconst org-agenda-custom-commands-local-options
  220. `(repeat :tag "Local settings for this command. Remember to quote values"
  221. (choice :tag "Setting"
  222. (list :tag "Heading for this block"
  223. (const org-agenda-overriding-header)
  224. (string :tag "Headline"))
  225. (list :tag "Files to be searched"
  226. (const org-agenda-files)
  227. (list
  228. (const :format "" quote)
  229. (repeat (file))))
  230. (list :tag "Sorting strategy"
  231. (const org-agenda-sorting-strategy)
  232. (list
  233. (const :format "" quote)
  234. (repeat
  235. ,org-sorting-choice)))
  236. (list :tag "Prefix format"
  237. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  238. (string))
  239. (list :tag "Number of days in agenda"
  240. (const org-agenda-span)
  241. (choice (const :tag "Day" 'day)
  242. (const :tag "Week" 'week)
  243. (const :tag "Month" 'month)
  244. (const :tag "Year" 'year)
  245. (integer :tag "Custom")))
  246. (list :tag "Fixed starting date"
  247. (const org-agenda-start-day)
  248. (string :value "2007-11-01"))
  249. (list :tag "Start on day of week"
  250. (const org-agenda-start-on-weekday)
  251. (choice :value 1
  252. (const :tag "Today" nil)
  253. (integer :tag "Weekday No.")))
  254. (list :tag "Include data from diary"
  255. (const org-agenda-include-diary)
  256. (boolean))
  257. (list :tag "Deadline Warning days"
  258. (const org-deadline-warning-days)
  259. (integer :value 1))
  260. (list :tag "Tags filter preset"
  261. (const org-agenda-filter-preset)
  262. (list
  263. (const :format "" quote)
  264. (repeat
  265. (string :tag "+tag or -tag"))))
  266. (list :tag "Set daily/weekly entry types"
  267. (const org-agenda-entry-types)
  268. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  269. (const :deadline)
  270. (const :scheduled)
  271. (const :timestamp)
  272. (const :sexp)))
  273. (list :tag "Standard skipping condition"
  274. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  275. (const org-agenda-skip-function)
  276. (list
  277. (const :format "" quote)
  278. (list
  279. (choice
  280. :tag "Skipping range"
  281. (const :tag "Skip entry" org-agenda-skip-entry-if)
  282. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  283. (repeat :inline t :tag "Conditions for skipping"
  284. (choice
  285. :tag "Condition type"
  286. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  287. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  288. (list :tag "TODO state is" :inline t
  289. (const 'todo)
  290. (choice
  291. (const :tag "any not-done state" 'todo)
  292. (const :tag "any done state" 'done)
  293. (const :tag "any state" 'any)
  294. (list :tag "Keyword list"
  295. (const :format "" quote)
  296. (repeat (string :tag "Keyword")))))
  297. (list :tag "TODO state is not" :inline t
  298. (const 'nottodo)
  299. (choice
  300. (const :tag "any not-done state" 'todo)
  301. (const :tag "any done state" 'done)
  302. (const :tag "any state" 'any)
  303. (list :tag "Keyword list"
  304. (const :format "" quote)
  305. (repeat (string :tag "Keyword")))))
  306. (const :tag "scheduled" 'scheduled)
  307. (const :tag "not scheduled" 'notscheduled)
  308. (const :tag "deadline" 'deadline)
  309. (const :tag "no deadline" 'notdeadline)
  310. (const :tag "timestamp" 'timestamp)
  311. (const :tag "no timestamp" 'nottimestamp))))))
  312. (list :tag "Non-standard skipping condition"
  313. :value (org-agenda-skip-function)
  314. (const org-agenda-skip-function)
  315. (sexp :tag "Function or form (quoted!)"))
  316. (list :tag "Any variable"
  317. (variable :tag "Variable")
  318. (sexp :tag "Value (sexp)"))))
  319. "Selection of examples for agenda command settings.
  320. This will be spliced into the custom type of
  321. `org-agenda-custom-commands'.")
  322. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  323. ((agenda "") (alltodo))))
  324. "Custom commands for the agenda.
  325. These commands will be offered on the splash screen displayed by the
  326. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  327. (key desc type match settings files)
  328. key The key (one or more characters as a string) to be associated
  329. with the command.
  330. desc A description of the command, when omitted or nil, a default
  331. description is built using MATCH.
  332. type The command type, any of the following symbols:
  333. agenda The daily/weekly agenda.
  334. todo Entries with a specific TODO keyword, in all agenda files.
  335. search Entries containing search words entry or headline.
  336. tags Tags/Property/TODO match in all agenda files.
  337. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  338. todo-tree Sparse tree of specific TODO keyword in *current* file.
  339. tags-tree Sparse tree with all tags matches in *current* file.
  340. occur-tree Occur sparse tree for *current* file.
  341. ... A user-defined function.
  342. match What to search for:
  343. - a single keyword for TODO keyword searches
  344. - a tags match expression for tags searches
  345. - a word search expression for text searches.
  346. - a regular expression for occur searches
  347. For all other commands, this should be the empty string.
  348. settings A list of option settings, similar to that in a let form, so like
  349. this: ((opt1 val1) (opt2 val2) ...). The values will be
  350. evaluated at the moment of execution, so quote them when needed.
  351. files A list of files file to write the produced agenda buffer to
  352. with the command `org-store-agenda-views'.
  353. If a file name ends in \".html\", an HTML version of the buffer
  354. is written out. If it ends in \".ps\", a postscript version is
  355. produced. Otherwise, only the plain text is written to the file.
  356. You can also define a set of commands, to create a composite agenda buffer.
  357. In this case, an entry looks like this:
  358. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  359. where
  360. desc A description string to be displayed in the dispatcher menu.
  361. cmd An agenda command, similar to the above. However, tree commands
  362. are no allowed, but instead you can get agenda and global todo list.
  363. So valid commands for a set are:
  364. (agenda \"\" settings)
  365. (alltodo \"\" settings)
  366. (stuck \"\" settings)
  367. (todo \"match\" settings files)
  368. (search \"match\" settings files)
  369. (tags \"match\" settings files)
  370. (tags-todo \"match\" settings files)
  371. Each command can carry a list of options, and another set of options can be
  372. given for the whole set of commands. Individual command options take
  373. precedence over the general options.
  374. When using several characters as key to a command, the first characters
  375. are prefix commands. For the dispatcher to display useful information, you
  376. should provide a description for the prefix, like
  377. (setq org-agenda-custom-commands
  378. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  379. (\"hl\" tags \"+HOME+Lisa\")
  380. (\"hp\" tags \"+HOME+Peter\")
  381. (\"hk\" tags \"+HOME+Kim\")))"
  382. :group 'org-agenda-custom-commands
  383. :type `(repeat
  384. (choice :value ("x" "Describe command here" tags "" nil)
  385. (list :tag "Single command"
  386. (string :tag "Access Key(s) ")
  387. (option (string :tag "Description"))
  388. (choice
  389. (const :tag "Agenda" agenda)
  390. (const :tag "TODO list" alltodo)
  391. (const :tag "Search words" search)
  392. (const :tag "Stuck projects" stuck)
  393. (const :tag "Tags/Property match (all agenda files)" tags)
  394. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  395. (const :tag "TODO keyword search (all agenda files)" todo)
  396. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  397. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  398. (const :tag "Occur tree (current buffer)" occur-tree)
  399. (sexp :tag "Other, user-defined function"))
  400. (string :tag "Match (only for some commands)")
  401. ,org-agenda-custom-commands-local-options
  402. (option (repeat :tag "Export" (file :tag "Export to"))))
  403. (list :tag "Command series, all agenda files"
  404. (string :tag "Access Key(s)")
  405. (string :tag "Description ")
  406. (repeat :tag "Component"
  407. (choice
  408. (list :tag "Agenda"
  409. (const :format "" agenda)
  410. (const :tag "" :format "" "")
  411. ,org-agenda-custom-commands-local-options)
  412. (list :tag "TODO list (all keywords)"
  413. (const :format "" alltodo)
  414. (const :tag "" :format "" "")
  415. ,org-agenda-custom-commands-local-options)
  416. (list :tag "Search words"
  417. (const :format "" search)
  418. (string :tag "Match")
  419. ,org-agenda-custom-commands-local-options)
  420. (list :tag "Stuck projects"
  421. (const :format "" stuck)
  422. (const :tag "" :format "" "")
  423. ,org-agenda-custom-commands-local-options)
  424. (list :tag "Tags search"
  425. (const :format "" tags)
  426. (string :tag "Match")
  427. ,org-agenda-custom-commands-local-options)
  428. (list :tag "Tags search, TODO entries only"
  429. (const :format "" tags-todo)
  430. (string :tag "Match")
  431. ,org-agenda-custom-commands-local-options)
  432. (list :tag "TODO keyword search"
  433. (const :format "" todo)
  434. (string :tag "Match")
  435. ,org-agenda-custom-commands-local-options)
  436. (list :tag "Other, user-defined function"
  437. (symbol :tag "function")
  438. (string :tag "Match")
  439. ,org-agenda-custom-commands-local-options)))
  440. (repeat :tag "Settings for entire command set"
  441. (list (variable :tag "Any variable")
  442. (sexp :tag "Value")))
  443. (option (repeat :tag "Export" (file :tag "Export to"))))
  444. (cons :tag "Prefix key documentation"
  445. (string :tag "Access Key(s)")
  446. (string :tag "Description ")))))
  447. (defcustom org-agenda-query-register ?o
  448. "The register holding the current query string.
  449. The purpose of this is that if you construct a query string interactively,
  450. you can then use it to define a custom command."
  451. :group 'org-agenda-custom-commands
  452. :type 'character)
  453. (defcustom org-stuck-projects
  454. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  455. "How to identify stuck projects.
  456. This is a list of four items:
  457. 1. A tags/todo/property matcher string that is used to identify a project.
  458. See the manual for a description of tag and property searches.
  459. The entire tree below a headline matched by this is considered one project.
  460. 2. A list of TODO keywords identifying non-stuck projects.
  461. If the project subtree contains any headline with one of these todo
  462. keywords, the project is considered to be not stuck. If you specify
  463. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  464. 3. A list of tags identifying non-stuck projects.
  465. If the project subtree contains any headline with one of these tags,
  466. the project is considered to be not stuck. If you specify \"*\" as
  467. a tag, any tag will mark the project unstuck. Note that this is about
  468. the explicit presence of a tag somewhere in the subtree, inherited
  469. tags to not count here. If inherited tags make a project not stuck,
  470. use \"-TAG\" in the tags part of the matcher under (1.) above.
  471. 4. An arbitrary regular expression matching non-stuck projects.
  472. If the project turns out to be not stuck, search continues also in the
  473. subtree to see if any of the subtasks have project status.
  474. See also the variable `org-tags-match-list-sublevels' which applies
  475. to projects matched by this search as well.
  476. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  477. or `C-c a #' to produce the list."
  478. :group 'org-agenda-custom-commands
  479. :type '(list
  480. (string :tag "Tags/TODO match to identify a project")
  481. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  482. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  483. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  484. (defcustom org-agenda-filter-effort-default-operator "<"
  485. "The default operator for effort estimate filtering.
  486. If you select an effort estimate limit without first pressing an operator,
  487. this one will be used."
  488. :group 'org-agenda-custom-commands
  489. :type '(choice (const :tag "less or equal" "<")
  490. (const :tag "greater or equal"">")
  491. (const :tag "equal" "=")))
  492. (defgroup org-agenda-skip nil
  493. "Options concerning skipping parts of agenda files."
  494. :tag "Org Agenda Skip"
  495. :group 'org-agenda)
  496. (defcustom org-agenda-skip-function-global nil
  497. "Function to be called at each match during agenda construction.
  498. If this function returns nil, the current match should not be skipped.
  499. If the function decided to skip an agenda match, is must return the
  500. buffer position from which the search should be continued.
  501. This may also be a Lisp form, which will be evaluated.
  502. This variable will be applied to every agenda match, including
  503. tags/property searches and TODO lists. So try to make the test function
  504. do its checking as efficiently as possible. To implement a skipping
  505. condition just for specific agenda commands, use the variable
  506. `org-agenda-skip-function' which can be set in the options section
  507. of custom agenda commands."
  508. :group 'org-agenda-skip
  509. :type 'sexp)
  510. (defgroup org-agenda-daily/weekly nil
  511. "Options concerning the daily/weekly agenda."
  512. :tag "Org Agenda Daily/Weekly"
  513. :group 'org-agenda)
  514. (defgroup org-agenda-todo-list nil
  515. "Options concerning the global todo list agenda view."
  516. :tag "Org Agenda Todo List"
  517. :group 'org-agenda)
  518. (defgroup org-agenda-match-view nil
  519. "Options concerning the general tags/property/todo match agenda view."
  520. :tag "Org Agenda Match View"
  521. :group 'org-agenda)
  522. (defgroup org-agenda-search-view nil
  523. "Options concerning the general tags/property/todo match agenda view."
  524. :tag "Org Agenda Match View"
  525. :group 'org-agenda)
  526. (defvar org-agenda-archives-mode nil
  527. "Non-nil means the agenda will include archived items.
  528. If this is the symbol `trees', trees in the selected agenda scope
  529. that are marked with the ARCHIVE tag will be included anyway. When this is
  530. t, also all archive files associated with the current selection of agenda
  531. files will be included.")
  532. (defcustom org-agenda-skip-comment-trees t
  533. "Non-nil means skip trees that start with the COMMENT keyword.
  534. When nil, these trees are also scanned by agenda commands."
  535. :group 'org-agenda-skip
  536. :type 'boolean)
  537. (defcustom org-agenda-todo-list-sublevels t
  538. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  539. When nil, the sublevels of a TODO entry are not checked, resulting in
  540. potentially much shorter TODO lists."
  541. :group 'org-agenda-skip
  542. :group 'org-agenda-todo-list
  543. :type 'boolean)
  544. (defcustom org-agenda-todo-ignore-with-date nil
  545. "Non-nil means don't show entries with a date in the global todo list.
  546. You can use this if you prefer to mark mere appointments with a TODO keyword,
  547. but don't want them to show up in the TODO list.
  548. When this is set, it also covers deadlines and scheduled items, the settings
  549. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  550. will be ignored.
  551. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  552. :group 'org-agenda-skip
  553. :group 'org-agenda-todo-list
  554. :type 'boolean)
  555. (defcustom org-agenda-todo-ignore-timestamp nil
  556. "Non-nil means don't show entries with a timestamp.
  557. This applies when creating the global todo list.
  558. Valid values are:
  559. past Don't show entries for today or in the past.
  560. future Don't show entries with a timestamp in the future.
  561. The idea behind this is that if it has a future
  562. timestamp, you don't want to think about it until the
  563. date.
  564. all Don't show any entries with a timestamp in the global todo list.
  565. The idea behind this is that by setting a timestamp, you
  566. have already \"taken care\" of this item.
  567. This variable can also have an integer as a value. If positive (N),
  568. todos with a timestamp N or more days in the future will be ignored. If
  569. negative (-N), todos with a timestamp N or more days in the past will be
  570. ignored. If 0, todos with a timestamp either today or in the future will
  571. be ignored. For example, a value of -1 will exclude todos with a
  572. timestamp in the past (yesterday or earlier), while a value of 7 will
  573. exclude todos with a timestamp a week or more in the future.
  574. See also `org-agenda-todo-ignore-with-date'.
  575. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  576. to make his option also apply to the tags-todo list."
  577. :group 'org-agenda-skip
  578. :group 'org-agenda-todo-list
  579. :type '(choice
  580. (const :tag "Ignore future timestamp todos" future)
  581. (const :tag "Ignore past or present timestamp todos" past)
  582. (const :tag "Ignore all timestamp todos" all)
  583. (const :tag "Show timestamp todos" nil)
  584. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  585. (defcustom org-agenda-todo-ignore-scheduled nil
  586. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  587. This applies when creating the global todo list.
  588. Valid values are:
  589. past Don't show entries scheduled today or in the past.
  590. future Don't show entries scheduled in the future.
  591. The idea behind this is that by scheduling it, you don't want to
  592. think about it until the scheduled date.
  593. all Don't show any scheduled entries in the global todo list.
  594. The idea behind this is that by scheduling it, you have already
  595. \"taken care\" of this item.
  596. t Same as `all', for backward compatibility.
  597. This variable can also have an integer as a value. See
  598. `org-agenda-todo-ignore-timestamp' for more details.
  599. See also `org-agenda-todo-ignore-with-date'.
  600. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  601. to make his option also apply to the tags-todo list."
  602. :group 'org-agenda-skip
  603. :group 'org-agenda-todo-list
  604. :type '(choice
  605. (const :tag "Ignore future-scheduled todos" future)
  606. (const :tag "Ignore past- or present-scheduled todos" past)
  607. (const :tag "Ignore all scheduled todos" all)
  608. (const :tag "Ignore all scheduled todos (compatibility)" t)
  609. (const :tag "Show scheduled todos" nil)
  610. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  611. (defcustom org-agenda-todo-ignore-deadlines nil
  612. "Non-nil means ignore some deadlined TODO items when making TODO list.
  613. There are different motivations for using different values, please think
  614. carefully when configuring this variable.
  615. This applies when creating the global todo list.
  616. Valid values are:
  617. near Don't show near deadline entries. A deadline is near when it is
  618. closer than `org-deadline-warning-days' days. The idea behind this
  619. is that such items will appear in the agenda anyway.
  620. far Don't show TODO entries where a deadline has been defined, but
  621. the deadline is not near. This is useful if you don't want to
  622. use the todo list to figure out what to do now.
  623. past Don't show entries with a deadline timestamp for today or in the past.
  624. future Don't show entries with a deadline timestamp in the future, not even
  625. when they become `near' ones. Use it with caution.
  626. all Ignore all TODO entries that do have a deadline.
  627. t Same as `near', for backward compatibility.
  628. This variable can also have an integer as a value. See
  629. `org-agenda-todo-ignore-timestamp' for more details.
  630. See also `org-agenda-todo-ignore-with-date'.
  631. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  632. to make his option also apply to the tags-todo list."
  633. :group 'org-agenda-skip
  634. :group 'org-agenda-todo-list
  635. :type '(choice
  636. (const :tag "Ignore near deadlines" near)
  637. (const :tag "Ignore near deadlines (compatibility)" t)
  638. (const :tag "Ignore far deadlines" far)
  639. (const :tag "Ignore all TODOs with a deadlines" all)
  640. (const :tag "Show all TODOs, even if they have a deadline" nil)
  641. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  642. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  643. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  644. The variables
  645. `org-agenda-todo-ignore-with-date',
  646. `org-agenda-todo-ignore-timestamp',
  647. `org-agenda-todo-ignore-scheduled',
  648. `org-agenda-todo-ignore-deadlines'
  649. make the global TODO list skip entries that have time stamps of certain
  650. kinds. If this option is set, the same options will also apply for the
  651. tags-todo search, which is the general tags/property matcher
  652. restricted to unfinished TODO entries only."
  653. :group 'org-agenda-skip
  654. :group 'org-agenda-todo-list
  655. :group 'org-agenda-match-view
  656. :type 'boolean)
  657. (defcustom org-agenda-skip-scheduled-if-done nil
  658. "Non-nil means don't show scheduled items in agenda when they are done.
  659. This is relevant for the daily/weekly agenda, not for the TODO list. And
  660. it applies only to the actual date of the scheduling. Warnings about
  661. an item with a past scheduling dates are always turned off when the item
  662. is DONE."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-daily/weekly
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  667. "Non-nil means skip scheduling line if same entry shows because of deadline.
  668. In the agenda of today, an entry can show up multiple times because
  669. it is both scheduled and has a nearby deadline, and maybe a plain time
  670. stamp as well.
  671. When this variable is t, then only the deadline is shown and the fact that
  672. the entry is scheduled today or was scheduled previously is not shown.
  673. When this variable is nil, the entry will be shown several times. When
  674. the variable is the symbol `not-today', then skip scheduled previously,
  675. but not scheduled today."
  676. :group 'org-agenda-skip
  677. :group 'org-agenda-daily/weekly
  678. :type '(choice
  679. (const :tag "Never" nil)
  680. (const :tag "Always" t)
  681. (const :tag "Not when scheduled today" not-today)))
  682. (defcustom org-agenda-skip-deadline-if-done nil
  683. "Non-nil means don't show deadlines when the corresponding item is done.
  684. When nil, the deadline is still shown and should give you a happy feeling.
  685. This is relevant for the daily/weekly agenda. And it applied only to the
  686. actually date of the deadline. Warnings about approaching and past-due
  687. deadlines are always turned off when the item is DONE."
  688. :group 'org-agenda-skip
  689. :group 'org-agenda-daily/weekly
  690. :type 'boolean)
  691. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  692. "Non-nil means skip deadline prewarning when entry is also scheduled.
  693. This will apply on all days where a prewarning for the deadline would
  694. be shown, but not at the day when the entry is actually due. On that day,
  695. the deadline will be shown anyway.
  696. This variable may be set to nil, t, or a number which will then give
  697. the number of days before the actual deadline when the prewarnings
  698. should resume.
  699. This can be used in a workflow where the first showing of the deadline will
  700. trigger you to schedule it, and then you don't want to be reminded of it
  701. because you will take care of it on the day when scheduled."
  702. :group 'org-agenda-skip
  703. :group 'org-agenda-daily/weekly
  704. :type '(choice
  705. (const :tag "Alwas show prewarning" nil)
  706. (const :tag "Remove prewarning if entry is scheduled" t)
  707. (integer :tag "Restart prewarning N days before deadline")))
  708. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  709. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  710. When non-nil, after the search for timestamps has matched once in an
  711. entry, the rest of the entry will not be searched."
  712. :group 'org-agenda-skip
  713. :type 'boolean)
  714. (defcustom org-agenda-skip-timestamp-if-done nil
  715. "Non-nil means don't select item by timestamp or -range if it is DONE."
  716. :group 'org-agenda-skip
  717. :group 'org-agenda-daily/weekly
  718. :type 'boolean)
  719. (defcustom org-agenda-dim-blocked-tasks t
  720. "Non-nil means dim blocked tasks in the agenda display.
  721. This causes some overhead during agenda construction, but if you
  722. have turned on `org-enforce-todo-dependencies',
  723. `org-enforce-todo-checkbox-dependencies', or any other blocking
  724. mechanism, this will create useful feedback in the agenda.
  725. Instead of t, this variable can also have the value `invisible'.
  726. Then blocked tasks will be invisible and only become visible when
  727. they become unblocked. An exemption to this behavior is when a task is
  728. blocked because of unchecked checkboxes below it. Since checkboxes do
  729. not show up in the agenda views, making this task invisible you remove any
  730. trace from agenda views that there is something to do. Therefore, a task
  731. that is blocked because of checkboxes will never be made invisible, it
  732. will only be dimmed."
  733. :group 'org-agenda-daily/weekly
  734. :group 'org-agenda-todo-list
  735. :type '(choice
  736. (const :tag "Do not dim" nil)
  737. (const :tag "Dim to a grey face" t)
  738. (const :tag "Make invisible" invisible)))
  739. (defcustom org-timeline-show-empty-dates 3
  740. "Non-nil means `org-timeline' also shows dates without an entry.
  741. When nil, only the days which actually have entries are shown.
  742. When t, all days between the first and the last date are shown.
  743. When an integer, show also empty dates, but if there is a gap of more than
  744. N days, just insert a special line indicating the size of the gap."
  745. :group 'org-agenda-skip
  746. :type '(choice
  747. (const :tag "None" nil)
  748. (const :tag "All" t)
  749. (integer :tag "at most")))
  750. (defgroup org-agenda-startup nil
  751. "Options concerning initial settings in the Agenda in Org Mode."
  752. :tag "Org Agenda Startup"
  753. :group 'org-agenda)
  754. (defcustom org-agenda-menu-show-matcher t
  755. "Non-nil means show the match string in the agenda dispatcher menu.
  756. When nil, the matcher string is not shown, but is put into the help-echo
  757. property so than moving the mouse over the command shows it.
  758. Setting it to nil is good if matcher strings are very long and/or if
  759. you want to use two-column display (see `org-agenda-menu-two-column')."
  760. :group 'org-agenda
  761. :type 'boolean)
  762. (defcustom org-agenda-menu-two-column nil
  763. "Non-nil means, use two columns to show custom commands in the dispatcher.
  764. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  765. to nil."
  766. :group 'org-agenda
  767. :type 'boolean)
  768. (defcustom org-finalize-agenda-hook nil
  769. "Hook run just before displaying an agenda buffer."
  770. :group 'org-agenda-startup
  771. :type 'hook)
  772. (defcustom org-agenda-mouse-1-follows-link nil
  773. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  774. A longer mouse click will still set point. Does not work on XEmacs.
  775. Needs to be set before org.el is loaded."
  776. :group 'org-agenda-startup
  777. :type 'boolean)
  778. (defcustom org-agenda-start-with-follow-mode nil
  779. "The initial value of follow mode in a newly created agenda window."
  780. :group 'org-agenda-startup
  781. :type 'boolean)
  782. (defcustom org-agenda-show-outline-path t
  783. "Non-nil means show outline path in echo area after line motion."
  784. :group 'org-agenda-startup
  785. :type 'boolean)
  786. (defcustom org-agenda-start-with-entry-text-mode nil
  787. "The initial value of entry-text-mode in a newly created agenda window."
  788. :group 'org-agenda-startup
  789. :type 'boolean)
  790. (defcustom org-agenda-entry-text-maxlines 5
  791. "Number of text lines to be added when `E' is pressed in the agenda.
  792. Note that this variable only used during agenda display. Add add entry text
  793. when exporting the agenda, configure the variable
  794. `org-agenda-add-entry-ext-maxlines'."
  795. :group 'org-agenda
  796. :type 'integer)
  797. (defcustom org-agenda-entry-text-exclude-regexps nil
  798. "List of regular expressions to clean up entry text.
  799. The complete matches of all regular expressions in this list will be
  800. removed from entry text before it is shown in the agenda."
  801. :group 'org-agenda
  802. :type '(repeat (regexp)))
  803. (defvar org-agenda-entry-text-cleanup-hook nil
  804. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  805. This cleanup is done in a temporary buffer, so the function may inspect and
  806. change the entire buffer.
  807. Some default stuff like drawers and scheduling/deadline dates will already
  808. have been removed when this is called, as will any matches for regular
  809. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  810. (defvar org-agenda-include-inactive-timestamps nil
  811. "Non-nil means include inactive time stamps in agenda and timeline.")
  812. (defgroup org-agenda-windows nil
  813. "Options concerning the windows used by the Agenda in Org Mode."
  814. :tag "Org Agenda Windows"
  815. :group 'org-agenda)
  816. (defcustom org-agenda-window-setup 'reorganize-frame
  817. "How the agenda buffer should be displayed.
  818. Possible values for this option are:
  819. current-window Show agenda in the current window, keeping all other windows.
  820. other-window Use `switch-to-buffer-other-window' to display agenda.
  821. reorganize-frame Show only two windows on the current frame, the current
  822. window and the agenda.
  823. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  824. Also, when exiting the agenda, kill that frame.
  825. See also the variable `org-agenda-restore-windows-after-quit'."
  826. :group 'org-agenda-windows
  827. :type '(choice
  828. (const current-window)
  829. (const other-frame)
  830. (const other-window)
  831. (const reorganize-frame)))
  832. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  833. "The min and max height of the agenda window as a fraction of frame height.
  834. The value of the variable is a cons cell with two numbers between 0 and 1.
  835. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  836. :group 'org-agenda-windows
  837. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  838. (defcustom org-agenda-restore-windows-after-quit nil
  839. "Non-nil means restore window configuration upon exiting agenda.
  840. Before the window configuration is changed for displaying the agenda,
  841. the current status is recorded. When the agenda is exited with
  842. `q' or `x' and this option is set, the old state is restored. If
  843. `org-agenda-window-setup' is `other-frame', the value of this
  844. option will be ignored."
  845. :group 'org-agenda-windows
  846. :type 'boolean)
  847. (defcustom org-agenda-ndays nil
  848. "Number of days to include in overview display.
  849. Should be 1 or 7.
  850. Obsolete, see `org-agenda-span'."
  851. :group 'org-agenda-daily/weekly
  852. :type 'integer)
  853. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  854. (defcustom org-agenda-span 'week
  855. "Number of days to include in overview display.
  856. Can be day, week, month, year, or any number of days.
  857. Custom commands can set this variable in the options section."
  858. :group 'org-agenda-daily/weekly
  859. :type '(choice (const :tag "Day" day)
  860. (const :tag "Week" week)
  861. (const :tag "Month" month)
  862. (const :tag "Year" year)
  863. (integer :tag "Custom")))
  864. (defcustom org-agenda-start-on-weekday 1
  865. "Non-nil means start the overview always on the specified weekday.
  866. 0 denotes Sunday, 1 denotes Monday etc.
  867. When nil, always start on the current day.
  868. Custom commands can set this variable in the options section."
  869. :group 'org-agenda-daily/weekly
  870. :type '(choice (const :tag "Today" nil)
  871. (integer :tag "Weekday No.")))
  872. (defcustom org-agenda-show-all-dates t
  873. "Non-nil means `org-agenda' shows every day in the selected range.
  874. When nil, only the days which actually have entries are shown."
  875. :group 'org-agenda-daily/weekly
  876. :type 'boolean)
  877. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  878. "Format string for displaying dates in the agenda.
  879. Used by the daily/weekly agenda and by the timeline. This should be
  880. a format string understood by `format-time-string', or a function returning
  881. the formatted date as a string. The function must take a single argument,
  882. a calendar-style date list like (month day year)."
  883. :group 'org-agenda-daily/weekly
  884. :type '(choice
  885. (string :tag "Format string")
  886. (function :tag "Function")))
  887. (defun org-agenda-format-date-aligned (date)
  888. "Format a date string for display in the daily/weekly agenda, or timeline.
  889. This function makes sure that dates are aligned for easy reading."
  890. (require 'cal-iso)
  891. (let* ((dayname (calendar-day-name date))
  892. (day (cadr date))
  893. (day-of-week (calendar-day-of-week date))
  894. (month (car date))
  895. (monthname (calendar-month-name month))
  896. (year (nth 2 date))
  897. (iso-week (org-days-to-iso-week
  898. (calendar-absolute-from-gregorian date)))
  899. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  900. (1- year))
  901. ((and (= month 12) (<= iso-week 1))
  902. (1+ year))
  903. (t year)))
  904. (weekstring (if (= day-of-week 1)
  905. (format " W%02d" iso-week)
  906. "")))
  907. (format "%-10s %2d %s %4d%s"
  908. dayname day monthname year weekstring)))
  909. (defcustom org-agenda-time-leading-zero nil
  910. "Non-nil means use leading zero for military times in agenda.
  911. For example, 9:30am would become 09:30 rather than 9:30."
  912. :group 'org-agenda-daily/weekly
  913. :type 'boolean)
  914. (defcustom org-agenda-timegrid-use-ampm nil
  915. "When set, show AM/PM style timestamps on the timegrid."
  916. :group 'org-agenda
  917. :type 'boolean)
  918. (defun org-agenda-time-of-day-to-ampm (time)
  919. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  920. (let* ((hour-number (string-to-number (substring time 0 -3)))
  921. (minute (substring time -2))
  922. (ampm "am"))
  923. (cond
  924. ((equal hour-number 12)
  925. (setq ampm "pm"))
  926. ((> hour-number 12)
  927. (setq ampm "pm")
  928. (setq hour-number (- hour-number 12))))
  929. (concat
  930. (if org-agenda-time-leading-zero
  931. (format "%02d" hour-number)
  932. (format "%02s" (number-to-string hour-number)))
  933. ":" minute ampm)))
  934. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  935. "Conditionally convert TIME to AM/PM format
  936. based on `org-agenda-timegrid-use-ampm'"
  937. (if org-agenda-timegrid-use-ampm
  938. (org-agenda-time-of-day-to-ampm time)
  939. time))
  940. (defcustom org-agenda-weekend-days '(6 0)
  941. "Which days are weekend?
  942. These days get the special face `org-agenda-date-weekend' in the agenda
  943. and timeline buffers."
  944. :group 'org-agenda-daily/weekly
  945. :type '(set :greedy t
  946. (const :tag "Monday" 1)
  947. (const :tag "Tuesday" 2)
  948. (const :tag "Wednesday" 3)
  949. (const :tag "Thursday" 4)
  950. (const :tag "Friday" 5)
  951. (const :tag "Saturday" 6)
  952. (const :tag "Sunday" 0)))
  953. (defcustom org-agenda-include-diary nil
  954. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  955. Custom commands can set this variable in the options section."
  956. :group 'org-agenda-daily/weekly
  957. :type 'boolean)
  958. (defcustom org-agenda-include-deadlines t
  959. "If non-nil, include entries within their deadline warning period.
  960. Custom commands can set this variable in the options section."
  961. :group 'org-agenda-daily/weekly
  962. :type 'boolean)
  963. (defcustom org-agenda-repeating-timestamp-show-all t
  964. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  965. When set to a list of strings, only show occurrences of repeating
  966. stamps for these TODO keywords. When nil, only one occurrence is
  967. shown, either today or the nearest into the future."
  968. :group 'org-agenda-daily/weekly
  969. :type '(choice
  970. (const :tag "Show repeating stamps" t)
  971. (repeat :tag "Show repeating stamps for these TODO keywords"
  972. (string :tag "TODO Keyword"))
  973. (const :tag "Don't show repeating stamps" nil)))
  974. (defcustom org-scheduled-past-days 10000
  975. "No. of days to continue listing scheduled items that are not marked DONE.
  976. When an item is scheduled on a date, it shows up in the agenda on this
  977. day and will be listed until it is marked done for the number of days
  978. given here."
  979. :group 'org-agenda-daily/weekly
  980. :type 'integer)
  981. (defcustom org-agenda-log-mode-items '(closed clock)
  982. "List of items that should be shown in agenda log mode.
  983. This list may contain the following symbols:
  984. closed Show entries that have been closed on that day.
  985. clock Show entries that have received clocked time on that day.
  986. state Show all logged state changes.
  987. Note that instead of changing this variable, you can also press `C-u l' in
  988. the agenda to display all available LOG items temporarily."
  989. :group 'org-agenda-daily/weekly
  990. :type '(set :greedy t (const closed) (const clock) (const state)))
  991. (defcustom org-agenda-clock-consistency-checks
  992. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  993. :gap-ok-around ("4:00")
  994. :default-face ((:background "DarkRed") (:foreground "white"))
  995. :overlap-face nil :gap-face nil :no-end-time-face nil
  996. :long-face nil :short-face nil)
  997. "This is a property list, with the following keys:
  998. :max-duration Mark clocking chunks that are longer than this time.
  999. This is a time string like \"HH:MM\", or the number
  1000. of minutes as an integer.
  1001. :min-duration Mark clocking chunks that are shorter that this.
  1002. This is a time string like \"HH:MM\", or the number
  1003. of minutes as an integer.
  1004. :max-gap Mark gaps between clocking chunks that are longer than
  1005. this duration. A number of minutes, or a string
  1006. like \"HH:MM\".
  1007. :gap-ok-around List of times during the day which are usually not working
  1008. times. When a gap is detected, but the gap contains any
  1009. of these times, the gap is *not* reported. For example,
  1010. if this is (\"4:00\" \"13:00\") then gaps that contain
  1011. 4:00 in the morning (i.e. the night) and 13:00
  1012. (i.e. a typical lunch time) do not cause a warning.
  1013. You should have at least one time during the night in this
  1014. list, or otherwise the first task each morning will trigger
  1015. a warning because it follows a long gap.
  1016. Furthermore, the following properties can be used to define faces for
  1017. issue display.
  1018. :default-face the default face, if the specific face is undefined
  1019. :overlap-face face for overlapping clocks
  1020. :gap-face face for gaps between clocks
  1021. :no-end-time-face face for incomplete clocks
  1022. :long-face face for clock intervals that are too long
  1023. :short-face face for clock intervals that are too short"
  1024. :group 'org-agenda-daily/weekly
  1025. :group 'org-clock
  1026. :type 'plist)
  1027. (defcustom org-agenda-log-mode-add-notes t
  1028. "Non-nil means add first line of notes to log entries in agenda views.
  1029. If a log item like a state change or a clock entry is associated with
  1030. notes, the first line of these notes will be added to the entry in the
  1031. agenda display."
  1032. :group 'org-agenda-daily/weekly
  1033. :type 'boolean)
  1034. (defcustom org-agenda-start-with-log-mode nil
  1035. "The initial value of log-mode in a newly created agenda window."
  1036. :group 'org-agenda-startup
  1037. :group 'org-agenda-daily/weekly
  1038. :type 'boolean)
  1039. (defcustom org-agenda-start-with-clockreport-mode nil
  1040. "The initial value of clockreport-mode in a newly created agenda window."
  1041. :group 'org-agenda-startup
  1042. :group 'org-agenda-daily/weekly
  1043. :type 'boolean)
  1044. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1045. "Property list with parameters for the clocktable in clockreport mode.
  1046. This is the display mode that shows a clock table in the daily/weekly
  1047. agenda, the properties for this dynamic block can be set here.
  1048. The usual clocktable parameters are allowed here, but you cannot set
  1049. the properties :name, :tstart, :tend, :block, and :scope - these will
  1050. be overwritten to make sure the content accurately reflects the
  1051. current display in the agenda."
  1052. :group 'org-agenda-daily/weekly
  1053. :type 'plist)
  1054. (defcustom org-agenda-search-view-always-boolean nil
  1055. "Non-nil means the search string is interpreted as individual parts.
  1056. The search string for search view can either be interpreted as a phrase,
  1057. or as a list of snippets that define a boolean search for a number of
  1058. strings.
  1059. When this is non-nil, the string will be split on whitespace, and each
  1060. snippet will be searched individually, and all must match in order to
  1061. select an entry. A snippet is then a single string of non-white
  1062. characters, or a string in double quotes, or a regexp in {} braces.
  1063. If a snippet is preceded by \"-\", the snippet must *not* match.
  1064. \"+\" is syntactic sugar for positive selection. Each snippet may
  1065. be found as a full word or a partial word, but see the variable
  1066. `org-agenda-search-view-force-full-words'.
  1067. When this is nil, search will look for the entire search phrase as one,
  1068. with each space character matching any amount of whitespace, including
  1069. line breaks.
  1070. Even when this is nil, you can still switch to Boolean search dynamically
  1071. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1072. is a regexp marked with braces like \"{abc}\", this will also switch to
  1073. boolean search."
  1074. :group 'org-agenda-search-view
  1075. :type 'boolean)
  1076. (if (fboundp 'defvaralias)
  1077. (defvaralias 'org-agenda-search-view-search-words-only
  1078. 'org-agenda-search-view-always-boolean))
  1079. (defcustom org-agenda-search-view-force-full-words nil
  1080. "Non-nil means, search words must be matches as complete words.
  1081. When nil, they may also match part of a word."
  1082. :group 'org-agenda-search-view
  1083. :type 'boolean)
  1084. (defgroup org-agenda-time-grid nil
  1085. "Options concerning the time grid in the Org-mode Agenda."
  1086. :tag "Org Agenda Time Grid"
  1087. :group 'org-agenda)
  1088. (defcustom org-agenda-search-headline-for-time t
  1089. "Non-nil means search headline for a time-of-day.
  1090. If the headline contains a time-of-day in one format or another, it will
  1091. be used to sort the entry into the time sequence of items for a day.
  1092. Some people have time stamps in the headline that refer to the creation
  1093. time or so, and then this produces an unwanted side effect. If this is
  1094. the case for your, use this variable to turn off searching the headline
  1095. for a time."
  1096. :group 'org-agenda-time-grid
  1097. :type 'boolean)
  1098. (defcustom org-agenda-use-time-grid t
  1099. "Non-nil means show a time grid in the agenda schedule.
  1100. A time grid is a set of lines for specific times (like every two hours between
  1101. 8:00 and 20:00). The items scheduled for a day at specific times are
  1102. sorted in between these lines.
  1103. For details about when the grid will be shown, and what it will look like, see
  1104. the variable `org-agenda-time-grid'."
  1105. :group 'org-agenda-time-grid
  1106. :type 'boolean)
  1107. (defcustom org-agenda-time-grid
  1108. '((daily today require-timed)
  1109. "----------------"
  1110. (800 1000 1200 1400 1600 1800 2000))
  1111. "The settings for time grid for agenda display.
  1112. This is a list of three items. The first item is again a list. It contains
  1113. symbols specifying conditions when the grid should be displayed:
  1114. daily if the agenda shows a single day
  1115. weekly if the agenda shows an entire week
  1116. today show grid on current date, independent of daily/weekly display
  1117. require-timed show grid only if at least one item has a time specification
  1118. The second item is a string which will be placed behind the grid time.
  1119. The third item is a list of integers, indicating the times that should have
  1120. a grid line."
  1121. :group 'org-agenda-time-grid
  1122. :type
  1123. '(list
  1124. (set :greedy t :tag "Grid Display Options"
  1125. (const :tag "Show grid in single day agenda display" daily)
  1126. (const :tag "Show grid in weekly agenda display" weekly)
  1127. (const :tag "Always show grid for today" today)
  1128. (const :tag "Show grid only if any timed entries are present"
  1129. require-timed)
  1130. (const :tag "Skip grid times already present in an entry"
  1131. remove-match))
  1132. (string :tag "Grid String")
  1133. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1134. (defcustom org-agenda-show-current-time-in-grid t
  1135. "Non-nil means show the current time in the time grid."
  1136. :group 'org-agenda-time-grid
  1137. :type 'boolean)
  1138. (defcustom org-agenda-current-time-string
  1139. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1140. "The string for the current time marker in the agenda."
  1141. :group 'org-agenda-time-grid
  1142. :type 'string)
  1143. (defgroup org-agenda-sorting nil
  1144. "Options concerning sorting in the Org-mode Agenda."
  1145. :tag "Org Agenda Sorting"
  1146. :group 'org-agenda)
  1147. (defcustom org-agenda-sorting-strategy
  1148. '((agenda habit-down time-up priority-down category-keep)
  1149. (todo priority-down category-keep)
  1150. (tags priority-down category-keep)
  1151. (search category-keep))
  1152. "Sorting structure for the agenda items of a single day.
  1153. This is a list of symbols which will be used in sequence to determine
  1154. if an entry should be listed before another entry. The following
  1155. symbols are recognized:
  1156. time-up Put entries with time-of-day indications first, early first
  1157. time-down Put entries with time-of-day indications first, late first
  1158. category-keep Keep the default order of categories, corresponding to the
  1159. sequence in `org-agenda-files'.
  1160. category-up Sort alphabetically by category, A-Z.
  1161. category-down Sort alphabetically by category, Z-A.
  1162. tag-up Sort alphabetically by last tag, A-Z.
  1163. tag-down Sort alphabetically by last tag, Z-A.
  1164. priority-up Sort numerically by priority, high priority last.
  1165. priority-down Sort numerically by priority, high priority first.
  1166. todo-state-up Sort by todo state, tasks that are done last.
  1167. todo-state-down Sort by todo state, tasks that are done first.
  1168. effort-up Sort numerically by estimated effort, high effort last.
  1169. effort-down Sort numerically by estimated effort, high effort first.
  1170. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1171. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1172. habit-up Put entries that are habits first
  1173. habit-down Put entries that are habits last
  1174. alpha-up Sort headlines alphabetically
  1175. alpha-down Sort headlines alphabetically, reversed
  1176. The different possibilities will be tried in sequence, and testing stops
  1177. if one comparison returns a \"not-equal\". For example, the default
  1178. '(time-up category-keep priority-down)
  1179. means: Pull out all entries having a specified time of day and sort them,
  1180. in order to make a time schedule for the current day the first thing in the
  1181. agenda listing for the day. Of the entries without a time indication, keep
  1182. the grouped in categories, don't sort the categories, but keep them in
  1183. the sequence given in `org-agenda-files'. Within each category sort by
  1184. priority.
  1185. Leaving out `category-keep' would mean that items will be sorted across
  1186. categories by priority.
  1187. Instead of a single list, this can also be a set of list for specific
  1188. contents, with a context symbol in the car of the list, any of
  1189. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1190. Custom commands can bind this variable in the options section."
  1191. :group 'org-agenda-sorting
  1192. :type `(choice
  1193. (repeat :tag "General" ,org-sorting-choice)
  1194. (list :tag "Individually"
  1195. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1196. (repeat ,org-sorting-choice))
  1197. (cons (const :tag "Strategy for TODO lists" todo)
  1198. (repeat ,org-sorting-choice))
  1199. (cons (const :tag "Strategy for Tags matches" tags)
  1200. (repeat ,org-sorting-choice))
  1201. (cons (const :tag "Strategy for search matches" search)
  1202. (repeat ,org-sorting-choice)))))
  1203. (defcustom org-agenda-cmp-user-defined nil
  1204. "A function to define the comparison `user-defined'.
  1205. This function must receive two arguments, agenda entry a and b.
  1206. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1207. the user comparison, return nil.
  1208. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1209. part of an agenda sorting strategy."
  1210. :group 'org-agenda-sorting
  1211. :type 'symbol)
  1212. (defcustom org-sort-agenda-notime-is-late t
  1213. "Non-nil means items without time are considered late.
  1214. This is only relevant for sorting. When t, items which have no explicit
  1215. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1216. do have a time. When nil, the default time is before 0:00. You can use this
  1217. option to decide if the schedule for today should come before or after timeless
  1218. agenda entries."
  1219. :group 'org-agenda-sorting
  1220. :type 'boolean)
  1221. (defcustom org-sort-agenda-noeffort-is-high t
  1222. "Non-nil means items without effort estimate are sorted as high effort.
  1223. This also applies when filtering an agenda view with respect to the
  1224. < or > effort operator. Then, tasks with no effort defined will be treated
  1225. as tasks with high effort.
  1226. When nil, such items are sorted as 0 minutes effort."
  1227. :group 'org-agenda-sorting
  1228. :type 'boolean)
  1229. (defgroup org-agenda-line-format nil
  1230. "Options concerning the entry prefix in the Org-mode agenda display."
  1231. :tag "Org Agenda Line Format"
  1232. :group 'org-agenda)
  1233. (defcustom org-agenda-prefix-format
  1234. '((agenda . " %i %-12:c%?-12t% s")
  1235. (timeline . " % s")
  1236. (todo . " %i %-12:c")
  1237. (tags . " %i %-12:c")
  1238. (search . " %i %-12:c"))
  1239. "Format specifications for the prefix of items in the agenda views.
  1240. An alist with five entries, each for the different agenda types. The
  1241. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1242. The values are format strings.
  1243. This format works similar to a printf format, with the following meaning:
  1244. %c the category of the item, \"Diary\" for entries from the diary,
  1245. or as given by the CATEGORY keyword or derived from the file name
  1246. %e the effort required by the item
  1247. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1248. %T the last tag of the item (ignore inherited tags, which come first)
  1249. %t the HH:MM time-of-day specification if one applies to the entry
  1250. %s Scheduling/Deadline information, a short string
  1251. %(expression) Eval EXPRESSION and replace the control string
  1252. by the result
  1253. All specifiers work basically like the standard `%s' of printf, but may
  1254. contain two additional characters: a question mark just after the `%'
  1255. and a whitespace/punctuation character just before the final letter.
  1256. If the first character after `%' is a question mark, the entire field
  1257. will only be included if the corresponding value applies to the current
  1258. entry. This is useful for fields which should have fixed width when
  1259. present, but zero width when absent. For example, \"%?-12t\" will
  1260. result in a 12 character time field if a time of the day is specified,
  1261. but will completely disappear in entries which do not contain a time.
  1262. If there is punctuation or whitespace character just before the final
  1263. format letter, this character will be appended to the field value if
  1264. the value is not empty. For example, the format \"%-12:c\" leads to
  1265. \"Diary: \" if the category is \"Diary\". If the category were be
  1266. empty, no additional colon would be inserted.
  1267. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1268. which means:
  1269. - Indent the line with two space characters
  1270. - Give the category a 12 chars wide field, padded with whitespace on
  1271. the right (because of `-'). Append a colon if there is a category
  1272. (because of `:').
  1273. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1274. time, don't put in an empty field, just skip it (because of '?').
  1275. - Finally, put the scheduling information.
  1276. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1277. `org-agenda-remove-tags'.
  1278. Custom commands can set this variable in the options section."
  1279. :type '(choice
  1280. (string :tag "General format")
  1281. (list :greedy t :tag "View dependent"
  1282. (cons (const agenda) (string :tag "Format"))
  1283. (cons (const timeline) (string :tag "Format"))
  1284. (cons (const todo) (string :tag "Format"))
  1285. (cons (const tags) (string :tag "Format"))
  1286. (cons (const search) (string :tag "Format"))))
  1287. :group 'org-agenda-line-format)
  1288. (defvar org-prefix-format-compiled nil
  1289. "The compiled version of the most recently used prefix format.
  1290. See the variable `org-agenda-prefix-format'.")
  1291. (defcustom org-agenda-todo-keyword-format "%-1s"
  1292. "Format for the TODO keyword in agenda lines.
  1293. Set this to something like \"%-12s\" if you want all TODO keywords
  1294. to occupy a fixed space in the agenda display."
  1295. :group 'org-agenda-line-format
  1296. :type 'string)
  1297. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1298. "Text preceding timerange entries in the agenda view.
  1299. This is a list with two strings. The first applies when the range
  1300. is entirely on one day. The second applies if the range spans several days.
  1301. The strings may have two \"%d\" format specifiers which will be filled
  1302. with the sequence number of the days, and the total number of days in the
  1303. range, respectively."
  1304. :group 'org-agenda-line-format
  1305. :type '(list
  1306. (string :tag "Deadline today ")
  1307. (choice :tag "Deadline relative"
  1308. (string :tag "Format string")
  1309. (function))))
  1310. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1311. "Text preceding scheduled items in the agenda view.
  1312. This is a list with two strings. The first applies when the item is
  1313. scheduled on the current day. The second applies when it has been scheduled
  1314. previously, it may contain a %d indicating that this is the nth time that
  1315. this item is scheduled, due to automatic rescheduling of unfinished items
  1316. for the following day. So this number is one larger than the number of days
  1317. that passed since this item was scheduled first."
  1318. :group 'org-agenda-line-format
  1319. :type '(list
  1320. (string :tag "Scheduled today ")
  1321. (string :tag "Scheduled previously")))
  1322. (defcustom org-agenda-inactive-leader "["
  1323. "Text preceding item pulled into the agenda by inactive time stamps.
  1324. These entries are added to the agenda when pressing \"[\"."
  1325. :group 'org-agenda-line-format
  1326. :type '(list
  1327. (string :tag "Scheduled today ")
  1328. (string :tag "Scheduled previously")))
  1329. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1330. "Text preceding deadline items in the agenda view.
  1331. This is a list with two strings. The first applies when the item has its
  1332. deadline on the current day. The second applies when it is in the past or
  1333. in the future, it may contain %d to capture how many days away the deadline
  1334. is (was)."
  1335. :group 'org-agenda-line-format
  1336. :type '(list
  1337. (string :tag "Deadline today ")
  1338. (choice :tag "Deadline relative"
  1339. (string :tag "Format string")
  1340. (function))))
  1341. (defcustom org-agenda-remove-times-when-in-prefix t
  1342. "Non-nil means remove duplicate time specifications in agenda items.
  1343. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1344. time-of-day specification in a headline or diary entry is extracted and
  1345. placed into the prefix. If this option is non-nil, the original specification
  1346. \(a timestamp or -range, or just a plain time(range) specification like
  1347. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1348. cluttered.
  1349. The option can be t or nil. It may also be the symbol `beg', indicating
  1350. that the time should only be removed when it is located at the beginning of
  1351. the headline/diary entry."
  1352. :group 'org-agenda-line-format
  1353. :type '(choice
  1354. (const :tag "Always" t)
  1355. (const :tag "Never" nil)
  1356. (const :tag "When at beginning of entry" beg)))
  1357. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1358. "Non-nil means remove time ranges specifications in agenda
  1359. items that span on several days."
  1360. :group 'org-agenda-line-format
  1361. :type 'boolean)
  1362. (defcustom org-agenda-default-appointment-duration nil
  1363. "Default duration for appointments that only have a starting time.
  1364. When nil, no duration is specified in such cases.
  1365. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1366. :group 'org-agenda-line-format
  1367. :type '(choice
  1368. (integer :tag "Minutes")
  1369. (const :tag "No default duration")))
  1370. (defcustom org-agenda-show-inherited-tags t
  1371. "Non-nil means show inherited tags in each agenda line."
  1372. :group 'org-agenda-line-format
  1373. :type 'boolean)
  1374. (defcustom org-agenda-hide-tags-regexp nil
  1375. "Regular expression used to filter away specific tags in agenda views.
  1376. This means that these tags will be present, but not be shown in the agenda
  1377. line. Secondary filtering will still work on the hidden tags.
  1378. Nil means don't hide any tags."
  1379. :group 'org-agenda-line-format
  1380. :type '(choice
  1381. (const :tag "Hide none" nil)
  1382. (string :tag "Regexp ")))
  1383. (defcustom org-agenda-remove-tags nil
  1384. "Non-nil means remove the tags from the headline copy in the agenda.
  1385. When this is the symbol `prefix', only remove tags when
  1386. `org-agenda-prefix-format' contains a `%T' specifier."
  1387. :group 'org-agenda-line-format
  1388. :type '(choice
  1389. (const :tag "Always" t)
  1390. (const :tag "Never" nil)
  1391. (const :tag "When prefix format contains %T" prefix)))
  1392. (if (fboundp 'defvaralias)
  1393. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1394. 'org-agenda-remove-tags))
  1395. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1396. "Shift tags in agenda items to this column.
  1397. If this number is positive, it specifies the column. If it is negative,
  1398. it means that the tags should be flushright to that column. For example,
  1399. -80 works well for a normal 80 character screen."
  1400. :group 'org-agenda-line-format
  1401. :type 'integer)
  1402. (if (fboundp 'defvaralias)
  1403. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1404. (defcustom org-agenda-fontify-priorities 'cookies
  1405. "Non-nil means highlight low and high priorities in agenda.
  1406. When t, the highest priority entries are bold, lowest priority italic.
  1407. However, settings in `org-priority-faces' will overrule these faces.
  1408. When this variable is the symbol `cookies', only fontify the
  1409. cookies, not the entire task.
  1410. This may also be an association list of priority faces, whose
  1411. keys are the character values of `org-highest-priority',
  1412. `org-default-priority', and `org-lowest-priority' (the default values
  1413. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1414. color as a string, or a list like `(:background \"Red\")'.
  1415. If it is a color, the variable `org-faces-easy-properties'
  1416. determines if it is a foreground or a background color."
  1417. :group 'org-agenda-line-format
  1418. :type '(choice
  1419. (const :tag "Never" nil)
  1420. (const :tag "Defaults" t)
  1421. (const :tag "Cookies only" cookies)
  1422. (repeat :tag "Specify"
  1423. (list (character :tag "Priority" :value ?A)
  1424. (choice :tag "Face "
  1425. (string :tag "Color")
  1426. (sexp :tag "Face"))))))
  1427. (defcustom org-agenda-day-face-function nil
  1428. "Function called to determine what face should be used to display a day.
  1429. The only argument passed to that function is the day. It should
  1430. returns a face, or nil if does not want to specify a face and let
  1431. the normal rules apply."
  1432. :group 'org-agenda-line-format
  1433. :type 'function)
  1434. (defcustom org-agenda-category-icon-alist nil
  1435. "Alist of category icon to be displayed in agenda views.
  1436. Each entry should have the following format:
  1437. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1438. Where CATEGORY-REGEXP is a regexp matching the categories where
  1439. the icon should be displayed.
  1440. FILE-OR-DATA either a file path or a string containing image data.
  1441. The other fields can be omited safely if not needed:
  1442. TYPE indicates the image type.
  1443. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1444. image data.
  1445. PROPS are additional image attributes to assign to the image,
  1446. like, e.g. `:ascent center'.
  1447. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1448. If you want to set the display properties yourself, just put a
  1449. list as second element:
  1450. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1451. For example, to display a 16px horizontal space for Emacs
  1452. category, you can use:
  1453. (\"Emacs\" '(space . (:width (16))))"
  1454. :group 'org-agenda-line-format
  1455. :type '(alist :key-type (string :tag "Regexp matching category")
  1456. :value-type (choice (list :tag "Icon"
  1457. (string :tag "File or data")
  1458. (symbol :tag "Type")
  1459. (boolean :tag "Data?")
  1460. (repeat :tag "Extra image properties" :inline t symbol))
  1461. (list :tag "Display properties" sexp))))
  1462. (defgroup org-agenda-column-view nil
  1463. "Options concerning column view in the agenda."
  1464. :tag "Org Agenda Column View"
  1465. :group 'org-agenda)
  1466. (defcustom org-agenda-columns-show-summaries t
  1467. "Non-nil means show summaries for columns displayed in the agenda view."
  1468. :group 'org-agenda-column-view
  1469. :type 'boolean)
  1470. (defcustom org-agenda-columns-compute-summary-properties t
  1471. "Non-nil means recompute all summary properties before column view.
  1472. When column view in the agenda is listing properties that have a summary
  1473. operator, it can go to all relevant buffers and recompute the summaries
  1474. there. This can mean overhead for the agenda column view, but is necessary
  1475. to have thing up to date.
  1476. As a special case, a CLOCKSUM property also makes sure that the clock
  1477. computations are current."
  1478. :group 'org-agenda-column-view
  1479. :type 'boolean)
  1480. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1481. "Non-nil means the duration of an appointment will add to day effort.
  1482. The property to which appointment durations will be added is the one given
  1483. in the option `org-effort-property'. If an appointment does not have
  1484. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1485. is not set, an appointment without end time will not contribute to the time
  1486. estimate."
  1487. :group 'org-agenda-column-view
  1488. :type 'boolean)
  1489. (defcustom org-agenda-auto-exclude-function nil
  1490. "A function called with a tag to decide if it is filtered on '/ RET'.
  1491. The sole argument to the function, which is called once for each
  1492. possible tag, is a string giving the name of the tag. The
  1493. function should return either nil if the tag should be included
  1494. as normal, or \"-<TAG>\" to exclude the tag.
  1495. Note that for the purpose of tag filtering, only the lower-case version of
  1496. all tags will be considered, so that this function will only ever see
  1497. the lower-case version of all tags."
  1498. :group 'org-agenda
  1499. :type 'function)
  1500. (defcustom org-agenda-bulk-custom-functions nil
  1501. "Alist of characters and custom functions for bulk actions.
  1502. For example, this value makes those two functions available:
  1503. '((?R set-category)
  1504. (?C bulk-cut))
  1505. With selected entries in an agenda buffer, `B R' will call
  1506. the custom function `set-category' on the selected entries.
  1507. Note that functions in this alist don't need to be quoted."
  1508. :type 'alist
  1509. :group 'org-agenda)
  1510. (eval-when-compile
  1511. (require 'cl))
  1512. (require 'org)
  1513. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1514. "Execute BODY with point at location given by `org-hd-marker' property.
  1515. If STRING is non-nil, the text property will be fetched from position 0
  1516. in that string. If STRING is nil, it will be fetched from the beginning
  1517. of the current line."
  1518. (org-with-gensyms (marker)
  1519. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1520. 'org-hd-marker string)))
  1521. (with-current-buffer (marker-buffer ,marker)
  1522. (save-excursion
  1523. (goto-char ,marker)
  1524. ,@body)))))
  1525. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1526. (defun org-add-agenda-custom-command (entry)
  1527. "Replace or add a command in `org-agenda-custom-commands'.
  1528. This is mostly for hacking and trying a new command - once the command
  1529. works you probably want to add it to `org-agenda-custom-commands' for good."
  1530. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1531. (if ass
  1532. (setcdr ass (cdr entry))
  1533. (push entry org-agenda-custom-commands))))
  1534. ;;; Define the Org-agenda-mode
  1535. (defvar org-agenda-mode-map (make-sparse-keymap)
  1536. "Keymap for `org-agenda-mode'.")
  1537. (if (fboundp 'defvaralias)
  1538. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1539. (defvar org-agenda-menu) ; defined later in this file.
  1540. (defvar org-agenda-restrict) ; defined later in this file.
  1541. (defvar org-agenda-follow-mode nil)
  1542. (defvar org-agenda-entry-text-mode nil)
  1543. (defvar org-agenda-clockreport-mode nil)
  1544. (defvar org-agenda-show-log nil)
  1545. (defvar org-agenda-redo-command nil)
  1546. (defvar org-agenda-query-string nil)
  1547. (defvar org-agenda-mode-hook nil
  1548. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1549. (defvar org-agenda-type nil)
  1550. (defvar org-agenda-force-single-file nil)
  1551. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1552. (defun org-agenda-mode ()
  1553. "Mode for time-sorted view on action items in Org-mode files.
  1554. The following commands are available:
  1555. \\{org-agenda-mode-map}"
  1556. (interactive)
  1557. (kill-all-local-variables)
  1558. (setq org-agenda-undo-list nil
  1559. org-agenda-pending-undo-list nil
  1560. org-agenda-bulk-marked-entries nil)
  1561. (setq major-mode 'org-agenda-mode)
  1562. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1563. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1564. (setq mode-name "Org-Agenda")
  1565. (use-local-map org-agenda-mode-map)
  1566. (easy-menu-add org-agenda-menu)
  1567. (if org-startup-truncated (setq truncate-lines t))
  1568. (org-set-local 'line-move-visual nil)
  1569. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1570. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1571. ;; Make sure properties are removed when copying text
  1572. (when (boundp 'buffer-substring-filters)
  1573. (org-set-local 'buffer-substring-filters
  1574. (cons (lambda (x)
  1575. (set-text-properties 0 (length x) nil x) x)
  1576. buffer-substring-filters)))
  1577. (unless org-agenda-keep-modes
  1578. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1579. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1580. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1581. org-agenda-show-log org-agenda-start-with-log-mode))
  1582. (easy-menu-change
  1583. '("Agenda") "Agenda Files"
  1584. (append
  1585. (list
  1586. (vector
  1587. (if (get 'org-agenda-files 'org-restrict)
  1588. "Restricted to single file"
  1589. "Edit File List")
  1590. '(org-edit-agenda-file-list)
  1591. (not (get 'org-agenda-files 'org-restrict)))
  1592. "--")
  1593. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1594. (org-agenda-set-mode-name)
  1595. (apply
  1596. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1597. (list 'org-agenda-mode-hook)))
  1598. (substitute-key-definition 'undo 'org-agenda-undo
  1599. org-agenda-mode-map global-map)
  1600. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1601. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1602. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1603. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1604. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1605. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1606. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1607. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1608. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1609. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1610. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1611. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1612. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1613. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1614. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1615. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1616. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1617. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1618. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1619. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1620. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1621. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1622. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1623. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1624. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1625. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1626. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1627. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1628. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1629. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1630. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1631. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1632. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1633. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1634. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1635. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1636. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1637. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1638. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1639. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1640. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1641. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1642. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1643. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1644. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1645. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1646. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1647. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1648. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1649. (while l (org-defkey org-agenda-mode-map
  1650. (int-to-string (pop l)) 'digit-argument)))
  1651. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1652. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1653. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1654. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1655. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1656. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1657. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1658. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1659. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1660. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1661. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1662. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1663. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1664. 'org-clock-modify-effort-estimate)
  1665. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1666. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1667. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1668. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1669. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1670. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1671. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1672. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1673. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1674. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1675. (substitute-key-definition 'next-line 'org-agenda-next-line
  1676. org-agenda-mode-map global-map)
  1677. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1678. org-agenda-mode-map global-map)
  1679. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1680. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1681. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1682. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1683. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1684. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1685. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1686. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1687. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1688. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1689. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1690. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1691. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1692. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1693. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1694. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1695. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1696. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1697. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1698. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1699. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1700. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1701. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1702. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1703. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1704. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1705. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1706. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1707. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1708. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1709. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1710. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1711. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1712. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1713. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1714. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1715. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1716. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1717. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1718. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1719. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1720. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1721. (when org-agenda-mouse-1-follows-link
  1722. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1723. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1724. '("Agenda"
  1725. ("Agenda Files")
  1726. "--"
  1727. ("Agenda Dates"
  1728. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1729. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1730. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1731. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1732. "--"
  1733. ("View"
  1734. ["Day View" org-agenda-day-view
  1735. :active (org-agenda-check-type nil 'agenda)
  1736. :style radio :selected (eq org-agenda-current-span 'day)
  1737. :keys "v d (or just d)"]
  1738. ["Week View" org-agenda-week-view
  1739. :active (org-agenda-check-type nil 'agenda)
  1740. :style radio :selected (eq org-agenda-current-span 'week)
  1741. :keys "v w (or just w)"]
  1742. ["Month View" org-agenda-month-view
  1743. :active (org-agenda-check-type nil 'agenda)
  1744. :style radio :selected (eq org-agenda-current-span 'month)
  1745. :keys "v m"]
  1746. ["Year View" org-agenda-year-view
  1747. :active (org-agenda-check-type nil 'agenda)
  1748. :style radio :selected (eq org-agenda-current-span 'year)
  1749. :keys "v y"]
  1750. "--"
  1751. ["Include Diary" org-agenda-toggle-diary
  1752. :style toggle :selected org-agenda-include-diary
  1753. :active (org-agenda-check-type nil 'agenda)]
  1754. ["Include Deadlines" org-agenda-toggle-deadlines
  1755. :style toggle :selected org-agenda-include-deadlines
  1756. :active (org-agenda-check-type nil 'agenda)]
  1757. ["Use Time Grid" org-agenda-toggle-time-grid
  1758. :style toggle :selected org-agenda-use-time-grid
  1759. :active (org-agenda-check-type nil 'agenda)]
  1760. "--"
  1761. ["Show clock report" org-agenda-clockreport-mode
  1762. :style toggle :selected org-agenda-clockreport-mode
  1763. :active (org-agenda-check-type nil 'agenda)]
  1764. ["Show some entry text" org-agenda-entry-text-mode
  1765. :style toggle :selected org-agenda-entry-text-mode
  1766. :active t]
  1767. "--"
  1768. ["Show Logbook entries" org-agenda-log-mode
  1769. :style toggle :selected org-agenda-show-log
  1770. :active (org-agenda-check-type nil 'agenda 'timeline)
  1771. :keys "v l (or just l)"]
  1772. ["Include archived trees" org-agenda-archives-mode
  1773. :style toggle :selected org-agenda-archives-mode :active t
  1774. :keys "v a"]
  1775. ["Include archive files" (org-agenda-archives-mode t)
  1776. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1777. :keys "v A"]
  1778. "--"
  1779. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1780. ["Write view to file" org-write-agenda t]
  1781. ["Rebuild buffer" org-agenda-redo t]
  1782. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1783. "--"
  1784. ["Show original entry" org-agenda-show t]
  1785. ["Go To (other window)" org-agenda-goto t]
  1786. ["Go To (this window)" org-agenda-switch-to t]
  1787. ["Follow Mode" org-agenda-follow-mode
  1788. :style toggle :selected org-agenda-follow-mode :active t]
  1789. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1790. "--"
  1791. ("TODO"
  1792. ["Cycle TODO" org-agenda-todo t]
  1793. ["Next TODO set" org-agenda-todo-nextset t]
  1794. ["Previous TODO set" org-agenda-todo-previousset t]
  1795. ["Add note" org-agenda-add-note t])
  1796. ("Archive/Refile/Delete"
  1797. ["Archive default" org-agenda-archive-default t]
  1798. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1799. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1800. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1801. ["Archive subtree" org-agenda-archive t]
  1802. "--"
  1803. ["Refile" org-agenda-refile t]
  1804. "--"
  1805. ["Delete subtree" org-agenda-kill t])
  1806. ("Bulk action"
  1807. ["Mark entry" org-agenda-bulk-mark t]
  1808. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1809. ["Unmark entry" org-agenda-bulk-unmark t]
  1810. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1811. ["Act on all marked" org-agenda-bulk-action t]
  1812. "--"
  1813. ("Tags and Properties"
  1814. ["Show all Tags" org-agenda-show-tags t]
  1815. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1816. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1817. "--"
  1818. ["Column View" org-columns t])
  1819. ("Deadline/Schedule"
  1820. ["Schedule" org-agenda-schedule t]
  1821. ["Set Deadline" org-agenda-deadline t]
  1822. "--"
  1823. ["Mark item" org-agenda-action :active t :keys "k m"]
  1824. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1825. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1826. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1827. "--"
  1828. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1829. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1830. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1831. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1832. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1833. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1834. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1835. ("Clock and Effort"
  1836. ["Clock in" org-agenda-clock-in t]
  1837. ["Clock out" org-agenda-clock-out t]
  1838. ["Clock cancel" org-agenda-clock-cancel t]
  1839. ["Goto running clock" org-clock-goto t]
  1840. "--"
  1841. ["Set Effort" org-agenda-set-effort t]
  1842. ["Change clocked effort" org-clock-modify-effort-estimate
  1843. (org-clock-is-active)])
  1844. ("Priority"
  1845. ["Set Priority" org-agenda-priority t]
  1846. ["Increase Priority" org-agenda-priority-up t]
  1847. ["Decrease Priority" org-agenda-priority-down t]
  1848. ["Show Priority" org-agenda-show-priority t])
  1849. ("Calendar/Diary"
  1850. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1851. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1852. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1853. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1854. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1855. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1856. "--"
  1857. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1858. "--"
  1859. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1860. "--"
  1861. ("MobileOrg"
  1862. ["Push Files and Views" org-mobile-push t]
  1863. ["Get Captured and Flagged" org-mobile-pull t]
  1864. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1865. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1866. "--"
  1867. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1868. "--"
  1869. ["Quit" org-agenda-quit t]
  1870. ["Exit and Release Buffers" org-agenda-exit t]
  1871. ))
  1872. ;;; Agenda undo
  1873. (defvar org-agenda-allow-remote-undo t
  1874. "Non-nil means allow remote undo from the agenda buffer.")
  1875. (defvar org-agenda-undo-list nil
  1876. "List of undoable operations in the agenda since last refresh.")
  1877. (defvar org-agenda-undo-has-started-in nil
  1878. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1879. (defvar org-agenda-pending-undo-list nil
  1880. "In a series of undo commands, this is the list of remaining undo items.")
  1881. (defun org-agenda-undo ()
  1882. "Undo a remote editing step in the agenda.
  1883. This undoes changes both in the agenda buffer and in the remote buffer
  1884. that have been changed along."
  1885. (interactive)
  1886. (or org-agenda-allow-remote-undo
  1887. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1888. (if (not (eq this-command last-command))
  1889. (setq org-agenda-undo-has-started-in nil
  1890. org-agenda-pending-undo-list org-agenda-undo-list))
  1891. (if (not org-agenda-pending-undo-list)
  1892. (error "No further undo information"))
  1893. (let* ((entry (pop org-agenda-pending-undo-list))
  1894. buf line cmd rembuf)
  1895. (setq cmd (pop entry) line (pop entry))
  1896. (setq rembuf (nth 2 entry))
  1897. (org-with-remote-undo rembuf
  1898. (while (bufferp (setq buf (pop entry)))
  1899. (if (pop entry)
  1900. (with-current-buffer buf
  1901. (let ((last-undo-buffer buf)
  1902. (inhibit-read-only t))
  1903. (unless (memq buf org-agenda-undo-has-started-in)
  1904. (push buf org-agenda-undo-has-started-in)
  1905. (make-local-variable 'pending-undo-list)
  1906. (undo-start))
  1907. (while (and pending-undo-list
  1908. (listp pending-undo-list)
  1909. (not (car pending-undo-list)))
  1910. (pop pending-undo-list))
  1911. (undo-more 1))))))
  1912. (org-goto-line line)
  1913. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1914. (defun org-verify-change-for-undo (l1 l2)
  1915. "Verify that a real change occurred between the undo lists L1 and L2."
  1916. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1917. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1918. (not (eq l1 l2)))
  1919. ;;; Agenda dispatch
  1920. (defvar org-agenda-restrict nil)
  1921. (defvar org-agenda-restrict-begin (make-marker))
  1922. (defvar org-agenda-restrict-end (make-marker))
  1923. (defvar org-agenda-last-dispatch-buffer nil)
  1924. (defvar org-agenda-overriding-restriction nil)
  1925. ;;;###autoload
  1926. (defun org-agenda (&optional arg keys restriction)
  1927. "Dispatch agenda commands to collect entries to the agenda buffer.
  1928. Prompts for a command to execute. Any prefix arg will be passed
  1929. on to the selected command. The default selections are:
  1930. a Call `org-agenda-list' to display the agenda for current day or week.
  1931. t Call `org-todo-list' to display the global todo list.
  1932. T Call `org-todo-list' to display the global todo list, select only
  1933. entries with a specific TODO keyword (the user gets a prompt).
  1934. m Call `org-tags-view' to display headlines with tags matching
  1935. a condition (the user is prompted for the condition).
  1936. M Like `m', but select only TODO entries, no ordinary headlines.
  1937. L Create a timeline for the current buffer.
  1938. e Export views to associated files.
  1939. s Search entries for keywords.
  1940. / Multi occur across all agenda files and also files listed
  1941. in `org-agenda-text-search-extra-files'.
  1942. < Restrict agenda commands to buffer, subtree, or region.
  1943. Press several times to get the desired effect.
  1944. > Remove a previous restriction.
  1945. # List \"stuck\" projects.
  1946. ! Configure what \"stuck\" means.
  1947. C Configure custom agenda commands.
  1948. More commands can be added by configuring the variable
  1949. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1950. searches can be pre-defined in this way.
  1951. If the current buffer is in Org-mode and visiting a file, you can also
  1952. first press `<' once to indicate that the agenda should be temporarily
  1953. \(until the next use of \\[org-agenda]) restricted to the current file.
  1954. Pressing `<' twice means to restrict to the current subtree or region
  1955. \(if active)."
  1956. (interactive "P")
  1957. (catch 'exit
  1958. (let* ((prefix-descriptions nil)
  1959. (org-agenda-window-setup (if (equal (buffer-name)
  1960. org-agenda-buffer-name)
  1961. 'current-window
  1962. org-agenda-window-setup))
  1963. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1964. (org-agenda-custom-commands
  1965. ;; normalize different versions
  1966. (delq nil
  1967. (mapcar
  1968. (lambda (x)
  1969. (cond ((stringp (cdr x))
  1970. (push x prefix-descriptions)
  1971. nil)
  1972. ((stringp (nth 1 x)) x)
  1973. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1974. (t (cons (car x) (cons "" (cdr x))))))
  1975. org-agenda-custom-commands)))
  1976. (buf (current-buffer))
  1977. (bfn (buffer-file-name (buffer-base-buffer)))
  1978. entry key type match lprops ans)
  1979. ;; Turn off restriction unless there is an overriding one,
  1980. (unless org-agenda-overriding-restriction
  1981. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1982. ;; There is a request to keep the file list in place
  1983. (put 'org-agenda-files 'org-restrict nil))
  1984. (setq org-agenda-restrict nil)
  1985. (move-marker org-agenda-restrict-begin nil)
  1986. (move-marker org-agenda-restrict-end nil))
  1987. ;; Delete old local properties
  1988. (put 'org-agenda-redo-command 'org-lprops nil)
  1989. ;; Delete previously set last-arguments
  1990. (put 'org-agenda-redo-command 'last-args nil)
  1991. ;; Remember where this call originated
  1992. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1993. (unless keys
  1994. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1995. keys (car ans)
  1996. restriction (cdr ans)))
  1997. ;; Establish the restriction, if any
  1998. (when (and (not org-agenda-overriding-restriction) restriction)
  1999. (put 'org-agenda-files 'org-restrict (list bfn))
  2000. (cond
  2001. ((eq restriction 'region)
  2002. (setq org-agenda-restrict t)
  2003. (move-marker org-agenda-restrict-begin (region-beginning))
  2004. (move-marker org-agenda-restrict-end (region-end)))
  2005. ((eq restriction 'subtree)
  2006. (save-excursion
  2007. (setq org-agenda-restrict t)
  2008. (org-back-to-heading t)
  2009. (move-marker org-agenda-restrict-begin (point))
  2010. (move-marker org-agenda-restrict-end
  2011. (progn (org-end-of-subtree t)))))))
  2012. ;; For example the todo list should not need it (but does...)
  2013. (cond
  2014. ((setq entry (assoc keys org-agenda-custom-commands))
  2015. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2016. (progn
  2017. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2018. lprops (nth 4 entry))
  2019. (put 'org-agenda-redo-command 'org-lprops lprops)
  2020. (cond
  2021. ((eq type 'agenda)
  2022. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2023. ((eq type 'alltodo)
  2024. (org-let lprops '(org-todo-list current-prefix-arg)))
  2025. ((eq type 'search)
  2026. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2027. ((eq type 'stuck)
  2028. (org-let lprops '(org-agenda-list-stuck-projects
  2029. current-prefix-arg)))
  2030. ((eq type 'tags)
  2031. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2032. ((eq type 'tags-todo)
  2033. (org-let lprops '(org-tags-view '(4) match)))
  2034. ((eq type 'todo)
  2035. (org-let lprops '(org-todo-list match)))
  2036. ((eq type 'tags-tree)
  2037. (org-check-for-org-mode)
  2038. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2039. ((eq type 'todo-tree)
  2040. (org-check-for-org-mode)
  2041. (org-let lprops
  2042. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2043. (regexp-quote match) "\\>"))))
  2044. ((eq type 'occur-tree)
  2045. (org-check-for-org-mode)
  2046. (org-let lprops '(org-occur match)))
  2047. ((functionp type)
  2048. (org-let lprops '(funcall type match)))
  2049. ((fboundp type)
  2050. (org-let lprops '(funcall type match)))
  2051. (t (error "Invalid custom agenda command type %s" type))))
  2052. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2053. ((equal keys "C")
  2054. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2055. (customize-variable 'org-agenda-custom-commands))
  2056. ((equal keys "a") (call-interactively 'org-agenda-list))
  2057. ((equal keys "s") (call-interactively 'org-search-view))
  2058. ((equal keys "t") (call-interactively 'org-todo-list))
  2059. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2060. ((equal keys "m") (call-interactively 'org-tags-view))
  2061. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2062. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2063. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2064. (org-add-hook
  2065. 'post-command-hook
  2066. (lambda ()
  2067. (unless (current-message)
  2068. (let* ((m (org-agenda-get-any-marker))
  2069. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2070. (when note
  2071. (message (concat
  2072. "FLAGGING-NOTE ([?] for more info): "
  2073. (org-add-props
  2074. (replace-regexp-in-string
  2075. "\\\\n" "//"
  2076. (copy-sequence note))
  2077. nil 'face 'org-warning)))))))
  2078. t t))
  2079. ((equal keys "L")
  2080. (unless (org-mode-p)
  2081. (error "This is not an Org-mode file"))
  2082. (unless restriction
  2083. (put 'org-agenda-files 'org-restrict (list bfn))
  2084. (org-call-with-arg 'org-timeline arg)))
  2085. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2086. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2087. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2088. (t (error "Invalid agenda key"))))))
  2089. (defun org-agenda-append-agenda ()
  2090. "Append another agenda view to the current one.
  2091. This function allows interactive building of block agendas.
  2092. Agenda views are separated by `org-agenda-block-separator'."
  2093. (interactive)
  2094. (unless (string= (buffer-name) org-agenda-buffer-name)
  2095. (error "Can only append from within agenda buffer"))
  2096. (let ((org-agenda-multi t))
  2097. (org-agenda)
  2098. (widen)))
  2099. (defun org-agenda-normalize-custom-commands (cmds)
  2100. (delq nil
  2101. (mapcar
  2102. (lambda (x)
  2103. (cond ((stringp (cdr x)) nil)
  2104. ((stringp (nth 1 x)) x)
  2105. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2106. (t (cons (car x) (cons "" (cdr x))))))
  2107. cmds)))
  2108. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2109. "The user interface for selecting an agenda command."
  2110. (catch 'exit
  2111. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2112. (restrict-ok (and bfn (org-mode-p)))
  2113. (region-p (org-region-active-p))
  2114. (custom org-agenda-custom-commands)
  2115. (selstring "")
  2116. restriction second-time
  2117. c entry key type match prefixes rmheader header-end custom1 desc
  2118. line lines left right n n1)
  2119. (save-window-excursion
  2120. (delete-other-windows)
  2121. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2122. (erase-buffer)
  2123. (insert (eval-when-compile
  2124. (let ((header
  2125. "
  2126. Press key for an agenda command: < Buffer, subtree/region restriction
  2127. -------------------------------- > Remove restriction
  2128. a Agenda for current week or day e Export agenda views
  2129. t List of all TODO entries T Entries with special TODO kwd
  2130. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2131. L Timeline for current buffer # List stuck projects (!=configure)
  2132. s Search for keywords C Configure custom agenda commands
  2133. / Multi-occur ? Find :FLAGGED: entries
  2134. ")
  2135. (start 0))
  2136. (while (string-match
  2137. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2138. header start)
  2139. (setq start (match-end 0))
  2140. (add-text-properties (match-beginning 2) (match-end 2)
  2141. '(face bold) header))
  2142. header)))
  2143. (setq header-end (move-marker (make-marker) (point)))
  2144. (while t
  2145. (setq custom1 custom)
  2146. (when (eq rmheader t)
  2147. (org-goto-line 1)
  2148. (re-search-forward ":" nil t)
  2149. (delete-region (match-end 0) (point-at-eol))
  2150. (forward-char 1)
  2151. (looking-at "-+")
  2152. (delete-region (match-end 0) (point-at-eol))
  2153. (move-marker header-end (match-end 0)))
  2154. (goto-char header-end)
  2155. (delete-region (point) (point-max))
  2156. ;; Produce all the lines that describe custom commands and prefixes
  2157. (setq lines nil)
  2158. (while (setq entry (pop custom1))
  2159. (setq key (car entry) desc (nth 1 entry)
  2160. type (nth 2 entry)
  2161. match (nth 3 entry))
  2162. (if (> (length key) 1)
  2163. (add-to-list 'prefixes (string-to-char key))
  2164. (setq line
  2165. (format
  2166. "%-4s%-14s"
  2167. (org-add-props (copy-sequence key)
  2168. '(face bold))
  2169. (cond
  2170. ((string-match "\\S-" desc) desc)
  2171. ((eq type 'agenda) "Agenda for current week or day")
  2172. ((eq type 'alltodo) "List of all TODO entries")
  2173. ((eq type 'search) "Word search")
  2174. ((eq type 'stuck) "List of stuck projects")
  2175. ((eq type 'todo) "TODO keyword")
  2176. ((eq type 'tags) "Tags query")
  2177. ((eq type 'tags-todo) "Tags (TODO)")
  2178. ((eq type 'tags-tree) "Tags tree")
  2179. ((eq type 'todo-tree) "TODO kwd tree")
  2180. ((eq type 'occur-tree) "Occur tree")
  2181. ((functionp type) (if (symbolp type)
  2182. (symbol-name type)
  2183. "Lambda expression"))
  2184. (t "???"))))
  2185. (if org-agenda-menu-show-matcher
  2186. (setq line
  2187. (concat line ": "
  2188. (cond
  2189. ((stringp match)
  2190. (setq match (copy-sequence match))
  2191. (org-add-props match nil 'face 'org-warning))
  2192. (match
  2193. (format "set of %d commands" (length match)))
  2194. (t ""))))
  2195. (if (org-string-nw-p match)
  2196. (add-text-properties
  2197. 0 (length line) (list 'help-echo
  2198. (concat "Matcher: "match)) line)))
  2199. (push line lines)))
  2200. (setq lines (nreverse lines))
  2201. (when prefixes
  2202. (mapc (lambda (x)
  2203. (push
  2204. (format "%s %s"
  2205. (org-add-props (char-to-string x)
  2206. nil 'face 'bold)
  2207. (or (cdr (assoc (concat selstring
  2208. (char-to-string x))
  2209. prefix-descriptions))
  2210. "Prefix key"))
  2211. lines))
  2212. prefixes))
  2213. ;; Check if we should display in two columns
  2214. (if org-agenda-menu-two-column
  2215. (progn
  2216. (setq n (length lines)
  2217. n1 (+ (/ n 2) (mod n 2))
  2218. right (nthcdr n1 lines)
  2219. left (copy-sequence lines))
  2220. (setcdr (nthcdr (1- n1) left) nil))
  2221. (setq left lines right nil))
  2222. (while left
  2223. (insert "\n" (pop left))
  2224. (when right
  2225. (if (< (current-column) 40)
  2226. (move-to-column 40 t)
  2227. (insert " "))
  2228. (insert (pop right))))
  2229. ;; Make the window the right size
  2230. (goto-char (point-min))
  2231. (if second-time
  2232. (if (not (pos-visible-in-window-p (point-max)))
  2233. (org-fit-window-to-buffer))
  2234. (setq second-time t)
  2235. (org-fit-window-to-buffer))
  2236. ;; Ask for selection
  2237. (message "Press key for agenda command%s:"
  2238. (if (or restrict-ok org-agenda-overriding-restriction)
  2239. (if org-agenda-overriding-restriction
  2240. " (restriction lock active)"
  2241. (if restriction
  2242. (format " (restricted to %s)" restriction)
  2243. " (unrestricted)"))
  2244. ""))
  2245. (setq c (read-char-exclusive))
  2246. (message "")
  2247. (cond
  2248. ((assoc (char-to-string c) custom)
  2249. (setq selstring (concat selstring (char-to-string c)))
  2250. (throw 'exit (cons selstring restriction)))
  2251. ((memq c prefixes)
  2252. (setq selstring (concat selstring (char-to-string c))
  2253. prefixes nil
  2254. rmheader (or rmheader t)
  2255. custom (delq nil (mapcar
  2256. (lambda (x)
  2257. (if (or (= (length (car x)) 1)
  2258. (/= (string-to-char (car x)) c))
  2259. nil
  2260. (cons (substring (car x) 1) (cdr x))))
  2261. custom))))
  2262. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2263. (message "Restriction is only possible in Org-mode buffers")
  2264. (ding) (sit-for 1))
  2265. ((eq c ?1)
  2266. (org-agenda-remove-restriction-lock 'noupdate)
  2267. (setq restriction 'buffer))
  2268. ((eq c ?0)
  2269. (org-agenda-remove-restriction-lock 'noupdate)
  2270. (setq restriction (if region-p 'region 'subtree)))
  2271. ((eq c ?<)
  2272. (org-agenda-remove-restriction-lock 'noupdate)
  2273. (setq restriction
  2274. (cond
  2275. ((eq restriction 'buffer)
  2276. (if region-p 'region 'subtree))
  2277. ((memq restriction '(subtree region))
  2278. nil)
  2279. (t 'buffer))))
  2280. ((eq c ?>)
  2281. (org-agenda-remove-restriction-lock 'noupdate)
  2282. (setq restriction nil))
  2283. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2284. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2285. ((and (> (length selstring) 0) (eq c ?\d))
  2286. (delete-window)
  2287. (org-agenda-get-restriction-and-command prefix-descriptions))
  2288. ((equal c ?q) (error "Abort"))
  2289. (t (error "Invalid key %c" c))))))))
  2290. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2291. (defvar org-agenda-last-arguments nil
  2292. "The arguments of the previous call to `org-agenda'.")
  2293. (defun org-agenda-run-series (name series)
  2294. (org-let (nth 1 series) '(org-prepare-agenda name))
  2295. (let* ((org-agenda-multi t)
  2296. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2297. (org-agenda-overriding-arguments
  2298. (or org-agenda-overriding-arguments
  2299. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2300. (get 'org-agenda-redo-command 'last-args))))
  2301. (cmds (car series))
  2302. (gprops (nth 1 series))
  2303. match ;; The byte compiler incorrectly complains about this. Keep it!
  2304. cmd type lprops)
  2305. (while (setq cmd (pop cmds))
  2306. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2307. (cond
  2308. ((eq type 'agenda)
  2309. (org-let2 gprops lprops
  2310. '(call-interactively 'org-agenda-list)))
  2311. ((eq type 'alltodo)
  2312. (org-let2 gprops lprops
  2313. '(call-interactively 'org-todo-list)))
  2314. ((eq type 'search)
  2315. (org-let2 gprops lprops
  2316. '(org-search-view current-prefix-arg match nil)))
  2317. ((eq type 'stuck)
  2318. (org-let2 gprops lprops
  2319. '(call-interactively 'org-agenda-list-stuck-projects)))
  2320. ((eq type 'tags)
  2321. (org-let2 gprops lprops
  2322. '(org-tags-view current-prefix-arg match)))
  2323. ((eq type 'tags-todo)
  2324. (org-let2 gprops lprops
  2325. '(org-tags-view '(4) match)))
  2326. ((eq type 'todo)
  2327. (org-let2 gprops lprops
  2328. '(org-todo-list match)))
  2329. ((fboundp type)
  2330. (org-let2 gprops lprops
  2331. '(funcall type match)))
  2332. (t (error "Invalid type in command series"))))
  2333. (widen)
  2334. (setq org-agenda-redo-command redo)
  2335. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2336. (goto-char (point-min)))
  2337. (org-fit-agenda-window)
  2338. (org-let (nth 1 series) '(org-finalize-agenda)))
  2339. ;;;###autoload
  2340. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2341. "Run an agenda command in batch mode and send the result to STDOUT.
  2342. If CMD-KEY is a string of length 1, it is used as a key in
  2343. `org-agenda-custom-commands' and triggers this command. If it is a
  2344. longer string it is used as a tags/todo match string.
  2345. Parameters are alternating variable names and values that will be bound
  2346. before running the agenda command."
  2347. (org-eval-in-environment (org-make-parameter-alist parameters)
  2348. (if (> (length cmd-key) 2)
  2349. (org-tags-view nil cmd-key)
  2350. (org-agenda nil cmd-key)))
  2351. (set-buffer org-agenda-buffer-name)
  2352. (princ (org-encode-for-stdout (buffer-string))))
  2353. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2354. ;(defun org-encode-for-stdout (string)
  2355. ; (if (fboundp 'encode-coding-string)
  2356. ; (encode-coding-string string buffer-file-coding-system)
  2357. ; string))
  2358. (defun org-encode-for-stdout (string)
  2359. string)
  2360. (defvar org-agenda-info nil)
  2361. ;;;###autoload
  2362. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2363. "Run an agenda command in batch mode and send the result to STDOUT.
  2364. If CMD-KEY is a string of length 1, it is used as a key in
  2365. `org-agenda-custom-commands' and triggers this command. If it is a
  2366. longer string it is used as a tags/todo match string.
  2367. Parameters are alternating variable names and values that will be bound
  2368. before running the agenda command.
  2369. The output gives a line for each selected agenda item. Each
  2370. item is a list of comma-separated values, like this:
  2371. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2372. category The category of the item
  2373. head The headline, without TODO kwd, TAGS and PRIORITY
  2374. type The type of the agenda entry, can be
  2375. todo selected in TODO match
  2376. tagsmatch selected in tags match
  2377. diary imported from diary
  2378. deadline a deadline on given date
  2379. scheduled scheduled on given date
  2380. timestamp entry has timestamp on given date
  2381. closed entry was closed on given date
  2382. upcoming-deadline warning about deadline
  2383. past-scheduled forwarded scheduled item
  2384. block entry has date block including g. date
  2385. todo The todo keyword, if any
  2386. tags All tags including inherited ones, separated by colons
  2387. date The relevant date, like 2007-2-14
  2388. time The time, like 15:00-16:50
  2389. extra Sting with extra planning info
  2390. priority-l The priority letter if any was given
  2391. priority-n The computed numerical priority
  2392. agenda-day The day in the agenda where this is listed"
  2393. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2394. (org-make-parameter-alist parameters))
  2395. (if (> (length cmd-key) 2)
  2396. (org-tags-view nil cmd-key)
  2397. (org-agenda nil cmd-key)))
  2398. (set-buffer org-agenda-buffer-name)
  2399. (let* ((lines (org-split-string (buffer-string) "\n"))
  2400. line)
  2401. (while (setq line (pop lines))
  2402. (catch 'next
  2403. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2404. (setq org-agenda-info
  2405. (org-fix-agenda-info (text-properties-at 0 line)))
  2406. (princ
  2407. (org-encode-for-stdout
  2408. (mapconcat 'org-agenda-export-csv-mapper
  2409. '(org-category txt type todo tags date time extra
  2410. priority-letter priority agenda-day)
  2411. ",")))
  2412. (princ "\n")))))
  2413. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2414. (defun org-fix-agenda-info (props)
  2415. "Make sure all properties on an agenda item have a canonical form.
  2416. This ensures the export commands can easily use it."
  2417. (let (tmp re)
  2418. (when (setq tmp (plist-get props 'tags))
  2419. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2420. (when (setq tmp (plist-get props 'date))
  2421. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2422. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2423. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2424. (setq tmp (calendar-date-string tmp)))
  2425. (setq props (plist-put props 'date tmp)))
  2426. (when (setq tmp (plist-get props 'day))
  2427. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2428. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2429. (setq tmp (calendar-date-string tmp)))
  2430. (setq props (plist-put props 'day tmp))
  2431. (setq props (plist-put props 'agenda-day tmp)))
  2432. (when (setq tmp (plist-get props 'txt))
  2433. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2434. (plist-put props 'priority-letter (match-string 1 tmp))
  2435. (setq tmp (replace-match "" t t tmp)))
  2436. (when (and (setq re (plist-get props 'org-todo-regexp))
  2437. (setq re (concat "\\`\\.*" re " ?"))
  2438. (string-match re tmp))
  2439. (plist-put props 'todo (match-string 1 tmp))
  2440. (setq tmp (replace-match "" t t tmp)))
  2441. (plist-put props 'txt tmp)))
  2442. props)
  2443. (defun org-agenda-export-csv-mapper (prop)
  2444. (let ((res (plist-get org-agenda-info prop)))
  2445. (setq res
  2446. (cond
  2447. ((not res) "")
  2448. ((stringp res) res)
  2449. (t (prin1-to-string res))))
  2450. (while (string-match "," res)
  2451. (setq res (replace-match ";" t t res)))
  2452. (org-trim res)))
  2453. ;;;###autoload
  2454. (defun org-store-agenda-views (&rest parameters)
  2455. (interactive)
  2456. (eval (list 'org-batch-store-agenda-views)))
  2457. ;;;###autoload
  2458. (defmacro org-batch-store-agenda-views (&rest parameters)
  2459. "Run all custom agenda commands that have a file argument."
  2460. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2461. (pop-up-frames nil)
  2462. (dir default-directory)
  2463. (pars (org-make-parameter-alist parameters))
  2464. cmd thiscmdkey files opts cmd-or-set)
  2465. (save-window-excursion
  2466. (while cmds
  2467. (setq cmd (pop cmds)
  2468. thiscmdkey (car cmd)
  2469. cmd-or-set (nth 2 cmd)
  2470. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2471. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2472. (if (stringp files) (setq files (list files)))
  2473. (when files
  2474. (org-eval-in-environment (append org-agenda-exporter-settings
  2475. opts pars)
  2476. (org-agenda nil thiscmdkey))
  2477. (set-buffer org-agenda-buffer-name)
  2478. (while files
  2479. (org-eval-in-environment (append org-agenda-exporter-settings
  2480. opts pars)
  2481. (org-write-agenda (expand-file-name (pop files) dir) nil t)))
  2482. (and (get-buffer org-agenda-buffer-name)
  2483. (kill-buffer org-agenda-buffer-name)))))))
  2484. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2485. (defun org-agenda-mark-header-line (pos)
  2486. "Mark the line at POS as an agenda structure header."
  2487. (save-excursion
  2488. (goto-char pos)
  2489. (put-text-property (point-at-bol) (point-at-eol)
  2490. 'org-agenda-structural-header t)
  2491. (when org-agenda-title-append
  2492. (put-text-property (point-at-bol) (point-at-eol)
  2493. 'org-agenda-title-append org-agenda-title-append))))
  2494. (defvar org-mobile-creating-agendas)
  2495. (defun org-write-agenda (file &optional open nosettings)
  2496. "Write the current buffer (an agenda view) as a file.
  2497. Depending on the extension of the file name, plain text (.txt),
  2498. HTML (.html or .htm) or Postscript (.ps) is produced.
  2499. If the extension is .ics, run icalendar export over all files used
  2500. to construct the agenda and limit the export to entries listed in the
  2501. agenda now.
  2502. With prefix argument OPEN, open the new file immediately.
  2503. If NOSETTINGS is given, do not scope the settings of
  2504. `org-agenda-exporter-settings' into the export commands. This is used when
  2505. the settings have already been scoped and we do not wish to overrule other,
  2506. higher priority settings."
  2507. (interactive "FWrite agenda to file: \nP")
  2508. (if (not (file-writable-p file))
  2509. (error "Cannot write agenda to file %s" file))
  2510. (org-let (if nosettings nil org-agenda-exporter-settings)
  2511. '(save-excursion
  2512. (save-window-excursion
  2513. (org-agenda-mark-filtered-text)
  2514. (let ((bs (copy-sequence (buffer-string))) beg)
  2515. (org-agenda-unmark-filtered-text)
  2516. (with-temp-buffer
  2517. (rename-buffer "Agenda View" t)
  2518. (set-buffer-modified-p nil)
  2519. (insert bs)
  2520. (org-agenda-remove-marked-text 'org-filtered)
  2521. (while (setq beg (text-property-any (point-min) (point-max)
  2522. 'org-filtered t))
  2523. (delete-region
  2524. beg (or (next-single-property-change beg 'org-filtered)
  2525. (point-max))))
  2526. (run-hooks 'org-agenda-before-write-hook)
  2527. (cond
  2528. ((org-bound-and-true-p org-mobile-creating-agendas)
  2529. (org-mobile-write-agenda-for-mobile file))
  2530. ((string-match "\\.html?\\'" file)
  2531. (require 'htmlize)
  2532. (set-buffer (htmlize-buffer (current-buffer)))
  2533. (when (and org-agenda-export-html-style
  2534. (string-match "<style>" org-agenda-export-html-style))
  2535. ;; replace <style> section with org-agenda-export-html-style
  2536. (goto-char (point-min))
  2537. (kill-region (- (search-forward "<style") 6)
  2538. (search-forward "</style>"))
  2539. (insert org-agenda-export-html-style))
  2540. (write-file file)
  2541. (kill-buffer (current-buffer))
  2542. (message "HTML written to %s" file))
  2543. ((string-match "\\.ps\\'" file)
  2544. (require 'ps-print)
  2545. (ps-print-buffer-with-faces file)
  2546. (message "Postscript written to %s" file))
  2547. ((string-match "\\.pdf\\'" file)
  2548. (require 'ps-print)
  2549. (ps-print-buffer-with-faces
  2550. (concat (file-name-sans-extension file) ".ps"))
  2551. (call-process "ps2pdf" nil nil nil
  2552. (expand-file-name
  2553. (concat (file-name-sans-extension file) ".ps"))
  2554. (expand-file-name file))
  2555. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2556. (message "PDF written to %s" file))
  2557. ((string-match "\\.ics\\'" file)
  2558. (require 'org-icalendar)
  2559. (let ((org-agenda-marker-table
  2560. (org-create-marker-find-array
  2561. (org-agenda-collect-markers)))
  2562. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2563. (org-combined-agenda-icalendar-file file))
  2564. (apply 'org-export-icalendar 'combine
  2565. (org-agenda-files nil 'ifmode))))
  2566. (t
  2567. (let ((bs (buffer-string)))
  2568. (find-file file)
  2569. (erase-buffer)
  2570. (insert bs)
  2571. (save-buffer 0)
  2572. (kill-buffer (current-buffer))
  2573. (message "Plain text written to %s" file))))))))
  2574. (set-buffer org-agenda-buffer-name))
  2575. (when open (org-open-file file)))
  2576. (defvar org-agenda-filter-overlays nil)
  2577. (defun org-agenda-mark-filtered-text ()
  2578. "Mark all text hidden by filtering with a text property."
  2579. (let ((inhibit-read-only t))
  2580. (mapc
  2581. (lambda (o)
  2582. (when (equal (overlay-buffer o) (current-buffer))
  2583. (put-text-property
  2584. (overlay-start o) (overlay-end o)
  2585. 'org-filtered t)))
  2586. org-agenda-filter-overlays)))
  2587. (defun org-agenda-unmark-filtered-text ()
  2588. "Remove the filtering text property."
  2589. (let ((inhibit-read-only t))
  2590. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2591. (defun org-agenda-remove-marked-text (property &optional value)
  2592. "Delete all text marked with VALUE of PROPERTY.
  2593. VALUE defaults to t."
  2594. (let (beg)
  2595. (setq value (or value t))
  2596. (while (setq beg (text-property-any (point-min) (point-max)
  2597. property value))
  2598. (delete-region
  2599. beg (or (next-single-property-change beg 'org-filtered)
  2600. (point-max))))))
  2601. (defun org-agenda-add-entry-text ()
  2602. "Add entry text to agenda lines.
  2603. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2604. entry text following headings shown in the agenda.
  2605. Drawers will be excluded, also the line with scheduling/deadline info."
  2606. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2607. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2608. (let (m txt)
  2609. (goto-char (point-min))
  2610. (while (not (eobp))
  2611. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2612. (beginning-of-line 2)
  2613. (setq txt (org-agenda-get-some-entry-text
  2614. m org-agenda-add-entry-text-maxlines " > "))
  2615. (end-of-line 1)
  2616. (if (string-match "\\S-" txt)
  2617. (insert "\n" txt)
  2618. (or (eobp) (forward-char 1))))))))
  2619. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2620. &rest keep)
  2621. "Extract entry text from MARKER, at most N-LINES lines.
  2622. This will ignore drawers etc, just get the text.
  2623. If INDENT is given, prefix every line with this string. If KEEP is
  2624. given, it is a list of symbols, defining stuff that should not be
  2625. removed from the entry content. Currently only `planning' is allowed here."
  2626. (let (txt drawer-re kwd-time-re ind)
  2627. (save-excursion
  2628. (with-current-buffer (marker-buffer marker)
  2629. (if (not (org-mode-p))
  2630. (setq txt "")
  2631. (save-excursion
  2632. (save-restriction
  2633. (widen)
  2634. (goto-char marker)
  2635. (end-of-line 1)
  2636. (setq txt (buffer-substring
  2637. (min (1+ (point)) (point-max))
  2638. (progn (outline-next-heading) (point)))
  2639. drawer-re org-drawer-regexp
  2640. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2641. ".*\n?"))
  2642. (with-temp-buffer
  2643. (insert txt)
  2644. (when org-agenda-add-entry-text-descriptive-links
  2645. (goto-char (point-min))
  2646. (while (org-activate-bracket-links (point-max))
  2647. (add-text-properties (match-beginning 0) (match-end 0)
  2648. '(face org-link))))
  2649. (goto-char (point-min))
  2650. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2651. (set-text-properties (match-beginning 0) (match-end 0)
  2652. nil))
  2653. (goto-char (point-min))
  2654. (while (re-search-forward drawer-re nil t)
  2655. (delete-region
  2656. (match-beginning 0)
  2657. (progn (re-search-forward
  2658. "^[ \t]*:END:.*\n?" nil 'move)
  2659. (point))))
  2660. (unless (member 'planning keep)
  2661. (goto-char (point-min))
  2662. (while (re-search-forward kwd-time-re nil t)
  2663. (replace-match "")))
  2664. (goto-char (point-min))
  2665. (when org-agenda-entry-text-exclude-regexps
  2666. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2667. (while (setq re (pop re-list))
  2668. (goto-char (point-min))
  2669. (while (re-search-forward re nil t)
  2670. (replace-match "")))))
  2671. (goto-char (point-max))
  2672. (skip-chars-backward " \t\n")
  2673. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2674. ;; find and remove min common indentation
  2675. (goto-char (point-min))
  2676. (untabify (point-min) (point-max))
  2677. (setq ind (org-get-indentation))
  2678. (while (not (eobp))
  2679. (unless (looking-at "[ \t]*$")
  2680. (setq ind (min ind (org-get-indentation))))
  2681. (beginning-of-line 2))
  2682. (goto-char (point-min))
  2683. (while (not (eobp))
  2684. (unless (looking-at "[ \t]*$")
  2685. (move-to-column ind)
  2686. (delete-region (point-at-bol) (point)))
  2687. (beginning-of-line 2))
  2688. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2689. (goto-char (point-min))
  2690. (when indent
  2691. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2692. (replace-match indent t t)))
  2693. (goto-char (point-min))
  2694. (while (looking-at "[ \t]*\n") (replace-match ""))
  2695. (goto-char (point-max))
  2696. (when (> (org-current-line)
  2697. n-lines)
  2698. (org-goto-line (1+ n-lines))
  2699. (backward-char 1))
  2700. (setq txt (buffer-substring (point-min) (point)))))))))
  2701. txt))
  2702. (defun org-agenda-collect-markers ()
  2703. "Collect the markers pointing to entries in the agenda buffer."
  2704. (let (m markers)
  2705. (save-excursion
  2706. (goto-char (point-min))
  2707. (while (not (eobp))
  2708. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2709. (org-get-at-bol 'org-marker)))
  2710. (push m markers))
  2711. (beginning-of-line 2)))
  2712. (nreverse markers)))
  2713. (defun org-create-marker-find-array (marker-list)
  2714. "Create a alist of files names with all marker positions in that file."
  2715. (let (f tbl m a p)
  2716. (while (setq m (pop marker-list))
  2717. (setq p (marker-position m)
  2718. f (buffer-file-name (or (buffer-base-buffer
  2719. (marker-buffer m))
  2720. (marker-buffer m))))
  2721. (if (setq a (assoc f tbl))
  2722. (push (marker-position m) (cdr a))
  2723. (push (list f p) tbl)))
  2724. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2725. tbl)))
  2726. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2727. (defun org-check-agenda-marker-table ()
  2728. "Check of the current entry is on the marker list."
  2729. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2730. a)
  2731. (and (setq a (assoc file org-agenda-marker-table))
  2732. (save-match-data
  2733. (save-excursion
  2734. (org-back-to-heading t)
  2735. (member (point) (cdr a)))))))
  2736. (defun org-check-for-org-mode ()
  2737. "Make sure current buffer is in org-mode. Error if not."
  2738. (or (org-mode-p)
  2739. (error "Cannot execute org-mode agenda command on buffer in %s"
  2740. major-mode)))
  2741. (defun org-fit-agenda-window ()
  2742. "Fit the window to the buffer size."
  2743. (and (memq org-agenda-window-setup '(reorganize-frame))
  2744. (fboundp 'fit-window-to-buffer)
  2745. (org-fit-window-to-buffer
  2746. nil
  2747. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2748. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2749. ;;; Agenda prepare and finalize
  2750. (defvar org-agenda-multi nil) ; dynamically scoped
  2751. (defvar org-agenda-buffer-name "*Org Agenda*")
  2752. (defvar org-pre-agenda-window-conf nil)
  2753. (defvar org-agenda-columns-active nil)
  2754. (defvar org-agenda-name nil)
  2755. (defvar org-agenda-filter nil)
  2756. (defvar org-agenda-filter-while-redo nil)
  2757. (defvar org-agenda-filter-preset nil
  2758. "A preset of the tags filter used for secondary agenda filtering.
  2759. This must be a list of strings, each string must be a single tag preceded
  2760. by \"+\" or \"-\".
  2761. This variable should not be set directly, but agenda custom commands can
  2762. bind it in the options section. The preset filter is a global property of
  2763. the entire agenda view. In a block agenda, it will not work reliably to
  2764. define a filter for one of the individual blocks. You need to set it in
  2765. the global options and expect it to be applied to the entire view.")
  2766. (defun org-prepare-agenda (&optional name)
  2767. (setq org-todo-keywords-for-agenda nil)
  2768. (setq org-done-keywords-for-agenda nil)
  2769. (setq org-drawers-for-agenda nil)
  2770. (unless org-agenda-persistent-filter
  2771. (setq org-agenda-filter nil))
  2772. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2773. (if org-agenda-multi
  2774. (progn
  2775. (setq buffer-read-only nil)
  2776. (goto-char (point-max))
  2777. (unless (or (bobp) org-agenda-compact-blocks
  2778. (not org-agenda-block-separator))
  2779. (insert "\n"
  2780. (if (stringp org-agenda-block-separator)
  2781. org-agenda-block-separator
  2782. (make-string (window-width) org-agenda-block-separator))
  2783. "\n"))
  2784. (narrow-to-region (point) (point-max)))
  2785. (org-agenda-reset-markers)
  2786. (setq org-agenda-contributing-files nil)
  2787. (setq org-agenda-columns-active nil)
  2788. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2789. (setq org-todo-keywords-for-agenda
  2790. (org-uniquify org-todo-keywords-for-agenda))
  2791. (setq org-done-keywords-for-agenda
  2792. (org-uniquify org-done-keywords-for-agenda))
  2793. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2794. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2795. (awin (get-buffer-window abuf)))
  2796. (cond
  2797. ((equal (current-buffer) abuf) nil)
  2798. (awin (select-window awin))
  2799. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2800. ((equal org-agenda-window-setup 'current-window)
  2801. (org-pop-to-buffer-same-window abuf))
  2802. ((equal org-agenda-window-setup 'other-window)
  2803. (org-switch-to-buffer-other-window abuf))
  2804. ((equal org-agenda-window-setup 'other-frame)
  2805. (switch-to-buffer-other-frame abuf))
  2806. ((equal org-agenda-window-setup 'reorganize-frame)
  2807. (delete-other-windows)
  2808. (org-switch-to-buffer-other-window abuf)))
  2809. ;; additional test in case agenda is invoked from within agenda
  2810. ;; buffer via elisp link
  2811. (unless (equal (current-buffer) abuf)
  2812. (org-pop-to-buffer-same-window abuf)))
  2813. (setq buffer-read-only nil)
  2814. (let ((inhibit-read-only t)) (erase-buffer))
  2815. (org-agenda-mode)
  2816. (and name (not org-agenda-name)
  2817. (org-set-local 'org-agenda-name name)))
  2818. (setq buffer-read-only nil))
  2819. (defun org-finalize-agenda ()
  2820. "Finishing touch for the agenda buffer, called just before displaying it."
  2821. (unless org-agenda-multi
  2822. (save-excursion
  2823. (let ((inhibit-read-only t))
  2824. (goto-char (point-min))
  2825. (while (org-activate-bracket-links (point-max))
  2826. (add-text-properties (match-beginning 0) (match-end 0)
  2827. '(face org-link)))
  2828. (org-agenda-align-tags)
  2829. (unless org-agenda-with-colors
  2830. (remove-text-properties (point-min) (point-max) '(face nil))))
  2831. (if (and (boundp 'org-agenda-overriding-columns-format)
  2832. org-agenda-overriding-columns-format)
  2833. (org-set-local 'org-agenda-overriding-columns-format
  2834. org-agenda-overriding-columns-format))
  2835. (if (and (boundp 'org-agenda-view-columns-initially)
  2836. org-agenda-view-columns-initially)
  2837. (org-agenda-columns))
  2838. (when org-agenda-fontify-priorities
  2839. (org-agenda-fontify-priorities))
  2840. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2841. (org-agenda-dim-blocked-tasks))
  2842. (org-agenda-mark-clocking-task)
  2843. (when org-agenda-entry-text-mode
  2844. (org-agenda-entry-text-hide)
  2845. (org-agenda-entry-text-show))
  2846. (if (functionp 'org-habit-insert-consistency-graphs)
  2847. (org-habit-insert-consistency-graphs))
  2848. (run-hooks 'org-finalize-agenda-hook)
  2849. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2850. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2851. (org-agenda-filter-apply org-agenda-filter))
  2852. )))
  2853. (defun org-agenda-mark-clocking-task ()
  2854. "Mark the current clock entry in the agenda if it is present."
  2855. (mapc (lambda (o)
  2856. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2857. (delete-overlay o)))
  2858. (overlays-in (point-min) (point-max)))
  2859. (when (marker-buffer org-clock-hd-marker)
  2860. (save-excursion
  2861. (goto-char (point-min))
  2862. (let (s ov)
  2863. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2864. (goto-char s)
  2865. (when (equal (org-get-at-bol 'org-hd-marker)
  2866. org-clock-hd-marker)
  2867. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2868. (overlay-put ov 'type 'org-agenda-clocking)
  2869. (overlay-put ov 'face 'org-agenda-clocking)
  2870. (overlay-put ov 'help-echo
  2871. "The clock is running in this item")))))))
  2872. (defun org-agenda-fontify-priorities ()
  2873. "Make highest priority lines bold, and lowest italic."
  2874. (interactive)
  2875. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2876. (delete-overlay o)))
  2877. (overlays-in (point-min) (point-max)))
  2878. (save-excursion
  2879. (let ((inhibit-read-only t)
  2880. b e p ov h l)
  2881. (goto-char (point-min))
  2882. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2883. (setq h (or (get-char-property (point) 'org-highest-priority)
  2884. org-highest-priority)
  2885. l (or (get-char-property (point) 'org-lowest-priority)
  2886. org-lowest-priority)
  2887. p (string-to-char (match-string 1))
  2888. b (match-beginning 0)
  2889. e (if (eq org-agenda-fontify-priorities 'cookies)
  2890. (match-end 0)
  2891. (point-at-eol))
  2892. ov (make-overlay b e))
  2893. (overlay-put
  2894. ov 'face
  2895. (cond ((org-face-from-face-or-color
  2896. 'priority nil
  2897. (cdr (assoc p org-priority-faces))))
  2898. ((and (listp org-agenda-fontify-priorities)
  2899. (org-face-from-face-or-color
  2900. 'priority nil
  2901. (cdr (assoc p org-agenda-fontify-priorities)))))
  2902. ((equal p l) 'italic)
  2903. ((equal p h) 'bold)))
  2904. (overlay-put ov 'org-type 'org-priority)))))
  2905. (defun org-agenda-dim-blocked-tasks ()
  2906. "Dim currently blocked TODO's in the agenda display."
  2907. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2908. (delete-overlay o)))
  2909. (overlays-in (point-min) (point-max)))
  2910. (save-excursion
  2911. (let ((inhibit-read-only t)
  2912. (org-depend-tag-blocked nil)
  2913. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2914. org-blocked-by-checkboxes
  2915. invis1 b e p ov h l)
  2916. (goto-char (point-min))
  2917. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2918. (and pos (goto-char (1+ pos))))
  2919. (setq org-blocked-by-checkboxes nil invis1 invis)
  2920. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2921. (when (and marker
  2922. (not (with-current-buffer (marker-buffer marker)
  2923. (save-excursion
  2924. (goto-char marker)
  2925. (if (org-entry-get nil "NOBLOCKING")
  2926. t ;; Never block this entry
  2927. (run-hook-with-args-until-failure
  2928. 'org-blocker-hook
  2929. (list :type 'todo-state-change
  2930. :position marker
  2931. :from 'todo
  2932. :to 'done)))))))
  2933. (if org-blocked-by-checkboxes (setq invis1 nil))
  2934. (setq b (if invis1
  2935. (max (point-min) (1- (point-at-bol)))
  2936. (point-at-bol))
  2937. e (point-at-eol)
  2938. ov (make-overlay b e))
  2939. (if invis1
  2940. (overlay-put ov 'invisible t)
  2941. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2942. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2943. (defvar org-agenda-skip-function nil
  2944. "Function to be called at each match during agenda construction.
  2945. If this function returns nil, the current match should not be skipped.
  2946. Otherwise, the function must return a position from where the search
  2947. should be continued.
  2948. This may also be a Lisp form, it will be evaluated.
  2949. Never set this variable using `setq' or so, because then it will apply
  2950. to all future agenda commands. If you do want a global skipping condition,
  2951. use the option `org-agenda-skip-function-global' instead.
  2952. The correct usage for `org-agenda-skip-function' is to bind it with
  2953. `let' to scope it dynamically into the agenda-constructing command.
  2954. A good way to set it is through options in `org-agenda-custom-commands'.")
  2955. (defun org-agenda-skip ()
  2956. "Throw to `:skip' in places that should be skipped.
  2957. Also moves point to the end of the skipped region, so that search can
  2958. continue from there."
  2959. (let ((p (point-at-bol)) to)
  2960. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2961. (get-text-property p :org-archived)
  2962. (org-end-of-subtree t)
  2963. (throw :skip t))
  2964. (and org-agenda-skip-comment-trees
  2965. (get-text-property p :org-comment)
  2966. (org-end-of-subtree t)
  2967. (throw :skip t))
  2968. (if (equal (char-after p) ?#) (throw :skip t))
  2969. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2970. (org-agenda-skip-eval org-agenda-skip-function)))
  2971. (goto-char to)
  2972. (throw :skip t))))
  2973. (defun org-agenda-skip-eval (form)
  2974. "If FORM is a function or a list, call (or eval) is and return result.
  2975. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2976. and match data are returned to the previous state no matter what these
  2977. functions do."
  2978. (let (fp)
  2979. (and form
  2980. (or (setq fp (functionp form))
  2981. (consp form))
  2982. (save-excursion
  2983. (save-match-data
  2984. (if fp
  2985. (funcall form)
  2986. (eval form)))))))
  2987. (defvar org-agenda-markers nil
  2988. "List of all currently active markers created by `org-agenda'.")
  2989. (defvar org-agenda-last-marker-time (org-float-time)
  2990. "Creation time of the last agenda marker.")
  2991. (defun org-agenda-new-marker (&optional pos)
  2992. "Return a new agenda marker.
  2993. Org-mode keeps a list of these markers and resets them when they are
  2994. no longer in use."
  2995. (let ((m (copy-marker (or pos (point)))))
  2996. (setq org-agenda-last-marker-time (org-float-time))
  2997. (push m org-agenda-markers)
  2998. m))
  2999. (defun org-agenda-reset-markers ()
  3000. "Reset markers created by `org-agenda'."
  3001. (while org-agenda-markers
  3002. (move-marker (pop org-agenda-markers) nil)))
  3003. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3004. "Save relative positions of markers in region."
  3005. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3006. org-agenda-markers))
  3007. ;;; Entry text mode
  3008. (defun org-agenda-entry-text-show-here ()
  3009. "Add some text from the entry as context to the current line."
  3010. (let (m txt o)
  3011. (setq m (org-get-at-bol 'org-hd-marker))
  3012. (unless (marker-buffer m)
  3013. (error "No marker points to an entry here"))
  3014. (setq txt (concat "\n" (org-no-properties
  3015. (org-agenda-get-some-entry-text
  3016. m org-agenda-entry-text-maxlines " > "))))
  3017. (when (string-match "\\S-" txt)
  3018. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3019. (overlay-put o 'evaporate t)
  3020. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3021. (overlay-put o 'after-string txt))))
  3022. (defun org-agenda-entry-text-show ()
  3023. "Add entry context for all agenda lines."
  3024. (interactive)
  3025. (save-excursion
  3026. (goto-char (point-max))
  3027. (beginning-of-line 1)
  3028. (while (not (bobp))
  3029. (when (org-get-at-bol 'org-hd-marker)
  3030. (org-agenda-entry-text-show-here))
  3031. (beginning-of-line 0))))
  3032. (defun org-agenda-entry-text-hide ()
  3033. "Remove any shown entry context."
  3034. (delq nil
  3035. (mapcar (lambda (o)
  3036. (if (eq (overlay-get o 'org-overlay-type)
  3037. 'agenda-entry-content)
  3038. (progn (delete-overlay o) t)))
  3039. (overlays-in (point-min) (point-max)))))
  3040. (defun org-agenda-get-day-face (date)
  3041. "Return the face DATE should be displayed with."
  3042. (or (and (functionp org-agenda-day-face-function)
  3043. (funcall org-agenda-day-face-function date))
  3044. (cond ((org-agenda-todayp date)
  3045. 'org-agenda-date-today)
  3046. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3047. 'org-agenda-date-weekend)
  3048. (t 'org-agenda-date))))
  3049. ;;; Agenda timeline
  3050. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3051. (defun org-timeline (&optional dotodo)
  3052. "Show a time-sorted view of the entries in the current org file.
  3053. Only entries with a time stamp of today or later will be listed. With
  3054. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3055. under the current date.
  3056. If the buffer contains an active region, only check the region for
  3057. dates."
  3058. (interactive "P")
  3059. (org-compile-prefix-format 'timeline)
  3060. (org-set-sorting-strategy 'timeline)
  3061. (let* ((dopast t)
  3062. (doclosed org-agenda-show-log)
  3063. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3064. (current-buffer))))
  3065. (date (calendar-current-date))
  3066. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3067. (end (if (org-region-active-p) (region-end) (point-max)))
  3068. (day-numbers (org-get-all-dates beg end 'no-ranges
  3069. t doclosed ; always include today
  3070. org-timeline-show-empty-dates))
  3071. (org-deadline-warning-days 0)
  3072. (org-agenda-only-exact-dates t)
  3073. (today (org-today))
  3074. (past t)
  3075. args
  3076. s e rtn d emptyp)
  3077. (setq org-agenda-redo-command
  3078. (list 'progn
  3079. (list 'org-switch-to-buffer-other-window (current-buffer))
  3080. (list 'org-timeline (list 'quote dotodo))))
  3081. (if (not dopast)
  3082. ;; Remove past dates from the list of dates.
  3083. (setq day-numbers (delq nil (mapcar (lambda(x)
  3084. (if (>= x today) x nil))
  3085. day-numbers))))
  3086. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3087. (if doclosed (push :closed args))
  3088. (push :timestamp args)
  3089. (push :deadline args)
  3090. (push :scheduled args)
  3091. (push :sexp args)
  3092. (if dotodo (push :todo args))
  3093. (insert "Timeline of file " entry "\n")
  3094. (add-text-properties (point-min) (point)
  3095. (list 'face 'org-agenda-structure))
  3096. (org-agenda-mark-header-line (point-min))
  3097. (while (setq d (pop day-numbers))
  3098. (if (and (listp d) (eq (car d) :omitted))
  3099. (progn
  3100. (setq s (point))
  3101. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3102. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3103. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3104. (if (and (>= d today)
  3105. dopast
  3106. past)
  3107. (progn
  3108. (setq past nil)
  3109. (insert (make-string 79 ?-) "\n")))
  3110. (setq date (calendar-gregorian-from-absolute d))
  3111. (setq s (point))
  3112. (setq rtn (and (not emptyp)
  3113. (apply 'org-agenda-get-day-entries entry
  3114. date args)))
  3115. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3116. (progn
  3117. (insert
  3118. (if (stringp org-agenda-format-date)
  3119. (format-time-string org-agenda-format-date
  3120. (org-time-from-absolute date))
  3121. (funcall org-agenda-format-date date))
  3122. "\n")
  3123. (put-text-property s (1- (point)) 'face
  3124. (org-agenda-get-day-face date))
  3125. (put-text-property s (1- (point)) 'org-date-line t)
  3126. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3127. (if (equal d today)
  3128. (put-text-property s (1- (point)) 'org-today t))
  3129. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3130. (put-text-property s (1- (point)) 'day d)))))
  3131. (goto-char (point-min))
  3132. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3133. (point-min)))
  3134. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3135. (org-finalize-agenda)
  3136. (setq buffer-read-only t)))
  3137. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3138. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3139. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3140. not every single day in the range. If FORCE-TODAY is non-nil, make
  3141. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3142. inactive time stamps (those in square brackets) are included.
  3143. When EMPTY is non-nil, also include days without any entries."
  3144. (let ((re (concat
  3145. (if pre-re pre-re "")
  3146. (if inactive org-ts-regexp-both org-ts-regexp)))
  3147. dates dates1 date day day1 day2 ts1 ts2)
  3148. (if force-today
  3149. (setq dates (list (org-today))))
  3150. (save-excursion
  3151. (goto-char beg)
  3152. (while (re-search-forward re end t)
  3153. (setq day (time-to-days (org-time-string-to-time
  3154. (substring (match-string 1) 0 10))))
  3155. (or (memq day dates) (push day dates)))
  3156. (unless no-ranges
  3157. (goto-char beg)
  3158. (while (re-search-forward org-tr-regexp end t)
  3159. (setq ts1 (substring (match-string 1) 0 10)
  3160. ts2 (substring (match-string 2) 0 10)
  3161. day1 (time-to-days (org-time-string-to-time ts1))
  3162. day2 (time-to-days (org-time-string-to-time ts2)))
  3163. (while (< (setq day1 (1+ day1)) day2)
  3164. (or (memq day1 dates) (push day1 dates)))))
  3165. (setq dates (sort dates '<))
  3166. (when empty
  3167. (while (setq day (pop dates))
  3168. (setq day2 (car dates))
  3169. (push day dates1)
  3170. (when (and day2 empty)
  3171. (if (or (eq empty t)
  3172. (and (numberp empty) (<= (- day2 day) empty)))
  3173. (while (< (setq day (1+ day)) day2)
  3174. (push (list day) dates1))
  3175. (push (cons :omitted (- day2 day)) dates1))))
  3176. (setq dates (nreverse dates1)))
  3177. dates)))
  3178. ;;; Agenda Daily/Weekly
  3179. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3180. "Start day for the agenda view.
  3181. Custom commands can set this variable in the options section.")
  3182. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3183. (defvar org-agenda-current-span nil
  3184. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3185. (defvar org-arg-loc nil) ; local variable
  3186. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3187. "List of types searched for when creating the daily/weekly agenda.
  3188. This variable is a list of symbols that controls the types of
  3189. items that appear in the daily/weekly agenda. Allowed symbols in this
  3190. list are are
  3191. :timestamp List items containing a date stamp or date range matching
  3192. the selected date. This includes sexp entries in
  3193. angular brackets.
  3194. :sexp List entries resulting from plain diary-like sexps.
  3195. :deadline List deadline due on that date. When the date is today,
  3196. also list any deadlines past due, or due within
  3197. `org-deadline-warning-days'. `:deadline' must appear before
  3198. `:scheduled' if the setting of
  3199. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3200. any effect.
  3201. :scheduled List all items which are scheduled for the given date.
  3202. The diary for *today* also contains items which were
  3203. scheduled earlier and are not yet marked DONE.
  3204. By default, all four types are turned on.
  3205. Never set this variable globally using `setq', because then it
  3206. will apply to all future agenda commands. Instead, bind it with
  3207. `let' to scope it dynamically into the agenda-constructing
  3208. command. A good way to set it is through options in
  3209. `org-agenda-custom-commands'. For a more flexible (though
  3210. somewhat less efficient) way of determining what is included in
  3211. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3212. ;;;###autoload
  3213. (defun org-agenda-list (&optional arg start-day span)
  3214. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3215. The view will be for the current day or week, but from the overview buffer
  3216. you will be able to go to other days/weeks.
  3217. With a numeric prefix argument in an interactive call, the agenda will
  3218. span ARG days. Lisp programs should instead specify SPAN to change
  3219. the number of days. SPAN defaults to `org-agenda-span'.
  3220. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3221. given in `org-agenda-start-on-weekday'."
  3222. (interactive "P")
  3223. (if (and (integerp arg) (> arg 0))
  3224. (setq span arg arg nil))
  3225. (setq start-day (or start-day org-agenda-start-day))
  3226. (if org-agenda-overriding-arguments
  3227. (setq arg (car org-agenda-overriding-arguments)
  3228. start-day (nth 1 org-agenda-overriding-arguments)
  3229. span (nth 2 org-agenda-overriding-arguments)))
  3230. (if (stringp start-day)
  3231. ;; Convert to an absolute day number
  3232. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3233. (setq org-agenda-last-arguments (list arg start-day span))
  3234. (org-compile-prefix-format 'agenda)
  3235. (org-set-sorting-strategy 'agenda)
  3236. (let* ((span (org-agenda-ndays-to-span
  3237. (or span org-agenda-ndays org-agenda-span)))
  3238. (today (org-today))
  3239. (sd (or start-day today))
  3240. (ndays (org-agenda-span-to-ndays span sd))
  3241. (org-agenda-start-on-weekday
  3242. (if (eq ndays 7)
  3243. org-agenda-start-on-weekday))
  3244. (thefiles (org-agenda-files nil 'ifmode))
  3245. (files thefiles)
  3246. (start (if (or (null org-agenda-start-on-weekday)
  3247. (< ndays 7))
  3248. sd
  3249. (let* ((nt (calendar-day-of-week
  3250. (calendar-gregorian-from-absolute sd)))
  3251. (n1 org-agenda-start-on-weekday)
  3252. (d (- nt n1)))
  3253. (- sd (+ (if (< d 0) 7 0) d)))))
  3254. (day-numbers (list start))
  3255. (day-cnt 0)
  3256. (inhibit-redisplay (not debug-on-error))
  3257. s e rtn rtnall file date d start-pos end-pos todayp
  3258. clocktable-start clocktable-end filter)
  3259. (setq org-agenda-redo-command
  3260. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3261. (dotimes (n (1- ndays))
  3262. (push (1+ (car day-numbers)) day-numbers))
  3263. (setq day-numbers (nreverse day-numbers))
  3264. (setq clocktable-start (car day-numbers)
  3265. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3266. (org-prepare-agenda "Day/Week")
  3267. (org-set-local 'org-starting-day (car day-numbers))
  3268. (org-set-local 'org-arg-loc arg)
  3269. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3270. (unless org-agenda-compact-blocks
  3271. (let* ((d1 (car day-numbers))
  3272. (d2 (org-last day-numbers))
  3273. (w1 (org-days-to-iso-week d1))
  3274. (w2 (org-days-to-iso-week d2)))
  3275. (setq s (point))
  3276. (if org-agenda-overriding-header
  3277. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3278. nil 'face 'org-agenda-structure) "\n")
  3279. (insert (org-agenda-span-name span)
  3280. "-agenda"
  3281. (if (< (- d2 d1) 350)
  3282. (if (= w1 w2)
  3283. (format " (W%02d)" w1)
  3284. (format " (W%02d-W%02d)" w1 w2))
  3285. "")
  3286. ":\n")))
  3287. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3288. 'org-date-line t))
  3289. (org-agenda-mark-header-line s))
  3290. (while (setq d (pop day-numbers))
  3291. (setq date (calendar-gregorian-from-absolute d)
  3292. s (point))
  3293. (if (or (setq todayp (= d today))
  3294. (and (not start-pos) (= d sd)))
  3295. (setq start-pos (point))
  3296. (if (and start-pos (not end-pos))
  3297. (setq end-pos (point))))
  3298. (setq files thefiles
  3299. rtnall nil)
  3300. (while (setq file (pop files))
  3301. (catch 'nextfile
  3302. (org-check-agenda-file file)
  3303. (let ((org-agenda-entry-types org-agenda-entry-types))
  3304. (unless org-agenda-include-deadlines
  3305. (setq org-agenda-entry-types
  3306. (delq :deadline org-agenda-entry-types)))
  3307. (cond
  3308. ((memq org-agenda-show-log '(only clockcheck))
  3309. (setq rtn (org-agenda-get-day-entries
  3310. file date :closed)))
  3311. (org-agenda-show-log
  3312. (setq rtn (apply 'org-agenda-get-day-entries
  3313. file date
  3314. (append '(:closed) org-agenda-entry-types))))
  3315. (t
  3316. (setq rtn (apply 'org-agenda-get-day-entries
  3317. file date
  3318. org-agenda-entry-types)))))
  3319. (setq rtnall (append rtnall rtn))))
  3320. (if org-agenda-include-diary
  3321. (let ((org-agenda-search-headline-for-time t))
  3322. (require 'diary-lib)
  3323. (setq rtn (org-get-entries-from-diary date))
  3324. (setq rtnall (append rtnall rtn))))
  3325. (if (or rtnall org-agenda-show-all-dates)
  3326. (progn
  3327. (setq day-cnt (1+ day-cnt))
  3328. (insert
  3329. (if (stringp org-agenda-format-date)
  3330. (format-time-string org-agenda-format-date
  3331. (org-time-from-absolute date))
  3332. (funcall org-agenda-format-date date))
  3333. "\n")
  3334. (put-text-property s (1- (point)) 'face
  3335. (org-agenda-get-day-face date))
  3336. (put-text-property s (1- (point)) 'org-date-line t)
  3337. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3338. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3339. (when todayp
  3340. (put-text-property s (1- (point)) 'org-today t))
  3341. (if rtnall (insert
  3342. (org-finalize-agenda-entries
  3343. (org-agenda-add-time-grid-maybe
  3344. rtnall ndays todayp))
  3345. "\n"))
  3346. (put-text-property s (1- (point)) 'day d)
  3347. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3348. (when (and org-agenda-clockreport-mode clocktable-start)
  3349. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3350. ;; the above line is to ensure the restricted range!
  3351. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3352. tbl)
  3353. (setq p (org-plist-delete p :block))
  3354. (setq p (plist-put p :tstart clocktable-start))
  3355. (setq p (plist-put p :tend clocktable-end))
  3356. (setq p (plist-put p :scope 'agenda))
  3357. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3358. (setq filter (or org-agenda-filter-while-redo
  3359. (get 'org-agenda-filter :preset-filter))))
  3360. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3361. (if (string-match "[<>=]" x)
  3362. ""
  3363. x))
  3364. filter ""))))
  3365. (setq tbl (apply 'org-get-clocktable p))
  3366. (insert tbl)))
  3367. (goto-char (point-min))
  3368. (or org-agenda-multi (org-fit-agenda-window))
  3369. (unless (and (pos-visible-in-window-p (point-min))
  3370. (pos-visible-in-window-p (point-max)))
  3371. (goto-char (1- (point-max)))
  3372. (recenter -1)
  3373. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3374. (progn
  3375. (goto-char (or start-pos 1))
  3376. (recenter 1))))
  3377. (goto-char (or start-pos 1))
  3378. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3379. (if (eq org-agenda-show-log 'clockcheck)
  3380. (org-agenda-show-clocking-issues))
  3381. (org-finalize-agenda)
  3382. (setq buffer-read-only t)
  3383. (message "")))
  3384. (defun org-agenda-ndays-to-span (n)
  3385. "Return a span symbol for a span of N days, or N if none matches."
  3386. (cond ((symbolp n) n)
  3387. ((= n 1) 'day)
  3388. ((= n 7) 'week)
  3389. (t n)))
  3390. (defun org-agenda-span-to-ndays (span start-day)
  3391. "Return ndays from SPAN starting at START-DAY."
  3392. (cond ((numberp span) span)
  3393. ((eq span 'day) 1)
  3394. ((eq span 'week) 7)
  3395. ((eq span 'month)
  3396. (let ((date (calendar-gregorian-from-absolute start-day)))
  3397. (calendar-last-day-of-month (car date) (caddr date))))
  3398. ((eq span 'year)
  3399. (let ((date (calendar-gregorian-from-absolute start-day)))
  3400. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3401. (defun org-agenda-span-name (span)
  3402. "Return a SPAN name."
  3403. (if (null span)
  3404. ""
  3405. (if (symbolp span)
  3406. (capitalize (symbol-name span))
  3407. (format "%d days" span))))
  3408. ;;; Agenda word search
  3409. (defvar org-agenda-search-history nil)
  3410. (defvar org-todo-only nil)
  3411. (defvar org-search-syntax-table nil
  3412. "Special syntax table for org-mode search.
  3413. In this table, we have single quotes not as word constituents, to
  3414. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3415. (defun org-search-syntax-table ()
  3416. (unless org-search-syntax-table
  3417. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3418. (modify-syntax-entry ?' "." org-search-syntax-table)
  3419. (modify-syntax-entry ?` "." org-search-syntax-table))
  3420. org-search-syntax-table)
  3421. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3422. ;;;###autoload
  3423. (defun org-search-view (&optional todo-only string edit-at)
  3424. "Show all entries that contain a phrase or words or regular expressions.
  3425. With optional prefix argument TODO-ONLY, only consider entries that are
  3426. TODO entries. The argument STRING can be used to pass a default search
  3427. string into this function. If EDIT-AT is non-nil, it means that the
  3428. user should get a chance to edit this string, with cursor at position
  3429. EDIT-AT.
  3430. The search string can be viewed either as a phrase that should be found as
  3431. is, or it can be broken into a number of snippets, each of which must match
  3432. in a Boolean way to select an entry. The default depends on the variable
  3433. `org-agenda-search-view-always-boolean'.
  3434. Even if this is turned off (the default) you can always switch to
  3435. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3436. The default is a direct search of the whole phrase, where each space in
  3437. the search string can expand to an arbitrary amount of whitespace,
  3438. including newlines.
  3439. If using a Boolean search, the search string is split on whitespace and
  3440. each snippet is searched separately, with logical AND to select an entry.
  3441. Words prefixed with a minus must *not* occur in the entry. Words without
  3442. a prefix or prefixed with a plus must occur in the entry. Matching is
  3443. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3444. match whole words, not parts of a word) if
  3445. `org-agenda-search-view-force-full-words' is set (default is nil).
  3446. Boolean search snippets enclosed by curly braces are interpreted as
  3447. regular expressions that must or (when preceded with \"-\") must not
  3448. match in the entry. Snippets enclosed into double quotes will be taken
  3449. as a whole, to include whitespace.
  3450. - If the search string starts with an asterisk, search only in headlines.
  3451. - If (possibly after the leading star) the search string starts with an
  3452. exclamation mark, this also means to look at TODO entries only, an effect
  3453. that can also be achieved with a prefix argument.
  3454. - If (possibly after star and exclamation mark) the search string starts
  3455. with a colon, this will mean that the (non-regexp) snippets of the
  3456. Boolean search must match as full words.
  3457. This command searches the agenda files, and in addition the files listed
  3458. in `org-agenda-text-search-extra-files'."
  3459. (interactive "P")
  3460. (org-compile-prefix-format 'search)
  3461. (org-set-sorting-strategy 'search)
  3462. (org-prepare-agenda "SEARCH")
  3463. (let* ((props (list 'face nil
  3464. 'done-face 'org-agenda-done
  3465. 'org-not-done-regexp org-not-done-regexp
  3466. 'org-todo-regexp org-todo-regexp
  3467. 'org-complex-heading-regexp org-complex-heading-regexp
  3468. 'mouse-face 'highlight
  3469. 'help-echo (format "mouse-2 or RET jump to location")))
  3470. (full-words org-agenda-search-view-force-full-words)
  3471. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3472. regexp rtn rtnall files file pos
  3473. marker category tags c neg re boolean
  3474. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3475. (unless (and (not edit-at)
  3476. (stringp string)
  3477. (string-match "\\S-" string))
  3478. (setq string (read-string
  3479. (if org-agenda-search-view-always-boolean
  3480. "[+-]Word/{Regexp} ...: "
  3481. "Phrase, or [+-]Word/{Regexp} ...: ")
  3482. (cond
  3483. ((integerp edit-at) (cons string edit-at))
  3484. (edit-at string))
  3485. 'org-agenda-search-history)))
  3486. (org-set-local 'org-todo-only todo-only)
  3487. (setq org-agenda-redo-command
  3488. (list 'org-search-view (if todo-only t nil) string
  3489. '(if current-prefix-arg 1 nil)))
  3490. (setq org-agenda-query-string string)
  3491. (if (equal (string-to-char string) ?*)
  3492. (setq hdl-only t
  3493. words (substring string 1))
  3494. (setq words string))
  3495. (when (equal (string-to-char words) ?!)
  3496. (setq todo-only t
  3497. words (substring words 1)))
  3498. (when (equal (string-to-char words) ?:)
  3499. (setq full-words t
  3500. words (substring words 1)))
  3501. (if (or org-agenda-search-view-always-boolean
  3502. (member (string-to-char words) '(?- ?+ ?\{)))
  3503. (setq boolean t))
  3504. (setq words (org-split-string words))
  3505. (let (www w)
  3506. (while (setq w (pop words))
  3507. (while (and (string-match "\\\\\\'" w) words)
  3508. (setq w (concat (substring w 0 -1) " " (pop words))))
  3509. (push w www))
  3510. (setq words (nreverse www) www nil)
  3511. (while (setq w (pop words))
  3512. (when (and (string-match "\\`[-+]?{" w)
  3513. (not (string-match "}\\'" w)))
  3514. (while (and words (not (string-match "}\\'" (car words))))
  3515. (setq w (concat w " " (pop words))))
  3516. (setq w (concat w " " (pop words))))
  3517. (push w www))
  3518. (setq words (nreverse www)))
  3519. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3520. (when boolean
  3521. (let (wds w)
  3522. (while (setq w (pop words))
  3523. (if (or (equal (substring w 0 1) "\"")
  3524. (and (> (length w) 1)
  3525. (member (substring w 0 1) '("+" "-"))
  3526. (equal (substring w 1 2) "\"")))
  3527. (while (and words (not (equal (substring w -1) "\"")))
  3528. (setq w (concat w " " (pop words)))))
  3529. (and (string-match "\\`\\([-+]?\\)\"" w)
  3530. (setq w (replace-match "\\1" nil nil w)))
  3531. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3532. (push w wds))
  3533. (setq words (nreverse wds))))
  3534. (if boolean
  3535. (mapc (lambda (w)
  3536. (setq c (string-to-char w))
  3537. (if (equal c ?-)
  3538. (setq neg t w (substring w 1))
  3539. (if (equal c ?+)
  3540. (setq neg nil w (substring w 1))
  3541. (setq neg nil)))
  3542. (if (string-match "\\`{.*}\\'" w)
  3543. (setq re (substring w 1 -1))
  3544. (if full-words
  3545. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3546. (setq re (regexp-quote (downcase w)))))
  3547. (if neg (push re regexps-) (push re regexps+)))
  3548. words)
  3549. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3550. regexps+))
  3551. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3552. (if (not regexps+)
  3553. (setq regexp org-outline-regexp-bol)
  3554. (setq regexp (pop regexps+))
  3555. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3556. regexp))))
  3557. (setq files (org-agenda-files nil 'ifmode))
  3558. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3559. (pop org-agenda-text-search-extra-files)
  3560. (setq files (org-add-archive-files files)))
  3561. (setq files (append files org-agenda-text-search-extra-files)
  3562. rtnall nil)
  3563. (while (setq file (pop files))
  3564. (setq ee nil)
  3565. (catch 'nextfile
  3566. (org-check-agenda-file file)
  3567. (setq buffer (if (file-exists-p file)
  3568. (org-get-agenda-file-buffer file)
  3569. (error "No such file %s" file)))
  3570. (if (not buffer)
  3571. ;; If file does not exist, make sure an error message is sent
  3572. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3573. file))))
  3574. (with-current-buffer buffer
  3575. (with-syntax-table (org-search-syntax-table)
  3576. (unless (org-mode-p)
  3577. (error "Agenda file %s is not in `org-mode'" file))
  3578. (let ((case-fold-search t))
  3579. (save-excursion
  3580. (save-restriction
  3581. (if org-agenda-restrict
  3582. (narrow-to-region org-agenda-restrict-begin
  3583. org-agenda-restrict-end)
  3584. (widen))
  3585. (goto-char (point-min))
  3586. (unless (or (org-on-heading-p)
  3587. (outline-next-heading))
  3588. (throw 'nextfile t))
  3589. (goto-char (max (point-min) (1- (point))))
  3590. (while (re-search-forward regexp nil t)
  3591. (org-back-to-heading t)
  3592. (skip-chars-forward "* ")
  3593. (setq beg (point-at-bol)
  3594. beg1 (point)
  3595. end (progn (outline-next-heading) (point)))
  3596. (catch :skip
  3597. (goto-char beg)
  3598. (org-agenda-skip)
  3599. (setq str (buffer-substring-no-properties
  3600. (point-at-bol)
  3601. (if hdl-only (point-at-eol) end)))
  3602. (mapc (lambda (wr) (when (string-match wr str)
  3603. (goto-char (1- end))
  3604. (throw :skip t)))
  3605. regexps-)
  3606. (mapc (lambda (wr) (unless (string-match wr str)
  3607. (goto-char (1- end))
  3608. (throw :skip t)))
  3609. (if todo-only
  3610. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3611. regexps+)
  3612. regexps+))
  3613. (goto-char beg)
  3614. (setq marker (org-agenda-new-marker (point))
  3615. category (org-get-category)
  3616. tags (org-get-tags-at (point))
  3617. txt (org-format-agenda-item
  3618. ""
  3619. (buffer-substring-no-properties
  3620. beg1 (point-at-eol))
  3621. category tags))
  3622. (org-add-props txt props
  3623. 'org-marker marker 'org-hd-marker marker
  3624. 'org-todo-regexp org-todo-regexp
  3625. 'org-complex-heading-regexp org-complex-heading-regexp
  3626. 'priority 1000 'org-category category
  3627. 'type "search")
  3628. (push txt ee)
  3629. (goto-char (1- end))))))))))
  3630. (setq rtn (nreverse ee))
  3631. (setq rtnall (append rtnall rtn)))
  3632. (if org-agenda-overriding-header
  3633. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3634. nil 'face 'org-agenda-structure) "\n")
  3635. (insert "Search words: ")
  3636. (add-text-properties (point-min) (1- (point))
  3637. (list 'face 'org-agenda-structure))
  3638. (setq pos (point))
  3639. (insert string "\n")
  3640. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3641. (setq pos (point))
  3642. (unless org-agenda-multi
  3643. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3644. (add-text-properties pos (1- (point))
  3645. (list 'face 'org-agenda-structure))))
  3646. (org-agenda-mark-header-line (point-min))
  3647. (when rtnall
  3648. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3649. (goto-char (point-min))
  3650. (or org-agenda-multi (org-fit-agenda-window))
  3651. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3652. (org-finalize-agenda)
  3653. (setq buffer-read-only t)))
  3654. ;;; Agenda TODO list
  3655. (defvar org-select-this-todo-keyword nil)
  3656. (defvar org-last-arg nil)
  3657. ;;;###autoload
  3658. (defun org-todo-list (arg)
  3659. "Show all (not done) TODO entries from all agenda file in a single list.
  3660. The prefix arg can be used to select a specific TODO keyword and limit
  3661. the list to these. When using \\[universal-argument], you will be prompted
  3662. for a keyword. A numeric prefix directly selects the Nth keyword in
  3663. `org-todo-keywords-1'."
  3664. (interactive "P")
  3665. (org-compile-prefix-format 'todo)
  3666. (org-set-sorting-strategy 'todo)
  3667. (org-prepare-agenda "TODO")
  3668. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3669. (let* ((today (org-today))
  3670. (date (calendar-gregorian-from-absolute today))
  3671. (kwds org-todo-keywords-for-agenda)
  3672. (completion-ignore-case t)
  3673. (org-select-this-todo-keyword
  3674. (if (stringp arg) arg
  3675. (and arg (integerp arg) (> arg 0)
  3676. (nth (1- arg) kwds))))
  3677. rtn rtnall files file pos)
  3678. (when (equal arg '(4))
  3679. (setq org-select-this-todo-keyword
  3680. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3681. (mapcar 'list kwds) nil nil)))
  3682. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3683. (org-set-local 'org-last-arg arg)
  3684. (setq org-agenda-redo-command
  3685. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3686. (setq files (org-agenda-files nil 'ifmode)
  3687. rtnall nil)
  3688. (while (setq file (pop files))
  3689. (catch 'nextfile
  3690. (org-check-agenda-file file)
  3691. (setq rtn (org-agenda-get-day-entries file date :todo))
  3692. (setq rtnall (append rtnall rtn))))
  3693. (if org-agenda-overriding-header
  3694. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3695. nil 'face 'org-agenda-structure) "\n")
  3696. (insert "Global list of TODO items of type: ")
  3697. (add-text-properties (point-min) (1- (point))
  3698. (list 'face 'org-agenda-structure
  3699. 'short-heading
  3700. (concat "ToDo: "
  3701. (or org-select-this-todo-keyword "ALL"))))
  3702. (org-agenda-mark-header-line (point-min))
  3703. (setq pos (point))
  3704. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3705. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3706. (setq pos (point))
  3707. (unless org-agenda-multi
  3708. (insert "Available with `N r': (0)ALL")
  3709. (let ((n 0) s)
  3710. (mapc (lambda (x)
  3711. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3712. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3713. (insert "\n "))
  3714. (insert " " s))
  3715. kwds))
  3716. (insert "\n"))
  3717. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3718. (org-agenda-mark-header-line (point-min))
  3719. (when rtnall
  3720. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3721. (goto-char (point-min))
  3722. (or org-agenda-multi (org-fit-agenda-window))
  3723. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3724. (org-finalize-agenda)
  3725. (setq buffer-read-only t)))
  3726. ;;; Agenda tags match
  3727. ;;;###autoload
  3728. (defun org-tags-view (&optional todo-only match)
  3729. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3730. The prefix arg TODO-ONLY limits the search to TODO entries."
  3731. (interactive "P")
  3732. (org-compile-prefix-format 'tags)
  3733. (org-set-sorting-strategy 'tags)
  3734. (let* ((org-tags-match-list-sublevels
  3735. org-tags-match-list-sublevels)
  3736. (completion-ignore-case t)
  3737. rtn rtnall files file pos matcher
  3738. buffer)
  3739. (when (and (stringp match) (not (string-match "\\S-" match)))
  3740. (setq match nil))
  3741. (setq matcher (org-make-tags-matcher match)
  3742. match (car matcher) matcher (cdr matcher))
  3743. (org-prepare-agenda (concat "TAGS " match))
  3744. (setq org-agenda-query-string match)
  3745. (setq org-agenda-redo-command
  3746. (list 'org-tags-view (list 'quote todo-only)
  3747. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3748. (setq files (org-agenda-files nil 'ifmode)
  3749. rtnall nil)
  3750. (while (setq file (pop files))
  3751. (catch 'nextfile
  3752. (org-check-agenda-file file)
  3753. (setq buffer (if (file-exists-p file)
  3754. (org-get-agenda-file-buffer file)
  3755. (error "No such file %s" file)))
  3756. (if (not buffer)
  3757. ;; If file does not exist, error message to agenda
  3758. (setq rtn (list
  3759. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3760. rtnall (append rtnall rtn))
  3761. (with-current-buffer buffer
  3762. (unless (org-mode-p)
  3763. (error "Agenda file %s is not in `org-mode'" file))
  3764. (save-excursion
  3765. (save-restriction
  3766. (if org-agenda-restrict
  3767. (narrow-to-region org-agenda-restrict-begin
  3768. org-agenda-restrict-end)
  3769. (widen))
  3770. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3771. (setq rtnall (append rtnall rtn))))))))
  3772. (if org-agenda-overriding-header
  3773. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3774. nil 'face 'org-agenda-structure) "\n")
  3775. (insert "Headlines with TAGS match: ")
  3776. (add-text-properties (point-min) (1- (point))
  3777. (list 'face 'org-agenda-structure
  3778. 'short-heading
  3779. (concat "Match: " match)))
  3780. (setq pos (point))
  3781. (insert match "\n")
  3782. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3783. (setq pos (point))
  3784. (unless org-agenda-multi
  3785. (insert "Press `C-u r' to search again with new search string\n"))
  3786. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3787. (org-agenda-mark-header-line (point-min))
  3788. (when rtnall
  3789. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3790. (goto-char (point-min))
  3791. (or org-agenda-multi (org-fit-agenda-window))
  3792. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3793. (org-finalize-agenda)
  3794. (setq buffer-read-only t)))
  3795. ;;; Agenda Finding stuck projects
  3796. (defvar org-agenda-skip-regexp nil
  3797. "Regular expression used in skipping subtrees for the agenda.
  3798. This is basically a temporary global variable that can be set and then
  3799. used by user-defined selections using `org-agenda-skip-function'.")
  3800. (defvar org-agenda-overriding-header nil
  3801. "When set during agenda, todo and tags searches it replaces the header.
  3802. This variable should not be set directly, but custom commands can bind it
  3803. in the options section.")
  3804. (defun org-agenda-skip-entry-when-regexp-matches ()
  3805. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3806. If yes, it returns the end position of this entry, causing agenda commands
  3807. to skip the entry but continuing the search in the subtree. This is a
  3808. function that can be put into `org-agenda-skip-function' for the duration
  3809. of a command."
  3810. (let ((end (save-excursion (org-end-of-subtree t)))
  3811. skip)
  3812. (save-excursion
  3813. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3814. (and skip end)))
  3815. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3816. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3817. If yes, it returns the end position of this tree, causing agenda commands
  3818. to skip this subtree. This is a function that can be put into
  3819. `org-agenda-skip-function' for the duration of a command."
  3820. (let ((end (save-excursion (org-end-of-subtree t)))
  3821. skip)
  3822. (save-excursion
  3823. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3824. (and skip end)))
  3825. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3826. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3827. If yes, it returns the end position of the current entry (NOT the tree),
  3828. causing agenda commands to skip the entry but continuing the search in
  3829. the subtree. This is a function that can be put into
  3830. `org-agenda-skip-function' for the duration of a command. An important
  3831. use of this function is for the stuck project list."
  3832. (let ((end (save-excursion (org-end-of-subtree t)))
  3833. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3834. skip)
  3835. (save-excursion
  3836. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3837. (and skip entry-end)))
  3838. (defun org-agenda-skip-entry-if (&rest conditions)
  3839. "Skip entry if any of CONDITIONS is true.
  3840. See `org-agenda-skip-if' for details."
  3841. (org-agenda-skip-if nil conditions))
  3842. (defun org-agenda-skip-subtree-if (&rest conditions)
  3843. "Skip entry if any of CONDITIONS is true.
  3844. See `org-agenda-skip-if' for details."
  3845. (org-agenda-skip-if t conditions))
  3846. (defun org-agenda-skip-if (subtree conditions)
  3847. "Checks current entity for CONDITIONS.
  3848. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3849. the entry, i.e. the text before the next heading is checked.
  3850. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3851. from different tests. Valid conditions are:
  3852. scheduled Check if there is a scheduled cookie
  3853. notscheduled Check if there is no scheduled cookie
  3854. deadline Check if there is a deadline
  3855. notdeadline Check if there is no deadline
  3856. timestamp Check if there is a timestamp (also deadline or scheduled)
  3857. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3858. regexp Check if regexp matches
  3859. notregexp Check if regexp does not match.
  3860. todo Check if TODO keyword matches
  3861. nottodo Check if TODO keyword does not match
  3862. The regexp is taken from the conditions list, it must come right after
  3863. the `regexp' or `notregexp' element.
  3864. `todo' and `nottodo' accept as an argument a list of todo
  3865. keywords, which may include \"*\" to match any todo keyword.
  3866. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3867. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3868. Instead of a list a keyword class may be given
  3869. (org-agenda-skip-entry-if 'nottodo 'done)
  3870. would skip entries that haven't been marked with any of \"DONE\"
  3871. keywords. Possible classes are: `todo', `done', `any'.
  3872. If any of these conditions is met, this function returns the end point of
  3873. the entity, causing the search to continue from there. This is a function
  3874. that can be put into `org-agenda-skip-function' for the duration of a command."
  3875. (let (beg end m)
  3876. (org-back-to-heading t)
  3877. (setq beg (point)
  3878. end (if subtree
  3879. (progn (org-end-of-subtree t) (point))
  3880. (progn (outline-next-heading) (1- (point)))))
  3881. (goto-char beg)
  3882. (and
  3883. (or
  3884. (and (memq 'scheduled conditions)
  3885. (re-search-forward org-scheduled-time-regexp end t))
  3886. (and (memq 'notscheduled conditions)
  3887. (not (re-search-forward org-scheduled-time-regexp end t)))
  3888. (and (memq 'deadline conditions)
  3889. (re-search-forward org-deadline-time-regexp end t))
  3890. (and (memq 'notdeadline conditions)
  3891. (not (re-search-forward org-deadline-time-regexp end t)))
  3892. (and (memq 'timestamp conditions)
  3893. (re-search-forward org-ts-regexp end t))
  3894. (and (memq 'nottimestamp conditions)
  3895. (not (re-search-forward org-ts-regexp end t)))
  3896. (and (setq m (memq 'regexp conditions))
  3897. (stringp (nth 1 m))
  3898. (re-search-forward (nth 1 m) end t))
  3899. (and (setq m (memq 'notregexp conditions))
  3900. (stringp (nth 1 m))
  3901. (not (re-search-forward (nth 1 m) end t)))
  3902. (and (or
  3903. (setq m (memq 'todo conditions))
  3904. (setq m (memq 'nottodo conditions)))
  3905. (org-agenda-skip-if-todo m end)))
  3906. end)))
  3907. (defun org-agenda-skip-if-todo (args end)
  3908. "Helper function for `org-agenda-skip-if', do not use it directly.
  3909. ARGS is a list with first element either `todo' or `nottodo'.
  3910. The remainder is either a list of TODO keywords, or a state symbol
  3911. `todo' or `done' or `any'."
  3912. (let ((kw (car args))
  3913. (arg (cadr args))
  3914. todo-wds todo-re)
  3915. (setq todo-wds
  3916. (org-uniquify
  3917. (cond
  3918. ((listp arg) ;; list of keywords
  3919. (if (member "*" arg)
  3920. (mapcar 'substring-no-properties org-todo-keywords-1)
  3921. arg))
  3922. ((symbolp arg) ;; keyword class name
  3923. (cond
  3924. ((eq arg 'todo)
  3925. (org-delete-all org-done-keywords
  3926. (mapcar 'substring-no-properties
  3927. org-todo-keywords-1)))
  3928. ((eq arg 'done) org-done-keywords)
  3929. ((eq arg 'any)
  3930. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3931. (setq todo-re
  3932. (concat "^\\*+[ \t]+\\<\\("
  3933. (mapconcat 'identity todo-wds "\\|")
  3934. "\\)\\>"))
  3935. (if (eq kw 'todo)
  3936. (re-search-forward todo-re end t)
  3937. (not (re-search-forward todo-re end t)))))
  3938. ;;;###autoload
  3939. (defun org-agenda-list-stuck-projects (&rest ignore)
  3940. "Create agenda view for projects that are stuck.
  3941. Stuck projects are project that have no next actions. For the definitions
  3942. of what a project is and how to check if it stuck, customize the variable
  3943. `org-stuck-projects'."
  3944. (interactive)
  3945. (let* ((org-agenda-skip-function
  3946. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3947. ;; We could have used org-agenda-skip-if here.
  3948. (org-agenda-overriding-header
  3949. (or org-agenda-overriding-header "List of stuck projects: "))
  3950. (matcher (nth 0 org-stuck-projects))
  3951. (todo (nth 1 org-stuck-projects))
  3952. (todo-wds (if (member "*" todo)
  3953. (progn
  3954. (org-prepare-agenda-buffers (org-agenda-files
  3955. nil 'ifmode))
  3956. (org-delete-all
  3957. org-done-keywords-for-agenda
  3958. (copy-sequence org-todo-keywords-for-agenda)))
  3959. todo))
  3960. (todo-re (concat "^\\*+[ \t]+\\("
  3961. (mapconcat 'identity todo-wds "\\|")
  3962. "\\)\\>"))
  3963. (tags (nth 2 org-stuck-projects))
  3964. (tags-re (if (member "*" tags)
  3965. (org-re (concat org-outline-regexp-bol
  3966. ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3967. (if tags
  3968. (concat org-outline-regexp-bol
  3969. ".*:\\("
  3970. (mapconcat 'identity tags "\\|")
  3971. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3972. (gen-re (nth 3 org-stuck-projects))
  3973. (re-list
  3974. (delq nil
  3975. (list
  3976. (if todo todo-re)
  3977. (if tags tags-re)
  3978. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3979. gen-re)))))
  3980. (setq org-agenda-skip-regexp
  3981. (if re-list
  3982. (mapconcat 'identity re-list "\\|")
  3983. (error "No information how to identify unstuck projects")))
  3984. (org-tags-view nil matcher)
  3985. (with-current-buffer org-agenda-buffer-name
  3986. (setq org-agenda-redo-command
  3987. '(org-agenda-list-stuck-projects
  3988. (or current-prefix-arg org-last-arg))))))
  3989. ;;; Diary integration
  3990. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3991. (defvar list-diary-entries-hook)
  3992. (defvar diary-time-regexp)
  3993. (defun org-get-entries-from-diary (date)
  3994. "Get the (Emacs Calendar) diary entries for DATE."
  3995. (require 'diary-lib)
  3996. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3997. (diary-display-hook '(fancy-diary-display))
  3998. (diary-display-function 'fancy-diary-display)
  3999. (pop-up-frames nil)
  4000. (list-diary-entries-hook
  4001. (cons 'org-diary-default-entry list-diary-entries-hook))
  4002. (diary-file-name-prefix-function nil) ; turn this feature off
  4003. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4004. entries
  4005. (org-disable-agenda-to-diary t))
  4006. (save-excursion
  4007. (save-window-excursion
  4008. (funcall (if (fboundp 'diary-list-entries)
  4009. 'diary-list-entries 'list-diary-entries)
  4010. date 1)))
  4011. (if (not (get-buffer diary-fancy-buffer))
  4012. (setq entries nil)
  4013. (with-current-buffer diary-fancy-buffer
  4014. (setq buffer-read-only nil)
  4015. (if (zerop (buffer-size))
  4016. ;; No entries
  4017. (setq entries nil)
  4018. ;; Omit the date and other unnecessary stuff
  4019. (org-agenda-cleanup-fancy-diary)
  4020. ;; Add prefix to each line and extend the text properties
  4021. (if (zerop (buffer-size))
  4022. (setq entries nil)
  4023. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4024. (setq entries
  4025. (with-temp-buffer
  4026. (insert entries) (goto-char (point-min))
  4027. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4028. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4029. (replace-match (concat "; " (match-string 1)))))
  4030. (buffer-string)))))
  4031. (set-buffer-modified-p nil)
  4032. (kill-buffer diary-fancy-buffer)))
  4033. (when entries
  4034. (setq entries (org-split-string entries "\n"))
  4035. (setq entries
  4036. (mapcar
  4037. (lambda (x)
  4038. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4039. ;; Extend the text properties to the beginning of the line
  4040. (org-add-props x (text-properties-at (1- (length x)) x)
  4041. 'type "diary" 'date date 'face 'org-agenda-diary))
  4042. entries)))))
  4043. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4044. "Hook run when the fancy diary buffer is cleaned up.")
  4045. (defun org-agenda-cleanup-fancy-diary ()
  4046. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4047. This gets rid of the date, the underline under the date, and
  4048. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4049. date. It also removes lines that contain only whitespace."
  4050. (goto-char (point-min))
  4051. (if (looking-at ".*?:[ \t]*")
  4052. (progn
  4053. (replace-match "")
  4054. (re-search-forward "\n=+$" nil t)
  4055. (replace-match "")
  4056. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4057. (re-search-forward "\n=+$" nil t)
  4058. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4059. (goto-char (point-min))
  4060. (while (re-search-forward "^ +\n" nil t)
  4061. (replace-match ""))
  4062. (goto-char (point-min))
  4063. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4064. (replace-match ""))
  4065. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4066. ;; Make sure entries from the diary have the right text properties.
  4067. (eval-after-load "diary-lib"
  4068. '(if (boundp 'diary-modify-entry-list-string-function)
  4069. ;; We can rely on the hook, nothing to do
  4070. nil
  4071. ;; Hook not available, must use advice to make this work
  4072. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4073. "Make the position visible."
  4074. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4075. (stringp string)
  4076. buffer-file-name)
  4077. (setq string (org-modify-diary-entry-string string))))))
  4078. (defun org-modify-diary-entry-string (string)
  4079. "Add text properties to string, allowing org-mode to act on it."
  4080. (org-add-props string nil
  4081. 'mouse-face 'highlight
  4082. 'help-echo (if buffer-file-name
  4083. (format "mouse-2 or RET jump to diary file %s"
  4084. (abbreviate-file-name buffer-file-name))
  4085. "")
  4086. 'org-agenda-diary-link t
  4087. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4088. (defun org-diary-default-entry ()
  4089. "Add a dummy entry to the diary.
  4090. Needed to avoid empty dates which mess up holiday display."
  4091. ;; Catch the error if dealing with the new add-to-diary-alist
  4092. (when org-disable-agenda-to-diary
  4093. (condition-case nil
  4094. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4095. (error
  4096. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4097. (defun org-add-to-diary-list (&rest args)
  4098. (if (fboundp 'diary-add-to-list)
  4099. (apply 'diary-add-to-list args)
  4100. (apply 'add-to-diary-list args)))
  4101. (defvar org-diary-last-run-time nil)
  4102. ;;;###autoload
  4103. (defun org-diary (&rest args)
  4104. "Return diary information from org-files.
  4105. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4106. It accesses org files and extracts information from those files to be
  4107. listed in the diary. The function accepts arguments specifying what
  4108. items should be listed. For a list of arguments allowed here, see the
  4109. variable `org-agenda-entry-types'.
  4110. The call in the diary file should look like this:
  4111. &%%(org-diary) ~/path/to/some/orgfile.org
  4112. Use a separate line for each org file to check. Or, if you omit the file name,
  4113. all files listed in `org-agenda-files' will be checked automatically:
  4114. &%%(org-diary)
  4115. If you don't give any arguments (as in the example above), the default
  4116. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4117. So the example above may also be written as
  4118. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4119. The function expects the lisp variables `entry' and `date' to be provided
  4120. by the caller, because this is how the calendar works. Don't use this
  4121. function from a program - use `org-agenda-get-day-entries' instead."
  4122. (when (> (- (org-float-time)
  4123. org-agenda-last-marker-time)
  4124. 5)
  4125. (org-agenda-reset-markers))
  4126. (org-compile-prefix-format 'agenda)
  4127. (org-set-sorting-strategy 'agenda)
  4128. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4129. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4130. (list entry)
  4131. (org-agenda-files t)))
  4132. (time (org-float-time))
  4133. file rtn results)
  4134. (when (or (not org-diary-last-run-time)
  4135. (> (- time
  4136. org-diary-last-run-time)
  4137. 3))
  4138. (org-prepare-agenda-buffers files))
  4139. (setq org-diary-last-run-time time)
  4140. ;; If this is called during org-agenda, don't return any entries to
  4141. ;; the calendar. Org Agenda will list these entries itself.
  4142. (if org-disable-agenda-to-diary (setq files nil))
  4143. (while (setq file (pop files))
  4144. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4145. (setq results (append results rtn)))
  4146. (if results
  4147. (concat (org-finalize-agenda-entries results) "\n"))))
  4148. ;;; Agenda entry finders
  4149. (defun org-agenda-get-day-entries (file date &rest args)
  4150. "Does the work for `org-diary' and `org-agenda'.
  4151. FILE is the path to a file to be checked for entries. DATE is date like
  4152. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4153. which kind of entries should be extracted. For details about these, see
  4154. the documentation of `org-diary'."
  4155. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4156. (let* ((org-startup-folded nil)
  4157. (org-startup-align-all-tables nil)
  4158. (buffer (if (file-exists-p file)
  4159. (org-get-agenda-file-buffer file)
  4160. (error "No such file %s" file)))
  4161. arg results rtn deadline-results)
  4162. (if (not buffer)
  4163. ;; If file does not exist, make sure an error message ends up in diary
  4164. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4165. (with-current-buffer buffer
  4166. (unless (org-mode-p)
  4167. (error "Agenda file %s is not in `org-mode'" file))
  4168. (let ((case-fold-search nil))
  4169. (save-excursion
  4170. (save-restriction
  4171. (if org-agenda-restrict
  4172. (narrow-to-region org-agenda-restrict-begin
  4173. org-agenda-restrict-end)
  4174. (widen))
  4175. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4176. (while (setq arg (pop args))
  4177. (cond
  4178. ((and (eq arg :todo)
  4179. (equal date (calendar-gregorian-from-absolute
  4180. (org-today))))
  4181. (setq rtn (org-agenda-get-todos))
  4182. (setq results (append results rtn)))
  4183. ((eq arg :timestamp)
  4184. (setq rtn (org-agenda-get-blocks))
  4185. (setq results (append results rtn))
  4186. (setq rtn (org-agenda-get-timestamps))
  4187. (setq results (append results rtn)))
  4188. ((eq arg :sexp)
  4189. (setq rtn (org-agenda-get-sexps))
  4190. (setq results (append results rtn)))
  4191. ((eq arg :scheduled)
  4192. (setq rtn (org-agenda-get-scheduled deadline-results))
  4193. (setq results (append results rtn)))
  4194. ((eq arg :closed)
  4195. (setq rtn (org-agenda-get-progress))
  4196. (setq results (append results rtn)))
  4197. ((eq arg :deadline)
  4198. (setq rtn (org-agenda-get-deadlines))
  4199. (setq deadline-results (copy-sequence rtn))
  4200. (setq results (append results rtn))))))))
  4201. results))))
  4202. (defun org-agenda-get-todos ()
  4203. "Return the TODO information for agenda display."
  4204. (let* ((props (list 'face nil
  4205. 'done-face 'org-agenda-done
  4206. 'org-not-done-regexp org-not-done-regexp
  4207. 'org-todo-regexp org-todo-regexp
  4208. 'org-complex-heading-regexp org-complex-heading-regexp
  4209. 'mouse-face 'highlight
  4210. 'help-echo
  4211. (format "mouse-2 or RET jump to org file %s"
  4212. (abbreviate-file-name buffer-file-name))))
  4213. (regexp (concat "^\\*+[ \t]+\\("
  4214. (if org-select-this-todo-keyword
  4215. (if (equal org-select-this-todo-keyword "*")
  4216. org-todo-regexp
  4217. (concat "\\<\\("
  4218. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4219. "\\)\\>"))
  4220. org-not-done-regexp)
  4221. "[^\n\r]*\\)"))
  4222. marker priority category tags todo-state
  4223. ee txt beg end)
  4224. (goto-char (point-min))
  4225. (while (re-search-forward regexp nil t)
  4226. (catch :skip
  4227. (save-match-data
  4228. (beginning-of-line)
  4229. (org-agenda-skip)
  4230. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4231. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4232. (goto-char (1+ beg))
  4233. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4234. (throw :skip nil)))
  4235. (goto-char (match-beginning 1))
  4236. (setq marker (org-agenda-new-marker (match-beginning 0))
  4237. category (org-get-category)
  4238. txt (match-string 1)
  4239. tags (org-get-tags-at (point))
  4240. txt (org-format-agenda-item "" txt category tags)
  4241. priority (1+ (org-get-priority txt))
  4242. todo-state (org-get-todo-state))
  4243. (org-add-props txt props
  4244. 'org-marker marker 'org-hd-marker marker
  4245. 'priority priority 'org-category category
  4246. 'type "todo" 'todo-state todo-state)
  4247. (push txt ee)
  4248. (if org-agenda-todo-list-sublevels
  4249. (goto-char (match-end 1))
  4250. (org-end-of-subtree 'invisible))))
  4251. (nreverse ee)))
  4252. (defun org-agenda-todo-custom-ignore-p (time n)
  4253. "Check whether timestamp is farther away then n number of days.
  4254. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4255. `org-agenda-todo-ignore-scheduled' or
  4256. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4257. (let ((days (org-days-to-time time)))
  4258. (if (>= n 0)
  4259. (>= days n)
  4260. (<= days n))))
  4261. ;;;###autoload
  4262. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4263. (&optional end)
  4264. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4265. (when (or org-agenda-todo-ignore-with-date
  4266. org-agenda-todo-ignore-scheduled
  4267. org-agenda-todo-ignore-deadlines
  4268. org-agenda-todo-ignore-timestamp)
  4269. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4270. (save-excursion
  4271. (or (and org-agenda-todo-ignore-with-date
  4272. (re-search-forward org-ts-regexp end t))
  4273. (and org-agenda-todo-ignore-scheduled
  4274. (re-search-forward org-scheduled-time-regexp end t)
  4275. (cond
  4276. ((eq org-agenda-todo-ignore-scheduled 'future)
  4277. (> (org-days-to-time (match-string 1)) 0))
  4278. ((eq org-agenda-todo-ignore-scheduled 'past)
  4279. (<= (org-days-to-time (match-string 1)) 0))
  4280. ((numberp org-agenda-todo-ignore-scheduled)
  4281. (org-agenda-todo-custom-ignore-p
  4282. (match-string 1) org-agenda-todo-ignore-scheduled))
  4283. (t)))
  4284. (and org-agenda-todo-ignore-deadlines
  4285. (re-search-forward org-deadline-time-regexp end t)
  4286. (cond
  4287. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4288. ((eq org-agenda-todo-ignore-deadlines 'far)
  4289. (not (org-deadline-close (match-string 1))))
  4290. ((eq org-agenda-todo-ignore-deadlines 'future)
  4291. (> (org-days-to-time (match-string 1)) 0))
  4292. ((eq org-agenda-todo-ignore-deadlines 'past)
  4293. (<= (org-days-to-time (match-string 1)) 0))
  4294. ((numberp org-agenda-todo-ignore-deadlines)
  4295. (org-agenda-todo-custom-ignore-p
  4296. (match-string 1) org-agenda-todo-ignore-deadlines))
  4297. (t (org-deadline-close (match-string 1)))))
  4298. (and org-agenda-todo-ignore-timestamp
  4299. (let ((buffer (current-buffer))
  4300. (regexp
  4301. (concat
  4302. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4303. (start (point)))
  4304. ;; Copy current buffer into a temporary one
  4305. (with-temp-buffer
  4306. (insert-buffer-substring buffer start end)
  4307. (goto-char (point-min))
  4308. ;; Delete SCHEDULED and DEADLINE items
  4309. (while (re-search-forward regexp end t)
  4310. (delete-region (match-beginning 0) (match-end 0)))
  4311. (goto-char (point-min))
  4312. ;; No search for timestamp left
  4313. (when (re-search-forward org-ts-regexp nil t)
  4314. (cond
  4315. ((eq org-agenda-todo-ignore-timestamp 'future)
  4316. (> (org-days-to-time (match-string 1)) 0))
  4317. ((eq org-agenda-todo-ignore-timestamp 'past)
  4318. (<= (org-days-to-time (match-string 1)) 0))
  4319. ((numberp org-agenda-todo-ignore-timestamp)
  4320. (org-agenda-todo-custom-ignore-p
  4321. (match-string 1) org-agenda-todo-ignore-timestamp))
  4322. (t))))))))))
  4323. (defconst org-agenda-no-heading-message
  4324. "No heading for this item in buffer or region.")
  4325. (defun org-agenda-get-timestamps ()
  4326. "Return the date stamp information for agenda display."
  4327. (let* ((props (list 'face nil
  4328. 'org-not-done-regexp org-not-done-regexp
  4329. 'org-todo-regexp org-todo-regexp
  4330. 'org-complex-heading-regexp org-complex-heading-regexp
  4331. 'mouse-face 'highlight
  4332. 'help-echo
  4333. (format "mouse-2 or RET jump to org file %s"
  4334. (abbreviate-file-name buffer-file-name))))
  4335. (d1 (calendar-absolute-from-gregorian date))
  4336. (remove-re
  4337. (concat
  4338. (regexp-quote
  4339. (format-time-string
  4340. "<%Y-%m-%d"
  4341. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4342. ".*?>"))
  4343. (regexp
  4344. (concat
  4345. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4346. (regexp-quote
  4347. (substring
  4348. (format-time-string
  4349. (car org-time-stamp-formats)
  4350. (apply 'encode-time ; DATE bound by calendar
  4351. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4352. 1 11))
  4353. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4354. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4355. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4356. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4357. todo-state end-of-match show-all)
  4358. (goto-char (point-min))
  4359. (while (setq end-of-match (re-search-forward regexp nil t))
  4360. (setq b0 (match-beginning 0)
  4361. b3 (match-beginning 3) e3 (match-end 3)
  4362. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4363. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4364. (member todo-state
  4365. org-agenda-repeating-timestamp-show-all)))
  4366. (catch :skip
  4367. (and (org-at-date-range-p) (throw :skip nil))
  4368. (org-agenda-skip)
  4369. (if (and (match-end 1)
  4370. (not (= d1 (org-time-string-to-absolute
  4371. (match-string 1) d1 nil show-all))))
  4372. (throw :skip nil))
  4373. (if (and e3
  4374. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4375. (throw :skip nil))
  4376. (setq tmp (buffer-substring (max (point-min)
  4377. (- b0 org-ds-keyword-length))
  4378. b0)
  4379. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4380. inactivep (= (char-after b0) ?\[)
  4381. deadlinep (string-match org-deadline-regexp tmp)
  4382. scheduledp (string-match org-scheduled-regexp tmp)
  4383. closedp (and org-agenda-include-inactive-timestamps
  4384. (string-match org-closed-string tmp))
  4385. clockp (and org-agenda-include-inactive-timestamps
  4386. (or (string-match org-clock-string tmp)
  4387. (string-match "]-+\\'" tmp)))
  4388. donep (member todo-state org-done-keywords))
  4389. (if (or scheduledp deadlinep closedp clockp
  4390. (and donep org-agenda-skip-timestamp-if-done))
  4391. (throw :skip t))
  4392. (if (string-match ">" timestr)
  4393. ;; substring should only run to end of time stamp
  4394. (setq timestr (substring timestr 0 (match-end 0))))
  4395. (setq marker (org-agenda-new-marker b0)
  4396. category (org-get-category b0))
  4397. (save-excursion
  4398. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4399. (setq txt org-agenda-no-heading-message)
  4400. (goto-char (match-beginning 0))
  4401. (setq hdmarker (org-agenda-new-marker)
  4402. tags (org-get-tags-at))
  4403. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4404. (setq head (or (match-string 1) ""))
  4405. (setq txt (org-format-agenda-item
  4406. (if inactivep org-agenda-inactive-leader nil)
  4407. head category tags timestr
  4408. remove-re)))
  4409. (setq priority (org-get-priority txt))
  4410. (org-add-props txt props
  4411. 'org-marker marker 'org-hd-marker hdmarker)
  4412. (org-add-props txt nil 'priority priority
  4413. 'org-category category 'date date
  4414. 'todo-state todo-state
  4415. 'type "timestamp")
  4416. (push txt ee))
  4417. (if org-agenda-skip-additional-timestamps-same-entry
  4418. (outline-next-heading)
  4419. (goto-char end-of-match))))
  4420. (nreverse ee)))
  4421. (defun org-agenda-get-sexps ()
  4422. "Return the sexp information for agenda display."
  4423. (require 'diary-lib)
  4424. (let* ((props (list 'mouse-face 'highlight
  4425. 'help-echo
  4426. (format "mouse-2 or RET jump to org file %s"
  4427. (abbreviate-file-name buffer-file-name))))
  4428. (regexp "^&?%%(")
  4429. marker category ee txt tags entry result beg b sexp sexp-entry
  4430. todo-state)
  4431. (goto-char (point-min))
  4432. (while (re-search-forward regexp nil t)
  4433. (catch :skip
  4434. (org-agenda-skip)
  4435. (setq beg (match-beginning 0))
  4436. (goto-char (1- (match-end 0)))
  4437. (setq b (point))
  4438. (forward-sexp 1)
  4439. (setq sexp (buffer-substring b (point)))
  4440. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4441. (org-trim (match-string 1))
  4442. ""))
  4443. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4444. (when result
  4445. (setq marker (org-agenda-new-marker beg)
  4446. category (org-get-category beg)
  4447. todo-state (org-get-todo-state))
  4448. (dolist (r (if (stringp result)
  4449. (list result)
  4450. result)) ;; we expect a list here
  4451. (if (string-match "\\S-" r)
  4452. (setq txt r)
  4453. (setq txt "SEXP entry returned empty string"))
  4454. (setq txt (org-format-agenda-item
  4455. "" txt category tags 'time))
  4456. (org-add-props txt props 'org-marker marker)
  4457. (org-add-props txt nil
  4458. 'org-category category 'date date 'todo-state todo-state
  4459. 'type "sexp")
  4460. (push txt ee)))))
  4461. (nreverse ee)))
  4462. ;; Calendar sanity: define some functions that are independent of
  4463. ;; `calendar-date-style'.
  4464. ;; Normally I would like to use ISO format when calling the diary functions,
  4465. ;; but to make sure we still have Emacs 22 compatibility we bind
  4466. ;; also `european-calendar-style' and use european format
  4467. (defun org-anniversary (year month day &optional mark)
  4468. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4469. (org-no-warnings
  4470. (let ((calendar-date-style 'european) (european-calendar-style t))
  4471. (diary-anniversary day month year mark))))
  4472. (defun org-cyclic (N year month day &optional mark)
  4473. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4474. (org-no-warnings
  4475. (let ((calendar-date-style 'european) (european-calendar-style t))
  4476. (diary-cyclic N day month year mark))))
  4477. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4478. "Like `diary-block', but with fixed (ISO) order of arguments."
  4479. (org-no-warnings
  4480. (let ((calendar-date-style 'european) (european-calendar-style t))
  4481. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4482. (defun org-date (year month day &optional mark)
  4483. "Like `diary-date', but with fixed (ISO) order of arguments."
  4484. (org-no-warnings
  4485. (let ((calendar-date-style 'european) (european-calendar-style t))
  4486. (diary-date day month year mark))))
  4487. (defalias 'org-float 'diary-float)
  4488. ;; Define the` org-class' function
  4489. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4490. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4491. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4492. is any number of ISO weeks in the block period for which the item should
  4493. be skipped."
  4494. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4495. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4496. (d (calendar-absolute-from-gregorian date)))
  4497. (and
  4498. (<= date1 d)
  4499. (<= d date2)
  4500. (= (calendar-day-of-week date) dayname)
  4501. (or (not skip-weeks)
  4502. (progn
  4503. (require 'cal-iso)
  4504. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4505. entry)))
  4506. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4507. "Like `org-class', but honor `calendar-date-style'.
  4508. The order of the first 2 times 3 arguments depends on the variable
  4509. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4510. So for American calendars, give this as MONTH DAY YEAR, for European as
  4511. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4512. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4513. is any number of ISO weeks in the block period for which the item should
  4514. be skipped.
  4515. This function is here only for backward compatibility and it is deprecated,
  4516. please use `org-class' instead."
  4517. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4518. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4519. (org-class
  4520. (nth 2 date1) (car date1) (nth 1 date1)
  4521. (nth 2 date2) (car date2) (nth 1 date2)
  4522. dayname skip-weeks)))
  4523. (defalias 'org-get-closed 'org-agenda-get-progress)
  4524. (defun org-agenda-get-progress ()
  4525. "Return the logged TODO entries for agenda display."
  4526. (let* ((props (list 'mouse-face 'highlight
  4527. 'org-not-done-regexp org-not-done-regexp
  4528. 'org-todo-regexp org-todo-regexp
  4529. 'org-complex-heading-regexp org-complex-heading-regexp
  4530. 'help-echo
  4531. (format "mouse-2 or RET jump to org file %s"
  4532. (abbreviate-file-name buffer-file-name))))
  4533. (items (if (consp org-agenda-show-log)
  4534. org-agenda-show-log
  4535. (if (eq org-agenda-show-log 'clockcheck)
  4536. '(clock)
  4537. org-agenda-log-mode-items)))
  4538. (parts
  4539. (delq nil
  4540. (list
  4541. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4542. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4543. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4544. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4545. (error "`org-agenda-log-mode-items' is empty")))
  4546. (regexp (concat
  4547. "\\(" parts-re "\\)"
  4548. " *\\["
  4549. (regexp-quote
  4550. (substring
  4551. (format-time-string
  4552. (car org-time-stamp-formats)
  4553. (apply 'encode-time ; DATE bound by calendar
  4554. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4555. 1 11))))
  4556. (org-agenda-search-headline-for-time nil)
  4557. marker hdmarker priority category tags closedp statep clockp state
  4558. ee txt extra timestr rest clocked)
  4559. (goto-char (point-min))
  4560. (while (re-search-forward regexp nil t)
  4561. (catch :skip
  4562. (org-agenda-skip)
  4563. (setq marker (org-agenda-new-marker (match-beginning 0))
  4564. closedp (equal (match-string 1) org-closed-string)
  4565. statep (equal (string-to-char (match-string 1)) ?-)
  4566. clockp (not (or closedp statep))
  4567. state (and statep (match-string 2))
  4568. category (org-get-category (match-beginning 0))
  4569. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4570. )
  4571. (when (string-match "\\]" timestr)
  4572. ;; substring should only run to end of time stamp
  4573. (setq rest (substring timestr (match-end 0))
  4574. timestr (substring timestr 0 (match-end 0)))
  4575. (if (and (not closedp) (not statep)
  4576. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4577. (progn (setq timestr (concat (substring timestr 0 -1)
  4578. "-" (match-string 1 rest) "]"))
  4579. (setq clocked (match-string 2 rest)))
  4580. (setq clocked "-")))
  4581. (save-excursion
  4582. (setq extra
  4583. (cond
  4584. ((not org-agenda-log-mode-add-notes) nil)
  4585. (statep
  4586. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4587. (match-string 1)))
  4588. (clockp
  4589. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4590. (match-string 1)))))
  4591. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4592. (setq txt org-agenda-no-heading-message)
  4593. (goto-char (match-beginning 0))
  4594. (setq hdmarker (org-agenda-new-marker)
  4595. tags (org-get-tags-at))
  4596. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4597. (setq txt (match-string 1))
  4598. (when extra
  4599. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4600. (setq txt (concat (substring txt 0 (match-beginning 1))
  4601. " - " extra " " (match-string 2 txt)))
  4602. (setq txt (concat txt " - " extra))))
  4603. (setq txt (org-format-agenda-item
  4604. (cond
  4605. (closedp "Closed: ")
  4606. (statep (concat "State: (" state ")"))
  4607. (t (concat "Clocked: (" clocked ")")))
  4608. txt category tags timestr)))
  4609. (setq priority 100000)
  4610. (org-add-props txt props
  4611. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4612. 'priority priority 'org-category category
  4613. 'type "closed" 'date date
  4614. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4615. (push txt ee))
  4616. (goto-char (point-at-eol))))
  4617. (nreverse ee)))
  4618. (defun org-agenda-show-clocking-issues ()
  4619. "Add overlays, showing issues with clocking.
  4620. See also the user option `org-agenda-clock-consistency-checks'."
  4621. (interactive)
  4622. (let* ((pl org-agenda-clock-consistency-checks)
  4623. (re (concat "^[ \t]*"
  4624. org-clock-string
  4625. "[ \t]+"
  4626. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4627. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4628. (tlstart 0.)
  4629. (tlend 0.)
  4630. (maxtime (org-hh:mm-string-to-minutes
  4631. (or (plist-get pl :max-duration) "24:00")))
  4632. (mintime (org-hh:mm-string-to-minutes
  4633. (or (plist-get pl :min-duration) 0)))
  4634. (maxgap (org-hh:mm-string-to-minutes
  4635. ;; default 30:00 means never complain
  4636. (or (plist-get pl :max-gap) "30:00")))
  4637. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4638. (plist-get pl :gap-ok-around)))
  4639. (def-face (or (plist-get pl :default-face)
  4640. '((:background "DarkRed") (:foreground "white"))))
  4641. issue face m te ts dt ov)
  4642. (goto-char (point-min))
  4643. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4644. (setq issue nil face def-face)
  4645. (catch 'next
  4646. (setq m (org-get-at-bol 'org-marker)
  4647. te nil ts nil)
  4648. (unless (and m (markerp m))
  4649. (setq issue "No valid clock line") (throw 'next t))
  4650. (org-with-point-at m
  4651. (save-excursion
  4652. (goto-char (point-at-bol))
  4653. (unless (looking-at re)
  4654. (error "No valid Clock line")
  4655. (throw 'next t))
  4656. (unless (match-end 3)
  4657. (setq issue "No end time"
  4658. face (or (plist-get pl :no-end-time-face) face))
  4659. (throw 'next t))
  4660. (setq ts (match-string 1)
  4661. te (match-string 3)
  4662. ts (org-float-time
  4663. (apply 'encode-time (org-parse-time-string ts)))
  4664. te (org-float-time
  4665. (apply 'encode-time (org-parse-time-string te)))
  4666. dt (- te ts))))
  4667. (cond
  4668. ((> dt (* 60 maxtime))
  4669. ;; a very long clocking chunk
  4670. (setq issue (format "Clocking interval is very long: %s"
  4671. (org-minutes-to-hh:mm-string
  4672. (floor (/ (float dt) 60.))))
  4673. face (or (plist-get pl :long-face) face)))
  4674. ((< dt (* 60 mintime))
  4675. ;; a very short clocking chunk
  4676. (setq issue (format "Clocking interval is very short: %s"
  4677. (org-minutes-to-hh:mm-string
  4678. (floor (/ (float dt) 60.))))
  4679. face (or (plist-get pl :short-face) face)))
  4680. ((and (> tlend 0) (< ts tlend))
  4681. ;; Two clock entries are overlapping
  4682. (setq issue (format "Clocking overlap: %d minutes"
  4683. (/ (- tlend ts) 60))
  4684. face (or (plist-get pl :overlap-face) face)))
  4685. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4686. ;; There is a gap, lets see if we need to report it
  4687. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4688. (setq issue (format "Clocking gap: %d minutes"
  4689. (/ (- ts tlend) 60))
  4690. face (or (plist-get pl :gap-face) face))))
  4691. (t nil)))
  4692. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4693. (when issue
  4694. ;; OK, there was some issue, add an overlay to show the issue
  4695. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4696. (overlay-put ov 'before-string
  4697. (concat
  4698. (org-add-props
  4699. (format "%-43s" (concat " " issue))
  4700. nil
  4701. 'face face)
  4702. "\n"))
  4703. (overlay-put ov 'evaporate t)))))
  4704. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4705. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4706. (catch 'exit
  4707. (unless ok-list
  4708. ;; there are no OK times for gaps...
  4709. (throw 'exit nil))
  4710. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4711. ;; This is more than 24 hours, so it is OK.
  4712. ;; because we have at least one OK time, that must be in the
  4713. ;; 24 hour interval.
  4714. (throw 'exit t))
  4715. ;; We have a shorter gap.
  4716. ;; Now we have to get the minute of the day when these times are
  4717. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4718. (t2dec (decode-time (seconds-to-time t2)))
  4719. ;; compute the minute on the day
  4720. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4721. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4722. (when (< min2 min1)
  4723. ;; if min2 is smaller than min1, this means it is on the next day.
  4724. ;; Wrap it to after midnight.
  4725. (setq min2 (+ min2 1440)))
  4726. ;; Now check if any of the OK times is in the gap
  4727. (mapc (lambda (x)
  4728. ;; Wrap the time to after midnight if necessary
  4729. (if (< x min1) (setq x (+ x 1440)))
  4730. ;; Check if in interval
  4731. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4732. ok-list)
  4733. ;; Nope, this gap is not OK
  4734. nil)))
  4735. (defun org-agenda-get-deadlines ()
  4736. "Return the deadline information for agenda display."
  4737. (let* ((props (list 'mouse-face 'highlight
  4738. 'org-not-done-regexp org-not-done-regexp
  4739. 'org-todo-regexp org-todo-regexp
  4740. 'org-complex-heading-regexp org-complex-heading-regexp
  4741. 'help-echo
  4742. (format "mouse-2 or RET jump to org file %s"
  4743. (abbreviate-file-name buffer-file-name))))
  4744. (regexp org-deadline-time-regexp)
  4745. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4746. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4747. d2 diff dfrac wdays pos pos1 category tags
  4748. suppress-prewarning
  4749. ee txt head face s todo-state show-all upcomingp donep timestr)
  4750. (goto-char (point-min))
  4751. (while (re-search-forward regexp nil t)
  4752. (setq suppress-prewarning nil)
  4753. (catch :skip
  4754. (org-agenda-skip)
  4755. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4756. (save-match-data
  4757. (string-match org-scheduled-time-regexp
  4758. (buffer-substring (point-at-bol)
  4759. (point-at-eol)))))
  4760. (setq suppress-prewarning
  4761. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4762. org-agenda-skip-deadline-prewarning-if-scheduled
  4763. 0)))
  4764. (setq s (match-string 1)
  4765. txt nil
  4766. pos (1- (match-beginning 1))
  4767. todo-state (save-match-data (org-get-todo-state))
  4768. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4769. (member todo-state
  4770. org-agenda-repeating-timestamp-show-all))
  4771. d2 (org-time-string-to-absolute
  4772. (match-string 1) d1 'past show-all)
  4773. diff (- d2 d1)
  4774. wdays (if suppress-prewarning
  4775. (let ((org-deadline-warning-days suppress-prewarning))
  4776. (org-get-wdays s))
  4777. (org-get-wdays s))
  4778. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4779. upcomingp (and todayp (> diff 0)))
  4780. ;; When to show a deadline in the calendar:
  4781. ;; If the expiration is within wdays warning time.
  4782. ;; Past-due deadlines are only shown on the current date
  4783. (if (and (or (and (<= diff wdays)
  4784. (and todayp (not org-agenda-only-exact-dates)))
  4785. (= diff 0)))
  4786. (save-excursion
  4787. ;; (setq todo-state (org-get-todo-state))
  4788. (setq donep (member todo-state org-done-keywords))
  4789. (if (and donep
  4790. (or org-agenda-skip-deadline-if-done
  4791. (not (= diff 0))))
  4792. (setq txt nil)
  4793. (setq category (org-get-category))
  4794. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4795. (setq txt org-agenda-no-heading-message)
  4796. (goto-char (match-end 0))
  4797. (setq pos1 (match-beginning 0))
  4798. (setq tags (org-get-tags-at pos1))
  4799. (setq head (buffer-substring-no-properties
  4800. (point)
  4801. (progn (skip-chars-forward "^\r\n")
  4802. (point))))
  4803. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4804. (setq timestr
  4805. (concat (substring s (match-beginning 1)) " "))
  4806. (setq timestr 'time))
  4807. (setq txt (org-format-agenda-item
  4808. (if (= diff 0)
  4809. (car org-agenda-deadline-leaders)
  4810. (if (functionp
  4811. (nth 1 org-agenda-deadline-leaders))
  4812. (funcall
  4813. (nth 1 org-agenda-deadline-leaders)
  4814. diff date)
  4815. (format (nth 1 org-agenda-deadline-leaders)
  4816. diff)))
  4817. head category tags
  4818. (if (not (= diff 0)) nil timestr)))))
  4819. (when txt
  4820. (setq face (org-agenda-deadline-face dfrac))
  4821. (org-add-props txt props
  4822. 'org-marker (org-agenda-new-marker pos)
  4823. 'org-hd-marker (org-agenda-new-marker pos1)
  4824. 'priority (+ (- diff)
  4825. (org-get-priority txt))
  4826. 'org-category category
  4827. 'todo-state todo-state
  4828. 'type (if upcomingp "upcoming-deadline" "deadline")
  4829. 'date (if upcomingp date d2)
  4830. 'face (if donep 'org-agenda-done face)
  4831. 'undone-face face 'done-face 'org-agenda-done)
  4832. (push txt ee))))))
  4833. (nreverse ee)))
  4834. (defun org-agenda-deadline-face (fraction)
  4835. "Return the face to displaying a deadline item.
  4836. FRACTION is what fraction of the head-warning time has passed."
  4837. (let ((faces org-agenda-deadline-faces) f)
  4838. (catch 'exit
  4839. (while (setq f (pop faces))
  4840. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4841. (defun org-agenda-get-scheduled (&optional deadline-results)
  4842. "Return the scheduled information for agenda display."
  4843. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4844. 'org-todo-regexp org-todo-regexp
  4845. 'org-complex-heading-regexp org-complex-heading-regexp
  4846. 'done-face 'org-agenda-done
  4847. 'mouse-face 'highlight
  4848. 'help-echo
  4849. (format "mouse-2 or RET jump to org file %s"
  4850. (abbreviate-file-name buffer-file-name))))
  4851. (regexp org-scheduled-time-regexp)
  4852. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4853. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4854. mm
  4855. (deadline-position-alist
  4856. (mapcar (lambda (a) (and (setq mm (get-text-property
  4857. 0 'org-hd-marker a))
  4858. (cons (marker-position mm) a)))
  4859. deadline-results))
  4860. d2 diff pos pos1 category tags donep
  4861. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4862. (goto-char (point-min))
  4863. (while (re-search-forward regexp nil t)
  4864. (catch :skip
  4865. (org-agenda-skip)
  4866. (setq s (match-string 1)
  4867. txt nil
  4868. pos (1- (match-beginning 1))
  4869. todo-state (save-match-data (org-get-todo-state))
  4870. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4871. (member todo-state
  4872. org-agenda-repeating-timestamp-show-all))
  4873. d2 (org-time-string-to-absolute
  4874. (match-string 1) d1 'past show-all)
  4875. diff (- d2 d1))
  4876. (setq pastschedp (and todayp (< diff 0)))
  4877. ;; When to show a scheduled item in the calendar:
  4878. ;; If it is on or past the date.
  4879. (when (or (and (< diff 0)
  4880. (< (abs diff) org-scheduled-past-days)
  4881. (and todayp (not org-agenda-only-exact-dates)))
  4882. (= diff 0))
  4883. (save-excursion
  4884. (setq donep (member todo-state org-done-keywords))
  4885. (if (and donep
  4886. (or org-agenda-skip-scheduled-if-done
  4887. (not (= diff 0))
  4888. (and (functionp 'org-is-habit-p)
  4889. (org-is-habit-p))))
  4890. (setq txt nil)
  4891. (setq habitp (and (functionp 'org-is-habit-p)
  4892. (org-is-habit-p)))
  4893. (setq category (org-get-category))
  4894. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4895. (setq txt org-agenda-no-heading-message)
  4896. (goto-char (match-end 0))
  4897. (setq pos1 (match-beginning 0))
  4898. (if habitp
  4899. (if (or (not org-habit-show-habits)
  4900. (and (not todayp)
  4901. org-habit-show-habits-only-for-today))
  4902. (throw :skip nil))
  4903. (if (and
  4904. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4905. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4906. pastschedp))
  4907. (setq mm (assoc pos1 deadline-position-alist)))
  4908. (throw :skip nil)))
  4909. (setq tags (org-get-tags-at))
  4910. (setq head (buffer-substring-no-properties
  4911. (point)
  4912. (progn (skip-chars-forward "^\r\n") (point))))
  4913. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4914. (setq timestr
  4915. (concat (substring s (match-beginning 1)) " "))
  4916. (setq timestr 'time))
  4917. (setq txt (org-format-agenda-item
  4918. (if (= diff 0)
  4919. (car org-agenda-scheduled-leaders)
  4920. (format (nth 1 org-agenda-scheduled-leaders)
  4921. (- 1 diff)))
  4922. head category tags
  4923. (if (not (= diff 0)) nil timestr)
  4924. nil habitp))))
  4925. (when txt
  4926. (setq face
  4927. (cond
  4928. ((and (not habitp) pastschedp)
  4929. 'org-scheduled-previously)
  4930. (todayp 'org-scheduled-today)
  4931. (t 'org-scheduled))
  4932. habitp (and habitp (org-habit-parse-todo)))
  4933. (org-add-props txt props
  4934. 'undone-face face
  4935. 'face (if donep 'org-agenda-done face)
  4936. 'org-marker (org-agenda-new-marker pos)
  4937. 'org-hd-marker (org-agenda-new-marker pos1)
  4938. 'type (if pastschedp "past-scheduled" "scheduled")
  4939. 'date (if pastschedp d2 date)
  4940. 'priority (if habitp
  4941. (org-habit-get-priority habitp)
  4942. (+ 94 (- 5 diff) (org-get-priority txt)))
  4943. 'org-category category
  4944. 'org-habit-p habitp
  4945. 'todo-state todo-state)
  4946. (push txt ee))))))
  4947. (nreverse ee)))
  4948. (defun org-agenda-get-blocks ()
  4949. "Return the date-range information for agenda display."
  4950. (let* ((props (list 'face nil
  4951. 'org-not-done-regexp org-not-done-regexp
  4952. 'org-todo-regexp org-todo-regexp
  4953. 'org-complex-heading-regexp org-complex-heading-regexp
  4954. 'mouse-face 'highlight
  4955. 'help-echo
  4956. (format "mouse-2 or RET jump to org file %s"
  4957. (abbreviate-file-name buffer-file-name))))
  4958. (regexp org-tr-regexp)
  4959. (d0 (calendar-absolute-from-gregorian date))
  4960. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4961. head donep)
  4962. (goto-char (point-min))
  4963. (while (re-search-forward regexp nil t)
  4964. (catch :skip
  4965. (org-agenda-skip)
  4966. (setq pos (point))
  4967. (let ((start-time (match-string 1))
  4968. (end-time (match-string 2)))
  4969. (setq s1 (match-string 1)
  4970. s2 (match-string 2)
  4971. d1 (time-to-days (org-time-string-to-time s1))
  4972. d2 (time-to-days (org-time-string-to-time s2)))
  4973. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4974. ;; Only allow days between the limits, because the normal
  4975. ;; date stamps will catch the limits.
  4976. (save-excursion
  4977. (setq todo-state (org-get-todo-state))
  4978. (setq donep (member todo-state org-done-keywords))
  4979. (if (and donep org-agenda-skip-timestamp-if-done)
  4980. (throw :skip t))
  4981. (setq marker (org-agenda-new-marker (point)))
  4982. (setq category (org-get-category))
  4983. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4984. (setq txt org-agenda-no-heading-message)
  4985. (goto-char (match-beginning 0))
  4986. (setq hdmarker (org-agenda-new-marker (point)))
  4987. (setq tags (org-get-tags-at))
  4988. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4989. (setq head (match-string 1))
  4990. (let ((remove-re
  4991. (if org-agenda-remove-timeranges-from-blocks
  4992. (concat
  4993. "<" (regexp-quote s1) ".*?>"
  4994. "--"
  4995. "<" (regexp-quote s2) ".*?>")
  4996. nil)))
  4997. (setq txt (org-format-agenda-item
  4998. (format
  4999. (nth (if (= d1 d2) 0 1)
  5000. org-agenda-timerange-leaders)
  5001. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5002. head category tags
  5003. (cond ((= d1 d0)
  5004. (concat "<" start-time ">"))
  5005. ((= d2 d0)
  5006. (concat "<" end-time ">"))
  5007. (t nil))
  5008. remove-re))))
  5009. (org-add-props txt props
  5010. 'org-marker marker 'org-hd-marker hdmarker
  5011. 'type "block" 'date date
  5012. 'todo-state todo-state
  5013. 'priority (org-get-priority txt) 'org-category category)
  5014. (push txt ee))))
  5015. (goto-char pos)))
  5016. ;; Sort the entries by expiration date.
  5017. (nreverse ee)))
  5018. ;;; Agenda presentation and sorting
  5019. (defvar org-prefix-has-time nil
  5020. "A flag, set by `org-compile-prefix-format'.
  5021. The flag is set if the currently compiled format contains a `%t'.")
  5022. (defvar org-prefix-has-tag nil
  5023. "A flag, set by `org-compile-prefix-format'.
  5024. The flag is set if the currently compiled format contains a `%T'.")
  5025. (defvar org-prefix-has-effort nil
  5026. "A flag, set by `org-compile-prefix-format'.
  5027. The flag is set if the currently compiled format contains a `%e'.")
  5028. (defvar org-prefix-category-length nil
  5029. "Used by `org-compile-prefix-format' to remember the category field width.")
  5030. (defvar org-prefix-category-max-length nil
  5031. "Used by `org-compile-prefix-format' to remember the category field width.")
  5032. (defun org-agenda-get-category-icon (category)
  5033. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5034. (dolist (entry org-agenda-category-icon-alist)
  5035. (when (org-string-match-p (car entry) category)
  5036. (if (listp (cadr entry))
  5037. (return (cadr entry))
  5038. (return (apply 'create-image (cdr entry)))))))
  5039. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5040. remove-re habitp)
  5041. "Format TXT to be inserted into the agenda buffer.
  5042. In particular, it adds the prefix and corresponding text properties. EXTRA
  5043. must be a string and replaces the `%s' specifier in the prefix format.
  5044. CATEGORY (string, symbol or nil) may be used to overrule the default
  5045. category taken from local variable or file name. It will replace the `%c'
  5046. specifier in the format. DOTIME, when non-nil, indicates that a
  5047. time-of-day should be extracted from TXT for sorting of this entry, and for
  5048. the `%t' specifier in the format. When DOTIME is a string, this string is
  5049. searched for a time before TXT is. TAGS can be the tags of the headline.
  5050. Any match of REMOVE-RE will be removed from TXT."
  5051. (save-match-data
  5052. ;; Diary entries sometimes have extra whitespace at the beginning
  5053. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5054. ;; Fix the tags part in txt
  5055. (setq txt (org-agenda-fix-displayed-tags
  5056. txt tags
  5057. org-agenda-show-inherited-tags
  5058. org-agenda-hide-tags-regexp))
  5059. (let* ((category (or category
  5060. (if (stringp org-category)
  5061. org-category
  5062. (and org-category (symbol-name org-category)))
  5063. (if buffer-file-name
  5064. (file-name-sans-extension
  5065. (file-name-nondirectory buffer-file-name))
  5066. "")))
  5067. (category-icon (org-agenda-get-category-icon category))
  5068. (category-icon (if category-icon
  5069. (propertize " " 'display category-icon)
  5070. ""))
  5071. ;; time, tag, effort are needed for the eval of the prefix format
  5072. (tag (if tags (nth (1- (length tags)) tags) ""))
  5073. time effort neffort
  5074. (ts (if dotime (concat
  5075. (if (stringp dotime) dotime "")
  5076. (and org-agenda-search-headline-for-time txt))))
  5077. (time-of-day (and dotime (org-get-time-of-day ts)))
  5078. stamp plain s0 s1 s2 rtn srp l
  5079. duration thecategory)
  5080. (and (org-mode-p) buffer-file-name
  5081. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5082. (when (and dotime time-of-day)
  5083. ;; Extract starting and ending time and move them to prefix
  5084. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5085. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5086. (setq s0 (match-string 0 ts)
  5087. srp (and stamp (match-end 3))
  5088. s1 (match-string (if plain 1 2) ts)
  5089. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5090. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5091. ;; them, we might want to remove them there to avoid duplication.
  5092. ;; The user can turn this off with a variable.
  5093. (if (and org-prefix-has-time
  5094. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5095. (string-match (concat (regexp-quote s0) " *") txt)
  5096. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5097. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5098. (= (match-beginning 0) 0)
  5099. t))
  5100. (setq txt (replace-match "" nil nil txt))))
  5101. ;; Normalize the time(s) to 24 hour
  5102. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5103. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5104. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5105. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5106. (setq s2
  5107. (org-minutes-to-hh:mm-string
  5108. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5109. ;; Compute the duration
  5110. (when s2
  5111. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5112. (org-hh:mm-string-to-minutes s1)))))
  5113. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5114. txt)
  5115. ;; Tags are in the string
  5116. (if (or (eq org-agenda-remove-tags t)
  5117. (and org-agenda-remove-tags
  5118. org-prefix-has-tag))
  5119. (setq txt (replace-match "" t t txt))
  5120. (setq txt (replace-match
  5121. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5122. (match-string 2 txt))
  5123. t t txt))))
  5124. (when (org-mode-p)
  5125. (setq effort
  5126. (condition-case nil
  5127. (org-get-effort
  5128. (or (get-text-property 0 'org-hd-marker txt)
  5129. (get-text-property 0 'org-marker txt)))
  5130. (error nil)))
  5131. (when effort
  5132. (setq neffort (org-duration-string-to-minutes effort)
  5133. effort (setq effort (concat "[" effort "]")))))
  5134. ;; prevent erroring out with %e format when there is no effort
  5135. (or effort (setq effort ""))
  5136. (when remove-re
  5137. (while (string-match remove-re txt)
  5138. (setq txt (replace-match "" t t txt))))
  5139. ;; Set org-heading property on `txt' to mark the start of the
  5140. ;; heading.
  5141. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5142. ;; Prepare the variables needed in the eval of the compiled format
  5143. (setq time (cond (s2 (concat
  5144. (org-agenda-time-of-day-to-ampm-maybe s1)
  5145. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5146. (if org-agenda-timegrid-use-ampm " ")))
  5147. (s1 (concat
  5148. (org-agenda-time-of-day-to-ampm-maybe s1)
  5149. (if org-agenda-timegrid-use-ampm
  5150. "........ "
  5151. "......")))
  5152. (t ""))
  5153. extra (or (and (not habitp) extra) "")
  5154. category (if (symbolp category) (symbol-name category) category)
  5155. thecategory (copy-sequence category))
  5156. (if (string-match org-bracket-link-regexp category)
  5157. (progn
  5158. (setq l (if (match-end 3)
  5159. (- (match-end 3) (match-beginning 3))
  5160. (- (match-end 1) (match-beginning 1))))
  5161. (when (< l (or org-prefix-category-length 0))
  5162. (setq category (copy-sequence category))
  5163. (org-add-props category nil
  5164. 'extra-space (make-string
  5165. (- org-prefix-category-length l 1) ?\ ))))
  5166. (if (and org-prefix-category-max-length
  5167. (>= (length category) org-prefix-category-max-length))
  5168. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5169. ;; Evaluate the compiled format
  5170. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5171. ;; And finally add the text properties
  5172. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5173. (org-add-props rtn nil
  5174. 'org-category (if thecategory (downcase thecategory) category)
  5175. 'tags (mapcar 'org-downcase-keep-props tags)
  5176. 'org-highest-priority org-highest-priority
  5177. 'org-lowest-priority org-lowest-priority
  5178. 'time-of-day time-of-day
  5179. 'duration duration
  5180. 'effort effort
  5181. 'effort-minutes neffort
  5182. 'txt txt
  5183. 'time time
  5184. 'extra extra
  5185. 'format org-prefix-format-compiled
  5186. 'dotime dotime))))
  5187. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5188. "Remove tags string from TXT, and add a modified list of tags.
  5189. The modified list may contain inherited tags, and tags matched by
  5190. `org-agenda-hide-tags-regexp' will be removed."
  5191. (when (or add-inherited hide-re)
  5192. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5193. (setq txt (substring txt 0 (match-beginning 0))))
  5194. (setq tags
  5195. (delq nil
  5196. (mapcar (lambda (tg)
  5197. (if (or (and hide-re (string-match hide-re tg))
  5198. (and (not add-inherited)
  5199. (get-text-property 0 'inherited tg)))
  5200. nil
  5201. tg))
  5202. tags)))
  5203. (when tags
  5204. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5205. i)
  5206. (setq txt (concat txt " :"
  5207. (mapconcat
  5208. (lambda (x)
  5209. (setq i (get-text-property 0 'inherited x))
  5210. (if (and have-i (not i))
  5211. (progn
  5212. (setq have-i nil)
  5213. (concat ":" x))
  5214. x))
  5215. tags ":")
  5216. (if have-i "::" ":"))))))
  5217. txt)
  5218. (defun org-downcase-keep-props (s)
  5219. (let ((props (text-properties-at 0 s)))
  5220. (setq s (downcase s))
  5221. (add-text-properties 0 (length s) props s)
  5222. s))
  5223. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5224. (defvar org-agenda-sorting-strategy-selected nil)
  5225. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5226. (catch 'exit
  5227. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5228. ((and todayp (member 'today (car org-agenda-time-grid))))
  5229. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5230. ((member 'weekly (car org-agenda-time-grid)))
  5231. (t (throw 'exit list)))
  5232. (let* ((have (delq nil (mapcar
  5233. (lambda (x) (get-text-property 1 'time-of-day x))
  5234. list)))
  5235. (string (nth 1 org-agenda-time-grid))
  5236. (gridtimes (nth 2 org-agenda-time-grid))
  5237. (req (car org-agenda-time-grid))
  5238. (remove (member 'remove-match req))
  5239. new time)
  5240. (if (and (member 'require-timed req) (not have))
  5241. ;; don't show empty grid
  5242. (throw 'exit list))
  5243. (while (setq time (pop gridtimes))
  5244. (unless (and remove (member time have))
  5245. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5246. (push (org-format-agenda-item
  5247. nil string "" nil
  5248. (concat (substring time 0 -2) ":" (substring time -2)))
  5249. new)
  5250. (put-text-property
  5251. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5252. (when (and todayp org-agenda-show-current-time-in-grid)
  5253. (push (org-format-agenda-item
  5254. nil
  5255. org-agenda-current-time-string
  5256. "" nil
  5257. (format-time-string "%H:%M "))
  5258. new)
  5259. (put-text-property
  5260. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5261. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5262. (append new list)
  5263. (append list new)))))
  5264. (defun org-compile-prefix-format (key)
  5265. "Compile the prefix format into a Lisp form that can be evaluated.
  5266. The resulting form is returned and stored in the variable
  5267. `org-prefix-format-compiled'."
  5268. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5269. org-prefix-category-length nil
  5270. org-prefix-has-effort nil)
  5271. (let ((s (cond
  5272. ((stringp org-agenda-prefix-format)
  5273. org-agenda-prefix-format)
  5274. ((assq key org-agenda-prefix-format)
  5275. (cdr (assq key org-agenda-prefix-format)))
  5276. (t " %-12:c%?-12t% s")))
  5277. (start 0)
  5278. varform vars var e c f opt)
  5279. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5280. s start)
  5281. (setq var (or (cdr (assoc (match-string 4 s)
  5282. '(("c" . category) ("t" . time) ("s" . extra)
  5283. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5284. 'eval)
  5285. c (or (match-string 3 s) "")
  5286. opt (match-beginning 1)
  5287. start (1+ (match-beginning 0)))
  5288. (if (equal var 'time) (setq org-prefix-has-time t))
  5289. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5290. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5291. (setq f (concat "%" (match-string 2 s) "s"))
  5292. (when (equal var 'category)
  5293. (setq org-prefix-category-length
  5294. (floor (abs (string-to-number (match-string 2 s)))))
  5295. (setq org-prefix-category-max-length
  5296. (let ((x (match-string 2 s)))
  5297. (save-match-data
  5298. (if (string-match "\\.[0-9]+" x)
  5299. (string-to-number (substring (match-string 0 x) 1)))))))
  5300. (if (eq var 'eval)
  5301. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5302. (if opt
  5303. (setq varform
  5304. `(if (equal "" ,var)
  5305. ""
  5306. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5307. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5308. (setq s (replace-match "%s" t nil s))
  5309. (push varform vars))
  5310. (setq vars (nreverse vars))
  5311. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5312. (defun org-set-sorting-strategy (key)
  5313. (if (symbolp (car org-agenda-sorting-strategy))
  5314. ;; the old format
  5315. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5316. (setq org-agenda-sorting-strategy-selected
  5317. (or (cdr (assq key org-agenda-sorting-strategy))
  5318. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5319. '(time-up category-keep priority-down)))))
  5320. (defun org-get-time-of-day (s &optional string mod24)
  5321. "Check string S for a time of day.
  5322. If found, return it as a military time number between 0 and 2400.
  5323. If not found, return nil.
  5324. The optional STRING argument forces conversion into a 5 character wide string
  5325. HH:MM."
  5326. (save-match-data
  5327. (when
  5328. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5329. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5330. (let* ((h (string-to-number (match-string 1 s)))
  5331. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5332. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5333. (am-p (equal ampm "am"))
  5334. (h1 (cond ((not ampm) h)
  5335. ((= h 12) (if am-p 0 12))
  5336. (t (+ h (if am-p 0 12)))))
  5337. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5338. (mod h1 24) h1))
  5339. (t0 (+ (* 100 h2) m))
  5340. (t1 (concat (if (>= h1 24) "+" " ")
  5341. (if (and org-agenda-time-leading-zero
  5342. (< t0 1000)) "0" "")
  5343. (if (< t0 100) "0" "")
  5344. (if (< t0 10) "0" "")
  5345. (int-to-string t0))))
  5346. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5347. (defvar org-agenda-before-sorting-filter-function nil
  5348. "Function to be applied to agenda items prior to sorting.
  5349. Prior to sorting also means just before they are inserted into the agenda.
  5350. To aid sorting, you may revisit the original entries and add more text
  5351. properties which will later be used by the sorting functions.
  5352. The function should take a string argument, an agenda line.
  5353. It has access to the text properties in that line, which contain among
  5354. other things, the property `org-hd-marker' that points to the entry
  5355. where the line comes from. Note that not all lines going into the agenda
  5356. have this property, only most.
  5357. The function should return the modified string. It is probably best
  5358. to ONLY change text properties.
  5359. You can also use this function as a filter, by returning nil for lines
  5360. you don't want to have in the agenda at all. For this application, you
  5361. could bind the variable in the options section of a custom command.")
  5362. (defun org-finalize-agenda-entries (list &optional nosort)
  5363. "Sort and concatenate the agenda items."
  5364. (setq list (mapcar 'org-agenda-highlight-todo list))
  5365. (if nosort
  5366. list
  5367. (when org-agenda-before-sorting-filter-function
  5368. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5369. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5370. (defun org-agenda-highlight-todo (x)
  5371. (let ((org-done-keywords org-done-keywords-for-agenda)
  5372. (case-fold-search nil)
  5373. re)
  5374. (if (eq x 'line)
  5375. (save-excursion
  5376. (beginning-of-line 1)
  5377. (setq re (org-get-at-bol 'org-todo-regexp))
  5378. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5379. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5380. (add-text-properties (match-beginning 0) (match-end 1)
  5381. (list 'face (org-get-todo-face 1)))
  5382. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5383. (delete-region (match-beginning 1) (1- (match-end 0)))
  5384. (goto-char (match-beginning 1))
  5385. (insert (format org-agenda-todo-keyword-format s)))))
  5386. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5387. (setq re (get-text-property 0 'org-todo-regexp x))
  5388. (when (and re
  5389. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5390. x (or pl 0)) pl))
  5391. (add-text-properties
  5392. (or (match-end 1) (match-end 0)) (match-end 0)
  5393. (list 'face (org-get-todo-face (match-string 2 x)))
  5394. x)
  5395. (when (match-end 1)
  5396. (setq x (concat (substring x 0 (match-end 1))
  5397. (format org-agenda-todo-keyword-format
  5398. (match-string 2 x))
  5399. (org-add-props " " (text-properties-at 0 x))
  5400. (substring x (match-end 3)))))))
  5401. x)))
  5402. (defsubst org-cmp-priority (a b)
  5403. "Compare the priorities of string A and B."
  5404. (let ((pa (or (get-text-property 1 'priority a) 0))
  5405. (pb (or (get-text-property 1 'priority b) 0)))
  5406. (cond ((> pa pb) +1)
  5407. ((< pa pb) -1)
  5408. (t nil))))
  5409. (defsubst org-cmp-effort (a b)
  5410. "Compare the effort values of string A and B."
  5411. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5412. (ea (or (get-text-property 1 'effort-minutes a) def))
  5413. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5414. (cond ((> ea eb) +1)
  5415. ((< ea eb) -1)
  5416. (t nil))))
  5417. (defsubst org-cmp-category (a b)
  5418. "Compare the string values of categories of strings A and B."
  5419. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5420. (cb (or (get-text-property 1 'org-category b) "")))
  5421. (cond ((string-lessp ca cb) -1)
  5422. ((string-lessp cb ca) +1)
  5423. (t nil))))
  5424. (defsubst org-cmp-todo-state (a b)
  5425. "Compare the todo states of strings A and B."
  5426. (let* ((ma (or (get-text-property 1 'org-marker a)
  5427. (get-text-property 1 'org-hd-marker a)))
  5428. (mb (or (get-text-property 1 'org-marker b)
  5429. (get-text-property 1 'org-hd-marker b)))
  5430. (fa (and ma (marker-buffer ma)))
  5431. (fb (and mb (marker-buffer mb)))
  5432. (todo-kwds
  5433. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5434. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5435. (ta (or (get-text-property 1 'todo-state a) ""))
  5436. (tb (or (get-text-property 1 'todo-state b) ""))
  5437. (la (- (length (member ta todo-kwds))))
  5438. (lb (- (length (member tb todo-kwds))))
  5439. (donepa (member ta org-done-keywords-for-agenda))
  5440. (donepb (member tb org-done-keywords-for-agenda)))
  5441. (cond ((and donepa (not donepb)) -1)
  5442. ((and (not donepa) donepb) +1)
  5443. ((< la lb) -1)
  5444. ((< lb la) +1)
  5445. (t nil))))
  5446. (defsubst org-cmp-alpha (a b)
  5447. "Compare the headlines, alphabetically."
  5448. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5449. (plb (text-property-any 0 (length b) 'org-heading t b))
  5450. (ta (and pla (substring a pla)))
  5451. (tb (and plb (substring b plb))))
  5452. (when pla
  5453. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5454. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5455. (setq ta (substring ta (match-end 0))))
  5456. (setq ta (downcase ta)))
  5457. (when plb
  5458. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5459. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5460. (setq tb (substring tb (match-end 0))))
  5461. (setq tb (downcase tb)))
  5462. (cond ((not ta) +1)
  5463. ((not tb) -1)
  5464. ((string-lessp ta tb) -1)
  5465. ((string-lessp tb ta) +1)
  5466. (t nil))))
  5467. (defsubst org-cmp-tag (a b)
  5468. "Compare the string values of the first tags of A and B."
  5469. (let ((ta (car (last (get-text-property 1 'tags a))))
  5470. (tb (car (last (get-text-property 1 'tags b)))))
  5471. (cond ((not ta) +1)
  5472. ((not tb) -1)
  5473. ((string-lessp ta tb) -1)
  5474. ((string-lessp tb ta) +1)
  5475. (t nil))))
  5476. (defsubst org-cmp-time (a b)
  5477. "Compare the time-of-day values of strings A and B."
  5478. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5479. (ta (or (get-text-property 1 'time-of-day a) def))
  5480. (tb (or (get-text-property 1 'time-of-day b) def)))
  5481. (cond ((< ta tb) -1)
  5482. ((< tb ta) +1)
  5483. (t nil))))
  5484. (defsubst org-cmp-habit-p (a b)
  5485. "Compare the todo states of strings A and B."
  5486. (let ((ha (get-text-property 1 'org-habit-p a))
  5487. (hb (get-text-property 1 'org-habit-p b)))
  5488. (cond ((and ha (not hb)) -1)
  5489. ((and (not ha) hb) +1)
  5490. (t nil))))
  5491. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5492. (defun org-entries-lessp (a b)
  5493. "Predicate for sorting agenda entries."
  5494. ;; The following variables will be used when the form is evaluated.
  5495. ;; So even though the compiler complains, keep them.
  5496. (let* ((ss org-agenda-sorting-strategy-selected)
  5497. (time-up (and (org-em 'time-up 'time-down ss)
  5498. (org-cmp-time a b)))
  5499. (time-down (if time-up (- time-up) nil))
  5500. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5501. (org-cmp-priority a b)))
  5502. (priority-down (if priority-up (- priority-up) nil))
  5503. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5504. (org-cmp-effort a b)))
  5505. (effort-down (if effort-up (- effort-up) nil))
  5506. (category-up (and (or (org-em 'category-up 'category-down ss)
  5507. (memq 'category-keep ss))
  5508. (org-cmp-category a b)))
  5509. (category-down (if category-up (- category-up) nil))
  5510. (category-keep (if category-up +1 nil))
  5511. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5512. (org-cmp-tag a b)))
  5513. (tag-down (if tag-up (- tag-up) nil))
  5514. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5515. (org-cmp-todo-state a b)))
  5516. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5517. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5518. (org-cmp-habit-p a b)))
  5519. (habit-down (if habit-up (- habit-up) nil))
  5520. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5521. (org-cmp-alpha a b)))
  5522. (alpha-down (if alpha-up (- alpha-up) nil))
  5523. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5524. user-defined-up user-defined-down)
  5525. (if (and need-user-cmp org-agenda-cmp-user-defined
  5526. (functionp org-agenda-cmp-user-defined))
  5527. (setq user-defined-up
  5528. (funcall org-agenda-cmp-user-defined a b)
  5529. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5530. (cdr (assoc
  5531. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5532. '((-1 . t) (1 . nil) (nil . nil))))))
  5533. ;;; Agenda restriction lock
  5534. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5535. "Overlay to mark the headline to which agenda commands are restricted.")
  5536. (overlay-put org-agenda-restriction-lock-overlay
  5537. 'face 'org-agenda-restriction-lock)
  5538. (overlay-put org-agenda-restriction-lock-overlay
  5539. 'help-echo "Agendas are currently limited to this subtree.")
  5540. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5541. (defun org-agenda-set-restriction-lock (&optional type)
  5542. "Set restriction lock for agenda, to current subtree or file.
  5543. Restriction will be the file if TYPE is `file', or if type is the
  5544. universal prefix '(4), or if the cursor is before the first headline
  5545. in the file. Otherwise, restriction will be to the current subtree."
  5546. (interactive "P")
  5547. (and (equal type '(4)) (setq type 'file))
  5548. (setq type (cond
  5549. (type type)
  5550. ((org-at-heading-p) 'subtree)
  5551. ((condition-case nil (org-back-to-heading t) (error nil))
  5552. 'subtree)
  5553. (t 'file)))
  5554. (if (eq type 'subtree)
  5555. (progn
  5556. (setq org-agenda-restrict t)
  5557. (setq org-agenda-overriding-restriction 'subtree)
  5558. (put 'org-agenda-files 'org-restrict
  5559. (list (buffer-file-name (buffer-base-buffer))))
  5560. (org-back-to-heading t)
  5561. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5562. (move-marker org-agenda-restrict-begin (point))
  5563. (move-marker org-agenda-restrict-end
  5564. (save-excursion (org-end-of-subtree t)))
  5565. (message "Locking agenda restriction to subtree"))
  5566. (put 'org-agenda-files 'org-restrict
  5567. (list (buffer-file-name (buffer-base-buffer))))
  5568. (setq org-agenda-restrict nil)
  5569. (setq org-agenda-overriding-restriction 'file)
  5570. (move-marker org-agenda-restrict-begin nil)
  5571. (move-marker org-agenda-restrict-end nil)
  5572. (message "Locking agenda restriction to file"))
  5573. (setq current-prefix-arg nil)
  5574. (org-agenda-maybe-redo))
  5575. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5576. "Remove the agenda restriction lock."
  5577. (interactive "P")
  5578. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5579. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5580. (setq org-agenda-overriding-restriction nil)
  5581. (setq org-agenda-restrict nil)
  5582. (put 'org-agenda-files 'org-restrict nil)
  5583. (move-marker org-agenda-restrict-begin nil)
  5584. (move-marker org-agenda-restrict-end nil)
  5585. (setq current-prefix-arg nil)
  5586. (message "Agenda restriction lock removed")
  5587. (or noupdate (org-agenda-maybe-redo)))
  5588. (defun org-agenda-maybe-redo ()
  5589. "If there is any window showing the agenda view, update it."
  5590. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5591. (w0 (selected-window)))
  5592. (when w
  5593. (select-window w)
  5594. (org-agenda-redo)
  5595. (select-window w0)
  5596. (if org-agenda-overriding-restriction
  5597. (message "Agenda view shifted to new %s restriction"
  5598. org-agenda-overriding-restriction)
  5599. (message "Agenda restriction lock removed")))))
  5600. ;;; Agenda commands
  5601. (defun org-agenda-check-type (error &rest types)
  5602. "Check if agenda buffer is of allowed type.
  5603. If ERROR is non-nil, throw an error, otherwise just return nil."
  5604. (if (memq org-agenda-type types)
  5605. t
  5606. (if error
  5607. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5608. nil)))
  5609. (defun org-agenda-quit ()
  5610. "Exit agenda by removing the window or the buffer."
  5611. (interactive)
  5612. (if org-agenda-columns-active
  5613. (org-columns-quit)
  5614. (let ((buf (current-buffer)))
  5615. (if (eq org-agenda-window-setup 'other-frame)
  5616. (progn
  5617. (kill-buffer buf)
  5618. (org-agenda-reset-markers)
  5619. (org-columns-remove-overlays)
  5620. (setq org-agenda-archives-mode nil)
  5621. (delete-frame))
  5622. (and (not (eq org-agenda-window-setup 'current-window))
  5623. (not (one-window-p))
  5624. (delete-window))
  5625. (kill-buffer buf)
  5626. (org-agenda-reset-markers)
  5627. (org-columns-remove-overlays)
  5628. (setq org-agenda-archives-mode nil)))
  5629. ;; Maybe restore the pre-agenda window configuration.
  5630. (and org-agenda-restore-windows-after-quit
  5631. (not (eq org-agenda-window-setup 'other-frame))
  5632. org-pre-agenda-window-conf
  5633. (set-window-configuration org-pre-agenda-window-conf))))
  5634. (defun org-agenda-exit ()
  5635. "Exit agenda by removing the window or the buffer.
  5636. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5637. Org-mode buffers visited directly by the user will not be touched."
  5638. (interactive)
  5639. (org-release-buffers org-agenda-new-buffers)
  5640. (setq org-agenda-new-buffers nil)
  5641. (org-agenda-quit))
  5642. (defun org-agenda-execute (arg)
  5643. "Execute another agenda command, keeping same window.
  5644. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5645. in the agenda."
  5646. (interactive "P")
  5647. (let ((org-agenda-window-setup 'current-window))
  5648. (org-agenda arg)))
  5649. (defun org-agenda-redo ()
  5650. "Rebuild Agenda.
  5651. When this is the global TODO list, a prefix argument will be interpreted."
  5652. (interactive)
  5653. (let* ((org-agenda-keep-modes t)
  5654. (filter org-agenda-filter)
  5655. (preset (get 'org-agenda-filter :preset-filter))
  5656. (org-agenda-filter-while-redo (or filter preset))
  5657. (cols org-agenda-columns-active)
  5658. (line (org-current-line))
  5659. (window-line (- line (org-current-line (window-start))))
  5660. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5661. (put 'org-agenda-filter :preset-filter nil)
  5662. (and cols (org-columns-quit))
  5663. (message "Rebuilding agenda buffer...")
  5664. (org-let lprops '(eval org-agenda-redo-command))
  5665. (setq org-agenda-undo-list nil
  5666. org-agenda-pending-undo-list nil)
  5667. (message "Rebuilding agenda buffer...done")
  5668. (put 'org-agenda-filter :preset-filter preset)
  5669. (and (or filter preset) (org-agenda-filter-apply filter))
  5670. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5671. (org-goto-line line)
  5672. (recenter window-line)))
  5673. (defvar org-global-tags-completion-table nil)
  5674. (defvar org-agenda-filter-form nil)
  5675. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5676. "Keep only those lines in the agenda buffer that have a specific tag.
  5677. The tag is selected with its fast selection letter, as configured.
  5678. With prefix argument STRIP, remove all lines that do have the tag.
  5679. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5680. used to narrow the search - the interactive user can also press `-' or `+'
  5681. to switch to narrowing."
  5682. (interactive "P")
  5683. (let* ((alist org-tag-alist-for-agenda)
  5684. (tag-chars (mapconcat
  5685. (lambda (x) (if (and (not (symbolp (car x)))
  5686. (cdr x))
  5687. (char-to-string (cdr x))
  5688. ""))
  5689. alist ""))
  5690. (efforts (org-split-string
  5691. (or (cdr (assoc (concat org-effort-property "_ALL")
  5692. org-global-properties))
  5693. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5694. "")))
  5695. (effort-op org-agenda-filter-effort-default-operator)
  5696. (effort-prompt "")
  5697. (inhibit-read-only t)
  5698. (current org-agenda-filter)
  5699. maybe-refresh a n tag)
  5700. (unless char
  5701. (message
  5702. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5703. (if narrow "Narrow" "Filter") tag-chars
  5704. (if org-agenda-auto-exclude-function "[RET], " ""))
  5705. (setq char (read-char)))
  5706. (when (member char '(?+ ?-))
  5707. ;; Narrowing down
  5708. (cond ((equal char ?-) (setq strip t narrow t))
  5709. ((equal char ?+) (setq strip nil narrow t)))
  5710. (message
  5711. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5712. (setq char (read-char)))
  5713. (when (member char '(?< ?> ?= ??))
  5714. ;; An effort operator
  5715. (setq effort-op (char-to-string char))
  5716. (setq alist nil) ; to make sure it will be interpreted as effort.
  5717. (unless (equal char ??)
  5718. (loop for i from 0 to 9 do
  5719. (setq effort-prompt
  5720. (concat
  5721. effort-prompt " ["
  5722. (if (= i 9) "0" (int-to-string (1+ i)))
  5723. "]" (nth i efforts))))
  5724. (message "Effort%s: %s " effort-op effort-prompt)
  5725. (setq char (read-char))
  5726. (when (or (< char ?0) (> char ?9))
  5727. (error "Need 1-9,0 to select effort" ))))
  5728. (when (equal char ?\t)
  5729. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5730. (org-set-local 'org-global-tags-completion-table
  5731. (org-global-tags-completion-table)))
  5732. (let ((completion-ignore-case t))
  5733. (setq tag (org-icompleting-read
  5734. "Tag: " org-global-tags-completion-table))))
  5735. (cond
  5736. ((equal char ?\r)
  5737. (org-agenda-filter-by-tag-show-all)
  5738. (when org-agenda-auto-exclude-function
  5739. (setq org-agenda-filter '())
  5740. (dolist (tag (org-agenda-get-represented-tags))
  5741. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5742. (if modifier
  5743. (push modifier org-agenda-filter))))
  5744. (if (not (null org-agenda-filter))
  5745. (org-agenda-filter-apply org-agenda-filter)))
  5746. (setq maybe-refresh t))
  5747. ((equal char ?/)
  5748. (org-agenda-filter-by-tag-show-all)
  5749. (when (get 'org-agenda-filter :preset-filter)
  5750. (org-agenda-filter-apply org-agenda-filter))
  5751. (setq maybe-refresh t))
  5752. ((or (equal char ?\ )
  5753. (setq a (rassoc char alist))
  5754. (and (>= char ?0) (<= char ?9)
  5755. (setq n (if (= char ?0) 9 (- char ?0 1))
  5756. tag (concat effort-op (nth n efforts))
  5757. a (cons tag nil)))
  5758. (and (= char ??)
  5759. (setq tag "?eff")
  5760. a (cons tag nil))
  5761. (and tag (setq a (cons tag nil))))
  5762. (org-agenda-filter-by-tag-show-all)
  5763. (setq tag (car a))
  5764. (setq org-agenda-filter
  5765. (cons (concat (if strip "-" "+") tag)
  5766. (if narrow current nil)))
  5767. (org-agenda-filter-apply org-agenda-filter)
  5768. (setq maybe-refresh t))
  5769. (t (error "Invalid tag selection character %c" char)))
  5770. (when (and maybe-refresh
  5771. (eq org-agenda-clockreport-mode 'with-filter))
  5772. (org-agenda-redo))))
  5773. (defun org-agenda-get-represented-tags ()
  5774. "Get a list of all tags currently represented in the agenda."
  5775. (let (p tags)
  5776. (save-excursion
  5777. (goto-char (point-min))
  5778. (while (setq p (next-single-property-change (point) 'tags))
  5779. (goto-char p)
  5780. (mapc (lambda (x) (add-to-list 'tags x))
  5781. (get-text-property (point) 'tags))))
  5782. tags))
  5783. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5784. "Refine the current filter. See `org-agenda-filter-by-tag."
  5785. (interactive "P")
  5786. (org-agenda-filter-by-tag strip char 'refine))
  5787. (defun org-agenda-filter-make-matcher ()
  5788. "Create the form that tests a line for the agenda filter."
  5789. (let (f f1)
  5790. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5791. org-agenda-filter))
  5792. (if (member x '("-" "+"))
  5793. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5794. (if (string-match "[<=>?]" x)
  5795. (setq f1 (org-agenda-filter-effort-form x))
  5796. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5797. (if (equal (string-to-char x) ?-)
  5798. (setq f1 (list 'not f1))))
  5799. (push f1 f))
  5800. (cons 'and (nreverse f))))
  5801. (defun org-agenda-filter-effort-form (e)
  5802. "Return the form to compare the effort of the current line with what E says.
  5803. E looks like \"+<2:25\"."
  5804. (let (op)
  5805. (setq e (substring e 1))
  5806. (setq op (string-to-char e) e (substring e 1))
  5807. (setq op (cond ((equal op ?<) '<=)
  5808. ((equal op ?>) '>=)
  5809. ((equal op ??) op)
  5810. (t '=)))
  5811. (list 'org-agenda-compare-effort (list 'quote op)
  5812. (org-duration-string-to-minutes e))))
  5813. (defun org-agenda-compare-effort (op value)
  5814. "Compare the effort of the current line with VALUE, using OP.
  5815. If the line does not have an effort defined, return nil."
  5816. (let ((eff (org-get-at-bol 'effort-minutes)))
  5817. (if (equal op ??)
  5818. (not eff)
  5819. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5820. value))))
  5821. (defun org-agenda-filter-apply (filter)
  5822. "Set FILTER as the new agenda filter and apply it."
  5823. (let (tags)
  5824. (setq org-agenda-filter filter
  5825. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5826. (org-agenda-set-mode-name)
  5827. (save-excursion
  5828. (goto-char (point-min))
  5829. (while (not (eobp))
  5830. (if (org-get-at-bol 'org-marker)
  5831. (progn
  5832. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5833. (if (not (eval org-agenda-filter-form))
  5834. (org-agenda-filter-by-tag-hide-line))
  5835. (beginning-of-line 2))
  5836. (beginning-of-line 2))))
  5837. (if (get-char-property (point) 'invisible)
  5838. (org-agenda-previous-line))))
  5839. (defun org-agenda-filter-by-tag-hide-line ()
  5840. (let (ov)
  5841. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5842. (point-at-eol)))
  5843. (overlay-put ov 'invisible t)
  5844. (overlay-put ov 'type 'tags-filter)
  5845. (push ov org-agenda-filter-overlays)))
  5846. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5847. (setq pos (or pos (point)))
  5848. (save-excursion
  5849. (dolist (ov (overlays-at pos))
  5850. (when (and (overlay-get ov 'invisible)
  5851. (eq (overlay-get ov 'type) 'tags-filter))
  5852. (goto-char pos)
  5853. (if (< (overlay-start ov) (point-at-eol))
  5854. (move-overlay ov (point-at-eol)
  5855. (overlay-end ov)))))))
  5856. (defun org-agenda-filter-by-tag-show-all ()
  5857. (mapc 'delete-overlay org-agenda-filter-overlays)
  5858. (setq org-agenda-filter-overlays nil)
  5859. (setq org-agenda-filter nil)
  5860. (setq org-agenda-filter-form nil)
  5861. (org-agenda-set-mode-name))
  5862. (defun org-agenda-manipulate-query-add ()
  5863. "Manipulate the query by adding a search term with positive selection.
  5864. Positive selection means the term must be matched for selection of an entry."
  5865. (interactive)
  5866. (org-agenda-manipulate-query ?\[))
  5867. (defun org-agenda-manipulate-query-subtract ()
  5868. "Manipulate the query by adding a search term with negative selection.
  5869. Negative selection means term must not be matched for selection of an entry."
  5870. (interactive)
  5871. (org-agenda-manipulate-query ?\]))
  5872. (defun org-agenda-manipulate-query-add-re ()
  5873. "Manipulate the query by adding a search regexp with positive selection.
  5874. Positive selection means the regexp must match for selection of an entry."
  5875. (interactive)
  5876. (org-agenda-manipulate-query ?\{))
  5877. (defun org-agenda-manipulate-query-subtract-re ()
  5878. "Manipulate the query by adding a search regexp with negative selection.
  5879. Negative selection means regexp must not match for selection of an entry."
  5880. (interactive)
  5881. (org-agenda-manipulate-query ?\}))
  5882. (defun org-agenda-manipulate-query (char)
  5883. (cond
  5884. ((memq org-agenda-type '(timeline agenda))
  5885. (let ((org-agenda-include-inactive-timestamps t))
  5886. (org-agenda-redo))
  5887. (message "Display now includes inactive timestamps as well"))
  5888. ((eq org-agenda-type 'search)
  5889. (org-add-to-string
  5890. 'org-agenda-query-string
  5891. (if org-agenda-last-search-view-search-was-boolean
  5892. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5893. (?\{ . " +{}") (?\} . " -{}"))))
  5894. " "))
  5895. (setq org-agenda-redo-command
  5896. (list 'org-search-view
  5897. org-todo-only
  5898. org-agenda-query-string
  5899. (+ (length org-agenda-query-string)
  5900. (if (member char '(?\{ ?\})) 0 1))))
  5901. (set-register org-agenda-query-register org-agenda-query-string)
  5902. (org-agenda-redo))
  5903. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5904. org-agenda-type))))
  5905. (defun org-add-to-string (var string)
  5906. (set var (concat (symbol-value var) string)))
  5907. (defun org-agenda-goto-date (date)
  5908. "Jump to DATE in agenda."
  5909. (interactive (list (let ((org-read-date-prefer-future
  5910. (eval org-agenda-jump-prefer-future)))
  5911. (org-read-date))))
  5912. (org-agenda-list nil date))
  5913. (defun org-agenda-goto-today ()
  5914. "Go to today."
  5915. (interactive)
  5916. (org-agenda-check-type t 'timeline 'agenda)
  5917. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5918. (cond
  5919. (tdpos (goto-char tdpos))
  5920. ((eq org-agenda-type 'agenda)
  5921. (let* ((sd (org-agenda-compute-starting-span
  5922. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5923. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5924. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5925. (org-agenda-redo)
  5926. (org-agenda-find-same-or-today-or-agenda)))
  5927. (t (error "Cannot find today")))))
  5928. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5929. (goto-char
  5930. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5931. (text-property-any (point-min) (point-max) 'org-today t)
  5932. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5933. (point-min))))
  5934. (defun org-agenda-later (arg)
  5935. "Go forward in time by thee current span.
  5936. With prefix ARG, go forward that many times the current span."
  5937. (interactive "p")
  5938. (org-agenda-check-type t 'agenda)
  5939. (let* ((span org-agenda-current-span)
  5940. (sd org-starting-day)
  5941. (greg (calendar-gregorian-from-absolute sd))
  5942. (cnt (org-get-at-bol 'org-day-cnt))
  5943. greg2)
  5944. (cond
  5945. ((eq span 'day)
  5946. (setq sd (+ arg sd)))
  5947. ((eq span 'week)
  5948. (setq sd (+ (* 7 arg) sd)))
  5949. ((eq span 'month)
  5950. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5951. sd (calendar-absolute-from-gregorian greg2))
  5952. (setcar greg2 (1+ (car greg2))))
  5953. ((eq span 'year)
  5954. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5955. sd (calendar-absolute-from-gregorian greg2))
  5956. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5957. (t
  5958. (setq sd (+ (* span arg) sd))))
  5959. (let ((org-agenda-overriding-arguments
  5960. (list (car org-agenda-last-arguments) sd span t)))
  5961. (org-agenda-redo)
  5962. (org-agenda-find-same-or-today-or-agenda cnt))))
  5963. (defun org-agenda-earlier (arg)
  5964. "Go backward in time by the current span.
  5965. With prefix ARG, go backward that many times the current span."
  5966. (interactive "p")
  5967. (org-agenda-later (- arg)))
  5968. (defun org-agenda-view-mode-dispatch ()
  5969. "Call one of the view mode commands."
  5970. (interactive)
  5971. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5972. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5973. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5974. [E]ntryText")
  5975. (let ((a (read-char-exclusive)))
  5976. (case a
  5977. (?\ (call-interactively 'org-agenda-reset-view))
  5978. (?d (call-interactively 'org-agenda-day-view))
  5979. (?w (call-interactively 'org-agenda-week-view))
  5980. (?m (call-interactively 'org-agenda-month-view))
  5981. (?y (call-interactively 'org-agenda-year-view))
  5982. (?l (call-interactively 'org-agenda-log-mode))
  5983. (?L (org-agenda-log-mode '(4)))
  5984. (?c (org-agenda-log-mode 'clockcheck))
  5985. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5986. (?a (call-interactively 'org-agenda-archives-mode))
  5987. (?A (org-agenda-archives-mode 'files))
  5988. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5989. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5990. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5991. (?D (call-interactively 'org-agenda-toggle-diary))
  5992. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5993. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5994. (org-agenda-check-type t 'timeline 'agenda)
  5995. (org-agenda-redo))
  5996. (message "Display now includes inactive timestamps as well"))
  5997. (?q (message "Abort"))
  5998. (otherwise (error "Invalid key" )))))
  5999. (defun org-agenda-reset-view ()
  6000. "Switch to default view for agenda."
  6001. (interactive)
  6002. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6003. (defun org-agenda-day-view (&optional day-of-year)
  6004. "Switch to daily view for agenda.
  6005. With argument DAY-OF-YEAR, switch to that day of the year."
  6006. (interactive "P")
  6007. (org-agenda-change-time-span 'day day-of-year))
  6008. (defun org-agenda-week-view (&optional iso-week)
  6009. "Switch to daily view for agenda.
  6010. With argument ISO-WEEK, switch to the corresponding ISO week.
  6011. If ISO-WEEK has more then 2 digits, only the last two encode the
  6012. week. Any digits before this encode a year. So 200712 means
  6013. week 12 of year 2007. Years in the range 1938-2037 can also be
  6014. written as 2-digit years."
  6015. (interactive "P")
  6016. (org-agenda-change-time-span 'week iso-week))
  6017. (defun org-agenda-month-view (&optional month)
  6018. "Switch to monthly view for agenda.
  6019. With argument MONTH, switch to that month."
  6020. (interactive "P")
  6021. (org-agenda-change-time-span 'month month))
  6022. (defun org-agenda-year-view (&optional year)
  6023. "Switch to yearly view for agenda.
  6024. With argument YEAR, switch to that year.
  6025. If MONTH has more then 2 digits, only the last two encode the
  6026. month. Any digits before this encode a year. So 200712 means
  6027. December year 2007. Years in the range 1938-2037 can also be
  6028. written as 2-digit years."
  6029. (interactive "P")
  6030. (when year
  6031. (setq year (org-small-year-to-year year)))
  6032. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6033. (org-agenda-change-time-span 'year year)
  6034. (error "Abort")))
  6035. (defun org-agenda-change-time-span (span &optional n)
  6036. "Change the agenda view to SPAN.
  6037. SPAN may be `day', `week', `month', `year'."
  6038. (org-agenda-check-type t 'agenda)
  6039. (if (and (not n) (equal org-agenda-current-span span))
  6040. (error "Viewing span is already \"%s\"" span))
  6041. (let* ((sd (or (org-get-at-bol 'day)
  6042. org-starting-day))
  6043. (sd (org-agenda-compute-starting-span sd span n))
  6044. (org-agenda-overriding-arguments
  6045. (or org-agenda-overriding-arguments
  6046. (list (car org-agenda-last-arguments) sd span t))))
  6047. (org-agenda-redo)
  6048. (org-agenda-find-same-or-today-or-agenda))
  6049. (org-agenda-set-mode-name)
  6050. (message "Switched to %s view" span))
  6051. (defun org-agenda-compute-starting-span (sd span &optional n)
  6052. "Compute starting date for agenda.
  6053. SPAN may be `day', `week', `month', `year'. The return value
  6054. is a cons cell with the starting date and the number of days,
  6055. so that the date SD will be in that range."
  6056. (let* ((greg (calendar-gregorian-from-absolute sd))
  6057. (dg (nth 1 greg))
  6058. (mg (car greg))
  6059. (yg (nth 2 greg)))
  6060. (cond
  6061. ((eq span 'day)
  6062. (when n
  6063. (setq sd (+ (calendar-absolute-from-gregorian
  6064. (list mg 1 yg))
  6065. n -1))))
  6066. ((eq span 'week)
  6067. (let* ((nt (calendar-day-of-week
  6068. (calendar-gregorian-from-absolute sd)))
  6069. (d (if org-agenda-start-on-weekday
  6070. (- nt org-agenda-start-on-weekday)
  6071. 0))
  6072. y1)
  6073. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6074. (when n
  6075. (require 'cal-iso)
  6076. (when (> n 99)
  6077. (setq y1 (org-small-year-to-year (/ n 100))
  6078. n (mod n 100)))
  6079. (setq sd
  6080. (calendar-absolute-from-iso
  6081. (list n 1
  6082. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6083. ((eq span 'month)
  6084. (let (y1)
  6085. (when (and n (> n 99))
  6086. (setq y1 (org-small-year-to-year (/ n 100))
  6087. n (mod n 100)))
  6088. (setq sd (calendar-absolute-from-gregorian
  6089. (list (or n mg) 1 (or y1 yg))))))
  6090. ((eq span 'year)
  6091. (setq sd (calendar-absolute-from-gregorian
  6092. (list 1 1 (or n yg))))))
  6093. sd))
  6094. (defun org-agenda-next-date-line (&optional arg)
  6095. "Jump to the next line indicating a date in agenda buffer."
  6096. (interactive "p")
  6097. (org-agenda-check-type t 'agenda 'timeline)
  6098. (beginning-of-line 1)
  6099. ;; This does not work if user makes date format that starts with a blank
  6100. (if (looking-at "^\\S-") (forward-char 1))
  6101. (if (not (re-search-forward "^\\S-" nil t arg))
  6102. (progn
  6103. (backward-char 1)
  6104. (error "No next date after this line in this buffer")))
  6105. (goto-char (match-beginning 0)))
  6106. (defun org-agenda-previous-date-line (&optional arg)
  6107. "Jump to the previous line indicating a date in agenda buffer."
  6108. (interactive "p")
  6109. (org-agenda-check-type t 'agenda 'timeline)
  6110. (beginning-of-line 1)
  6111. (if (not (re-search-backward "^\\S-" nil t arg))
  6112. (error "No previous date before this line in this buffer")))
  6113. ;; Initialize the highlight
  6114. (defvar org-hl (make-overlay 1 1))
  6115. (overlay-put org-hl 'face 'highlight)
  6116. (defun org-highlight (begin end &optional buffer)
  6117. "Highlight a region with overlay."
  6118. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6119. (defun org-unhighlight ()
  6120. "Detach overlay INDEX."
  6121. (org-detach-overlay org-hl))
  6122. ;; FIXME this is currently not used.
  6123. (defun org-highlight-until-next-command (beg end &optional buffer)
  6124. "Move the highlight overlay to BEG/END, remove it before the next command."
  6125. (org-highlight beg end buffer)
  6126. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6127. (defun org-unhighlight-once ()
  6128. "Remove the highlight from its position, and this function from the hook."
  6129. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6130. (org-unhighlight))
  6131. (defun org-agenda-follow-mode ()
  6132. "Toggle follow mode in an agenda buffer."
  6133. (interactive)
  6134. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6135. (org-agenda-set-mode-name)
  6136. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6137. (org-agenda-show))
  6138. (message "Follow mode is %s"
  6139. (if org-agenda-follow-mode "on" "off")))
  6140. (defun org-agenda-entry-text-mode (&optional arg)
  6141. "Toggle entry text mode in an agenda buffer."
  6142. (interactive "P")
  6143. (setq org-agenda-entry-text-mode (or (integerp arg)
  6144. (not org-agenda-entry-text-mode)))
  6145. (org-agenda-entry-text-hide)
  6146. (and org-agenda-entry-text-mode
  6147. (let ((org-agenda-entry-text-maxlines
  6148. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6149. (org-agenda-entry-text-show)))
  6150. (org-agenda-set-mode-name)
  6151. (message "Entry text mode is %s. Maximum number of lines is %d"
  6152. (if org-agenda-entry-text-mode "on" "off")
  6153. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6154. (defun org-agenda-clockreport-mode (&optional with-filter)
  6155. "Toggle clocktable mode in an agenda buffer.
  6156. With prefix arg WITH-FILTER, make the clocktable respect the current
  6157. agenda filter."
  6158. (interactive "P")
  6159. (org-agenda-check-type t 'agenda)
  6160. (if with-filter
  6161. (setq org-agenda-clockreport-mode 'with-filter)
  6162. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6163. (org-agenda-set-mode-name)
  6164. (org-agenda-redo)
  6165. (message "Clocktable mode is %s"
  6166. (if org-agenda-clockreport-mode "on" "off")))
  6167. (defun org-agenda-log-mode (&optional special)
  6168. "Toggle log mode in an agenda buffer.
  6169. With argument SPECIAL, show all possible log items, not only the ones
  6170. configured in `org-agenda-log-mode-items'.
  6171. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6172. (interactive "P")
  6173. (org-agenda-check-type t 'agenda 'timeline)
  6174. (setq org-agenda-show-log
  6175. (cond
  6176. ((equal special '(16)) 'only)
  6177. ((eq special 'clockcheck)
  6178. (if (eq org-agenda-show-log 'clockcheck)
  6179. nil 'clockcheck))
  6180. (special '(closed clock state))
  6181. (t (not org-agenda-show-log))))
  6182. (org-agenda-set-mode-name)
  6183. (org-agenda-redo)
  6184. (message "Log mode is %s"
  6185. (if org-agenda-show-log "on" "off")))
  6186. (defun org-agenda-archives-mode (&optional with-files)
  6187. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6188. When called with a prefix argument, include all archive files as well."
  6189. (interactive "P")
  6190. (setq org-agenda-archives-mode
  6191. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6192. (org-agenda-set-mode-name)
  6193. (org-agenda-redo)
  6194. (message
  6195. "%s"
  6196. (cond
  6197. ((eq org-agenda-archives-mode nil)
  6198. "No archives are included")
  6199. ((eq org-agenda-archives-mode 'trees)
  6200. (format "Trees with :%s: tag are included" org-archive-tag))
  6201. ((eq org-agenda-archives-mode t)
  6202. (format "Trees with :%s: tag and all active archive files are included"
  6203. org-archive-tag)))))
  6204. (defun org-agenda-toggle-diary ()
  6205. "Toggle diary inclusion in an agenda buffer."
  6206. (interactive)
  6207. (org-agenda-check-type t 'agenda)
  6208. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6209. (org-agenda-redo)
  6210. (org-agenda-set-mode-name)
  6211. (message "Diary inclusion turned %s"
  6212. (if org-agenda-include-diary "on" "off")))
  6213. (defun org-agenda-toggle-deadlines ()
  6214. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6215. (interactive)
  6216. (org-agenda-check-type t 'agenda)
  6217. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6218. (org-agenda-redo)
  6219. (org-agenda-set-mode-name)
  6220. (message "Deadlines inclusion turned %s"
  6221. (if org-agenda-include-deadlines "on" "off")))
  6222. (defun org-agenda-toggle-time-grid ()
  6223. "Toggle time grid in an agenda buffer."
  6224. (interactive)
  6225. (org-agenda-check-type t 'agenda)
  6226. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6227. (org-agenda-redo)
  6228. (org-agenda-set-mode-name)
  6229. (message "Time-grid turned %s"
  6230. (if org-agenda-use-time-grid "on" "off")))
  6231. (defun org-agenda-set-mode-name ()
  6232. "Set the mode name to indicate all the small mode settings."
  6233. (setq mode-name
  6234. (list "Org-Agenda"
  6235. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6236. " "
  6237. '(:eval (org-agenda-span-name org-agenda-current-span))
  6238. (if org-agenda-follow-mode " Follow" "")
  6239. (if org-agenda-entry-text-mode " ETxt" "")
  6240. (if org-agenda-include-diary " Diary" "")
  6241. (if org-agenda-include-deadlines " Ddl" "")
  6242. (if org-agenda-use-time-grid " Grid" "")
  6243. (if (and (boundp 'org-habit-show-habits)
  6244. org-habit-show-habits) " Habit" "")
  6245. (cond
  6246. ((consp org-agenda-show-log) " LogAll")
  6247. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6248. (org-agenda-show-log " Log")
  6249. (t ""))
  6250. (if (or org-agenda-filter (get 'org-agenda-filter
  6251. :preset-filter))
  6252. (concat " {" (mapconcat
  6253. 'identity
  6254. (append (get 'org-agenda-filter
  6255. :preset-filter)
  6256. org-agenda-filter) "") "}")
  6257. "")
  6258. (if org-agenda-archives-mode
  6259. (if (eq org-agenda-archives-mode t)
  6260. " Archives"
  6261. (format " :%s:" org-archive-tag))
  6262. "")
  6263. (if org-agenda-clockreport-mode
  6264. (if (eq org-agenda-clockreport-mode 'with-filter)
  6265. " Clock{}" " Clock")
  6266. "")))
  6267. (force-mode-line-update))
  6268. (defun org-agenda-post-command-hook ()
  6269. (setq org-agenda-type
  6270. (or (get-text-property (point) 'org-agenda-type)
  6271. (get-text-property (max (point-min) (1- (point)))
  6272. 'org-agenda-type))))
  6273. (defun org-agenda-next-line ()
  6274. "Move cursor to the next line, and show if follow mode is active."
  6275. (interactive)
  6276. (call-interactively 'next-line)
  6277. (org-agenda-do-context-action))
  6278. (defun org-agenda-previous-line ()
  6279. "Move cursor to the previous line, and show if follow-mode is active."
  6280. (interactive)
  6281. (call-interactively 'previous-line)
  6282. (org-agenda-do-context-action))
  6283. (defun org-agenda-do-context-action ()
  6284. "Show outline path and, maybe, follow mode window."
  6285. (let ((m (org-get-at-bol 'org-marker)))
  6286. (if (and org-agenda-follow-mode m)
  6287. (org-agenda-show))
  6288. (if (and m org-agenda-show-outline-path)
  6289. (org-with-point-at m
  6290. (org-display-outline-path t)))))
  6291. (defun org-agenda-show-priority ()
  6292. "Show the priority of the current item.
  6293. This priority is composed of the main priority given with the [#A] cookies,
  6294. and by additional input from the age of a schedules or deadline entry."
  6295. (interactive)
  6296. (let* ((pri (org-get-at-bol 'priority)))
  6297. (message "Priority is %d" (if pri pri -1000))))
  6298. (defun org-agenda-show-tags ()
  6299. "Show the tags applicable to the current item."
  6300. (interactive)
  6301. (let* ((tags (org-get-at-bol 'tags)))
  6302. (if tags
  6303. (message "Tags are :%s:"
  6304. (org-no-properties (mapconcat 'identity tags ":")))
  6305. (message "No tags associated with this line"))))
  6306. (defun org-agenda-goto (&optional highlight)
  6307. "Go to the Org-mode file which contains the item at point."
  6308. (interactive)
  6309. (let* ((marker (or (org-get-at-bol 'org-marker)
  6310. (org-agenda-error)))
  6311. (buffer (marker-buffer marker))
  6312. (pos (marker-position marker)))
  6313. (switch-to-buffer-other-window buffer)
  6314. (widen)
  6315. (push-mark)
  6316. (goto-char pos)
  6317. (when (org-mode-p)
  6318. (org-show-context 'agenda)
  6319. (save-excursion
  6320. (and (outline-next-heading)
  6321. (org-flag-heading nil)))) ; show the next heading
  6322. (when (outline-invisible-p)
  6323. (show-entry)) ; display invisible text
  6324. (recenter (/ (window-height) 2))
  6325. (run-hooks 'org-agenda-after-show-hook)
  6326. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6327. (defvar org-agenda-after-show-hook nil
  6328. "Normal hook run after an item has been shown from the agenda.
  6329. Point is in the buffer where the item originated.")
  6330. (defun org-agenda-kill ()
  6331. "Kill the entry or subtree belonging to the current agenda entry."
  6332. (interactive)
  6333. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6334. (let* ((marker (or (org-get-at-bol 'org-marker)
  6335. (org-agenda-error)))
  6336. (buffer (marker-buffer marker))
  6337. (pos (marker-position marker))
  6338. (type (org-get-at-bol 'type))
  6339. dbeg dend (n 0) conf)
  6340. (org-with-remote-undo buffer
  6341. (with-current-buffer buffer
  6342. (save-excursion
  6343. (goto-char pos)
  6344. (if (and (org-mode-p) (not (member type '("sexp"))))
  6345. (setq dbeg (progn (org-back-to-heading t) (point))
  6346. dend (org-end-of-subtree t t))
  6347. (setq dbeg (point-at-bol)
  6348. dend (min (point-max) (1+ (point-at-eol)))))
  6349. (goto-char dbeg)
  6350. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6351. (setq conf (or (eq t org-agenda-confirm-kill)
  6352. (and (numberp org-agenda-confirm-kill)
  6353. (> n org-agenda-confirm-kill))))
  6354. (and conf
  6355. (not (y-or-n-p
  6356. (format "Delete entry with %d lines in buffer \"%s\"? "
  6357. n (buffer-name buffer))))
  6358. (error "Abort"))
  6359. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6360. (with-current-buffer buffer (delete-region dbeg dend))
  6361. (message "Agenda item and source killed"))))
  6362. (defvar org-archive-default-command)
  6363. (defun org-agenda-archive-default ()
  6364. "Archive the entry or subtree belonging to the current agenda entry."
  6365. (interactive)
  6366. (require 'org-archive)
  6367. (org-agenda-archive-with org-archive-default-command))
  6368. (defun org-agenda-archive-default-with-confirmation ()
  6369. "Archive the entry or subtree belonging to the current agenda entry."
  6370. (interactive)
  6371. (require 'org-archive)
  6372. (org-agenda-archive-with org-archive-default-command 'confirm))
  6373. (defun org-agenda-archive ()
  6374. "Archive the entry or subtree belonging to the current agenda entry."
  6375. (interactive)
  6376. (org-agenda-archive-with 'org-archive-subtree))
  6377. (defun org-agenda-archive-to-archive-sibling ()
  6378. "Move the entry to the archive sibling."
  6379. (interactive)
  6380. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6381. (defun org-agenda-archive-with (cmd &optional confirm)
  6382. "Move the entry to the archive sibling."
  6383. (interactive)
  6384. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6385. (let* ((marker (or (org-get-at-bol 'org-marker)
  6386. (org-agenda-error)))
  6387. (buffer (marker-buffer marker))
  6388. (pos (marker-position marker)))
  6389. (org-with-remote-undo buffer
  6390. (with-current-buffer buffer
  6391. (if (org-mode-p)
  6392. (if (and confirm
  6393. (not (y-or-n-p "Archive this subtree or entry? ")))
  6394. (error "Abort")
  6395. (save-excursion
  6396. (goto-char pos)
  6397. (org-remove-subtree-entries-from-agenda)
  6398. (org-back-to-heading t)
  6399. (funcall cmd)))
  6400. (error "Archiving works only in Org-mode files"))))))
  6401. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6402. "Remove all lines in the agenda that correspond to a given subtree.
  6403. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6404. If this information is not given, the function uses the tree at point."
  6405. (let ((buf (or buf (current-buffer))) m p)
  6406. (save-excursion
  6407. (unless (and beg end)
  6408. (org-back-to-heading t)
  6409. (setq beg (point))
  6410. (org-end-of-subtree t)
  6411. (setq end (point)))
  6412. (set-buffer (get-buffer org-agenda-buffer-name))
  6413. (save-excursion
  6414. (goto-char (point-max))
  6415. (beginning-of-line 1)
  6416. (while (not (bobp))
  6417. (when (and (setq m (org-get-at-bol 'org-marker))
  6418. (equal buf (marker-buffer m))
  6419. (setq p (marker-position m))
  6420. (>= p beg)
  6421. (< p end))
  6422. (let ((inhibit-read-only t))
  6423. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6424. (beginning-of-line 0))))))
  6425. (defun org-agenda-refile (&optional goto rfloc no-update)
  6426. "Refile the item at point."
  6427. (interactive "P")
  6428. (if (equal goto '(16))
  6429. (org-refile-goto-last-stored)
  6430. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6431. (org-agenda-error)))
  6432. (buffer (marker-buffer marker))
  6433. (pos (marker-position marker))
  6434. (rfloc (or rfloc
  6435. (org-refile-get-location
  6436. (if goto "Goto" "Refile to") buffer
  6437. org-refile-allow-creating-parent-nodes))))
  6438. (with-current-buffer buffer
  6439. (save-excursion
  6440. (save-restriction
  6441. (widen)
  6442. (goto-char marker)
  6443. (org-remove-subtree-entries-from-agenda)
  6444. (org-refile goto buffer rfloc)))))
  6445. (unless no-update (org-agenda-redo))))
  6446. (defun org-agenda-open-link (&optional arg)
  6447. "Follow the link in the current line, if any.
  6448. This looks for a link in the displayed line in the agenda. It also looks
  6449. at the text of the entry itself."
  6450. (interactive "P")
  6451. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6452. (org-get-at-bol 'org-marker)))
  6453. (buffer (and marker (marker-buffer marker)))
  6454. (prefix (buffer-substring
  6455. (point-at-bol) (point-at-eol))))
  6456. (cond
  6457. (buffer
  6458. (with-current-buffer buffer
  6459. (save-excursion
  6460. (save-restriction
  6461. (widen)
  6462. (goto-char marker)
  6463. (org-offer-links-in-entry arg prefix)))))
  6464. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6465. (save-excursion
  6466. (beginning-of-line 1)
  6467. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6468. (org-open-link-from-string (match-string 1)))
  6469. (t (error "No link to open here")))))
  6470. (defun org-agenda-copy-local-variable (var)
  6471. "Get a variable from a referenced buffer and install it here."
  6472. (let ((m (org-get-at-bol 'org-marker)))
  6473. (when (and m (buffer-live-p (marker-buffer m)))
  6474. (org-set-local var (with-current-buffer (marker-buffer m)
  6475. (symbol-value var))))))
  6476. (defun org-agenda-switch-to (&optional delete-other-windows)
  6477. "Go to the Org-mode file which contains the item at point."
  6478. (interactive)
  6479. (if (and org-return-follows-link
  6480. (not (org-get-at-bol 'org-marker))
  6481. (org-in-regexp org-bracket-link-regexp))
  6482. (org-open-link-from-string (match-string 0))
  6483. (let* ((marker (or (org-get-at-bol 'org-marker)
  6484. (org-agenda-error)))
  6485. (buffer (marker-buffer marker))
  6486. (pos (marker-position marker)))
  6487. (org-pop-to-buffer-same-window buffer)
  6488. (and delete-other-windows (delete-other-windows))
  6489. (widen)
  6490. (goto-char pos)
  6491. (when (org-mode-p)
  6492. (org-show-context 'agenda)
  6493. (save-excursion
  6494. (and (outline-next-heading)
  6495. (org-flag-heading nil))) ; show the next heading
  6496. (when (outline-invisible-p)
  6497. (show-entry)))))) ; display invisible text
  6498. (defun org-agenda-goto-mouse (ev)
  6499. "Go to the Org-mode file which contains the item at the mouse click."
  6500. (interactive "e")
  6501. (mouse-set-point ev)
  6502. (org-agenda-goto))
  6503. (defun org-agenda-show (&optional full-entry)
  6504. "Display the Org-mode file which contains the item at point.
  6505. With prefix argument FULL-ENTRY, make the entire entry visible
  6506. if it was hidden in the outline."
  6507. (interactive "P")
  6508. (let ((win (selected-window)))
  6509. (if full-entry
  6510. (let ((org-show-entry-below t))
  6511. (org-agenda-goto t))
  6512. (org-agenda-goto t))
  6513. (select-window win)))
  6514. (defvar org-agenda-show-window nil)
  6515. (defun org-agenda-show-and-scroll-up ()
  6516. "Display the Org-mode file which contains the item at point.
  6517. When called repeatedly, scroll the window that is displaying the buffer."
  6518. (interactive)
  6519. (let ((win (selected-window)))
  6520. (if (and (window-live-p org-agenda-show-window)
  6521. (eq this-command last-command))
  6522. (progn
  6523. (select-window org-agenda-show-window)
  6524. (ignore-errors (scroll-up)))
  6525. (org-agenda-goto t)
  6526. (show-subtree)
  6527. (setq org-agenda-show-window (selected-window)))
  6528. (select-window win)))
  6529. (defun org-agenda-show-scroll-down ()
  6530. "Scroll down the window showing the agenda."
  6531. (interactive)
  6532. (let ((win (selected-window)))
  6533. (when (window-live-p org-agenda-show-window)
  6534. (select-window org-agenda-show-window)
  6535. (ignore-errors (scroll-down))
  6536. (select-window win))))
  6537. (defun org-agenda-show-1 (&optional more)
  6538. "Display the Org-mode file which contains the item at point.
  6539. The prefix arg selects the amount of information to display:
  6540. 0 hide the subtree
  6541. 1 just show the entry according to defaults.
  6542. 2 show the children view
  6543. 3 show the subtree view
  6544. 4 show the entire subtree and any LOGBOOK drawers
  6545. 5 show the entire subtree and any drawers
  6546. With prefix argument FULL-ENTRY, make the entire entry visible
  6547. if it was hidden in the outline."
  6548. (interactive "p")
  6549. (let ((win (selected-window)))
  6550. (org-agenda-goto t)
  6551. (org-recenter-heading 1)
  6552. (cond
  6553. ((= more 0)
  6554. (hide-subtree)
  6555. (save-excursion
  6556. (org-back-to-heading)
  6557. (run-hook-with-args 'org-cycle-hook 'folded))
  6558. (message "Remote: FOLDED"))
  6559. ((and (org-called-interactively-p 'any) (= more 1))
  6560. (message "Remote: show with default settings"))
  6561. ((= more 2)
  6562. (show-entry)
  6563. (show-children)
  6564. (save-excursion
  6565. (org-back-to-heading)
  6566. (run-hook-with-args 'org-cycle-hook 'children))
  6567. (message "Remote: CHILDREN"))
  6568. ((= more 3)
  6569. (show-subtree)
  6570. (save-excursion
  6571. (org-back-to-heading)
  6572. (run-hook-with-args 'org-cycle-hook 'subtree))
  6573. (message "Remote: SUBTREE"))
  6574. ((= more 4)
  6575. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6576. (org-drawer-regexp
  6577. (concat "^[ \t]*:\\("
  6578. (mapconcat 'regexp-quote org-drawers "\\|")
  6579. "\\):[ \t]*$")))
  6580. (show-subtree)
  6581. (save-excursion
  6582. (org-back-to-heading)
  6583. (org-cycle-hide-drawers 'subtree)))
  6584. (message "Remote: SUBTREE AND LOGBOOK"))
  6585. ((> more 4)
  6586. (show-subtree)
  6587. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6588. (select-window win)))
  6589. (defun org-recenter-heading (n)
  6590. (save-excursion
  6591. (org-back-to-heading)
  6592. (recenter n)))
  6593. (defvar org-agenda-cycle-counter nil)
  6594. (defun org-agenda-cycle-show (&optional n)
  6595. "Show the current entry in another window, with default settings.
  6596. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6597. When use repeatedly in immediate succession, the remote entry will cycle
  6598. through visibility
  6599. children -> subtree -> folded
  6600. When called with a numeric prefix arg, that arg will be passed through to
  6601. `org-agenda-show-1'. For the interpretation of that argument, see the
  6602. docstring of `org-agenda-show-1'."
  6603. (interactive "P")
  6604. (if (integerp n)
  6605. (setq org-agenda-cycle-counter n)
  6606. (if (not (eq last-command this-command))
  6607. (setq org-agenda-cycle-counter 1)
  6608. (if (equal org-agenda-cycle-counter 0)
  6609. (setq org-agenda-cycle-counter 2)
  6610. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6611. (if (> org-agenda-cycle-counter 3)
  6612. (setq org-agenda-cycle-counter 0)))))
  6613. (org-agenda-show-1 org-agenda-cycle-counter))
  6614. (defun org-agenda-recenter (arg)
  6615. "Display the Org-mode file which contains the item at point and recenter."
  6616. (interactive "P")
  6617. (let ((win (selected-window)))
  6618. (org-agenda-goto t)
  6619. (recenter arg)
  6620. (select-window win)))
  6621. (defun org-agenda-show-mouse (ev)
  6622. "Display the Org-mode file which contains the item at the mouse click."
  6623. (interactive "e")
  6624. (mouse-set-point ev)
  6625. (org-agenda-show))
  6626. (defun org-agenda-check-no-diary ()
  6627. "Check if the entry is a diary link and abort if yes."
  6628. (if (org-get-at-bol 'org-agenda-diary-link)
  6629. (org-agenda-error)))
  6630. (defun org-agenda-error ()
  6631. (error "Command not allowed in this line"))
  6632. (defun org-agenda-tree-to-indirect-buffer ()
  6633. "Show the subtree corresponding to the current entry in an indirect buffer.
  6634. This calls the command `org-tree-to-indirect-buffer' from the original
  6635. Org-mode buffer.
  6636. With numerical prefix arg ARG, go up to this level and then take that tree.
  6637. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6638. use the dedicated frame)."
  6639. (interactive)
  6640. (org-agenda-check-no-diary)
  6641. (let* ((marker (or (org-get-at-bol 'org-marker)
  6642. (org-agenda-error)))
  6643. (buffer (marker-buffer marker))
  6644. (pos (marker-position marker)))
  6645. (with-current-buffer buffer
  6646. (save-excursion
  6647. (goto-char pos)
  6648. (call-interactively 'org-tree-to-indirect-buffer)))))
  6649. (defvar org-last-heading-marker (make-marker)
  6650. "Marker pointing to the headline that last changed its TODO state
  6651. by a remote command from the agenda.")
  6652. (defun org-agenda-todo-nextset ()
  6653. "Switch TODO entry to next sequence."
  6654. (interactive)
  6655. (org-agenda-todo 'nextset))
  6656. (defun org-agenda-todo-previousset ()
  6657. "Switch TODO entry to previous sequence."
  6658. (interactive)
  6659. (org-agenda-todo 'previousset))
  6660. (defun org-agenda-todo (&optional arg)
  6661. "Cycle TODO state of line at point, also in Org-mode file.
  6662. This changes the line at point, all other lines in the agenda referring to
  6663. the same tree node, and the headline of the tree node in the Org-mode file."
  6664. (interactive "P")
  6665. (org-agenda-check-no-diary)
  6666. (let* ((col (current-column))
  6667. (marker (or (org-get-at-bol 'org-marker)
  6668. (org-agenda-error)))
  6669. (buffer (marker-buffer marker))
  6670. (pos (marker-position marker))
  6671. (hdmarker (org-get-at-bol 'org-hd-marker))
  6672. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6673. (inhibit-read-only t)
  6674. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6675. (org-with-remote-undo buffer
  6676. (with-current-buffer buffer
  6677. (widen)
  6678. (goto-char pos)
  6679. (org-show-context 'agenda)
  6680. (save-excursion
  6681. (and (outline-next-heading)
  6682. (org-flag-heading nil))) ; show the next heading
  6683. (let ((current-prefix-arg arg))
  6684. (call-interactively 'org-todo))
  6685. (and (bolp) (forward-char 1))
  6686. (setq newhead (org-get-heading))
  6687. (when (and (org-bound-and-true-p
  6688. org-agenda-headline-snapshot-before-repeat)
  6689. (not (equal org-agenda-headline-snapshot-before-repeat
  6690. newhead))
  6691. todayp)
  6692. (setq newhead org-agenda-headline-snapshot-before-repeat
  6693. just-one t))
  6694. (save-excursion
  6695. (org-back-to-heading)
  6696. (move-marker org-last-heading-marker (point))))
  6697. (beginning-of-line 1)
  6698. (save-excursion
  6699. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6700. (org-move-to-column col))))
  6701. (defun org-agenda-add-note (&optional arg)
  6702. "Add a time-stamped note to the entry at point."
  6703. (interactive "P")
  6704. (org-agenda-check-no-diary)
  6705. (let* ((marker (or (org-get-at-bol 'org-marker)
  6706. (org-agenda-error)))
  6707. (buffer (marker-buffer marker))
  6708. (pos (marker-position marker))
  6709. (hdmarker (org-get-at-bol 'org-hd-marker))
  6710. (inhibit-read-only t))
  6711. (with-current-buffer buffer
  6712. (widen)
  6713. (goto-char pos)
  6714. (org-show-context 'agenda)
  6715. (save-excursion
  6716. (and (outline-next-heading)
  6717. (org-flag-heading nil))) ; show the next heading
  6718. (org-add-note))))
  6719. (defun org-agenda-change-all-lines (newhead hdmarker
  6720. &optional fixface just-this)
  6721. "Change all lines in the agenda buffer which match HDMARKER.
  6722. The new content of the line will be NEWHEAD (as modified by
  6723. `org-format-agenda-item'). HDMARKER is checked with
  6724. `equal' against all `org-hd-marker' text properties in the file.
  6725. If FIXFACE is non-nil, the face of each item is modified according to
  6726. the new TODO state.
  6727. If JUST-THIS is non-nil, change just the current line, not all.
  6728. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6729. (let* ((inhibit-read-only t)
  6730. (line (org-current-line))
  6731. (thetags (with-current-buffer (marker-buffer hdmarker)
  6732. (save-excursion (save-restriction (widen)
  6733. (goto-char hdmarker)
  6734. (org-get-tags-at)))))
  6735. props m pl undone-face done-face finish new dotime cat tags)
  6736. (save-excursion
  6737. (goto-char (point-max))
  6738. (beginning-of-line 1)
  6739. (while (not finish)
  6740. (setq finish (bobp))
  6741. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6742. (or (not just-this) (= (org-current-line) line))
  6743. (equal m hdmarker))
  6744. (setq props (text-properties-at (point))
  6745. dotime (org-get-at-bol 'dotime)
  6746. cat (org-get-at-bol 'org-category)
  6747. tags thetags
  6748. new
  6749. (let ((org-prefix-format-compiled
  6750. (or (get-text-property (point) 'format)
  6751. org-prefix-format-compiled)))
  6752. (with-current-buffer (marker-buffer hdmarker)
  6753. (save-excursion
  6754. (save-restriction
  6755. (widen)
  6756. (org-format-agenda-item (org-get-at-bol 'extra)
  6757. newhead cat tags dotime)))))
  6758. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6759. undone-face (org-get-at-bol 'undone-face)
  6760. done-face (org-get-at-bol 'done-face))
  6761. (beginning-of-line 1)
  6762. (cond
  6763. ((equal new "")
  6764. (and (looking-at ".*\n?") (replace-match "")))
  6765. ((looking-at ".*")
  6766. (replace-match new t t)
  6767. (beginning-of-line 1)
  6768. (add-text-properties (point-at-bol) (point-at-eol) props)
  6769. (when fixface
  6770. (add-text-properties
  6771. (point-at-bol) (point-at-eol)
  6772. (list 'face
  6773. (if org-last-todo-state-is-todo
  6774. undone-face done-face))))
  6775. (org-agenda-highlight-todo 'line)
  6776. (beginning-of-line 1))
  6777. (t (error "Line update did not work"))))
  6778. (beginning-of-line 0)))
  6779. (org-finalize-agenda)))
  6780. (defun org-agenda-align-tags (&optional line)
  6781. "Align all tags in agenda items to `org-agenda-tags-column'."
  6782. (let ((inhibit-read-only t) l c)
  6783. (save-excursion
  6784. (goto-char (if line (point-at-bol) (point-min)))
  6785. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6786. (if line (point-at-eol) nil) t)
  6787. (add-text-properties
  6788. (match-beginning 2) (match-end 2)
  6789. (list 'face (delq nil (let ((prop (get-text-property
  6790. (match-beginning 2) 'face)))
  6791. (or (listp prop) (setq prop (list prop)))
  6792. (if (memq 'org-tag prop)
  6793. prop
  6794. (cons 'org-tag prop))))))
  6795. (setq l (- (match-end 2) (match-beginning 2))
  6796. c (if (< org-agenda-tags-column 0)
  6797. (- (abs org-agenda-tags-column) l)
  6798. org-agenda-tags-column))
  6799. (delete-region (match-beginning 1) (match-end 1))
  6800. (goto-char (match-beginning 1))
  6801. (insert (org-add-props
  6802. (make-string (max 1 (- c (current-column))) ?\ )
  6803. (plist-put (copy-sequence (text-properties-at (point)))
  6804. 'face nil))))
  6805. (goto-char (point-min))
  6806. (org-font-lock-add-tag-faces (point-max)))))
  6807. (defun org-agenda-priority-up ()
  6808. "Increase the priority of line at point, also in Org-mode file."
  6809. (interactive)
  6810. (org-agenda-priority 'up))
  6811. (defun org-agenda-priority-down ()
  6812. "Decrease the priority of line at point, also in Org-mode file."
  6813. (interactive)
  6814. (org-agenda-priority 'down))
  6815. (defun org-agenda-priority (&optional force-direction)
  6816. "Set the priority of line at point, also in Org-mode file.
  6817. This changes the line at point, all other lines in the agenda referring to
  6818. the same tree node, and the headline of the tree node in the Org-mode file."
  6819. (interactive)
  6820. (unless org-enable-priority-commands
  6821. (error "Priority commands are disabled"))
  6822. (org-agenda-check-no-diary)
  6823. (let* ((marker (or (org-get-at-bol 'org-marker)
  6824. (org-agenda-error)))
  6825. (hdmarker (org-get-at-bol 'org-hd-marker))
  6826. (buffer (marker-buffer hdmarker))
  6827. (pos (marker-position hdmarker))
  6828. (inhibit-read-only t)
  6829. newhead)
  6830. (org-with-remote-undo buffer
  6831. (with-current-buffer buffer
  6832. (widen)
  6833. (goto-char pos)
  6834. (org-show-context 'agenda)
  6835. (save-excursion
  6836. (and (outline-next-heading)
  6837. (org-flag-heading nil))) ; show the next heading
  6838. (funcall 'org-priority force-direction)
  6839. (end-of-line 1)
  6840. (setq newhead (org-get-heading)))
  6841. (org-agenda-change-all-lines newhead hdmarker)
  6842. (beginning-of-line 1))))
  6843. ;; FIXME: should fix the tags property of the agenda line.
  6844. (defun org-agenda-set-tags (&optional tag onoff)
  6845. "Set tags for the current headline."
  6846. (interactive)
  6847. (org-agenda-check-no-diary)
  6848. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6849. (call-interactively 'org-change-tag-in-region)
  6850. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6851. (org-agenda-error)))
  6852. (buffer (marker-buffer hdmarker))
  6853. (pos (marker-position hdmarker))
  6854. (inhibit-read-only t)
  6855. newhead)
  6856. (org-with-remote-undo buffer
  6857. (with-current-buffer buffer
  6858. (widen)
  6859. (goto-char pos)
  6860. (save-excursion
  6861. (org-show-context 'agenda))
  6862. (save-excursion
  6863. (and (outline-next-heading)
  6864. (org-flag-heading nil))) ; show the next heading
  6865. (goto-char pos)
  6866. (if tag
  6867. (org-toggle-tag tag onoff)
  6868. (call-interactively 'org-set-tags))
  6869. (end-of-line 1)
  6870. (setq newhead (org-get-heading)))
  6871. (org-agenda-change-all-lines newhead hdmarker)
  6872. (beginning-of-line 1)))))
  6873. (defun org-agenda-set-property ()
  6874. "Set a property for the current headline."
  6875. (interactive)
  6876. (org-agenda-check-no-diary)
  6877. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6878. (org-agenda-error)))
  6879. (buffer (marker-buffer hdmarker))
  6880. (pos (marker-position hdmarker))
  6881. (inhibit-read-only t)
  6882. newhead)
  6883. (org-with-remote-undo buffer
  6884. (with-current-buffer buffer
  6885. (widen)
  6886. (goto-char pos)
  6887. (save-excursion
  6888. (org-show-context 'agenda))
  6889. (save-excursion
  6890. (and (outline-next-heading)
  6891. (org-flag-heading nil))) ; show the next heading
  6892. (goto-char pos)
  6893. (call-interactively 'org-set-property)))))
  6894. (defun org-agenda-set-effort ()
  6895. "Set the effort property for the current headline."
  6896. (interactive)
  6897. (org-agenda-check-no-diary)
  6898. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6899. (org-agenda-error)))
  6900. (buffer (marker-buffer hdmarker))
  6901. (pos (marker-position hdmarker))
  6902. (inhibit-read-only t)
  6903. newhead)
  6904. (org-with-remote-undo buffer
  6905. (with-current-buffer buffer
  6906. (widen)
  6907. (goto-char pos)
  6908. (save-excursion
  6909. (org-show-context 'agenda))
  6910. (save-excursion
  6911. (and (outline-next-heading)
  6912. (org-flag-heading nil))) ; show the next heading
  6913. (goto-char pos)
  6914. (call-interactively 'org-set-effort)
  6915. (end-of-line 1)
  6916. (setq newhead (org-get-heading)))
  6917. (org-agenda-change-all-lines newhead hdmarker))))
  6918. (defun org-agenda-toggle-archive-tag ()
  6919. "Toggle the archive tag for the current entry."
  6920. (interactive)
  6921. (org-agenda-check-no-diary)
  6922. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6923. (org-agenda-error)))
  6924. (buffer (marker-buffer hdmarker))
  6925. (pos (marker-position hdmarker))
  6926. (inhibit-read-only t)
  6927. newhead)
  6928. (org-with-remote-undo buffer
  6929. (with-current-buffer buffer
  6930. (widen)
  6931. (goto-char pos)
  6932. (org-show-context 'agenda)
  6933. (save-excursion
  6934. (and (outline-next-heading)
  6935. (org-flag-heading nil))) ; show the next heading
  6936. (call-interactively 'org-toggle-archive-tag)
  6937. (end-of-line 1)
  6938. (setq newhead (org-get-heading)))
  6939. (org-agenda-change-all-lines newhead hdmarker)
  6940. (beginning-of-line 1))))
  6941. (defun org-agenda-do-date-later (arg)
  6942. (interactive "P")
  6943. (cond
  6944. ((or (equal arg '(16))
  6945. (memq last-command
  6946. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6947. (setq this-command 'org-agenda-date-later-minutes)
  6948. (org-agenda-date-later-minutes 1))
  6949. ((or (equal arg '(4))
  6950. (memq last-command
  6951. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6952. (setq this-command 'org-agenda-date-later-hours)
  6953. (org-agenda-date-later-hours 1))
  6954. (t
  6955. (org-agenda-date-later (prefix-numeric-value arg)))))
  6956. (defun org-agenda-do-date-earlier (arg)
  6957. (interactive "P")
  6958. (cond
  6959. ((or (equal arg '(16))
  6960. (memq last-command
  6961. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6962. (setq this-command 'org-agenda-date-earlier-minutes)
  6963. (org-agenda-date-earlier-minutes 1))
  6964. ((or (equal arg '(4))
  6965. (memq last-command
  6966. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6967. (setq this-command 'org-agenda-date-earlier-hours)
  6968. (org-agenda-date-earlier-hours 1))
  6969. (t
  6970. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6971. (defun org-agenda-date-later (arg &optional what)
  6972. "Change the date of this item to ARG day(s) later."
  6973. (interactive "p")
  6974. (org-agenda-check-type t 'agenda 'timeline)
  6975. (org-agenda-check-no-diary)
  6976. (let* ((marker (or (org-get-at-bol 'org-marker)
  6977. (org-agenda-error)))
  6978. (buffer (marker-buffer marker))
  6979. (pos (marker-position marker)))
  6980. (org-with-remote-undo buffer
  6981. (with-current-buffer buffer
  6982. (widen)
  6983. (goto-char pos)
  6984. (if (not (org-at-timestamp-p))
  6985. (error "Cannot find time stamp"))
  6986. (org-timestamp-change arg (or what 'day)))
  6987. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6988. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6989. (defun org-agenda-date-earlier (arg &optional what)
  6990. "Change the date of this item to ARG day(s) earlier."
  6991. (interactive "p")
  6992. (org-agenda-date-later (- arg) what))
  6993. (defun org-agenda-date-later-minutes (arg)
  6994. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6995. (interactive "p")
  6996. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6997. (org-agenda-date-later arg 'minute))
  6998. (defun org-agenda-date-earlier-minutes (arg)
  6999. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7000. (interactive "p")
  7001. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7002. (org-agenda-date-earlier arg 'minute))
  7003. (defun org-agenda-date-later-hours (arg)
  7004. "Change the time of this item, in hour steps."
  7005. (interactive "p")
  7006. (org-agenda-date-later arg 'hour))
  7007. (defun org-agenda-date-earlier-hours (arg)
  7008. "Change the time of this item, in hour steps."
  7009. (interactive "p")
  7010. (org-agenda-date-earlier arg 'hour))
  7011. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7012. "Show new date stamp via text properties."
  7013. ;; We use text properties to make this undoable
  7014. (let ((inhibit-read-only t)
  7015. (buffer-invisibility-spec))
  7016. (setq stamp (concat " " prefix " => " stamp))
  7017. (save-excursion
  7018. (goto-char (point-max))
  7019. (while (not (bobp))
  7020. (when (equal marker (org-get-at-bol 'org-marker))
  7021. (org-move-to-column (- (window-width) (length stamp)) t)
  7022. (org-agenda-fix-tags-filter-overlays-at (point))
  7023. (if (featurep 'xemacs)
  7024. ;; Use `duplicable' property to trigger undo recording
  7025. (let ((ex (make-extent nil nil))
  7026. (gl (make-glyph stamp)))
  7027. (set-glyph-face gl 'secondary-selection)
  7028. (set-extent-properties
  7029. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7030. (insert-extent ex (1- (point)) (point-at-eol)))
  7031. (add-text-properties
  7032. (1- (point)) (point-at-eol)
  7033. (list 'display (org-add-props stamp nil
  7034. 'face 'secondary-selection))))
  7035. (beginning-of-line 1))
  7036. (beginning-of-line 0)))))
  7037. (defun org-agenda-date-prompt (arg)
  7038. "Change the date of this item. Date is prompted for, with default today.
  7039. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7040. be used to request time specification in the time stamp."
  7041. (interactive "P")
  7042. (org-agenda-check-type t 'agenda 'timeline)
  7043. (org-agenda-check-no-diary)
  7044. (let* ((marker (or (org-get-at-bol 'org-marker)
  7045. (org-agenda-error)))
  7046. (buffer (marker-buffer marker))
  7047. (pos (marker-position marker)))
  7048. (org-with-remote-undo buffer
  7049. (with-current-buffer buffer
  7050. (widen)
  7051. (goto-char pos)
  7052. (if (not (org-at-timestamp-p t))
  7053. (error "Cannot find time stamp"))
  7054. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7055. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7056. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7057. (defun org-agenda-schedule (arg &optional time)
  7058. "Schedule the item at point.
  7059. ARG is passed through to `org-schedule'."
  7060. (interactive "P")
  7061. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7062. (org-agenda-check-no-diary)
  7063. (let* ((marker (or (org-get-at-bol 'org-marker)
  7064. (org-agenda-error)))
  7065. (type (marker-insertion-type marker))
  7066. (buffer (marker-buffer marker))
  7067. (pos (marker-position marker))
  7068. (org-insert-labeled-timestamps-at-point nil)
  7069. ts)
  7070. (set-marker-insertion-type marker t)
  7071. (org-with-remote-undo buffer
  7072. (with-current-buffer buffer
  7073. (widen)
  7074. (goto-char pos)
  7075. (setq ts (org-schedule arg time)))
  7076. (org-agenda-show-new-time marker ts "S"))
  7077. (message "Item scheduled for %s" ts)))
  7078. (defun org-agenda-deadline (arg &optional time)
  7079. "Schedule the item at point.
  7080. ARG is passed through to `org-deadline'."
  7081. (interactive "P")
  7082. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7083. (org-agenda-check-no-diary)
  7084. (let* ((marker (or (org-get-at-bol 'org-marker)
  7085. (org-agenda-error)))
  7086. (buffer (marker-buffer marker))
  7087. (pos (marker-position marker))
  7088. (org-insert-labeled-timestamps-at-point nil)
  7089. ts)
  7090. (org-with-remote-undo buffer
  7091. (with-current-buffer buffer
  7092. (widen)
  7093. (goto-char pos)
  7094. (setq ts (org-deadline arg time)))
  7095. (org-agenda-show-new-time marker ts "D"))
  7096. (message "Deadline for this item set to %s" ts)))
  7097. (defun org-agenda-action ()
  7098. "Select entry for agenda action, or execute an agenda action.
  7099. This command prompts for another letter. Valid inputs are:
  7100. m Mark the entry at point for an agenda action
  7101. s Schedule the marked entry to the date at the cursor
  7102. d Set the deadline of the marked entry to the date at the cursor
  7103. r Call `org-remember' with cursor date as the default date
  7104. c Call `org-capture' with cursor date as the default date
  7105. SPC Show marked entry in other window
  7106. TAB Visit marked entry in other window
  7107. The cursor may be at a date in the calendar, or in the Org agenda."
  7108. (interactive)
  7109. (let (ans)
  7110. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7111. (setq ans (read-char-exclusive))
  7112. (cond
  7113. ((equal ans ?m)
  7114. ;; Mark this entry
  7115. (if (eq major-mode 'org-agenda-mode)
  7116. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7117. (org-get-at-bol 'org-marker))))
  7118. (if m
  7119. (progn
  7120. (move-marker org-agenda-action-marker
  7121. (marker-position m) (marker-buffer m))
  7122. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7123. (error "Don't know which entry to mark")))
  7124. (error "This command works only in the agenda")))
  7125. ((equal ans ?s)
  7126. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7127. ((equal ans ?d)
  7128. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7129. ((equal ans ?r)
  7130. (org-agenda-do-action '(org-remember) t))
  7131. ((equal ans ?c)
  7132. (org-agenda-do-action '(org-capture) t))
  7133. ((equal ans ?\ )
  7134. (let ((cw (selected-window)))
  7135. (org-switch-to-buffer-other-window
  7136. (marker-buffer org-agenda-action-marker))
  7137. (goto-char org-agenda-action-marker)
  7138. (org-show-context 'agenda)
  7139. (select-window cw)))
  7140. ((equal ans ?\C-i)
  7141. (org-switch-to-buffer-other-window
  7142. (marker-buffer org-agenda-action-marker))
  7143. (goto-char org-agenda-action-marker)
  7144. (org-show-context 'agenda))
  7145. (t (error "Invalid agenda action %c" ans)))))
  7146. (defun org-agenda-do-action (form &optional current-buffer)
  7147. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7148. (let ((org-overriding-default-time (org-get-cursor-date)))
  7149. (if current-buffer
  7150. (eval form)
  7151. (if (not (marker-buffer org-agenda-action-marker))
  7152. (error "No entry has been selected for agenda action")
  7153. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7154. (save-excursion
  7155. (save-restriction
  7156. (widen)
  7157. (goto-char org-agenda-action-marker)
  7158. (eval form))))))))
  7159. (defun org-agenda-clock-in (&optional arg)
  7160. "Start the clock on the currently selected item."
  7161. (interactive "P")
  7162. (org-agenda-check-no-diary)
  7163. (if (equal arg '(4))
  7164. (org-clock-in arg)
  7165. (let* ((marker (or (org-get-at-bol 'org-marker)
  7166. (org-agenda-error)))
  7167. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7168. marker))
  7169. (pos (marker-position marker))
  7170. newhead)
  7171. (org-with-remote-undo (marker-buffer marker)
  7172. (with-current-buffer (marker-buffer marker)
  7173. (widen)
  7174. (goto-char pos)
  7175. (org-show-context 'agenda)
  7176. (org-show-entry)
  7177. (org-cycle-hide-drawers 'children)
  7178. (org-clock-in arg)
  7179. (setq newhead (org-get-heading)))
  7180. (org-agenda-change-all-lines newhead hdmarker)))))
  7181. (defun org-agenda-clock-out ()
  7182. "Stop the currently running clock."
  7183. (interactive)
  7184. (unless (marker-buffer org-clock-marker)
  7185. (error "No running clock"))
  7186. (let ((marker (make-marker)) newhead)
  7187. (org-with-remote-undo (marker-buffer org-clock-marker)
  7188. (with-current-buffer (marker-buffer org-clock-marker)
  7189. (save-excursion
  7190. (save-restriction
  7191. (widen)
  7192. (goto-char org-clock-marker)
  7193. (org-back-to-heading t)
  7194. (move-marker marker (point))
  7195. (org-clock-out)
  7196. (setq newhead (org-get-heading))))))
  7197. (org-agenda-change-all-lines newhead marker)
  7198. (move-marker marker nil)))
  7199. (defun org-agenda-clock-cancel (&optional arg)
  7200. "Cancel the currently running clock."
  7201. (interactive "P")
  7202. (unless (marker-buffer org-clock-marker)
  7203. (error "No running clock"))
  7204. (org-with-remote-undo (marker-buffer org-clock-marker)
  7205. (org-clock-cancel)))
  7206. (defun org-agenda-clock-goto ()
  7207. "Jump to the currently clocked in task within the agenda.
  7208. If the currently clocked in task is not listed in the agenda
  7209. buffer, display it in another window."
  7210. (interactive)
  7211. (let (pos)
  7212. (mapc (lambda (o)
  7213. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7214. (setq pos (overlay-start o))))
  7215. (overlays-in (point-min) (point-max)))
  7216. (cond (pos (goto-char pos))
  7217. ;; If the currently clocked entry is not in the agenda
  7218. ;; buffer, we visit it in another window:
  7219. (org-clock-current-task
  7220. (org-switch-to-buffer-other-window (org-clock-goto)))
  7221. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7222. (defun org-agenda-diary-entry-in-org-file ()
  7223. "Make a diary entry in the file `org-agenda-diary-file'."
  7224. (let (d1 d2 char (text "") dp1 dp2)
  7225. (if (equal (buffer-name) "*Calendar*")
  7226. (setq d1 (calendar-cursor-to-date t)
  7227. d2 (car calendar-mark-ring))
  7228. (setq dp1 (get-text-property (point-at-bol) 'day))
  7229. (unless dp1 (error "No date defined in current line"))
  7230. (setq d1 (calendar-gregorian-from-absolute dp1)
  7231. d2 (and (ignore-errors (mark))
  7232. (save-excursion
  7233. (goto-char (mark))
  7234. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7235. (calendar-gregorian-from-absolute dp2))))
  7236. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7237. (setq char (read-char-exclusive))
  7238. (cond
  7239. ((equal char ?d)
  7240. (setq text (read-string "Day entry: "))
  7241. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7242. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7243. ((equal char ?a)
  7244. (setq d1 (list (car d1) (nth 1 d1)
  7245. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7246. (nth 2 d1))))
  7247. (setq text (read-string "Anniversary (use %d to show years): "))
  7248. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7249. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7250. ((equal char ?b)
  7251. (setq text (read-string "Block entry: "))
  7252. (unless (and d1 d2 (not (equal d1 d2)))
  7253. (error "No block of days selected"))
  7254. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7255. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7256. ((equal char ?j)
  7257. (org-switch-to-buffer-other-window
  7258. (find-file-noselect org-agenda-diary-file))
  7259. (require 'org-datetree)
  7260. (org-datetree-find-date-create d1)
  7261. (org-reveal t))
  7262. (t (error "Invalid selection character `%c'" char)))))
  7263. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7264. "Where in `org-agenda-diary-file' should new entries be added?
  7265. Valid values:
  7266. date-tree in the date tree, as child of the date
  7267. top-level as top-level entries at the end of the file."
  7268. :group 'org-agenda
  7269. :type '(choice
  7270. (const :tag "in a date tree" date-tree)
  7271. (const :tag "as top level at end of file" top-level)))
  7272. (defcustom org-agenda-insert-diary-extract-time nil
  7273. "Non-nil means extract any time specification from the diary entry."
  7274. :group 'org-agenda
  7275. :type 'boolean)
  7276. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7277. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7278. If TEXT is not empty, it will become the headline of the new entry, and
  7279. the resulting entry will not be shown. When TEXT is empty, switch to
  7280. `org-agenda-diary-file' and let the user finish the entry there."
  7281. (let ((cw (current-window-configuration)))
  7282. (org-switch-to-buffer-other-window
  7283. (find-file-noselect org-agenda-diary-file))
  7284. (widen)
  7285. (goto-char (point-min))
  7286. (cond
  7287. ((eq type 'anniversary)
  7288. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7289. (progn
  7290. (or (org-on-heading-p t)
  7291. (progn
  7292. (outline-next-heading)
  7293. (insert "* Anniversaries\n\n")
  7294. (beginning-of-line -1)))))
  7295. (outline-next-heading)
  7296. (org-back-over-empty-lines)
  7297. (backward-char 1)
  7298. (insert "\n")
  7299. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7300. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7301. ((eq type 'day)
  7302. (let ((org-prefix-has-time t)
  7303. (org-agenda-time-leading-zero t)
  7304. fmt time time2)
  7305. (if org-agenda-insert-diary-extract-time
  7306. ;; Use org-format-agenda-item to parse text for a time-range and
  7307. ;; remove it. FIXME: This is a hack, we should refactor
  7308. ;; that function to make time extraction available separately
  7309. (setq fmt (org-format-agenda-item nil text nil nil t)
  7310. time (get-text-property 0 'time fmt)
  7311. time2 (if (> (length time) 0)
  7312. ;; split-string removes trailing ...... if
  7313. ;; no end time given. First space
  7314. ;; separates time from date.
  7315. (concat " " (car (split-string time "\\.")))
  7316. nil)
  7317. text (get-text-property 0 'txt fmt)))
  7318. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7319. (org-agenda-insert-diary-as-top-level text)
  7320. (require 'org-datetree)
  7321. (org-datetree-find-date-create d1)
  7322. (org-agenda-insert-diary-make-new-entry text))
  7323. (org-insert-time-stamp (org-time-from-absolute
  7324. (calendar-absolute-from-gregorian d1))
  7325. nil nil nil nil time2))
  7326. (end-of-line 0))
  7327. ((eq type 'block)
  7328. (if (> (calendar-absolute-from-gregorian d1)
  7329. (calendar-absolute-from-gregorian d2))
  7330. (setq d1 (prog1 d2 (setq d2 d1))))
  7331. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7332. (org-agenda-insert-diary-as-top-level text)
  7333. (require 'org-datetree)
  7334. (org-datetree-find-date-create d1)
  7335. (org-agenda-insert-diary-make-new-entry text))
  7336. (org-insert-time-stamp (org-time-from-absolute
  7337. (calendar-absolute-from-gregorian d1)))
  7338. (insert "--")
  7339. (org-insert-time-stamp (org-time-from-absolute
  7340. (calendar-absolute-from-gregorian d2)))
  7341. (end-of-line 0)))
  7342. (if (string-match "\\S-" text)
  7343. (progn
  7344. (set-window-configuration cw)
  7345. (message "%s entry added to %s"
  7346. (capitalize (symbol-name type))
  7347. (abbreviate-file-name org-agenda-diary-file)))
  7348. (org-reveal t)
  7349. (message "Please finish entry here"))))
  7350. (defun org-agenda-insert-diary-as-top-level (text)
  7351. "Make new entry as a top-level entry at the end of the file.
  7352. Add TEXT as headline, and position the cursor in the second line so that
  7353. a timestamp can be added there."
  7354. (widen)
  7355. (goto-char (point-max))
  7356. (or (bolp) (insert "\n"))
  7357. (insert "* " text "\n")
  7358. (if org-adapt-indentation (org-indent-to-column 2)))
  7359. (defun org-agenda-insert-diary-make-new-entry (text)
  7360. "Make new entry as last child of current entry.
  7361. Add TEXT as headline, and position the cursor in the second line so that
  7362. a timestamp can be added there."
  7363. (let ((org-show-following-heading t)
  7364. (org-show-siblings t)
  7365. (org-show-hierarchy-above t)
  7366. (org-show-entry-below t)
  7367. col)
  7368. (outline-next-heading)
  7369. (org-back-over-empty-lines)
  7370. (or (looking-at "[ \t]*$")
  7371. (progn (insert "\n") (backward-char 1)))
  7372. (org-insert-heading nil t)
  7373. (org-do-demote)
  7374. (setq col (current-column))
  7375. (insert text "\n")
  7376. (if org-adapt-indentation (org-indent-to-column col))
  7377. (let ((org-show-following-heading t)
  7378. (org-show-siblings t)
  7379. (org-show-hierarchy-above t)
  7380. (org-show-entry-below t))
  7381. (org-show-context))))
  7382. (defun org-agenda-diary-entry ()
  7383. "Make a diary entry, like the `i' command from the calendar.
  7384. All the standard commands work: block, weekly etc.
  7385. When `org-agenda-diary-file' points to a file,
  7386. `org-agenda-diary-entry-in-org-file' is called instead to create
  7387. entries in that Org-mode file."
  7388. (interactive)
  7389. (org-agenda-check-type t 'agenda 'timeline)
  7390. (if (not (eq org-agenda-diary-file 'diary-file))
  7391. (org-agenda-diary-entry-in-org-file)
  7392. (require 'diary-lib)
  7393. (let* ((char (progn
  7394. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7395. (read-char-exclusive)))
  7396. (cmd (cdr (assoc char
  7397. '((?d . insert-diary-entry)
  7398. (?w . insert-weekly-diary-entry)
  7399. (?m . insert-monthly-diary-entry)
  7400. (?y . insert-yearly-diary-entry)
  7401. (?a . insert-anniversary-diary-entry)
  7402. (?b . insert-block-diary-entry)
  7403. (?c . insert-cyclic-diary-entry)))))
  7404. (oldf (symbol-function 'calendar-cursor-to-date))
  7405. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7406. (point (point))
  7407. (mark (or (mark t) (point))))
  7408. (unless cmd
  7409. (error "No command associated with <%c>" char))
  7410. (unless (and (get-text-property point 'day)
  7411. (or (not (equal ?b char))
  7412. (get-text-property mark 'day)))
  7413. (error "Don't know which date to use for diary entry"))
  7414. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7415. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7416. (let ((calendar-mark-ring
  7417. (list (calendar-gregorian-from-absolute
  7418. (or (get-text-property mark 'day)
  7419. (get-text-property point 'day))))))
  7420. (unwind-protect
  7421. (progn
  7422. (fset 'calendar-cursor-to-date
  7423. (lambda (&optional error dummy)
  7424. (calendar-gregorian-from-absolute
  7425. (get-text-property point 'day))))
  7426. (call-interactively cmd))
  7427. (fset 'calendar-cursor-to-date oldf))))))
  7428. (defun org-agenda-execute-calendar-command (cmd)
  7429. "Execute a calendar command from the agenda, with the date associated to
  7430. the cursor position."
  7431. (org-agenda-check-type t 'agenda 'timeline)
  7432. (require 'diary-lib)
  7433. (unless (get-text-property (point) 'day)
  7434. (error "Don't know which date to use for calendar command"))
  7435. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7436. (point (point))
  7437. (date (calendar-gregorian-from-absolute
  7438. (get-text-property point 'day)))
  7439. ;; the following 2 vars are needed in the calendar
  7440. (displayed-month (car date))
  7441. (displayed-year (nth 2 date)))
  7442. (unwind-protect
  7443. (progn
  7444. (fset 'calendar-cursor-to-date
  7445. (lambda (&optional error dummy)
  7446. (calendar-gregorian-from-absolute
  7447. (get-text-property point 'day))))
  7448. (call-interactively cmd))
  7449. (fset 'calendar-cursor-to-date oldf))))
  7450. (defun org-agenda-phases-of-moon ()
  7451. "Display the phases of the moon for the 3 months around the cursor date."
  7452. (interactive)
  7453. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7454. (defun org-agenda-holidays ()
  7455. "Display the holidays for the 3 months around the cursor date."
  7456. (interactive)
  7457. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7458. (defvar calendar-longitude)
  7459. (defvar calendar-latitude)
  7460. (defvar calendar-location-name)
  7461. (defun org-agenda-sunrise-sunset (arg)
  7462. "Display sunrise and sunset for the cursor date.
  7463. Latitude and longitude can be specified with the variables
  7464. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7465. argument, latitude and longitude will be prompted for."
  7466. (interactive "P")
  7467. (require 'solar)
  7468. (let ((calendar-longitude (if arg nil calendar-longitude))
  7469. (calendar-latitude (if arg nil calendar-latitude))
  7470. (calendar-location-name
  7471. (if arg "the given coordinates" calendar-location-name)))
  7472. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7473. (defun org-agenda-goto-calendar ()
  7474. "Open the Emacs calendar with the date at the cursor."
  7475. (interactive)
  7476. (org-agenda-check-type t 'agenda 'timeline)
  7477. (let* ((day (or (get-text-property (point) 'day)
  7478. (error "Don't know which date to open in calendar")))
  7479. (date (calendar-gregorian-from-absolute day))
  7480. (calendar-move-hook nil)
  7481. (calendar-view-holidays-initially-flag nil)
  7482. (calendar-view-diary-initially-flag nil))
  7483. (calendar)
  7484. (calendar-goto-date date)))
  7485. ;;;###autoload
  7486. (defun org-calendar-goto-agenda ()
  7487. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7488. This is a command that has to be installed in `calendar-mode-map'."
  7489. (interactive)
  7490. (org-agenda-list nil (calendar-absolute-from-gregorian
  7491. (calendar-cursor-to-date))
  7492. nil))
  7493. (defun org-agenda-convert-date ()
  7494. (interactive)
  7495. (org-agenda-check-type t 'agenda 'timeline)
  7496. (let ((day (get-text-property (point) 'day))
  7497. date s)
  7498. (unless day
  7499. (error "Don't know which date to convert"))
  7500. (setq date (calendar-gregorian-from-absolute day))
  7501. (setq s (concat
  7502. "Gregorian: " (calendar-date-string date) "\n"
  7503. "ISO: " (calendar-iso-date-string date) "\n"
  7504. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7505. "Julian: " (calendar-julian-date-string date) "\n"
  7506. "Astron. JD: " (calendar-astro-date-string date)
  7507. " (Julian date number at noon UTC)\n"
  7508. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7509. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7510. "French: " (calendar-french-date-string date) "\n"
  7511. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7512. "Mayan: " (calendar-mayan-date-string date) "\n"
  7513. "Coptic: " (calendar-coptic-date-string date) "\n"
  7514. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7515. "Persian: " (calendar-persian-date-string date) "\n"
  7516. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7517. (with-output-to-temp-buffer "*Dates*"
  7518. (princ s))
  7519. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7520. ;;; Bulk commands
  7521. (defvar org-agenda-bulk-marked-entries nil
  7522. "List of markers that refer to marked entries in the agenda.")
  7523. (defun org-agenda-bulk-marked-p ()
  7524. (eq (get-char-property (point-at-bol) 'type)
  7525. 'org-marked-entry-overlay))
  7526. (defun org-agenda-bulk-mark (&optional arg)
  7527. "Mark the entry at point for future bulk action."
  7528. (interactive "p")
  7529. (dotimes (i (max arg 1))
  7530. (unless (org-get-at-bol 'org-agenda-diary-link)
  7531. (let* ((m (org-get-at-bol 'org-hd-marker))
  7532. ov)
  7533. (unless (org-agenda-bulk-marked-p)
  7534. (unless m (error "Nothing to mark at point"))
  7535. (push m org-agenda-bulk-marked-entries)
  7536. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7537. (org-overlay-display ov "> "
  7538. (org-get-todo-face "TODO")
  7539. 'evaporate)
  7540. (overlay-put ov 'type 'org-marked-entry-overlay))
  7541. (beginning-of-line 2)
  7542. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7543. (beginning-of-line 2))
  7544. (message "%d entries marked for bulk action"
  7545. (length org-agenda-bulk-marked-entries))))))
  7546. (defun org-agenda-bulk-mark-regexp (regexp)
  7547. "Mark entries match REGEXP."
  7548. (interactive "sMark entries matching regexp: ")
  7549. (let (entries-marked)
  7550. (save-excursion
  7551. (goto-char (point-min))
  7552. (goto-char (next-single-property-change (point) 'txt))
  7553. (while (re-search-forward regexp nil t)
  7554. (when (string-match regexp (get-text-property (point) 'txt))
  7555. (setq entries-marked (+ entries-marked 1))
  7556. (call-interactively 'org-agenda-bulk-mark))))
  7557. (if (not entries-marked)
  7558. (message "No entry matching this regexp."))))
  7559. (defun org-agenda-bulk-unmark ()
  7560. "Unmark the entry at point for future bulk action."
  7561. (interactive)
  7562. (when (org-agenda-bulk-marked-p)
  7563. (org-agenda-bulk-remove-overlays
  7564. (point-at-bol) (+ 2 (point-at-bol)))
  7565. (setq org-agenda-bulk-marked-entries
  7566. (delete (org-get-at-bol 'org-hd-marker)
  7567. org-agenda-bulk-marked-entries)))
  7568. (beginning-of-line 2)
  7569. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7570. (beginning-of-line 2))
  7571. (message "%d entries marked for bulk action"
  7572. (length org-agenda-bulk-marked-entries)))
  7573. (defun org-agenda-bulk-toggle ()
  7574. "Toggle marking the entry at point for bulk action."
  7575. (interactive)
  7576. (if (org-agenda-bulk-marked-p)
  7577. (org-agenda-bulk-unmark)
  7578. (org-agenda-bulk-mark)))
  7579. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7580. "Remove the mark overlays between BEG and END in the agenda buffer.
  7581. BEG and END default to the buffer limits.
  7582. This only removes the overlays, it does not remove the markers
  7583. from the list in `org-agenda-bulk-marked-entries'."
  7584. (interactive)
  7585. (mapc (lambda (ov)
  7586. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7587. (delete-overlay ov)))
  7588. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7589. (defun org-agenda-bulk-remove-all-marks ()
  7590. "Remove all marks in the agenda buffer.
  7591. This will remove the markers, and the overlays."
  7592. (interactive)
  7593. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7594. (setq org-agenda-bulk-marked-entries nil)
  7595. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7596. (defun org-agenda-bulk-action (&optional arg)
  7597. "Execute an remote-editing action on all marked entries.
  7598. The prefix arg is passed through to the command if possible."
  7599. (interactive "P")
  7600. ;; Make sure we have markers, and only valid ones
  7601. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7602. (mapc
  7603. (lambda (m)
  7604. (unless (and (markerp m)
  7605. (marker-buffer m)
  7606. (buffer-live-p (marker-buffer m))
  7607. (marker-position m))
  7608. (error "Marker %s for bulk command is invalid" m)))
  7609. org-agenda-bulk-marked-entries)
  7610. ;; Prompt for the bulk command
  7611. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7612. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7613. (when org-agenda-bulk-custom-functions
  7614. (concat " Custom: ["
  7615. (mapconcat (lambda(f) (char-to-string (car f)))
  7616. org-agenda-bulk-custom-functions "")
  7617. "]"))))
  7618. (let* ((action (read-char-exclusive))
  7619. (org-log-refile (if org-log-refile 'time nil))
  7620. (entries (reverse org-agenda-bulk-marked-entries))
  7621. redo-at-end
  7622. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7623. (cond
  7624. ((equal action ?$)
  7625. (setq cmd '(org-agenda-archive)))
  7626. ((equal action ?A)
  7627. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7628. ((member action '(?r ?w))
  7629. (setq rfloc (org-refile-get-location
  7630. "Refile to"
  7631. (marker-buffer (car org-agenda-bulk-marked-entries))
  7632. org-refile-allow-creating-parent-nodes))
  7633. (if (nth 3 rfloc)
  7634. (setcar (nthcdr 3 rfloc)
  7635. (move-marker (make-marker) (nth 3 rfloc)
  7636. (or (get-file-buffer (nth 1 rfloc))
  7637. (find-buffer-visiting (nth 1 rfloc))
  7638. (error "This should not happen")))))
  7639. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7640. redo-at-end t))
  7641. ((equal action ?t)
  7642. (setq state (org-icompleting-read
  7643. "Todo state: "
  7644. (with-current-buffer (marker-buffer (car entries))
  7645. (mapcar 'list org-todo-keywords-1))))
  7646. (setq cmd `(let ((org-inhibit-blocking t)
  7647. (org-inhibit-logging 'note))
  7648. (org-agenda-todo ,state))))
  7649. ((memq action '(?- ?+))
  7650. (setq tag (org-icompleting-read
  7651. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7652. (with-current-buffer (marker-buffer (car entries))
  7653. (delq nil
  7654. (mapcar (lambda (x)
  7655. (if (stringp (car x)) x)) org-tag-alist)))))
  7656. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7657. ((memq action '(?s ?d))
  7658. (let* ((date (unless arg
  7659. (org-read-date
  7660. nil nil nil
  7661. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7662. (ans (if arg nil org-read-date-final-answer))
  7663. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7664. (setq cmd `(let* ((bound (fboundp 'read-string))
  7665. (old (and bound (symbol-function 'read-string))))
  7666. (unwind-protect
  7667. (progn
  7668. (fset 'read-string (lambda (&rest ignore) ,ans))
  7669. (eval '(,c1 arg)))
  7670. (if bound
  7671. (fset 'read-string old)
  7672. (fmakunbound 'read-string)))))))
  7673. ((equal action ?S)
  7674. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7675. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7676. (let ((days (read-number
  7677. (format "Scatter tasks across how many %sdays: "
  7678. (if arg "week" "")) 7)))
  7679. (setq cmd
  7680. `(let ((distance (1+ (random ,days))))
  7681. (if arg
  7682. (let ((dist distance)
  7683. (day-of-week
  7684. (calendar-day-of-week
  7685. (calendar-gregorian-from-absolute (org-today)))))
  7686. (dotimes (i (1+ dist))
  7687. (while (member day-of-week org-agenda-weekend-days)
  7688. (incf distance)
  7689. (incf day-of-week)
  7690. (if (= day-of-week 7)
  7691. (setq day-of-week 0)))
  7692. (incf day-of-week)
  7693. (if (= day-of-week 7)
  7694. (setq day-of-week 0)))))
  7695. ;; silently fail when try to replan a sexp entry
  7696. (condition-case nil
  7697. (let* ((date (calendar-gregorian-from-absolute
  7698. (+ (org-today) distance)))
  7699. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7700. (nth 2 date))))
  7701. (org-agenda-schedule nil time))
  7702. (error nil)))))))
  7703. ((assoc action org-agenda-bulk-custom-functions)
  7704. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7705. redo-at-end t))
  7706. ((equal action ?f)
  7707. (setq cmd (list (intern
  7708. (org-icompleting-read "Function: "
  7709. obarray 'fboundp t nil nil)))))
  7710. (t (error "Invalid bulk action")))
  7711. ;; Sort the markers, to make sure that parents are handled before children
  7712. (setq entries (sort entries
  7713. (lambda (a b)
  7714. (cond
  7715. ((equal (marker-buffer a) (marker-buffer b))
  7716. (< (marker-position a) (marker-position b)))
  7717. (t
  7718. (string< (buffer-name (marker-buffer a))
  7719. (buffer-name (marker-buffer b))))))))
  7720. ;; Now loop over all markers and apply cmd
  7721. (while (setq e (pop entries))
  7722. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7723. (if (not pos)
  7724. (progn (message "Skipping removed entry at %s" e)
  7725. (setq cntskip (1+ cntskip)))
  7726. (goto-char pos)
  7727. (eval cmd)
  7728. (setq org-agenda-bulk-marked-entries
  7729. (delete e org-agenda-bulk-marked-entries))
  7730. (setq cnt (1+ cnt))))
  7731. (setq org-agenda-bulk-marked-entries nil)
  7732. (org-agenda-bulk-remove-all-marks)
  7733. (when redo-at-end (org-agenda-redo))
  7734. (message "Acted on %d entries%s"
  7735. cnt
  7736. (if (= cntskip 0)
  7737. ""
  7738. (format ", skipped %d (disappeared before their turn)"
  7739. cntskip)))))
  7740. ;;; Flagging notes
  7741. (defun org-agenda-show-the-flagging-note ()
  7742. "Display the flagging note in the other window.
  7743. When called a second time in direct sequence, offer to remove the FLAGGING
  7744. tag and (if present) the flagging note."
  7745. (interactive)
  7746. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7747. (win (selected-window))
  7748. note heading newhead)
  7749. (unless hdmarker
  7750. (error "No linked entry at point"))
  7751. (if (and (eq this-command last-command)
  7752. (y-or-n-p "Unflag and remove any flagging note? "))
  7753. (progn
  7754. (org-agenda-remove-flag hdmarker)
  7755. (let ((win (get-buffer-window "*Flagging Note*")))
  7756. (and win (delete-window win)))
  7757. (message "Entry unflaged"))
  7758. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7759. (unless note
  7760. (error "No flagging note"))
  7761. (org-kill-new note)
  7762. (org-switch-to-buffer-other-window "*Flagging Note*")
  7763. (erase-buffer)
  7764. (insert note)
  7765. (goto-char (point-min))
  7766. (while (re-search-forward "\\\\n" nil t)
  7767. (replace-match "\n" t t))
  7768. (goto-char (point-min))
  7769. (select-window win)
  7770. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7771. (defun org-agenda-remove-flag (marker)
  7772. "Remove the FLAGGED tag and any flagging note in the entry."
  7773. (let (newhead)
  7774. (org-with-point-at marker
  7775. (org-toggle-tag "FLAGGED" 'off)
  7776. (org-entry-delete nil "THEFLAGGINGNOTE")
  7777. (setq newhead (org-get-heading)))
  7778. (org-agenda-change-all-lines newhead marker)
  7779. (message "Entry unflaged")))
  7780. (defun org-agenda-get-any-marker (&optional pos)
  7781. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7782. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7783. ;;; Appointment reminders
  7784. (defvar appt-time-msg-list)
  7785. ;;;###autoload
  7786. (defun org-agenda-to-appt (&optional refresh filter)
  7787. "Activate appointments found in `org-agenda-files'.
  7788. With a \\[universal-argument] prefix, refresh the list of
  7789. appointments.
  7790. If FILTER is t, interactively prompt the user for a regular
  7791. expression, and filter out entries that don't match it.
  7792. If FILTER is a string, use this string as a regular expression
  7793. for filtering entries out.
  7794. FILTER can also be an alist with the car of each cell being
  7795. either 'headline or 'category. For example:
  7796. '((headline \"IMPORTANT\")
  7797. (category \"Work\"))
  7798. will only add headlines containing IMPORTANT or headlines
  7799. belonging to the \"Work\" category."
  7800. (interactive "P")
  7801. (if refresh (setq appt-time-msg-list nil))
  7802. (if (eq filter t)
  7803. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7804. (let* ((cnt 0) ; count added events
  7805. (org-agenda-new-buffers nil)
  7806. (org-deadline-warning-days 0)
  7807. ;; Do not use `org-today' here because appt only takes
  7808. ;; time and without date as argument, so it may pass wrong
  7809. ;; information otherwise
  7810. (today (org-date-to-gregorian
  7811. (time-to-days (current-time))))
  7812. (org-agenda-restrict nil)
  7813. (files (org-agenda-files 'unrestricted)) entries file)
  7814. ;; Get all entries which may contain an appt
  7815. (org-prepare-agenda-buffers files)
  7816. (while (setq file (pop files))
  7817. (setq entries
  7818. (append entries
  7819. (org-agenda-get-day-entries
  7820. file today :timestamp :scheduled :deadline))))
  7821. (setq entries (delq nil entries))
  7822. ;; Map thru entries and find if we should filter them out
  7823. (mapc
  7824. (lambda(x)
  7825. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7826. (cat (get-text-property 1 'org-category x))
  7827. (tod (get-text-property 1 'time-of-day x))
  7828. (ok (or (null filter)
  7829. (and (stringp filter) (string-match filter evt))
  7830. (and (listp filter)
  7831. (or (string-match
  7832. (cadr (assoc 'category filter)) cat)
  7833. (string-match
  7834. (cadr (assoc 'headline filter)) evt))))))
  7835. ;; FIXME: Shall we remove text-properties for the appt text?
  7836. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7837. (when (and ok tod)
  7838. (setq tod (concat "00" (number-to-string tod))
  7839. tod (when (string-match
  7840. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7841. (concat (match-string 1 tod) ":"
  7842. (match-string 2 tod))))
  7843. (appt-add tod evt)
  7844. (setq cnt (1+ cnt))))) entries)
  7845. (org-release-buffers org-agenda-new-buffers)
  7846. (if (eq cnt 0)
  7847. (message "No event to add")
  7848. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7849. (defun org-agenda-todayp (date)
  7850. "Does DATE mean today, when considering `org-extend-today-until'?"
  7851. (let ((today (org-today))
  7852. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7853. date)))
  7854. (eq date today)))
  7855. (defun org-agenda-todo-yesterday (&optional arg)
  7856. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  7857. (interactive "P")
  7858. (let* ((hour (third (decode-time
  7859. (org-current-time))))
  7860. (org-extend-today-until (1+ hour)))
  7861. (org-agenda-todo arg)))
  7862. (provide 'org-agenda)
  7863. ;;; org-agenda.el ends here