org-agenda.el 332 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (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 calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. ;; Defined somewhere in this file, but used before definition.
  80. (defvar org-agenda-buffer-name)
  81. (defvar org-agenda-overriding-header)
  82. (defvar org-agenda-title-append nil)
  83. (defvar entry)
  84. (defvar date)
  85. (defvar org-agenda-undo-list)
  86. (defvar org-agenda-pending-undo-list)
  87. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  88. (defcustom org-agenda-confirm-kill 1
  89. "When set, remote killing from the agenda buffer needs confirmation.
  90. When t, a confirmation is always needed. When a number N, confirmation is
  91. only needed when the text to be killed contains more than N non-white lines."
  92. :group 'org-agenda
  93. :type '(choice
  94. (const :tag "Never" nil)
  95. (const :tag "Always" t)
  96. (integer :tag "When more than N lines")))
  97. (defcustom org-agenda-compact-blocks nil
  98. "Non-nil means make the block agenda more compact.
  99. This is done globally by leaving out lines like the agenda span
  100. name and week number or the separator lines."
  101. :group 'org-agenda
  102. :type 'boolean)
  103. (defcustom org-agenda-block-separator ?=
  104. "The separator between blocks in the agenda.
  105. If this is a string, it will be used as the separator, with a newline added.
  106. If it is a character, it will be repeated to fill the window width.
  107. If nil the separator is disabled. In `org-agenda-custom-commands' this
  108. addresses the separator between the current and the previous block."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Disabled" nil)
  112. (character)
  113. (string)))
  114. (defgroup org-agenda-export nil
  115. "Options concerning exporting agenda views in Org-mode."
  116. :tag "Org Agenda Export"
  117. :group 'org-agenda)
  118. (defcustom org-agenda-with-colors t
  119. "Non-nil means use colors in agenda views."
  120. :group 'org-agenda-export
  121. :type 'boolean)
  122. (defcustom org-agenda-exporter-settings nil
  123. "Alist of variable/value pairs that should be active during agenda export.
  124. This is a good place to set options for ps-print and for htmlize.
  125. Note that the way this is implemented, the values will be evaluated
  126. before assigned to the variables. So make sure to quote values you do
  127. *not* want evaluated, for example
  128. (setq org-agenda-exporter-settings
  129. '((ps-print-color-p 'black-white)))"
  130. :group 'org-agenda-export
  131. :type '(repeat
  132. (list
  133. (variable)
  134. (sexp :tag "Value"))))
  135. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  136. "Hook run in temporary buffer before writing it to an export file.
  137. A useful function is `org-agenda-add-entry-text'."
  138. :group 'org-agenda-export
  139. :type 'hook
  140. :options '(org-agenda-add-entry-text))
  141. (defcustom org-agenda-add-entry-text-maxlines 0
  142. "Maximum number of entry text lines to be added to agenda.
  143. This is only relevant when `org-agenda-add-entry-text' is part of
  144. `org-agenda-before-write-hook', which it is by default.
  145. When this is 0, nothing will happen. When it is greater than 0, it
  146. specifies the maximum number of lines that will be added for each entry
  147. that is listed in the agenda view.
  148. Note that this variable is not used during display, only when exporting
  149. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  150. and `org-agenda-entry-text-maxlines'."
  151. :group 'org-agenda
  152. :type 'integer)
  153. (defcustom org-agenda-add-entry-text-descriptive-links t
  154. "Non-nil means export org-links as descriptive links in agenda added text.
  155. This variable applies to the text added to the agenda when
  156. `org-agenda-add-entry-text-maxlines' is larger than 0.
  157. When this variable nil, the URL will (also) be shown."
  158. :group 'org-agenda
  159. :type 'boolean)
  160. (defcustom org-agenda-export-html-style ""
  161. "The style specification for exported HTML Agenda files.
  162. If this variable contains a string, it will replace the default <style>
  163. section as produced by `htmlize'.
  164. Since there are different ways of setting style information, this variable
  165. needs to contain the full HTML structure to provide a style, including the
  166. surrounding HTML tags. The style specifications should include definitions
  167. the fonts used by the agenda, here is an example:
  168. <style type=\"text/css\">
  169. p { font-weight: normal; color: gray; }
  170. .org-agenda-structure {
  171. font-size: 110%;
  172. color: #003399;
  173. font-weight: 600;
  174. }
  175. .org-todo {
  176. color: #cc6666;
  177. font-weight: bold;
  178. }
  179. .org-agenda-done {
  180. color: #339933;
  181. }
  182. .org-done {
  183. color: #339933;
  184. }
  185. .title { text-align: center; }
  186. .todo, .deadline { color: red; }
  187. .done { color: green; }
  188. </style>
  189. or, if you want to keep the style in a file,
  190. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  191. As the value of this option simply gets inserted into the HTML <head> header,
  192. you can \"misuse\" it to also add other text to the header. However,
  193. <style>...</style> is required, if not present the variable will be ignored."
  194. :group 'org-agenda-export
  195. :group 'org-export-html
  196. :type 'string)
  197. (defcustom org-agenda-persistent-filter nil
  198. "When set, keep filters from one agenda view to the next."
  199. :group 'org-agenda
  200. :type 'boolean)
  201. (defgroup org-agenda-custom-commands nil
  202. "Options concerning agenda views in Org-mode."
  203. :tag "Org Agenda Custom Commands"
  204. :group 'org-agenda)
  205. (defconst org-sorting-choice
  206. '(choice
  207. (const time-up) (const time-down)
  208. (const category-keep) (const category-up) (const category-down)
  209. (const tag-down) (const tag-up)
  210. (const priority-up) (const priority-down)
  211. (const todo-state-up) (const todo-state-down)
  212. (const effort-up) (const effort-down)
  213. (const habit-up) (const habit-down)
  214. (const alpha-up) (const alpha-down)
  215. (const user-defined-up) (const user-defined-down))
  216. "Sorting choices.")
  217. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  218. ;; the new variable `org-agenda-tag-filter-preset'.
  219. (if (fboundp 'defvaralias)
  220. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  221. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  222. (defconst org-agenda-custom-commands-local-options
  223. `(repeat :tag "Local settings for this command. Remember to quote values"
  224. (choice :tag "Setting"
  225. (list :tag "Heading for this block"
  226. (const org-agenda-overriding-header)
  227. (string :tag "Headline"))
  228. (list :tag "Files to be searched"
  229. (const org-agenda-files)
  230. (list
  231. (const :format "" quote)
  232. (repeat (file))))
  233. (list :tag "Sorting strategy"
  234. (const org-agenda-sorting-strategy)
  235. (list
  236. (const :format "" quote)
  237. (repeat
  238. ,org-sorting-choice)))
  239. (list :tag "Prefix format"
  240. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  241. (string))
  242. (list :tag "Number of days in agenda"
  243. (const org-agenda-span)
  244. (choice (const :tag "Day" 'day)
  245. (const :tag "Week" 'week)
  246. (const :tag "Month" 'month)
  247. (const :tag "Year" 'year)
  248. (integer :tag "Custom")))
  249. (list :tag "Fixed starting date"
  250. (const org-agenda-start-day)
  251. (string :value "2007-11-01"))
  252. (list :tag "Start on day of week"
  253. (const org-agenda-start-on-weekday)
  254. (choice :value 1
  255. (const :tag "Today" nil)
  256. (integer :tag "Weekday No.")))
  257. (list :tag "Include data from diary"
  258. (const org-agenda-include-diary)
  259. (boolean))
  260. (list :tag "Deadline Warning days"
  261. (const org-deadline-warning-days)
  262. (integer :value 1))
  263. (list :tag "Category filter preset"
  264. (const org-agenda-category-filter-preset)
  265. (list
  266. (const :format "" quote)
  267. (repeat
  268. (string :tag "+category or -category"))))
  269. (list :tag "Tags filter preset"
  270. (const org-agenda-tag-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+tag or -tag"))))
  275. (list :tag "Set daily/weekly entry types"
  276. (const org-agenda-entry-types)
  277. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  278. (const :deadline)
  279. (const :scheduled)
  280. (const :timestamp)
  281. (const :sexp)))
  282. (list :tag "Standard skipping condition"
  283. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  284. (const org-agenda-skip-function)
  285. (list
  286. (const :format "" quote)
  287. (list
  288. (choice
  289. :tag "Skipping range"
  290. (const :tag "Skip entry" org-agenda-skip-entry-if)
  291. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  292. (repeat :inline t :tag "Conditions for skipping"
  293. (choice
  294. :tag "Condition type"
  295. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  296. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  297. (list :tag "TODO state is" :inline t
  298. (const 'todo)
  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. (list :tag "TODO state is not" :inline t
  307. (const 'nottodo)
  308. (choice
  309. (const :tag "any not-done state" 'todo)
  310. (const :tag "any done state" 'done)
  311. (const :tag "any state" 'any)
  312. (list :tag "Keyword list"
  313. (const :format "" quote)
  314. (repeat (string :tag "Keyword")))))
  315. (const :tag "scheduled" 'scheduled)
  316. (const :tag "not scheduled" 'notscheduled)
  317. (const :tag "deadline" 'deadline)
  318. (const :tag "no deadline" 'notdeadline)
  319. (const :tag "timestamp" 'timestamp)
  320. (const :tag "no timestamp" 'nottimestamp))))))
  321. (list :tag "Non-standard skipping condition"
  322. :value (org-agenda-skip-function)
  323. (const org-agenda-skip-function)
  324. (sexp :tag "Function or form (quoted!)"))
  325. (list :tag "Any variable"
  326. (variable :tag "Variable")
  327. (sexp :tag "Value (sexp)"))))
  328. "Selection of examples for agenda command settings.
  329. This will be spliced into the custom type of
  330. `org-agenda-custom-commands'.")
  331. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  332. ((agenda "") (alltodo))))
  333. "Custom commands for the agenda.
  334. These commands will be offered on the splash screen displayed by the
  335. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  336. (key desc type match settings files)
  337. key The key (one or more characters as a string) to be associated
  338. with the command.
  339. desc A description of the command, when omitted or nil, a default
  340. description is built using MATCH.
  341. type The command type, any of the following symbols:
  342. agenda The daily/weekly agenda.
  343. todo Entries with a specific TODO keyword, in all agenda files.
  344. search Entries containing search words entry or headline.
  345. tags Tags/Property/TODO match in all agenda files.
  346. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  347. todo-tree Sparse tree of specific TODO keyword in *current* file.
  348. tags-tree Sparse tree with all tags matches in *current* file.
  349. occur-tree Occur sparse tree for *current* file.
  350. ... A user-defined function.
  351. match What to search for:
  352. - a single keyword for TODO keyword searches
  353. - a tags match expression for tags searches
  354. - a word search expression for text searches.
  355. - a regular expression for occur searches
  356. For all other commands, this should be the empty string.
  357. settings A list of option settings, similar to that in a let form, so like
  358. this: ((opt1 val1) (opt2 val2) ...). The values will be
  359. evaluated at the moment of execution, so quote them when needed.
  360. files A list of files file to write the produced agenda buffer to
  361. with the command `org-store-agenda-views'.
  362. If a file name ends in \".html\", an HTML version of the buffer
  363. is written out. If it ends in \".ps\", a postscript version is
  364. produced. Otherwise, only the plain text is written to the file.
  365. You can also define a set of commands, to create a composite agenda buffer.
  366. In this case, an entry looks like this:
  367. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  368. where
  369. desc A description string to be displayed in the dispatcher menu.
  370. cmd An agenda command, similar to the above. However, tree commands
  371. are no allowed, but instead you can get agenda and global todo list.
  372. So valid commands for a set are:
  373. (agenda \"\" settings)
  374. (alltodo \"\" settings)
  375. (stuck \"\" settings)
  376. (todo \"match\" settings files)
  377. (search \"match\" settings files)
  378. (tags \"match\" settings files)
  379. (tags-todo \"match\" settings files)
  380. Each command can carry a list of options, and another set of options can be
  381. given for the whole set of commands. Individual command options take
  382. precedence over the general options.
  383. When using several characters as key to a command, the first characters
  384. are prefix commands. For the dispatcher to display useful information, you
  385. should provide a description for the prefix, like
  386. (setq org-agenda-custom-commands
  387. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  388. (\"hl\" tags \"+HOME+Lisa\")
  389. (\"hp\" tags \"+HOME+Peter\")
  390. (\"hk\" tags \"+HOME+Kim\")))"
  391. :group 'org-agenda-custom-commands
  392. :type `(repeat
  393. (choice :value ("x" "Describe command here" tags "" nil)
  394. (list :tag "Single command"
  395. (string :tag "Access Key(s) ")
  396. (option (string :tag "Description"))
  397. (choice
  398. (const :tag "Agenda" agenda)
  399. (const :tag "TODO list" alltodo)
  400. (const :tag "Search words" search)
  401. (const :tag "Stuck projects" stuck)
  402. (const :tag "Tags/Property match (all agenda files)" tags)
  403. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  404. (const :tag "TODO keyword search (all agenda files)" todo)
  405. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  406. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  407. (const :tag "Occur tree (current buffer)" occur-tree)
  408. (sexp :tag "Other, user-defined function"))
  409. (string :tag "Match (only for some commands)")
  410. ,org-agenda-custom-commands-local-options
  411. (option (repeat :tag "Export" (file :tag "Export to"))))
  412. (list :tag "Command series, all agenda files"
  413. (string :tag "Access Key(s)")
  414. (string :tag "Description ")
  415. (repeat :tag "Component"
  416. (choice
  417. (list :tag "Agenda"
  418. (const :format "" agenda)
  419. (const :tag "" :format "" "")
  420. ,org-agenda-custom-commands-local-options)
  421. (list :tag "TODO list (all keywords)"
  422. (const :format "" alltodo)
  423. (const :tag "" :format "" "")
  424. ,org-agenda-custom-commands-local-options)
  425. (list :tag "Search words"
  426. (const :format "" search)
  427. (string :tag "Match")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "Stuck projects"
  430. (const :format "" stuck)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Tags search"
  434. (const :format "" tags)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Tags search, TODO entries only"
  438. (const :format "" tags-todo)
  439. (string :tag "Match")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "TODO keyword search"
  442. (const :format "" todo)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Other, user-defined function"
  446. (symbol :tag "function")
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)))
  449. (repeat :tag "Settings for entire command set"
  450. (list (variable :tag "Any variable")
  451. (sexp :tag "Value")))
  452. (option (repeat :tag "Export" (file :tag "Export to"))))
  453. (cons :tag "Prefix key documentation"
  454. (string :tag "Access Key(s)")
  455. (string :tag "Description ")))))
  456. (defcustom org-agenda-query-register ?o
  457. "The register holding the current query string.
  458. The purpose of this is that if you construct a query string interactively,
  459. you can then use it to define a custom command."
  460. :group 'org-agenda-custom-commands
  461. :type 'character)
  462. (defcustom org-stuck-projects
  463. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  464. "How to identify stuck projects.
  465. This is a list of four items:
  466. 1. A tags/todo/property matcher string that is used to identify a project.
  467. See the manual for a description of tag and property searches.
  468. The entire tree below a headline matched by this is considered one project.
  469. 2. A list of TODO keywords identifying non-stuck projects.
  470. If the project subtree contains any headline with one of these todo
  471. keywords, the project is considered to be not stuck. If you specify
  472. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  473. 3. A list of tags identifying non-stuck projects.
  474. If the project subtree contains any headline with one of these tags,
  475. the project is considered to be not stuck. If you specify \"*\" as
  476. a tag, any tag will mark the project unstuck. Note that this is about
  477. the explicit presence of a tag somewhere in the subtree, inherited
  478. tags to not count here. If inherited tags make a project not stuck,
  479. use \"-TAG\" in the tags part of the matcher under (1.) above.
  480. 4. An arbitrary regular expression matching non-stuck projects.
  481. If the project turns out to be not stuck, search continues also in the
  482. subtree to see if any of the subtasks have project status.
  483. See also the variable `org-tags-match-list-sublevels' which applies
  484. to projects matched by this search as well.
  485. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  486. or `C-c a #' to produce the list."
  487. :group 'org-agenda-custom-commands
  488. :type '(list
  489. (string :tag "Tags/TODO match to identify a project")
  490. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  491. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  492. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  493. (defcustom org-agenda-filter-effort-default-operator "<"
  494. "The default operator for effort estimate filtering.
  495. If you select an effort estimate limit without first pressing an operator,
  496. this one will be used."
  497. :group 'org-agenda-custom-commands
  498. :type '(choice (const :tag "less or equal" "<")
  499. (const :tag "greater or equal"">")
  500. (const :tag "equal" "=")))
  501. (defgroup org-agenda-skip nil
  502. "Options concerning skipping parts of agenda files."
  503. :tag "Org Agenda Skip"
  504. :group 'org-agenda)
  505. (defcustom org-agenda-skip-function-global nil
  506. "Function to be called at each match during agenda construction.
  507. If this function returns nil, the current match should not be skipped.
  508. If the function decided to skip an agenda match, is must return the
  509. buffer position from which the search should be continued.
  510. This may also be a Lisp form, which will be evaluated.
  511. This variable will be applied to every agenda match, including
  512. tags/property searches and TODO lists. So try to make the test function
  513. do its checking as efficiently as possible. To implement a skipping
  514. condition just for specific agenda commands, use the variable
  515. `org-agenda-skip-function' which can be set in the options section
  516. of custom agenda commands."
  517. :group 'org-agenda-skip
  518. :type 'sexp)
  519. (defgroup org-agenda-daily/weekly nil
  520. "Options concerning the daily/weekly agenda."
  521. :tag "Org Agenda Daily/Weekly"
  522. :group 'org-agenda)
  523. (defgroup org-agenda-todo-list nil
  524. "Options concerning the global todo list agenda view."
  525. :tag "Org Agenda Todo List"
  526. :group 'org-agenda)
  527. (defgroup org-agenda-match-view nil
  528. "Options concerning the general tags/property/todo match agenda view."
  529. :tag "Org Agenda Match View"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-search-view nil
  532. "Options concerning the general tags/property/todo match agenda view."
  533. :tag "Org Agenda Match View"
  534. :group 'org-agenda)
  535. (defvar org-agenda-archives-mode nil
  536. "Non-nil means the agenda will include archived items.
  537. If this is the symbol `trees', trees in the selected agenda scope
  538. that are marked with the ARCHIVE tag will be included anyway. When this is
  539. t, also all archive files associated with the current selection of agenda
  540. files will be included.")
  541. (defcustom org-agenda-skip-comment-trees t
  542. "Non-nil means skip trees that start with the COMMENT keyword.
  543. When nil, these trees are also scanned by agenda commands."
  544. :group 'org-agenda-skip
  545. :type 'boolean)
  546. (defcustom org-agenda-todo-list-sublevels t
  547. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  548. When nil, the sublevels of a TODO entry are not checked, resulting in
  549. potentially much shorter TODO lists."
  550. :group 'org-agenda-skip
  551. :group 'org-agenda-todo-list
  552. :type 'boolean)
  553. (defcustom org-agenda-todo-ignore-with-date nil
  554. "Non-nil means don't show entries with a date in the global todo list.
  555. You can use this if you prefer to mark mere appointments with a TODO keyword,
  556. but don't want them to show up in the TODO list.
  557. When this is set, it also covers deadlines and scheduled items, the settings
  558. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  559. will be ignored.
  560. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  561. :group 'org-agenda-skip
  562. :group 'org-agenda-todo-list
  563. :type 'boolean)
  564. (defcustom org-agenda-todo-ignore-timestamp nil
  565. "Non-nil means don't show entries with a timestamp.
  566. This applies when creating the global todo list.
  567. Valid values are:
  568. past Don't show entries for today or in the past.
  569. future Don't show entries with a timestamp in the future.
  570. The idea behind this is that if it has a future
  571. timestamp, you don't want to think about it until the
  572. date.
  573. all Don't show any entries with a timestamp in the global todo list.
  574. The idea behind this is that by setting a timestamp, you
  575. have already \"taken care\" of this item.
  576. This variable can also have an integer as a value. If positive (N),
  577. todos with a timestamp N or more days in the future will be ignored. If
  578. negative (-N), todos with a timestamp N or more days in the past will be
  579. ignored. If 0, todos with a timestamp either today or in the future will
  580. be ignored. For example, a value of -1 will exclude todos with a
  581. timestamp in the past (yesterday or earlier), while a value of 7 will
  582. exclude todos with a timestamp a week or more in the future.
  583. See also `org-agenda-todo-ignore-with-date'.
  584. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  585. to make his option also apply to the tags-todo list."
  586. :group 'org-agenda-skip
  587. :group 'org-agenda-todo-list
  588. :type '(choice
  589. (const :tag "Ignore future timestamp todos" future)
  590. (const :tag "Ignore past or present timestamp todos" past)
  591. (const :tag "Ignore all timestamp todos" all)
  592. (const :tag "Show timestamp todos" nil)
  593. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  594. (defcustom org-agenda-todo-ignore-scheduled nil
  595. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  596. This applies when creating the global todo list.
  597. Valid values are:
  598. past Don't show entries scheduled today or in the past.
  599. future Don't show entries scheduled in the future.
  600. The idea behind this is that by scheduling it, you don't want to
  601. think about it until the scheduled date.
  602. all Don't show any scheduled entries in the global todo list.
  603. The idea behind this is that by scheduling it, you have already
  604. \"taken care\" of this item.
  605. t Same as `all', for backward compatibility.
  606. This variable can also have an integer as a value. See
  607. `org-agenda-todo-ignore-timestamp' for more details.
  608. See also `org-agenda-todo-ignore-with-date'.
  609. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  610. to make his option also apply to the tags-todo list."
  611. :group 'org-agenda-skip
  612. :group 'org-agenda-todo-list
  613. :type '(choice
  614. (const :tag "Ignore future-scheduled todos" future)
  615. (const :tag "Ignore past- or present-scheduled todos" past)
  616. (const :tag "Ignore all scheduled todos" all)
  617. (const :tag "Ignore all scheduled todos (compatibility)" t)
  618. (const :tag "Show scheduled todos" nil)
  619. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  620. (defcustom org-agenda-todo-ignore-deadlines nil
  621. "Non-nil means ignore some deadlined TODO items when making TODO list.
  622. There are different motivations for using different values, please think
  623. carefully when configuring this variable.
  624. This applies when creating the global todo list.
  625. Valid values are:
  626. near Don't show near deadline entries. A deadline is near when it is
  627. closer than `org-deadline-warning-days' days. The idea behind this
  628. is that such items will appear in the agenda anyway.
  629. far Don't show TODO entries where a deadline has been defined, but
  630. the deadline is not near. This is useful if you don't want to
  631. use the todo list to figure out what to do now.
  632. past Don't show entries with a deadline timestamp for today or in the past.
  633. future Don't show entries with a deadline timestamp in the future, not even
  634. when they become `near' ones. Use it with caution.
  635. all Ignore all TODO entries that do have a deadline.
  636. t Same as `near', for backward compatibility.
  637. This variable can also have an integer as a value. See
  638. `org-agenda-todo-ignore-timestamp' for more details.
  639. See also `org-agenda-todo-ignore-with-date'.
  640. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  641. to make his option also apply to the tags-todo list."
  642. :group 'org-agenda-skip
  643. :group 'org-agenda-todo-list
  644. :type '(choice
  645. (const :tag "Ignore near deadlines" near)
  646. (const :tag "Ignore near deadlines (compatibility)" t)
  647. (const :tag "Ignore far deadlines" far)
  648. (const :tag "Ignore all TODOs with a deadlines" all)
  649. (const :tag "Show all TODOs, even if they have a deadline" nil)
  650. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  651. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  652. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  653. The variables
  654. `org-agenda-todo-ignore-with-date',
  655. `org-agenda-todo-ignore-timestamp',
  656. `org-agenda-todo-ignore-scheduled',
  657. `org-agenda-todo-ignore-deadlines'
  658. make the global TODO list skip entries that have time stamps of certain
  659. kinds. If this option is set, the same options will also apply for the
  660. tags-todo search, which is the general tags/property matcher
  661. restricted to unfinished TODO entries only."
  662. :group 'org-agenda-skip
  663. :group 'org-agenda-todo-list
  664. :group 'org-agenda-match-view
  665. :type 'boolean)
  666. (defcustom org-agenda-skip-scheduled-if-done nil
  667. "Non-nil means don't show scheduled items in agenda when they are done.
  668. This is relevant for the daily/weekly agenda, not for the TODO list. And
  669. it applies only to the actual date of the scheduling. Warnings about
  670. an item with a past scheduling dates are always turned off when the item
  671. is DONE."
  672. :group 'org-agenda-skip
  673. :group 'org-agenda-daily/weekly
  674. :type 'boolean)
  675. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  676. "Non-nil means skip scheduling line if same entry shows because of deadline.
  677. In the agenda of today, an entry can show up multiple times because
  678. it is both scheduled and has a nearby deadline, and maybe a plain time
  679. stamp as well.
  680. When this variable is t, then only the deadline is shown and the fact that
  681. the entry is scheduled today or was scheduled previously is not shown.
  682. When this variable is nil, the entry will be shown several times. When
  683. the variable is the symbol `not-today', then skip scheduled previously,
  684. but not scheduled today."
  685. :group 'org-agenda-skip
  686. :group 'org-agenda-daily/weekly
  687. :type '(choice
  688. (const :tag "Never" nil)
  689. (const :tag "Always" t)
  690. (const :tag "Not when scheduled today" not-today)))
  691. (defcustom org-agenda-skip-deadline-if-done nil
  692. "Non-nil means don't show deadlines when the corresponding item is done.
  693. When nil, the deadline is still shown and should give you a happy feeling.
  694. This is relevant for the daily/weekly agenda. And it applied only to the
  695. actually date of the deadline. Warnings about approaching and past-due
  696. deadlines are always turned off when the item is DONE."
  697. :group 'org-agenda-skip
  698. :group 'org-agenda-daily/weekly
  699. :type 'boolean)
  700. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  701. "Non-nil means skip deadline prewarning when entry is also scheduled.
  702. This will apply on all days where a prewarning for the deadline would
  703. be shown, but not at the day when the entry is actually due. On that day,
  704. the deadline will be shown anyway.
  705. This variable may be set to nil, t, or a number which will then give
  706. the number of days before the actual deadline when the prewarnings
  707. should resume.
  708. This can be used in a workflow where the first showing of the deadline will
  709. trigger you to schedule it, and then you don't want to be reminded of it
  710. because you will take care of it on the day when scheduled."
  711. :group 'org-agenda-skip
  712. :group 'org-agenda-daily/weekly
  713. :type '(choice
  714. (const :tag "Alwas show prewarning" nil)
  715. (const :tag "Remove prewarning if entry is scheduled" t)
  716. (integer :tag "Restart prewarning N days before deadline")))
  717. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  718. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  719. When non-nil, after the search for timestamps has matched once in an
  720. entry, the rest of the entry will not be searched."
  721. :group 'org-agenda-skip
  722. :type 'boolean)
  723. (defcustom org-agenda-skip-timestamp-if-done nil
  724. "Non-nil means don't select item by timestamp or -range if it is DONE."
  725. :group 'org-agenda-skip
  726. :group 'org-agenda-daily/weekly
  727. :type 'boolean)
  728. (defcustom org-agenda-dim-blocked-tasks t
  729. "Non-nil means dim blocked tasks in the agenda display.
  730. This causes some overhead during agenda construction, but if you
  731. have turned on `org-enforce-todo-dependencies',
  732. `org-enforce-todo-checkbox-dependencies', or any other blocking
  733. mechanism, this will create useful feedback in the agenda.
  734. Instead of t, this variable can also have the value `invisible'.
  735. Then blocked tasks will be invisible and only become visible when
  736. they become unblocked. An exemption to this behavior is when a task is
  737. blocked because of unchecked checkboxes below it. Since checkboxes do
  738. not show up in the agenda views, making this task invisible you remove any
  739. trace from agenda views that there is something to do. Therefore, a task
  740. that is blocked because of checkboxes will never be made invisible, it
  741. will only be dimmed."
  742. :group 'org-agenda-daily/weekly
  743. :group 'org-agenda-todo-list
  744. :type '(choice
  745. (const :tag "Do not dim" nil)
  746. (const :tag "Dim to a gray face" t)
  747. (const :tag "Make invisible" invisible)))
  748. (defcustom org-timeline-show-empty-dates 3
  749. "Non-nil means `org-timeline' also shows dates without an entry.
  750. When nil, only the days which actually have entries are shown.
  751. When t, all days between the first and the last date are shown.
  752. When an integer, show also empty dates, but if there is a gap of more than
  753. N days, just insert a special line indicating the size of the gap."
  754. :group 'org-agenda-skip
  755. :type '(choice
  756. (const :tag "None" nil)
  757. (const :tag "All" t)
  758. (integer :tag "at most")))
  759. (defgroup org-agenda-startup nil
  760. "Options concerning initial settings in the Agenda in Org Mode."
  761. :tag "Org Agenda Startup"
  762. :group 'org-agenda)
  763. (defcustom org-agenda-menu-show-matcher t
  764. "Non-nil means show the match string in the agenda dispatcher menu.
  765. When nil, the matcher string is not shown, but is put into the help-echo
  766. property so than moving the mouse over the command shows it.
  767. Setting it to nil is good if matcher strings are very long and/or if
  768. you want to use two-column display (see `org-agenda-menu-two-column')."
  769. :group 'org-agenda
  770. :type 'boolean)
  771. (defcustom org-agenda-menu-two-column nil
  772. "Non-nil means, use two columns to show custom commands in the dispatcher.
  773. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  774. to nil."
  775. :group 'org-agenda
  776. :type 'boolean)
  777. (defcustom org-finalize-agenda-hook nil
  778. "Hook run just before displaying an agenda buffer."
  779. :group 'org-agenda-startup
  780. :type 'hook)
  781. (defcustom org-agenda-mouse-1-follows-link nil
  782. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  783. A longer mouse click will still set point. Does not work on XEmacs.
  784. Needs to be set before org.el is loaded."
  785. :group 'org-agenda-startup
  786. :type 'boolean)
  787. (defcustom org-agenda-start-with-follow-mode nil
  788. "The initial value of follow mode in a newly created agenda window."
  789. :group 'org-agenda-startup
  790. :type 'boolean)
  791. (defcustom org-agenda-follow-indirect nil
  792. "Non-nil means `org-agenda-follow-mode' displays only the
  793. current item's tree, in an indirect buffer."
  794. :group 'org-agenda
  795. :type 'boolean)
  796. (defcustom org-agenda-show-outline-path t
  797. "Non-nil means show outline path in echo area after line motion."
  798. :group 'org-agenda-startup
  799. :type 'boolean)
  800. (defcustom org-agenda-start-with-entry-text-mode nil
  801. "The initial value of entry-text-mode in a newly created agenda window."
  802. :group 'org-agenda-startup
  803. :type 'boolean)
  804. (defcustom org-agenda-entry-text-maxlines 5
  805. "Number of text lines to be added when `E' is pressed in the agenda.
  806. Note that this variable only used during agenda display. Add add entry text
  807. when exporting the agenda, configure the variable
  808. `org-agenda-add-entry-ext-maxlines'."
  809. :group 'org-agenda
  810. :type 'integer)
  811. (defcustom org-agenda-entry-text-exclude-regexps nil
  812. "List of regular expressions to clean up entry text.
  813. The complete matches of all regular expressions in this list will be
  814. removed from entry text before it is shown in the agenda."
  815. :group 'org-agenda
  816. :type '(repeat (regexp)))
  817. (defvar org-agenda-entry-text-cleanup-hook nil
  818. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  819. This cleanup is done in a temporary buffer, so the function may inspect and
  820. change the entire buffer.
  821. Some default stuff like drawers and scheduling/deadline dates will already
  822. have been removed when this is called, as will any matches for regular
  823. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  824. (defvar org-agenda-include-inactive-timestamps nil
  825. "Non-nil means include inactive time stamps in agenda and timeline.")
  826. (defgroup org-agenda-windows nil
  827. "Options concerning the windows used by the Agenda in Org Mode."
  828. :tag "Org Agenda Windows"
  829. :group 'org-agenda)
  830. (defcustom org-agenda-window-setup 'reorganize-frame
  831. "How the agenda buffer should be displayed.
  832. Possible values for this option are:
  833. current-window Show agenda in the current window, keeping all other windows.
  834. other-window Use `switch-to-buffer-other-window' to display agenda.
  835. reorganize-frame Show only two windows on the current frame, the current
  836. window and the agenda.
  837. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  838. Also, when exiting the agenda, kill that frame.
  839. See also the variable `org-agenda-restore-windows-after-quit'."
  840. :group 'org-agenda-windows
  841. :type '(choice
  842. (const current-window)
  843. (const other-frame)
  844. (const other-window)
  845. (const reorganize-frame)))
  846. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  847. "The min and max height of the agenda window as a fraction of frame height.
  848. The value of the variable is a cons cell with two numbers between 0 and 1.
  849. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  850. :group 'org-agenda-windows
  851. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  852. (defcustom org-agenda-restore-windows-after-quit nil
  853. "Non-nil means restore window configuration upon exiting agenda.
  854. Before the window configuration is changed for displaying the agenda,
  855. the current status is recorded. When the agenda is exited with
  856. `q' or `x' and this option is set, the old state is restored. If
  857. `org-agenda-window-setup' is `other-frame', the value of this
  858. option will be ignored."
  859. :group 'org-agenda-windows
  860. :type 'boolean)
  861. (defcustom org-agenda-ndays nil
  862. "Number of days to include in overview display.
  863. Should be 1 or 7.
  864. Obsolete, see `org-agenda-span'."
  865. :group 'org-agenda-daily/weekly
  866. :type 'integer)
  867. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  868. (defcustom org-agenda-span 'week
  869. "Number of days to include in overview display.
  870. Can be day, week, month, year, or any number of days.
  871. Custom commands can set this variable in the options section."
  872. :group 'org-agenda-daily/weekly
  873. :type '(choice (const :tag "Day" day)
  874. (const :tag "Week" week)
  875. (const :tag "Month" month)
  876. (const :tag "Year" year)
  877. (integer :tag "Custom")))
  878. (defcustom org-agenda-start-on-weekday 1
  879. "Non-nil means start the overview always on the specified weekday.
  880. 0 denotes Sunday, 1 denotes Monday etc.
  881. When nil, always start on the current day.
  882. Custom commands can set this variable in the options section."
  883. :group 'org-agenda-daily/weekly
  884. :type '(choice (const :tag "Today" nil)
  885. (integer :tag "Weekday No.")))
  886. (defcustom org-agenda-show-all-dates t
  887. "Non-nil means `org-agenda' shows every day in the selected range.
  888. When nil, only the days which actually have entries are shown."
  889. :group 'org-agenda-daily/weekly
  890. :type 'boolean)
  891. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  892. "Format string for displaying dates in the agenda.
  893. Used by the daily/weekly agenda and by the timeline. This should be
  894. a format string understood by `format-time-string', or a function returning
  895. the formatted date as a string. The function must take a single argument,
  896. a calendar-style date list like (month day year)."
  897. :group 'org-agenda-daily/weekly
  898. :type '(choice
  899. (string :tag "Format string")
  900. (function :tag "Function")))
  901. (defun org-agenda-format-date-aligned (date)
  902. "Format a date string for display in the daily/weekly agenda, or timeline.
  903. This function makes sure that dates are aligned for easy reading."
  904. (require 'cal-iso)
  905. (let* ((dayname (calendar-day-name date))
  906. (day (cadr date))
  907. (day-of-week (calendar-day-of-week date))
  908. (month (car date))
  909. (monthname (calendar-month-name month))
  910. (year (nth 2 date))
  911. (iso-week (org-days-to-iso-week
  912. (calendar-absolute-from-gregorian date)))
  913. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  914. (1- year))
  915. ((and (= month 12) (<= iso-week 1))
  916. (1+ year))
  917. (t year)))
  918. (weekstring (if (= day-of-week 1)
  919. (format " W%02d" iso-week)
  920. "")))
  921. (format "%-10s %2d %s %4d%s"
  922. dayname day monthname year weekstring)))
  923. (defcustom org-agenda-time-leading-zero nil
  924. "Non-nil means use leading zero for military times in agenda.
  925. For example, 9:30am would become 09:30 rather than 9:30."
  926. :group 'org-agenda-daily/weekly
  927. :type 'boolean)
  928. (defcustom org-agenda-timegrid-use-ampm nil
  929. "When set, show AM/PM style timestamps on the timegrid."
  930. :group 'org-agenda
  931. :type 'boolean)
  932. (defun org-agenda-time-of-day-to-ampm (time)
  933. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  934. (let* ((hour-number (string-to-number (substring time 0 -3)))
  935. (minute (substring time -2))
  936. (ampm "am"))
  937. (cond
  938. ((equal hour-number 12)
  939. (setq ampm "pm"))
  940. ((> hour-number 12)
  941. (setq ampm "pm")
  942. (setq hour-number (- hour-number 12))))
  943. (concat
  944. (if org-agenda-time-leading-zero
  945. (format "%02d" hour-number)
  946. (format "%02s" (number-to-string hour-number)))
  947. ":" minute ampm)))
  948. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  949. "Conditionally convert TIME to AM/PM format
  950. based on `org-agenda-timegrid-use-ampm'"
  951. (if org-agenda-timegrid-use-ampm
  952. (org-agenda-time-of-day-to-ampm time)
  953. time))
  954. (defcustom org-agenda-weekend-days '(6 0)
  955. "Which days are weekend?
  956. These days get the special face `org-agenda-date-weekend' in the agenda
  957. and timeline buffers."
  958. :group 'org-agenda-daily/weekly
  959. :type '(set :greedy t
  960. (const :tag "Monday" 1)
  961. (const :tag "Tuesday" 2)
  962. (const :tag "Wednesday" 3)
  963. (const :tag "Thursday" 4)
  964. (const :tag "Friday" 5)
  965. (const :tag "Saturday" 6)
  966. (const :tag "Sunday" 0)))
  967. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  968. "Non-nil means jump to today when moving a past date forward in time.
  969. When using S-right in the agenda to move a a date forward, and the date
  970. stamp currently points to the past, the first key press will move it
  971. to today. WHen nil, just move one day forward even if the date stays
  972. in the past."
  973. :group 'org-agenda-daily/weekly
  974. :type 'boolean)
  975. (defcustom org-agenda-include-diary nil
  976. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  977. Custom commands can set this variable in the options section."
  978. :group 'org-agenda-daily/weekly
  979. :type 'boolean)
  980. (defcustom org-agenda-include-deadlines t
  981. "If non-nil, include entries within their deadline warning period.
  982. Custom commands can set this variable in the options section."
  983. :group 'org-agenda-daily/weekly
  984. :type 'boolean)
  985. (defcustom org-agenda-repeating-timestamp-show-all t
  986. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  987. When set to a list of strings, only show occurrences of repeating
  988. stamps for these TODO keywords. When nil, only one occurrence is
  989. shown, either today or the nearest into the future."
  990. :group 'org-agenda-daily/weekly
  991. :type '(choice
  992. (const :tag "Show repeating stamps" t)
  993. (repeat :tag "Show repeating stamps for these TODO keywords"
  994. (string :tag "TODO Keyword"))
  995. (const :tag "Don't show repeating stamps" nil)))
  996. (defcustom org-scheduled-past-days 10000
  997. "No. of days to continue listing scheduled items that are not marked DONE.
  998. When an item is scheduled on a date, it shows up in the agenda on this
  999. day and will be listed until it is marked done for the number of days
  1000. given here."
  1001. :group 'org-agenda-daily/weekly
  1002. :type 'integer)
  1003. (defcustom org-agenda-log-mode-items '(closed clock)
  1004. "List of items that should be shown in agenda log mode.
  1005. This list may contain the following symbols:
  1006. closed Show entries that have been closed on that day.
  1007. clock Show entries that have received clocked time on that day.
  1008. state Show all logged state changes.
  1009. Note that instead of changing this variable, you can also press `C-u l' in
  1010. the agenda to display all available LOG items temporarily."
  1011. :group 'org-agenda-daily/weekly
  1012. :type '(set :greedy t (const closed) (const clock) (const state)))
  1013. (defcustom org-agenda-clock-consistency-checks
  1014. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1015. :gap-ok-around ("4:00")
  1016. :default-face ((:background "DarkRed") (:foreground "white"))
  1017. :overlap-face nil :gap-face nil :no-end-time-face nil
  1018. :long-face nil :short-face nil)
  1019. "This is a property list, with the following keys:
  1020. :max-duration Mark clocking chunks that are longer than this time.
  1021. This is a time string like \"HH:MM\", or the number
  1022. of minutes as an integer.
  1023. :min-duration Mark clocking chunks that are shorter that this.
  1024. This is a time string like \"HH:MM\", or the number
  1025. of minutes as an integer.
  1026. :max-gap Mark gaps between clocking chunks that are longer than
  1027. this duration. A number of minutes, or a string
  1028. like \"HH:MM\".
  1029. :gap-ok-around List of times during the day which are usually not working
  1030. times. When a gap is detected, but the gap contains any
  1031. of these times, the gap is *not* reported. For example,
  1032. if this is (\"4:00\" \"13:00\") then gaps that contain
  1033. 4:00 in the morning (i.e. the night) and 13:00
  1034. (i.e. a typical lunch time) do not cause a warning.
  1035. You should have at least one time during the night in this
  1036. list, or otherwise the first task each morning will trigger
  1037. a warning because it follows a long gap.
  1038. Furthermore, the following properties can be used to define faces for
  1039. issue display.
  1040. :default-face the default face, if the specific face is undefined
  1041. :overlap-face face for overlapping clocks
  1042. :gap-face face for gaps between clocks
  1043. :no-end-time-face face for incomplete clocks
  1044. :long-face face for clock intervals that are too long
  1045. :short-face face for clock intervals that are too short"
  1046. :group 'org-agenda-daily/weekly
  1047. :group 'org-clock
  1048. :type 'plist)
  1049. (defcustom org-agenda-log-mode-add-notes t
  1050. "Non-nil means add first line of notes to log entries in agenda views.
  1051. If a log item like a state change or a clock entry is associated with
  1052. notes, the first line of these notes will be added to the entry in the
  1053. agenda display."
  1054. :group 'org-agenda-daily/weekly
  1055. :type 'boolean)
  1056. (defcustom org-agenda-start-with-log-mode nil
  1057. "The initial value of log-mode in a newly created agenda window."
  1058. :group 'org-agenda-startup
  1059. :group 'org-agenda-daily/weekly
  1060. :type 'boolean)
  1061. (defcustom org-agenda-start-with-clockreport-mode nil
  1062. "The initial value of clockreport-mode in a newly created agenda window."
  1063. :group 'org-agenda-startup
  1064. :group 'org-agenda-daily/weekly
  1065. :type 'boolean)
  1066. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1067. "Property list with parameters for the clocktable in clockreport mode.
  1068. This is the display mode that shows a clock table in the daily/weekly
  1069. agenda, the properties for this dynamic block can be set here.
  1070. The usual clocktable parameters are allowed here, but you cannot set
  1071. the properties :name, :tstart, :tend, :block, and :scope - these will
  1072. be overwritten to make sure the content accurately reflects the
  1073. current display in the agenda."
  1074. :group 'org-agenda-daily/weekly
  1075. :type 'plist)
  1076. (defcustom org-agenda-search-view-always-boolean nil
  1077. "Non-nil means the search string is interpreted as individual parts.
  1078. The search string for search view can either be interpreted as a phrase,
  1079. or as a list of snippets that define a boolean search for a number of
  1080. strings.
  1081. When this is non-nil, the string will be split on whitespace, and each
  1082. snippet will be searched individually, and all must match in order to
  1083. select an entry. A snippet is then a single string of non-white
  1084. characters, or a string in double quotes, or a regexp in {} braces.
  1085. If a snippet is preceded by \"-\", the snippet must *not* match.
  1086. \"+\" is syntactic sugar for positive selection. Each snippet may
  1087. be found as a full word or a partial word, but see the variable
  1088. `org-agenda-search-view-force-full-words'.
  1089. When this is nil, search will look for the entire search phrase as one,
  1090. with each space character matching any amount of whitespace, including
  1091. line breaks.
  1092. Even when this is nil, you can still switch to Boolean search dynamically
  1093. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1094. is a regexp marked with braces like \"{abc}\", this will also switch to
  1095. boolean search."
  1096. :group 'org-agenda-search-view
  1097. :type 'boolean)
  1098. (if (fboundp 'defvaralias)
  1099. (defvaralias 'org-agenda-search-view-search-words-only
  1100. 'org-agenda-search-view-always-boolean))
  1101. (defcustom org-agenda-search-view-force-full-words nil
  1102. "Non-nil means, search words must be matches as complete words.
  1103. When nil, they may also match part of a word."
  1104. :group 'org-agenda-search-view
  1105. :type 'boolean)
  1106. (defgroup org-agenda-time-grid nil
  1107. "Options concerning the time grid in the Org-mode Agenda."
  1108. :tag "Org Agenda Time Grid"
  1109. :group 'org-agenda)
  1110. (defcustom org-agenda-search-headline-for-time t
  1111. "Non-nil means search headline for a time-of-day.
  1112. If the headline contains a time-of-day in one format or another, it will
  1113. be used to sort the entry into the time sequence of items for a day.
  1114. Some people have time stamps in the headline that refer to the creation
  1115. time or so, and then this produces an unwanted side effect. If this is
  1116. the case for your, use this variable to turn off searching the headline
  1117. for a time."
  1118. :group 'org-agenda-time-grid
  1119. :type 'boolean)
  1120. (defcustom org-agenda-use-time-grid t
  1121. "Non-nil means show a time grid in the agenda schedule.
  1122. A time grid is a set of lines for specific times (like every two hours between
  1123. 8:00 and 20:00). The items scheduled for a day at specific times are
  1124. sorted in between these lines.
  1125. For details about when the grid will be shown, and what it will look like, see
  1126. the variable `org-agenda-time-grid'."
  1127. :group 'org-agenda-time-grid
  1128. :type 'boolean)
  1129. (defcustom org-agenda-time-grid
  1130. '((daily today require-timed)
  1131. "----------------"
  1132. (800 1000 1200 1400 1600 1800 2000))
  1133. "The settings for time grid for agenda display.
  1134. This is a list of three items. The first item is again a list. It contains
  1135. symbols specifying conditions when the grid should be displayed:
  1136. daily if the agenda shows a single day
  1137. weekly if the agenda shows an entire week
  1138. today show grid on current date, independent of daily/weekly display
  1139. require-timed show grid only if at least one item has a time specification
  1140. The second item is a string which will be placed behind the grid time.
  1141. The third item is a list of integers, indicating the times that should have
  1142. a grid line."
  1143. :group 'org-agenda-time-grid
  1144. :type
  1145. '(list
  1146. (set :greedy t :tag "Grid Display Options"
  1147. (const :tag "Show grid in single day agenda display" daily)
  1148. (const :tag "Show grid in weekly agenda display" weekly)
  1149. (const :tag "Always show grid for today" today)
  1150. (const :tag "Show grid only if any timed entries are present"
  1151. require-timed)
  1152. (const :tag "Skip grid times already present in an entry"
  1153. remove-match))
  1154. (string :tag "Grid String")
  1155. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1156. (defcustom org-agenda-show-current-time-in-grid t
  1157. "Non-nil means show the current time in the time grid."
  1158. :group 'org-agenda-time-grid
  1159. :type 'boolean)
  1160. (defcustom org-agenda-current-time-string
  1161. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1162. "The string for the current time marker in the agenda."
  1163. :group 'org-agenda-time-grid
  1164. :type 'string)
  1165. (defgroup org-agenda-sorting nil
  1166. "Options concerning sorting in the Org-mode Agenda."
  1167. :tag "Org Agenda Sorting"
  1168. :group 'org-agenda)
  1169. (defcustom org-agenda-sorting-strategy
  1170. '((agenda habit-down time-up priority-down category-keep)
  1171. (todo priority-down category-keep)
  1172. (tags priority-down category-keep)
  1173. (search category-keep))
  1174. "Sorting structure for the agenda items of a single day.
  1175. This is a list of symbols which will be used in sequence to determine
  1176. if an entry should be listed before another entry. The following
  1177. symbols are recognized:
  1178. time-up Put entries with time-of-day indications first, early first
  1179. time-down Put entries with time-of-day indications first, late first
  1180. category-keep Keep the default order of categories, corresponding to the
  1181. sequence in `org-agenda-files'.
  1182. category-up Sort alphabetically by category, A-Z.
  1183. category-down Sort alphabetically by category, Z-A.
  1184. tag-up Sort alphabetically by last tag, A-Z.
  1185. tag-down Sort alphabetically by last tag, Z-A.
  1186. priority-up Sort numerically by priority, high priority last.
  1187. priority-down Sort numerically by priority, high priority first.
  1188. todo-state-up Sort by todo state, tasks that are done last.
  1189. todo-state-down Sort by todo state, tasks that are done first.
  1190. effort-up Sort numerically by estimated effort, high effort last.
  1191. effort-down Sort numerically by estimated effort, high effort first.
  1192. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1193. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1194. habit-up Put entries that are habits first
  1195. habit-down Put entries that are habits last
  1196. alpha-up Sort headlines alphabetically
  1197. alpha-down Sort headlines alphabetically, reversed
  1198. The different possibilities will be tried in sequence, and testing stops
  1199. if one comparison returns a \"not-equal\". For example, the default
  1200. '(time-up category-keep priority-down)
  1201. means: Pull out all entries having a specified time of day and sort them,
  1202. in order to make a time schedule for the current day the first thing in the
  1203. agenda listing for the day. Of the entries without a time indication, keep
  1204. the grouped in categories, don't sort the categories, but keep them in
  1205. the sequence given in `org-agenda-files'. Within each category sort by
  1206. priority.
  1207. Leaving out `category-keep' would mean that items will be sorted across
  1208. categories by priority.
  1209. Instead of a single list, this can also be a set of list for specific
  1210. contents, with a context symbol in the car of the list, any of
  1211. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1212. Custom commands can bind this variable in the options section."
  1213. :group 'org-agenda-sorting
  1214. :type `(choice
  1215. (repeat :tag "General" ,org-sorting-choice)
  1216. (list :tag "Individually"
  1217. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1218. (repeat ,org-sorting-choice))
  1219. (cons (const :tag "Strategy for TODO lists" todo)
  1220. (repeat ,org-sorting-choice))
  1221. (cons (const :tag "Strategy for Tags matches" tags)
  1222. (repeat ,org-sorting-choice))
  1223. (cons (const :tag "Strategy for search matches" search)
  1224. (repeat ,org-sorting-choice)))))
  1225. (defcustom org-agenda-cmp-user-defined nil
  1226. "A function to define the comparison `user-defined'.
  1227. This function must receive two arguments, agenda entry a and b.
  1228. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1229. the user comparison, return nil.
  1230. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1231. part of an agenda sorting strategy."
  1232. :group 'org-agenda-sorting
  1233. :type 'symbol)
  1234. (defcustom org-sort-agenda-notime-is-late t
  1235. "Non-nil means items without time are considered late.
  1236. This is only relevant for sorting. When t, items which have no explicit
  1237. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1238. do have a time. When nil, the default time is before 0:00. You can use this
  1239. option to decide if the schedule for today should come before or after timeless
  1240. agenda entries."
  1241. :group 'org-agenda-sorting
  1242. :type 'boolean)
  1243. (defcustom org-sort-agenda-noeffort-is-high t
  1244. "Non-nil means items without effort estimate are sorted as high effort.
  1245. This also applies when filtering an agenda view with respect to the
  1246. < or > effort operator. Then, tasks with no effort defined will be treated
  1247. as tasks with high effort.
  1248. When nil, such items are sorted as 0 minutes effort."
  1249. :group 'org-agenda-sorting
  1250. :type 'boolean)
  1251. (defgroup org-agenda-line-format nil
  1252. "Options concerning the entry prefix in the Org-mode agenda display."
  1253. :tag "Org Agenda Line Format"
  1254. :group 'org-agenda)
  1255. (defcustom org-agenda-prefix-format
  1256. '((agenda . " %i %-12:c%?-12t% s")
  1257. (timeline . " % s")
  1258. (todo . " %i %-12:c")
  1259. (tags . " %i %-12:c")
  1260. (search . " %i %-12:c"))
  1261. "Format specifications for the prefix of items in the agenda views.
  1262. An alist with five entries, each for the different agenda types. The
  1263. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1264. The values are format strings.
  1265. This format works similar to a printf format, with the following meaning:
  1266. %c the category of the item, \"Diary\" for entries from the diary,
  1267. or as given by the CATEGORY keyword or derived from the file name
  1268. %e the effort required by the item
  1269. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1270. %T the last tag of the item (ignore inherited tags, which come first)
  1271. %t the HH:MM time-of-day specification if one applies to the entry
  1272. %s Scheduling/Deadline information, a short string
  1273. %(expression) Eval EXPRESSION and replace the control string
  1274. by the result
  1275. All specifiers work basically like the standard `%s' of printf, but may
  1276. contain two additional characters: a question mark just after the `%'
  1277. and a whitespace/punctuation character just before the final letter.
  1278. If the first character after `%' is a question mark, the entire field
  1279. will only be included if the corresponding value applies to the current
  1280. entry. This is useful for fields which should have fixed width when
  1281. present, but zero width when absent. For example, \"%?-12t\" will
  1282. result in a 12 character time field if a time of the day is specified,
  1283. but will completely disappear in entries which do not contain a time.
  1284. If there is punctuation or whitespace character just before the final
  1285. format letter, this character will be appended to the field value if
  1286. the value is not empty. For example, the format \"%-12:c\" leads to
  1287. \"Diary: \" if the category is \"Diary\". If the category were be
  1288. empty, no additional colon would be inserted.
  1289. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1290. which means:
  1291. - Indent the line with two space characters
  1292. - Give the category a 12 chars wide field, padded with whitespace on
  1293. the right (because of `-'). Append a colon if there is a category
  1294. (because of `:').
  1295. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1296. time, don't put in an empty field, just skip it (because of '?').
  1297. - Finally, put the scheduling information.
  1298. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1299. `org-agenda-remove-tags'.
  1300. Custom commands can set this variable in the options section."
  1301. :type '(choice
  1302. (string :tag "General format")
  1303. (list :greedy t :tag "View dependent"
  1304. (cons (const agenda) (string :tag "Format"))
  1305. (cons (const timeline) (string :tag "Format"))
  1306. (cons (const todo) (string :tag "Format"))
  1307. (cons (const tags) (string :tag "Format"))
  1308. (cons (const search) (string :tag "Format"))))
  1309. :group 'org-agenda-line-format)
  1310. (defvar org-prefix-format-compiled nil
  1311. "The compiled version of the most recently used prefix format.
  1312. See the variable `org-agenda-prefix-format'.")
  1313. (defcustom org-agenda-todo-keyword-format "%-1s"
  1314. "Format for the TODO keyword in agenda lines.
  1315. Set this to something like \"%-12s\" if you want all TODO keywords
  1316. to occupy a fixed space in the agenda display."
  1317. :group 'org-agenda-line-format
  1318. :type 'string)
  1319. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1320. "Text preceding timerange entries in the agenda view.
  1321. This is a list with two strings. The first applies when the range
  1322. is entirely on one day. The second applies if the range spans several days.
  1323. The strings may have two \"%d\" format specifiers which will be filled
  1324. with the sequence number of the days, and the total number of days in the
  1325. range, respectively."
  1326. :group 'org-agenda-line-format
  1327. :type '(list
  1328. (string :tag "Deadline today ")
  1329. (choice :tag "Deadline relative"
  1330. (string :tag "Format string")
  1331. (function))))
  1332. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1333. "Text preceding scheduled items in the agenda view.
  1334. This is a list with two strings. The first applies when the item is
  1335. scheduled on the current day. The second applies when it has been scheduled
  1336. previously, it may contain a %d indicating that this is the nth time that
  1337. this item is scheduled, due to automatic rescheduling of unfinished items
  1338. for the following day. So this number is one larger than the number of days
  1339. that passed since this item was scheduled first."
  1340. :group 'org-agenda-line-format
  1341. :type '(list
  1342. (string :tag "Scheduled today ")
  1343. (string :tag "Scheduled previously")))
  1344. (defcustom org-agenda-inactive-leader "["
  1345. "Text preceding item pulled into the agenda by inactive time stamps.
  1346. These entries are added to the agenda when pressing \"[\"."
  1347. :group 'org-agenda-line-format
  1348. :type '(list
  1349. (string :tag "Scheduled today ")
  1350. (string :tag "Scheduled previously")))
  1351. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1352. "Text preceding deadline items in the agenda view.
  1353. This is a list with two strings. The first applies when the item has its
  1354. deadline on the current day. The second applies when it is in the past or
  1355. in the future, it may contain %d to capture how many days away the deadline
  1356. is (was)."
  1357. :group 'org-agenda-line-format
  1358. :type '(list
  1359. (string :tag "Deadline today ")
  1360. (choice :tag "Deadline relative"
  1361. (string :tag "Format string")
  1362. (function))))
  1363. (defcustom org-agenda-remove-times-when-in-prefix t
  1364. "Non-nil means remove duplicate time specifications in agenda items.
  1365. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1366. time-of-day specification in a headline or diary entry is extracted and
  1367. placed into the prefix. If this option is non-nil, the original specification
  1368. \(a timestamp or -range, or just a plain time(range) specification like
  1369. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1370. cluttered.
  1371. The option can be t or nil. It may also be the symbol `beg', indicating
  1372. that the time should only be removed when it is located at the beginning of
  1373. the headline/diary entry."
  1374. :group 'org-agenda-line-format
  1375. :type '(choice
  1376. (const :tag "Always" t)
  1377. (const :tag "Never" nil)
  1378. (const :tag "When at beginning of entry" beg)))
  1379. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1380. "Non-nil means remove time ranges specifications in agenda
  1381. items that span on several days."
  1382. :group 'org-agenda-line-format
  1383. :type 'boolean)
  1384. (defcustom org-agenda-default-appointment-duration nil
  1385. "Default duration for appointments that only have a starting time.
  1386. When nil, no duration is specified in such cases.
  1387. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1388. :group 'org-agenda-line-format
  1389. :type '(choice
  1390. (integer :tag "Minutes")
  1391. (const :tag "No default duration")))
  1392. (defcustom org-agenda-show-inherited-tags t
  1393. "Non-nil means show inherited tags in each agenda line."
  1394. :group 'org-agenda-line-format
  1395. :type 'boolean)
  1396. (defcustom org-agenda-hide-tags-regexp nil
  1397. "Regular expression used to filter away specific tags in agenda views.
  1398. This means that these tags will be present, but not be shown in the agenda
  1399. line. Secondary filtering will still work on the hidden tags.
  1400. Nil means don't hide any tags."
  1401. :group 'org-agenda-line-format
  1402. :type '(choice
  1403. (const :tag "Hide none" nil)
  1404. (string :tag "Regexp ")))
  1405. (defcustom org-agenda-remove-tags nil
  1406. "Non-nil means remove the tags from the headline copy in the agenda.
  1407. When this is the symbol `prefix', only remove tags when
  1408. `org-agenda-prefix-format' contains a `%T' specifier."
  1409. :group 'org-agenda-line-format
  1410. :type '(choice
  1411. (const :tag "Always" t)
  1412. (const :tag "Never" nil)
  1413. (const :tag "When prefix format contains %T" prefix)))
  1414. (if (fboundp 'defvaralias)
  1415. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1416. 'org-agenda-remove-tags))
  1417. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1418. "Shift tags in agenda items to this column.
  1419. If this number is positive, it specifies the column. If it is negative,
  1420. it means that the tags should be flushright to that column. For example,
  1421. -80 works well for a normal 80 character screen."
  1422. :group 'org-agenda-line-format
  1423. :type 'integer)
  1424. (if (fboundp 'defvaralias)
  1425. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1426. (defcustom org-agenda-fontify-priorities 'cookies
  1427. "Non-nil means highlight low and high priorities in agenda.
  1428. When t, the highest priority entries are bold, lowest priority italic.
  1429. However, settings in `org-priority-faces' will overrule these faces.
  1430. When this variable is the symbol `cookies', only fontify the
  1431. cookies, not the entire task.
  1432. This may also be an association list of priority faces, whose
  1433. keys are the character values of `org-highest-priority',
  1434. `org-default-priority', and `org-lowest-priority' (the default values
  1435. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1436. color as a string, or a list like `(:background \"Red\")'.
  1437. If it is a color, the variable `org-faces-easy-properties'
  1438. determines if it is a foreground or a background color."
  1439. :group 'org-agenda-line-format
  1440. :type '(choice
  1441. (const :tag "Never" nil)
  1442. (const :tag "Defaults" t)
  1443. (const :tag "Cookies only" cookies)
  1444. (repeat :tag "Specify"
  1445. (list (character :tag "Priority" :value ?A)
  1446. (choice :tag "Face "
  1447. (string :tag "Color")
  1448. (sexp :tag "Face"))))))
  1449. (defcustom org-agenda-day-face-function nil
  1450. "Function called to determine what face should be used to display a day.
  1451. The only argument passed to that function is the day. It should
  1452. returns a face, or nil if does not want to specify a face and let
  1453. the normal rules apply."
  1454. :group 'org-agenda-line-format
  1455. :type 'function)
  1456. (defcustom org-agenda-category-icon-alist nil
  1457. "Alist of category icon to be displayed in agenda views.
  1458. Each entry should have the following format:
  1459. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1460. Where CATEGORY-REGEXP is a regexp matching the categories where
  1461. the icon should be displayed.
  1462. FILE-OR-DATA either a file path or a string containing image data.
  1463. The other fields can be omitted safely if not needed:
  1464. TYPE indicates the image type.
  1465. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1466. image data.
  1467. PROPS are additional image attributes to assign to the image,
  1468. like, e.g. `:ascent center'.
  1469. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1470. If you want to set the display properties yourself, just put a
  1471. list as second element:
  1472. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1473. For example, to display a 16px horizontal space for Emacs
  1474. category, you can use:
  1475. (\"Emacs\" '(space . (:width (16))))"
  1476. :group 'org-agenda-line-format
  1477. :type '(alist :key-type (string :tag "Regexp matching category")
  1478. :value-type (choice (list :tag "Icon"
  1479. (string :tag "File or data")
  1480. (symbol :tag "Type")
  1481. (boolean :tag "Data?")
  1482. (repeat :tag "Extra image properties" :inline t symbol))
  1483. (list :tag "Display properties" sexp))))
  1484. (defgroup org-agenda-column-view nil
  1485. "Options concerning column view in the agenda."
  1486. :tag "Org Agenda Column View"
  1487. :group 'org-agenda)
  1488. (defcustom org-agenda-columns-show-summaries t
  1489. "Non-nil means show summaries for columns displayed in the agenda view."
  1490. :group 'org-agenda-column-view
  1491. :type 'boolean)
  1492. (defcustom org-agenda-columns-compute-summary-properties t
  1493. "Non-nil means recompute all summary properties before column view.
  1494. When column view in the agenda is listing properties that have a summary
  1495. operator, it can go to all relevant buffers and recompute the summaries
  1496. there. This can mean overhead for the agenda column view, but is necessary
  1497. to have thing up to date.
  1498. As a special case, a CLOCKSUM property also makes sure that the clock
  1499. computations are current."
  1500. :group 'org-agenda-column-view
  1501. :type 'boolean)
  1502. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1503. "Non-nil means the duration of an appointment will add to day effort.
  1504. The property to which appointment durations will be added is the one given
  1505. in the option `org-effort-property'. If an appointment does not have
  1506. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1507. is not set, an appointment without end time will not contribute to the time
  1508. estimate."
  1509. :group 'org-agenda-column-view
  1510. :type 'boolean)
  1511. (defcustom org-agenda-auto-exclude-function nil
  1512. "A function called with a tag to decide if it is filtered on '/ RET'.
  1513. The sole argument to the function, which is called once for each
  1514. possible tag, is a string giving the name of the tag. The
  1515. function should return either nil if the tag should be included
  1516. as normal, or \"-<TAG>\" to exclude the tag.
  1517. Note that for the purpose of tag filtering, only the lower-case version of
  1518. all tags will be considered, so that this function will only ever see
  1519. the lower-case version of all tags."
  1520. :group 'org-agenda
  1521. :type 'function)
  1522. (defcustom org-agenda-bulk-custom-functions nil
  1523. "Alist of characters and custom functions for bulk actions.
  1524. For example, this value makes those two functions available:
  1525. '((?R set-category)
  1526. (?C bulk-cut))
  1527. With selected entries in an agenda buffer, `B R' will call
  1528. the custom function `set-category' on the selected entries.
  1529. Note that functions in this alist don't need to be quoted."
  1530. :type 'alist
  1531. :group 'org-agenda)
  1532. (eval-when-compile
  1533. (require 'cl))
  1534. (require 'org)
  1535. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1536. "Execute BODY with point at location given by `org-hd-marker' property.
  1537. If STRING is non-nil, the text property will be fetched from position 0
  1538. in that string. If STRING is nil, it will be fetched from the beginning
  1539. of the current line."
  1540. (org-with-gensyms (marker)
  1541. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1542. 'org-hd-marker ,string)))
  1543. (with-current-buffer (marker-buffer ,marker)
  1544. (save-excursion
  1545. (goto-char ,marker)
  1546. ,@body)))))
  1547. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1548. (defun org-add-agenda-custom-command (entry)
  1549. "Replace or add a command in `org-agenda-custom-commands'.
  1550. This is mostly for hacking and trying a new command - once the command
  1551. works you probably want to add it to `org-agenda-custom-commands' for good."
  1552. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1553. (if ass
  1554. (setcdr ass (cdr entry))
  1555. (push entry org-agenda-custom-commands))))
  1556. ;;; Define the org-agenda-mode
  1557. (defvar org-agenda-mode-map (make-sparse-keymap)
  1558. "Keymap for `org-agenda-mode'.")
  1559. (if (fboundp 'defvaralias)
  1560. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1561. (defvar org-agenda-menu) ; defined later in this file.
  1562. (defvar org-agenda-restrict) ; defined later in this file.
  1563. (defvar org-agenda-follow-mode nil)
  1564. (defvar org-agenda-entry-text-mode nil)
  1565. (defvar org-agenda-clockreport-mode nil)
  1566. (defvar org-agenda-show-log nil)
  1567. (defvar org-agenda-redo-command nil)
  1568. (defvar org-agenda-query-string nil)
  1569. (defvar org-agenda-mode-hook nil
  1570. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1571. (defvar org-agenda-type nil)
  1572. (defvar org-agenda-force-single-file nil)
  1573. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1574. (defun org-agenda-mode ()
  1575. "Mode for time-sorted view on action items in Org-mode files.
  1576. The following commands are available:
  1577. \\{org-agenda-mode-map}"
  1578. (interactive)
  1579. (kill-all-local-variables)
  1580. (setq org-agenda-undo-list nil
  1581. org-agenda-pending-undo-list nil
  1582. org-agenda-bulk-marked-entries nil)
  1583. (setq major-mode 'org-agenda-mode)
  1584. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1585. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1586. (setq mode-name "Org-Agenda")
  1587. (use-local-map org-agenda-mode-map)
  1588. (easy-menu-add org-agenda-menu)
  1589. (if org-startup-truncated (setq truncate-lines t))
  1590. (org-set-local 'line-move-visual nil)
  1591. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1592. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1593. ;; Make sure properties are removed when copying text
  1594. (when (boundp 'buffer-substring-filters)
  1595. (org-set-local 'buffer-substring-filters
  1596. (cons (lambda (x)
  1597. (set-text-properties 0 (length x) nil x) x)
  1598. buffer-substring-filters)))
  1599. (unless org-agenda-keep-modes
  1600. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1601. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1602. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1603. org-agenda-show-log org-agenda-start-with-log-mode))
  1604. (easy-menu-change
  1605. '("Agenda") "Agenda Files"
  1606. (append
  1607. (list
  1608. (vector
  1609. (if (get 'org-agenda-files 'org-restrict)
  1610. "Restricted to single file"
  1611. "Edit File List")
  1612. '(org-edit-agenda-file-list)
  1613. (not (get 'org-agenda-files 'org-restrict)))
  1614. "--")
  1615. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1616. (org-agenda-set-mode-name)
  1617. (apply
  1618. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1619. (list 'org-agenda-mode-hook)))
  1620. (substitute-key-definition 'undo 'org-agenda-undo
  1621. org-agenda-mode-map global-map)
  1622. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1623. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1624. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1625. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1627. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1628. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1629. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1630. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1631. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1632. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1633. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1634. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1635. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1636. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1637. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1638. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1639. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1640. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1641. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1642. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1643. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1644. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1645. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1646. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1647. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1648. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1649. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1650. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1651. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1652. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1653. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1654. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1655. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1656. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1657. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1658. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1659. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1660. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1661. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1662. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1663. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1664. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1665. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1666. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1667. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1668. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1669. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1670. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1671. (while l (org-defkey org-agenda-mode-map
  1672. (int-to-string (pop l)) 'digit-argument)))
  1673. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1674. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1675. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1676. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1677. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1678. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1679. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1680. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1681. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1682. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1683. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1684. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1685. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1686. 'org-clock-modify-effort-estimate)
  1687. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1688. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1689. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1690. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1691. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1692. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1693. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1694. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1695. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1696. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1697. (substitute-key-definition 'next-line 'org-agenda-next-line
  1698. org-agenda-mode-map global-map)
  1699. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1700. org-agenda-mode-map global-map)
  1701. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1702. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1703. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1704. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1705. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1706. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1707. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1708. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1709. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1710. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1711. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1712. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1713. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1714. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1715. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1716. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1717. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1718. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1719. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1720. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1721. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1722. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1723. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1724. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1725. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1726. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1727. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1728. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1729. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1730. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1731. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1732. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1733. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1734. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1735. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1736. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1737. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1738. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1739. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1740. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1741. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1742. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1743. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1744. (when org-agenda-mouse-1-follows-link
  1745. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1746. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1747. '("Agenda"
  1748. ("Agenda Files")
  1749. "--"
  1750. ("Agenda Dates"
  1751. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1752. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1753. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1754. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1755. "--"
  1756. ("View"
  1757. ["Day View" org-agenda-day-view
  1758. :active (org-agenda-check-type nil 'agenda)
  1759. :style radio :selected (eq org-agenda-current-span 'day)
  1760. :keys "v d (or just d)"]
  1761. ["Week View" org-agenda-week-view
  1762. :active (org-agenda-check-type nil 'agenda)
  1763. :style radio :selected (eq org-agenda-current-span 'week)
  1764. :keys "v w (or just w)"]
  1765. ["Month View" org-agenda-month-view
  1766. :active (org-agenda-check-type nil 'agenda)
  1767. :style radio :selected (eq org-agenda-current-span 'month)
  1768. :keys "v m"]
  1769. ["Year View" org-agenda-year-view
  1770. :active (org-agenda-check-type nil 'agenda)
  1771. :style radio :selected (eq org-agenda-current-span 'year)
  1772. :keys "v y"]
  1773. "--"
  1774. ["Include Diary" org-agenda-toggle-diary
  1775. :style toggle :selected org-agenda-include-diary
  1776. :active (org-agenda-check-type nil 'agenda)]
  1777. ["Include Deadlines" org-agenda-toggle-deadlines
  1778. :style toggle :selected org-agenda-include-deadlines
  1779. :active (org-agenda-check-type nil 'agenda)]
  1780. ["Use Time Grid" org-agenda-toggle-time-grid
  1781. :style toggle :selected org-agenda-use-time-grid
  1782. :active (org-agenda-check-type nil 'agenda)]
  1783. "--"
  1784. ["Show clock report" org-agenda-clockreport-mode
  1785. :style toggle :selected org-agenda-clockreport-mode
  1786. :active (org-agenda-check-type nil 'agenda)]
  1787. ["Show some entry text" org-agenda-entry-text-mode
  1788. :style toggle :selected org-agenda-entry-text-mode
  1789. :active t]
  1790. "--"
  1791. ["Show Logbook entries" org-agenda-log-mode
  1792. :style toggle :selected org-agenda-show-log
  1793. :active (org-agenda-check-type nil 'agenda 'timeline)
  1794. :keys "v l (or just l)"]
  1795. ["Include archived trees" org-agenda-archives-mode
  1796. :style toggle :selected org-agenda-archives-mode :active t
  1797. :keys "v a"]
  1798. ["Include archive files" (org-agenda-archives-mode t)
  1799. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1800. :keys "v A"]
  1801. "--"
  1802. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1803. ["Write view to file" org-agenda-write t]
  1804. ["Rebuild buffer" org-agenda-redo t]
  1805. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1806. "--"
  1807. ["Show original entry" org-agenda-show t]
  1808. ["Go To (other window)" org-agenda-goto t]
  1809. ["Go To (this window)" org-agenda-switch-to t]
  1810. ["Follow Mode" org-agenda-follow-mode
  1811. :style toggle :selected org-agenda-follow-mode :active t]
  1812. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1813. "--"
  1814. ("TODO"
  1815. ["Cycle TODO" org-agenda-todo t]
  1816. ["Next TODO set" org-agenda-todo-nextset t]
  1817. ["Previous TODO set" org-agenda-todo-previousset t]
  1818. ["Add note" org-agenda-add-note t])
  1819. ("Archive/Refile/Delete"
  1820. ["Archive default" org-agenda-archive-default t]
  1821. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1822. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1823. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1824. ["Archive subtree" org-agenda-archive t]
  1825. "--"
  1826. ["Refile" org-agenda-refile t]
  1827. "--"
  1828. ["Delete subtree" org-agenda-kill t])
  1829. ("Bulk action"
  1830. ["Mark entry" org-agenda-bulk-mark t]
  1831. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1832. ["Unmark entry" org-agenda-bulk-unmark t]
  1833. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1834. ["Act on all marked" org-agenda-bulk-action t]
  1835. "--"
  1836. ("Tags and Properties"
  1837. ["Show all Tags" org-agenda-show-tags t]
  1838. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1839. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1840. "--"
  1841. ["Column View" org-columns t])
  1842. ("Deadline/Schedule"
  1843. ["Schedule" org-agenda-schedule t]
  1844. ["Set Deadline" org-agenda-deadline t]
  1845. "--"
  1846. ["Mark item" org-agenda-action :active t :keys "k m"]
  1847. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1848. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1849. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1850. "--"
  1851. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1852. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1853. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1854. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1855. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1856. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1857. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1858. ("Clock and Effort"
  1859. ["Clock in" org-agenda-clock-in t]
  1860. ["Clock out" org-agenda-clock-out t]
  1861. ["Clock cancel" org-agenda-clock-cancel t]
  1862. ["Goto running clock" org-clock-goto t]
  1863. "--"
  1864. ["Set Effort" org-agenda-set-effort t]
  1865. ["Change clocked effort" org-clock-modify-effort-estimate
  1866. (org-clock-is-active)])
  1867. ("Priority"
  1868. ["Set Priority" org-agenda-priority t]
  1869. ["Increase Priority" org-agenda-priority-up t]
  1870. ["Decrease Priority" org-agenda-priority-down t]
  1871. ["Show Priority" org-agenda-show-priority t])
  1872. ("Calendar/Diary"
  1873. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1874. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1875. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1876. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1877. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1878. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1879. "--"
  1880. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1881. "--"
  1882. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1883. "--"
  1884. ("MobileOrg"
  1885. ["Push Files and Views" org-mobile-push t]
  1886. ["Get Captured and Flagged" org-mobile-pull t]
  1887. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1888. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1889. "--"
  1890. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1891. "--"
  1892. ["Quit" org-agenda-quit t]
  1893. ["Exit and Release Buffers" org-agenda-exit t]
  1894. ))
  1895. ;;; Agenda undo
  1896. (defvar org-agenda-allow-remote-undo t
  1897. "Non-nil means allow remote undo from the agenda buffer.")
  1898. (defvar org-agenda-undo-list nil
  1899. "List of undoable operations in the agenda since last refresh.")
  1900. (defvar org-agenda-undo-has-started-in nil
  1901. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1902. (defvar org-agenda-pending-undo-list nil
  1903. "In a series of undo commands, this is the list of remaining undo items.")
  1904. (defun org-agenda-undo ()
  1905. "Undo a remote editing step in the agenda.
  1906. This undoes changes both in the agenda buffer and in the remote buffer
  1907. that have been changed along."
  1908. (interactive)
  1909. (or org-agenda-allow-remote-undo
  1910. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1911. (if (not (eq this-command last-command))
  1912. (setq org-agenda-undo-has-started-in nil
  1913. org-agenda-pending-undo-list org-agenda-undo-list))
  1914. (if (not org-agenda-pending-undo-list)
  1915. (error "No further undo information"))
  1916. (let* ((entry (pop org-agenda-pending-undo-list))
  1917. buf line cmd rembuf)
  1918. (setq cmd (pop entry) line (pop entry))
  1919. (setq rembuf (nth 2 entry))
  1920. (org-with-remote-undo rembuf
  1921. (while (bufferp (setq buf (pop entry)))
  1922. (if (pop entry)
  1923. (with-current-buffer buf
  1924. (let ((last-undo-buffer buf)
  1925. (inhibit-read-only t))
  1926. (unless (memq buf org-agenda-undo-has-started-in)
  1927. (push buf org-agenda-undo-has-started-in)
  1928. (make-local-variable 'pending-undo-list)
  1929. (undo-start))
  1930. (while (and pending-undo-list
  1931. (listp pending-undo-list)
  1932. (not (car pending-undo-list)))
  1933. (pop pending-undo-list))
  1934. (undo-more 1))))))
  1935. (org-goto-line line)
  1936. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1937. (defun org-verify-change-for-undo (l1 l2)
  1938. "Verify that a real change occurred between the undo lists L1 and L2."
  1939. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1940. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1941. (not (eq l1 l2)))
  1942. ;;; Agenda dispatch
  1943. (defvar org-agenda-restrict nil)
  1944. (defvar org-agenda-restrict-begin (make-marker))
  1945. (defvar org-agenda-restrict-end (make-marker))
  1946. (defvar org-agenda-last-dispatch-buffer nil)
  1947. (defvar org-agenda-overriding-restriction nil)
  1948. ;;;###autoload
  1949. (defun org-agenda (&optional arg keys restriction)
  1950. "Dispatch agenda commands to collect entries to the agenda buffer.
  1951. Prompts for a command to execute. Any prefix arg will be passed
  1952. on to the selected command. The default selections are:
  1953. a Call `org-agenda-list' to display the agenda for current day or week.
  1954. t Call `org-todo-list' to display the global todo list.
  1955. T Call `org-todo-list' to display the global todo list, select only
  1956. entries with a specific TODO keyword (the user gets a prompt).
  1957. m Call `org-tags-view' to display headlines with tags matching
  1958. a condition (the user is prompted for the condition).
  1959. M Like `m', but select only TODO entries, no ordinary headlines.
  1960. L Create a timeline for the current buffer.
  1961. e Export views to associated files.
  1962. s Search entries for keywords.
  1963. / Multi occur across all agenda files and also files listed
  1964. in `org-agenda-text-search-extra-files'.
  1965. < Restrict agenda commands to buffer, subtree, or region.
  1966. Press several times to get the desired effect.
  1967. > Remove a previous restriction.
  1968. # List \"stuck\" projects.
  1969. ! Configure what \"stuck\" means.
  1970. C Configure custom agenda commands.
  1971. More commands can be added by configuring the variable
  1972. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1973. searches can be pre-defined in this way.
  1974. If the current buffer is in Org-mode and visiting a file, you can also
  1975. first press `<' once to indicate that the agenda should be temporarily
  1976. \(until the next use of \\[org-agenda]) restricted to the current file.
  1977. Pressing `<' twice means to restrict to the current subtree or region
  1978. \(if active)."
  1979. (interactive "P")
  1980. (catch 'exit
  1981. (let* ((prefix-descriptions nil)
  1982. (org-agenda-window-setup (if (equal (buffer-name)
  1983. org-agenda-buffer-name)
  1984. 'current-window
  1985. org-agenda-window-setup))
  1986. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1987. (org-agenda-custom-commands
  1988. ;; normalize different versions
  1989. (delq nil
  1990. (mapcar
  1991. (lambda (x)
  1992. (cond ((stringp (cdr x))
  1993. (push x prefix-descriptions)
  1994. nil)
  1995. ((stringp (nth 1 x)) x)
  1996. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1997. (t (cons (car x) (cons "" (cdr x))))))
  1998. org-agenda-custom-commands)))
  1999. (buf (current-buffer))
  2000. (bfn (buffer-file-name (buffer-base-buffer)))
  2001. entry key type match lprops ans)
  2002. ;; Turn off restriction unless there is an overriding one,
  2003. (unless org-agenda-overriding-restriction
  2004. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2005. ;; There is a request to keep the file list in place
  2006. (put 'org-agenda-files 'org-restrict nil))
  2007. (setq org-agenda-restrict nil)
  2008. (move-marker org-agenda-restrict-begin nil)
  2009. (move-marker org-agenda-restrict-end nil))
  2010. ;; Delete old local properties
  2011. (put 'org-agenda-redo-command 'org-lprops nil)
  2012. ;; Delete previously set last-arguments
  2013. (put 'org-agenda-redo-command 'last-args nil)
  2014. ;; Remember where this call originated
  2015. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2016. (unless keys
  2017. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2018. keys (car ans)
  2019. restriction (cdr ans)))
  2020. ;; Establish the restriction, if any
  2021. (when (and (not org-agenda-overriding-restriction) restriction)
  2022. (put 'org-agenda-files 'org-restrict (list bfn))
  2023. (cond
  2024. ((eq restriction 'region)
  2025. (setq org-agenda-restrict t)
  2026. (move-marker org-agenda-restrict-begin (region-beginning))
  2027. (move-marker org-agenda-restrict-end (region-end)))
  2028. ((eq restriction 'subtree)
  2029. (save-excursion
  2030. (setq org-agenda-restrict t)
  2031. (org-back-to-heading t)
  2032. (move-marker org-agenda-restrict-begin (point))
  2033. (move-marker org-agenda-restrict-end
  2034. (progn (org-end-of-subtree t)))))))
  2035. ;; For example the todo list should not need it (but does...)
  2036. (cond
  2037. ((setq entry (assoc keys org-agenda-custom-commands))
  2038. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2039. (progn
  2040. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2041. lprops (nth 4 entry))
  2042. (put 'org-agenda-redo-command 'org-lprops lprops)
  2043. (cond
  2044. ((eq type 'agenda)
  2045. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2046. ((eq type 'alltodo)
  2047. (org-let lprops '(org-todo-list current-prefix-arg)))
  2048. ((eq type 'search)
  2049. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2050. ((eq type 'stuck)
  2051. (org-let lprops '(org-agenda-list-stuck-projects
  2052. current-prefix-arg)))
  2053. ((eq type 'tags)
  2054. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2055. ((eq type 'tags-todo)
  2056. (org-let lprops '(org-tags-view '(4) match)))
  2057. ((eq type 'todo)
  2058. (org-let lprops '(org-todo-list match)))
  2059. ((eq type 'tags-tree)
  2060. (org-check-for-org-mode)
  2061. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2062. ((eq type 'todo-tree)
  2063. (org-check-for-org-mode)
  2064. (org-let lprops
  2065. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2066. (regexp-quote match) "\\>"))))
  2067. ((eq type 'occur-tree)
  2068. (org-check-for-org-mode)
  2069. (org-let lprops '(org-occur match)))
  2070. ((functionp type)
  2071. (org-let lprops '(funcall type match)))
  2072. ((fboundp type)
  2073. (org-let lprops '(funcall type match)))
  2074. (t (error "Invalid custom agenda command type %s" type))))
  2075. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2076. ((equal keys "C")
  2077. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2078. (customize-variable 'org-agenda-custom-commands))
  2079. ((equal keys "a") (call-interactively 'org-agenda-list))
  2080. ((equal keys "s") (call-interactively 'org-search-view))
  2081. ((equal keys "t") (call-interactively 'org-todo-list))
  2082. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2083. ((equal keys "m") (call-interactively 'org-tags-view))
  2084. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2085. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2086. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2087. (org-add-hook
  2088. 'post-command-hook
  2089. (lambda ()
  2090. (unless (current-message)
  2091. (let* ((m (org-agenda-get-any-marker))
  2092. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2093. (when note
  2094. (message (concat
  2095. "FLAGGING-NOTE ([?] for more info): "
  2096. (org-add-props
  2097. (replace-regexp-in-string
  2098. "\\\\n" "//"
  2099. (copy-sequence note))
  2100. nil 'face 'org-warning)))))))
  2101. t t))
  2102. ((equal keys "L")
  2103. (unless (eq major-mode 'org-mode)
  2104. (error "This is not an Org-mode file"))
  2105. (unless restriction
  2106. (put 'org-agenda-files 'org-restrict (list bfn))
  2107. (org-call-with-arg 'org-timeline arg)))
  2108. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2109. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2110. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2111. (t (error "Invalid agenda key"))))))
  2112. (defun org-agenda-append-agenda ()
  2113. "Append another agenda view to the current one.
  2114. This function allows interactive building of block agendas.
  2115. Agenda views are separated by `org-agenda-block-separator'."
  2116. (interactive)
  2117. (unless (string= (buffer-name) org-agenda-buffer-name)
  2118. (error "Can only append from within agenda buffer"))
  2119. (let ((org-agenda-multi t))
  2120. (org-agenda)
  2121. (widen)))
  2122. (defun org-agenda-normalize-custom-commands (cmds)
  2123. (delq nil
  2124. (mapcar
  2125. (lambda (x)
  2126. (cond ((stringp (cdr x)) nil)
  2127. ((stringp (nth 1 x)) x)
  2128. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2129. (t (cons (car x) (cons "" (cdr x))))))
  2130. cmds)))
  2131. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2132. "The user interface for selecting an agenda command."
  2133. (catch 'exit
  2134. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2135. (restrict-ok (and bfn (eq major-mode 'org-mode)))
  2136. (region-p (org-region-active-p))
  2137. (custom org-agenda-custom-commands)
  2138. (selstring "")
  2139. restriction second-time
  2140. c entry key type match prefixes rmheader header-end custom1 desc
  2141. line lines left right n n1)
  2142. (save-window-excursion
  2143. (delete-other-windows)
  2144. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2145. (erase-buffer)
  2146. (insert (eval-when-compile
  2147. (let ((header
  2148. "
  2149. Press key for an agenda command: < Buffer, subtree/region restriction
  2150. -------------------------------- > Remove restriction
  2151. a Agenda for current week or day e Export agenda views
  2152. t List of all TODO entries T Entries with special TODO kwd
  2153. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2154. L Timeline for current buffer # List stuck projects (!=configure)
  2155. s Search for keywords C Configure custom agenda commands
  2156. / Multi-occur ? Find :FLAGGED: entries
  2157. ")
  2158. (start 0))
  2159. (while (string-match
  2160. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2161. header start)
  2162. (setq start (match-end 0))
  2163. (add-text-properties (match-beginning 2) (match-end 2)
  2164. '(face bold) header))
  2165. header)))
  2166. (setq header-end (move-marker (make-marker) (point)))
  2167. (while t
  2168. (setq custom1 custom)
  2169. (when (eq rmheader t)
  2170. (org-goto-line 1)
  2171. (re-search-forward ":" nil t)
  2172. (delete-region (match-end 0) (point-at-eol))
  2173. (forward-char 1)
  2174. (looking-at "-+")
  2175. (delete-region (match-end 0) (point-at-eol))
  2176. (move-marker header-end (match-end 0)))
  2177. (goto-char header-end)
  2178. (delete-region (point) (point-max))
  2179. ;; Produce all the lines that describe custom commands and prefixes
  2180. (setq lines nil)
  2181. (while (setq entry (pop custom1))
  2182. (setq key (car entry) desc (nth 1 entry)
  2183. type (nth 2 entry)
  2184. match (nth 3 entry))
  2185. (if (> (length key) 1)
  2186. (add-to-list 'prefixes (string-to-char key))
  2187. (setq line
  2188. (format
  2189. "%-4s%-14s"
  2190. (org-add-props (copy-sequence key)
  2191. '(face bold))
  2192. (cond
  2193. ((string-match "\\S-" desc) desc)
  2194. ((eq type 'agenda) "Agenda for current week or day")
  2195. ((eq type 'alltodo) "List of all TODO entries")
  2196. ((eq type 'search) "Word search")
  2197. ((eq type 'stuck) "List of stuck projects")
  2198. ((eq type 'todo) "TODO keyword")
  2199. ((eq type 'tags) "Tags query")
  2200. ((eq type 'tags-todo) "Tags (TODO)")
  2201. ((eq type 'tags-tree) "Tags tree")
  2202. ((eq type 'todo-tree) "TODO kwd tree")
  2203. ((eq type 'occur-tree) "Occur tree")
  2204. ((functionp type) (if (symbolp type)
  2205. (symbol-name type)
  2206. "Lambda expression"))
  2207. (t "???"))))
  2208. (if org-agenda-menu-show-matcher
  2209. (setq line
  2210. (concat line ": "
  2211. (cond
  2212. ((stringp match)
  2213. (setq match (copy-sequence match))
  2214. (org-add-props match nil 'face 'org-warning))
  2215. (match
  2216. (format "set of %d commands" (length match)))
  2217. (t ""))))
  2218. (if (org-string-nw-p match)
  2219. (add-text-properties
  2220. 0 (length line) (list 'help-echo
  2221. (concat "Matcher: "match)) line)))
  2222. (push line lines)))
  2223. (setq lines (nreverse lines))
  2224. (when prefixes
  2225. (mapc (lambda (x)
  2226. (push
  2227. (format "%s %s"
  2228. (org-add-props (char-to-string x)
  2229. nil 'face 'bold)
  2230. (or (cdr (assoc (concat selstring
  2231. (char-to-string x))
  2232. prefix-descriptions))
  2233. "Prefix key"))
  2234. lines))
  2235. prefixes))
  2236. ;; Check if we should display in two columns
  2237. (if org-agenda-menu-two-column
  2238. (progn
  2239. (setq n (length lines)
  2240. n1 (+ (/ n 2) (mod n 2))
  2241. right (nthcdr n1 lines)
  2242. left (copy-sequence lines))
  2243. (setcdr (nthcdr (1- n1) left) nil))
  2244. (setq left lines right nil))
  2245. (while left
  2246. (insert "\n" (pop left))
  2247. (when right
  2248. (if (< (current-column) 40)
  2249. (move-to-column 40 t)
  2250. (insert " "))
  2251. (insert (pop right))))
  2252. ;; Make the window the right size
  2253. (goto-char (point-min))
  2254. (if second-time
  2255. (if (not (pos-visible-in-window-p (point-max)))
  2256. (org-fit-window-to-buffer))
  2257. (setq second-time t)
  2258. (org-fit-window-to-buffer))
  2259. ;; Ask for selection
  2260. (message "Press key for agenda command%s:"
  2261. (if (or restrict-ok org-agenda-overriding-restriction)
  2262. (if org-agenda-overriding-restriction
  2263. " (restriction lock active)"
  2264. (if restriction
  2265. (format " (restricted to %s)" restriction)
  2266. " (unrestricted)"))
  2267. ""))
  2268. (setq c (read-char-exclusive))
  2269. (message "")
  2270. (cond
  2271. ((assoc (char-to-string c) custom)
  2272. (setq selstring (concat selstring (char-to-string c)))
  2273. (throw 'exit (cons selstring restriction)))
  2274. ((memq c prefixes)
  2275. (setq selstring (concat selstring (char-to-string c))
  2276. prefixes nil
  2277. rmheader (or rmheader t)
  2278. custom (delq nil (mapcar
  2279. (lambda (x)
  2280. (if (or (= (length (car x)) 1)
  2281. (/= (string-to-char (car x)) c))
  2282. nil
  2283. (cons (substring (car x) 1) (cdr x))))
  2284. custom))))
  2285. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2286. (message "Restriction is only possible in Org-mode buffers")
  2287. (ding) (sit-for 1))
  2288. ((eq c ?1)
  2289. (org-agenda-remove-restriction-lock 'noupdate)
  2290. (setq restriction 'buffer))
  2291. ((eq c ?0)
  2292. (org-agenda-remove-restriction-lock 'noupdate)
  2293. (setq restriction (if region-p 'region 'subtree)))
  2294. ((eq c ?<)
  2295. (org-agenda-remove-restriction-lock 'noupdate)
  2296. (setq restriction
  2297. (cond
  2298. ((eq restriction 'buffer)
  2299. (if region-p 'region 'subtree))
  2300. ((memq restriction '(subtree region))
  2301. nil)
  2302. (t 'buffer))))
  2303. ((eq c ?>)
  2304. (org-agenda-remove-restriction-lock 'noupdate)
  2305. (setq restriction nil))
  2306. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2307. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2308. ((and (> (length selstring) 0) (eq c ?\d))
  2309. (delete-window)
  2310. (org-agenda-get-restriction-and-command prefix-descriptions))
  2311. ((equal c ?q) (error "Abort"))
  2312. (t (error "Invalid key %c" c))))))))
  2313. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2314. (defvar org-agenda-last-arguments nil
  2315. "The arguments of the previous call to `org-agenda'.")
  2316. (defun org-agenda-run-series (name series)
  2317. (org-let (nth 1 series) '(org-prepare-agenda name))
  2318. (let* ((org-agenda-multi t)
  2319. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2320. (org-agenda-overriding-arguments
  2321. (or org-agenda-overriding-arguments
  2322. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2323. (get 'org-agenda-redo-command 'last-args))))
  2324. (cmds (car series))
  2325. (gprops (nth 1 series))
  2326. match ;; The byte compiler incorrectly complains about this. Keep it!
  2327. cmd type lprops)
  2328. (while (setq cmd (pop cmds))
  2329. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2330. (cond
  2331. ((eq type 'agenda)
  2332. (org-let2 gprops lprops
  2333. '(call-interactively 'org-agenda-list)))
  2334. ((eq type 'alltodo)
  2335. (org-let2 gprops lprops
  2336. '(call-interactively 'org-todo-list)))
  2337. ((eq type 'search)
  2338. (org-let2 gprops lprops
  2339. '(org-search-view current-prefix-arg match nil)))
  2340. ((eq type 'stuck)
  2341. (org-let2 gprops lprops
  2342. '(call-interactively 'org-agenda-list-stuck-projects)))
  2343. ((eq type 'tags)
  2344. (org-let2 gprops lprops
  2345. '(org-tags-view current-prefix-arg match)))
  2346. ((eq type 'tags-todo)
  2347. (org-let2 gprops lprops
  2348. '(org-tags-view '(4) match)))
  2349. ((eq type 'todo)
  2350. (org-let2 gprops lprops
  2351. '(org-todo-list match)))
  2352. ((fboundp type)
  2353. (org-let2 gprops lprops
  2354. '(funcall type match)))
  2355. (t (error "Invalid type in command series"))))
  2356. (widen)
  2357. (setq org-agenda-redo-command redo)
  2358. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2359. (goto-char (point-min)))
  2360. (org-fit-agenda-window)
  2361. (org-let (nth 1 series) '(org-finalize-agenda)))
  2362. ;;;###autoload
  2363. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2364. "Run an agenda command in batch mode and send the result to STDOUT.
  2365. If CMD-KEY is a string of length 1, it is used as a key in
  2366. `org-agenda-custom-commands' and triggers this command. If it is a
  2367. longer string it is used as a tags/todo match string.
  2368. Parameters are alternating variable names and values that will be bound
  2369. before running the agenda command."
  2370. (org-eval-in-environment (org-make-parameter-alist parameters)
  2371. (if (> (length cmd-key) 2)
  2372. (org-tags-view nil cmd-key)
  2373. (org-agenda nil cmd-key)))
  2374. (set-buffer org-agenda-buffer-name)
  2375. (princ (buffer-string)))
  2376. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2377. (defvar org-agenda-info nil)
  2378. ;;;###autoload
  2379. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2380. "Run an agenda command in batch mode and send the result to STDOUT.
  2381. If CMD-KEY is a string of length 1, it is used as a key in
  2382. `org-agenda-custom-commands' and triggers this command. If it is a
  2383. longer string it is used as a tags/todo match string.
  2384. Parameters are alternating variable names and values that will be bound
  2385. before running the agenda command.
  2386. The output gives a line for each selected agenda item. Each
  2387. item is a list of comma-separated values, like this:
  2388. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2389. category The category of the item
  2390. head The headline, without TODO kwd, TAGS and PRIORITY
  2391. type The type of the agenda entry, can be
  2392. todo selected in TODO match
  2393. tagsmatch selected in tags match
  2394. diary imported from diary
  2395. deadline a deadline on given date
  2396. scheduled scheduled on given date
  2397. timestamp entry has timestamp on given date
  2398. closed entry was closed on given date
  2399. upcoming-deadline warning about deadline
  2400. past-scheduled forwarded scheduled item
  2401. block entry has date block including g. date
  2402. todo The todo keyword, if any
  2403. tags All tags including inherited ones, separated by colons
  2404. date The relevant date, like 2007-2-14
  2405. time The time, like 15:00-16:50
  2406. extra Sting with extra planning info
  2407. priority-l The priority letter if any was given
  2408. priority-n The computed numerical priority
  2409. agenda-day The day in the agenda where this is listed"
  2410. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2411. (org-make-parameter-alist parameters))
  2412. (if (> (length cmd-key) 2)
  2413. (org-tags-view nil cmd-key)
  2414. (org-agenda nil cmd-key)))
  2415. (set-buffer org-agenda-buffer-name)
  2416. (let* ((lines (org-split-string (buffer-string) "\n"))
  2417. line)
  2418. (while (setq line (pop lines))
  2419. (catch 'next
  2420. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2421. (setq org-agenda-info
  2422. (org-fix-agenda-info (text-properties-at 0 line)))
  2423. (princ
  2424. (mapconcat 'org-agenda-export-csv-mapper
  2425. '(org-category txt type todo tags date time extra
  2426. priority-letter priority agenda-day)
  2427. ","))
  2428. (princ "\n")))))
  2429. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2430. (defun org-fix-agenda-info (props)
  2431. "Make sure all properties on an agenda item have a canonical form.
  2432. This ensures the export commands can easily use it."
  2433. (let (tmp re)
  2434. (when (setq tmp (plist-get props 'tags))
  2435. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2436. (when (setq tmp (plist-get props 'date))
  2437. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2438. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2439. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2440. (setq tmp (calendar-date-string tmp)))
  2441. (setq props (plist-put props 'date tmp)))
  2442. (when (setq tmp (plist-get props 'day))
  2443. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2444. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2445. (setq tmp (calendar-date-string tmp)))
  2446. (setq props (plist-put props 'day tmp))
  2447. (setq props (plist-put props 'agenda-day tmp)))
  2448. (when (setq tmp (plist-get props 'txt))
  2449. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2450. (plist-put props 'priority-letter (match-string 1 tmp))
  2451. (setq tmp (replace-match "" t t tmp)))
  2452. (when (and (setq re (plist-get props 'org-todo-regexp))
  2453. (setq re (concat "\\`\\.*" re " ?"))
  2454. (string-match re tmp))
  2455. (plist-put props 'todo (match-string 1 tmp))
  2456. (setq tmp (replace-match "" t t tmp)))
  2457. (plist-put props 'txt tmp)))
  2458. props)
  2459. (defun org-agenda-export-csv-mapper (prop)
  2460. (let ((res (plist-get org-agenda-info prop)))
  2461. (setq res
  2462. (cond
  2463. ((not res) "")
  2464. ((stringp res) res)
  2465. (t (prin1-to-string res))))
  2466. (while (string-match "," res)
  2467. (setq res (replace-match ";" t t res)))
  2468. (org-trim res)))
  2469. ;;;###autoload
  2470. (defun org-store-agenda-views (&rest parameters)
  2471. (interactive)
  2472. (eval (list 'org-batch-store-agenda-views)))
  2473. ;;;###autoload
  2474. (defmacro org-batch-store-agenda-views (&rest parameters)
  2475. "Run all custom agenda commands that have a file argument."
  2476. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2477. (pop-up-frames nil)
  2478. (dir default-directory)
  2479. (pars (org-make-parameter-alist parameters))
  2480. cmd thiscmdkey files opts cmd-or-set)
  2481. (save-window-excursion
  2482. (while cmds
  2483. (setq cmd (pop cmds)
  2484. thiscmdkey (car cmd)
  2485. cmd-or-set (nth 2 cmd)
  2486. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2487. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2488. (if (stringp files) (setq files (list files)))
  2489. (when files
  2490. (org-eval-in-environment (append org-agenda-exporter-settings
  2491. opts pars)
  2492. (org-agenda nil thiscmdkey))
  2493. (set-buffer org-agenda-buffer-name)
  2494. (while files
  2495. (org-eval-in-environment (append org-agenda-exporter-settings
  2496. opts pars)
  2497. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2498. (and (get-buffer org-agenda-buffer-name)
  2499. (kill-buffer org-agenda-buffer-name)))))))
  2500. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2501. (defun org-agenda-mark-header-line (pos)
  2502. "Mark the line at POS as an agenda structure header."
  2503. (save-excursion
  2504. (goto-char pos)
  2505. (put-text-property (point-at-bol) (point-at-eol)
  2506. 'org-agenda-structural-header t)
  2507. (when org-agenda-title-append
  2508. (put-text-property (point-at-bol) (point-at-eol)
  2509. 'org-agenda-title-append org-agenda-title-append))))
  2510. (defvar org-mobile-creating-agendas)
  2511. (defvar org-agenda-write-buffer-name "Agenda View")
  2512. (defun org-agenda-write (file &optional open nosettings)
  2513. "Write the current buffer (an agenda view) as a file.
  2514. Depending on the extension of the file name, plain text (.txt),
  2515. HTML (.html or .htm) or Postscript (.ps) is produced.
  2516. If the extension is .ics, run icalendar export over all files used
  2517. to construct the agenda and limit the export to entries listed in the
  2518. agenda now.
  2519. With prefix argument OPEN, open the new file immediately.
  2520. If NOSETTINGS is given, do not scope the settings of
  2521. `org-agenda-exporter-settings' into the export commands. This is used when
  2522. the settings have already been scoped and we do not wish to overrule other,
  2523. higher priority settings."
  2524. (interactive "FWrite agenda to file: \nP")
  2525. (if (not (file-writable-p file))
  2526. (error "Cannot write agenda to file %s" file))
  2527. (org-let (if nosettings nil org-agenda-exporter-settings)
  2528. '(save-excursion
  2529. (save-window-excursion
  2530. (org-agenda-mark-filtered-text)
  2531. (let ((bs (copy-sequence (buffer-string))) beg)
  2532. (org-agenda-unmark-filtered-text)
  2533. (with-temp-buffer
  2534. (rename-buffer org-agenda-write-buffer-name t)
  2535. (set-buffer-modified-p nil)
  2536. (insert bs)
  2537. (org-agenda-remove-marked-text 'org-filtered)
  2538. (while (setq beg (text-property-any (point-min) (point-max)
  2539. 'org-filtered t))
  2540. (delete-region
  2541. beg (or (next-single-property-change beg 'org-filtered)
  2542. (point-max))))
  2543. (run-hooks 'org-agenda-before-write-hook)
  2544. (cond
  2545. ((org-bound-and-true-p org-mobile-creating-agendas)
  2546. (org-mobile-write-agenda-for-mobile file))
  2547. ((string-match "\\.html?\\'" file)
  2548. (require 'htmlize)
  2549. (set-buffer (htmlize-buffer (current-buffer)))
  2550. (when (and org-agenda-export-html-style
  2551. (string-match "<style>" org-agenda-export-html-style))
  2552. ;; replace <style> section with org-agenda-export-html-style
  2553. (goto-char (point-min))
  2554. (kill-region (- (search-forward "<style") 6)
  2555. (search-forward "</style>"))
  2556. (insert org-agenda-export-html-style))
  2557. (write-file file)
  2558. (kill-buffer (current-buffer))
  2559. (message "HTML written to %s" file))
  2560. ((string-match "\\.ps\\'" file)
  2561. (require 'ps-print)
  2562. (ps-print-buffer-with-faces file)
  2563. (message "Postscript written to %s" file))
  2564. ((string-match "\\.pdf\\'" file)
  2565. (require 'ps-print)
  2566. (ps-print-buffer-with-faces
  2567. (concat (file-name-sans-extension file) ".ps"))
  2568. (call-process "ps2pdf" nil nil nil
  2569. (expand-file-name
  2570. (concat (file-name-sans-extension file) ".ps"))
  2571. (expand-file-name file))
  2572. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2573. (message "PDF written to %s" file))
  2574. ((string-match "\\.ics\\'" file)
  2575. (require 'org-icalendar)
  2576. (let ((org-agenda-marker-table
  2577. (org-create-marker-find-array
  2578. (org-agenda-collect-markers)))
  2579. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2580. (org-combined-agenda-icalendar-file file))
  2581. (apply 'org-export-icalendar 'combine
  2582. (org-agenda-files nil 'ifmode))))
  2583. (t
  2584. (let ((bs (buffer-string)))
  2585. (find-file file)
  2586. (erase-buffer)
  2587. (insert bs)
  2588. (save-buffer 0)
  2589. (kill-buffer (current-buffer))
  2590. (message "Plain text written to %s" file))))))))
  2591. (set-buffer org-agenda-buffer-name))
  2592. (when open (org-open-file file)))
  2593. (defvar org-agenda-tag-filter-overlays nil)
  2594. (defvar org-agenda-cat-filter-overlays nil)
  2595. (defun org-agenda-mark-filtered-text ()
  2596. "Mark all text hidden by filtering with a text property."
  2597. (let ((inhibit-read-only t))
  2598. (mapc
  2599. (lambda (o)
  2600. (when (equal (overlay-buffer o) (current-buffer))
  2601. (put-text-property
  2602. (overlay-start o) (overlay-end o)
  2603. 'org-filtered t)))
  2604. (append org-agenda-tag-filter-overlays
  2605. org-agenda-cat-filter-overlays))))
  2606. (defun org-agenda-unmark-filtered-text ()
  2607. "Remove the filtering text property."
  2608. (let ((inhibit-read-only t))
  2609. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2610. (defun org-agenda-remove-marked-text (property &optional value)
  2611. "Delete all text marked with VALUE of PROPERTY.
  2612. VALUE defaults to t."
  2613. (let (beg)
  2614. (setq value (or value t))
  2615. (while (setq beg (text-property-any (point-min) (point-max)
  2616. property value))
  2617. (delete-region
  2618. beg (or (next-single-property-change beg 'org-filtered)
  2619. (point-max))))))
  2620. (defun org-agenda-add-entry-text ()
  2621. "Add entry text to agenda lines.
  2622. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2623. entry text following headings shown in the agenda.
  2624. Drawers will be excluded, also the line with scheduling/deadline info."
  2625. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2626. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2627. (let (m txt)
  2628. (goto-char (point-min))
  2629. (while (not (eobp))
  2630. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2631. (beginning-of-line 2)
  2632. (setq txt (org-agenda-get-some-entry-text
  2633. m org-agenda-add-entry-text-maxlines " > "))
  2634. (end-of-line 1)
  2635. (if (string-match "\\S-" txt)
  2636. (insert "\n" txt)
  2637. (or (eobp) (forward-char 1))))))))
  2638. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2639. &rest keep)
  2640. "Extract entry text from MARKER, at most N-LINES lines.
  2641. This will ignore drawers etc, just get the text.
  2642. If INDENT is given, prefix every line with this string. If KEEP is
  2643. given, it is a list of symbols, defining stuff that should not be
  2644. removed from the entry content. Currently only `planning' is allowed here."
  2645. (let (txt drawer-re kwd-time-re ind)
  2646. (save-excursion
  2647. (with-current-buffer (marker-buffer marker)
  2648. (if (not (eq major-mode 'org-mode))
  2649. (setq txt "")
  2650. (save-excursion
  2651. (save-restriction
  2652. (widen)
  2653. (goto-char marker)
  2654. (end-of-line 1)
  2655. (setq txt (buffer-substring
  2656. (min (1+ (point)) (point-max))
  2657. (progn (outline-next-heading) (point)))
  2658. drawer-re org-drawer-regexp
  2659. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2660. ".*\n?"))
  2661. (with-temp-buffer
  2662. (insert txt)
  2663. (when org-agenda-add-entry-text-descriptive-links
  2664. (goto-char (point-min))
  2665. (while (org-activate-bracket-links (point-max))
  2666. (add-text-properties (match-beginning 0) (match-end 0)
  2667. '(face org-link))))
  2668. (goto-char (point-min))
  2669. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2670. (set-text-properties (match-beginning 0) (match-end 0)
  2671. nil))
  2672. (goto-char (point-min))
  2673. (while (re-search-forward drawer-re nil t)
  2674. (delete-region
  2675. (match-beginning 0)
  2676. (progn (re-search-forward
  2677. "^[ \t]*:END:.*\n?" nil 'move)
  2678. (point))))
  2679. (unless (member 'planning keep)
  2680. (goto-char (point-min))
  2681. (while (re-search-forward kwd-time-re nil t)
  2682. (replace-match "")))
  2683. (goto-char (point-min))
  2684. (when org-agenda-entry-text-exclude-regexps
  2685. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2686. (while (setq re (pop re-list))
  2687. (goto-char (point-min))
  2688. (while (re-search-forward re nil t)
  2689. (replace-match "")))))
  2690. (goto-char (point-max))
  2691. (skip-chars-backward " \t\n")
  2692. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2693. ;; find and remove min common indentation
  2694. (goto-char (point-min))
  2695. (untabify (point-min) (point-max))
  2696. (setq ind (org-get-indentation))
  2697. (while (not (eobp))
  2698. (unless (looking-at "[ \t]*$")
  2699. (setq ind (min ind (org-get-indentation))))
  2700. (beginning-of-line 2))
  2701. (goto-char (point-min))
  2702. (while (not (eobp))
  2703. (unless (looking-at "[ \t]*$")
  2704. (move-to-column ind)
  2705. (delete-region (point-at-bol) (point)))
  2706. (beginning-of-line 2))
  2707. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2708. (goto-char (point-min))
  2709. (when indent
  2710. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2711. (replace-match indent t t)))
  2712. (goto-char (point-min))
  2713. (while (looking-at "[ \t]*\n") (replace-match ""))
  2714. (goto-char (point-max))
  2715. (when (> (org-current-line)
  2716. n-lines)
  2717. (org-goto-line (1+ n-lines))
  2718. (backward-char 1))
  2719. (setq txt (buffer-substring (point-min) (point)))))))))
  2720. txt))
  2721. (defun org-agenda-collect-markers ()
  2722. "Collect the markers pointing to entries in the agenda buffer."
  2723. (let (m markers)
  2724. (save-excursion
  2725. (goto-char (point-min))
  2726. (while (not (eobp))
  2727. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2728. (org-get-at-bol 'org-marker)))
  2729. (push m markers))
  2730. (beginning-of-line 2)))
  2731. (nreverse markers)))
  2732. (defun org-create-marker-find-array (marker-list)
  2733. "Create a alist of files names with all marker positions in that file."
  2734. (let (f tbl m a p)
  2735. (while (setq m (pop marker-list))
  2736. (setq p (marker-position m)
  2737. f (buffer-file-name (or (buffer-base-buffer
  2738. (marker-buffer m))
  2739. (marker-buffer m))))
  2740. (if (setq a (assoc f tbl))
  2741. (push (marker-position m) (cdr a))
  2742. (push (list f p) tbl)))
  2743. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2744. tbl)))
  2745. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2746. (defun org-check-agenda-marker-table ()
  2747. "Check of the current entry is on the marker list."
  2748. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2749. a)
  2750. (and (setq a (assoc file org-agenda-marker-table))
  2751. (save-match-data
  2752. (save-excursion
  2753. (org-back-to-heading t)
  2754. (member (point) (cdr a)))))))
  2755. (defun org-check-for-org-mode ()
  2756. "Make sure current buffer is in org-mode. Error if not."
  2757. (or (eq major-mode 'org-mode)
  2758. (error "Cannot execute org-mode agenda command on buffer in %s"
  2759. major-mode)))
  2760. (defun org-fit-agenda-window ()
  2761. "Fit the window to the buffer size."
  2762. (and (memq org-agenda-window-setup '(reorganize-frame))
  2763. (fboundp 'fit-window-to-buffer)
  2764. (org-fit-window-to-buffer
  2765. nil
  2766. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2767. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2768. ;;; Agenda prepare and finalize
  2769. (defvar org-agenda-multi nil) ; dynamically scoped
  2770. (defvar org-agenda-buffer-name "*Org Agenda*")
  2771. (defvar org-pre-agenda-window-conf nil)
  2772. (defvar org-agenda-columns-active nil)
  2773. (defvar org-agenda-name nil)
  2774. (defvar org-agenda-tag-filter nil)
  2775. (defvar org-agenda-category-filter nil)
  2776. (defvar org-agenda-tag-filter-while-redo nil)
  2777. (defvar org-agenda-tag-filter-preset nil
  2778. "A preset of the tags filter used for secondary agenda filtering.
  2779. This must be a list of strings, each string must be a single tag preceded
  2780. by \"+\" or \"-\".
  2781. This variable should not be set directly, but agenda custom commands can
  2782. bind it in the options section. The preset filter is a global property of
  2783. the entire agenda view. In a block agenda, it will not work reliably to
  2784. define a filter for one of the individual blocks. You need to set it in
  2785. the global options and expect it to be applied to the entire view.")
  2786. (defvar org-agenda-category-filter-preset nil
  2787. "A preset of the category filter used for secondary agenda filtering.
  2788. This must be a list of strings, each string must be a single category
  2789. preceded by \"+\" or \"-\".
  2790. This variable should not be set directly, but agenda custom commands can
  2791. bind it in the options section. The preset filter is a global property of
  2792. the entire agenda view. In a block agenda, it will not work reliably to
  2793. define a filter for one of the individual blocks. You need to set it in
  2794. the global options and expect it to be applied to the entire view.")
  2795. (defun org-prepare-agenda (&optional name)
  2796. (setq org-todo-keywords-for-agenda nil)
  2797. (setq org-done-keywords-for-agenda nil)
  2798. (setq org-drawers-for-agenda nil)
  2799. (unless org-agenda-persistent-filter
  2800. (setq org-agenda-tag-filter nil
  2801. org-agenda-category-filter nil))
  2802. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2803. (put 'org-agenda-category-filter :preset-filter org-agenda-category-filter-preset)
  2804. (if org-agenda-multi
  2805. (progn
  2806. (setq buffer-read-only nil)
  2807. (goto-char (point-max))
  2808. (unless (or (bobp) org-agenda-compact-blocks
  2809. (not org-agenda-block-separator))
  2810. (insert "\n"
  2811. (if (stringp org-agenda-block-separator)
  2812. org-agenda-block-separator
  2813. (make-string (window-width) org-agenda-block-separator))
  2814. "\n"))
  2815. (narrow-to-region (point) (point-max)))
  2816. (org-agenda-reset-markers)
  2817. (setq org-agenda-contributing-files nil)
  2818. (setq org-agenda-columns-active nil)
  2819. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2820. (setq org-todo-keywords-for-agenda
  2821. (org-uniquify org-todo-keywords-for-agenda))
  2822. (setq org-done-keywords-for-agenda
  2823. (org-uniquify org-done-keywords-for-agenda))
  2824. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2825. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2826. (awin (get-buffer-window abuf)))
  2827. (cond
  2828. ((equal (current-buffer) abuf) nil)
  2829. (awin (select-window awin))
  2830. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2831. ((equal org-agenda-window-setup 'current-window)
  2832. (org-pop-to-buffer-same-window abuf))
  2833. ((equal org-agenda-window-setup 'other-window)
  2834. (org-switch-to-buffer-other-window abuf))
  2835. ((equal org-agenda-window-setup 'other-frame)
  2836. (switch-to-buffer-other-frame abuf))
  2837. ((equal org-agenda-window-setup 'reorganize-frame)
  2838. (delete-other-windows)
  2839. (org-switch-to-buffer-other-window abuf)))
  2840. ;; additional test in case agenda is invoked from within agenda
  2841. ;; buffer via elisp link
  2842. (unless (equal (current-buffer) abuf)
  2843. (org-pop-to-buffer-same-window abuf)))
  2844. (setq buffer-read-only nil)
  2845. (let ((inhibit-read-only t)) (erase-buffer))
  2846. (org-agenda-mode)
  2847. (and name (not org-agenda-name)
  2848. (org-set-local 'org-agenda-name name)))
  2849. (setq buffer-read-only nil))
  2850. (defun org-finalize-agenda ()
  2851. "Finishing touch for the agenda buffer, called just before displaying it."
  2852. (unless org-agenda-multi
  2853. (save-excursion
  2854. (let ((inhibit-read-only t))
  2855. (goto-char (point-min))
  2856. (while (org-activate-bracket-links (point-max))
  2857. (add-text-properties (match-beginning 0) (match-end 0)
  2858. '(face org-link)))
  2859. (org-agenda-align-tags)
  2860. (unless org-agenda-with-colors
  2861. (remove-text-properties (point-min) (point-max) '(face nil))))
  2862. (if (and (boundp 'org-agenda-overriding-columns-format)
  2863. org-agenda-overriding-columns-format)
  2864. (org-set-local 'org-agenda-overriding-columns-format
  2865. org-agenda-overriding-columns-format))
  2866. (if (and (boundp 'org-agenda-view-columns-initially)
  2867. org-agenda-view-columns-initially)
  2868. (org-agenda-columns))
  2869. (when org-agenda-fontify-priorities
  2870. (org-agenda-fontify-priorities))
  2871. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2872. (org-agenda-dim-blocked-tasks))
  2873. (org-agenda-mark-clocking-task)
  2874. (when org-agenda-entry-text-mode
  2875. (org-agenda-entry-text-hide)
  2876. (org-agenda-entry-text-show))
  2877. (if (functionp 'org-habit-insert-consistency-graphs)
  2878. (org-habit-insert-consistency-graphs))
  2879. (run-hooks 'org-finalize-agenda-hook)
  2880. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2881. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  2882. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  2883. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  2884. (org-agenda-filter-apply org-agenda-category-filter 'category))
  2885. )))
  2886. (defun org-agenda-mark-clocking-task ()
  2887. "Mark the current clock entry in the agenda if it is present."
  2888. (mapc (lambda (o)
  2889. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2890. (delete-overlay o)))
  2891. (overlays-in (point-min) (point-max)))
  2892. (when (marker-buffer org-clock-hd-marker)
  2893. (save-excursion
  2894. (goto-char (point-min))
  2895. (let (s ov)
  2896. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2897. (goto-char s)
  2898. (when (equal (org-get-at-bol 'org-hd-marker)
  2899. org-clock-hd-marker)
  2900. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2901. (overlay-put ov 'type 'org-agenda-clocking)
  2902. (overlay-put ov 'face 'org-agenda-clocking)
  2903. (overlay-put ov 'help-echo
  2904. "The clock is running in this item")))))))
  2905. (defun org-agenda-fontify-priorities ()
  2906. "Make highest priority lines bold, and lowest italic."
  2907. (interactive)
  2908. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2909. (delete-overlay o)))
  2910. (overlays-in (point-min) (point-max)))
  2911. (save-excursion
  2912. (let ((inhibit-read-only t)
  2913. b e p ov h l)
  2914. (goto-char (point-min))
  2915. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2916. (setq h (or (get-char-property (point) 'org-highest-priority)
  2917. org-highest-priority)
  2918. l (or (get-char-property (point) 'org-lowest-priority)
  2919. org-lowest-priority)
  2920. p (string-to-char (match-string 1))
  2921. b (match-beginning 0)
  2922. e (if (eq org-agenda-fontify-priorities 'cookies)
  2923. (match-end 0)
  2924. (point-at-eol))
  2925. ov (make-overlay b e))
  2926. (overlay-put
  2927. ov 'face
  2928. (cond ((org-face-from-face-or-color
  2929. 'priority nil
  2930. (cdr (assoc p org-priority-faces))))
  2931. ((and (listp org-agenda-fontify-priorities)
  2932. (org-face-from-face-or-color
  2933. 'priority nil
  2934. (cdr (assoc p org-agenda-fontify-priorities)))))
  2935. ((equal p l) 'italic)
  2936. ((equal p h) 'bold)))
  2937. (overlay-put ov 'org-type 'org-priority)))))
  2938. (defun org-agenda-dim-blocked-tasks ()
  2939. "Dim currently blocked TODO's in the agenda display."
  2940. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2941. (delete-overlay o)))
  2942. (overlays-in (point-min) (point-max)))
  2943. (save-excursion
  2944. (let ((inhibit-read-only t)
  2945. (org-depend-tag-blocked nil)
  2946. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2947. org-blocked-by-checkboxes
  2948. invis1 b e p ov h l)
  2949. (goto-char (point-min))
  2950. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2951. (and pos (goto-char (1+ pos))))
  2952. (setq org-blocked-by-checkboxes nil invis1 invis)
  2953. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2954. (when (and marker
  2955. (with-current-buffer (marker-buffer marker)
  2956. (save-excursion (goto-char marker)
  2957. (org-entry-blocked-p))))
  2958. (if org-blocked-by-checkboxes (setq invis1 nil))
  2959. (setq b (if invis1
  2960. (max (point-min) (1- (point-at-bol)))
  2961. (point-at-bol))
  2962. e (point-at-eol)
  2963. ov (make-overlay b e))
  2964. (if invis1
  2965. (overlay-put ov 'invisible t)
  2966. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2967. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2968. (defvar org-agenda-skip-function nil
  2969. "Function to be called at each match during agenda construction.
  2970. If this function returns nil, the current match should not be skipped.
  2971. Otherwise, the function must return a position from where the search
  2972. should be continued.
  2973. This may also be a Lisp form, it will be evaluated.
  2974. Never set this variable using `setq' or so, because then it will apply
  2975. to all future agenda commands. If you do want a global skipping condition,
  2976. use the option `org-agenda-skip-function-global' instead.
  2977. The correct usage for `org-agenda-skip-function' is to bind it with
  2978. `let' to scope it dynamically into the agenda-constructing command.
  2979. A good way to set it is through options in `org-agenda-custom-commands'.")
  2980. (defun org-agenda-skip ()
  2981. "Throw to `:skip' in places that should be skipped.
  2982. Also moves point to the end of the skipped region, so that search can
  2983. continue from there."
  2984. (let ((p (point-at-bol)) to)
  2985. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2986. (get-text-property p :org-archived)
  2987. (org-end-of-subtree t)
  2988. (throw :skip t))
  2989. (and org-agenda-skip-comment-trees
  2990. (get-text-property p :org-comment)
  2991. (org-end-of-subtree t)
  2992. (throw :skip t))
  2993. (if (equal (char-after p) ?#) (throw :skip t))
  2994. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2995. (org-agenda-skip-eval org-agenda-skip-function)))
  2996. (goto-char to)
  2997. (throw :skip t))))
  2998. (defun org-agenda-skip-eval (form)
  2999. "If FORM is a function or a list, call (or eval) is and return result.
  3000. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3001. and match data are returned to the previous state no matter what these
  3002. functions do."
  3003. (let (fp)
  3004. (and form
  3005. (or (setq fp (functionp form))
  3006. (consp form))
  3007. (save-excursion
  3008. (save-match-data
  3009. (if fp
  3010. (funcall form)
  3011. (eval form)))))))
  3012. (defvar org-agenda-markers nil
  3013. "List of all currently active markers created by `org-agenda'.")
  3014. (defvar org-agenda-last-marker-time (org-float-time)
  3015. "Creation time of the last agenda marker.")
  3016. (defun org-agenda-new-marker (&optional pos)
  3017. "Return a new agenda marker.
  3018. Org-mode keeps a list of these markers and resets them when they are
  3019. no longer in use."
  3020. (let ((m (copy-marker (or pos (point)))))
  3021. (setq org-agenda-last-marker-time (org-float-time))
  3022. (push m org-agenda-markers)
  3023. m))
  3024. (defun org-agenda-reset-markers ()
  3025. "Reset markers created by `org-agenda'."
  3026. (while org-agenda-markers
  3027. (move-marker (pop org-agenda-markers) nil)))
  3028. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3029. "Save relative positions of markers in region."
  3030. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3031. org-agenda-markers))
  3032. ;;; Entry text mode
  3033. (defun org-agenda-entry-text-show-here ()
  3034. "Add some text from the entry as context to the current line."
  3035. (let (m txt o)
  3036. (setq m (org-get-at-bol 'org-hd-marker))
  3037. (unless (marker-buffer m)
  3038. (error "No marker points to an entry here"))
  3039. (setq txt (concat "\n" (org-no-properties
  3040. (org-agenda-get-some-entry-text
  3041. m org-agenda-entry-text-maxlines " > "))))
  3042. (when (string-match "\\S-" txt)
  3043. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3044. (overlay-put o 'evaporate t)
  3045. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3046. (overlay-put o 'after-string txt))))
  3047. (defun org-agenda-entry-text-show ()
  3048. "Add entry context for all agenda lines."
  3049. (interactive)
  3050. (save-excursion
  3051. (goto-char (point-max))
  3052. (beginning-of-line 1)
  3053. (while (not (bobp))
  3054. (when (org-get-at-bol 'org-hd-marker)
  3055. (org-agenda-entry-text-show-here))
  3056. (beginning-of-line 0))))
  3057. (defun org-agenda-entry-text-hide ()
  3058. "Remove any shown entry context."
  3059. (delq nil
  3060. (mapcar (lambda (o)
  3061. (if (eq (overlay-get o 'org-overlay-type)
  3062. 'agenda-entry-content)
  3063. (progn (delete-overlay o) t)))
  3064. (overlays-in (point-min) (point-max)))))
  3065. (defun org-agenda-get-day-face (date)
  3066. "Return the face DATE should be displayed with."
  3067. (or (and (functionp org-agenda-day-face-function)
  3068. (funcall org-agenda-day-face-function date))
  3069. (cond ((org-agenda-todayp date)
  3070. 'org-agenda-date-today)
  3071. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3072. 'org-agenda-date-weekend)
  3073. (t 'org-agenda-date))))
  3074. ;;; Agenda timeline
  3075. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3076. (defun org-timeline (&optional dotodo)
  3077. "Show a time-sorted view of the entries in the current org file.
  3078. Only entries with a time stamp of today or later will be listed. With
  3079. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3080. under the current date.
  3081. If the buffer contains an active region, only check the region for
  3082. dates."
  3083. (interactive "P")
  3084. (org-compile-prefix-format 'timeline)
  3085. (org-set-sorting-strategy 'timeline)
  3086. (let* ((dopast t)
  3087. (doclosed org-agenda-show-log)
  3088. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3089. (current-buffer))))
  3090. (date (calendar-current-date))
  3091. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3092. (end (if (org-region-active-p) (region-end) (point-max)))
  3093. (day-numbers (org-get-all-dates beg end 'no-ranges
  3094. t doclosed ; always include today
  3095. org-timeline-show-empty-dates))
  3096. (org-deadline-warning-days 0)
  3097. (org-agenda-only-exact-dates t)
  3098. (today (org-today))
  3099. (past t)
  3100. args
  3101. s e rtn d emptyp)
  3102. (setq org-agenda-redo-command
  3103. (list 'progn
  3104. (list 'org-switch-to-buffer-other-window (current-buffer))
  3105. (list 'org-timeline (list 'quote dotodo))))
  3106. (if (not dopast)
  3107. ;; Remove past dates from the list of dates.
  3108. (setq day-numbers (delq nil (mapcar (lambda(x)
  3109. (if (>= x today) x nil))
  3110. day-numbers))))
  3111. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3112. (if doclosed (push :closed args))
  3113. (push :timestamp args)
  3114. (push :deadline args)
  3115. (push :scheduled args)
  3116. (push :sexp args)
  3117. (if dotodo (push :todo args))
  3118. (insert "Timeline of file " entry "\n")
  3119. (add-text-properties (point-min) (point)
  3120. (list 'face 'org-agenda-structure))
  3121. (org-agenda-mark-header-line (point-min))
  3122. (while (setq d (pop day-numbers))
  3123. (if (and (listp d) (eq (car d) :omitted))
  3124. (progn
  3125. (setq s (point))
  3126. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3127. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3128. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3129. (if (and (>= d today)
  3130. dopast
  3131. past)
  3132. (progn
  3133. (setq past nil)
  3134. (insert (make-string 79 ?-) "\n")))
  3135. (setq date (calendar-gregorian-from-absolute d))
  3136. (setq s (point))
  3137. (setq rtn (and (not emptyp)
  3138. (apply 'org-agenda-get-day-entries entry
  3139. date args)))
  3140. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3141. (progn
  3142. (insert
  3143. (if (stringp org-agenda-format-date)
  3144. (format-time-string org-agenda-format-date
  3145. (org-time-from-absolute date))
  3146. (funcall org-agenda-format-date date))
  3147. "\n")
  3148. (put-text-property s (1- (point)) 'face
  3149. (org-agenda-get-day-face date))
  3150. (put-text-property s (1- (point)) 'org-date-line t)
  3151. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3152. (if (equal d today)
  3153. (put-text-property s (1- (point)) 'org-today t))
  3154. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3155. (put-text-property s (1- (point)) 'day d)))))
  3156. (goto-char (point-min))
  3157. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3158. (point-min)))
  3159. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3160. (org-finalize-agenda)
  3161. (setq buffer-read-only t)))
  3162. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3163. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3164. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3165. not every single day in the range. If FORCE-TODAY is non-nil, make
  3166. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3167. inactive time stamps (those in square brackets) are included.
  3168. When EMPTY is non-nil, also include days without any entries."
  3169. (let ((re (concat
  3170. (if pre-re pre-re "")
  3171. (if inactive org-ts-regexp-both org-ts-regexp)))
  3172. dates dates1 date day day1 day2 ts1 ts2 pos)
  3173. (if force-today
  3174. (setq dates (list (org-today))))
  3175. (save-excursion
  3176. (goto-char beg)
  3177. (while (re-search-forward re end t)
  3178. (setq day (time-to-days (org-time-string-to-time
  3179. (substring (match-string 1) 0 10)
  3180. (current-buffer) (match-beginning 0))))
  3181. (or (memq day dates) (push day dates)))
  3182. (unless no-ranges
  3183. (goto-char beg)
  3184. (while (re-search-forward org-tr-regexp end t)
  3185. (setq pos (match-beginning 0))
  3186. (setq ts1 (substring (match-string 1) 0 10)
  3187. ts2 (substring (match-string 2) 0 10)
  3188. day1 (time-to-days (org-time-string-to-time
  3189. ts1 (current-buffer) pos))
  3190. day2 (time-to-days (org-time-string-to-time
  3191. ts2 (current-buffer) pos)))
  3192. (while (< (setq day1 (1+ day1)) day2)
  3193. (or (memq day1 dates) (push day1 dates)))))
  3194. (setq dates (sort dates '<))
  3195. (when empty
  3196. (while (setq day (pop dates))
  3197. (setq day2 (car dates))
  3198. (push day dates1)
  3199. (when (and day2 empty)
  3200. (if (or (eq empty t)
  3201. (and (numberp empty) (<= (- day2 day) empty)))
  3202. (while (< (setq day (1+ day)) day2)
  3203. (push (list day) dates1))
  3204. (push (cons :omitted (- day2 day)) dates1))))
  3205. (setq dates (nreverse dates1)))
  3206. dates)))
  3207. ;;; Agenda Daily/Weekly
  3208. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3209. "Start day for the agenda view.
  3210. Custom commands can set this variable in the options section.")
  3211. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3212. (defvar org-agenda-current-span nil
  3213. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3214. (defvar org-arg-loc nil) ; local variable
  3215. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3216. "List of types searched for when creating the daily/weekly agenda.
  3217. This variable is a list of symbols that controls the types of
  3218. items that appear in the daily/weekly agenda. Allowed symbols in this
  3219. list are are
  3220. :timestamp List items containing a date stamp or date range matching
  3221. the selected date. This includes sexp entries in
  3222. angular brackets.
  3223. :sexp List entries resulting from plain diary-like sexps.
  3224. :deadline List deadline due on that date. When the date is today,
  3225. also list any deadlines past due, or due within
  3226. `org-deadline-warning-days'. `:deadline' must appear before
  3227. `:scheduled' if the setting of
  3228. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3229. any effect.
  3230. :scheduled List all items which are scheduled for the given date.
  3231. The diary for *today* also contains items which were
  3232. scheduled earlier and are not yet marked DONE.
  3233. By default, all four types are turned on.
  3234. Never set this variable globally using `setq', because then it
  3235. will apply to all future agenda commands. Instead, bind it with
  3236. `let' to scope it dynamically into the agenda-constructing
  3237. command. A good way to set it is through options in
  3238. `org-agenda-custom-commands'. For a more flexible (though
  3239. somewhat less efficient) way of determining what is included in
  3240. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3241. ;;;###autoload
  3242. (defun org-agenda-list (&optional arg start-day span)
  3243. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3244. The view will be for the current day or week, but from the overview buffer
  3245. you will be able to go to other days/weeks.
  3246. With a numeric prefix argument in an interactive call, the agenda will
  3247. span ARG days. Lisp programs should instead specify SPAN to change
  3248. the number of days. SPAN defaults to `org-agenda-span'.
  3249. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3250. given in `org-agenda-start-on-weekday'."
  3251. (interactive "P")
  3252. (if (and (integerp arg) (> arg 0))
  3253. (setq span arg arg nil))
  3254. (setq start-day (or start-day org-agenda-start-day))
  3255. (if org-agenda-overriding-arguments
  3256. (setq arg (car org-agenda-overriding-arguments)
  3257. start-day (nth 1 org-agenda-overriding-arguments)
  3258. span (nth 2 org-agenda-overriding-arguments)))
  3259. (if (stringp start-day)
  3260. ;; Convert to an absolute day number
  3261. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3262. (setq org-agenda-last-arguments (list arg start-day span))
  3263. (org-compile-prefix-format 'agenda)
  3264. (org-set-sorting-strategy 'agenda)
  3265. (let* ((span (org-agenda-ndays-to-span
  3266. (or span org-agenda-ndays org-agenda-span)))
  3267. (today (org-today))
  3268. (sd (or start-day today))
  3269. (ndays (org-agenda-span-to-ndays span sd))
  3270. (org-agenda-start-on-weekday
  3271. (if (eq ndays 7)
  3272. org-agenda-start-on-weekday))
  3273. (thefiles (org-agenda-files nil 'ifmode))
  3274. (files thefiles)
  3275. (start (if (or (null org-agenda-start-on-weekday)
  3276. (< ndays 7))
  3277. sd
  3278. (let* ((nt (calendar-day-of-week
  3279. (calendar-gregorian-from-absolute sd)))
  3280. (n1 org-agenda-start-on-weekday)
  3281. (d (- nt n1)))
  3282. (- sd (+ (if (< d 0) 7 0) d)))))
  3283. (day-numbers (list start))
  3284. (day-cnt 0)
  3285. (inhibit-redisplay (not debug-on-error))
  3286. s e rtn rtnall file date d start-pos end-pos todayp
  3287. clocktable-start clocktable-end filter)
  3288. (setq org-agenda-redo-command
  3289. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3290. (dotimes (n (1- ndays))
  3291. (push (1+ (car day-numbers)) day-numbers))
  3292. (setq day-numbers (nreverse day-numbers))
  3293. (setq clocktable-start (car day-numbers)
  3294. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3295. (org-prepare-agenda "Day/Week")
  3296. (org-set-local 'org-starting-day (car day-numbers))
  3297. (org-set-local 'org-arg-loc arg)
  3298. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3299. (unless org-agenda-compact-blocks
  3300. (let* ((d1 (car day-numbers))
  3301. (d2 (org-last day-numbers))
  3302. (w1 (org-days-to-iso-week d1))
  3303. (w2 (org-days-to-iso-week d2)))
  3304. (setq s (point))
  3305. (if org-agenda-overriding-header
  3306. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3307. nil 'face 'org-agenda-structure) "\n")
  3308. (insert (org-agenda-span-name span)
  3309. "-agenda"
  3310. (if (< (- d2 d1) 350)
  3311. (if (= w1 w2)
  3312. (format " (W%02d)" w1)
  3313. (format " (W%02d-W%02d)" w1 w2))
  3314. "")
  3315. ":\n")))
  3316. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3317. 'org-date-line t))
  3318. (org-agenda-mark-header-line s))
  3319. (while (setq d (pop day-numbers))
  3320. (setq date (calendar-gregorian-from-absolute d)
  3321. s (point))
  3322. (if (or (setq todayp (= d today))
  3323. (and (not start-pos) (= d sd)))
  3324. (setq start-pos (point))
  3325. (if (and start-pos (not end-pos))
  3326. (setq end-pos (point))))
  3327. (setq files thefiles
  3328. rtnall nil)
  3329. (while (setq file (pop files))
  3330. (catch 'nextfile
  3331. (org-check-agenda-file file)
  3332. (let ((org-agenda-entry-types org-agenda-entry-types))
  3333. (unless org-agenda-include-deadlines
  3334. (setq org-agenda-entry-types
  3335. (delq :deadline org-agenda-entry-types)))
  3336. (cond
  3337. ((memq org-agenda-show-log '(only clockcheck))
  3338. (setq rtn (org-agenda-get-day-entries
  3339. file date :closed)))
  3340. (org-agenda-show-log
  3341. (setq rtn (apply 'org-agenda-get-day-entries
  3342. file date
  3343. (append '(:closed) org-agenda-entry-types))))
  3344. (t
  3345. (setq rtn (apply 'org-agenda-get-day-entries
  3346. file date
  3347. org-agenda-entry-types)))))
  3348. (setq rtnall (append rtnall rtn)))) ;; all entries
  3349. (if org-agenda-include-diary
  3350. (let ((org-agenda-search-headline-for-time t))
  3351. (require 'diary-lib)
  3352. (setq rtn (org-get-entries-from-diary date))
  3353. (setq rtnall (append rtnall rtn))))
  3354. (if (or rtnall org-agenda-show-all-dates)
  3355. (progn
  3356. (setq day-cnt (1+ day-cnt))
  3357. (insert
  3358. (if (stringp org-agenda-format-date)
  3359. (format-time-string org-agenda-format-date
  3360. (org-time-from-absolute date))
  3361. (funcall org-agenda-format-date date))
  3362. "\n")
  3363. (put-text-property s (1- (point)) 'face
  3364. (org-agenda-get-day-face date))
  3365. (put-text-property s (1- (point)) 'org-date-line t)
  3366. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3367. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3368. (when todayp
  3369. (put-text-property s (1- (point)) 'org-today t))
  3370. (if rtnall (insert ;; all entries
  3371. (org-finalize-agenda-entries
  3372. (org-agenda-add-time-grid-maybe
  3373. rtnall ndays todayp))
  3374. "\n"))
  3375. (put-text-property s (1- (point)) 'day d)
  3376. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3377. (when (and org-agenda-clockreport-mode clocktable-start)
  3378. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3379. ;; the above line is to ensure the restricted range!
  3380. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3381. tbl)
  3382. (setq p (org-plist-delete p :block))
  3383. (setq p (plist-put p :tstart clocktable-start))
  3384. (setq p (plist-put p :tend clocktable-end))
  3385. (setq p (plist-put p :scope 'agenda))
  3386. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3387. (setq filter (or org-agenda-tag-filter-while-redo
  3388. (get 'org-agenda-tag-filter :preset-filter))))
  3389. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3390. (if (string-match "[<>=]" x)
  3391. ""
  3392. x))
  3393. filter ""))))
  3394. (setq tbl (apply 'org-get-clocktable p))
  3395. (insert tbl)))
  3396. (goto-char (point-min))
  3397. (or org-agenda-multi (org-fit-agenda-window))
  3398. (unless (and (pos-visible-in-window-p (point-min))
  3399. (pos-visible-in-window-p (point-max)))
  3400. (goto-char (1- (point-max)))
  3401. (recenter -1)
  3402. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3403. (progn
  3404. (goto-char (or start-pos 1))
  3405. (recenter 1))))
  3406. (goto-char (or start-pos 1))
  3407. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3408. (if (eq org-agenda-show-log 'clockcheck)
  3409. (org-agenda-show-clocking-issues))
  3410. (org-finalize-agenda)
  3411. (setq buffer-read-only t)
  3412. (message "")))
  3413. (defun org-agenda-ndays-to-span (n)
  3414. "Return a span symbol for a span of N days, or N if none matches."
  3415. (cond ((symbolp n) n)
  3416. ((= n 1) 'day)
  3417. ((= n 7) 'week)
  3418. (t n)))
  3419. (defun org-agenda-span-to-ndays (span start-day)
  3420. "Return ndays from SPAN starting at START-DAY."
  3421. (cond ((numberp span) span)
  3422. ((eq span 'day) 1)
  3423. ((eq span 'week) 7)
  3424. ((eq span 'month)
  3425. (let ((date (calendar-gregorian-from-absolute start-day)))
  3426. (calendar-last-day-of-month (car date) (caddr date))))
  3427. ((eq span 'year)
  3428. (let ((date (calendar-gregorian-from-absolute start-day)))
  3429. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3430. (defun org-agenda-span-name (span)
  3431. "Return a SPAN name."
  3432. (if (null span)
  3433. ""
  3434. (if (symbolp span)
  3435. (capitalize (symbol-name span))
  3436. (format "%d days" span))))
  3437. ;;; Agenda word search
  3438. (defvar org-agenda-search-history nil)
  3439. (defvar org-todo-only nil)
  3440. (defvar org-search-syntax-table nil
  3441. "Special syntax table for org-mode search.
  3442. In this table, we have single quotes not as word constituents, to
  3443. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3444. (defun org-search-syntax-table ()
  3445. (unless org-search-syntax-table
  3446. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3447. (modify-syntax-entry ?' "." org-search-syntax-table)
  3448. (modify-syntax-entry ?` "." org-search-syntax-table))
  3449. org-search-syntax-table)
  3450. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3451. ;;;###autoload
  3452. (defun org-search-view (&optional todo-only string edit-at)
  3453. "Show all entries that contain a phrase or words or regular expressions.
  3454. With optional prefix argument TODO-ONLY, only consider entries that are
  3455. TODO entries. The argument STRING can be used to pass a default search
  3456. string into this function. If EDIT-AT is non-nil, it means that the
  3457. user should get a chance to edit this string, with cursor at position
  3458. EDIT-AT.
  3459. The search string can be viewed either as a phrase that should be found as
  3460. is, or it can be broken into a number of snippets, each of which must match
  3461. in a Boolean way to select an entry. The default depends on the variable
  3462. `org-agenda-search-view-always-boolean'.
  3463. Even if this is turned off (the default) you can always switch to
  3464. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3465. The default is a direct search of the whole phrase, where each space in
  3466. the search string can expand to an arbitrary amount of whitespace,
  3467. including newlines.
  3468. If using a Boolean search, the search string is split on whitespace and
  3469. each snippet is searched separately, with logical AND to select an entry.
  3470. Words prefixed with a minus must *not* occur in the entry. Words without
  3471. a prefix or prefixed with a plus must occur in the entry. Matching is
  3472. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3473. match whole words, not parts of a word) if
  3474. `org-agenda-search-view-force-full-words' is set (default is nil).
  3475. Boolean search snippets enclosed by curly braces are interpreted as
  3476. regular expressions that must or (when preceded with \"-\") must not
  3477. match in the entry. Snippets enclosed into double quotes will be taken
  3478. as a whole, to include whitespace.
  3479. - If the search string starts with an asterisk, search only in headlines.
  3480. - If (possibly after the leading star) the search string starts with an
  3481. exclamation mark, this also means to look at TODO entries only, an effect
  3482. that can also be achieved with a prefix argument.
  3483. - If (possibly after star and exclamation mark) the search string starts
  3484. with a colon, this will mean that the (non-regexp) snippets of the
  3485. Boolean search must match as full words.
  3486. This command searches the agenda files, and in addition the files listed
  3487. in `org-agenda-text-search-extra-files'."
  3488. (interactive "P")
  3489. (org-compile-prefix-format 'search)
  3490. (org-set-sorting-strategy 'search)
  3491. (org-prepare-agenda "SEARCH")
  3492. (let* ((props (list 'face nil
  3493. 'done-face 'org-agenda-done
  3494. 'org-not-done-regexp org-not-done-regexp
  3495. 'org-todo-regexp org-todo-regexp
  3496. 'org-complex-heading-regexp org-complex-heading-regexp
  3497. 'mouse-face 'highlight
  3498. 'help-echo (format "mouse-2 or RET jump to location")))
  3499. (full-words org-agenda-search-view-force-full-words)
  3500. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3501. regexp rtn rtnall files file pos
  3502. marker category org-category-pos tags c neg re boolean
  3503. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3504. (unless (and (not edit-at)
  3505. (stringp string)
  3506. (string-match "\\S-" string))
  3507. (setq string (read-string
  3508. (if org-agenda-search-view-always-boolean
  3509. "[+-]Word/{Regexp} ...: "
  3510. "Phrase, or [+-]Word/{Regexp} ...: ")
  3511. (cond
  3512. ((integerp edit-at) (cons string edit-at))
  3513. (edit-at string))
  3514. 'org-agenda-search-history)))
  3515. (org-set-local 'org-todo-only todo-only)
  3516. (setq org-agenda-redo-command
  3517. (list 'org-search-view (if todo-only t nil) string
  3518. '(if current-prefix-arg 1 nil)))
  3519. (setq org-agenda-query-string string)
  3520. (if (equal (string-to-char string) ?*)
  3521. (setq hdl-only t
  3522. words (substring string 1))
  3523. (setq words string))
  3524. (when (equal (string-to-char words) ?!)
  3525. (setq todo-only t
  3526. words (substring words 1)))
  3527. (when (equal (string-to-char words) ?:)
  3528. (setq full-words t
  3529. words (substring words 1)))
  3530. (if (or org-agenda-search-view-always-boolean
  3531. (member (string-to-char words) '(?- ?+ ?\{)))
  3532. (setq boolean t))
  3533. (setq words (org-split-string words))
  3534. (let (www w)
  3535. (while (setq w (pop words))
  3536. (while (and (string-match "\\\\\\'" w) words)
  3537. (setq w (concat (substring w 0 -1) " " (pop words))))
  3538. (push w www))
  3539. (setq words (nreverse www) www nil)
  3540. (while (setq w (pop words))
  3541. (when (and (string-match "\\`[-+]?{" w)
  3542. (not (string-match "}\\'" w)))
  3543. (while (and words (not (string-match "}\\'" (car words))))
  3544. (setq w (concat w " " (pop words))))
  3545. (setq w (concat w " " (pop words))))
  3546. (push w www))
  3547. (setq words (nreverse www)))
  3548. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3549. (when boolean
  3550. (let (wds w)
  3551. (while (setq w (pop words))
  3552. (if (or (equal (substring w 0 1) "\"")
  3553. (and (> (length w) 1)
  3554. (member (substring w 0 1) '("+" "-"))
  3555. (equal (substring w 1 2) "\"")))
  3556. (while (and words (not (equal (substring w -1) "\"")))
  3557. (setq w (concat w " " (pop words)))))
  3558. (and (string-match "\\`\\([-+]?\\)\"" w)
  3559. (setq w (replace-match "\\1" nil nil w)))
  3560. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3561. (push w wds))
  3562. (setq words (nreverse wds))))
  3563. (if boolean
  3564. (mapc (lambda (w)
  3565. (setq c (string-to-char w))
  3566. (if (equal c ?-)
  3567. (setq neg t w (substring w 1))
  3568. (if (equal c ?+)
  3569. (setq neg nil w (substring w 1))
  3570. (setq neg nil)))
  3571. (if (string-match "\\`{.*}\\'" w)
  3572. (setq re (substring w 1 -1))
  3573. (if full-words
  3574. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3575. (setq re (regexp-quote (downcase w)))))
  3576. (if neg (push re regexps-) (push re regexps+)))
  3577. words)
  3578. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3579. regexps+))
  3580. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3581. (if (not regexps+)
  3582. (setq regexp org-outline-regexp-bol)
  3583. (setq regexp (pop regexps+))
  3584. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3585. regexp))))
  3586. (setq files (org-agenda-files nil 'ifmode))
  3587. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3588. (pop org-agenda-text-search-extra-files)
  3589. (setq files (org-add-archive-files files)))
  3590. (setq files (append files org-agenda-text-search-extra-files)
  3591. rtnall nil)
  3592. (while (setq file (pop files))
  3593. (setq ee nil)
  3594. (catch 'nextfile
  3595. (org-check-agenda-file file)
  3596. (setq buffer (if (file-exists-p file)
  3597. (org-get-agenda-file-buffer file)
  3598. (error "No such file %s" file)))
  3599. (if (not buffer)
  3600. ;; If file does not exist, make sure an error message is sent
  3601. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3602. file))))
  3603. (with-current-buffer buffer
  3604. (with-syntax-table (org-search-syntax-table)
  3605. (unless (eq major-mode 'org-mode)
  3606. (error "Agenda file %s is not in `org-mode'" file))
  3607. (let ((case-fold-search t))
  3608. (save-excursion
  3609. (save-restriction
  3610. (if org-agenda-restrict
  3611. (narrow-to-region org-agenda-restrict-begin
  3612. org-agenda-restrict-end)
  3613. (widen))
  3614. (goto-char (point-min))
  3615. (unless (or (org-at-heading-p)
  3616. (outline-next-heading))
  3617. (throw 'nextfile t))
  3618. (goto-char (max (point-min) (1- (point))))
  3619. (while (re-search-forward regexp nil t)
  3620. (org-back-to-heading t)
  3621. (skip-chars-forward "* ")
  3622. (setq beg (point-at-bol)
  3623. beg1 (point)
  3624. end (progn (outline-next-heading) (point)))
  3625. (catch :skip
  3626. (goto-char beg)
  3627. (org-agenda-skip)
  3628. (setq str (buffer-substring-no-properties
  3629. (point-at-bol)
  3630. (if hdl-only (point-at-eol) end)))
  3631. (mapc (lambda (wr) (when (string-match wr str)
  3632. (goto-char (1- end))
  3633. (throw :skip t)))
  3634. regexps-)
  3635. (mapc (lambda (wr) (unless (string-match wr str)
  3636. (goto-char (1- end))
  3637. (throw :skip t)))
  3638. (if todo-only
  3639. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3640. regexps+)
  3641. regexps+))
  3642. (goto-char beg)
  3643. (setq marker (org-agenda-new-marker (point))
  3644. category (org-get-category)
  3645. org-category-pos (get-text-property (point) 'org-category-position)
  3646. tags (org-get-tags-at (point))
  3647. txt (org-agenda-format-item
  3648. ""
  3649. (buffer-substring-no-properties
  3650. beg1 (point-at-eol))
  3651. category tags))
  3652. (org-add-props txt props
  3653. 'org-marker marker 'org-hd-marker marker
  3654. 'org-todo-regexp org-todo-regexp
  3655. 'org-complex-heading-regexp org-complex-heading-regexp
  3656. 'priority 1000 'org-category category
  3657. 'org-category-position org-category-pos
  3658. 'type "search")
  3659. (push txt ee)
  3660. (goto-char (1- end))))))))))
  3661. (setq rtn (nreverse ee))
  3662. (setq rtnall (append rtnall rtn)))
  3663. (if org-agenda-overriding-header
  3664. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3665. nil 'face 'org-agenda-structure) "\n")
  3666. (insert "Search words: ")
  3667. (add-text-properties (point-min) (1- (point))
  3668. (list 'face 'org-agenda-structure))
  3669. (setq pos (point))
  3670. (insert string "\n")
  3671. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3672. (setq pos (point))
  3673. (unless org-agenda-multi
  3674. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3675. (add-text-properties pos (1- (point))
  3676. (list 'face 'org-agenda-structure))))
  3677. (org-agenda-mark-header-line (point-min))
  3678. (when rtnall
  3679. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3680. (goto-char (point-min))
  3681. (or org-agenda-multi (org-fit-agenda-window))
  3682. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3683. (org-finalize-agenda)
  3684. (setq buffer-read-only t)))
  3685. ;;; Agenda TODO list
  3686. (defvar org-select-this-todo-keyword nil)
  3687. (defvar org-last-arg nil)
  3688. ;;;###autoload
  3689. (defun org-todo-list (arg)
  3690. "Show all (not done) TODO entries from all agenda file in a single list.
  3691. The prefix arg can be used to select a specific TODO keyword and limit
  3692. the list to these. When using \\[universal-argument], you will be prompted
  3693. for a keyword. A numeric prefix directly selects the Nth keyword in
  3694. `org-todo-keywords-1'."
  3695. (interactive "P")
  3696. (org-compile-prefix-format 'todo)
  3697. (org-set-sorting-strategy 'todo)
  3698. (org-prepare-agenda "TODO")
  3699. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3700. (let* ((today (org-today))
  3701. (date (calendar-gregorian-from-absolute today))
  3702. (kwds org-todo-keywords-for-agenda)
  3703. (completion-ignore-case t)
  3704. (org-select-this-todo-keyword
  3705. (if (stringp arg) arg
  3706. (and arg (integerp arg) (> arg 0)
  3707. (nth (1- arg) kwds))))
  3708. rtn rtnall files file pos)
  3709. (when (equal arg '(4))
  3710. (setq org-select-this-todo-keyword
  3711. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3712. (mapcar 'list kwds) nil nil)))
  3713. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3714. (org-set-local 'org-last-arg arg)
  3715. (setq org-agenda-redo-command
  3716. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3717. (setq files (org-agenda-files nil 'ifmode)
  3718. rtnall nil)
  3719. (while (setq file (pop files))
  3720. (catch 'nextfile
  3721. (org-check-agenda-file file)
  3722. (setq rtn (org-agenda-get-day-entries file date :todo))
  3723. (setq rtnall (append rtnall rtn))))
  3724. (if org-agenda-overriding-header
  3725. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3726. nil 'face 'org-agenda-structure) "\n")
  3727. (insert "Global list of TODO items of type: ")
  3728. (add-text-properties (point-min) (1- (point))
  3729. (list 'face 'org-agenda-structure
  3730. 'short-heading
  3731. (concat "ToDo: "
  3732. (or org-select-this-todo-keyword "ALL"))))
  3733. (org-agenda-mark-header-line (point-min))
  3734. (setq pos (point))
  3735. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3736. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3737. (setq pos (point))
  3738. (unless org-agenda-multi
  3739. (insert "Available with `N r': (0)ALL")
  3740. (let ((n 0) s)
  3741. (mapc (lambda (x)
  3742. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3743. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3744. (insert "\n "))
  3745. (insert " " s))
  3746. kwds))
  3747. (insert "\n"))
  3748. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3749. (org-agenda-mark-header-line (point-min))
  3750. (when rtnall
  3751. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3752. (goto-char (point-min))
  3753. (or org-agenda-multi (org-fit-agenda-window))
  3754. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3755. (org-finalize-agenda)
  3756. (setq buffer-read-only t)))
  3757. ;;; Agenda tags match
  3758. ;;;###autoload
  3759. (defun org-tags-view (&optional todo-only match)
  3760. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3761. The prefix arg TODO-ONLY limits the search to TODO entries."
  3762. (interactive "P")
  3763. (org-compile-prefix-format 'tags)
  3764. (org-set-sorting-strategy 'tags)
  3765. (let* ((org-tags-match-list-sublevels
  3766. org-tags-match-list-sublevels)
  3767. (completion-ignore-case t)
  3768. rtn rtnall files file pos matcher
  3769. buffer)
  3770. (when (and (stringp match) (not (string-match "\\S-" match)))
  3771. (setq match nil))
  3772. (setq matcher (org-make-tags-matcher match)
  3773. match (car matcher) matcher (cdr matcher))
  3774. (org-prepare-agenda (concat "TAGS " match))
  3775. (setq org-agenda-query-string match)
  3776. (setq org-agenda-redo-command
  3777. (list 'org-tags-view (list 'quote todo-only)
  3778. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3779. (setq files (org-agenda-files nil 'ifmode)
  3780. rtnall nil)
  3781. (while (setq file (pop files))
  3782. (catch 'nextfile
  3783. (org-check-agenda-file file)
  3784. (setq buffer (if (file-exists-p file)
  3785. (org-get-agenda-file-buffer file)
  3786. (error "No such file %s" file)))
  3787. (if (not buffer)
  3788. ;; If file does not exist, error message to agenda
  3789. (setq rtn (list
  3790. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3791. rtnall (append rtnall rtn))
  3792. (with-current-buffer buffer
  3793. (unless (eq major-mode 'org-mode)
  3794. (error "Agenda file %s is not in `org-mode'" file))
  3795. (save-excursion
  3796. (save-restriction
  3797. (if org-agenda-restrict
  3798. (narrow-to-region org-agenda-restrict-begin
  3799. org-agenda-restrict-end)
  3800. (widen))
  3801. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3802. (setq rtnall (append rtnall rtn))))))))
  3803. (if org-agenda-overriding-header
  3804. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3805. nil 'face 'org-agenda-structure) "\n")
  3806. (insert "Headlines with TAGS match: ")
  3807. (add-text-properties (point-min) (1- (point))
  3808. (list 'face 'org-agenda-structure
  3809. 'short-heading
  3810. (concat "Match: " match)))
  3811. (setq pos (point))
  3812. (insert match "\n")
  3813. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3814. (setq pos (point))
  3815. (unless org-agenda-multi
  3816. (insert "Press `C-u r' to search again with new search string\n"))
  3817. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3818. (org-agenda-mark-header-line (point-min))
  3819. (when rtnall
  3820. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3821. (goto-char (point-min))
  3822. (or org-agenda-multi (org-fit-agenda-window))
  3823. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3824. (org-finalize-agenda)
  3825. (setq buffer-read-only t)))
  3826. ;;; Agenda Finding stuck projects
  3827. (defvar org-agenda-skip-regexp nil
  3828. "Regular expression used in skipping subtrees for the agenda.
  3829. This is basically a temporary global variable that can be set and then
  3830. used by user-defined selections using `org-agenda-skip-function'.")
  3831. (defvar org-agenda-overriding-header nil
  3832. "When set during agenda, todo and tags searches it replaces the header.
  3833. This variable should not be set directly, but custom commands can bind it
  3834. in the options section.")
  3835. (defun org-agenda-skip-entry-when-regexp-matches ()
  3836. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3837. If yes, it returns the end position of this entry, causing agenda commands
  3838. to skip the entry but continuing the search in the subtree. This is a
  3839. function that can be put into `org-agenda-skip-function' for the duration
  3840. of a command."
  3841. (let ((end (save-excursion (org-end-of-subtree t)))
  3842. skip)
  3843. (save-excursion
  3844. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3845. (and skip end)))
  3846. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3847. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3848. If yes, it returns the end position of this tree, causing agenda commands
  3849. to skip this subtree. This is a function that can be put into
  3850. `org-agenda-skip-function' for the duration of a command."
  3851. (let ((end (save-excursion (org-end-of-subtree t)))
  3852. skip)
  3853. (save-excursion
  3854. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3855. (and skip end)))
  3856. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3857. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3858. If yes, it returns the end position of the current entry (NOT the tree),
  3859. causing agenda commands to skip the entry but continuing the search in
  3860. the subtree. This is a function that can be put into
  3861. `org-agenda-skip-function' for the duration of a command. An important
  3862. use of this function is for the stuck project list."
  3863. (let ((end (save-excursion (org-end-of-subtree t)))
  3864. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3865. skip)
  3866. (save-excursion
  3867. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3868. (and skip entry-end)))
  3869. (defun org-agenda-skip-entry-if (&rest conditions)
  3870. "Skip entry if any of CONDITIONS is true.
  3871. See `org-agenda-skip-if' for details."
  3872. (org-agenda-skip-if nil conditions))
  3873. (defun org-agenda-skip-subtree-if (&rest conditions)
  3874. "Skip entry if any of CONDITIONS is true.
  3875. See `org-agenda-skip-if' for details."
  3876. (org-agenda-skip-if t conditions))
  3877. (defun org-agenda-skip-if (subtree conditions)
  3878. "Checks current entity for CONDITIONS.
  3879. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3880. the entry, i.e. the text before the next heading is checked.
  3881. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3882. from different tests. Valid conditions are:
  3883. scheduled Check if there is a scheduled cookie
  3884. notscheduled Check if there is no scheduled cookie
  3885. deadline Check if there is a deadline
  3886. notdeadline Check if there is no deadline
  3887. timestamp Check if there is a timestamp (also deadline or scheduled)
  3888. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3889. regexp Check if regexp matches
  3890. notregexp Check if regexp does not match.
  3891. todo Check if TODO keyword matches
  3892. nottodo Check if TODO keyword does not match
  3893. The regexp is taken from the conditions list, it must come right after
  3894. the `regexp' or `notregexp' element.
  3895. `todo' and `nottodo' accept as an argument a list of todo
  3896. keywords, which may include \"*\" to match any todo keyword.
  3897. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3898. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3899. Instead of a list a keyword class may be given
  3900. (org-agenda-skip-entry-if 'nottodo 'done)
  3901. would skip entries that haven't been marked with any of \"DONE\"
  3902. keywords. Possible classes are: `todo', `done', `any'.
  3903. If any of these conditions is met, this function returns the end point of
  3904. the entity, causing the search to continue from there. This is a function
  3905. that can be put into `org-agenda-skip-function' for the duration of a command."
  3906. (let (beg end m)
  3907. (org-back-to-heading t)
  3908. (setq beg (point)
  3909. end (if subtree
  3910. (progn (org-end-of-subtree t) (point))
  3911. (progn (outline-next-heading) (1- (point)))))
  3912. (goto-char beg)
  3913. (and
  3914. (or
  3915. (and (memq 'scheduled conditions)
  3916. (re-search-forward org-scheduled-time-regexp end t))
  3917. (and (memq 'notscheduled conditions)
  3918. (not (re-search-forward org-scheduled-time-regexp end t)))
  3919. (and (memq 'deadline conditions)
  3920. (re-search-forward org-deadline-time-regexp end t))
  3921. (and (memq 'notdeadline conditions)
  3922. (not (re-search-forward org-deadline-time-regexp end t)))
  3923. (and (memq 'timestamp conditions)
  3924. (re-search-forward org-ts-regexp end t))
  3925. (and (memq 'nottimestamp conditions)
  3926. (not (re-search-forward org-ts-regexp end t)))
  3927. (and (setq m (memq 'regexp conditions))
  3928. (stringp (nth 1 m))
  3929. (re-search-forward (nth 1 m) end t))
  3930. (and (setq m (memq 'notregexp conditions))
  3931. (stringp (nth 1 m))
  3932. (not (re-search-forward (nth 1 m) end t)))
  3933. (and (or
  3934. (setq m (memq 'todo conditions))
  3935. (setq m (memq 'nottodo conditions)))
  3936. (org-agenda-skip-if-todo m end)))
  3937. end)))
  3938. (defun org-agenda-skip-if-todo (args end)
  3939. "Helper function for `org-agenda-skip-if', do not use it directly.
  3940. ARGS is a list with first element either `todo' or `nottodo'.
  3941. The remainder is either a list of TODO keywords, or a state symbol
  3942. `todo' or `done' or `any'."
  3943. (let ((kw (car args))
  3944. (arg (cadr args))
  3945. todo-wds todo-re)
  3946. (setq todo-wds
  3947. (org-uniquify
  3948. (cond
  3949. ((listp arg) ;; list of keywords
  3950. (if (member "*" arg)
  3951. (mapcar 'substring-no-properties org-todo-keywords-1)
  3952. arg))
  3953. ((symbolp arg) ;; keyword class name
  3954. (cond
  3955. ((eq arg 'todo)
  3956. (org-delete-all org-done-keywords
  3957. (mapcar 'substring-no-properties
  3958. org-todo-keywords-1)))
  3959. ((eq arg 'done) org-done-keywords)
  3960. ((eq arg 'any)
  3961. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3962. (setq todo-re
  3963. (concat "^\\*+[ \t]+\\<\\("
  3964. (mapconcat 'identity todo-wds "\\|")
  3965. "\\)\\>"))
  3966. (if (eq kw 'todo)
  3967. (re-search-forward todo-re end t)
  3968. (not (re-search-forward todo-re end t)))))
  3969. ;;;###autoload
  3970. (defun org-agenda-list-stuck-projects (&rest ignore)
  3971. "Create agenda view for projects that are stuck.
  3972. Stuck projects are project that have no next actions. For the definitions
  3973. of what a project is and how to check if it stuck, customize the variable
  3974. `org-stuck-projects'."
  3975. (interactive)
  3976. (let* ((org-agenda-skip-function
  3977. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3978. ;; We could have used org-agenda-skip-if here.
  3979. (org-agenda-overriding-header
  3980. (or org-agenda-overriding-header "List of stuck projects: "))
  3981. (matcher (nth 0 org-stuck-projects))
  3982. (todo (nth 1 org-stuck-projects))
  3983. (todo-wds (if (member "*" todo)
  3984. (progn
  3985. (org-prepare-agenda-buffers (org-agenda-files
  3986. nil 'ifmode))
  3987. (org-delete-all
  3988. org-done-keywords-for-agenda
  3989. (copy-sequence org-todo-keywords-for-agenda)))
  3990. todo))
  3991. (todo-re (concat "^\\*+[ \t]+\\("
  3992. (mapconcat 'identity todo-wds "\\|")
  3993. "\\)\\>"))
  3994. (tags (nth 2 org-stuck-projects))
  3995. (tags-re (if (member "*" tags)
  3996. (concat org-outline-regexp-bol
  3997. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3998. (if tags
  3999. (concat org-outline-regexp-bol
  4000. ".*:\\("
  4001. (mapconcat 'identity tags "\\|")
  4002. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4003. (gen-re (nth 3 org-stuck-projects))
  4004. (re-list
  4005. (delq nil
  4006. (list
  4007. (if todo todo-re)
  4008. (if tags tags-re)
  4009. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4010. gen-re)))))
  4011. (setq org-agenda-skip-regexp
  4012. (if re-list
  4013. (mapconcat 'identity re-list "\\|")
  4014. (error "No information how to identify unstuck projects")))
  4015. (org-tags-view nil matcher)
  4016. (with-current-buffer org-agenda-buffer-name
  4017. (setq org-agenda-redo-command
  4018. '(org-agenda-list-stuck-projects
  4019. (or current-prefix-arg org-last-arg))))))
  4020. ;;; Diary integration
  4021. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4022. (defvar diary-list-entries-hook)
  4023. (defvar diary-time-regexp)
  4024. (defun org-get-entries-from-diary (date)
  4025. "Get the (Emacs Calendar) diary entries for DATE."
  4026. (require 'diary-lib)
  4027. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4028. (diary-display-hook '(fancy-diary-display))
  4029. (diary-display-function 'fancy-diary-display)
  4030. (pop-up-frames nil)
  4031. (diary-list-entries-hook
  4032. (cons 'org-diary-default-entry diary-list-entries-hook))
  4033. (diary-file-name-prefix-function nil) ; turn this feature off
  4034. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4035. entries
  4036. (org-disable-agenda-to-diary t))
  4037. (save-excursion
  4038. (save-window-excursion
  4039. (funcall (if (fboundp 'diary-list-entries)
  4040. 'diary-list-entries 'list-diary-entries)
  4041. date 1)))
  4042. (if (not (get-buffer diary-fancy-buffer))
  4043. (setq entries nil)
  4044. (with-current-buffer diary-fancy-buffer
  4045. (setq buffer-read-only nil)
  4046. (if (zerop (buffer-size))
  4047. ;; No entries
  4048. (setq entries nil)
  4049. ;; Omit the date and other unnecessary stuff
  4050. (org-agenda-cleanup-fancy-diary)
  4051. ;; Add prefix to each line and extend the text properties
  4052. (if (zerop (buffer-size))
  4053. (setq entries nil)
  4054. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4055. (setq entries
  4056. (with-temp-buffer
  4057. (insert entries) (goto-char (point-min))
  4058. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4059. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4060. (replace-match (concat "; " (match-string 1)))))
  4061. (buffer-string)))))
  4062. (set-buffer-modified-p nil)
  4063. (kill-buffer diary-fancy-buffer)))
  4064. (when entries
  4065. (setq entries (org-split-string entries "\n"))
  4066. (setq entries
  4067. (mapcar
  4068. (lambda (x)
  4069. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4070. ;; Extend the text properties to the beginning of the line
  4071. (org-add-props x (text-properties-at (1- (length x)) x)
  4072. 'type "diary" 'date date 'face 'org-agenda-diary))
  4073. entries)))))
  4074. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4075. "Hook run when the fancy diary buffer is cleaned up.")
  4076. (defun org-agenda-cleanup-fancy-diary ()
  4077. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4078. This gets rid of the date, the underline under the date, and
  4079. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4080. date. It also removes lines that contain only whitespace."
  4081. (goto-char (point-min))
  4082. (if (looking-at ".*?:[ \t]*")
  4083. (progn
  4084. (replace-match "")
  4085. (re-search-forward "\n=+$" nil t)
  4086. (replace-match "")
  4087. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4088. (re-search-forward "\n=+$" nil t)
  4089. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4090. (goto-char (point-min))
  4091. (while (re-search-forward "^ +\n" nil t)
  4092. (replace-match ""))
  4093. (goto-char (point-min))
  4094. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4095. (replace-match ""))
  4096. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4097. ;; Make sure entries from the diary have the right text properties.
  4098. (eval-after-load "diary-lib"
  4099. '(if (boundp 'diary-modify-entry-list-string-function)
  4100. ;; We can rely on the hook, nothing to do
  4101. nil
  4102. ;; Hook not available, must use advice to make this work
  4103. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4104. "Make the position visible."
  4105. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4106. (stringp string)
  4107. buffer-file-name)
  4108. (setq string (org-modify-diary-entry-string string))))))
  4109. (defun org-modify-diary-entry-string (string)
  4110. "Add text properties to string, allowing org-mode to act on it."
  4111. (org-add-props string nil
  4112. 'mouse-face 'highlight
  4113. 'help-echo (if buffer-file-name
  4114. (format "mouse-2 or RET jump to diary file %s"
  4115. (abbreviate-file-name buffer-file-name))
  4116. "")
  4117. 'org-agenda-diary-link t
  4118. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4119. (defun org-diary-default-entry ()
  4120. "Add a dummy entry to the diary.
  4121. Needed to avoid empty dates which mess up holiday display."
  4122. ;; Catch the error if dealing with the new add-to-diary-alist
  4123. (when org-disable-agenda-to-diary
  4124. (condition-case nil
  4125. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4126. (error
  4127. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4128. (defun org-add-to-diary-list (&rest args)
  4129. (if (fboundp 'diary-add-to-list)
  4130. (apply 'diary-add-to-list args)
  4131. (apply 'add-to-diary-list args)))
  4132. (defvar org-diary-last-run-time nil)
  4133. ;;;###autoload
  4134. (defun org-diary (&rest args)
  4135. "Return diary information from org-files.
  4136. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4137. It accesses org files and extracts information from those files to be
  4138. listed in the diary. The function accepts arguments specifying what
  4139. items should be listed. For a list of arguments allowed here, see the
  4140. variable `org-agenda-entry-types'.
  4141. The call in the diary file should look like this:
  4142. &%%(org-diary) ~/path/to/some/orgfile.org
  4143. Use a separate line for each org file to check. Or, if you omit the file name,
  4144. all files listed in `org-agenda-files' will be checked automatically:
  4145. &%%(org-diary)
  4146. If you don't give any arguments (as in the example above), the default
  4147. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4148. So the example above may also be written as
  4149. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4150. The function expects the lisp variables `entry' and `date' to be provided
  4151. by the caller, because this is how the calendar works. Don't use this
  4152. function from a program - use `org-agenda-get-day-entries' instead."
  4153. (when (> (- (org-float-time)
  4154. org-agenda-last-marker-time)
  4155. 5)
  4156. (org-agenda-reset-markers))
  4157. (org-compile-prefix-format 'agenda)
  4158. (org-set-sorting-strategy 'agenda)
  4159. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4160. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4161. (list entry)
  4162. (org-agenda-files t)))
  4163. (time (org-float-time))
  4164. file rtn results)
  4165. (when (or (not org-diary-last-run-time)
  4166. (> (- time
  4167. org-diary-last-run-time)
  4168. 3))
  4169. (org-prepare-agenda-buffers files))
  4170. (setq org-diary-last-run-time time)
  4171. ;; If this is called during org-agenda, don't return any entries to
  4172. ;; the calendar. Org Agenda will list these entries itself.
  4173. (if org-disable-agenda-to-diary (setq files nil))
  4174. (while (setq file (pop files))
  4175. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4176. (setq results (append results rtn)))
  4177. (if results
  4178. (concat (org-finalize-agenda-entries results) "\n"))))
  4179. ;;; Agenda entry finders
  4180. (defun org-agenda-get-day-entries (file date &rest args)
  4181. "Does the work for `org-diary' and `org-agenda'.
  4182. FILE is the path to a file to be checked for entries. DATE is date like
  4183. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4184. which kind of entries should be extracted. For details about these, see
  4185. the documentation of `org-diary'."
  4186. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4187. (let* ((org-startup-folded nil)
  4188. (org-startup-align-all-tables nil)
  4189. (buffer (if (file-exists-p file)
  4190. (org-get-agenda-file-buffer file)
  4191. (error "No such file %s" file)))
  4192. arg results rtn deadline-results)
  4193. (if (not buffer)
  4194. ;; If file does not exist, make sure an error message ends up in diary
  4195. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4196. (with-current-buffer buffer
  4197. (unless (eq major-mode 'org-mode)
  4198. (error "Agenda file %s is not in `org-mode'" file))
  4199. (let ((case-fold-search nil))
  4200. (save-excursion
  4201. (save-restriction
  4202. (if org-agenda-restrict
  4203. (narrow-to-region org-agenda-restrict-begin
  4204. org-agenda-restrict-end)
  4205. (widen))
  4206. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4207. (while (setq arg (pop args))
  4208. (cond
  4209. ((and (eq arg :todo)
  4210. (equal date (calendar-gregorian-from-absolute
  4211. (org-today))))
  4212. (setq rtn (org-agenda-get-todos))
  4213. (setq results (append results rtn)))
  4214. ((eq arg :timestamp)
  4215. (setq rtn (org-agenda-get-blocks))
  4216. (setq results (append results rtn))
  4217. (setq rtn (org-agenda-get-timestamps))
  4218. (setq results (append results rtn)))
  4219. ((eq arg :sexp)
  4220. (setq rtn (org-agenda-get-sexps))
  4221. (setq results (append results rtn)))
  4222. ((eq arg :scheduled)
  4223. (setq rtn (org-agenda-get-scheduled deadline-results))
  4224. (setq results (append results rtn)))
  4225. ((eq arg :closed)
  4226. (setq rtn (org-agenda-get-progress))
  4227. (setq results (append results rtn)))
  4228. ((eq arg :deadline)
  4229. (setq rtn (org-agenda-get-deadlines))
  4230. (setq deadline-results (copy-sequence rtn))
  4231. (setq results (append results rtn))))))))
  4232. results))))
  4233. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4234. (defun org-agenda-get-todos ()
  4235. "Return the TODO information for agenda display."
  4236. (let* ((props (list 'face nil
  4237. 'done-face 'org-agenda-done
  4238. 'org-not-done-regexp org-not-done-regexp
  4239. 'org-todo-regexp org-todo-regexp
  4240. 'org-complex-heading-regexp org-complex-heading-regexp
  4241. 'mouse-face 'highlight
  4242. 'help-echo
  4243. (format "mouse-2 or RET jump to org file %s"
  4244. (abbreviate-file-name buffer-file-name))))
  4245. (regexp (format org-heading-keyword-regexp-format
  4246. (cond
  4247. ((and org-select-this-todo-keyword
  4248. (equal org-select-this-todo-keyword "*"))
  4249. org-todo-regexp)
  4250. (org-select-this-todo-keyword
  4251. (concat "\\("
  4252. (mapconcat 'identity
  4253. (org-split-string
  4254. org-select-this-todo-keyword
  4255. "|")
  4256. "\\|") "\\)"))
  4257. (t org-not-done-regexp))))
  4258. marker priority category org-category-pos tags todo-state
  4259. ee txt beg end)
  4260. (goto-char (point-min))
  4261. (while (re-search-forward regexp nil t)
  4262. (catch :skip
  4263. (save-match-data
  4264. (beginning-of-line)
  4265. (org-agenda-skip)
  4266. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4267. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4268. (goto-char (1+ beg))
  4269. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4270. (throw :skip nil)))
  4271. (goto-char (match-beginning 2))
  4272. (setq marker (org-agenda-new-marker (match-beginning 0))
  4273. category (org-get-category)
  4274. org-category-pos (get-text-property (point) 'org-category-position)
  4275. txt (org-trim
  4276. (buffer-substring (match-beginning 2) (match-end 0)))
  4277. tags (org-get-tags-at (point))
  4278. txt (org-agenda-format-item "" txt category tags)
  4279. priority (1+ (org-get-priority txt))
  4280. todo-state (org-get-todo-state))
  4281. (org-add-props txt props
  4282. 'org-marker marker 'org-hd-marker marker
  4283. 'priority priority 'org-category category
  4284. 'org-category-position org-category-pos
  4285. 'type "todo" 'todo-state todo-state)
  4286. (push txt ee)
  4287. (if org-agenda-todo-list-sublevels
  4288. (goto-char (match-end 2))
  4289. (org-end-of-subtree 'invisible))))
  4290. (nreverse ee)))
  4291. (defun org-agenda-todo-custom-ignore-p (time n)
  4292. "Check whether timestamp is farther away then n number of days.
  4293. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4294. `org-agenda-todo-ignore-scheduled' or
  4295. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4296. (let ((days (org-days-to-time time)))
  4297. (if (>= n 0)
  4298. (>= days n)
  4299. (<= days n))))
  4300. ;;;###autoload
  4301. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4302. (&optional end)
  4303. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4304. (when (or org-agenda-todo-ignore-with-date
  4305. org-agenda-todo-ignore-scheduled
  4306. org-agenda-todo-ignore-deadlines
  4307. org-agenda-todo-ignore-timestamp)
  4308. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4309. (save-excursion
  4310. (or (and org-agenda-todo-ignore-with-date
  4311. (re-search-forward org-ts-regexp end t))
  4312. (and org-agenda-todo-ignore-scheduled
  4313. (re-search-forward org-scheduled-time-regexp end t)
  4314. (cond
  4315. ((eq org-agenda-todo-ignore-scheduled 'future)
  4316. (> (org-days-to-time (match-string 1)) 0))
  4317. ((eq org-agenda-todo-ignore-scheduled 'past)
  4318. (<= (org-days-to-time (match-string 1)) 0))
  4319. ((numberp org-agenda-todo-ignore-scheduled)
  4320. (org-agenda-todo-custom-ignore-p
  4321. (match-string 1) org-agenda-todo-ignore-scheduled))
  4322. (t)))
  4323. (and org-agenda-todo-ignore-deadlines
  4324. (re-search-forward org-deadline-time-regexp end t)
  4325. (cond
  4326. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4327. ((eq org-agenda-todo-ignore-deadlines 'far)
  4328. (not (org-deadline-close (match-string 1))))
  4329. ((eq org-agenda-todo-ignore-deadlines 'future)
  4330. (> (org-days-to-time (match-string 1)) 0))
  4331. ((eq org-agenda-todo-ignore-deadlines 'past)
  4332. (<= (org-days-to-time (match-string 1)) 0))
  4333. ((numberp org-agenda-todo-ignore-deadlines)
  4334. (org-agenda-todo-custom-ignore-p
  4335. (match-string 1) org-agenda-todo-ignore-deadlines))
  4336. (t (org-deadline-close (match-string 1)))))
  4337. (and org-agenda-todo-ignore-timestamp
  4338. (let ((buffer (current-buffer))
  4339. (regexp
  4340. (concat
  4341. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4342. (start (point)))
  4343. ;; Copy current buffer into a temporary one
  4344. (with-temp-buffer
  4345. (insert-buffer-substring buffer start end)
  4346. (goto-char (point-min))
  4347. ;; Delete SCHEDULED and DEADLINE items
  4348. (while (re-search-forward regexp end t)
  4349. (delete-region (match-beginning 0) (match-end 0)))
  4350. (goto-char (point-min))
  4351. ;; No search for timestamp left
  4352. (when (re-search-forward org-ts-regexp nil t)
  4353. (cond
  4354. ((eq org-agenda-todo-ignore-timestamp 'future)
  4355. (> (org-days-to-time (match-string 1)) 0))
  4356. ((eq org-agenda-todo-ignore-timestamp 'past)
  4357. (<= (org-days-to-time (match-string 1)) 0))
  4358. ((numberp org-agenda-todo-ignore-timestamp)
  4359. (org-agenda-todo-custom-ignore-p
  4360. (match-string 1) org-agenda-todo-ignore-timestamp))
  4361. (t))))))))))
  4362. (defconst org-agenda-no-heading-message
  4363. "No heading for this item in buffer or region.")
  4364. (defun org-agenda-get-timestamps ()
  4365. "Return the date stamp information for agenda display."
  4366. (let* ((props (list 'face 'org-agenda-calendar-event
  4367. 'org-not-done-regexp org-not-done-regexp
  4368. 'org-todo-regexp org-todo-regexp
  4369. 'org-complex-heading-regexp org-complex-heading-regexp
  4370. 'mouse-face 'highlight
  4371. 'help-echo
  4372. (format "mouse-2 or RET jump to org file %s"
  4373. (abbreviate-file-name buffer-file-name))))
  4374. (d1 (calendar-absolute-from-gregorian date))
  4375. (remove-re
  4376. (concat
  4377. (regexp-quote
  4378. (format-time-string
  4379. "<%Y-%m-%d"
  4380. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4381. ".*?>"))
  4382. (regexp
  4383. (concat
  4384. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4385. (regexp-quote
  4386. (substring
  4387. (format-time-string
  4388. (car org-time-stamp-formats)
  4389. (apply 'encode-time ; DATE bound by calendar
  4390. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4391. 1 11))
  4392. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4393. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4394. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4395. donep tmp priority category org-category-pos ee txt timestr tags
  4396. b0 b3 e3 head todo-state end-of-match show-all)
  4397. (goto-char (point-min))
  4398. (while (setq end-of-match (re-search-forward regexp nil t))
  4399. (setq b0 (match-beginning 0)
  4400. b3 (match-beginning 3) e3 (match-end 3)
  4401. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4402. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4403. (member todo-state
  4404. org-agenda-repeating-timestamp-show-all)))
  4405. (catch :skip
  4406. (and (org-at-date-range-p) (throw :skip nil))
  4407. (org-agenda-skip)
  4408. (if (and (match-end 1)
  4409. (not (= d1 (org-time-string-to-absolute
  4410. (match-string 1) d1 nil show-all
  4411. (current-buffer) b0))))
  4412. (throw :skip nil))
  4413. (if (and e3
  4414. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4415. (throw :skip nil))
  4416. (setq tmp (buffer-substring (max (point-min)
  4417. (- b0 org-ds-keyword-length))
  4418. b0)
  4419. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4420. inactivep (= (char-after b0) ?\[)
  4421. deadlinep (string-match org-deadline-regexp tmp)
  4422. scheduledp (string-match org-scheduled-regexp tmp)
  4423. closedp (and org-agenda-include-inactive-timestamps
  4424. (string-match org-closed-string tmp))
  4425. clockp (and org-agenda-include-inactive-timestamps
  4426. (or (string-match org-clock-string tmp)
  4427. (string-match "]-+\\'" tmp)))
  4428. donep (member todo-state org-done-keywords))
  4429. (if (or scheduledp deadlinep closedp clockp
  4430. (and donep org-agenda-skip-timestamp-if-done))
  4431. (throw :skip t))
  4432. (if (string-match ">" timestr)
  4433. ;; substring should only run to end of time stamp
  4434. (setq timestr (substring timestr 0 (match-end 0))))
  4435. (setq marker (org-agenda-new-marker b0)
  4436. category (org-get-category b0)
  4437. org-category-pos (get-text-property b0 'org-category-position))
  4438. (save-excursion
  4439. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4440. (setq txt org-agenda-no-heading-message)
  4441. (goto-char (match-beginning 0))
  4442. (setq hdmarker (org-agenda-new-marker)
  4443. tags (org-get-tags-at))
  4444. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4445. (setq head (or (match-string 1) ""))
  4446. (setq txt (org-agenda-format-item
  4447. (if inactivep org-agenda-inactive-leader nil)
  4448. head category tags timestr
  4449. remove-re)))
  4450. (setq priority (org-get-priority txt))
  4451. (org-add-props txt props
  4452. 'org-marker marker 'org-hd-marker hdmarker)
  4453. (org-add-props txt nil 'priority priority
  4454. 'org-category category 'date date
  4455. 'org-category-position org-category-pos
  4456. 'todo-state todo-state
  4457. 'type "timestamp")
  4458. (push txt ee))
  4459. (if org-agenda-skip-additional-timestamps-same-entry
  4460. (outline-next-heading)
  4461. (goto-char end-of-match))))
  4462. (nreverse ee)))
  4463. (defun org-agenda-get-sexps ()
  4464. "Return the sexp information for agenda display."
  4465. (require 'diary-lib)
  4466. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4467. 'mouse-face 'highlight
  4468. 'help-echo
  4469. (format "mouse-2 or RET jump to org file %s"
  4470. (abbreviate-file-name buffer-file-name))))
  4471. (regexp "^&?%%(")
  4472. marker category org-category-pos ee txt tags entry
  4473. result beg b sexp sexp-entry todo-state)
  4474. (goto-char (point-min))
  4475. (while (re-search-forward regexp nil t)
  4476. (catch :skip
  4477. (org-agenda-skip)
  4478. (setq beg (match-beginning 0))
  4479. (goto-char (1- (match-end 0)))
  4480. (setq b (point))
  4481. (forward-sexp 1)
  4482. (setq sexp (buffer-substring b (point)))
  4483. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4484. (org-trim (match-string 1))
  4485. ""))
  4486. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4487. (when result
  4488. (setq marker (org-agenda-new-marker beg)
  4489. category (org-get-category beg)
  4490. org-category-pos (get-text-property beg 'org-category-position)
  4491. todo-state (org-get-todo-state))
  4492. (dolist (r (if (stringp result)
  4493. (list result)
  4494. result)) ;; we expect a list here
  4495. (if (string-match "\\S-" r)
  4496. (setq txt r)
  4497. (setq txt "SEXP entry returned empty string"))
  4498. (setq txt (org-agenda-format-item
  4499. "" txt category tags 'time))
  4500. (org-add-props txt props 'org-marker marker)
  4501. (org-add-props txt nil
  4502. 'org-category category 'date date 'todo-state todo-state
  4503. 'org-category-position org-category-pos
  4504. 'type "sexp")
  4505. (push txt ee)))))
  4506. (nreverse ee)))
  4507. ;; Calendar sanity: define some functions that are independent of
  4508. ;; `calendar-date-style'.
  4509. ;; Normally I would like to use ISO format when calling the diary functions,
  4510. ;; but to make sure we still have Emacs 22 compatibility we bind
  4511. ;; also `european-calendar-style' and use european format
  4512. (defun org-anniversary (year month day &optional mark)
  4513. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4514. (org-no-warnings
  4515. (let ((calendar-date-style 'european) (european-calendar-style t))
  4516. (diary-anniversary day month year mark))))
  4517. (defun org-cyclic (N year month day &optional mark)
  4518. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4519. (org-no-warnings
  4520. (let ((calendar-date-style 'european) (european-calendar-style t))
  4521. (diary-cyclic N day month year mark))))
  4522. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4523. "Like `diary-block', but with fixed (ISO) order of arguments."
  4524. (org-no-warnings
  4525. (let ((calendar-date-style 'european) (european-calendar-style t))
  4526. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4527. (defun org-date (year month day &optional mark)
  4528. "Like `diary-date', but with fixed (ISO) order of arguments."
  4529. (org-no-warnings
  4530. (let ((calendar-date-style 'european) (european-calendar-style t))
  4531. (diary-date day month year mark))))
  4532. (defalias 'org-float 'diary-float)
  4533. ;; Define the` org-class' function
  4534. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4535. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4536. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4537. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4538. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4539. `holidays', then any date that is known by the Emacs calendar to be a
  4540. holiday will also be skipped."
  4541. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4542. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4543. (d (calendar-absolute-from-gregorian date)))
  4544. (and
  4545. (<= date1 d)
  4546. (<= d date2)
  4547. (= (calendar-day-of-week date) dayname)
  4548. (or (not skip-weeks)
  4549. (progn
  4550. (require 'cal-iso)
  4551. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4552. (not (and (memq 'holidays skip-weeks)
  4553. (calendar-check-holidays date)))
  4554. entry)))
  4555. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4556. "Like `org-class', but honor `calendar-date-style'.
  4557. The order of the first 2 times 3 arguments depends on the variable
  4558. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4559. So for American calendars, give this as MONTH DAY YEAR, for European as
  4560. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4561. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4562. is any number of ISO weeks in the block period for which the item should
  4563. be skipped.
  4564. This function is here only for backward compatibility and it is deprecated,
  4565. please use `org-class' instead."
  4566. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4567. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4568. (org-class
  4569. (nth 2 date1) (car date1) (nth 1 date1)
  4570. (nth 2 date2) (car date2) (nth 1 date2)
  4571. dayname skip-weeks)))
  4572. (make-obsolete 'org-diary-class 'org-class "")
  4573. (defalias 'org-get-closed 'org-agenda-get-progress)
  4574. (defun org-agenda-get-progress ()
  4575. "Return the logged TODO entries for agenda display."
  4576. (let* ((props (list 'mouse-face 'highlight
  4577. 'org-not-done-regexp org-not-done-regexp
  4578. 'org-todo-regexp org-todo-regexp
  4579. 'org-complex-heading-regexp org-complex-heading-regexp
  4580. 'help-echo
  4581. (format "mouse-2 or RET jump to org file %s"
  4582. (abbreviate-file-name buffer-file-name))))
  4583. (items (if (consp org-agenda-show-log)
  4584. org-agenda-show-log
  4585. (if (eq org-agenda-show-log 'clockcheck)
  4586. '(clock)
  4587. org-agenda-log-mode-items)))
  4588. (parts
  4589. (delq nil
  4590. (list
  4591. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4592. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4593. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4594. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4595. (error "`org-agenda-log-mode-items' is empty")))
  4596. (regexp (concat
  4597. "\\(" parts-re "\\)"
  4598. " *\\["
  4599. (regexp-quote
  4600. (substring
  4601. (format-time-string
  4602. (car org-time-stamp-formats)
  4603. (apply 'encode-time ; DATE bound by calendar
  4604. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4605. 1 11))))
  4606. (org-agenda-search-headline-for-time nil)
  4607. marker hdmarker priority category org-category-pos tags closedp
  4608. statep clockp state ee txt extra timestr rest clocked)
  4609. (goto-char (point-min))
  4610. (while (re-search-forward regexp nil t)
  4611. (catch :skip
  4612. (org-agenda-skip)
  4613. (setq marker (org-agenda-new-marker (match-beginning 0))
  4614. closedp (equal (match-string 1) org-closed-string)
  4615. statep (equal (string-to-char (match-string 1)) ?-)
  4616. clockp (not (or closedp statep))
  4617. state (and statep (match-string 2))
  4618. category (org-get-category (match-beginning 0))
  4619. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4620. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4621. (when (string-match "\\]" timestr)
  4622. ;; substring should only run to end of time stamp
  4623. (setq rest (substring timestr (match-end 0))
  4624. timestr (substring timestr 0 (match-end 0)))
  4625. (if (and (not closedp) (not statep)
  4626. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4627. rest))
  4628. (progn (setq timestr (concat (substring timestr 0 -1)
  4629. "-" (match-string 1 rest) "]"))
  4630. (setq clocked (match-string 2 rest)))
  4631. (setq clocked "-")))
  4632. (save-excursion
  4633. (setq extra
  4634. (cond
  4635. ((not org-agenda-log-mode-add-notes) nil)
  4636. (statep
  4637. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4638. (match-string 1)))
  4639. (clockp
  4640. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4641. (match-string 1)))))
  4642. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4643. (setq txt org-agenda-no-heading-message)
  4644. (goto-char (match-beginning 0))
  4645. (setq hdmarker (org-agenda-new-marker)
  4646. tags (org-get-tags-at))
  4647. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4648. (setq txt (match-string 1))
  4649. (when extra
  4650. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4651. (setq txt (concat (substring txt 0 (match-beginning 1))
  4652. " - " extra " " (match-string 2 txt)))
  4653. (setq txt (concat txt " - " extra))))
  4654. (setq txt (org-agenda-format-item
  4655. (cond
  4656. (closedp "Closed: ")
  4657. (statep (concat "State: (" state ")"))
  4658. (t (concat "Clocked: (" clocked ")")))
  4659. txt category tags timestr)))
  4660. (setq priority 100000)
  4661. (org-add-props txt props
  4662. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4663. 'priority priority 'org-category category
  4664. 'org-category-position org-category-pos
  4665. 'type "closed" 'date date
  4666. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4667. (push txt ee))
  4668. (goto-char (point-at-eol))))
  4669. (nreverse ee)))
  4670. (defun org-agenda-show-clocking-issues ()
  4671. "Add overlays, showing issues with clocking.
  4672. See also the user option `org-agenda-clock-consistency-checks'."
  4673. (interactive)
  4674. (let* ((pl org-agenda-clock-consistency-checks)
  4675. (re (concat "^[ \t]*"
  4676. org-clock-string
  4677. "[ \t]+"
  4678. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4679. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4680. (tlstart 0.)
  4681. (tlend 0.)
  4682. (maxtime (org-hh:mm-string-to-minutes
  4683. (or (plist-get pl :max-duration) "24:00")))
  4684. (mintime (org-hh:mm-string-to-minutes
  4685. (or (plist-get pl :min-duration) 0)))
  4686. (maxgap (org-hh:mm-string-to-minutes
  4687. ;; default 30:00 means never complain
  4688. (or (plist-get pl :max-gap) "30:00")))
  4689. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4690. (plist-get pl :gap-ok-around)))
  4691. (def-face (or (plist-get pl :default-face)
  4692. '((:background "DarkRed") (:foreground "white"))))
  4693. issue face m te ts dt ov)
  4694. (goto-char (point-min))
  4695. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4696. (setq issue nil face def-face)
  4697. (catch 'next
  4698. (setq m (org-get-at-bol 'org-marker)
  4699. te nil ts nil)
  4700. (unless (and m (markerp m))
  4701. (setq issue "No valid clock line") (throw 'next t))
  4702. (org-with-point-at m
  4703. (save-excursion
  4704. (goto-char (point-at-bol))
  4705. (unless (looking-at re)
  4706. (error "No valid Clock line")
  4707. (throw 'next t))
  4708. (unless (match-end 3)
  4709. (setq issue "No end time"
  4710. face (or (plist-get pl :no-end-time-face) face))
  4711. (throw 'next t))
  4712. (setq ts (match-string 1)
  4713. te (match-string 3)
  4714. ts (org-float-time
  4715. (apply 'encode-time (org-parse-time-string ts)))
  4716. te (org-float-time
  4717. (apply 'encode-time (org-parse-time-string te)))
  4718. dt (- te ts))))
  4719. (cond
  4720. ((> dt (* 60 maxtime))
  4721. ;; a very long clocking chunk
  4722. (setq issue (format "Clocking interval is very long: %s"
  4723. (org-minutes-to-hh:mm-string
  4724. (floor (/ (float dt) 60.))))
  4725. face (or (plist-get pl :long-face) face)))
  4726. ((< dt (* 60 mintime))
  4727. ;; a very short clocking chunk
  4728. (setq issue (format "Clocking interval is very short: %s"
  4729. (org-minutes-to-hh:mm-string
  4730. (floor (/ (float dt) 60.))))
  4731. face (or (plist-get pl :short-face) face)))
  4732. ((and (> tlend 0) (< ts tlend))
  4733. ;; Two clock entries are overlapping
  4734. (setq issue (format "Clocking overlap: %d minutes"
  4735. (/ (- tlend ts) 60))
  4736. face (or (plist-get pl :overlap-face) face)))
  4737. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4738. ;; There is a gap, lets see if we need to report it
  4739. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4740. (setq issue (format "Clocking gap: %d minutes"
  4741. (/ (- ts tlend) 60))
  4742. face (or (plist-get pl :gap-face) face))))
  4743. (t nil)))
  4744. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4745. (when issue
  4746. ;; OK, there was some issue, add an overlay to show the issue
  4747. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4748. (overlay-put ov 'before-string
  4749. (concat
  4750. (org-add-props
  4751. (format "%-43s" (concat " " issue))
  4752. nil
  4753. 'face face)
  4754. "\n"))
  4755. (overlay-put ov 'evaporate t)))))
  4756. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4757. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4758. (catch 'exit
  4759. (unless ok-list
  4760. ;; there are no OK times for gaps...
  4761. (throw 'exit nil))
  4762. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4763. ;; This is more than 24 hours, so it is OK.
  4764. ;; because we have at least one OK time, that must be in the
  4765. ;; 24 hour interval.
  4766. (throw 'exit t))
  4767. ;; We have a shorter gap.
  4768. ;; Now we have to get the minute of the day when these times are
  4769. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4770. (t2dec (decode-time (seconds-to-time t2)))
  4771. ;; compute the minute on the day
  4772. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4773. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4774. (when (< min2 min1)
  4775. ;; if min2 is smaller than min1, this means it is on the next day.
  4776. ;; Wrap it to after midnight.
  4777. (setq min2 (+ min2 1440)))
  4778. ;; Now check if any of the OK times is in the gap
  4779. (mapc (lambda (x)
  4780. ;; Wrap the time to after midnight if necessary
  4781. (if (< x min1) (setq x (+ x 1440)))
  4782. ;; Check if in interval
  4783. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4784. ok-list)
  4785. ;; Nope, this gap is not OK
  4786. nil)))
  4787. (defun org-agenda-get-deadlines ()
  4788. "Return the deadline information for agenda display."
  4789. (let* ((props (list 'mouse-face 'highlight
  4790. 'org-not-done-regexp org-not-done-regexp
  4791. 'org-todo-regexp org-todo-regexp
  4792. 'org-complex-heading-regexp org-complex-heading-regexp
  4793. 'help-echo
  4794. (format "mouse-2 or RET jump to org file %s"
  4795. (abbreviate-file-name buffer-file-name))))
  4796. (regexp org-deadline-time-regexp)
  4797. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4798. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4799. d2 diff dfrac wdays pos pos1 category org-category-pos
  4800. tags suppress-prewarning ee txt head face s todo-state
  4801. show-all upcomingp donep timestr)
  4802. (goto-char (point-min))
  4803. (while (re-search-forward regexp nil t)
  4804. (setq suppress-prewarning nil)
  4805. (catch :skip
  4806. (org-agenda-skip)
  4807. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4808. (save-match-data
  4809. (string-match org-scheduled-time-regexp
  4810. (buffer-substring (point-at-bol)
  4811. (point-at-eol)))))
  4812. (setq suppress-prewarning
  4813. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4814. org-agenda-skip-deadline-prewarning-if-scheduled
  4815. 0)))
  4816. (setq s (match-string 1)
  4817. txt nil
  4818. pos (1- (match-beginning 1))
  4819. todo-state (save-match-data (org-get-todo-state))
  4820. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4821. (member todo-state
  4822. org-agenda-repeating-timestamp-show-all))
  4823. d2 (org-time-string-to-absolute
  4824. (match-string 1) d1 'past show-all
  4825. (current-buffer) pos)
  4826. diff (- d2 d1)
  4827. wdays (if suppress-prewarning
  4828. (let ((org-deadline-warning-days suppress-prewarning))
  4829. (org-get-wdays s))
  4830. (org-get-wdays s))
  4831. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4832. upcomingp (and todayp (> diff 0)))
  4833. ;; When to show a deadline in the calendar:
  4834. ;; If the expiration is within wdays warning time.
  4835. ;; Past-due deadlines are only shown on the current date
  4836. (if (and (or (and (<= diff wdays)
  4837. (and todayp (not org-agenda-only-exact-dates)))
  4838. (= diff 0)))
  4839. (save-excursion
  4840. ;; (setq todo-state (org-get-todo-state))
  4841. (setq donep (member todo-state org-done-keywords))
  4842. (if (and donep
  4843. (or org-agenda-skip-deadline-if-done
  4844. (not (= diff 0))))
  4845. (setq txt nil)
  4846. (setq category (org-get-category)
  4847. org-category-pos (get-text-property (point) 'org-category-position))
  4848. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4849. (setq txt org-agenda-no-heading-message)
  4850. (goto-char (match-end 0))
  4851. (setq pos1 (match-beginning 0))
  4852. (setq tags (org-get-tags-at pos1))
  4853. (setq head (buffer-substring-no-properties
  4854. (point)
  4855. (progn (skip-chars-forward "^\r\n")
  4856. (point))))
  4857. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4858. (setq timestr
  4859. (concat (substring s (match-beginning 1)) " "))
  4860. (setq timestr 'time))
  4861. (setq txt (org-agenda-format-item
  4862. (if (= diff 0)
  4863. (car org-agenda-deadline-leaders)
  4864. (if (functionp
  4865. (nth 1 org-agenda-deadline-leaders))
  4866. (funcall
  4867. (nth 1 org-agenda-deadline-leaders)
  4868. diff date)
  4869. (format (nth 1 org-agenda-deadline-leaders)
  4870. diff)))
  4871. head category tags
  4872. (if (not (= diff 0)) nil timestr)))))
  4873. (when txt
  4874. (setq face (org-agenda-deadline-face dfrac))
  4875. (org-add-props txt props
  4876. 'org-marker (org-agenda-new-marker pos)
  4877. 'org-hd-marker (org-agenda-new-marker pos1)
  4878. 'priority (+ (- diff)
  4879. (org-get-priority txt))
  4880. 'org-category category
  4881. 'org-category-position org-category-pos
  4882. 'todo-state todo-state
  4883. 'type (if upcomingp "upcoming-deadline" "deadline")
  4884. 'date (if upcomingp date d2)
  4885. 'face (if donep 'org-agenda-done face)
  4886. 'undone-face face 'done-face 'org-agenda-done)
  4887. (push txt ee))))))
  4888. (nreverse ee)))
  4889. (defun org-agenda-deadline-face (fraction)
  4890. "Return the face to displaying a deadline item.
  4891. FRACTION is what fraction of the head-warning time has passed."
  4892. (let ((faces org-agenda-deadline-faces) f)
  4893. (catch 'exit
  4894. (while (setq f (pop faces))
  4895. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4896. (defun org-agenda-get-scheduled (&optional deadline-results)
  4897. "Return the scheduled information for agenda display."
  4898. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4899. 'org-todo-regexp org-todo-regexp
  4900. 'org-complex-heading-regexp org-complex-heading-regexp
  4901. 'done-face 'org-agenda-done
  4902. 'mouse-face 'highlight
  4903. 'help-echo
  4904. (format "mouse-2 or RET jump to org file %s"
  4905. (abbreviate-file-name buffer-file-name))))
  4906. (regexp org-scheduled-time-regexp)
  4907. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4908. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4909. mm
  4910. (deadline-position-alist
  4911. (mapcar (lambda (a) (and (setq mm (get-text-property
  4912. 0 'org-hd-marker a))
  4913. (cons (marker-position mm) a)))
  4914. deadline-results))
  4915. d2 diff pos pos1 category org-category-pos tags donep
  4916. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4917. (goto-char (point-min))
  4918. (while (re-search-forward regexp nil t)
  4919. (catch :skip
  4920. (org-agenda-skip)
  4921. (setq s (match-string 1)
  4922. txt nil
  4923. pos (1- (match-beginning 1))
  4924. todo-state (save-match-data (org-get-todo-state))
  4925. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4926. (member todo-state
  4927. org-agenda-repeating-timestamp-show-all))
  4928. d2 (org-time-string-to-absolute
  4929. (match-string 1) d1 'past show-all
  4930. (current-buffer) pos)
  4931. diff (- d2 d1))
  4932. (setq pastschedp (and todayp (< diff 0)))
  4933. ;; When to show a scheduled item in the calendar:
  4934. ;; If it is on or past the date.
  4935. (when (or (and (< diff 0)
  4936. (< (abs diff) org-scheduled-past-days)
  4937. (and todayp (not org-agenda-only-exact-dates)))
  4938. (= diff 0))
  4939. (save-excursion
  4940. (setq donep (member todo-state org-done-keywords))
  4941. (if (and donep
  4942. (or org-agenda-skip-scheduled-if-done
  4943. (not (= diff 0))
  4944. (and (functionp 'org-is-habit-p)
  4945. (org-is-habit-p))))
  4946. (setq txt nil)
  4947. (setq habitp (and (functionp 'org-is-habit-p)
  4948. (org-is-habit-p)))
  4949. (setq category (org-get-category)
  4950. org-category-pos (get-text-property (point) 'org-category-position))
  4951. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4952. (setq txt org-agenda-no-heading-message)
  4953. (goto-char (match-end 0))
  4954. (setq pos1 (match-beginning 0))
  4955. (if habitp
  4956. (if (or (not org-habit-show-habits)
  4957. (and (not todayp)
  4958. org-habit-show-habits-only-for-today))
  4959. (throw :skip nil))
  4960. (if (and
  4961. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4962. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4963. pastschedp))
  4964. (setq mm (assoc pos1 deadline-position-alist)))
  4965. (throw :skip nil)))
  4966. (setq tags (org-get-tags-at))
  4967. (setq head (buffer-substring-no-properties
  4968. (point)
  4969. (progn (skip-chars-forward "^\r\n") (point))))
  4970. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4971. (setq timestr
  4972. (concat (substring s (match-beginning 1)) " "))
  4973. (setq timestr 'time))
  4974. (setq txt (org-agenda-format-item
  4975. (if (= diff 0)
  4976. (car org-agenda-scheduled-leaders)
  4977. (format (nth 1 org-agenda-scheduled-leaders)
  4978. (- 1 diff)))
  4979. head category tags
  4980. (if (not (= diff 0)) nil timestr)
  4981. nil habitp))))
  4982. (when txt
  4983. (setq face
  4984. (cond
  4985. ((and (not habitp) pastschedp)
  4986. 'org-scheduled-previously)
  4987. (todayp 'org-scheduled-today)
  4988. (t 'org-scheduled))
  4989. habitp (and habitp (org-habit-parse-todo)))
  4990. (org-add-props txt props
  4991. 'undone-face face
  4992. 'face (if donep 'org-agenda-done face)
  4993. 'org-marker (org-agenda-new-marker pos)
  4994. 'org-hd-marker (org-agenda-new-marker pos1)
  4995. 'type (if pastschedp "past-scheduled" "scheduled")
  4996. 'date (if pastschedp d2 date)
  4997. 'priority (if habitp
  4998. (org-habit-get-priority habitp)
  4999. (+ 94 (- 5 diff) (org-get-priority txt)))
  5000. 'org-category category
  5001. 'org-category-position org-category-pos
  5002. 'org-habit-p habitp
  5003. 'todo-state todo-state)
  5004. (push txt ee))))))
  5005. (nreverse ee)))
  5006. (defun org-agenda-get-blocks ()
  5007. "Return the date-range information for agenda display."
  5008. (let* ((props (list 'face nil
  5009. 'org-not-done-regexp org-not-done-regexp
  5010. 'org-todo-regexp org-todo-regexp
  5011. 'org-complex-heading-regexp org-complex-heading-regexp
  5012. 'mouse-face 'highlight
  5013. 'help-echo
  5014. (format "mouse-2 or RET jump to org file %s"
  5015. (abbreviate-file-name buffer-file-name))))
  5016. (regexp org-tr-regexp)
  5017. (d0 (calendar-absolute-from-gregorian date))
  5018. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5019. todo-state tags pos head donep)
  5020. (goto-char (point-min))
  5021. (while (re-search-forward regexp nil t)
  5022. (catch :skip
  5023. (org-agenda-skip)
  5024. (setq pos (point))
  5025. (let ((start-time (match-string 1))
  5026. (end-time (match-string 2)))
  5027. (setq s1 (match-string 1)
  5028. s2 (match-string 2)
  5029. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5030. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5031. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5032. ;; Only allow days between the limits, because the normal
  5033. ;; date stamps will catch the limits.
  5034. (save-excursion
  5035. (setq todo-state (org-get-todo-state))
  5036. (setq donep (member todo-state org-done-keywords))
  5037. (if (and donep org-agenda-skip-timestamp-if-done)
  5038. (throw :skip t))
  5039. (setq marker (org-agenda-new-marker (point)))
  5040. (setq category (org-get-category)
  5041. org-category-pos (get-text-property (point) 'org-category-position))
  5042. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5043. (setq txt org-agenda-no-heading-message)
  5044. (goto-char (match-beginning 0))
  5045. (setq hdmarker (org-agenda-new-marker (point)))
  5046. (setq tags (org-get-tags-at))
  5047. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5048. (setq head (match-string 1))
  5049. (let ((remove-re
  5050. (if org-agenda-remove-timeranges-from-blocks
  5051. (concat
  5052. "<" (regexp-quote s1) ".*?>"
  5053. "--"
  5054. "<" (regexp-quote s2) ".*?>")
  5055. nil)))
  5056. (setq txt (org-agenda-format-item
  5057. (format
  5058. (nth (if (= d1 d2) 0 1)
  5059. org-agenda-timerange-leaders)
  5060. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5061. head category tags
  5062. (cond ((and (= d1 d0) (= d2 d0))
  5063. (concat "<" start-time ">--<" end-time ">"))
  5064. ((= d1 d0)
  5065. (concat "<" start-time ">"))
  5066. ((= d2 d0)
  5067. (concat "<" end-time ">"))
  5068. (t nil))
  5069. remove-re))))
  5070. (org-add-props txt props
  5071. 'org-marker marker 'org-hd-marker hdmarker
  5072. 'type "block" 'date date
  5073. 'todo-state todo-state
  5074. 'priority (org-get-priority txt) 'org-category category
  5075. 'org-category-position org-category-pos)
  5076. (push txt ee))))
  5077. (goto-char pos)))
  5078. ;; Sort the entries by expiration date.
  5079. (nreverse ee)))
  5080. ;;; Agenda presentation and sorting
  5081. (defvar org-prefix-has-time nil
  5082. "A flag, set by `org-compile-prefix-format'.
  5083. The flag is set if the currently compiled format contains a `%t'.")
  5084. (defvar org-prefix-has-tag nil
  5085. "A flag, set by `org-compile-prefix-format'.
  5086. The flag is set if the currently compiled format contains a `%T'.")
  5087. (defvar org-prefix-has-effort nil
  5088. "A flag, set by `org-compile-prefix-format'.
  5089. The flag is set if the currently compiled format contains a `%e'.")
  5090. (defvar org-prefix-category-length nil
  5091. "Used by `org-compile-prefix-format' to remember the category field width.")
  5092. (defvar org-prefix-category-max-length nil
  5093. "Used by `org-compile-prefix-format' to remember the category field width.")
  5094. (defun org-agenda-get-category-icon (category)
  5095. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5096. (dolist (entry org-agenda-category-icon-alist)
  5097. (when (org-string-match-p (car entry) category)
  5098. (if (listp (cadr entry))
  5099. (return (cadr entry))
  5100. (return (apply 'create-image (cdr entry)))))))
  5101. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5102. remove-re habitp)
  5103. "Format TXT to be inserted into the agenda buffer.
  5104. In particular, it adds the prefix and corresponding text properties. EXTRA
  5105. must be a string and replaces the `%s' specifier in the prefix format.
  5106. CATEGORY (string, symbol or nil) may be used to overrule the default
  5107. category taken from local variable or file name. It will replace the `%c'
  5108. specifier in the format. DOTIME, when non-nil, indicates that a
  5109. time-of-day should be extracted from TXT for sorting of this entry, and for
  5110. the `%t' specifier in the format. When DOTIME is a string, this string is
  5111. searched for a time before TXT is. TAGS can be the tags of the headline.
  5112. Any match of REMOVE-RE will be removed from TXT."
  5113. (save-match-data
  5114. ;; Diary entries sometimes have extra whitespace at the beginning
  5115. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5116. ;; Fix the tags part in txt
  5117. (setq txt (org-agenda-fix-displayed-tags
  5118. txt tags
  5119. org-agenda-show-inherited-tags
  5120. org-agenda-hide-tags-regexp))
  5121. (let* ((category (or category
  5122. (if (stringp org-category)
  5123. org-category
  5124. (and org-category (symbol-name org-category)))
  5125. (if buffer-file-name
  5126. (file-name-sans-extension
  5127. (file-name-nondirectory buffer-file-name))
  5128. "")))
  5129. (category-icon (org-agenda-get-category-icon category))
  5130. (category-icon (if category-icon
  5131. (propertize " " 'display category-icon)
  5132. ""))
  5133. ;; time, tag, effort are needed for the eval of the prefix format
  5134. (tag (if tags (nth (1- (length tags)) tags) ""))
  5135. time effort neffort
  5136. (ts (if dotime (concat
  5137. (if (stringp dotime) dotime "")
  5138. (and org-agenda-search-headline-for-time txt))))
  5139. (time-of-day (and dotime (org-get-time-of-day ts)))
  5140. stamp plain s0 s1 s2 rtn srp l
  5141. duration thecategory)
  5142. (and (eq major-mode 'org-mode) buffer-file-name
  5143. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5144. (when (and dotime time-of-day)
  5145. ;; Extract starting and ending time and move them to prefix
  5146. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5147. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5148. (setq s0 (match-string 0 ts)
  5149. srp (and stamp (match-end 3))
  5150. s1 (match-string (if plain 1 2) ts)
  5151. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5152. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5153. ;; them, we might want to remove them there to avoid duplication.
  5154. ;; The user can turn this off with a variable.
  5155. (if (and org-prefix-has-time
  5156. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5157. (string-match (concat (regexp-quote s0) " *") txt)
  5158. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5159. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5160. (= (match-beginning 0) 0)
  5161. t))
  5162. (setq txt (replace-match "" nil nil txt))))
  5163. ;; Normalize the time(s) to 24 hour
  5164. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5165. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5166. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5167. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5168. (setq s2
  5169. (org-minutes-to-hh:mm-string
  5170. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5171. ;; Compute the duration
  5172. (when s2
  5173. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5174. (org-hh:mm-string-to-minutes s1)))))
  5175. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5176. txt)
  5177. ;; Tags are in the string
  5178. (if (or (eq org-agenda-remove-tags t)
  5179. (and org-agenda-remove-tags
  5180. org-prefix-has-tag))
  5181. (setq txt (replace-match "" t t txt))
  5182. (setq txt (replace-match
  5183. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5184. (match-string 2 txt))
  5185. t t txt))))
  5186. (when (eq major-mode 'org-mode)
  5187. (setq effort
  5188. (condition-case nil
  5189. (org-get-effort
  5190. (or (get-text-property 0 'org-hd-marker txt)
  5191. (get-text-property 0 'org-marker txt)))
  5192. (error nil)))
  5193. (when effort
  5194. (setq neffort (org-duration-string-to-minutes effort)
  5195. effort (setq effort (concat "[" effort "]")))))
  5196. ;; prevent erroring out with %e format when there is no effort
  5197. (or effort (setq effort ""))
  5198. (when remove-re
  5199. (while (string-match remove-re txt)
  5200. (setq txt (replace-match "" t t txt))))
  5201. ;; Set org-heading property on `txt' to mark the start of the
  5202. ;; heading.
  5203. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5204. ;; Prepare the variables needed in the eval of the compiled format
  5205. (setq time (cond (s2 (concat
  5206. (org-agenda-time-of-day-to-ampm-maybe s1)
  5207. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5208. (if org-agenda-timegrid-use-ampm " ")))
  5209. (s1 (concat
  5210. (org-agenda-time-of-day-to-ampm-maybe s1)
  5211. (if org-agenda-timegrid-use-ampm
  5212. "........ "
  5213. "......")))
  5214. (t ""))
  5215. extra (or (and (not habitp) extra) "")
  5216. category (if (symbolp category) (symbol-name category) category)
  5217. thecategory (copy-sequence category))
  5218. (if (string-match org-bracket-link-regexp category)
  5219. (progn
  5220. (setq l (if (match-end 3)
  5221. (- (match-end 3) (match-beginning 3))
  5222. (- (match-end 1) (match-beginning 1))))
  5223. (when (< l (or org-prefix-category-length 0))
  5224. (setq category (copy-sequence category))
  5225. (org-add-props category nil
  5226. 'extra-space (make-string
  5227. (- org-prefix-category-length l 1) ?\ ))))
  5228. (if (and org-prefix-category-max-length
  5229. (>= (length category) org-prefix-category-max-length))
  5230. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5231. ;; Evaluate the compiled format
  5232. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5233. ;; And finally add the text properties
  5234. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5235. (org-add-props rtn nil
  5236. 'org-category (if thecategory (downcase thecategory) category)
  5237. 'tags (mapcar 'org-downcase-keep-props tags)
  5238. 'org-highest-priority org-highest-priority
  5239. 'org-lowest-priority org-lowest-priority
  5240. 'time-of-day time-of-day
  5241. 'duration duration
  5242. 'effort effort
  5243. 'effort-minutes neffort
  5244. 'txt txt
  5245. 'time time
  5246. 'extra extra
  5247. 'format org-prefix-format-compiled
  5248. 'dotime dotime))))
  5249. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5250. "Remove tags string from TXT, and add a modified list of tags.
  5251. The modified list may contain inherited tags, and tags matched by
  5252. `org-agenda-hide-tags-regexp' will be removed."
  5253. (when (or add-inherited hide-re)
  5254. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5255. (setq txt (substring txt 0 (match-beginning 0))))
  5256. (setq tags
  5257. (delq nil
  5258. (mapcar (lambda (tg)
  5259. (if (or (and hide-re (string-match hide-re tg))
  5260. (and (not add-inherited)
  5261. (get-text-property 0 'inherited tg)))
  5262. nil
  5263. tg))
  5264. tags)))
  5265. (when tags
  5266. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5267. i)
  5268. (setq txt (concat txt " :"
  5269. (mapconcat
  5270. (lambda (x)
  5271. (setq i (get-text-property 0 'inherited x))
  5272. (if (and have-i (not i))
  5273. (progn
  5274. (setq have-i nil)
  5275. (concat ":" x))
  5276. x))
  5277. tags ":")
  5278. (if have-i "::" ":"))))))
  5279. txt)
  5280. (defun org-downcase-keep-props (s)
  5281. (let ((props (text-properties-at 0 s)))
  5282. (setq s (downcase s))
  5283. (add-text-properties 0 (length s) props s)
  5284. s))
  5285. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5286. (defvar org-agenda-sorting-strategy-selected nil)
  5287. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5288. (catch 'exit
  5289. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5290. ((and todayp (member 'today (car org-agenda-time-grid))))
  5291. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5292. ((member 'weekly (car org-agenda-time-grid)))
  5293. (t (throw 'exit list)))
  5294. (let* ((have (delq nil (mapcar
  5295. (lambda (x) (get-text-property 1 'time-of-day x))
  5296. list)))
  5297. (string (nth 1 org-agenda-time-grid))
  5298. (gridtimes (nth 2 org-agenda-time-grid))
  5299. (req (car org-agenda-time-grid))
  5300. (remove (member 'remove-match req))
  5301. new time)
  5302. (if (and (member 'require-timed req) (not have))
  5303. ;; don't show empty grid
  5304. (throw 'exit list))
  5305. (while (setq time (pop gridtimes))
  5306. (unless (and remove (member time have))
  5307. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5308. (push (org-agenda-format-item
  5309. nil string "" nil
  5310. (concat (substring time 0 -2) ":" (substring time -2)))
  5311. new)
  5312. (put-text-property
  5313. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5314. (when (and todayp org-agenda-show-current-time-in-grid)
  5315. (push (org-agenda-format-item
  5316. nil
  5317. org-agenda-current-time-string
  5318. "" nil
  5319. (format-time-string "%H:%M "))
  5320. new)
  5321. (put-text-property
  5322. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5323. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5324. (append new list)
  5325. (append list new)))))
  5326. (defun org-compile-prefix-format (key)
  5327. "Compile the prefix format into a Lisp form that can be evaluated.
  5328. The resulting form is returned and stored in the variable
  5329. `org-prefix-format-compiled'."
  5330. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5331. org-prefix-category-length nil
  5332. org-prefix-has-effort nil)
  5333. (let ((s (cond
  5334. ((stringp org-agenda-prefix-format)
  5335. org-agenda-prefix-format)
  5336. ((assq key org-agenda-prefix-format)
  5337. (cdr (assq key org-agenda-prefix-format)))
  5338. (t " %-12:c%?-12t% s")))
  5339. (start 0)
  5340. varform vars var e c f opt)
  5341. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5342. s start)
  5343. (setq var (or (cdr (assoc (match-string 4 s)
  5344. '(("c" . category) ("t" . time) ("s" . extra)
  5345. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5346. 'eval)
  5347. c (or (match-string 3 s) "")
  5348. opt (match-beginning 1)
  5349. start (1+ (match-beginning 0)))
  5350. (if (equal var 'time) (setq org-prefix-has-time t))
  5351. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5352. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5353. (setq f (concat "%" (match-string 2 s) "s"))
  5354. (when (equal var 'category)
  5355. (setq org-prefix-category-length
  5356. (floor (abs (string-to-number (match-string 2 s)))))
  5357. (setq org-prefix-category-max-length
  5358. (let ((x (match-string 2 s)))
  5359. (save-match-data
  5360. (if (string-match "\\.[0-9]+" x)
  5361. (string-to-number (substring (match-string 0 x) 1)))))))
  5362. (if (eq var 'eval)
  5363. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5364. (if opt
  5365. (setq varform
  5366. `(if (equal "" ,var)
  5367. ""
  5368. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5369. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5370. (setq s (replace-match "%s" t nil s))
  5371. (push varform vars))
  5372. (setq vars (nreverse vars))
  5373. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5374. (defun org-set-sorting-strategy (key)
  5375. (if (symbolp (car org-agenda-sorting-strategy))
  5376. ;; the old format
  5377. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5378. (setq org-agenda-sorting-strategy-selected
  5379. (or (cdr (assq key org-agenda-sorting-strategy))
  5380. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5381. '(time-up category-keep priority-down)))))
  5382. (defun org-get-time-of-day (s &optional string mod24)
  5383. "Check string S for a time of day.
  5384. If found, return it as a military time number between 0 and 2400.
  5385. If not found, return nil.
  5386. The optional STRING argument forces conversion into a 5 character wide string
  5387. HH:MM."
  5388. (save-match-data
  5389. (when
  5390. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5391. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5392. (let* ((h (string-to-number (match-string 1 s)))
  5393. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5394. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5395. (am-p (equal ampm "am"))
  5396. (h1 (cond ((not ampm) h)
  5397. ((= h 12) (if am-p 0 12))
  5398. (t (+ h (if am-p 0 12)))))
  5399. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5400. (mod h1 24) h1))
  5401. (t0 (+ (* 100 h2) m))
  5402. (t1 (concat (if (>= h1 24) "+" " ")
  5403. (if (and org-agenda-time-leading-zero
  5404. (< t0 1000)) "0" "")
  5405. (if (< t0 100) "0" "")
  5406. (if (< t0 10) "0" "")
  5407. (int-to-string t0))))
  5408. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5409. (defvar org-agenda-before-sorting-filter-function nil
  5410. "Function to be applied to agenda items prior to sorting.
  5411. Prior to sorting also means just before they are inserted into the agenda.
  5412. To aid sorting, you may revisit the original entries and add more text
  5413. properties which will later be used by the sorting functions.
  5414. The function should take a string argument, an agenda line.
  5415. It has access to the text properties in that line, which contain among
  5416. other things, the property `org-hd-marker' that points to the entry
  5417. where the line comes from. Note that not all lines going into the agenda
  5418. have this property, only most.
  5419. The function should return the modified string. It is probably best
  5420. to ONLY change text properties.
  5421. You can also use this function as a filter, by returning nil for lines
  5422. you don't want to have in the agenda at all. For this application, you
  5423. could bind the variable in the options section of a custom command.")
  5424. (defun org-finalize-agenda-entries (list &optional nosort)
  5425. "Sort and concatenate the agenda items."
  5426. (setq list (mapcar 'org-agenda-highlight-todo list))
  5427. (if nosort
  5428. list
  5429. (when org-agenda-before-sorting-filter-function
  5430. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5431. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5432. (defun org-agenda-highlight-todo (x)
  5433. (let ((org-done-keywords org-done-keywords-for-agenda)
  5434. (case-fold-search nil)
  5435. re)
  5436. (if (eq x 'line)
  5437. (save-excursion
  5438. (beginning-of-line 1)
  5439. (setq re (org-get-at-bol 'org-todo-regexp))
  5440. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5441. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5442. (add-text-properties (match-beginning 0) (match-end 1)
  5443. (list 'face (org-get-todo-face 1)))
  5444. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5445. (delete-region (match-beginning 1) (1- (match-end 0)))
  5446. (goto-char (match-beginning 1))
  5447. (insert (format org-agenda-todo-keyword-format s)))))
  5448. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5449. (setq re (get-text-property 0 'org-todo-regexp x))
  5450. (when (and re
  5451. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5452. x (or pl 0)) pl))
  5453. (add-text-properties
  5454. (or (match-end 1) (match-end 0)) (match-end 0)
  5455. (list 'face (org-get-todo-face (match-string 2 x)))
  5456. x)
  5457. (when (match-end 1)
  5458. (setq x (concat (substring x 0 (match-end 1))
  5459. (format org-agenda-todo-keyword-format
  5460. (match-string 2 x))
  5461. (org-add-props " " (text-properties-at 0 x))
  5462. (substring x (match-end 3)))))))
  5463. x)))
  5464. (defsubst org-cmp-priority (a b)
  5465. "Compare the priorities of string A and B."
  5466. (let ((pa (or (get-text-property 1 'priority a) 0))
  5467. (pb (or (get-text-property 1 'priority b) 0)))
  5468. (cond ((> pa pb) +1)
  5469. ((< pa pb) -1)
  5470. (t nil))))
  5471. (defsubst org-cmp-effort (a b)
  5472. "Compare the effort values of string A and B."
  5473. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5474. (ea (or (get-text-property 1 'effort-minutes a) def))
  5475. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5476. (cond ((> ea eb) +1)
  5477. ((< ea eb) -1)
  5478. (t nil))))
  5479. (defsubst org-cmp-category (a b)
  5480. "Compare the string values of categories of strings A and B."
  5481. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5482. (cb (or (get-text-property 1 'org-category b) "")))
  5483. (cond ((string-lessp ca cb) -1)
  5484. ((string-lessp cb ca) +1)
  5485. (t nil))))
  5486. (defsubst org-cmp-todo-state (a b)
  5487. "Compare the todo states of strings A and B."
  5488. (let* ((ma (or (get-text-property 1 'org-marker a)
  5489. (get-text-property 1 'org-hd-marker a)))
  5490. (mb (or (get-text-property 1 'org-marker b)
  5491. (get-text-property 1 'org-hd-marker b)))
  5492. (fa (and ma (marker-buffer ma)))
  5493. (fb (and mb (marker-buffer mb)))
  5494. (todo-kwds
  5495. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5496. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5497. (ta (or (get-text-property 1 'todo-state a) ""))
  5498. (tb (or (get-text-property 1 'todo-state b) ""))
  5499. (la (- (length (member ta todo-kwds))))
  5500. (lb (- (length (member tb todo-kwds))))
  5501. (donepa (member ta org-done-keywords-for-agenda))
  5502. (donepb (member tb org-done-keywords-for-agenda)))
  5503. (cond ((and donepa (not donepb)) -1)
  5504. ((and (not donepa) donepb) +1)
  5505. ((< la lb) -1)
  5506. ((< lb la) +1)
  5507. (t nil))))
  5508. (defsubst org-cmp-alpha (a b)
  5509. "Compare the headlines, alphabetically."
  5510. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5511. (plb (text-property-any 0 (length b) 'org-heading t b))
  5512. (ta (and pla (substring a pla)))
  5513. (tb (and plb (substring b plb))))
  5514. (when pla
  5515. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5516. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5517. (setq ta (substring ta (match-end 0))))
  5518. (setq ta (downcase ta)))
  5519. (when plb
  5520. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5521. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5522. (setq tb (substring tb (match-end 0))))
  5523. (setq tb (downcase tb)))
  5524. (cond ((not ta) +1)
  5525. ((not tb) -1)
  5526. ((string-lessp ta tb) -1)
  5527. ((string-lessp tb ta) +1)
  5528. (t nil))))
  5529. (defsubst org-cmp-tag (a b)
  5530. "Compare the string values of the first tags of A and B."
  5531. (let ((ta (car (last (get-text-property 1 'tags a))))
  5532. (tb (car (last (get-text-property 1 'tags b)))))
  5533. (cond ((not ta) +1)
  5534. ((not tb) -1)
  5535. ((string-lessp ta tb) -1)
  5536. ((string-lessp tb ta) +1)
  5537. (t nil))))
  5538. (defsubst org-cmp-time (a b)
  5539. "Compare the time-of-day values of strings A and B."
  5540. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5541. (ta (or (get-text-property 1 'time-of-day a) def))
  5542. (tb (or (get-text-property 1 'time-of-day b) def)))
  5543. (cond ((< ta tb) -1)
  5544. ((< tb ta) +1)
  5545. (t nil))))
  5546. (defsubst org-cmp-habit-p (a b)
  5547. "Compare the todo states of strings A and B."
  5548. (let ((ha (get-text-property 1 'org-habit-p a))
  5549. (hb (get-text-property 1 'org-habit-p b)))
  5550. (cond ((and ha (not hb)) -1)
  5551. ((and (not ha) hb) +1)
  5552. (t nil))))
  5553. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5554. (defun org-entries-lessp (a b)
  5555. "Predicate for sorting agenda entries."
  5556. ;; The following variables will be used when the form is evaluated.
  5557. ;; So even though the compiler complains, keep them.
  5558. (let* ((ss org-agenda-sorting-strategy-selected)
  5559. (time-up (and (org-em 'time-up 'time-down ss)
  5560. (org-cmp-time a b)))
  5561. (time-down (if time-up (- time-up) nil))
  5562. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5563. (org-cmp-priority a b)))
  5564. (priority-down (if priority-up (- priority-up) nil))
  5565. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5566. (org-cmp-effort a b)))
  5567. (effort-down (if effort-up (- effort-up) nil))
  5568. (category-up (and (or (org-em 'category-up 'category-down ss)
  5569. (memq 'category-keep ss))
  5570. (org-cmp-category a b)))
  5571. (category-down (if category-up (- category-up) nil))
  5572. (category-keep (if category-up +1 nil))
  5573. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5574. (org-cmp-tag a b)))
  5575. (tag-down (if tag-up (- tag-up) nil))
  5576. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5577. (org-cmp-todo-state a b)))
  5578. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5579. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5580. (org-cmp-habit-p a b)))
  5581. (habit-down (if habit-up (- habit-up) nil))
  5582. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5583. (org-cmp-alpha a b)))
  5584. (alpha-down (if alpha-up (- alpha-up) nil))
  5585. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5586. user-defined-up user-defined-down)
  5587. (if (and need-user-cmp org-agenda-cmp-user-defined
  5588. (functionp org-agenda-cmp-user-defined))
  5589. (setq user-defined-up
  5590. (funcall org-agenda-cmp-user-defined a b)
  5591. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5592. (cdr (assoc
  5593. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5594. '((-1 . t) (1 . nil) (nil . nil))))))
  5595. ;;; Agenda restriction lock
  5596. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5597. "Overlay to mark the headline to which agenda commands are restricted.")
  5598. (overlay-put org-agenda-restriction-lock-overlay
  5599. 'face 'org-agenda-restriction-lock)
  5600. (overlay-put org-agenda-restriction-lock-overlay
  5601. 'help-echo "Agendas are currently limited to this subtree.")
  5602. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5603. (defun org-agenda-set-restriction-lock (&optional type)
  5604. "Set restriction lock for agenda, to current subtree or file.
  5605. Restriction will be the file if TYPE is `file', or if type is the
  5606. universal prefix '(4), or if the cursor is before the first headline
  5607. in the file. Otherwise, restriction will be to the current subtree."
  5608. (interactive "P")
  5609. (and (equal type '(4)) (setq type 'file))
  5610. (setq type (cond
  5611. (type type)
  5612. ((org-at-heading-p) 'subtree)
  5613. ((condition-case nil (org-back-to-heading t) (error nil))
  5614. 'subtree)
  5615. (t 'file)))
  5616. (if (eq type 'subtree)
  5617. (progn
  5618. (setq org-agenda-restrict t)
  5619. (setq org-agenda-overriding-restriction 'subtree)
  5620. (put 'org-agenda-files 'org-restrict
  5621. (list (buffer-file-name (buffer-base-buffer))))
  5622. (org-back-to-heading t)
  5623. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5624. (move-marker org-agenda-restrict-begin (point))
  5625. (move-marker org-agenda-restrict-end
  5626. (save-excursion (org-end-of-subtree t)))
  5627. (message "Locking agenda restriction to subtree"))
  5628. (put 'org-agenda-files 'org-restrict
  5629. (list (buffer-file-name (buffer-base-buffer))))
  5630. (setq org-agenda-restrict nil)
  5631. (setq org-agenda-overriding-restriction 'file)
  5632. (move-marker org-agenda-restrict-begin nil)
  5633. (move-marker org-agenda-restrict-end nil)
  5634. (message "Locking agenda restriction to file"))
  5635. (setq current-prefix-arg nil)
  5636. (org-agenda-maybe-redo))
  5637. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5638. "Remove the agenda restriction lock."
  5639. (interactive "P")
  5640. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5641. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5642. (setq org-agenda-overriding-restriction nil)
  5643. (setq org-agenda-restrict nil)
  5644. (put 'org-agenda-files 'org-restrict nil)
  5645. (move-marker org-agenda-restrict-begin nil)
  5646. (move-marker org-agenda-restrict-end nil)
  5647. (setq current-prefix-arg nil)
  5648. (message "Agenda restriction lock removed")
  5649. (or noupdate (org-agenda-maybe-redo)))
  5650. (defun org-agenda-maybe-redo ()
  5651. "If there is any window showing the agenda view, update it."
  5652. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5653. (w0 (selected-window)))
  5654. (when w
  5655. (select-window w)
  5656. (org-agenda-redo)
  5657. (select-window w0)
  5658. (if org-agenda-overriding-restriction
  5659. (message "Agenda view shifted to new %s restriction"
  5660. org-agenda-overriding-restriction)
  5661. (message "Agenda restriction lock removed")))))
  5662. ;;; Agenda commands
  5663. (defun org-agenda-check-type (error &rest types)
  5664. "Check if agenda buffer is of allowed type.
  5665. If ERROR is non-nil, throw an error, otherwise just return nil."
  5666. (if (memq org-agenda-type types)
  5667. t
  5668. (if error
  5669. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5670. nil)))
  5671. (defun org-agenda-quit ()
  5672. "Exit agenda by removing the window or the buffer."
  5673. (interactive)
  5674. (if org-agenda-columns-active
  5675. (org-columns-quit)
  5676. (let ((buf (current-buffer)))
  5677. (if (eq org-agenda-window-setup 'other-frame)
  5678. (progn
  5679. (kill-buffer buf)
  5680. (org-agenda-reset-markers)
  5681. (org-columns-remove-overlays)
  5682. (setq org-agenda-archives-mode nil)
  5683. (delete-frame))
  5684. (and (not (eq org-agenda-window-setup 'current-window))
  5685. (not (one-window-p))
  5686. (delete-window))
  5687. (kill-buffer buf)
  5688. (org-agenda-reset-markers)
  5689. (org-columns-remove-overlays)
  5690. (setq org-agenda-archives-mode nil)))
  5691. ;; Maybe restore the pre-agenda window configuration.
  5692. (and org-agenda-restore-windows-after-quit
  5693. (not (eq org-agenda-window-setup 'other-frame))
  5694. org-pre-agenda-window-conf
  5695. (set-window-configuration org-pre-agenda-window-conf))))
  5696. (defun org-agenda-exit ()
  5697. "Exit agenda by removing the window or the buffer.
  5698. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5699. Org-mode buffers visited directly by the user will not be touched."
  5700. (interactive)
  5701. (org-release-buffers org-agenda-new-buffers)
  5702. (setq org-agenda-new-buffers nil)
  5703. (org-agenda-quit))
  5704. (defun org-agenda-execute (arg)
  5705. "Execute another agenda command, keeping same window.
  5706. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5707. in the agenda."
  5708. (interactive "P")
  5709. (let ((org-agenda-window-setup 'current-window))
  5710. (org-agenda arg)))
  5711. (defun org-agenda-redo ()
  5712. "Rebuild Agenda.
  5713. When this is the global TODO list, a prefix argument will be interpreted."
  5714. (interactive)
  5715. (let* ((org-agenda-keep-modes t)
  5716. (tag-filter org-agenda-tag-filter)
  5717. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5718. (cat-filter org-agenda-category-filter)
  5719. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5720. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5721. (cols org-agenda-columns-active)
  5722. (line (org-current-line))
  5723. (window-line (- line (org-current-line (window-start))))
  5724. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5725. (put 'org-agenda-tag-filter :preset-filter nil)
  5726. (put 'org-agenda-category-filter :preset-filter nil)
  5727. (and cols (org-columns-quit))
  5728. (message "Rebuilding agenda buffer...")
  5729. (org-let lprops '(eval org-agenda-redo-command))
  5730. (setq org-agenda-undo-list nil
  5731. org-agenda-pending-undo-list nil)
  5732. (message "Rebuilding agenda buffer...done")
  5733. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5734. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5735. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5736. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5737. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5738. (org-goto-line line)
  5739. (recenter window-line)))
  5740. (defvar org-global-tags-completion-table nil)
  5741. (defvar org-agenda-filtered-by-category nil)
  5742. (defvar org-agenda-filter-form nil)
  5743. (defun org-agenda-filter-by-category (strip)
  5744. "Keep only those lines in the agenda buffer that have a specific category.
  5745. The category is that of the current line."
  5746. (interactive "P")
  5747. (if org-agenda-filtered-by-category
  5748. (org-agenda-filter-show-all-cat)
  5749. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  5750. (if cat (org-agenda-filter-apply
  5751. (list (concat (if strip "-" "+") cat)) 'category)
  5752. (error "No category at point")))))
  5753. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5754. "Keep only those lines in the agenda buffer that have a specific tag.
  5755. The tag is selected with its fast selection letter, as configured.
  5756. With prefix argument STRIP, remove all lines that do have the tag.
  5757. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5758. used to narrow the search - the interactive user can also press `-' or `+'
  5759. to switch to narrowing."
  5760. (interactive "P")
  5761. (let* ((alist org-tag-alist-for-agenda)
  5762. (tag-chars (mapconcat
  5763. (lambda (x) (if (and (not (symbolp (car x)))
  5764. (cdr x))
  5765. (char-to-string (cdr x))
  5766. ""))
  5767. alist ""))
  5768. (efforts (org-split-string
  5769. (or (cdr (assoc (concat org-effort-property "_ALL")
  5770. org-global-properties))
  5771. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5772. "")))
  5773. (effort-op org-agenda-filter-effort-default-operator)
  5774. (effort-prompt "")
  5775. (inhibit-read-only t)
  5776. (current org-agenda-tag-filter)
  5777. maybe-refresh a n tag)
  5778. (unless char
  5779. (message
  5780. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5781. (if narrow "Narrow" "Filter") tag-chars
  5782. (if org-agenda-auto-exclude-function "[RET], " ""))
  5783. (setq char (read-char-exclusive)))
  5784. (when (member char '(?+ ?-))
  5785. ;; Narrowing down
  5786. (cond ((equal char ?-) (setq strip t narrow t))
  5787. ((equal char ?+) (setq strip nil narrow t)))
  5788. (message
  5789. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5790. (setq char (read-char-exclusive)))
  5791. (when (member char '(?< ?> ?= ??))
  5792. ;; An effort operator
  5793. (setq effort-op (char-to-string char))
  5794. (setq alist nil) ; to make sure it will be interpreted as effort.
  5795. (unless (equal char ??)
  5796. (loop for i from 0 to 9 do
  5797. (setq effort-prompt
  5798. (concat
  5799. effort-prompt " ["
  5800. (if (= i 9) "0" (int-to-string (1+ i)))
  5801. "]" (nth i efforts))))
  5802. (message "Effort%s: %s " effort-op effort-prompt)
  5803. (setq char (read-char-exclusive))
  5804. (when (or (< char ?0) (> char ?9))
  5805. (error "Need 1-9,0 to select effort" ))))
  5806. (when (equal char ?\t)
  5807. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5808. (org-set-local 'org-global-tags-completion-table
  5809. (org-global-tags-completion-table)))
  5810. (let ((completion-ignore-case t))
  5811. (setq tag (org-icompleting-read
  5812. "Tag: " org-global-tags-completion-table))))
  5813. (cond
  5814. ((equal char ?\r)
  5815. (org-agenda-filter-show-all-tag)
  5816. (when org-agenda-auto-exclude-function
  5817. (setq org-agenda-tag-filter '())
  5818. (dolist (tag (org-agenda-get-represented-tags))
  5819. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5820. (if modifier
  5821. (push modifier org-agenda-tag-filter))))
  5822. (if (not (null org-agenda-tag-filter))
  5823. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  5824. (setq maybe-refresh t))
  5825. ((equal char ?/)
  5826. (org-agenda-filter-show-all-tag)
  5827. (when (get 'org-agenda-tag-filter :preset-filter)
  5828. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  5829. (setq maybe-refresh t))
  5830. ((equal char ?. )
  5831. (setq org-agenda-tag-filter
  5832. (mapcar (lambda(tag) (concat "+" tag))
  5833. (org-get-at-bol 'tags)))
  5834. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5835. (setq maybe-refresh t))
  5836. ((or (equal char ?\ )
  5837. (setq a (rassoc char alist))
  5838. (and (>= char ?0) (<= char ?9)
  5839. (setq n (if (= char ?0) 9 (- char ?0 1))
  5840. tag (concat effort-op (nth n efforts))
  5841. a (cons tag nil)))
  5842. (and (= char ??)
  5843. (setq tag "?eff")
  5844. a (cons tag nil))
  5845. (and tag (setq a (cons tag nil))))
  5846. (org-agenda-filter-show-all-tag)
  5847. (setq tag (car a))
  5848. (setq org-agenda-tag-filter
  5849. (cons (concat (if strip "-" "+") tag)
  5850. (if narrow current nil)))
  5851. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  5852. (setq maybe-refresh t))
  5853. (t (error "Invalid tag selection character %c" char)))
  5854. (when (and maybe-refresh
  5855. (eq org-agenda-clockreport-mode 'with-filter))
  5856. (org-agenda-redo))))
  5857. (defun org-agenda-get-represented-tags ()
  5858. "Get a list of all tags currently represented in the agenda."
  5859. (let (p tags)
  5860. (save-excursion
  5861. (goto-char (point-min))
  5862. (while (setq p (next-single-property-change (point) 'tags))
  5863. (goto-char p)
  5864. (mapc (lambda (x) (add-to-list 'tags x))
  5865. (get-text-property (point) 'tags))))
  5866. tags))
  5867. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5868. "Refine the current filter. See `org-agenda-filter-by-tag'."
  5869. (interactive "P")
  5870. (org-agenda-filter-by-tag strip char 'refine))
  5871. (defun org-agenda-filter-make-matcher ()
  5872. "Create the form that tests a line for agenda filter."
  5873. (let (f f1)
  5874. ;; first compute the tag-filter matcher
  5875. (dolist (x (delete-dups
  5876. (append (get 'org-agenda-tag-filter
  5877. :preset-filter) org-agenda-tag-filter)))
  5878. (if (member x '("-" "+"))
  5879. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5880. (if (string-match "[<=>?]" x)
  5881. (setq f1 (org-agenda-filter-effort-form x))
  5882. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5883. (if (equal (string-to-char x) ?-)
  5884. (setq f1 (list 'not f1))))
  5885. (push f1 f))
  5886. ;; then compute the category-filter matcher
  5887. (dolist (x (delete-dups
  5888. (append (get 'org-agenda-category-filter
  5889. :preset-filter) org-agenda-category-filter)))
  5890. (setq f1 (list 'equal (substring x 1) 'cat))
  5891. (push f1 f))
  5892. (cons 'and (nreverse f))))
  5893. (defun org-agenda-filter-effort-form (e)
  5894. "Return the form to compare the effort of the current line with what E says.
  5895. E looks like \"+<2:25\"."
  5896. (let (op)
  5897. (setq e (substring e 1))
  5898. (setq op (string-to-char e) e (substring e 1))
  5899. (setq op (cond ((equal op ?<) '<=)
  5900. ((equal op ?>) '>=)
  5901. ((equal op ??) op)
  5902. (t '=)))
  5903. (list 'org-agenda-compare-effort (list 'quote op)
  5904. (org-duration-string-to-minutes e))))
  5905. (defun org-agenda-compare-effort (op value)
  5906. "Compare the effort of the current line with VALUE, using OP.
  5907. If the line does not have an effort defined, return nil."
  5908. (let ((eff (org-get-at-bol 'effort-minutes)))
  5909. (if (equal op ??)
  5910. (not eff)
  5911. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5912. value))))
  5913. (defun org-agenda-filter-apply (filter type)
  5914. "Set FILTER as the new agenda filter and apply it."
  5915. (let (tags cat)
  5916. (if (eq type 'tag)
  5917. (setq org-agenda-tag-filter filter)
  5918. (setq org-agenda-category-filter filter
  5919. org-agenda-filtered-by-category t))
  5920. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  5921. (org-agenda-set-mode-name)
  5922. (save-excursion
  5923. (goto-char (point-min))
  5924. (while (not (eobp))
  5925. (if (org-get-at-bol 'org-marker)
  5926. (progn
  5927. (setq tags (org-get-at-bol 'tags) ; used in eval
  5928. cat (get-text-property (point) 'org-category))
  5929. (if (not (eval org-agenda-filter-form))
  5930. (org-agenda-filter-hide-line type))
  5931. (beginning-of-line 2))
  5932. (beginning-of-line 2))))
  5933. (if (get-char-property (point) 'invisible)
  5934. (org-agenda-previous-line))))
  5935. (defun org-agenda-filter-hide-line (type)
  5936. (let (ov)
  5937. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5938. (point-at-eol)))
  5939. (overlay-put ov 'invisible t)
  5940. (overlay-put ov 'type type)
  5941. (if (eq type 'tag)
  5942. (push ov org-agenda-tag-filter-overlays)
  5943. (push ov org-agenda-cat-filter-overlays))))
  5944. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5945. (setq pos (or pos (point)))
  5946. (save-excursion
  5947. (dolist (ov (overlays-at pos))
  5948. (when (and (overlay-get ov 'invisible)
  5949. (eq (overlay-get ov 'type) 'tag))
  5950. (goto-char pos)
  5951. (if (< (overlay-start ov) (point-at-eol))
  5952. (move-overlay ov (point-at-eol)
  5953. (overlay-end ov)))))))
  5954. (defun org-agenda-filter-show-all-tag nil
  5955. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  5956. (setq org-agenda-tag-filter-overlays nil
  5957. org-agenda-tag-filter nil
  5958. org-agenda-filter-form nil)
  5959. (org-agenda-set-mode-name))
  5960. (defun org-agenda-filter-show-all-cat nil
  5961. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  5962. (setq org-agenda-cat-filter-overlays nil
  5963. org-agenda-filtered-by-category nil
  5964. org-agenda-category-filter nil
  5965. org-agenda-filter-form nil)
  5966. (org-agenda-set-mode-name))
  5967. (defun org-agenda-manipulate-query-add ()
  5968. "Manipulate the query by adding a search term with positive selection.
  5969. Positive selection means the term must be matched for selection of an entry."
  5970. (interactive)
  5971. (org-agenda-manipulate-query ?\[))
  5972. (defun org-agenda-manipulate-query-subtract ()
  5973. "Manipulate the query by adding a search term with negative selection.
  5974. Negative selection means term must not be matched for selection of an entry."
  5975. (interactive)
  5976. (org-agenda-manipulate-query ?\]))
  5977. (defun org-agenda-manipulate-query-add-re ()
  5978. "Manipulate the query by adding a search regexp with positive selection.
  5979. Positive selection means the regexp must match for selection of an entry."
  5980. (interactive)
  5981. (org-agenda-manipulate-query ?\{))
  5982. (defun org-agenda-manipulate-query-subtract-re ()
  5983. "Manipulate the query by adding a search regexp with negative selection.
  5984. Negative selection means regexp must not match for selection of an entry."
  5985. (interactive)
  5986. (org-agenda-manipulate-query ?\}))
  5987. (defun org-agenda-manipulate-query (char)
  5988. (cond
  5989. ((memq org-agenda-type '(timeline agenda))
  5990. (let ((org-agenda-include-inactive-timestamps t))
  5991. (org-agenda-redo))
  5992. (message "Display now includes inactive timestamps as well"))
  5993. ((eq org-agenda-type 'search)
  5994. (org-add-to-string
  5995. 'org-agenda-query-string
  5996. (if org-agenda-last-search-view-search-was-boolean
  5997. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5998. (?\{ . " +{}") (?\} . " -{}"))))
  5999. " "))
  6000. (setq org-agenda-redo-command
  6001. (list 'org-search-view
  6002. org-todo-only
  6003. org-agenda-query-string
  6004. (+ (length org-agenda-query-string)
  6005. (if (member char '(?\{ ?\})) 0 1))))
  6006. (set-register org-agenda-query-register org-agenda-query-string)
  6007. (org-agenda-redo))
  6008. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6009. org-agenda-type))))
  6010. (defun org-add-to-string (var string)
  6011. (set var (concat (symbol-value var) string)))
  6012. (defun org-agenda-goto-date (date)
  6013. "Jump to DATE in agenda."
  6014. (interactive (list (let ((org-read-date-prefer-future
  6015. (eval org-agenda-jump-prefer-future)))
  6016. (org-read-date))))
  6017. (org-agenda-list nil date))
  6018. (defun org-agenda-goto-today ()
  6019. "Go to today."
  6020. (interactive)
  6021. (org-agenda-check-type t 'timeline 'agenda)
  6022. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6023. (cond
  6024. (tdpos (goto-char tdpos))
  6025. ((eq org-agenda-type 'agenda)
  6026. (let* ((sd (org-agenda-compute-starting-span
  6027. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6028. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6029. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6030. (org-agenda-redo)
  6031. (org-agenda-find-same-or-today-or-agenda)))
  6032. (t (error "Cannot find today")))))
  6033. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6034. (goto-char
  6035. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6036. (text-property-any (point-min) (point-max) 'org-today t)
  6037. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6038. (point-min))))
  6039. (defun org-agenda-later (arg)
  6040. "Go forward in time by thee current span.
  6041. With prefix ARG, go forward that many times the current span."
  6042. (interactive "p")
  6043. (org-agenda-check-type t 'agenda)
  6044. (let* ((span org-agenda-current-span)
  6045. (sd org-starting-day)
  6046. (greg (calendar-gregorian-from-absolute sd))
  6047. (cnt (org-get-at-bol 'org-day-cnt))
  6048. greg2)
  6049. (cond
  6050. ((eq span 'day)
  6051. (setq sd (+ arg sd)))
  6052. ((eq span 'week)
  6053. (setq sd (+ (* 7 arg) sd)))
  6054. ((eq span 'month)
  6055. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6056. sd (calendar-absolute-from-gregorian greg2))
  6057. (setcar greg2 (1+ (car greg2))))
  6058. ((eq span 'year)
  6059. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6060. sd (calendar-absolute-from-gregorian greg2))
  6061. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6062. (t
  6063. (setq sd (+ (* span arg) sd))))
  6064. (let ((org-agenda-overriding-arguments
  6065. (list (car org-agenda-last-arguments) sd span t)))
  6066. (org-agenda-redo)
  6067. (org-agenda-find-same-or-today-or-agenda cnt))))
  6068. (defun org-agenda-earlier (arg)
  6069. "Go backward in time by the current span.
  6070. With prefix ARG, go backward that many times the current span."
  6071. (interactive "p")
  6072. (org-agenda-later (- arg)))
  6073. (defun org-agenda-view-mode-dispatch ()
  6074. "Call one of the view mode commands."
  6075. (interactive)
  6076. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6077. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6078. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6079. [E]ntryText")
  6080. (let ((a (read-char-exclusive)))
  6081. (case a
  6082. (?\ (call-interactively 'org-agenda-reset-view))
  6083. (?d (call-interactively 'org-agenda-day-view))
  6084. (?w (call-interactively 'org-agenda-week-view))
  6085. (?m (call-interactively 'org-agenda-month-view))
  6086. (?y (call-interactively 'org-agenda-year-view))
  6087. (?l (call-interactively 'org-agenda-log-mode))
  6088. (?L (org-agenda-log-mode '(4)))
  6089. (?c (org-agenda-log-mode 'clockcheck))
  6090. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6091. (?a (call-interactively 'org-agenda-archives-mode))
  6092. (?A (org-agenda-archives-mode 'files))
  6093. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6094. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6095. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6096. (?D (call-interactively 'org-agenda-toggle-diary))
  6097. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6098. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6099. (org-agenda-check-type t 'timeline 'agenda)
  6100. (org-agenda-redo))
  6101. (message "Display now includes inactive timestamps as well"))
  6102. (?q (message "Abort"))
  6103. (otherwise (error "Invalid key" )))))
  6104. (defun org-agenda-reset-view ()
  6105. "Switch to default view for agenda."
  6106. (interactive)
  6107. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6108. (defun org-agenda-day-view (&optional day-of-year)
  6109. "Switch to daily view for agenda.
  6110. With argument DAY-OF-YEAR, switch to that day of the year."
  6111. (interactive "P")
  6112. (org-agenda-change-time-span 'day day-of-year))
  6113. (defun org-agenda-week-view (&optional iso-week)
  6114. "Switch to daily view for agenda.
  6115. With argument ISO-WEEK, switch to the corresponding ISO week.
  6116. If ISO-WEEK has more then 2 digits, only the last two encode the
  6117. week. Any digits before this encode a year. So 200712 means
  6118. week 12 of year 2007. Years in the range 1938-2037 can also be
  6119. written as 2-digit years."
  6120. (interactive "P")
  6121. (org-agenda-change-time-span 'week iso-week))
  6122. (defun org-agenda-month-view (&optional month)
  6123. "Switch to monthly view for agenda.
  6124. With argument MONTH, switch to that month."
  6125. (interactive "P")
  6126. (org-agenda-change-time-span 'month month))
  6127. (defun org-agenda-year-view (&optional year)
  6128. "Switch to yearly view for agenda.
  6129. With argument YEAR, switch to that year.
  6130. If MONTH has more then 2 digits, only the last two encode the
  6131. month. Any digits before this encode a year. So 200712 means
  6132. December year 2007. Years in the range 1938-2037 can also be
  6133. written as 2-digit years."
  6134. (interactive "P")
  6135. (when year
  6136. (setq year (org-small-year-to-year year)))
  6137. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6138. (org-agenda-change-time-span 'year year)
  6139. (error "Abort")))
  6140. (defun org-agenda-change-time-span (span &optional n)
  6141. "Change the agenda view to SPAN.
  6142. SPAN may be `day', `week', `month', `year'."
  6143. (org-agenda-check-type t 'agenda)
  6144. (if (and (not n) (equal org-agenda-current-span span))
  6145. (error "Viewing span is already \"%s\"" span))
  6146. (let* ((sd (or (org-get-at-bol 'day)
  6147. org-starting-day))
  6148. (sd (org-agenda-compute-starting-span sd span n))
  6149. (org-agenda-overriding-arguments
  6150. (or org-agenda-overriding-arguments
  6151. (list (car org-agenda-last-arguments) sd span t))))
  6152. (org-agenda-redo)
  6153. (org-agenda-find-same-or-today-or-agenda))
  6154. (org-agenda-set-mode-name)
  6155. (message "Switched to %s view" span))
  6156. (defun org-agenda-compute-starting-span (sd span &optional n)
  6157. "Compute starting date for agenda.
  6158. SPAN may be `day', `week', `month', `year'. The return value
  6159. is a cons cell with the starting date and the number of days,
  6160. so that the date SD will be in that range."
  6161. (let* ((greg (calendar-gregorian-from-absolute sd))
  6162. (dg (nth 1 greg))
  6163. (mg (car greg))
  6164. (yg (nth 2 greg)))
  6165. (cond
  6166. ((eq span 'day)
  6167. (when n
  6168. (setq sd (+ (calendar-absolute-from-gregorian
  6169. (list mg 1 yg))
  6170. n -1))))
  6171. ((eq span 'week)
  6172. (let* ((nt (calendar-day-of-week
  6173. (calendar-gregorian-from-absolute sd)))
  6174. (d (if org-agenda-start-on-weekday
  6175. (- nt org-agenda-start-on-weekday)
  6176. 0))
  6177. y1)
  6178. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6179. (when n
  6180. (require 'cal-iso)
  6181. (when (> n 99)
  6182. (setq y1 (org-small-year-to-year (/ n 100))
  6183. n (mod n 100)))
  6184. (setq sd
  6185. (calendar-absolute-from-iso
  6186. (list n 1
  6187. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6188. ((eq span 'month)
  6189. (let (y1)
  6190. (when (and n (> n 99))
  6191. (setq y1 (org-small-year-to-year (/ n 100))
  6192. n (mod n 100)))
  6193. (setq sd (calendar-absolute-from-gregorian
  6194. (list (or n mg) 1 (or y1 yg))))))
  6195. ((eq span 'year)
  6196. (setq sd (calendar-absolute-from-gregorian
  6197. (list 1 1 (or n yg))))))
  6198. sd))
  6199. (defun org-agenda-next-date-line (&optional arg)
  6200. "Jump to the next line indicating a date in agenda buffer."
  6201. (interactive "p")
  6202. (org-agenda-check-type t 'agenda 'timeline)
  6203. (beginning-of-line 1)
  6204. ;; This does not work if user makes date format that starts with a blank
  6205. (if (looking-at "^\\S-") (forward-char 1))
  6206. (if (not (re-search-forward "^\\S-" nil t arg))
  6207. (progn
  6208. (backward-char 1)
  6209. (error "No next date after this line in this buffer")))
  6210. (goto-char (match-beginning 0)))
  6211. (defun org-agenda-previous-date-line (&optional arg)
  6212. "Jump to the previous line indicating a date in agenda buffer."
  6213. (interactive "p")
  6214. (org-agenda-check-type t 'agenda 'timeline)
  6215. (beginning-of-line 1)
  6216. (if (not (re-search-backward "^\\S-" nil t arg))
  6217. (error "No previous date before this line in this buffer")))
  6218. ;; Initialize the highlight
  6219. (defvar org-hl (make-overlay 1 1))
  6220. (overlay-put org-hl 'face 'highlight)
  6221. (defun org-highlight (begin end &optional buffer)
  6222. "Highlight a region with overlay."
  6223. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6224. (defun org-unhighlight ()
  6225. "Detach overlay INDEX."
  6226. (org-detach-overlay org-hl))
  6227. ;; FIXME this is currently not used.
  6228. (defun org-highlight-until-next-command (beg end &optional buffer)
  6229. "Move the highlight overlay to BEG/END, remove it before the next command."
  6230. (org-highlight beg end buffer)
  6231. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6232. (defun org-unhighlight-once ()
  6233. "Remove the highlight from its position, and this function from the hook."
  6234. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6235. (org-unhighlight))
  6236. (defun org-agenda-follow-mode ()
  6237. "Toggle follow mode in an agenda buffer."
  6238. (interactive)
  6239. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6240. (org-agenda-set-mode-name)
  6241. (org-agenda-do-context-action)
  6242. (message "Follow mode is %s"
  6243. (if org-agenda-follow-mode "on" "off")))
  6244. (defun org-agenda-entry-text-mode (&optional arg)
  6245. "Toggle entry text mode in an agenda buffer."
  6246. (interactive "P")
  6247. (setq org-agenda-entry-text-mode (or (integerp arg)
  6248. (not org-agenda-entry-text-mode)))
  6249. (org-agenda-entry-text-hide)
  6250. (and org-agenda-entry-text-mode
  6251. (let ((org-agenda-entry-text-maxlines
  6252. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6253. (org-agenda-entry-text-show)))
  6254. (org-agenda-set-mode-name)
  6255. (message "Entry text mode is %s. Maximum number of lines is %d"
  6256. (if org-agenda-entry-text-mode "on" "off")
  6257. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6258. (defun org-agenda-clockreport-mode (&optional with-filter)
  6259. "Toggle clocktable mode in an agenda buffer.
  6260. With prefix arg WITH-FILTER, make the clocktable respect the current
  6261. agenda filter."
  6262. (interactive "P")
  6263. (org-agenda-check-type t 'agenda)
  6264. (if with-filter
  6265. (setq org-agenda-clockreport-mode 'with-filter)
  6266. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6267. (org-agenda-set-mode-name)
  6268. (org-agenda-redo)
  6269. (message "Clocktable mode is %s"
  6270. (if org-agenda-clockreport-mode "on" "off")))
  6271. (defun org-agenda-log-mode (&optional special)
  6272. "Toggle log mode in an agenda buffer.
  6273. With argument SPECIAL, show all possible log items, not only the ones
  6274. configured in `org-agenda-log-mode-items'.
  6275. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6276. (interactive "P")
  6277. (org-agenda-check-type t 'agenda 'timeline)
  6278. (setq org-agenda-show-log
  6279. (cond
  6280. ((equal special '(16)) 'only)
  6281. ((eq special 'clockcheck)
  6282. (if (eq org-agenda-show-log 'clockcheck)
  6283. nil 'clockcheck))
  6284. (special '(closed clock state))
  6285. (t (not org-agenda-show-log))))
  6286. (org-agenda-set-mode-name)
  6287. (org-agenda-redo)
  6288. (message "Log mode is %s"
  6289. (if org-agenda-show-log "on" "off")))
  6290. (defun org-agenda-archives-mode (&optional with-files)
  6291. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6292. When called with a prefix argument, include all archive files as well."
  6293. (interactive "P")
  6294. (setq org-agenda-archives-mode
  6295. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6296. (org-agenda-set-mode-name)
  6297. (org-agenda-redo)
  6298. (message
  6299. "%s"
  6300. (cond
  6301. ((eq org-agenda-archives-mode nil)
  6302. "No archives are included")
  6303. ((eq org-agenda-archives-mode 'trees)
  6304. (format "Trees with :%s: tag are included" org-archive-tag))
  6305. ((eq org-agenda-archives-mode t)
  6306. (format "Trees with :%s: tag and all active archive files are included"
  6307. org-archive-tag)))))
  6308. (defun org-agenda-toggle-diary ()
  6309. "Toggle diary inclusion in an agenda buffer."
  6310. (interactive)
  6311. (org-agenda-check-type t 'agenda)
  6312. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6313. (org-agenda-redo)
  6314. (org-agenda-set-mode-name)
  6315. (message "Diary inclusion turned %s"
  6316. (if org-agenda-include-diary "on" "off")))
  6317. (defun org-agenda-toggle-deadlines ()
  6318. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6319. (interactive)
  6320. (org-agenda-check-type t 'agenda)
  6321. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6322. (org-agenda-redo)
  6323. (org-agenda-set-mode-name)
  6324. (message "Deadlines inclusion turned %s"
  6325. (if org-agenda-include-deadlines "on" "off")))
  6326. (defun org-agenda-toggle-time-grid ()
  6327. "Toggle time grid in an agenda buffer."
  6328. (interactive)
  6329. (org-agenda-check-type t 'agenda)
  6330. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6331. (org-agenda-redo)
  6332. (org-agenda-set-mode-name)
  6333. (message "Time-grid turned %s"
  6334. (if org-agenda-use-time-grid "on" "off")))
  6335. (defun org-agenda-set-mode-name ()
  6336. "Set the mode name to indicate all the small mode settings."
  6337. (setq mode-name
  6338. (list "Org-Agenda"
  6339. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6340. " "
  6341. '(:eval (org-agenda-span-name org-agenda-current-span))
  6342. (if org-agenda-follow-mode " Follow" "")
  6343. (if org-agenda-entry-text-mode " ETxt" "")
  6344. (if org-agenda-include-diary " Diary" "")
  6345. (if org-agenda-include-deadlines " Ddl" "")
  6346. (if org-agenda-use-time-grid " Grid" "")
  6347. (if (and (boundp 'org-habit-show-habits)
  6348. org-habit-show-habits) " Habit" "")
  6349. (cond
  6350. ((consp org-agenda-show-log) " LogAll")
  6351. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6352. (org-agenda-show-log " Log")
  6353. (t ""))
  6354. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6355. :preset-filter))
  6356. '(:eval (org-propertize
  6357. (concat " <"
  6358. (mapconcat
  6359. 'identity
  6360. (append
  6361. (get 'org-agenda-category-filter :preset-filter)
  6362. org-agenda-category-filter)
  6363. "")
  6364. ">")
  6365. 'face 'org-agenda-filter-category
  6366. 'help-echo "Category used in filtering"))
  6367. "")
  6368. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6369. :preset-filter))
  6370. '(:eval (org-propertize
  6371. (concat " {"
  6372. (mapconcat
  6373. 'identity
  6374. (append
  6375. (get 'org-agenda-tag-filter :preset-filter)
  6376. org-agenda-tag-filter)
  6377. "")
  6378. "}")
  6379. 'face 'org-agenda-filter-tags
  6380. 'help-echo "Tags used in filtering"))
  6381. "")
  6382. (if org-agenda-archives-mode
  6383. (if (eq org-agenda-archives-mode t)
  6384. " Archives"
  6385. (format " :%s:" org-archive-tag))
  6386. "")
  6387. (if org-agenda-clockreport-mode
  6388. (if (eq org-agenda-clockreport-mode 'with-filter)
  6389. " Clock{}" " Clock")
  6390. "")))
  6391. (force-mode-line-update))
  6392. (defun org-agenda-post-command-hook ()
  6393. (setq org-agenda-type
  6394. (or (get-text-property (point) 'org-agenda-type)
  6395. (get-text-property (max (point-min) (1- (point)))
  6396. 'org-agenda-type))))
  6397. (defun org-agenda-next-line ()
  6398. "Move cursor to the next line, and show if follow mode is active."
  6399. (interactive)
  6400. (call-interactively 'next-line)
  6401. (org-agenda-do-context-action))
  6402. (defun org-agenda-previous-line ()
  6403. "Move cursor to the previous line, and show if follow-mode is active."
  6404. (interactive)
  6405. (call-interactively 'previous-line)
  6406. (org-agenda-do-context-action))
  6407. (defun org-agenda-do-context-action ()
  6408. "Show outline path and, maybe, follow mode window."
  6409. (let ((m (org-get-at-bol 'org-marker)))
  6410. (when (and (markerp m) (marker-buffer m))
  6411. (and org-agenda-follow-mode
  6412. (if org-agenda-follow-indirect
  6413. (org-agenda-tree-to-indirect-buffer)
  6414. (org-agenda-show)))
  6415. (and org-agenda-show-outline-path
  6416. (org-with-point-at m (org-display-outline-path t))))))
  6417. (defun org-agenda-show-priority ()
  6418. "Show the priority of the current item.
  6419. This priority is composed of the main priority given with the [#A] cookies,
  6420. and by additional input from the age of a schedules or deadline entry."
  6421. (interactive)
  6422. (let* ((pri (org-get-at-bol 'priority)))
  6423. (message "Priority is %d" (if pri pri -1000))))
  6424. (defun org-agenda-show-tags ()
  6425. "Show the tags applicable to the current item."
  6426. (interactive)
  6427. (let* ((tags (org-get-at-bol 'tags)))
  6428. (if tags
  6429. (message "Tags are :%s:"
  6430. (org-no-properties (mapconcat 'identity tags ":")))
  6431. (message "No tags associated with this line"))))
  6432. (defun org-agenda-goto (&optional highlight)
  6433. "Go to the Org-mode file which contains the item at point."
  6434. (interactive)
  6435. (let* ((marker (or (org-get-at-bol 'org-marker)
  6436. (org-agenda-error)))
  6437. (buffer (marker-buffer marker))
  6438. (pos (marker-position marker)))
  6439. (switch-to-buffer-other-window buffer)
  6440. (widen)
  6441. (push-mark)
  6442. (goto-char pos)
  6443. (when (eq major-mode 'org-mode)
  6444. (org-show-context 'agenda)
  6445. (save-excursion
  6446. (and (outline-next-heading)
  6447. (org-flag-heading nil)))) ; show the next heading
  6448. (when (outline-invisible-p)
  6449. (show-entry)) ; display invisible text
  6450. (recenter (/ (window-height) 2))
  6451. (run-hooks 'org-agenda-after-show-hook)
  6452. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6453. (defvar org-agenda-after-show-hook nil
  6454. "Normal hook run after an item has been shown from the agenda.
  6455. Point is in the buffer where the item originated.")
  6456. (defun org-agenda-kill ()
  6457. "Kill the entry or subtree belonging to the current agenda entry."
  6458. (interactive)
  6459. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6460. (let* ((marker (or (org-get-at-bol 'org-marker)
  6461. (org-agenda-error)))
  6462. (buffer (marker-buffer marker))
  6463. (pos (marker-position marker))
  6464. (type (org-get-at-bol 'type))
  6465. dbeg dend (n 0) conf)
  6466. (org-with-remote-undo buffer
  6467. (with-current-buffer buffer
  6468. (save-excursion
  6469. (goto-char pos)
  6470. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6471. (setq dbeg (progn (org-back-to-heading t) (point))
  6472. dend (org-end-of-subtree t t))
  6473. (setq dbeg (point-at-bol)
  6474. dend (min (point-max) (1+ (point-at-eol)))))
  6475. (goto-char dbeg)
  6476. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6477. (setq conf (or (eq t org-agenda-confirm-kill)
  6478. (and (numberp org-agenda-confirm-kill)
  6479. (> n org-agenda-confirm-kill))))
  6480. (and conf
  6481. (not (y-or-n-p
  6482. (format "Delete entry with %d lines in buffer \"%s\"? "
  6483. n (buffer-name buffer))))
  6484. (error "Abort"))
  6485. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6486. (with-current-buffer buffer (delete-region dbeg dend))
  6487. (message "Agenda item and source killed"))))
  6488. (defvar org-archive-default-command)
  6489. (defun org-agenda-archive-default ()
  6490. "Archive the entry or subtree belonging to the current agenda entry."
  6491. (interactive)
  6492. (require 'org-archive)
  6493. (org-agenda-archive-with org-archive-default-command))
  6494. (defun org-agenda-archive-default-with-confirmation ()
  6495. "Archive the entry or subtree belonging to the current agenda entry."
  6496. (interactive)
  6497. (require 'org-archive)
  6498. (org-agenda-archive-with org-archive-default-command 'confirm))
  6499. (defun org-agenda-archive ()
  6500. "Archive the entry or subtree belonging to the current agenda entry."
  6501. (interactive)
  6502. (org-agenda-archive-with 'org-archive-subtree))
  6503. (defun org-agenda-archive-to-archive-sibling ()
  6504. "Move the entry to the archive sibling."
  6505. (interactive)
  6506. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6507. (defun org-agenda-archive-with (cmd &optional confirm)
  6508. "Move the entry to the archive sibling."
  6509. (interactive)
  6510. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6511. (let* ((marker (or (org-get-at-bol 'org-marker)
  6512. (org-agenda-error)))
  6513. (buffer (marker-buffer marker))
  6514. (pos (marker-position marker)))
  6515. (org-with-remote-undo buffer
  6516. (with-current-buffer buffer
  6517. (if (eq major-mode 'org-mode)
  6518. (if (and confirm
  6519. (not (y-or-n-p "Archive this subtree or entry? ")))
  6520. (error "Abort")
  6521. (save-excursion
  6522. (goto-char pos)
  6523. (org-remove-subtree-entries-from-agenda)
  6524. (org-back-to-heading t)
  6525. (funcall cmd)))
  6526. (error "Archiving works only in Org-mode files"))))))
  6527. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6528. "Remove all lines in the agenda that correspond to a given subtree.
  6529. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6530. If this information is not given, the function uses the tree at point."
  6531. (let ((buf (or buf (current-buffer))) m p)
  6532. (save-excursion
  6533. (unless (and beg end)
  6534. (org-back-to-heading t)
  6535. (setq beg (point))
  6536. (org-end-of-subtree t)
  6537. (setq end (point)))
  6538. (set-buffer (get-buffer org-agenda-buffer-name))
  6539. (save-excursion
  6540. (goto-char (point-max))
  6541. (beginning-of-line 1)
  6542. (while (not (bobp))
  6543. (when (and (setq m (org-get-at-bol 'org-marker))
  6544. (equal buf (marker-buffer m))
  6545. (setq p (marker-position m))
  6546. (>= p beg)
  6547. (< p end))
  6548. (let ((inhibit-read-only t))
  6549. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6550. (beginning-of-line 0))))))
  6551. (defun org-agenda-refile (&optional goto rfloc no-update)
  6552. "Refile the item at point."
  6553. (interactive "P")
  6554. (if (equal goto '(16))
  6555. (org-refile-goto-last-stored)
  6556. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6557. (org-agenda-error)))
  6558. (buffer (marker-buffer marker))
  6559. (pos (marker-position marker))
  6560. (rfloc (or rfloc
  6561. (org-refile-get-location
  6562. (if goto "Goto" "Refile to") buffer
  6563. org-refile-allow-creating-parent-nodes))))
  6564. (with-current-buffer buffer
  6565. (save-excursion
  6566. (save-restriction
  6567. (widen)
  6568. (goto-char marker)
  6569. (org-remove-subtree-entries-from-agenda)
  6570. (org-refile goto buffer rfloc)))))
  6571. (unless no-update (org-agenda-redo))))
  6572. (defun org-agenda-open-link (&optional arg)
  6573. "Follow the link in the current line, if any.
  6574. This looks for a link in the displayed line in the agenda. It also looks
  6575. at the text of the entry itself."
  6576. (interactive "P")
  6577. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6578. (org-get-at-bol 'org-marker)))
  6579. (buffer (and marker (marker-buffer marker)))
  6580. (prefix (buffer-substring
  6581. (point-at-bol) (point-at-eol))))
  6582. (cond
  6583. (buffer
  6584. (with-current-buffer buffer
  6585. (save-excursion
  6586. (save-restriction
  6587. (widen)
  6588. (goto-char marker)
  6589. (org-offer-links-in-entry arg prefix)))))
  6590. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6591. (save-excursion
  6592. (beginning-of-line 1)
  6593. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6594. (org-open-link-from-string (match-string 1)))
  6595. (t (error "No link to open here")))))
  6596. (defun org-agenda-copy-local-variable (var)
  6597. "Get a variable from a referenced buffer and install it here."
  6598. (let ((m (org-get-at-bol 'org-marker)))
  6599. (when (and m (buffer-live-p (marker-buffer m)))
  6600. (org-set-local var (with-current-buffer (marker-buffer m)
  6601. (symbol-value var))))))
  6602. (defun org-agenda-switch-to (&optional delete-other-windows)
  6603. "Go to the Org-mode file which contains the item at point."
  6604. (interactive)
  6605. (if (and org-return-follows-link
  6606. (not (org-get-at-bol 'org-marker))
  6607. (org-in-regexp org-bracket-link-regexp))
  6608. (org-open-link-from-string (match-string 0))
  6609. (let* ((marker (or (org-get-at-bol 'org-marker)
  6610. (org-agenda-error)))
  6611. (buffer (marker-buffer marker))
  6612. (pos (marker-position marker)))
  6613. (org-pop-to-buffer-same-window buffer)
  6614. (and delete-other-windows (delete-other-windows))
  6615. (widen)
  6616. (goto-char pos)
  6617. (when (eq major-mode 'org-mode)
  6618. (org-show-context 'agenda)
  6619. (save-excursion
  6620. (and (outline-next-heading)
  6621. (org-flag-heading nil))) ; show the next heading
  6622. (when (outline-invisible-p)
  6623. (show-entry)))))) ; display invisible text
  6624. (defun org-agenda-goto-mouse (ev)
  6625. "Go to the Org-mode file which contains the item at the mouse click."
  6626. (interactive "e")
  6627. (mouse-set-point ev)
  6628. (org-agenda-goto))
  6629. (defun org-agenda-show (&optional full-entry)
  6630. "Display the Org-mode file which contains the item at point.
  6631. With prefix argument FULL-ENTRY, make the entire entry visible
  6632. if it was hidden in the outline."
  6633. (interactive "P")
  6634. (let ((win (selected-window)))
  6635. (if full-entry
  6636. (let ((org-show-entry-below t))
  6637. (org-agenda-goto t))
  6638. (org-agenda-goto t))
  6639. (select-window win)))
  6640. (defvar org-agenda-show-window nil)
  6641. (defun org-agenda-show-and-scroll-up (&optional arg)
  6642. "Display the Org-mode file which contains the item at point.
  6643. When called repeatedly, scroll the window that is displaying the buffer.
  6644. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6645. `show-subtree' to display the item, so that drawers and logbooks stay
  6646. folded."
  6647. (interactive "P")
  6648. (let ((win (selected-window)))
  6649. (if (and (window-live-p org-agenda-show-window)
  6650. (eq this-command last-command))
  6651. (progn
  6652. (select-window org-agenda-show-window)
  6653. (ignore-errors (scroll-up)))
  6654. (org-agenda-goto t)
  6655. (if arg (org-show-entry) (show-subtree))
  6656. (setq org-agenda-show-window (selected-window)))
  6657. (select-window win)))
  6658. (defun org-agenda-show-scroll-down ()
  6659. "Scroll down the window showing the agenda."
  6660. (interactive)
  6661. (let ((win (selected-window)))
  6662. (when (window-live-p org-agenda-show-window)
  6663. (select-window org-agenda-show-window)
  6664. (ignore-errors (scroll-down))
  6665. (select-window win))))
  6666. (defun org-agenda-show-1 (&optional more)
  6667. "Display the Org-mode file which contains the item at point.
  6668. The prefix arg selects the amount of information to display:
  6669. 0 hide the subtree
  6670. 1 just show the entry according to defaults.
  6671. 2 show the children view
  6672. 3 show the subtree view
  6673. 4 show the entire subtree and any LOGBOOK drawers
  6674. 5 show the entire subtree and any drawers
  6675. With prefix argument FULL-ENTRY, make the entire entry visible
  6676. if it was hidden in the outline."
  6677. (interactive "p")
  6678. (let ((win (selected-window)))
  6679. (org-agenda-goto t)
  6680. (org-recenter-heading 1)
  6681. (cond
  6682. ((= more 0)
  6683. (hide-subtree)
  6684. (save-excursion
  6685. (org-back-to-heading)
  6686. (run-hook-with-args 'org-cycle-hook 'folded))
  6687. (message "Remote: FOLDED"))
  6688. ((and (org-called-interactively-p 'any) (= more 1))
  6689. (message "Remote: show with default settings"))
  6690. ((= more 2)
  6691. (show-entry)
  6692. (show-children)
  6693. (save-excursion
  6694. (org-back-to-heading)
  6695. (run-hook-with-args 'org-cycle-hook 'children))
  6696. (message "Remote: CHILDREN"))
  6697. ((= more 3)
  6698. (show-subtree)
  6699. (save-excursion
  6700. (org-back-to-heading)
  6701. (run-hook-with-args 'org-cycle-hook 'subtree))
  6702. (message "Remote: SUBTREE"))
  6703. ((= more 4)
  6704. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6705. (org-drawer-regexp
  6706. (concat "^[ \t]*:\\("
  6707. (mapconcat 'regexp-quote org-drawers "\\|")
  6708. "\\):[ \t]*$")))
  6709. (show-subtree)
  6710. (save-excursion
  6711. (org-back-to-heading)
  6712. (org-cycle-hide-drawers 'subtree)))
  6713. (message "Remote: SUBTREE AND LOGBOOK"))
  6714. ((> more 4)
  6715. (show-subtree)
  6716. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6717. (select-window win)))
  6718. (defun org-recenter-heading (n)
  6719. (save-excursion
  6720. (org-back-to-heading)
  6721. (recenter n)))
  6722. (defvar org-agenda-cycle-counter nil)
  6723. (defun org-agenda-cycle-show (&optional n)
  6724. "Show the current entry in another window, with default settings.
  6725. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6726. When use repeatedly in immediate succession, the remote entry will cycle
  6727. through visibility
  6728. children -> subtree -> folded
  6729. When called with a numeric prefix arg, that arg will be passed through to
  6730. `org-agenda-show-1'. For the interpretation of that argument, see the
  6731. docstring of `org-agenda-show-1'."
  6732. (interactive "P")
  6733. (if (integerp n)
  6734. (setq org-agenda-cycle-counter n)
  6735. (if (not (eq last-command this-command))
  6736. (setq org-agenda-cycle-counter 1)
  6737. (if (equal org-agenda-cycle-counter 0)
  6738. (setq org-agenda-cycle-counter 2)
  6739. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6740. (if (> org-agenda-cycle-counter 3)
  6741. (setq org-agenda-cycle-counter 0)))))
  6742. (org-agenda-show-1 org-agenda-cycle-counter))
  6743. (defun org-agenda-recenter (arg)
  6744. "Display the Org-mode file which contains the item at point and recenter."
  6745. (interactive "P")
  6746. (let ((win (selected-window)))
  6747. (org-agenda-goto t)
  6748. (recenter arg)
  6749. (select-window win)))
  6750. (defun org-agenda-show-mouse (ev)
  6751. "Display the Org-mode file which contains the item at the mouse click."
  6752. (interactive "e")
  6753. (mouse-set-point ev)
  6754. (org-agenda-show))
  6755. (defun org-agenda-check-no-diary ()
  6756. "Check if the entry is a diary link and abort if yes."
  6757. (if (org-get-at-bol 'org-agenda-diary-link)
  6758. (org-agenda-error)))
  6759. (defun org-agenda-error ()
  6760. (error "Command not allowed in this line"))
  6761. (defun org-agenda-tree-to-indirect-buffer ()
  6762. "Show the subtree corresponding to the current entry in an indirect buffer.
  6763. This calls the command `org-tree-to-indirect-buffer' from the original
  6764. Org-mode buffer.
  6765. With numerical prefix arg ARG, go up to this level and then take that tree.
  6766. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6767. use the dedicated frame)."
  6768. (interactive)
  6769. (if (and current-prefix-arg (listp current-prefix-arg))
  6770. (org-agenda-do-tree-to-indirect-buffer)
  6771. (let ((agenda-window (selected-window))
  6772. (indirect-window (get-buffer-window org-last-indirect-buffer)))
  6773. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  6774. (unwind-protect
  6775. (progn
  6776. (unless indirect-window
  6777. (setq indirect-window (split-window agenda-window)))
  6778. (select-window indirect-window)
  6779. (switch-to-buffer org-last-indirect-buffer :norecord)
  6780. (fit-window-to-buffer indirect-window))
  6781. (select-window agenda-window)))))
  6782. (defun org-agenda-do-tree-to-indirect-buffer ()
  6783. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  6784. (org-agenda-check-no-diary)
  6785. (let* ((marker (or (org-get-at-bol 'org-marker)
  6786. (org-agenda-error)))
  6787. (buffer (marker-buffer marker))
  6788. (pos (marker-position marker)))
  6789. (with-current-buffer buffer
  6790. (save-excursion
  6791. (goto-char pos)
  6792. (call-interactively 'org-tree-to-indirect-buffer)))))
  6793. (defvar org-last-heading-marker (make-marker)
  6794. "Marker pointing to the headline that last changed its TODO state
  6795. by a remote command from the agenda.")
  6796. (defun org-agenda-todo-nextset ()
  6797. "Switch TODO entry to next sequence."
  6798. (interactive)
  6799. (org-agenda-todo 'nextset))
  6800. (defun org-agenda-todo-previousset ()
  6801. "Switch TODO entry to previous sequence."
  6802. (interactive)
  6803. (org-agenda-todo 'previousset))
  6804. (defun org-agenda-todo (&optional arg)
  6805. "Cycle TODO state of line at point, also in Org-mode file.
  6806. This changes the line at point, all other lines in the agenda referring to
  6807. the same tree node, and the headline of the tree node in the Org-mode file."
  6808. (interactive "P")
  6809. (org-agenda-check-no-diary)
  6810. (let* ((col (current-column))
  6811. (marker (or (org-get-at-bol 'org-marker)
  6812. (org-agenda-error)))
  6813. (buffer (marker-buffer marker))
  6814. (pos (marker-position marker))
  6815. (hdmarker (org-get-at-bol 'org-hd-marker))
  6816. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6817. (inhibit-read-only t)
  6818. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6819. (org-with-remote-undo buffer
  6820. (with-current-buffer buffer
  6821. (widen)
  6822. (goto-char pos)
  6823. (org-show-context 'agenda)
  6824. (save-excursion
  6825. (and (outline-next-heading)
  6826. (org-flag-heading nil))) ; show the next heading
  6827. (let ((current-prefix-arg arg))
  6828. (call-interactively 'org-todo))
  6829. (and (bolp) (forward-char 1))
  6830. (setq newhead (org-get-heading))
  6831. (when (and (org-bound-and-true-p
  6832. org-agenda-headline-snapshot-before-repeat)
  6833. (not (equal org-agenda-headline-snapshot-before-repeat
  6834. newhead))
  6835. todayp)
  6836. (setq newhead org-agenda-headline-snapshot-before-repeat
  6837. just-one t))
  6838. (save-excursion
  6839. (org-back-to-heading)
  6840. (move-marker org-last-heading-marker (point))))
  6841. (beginning-of-line 1)
  6842. (save-excursion
  6843. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6844. (org-move-to-column col))))
  6845. (defun org-agenda-add-note (&optional arg)
  6846. "Add a time-stamped note to the entry at point."
  6847. (interactive "P")
  6848. (org-agenda-check-no-diary)
  6849. (let* ((marker (or (org-get-at-bol 'org-marker)
  6850. (org-agenda-error)))
  6851. (buffer (marker-buffer marker))
  6852. (pos (marker-position marker))
  6853. (hdmarker (org-get-at-bol 'org-hd-marker))
  6854. (inhibit-read-only t))
  6855. (with-current-buffer buffer
  6856. (widen)
  6857. (goto-char pos)
  6858. (org-show-context 'agenda)
  6859. (save-excursion
  6860. (and (outline-next-heading)
  6861. (org-flag-heading nil))) ; show the next heading
  6862. (org-add-note))))
  6863. (defun org-agenda-change-all-lines (newhead hdmarker
  6864. &optional fixface just-this)
  6865. "Change all lines in the agenda buffer which match HDMARKER.
  6866. The new content of the line will be NEWHEAD (as modified by
  6867. `org-agenda-format-item'). HDMARKER is checked with
  6868. `equal' against all `org-hd-marker' text properties in the file.
  6869. If FIXFACE is non-nil, the face of each item is modified according to
  6870. the new TODO state.
  6871. If JUST-THIS is non-nil, change just the current line, not all.
  6872. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6873. (let* ((inhibit-read-only t)
  6874. (line (org-current-line))
  6875. (thetags (with-current-buffer (marker-buffer hdmarker)
  6876. (save-excursion (save-restriction (widen)
  6877. (goto-char hdmarker)
  6878. (org-get-tags-at)))))
  6879. props m pl undone-face done-face finish new dotime cat tags)
  6880. (save-excursion
  6881. (goto-char (point-max))
  6882. (beginning-of-line 1)
  6883. (while (not finish)
  6884. (setq finish (bobp))
  6885. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6886. (or (not just-this) (= (org-current-line) line))
  6887. (equal m hdmarker))
  6888. (setq props (text-properties-at (point))
  6889. dotime (org-get-at-bol 'dotime)
  6890. cat (org-get-at-bol 'org-category)
  6891. tags thetags
  6892. new
  6893. (let ((org-prefix-format-compiled
  6894. (or (get-text-property (point) 'format)
  6895. org-prefix-format-compiled)))
  6896. (with-current-buffer (marker-buffer hdmarker)
  6897. (save-excursion
  6898. (save-restriction
  6899. (widen)
  6900. (org-agenda-format-item (org-get-at-bol 'extra)
  6901. newhead cat tags dotime)))))
  6902. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6903. undone-face (org-get-at-bol 'undone-face)
  6904. done-face (org-get-at-bol 'done-face))
  6905. (beginning-of-line 1)
  6906. (cond
  6907. ((equal new "")
  6908. (and (looking-at ".*\n?") (replace-match "")))
  6909. ((looking-at ".*")
  6910. (replace-match new t t)
  6911. (beginning-of-line 1)
  6912. (add-text-properties (point-at-bol) (point-at-eol) props)
  6913. (when fixface
  6914. (add-text-properties
  6915. (point-at-bol) (point-at-eol)
  6916. (list 'face
  6917. (if org-last-todo-state-is-todo
  6918. undone-face done-face))))
  6919. (org-agenda-highlight-todo 'line)
  6920. (beginning-of-line 1))
  6921. (t (error "Line update did not work"))))
  6922. (beginning-of-line 0)))
  6923. (org-finalize-agenda)))
  6924. (defun org-agenda-align-tags (&optional line)
  6925. "Align all tags in agenda items to `org-agenda-tags-column'."
  6926. (let ((inhibit-read-only t) l c)
  6927. (save-excursion
  6928. (goto-char (if line (point-at-bol) (point-min)))
  6929. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6930. (if line (point-at-eol) nil) t)
  6931. (add-text-properties
  6932. (match-beginning 2) (match-end 2)
  6933. (list 'face (delq nil (let ((prop (get-text-property
  6934. (match-beginning 2) 'face)))
  6935. (or (listp prop) (setq prop (list prop)))
  6936. (if (memq 'org-tag prop)
  6937. prop
  6938. (cons 'org-tag prop))))))
  6939. (setq l (- (match-end 2) (match-beginning 2))
  6940. c (if (< org-agenda-tags-column 0)
  6941. (- (abs org-agenda-tags-column) l)
  6942. org-agenda-tags-column))
  6943. (delete-region (match-beginning 1) (match-end 1))
  6944. (goto-char (match-beginning 1))
  6945. (insert (org-add-props
  6946. (make-string (max 1 (- c (current-column))) ?\ )
  6947. (plist-put (copy-sequence (text-properties-at (point)))
  6948. 'face nil))))
  6949. (goto-char (point-min))
  6950. (org-font-lock-add-tag-faces (point-max)))))
  6951. (defun org-agenda-priority-up ()
  6952. "Increase the priority of line at point, also in Org-mode file."
  6953. (interactive)
  6954. (org-agenda-priority 'up))
  6955. (defun org-agenda-priority-down ()
  6956. "Decrease the priority of line at point, also in Org-mode file."
  6957. (interactive)
  6958. (org-agenda-priority 'down))
  6959. (defun org-agenda-priority (&optional force-direction)
  6960. "Set the priority of line at point, also in Org-mode file.
  6961. This changes the line at point, all other lines in the agenda referring to
  6962. the same tree node, and the headline of the tree node in the Org-mode file."
  6963. (interactive)
  6964. (unless org-enable-priority-commands
  6965. (error "Priority commands are disabled"))
  6966. (org-agenda-check-no-diary)
  6967. (let* ((marker (or (org-get-at-bol 'org-marker)
  6968. (org-agenda-error)))
  6969. (hdmarker (org-get-at-bol 'org-hd-marker))
  6970. (buffer (marker-buffer hdmarker))
  6971. (pos (marker-position hdmarker))
  6972. (inhibit-read-only t)
  6973. newhead)
  6974. (org-with-remote-undo buffer
  6975. (with-current-buffer buffer
  6976. (widen)
  6977. (goto-char pos)
  6978. (org-show-context 'agenda)
  6979. (save-excursion
  6980. (and (outline-next-heading)
  6981. (org-flag-heading nil))) ; show the next heading
  6982. (funcall 'org-priority force-direction)
  6983. (end-of-line 1)
  6984. (setq newhead (org-get-heading)))
  6985. (org-agenda-change-all-lines newhead hdmarker)
  6986. (beginning-of-line 1))))
  6987. ;; FIXME: should fix the tags property of the agenda line.
  6988. (defun org-agenda-set-tags (&optional tag onoff)
  6989. "Set tags for the current headline."
  6990. (interactive)
  6991. (org-agenda-check-no-diary)
  6992. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6993. (call-interactively 'org-change-tag-in-region)
  6994. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6995. (org-agenda-error)))
  6996. (buffer (marker-buffer hdmarker))
  6997. (pos (marker-position hdmarker))
  6998. (inhibit-read-only t)
  6999. newhead)
  7000. (org-with-remote-undo buffer
  7001. (with-current-buffer buffer
  7002. (widen)
  7003. (goto-char pos)
  7004. (save-excursion
  7005. (org-show-context 'agenda))
  7006. (save-excursion
  7007. (and (outline-next-heading)
  7008. (org-flag-heading nil))) ; show the next heading
  7009. (goto-char pos)
  7010. (if tag
  7011. (org-toggle-tag tag onoff)
  7012. (call-interactively 'org-set-tags))
  7013. (end-of-line 1)
  7014. (setq newhead (org-get-heading)))
  7015. (org-agenda-change-all-lines newhead hdmarker)
  7016. (beginning-of-line 1)))))
  7017. (defun org-agenda-set-property ()
  7018. "Set a property for the current headline."
  7019. (interactive)
  7020. (org-agenda-check-no-diary)
  7021. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7022. (org-agenda-error)))
  7023. (buffer (marker-buffer hdmarker))
  7024. (pos (marker-position hdmarker))
  7025. (inhibit-read-only t)
  7026. newhead)
  7027. (org-with-remote-undo buffer
  7028. (with-current-buffer buffer
  7029. (widen)
  7030. (goto-char pos)
  7031. (save-excursion
  7032. (org-show-context 'agenda))
  7033. (save-excursion
  7034. (and (outline-next-heading)
  7035. (org-flag-heading nil))) ; show the next heading
  7036. (goto-char pos)
  7037. (call-interactively 'org-set-property)))))
  7038. (defun org-agenda-set-effort ()
  7039. "Set the effort property for the current headline."
  7040. (interactive)
  7041. (org-agenda-check-no-diary)
  7042. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7043. (org-agenda-error)))
  7044. (buffer (marker-buffer hdmarker))
  7045. (pos (marker-position hdmarker))
  7046. (inhibit-read-only t)
  7047. newhead)
  7048. (org-with-remote-undo buffer
  7049. (with-current-buffer buffer
  7050. (widen)
  7051. (goto-char pos)
  7052. (save-excursion
  7053. (org-show-context 'agenda))
  7054. (save-excursion
  7055. (and (outline-next-heading)
  7056. (org-flag-heading nil))) ; show the next heading
  7057. (goto-char pos)
  7058. (call-interactively 'org-set-effort)
  7059. (end-of-line 1)
  7060. (setq newhead (org-get-heading)))
  7061. (org-agenda-change-all-lines newhead hdmarker))))
  7062. (defun org-agenda-toggle-archive-tag ()
  7063. "Toggle the archive tag for the current entry."
  7064. (interactive)
  7065. (org-agenda-check-no-diary)
  7066. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7067. (org-agenda-error)))
  7068. (buffer (marker-buffer hdmarker))
  7069. (pos (marker-position hdmarker))
  7070. (inhibit-read-only t)
  7071. newhead)
  7072. (org-with-remote-undo buffer
  7073. (with-current-buffer buffer
  7074. (widen)
  7075. (goto-char pos)
  7076. (org-show-context 'agenda)
  7077. (save-excursion
  7078. (and (outline-next-heading)
  7079. (org-flag-heading nil))) ; show the next heading
  7080. (call-interactively 'org-toggle-archive-tag)
  7081. (end-of-line 1)
  7082. (setq newhead (org-get-heading)))
  7083. (org-agenda-change-all-lines newhead hdmarker)
  7084. (beginning-of-line 1))))
  7085. (defun org-agenda-do-date-later (arg)
  7086. (interactive "P")
  7087. (cond
  7088. ((or (equal arg '(16))
  7089. (memq last-command
  7090. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7091. (setq this-command 'org-agenda-date-later-minutes)
  7092. (org-agenda-date-later-minutes 1))
  7093. ((or (equal arg '(4))
  7094. (memq last-command
  7095. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7096. (setq this-command 'org-agenda-date-later-hours)
  7097. (org-agenda-date-later-hours 1))
  7098. (t
  7099. (org-agenda-date-later (prefix-numeric-value arg)))))
  7100. (defun org-agenda-do-date-earlier (arg)
  7101. (interactive "P")
  7102. (cond
  7103. ((or (equal arg '(16))
  7104. (memq last-command
  7105. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7106. (setq this-command 'org-agenda-date-earlier-minutes)
  7107. (org-agenda-date-earlier-minutes 1))
  7108. ((or (equal arg '(4))
  7109. (memq last-command
  7110. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7111. (setq this-command 'org-agenda-date-earlier-hours)
  7112. (org-agenda-date-earlier-hours 1))
  7113. (t
  7114. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7115. (defun org-agenda-date-later (arg &optional what)
  7116. "Change the date of this item to ARG day(s) later."
  7117. (interactive "p")
  7118. (org-agenda-check-type t 'agenda 'timeline)
  7119. (org-agenda-check-no-diary)
  7120. (let* ((marker (or (org-get-at-bol 'org-marker)
  7121. (org-agenda-error)))
  7122. (buffer (marker-buffer marker))
  7123. (pos (marker-position marker))
  7124. cdate today)
  7125. (org-with-remote-undo buffer
  7126. (with-current-buffer buffer
  7127. (widen)
  7128. (goto-char pos)
  7129. (if (not (org-at-timestamp-p))
  7130. (error "Cannot find time stamp"))
  7131. (when (and org-agenda-move-date-from-past-immediately-to-today
  7132. (equal arg 1)
  7133. (or (not what) (eq what 'day))
  7134. (not (save-match-data (org-at-date-range-p))))
  7135. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7136. cdate (calendar-absolute-from-gregorian
  7137. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7138. today (org-today))
  7139. (if (> today cdate)
  7140. ;; immediately shift to today
  7141. (setq arg (- today cdate))))
  7142. (org-timestamp-change arg (or what 'day))
  7143. (when (and (org-at-date-range-p)
  7144. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7145. (let ((end org-last-changed-timestamp))
  7146. (org-timestamp-change arg (or what 'day))
  7147. (setq org-last-changed-timestamp
  7148. (concat org-last-changed-timestamp "--" end)))))
  7149. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7150. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7151. (defun org-agenda-date-earlier (arg &optional what)
  7152. "Change the date of this item to ARG day(s) earlier."
  7153. (interactive "p")
  7154. (org-agenda-date-later (- arg) what))
  7155. (defun org-agenda-date-later-minutes (arg)
  7156. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7157. (interactive "p")
  7158. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7159. (org-agenda-date-later arg 'minute))
  7160. (defun org-agenda-date-earlier-minutes (arg)
  7161. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7162. (interactive "p")
  7163. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7164. (org-agenda-date-earlier arg 'minute))
  7165. (defun org-agenda-date-later-hours (arg)
  7166. "Change the time of this item, in hour steps."
  7167. (interactive "p")
  7168. (org-agenda-date-later arg 'hour))
  7169. (defun org-agenda-date-earlier-hours (arg)
  7170. "Change the time of this item, in hour steps."
  7171. (interactive "p")
  7172. (org-agenda-date-earlier arg 'hour))
  7173. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7174. "Show new date stamp via text properties."
  7175. ;; We use text properties to make this undoable
  7176. (let ((inhibit-read-only t)
  7177. (buffer-invisibility-spec))
  7178. (setq stamp (concat " " prefix " => " stamp))
  7179. (save-excursion
  7180. (goto-char (point-max))
  7181. (while (not (bobp))
  7182. (when (equal marker (org-get-at-bol 'org-marker))
  7183. (org-move-to-column (- (window-width) (length stamp)) t)
  7184. (org-agenda-fix-tags-filter-overlays-at (point))
  7185. (if (featurep 'xemacs)
  7186. ;; Use `duplicable' property to trigger undo recording
  7187. (let ((ex (make-extent nil nil))
  7188. (gl (make-glyph stamp)))
  7189. (set-glyph-face gl 'secondary-selection)
  7190. (set-extent-properties
  7191. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7192. (insert-extent ex (1- (point)) (point-at-eol)))
  7193. (add-text-properties
  7194. (1- (point)) (point-at-eol)
  7195. (list 'display (org-add-props stamp nil
  7196. 'face 'secondary-selection))))
  7197. (beginning-of-line 1))
  7198. (beginning-of-line 0)))))
  7199. (defun org-agenda-date-prompt (arg)
  7200. "Change the date of this item. Date is prompted for, with default today.
  7201. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7202. be used to request time specification in the time stamp."
  7203. (interactive "P")
  7204. (org-agenda-check-type t 'agenda 'timeline)
  7205. (org-agenda-check-no-diary)
  7206. (let* ((marker (or (org-get-at-bol 'org-marker)
  7207. (org-agenda-error)))
  7208. (buffer (marker-buffer marker))
  7209. (pos (marker-position marker)))
  7210. (org-with-remote-undo buffer
  7211. (with-current-buffer buffer
  7212. (widen)
  7213. (goto-char pos)
  7214. (if (not (org-at-timestamp-p t))
  7215. (error "Cannot find time stamp"))
  7216. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7217. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7218. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7219. (defun org-agenda-schedule (arg &optional time)
  7220. "Schedule the item at point.
  7221. ARG is passed through to `org-schedule'."
  7222. (interactive "P")
  7223. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7224. (org-agenda-check-no-diary)
  7225. (let* ((marker (or (org-get-at-bol 'org-marker)
  7226. (org-agenda-error)))
  7227. (type (marker-insertion-type marker))
  7228. (buffer (marker-buffer marker))
  7229. (pos (marker-position marker))
  7230. (org-insert-labeled-timestamps-at-point nil)
  7231. ts)
  7232. (set-marker-insertion-type marker t)
  7233. (org-with-remote-undo buffer
  7234. (with-current-buffer buffer
  7235. (widen)
  7236. (goto-char pos)
  7237. (setq ts (org-schedule arg time)))
  7238. (org-agenda-show-new-time marker ts "S"))
  7239. (message "Item scheduled for %s" ts)))
  7240. (defun org-agenda-deadline (arg &optional time)
  7241. "Schedule the item at point.
  7242. ARG is passed through to `org-deadline'."
  7243. (interactive "P")
  7244. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7245. (org-agenda-check-no-diary)
  7246. (let* ((marker (or (org-get-at-bol 'org-marker)
  7247. (org-agenda-error)))
  7248. (buffer (marker-buffer marker))
  7249. (pos (marker-position marker))
  7250. (org-insert-labeled-timestamps-at-point nil)
  7251. ts)
  7252. (org-with-remote-undo buffer
  7253. (with-current-buffer buffer
  7254. (widen)
  7255. (goto-char pos)
  7256. (setq ts (org-deadline arg time)))
  7257. (org-agenda-show-new-time marker ts "D"))
  7258. (message "Deadline for this item set to %s" ts)))
  7259. (defun org-agenda-action ()
  7260. "Select entry for agenda action, or execute an agenda action.
  7261. This command prompts for another letter. Valid inputs are:
  7262. m Mark the entry at point for an agenda action
  7263. s Schedule the marked entry to the date at the cursor
  7264. d Set the deadline of the marked entry to the date at the cursor
  7265. r Call `org-remember' with cursor date as the default date
  7266. c Call `org-capture' with cursor date as the default date
  7267. SPC Show marked entry in other window
  7268. TAB Visit marked entry in other window
  7269. The cursor may be at a date in the calendar, or in the Org agenda."
  7270. (interactive)
  7271. (let (ans)
  7272. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7273. (setq ans (read-char-exclusive))
  7274. (cond
  7275. ((equal ans ?m)
  7276. ;; Mark this entry
  7277. (if (eq major-mode 'org-agenda-mode)
  7278. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7279. (org-get-at-bol 'org-marker))))
  7280. (if m
  7281. (progn
  7282. (move-marker org-agenda-action-marker
  7283. (marker-position m) (marker-buffer m))
  7284. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7285. (error "Don't know which entry to mark")))
  7286. (error "This command works only in the agenda")))
  7287. ((equal ans ?s)
  7288. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7289. ((equal ans ?d)
  7290. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7291. ((equal ans ?r)
  7292. (org-agenda-do-action '(org-remember) t))
  7293. ((equal ans ?c)
  7294. (org-agenda-do-action '(org-capture) t))
  7295. ((equal ans ?\ )
  7296. (let ((cw (selected-window)))
  7297. (org-switch-to-buffer-other-window
  7298. (marker-buffer org-agenda-action-marker))
  7299. (goto-char org-agenda-action-marker)
  7300. (org-show-context 'agenda)
  7301. (select-window cw)))
  7302. ((equal ans ?\C-i)
  7303. (org-switch-to-buffer-other-window
  7304. (marker-buffer org-agenda-action-marker))
  7305. (goto-char org-agenda-action-marker)
  7306. (org-show-context 'agenda))
  7307. (t (error "Invalid agenda action %c" ans)))))
  7308. (defun org-agenda-do-action (form &optional current-buffer)
  7309. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7310. (let ((org-overriding-default-time (org-get-cursor-date)))
  7311. (if current-buffer
  7312. (eval form)
  7313. (if (not (marker-buffer org-agenda-action-marker))
  7314. (error "No entry has been selected for agenda action")
  7315. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7316. (save-excursion
  7317. (save-restriction
  7318. (widen)
  7319. (goto-char org-agenda-action-marker)
  7320. (eval form))))))))
  7321. (defun org-agenda-clock-in (&optional arg)
  7322. "Start the clock on the currently selected item."
  7323. (interactive "P")
  7324. (org-agenda-check-no-diary)
  7325. (if (equal arg '(4))
  7326. (org-clock-in arg)
  7327. (let* ((marker (or (org-get-at-bol 'org-marker)
  7328. (org-agenda-error)))
  7329. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7330. marker))
  7331. (pos (marker-position marker))
  7332. newhead)
  7333. (org-with-remote-undo (marker-buffer marker)
  7334. (with-current-buffer (marker-buffer marker)
  7335. (widen)
  7336. (goto-char pos)
  7337. (org-show-context 'agenda)
  7338. (org-show-entry)
  7339. (org-cycle-hide-drawers 'children)
  7340. (org-clock-in arg)
  7341. (setq newhead (org-get-heading)))
  7342. (org-agenda-change-all-lines newhead hdmarker)))))
  7343. (defun org-agenda-clock-out ()
  7344. "Stop the currently running clock."
  7345. (interactive)
  7346. (unless (marker-buffer org-clock-marker)
  7347. (error "No running clock"))
  7348. (let ((marker (make-marker)) newhead)
  7349. (org-with-remote-undo (marker-buffer org-clock-marker)
  7350. (with-current-buffer (marker-buffer org-clock-marker)
  7351. (save-excursion
  7352. (save-restriction
  7353. (widen)
  7354. (goto-char org-clock-marker)
  7355. (org-back-to-heading t)
  7356. (move-marker marker (point))
  7357. (org-clock-out)
  7358. (setq newhead (org-get-heading))))))
  7359. (org-agenda-change-all-lines newhead marker)
  7360. (move-marker marker nil)))
  7361. (defun org-agenda-clock-cancel (&optional arg)
  7362. "Cancel the currently running clock."
  7363. (interactive "P")
  7364. (unless (marker-buffer org-clock-marker)
  7365. (error "No running clock"))
  7366. (org-with-remote-undo (marker-buffer org-clock-marker)
  7367. (org-clock-cancel)))
  7368. (defun org-agenda-clock-goto ()
  7369. "Jump to the currently clocked in task within the agenda.
  7370. If the currently clocked in task is not listed in the agenda
  7371. buffer, display it in another window."
  7372. (interactive)
  7373. (let (pos)
  7374. (mapc (lambda (o)
  7375. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7376. (setq pos (overlay-start o))))
  7377. (overlays-in (point-min) (point-max)))
  7378. (cond (pos (goto-char pos))
  7379. ;; If the currently clocked entry is not in the agenda
  7380. ;; buffer, we visit it in another window:
  7381. (org-clock-current-task
  7382. (org-switch-to-buffer-other-window (org-clock-goto)))
  7383. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7384. (defun org-agenda-diary-entry-in-org-file ()
  7385. "Make a diary entry in the file `org-agenda-diary-file'."
  7386. (let (d1 d2 char (text "") dp1 dp2)
  7387. (if (equal (buffer-name) "*Calendar*")
  7388. (setq d1 (calendar-cursor-to-date t)
  7389. d2 (car calendar-mark-ring))
  7390. (setq dp1 (get-text-property (point-at-bol) 'day))
  7391. (unless dp1 (error "No date defined in current line"))
  7392. (setq d1 (calendar-gregorian-from-absolute dp1)
  7393. d2 (and (ignore-errors (mark))
  7394. (save-excursion
  7395. (goto-char (mark))
  7396. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7397. (calendar-gregorian-from-absolute dp2))))
  7398. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7399. (setq char (read-char-exclusive))
  7400. (cond
  7401. ((equal char ?d)
  7402. (setq text (read-string "Day entry: "))
  7403. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7404. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7405. ((equal char ?a)
  7406. (setq d1 (list (car d1) (nth 1 d1)
  7407. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7408. (nth 2 d1))))
  7409. (setq text (read-string "Anniversary (use %d to show years): "))
  7410. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7411. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7412. ((equal char ?b)
  7413. (setq text (read-string "Block entry: "))
  7414. (unless (and d1 d2 (not (equal d1 d2)))
  7415. (error "No block of days selected"))
  7416. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7417. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7418. ((equal char ?j)
  7419. (org-switch-to-buffer-other-window
  7420. (find-file-noselect org-agenda-diary-file))
  7421. (require 'org-datetree)
  7422. (org-datetree-find-date-create d1)
  7423. (org-reveal t))
  7424. (t (error "Invalid selection character `%c'" char)))))
  7425. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7426. "Where in `org-agenda-diary-file' should new entries be added?
  7427. Valid values:
  7428. date-tree in the date tree, as child of the date
  7429. top-level as top-level entries at the end of the file."
  7430. :group 'org-agenda
  7431. :type '(choice
  7432. (const :tag "in a date tree" date-tree)
  7433. (const :tag "as top level at end of file" top-level)))
  7434. (defcustom org-agenda-insert-diary-extract-time nil
  7435. "Non-nil means extract any time specification from the diary entry."
  7436. :group 'org-agenda
  7437. :type 'boolean)
  7438. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7439. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7440. If TEXT is not empty, it will become the headline of the new entry, and
  7441. the resulting entry will not be shown. When TEXT is empty, switch to
  7442. `org-agenda-diary-file' and let the user finish the entry there."
  7443. (let ((cw (current-window-configuration)))
  7444. (org-switch-to-buffer-other-window
  7445. (find-file-noselect org-agenda-diary-file))
  7446. (widen)
  7447. (goto-char (point-min))
  7448. (cond
  7449. ((eq type 'anniversary)
  7450. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7451. (progn
  7452. (or (org-at-heading-p t)
  7453. (progn
  7454. (outline-next-heading)
  7455. (insert "* Anniversaries\n\n")
  7456. (beginning-of-line -1)))))
  7457. (outline-next-heading)
  7458. (org-back-over-empty-lines)
  7459. (backward-char 1)
  7460. (insert "\n")
  7461. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7462. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7463. ((eq type 'day)
  7464. (let ((org-prefix-has-time t)
  7465. (org-agenda-time-leading-zero t)
  7466. fmt time time2)
  7467. (if org-agenda-insert-diary-extract-time
  7468. ;; Use org-agenda-format-item to parse text for a time-range and
  7469. ;; remove it. FIXME: This is a hack, we should refactor
  7470. ;; that function to make time extraction available separately
  7471. (setq fmt (org-agenda-format-item nil text nil nil t)
  7472. time (get-text-property 0 'time fmt)
  7473. time2 (if (> (length time) 0)
  7474. ;; split-string removes trailing ...... if
  7475. ;; no end time given. First space
  7476. ;; separates time from date.
  7477. (concat " " (car (split-string time "\\.")))
  7478. nil)
  7479. text (get-text-property 0 'txt fmt)))
  7480. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7481. (org-agenda-insert-diary-as-top-level text)
  7482. (require 'org-datetree)
  7483. (org-datetree-find-date-create d1)
  7484. (org-agenda-insert-diary-make-new-entry text))
  7485. (org-insert-time-stamp (org-time-from-absolute
  7486. (calendar-absolute-from-gregorian d1))
  7487. nil nil nil nil time2))
  7488. (end-of-line 0))
  7489. ((eq type 'block)
  7490. (if (> (calendar-absolute-from-gregorian d1)
  7491. (calendar-absolute-from-gregorian d2))
  7492. (setq d1 (prog1 d2 (setq d2 d1))))
  7493. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7494. (org-agenda-insert-diary-as-top-level text)
  7495. (require 'org-datetree)
  7496. (org-datetree-find-date-create d1)
  7497. (org-agenda-insert-diary-make-new-entry text))
  7498. (org-insert-time-stamp (org-time-from-absolute
  7499. (calendar-absolute-from-gregorian d1)))
  7500. (insert "--")
  7501. (org-insert-time-stamp (org-time-from-absolute
  7502. (calendar-absolute-from-gregorian d2)))
  7503. (end-of-line 0)))
  7504. (if (string-match "\\S-" text)
  7505. (progn
  7506. (set-window-configuration cw)
  7507. (message "%s entry added to %s"
  7508. (capitalize (symbol-name type))
  7509. (abbreviate-file-name org-agenda-diary-file)))
  7510. (org-reveal t)
  7511. (message "Please finish entry here"))))
  7512. (defun org-agenda-insert-diary-as-top-level (text)
  7513. "Make new entry as a top-level entry at the end of the file.
  7514. Add TEXT as headline, and position the cursor in the second line so that
  7515. a timestamp can be added there."
  7516. (widen)
  7517. (goto-char (point-max))
  7518. (or (bolp) (insert "\n"))
  7519. (insert "* " text "\n")
  7520. (if org-adapt-indentation (org-indent-to-column 2)))
  7521. (defun org-agenda-insert-diary-make-new-entry (text)
  7522. "Make new entry as last child of current entry.
  7523. Add TEXT as headline, and position the cursor in the second line so that
  7524. a timestamp can be added there."
  7525. (let ((org-show-following-heading t)
  7526. (org-show-siblings t)
  7527. (org-show-hierarchy-above t)
  7528. (org-show-entry-below t)
  7529. col)
  7530. (outline-next-heading)
  7531. (org-back-over-empty-lines)
  7532. (or (looking-at "[ \t]*$")
  7533. (progn (insert "\n") (backward-char 1)))
  7534. (org-insert-heading nil t)
  7535. (org-do-demote)
  7536. (setq col (current-column))
  7537. (insert text "\n")
  7538. (if org-adapt-indentation (org-indent-to-column col))
  7539. (let ((org-show-following-heading t)
  7540. (org-show-siblings t)
  7541. (org-show-hierarchy-above t)
  7542. (org-show-entry-below t))
  7543. (org-show-context))))
  7544. (defun org-agenda-diary-entry ()
  7545. "Make a diary entry, like the `i' command from the calendar.
  7546. All the standard commands work: block, weekly etc.
  7547. When `org-agenda-diary-file' points to a file,
  7548. `org-agenda-diary-entry-in-org-file' is called instead to create
  7549. entries in that Org-mode file."
  7550. (interactive)
  7551. (org-agenda-check-type t 'agenda 'timeline)
  7552. (if (not (eq org-agenda-diary-file 'diary-file))
  7553. (org-agenda-diary-entry-in-org-file)
  7554. (require 'diary-lib)
  7555. (let* ((char (progn
  7556. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7557. (read-char-exclusive)))
  7558. (cmd (cdr (assoc char
  7559. '((?d . insert-diary-entry)
  7560. (?w . insert-weekly-diary-entry)
  7561. (?m . insert-monthly-diary-entry)
  7562. (?y . insert-yearly-diary-entry)
  7563. (?a . insert-anniversary-diary-entry)
  7564. (?b . insert-block-diary-entry)
  7565. (?c . insert-cyclic-diary-entry)))))
  7566. (oldf (symbol-function 'calendar-cursor-to-date))
  7567. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7568. (point (point))
  7569. (mark (or (mark t) (point))))
  7570. (unless cmd
  7571. (error "No command associated with <%c>" char))
  7572. (unless (and (get-text-property point 'day)
  7573. (or (not (equal ?b char))
  7574. (get-text-property mark 'day)))
  7575. (error "Don't know which date to use for diary entry"))
  7576. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7577. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7578. (let ((calendar-mark-ring
  7579. (list (calendar-gregorian-from-absolute
  7580. (or (get-text-property mark 'day)
  7581. (get-text-property point 'day))))))
  7582. (unwind-protect
  7583. (progn
  7584. (fset 'calendar-cursor-to-date
  7585. (lambda (&optional error dummy)
  7586. (calendar-gregorian-from-absolute
  7587. (get-text-property point 'day))))
  7588. (call-interactively cmd))
  7589. (fset 'calendar-cursor-to-date oldf))))))
  7590. (defun org-agenda-execute-calendar-command (cmd)
  7591. "Execute a calendar command from the agenda, with the date associated to
  7592. the cursor position."
  7593. (org-agenda-check-type t 'agenda 'timeline)
  7594. (require 'diary-lib)
  7595. (unless (get-text-property (point) 'day)
  7596. (error "Don't know which date to use for calendar command"))
  7597. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7598. (point (point))
  7599. (date (calendar-gregorian-from-absolute
  7600. (get-text-property point 'day)))
  7601. ;; the following 2 vars are needed in the calendar
  7602. (displayed-month (car date))
  7603. (displayed-year (nth 2 date)))
  7604. (unwind-protect
  7605. (progn
  7606. (fset 'calendar-cursor-to-date
  7607. (lambda (&optional error dummy)
  7608. (calendar-gregorian-from-absolute
  7609. (get-text-property point 'day))))
  7610. (call-interactively cmd))
  7611. (fset 'calendar-cursor-to-date oldf))))
  7612. (defun org-agenda-phases-of-moon ()
  7613. "Display the phases of the moon for the 3 months around the cursor date."
  7614. (interactive)
  7615. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7616. (defun org-agenda-holidays ()
  7617. "Display the holidays for the 3 months around the cursor date."
  7618. (interactive)
  7619. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7620. (defvar calendar-longitude)
  7621. (defvar calendar-latitude)
  7622. (defvar calendar-location-name)
  7623. (defun org-agenda-sunrise-sunset (arg)
  7624. "Display sunrise and sunset for the cursor date.
  7625. Latitude and longitude can be specified with the variables
  7626. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7627. argument, latitude and longitude will be prompted for."
  7628. (interactive "P")
  7629. (require 'solar)
  7630. (let ((calendar-longitude (if arg nil calendar-longitude))
  7631. (calendar-latitude (if arg nil calendar-latitude))
  7632. (calendar-location-name
  7633. (if arg "the given coordinates" calendar-location-name)))
  7634. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7635. (defun org-agenda-goto-calendar ()
  7636. "Open the Emacs calendar with the date at the cursor."
  7637. (interactive)
  7638. (org-agenda-check-type t 'agenda 'timeline)
  7639. (let* ((day (or (get-text-property (point) 'day)
  7640. (error "Don't know which date to open in calendar")))
  7641. (date (calendar-gregorian-from-absolute day))
  7642. (calendar-move-hook nil)
  7643. (calendar-view-holidays-initially-flag nil)
  7644. (calendar-view-diary-initially-flag nil))
  7645. (calendar)
  7646. (calendar-goto-date date)))
  7647. ;;;###autoload
  7648. (defun org-calendar-goto-agenda ()
  7649. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7650. This is a command that has to be installed in `calendar-mode-map'."
  7651. (interactive)
  7652. (org-agenda-list nil (calendar-absolute-from-gregorian
  7653. (calendar-cursor-to-date))
  7654. nil))
  7655. (defun org-agenda-convert-date ()
  7656. (interactive)
  7657. (org-agenda-check-type t 'agenda 'timeline)
  7658. (let ((day (get-text-property (point) 'day))
  7659. date s)
  7660. (unless day
  7661. (error "Don't know which date to convert"))
  7662. (setq date (calendar-gregorian-from-absolute day))
  7663. (setq s (concat
  7664. "Gregorian: " (calendar-date-string date) "\n"
  7665. "ISO: " (calendar-iso-date-string date) "\n"
  7666. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7667. "Julian: " (calendar-julian-date-string date) "\n"
  7668. "Astron. JD: " (calendar-astro-date-string date)
  7669. " (Julian date number at noon UTC)\n"
  7670. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7671. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7672. "French: " (calendar-french-date-string date) "\n"
  7673. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7674. "Mayan: " (calendar-mayan-date-string date) "\n"
  7675. "Coptic: " (calendar-coptic-date-string date) "\n"
  7676. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7677. "Persian: " (calendar-persian-date-string date) "\n"
  7678. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7679. (with-output-to-temp-buffer "*Dates*"
  7680. (princ s))
  7681. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7682. ;;; Bulk commands
  7683. (defvar org-agenda-bulk-marked-entries nil
  7684. "List of markers that refer to marked entries in the agenda.")
  7685. (defun org-agenda-bulk-marked-p ()
  7686. (eq (get-char-property (point-at-bol) 'type)
  7687. 'org-marked-entry-overlay))
  7688. (defun org-agenda-bulk-mark (&optional arg)
  7689. "Mark the entry at point for future bulk action."
  7690. (interactive "p")
  7691. (dotimes (i (max arg 1))
  7692. (unless (org-get-at-bol 'org-agenda-diary-link)
  7693. (let* ((m (org-get-at-bol 'org-hd-marker))
  7694. ov)
  7695. (unless (org-agenda-bulk-marked-p)
  7696. (unless m (error "Nothing to mark at point"))
  7697. (push m org-agenda-bulk-marked-entries)
  7698. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7699. (org-overlay-display ov "> "
  7700. (org-get-todo-face "TODO")
  7701. 'evaporate)
  7702. (overlay-put ov 'type 'org-marked-entry-overlay))
  7703. (beginning-of-line 2)
  7704. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7705. (beginning-of-line 2))
  7706. (message "%d entries marked for bulk action"
  7707. (length org-agenda-bulk-marked-entries))))))
  7708. (defun org-agenda-bulk-mark-regexp (regexp)
  7709. "Mark entries match REGEXP."
  7710. (interactive "sMark entries matching regexp: ")
  7711. (let (entries-marked)
  7712. (save-excursion
  7713. (goto-char (point-min))
  7714. (goto-char (next-single-property-change (point) 'txt))
  7715. (while (re-search-forward regexp nil t)
  7716. (when (string-match regexp (get-text-property (point) 'txt))
  7717. (setq entries-marked (+ entries-marked 1))
  7718. (call-interactively 'org-agenda-bulk-mark))))
  7719. (if (not entries-marked)
  7720. (message "No entry matching this regexp."))))
  7721. (defun org-agenda-bulk-unmark ()
  7722. "Unmark the entry at point for future bulk action."
  7723. (interactive)
  7724. (when (org-agenda-bulk-marked-p)
  7725. (org-agenda-bulk-remove-overlays
  7726. (point-at-bol) (+ 2 (point-at-bol)))
  7727. (setq org-agenda-bulk-marked-entries
  7728. (delete (org-get-at-bol 'org-hd-marker)
  7729. org-agenda-bulk-marked-entries)))
  7730. (beginning-of-line 2)
  7731. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7732. (beginning-of-line 2))
  7733. (message "%d entries marked for bulk action"
  7734. (length org-agenda-bulk-marked-entries)))
  7735. (defun org-agenda-bulk-toggle ()
  7736. "Toggle marking the entry at point for bulk action."
  7737. (interactive)
  7738. (if (org-agenda-bulk-marked-p)
  7739. (org-agenda-bulk-unmark)
  7740. (org-agenda-bulk-mark)))
  7741. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7742. "Remove the mark overlays between BEG and END in the agenda buffer.
  7743. BEG and END default to the buffer limits.
  7744. This only removes the overlays, it does not remove the markers
  7745. from the list in `org-agenda-bulk-marked-entries'."
  7746. (interactive)
  7747. (mapc (lambda (ov)
  7748. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7749. (delete-overlay ov)))
  7750. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7751. (defun org-agenda-bulk-remove-all-marks ()
  7752. "Remove all marks in the agenda buffer.
  7753. This will remove the markers, and the overlays."
  7754. (interactive)
  7755. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7756. (setq org-agenda-bulk-marked-entries nil)
  7757. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7758. (defun org-agenda-bulk-action (&optional arg)
  7759. "Execute an remote-editing action on all marked entries.
  7760. The prefix arg is passed through to the command if possible."
  7761. (interactive "P")
  7762. ;; Make sure we have markers, and only valid ones
  7763. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7764. (mapc
  7765. (lambda (m)
  7766. (unless (and (markerp m)
  7767. (marker-buffer m)
  7768. (buffer-live-p (marker-buffer m))
  7769. (marker-position m))
  7770. (error "Marker %s for bulk command is invalid" m)))
  7771. org-agenda-bulk-marked-entries)
  7772. ;; Prompt for the bulk command
  7773. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7774. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7775. (when org-agenda-bulk-custom-functions
  7776. (concat " Custom: ["
  7777. (mapconcat (lambda(f) (char-to-string (car f)))
  7778. org-agenda-bulk-custom-functions "")
  7779. "]"))))
  7780. (let* ((action (read-char-exclusive))
  7781. (org-log-refile (if org-log-refile 'time nil))
  7782. (entries (reverse org-agenda-bulk-marked-entries))
  7783. redo-at-end
  7784. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7785. (cond
  7786. ((equal action ?$)
  7787. (setq cmd '(org-agenda-archive)))
  7788. ((equal action ?A)
  7789. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7790. ((member action '(?r ?w))
  7791. (setq rfloc (org-refile-get-location
  7792. "Refile to"
  7793. (marker-buffer (car org-agenda-bulk-marked-entries))
  7794. org-refile-allow-creating-parent-nodes))
  7795. (if (nth 3 rfloc)
  7796. (setcar (nthcdr 3 rfloc)
  7797. (move-marker (make-marker) (nth 3 rfloc)
  7798. (or (get-file-buffer (nth 1 rfloc))
  7799. (find-buffer-visiting (nth 1 rfloc))
  7800. (error "This should not happen")))))
  7801. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7802. redo-at-end t))
  7803. ((equal action ?t)
  7804. (setq state (org-icompleting-read
  7805. "Todo state: "
  7806. (with-current-buffer (marker-buffer (car entries))
  7807. (mapcar 'list org-todo-keywords-1))))
  7808. (setq cmd `(let ((org-inhibit-blocking t)
  7809. (org-inhibit-logging 'note))
  7810. (org-agenda-todo ,state))))
  7811. ((memq action '(?- ?+))
  7812. (setq tag (org-icompleting-read
  7813. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7814. (with-current-buffer (marker-buffer (car entries))
  7815. (delq nil
  7816. (mapcar (lambda (x)
  7817. (if (stringp (car x)) x)) org-tag-alist)))))
  7818. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7819. ((memq action '(?s ?d))
  7820. (let* ((date (unless arg
  7821. (org-read-date
  7822. nil nil nil
  7823. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7824. (ans (if arg nil org-read-date-final-answer))
  7825. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7826. (setq cmd `(let* ((bound (fboundp 'read-string))
  7827. (old (and bound (symbol-function 'read-string))))
  7828. (unwind-protect
  7829. (progn
  7830. (fset 'read-string (lambda (&rest ignore) ,ans))
  7831. (eval '(,c1 arg)))
  7832. (if bound
  7833. (fset 'read-string old)
  7834. (fmakunbound 'read-string)))))))
  7835. ((equal action ?S)
  7836. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7837. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7838. (let ((days (read-number
  7839. (format "Scatter tasks across how many %sdays: "
  7840. (if arg "week" "")) 7)))
  7841. (setq cmd
  7842. `(let ((distance (1+ (random ,days))))
  7843. (if arg
  7844. (let ((dist distance)
  7845. (day-of-week
  7846. (calendar-day-of-week
  7847. (calendar-gregorian-from-absolute (org-today)))))
  7848. (dotimes (i (1+ dist))
  7849. (while (member day-of-week org-agenda-weekend-days)
  7850. (incf distance)
  7851. (incf day-of-week)
  7852. (if (= day-of-week 7)
  7853. (setq day-of-week 0)))
  7854. (incf day-of-week)
  7855. (if (= day-of-week 7)
  7856. (setq day-of-week 0)))))
  7857. ;; silently fail when try to replan a sexp entry
  7858. (condition-case nil
  7859. (let* ((date (calendar-gregorian-from-absolute
  7860. (+ (org-today) distance)))
  7861. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7862. (nth 2 date))))
  7863. (org-agenda-schedule nil time))
  7864. (error nil)))))))
  7865. ((assoc action org-agenda-bulk-custom-functions)
  7866. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7867. redo-at-end t))
  7868. ((equal action ?f)
  7869. (setq cmd (list (intern
  7870. (org-icompleting-read "Function: "
  7871. obarray 'fboundp t nil nil)))))
  7872. (t (error "Invalid bulk action")))
  7873. ;; Sort the markers, to make sure that parents are handled before children
  7874. (setq entries (sort entries
  7875. (lambda (a b)
  7876. (cond
  7877. ((equal (marker-buffer a) (marker-buffer b))
  7878. (< (marker-position a) (marker-position b)))
  7879. (t
  7880. (string< (buffer-name (marker-buffer a))
  7881. (buffer-name (marker-buffer b))))))))
  7882. ;; Now loop over all markers and apply cmd
  7883. (while (setq e (pop entries))
  7884. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7885. (if (not pos)
  7886. (progn (message "Skipping removed entry at %s" e)
  7887. (setq cntskip (1+ cntskip)))
  7888. (goto-char pos)
  7889. (let (org-loop-over-headlines-in-active-region)
  7890. (eval cmd))
  7891. (setq org-agenda-bulk-marked-entries
  7892. (delete e org-agenda-bulk-marked-entries))
  7893. (setq cnt (1+ cnt))))
  7894. (setq org-agenda-bulk-marked-entries nil)
  7895. (org-agenda-bulk-remove-all-marks)
  7896. (when redo-at-end (org-agenda-redo))
  7897. (message "Acted on %d entries%s"
  7898. cnt
  7899. (if (= cntskip 0)
  7900. ""
  7901. (format ", skipped %d (disappeared before their turn)"
  7902. cntskip)))))
  7903. ;;; Flagging notes
  7904. (defun org-agenda-show-the-flagging-note ()
  7905. "Display the flagging note in the other window.
  7906. When called a second time in direct sequence, offer to remove the FLAGGING
  7907. tag and (if present) the flagging note."
  7908. (interactive)
  7909. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7910. (win (selected-window))
  7911. note heading newhead)
  7912. (unless hdmarker
  7913. (error "No linked entry at point"))
  7914. (if (and (eq this-command last-command)
  7915. (y-or-n-p "Unflag and remove any flagging note? "))
  7916. (progn
  7917. (org-agenda-remove-flag hdmarker)
  7918. (let ((win (get-buffer-window "*Flagging Note*")))
  7919. (and win (delete-window win)))
  7920. (message "Entry unflagged"))
  7921. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7922. (unless note
  7923. (error "No flagging note"))
  7924. (org-kill-new note)
  7925. (org-switch-to-buffer-other-window "*Flagging Note*")
  7926. (erase-buffer)
  7927. (insert note)
  7928. (goto-char (point-min))
  7929. (while (re-search-forward "\\\\n" nil t)
  7930. (replace-match "\n" t t))
  7931. (goto-char (point-min))
  7932. (select-window win)
  7933. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7934. (defun org-agenda-remove-flag (marker)
  7935. "Remove the FLAGGED tag and any flagging note in the entry."
  7936. (let (newhead)
  7937. (org-with-point-at marker
  7938. (org-toggle-tag "FLAGGED" 'off)
  7939. (org-entry-delete nil "THEFLAGGINGNOTE")
  7940. (setq newhead (org-get-heading)))
  7941. (org-agenda-change-all-lines newhead marker)
  7942. (message "Entry unflagged")))
  7943. (defun org-agenda-get-any-marker (&optional pos)
  7944. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7945. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7946. ;;; Appointment reminders
  7947. (defvar appt-time-msg-list)
  7948. ;;;###autoload
  7949. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  7950. "Activate appointments found in `org-agenda-files'.
  7951. With a \\[universal-argument] prefix, refresh the list of
  7952. appointments.
  7953. If FILTER is t, interactively prompt the user for a regular
  7954. expression, and filter out entries that don't match it.
  7955. If FILTER is a string, use this string as a regular expression
  7956. for filtering entries out.
  7957. If FILTER is a function, filter out entries against which
  7958. calling the function returns nil. This function takes one
  7959. argument: an entry from `org-agenda-get-day-entries'.
  7960. FILTER can also be an alist with the car of each cell being
  7961. either 'headline or 'category. For example:
  7962. '((headline \"IMPORTANT\")
  7963. (category \"Work\"))
  7964. will only add headlines containing IMPORTANT or headlines
  7965. belonging to the \"Work\" category.
  7966. ARGS are symbols indicating what kind of entries to consider.
  7967. By default `org-agenda-to-appt' will use :deadline, :scheduled
  7968. and :timestamp entries. See the docstring of `org-diary' for
  7969. details and examples."
  7970. (interactive "P")
  7971. (if refresh (setq appt-time-msg-list nil))
  7972. (if (eq filter t)
  7973. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7974. (let* ((cnt 0) ; count added events
  7975. (scope (or args '(:deadline :scheduled :timestamp)))
  7976. (org-agenda-new-buffers nil)
  7977. (org-deadline-warning-days 0)
  7978. ;; Do not use `org-today' here because appt only takes
  7979. ;; time and without date as argument, so it may pass wrong
  7980. ;; information otherwise
  7981. (today (org-date-to-gregorian
  7982. (time-to-days (current-time))))
  7983. (org-agenda-restrict nil)
  7984. (files (org-agenda-files 'unrestricted)) entries file)
  7985. ;; Get all entries which may contain an appt
  7986. (org-prepare-agenda-buffers files)
  7987. (while (setq file (pop files))
  7988. (setq entries
  7989. (delq nil
  7990. (append entries
  7991. (apply 'org-agenda-get-day-entries
  7992. file today scope)))))
  7993. ;; Map thru entries and find if we should filter them out
  7994. (mapc
  7995. (lambda(x)
  7996. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7997. (cat (get-text-property 1 'org-category x))
  7998. (tod (get-text-property 1 'time-of-day x))
  7999. (ok (or (null filter)
  8000. (and (stringp filter) (string-match filter evt))
  8001. (and (functionp filter) (funcall filter x))
  8002. (and (listp filter)
  8003. (let ((cat-filter (cadr (assoc 'category filter)))
  8004. (evt-filter (cadr (assoc 'headline filter))))
  8005. (or (and (stringp cat-filter)
  8006. (string-match cat-filter cat))
  8007. (and (stringp evt-filter)
  8008. (string-match evt-filter evt))))))))
  8009. ;; FIXME: Shall we remove text-properties for the appt text?
  8010. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8011. (when (and ok tod)
  8012. (setq tod (concat "00" (number-to-string tod))
  8013. tod (when (string-match
  8014. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8015. (concat (match-string 1 tod) ":"
  8016. (match-string 2 tod))))
  8017. (appt-add tod evt)
  8018. (setq cnt (1+ cnt))))) entries)
  8019. (org-release-buffers org-agenda-new-buffers)
  8020. (if (eq cnt 0)
  8021. (message "No event to add")
  8022. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8023. (defun org-agenda-todayp (date)
  8024. "Does DATE mean today, when considering `org-extend-today-until'?"
  8025. (let ((today (org-today))
  8026. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8027. date)))
  8028. (eq date today)))
  8029. (defun org-agenda-todo-yesterday (&optional arg)
  8030. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8031. (interactive "P")
  8032. (let* ((hour (third (decode-time
  8033. (org-current-time))))
  8034. (org-extend-today-until (1+ hour)))
  8035. (org-agenda-todo arg)))
  8036. (provide 'org-agenda)
  8037. ;;; org-agenda.el ends here