org-agenda.el 321 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.6
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done globally by leaving out lines like the agenda span
  82. name and week number or the separator lines."
  83. :group 'org-agenda
  84. :type 'boolean)
  85. (defcustom org-agenda-block-separator ?=
  86. "The separator between blocks in the agenda.
  87. If this is a string, it will be used as the separator, with a newline added.
  88. If it is a character, it will be repeated to fill the window width.
  89. If nil the separator is disabled. In `org-agenda-custom-commands' this
  90. addresses the separator between the current and the previous block."
  91. :group 'org-agenda
  92. :type '(choice
  93. (const :tag "Disabled" nil)
  94. (character)
  95. (string)))
  96. (defgroup org-agenda-export nil
  97. "Options concerning exporting agenda views in Org-mode."
  98. :tag "Org Agenda Export"
  99. :group 'org-agenda)
  100. (defcustom org-agenda-with-colors t
  101. "Non-nil means use colors in agenda views."
  102. :group 'org-agenda-export
  103. :type 'boolean)
  104. (defcustom org-agenda-exporter-settings nil
  105. "Alist of variable/value pairs that should be active during agenda export.
  106. This is a good place to set options for ps-print and for htmlize.
  107. Note that the way this is implemented, the values will be evaluated
  108. before assigned to the variables. So make sure to quote values you do
  109. *not* want evaluated, for example
  110. (setq org-agenda-exporter-settings
  111. '((ps-print-color-p 'black-white)))"
  112. :group 'org-agenda-export
  113. :type '(repeat
  114. (list
  115. (variable)
  116. (sexp :tag "Value"))))
  117. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  118. "Hook run in temporary buffer before writing it to an export file.
  119. A useful function is `org-agenda-add-entry-text'."
  120. :group 'org-agenda-export
  121. :type 'hook
  122. :options '(org-agenda-add-entry-text))
  123. (defcustom org-agenda-add-entry-text-maxlines 0
  124. "Maximum number of entry text lines to be added to agenda.
  125. This is only relevant when `org-agenda-add-entry-text' is part of
  126. `org-agenda-before-write-hook', which it is by default.
  127. When this is 0, nothing will happen. When it is greater than 0, it
  128. specifies the maximum number of lines that will be added for each entry
  129. that is listed in the agenda view.
  130. Note that this variable is not used during display, only when exporting
  131. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  132. and `org-agenda-entry-text-maxlines'."
  133. :group 'org-agenda
  134. :type 'integer)
  135. (defcustom org-agenda-add-entry-text-descriptive-links t
  136. "Non-nil means export org-links as descriptive links in agenda added text.
  137. This variable applies to the text added to the agenda when
  138. `org-agenda-add-entry-text-maxlines' is larger than 0.
  139. When this variable nil, the URL will (also) be shown."
  140. :group 'org-agenda
  141. :type 'boolean)
  142. (defcustom org-agenda-export-html-style ""
  143. "The style specification for exported HTML Agenda files.
  144. If this variable contains a string, it will replace the default <style>
  145. section as produced by `htmlize'.
  146. Since there are different ways of setting style information, this variable
  147. needs to contain the full HTML structure to provide a style, including the
  148. surrounding HTML tags. The style specifications should include definitions
  149. the fonts used by the agenda, here is an example:
  150. <style type=\"text/css\">
  151. p { font-weight: normal; color: gray; }
  152. .org-agenda-structure {
  153. font-size: 110%;
  154. color: #003399;
  155. font-weight: 600;
  156. }
  157. .org-todo {
  158. color: #cc6666;
  159. font-weight: bold;
  160. }
  161. .org-agenda-done {
  162. color: #339933;
  163. }
  164. .org-done {
  165. color: #339933;
  166. }
  167. .title { text-align: center; }
  168. .todo, .deadline { color: red; }
  169. .done { color: green; }
  170. </style>
  171. or, if you want to keep the style in a file,
  172. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  173. As the value of this option simply gets inserted into the HTML <head> header,
  174. you can \"misuse\" it to also add other text to the header. However,
  175. <style>...</style> is required, if not present the variable will be ignored."
  176. :group 'org-agenda-export
  177. :group 'org-export-html
  178. :type 'string)
  179. (defcustom org-agenda-persistent-filter nil
  180. "When set, keep filters from one agenda view to the next."
  181. :group 'org-agenda
  182. :type 'boolean)
  183. (defgroup org-agenda-custom-commands nil
  184. "Options concerning agenda views in Org-mode."
  185. :tag "Org Agenda Custom Commands"
  186. :group 'org-agenda)
  187. (defconst org-sorting-choice
  188. '(choice
  189. (const time-up) (const time-down)
  190. (const category-keep) (const category-up) (const category-down)
  191. (const tag-down) (const tag-up)
  192. (const priority-up) (const priority-down)
  193. (const todo-state-up) (const todo-state-down)
  194. (const effort-up) (const effort-down)
  195. (const habit-up) (const habit-down)
  196. (const alpha-up) (const alpha-down)
  197. (const user-defined-up) (const user-defined-down))
  198. "Sorting choices.")
  199. (defconst org-agenda-custom-commands-local-options
  200. `(repeat :tag "Local settings for this command. Remember to quote values"
  201. (choice :tag "Setting"
  202. (list :tag "Heading for this block"
  203. (const org-agenda-overriding-header)
  204. (string :tag "Headline"))
  205. (list :tag "Files to be searched"
  206. (const org-agenda-files)
  207. (list
  208. (const :format "" quote)
  209. (repeat (file))))
  210. (list :tag "Sorting strategy"
  211. (const org-agenda-sorting-strategy)
  212. (list
  213. (const :format "" quote)
  214. (repeat
  215. ,org-sorting-choice)))
  216. (list :tag "Prefix format"
  217. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  218. (string))
  219. (list :tag "Number of days in agenda"
  220. (const org-agenda-span)
  221. (choice (const :tag "Day" 'day)
  222. (const :tag "Week" 'week)
  223. (const :tag "Month" 'month)
  224. (const :tag "Year" 'year)
  225. (integer :tag "Custom")))
  226. (list :tag "Fixed starting date"
  227. (const org-agenda-start-day)
  228. (string :value "2007-11-01"))
  229. (list :tag "Start on day of week"
  230. (const org-agenda-start-on-weekday)
  231. (choice :value 1
  232. (const :tag "Today" nil)
  233. (integer :tag "Weekday No.")))
  234. (list :tag "Include data from diary"
  235. (const org-agenda-include-diary)
  236. (boolean))
  237. (list :tag "Deadline Warning days"
  238. (const org-deadline-warning-days)
  239. (integer :value 1))
  240. (list :tag "Tags filter preset"
  241. (const org-agenda-filter-preset)
  242. (list
  243. (const :format "" quote)
  244. (repeat
  245. (string :tag "+tag or -tag"))))
  246. (list :tag "Set daily/weekly entry types"
  247. (const org-agenda-entry-types)
  248. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  249. (const :deadline)
  250. (const :scheduled)
  251. (const :timestamp)
  252. (const :sexp)))
  253. (list :tag "Standard skipping condition"
  254. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  255. (const org-agenda-skip-function)
  256. (list
  257. (const :format "" quote)
  258. (list
  259. (choice
  260. :tag "Skipping range"
  261. (const :tag "Skip entry" org-agenda-skip-entry-if)
  262. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  263. (repeat :inline t :tag "Conditions for skipping"
  264. (choice
  265. :tag "Condition type"
  266. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  267. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  268. (list :tag "TODO state is" :inline t
  269. (const 'todo)
  270. (choice
  271. (const :tag "any not-done state" 'todo)
  272. (const :tag "any done state" 'done)
  273. (const :tag "any state" 'any)
  274. (list :tag "Keyword list"
  275. (const :format "" quote)
  276. (repeat (string :tag "Keyword")))))
  277. (list :tag "TODO state is not" :inline t
  278. (const 'nottodo)
  279. (choice
  280. (const :tag "any not-done state" 'todo)
  281. (const :tag "any done state" 'done)
  282. (const :tag "any state" 'any)
  283. (list :tag "Keyword list"
  284. (const :format "" quote)
  285. (repeat (string :tag "Keyword")))))
  286. (const :tag "scheduled" 'scheduled)
  287. (const :tag "not scheduled" 'notscheduled)
  288. (const :tag "deadline" 'deadline)
  289. (const :tag "no deadline" 'notdeadline)
  290. (const :tag "timestamp" 'timestamp)
  291. (const :tag "no timestamp" 'nottimestamp))))))
  292. (list :tag "Non-standard skipping condition"
  293. :value (org-agenda-skip-function)
  294. (const org-agenda-skip-function)
  295. (sexp :tag "Function or form (quoted!)"))
  296. (list :tag "Any variable"
  297. (variable :tag "Variable")
  298. (sexp :tag "Value (sexp)"))))
  299. "Selection of examples for agenda command settings.
  300. This will be spliced into the custom type of
  301. `org-agenda-custom-commands'.")
  302. (defcustom org-agenda-custom-commands nil
  303. "Custom commands for the agenda.
  304. These commands will be offered on the splash screen displayed by the
  305. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  306. (key desc type match settings files)
  307. key The key (one or more characters as a string) to be associated
  308. with the command.
  309. desc A description of the command, when omitted or nil, a default
  310. description is built using MATCH.
  311. type The command type, any of the following symbols:
  312. agenda The daily/weekly agenda.
  313. todo Entries with a specific TODO keyword, in all agenda files.
  314. search Entries containing search words entry or headline.
  315. tags Tags/Property/TODO match in all agenda files.
  316. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  317. todo-tree Sparse tree of specific TODO keyword in *current* file.
  318. tags-tree Sparse tree with all tags matches in *current* file.
  319. occur-tree Occur sparse tree for *current* file.
  320. ... A user-defined function.
  321. match What to search for:
  322. - a single keyword for TODO keyword searches
  323. - a tags match expression for tags searches
  324. - a word search expression for text searches.
  325. - a regular expression for occur searches
  326. For all other commands, this should be the empty string.
  327. settings A list of option settings, similar to that in a let form, so like
  328. this: ((opt1 val1) (opt2 val2) ...). The values will be
  329. evaluated at the moment of execution, so quote them when needed.
  330. files A list of files file to write the produced agenda buffer to
  331. with the command `org-store-agenda-views'.
  332. If a file name ends in \".html\", an HTML version of the buffer
  333. is written out. If it ends in \".ps\", a postscript version is
  334. produced. Otherwise, only the plain text is written to the file.
  335. You can also define a set of commands, to create a composite agenda buffer.
  336. In this case, an entry looks like this:
  337. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  338. where
  339. desc A description string to be displayed in the dispatcher menu.
  340. cmd An agenda command, similar to the above. However, tree commands
  341. are no allowed, but instead you can get agenda and global todo list.
  342. So valid commands for a set are:
  343. (agenda \"\" settings)
  344. (alltodo \"\" settings)
  345. (stuck \"\" settings)
  346. (todo \"match\" settings files)
  347. (search \"match\" settings files)
  348. (tags \"match\" settings files)
  349. (tags-todo \"match\" settings files)
  350. Each command can carry a list of options, and another set of options can be
  351. given for the whole set of commands. Individual command options take
  352. precedence over the general options.
  353. When using several characters as key to a command, the first characters
  354. are prefix commands. For the dispatcher to display useful information, you
  355. should provide a description for the prefix, like
  356. (setq org-agenda-custom-commands
  357. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  358. (\"hl\" tags \"+HOME+Lisa\")
  359. (\"hp\" tags \"+HOME+Peter\")
  360. (\"hk\" tags \"+HOME+Kim\")))"
  361. :group 'org-agenda-custom-commands
  362. :type `(repeat
  363. (choice :value ("x" "Describe command here" tags "" nil)
  364. (list :tag "Single command"
  365. (string :tag "Access Key(s) ")
  366. (option (string :tag "Description"))
  367. (choice
  368. (const :tag "Agenda" agenda)
  369. (const :tag "TODO list" alltodo)
  370. (const :tag "Search words" search)
  371. (const :tag "Stuck projects" stuck)
  372. (const :tag "Tags/Property match (all agenda files)" tags)
  373. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  374. (const :tag "TODO keyword search (all agenda files)" todo)
  375. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  376. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  377. (const :tag "Occur tree (current buffer)" occur-tree)
  378. (sexp :tag "Other, user-defined function"))
  379. (string :tag "Match (only for some commands)")
  380. ,org-agenda-custom-commands-local-options
  381. (option (repeat :tag "Export" (file :tag "Export to"))))
  382. (list :tag "Command series, all agenda files"
  383. (string :tag "Access Key(s)")
  384. (string :tag "Description ")
  385. (repeat :tag "Component"
  386. (choice
  387. (list :tag "Agenda"
  388. (const :format "" agenda)
  389. (const :tag "" :format "" "")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "TODO list (all keywords)"
  392. (const :format "" alltodo)
  393. (const :tag "" :format "" "")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Search words"
  396. (const :format "" search)
  397. (string :tag "Match")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Stuck projects"
  400. (const :format "" stuck)
  401. (const :tag "" :format "" "")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "Tags search"
  404. (const :format "" tags)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "Tags search, TODO entries only"
  408. (const :format "" tags-todo)
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)
  411. (list :tag "TODO keyword search"
  412. (const :format "" todo)
  413. (string :tag "Match")
  414. ,org-agenda-custom-commands-local-options)
  415. (list :tag "Other, user-defined function"
  416. (symbol :tag "function")
  417. (string :tag "Match")
  418. ,org-agenda-custom-commands-local-options)))
  419. (repeat :tag "Settings for entire command set"
  420. (list (variable :tag "Any variable")
  421. (sexp :tag "Value")))
  422. (option (repeat :tag "Export" (file :tag "Export to"))))
  423. (cons :tag "Prefix key documentation"
  424. (string :tag "Access Key(s)")
  425. (string :tag "Description ")))))
  426. (defcustom org-agenda-query-register ?o
  427. "The register holding the current query string.
  428. The purpose of this is that if you construct a query string interactively,
  429. you can then use it to define a custom command."
  430. :group 'org-agenda-custom-commands
  431. :type 'character)
  432. (defcustom org-stuck-projects
  433. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  434. "How to identify stuck projects.
  435. This is a list of four items:
  436. 1. A tags/todo/property matcher string that is used to identify a project.
  437. See the manual for a description of tag and property searches.
  438. The entire tree below a headline matched by this is considered one project.
  439. 2. A list of TODO keywords identifying non-stuck projects.
  440. If the project subtree contains any headline with one of these todo
  441. keywords, the project is considered to be not stuck. If you specify
  442. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  443. 3. A list of tags identifying non-stuck projects.
  444. If the project subtree contains any headline with one of these tags,
  445. the project is considered to be not stuck. If you specify \"*\" as
  446. a tag, any tag will mark the project unstuck. Note that this is about
  447. the explicit presence of a tag somewhere in the subtree, inherited
  448. tags to not count here. If inherited tags make a project not stuck,
  449. use \"-TAG\" in the tags part of the matcher under (1.) above.
  450. 4. An arbitrary regular expression matching non-stuck projects.
  451. If the project turns out to be not stuck, search continues also in the
  452. subtree to see if any of the subtasks have project status.
  453. See also the variable `org-tags-match-list-sublevels' which applies
  454. to projects matched by this search as well.
  455. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  456. or `C-c a #' to produce the list."
  457. :group 'org-agenda-custom-commands
  458. :type '(list
  459. (string :tag "Tags/TODO match to identify a project")
  460. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  461. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  462. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  463. (defcustom org-agenda-filter-effort-default-operator "<"
  464. "The default operator for effort estimate filtering.
  465. If you select an effort estimate limit without first pressing an operator,
  466. this one will be used."
  467. :group 'org-agenda-custom-commands
  468. :type '(choice (const :tag "less or equal" "<")
  469. (const :tag "greater or equal"">")
  470. (const :tag "equal" "=")))
  471. (defgroup org-agenda-skip nil
  472. "Options concerning skipping parts of agenda files."
  473. :tag "Org Agenda Skip"
  474. :group 'org-agenda)
  475. (defcustom org-agenda-skip-function-global nil
  476. "Function to be called at each match during agenda construction.
  477. If this function returns nil, the current match should not be skipped.
  478. If the function decided to skip an agenda match, is must return the
  479. buffer position from which the search should be continued.
  480. This may also be a Lisp form, which will be evaluated.
  481. This variable will be applied to every agenda match, including
  482. tags/property searches and TODO lists. So try to make the test function
  483. do its checking as efficiently as possible. To implement a skipping
  484. condition just for specific agenda commands, use the variable
  485. `org-agenda-skip-function' which can be set in the options section
  486. of custom agenda commands."
  487. :group 'org-agenda-skip
  488. :type 'sexp)
  489. (defgroup org-agenda-daily/weekly nil
  490. "Options concerning the daily/weekly agenda."
  491. :tag "Org Agenda Daily/Weekly"
  492. :group 'org-agenda)
  493. (defgroup org-agenda-todo-list nil
  494. "Options concerning the global todo list agenda view."
  495. :tag "Org Agenda Todo List"
  496. :group 'org-agenda)
  497. (defgroup org-agenda-match-view nil
  498. "Options concerning the general tags/property/todo match agenda view."
  499. :tag "Org Agenda Match View"
  500. :group 'org-agenda)
  501. (defgroup org-agenda-search-view nil
  502. "Options concerning the general tags/property/todo match agenda view."
  503. :tag "Org Agenda Match View"
  504. :group 'org-agenda)
  505. (defvar org-agenda-archives-mode nil
  506. "Non-nil means the agenda will include archived items.
  507. If this is the symbol `trees', trees in the selected agenda scope
  508. that are marked with the ARCHIVE tag will be included anyway. When this is
  509. t, also all archive files associated with the current selection of agenda
  510. files will be included.")
  511. (defcustom org-agenda-skip-comment-trees t
  512. "Non-nil means skip trees that start with the COMMENT keyword.
  513. When nil, these trees are also scanned by agenda commands."
  514. :group 'org-agenda-skip
  515. :type 'boolean)
  516. (defcustom org-agenda-todo-list-sublevels t
  517. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  518. When nil, the sublevels of a TODO entry are not checked, resulting in
  519. potentially much shorter TODO lists."
  520. :group 'org-agenda-skip
  521. :group 'org-agenda-todo-list
  522. :type 'boolean)
  523. (defcustom org-agenda-todo-ignore-with-date nil
  524. "Non-nil means don't show entries with a date in the global todo list.
  525. You can use this if you prefer to mark mere appointments with a TODO keyword,
  526. but don't want them to show up in the TODO list.
  527. When this is set, it also covers deadlines and scheduled items, the settings
  528. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  529. will be ignored.
  530. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  531. :group 'org-agenda-skip
  532. :group 'org-agenda-todo-list
  533. :type 'boolean)
  534. (defcustom org-agenda-todo-ignore-timestamp nil
  535. "Non-nil means don't show entries with a timestamp.
  536. This applies when creating the global todo list.
  537. Valid values are:
  538. past Don't show entries for today or in the past.
  539. future Don't show entries with a timestamp in the future.
  540. The idea behind this is that if it has a future
  541. timestamp, you don't want to think about it until the
  542. date.
  543. all Don't show any entries with a timestamp in the global todo list.
  544. The idea behind this is that by setting a timestamp, you
  545. have already \"taken care\" of this item.
  546. This variable can also have an integer as a value. If positive (N),
  547. todos with a timestamp N or more days in the future will be ignored. If
  548. negative (-N), todos with a timestamp N or more days in the past will be
  549. ignored. If 0, todos with a timestamp either today or in the future will
  550. be ignored. For example, a value of -1 will exclude todos with a
  551. timestamp in the past (yesterday or earlier), while a value of 7 will
  552. exclude todos with a timestamp a week or more in the future.
  553. See also `org-agenda-todo-ignore-with-date'.
  554. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  555. to make his option also apply to the tags-todo list."
  556. :group 'org-agenda-skip
  557. :group 'org-agenda-todo-list
  558. :type '(choice
  559. (const :tag "Ignore future timestamp todos" future)
  560. (const :tag "Ignore past or present timestamp todos" past)
  561. (const :tag "Ignore all timestamp todos" all)
  562. (const :tag "Show timestamp todos" nil)
  563. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  564. (defcustom org-agenda-todo-ignore-scheduled nil
  565. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  566. This applies when creating the global todo list.
  567. Valid values are:
  568. past Don't show entries scheduled today or in the past.
  569. future Don't show entries scheduled in the future.
  570. The idea behind this is that by scheduling it, you don't want to
  571. think about it until the scheduled date.
  572. all Don't show any scheduled entries in the global todo list.
  573. The idea behind this is that by scheduling it, you have already
  574. \"taken care\" of this item.
  575. t Same as `all', for backward compatibility.
  576. This variable can also have an integer as a value. See
  577. `org-agenda-todo-ignore-timestamp' for more details.
  578. See also `org-agenda-todo-ignore-with-date'.
  579. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  580. to make his option also apply to the tags-todo list."
  581. :group 'org-agenda-skip
  582. :group 'org-agenda-todo-list
  583. :type '(choice
  584. (const :tag "Ignore future-scheduled todos" future)
  585. (const :tag "Ignore past- or present-scheduled todos" past)
  586. (const :tag "Ignore all scheduled todos" all)
  587. (const :tag "Ignore all scheduled todos (compatibility)" t)
  588. (const :tag "Show scheduled todos" nil)
  589. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  590. (defcustom org-agenda-todo-ignore-deadlines nil
  591. "Non-nil means ignore some deadlined TODO items when making TODO list.
  592. There are different motivations for using different values, please think
  593. carefully when configuring this variable.
  594. This applies when creating the global todo list.
  595. Valid values are:
  596. near Don't show near deadline entries. A deadline is near when it is
  597. closer than `org-deadline-warning-days' days. The idea behind this
  598. is that such items will appear in the agenda anyway.
  599. far Don't show TODO entries where a deadline has been defined, but
  600. the deadline is not near. This is useful if you don't want to
  601. use the todo list to figure out what to do now.
  602. past Don't show entries with a deadline timestamp for today or in the past.
  603. future Don't show entries with a deadline timestamp in the future, not even
  604. when they become `near' ones. Use it with caution.
  605. all Ignore all TODO entries that do have a deadline.
  606. t Same as `near', for backward compatibility.
  607. This variable can also have an integer as a value. See
  608. `org-agenda-todo-ignore-timestamp' for more details.
  609. See also `org-agenda-todo-ignore-with-date'.
  610. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  611. to make his option also apply to the tags-todo list."
  612. :group 'org-agenda-skip
  613. :group 'org-agenda-todo-list
  614. :type '(choice
  615. (const :tag "Ignore near deadlines" near)
  616. (const :tag "Ignore near deadlines (compatibility)" t)
  617. (const :tag "Ignore far deadlines" far)
  618. (const :tag "Ignore all TODOs with a deadlines" all)
  619. (const :tag "Show all TODOs, even if they have a deadline" nil)
  620. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  621. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  622. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  623. The variables
  624. `org-agenda-todo-ignore-with-date',
  625. `org-agenda-todo-ignore-timestamp',
  626. `org-agenda-todo-ignore-scheduled',
  627. `org-agenda-todo-ignore-deadlines'
  628. make the global TODO list skip entries that have time stamps of certain
  629. kinds. If this option is set, the same options will also apply for the
  630. tags-todo search, which is the general tags/property matcher
  631. restricted to unfinished TODO entries only."
  632. :group 'org-agenda-skip
  633. :group 'org-agenda-todo-list
  634. :group 'org-agenda-match-view
  635. :type 'boolean)
  636. (defcustom org-agenda-skip-scheduled-if-done nil
  637. "Non-nil means don't show scheduled items in agenda when they are done.
  638. This is relevant for the daily/weekly agenda, not for the TODO list. And
  639. it applies only to the actual date of the scheduling. Warnings about
  640. an item with a past scheduling dates are always turned off when the item
  641. is DONE."
  642. :group 'org-agenda-skip
  643. :group 'org-agenda-daily/weekly
  644. :type 'boolean)
  645. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  646. "Non-nil means skip scheduling line if same entry shows because of deadline.
  647. In the agenda of today, an entry can show up multiple times because
  648. it is both scheduled and has a nearby deadline, and maybe a plain time
  649. stamp as well.
  650. When this variable is t, then only the deadline is shown and the fact that
  651. the entry is scheduled today or was scheduled previously is not shown.
  652. When this variable is nil, the entry will be shown several times. When
  653. the variable is the symbol `not-today', then skip scheduled previously,
  654. but not scheduled today."
  655. :group 'org-agenda-skip
  656. :group 'org-agenda-daily/weekly
  657. :type '(choice
  658. (const :tag "Never" nil)
  659. (const :tag "Always" t)
  660. (const :tag "Not when scheduled today" not-today)))
  661. (defcustom org-agenda-skip-deadline-if-done nil
  662. "Non-nil means don't show deadlines when the corresponding item is done.
  663. When nil, the deadline is still shown and should give you a happy feeling.
  664. This is relevant for the daily/weekly agenda. And it applied only to the
  665. actually date of the deadline. Warnings about approaching and past-due
  666. deadlines are always turned off when the item is DONE."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-daily/weekly
  669. :type 'boolean)
  670. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  671. "Non-nil means skip deadline prewarning when entry is also scheduled.
  672. This will apply on all days where a prewarning for the deadline would
  673. be shown, but not at the day when the entry is actually due. On that day,
  674. the deadline will be shown anyway.
  675. This variable may be set to nil, t, or a number which will then give
  676. the number of days before the actual deadline when the prewarnings
  677. should resume.
  678. This can be used in a workflow where the first showing of the deadline will
  679. trigger you to schedule it, and then you don't want to be reminded of it
  680. because you will take care of it on the day when scheduled."
  681. :group 'org-agenda-skip
  682. :group 'org-agenda-daily/weekly
  683. :type '(choice
  684. (const :tag "Alwas show prewarning" nil)
  685. (const :tag "Remove prewarning if entry is scheduled" t)
  686. (integer :tag "Restart prewarning N days before deadline")))
  687. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  688. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  689. When non-nil, after the search for timestamps has matched once in an
  690. entry, the rest of the entry will not be searched."
  691. :group 'org-agenda-skip
  692. :type 'boolean)
  693. (defcustom org-agenda-skip-timestamp-if-done nil
  694. "Non-nil means don't select item by timestamp or -range if it is DONE."
  695. :group 'org-agenda-skip
  696. :group 'org-agenda-daily/weekly
  697. :type 'boolean)
  698. (defcustom org-agenda-dim-blocked-tasks t
  699. "Non-nil means dim blocked tasks in the agenda display.
  700. This causes some overhead during agenda construction, but if you
  701. have turned on `org-enforce-todo-dependencies',
  702. `org-enforce-todo-checkbox-dependencies', or any other blocking
  703. mechanism, this will create useful feedback in the agenda.
  704. Instead of t, this variable can also have the value `invisible'.
  705. Then blocked tasks will be invisible and only become visible when
  706. they become unblocked. An exemption to this behavior is when a task is
  707. blocked because of unchecked checkboxes below it. Since checkboxes do
  708. not show up in the agenda views, making this task invisible you remove any
  709. trace from agenda views that there is something to do. Therefore, a task
  710. that is blocked because of checkboxes will never be made invisible, it
  711. will only be dimmed."
  712. :group 'org-agenda-daily/weekly
  713. :group 'org-agenda-todo-list
  714. :type '(choice
  715. (const :tag "Do not dim" nil)
  716. (const :tag "Dim to a grey face" t)
  717. (const :tag "Make invisible" invisible)))
  718. (defcustom org-timeline-show-empty-dates 3
  719. "Non-nil means `org-timeline' also shows dates without an entry.
  720. When nil, only the days which actually have entries are shown.
  721. When t, all days between the first and the last date are shown.
  722. When an integer, show also empty dates, but if there is a gap of more than
  723. N days, just insert a special line indicating the size of the gap."
  724. :group 'org-agenda-skip
  725. :type '(choice
  726. (const :tag "None" nil)
  727. (const :tag "All" t)
  728. (integer :tag "at most")))
  729. (defgroup org-agenda-startup nil
  730. "Options concerning initial settings in the Agenda in Org Mode."
  731. :tag "Org Agenda Startup"
  732. :group 'org-agenda)
  733. (defcustom org-agenda-menu-show-matcher t
  734. "Non-nil means show the match string in the agenda dispatcher menu.
  735. When nil, the matcher string is not shown, but is put into the help-echo
  736. property so than moving the mouse over the command shows it.
  737. Setting it to nil is good if matcher strings are very long and/or if
  738. you want to use two-column display (see `org-agenda-menu-two-column')."
  739. :group 'org-agenda
  740. :type 'boolean)
  741. (defcustom org-agenda-menu-two-column nil
  742. "Non-nil means, use two columns to show custom commands in the dispatcher.
  743. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  744. to nil."
  745. :group 'org-agenda
  746. :type 'boolean)
  747. (defcustom org-finalize-agenda-hook nil
  748. "Hook run just before displaying an agenda buffer."
  749. :group 'org-agenda-startup
  750. :type 'hook)
  751. (defcustom org-agenda-mouse-1-follows-link nil
  752. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  753. A longer mouse click will still set point. Does not work on XEmacs.
  754. Needs to be set before org.el is loaded."
  755. :group 'org-agenda-startup
  756. :type 'boolean)
  757. (defcustom org-agenda-start-with-follow-mode nil
  758. "The initial value of follow mode in a newly created agenda window."
  759. :group 'org-agenda-startup
  760. :type 'boolean)
  761. (defcustom org-agenda-show-outline-path t
  762. "Non-nil means show outline path in echo area after line motion."
  763. :group 'org-agenda-startup
  764. :type 'boolean)
  765. (defcustom org-agenda-start-with-entry-text-mode nil
  766. "The initial value of entry-text-mode in a newly created agenda window."
  767. :group 'org-agenda-startup
  768. :type 'boolean)
  769. (defcustom org-agenda-entry-text-maxlines 5
  770. "Number of text lines to be added when `E' is pressed in the agenda.
  771. Note that this variable only used during agenda display. Add add entry text
  772. when exporting the agenda, configure the variable
  773. `org-agenda-add-entry-ext-maxlines'."
  774. :group 'org-agenda
  775. :type 'integer)
  776. (defcustom org-agenda-entry-text-exclude-regexps nil
  777. "List of regular expressions to clean up entry text.
  778. The complete matches of all regular expressions in this list will be
  779. removed from entry text before it is shown in the agenda."
  780. :group 'org-agenda
  781. :type '(repeat (regexp)))
  782. (defvar org-agenda-entry-text-cleanup-hook nil
  783. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  784. This cleanup is done in a temporary buffer, so the function may inspect and
  785. change the entire buffer.
  786. Some default stuff like drawers and scheduling/deadline dates will already
  787. have been removed when this is called, as will any matches for regular
  788. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  789. (defvar org-agenda-include-inactive-timestamps nil
  790. "Non-nil means include inactive time stamps in agenda and timeline.")
  791. (defgroup org-agenda-windows nil
  792. "Options concerning the windows used by the Agenda in Org Mode."
  793. :tag "Org Agenda Windows"
  794. :group 'org-agenda)
  795. (defcustom org-agenda-window-setup 'reorganize-frame
  796. "How the agenda buffer should be displayed.
  797. Possible values for this option are:
  798. current-window Show agenda in the current window, keeping all other windows.
  799. other-window Use `switch-to-buffer-other-window' to display agenda.
  800. reorganize-frame Show only two windows on the current frame, the current
  801. window and the agenda.
  802. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  803. Also, when exiting the agenda, kill that frame.
  804. See also the variable `org-agenda-restore-windows-after-quit'."
  805. :group 'org-agenda-windows
  806. :type '(choice
  807. (const current-window)
  808. (const other-frame)
  809. (const other-window)
  810. (const reorganize-frame)))
  811. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  812. "The min and max height of the agenda window as a fraction of frame height.
  813. The value of the variable is a cons cell with two numbers between 0 and 1.
  814. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  815. :group 'org-agenda-windows
  816. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  817. (defcustom org-agenda-restore-windows-after-quit nil
  818. "Non-nil means restore window configuration upon exiting agenda.
  819. Before the window configuration is changed for displaying the agenda,
  820. the current status is recorded. When the agenda is exited with
  821. `q' or `x' and this option is set, the old state is restored. If
  822. `org-agenda-window-setup' is `other-frame', the value of this
  823. option will be ignored."
  824. :group 'org-agenda-windows
  825. :type 'boolean)
  826. (defcustom org-agenda-ndays nil
  827. "Number of days to include in overview display.
  828. Should be 1 or 7.
  829. Obsolete, see `org-agenda-span'."
  830. :group 'org-agenda-daily/weekly
  831. :type 'integer)
  832. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  833. (defcustom org-agenda-span 'week
  834. "Number of days to include in overview display.
  835. Can be day, week, month, year, or any number of days.
  836. Custom commands can set this variable in the options section."
  837. :group 'org-agenda-daily/weekly
  838. :type '(choice (const :tag "Day" day)
  839. (const :tag "Week" week)
  840. (const :tag "Month" month)
  841. (const :tag "Year" year)
  842. (integer :tag "Custom")))
  843. (defcustom org-agenda-start-on-weekday 1
  844. "Non-nil means start the overview always on the specified weekday.
  845. 0 denotes Sunday, 1 denotes Monday etc.
  846. When nil, always start on the current day.
  847. Custom commands can set this variable in the options section."
  848. :group 'org-agenda-daily/weekly
  849. :type '(choice (const :tag "Today" nil)
  850. (integer :tag "Weekday No.")))
  851. (defcustom org-agenda-show-all-dates t
  852. "Non-nil means `org-agenda' shows every day in the selected range.
  853. When nil, only the days which actually have entries are shown."
  854. :group 'org-agenda-daily/weekly
  855. :type 'boolean)
  856. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  857. "Format string for displaying dates in the agenda.
  858. Used by the daily/weekly agenda and by the timeline. This should be
  859. a format string understood by `format-time-string', or a function returning
  860. the formatted date as a string. The function must take a single argument,
  861. a calendar-style date list like (month day year)."
  862. :group 'org-agenda-daily/weekly
  863. :type '(choice
  864. (string :tag "Format string")
  865. (function :tag "Function")))
  866. (defun org-agenda-format-date-aligned (date)
  867. "Format a date string for display in the daily/weekly agenda, or timeline.
  868. This function makes sure that dates are aligned for easy reading."
  869. (require 'cal-iso)
  870. (let* ((dayname (calendar-day-name date))
  871. (day (cadr date))
  872. (day-of-week (calendar-day-of-week date))
  873. (month (car date))
  874. (monthname (calendar-month-name month))
  875. (year (nth 2 date))
  876. (iso-week (org-days-to-iso-week
  877. (calendar-absolute-from-gregorian date)))
  878. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  879. (1- year))
  880. ((and (= month 12) (<= iso-week 1))
  881. (1+ year))
  882. (t year)))
  883. (weekstring (if (= day-of-week 1)
  884. (format " W%02d" iso-week)
  885. "")))
  886. (format "%-10s %2d %s %4d%s"
  887. dayname day monthname year weekstring)))
  888. (defcustom org-agenda-time-leading-zero nil
  889. "Non-nil means use leading zero for military times in agenda.
  890. For example, 9:30am would become 09:30 rather than 9:30."
  891. :group 'org-agenda-daily/weekly
  892. :type 'boolean)
  893. (defcustom org-agenda-timegrid-use-ampm nil
  894. "When set, show AM/PM style timestamps on the timegrid."
  895. :group 'org-agenda
  896. :type 'boolean)
  897. (defun org-agenda-time-of-day-to-ampm (time)
  898. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  899. (let* ((hour-number (string-to-number (substring time 0 -3)))
  900. (minute (substring time -2))
  901. (ampm "am"))
  902. (cond
  903. ((equal hour-number 12)
  904. (setq ampm "pm"))
  905. ((> hour-number 12)
  906. (setq ampm "pm")
  907. (setq hour-number (- hour-number 12))))
  908. (concat
  909. (if org-agenda-time-leading-zero
  910. (format "%02d" hour-number)
  911. (format "%02s" (number-to-string hour-number)))
  912. ":" minute ampm)))
  913. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  914. "Conditionally convert TIME to AM/PM format
  915. based on `org-agenda-timegrid-use-ampm'"
  916. (if org-agenda-timegrid-use-ampm
  917. (org-agenda-time-of-day-to-ampm time)
  918. time))
  919. (defcustom org-agenda-weekend-days '(6 0)
  920. "Which days are weekend?
  921. These days get the special face `org-agenda-date-weekend' in the agenda
  922. and timeline buffers."
  923. :group 'org-agenda-daily/weekly
  924. :type '(set :greedy t
  925. (const :tag "Monday" 1)
  926. (const :tag "Tuesday" 2)
  927. (const :tag "Wednesday" 3)
  928. (const :tag "Thursday" 4)
  929. (const :tag "Friday" 5)
  930. (const :tag "Saturday" 6)
  931. (const :tag "Sunday" 0)))
  932. (defcustom org-agenda-include-diary nil
  933. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  934. Custom commands can set this variable in the options section."
  935. :group 'org-agenda-daily/weekly
  936. :type 'boolean)
  937. (defcustom org-agenda-include-deadlines t
  938. "If non-nil, include entries within their deadline warning period.
  939. Custom commands can set this variable in the options section."
  940. :group 'org-agenda-daily/weekly
  941. :type 'boolean)
  942. (defcustom org-agenda-include-all-todo nil
  943. "Set means weekly/daily agenda will always contain all TODO entries.
  944. The TODO entries will be listed at the top of the agenda, before
  945. the entries for specific days.
  946. This option is deprecated, it is better to define a block agenda instead."
  947. :group 'org-agenda-daily/weekly
  948. :type 'boolean)
  949. (defcustom org-agenda-repeating-timestamp-show-all t
  950. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  951. When set to a list of strings, only show occurrences of repeating
  952. stamps for these TODO keywords. When nil, only one occurrence is
  953. shown, either today or the nearest into the future."
  954. :group 'org-agenda-daily/weekly
  955. :type '(choice
  956. (const :tag "Show repeating stamps" t)
  957. (repeat :tag "Show repeating stamps for these TODO keywords"
  958. (string :tag "TODO Keyword"))
  959. (const :tag "Don't show repeating stamps" nil)))
  960. (defcustom org-scheduled-past-days 10000
  961. "No. of days to continue listing scheduled items that are not marked DONE.
  962. When an item is scheduled on a date, it shows up in the agenda on this
  963. day and will be listed until it is marked done for the number of days
  964. given here."
  965. :group 'org-agenda-daily/weekly
  966. :type 'integer)
  967. (defcustom org-agenda-log-mode-items '(closed clock)
  968. "List of items that should be shown in agenda log mode.
  969. This list may contain the following symbols:
  970. closed Show entries that have been closed on that day.
  971. clock Show entries that have received clocked time on that day.
  972. state Show all logged state changes.
  973. Note that instead of changing this variable, you can also press `C-u l' in
  974. the agenda to display all available LOG items temporarily."
  975. :group 'org-agenda-daily/weekly
  976. :type '(set :greedy t (const closed) (const clock) (const state)))
  977. (defcustom org-agenda-clock-consistency-checks
  978. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  979. :gap-ok-around ("4:00")
  980. :default-face ((:background "DarkRed") (:foreground "white"))
  981. :overlap-face nil :gap-face nil :no-end-time-face nil
  982. :long-face nil :short-face nil)
  983. "This is a property list, with the following keys:
  984. :max-duration Mark clocking chunks that are longer than this time.
  985. This is a time string like \"HH:MM\", or the number
  986. of minutes as an integer.
  987. :min-duration Mark clocking chunks that are shorter that this.
  988. This is a time string like \"HH:MM\", or the number
  989. of minutes as an integer.
  990. :max-gap Mark gaps between clocking chunks that are longer than
  991. this duration. A number of minutes, or a string
  992. like \"HH:MM\".
  993. :gap-ok-around List of times during the day which are usually not working
  994. times. When a gap is detected, but the gap contains any
  995. of these times, the gap is *not* reported. For example,
  996. if this is (\"4:00\" \"13:00\") then gaps that contain
  997. 4:00 in the morning (i.e. the night) and 13:00
  998. (i.e. a typical lunch time) do not cause a warning.
  999. You should have at least one time during the night in this
  1000. list, or otherwise the first task each morning will trigger
  1001. a warning because it follows a long gap.
  1002. Furthermore, the following properties can be used to define faces for
  1003. issue display.
  1004. :default-face the default face, if the specific face is undefined
  1005. :overlap-face face for overlapping clocks
  1006. :gap-face face for gaps between clocks
  1007. :no-end-time-face face for incomplete clocks
  1008. :long-face face for clock intervals that are too long
  1009. :short-face face for clock intervals that are too short"
  1010. :group 'org-agenda-daily/weekly
  1011. :group 'org-clock
  1012. :type 'plist)
  1013. (defcustom org-agenda-log-mode-add-notes t
  1014. "Non-nil means add first line of notes to log entries in agenda views.
  1015. If a log item like a state change or a clock entry is associated with
  1016. notes, the first line of these notes will be added to the entry in the
  1017. agenda display."
  1018. :group 'org-agenda-daily/weekly
  1019. :type 'boolean)
  1020. (defcustom org-agenda-start-with-log-mode nil
  1021. "The initial value of log-mode in a newly created agenda window."
  1022. :group 'org-agenda-startup
  1023. :group 'org-agenda-daily/weekly
  1024. :type 'boolean)
  1025. (defcustom org-agenda-start-with-clockreport-mode nil
  1026. "The initial value of clockreport-mode in a newly created agenda window."
  1027. :group 'org-agenda-startup
  1028. :group 'org-agenda-daily/weekly
  1029. :type 'boolean)
  1030. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1031. "Property list with parameters for the clocktable in clockreport mode.
  1032. This is the display mode that shows a clock table in the daily/weekly
  1033. agenda, the properties for this dynamic block can be set here.
  1034. The usual clocktable parameters are allowed here, but you cannot set
  1035. the properties :name, :tstart, :tend, :block, and :scope - these will
  1036. be overwritten to make sure the content accurately reflects the
  1037. current display in the agenda."
  1038. :group 'org-agenda-daily/weekly
  1039. :type 'plist)
  1040. (defcustom org-agenda-search-view-always-boolean nil
  1041. "Non-nil means the search string is interpreted as individual parts.
  1042. The search string for search view can either be interpreted as a phrase,
  1043. or as a list of snippets that define a boolean search for a number of
  1044. strings.
  1045. When this is non-nil, the string will be split on whitespace, and each
  1046. snippet will be searched individually, and all must match in order to
  1047. select an entry. A snippet is then a single string of non-white
  1048. characters, or a string in double quotes, or a regexp in {} braces.
  1049. If a snippet is preceded by \"-\", the snippet must *not* match.
  1050. \"+\" is syntactic sugar for positive selection. Each snippet may
  1051. be found as a full word or a partial word, but see the variable
  1052. `org-agenda-search-view-force-full-words'.
  1053. When this is nil, search will look for the entire search phrase as one,
  1054. with each space character matching any amount of whitespace, including
  1055. line breaks.
  1056. Even when this is nil, you can still switch to Boolean search dynamically
  1057. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1058. is a regexp marked with braces like \"{abc}\", this will also switch to
  1059. boolean search."
  1060. :group 'org-agenda-search-view
  1061. :type 'boolean)
  1062. (if (fboundp 'defvaralias)
  1063. (defvaralias 'org-agenda-search-view-search-words-only
  1064. 'org-agenda-search-view-always-boolean))
  1065. (defcustom org-agenda-search-view-force-full-words nil
  1066. "Non-nil means, search words must be matches as complete words.
  1067. When nil, they may also match part of a word."
  1068. :group 'org-agenda-search-view
  1069. :type 'boolean)
  1070. (defgroup org-agenda-time-grid nil
  1071. "Options concerning the time grid in the Org-mode Agenda."
  1072. :tag "Org Agenda Time Grid"
  1073. :group 'org-agenda)
  1074. (defcustom org-agenda-search-headline-for-time t
  1075. "Non-nil means search headline for a time-of-day.
  1076. If the headline contains a time-of-day in one format or another, it will
  1077. be used to sort the entry into the time sequence of items for a day.
  1078. Some people have time stamps in the headline that refer to the creation
  1079. time or so, and then this produces an unwanted side effect. If this is
  1080. the case for your, use this variable to turn off searching the headline
  1081. for a time."
  1082. :group 'org-agenda-time-grid
  1083. :type 'boolean)
  1084. (defcustom org-agenda-use-time-grid t
  1085. "Non-nil means show a time grid in the agenda schedule.
  1086. A time grid is a set of lines for specific times (like every two hours between
  1087. 8:00 and 20:00). The items scheduled for a day at specific times are
  1088. sorted in between these lines.
  1089. For details about when the grid will be shown, and what it will look like, see
  1090. the variable `org-agenda-time-grid'."
  1091. :group 'org-agenda-time-grid
  1092. :type 'boolean)
  1093. (defcustom org-agenda-time-grid
  1094. '((daily today require-timed)
  1095. "----------------"
  1096. (800 1000 1200 1400 1600 1800 2000))
  1097. "The settings for time grid for agenda display.
  1098. This is a list of three items. The first item is again a list. It contains
  1099. symbols specifying conditions when the grid should be displayed:
  1100. daily if the agenda shows a single day
  1101. weekly if the agenda shows an entire week
  1102. today show grid on current date, independent of daily/weekly display
  1103. require-timed show grid only if at least one item has a time specification
  1104. The second item is a string which will be placed behind the grid time.
  1105. The third item is a list of integers, indicating the times that should have
  1106. a grid line."
  1107. :group 'org-agenda-time-grid
  1108. :type
  1109. '(list
  1110. (set :greedy t :tag "Grid Display Options"
  1111. (const :tag "Show grid in single day agenda display" daily)
  1112. (const :tag "Show grid in weekly agenda display" weekly)
  1113. (const :tag "Always show grid for today" today)
  1114. (const :tag "Show grid only if any timed entries are present"
  1115. require-timed)
  1116. (const :tag "Skip grid times already present in an entry"
  1117. remove-match))
  1118. (string :tag "Grid String")
  1119. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1120. (defcustom org-agenda-show-current-time-in-grid t
  1121. "Non-nil means show the current time in the time grid."
  1122. :group 'org-agenda-time-grid
  1123. :type 'boolean)
  1124. (defcustom org-agenda-current-time-string
  1125. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1126. "The string for the current time marker in the agenda."
  1127. :group 'org-agenda-time-grid
  1128. :type 'string)
  1129. (defgroup org-agenda-sorting nil
  1130. "Options concerning sorting in the Org-mode Agenda."
  1131. :tag "Org Agenda Sorting"
  1132. :group 'org-agenda)
  1133. (defcustom org-agenda-sorting-strategy
  1134. '((agenda habit-down time-up priority-down category-keep)
  1135. (todo priority-down category-keep)
  1136. (tags priority-down category-keep)
  1137. (search category-keep))
  1138. "Sorting structure for the agenda items of a single day.
  1139. This is a list of symbols which will be used in sequence to determine
  1140. if an entry should be listed before another entry. The following
  1141. symbols are recognized:
  1142. time-up Put entries with time-of-day indications first, early first
  1143. time-down Put entries with time-of-day indications first, late first
  1144. category-keep Keep the default order of categories, corresponding to the
  1145. sequence in `org-agenda-files'.
  1146. category-up Sort alphabetically by category, A-Z.
  1147. category-down Sort alphabetically by category, Z-A.
  1148. tag-up Sort alphabetically by last tag, A-Z.
  1149. tag-down Sort alphabetically by last tag, Z-A.
  1150. priority-up Sort numerically by priority, high priority last.
  1151. priority-down Sort numerically by priority, high priority first.
  1152. todo-state-up Sort by todo state, tasks that are done last.
  1153. todo-state-down Sort by todo state, tasks that are done first.
  1154. effort-up Sort numerically by estimated effort, high effort last.
  1155. effort-down Sort numerically by estimated effort, high effort first.
  1156. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1157. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1158. habit-up Put entries that are habits first
  1159. habit-down Put entries that are habits last
  1160. alpha-up Sort headlines alphabetically
  1161. alpha-down Sort headlines alphabetically, reversed
  1162. The different possibilities will be tried in sequence, and testing stops
  1163. if one comparison returns a \"not-equal\". For example, the default
  1164. '(time-up category-keep priority-down)
  1165. means: Pull out all entries having a specified time of day and sort them,
  1166. in order to make a time schedule for the current day the first thing in the
  1167. agenda listing for the day. Of the entries without a time indication, keep
  1168. the grouped in categories, don't sort the categories, but keep them in
  1169. the sequence given in `org-agenda-files'. Within each category sort by
  1170. priority.
  1171. Leaving out `category-keep' would mean that items will be sorted across
  1172. categories by priority.
  1173. Instead of a single list, this can also be a set of list for specific
  1174. contents, with a context symbol in the car of the list, any of
  1175. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1176. Custom commands can bind this variable in the options section."
  1177. :group 'org-agenda-sorting
  1178. :type `(choice
  1179. (repeat :tag "General" ,org-sorting-choice)
  1180. (list :tag "Individually"
  1181. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1182. (repeat ,org-sorting-choice))
  1183. (cons (const :tag "Strategy for TODO lists" todo)
  1184. (repeat ,org-sorting-choice))
  1185. (cons (const :tag "Strategy for Tags matches" tags)
  1186. (repeat ,org-sorting-choice))
  1187. (cons (const :tag "Strategy for search matches" search)
  1188. (repeat ,org-sorting-choice)))))
  1189. (defcustom org-agenda-cmp-user-defined nil
  1190. "A function to define the comparison `user-defined'.
  1191. This function must receive two arguments, agenda entry a and b.
  1192. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1193. the user comparison, return nil.
  1194. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1195. part of an agenda sorting strategy."
  1196. :group 'org-agenda-sorting
  1197. :type 'symbol)
  1198. (defcustom org-sort-agenda-notime-is-late t
  1199. "Non-nil means items without time are considered late.
  1200. This is only relevant for sorting. When t, items which have no explicit
  1201. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1202. do have a time. When nil, the default time is before 0:00. You can use this
  1203. option to decide if the schedule for today should come before or after timeless
  1204. agenda entries."
  1205. :group 'org-agenda-sorting
  1206. :type 'boolean)
  1207. (defcustom org-sort-agenda-noeffort-is-high t
  1208. "Non-nil means items without effort estimate are sorted as high effort.
  1209. This also applies when filtering an agenda view with respect to the
  1210. < or > effort operator. Then, tasks with no effort defined will be treated
  1211. as tasks with high effort.
  1212. When nil, such items are sorted as 0 minutes effort."
  1213. :group 'org-agenda-sorting
  1214. :type 'boolean)
  1215. (defgroup org-agenda-line-format nil
  1216. "Options concerning the entry prefix in the Org-mode agenda display."
  1217. :tag "Org Agenda Line Format"
  1218. :group 'org-agenda)
  1219. (defcustom org-agenda-prefix-format
  1220. '((agenda . " %i %-12:c%?-12t% s")
  1221. (timeline . " % s")
  1222. (todo . " %i %-12:c")
  1223. (tags . " %i %-12:c")
  1224. (search . " %i %-12:c"))
  1225. "Format specifications for the prefix of items in the agenda views.
  1226. An alist with four entries, for the different agenda types. The keys to the
  1227. sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
  1228. are format strings.
  1229. This format works similar to a printf format, with the following meaning:
  1230. %c the category of the item, \"Diary\" for entries from the diary, or
  1231. as given by the CATEGORY keyword or derived from the file name.
  1232. %i the icon category of the item, as give in
  1233. `org-agenda-category-icon-alist'.
  1234. %T the *last* tag of the item. Last because inherited tags come
  1235. first in the list.
  1236. %t the time-of-day specification if one applies to the entry, in the
  1237. format HH:MM
  1238. %s Scheduling/Deadline information, a short string
  1239. %(expression) Eval EXPRESSION and replace the control string
  1240. by the result
  1241. All specifiers work basically like the standard `%s' of printf, but may
  1242. contain two additional characters: A question mark just after the `%' and
  1243. a whitespace/punctuation character just before the final letter.
  1244. If the first character after `%' is a question mark, the entire field
  1245. will only be included if the corresponding value applies to the
  1246. current entry. This is useful for fields which should have fixed
  1247. width when present, but zero width when absent. For example,
  1248. \"%?-12t\" will result in a 12 character time field if a time of the
  1249. day is specified, but will completely disappear in entries which do
  1250. not contain a time.
  1251. If there is punctuation or whitespace character just before the final
  1252. format letter, this character will be appended to the field value if
  1253. the value is not empty. For example, the format \"%-12:c\" leads to
  1254. \"Diary: \" if the category is \"Diary\". If the category were be
  1255. empty, no additional colon would be inserted.
  1256. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1257. - Indent the line with two space characters
  1258. - Give the category in a 12 chars wide field, padded with whitespace on
  1259. the right (because of `-'). Append a colon if there is a category
  1260. (because of `:').
  1261. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1262. time, don't put in an empty field, just skip it (because of '?').
  1263. - Finally, put the scheduling information and append a whitespace.
  1264. As another example, if you don't want the time-of-day of entries in
  1265. the prefix, you could use:
  1266. (setq org-agenda-prefix-format \" %-11:c% s\")
  1267. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1268. `org-agenda-remove-tags'.
  1269. Custom commands can set this variable in the options section."
  1270. :type '(choice
  1271. (string :tag "General format")
  1272. (list :greedy t :tag "View dependent"
  1273. (cons (const agenda) (string :tag "Format"))
  1274. (cons (const timeline) (string :tag "Format"))
  1275. (cons (const todo) (string :tag "Format"))
  1276. (cons (const tags) (string :tag "Format"))
  1277. (cons (const search) (string :tag "Format"))))
  1278. :group 'org-agenda-line-format)
  1279. (defvar org-prefix-format-compiled nil
  1280. "The compiled version of the most recently used prefix format.
  1281. See the variable `org-agenda-prefix-format'.")
  1282. (defcustom org-agenda-todo-keyword-format "%-1s"
  1283. "Format for the TODO keyword in agenda lines.
  1284. Set this to something like \"%-12s\" if you want all TODO keywords
  1285. to occupy a fixed space in the agenda display."
  1286. :group 'org-agenda-line-format
  1287. :type 'string)
  1288. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1289. "Text preceding timerange entries in the agenda view.
  1290. This is a list with two strings. The first applies when the range
  1291. is entirely on one day. The second applies if the range spans several days.
  1292. The strings may have two \"%d\" format specifiers which will be filled
  1293. with the sequence number of the days, and the total number of days in the
  1294. range, respectively."
  1295. :group 'org-agenda-line-format
  1296. :type '(list
  1297. (string :tag "Deadline today ")
  1298. (choice :tag "Deadline relative"
  1299. (string :tag "Format string")
  1300. (function))))
  1301. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1302. "Text preceding scheduled items in the agenda view.
  1303. This is a list with two strings. The first applies when the item is
  1304. scheduled on the current day. The second applies when it has been scheduled
  1305. previously, it may contain a %d indicating that this is the nth time that
  1306. this item is scheduled, due to automatic rescheduling of unfinished items
  1307. for the following day. So this number is one larger than the number of days
  1308. that passed since this item was scheduled first."
  1309. :group 'org-agenda-line-format
  1310. :type '(list
  1311. (string :tag "Scheduled today ")
  1312. (string :tag "Scheduled previously")))
  1313. (defcustom org-agenda-inactive-leader "["
  1314. "Text preceding item pulled into the agenda by inactive time stamps.
  1315. These entries are added to the agenda when pressing \"[\"."
  1316. :group 'org-agenda-line-format
  1317. :type '(list
  1318. (string :tag "Scheduled today ")
  1319. (string :tag "Scheduled previously")))
  1320. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1321. "Text preceding deadline items in the agenda view.
  1322. This is a list with two strings. The first applies when the item has its
  1323. deadline on the current day. The second applies when it is in the past or
  1324. in the future, it may contain %d to capture how many days away the deadline
  1325. is (was)."
  1326. :group 'org-agenda-line-format
  1327. :type '(list
  1328. (string :tag "Deadline today ")
  1329. (choice :tag "Deadline relative"
  1330. (string :tag "Format string")
  1331. (function))))
  1332. (defcustom org-agenda-remove-times-when-in-prefix t
  1333. "Non-nil means remove duplicate time specifications in agenda items.
  1334. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1335. time-of-day specification in a headline or diary entry is extracted and
  1336. placed into the prefix. If this option is non-nil, the original specification
  1337. \(a timestamp or -range, or just a plain time(range) specification like
  1338. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1339. cluttered.
  1340. The option can be t or nil. It may also be the symbol `beg', indicating
  1341. that the time should only be removed when it is located at the beginning of
  1342. the headline/diary entry."
  1343. :group 'org-agenda-line-format
  1344. :type '(choice
  1345. (const :tag "Always" t)
  1346. (const :tag "Never" nil)
  1347. (const :tag "When at beginning of entry" beg)))
  1348. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1349. "Non-nil means remove time ranges specifications in agenda
  1350. items that span on several days."
  1351. :group 'org-agenda-line-format
  1352. :type 'boolean)
  1353. (defcustom org-agenda-default-appointment-duration nil
  1354. "Default duration for appointments that only have a starting time.
  1355. When nil, no duration is specified in such cases.
  1356. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1357. :group 'org-agenda-line-format
  1358. :type '(choice
  1359. (integer :tag "Minutes")
  1360. (const :tag "No default duration")))
  1361. (defcustom org-agenda-show-inherited-tags t
  1362. "Non-nil means show inherited tags in each agenda line."
  1363. :group 'org-agenda-line-format
  1364. :type 'boolean)
  1365. (defcustom org-agenda-hide-tags-regexp nil
  1366. "Regular expression used to filter away specific tags in agenda views.
  1367. This means that these tags will be present, but not be shown in the agenda
  1368. line. Secondary filtering will still work on the hidden tags.
  1369. Nil means don't hide any tags."
  1370. :group 'org-agenda-line-format
  1371. :type '(choice
  1372. (const :tag "Hide none" nil)
  1373. (string :tag "Regexp ")))
  1374. (defcustom org-agenda-remove-tags nil
  1375. "Non-nil means remove the tags from the headline copy in the agenda.
  1376. When this is the symbol `prefix', only remove tags when
  1377. `org-agenda-prefix-format' contains a `%T' specifier."
  1378. :group 'org-agenda-line-format
  1379. :type '(choice
  1380. (const :tag "Always" t)
  1381. (const :tag "Never" nil)
  1382. (const :tag "When prefix format contains %T" prefix)))
  1383. (if (fboundp 'defvaralias)
  1384. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1385. 'org-agenda-remove-tags))
  1386. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1387. "Shift tags in agenda items to this column.
  1388. If this number is positive, it specifies the column. If it is negative,
  1389. it means that the tags should be flushright to that column. For example,
  1390. -80 works well for a normal 80 character screen."
  1391. :group 'org-agenda-line-format
  1392. :type 'integer)
  1393. (if (fboundp 'defvaralias)
  1394. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1395. (defcustom org-agenda-fontify-priorities 'cookies
  1396. "Non-nil means highlight low and high priorities in agenda.
  1397. When t, the highest priority entries are bold, lowest priority italic.
  1398. However, settings in `org-priority-faces' will overrule these faces.
  1399. When this variable is the symbol `cookies', only fontify the
  1400. cookies, not the entire task.
  1401. This may also be an association list of priority faces, whose
  1402. keys are the character values of `org-highest-priority',
  1403. `org-default-priority', and `org-lowest-priority' (the default values
  1404. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1405. color as a string, or a list like `(:background \"Red\")'.
  1406. If it is a color, the variable `org-faces-easy-properties'
  1407. determines if it is a foreground or a background color."
  1408. :group 'org-agenda-line-format
  1409. :type '(choice
  1410. (const :tag "Never" nil)
  1411. (const :tag "Defaults" t)
  1412. (const :tag "Cookies only" cookies)
  1413. (repeat :tag "Specify"
  1414. (list (character :tag "Priority" :value ?A)
  1415. (choice :tag "Face "
  1416. (string :tag "Color")
  1417. (sexp :tag "Face"))))))
  1418. (defcustom org-agenda-day-face-function nil
  1419. "Function called to determine what face should be used to display a day.
  1420. The only argument passed to that function is the day. It should
  1421. returns a face, or nil if does not want to specify a face and let
  1422. the normal rules apply."
  1423. :group 'org-agenda-line-format
  1424. :type 'function)
  1425. (defcustom org-agenda-category-icon-alist nil
  1426. "Alist of category icon to be displayed in agenda views.
  1427. Each entry should have the following format:
  1428. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1429. Where CATEGORY-REGEXP is a regexp matching the categories where
  1430. the icon should be displayed.
  1431. FILE-OR-DATA either a file path or a string containing image data.
  1432. The other fields can be omited safely if not needed:
  1433. TYPE indicates the image type.
  1434. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1435. image data.
  1436. PROPS are additional image attributes to assign to the image,
  1437. like, e.g. `:ascent center'.
  1438. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1439. If you want to set the display properties yourself, just put a
  1440. list as second element:
  1441. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1442. For example, to display a 16px horizontal space for Emacs
  1443. category, you can use:
  1444. (\"Emacs\" '(space . (:width (16))))"
  1445. :group 'org-agenda-line-format
  1446. :type '(alist :key-type (string :tag "Regexp matching category")
  1447. :value-type (choice (list :tag "Icon"
  1448. (string :tag "File or data")
  1449. (symbol :tag "Type")
  1450. (boolean :tag "Data?")
  1451. (repeat :tag "Extra image properties" :inline t symbol))
  1452. (list :tag "Display properties" sexp))))
  1453. (defgroup org-agenda-column-view nil
  1454. "Options concerning column view in the agenda."
  1455. :tag "Org Agenda Column View"
  1456. :group 'org-agenda)
  1457. (defcustom org-agenda-columns-show-summaries t
  1458. "Non-nil means show summaries for columns displayed in the agenda view."
  1459. :group 'org-agenda-column-view
  1460. :type 'boolean)
  1461. (defcustom org-agenda-columns-compute-summary-properties t
  1462. "Non-nil means recompute all summary properties before column view.
  1463. When column view in the agenda is listing properties that have a summary
  1464. operator, it can go to all relevant buffers and recompute the summaries
  1465. there. This can mean overhead for the agenda column view, but is necessary
  1466. to have thing up to date.
  1467. As a special case, a CLOCKSUM property also makes sure that the clock
  1468. computations are current."
  1469. :group 'org-agenda-column-view
  1470. :type 'boolean)
  1471. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1472. "Non-nil means the duration of an appointment will add to day effort.
  1473. The property to which appointment durations will be added is the one given
  1474. in the option `org-effort-property'. If an appointment does not have
  1475. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1476. is not set, an appointment without end time will not contribute to the time
  1477. estimate."
  1478. :group 'org-agenda-column-view
  1479. :type 'boolean)
  1480. (defcustom org-agenda-auto-exclude-function nil
  1481. "A function called with a tag to decide if it is filtered on '/ RET'.
  1482. The sole argument to the function, which is called once for each
  1483. possible tag, is a string giving the name of the tag. The
  1484. function should return either nil if the tag should be included
  1485. as normal, or \"-<TAG>\" to exclude the tag.
  1486. Note that for the purpose of tag filtering, only the lower-case version of
  1487. all tags will be considered, so that this function will only ever see
  1488. the lower-case version of all tags."
  1489. :group 'org-agenda
  1490. :type 'function)
  1491. (eval-when-compile
  1492. (require 'cl))
  1493. (require 'org)
  1494. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1495. "Execute BODY with point at location given by `org-hd-marker' property.
  1496. If STRING is non-nil, the text property will be fetched from position 0
  1497. in that string. If STRING is nil, it will be fetched from the beginning
  1498. of the current line."
  1499. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1500. 'org-hd-marker string)))
  1501. (with-current-buffer (marker-buffer marker)
  1502. (save-excursion
  1503. (goto-char marker)
  1504. ,@body))))
  1505. (defun org-add-agenda-custom-command (entry)
  1506. "Replace or add a command in `org-agenda-custom-commands'.
  1507. This is mostly for hacking and trying a new command - once the command
  1508. works you probably want to add it to `org-agenda-custom-commands' for good."
  1509. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1510. (if ass
  1511. (setcdr ass (cdr entry))
  1512. (push entry org-agenda-custom-commands))))
  1513. ;;; Define the Org-agenda-mode
  1514. (defvar org-agenda-mode-map (make-sparse-keymap)
  1515. "Keymap for `org-agenda-mode'.")
  1516. (if (fboundp 'defvaralias)
  1517. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1518. (defvar org-agenda-menu) ; defined later in this file.
  1519. (defvar org-agenda-restrict) ; defined later in this file.
  1520. (defvar org-agenda-follow-mode nil)
  1521. (defvar org-agenda-entry-text-mode nil)
  1522. (defvar org-agenda-clockreport-mode nil)
  1523. (defvar org-agenda-show-log nil)
  1524. (defvar org-agenda-redo-command nil)
  1525. (defvar org-agenda-query-string nil)
  1526. (defvar org-agenda-mode-hook nil
  1527. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1528. (defvar org-agenda-type nil)
  1529. (defvar org-agenda-force-single-file nil)
  1530. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1531. (defun org-agenda-mode ()
  1532. "Mode for time-sorted view on action items in Org-mode files.
  1533. The following commands are available:
  1534. \\{org-agenda-mode-map}"
  1535. (interactive)
  1536. (kill-all-local-variables)
  1537. (setq org-agenda-undo-list nil
  1538. org-agenda-pending-undo-list nil
  1539. org-agenda-bulk-marked-entries nil)
  1540. (setq major-mode 'org-agenda-mode)
  1541. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1542. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1543. (setq mode-name "Org-Agenda")
  1544. (use-local-map org-agenda-mode-map)
  1545. (easy-menu-add org-agenda-menu)
  1546. (if org-startup-truncated (setq truncate-lines t))
  1547. (org-set-local 'line-move-visual nil)
  1548. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1549. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1550. ;; Make sure properties are removed when copying text
  1551. (when (boundp 'buffer-substring-filters)
  1552. (org-set-local 'buffer-substring-filters
  1553. (cons (lambda (x)
  1554. (set-text-properties 0 (length x) nil x) x)
  1555. buffer-substring-filters)))
  1556. (unless org-agenda-keep-modes
  1557. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1558. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1559. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1560. org-agenda-show-log org-agenda-start-with-log-mode))
  1561. (easy-menu-change
  1562. '("Agenda") "Agenda Files"
  1563. (append
  1564. (list
  1565. (vector
  1566. (if (get 'org-agenda-files 'org-restrict)
  1567. "Restricted to single file"
  1568. "Edit File List")
  1569. '(org-edit-agenda-file-list)
  1570. (not (get 'org-agenda-files 'org-restrict)))
  1571. "--")
  1572. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1573. (org-agenda-set-mode-name)
  1574. (apply
  1575. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1576. (list 'org-agenda-mode-hook)))
  1577. (substitute-key-definition 'undo 'org-agenda-undo
  1578. org-agenda-mode-map global-map)
  1579. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1580. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1581. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1582. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1583. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1584. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1585. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1586. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1587. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1588. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1589. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1590. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1591. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1592. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1593. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1594. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1595. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1596. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1597. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1598. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1599. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1600. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1601. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1602. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1603. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1604. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1605. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1606. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1607. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1608. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1609. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1610. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1611. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1612. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1613. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1614. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1615. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1616. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1617. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1618. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1619. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1620. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1621. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1622. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1623. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1624. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1625. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1627. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1628. (while l (org-defkey org-agenda-mode-map
  1629. (int-to-string (pop l)) 'digit-argument)))
  1630. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1631. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1632. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1633. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1634. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1635. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1636. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1637. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1638. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1639. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1640. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1641. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1642. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1643. 'org-clock-modify-effort-estimate)
  1644. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1645. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1646. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1647. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1648. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1649. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1650. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1651. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1652. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1653. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1654. (substitute-key-definition 'next-line 'org-agenda-next-line
  1655. org-agenda-mode-map global-map)
  1656. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1657. org-agenda-mode-map global-map)
  1658. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1659. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1660. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1661. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1662. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1663. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1664. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1665. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1666. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1667. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1668. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1669. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1670. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1671. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1672. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1673. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1674. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1675. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1676. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1677. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1678. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1679. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1680. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1681. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1682. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1683. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1684. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1685. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1686. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1687. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1688. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1689. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1690. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1691. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1692. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1693. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1694. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1695. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1696. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1697. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1698. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1699. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1700. (when org-agenda-mouse-1-follows-link
  1701. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1702. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1703. '("Agenda"
  1704. ("Agenda Files")
  1705. "--"
  1706. ("Agenda Dates"
  1707. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1708. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1709. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1710. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1711. "--"
  1712. ("View"
  1713. ["Day View" org-agenda-day-view
  1714. :active (org-agenda-check-type nil 'agenda)
  1715. :style radio :selected (eq org-agenda-current-span 'day)
  1716. :keys "v d (or just d)"]
  1717. ["Week View" org-agenda-week-view
  1718. :active (org-agenda-check-type nil 'agenda)
  1719. :style radio :selected (eq org-agenda-current-span 'week)
  1720. :keys "v w (or just w)"]
  1721. ["Month View" org-agenda-month-view
  1722. :active (org-agenda-check-type nil 'agenda)
  1723. :style radio :selected (eq org-agenda-current-span 'month)
  1724. :keys "v m"]
  1725. ["Year View" org-agenda-year-view
  1726. :active (org-agenda-check-type nil 'agenda)
  1727. :style radio :selected (eq org-agenda-current-span 'year)
  1728. :keys "v y"]
  1729. "--"
  1730. ["Include Diary" org-agenda-toggle-diary
  1731. :style toggle :selected org-agenda-include-diary
  1732. :active (org-agenda-check-type nil 'agenda)]
  1733. ["Include Deadlines" org-agenda-toggle-deadlines
  1734. :style toggle :selected org-agenda-include-deadlines
  1735. :active (org-agenda-check-type nil 'agenda)]
  1736. ["Use Time Grid" org-agenda-toggle-time-grid
  1737. :style toggle :selected org-agenda-use-time-grid
  1738. :active (org-agenda-check-type nil 'agenda)]
  1739. "--"
  1740. ["Show clock report" org-agenda-clockreport-mode
  1741. :style toggle :selected org-agenda-clockreport-mode
  1742. :active (org-agenda-check-type nil 'agenda)]
  1743. ["Show some entry text" org-agenda-entry-text-mode
  1744. :style toggle :selected org-agenda-entry-text-mode
  1745. :active t]
  1746. "--"
  1747. ["Show Logbook entries" org-agenda-log-mode
  1748. :style toggle :selected org-agenda-show-log
  1749. :active (org-agenda-check-type nil 'agenda 'timeline)
  1750. :keys "v l (or just l)"]
  1751. ["Include archived trees" org-agenda-archives-mode
  1752. :style toggle :selected org-agenda-archives-mode :active t
  1753. :keys "v a"]
  1754. ["Include archive files" (org-agenda-archives-mode t)
  1755. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1756. :keys "v A"]
  1757. "--"
  1758. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1759. ["Write view to file" org-write-agenda t]
  1760. ["Rebuild buffer" org-agenda-redo t]
  1761. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1762. "--"
  1763. ["Show original entry" org-agenda-show t]
  1764. ["Go To (other window)" org-agenda-goto t]
  1765. ["Go To (this window)" org-agenda-switch-to t]
  1766. ["Follow Mode" org-agenda-follow-mode
  1767. :style toggle :selected org-agenda-follow-mode :active t]
  1768. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1769. "--"
  1770. ("TODO"
  1771. ["Cycle TODO" org-agenda-todo t]
  1772. ["Next TODO set" org-agenda-todo-nextset t]
  1773. ["Previous TODO set" org-agenda-todo-previousset t]
  1774. ["Add note" org-agenda-add-note t])
  1775. ("Archive/Refile/Delete"
  1776. ["Archive default" org-agenda-archive-default t]
  1777. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1778. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1779. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1780. ["Archive subtree" org-agenda-archive t]
  1781. "--"
  1782. ["Refile" org-agenda-refile t]
  1783. "--"
  1784. ["Delete subtree" org-agenda-kill t])
  1785. ("Bulk action"
  1786. ["Mark entry" org-agenda-bulk-mark t]
  1787. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1788. ["Unmark entry" org-agenda-bulk-unmark t]
  1789. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1790. ["Act on all marked" org-agenda-bulk-action t]
  1791. "--"
  1792. ("Tags and Properties"
  1793. ["Show all Tags" org-agenda-show-tags t]
  1794. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1795. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1796. "--"
  1797. ["Column View" org-columns t])
  1798. ("Deadline/Schedule"
  1799. ["Schedule" org-agenda-schedule t]
  1800. ["Set Deadline" org-agenda-deadline t]
  1801. "--"
  1802. ["Mark item" org-agenda-action :active t :keys "k m"]
  1803. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1804. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1805. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1806. "--"
  1807. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1808. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1809. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1810. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1811. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1812. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1813. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1814. ("Clock and Effort"
  1815. ["Clock in" org-agenda-clock-in t]
  1816. ["Clock out" org-agenda-clock-out t]
  1817. ["Clock cancel" org-agenda-clock-cancel t]
  1818. ["Goto running clock" org-clock-goto t]
  1819. "--"
  1820. ["Set Effort" org-agenda-set-effort t]
  1821. ["Change clocked effort" org-clock-modify-effort-estimate
  1822. (org-clock-is-active)])
  1823. ("Priority"
  1824. ["Set Priority" org-agenda-priority t]
  1825. ["Increase Priority" org-agenda-priority-up t]
  1826. ["Decrease Priority" org-agenda-priority-down t]
  1827. ["Show Priority" org-agenda-show-priority t])
  1828. ("Calendar/Diary"
  1829. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1830. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1831. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1832. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1833. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1834. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1835. "--"
  1836. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1837. "--"
  1838. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1839. "--"
  1840. ("MobileOrg"
  1841. ["Push Files and Views" org-mobile-push t]
  1842. ["Get Captured and Flagged" org-mobile-pull t]
  1843. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1844. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1845. "--"
  1846. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1847. "--"
  1848. ["Quit" org-agenda-quit t]
  1849. ["Exit and Release Buffers" org-agenda-exit t]
  1850. ))
  1851. ;;; Agenda undo
  1852. (defvar org-agenda-allow-remote-undo t
  1853. "Non-nil means allow remote undo from the agenda buffer.")
  1854. (defvar org-agenda-undo-list nil
  1855. "List of undoable operations in the agenda since last refresh.")
  1856. (defvar org-agenda-undo-has-started-in nil
  1857. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1858. (defvar org-agenda-pending-undo-list nil
  1859. "In a series of undo commands, this is the list of remaining undo items.")
  1860. (defun org-agenda-undo ()
  1861. "Undo a remote editing step in the agenda.
  1862. This undoes changes both in the agenda buffer and in the remote buffer
  1863. that have been changed along."
  1864. (interactive)
  1865. (or org-agenda-allow-remote-undo
  1866. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1867. (if (not (eq this-command last-command))
  1868. (setq org-agenda-undo-has-started-in nil
  1869. org-agenda-pending-undo-list org-agenda-undo-list))
  1870. (if (not org-agenda-pending-undo-list)
  1871. (error "No further undo information"))
  1872. (let* ((entry (pop org-agenda-pending-undo-list))
  1873. buf line cmd rembuf)
  1874. (setq cmd (pop entry) line (pop entry))
  1875. (setq rembuf (nth 2 entry))
  1876. (org-with-remote-undo rembuf
  1877. (while (bufferp (setq buf (pop entry)))
  1878. (if (pop entry)
  1879. (with-current-buffer buf
  1880. (let ((last-undo-buffer buf)
  1881. (inhibit-read-only t))
  1882. (unless (memq buf org-agenda-undo-has-started-in)
  1883. (push buf org-agenda-undo-has-started-in)
  1884. (make-local-variable 'pending-undo-list)
  1885. (undo-start))
  1886. (while (and pending-undo-list
  1887. (listp pending-undo-list)
  1888. (not (car pending-undo-list)))
  1889. (pop pending-undo-list))
  1890. (undo-more 1))))))
  1891. (org-goto-line line)
  1892. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1893. (defun org-verify-change-for-undo (l1 l2)
  1894. "Verify that a real change occurred between the undo lists L1 and L2."
  1895. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1896. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1897. (not (eq l1 l2)))
  1898. ;;; Agenda dispatch
  1899. (defvar org-agenda-restrict nil)
  1900. (defvar org-agenda-restrict-begin (make-marker))
  1901. (defvar org-agenda-restrict-end (make-marker))
  1902. (defvar org-agenda-last-dispatch-buffer nil)
  1903. (defvar org-agenda-overriding-restriction nil)
  1904. ;;;###autoload
  1905. (defun org-agenda (&optional arg keys restriction)
  1906. "Dispatch agenda commands to collect entries to the agenda buffer.
  1907. Prompts for a command to execute. Any prefix arg will be passed
  1908. on to the selected command. The default selections are:
  1909. a Call `org-agenda-list' to display the agenda for current day or week.
  1910. t Call `org-todo-list' to display the global todo list.
  1911. T Call `org-todo-list' to display the global todo list, select only
  1912. entries with a specific TODO keyword (the user gets a prompt).
  1913. m Call `org-tags-view' to display headlines with tags matching
  1914. a condition (the user is prompted for the condition).
  1915. M Like `m', but select only TODO entries, no ordinary headlines.
  1916. L Create a timeline for the current buffer.
  1917. e Export views to associated files.
  1918. s Search entries for keywords.
  1919. / Multi occur across all agenda files and also files listed
  1920. in `org-agenda-text-search-extra-files'.
  1921. < Restrict agenda commands to buffer, subtree, or region.
  1922. Press several times to get the desired effect.
  1923. > Remove a previous restriction.
  1924. # List \"stuck\" projects.
  1925. ! Configure what \"stuck\" means.
  1926. C Configure custom agenda commands.
  1927. More commands can be added by configuring the variable
  1928. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1929. searches can be pre-defined in this way.
  1930. If the current buffer is in Org-mode and visiting a file, you can also
  1931. first press `<' once to indicate that the agenda should be temporarily
  1932. \(until the next use of \\[org-agenda]) restricted to the current file.
  1933. Pressing `<' twice means to restrict to the current subtree or region
  1934. \(if active)."
  1935. (interactive "P")
  1936. (catch 'exit
  1937. (let* ((prefix-descriptions nil)
  1938. (org-agenda-window-setup (if (equal (buffer-name)
  1939. org-agenda-buffer-name)
  1940. 'current-window
  1941. org-agenda-window-setup))
  1942. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1943. (org-agenda-custom-commands
  1944. ;; normalize different versions
  1945. (delq nil
  1946. (mapcar
  1947. (lambda (x)
  1948. (cond ((stringp (cdr x))
  1949. (push x prefix-descriptions)
  1950. nil)
  1951. ((stringp (nth 1 x)) x)
  1952. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1953. (t (cons (car x) (cons "" (cdr x))))))
  1954. org-agenda-custom-commands)))
  1955. (buf (current-buffer))
  1956. (bfn (buffer-file-name (buffer-base-buffer)))
  1957. entry key type match lprops ans)
  1958. ;; Turn off restriction unless there is an overriding one,
  1959. (unless org-agenda-overriding-restriction
  1960. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1961. ;; There is a request to keep the file list in place
  1962. (put 'org-agenda-files 'org-restrict nil))
  1963. (setq org-agenda-restrict nil)
  1964. (move-marker org-agenda-restrict-begin nil)
  1965. (move-marker org-agenda-restrict-end nil))
  1966. ;; Delete old local properties
  1967. (put 'org-agenda-redo-command 'org-lprops nil)
  1968. ;; Delete previously set last-arguments
  1969. (put 'org-agenda-redo-command 'last-args nil)
  1970. ;; Remember where this call originated
  1971. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1972. (unless keys
  1973. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1974. keys (car ans)
  1975. restriction (cdr ans)))
  1976. ;; Establish the restriction, if any
  1977. (when (and (not org-agenda-overriding-restriction) restriction)
  1978. (put 'org-agenda-files 'org-restrict (list bfn))
  1979. (cond
  1980. ((eq restriction 'region)
  1981. (setq org-agenda-restrict t)
  1982. (move-marker org-agenda-restrict-begin (region-beginning))
  1983. (move-marker org-agenda-restrict-end (region-end)))
  1984. ((eq restriction 'subtree)
  1985. (save-excursion
  1986. (setq org-agenda-restrict t)
  1987. (org-back-to-heading t)
  1988. (move-marker org-agenda-restrict-begin (point))
  1989. (move-marker org-agenda-restrict-end
  1990. (progn (org-end-of-subtree t)))))))
  1991. ;; For example the todo list should not need it (but does...)
  1992. (cond
  1993. ((setq entry (assoc keys org-agenda-custom-commands))
  1994. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1995. (progn
  1996. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1997. lprops (nth 4 entry))
  1998. (put 'org-agenda-redo-command 'org-lprops lprops)
  1999. (cond
  2000. ((eq type 'agenda)
  2001. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2002. ((eq type 'alltodo)
  2003. (org-let lprops '(org-todo-list current-prefix-arg)))
  2004. ((eq type 'search)
  2005. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2006. ((eq type 'stuck)
  2007. (org-let lprops '(org-agenda-list-stuck-projects
  2008. current-prefix-arg)))
  2009. ((eq type 'tags)
  2010. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2011. ((eq type 'tags-todo)
  2012. (org-let lprops '(org-tags-view '(4) match)))
  2013. ((eq type 'todo)
  2014. (org-let lprops '(org-todo-list match)))
  2015. ((eq type 'tags-tree)
  2016. (org-check-for-org-mode)
  2017. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2018. ((eq type 'todo-tree)
  2019. (org-check-for-org-mode)
  2020. (org-let lprops
  2021. '(org-occur (concat "^" outline-regexp "[ \t]*"
  2022. (regexp-quote match) "\\>"))))
  2023. ((eq type 'occur-tree)
  2024. (org-check-for-org-mode)
  2025. (org-let lprops '(org-occur match)))
  2026. ((functionp type)
  2027. (org-let lprops '(funcall type match)))
  2028. ((fboundp type)
  2029. (org-let lprops '(funcall type match)))
  2030. (t (error "Invalid custom agenda command type %s" type))))
  2031. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2032. ((equal keys "C")
  2033. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2034. (customize-variable 'org-agenda-custom-commands))
  2035. ((equal keys "a") (call-interactively 'org-agenda-list))
  2036. ((equal keys "s") (call-interactively 'org-search-view))
  2037. ((equal keys "t") (call-interactively 'org-todo-list))
  2038. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2039. ((equal keys "m") (call-interactively 'org-tags-view))
  2040. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2041. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2042. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2043. (org-add-hook
  2044. 'post-command-hook
  2045. (lambda ()
  2046. (unless (current-message)
  2047. (let* ((m (org-agenda-get-any-marker))
  2048. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2049. (when note
  2050. (message (concat
  2051. "FLAGGING-NOTE ([?] for more info): "
  2052. (org-add-props
  2053. (replace-regexp-in-string
  2054. "\\\\n" "//"
  2055. (copy-sequence note))
  2056. nil 'face 'org-warning)))))))
  2057. t t))
  2058. ((equal keys "L")
  2059. (unless (org-mode-p)
  2060. (error "This is not an Org-mode file"))
  2061. (unless restriction
  2062. (put 'org-agenda-files 'org-restrict (list bfn))
  2063. (org-call-with-arg 'org-timeline arg)))
  2064. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2065. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2066. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2067. (t (error "Invalid agenda key"))))))
  2068. (defun org-agenda-append-agenda ()
  2069. "Append another agenda view to the current one.
  2070. This function allows interactive building of block agendas.
  2071. Agenda views are separated by `org-agenda-block-separator'."
  2072. (interactive)
  2073. (unless (string= (buffer-name) org-agenda-buffer-name)
  2074. (error "Can only append from within agenda buffer"))
  2075. (let ((org-agenda-multi t))
  2076. (org-agenda)
  2077. (widen)))
  2078. (defun org-agenda-normalize-custom-commands (cmds)
  2079. (delq nil
  2080. (mapcar
  2081. (lambda (x)
  2082. (cond ((stringp (cdr x)) nil)
  2083. ((stringp (nth 1 x)) x)
  2084. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2085. (t (cons (car x) (cons "" (cdr x))))))
  2086. cmds)))
  2087. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2088. "The user interface for selecting an agenda command."
  2089. (catch 'exit
  2090. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2091. (restrict-ok (and bfn (org-mode-p)))
  2092. (region-p (org-region-active-p))
  2093. (custom org-agenda-custom-commands)
  2094. (selstring "")
  2095. restriction second-time
  2096. c entry key type match prefixes rmheader header-end custom1 desc
  2097. line lines left right n n1)
  2098. (save-window-excursion
  2099. (delete-other-windows)
  2100. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2101. (erase-buffer)
  2102. (insert (eval-when-compile
  2103. (let ((header
  2104. "
  2105. Press key for an agenda command: < Buffer, subtree/region restriction
  2106. -------------------------------- > Remove restriction
  2107. a Agenda for current week or day e Export agenda views
  2108. t List of all TODO entries T Entries with special TODO kwd
  2109. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2110. L Timeline for current buffer # List stuck projects (!=configure)
  2111. s Search for keywords C Configure custom agenda commands
  2112. / Multi-occur ? Find :FLAGGED: entries
  2113. ")
  2114. (start 0))
  2115. (while (string-match
  2116. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2117. header start)
  2118. (setq start (match-end 0))
  2119. (add-text-properties (match-beginning 2) (match-end 2)
  2120. '(face bold) header))
  2121. header)))
  2122. (setq header-end (move-marker (make-marker) (point)))
  2123. (while t
  2124. (setq custom1 custom)
  2125. (when (eq rmheader t)
  2126. (org-goto-line 1)
  2127. (re-search-forward ":" nil t)
  2128. (delete-region (match-end 0) (point-at-eol))
  2129. (forward-char 1)
  2130. (looking-at "-+")
  2131. (delete-region (match-end 0) (point-at-eol))
  2132. (move-marker header-end (match-end 0)))
  2133. (goto-char header-end)
  2134. (delete-region (point) (point-max))
  2135. ;; Produce all the lines that describe custom commands and prefixes
  2136. (setq lines nil)
  2137. (while (setq entry (pop custom1))
  2138. (setq key (car entry) desc (nth 1 entry)
  2139. type (nth 2 entry)
  2140. match (nth 3 entry))
  2141. (if (> (length key) 1)
  2142. (add-to-list 'prefixes (string-to-char key))
  2143. (setq line
  2144. (format
  2145. "%-4s%-14s"
  2146. (org-add-props (copy-sequence key)
  2147. '(face bold))
  2148. (cond
  2149. ((string-match "\\S-" desc) desc)
  2150. ((eq type 'agenda) "Agenda for current week or day")
  2151. ((eq type 'alltodo) "List of all TODO entries")
  2152. ((eq type 'search) "Word search")
  2153. ((eq type 'stuck) "List of stuck projects")
  2154. ((eq type 'todo) "TODO keyword")
  2155. ((eq type 'tags) "Tags query")
  2156. ((eq type 'tags-todo) "Tags (TODO)")
  2157. ((eq type 'tags-tree) "Tags tree")
  2158. ((eq type 'todo-tree) "TODO kwd tree")
  2159. ((eq type 'occur-tree) "Occur tree")
  2160. ((functionp type) (if (symbolp type)
  2161. (symbol-name type)
  2162. "Lambda expression"))
  2163. (t "???"))))
  2164. (if org-agenda-menu-show-matcher
  2165. (setq line
  2166. (concat line ": "
  2167. (cond
  2168. ((stringp match)
  2169. (setq match (copy-sequence match))
  2170. (org-add-props match nil 'face 'org-warning))
  2171. (match
  2172. (format "set of %d commands" (length match)))
  2173. (t ""))))
  2174. (if (org-string-nw-p match)
  2175. (add-text-properties
  2176. 0 (length line) (list 'help-echo
  2177. (concat "Matcher: "match)) line)))
  2178. (push line lines)))
  2179. (setq lines (nreverse lines))
  2180. (when prefixes
  2181. (mapc (lambda (x)
  2182. (push
  2183. (format "%s %s"
  2184. (org-add-props (char-to-string x)
  2185. nil 'face 'bold)
  2186. (or (cdr (assoc (concat selstring
  2187. (char-to-string x))
  2188. prefix-descriptions))
  2189. "Prefix key"))
  2190. lines))
  2191. prefixes))
  2192. ;; Check if we should display in two columns
  2193. (if org-agenda-menu-two-column
  2194. (progn
  2195. (setq n (length lines)
  2196. n1 (+ (/ n 2) (mod n 2))
  2197. right (nthcdr n1 lines)
  2198. left (copy-sequence lines))
  2199. (setcdr (nthcdr (1- n1) left) nil))
  2200. (setq left lines right nil))
  2201. (while left
  2202. (insert "\n" (pop left))
  2203. (when right
  2204. (if (< (current-column) 40)
  2205. (move-to-column 40 t)
  2206. (insert " "))
  2207. (insert (pop right))))
  2208. ;; Make the window the right size
  2209. (goto-char (point-min))
  2210. (if second-time
  2211. (if (not (pos-visible-in-window-p (point-max)))
  2212. (org-fit-window-to-buffer))
  2213. (setq second-time t)
  2214. (org-fit-window-to-buffer))
  2215. ;; Ask for selection
  2216. (message "Press key for agenda command%s:"
  2217. (if (or restrict-ok org-agenda-overriding-restriction)
  2218. (if org-agenda-overriding-restriction
  2219. " (restriction lock active)"
  2220. (if restriction
  2221. (format " (restricted to %s)" restriction)
  2222. " (unrestricted)"))
  2223. ""))
  2224. (setq c (read-char-exclusive))
  2225. (message "")
  2226. (cond
  2227. ((assoc (char-to-string c) custom)
  2228. (setq selstring (concat selstring (char-to-string c)))
  2229. (throw 'exit (cons selstring restriction)))
  2230. ((memq c prefixes)
  2231. (setq selstring (concat selstring (char-to-string c))
  2232. prefixes nil
  2233. rmheader (or rmheader t)
  2234. custom (delq nil (mapcar
  2235. (lambda (x)
  2236. (if (or (= (length (car x)) 1)
  2237. (/= (string-to-char (car x)) c))
  2238. nil
  2239. (cons (substring (car x) 1) (cdr x))))
  2240. custom))))
  2241. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2242. (message "Restriction is only possible in Org-mode buffers")
  2243. (ding) (sit-for 1))
  2244. ((eq c ?1)
  2245. (org-agenda-remove-restriction-lock 'noupdate)
  2246. (setq restriction 'buffer))
  2247. ((eq c ?0)
  2248. (org-agenda-remove-restriction-lock 'noupdate)
  2249. (setq restriction (if region-p 'region 'subtree)))
  2250. ((eq c ?<)
  2251. (org-agenda-remove-restriction-lock 'noupdate)
  2252. (setq restriction
  2253. (cond
  2254. ((eq restriction 'buffer)
  2255. (if region-p 'region 'subtree))
  2256. ((memq restriction '(subtree region))
  2257. nil)
  2258. (t 'buffer))))
  2259. ((eq c ?>)
  2260. (org-agenda-remove-restriction-lock 'noupdate)
  2261. (setq restriction nil))
  2262. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2263. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2264. ((and (> (length selstring) 0) (eq c ?\d))
  2265. (delete-window)
  2266. (org-agenda-get-restriction-and-command prefix-descriptions))
  2267. ((equal c ?q) (error "Abort"))
  2268. (t (error "Invalid key %c" c))))))))
  2269. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2270. (defvar org-agenda-last-arguments nil
  2271. "The arguments of the previous call to `org-agenda'.")
  2272. (defun org-agenda-run-series (name series)
  2273. (org-let (nth 1 series) '(org-prepare-agenda name))
  2274. (let* ((org-agenda-multi t)
  2275. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2276. (org-agenda-overriding-arguments
  2277. (or org-agenda-overriding-arguments
  2278. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2279. (get 'org-agenda-redo-command 'last-args))))
  2280. (cmds (car series))
  2281. (gprops (nth 1 series))
  2282. match ;; The byte compiler incorrectly complains about this. Keep it!
  2283. cmd type lprops)
  2284. (while (setq cmd (pop cmds))
  2285. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2286. (cond
  2287. ((eq type 'agenda)
  2288. (org-let2 gprops lprops
  2289. '(call-interactively 'org-agenda-list)))
  2290. ((eq type 'alltodo)
  2291. (org-let2 gprops lprops
  2292. '(call-interactively 'org-todo-list)))
  2293. ((eq type 'search)
  2294. (org-let2 gprops lprops
  2295. '(org-search-view current-prefix-arg match nil)))
  2296. ((eq type 'stuck)
  2297. (org-let2 gprops lprops
  2298. '(call-interactively 'org-agenda-list-stuck-projects)))
  2299. ((eq type 'tags)
  2300. (org-let2 gprops lprops
  2301. '(org-tags-view current-prefix-arg match)))
  2302. ((eq type 'tags-todo)
  2303. (org-let2 gprops lprops
  2304. '(org-tags-view '(4) match)))
  2305. ((eq type 'todo)
  2306. (org-let2 gprops lprops
  2307. '(org-todo-list match)))
  2308. ((fboundp type)
  2309. (org-let2 gprops lprops
  2310. '(funcall type match)))
  2311. (t (error "Invalid type in command series"))))
  2312. (widen)
  2313. (setq org-agenda-redo-command redo)
  2314. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2315. (goto-char (point-min)))
  2316. (org-fit-agenda-window)
  2317. (org-let (nth 1 series) '(org-finalize-agenda)))
  2318. ;;;###autoload
  2319. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2320. "Run an agenda command in batch mode and send the result to STDOUT.
  2321. If CMD-KEY is a string of length 1, it is used as a key in
  2322. `org-agenda-custom-commands' and triggers this command. If it is a
  2323. longer string it is used as a tags/todo match string.
  2324. Parameters are alternating variable names and values that will be bound
  2325. before running the agenda command."
  2326. (let (pars)
  2327. (while parameters
  2328. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2329. (if (> (length cmd-key) 2)
  2330. (eval (list 'let (nreverse pars)
  2331. (list 'org-tags-view nil cmd-key)))
  2332. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2333. (set-buffer org-agenda-buffer-name)
  2334. (princ (org-encode-for-stdout (buffer-string)))))
  2335. ;(defun org-encode-for-stdout (string)
  2336. ; (if (fboundp 'encode-coding-string)
  2337. ; (encode-coding-string string buffer-file-coding-system)
  2338. ; string))
  2339. (defun org-encode-for-stdout (string)
  2340. string)
  2341. (defvar org-agenda-info nil)
  2342. ;;;###autoload
  2343. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2344. "Run an agenda command in batch mode and send the result to STDOUT.
  2345. If CMD-KEY is a string of length 1, it is used as a key in
  2346. `org-agenda-custom-commands' and triggers this command. If it is a
  2347. longer string it is used as a tags/todo match string.
  2348. Parameters are alternating variable names and values that will be bound
  2349. before running the agenda command.
  2350. The output gives a line for each selected agenda item. Each
  2351. item is a list of comma-separated values, like this:
  2352. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2353. category The category of the item
  2354. head The headline, without TODO kwd, TAGS and PRIORITY
  2355. type The type of the agenda entry, can be
  2356. todo selected in TODO match
  2357. tagsmatch selected in tags match
  2358. diary imported from diary
  2359. deadline a deadline on given date
  2360. scheduled scheduled on given date
  2361. timestamp entry has timestamp on given date
  2362. closed entry was closed on given date
  2363. upcoming-deadline warning about deadline
  2364. past-scheduled forwarded scheduled item
  2365. block entry has date block including g. date
  2366. todo The todo keyword, if any
  2367. tags All tags including inherited ones, separated by colons
  2368. date The relevant date, like 2007-2-14
  2369. time The time, like 15:00-16:50
  2370. extra Sting with extra planning info
  2371. priority-l The priority letter if any was given
  2372. priority-n The computed numerical priority
  2373. agenda-day The day in the agenda where this is listed"
  2374. (let (pars)
  2375. (while parameters
  2376. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2377. (push (list 'org-agenda-remove-tags t) pars)
  2378. (if (> (length cmd-key) 2)
  2379. (eval (list 'let (nreverse pars)
  2380. (list 'org-tags-view nil cmd-key)))
  2381. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2382. (set-buffer org-agenda-buffer-name)
  2383. (let* ((lines (org-split-string (buffer-string) "\n"))
  2384. line)
  2385. (while (setq line (pop lines))
  2386. (catch 'next
  2387. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2388. (setq org-agenda-info
  2389. (org-fix-agenda-info (text-properties-at 0 line)))
  2390. (princ
  2391. (org-encode-for-stdout
  2392. (mapconcat 'org-agenda-export-csv-mapper
  2393. '(org-category txt type todo tags date time extra
  2394. priority-letter priority agenda-day)
  2395. ",")))
  2396. (princ "\n"))))))
  2397. (defun org-fix-agenda-info (props)
  2398. "Make sure all properties on an agenda item have a canonical form.
  2399. This ensures the export commands can easily use it."
  2400. (let (tmp re)
  2401. (when (setq tmp (plist-get props 'tags))
  2402. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2403. (when (setq tmp (plist-get props 'date))
  2404. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2405. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2406. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2407. (setq tmp (calendar-date-string tmp)))
  2408. (setq props (plist-put props 'date tmp)))
  2409. (when (setq tmp (plist-get props 'day))
  2410. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2411. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2412. (setq tmp (calendar-date-string tmp)))
  2413. (setq props (plist-put props 'day tmp))
  2414. (setq props (plist-put props 'agenda-day tmp)))
  2415. (when (setq tmp (plist-get props 'txt))
  2416. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2417. (plist-put props 'priority-letter (match-string 1 tmp))
  2418. (setq tmp (replace-match "" t t tmp)))
  2419. (when (and (setq re (plist-get props 'org-todo-regexp))
  2420. (setq re (concat "\\`\\.*" re " ?"))
  2421. (string-match re tmp))
  2422. (plist-put props 'todo (match-string 1 tmp))
  2423. (setq tmp (replace-match "" t t tmp)))
  2424. (plist-put props 'txt tmp)))
  2425. props)
  2426. (defun org-agenda-export-csv-mapper (prop)
  2427. (let ((res (plist-get org-agenda-info prop)))
  2428. (setq res
  2429. (cond
  2430. ((not res) "")
  2431. ((stringp res) res)
  2432. (t (prin1-to-string res))))
  2433. (while (string-match "," res)
  2434. (setq res (replace-match ";" t t res)))
  2435. (org-trim res)))
  2436. ;;;###autoload
  2437. (defun org-store-agenda-views (&rest parameters)
  2438. (interactive)
  2439. (eval (list 'org-batch-store-agenda-views)))
  2440. ;; FIXME, why is this a macro?????
  2441. ;;;###autoload
  2442. (defmacro org-batch-store-agenda-views (&rest parameters)
  2443. "Run all custom agenda commands that have a file argument."
  2444. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2445. (pop-up-frames nil)
  2446. (dir default-directory)
  2447. pars cmd thiscmdkey files opts cmd-or-set)
  2448. (while parameters
  2449. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2450. (setq pars (reverse pars))
  2451. (save-window-excursion
  2452. (while cmds
  2453. (setq cmd (pop cmds)
  2454. thiscmdkey (car cmd)
  2455. cmd-or-set (nth 2 cmd)
  2456. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2457. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2458. (if (stringp files) (setq files (list files)))
  2459. (when files
  2460. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2461. (list 'org-agenda nil thiscmdkey)))
  2462. (set-buffer org-agenda-buffer-name)
  2463. (while files
  2464. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2465. (list 'org-write-agenda
  2466. (expand-file-name (pop files) dir) nil t))))
  2467. (and (get-buffer org-agenda-buffer-name)
  2468. (kill-buffer org-agenda-buffer-name)))))))
  2469. (defun org-agenda-mark-header-line (pos)
  2470. "Mark the line at POS as an agenda structure header."
  2471. (save-excursion
  2472. (goto-char pos)
  2473. (put-text-property (point-at-bol) (point-at-eol)
  2474. 'org-agenda-structural-header t)
  2475. (when org-agenda-title-append
  2476. (put-text-property (point-at-bol) (point-at-eol)
  2477. 'org-agenda-title-append org-agenda-title-append))))
  2478. (defvar org-mobile-creating-agendas)
  2479. (defun org-write-agenda (file &optional open nosettings)
  2480. "Write the current buffer (an agenda view) as a file.
  2481. Depending on the extension of the file name, plain text (.txt),
  2482. HTML (.html or .htm) or Postscript (.ps) is produced.
  2483. If the extension is .ics, run icalendar export over all files used
  2484. to construct the agenda and limit the export to entries listed in the
  2485. agenda now.
  2486. With prefix argument OPEN, open the new file immediately.
  2487. If NOSETTINGS is given, do not scope the settings of
  2488. `org-agenda-exporter-settings' into the export commands. This is used when
  2489. the settings have already been scoped and we do not wish to overrule other,
  2490. higher priority settings."
  2491. (interactive "FWrite agenda to file: \nP")
  2492. (if (not (file-writable-p file))
  2493. (error "Cannot write agenda to file %s" file))
  2494. (org-let (if nosettings nil org-agenda-exporter-settings)
  2495. '(save-excursion
  2496. (save-window-excursion
  2497. (org-agenda-mark-filtered-text)
  2498. (let ((bs (copy-sequence (buffer-string))) beg)
  2499. (org-agenda-unmark-filtered-text)
  2500. (with-temp-buffer
  2501. (rename-buffer "Agenda View" t)
  2502. (set-buffer-modified-p nil)
  2503. (insert bs)
  2504. (org-agenda-remove-marked-text 'org-filtered)
  2505. (while (setq beg (text-property-any (point-min) (point-max)
  2506. 'org-filtered t))
  2507. (delete-region
  2508. beg (or (next-single-property-change beg 'org-filtered)
  2509. (point-max))))
  2510. (run-hooks 'org-agenda-before-write-hook)
  2511. (cond
  2512. ((org-bound-and-true-p org-mobile-creating-agendas)
  2513. (org-mobile-write-agenda-for-mobile file))
  2514. ((string-match "\\.html?\\'" file)
  2515. (require 'htmlize)
  2516. (set-buffer (htmlize-buffer (current-buffer)))
  2517. (when (and org-agenda-export-html-style
  2518. (string-match "<style>" org-agenda-export-html-style))
  2519. ;; replace <style> section with org-agenda-export-html-style
  2520. (goto-char (point-min))
  2521. (kill-region (- (search-forward "<style") 6)
  2522. (search-forward "</style>"))
  2523. (insert org-agenda-export-html-style))
  2524. (write-file file)
  2525. (kill-buffer (current-buffer))
  2526. (message "HTML written to %s" file))
  2527. ((string-match "\\.ps\\'" file)
  2528. (require 'ps-print)
  2529. (ps-print-buffer-with-faces file)
  2530. (message "Postscript written to %s" file))
  2531. ((string-match "\\.pdf\\'" file)
  2532. (require 'ps-print)
  2533. (ps-print-buffer-with-faces
  2534. (concat (file-name-sans-extension file) ".ps"))
  2535. (call-process "ps2pdf" nil nil nil
  2536. (expand-file-name
  2537. (concat (file-name-sans-extension file) ".ps"))
  2538. (expand-file-name file))
  2539. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2540. (message "PDF written to %s" file))
  2541. ((string-match "\\.ics\\'" file)
  2542. (require 'org-icalendar)
  2543. (let ((org-agenda-marker-table
  2544. (org-create-marker-find-array
  2545. (org-agenda-collect-markers)))
  2546. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2547. (org-combined-agenda-icalendar-file file))
  2548. (apply 'org-export-icalendar 'combine
  2549. (org-agenda-files nil 'ifmode))))
  2550. (t
  2551. (let ((bs (buffer-string)))
  2552. (find-file file)
  2553. (erase-buffer)
  2554. (insert bs)
  2555. (save-buffer 0)
  2556. (kill-buffer (current-buffer))
  2557. (message "Plain text written to %s" file))))))))
  2558. (set-buffer org-agenda-buffer-name))
  2559. (when open (org-open-file file)))
  2560. (defvar org-agenda-filter-overlays nil)
  2561. (defun org-agenda-mark-filtered-text ()
  2562. "Mark all text hidden by filtering with a text property."
  2563. (let ((inhibit-read-only t))
  2564. (mapc
  2565. (lambda (o)
  2566. (when (equal (overlay-buffer o) (current-buffer))
  2567. (put-text-property
  2568. (overlay-start o) (overlay-end o)
  2569. 'org-filtered t)))
  2570. org-agenda-filter-overlays)))
  2571. (defun org-agenda-unmark-filtered-text ()
  2572. "Remove the filtering text property."
  2573. (let ((inhibit-read-only t))
  2574. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2575. (defun org-agenda-remove-marked-text (property &optional value)
  2576. "Delete all text marked with VALUE of PROPERTY.
  2577. VALUE defaults to t."
  2578. (let (beg)
  2579. (setq value (or value t))
  2580. (while (setq beg (text-property-any (point-min) (point-max)
  2581. property value))
  2582. (delete-region
  2583. beg (or (next-single-property-change beg 'org-filtered)
  2584. (point-max))))))
  2585. (defun org-agenda-add-entry-text ()
  2586. "Add entry text to agenda lines.
  2587. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2588. entry text following headings shown in the agenda.
  2589. Drawers will be excluded, also the line with scheduling/deadline info."
  2590. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2591. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2592. (let (m txt)
  2593. (goto-char (point-min))
  2594. (while (not (eobp))
  2595. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2596. (beginning-of-line 2)
  2597. (setq txt (org-agenda-get-some-entry-text
  2598. m org-agenda-add-entry-text-maxlines " > "))
  2599. (end-of-line 1)
  2600. (if (string-match "\\S-" txt)
  2601. (insert "\n" txt)
  2602. (or (eobp) (forward-char 1))))))))
  2603. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2604. &rest keep)
  2605. "Extract entry text from MARKER, at most N-LINES lines.
  2606. This will ignore drawers etc, just get the text.
  2607. If INDENT is given, prefix every line with this string. If KEEP is
  2608. given, it is a list of symbols, defining stuff that should not be
  2609. removed from the entry content. Currently only `planning' is allowed here."
  2610. (let (txt drawer-re kwd-time-re ind)
  2611. (save-excursion
  2612. (with-current-buffer (marker-buffer marker)
  2613. (if (not (org-mode-p))
  2614. (setq txt "")
  2615. (save-excursion
  2616. (save-restriction
  2617. (widen)
  2618. (goto-char marker)
  2619. (end-of-line 1)
  2620. (setq txt (buffer-substring
  2621. (min (1+ (point)) (point-max))
  2622. (progn (outline-next-heading) (point)))
  2623. drawer-re org-drawer-regexp
  2624. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2625. ".*\n?"))
  2626. (with-temp-buffer
  2627. (insert txt)
  2628. (when org-agenda-add-entry-text-descriptive-links
  2629. (goto-char (point-min))
  2630. (while (org-activate-bracket-links (point-max))
  2631. (add-text-properties (match-beginning 0) (match-end 0)
  2632. '(face org-link))))
  2633. (goto-char (point-min))
  2634. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2635. (set-text-properties (match-beginning 0) (match-end 0)
  2636. nil))
  2637. (goto-char (point-min))
  2638. (while (re-search-forward drawer-re nil t)
  2639. (delete-region
  2640. (match-beginning 0)
  2641. (progn (re-search-forward
  2642. "^[ \t]*:END:.*\n?" nil 'move)
  2643. (point))))
  2644. (unless (member 'planning keep)
  2645. (goto-char (point-min))
  2646. (while (re-search-forward kwd-time-re nil t)
  2647. (replace-match "")))
  2648. (goto-char (point-min))
  2649. (when org-agenda-entry-text-exclude-regexps
  2650. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2651. (while (setq re (pop re-list))
  2652. (goto-char (point-min))
  2653. (while (re-search-forward re nil t)
  2654. (replace-match "")))))
  2655. (goto-char (point-max))
  2656. (skip-chars-backward " \t\n")
  2657. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2658. ;; find and remove min common indentation
  2659. (goto-char (point-min))
  2660. (untabify (point-min) (point-max))
  2661. (setq ind (org-get-indentation))
  2662. (while (not (eobp))
  2663. (unless (looking-at "[ \t]*$")
  2664. (setq ind (min ind (org-get-indentation))))
  2665. (beginning-of-line 2))
  2666. (goto-char (point-min))
  2667. (while (not (eobp))
  2668. (unless (looking-at "[ \t]*$")
  2669. (move-to-column ind)
  2670. (delete-region (point-at-bol) (point)))
  2671. (beginning-of-line 2))
  2672. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2673. (goto-char (point-min))
  2674. (when indent
  2675. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2676. (replace-match indent t t)))
  2677. (goto-char (point-min))
  2678. (while (looking-at "[ \t]*\n") (replace-match ""))
  2679. (goto-char (point-max))
  2680. (when (> (org-current-line)
  2681. n-lines)
  2682. (org-goto-line (1+ n-lines))
  2683. (backward-char 1))
  2684. (setq txt (buffer-substring (point-min) (point)))))))))
  2685. txt))
  2686. (defun org-agenda-collect-markers ()
  2687. "Collect the markers pointing to entries in the agenda buffer."
  2688. (let (m markers)
  2689. (save-excursion
  2690. (goto-char (point-min))
  2691. (while (not (eobp))
  2692. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2693. (org-get-at-bol 'org-marker)))
  2694. (push m markers))
  2695. (beginning-of-line 2)))
  2696. (nreverse markers)))
  2697. (defun org-create-marker-find-array (marker-list)
  2698. "Create a alist of files names with all marker positions in that file."
  2699. (let (f tbl m a p)
  2700. (while (setq m (pop marker-list))
  2701. (setq p (marker-position m)
  2702. f (buffer-file-name (or (buffer-base-buffer
  2703. (marker-buffer m))
  2704. (marker-buffer m))))
  2705. (if (setq a (assoc f tbl))
  2706. (push (marker-position m) (cdr a))
  2707. (push (list f p) tbl)))
  2708. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2709. tbl)))
  2710. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2711. (defun org-check-agenda-marker-table ()
  2712. "Check of the current entry is on the marker list."
  2713. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2714. a)
  2715. (and (setq a (assoc file org-agenda-marker-table))
  2716. (save-match-data
  2717. (save-excursion
  2718. (org-back-to-heading t)
  2719. (member (point) (cdr a)))))))
  2720. (defun org-check-for-org-mode ()
  2721. "Make sure current buffer is in org-mode. Error if not."
  2722. (or (org-mode-p)
  2723. (error "Cannot execute org-mode agenda command on buffer in %s"
  2724. major-mode)))
  2725. (defun org-fit-agenda-window ()
  2726. "Fit the window to the buffer size."
  2727. (and (memq org-agenda-window-setup '(reorganize-frame))
  2728. (fboundp 'fit-window-to-buffer)
  2729. (org-fit-window-to-buffer
  2730. nil
  2731. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2732. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2733. ;;; Agenda prepare and finalize
  2734. (defvar org-agenda-multi nil) ; dynamically scoped
  2735. (defvar org-agenda-buffer-name "*Org Agenda*")
  2736. (defvar org-pre-agenda-window-conf nil)
  2737. (defvar org-agenda-columns-active nil)
  2738. (defvar org-agenda-name nil)
  2739. (defvar org-agenda-filter nil)
  2740. (defvar org-agenda-filter-while-redo nil)
  2741. (defvar org-agenda-filter-preset nil
  2742. "A preset of the tags filter used for secondary agenda filtering.
  2743. This must be a list of strings, each string must be a single tag preceded
  2744. by \"+\" or \"-\".
  2745. This variable should not be set directly, but agenda custom commands can
  2746. bind it in the options section. The preset filter is a global property of
  2747. the entire agenda view. In a block agenda, it will not work reliably to
  2748. define a filter for one of the individual blocks. You need to set it in
  2749. the global options and expect it to be applied to the entire view.")
  2750. (defun org-prepare-agenda (&optional name)
  2751. (setq org-todo-keywords-for-agenda nil)
  2752. (setq org-done-keywords-for-agenda nil)
  2753. (setq org-drawers-for-agenda nil)
  2754. (unless org-agenda-persistent-filter
  2755. (setq org-agenda-filter nil))
  2756. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2757. (if org-agenda-multi
  2758. (progn
  2759. (setq buffer-read-only nil)
  2760. (goto-char (point-max))
  2761. (unless (or (bobp) org-agenda-compact-blocks
  2762. (not org-agenda-block-separator))
  2763. (insert "\n"
  2764. (if (stringp org-agenda-block-separator)
  2765. org-agenda-block-separator
  2766. (make-string (window-width) org-agenda-block-separator))
  2767. "\n"))
  2768. (narrow-to-region (point) (point-max)))
  2769. (org-agenda-reset-markers)
  2770. (setq org-agenda-contributing-files nil)
  2771. (setq org-agenda-columns-active nil)
  2772. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2773. (setq org-todo-keywords-for-agenda
  2774. (org-uniquify org-todo-keywords-for-agenda))
  2775. (setq org-done-keywords-for-agenda
  2776. (org-uniquify org-done-keywords-for-agenda))
  2777. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2778. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2779. (awin (get-buffer-window abuf)))
  2780. (cond
  2781. ((equal (current-buffer) abuf) nil)
  2782. (awin (select-window awin))
  2783. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2784. ((equal org-agenda-window-setup 'current-window)
  2785. (switch-to-buffer abuf))
  2786. ((equal org-agenda-window-setup 'other-window)
  2787. (org-switch-to-buffer-other-window abuf))
  2788. ((equal org-agenda-window-setup 'other-frame)
  2789. (switch-to-buffer-other-frame abuf))
  2790. ((equal org-agenda-window-setup 'reorganize-frame)
  2791. (delete-other-windows)
  2792. (org-switch-to-buffer-other-window abuf)))
  2793. ;; additional test in case agenda is invoked from within agenda
  2794. ;; buffer via elisp link
  2795. (unless (equal (current-buffer) abuf)
  2796. (switch-to-buffer abuf)))
  2797. (setq buffer-read-only nil)
  2798. (let ((inhibit-read-only t)) (erase-buffer))
  2799. (org-agenda-mode)
  2800. (and name (not org-agenda-name)
  2801. (org-set-local 'org-agenda-name name)))
  2802. (setq buffer-read-only nil))
  2803. (defun org-finalize-agenda ()
  2804. "Finishing touch for the agenda buffer, called just before displaying it."
  2805. (unless org-agenda-multi
  2806. (save-excursion
  2807. (let ((inhibit-read-only t))
  2808. (goto-char (point-min))
  2809. (while (org-activate-bracket-links (point-max))
  2810. (add-text-properties (match-beginning 0) (match-end 0)
  2811. '(face org-link)))
  2812. (org-agenda-align-tags)
  2813. (unless org-agenda-with-colors
  2814. (remove-text-properties (point-min) (point-max) '(face nil))))
  2815. (if (and (boundp 'org-agenda-overriding-columns-format)
  2816. org-agenda-overriding-columns-format)
  2817. (org-set-local 'org-agenda-overriding-columns-format
  2818. org-agenda-overriding-columns-format))
  2819. (if (and (boundp 'org-agenda-view-columns-initially)
  2820. org-agenda-view-columns-initially)
  2821. (org-agenda-columns))
  2822. (when org-agenda-fontify-priorities
  2823. (org-agenda-fontify-priorities))
  2824. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2825. (org-agenda-dim-blocked-tasks))
  2826. (org-agenda-mark-clocking-task)
  2827. (when org-agenda-entry-text-mode
  2828. (org-agenda-entry-text-hide)
  2829. (org-agenda-entry-text-show))
  2830. (if (functionp 'org-habit-insert-consistency-graphs)
  2831. (org-habit-insert-consistency-graphs))
  2832. (run-hooks 'org-finalize-agenda-hook)
  2833. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2834. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2835. (org-agenda-filter-apply org-agenda-filter))
  2836. )))
  2837. (defun org-agenda-mark-clocking-task ()
  2838. "Mark the current clock entry in the agenda if it is present."
  2839. (mapc (lambda (o)
  2840. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2841. (delete-overlay o)))
  2842. (overlays-in (point-min) (point-max)))
  2843. (when (marker-buffer org-clock-hd-marker)
  2844. (save-excursion
  2845. (goto-char (point-min))
  2846. (let (s ov)
  2847. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2848. (goto-char s)
  2849. (when (equal (org-get-at-bol 'org-hd-marker)
  2850. org-clock-hd-marker)
  2851. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2852. (overlay-put ov 'type 'org-agenda-clocking)
  2853. (overlay-put ov 'face 'org-agenda-clocking)
  2854. (overlay-put ov 'help-echo
  2855. "The clock is running in this item")))))))
  2856. (defun org-agenda-fontify-priorities ()
  2857. "Make highest priority lines bold, and lowest italic."
  2858. (interactive)
  2859. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2860. (delete-overlay o)))
  2861. (overlays-in (point-min) (point-max)))
  2862. (save-excursion
  2863. (let ((inhibit-read-only t)
  2864. b e p ov h l)
  2865. (goto-char (point-min))
  2866. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2867. (setq h (or (get-char-property (point) 'org-highest-priority)
  2868. org-highest-priority)
  2869. l (or (get-char-property (point) 'org-lowest-priority)
  2870. org-lowest-priority)
  2871. p (string-to-char (match-string 1))
  2872. b (match-beginning 0)
  2873. e (if (eq org-agenda-fontify-priorities 'cookies)
  2874. (match-end 0)
  2875. (point-at-eol))
  2876. ov (make-overlay b e))
  2877. (overlay-put
  2878. ov 'face
  2879. (cond ((org-face-from-face-or-color
  2880. 'priority nil
  2881. (cdr (assoc p org-priority-faces))))
  2882. ((and (listp org-agenda-fontify-priorities)
  2883. (org-face-from-face-or-color
  2884. 'priority nil
  2885. (cdr (assoc p org-agenda-fontify-priorities)))))
  2886. ((equal p l) 'italic)
  2887. ((equal p h) 'bold)))
  2888. (overlay-put ov 'org-type 'org-priority)))))
  2889. (defun org-agenda-dim-blocked-tasks ()
  2890. "Dim currently blocked TODO's in the agenda display."
  2891. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2892. (delete-overlay o)))
  2893. (overlays-in (point-min) (point-max)))
  2894. (save-excursion
  2895. (let ((inhibit-read-only t)
  2896. (org-depend-tag-blocked nil)
  2897. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2898. org-blocked-by-checkboxes
  2899. invis1 b e p ov h l)
  2900. (goto-char (point-min))
  2901. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2902. (and pos (goto-char (1+ pos))))
  2903. (setq org-blocked-by-checkboxes nil invis1 invis)
  2904. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2905. (when (and marker
  2906. (not (with-current-buffer (marker-buffer marker)
  2907. (save-excursion
  2908. (goto-char marker)
  2909. (if (org-entry-get nil "NOBLOCKING")
  2910. t ;; Never block this entry
  2911. (run-hook-with-args-until-failure
  2912. 'org-blocker-hook
  2913. (list :type 'todo-state-change
  2914. :position marker
  2915. :from 'todo
  2916. :to 'done)))))))
  2917. (if org-blocked-by-checkboxes (setq invis1 nil))
  2918. (setq b (if invis1
  2919. (max (point-min) (1- (point-at-bol)))
  2920. (point-at-bol))
  2921. e (point-at-eol)
  2922. ov (make-overlay b e))
  2923. (if invis1
  2924. (overlay-put ov 'invisible t)
  2925. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2926. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2927. (defvar org-agenda-skip-function nil
  2928. "Function to be called at each match during agenda construction.
  2929. If this function returns nil, the current match should not be skipped.
  2930. Otherwise, the function must return a position from where the search
  2931. should be continued.
  2932. This may also be a Lisp form, it will be evaluated.
  2933. Never set this variable using `setq' or so, because then it will apply
  2934. to all future agenda commands. If you do want a global skipping condition,
  2935. use the option `org-agenda-skip-function-global' instead.
  2936. The correct usage for `org-agenda-skip-function' is to bind it with
  2937. `let' to scope it dynamically into the agenda-constructing command.
  2938. A good way to set it is through options in `org-agenda-custom-commands'.")
  2939. (defun org-agenda-skip ()
  2940. "Throw to `:skip' in places that should be skipped.
  2941. Also moves point to the end of the skipped region, so that search can
  2942. continue from there."
  2943. (let ((p (point-at-bol)) to)
  2944. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2945. (get-text-property p :org-archived)
  2946. (org-end-of-subtree t)
  2947. (throw :skip t))
  2948. (and org-agenda-skip-comment-trees
  2949. (get-text-property p :org-comment)
  2950. (org-end-of-subtree t)
  2951. (throw :skip t))
  2952. (if (equal (char-after p) ?#) (throw :skip t))
  2953. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2954. (org-agenda-skip-eval org-agenda-skip-function)))
  2955. (goto-char to)
  2956. (throw :skip t))))
  2957. (defun org-agenda-skip-eval (form)
  2958. "If FORM is a function or a list, call (or eval) is and return result.
  2959. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2960. and match data are returned to the previous state no matter what these
  2961. functions do."
  2962. (let (fp)
  2963. (and form
  2964. (or (setq fp (functionp form))
  2965. (consp form))
  2966. (save-excursion
  2967. (save-match-data
  2968. (if fp
  2969. (funcall form)
  2970. (eval form)))))))
  2971. (defvar org-agenda-markers nil
  2972. "List of all currently active markers created by `org-agenda'.")
  2973. (defvar org-agenda-last-marker-time (org-float-time)
  2974. "Creation time of the last agenda marker.")
  2975. (defun org-agenda-new-marker (&optional pos)
  2976. "Return a new agenda marker.
  2977. Org-mode keeps a list of these markers and resets them when they are
  2978. no longer in use."
  2979. (let ((m (copy-marker (or pos (point)))))
  2980. (setq org-agenda-last-marker-time (org-float-time))
  2981. (push m org-agenda-markers)
  2982. m))
  2983. (defun org-agenda-reset-markers ()
  2984. "Reset markers created by `org-agenda'."
  2985. (while org-agenda-markers
  2986. (move-marker (pop org-agenda-markers) nil)))
  2987. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2988. "Save relative positions of markers in region."
  2989. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2990. org-agenda-markers))
  2991. ;;; Entry text mode
  2992. (defun org-agenda-entry-text-show-here ()
  2993. "Add some text from the entry as context to the current line."
  2994. (let (m txt o)
  2995. (setq m (org-get-at-bol 'org-hd-marker))
  2996. (unless (marker-buffer m)
  2997. (error "No marker points to an entry here"))
  2998. (setq txt (concat "\n" (org-no-properties
  2999. (org-agenda-get-some-entry-text
  3000. m org-agenda-entry-text-maxlines " > "))))
  3001. (when (string-match "\\S-" txt)
  3002. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3003. (overlay-put o 'evaporate t)
  3004. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3005. (overlay-put o 'after-string txt))))
  3006. (defun org-agenda-entry-text-show ()
  3007. "Add entry context for all agenda lines."
  3008. (interactive)
  3009. (save-excursion
  3010. (goto-char (point-max))
  3011. (beginning-of-line 1)
  3012. (while (not (bobp))
  3013. (when (org-get-at-bol 'org-hd-marker)
  3014. (org-agenda-entry-text-show-here))
  3015. (beginning-of-line 0))))
  3016. (defun org-agenda-entry-text-hide ()
  3017. "Remove any shown entry context."
  3018. (delq nil
  3019. (mapcar (lambda (o)
  3020. (if (eq (overlay-get o 'org-overlay-type)
  3021. 'agenda-entry-content)
  3022. (progn (delete-overlay o) t)))
  3023. (overlays-in (point-min) (point-max)))))
  3024. (defun org-agenda-get-day-face (date)
  3025. "Return the face DATE should be displayed with."
  3026. (or (and (functionp org-agenda-day-face-function)
  3027. (funcall org-agenda-day-face-function date))
  3028. (cond ((org-agenda-todayp date)
  3029. 'org-agenda-date-today)
  3030. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3031. 'org-agenda-date-weekend)
  3032. (t 'org-agenda-date))))
  3033. ;;; Agenda timeline
  3034. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3035. (defun org-timeline (&optional include-all)
  3036. "Show a time-sorted view of the entries in the current org file.
  3037. Only entries with a time stamp of today or later will be listed. With
  3038. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3039. under the current date.
  3040. If the buffer contains an active region, only check the region for
  3041. dates."
  3042. (interactive "P")
  3043. (org-compile-prefix-format 'timeline)
  3044. (org-set-sorting-strategy 'timeline)
  3045. (let* ((dopast t)
  3046. (dotodo include-all)
  3047. (doclosed org-agenda-show-log)
  3048. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3049. (current-buffer))))
  3050. (date (calendar-current-date))
  3051. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3052. (end (if (org-region-active-p) (region-end) (point-max)))
  3053. (day-numbers (org-get-all-dates beg end 'no-ranges
  3054. t doclosed ; always include today
  3055. org-timeline-show-empty-dates))
  3056. (org-deadline-warning-days 0)
  3057. (org-agenda-only-exact-dates t)
  3058. (today (org-today))
  3059. (past t)
  3060. args
  3061. s e rtn d emptyp)
  3062. (setq org-agenda-redo-command
  3063. (list 'progn
  3064. (list 'org-switch-to-buffer-other-window (current-buffer))
  3065. (list 'org-timeline (list 'quote include-all))))
  3066. (if (not dopast)
  3067. ;; Remove past dates from the list of dates.
  3068. (setq day-numbers (delq nil (mapcar (lambda(x)
  3069. (if (>= x today) x nil))
  3070. day-numbers))))
  3071. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3072. (if doclosed (push :closed args))
  3073. (push :timestamp args)
  3074. (push :deadline args)
  3075. (push :scheduled args)
  3076. (push :sexp args)
  3077. (if dotodo (push :todo args))
  3078. (insert "Timeline of file " entry "\n")
  3079. (add-text-properties (point-min) (point)
  3080. (list 'face 'org-agenda-structure))
  3081. (org-agenda-mark-header-line (point-min))
  3082. (while (setq d (pop day-numbers))
  3083. (if (and (listp d) (eq (car d) :omitted))
  3084. (progn
  3085. (setq s (point))
  3086. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3087. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3088. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3089. (if (and (>= d today)
  3090. dopast
  3091. past)
  3092. (progn
  3093. (setq past nil)
  3094. (insert (make-string 79 ?-) "\n")))
  3095. (setq date (calendar-gregorian-from-absolute d))
  3096. (setq s (point))
  3097. (setq rtn (and (not emptyp)
  3098. (apply 'org-agenda-get-day-entries entry
  3099. date args)))
  3100. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3101. (progn
  3102. (insert
  3103. (if (stringp org-agenda-format-date)
  3104. (format-time-string org-agenda-format-date
  3105. (org-time-from-absolute date))
  3106. (funcall org-agenda-format-date date))
  3107. "\n")
  3108. (put-text-property s (1- (point)) 'face
  3109. (org-agenda-get-day-face date))
  3110. (put-text-property s (1- (point)) 'org-date-line t)
  3111. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3112. (if (equal d today)
  3113. (put-text-property s (1- (point)) 'org-today t))
  3114. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3115. (put-text-property s (1- (point)) 'day d)))))
  3116. (goto-char (point-min))
  3117. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3118. (point-min)))
  3119. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3120. (org-finalize-agenda)
  3121. (setq buffer-read-only t)))
  3122. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3123. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3124. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3125. not every single day in the range. If FORCE-TODAY is non-nil, make
  3126. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3127. inactive time stamps (those in square brackets) are included.
  3128. When EMPTY is non-nil, also include days without any entries."
  3129. (let ((re (concat
  3130. (if pre-re pre-re "")
  3131. (if inactive org-ts-regexp-both org-ts-regexp)))
  3132. dates dates1 date day day1 day2 ts1 ts2)
  3133. (if force-today
  3134. (setq dates (list (org-today))))
  3135. (save-excursion
  3136. (goto-char beg)
  3137. (while (re-search-forward re end t)
  3138. (setq day (time-to-days (org-time-string-to-time
  3139. (substring (match-string 1) 0 10))))
  3140. (or (memq day dates) (push day dates)))
  3141. (unless no-ranges
  3142. (goto-char beg)
  3143. (while (re-search-forward org-tr-regexp end t)
  3144. (setq ts1 (substring (match-string 1) 0 10)
  3145. ts2 (substring (match-string 2) 0 10)
  3146. day1 (time-to-days (org-time-string-to-time ts1))
  3147. day2 (time-to-days (org-time-string-to-time ts2)))
  3148. (while (< (setq day1 (1+ day1)) day2)
  3149. (or (memq day1 dates) (push day1 dates)))))
  3150. (setq dates (sort dates '<))
  3151. (when empty
  3152. (while (setq day (pop dates))
  3153. (setq day2 (car dates))
  3154. (push day dates1)
  3155. (when (and day2 empty)
  3156. (if (or (eq empty t)
  3157. (and (numberp empty) (<= (- day2 day) empty)))
  3158. (while (< (setq day (1+ day)) day2)
  3159. (push (list day) dates1))
  3160. (push (cons :omitted (- day2 day)) dates1))))
  3161. (setq dates (nreverse dates1)))
  3162. dates)))
  3163. ;;; Agenda Daily/Weekly
  3164. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3165. "Start day for the agenda view.
  3166. Custom commands can set this variable in the options section.")
  3167. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3168. (defvar org-agenda-current-span nil
  3169. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3170. (defvar org-include-all-loc nil) ; local variable
  3171. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3172. "List of types searched for when creating the daily/weekly agenda.
  3173. This variable is a list of symbols that controls the types of
  3174. items that appear in the daily/weekly agenda. Allowed symbols in this
  3175. list are are
  3176. :timestamp List items containing a date stamp or date range matching
  3177. the selected date. This includes sexp entries in
  3178. angular brackets.
  3179. :sexp List entries resulting from plain diary-like sexps.
  3180. :deadline List deadline due on that date. When the date is today,
  3181. also list any deadlines past due, or due within
  3182. `org-deadline-warning-days'. `:deadline' must appear before
  3183. `:scheduled' if the setting of
  3184. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3185. any effect.
  3186. :scheduled List all items which are scheduled for the given date.
  3187. The diary for *today* also contains items which were
  3188. scheduled earlier and are not yet marked DONE.
  3189. By default, all four types are turned on.
  3190. Never set this variable globally using `setq', because then it
  3191. will apply to all future agenda commands. Instead, bind it with
  3192. `let' to scope it dynamically into the agenda-constructing
  3193. command. A good way to set it is through options in
  3194. `org-agenda-custom-commands'. For a more flexible (though
  3195. somewhat less efficient) way of determining what is included in
  3196. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3197. ;;;###autoload
  3198. (defun org-agenda-list (&optional include-all start-day span)
  3199. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3200. The view will be for the current day or week, but from the overview buffer
  3201. you will be able to go to other days/weeks.
  3202. With a numeric prefix argument in an interactive call, the agenda will
  3203. span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
  3204. the number of days. SPAN defaults to `org-agenda-span'.
  3205. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3206. given in `org-agenda-start-on-weekday'."
  3207. (interactive "P")
  3208. (if (and (integerp include-all) (> include-all 0))
  3209. (setq span include-all include-all nil))
  3210. (setq start-day (or start-day org-agenda-start-day))
  3211. (if org-agenda-overriding-arguments
  3212. (setq include-all (car org-agenda-overriding-arguments)
  3213. start-day (nth 1 org-agenda-overriding-arguments)
  3214. span (nth 2 org-agenda-overriding-arguments)))
  3215. (if (stringp start-day)
  3216. ;; Convert to an absolute day number
  3217. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3218. (setq org-agenda-last-arguments (list include-all start-day span))
  3219. (org-compile-prefix-format 'agenda)
  3220. (org-set-sorting-strategy 'agenda)
  3221. (let* ((span (org-agenda-ndays-to-span
  3222. (or span org-agenda-ndays org-agenda-span)))
  3223. (today (org-today))
  3224. (sd (or start-day today))
  3225. (ndays (org-agenda-span-to-ndays span sd))
  3226. (org-agenda-start-on-weekday
  3227. (if (eq ndays 7)
  3228. org-agenda-start-on-weekday))
  3229. (thefiles (org-agenda-files nil 'ifmode))
  3230. (files thefiles)
  3231. (start (if (or (null org-agenda-start-on-weekday)
  3232. (< ndays 7))
  3233. sd
  3234. (let* ((nt (calendar-day-of-week
  3235. (calendar-gregorian-from-absolute sd)))
  3236. (n1 org-agenda-start-on-weekday)
  3237. (d (- nt n1)))
  3238. (- sd (+ (if (< d 0) 7 0) d)))))
  3239. (day-numbers (list start))
  3240. (day-cnt 0)
  3241. (inhibit-redisplay (not debug-on-error))
  3242. s e rtn rtnall file date d start-pos end-pos todayp
  3243. clocktable-start clocktable-end filter)
  3244. (setq org-agenda-redo-command
  3245. (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
  3246. (dotimes (n (1- ndays))
  3247. (push (1+ (car day-numbers)) day-numbers))
  3248. (setq day-numbers (nreverse day-numbers))
  3249. (setq clocktable-start (car day-numbers)
  3250. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3251. (org-prepare-agenda "Day/Week")
  3252. (org-set-local 'org-starting-day (car day-numbers))
  3253. (org-set-local 'org-include-all-loc include-all)
  3254. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3255. (unless org-agenda-compact-blocks
  3256. (let* ((d1 (car day-numbers))
  3257. (d2 (org-last day-numbers))
  3258. (w1 (org-days-to-iso-week d1))
  3259. (w2 (org-days-to-iso-week d2)))
  3260. (setq s (point))
  3261. (if org-agenda-overriding-header
  3262. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3263. nil 'face 'org-agenda-structure) "\n")
  3264. (insert (org-agenda-span-name span)
  3265. "-agenda"
  3266. (if (< (- d2 d1) 350)
  3267. (if (= w1 w2)
  3268. (format " (W%02d)" w1)
  3269. (format " (W%02d-W%02d)" w1 w2))
  3270. "")
  3271. ":\n")))
  3272. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3273. 'org-date-line t))
  3274. (org-agenda-mark-header-line s))
  3275. (while (setq d (pop day-numbers))
  3276. (setq date (calendar-gregorian-from-absolute d)
  3277. s (point))
  3278. (if (or (setq todayp (= d today))
  3279. (and (not start-pos) (= d sd)))
  3280. (setq start-pos (point))
  3281. (if (and start-pos (not end-pos))
  3282. (setq end-pos (point))))
  3283. (setq files thefiles
  3284. rtnall nil)
  3285. (while (setq file (pop files))
  3286. (catch 'nextfile
  3287. (org-check-agenda-file file)
  3288. (let ((org-agenda-entry-types org-agenda-entry-types))
  3289. (unless org-agenda-include-deadlines
  3290. (setq org-agenda-entry-types
  3291. (delq :deadline org-agenda-entry-types)))
  3292. (cond
  3293. ((memq org-agenda-show-log '(only clockcheck))
  3294. (setq rtn (org-agenda-get-day-entries
  3295. file date :closed)))
  3296. (org-agenda-show-log
  3297. (setq rtn (apply 'org-agenda-get-day-entries
  3298. file date
  3299. (append '(:closed) org-agenda-entry-types))))
  3300. (t
  3301. (setq rtn (apply 'org-agenda-get-day-entries
  3302. file date
  3303. org-agenda-entry-types)))))
  3304. (setq rtnall (append rtnall rtn))))
  3305. (if org-agenda-include-diary
  3306. (let ((org-agenda-search-headline-for-time t))
  3307. (require 'diary-lib)
  3308. (setq rtn (org-get-entries-from-diary date))
  3309. (setq rtnall (append rtnall rtn))))
  3310. (if (or rtnall org-agenda-show-all-dates)
  3311. (progn
  3312. (setq day-cnt (1+ day-cnt))
  3313. (insert
  3314. (if (stringp org-agenda-format-date)
  3315. (format-time-string org-agenda-format-date
  3316. (org-time-from-absolute date))
  3317. (funcall org-agenda-format-date date))
  3318. "\n")
  3319. (put-text-property s (1- (point)) 'face
  3320. (org-agenda-get-day-face date))
  3321. (put-text-property s (1- (point)) 'org-date-line t)
  3322. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3323. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3324. (when todayp
  3325. (put-text-property s (1- (point)) 'org-today t))
  3326. (if rtnall (insert
  3327. (org-finalize-agenda-entries
  3328. (org-agenda-add-time-grid-maybe
  3329. rtnall ndays todayp))
  3330. "\n"))
  3331. (put-text-property s (1- (point)) 'day d)
  3332. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3333. (when (and org-agenda-clockreport-mode clocktable-start)
  3334. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3335. ;; the above line is to ensure the restricted range!
  3336. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3337. tbl)
  3338. (setq p (org-plist-delete p :block))
  3339. (setq p (plist-put p :tstart clocktable-start))
  3340. (setq p (plist-put p :tend clocktable-end))
  3341. (setq p (plist-put p :scope 'agenda))
  3342. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3343. (setq filter (or org-agenda-filter-while-redo
  3344. (get 'org-agenda-filter :preset-filter))))
  3345. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3346. (if (string-match "[<>=]" x)
  3347. ""
  3348. x))
  3349. filter ""))))
  3350. (setq tbl (apply 'org-get-clocktable p))
  3351. (insert tbl)))
  3352. (goto-char (point-min))
  3353. (or org-agenda-multi (org-fit-agenda-window))
  3354. (unless (and (pos-visible-in-window-p (point-min))
  3355. (pos-visible-in-window-p (point-max)))
  3356. (goto-char (1- (point-max)))
  3357. (recenter -1)
  3358. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3359. (progn
  3360. (goto-char (or start-pos 1))
  3361. (recenter 1))))
  3362. (goto-char (or start-pos 1))
  3363. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3364. (if (eq org-agenda-show-log 'clockcheck)
  3365. (org-agenda-show-clocking-issues))
  3366. (org-finalize-agenda)
  3367. (setq buffer-read-only t)
  3368. (message "")))
  3369. (defun org-agenda-ndays-to-span (n)
  3370. "Return a span symbol for a span of N days, or N if none matches."
  3371. (cond ((symbolp n) n)
  3372. ((= n 1) 'day)
  3373. ((= n 7) 'week)
  3374. (t n)))
  3375. (defun org-agenda-span-to-ndays (span start-day)
  3376. "Return ndays from SPAN starting at START-DAY."
  3377. (cond ((numberp span) span)
  3378. ((eq span 'day) 1)
  3379. ((eq span 'week) 7)
  3380. ((eq span 'month)
  3381. (let ((date (calendar-gregorian-from-absolute start-day)))
  3382. (calendar-last-day-of-month (car date) (caddr date))))
  3383. ((eq span 'year)
  3384. (let ((date (calendar-gregorian-from-absolute start-day)))
  3385. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3386. (defun org-agenda-span-name (span)
  3387. "Return a SPAN name."
  3388. (if (null span)
  3389. ""
  3390. (if (symbolp span)
  3391. (capitalize (symbol-name span))
  3392. (format "%d days" span))))
  3393. ;;; Agenda word search
  3394. (defvar org-agenda-search-history nil)
  3395. (defvar org-todo-only nil)
  3396. (defvar org-search-syntax-table nil
  3397. "Special syntax table for org-mode search.
  3398. In this table, we have single quotes not as word constituents, to
  3399. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3400. (defun org-search-syntax-table ()
  3401. (unless org-search-syntax-table
  3402. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3403. (modify-syntax-entry ?' "." org-search-syntax-table)
  3404. (modify-syntax-entry ?` "." org-search-syntax-table))
  3405. org-search-syntax-table)
  3406. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3407. ;;;###autoload
  3408. (defun org-search-view (&optional todo-only string edit-at)
  3409. "Show all entries that contain a phrase or words or regular expressions.
  3410. With optional prefix argument TODO-ONLY, only consider entries that are
  3411. TODO entries. The argument STRING can be used to pass a default search
  3412. string into this function. If EDIT-AT is non-nil, it means that the
  3413. user should get a chance to edit this string, with cursor at position
  3414. EDIT-AT.
  3415. The search string can be viewed either as a phrase that should be found as
  3416. is, or it can be broken into a number of snippets, each of which must match
  3417. in a Boolean way to select an entry. The default depends on the variable
  3418. `org-agenda-search-view-always-boolean'.
  3419. Even if this is turned off (the default) you can always switch to
  3420. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3421. The default is a direct search of the whole phrase, where each space in
  3422. the search string can expand to an arbitrary amount of whitespace,
  3423. including newlines.
  3424. If using a Boolean search, the search string is split on whitespace and
  3425. each snippet is searched separately, with logical AND to select an entry.
  3426. Words prefixed with a minus must *not* occur in the entry. Words without
  3427. a prefix or prefixed with a plus must occur in the entry. Matching is
  3428. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3429. match whole words, not parts of a word) if
  3430. `org-agenda-search-view-force-full-words' is set (default is nil).
  3431. Boolean search snippets enclosed by curly braces are interpreted as
  3432. regular expressions that must or (when preceded with \"-\") must not
  3433. match in the entry. Snippets enclosed into double quotes will be taken
  3434. as a whole, to include whitespace.
  3435. - If the search string starts with an asterisk, search only in headlines.
  3436. - If (possibly after the leading star) the search string starts with an
  3437. exclamation mark, this also means to look at TODO entries only, an effect
  3438. that can also be achieved with a prefix argument.
  3439. - If (possibly after star and exclamation mark) the search string starts
  3440. with a colon, this will mean that the (non-regexp) snippets of the
  3441. Boolean search must match as full words.
  3442. This command searches the agenda files, and in addition the files listed
  3443. in `org-agenda-text-search-extra-files'."
  3444. (interactive "P")
  3445. (org-compile-prefix-format 'search)
  3446. (org-set-sorting-strategy 'search)
  3447. (org-prepare-agenda "SEARCH")
  3448. (let* ((props (list 'face nil
  3449. 'done-face 'org-agenda-done
  3450. 'org-not-done-regexp org-not-done-regexp
  3451. 'org-todo-regexp org-todo-regexp
  3452. 'org-complex-heading-regexp org-complex-heading-regexp
  3453. 'mouse-face 'highlight
  3454. 'help-echo (format "mouse-2 or RET jump to location")))
  3455. (full-words org-agenda-search-view-force-full-words)
  3456. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3457. regexp rtn rtnall files file pos
  3458. marker category tags c neg re boolean
  3459. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3460. (unless (and (not edit-at)
  3461. (stringp string)
  3462. (string-match "\\S-" string))
  3463. (setq string (read-string
  3464. (if org-agenda-search-view-always-boolean
  3465. "[+-]Word/{Regexp} ...: "
  3466. "Phrase, or [+-]Word/{Regexp} ...: ")
  3467. (cond
  3468. ((integerp edit-at) (cons string edit-at))
  3469. (edit-at string))
  3470. 'org-agenda-search-history)))
  3471. (org-set-local 'org-todo-only todo-only)
  3472. (setq org-agenda-redo-command
  3473. (list 'org-search-view (if todo-only t nil) string
  3474. '(if current-prefix-arg 1 nil)))
  3475. (setq org-agenda-query-string string)
  3476. (if (equal (string-to-char string) ?*)
  3477. (setq hdl-only t
  3478. words (substring string 1))
  3479. (setq words string))
  3480. (when (equal (string-to-char words) ?!)
  3481. (setq todo-only t
  3482. words (substring words 1)))
  3483. (when (equal (string-to-char words) ?:)
  3484. (setq full-words t
  3485. words (substring words 1)))
  3486. (if (or org-agenda-search-view-always-boolean
  3487. (member (string-to-char words) '(?- ?+ ?\{)))
  3488. (setq boolean t))
  3489. (setq words (org-split-string words))
  3490. (let (www w)
  3491. (while (setq w (pop words))
  3492. (while (and (string-match "\\\\\\'" w) words)
  3493. (setq w (concat (substring w 0 -1) " " (pop words))))
  3494. (push w www))
  3495. (setq words (nreverse www) www nil)
  3496. (while (setq w (pop words))
  3497. (when (and (string-match "\\`[-+]?{" w)
  3498. (not (string-match "}\\'" w)))
  3499. (while (and words (not (string-match "}\\'" (car words))))
  3500. (setq w (concat w " " (pop words))))
  3501. (setq w (concat w " " (pop words))))
  3502. (push w www))
  3503. (setq words (nreverse www)))
  3504. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3505. (when boolean
  3506. (let (wds w)
  3507. (while (setq w (pop words))
  3508. (if (or (equal (substring w 0 1) "\"")
  3509. (and (> (length w) 1)
  3510. (member (substring w 0 1) '("+" "-"))
  3511. (equal (substring w 1 2) "\"")))
  3512. (while (and words (not (equal (substring w -1) "\"")))
  3513. (setq w (concat w " " (pop words)))))
  3514. (and (string-match "\\`\\([-+]?\\)\"" w)
  3515. (setq w (replace-match "\\1" nil nil w)))
  3516. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3517. (push w wds))
  3518. (setq words (nreverse wds))))
  3519. (if boolean
  3520. (mapc (lambda (w)
  3521. (setq c (string-to-char w))
  3522. (if (equal c ?-)
  3523. (setq neg t w (substring w 1))
  3524. (if (equal c ?+)
  3525. (setq neg nil w (substring w 1))
  3526. (setq neg nil)))
  3527. (if (string-match "\\`{.*}\\'" w)
  3528. (setq re (substring w 1 -1))
  3529. (if full-words
  3530. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3531. (setq re (regexp-quote (downcase w)))))
  3532. (if neg (push re regexps-) (push re regexps+)))
  3533. words)
  3534. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3535. regexps+))
  3536. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3537. (if (not regexps+)
  3538. (setq regexp (concat "^" org-outline-regexp))
  3539. (setq regexp (pop regexps+))
  3540. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3541. regexp))))
  3542. (setq files (org-agenda-files nil 'ifmode))
  3543. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3544. (pop org-agenda-text-search-extra-files)
  3545. (setq files (org-add-archive-files files)))
  3546. (setq files (append files org-agenda-text-search-extra-files)
  3547. rtnall nil)
  3548. (while (setq file (pop files))
  3549. (setq ee nil)
  3550. (catch 'nextfile
  3551. (org-check-agenda-file file)
  3552. (setq buffer (if (file-exists-p file)
  3553. (org-get-agenda-file-buffer file)
  3554. (error "No such file %s" file)))
  3555. (if (not buffer)
  3556. ;; If file does not exist, make sure an error message is sent
  3557. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3558. file))))
  3559. (with-current-buffer buffer
  3560. (with-syntax-table (org-search-syntax-table)
  3561. (unless (org-mode-p)
  3562. (error "Agenda file %s is not in `org-mode'" file))
  3563. (let ((case-fold-search t))
  3564. (save-excursion
  3565. (save-restriction
  3566. (if org-agenda-restrict
  3567. (narrow-to-region org-agenda-restrict-begin
  3568. org-agenda-restrict-end)
  3569. (widen))
  3570. (goto-char (point-min))
  3571. (unless (or (org-on-heading-p)
  3572. (outline-next-heading))
  3573. (throw 'nextfile t))
  3574. (goto-char (max (point-min) (1- (point))))
  3575. (while (re-search-forward regexp nil t)
  3576. (org-back-to-heading t)
  3577. (skip-chars-forward "* ")
  3578. (setq beg (point-at-bol)
  3579. beg1 (point)
  3580. end (progn (outline-next-heading) (point)))
  3581. (catch :skip
  3582. (goto-char beg)
  3583. (org-agenda-skip)
  3584. (setq str (buffer-substring-no-properties
  3585. (point-at-bol)
  3586. (if hdl-only (point-at-eol) end)))
  3587. (mapc (lambda (wr) (when (string-match wr str)
  3588. (goto-char (1- end))
  3589. (throw :skip t)))
  3590. regexps-)
  3591. (mapc (lambda (wr) (unless (string-match wr str)
  3592. (goto-char (1- end))
  3593. (throw :skip t)))
  3594. (if todo-only
  3595. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3596. regexps+)
  3597. regexps+))
  3598. (goto-char beg)
  3599. (setq marker (org-agenda-new-marker (point))
  3600. category (org-get-category)
  3601. tags (org-get-tags-at (point))
  3602. txt (org-format-agenda-item
  3603. ""
  3604. (buffer-substring-no-properties
  3605. beg1 (point-at-eol))
  3606. category tags))
  3607. (org-add-props txt props
  3608. 'org-marker marker 'org-hd-marker marker
  3609. 'org-todo-regexp org-todo-regexp
  3610. 'org-complex-heading-regexp org-complex-heading-regexp
  3611. 'priority 1000 'org-category category
  3612. 'type "search")
  3613. (push txt ee)
  3614. (goto-char (1- end))))))))))
  3615. (setq rtn (nreverse ee))
  3616. (setq rtnall (append rtnall rtn)))
  3617. (if org-agenda-overriding-header
  3618. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3619. nil 'face 'org-agenda-structure) "\n")
  3620. (insert "Search words: ")
  3621. (add-text-properties (point-min) (1- (point))
  3622. (list 'face 'org-agenda-structure))
  3623. (setq pos (point))
  3624. (insert string "\n")
  3625. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3626. (setq pos (point))
  3627. (unless org-agenda-multi
  3628. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3629. (add-text-properties pos (1- (point))
  3630. (list 'face 'org-agenda-structure))))
  3631. (org-agenda-mark-header-line (point-min))
  3632. (when rtnall
  3633. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3634. (goto-char (point-min))
  3635. (or org-agenda-multi (org-fit-agenda-window))
  3636. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3637. (org-finalize-agenda)
  3638. (setq buffer-read-only t)))
  3639. ;;; Agenda TODO list
  3640. (defvar org-select-this-todo-keyword nil)
  3641. (defvar org-last-arg nil)
  3642. ;;;###autoload
  3643. (defun org-todo-list (arg)
  3644. "Show all (not done) TODO entries from all agenda file in a single list.
  3645. The prefix arg can be used to select a specific TODO keyword and limit
  3646. the list to these. When using \\[universal-argument], you will be prompted
  3647. for a keyword. A numeric prefix directly selects the Nth keyword in
  3648. `org-todo-keywords-1'."
  3649. (interactive "P")
  3650. (org-compile-prefix-format 'todo)
  3651. (org-set-sorting-strategy 'todo)
  3652. (org-prepare-agenda "TODO")
  3653. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3654. (let* ((today (org-today))
  3655. (date (calendar-gregorian-from-absolute today))
  3656. (kwds org-todo-keywords-for-agenda)
  3657. (completion-ignore-case t)
  3658. (org-select-this-todo-keyword
  3659. (if (stringp arg) arg
  3660. (and arg (integerp arg) (> arg 0)
  3661. (nth (1- arg) kwds))))
  3662. rtn rtnall files file pos)
  3663. (when (equal arg '(4))
  3664. (setq org-select-this-todo-keyword
  3665. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3666. (mapcar 'list kwds) nil nil)))
  3667. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3668. (org-set-local 'org-last-arg arg)
  3669. (setq org-agenda-redo-command
  3670. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3671. (setq files (org-agenda-files nil 'ifmode)
  3672. rtnall nil)
  3673. (while (setq file (pop files))
  3674. (catch 'nextfile
  3675. (org-check-agenda-file file)
  3676. (setq rtn (org-agenda-get-day-entries file date :todo))
  3677. (setq rtnall (append rtnall rtn))))
  3678. (if org-agenda-overriding-header
  3679. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3680. nil 'face 'org-agenda-structure) "\n")
  3681. (insert "Global list of TODO items of type: ")
  3682. (add-text-properties (point-min) (1- (point))
  3683. (list 'face 'org-agenda-structure
  3684. 'short-heading
  3685. (concat "ToDo: "
  3686. (or org-select-this-todo-keyword "ALL"))))
  3687. (org-agenda-mark-header-line (point-min))
  3688. (setq pos (point))
  3689. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3690. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3691. (setq pos (point))
  3692. (unless org-agenda-multi
  3693. (insert "Available with `N r': (0)ALL")
  3694. (let ((n 0) s)
  3695. (mapc (lambda (x)
  3696. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3697. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3698. (insert "\n "))
  3699. (insert " " s))
  3700. kwds))
  3701. (insert "\n"))
  3702. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3703. (org-agenda-mark-header-line (point-min))
  3704. (when rtnall
  3705. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3706. (goto-char (point-min))
  3707. (or org-agenda-multi (org-fit-agenda-window))
  3708. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3709. (org-finalize-agenda)
  3710. (setq buffer-read-only t)))
  3711. ;;; Agenda tags match
  3712. ;;;###autoload
  3713. (defun org-tags-view (&optional todo-only match)
  3714. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3715. The prefix arg TODO-ONLY limits the search to TODO entries."
  3716. (interactive "P")
  3717. (org-compile-prefix-format 'tags)
  3718. (org-set-sorting-strategy 'tags)
  3719. (let* ((org-tags-match-list-sublevels
  3720. org-tags-match-list-sublevels)
  3721. (completion-ignore-case t)
  3722. rtn rtnall files file pos matcher
  3723. buffer)
  3724. (when (and (stringp match) (not (string-match "\\S-" match)))
  3725. (setq match nil))
  3726. (setq matcher (org-make-tags-matcher match)
  3727. match (car matcher) matcher (cdr matcher))
  3728. (org-prepare-agenda (concat "TAGS " match))
  3729. (setq org-agenda-query-string match)
  3730. (setq org-agenda-redo-command
  3731. (list 'org-tags-view (list 'quote todo-only)
  3732. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3733. (setq files (org-agenda-files nil 'ifmode)
  3734. rtnall nil)
  3735. (while (setq file (pop files))
  3736. (catch 'nextfile
  3737. (org-check-agenda-file file)
  3738. (setq buffer (if (file-exists-p file)
  3739. (org-get-agenda-file-buffer file)
  3740. (error "No such file %s" file)))
  3741. (if (not buffer)
  3742. ;; If file does not exist, error message to agenda
  3743. (setq rtn (list
  3744. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3745. rtnall (append rtnall rtn))
  3746. (with-current-buffer buffer
  3747. (unless (org-mode-p)
  3748. (error "Agenda file %s is not in `org-mode'" file))
  3749. (save-excursion
  3750. (save-restriction
  3751. (if org-agenda-restrict
  3752. (narrow-to-region org-agenda-restrict-begin
  3753. org-agenda-restrict-end)
  3754. (widen))
  3755. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3756. (setq rtnall (append rtnall rtn))))))))
  3757. (if org-agenda-overriding-header
  3758. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3759. nil 'face 'org-agenda-structure) "\n")
  3760. (insert "Headlines with TAGS match: ")
  3761. (add-text-properties (point-min) (1- (point))
  3762. (list 'face 'org-agenda-structure
  3763. 'short-heading
  3764. (concat "Match: " match)))
  3765. (setq pos (point))
  3766. (insert match "\n")
  3767. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3768. (setq pos (point))
  3769. (unless org-agenda-multi
  3770. (insert "Press `C-u r' to search again with new search string\n"))
  3771. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3772. (org-agenda-mark-header-line (point-min))
  3773. (when rtnall
  3774. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3775. (goto-char (point-min))
  3776. (or org-agenda-multi (org-fit-agenda-window))
  3777. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3778. (org-finalize-agenda)
  3779. (setq buffer-read-only t)))
  3780. ;;; Agenda Finding stuck projects
  3781. (defvar org-agenda-skip-regexp nil
  3782. "Regular expression used in skipping subtrees for the agenda.
  3783. This is basically a temporary global variable that can be set and then
  3784. used by user-defined selections using `org-agenda-skip-function'.")
  3785. (defvar org-agenda-overriding-header nil
  3786. "When set during agenda, todo and tags searches it replaces the header.
  3787. This variable should not be set directly, but custom commands can bind it
  3788. in the options section.")
  3789. (defun org-agenda-skip-entry-when-regexp-matches ()
  3790. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3791. If yes, it returns the end position of this entry, causing agenda commands
  3792. to skip the entry but continuing the search in the subtree. This is a
  3793. function that can be put into `org-agenda-skip-function' for the duration
  3794. of a command."
  3795. (let ((end (save-excursion (org-end-of-subtree t)))
  3796. skip)
  3797. (save-excursion
  3798. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3799. (and skip end)))
  3800. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3801. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3802. If yes, it returns the end position of this tree, causing agenda commands
  3803. to skip this subtree. This is a function that can be put into
  3804. `org-agenda-skip-function' for the duration of a command."
  3805. (let ((end (save-excursion (org-end-of-subtree t)))
  3806. skip)
  3807. (save-excursion
  3808. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3809. (and skip end)))
  3810. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3811. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3812. If yes, it returns the end position of the current entry (NOT the tree),
  3813. causing agenda commands to skip the entry but continuing the search in
  3814. the subtree. This is a function that can be put into
  3815. `org-agenda-skip-function' for the duration of a command. An important
  3816. use of this function is for the stuck project list."
  3817. (let ((end (save-excursion (org-end-of-subtree t)))
  3818. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3819. skip)
  3820. (save-excursion
  3821. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3822. (and skip entry-end)))
  3823. (defun org-agenda-skip-entry-if (&rest conditions)
  3824. "Skip entry if any of CONDITIONS is true.
  3825. See `org-agenda-skip-if' for details."
  3826. (org-agenda-skip-if nil conditions))
  3827. (defun org-agenda-skip-subtree-if (&rest conditions)
  3828. "Skip entry if any of CONDITIONS is true.
  3829. See `org-agenda-skip-if' for details."
  3830. (org-agenda-skip-if t conditions))
  3831. (defun org-agenda-skip-if (subtree conditions)
  3832. "Checks current entity for CONDITIONS.
  3833. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3834. the entry, i.e. the text before the next heading is checked.
  3835. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3836. from different tests. Valid conditions are:
  3837. scheduled Check if there is a scheduled cookie
  3838. notscheduled Check if there is no scheduled cookie
  3839. deadline Check if there is a deadline
  3840. notdeadline Check if there is no deadline
  3841. timestamp Check if there is a timestamp (also deadline or scheduled)
  3842. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3843. regexp Check if regexp matches
  3844. notregexp Check if regexp does not match.
  3845. todo Check if TODO keyword matches
  3846. nottodo Check if TODO keyword does not match
  3847. The regexp is taken from the conditions list, it must come right after
  3848. the `regexp' or `notregexp' element.
  3849. `todo' and `nottodo' accept as an argument a list of todo
  3850. keywords, which may include \"*\" to match any todo keyword.
  3851. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3852. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3853. Instead of a list a keyword class may be given
  3854. (org-agenda-skip-entry-if 'nottodo 'done)
  3855. would skip entries that haven't been marked with any of \"DONE\"
  3856. keywords. Possible classes are: `todo', `done', `any'.
  3857. If any of these conditions is met, this function returns the end point of
  3858. the entity, causing the search to continue from there. This is a function
  3859. that can be put into `org-agenda-skip-function' for the duration of a command."
  3860. (let (beg end m)
  3861. (org-back-to-heading t)
  3862. (setq beg (point)
  3863. end (if subtree
  3864. (progn (org-end-of-subtree t) (point))
  3865. (progn (outline-next-heading) (1- (point)))))
  3866. (goto-char beg)
  3867. (and
  3868. (or
  3869. (and (memq 'scheduled conditions)
  3870. (re-search-forward org-scheduled-time-regexp end t))
  3871. (and (memq 'notscheduled conditions)
  3872. (not (re-search-forward org-scheduled-time-regexp end t)))
  3873. (and (memq 'deadline conditions)
  3874. (re-search-forward org-deadline-time-regexp end t))
  3875. (and (memq 'notdeadline conditions)
  3876. (not (re-search-forward org-deadline-time-regexp end t)))
  3877. (and (memq 'timestamp conditions)
  3878. (re-search-forward org-ts-regexp end t))
  3879. (and (memq 'nottimestamp conditions)
  3880. (not (re-search-forward org-ts-regexp end t)))
  3881. (and (setq m (memq 'regexp conditions))
  3882. (stringp (nth 1 m))
  3883. (re-search-forward (nth 1 m) end t))
  3884. (and (setq m (memq 'notregexp conditions))
  3885. (stringp (nth 1 m))
  3886. (not (re-search-forward (nth 1 m) end t)))
  3887. (and (or
  3888. (setq m (memq 'todo conditions))
  3889. (setq m (memq 'nottodo conditions)))
  3890. (org-agenda-skip-if-todo m end)))
  3891. end)))
  3892. (defun org-agenda-skip-if-todo (args end)
  3893. "Helper function for `org-agenda-skip-if', do not use it directly.
  3894. ARGS is a list with first element either `todo' or `nottodo'.
  3895. The remainder is either a list of TODO keywords, or a state symbol
  3896. `todo' or `done' or `any'."
  3897. (let ((kw (car args))
  3898. (arg (cadr args))
  3899. todo-wds todo-re)
  3900. (setq todo-wds
  3901. (org-uniquify
  3902. (cond
  3903. ((listp arg) ;; list of keywords
  3904. (if (member "*" arg)
  3905. (mapcar 'substring-no-properties org-todo-keywords-1)
  3906. arg))
  3907. ((symbolp arg) ;; keyword class name
  3908. (cond
  3909. ((eq arg 'todo)
  3910. (org-delete-all org-done-keywords
  3911. (mapcar 'substring-no-properties
  3912. org-todo-keywords-1)))
  3913. ((eq arg 'done) org-done-keywords)
  3914. ((eq arg 'any)
  3915. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3916. (setq todo-re
  3917. (concat "^\\*+[ \t]+\\<\\("
  3918. (mapconcat 'identity todo-wds "\\|")
  3919. "\\)\\>"))
  3920. (if (eq kw 'todo)
  3921. (re-search-forward todo-re end t)
  3922. (not (re-search-forward todo-re end t)))))
  3923. ;;;###autoload
  3924. (defun org-agenda-list-stuck-projects (&rest ignore)
  3925. "Create agenda view for projects that are stuck.
  3926. Stuck projects are project that have no next actions. For the definitions
  3927. of what a project is and how to check if it stuck, customize the variable
  3928. `org-stuck-projects'."
  3929. (interactive)
  3930. (let* ((org-agenda-skip-function
  3931. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3932. ;; We could have used org-agenda-skip-if here.
  3933. (org-agenda-overriding-header
  3934. (or org-agenda-overriding-header "List of stuck projects: "))
  3935. (matcher (nth 0 org-stuck-projects))
  3936. (todo (nth 1 org-stuck-projects))
  3937. (todo-wds (if (member "*" todo)
  3938. (progn
  3939. (org-prepare-agenda-buffers (org-agenda-files
  3940. nil 'ifmode))
  3941. (org-delete-all
  3942. org-done-keywords-for-agenda
  3943. (copy-sequence org-todo-keywords-for-agenda)))
  3944. todo))
  3945. (todo-re (concat "^\\*+[ \t]+\\("
  3946. (mapconcat 'identity todo-wds "\\|")
  3947. "\\)\\>"))
  3948. (tags (nth 2 org-stuck-projects))
  3949. (tags-re (if (member "*" tags)
  3950. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3951. (if tags
  3952. (concat "^\\*+ .*:\\("
  3953. (mapconcat 'identity tags "\\|")
  3954. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3955. (gen-re (nth 3 org-stuck-projects))
  3956. (re-list
  3957. (delq nil
  3958. (list
  3959. (if todo todo-re)
  3960. (if tags tags-re)
  3961. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3962. gen-re)))))
  3963. (setq org-agenda-skip-regexp
  3964. (if re-list
  3965. (mapconcat 'identity re-list "\\|")
  3966. (error "No information how to identify unstuck projects")))
  3967. (org-tags-view nil matcher)
  3968. (with-current-buffer org-agenda-buffer-name
  3969. (setq org-agenda-redo-command
  3970. '(org-agenda-list-stuck-projects
  3971. (or current-prefix-arg org-last-arg))))))
  3972. ;;; Diary integration
  3973. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3974. (defvar list-diary-entries-hook)
  3975. (defvar diary-time-regexp)
  3976. (defun org-get-entries-from-diary (date)
  3977. "Get the (Emacs Calendar) diary entries for DATE."
  3978. (require 'diary-lib)
  3979. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3980. (diary-display-hook '(fancy-diary-display))
  3981. (diary-display-function 'fancy-diary-display)
  3982. (pop-up-frames nil)
  3983. (list-diary-entries-hook
  3984. (cons 'org-diary-default-entry list-diary-entries-hook))
  3985. (diary-file-name-prefix-function nil) ; turn this feature off
  3986. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3987. entries
  3988. (org-disable-agenda-to-diary t))
  3989. (save-excursion
  3990. (save-window-excursion
  3991. (funcall (if (fboundp 'diary-list-entries)
  3992. 'diary-list-entries 'list-diary-entries)
  3993. date 1)))
  3994. (if (not (get-buffer diary-fancy-buffer))
  3995. (setq entries nil)
  3996. (with-current-buffer diary-fancy-buffer
  3997. (setq buffer-read-only nil)
  3998. (if (zerop (buffer-size))
  3999. ;; No entries
  4000. (setq entries nil)
  4001. ;; Omit the date and other unnecessary stuff
  4002. (org-agenda-cleanup-fancy-diary)
  4003. ;; Add prefix to each line and extend the text properties
  4004. (if (zerop (buffer-size))
  4005. (setq entries nil)
  4006. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4007. (setq entries
  4008. (with-temp-buffer
  4009. (insert entries) (goto-char (point-min))
  4010. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4011. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4012. (replace-match (concat "; " (match-string 1)))))
  4013. (buffer-string)))))
  4014. (set-buffer-modified-p nil)
  4015. (kill-buffer diary-fancy-buffer)))
  4016. (when entries
  4017. (setq entries (org-split-string entries "\n"))
  4018. (setq entries
  4019. (mapcar
  4020. (lambda (x)
  4021. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  4022. ;; Extend the text properties to the beginning of the line
  4023. (org-add-props x (text-properties-at (1- (length x)) x)
  4024. 'type "diary" 'date date 'face 'org-agenda-diary))
  4025. entries)))))
  4026. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4027. "Hook run when the fancy diary buffer is cleaned up.")
  4028. (defun org-agenda-cleanup-fancy-diary ()
  4029. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4030. This gets rid of the date, the underline under the date, and
  4031. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4032. date. It also removes lines that contain only whitespace."
  4033. (goto-char (point-min))
  4034. (if (looking-at ".*?:[ \t]*")
  4035. (progn
  4036. (replace-match "")
  4037. (re-search-forward "\n=+$" nil t)
  4038. (replace-match "")
  4039. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4040. (re-search-forward "\n=+$" nil t)
  4041. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4042. (goto-char (point-min))
  4043. (while (re-search-forward "^ +\n" nil t)
  4044. (replace-match ""))
  4045. (goto-char (point-min))
  4046. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4047. (replace-match ""))
  4048. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4049. ;; Make sure entries from the diary have the right text properties.
  4050. (eval-after-load "diary-lib"
  4051. '(if (boundp 'diary-modify-entry-list-string-function)
  4052. ;; We can rely on the hook, nothing to do
  4053. nil
  4054. ;; Hook not available, must use advice to make this work
  4055. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4056. "Make the position visible."
  4057. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4058. (stringp string)
  4059. buffer-file-name)
  4060. (setq string (org-modify-diary-entry-string string))))))
  4061. (defun org-modify-diary-entry-string (string)
  4062. "Add text properties to string, allowing org-mode to act on it."
  4063. (org-add-props string nil
  4064. 'mouse-face 'highlight
  4065. 'help-echo (if buffer-file-name
  4066. (format "mouse-2 or RET jump to diary file %s"
  4067. (abbreviate-file-name buffer-file-name))
  4068. "")
  4069. 'org-agenda-diary-link t
  4070. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4071. (defun org-diary-default-entry ()
  4072. "Add a dummy entry to the diary.
  4073. Needed to avoid empty dates which mess up holiday display."
  4074. ;; Catch the error if dealing with the new add-to-diary-alist
  4075. (when org-disable-agenda-to-diary
  4076. (condition-case nil
  4077. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4078. (error
  4079. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4080. (defun org-add-to-diary-list (&rest args)
  4081. (if (fboundp 'diary-add-to-list)
  4082. (apply 'diary-add-to-list args)
  4083. (apply 'add-to-diary-list args)))
  4084. (defvar org-diary-last-run-time nil)
  4085. ;;;###autoload
  4086. (defun org-diary (&rest args)
  4087. "Return diary information from org-files.
  4088. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4089. It accesses org files and extracts information from those files to be
  4090. listed in the diary. The function accepts arguments specifying what
  4091. items should be listed. For a list of arguments allowed here, see the
  4092. variable `org-agenda-entry-types'.
  4093. The call in the diary file should look like this:
  4094. &%%(org-diary) ~/path/to/some/orgfile.org
  4095. Use a separate line for each org file to check. Or, if you omit the file name,
  4096. all files listed in `org-agenda-files' will be checked automatically:
  4097. &%%(org-diary)
  4098. If you don't give any arguments (as in the example above), the default
  4099. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4100. So the example above may also be written as
  4101. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4102. The function expects the lisp variables `entry' and `date' to be provided
  4103. by the caller, because this is how the calendar works. Don't use this
  4104. function from a program - use `org-agenda-get-day-entries' instead."
  4105. (when (> (- (org-float-time)
  4106. org-agenda-last-marker-time)
  4107. 5)
  4108. (org-agenda-reset-markers))
  4109. (org-compile-prefix-format 'agenda)
  4110. (org-set-sorting-strategy 'agenda)
  4111. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4112. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4113. (list entry)
  4114. (org-agenda-files t)))
  4115. (time (org-float-time))
  4116. file rtn results)
  4117. (when (or (not org-diary-last-run-time)
  4118. (> (- time
  4119. org-diary-last-run-time)
  4120. 3))
  4121. (org-prepare-agenda-buffers files))
  4122. (setq org-diary-last-run-time time)
  4123. ;; If this is called during org-agenda, don't return any entries to
  4124. ;; the calendar. Org Agenda will list these entries itself.
  4125. (if org-disable-agenda-to-diary (setq files nil))
  4126. (while (setq file (pop files))
  4127. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4128. (setq results (append results rtn)))
  4129. (if results
  4130. (concat (org-finalize-agenda-entries results) "\n"))))
  4131. ;;; Agenda entry finders
  4132. (defun org-agenda-get-day-entries (file date &rest args)
  4133. "Does the work for `org-diary' and `org-agenda'.
  4134. FILE is the path to a file to be checked for entries. DATE is date like
  4135. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4136. which kind of entries should be extracted. For details about these, see
  4137. the documentation of `org-diary'."
  4138. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4139. (let* ((org-startup-folded nil)
  4140. (org-startup-align-all-tables nil)
  4141. (buffer (if (file-exists-p file)
  4142. (org-get-agenda-file-buffer file)
  4143. (error "No such file %s" file)))
  4144. arg results rtn deadline-results)
  4145. (if (not buffer)
  4146. ;; If file does not exist, make sure an error message ends up in diary
  4147. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4148. (with-current-buffer buffer
  4149. (unless (org-mode-p)
  4150. (error "Agenda file %s is not in `org-mode'" file))
  4151. (let ((case-fold-search nil))
  4152. (save-excursion
  4153. (save-restriction
  4154. (if org-agenda-restrict
  4155. (narrow-to-region org-agenda-restrict-begin
  4156. org-agenda-restrict-end)
  4157. (widen))
  4158. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4159. (while (setq arg (pop args))
  4160. (cond
  4161. ((and (eq arg :todo)
  4162. (equal date (calendar-gregorian-from-absolute
  4163. (org-today))))
  4164. (setq rtn (org-agenda-get-todos))
  4165. (setq results (append results rtn)))
  4166. ((eq arg :timestamp)
  4167. (setq rtn (org-agenda-get-blocks))
  4168. (setq results (append results rtn))
  4169. (setq rtn (org-agenda-get-timestamps))
  4170. (setq results (append results rtn)))
  4171. ((eq arg :sexp)
  4172. (setq rtn (org-agenda-get-sexps))
  4173. (setq results (append results rtn)))
  4174. ((eq arg :scheduled)
  4175. (setq rtn (org-agenda-get-scheduled deadline-results))
  4176. (setq results (append results rtn)))
  4177. ((eq arg :closed)
  4178. (setq rtn (org-agenda-get-progress))
  4179. (setq results (append results rtn)))
  4180. ((eq arg :deadline)
  4181. (setq rtn (org-agenda-get-deadlines))
  4182. (setq deadline-results (copy-sequence rtn))
  4183. (setq results (append results rtn))))))))
  4184. results))))
  4185. (defun org-agenda-get-todos ()
  4186. "Return the TODO information for agenda display."
  4187. (let* ((props (list 'face nil
  4188. 'done-face 'org-agenda-done
  4189. 'org-not-done-regexp org-not-done-regexp
  4190. 'org-todo-regexp org-todo-regexp
  4191. 'org-complex-heading-regexp org-complex-heading-regexp
  4192. 'mouse-face 'highlight
  4193. 'help-echo
  4194. (format "mouse-2 or RET jump to org file %s"
  4195. (abbreviate-file-name buffer-file-name))))
  4196. (regexp (concat "^\\*+[ \t]+\\("
  4197. (if org-select-this-todo-keyword
  4198. (if (equal org-select-this-todo-keyword "*")
  4199. org-todo-regexp
  4200. (concat "\\<\\("
  4201. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4202. "\\)\\>"))
  4203. org-not-done-regexp)
  4204. "[^\n\r]*\\)"))
  4205. marker priority category tags todo-state
  4206. ee txt beg end)
  4207. (goto-char (point-min))
  4208. (while (re-search-forward regexp nil t)
  4209. (catch :skip
  4210. (save-match-data
  4211. (beginning-of-line)
  4212. (org-agenda-skip)
  4213. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4214. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4215. (goto-char (1+ beg))
  4216. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4217. (throw :skip nil)))
  4218. (goto-char (match-beginning 1))
  4219. (setq marker (org-agenda-new-marker (match-beginning 0))
  4220. category (org-get-category)
  4221. txt (match-string 1)
  4222. tags (org-get-tags-at (point))
  4223. txt (org-format-agenda-item "" txt category tags)
  4224. priority (1+ (org-get-priority txt))
  4225. todo-state (org-get-todo-state))
  4226. (org-add-props txt props
  4227. 'org-marker marker 'org-hd-marker marker
  4228. 'priority priority 'org-category category
  4229. 'type "todo" 'todo-state todo-state)
  4230. (push txt ee)
  4231. (if org-agenda-todo-list-sublevels
  4232. (goto-char (match-end 1))
  4233. (org-end-of-subtree 'invisible))))
  4234. (nreverse ee)))
  4235. (defun org-agenda-todo-custom-ignore-p (time n)
  4236. "Check whether timestamp is farther away then n number of days.
  4237. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4238. `org-agenda-todo-ignore-scheduled' or
  4239. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4240. (let ((days (org-days-to-time time)))
  4241. (if (>= n 0)
  4242. (>= days n)
  4243. (<= days n))))
  4244. ;;;###autoload
  4245. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4246. (&optional end)
  4247. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4248. (when (or org-agenda-todo-ignore-with-date
  4249. org-agenda-todo-ignore-scheduled
  4250. org-agenda-todo-ignore-deadlines
  4251. org-agenda-todo-ignore-timestamp)
  4252. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4253. (save-excursion
  4254. (or (and org-agenda-todo-ignore-with-date
  4255. (re-search-forward org-ts-regexp end t))
  4256. (and org-agenda-todo-ignore-scheduled
  4257. (re-search-forward org-scheduled-time-regexp end t)
  4258. (cond
  4259. ((eq org-agenda-todo-ignore-scheduled 'future)
  4260. (> (org-days-to-time (match-string 1)) 0))
  4261. ((eq org-agenda-todo-ignore-scheduled 'past)
  4262. (<= (org-days-to-time (match-string 1)) 0))
  4263. ((numberp org-agenda-todo-ignore-scheduled)
  4264. (org-agenda-todo-custom-ignore-p
  4265. (match-string 1) org-agenda-todo-ignore-scheduled))
  4266. (t)))
  4267. (and org-agenda-todo-ignore-deadlines
  4268. (re-search-forward org-deadline-time-regexp end t)
  4269. (cond
  4270. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4271. ((eq org-agenda-todo-ignore-deadlines 'far)
  4272. (not (org-deadline-close (match-string 1))))
  4273. ((eq org-agenda-todo-ignore-deadlines 'future)
  4274. (> (org-days-to-time (match-string 1)) 0))
  4275. ((eq org-agenda-todo-ignore-deadlines 'past)
  4276. (<= (org-days-to-time (match-string 1)) 0))
  4277. ((numberp org-agenda-todo-ignore-deadlines)
  4278. (org-agenda-todo-custom-ignore-p
  4279. (match-string 1) org-agenda-todo-ignore-deadlines))
  4280. (t (org-deadline-close (match-string 1)))))
  4281. (and org-agenda-todo-ignore-timestamp
  4282. (let ((buffer (current-buffer))
  4283. (regexp
  4284. (concat
  4285. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4286. (start (point)))
  4287. ;; Copy current buffer into a temporary one
  4288. (with-temp-buffer
  4289. (insert-buffer-substring buffer start end)
  4290. (goto-char (point-min))
  4291. ;; Delete SCHEDULED and DEADLINE items
  4292. (while (re-search-forward regexp end t)
  4293. (delete-region (match-beginning 0) (match-end 0)))
  4294. (goto-char (point-min))
  4295. ;; No search for timestamp left
  4296. (when (re-search-forward org-ts-regexp nil t)
  4297. (cond
  4298. ((eq org-agenda-todo-ignore-timestamp 'future)
  4299. (> (org-days-to-time (match-string 1)) 0))
  4300. ((eq org-agenda-todo-ignore-timestamp 'past)
  4301. (<= (org-days-to-time (match-string 1)) 0))
  4302. ((numberp org-agenda-todo-ignore-timestamp)
  4303. (org-agenda-todo-custom-ignore-p
  4304. (match-string 1) org-agenda-todo-ignore-timestamp))
  4305. (t))))))))))
  4306. (defconst org-agenda-no-heading-message
  4307. "No heading for this item in buffer or region.")
  4308. (defun org-agenda-get-timestamps ()
  4309. "Return the date stamp information for agenda display."
  4310. (let* ((props (list 'face nil
  4311. 'org-not-done-regexp org-not-done-regexp
  4312. 'org-todo-regexp org-todo-regexp
  4313. 'org-complex-heading-regexp org-complex-heading-regexp
  4314. 'mouse-face 'highlight
  4315. 'help-echo
  4316. (format "mouse-2 or RET jump to org file %s"
  4317. (abbreviate-file-name buffer-file-name))))
  4318. (d1 (calendar-absolute-from-gregorian date))
  4319. (remove-re
  4320. (concat
  4321. (regexp-quote
  4322. (format-time-string
  4323. "<%Y-%m-%d"
  4324. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4325. ".*?>"))
  4326. (regexp
  4327. (concat
  4328. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4329. (regexp-quote
  4330. (substring
  4331. (format-time-string
  4332. (car org-time-stamp-formats)
  4333. (apply 'encode-time ; DATE bound by calendar
  4334. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4335. 1 11))
  4336. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4337. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4338. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4339. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4340. todo-state end-of-match show-all)
  4341. (goto-char (point-min))
  4342. (while (setq end-of-match (re-search-forward regexp nil t))
  4343. (setq b0 (match-beginning 0)
  4344. b3 (match-beginning 3) e3 (match-end 3)
  4345. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4346. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4347. (member todo-state
  4348. org-agenda-repeating-timestamp-show-all)))
  4349. (catch :skip
  4350. (and (org-at-date-range-p) (throw :skip nil))
  4351. (org-agenda-skip)
  4352. (if (and (match-end 1)
  4353. (not (= d1 (org-time-string-to-absolute
  4354. (match-string 1) d1 nil show-all))))
  4355. (throw :skip nil))
  4356. (if (and e3
  4357. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4358. (throw :skip nil))
  4359. (setq tmp (buffer-substring (max (point-min)
  4360. (- b0 org-ds-keyword-length))
  4361. b0)
  4362. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4363. inactivep (= (char-after b0) ?\[)
  4364. deadlinep (string-match org-deadline-regexp tmp)
  4365. scheduledp (string-match org-scheduled-regexp tmp)
  4366. closedp (and org-agenda-include-inactive-timestamps
  4367. (string-match org-closed-string tmp))
  4368. clockp (and org-agenda-include-inactive-timestamps
  4369. (or (string-match org-clock-string tmp)
  4370. (string-match "]-+\\'" tmp)))
  4371. donep (member todo-state org-done-keywords))
  4372. (if (or scheduledp deadlinep closedp clockp
  4373. (and donep org-agenda-skip-timestamp-if-done))
  4374. (throw :skip t))
  4375. (if (string-match ">" timestr)
  4376. ;; substring should only run to end of time stamp
  4377. (setq timestr (substring timestr 0 (match-end 0))))
  4378. (setq marker (org-agenda-new-marker b0)
  4379. category (org-get-category b0))
  4380. (save-excursion
  4381. (if (not (re-search-backward "^\\*+ " nil t))
  4382. (setq txt org-agenda-no-heading-message)
  4383. (goto-char (match-beginning 0))
  4384. (setq hdmarker (org-agenda-new-marker)
  4385. tags (org-get-tags-at))
  4386. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4387. (setq head (or (match-string 1) ""))
  4388. (setq txt (org-format-agenda-item
  4389. (if inactivep org-agenda-inactive-leader nil)
  4390. head category tags timestr
  4391. remove-re)))
  4392. (setq priority (org-get-priority txt))
  4393. (org-add-props txt props
  4394. 'org-marker marker 'org-hd-marker hdmarker)
  4395. (org-add-props txt nil 'priority priority
  4396. 'org-category category 'date date
  4397. 'todo-state todo-state
  4398. 'type "timestamp")
  4399. (push txt ee))
  4400. (if org-agenda-skip-additional-timestamps-same-entry
  4401. (outline-next-heading)
  4402. (goto-char end-of-match))))
  4403. (nreverse ee)))
  4404. (defun org-agenda-get-sexps ()
  4405. "Return the sexp information for agenda display."
  4406. (require 'diary-lib)
  4407. (let* ((props (list 'mouse-face 'highlight
  4408. 'help-echo
  4409. (format "mouse-2 or RET jump to org file %s"
  4410. (abbreviate-file-name buffer-file-name))))
  4411. (regexp "^&?%%(")
  4412. marker category ee txt tags entry result beg b sexp sexp-entry
  4413. todo-state)
  4414. (goto-char (point-min))
  4415. (while (re-search-forward regexp nil t)
  4416. (catch :skip
  4417. (org-agenda-skip)
  4418. (setq beg (match-beginning 0))
  4419. (goto-char (1- (match-end 0)))
  4420. (setq b (point))
  4421. (forward-sexp 1)
  4422. (setq sexp (buffer-substring b (point)))
  4423. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4424. (org-trim (match-string 1))
  4425. ""))
  4426. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4427. (when result
  4428. (setq marker (org-agenda-new-marker beg)
  4429. category (org-get-category beg)
  4430. todo-state (org-get-todo-state))
  4431. (dolist (r (if (stringp result)
  4432. (list result)
  4433. result)) ;; we expect a list here
  4434. (if (string-match "\\S-" r)
  4435. (setq txt r)
  4436. (setq txt "SEXP entry returned empty string"))
  4437. (setq txt (org-format-agenda-item
  4438. "" txt category tags 'time))
  4439. (org-add-props txt props 'org-marker marker)
  4440. (org-add-props txt nil
  4441. 'org-category category 'date date 'todo-state todo-state
  4442. 'type "sexp")
  4443. (push txt ee)))))
  4444. (nreverse ee)))
  4445. ;; Calendar sanity: define some functions that are independent of
  4446. ;; `calendar-date-style'.
  4447. ;; Normally I would like to use ISO format when calling the diary functions,
  4448. ;; but to make sure we still have Emacs 22 compatibility we bind
  4449. ;; also `european-calendar-style' and use european format
  4450. (defun org-anniversary (year month day &optional mark)
  4451. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4452. (org-no-warnings
  4453. (let ((calendar-date-style 'european) (european-calendar-style t))
  4454. (diary-anniversary day month year mark))))
  4455. (defun org-cyclic (N year month day &optional mark)
  4456. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4457. (org-no-warnings
  4458. (let ((calendar-date-style 'european) (european-calendar-style t))
  4459. (diary-cyclic N day month year mark))))
  4460. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4461. "Like `diary-block', but with fixed (ISO) order of arguments."
  4462. (org-no-warnings
  4463. (let ((calendar-date-style 'european) (european-calendar-style t))
  4464. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4465. (defun org-date (year month day &optional mark)
  4466. "Like `diary-date', but with fixed (ISO) order of arguments."
  4467. (org-no-warnings
  4468. (let ((calendar-date-style 'european) (european-calendar-style t))
  4469. (diary-date day month year mark))))
  4470. (defalias 'org-float 'diary-float)
  4471. ;; Define the` org-class' function
  4472. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4473. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4474. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4475. is any number of ISO weeks in the block period for which the item should
  4476. be skipped."
  4477. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4478. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4479. (d (calendar-absolute-from-gregorian date)))
  4480. (and
  4481. (<= date1 d)
  4482. (<= d date2)
  4483. (= (calendar-day-of-week date) dayname)
  4484. (or (not skip-weeks)
  4485. (progn
  4486. (require 'cal-iso)
  4487. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4488. entry)))
  4489. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4490. "Like `org-class', but honor `calendar-date-style'.
  4491. The order of the first 2 times 3 arguments depends on the variable
  4492. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4493. So for American calendars, give this as MONTH DAY YEAR, for European as
  4494. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4495. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4496. is any number of ISO weeks in the block period for which the item should
  4497. be skipped.
  4498. This function is here only for backward compatibility and it is deprecated,
  4499. please use `org-class' instead."
  4500. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4501. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4502. (org-class
  4503. (nth 2 date1) (car date1) (nth 1 date1)
  4504. (nth 2 date2) (car date2) (nth 1 date2)
  4505. dayname skip-weeks)))
  4506. (defalias 'org-get-closed 'org-agenda-get-progress)
  4507. (defun org-agenda-get-progress ()
  4508. "Return the logged TODO entries for agenda display."
  4509. (let* ((props (list 'mouse-face 'highlight
  4510. 'org-not-done-regexp org-not-done-regexp
  4511. 'org-todo-regexp org-todo-regexp
  4512. 'org-complex-heading-regexp org-complex-heading-regexp
  4513. 'help-echo
  4514. (format "mouse-2 or RET jump to org file %s"
  4515. (abbreviate-file-name buffer-file-name))))
  4516. (items (if (consp org-agenda-show-log)
  4517. org-agenda-show-log
  4518. (if (eq org-agenda-show-log 'clockcheck)
  4519. '(clock)
  4520. org-agenda-log-mode-items)))
  4521. (parts
  4522. (delq nil
  4523. (list
  4524. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4525. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4526. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4527. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4528. (error "`org-agenda-log-mode-items' is empty")))
  4529. (regexp (concat
  4530. "\\(" parts-re "\\)"
  4531. " *\\["
  4532. (regexp-quote
  4533. (substring
  4534. (format-time-string
  4535. (car org-time-stamp-formats)
  4536. (apply 'encode-time ; DATE bound by calendar
  4537. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4538. 1 11))))
  4539. (org-agenda-search-headline-for-time nil)
  4540. marker hdmarker priority category tags closedp statep clockp state
  4541. ee txt extra timestr rest clocked)
  4542. (goto-char (point-min))
  4543. (while (re-search-forward regexp nil t)
  4544. (catch :skip
  4545. (org-agenda-skip)
  4546. (setq marker (org-agenda-new-marker (match-beginning 0))
  4547. closedp (equal (match-string 1) org-closed-string)
  4548. statep (equal (string-to-char (match-string 1)) ?-)
  4549. clockp (not (or closedp statep))
  4550. state (and statep (match-string 2))
  4551. category (org-get-category (match-beginning 0))
  4552. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4553. )
  4554. (when (string-match "\\]" timestr)
  4555. ;; substring should only run to end of time stamp
  4556. (setq rest (substring timestr (match-end 0))
  4557. timestr (substring timestr 0 (match-end 0)))
  4558. (if (and (not closedp) (not statep)
  4559. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4560. (progn (setq timestr (concat (substring timestr 0 -1)
  4561. "-" (match-string 1 rest) "]"))
  4562. (setq clocked (match-string 2 rest)))
  4563. (setq clocked "-")))
  4564. (save-excursion
  4565. (setq extra
  4566. (cond
  4567. ((not org-agenda-log-mode-add-notes) nil)
  4568. (statep
  4569. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4570. (match-string 1)))
  4571. (clockp
  4572. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4573. (match-string 1)))))
  4574. (if (not (re-search-backward "^\\*+ " nil t))
  4575. (setq txt org-agenda-no-heading-message)
  4576. (goto-char (match-beginning 0))
  4577. (setq hdmarker (org-agenda-new-marker)
  4578. tags (org-get-tags-at))
  4579. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4580. (setq txt (match-string 1))
  4581. (when extra
  4582. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4583. (setq txt (concat (substring txt 0 (match-beginning 1))
  4584. " - " extra " " (match-string 2 txt)))
  4585. (setq txt (concat txt " - " extra))))
  4586. (setq txt (org-format-agenda-item
  4587. (cond
  4588. (closedp "Closed: ")
  4589. (statep (concat "State: (" state ")"))
  4590. (t (concat "Clocked: (" clocked ")")))
  4591. txt category tags timestr)))
  4592. (setq priority 100000)
  4593. (org-add-props txt props
  4594. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4595. 'priority priority 'org-category category
  4596. 'type "closed" 'date date
  4597. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4598. (push txt ee))
  4599. (goto-char (point-at-eol))))
  4600. (nreverse ee)))
  4601. (defun org-agenda-show-clocking-issues ()
  4602. "Add overlays, showing issues with clocking.
  4603. See also the user option `org-agenda-clock-consistency-checks'."
  4604. (interactive)
  4605. (let* ((pl org-agenda-clock-consistency-checks)
  4606. (re (concat "^[ \t]*"
  4607. org-clock-string
  4608. "[ \t]+"
  4609. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4610. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4611. (tlstart 0.)
  4612. (tlend 0.)
  4613. (maxtime (org-hh:mm-string-to-minutes
  4614. (or (plist-get pl :max-duration) "24:00")))
  4615. (mintime (org-hh:mm-string-to-minutes
  4616. (or (plist-get pl :min-duration) 0)))
  4617. (maxgap (org-hh:mm-string-to-minutes
  4618. ;; default 30:00 means never complain
  4619. (or (plist-get pl :max-gap) "30:00")))
  4620. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4621. (plist-get pl :gap-ok-around)))
  4622. (def-face (or (plist-get pl :default-face)
  4623. '((:background "DarkRed") (:foreground "white"))))
  4624. issue face m te ts dt ov)
  4625. (goto-char (point-min))
  4626. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4627. (setq issue nil face def-face)
  4628. (catch 'next
  4629. (setq m (org-get-at-bol 'org-marker)
  4630. te nil ts nil)
  4631. (unless (and m (markerp m))
  4632. (setq issue "No valid clock line") (throw 'next t))
  4633. (org-with-point-at m
  4634. (save-excursion
  4635. (goto-char (point-at-bol))
  4636. (unless (looking-at re)
  4637. (error "No valid Clock line")
  4638. (throw 'next t))
  4639. (unless (match-end 3)
  4640. (setq issue "No end time"
  4641. face (or (plist-get pl :no-end-time-face) face))
  4642. (throw 'next t))
  4643. (setq ts (match-string 1)
  4644. te (match-string 3)
  4645. ts (org-float-time
  4646. (apply 'encode-time (org-parse-time-string ts)))
  4647. te (org-float-time
  4648. (apply 'encode-time (org-parse-time-string te)))
  4649. dt (- te ts))))
  4650. (cond
  4651. ((> dt (* 60 maxtime))
  4652. ;; a very long clocking chunk
  4653. (setq issue (format "Clocking interval is very long: %s"
  4654. (org-minutes-to-hh:mm-string
  4655. (floor (/ (float dt) 60.))))
  4656. face (or (plist-get pl :long-face) face)))
  4657. ((< dt (* 60 mintime))
  4658. ;; a very short clocking chunk
  4659. (setq issue (format "Clocking interval is very short: %s"
  4660. (org-minutes-to-hh:mm-string
  4661. (floor (/ (float dt) 60.))))
  4662. face (or (plist-get pl :short-face) face)))
  4663. ((and (> tlend 0) (< ts tlend))
  4664. ;; Two clock entries are overlapping
  4665. (setq issue (format "Clocking overlap: %d minutes"
  4666. (/ (- tlend ts) 60))
  4667. face (or (plist-get pl :overlap-face) face)))
  4668. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4669. ;; There is a gap, lets see if we need to report it
  4670. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4671. (setq issue (format "Clocking gap: %d minutes"
  4672. (/ (- ts tlend) 60))
  4673. face (or (plist-get pl :gap-face) face))))
  4674. (t nil)))
  4675. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4676. (when issue
  4677. ;; OK, there was some issue, add an overlay to show the issue
  4678. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4679. (overlay-put ov 'before-string
  4680. (concat
  4681. (org-add-props
  4682. (format "%-43s" (concat " " issue))
  4683. nil
  4684. 'face face)
  4685. "\n"))
  4686. (overlay-put ov 'evaporate t)))))
  4687. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4688. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4689. (catch 'exit
  4690. (unless ok-list
  4691. ;; there are no OK times for gaps...
  4692. (throw 'exit nil))
  4693. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4694. ;; This is more than 24 hours, so it is OK.
  4695. ;; because we have at least one OK time, that must be in the
  4696. ;; 24 hour interval.
  4697. (throw 'exit t))
  4698. ;; We have a shorter gap.
  4699. ;; Now we have to get the minute of the day when these times are
  4700. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4701. (t2dec (decode-time (seconds-to-time t2)))
  4702. ;; compute the minute on the day
  4703. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4704. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4705. (when (< min2 min1)
  4706. ;; if min2 is smaller than min1, this means it is on the next day.
  4707. ;; Wrap it to after midnight.
  4708. (setq min2 (+ min2 1440)))
  4709. ;; Now check if any of the OK times is in the gap
  4710. (mapc (lambda (x)
  4711. ;; Wrap the time to after midnight if necessary
  4712. (if (< x min1) (setq x (+ x 1440)))
  4713. ;; Check if in interval
  4714. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4715. ok-list)
  4716. ;; Nope, this gap is not OK
  4717. nil)))
  4718. (defun org-agenda-get-deadlines ()
  4719. "Return the deadline information for agenda display."
  4720. (let* ((props (list 'mouse-face 'highlight
  4721. 'org-not-done-regexp org-not-done-regexp
  4722. 'org-todo-regexp org-todo-regexp
  4723. 'org-complex-heading-regexp org-complex-heading-regexp
  4724. 'help-echo
  4725. (format "mouse-2 or RET jump to org file %s"
  4726. (abbreviate-file-name buffer-file-name))))
  4727. (regexp org-deadline-time-regexp)
  4728. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4729. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4730. d2 diff dfrac wdays pos pos1 category tags
  4731. suppress-prewarning
  4732. ee txt head face s todo-state show-all upcomingp donep timestr)
  4733. (goto-char (point-min))
  4734. (while (re-search-forward regexp nil t)
  4735. (setq suppress-prewarning nil)
  4736. (catch :skip
  4737. (org-agenda-skip)
  4738. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4739. (save-match-data
  4740. (string-match org-scheduled-time-regexp
  4741. (buffer-substring (point-at-bol)
  4742. (point-at-eol)))))
  4743. (setq suppress-prewarning
  4744. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4745. org-agenda-skip-deadline-prewarning-if-scheduled
  4746. 0)))
  4747. (setq s (match-string 1)
  4748. txt nil
  4749. pos (1- (match-beginning 1))
  4750. todo-state (save-match-data (org-get-todo-state))
  4751. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4752. (member todo-state
  4753. org-agenda-repeating-timestamp-show-all))
  4754. d2 (org-time-string-to-absolute
  4755. (match-string 1) d1 'past show-all)
  4756. diff (- d2 d1)
  4757. wdays (if suppress-prewarning
  4758. (let ((org-deadline-warning-days suppress-prewarning))
  4759. (org-get-wdays s))
  4760. (org-get-wdays s))
  4761. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4762. upcomingp (and todayp (> diff 0)))
  4763. ;; When to show a deadline in the calendar:
  4764. ;; If the expiration is within wdays warning time.
  4765. ;; Past-due deadlines are only shown on the current date
  4766. (if (and (or (and (<= diff wdays)
  4767. (and todayp (not org-agenda-only-exact-dates)))
  4768. (= diff 0)))
  4769. (save-excursion
  4770. ;; (setq todo-state (org-get-todo-state))
  4771. (setq donep (member todo-state org-done-keywords))
  4772. (if (and donep
  4773. (or org-agenda-skip-deadline-if-done
  4774. (not (= diff 0))))
  4775. (setq txt nil)
  4776. (setq category (org-get-category))
  4777. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4778. (setq txt org-agenda-no-heading-message)
  4779. (goto-char (match-end 0))
  4780. (setq pos1 (match-beginning 0))
  4781. (setq tags (org-get-tags-at pos1))
  4782. (setq head (buffer-substring-no-properties
  4783. (point)
  4784. (progn (skip-chars-forward "^\r\n")
  4785. (point))))
  4786. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4787. (setq timestr
  4788. (concat (substring s (match-beginning 1)) " "))
  4789. (setq timestr 'time))
  4790. (setq txt (org-format-agenda-item
  4791. (if (= diff 0)
  4792. (car org-agenda-deadline-leaders)
  4793. (if (functionp
  4794. (nth 1 org-agenda-deadline-leaders))
  4795. (funcall
  4796. (nth 1 org-agenda-deadline-leaders)
  4797. diff date)
  4798. (format (nth 1 org-agenda-deadline-leaders)
  4799. diff)))
  4800. head category tags
  4801. (if (not (= diff 0)) nil timestr)))))
  4802. (when txt
  4803. (setq face (org-agenda-deadline-face dfrac wdays))
  4804. (org-add-props txt props
  4805. 'org-marker (org-agenda-new-marker pos)
  4806. 'org-hd-marker (org-agenda-new-marker pos1)
  4807. 'priority (+ (- diff)
  4808. (org-get-priority txt))
  4809. 'org-category category
  4810. 'todo-state todo-state
  4811. 'type (if upcomingp "upcoming-deadline" "deadline")
  4812. 'date (if upcomingp date d2)
  4813. 'face (if donep 'org-agenda-done face)
  4814. 'undone-face face 'done-face 'org-agenda-done)
  4815. (push txt ee))))))
  4816. (nreverse ee)))
  4817. (defun org-agenda-deadline-face (fraction &optional wdays)
  4818. "Return the face to displaying a deadline item.
  4819. FRACTION is what fraction of the head-warning time has passed."
  4820. (if (equal wdays 0) (setq fraction 1.))
  4821. (let ((faces org-agenda-deadline-faces) f)
  4822. (catch 'exit
  4823. (while (setq f (pop faces))
  4824. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4825. (defun org-agenda-get-scheduled (&optional deadline-results)
  4826. "Return the scheduled information for agenda display."
  4827. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4828. 'org-todo-regexp org-todo-regexp
  4829. 'org-complex-heading-regexp org-complex-heading-regexp
  4830. 'done-face 'org-agenda-done
  4831. 'mouse-face 'highlight
  4832. 'help-echo
  4833. (format "mouse-2 or RET jump to org file %s"
  4834. (abbreviate-file-name buffer-file-name))))
  4835. (regexp org-scheduled-time-regexp)
  4836. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4837. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4838. mm
  4839. (deadline-position-alist
  4840. (mapcar (lambda (a) (and (setq mm (get-text-property
  4841. 0 'org-hd-marker a))
  4842. (cons (marker-position mm) a)))
  4843. deadline-results))
  4844. d2 diff pos pos1 category tags donep
  4845. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4846. (goto-char (point-min))
  4847. (while (re-search-forward regexp nil t)
  4848. (catch :skip
  4849. (org-agenda-skip)
  4850. (setq s (match-string 1)
  4851. txt nil
  4852. pos (1- (match-beginning 1))
  4853. todo-state (save-match-data (org-get-todo-state))
  4854. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4855. (member todo-state
  4856. org-agenda-repeating-timestamp-show-all))
  4857. d2 (org-time-string-to-absolute
  4858. (match-string 1) d1 'past show-all)
  4859. diff (- d2 d1))
  4860. (setq pastschedp (and todayp (< diff 0)))
  4861. ;; When to show a scheduled item in the calendar:
  4862. ;; If it is on or past the date.
  4863. (when (or (and (< diff 0)
  4864. (< (abs diff) org-scheduled-past-days)
  4865. (and todayp (not org-agenda-only-exact-dates)))
  4866. (= diff 0))
  4867. (save-excursion
  4868. (setq donep (member todo-state org-done-keywords))
  4869. (if (and donep
  4870. (or org-agenda-skip-scheduled-if-done
  4871. (not (= diff 0))
  4872. (and (functionp 'org-is-habit-p)
  4873. (org-is-habit-p))))
  4874. (setq txt nil)
  4875. (setq habitp (and (functionp 'org-is-habit-p)
  4876. (org-is-habit-p)))
  4877. (setq category (org-get-category))
  4878. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4879. (setq txt org-agenda-no-heading-message)
  4880. (goto-char (match-end 0))
  4881. (setq pos1 (match-beginning 0))
  4882. (if habitp
  4883. (if (or (not org-habit-show-habits)
  4884. (and (not todayp)
  4885. org-habit-show-habits-only-for-today))
  4886. (throw :skip nil))
  4887. (if (and
  4888. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4889. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4890. pastschedp))
  4891. (setq mm (assoc pos1 deadline-position-alist)))
  4892. (throw :skip nil)))
  4893. (setq tags (org-get-tags-at))
  4894. (setq head (buffer-substring-no-properties
  4895. (point)
  4896. (progn (skip-chars-forward "^\r\n") (point))))
  4897. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4898. (setq timestr
  4899. (concat (substring s (match-beginning 1)) " "))
  4900. (setq timestr 'time))
  4901. (setq txt (org-format-agenda-item
  4902. (if (= diff 0)
  4903. (car org-agenda-scheduled-leaders)
  4904. (format (nth 1 org-agenda-scheduled-leaders)
  4905. (- 1 diff)))
  4906. head category tags
  4907. (if (not (= diff 0)) nil timestr)
  4908. nil habitp))))
  4909. (when txt
  4910. (setq face
  4911. (cond
  4912. ((and (not habitp) pastschedp)
  4913. 'org-scheduled-previously)
  4914. (todayp 'org-scheduled-today)
  4915. (t 'org-scheduled))
  4916. habitp (and habitp (org-habit-parse-todo)))
  4917. (org-add-props txt props
  4918. 'undone-face face
  4919. 'face (if donep 'org-agenda-done face)
  4920. 'org-marker (org-agenda-new-marker pos)
  4921. 'org-hd-marker (org-agenda-new-marker pos1)
  4922. 'type (if pastschedp "past-scheduled" "scheduled")
  4923. 'date (if pastschedp d2 date)
  4924. 'priority (if habitp
  4925. (org-habit-get-priority habitp)
  4926. (+ 94 (- 5 diff) (org-get-priority txt)))
  4927. 'org-category category
  4928. 'org-habit-p habitp
  4929. 'todo-state todo-state)
  4930. (push txt ee))))))
  4931. (nreverse ee)))
  4932. (defun org-agenda-get-blocks ()
  4933. "Return the date-range information for agenda display."
  4934. (let* ((props (list 'face nil
  4935. 'org-not-done-regexp org-not-done-regexp
  4936. 'org-todo-regexp org-todo-regexp
  4937. 'org-complex-heading-regexp org-complex-heading-regexp
  4938. 'mouse-face 'highlight
  4939. 'help-echo
  4940. (format "mouse-2 or RET jump to org file %s"
  4941. (abbreviate-file-name buffer-file-name))))
  4942. (regexp org-tr-regexp)
  4943. (d0 (calendar-absolute-from-gregorian date))
  4944. marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
  4945. head donep)
  4946. (goto-char (point-min))
  4947. (while (re-search-forward regexp nil t)
  4948. (catch :skip
  4949. (org-agenda-skip)
  4950. (setq pos (point))
  4951. (let ((start-time (match-string 1))
  4952. (end-time (match-string 2)))
  4953. (setq s1 (match-string 1)
  4954. s2 (match-string 2)
  4955. d1 (time-to-days (org-time-string-to-time s1))
  4956. d2 (time-to-days (org-time-string-to-time s2)))
  4957. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4958. ;; Only allow days between the limits, because the normal
  4959. ;; date stamps will catch the limits.
  4960. (save-excursion
  4961. (setq todo-state (org-get-todo-state))
  4962. (setq donep (member todo-state org-done-keywords))
  4963. (if (and donep org-agenda-skip-timestamp-if-done)
  4964. (throw :skip t))
  4965. (setq marker (org-agenda-new-marker (point)))
  4966. (setq category (org-get-category))
  4967. (if (not (re-search-backward "^\\*+ " nil t))
  4968. (setq txt org-agenda-no-heading-message)
  4969. (goto-char (match-beginning 0))
  4970. (setq hdmarker (org-agenda-new-marker (point)))
  4971. (setq tags (org-get-tags-at))
  4972. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4973. (setq head (match-string 1))
  4974. (let ((remove-re
  4975. (if org-agenda-remove-timeranges-from-blocks
  4976. (concat
  4977. "<" (regexp-quote s1) ".*?>"
  4978. "--"
  4979. "<" (regexp-quote s2) ".*?>")
  4980. nil)))
  4981. (setq txt (org-format-agenda-item
  4982. (format
  4983. (nth (if (= d1 d2) 0 1)
  4984. org-agenda-timerange-leaders)
  4985. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4986. head category tags
  4987. (cond ((= d1 d0)
  4988. (concat "<" start-time ">"))
  4989. ((= d2 d0)
  4990. (concat "<" end-time ">"))
  4991. (t nil))
  4992. remove-re))))
  4993. (org-add-props txt props
  4994. 'org-marker marker 'org-hd-marker hdmarker
  4995. 'type "block" 'date date
  4996. 'todo-state todo-state
  4997. 'priority (org-get-priority txt) 'org-category category)
  4998. (push txt ee))))
  4999. (goto-char pos)))
  5000. ;; Sort the entries by expiration date.
  5001. (nreverse ee)))
  5002. ;;; Agenda presentation and sorting
  5003. (defvar org-prefix-has-time nil
  5004. "A flag, set by `org-compile-prefix-format'.
  5005. The flag is set if the currently compiled format contains a `%t'.")
  5006. (defvar org-prefix-has-tag nil
  5007. "A flag, set by `org-compile-prefix-format'.
  5008. The flag is set if the currently compiled format contains a `%T'.")
  5009. (defvar org-prefix-has-effort nil
  5010. "A flag, set by `org-compile-prefix-format'.
  5011. The flag is set if the currently compiled format contains a `%e'.")
  5012. (defvar org-prefix-category-length nil
  5013. "Used by `org-compile-prefix-format' to remember the category field width.")
  5014. (defvar org-prefix-category-max-length nil
  5015. "Used by `org-compile-prefix-format' to remember the category field width.")
  5016. (defun org-agenda-get-category-icon (category)
  5017. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5018. (dolist (entry org-agenda-category-icon-alist)
  5019. (when (org-string-match-p (car entry) category)
  5020. (if (listp (cadr entry))
  5021. (return (cadr entry))
  5022. (return (apply 'create-image (cdr entry)))))))
  5023. (defun org-format-agenda-item (extra txt &optional category tags dotime
  5024. remove-re habitp)
  5025. "Format TXT to be inserted into the agenda buffer.
  5026. In particular, it adds the prefix and corresponding text properties. EXTRA
  5027. must be a string and replaces the `%s' specifier in the prefix format.
  5028. CATEGORY (string, symbol or nil) may be used to overrule the default
  5029. category taken from local variable or file name. It will replace the `%c'
  5030. specifier in the format. DOTIME, when non-nil, indicates that a
  5031. time-of-day should be extracted from TXT for sorting of this entry, and for
  5032. the `%t' specifier in the format. When DOTIME is a string, this string is
  5033. searched for a time before TXT is. TAGS can be the tags of the headline.
  5034. Any match of REMOVE-RE will be removed from TXT."
  5035. (save-match-data
  5036. ;; Diary entries sometimes have extra whitespace at the beginning
  5037. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5038. ;; Fix the tags part in txt
  5039. (setq txt (org-agenda-fix-displayed-tags
  5040. txt tags
  5041. org-agenda-show-inherited-tags
  5042. org-agenda-hide-tags-regexp))
  5043. (let* ((category (or category
  5044. (if (stringp org-category)
  5045. org-category
  5046. (and org-category (symbol-name org-category)))
  5047. (if buffer-file-name
  5048. (file-name-sans-extension
  5049. (file-name-nondirectory buffer-file-name))
  5050. "")))
  5051. (category-icon (org-agenda-get-category-icon category))
  5052. (category-icon (if category-icon
  5053. (propertize " " 'display category-icon)
  5054. ""))
  5055. ;; time, tag, effort are needed for the eval of the prefix format
  5056. (tag (if tags (nth (1- (length tags)) tags) ""))
  5057. time effort neffort
  5058. (ts (if dotime (concat
  5059. (if (stringp dotime) dotime "")
  5060. (and org-agenda-search-headline-for-time txt))))
  5061. (time-of-day (and dotime (org-get-time-of-day ts)))
  5062. stamp plain s0 s1 s2 rtn srp l
  5063. duration thecategory)
  5064. (and (org-mode-p) buffer-file-name
  5065. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5066. (when (and dotime time-of-day)
  5067. ;; Extract starting and ending time and move them to prefix
  5068. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5069. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5070. (setq s0 (match-string 0 ts)
  5071. srp (and stamp (match-end 3))
  5072. s1 (match-string (if plain 1 2) ts)
  5073. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5074. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5075. ;; them, we might want to remove them there to avoid duplication.
  5076. ;; The user can turn this off with a variable.
  5077. (if (and org-prefix-has-time
  5078. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5079. (string-match (concat (regexp-quote s0) " *") txt)
  5080. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5081. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5082. (= (match-beginning 0) 0)
  5083. t))
  5084. (setq txt (replace-match "" nil nil txt))))
  5085. ;; Normalize the time(s) to 24 hour
  5086. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5087. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5088. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5089. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5090. (setq s2
  5091. (org-minutes-to-hh:mm-string
  5092. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5093. ;; Compute the duration
  5094. (when s2
  5095. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5096. (org-hh:mm-string-to-minutes s1)))))
  5097. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5098. txt)
  5099. ;; Tags are in the string
  5100. (if (or (eq org-agenda-remove-tags t)
  5101. (and org-agenda-remove-tags
  5102. org-prefix-has-tag))
  5103. (setq txt (replace-match "" t t txt))
  5104. (setq txt (replace-match
  5105. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5106. (match-string 2 txt))
  5107. t t txt))))
  5108. (when (org-mode-p)
  5109. (setq effort
  5110. (condition-case nil
  5111. (org-get-effort
  5112. (or (get-text-property 0 'org-hd-marker txt)
  5113. (get-text-property 0 'org-marker txt)))
  5114. (error nil)))
  5115. (when effort
  5116. (setq neffort (org-duration-string-to-minutes effort)
  5117. effort (setq effort (concat "[" effort "]" )))))
  5118. (when remove-re
  5119. (while (string-match remove-re txt)
  5120. (setq txt (replace-match "" t t txt))))
  5121. ;; Set org-heading property on `txt' to mark the start of the
  5122. ;; heading.
  5123. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5124. ;; Prepare the variables needed in the eval of the compiled format
  5125. (setq time (cond (s2 (concat
  5126. (org-agenda-time-of-day-to-ampm-maybe s1)
  5127. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5128. (if org-agenda-timegrid-use-ampm " ")))
  5129. (s1 (concat
  5130. (org-agenda-time-of-day-to-ampm-maybe s1)
  5131. (if org-agenda-timegrid-use-ampm
  5132. "........ "
  5133. "......")))
  5134. (t ""))
  5135. extra (or (and (not habitp) extra) "")
  5136. category (if (symbolp category) (symbol-name category) category)
  5137. thecategory (copy-sequence category))
  5138. (if (string-match org-bracket-link-regexp category)
  5139. (progn
  5140. (setq l (if (match-end 3)
  5141. (- (match-end 3) (match-beginning 3))
  5142. (- (match-end 1) (match-beginning 1))))
  5143. (when (< l (or org-prefix-category-length 0))
  5144. (setq category (copy-sequence category))
  5145. (org-add-props category nil
  5146. 'extra-space (make-string
  5147. (- org-prefix-category-length l 1) ?\ ))))
  5148. (if (and org-prefix-category-max-length
  5149. (>= (length category) org-prefix-category-max-length))
  5150. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5151. ;; Evaluate the compiled format
  5152. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5153. ;; And finally add the text properties
  5154. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5155. (org-add-props rtn nil
  5156. 'org-category (if thecategory (downcase thecategory) category)
  5157. 'tags (mapcar 'org-downcase-keep-props tags)
  5158. 'org-highest-priority org-highest-priority
  5159. 'org-lowest-priority org-lowest-priority
  5160. 'time-of-day time-of-day
  5161. 'duration duration
  5162. 'effort effort
  5163. 'effort-minutes neffort
  5164. 'txt txt
  5165. 'time time
  5166. 'extra extra
  5167. 'dotime dotime))))
  5168. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5169. "Remove tags string from TXT, and add a modified list of tags.
  5170. The modified list may contain inherited tags, and tags matched by
  5171. `org-agenda-hide-tags-regexp' will be removed."
  5172. (when (or add-inherited hide-re)
  5173. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5174. (setq txt (substring txt 0 (match-beginning 0))))
  5175. (setq tags
  5176. (delq nil
  5177. (mapcar (lambda (tg)
  5178. (if (or (and hide-re (string-match hide-re tg))
  5179. (and (not add-inherited)
  5180. (get-text-property 0 'inherited tg)))
  5181. nil
  5182. tg))
  5183. tags)))
  5184. (when tags
  5185. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5186. i)
  5187. (setq txt (concat txt " :"
  5188. (mapconcat
  5189. (lambda (x)
  5190. (setq i (get-text-property 0 'inherited x))
  5191. (if (and have-i (not i))
  5192. (progn
  5193. (setq have-i nil)
  5194. (concat ":" x))
  5195. x))
  5196. tags ":")
  5197. (if have-i "::" ":"))))))
  5198. txt)
  5199. (defun org-downcase-keep-props (s)
  5200. (let ((props (text-properties-at 0 s)))
  5201. (setq s (downcase s))
  5202. (add-text-properties 0 (length s) props s)
  5203. s))
  5204. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5205. (defvar org-agenda-sorting-strategy-selected nil)
  5206. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5207. (catch 'exit
  5208. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5209. ((and todayp (member 'today (car org-agenda-time-grid))))
  5210. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5211. ((member 'weekly (car org-agenda-time-grid)))
  5212. (t (throw 'exit list)))
  5213. (let* ((have (delq nil (mapcar
  5214. (lambda (x) (get-text-property 1 'time-of-day x))
  5215. list)))
  5216. (string (nth 1 org-agenda-time-grid))
  5217. (gridtimes (nth 2 org-agenda-time-grid))
  5218. (req (car org-agenda-time-grid))
  5219. (remove (member 'remove-match req))
  5220. new time)
  5221. (if (and (member 'require-timed req) (not have))
  5222. ;; don't show empty grid
  5223. (throw 'exit list))
  5224. (while (setq time (pop gridtimes))
  5225. (unless (and remove (member time have))
  5226. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5227. (push (org-format-agenda-item
  5228. nil string "" nil
  5229. (concat (substring time 0 -2) ":" (substring time -2)))
  5230. new)
  5231. (put-text-property
  5232. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5233. (when (and todayp org-agenda-show-current-time-in-grid)
  5234. (push (org-format-agenda-item
  5235. nil
  5236. org-agenda-current-time-string
  5237. "" nil
  5238. (format-time-string "%H:%M "))
  5239. new)
  5240. (put-text-property
  5241. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5242. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5243. (append new list)
  5244. (append list new)))))
  5245. (defun org-compile-prefix-format (key)
  5246. "Compile the prefix format into a Lisp form that can be evaluated.
  5247. The resulting form is returned and stored in the variable
  5248. `org-prefix-format-compiled'."
  5249. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5250. org-prefix-category-length nil org-prefix-has-effort nil)
  5251. (let ((s (cond
  5252. ((stringp org-agenda-prefix-format)
  5253. org-agenda-prefix-format)
  5254. ((assq key org-agenda-prefix-format)
  5255. (cdr (assq key org-agenda-prefix-format)))
  5256. (t " %-12:c%?-12t% s")))
  5257. (start 0)
  5258. varform vars var e c f opt)
  5259. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5260. s start)
  5261. (setq var (or (cdr (assoc (match-string 4 s)
  5262. '(("c" . category) ("t" . time) ("s" . extra)
  5263. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5264. 'eval)
  5265. c (or (match-string 3 s) "")
  5266. opt (match-beginning 1)
  5267. start (1+ (match-beginning 0)))
  5268. (if (equal var 'time) (setq org-prefix-has-time t))
  5269. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5270. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5271. (setq f (concat "%" (match-string 2 s) "s"))
  5272. (when (equal var 'category)
  5273. (setq org-prefix-category-length
  5274. (floor (abs (string-to-number (match-string 2 s)))))
  5275. (setq org-prefix-category-max-length
  5276. (let ((x (match-string 2 s)))
  5277. (save-match-data
  5278. (if (string-match "\\.[0-9]+" x)
  5279. (string-to-number (substring (match-string 0 x) 1)))))))
  5280. (if (eq var 'eval)
  5281. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5282. (if opt
  5283. (setq varform
  5284. `(if (equal "" ,var)
  5285. ""
  5286. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5287. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5288. (setq s (replace-match "%s" t nil s))
  5289. (push varform vars))
  5290. (setq vars (nreverse vars))
  5291. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5292. (defun org-set-sorting-strategy (key)
  5293. (if (symbolp (car org-agenda-sorting-strategy))
  5294. ;; the old format
  5295. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5296. (setq org-agenda-sorting-strategy-selected
  5297. (or (cdr (assq key org-agenda-sorting-strategy))
  5298. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5299. '(time-up category-keep priority-down)))))
  5300. (defun org-get-time-of-day (s &optional string mod24)
  5301. "Check string S for a time of day.
  5302. If found, return it as a military time number between 0 and 2400.
  5303. If not found, return nil.
  5304. The optional STRING argument forces conversion into a 5 character wide string
  5305. HH:MM."
  5306. (save-match-data
  5307. (when
  5308. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5309. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5310. (let* ((h (string-to-number (match-string 1 s)))
  5311. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5312. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5313. (am-p (equal ampm "am"))
  5314. (h1 (cond ((not ampm) h)
  5315. ((= h 12) (if am-p 0 12))
  5316. (t (+ h (if am-p 0 12)))))
  5317. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5318. (mod h1 24) h1))
  5319. (t0 (+ (* 100 h2) m))
  5320. (t1 (concat (if (>= h1 24) "+" " ")
  5321. (if (and org-agenda-time-leading-zero
  5322. (< t0 1000)) "0" "")
  5323. (if (< t0 100) "0" "")
  5324. (if (< t0 10) "0" "")
  5325. (int-to-string t0))))
  5326. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5327. (defvar org-agenda-before-sorting-filter-function nil
  5328. "Function to be applied to agenda items prior to sorting.
  5329. Prior to sorting also means just before they are inserted into the agenda.
  5330. To aid sorting, you may revisit the original entries and add more text
  5331. properties which will later be used by the sorting functions.
  5332. The function should take a string argument, an agenda line.
  5333. It has access to the text properties in that line, which contain among
  5334. other things, the property `org-hd-marker' that points to the entry
  5335. where the line comes from. Note that not all lines going into the agenda
  5336. have this property, only most.
  5337. The function should return the modified string. It is probably best
  5338. to ONLY change text properties.
  5339. You can also use this function as a filter, by returning nil for lines
  5340. you don't want to have in the agenda at all. For this application, you
  5341. could bind the variable in the options section of a custom command.")
  5342. (defun org-finalize-agenda-entries (list &optional nosort)
  5343. "Sort and concatenate the agenda items."
  5344. (setq list (mapcar 'org-agenda-highlight-todo list))
  5345. (if nosort
  5346. list
  5347. (when org-agenda-before-sorting-filter-function
  5348. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5349. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5350. (defun org-agenda-highlight-todo (x)
  5351. (let ((org-done-keywords org-done-keywords-for-agenda)
  5352. (case-fold-search nil)
  5353. re)
  5354. (if (eq x 'line)
  5355. (save-excursion
  5356. (beginning-of-line 1)
  5357. (setq re (org-get-at-bol 'org-todo-regexp))
  5358. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5359. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5360. (add-text-properties (match-beginning 0) (match-end 1)
  5361. (list 'face (org-get-todo-face 1)))
  5362. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5363. (delete-region (match-beginning 1) (1- (match-end 0)))
  5364. (goto-char (match-beginning 1))
  5365. (insert (format org-agenda-todo-keyword-format s)))))
  5366. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5367. (setq re (get-text-property 0 'org-todo-regexp x))
  5368. (when (and re
  5369. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5370. x (or pl 0)) pl))
  5371. (add-text-properties
  5372. (or (match-end 1) (match-end 0)) (match-end 0)
  5373. (list 'face (org-get-todo-face (match-string 2 x)))
  5374. x)
  5375. (when (match-end 1)
  5376. (setq x (concat (substring x 0 (match-end 1))
  5377. (format org-agenda-todo-keyword-format
  5378. (match-string 2 x))
  5379. (org-add-props " " (text-properties-at 0 x))
  5380. (substring x (match-end 3)))))))
  5381. x)))
  5382. (defsubst org-cmp-priority (a b)
  5383. "Compare the priorities of string A and B."
  5384. (let ((pa (or (get-text-property 1 'priority a) 0))
  5385. (pb (or (get-text-property 1 'priority b) 0)))
  5386. (cond ((> pa pb) +1)
  5387. ((< pa pb) -1)
  5388. (t nil))))
  5389. (defsubst org-cmp-effort (a b)
  5390. "Compare the priorities of string A and B."
  5391. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5392. (ea (or (get-text-property 1 'effort-minutes a) def))
  5393. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5394. (cond ((> ea eb) +1)
  5395. ((< ea eb) -1)
  5396. (t nil))))
  5397. (defsubst org-cmp-category (a b)
  5398. "Compare the string values of categories of strings A and B."
  5399. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5400. (cb (or (get-text-property 1 'org-category b) "")))
  5401. (cond ((string-lessp ca cb) -1)
  5402. ((string-lessp cb ca) +1)
  5403. (t nil))))
  5404. (defsubst org-cmp-todo-state (a b)
  5405. "Compare the todo states of strings A and B."
  5406. (let* ((ma (or (get-text-property 1 'org-marker a)
  5407. (get-text-property 1 'org-hd-marker a)))
  5408. (mb (or (get-text-property 1 'org-marker b)
  5409. (get-text-property 1 'org-hd-marker b)))
  5410. (fa (and ma (marker-buffer ma)))
  5411. (fb (and mb (marker-buffer mb)))
  5412. (todo-kwds
  5413. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5414. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5415. (ta (or (get-text-property 1 'todo-state a) ""))
  5416. (tb (or (get-text-property 1 'todo-state b) ""))
  5417. (la (- (length (member ta todo-kwds))))
  5418. (lb (- (length (member tb todo-kwds))))
  5419. (donepa (member ta org-done-keywords-for-agenda))
  5420. (donepb (member tb org-done-keywords-for-agenda)))
  5421. (cond ((and donepa (not donepb)) -1)
  5422. ((and (not donepa) donepb) +1)
  5423. ((< la lb) -1)
  5424. ((< lb la) +1)
  5425. (t nil))))
  5426. (defsubst org-cmp-alpha (a b)
  5427. "Compare the headlines, alphabetically."
  5428. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5429. (plb (text-property-any 0 (length b) 'org-heading t b))
  5430. (ta (and pla (substring a pla)))
  5431. (tb (and plb (substring b plb))))
  5432. (when pla
  5433. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5434. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5435. (setq ta (substring ta (match-end 0))))
  5436. (setq ta (downcase ta)))
  5437. (when plb
  5438. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5439. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5440. (setq tb (substring tb (match-end 0))))
  5441. (setq tb (downcase tb)))
  5442. (cond ((not ta) +1)
  5443. ((not tb) -1)
  5444. ((string-lessp ta tb) -1)
  5445. ((string-lessp tb ta) +1)
  5446. (t nil))))
  5447. (defsubst org-cmp-tag (a b)
  5448. "Compare the string values of the first tags of A and B."
  5449. (let ((ta (car (last (get-text-property 1 'tags a))))
  5450. (tb (car (last (get-text-property 1 'tags b)))))
  5451. (cond ((not ta) +1)
  5452. ((not tb) -1)
  5453. ((string-lessp ta tb) -1)
  5454. ((string-lessp tb ta) +1)
  5455. (t nil))))
  5456. (defsubst org-cmp-time (a b)
  5457. "Compare the time-of-day values of strings A and B."
  5458. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5459. (ta (or (get-text-property 1 'time-of-day a) def))
  5460. (tb (or (get-text-property 1 'time-of-day b) def)))
  5461. (cond ((< ta tb) -1)
  5462. ((< tb ta) +1)
  5463. (t nil))))
  5464. (defsubst org-cmp-habit-p (a b)
  5465. "Compare the todo states of strings A and B."
  5466. (let ((ha (get-text-property 1 'org-habit-p a))
  5467. (hb (get-text-property 1 'org-habit-p b)))
  5468. (cond ((and ha (not hb)) -1)
  5469. ((and (not ha) hb) +1)
  5470. (t nil))))
  5471. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5472. (defun org-entries-lessp (a b)
  5473. "Predicate for sorting agenda entries."
  5474. ;; The following variables will be used when the form is evaluated.
  5475. ;; So even though the compiler complains, keep them.
  5476. (let* ((ss org-agenda-sorting-strategy-selected)
  5477. (time-up (and (org-em 'time-up 'time-down ss)
  5478. (org-cmp-time a b)))
  5479. (time-down (if time-up (- time-up) nil))
  5480. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5481. (org-cmp-priority a b)))
  5482. (priority-down (if priority-up (- priority-up) nil))
  5483. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5484. (org-cmp-effort a b)))
  5485. (effort-down (if effort-up (- effort-up) nil))
  5486. (category-up (and (or (org-em 'category-up 'category-down ss)
  5487. (memq 'category-keep ss))
  5488. (org-cmp-category a b)))
  5489. (category-down (if category-up (- category-up) nil))
  5490. (category-keep (if category-up +1 nil))
  5491. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5492. (org-cmp-tag a b)))
  5493. (tag-down (if tag-up (- tag-up) nil))
  5494. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5495. (org-cmp-todo-state a b)))
  5496. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5497. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5498. (org-cmp-habit-p a b)))
  5499. (habit-down (if habit-up (- habit-up) nil))
  5500. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5501. (org-cmp-alpha a b)))
  5502. (alpha-down (if alpha-up (- alpha-up) nil))
  5503. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5504. user-defined-up user-defined-down)
  5505. (if (and need-user-cmp org-agenda-cmp-user-defined
  5506. (functionp org-agenda-cmp-user-defined))
  5507. (setq user-defined-up
  5508. (funcall org-agenda-cmp-user-defined a b)
  5509. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5510. (cdr (assoc
  5511. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5512. '((-1 . t) (1 . nil) (nil . nil))))))
  5513. ;;; Agenda restriction lock
  5514. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5515. "Overlay to mark the headline to which agenda commands are restricted.")
  5516. (overlay-put org-agenda-restriction-lock-overlay
  5517. 'face 'org-agenda-restriction-lock)
  5518. (overlay-put org-agenda-restriction-lock-overlay
  5519. 'help-echo "Agendas are currently limited to this subtree.")
  5520. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5521. (defun org-agenda-set-restriction-lock (&optional type)
  5522. "Set restriction lock for agenda, to current subtree or file.
  5523. Restriction will be the file if TYPE is `file', or if type is the
  5524. universal prefix '(4), or if the cursor is before the first headline
  5525. in the file. Otherwise, restriction will be to the current subtree."
  5526. (interactive "P")
  5527. (and (equal type '(4)) (setq type 'file))
  5528. (setq type (cond
  5529. (type type)
  5530. ((org-at-heading-p) 'subtree)
  5531. ((condition-case nil (org-back-to-heading t) (error nil))
  5532. 'subtree)
  5533. (t 'file)))
  5534. (if (eq type 'subtree)
  5535. (progn
  5536. (setq org-agenda-restrict t)
  5537. (setq org-agenda-overriding-restriction 'subtree)
  5538. (put 'org-agenda-files 'org-restrict
  5539. (list (buffer-file-name (buffer-base-buffer))))
  5540. (org-back-to-heading t)
  5541. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5542. (move-marker org-agenda-restrict-begin (point))
  5543. (move-marker org-agenda-restrict-end
  5544. (save-excursion (org-end-of-subtree t)))
  5545. (message "Locking agenda restriction to subtree"))
  5546. (put 'org-agenda-files 'org-restrict
  5547. (list (buffer-file-name (buffer-base-buffer))))
  5548. (setq org-agenda-restrict nil)
  5549. (setq org-agenda-overriding-restriction 'file)
  5550. (move-marker org-agenda-restrict-begin nil)
  5551. (move-marker org-agenda-restrict-end nil)
  5552. (message "Locking agenda restriction to file"))
  5553. (setq current-prefix-arg nil)
  5554. (org-agenda-maybe-redo))
  5555. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5556. "Remove the agenda restriction lock."
  5557. (interactive "P")
  5558. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5559. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5560. (setq org-agenda-overriding-restriction nil)
  5561. (setq org-agenda-restrict nil)
  5562. (put 'org-agenda-files 'org-restrict nil)
  5563. (move-marker org-agenda-restrict-begin nil)
  5564. (move-marker org-agenda-restrict-end nil)
  5565. (setq current-prefix-arg nil)
  5566. (message "Agenda restriction lock removed")
  5567. (or noupdate (org-agenda-maybe-redo)))
  5568. (defun org-agenda-maybe-redo ()
  5569. "If there is any window showing the agenda view, update it."
  5570. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5571. (w0 (selected-window)))
  5572. (when w
  5573. (select-window w)
  5574. (org-agenda-redo)
  5575. (select-window w0)
  5576. (if org-agenda-overriding-restriction
  5577. (message "Agenda view shifted to new %s restriction"
  5578. org-agenda-overriding-restriction)
  5579. (message "Agenda restriction lock removed")))))
  5580. ;;; Agenda commands
  5581. (defun org-agenda-check-type (error &rest types)
  5582. "Check if agenda buffer is of allowed type.
  5583. If ERROR is non-nil, throw an error, otherwise just return nil."
  5584. (if (memq org-agenda-type types)
  5585. t
  5586. (if error
  5587. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5588. nil)))
  5589. (defun org-agenda-quit ()
  5590. "Exit agenda by removing the window or the buffer."
  5591. (interactive)
  5592. (if org-agenda-columns-active
  5593. (org-columns-quit)
  5594. (let ((buf (current-buffer)))
  5595. (if (eq org-agenda-window-setup 'other-frame)
  5596. (progn
  5597. (kill-buffer buf)
  5598. (org-agenda-reset-markers)
  5599. (org-columns-remove-overlays)
  5600. (setq org-agenda-archives-mode nil)
  5601. (delete-frame))
  5602. (and (not (eq org-agenda-window-setup 'current-window))
  5603. (not (one-window-p))
  5604. (delete-window))
  5605. (kill-buffer buf)
  5606. (org-agenda-reset-markers)
  5607. (org-columns-remove-overlays)
  5608. (setq org-agenda-archives-mode nil)))
  5609. ;; Maybe restore the pre-agenda window configuration.
  5610. (and org-agenda-restore-windows-after-quit
  5611. (not (eq org-agenda-window-setup 'other-frame))
  5612. org-pre-agenda-window-conf
  5613. (set-window-configuration org-pre-agenda-window-conf))))
  5614. (defun org-agenda-exit ()
  5615. "Exit agenda by removing the window or the buffer.
  5616. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5617. Org-mode buffers visited directly by the user will not be touched."
  5618. (interactive)
  5619. (org-release-buffers org-agenda-new-buffers)
  5620. (setq org-agenda-new-buffers nil)
  5621. (org-agenda-quit))
  5622. (defun org-agenda-execute (arg)
  5623. "Execute another agenda command, keeping same window.
  5624. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5625. in the agenda."
  5626. (interactive "P")
  5627. (let ((org-agenda-window-setup 'current-window))
  5628. (org-agenda arg)))
  5629. (defun org-agenda-redo ()
  5630. "Rebuild Agenda.
  5631. When this is the global TODO list, a prefix argument will be interpreted."
  5632. (interactive)
  5633. (let* ((org-agenda-keep-modes t)
  5634. (filter org-agenda-filter)
  5635. (preset (get 'org-agenda-filter :preset-filter))
  5636. (org-agenda-filter-while-redo (or filter preset))
  5637. (cols org-agenda-columns-active)
  5638. (line (org-current-line))
  5639. (window-line (- line (org-current-line (window-start))))
  5640. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5641. (put 'org-agenda-filter :preset-filter nil)
  5642. (and cols (org-columns-quit))
  5643. (message "Rebuilding agenda buffer...")
  5644. (org-let lprops '(eval org-agenda-redo-command))
  5645. (setq org-agenda-undo-list nil
  5646. org-agenda-pending-undo-list nil)
  5647. (message "Rebuilding agenda buffer...done")
  5648. (put 'org-agenda-filter :preset-filter preset)
  5649. (and (or filter preset) (org-agenda-filter-apply filter))
  5650. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5651. (org-goto-line line)
  5652. (recenter window-line)))
  5653. (defvar org-global-tags-completion-table nil)
  5654. (defvar org-agenda-filter-form nil)
  5655. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5656. "Keep only those lines in the agenda buffer that have a specific tag.
  5657. The tag is selected with its fast selection letter, as configured.
  5658. With prefix argument STRIP, remove all lines that do have the tag.
  5659. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5660. used to narrow the search - the interactive user can also press `-' or `+'
  5661. to switch to narrowing."
  5662. (interactive "P")
  5663. (let* ((alist org-tag-alist-for-agenda)
  5664. (tag-chars (mapconcat
  5665. (lambda (x) (if (and (not (symbolp (car x)))
  5666. (cdr x))
  5667. (char-to-string (cdr x))
  5668. ""))
  5669. alist ""))
  5670. (efforts (org-split-string
  5671. (or (cdr (assoc (concat org-effort-property "_ALL")
  5672. org-global-properties))
  5673. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5674. "")))
  5675. (effort-op org-agenda-filter-effort-default-operator)
  5676. (effort-prompt "")
  5677. (inhibit-read-only t)
  5678. (current org-agenda-filter)
  5679. maybe-refresh a n tag)
  5680. (unless char
  5681. (message
  5682. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5683. (if narrow "Narrow" "Filter") tag-chars
  5684. (if org-agenda-auto-exclude-function "[RET], " ""))
  5685. (setq char (read-char)))
  5686. (when (member char '(?+ ?-))
  5687. ;; Narrowing down
  5688. (cond ((equal char ?-) (setq strip t narrow t))
  5689. ((equal char ?+) (setq strip nil narrow t)))
  5690. (message
  5691. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5692. (setq char (read-char)))
  5693. (when (member char '(?< ?> ?= ??))
  5694. ;; An effort operator
  5695. (setq effort-op (char-to-string char))
  5696. (setq alist nil) ; to make sure it will be interpreted as effort.
  5697. (unless (equal char ??)
  5698. (loop for i from 0 to 9 do
  5699. (setq effort-prompt
  5700. (concat
  5701. effort-prompt " ["
  5702. (if (= i 9) "0" (int-to-string (1+ i)))
  5703. "]" (nth i efforts))))
  5704. (message "Effort%s: %s " effort-op effort-prompt)
  5705. (setq char (read-char))
  5706. (when (or (< char ?0) (> char ?9))
  5707. (error "Need 1-9,0 to select effort" ))))
  5708. (when (equal char ?\t)
  5709. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5710. (org-set-local 'org-global-tags-completion-table
  5711. (org-global-tags-completion-table)))
  5712. (let ((completion-ignore-case t))
  5713. (setq tag (org-icompleting-read
  5714. "Tag: " org-global-tags-completion-table))))
  5715. (cond
  5716. ((equal char ?\r)
  5717. (org-agenda-filter-by-tag-show-all)
  5718. (when org-agenda-auto-exclude-function
  5719. (setq org-agenda-filter '())
  5720. (dolist (tag (org-agenda-get-represented-tags))
  5721. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5722. (if modifier
  5723. (push modifier org-agenda-filter))))
  5724. (if (not (null org-agenda-filter))
  5725. (org-agenda-filter-apply org-agenda-filter)))
  5726. (setq maybe-refresh t))
  5727. ((equal char ?/)
  5728. (org-agenda-filter-by-tag-show-all)
  5729. (when (get 'org-agenda-filter :preset-filter)
  5730. (org-agenda-filter-apply org-agenda-filter))
  5731. (setq maybe-refresh t))
  5732. ((or (equal char ?\ )
  5733. (setq a (rassoc char alist))
  5734. (and (>= char ?0) (<= char ?9)
  5735. (setq n (if (= char ?0) 9 (- char ?0 1))
  5736. tag (concat effort-op (nth n efforts))
  5737. a (cons tag nil)))
  5738. (and (= char ??)
  5739. (setq tag "?eff")
  5740. a (cons tag nil))
  5741. (and tag (setq a (cons tag nil))))
  5742. (org-agenda-filter-by-tag-show-all)
  5743. (setq tag (car a))
  5744. (setq org-agenda-filter
  5745. (cons (concat (if strip "-" "+") tag)
  5746. (if narrow current nil)))
  5747. (org-agenda-filter-apply org-agenda-filter)
  5748. (setq maybe-refresh t))
  5749. (t (error "Invalid tag selection character %c" char)))
  5750. (when (and maybe-refresh
  5751. (eq org-agenda-clockreport-mode 'with-filter))
  5752. (org-agenda-redo))))
  5753. (defun org-agenda-get-represented-tags ()
  5754. "Get a list of all tags currently represented in the agenda."
  5755. (let (p tags)
  5756. (save-excursion
  5757. (goto-char (point-min))
  5758. (while (setq p (next-single-property-change (point) 'tags))
  5759. (goto-char p)
  5760. (mapc (lambda (x) (add-to-list 'tags x))
  5761. (get-text-property (point) 'tags))))
  5762. tags))
  5763. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5764. "Refine the current filter. See `org-agenda-filter-by-tag."
  5765. (interactive "P")
  5766. (org-agenda-filter-by-tag strip char 'refine))
  5767. (defun org-agenda-filter-make-matcher ()
  5768. "Create the form that tests a line for the agenda filter."
  5769. (let (f f1)
  5770. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5771. org-agenda-filter))
  5772. (if (member x '("-" "+"))
  5773. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5774. (if (string-match "[<=>?]" x)
  5775. (setq f1 (org-agenda-filter-effort-form x))
  5776. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5777. (if (equal (string-to-char x) ?-)
  5778. (setq f1 (list 'not f1))))
  5779. (push f1 f))
  5780. (cons 'and (nreverse f))))
  5781. (defun org-agenda-filter-effort-form (e)
  5782. "Return the form to compare the effort of the current line with what E says.
  5783. E looks like \"+<2:25\"."
  5784. (let (op)
  5785. (setq e (substring e 1))
  5786. (setq op (string-to-char e) e (substring e 1))
  5787. (setq op (cond ((equal op ?<) '<=)
  5788. ((equal op ?>) '>=)
  5789. ((equal op ??) op)
  5790. (t '=)))
  5791. (list 'org-agenda-compare-effort (list 'quote op)
  5792. (org-duration-string-to-minutes e))))
  5793. (defun org-agenda-compare-effort (op value)
  5794. "Compare the effort of the current line with VALUE, using OP.
  5795. If the line does not have an effort defined, return nil."
  5796. (let ((eff (org-get-at-bol 'effort-minutes)))
  5797. (if (equal op ??)
  5798. (not eff)
  5799. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5800. value))))
  5801. (defun org-agenda-filter-apply (filter)
  5802. "Set FILTER as the new agenda filter and apply it."
  5803. (let (tags)
  5804. (setq org-agenda-filter filter
  5805. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5806. (org-agenda-set-mode-name)
  5807. (save-excursion
  5808. (goto-char (point-min))
  5809. (while (not (eobp))
  5810. (if (org-get-at-bol 'org-marker)
  5811. (progn
  5812. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5813. (if (not (eval org-agenda-filter-form))
  5814. (org-agenda-filter-by-tag-hide-line))
  5815. (beginning-of-line 2))
  5816. (beginning-of-line 2))))
  5817. (if (get-char-property (point) 'invisible)
  5818. (org-agenda-previous-line))))
  5819. (defun org-agenda-filter-by-tag-hide-line ()
  5820. (let (ov)
  5821. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5822. (point-at-eol)))
  5823. (overlay-put ov 'invisible t)
  5824. (overlay-put ov 'type 'tags-filter)
  5825. (push ov org-agenda-filter-overlays)))
  5826. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5827. (setq pos (or pos (point)))
  5828. (save-excursion
  5829. (dolist (ov (overlays-at pos))
  5830. (when (and (overlay-get ov 'invisible)
  5831. (eq (overlay-get ov 'type) 'tags-filter))
  5832. (goto-char pos)
  5833. (if (< (overlay-start ov) (point-at-eol))
  5834. (move-overlay ov (point-at-eol)
  5835. (overlay-end ov)))))))
  5836. (defun org-agenda-filter-by-tag-show-all ()
  5837. (mapc 'delete-overlay org-agenda-filter-overlays)
  5838. (setq org-agenda-filter-overlays nil)
  5839. (setq org-agenda-filter nil)
  5840. (setq org-agenda-filter-form nil)
  5841. (org-agenda-set-mode-name))
  5842. (defun org-agenda-manipulate-query-add ()
  5843. "Manipulate the query by adding a search term with positive selection.
  5844. Positive selection means the term must be matched for selection of an entry."
  5845. (interactive)
  5846. (org-agenda-manipulate-query ?\[))
  5847. (defun org-agenda-manipulate-query-subtract ()
  5848. "Manipulate the query by adding a search term with negative selection.
  5849. Negative selection means term must not be matched for selection of an entry."
  5850. (interactive)
  5851. (org-agenda-manipulate-query ?\]))
  5852. (defun org-agenda-manipulate-query-add-re ()
  5853. "Manipulate the query by adding a search regexp with positive selection.
  5854. Positive selection means the regexp must match for selection of an entry."
  5855. (interactive)
  5856. (org-agenda-manipulate-query ?\{))
  5857. (defun org-agenda-manipulate-query-subtract-re ()
  5858. "Manipulate the query by adding a search regexp with negative selection.
  5859. Negative selection means regexp must not match for selection of an entry."
  5860. (interactive)
  5861. (org-agenda-manipulate-query ?\}))
  5862. (defun org-agenda-manipulate-query (char)
  5863. (cond
  5864. ((memq org-agenda-type '(timeline agenda))
  5865. (let ((org-agenda-include-inactive-timestamps t))
  5866. (org-agenda-redo))
  5867. (message "Display now includes inactive timestamps as well"))
  5868. ((eq org-agenda-type 'search)
  5869. (org-add-to-string
  5870. 'org-agenda-query-string
  5871. (if org-agenda-last-search-view-search-was-boolean
  5872. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5873. (?\{ . " +{}") (?\} . " -{}"))))
  5874. " "))
  5875. (setq org-agenda-redo-command
  5876. (list 'org-search-view
  5877. org-todo-only
  5878. org-agenda-query-string
  5879. (+ (length org-agenda-query-string)
  5880. (if (member char '(?\{ ?\})) 0 1))))
  5881. (set-register org-agenda-query-register org-agenda-query-string)
  5882. (org-agenda-redo))
  5883. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5884. org-agenda-type))))
  5885. (defun org-add-to-string (var string)
  5886. (set var (concat (symbol-value var) string)))
  5887. (defun org-agenda-goto-date (date)
  5888. "Jump to DATE in agenda."
  5889. (interactive (list (let ((org-read-date-prefer-future
  5890. (eval org-agenda-jump-prefer-future)))
  5891. (org-read-date))))
  5892. (org-agenda-list nil date))
  5893. (defun org-agenda-goto-today ()
  5894. "Go to today."
  5895. (interactive)
  5896. (org-agenda-check-type t 'timeline 'agenda)
  5897. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5898. (cond
  5899. (tdpos (goto-char tdpos))
  5900. ((eq org-agenda-type 'agenda)
  5901. (let* ((sd (org-agenda-compute-starting-span
  5902. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5903. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5904. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5905. (org-agenda-redo)
  5906. (org-agenda-find-same-or-today-or-agenda)))
  5907. (t (error "Cannot find today")))))
  5908. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5909. (goto-char
  5910. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5911. (text-property-any (point-min) (point-max) 'org-today t)
  5912. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5913. (point-min))))
  5914. (defun org-agenda-later (arg)
  5915. "Go forward in time by thee current span.
  5916. With prefix ARG, go forward that many times the current span."
  5917. (interactive "p")
  5918. (org-agenda-check-type t 'agenda)
  5919. (let* ((span org-agenda-current-span)
  5920. (sd org-starting-day)
  5921. (greg (calendar-gregorian-from-absolute sd))
  5922. (cnt (org-get-at-bol 'org-day-cnt))
  5923. greg2)
  5924. (cond
  5925. ((eq span 'day)
  5926. (setq sd (+ arg sd)))
  5927. ((eq span 'week)
  5928. (setq sd (+ (* 7 arg) sd)))
  5929. ((eq span 'month)
  5930. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5931. sd (calendar-absolute-from-gregorian greg2))
  5932. (setcar greg2 (1+ (car greg2))))
  5933. ((eq span 'year)
  5934. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5935. sd (calendar-absolute-from-gregorian greg2))
  5936. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5937. (t
  5938. (setq sd (+ (* span arg) sd))))
  5939. (let ((org-agenda-overriding-arguments
  5940. (list (car org-agenda-last-arguments) sd span t)))
  5941. (org-agenda-redo)
  5942. (org-agenda-find-same-or-today-or-agenda cnt))))
  5943. (defun org-agenda-earlier (arg)
  5944. "Go backward in time by the current span.
  5945. With prefix ARG, go backward that many times the current span."
  5946. (interactive "p")
  5947. (org-agenda-later (- arg)))
  5948. (defun org-agenda-view-mode-dispatch ()
  5949. "Call one of the view mode commands."
  5950. (interactive)
  5951. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  5952. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  5953. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  5954. [E]ntryText")
  5955. (let ((a (read-char-exclusive)))
  5956. (case a
  5957. (?\ (call-interactively 'org-agenda-reset-view))
  5958. (?d (call-interactively 'org-agenda-day-view))
  5959. (?w (call-interactively 'org-agenda-week-view))
  5960. (?m (call-interactively 'org-agenda-month-view))
  5961. (?y (call-interactively 'org-agenda-year-view))
  5962. (?l (call-interactively 'org-agenda-log-mode))
  5963. (?L (org-agenda-log-mode '(4)))
  5964. (?c (org-agenda-log-mode 'clockcheck))
  5965. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5966. (?a (call-interactively 'org-agenda-archives-mode))
  5967. (?A (org-agenda-archives-mode 'files))
  5968. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5969. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5970. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5971. (?D (call-interactively 'org-agenda-toggle-diary))
  5972. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5973. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5974. (org-agenda-check-type t 'timeline 'agenda)
  5975. (org-agenda-redo))
  5976. (message "Display now includes inactive timestamps as well"))
  5977. (?q (message "Abort"))
  5978. (otherwise (error "Invalid key" )))))
  5979. (defun org-agenda-reset-view ()
  5980. "Switch to default view for agenda."
  5981. (interactive)
  5982. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  5983. (defun org-agenda-day-view (&optional day-of-year)
  5984. "Switch to daily view for agenda.
  5985. With argument DAY-OF-YEAR, switch to that day of the year."
  5986. (interactive "P")
  5987. (org-agenda-change-time-span 'day day-of-year))
  5988. (defun org-agenda-week-view (&optional iso-week)
  5989. "Switch to daily view for agenda.
  5990. With argument ISO-WEEK, switch to the corresponding ISO week.
  5991. If ISO-WEEK has more then 2 digits, only the last two encode the
  5992. week. Any digits before this encode a year. So 200712 means
  5993. week 12 of year 2007. Years in the range 1938-2037 can also be
  5994. written as 2-digit years."
  5995. (interactive "P")
  5996. (org-agenda-change-time-span 'week iso-week))
  5997. (defun org-agenda-month-view (&optional month)
  5998. "Switch to monthly view for agenda.
  5999. With argument MONTH, switch to that month."
  6000. (interactive "P")
  6001. (org-agenda-change-time-span 'month month))
  6002. (defun org-agenda-year-view (&optional year)
  6003. "Switch to yearly view for agenda.
  6004. With argument YEAR, switch to that year.
  6005. If MONTH has more then 2 digits, only the last two encode the
  6006. month. Any digits before this encode a year. So 200712 means
  6007. December year 2007. Years in the range 1938-2037 can also be
  6008. written as 2-digit years."
  6009. (interactive "P")
  6010. (when year
  6011. (setq year (org-small-year-to-year year)))
  6012. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6013. (org-agenda-change-time-span 'year year)
  6014. (error "Abort")))
  6015. (defun org-agenda-change-time-span (span &optional n)
  6016. "Change the agenda view to SPAN.
  6017. SPAN may be `day', `week', `month', `year'."
  6018. (org-agenda-check-type t 'agenda)
  6019. (if (and (not n) (equal org-agenda-current-span span))
  6020. (error "Viewing span is already \"%s\"" span))
  6021. (let* ((sd (or (org-get-at-bol 'day)
  6022. org-starting-day))
  6023. (sd (org-agenda-compute-starting-span sd span n))
  6024. (org-agenda-overriding-arguments
  6025. (or org-agenda-overriding-arguments
  6026. (list (car org-agenda-last-arguments) sd span t))))
  6027. (org-agenda-redo)
  6028. (org-agenda-find-same-or-today-or-agenda))
  6029. (org-agenda-set-mode-name)
  6030. (message "Switched to %s view" span))
  6031. (defun org-agenda-compute-starting-span (sd span &optional n)
  6032. "Compute starting date for agenda.
  6033. SPAN may be `day', `week', `month', `year'. The return value
  6034. is a cons cell with the starting date and the number of days,
  6035. so that the date SD will be in that range."
  6036. (let* ((greg (calendar-gregorian-from-absolute sd))
  6037. (dg (nth 1 greg))
  6038. (mg (car greg))
  6039. (yg (nth 2 greg)))
  6040. (cond
  6041. ((eq span 'day)
  6042. (when n
  6043. (setq sd (+ (calendar-absolute-from-gregorian
  6044. (list mg 1 yg))
  6045. n -1))))
  6046. ((eq span 'week)
  6047. (let* ((nt (calendar-day-of-week
  6048. (calendar-gregorian-from-absolute sd)))
  6049. (d (if org-agenda-start-on-weekday
  6050. (- nt org-agenda-start-on-weekday)
  6051. 0))
  6052. y1)
  6053. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6054. (when n
  6055. (require 'cal-iso)
  6056. (when (> n 99)
  6057. (setq y1 (org-small-year-to-year (/ n 100))
  6058. n (mod n 100)))
  6059. (setq sd
  6060. (calendar-absolute-from-iso
  6061. (list n 1
  6062. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6063. ((eq span 'month)
  6064. (let (y1)
  6065. (when (and n (> n 99))
  6066. (setq y1 (org-small-year-to-year (/ n 100))
  6067. n (mod n 100)))
  6068. (setq sd (calendar-absolute-from-gregorian
  6069. (list (or n mg) 1 (or y1 yg))))))
  6070. ((eq span 'year)
  6071. (setq sd (calendar-absolute-from-gregorian
  6072. (list 1 1 (or n yg))))))
  6073. sd))
  6074. (defun org-agenda-next-date-line (&optional arg)
  6075. "Jump to the next line indicating a date in agenda buffer."
  6076. (interactive "p")
  6077. (org-agenda-check-type t 'agenda 'timeline)
  6078. (beginning-of-line 1)
  6079. ;; This does not work if user makes date format that starts with a blank
  6080. (if (looking-at "^\\S-") (forward-char 1))
  6081. (if (not (re-search-forward "^\\S-" nil t arg))
  6082. (progn
  6083. (backward-char 1)
  6084. (error "No next date after this line in this buffer")))
  6085. (goto-char (match-beginning 0)))
  6086. (defun org-agenda-previous-date-line (&optional arg)
  6087. "Jump to the previous line indicating a date in agenda buffer."
  6088. (interactive "p")
  6089. (org-agenda-check-type t 'agenda 'timeline)
  6090. (beginning-of-line 1)
  6091. (if (not (re-search-backward "^\\S-" nil t arg))
  6092. (error "No previous date before this line in this buffer")))
  6093. ;; Initialize the highlight
  6094. (defvar org-hl (make-overlay 1 1))
  6095. (overlay-put org-hl 'face 'highlight)
  6096. (defun org-highlight (begin end &optional buffer)
  6097. "Highlight a region with overlay."
  6098. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6099. (defun org-unhighlight ()
  6100. "Detach overlay INDEX."
  6101. (org-detach-overlay org-hl))
  6102. ;; FIXME this is currently not used.
  6103. (defun org-highlight-until-next-command (beg end &optional buffer)
  6104. "Move the highlight overlay to BEG/END, remove it before the next command."
  6105. (org-highlight beg end buffer)
  6106. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6107. (defun org-unhighlight-once ()
  6108. "Remove the highlight from its position, and this function from the hook."
  6109. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6110. (org-unhighlight))
  6111. (defun org-agenda-follow-mode ()
  6112. "Toggle follow mode in an agenda buffer."
  6113. (interactive)
  6114. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6115. (org-agenda-set-mode-name)
  6116. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  6117. (org-agenda-show))
  6118. (message "Follow mode is %s"
  6119. (if org-agenda-follow-mode "on" "off")))
  6120. (defun org-agenda-entry-text-mode (&optional arg)
  6121. "Toggle entry text mode in an agenda buffer."
  6122. (interactive "P")
  6123. (setq org-agenda-entry-text-mode (or (integerp arg)
  6124. (not org-agenda-entry-text-mode)))
  6125. (org-agenda-entry-text-hide)
  6126. (and org-agenda-entry-text-mode
  6127. (let ((org-agenda-entry-text-maxlines
  6128. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6129. (org-agenda-entry-text-show)))
  6130. (org-agenda-set-mode-name)
  6131. (message "Entry text mode is %s. Maximum number of lines is %d"
  6132. (if org-agenda-entry-text-mode "on" "off")
  6133. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6134. (defun org-agenda-clockreport-mode (&optional with-filter)
  6135. "Toggle clocktable mode in an agenda buffer.
  6136. With prefix arg WITH-FILTER, make the clocktable respect the current
  6137. agenda filter."
  6138. (interactive "P")
  6139. (org-agenda-check-type t 'agenda)
  6140. (if with-filter
  6141. (setq org-agenda-clockreport-mode 'with-filter)
  6142. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6143. (org-agenda-set-mode-name)
  6144. (org-agenda-redo)
  6145. (message "Clocktable mode is %s"
  6146. (if org-agenda-clockreport-mode "on" "off")))
  6147. (defun org-agenda-log-mode (&optional special)
  6148. "Toggle log mode in an agenda buffer.
  6149. With argument SPECIAL, show all possible log items, not only the ones
  6150. configured in `org-agenda-log-mode-items'.
  6151. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6152. (interactive "P")
  6153. (org-agenda-check-type t 'agenda 'timeline)
  6154. (setq org-agenda-show-log
  6155. (cond
  6156. ((equal special '(16)) 'only)
  6157. ((eq special 'clockcheck)
  6158. (if (eq org-agenda-show-log 'clockcheck)
  6159. nil 'clockcheck))
  6160. (special '(closed clock state))
  6161. (t (not org-agenda-show-log))))
  6162. (org-agenda-set-mode-name)
  6163. (org-agenda-redo)
  6164. (message "Log mode is %s"
  6165. (if org-agenda-show-log "on" "off")))
  6166. (defun org-agenda-archives-mode (&optional with-files)
  6167. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6168. When called with a prefix argument, include all archive files as well."
  6169. (interactive "P")
  6170. (setq org-agenda-archives-mode
  6171. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6172. (org-agenda-set-mode-name)
  6173. (org-agenda-redo)
  6174. (message
  6175. "%s"
  6176. (cond
  6177. ((eq org-agenda-archives-mode nil)
  6178. "No archives are included")
  6179. ((eq org-agenda-archives-mode 'trees)
  6180. (format "Trees with :%s: tag are included" org-archive-tag))
  6181. ((eq org-agenda-archives-mode t)
  6182. (format "Trees with :%s: tag and all active archive files are included"
  6183. org-archive-tag)))))
  6184. (defun org-agenda-toggle-diary ()
  6185. "Toggle diary inclusion in an agenda buffer."
  6186. (interactive)
  6187. (org-agenda-check-type t 'agenda)
  6188. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6189. (org-agenda-redo)
  6190. (org-agenda-set-mode-name)
  6191. (message "Diary inclusion turned %s"
  6192. (if org-agenda-include-diary "on" "off")))
  6193. (defun org-agenda-toggle-deadlines ()
  6194. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6195. (interactive)
  6196. (org-agenda-check-type t 'agenda)
  6197. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6198. (org-agenda-redo)
  6199. (org-agenda-set-mode-name)
  6200. (message "Deadlines inclusion turned %s"
  6201. (if org-agenda-include-deadlines "on" "off")))
  6202. (defun org-agenda-toggle-time-grid ()
  6203. "Toggle time grid in an agenda buffer."
  6204. (interactive)
  6205. (org-agenda-check-type t 'agenda)
  6206. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6207. (org-agenda-redo)
  6208. (org-agenda-set-mode-name)
  6209. (message "Time-grid turned %s"
  6210. (if org-agenda-use-time-grid "on" "off")))
  6211. (defun org-agenda-set-mode-name ()
  6212. "Set the mode name to indicate all the small mode settings."
  6213. (setq mode-name
  6214. (list "Org-Agenda"
  6215. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6216. " "
  6217. '(:eval (org-agenda-span-name org-agenda-current-span))
  6218. (if org-agenda-follow-mode " Follow" "")
  6219. (if org-agenda-entry-text-mode " ETxt" "")
  6220. (if org-agenda-include-diary " Diary" "")
  6221. (if org-agenda-include-deadlines " Ddl" "")
  6222. (if org-agenda-use-time-grid " Grid" "")
  6223. (if (and (boundp 'org-habit-show-habits)
  6224. org-habit-show-habits) " Habit" "")
  6225. (cond
  6226. ((consp org-agenda-show-log) " LogAll")
  6227. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6228. (org-agenda-show-log " Log")
  6229. (t ""))
  6230. (if (or org-agenda-filter (get 'org-agenda-filter
  6231. :preset-filter))
  6232. (concat " {" (mapconcat
  6233. 'identity
  6234. (append (get 'org-agenda-filter
  6235. :preset-filter)
  6236. org-agenda-filter) "") "}")
  6237. "")
  6238. (if org-agenda-archives-mode
  6239. (if (eq org-agenda-archives-mode t)
  6240. " Archives"
  6241. (format " :%s:" org-archive-tag))
  6242. "")
  6243. (if org-agenda-clockreport-mode
  6244. (if (eq org-agenda-clockreport-mode 'with-filter)
  6245. " Clock{}" " Clock")
  6246. "")))
  6247. (force-mode-line-update))
  6248. (defun org-agenda-post-command-hook ()
  6249. (setq org-agenda-type
  6250. (or (get-text-property (point) 'org-agenda-type)
  6251. (get-text-property (max (point-min) (1- (point)))
  6252. 'org-agenda-type))))
  6253. (defun org-agenda-next-line ()
  6254. "Move cursor to the next line, and show if follow mode is active."
  6255. (interactive)
  6256. (call-interactively 'next-line)
  6257. (org-agenda-do-context-action))
  6258. (defun org-agenda-previous-line ()
  6259. "Move cursor to the previous line, and show if follow-mode is active."
  6260. (interactive)
  6261. (call-interactively 'previous-line)
  6262. (org-agenda-do-context-action))
  6263. (defun org-agenda-do-context-action ()
  6264. "Show outline path and, maybe, follow mode window."
  6265. (let ((m (org-get-at-bol 'org-marker)))
  6266. (if (and org-agenda-follow-mode m)
  6267. (org-agenda-show))
  6268. (if (and m org-agenda-show-outline-path)
  6269. (org-with-point-at m
  6270. (org-display-outline-path t)))))
  6271. (defun org-agenda-show-priority ()
  6272. "Show the priority of the current item.
  6273. This priority is composed of the main priority given with the [#A] cookies,
  6274. and by additional input from the age of a schedules or deadline entry."
  6275. (interactive)
  6276. (let* ((pri (org-get-at-bol 'priority)))
  6277. (message "Priority is %d" (if pri pri -1000))))
  6278. (defun org-agenda-show-tags ()
  6279. "Show the tags applicable to the current item."
  6280. (interactive)
  6281. (let* ((tags (org-get-at-bol 'tags)))
  6282. (if tags
  6283. (message "Tags are :%s:"
  6284. (org-no-properties (mapconcat 'identity tags ":")))
  6285. (message "No tags associated with this line"))))
  6286. (defun org-agenda-goto (&optional highlight)
  6287. "Go to the Org-mode file which contains the item at point."
  6288. (interactive)
  6289. (let* ((marker (or (org-get-at-bol 'org-marker)
  6290. (org-agenda-error)))
  6291. (buffer (marker-buffer marker))
  6292. (pos (marker-position marker)))
  6293. (switch-to-buffer-other-window buffer)
  6294. (widen)
  6295. (push-mark)
  6296. (goto-char pos)
  6297. (when (org-mode-p)
  6298. (org-show-context 'agenda)
  6299. (save-excursion
  6300. (and (outline-next-heading)
  6301. (org-flag-heading nil)))) ; show the next heading
  6302. (when (outline-invisible-p)
  6303. (show-entry)) ; display invisible text
  6304. (recenter (/ (window-height) 2))
  6305. (run-hooks 'org-agenda-after-show-hook)
  6306. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6307. (defvar org-agenda-after-show-hook nil
  6308. "Normal hook run after an item has been shown from the agenda.
  6309. Point is in the buffer where the item originated.")
  6310. (defun org-agenda-kill ()
  6311. "Kill the entry or subtree belonging to the current agenda entry."
  6312. (interactive)
  6313. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  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. (type (org-get-at-bol 'type))
  6319. dbeg dend (n 0) conf)
  6320. (org-with-remote-undo buffer
  6321. (with-current-buffer buffer
  6322. (save-excursion
  6323. (goto-char pos)
  6324. (if (and (org-mode-p) (not (member type '("sexp"))))
  6325. (setq dbeg (progn (org-back-to-heading t) (point))
  6326. dend (org-end-of-subtree t t))
  6327. (setq dbeg (point-at-bol)
  6328. dend (min (point-max) (1+ (point-at-eol)))))
  6329. (goto-char dbeg)
  6330. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6331. (setq conf (or (eq t org-agenda-confirm-kill)
  6332. (and (numberp org-agenda-confirm-kill)
  6333. (> n org-agenda-confirm-kill))))
  6334. (and conf
  6335. (not (y-or-n-p
  6336. (format "Delete entry with %d lines in buffer \"%s\"? "
  6337. n (buffer-name buffer))))
  6338. (error "Abort"))
  6339. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6340. (with-current-buffer buffer (delete-region dbeg dend))
  6341. (message "Agenda item and source killed"))))
  6342. (defvar org-archive-default-command)
  6343. (defun org-agenda-archive-default ()
  6344. "Archive the entry or subtree belonging to the current agenda entry."
  6345. (interactive)
  6346. (require 'org-archive)
  6347. (org-agenda-archive-with org-archive-default-command))
  6348. (defun org-agenda-archive-default-with-confirmation ()
  6349. "Archive the entry or subtree belonging to the current agenda entry."
  6350. (interactive)
  6351. (require 'org-archive)
  6352. (org-agenda-archive-with org-archive-default-command 'confirm))
  6353. (defun org-agenda-archive ()
  6354. "Archive the entry or subtree belonging to the current agenda entry."
  6355. (interactive)
  6356. (org-agenda-archive-with 'org-archive-subtree))
  6357. (defun org-agenda-archive-to-archive-sibling ()
  6358. "Move the entry to the archive sibling."
  6359. (interactive)
  6360. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6361. (defun org-agenda-archive-with (cmd &optional confirm)
  6362. "Move the entry to the archive sibling."
  6363. (interactive)
  6364. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6365. (let* ((marker (or (org-get-at-bol 'org-marker)
  6366. (org-agenda-error)))
  6367. (buffer (marker-buffer marker))
  6368. (pos (marker-position marker)))
  6369. (org-with-remote-undo buffer
  6370. (with-current-buffer buffer
  6371. (if (org-mode-p)
  6372. (if (and confirm
  6373. (not (y-or-n-p "Archive this subtree or entry? ")))
  6374. (error "Abort")
  6375. (save-excursion
  6376. (goto-char pos)
  6377. (org-remove-subtree-entries-from-agenda)
  6378. (org-back-to-heading t)
  6379. (funcall cmd)))
  6380. (error "Archiving works only in Org-mode files"))))))
  6381. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6382. "Remove all lines in the agenda that correspond to a given subtree.
  6383. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6384. If this information is not given, the function uses the tree at point."
  6385. (let ((buf (or buf (current-buffer))) m p)
  6386. (save-excursion
  6387. (unless (and beg end)
  6388. (org-back-to-heading t)
  6389. (setq beg (point))
  6390. (org-end-of-subtree t)
  6391. (setq end (point)))
  6392. (set-buffer (get-buffer org-agenda-buffer-name))
  6393. (save-excursion
  6394. (goto-char (point-max))
  6395. (beginning-of-line 1)
  6396. (while (not (bobp))
  6397. (when (and (setq m (org-get-at-bol 'org-marker))
  6398. (equal buf (marker-buffer m))
  6399. (setq p (marker-position m))
  6400. (>= p beg)
  6401. (< p end))
  6402. (let ((inhibit-read-only t))
  6403. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6404. (beginning-of-line 0))))))
  6405. (defun org-agenda-refile (&optional goto rfloc no-update)
  6406. "Refile the item at point."
  6407. (interactive "P")
  6408. (if (equal goto '(16))
  6409. (org-refile-goto-last-stored)
  6410. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6411. (org-agenda-error)))
  6412. (buffer (marker-buffer marker))
  6413. (pos (marker-position marker))
  6414. (rfloc (or rfloc
  6415. (org-refile-get-location
  6416. (if goto "Goto" "Refile to") buffer
  6417. org-refile-allow-creating-parent-nodes))))
  6418. (with-current-buffer buffer
  6419. (save-excursion
  6420. (save-restriction
  6421. (widen)
  6422. (goto-char marker)
  6423. (org-remove-subtree-entries-from-agenda)
  6424. (org-refile goto buffer rfloc)))))
  6425. (unless no-update (org-agenda-redo))))
  6426. (defun org-agenda-open-link (&optional arg)
  6427. "Follow the link in the current line, if any.
  6428. This looks for a link in the displayed line in the agenda. It also looks
  6429. at the text of the entry itself."
  6430. (interactive "P")
  6431. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6432. (org-get-at-bol 'org-marker)))
  6433. (buffer (and marker (marker-buffer marker)))
  6434. (prefix (buffer-substring
  6435. (point-at-bol) (point-at-eol))))
  6436. (cond
  6437. (buffer
  6438. (with-current-buffer buffer
  6439. (save-excursion
  6440. (save-restriction
  6441. (widen)
  6442. (goto-char marker)
  6443. (org-offer-links-in-entry arg prefix)))))
  6444. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6445. (save-excursion
  6446. (beginning-of-line 1)
  6447. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6448. (org-open-link-from-string (match-string 1)))
  6449. (t (error "No link to open here")))))
  6450. (defun org-agenda-copy-local-variable (var)
  6451. "Get a variable from a referenced buffer and install it here."
  6452. (let ((m (org-get-at-bol 'org-marker)))
  6453. (when (and m (buffer-live-p (marker-buffer m)))
  6454. (org-set-local var (with-current-buffer (marker-buffer m)
  6455. (symbol-value var))))))
  6456. (defun org-agenda-switch-to (&optional delete-other-windows)
  6457. "Go to the Org-mode file which contains the item at point."
  6458. (interactive)
  6459. (if (and org-return-follows-link
  6460. (not (org-get-at-bol 'org-marker))
  6461. (org-in-regexp org-bracket-link-regexp))
  6462. (org-open-link-from-string (match-string 0))
  6463. (let* ((marker (or (org-get-at-bol 'org-marker)
  6464. (org-agenda-error)))
  6465. (buffer (marker-buffer marker))
  6466. (pos (marker-position marker)))
  6467. (switch-to-buffer buffer)
  6468. (and delete-other-windows (delete-other-windows))
  6469. (widen)
  6470. (goto-char pos)
  6471. (when (org-mode-p)
  6472. (org-show-context 'agenda)
  6473. (save-excursion
  6474. (and (outline-next-heading)
  6475. (org-flag-heading nil))) ; show the next heading
  6476. (when (outline-invisible-p)
  6477. (show-entry)))))) ; display invisible text
  6478. (defun org-agenda-goto-mouse (ev)
  6479. "Go to the Org-mode file which contains the item at the mouse click."
  6480. (interactive "e")
  6481. (mouse-set-point ev)
  6482. (org-agenda-goto))
  6483. (defun org-agenda-show (&optional full-entry)
  6484. "Display the Org-mode file which contains the item at point.
  6485. With prefix argument FULL-ENTRY, make the entire entry visible
  6486. if it was hidden in the outline."
  6487. (interactive "P")
  6488. (let ((win (selected-window)))
  6489. (if full-entry
  6490. (let ((org-show-entry-below t))
  6491. (org-agenda-goto t))
  6492. (org-agenda-goto t))
  6493. (select-window win)))
  6494. (defvar org-agenda-show-window nil)
  6495. (defun org-agenda-show-and-scroll-up ()
  6496. "Display the Org-mode file which contains the item at point.
  6497. When called repeatedly, scroll the window that is displaying the buffer."
  6498. (interactive)
  6499. (let ((win (selected-window)))
  6500. (if (and (window-live-p org-agenda-show-window)
  6501. (eq this-command last-command))
  6502. (progn
  6503. (select-window org-agenda-show-window)
  6504. (ignore-errors (scroll-up)))
  6505. (org-agenda-goto t)
  6506. (show-subtree)
  6507. (setq org-agenda-show-window (selected-window)))
  6508. (select-window win)))
  6509. (defun org-agenda-show-scroll-down ()
  6510. "Scroll down the window showing the agenda."
  6511. (interactive)
  6512. (let ((win (selected-window)))
  6513. (when (window-live-p org-agenda-show-window)
  6514. (select-window org-agenda-show-window)
  6515. (ignore-errors (scroll-down))
  6516. (select-window win))))
  6517. (defun org-agenda-show-1 (&optional more)
  6518. "Display the Org-mode file which contains the item at point.
  6519. The prefix arg selects the amount of information to display:
  6520. 0 hide the subtree
  6521. 1 just show the entry according to defaults.
  6522. 2 show the children view
  6523. 3 show the subtree view
  6524. 4 show the entire subtree and any LOGBOOK drawers
  6525. 5 show the entire subtree and any drawers
  6526. With prefix argument FULL-ENTRY, make the entire entry visible
  6527. if it was hidden in the outline."
  6528. (interactive "p")
  6529. (let ((win (selected-window)))
  6530. (org-agenda-goto t)
  6531. (org-recenter-heading 1)
  6532. (cond
  6533. ((= more 0)
  6534. (hide-subtree)
  6535. (save-excursion
  6536. (org-back-to-heading)
  6537. (run-hook-with-args 'org-cycle-hook 'folded))
  6538. (message "Remote: FOLDED"))
  6539. ((and (org-called-interactively-p 'any) (= more 1))
  6540. (message "Remote: show with default settings"))
  6541. ((= more 2)
  6542. (show-entry)
  6543. (show-children)
  6544. (save-excursion
  6545. (org-back-to-heading)
  6546. (run-hook-with-args 'org-cycle-hook 'children))
  6547. (message "Remote: CHILDREN"))
  6548. ((= more 3)
  6549. (show-subtree)
  6550. (save-excursion
  6551. (org-back-to-heading)
  6552. (run-hook-with-args 'org-cycle-hook 'subtree))
  6553. (message "Remote: SUBTREE"))
  6554. ((= more 4)
  6555. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6556. (org-drawer-regexp
  6557. (concat "^[ \t]*:\\("
  6558. (mapconcat 'regexp-quote org-drawers "\\|")
  6559. "\\):[ \t]*$")))
  6560. (show-subtree)
  6561. (save-excursion
  6562. (org-back-to-heading)
  6563. (org-cycle-hide-drawers 'subtree)))
  6564. (message "Remote: SUBTREE AND LOGBOOK"))
  6565. ((> more 4)
  6566. (show-subtree)
  6567. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6568. (select-window win)))
  6569. (defun org-recenter-heading (n)
  6570. (save-excursion
  6571. (org-back-to-heading)
  6572. (recenter n)))
  6573. (defvar org-agenda-cycle-counter nil)
  6574. (defun org-agenda-cycle-show (&optional n)
  6575. "Show the current entry in another window, with default settings.
  6576. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6577. When use repeatedly in immediate succession, the remote entry will cycle
  6578. through visibility
  6579. children -> subtree -> folded
  6580. When called with a numeric prefix arg, that arg will be passed through to
  6581. `org-agenda-show-1'. For the interpretation of that argument, see the
  6582. docstring of `org-agenda-show-1'."
  6583. (interactive "P")
  6584. (if (integerp n)
  6585. (setq org-agenda-cycle-counter n)
  6586. (if (not (eq last-command this-command))
  6587. (setq org-agenda-cycle-counter 1)
  6588. (if (equal org-agenda-cycle-counter 0)
  6589. (setq org-agenda-cycle-counter 2)
  6590. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6591. (if (> org-agenda-cycle-counter 3)
  6592. (setq org-agenda-cycle-counter 0)))))
  6593. (org-agenda-show-1 org-agenda-cycle-counter))
  6594. (defun org-agenda-recenter (arg)
  6595. "Display the Org-mode file which contains the item at point and recenter."
  6596. (interactive "P")
  6597. (let ((win (selected-window)))
  6598. (org-agenda-goto t)
  6599. (recenter arg)
  6600. (select-window win)))
  6601. (defun org-agenda-show-mouse (ev)
  6602. "Display the Org-mode file which contains the item at the mouse click."
  6603. (interactive "e")
  6604. (mouse-set-point ev)
  6605. (org-agenda-show))
  6606. (defun org-agenda-check-no-diary ()
  6607. "Check if the entry is a diary link and abort if yes."
  6608. (if (org-get-at-bol 'org-agenda-diary-link)
  6609. (org-agenda-error)))
  6610. (defun org-agenda-error ()
  6611. (error "Command not allowed in this line"))
  6612. (defun org-agenda-tree-to-indirect-buffer ()
  6613. "Show the subtree corresponding to the current entry in an indirect buffer.
  6614. This calls the command `org-tree-to-indirect-buffer' from the original
  6615. Org-mode buffer.
  6616. With numerical prefix arg ARG, go up to this level and then take that tree.
  6617. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6618. use the dedicated frame)."
  6619. (interactive)
  6620. (org-agenda-check-no-diary)
  6621. (let* ((marker (or (org-get-at-bol 'org-marker)
  6622. (org-agenda-error)))
  6623. (buffer (marker-buffer marker))
  6624. (pos (marker-position marker)))
  6625. (with-current-buffer buffer
  6626. (save-excursion
  6627. (goto-char pos)
  6628. (call-interactively 'org-tree-to-indirect-buffer)))))
  6629. (defvar org-last-heading-marker (make-marker)
  6630. "Marker pointing to the headline that last changed its TODO state
  6631. by a remote command from the agenda.")
  6632. (defun org-agenda-todo-nextset ()
  6633. "Switch TODO entry to next sequence."
  6634. (interactive)
  6635. (org-agenda-todo 'nextset))
  6636. (defun org-agenda-todo-previousset ()
  6637. "Switch TODO entry to previous sequence."
  6638. (interactive)
  6639. (org-agenda-todo 'previousset))
  6640. (defun org-agenda-todo (&optional arg)
  6641. "Cycle TODO state of line at point, also in Org-mode file.
  6642. This changes the line at point, all other lines in the agenda referring to
  6643. the same tree node, and the headline of the tree node in the Org-mode file."
  6644. (interactive "P")
  6645. (org-agenda-check-no-diary)
  6646. (let* ((col (current-column))
  6647. (marker (or (org-get-at-bol 'org-marker)
  6648. (org-agenda-error)))
  6649. (buffer (marker-buffer marker))
  6650. (pos (marker-position marker))
  6651. (hdmarker (org-get-at-bol 'org-hd-marker))
  6652. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6653. (inhibit-read-only t)
  6654. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6655. (org-with-remote-undo buffer
  6656. (with-current-buffer buffer
  6657. (widen)
  6658. (goto-char pos)
  6659. (org-show-context 'agenda)
  6660. (save-excursion
  6661. (and (outline-next-heading)
  6662. (org-flag-heading nil))) ; show the next heading
  6663. (let ((current-prefix-arg arg))
  6664. (call-interactively 'org-todo))
  6665. (and (bolp) (forward-char 1))
  6666. (setq newhead (org-get-heading))
  6667. (when (and (org-bound-and-true-p
  6668. org-agenda-headline-snapshot-before-repeat)
  6669. (not (equal org-agenda-headline-snapshot-before-repeat
  6670. newhead))
  6671. todayp)
  6672. (setq newhead org-agenda-headline-snapshot-before-repeat
  6673. just-one t))
  6674. (save-excursion
  6675. (org-back-to-heading)
  6676. (move-marker org-last-heading-marker (point))))
  6677. (beginning-of-line 1)
  6678. (save-excursion
  6679. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6680. (org-move-to-column col))))
  6681. (defun org-agenda-add-note (&optional arg)
  6682. "Add a time-stamped note to the entry at point."
  6683. (interactive "P")
  6684. (org-agenda-check-no-diary)
  6685. (let* ((marker (or (org-get-at-bol 'org-marker)
  6686. (org-agenda-error)))
  6687. (buffer (marker-buffer marker))
  6688. (pos (marker-position marker))
  6689. (hdmarker (org-get-at-bol 'org-hd-marker))
  6690. (inhibit-read-only t))
  6691. (with-current-buffer buffer
  6692. (widen)
  6693. (goto-char pos)
  6694. (org-show-context 'agenda)
  6695. (save-excursion
  6696. (and (outline-next-heading)
  6697. (org-flag-heading nil))) ; show the next heading
  6698. (org-add-note))))
  6699. (defun org-agenda-change-all-lines (newhead hdmarker
  6700. &optional fixface just-this)
  6701. "Change all lines in the agenda buffer which match HDMARKER.
  6702. The new content of the line will be NEWHEAD (as modified by
  6703. `org-format-agenda-item'). HDMARKER is checked with
  6704. `equal' against all `org-hd-marker' text properties in the file.
  6705. If FIXFACE is non-nil, the face of each item is modified according to
  6706. the new TODO state.
  6707. If JUST-THIS is non-nil, change just the current line, not all.
  6708. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6709. (let* ((inhibit-read-only t)
  6710. (line (org-current-line))
  6711. (thetags (with-current-buffer (marker-buffer hdmarker)
  6712. (save-excursion (save-restriction (widen)
  6713. (goto-char hdmarker)
  6714. (org-get-tags-at)))))
  6715. props m pl undone-face done-face finish new dotime cat tags)
  6716. (save-excursion
  6717. (goto-char (point-max))
  6718. (beginning-of-line 1)
  6719. (while (not finish)
  6720. (setq finish (bobp))
  6721. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6722. (or (not just-this) (= (org-current-line) line))
  6723. (equal m hdmarker))
  6724. (setq props (text-properties-at (point))
  6725. dotime (org-get-at-bol 'dotime)
  6726. cat (org-get-at-bol 'org-category)
  6727. tags thetags
  6728. new (org-format-agenda-item (org-get-at-bol 'extra)
  6729. newhead cat tags dotime)
  6730. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6731. undone-face (org-get-at-bol 'undone-face)
  6732. done-face (org-get-at-bol 'done-face))
  6733. (beginning-of-line 1)
  6734. (cond
  6735. ((equal new "")
  6736. (and (looking-at ".*\n?") (replace-match "")))
  6737. ((looking-at ".*")
  6738. (replace-match new t t)
  6739. (beginning-of-line 1)
  6740. (add-text-properties (point-at-bol) (point-at-eol) props)
  6741. (when fixface
  6742. (add-text-properties
  6743. (point-at-bol) (point-at-eol)
  6744. (list 'face
  6745. (if org-last-todo-state-is-todo
  6746. undone-face done-face))))
  6747. (org-agenda-highlight-todo 'line)
  6748. (beginning-of-line 1))
  6749. (t (error "Line update did not work"))))
  6750. (beginning-of-line 0)))
  6751. (org-finalize-agenda)))
  6752. (defun org-agenda-align-tags (&optional line)
  6753. "Align all tags in agenda items to `org-agenda-tags-column'."
  6754. (let ((inhibit-read-only t) l c)
  6755. (save-excursion
  6756. (goto-char (if line (point-at-bol) (point-min)))
  6757. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6758. (if line (point-at-eol) nil) t)
  6759. (add-text-properties
  6760. (match-beginning 2) (match-end 2)
  6761. (list 'face (delq nil (let ((prop (get-text-property
  6762. (match-beginning 2) 'face)))
  6763. (or (listp prop) (setq prop (list prop)))
  6764. (if (memq 'org-tag prop)
  6765. prop
  6766. (cons 'org-tag prop))))))
  6767. (setq l (- (match-end 2) (match-beginning 2))
  6768. c (if (< org-agenda-tags-column 0)
  6769. (- (abs org-agenda-tags-column) l)
  6770. org-agenda-tags-column))
  6771. (delete-region (match-beginning 1) (match-end 1))
  6772. (goto-char (match-beginning 1))
  6773. (insert (org-add-props
  6774. (make-string (max 1 (- c (current-column))) ?\ )
  6775. (plist-put (copy-sequence (text-properties-at (point)))
  6776. 'face nil))))
  6777. (goto-char (point-min))
  6778. (org-font-lock-add-tag-faces (point-max)))))
  6779. (defun org-agenda-priority-up ()
  6780. "Increase the priority of line at point, also in Org-mode file."
  6781. (interactive)
  6782. (org-agenda-priority 'up))
  6783. (defun org-agenda-priority-down ()
  6784. "Decrease the priority of line at point, also in Org-mode file."
  6785. (interactive)
  6786. (org-agenda-priority 'down))
  6787. (defun org-agenda-priority (&optional force-direction)
  6788. "Set the priority of line at point, also in Org-mode file.
  6789. This changes the line at point, all other lines in the agenda referring to
  6790. the same tree node, and the headline of the tree node in the Org-mode file."
  6791. (interactive)
  6792. (unless org-enable-priority-commands
  6793. (error "Priority commands are disabled"))
  6794. (org-agenda-check-no-diary)
  6795. (let* ((marker (or (org-get-at-bol 'org-marker)
  6796. (org-agenda-error)))
  6797. (hdmarker (org-get-at-bol 'org-hd-marker))
  6798. (buffer (marker-buffer hdmarker))
  6799. (pos (marker-position hdmarker))
  6800. (inhibit-read-only t)
  6801. newhead)
  6802. (org-with-remote-undo buffer
  6803. (with-current-buffer buffer
  6804. (widen)
  6805. (goto-char pos)
  6806. (org-show-context 'agenda)
  6807. (save-excursion
  6808. (and (outline-next-heading)
  6809. (org-flag-heading nil))) ; show the next heading
  6810. (funcall 'org-priority force-direction)
  6811. (end-of-line 1)
  6812. (setq newhead (org-get-heading)))
  6813. (org-agenda-change-all-lines newhead hdmarker)
  6814. (beginning-of-line 1))))
  6815. ;; FIXME: should fix the tags property of the agenda line.
  6816. (defun org-agenda-set-tags (&optional tag onoff)
  6817. "Set tags for the current headline."
  6818. (interactive)
  6819. (org-agenda-check-no-diary)
  6820. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6821. (call-interactively 'org-change-tag-in-region)
  6822. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6823. (org-agenda-error)))
  6824. (buffer (marker-buffer hdmarker))
  6825. (pos (marker-position hdmarker))
  6826. (inhibit-read-only t)
  6827. newhead)
  6828. (org-with-remote-undo buffer
  6829. (with-current-buffer buffer
  6830. (widen)
  6831. (goto-char pos)
  6832. (save-excursion
  6833. (org-show-context 'agenda))
  6834. (save-excursion
  6835. (and (outline-next-heading)
  6836. (org-flag-heading nil))) ; show the next heading
  6837. (goto-char pos)
  6838. (if tag
  6839. (org-toggle-tag tag onoff)
  6840. (call-interactively 'org-set-tags))
  6841. (end-of-line 1)
  6842. (setq newhead (org-get-heading)))
  6843. (org-agenda-change-all-lines newhead hdmarker)
  6844. (beginning-of-line 1)))))
  6845. (defun org-agenda-set-property ()
  6846. "Set a property for the current headline."
  6847. (interactive)
  6848. (org-agenda-check-no-diary)
  6849. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6850. (org-agenda-error)))
  6851. (buffer (marker-buffer hdmarker))
  6852. (pos (marker-position hdmarker))
  6853. (inhibit-read-only t)
  6854. newhead)
  6855. (org-with-remote-undo buffer
  6856. (with-current-buffer buffer
  6857. (widen)
  6858. (goto-char pos)
  6859. (save-excursion
  6860. (org-show-context 'agenda))
  6861. (save-excursion
  6862. (and (outline-next-heading)
  6863. (org-flag-heading nil))) ; show the next heading
  6864. (goto-char pos)
  6865. (call-interactively 'org-set-property)))))
  6866. (defun org-agenda-set-effort ()
  6867. "Set the effort property for the current headline."
  6868. (interactive)
  6869. (org-agenda-check-no-diary)
  6870. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6871. (org-agenda-error)))
  6872. (buffer (marker-buffer hdmarker))
  6873. (pos (marker-position hdmarker))
  6874. (inhibit-read-only t)
  6875. newhead)
  6876. (org-with-remote-undo buffer
  6877. (with-current-buffer buffer
  6878. (widen)
  6879. (goto-char pos)
  6880. (save-excursion
  6881. (org-show-context 'agenda))
  6882. (save-excursion
  6883. (and (outline-next-heading)
  6884. (org-flag-heading nil))) ; show the next heading
  6885. (goto-char pos)
  6886. (call-interactively 'org-set-effort)
  6887. (end-of-line 1)))))
  6888. (defun org-agenda-toggle-archive-tag ()
  6889. "Toggle the archive tag for the current entry."
  6890. (interactive)
  6891. (org-agenda-check-no-diary)
  6892. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6893. (org-agenda-error)))
  6894. (buffer (marker-buffer hdmarker))
  6895. (pos (marker-position hdmarker))
  6896. (inhibit-read-only t)
  6897. newhead)
  6898. (org-with-remote-undo buffer
  6899. (with-current-buffer buffer
  6900. (widen)
  6901. (goto-char pos)
  6902. (org-show-context 'agenda)
  6903. (save-excursion
  6904. (and (outline-next-heading)
  6905. (org-flag-heading nil))) ; show the next heading
  6906. (call-interactively 'org-toggle-archive-tag)
  6907. (end-of-line 1)
  6908. (setq newhead (org-get-heading)))
  6909. (org-agenda-change-all-lines newhead hdmarker)
  6910. (beginning-of-line 1))))
  6911. (defun org-agenda-do-date-later (arg)
  6912. (interactive "P")
  6913. (cond
  6914. ((or (equal arg '(16))
  6915. (memq last-command
  6916. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6917. (setq this-command 'org-agenda-date-later-minutes)
  6918. (org-agenda-date-later-minutes 1))
  6919. ((or (equal arg '(4))
  6920. (memq last-command
  6921. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6922. (setq this-command 'org-agenda-date-later-hours)
  6923. (org-agenda-date-later-hours 1))
  6924. (t
  6925. (org-agenda-date-later (prefix-numeric-value arg)))))
  6926. (defun org-agenda-do-date-earlier (arg)
  6927. (interactive "P")
  6928. (cond
  6929. ((or (equal arg '(16))
  6930. (memq last-command
  6931. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6932. (setq this-command 'org-agenda-date-earlier-minutes)
  6933. (org-agenda-date-earlier-minutes 1))
  6934. ((or (equal arg '(4))
  6935. (memq last-command
  6936. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6937. (setq this-command 'org-agenda-date-earlier-hours)
  6938. (org-agenda-date-earlier-hours 1))
  6939. (t
  6940. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6941. (defun org-agenda-date-later (arg &optional what)
  6942. "Change the date of this item to ARG day(s) later."
  6943. (interactive "p")
  6944. (org-agenda-check-type t 'agenda 'timeline)
  6945. (org-agenda-check-no-diary)
  6946. (let* ((marker (or (org-get-at-bol 'org-marker)
  6947. (org-agenda-error)))
  6948. (buffer (marker-buffer marker))
  6949. (pos (marker-position marker)))
  6950. (org-with-remote-undo buffer
  6951. (with-current-buffer buffer
  6952. (widen)
  6953. (goto-char pos)
  6954. (if (not (org-at-timestamp-p))
  6955. (error "Cannot find time stamp"))
  6956. (org-timestamp-change arg (or what 'day)))
  6957. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6958. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6959. (defun org-agenda-date-earlier (arg &optional what)
  6960. "Change the date of this item to ARG day(s) earlier."
  6961. (interactive "p")
  6962. (org-agenda-date-later (- arg) what))
  6963. (defun org-agenda-date-later-minutes (arg)
  6964. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6965. (interactive "p")
  6966. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6967. (org-agenda-date-later arg 'minute))
  6968. (defun org-agenda-date-earlier-minutes (arg)
  6969. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6970. (interactive "p")
  6971. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6972. (org-agenda-date-earlier arg 'minute))
  6973. (defun org-agenda-date-later-hours (arg)
  6974. "Change the time of this item, in hour steps."
  6975. (interactive "p")
  6976. (org-agenda-date-later arg 'hour))
  6977. (defun org-agenda-date-earlier-hours (arg)
  6978. "Change the time of this item, in hour steps."
  6979. (interactive "p")
  6980. (org-agenda-date-earlier arg 'hour))
  6981. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6982. "Show new date stamp via text properties."
  6983. ;; We use text properties to make this undoable
  6984. (let ((inhibit-read-only t)
  6985. (buffer-invisibility-spec))
  6986. (setq stamp (concat " " prefix " => " stamp))
  6987. (save-excursion
  6988. (goto-char (point-max))
  6989. (while (not (bobp))
  6990. (when (equal marker (org-get-at-bol 'org-marker))
  6991. (org-move-to-column (- (window-width) (length stamp)) t)
  6992. (org-agenda-fix-tags-filter-overlays-at (point))
  6993. (if (featurep 'xemacs)
  6994. ;; Use `duplicable' property to trigger undo recording
  6995. (let ((ex (make-extent nil nil))
  6996. (gl (make-glyph stamp)))
  6997. (set-glyph-face gl 'secondary-selection)
  6998. (set-extent-properties
  6999. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7000. (insert-extent ex (1- (point)) (point-at-eol)))
  7001. (add-text-properties
  7002. (1- (point)) (point-at-eol)
  7003. (list 'display (org-add-props stamp nil
  7004. 'face 'secondary-selection))))
  7005. (beginning-of-line 1))
  7006. (beginning-of-line 0)))))
  7007. (defun org-agenda-date-prompt (arg)
  7008. "Change the date of this item. Date is prompted for, with default today.
  7009. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7010. be used to request time specification in the time stamp."
  7011. (interactive "P")
  7012. (org-agenda-check-type t 'agenda 'timeline)
  7013. (org-agenda-check-no-diary)
  7014. (let* ((marker (or (org-get-at-bol 'org-marker)
  7015. (org-agenda-error)))
  7016. (buffer (marker-buffer marker))
  7017. (pos (marker-position marker)))
  7018. (org-with-remote-undo buffer
  7019. (with-current-buffer buffer
  7020. (widen)
  7021. (goto-char pos)
  7022. (if (not (org-at-timestamp-p t))
  7023. (error "Cannot find time stamp"))
  7024. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7025. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7026. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7027. (defun org-agenda-schedule (arg &optional time)
  7028. "Schedule the item at point.
  7029. Arg is passed through to `org-schedule'."
  7030. (interactive "P")
  7031. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7032. (org-agenda-check-no-diary)
  7033. (let* ((marker (or (org-get-at-bol 'org-marker)
  7034. (org-agenda-error)))
  7035. (type (marker-insertion-type marker))
  7036. (buffer (marker-buffer marker))
  7037. (pos (marker-position marker))
  7038. (org-insert-labeled-timestamps-at-point nil)
  7039. ts)
  7040. (set-marker-insertion-type marker t)
  7041. (org-with-remote-undo buffer
  7042. (with-current-buffer buffer
  7043. (widen)
  7044. (goto-char pos)
  7045. (setq ts (org-schedule arg time)))
  7046. (org-agenda-show-new-time marker ts "S"))
  7047. (message "Item scheduled for %s" ts)))
  7048. (defun org-agenda-deadline (arg &optional time)
  7049. "Schedule the item at point.
  7050. Arg is passed through to `org-deadline'."
  7051. (interactive "P")
  7052. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7053. (org-agenda-check-no-diary)
  7054. (let* ((marker (or (org-get-at-bol 'org-marker)
  7055. (org-agenda-error)))
  7056. (buffer (marker-buffer marker))
  7057. (pos (marker-position marker))
  7058. (org-insert-labeled-timestamps-at-point nil)
  7059. ts)
  7060. (org-with-remote-undo buffer
  7061. (with-current-buffer buffer
  7062. (widen)
  7063. (goto-char pos)
  7064. (setq ts (org-deadline arg time)))
  7065. (org-agenda-show-new-time marker ts "D"))
  7066. (message "Deadline for this item set to %s" ts)))
  7067. (defun org-agenda-action ()
  7068. "Select entry for agenda action, or execute an agenda action.
  7069. This command prompts for another letter. Valid inputs are:
  7070. m Mark the entry at point for an agenda action
  7071. s Schedule the marked entry to the date at the cursor
  7072. d Set the deadline of the marked entry to the date at the cursor
  7073. r Call `org-remember' with cursor date as the default date
  7074. c Call `org-capture' with cursor date as the default date
  7075. SPC Show marked entry in other window
  7076. TAB Visit marked entry in other window
  7077. The cursor may be at a date in the calendar, or in the Org agenda."
  7078. (interactive)
  7079. (let (ans)
  7080. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7081. (setq ans (read-char-exclusive))
  7082. (cond
  7083. ((equal ans ?m)
  7084. ;; Mark this entry
  7085. (if (eq major-mode 'org-agenda-mode)
  7086. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7087. (org-get-at-bol 'org-marker))))
  7088. (if m
  7089. (progn
  7090. (move-marker org-agenda-action-marker
  7091. (marker-position m) (marker-buffer m))
  7092. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7093. (error "Don't know which entry to mark")))
  7094. (error "This command works only in the agenda")))
  7095. ((equal ans ?s)
  7096. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7097. ((equal ans ?d)
  7098. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7099. ((equal ans ?r)
  7100. (org-agenda-do-action '(org-remember) t))
  7101. ((equal ans ?c)
  7102. (org-agenda-do-action '(org-capture) t))
  7103. ((equal ans ?\ )
  7104. (let ((cw (selected-window)))
  7105. (org-switch-to-buffer-other-window
  7106. (marker-buffer org-agenda-action-marker))
  7107. (goto-char org-agenda-action-marker)
  7108. (org-show-context 'agenda)
  7109. (select-window cw)))
  7110. ((equal ans ?\C-i)
  7111. (org-switch-to-buffer-other-window
  7112. (marker-buffer org-agenda-action-marker))
  7113. (goto-char org-agenda-action-marker)
  7114. (org-show-context 'agenda))
  7115. (t (error "Invalid agenda action %c" ans)))))
  7116. (defun org-agenda-do-action (form &optional current-buffer)
  7117. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7118. (let ((org-overriding-default-time (org-get-cursor-date)))
  7119. (if current-buffer
  7120. (eval form)
  7121. (if (not (marker-buffer org-agenda-action-marker))
  7122. (error "No entry has been selected for agenda action")
  7123. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7124. (save-excursion
  7125. (save-restriction
  7126. (widen)
  7127. (goto-char org-agenda-action-marker)
  7128. (eval form))))))))
  7129. (defun org-agenda-clock-in (&optional arg)
  7130. "Start the clock on the currently selected item."
  7131. (interactive "P")
  7132. (org-agenda-check-no-diary)
  7133. (if (equal arg '(4))
  7134. (org-clock-in arg)
  7135. (let* ((marker (or (org-get-at-bol 'org-marker)
  7136. (org-agenda-error)))
  7137. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7138. marker))
  7139. (pos (marker-position marker))
  7140. newhead)
  7141. (org-with-remote-undo (marker-buffer marker)
  7142. (with-current-buffer (marker-buffer marker)
  7143. (widen)
  7144. (goto-char pos)
  7145. (org-show-context 'agenda)
  7146. (org-show-entry)
  7147. (org-cycle-hide-drawers 'children)
  7148. (org-clock-in arg)
  7149. (setq newhead (org-get-heading)))
  7150. (org-agenda-change-all-lines newhead hdmarker)))))
  7151. (defun org-agenda-clock-out ()
  7152. "Stop the currently running clock."
  7153. (interactive)
  7154. (unless (marker-buffer org-clock-marker)
  7155. (error "No running clock"))
  7156. (let ((marker (make-marker)) newhead)
  7157. (org-with-remote-undo (marker-buffer org-clock-marker)
  7158. (with-current-buffer (marker-buffer org-clock-marker)
  7159. (save-excursion
  7160. (save-restriction
  7161. (widen)
  7162. (goto-char org-clock-marker)
  7163. (org-back-to-heading t)
  7164. (move-marker marker (point))
  7165. (org-clock-out)
  7166. (setq newhead (org-get-heading))))))
  7167. (org-agenda-change-all-lines newhead marker)
  7168. (move-marker marker nil)))
  7169. (defun org-agenda-clock-cancel (&optional arg)
  7170. "Cancel the currently running clock."
  7171. (interactive "P")
  7172. (unless (marker-buffer org-clock-marker)
  7173. (error "No running clock"))
  7174. (org-with-remote-undo (marker-buffer org-clock-marker)
  7175. (org-clock-cancel)))
  7176. (defun org-agenda-clock-goto ()
  7177. "Jump to the currently clocked in task within the agenda.
  7178. If the currently clocked in task is not listed in the agenda
  7179. buffer, display it in another window."
  7180. (interactive)
  7181. (let (pos)
  7182. (mapc (lambda (o)
  7183. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7184. (setq pos (overlay-start o))))
  7185. (overlays-in (point-min) (point-max)))
  7186. (cond (pos (goto-char pos))
  7187. ;; If the currently clocked entry is not in the agenda
  7188. ;; buffer, we visit it in another window:
  7189. (org-clock-current-task
  7190. (org-switch-to-buffer-other-window (org-clock-goto)))
  7191. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7192. (defun org-agenda-diary-entry-in-org-file ()
  7193. "Make a diary entry in the file `org-agenda-diary-file'."
  7194. (let (d1 d2 char (text "") dp1 dp2)
  7195. (if (equal (buffer-name) "*Calendar*")
  7196. (setq d1 (calendar-cursor-to-date t)
  7197. d2 (car calendar-mark-ring))
  7198. (setq dp1 (get-text-property (point-at-bol) 'day))
  7199. (unless dp1 (error "No date defined in current line"))
  7200. (setq d1 (calendar-gregorian-from-absolute dp1)
  7201. d2 (and (ignore-errors (mark))
  7202. (save-excursion
  7203. (goto-char (mark))
  7204. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7205. (calendar-gregorian-from-absolute dp2))))
  7206. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7207. (setq char (read-char-exclusive))
  7208. (cond
  7209. ((equal char ?d)
  7210. (setq text (read-string "Day entry: "))
  7211. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7212. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7213. ((equal char ?a)
  7214. (setq d1 (list (car d1) (nth 1 d1)
  7215. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7216. (nth 2 d1))))
  7217. (setq text (read-string "Anniversary (use %d to show years): "))
  7218. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7219. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7220. ((equal char ?b)
  7221. (setq text (read-string "Block entry: "))
  7222. (unless (and d1 d2 (not (equal d1 d2)))
  7223. (error "No block of days selected"))
  7224. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7225. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7226. ((equal char ?j)
  7227. (org-switch-to-buffer-other-window
  7228. (find-file-noselect org-agenda-diary-file))
  7229. (require 'org-datetree)
  7230. (org-datetree-find-date-create d1)
  7231. (org-reveal t))
  7232. (t (error "Invalid selection character `%c'" char)))))
  7233. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7234. "Where in `org-agenda-diary-file' should new entries be added?
  7235. Valid values:
  7236. date-tree in the date tree, as child of the date
  7237. top-level as top-level entries at the end of the file."
  7238. :group 'org-agenda
  7239. :type '(choice
  7240. (const :tag "in a date tree" date-tree)
  7241. (const :tag "as top level at end of file" top-level)))
  7242. (defcustom org-agenda-insert-diary-extract-time nil
  7243. "Non-nil means extract any time specification from the diary entry."
  7244. :group 'org-agenda
  7245. :type 'boolean)
  7246. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7247. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7248. If TEXT is not empty, it will become the headline of the new entry, and
  7249. the resulting entry will not be shown. When TEXT is empty, switch to
  7250. `org-agenda-diary-file' and let the user finish the entry there."
  7251. (let ((cw (current-window-configuration)))
  7252. (org-switch-to-buffer-other-window
  7253. (find-file-noselect org-agenda-diary-file))
  7254. (widen)
  7255. (goto-char (point-min))
  7256. (cond
  7257. ((eq type 'anniversary)
  7258. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7259. (progn
  7260. (or (org-on-heading-p t)
  7261. (progn
  7262. (outline-next-heading)
  7263. (insert "* Anniversaries\n\n")
  7264. (beginning-of-line -1)))))
  7265. (outline-next-heading)
  7266. (org-back-over-empty-lines)
  7267. (backward-char 1)
  7268. (insert "\n")
  7269. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7270. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7271. ((eq type 'day)
  7272. (let ((org-prefix-has-time t)
  7273. (org-agenda-time-leading-zero t)
  7274. fmt time time2)
  7275. (if org-agenda-insert-diary-extract-time
  7276. ;; Use org-format-agenda-item to parse text for a time-range and
  7277. ;; remove it. FIXME: This is a hack, we should refactor
  7278. ;; that function to make time extraction available separately
  7279. (setq fmt (org-format-agenda-item nil text nil nil t)
  7280. time (get-text-property 0 'time fmt)
  7281. time2 (if (> (length time) 0)
  7282. ;; split-string removes trailing ...... if
  7283. ;; no end time given. First space
  7284. ;; separates time from date.
  7285. (concat " " (car (split-string time "\\.")))
  7286. nil)
  7287. text (get-text-property 0 'txt fmt)))
  7288. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7289. (org-agenda-insert-diary-as-top-level text)
  7290. (require 'org-datetree)
  7291. (org-datetree-find-date-create d1)
  7292. (org-agenda-insert-diary-make-new-entry text))
  7293. (org-insert-time-stamp (org-time-from-absolute
  7294. (calendar-absolute-from-gregorian d1))
  7295. nil nil nil nil time2))
  7296. (end-of-line 0))
  7297. ((eq type 'block)
  7298. (if (> (calendar-absolute-from-gregorian d1)
  7299. (calendar-absolute-from-gregorian d2))
  7300. (setq d1 (prog1 d2 (setq d2 d1))))
  7301. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7302. (org-agenda-insert-diary-as-top-level text)
  7303. (require 'org-datetree)
  7304. (org-datetree-find-date-create d1)
  7305. (org-agenda-insert-diary-make-new-entry text))
  7306. (org-insert-time-stamp (org-time-from-absolute
  7307. (calendar-absolute-from-gregorian d1)))
  7308. (insert "--")
  7309. (org-insert-time-stamp (org-time-from-absolute
  7310. (calendar-absolute-from-gregorian d2)))
  7311. (end-of-line 0)))
  7312. (if (string-match "\\S-" text)
  7313. (progn
  7314. (set-window-configuration cw)
  7315. (message "%s entry added to %s"
  7316. (capitalize (symbol-name type))
  7317. (abbreviate-file-name org-agenda-diary-file)))
  7318. (org-reveal t)
  7319. (message "Please finish entry here"))))
  7320. (defun org-agenda-insert-diary-as-top-level (text)
  7321. "Make new entry as a top-level entry at the end of the file.
  7322. Add TEXT as headline, and position the cursor in the second line so that
  7323. a timestamp can be added there."
  7324. (widen)
  7325. (goto-char (point-max))
  7326. (or (bolp) (insert "\n"))
  7327. (insert "* " text "\n")
  7328. (if org-adapt-indentation (org-indent-to-column 2)))
  7329. (defun org-agenda-insert-diary-make-new-entry (text)
  7330. "Make new entry as last child of current entry.
  7331. Add TEXT as headline, and position the cursor in the second line so that
  7332. a timestamp can be added there."
  7333. (let ((org-show-following-heading t)
  7334. (org-show-siblings t)
  7335. (org-show-hierarchy-above t)
  7336. (org-show-entry-below t)
  7337. col)
  7338. (outline-next-heading)
  7339. (org-back-over-empty-lines)
  7340. (or (looking-at "[ \t]*$")
  7341. (progn (insert "\n") (backward-char 1)))
  7342. (org-insert-heading nil t)
  7343. (org-do-demote)
  7344. (setq col (current-column))
  7345. (insert text "\n")
  7346. (if org-adapt-indentation (org-indent-to-column col))
  7347. (let ((org-show-following-heading t)
  7348. (org-show-siblings t)
  7349. (org-show-hierarchy-above t)
  7350. (org-show-entry-below t))
  7351. (org-show-context))))
  7352. (defun org-agenda-diary-entry ()
  7353. "Make a diary entry, like the `i' command from the calendar.
  7354. All the standard commands work: block, weekly etc.
  7355. When `org-agenda-diary-file' points to a file,
  7356. `org-agenda-diary-entry-in-org-file' is called instead to create
  7357. entries in that Org-mode file."
  7358. (interactive)
  7359. (org-agenda-check-type t 'agenda 'timeline)
  7360. (if (not (eq org-agenda-diary-file 'diary-file))
  7361. (org-agenda-diary-entry-in-org-file)
  7362. (require 'diary-lib)
  7363. (let* ((char (progn
  7364. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7365. (read-char-exclusive)))
  7366. (cmd (cdr (assoc char
  7367. '((?d . insert-diary-entry)
  7368. (?w . insert-weekly-diary-entry)
  7369. (?m . insert-monthly-diary-entry)
  7370. (?y . insert-yearly-diary-entry)
  7371. (?a . insert-anniversary-diary-entry)
  7372. (?b . insert-block-diary-entry)
  7373. (?c . insert-cyclic-diary-entry)))))
  7374. (oldf (symbol-function 'calendar-cursor-to-date))
  7375. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7376. (point (point))
  7377. (mark (or (mark t) (point))))
  7378. (unless cmd
  7379. (error "No command associated with <%c>" char))
  7380. (unless (and (get-text-property point 'day)
  7381. (or (not (equal ?b char))
  7382. (get-text-property mark 'day)))
  7383. (error "Don't know which date to use for diary entry"))
  7384. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7385. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7386. (let ((calendar-mark-ring
  7387. (list (calendar-gregorian-from-absolute
  7388. (or (get-text-property mark 'day)
  7389. (get-text-property point 'day))))))
  7390. (unwind-protect
  7391. (progn
  7392. (fset 'calendar-cursor-to-date
  7393. (lambda (&optional error dummy)
  7394. (calendar-gregorian-from-absolute
  7395. (get-text-property point 'day))))
  7396. (call-interactively cmd))
  7397. (fset 'calendar-cursor-to-date oldf))))))
  7398. (defun org-agenda-execute-calendar-command (cmd)
  7399. "Execute a calendar command from the agenda, with the date associated to
  7400. the cursor position."
  7401. (org-agenda-check-type t 'agenda 'timeline)
  7402. (require 'diary-lib)
  7403. (unless (get-text-property (point) 'day)
  7404. (error "Don't know which date to use for calendar command"))
  7405. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7406. (point (point))
  7407. (date (calendar-gregorian-from-absolute
  7408. (get-text-property point 'day)))
  7409. ;; the following 2 vars are needed in the calendar
  7410. (displayed-month (car date))
  7411. (displayed-year (nth 2 date)))
  7412. (unwind-protect
  7413. (progn
  7414. (fset 'calendar-cursor-to-date
  7415. (lambda (&optional error dummy)
  7416. (calendar-gregorian-from-absolute
  7417. (get-text-property point 'day))))
  7418. (call-interactively cmd))
  7419. (fset 'calendar-cursor-to-date oldf))))
  7420. (defun org-agenda-phases-of-moon ()
  7421. "Display the phases of the moon for the 3 months around the cursor date."
  7422. (interactive)
  7423. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7424. (defun org-agenda-holidays ()
  7425. "Display the holidays for the 3 months around the cursor date."
  7426. (interactive)
  7427. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7428. (defvar calendar-longitude)
  7429. (defvar calendar-latitude)
  7430. (defvar calendar-location-name)
  7431. (defun org-agenda-sunrise-sunset (arg)
  7432. "Display sunrise and sunset for the cursor date.
  7433. Latitude and longitude can be specified with the variables
  7434. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7435. argument, latitude and longitude will be prompted for."
  7436. (interactive "P")
  7437. (require 'solar)
  7438. (let ((calendar-longitude (if arg nil calendar-longitude))
  7439. (calendar-latitude (if arg nil calendar-latitude))
  7440. (calendar-location-name
  7441. (if arg "the given coordinates" calendar-location-name)))
  7442. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7443. (defun org-agenda-goto-calendar ()
  7444. "Open the Emacs calendar with the date at the cursor."
  7445. (interactive)
  7446. (org-agenda-check-type t 'agenda 'timeline)
  7447. (let* ((day (or (get-text-property (point) 'day)
  7448. (error "Don't know which date to open in calendar")))
  7449. (date (calendar-gregorian-from-absolute day))
  7450. (calendar-move-hook nil)
  7451. (calendar-view-holidays-initially-flag nil)
  7452. (calendar-view-diary-initially-flag nil))
  7453. (calendar)
  7454. (calendar-goto-date date)))
  7455. ;;;###autoload
  7456. (defun org-calendar-goto-agenda ()
  7457. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7458. This is a command that has to be installed in `calendar-mode-map'."
  7459. (interactive)
  7460. (org-agenda-list nil (calendar-absolute-from-gregorian
  7461. (calendar-cursor-to-date))
  7462. nil))
  7463. (defun org-agenda-convert-date ()
  7464. (interactive)
  7465. (org-agenda-check-type t 'agenda 'timeline)
  7466. (let ((day (get-text-property (point) 'day))
  7467. date s)
  7468. (unless day
  7469. (error "Don't know which date to convert"))
  7470. (setq date (calendar-gregorian-from-absolute day))
  7471. (setq s (concat
  7472. "Gregorian: " (calendar-date-string date) "\n"
  7473. "ISO: " (calendar-iso-date-string date) "\n"
  7474. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7475. "Julian: " (calendar-julian-date-string date) "\n"
  7476. "Astron. JD: " (calendar-astro-date-string date)
  7477. " (Julian date number at noon UTC)\n"
  7478. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7479. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7480. "French: " (calendar-french-date-string date) "\n"
  7481. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7482. "Mayan: " (calendar-mayan-date-string date) "\n"
  7483. "Coptic: " (calendar-coptic-date-string date) "\n"
  7484. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7485. "Persian: " (calendar-persian-date-string date) "\n"
  7486. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7487. (with-output-to-temp-buffer "*Dates*"
  7488. (princ s))
  7489. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7490. ;;; Bulk commands
  7491. (defvar org-agenda-bulk-marked-entries nil
  7492. "List of markers that refer to marked entries in the agenda.")
  7493. (defun org-agenda-bulk-marked-p ()
  7494. (eq (get-char-property (point-at-bol) 'type)
  7495. 'org-marked-entry-overlay))
  7496. (defun org-agenda-bulk-mark (&optional arg)
  7497. "Mark the entry at point for future bulk action."
  7498. (interactive "p")
  7499. (dotimes (i (max arg 1))
  7500. (unless (org-get-at-bol 'org-agenda-diary-link)
  7501. (let* ((m (org-get-at-bol 'org-hd-marker))
  7502. ov)
  7503. (unless (org-agenda-bulk-marked-p)
  7504. (unless m (error "Nothing to mark at point"))
  7505. (push m org-agenda-bulk-marked-entries)
  7506. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7507. (org-overlay-display ov "> "
  7508. (org-get-todo-face "TODO")
  7509. 'evaporate)
  7510. (overlay-put ov 'type 'org-marked-entry-overlay))
  7511. (beginning-of-line 2)
  7512. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7513. (beginning-of-line 2))
  7514. (message "%d entries marked for bulk action"
  7515. (length org-agenda-bulk-marked-entries))))))
  7516. (defun org-agenda-bulk-mark-regexp (regexp)
  7517. "Mark entries match REGEXP."
  7518. (interactive "sMark entries matching regexp: ")
  7519. (let (entries-marked)
  7520. (save-excursion
  7521. (goto-char (point-min))
  7522. (goto-char (next-single-property-change (point) 'txt))
  7523. (while (re-search-forward regexp nil t)
  7524. (when (string-match regexp (get-text-property (point) 'txt))
  7525. (setq entries-marked (+ entries-marked 1))
  7526. (call-interactively 'org-agenda-bulk-mark))))
  7527. (if (not entries-marked)
  7528. (message "No entry matching this regexp."))))
  7529. (defun org-agenda-bulk-unmark ()
  7530. "Unmark the entry at point for future bulk action."
  7531. (interactive)
  7532. (when (org-agenda-bulk-marked-p)
  7533. (org-agenda-bulk-remove-overlays
  7534. (point-at-bol) (+ 2 (point-at-bol)))
  7535. (setq org-agenda-bulk-marked-entries
  7536. (delete (org-get-at-bol 'org-hd-marker)
  7537. org-agenda-bulk-marked-entries)))
  7538. (beginning-of-line 2)
  7539. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7540. (beginning-of-line 2))
  7541. (message "%d entries marked for bulk action"
  7542. (length org-agenda-bulk-marked-entries)))
  7543. (defun org-agenda-bulk-toggle ()
  7544. "Toggle marking the entry at point for bulk action."
  7545. (interactive)
  7546. (if (org-agenda-bulk-marked-p)
  7547. (org-agenda-bulk-unmark)
  7548. (org-agenda-bulk-mark)))
  7549. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7550. "Remove the mark overlays between BEG and END in the agenda buffer.
  7551. BEG and END default to the buffer limits.
  7552. This only removes the overlays, it does not remove the markers
  7553. from the list in `org-agenda-bulk-marked-entries'."
  7554. (interactive)
  7555. (mapc (lambda (ov)
  7556. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7557. (delete-overlay ov)))
  7558. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7559. (defun org-agenda-bulk-remove-all-marks ()
  7560. "Remove all marks in the agenda buffer.
  7561. This will remove the markers, and the overlays."
  7562. (interactive)
  7563. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7564. (setq org-agenda-bulk-marked-entries nil)
  7565. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7566. (defun org-agenda-bulk-action (&optional arg)
  7567. "Execute an remote-editing action on all marked entries.
  7568. The prefix arg is passed through to the command if possible."
  7569. (interactive "P")
  7570. ;; Make sure we have markers, and only valid ones
  7571. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7572. (mapc
  7573. (lambda (m)
  7574. (unless (and (markerp m)
  7575. (marker-buffer m)
  7576. (buffer-live-p (marker-buffer m))
  7577. (marker-position m))
  7578. (error "Marker %s for bulk command is invalid" m)))
  7579. org-agenda-bulk-marked-entries)
  7580. ;; Prompt for the bulk command
  7581. (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline [f]unction")
  7582. (let* ((action (read-char-exclusive))
  7583. (org-log-refile (if org-log-refile 'time nil))
  7584. (entries (reverse org-agenda-bulk-marked-entries))
  7585. redo-at-end
  7586. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7587. (cond
  7588. ((equal action ?$)
  7589. (setq cmd '(org-agenda-archive)))
  7590. ((equal action ?A)
  7591. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7592. ((member action '(?r ?w))
  7593. (setq rfloc (org-refile-get-location
  7594. "Refile to"
  7595. (marker-buffer (car org-agenda-bulk-marked-entries))
  7596. org-refile-allow-creating-parent-nodes))
  7597. (if (nth 3 rfloc)
  7598. (setcar (nthcdr 3 rfloc)
  7599. (move-marker (make-marker) (nth 3 rfloc)
  7600. (or (get-file-buffer (nth 1 rfloc))
  7601. (find-buffer-visiting (nth 1 rfloc))
  7602. (error "This should not happen")))))
  7603. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7604. redo-at-end t))
  7605. ((equal action ?t)
  7606. (setq state (org-icompleting-read
  7607. "Todo state: "
  7608. (with-current-buffer (marker-buffer (car entries))
  7609. (mapcar 'list org-todo-keywords-1))))
  7610. (setq cmd `(let ((org-inhibit-blocking t)
  7611. (org-inhibit-logging 'note))
  7612. (org-agenda-todo ,state))))
  7613. ((memq action '(?- ?+))
  7614. (setq tag (org-icompleting-read
  7615. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7616. (with-current-buffer (marker-buffer (car entries))
  7617. (delq nil
  7618. (mapcar (lambda (x)
  7619. (if (stringp (car x)) x)) org-tag-alist)))))
  7620. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7621. ((memq action '(?s ?d))
  7622. (let* ((date (unless arg
  7623. (org-read-date
  7624. nil nil nil
  7625. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7626. (ans (if arg nil org-read-date-final-answer))
  7627. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7628. (setq cmd `(let* ((bound (fboundp 'read-string))
  7629. (old (and bound (symbol-function 'read-string))))
  7630. (unwind-protect
  7631. (progn
  7632. (fset 'read-string (lambda (&rest ignore) ,ans))
  7633. (eval '(,c1 arg)))
  7634. (if bound
  7635. (fset 'read-string old)
  7636. (fmakunbound 'read-string)))))))
  7637. ((equal action ?S)
  7638. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7639. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7640. (let ((days (read-number
  7641. (format "Scatter tasks across how many %sdays: "
  7642. (if arg "week" "")) 7)))
  7643. (setq cmd
  7644. `(let ((distance (1+ (random ,days))))
  7645. (if arg
  7646. (let ((dist distance)
  7647. (day-of-week
  7648. (calendar-day-of-week
  7649. (calendar-gregorian-from-absolute (org-today)))))
  7650. (dotimes (i (1+ dist))
  7651. (while (member day-of-week org-agenda-weekend-days)
  7652. (incf distance)
  7653. (incf day-of-week)
  7654. (if (= day-of-week 7)
  7655. (setq day-of-week 0)))
  7656. (incf day-of-week)
  7657. (if (= day-of-week 7)
  7658. (setq day-of-week 0)))))
  7659. ;; silently fail when try to replan a sexp entry
  7660. (condition-case nil
  7661. (let* ((date (calendar-gregorian-from-absolute
  7662. (+ (org-today) distance)))
  7663. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7664. (nth 2 date))))
  7665. (org-agenda-schedule nil time))
  7666. (error nil)))))))
  7667. ((equal action ?f)
  7668. (setq cmd (list (intern
  7669. (org-icompleting-read "Function: "
  7670. obarray 'fboundp t nil nil)))))
  7671. (t (error "Invalid bulk action")))
  7672. ;; Sort the markers, to make sure that parents are handled before children
  7673. (setq entries (sort entries
  7674. (lambda (a b)
  7675. (cond
  7676. ((equal (marker-buffer a) (marker-buffer b))
  7677. (< (marker-position a) (marker-position b)))
  7678. (t
  7679. (string< (buffer-name (marker-buffer a))
  7680. (buffer-name (marker-buffer b))))))))
  7681. ;; Now loop over all markers and apply cmd
  7682. (while (setq e (pop entries))
  7683. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7684. (if (not pos)
  7685. (progn (message "Skipping removed entry at %s" e)
  7686. (setq cntskip (1+ cntskip)))
  7687. (goto-char pos)
  7688. (eval cmd)
  7689. (setq org-agenda-bulk-marked-entries
  7690. (delete e org-agenda-bulk-marked-entries))
  7691. (setq cnt (1+ cnt))))
  7692. (setq org-agenda-bulk-marked-entries nil)
  7693. (org-agenda-bulk-remove-all-marks)
  7694. (when redo-at-end (org-agenda-redo))
  7695. (message "Acted on %d entries%s"
  7696. cnt
  7697. (if (= cntskip 0)
  7698. ""
  7699. (format ", skipped %d (disappeared before their turn)"
  7700. cntskip)))))
  7701. ;;; Flagging notes
  7702. (defun org-agenda-show-the-flagging-note ()
  7703. "Display the flagging note in the other window.
  7704. When called a second time in direct sequence, offer to remove the FLAGGING
  7705. tag and (if present) the flagging note."
  7706. (interactive)
  7707. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7708. (win (selected-window))
  7709. note heading newhead)
  7710. (unless hdmarker
  7711. (error "No linked entry at point"))
  7712. (if (and (eq this-command last-command)
  7713. (y-or-n-p "Unflag and remove any flagging note? "))
  7714. (progn
  7715. (org-agenda-remove-flag hdmarker)
  7716. (let ((win (get-buffer-window "*Flagging Note*")))
  7717. (and win (delete-window win)))
  7718. (message "Entry unflaged"))
  7719. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7720. (unless note
  7721. (error "No flagging note"))
  7722. (org-kill-new note)
  7723. (org-switch-to-buffer-other-window "*Flagging Note*")
  7724. (erase-buffer)
  7725. (insert note)
  7726. (goto-char (point-min))
  7727. (while (re-search-forward "\\\\n" nil t)
  7728. (replace-match "\n" t t))
  7729. (goto-char (point-min))
  7730. (select-window win)
  7731. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7732. (defun org-agenda-remove-flag (marker)
  7733. "Remove the FLAGGED tag and any flagging note in the entry."
  7734. (let (newhead)
  7735. (org-with-point-at marker
  7736. (org-toggle-tag "FLAGGED" 'off)
  7737. (org-entry-delete nil "THEFLAGGINGNOTE")
  7738. (setq newhead (org-get-heading)))
  7739. (org-agenda-change-all-lines newhead marker)
  7740. (message "Entry unflaged")))
  7741. (defun org-agenda-get-any-marker (&optional pos)
  7742. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7743. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7744. ;;; Appointment reminders
  7745. (defvar appt-time-msg-list)
  7746. ;;;###autoload
  7747. (defun org-agenda-to-appt (&optional refresh filter)
  7748. "Activate appointments found in `org-agenda-files'.
  7749. With a \\[universal-argument] prefix, refresh the list of
  7750. appointments.
  7751. If FILTER is t, interactively prompt the user for a regular
  7752. expression, and filter out entries that don't match it.
  7753. If FILTER is a string, use this string as a regular expression
  7754. for filtering entries out.
  7755. FILTER can also be an alist with the car of each cell being
  7756. either 'headline or 'category. For example:
  7757. '((headline \"IMPORTANT\")
  7758. (category \"Work\"))
  7759. will only add headlines containing IMPORTANT or headlines
  7760. belonging to the \"Work\" category."
  7761. (interactive "P")
  7762. (if refresh (setq appt-time-msg-list nil))
  7763. (if (eq filter t)
  7764. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7765. (let* ((cnt 0) ; count added events
  7766. (org-agenda-new-buffers nil)
  7767. (org-deadline-warning-days 0)
  7768. ;; Do not use `org-today' here because appt only takes
  7769. ;; time and without date as argument, so it may pass wrong
  7770. ;; information otherwise
  7771. (today (org-date-to-gregorian
  7772. (time-to-days (current-time))))
  7773. (org-agenda-restrict nil)
  7774. (files (org-agenda-files 'unrestricted)) entries file)
  7775. ;; Get all entries which may contain an appt
  7776. (org-prepare-agenda-buffers files)
  7777. (while (setq file (pop files))
  7778. (setq entries
  7779. (append entries
  7780. (org-agenda-get-day-entries
  7781. file today :timestamp :scheduled :deadline))))
  7782. (setq entries (delq nil entries))
  7783. ;; Map thru entries and find if we should filter them out
  7784. (mapc
  7785. (lambda(x)
  7786. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7787. (cat (get-text-property 1 'org-category x))
  7788. (tod (get-text-property 1 'time-of-day x))
  7789. (ok (or (null filter)
  7790. (and (stringp filter) (string-match filter evt))
  7791. (and (listp filter)
  7792. (or (string-match
  7793. (cadr (assoc 'category filter)) cat)
  7794. (string-match
  7795. (cadr (assoc 'headline filter)) evt))))))
  7796. ;; FIXME: Shall we remove text-properties for the appt text?
  7797. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7798. (when (and ok tod)
  7799. (setq tod (concat "00" (number-to-string tod))
  7800. tod (when (string-match
  7801. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7802. (concat (match-string 1 tod) ":"
  7803. (match-string 2 tod))))
  7804. (appt-add tod evt)
  7805. (setq cnt (1+ cnt))))) entries)
  7806. (org-release-buffers org-agenda-new-buffers)
  7807. (if (eq cnt 0)
  7808. (message "No event to add")
  7809. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7810. (defun org-agenda-todayp (date)
  7811. "Does DATE mean today, when considering `org-extend-today-until'?"
  7812. (let ((today (org-today))
  7813. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7814. date)))
  7815. (eq date today)))
  7816. (provide 'org-agenda)
  7817. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7818. ;;; org-agenda.el ends here