org-agenda.el 323 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a conveniant way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function org-datetree-find-date-create "org-datetree"
  62. (date &optional keep-restriction))
  63. (declare-function org-columns-quit "org-colview" ())
  64. (declare-function diary-date-display-form "diary-lib" (&optional type))
  65. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  66. (declare-function org-habit-insert-consistency-graphs
  67. "org-habit" (&optional line))
  68. (declare-function org-is-habit-p "org-habit" (&optional pom))
  69. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  70. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  71. (declare-function org-pop-to-buffer-same-window "org-compat"
  72. (&optional buffer-or-name norecord label))
  73. (declare-function org-duration-string-to-minutes "org-clock" (s))
  74. (declare-function org-hh:mm-string-to-minutes "org-clock" (s))
  75. (declare-function org-minutes-to-hh:mm-string "org-clock" (m))
  76. (defvar calendar-mode-map)
  77. (defvar org-clock-current-task) ; defined in org-clock.el
  78. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  79. (defvar org-habit-show-habits)
  80. (defvar org-habit-show-habits-only-for-today)
  81. ;; Defined somewhere in this file, but used before definition.
  82. (defvar org-agenda-buffer-name)
  83. (defvar org-agenda-overriding-header)
  84. (defvar org-agenda-title-append nil)
  85. (defvar entry)
  86. (defvar date)
  87. (defvar org-agenda-undo-list)
  88. (defvar org-agenda-pending-undo-list)
  89. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  90. (defcustom org-agenda-confirm-kill 1
  91. "When set, remote killing from the agenda buffer needs confirmation.
  92. When t, a confirmation is always needed. When a number N, confirmation is
  93. only needed when the text to be killed contains more than N non-white lines."
  94. :group 'org-agenda
  95. :type '(choice
  96. (const :tag "Never" nil)
  97. (const :tag "Always" t)
  98. (integer :tag "When more than N lines")))
  99. (defcustom org-agenda-compact-blocks nil
  100. "Non-nil means make the block agenda more compact.
  101. This is done globally by leaving out lines like the agenda span
  102. name and week number or the separator lines."
  103. :group 'org-agenda
  104. :type 'boolean)
  105. (defcustom org-agenda-block-separator ?=
  106. "The separator between blocks in the agenda.
  107. If this is a string, it will be used as the separator, with a newline added.
  108. If it is a character, it will be repeated to fill the window width.
  109. If nil the separator is disabled. In `org-agenda-custom-commands' this
  110. addresses the separator between the current and the previous block."
  111. :group 'org-agenda
  112. :type '(choice
  113. (const :tag "Disabled" nil)
  114. (character)
  115. (string)))
  116. (defgroup org-agenda-export nil
  117. "Options concerning exporting agenda views in Org-mode."
  118. :tag "Org Agenda Export"
  119. :group 'org-agenda)
  120. (defcustom org-agenda-with-colors t
  121. "Non-nil means use colors in agenda views."
  122. :group 'org-agenda-export
  123. :type 'boolean)
  124. (defcustom org-agenda-exporter-settings nil
  125. "Alist of variable/value pairs that should be active during agenda export.
  126. This is a good place to set options for ps-print and for htmlize.
  127. Note that the way this is implemented, the values will be evaluated
  128. before assigned to the variables. So make sure to quote values you do
  129. *not* want evaluated, for example
  130. (setq org-agenda-exporter-settings
  131. '((ps-print-color-p 'black-white)))"
  132. :group 'org-agenda-export
  133. :type '(repeat
  134. (list
  135. (variable)
  136. (sexp :tag "Value"))))
  137. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  138. "Hook run in temporary buffer before writing it to an export file.
  139. A useful function is `org-agenda-add-entry-text'."
  140. :group 'org-agenda-export
  141. :type 'hook
  142. :options '(org-agenda-add-entry-text))
  143. (defcustom org-agenda-add-entry-text-maxlines 0
  144. "Maximum number of entry text lines to be added to agenda.
  145. This is only relevant when `org-agenda-add-entry-text' is part of
  146. `org-agenda-before-write-hook', which it is by default.
  147. When this is 0, nothing will happen. When it is greater than 0, it
  148. specifies the maximum number of lines that will be added for each entry
  149. that is listed in the agenda view.
  150. Note that this variable is not used during display, only when exporting
  151. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  152. and `org-agenda-entry-text-maxlines'."
  153. :group 'org-agenda
  154. :type 'integer)
  155. (defcustom org-agenda-add-entry-text-descriptive-links t
  156. "Non-nil means export org-links as descriptive links in agenda added text.
  157. This variable applies to the text added to the agenda when
  158. `org-agenda-add-entry-text-maxlines' is larger than 0.
  159. When this variable nil, the URL will (also) be shown."
  160. :group 'org-agenda
  161. :type 'boolean)
  162. (defcustom org-agenda-export-html-style ""
  163. "The style specification for exported HTML Agenda files.
  164. If this variable contains a string, it will replace the default <style>
  165. section as produced by `htmlize'.
  166. Since there are different ways of setting style information, this variable
  167. needs to contain the full HTML structure to provide a style, including the
  168. surrounding HTML tags. The style specifications should include definitions
  169. the fonts used by the agenda, here is an example:
  170. <style type=\"text/css\">
  171. p { font-weight: normal; color: gray; }
  172. .org-agenda-structure {
  173. font-size: 110%;
  174. color: #003399;
  175. font-weight: 600;
  176. }
  177. .org-todo {
  178. color: #cc6666;
  179. font-weight: bold;
  180. }
  181. .org-agenda-done {
  182. color: #339933;
  183. }
  184. .org-done {
  185. color: #339933;
  186. }
  187. .title { text-align: center; }
  188. .todo, .deadline { color: red; }
  189. .done { color: green; }
  190. </style>
  191. or, if you want to keep the style in a file,
  192. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  193. As the value of this option simply gets inserted into the HTML <head> header,
  194. you can \"misuse\" it to also add other text to the header. However,
  195. <style>...</style> is required, if not present the variable will be ignored."
  196. :group 'org-agenda-export
  197. :group 'org-export-html
  198. :type 'string)
  199. (defcustom org-agenda-persistent-filter nil
  200. "When set, keep filters from one agenda view to the next."
  201. :group 'org-agenda
  202. :type 'boolean)
  203. (defgroup org-agenda-custom-commands nil
  204. "Options concerning agenda views in Org-mode."
  205. :tag "Org Agenda Custom Commands"
  206. :group 'org-agenda)
  207. (defconst org-sorting-choice
  208. '(choice
  209. (const time-up) (const time-down)
  210. (const category-keep) (const category-up) (const category-down)
  211. (const tag-down) (const tag-up)
  212. (const priority-up) (const priority-down)
  213. (const todo-state-up) (const todo-state-down)
  214. (const effort-up) (const effort-down)
  215. (const habit-up) (const habit-down)
  216. (const alpha-up) (const alpha-down)
  217. (const user-defined-up) (const user-defined-down))
  218. "Sorting choices.")
  219. (defconst org-agenda-custom-commands-local-options
  220. `(repeat :tag "Local settings for this command. Remember to quote values"
  221. (choice :tag "Setting"
  222. (list :tag "Heading for this block"
  223. (const org-agenda-overriding-header)
  224. (string :tag "Headline"))
  225. (list :tag "Files to be searched"
  226. (const org-agenda-files)
  227. (list
  228. (const :format "" quote)
  229. (repeat (file))))
  230. (list :tag "Sorting strategy"
  231. (const org-agenda-sorting-strategy)
  232. (list
  233. (const :format "" quote)
  234. (repeat
  235. ,org-sorting-choice)))
  236. (list :tag "Prefix format"
  237. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  238. (string))
  239. (list :tag "Number of days in agenda"
  240. (const org-agenda-span)
  241. (choice (const :tag "Day" 'day)
  242. (const :tag "Week" 'week)
  243. (const :tag "Month" 'month)
  244. (const :tag "Year" 'year)
  245. (integer :tag "Custom")))
  246. (list :tag "Fixed starting date"
  247. (const org-agenda-start-day)
  248. (string :value "2007-11-01"))
  249. (list :tag "Start on day of week"
  250. (const org-agenda-start-on-weekday)
  251. (choice :value 1
  252. (const :tag "Today" nil)
  253. (integer :tag "Weekday No.")))
  254. (list :tag "Include data from diary"
  255. (const org-agenda-include-diary)
  256. (boolean))
  257. (list :tag "Deadline Warning days"
  258. (const org-deadline-warning-days)
  259. (integer :value 1))
  260. (list :tag "Tags filter preset"
  261. (const org-agenda-filter-preset)
  262. (list
  263. (const :format "" quote)
  264. (repeat
  265. (string :tag "+tag or -tag"))))
  266. (list :tag "Set daily/weekly entry types"
  267. (const org-agenda-entry-types)
  268. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  269. (const :deadline)
  270. (const :scheduled)
  271. (const :timestamp)
  272. (const :sexp)))
  273. (list :tag "Standard skipping condition"
  274. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  275. (const org-agenda-skip-function)
  276. (list
  277. (const :format "" quote)
  278. (list
  279. (choice
  280. :tag "Skipping range"
  281. (const :tag "Skip entry" org-agenda-skip-entry-if)
  282. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  283. (repeat :inline t :tag "Conditions for skipping"
  284. (choice
  285. :tag "Condition type"
  286. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  287. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  288. (list :tag "TODO state is" :inline t
  289. (const 'todo)
  290. (choice
  291. (const :tag "any not-done state" 'todo)
  292. (const :tag "any done state" 'done)
  293. (const :tag "any state" 'any)
  294. (list :tag "Keyword list"
  295. (const :format "" quote)
  296. (repeat (string :tag "Keyword")))))
  297. (list :tag "TODO state is not" :inline t
  298. (const 'nottodo)
  299. (choice
  300. (const :tag "any not-done state" 'todo)
  301. (const :tag "any done state" 'done)
  302. (const :tag "any state" 'any)
  303. (list :tag "Keyword list"
  304. (const :format "" quote)
  305. (repeat (string :tag "Keyword")))))
  306. (const :tag "scheduled" 'scheduled)
  307. (const :tag "not scheduled" 'notscheduled)
  308. (const :tag "deadline" 'deadline)
  309. (const :tag "no deadline" 'notdeadline)
  310. (const :tag "timestamp" 'timestamp)
  311. (const :tag "no timestamp" 'nottimestamp))))))
  312. (list :tag "Non-standard skipping condition"
  313. :value (org-agenda-skip-function)
  314. (const org-agenda-skip-function)
  315. (sexp :tag "Function or form (quoted!)"))
  316. (list :tag "Any variable"
  317. (variable :tag "Variable")
  318. (sexp :tag "Value (sexp)"))))
  319. "Selection of examples for agenda command settings.
  320. This will be spliced into the custom type of
  321. `org-agenda-custom-commands'.")
  322. (defcustom org-agenda-custom-commands nil
  323. "Custom commands for the agenda.
  324. These commands will be offered on the splash screen displayed by the
  325. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  326. (key desc type match settings files)
  327. key The key (one or more characters as a string) to be associated
  328. with the command.
  329. desc A description of the command, when omitted or nil, a default
  330. description is built using MATCH.
  331. type The command type, any of the following symbols:
  332. agenda The daily/weekly agenda.
  333. todo Entries with a specific TODO keyword, in all agenda files.
  334. search Entries containing search words entry or headline.
  335. tags Tags/Property/TODO match in all agenda files.
  336. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  337. todo-tree Sparse tree of specific TODO keyword in *current* file.
  338. tags-tree Sparse tree with all tags matches in *current* file.
  339. occur-tree Occur sparse tree for *current* file.
  340. ... A user-defined function.
  341. match What to search for:
  342. - a single keyword for TODO keyword searches
  343. - a tags match expression for tags searches
  344. - a word search expression for text searches.
  345. - a regular expression for occur searches
  346. For all other commands, this should be the empty string.
  347. settings A list of option settings, similar to that in a let form, so like
  348. this: ((opt1 val1) (opt2 val2) ...). The values will be
  349. evaluated at the moment of execution, so quote them when needed.
  350. files A list of files file to write the produced agenda buffer to
  351. with the command `org-store-agenda-views'.
  352. If a file name ends in \".html\", an HTML version of the buffer
  353. is written out. If it ends in \".ps\", a postscript version is
  354. produced. Otherwise, only the plain text is written to the file.
  355. You can also define a set of commands, to create a composite agenda buffer.
  356. In this case, an entry looks like this:
  357. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  358. where
  359. desc A description string to be displayed in the dispatcher menu.
  360. cmd An agenda command, similar to the above. However, tree commands
  361. are no allowed, but instead you can get agenda and global todo list.
  362. So valid commands for a set are:
  363. (agenda \"\" settings)
  364. (alltodo \"\" settings)
  365. (stuck \"\" settings)
  366. (todo \"match\" settings files)
  367. (search \"match\" settings files)
  368. (tags \"match\" settings files)
  369. (tags-todo \"match\" settings files)
  370. Each command can carry a list of options, and another set of options can be
  371. given for the whole set of commands. Individual command options take
  372. precedence over the general options.
  373. When using several characters as key to a command, the first characters
  374. are prefix commands. For the dispatcher to display useful information, you
  375. should provide a description for the prefix, like
  376. (setq org-agenda-custom-commands
  377. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  378. (\"hl\" tags \"+HOME+Lisa\")
  379. (\"hp\" tags \"+HOME+Peter\")
  380. (\"hk\" tags \"+HOME+Kim\")))"
  381. :group 'org-agenda-custom-commands
  382. :type `(repeat
  383. (choice :value ("x" "Describe command here" tags "" nil)
  384. (list :tag "Single command"
  385. (string :tag "Access Key(s) ")
  386. (option (string :tag "Description"))
  387. (choice
  388. (const :tag "Agenda" agenda)
  389. (const :tag "TODO list" alltodo)
  390. (const :tag "Search words" search)
  391. (const :tag "Stuck projects" stuck)
  392. (const :tag "Tags/Property match (all agenda files)" tags)
  393. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  394. (const :tag "TODO keyword search (all agenda files)" todo)
  395. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  396. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  397. (const :tag "Occur tree (current buffer)" occur-tree)
  398. (sexp :tag "Other, user-defined function"))
  399. (string :tag "Match (only for some commands)")
  400. ,org-agenda-custom-commands-local-options
  401. (option (repeat :tag "Export" (file :tag "Export to"))))
  402. (list :tag "Command series, all agenda files"
  403. (string :tag "Access Key(s)")
  404. (string :tag "Description ")
  405. (repeat :tag "Component"
  406. (choice
  407. (list :tag "Agenda"
  408. (const :format "" agenda)
  409. (const :tag "" :format "" "")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "TODO list (all keywords)"
  412. (const :format "" alltodo)
  413. (const :tag "" :format "" "")
  414. ,org-agenda-custom-commands-local-options)
  415. (list :tag "Search words"
  416. (const :format "" search)
  417. (string :tag "Match")
  418. ,org-agenda-custom-commands-local-options)
  419. (list :tag "Stuck projects"
  420. (const :format "" stuck)
  421. (const :tag "" :format "" "")
  422. ,org-agenda-custom-commands-local-options)
  423. (list :tag "Tags search"
  424. (const :format "" tags)
  425. (string :tag "Match")
  426. ,org-agenda-custom-commands-local-options)
  427. (list :tag "Tags search, TODO entries only"
  428. (const :format "" tags-todo)
  429. (string :tag "Match")
  430. ,org-agenda-custom-commands-local-options)
  431. (list :tag "TODO keyword search"
  432. (const :format "" todo)
  433. (string :tag "Match")
  434. ,org-agenda-custom-commands-local-options)
  435. (list :tag "Other, user-defined function"
  436. (symbol :tag "function")
  437. (string :tag "Match")
  438. ,org-agenda-custom-commands-local-options)))
  439. (repeat :tag "Settings for entire command set"
  440. (list (variable :tag "Any variable")
  441. (sexp :tag "Value")))
  442. (option (repeat :tag "Export" (file :tag "Export to"))))
  443. (cons :tag "Prefix key documentation"
  444. (string :tag "Access Key(s)")
  445. (string :tag "Description ")))))
  446. (defcustom org-agenda-query-register ?o
  447. "The register holding the current query string.
  448. The purpose of this is that if you construct a query string interactively,
  449. you can then use it to define a custom command."
  450. :group 'org-agenda-custom-commands
  451. :type 'character)
  452. (defcustom org-stuck-projects
  453. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  454. "How to identify stuck projects.
  455. This is a list of four items:
  456. 1. A tags/todo/property matcher string that is used to identify a project.
  457. See the manual for a description of tag and property searches.
  458. The entire tree below a headline matched by this is considered one project.
  459. 2. A list of TODO keywords identifying non-stuck projects.
  460. If the project subtree contains any headline with one of these todo
  461. keywords, the project is considered to be not stuck. If you specify
  462. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  463. 3. A list of tags identifying non-stuck projects.
  464. If the project subtree contains any headline with one of these tags,
  465. the project is considered to be not stuck. If you specify \"*\" as
  466. a tag, any tag will mark the project unstuck. Note that this is about
  467. the explicit presence of a tag somewhere in the subtree, inherited
  468. tags to not count here. If inherited tags make a project not stuck,
  469. use \"-TAG\" in the tags part of the matcher under (1.) above.
  470. 4. An arbitrary regular expression matching non-stuck projects.
  471. If the project turns out to be not stuck, search continues also in the
  472. subtree to see if any of the subtasks have project status.
  473. See also the variable `org-tags-match-list-sublevels' which applies
  474. to projects matched by this search as well.
  475. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  476. or `C-c a #' to produce the list."
  477. :group 'org-agenda-custom-commands
  478. :type '(list
  479. (string :tag "Tags/TODO match to identify a project")
  480. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  481. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  482. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  483. (defcustom org-agenda-filter-effort-default-operator "<"
  484. "The default operator for effort estimate filtering.
  485. If you select an effort estimate limit without first pressing an operator,
  486. this one will be used."
  487. :group 'org-agenda-custom-commands
  488. :type '(choice (const :tag "less or equal" "<")
  489. (const :tag "greater or equal"">")
  490. (const :tag "equal" "=")))
  491. (defgroup org-agenda-skip nil
  492. "Options concerning skipping parts of agenda files."
  493. :tag "Org Agenda Skip"
  494. :group 'org-agenda)
  495. (defcustom org-agenda-skip-function-global nil
  496. "Function to be called at each match during agenda construction.
  497. If this function returns nil, the current match should not be skipped.
  498. If the function decided to skip an agenda match, is must return the
  499. buffer position from which the search should be continued.
  500. This may also be a Lisp form, which will be evaluated.
  501. This variable will be applied to every agenda match, including
  502. tags/property searches and TODO lists. So try to make the test function
  503. do its checking as efficiently as possible. To implement a skipping
  504. condition just for specific agenda commands, use the variable
  505. `org-agenda-skip-function' which can be set in the options section
  506. of custom agenda commands."
  507. :group 'org-agenda-skip
  508. :type 'sexp)
  509. (defgroup org-agenda-daily/weekly nil
  510. "Options concerning the daily/weekly agenda."
  511. :tag "Org Agenda Daily/Weekly"
  512. :group 'org-agenda)
  513. (defgroup org-agenda-todo-list nil
  514. "Options concerning the global todo list agenda view."
  515. :tag "Org Agenda Todo List"
  516. :group 'org-agenda)
  517. (defgroup org-agenda-match-view nil
  518. "Options concerning the general tags/property/todo match agenda view."
  519. :tag "Org Agenda Match View"
  520. :group 'org-agenda)
  521. (defgroup org-agenda-search-view nil
  522. "Options concerning the general tags/property/todo match agenda view."
  523. :tag "Org Agenda Match View"
  524. :group 'org-agenda)
  525. (defvar org-agenda-archives-mode nil
  526. "Non-nil means the agenda will include archived items.
  527. If this is the symbol `trees', trees in the selected agenda scope
  528. that are marked with the ARCHIVE tag will be included anyway. When this is
  529. t, also all archive files associated with the current selection of agenda
  530. files will be included.")
  531. (defcustom org-agenda-skip-comment-trees t
  532. "Non-nil means skip trees that start with the COMMENT keyword.
  533. When nil, these trees are also scanned by agenda commands."
  534. :group 'org-agenda-skip
  535. :type 'boolean)
  536. (defcustom org-agenda-todo-list-sublevels t
  537. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  538. When nil, the sublevels of a TODO entry are not checked, resulting in
  539. potentially much shorter TODO lists."
  540. :group 'org-agenda-skip
  541. :group 'org-agenda-todo-list
  542. :type 'boolean)
  543. (defcustom org-agenda-todo-ignore-with-date nil
  544. "Non-nil means don't show entries with a date in the global todo list.
  545. You can use this if you prefer to mark mere appointments with a TODO keyword,
  546. but don't want them to show up in the TODO list.
  547. When this is set, it also covers deadlines and scheduled items, the settings
  548. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  549. will be ignored.
  550. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  551. :group 'org-agenda-skip
  552. :group 'org-agenda-todo-list
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-ignore-timestamp nil
  555. "Non-nil means don't show entries with a timestamp.
  556. This applies when creating the global todo list.
  557. Valid values are:
  558. past Don't show entries for today or in the past.
  559. future Don't show entries with a timestamp in the future.
  560. The idea behind this is that if it has a future
  561. timestamp, you don't want to think about it until the
  562. date.
  563. all Don't show any entries with a timestamp in the global todo list.
  564. The idea behind this is that by setting a timestamp, you
  565. have already \"taken care\" of this item.
  566. This variable can also have an integer as a value. If positive (N),
  567. todos with a timestamp N or more days in the future will be ignored. If
  568. negative (-N), todos with a timestamp N or more days in the past will be
  569. ignored. If 0, todos with a timestamp either today or in the future will
  570. be ignored. For example, a value of -1 will exclude todos with a
  571. timestamp in the past (yesterday or earlier), while a value of 7 will
  572. exclude todos with a timestamp a week or more in the future.
  573. See also `org-agenda-todo-ignore-with-date'.
  574. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  575. to make his option also apply to the tags-todo list."
  576. :group 'org-agenda-skip
  577. :group 'org-agenda-todo-list
  578. :type '(choice
  579. (const :tag "Ignore future timestamp todos" future)
  580. (const :tag "Ignore past or present timestamp todos" past)
  581. (const :tag "Ignore all timestamp todos" all)
  582. (const :tag "Show timestamp todos" nil)
  583. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  584. (defcustom org-agenda-todo-ignore-scheduled nil
  585. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  586. This applies when creating the global todo list.
  587. Valid values are:
  588. past Don't show entries scheduled today or in the past.
  589. future Don't show entries scheduled in the future.
  590. The idea behind this is that by scheduling it, you don't want to
  591. think about it until the scheduled date.
  592. all Don't show any scheduled entries in the global todo list.
  593. The idea behind this is that by scheduling it, you have already
  594. \"taken care\" of this item.
  595. t Same as `all', for backward compatibility.
  596. This variable can also have an integer as a value. See
  597. `org-agenda-todo-ignore-timestamp' for more details.
  598. See also `org-agenda-todo-ignore-with-date'.
  599. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  600. to make his option also apply to the tags-todo list."
  601. :group 'org-agenda-skip
  602. :group 'org-agenda-todo-list
  603. :type '(choice
  604. (const :tag "Ignore future-scheduled todos" future)
  605. (const :tag "Ignore past- or present-scheduled todos" past)
  606. (const :tag "Ignore all scheduled todos" all)
  607. (const :tag "Ignore all scheduled todos (compatibility)" t)
  608. (const :tag "Show scheduled todos" nil)
  609. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  610. (defcustom org-agenda-todo-ignore-deadlines nil
  611. "Non-nil means ignore some deadlined TODO items when making TODO list.
  612. There are different motivations for using different values, please think
  613. carefully when configuring this variable.
  614. This applies when creating the global todo list.
  615. Valid values are:
  616. near Don't show near deadline entries. A deadline is near when it is
  617. closer than `org-deadline-warning-days' days. The idea behind this
  618. is that such items will appear in the agenda anyway.
  619. far Don't show TODO entries where a deadline has been defined, but
  620. the deadline is not near. This is useful if you don't want to
  621. use the todo list to figure out what to do now.
  622. past Don't show entries with a deadline timestamp for today or in the past.
  623. future Don't show entries with a deadline timestamp in the future, not even
  624. when they become `near' ones. Use it with caution.
  625. all Ignore all TODO entries that do have a deadline.
  626. t Same as `near', for backward compatibility.
  627. This variable can also have an integer as a value. See
  628. `org-agenda-todo-ignore-timestamp' for more details.
  629. See also `org-agenda-todo-ignore-with-date'.
  630. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  631. to make his option also apply to the tags-todo list."
  632. :group 'org-agenda-skip
  633. :group 'org-agenda-todo-list
  634. :type '(choice
  635. (const :tag "Ignore near deadlines" near)
  636. (const :tag "Ignore near deadlines (compatibility)" t)
  637. (const :tag "Ignore far deadlines" far)
  638. (const :tag "Ignore all TODOs with a deadlines" all)
  639. (const :tag "Show all TODOs, even if they have a deadline" nil)
  640. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  641. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  642. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  643. The variables
  644. `org-agenda-todo-ignore-with-date',
  645. `org-agenda-todo-ignore-timestamp',
  646. `org-agenda-todo-ignore-scheduled',
  647. `org-agenda-todo-ignore-deadlines'
  648. make the global TODO list skip entries that have time stamps of certain
  649. kinds. If this option is set, the same options will also apply for the
  650. tags-todo search, which is the general tags/property matcher
  651. restricted to unfinished TODO entries only."
  652. :group 'org-agenda-skip
  653. :group 'org-agenda-todo-list
  654. :group 'org-agenda-match-view
  655. :type 'boolean)
  656. (defcustom org-agenda-skip-scheduled-if-done nil
  657. "Non-nil means don't show scheduled items in agenda when they are done.
  658. This is relevant for the daily/weekly agenda, not for the TODO list. And
  659. it applies only to the actual date of the scheduling. Warnings about
  660. an item with a past scheduling dates are always turned off when the item
  661. is DONE."
  662. :group 'org-agenda-skip
  663. :group 'org-agenda-daily/weekly
  664. :type 'boolean)
  665. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  666. "Non-nil means skip scheduling line if same entry shows because of deadline.
  667. In the agenda of today, an entry can show up multiple times because
  668. it is both scheduled and has a nearby deadline, and maybe a plain time
  669. stamp as well.
  670. When this variable is t, then only the deadline is shown and the fact that
  671. the entry is scheduled today or was scheduled previously is not shown.
  672. When this variable is nil, the entry will be shown several times. When
  673. the variable is the symbol `not-today', then skip scheduled previously,
  674. but not scheduled today."
  675. :group 'org-agenda-skip
  676. :group 'org-agenda-daily/weekly
  677. :type '(choice
  678. (const :tag "Never" nil)
  679. (const :tag "Always" t)
  680. (const :tag "Not when scheduled today" not-today)))
  681. (defcustom org-agenda-skip-deadline-if-done nil
  682. "Non-nil means don't show deadlines when the corresponding item is done.
  683. When nil, the deadline is still shown and should give you a happy feeling.
  684. This is relevant for the daily/weekly agenda. And it applied only to the
  685. actually date of the deadline. Warnings about approaching and past-due
  686. deadlines are always turned off when the item is DONE."
  687. :group 'org-agenda-skip
  688. :group 'org-agenda-daily/weekly
  689. :type 'boolean)
  690. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  691. "Non-nil means skip deadline prewarning when entry is also scheduled.
  692. This will apply on all days where a prewarning for the deadline would
  693. be shown, but not at the day when the entry is actually due. On that day,
  694. the deadline will be shown anyway.
  695. This variable may be set to nil, t, or a number which will then give
  696. the number of days before the actual deadline when the prewarnings
  697. should resume.
  698. This can be used in a workflow where the first showing of the deadline will
  699. trigger you to schedule it, and then you don't want to be reminded of it
  700. because you will take care of it on the day when scheduled."
  701. :group 'org-agenda-skip
  702. :group 'org-agenda-daily/weekly
  703. :type '(choice
  704. (const :tag "Alwas show prewarning" nil)
  705. (const :tag "Remove prewarning if entry is scheduled" t)
  706. (integer :tag "Restart prewarning N days before deadline")))
  707. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  708. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  709. When non-nil, after the search for timestamps has matched once in an
  710. entry, the rest of the entry will not be searched."
  711. :group 'org-agenda-skip
  712. :type 'boolean)
  713. (defcustom org-agenda-skip-timestamp-if-done nil
  714. "Non-nil means don't select item by timestamp or -range if it is DONE."
  715. :group 'org-agenda-skip
  716. :group 'org-agenda-daily/weekly
  717. :type 'boolean)
  718. (defcustom org-agenda-dim-blocked-tasks t
  719. "Non-nil means dim blocked tasks in the agenda display.
  720. This causes some overhead during agenda construction, but if you
  721. have turned on `org-enforce-todo-dependencies',
  722. `org-enforce-todo-checkbox-dependencies', or any other blocking
  723. mechanism, this will create useful feedback in the agenda.
  724. Instead of t, this variable can also have the value `invisible'.
  725. Then blocked tasks will be invisible and only become visible when
  726. they become unblocked. An exemption to this behavior is when a task is
  727. blocked because of unchecked checkboxes below it. Since checkboxes do
  728. not show up in the agenda views, making this task invisible you remove any
  729. trace from agenda views that there is something to do. Therefore, a task
  730. that is blocked because of checkboxes will never be made invisible, it
  731. will only be dimmed."
  732. :group 'org-agenda-daily/weekly
  733. :group 'org-agenda-todo-list
  734. :type '(choice
  735. (const :tag "Do not dim" nil)
  736. (const :tag "Dim to a grey face" t)
  737. (const :tag "Make invisible" invisible)))
  738. (defcustom org-timeline-show-empty-dates 3
  739. "Non-nil means `org-timeline' also shows dates without an entry.
  740. When nil, only the days which actually have entries are shown.
  741. When t, all days between the first and the last date are shown.
  742. When an integer, show also empty dates, but if there is a gap of more than
  743. N days, just insert a special line indicating the size of the gap."
  744. :group 'org-agenda-skip
  745. :type '(choice
  746. (const :tag "None" nil)
  747. (const :tag "All" t)
  748. (integer :tag "at most")))
  749. (defgroup org-agenda-startup nil
  750. "Options concerning initial settings in the Agenda in Org Mode."
  751. :tag "Org Agenda Startup"
  752. :group 'org-agenda)
  753. (defcustom org-agenda-menu-show-matcher t
  754. "Non-nil means show the match string in the agenda dispatcher menu.
  755. When nil, the matcher string is not shown, but is put into the help-echo
  756. property so than moving the mouse over the command shows it.
  757. Setting it to nil is good if matcher strings are very long and/or if
  758. you want to use two-column display (see `org-agenda-menu-two-column')."
  759. :group 'org-agenda
  760. :type 'boolean)
  761. (defcustom org-agenda-menu-two-column nil
  762. "Non-nil means, use two columns to show custom commands in the dispatcher.
  763. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  764. to nil."
  765. :group 'org-agenda
  766. :type 'boolean)
  767. (defcustom org-finalize-agenda-hook nil
  768. "Hook run just before displaying an agenda buffer."
  769. :group 'org-agenda-startup
  770. :type 'hook)
  771. (defcustom org-agenda-mouse-1-follows-link nil
  772. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  773. A longer mouse click will still set point. Does not work on XEmacs.
  774. Needs to be set before org.el is loaded."
  775. :group 'org-agenda-startup
  776. :type 'boolean)
  777. (defcustom org-agenda-start-with-follow-mode nil
  778. "The initial value of follow mode in a newly created agenda window."
  779. :group 'org-agenda-startup
  780. :type 'boolean)
  781. (defcustom org-agenda-show-outline-path t
  782. "Non-nil means show outline path in echo area after line motion."
  783. :group 'org-agenda-startup
  784. :type 'boolean)
  785. (defcustom org-agenda-start-with-entry-text-mode nil
  786. "The initial value of entry-text-mode in a newly created agenda window."
  787. :group 'org-agenda-startup
  788. :type 'boolean)
  789. (defcustom org-agenda-entry-text-maxlines 5
  790. "Number of text lines to be added when `E' is pressed in the agenda.
  791. Note that this variable only used during agenda display. Add add entry text
  792. when exporting the agenda, configure the variable
  793. `org-agenda-add-entry-ext-maxlines'."
  794. :group 'org-agenda
  795. :type 'integer)
  796. (defcustom org-agenda-entry-text-exclude-regexps nil
  797. "List of regular expressions to clean up entry text.
  798. The complete matches of all regular expressions in this list will be
  799. removed from entry text before it is shown in the agenda."
  800. :group 'org-agenda
  801. :type '(repeat (regexp)))
  802. (defvar org-agenda-entry-text-cleanup-hook nil
  803. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  804. This cleanup is done in a temporary buffer, so the function may inspect and
  805. change the entire buffer.
  806. Some default stuff like drawers and scheduling/deadline dates will already
  807. have been removed when this is called, as will any matches for regular
  808. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  809. (defvar org-agenda-include-inactive-timestamps nil
  810. "Non-nil means include inactive time stamps in agenda and timeline.")
  811. (defgroup org-agenda-windows nil
  812. "Options concerning the windows used by the Agenda in Org Mode."
  813. :tag "Org Agenda Windows"
  814. :group 'org-agenda)
  815. (defcustom org-agenda-window-setup 'reorganize-frame
  816. "How the agenda buffer should be displayed.
  817. Possible values for this option are:
  818. current-window Show agenda in the current window, keeping all other windows.
  819. other-window Use `switch-to-buffer-other-window' to display agenda.
  820. reorganize-frame Show only two windows on the current frame, the current
  821. window and the agenda.
  822. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  823. Also, when exiting the agenda, kill that frame.
  824. See also the variable `org-agenda-restore-windows-after-quit'."
  825. :group 'org-agenda-windows
  826. :type '(choice
  827. (const current-window)
  828. (const other-frame)
  829. (const other-window)
  830. (const reorganize-frame)))
  831. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  832. "The min and max height of the agenda window as a fraction of frame height.
  833. The value of the variable is a cons cell with two numbers between 0 and 1.
  834. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  835. :group 'org-agenda-windows
  836. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  837. (defcustom org-agenda-restore-windows-after-quit nil
  838. "Non-nil means restore window configuration upon exiting agenda.
  839. Before the window configuration is changed for displaying the agenda,
  840. the current status is recorded. When the agenda is exited with
  841. `q' or `x' and this option is set, the old state is restored. If
  842. `org-agenda-window-setup' is `other-frame', the value of this
  843. option will be ignored."
  844. :group 'org-agenda-windows
  845. :type 'boolean)
  846. (defcustom org-agenda-ndays nil
  847. "Number of days to include in overview display.
  848. Should be 1 or 7.
  849. Obsolete, see `org-agenda-span'."
  850. :group 'org-agenda-daily/weekly
  851. :type 'integer)
  852. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  853. (defcustom org-agenda-span 'week
  854. "Number of days to include in overview display.
  855. Can be day, week, month, year, or any number of days.
  856. Custom commands can set this variable in the options section."
  857. :group 'org-agenda-daily/weekly
  858. :type '(choice (const :tag "Day" day)
  859. (const :tag "Week" week)
  860. (const :tag "Month" month)
  861. (const :tag "Year" year)
  862. (integer :tag "Custom")))
  863. (defcustom org-agenda-start-on-weekday 1
  864. "Non-nil means start the overview always on the specified weekday.
  865. 0 denotes Sunday, 1 denotes Monday etc.
  866. When nil, always start on the current day.
  867. Custom commands can set this variable in the options section."
  868. :group 'org-agenda-daily/weekly
  869. :type '(choice (const :tag "Today" nil)
  870. (integer :tag "Weekday No.")))
  871. (defcustom org-agenda-show-all-dates t
  872. "Non-nil means `org-agenda' shows every day in the selected range.
  873. When nil, only the days which actually have entries are shown."
  874. :group 'org-agenda-daily/weekly
  875. :type 'boolean)
  876. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  877. "Format string for displaying dates in the agenda.
  878. Used by the daily/weekly agenda and by the timeline. This should be
  879. a format string understood by `format-time-string', or a function returning
  880. the formatted date as a string. The function must take a single argument,
  881. a calendar-style date list like (month day year)."
  882. :group 'org-agenda-daily/weekly
  883. :type '(choice
  884. (string :tag "Format string")
  885. (function :tag "Function")))
  886. (defun org-agenda-format-date-aligned (date)
  887. "Format a date string for display in the daily/weekly agenda, or timeline.
  888. This function makes sure that dates are aligned for easy reading."
  889. (require 'cal-iso)
  890. (let* ((dayname (calendar-day-name date))
  891. (day (cadr date))
  892. (day-of-week (calendar-day-of-week date))
  893. (month (car date))
  894. (monthname (calendar-month-name month))
  895. (year (nth 2 date))
  896. (iso-week (org-days-to-iso-week
  897. (calendar-absolute-from-gregorian date)))
  898. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  899. (1- year))
  900. ((and (= month 12) (<= iso-week 1))
  901. (1+ year))
  902. (t year)))
  903. (weekstring (if (= day-of-week 1)
  904. (format " W%02d" iso-week)
  905. "")))
  906. (format "%-10s %2d %s %4d%s"
  907. dayname day monthname year weekstring)))
  908. (defcustom org-agenda-time-leading-zero nil
  909. "Non-nil means use leading zero for military times in agenda.
  910. For example, 9:30am would become 09:30 rather than 9:30."
  911. :group 'org-agenda-daily/weekly
  912. :type 'boolean)
  913. (defcustom org-agenda-timegrid-use-ampm nil
  914. "When set, show AM/PM style timestamps on the timegrid."
  915. :group 'org-agenda
  916. :type 'boolean)
  917. (defun org-agenda-time-of-day-to-ampm (time)
  918. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  919. (let* ((hour-number (string-to-number (substring time 0 -3)))
  920. (minute (substring time -2))
  921. (ampm "am"))
  922. (cond
  923. ((equal hour-number 12)
  924. (setq ampm "pm"))
  925. ((> hour-number 12)
  926. (setq ampm "pm")
  927. (setq hour-number (- hour-number 12))))
  928. (concat
  929. (if org-agenda-time-leading-zero
  930. (format "%02d" hour-number)
  931. (format "%02s" (number-to-string hour-number)))
  932. ":" minute ampm)))
  933. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  934. "Conditionally convert TIME to AM/PM format
  935. based on `org-agenda-timegrid-use-ampm'"
  936. (if org-agenda-timegrid-use-ampm
  937. (org-agenda-time-of-day-to-ampm time)
  938. time))
  939. (defcustom org-agenda-weekend-days '(6 0)
  940. "Which days are weekend?
  941. These days get the special face `org-agenda-date-weekend' in the agenda
  942. and timeline buffers."
  943. :group 'org-agenda-daily/weekly
  944. :type '(set :greedy t
  945. (const :tag "Monday" 1)
  946. (const :tag "Tuesday" 2)
  947. (const :tag "Wednesday" 3)
  948. (const :tag "Thursday" 4)
  949. (const :tag "Friday" 5)
  950. (const :tag "Saturday" 6)
  951. (const :tag "Sunday" 0)))
  952. (defcustom org-agenda-include-diary nil
  953. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  954. Custom commands can set this variable in the options section."
  955. :group 'org-agenda-daily/weekly
  956. :type 'boolean)
  957. (defcustom org-agenda-include-deadlines t
  958. "If non-nil, include entries within their deadline warning period.
  959. Custom commands can set this variable in the options section."
  960. :group 'org-agenda-daily/weekly
  961. :type 'boolean)
  962. (defcustom org-agenda-include-all-todo nil
  963. "Set means weekly/daily agenda will always contain all TODO entries.
  964. The TODO entries will be listed at the top of the agenda, before
  965. the entries for specific days.
  966. This option is deprecated, it is better to define a block agenda instead."
  967. :group 'org-agenda-daily/weekly
  968. :type 'boolean)
  969. (defcustom org-agenda-repeating-timestamp-show-all t
  970. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  971. When set to a list of strings, only show occurrences of repeating
  972. stamps for these TODO keywords. When nil, only one occurrence is
  973. shown, either today or the nearest into the future."
  974. :group 'org-agenda-daily/weekly
  975. :type '(choice
  976. (const :tag "Show repeating stamps" t)
  977. (repeat :tag "Show repeating stamps for these TODO keywords"
  978. (string :tag "TODO Keyword"))
  979. (const :tag "Don't show repeating stamps" nil)))
  980. (defcustom org-scheduled-past-days 10000
  981. "No. of days to continue listing scheduled items that are not marked DONE.
  982. When an item is scheduled on a date, it shows up in the agenda on this
  983. day and will be listed until it is marked done for the number of days
  984. given here."
  985. :group 'org-agenda-daily/weekly
  986. :type 'integer)
  987. (defcustom org-agenda-log-mode-items '(closed clock)
  988. "List of items that should be shown in agenda log mode.
  989. This list may contain the following symbols:
  990. closed Show entries that have been closed on that day.
  991. clock Show entries that have received clocked time on that day.
  992. state Show all logged state changes.
  993. Note that instead of changing this variable, you can also press `C-u l' in
  994. the agenda to display all available LOG items temporarily."
  995. :group 'org-agenda-daily/weekly
  996. :type '(set :greedy t (const closed) (const clock) (const state)))
  997. (defcustom org-agenda-clock-consistency-checks
  998. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  999. :gap-ok-around ("4:00")
  1000. :default-face ((:background "DarkRed") (:foreground "white"))
  1001. :overlap-face nil :gap-face nil :no-end-time-face nil
  1002. :long-face nil :short-face nil)
  1003. "This is a property list, with the following keys:
  1004. :max-duration Mark clocking chunks that are longer than this time.
  1005. This is a time string like \"HH:MM\", or the number
  1006. of minutes as an integer.
  1007. :min-duration Mark clocking chunks that are shorter that this.
  1008. This is a time string like \"HH:MM\", or the number
  1009. of minutes as an integer.
  1010. :max-gap Mark gaps between clocking chunks that are longer than
  1011. this duration. A number of minutes, or a string
  1012. like \"HH:MM\".
  1013. :gap-ok-around List of times during the day which are usually not working
  1014. times. When a gap is detected, but the gap contains any
  1015. of these times, the gap is *not* reported. For example,
  1016. if this is (\"4:00\" \"13:00\") then gaps that contain
  1017. 4:00 in the morning (i.e. the night) and 13:00
  1018. (i.e. a typical lunch time) do not cause a warning.
  1019. You should have at least one time during the night in this
  1020. list, or otherwise the first task each morning will trigger
  1021. a warning because it follows a long gap.
  1022. Furthermore, the following properties can be used to define faces for
  1023. issue display.
  1024. :default-face the default face, if the specific face is undefined
  1025. :overlap-face face for overlapping clocks
  1026. :gap-face face for gaps between clocks
  1027. :no-end-time-face face for incomplete clocks
  1028. :long-face face for clock intervals that are too long
  1029. :short-face face for clock intervals that are too short"
  1030. :group 'org-agenda-daily/weekly
  1031. :group 'org-clock
  1032. :type 'plist)
  1033. (defcustom org-agenda-log-mode-add-notes t
  1034. "Non-nil means add first line of notes to log entries in agenda views.
  1035. If a log item like a state change or a clock entry is associated with
  1036. notes, the first line of these notes will be added to the entry in the
  1037. agenda display."
  1038. :group 'org-agenda-daily/weekly
  1039. :type 'boolean)
  1040. (defcustom org-agenda-start-with-log-mode nil
  1041. "The initial value of log-mode in a newly created agenda window."
  1042. :group 'org-agenda-startup
  1043. :group 'org-agenda-daily/weekly
  1044. :type 'boolean)
  1045. (defcustom org-agenda-start-with-clockreport-mode nil
  1046. "The initial value of clockreport-mode in a newly created agenda window."
  1047. :group 'org-agenda-startup
  1048. :group 'org-agenda-daily/weekly
  1049. :type 'boolean)
  1050. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1051. "Property list with parameters for the clocktable in clockreport mode.
  1052. This is the display mode that shows a clock table in the daily/weekly
  1053. agenda, the properties for this dynamic block can be set here.
  1054. The usual clocktable parameters are allowed here, but you cannot set
  1055. the properties :name, :tstart, :tend, :block, and :scope - these will
  1056. be overwritten to make sure the content accurately reflects the
  1057. current display in the agenda."
  1058. :group 'org-agenda-daily/weekly
  1059. :type 'plist)
  1060. (defcustom org-agenda-search-view-always-boolean nil
  1061. "Non-nil means the search string is interpreted as individual parts.
  1062. The search string for search view can either be interpreted as a phrase,
  1063. or as a list of snippets that define a boolean search for a number of
  1064. strings.
  1065. When this is non-nil, the string will be split on whitespace, and each
  1066. snippet will be searched individually, and all must match in order to
  1067. select an entry. A snippet is then a single string of non-white
  1068. characters, or a string in double quotes, or a regexp in {} braces.
  1069. If a snippet is preceded by \"-\", the snippet must *not* match.
  1070. \"+\" is syntactic sugar for positive selection. Each snippet may
  1071. be found as a full word or a partial word, but see the variable
  1072. `org-agenda-search-view-force-full-words'.
  1073. When this is nil, search will look for the entire search phrase as one,
  1074. with each space character matching any amount of whitespace, including
  1075. line breaks.
  1076. Even when this is nil, you can still switch to Boolean search dynamically
  1077. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1078. is a regexp marked with braces like \"{abc}\", this will also switch to
  1079. boolean search."
  1080. :group 'org-agenda-search-view
  1081. :type 'boolean)
  1082. (if (fboundp 'defvaralias)
  1083. (defvaralias 'org-agenda-search-view-search-words-only
  1084. 'org-agenda-search-view-always-boolean))
  1085. (defcustom org-agenda-search-view-force-full-words nil
  1086. "Non-nil means, search words must be matches as complete words.
  1087. When nil, they may also match part of a word."
  1088. :group 'org-agenda-search-view
  1089. :type 'boolean)
  1090. (defgroup org-agenda-time-grid nil
  1091. "Options concerning the time grid in the Org-mode Agenda."
  1092. :tag "Org Agenda Time Grid"
  1093. :group 'org-agenda)
  1094. (defcustom org-agenda-search-headline-for-time t
  1095. "Non-nil means search headline for a time-of-day.
  1096. If the headline contains a time-of-day in one format or another, it will
  1097. be used to sort the entry into the time sequence of items for a day.
  1098. Some people have time stamps in the headline that refer to the creation
  1099. time or so, and then this produces an unwanted side effect. If this is
  1100. the case for your, use this variable to turn off searching the headline
  1101. for a time."
  1102. :group 'org-agenda-time-grid
  1103. :type 'boolean)
  1104. (defcustom org-agenda-use-time-grid t
  1105. "Non-nil means show a time grid in the agenda schedule.
  1106. A time grid is a set of lines for specific times (like every two hours between
  1107. 8:00 and 20:00). The items scheduled for a day at specific times are
  1108. sorted in between these lines.
  1109. For details about when the grid will be shown, and what it will look like, see
  1110. the variable `org-agenda-time-grid'."
  1111. :group 'org-agenda-time-grid
  1112. :type 'boolean)
  1113. (defcustom org-agenda-time-grid
  1114. '((daily today require-timed)
  1115. "----------------"
  1116. (800 1000 1200 1400 1600 1800 2000))
  1117. "The settings for time grid for agenda display.
  1118. This is a list of three items. The first item is again a list. It contains
  1119. symbols specifying conditions when the grid should be displayed:
  1120. daily if the agenda shows a single day
  1121. weekly if the agenda shows an entire week
  1122. today show grid on current date, independent of daily/weekly display
  1123. require-timed show grid only if at least one item has a time specification
  1124. The second item is a string which will be placed behind the grid time.
  1125. The third item is a list of integers, indicating the times that should have
  1126. a grid line."
  1127. :group 'org-agenda-time-grid
  1128. :type
  1129. '(list
  1130. (set :greedy t :tag "Grid Display Options"
  1131. (const :tag "Show grid in single day agenda display" daily)
  1132. (const :tag "Show grid in weekly agenda display" weekly)
  1133. (const :tag "Always show grid for today" today)
  1134. (const :tag "Show grid only if any timed entries are present"
  1135. require-timed)
  1136. (const :tag "Skip grid times already present in an entry"
  1137. remove-match))
  1138. (string :tag "Grid String")
  1139. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1140. (defcustom org-agenda-show-current-time-in-grid t
  1141. "Non-nil means show the current time in the time grid."
  1142. :group 'org-agenda-time-grid
  1143. :type 'boolean)
  1144. (defcustom org-agenda-current-time-string
  1145. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1146. "The string for the current time marker in the agenda."
  1147. :group 'org-agenda-time-grid
  1148. :type 'string)
  1149. (defgroup org-agenda-sorting nil
  1150. "Options concerning sorting in the Org-mode Agenda."
  1151. :tag "Org Agenda Sorting"
  1152. :group 'org-agenda)
  1153. (defcustom org-agenda-sorting-strategy
  1154. '((agenda habit-down time-up priority-down category-keep)
  1155. (todo priority-down category-keep)
  1156. (tags priority-down category-keep)
  1157. (search category-keep))
  1158. "Sorting structure for the agenda items of a single day.
  1159. This is a list of symbols which will be used in sequence to determine
  1160. if an entry should be listed before another entry. The following
  1161. symbols are recognized:
  1162. time-up Put entries with time-of-day indications first, early first
  1163. time-down Put entries with time-of-day indications first, late first
  1164. category-keep Keep the default order of categories, corresponding to the
  1165. sequence in `org-agenda-files'.
  1166. category-up Sort alphabetically by category, A-Z.
  1167. category-down Sort alphabetically by category, Z-A.
  1168. tag-up Sort alphabetically by last tag, A-Z.
  1169. tag-down Sort alphabetically by last tag, Z-A.
  1170. priority-up Sort numerically by priority, high priority last.
  1171. priority-down Sort numerically by priority, high priority first.
  1172. todo-state-up Sort by todo state, tasks that are done last.
  1173. todo-state-down Sort by todo state, tasks that are done first.
  1174. effort-up Sort numerically by estimated effort, high effort last.
  1175. effort-down Sort numerically by estimated effort, high effort first.
  1176. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1177. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1178. habit-up Put entries that are habits first
  1179. habit-down Put entries that are habits last
  1180. alpha-up Sort headlines alphabetically
  1181. alpha-down Sort headlines alphabetically, reversed
  1182. The different possibilities will be tried in sequence, and testing stops
  1183. if one comparison returns a \"not-equal\". For example, the default
  1184. '(time-up category-keep priority-down)
  1185. means: Pull out all entries having a specified time of day and sort them,
  1186. in order to make a time schedule for the current day the first thing in the
  1187. agenda listing for the day. Of the entries without a time indication, keep
  1188. the grouped in categories, don't sort the categories, but keep them in
  1189. the sequence given in `org-agenda-files'. Within each category sort by
  1190. priority.
  1191. Leaving out `category-keep' would mean that items will be sorted across
  1192. categories by priority.
  1193. Instead of a single list, this can also be a set of list for specific
  1194. contents, with a context symbol in the car of the list, any of
  1195. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1196. Custom commands can bind this variable in the options section."
  1197. :group 'org-agenda-sorting
  1198. :type `(choice
  1199. (repeat :tag "General" ,org-sorting-choice)
  1200. (list :tag "Individually"
  1201. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1202. (repeat ,org-sorting-choice))
  1203. (cons (const :tag "Strategy for TODO lists" todo)
  1204. (repeat ,org-sorting-choice))
  1205. (cons (const :tag "Strategy for Tags matches" tags)
  1206. (repeat ,org-sorting-choice))
  1207. (cons (const :tag "Strategy for search matches" search)
  1208. (repeat ,org-sorting-choice)))))
  1209. (defcustom org-agenda-cmp-user-defined nil
  1210. "A function to define the comparison `user-defined'.
  1211. This function must receive two arguments, agenda entry a and b.
  1212. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1213. the user comparison, return nil.
  1214. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1215. part of an agenda sorting strategy."
  1216. :group 'org-agenda-sorting
  1217. :type 'symbol)
  1218. (defcustom org-sort-agenda-notime-is-late t
  1219. "Non-nil means items without time are considered late.
  1220. This is only relevant for sorting. When t, items which have no explicit
  1221. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1222. do have a time. When nil, the default time is before 0:00. You can use this
  1223. option to decide if the schedule for today should come before or after timeless
  1224. agenda entries."
  1225. :group 'org-agenda-sorting
  1226. :type 'boolean)
  1227. (defcustom org-sort-agenda-noeffort-is-high t
  1228. "Non-nil means items without effort estimate are sorted as high effort.
  1229. This also applies when filtering an agenda view with respect to the
  1230. < or > effort operator. Then, tasks with no effort defined will be treated
  1231. as tasks with high effort.
  1232. When nil, such items are sorted as 0 minutes effort."
  1233. :group 'org-agenda-sorting
  1234. :type 'boolean)
  1235. (defgroup org-agenda-line-format nil
  1236. "Options concerning the entry prefix in the Org-mode agenda display."
  1237. :tag "Org Agenda Line Format"
  1238. :group 'org-agenda)
  1239. (defcustom org-agenda-prefix-format
  1240. '((agenda . " %i %-12:c%?-12t% s")
  1241. (timeline . " % s")
  1242. (todo . " %i %-12:c")
  1243. (tags . " %i %-12:c")
  1244. (search . " %i %-12:c"))
  1245. "Format specifications for the prefix of items in the agenda views.
  1246. An alist with five entries, each for the different agenda types. The
  1247. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1248. The values are format strings.
  1249. This format works similar to a printf format, with the following meaning:
  1250. %c the category of the item, \"Diary\" for entries from the diary,
  1251. or as given by the CATEGORY keyword or derived from the file name
  1252. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1253. %T the last tag of the item (ignore inherited tags, which come first)
  1254. %t the HH:MM time-of-day specification if one applies to the entry
  1255. %s Scheduling/Deadline information, a short string
  1256. %(expression) Eval EXPRESSION and replace the control string
  1257. by the result
  1258. All specifiers work basically like the standard `%s' of printf, but may
  1259. contain two additional characters: a question mark just after the `%'
  1260. and a whitespace/punctuation character just before the final letter.
  1261. If the first character after `%' is a question mark, the entire field
  1262. will only be included if the corresponding value applies to the current
  1263. entry. This is useful for fields which should have fixed width when
  1264. present, but zero width when absent. For example, \"%?-12t\" will
  1265. result in a 12 character time field if a time of the day is specified,
  1266. but will completely disappear in entries which do not contain a time.
  1267. If there is punctuation or whitespace character just before the final
  1268. format letter, this character will be appended to the field value if
  1269. the value is not empty. For example, the format \"%-12:c\" leads to
  1270. \"Diary: \" if the category is \"Diary\". If the category were be
  1271. empty, no additional colon would be inserted.
  1272. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1273. which means:
  1274. - Indent the line with two space characters
  1275. - Give the category a 12 chars wide field, padded with whitespace on
  1276. the right (because of `-'). Append a colon if there is a category
  1277. (because of `:').
  1278. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1279. time, don't put in an empty field, just skip it (because of '?').
  1280. - Finally, put the scheduling information.
  1281. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1282. `org-agenda-remove-tags'.
  1283. Custom commands can set this variable in the options section."
  1284. :type '(choice
  1285. (string :tag "General format")
  1286. (list :greedy t :tag "View dependent"
  1287. (cons (const agenda) (string :tag "Format"))
  1288. (cons (const timeline) (string :tag "Format"))
  1289. (cons (const todo) (string :tag "Format"))
  1290. (cons (const tags) (string :tag "Format"))
  1291. (cons (const search) (string :tag "Format"))))
  1292. :group 'org-agenda-line-format)
  1293. (defvar org-prefix-format-compiled nil
  1294. "The compiled version of the most recently used prefix format.
  1295. See the variable `org-agenda-prefix-format'.")
  1296. (defcustom org-agenda-todo-keyword-format "%-1s"
  1297. "Format for the TODO keyword in agenda lines.
  1298. Set this to something like \"%-12s\" if you want all TODO keywords
  1299. to occupy a fixed space in the agenda display."
  1300. :group 'org-agenda-line-format
  1301. :type 'string)
  1302. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1303. "Text preceding timerange entries in the agenda view.
  1304. This is a list with two strings. The first applies when the range
  1305. is entirely on one day. The second applies if the range spans several days.
  1306. The strings may have two \"%d\" format specifiers which will be filled
  1307. with the sequence number of the days, and the total number of days in the
  1308. range, respectively."
  1309. :group 'org-agenda-line-format
  1310. :type '(list
  1311. (string :tag "Deadline today ")
  1312. (choice :tag "Deadline relative"
  1313. (string :tag "Format string")
  1314. (function))))
  1315. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1316. "Text preceding scheduled items in the agenda view.
  1317. This is a list with two strings. The first applies when the item is
  1318. scheduled on the current day. The second applies when it has been scheduled
  1319. previously, it may contain a %d indicating that this is the nth time that
  1320. this item is scheduled, due to automatic rescheduling of unfinished items
  1321. for the following day. So this number is one larger than the number of days
  1322. that passed since this item was scheduled first."
  1323. :group 'org-agenda-line-format
  1324. :type '(list
  1325. (string :tag "Scheduled today ")
  1326. (string :tag "Scheduled previously")))
  1327. (defcustom org-agenda-inactive-leader "["
  1328. "Text preceding item pulled into the agenda by inactive time stamps.
  1329. These entries are added to the agenda when pressing \"[\"."
  1330. :group 'org-agenda-line-format
  1331. :type '(list
  1332. (string :tag "Scheduled today ")
  1333. (string :tag "Scheduled previously")))
  1334. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1335. "Text preceding deadline items in the agenda view.
  1336. This is a list with two strings. The first applies when the item has its
  1337. deadline on the current day. The second applies when it is in the past or
  1338. in the future, it may contain %d to capture how many days away the deadline
  1339. is (was)."
  1340. :group 'org-agenda-line-format
  1341. :type '(list
  1342. (string :tag "Deadline today ")
  1343. (choice :tag "Deadline relative"
  1344. (string :tag "Format string")
  1345. (function))))
  1346. (defcustom org-agenda-remove-times-when-in-prefix t
  1347. "Non-nil means remove duplicate time specifications in agenda items.
  1348. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1349. time-of-day specification in a headline or diary entry is extracted and
  1350. placed into the prefix. If this option is non-nil, the original specification
  1351. \(a timestamp or -range, or just a plain time(range) specification like
  1352. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1353. cluttered.
  1354. The option can be t or nil. It may also be the symbol `beg', indicating
  1355. that the time should only be removed when it is located at the beginning of
  1356. the headline/diary entry."
  1357. :group 'org-agenda-line-format
  1358. :type '(choice
  1359. (const :tag "Always" t)
  1360. (const :tag "Never" nil)
  1361. (const :tag "When at beginning of entry" beg)))
  1362. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1363. "Non-nil means remove time ranges specifications in agenda
  1364. items that span on several days."
  1365. :group 'org-agenda-line-format
  1366. :type 'boolean)
  1367. (defcustom org-agenda-default-appointment-duration nil
  1368. "Default duration for appointments that only have a starting time.
  1369. When nil, no duration is specified in such cases.
  1370. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1371. :group 'org-agenda-line-format
  1372. :type '(choice
  1373. (integer :tag "Minutes")
  1374. (const :tag "No default duration")))
  1375. (defcustom org-agenda-show-inherited-tags t
  1376. "Non-nil means show inherited tags in each agenda line."
  1377. :group 'org-agenda-line-format
  1378. :type 'boolean)
  1379. (defcustom org-agenda-hide-tags-regexp nil
  1380. "Regular expression used to filter away specific tags in agenda views.
  1381. This means that these tags will be present, but not be shown in the agenda
  1382. line. Secondary filtering will still work on the hidden tags.
  1383. Nil means don't hide any tags."
  1384. :group 'org-agenda-line-format
  1385. :type '(choice
  1386. (const :tag "Hide none" nil)
  1387. (string :tag "Regexp ")))
  1388. (defcustom org-agenda-remove-tags nil
  1389. "Non-nil means remove the tags from the headline copy in the agenda.
  1390. When this is the symbol `prefix', only remove tags when
  1391. `org-agenda-prefix-format' contains a `%T' specifier."
  1392. :group 'org-agenda-line-format
  1393. :type '(choice
  1394. (const :tag "Always" t)
  1395. (const :tag "Never" nil)
  1396. (const :tag "When prefix format contains %T" prefix)))
  1397. (if (fboundp 'defvaralias)
  1398. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1399. 'org-agenda-remove-tags))
  1400. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1401. "Shift tags in agenda items to this column.
  1402. If this number is positive, it specifies the column. If it is negative,
  1403. it means that the tags should be flushright to that column. For example,
  1404. -80 works well for a normal 80 character screen."
  1405. :group 'org-agenda-line-format
  1406. :type 'integer)
  1407. (if (fboundp 'defvaralias)
  1408. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1409. (defcustom org-agenda-fontify-priorities 'cookies
  1410. "Non-nil means highlight low and high priorities in agenda.
  1411. When t, the highest priority entries are bold, lowest priority italic.
  1412. However, settings in `org-priority-faces' will overrule these faces.
  1413. When this variable is the symbol `cookies', only fontify the
  1414. cookies, not the entire task.
  1415. This may also be an association list of priority faces, whose
  1416. keys are the character values of `org-highest-priority',
  1417. `org-default-priority', and `org-lowest-priority' (the default values
  1418. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1419. color as a string, or a list like `(:background \"Red\")'.
  1420. If it is a color, the variable `org-faces-easy-properties'
  1421. determines if it is a foreground or a background color."
  1422. :group 'org-agenda-line-format
  1423. :type '(choice
  1424. (const :tag "Never" nil)
  1425. (const :tag "Defaults" t)
  1426. (const :tag "Cookies only" cookies)
  1427. (repeat :tag "Specify"
  1428. (list (character :tag "Priority" :value ?A)
  1429. (choice :tag "Face "
  1430. (string :tag "Color")
  1431. (sexp :tag "Face"))))))
  1432. (defcustom org-agenda-day-face-function nil
  1433. "Function called to determine what face should be used to display a day.
  1434. The only argument passed to that function is the day. It should
  1435. returns a face, or nil if does not want to specify a face and let
  1436. the normal rules apply."
  1437. :group 'org-agenda-line-format
  1438. :type 'function)
  1439. (defcustom org-agenda-category-icon-alist nil
  1440. "Alist of category icon to be displayed in agenda views.
  1441. Each entry should have the following format:
  1442. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1443. Where CATEGORY-REGEXP is a regexp matching the categories where
  1444. the icon should be displayed.
  1445. FILE-OR-DATA either a file path or a string containing image data.
  1446. The other fields can be omited safely if not needed:
  1447. TYPE indicates the image type.
  1448. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1449. image data.
  1450. PROPS are additional image attributes to assign to the image,
  1451. like, e.g. `:ascent center'.
  1452. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1453. If you want to set the display properties yourself, just put a
  1454. list as second element:
  1455. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1456. For example, to display a 16px horizontal space for Emacs
  1457. category, you can use:
  1458. (\"Emacs\" '(space . (:width (16))))"
  1459. :group 'org-agenda-line-format
  1460. :type '(alist :key-type (string :tag "Regexp matching category")
  1461. :value-type (choice (list :tag "Icon"
  1462. (string :tag "File or data")
  1463. (symbol :tag "Type")
  1464. (boolean :tag "Data?")
  1465. (repeat :tag "Extra image properties" :inline t symbol))
  1466. (list :tag "Display properties" sexp))))
  1467. (defgroup org-agenda-column-view nil
  1468. "Options concerning column view in the agenda."
  1469. :tag "Org Agenda Column View"
  1470. :group 'org-agenda)
  1471. (defcustom org-agenda-columns-show-summaries t
  1472. "Non-nil means show summaries for columns displayed in the agenda view."
  1473. :group 'org-agenda-column-view
  1474. :type 'boolean)
  1475. (defcustom org-agenda-columns-compute-summary-properties t
  1476. "Non-nil means recompute all summary properties before column view.
  1477. When column view in the agenda is listing properties that have a summary
  1478. operator, it can go to all relevant buffers and recompute the summaries
  1479. there. This can mean overhead for the agenda column view, but is necessary
  1480. to have thing up to date.
  1481. As a special case, a CLOCKSUM property also makes sure that the clock
  1482. computations are current."
  1483. :group 'org-agenda-column-view
  1484. :type 'boolean)
  1485. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1486. "Non-nil means the duration of an appointment will add to day effort.
  1487. The property to which appointment durations will be added is the one given
  1488. in the option `org-effort-property'. If an appointment does not have
  1489. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1490. is not set, an appointment without end time will not contribute to the time
  1491. estimate."
  1492. :group 'org-agenda-column-view
  1493. :type 'boolean)
  1494. (defcustom org-agenda-auto-exclude-function nil
  1495. "A function called with a tag to decide if it is filtered on '/ RET'.
  1496. The sole argument to the function, which is called once for each
  1497. possible tag, is a string giving the name of the tag. The
  1498. function should return either nil if the tag should be included
  1499. as normal, or \"-<TAG>\" to exclude the tag.
  1500. Note that for the purpose of tag filtering, only the lower-case version of
  1501. all tags will be considered, so that this function will only ever see
  1502. the lower-case version of all tags."
  1503. :group 'org-agenda
  1504. :type 'function)
  1505. (defcustom org-agenda-bulk-custom-functions nil
  1506. "Alist of characters and custom functions for bulk actions.
  1507. For example, this value makes those two functions available:
  1508. '((?R set-category)
  1509. (?C bulk-cut))
  1510. With selected entries in an agenda buffer, `B R' will call
  1511. the custom function `set-category' on the selected entries.
  1512. Note that functions in this alist don't need to be quoted."
  1513. :type 'alist
  1514. :group 'org-agenda)
  1515. (eval-when-compile
  1516. (require 'cl))
  1517. (require 'org)
  1518. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1519. "Execute BODY with point at location given by `org-hd-marker' property.
  1520. If STRING is non-nil, the text property will be fetched from position 0
  1521. in that string. If STRING is nil, it will be fetched from the beginning
  1522. of the current line."
  1523. (org-with-gensyms (marker)
  1524. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1525. 'org-hd-marker string)))
  1526. (with-current-buffer (marker-buffer ,marker)
  1527. (save-excursion
  1528. (goto-char ,marker)
  1529. ,@body)))))
  1530. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1531. (defun org-add-agenda-custom-command (entry)
  1532. "Replace or add a command in `org-agenda-custom-commands'.
  1533. This is mostly for hacking and trying a new command - once the command
  1534. works you probably want to add it to `org-agenda-custom-commands' for good."
  1535. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1536. (if ass
  1537. (setcdr ass (cdr entry))
  1538. (push entry org-agenda-custom-commands))))
  1539. ;;; Define the Org-agenda-mode
  1540. (defvar org-agenda-mode-map (make-sparse-keymap)
  1541. "Keymap for `org-agenda-mode'.")
  1542. (if (fboundp 'defvaralias)
  1543. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1544. (defvar org-agenda-menu) ; defined later in this file.
  1545. (defvar org-agenda-restrict) ; defined later in this file.
  1546. (defvar org-agenda-follow-mode nil)
  1547. (defvar org-agenda-entry-text-mode nil)
  1548. (defvar org-agenda-clockreport-mode nil)
  1549. (defvar org-agenda-show-log nil)
  1550. (defvar org-agenda-redo-command nil)
  1551. (defvar org-agenda-query-string nil)
  1552. (defvar org-agenda-mode-hook nil
  1553. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1554. (defvar org-agenda-type nil)
  1555. (defvar org-agenda-force-single-file nil)
  1556. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1557. (defun org-agenda-mode ()
  1558. "Mode for time-sorted view on action items in Org-mode files.
  1559. The following commands are available:
  1560. \\{org-agenda-mode-map}"
  1561. (interactive)
  1562. (kill-all-local-variables)
  1563. (setq org-agenda-undo-list nil
  1564. org-agenda-pending-undo-list nil
  1565. org-agenda-bulk-marked-entries nil)
  1566. (setq major-mode 'org-agenda-mode)
  1567. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1568. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1569. (setq mode-name "Org-Agenda")
  1570. (use-local-map org-agenda-mode-map)
  1571. (easy-menu-add org-agenda-menu)
  1572. (if org-startup-truncated (setq truncate-lines t))
  1573. (org-set-local 'line-move-visual nil)
  1574. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1575. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1576. ;; Make sure properties are removed when copying text
  1577. (when (boundp 'buffer-substring-filters)
  1578. (org-set-local 'buffer-substring-filters
  1579. (cons (lambda (x)
  1580. (set-text-properties 0 (length x) nil x) x)
  1581. buffer-substring-filters)))
  1582. (unless org-agenda-keep-modes
  1583. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1584. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1585. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1586. org-agenda-show-log org-agenda-start-with-log-mode))
  1587. (easy-menu-change
  1588. '("Agenda") "Agenda Files"
  1589. (append
  1590. (list
  1591. (vector
  1592. (if (get 'org-agenda-files 'org-restrict)
  1593. "Restricted to single file"
  1594. "Edit File List")
  1595. '(org-edit-agenda-file-list)
  1596. (not (get 'org-agenda-files 'org-restrict)))
  1597. "--")
  1598. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1599. (org-agenda-set-mode-name)
  1600. (apply
  1601. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1602. (list 'org-agenda-mode-hook)))
  1603. (substitute-key-definition 'undo 'org-agenda-undo
  1604. org-agenda-mode-map global-map)
  1605. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1606. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1607. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1608. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1609. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1610. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1611. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1612. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1613. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1614. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1615. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1616. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1617. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1618. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1619. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1620. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1621. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1622. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1623. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1624. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1625. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1626. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1627. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1628. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1630. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1631. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1632. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1633. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1634. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1635. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1636. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1637. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1638. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1639. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1640. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1641. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1642. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1643. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1644. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1645. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1646. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1647. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1648. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1649. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1650. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1651. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1652. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1653. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1654. (while l (org-defkey org-agenda-mode-map
  1655. (int-to-string (pop l)) 'digit-argument)))
  1656. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1657. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1658. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1659. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1660. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1661. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1662. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1663. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1664. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1665. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1666. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1667. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1668. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1669. 'org-clock-modify-effort-estimate)
  1670. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1671. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1672. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1673. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1674. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1675. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1676. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1677. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1678. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1679. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1680. (substitute-key-definition 'next-line 'org-agenda-next-line
  1681. org-agenda-mode-map global-map)
  1682. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1683. org-agenda-mode-map global-map)
  1684. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1685. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1686. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1687. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1688. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1689. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1690. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1691. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1692. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1693. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1694. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1695. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1696. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1697. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1698. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1699. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1700. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1701. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1702. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1703. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1704. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1705. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1706. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1707. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1708. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1709. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1710. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1711. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1712. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1713. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1714. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1715. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1716. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1717. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1718. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1719. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1720. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1721. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1722. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1723. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1724. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1725. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1726. (when org-agenda-mouse-1-follows-link
  1727. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1728. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1729. '("Agenda"
  1730. ("Agenda Files")
  1731. "--"
  1732. ("Agenda Dates"
  1733. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1734. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1735. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1736. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1737. "--"
  1738. ("View"
  1739. ["Day View" org-agenda-day-view
  1740. :active (org-agenda-check-type nil 'agenda)
  1741. :style radio :selected (eq org-agenda-current-span 'day)
  1742. :keys "v d (or just d)"]
  1743. ["Week View" org-agenda-week-view
  1744. :active (org-agenda-check-type nil 'agenda)
  1745. :style radio :selected (eq org-agenda-current-span 'week)
  1746. :keys "v w (or just w)"]
  1747. ["Month View" org-agenda-month-view
  1748. :active (org-agenda-check-type nil 'agenda)
  1749. :style radio :selected (eq org-agenda-current-span 'month)
  1750. :keys "v m"]
  1751. ["Year View" org-agenda-year-view
  1752. :active (org-agenda-check-type nil 'agenda)
  1753. :style radio :selected (eq org-agenda-current-span 'year)
  1754. :keys "v y"]
  1755. "--"
  1756. ["Include Diary" org-agenda-toggle-diary
  1757. :style toggle :selected org-agenda-include-diary
  1758. :active (org-agenda-check-type nil 'agenda)]
  1759. ["Include Deadlines" org-agenda-toggle-deadlines
  1760. :style toggle :selected org-agenda-include-deadlines
  1761. :active (org-agenda-check-type nil 'agenda)]
  1762. ["Use Time Grid" org-agenda-toggle-time-grid
  1763. :style toggle :selected org-agenda-use-time-grid
  1764. :active (org-agenda-check-type nil 'agenda)]
  1765. "--"
  1766. ["Show clock report" org-agenda-clockreport-mode
  1767. :style toggle :selected org-agenda-clockreport-mode
  1768. :active (org-agenda-check-type nil 'agenda)]
  1769. ["Show some entry text" org-agenda-entry-text-mode
  1770. :style toggle :selected org-agenda-entry-text-mode
  1771. :active t]
  1772. "--"
  1773. ["Show Logbook entries" org-agenda-log-mode
  1774. :style toggle :selected org-agenda-show-log
  1775. :active (org-agenda-check-type nil 'agenda 'timeline)
  1776. :keys "v l (or just l)"]
  1777. ["Include archived trees" org-agenda-archives-mode
  1778. :style toggle :selected org-agenda-archives-mode :active t
  1779. :keys "v a"]
  1780. ["Include archive files" (org-agenda-archives-mode t)
  1781. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1782. :keys "v A"]
  1783. "--"
  1784. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1785. ["Write view to file" org-write-agenda t]
  1786. ["Rebuild buffer" org-agenda-redo t]
  1787. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1788. "--"
  1789. ["Show original entry" org-agenda-show t]
  1790. ["Go To (other window)" org-agenda-goto t]
  1791. ["Go To (this window)" org-agenda-switch-to t]
  1792. ["Follow Mode" org-agenda-follow-mode
  1793. :style toggle :selected org-agenda-follow-mode :active t]
  1794. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1795. "--"
  1796. ("TODO"
  1797. ["Cycle TODO" org-agenda-todo t]
  1798. ["Next TODO set" org-agenda-todo-nextset t]
  1799. ["Previous TODO set" org-agenda-todo-previousset t]
  1800. ["Add note" org-agenda-add-note t])
  1801. ("Archive/Refile/Delete"
  1802. ["Archive default" org-agenda-archive-default t]
  1803. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1804. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1805. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1806. ["Archive subtree" org-agenda-archive t]
  1807. "--"
  1808. ["Refile" org-agenda-refile t]
  1809. "--"
  1810. ["Delete subtree" org-agenda-kill t])
  1811. ("Bulk action"
  1812. ["Mark entry" org-agenda-bulk-mark t]
  1813. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1814. ["Unmark entry" org-agenda-bulk-unmark t]
  1815. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1816. ["Act on all marked" org-agenda-bulk-action t]
  1817. "--"
  1818. ("Tags and Properties"
  1819. ["Show all Tags" org-agenda-show-tags t]
  1820. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1821. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1822. "--"
  1823. ["Column View" org-columns t])
  1824. ("Deadline/Schedule"
  1825. ["Schedule" org-agenda-schedule t]
  1826. ["Set Deadline" org-agenda-deadline t]
  1827. "--"
  1828. ["Mark item" org-agenda-action :active t :keys "k m"]
  1829. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1830. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1831. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1832. "--"
  1833. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1834. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1835. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1836. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1837. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1838. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1839. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1840. ("Clock and Effort"
  1841. ["Clock in" org-agenda-clock-in t]
  1842. ["Clock out" org-agenda-clock-out t]
  1843. ["Clock cancel" org-agenda-clock-cancel t]
  1844. ["Goto running clock" org-clock-goto t]
  1845. "--"
  1846. ["Set Effort" org-agenda-set-effort t]
  1847. ["Change clocked effort" org-clock-modify-effort-estimate
  1848. (org-clock-is-active)])
  1849. ("Priority"
  1850. ["Set Priority" org-agenda-priority t]
  1851. ["Increase Priority" org-agenda-priority-up t]
  1852. ["Decrease Priority" org-agenda-priority-down t]
  1853. ["Show Priority" org-agenda-show-priority t])
  1854. ("Calendar/Diary"
  1855. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1856. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1857. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1858. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1859. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1860. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1861. "--"
  1862. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1863. "--"
  1864. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1865. "--"
  1866. ("MobileOrg"
  1867. ["Push Files and Views" org-mobile-push t]
  1868. ["Get Captured and Flagged" org-mobile-pull t]
  1869. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1870. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1871. "--"
  1872. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1873. "--"
  1874. ["Quit" org-agenda-quit t]
  1875. ["Exit and Release Buffers" org-agenda-exit t]
  1876. ))
  1877. ;;; Agenda undo
  1878. (defvar org-agenda-allow-remote-undo t
  1879. "Non-nil means allow remote undo from the agenda buffer.")
  1880. (defvar org-agenda-undo-list nil
  1881. "List of undoable operations in the agenda since last refresh.")
  1882. (defvar org-agenda-undo-has-started-in nil
  1883. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1884. (defvar org-agenda-pending-undo-list nil
  1885. "In a series of undo commands, this is the list of remaining undo items.")
  1886. (defun org-agenda-undo ()
  1887. "Undo a remote editing step in the agenda.
  1888. This undoes changes both in the agenda buffer and in the remote buffer
  1889. that have been changed along."
  1890. (interactive)
  1891. (or org-agenda-allow-remote-undo
  1892. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1893. (if (not (eq this-command last-command))
  1894. (setq org-agenda-undo-has-started-in nil
  1895. org-agenda-pending-undo-list org-agenda-undo-list))
  1896. (if (not org-agenda-pending-undo-list)
  1897. (error "No further undo information"))
  1898. (let* ((entry (pop org-agenda-pending-undo-list))
  1899. buf line cmd rembuf)
  1900. (setq cmd (pop entry) line (pop entry))
  1901. (setq rembuf (nth 2 entry))
  1902. (org-with-remote-undo rembuf
  1903. (while (bufferp (setq buf (pop entry)))
  1904. (if (pop entry)
  1905. (with-current-buffer buf
  1906. (let ((last-undo-buffer buf)
  1907. (inhibit-read-only t))
  1908. (unless (memq buf org-agenda-undo-has-started-in)
  1909. (push buf org-agenda-undo-has-started-in)
  1910. (make-local-variable 'pending-undo-list)
  1911. (undo-start))
  1912. (while (and pending-undo-list
  1913. (listp pending-undo-list)
  1914. (not (car pending-undo-list)))
  1915. (pop pending-undo-list))
  1916. (undo-more 1))))))
  1917. (org-goto-line line)
  1918. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1919. (defun org-verify-change-for-undo (l1 l2)
  1920. "Verify that a real change occurred between the undo lists L1 and L2."
  1921. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1922. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1923. (not (eq l1 l2)))
  1924. ;;; Agenda dispatch
  1925. (defvar org-agenda-restrict nil)
  1926. (defvar org-agenda-restrict-begin (make-marker))
  1927. (defvar org-agenda-restrict-end (make-marker))
  1928. (defvar org-agenda-last-dispatch-buffer nil)
  1929. (defvar org-agenda-overriding-restriction nil)
  1930. ;;;###autoload
  1931. (defun org-agenda (&optional arg keys restriction)
  1932. "Dispatch agenda commands to collect entries to the agenda buffer.
  1933. Prompts for a command to execute. Any prefix arg will be passed
  1934. on to the selected command. The default selections are:
  1935. a Call `org-agenda-list' to display the agenda for current day or week.
  1936. t Call `org-todo-list' to display the global todo list.
  1937. T Call `org-todo-list' to display the global todo list, select only
  1938. entries with a specific TODO keyword (the user gets a prompt).
  1939. m Call `org-tags-view' to display headlines with tags matching
  1940. a condition (the user is prompted for the condition).
  1941. M Like `m', but select only TODO entries, no ordinary headlines.
  1942. L Create a timeline for the current buffer.
  1943. e Export views to associated files.
  1944. s Search entries for keywords.
  1945. / Multi occur across all agenda files and also files listed
  1946. in `org-agenda-text-search-extra-files'.
  1947. < Restrict agenda commands to buffer, subtree, or region.
  1948. Press several times to get the desired effect.
  1949. > Remove a previous restriction.
  1950. # List \"stuck\" projects.
  1951. ! Configure what \"stuck\" means.
  1952. C Configure custom agenda commands.
  1953. More commands can be added by configuring the variable
  1954. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1955. searches can be pre-defined in this way.
  1956. If the current buffer is in Org-mode and visiting a file, you can also
  1957. first press `<' once to indicate that the agenda should be temporarily
  1958. \(until the next use of \\[org-agenda]) restricted to the current file.
  1959. Pressing `<' twice means to restrict to the current subtree or region
  1960. \(if active)."
  1961. (interactive "P")
  1962. (catch 'exit
  1963. (let* ((prefix-descriptions nil)
  1964. (org-agenda-window-setup (if (equal (buffer-name)
  1965. org-agenda-buffer-name)
  1966. 'current-window
  1967. org-agenda-window-setup))
  1968. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1969. (org-agenda-custom-commands
  1970. ;; normalize different versions
  1971. (delq nil
  1972. (mapcar
  1973. (lambda (x)
  1974. (cond ((stringp (cdr x))
  1975. (push x prefix-descriptions)
  1976. nil)
  1977. ((stringp (nth 1 x)) x)
  1978. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1979. (t (cons (car x) (cons "" (cdr x))))))
  1980. org-agenda-custom-commands)))
  1981. (buf (current-buffer))
  1982. (bfn (buffer-file-name (buffer-base-buffer)))
  1983. entry key type match lprops ans)
  1984. ;; Turn off restriction unless there is an overriding one,
  1985. (unless org-agenda-overriding-restriction
  1986. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1987. ;; There is a request to keep the file list in place
  1988. (put 'org-agenda-files 'org-restrict nil))
  1989. (setq org-agenda-restrict nil)
  1990. (move-marker org-agenda-restrict-begin nil)
  1991. (move-marker org-agenda-restrict-end nil))
  1992. ;; Delete old local properties
  1993. (put 'org-agenda-redo-command 'org-lprops nil)
  1994. ;; Delete previously set last-arguments
  1995. (put 'org-agenda-redo-command 'last-args nil)
  1996. ;; Remember where this call originated
  1997. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1998. (unless keys
  1999. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2000. keys (car ans)
  2001. restriction (cdr ans)))
  2002. ;; Establish the restriction, if any
  2003. (when (and (not org-agenda-overriding-restriction) restriction)
  2004. (put 'org-agenda-files 'org-restrict (list bfn))
  2005. (cond
  2006. ((eq restriction 'region)
  2007. (setq org-agenda-restrict t)
  2008. (move-marker org-agenda-restrict-begin (region-beginning))
  2009. (move-marker org-agenda-restrict-end (region-end)))
  2010. ((eq restriction 'subtree)
  2011. (save-excursion
  2012. (setq org-agenda-restrict t)
  2013. (org-back-to-heading t)
  2014. (move-marker org-agenda-restrict-begin (point))
  2015. (move-marker org-agenda-restrict-end
  2016. (progn (org-end-of-subtree t)))))))
  2017. ;; For example the todo list should not need it (but does...)
  2018. (cond
  2019. ((setq entry (assoc keys org-agenda-custom-commands))
  2020. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2021. (progn
  2022. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2023. lprops (nth 4 entry))
  2024. (put 'org-agenda-redo-command 'org-lprops lprops)
  2025. (cond
  2026. ((eq type 'agenda)
  2027. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2028. ((eq type 'alltodo)
  2029. (org-let lprops '(org-todo-list current-prefix-arg)))
  2030. ((eq type 'search)
  2031. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2032. ((eq type 'stuck)
  2033. (org-let lprops '(org-agenda-list-stuck-projects
  2034. current-prefix-arg)))
  2035. ((eq type 'tags)
  2036. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2037. ((eq type 'tags-todo)
  2038. (org-let lprops '(org-tags-view '(4) match)))
  2039. ((eq type 'todo)
  2040. (org-let lprops '(org-todo-list match)))
  2041. ((eq type 'tags-tree)
  2042. (org-check-for-org-mode)
  2043. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2044. ((eq type 'todo-tree)
  2045. (org-check-for-org-mode)
  2046. (org-let lprops
  2047. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2048. (regexp-quote match) "\\>"))))
  2049. ((eq type 'occur-tree)
  2050. (org-check-for-org-mode)
  2051. (org-let lprops '(org-occur match)))
  2052. ((functionp type)
  2053. (org-let lprops '(funcall type match)))
  2054. ((fboundp type)
  2055. (org-let lprops '(funcall type match)))
  2056. (t (error "Invalid custom agenda command type %s" type))))
  2057. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2058. ((equal keys "C")
  2059. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2060. (customize-variable 'org-agenda-custom-commands))
  2061. ((equal keys "a") (call-interactively 'org-agenda-list))
  2062. ((equal keys "s") (call-interactively 'org-search-view))
  2063. ((equal keys "t") (call-interactively 'org-todo-list))
  2064. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2065. ((equal keys "m") (call-interactively 'org-tags-view))
  2066. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2067. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2068. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2069. (org-add-hook
  2070. 'post-command-hook
  2071. (lambda ()
  2072. (unless (current-message)
  2073. (let* ((m (org-agenda-get-any-marker))
  2074. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2075. (when note
  2076. (message (concat
  2077. "FLAGGING-NOTE ([?] for more info): "
  2078. (org-add-props
  2079. (replace-regexp-in-string
  2080. "\\\\n" "//"
  2081. (copy-sequence note))
  2082. nil 'face 'org-warning)))))))
  2083. t t))
  2084. ((equal keys "L")
  2085. (unless (org-mode-p)
  2086. (error "This is not an Org-mode file"))
  2087. (unless restriction
  2088. (put 'org-agenda-files 'org-restrict (list bfn))
  2089. (org-call-with-arg 'org-timeline arg)))
  2090. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2091. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2092. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2093. (t (error "Invalid agenda key"))))))
  2094. (defun org-agenda-append-agenda ()
  2095. "Append another agenda view to the current one.
  2096. This function allows interactive building of block agendas.
  2097. Agenda views are separated by `org-agenda-block-separator'."
  2098. (interactive)
  2099. (unless (string= (buffer-name) org-agenda-buffer-name)
  2100. (error "Can only append from within agenda buffer"))
  2101. (let ((org-agenda-multi t))
  2102. (org-agenda)
  2103. (widen)))
  2104. (defun org-agenda-normalize-custom-commands (cmds)
  2105. (delq nil
  2106. (mapcar
  2107. (lambda (x)
  2108. (cond ((stringp (cdr x)) nil)
  2109. ((stringp (nth 1 x)) x)
  2110. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2111. (t (cons (car x) (cons "" (cdr x))))))
  2112. cmds)))
  2113. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2114. "The user interface for selecting an agenda command."
  2115. (catch 'exit
  2116. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2117. (restrict-ok (and bfn (org-mode-p)))
  2118. (region-p (org-region-active-p))
  2119. (custom org-agenda-custom-commands)
  2120. (selstring "")
  2121. restriction second-time
  2122. c entry key type match prefixes rmheader header-end custom1 desc
  2123. line lines left right n n1)
  2124. (save-window-excursion
  2125. (delete-other-windows)
  2126. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2127. (erase-buffer)
  2128. (insert (eval-when-compile
  2129. (let ((header
  2130. "
  2131. Press key for an agenda command: < Buffer, subtree/region restriction
  2132. -------------------------------- > Remove restriction
  2133. a Agenda for current week or day e Export agenda views
  2134. t List of all TODO entries T Entries with special TODO kwd
  2135. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2136. L Timeline for current buffer # List stuck projects (!=configure)
  2137. s Search for keywords C Configure custom agenda commands
  2138. / Multi-occur ? Find :FLAGGED: entries
  2139. ")
  2140. (start 0))
  2141. (while (string-match
  2142. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2143. header start)
  2144. (setq start (match-end 0))
  2145. (add-text-properties (match-beginning 2) (match-end 2)
  2146. '(face bold) header))
  2147. header)))
  2148. (setq header-end (move-marker (make-marker) (point)))
  2149. (while t
  2150. (setq custom1 custom)
  2151. (when (eq rmheader t)
  2152. (org-goto-line 1)
  2153. (re-search-forward ":" nil t)
  2154. (delete-region (match-end 0) (point-at-eol))
  2155. (forward-char 1)
  2156. (looking-at "-+")
  2157. (delete-region (match-end 0) (point-at-eol))
  2158. (move-marker header-end (match-end 0)))
  2159. (goto-char header-end)
  2160. (delete-region (point) (point-max))
  2161. ;; Produce all the lines that describe custom commands and prefixes
  2162. (setq lines nil)
  2163. (while (setq entry (pop custom1))
  2164. (setq key (car entry) desc (nth 1 entry)
  2165. type (nth 2 entry)
  2166. match (nth 3 entry))
  2167. (if (> (length key) 1)
  2168. (add-to-list 'prefixes (string-to-char key))
  2169. (setq line
  2170. (format
  2171. "%-4s%-14s"
  2172. (org-add-props (copy-sequence key)
  2173. '(face bold))
  2174. (cond
  2175. ((string-match "\\S-" desc) desc)
  2176. ((eq type 'agenda) "Agenda for current week or day")
  2177. ((eq type 'alltodo) "List of all TODO entries")
  2178. ((eq type 'search) "Word search")
  2179. ((eq type 'stuck) "List of stuck projects")
  2180. ((eq type 'todo) "TODO keyword")
  2181. ((eq type 'tags) "Tags query")
  2182. ((eq type 'tags-todo) "Tags (TODO)")
  2183. ((eq type 'tags-tree) "Tags tree")
  2184. ((eq type 'todo-tree) "TODO kwd tree")
  2185. ((eq type 'occur-tree) "Occur tree")
  2186. ((functionp type) (if (symbolp type)
  2187. (symbol-name type)
  2188. "Lambda expression"))
  2189. (t "???"))))
  2190. (if org-agenda-menu-show-matcher
  2191. (setq line
  2192. (concat line ": "
  2193. (cond
  2194. ((stringp match)
  2195. (setq match (copy-sequence match))
  2196. (org-add-props match nil 'face 'org-warning))
  2197. (match
  2198. (format "set of %d commands" (length match)))
  2199. (t ""))))
  2200. (if (org-string-nw-p match)
  2201. (add-text-properties
  2202. 0 (length line) (list 'help-echo
  2203. (concat "Matcher: "match)) line)))
  2204. (push line lines)))
  2205. (setq lines (nreverse lines))
  2206. (when prefixes
  2207. (mapc (lambda (x)
  2208. (push
  2209. (format "%s %s"
  2210. (org-add-props (char-to-string x)
  2211. nil 'face 'bold)
  2212. (or (cdr (assoc (concat selstring
  2213. (char-to-string x))
  2214. prefix-descriptions))
  2215. "Prefix key"))
  2216. lines))
  2217. prefixes))
  2218. ;; Check if we should display in two columns
  2219. (if org-agenda-menu-two-column
  2220. (progn
  2221. (setq n (length lines)
  2222. n1 (+ (/ n 2) (mod n 2))
  2223. right (nthcdr n1 lines)
  2224. left (copy-sequence lines))
  2225. (setcdr (nthcdr (1- n1) left) nil))
  2226. (setq left lines right nil))
  2227. (while left
  2228. (insert "\n" (pop left))
  2229. (when right
  2230. (if (< (current-column) 40)
  2231. (move-to-column 40 t)
  2232. (insert " "))
  2233. (insert (pop right))))
  2234. ;; Make the window the right size
  2235. (goto-char (point-min))
  2236. (if second-time
  2237. (if (not (pos-visible-in-window-p (point-max)))
  2238. (org-fit-window-to-buffer))
  2239. (setq second-time t)
  2240. (org-fit-window-to-buffer))
  2241. ;; Ask for selection
  2242. (message "Press key for agenda command%s:"
  2243. (if (or restrict-ok org-agenda-overriding-restriction)
  2244. (if org-agenda-overriding-restriction
  2245. " (restriction lock active)"
  2246. (if restriction
  2247. (format " (restricted to %s)" restriction)
  2248. " (unrestricted)"))
  2249. ""))
  2250. (setq c (read-char-exclusive))
  2251. (message "")
  2252. (cond
  2253. ((assoc (char-to-string c) custom)
  2254. (setq selstring (concat selstring (char-to-string c)))
  2255. (throw 'exit (cons selstring restriction)))
  2256. ((memq c prefixes)
  2257. (setq selstring (concat selstring (char-to-string c))
  2258. prefixes nil
  2259. rmheader (or rmheader t)
  2260. custom (delq nil (mapcar
  2261. (lambda (x)
  2262. (if (or (= (length (car x)) 1)
  2263. (/= (string-to-char (car x)) c))
  2264. nil
  2265. (cons (substring (car x) 1) (cdr x))))
  2266. custom))))
  2267. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2268. (message "Restriction is only possible in Org-mode buffers")
  2269. (ding) (sit-for 1))
  2270. ((eq c ?1)
  2271. (org-agenda-remove-restriction-lock 'noupdate)
  2272. (setq restriction 'buffer))
  2273. ((eq c ?0)
  2274. (org-agenda-remove-restriction-lock 'noupdate)
  2275. (setq restriction (if region-p 'region 'subtree)))
  2276. ((eq c ?<)
  2277. (org-agenda-remove-restriction-lock 'noupdate)
  2278. (setq restriction
  2279. (cond
  2280. ((eq restriction 'buffer)
  2281. (if region-p 'region 'subtree))
  2282. ((memq restriction '(subtree region))
  2283. nil)
  2284. (t 'buffer))))
  2285. ((eq c ?>)
  2286. (org-agenda-remove-restriction-lock 'noupdate)
  2287. (setq restriction nil))
  2288. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2289. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2290. ((and (> (length selstring) 0) (eq c ?\d))
  2291. (delete-window)
  2292. (org-agenda-get-restriction-and-command prefix-descriptions))
  2293. ((equal c ?q) (error "Abort"))
  2294. (t (error "Invalid key %c" c))))))))
  2295. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2296. (defvar org-agenda-last-arguments nil
  2297. "The arguments of the previous call to `org-agenda'.")
  2298. (defun org-agenda-run-series (name series)
  2299. (org-let (nth 1 series) '(org-prepare-agenda name))
  2300. (let* ((org-agenda-multi t)
  2301. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2302. (org-agenda-overriding-arguments
  2303. (or org-agenda-overriding-arguments
  2304. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2305. (get 'org-agenda-redo-command 'last-args))))
  2306. (cmds (car series))
  2307. (gprops (nth 1 series))
  2308. match ;; The byte compiler incorrectly complains about this. Keep it!
  2309. cmd type lprops)
  2310. (while (setq cmd (pop cmds))
  2311. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2312. (cond
  2313. ((eq type 'agenda)
  2314. (org-let2 gprops lprops
  2315. '(call-interactively 'org-agenda-list)))
  2316. ((eq type 'alltodo)
  2317. (org-let2 gprops lprops
  2318. '(call-interactively 'org-todo-list)))
  2319. ((eq type 'search)
  2320. (org-let2 gprops lprops
  2321. '(org-search-view current-prefix-arg match nil)))
  2322. ((eq type 'stuck)
  2323. (org-let2 gprops lprops
  2324. '(call-interactively 'org-agenda-list-stuck-projects)))
  2325. ((eq type 'tags)
  2326. (org-let2 gprops lprops
  2327. '(org-tags-view current-prefix-arg match)))
  2328. ((eq type 'tags-todo)
  2329. (org-let2 gprops lprops
  2330. '(org-tags-view '(4) match)))
  2331. ((eq type 'todo)
  2332. (org-let2 gprops lprops
  2333. '(org-todo-list match)))
  2334. ((fboundp type)
  2335. (org-let2 gprops lprops
  2336. '(funcall type match)))
  2337. (t (error "Invalid type in command series"))))
  2338. (widen)
  2339. (setq org-agenda-redo-command redo)
  2340. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2341. (goto-char (point-min)))
  2342. (org-fit-agenda-window)
  2343. (org-let (nth 1 series) '(org-finalize-agenda)))
  2344. ;;;###autoload
  2345. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2346. "Run an agenda command in batch mode and send the result to STDOUT.
  2347. If CMD-KEY is a string of length 1, it is used as a key in
  2348. `org-agenda-custom-commands' and triggers this command. If it is a
  2349. longer string it is used as a tags/todo match string.
  2350. Parameters are alternating variable names and values that will be bound
  2351. before running the agenda command."
  2352. (org-eval-in-environment (org-make-parameter-alist parameters)
  2353. (if (> (length cmd-key) 2)
  2354. (org-tags-view nil cmd-key)
  2355. (org-agenda nil cmd-key)))
  2356. (set-buffer org-agenda-buffer-name)
  2357. (princ (org-encode-for-stdout (buffer-string))))
  2358. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2359. ;(defun org-encode-for-stdout (string)
  2360. ; (if (fboundp 'encode-coding-string)
  2361. ; (encode-coding-string string buffer-file-coding-system)
  2362. ; string))
  2363. (defun org-encode-for-stdout (string)
  2364. string)
  2365. (defvar org-agenda-info nil)
  2366. ;;;###autoload
  2367. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2368. "Run an agenda command in batch mode and send the result to STDOUT.
  2369. If CMD-KEY is a string of length 1, it is used as a key in
  2370. `org-agenda-custom-commands' and triggers this command. If it is a
  2371. longer string it is used as a tags/todo match string.
  2372. Parameters are alternating variable names and values that will be bound
  2373. before running the agenda command.
  2374. The output gives a line for each selected agenda item. Each
  2375. item is a list of comma-separated values, like this:
  2376. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2377. category The category of the item
  2378. head The headline, without TODO kwd, TAGS and PRIORITY
  2379. type The type of the agenda entry, can be
  2380. todo selected in TODO match
  2381. tagsmatch selected in tags match
  2382. diary imported from diary
  2383. deadline a deadline on given date
  2384. scheduled scheduled on given date
  2385. timestamp entry has timestamp on given date
  2386. closed entry was closed on given date
  2387. upcoming-deadline warning about deadline
  2388. past-scheduled forwarded scheduled item
  2389. block entry has date block including g. date
  2390. todo The todo keyword, if any
  2391. tags All tags including inherited ones, separated by colons
  2392. date The relevant date, like 2007-2-14
  2393. time The time, like 15:00-16:50
  2394. extra Sting with extra planning info
  2395. priority-l The priority letter if any was given
  2396. priority-n The computed numerical priority
  2397. agenda-day The day in the agenda where this is listed"
  2398. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2399. (org-make-parameter-alist parameters))
  2400. (if (> (length cmd-key) 2)
  2401. (org-tags-view nil cmd-key)
  2402. (org-agenda nil cmd-key)))
  2403. (set-buffer org-agenda-buffer-name)
  2404. (let* ((lines (org-split-string (buffer-string) "\n"))
  2405. line)
  2406. (while (setq line (pop lines))
  2407. (catch 'next
  2408. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2409. (setq org-agenda-info
  2410. (org-fix-agenda-info (text-properties-at 0 line)))
  2411. (princ
  2412. (org-encode-for-stdout
  2413. (mapconcat 'org-agenda-export-csv-mapper
  2414. '(org-category txt type todo tags date time extra
  2415. priority-letter priority agenda-day)
  2416. ",")))
  2417. (princ "\n")))))
  2418. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2419. (defun org-fix-agenda-info (props)
  2420. "Make sure all properties on an agenda item have a canonical form.
  2421. This ensures the export commands can easily use it."
  2422. (let (tmp re)
  2423. (when (setq tmp (plist-get props 'tags))
  2424. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2425. (when (setq tmp (plist-get props 'date))
  2426. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2427. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2428. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2429. (setq tmp (calendar-date-string tmp)))
  2430. (setq props (plist-put props 'date tmp)))
  2431. (when (setq tmp (plist-get props 'day))
  2432. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2433. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2434. (setq tmp (calendar-date-string tmp)))
  2435. (setq props (plist-put props 'day tmp))
  2436. (setq props (plist-put props 'agenda-day tmp)))
  2437. (when (setq tmp (plist-get props 'txt))
  2438. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2439. (plist-put props 'priority-letter (match-string 1 tmp))
  2440. (setq tmp (replace-match "" t t tmp)))
  2441. (when (and (setq re (plist-get props 'org-todo-regexp))
  2442. (setq re (concat "\\`\\.*" re " ?"))
  2443. (string-match re tmp))
  2444. (plist-put props 'todo (match-string 1 tmp))
  2445. (setq tmp (replace-match "" t t tmp)))
  2446. (plist-put props 'txt tmp)))
  2447. props)
  2448. (defun org-agenda-export-csv-mapper (prop)
  2449. (let ((res (plist-get org-agenda-info prop)))
  2450. (setq res
  2451. (cond
  2452. ((not res) "")
  2453. ((stringp res) res)
  2454. (t (prin1-to-string res))))
  2455. (while (string-match "," res)
  2456. (setq res (replace-match ";" t t res)))
  2457. (org-trim res)))
  2458. ;;;###autoload
  2459. (defun org-store-agenda-views (&rest parameters)
  2460. (interactive)
  2461. (eval (list 'org-batch-store-agenda-views)))
  2462. ;;;###autoload
  2463. (defmacro org-batch-store-agenda-views (&rest parameters)
  2464. "Run all custom agenda commands that have a file argument."
  2465. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2466. (pop-up-frames nil)
  2467. (dir default-directory)
  2468. (pars (org-make-parameter-alist parameters))
  2469. cmd thiscmdkey files opts cmd-or-set)
  2470. (save-window-excursion
  2471. (while cmds
  2472. (setq cmd (pop cmds)
  2473. thiscmdkey (car cmd)
  2474. cmd-or-set (nth 2 cmd)
  2475. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2476. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2477. (if (stringp files) (setq files (list files)))
  2478. (when files
  2479. (org-eval-in-environment (append org-agenda-exporter-settings
  2480. opts pars)
  2481. (org-agenda nil thiscmdkey))
  2482. (set-buffer org-agenda-buffer-name)
  2483. (while files
  2484. (org-eval-in-environment (append org-agenda-exporter-settings
  2485. opts pars)
  2486. (org-write-agenda (expand-file-name (pop files) dir) nil t)))
  2487. (and (get-buffer org-agenda-buffer-name)
  2488. (kill-buffer org-agenda-buffer-name)))))))
  2489. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2490. (defun org-agenda-mark-header-line (pos)
  2491. "Mark the line at POS as an agenda structure header."
  2492. (save-excursion
  2493. (goto-char pos)
  2494. (put-text-property (point-at-bol) (point-at-eol)
  2495. 'org-agenda-structural-header t)
  2496. (when org-agenda-title-append
  2497. (put-text-property (point-at-bol) (point-at-eol)
  2498. 'org-agenda-title-append org-agenda-title-append))))
  2499. (defvar org-mobile-creating-agendas)
  2500. (defun org-write-agenda (file &optional open nosettings)
  2501. "Write the current buffer (an agenda view) as a file.
  2502. Depending on the extension of the file name, plain text (.txt),
  2503. HTML (.html or .htm) or Postscript (.ps) is produced.
  2504. If the extension is .ics, run icalendar export over all files used
  2505. to construct the agenda and limit the export to entries listed in the
  2506. agenda now.
  2507. With prefix argument OPEN, open the new file immediately.
  2508. If NOSETTINGS is given, do not scope the settings of
  2509. `org-agenda-exporter-settings' into the export commands. This is used when
  2510. the settings have already been scoped and we do not wish to overrule other,
  2511. higher priority settings."
  2512. (interactive "FWrite agenda to file: \nP")
  2513. (if (not (file-writable-p file))
  2514. (error "Cannot write agenda to file %s" file))
  2515. (org-let (if nosettings nil org-agenda-exporter-settings)
  2516. '(save-excursion
  2517. (save-window-excursion
  2518. (org-agenda-mark-filtered-text)
  2519. (let ((bs (copy-sequence (buffer-string))) beg)
  2520. (org-agenda-unmark-filtered-text)
  2521. (with-temp-buffer
  2522. (rename-buffer "Agenda View" t)
  2523. (set-buffer-modified-p nil)
  2524. (insert bs)
  2525. (org-agenda-remove-marked-text 'org-filtered)
  2526. (while (setq beg (text-property-any (point-min) (point-max)
  2527. 'org-filtered t))
  2528. (delete-region
  2529. beg (or (next-single-property-change beg 'org-filtered)
  2530. (point-max))))
  2531. (run-hooks 'org-agenda-before-write-hook)
  2532. (cond
  2533. ((org-bound-and-true-p org-mobile-creating-agendas)
  2534. (org-mobile-write-agenda-for-mobile file))
  2535. ((string-match "\\.html?\\'" file)
  2536. (require 'htmlize)
  2537. (set-buffer (htmlize-buffer (current-buffer)))
  2538. (when (and org-agenda-export-html-style
  2539. (string-match "<style>" org-agenda-export-html-style))
  2540. ;; replace <style> section with org-agenda-export-html-style
  2541. (goto-char (point-min))
  2542. (kill-region (- (search-forward "<style") 6)
  2543. (search-forward "</style>"))
  2544. (insert org-agenda-export-html-style))
  2545. (write-file file)
  2546. (kill-buffer (current-buffer))
  2547. (message "HTML written to %s" file))
  2548. ((string-match "\\.ps\\'" file)
  2549. (require 'ps-print)
  2550. (ps-print-buffer-with-faces file)
  2551. (message "Postscript written to %s" file))
  2552. ((string-match "\\.pdf\\'" file)
  2553. (require 'ps-print)
  2554. (ps-print-buffer-with-faces
  2555. (concat (file-name-sans-extension file) ".ps"))
  2556. (call-process "ps2pdf" nil nil nil
  2557. (expand-file-name
  2558. (concat (file-name-sans-extension file) ".ps"))
  2559. (expand-file-name file))
  2560. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2561. (message "PDF written to %s" file))
  2562. ((string-match "\\.ics\\'" file)
  2563. (require 'org-icalendar)
  2564. (let ((org-agenda-marker-table
  2565. (org-create-marker-find-array
  2566. (org-agenda-collect-markers)))
  2567. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2568. (org-combined-agenda-icalendar-file file))
  2569. (apply 'org-export-icalendar 'combine
  2570. (org-agenda-files nil 'ifmode))))
  2571. (t
  2572. (let ((bs (buffer-string)))
  2573. (find-file file)
  2574. (erase-buffer)
  2575. (insert bs)
  2576. (save-buffer 0)
  2577. (kill-buffer (current-buffer))
  2578. (message "Plain text written to %s" file))))))))
  2579. (set-buffer org-agenda-buffer-name))
  2580. (when open (org-open-file file)))
  2581. (defvar org-agenda-filter-overlays nil)
  2582. (defun org-agenda-mark-filtered-text ()
  2583. "Mark all text hidden by filtering with a text property."
  2584. (let ((inhibit-read-only t))
  2585. (mapc
  2586. (lambda (o)
  2587. (when (equal (overlay-buffer o) (current-buffer))
  2588. (put-text-property
  2589. (overlay-start o) (overlay-end o)
  2590. 'org-filtered t)))
  2591. org-agenda-filter-overlays)))
  2592. (defun org-agenda-unmark-filtered-text ()
  2593. "Remove the filtering text property."
  2594. (let ((inhibit-read-only t))
  2595. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2596. (defun org-agenda-remove-marked-text (property &optional value)
  2597. "Delete all text marked with VALUE of PROPERTY.
  2598. VALUE defaults to t."
  2599. (let (beg)
  2600. (setq value (or value t))
  2601. (while (setq beg (text-property-any (point-min) (point-max)
  2602. property value))
  2603. (delete-region
  2604. beg (or (next-single-property-change beg 'org-filtered)
  2605. (point-max))))))
  2606. (defun org-agenda-add-entry-text ()
  2607. "Add entry text to agenda lines.
  2608. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2609. entry text following headings shown in the agenda.
  2610. Drawers will be excluded, also the line with scheduling/deadline info."
  2611. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2612. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2613. (let (m txt)
  2614. (goto-char (point-min))
  2615. (while (not (eobp))
  2616. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2617. (beginning-of-line 2)
  2618. (setq txt (org-agenda-get-some-entry-text
  2619. m org-agenda-add-entry-text-maxlines " > "))
  2620. (end-of-line 1)
  2621. (if (string-match "\\S-" txt)
  2622. (insert "\n" txt)
  2623. (or (eobp) (forward-char 1))))))))
  2624. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2625. &rest keep)
  2626. "Extract entry text from MARKER, at most N-LINES lines.
  2627. This will ignore drawers etc, just get the text.
  2628. If INDENT is given, prefix every line with this string. If KEEP is
  2629. given, it is a list of symbols, defining stuff that should not be
  2630. removed from the entry content. Currently only `planning' is allowed here."
  2631. (let (txt drawer-re kwd-time-re ind)
  2632. (save-excursion
  2633. (with-current-buffer (marker-buffer marker)
  2634. (if (not (org-mode-p))
  2635. (setq txt "")
  2636. (save-excursion
  2637. (save-restriction
  2638. (widen)
  2639. (goto-char marker)
  2640. (end-of-line 1)
  2641. (setq txt (buffer-substring
  2642. (min (1+ (point)) (point-max))
  2643. (progn (outline-next-heading) (point)))
  2644. drawer-re org-drawer-regexp
  2645. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2646. ".*\n?"))
  2647. (with-temp-buffer
  2648. (insert txt)
  2649. (when org-agenda-add-entry-text-descriptive-links
  2650. (goto-char (point-min))
  2651. (while (org-activate-bracket-links (point-max))
  2652. (add-text-properties (match-beginning 0) (match-end 0)
  2653. '(face org-link))))
  2654. (goto-char (point-min))
  2655. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2656. (set-text-properties (match-beginning 0) (match-end 0)
  2657. nil))
  2658. (goto-char (point-min))
  2659. (while (re-search-forward drawer-re nil t)
  2660. (delete-region
  2661. (match-beginning 0)
  2662. (progn (re-search-forward
  2663. "^[ \t]*:END:.*\n?" nil 'move)
  2664. (point))))
  2665. (unless (member 'planning keep)
  2666. (goto-char (point-min))
  2667. (while (re-search-forward kwd-time-re nil t)
  2668. (replace-match "")))
  2669. (goto-char (point-min))
  2670. (when org-agenda-entry-text-exclude-regexps
  2671. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2672. (while (setq re (pop re-list))
  2673. (goto-char (point-min))
  2674. (while (re-search-forward re nil t)
  2675. (replace-match "")))))
  2676. (goto-char (point-max))
  2677. (skip-chars-backward " \t\n")
  2678. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2679. ;; find and remove min common indentation
  2680. (goto-char (point-min))
  2681. (untabify (point-min) (point-max))
  2682. (setq ind (org-get-indentation))
  2683. (while (not (eobp))
  2684. (unless (looking-at "[ \t]*$")
  2685. (setq ind (min ind (org-get-indentation))))
  2686. (beginning-of-line 2))
  2687. (goto-char (point-min))
  2688. (while (not (eobp))
  2689. (unless (looking-at "[ \t]*$")
  2690. (move-to-column ind)
  2691. (delete-region (point-at-bol) (point)))
  2692. (beginning-of-line 2))
  2693. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2694. (goto-char (point-min))
  2695. (when indent
  2696. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2697. (replace-match indent t t)))
  2698. (goto-char (point-min))
  2699. (while (looking-at "[ \t]*\n") (replace-match ""))
  2700. (goto-char (point-max))
  2701. (when (> (org-current-line)
  2702. n-lines)
  2703. (org-goto-line (1+ n-lines))
  2704. (backward-char 1))
  2705. (setq txt (buffer-substring (point-min) (point)))))))))
  2706. txt))
  2707. (defun org-agenda-collect-markers ()
  2708. "Collect the markers pointing to entries in the agenda buffer."
  2709. (let (m markers)
  2710. (save-excursion
  2711. (goto-char (point-min))
  2712. (while (not (eobp))
  2713. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2714. (org-get-at-bol 'org-marker)))
  2715. (push m markers))
  2716. (beginning-of-line 2)))
  2717. (nreverse markers)))
  2718. (defun org-create-marker-find-array (marker-list)
  2719. "Create a alist of files names with all marker positions in that file."
  2720. (let (f tbl m a p)
  2721. (while (setq m (pop marker-list))
  2722. (setq p (marker-position m)
  2723. f (buffer-file-name (or (buffer-base-buffer
  2724. (marker-buffer m))
  2725. (marker-buffer m))))
  2726. (if (setq a (assoc f tbl))
  2727. (push (marker-position m) (cdr a))
  2728. (push (list f p) tbl)))
  2729. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2730. tbl)))
  2731. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2732. (defun org-check-agenda-marker-table ()
  2733. "Check of the current entry is on the marker list."
  2734. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2735. a)
  2736. (and (setq a (assoc file org-agenda-marker-table))
  2737. (save-match-data
  2738. (save-excursion
  2739. (org-back-to-heading t)
  2740. (member (point) (cdr a)))))))
  2741. (defun org-check-for-org-mode ()
  2742. "Make sure current buffer is in org-mode. Error if not."
  2743. (or (org-mode-p)
  2744. (error "Cannot execute org-mode agenda command on buffer in %s"
  2745. major-mode)))
  2746. (defun org-fit-agenda-window ()
  2747. "Fit the window to the buffer size."
  2748. (and (memq org-agenda-window-setup '(reorganize-frame))
  2749. (fboundp 'fit-window-to-buffer)
  2750. (org-fit-window-to-buffer
  2751. nil
  2752. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2753. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2754. ;;; Agenda prepare and finalize
  2755. (defvar org-agenda-multi nil) ; dynamically scoped
  2756. (defvar org-agenda-buffer-name "*Org Agenda*")
  2757. (defvar org-pre-agenda-window-conf nil)
  2758. (defvar org-agenda-columns-active nil)
  2759. (defvar org-agenda-name nil)
  2760. (defvar org-agenda-filter nil)
  2761. (defvar org-agenda-filter-while-redo nil)
  2762. (defvar org-agenda-filter-preset nil
  2763. "A preset of the tags filter used for secondary agenda filtering.
  2764. This must be a list of strings, each string must be a single tag preceded
  2765. by \"+\" or \"-\".
  2766. This variable should not be set directly, but agenda custom commands can
  2767. bind it in the options section. The preset filter is a global property of
  2768. the entire agenda view. In a block agenda, it will not work reliably to
  2769. define a filter for one of the individual blocks. You need to set it in
  2770. the global options and expect it to be applied to the entire view.")
  2771. (defun org-prepare-agenda (&optional name)
  2772. (setq org-todo-keywords-for-agenda nil)
  2773. (setq org-done-keywords-for-agenda nil)
  2774. (setq org-drawers-for-agenda nil)
  2775. (unless org-agenda-persistent-filter
  2776. (setq org-agenda-filter nil))
  2777. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2778. (if org-agenda-multi
  2779. (progn
  2780. (setq buffer-read-only nil)
  2781. (goto-char (point-max))
  2782. (unless (or (bobp) org-agenda-compact-blocks
  2783. (not org-agenda-block-separator))
  2784. (insert "\n"
  2785. (if (stringp org-agenda-block-separator)
  2786. org-agenda-block-separator
  2787. (make-string (window-width) org-agenda-block-separator))
  2788. "\n"))
  2789. (narrow-to-region (point) (point-max)))
  2790. (org-agenda-reset-markers)
  2791. (setq org-agenda-contributing-files nil)
  2792. (setq org-agenda-columns-active nil)
  2793. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2794. (setq org-todo-keywords-for-agenda
  2795. (org-uniquify org-todo-keywords-for-agenda))
  2796. (setq org-done-keywords-for-agenda
  2797. (org-uniquify org-done-keywords-for-agenda))
  2798. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2799. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2800. (awin (get-buffer-window abuf)))
  2801. (cond
  2802. ((equal (current-buffer) abuf) nil)
  2803. (awin (select-window awin))
  2804. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2805. ((equal org-agenda-window-setup 'current-window)
  2806. (org-pop-to-buffer-same-window abuf))
  2807. ((equal org-agenda-window-setup 'other-window)
  2808. (org-switch-to-buffer-other-window abuf))
  2809. ((equal org-agenda-window-setup 'other-frame)
  2810. (switch-to-buffer-other-frame abuf))
  2811. ((equal org-agenda-window-setup 'reorganize-frame)
  2812. (delete-other-windows)
  2813. (org-switch-to-buffer-other-window abuf)))
  2814. ;; additional test in case agenda is invoked from within agenda
  2815. ;; buffer via elisp link
  2816. (unless (equal (current-buffer) abuf)
  2817. (org-pop-to-buffer-same-window abuf)))
  2818. (setq buffer-read-only nil)
  2819. (let ((inhibit-read-only t)) (erase-buffer))
  2820. (org-agenda-mode)
  2821. (and name (not org-agenda-name)
  2822. (org-set-local 'org-agenda-name name)))
  2823. (setq buffer-read-only nil))
  2824. (defun org-finalize-agenda ()
  2825. "Finishing touch for the agenda buffer, called just before displaying it."
  2826. (unless org-agenda-multi
  2827. (save-excursion
  2828. (let ((inhibit-read-only t))
  2829. (goto-char (point-min))
  2830. (while (org-activate-bracket-links (point-max))
  2831. (add-text-properties (match-beginning 0) (match-end 0)
  2832. '(face org-link)))
  2833. (org-agenda-align-tags)
  2834. (unless org-agenda-with-colors
  2835. (remove-text-properties (point-min) (point-max) '(face nil))))
  2836. (if (and (boundp 'org-agenda-overriding-columns-format)
  2837. org-agenda-overriding-columns-format)
  2838. (org-set-local 'org-agenda-overriding-columns-format
  2839. org-agenda-overriding-columns-format))
  2840. (if (and (boundp 'org-agenda-view-columns-initially)
  2841. org-agenda-view-columns-initially)
  2842. (org-agenda-columns))
  2843. (when org-agenda-fontify-priorities
  2844. (org-agenda-fontify-priorities))
  2845. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2846. (org-agenda-dim-blocked-tasks))
  2847. (org-agenda-mark-clocking-task)
  2848. (when org-agenda-entry-text-mode
  2849. (org-agenda-entry-text-hide)
  2850. (org-agenda-entry-text-show))
  2851. (if (functionp 'org-habit-insert-consistency-graphs)
  2852. (org-habit-insert-consistency-graphs))
  2853. (run-hooks 'org-finalize-agenda-hook)
  2854. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2855. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2856. (org-agenda-filter-apply org-agenda-filter))
  2857. )))
  2858. (defun org-agenda-mark-clocking-task ()
  2859. "Mark the current clock entry in the agenda if it is present."
  2860. (mapc (lambda (o)
  2861. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2862. (delete-overlay o)))
  2863. (overlays-in (point-min) (point-max)))
  2864. (when (marker-buffer org-clock-hd-marker)
  2865. (save-excursion
  2866. (goto-char (point-min))
  2867. (let (s ov)
  2868. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2869. (goto-char s)
  2870. (when (equal (org-get-at-bol 'org-hd-marker)
  2871. org-clock-hd-marker)
  2872. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2873. (overlay-put ov 'type 'org-agenda-clocking)
  2874. (overlay-put ov 'face 'org-agenda-clocking)
  2875. (overlay-put ov 'help-echo
  2876. "The clock is running in this item")))))))
  2877. (defun org-agenda-fontify-priorities ()
  2878. "Make highest priority lines bold, and lowest italic."
  2879. (interactive)
  2880. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2881. (delete-overlay o)))
  2882. (overlays-in (point-min) (point-max)))
  2883. (save-excursion
  2884. (let ((inhibit-read-only t)
  2885. b e p ov h l)
  2886. (goto-char (point-min))
  2887. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2888. (setq h (or (get-char-property (point) 'org-highest-priority)
  2889. org-highest-priority)
  2890. l (or (get-char-property (point) 'org-lowest-priority)
  2891. org-lowest-priority)
  2892. p (string-to-char (match-string 1))
  2893. b (match-beginning 0)
  2894. e (if (eq org-agenda-fontify-priorities 'cookies)
  2895. (match-end 0)
  2896. (point-at-eol))
  2897. ov (make-overlay b e))
  2898. (overlay-put
  2899. ov 'face
  2900. (cond ((org-face-from-face-or-color
  2901. 'priority nil
  2902. (cdr (assoc p org-priority-faces))))
  2903. ((and (listp org-agenda-fontify-priorities)
  2904. (org-face-from-face-or-color
  2905. 'priority nil
  2906. (cdr (assoc p org-agenda-fontify-priorities)))))
  2907. ((equal p l) 'italic)
  2908. ((equal p h) 'bold)))
  2909. (overlay-put ov 'org-type 'org-priority)))))
  2910. (defun org-agenda-dim-blocked-tasks ()
  2911. "Dim currently blocked TODO's in the agenda display."
  2912. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2913. (delete-overlay o)))
  2914. (overlays-in (point-min) (point-max)))
  2915. (save-excursion
  2916. (let ((inhibit-read-only t)
  2917. (org-depend-tag-blocked nil)
  2918. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2919. org-blocked-by-checkboxes
  2920. invis1 b e p ov h l)
  2921. (goto-char (point-min))
  2922. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2923. (and pos (goto-char (1+ pos))))
  2924. (setq org-blocked-by-checkboxes nil invis1 invis)
  2925. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2926. (when (and marker
  2927. (not (with-current-buffer (marker-buffer marker)
  2928. (save-excursion
  2929. (goto-char marker)
  2930. (if (org-entry-get nil "NOBLOCKING")
  2931. t ;; Never block this entry
  2932. (run-hook-with-args-until-failure
  2933. 'org-blocker-hook
  2934. (list :type 'todo-state-change
  2935. :position marker
  2936. :from 'todo
  2937. :to 'done)))))))
  2938. (if org-blocked-by-checkboxes (setq invis1 nil))
  2939. (setq b (if invis1
  2940. (max (point-min) (1- (point-at-bol)))
  2941. (point-at-bol))
  2942. e (point-at-eol)
  2943. ov (make-overlay b e))
  2944. (if invis1
  2945. (overlay-put ov 'invisible t)
  2946. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2947. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2948. (defvar org-agenda-skip-function nil
  2949. "Function to be called at each match during agenda construction.
  2950. If this function returns nil, the current match should not be skipped.
  2951. Otherwise, the function must return a position from where the search
  2952. should be continued.
  2953. This may also be a Lisp form, it will be evaluated.
  2954. Never set this variable using `setq' or so, because then it will apply
  2955. to all future agenda commands. If you do want a global skipping condition,
  2956. use the option `org-agenda-skip-function-global' instead.
  2957. The correct usage for `org-agenda-skip-function' is to bind it with
  2958. `let' to scope it dynamically into the agenda-constructing command.
  2959. A good way to set it is through options in `org-agenda-custom-commands'.")
  2960. (defun org-agenda-skip ()
  2961. "Throw to `:skip' in places that should be skipped.
  2962. Also moves point to the end of the skipped region, so that search can
  2963. continue from there."
  2964. (let ((p (point-at-bol)) to)
  2965. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2966. (get-text-property p :org-archived)
  2967. (org-end-of-subtree t)
  2968. (throw :skip t))
  2969. (and org-agenda-skip-comment-trees
  2970. (get-text-property p :org-comment)
  2971. (org-end-of-subtree t)
  2972. (throw :skip t))
  2973. (if (equal (char-after p) ?#) (throw :skip t))
  2974. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2975. (org-agenda-skip-eval org-agenda-skip-function)))
  2976. (goto-char to)
  2977. (throw :skip t))))
  2978. (defun org-agenda-skip-eval (form)
  2979. "If FORM is a function or a list, call (or eval) is and return result.
  2980. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2981. and match data are returned to the previous state no matter what these
  2982. functions do."
  2983. (let (fp)
  2984. (and form
  2985. (or (setq fp (functionp form))
  2986. (consp form))
  2987. (save-excursion
  2988. (save-match-data
  2989. (if fp
  2990. (funcall form)
  2991. (eval form)))))))
  2992. (defvar org-agenda-markers nil
  2993. "List of all currently active markers created by `org-agenda'.")
  2994. (defvar org-agenda-last-marker-time (org-float-time)
  2995. "Creation time of the last agenda marker.")
  2996. (defun org-agenda-new-marker (&optional pos)
  2997. "Return a new agenda marker.
  2998. Org-mode keeps a list of these markers and resets them when they are
  2999. no longer in use."
  3000. (let ((m (copy-marker (or pos (point)))))
  3001. (setq org-agenda-last-marker-time (org-float-time))
  3002. (push m org-agenda-markers)
  3003. m))
  3004. (defun org-agenda-reset-markers ()
  3005. "Reset markers created by `org-agenda'."
  3006. (while org-agenda-markers
  3007. (move-marker (pop org-agenda-markers) nil)))
  3008. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3009. "Save relative positions of markers in region."
  3010. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3011. org-agenda-markers))
  3012. ;;; Entry text mode
  3013. (defun org-agenda-entry-text-show-here ()
  3014. "Add some text from the entry as context to the current line."
  3015. (let (m txt o)
  3016. (setq m (org-get-at-bol 'org-hd-marker))
  3017. (unless (marker-buffer m)
  3018. (error "No marker points to an entry here"))
  3019. (setq txt (concat "\n" (org-no-properties
  3020. (org-agenda-get-some-entry-text
  3021. m org-agenda-entry-text-maxlines " > "))))
  3022. (when (string-match "\\S-" txt)
  3023. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3024. (overlay-put o 'evaporate t)
  3025. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3026. (overlay-put o 'after-string txt))))
  3027. (defun org-agenda-entry-text-show ()
  3028. "Add entry context for all agenda lines."
  3029. (interactive)
  3030. (save-excursion
  3031. (goto-char (point-max))
  3032. (beginning-of-line 1)
  3033. (while (not (bobp))
  3034. (when (org-get-at-bol 'org-hd-marker)
  3035. (org-agenda-entry-text-show-here))
  3036. (beginning-of-line 0))))
  3037. (defun org-agenda-entry-text-hide ()
  3038. "Remove any shown entry context."
  3039. (delq nil
  3040. (mapcar (lambda (o)
  3041. (if (eq (overlay-get o 'org-overlay-type)
  3042. 'agenda-entry-content)
  3043. (progn (delete-overlay o) t)))
  3044. (overlays-in (point-min) (point-max)))))
  3045. (defun org-agenda-get-day-face (date)
  3046. "Return the face DATE should be displayed with."
  3047. (or (and (functionp org-agenda-day-face-function)
  3048. (funcall org-agenda-day-face-function date))
  3049. (cond ((org-agenda-todayp date)
  3050. 'org-agenda-date-today)
  3051. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3052. 'org-agenda-date-weekend)
  3053. (t 'org-agenda-date))))
  3054. ;;; Agenda timeline
  3055. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3056. (defun org-timeline (&optional include-all)
  3057. "Show a time-sorted view of the entries in the current org file.
  3058. Only entries with a time stamp of today or later will be listed. With
  3059. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3060. under the current date.
  3061. If the buffer contains an active region, only check the region for
  3062. dates."
  3063. (interactive "P")
  3064. (org-compile-prefix-format 'timeline)
  3065. (org-set-sorting-strategy 'timeline)
  3066. (let* ((dopast t)
  3067. (dotodo include-all)
  3068. (doclosed org-agenda-show-log)
  3069. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3070. (current-buffer))))
  3071. (date (calendar-current-date))
  3072. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3073. (end (if (org-region-active-p) (region-end) (point-max)))
  3074. (day-numbers (org-get-all-dates beg end 'no-ranges
  3075. t doclosed ; always include today
  3076. org-timeline-show-empty-dates))
  3077. (org-deadline-warning-days 0)
  3078. (org-agenda-only-exact-dates t)
  3079. (today (org-today))
  3080. (past t)
  3081. args
  3082. s e rtn d emptyp)
  3083. (setq org-agenda-redo-command
  3084. (list 'progn
  3085. (list 'org-switch-to-buffer-other-window (current-buffer))
  3086. (list 'org-timeline (list 'quote include-all))))
  3087. (if (not dopast)
  3088. ;; Remove past dates from the list of dates.
  3089. (setq day-numbers (delq nil (mapcar (lambda(x)
  3090. (if (>= x today) x nil))
  3091. day-numbers))))
  3092. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3093. (if doclosed (push :closed args))
  3094. (push :timestamp args)
  3095. (push :deadline args)
  3096. (push :scheduled args)
  3097. (push :sexp args)
  3098. (if dotodo (push :todo args))
  3099. (insert "Timeline of file " entry "\n")
  3100. (add-text-properties (point-min) (point)
  3101. (list 'face 'org-agenda-structure))
  3102. (org-agenda-mark-header-line (point-min))
  3103. (while (setq d (pop day-numbers))
  3104. (if (and (listp d) (eq (car d) :omitted))
  3105. (progn
  3106. (setq s (point))
  3107. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3108. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3109. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3110. (if (and (>= d today)
  3111. dopast
  3112. past)
  3113. (progn
  3114. (setq past nil)
  3115. (insert (make-string 79 ?-) "\n")))
  3116. (setq date (calendar-gregorian-from-absolute d))
  3117. (setq s (point))
  3118. (setq rtn (and (not emptyp)
  3119. (apply 'org-agenda-get-day-entries entry
  3120. date args)))
  3121. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3122. (progn
  3123. (insert
  3124. (if (stringp org-agenda-format-date)
  3125. (format-time-string org-agenda-format-date
  3126. (org-time-from-absolute date))
  3127. (funcall org-agenda-format-date date))
  3128. "\n")
  3129. (put-text-property s (1- (point)) 'face
  3130. (org-agenda-get-day-face date))
  3131. (put-text-property s (1- (point)) 'org-date-line t)
  3132. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3133. (if (equal d today)
  3134. (put-text-property s (1- (point)) 'org-today t))
  3135. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3136. (put-text-property s (1- (point)) 'day d)))))
  3137. (goto-char (point-min))
  3138. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3139. (point-min)))
  3140. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3141. (org-finalize-agenda)
  3142. (setq buffer-read-only t)))
  3143. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3144. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3145. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3146. not every single day in the range. If FORCE-TODAY is non-nil, make
  3147. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3148. inactive time stamps (those in square brackets) are included.
  3149. When EMPTY is non-nil, also include days without any entries."
  3150. (let ((re (concat
  3151. (if pre-re pre-re "")
  3152. (if inactive org-ts-regexp-both org-ts-regexp)))
  3153. dates dates1 date day day1 day2 ts1 ts2)
  3154. (if force-today
  3155. (setq dates (list (org-today))))
  3156. (save-excursion
  3157. (goto-char beg)
  3158. (while (re-search-forward re end t)
  3159. (setq day (time-to-days (org-time-string-to-time
  3160. (substring (match-string 1) 0 10))))
  3161. (or (memq day dates) (push day dates)))
  3162. (unless no-ranges
  3163. (goto-char beg)
  3164. (while (re-search-forward org-tr-regexp end t)
  3165. (setq ts1 (substring (match-string 1) 0 10)
  3166. ts2 (substring (match-string 2) 0 10)
  3167. day1 (time-to-days (org-time-string-to-time ts1))
  3168. day2 (time-to-days (org-time-string-to-time ts2)))
  3169. (while (< (setq day1 (1+ day1)) day2)
  3170. (or (memq day1 dates) (push day1 dates)))))
  3171. (setq dates (sort dates '<))
  3172. (when empty
  3173. (while (setq day (pop dates))
  3174. (setq day2 (car dates))
  3175. (push day dates1)
  3176. (when (and day2 empty)
  3177. (if (or (eq empty t)
  3178. (and (numberp empty) (<= (- day2 day) empty)))
  3179. (while (< (setq day (1+ day)) day2)
  3180. (push (list day) dates1))
  3181. (push (cons :omitted (- day2 day)) dates1))))
  3182. (setq dates (nreverse dates1)))
  3183. dates)))
  3184. ;;; Agenda Daily/Weekly
  3185. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3186. "Start day for the agenda view.
  3187. Custom commands can set this variable in the options section.")
  3188. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3189. (defvar org-agenda-current-span nil
  3190. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3191. (defvar org-include-all-loc nil) ; local variable
  3192. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3193. "List of types searched for when creating the daily/weekly agenda.
  3194. This variable is a list of symbols that controls the types of
  3195. items that appear in the daily/weekly agenda. Allowed symbols in this
  3196. list are are
  3197. :timestamp List items containing a date stamp or date range matching
  3198. the selected date. This includes sexp entries in
  3199. angular brackets.
  3200. :sexp List entries resulting from plain diary-like sexps.
  3201. :deadline List deadline due on that date. When the date is today,
  3202. also list any deadlines past due, or due within
  3203. `org-deadline-warning-days'. `:deadline' must appear before
  3204. `:scheduled' if the setting of
  3205. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3206. any effect.
  3207. :scheduled List all items which are scheduled for the given date.
  3208. The diary for *today* also contains items which were
  3209. scheduled earlier and are not yet marked DONE.
  3210. By default, all four types are turned on.
  3211. Never set this variable globally using `setq', because then it
  3212. will apply to all future agenda commands. Instead, bind it with
  3213. `let' to scope it dynamically into the agenda-constructing
  3214. command. A good way to set it is through options in
  3215. `org-agenda-custom-commands'. For a more flexible (though
  3216. somewhat less efficient) way of determining what is included in
  3217. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3218. ;;;###autoload
  3219. (defun org-agenda-list (&optional include-all start-day span)
  3220. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3221. The view will be for the current day or week, but from the overview buffer
  3222. you will be able to go to other days/weeks.
  3223. With a numeric prefix argument in an interactive call, the agenda will
  3224. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3225. the number of days. SPAN defaults to `org-agenda-span'.
  3226. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3227. given in `org-agenda-start-on-weekday'."
  3228. (interactive "P")
  3229. (if (and (integerp include-all) (> include-all 0))
  3230. (setq span include-all include-all nil))
  3231. (setq start-day (or start-day org-agenda-start-day))
  3232. (if org-agenda-overriding-arguments
  3233. (setq include-all (car org-agenda-overriding-arguments)
  3234. start-day (nth 1 org-agenda-overriding-arguments)
  3235. span (nth 2 org-agenda-overriding-arguments)))
  3236. (if (stringp start-day)
  3237. ;; Convert to an absolute day number
  3238. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3239. (setq org-agenda-last-arguments (list include-all start-day span))
  3240. (org-compile-prefix-format 'agenda)
  3241. (org-set-sorting-strategy 'agenda)
  3242. (let* ((span (org-agenda-ndays-to-span
  3243. (or span org-agenda-ndays org-agenda-span)))
  3244. (today (org-today))
  3245. (sd (or start-day today))
  3246. (ndays (org-agenda-span-to-ndays span sd))
  3247. (org-agenda-start-on-weekday
  3248. (if (eq ndays 7)
  3249. org-agenda-start-on-weekday))
  3250. (thefiles (org-agenda-files nil 'ifmode))
  3251. (files thefiles)
  3252. (start (if (or (null org-agenda-start-on-weekday)
  3253. (< ndays 7))
  3254. sd
  3255. (let* ((nt (calendar-day-of-week
  3256. (calendar-gregorian-from-absolute sd)))
  3257. (n1 org-agenda-start-on-weekday)
  3258. (d (- nt n1)))
  3259. (- sd (+ (if (< d 0) 7 0) d)))))
  3260. (day-numbers (list start))
  3261. (day-cnt 0)
  3262. (inhibit-redisplay (not debug-on-error))
  3263. s e rtn rtnall file date d start-pos end-pos todayp
  3264. clocktable-start clocktable-end filter)
  3265. (setq org-agenda-redo-command
  3266. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3267. (dotimes (n (1- ndays))
  3268. (push (1+ (car day-numbers)) day-numbers))
  3269. (setq day-numbers (nreverse day-numbers))
  3270. (setq clocktable-start (car day-numbers)
  3271. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3272. (org-prepare-agenda "Day/Week")
  3273. (org-set-local 'org-starting-day (car day-numbers))
  3274. (org-set-local 'org-include-all-loc include-all)
  3275. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3276. (unless org-agenda-compact-blocks
  3277. (let* ((d1 (car day-numbers))
  3278. (d2 (org-last day-numbers))
  3279. (w1 (org-days-to-iso-week d1))
  3280. (w2 (org-days-to-iso-week d2)))
  3281. (setq s (point))
  3282. (if org-agenda-overriding-header
  3283. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3284. nil 'face 'org-agenda-structure) "\n")
  3285. (insert (org-agenda-span-name span)
  3286. "-agenda"
  3287. (if (< (- d2 d1) 350)
  3288. (if (= w1 w2)
  3289. (format " (W%02d)" w1)
  3290. (format " (W%02d-W%02d)" w1 w2))
  3291. "")
  3292. ":\n")))
  3293. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3294. 'org-date-line t))
  3295. (org-agenda-mark-header-line s))
  3296. (while (setq d (pop day-numbers))
  3297. (setq date (calendar-gregorian-from-absolute d)
  3298. s (point))
  3299. (if (or (setq todayp (= d today))
  3300. (and (not start-pos) (= d sd)))
  3301. (setq start-pos (point))
  3302. (if (and start-pos (not end-pos))
  3303. (setq end-pos (point))))
  3304. (setq files thefiles
  3305. rtnall nil)
  3306. (while (setq file (pop files))
  3307. (catch 'nextfile
  3308. (org-check-agenda-file file)
  3309. (let ((org-agenda-entry-types org-agenda-entry-types))
  3310. (unless org-agenda-include-deadlines
  3311. (setq org-agenda-entry-types
  3312. (delq :deadline org-agenda-entry-types)))
  3313. (cond
  3314. ((memq org-agenda-show-log '(only clockcheck))
  3315. (setq rtn (org-agenda-get-day-entries
  3316. file date :closed)))
  3317. (org-agenda-show-log
  3318. (setq rtn (apply 'org-agenda-get-day-entries
  3319. file date
  3320. (append '(:closed) org-agenda-entry-types))))
  3321. (t
  3322. (setq rtn (apply 'org-agenda-get-day-entries
  3323. file date
  3324. org-agenda-entry-types)))))
  3325. (setq rtnall (append rtnall rtn))))
  3326. (if org-agenda-include-diary
  3327. (let ((org-agenda-search-headline-for-time t))
  3328. (require 'diary-lib)
  3329. (setq rtn (org-get-entries-from-diary date))
  3330. (setq rtnall (append rtnall rtn))))
  3331. (if (or rtnall org-agenda-show-all-dates)
  3332. (progn
  3333. (setq day-cnt (1+ day-cnt))
  3334. (insert
  3335. (if (stringp org-agenda-format-date)
  3336. (format-time-string org-agenda-format-date
  3337. (org-time-from-absolute date))
  3338. (funcall org-agenda-format-date date))
  3339. "\n")
  3340. (put-text-property s (1- (point)) 'face
  3341. (org-agenda-get-day-face date))
  3342. (put-text-property s (1- (point)) 'org-date-line t)
  3343. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3344. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3345. (when todayp
  3346. (put-text-property s (1- (point)) 'org-today t))
  3347. (if rtnall (insert
  3348. (org-finalize-agenda-entries
  3349. (org-agenda-add-time-grid-maybe
  3350. rtnall ndays todayp))
  3351. "\n"))
  3352. (put-text-property s (1- (point)) 'day d)
  3353. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3354. (when (and org-agenda-clockreport-mode clocktable-start)
  3355. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3356. ;; the above line is to ensure the restricted range!
  3357. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3358. tbl)
  3359. (setq p (org-plist-delete p :block))
  3360. (setq p (plist-put p :tstart clocktable-start))
  3361. (setq p (plist-put p :tend clocktable-end))
  3362. (setq p (plist-put p :scope 'agenda))
  3363. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3364. (setq filter (or org-agenda-filter-while-redo
  3365. (get 'org-agenda-filter :preset-filter))))
  3366. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3367. (if (string-match "[<>=]" x)
  3368. ""
  3369. x))
  3370. filter ""))))
  3371. (setq tbl (apply 'org-get-clocktable p))
  3372. (insert tbl)))
  3373. (goto-char (point-min))
  3374. (or org-agenda-multi (org-fit-agenda-window))
  3375. (unless (and (pos-visible-in-window-p (point-min))
  3376. (pos-visible-in-window-p (point-max)))
  3377. (goto-char (1- (point-max)))
  3378. (recenter -1)
  3379. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3380. (progn
  3381. (goto-char (or start-pos 1))
  3382. (recenter 1))))
  3383. (goto-char (or start-pos 1))
  3384. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3385. (if (eq org-agenda-show-log 'clockcheck)
  3386. (org-agenda-show-clocking-issues))
  3387. (org-finalize-agenda)
  3388. (setq buffer-read-only t)
  3389. (message "")))
  3390. (defun org-agenda-ndays-to-span (n)
  3391. "Return a span symbol for a span of N days, or N if none matches."
  3392. (cond ((symbolp n) n)
  3393. ((= n 1) 'day)
  3394. ((= n 7) 'week)
  3395. (t n)))
  3396. (defun org-agenda-span-to-ndays (span start-day)
  3397. "Return ndays from SPAN starting at START-DAY."
  3398. (cond ((numberp span) span)
  3399. ((eq span 'day) 1)
  3400. ((eq span 'week) 7)
  3401. ((eq span 'month)
  3402. (let ((date (calendar-gregorian-from-absolute start-day)))
  3403. (calendar-last-day-of-month (car date) (caddr date))))
  3404. ((eq span 'year)
  3405. (let ((date (calendar-gregorian-from-absolute start-day)))
  3406. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3407. (defun org-agenda-span-name (span)
  3408. "Return a SPAN name."
  3409. (if (null span)
  3410. ""
  3411. (if (symbolp span)
  3412. (capitalize (symbol-name span))
  3413. (format "%d days" span))))
  3414. ;;; Agenda word search
  3415. (defvar org-agenda-search-history nil)
  3416. (defvar org-todo-only nil)
  3417. (defvar org-search-syntax-table nil
  3418. "Special syntax table for org-mode search.
  3419. In this table, we have single quotes not as word constituents, to
  3420. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3421. (defun org-search-syntax-table ()
  3422. (unless org-search-syntax-table
  3423. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3424. (modify-syntax-entry ?' "." org-search-syntax-table)
  3425. (modify-syntax-entry ?` "." org-search-syntax-table))
  3426. org-search-syntax-table)
  3427. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3428. ;;;###autoload
  3429. (defun org-search-view (&optional todo-only string edit-at)
  3430. "Show all entries that contain a phrase or words or regular expressions.
  3431. With optional prefix argument TODO-ONLY, only consider entries that are
  3432. TODO entries. The argument STRING can be used to pass a default search
  3433. string into this function. If EDIT-AT is non-nil, it means that the
  3434. user should get a chance to edit this string, with cursor at position
  3435. EDIT-AT.
  3436. The search string can be viewed either as a phrase that should be found as
  3437. is, or it can be broken into a number of snippets, each of which must match
  3438. in a Boolean way to select an entry. The default depends on the variable
  3439. `org-agenda-search-view-always-boolean'.
  3440. Even if this is turned off (the default) you can always switch to
  3441. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3442. The default is a direct search of the whole phrase, where each space in
  3443. the search string can expand to an arbitrary amount of whitespace,
  3444. including newlines.
  3445. If using a Boolean search, the search string is split on whitespace and
  3446. each snippet is searched separately, with logical AND to select an entry.
  3447. Words prefixed with a minus must *not* occur in the entry. Words without
  3448. a prefix or prefixed with a plus must occur in the entry. Matching is
  3449. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3450. match whole words, not parts of a word) if
  3451. `org-agenda-search-view-force-full-words' is set (default is nil).
  3452. Boolean search snippets enclosed by curly braces are interpreted as
  3453. regular expressions that must or (when preceded with \"-\") must not
  3454. match in the entry. Snippets enclosed into double quotes will be taken
  3455. as a whole, to include whitespace.
  3456. - If the search string starts with an asterisk, search only in headlines.
  3457. - If (possibly after the leading star) the search string starts with an
  3458. exclamation mark, this also means to look at TODO entries only, an effect
  3459. that can also be achieved with a prefix argument.
  3460. - If (possibly after star and exclamation mark) the search string starts
  3461. with a colon, this will mean that the (non-regexp) snippets of the
  3462. Boolean search must match as full words.
  3463. This command searches the agenda files, and in addition the files listed
  3464. in `org-agenda-text-search-extra-files'."
  3465. (interactive "P")
  3466. (org-compile-prefix-format 'search)
  3467. (org-set-sorting-strategy 'search)
  3468. (org-prepare-agenda "SEARCH")
  3469. (let* ((props (list 'face nil
  3470. 'done-face 'org-agenda-done
  3471. 'org-not-done-regexp org-not-done-regexp
  3472. 'org-todo-regexp org-todo-regexp
  3473. 'org-complex-heading-regexp org-complex-heading-regexp
  3474. 'mouse-face 'highlight
  3475. 'help-echo (format "mouse-2 or RET jump to location")))
  3476. (full-words org-agenda-search-view-force-full-words)
  3477. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3478. regexp rtn rtnall files file pos
  3479. marker category tags c neg re boolean
  3480. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3481. (unless (and (not edit-at)
  3482. (stringp string)
  3483. (string-match "\\S-" string))
  3484. (setq string (read-string
  3485. (if org-agenda-search-view-always-boolean
  3486. "[+-]Word/{Regexp} ...: "
  3487. "Phrase, or [+-]Word/{Regexp} ...: ")
  3488. (cond
  3489. ((integerp edit-at) (cons string edit-at))
  3490. (edit-at string))
  3491. 'org-agenda-search-history)))
  3492. (org-set-local 'org-todo-only todo-only)
  3493. (setq org-agenda-redo-command
  3494. (list 'org-search-view (if todo-only t nil) string
  3495. '(if current-prefix-arg 1 nil)))
  3496. (setq org-agenda-query-string string)
  3497. (if (equal (string-to-char string) ?*)
  3498. (setq hdl-only t
  3499. words (substring string 1))
  3500. (setq words string))
  3501. (when (equal (string-to-char words) ?!)
  3502. (setq todo-only t
  3503. words (substring words 1)))
  3504. (when (equal (string-to-char words) ?:)
  3505. (setq full-words t
  3506. words (substring words 1)))
  3507. (if (or org-agenda-search-view-always-boolean
  3508. (member (string-to-char words) '(?- ?+ ?\{)))
  3509. (setq boolean t))
  3510. (setq words (org-split-string words))
  3511. (let (www w)
  3512. (while (setq w (pop words))
  3513. (while (and (string-match "\\\\\\'" w) words)
  3514. (setq w (concat (substring w 0 -1) " " (pop words))))
  3515. (push w www))
  3516. (setq words (nreverse www) www nil)
  3517. (while (setq w (pop words))
  3518. (when (and (string-match "\\`[-+]?{" w)
  3519. (not (string-match "}\\'" w)))
  3520. (while (and words (not (string-match "}\\'" (car words))))
  3521. (setq w (concat w " " (pop words))))
  3522. (setq w (concat w " " (pop words))))
  3523. (push w www))
  3524. (setq words (nreverse www)))
  3525. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3526. (when boolean
  3527. (let (wds w)
  3528. (while (setq w (pop words))
  3529. (if (or (equal (substring w 0 1) "\"")
  3530. (and (> (length w) 1)
  3531. (member (substring w 0 1) '("+" "-"))
  3532. (equal (substring w 1 2) "\"")))
  3533. (while (and words (not (equal (substring w -1) "\"")))
  3534. (setq w (concat w " " (pop words)))))
  3535. (and (string-match "\\`\\([-+]?\\)\"" w)
  3536. (setq w (replace-match "\\1" nil nil w)))
  3537. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3538. (push w wds))
  3539. (setq words (nreverse wds))))
  3540. (if boolean
  3541. (mapc (lambda (w)
  3542. (setq c (string-to-char w))
  3543. (if (equal c ?-)
  3544. (setq neg t w (substring w 1))
  3545. (if (equal c ?+)
  3546. (setq neg nil w (substring w 1))
  3547. (setq neg nil)))
  3548. (if (string-match "\\`{.*}\\'" w)
  3549. (setq re (substring w 1 -1))
  3550. (if full-words
  3551. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3552. (setq re (regexp-quote (downcase w)))))
  3553. (if neg (push re regexps-) (push re regexps+)))
  3554. words)
  3555. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3556. regexps+))
  3557. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3558. (if (not regexps+)
  3559. (setq regexp org-outline-regexp-bol)
  3560. (setq regexp (pop regexps+))
  3561. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3562. regexp))))
  3563. (setq files (org-agenda-files nil 'ifmode))
  3564. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3565. (pop org-agenda-text-search-extra-files)
  3566. (setq files (org-add-archive-files files)))
  3567. (setq files (append files org-agenda-text-search-extra-files)
  3568. rtnall nil)
  3569. (while (setq file (pop files))
  3570. (setq ee nil)
  3571. (catch 'nextfile
  3572. (org-check-agenda-file file)
  3573. (setq buffer (if (file-exists-p file)
  3574. (org-get-agenda-file-buffer file)
  3575. (error "No such file %s" file)))
  3576. (if (not buffer)
  3577. ;; If file does not exist, make sure an error message is sent
  3578. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3579. file))))
  3580. (with-current-buffer buffer
  3581. (with-syntax-table (org-search-syntax-table)
  3582. (unless (org-mode-p)
  3583. (error "Agenda file %s is not in `org-mode'" file))
  3584. (let ((case-fold-search t))
  3585. (save-excursion
  3586. (save-restriction
  3587. (if org-agenda-restrict
  3588. (narrow-to-region org-agenda-restrict-begin
  3589. org-agenda-restrict-end)
  3590. (widen))
  3591. (goto-char (point-min))
  3592. (unless (or (org-on-heading-p)
  3593. (outline-next-heading))
  3594. (throw 'nextfile t))
  3595. (goto-char (max (point-min) (1- (point))))
  3596. (while (re-search-forward regexp nil t)
  3597. (org-back-to-heading t)
  3598. (skip-chars-forward "* ")
  3599. (setq beg (point-at-bol)
  3600. beg1 (point)
  3601. end (progn (outline-next-heading) (point)))
  3602. (catch :skip
  3603. (goto-char beg)
  3604. (org-agenda-skip)
  3605. (setq str (buffer-substring-no-properties
  3606. (point-at-bol)
  3607. (if hdl-only (point-at-eol) end)))
  3608. (mapc (lambda (wr) (when (string-match wr str)
  3609. (goto-char (1- end))
  3610. (throw :skip t)))
  3611. regexps-)
  3612. (mapc (lambda (wr) (unless (string-match wr str)
  3613. (goto-char (1- end))
  3614. (throw :skip t)))
  3615. (if todo-only
  3616. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3617. regexps+)
  3618. regexps+))
  3619. (goto-char beg)
  3620. (setq marker (org-agenda-new-marker (point))
  3621. category (org-get-category)
  3622. tags (org-get-tags-at (point))
  3623. txt (org-format-agenda-item
  3624. ""
  3625. (buffer-substring-no-properties
  3626. beg1 (point-at-eol))
  3627. category tags))
  3628. (org-add-props txt props
  3629. 'org-marker marker 'org-hd-marker marker
  3630. 'org-todo-regexp org-todo-regexp
  3631. 'org-complex-heading-regexp org-complex-heading-regexp
  3632. 'priority 1000 'org-category category
  3633. 'type "search")
  3634. (push txt ee)
  3635. (goto-char (1- end))))))))))
  3636. (setq rtn (nreverse ee))
  3637. (setq rtnall (append rtnall rtn)))
  3638. (if org-agenda-overriding-header
  3639. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3640. nil 'face 'org-agenda-structure) "\n")
  3641. (insert "Search words: ")
  3642. (add-text-properties (point-min) (1- (point))
  3643. (list 'face 'org-agenda-structure))
  3644. (setq pos (point))
  3645. (insert string "\n")
  3646. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3647. (setq pos (point))
  3648. (unless org-agenda-multi
  3649. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3650. (add-text-properties pos (1- (point))
  3651. (list 'face 'org-agenda-structure))))
  3652. (org-agenda-mark-header-line (point-min))
  3653. (when rtnall
  3654. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3655. (goto-char (point-min))
  3656. (or org-agenda-multi (org-fit-agenda-window))
  3657. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3658. (org-finalize-agenda)
  3659. (setq buffer-read-only t)))
  3660. ;;; Agenda TODO list
  3661. (defvar org-select-this-todo-keyword nil)
  3662. (defvar org-last-arg nil)
  3663. ;;;###autoload
  3664. (defun org-todo-list (arg)
  3665. "Show all (not done) TODO entries from all agenda file in a single list.
  3666. The prefix arg can be used to select a specific TODO keyword and limit
  3667. the list to these. When using \\[universal-argument], you will be prompted
  3668. for a keyword. A numeric prefix directly selects the Nth keyword in
  3669. `org-todo-keywords-1'."
  3670. (interactive "P")
  3671. (org-compile-prefix-format 'todo)
  3672. (org-set-sorting-strategy 'todo)
  3673. (org-prepare-agenda "TODO")
  3674. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3675. (let* ((today (org-today))
  3676. (date (calendar-gregorian-from-absolute today))
  3677. (kwds org-todo-keywords-for-agenda)
  3678. (completion-ignore-case t)
  3679. (org-select-this-todo-keyword
  3680. (if (stringp arg) arg
  3681. (and arg (integerp arg) (> arg 0)
  3682. (nth (1- arg) kwds))))
  3683. rtn rtnall files file pos)
  3684. (when (equal arg '(4))
  3685. (setq org-select-this-todo-keyword
  3686. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3687. (mapcar 'list kwds) nil nil)))
  3688. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3689. (org-set-local 'org-last-arg arg)
  3690. (setq org-agenda-redo-command
  3691. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3692. (setq files (org-agenda-files nil 'ifmode)
  3693. rtnall nil)
  3694. (while (setq file (pop files))
  3695. (catch 'nextfile
  3696. (org-check-agenda-file file)
  3697. (setq rtn (org-agenda-get-day-entries file date :todo))
  3698. (setq rtnall (append rtnall rtn))))
  3699. (if org-agenda-overriding-header
  3700. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3701. nil 'face 'org-agenda-structure) "\n")
  3702. (insert "Global list of TODO items of type: ")
  3703. (add-text-properties (point-min) (1- (point))
  3704. (list 'face 'org-agenda-structure
  3705. 'short-heading
  3706. (concat "ToDo: "
  3707. (or org-select-this-todo-keyword "ALL"))))
  3708. (org-agenda-mark-header-line (point-min))
  3709. (setq pos (point))
  3710. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3711. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3712. (setq pos (point))
  3713. (unless org-agenda-multi
  3714. (insert "Available with `N r': (0)ALL")
  3715. (let ((n 0) s)
  3716. (mapc (lambda (x)
  3717. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3718. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3719. (insert "\n "))
  3720. (insert " " s))
  3721. kwds))
  3722. (insert "\n"))
  3723. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3724. (org-agenda-mark-header-line (point-min))
  3725. (when rtnall
  3726. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3727. (goto-char (point-min))
  3728. (or org-agenda-multi (org-fit-agenda-window))
  3729. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3730. (org-finalize-agenda)
  3731. (setq buffer-read-only t)))
  3732. ;;; Agenda tags match
  3733. ;;;###autoload
  3734. (defun org-tags-view (&optional todo-only match)
  3735. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3736. The prefix arg TODO-ONLY limits the search to TODO entries."
  3737. (interactive "P")
  3738. (org-compile-prefix-format 'tags)
  3739. (org-set-sorting-strategy 'tags)
  3740. (let* ((org-tags-match-list-sublevels
  3741. org-tags-match-list-sublevels)
  3742. (completion-ignore-case t)
  3743. rtn rtnall files file pos matcher
  3744. buffer)
  3745. (when (and (stringp match) (not (string-match "\\S-" match)))
  3746. (setq match nil))
  3747. (setq matcher (org-make-tags-matcher match)
  3748. match (car matcher) matcher (cdr matcher))
  3749. (org-prepare-agenda (concat "TAGS " match))
  3750. (setq org-agenda-query-string match)
  3751. (setq org-agenda-redo-command
  3752. (list 'org-tags-view (list 'quote todo-only)
  3753. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3754. (setq files (org-agenda-files nil 'ifmode)
  3755. rtnall nil)
  3756. (while (setq file (pop files))
  3757. (catch 'nextfile
  3758. (org-check-agenda-file file)
  3759. (setq buffer (if (file-exists-p file)
  3760. (org-get-agenda-file-buffer file)
  3761. (error "No such file %s" file)))
  3762. (if (not buffer)
  3763. ;; If file does not exist, error message to agenda
  3764. (setq rtn (list
  3765. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3766. rtnall (append rtnall rtn))
  3767. (with-current-buffer buffer
  3768. (unless (org-mode-p)
  3769. (error "Agenda file %s is not in `org-mode'" file))
  3770. (save-excursion
  3771. (save-restriction
  3772. (if org-agenda-restrict
  3773. (narrow-to-region org-agenda-restrict-begin
  3774. org-agenda-restrict-end)
  3775. (widen))
  3776. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3777. (setq rtnall (append rtnall rtn))))))))
  3778. (if org-agenda-overriding-header
  3779. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3780. nil 'face 'org-agenda-structure) "\n")
  3781. (insert "Headlines with TAGS match: ")
  3782. (add-text-properties (point-min) (1- (point))
  3783. (list 'face 'org-agenda-structure
  3784. 'short-heading
  3785. (concat "Match: " match)))
  3786. (setq pos (point))
  3787. (insert match "\n")
  3788. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3789. (setq pos (point))
  3790. (unless org-agenda-multi
  3791. (insert "Press `C-u r' to search again with new search string\n"))
  3792. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3793. (org-agenda-mark-header-line (point-min))
  3794. (when rtnall
  3795. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3796. (goto-char (point-min))
  3797. (or org-agenda-multi (org-fit-agenda-window))
  3798. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3799. (org-finalize-agenda)
  3800. (setq buffer-read-only t)))
  3801. ;;; Agenda Finding stuck projects
  3802. (defvar org-agenda-skip-regexp nil
  3803. "Regular expression used in skipping subtrees for the agenda.
  3804. This is basically a temporary global variable that can be set and then
  3805. used by user-defined selections using `org-agenda-skip-function'.")
  3806. (defvar org-agenda-overriding-header nil
  3807. "When set during agenda, todo and tags searches it replaces the header.
  3808. This variable should not be set directly, but custom commands can bind it
  3809. in the options section.")
  3810. (defun org-agenda-skip-entry-when-regexp-matches ()
  3811. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3812. If yes, it returns the end position of this entry, causing agenda commands
  3813. to skip the entry but continuing the search in the subtree. This is a
  3814. function that can be put into `org-agenda-skip-function' for the duration
  3815. of a command."
  3816. (let ((end (save-excursion (org-end-of-subtree t)))
  3817. skip)
  3818. (save-excursion
  3819. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3820. (and skip end)))
  3821. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3822. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3823. If yes, it returns the end position of this tree, causing agenda commands
  3824. to skip this subtree. This is a function that can be put into
  3825. `org-agenda-skip-function' for the duration of a command."
  3826. (let ((end (save-excursion (org-end-of-subtree t)))
  3827. skip)
  3828. (save-excursion
  3829. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3830. (and skip end)))
  3831. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3832. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3833. If yes, it returns the end position of the current entry (NOT the tree),
  3834. causing agenda commands to skip the entry but continuing the search in
  3835. the subtree. This is a function that can be put into
  3836. `org-agenda-skip-function' for the duration of a command. An important
  3837. use of this function is for the stuck project list."
  3838. (let ((end (save-excursion (org-end-of-subtree t)))
  3839. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3840. skip)
  3841. (save-excursion
  3842. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3843. (and skip entry-end)))
  3844. (defun org-agenda-skip-entry-if (&rest conditions)
  3845. "Skip entry if any of CONDITIONS is true.
  3846. See `org-agenda-skip-if' for details."
  3847. (org-agenda-skip-if nil conditions))
  3848. (defun org-agenda-skip-subtree-if (&rest conditions)
  3849. "Skip entry if any of CONDITIONS is true.
  3850. See `org-agenda-skip-if' for details."
  3851. (org-agenda-skip-if t conditions))
  3852. (defun org-agenda-skip-if (subtree conditions)
  3853. "Checks current entity for CONDITIONS.
  3854. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3855. the entry, i.e. the text before the next heading is checked.
  3856. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3857. from different tests. Valid conditions are:
  3858. scheduled Check if there is a scheduled cookie
  3859. notscheduled Check if there is no scheduled cookie
  3860. deadline Check if there is a deadline
  3861. notdeadline Check if there is no deadline
  3862. timestamp Check if there is a timestamp (also deadline or scheduled)
  3863. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3864. regexp Check if regexp matches
  3865. notregexp Check if regexp does not match.
  3866. todo Check if TODO keyword matches
  3867. nottodo Check if TODO keyword does not match
  3868. The regexp is taken from the conditions list, it must come right after
  3869. the `regexp' or `notregexp' element.
  3870. `todo' and `nottodo' accept as an argument a list of todo
  3871. keywords, which may include \"*\" to match any todo keyword.
  3872. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3873. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3874. Instead of a list a keyword class may be given
  3875. (org-agenda-skip-entry-if 'nottodo 'done)
  3876. would skip entries that haven't been marked with any of \"DONE\"
  3877. keywords. Possible classes are: `todo', `done', `any'.
  3878. If any of these conditions is met, this function returns the end point of
  3879. the entity, causing the search to continue from there. This is a function
  3880. that can be put into `org-agenda-skip-function' for the duration of a command."
  3881. (let (beg end m)
  3882. (org-back-to-heading t)
  3883. (setq beg (point)
  3884. end (if subtree
  3885. (progn (org-end-of-subtree t) (point))
  3886. (progn (outline-next-heading) (1- (point)))))
  3887. (goto-char beg)
  3888. (and
  3889. (or
  3890. (and (memq 'scheduled conditions)
  3891. (re-search-forward org-scheduled-time-regexp end t))
  3892. (and (memq 'notscheduled conditions)
  3893. (not (re-search-forward org-scheduled-time-regexp end t)))
  3894. (and (memq 'deadline conditions)
  3895. (re-search-forward org-deadline-time-regexp end t))
  3896. (and (memq 'notdeadline conditions)
  3897. (not (re-search-forward org-deadline-time-regexp end t)))
  3898. (and (memq 'timestamp conditions)
  3899. (re-search-forward org-ts-regexp end t))
  3900. (and (memq 'nottimestamp conditions)
  3901. (not (re-search-forward org-ts-regexp end t)))
  3902. (and (setq m (memq 'regexp conditions))
  3903. (stringp (nth 1 m))
  3904. (re-search-forward (nth 1 m) end t))
  3905. (and (setq m (memq 'notregexp conditions))
  3906. (stringp (nth 1 m))
  3907. (not (re-search-forward (nth 1 m) end t)))
  3908. (and (or
  3909. (setq m (memq 'todo conditions))
  3910. (setq m (memq 'nottodo conditions)))
  3911. (org-agenda-skip-if-todo m end)))
  3912. end)))
  3913. (defun org-agenda-skip-if-todo (args end)
  3914. "Helper function for `org-agenda-skip-if', do not use it directly.
  3915. ARGS is a list with first element either `todo' or `nottodo'.
  3916. The remainder is either a list of TODO keywords, or a state symbol
  3917. `todo' or `done' or `any'."
  3918. (let ((kw (car args))
  3919. (arg (cadr args))
  3920. todo-wds todo-re)
  3921. (setq todo-wds
  3922. (org-uniquify
  3923. (cond
  3924. ((listp arg) ;; list of keywords
  3925. (if (member "*" arg)
  3926. (mapcar 'substring-no-properties org-todo-keywords-1)
  3927. arg))
  3928. ((symbolp arg) ;; keyword class name
  3929. (cond
  3930. ((eq arg 'todo)
  3931. (org-delete-all org-done-keywords
  3932. (mapcar 'substring-no-properties
  3933. org-todo-keywords-1)))
  3934. ((eq arg 'done) org-done-keywords)
  3935. ((eq arg 'any)
  3936. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3937. (setq todo-re
  3938. (concat "^\\*+[ \t]+\\<\\("
  3939. (mapconcat 'identity todo-wds "\\|")
  3940. "\\)\\>"))
  3941. (if (eq kw 'todo)
  3942. (re-search-forward todo-re end t)
  3943. (not (re-search-forward todo-re end t)))))
  3944. ;;;###autoload
  3945. (defun org-agenda-list-stuck-projects (&rest ignore)
  3946. "Create agenda view for projects that are stuck.
  3947. Stuck projects are project that have no next actions. For the definitions
  3948. of what a project is and how to check if it stuck, customize the variable
  3949. `org-stuck-projects'."
  3950. (interactive)
  3951. (let* ((org-agenda-skip-function
  3952. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3953. ;; We could have used org-agenda-skip-if here.
  3954. (org-agenda-overriding-header
  3955. (or org-agenda-overriding-header "List of stuck projects: "))
  3956. (matcher (nth 0 org-stuck-projects))
  3957. (todo (nth 1 org-stuck-projects))
  3958. (todo-wds (if (member "*" todo)
  3959. (progn
  3960. (org-prepare-agenda-buffers (org-agenda-files
  3961. nil 'ifmode))
  3962. (org-delete-all
  3963. org-done-keywords-for-agenda
  3964. (copy-sequence org-todo-keywords-for-agenda)))
  3965. todo))
  3966. (todo-re (concat "^\\*+[ \t]+\\("
  3967. (mapconcat 'identity todo-wds "\\|")
  3968. "\\)\\>"))
  3969. (tags (nth 2 org-stuck-projects))
  3970. (tags-re (if (member "*" tags)
  3971. (org-re (concat org-outline-regexp-bol
  3972. ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3973. (if tags
  3974. (concat org-outline-regexp-bol
  3975. ".*:\\("
  3976. (mapconcat 'identity tags "\\|")
  3977. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3978. (gen-re (nth 3 org-stuck-projects))
  3979. (re-list
  3980. (delq nil
  3981. (list
  3982. (if todo todo-re)
  3983. (if tags tags-re)
  3984. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3985. gen-re)))))
  3986. (setq org-agenda-skip-regexp
  3987. (if re-list
  3988. (mapconcat 'identity re-list "\\|")
  3989. (error "No information how to identify unstuck projects")))
  3990. (org-tags-view nil matcher)
  3991. (with-current-buffer org-agenda-buffer-name
  3992. (setq org-agenda-redo-command
  3993. '(org-agenda-list-stuck-projects
  3994. (or current-prefix-arg org-last-arg))))))
  3995. ;;; Diary integration
  3996. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3997. (defvar list-diary-entries-hook)
  3998. (defvar diary-time-regexp)
  3999. (defun org-get-entries-from-diary (date)
  4000. "Get the (Emacs Calendar) diary entries for DATE."
  4001. (require 'diary-lib)
  4002. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4003. (diary-display-hook '(fancy-diary-display))
  4004. (diary-display-function 'fancy-diary-display)
  4005. (pop-up-frames nil)
  4006. (list-diary-entries-hook
  4007. (cons 'org-diary-default-entry list-diary-entries-hook))
  4008. (diary-file-name-prefix-function nil) ; turn this feature off
  4009. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4010. entries
  4011. (org-disable-agenda-to-diary t))
  4012. (save-excursion
  4013. (save-window-excursion
  4014. (funcall (if (fboundp 'diary-list-entries)
  4015. 'diary-list-entries 'list-diary-entries)
  4016. date 1)))
  4017. (if (not (get-buffer diary-fancy-buffer))
  4018. (setq entries nil)
  4019. (with-current-buffer diary-fancy-buffer
  4020. (setq buffer-read-only nil)
  4021. (if (zerop (buffer-size))
  4022. ;; No entries
  4023. (setq entries nil)
  4024. ;; Omit the date and other unnecessary stuff
  4025. (org-agenda-cleanup-fancy-diary)
  4026. ;; Add prefix to each line and extend the text properties
  4027. (if (zerop (buffer-size))
  4028. (setq entries nil)
  4029. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4030. (setq entries
  4031. (with-temp-buffer
  4032. (insert entries) (goto-char (point-min))
  4033. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4034. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4035. (replace-match (concat "; " (match-string 1)))))
  4036. (buffer-string)))))
  4037. (set-buffer-modified-p nil)
  4038. (kill-buffer diary-fancy-buffer)))
  4039. (when entries
  4040. (setq entries (org-split-string entries "\n"))
  4041. (setq entries
  4042. (mapcar
  4043. (lambda (x)
  4044. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4045. ;; Extend the text properties to the beginning of the line
  4046. (org-add-props x (text-properties-at (1- (length x)) x)
  4047. 'type "diary" 'date date 'face 'org-agenda-diary))
  4048. entries)))))
  4049. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4050. "Hook run when the fancy diary buffer is cleaned up.")
  4051. (defun org-agenda-cleanup-fancy-diary ()
  4052. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4053. This gets rid of the date, the underline under the date, and
  4054. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4055. date. It also removes lines that contain only whitespace."
  4056. (goto-char (point-min))
  4057. (if (looking-at ".*?:[ \t]*")
  4058. (progn
  4059. (replace-match "")
  4060. (re-search-forward "\n=+$" nil t)
  4061. (replace-match "")
  4062. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4063. (re-search-forward "\n=+$" nil t)
  4064. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4065. (goto-char (point-min))
  4066. (while (re-search-forward "^ +\n" nil t)
  4067. (replace-match ""))
  4068. (goto-char (point-min))
  4069. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4070. (replace-match ""))
  4071. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4072. ;; Make sure entries from the diary have the right text properties.
  4073. (eval-after-load "diary-lib"
  4074. '(if (boundp 'diary-modify-entry-list-string-function)
  4075. ;; We can rely on the hook, nothing to do
  4076. nil
  4077. ;; Hook not available, must use advice to make this work
  4078. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4079. "Make the position visible."
  4080. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4081. (stringp string)
  4082. buffer-file-name)
  4083. (setq string (org-modify-diary-entry-string string))))))
  4084. (defun org-modify-diary-entry-string (string)
  4085. "Add text properties to string, allowing org-mode to act on it."
  4086. (org-add-props string nil
  4087. 'mouse-face 'highlight
  4088. 'help-echo (if buffer-file-name
  4089. (format "mouse-2 or RET jump to diary file %s"
  4090. (abbreviate-file-name buffer-file-name))
  4091. "")
  4092. 'org-agenda-diary-link t
  4093. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4094. (defun org-diary-default-entry ()
  4095. "Add a dummy entry to the diary.
  4096. Needed to avoid empty dates which mess up holiday display."
  4097. ;; Catch the error if dealing with the new add-to-diary-alist
  4098. (when org-disable-agenda-to-diary
  4099. (condition-case nil
  4100. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4101. (error
  4102. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4103. (defun org-add-to-diary-list (&rest args)
  4104. (if (fboundp 'diary-add-to-list)
  4105. (apply 'diary-add-to-list args)
  4106. (apply 'add-to-diary-list args)))
  4107. (defvar org-diary-last-run-time nil)
  4108. ;;;###autoload
  4109. (defun org-diary (&rest args)
  4110. "Return diary information from org-files.
  4111. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4112. It accesses org files and extracts information from those files to be
  4113. listed in the diary. The function accepts arguments specifying what
  4114. items should be listed. For a list of arguments allowed here, see the
  4115. variable `org-agenda-entry-types'.
  4116. The call in the diary file should look like this:
  4117. &%%(org-diary) ~/path/to/some/orgfile.org
  4118. Use a separate line for each org file to check. Or, if you omit the file name,
  4119. all files listed in `org-agenda-files' will be checked automatically:
  4120. &%%(org-diary)
  4121. If you don't give any arguments (as in the example above), the default
  4122. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4123. So the example above may also be written as
  4124. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4125. The function expects the lisp variables `entry' and `date' to be provided
  4126. by the caller, because this is how the calendar works. Don't use this
  4127. function from a program - use `org-agenda-get-day-entries' instead."
  4128. (when (> (- (org-float-time)
  4129. org-agenda-last-marker-time)
  4130. 5)
  4131. (org-agenda-reset-markers))
  4132. (org-compile-prefix-format 'agenda)
  4133. (org-set-sorting-strategy 'agenda)
  4134. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4135. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4136. (list entry)
  4137. (org-agenda-files t)))
  4138. (time (org-float-time))
  4139. file rtn results)
  4140. (when (or (not org-diary-last-run-time)
  4141. (> (- time
  4142. org-diary-last-run-time)
  4143. 3))
  4144. (org-prepare-agenda-buffers files))
  4145. (setq org-diary-last-run-time time)
  4146. ;; If this is called during org-agenda, don't return any entries to
  4147. ;; the calendar. Org Agenda will list these entries itself.
  4148. (if org-disable-agenda-to-diary (setq files nil))
  4149. (while (setq file (pop files))
  4150. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4151. (setq results (append results rtn)))
  4152. (if results
  4153. (concat (org-finalize-agenda-entries results) "\n"))))
  4154. ;;; Agenda entry finders
  4155. (defun org-agenda-get-day-entries (file date &rest args)
  4156. "Does the work for `org-diary' and `org-agenda'.
  4157. FILE is the path to a file to be checked for entries. DATE is date like
  4158. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4159. which kind of entries should be extracted. For details about these, see
  4160. the documentation of `org-diary'."
  4161. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4162. (let* ((org-startup-folded nil)
  4163. (org-startup-align-all-tables nil)
  4164. (buffer (if (file-exists-p file)
  4165. (org-get-agenda-file-buffer file)
  4166. (error "No such file %s" file)))
  4167. arg results rtn deadline-results)
  4168. (if (not buffer)
  4169. ;; If file does not exist, make sure an error message ends up in diary
  4170. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4171. (with-current-buffer buffer
  4172. (unless (org-mode-p)
  4173. (error "Agenda file %s is not in `org-mode'" file))
  4174. (let ((case-fold-search nil))
  4175. (save-excursion
  4176. (save-restriction
  4177. (if org-agenda-restrict
  4178. (narrow-to-region org-agenda-restrict-begin
  4179. org-agenda-restrict-end)
  4180. (widen))
  4181. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4182. (while (setq arg (pop args))
  4183. (cond
  4184. ((and (eq arg :todo)
  4185. (equal date (calendar-gregorian-from-absolute
  4186. (org-today))))
  4187. (setq rtn (org-agenda-get-todos))
  4188. (setq results (append results rtn)))
  4189. ((eq arg :timestamp)
  4190. (setq rtn (org-agenda-get-blocks))
  4191. (setq results (append results rtn))
  4192. (setq rtn (org-agenda-get-timestamps))
  4193. (setq results (append results rtn)))
  4194. ((eq arg :sexp)
  4195. (setq rtn (org-agenda-get-sexps))
  4196. (setq results (append results rtn)))
  4197. ((eq arg :scheduled)
  4198. (setq rtn (org-agenda-get-scheduled deadline-results))
  4199. (setq results (append results rtn)))
  4200. ((eq arg :closed)
  4201. (setq rtn (org-agenda-get-progress))
  4202. (setq results (append results rtn)))
  4203. ((eq arg :deadline)
  4204. (setq rtn (org-agenda-get-deadlines))
  4205. (setq deadline-results (copy-sequence rtn))
  4206. (setq results (append results rtn))))))))
  4207. results))))
  4208. (defun org-agenda-get-todos ()
  4209. "Return the TODO information for agenda display."
  4210. (let* ((props (list 'face nil
  4211. 'done-face 'org-agenda-done
  4212. 'org-not-done-regexp org-not-done-regexp
  4213. 'org-todo-regexp org-todo-regexp
  4214. 'org-complex-heading-regexp org-complex-heading-regexp
  4215. 'mouse-face 'highlight
  4216. 'help-echo
  4217. (format "mouse-2 or RET jump to org file %s"
  4218. (abbreviate-file-name buffer-file-name))))
  4219. (regexp (concat "^\\*+[ \t]+\\("
  4220. (if org-select-this-todo-keyword
  4221. (if (equal org-select-this-todo-keyword "*")
  4222. org-todo-regexp
  4223. (concat "\\<\\("
  4224. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4225. "\\)\\>"))
  4226. org-not-done-regexp)
  4227. "[^\n\r]*\\)"))
  4228. marker priority category tags todo-state
  4229. ee txt beg end)
  4230. (goto-char (point-min))
  4231. (while (re-search-forward regexp nil t)
  4232. (catch :skip
  4233. (save-match-data
  4234. (beginning-of-line)
  4235. (org-agenda-skip)
  4236. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4237. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4238. (goto-char (1+ beg))
  4239. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4240. (throw :skip nil)))
  4241. (goto-char (match-beginning 1))
  4242. (setq marker (org-agenda-new-marker (match-beginning 0))
  4243. category (org-get-category)
  4244. txt (match-string 1)
  4245. tags (org-get-tags-at (point))
  4246. txt (org-format-agenda-item "" txt category tags)
  4247. priority (1+ (org-get-priority txt))
  4248. todo-state (org-get-todo-state))
  4249. (org-add-props txt props
  4250. 'org-marker marker 'org-hd-marker marker
  4251. 'priority priority 'org-category category
  4252. 'type "todo" 'todo-state todo-state)
  4253. (push txt ee)
  4254. (if org-agenda-todo-list-sublevels
  4255. (goto-char (match-end 1))
  4256. (org-end-of-subtree 'invisible))))
  4257. (nreverse ee)))
  4258. (defun org-agenda-todo-custom-ignore-p (time n)
  4259. "Check whether timestamp is farther away then n number of days.
  4260. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4261. `org-agenda-todo-ignore-scheduled' or
  4262. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4263. (let ((days (org-days-to-time time)))
  4264. (if (>= n 0)
  4265. (>= days n)
  4266. (<= days n))))
  4267. ;;;###autoload
  4268. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4269. (&optional end)
  4270. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4271. (when (or org-agenda-todo-ignore-with-date
  4272. org-agenda-todo-ignore-scheduled
  4273. org-agenda-todo-ignore-deadlines
  4274. org-agenda-todo-ignore-timestamp)
  4275. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4276. (save-excursion
  4277. (or (and org-agenda-todo-ignore-with-date
  4278. (re-search-forward org-ts-regexp end t))
  4279. (and org-agenda-todo-ignore-scheduled
  4280. (re-search-forward org-scheduled-time-regexp end t)
  4281. (cond
  4282. ((eq org-agenda-todo-ignore-scheduled 'future)
  4283. (> (org-days-to-time (match-string 1)) 0))
  4284. ((eq org-agenda-todo-ignore-scheduled 'past)
  4285. (<= (org-days-to-time (match-string 1)) 0))
  4286. ((numberp org-agenda-todo-ignore-scheduled)
  4287. (org-agenda-todo-custom-ignore-p
  4288. (match-string 1) org-agenda-todo-ignore-scheduled))
  4289. (t)))
  4290. (and org-agenda-todo-ignore-deadlines
  4291. (re-search-forward org-deadline-time-regexp end t)
  4292. (cond
  4293. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4294. ((eq org-agenda-todo-ignore-deadlines 'far)
  4295. (not (org-deadline-close (match-string 1))))
  4296. ((eq org-agenda-todo-ignore-deadlines 'future)
  4297. (> (org-days-to-time (match-string 1)) 0))
  4298. ((eq org-agenda-todo-ignore-deadlines 'past)
  4299. (<= (org-days-to-time (match-string 1)) 0))
  4300. ((numberp org-agenda-todo-ignore-deadlines)
  4301. (org-agenda-todo-custom-ignore-p
  4302. (match-string 1) org-agenda-todo-ignore-deadlines))
  4303. (t (org-deadline-close (match-string 1)))))
  4304. (and org-agenda-todo-ignore-timestamp
  4305. (let ((buffer (current-buffer))
  4306. (regexp
  4307. (concat
  4308. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4309. (start (point)))
  4310. ;; Copy current buffer into a temporary one
  4311. (with-temp-buffer
  4312. (insert-buffer-substring buffer start end)
  4313. (goto-char (point-min))
  4314. ;; Delete SCHEDULED and DEADLINE items
  4315. (while (re-search-forward regexp end t)
  4316. (delete-region (match-beginning 0) (match-end 0)))
  4317. (goto-char (point-min))
  4318. ;; No search for timestamp left
  4319. (when (re-search-forward org-ts-regexp nil t)
  4320. (cond
  4321. ((eq org-agenda-todo-ignore-timestamp 'future)
  4322. (> (org-days-to-time (match-string 1)) 0))
  4323. ((eq org-agenda-todo-ignore-timestamp 'past)
  4324. (<= (org-days-to-time (match-string 1)) 0))
  4325. ((numberp org-agenda-todo-ignore-timestamp)
  4326. (org-agenda-todo-custom-ignore-p
  4327. (match-string 1) org-agenda-todo-ignore-timestamp))
  4328. (t))))))))))
  4329. (defconst org-agenda-no-heading-message
  4330. "No heading for this item in buffer or region.")
  4331. (defun org-agenda-get-timestamps ()
  4332. "Return the date stamp information for agenda display."
  4333. (let* ((props (list 'face nil
  4334. 'org-not-done-regexp org-not-done-regexp
  4335. 'org-todo-regexp org-todo-regexp
  4336. 'org-complex-heading-regexp org-complex-heading-regexp
  4337. 'mouse-face 'highlight
  4338. 'help-echo
  4339. (format "mouse-2 or RET jump to org file %s"
  4340. (abbreviate-file-name buffer-file-name))))
  4341. (d1 (calendar-absolute-from-gregorian date))
  4342. (remove-re
  4343. (concat
  4344. (regexp-quote
  4345. (format-time-string
  4346. "<%Y-%m-%d"
  4347. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4348. ".*?>"))
  4349. (regexp
  4350. (concat
  4351. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4352. (regexp-quote
  4353. (substring
  4354. (format-time-string
  4355. (car org-time-stamp-formats)
  4356. (apply 'encode-time ; DATE bound by calendar
  4357. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4358. 1 11))
  4359. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4360. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4361. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4362. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4363. todo-state end-of-match show-all)
  4364. (goto-char (point-min))
  4365. (while (setq end-of-match (re-search-forward regexp nil t))
  4366. (setq b0 (match-beginning 0)
  4367. b3 (match-beginning 3) e3 (match-end 3)
  4368. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4369. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4370. (member todo-state
  4371. org-agenda-repeating-timestamp-show-all)))
  4372. (catch :skip
  4373. (and (org-at-date-range-p) (throw :skip nil))
  4374. (org-agenda-skip)
  4375. (if (and (match-end 1)
  4376. (not (= d1 (org-time-string-to-absolute
  4377. (match-string 1) d1 nil show-all))))
  4378. (throw :skip nil))
  4379. (if (and e3
  4380. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4381. (throw :skip nil))
  4382. (setq tmp (buffer-substring (max (point-min)
  4383. (- b0 org-ds-keyword-length))
  4384. b0)
  4385. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4386. inactivep (= (char-after b0) ?\[)
  4387. deadlinep (string-match org-deadline-regexp tmp)
  4388. scheduledp (string-match org-scheduled-regexp tmp)
  4389. closedp (and org-agenda-include-inactive-timestamps
  4390. (string-match org-closed-string tmp))
  4391. clockp (and org-agenda-include-inactive-timestamps
  4392. (or (string-match org-clock-string tmp)
  4393. (string-match "]-+\\'" tmp)))
  4394. donep (member todo-state org-done-keywords))
  4395. (if (or scheduledp deadlinep closedp clockp
  4396. (and donep org-agenda-skip-timestamp-if-done))
  4397. (throw :skip t))
  4398. (if (string-match ">" timestr)
  4399. ;; substring should only run to end of time stamp
  4400. (setq timestr (substring timestr 0 (match-end 0))))
  4401. (setq marker (org-agenda-new-marker b0)
  4402. category (org-get-category b0))
  4403. (save-excursion
  4404. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4405. (setq txt org-agenda-no-heading-message)
  4406. (goto-char (match-beginning 0))
  4407. (setq hdmarker (org-agenda-new-marker)
  4408. tags (org-get-tags-at))
  4409. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4410. (setq head (or (match-string 1) ""))
  4411. (setq txt (org-format-agenda-item
  4412. (if inactivep org-agenda-inactive-leader nil)
  4413. head category tags timestr
  4414. remove-re)))
  4415. (setq priority (org-get-priority txt))
  4416. (org-add-props txt props
  4417. 'org-marker marker 'org-hd-marker hdmarker)
  4418. (org-add-props txt nil 'priority priority
  4419. 'org-category category 'date date
  4420. 'todo-state todo-state
  4421. 'type "timestamp")
  4422. (push txt ee))
  4423. (if org-agenda-skip-additional-timestamps-same-entry
  4424. (outline-next-heading)
  4425. (goto-char end-of-match))))
  4426. (nreverse ee)))
  4427. (defun org-agenda-get-sexps ()
  4428. "Return the sexp information for agenda display."
  4429. (require 'diary-lib)
  4430. (let* ((props (list 'mouse-face 'highlight
  4431. 'help-echo
  4432. (format "mouse-2 or RET jump to org file %s"
  4433. (abbreviate-file-name buffer-file-name))))
  4434. (regexp "^&?%%(")
  4435. marker category ee txt tags entry result beg b sexp sexp-entry
  4436. todo-state)
  4437. (goto-char (point-min))
  4438. (while (re-search-forward regexp nil t)
  4439. (catch :skip
  4440. (org-agenda-skip)
  4441. (setq beg (match-beginning 0))
  4442. (goto-char (1- (match-end 0)))
  4443. (setq b (point))
  4444. (forward-sexp 1)
  4445. (setq sexp (buffer-substring b (point)))
  4446. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4447. (org-trim (match-string 1))
  4448. ""))
  4449. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4450. (when result
  4451. (setq marker (org-agenda-new-marker beg)
  4452. category (org-get-category beg)
  4453. todo-state (org-get-todo-state))
  4454. (dolist (r (if (stringp result)
  4455. (list result)
  4456. result)) ;; we expect a list here
  4457. (if (string-match "\\S-" r)
  4458. (setq txt r)
  4459. (setq txt "SEXP entry returned empty string"))
  4460. (setq txt (org-format-agenda-item
  4461. "" txt category tags 'time))
  4462. (org-add-props txt props 'org-marker marker)
  4463. (org-add-props txt nil
  4464. 'org-category category 'date date 'todo-state todo-state
  4465. 'type "sexp")
  4466. (push txt ee)))))
  4467. (nreverse ee)))
  4468. ;; Calendar sanity: define some functions that are independent of
  4469. ;; `calendar-date-style'.
  4470. ;; Normally I would like to use ISO format when calling the diary functions,
  4471. ;; but to make sure we still have Emacs 22 compatibility we bind
  4472. ;; also `european-calendar-style' and use european format
  4473. (defun org-anniversary (year month day &optional mark)
  4474. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4475. (org-no-warnings
  4476. (let ((calendar-date-style 'european) (european-calendar-style t))
  4477. (diary-anniversary day month year mark))))
  4478. (defun org-cyclic (N year month day &optional mark)
  4479. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4480. (org-no-warnings
  4481. (let ((calendar-date-style 'european) (european-calendar-style t))
  4482. (diary-cyclic N day month year mark))))
  4483. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4484. "Like `diary-block', but with fixed (ISO) order of arguments."
  4485. (org-no-warnings
  4486. (let ((calendar-date-style 'european) (european-calendar-style t))
  4487. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4488. (defun org-date (year month day &optional mark)
  4489. "Like `diary-date', but with fixed (ISO) order of arguments."
  4490. (org-no-warnings
  4491. (let ((calendar-date-style 'european) (european-calendar-style t))
  4492. (diary-date day month year mark))))
  4493. (defalias 'org-float 'diary-float)
  4494. ;; Define the` org-class' function
  4495. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4496. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4497. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4498. is any number of ISO weeks in the block period for which the item should
  4499. be skipped."
  4500. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4501. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4502. (d (calendar-absolute-from-gregorian date)))
  4503. (and
  4504. (<= date1 d)
  4505. (<= d date2)
  4506. (= (calendar-day-of-week date) dayname)
  4507. (or (not skip-weeks)
  4508. (progn
  4509. (require 'cal-iso)
  4510. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4511. entry)))
  4512. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4513. "Like `org-class', but honor `calendar-date-style'.
  4514. The order of the first 2 times 3 arguments depends on the variable
  4515. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4516. So for American calendars, give this as MONTH DAY YEAR, for European as
  4517. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4518. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4519. is any number of ISO weeks in the block period for which the item should
  4520. be skipped.
  4521. This function is here only for backward compatibility and it is deprecated,
  4522. please use `org-class' instead."
  4523. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4524. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4525. (org-class
  4526. (nth 2 date1) (car date1) (nth 1 date1)
  4527. (nth 2 date2) (car date2) (nth 1 date2)
  4528. dayname skip-weeks)))
  4529. (defalias 'org-get-closed 'org-agenda-get-progress)
  4530. (defun org-agenda-get-progress ()
  4531. "Return the logged TODO entries for agenda display."
  4532. (let* ((props (list 'mouse-face 'highlight
  4533. 'org-not-done-regexp org-not-done-regexp
  4534. 'org-todo-regexp org-todo-regexp
  4535. 'org-complex-heading-regexp org-complex-heading-regexp
  4536. 'help-echo
  4537. (format "mouse-2 or RET jump to org file %s"
  4538. (abbreviate-file-name buffer-file-name))))
  4539. (items (if (consp org-agenda-show-log)
  4540. org-agenda-show-log
  4541. (if (eq org-agenda-show-log 'clockcheck)
  4542. '(clock)
  4543. org-agenda-log-mode-items)))
  4544. (parts
  4545. (delq nil
  4546. (list
  4547. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4548. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4549. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4550. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4551. (error "`org-agenda-log-mode-items' is empty")))
  4552. (regexp (concat
  4553. "\\(" parts-re "\\)"
  4554. " *\\["
  4555. (regexp-quote
  4556. (substring
  4557. (format-time-string
  4558. (car org-time-stamp-formats)
  4559. (apply 'encode-time ; DATE bound by calendar
  4560. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4561. 1 11))))
  4562. (org-agenda-search-headline-for-time nil)
  4563. marker hdmarker priority category tags closedp statep clockp state
  4564. ee txt extra timestr rest clocked)
  4565. (goto-char (point-min))
  4566. (while (re-search-forward regexp nil t)
  4567. (catch :skip
  4568. (org-agenda-skip)
  4569. (setq marker (org-agenda-new-marker (match-beginning 0))
  4570. closedp (equal (match-string 1) org-closed-string)
  4571. statep (equal (string-to-char (match-string 1)) ?-)
  4572. clockp (not (or closedp statep))
  4573. state (and statep (match-string 2))
  4574. category (org-get-category (match-beginning 0))
  4575. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4576. )
  4577. (when (string-match "\\]" timestr)
  4578. ;; substring should only run to end of time stamp
  4579. (setq rest (substring timestr (match-end 0))
  4580. timestr (substring timestr 0 (match-end 0)))
  4581. (if (and (not closedp) (not statep)
  4582. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4583. (progn (setq timestr (concat (substring timestr 0 -1)
  4584. "-" (match-string 1 rest) "]"))
  4585. (setq clocked (match-string 2 rest)))
  4586. (setq clocked "-")))
  4587. (save-excursion
  4588. (setq extra
  4589. (cond
  4590. ((not org-agenda-log-mode-add-notes) nil)
  4591. (statep
  4592. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4593. (match-string 1)))
  4594. (clockp
  4595. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4596. (match-string 1)))))
  4597. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4598. (setq txt org-agenda-no-heading-message)
  4599. (goto-char (match-beginning 0))
  4600. (setq hdmarker (org-agenda-new-marker)
  4601. tags (org-get-tags-at))
  4602. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4603. (setq txt (match-string 1))
  4604. (when extra
  4605. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4606. (setq txt (concat (substring txt 0 (match-beginning 1))
  4607. " - " extra " " (match-string 2 txt)))
  4608. (setq txt (concat txt " - " extra))))
  4609. (setq txt (org-format-agenda-item
  4610. (cond
  4611. (closedp "Closed: ")
  4612. (statep (concat "State: (" state ")"))
  4613. (t (concat "Clocked: (" clocked ")")))
  4614. txt category tags timestr)))
  4615. (setq priority 100000)
  4616. (org-add-props txt props
  4617. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4618. 'priority priority 'org-category category
  4619. 'type "closed" 'date date
  4620. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4621. (push txt ee))
  4622. (goto-char (point-at-eol))))
  4623. (nreverse ee)))
  4624. (defun org-agenda-show-clocking-issues ()
  4625. "Add overlays, showing issues with clocking.
  4626. See also the user option `org-agenda-clock-consistency-checks'."
  4627. (interactive)
  4628. (let* ((pl org-agenda-clock-consistency-checks)
  4629. (re (concat "^[ \t]*"
  4630. org-clock-string
  4631. "[ \t]+"
  4632. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4633. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4634. (tlstart 0.)
  4635. (tlend 0.)
  4636. (maxtime (org-hh:mm-string-to-minutes
  4637. (or (plist-get pl :max-duration) "24:00")))
  4638. (mintime (org-hh:mm-string-to-minutes
  4639. (or (plist-get pl :min-duration) 0)))
  4640. (maxgap (org-hh:mm-string-to-minutes
  4641. ;; default 30:00 means never complain
  4642. (or (plist-get pl :max-gap) "30:00")))
  4643. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4644. (plist-get pl :gap-ok-around)))
  4645. (def-face (or (plist-get pl :default-face)
  4646. '((:background "DarkRed") (:foreground "white"))))
  4647. issue face m te ts dt ov)
  4648. (goto-char (point-min))
  4649. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4650. (setq issue nil face def-face)
  4651. (catch 'next
  4652. (setq m (org-get-at-bol 'org-marker)
  4653. te nil ts nil)
  4654. (unless (and m (markerp m))
  4655. (setq issue "No valid clock line") (throw 'next t))
  4656. (org-with-point-at m
  4657. (save-excursion
  4658. (goto-char (point-at-bol))
  4659. (unless (looking-at re)
  4660. (error "No valid Clock line")
  4661. (throw 'next t))
  4662. (unless (match-end 3)
  4663. (setq issue "No end time"
  4664. face (or (plist-get pl :no-end-time-face) face))
  4665. (throw 'next t))
  4666. (setq ts (match-string 1)
  4667. te (match-string 3)
  4668. ts (org-float-time
  4669. (apply 'encode-time (org-parse-time-string ts)))
  4670. te (org-float-time
  4671. (apply 'encode-time (org-parse-time-string te)))
  4672. dt (- te ts))))
  4673. (cond
  4674. ((> dt (* 60 maxtime))
  4675. ;; a very long clocking chunk
  4676. (setq issue (format "Clocking interval is very long: %s"
  4677. (org-minutes-to-hh:mm-string
  4678. (floor (/ (float dt) 60.))))
  4679. face (or (plist-get pl :long-face) face)))
  4680. ((< dt (* 60 mintime))
  4681. ;; a very short clocking chunk
  4682. (setq issue (format "Clocking interval is very short: %s"
  4683. (org-minutes-to-hh:mm-string
  4684. (floor (/ (float dt) 60.))))
  4685. face (or (plist-get pl :short-face) face)))
  4686. ((and (> tlend 0) (< ts tlend))
  4687. ;; Two clock entries are overlapping
  4688. (setq issue (format "Clocking overlap: %d minutes"
  4689. (/ (- tlend ts) 60))
  4690. face (or (plist-get pl :overlap-face) face)))
  4691. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4692. ;; There is a gap, lets see if we need to report it
  4693. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4694. (setq issue (format "Clocking gap: %d minutes"
  4695. (/ (- ts tlend) 60))
  4696. face (or (plist-get pl :gap-face) face))))
  4697. (t nil)))
  4698. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4699. (when issue
  4700. ;; OK, there was some issue, add an overlay to show the issue
  4701. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4702. (overlay-put ov 'before-string
  4703. (concat
  4704. (org-add-props
  4705. (format "%-43s" (concat " " issue))
  4706. nil
  4707. 'face face)
  4708. "\n"))
  4709. (overlay-put ov 'evaporate t)))))
  4710. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4711. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4712. (catch 'exit
  4713. (unless ok-list
  4714. ;; there are no OK times for gaps...
  4715. (throw 'exit nil))
  4716. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4717. ;; This is more than 24 hours, so it is OK.
  4718. ;; because we have at least one OK time, that must be in the
  4719. ;; 24 hour interval.
  4720. (throw 'exit t))
  4721. ;; We have a shorter gap.
  4722. ;; Now we have to get the minute of the day when these times are
  4723. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4724. (t2dec (decode-time (seconds-to-time t2)))
  4725. ;; compute the minute on the day
  4726. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4727. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4728. (when (< min2 min1)
  4729. ;; if min2 is smaller than min1, this means it is on the next day.
  4730. ;; Wrap it to after midnight.
  4731. (setq min2 (+ min2 1440)))
  4732. ;; Now check if any of the OK times is in the gap
  4733. (mapc (lambda (x)
  4734. ;; Wrap the time to after midnight if necessary
  4735. (if (< x min1) (setq x (+ x 1440)))
  4736. ;; Check if in interval
  4737. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4738. ok-list)
  4739. ;; Nope, this gap is not OK
  4740. nil)))
  4741. (defun org-agenda-get-deadlines ()
  4742. "Return the deadline information for agenda display."
  4743. (let* ((props (list 'mouse-face 'highlight
  4744. 'org-not-done-regexp org-not-done-regexp
  4745. 'org-todo-regexp org-todo-regexp
  4746. 'org-complex-heading-regexp org-complex-heading-regexp
  4747. 'help-echo
  4748. (format "mouse-2 or RET jump to org file %s"
  4749. (abbreviate-file-name buffer-file-name))))
  4750. (regexp org-deadline-time-regexp)
  4751. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4752. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4753. d2 diff dfrac wdays pos pos1 category tags
  4754. suppress-prewarning
  4755. ee txt head face s todo-state show-all upcomingp donep timestr)
  4756. (goto-char (point-min))
  4757. (while (re-search-forward regexp nil t)
  4758. (setq suppress-prewarning nil)
  4759. (catch :skip
  4760. (org-agenda-skip)
  4761. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4762. (save-match-data
  4763. (string-match org-scheduled-time-regexp
  4764. (buffer-substring (point-at-bol)
  4765. (point-at-eol)))))
  4766. (setq suppress-prewarning
  4767. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4768. org-agenda-skip-deadline-prewarning-if-scheduled
  4769. 0)))
  4770. (setq s (match-string 1)
  4771. txt nil
  4772. pos (1- (match-beginning 1))
  4773. todo-state (save-match-data (org-get-todo-state))
  4774. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4775. (member todo-state
  4776. org-agenda-repeating-timestamp-show-all))
  4777. d2 (org-time-string-to-absolute
  4778. (match-string 1) d1 'past show-all)
  4779. diff (- d2 d1)
  4780. wdays (if suppress-prewarning
  4781. (let ((org-deadline-warning-days suppress-prewarning))
  4782. (org-get-wdays s))
  4783. (org-get-wdays s))
  4784. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4785. upcomingp (and todayp (> diff 0)))
  4786. ;; When to show a deadline in the calendar:
  4787. ;; If the expiration is within wdays warning time.
  4788. ;; Past-due deadlines are only shown on the current date
  4789. (if (and (or (and (<= diff wdays)
  4790. (and todayp (not org-agenda-only-exact-dates)))
  4791. (= diff 0)))
  4792. (save-excursion
  4793. ;; (setq todo-state (org-get-todo-state))
  4794. (setq donep (member todo-state org-done-keywords))
  4795. (if (and donep
  4796. (or org-agenda-skip-deadline-if-done
  4797. (not (= diff 0))))
  4798. (setq txt nil)
  4799. (setq category (org-get-category))
  4800. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4801. (setq txt org-agenda-no-heading-message)
  4802. (goto-char (match-end 0))
  4803. (setq pos1 (match-beginning 0))
  4804. (setq tags (org-get-tags-at pos1))
  4805. (setq head (buffer-substring-no-properties
  4806. (point)
  4807. (progn (skip-chars-forward "^\r\n")
  4808. (point))))
  4809. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4810. (setq timestr
  4811. (concat (substring s (match-beginning 1)) " "))
  4812. (setq timestr 'time))
  4813. (setq txt (org-format-agenda-item
  4814. (if (= diff 0)
  4815. (car org-agenda-deadline-leaders)
  4816. (if (functionp
  4817. (nth 1 org-agenda-deadline-leaders))
  4818. (funcall
  4819. (nth 1 org-agenda-deadline-leaders)
  4820. diff date)
  4821. (format (nth 1 org-agenda-deadline-leaders)
  4822. diff)))
  4823. head category tags
  4824. (if (not (= diff 0)) nil timestr)))))
  4825. (when txt
  4826. (setq face (org-agenda-deadline-face dfrac))
  4827. (org-add-props txt props
  4828. 'org-marker (org-agenda-new-marker pos)
  4829. 'org-hd-marker (org-agenda-new-marker pos1)
  4830. 'priority (+ (- diff)
  4831. (org-get-priority txt))
  4832. 'org-category category
  4833. 'todo-state todo-state
  4834. 'type (if upcomingp "upcoming-deadline" "deadline")
  4835. 'date (if upcomingp date d2)
  4836. 'face (if donep 'org-agenda-done face)
  4837. 'undone-face face 'done-face 'org-agenda-done)
  4838. (push txt ee))))))
  4839. (nreverse ee)))
  4840. (defun org-agenda-deadline-face (fraction)
  4841. "Return the face to displaying a deadline item.
  4842. FRACTION is what fraction of the head-warning time has passed."
  4843. (let ((faces org-agenda-deadline-faces) f)
  4844. (catch 'exit
  4845. (while (setq f (pop faces))
  4846. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4847. (defun org-agenda-get-scheduled (&optional deadline-results)
  4848. "Return the scheduled information for agenda display."
  4849. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4850. 'org-todo-regexp org-todo-regexp
  4851. 'org-complex-heading-regexp org-complex-heading-regexp
  4852. 'done-face 'org-agenda-done
  4853. 'mouse-face 'highlight
  4854. 'help-echo
  4855. (format "mouse-2 or RET jump to org file %s"
  4856. (abbreviate-file-name buffer-file-name))))
  4857. (regexp org-scheduled-time-regexp)
  4858. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4859. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4860. mm
  4861. (deadline-position-alist
  4862. (mapcar (lambda (a) (and (setq mm (get-text-property
  4863. 0 'org-hd-marker a))
  4864. (cons (marker-position mm) a)))
  4865. deadline-results))
  4866. d2 diff pos pos1 category tags donep
  4867. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4868. (goto-char (point-min))
  4869. (while (re-search-forward regexp nil t)
  4870. (catch :skip
  4871. (org-agenda-skip)
  4872. (setq s (match-string 1)
  4873. txt nil
  4874. pos (1- (match-beginning 1))
  4875. todo-state (save-match-data (org-get-todo-state))
  4876. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4877. (member todo-state
  4878. org-agenda-repeating-timestamp-show-all))
  4879. d2 (org-time-string-to-absolute
  4880. (match-string 1) d1 'past show-all)
  4881. diff (- d2 d1))
  4882. (setq pastschedp (and todayp (< diff 0)))
  4883. ;; When to show a scheduled item in the calendar:
  4884. ;; If it is on or past the date.
  4885. (when (or (and (< diff 0)
  4886. (< (abs diff) org-scheduled-past-days)
  4887. (and todayp (not org-agenda-only-exact-dates)))
  4888. (= diff 0))
  4889. (save-excursion
  4890. (setq donep (member todo-state org-done-keywords))
  4891. (if (and donep
  4892. (or org-agenda-skip-scheduled-if-done
  4893. (not (= diff 0))
  4894. (and (functionp 'org-is-habit-p)
  4895. (org-is-habit-p))))
  4896. (setq txt nil)
  4897. (setq habitp (and (functionp 'org-is-habit-p)
  4898. (org-is-habit-p)))
  4899. (setq category (org-get-category))
  4900. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4901. (setq txt org-agenda-no-heading-message)
  4902. (goto-char (match-end 0))
  4903. (setq pos1 (match-beginning 0))
  4904. (if habitp
  4905. (if (or (not org-habit-show-habits)
  4906. (and (not todayp)
  4907. org-habit-show-habits-only-for-today))
  4908. (throw :skip nil))
  4909. (if (and
  4910. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4911. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4912. pastschedp))
  4913. (setq mm (assoc pos1 deadline-position-alist)))
  4914. (throw :skip nil)))
  4915. (setq tags (org-get-tags-at))
  4916. (setq head (buffer-substring-no-properties
  4917. (point)
  4918. (progn (skip-chars-forward "^\r\n") (point))))
  4919. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4920. (setq timestr
  4921. (concat (substring s (match-beginning 1)) " "))
  4922. (setq timestr 'time))
  4923. (setq txt (org-format-agenda-item
  4924. (if (= diff 0)
  4925. (car org-agenda-scheduled-leaders)
  4926. (format (nth 1 org-agenda-scheduled-leaders)
  4927. (- 1 diff)))
  4928. head category tags
  4929. (if (not (= diff 0)) nil timestr)
  4930. nil habitp))))
  4931. (when txt
  4932. (setq face
  4933. (cond
  4934. ((and (not habitp) pastschedp)
  4935. 'org-scheduled-previously)
  4936. (todayp 'org-scheduled-today)
  4937. (t 'org-scheduled))
  4938. habitp (and habitp (org-habit-parse-todo)))
  4939. (org-add-props txt props
  4940. 'undone-face face
  4941. 'face (if donep 'org-agenda-done face)
  4942. 'org-marker (org-agenda-new-marker pos)
  4943. 'org-hd-marker (org-agenda-new-marker pos1)
  4944. 'type (if pastschedp "past-scheduled" "scheduled")
  4945. 'date (if pastschedp d2 date)
  4946. 'priority (if habitp
  4947. (org-habit-get-priority habitp)
  4948. (+ 94 (- 5 diff) (org-get-priority txt)))
  4949. 'org-category category
  4950. 'org-habit-p habitp
  4951. 'todo-state todo-state)
  4952. (push txt ee))))))
  4953. (nreverse ee)))
  4954. (defun org-agenda-get-blocks ()
  4955. "Return the date-range information for agenda display."
  4956. (let* ((props (list 'face nil
  4957. 'org-not-done-regexp org-not-done-regexp
  4958. 'org-todo-regexp org-todo-regexp
  4959. 'org-complex-heading-regexp org-complex-heading-regexp
  4960. 'mouse-face 'highlight
  4961. 'help-echo
  4962. (format "mouse-2 or RET jump to org file %s"
  4963. (abbreviate-file-name buffer-file-name))))
  4964. (regexp org-tr-regexp)
  4965. (d0 (calendar-absolute-from-gregorian date))
  4966. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4967. head donep)
  4968. (goto-char (point-min))
  4969. (while (re-search-forward regexp nil t)
  4970. (catch :skip
  4971. (org-agenda-skip)
  4972. (setq pos (point))
  4973. (let ((start-time (match-string 1))
  4974. (end-time (match-string 2)))
  4975. (setq s1 (match-string 1)
  4976. s2 (match-string 2)
  4977. d1 (time-to-days (org-time-string-to-time s1))
  4978. d2 (time-to-days (org-time-string-to-time s2)))
  4979. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4980. ;; Only allow days between the limits, because the normal
  4981. ;; date stamps will catch the limits.
  4982. (save-excursion
  4983. (setq todo-state (org-get-todo-state))
  4984. (setq donep (member todo-state org-done-keywords))
  4985. (if (and donep org-agenda-skip-timestamp-if-done)
  4986. (throw :skip t))
  4987. (setq marker (org-agenda-new-marker (point)))
  4988. (setq category (org-get-category))
  4989. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4990. (setq txt org-agenda-no-heading-message)
  4991. (goto-char (match-beginning 0))
  4992. (setq hdmarker (org-agenda-new-marker (point)))
  4993. (setq tags (org-get-tags-at))
  4994. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4995. (setq head (match-string 1))
  4996. (let ((remove-re
  4997. (if org-agenda-remove-timeranges-from-blocks
  4998. (concat
  4999. "<" (regexp-quote s1) ".*?>"
  5000. "--"
  5001. "<" (regexp-quote s2) ".*?>")
  5002. nil)))
  5003. (setq txt (org-format-agenda-item
  5004. (format
  5005. (nth (if (= d1 d2) 0 1)
  5006. org-agenda-timerange-leaders)
  5007. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5008. head category tags
  5009. (cond ((= d1 d0)
  5010. (concat "<" start-time ">"))
  5011. ((= d2 d0)
  5012. (concat "<" end-time ">"))
  5013. (t nil))
  5014. remove-re))))
  5015. (org-add-props txt props
  5016. 'org-marker marker 'org-hd-marker hdmarker
  5017. 'type "block" 'date date
  5018. 'todo-state todo-state
  5019. 'priority (org-get-priority txt) 'org-category category)
  5020. (push txt ee))))
  5021. (goto-char pos)))
  5022. ;; Sort the entries by expiration date.
  5023. (nreverse ee)))
  5024. ;;; Agenda presentation and sorting
  5025. (defvar org-prefix-has-time nil
  5026. "A flag, set by `org-compile-prefix-format'.
  5027. The flag is set if the currently compiled format contains a `%t'.")
  5028. (defvar org-prefix-has-tag nil
  5029. "A flag, set by `org-compile-prefix-format'.
  5030. The flag is set if the currently compiled format contains a `%T'.")
  5031. (defvar org-prefix-has-effort nil
  5032. "A flag, set by `org-compile-prefix-format'.
  5033. The flag is set if the currently compiled format contains a `%e'.")
  5034. (defvar org-prefix-category-length nil
  5035. "Used by `org-compile-prefix-format' to remember the category field width.")
  5036. (defvar org-prefix-category-max-length nil
  5037. "Used by `org-compile-prefix-format' to remember the category field width.")
  5038. (defun org-agenda-get-category-icon (category)
  5039. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5040. (dolist (entry org-agenda-category-icon-alist)
  5041. (when (org-string-match-p (car entry) category)
  5042. (if (listp (cadr entry))
  5043. (return (cadr entry))
  5044. (return (apply 'create-image (cdr entry)))))))
  5045. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5046. remove-re habitp)
  5047. "Format TXT to be inserted into the agenda buffer.
  5048. In particular, it adds the prefix and corresponding text properties. EXTRA
  5049. must be a string and replaces the `%s' specifier in the prefix format.
  5050. CATEGORY (string, symbol or nil) may be used to overrule the default
  5051. category taken from local variable or file name. It will replace the `%c'
  5052. specifier in the format. DOTIME, when non-nil, indicates that a
  5053. time-of-day should be extracted from TXT for sorting of this entry, and for
  5054. the `%t' specifier in the format. When DOTIME is a string, this string is
  5055. searched for a time before TXT is. TAGS can be the tags of the headline.
  5056. Any match of REMOVE-RE will be removed from TXT."
  5057. (save-match-data
  5058. ;; Diary entries sometimes have extra whitespace at the beginning
  5059. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5060. ;; Fix the tags part in txt
  5061. (setq txt (org-agenda-fix-displayed-tags
  5062. txt tags
  5063. org-agenda-show-inherited-tags
  5064. org-agenda-hide-tags-regexp))
  5065. (let* ((category (or category
  5066. (if (stringp org-category)
  5067. org-category
  5068. (and org-category (symbol-name org-category)))
  5069. (if buffer-file-name
  5070. (file-name-sans-extension
  5071. (file-name-nondirectory buffer-file-name))
  5072. "")))
  5073. (category-icon (org-agenda-get-category-icon category))
  5074. (category-icon (if category-icon
  5075. (propertize " " 'display category-icon)
  5076. ""))
  5077. ;; time, tag, effort are needed for the eval of the prefix format
  5078. (tag (if tags (nth (1- (length tags)) tags) ""))
  5079. time effort neffort
  5080. (ts (if dotime (concat
  5081. (if (stringp dotime) dotime "")
  5082. (and org-agenda-search-headline-for-time txt))))
  5083. (time-of-day (and dotime (org-get-time-of-day ts)))
  5084. stamp plain s0 s1 s2 rtn srp l
  5085. duration thecategory)
  5086. (and (org-mode-p) buffer-file-name
  5087. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5088. (when (and dotime time-of-day)
  5089. ;; Extract starting and ending time and move them to prefix
  5090. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5091. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5092. (setq s0 (match-string 0 ts)
  5093. srp (and stamp (match-end 3))
  5094. s1 (match-string (if plain 1 2) ts)
  5095. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5096. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5097. ;; them, we might want to remove them there to avoid duplication.
  5098. ;; The user can turn this off with a variable.
  5099. (if (and org-prefix-has-time
  5100. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5101. (string-match (concat (regexp-quote s0) " *") txt)
  5102. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5103. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5104. (= (match-beginning 0) 0)
  5105. t))
  5106. (setq txt (replace-match "" nil nil txt))))
  5107. ;; Normalize the time(s) to 24 hour
  5108. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5109. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5110. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5111. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5112. (setq s2
  5113. (org-minutes-to-hh:mm-string
  5114. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5115. ;; Compute the duration
  5116. (when s2
  5117. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5118. (org-hh:mm-string-to-minutes s1)))))
  5119. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5120. txt)
  5121. ;; Tags are in the string
  5122. (if (or (eq org-agenda-remove-tags t)
  5123. (and org-agenda-remove-tags
  5124. org-prefix-has-tag))
  5125. (setq txt (replace-match "" t t txt))
  5126. (setq txt (replace-match
  5127. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5128. (match-string 2 txt))
  5129. t t txt))))
  5130. (when (org-mode-p)
  5131. (setq effort
  5132. (condition-case nil
  5133. (org-get-effort
  5134. (or (get-text-property 0 'org-hd-marker txt)
  5135. (get-text-property 0 'org-marker txt)))
  5136. (error nil)))
  5137. (when effort
  5138. (setq neffort (org-duration-string-to-minutes effort)
  5139. effort (setq effort (concat "[" effort "]")))))
  5140. ;; prevent erroring out with %e format when there is no effort
  5141. (or effort (setq effort ""))
  5142. (when remove-re
  5143. (while (string-match remove-re txt)
  5144. (setq txt (replace-match "" t t txt))))
  5145. ;; Set org-heading property on `txt' to mark the start of the
  5146. ;; heading.
  5147. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5148. ;; Prepare the variables needed in the eval of the compiled format
  5149. (setq time (cond (s2 (concat
  5150. (org-agenda-time-of-day-to-ampm-maybe s1)
  5151. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5152. (if org-agenda-timegrid-use-ampm " ")))
  5153. (s1 (concat
  5154. (org-agenda-time-of-day-to-ampm-maybe s1)
  5155. (if org-agenda-timegrid-use-ampm
  5156. "........ "
  5157. "......")))
  5158. (t ""))
  5159. extra (or (and (not habitp) extra) "")
  5160. category (if (symbolp category) (symbol-name category) category)
  5161. thecategory (copy-sequence category))
  5162. (if (string-match org-bracket-link-regexp category)
  5163. (progn
  5164. (setq l (if (match-end 3)
  5165. (- (match-end 3) (match-beginning 3))
  5166. (- (match-end 1) (match-beginning 1))))
  5167. (when (< l (or org-prefix-category-length 0))
  5168. (setq category (copy-sequence category))
  5169. (org-add-props category nil
  5170. 'extra-space (make-string
  5171. (- org-prefix-category-length l 1) ?\ ))))
  5172. (if (and org-prefix-category-max-length
  5173. (>= (length category) org-prefix-category-max-length))
  5174. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5175. ;; Evaluate the compiled format
  5176. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5177. ;; And finally add the text properties
  5178. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5179. (org-add-props rtn nil
  5180. 'org-category (if thecategory (downcase thecategory) category)
  5181. 'tags (mapcar 'org-downcase-keep-props tags)
  5182. 'org-highest-priority org-highest-priority
  5183. 'org-lowest-priority org-lowest-priority
  5184. 'time-of-day time-of-day
  5185. 'duration duration
  5186. 'effort effort
  5187. 'effort-minutes neffort
  5188. 'txt txt
  5189. 'time time
  5190. 'extra extra
  5191. 'format org-prefix-format-compiled
  5192. 'dotime dotime))))
  5193. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5194. "Remove tags string from TXT, and add a modified list of tags.
  5195. The modified list may contain inherited tags, and tags matched by
  5196. `org-agenda-hide-tags-regexp' will be removed."
  5197. (when (or add-inherited hide-re)
  5198. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5199. (setq txt (substring txt 0 (match-beginning 0))))
  5200. (setq tags
  5201. (delq nil
  5202. (mapcar (lambda (tg)
  5203. (if (or (and hide-re (string-match hide-re tg))
  5204. (and (not add-inherited)
  5205. (get-text-property 0 'inherited tg)))
  5206. nil
  5207. tg))
  5208. tags)))
  5209. (when tags
  5210. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5211. i)
  5212. (setq txt (concat txt " :"
  5213. (mapconcat
  5214. (lambda (x)
  5215. (setq i (get-text-property 0 'inherited x))
  5216. (if (and have-i (not i))
  5217. (progn
  5218. (setq have-i nil)
  5219. (concat ":" x))
  5220. x))
  5221. tags ":")
  5222. (if have-i "::" ":"))))))
  5223. txt)
  5224. (defun org-downcase-keep-props (s)
  5225. (let ((props (text-properties-at 0 s)))
  5226. (setq s (downcase s))
  5227. (add-text-properties 0 (length s) props s)
  5228. s))
  5229. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5230. (defvar org-agenda-sorting-strategy-selected nil)
  5231. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5232. (catch 'exit
  5233. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5234. ((and todayp (member 'today (car org-agenda-time-grid))))
  5235. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5236. ((member 'weekly (car org-agenda-time-grid)))
  5237. (t (throw 'exit list)))
  5238. (let* ((have (delq nil (mapcar
  5239. (lambda (x) (get-text-property 1 'time-of-day x))
  5240. list)))
  5241. (string (nth 1 org-agenda-time-grid))
  5242. (gridtimes (nth 2 org-agenda-time-grid))
  5243. (req (car org-agenda-time-grid))
  5244. (remove (member 'remove-match req))
  5245. new time)
  5246. (if (and (member 'require-timed req) (not have))
  5247. ;; don't show empty grid
  5248. (throw 'exit list))
  5249. (while (setq time (pop gridtimes))
  5250. (unless (and remove (member time have))
  5251. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5252. (push (org-format-agenda-item
  5253. nil string "" nil
  5254. (concat (substring time 0 -2) ":" (substring time -2)))
  5255. new)
  5256. (put-text-property
  5257. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5258. (when (and todayp org-agenda-show-current-time-in-grid)
  5259. (push (org-format-agenda-item
  5260. nil
  5261. org-agenda-current-time-string
  5262. "" nil
  5263. (format-time-string "%H:%M "))
  5264. new)
  5265. (put-text-property
  5266. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5267. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5268. (append new list)
  5269. (append list new)))))
  5270. (defun org-compile-prefix-format (key)
  5271. "Compile the prefix format into a Lisp form that can be evaluated.
  5272. The resulting form is returned and stored in the variable
  5273. `org-prefix-format-compiled'."
  5274. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5275. org-prefix-category-length nil org-prefix-has-effort nil)
  5276. (let ((s (cond
  5277. ((stringp org-agenda-prefix-format)
  5278. org-agenda-prefix-format)
  5279. ((assq key org-agenda-prefix-format)
  5280. (cdr (assq key org-agenda-prefix-format)))
  5281. (t " %-12:c%?-12t% s")))
  5282. (start 0)
  5283. varform vars var e c f opt)
  5284. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5285. s start)
  5286. (setq var (or (cdr (assoc (match-string 4 s)
  5287. '(("c" . category) ("t" . time) ("s" . extra)
  5288. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5289. 'eval)
  5290. c (or (match-string 3 s) "")
  5291. opt (match-beginning 1)
  5292. start (1+ (match-beginning 0)))
  5293. (if (equal var 'time) (setq org-prefix-has-time t))
  5294. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5295. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5296. (setq f (concat "%" (match-string 2 s) "s"))
  5297. (when (equal var 'category)
  5298. (setq org-prefix-category-length
  5299. (floor (abs (string-to-number (match-string 2 s)))))
  5300. (setq org-prefix-category-max-length
  5301. (let ((x (match-string 2 s)))
  5302. (save-match-data
  5303. (if (string-match "\\.[0-9]+" x)
  5304. (string-to-number (substring (match-string 0 x) 1)))))))
  5305. (if (eq var 'eval)
  5306. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5307. (if opt
  5308. (setq varform
  5309. `(if (equal "" ,var)
  5310. ""
  5311. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5312. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5313. (setq s (replace-match "%s" t nil s))
  5314. (push varform vars))
  5315. (setq vars (nreverse vars))
  5316. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5317. (defun org-set-sorting-strategy (key)
  5318. (if (symbolp (car org-agenda-sorting-strategy))
  5319. ;; the old format
  5320. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5321. (setq org-agenda-sorting-strategy-selected
  5322. (or (cdr (assq key org-agenda-sorting-strategy))
  5323. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5324. '(time-up category-keep priority-down)))))
  5325. (defun org-get-time-of-day (s &optional string mod24)
  5326. "Check string S for a time of day.
  5327. If found, return it as a military time number between 0 and 2400.
  5328. If not found, return nil.
  5329. The optional STRING argument forces conversion into a 5 character wide string
  5330. HH:MM."
  5331. (save-match-data
  5332. (when
  5333. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5334. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5335. (let* ((h (string-to-number (match-string 1 s)))
  5336. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5337. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5338. (am-p (equal ampm "am"))
  5339. (h1 (cond ((not ampm) h)
  5340. ((= h 12) (if am-p 0 12))
  5341. (t (+ h (if am-p 0 12)))))
  5342. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5343. (mod h1 24) h1))
  5344. (t0 (+ (* 100 h2) m))
  5345. (t1 (concat (if (>= h1 24) "+" " ")
  5346. (if (and org-agenda-time-leading-zero
  5347. (< t0 1000)) "0" "")
  5348. (if (< t0 100) "0" "")
  5349. (if (< t0 10) "0" "")
  5350. (int-to-string t0))))
  5351. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5352. (defvar org-agenda-before-sorting-filter-function nil
  5353. "Function to be applied to agenda items prior to sorting.
  5354. Prior to sorting also means just before they are inserted into the agenda.
  5355. To aid sorting, you may revisit the original entries and add more text
  5356. properties which will later be used by the sorting functions.
  5357. The function should take a string argument, an agenda line.
  5358. It has access to the text properties in that line, which contain among
  5359. other things, the property `org-hd-marker' that points to the entry
  5360. where the line comes from. Note that not all lines going into the agenda
  5361. have this property, only most.
  5362. The function should return the modified string. It is probably best
  5363. to ONLY change text properties.
  5364. You can also use this function as a filter, by returning nil for lines
  5365. you don't want to have in the agenda at all. For this application, you
  5366. could bind the variable in the options section of a custom command.")
  5367. (defun org-finalize-agenda-entries (list &optional nosort)
  5368. "Sort and concatenate the agenda items."
  5369. (setq list (mapcar 'org-agenda-highlight-todo list))
  5370. (if nosort
  5371. list
  5372. (when org-agenda-before-sorting-filter-function
  5373. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5374. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5375. (defun org-agenda-highlight-todo (x)
  5376. (let ((org-done-keywords org-done-keywords-for-agenda)
  5377. (case-fold-search nil)
  5378. re)
  5379. (if (eq x 'line)
  5380. (save-excursion
  5381. (beginning-of-line 1)
  5382. (setq re (org-get-at-bol 'org-todo-regexp))
  5383. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5384. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5385. (add-text-properties (match-beginning 0) (match-end 1)
  5386. (list 'face (org-get-todo-face 1)))
  5387. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5388. (delete-region (match-beginning 1) (1- (match-end 0)))
  5389. (goto-char (match-beginning 1))
  5390. (insert (format org-agenda-todo-keyword-format s)))))
  5391. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5392. (setq re (get-text-property 0 'org-todo-regexp x))
  5393. (when (and re
  5394. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5395. x (or pl 0)) pl))
  5396. (add-text-properties
  5397. (or (match-end 1) (match-end 0)) (match-end 0)
  5398. (list 'face (org-get-todo-face (match-string 2 x)))
  5399. x)
  5400. (when (match-end 1)
  5401. (setq x (concat (substring x 0 (match-end 1))
  5402. (format org-agenda-todo-keyword-format
  5403. (match-string 2 x))
  5404. (org-add-props " " (text-properties-at 0 x))
  5405. (substring x (match-end 3)))))))
  5406. x)))
  5407. (defsubst org-cmp-priority (a b)
  5408. "Compare the priorities of string A and B."
  5409. (let ((pa (or (get-text-property 1 'priority a) 0))
  5410. (pb (or (get-text-property 1 'priority b) 0)))
  5411. (cond ((> pa pb) +1)
  5412. ((< pa pb) -1)
  5413. (t nil))))
  5414. (defsubst org-cmp-effort (a b)
  5415. "Compare the effort values of string A and B."
  5416. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5417. (ea (or (get-text-property 1 'effort-minutes a) def))
  5418. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5419. (cond ((> ea eb) +1)
  5420. ((< ea eb) -1)
  5421. (t nil))))
  5422. (defsubst org-cmp-category (a b)
  5423. "Compare the string values of categories of strings A and B."
  5424. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5425. (cb (or (get-text-property 1 'org-category b) "")))
  5426. (cond ((string-lessp ca cb) -1)
  5427. ((string-lessp cb ca) +1)
  5428. (t nil))))
  5429. (defsubst org-cmp-todo-state (a b)
  5430. "Compare the todo states of strings A and B."
  5431. (let* ((ma (or (get-text-property 1 'org-marker a)
  5432. (get-text-property 1 'org-hd-marker a)))
  5433. (mb (or (get-text-property 1 'org-marker b)
  5434. (get-text-property 1 'org-hd-marker b)))
  5435. (fa (and ma (marker-buffer ma)))
  5436. (fb (and mb (marker-buffer mb)))
  5437. (todo-kwds
  5438. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5439. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5440. (ta (or (get-text-property 1 'todo-state a) ""))
  5441. (tb (or (get-text-property 1 'todo-state b) ""))
  5442. (la (- (length (member ta todo-kwds))))
  5443. (lb (- (length (member tb todo-kwds))))
  5444. (donepa (member ta org-done-keywords-for-agenda))
  5445. (donepb (member tb org-done-keywords-for-agenda)))
  5446. (cond ((and donepa (not donepb)) -1)
  5447. ((and (not donepa) donepb) +1)
  5448. ((< la lb) -1)
  5449. ((< lb la) +1)
  5450. (t nil))))
  5451. (defsubst org-cmp-alpha (a b)
  5452. "Compare the headlines, alphabetically."
  5453. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5454. (plb (text-property-any 0 (length b) 'org-heading t b))
  5455. (ta (and pla (substring a pla)))
  5456. (tb (and plb (substring b plb))))
  5457. (when pla
  5458. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5459. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5460. (setq ta (substring ta (match-end 0))))
  5461. (setq ta (downcase ta)))
  5462. (when plb
  5463. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5464. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5465. (setq tb (substring tb (match-end 0))))
  5466. (setq tb (downcase tb)))
  5467. (cond ((not ta) +1)
  5468. ((not tb) -1)
  5469. ((string-lessp ta tb) -1)
  5470. ((string-lessp tb ta) +1)
  5471. (t nil))))
  5472. (defsubst org-cmp-tag (a b)
  5473. "Compare the string values of the first tags of A and B."
  5474. (let ((ta (car (last (get-text-property 1 'tags a))))
  5475. (tb (car (last (get-text-property 1 'tags b)))))
  5476. (cond ((not ta) +1)
  5477. ((not tb) -1)
  5478. ((string-lessp ta tb) -1)
  5479. ((string-lessp tb ta) +1)
  5480. (t nil))))
  5481. (defsubst org-cmp-time (a b)
  5482. "Compare the time-of-day values of strings A and B."
  5483. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5484. (ta (or (get-text-property 1 'time-of-day a) def))
  5485. (tb (or (get-text-property 1 'time-of-day b) def)))
  5486. (cond ((< ta tb) -1)
  5487. ((< tb ta) +1)
  5488. (t nil))))
  5489. (defsubst org-cmp-habit-p (a b)
  5490. "Compare the todo states of strings A and B."
  5491. (let ((ha (get-text-property 1 'org-habit-p a))
  5492. (hb (get-text-property 1 'org-habit-p b)))
  5493. (cond ((and ha (not hb)) -1)
  5494. ((and (not ha) hb) +1)
  5495. (t nil))))
  5496. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5497. (defun org-entries-lessp (a b)
  5498. "Predicate for sorting agenda entries."
  5499. ;; The following variables will be used when the form is evaluated.
  5500. ;; So even though the compiler complains, keep them.
  5501. (let* ((ss org-agenda-sorting-strategy-selected)
  5502. (time-up (and (org-em 'time-up 'time-down ss)
  5503. (org-cmp-time a b)))
  5504. (time-down (if time-up (- time-up) nil))
  5505. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5506. (org-cmp-priority a b)))
  5507. (priority-down (if priority-up (- priority-up) nil))
  5508. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5509. (org-cmp-effort a b)))
  5510. (effort-down (if effort-up (- effort-up) nil))
  5511. (category-up (and (or (org-em 'category-up 'category-down ss)
  5512. (memq 'category-keep ss))
  5513. (org-cmp-category a b)))
  5514. (category-down (if category-up (- category-up) nil))
  5515. (category-keep (if category-up +1 nil))
  5516. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5517. (org-cmp-tag a b)))
  5518. (tag-down (if tag-up (- tag-up) nil))
  5519. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5520. (org-cmp-todo-state a b)))
  5521. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5522. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5523. (org-cmp-habit-p a b)))
  5524. (habit-down (if habit-up (- habit-up) nil))
  5525. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5526. (org-cmp-alpha a b)))
  5527. (alpha-down (if alpha-up (- alpha-up) nil))
  5528. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5529. user-defined-up user-defined-down)
  5530. (if (and need-user-cmp org-agenda-cmp-user-defined
  5531. (functionp org-agenda-cmp-user-defined))
  5532. (setq user-defined-up
  5533. (funcall org-agenda-cmp-user-defined a b)
  5534. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5535. (cdr (assoc
  5536. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5537. '((-1 . t) (1 . nil) (nil . nil))))))
  5538. ;;; Agenda restriction lock
  5539. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5540. "Overlay to mark the headline to which agenda commands are restricted.")
  5541. (overlay-put org-agenda-restriction-lock-overlay
  5542. 'face 'org-agenda-restriction-lock)
  5543. (overlay-put org-agenda-restriction-lock-overlay
  5544. 'help-echo "Agendas are currently limited to this subtree.")
  5545. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5546. (defun org-agenda-set-restriction-lock (&optional type)
  5547. "Set restriction lock for agenda, to current subtree or file.
  5548. Restriction will be the file if TYPE is `file', or if type is the
  5549. universal prefix '(4), or if the cursor is before the first headline
  5550. in the file. Otherwise, restriction will be to the current subtree."
  5551. (interactive "P")
  5552. (and (equal type '(4)) (setq type 'file))
  5553. (setq type (cond
  5554. (type type)
  5555. ((org-at-heading-p) 'subtree)
  5556. ((condition-case nil (org-back-to-heading t) (error nil))
  5557. 'subtree)
  5558. (t 'file)))
  5559. (if (eq type 'subtree)
  5560. (progn
  5561. (setq org-agenda-restrict t)
  5562. (setq org-agenda-overriding-restriction 'subtree)
  5563. (put 'org-agenda-files 'org-restrict
  5564. (list (buffer-file-name (buffer-base-buffer))))
  5565. (org-back-to-heading t)
  5566. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5567. (move-marker org-agenda-restrict-begin (point))
  5568. (move-marker org-agenda-restrict-end
  5569. (save-excursion (org-end-of-subtree t)))
  5570. (message "Locking agenda restriction to subtree"))
  5571. (put 'org-agenda-files 'org-restrict
  5572. (list (buffer-file-name (buffer-base-buffer))))
  5573. (setq org-agenda-restrict nil)
  5574. (setq org-agenda-overriding-restriction 'file)
  5575. (move-marker org-agenda-restrict-begin nil)
  5576. (move-marker org-agenda-restrict-end nil)
  5577. (message "Locking agenda restriction to file"))
  5578. (setq current-prefix-arg nil)
  5579. (org-agenda-maybe-redo))
  5580. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5581. "Remove the agenda restriction lock."
  5582. (interactive "P")
  5583. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5584. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5585. (setq org-agenda-overriding-restriction nil)
  5586. (setq org-agenda-restrict nil)
  5587. (put 'org-agenda-files 'org-restrict nil)
  5588. (move-marker org-agenda-restrict-begin nil)
  5589. (move-marker org-agenda-restrict-end nil)
  5590. (setq current-prefix-arg nil)
  5591. (message "Agenda restriction lock removed")
  5592. (or noupdate (org-agenda-maybe-redo)))
  5593. (defun org-agenda-maybe-redo ()
  5594. "If there is any window showing the agenda view, update it."
  5595. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5596. (w0 (selected-window)))
  5597. (when w
  5598. (select-window w)
  5599. (org-agenda-redo)
  5600. (select-window w0)
  5601. (if org-agenda-overriding-restriction
  5602. (message "Agenda view shifted to new %s restriction"
  5603. org-agenda-overriding-restriction)
  5604. (message "Agenda restriction lock removed")))))
  5605. ;;; Agenda commands
  5606. (defun org-agenda-check-type (error &rest types)
  5607. "Check if agenda buffer is of allowed type.
  5608. If ERROR is non-nil, throw an error, otherwise just return nil."
  5609. (if (memq org-agenda-type types)
  5610. t
  5611. (if error
  5612. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5613. nil)))
  5614. (defun org-agenda-quit ()
  5615. "Exit agenda by removing the window or the buffer."
  5616. (interactive)
  5617. (if org-agenda-columns-active
  5618. (org-columns-quit)
  5619. (let ((buf (current-buffer)))
  5620. (if (eq org-agenda-window-setup 'other-frame)
  5621. (progn
  5622. (kill-buffer buf)
  5623. (org-agenda-reset-markers)
  5624. (org-columns-remove-overlays)
  5625. (setq org-agenda-archives-mode nil)
  5626. (delete-frame))
  5627. (and (not (eq org-agenda-window-setup 'current-window))
  5628. (not (one-window-p))
  5629. (delete-window))
  5630. (kill-buffer buf)
  5631. (org-agenda-reset-markers)
  5632. (org-columns-remove-overlays)
  5633. (setq org-agenda-archives-mode nil)))
  5634. ;; Maybe restore the pre-agenda window configuration.
  5635. (and org-agenda-restore-windows-after-quit
  5636. (not (eq org-agenda-window-setup 'other-frame))
  5637. org-pre-agenda-window-conf
  5638. (set-window-configuration org-pre-agenda-window-conf))))
  5639. (defun org-agenda-exit ()
  5640. "Exit agenda by removing the window or the buffer.
  5641. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5642. Org-mode buffers visited directly by the user will not be touched."
  5643. (interactive)
  5644. (org-release-buffers org-agenda-new-buffers)
  5645. (setq org-agenda-new-buffers nil)
  5646. (org-agenda-quit))
  5647. (defun org-agenda-execute (arg)
  5648. "Execute another agenda command, keeping same window.
  5649. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5650. in the agenda."
  5651. (interactive "P")
  5652. (let ((org-agenda-window-setup 'current-window))
  5653. (org-agenda arg)))
  5654. (defun org-agenda-redo ()
  5655. "Rebuild Agenda.
  5656. When this is the global TODO list, a prefix argument will be interpreted."
  5657. (interactive)
  5658. (let* ((org-agenda-keep-modes t)
  5659. (filter org-agenda-filter)
  5660. (preset (get 'org-agenda-filter :preset-filter))
  5661. (org-agenda-filter-while-redo (or filter preset))
  5662. (cols org-agenda-columns-active)
  5663. (line (org-current-line))
  5664. (window-line (- line (org-current-line (window-start))))
  5665. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5666. (put 'org-agenda-filter :preset-filter nil)
  5667. (and cols (org-columns-quit))
  5668. (message "Rebuilding agenda buffer...")
  5669. (org-let lprops '(eval org-agenda-redo-command))
  5670. (setq org-agenda-undo-list nil
  5671. org-agenda-pending-undo-list nil)
  5672. (message "Rebuilding agenda buffer...done")
  5673. (put 'org-agenda-filter :preset-filter preset)
  5674. (and (or filter preset) (org-agenda-filter-apply filter))
  5675. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5676. (org-goto-line line)
  5677. (recenter window-line)))
  5678. (defvar org-global-tags-completion-table nil)
  5679. (defvar org-agenda-filter-form nil)
  5680. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5681. "Keep only those lines in the agenda buffer that have a specific tag.
  5682. The tag is selected with its fast selection letter, as configured.
  5683. With prefix argument STRIP, remove all lines that do have the tag.
  5684. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5685. used to narrow the search - the interactive user can also press `-' or `+'
  5686. to switch to narrowing."
  5687. (interactive "P")
  5688. (let* ((alist org-tag-alist-for-agenda)
  5689. (tag-chars (mapconcat
  5690. (lambda (x) (if (and (not (symbolp (car x)))
  5691. (cdr x))
  5692. (char-to-string (cdr x))
  5693. ""))
  5694. alist ""))
  5695. (efforts (org-split-string
  5696. (or (cdr (assoc (concat org-effort-property "_ALL")
  5697. org-global-properties))
  5698. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5699. "")))
  5700. (effort-op org-agenda-filter-effort-default-operator)
  5701. (effort-prompt "")
  5702. (inhibit-read-only t)
  5703. (current org-agenda-filter)
  5704. maybe-refresh a n tag)
  5705. (unless char
  5706. (message
  5707. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5708. (if narrow "Narrow" "Filter") tag-chars
  5709. (if org-agenda-auto-exclude-function "[RET], " ""))
  5710. (setq char (read-char)))
  5711. (when (member char '(?+ ?-))
  5712. ;; Narrowing down
  5713. (cond ((equal char ?-) (setq strip t narrow t))
  5714. ((equal char ?+) (setq strip nil narrow t)))
  5715. (message
  5716. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5717. (setq char (read-char)))
  5718. (when (member char '(?< ?> ?= ??))
  5719. ;; An effort operator
  5720. (setq effort-op (char-to-string char))
  5721. (setq alist nil) ; to make sure it will be interpreted as effort.
  5722. (unless (equal char ??)
  5723. (loop for i from 0 to 9 do
  5724. (setq effort-prompt
  5725. (concat
  5726. effort-prompt " ["
  5727. (if (= i 9) "0" (int-to-string (1+ i)))
  5728. "]" (nth i efforts))))
  5729. (message "Effort%s: %s " effort-op effort-prompt)
  5730. (setq char (read-char))
  5731. (when (or (< char ?0) (> char ?9))
  5732. (error "Need 1-9,0 to select effort" ))))
  5733. (when (equal char ?\t)
  5734. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5735. (org-set-local 'org-global-tags-completion-table
  5736. (org-global-tags-completion-table)))
  5737. (let ((completion-ignore-case t))
  5738. (setq tag (org-icompleting-read
  5739. "Tag: " org-global-tags-completion-table))))
  5740. (cond
  5741. ((equal char ?\r)
  5742. (org-agenda-filter-by-tag-show-all)
  5743. (when org-agenda-auto-exclude-function
  5744. (setq org-agenda-filter '())
  5745. (dolist (tag (org-agenda-get-represented-tags))
  5746. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5747. (if modifier
  5748. (push modifier org-agenda-filter))))
  5749. (if (not (null org-agenda-filter))
  5750. (org-agenda-filter-apply org-agenda-filter)))
  5751. (setq maybe-refresh t))
  5752. ((equal char ?/)
  5753. (org-agenda-filter-by-tag-show-all)
  5754. (when (get 'org-agenda-filter :preset-filter)
  5755. (org-agenda-filter-apply org-agenda-filter))
  5756. (setq maybe-refresh t))
  5757. ((or (equal char ?\ )
  5758. (setq a (rassoc char alist))
  5759. (and (>= char ?0) (<= char ?9)
  5760. (setq n (if (= char ?0) 9 (- char ?0 1))
  5761. tag (concat effort-op (nth n efforts))
  5762. a (cons tag nil)))
  5763. (and (= char ??)
  5764. (setq tag "?eff")
  5765. a (cons tag nil))
  5766. (and tag (setq a (cons tag nil))))
  5767. (org-agenda-filter-by-tag-show-all)
  5768. (setq tag (car a))
  5769. (setq org-agenda-filter
  5770. (cons (concat (if strip "-" "+") tag)
  5771. (if narrow current nil)))
  5772. (org-agenda-filter-apply org-agenda-filter)
  5773. (setq maybe-refresh t))
  5774. (t (error "Invalid tag selection character %c" char)))
  5775. (when (and maybe-refresh
  5776. (eq org-agenda-clockreport-mode 'with-filter))
  5777. (org-agenda-redo))))
  5778. (defun org-agenda-get-represented-tags ()
  5779. "Get a list of all tags currently represented in the agenda."
  5780. (let (p tags)
  5781. (save-excursion
  5782. (goto-char (point-min))
  5783. (while (setq p (next-single-property-change (point) 'tags))
  5784. (goto-char p)
  5785. (mapc (lambda (x) (add-to-list 'tags x))
  5786. (get-text-property (point) 'tags))))
  5787. tags))
  5788. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5789. "Refine the current filter. See `org-agenda-filter-by-tag."
  5790. (interactive "P")
  5791. (org-agenda-filter-by-tag strip char 'refine))
  5792. (defun org-agenda-filter-make-matcher ()
  5793. "Create the form that tests a line for the agenda filter."
  5794. (let (f f1)
  5795. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5796. org-agenda-filter))
  5797. (if (member x '("-" "+"))
  5798. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5799. (if (string-match "[<=>?]" x)
  5800. (setq f1 (org-agenda-filter-effort-form x))
  5801. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5802. (if (equal (string-to-char x) ?-)
  5803. (setq f1 (list 'not f1))))
  5804. (push f1 f))
  5805. (cons 'and (nreverse f))))
  5806. (defun org-agenda-filter-effort-form (e)
  5807. "Return the form to compare the effort of the current line with what E says.
  5808. E looks like \"+<2:25\"."
  5809. (let (op)
  5810. (setq e (substring e 1))
  5811. (setq op (string-to-char e) e (substring e 1))
  5812. (setq op (cond ((equal op ?<) '<=)
  5813. ((equal op ?>) '>=)
  5814. ((equal op ??) op)
  5815. (t '=)))
  5816. (list 'org-agenda-compare-effort (list 'quote op)
  5817. (org-duration-string-to-minutes e))))
  5818. (defun org-agenda-compare-effort (op value)
  5819. "Compare the effort of the current line with VALUE, using OP.
  5820. If the line does not have an effort defined, return nil."
  5821. (let ((eff (org-get-at-bol 'effort-minutes)))
  5822. (if (equal op ??)
  5823. (not eff)
  5824. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5825. value))))
  5826. (defun org-agenda-filter-apply (filter)
  5827. "Set FILTER as the new agenda filter and apply it."
  5828. (let (tags)
  5829. (setq org-agenda-filter filter
  5830. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5831. (org-agenda-set-mode-name)
  5832. (save-excursion
  5833. (goto-char (point-min))
  5834. (while (not (eobp))
  5835. (if (org-get-at-bol 'org-marker)
  5836. (progn
  5837. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5838. (if (not (eval org-agenda-filter-form))
  5839. (org-agenda-filter-by-tag-hide-line))
  5840. (beginning-of-line 2))
  5841. (beginning-of-line 2))))
  5842. (if (get-char-property (point) 'invisible)
  5843. (org-agenda-previous-line))))
  5844. (defun org-agenda-filter-by-tag-hide-line ()
  5845. (let (ov)
  5846. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5847. (point-at-eol)))
  5848. (overlay-put ov 'invisible t)
  5849. (overlay-put ov 'type 'tags-filter)
  5850. (push ov org-agenda-filter-overlays)))
  5851. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5852. (setq pos (or pos (point)))
  5853. (save-excursion
  5854. (dolist (ov (overlays-at pos))
  5855. (when (and (overlay-get ov 'invisible)
  5856. (eq (overlay-get ov 'type) 'tags-filter))
  5857. (goto-char pos)
  5858. (if (< (overlay-start ov) (point-at-eol))
  5859. (move-overlay ov (point-at-eol)
  5860. (overlay-end ov)))))))
  5861. (defun org-agenda-filter-by-tag-show-all ()
  5862. (mapc 'delete-overlay org-agenda-filter-overlays)
  5863. (setq org-agenda-filter-overlays nil)
  5864. (setq org-agenda-filter nil)
  5865. (setq org-agenda-filter-form nil)
  5866. (org-agenda-set-mode-name))
  5867. (defun org-agenda-manipulate-query-add ()
  5868. "Manipulate the query by adding a search term with positive selection.
  5869. Positive selection means the term must be matched for selection of an entry."
  5870. (interactive)
  5871. (org-agenda-manipulate-query ?\[))
  5872. (defun org-agenda-manipulate-query-subtract ()
  5873. "Manipulate the query by adding a search term with negative selection.
  5874. Negative selection means term must not be matched for selection of an entry."
  5875. (interactive)
  5876. (org-agenda-manipulate-query ?\]))
  5877. (defun org-agenda-manipulate-query-add-re ()
  5878. "Manipulate the query by adding a search regexp with positive selection.
  5879. Positive selection means the regexp must match for selection of an entry."
  5880. (interactive)
  5881. (org-agenda-manipulate-query ?\{))
  5882. (defun org-agenda-manipulate-query-subtract-re ()
  5883. "Manipulate the query by adding a search regexp with negative selection.
  5884. Negative selection means regexp must not match for selection of an entry."
  5885. (interactive)
  5886. (org-agenda-manipulate-query ?\}))
  5887. (defun org-agenda-manipulate-query (char)
  5888. (cond
  5889. ((memq org-agenda-type '(timeline agenda))
  5890. (let ((org-agenda-include-inactive-timestamps t))
  5891. (org-agenda-redo))
  5892. (message "Display now includes inactive timestamps as well"))
  5893. ((eq org-agenda-type 'search)
  5894. (org-add-to-string
  5895. 'org-agenda-query-string
  5896. (if org-agenda-last-search-view-search-was-boolean
  5897. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5898. (?\{ . " +{}") (?\} . " -{}"))))
  5899. " "))
  5900. (setq org-agenda-redo-command
  5901. (list 'org-search-view
  5902. org-todo-only
  5903. org-agenda-query-string
  5904. (+ (length org-agenda-query-string)
  5905. (if (member char '(?\{ ?\})) 0 1))))
  5906. (set-register org-agenda-query-register org-agenda-query-string)
  5907. (org-agenda-redo))
  5908. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5909. org-agenda-type))))
  5910. (defun org-add-to-string (var string)
  5911. (set var (concat (symbol-value var) string)))
  5912. (defun org-agenda-goto-date (date)
  5913. "Jump to DATE in agenda."
  5914. (interactive (list (let ((org-read-date-prefer-future
  5915. (eval org-agenda-jump-prefer-future)))
  5916. (org-read-date))))
  5917. (org-agenda-list nil date))
  5918. (defun org-agenda-goto-today ()
  5919. "Go to today."
  5920. (interactive)
  5921. (org-agenda-check-type t 'timeline 'agenda)
  5922. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5923. (cond
  5924. (tdpos (goto-char tdpos))
  5925. ((eq org-agenda-type 'agenda)
  5926. (let* ((sd (org-agenda-compute-starting-span
  5927. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5928. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5929. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5930. (org-agenda-redo)
  5931. (org-agenda-find-same-or-today-or-agenda)))
  5932. (t (error "Cannot find today")))))
  5933. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5934. (goto-char
  5935. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5936. (text-property-any (point-min) (point-max) 'org-today t)
  5937. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5938. (point-min))))
  5939. (defun org-agenda-later (arg)
  5940. "Go forward in time by thee current span.
  5941. With prefix ARG, go forward that many times the current span."
  5942. (interactive "p")
  5943. (org-agenda-check-type t 'agenda)
  5944. (let* ((span org-agenda-current-span)
  5945. (sd org-starting-day)
  5946. (greg (calendar-gregorian-from-absolute sd))
  5947. (cnt (org-get-at-bol 'org-day-cnt))
  5948. greg2)
  5949. (cond
  5950. ((eq span 'day)
  5951. (setq sd (+ arg sd)))
  5952. ((eq span 'week)
  5953. (setq sd (+ (* 7 arg) sd)))
  5954. ((eq span 'month)
  5955. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5956. sd (calendar-absolute-from-gregorian greg2))
  5957. (setcar greg2 (1+ (car greg2))))
  5958. ((eq span 'year)
  5959. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5960. sd (calendar-absolute-from-gregorian greg2))
  5961. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5962. (t
  5963. (setq sd (+ (* span arg) sd))))
  5964. (let ((org-agenda-overriding-arguments
  5965. (list (car org-agenda-last-arguments) sd span t)))
  5966. (org-agenda-redo)
  5967. (org-agenda-find-same-or-today-or-agenda cnt))))
  5968. (defun org-agenda-earlier (arg)
  5969. "Go backward in time by the current span.
  5970. With prefix ARG, go backward that many times the current span."
  5971. (interactive "p")
  5972. (org-agenda-later (- arg)))
  5973. (defun org-agenda-view-mode-dispatch ()
  5974. "Call one of the view mode commands."
  5975. (interactive)
  5976. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5977. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5978. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5979. [E]ntryText")
  5980. (let ((a (read-char-exclusive)))
  5981. (case a
  5982. (?\ (call-interactively 'org-agenda-reset-view))
  5983. (?d (call-interactively 'org-agenda-day-view))
  5984. (?w (call-interactively 'org-agenda-week-view))
  5985. (?m (call-interactively 'org-agenda-month-view))
  5986. (?y (call-interactively 'org-agenda-year-view))
  5987. (?l (call-interactively 'org-agenda-log-mode))
  5988. (?L (org-agenda-log-mode '(4)))
  5989. (?c (org-agenda-log-mode 'clockcheck))
  5990. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5991. (?a (call-interactively 'org-agenda-archives-mode))
  5992. (?A (org-agenda-archives-mode 'files))
  5993. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5994. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5995. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5996. (?D (call-interactively 'org-agenda-toggle-diary))
  5997. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5998. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5999. (org-agenda-check-type t 'timeline 'agenda)
  6000. (org-agenda-redo))
  6001. (message "Display now includes inactive timestamps as well"))
  6002. (?q (message "Abort"))
  6003. (otherwise (error "Invalid key" )))))
  6004. (defun org-agenda-reset-view ()
  6005. "Switch to default view for agenda."
  6006. (interactive)
  6007. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6008. (defun org-agenda-day-view (&optional day-of-year)
  6009. "Switch to daily view for agenda.
  6010. With argument DAY-OF-YEAR, switch to that day of the year."
  6011. (interactive "P")
  6012. (org-agenda-change-time-span 'day day-of-year))
  6013. (defun org-agenda-week-view (&optional iso-week)
  6014. "Switch to daily view for agenda.
  6015. With argument ISO-WEEK, switch to the corresponding ISO week.
  6016. If ISO-WEEK has more then 2 digits, only the last two encode the
  6017. week. Any digits before this encode a year. So 200712 means
  6018. week 12 of year 2007. Years in the range 1938-2037 can also be
  6019. written as 2-digit years."
  6020. (interactive "P")
  6021. (org-agenda-change-time-span 'week iso-week))
  6022. (defun org-agenda-month-view (&optional month)
  6023. "Switch to monthly view for agenda.
  6024. With argument MONTH, switch to that month."
  6025. (interactive "P")
  6026. (org-agenda-change-time-span 'month month))
  6027. (defun org-agenda-year-view (&optional year)
  6028. "Switch to yearly view for agenda.
  6029. With argument YEAR, switch to that year.
  6030. If MONTH has more then 2 digits, only the last two encode the
  6031. month. Any digits before this encode a year. So 200712 means
  6032. December year 2007. Years in the range 1938-2037 can also be
  6033. written as 2-digit years."
  6034. (interactive "P")
  6035. (when year
  6036. (setq year (org-small-year-to-year year)))
  6037. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6038. (org-agenda-change-time-span 'year year)
  6039. (error "Abort")))
  6040. (defun org-agenda-change-time-span (span &optional n)
  6041. "Change the agenda view to SPAN.
  6042. SPAN may be `day', `week', `month', `year'."
  6043. (org-agenda-check-type t 'agenda)
  6044. (if (and (not n) (equal org-agenda-current-span span))
  6045. (error "Viewing span is already \"%s\"" span))
  6046. (let* ((sd (or (org-get-at-bol 'day)
  6047. org-starting-day))
  6048. (sd (org-agenda-compute-starting-span sd span n))
  6049. (org-agenda-overriding-arguments
  6050. (or org-agenda-overriding-arguments
  6051. (list (car org-agenda-last-arguments) sd span t))))
  6052. (org-agenda-redo)
  6053. (org-agenda-find-same-or-today-or-agenda))
  6054. (org-agenda-set-mode-name)
  6055. (message "Switched to %s view" span))
  6056. (defun org-agenda-compute-starting-span (sd span &optional n)
  6057. "Compute starting date for agenda.
  6058. SPAN may be `day', `week', `month', `year'. The return value
  6059. is a cons cell with the starting date and the number of days,
  6060. so that the date SD will be in that range."
  6061. (let* ((greg (calendar-gregorian-from-absolute sd))
  6062. (dg (nth 1 greg))
  6063. (mg (car greg))
  6064. (yg (nth 2 greg)))
  6065. (cond
  6066. ((eq span 'day)
  6067. (when n
  6068. (setq sd (+ (calendar-absolute-from-gregorian
  6069. (list mg 1 yg))
  6070. n -1))))
  6071. ((eq span 'week)
  6072. (let* ((nt (calendar-day-of-week
  6073. (calendar-gregorian-from-absolute sd)))
  6074. (d (if org-agenda-start-on-weekday
  6075. (- nt org-agenda-start-on-weekday)
  6076. 0))
  6077. y1)
  6078. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6079. (when n
  6080. (require 'cal-iso)
  6081. (when (> n 99)
  6082. (setq y1 (org-small-year-to-year (/ n 100))
  6083. n (mod n 100)))
  6084. (setq sd
  6085. (calendar-absolute-from-iso
  6086. (list n 1
  6087. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6088. ((eq span 'month)
  6089. (let (y1)
  6090. (when (and n (> n 99))
  6091. (setq y1 (org-small-year-to-year (/ n 100))
  6092. n (mod n 100)))
  6093. (setq sd (calendar-absolute-from-gregorian
  6094. (list (or n mg) 1 (or y1 yg))))))
  6095. ((eq span 'year)
  6096. (setq sd (calendar-absolute-from-gregorian
  6097. (list 1 1 (or n yg))))))
  6098. sd))
  6099. (defun org-agenda-next-date-line (&optional arg)
  6100. "Jump to the next line indicating a date in agenda buffer."
  6101. (interactive "p")
  6102. (org-agenda-check-type t 'agenda 'timeline)
  6103. (beginning-of-line 1)
  6104. ;; This does not work if user makes date format that starts with a blank
  6105. (if (looking-at "^\\S-") (forward-char 1))
  6106. (if (not (re-search-forward "^\\S-" nil t arg))
  6107. (progn
  6108. (backward-char 1)
  6109. (error "No next date after this line in this buffer")))
  6110. (goto-char (match-beginning 0)))
  6111. (defun org-agenda-previous-date-line (&optional arg)
  6112. "Jump to the previous line indicating a date in agenda buffer."
  6113. (interactive "p")
  6114. (org-agenda-check-type t 'agenda 'timeline)
  6115. (beginning-of-line 1)
  6116. (if (not (re-search-backward "^\\S-" nil t arg))
  6117. (error "No previous date before this line in this buffer")))
  6118. ;; Initialize the highlight
  6119. (defvar org-hl (make-overlay 1 1))
  6120. (overlay-put org-hl 'face 'highlight)
  6121. (defun org-highlight (begin end &optional buffer)
  6122. "Highlight a region with overlay."
  6123. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6124. (defun org-unhighlight ()
  6125. "Detach overlay INDEX."
  6126. (org-detach-overlay org-hl))
  6127. ;; FIXME this is currently not used.
  6128. (defun org-highlight-until-next-command (beg end &optional buffer)
  6129. "Move the highlight overlay to BEG/END, remove it before the next command."
  6130. (org-highlight beg end buffer)
  6131. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6132. (defun org-unhighlight-once ()
  6133. "Remove the highlight from its position, and this function from the hook."
  6134. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6135. (org-unhighlight))
  6136. (defun org-agenda-follow-mode ()
  6137. "Toggle follow mode in an agenda buffer."
  6138. (interactive)
  6139. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6140. (org-agenda-set-mode-name)
  6141. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6142. (org-agenda-show))
  6143. (message "Follow mode is %s"
  6144. (if org-agenda-follow-mode "on" "off")))
  6145. (defun org-agenda-entry-text-mode (&optional arg)
  6146. "Toggle entry text mode in an agenda buffer."
  6147. (interactive "P")
  6148. (setq org-agenda-entry-text-mode (or (integerp arg)
  6149. (not org-agenda-entry-text-mode)))
  6150. (org-agenda-entry-text-hide)
  6151. (and org-agenda-entry-text-mode
  6152. (let ((org-agenda-entry-text-maxlines
  6153. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6154. (org-agenda-entry-text-show)))
  6155. (org-agenda-set-mode-name)
  6156. (message "Entry text mode is %s. Maximum number of lines is %d"
  6157. (if org-agenda-entry-text-mode "on" "off")
  6158. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6159. (defun org-agenda-clockreport-mode (&optional with-filter)
  6160. "Toggle clocktable mode in an agenda buffer.
  6161. With prefix arg WITH-FILTER, make the clocktable respect the current
  6162. agenda filter."
  6163. (interactive "P")
  6164. (org-agenda-check-type t 'agenda)
  6165. (if with-filter
  6166. (setq org-agenda-clockreport-mode 'with-filter)
  6167. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6168. (org-agenda-set-mode-name)
  6169. (org-agenda-redo)
  6170. (message "Clocktable mode is %s"
  6171. (if org-agenda-clockreport-mode "on" "off")))
  6172. (defun org-agenda-log-mode (&optional special)
  6173. "Toggle log mode in an agenda buffer.
  6174. With argument SPECIAL, show all possible log items, not only the ones
  6175. configured in `org-agenda-log-mode-items'.
  6176. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6177. (interactive "P")
  6178. (org-agenda-check-type t 'agenda 'timeline)
  6179. (setq org-agenda-show-log
  6180. (cond
  6181. ((equal special '(16)) 'only)
  6182. ((eq special 'clockcheck)
  6183. (if (eq org-agenda-show-log 'clockcheck)
  6184. nil 'clockcheck))
  6185. (special '(closed clock state))
  6186. (t (not org-agenda-show-log))))
  6187. (org-agenda-set-mode-name)
  6188. (org-agenda-redo)
  6189. (message "Log mode is %s"
  6190. (if org-agenda-show-log "on" "off")))
  6191. (defun org-agenda-archives-mode (&optional with-files)
  6192. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6193. When called with a prefix argument, include all archive files as well."
  6194. (interactive "P")
  6195. (setq org-agenda-archives-mode
  6196. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6197. (org-agenda-set-mode-name)
  6198. (org-agenda-redo)
  6199. (message
  6200. "%s"
  6201. (cond
  6202. ((eq org-agenda-archives-mode nil)
  6203. "No archives are included")
  6204. ((eq org-agenda-archives-mode 'trees)
  6205. (format "Trees with :%s: tag are included" org-archive-tag))
  6206. ((eq org-agenda-archives-mode t)
  6207. (format "Trees with :%s: tag and all active archive files are included"
  6208. org-archive-tag)))))
  6209. (defun org-agenda-toggle-diary ()
  6210. "Toggle diary inclusion in an agenda buffer."
  6211. (interactive)
  6212. (org-agenda-check-type t 'agenda)
  6213. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6214. (org-agenda-redo)
  6215. (org-agenda-set-mode-name)
  6216. (message "Diary inclusion turned %s"
  6217. (if org-agenda-include-diary "on" "off")))
  6218. (defun org-agenda-toggle-deadlines ()
  6219. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6220. (interactive)
  6221. (org-agenda-check-type t 'agenda)
  6222. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6223. (org-agenda-redo)
  6224. (org-agenda-set-mode-name)
  6225. (message "Deadlines inclusion turned %s"
  6226. (if org-agenda-include-deadlines "on" "off")))
  6227. (defun org-agenda-toggle-time-grid ()
  6228. "Toggle time grid in an agenda buffer."
  6229. (interactive)
  6230. (org-agenda-check-type t 'agenda)
  6231. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6232. (org-agenda-redo)
  6233. (org-agenda-set-mode-name)
  6234. (message "Time-grid turned %s"
  6235. (if org-agenda-use-time-grid "on" "off")))
  6236. (defun org-agenda-set-mode-name ()
  6237. "Set the mode name to indicate all the small mode settings."
  6238. (setq mode-name
  6239. (list "Org-Agenda"
  6240. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6241. " "
  6242. '(:eval (org-agenda-span-name org-agenda-current-span))
  6243. (if org-agenda-follow-mode " Follow" "")
  6244. (if org-agenda-entry-text-mode " ETxt" "")
  6245. (if org-agenda-include-diary " Diary" "")
  6246. (if org-agenda-include-deadlines " Ddl" "")
  6247. (if org-agenda-use-time-grid " Grid" "")
  6248. (if (and (boundp 'org-habit-show-habits)
  6249. org-habit-show-habits) " Habit" "")
  6250. (cond
  6251. ((consp org-agenda-show-log) " LogAll")
  6252. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6253. (org-agenda-show-log " Log")
  6254. (t ""))
  6255. (if (or org-agenda-filter (get 'org-agenda-filter
  6256. :preset-filter))
  6257. (concat " {" (mapconcat
  6258. 'identity
  6259. (append (get 'org-agenda-filter
  6260. :preset-filter)
  6261. org-agenda-filter) "") "}")
  6262. "")
  6263. (if org-agenda-archives-mode
  6264. (if (eq org-agenda-archives-mode t)
  6265. " Archives"
  6266. (format " :%s:" org-archive-tag))
  6267. "")
  6268. (if org-agenda-clockreport-mode
  6269. (if (eq org-agenda-clockreport-mode 'with-filter)
  6270. " Clock{}" " Clock")
  6271. "")))
  6272. (force-mode-line-update))
  6273. (defun org-agenda-post-command-hook ()
  6274. (setq org-agenda-type
  6275. (or (get-text-property (point) 'org-agenda-type)
  6276. (get-text-property (max (point-min) (1- (point)))
  6277. 'org-agenda-type))))
  6278. (defun org-agenda-next-line ()
  6279. "Move cursor to the next line, and show if follow mode is active."
  6280. (interactive)
  6281. (call-interactively 'next-line)
  6282. (org-agenda-do-context-action))
  6283. (defun org-agenda-previous-line ()
  6284. "Move cursor to the previous line, and show if follow-mode is active."
  6285. (interactive)
  6286. (call-interactively 'previous-line)
  6287. (org-agenda-do-context-action))
  6288. (defun org-agenda-do-context-action ()
  6289. "Show outline path and, maybe, follow mode window."
  6290. (let ((m (org-get-at-bol 'org-marker)))
  6291. (if (and org-agenda-follow-mode m)
  6292. (org-agenda-show))
  6293. (if (and m org-agenda-show-outline-path)
  6294. (org-with-point-at m
  6295. (org-display-outline-path t)))))
  6296. (defun org-agenda-show-priority ()
  6297. "Show the priority of the current item.
  6298. This priority is composed of the main priority given with the [#A] cookies,
  6299. and by additional input from the age of a schedules or deadline entry."
  6300. (interactive)
  6301. (let* ((pri (org-get-at-bol 'priority)))
  6302. (message "Priority is %d" (if pri pri -1000))))
  6303. (defun org-agenda-show-tags ()
  6304. "Show the tags applicable to the current item."
  6305. (interactive)
  6306. (let* ((tags (org-get-at-bol 'tags)))
  6307. (if tags
  6308. (message "Tags are :%s:"
  6309. (org-no-properties (mapconcat 'identity tags ":")))
  6310. (message "No tags associated with this line"))))
  6311. (defun org-agenda-goto (&optional highlight)
  6312. "Go to the Org-mode file which contains the item at point."
  6313. (interactive)
  6314. (let* ((marker (or (org-get-at-bol 'org-marker)
  6315. (org-agenda-error)))
  6316. (buffer (marker-buffer marker))
  6317. (pos (marker-position marker)))
  6318. (switch-to-buffer-other-window buffer)
  6319. (widen)
  6320. (push-mark)
  6321. (goto-char pos)
  6322. (when (org-mode-p)
  6323. (org-show-context 'agenda)
  6324. (save-excursion
  6325. (and (outline-next-heading)
  6326. (org-flag-heading nil)))) ; show the next heading
  6327. (when (outline-invisible-p)
  6328. (show-entry)) ; display invisible text
  6329. (recenter (/ (window-height) 2))
  6330. (run-hooks 'org-agenda-after-show-hook)
  6331. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6332. (defvar org-agenda-after-show-hook nil
  6333. "Normal hook run after an item has been shown from the agenda.
  6334. Point is in the buffer where the item originated.")
  6335. (defun org-agenda-kill ()
  6336. "Kill the entry or subtree belonging to the current agenda entry."
  6337. (interactive)
  6338. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6339. (let* ((marker (or (org-get-at-bol 'org-marker)
  6340. (org-agenda-error)))
  6341. (buffer (marker-buffer marker))
  6342. (pos (marker-position marker))
  6343. (type (org-get-at-bol 'type))
  6344. dbeg dend (n 0) conf)
  6345. (org-with-remote-undo buffer
  6346. (with-current-buffer buffer
  6347. (save-excursion
  6348. (goto-char pos)
  6349. (if (and (org-mode-p) (not (member type '("sexp"))))
  6350. (setq dbeg (progn (org-back-to-heading t) (point))
  6351. dend (org-end-of-subtree t t))
  6352. (setq dbeg (point-at-bol)
  6353. dend (min (point-max) (1+ (point-at-eol)))))
  6354. (goto-char dbeg)
  6355. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6356. (setq conf (or (eq t org-agenda-confirm-kill)
  6357. (and (numberp org-agenda-confirm-kill)
  6358. (> n org-agenda-confirm-kill))))
  6359. (and conf
  6360. (not (y-or-n-p
  6361. (format "Delete entry with %d lines in buffer \"%s\"? "
  6362. n (buffer-name buffer))))
  6363. (error "Abort"))
  6364. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6365. (with-current-buffer buffer (delete-region dbeg dend))
  6366. (message "Agenda item and source killed"))))
  6367. (defvar org-archive-default-command)
  6368. (defun org-agenda-archive-default ()
  6369. "Archive the entry or subtree belonging to the current agenda entry."
  6370. (interactive)
  6371. (require 'org-archive)
  6372. (org-agenda-archive-with org-archive-default-command))
  6373. (defun org-agenda-archive-default-with-confirmation ()
  6374. "Archive the entry or subtree belonging to the current agenda entry."
  6375. (interactive)
  6376. (require 'org-archive)
  6377. (org-agenda-archive-with org-archive-default-command 'confirm))
  6378. (defun org-agenda-archive ()
  6379. "Archive the entry or subtree belonging to the current agenda entry."
  6380. (interactive)
  6381. (org-agenda-archive-with 'org-archive-subtree))
  6382. (defun org-agenda-archive-to-archive-sibling ()
  6383. "Move the entry to the archive sibling."
  6384. (interactive)
  6385. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6386. (defun org-agenda-archive-with (cmd &optional confirm)
  6387. "Move the entry to the archive sibling."
  6388. (interactive)
  6389. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6390. (let* ((marker (or (org-get-at-bol 'org-marker)
  6391. (org-agenda-error)))
  6392. (buffer (marker-buffer marker))
  6393. (pos (marker-position marker)))
  6394. (org-with-remote-undo buffer
  6395. (with-current-buffer buffer
  6396. (if (org-mode-p)
  6397. (if (and confirm
  6398. (not (y-or-n-p "Archive this subtree or entry? ")))
  6399. (error "Abort")
  6400. (save-excursion
  6401. (goto-char pos)
  6402. (org-remove-subtree-entries-from-agenda)
  6403. (org-back-to-heading t)
  6404. (funcall cmd)))
  6405. (error "Archiving works only in Org-mode files"))))))
  6406. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6407. "Remove all lines in the agenda that correspond to a given subtree.
  6408. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6409. If this information is not given, the function uses the tree at point."
  6410. (let ((buf (or buf (current-buffer))) m p)
  6411. (save-excursion
  6412. (unless (and beg end)
  6413. (org-back-to-heading t)
  6414. (setq beg (point))
  6415. (org-end-of-subtree t)
  6416. (setq end (point)))
  6417. (set-buffer (get-buffer org-agenda-buffer-name))
  6418. (save-excursion
  6419. (goto-char (point-max))
  6420. (beginning-of-line 1)
  6421. (while (not (bobp))
  6422. (when (and (setq m (org-get-at-bol 'org-marker))
  6423. (equal buf (marker-buffer m))
  6424. (setq p (marker-position m))
  6425. (>= p beg)
  6426. (< p end))
  6427. (let ((inhibit-read-only t))
  6428. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6429. (beginning-of-line 0))))))
  6430. (defun org-agenda-refile (&optional goto rfloc no-update)
  6431. "Refile the item at point."
  6432. (interactive "P")
  6433. (if (equal goto '(16))
  6434. (org-refile-goto-last-stored)
  6435. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6436. (org-agenda-error)))
  6437. (buffer (marker-buffer marker))
  6438. (pos (marker-position marker))
  6439. (rfloc (or rfloc
  6440. (org-refile-get-location
  6441. (if goto "Goto" "Refile to") buffer
  6442. org-refile-allow-creating-parent-nodes))))
  6443. (with-current-buffer buffer
  6444. (save-excursion
  6445. (save-restriction
  6446. (widen)
  6447. (goto-char marker)
  6448. (org-remove-subtree-entries-from-agenda)
  6449. (org-refile goto buffer rfloc)))))
  6450. (unless no-update (org-agenda-redo))))
  6451. (defun org-agenda-open-link (&optional arg)
  6452. "Follow the link in the current line, if any.
  6453. This looks for a link in the displayed line in the agenda. It also looks
  6454. at the text of the entry itself."
  6455. (interactive "P")
  6456. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6457. (org-get-at-bol 'org-marker)))
  6458. (buffer (and marker (marker-buffer marker)))
  6459. (prefix (buffer-substring
  6460. (point-at-bol) (point-at-eol))))
  6461. (cond
  6462. (buffer
  6463. (with-current-buffer buffer
  6464. (save-excursion
  6465. (save-restriction
  6466. (widen)
  6467. (goto-char marker)
  6468. (org-offer-links-in-entry arg prefix)))))
  6469. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6470. (save-excursion
  6471. (beginning-of-line 1)
  6472. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6473. (org-open-link-from-string (match-string 1)))
  6474. (t (error "No link to open here")))))
  6475. (defun org-agenda-copy-local-variable (var)
  6476. "Get a variable from a referenced buffer and install it here."
  6477. (let ((m (org-get-at-bol 'org-marker)))
  6478. (when (and m (buffer-live-p (marker-buffer m)))
  6479. (org-set-local var (with-current-buffer (marker-buffer m)
  6480. (symbol-value var))))))
  6481. (defun org-agenda-switch-to (&optional delete-other-windows)
  6482. "Go to the Org-mode file which contains the item at point."
  6483. (interactive)
  6484. (if (and org-return-follows-link
  6485. (not (org-get-at-bol 'org-marker))
  6486. (org-in-regexp org-bracket-link-regexp))
  6487. (org-open-link-from-string (match-string 0))
  6488. (let* ((marker (or (org-get-at-bol 'org-marker)
  6489. (org-agenda-error)))
  6490. (buffer (marker-buffer marker))
  6491. (pos (marker-position marker)))
  6492. (org-pop-to-buffer-same-window buffer)
  6493. (and delete-other-windows (delete-other-windows))
  6494. (widen)
  6495. (goto-char pos)
  6496. (when (org-mode-p)
  6497. (org-show-context 'agenda)
  6498. (save-excursion
  6499. (and (outline-next-heading)
  6500. (org-flag-heading nil))) ; show the next heading
  6501. (when (outline-invisible-p)
  6502. (show-entry)))))) ; display invisible text
  6503. (defun org-agenda-goto-mouse (ev)
  6504. "Go to the Org-mode file which contains the item at the mouse click."
  6505. (interactive "e")
  6506. (mouse-set-point ev)
  6507. (org-agenda-goto))
  6508. (defun org-agenda-show (&optional full-entry)
  6509. "Display the Org-mode file which contains the item at point.
  6510. With prefix argument FULL-ENTRY, make the entire entry visible
  6511. if it was hidden in the outline."
  6512. (interactive "P")
  6513. (let ((win (selected-window)))
  6514. (if full-entry
  6515. (let ((org-show-entry-below t))
  6516. (org-agenda-goto t))
  6517. (org-agenda-goto t))
  6518. (select-window win)))
  6519. (defvar org-agenda-show-window nil)
  6520. (defun org-agenda-show-and-scroll-up ()
  6521. "Display the Org-mode file which contains the item at point.
  6522. When called repeatedly, scroll the window that is displaying the buffer."
  6523. (interactive)
  6524. (let ((win (selected-window)))
  6525. (if (and (window-live-p org-agenda-show-window)
  6526. (eq this-command last-command))
  6527. (progn
  6528. (select-window org-agenda-show-window)
  6529. (ignore-errors (scroll-up)))
  6530. (org-agenda-goto t)
  6531. (show-subtree)
  6532. (setq org-agenda-show-window (selected-window)))
  6533. (select-window win)))
  6534. (defun org-agenda-show-scroll-down ()
  6535. "Scroll down the window showing the agenda."
  6536. (interactive)
  6537. (let ((win (selected-window)))
  6538. (when (window-live-p org-agenda-show-window)
  6539. (select-window org-agenda-show-window)
  6540. (ignore-errors (scroll-down))
  6541. (select-window win))))
  6542. (defun org-agenda-show-1 (&optional more)
  6543. "Display the Org-mode file which contains the item at point.
  6544. The prefix arg selects the amount of information to display:
  6545. 0 hide the subtree
  6546. 1 just show the entry according to defaults.
  6547. 2 show the children view
  6548. 3 show the subtree view
  6549. 4 show the entire subtree and any LOGBOOK drawers
  6550. 5 show the entire subtree and any drawers
  6551. With prefix argument FULL-ENTRY, make the entire entry visible
  6552. if it was hidden in the outline."
  6553. (interactive "p")
  6554. (let ((win (selected-window)))
  6555. (org-agenda-goto t)
  6556. (org-recenter-heading 1)
  6557. (cond
  6558. ((= more 0)
  6559. (hide-subtree)
  6560. (save-excursion
  6561. (org-back-to-heading)
  6562. (run-hook-with-args 'org-cycle-hook 'folded))
  6563. (message "Remote: FOLDED"))
  6564. ((and (org-called-interactively-p 'any) (= more 1))
  6565. (message "Remote: show with default settings"))
  6566. ((= more 2)
  6567. (show-entry)
  6568. (show-children)
  6569. (save-excursion
  6570. (org-back-to-heading)
  6571. (run-hook-with-args 'org-cycle-hook 'children))
  6572. (message "Remote: CHILDREN"))
  6573. ((= more 3)
  6574. (show-subtree)
  6575. (save-excursion
  6576. (org-back-to-heading)
  6577. (run-hook-with-args 'org-cycle-hook 'subtree))
  6578. (message "Remote: SUBTREE"))
  6579. ((= more 4)
  6580. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6581. (org-drawer-regexp
  6582. (concat "^[ \t]*:\\("
  6583. (mapconcat 'regexp-quote org-drawers "\\|")
  6584. "\\):[ \t]*$")))
  6585. (show-subtree)
  6586. (save-excursion
  6587. (org-back-to-heading)
  6588. (org-cycle-hide-drawers 'subtree)))
  6589. (message "Remote: SUBTREE AND LOGBOOK"))
  6590. ((> more 4)
  6591. (show-subtree)
  6592. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6593. (select-window win)))
  6594. (defun org-recenter-heading (n)
  6595. (save-excursion
  6596. (org-back-to-heading)
  6597. (recenter n)))
  6598. (defvar org-agenda-cycle-counter nil)
  6599. (defun org-agenda-cycle-show (&optional n)
  6600. "Show the current entry in another window, with default settings.
  6601. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6602. When use repeatedly in immediate succession, the remote entry will cycle
  6603. through visibility
  6604. children -> subtree -> folded
  6605. When called with a numeric prefix arg, that arg will be passed through to
  6606. `org-agenda-show-1'. For the interpretation of that argument, see the
  6607. docstring of `org-agenda-show-1'."
  6608. (interactive "P")
  6609. (if (integerp n)
  6610. (setq org-agenda-cycle-counter n)
  6611. (if (not (eq last-command this-command))
  6612. (setq org-agenda-cycle-counter 1)
  6613. (if (equal org-agenda-cycle-counter 0)
  6614. (setq org-agenda-cycle-counter 2)
  6615. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6616. (if (> org-agenda-cycle-counter 3)
  6617. (setq org-agenda-cycle-counter 0)))))
  6618. (org-agenda-show-1 org-agenda-cycle-counter))
  6619. (defun org-agenda-recenter (arg)
  6620. "Display the Org-mode file which contains the item at point and recenter."
  6621. (interactive "P")
  6622. (let ((win (selected-window)))
  6623. (org-agenda-goto t)
  6624. (recenter arg)
  6625. (select-window win)))
  6626. (defun org-agenda-show-mouse (ev)
  6627. "Display the Org-mode file which contains the item at the mouse click."
  6628. (interactive "e")
  6629. (mouse-set-point ev)
  6630. (org-agenda-show))
  6631. (defun org-agenda-check-no-diary ()
  6632. "Check if the entry is a diary link and abort if yes."
  6633. (if (org-get-at-bol 'org-agenda-diary-link)
  6634. (org-agenda-error)))
  6635. (defun org-agenda-error ()
  6636. (error "Command not allowed in this line"))
  6637. (defun org-agenda-tree-to-indirect-buffer ()
  6638. "Show the subtree corresponding to the current entry in an indirect buffer.
  6639. This calls the command `org-tree-to-indirect-buffer' from the original
  6640. Org-mode buffer.
  6641. With numerical prefix arg ARG, go up to this level and then take that tree.
  6642. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6643. use the dedicated frame)."
  6644. (interactive)
  6645. (org-agenda-check-no-diary)
  6646. (let* ((marker (or (org-get-at-bol 'org-marker)
  6647. (org-agenda-error)))
  6648. (buffer (marker-buffer marker))
  6649. (pos (marker-position marker)))
  6650. (with-current-buffer buffer
  6651. (save-excursion
  6652. (goto-char pos)
  6653. (call-interactively 'org-tree-to-indirect-buffer)))))
  6654. (defvar org-last-heading-marker (make-marker)
  6655. "Marker pointing to the headline that last changed its TODO state
  6656. by a remote command from the agenda.")
  6657. (defun org-agenda-todo-nextset ()
  6658. "Switch TODO entry to next sequence."
  6659. (interactive)
  6660. (org-agenda-todo 'nextset))
  6661. (defun org-agenda-todo-previousset ()
  6662. "Switch TODO entry to previous sequence."
  6663. (interactive)
  6664. (org-agenda-todo 'previousset))
  6665. (defun org-agenda-todo (&optional arg)
  6666. "Cycle TODO state of line at point, also in Org-mode file.
  6667. This changes the line at point, all other lines in the agenda referring to
  6668. the same tree node, and the headline of the tree node in the Org-mode file."
  6669. (interactive "P")
  6670. (org-agenda-check-no-diary)
  6671. (let* ((col (current-column))
  6672. (marker (or (org-get-at-bol 'org-marker)
  6673. (org-agenda-error)))
  6674. (buffer (marker-buffer marker))
  6675. (pos (marker-position marker))
  6676. (hdmarker (org-get-at-bol 'org-hd-marker))
  6677. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6678. (inhibit-read-only t)
  6679. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6680. (org-with-remote-undo buffer
  6681. (with-current-buffer buffer
  6682. (widen)
  6683. (goto-char pos)
  6684. (org-show-context 'agenda)
  6685. (save-excursion
  6686. (and (outline-next-heading)
  6687. (org-flag-heading nil))) ; show the next heading
  6688. (let ((current-prefix-arg arg))
  6689. (call-interactively 'org-todo))
  6690. (and (bolp) (forward-char 1))
  6691. (setq newhead (org-get-heading))
  6692. (when (and (org-bound-and-true-p
  6693. org-agenda-headline-snapshot-before-repeat)
  6694. (not (equal org-agenda-headline-snapshot-before-repeat
  6695. newhead))
  6696. todayp)
  6697. (setq newhead org-agenda-headline-snapshot-before-repeat
  6698. just-one t))
  6699. (save-excursion
  6700. (org-back-to-heading)
  6701. (move-marker org-last-heading-marker (point))))
  6702. (beginning-of-line 1)
  6703. (save-excursion
  6704. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6705. (org-move-to-column col))))
  6706. (defun org-agenda-add-note (&optional arg)
  6707. "Add a time-stamped note to the entry at point."
  6708. (interactive "P")
  6709. (org-agenda-check-no-diary)
  6710. (let* ((marker (or (org-get-at-bol 'org-marker)
  6711. (org-agenda-error)))
  6712. (buffer (marker-buffer marker))
  6713. (pos (marker-position marker))
  6714. (hdmarker (org-get-at-bol 'org-hd-marker))
  6715. (inhibit-read-only t))
  6716. (with-current-buffer buffer
  6717. (widen)
  6718. (goto-char pos)
  6719. (org-show-context 'agenda)
  6720. (save-excursion
  6721. (and (outline-next-heading)
  6722. (org-flag-heading nil))) ; show the next heading
  6723. (org-add-note))))
  6724. (defun org-agenda-change-all-lines (newhead hdmarker
  6725. &optional fixface just-this)
  6726. "Change all lines in the agenda buffer which match HDMARKER.
  6727. The new content of the line will be NEWHEAD (as modified by
  6728. `org-format-agenda-item'). HDMARKER is checked with
  6729. `equal' against all `org-hd-marker' text properties in the file.
  6730. If FIXFACE is non-nil, the face of each item is modified according to
  6731. the new TODO state.
  6732. If JUST-THIS is non-nil, change just the current line, not all.
  6733. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6734. (let* ((inhibit-read-only t)
  6735. (line (org-current-line))
  6736. (thetags (with-current-buffer (marker-buffer hdmarker)
  6737. (save-excursion (save-restriction (widen)
  6738. (goto-char hdmarker)
  6739. (org-get-tags-at)))))
  6740. props m pl undone-face done-face finish new dotime cat tags)
  6741. (save-excursion
  6742. (goto-char (point-max))
  6743. (beginning-of-line 1)
  6744. (while (not finish)
  6745. (setq finish (bobp))
  6746. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6747. (or (not just-this) (= (org-current-line) line))
  6748. (equal m hdmarker))
  6749. (setq props (text-properties-at (point))
  6750. dotime (org-get-at-bol 'dotime)
  6751. cat (org-get-at-bol 'org-category)
  6752. tags thetags
  6753. new
  6754. (let ((org-prefix-format-compiled
  6755. (or (get-text-property (point) 'format)
  6756. org-prefix-format-compiled)))
  6757. (with-current-buffer (marker-buffer hdmarker)
  6758. (save-excursion
  6759. (save-restriction
  6760. (widen)
  6761. (org-format-agenda-item (org-get-at-bol 'extra)
  6762. newhead cat tags dotime)))))
  6763. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6764. undone-face (org-get-at-bol 'undone-face)
  6765. done-face (org-get-at-bol 'done-face))
  6766. (beginning-of-line 1)
  6767. (cond
  6768. ((equal new "")
  6769. (and (looking-at ".*\n?") (replace-match "")))
  6770. ((looking-at ".*")
  6771. (replace-match new t t)
  6772. (beginning-of-line 1)
  6773. (add-text-properties (point-at-bol) (point-at-eol) props)
  6774. (when fixface
  6775. (add-text-properties
  6776. (point-at-bol) (point-at-eol)
  6777. (list 'face
  6778. (if org-last-todo-state-is-todo
  6779. undone-face done-face))))
  6780. (org-agenda-highlight-todo 'line)
  6781. (beginning-of-line 1))
  6782. (t (error "Line update did not work"))))
  6783. (beginning-of-line 0)))
  6784. (org-finalize-agenda)))
  6785. (defun org-agenda-align-tags (&optional line)
  6786. "Align all tags in agenda items to `org-agenda-tags-column'."
  6787. (let ((inhibit-read-only t) l c)
  6788. (save-excursion
  6789. (goto-char (if line (point-at-bol) (point-min)))
  6790. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6791. (if line (point-at-eol) nil) t)
  6792. (add-text-properties
  6793. (match-beginning 2) (match-end 2)
  6794. (list 'face (delq nil (let ((prop (get-text-property
  6795. (match-beginning 2) 'face)))
  6796. (or (listp prop) (setq prop (list prop)))
  6797. (if (memq 'org-tag prop)
  6798. prop
  6799. (cons 'org-tag prop))))))
  6800. (setq l (- (match-end 2) (match-beginning 2))
  6801. c (if (< org-agenda-tags-column 0)
  6802. (- (abs org-agenda-tags-column) l)
  6803. org-agenda-tags-column))
  6804. (delete-region (match-beginning 1) (match-end 1))
  6805. (goto-char (match-beginning 1))
  6806. (insert (org-add-props
  6807. (make-string (max 1 (- c (current-column))) ?\ )
  6808. (plist-put (copy-sequence (text-properties-at (point)))
  6809. 'face nil))))
  6810. (goto-char (point-min))
  6811. (org-font-lock-add-tag-faces (point-max)))))
  6812. (defun org-agenda-priority-up ()
  6813. "Increase the priority of line at point, also in Org-mode file."
  6814. (interactive)
  6815. (org-agenda-priority 'up))
  6816. (defun org-agenda-priority-down ()
  6817. "Decrease the priority of line at point, also in Org-mode file."
  6818. (interactive)
  6819. (org-agenda-priority 'down))
  6820. (defun org-agenda-priority (&optional force-direction)
  6821. "Set the priority of line at point, also in Org-mode file.
  6822. This changes the line at point, all other lines in the agenda referring to
  6823. the same tree node, and the headline of the tree node in the Org-mode file."
  6824. (interactive)
  6825. (unless org-enable-priority-commands
  6826. (error "Priority commands are disabled"))
  6827. (org-agenda-check-no-diary)
  6828. (let* ((marker (or (org-get-at-bol 'org-marker)
  6829. (org-agenda-error)))
  6830. (hdmarker (org-get-at-bol 'org-hd-marker))
  6831. (buffer (marker-buffer hdmarker))
  6832. (pos (marker-position hdmarker))
  6833. (inhibit-read-only t)
  6834. newhead)
  6835. (org-with-remote-undo buffer
  6836. (with-current-buffer buffer
  6837. (widen)
  6838. (goto-char pos)
  6839. (org-show-context 'agenda)
  6840. (save-excursion
  6841. (and (outline-next-heading)
  6842. (org-flag-heading nil))) ; show the next heading
  6843. (funcall 'org-priority force-direction)
  6844. (end-of-line 1)
  6845. (setq newhead (org-get-heading)))
  6846. (org-agenda-change-all-lines newhead hdmarker)
  6847. (beginning-of-line 1))))
  6848. ;; FIXME: should fix the tags property of the agenda line.
  6849. (defun org-agenda-set-tags (&optional tag onoff)
  6850. "Set tags for the current headline."
  6851. (interactive)
  6852. (org-agenda-check-no-diary)
  6853. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6854. (call-interactively 'org-change-tag-in-region)
  6855. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6856. (org-agenda-error)))
  6857. (buffer (marker-buffer hdmarker))
  6858. (pos (marker-position hdmarker))
  6859. (inhibit-read-only t)
  6860. newhead)
  6861. (org-with-remote-undo buffer
  6862. (with-current-buffer buffer
  6863. (widen)
  6864. (goto-char pos)
  6865. (save-excursion
  6866. (org-show-context 'agenda))
  6867. (save-excursion
  6868. (and (outline-next-heading)
  6869. (org-flag-heading nil))) ; show the next heading
  6870. (goto-char pos)
  6871. (if tag
  6872. (org-toggle-tag tag onoff)
  6873. (call-interactively 'org-set-tags))
  6874. (end-of-line 1)
  6875. (setq newhead (org-get-heading)))
  6876. (org-agenda-change-all-lines newhead hdmarker)
  6877. (beginning-of-line 1)))))
  6878. (defun org-agenda-set-property ()
  6879. "Set a property for the current headline."
  6880. (interactive)
  6881. (org-agenda-check-no-diary)
  6882. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6883. (org-agenda-error)))
  6884. (buffer (marker-buffer hdmarker))
  6885. (pos (marker-position hdmarker))
  6886. (inhibit-read-only t)
  6887. newhead)
  6888. (org-with-remote-undo buffer
  6889. (with-current-buffer buffer
  6890. (widen)
  6891. (goto-char pos)
  6892. (save-excursion
  6893. (org-show-context 'agenda))
  6894. (save-excursion
  6895. (and (outline-next-heading)
  6896. (org-flag-heading nil))) ; show the next heading
  6897. (goto-char pos)
  6898. (call-interactively 'org-set-property)))))
  6899. (defun org-agenda-set-effort ()
  6900. "Set the effort property for the current headline."
  6901. (interactive)
  6902. (org-agenda-check-no-diary)
  6903. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6904. (org-agenda-error)))
  6905. (buffer (marker-buffer hdmarker))
  6906. (pos (marker-position hdmarker))
  6907. (inhibit-read-only t)
  6908. newhead)
  6909. (org-with-remote-undo buffer
  6910. (with-current-buffer buffer
  6911. (widen)
  6912. (goto-char pos)
  6913. (save-excursion
  6914. (org-show-context 'agenda))
  6915. (save-excursion
  6916. (and (outline-next-heading)
  6917. (org-flag-heading nil))) ; show the next heading
  6918. (goto-char pos)
  6919. (call-interactively 'org-set-effort)
  6920. (end-of-line 1)
  6921. (setq newhead (org-get-heading)))
  6922. (org-agenda-change-all-lines newhead hdmarker))))
  6923. (defun org-agenda-toggle-archive-tag ()
  6924. "Toggle the archive tag for the current entry."
  6925. (interactive)
  6926. (org-agenda-check-no-diary)
  6927. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6928. (org-agenda-error)))
  6929. (buffer (marker-buffer hdmarker))
  6930. (pos (marker-position hdmarker))
  6931. (inhibit-read-only t)
  6932. newhead)
  6933. (org-with-remote-undo buffer
  6934. (with-current-buffer buffer
  6935. (widen)
  6936. (goto-char pos)
  6937. (org-show-context 'agenda)
  6938. (save-excursion
  6939. (and (outline-next-heading)
  6940. (org-flag-heading nil))) ; show the next heading
  6941. (call-interactively 'org-toggle-archive-tag)
  6942. (end-of-line 1)
  6943. (setq newhead (org-get-heading)))
  6944. (org-agenda-change-all-lines newhead hdmarker)
  6945. (beginning-of-line 1))))
  6946. (defun org-agenda-do-date-later (arg)
  6947. (interactive "P")
  6948. (cond
  6949. ((or (equal arg '(16))
  6950. (memq last-command
  6951. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6952. (setq this-command 'org-agenda-date-later-minutes)
  6953. (org-agenda-date-later-minutes 1))
  6954. ((or (equal arg '(4))
  6955. (memq last-command
  6956. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6957. (setq this-command 'org-agenda-date-later-hours)
  6958. (org-agenda-date-later-hours 1))
  6959. (t
  6960. (org-agenda-date-later (prefix-numeric-value arg)))))
  6961. (defun org-agenda-do-date-earlier (arg)
  6962. (interactive "P")
  6963. (cond
  6964. ((or (equal arg '(16))
  6965. (memq last-command
  6966. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6967. (setq this-command 'org-agenda-date-earlier-minutes)
  6968. (org-agenda-date-earlier-minutes 1))
  6969. ((or (equal arg '(4))
  6970. (memq last-command
  6971. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6972. (setq this-command 'org-agenda-date-earlier-hours)
  6973. (org-agenda-date-earlier-hours 1))
  6974. (t
  6975. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6976. (defun org-agenda-date-later (arg &optional what)
  6977. "Change the date of this item to ARG day(s) later."
  6978. (interactive "p")
  6979. (org-agenda-check-type t 'agenda 'timeline)
  6980. (org-agenda-check-no-diary)
  6981. (let* ((marker (or (org-get-at-bol 'org-marker)
  6982. (org-agenda-error)))
  6983. (buffer (marker-buffer marker))
  6984. (pos (marker-position marker)))
  6985. (org-with-remote-undo buffer
  6986. (with-current-buffer buffer
  6987. (widen)
  6988. (goto-char pos)
  6989. (if (not (org-at-timestamp-p))
  6990. (error "Cannot find time stamp"))
  6991. (org-timestamp-change arg (or what 'day)))
  6992. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6993. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6994. (defun org-agenda-date-earlier (arg &optional what)
  6995. "Change the date of this item to ARG day(s) earlier."
  6996. (interactive "p")
  6997. (org-agenda-date-later (- arg) what))
  6998. (defun org-agenda-date-later-minutes (arg)
  6999. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7000. (interactive "p")
  7001. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7002. (org-agenda-date-later arg 'minute))
  7003. (defun org-agenda-date-earlier-minutes (arg)
  7004. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7005. (interactive "p")
  7006. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7007. (org-agenda-date-earlier arg 'minute))
  7008. (defun org-agenda-date-later-hours (arg)
  7009. "Change the time of this item, in hour steps."
  7010. (interactive "p")
  7011. (org-agenda-date-later arg 'hour))
  7012. (defun org-agenda-date-earlier-hours (arg)
  7013. "Change the time of this item, in hour steps."
  7014. (interactive "p")
  7015. (org-agenda-date-earlier arg 'hour))
  7016. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7017. "Show new date stamp via text properties."
  7018. ;; We use text properties to make this undoable
  7019. (let ((inhibit-read-only t)
  7020. (buffer-invisibility-spec))
  7021. (setq stamp (concat " " prefix " => " stamp))
  7022. (save-excursion
  7023. (goto-char (point-max))
  7024. (while (not (bobp))
  7025. (when (equal marker (org-get-at-bol 'org-marker))
  7026. (org-move-to-column (- (window-width) (length stamp)) t)
  7027. (org-agenda-fix-tags-filter-overlays-at (point))
  7028. (if (featurep 'xemacs)
  7029. ;; Use `duplicable' property to trigger undo recording
  7030. (let ((ex (make-extent nil nil))
  7031. (gl (make-glyph stamp)))
  7032. (set-glyph-face gl 'secondary-selection)
  7033. (set-extent-properties
  7034. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7035. (insert-extent ex (1- (point)) (point-at-eol)))
  7036. (add-text-properties
  7037. (1- (point)) (point-at-eol)
  7038. (list 'display (org-add-props stamp nil
  7039. 'face 'secondary-selection))))
  7040. (beginning-of-line 1))
  7041. (beginning-of-line 0)))))
  7042. (defun org-agenda-date-prompt (arg)
  7043. "Change the date of this item. Date is prompted for, with default today.
  7044. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7045. be used to request time specification in the time stamp."
  7046. (interactive "P")
  7047. (org-agenda-check-type t 'agenda 'timeline)
  7048. (org-agenda-check-no-diary)
  7049. (let* ((marker (or (org-get-at-bol 'org-marker)
  7050. (org-agenda-error)))
  7051. (buffer (marker-buffer marker))
  7052. (pos (marker-position marker)))
  7053. (org-with-remote-undo buffer
  7054. (with-current-buffer buffer
  7055. (widen)
  7056. (goto-char pos)
  7057. (if (not (org-at-timestamp-p t))
  7058. (error "Cannot find time stamp"))
  7059. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7060. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7061. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7062. (defun org-agenda-schedule (arg &optional time)
  7063. "Schedule the item at point.
  7064. ARG is passed through to `org-schedule'."
  7065. (interactive "P")
  7066. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7067. (org-agenda-check-no-diary)
  7068. (let* ((marker (or (org-get-at-bol 'org-marker)
  7069. (org-agenda-error)))
  7070. (type (marker-insertion-type marker))
  7071. (buffer (marker-buffer marker))
  7072. (pos (marker-position marker))
  7073. (org-insert-labeled-timestamps-at-point nil)
  7074. ts)
  7075. (set-marker-insertion-type marker t)
  7076. (org-with-remote-undo buffer
  7077. (with-current-buffer buffer
  7078. (widen)
  7079. (goto-char pos)
  7080. (setq ts (org-schedule arg time)))
  7081. (org-agenda-show-new-time marker ts "S"))
  7082. (message "Item scheduled for %s" ts)))
  7083. (defun org-agenda-deadline (arg &optional time)
  7084. "Schedule the item at point.
  7085. ARG is passed through to `org-deadline'."
  7086. (interactive "P")
  7087. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7088. (org-agenda-check-no-diary)
  7089. (let* ((marker (or (org-get-at-bol 'org-marker)
  7090. (org-agenda-error)))
  7091. (buffer (marker-buffer marker))
  7092. (pos (marker-position marker))
  7093. (org-insert-labeled-timestamps-at-point nil)
  7094. ts)
  7095. (org-with-remote-undo buffer
  7096. (with-current-buffer buffer
  7097. (widen)
  7098. (goto-char pos)
  7099. (setq ts (org-deadline arg time)))
  7100. (org-agenda-show-new-time marker ts "D"))
  7101. (message "Deadline for this item set to %s" ts)))
  7102. (defun org-agenda-action ()
  7103. "Select entry for agenda action, or execute an agenda action.
  7104. This command prompts for another letter. Valid inputs are:
  7105. m Mark the entry at point for an agenda action
  7106. s Schedule the marked entry to the date at the cursor
  7107. d Set the deadline of the marked entry to the date at the cursor
  7108. r Call `org-remember' with cursor date as the default date
  7109. c Call `org-capture' with cursor date as the default date
  7110. SPC Show marked entry in other window
  7111. TAB Visit marked entry in other window
  7112. The cursor may be at a date in the calendar, or in the Org agenda."
  7113. (interactive)
  7114. (let (ans)
  7115. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7116. (setq ans (read-char-exclusive))
  7117. (cond
  7118. ((equal ans ?m)
  7119. ;; Mark this entry
  7120. (if (eq major-mode 'org-agenda-mode)
  7121. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7122. (org-get-at-bol 'org-marker))))
  7123. (if m
  7124. (progn
  7125. (move-marker org-agenda-action-marker
  7126. (marker-position m) (marker-buffer m))
  7127. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7128. (error "Don't know which entry to mark")))
  7129. (error "This command works only in the agenda")))
  7130. ((equal ans ?s)
  7131. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7132. ((equal ans ?d)
  7133. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7134. ((equal ans ?r)
  7135. (org-agenda-do-action '(org-remember) t))
  7136. ((equal ans ?c)
  7137. (org-agenda-do-action '(org-capture) t))
  7138. ((equal ans ?\ )
  7139. (let ((cw (selected-window)))
  7140. (org-switch-to-buffer-other-window
  7141. (marker-buffer org-agenda-action-marker))
  7142. (goto-char org-agenda-action-marker)
  7143. (org-show-context 'agenda)
  7144. (select-window cw)))
  7145. ((equal ans ?\C-i)
  7146. (org-switch-to-buffer-other-window
  7147. (marker-buffer org-agenda-action-marker))
  7148. (goto-char org-agenda-action-marker)
  7149. (org-show-context 'agenda))
  7150. (t (error "Invalid agenda action %c" ans)))))
  7151. (defun org-agenda-do-action (form &optional current-buffer)
  7152. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7153. (let ((org-overriding-default-time (org-get-cursor-date)))
  7154. (if current-buffer
  7155. (eval form)
  7156. (if (not (marker-buffer org-agenda-action-marker))
  7157. (error "No entry has been selected for agenda action")
  7158. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7159. (save-excursion
  7160. (save-restriction
  7161. (widen)
  7162. (goto-char org-agenda-action-marker)
  7163. (eval form))))))))
  7164. (defun org-agenda-clock-in (&optional arg)
  7165. "Start the clock on the currently selected item."
  7166. (interactive "P")
  7167. (org-agenda-check-no-diary)
  7168. (if (equal arg '(4))
  7169. (org-clock-in arg)
  7170. (let* ((marker (or (org-get-at-bol 'org-marker)
  7171. (org-agenda-error)))
  7172. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7173. marker))
  7174. (pos (marker-position marker))
  7175. newhead)
  7176. (org-with-remote-undo (marker-buffer marker)
  7177. (with-current-buffer (marker-buffer marker)
  7178. (widen)
  7179. (goto-char pos)
  7180. (org-show-context 'agenda)
  7181. (org-show-entry)
  7182. (org-cycle-hide-drawers 'children)
  7183. (org-clock-in arg)
  7184. (setq newhead (org-get-heading)))
  7185. (org-agenda-change-all-lines newhead hdmarker)))))
  7186. (defun org-agenda-clock-out ()
  7187. "Stop the currently running clock."
  7188. (interactive)
  7189. (unless (marker-buffer org-clock-marker)
  7190. (error "No running clock"))
  7191. (let ((marker (make-marker)) newhead)
  7192. (org-with-remote-undo (marker-buffer org-clock-marker)
  7193. (with-current-buffer (marker-buffer org-clock-marker)
  7194. (save-excursion
  7195. (save-restriction
  7196. (widen)
  7197. (goto-char org-clock-marker)
  7198. (org-back-to-heading t)
  7199. (move-marker marker (point))
  7200. (org-clock-out)
  7201. (setq newhead (org-get-heading))))))
  7202. (org-agenda-change-all-lines newhead marker)
  7203. (move-marker marker nil)))
  7204. (defun org-agenda-clock-cancel (&optional arg)
  7205. "Cancel the currently running clock."
  7206. (interactive "P")
  7207. (unless (marker-buffer org-clock-marker)
  7208. (error "No running clock"))
  7209. (org-with-remote-undo (marker-buffer org-clock-marker)
  7210. (org-clock-cancel)))
  7211. (defun org-agenda-clock-goto ()
  7212. "Jump to the currently clocked in task within the agenda.
  7213. If the currently clocked in task is not listed in the agenda
  7214. buffer, display it in another window."
  7215. (interactive)
  7216. (let (pos)
  7217. (mapc (lambda (o)
  7218. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7219. (setq pos (overlay-start o))))
  7220. (overlays-in (point-min) (point-max)))
  7221. (cond (pos (goto-char pos))
  7222. ;; If the currently clocked entry is not in the agenda
  7223. ;; buffer, we visit it in another window:
  7224. (org-clock-current-task
  7225. (org-switch-to-buffer-other-window (org-clock-goto)))
  7226. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7227. (defun org-agenda-diary-entry-in-org-file ()
  7228. "Make a diary entry in the file `org-agenda-diary-file'."
  7229. (let (d1 d2 char (text "") dp1 dp2)
  7230. (if (equal (buffer-name) "*Calendar*")
  7231. (setq d1 (calendar-cursor-to-date t)
  7232. d2 (car calendar-mark-ring))
  7233. (setq dp1 (get-text-property (point-at-bol) 'day))
  7234. (unless dp1 (error "No date defined in current line"))
  7235. (setq d1 (calendar-gregorian-from-absolute dp1)
  7236. d2 (and (ignore-errors (mark))
  7237. (save-excursion
  7238. (goto-char (mark))
  7239. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7240. (calendar-gregorian-from-absolute dp2))))
  7241. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7242. (setq char (read-char-exclusive))
  7243. (cond
  7244. ((equal char ?d)
  7245. (setq text (read-string "Day entry: "))
  7246. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7247. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7248. ((equal char ?a)
  7249. (setq d1 (list (car d1) (nth 1 d1)
  7250. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7251. (nth 2 d1))))
  7252. (setq text (read-string "Anniversary (use %d to show years): "))
  7253. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7254. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7255. ((equal char ?b)
  7256. (setq text (read-string "Block entry: "))
  7257. (unless (and d1 d2 (not (equal d1 d2)))
  7258. (error "No block of days selected"))
  7259. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7260. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7261. ((equal char ?j)
  7262. (org-switch-to-buffer-other-window
  7263. (find-file-noselect org-agenda-diary-file))
  7264. (require 'org-datetree)
  7265. (org-datetree-find-date-create d1)
  7266. (org-reveal t))
  7267. (t (error "Invalid selection character `%c'" char)))))
  7268. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7269. "Where in `org-agenda-diary-file' should new entries be added?
  7270. Valid values:
  7271. date-tree in the date tree, as child of the date
  7272. top-level as top-level entries at the end of the file."
  7273. :group 'org-agenda
  7274. :type '(choice
  7275. (const :tag "in a date tree" date-tree)
  7276. (const :tag "as top level at end of file" top-level)))
  7277. (defcustom org-agenda-insert-diary-extract-time nil
  7278. "Non-nil means extract any time specification from the diary entry."
  7279. :group 'org-agenda
  7280. :type 'boolean)
  7281. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7282. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7283. If TEXT is not empty, it will become the headline of the new entry, and
  7284. the resulting entry will not be shown. When TEXT is empty, switch to
  7285. `org-agenda-diary-file' and let the user finish the entry there."
  7286. (let ((cw (current-window-configuration)))
  7287. (org-switch-to-buffer-other-window
  7288. (find-file-noselect org-agenda-diary-file))
  7289. (widen)
  7290. (goto-char (point-min))
  7291. (cond
  7292. ((eq type 'anniversary)
  7293. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7294. (progn
  7295. (or (org-on-heading-p t)
  7296. (progn
  7297. (outline-next-heading)
  7298. (insert "* Anniversaries\n\n")
  7299. (beginning-of-line -1)))))
  7300. (outline-next-heading)
  7301. (org-back-over-empty-lines)
  7302. (backward-char 1)
  7303. (insert "\n")
  7304. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7305. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7306. ((eq type 'day)
  7307. (let ((org-prefix-has-time t)
  7308. (org-agenda-time-leading-zero t)
  7309. fmt time time2)
  7310. (if org-agenda-insert-diary-extract-time
  7311. ;; Use org-format-agenda-item to parse text for a time-range and
  7312. ;; remove it. FIXME: This is a hack, we should refactor
  7313. ;; that function to make time extraction available separately
  7314. (setq fmt (org-format-agenda-item nil text nil nil t)
  7315. time (get-text-property 0 'time fmt)
  7316. time2 (if (> (length time) 0)
  7317. ;; split-string removes trailing ...... if
  7318. ;; no end time given. First space
  7319. ;; separates time from date.
  7320. (concat " " (car (split-string time "\\.")))
  7321. nil)
  7322. text (get-text-property 0 'txt fmt)))
  7323. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7324. (org-agenda-insert-diary-as-top-level text)
  7325. (require 'org-datetree)
  7326. (org-datetree-find-date-create d1)
  7327. (org-agenda-insert-diary-make-new-entry text))
  7328. (org-insert-time-stamp (org-time-from-absolute
  7329. (calendar-absolute-from-gregorian d1))
  7330. nil nil nil nil time2))
  7331. (end-of-line 0))
  7332. ((eq type 'block)
  7333. (if (> (calendar-absolute-from-gregorian d1)
  7334. (calendar-absolute-from-gregorian d2))
  7335. (setq d1 (prog1 d2 (setq d2 d1))))
  7336. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7337. (org-agenda-insert-diary-as-top-level text)
  7338. (require 'org-datetree)
  7339. (org-datetree-find-date-create d1)
  7340. (org-agenda-insert-diary-make-new-entry text))
  7341. (org-insert-time-stamp (org-time-from-absolute
  7342. (calendar-absolute-from-gregorian d1)))
  7343. (insert "--")
  7344. (org-insert-time-stamp (org-time-from-absolute
  7345. (calendar-absolute-from-gregorian d2)))
  7346. (end-of-line 0)))
  7347. (if (string-match "\\S-" text)
  7348. (progn
  7349. (set-window-configuration cw)
  7350. (message "%s entry added to %s"
  7351. (capitalize (symbol-name type))
  7352. (abbreviate-file-name org-agenda-diary-file)))
  7353. (org-reveal t)
  7354. (message "Please finish entry here"))))
  7355. (defun org-agenda-insert-diary-as-top-level (text)
  7356. "Make new entry as a top-level entry at the end of the file.
  7357. Add TEXT as headline, and position the cursor in the second line so that
  7358. a timestamp can be added there."
  7359. (widen)
  7360. (goto-char (point-max))
  7361. (or (bolp) (insert "\n"))
  7362. (insert "* " text "\n")
  7363. (if org-adapt-indentation (org-indent-to-column 2)))
  7364. (defun org-agenda-insert-diary-make-new-entry (text)
  7365. "Make new entry as last child of current entry.
  7366. Add TEXT as headline, and position the cursor in the second line so that
  7367. a timestamp can be added there."
  7368. (let ((org-show-following-heading t)
  7369. (org-show-siblings t)
  7370. (org-show-hierarchy-above t)
  7371. (org-show-entry-below t)
  7372. col)
  7373. (outline-next-heading)
  7374. (org-back-over-empty-lines)
  7375. (or (looking-at "[ \t]*$")
  7376. (progn (insert "\n") (backward-char 1)))
  7377. (org-insert-heading nil t)
  7378. (org-do-demote)
  7379. (setq col (current-column))
  7380. (insert text "\n")
  7381. (if org-adapt-indentation (org-indent-to-column col))
  7382. (let ((org-show-following-heading t)
  7383. (org-show-siblings t)
  7384. (org-show-hierarchy-above t)
  7385. (org-show-entry-below t))
  7386. (org-show-context))))
  7387. (defun org-agenda-diary-entry ()
  7388. "Make a diary entry, like the `i' command from the calendar.
  7389. All the standard commands work: block, weekly etc.
  7390. When `org-agenda-diary-file' points to a file,
  7391. `org-agenda-diary-entry-in-org-file' is called instead to create
  7392. entries in that Org-mode file."
  7393. (interactive)
  7394. (org-agenda-check-type t 'agenda 'timeline)
  7395. (if (not (eq org-agenda-diary-file 'diary-file))
  7396. (org-agenda-diary-entry-in-org-file)
  7397. (require 'diary-lib)
  7398. (let* ((char (progn
  7399. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7400. (read-char-exclusive)))
  7401. (cmd (cdr (assoc char
  7402. '((?d . insert-diary-entry)
  7403. (?w . insert-weekly-diary-entry)
  7404. (?m . insert-monthly-diary-entry)
  7405. (?y . insert-yearly-diary-entry)
  7406. (?a . insert-anniversary-diary-entry)
  7407. (?b . insert-block-diary-entry)
  7408. (?c . insert-cyclic-diary-entry)))))
  7409. (oldf (symbol-function 'calendar-cursor-to-date))
  7410. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7411. (point (point))
  7412. (mark (or (mark t) (point))))
  7413. (unless cmd
  7414. (error "No command associated with <%c>" char))
  7415. (unless (and (get-text-property point 'day)
  7416. (or (not (equal ?b char))
  7417. (get-text-property mark 'day)))
  7418. (error "Don't know which date to use for diary entry"))
  7419. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7420. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7421. (let ((calendar-mark-ring
  7422. (list (calendar-gregorian-from-absolute
  7423. (or (get-text-property mark 'day)
  7424. (get-text-property point 'day))))))
  7425. (unwind-protect
  7426. (progn
  7427. (fset 'calendar-cursor-to-date
  7428. (lambda (&optional error dummy)
  7429. (calendar-gregorian-from-absolute
  7430. (get-text-property point 'day))))
  7431. (call-interactively cmd))
  7432. (fset 'calendar-cursor-to-date oldf))))))
  7433. (defun org-agenda-execute-calendar-command (cmd)
  7434. "Execute a calendar command from the agenda, with the date associated to
  7435. the cursor position."
  7436. (org-agenda-check-type t 'agenda 'timeline)
  7437. (require 'diary-lib)
  7438. (unless (get-text-property (point) 'day)
  7439. (error "Don't know which date to use for calendar command"))
  7440. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7441. (point (point))
  7442. (date (calendar-gregorian-from-absolute
  7443. (get-text-property point 'day)))
  7444. ;; the following 2 vars are needed in the calendar
  7445. (displayed-month (car date))
  7446. (displayed-year (nth 2 date)))
  7447. (unwind-protect
  7448. (progn
  7449. (fset 'calendar-cursor-to-date
  7450. (lambda (&optional error dummy)
  7451. (calendar-gregorian-from-absolute
  7452. (get-text-property point 'day))))
  7453. (call-interactively cmd))
  7454. (fset 'calendar-cursor-to-date oldf))))
  7455. (defun org-agenda-phases-of-moon ()
  7456. "Display the phases of the moon for the 3 months around the cursor date."
  7457. (interactive)
  7458. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7459. (defun org-agenda-holidays ()
  7460. "Display the holidays for the 3 months around the cursor date."
  7461. (interactive)
  7462. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7463. (defvar calendar-longitude)
  7464. (defvar calendar-latitude)
  7465. (defvar calendar-location-name)
  7466. (defun org-agenda-sunrise-sunset (arg)
  7467. "Display sunrise and sunset for the cursor date.
  7468. Latitude and longitude can be specified with the variables
  7469. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7470. argument, latitude and longitude will be prompted for."
  7471. (interactive "P")
  7472. (require 'solar)
  7473. (let ((calendar-longitude (if arg nil calendar-longitude))
  7474. (calendar-latitude (if arg nil calendar-latitude))
  7475. (calendar-location-name
  7476. (if arg "the given coordinates" calendar-location-name)))
  7477. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7478. (defun org-agenda-goto-calendar ()
  7479. "Open the Emacs calendar with the date at the cursor."
  7480. (interactive)
  7481. (org-agenda-check-type t 'agenda 'timeline)
  7482. (let* ((day (or (get-text-property (point) 'day)
  7483. (error "Don't know which date to open in calendar")))
  7484. (date (calendar-gregorian-from-absolute day))
  7485. (calendar-move-hook nil)
  7486. (calendar-view-holidays-initially-flag nil)
  7487. (calendar-view-diary-initially-flag nil))
  7488. (calendar)
  7489. (calendar-goto-date date)))
  7490. ;;;###autoload
  7491. (defun org-calendar-goto-agenda ()
  7492. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7493. This is a command that has to be installed in `calendar-mode-map'."
  7494. (interactive)
  7495. (org-agenda-list nil (calendar-absolute-from-gregorian
  7496. (calendar-cursor-to-date))
  7497. nil))
  7498. (defun org-agenda-convert-date ()
  7499. (interactive)
  7500. (org-agenda-check-type t 'agenda 'timeline)
  7501. (let ((day (get-text-property (point) 'day))
  7502. date s)
  7503. (unless day
  7504. (error "Don't know which date to convert"))
  7505. (setq date (calendar-gregorian-from-absolute day))
  7506. (setq s (concat
  7507. "Gregorian: " (calendar-date-string date) "\n"
  7508. "ISO: " (calendar-iso-date-string date) "\n"
  7509. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7510. "Julian: " (calendar-julian-date-string date) "\n"
  7511. "Astron. JD: " (calendar-astro-date-string date)
  7512. " (Julian date number at noon UTC)\n"
  7513. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7514. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7515. "French: " (calendar-french-date-string date) "\n"
  7516. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7517. "Mayan: " (calendar-mayan-date-string date) "\n"
  7518. "Coptic: " (calendar-coptic-date-string date) "\n"
  7519. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7520. "Persian: " (calendar-persian-date-string date) "\n"
  7521. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7522. (with-output-to-temp-buffer "*Dates*"
  7523. (princ s))
  7524. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7525. ;;; Bulk commands
  7526. (defvar org-agenda-bulk-marked-entries nil
  7527. "List of markers that refer to marked entries in the agenda.")
  7528. (defun org-agenda-bulk-marked-p ()
  7529. (eq (get-char-property (point-at-bol) 'type)
  7530. 'org-marked-entry-overlay))
  7531. (defun org-agenda-bulk-mark (&optional arg)
  7532. "Mark the entry at point for future bulk action."
  7533. (interactive "p")
  7534. (dotimes (i (max arg 1))
  7535. (unless (org-get-at-bol 'org-agenda-diary-link)
  7536. (let* ((m (org-get-at-bol 'org-hd-marker))
  7537. ov)
  7538. (unless (org-agenda-bulk-marked-p)
  7539. (unless m (error "Nothing to mark at point"))
  7540. (push m org-agenda-bulk-marked-entries)
  7541. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7542. (org-overlay-display ov "> "
  7543. (org-get-todo-face "TODO")
  7544. 'evaporate)
  7545. (overlay-put ov 'type 'org-marked-entry-overlay))
  7546. (beginning-of-line 2)
  7547. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7548. (beginning-of-line 2))
  7549. (message "%d entries marked for bulk action"
  7550. (length org-agenda-bulk-marked-entries))))))
  7551. (defun org-agenda-bulk-mark-regexp (regexp)
  7552. "Mark entries match REGEXP."
  7553. (interactive "sMark entries matching regexp: ")
  7554. (let (entries-marked)
  7555. (save-excursion
  7556. (goto-char (point-min))
  7557. (goto-char (next-single-property-change (point) 'txt))
  7558. (while (re-search-forward regexp nil t)
  7559. (when (string-match regexp (get-text-property (point) 'txt))
  7560. (setq entries-marked (+ entries-marked 1))
  7561. (call-interactively 'org-agenda-bulk-mark))))
  7562. (if (not entries-marked)
  7563. (message "No entry matching this regexp."))))
  7564. (defun org-agenda-bulk-unmark ()
  7565. "Unmark the entry at point for future bulk action."
  7566. (interactive)
  7567. (when (org-agenda-bulk-marked-p)
  7568. (org-agenda-bulk-remove-overlays
  7569. (point-at-bol) (+ 2 (point-at-bol)))
  7570. (setq org-agenda-bulk-marked-entries
  7571. (delete (org-get-at-bol 'org-hd-marker)
  7572. org-agenda-bulk-marked-entries)))
  7573. (beginning-of-line 2)
  7574. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7575. (beginning-of-line 2))
  7576. (message "%d entries marked for bulk action"
  7577. (length org-agenda-bulk-marked-entries)))
  7578. (defun org-agenda-bulk-toggle ()
  7579. "Toggle marking the entry at point for bulk action."
  7580. (interactive)
  7581. (if (org-agenda-bulk-marked-p)
  7582. (org-agenda-bulk-unmark)
  7583. (org-agenda-bulk-mark)))
  7584. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7585. "Remove the mark overlays between BEG and END in the agenda buffer.
  7586. BEG and END default to the buffer limits.
  7587. This only removes the overlays, it does not remove the markers
  7588. from the list in `org-agenda-bulk-marked-entries'."
  7589. (interactive)
  7590. (mapc (lambda (ov)
  7591. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7592. (delete-overlay ov)))
  7593. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7594. (defun org-agenda-bulk-remove-all-marks ()
  7595. "Remove all marks in the agenda buffer.
  7596. This will remove the markers, and the overlays."
  7597. (interactive)
  7598. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7599. (setq org-agenda-bulk-marked-entries nil)
  7600. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7601. (defun org-agenda-bulk-action (&optional arg)
  7602. "Execute an remote-editing action on all marked entries.
  7603. The prefix arg is passed through to the command if possible."
  7604. (interactive "P")
  7605. ;; Make sure we have markers, and only valid ones
  7606. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7607. (mapc
  7608. (lambda (m)
  7609. (unless (and (markerp m)
  7610. (marker-buffer m)
  7611. (buffer-live-p (marker-buffer m))
  7612. (marker-position m))
  7613. (error "Marker %s for bulk command is invalid" m)))
  7614. org-agenda-bulk-marked-entries)
  7615. ;; Prompt for the bulk command
  7616. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7617. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7618. (when org-agenda-bulk-custom-functions
  7619. (concat " Custom: ["
  7620. (mapconcat (lambda(f) (char-to-string (car f)))
  7621. org-agenda-bulk-custom-functions "")
  7622. "]"))))
  7623. (let* ((action (read-char-exclusive))
  7624. (org-log-refile (if org-log-refile 'time nil))
  7625. (entries (reverse org-agenda-bulk-marked-entries))
  7626. redo-at-end
  7627. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7628. (cond
  7629. ((equal action ?$)
  7630. (setq cmd '(org-agenda-archive)))
  7631. ((equal action ?A)
  7632. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7633. ((member action '(?r ?w))
  7634. (setq rfloc (org-refile-get-location
  7635. "Refile to"
  7636. (marker-buffer (car org-agenda-bulk-marked-entries))
  7637. org-refile-allow-creating-parent-nodes))
  7638. (if (nth 3 rfloc)
  7639. (setcar (nthcdr 3 rfloc)
  7640. (move-marker (make-marker) (nth 3 rfloc)
  7641. (or (get-file-buffer (nth 1 rfloc))
  7642. (find-buffer-visiting (nth 1 rfloc))
  7643. (error "This should not happen")))))
  7644. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7645. redo-at-end t))
  7646. ((equal action ?t)
  7647. (setq state (org-icompleting-read
  7648. "Todo state: "
  7649. (with-current-buffer (marker-buffer (car entries))
  7650. (mapcar 'list org-todo-keywords-1))))
  7651. (setq cmd `(let ((org-inhibit-blocking t)
  7652. (org-inhibit-logging 'note))
  7653. (org-agenda-todo ,state))))
  7654. ((memq action '(?- ?+))
  7655. (setq tag (org-icompleting-read
  7656. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7657. (with-current-buffer (marker-buffer (car entries))
  7658. (delq nil
  7659. (mapcar (lambda (x)
  7660. (if (stringp (car x)) x)) org-tag-alist)))))
  7661. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7662. ((memq action '(?s ?d))
  7663. (let* ((date (unless arg
  7664. (org-read-date
  7665. nil nil nil
  7666. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7667. (ans (if arg nil org-read-date-final-answer))
  7668. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7669. (setq cmd `(let* ((bound (fboundp 'read-string))
  7670. (old (and bound (symbol-function 'read-string))))
  7671. (unwind-protect
  7672. (progn
  7673. (fset 'read-string (lambda (&rest ignore) ,ans))
  7674. (eval '(,c1 arg)))
  7675. (if bound
  7676. (fset 'read-string old)
  7677. (fmakunbound 'read-string)))))))
  7678. ((equal action ?S)
  7679. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7680. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7681. (let ((days (read-number
  7682. (format "Scatter tasks across how many %sdays: "
  7683. (if arg "week" "")) 7)))
  7684. (setq cmd
  7685. `(let ((distance (1+ (random ,days))))
  7686. (if arg
  7687. (let ((dist distance)
  7688. (day-of-week
  7689. (calendar-day-of-week
  7690. (calendar-gregorian-from-absolute (org-today)))))
  7691. (dotimes (i (1+ dist))
  7692. (while (member day-of-week org-agenda-weekend-days)
  7693. (incf distance)
  7694. (incf day-of-week)
  7695. (if (= day-of-week 7)
  7696. (setq day-of-week 0)))
  7697. (incf day-of-week)
  7698. (if (= day-of-week 7)
  7699. (setq day-of-week 0)))))
  7700. ;; silently fail when try to replan a sexp entry
  7701. (condition-case nil
  7702. (let* ((date (calendar-gregorian-from-absolute
  7703. (+ (org-today) distance)))
  7704. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7705. (nth 2 date))))
  7706. (org-agenda-schedule nil time))
  7707. (error nil)))))))
  7708. ((assoc action org-agenda-bulk-custom-functions)
  7709. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7710. redo-at-end t))
  7711. ((equal action ?f)
  7712. (setq cmd (list (intern
  7713. (org-icompleting-read "Function: "
  7714. obarray 'fboundp t nil nil)))))
  7715. (t (error "Invalid bulk action")))
  7716. ;; Sort the markers, to make sure that parents are handled before children
  7717. (setq entries (sort entries
  7718. (lambda (a b)
  7719. (cond
  7720. ((equal (marker-buffer a) (marker-buffer b))
  7721. (< (marker-position a) (marker-position b)))
  7722. (t
  7723. (string< (buffer-name (marker-buffer a))
  7724. (buffer-name (marker-buffer b))))))))
  7725. ;; Now loop over all markers and apply cmd
  7726. (while (setq e (pop entries))
  7727. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7728. (if (not pos)
  7729. (progn (message "Skipping removed entry at %s" e)
  7730. (setq cntskip (1+ cntskip)))
  7731. (goto-char pos)
  7732. (eval cmd)
  7733. (setq org-agenda-bulk-marked-entries
  7734. (delete e org-agenda-bulk-marked-entries))
  7735. (setq cnt (1+ cnt))))
  7736. (setq org-agenda-bulk-marked-entries nil)
  7737. (org-agenda-bulk-remove-all-marks)
  7738. (when redo-at-end (org-agenda-redo))
  7739. (message "Acted on %d entries%s"
  7740. cnt
  7741. (if (= cntskip 0)
  7742. ""
  7743. (format ", skipped %d (disappeared before their turn)"
  7744. cntskip)))))
  7745. ;;; Flagging notes
  7746. (defun org-agenda-show-the-flagging-note ()
  7747. "Display the flagging note in the other window.
  7748. When called a second time in direct sequence, offer to remove the FLAGGING
  7749. tag and (if present) the flagging note."
  7750. (interactive)
  7751. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7752. (win (selected-window))
  7753. note heading newhead)
  7754. (unless hdmarker
  7755. (error "No linked entry at point"))
  7756. (if (and (eq this-command last-command)
  7757. (y-or-n-p "Unflag and remove any flagging note? "))
  7758. (progn
  7759. (org-agenda-remove-flag hdmarker)
  7760. (let ((win (get-buffer-window "*Flagging Note*")))
  7761. (and win (delete-window win)))
  7762. (message "Entry unflaged"))
  7763. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7764. (unless note
  7765. (error "No flagging note"))
  7766. (org-kill-new note)
  7767. (org-switch-to-buffer-other-window "*Flagging Note*")
  7768. (erase-buffer)
  7769. (insert note)
  7770. (goto-char (point-min))
  7771. (while (re-search-forward "\\\\n" nil t)
  7772. (replace-match "\n" t t))
  7773. (goto-char (point-min))
  7774. (select-window win)
  7775. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7776. (defun org-agenda-remove-flag (marker)
  7777. "Remove the FLAGGED tag and any flagging note in the entry."
  7778. (let (newhead)
  7779. (org-with-point-at marker
  7780. (org-toggle-tag "FLAGGED" 'off)
  7781. (org-entry-delete nil "THEFLAGGINGNOTE")
  7782. (setq newhead (org-get-heading)))
  7783. (org-agenda-change-all-lines newhead marker)
  7784. (message "Entry unflaged")))
  7785. (defun org-agenda-get-any-marker (&optional pos)
  7786. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7787. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7788. ;;; Appointment reminders
  7789. (defvar appt-time-msg-list)
  7790. ;;;###autoload
  7791. (defun org-agenda-to-appt (&optional refresh filter)
  7792. "Activate appointments found in `org-agenda-files'.
  7793. With a \\[universal-argument] prefix, refresh the list of
  7794. appointments.
  7795. If FILTER is t, interactively prompt the user for a regular
  7796. expression, and filter out entries that don't match it.
  7797. If FILTER is a string, use this string as a regular expression
  7798. for filtering entries out.
  7799. FILTER can also be an alist with the car of each cell being
  7800. either 'headline or 'category. For example:
  7801. '((headline \"IMPORTANT\")
  7802. (category \"Work\"))
  7803. will only add headlines containing IMPORTANT or headlines
  7804. belonging to the \"Work\" category."
  7805. (interactive "P")
  7806. (if refresh (setq appt-time-msg-list nil))
  7807. (if (eq filter t)
  7808. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7809. (let* ((cnt 0) ; count added events
  7810. (org-agenda-new-buffers nil)
  7811. (org-deadline-warning-days 0)
  7812. ;; Do not use `org-today' here because appt only takes
  7813. ;; time and without date as argument, so it may pass wrong
  7814. ;; information otherwise
  7815. (today (org-date-to-gregorian
  7816. (time-to-days (current-time))))
  7817. (org-agenda-restrict nil)
  7818. (files (org-agenda-files 'unrestricted)) entries file)
  7819. ;; Get all entries which may contain an appt
  7820. (org-prepare-agenda-buffers files)
  7821. (while (setq file (pop files))
  7822. (setq entries
  7823. (append entries
  7824. (org-agenda-get-day-entries
  7825. file today :timestamp :scheduled :deadline))))
  7826. (setq entries (delq nil entries))
  7827. ;; Map thru entries and find if we should filter them out
  7828. (mapc
  7829. (lambda(x)
  7830. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7831. (cat (get-text-property 1 'org-category x))
  7832. (tod (get-text-property 1 'time-of-day x))
  7833. (ok (or (null filter)
  7834. (and (stringp filter) (string-match filter evt))
  7835. (and (listp filter)
  7836. (or (string-match
  7837. (cadr (assoc 'category filter)) cat)
  7838. (string-match
  7839. (cadr (assoc 'headline filter)) evt))))))
  7840. ;; FIXME: Shall we remove text-properties for the appt text?
  7841. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7842. (when (and ok tod)
  7843. (setq tod (concat "00" (number-to-string tod))
  7844. tod (when (string-match
  7845. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7846. (concat (match-string 1 tod) ":"
  7847. (match-string 2 tod))))
  7848. (appt-add tod evt)
  7849. (setq cnt (1+ cnt))))) entries)
  7850. (org-release-buffers org-agenda-new-buffers)
  7851. (if (eq cnt 0)
  7852. (message "No event to add")
  7853. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7854. (defun org-agenda-todayp (date)
  7855. "Does DATE mean today, when considering `org-extend-today-until'?"
  7856. (let ((today (org-today))
  7857. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7858. date)))
  7859. (eq date today)))
  7860. (defun org-agenda-todo-yesterday (&optional arg)
  7861. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  7862. (interactive "P")
  7863. (let* ((hour (third (decode-time
  7864. (org-current-time))))
  7865. (org-extend-today-until (1+ hour)))
  7866. (org-agenda-todo arg)))
  7867. (provide 'org-agenda)
  7868. ;;; org-agenda.el ends here