org-agenda.el 298 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825
  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.01trans
  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 by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-ndays)
  217. (integer :value 1))
  218. (list :tag "Fixed starting date"
  219. (const org-agenda-start-day)
  220. (string :value "2007-11-01"))
  221. (list :tag "Start on day of week"
  222. (const org-agenda-start-on-weekday)
  223. (choice :value 1
  224. (const :tag "Today" nil)
  225. (integer :tag "Weekday No.")))
  226. (list :tag "Include data from diary"
  227. (const org-agenda-include-diary)
  228. (boolean))
  229. (list :tag "Deadline Warning days"
  230. (const org-deadline-warning-days)
  231. (integer :value 1))
  232. (list :tag "Tags filter preset"
  233. (const org-agenda-filter-preset)
  234. (list
  235. (const :format "" quote)
  236. (repeat
  237. (string :tag "+tag or -tag"))))
  238. (list :tag "Set daily/weekly entry types"
  239. (const org-agenda-entry-types)
  240. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  241. (const :deadline)
  242. (const :scheduled)
  243. (const :timestamp)
  244. (const :sexp)))
  245. (list :tag "Standard skipping condition"
  246. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  247. (const org-agenda-skip-function)
  248. (list
  249. (const :format "" quote)
  250. (list
  251. (choice
  252. :tag "Skipping range"
  253. (const :tag "Skip entry" org-agenda-skip-entry-if)
  254. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  255. (repeat :inline t :tag "Conditions for skipping"
  256. (choice
  257. :tag "Condition type"
  258. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  259. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  260. (list :tag "TODO state is" :inline t
  261. (const 'todo)
  262. (choice
  263. (const :tag "any not-done state" 'todo)
  264. (const :tag "any done state" 'done)
  265. (const :tag "any state" 'any)
  266. (list :tag "Keyword list"
  267. (const :format "" quote)
  268. (repeat (string :tag "Keyword")))))
  269. (list :tag "TODO state is not" :inline t
  270. (const 'nottodo)
  271. (choice
  272. (const :tag "any not-done state" 'todo)
  273. (const :tag "any done state" 'done)
  274. (const :tag "any state" 'any)
  275. (list :tag "Keyword list"
  276. (const :format "" quote)
  277. (repeat (string :tag "Keyword")))))
  278. (const :tag "scheduled" 'scheduled)
  279. (const :tag "not scheduled" 'notscheduled)
  280. (const :tag "deadline" 'deadline)
  281. (const :tag "no deadline" 'notdeadline)
  282. (const :tag "timestamp" 'timestamp)
  283. (const :tag "no timestamp" 'nottimestamp))))))
  284. (list :tag "Non-standard skipping condition"
  285. :value (org-agenda-skip-function)
  286. (const org-agenda-skip-function)
  287. (sexp :tag "Function or form (quoted!)"))
  288. (list :tag "Any variable"
  289. (variable :tag "Variable")
  290. (sexp :tag "Value (sexp)"))))
  291. "Selection of examples for agenda command settings.
  292. This will be spliced into the custom type of
  293. `org-agenda-custom-commands'.")
  294. (defcustom org-agenda-custom-commands nil
  295. "Custom commands for the agenda.
  296. These commands will be offered on the splash screen displayed by the
  297. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  298. (key desc type match settings files)
  299. key The key (one or more characters as a string) to be associated
  300. with the command.
  301. desc A description of the command, when omitted or nil, a default
  302. description is built using MATCH.
  303. type The command type, any of the following symbols:
  304. agenda The daily/weekly agenda.
  305. todo Entries with a specific TODO keyword, in all agenda files.
  306. search Entries containing search words entry or headline.
  307. tags Tags/Property/TODO match in all agenda files.
  308. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  309. todo-tree Sparse tree of specific TODO keyword in *current* file.
  310. tags-tree Sparse tree with all tags matches in *current* file.
  311. occur-tree Occur sparse tree for *current* file.
  312. ... A user-defined function.
  313. match What to search for:
  314. - a single keyword for TODO keyword searches
  315. - a tags match expression for tags searches
  316. - a word search expression for text searches.
  317. - a regular expression for occur searches
  318. For all other commands, this should be the empty string.
  319. settings A list of option settings, similar to that in a let form, so like
  320. this: ((opt1 val1) (opt2 val2) ...). The values will be
  321. evaluated at the moment of execution, so quote them when needed.
  322. files A list of files file to write the produced agenda buffer to
  323. with the command `org-store-agenda-views'.
  324. If a file name ends in \".html\", an HTML version of the buffer
  325. is written out. If it ends in \".ps\", a postscript version is
  326. produced. Otherwise, only the plain text is written to the file.
  327. You can also define a set of commands, to create a composite agenda buffer.
  328. In this case, an entry looks like this:
  329. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  330. where
  331. desc A description string to be displayed in the dispatcher menu.
  332. cmd An agenda command, similar to the above. However, tree commands
  333. are no allowed, but instead you can get agenda and global todo list.
  334. So valid commands for a set are:
  335. (agenda \"\" settings)
  336. (alltodo \"\" settings)
  337. (stuck \"\" settings)
  338. (todo \"match\" settings files)
  339. (search \"match\" settings files)
  340. (tags \"match\" settings files)
  341. (tags-todo \"match\" settings files)
  342. Each command can carry a list of options, and another set of options can be
  343. given for the whole set of commands. Individual command options take
  344. precedence over the general options.
  345. When using several characters as key to a command, the first characters
  346. are prefix commands. For the dispatcher to display useful information, you
  347. should provide a description for the prefix, like
  348. (setq org-agenda-custom-commands
  349. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  350. (\"hl\" tags \"+HOME+Lisa\")
  351. (\"hp\" tags \"+HOME+Peter\")
  352. (\"hk\" tags \"+HOME+Kim\")))"
  353. :group 'org-agenda-custom-commands
  354. :type `(repeat
  355. (choice :value ("x" "Describe command here" tags "" nil)
  356. (list :tag "Single command"
  357. (string :tag "Access Key(s) ")
  358. (option (string :tag "Description"))
  359. (choice
  360. (const :tag "Agenda" agenda)
  361. (const :tag "TODO list" alltodo)
  362. (const :tag "Search words" search)
  363. (const :tag "Stuck projects" stuck)
  364. (const :tag "Tags/Property match (all agenda files)" tags)
  365. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  366. (const :tag "TODO keyword search (all agenda files)" todo)
  367. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  368. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  369. (const :tag "Occur tree (current buffer)" occur-tree)
  370. (sexp :tag "Other, user-defined function"))
  371. (string :tag "Match (only for some commands)")
  372. ,org-agenda-custom-commands-local-options
  373. (option (repeat :tag "Export" (file :tag "Export to"))))
  374. (list :tag "Command series, all agenda files"
  375. (string :tag "Access Key(s)")
  376. (string :tag "Description ")
  377. (repeat :tag "Component"
  378. (choice
  379. (list :tag "Agenda"
  380. (const :format "" agenda)
  381. (const :tag "" :format "" "")
  382. ,org-agenda-custom-commands-local-options)
  383. (list :tag "TODO list (all keywords)"
  384. (const :format "" alltodo)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "Search words"
  388. (const :format "" search)
  389. (string :tag "Match")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Stuck projects"
  392. (const :format "" stuck)
  393. (const :tag "" :format "" "")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Tags search"
  396. (const :format "" tags)
  397. (string :tag "Match")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search, TODO entries only"
  400. (const :format "" tags-todo)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "TODO keyword search"
  404. (const :format "" todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "Other, user-defined function"
  408. (symbol :tag "function")
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)))
  411. (repeat :tag "Settings for entire command set"
  412. (list (variable :tag "Any variable")
  413. (sexp :tag "Value")))
  414. (option (repeat :tag "Export" (file :tag "Export to"))))
  415. (cons :tag "Prefix key documentation"
  416. (string :tag "Access Key(s)")
  417. (string :tag "Description ")))))
  418. (defcustom org-agenda-query-register ?o
  419. "The register holding the current query string.
  420. The purpose of this is that if you construct a query string interactively,
  421. you can then use it to define a custom command."
  422. :group 'org-agenda-custom-commands
  423. :type 'character)
  424. (defcustom org-stuck-projects
  425. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  426. "How to identify stuck projects.
  427. This is a list of four items:
  428. 1. A tags/todo/property matcher string that is used to identify a project.
  429. See the manual for a description of tag and property searches.
  430. The entire tree below a headline matched by this is considered one project.
  431. 2. A list of TODO keywords identifying non-stuck projects.
  432. If the project subtree contains any headline with one of these todo
  433. keywords, the project is considered to be not stuck. If you specify
  434. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  435. 3. A list of tags identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these tags,
  437. the project is considered to be not stuck. If you specify \"*\" as
  438. a tag, any tag will mark the project unstuck. Note that this is about
  439. the explicit presence of a tag somewhere in the subtree, inherited
  440. tags to not count here. If inherited tags make a project not stuck,
  441. use \"-TAG\" in the tags part of the matcher under (1.) above.
  442. 4. An arbitrary regular expression matching non-stuck projects.
  443. If the project turns out to be not stuck, search continues also in the
  444. subtree to see if any of the subtasks have project status.
  445. See also the variable `org-tags-match-list-sublevels' which applies
  446. to projects matched by this search as well.
  447. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  448. or `C-c a #' to produce the list."
  449. :group 'org-agenda-custom-commands
  450. :type '(list
  451. (string :tag "Tags/TODO match to identify a project")
  452. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  453. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  454. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  455. (defcustom org-agenda-filter-effort-default-operator "<"
  456. "The default operator for effort estimate filtering.
  457. If you select an effort estimate limit without first pressing an operator,
  458. this one will be used."
  459. :group 'org-agenda-custom-commands
  460. :type '(choice (const :tag "less or equal" "<")
  461. (const :tag "greater or equal"">")
  462. (const :tag "equal" "=")))
  463. (defgroup org-agenda-skip nil
  464. "Options concerning skipping parts of agenda files."
  465. :tag "Org Agenda Skip"
  466. :group 'org-agenda)
  467. (defgroup org-agenda-daily/weekly nil
  468. "Options concerning the daily/weekly agenda."
  469. :tag "Org Agenda Daily/Weekly"
  470. :group 'org-agenda)
  471. (defgroup org-agenda-todo-list nil
  472. "Options concerning the global todo list agenda view."
  473. :tag "Org Agenda Todo List"
  474. :group 'org-agenda)
  475. (defgroup org-agenda-match-view nil
  476. "Options concerning the general tags/property/todo match agenda view."
  477. :tag "Org Agenda Match View"
  478. :group 'org-agenda)
  479. (defgroup org-agenda-search-view nil
  480. "Options concerning the general tags/property/todo match agenda view."
  481. :tag "Org Agenda Match View"
  482. :group 'org-agenda)
  483. (defvar org-agenda-archives-mode nil
  484. "Non-nil means the agenda will include archived items.
  485. If this is the symbol `trees', trees in the selected agenda scope
  486. that are marked with the ARCHIVE tag will be included anyway. When this is
  487. t, also all archive files associated with the current selection of agenda
  488. files will be included.")
  489. (defcustom org-agenda-skip-comment-trees t
  490. "Non-nil means skip trees that start with the COMMENT keyword.
  491. When nil, these trees are also scanned by agenda commands."
  492. :group 'org-agenda-skip
  493. :type 'boolean)
  494. (defcustom org-agenda-todo-list-sublevels t
  495. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  496. When nil, the sublevels of a TODO entry are not checked, resulting in
  497. potentially much shorter TODO lists."
  498. :group 'org-agenda-skip
  499. :group 'org-agenda-todo-list
  500. :type 'boolean)
  501. (defcustom org-agenda-todo-ignore-with-date nil
  502. "Non-nil means don't show entries with a date in the global todo list.
  503. You can use this if you prefer to mark mere appointments with a TODO keyword,
  504. but don't want them to show up in the TODO list.
  505. When this is set, it also covers deadlines and scheduled items, the settings
  506. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  507. will be ignored.
  508. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-todo-list
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-ignore-scheduled nil
  513. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  514. This applies when creating the global todo list.
  515. Valid values are:
  516. past Don't show entries scheduled today or in the past.
  517. future Don't show entries scheduled in the future.
  518. The idea behind this is that by scheduling it, you don't want to
  519. think about it until the scheduled date.
  520. all Don't show any scheduled entries in the global todo list.
  521. The idea behind this is that by scheduling it, you have already
  522. \"taken care\" of this item.
  523. t Same as `all', for backward compatibility.
  524. See also `org-agenda-todo-ignore-with-date'.
  525. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  526. to make his option also apply to the tags-todo list."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type '(choice
  530. (const :tag "Ignore future-scheduled todos" future)
  531. (const :tag "Ignore past- or present-scheduled todos" past)
  532. (const :tag "Ignore all scheduled todos" all)
  533. (const :tag "Ignore all scheduled todos (compatibility)" t)
  534. (const :tag "Show scheduled todos" nil)))
  535. (defcustom org-agenda-todo-ignore-deadlines nil
  536. "Non-nil means ignore some deadlined TODO items when making TODO list.
  537. There are different motivations for using different values, please think
  538. carefully when configuring this variable.
  539. This applies when creating the global todo list.
  540. Valid values are:
  541. near Don't show near deadline entries. A deadline is near when it is
  542. closer than `org-deadline-warning-days' days. The idea behind this
  543. is that such items will appear in the agenda anyway.
  544. far Don't show TODO entries where a deadline has been defined, but
  545. the deadline is not near. This is useful if you don't want to
  546. use the todo list to figure out what to do now.
  547. past Don't show entries with a deadline timestamp for today or in the past.
  548. future Don't show entries with a deadline timestamp in the future, not even
  549. when they become `near' ones. Use it with caution.
  550. all Ignore all TODO entries that do have a deadline.
  551. t Same as `near', for backward compatibility.
  552. See also `org-agenda-todo-ignore-with-date'.
  553. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  554. to make his option also apply to the tags-todo list."
  555. :group 'org-agenda-skip
  556. :group 'org-agenda-todo-list
  557. :type '(choice
  558. (const :tag "Ignore near deadlines" near)
  559. (const :tag "Ignore near deadlines (compatibility)" t)
  560. (const :tag "Ignore far deadlines" far)
  561. (const :tag "Ignore all TODOs with a deadlines" all)
  562. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  563. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  564. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  565. The variables
  566. `org-agenda-todo-ignore-with-date',
  567. `org-agenda-todo-ignore-scheduled'
  568. `org-agenda-todo-ignore-deadlines'
  569. make the global TODO list skip entries that have time stamps of certain
  570. kinds. If this option is set, the same options will also apply for the
  571. tags-todo search, which is the general tags/property matcher
  572. restricted to unfinished TODO entries only."
  573. :group 'org-agenda-skip
  574. :group 'org-agenda-todo-list
  575. :group 'org-agenda-match-view
  576. :type 'boolean)
  577. (defcustom org-agenda-skip-scheduled-if-done nil
  578. "Non-nil means don't show scheduled items in agenda when they are done.
  579. This is relevant for the daily/weekly agenda, not for the TODO list. And
  580. it applies only to the actual date of the scheduling. Warnings about
  581. an item with a past scheduling dates are always turned off when the item
  582. is DONE."
  583. :group 'org-agenda-skip
  584. :group 'org-agenda-daily/weekly
  585. :type 'boolean)
  586. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  587. "Non-nil means skip scheduling line if same entry shows because of deadline.
  588. In the agenda of today, an entry can show up multiple times because
  589. it is both scheduled and has a nearby deadline, and maybe a plain time
  590. stamp as well.
  591. When this variable is t, then only the deadline is shown and the fact that
  592. the entry is scheduled today or was scheduled previously is not shown.
  593. When this variable is nil, the entry will be shown several times. When
  594. the variable is the symbol `not-today', then skip scheduled previously,
  595. but not scheduled today."
  596. :group 'org-agenda-skip
  597. :group 'org-agenda-daily/weekly
  598. :type '(choice
  599. (const :tag "Never" nil)
  600. (const :tag "Always" t)
  601. (const :tag "Not when scheduled today" not-today)))
  602. (defcustom org-agenda-skip-deadline-if-done nil
  603. "Non-nil means don't show deadlines when the corresponding item is done.
  604. When nil, the deadline is still shown and should give you a happy feeling.
  605. This is relevant for the daily/weekly agenda. And it applied only to the
  606. actually date of the deadline. Warnings about approaching and past-due
  607. deadlines are always turned off when the item is DONE."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-daily/weekly
  610. :type 'boolean)
  611. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  612. "Non-nil means skip deadline prewarning when entry is also scheduled.
  613. This will apply on all days where a prewarning for the deadline would
  614. be shown, but not at the day when the entry is actually due. On that day,
  615. the deadline will be shown anyway.
  616. This variable may be set to nil, t, or a number which will then give
  617. the number of days before the actual deadline when the prewarnings
  618. should resume.
  619. This can be used in a workflow where the first showing of the deadline will
  620. trigger you to schedule it, and then you don't want to be reminded of it
  621. because you will take care of it on the day when scheduled."
  622. :group 'org-agenda-skip
  623. :group 'org-agenda-daily/weekly
  624. :type '(choice
  625. (const :tag "Alwas show prewarning" nil)
  626. (const :tag "Remove prewarning if entry is scheduled" t)
  627. (integer :tag "Restart prewarning N days before deadline")))
  628. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  629. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  630. When non-nil, after the search for timestamps has matched once in an
  631. entry, the rest of the entry will not be searched."
  632. :group 'org-agenda-skip
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-timestamp-if-done nil
  635. "Non-nil means don't select item by timestamp or -range if it is DONE."
  636. :group 'org-agenda-skip
  637. :group 'org-agenda-daily/weekly
  638. :type 'boolean)
  639. (defcustom org-agenda-dim-blocked-tasks t
  640. "Non-nil means dim blocked tasks in the agenda display.
  641. This causes some overhead during agenda construction, but if you
  642. have turned on `org-enforce-todo-dependencies',
  643. `org-enforce-todo-checkbox-dependencies', or any other blocking
  644. mechanism, this will create useful feedback in the agenda.
  645. Instead of t, this variable can also have the value `invisible'.
  646. Then blocked tasks will be invisible and only become visible when
  647. they become unblocked. An exemption to this behavior is when a task is
  648. blocked because of unchecked checkboxes below it. Since checkboxes do
  649. not show up in the agenda views, making this task invisible you remove any
  650. trace from agenda views that there is something to do. Therefore, a task
  651. that is blocked because of checkboxes will never be made invisible, it
  652. will only be dimmed."
  653. :group 'org-agenda-daily/weekly
  654. :group 'org-agenda-todo-list
  655. :type '(choice
  656. (const :tag "Do not dim" nil)
  657. (const :tag "Dim to a grey face" t)
  658. (const :tag "Make invisible" invisible)))
  659. (defcustom org-timeline-show-empty-dates 3
  660. "Non-nil means `org-timeline' also shows dates without an entry.
  661. When nil, only the days which actually have entries are shown.
  662. When t, all days between the first and the last date are shown.
  663. When an integer, show also empty dates, but if there is a gap of more than
  664. N days, just insert a special line indicating the size of the gap."
  665. :group 'org-agenda-skip
  666. :type '(choice
  667. (const :tag "None" nil)
  668. (const :tag "All" t)
  669. (integer :tag "at most")))
  670. (defgroup org-agenda-startup nil
  671. "Options concerning initial settings in the Agenda in Org Mode."
  672. :tag "Org Agenda Startup"
  673. :group 'org-agenda)
  674. (defcustom org-agenda-menu-show-matcher t
  675. "Non-nil menas show the match string in the agenda dispatcher menu.
  676. When nil, the matcher string is not shown, but is put into the help-echo
  677. property so than moving the mouse over the command shows it.
  678. Setting it to nil is good if matcher strings are very long and/or if
  679. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  680. :group 'org-agenda
  681. :type 'boolean)
  682. (defcustom org-agenda-menu-two-column nil
  683. "Non-nil means, use two columns to show custom commands in the dispatcher.
  684. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  685. to nil."
  686. :group 'org-agenda
  687. :type 'boolean)
  688. (defcustom org-finalize-agenda-hook nil
  689. "Hook run just before displaying an agenda buffer."
  690. :group 'org-agenda-startup
  691. :type 'hook)
  692. (defcustom org-agenda-mouse-1-follows-link nil
  693. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  694. A longer mouse click will still set point. Does not work on XEmacs.
  695. Needs to be set before org.el is loaded."
  696. :group 'org-agenda-startup
  697. :type 'boolean)
  698. (defcustom org-agenda-start-with-follow-mode nil
  699. "The initial value of follow mode in a newly created agenda window."
  700. :group 'org-agenda-startup
  701. :type 'boolean)
  702. (defcustom org-agenda-show-outline-path t
  703. "Non-nil means show outline path in echo area after line motion."
  704. :group 'org-agenda-startup
  705. :type 'boolean)
  706. (defcustom org-agenda-start-with-entry-text-mode nil
  707. "The initial value of entry-text-mode in a newly created agenda window."
  708. :group 'org-agenda-startup
  709. :type 'boolean)
  710. (defcustom org-agenda-entry-text-maxlines 5
  711. "Number of text lines to be added when `E' is pressed in the agenda.
  712. Note that this variable only used during agenda display. Add add entry text
  713. when exporting the agenda, configure the variable
  714. `org-agenda-add-entry-ext-maxlines'."
  715. :group 'org-agenda
  716. :type 'integer)
  717. (defcustom org-agenda-entry-text-exclude-regexps nil
  718. "List of regular expressions to clean up entry text.
  719. The complete matches of all regular expressions in this list will be
  720. removed from entry text before it is shown in the agenda."
  721. :group 'org-agenda
  722. :type '(repeat (regexp)))
  723. (defvar org-agenda-entry-text-cleanup-hook nil
  724. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  725. This cleanup is done in a temporary buffer, so the function may inspect and
  726. change the entire buffer.
  727. Some default stuff like drawers and scheduling/deadline dates will already
  728. have been removed when this is called, as will any matches for regular
  729. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  730. (defvar org-agenda-include-inactive-timestamps nil
  731. "Non-nil means include inactive time stamps in agenda and timeline.")
  732. (defgroup org-agenda-windows nil
  733. "Options concerning the windows used by the Agenda in Org Mode."
  734. :tag "Org Agenda Windows"
  735. :group 'org-agenda)
  736. (defcustom org-agenda-window-setup 'reorganize-frame
  737. "How the agenda buffer should be displayed.
  738. Possible values for this option are:
  739. current-window Show agenda in the current window, keeping all other windows.
  740. other-window Use `switch-to-buffer-other-window' to display agenda.
  741. reorganize-frame Show only two windows on the current frame, the current
  742. window and the agenda.
  743. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  744. Also, when exiting the agenda, kill that frame.
  745. See also the variable `org-agenda-restore-windows-after-quit'."
  746. :group 'org-agenda-windows
  747. :type '(choice
  748. (const current-window)
  749. (const other-frame)
  750. (const other-window)
  751. (const reorganize-frame)))
  752. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  753. "The min and max height of the agenda window as a fraction of frame height.
  754. The value of the variable is a cons cell with two numbers between 0 and 1.
  755. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  756. :group 'org-agenda-windows
  757. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  758. (defcustom org-agenda-restore-windows-after-quit nil
  759. "Non-nil means restore window configuration open exiting agenda.
  760. Before the window configuration is changed for displaying the agenda,
  761. the current status is recorded. When the agenda is exited with
  762. `q' or `x' and this option is set, the old state is restored. If
  763. `org-agenda-window-setup' is `other-frame', the value of this
  764. option will be ignored."
  765. :group 'org-agenda-windows
  766. :type 'boolean)
  767. (defcustom org-agenda-ndays 7
  768. "Number of days to include in overview display.
  769. Should be 1 or 7.
  770. Custom commands can set this variable in the options section."
  771. :group 'org-agenda-daily/weekly
  772. :type 'integer)
  773. (defcustom org-agenda-start-on-weekday 1
  774. "Non-nil means start the overview always on the specified weekday.
  775. 0 denotes Sunday, 1 denotes Monday etc.
  776. When nil, always start on the current day.
  777. Custom commands can set this variable in the options section."
  778. :group 'org-agenda-daily/weekly
  779. :type '(choice (const :tag "Today" nil)
  780. (integer :tag "Weekday No.")))
  781. (defcustom org-agenda-show-all-dates t
  782. "Non-nil means `org-agenda' shows every day in the selected range.
  783. When nil, only the days which actually have entries are shown."
  784. :group 'org-agenda-daily/weekly
  785. :type 'boolean)
  786. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  787. "Format string for displaying dates in the agenda.
  788. Used by the daily/weekly agenda and by the timeline. This should be
  789. a format string understood by `format-time-string', or a function returning
  790. the formatted date as a string. The function must take a single argument,
  791. a calendar-style date list like (month day year)."
  792. :group 'org-agenda-daily/weekly
  793. :type '(choice
  794. (string :tag "Format string")
  795. (function :tag "Function")))
  796. (defun org-agenda-format-date-aligned (date)
  797. "Format a date string for display in the daily/weekly agenda, or timeline.
  798. This function makes sure that dates are aligned for easy reading."
  799. (require 'cal-iso)
  800. (let* ((dayname (calendar-day-name date))
  801. (day (cadr date))
  802. (day-of-week (calendar-day-of-week date))
  803. (month (car date))
  804. (monthname (calendar-month-name month))
  805. (year (nth 2 date))
  806. (iso-week (org-days-to-iso-week
  807. (calendar-absolute-from-gregorian date)))
  808. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  809. (1- year))
  810. ((and (= month 12) (<= iso-week 1))
  811. (1+ year))
  812. (t year)))
  813. (weekstring (if (= day-of-week 1)
  814. (format " W%02d" iso-week)
  815. "")))
  816. (format "%-10s %2d %s %4d%s"
  817. dayname day monthname year weekstring)))
  818. (defcustom org-agenda-time-leading-zero nil
  819. "Non-nil means use leading zero for military times in agenda.
  820. For example, 9:30am would become 09:30 rather than 9:30."
  821. :group 'org-agenda-daily/weekly
  822. :type 'boolean)
  823. (defcustom org-agenda-weekend-days '(6 0)
  824. "Which days are weekend?
  825. These days get the special face `org-agenda-date-weekend' in the agenda
  826. and timeline buffers."
  827. :group 'org-agenda-daily/weekly
  828. :type '(set :greedy t
  829. (const :tag "Monday" 1)
  830. (const :tag "Tuesday" 2)
  831. (const :tag "Wednesday" 3)
  832. (const :tag "Thursday" 4)
  833. (const :tag "Friday" 5)
  834. (const :tag "Saturday" 6)
  835. (const :tag "Sunday" 0)))
  836. (defcustom org-agenda-include-diary nil
  837. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  838. Custom commands can set this variable in the options section."
  839. :group 'org-agenda-daily/weekly
  840. :type 'boolean)
  841. (defcustom org-agenda-include-deadlines t
  842. "If non-nil, include entries within their deadline warning period.
  843. Custom commands can set this variable in the options section."
  844. :group 'org-agenda-daily/weekly
  845. :type 'boolean)
  846. (defcustom org-agenda-include-all-todo nil
  847. "Set means weekly/daily agenda will always contain all TODO entries.
  848. The TODO entries will be listed at the top of the agenda, before
  849. the entries for specific days.
  850. This option is deprecated, it is better to define a block agenda instead."
  851. :group 'org-agenda-daily/weekly
  852. :type 'boolean)
  853. (defcustom org-agenda-repeating-timestamp-show-all t
  854. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  855. When nil, only one occurrence is shown, either today or the
  856. nearest into the future."
  857. :group 'org-agenda-daily/weekly
  858. :type 'boolean)
  859. (defcustom org-scheduled-past-days 10000
  860. "No. of days to continue listing scheduled items that are not marked DONE.
  861. When an item is scheduled on a date, it shows up in the agenda on this
  862. day and will be listed until it is marked done for the number of days
  863. given here."
  864. :group 'org-agenda-daily/weekly
  865. :type 'integer)
  866. (defcustom org-agenda-log-mode-items '(closed clock)
  867. "List of items that should be shown in agenda log mode.
  868. This list may contain the following symbols:
  869. closed Show entries that have been closed on that day.
  870. clock Show entries that have received clocked time on that day.
  871. state Show all logged state changes.
  872. Note that instead of changing this variable, you can also press `C-u l' in
  873. the agenda to display all available LOG items temporarily."
  874. :group 'org-agenda-daily/weekly
  875. :type '(set :greedy t (const closed) (const clock) (const state)))
  876. (defcustom org-agenda-log-mode-add-notes t
  877. "Non-nil means add first line of notes to log entries in agenda views.
  878. If a log item like a state change or a clock entry is associated with
  879. notes, the first line of these notes will be added to the entry in the
  880. agenda display."
  881. :group 'org-agenda-daily/weekly
  882. :type 'boolean)
  883. (defcustom org-agenda-start-with-log-mode nil
  884. "The initial value of log-mode in a newly created agenda window."
  885. :group 'org-agenda-startup
  886. :group 'org-agenda-daily/weekly
  887. :type 'boolean)
  888. (defcustom org-agenda-start-with-clockreport-mode nil
  889. "The initial value of clockreport-mode in a newly created agenda window."
  890. :group 'org-agenda-startup
  891. :group 'org-agenda-daily/weekly
  892. :type 'boolean)
  893. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  894. "Property list with parameters for the clocktable in clockreport mode.
  895. This is the display mode that shows a clock table in the daily/weekly
  896. agenda, the properties for this dynamic block can be set here.
  897. The usual clocktable parameters are allowed here, but you cannot set
  898. the properties :name, :tstart, :tend, :block, and :scope - these will
  899. be overwritten to make sure the content accurately reflects the
  900. current display in the agenda."
  901. :group 'org-agenda-daily/weekly
  902. :type 'plist)
  903. (defcustom org-agenda-search-view-always-boolean nil
  904. "Non-nil means the search string is interpreted as individual parts.
  905. The search string for search view can either be interpreted as a phrase,
  906. or as a list of snippets that define a boolean search for a number of
  907. strings.
  908. When this is non-nil, the string will be split on whitespace, and each
  909. snippet will be searched individually, and all must match in order to
  910. select an entry. A snippet is then a single string of non-white
  911. characters, or a string in double quotes, or a regexp in {} braces.
  912. If a snippet is preceded by \"-\", the snippet must *not* match.
  913. \"+\" is syntactic sugar for positive selection. Each snippet may
  914. be found as a full word or a partial word, but see the variable
  915. `org-agenda-search-view-force-full-words'.
  916. When this is nil, search will look for the entire search phrase as one,
  917. with each space character matching any amount of whitespace, including
  918. line breaks.
  919. Even when this is nil, you can still switch to Boolean search dynamically
  920. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  921. is a regexp marked with braces like \"{abc}\", this will also switch to
  922. boolean search."
  923. :group 'org-agenda-search-view
  924. :type 'boolean)
  925. (if (fboundp 'defvaralias)
  926. (defvaralias 'org-agenda-search-view-search-words-only
  927. 'org-agenda-search-view-always-boolean))
  928. (defcustom org-agenda-search-view-force-full-words nil
  929. "Non-nil means, search words must be matches as complete words.
  930. When nil, they may also match part of a word."
  931. :group 'org-agenda-search-view
  932. :type 'boolean)
  933. (defgroup org-agenda-time-grid nil
  934. "Options concerning the time grid in the Org-mode Agenda."
  935. :tag "Org Agenda Time Grid"
  936. :group 'org-agenda)
  937. (defcustom org-agenda-search-headline-for-time t
  938. "Non-nil means search headline for a time-of-day.
  939. If the headline contains a time-of-day in one format or another, it will
  940. be used to sort the entry into the time sequence of items for a day.
  941. Some people have time stamps in the headline that refer to the creation
  942. time or so, and then this produces an unwanted side effect. If this is
  943. the case for your, use this variable to turn off searching the headline
  944. for a time."
  945. :group 'org-agenda-time-grid
  946. :type 'boolean)
  947. (defcustom org-agenda-use-time-grid t
  948. "Non-nil means show a time grid in the agenda schedule.
  949. A time grid is a set of lines for specific times (like every two hours between
  950. 8:00 and 20:00). The items scheduled for a day at specific times are
  951. sorted in between these lines.
  952. For details about when the grid will be shown, and what it will look like, see
  953. the variable `org-agenda-time-grid'."
  954. :group 'org-agenda-time-grid
  955. :type 'boolean)
  956. (defcustom org-agenda-time-grid
  957. '((daily today require-timed)
  958. "----------------"
  959. (800 1000 1200 1400 1600 1800 2000))
  960. "The settings for time grid for agenda display.
  961. This is a list of three items. The first item is again a list. It contains
  962. symbols specifying conditions when the grid should be displayed:
  963. daily if the agenda shows a single day
  964. weekly if the agenda shows an entire week
  965. today show grid on current date, independent of daily/weekly display
  966. require-timed show grid only if at least one item has a time specification
  967. The second item is a string which will be placed behind the grid time.
  968. The third item is a list of integers, indicating the times that should have
  969. a grid line."
  970. :group 'org-agenda-time-grid
  971. :type
  972. '(list
  973. (set :greedy t :tag "Grid Display Options"
  974. (const :tag "Show grid in single day agenda display" daily)
  975. (const :tag "Show grid in weekly agenda display" weekly)
  976. (const :tag "Always show grid for today" today)
  977. (const :tag "Show grid only if any timed entries are present"
  978. require-timed)
  979. (const :tag "Skip grid times already present in an entry"
  980. remove-match))
  981. (string :tag "Grid String")
  982. (repeat :tag "Grid Times" (integer :tag "Time"))))
  983. (defgroup org-agenda-sorting nil
  984. "Options concerning sorting in the Org-mode Agenda."
  985. :tag "Org Agenda Sorting"
  986. :group 'org-agenda)
  987. (defcustom org-agenda-sorting-strategy
  988. '((agenda habit-down time-up priority-down category-keep)
  989. (todo priority-down category-keep)
  990. (tags priority-down category-keep)
  991. (search category-keep))
  992. "Sorting structure for the agenda items of a single day.
  993. This is a list of symbols which will be used in sequence to determine
  994. if an entry should be listed before another entry. The following
  995. symbols are recognized:
  996. time-up Put entries with time-of-day indications first, early first
  997. time-down Put entries with time-of-day indications first, late first
  998. category-keep Keep the default order of categories, corresponding to the
  999. sequence in `org-agenda-files'.
  1000. category-up Sort alphabetically by category, A-Z.
  1001. category-down Sort alphabetically by category, Z-A.
  1002. tag-up Sort alphabetically by last tag, A-Z.
  1003. tag-down Sort alphabetically by last tag, Z-A.
  1004. priority-up Sort numerically by priority, high priority last.
  1005. priority-down Sort numerically by priority, high priority first.
  1006. todo-state-up Sort by todo state, tasks that are done last.
  1007. todo-state-down Sort by todo state, tasks that are done first.
  1008. effort-up Sort numerically by estimated effort, high effort last.
  1009. effort-down Sort numerically by estimated effort, high effort first.
  1010. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1011. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1012. habit-up Put entries that are habits first
  1013. habit-down Put entries that are habits last
  1014. alpha-up Sort headlines alphabetically
  1015. alpha-down Sort headlines alphabetically, reversed
  1016. The different possibilities will be tried in sequence, and testing stops
  1017. if one comparison returns a \"not-equal\". For example, the default
  1018. '(time-up category-keep priority-down)
  1019. means: Pull out all entries having a specified time of day and sort them,
  1020. in order to make a time schedule for the current day the first thing in the
  1021. agenda listing for the day. Of the entries without a time indication, keep
  1022. the grouped in categories, don't sort the categories, but keep them in
  1023. the sequence given in `org-agenda-files'. Within each category sort by
  1024. priority.
  1025. Leaving out `category-keep' would mean that items will be sorted across
  1026. categories by priority.
  1027. Instead of a single list, this can also be a set of list for specific
  1028. contents, with a context symbol in the car of the list, any of
  1029. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1030. Custom commands can bind this variable in the options section."
  1031. :group 'org-agenda-sorting
  1032. :type `(choice
  1033. (repeat :tag "General" ,org-sorting-choice)
  1034. (list :tag "Individually"
  1035. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1036. (repeat ,org-sorting-choice))
  1037. (cons (const :tag "Strategy for TODO lists" todo)
  1038. (repeat ,org-sorting-choice))
  1039. (cons (const :tag "Strategy for Tags matches" tags)
  1040. (repeat ,org-sorting-choice))
  1041. (cons (const :tag "Strategy for search matches" search)
  1042. (repeat ,org-sorting-choice)))))
  1043. (defcustom org-agenda-cmp-user-defined nil
  1044. "A function to define the comparison `user-defined'.
  1045. This function must receive two arguments, agenda entry a and b.
  1046. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1047. the user comparison, return nil.
  1048. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1049. part of an agenda sorting strategy."
  1050. :group 'org-agenda-sorting
  1051. :type 'symbol)
  1052. (defcustom org-sort-agenda-notime-is-late t
  1053. "Non-nil means items without time are considered late.
  1054. This is only relevant for sorting. When t, items which have no explicit
  1055. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1056. do have a time. When nil, the default time is before 0:00. You can use this
  1057. option to decide if the schedule for today should come before or after timeless
  1058. agenda entries."
  1059. :group 'org-agenda-sorting
  1060. :type 'boolean)
  1061. (defcustom org-sort-agenda-noeffort-is-high t
  1062. "Non-nil means items without effort estimate are sorted as high effort.
  1063. This also applies when filtering an agenda view with respect to the
  1064. < or > effort operator. Then, tasks with no effort defined will be treated
  1065. as tasks with high effort.
  1066. When nil, such items are sorted as 0 minutes effort."
  1067. :group 'org-agenda-sorting
  1068. :type 'boolean)
  1069. (defgroup org-agenda-line-format nil
  1070. "Options concerning the entry prefix in the Org-mode agenda display."
  1071. :tag "Org Agenda Line Format"
  1072. :group 'org-agenda)
  1073. (defcustom org-agenda-prefix-format
  1074. '((agenda . " %-12:c%?-12t% s")
  1075. (timeline . " % s")
  1076. (todo . " %-12:c")
  1077. (tags . " %-12:c")
  1078. (search . " %-12:c"))
  1079. "Format specifications for the prefix of items in the agenda views.
  1080. An alist with four entries, for the different agenda types. The keys to the
  1081. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1082. are format strings.
  1083. This format works similar to a printf format, with the following meaning:
  1084. %c the category of the item, \"Diary\" for entries from the diary, or
  1085. as given by the CATEGORY keyword or derived from the file name.
  1086. %T the *last* tag of the item. Last because inherited tags come
  1087. first in the list.
  1088. %t the time-of-day specification if one applies to the entry, in the
  1089. format HH:MM
  1090. %s Scheduling/Deadline information, a short string
  1091. All specifiers work basically like the standard `%s' of printf, but may
  1092. contain two additional characters: A question mark just after the `%' and
  1093. a whitespace/punctuation character just before the final letter.
  1094. If the first character after `%' is a question mark, the entire field
  1095. will only be included if the corresponding value applies to the
  1096. current entry. This is useful for fields which should have fixed
  1097. width when present, but zero width when absent. For example,
  1098. \"%?-12t\" will result in a 12 character time field if a time of the
  1099. day is specified, but will completely disappear in entries which do
  1100. not contain a time.
  1101. If there is punctuation or whitespace character just before the final
  1102. format letter, this character will be appended to the field value if
  1103. the value is not empty. For example, the format \"%-12:c\" leads to
  1104. \"Diary: \" if the category is \"Diary\". If the category were be
  1105. empty, no additional colon would be inserted.
  1106. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1107. - Indent the line with two space characters
  1108. - Give the category in a 12 chars wide field, padded with whitespace on
  1109. the right (because of `-'). Append a colon if there is a category
  1110. (because of `:').
  1111. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1112. time, don't put in an empty field, just skip it (because of '?').
  1113. - Finally, put the scheduling information and append a whitespace.
  1114. As another example, if you don't want the time-of-day of entries in
  1115. the prefix, you could use:
  1116. (setq org-agenda-prefix-format \" %-11:c% s\")
  1117. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1118. `org-agenda-remove-tags'.
  1119. Custom commands can set this variable in the options section."
  1120. :type '(choice
  1121. (string :tag "General format")
  1122. (list :greedy t :tag "View dependent"
  1123. (cons (const agenda) (string :tag "Format"))
  1124. (cons (const timeline) (string :tag "Format"))
  1125. (cons (const todo) (string :tag "Format"))
  1126. (cons (const tags) (string :tag "Format"))
  1127. (cons (const search) (string :tag "Format"))))
  1128. :group 'org-agenda-line-format)
  1129. (defvar org-prefix-format-compiled nil
  1130. "The compiled version of the most recently used prefix format.
  1131. See the variable `org-agenda-prefix-format'.")
  1132. (defcustom org-agenda-todo-keyword-format "%-1s"
  1133. "Format for the TODO keyword in agenda lines.
  1134. Set this to something like \"%-12s\" if you want all TODO keywords
  1135. to occupy a fixed space in the agenda display."
  1136. :group 'org-agenda-line-format
  1137. :type 'string)
  1138. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1139. "Text preceding timerange entries in the agenda view.
  1140. This is a list with two strings. The first applies when the range
  1141. is entirely on one day. The second applies if the range spans several days.
  1142. The strings may have two \"%d\" format specifiers which will be filled
  1143. with the sequence number of the days, and the total number of days in the
  1144. range, respectively."
  1145. :group 'org-agenda-line-format
  1146. :type '(list
  1147. (string :tag "Deadline today ")
  1148. (choice :tag "Deadline relative"
  1149. (string :tag "Format string")
  1150. (function))))
  1151. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1152. "Text preceding scheduled items in the agenda view.
  1153. This is a list with two strings. The first applies when the item is
  1154. scheduled on the current day. The second applies when it has been scheduled
  1155. previously, it may contain a %d indicating that this is the nth time that
  1156. this item is scheduled, due to automatic rescheduling of unfinished items
  1157. for the following day. So this number is one larger than the number of days
  1158. that passed since this item was scheduled first."
  1159. :group 'org-agenda-line-format
  1160. :type '(list
  1161. (string :tag "Scheduled today ")
  1162. (string :tag "Scheduled previously")))
  1163. (defcustom org-agenda-inactive-leader "["
  1164. "Text preceding item pulled into the agenda by inactive time stamps.
  1165. These entries are added to the agenda when pressing \"[\"."
  1166. :group 'org-agenda-line-format
  1167. :type '(list
  1168. (string :tag "Scheduled today ")
  1169. (string :tag "Scheduled previously")))
  1170. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1171. "Text preceding deadline items in the agenda view.
  1172. This is a list with two strings. The first applies when the item has its
  1173. deadline on the current day. The second applies when it is in the past or
  1174. in the future, it may contain %d to capture how many days away the deadline
  1175. is (was)."
  1176. :group 'org-agenda-line-format
  1177. :type '(list
  1178. (string :tag "Deadline today ")
  1179. (choice :tag "Deadline relative"
  1180. (string :tag "Format string")
  1181. (function))))
  1182. (defcustom org-agenda-remove-times-when-in-prefix t
  1183. "Non-nil means remove duplicate time specifications in agenda items.
  1184. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1185. time-of-day specification in a headline or diary entry is extracted and
  1186. placed into the prefix. If this option is non-nil, the original specification
  1187. \(a timestamp or -range, or just a plain time(range) specification like
  1188. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1189. cluttered.
  1190. The option can be t or nil. It may also be the symbol `beg', indicating
  1191. that the time should only be removed when it is located at the beginning of
  1192. the headline/diary entry."
  1193. :group 'org-agenda-line-format
  1194. :type '(choice
  1195. (const :tag "Always" t)
  1196. (const :tag "Never" nil)
  1197. (const :tag "When at beginning of entry" beg)))
  1198. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1199. "Non-nil means remove time ranges specifications in agenda
  1200. items that span on several days."
  1201. :group 'org-agenda-line-format
  1202. :type 'boolean)
  1203. (defcustom org-agenda-default-appointment-duration nil
  1204. "Default duration for appointments that only have a starting time.
  1205. When nil, no duration is specified in such cases.
  1206. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1207. :group 'org-agenda-line-format
  1208. :type '(choice
  1209. (integer :tag "Minutes")
  1210. (const :tag "No default duration")))
  1211. (defcustom org-agenda-show-inherited-tags t
  1212. "Non-nil means show inherited tags in each agenda line."
  1213. :group 'org-agenda-line-format
  1214. :type 'boolean)
  1215. (defcustom org-agenda-hide-tags-regexp nil
  1216. "Regular expression used to filter away specific tags in agenda views.
  1217. This means that these tags will be present, but not be shown in the agenda
  1218. line. Secondary filtering will still work on the hidden tags.
  1219. Nil means don't hide any tags."
  1220. :group 'org-agenda-line-format
  1221. :type '(choice
  1222. (const :tag "Hide none" nil)
  1223. (string :tag "Regexp ")))
  1224. (defcustom org-agenda-remove-tags nil
  1225. "Non-nil means remove the tags from the headline copy in the agenda.
  1226. When this is the symbol `prefix', only remove tags when
  1227. `org-agenda-prefix-format' contains a `%T' specifier."
  1228. :group 'org-agenda-line-format
  1229. :type '(choice
  1230. (const :tag "Always" t)
  1231. (const :tag "Never" nil)
  1232. (const :tag "When prefix format contains %T" prefix)))
  1233. (if (fboundp 'defvaralias)
  1234. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1235. 'org-agenda-remove-tags))
  1236. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1237. "Shift tags in agenda items to this column.
  1238. If this number is positive, it specifies the column. If it is negative,
  1239. it means that the tags should be flushright to that column. For example,
  1240. -80 works well for a normal 80 character screen."
  1241. :group 'org-agenda-line-format
  1242. :type 'integer)
  1243. (if (fboundp 'defvaralias)
  1244. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1245. (defcustom org-agenda-fontify-priorities 'cookies
  1246. "Non-nil means highlight low and high priorities in agenda.
  1247. When t, the highest priority entries are bold, lowest priority italic.
  1248. However, settings in `org-priority-faces' will overrule these faces.
  1249. When this variable is the symbol `cookies', only fontify the
  1250. cookies, not the entire task.
  1251. This may also be an association list of priority faces, whose
  1252. keys are the character values of `org-highest-priority',
  1253. `org-default-priority', and `org-lowest-priority' (the default values
  1254. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1255. color as a string, or a list like `(:background \"Red\")'.
  1256. If it is a color, the variable `org-faces-easy-properties'
  1257. determines if it is a foreground or a background color."
  1258. :group 'org-agenda-line-format
  1259. :type '(choice
  1260. (const :tag "Never" nil)
  1261. (const :tag "Defaults" t)
  1262. (const :tag "Cookies only" cookies)
  1263. (repeat :tag "Specify"
  1264. (list (character :tag "Priority" :value ?A)
  1265. (choice :tag "Face "
  1266. (string :tag "Color")
  1267. (sexp :tag "Face"))))))
  1268. (defgroup org-agenda-column-view nil
  1269. "Options concerning column view in the agenda."
  1270. :tag "Org Agenda Column View"
  1271. :group 'org-agenda)
  1272. (defcustom org-agenda-columns-show-summaries t
  1273. "Non-nil means show summaries for columns displayed in the agenda view."
  1274. :group 'org-agenda-column-view
  1275. :type 'boolean)
  1276. (defcustom org-agenda-columns-remove-prefix-from-item t
  1277. "Non-nil means remove the prefix from a headline for agenda column view.
  1278. The special ITEM field in the columns format contains the current line, with
  1279. all information shown in other columns (like the TODO state or a tag).
  1280. When this variable is non-nil, also the agenda prefix will be removed from
  1281. the content of the ITEM field, to make sure as much as possible of the
  1282. headline can be shown in the limited width of the field."
  1283. :group 'org-agenda
  1284. :type 'boolean)
  1285. (defcustom org-agenda-columns-compute-summary-properties t
  1286. "Non-nil means recompute all summary properties before column view.
  1287. When column view in the agenda is listing properties that have a summary
  1288. operator, it can go to all relevant buffers and recompute the summaries
  1289. there. This can mean overhead for the agenda column view, but is necessary
  1290. to have thing up to date.
  1291. As a special case, a CLOCKSUM property also makes sure that the clock
  1292. computations are current."
  1293. :group 'org-agenda-column-view
  1294. :type 'boolean)
  1295. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1296. "Non-nil means the duration of an appointment will add to day effort.
  1297. The property to which appointment durations will be added is the one given
  1298. in the option `org-effort-property'. If an appointment does not have
  1299. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1300. is not set, an appointment without end time will not contribute to the time
  1301. estimate."
  1302. :group 'org-agenda-column-view
  1303. :type 'boolean)
  1304. (defcustom org-agenda-auto-exclude-function nil
  1305. "A function called with a tag to decide if it is filtered on '/ RET'.
  1306. The sole argument to the function, which is called once for each
  1307. possible tag, is a string giving the name of the tag. The
  1308. function should return either nil if the tag should be included
  1309. as normal, or \"-<TAG>\" to exclude the tag.
  1310. Note that for the purpose of tag filtering, only the lower-case version of
  1311. all tags will be considered, so that this function will only ever see
  1312. the lower-case version of all tags."
  1313. :group 'org-agenda
  1314. :type 'function)
  1315. (eval-when-compile
  1316. (require 'cl))
  1317. (require 'org)
  1318. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1319. "Execute BODY with point at location given by `org-hd-marker' property.
  1320. If STRING is non-nil, the text property will be fetched from position 0
  1321. in that string. If STRING is nil, it will be fetched from the beginning
  1322. of the current line."
  1323. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1324. 'org-hd-marker string)))
  1325. (with-current-buffer (marker-buffer marker)
  1326. (save-excursion
  1327. (goto-char marker)
  1328. ,@body))))
  1329. (defun org-add-agenda-custom-command (entry)
  1330. "Replace or add a command in `org-agenda-custom-commands'.
  1331. This is mostly for hacking and trying a new command - once the command
  1332. works you probably want to add it to `org-agenda-custom-commands' for good."
  1333. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1334. (if ass
  1335. (setcdr ass (cdr entry))
  1336. (push entry org-agenda-custom-commands))))
  1337. ;;; Define the Org-agenda-mode
  1338. (defvar org-agenda-mode-map (make-sparse-keymap)
  1339. "Keymap for `org-agenda-mode'.")
  1340. (if (fboundp 'defvaralias)
  1341. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1342. (defvar org-agenda-menu) ; defined later in this file.
  1343. (defvar org-agenda-restrict) ; defined later in this file.
  1344. (defvar org-agenda-follow-mode nil)
  1345. (defvar org-agenda-entry-text-mode nil)
  1346. (defvar org-agenda-clockreport-mode nil)
  1347. (defvar org-agenda-show-log nil)
  1348. (defvar org-agenda-redo-command nil)
  1349. (defvar org-agenda-query-string nil)
  1350. (defvar org-agenda-mode-hook nil
  1351. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1352. (defvar org-agenda-type nil)
  1353. (defvar org-agenda-force-single-file nil)
  1354. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1355. (defun org-agenda-mode ()
  1356. "Mode for time-sorted view on action items in Org-mode files.
  1357. The following commands are available:
  1358. \\{org-agenda-mode-map}"
  1359. (interactive)
  1360. (kill-all-local-variables)
  1361. (setq org-agenda-undo-list nil
  1362. org-agenda-pending-undo-list nil
  1363. org-agenda-bulk-marked-entries nil)
  1364. (setq major-mode 'org-agenda-mode)
  1365. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1366. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1367. (setq mode-name "Org-Agenda")
  1368. (use-local-map org-agenda-mode-map)
  1369. (easy-menu-add org-agenda-menu)
  1370. (if org-startup-truncated (setq truncate-lines t))
  1371. (org-set-local 'line-move-visual nil)
  1372. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1373. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1374. ;; Make sure properties are removed when copying text
  1375. (when (boundp 'buffer-substring-filters)
  1376. (org-set-local 'buffer-substring-filters
  1377. (cons (lambda (x)
  1378. (set-text-properties 0 (length x) nil x) x)
  1379. buffer-substring-filters)))
  1380. (unless org-agenda-keep-modes
  1381. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1382. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1383. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1384. org-agenda-show-log org-agenda-start-with-log-mode))
  1385. (easy-menu-change
  1386. '("Agenda") "Agenda Files"
  1387. (append
  1388. (list
  1389. (vector
  1390. (if (get 'org-agenda-files 'org-restrict)
  1391. "Restricted to single file"
  1392. "Edit File List")
  1393. '(org-edit-agenda-file-list)
  1394. (not (get 'org-agenda-files 'org-restrict)))
  1395. "--")
  1396. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1397. (org-agenda-set-mode-name)
  1398. (apply
  1399. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1400. (list 'org-agenda-mode-hook)))
  1401. (substitute-key-definition 'undo 'org-agenda-undo
  1402. org-agenda-mode-map global-map)
  1403. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1404. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1405. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1406. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1407. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1408. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1409. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1410. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1411. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1412. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1413. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1414. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1415. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1416. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1417. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1418. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1419. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1420. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1421. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1422. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1423. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1424. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1425. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1426. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1427. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1428. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1429. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1430. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1431. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1432. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1433. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1434. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1435. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1436. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1437. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1438. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1439. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1440. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1441. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1442. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1443. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1444. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1445. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1446. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1447. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1448. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1449. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1450. (while l (org-defkey org-agenda-mode-map
  1451. (int-to-string (pop l)) 'digit-argument)))
  1452. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1453. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1454. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1455. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1456. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1457. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1458. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1459. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1460. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1461. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1462. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1463. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1464. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1465. 'org-clock-modify-effort-estimate)
  1466. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1467. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1468. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1469. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1470. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1471. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1472. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1473. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1474. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1475. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1476. (substitute-key-definition 'next-line 'org-agenda-next-line
  1477. org-agenda-mode-map global-map)
  1478. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1479. org-agenda-mode-map global-map)
  1480. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1481. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1482. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1483. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1484. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1485. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1486. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1487. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1488. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1489. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1490. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1491. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1492. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1493. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1494. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1495. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1496. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1497. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1498. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1499. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1500. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1501. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1502. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1503. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1504. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1505. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1506. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1507. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1508. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1509. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1510. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1511. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1512. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1513. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1514. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1515. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1516. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1517. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1518. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1519. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1520. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1521. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1522. (when org-agenda-mouse-1-follows-link
  1523. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1524. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1525. '("Agenda"
  1526. ("Agenda Files")
  1527. "--"
  1528. ("Agenda Dates"
  1529. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1530. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1531. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1532. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1533. "--"
  1534. ("View"
  1535. ["Day View" org-agenda-day-view
  1536. :active (org-agenda-check-type nil 'agenda)
  1537. :style radio :selected (equal org-agenda-ndays 1)
  1538. :keys "v d (or just d)"]
  1539. ["Week View" org-agenda-week-view
  1540. :active (org-agenda-check-type nil 'agenda)
  1541. :style radio :selected (equal org-agenda-ndays 7)
  1542. :keys "v w (or just w)"]
  1543. ["Month View" org-agenda-month-view
  1544. :active (org-agenda-check-type nil 'agenda)
  1545. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1546. :keys "v m"]
  1547. ["Year View" org-agenda-year-view
  1548. :active (org-agenda-check-type nil 'agenda)
  1549. :style radio :selected (member org-agenda-ndays '(365 366))
  1550. :keys "v y"]
  1551. "--"
  1552. ["Include Diary" org-agenda-toggle-diary
  1553. :style toggle :selected org-agenda-include-diary
  1554. :active (org-agenda-check-type nil 'agenda)]
  1555. ["Include Deadlines" org-agenda-toggle-deadlines
  1556. :style toggle :selected org-agenda-include-deadlines
  1557. :active (org-agenda-check-type nil 'agenda)]
  1558. ["Use Time Grid" org-agenda-toggle-time-grid
  1559. :style toggle :selected org-agenda-use-time-grid
  1560. :active (org-agenda-check-type nil 'agenda)]
  1561. "--"
  1562. ["Show clock report" org-agenda-clockreport-mode
  1563. :style toggle :selected org-agenda-clockreport-mode
  1564. :active (org-agenda-check-type nil 'agenda)]
  1565. ["Show some entry text" org-agenda-entry-text-mode
  1566. :style toggle :selected org-agenda-entry-text-mode
  1567. :active t]
  1568. "--"
  1569. ["Show Logbook entries" org-agenda-log-mode
  1570. :style toggle :selected org-agenda-show-log
  1571. :active (org-agenda-check-type nil 'agenda 'timeline)
  1572. :keys "v l (or just l)"]
  1573. ["Include archived trees" org-agenda-archives-mode
  1574. :style toggle :selected org-agenda-archives-mode :active t
  1575. :keys "v a"]
  1576. ["Include archive files" (org-agenda-archives-mode t)
  1577. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1578. :keys "v A"]
  1579. "--"
  1580. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1581. ["Write view to file" org-write-agenda t]
  1582. ["Rebuild buffer" org-agenda-redo t]
  1583. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1584. "--"
  1585. ["Show original entry" org-agenda-show t]
  1586. ["Go To (other window)" org-agenda-goto t]
  1587. ["Go To (this window)" org-agenda-switch-to t]
  1588. ["Follow Mode" org-agenda-follow-mode
  1589. :style toggle :selected org-agenda-follow-mode :active t]
  1590. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1591. "--"
  1592. ("TODO"
  1593. ["Cycle TODO" org-agenda-todo t]
  1594. ["Next TODO set" org-agenda-todo-nextset t]
  1595. ["Previous TODO set" org-agenda-todo-previousset t]
  1596. ["Add note" org-agenda-add-note t])
  1597. ("Archive/Refile/Delete"
  1598. ["Archive default" org-agenda-archive-default t]
  1599. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1600. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1601. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1602. ["Archive subtree" org-agenda-archive t]
  1603. "--"
  1604. ["Refile" org-agenda-refile t]
  1605. "--"
  1606. ["Delete subtree" org-agenda-kill t])
  1607. ("Bulk action"
  1608. ["Mark entry" org-agenda-bulk-mark t]
  1609. ["Unmark entry" org-agenda-bulk-unmark t]
  1610. ["Act on all marked" org-agenda-bulk-action t]
  1611. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1612. "--"
  1613. ("Tags and Properties"
  1614. ["Show all Tags" org-agenda-show-tags t]
  1615. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1616. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1617. "--"
  1618. ["Column View" org-columns t])
  1619. ("Deadline/Schedule"
  1620. ["Schedule" org-agenda-schedule t]
  1621. ["Set Deadline" org-agenda-deadline t]
  1622. "--"
  1623. ["Mark item" org-agenda-action :active t :keys "k m"]
  1624. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1625. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1626. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1627. "--"
  1628. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1629. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1630. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1631. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1632. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1633. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1634. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1635. ("Clock and Effort"
  1636. ["Clock in" org-agenda-clock-in t]
  1637. ["Clock out" org-agenda-clock-out t]
  1638. ["Clock cancel" org-agenda-clock-cancel t]
  1639. ["Goto running clock" org-clock-goto t]
  1640. "--"
  1641. ["Set Effort" org-agenda-set-effort t]
  1642. ["Change clocked effort" org-clock-modify-effort-estimate
  1643. (org-clock-is-active)])
  1644. ("Priority"
  1645. ["Set Priority" org-agenda-priority t]
  1646. ["Increase Priority" org-agenda-priority-up t]
  1647. ["Decrease Priority" org-agenda-priority-down t]
  1648. ["Show Priority" org-agenda-show-priority t])
  1649. ("Calendar/Diary"
  1650. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1651. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1652. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1653. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1654. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1655. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1656. "--"
  1657. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1658. "--"
  1659. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1660. "--"
  1661. ("MobileOrg"
  1662. ["Push Files and Views" org-mobile-push t]
  1663. ["Get Captured and Flagged" org-mobile-pull t]
  1664. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1665. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1666. "--"
  1667. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1668. "--"
  1669. ["Quit" org-agenda-quit t]
  1670. ["Exit and Release Buffers" org-agenda-exit t]
  1671. ))
  1672. ;;; Agenda undo
  1673. (defvar org-agenda-allow-remote-undo t
  1674. "Non-nil means allow remote undo from the agenda buffer.")
  1675. (defvar org-agenda-undo-list nil
  1676. "List of undoable operations in the agenda since last refresh.")
  1677. (defvar org-agenda-undo-has-started-in nil
  1678. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1679. (defvar org-agenda-pending-undo-list nil
  1680. "In a series of undo commands, this is the list of remaining undo items.")
  1681. (defun org-agenda-undo ()
  1682. "Undo a remote editing step in the agenda.
  1683. This undoes changes both in the agenda buffer and in the remote buffer
  1684. that have been changed along."
  1685. (interactive)
  1686. (or org-agenda-allow-remote-undo
  1687. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1688. (if (not (eq this-command last-command))
  1689. (setq org-agenda-undo-has-started-in nil
  1690. org-agenda-pending-undo-list org-agenda-undo-list))
  1691. (if (not org-agenda-pending-undo-list)
  1692. (error "No further undo information"))
  1693. (let* ((entry (pop org-agenda-pending-undo-list))
  1694. buf line cmd rembuf)
  1695. (setq cmd (pop entry) line (pop entry))
  1696. (setq rembuf (nth 2 entry))
  1697. (org-with-remote-undo rembuf
  1698. (while (bufferp (setq buf (pop entry)))
  1699. (if (pop entry)
  1700. (with-current-buffer buf
  1701. (let ((last-undo-buffer buf)
  1702. (inhibit-read-only t))
  1703. (unless (memq buf org-agenda-undo-has-started-in)
  1704. (push buf org-agenda-undo-has-started-in)
  1705. (make-local-variable 'pending-undo-list)
  1706. (undo-start))
  1707. (while (and pending-undo-list
  1708. (listp pending-undo-list)
  1709. (not (car pending-undo-list)))
  1710. (pop pending-undo-list))
  1711. (undo-more 1))))))
  1712. (org-goto-line line)
  1713. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1714. (defun org-verify-change-for-undo (l1 l2)
  1715. "Verify that a real change occurred between the undo lists L1 and L2."
  1716. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1717. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1718. (not (eq l1 l2)))
  1719. ;;; Agenda dispatch
  1720. (defvar org-agenda-restrict nil)
  1721. (defvar org-agenda-restrict-begin (make-marker))
  1722. (defvar org-agenda-restrict-end (make-marker))
  1723. (defvar org-agenda-last-dispatch-buffer nil)
  1724. (defvar org-agenda-overriding-restriction nil)
  1725. ;;;###autoload
  1726. (defun org-agenda (&optional arg keys restriction)
  1727. "Dispatch agenda commands to collect entries to the agenda buffer.
  1728. Prompts for a command to execute. Any prefix arg will be passed
  1729. on to the selected command. The default selections are:
  1730. a Call `org-agenda-list' to display the agenda for current day or week.
  1731. t Call `org-todo-list' to display the global todo list.
  1732. T Call `org-todo-list' to display the global todo list, select only
  1733. entries with a specific TODO keyword (the user gets a prompt).
  1734. m Call `org-tags-view' to display headlines with tags matching
  1735. a condition (the user is prompted for the condition).
  1736. M Like `m', but select only TODO entries, no ordinary headlines.
  1737. L Create a timeline for the current buffer.
  1738. e Export views to associated files.
  1739. s Search entries for keywords.
  1740. / Multi occur across all agenda files and also files listed
  1741. in `org-agenda-text-search-extra-files'.
  1742. < Restrict agenda commands to buffer, subtree, or region.
  1743. Press several times to get the desired effect.
  1744. > Remove a previous restriction.
  1745. # List \"stuck\" projects.
  1746. ! Configure what \"stuck\" means.
  1747. C Configure custom agenda commands.
  1748. More commands can be added by configuring the variable
  1749. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1750. searches can be pre-defined in this way.
  1751. If the current buffer is in Org-mode and visiting a file, you can also
  1752. first press `<' once to indicate that the agenda should be temporarily
  1753. \(until the next use of \\[org-agenda]) restricted to the current file.
  1754. Pressing `<' twice means to restrict to the current subtree or region
  1755. \(if active)."
  1756. (interactive "P")
  1757. (catch 'exit
  1758. (let* ((prefix-descriptions nil)
  1759. (org-agenda-window-setup (if (equal (buffer-name)
  1760. org-agenda-buffer-name)
  1761. 'current-window
  1762. org-agenda-window-setup))
  1763. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1764. (org-agenda-custom-commands
  1765. ;; normalize different versions
  1766. (delq nil
  1767. (mapcar
  1768. (lambda (x)
  1769. (cond ((stringp (cdr x))
  1770. (push x prefix-descriptions)
  1771. nil)
  1772. ((stringp (nth 1 x)) x)
  1773. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1774. (t (cons (car x) (cons "" (cdr x))))))
  1775. org-agenda-custom-commands)))
  1776. (buf (current-buffer))
  1777. (bfn (buffer-file-name (buffer-base-buffer)))
  1778. entry key type match lprops ans)
  1779. ;; Turn off restriction unless there is an overriding one,
  1780. (unless org-agenda-overriding-restriction
  1781. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1782. ;; There is a request to keep the file list in place
  1783. (put 'org-agenda-files 'org-restrict nil))
  1784. (setq org-agenda-restrict nil)
  1785. (move-marker org-agenda-restrict-begin nil)
  1786. (move-marker org-agenda-restrict-end nil))
  1787. ;; Delete old local properties
  1788. (put 'org-agenda-redo-command 'org-lprops nil)
  1789. ;; Remember where this call originated
  1790. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1791. (unless keys
  1792. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1793. keys (car ans)
  1794. restriction (cdr ans)))
  1795. ;; Establish the restriction, if any
  1796. (when (and (not org-agenda-overriding-restriction) restriction)
  1797. (put 'org-agenda-files 'org-restrict (list bfn))
  1798. (cond
  1799. ((eq restriction 'region)
  1800. (setq org-agenda-restrict t)
  1801. (move-marker org-agenda-restrict-begin (region-beginning))
  1802. (move-marker org-agenda-restrict-end (region-end)))
  1803. ((eq restriction 'subtree)
  1804. (save-excursion
  1805. (setq org-agenda-restrict t)
  1806. (org-back-to-heading t)
  1807. (move-marker org-agenda-restrict-begin (point))
  1808. (move-marker org-agenda-restrict-end
  1809. (progn (org-end-of-subtree t)))))))
  1810. ;; For example the todo list should not need it (but does...)
  1811. (cond
  1812. ((setq entry (assoc keys org-agenda-custom-commands))
  1813. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1814. (progn
  1815. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1816. lprops (nth 4 entry))
  1817. (put 'org-agenda-redo-command 'org-lprops lprops)
  1818. (cond
  1819. ((eq type 'agenda)
  1820. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1821. ((eq type 'alltodo)
  1822. (org-let lprops '(org-todo-list current-prefix-arg)))
  1823. ((eq type 'search)
  1824. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1825. ((eq type 'stuck)
  1826. (org-let lprops '(org-agenda-list-stuck-projects
  1827. current-prefix-arg)))
  1828. ((eq type 'tags)
  1829. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1830. ((eq type 'tags-todo)
  1831. (org-let lprops '(org-tags-view '(4) match)))
  1832. ((eq type 'todo)
  1833. (org-let lprops '(org-todo-list match)))
  1834. ((eq type 'tags-tree)
  1835. (org-check-for-org-mode)
  1836. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1837. ((eq type 'todo-tree)
  1838. (org-check-for-org-mode)
  1839. (org-let lprops
  1840. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1841. (regexp-quote match) "\\>"))))
  1842. ((eq type 'occur-tree)
  1843. (org-check-for-org-mode)
  1844. (org-let lprops '(org-occur match)))
  1845. ((functionp type)
  1846. (org-let lprops '(funcall type match)))
  1847. ((fboundp type)
  1848. (org-let lprops '(funcall type match)))
  1849. (t (error "Invalid custom agenda command type %s" type))))
  1850. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1851. ((equal keys "C")
  1852. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1853. (customize-variable 'org-agenda-custom-commands))
  1854. ((equal keys "a") (call-interactively 'org-agenda-list))
  1855. ((equal keys "s") (call-interactively 'org-search-view))
  1856. ((equal keys "t") (call-interactively 'org-todo-list))
  1857. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1858. ((equal keys "m") (call-interactively 'org-tags-view))
  1859. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1860. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1861. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1862. (org-add-hook
  1863. 'post-command-hook
  1864. (lambda ()
  1865. (unless (current-message)
  1866. (let* ((m (org-agenda-get-any-marker))
  1867. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1868. (when note
  1869. (message (concat
  1870. "FLAGGING-NOTE ([?] for more info): "
  1871. (org-add-props
  1872. (replace-regexp-in-string
  1873. "\\\\n" "//"
  1874. (copy-sequence note))
  1875. nil 'face 'org-warning)))))))
  1876. t t))
  1877. ((equal keys "L")
  1878. (unless (org-mode-p)
  1879. (error "This is not an Org-mode file"))
  1880. (unless restriction
  1881. (put 'org-agenda-files 'org-restrict (list bfn))
  1882. (org-call-with-arg 'org-timeline arg)))
  1883. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1884. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1885. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1886. (t (error "Invalid agenda key"))))))
  1887. (defun org-agenda-normalize-custom-commands (cmds)
  1888. (delq nil
  1889. (mapcar
  1890. (lambda (x)
  1891. (cond ((stringp (cdr x)) nil)
  1892. ((stringp (nth 1 x)) x)
  1893. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1894. (t (cons (car x) (cons "" (cdr x))))))
  1895. cmds)))
  1896. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1897. "The user interface for selecting an agenda command."
  1898. (catch 'exit
  1899. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1900. (restrict-ok (and bfn (org-mode-p)))
  1901. (region-p (org-region-active-p))
  1902. (custom org-agenda-custom-commands)
  1903. (selstring "")
  1904. restriction second-time
  1905. c entry key type match prefixes rmheader header-end custom1 desc
  1906. line lines left right n n1)
  1907. (save-window-excursion
  1908. (delete-other-windows)
  1909. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1910. (erase-buffer)
  1911. (insert (eval-when-compile
  1912. (let ((header
  1913. "
  1914. Press key for an agenda command: < Buffer, subtree/region restriction
  1915. -------------------------------- > Remove restriction
  1916. a Agenda for current week or day e Export agenda views
  1917. t List of all TODO entries T Entries with special TODO kwd
  1918. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1919. L Timeline for current buffer # List stuck projects (!=configure)
  1920. s Search for keywords C Configure custom agenda commands
  1921. / Multi-occur ? Find :FLAGGED: entries
  1922. ")
  1923. (start 0))
  1924. (while (string-match
  1925. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1926. header start)
  1927. (setq start (match-end 0))
  1928. (add-text-properties (match-beginning 2) (match-end 2)
  1929. '(face bold) header))
  1930. header)))
  1931. (setq header-end (move-marker (make-marker) (point)))
  1932. (while t
  1933. (setq custom1 custom)
  1934. (when (eq rmheader t)
  1935. (org-goto-line 1)
  1936. (re-search-forward ":" nil t)
  1937. (delete-region (match-end 0) (point-at-eol))
  1938. (forward-char 1)
  1939. (looking-at "-+")
  1940. (delete-region (match-end 0) (point-at-eol))
  1941. (move-marker header-end (match-end 0)))
  1942. (goto-char header-end)
  1943. (delete-region (point) (point-max))
  1944. ;; Produce all the lines that describe custom commands and prefixes
  1945. (setq lines nil)
  1946. (while (setq entry (pop custom1))
  1947. (setq key (car entry) desc (nth 1 entry)
  1948. type (nth 2 entry)
  1949. match (nth 3 entry))
  1950. (if (> (length key) 1)
  1951. (add-to-list 'prefixes (string-to-char key))
  1952. (setq line
  1953. (format
  1954. "%-4s%-14s"
  1955. (org-add-props (copy-sequence key)
  1956. '(face bold))
  1957. (cond
  1958. ((string-match "\\S-" desc) desc)
  1959. ((eq type 'agenda) "Agenda for current week or day")
  1960. ((eq type 'alltodo) "List of all TODO entries")
  1961. ((eq type 'search) "Word search")
  1962. ((eq type 'stuck) "List of stuck projects")
  1963. ((eq type 'todo) "TODO keyword")
  1964. ((eq type 'tags) "Tags query")
  1965. ((eq type 'tags-todo) "Tags (TODO)")
  1966. ((eq type 'tags-tree) "Tags tree")
  1967. ((eq type 'todo-tree) "TODO kwd tree")
  1968. ((eq type 'occur-tree) "Occur tree")
  1969. ((functionp type) (if (symbolp type)
  1970. (symbol-name type)
  1971. "Lambda expression"))
  1972. (t "???"))))
  1973. (if org-agenda-menu-show-matcher
  1974. (setq line
  1975. (concat line ": "
  1976. (cond
  1977. ((stringp match)
  1978. (setq match (copy-sequence match))
  1979. (org-add-props match nil 'face 'org-warning))
  1980. (match
  1981. (format "set of %d commands" (length match)))
  1982. (t ""))))
  1983. (if (org-string-nw-p match)
  1984. (add-text-properties
  1985. 0 (length line) (list 'help-echo
  1986. (concat "Matcher: "match)) line)))
  1987. (push line lines)))
  1988. (setq lines (nreverse lines))
  1989. (when prefixes
  1990. (mapc (lambda (x)
  1991. (push
  1992. (format "%s %s"
  1993. (org-add-props (char-to-string x)
  1994. nil 'face 'bold)
  1995. (or (cdr (assoc (concat selstring
  1996. (char-to-string x))
  1997. prefix-descriptions))
  1998. "Prefix key"))
  1999. lines))
  2000. prefixes))
  2001. ;; Check if we should display in two columns
  2002. (if org-agenda-menu-two-column
  2003. (progn
  2004. (setq n (length lines)
  2005. n1 (+ (/ n 2) (mod n 2))
  2006. right (nthcdr n1 lines)
  2007. left (copy-sequence lines))
  2008. (setcdr (nthcdr (1- n1) left) nil))
  2009. (setq left lines right nil))
  2010. (while left
  2011. (insert "\n" (pop left))
  2012. (when right
  2013. (if (< (current-column) 40)
  2014. (move-to-column 40 t)
  2015. (insert " "))
  2016. (insert (pop right))))
  2017. ;; Make the window the right size
  2018. (goto-char (point-min))
  2019. (if second-time
  2020. (if (not (pos-visible-in-window-p (point-max)))
  2021. (org-fit-window-to-buffer))
  2022. (setq second-time t)
  2023. (org-fit-window-to-buffer))
  2024. ;; Ask for selection
  2025. (message "Press key for agenda command%s:"
  2026. (if (or restrict-ok org-agenda-overriding-restriction)
  2027. (if org-agenda-overriding-restriction
  2028. " (restriction lock active)"
  2029. (if restriction
  2030. (format " (restricted to %s)" restriction)
  2031. " (unrestricted)"))
  2032. ""))
  2033. (setq c (read-char-exclusive))
  2034. (message "")
  2035. (cond
  2036. ((assoc (char-to-string c) custom)
  2037. (setq selstring (concat selstring (char-to-string c)))
  2038. (throw 'exit (cons selstring restriction)))
  2039. ((memq c prefixes)
  2040. (setq selstring (concat selstring (char-to-string c))
  2041. prefixes nil
  2042. rmheader (or rmheader t)
  2043. custom (delq nil (mapcar
  2044. (lambda (x)
  2045. (if (or (= (length (car x)) 1)
  2046. (/= (string-to-char (car x)) c))
  2047. nil
  2048. (cons (substring (car x) 1) (cdr x))))
  2049. custom))))
  2050. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2051. (message "Restriction is only possible in Org-mode buffers")
  2052. (ding) (sit-for 1))
  2053. ((eq c ?1)
  2054. (org-agenda-remove-restriction-lock 'noupdate)
  2055. (setq restriction 'buffer))
  2056. ((eq c ?0)
  2057. (org-agenda-remove-restriction-lock 'noupdate)
  2058. (setq restriction (if region-p 'region 'subtree)))
  2059. ((eq c ?<)
  2060. (org-agenda-remove-restriction-lock 'noupdate)
  2061. (setq restriction
  2062. (cond
  2063. ((eq restriction 'buffer)
  2064. (if region-p 'region 'subtree))
  2065. ((memq restriction '(subtree region))
  2066. nil)
  2067. (t 'buffer))))
  2068. ((eq c ?>)
  2069. (org-agenda-remove-restriction-lock 'noupdate)
  2070. (setq restriction nil))
  2071. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2072. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2073. ((and (> (length selstring) 0) (eq c ?\d))
  2074. (delete-window)
  2075. (org-agenda-get-restriction-and-command prefix-descriptions))
  2076. ((equal c ?q) (error "Abort"))
  2077. (t (error "Invalid key %c" c))))))))
  2078. (defun org-run-agenda-series (name series)
  2079. (org-let (nth 1 series) '(org-prepare-agenda name))
  2080. (let* ((org-agenda-multi t)
  2081. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2082. (cmds (car series))
  2083. (gprops (nth 1 series))
  2084. match ;; The byte compiler incorrectly complains about this. Keep it!
  2085. cmd type lprops)
  2086. (while (setq cmd (pop cmds))
  2087. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2088. (cond
  2089. ((eq type 'agenda)
  2090. (org-let2 gprops lprops
  2091. '(call-interactively 'org-agenda-list)))
  2092. ((eq type 'alltodo)
  2093. (org-let2 gprops lprops
  2094. '(call-interactively 'org-todo-list)))
  2095. ((eq type 'search)
  2096. (org-let2 gprops lprops
  2097. '(org-search-view current-prefix-arg match nil)))
  2098. ((eq type 'stuck)
  2099. (org-let2 gprops lprops
  2100. '(call-interactively 'org-agenda-list-stuck-projects)))
  2101. ((eq type 'tags)
  2102. (org-let2 gprops lprops
  2103. '(org-tags-view current-prefix-arg match)))
  2104. ((eq type 'tags-todo)
  2105. (org-let2 gprops lprops
  2106. '(org-tags-view '(4) match)))
  2107. ((eq type 'todo)
  2108. (org-let2 gprops lprops
  2109. '(org-todo-list match)))
  2110. ((fboundp type)
  2111. (org-let2 gprops lprops
  2112. '(funcall type match)))
  2113. (t (error "Invalid type in command series"))))
  2114. (widen)
  2115. (setq org-agenda-redo-command redo)
  2116. (goto-char (point-min)))
  2117. (org-fit-agenda-window)
  2118. (org-let (nth 1 series) '(org-finalize-agenda)))
  2119. ;;;###autoload
  2120. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2121. "Run an agenda command in batch mode and send the result to STDOUT.
  2122. If CMD-KEY is a string of length 1, it is used as a key in
  2123. `org-agenda-custom-commands' and triggers this command. If it is a
  2124. longer string it is used as a tags/todo match string.
  2125. Parameters are alternating variable names and values that will be bound
  2126. before running the agenda command."
  2127. (let (pars)
  2128. (while parameters
  2129. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2130. (if (> (length cmd-key) 2)
  2131. (eval (list 'let (nreverse pars)
  2132. (list 'org-tags-view nil cmd-key)))
  2133. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2134. (set-buffer org-agenda-buffer-name)
  2135. (princ (org-encode-for-stdout (buffer-string)))))
  2136. ;(defun org-encode-for-stdout (string)
  2137. ; (if (fboundp 'encode-coding-string)
  2138. ; (encode-coding-string string buffer-file-coding-system)
  2139. ; string))
  2140. (defun org-encode-for-stdout (string)
  2141. string)
  2142. (defvar org-agenda-info nil)
  2143. ;;;###autoload
  2144. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2145. "Run an agenda command in batch mode and send the result to STDOUT.
  2146. If CMD-KEY is a string of length 1, it is used as a key in
  2147. `org-agenda-custom-commands' and triggers this command. If it is a
  2148. longer string it is used as a tags/todo match string.
  2149. Parameters are alternating variable names and values that will be bound
  2150. before running the agenda command.
  2151. The output gives a line for each selected agenda item. Each
  2152. item is a list of comma-separated values, like this:
  2153. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2154. category The category of the item
  2155. head The headline, without TODO kwd, TAGS and PRIORITY
  2156. type The type of the agenda entry, can be
  2157. todo selected in TODO match
  2158. tagsmatch selected in tags match
  2159. diary imported from diary
  2160. deadline a deadline on given date
  2161. scheduled scheduled on given date
  2162. timestamp entry has timestamp on given date
  2163. closed entry was closed on given date
  2164. upcoming-deadline warning about deadline
  2165. past-scheduled forwarded scheduled item
  2166. block entry has date block including g. date
  2167. todo The todo keyword, if any
  2168. tags All tags including inherited ones, separated by colons
  2169. date The relevant date, like 2007-2-14
  2170. time The time, like 15:00-16:50
  2171. extra Sting with extra planning info
  2172. priority-l The priority letter if any was given
  2173. priority-n The computed numerical priority
  2174. agenda-day The day in the agenda where this is listed"
  2175. (let (pars)
  2176. (while parameters
  2177. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2178. (push (list 'org-agenda-remove-tags t) pars)
  2179. (if (> (length cmd-key) 2)
  2180. (eval (list 'let (nreverse pars)
  2181. (list 'org-tags-view nil cmd-key)))
  2182. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2183. (set-buffer org-agenda-buffer-name)
  2184. (let* ((lines (org-split-string (buffer-string) "\n"))
  2185. line)
  2186. (while (setq line (pop lines))
  2187. (catch 'next
  2188. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2189. (setq org-agenda-info
  2190. (org-fix-agenda-info (text-properties-at 0 line)))
  2191. (princ
  2192. (org-encode-for-stdout
  2193. (mapconcat 'org-agenda-export-csv-mapper
  2194. '(org-category txt type todo tags date time extra
  2195. priority-letter priority agenda-day)
  2196. ",")))
  2197. (princ "\n"))))))
  2198. (defun org-fix-agenda-info (props)
  2199. "Make sure all properties on an agenda item have a canonical form.
  2200. This ensures the export commands can easily use it."
  2201. (let (tmp re)
  2202. (when (setq tmp (plist-get props 'tags))
  2203. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2204. (when (setq tmp (plist-get props 'date))
  2205. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2206. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2207. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2208. (setq tmp (calendar-date-string tmp)))
  2209. (setq props (plist-put props 'date tmp)))
  2210. (when (setq tmp (plist-get props 'day))
  2211. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2212. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2213. (setq tmp (calendar-date-string tmp)))
  2214. (setq props (plist-put props 'day tmp))
  2215. (setq props (plist-put props 'agenda-day tmp)))
  2216. (when (setq tmp (plist-get props 'txt))
  2217. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2218. (plist-put props 'priority-letter (match-string 1 tmp))
  2219. (setq tmp (replace-match "" t t tmp)))
  2220. (when (and (setq re (plist-get props 'org-todo-regexp))
  2221. (setq re (concat "\\`\\.*" re " ?"))
  2222. (string-match re tmp))
  2223. (plist-put props 'todo (match-string 1 tmp))
  2224. (setq tmp (replace-match "" t t tmp)))
  2225. (plist-put props 'txt tmp)))
  2226. props)
  2227. (defun org-agenda-export-csv-mapper (prop)
  2228. (let ((res (plist-get org-agenda-info prop)))
  2229. (setq res
  2230. (cond
  2231. ((not res) "")
  2232. ((stringp res) res)
  2233. (t (prin1-to-string res))))
  2234. (while (string-match "," res)
  2235. (setq res (replace-match ";" t t res)))
  2236. (org-trim res)))
  2237. ;;;###autoload
  2238. (defun org-store-agenda-views (&rest parameters)
  2239. (interactive)
  2240. (eval (list 'org-batch-store-agenda-views)))
  2241. ;; FIXME, why is this a macro?????
  2242. ;;;###autoload
  2243. (defmacro org-batch-store-agenda-views (&rest parameters)
  2244. "Run all custom agenda commands that have a file argument."
  2245. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2246. (pop-up-frames nil)
  2247. (dir default-directory)
  2248. pars cmd thiscmdkey files opts cmd-or-set)
  2249. (while parameters
  2250. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2251. (setq pars (reverse pars))
  2252. (save-window-excursion
  2253. (while cmds
  2254. (setq cmd (pop cmds)
  2255. thiscmdkey (car cmd)
  2256. cmd-or-set (nth 2 cmd)
  2257. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2258. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2259. (if (stringp files) (setq files (list files)))
  2260. (when files
  2261. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2262. (list 'org-agenda nil thiscmdkey)))
  2263. (set-buffer org-agenda-buffer-name)
  2264. (while files
  2265. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2266. (list 'org-write-agenda
  2267. (expand-file-name (pop files) dir) nil t))))
  2268. (and (get-buffer org-agenda-buffer-name)
  2269. (kill-buffer org-agenda-buffer-name)))))))
  2270. (defun org-agenda-mark-header-line (pos)
  2271. "Mark the line at POS as an agenda structure header."
  2272. (save-excursion
  2273. (goto-char pos)
  2274. (put-text-property (point-at-bol) (point-at-eol)
  2275. 'org-agenda-structural-header t)
  2276. (when org-agenda-title-append
  2277. (put-text-property (point-at-bol) (point-at-eol)
  2278. 'org-agenda-title-append org-agenda-title-append))))
  2279. (defvar org-mobile-creating-agendas)
  2280. (defun org-write-agenda (file &optional open nosettings)
  2281. "Write the current buffer (an agenda view) as a file.
  2282. Depending on the extension of the file name, plain text (.txt),
  2283. HTML (.html or .htm) or Postscript (.ps) is produced.
  2284. If the extension is .ics, run icalendar export over all files used
  2285. to construct the agenda and limit the export to entries listed in the
  2286. agenda now.
  2287. With prefix argument OPEN, open the new file immediately.
  2288. If NOSETTINGS is given, do not scope the settings of
  2289. `org-agenda-exporter-settings' into the export commands. This is used when
  2290. the settings have already been scoped and we do not wish to overrule other,
  2291. higher priority settings."
  2292. (interactive "FWrite agenda to file: \nP")
  2293. (if (not (file-writable-p file))
  2294. (error "Cannot write agenda to file %s" file))
  2295. (org-let (if nosettings nil org-agenda-exporter-settings)
  2296. '(save-excursion
  2297. (save-window-excursion
  2298. (org-agenda-mark-filtered-text)
  2299. (let ((bs (copy-sequence (buffer-string))) beg)
  2300. (org-agenda-unmark-filtered-text)
  2301. (with-temp-buffer
  2302. (rename-buffer "Agenda View" t)
  2303. (set-buffer-modified-p nil)
  2304. (insert bs)
  2305. (org-agenda-remove-marked-text 'org-filtered)
  2306. (while (setq beg (text-property-any (point-min) (point-max)
  2307. 'org-filtered t))
  2308. (delete-region
  2309. beg (or (next-single-property-change beg 'org-filtered)
  2310. (point-max))))
  2311. (run-hooks 'org-agenda-before-write-hook)
  2312. (cond
  2313. ((org-bound-and-true-p org-mobile-creating-agendas)
  2314. (org-mobile-write-agenda-for-mobile file))
  2315. ((string-match "\\.html?\\'" file)
  2316. (require 'htmlize)
  2317. (set-buffer (htmlize-buffer (current-buffer)))
  2318. (when (and org-agenda-export-html-style
  2319. (string-match "<style>" org-agenda-export-html-style))
  2320. ;; replace <style> section with org-agenda-export-html-style
  2321. (goto-char (point-min))
  2322. (kill-region (- (search-forward "<style") 6)
  2323. (search-forward "</style>"))
  2324. (insert org-agenda-export-html-style))
  2325. (write-file file)
  2326. (kill-buffer (current-buffer))
  2327. (message "HTML written to %s" file))
  2328. ((string-match "\\.ps\\'" file)
  2329. (require 'ps-print)
  2330. (ps-print-buffer-with-faces file)
  2331. (message "Postscript written to %s" file))
  2332. ((string-match "\\.pdf\\'" file)
  2333. (require 'ps-print)
  2334. (ps-print-buffer-with-faces
  2335. (concat (file-name-sans-extension file) ".ps"))
  2336. (call-process "ps2pdf" nil nil nil
  2337. (expand-file-name
  2338. (concat (file-name-sans-extension file) ".ps"))
  2339. (expand-file-name file))
  2340. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2341. (message "PDF written to %s" file))
  2342. ((string-match "\\.ics\\'" file)
  2343. (require 'org-icalendar)
  2344. (let ((org-agenda-marker-table
  2345. (org-create-marker-find-array
  2346. (org-agenda-collect-markers)))
  2347. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2348. (org-combined-agenda-icalendar-file file))
  2349. (apply 'org-export-icalendar 'combine
  2350. (org-agenda-files nil 'ifmode))))
  2351. (t
  2352. (let ((bs (buffer-string)))
  2353. (find-file file)
  2354. (erase-buffer)
  2355. (insert bs)
  2356. (save-buffer 0)
  2357. (kill-buffer (current-buffer))
  2358. (message "Plain text written to %s" file))))))))
  2359. (set-buffer org-agenda-buffer-name))
  2360. (when open (org-open-file file)))
  2361. (defvar org-agenda-filter-overlays nil)
  2362. (defun org-agenda-mark-filtered-text ()
  2363. "Mark all text hidden by filtering with a text property."
  2364. (let ((inhibit-read-only t))
  2365. (mapc
  2366. (lambda (o)
  2367. (when (equal (overlay-buffer o) (current-buffer))
  2368. (put-text-property
  2369. (overlay-start o) (overlay-end o)
  2370. 'org-filtered t)))
  2371. org-agenda-filter-overlays)))
  2372. (defun org-agenda-unmark-filtered-text ()
  2373. "Remove the filtering text property."
  2374. (let ((inhibit-read-only t))
  2375. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2376. (defun org-agenda-remove-marked-text (property &optional value)
  2377. "Delete all text marked with VALUE of PROPERTY.
  2378. VALUE defaults to t."
  2379. (let (beg)
  2380. (setq value (or value t))
  2381. (while (setq beg (text-property-any (point-min) (point-max)
  2382. property value))
  2383. (delete-region
  2384. beg (or (next-single-property-change beg 'org-filtered)
  2385. (point-max))))))
  2386. (defun org-agenda-add-entry-text ()
  2387. "Add entry text to agenda lines.
  2388. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2389. entry text following headings shown in the agenda.
  2390. Drawers will be excluded, also the line with scheduling/deadline info."
  2391. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2392. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2393. (let (m txt)
  2394. (goto-char (point-min))
  2395. (while (not (eobp))
  2396. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2397. (beginning-of-line 2)
  2398. (setq txt (org-agenda-get-some-entry-text
  2399. m org-agenda-add-entry-text-maxlines " > "))
  2400. (end-of-line 1)
  2401. (if (string-match "\\S-" txt)
  2402. (insert "\n" txt)
  2403. (or (eobp) (forward-char 1))))))))
  2404. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2405. &rest keep)
  2406. "Extract entry text from MARKER, at most N-LINES lines.
  2407. This will ignore drawers etc, just get the text.
  2408. If INDENT is given, prefix every line with this string. If KEEP is
  2409. given, it is a list of symbols, defining stuff that should not be
  2410. removed from the entry content. Currently only `planning' is allowed here."
  2411. (let (txt drawer-re kwd-time-re ind)
  2412. (save-excursion
  2413. (with-current-buffer (marker-buffer marker)
  2414. (if (not (org-mode-p))
  2415. (setq txt "")
  2416. (save-excursion
  2417. (save-restriction
  2418. (widen)
  2419. (goto-char marker)
  2420. (end-of-line 1)
  2421. (setq txt (buffer-substring
  2422. (min (1+ (point)) (point-max))
  2423. (progn (outline-next-heading) (point)))
  2424. drawer-re org-drawer-regexp
  2425. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2426. ".*\n?"))
  2427. (with-temp-buffer
  2428. (insert txt)
  2429. (when org-agenda-add-entry-text-descriptive-links
  2430. (goto-char (point-min))
  2431. (while (org-activate-bracket-links (point-max))
  2432. (add-text-properties (match-beginning 0) (match-end 0)
  2433. '(face org-link))))
  2434. (goto-char (point-min))
  2435. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2436. (set-text-properties (match-beginning 0) (match-end 0)
  2437. nil))
  2438. (goto-char (point-min))
  2439. (while (re-search-forward drawer-re nil t)
  2440. (delete-region
  2441. (match-beginning 0)
  2442. (progn (re-search-forward
  2443. "^[ \t]*:END:.*\n?" nil 'move)
  2444. (point))))
  2445. (unless (member 'planning keep)
  2446. (goto-char (point-min))
  2447. (while (re-search-forward kwd-time-re nil t)
  2448. (replace-match "")))
  2449. (goto-char (point-min))
  2450. (when org-agenda-entry-text-exclude-regexps
  2451. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2452. (while (setq re (pop re-list))
  2453. (goto-char (point-min))
  2454. (while (re-search-forward re nil t)
  2455. (replace-match "")))))
  2456. (goto-char (point-max))
  2457. (skip-chars-backward " \t\n")
  2458. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2459. ;; find and remove min common indentation
  2460. (goto-char (point-min))
  2461. (untabify (point-min) (point-max))
  2462. (setq ind (org-get-indentation))
  2463. (while (not (eobp))
  2464. (unless (looking-at "[ \t]*$")
  2465. (setq ind (min ind (org-get-indentation))))
  2466. (beginning-of-line 2))
  2467. (goto-char (point-min))
  2468. (while (not (eobp))
  2469. (unless (looking-at "[ \t]*$")
  2470. (move-to-column ind)
  2471. (delete-region (point-at-bol) (point)))
  2472. (beginning-of-line 2))
  2473. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2474. (goto-char (point-min))
  2475. (when indent
  2476. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2477. (replace-match indent t t)))
  2478. (goto-char (point-min))
  2479. (while (looking-at "[ \t]*\n") (replace-match ""))
  2480. (goto-char (point-max))
  2481. (when (> (org-current-line)
  2482. n-lines)
  2483. (org-goto-line (1+ n-lines))
  2484. (backward-char 1))
  2485. (setq txt (buffer-substring (point-min) (point)))))))))
  2486. txt))
  2487. (defun org-agenda-collect-markers ()
  2488. "Collect the markers pointing to entries in the agenda buffer."
  2489. (let (m markers)
  2490. (save-excursion
  2491. (goto-char (point-min))
  2492. (while (not (eobp))
  2493. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2494. (org-get-at-bol 'org-marker)))
  2495. (push m markers))
  2496. (beginning-of-line 2)))
  2497. (nreverse markers)))
  2498. (defun org-create-marker-find-array (marker-list)
  2499. "Create a alist of files names with all marker positions in that file."
  2500. (let (f tbl m a p)
  2501. (while (setq m (pop marker-list))
  2502. (setq p (marker-position m)
  2503. f (buffer-file-name (or (buffer-base-buffer
  2504. (marker-buffer m))
  2505. (marker-buffer m))))
  2506. (if (setq a (assoc f tbl))
  2507. (push (marker-position m) (cdr a))
  2508. (push (list f p) tbl)))
  2509. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2510. tbl)))
  2511. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2512. (defun org-check-agenda-marker-table ()
  2513. "Check of the current entry is on the marker list."
  2514. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2515. a)
  2516. (and (setq a (assoc file org-agenda-marker-table))
  2517. (save-match-data
  2518. (save-excursion
  2519. (org-back-to-heading t)
  2520. (member (point) (cdr a)))))))
  2521. (defun org-check-for-org-mode ()
  2522. "Make sure current buffer is in org-mode. Error if not."
  2523. (or (org-mode-p)
  2524. (error "Cannot execute org-mode agenda command on buffer in %s"
  2525. major-mode)))
  2526. (defun org-fit-agenda-window ()
  2527. "Fit the window to the buffer size."
  2528. (and (memq org-agenda-window-setup '(reorganize-frame))
  2529. (fboundp 'fit-window-to-buffer)
  2530. (org-fit-window-to-buffer
  2531. nil
  2532. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2533. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2534. ;;; Agenda prepare and finalize
  2535. (defvar org-agenda-multi nil) ; dynamically scoped
  2536. (defvar org-agenda-buffer-name "*Org Agenda*")
  2537. (defvar org-pre-agenda-window-conf nil)
  2538. (defvar org-agenda-columns-active nil)
  2539. (defvar org-agenda-name nil)
  2540. (defvar org-agenda-filter nil)
  2541. (defvar org-agenda-filter-preset nil
  2542. "A preset of the tags filter used for secondary agenda filtering.
  2543. This must be a list of strings, each string must be a single tag preceded
  2544. by \"+\" or \"-\".
  2545. This variable should not be set directly, but agenda custom commands can
  2546. bind it in the options section. The preset filter is a global property of
  2547. the entire agenda view. In a block agenda, it will not work reliably to
  2548. define a filter for one of the individual blocks. You need to set it in
  2549. the global options and expect it to be applied to the entire view.")
  2550. (defun org-prepare-agenda (&optional name)
  2551. (setq org-todo-keywords-for-agenda nil)
  2552. (setq org-done-keywords-for-agenda nil)
  2553. (setq org-drawers-for-agenda nil)
  2554. (unless org-agenda-persistent-filter
  2555. (setq org-agenda-filter nil))
  2556. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2557. (if org-agenda-multi
  2558. (progn
  2559. (setq buffer-read-only nil)
  2560. (goto-char (point-max))
  2561. (unless (or (bobp) org-agenda-compact-blocks)
  2562. (insert "\n"
  2563. (if (stringp org-agenda-block-separator)
  2564. org-agenda-block-separator
  2565. (make-string (window-width) org-agenda-block-separator))
  2566. "\n"))
  2567. (narrow-to-region (point) (point-max)))
  2568. (org-agenda-reset-markers)
  2569. (setq org-agenda-contributing-files nil)
  2570. (setq org-agenda-columns-active nil)
  2571. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2572. (setq org-todo-keywords-for-agenda
  2573. (org-uniquify org-todo-keywords-for-agenda))
  2574. (setq org-done-keywords-for-agenda
  2575. (org-uniquify org-done-keywords-for-agenda))
  2576. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2577. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2578. (awin (get-buffer-window abuf)))
  2579. (cond
  2580. ((equal (current-buffer) abuf) nil)
  2581. (awin (select-window awin))
  2582. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2583. ((equal org-agenda-window-setup 'current-window)
  2584. (switch-to-buffer abuf))
  2585. ((equal org-agenda-window-setup 'other-window)
  2586. (org-switch-to-buffer-other-window abuf))
  2587. ((equal org-agenda-window-setup 'other-frame)
  2588. (switch-to-buffer-other-frame abuf))
  2589. ((equal org-agenda-window-setup 'reorganize-frame)
  2590. (delete-other-windows)
  2591. (org-switch-to-buffer-other-window abuf))))
  2592. (setq buffer-read-only nil)
  2593. (let ((inhibit-read-only t)) (erase-buffer))
  2594. (org-agenda-mode)
  2595. (and name (not org-agenda-name)
  2596. (org-set-local 'org-agenda-name name)))
  2597. (setq buffer-read-only nil))
  2598. (defun org-finalize-agenda ()
  2599. "Finishing touch for the agenda buffer, called just before displaying it."
  2600. (unless org-agenda-multi
  2601. (save-excursion
  2602. (let ((inhibit-read-only t))
  2603. (goto-char (point-min))
  2604. (while (org-activate-bracket-links (point-max))
  2605. (add-text-properties (match-beginning 0) (match-end 0)
  2606. '(face org-link)))
  2607. (org-agenda-align-tags)
  2608. (unless org-agenda-with-colors
  2609. (remove-text-properties (point-min) (point-max) '(face nil))))
  2610. (if (and (boundp 'org-agenda-overriding-columns-format)
  2611. org-agenda-overriding-columns-format)
  2612. (org-set-local 'org-agenda-overriding-columns-format
  2613. org-agenda-overriding-columns-format))
  2614. (if (and (boundp 'org-agenda-view-columns-initially)
  2615. org-agenda-view-columns-initially)
  2616. (org-agenda-columns))
  2617. (when org-agenda-fontify-priorities
  2618. (org-agenda-fontify-priorities))
  2619. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2620. (org-agenda-dim-blocked-tasks))
  2621. (org-agenda-mark-clocking-task)
  2622. (when org-agenda-entry-text-mode
  2623. (org-agenda-entry-text-hide)
  2624. (org-agenda-entry-text-show))
  2625. (if (functionp 'org-habit-insert-consistency-graphs)
  2626. (org-habit-insert-consistency-graphs))
  2627. (run-hooks 'org-finalize-agenda-hook)
  2628. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2629. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2630. (org-agenda-filter-apply org-agenda-filter))
  2631. )))
  2632. (defun org-agenda-mark-clocking-task ()
  2633. "Mark the current clock entry in the agenda if it is present."
  2634. (mapc (lambda (o)
  2635. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2636. (delete-overlay o)))
  2637. (overlays-in (point-min) (point-max)))
  2638. (when (marker-buffer org-clock-hd-marker)
  2639. (save-excursion
  2640. (goto-char (point-min))
  2641. (let (s ov)
  2642. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2643. (goto-char s)
  2644. (when (equal (org-get-at-bol 'org-hd-marker)
  2645. org-clock-hd-marker)
  2646. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2647. (overlay-put ov 'type 'org-agenda-clocking)
  2648. (overlay-put ov 'face 'org-agenda-clocking)
  2649. (overlay-put ov 'help-echo
  2650. "The clock is running in this item")))))))
  2651. (defun org-agenda-fontify-priorities ()
  2652. "Make highest priority lines bold, and lowest italic."
  2653. (interactive)
  2654. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2655. (delete-overlay o)))
  2656. (overlays-in (point-min) (point-max)))
  2657. (save-excursion
  2658. (let ((inhibit-read-only t)
  2659. b e p ov h l)
  2660. (goto-char (point-min))
  2661. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2662. (setq h (or (get-char-property (point) 'org-highest-priority)
  2663. org-highest-priority)
  2664. l (or (get-char-property (point) 'org-lowest-priority)
  2665. org-lowest-priority)
  2666. p (string-to-char (match-string 1))
  2667. b (match-beginning 0)
  2668. e (if (eq org-agenda-fontify-priorities 'cookies)
  2669. (match-end 0)
  2670. (point-at-eol))
  2671. ov (make-overlay b e))
  2672. (overlay-put
  2673. ov 'face
  2674. (cond ((org-face-from-face-or-color
  2675. 'priority nil
  2676. (cdr (assoc p org-priority-faces))))
  2677. ((and (listp org-agenda-fontify-priorities)
  2678. (org-face-from-face-or-color
  2679. 'priority nil
  2680. (cdr (assoc p org-agenda-fontify-priorities)))))
  2681. ((equal p l) 'italic)
  2682. ((equal p h) 'bold)))
  2683. (overlay-put ov 'org-type 'org-priority)))))
  2684. (defun org-agenda-dim-blocked-tasks ()
  2685. "Dim currently blocked TODO's in the agenda display."
  2686. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2687. (delete-overlay o)))
  2688. (overlays-in (point-min) (point-max)))
  2689. (save-excursion
  2690. (let ((inhibit-read-only t)
  2691. (org-depend-tag-blocked nil)
  2692. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2693. org-blocked-by-checkboxes
  2694. invis1 b e p ov h l)
  2695. (goto-char (point-min))
  2696. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2697. (and pos (goto-char (1+ pos))))
  2698. (setq org-blocked-by-checkboxes nil invis1 invis)
  2699. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2700. (when (and marker
  2701. (not (with-current-buffer (marker-buffer marker)
  2702. (save-excursion
  2703. (goto-char marker)
  2704. (if (org-entry-get nil "NOBLOCKING")
  2705. t ;; Never block this entry
  2706. (run-hook-with-args-until-failure
  2707. 'org-blocker-hook
  2708. (list :type 'todo-state-change
  2709. :position marker
  2710. :from 'todo
  2711. :to 'done)))))))
  2712. (if org-blocked-by-checkboxes (setq invis1 nil))
  2713. (setq b (if invis1
  2714. (max (point-min) (1- (point-at-bol)))
  2715. (point-at-bol))
  2716. e (point-at-eol)
  2717. ov (make-overlay b e))
  2718. (if invis1
  2719. (overlay-put ov 'invisible t)
  2720. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2721. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2722. (defvar org-agenda-skip-function nil
  2723. "Function to be called at each match during agenda construction.
  2724. If this function returns nil, the current match should not be skipped.
  2725. Otherwise, the function must return a position from where the search
  2726. should be continued.
  2727. This may also be a Lisp form, it will be evaluated.
  2728. Never set this variable using `setq' or so, because then it will apply
  2729. to all future agenda commands. Instead, bind it with `let' to scope
  2730. it dynamically into the agenda-constructing command. A good way to set
  2731. it is through options in `org-agenda-custom-commands'.")
  2732. (defun org-agenda-skip ()
  2733. "Throw to `:skip' in places that should be skipped.
  2734. Also moves point to the end of the skipped region, so that search can
  2735. continue from there."
  2736. (let ((p (point-at-bol)) to fp)
  2737. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2738. (get-text-property p :org-archived)
  2739. (org-end-of-subtree t)
  2740. (throw :skip t))
  2741. (and org-agenda-skip-comment-trees
  2742. (get-text-property p :org-comment)
  2743. (org-end-of-subtree t)
  2744. (throw :skip t))
  2745. (if (equal (char-after p) ?#) (throw :skip t))
  2746. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2747. (consp org-agenda-skip-function))
  2748. (setq to (save-excursion
  2749. (save-match-data
  2750. (if fp
  2751. (funcall org-agenda-skip-function)
  2752. (eval org-agenda-skip-function))))))
  2753. (goto-char to)
  2754. (throw :skip t))))
  2755. (defvar org-agenda-markers nil
  2756. "List of all currently active markers created by `org-agenda'.")
  2757. (defvar org-agenda-last-marker-time (org-float-time)
  2758. "Creation time of the last agenda marker.")
  2759. (defun org-agenda-new-marker (&optional pos)
  2760. "Return a new agenda marker.
  2761. Org-mode keeps a list of these markers and resets them when they are
  2762. no longer in use."
  2763. (let ((m (copy-marker (or pos (point)))))
  2764. (setq org-agenda-last-marker-time (org-float-time))
  2765. (push m org-agenda-markers)
  2766. m))
  2767. (defun org-agenda-reset-markers ()
  2768. "Reset markers created by `org-agenda'."
  2769. (while org-agenda-markers
  2770. (move-marker (pop org-agenda-markers) nil)))
  2771. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2772. "Save relative positions of markers in region."
  2773. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2774. org-agenda-markers))
  2775. ;;; Entry text mode
  2776. (defun org-agenda-entry-text-show-here ()
  2777. "Add some text from the entry as context to the current line."
  2778. (let (m txt o)
  2779. (setq m (org-get-at-bol 'org-hd-marker))
  2780. (unless (marker-buffer m)
  2781. (error "No marker points to an entry here"))
  2782. (setq txt (concat "\n" (org-no-properties
  2783. (org-agenda-get-some-entry-text
  2784. m org-agenda-entry-text-maxlines " > "))))
  2785. (when (string-match "\\S-" txt)
  2786. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2787. (overlay-put o 'evaporate t)
  2788. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2789. (overlay-put o 'after-string txt))))
  2790. (defun org-agenda-entry-text-show ()
  2791. "Add entry context for all agenda lines."
  2792. (interactive)
  2793. (save-excursion
  2794. (goto-char (point-max))
  2795. (beginning-of-line 1)
  2796. (while (not (bobp))
  2797. (when (org-get-at-bol 'org-hd-marker)
  2798. (org-agenda-entry-text-show-here))
  2799. (beginning-of-line 0))))
  2800. (defun org-agenda-entry-text-hide ()
  2801. "Remove any shown entry context."
  2802. (delq nil
  2803. (mapcar (lambda (o)
  2804. (if (eq (overlay-get o 'org-overlay-type)
  2805. 'agenda-entry-content)
  2806. (progn (delete-overlay o) t)))
  2807. (overlays-in (point-min) (point-max)))))
  2808. ;;; Agenda timeline
  2809. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2810. (defun org-timeline (&optional include-all)
  2811. "Show a time-sorted view of the entries in the current org file.
  2812. Only entries with a time stamp of today or later will be listed. With
  2813. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2814. under the current date.
  2815. If the buffer contains an active region, only check the region for
  2816. dates."
  2817. (interactive "P")
  2818. (org-compile-prefix-format 'timeline)
  2819. (org-set-sorting-strategy 'timeline)
  2820. (let* ((dopast t)
  2821. (dotodo include-all)
  2822. (doclosed org-agenda-show-log)
  2823. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2824. (current-buffer))))
  2825. (date (calendar-current-date))
  2826. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2827. (end (if (org-region-active-p) (region-end) (point-max)))
  2828. (day-numbers (org-get-all-dates beg end 'no-ranges
  2829. t doclosed ; always include today
  2830. org-timeline-show-empty-dates))
  2831. (org-deadline-warning-days 0)
  2832. (org-agenda-only-exact-dates t)
  2833. (today (time-to-days (current-time)))
  2834. (past t)
  2835. args
  2836. s e rtn d emptyp wd)
  2837. (setq org-agenda-redo-command
  2838. (list 'progn
  2839. (list 'org-switch-to-buffer-other-window (current-buffer))
  2840. (list 'org-timeline (list 'quote include-all))))
  2841. (if (not dopast)
  2842. ;; Remove past dates from the list of dates.
  2843. (setq day-numbers (delq nil (mapcar (lambda(x)
  2844. (if (>= x today) x nil))
  2845. day-numbers))))
  2846. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2847. (if doclosed (push :closed args))
  2848. (push :timestamp args)
  2849. (push :deadline args)
  2850. (push :scheduled args)
  2851. (push :sexp args)
  2852. (if dotodo (push :todo args))
  2853. (insert "Timeline of file " entry "\n")
  2854. (add-text-properties (point-min) (point)
  2855. (list 'face 'org-agenda-structure))
  2856. (org-agenda-mark-header-line (point-min))
  2857. (while (setq d (pop day-numbers))
  2858. (if (and (listp d) (eq (car d) :omitted))
  2859. (progn
  2860. (setq s (point))
  2861. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2862. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2863. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2864. (if (and (>= d today)
  2865. dopast
  2866. past)
  2867. (progn
  2868. (setq past nil)
  2869. (insert (make-string 79 ?-) "\n")))
  2870. (setq date (calendar-gregorian-from-absolute d)
  2871. wd (calendar-day-of-week date))
  2872. (setq s (point))
  2873. (setq rtn (and (not emptyp)
  2874. (apply 'org-agenda-get-day-entries entry
  2875. date args)))
  2876. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2877. (progn
  2878. (insert
  2879. (if (stringp org-agenda-format-date)
  2880. (format-time-string org-agenda-format-date
  2881. (org-time-from-absolute date))
  2882. (funcall org-agenda-format-date date))
  2883. "\n")
  2884. (put-text-property s (1- (point)) 'face
  2885. (if (member wd org-agenda-weekend-days)
  2886. 'org-agenda-date-weekend
  2887. 'org-agenda-date))
  2888. (put-text-property s (1- (point)) 'org-date-line t)
  2889. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2890. (if (equal d today)
  2891. (put-text-property s (1- (point)) 'org-today t))
  2892. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2893. (put-text-property s (1- (point)) 'day d)))))
  2894. (goto-char (point-min))
  2895. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2896. (point-min)))
  2897. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2898. (org-finalize-agenda)
  2899. (setq buffer-read-only t)))
  2900. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2901. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2902. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2903. not every single day in the range. If FORCE-TODAY is non-nil, make
  2904. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2905. inactive time stamps (those in square brackets) are included.
  2906. When EMPTY is non-nil, also include days without any entries."
  2907. (let ((re (concat
  2908. (if pre-re pre-re "")
  2909. (if inactive org-ts-regexp-both org-ts-regexp)))
  2910. dates dates1 date day day1 day2 ts1 ts2)
  2911. (if force-today
  2912. (setq dates (list (time-to-days (current-time)))))
  2913. (save-excursion
  2914. (goto-char beg)
  2915. (while (re-search-forward re end t)
  2916. (setq day (time-to-days (org-time-string-to-time
  2917. (substring (match-string 1) 0 10))))
  2918. (or (memq day dates) (push day dates)))
  2919. (unless no-ranges
  2920. (goto-char beg)
  2921. (while (re-search-forward org-tr-regexp end t)
  2922. (setq ts1 (substring (match-string 1) 0 10)
  2923. ts2 (substring (match-string 2) 0 10)
  2924. day1 (time-to-days (org-time-string-to-time ts1))
  2925. day2 (time-to-days (org-time-string-to-time ts2)))
  2926. (while (< (setq day1 (1+ day1)) day2)
  2927. (or (memq day1 dates) (push day1 dates)))))
  2928. (setq dates (sort dates '<))
  2929. (when empty
  2930. (while (setq day (pop dates))
  2931. (setq day2 (car dates))
  2932. (push day dates1)
  2933. (when (and day2 empty)
  2934. (if (or (eq empty t)
  2935. (and (numberp empty) (<= (- day2 day) empty)))
  2936. (while (< (setq day (1+ day)) day2)
  2937. (push (list day) dates1))
  2938. (push (cons :omitted (- day2 day)) dates1))))
  2939. (setq dates (nreverse dates1)))
  2940. dates)))
  2941. ;;; Agenda Daily/Weekly
  2942. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2943. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2944. "Custom commands can set this variable in the options section.")
  2945. (defvar org-agenda-last-arguments nil
  2946. "The arguments of the previous call to `org-agenda'.")
  2947. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2948. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2949. (defvar org-include-all-loc nil) ; local variable
  2950. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  2951. "List of types searched for when creating the daily/weekly agenda.
  2952. This variable is a list of symbols that controls the types of
  2953. items that appear in the daily/weekly agenda. Allowed symbols in this
  2954. list are are
  2955. :timestamp List items containing a date stamp or date range matching
  2956. the selected date. This includes sexp entries in
  2957. angular brackets.
  2958. :sexp List entries resulting from plain diary-like sexps.
  2959. :deadline List deadline due on that date. When the date is today,
  2960. also list any deadlines past due, or due within
  2961. `org-deadline-warning-days'. `:deadline' must appear before
  2962. `:scheduled' if the setting of
  2963. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  2964. any effect.
  2965. :scheduled List all items which are scheduled for the given date.
  2966. The diary for *today* also contains items which were
  2967. scheduled earlier and are not yet marked DONE.
  2968. By default, all four types are turned on.
  2969. Never set this variable globally using `setq', because then it
  2970. will apply to all future agenda commands. Instead, bind it with
  2971. `let' to scope it dynamically into the the agenda-constructing
  2972. command. A good way to set it is through options in
  2973. `org-agenda-custom-commands'. For a more flexible (though
  2974. somewhat less efficient) way of determining what is included in
  2975. the daily/weekly agenda, see `org-agenda-skip-function'.")
  2976. ;;;###autoload
  2977. (defun org-agenda-list (&optional include-all start-day ndays)
  2978. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2979. The view will be for the current day or week, but from the overview buffer
  2980. you will be able to go to other days/weeks.
  2981. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2982. all unfinished TODO items will also be shown, before the agenda.
  2983. This feature is considered obsolete, please use the TODO list or a block
  2984. agenda instead.
  2985. With a numeric prefix argument in an interactive call, the agenda will
  2986. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2987. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2988. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2989. given in `org-agenda-start-on-weekday'."
  2990. (interactive "P")
  2991. (if (and (integerp include-all) (> include-all 0))
  2992. (setq ndays include-all include-all nil))
  2993. (setq ndays (or ndays org-agenda-ndays)
  2994. start-day (or start-day org-agenda-start-day))
  2995. (if org-agenda-overriding-arguments
  2996. (setq include-all (car org-agenda-overriding-arguments)
  2997. start-day (nth 1 org-agenda-overriding-arguments)
  2998. ndays (nth 2 org-agenda-overriding-arguments)))
  2999. (if (stringp start-day)
  3000. ;; Convert to an absolute day number
  3001. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3002. (setq org-agenda-last-arguments (list include-all start-day ndays))
  3003. (org-compile-prefix-format 'agenda)
  3004. (org-set-sorting-strategy 'agenda)
  3005. (let* ((org-agenda-start-on-weekday
  3006. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  3007. org-agenda-start-on-weekday nil))
  3008. (thefiles (org-agenda-files nil 'ifmode))
  3009. (files thefiles)
  3010. (today (time-to-days
  3011. (time-subtract (current-time)
  3012. (list 0 (* 3600 org-extend-today-until) 0))))
  3013. (sd (or start-day today))
  3014. (start (if (or (null org-agenda-start-on-weekday)
  3015. (< org-agenda-ndays 7))
  3016. sd
  3017. (let* ((nt (calendar-day-of-week
  3018. (calendar-gregorian-from-absolute sd)))
  3019. (n1 org-agenda-start-on-weekday)
  3020. (d (- nt n1)))
  3021. (- sd (+ (if (< d 0) 7 0) d)))))
  3022. (day-numbers (list start))
  3023. (day-cnt 0)
  3024. (inhibit-redisplay (not debug-on-error))
  3025. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  3026. clocktable-start clocktable-end)
  3027. (setq org-agenda-redo-command
  3028. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3029. ;; Make the list of days
  3030. (setq ndays (or ndays org-agenda-ndays)
  3031. nd ndays)
  3032. (while (> ndays 1)
  3033. (push (1+ (car day-numbers)) day-numbers)
  3034. (setq ndays (1- ndays)))
  3035. (setq day-numbers (nreverse day-numbers))
  3036. (setq clocktable-start (car day-numbers)
  3037. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3038. (org-prepare-agenda "Day/Week")
  3039. (org-set-local 'org-starting-day (car day-numbers))
  3040. (org-set-local 'org-include-all-loc include-all)
  3041. (org-set-local 'org-agenda-span
  3042. (org-agenda-ndays-to-span nd))
  3043. (when (and (or include-all org-agenda-include-all-todo)
  3044. (member today day-numbers))
  3045. (setq files thefiles
  3046. rtnall nil)
  3047. (while (setq file (pop files))
  3048. (catch 'nextfile
  3049. (org-check-agenda-file file)
  3050. (setq date (calendar-gregorian-from-absolute today)
  3051. rtn (org-agenda-get-day-entries
  3052. file date :todo))
  3053. (setq rtnall (append rtnall rtn))))
  3054. (when rtnall
  3055. (insert "All currently open TODO items:\n")
  3056. (add-text-properties (point-min) (1- (point))
  3057. (list 'face 'org-agenda-structure
  3058. 'short-heading "All TODO items"))
  3059. (org-agenda-mark-header-line (point-min))
  3060. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3061. (unless org-agenda-compact-blocks
  3062. (let* ((d1 (car day-numbers))
  3063. (d2 (org-last day-numbers))
  3064. (w1 (org-days-to-iso-week d1))
  3065. (w2 (org-days-to-iso-week d2)))
  3066. (setq s (point))
  3067. (if org-agenda-overriding-header
  3068. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3069. nil 'face 'org-agenda-structure) "\n")
  3070. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3071. "-agenda"
  3072. (if (< (- d2 d1) 350)
  3073. (if (= w1 w2)
  3074. (format " (W%02d)" w1)
  3075. (format " (W%02d-W%02d)" w1 w2))
  3076. "")
  3077. ":\n")))
  3078. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3079. 'org-date-line t))
  3080. (org-agenda-mark-header-line s))
  3081. (while (setq d (pop day-numbers))
  3082. (setq date (calendar-gregorian-from-absolute d)
  3083. wd (calendar-day-of-week date)
  3084. s (point))
  3085. (if (or (setq todayp (= d today))
  3086. (and (not start-pos) (= d sd)))
  3087. (setq start-pos (point))
  3088. (if (and start-pos (not end-pos))
  3089. (setq end-pos (point))))
  3090. (setq files thefiles
  3091. rtnall nil)
  3092. (while (setq file (pop files))
  3093. (catch 'nextfile
  3094. (org-check-agenda-file file)
  3095. (let ((org-agenda-entry-types org-agenda-entry-types))
  3096. (unless org-agenda-include-deadlines
  3097. (setq org-agenda-entry-types
  3098. (delq :deadline org-agenda-entry-types)))
  3099. (cond
  3100. ((eq org-agenda-show-log 'only)
  3101. (setq rtn (org-agenda-get-day-entries
  3102. file date :closed)))
  3103. (org-agenda-show-log
  3104. (setq rtn (apply 'org-agenda-get-day-entries
  3105. file date
  3106. (append '(:closed) org-agenda-entry-types))))
  3107. (t
  3108. (setq rtn (apply 'org-agenda-get-day-entries
  3109. file date
  3110. org-agenda-entry-types)))))
  3111. (setq rtnall (append rtnall rtn))))
  3112. (if org-agenda-include-diary
  3113. (let ((org-agenda-search-headline-for-time t))
  3114. (require 'diary-lib)
  3115. (setq rtn (org-get-entries-from-diary date))
  3116. (setq rtnall (append rtnall rtn))))
  3117. (if (or rtnall org-agenda-show-all-dates)
  3118. (progn
  3119. (setq day-cnt (1+ day-cnt))
  3120. (insert
  3121. (if (stringp org-agenda-format-date)
  3122. (format-time-string org-agenda-format-date
  3123. (org-time-from-absolute date))
  3124. (funcall org-agenda-format-date date))
  3125. "\n")
  3126. (put-text-property s (1- (point)) 'face
  3127. (if (member wd org-agenda-weekend-days)
  3128. 'org-agenda-date-weekend
  3129. 'org-agenda-date))
  3130. (put-text-property s (1- (point)) 'org-date-line t)
  3131. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3132. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3133. (when todayp
  3134. (put-text-property s (1- (point)) 'org-today t)
  3135. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  3136. (if rtnall (insert
  3137. (org-finalize-agenda-entries
  3138. (org-agenda-add-time-grid-maybe
  3139. rtnall nd todayp))
  3140. "\n"))
  3141. (put-text-property s (1- (point)) 'day d)
  3142. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3143. (when (and org-agenda-clockreport-mode clocktable-start)
  3144. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3145. ;; the above line is to ensure the restricted range!
  3146. (p org-agenda-clockreport-parameter-plist)
  3147. tbl)
  3148. (setq p (org-plist-delete p :block))
  3149. (setq p (plist-put p :tstart clocktable-start))
  3150. (setq p (plist-put p :tend clocktable-end))
  3151. (setq p (plist-put p :scope 'agenda))
  3152. (setq tbl (apply 'org-get-clocktable p))
  3153. (insert tbl)))
  3154. (goto-char (point-min))
  3155. (or org-agenda-multi (org-fit-agenda-window))
  3156. (unless (and (pos-visible-in-window-p (point-min))
  3157. (pos-visible-in-window-p (point-max)))
  3158. (goto-char (1- (point-max)))
  3159. (recenter -1)
  3160. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3161. (progn
  3162. (goto-char (or start-pos 1))
  3163. (recenter 1))))
  3164. (goto-char (or start-pos 1))
  3165. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3166. (org-finalize-agenda)
  3167. (setq buffer-read-only t)
  3168. (message "")))
  3169. (defun org-agenda-ndays-to-span (n)
  3170. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3171. ;;; Agenda word search
  3172. (defvar org-agenda-search-history nil)
  3173. (defvar org-todo-only nil)
  3174. (defvar org-search-syntax-table nil
  3175. "Special syntax table for org-mode search.
  3176. In this table, we have single quotes not as word constituents, to
  3177. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3178. (defun org-search-syntax-table ()
  3179. (unless org-search-syntax-table
  3180. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3181. (modify-syntax-entry ?' "." org-search-syntax-table)
  3182. (modify-syntax-entry ?` "." org-search-syntax-table))
  3183. org-search-syntax-table)
  3184. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3185. ;;;###autoload
  3186. (defun org-search-view (&optional todo-only string edit-at)
  3187. "Show all entries that contain a phrase or words or regular expressions.
  3188. With optional prefix argument TODO-ONLY, only consider entries that are
  3189. TODO entries. The argument STRING can be used to pass a default search
  3190. string into this function. If EDIT-AT is non-nil, it means that the
  3191. user should get a chance to edit this string, with cursor at position
  3192. EDIT-AT.
  3193. The search string can be viewed either as a phrase that should be found as
  3194. is, or it can be broken into a number of snippets, each of which must match
  3195. in a Boolean way to select an entry. The default depends on the variable
  3196. `org-agenda-search-view-always-boolean'.
  3197. Even if this is turned off (the default) you can always switch to
  3198. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3199. The default is a direct search of the whole phrase, where each space in
  3200. the search string can expand to an arbitrary amount of whitespace,
  3201. including newlines.
  3202. If using a Boolean search, the search string is split on whitespace and
  3203. each snippet is searched separately, with logical AND to select an entry.
  3204. Words prefixed with a minus must *not* occur in the entry. Words without
  3205. a prefix or prefixed with a plus must occur in the entry. Matching is
  3206. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3207. match whole words, not parts of a word) if
  3208. `org-agenda-search-view-force-full-words' is set (default is nil).
  3209. Boolean search snippets enclosed by curly braces are interpreted as
  3210. regular expressions that must or (when preceded with \"-\") must not
  3211. match in the entry. Snippets enclosed into double quotes will be taken
  3212. as a whole, to include whitespace.
  3213. - If the search string starts with an asterisk, search only in headlines.
  3214. - If (possibly after the leading star) the search string starts with an
  3215. exclamation mark, this also means to look at TODO entries only, an effect
  3216. that can also be achieved with a prefix argument.
  3217. - If (possibly after star and exclamation mark) the search string starts
  3218. with a colon, this will mean that the (non-regexp) snippets of the
  3219. Boolean search must match as full words.
  3220. This command searches the agenda files, and in addition the files listed
  3221. in `org-agenda-text-search-extra-files'."
  3222. (interactive "P")
  3223. (org-compile-prefix-format 'search)
  3224. (org-set-sorting-strategy 'search)
  3225. (org-prepare-agenda "SEARCH")
  3226. (let* ((props (list 'face nil
  3227. 'done-face 'org-agenda-done
  3228. 'org-not-done-regexp org-not-done-regexp
  3229. 'org-todo-regexp org-todo-regexp
  3230. 'org-complex-heading-regexp org-complex-heading-regexp
  3231. 'mouse-face 'highlight
  3232. 'help-echo (format "mouse-2 or RET jump to location")))
  3233. (full-words org-agenda-search-view-force-full-words)
  3234. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3235. regexp rtn rtnall files file pos
  3236. marker category tags c neg re boolean
  3237. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3238. (unless (and (not edit-at)
  3239. (stringp string)
  3240. (string-match "\\S-" string))
  3241. (setq string (read-string
  3242. (if org-agenda-search-view-always-boolean
  3243. "[+-]Word/{Regexp} ...: "
  3244. "Phrase, or [+-]Word/{Regexp} ...: ")
  3245. (cond
  3246. ((integerp edit-at) (cons string edit-at))
  3247. (edit-at string))
  3248. 'org-agenda-search-history)))
  3249. (org-set-local 'org-todo-only todo-only)
  3250. (setq org-agenda-redo-command
  3251. (list 'org-search-view (if todo-only t nil) string
  3252. '(if current-prefix-arg 1 nil)))
  3253. (setq org-agenda-query-string string)
  3254. (if (equal (string-to-char string) ?*)
  3255. (setq hdl-only t
  3256. words (substring string 1))
  3257. (setq words string))
  3258. (when (equal (string-to-char words) ?!)
  3259. (setq todo-only t
  3260. words (substring words 1)))
  3261. (when (equal (string-to-char words) ?:)
  3262. (setq full-words t
  3263. words (substring words 1)))
  3264. (if (or org-agenda-search-view-always-boolean
  3265. (member (string-to-char words) '(?- ?+ ?\{)))
  3266. (setq boolean t))
  3267. (setq words (org-split-string words))
  3268. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3269. (when boolean
  3270. (let (wds w)
  3271. (while (setq w (pop words))
  3272. (if (or (equal (substring w 0 1) "\"")
  3273. (and (> (length w) 1)
  3274. (member (substring w 0 1) '("+" "-"))
  3275. (equal (substring w 1 2) "\"")))
  3276. (while (and words (not (equal (substring w -1) "\"")))
  3277. (setq w (concat w " " (pop words)))))
  3278. (and (string-match "\\`\\([-+]?\\)\"" w)
  3279. (setq w (replace-match "\\1" nil nil w)))
  3280. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3281. (push w wds))
  3282. (setq words (nreverse wds))))
  3283. (if boolean
  3284. (mapc (lambda (w)
  3285. (setq c (string-to-char w))
  3286. (if (equal c ?-)
  3287. (setq neg t w (substring w 1))
  3288. (if (equal c ?+)
  3289. (setq neg nil w (substring w 1))
  3290. (setq neg nil)))
  3291. (if (string-match "\\`{.*}\\'" w)
  3292. (setq re (substring w 1 -1))
  3293. (if full-words
  3294. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3295. (setq re (regexp-quote (downcase w)))))
  3296. (if neg (push re regexps-) (push re regexps+)))
  3297. words)
  3298. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3299. regexps+))
  3300. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3301. (if (not regexps+)
  3302. (setq regexp (concat "^" org-outline-regexp))
  3303. (setq regexp (pop regexps+))
  3304. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3305. regexp))))
  3306. (setq files (org-agenda-files nil 'ifmode))
  3307. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3308. (pop org-agenda-text-search-extra-files)
  3309. (setq files (org-add-archive-files files)))
  3310. (setq files (append files org-agenda-text-search-extra-files)
  3311. rtnall nil)
  3312. (while (setq file (pop files))
  3313. (setq ee nil)
  3314. (catch 'nextfile
  3315. (org-check-agenda-file file)
  3316. (setq buffer (if (file-exists-p file)
  3317. (org-get-agenda-file-buffer file)
  3318. (error "No such file %s" file)))
  3319. (if (not buffer)
  3320. ;; If file does not exist, make sure an error message is sent
  3321. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3322. file))))
  3323. (with-current-buffer buffer
  3324. (with-syntax-table (org-search-syntax-table)
  3325. (unless (org-mode-p)
  3326. (error "Agenda file %s is not in `org-mode'" file))
  3327. (let ((case-fold-search t))
  3328. (save-excursion
  3329. (save-restriction
  3330. (if org-agenda-restrict
  3331. (narrow-to-region org-agenda-restrict-begin
  3332. org-agenda-restrict-end)
  3333. (widen))
  3334. (goto-char (point-min))
  3335. (unless (or (org-on-heading-p)
  3336. (outline-next-heading))
  3337. (throw 'nextfile t))
  3338. (goto-char (max (point-min) (1- (point))))
  3339. (while (re-search-forward regexp nil t)
  3340. (org-back-to-heading t)
  3341. (skip-chars-forward "* ")
  3342. (setq beg (point-at-bol)
  3343. beg1 (point)
  3344. end (progn (outline-next-heading) (point)))
  3345. (catch :skip
  3346. (goto-char beg)
  3347. (org-agenda-skip)
  3348. (setq str (buffer-substring-no-properties
  3349. (point-at-bol)
  3350. (if hdl-only (point-at-eol) end)))
  3351. (mapc (lambda (wr) (when (string-match wr str)
  3352. (goto-char (1- end))
  3353. (throw :skip t)))
  3354. regexps-)
  3355. (mapc (lambda (wr) (unless (string-match wr str)
  3356. (goto-char (1- end))
  3357. (throw :skip t)))
  3358. (if todo-only
  3359. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3360. regexps+)
  3361. regexps+))
  3362. (goto-char beg)
  3363. (setq marker (org-agenda-new-marker (point))
  3364. category (org-get-category)
  3365. tags (org-get-tags-at (point))
  3366. txt (org-format-agenda-item
  3367. ""
  3368. (buffer-substring-no-properties
  3369. beg1 (point-at-eol))
  3370. category tags))
  3371. (org-add-props txt props
  3372. 'org-marker marker 'org-hd-marker marker
  3373. 'org-todo-regexp org-todo-regexp
  3374. 'org-complex-heading-regexp org-complex-heading-regexp
  3375. 'priority 1000 'org-category category
  3376. 'type "search")
  3377. (push txt ee)
  3378. (goto-char (1- end))))))))))
  3379. (setq rtn (nreverse ee))
  3380. (setq rtnall (append rtnall rtn)))
  3381. (if org-agenda-overriding-header
  3382. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3383. nil 'face 'org-agenda-structure) "\n")
  3384. (insert "Search words: ")
  3385. (add-text-properties (point-min) (1- (point))
  3386. (list 'face 'org-agenda-structure))
  3387. (setq pos (point))
  3388. (insert string "\n")
  3389. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3390. (setq pos (point))
  3391. (unless org-agenda-multi
  3392. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3393. (add-text-properties pos (1- (point))
  3394. (list 'face 'org-agenda-structure))))
  3395. (org-agenda-mark-header-line (point-min))
  3396. (when rtnall
  3397. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3398. (goto-char (point-min))
  3399. (or org-agenda-multi (org-fit-agenda-window))
  3400. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3401. (org-finalize-agenda)
  3402. (setq buffer-read-only t)))
  3403. ;;; Agenda TODO list
  3404. (defvar org-select-this-todo-keyword nil)
  3405. (defvar org-last-arg nil)
  3406. ;;;###autoload
  3407. (defun org-todo-list (arg)
  3408. "Show all (not done) TODO entries from all agenda file in a single list.
  3409. The prefix arg can be used to select a specific TODO keyword and limit
  3410. the list to these. When using \\[universal-argument], you will be prompted
  3411. for a keyword. A numeric prefix directly selects the Nth keyword in
  3412. `org-todo-keywords-1'."
  3413. (interactive "P")
  3414. (org-compile-prefix-format 'todo)
  3415. (org-set-sorting-strategy 'todo)
  3416. (org-prepare-agenda "TODO")
  3417. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3418. (let* ((today (time-to-days (current-time)))
  3419. (date (calendar-gregorian-from-absolute today))
  3420. (kwds org-todo-keywords-for-agenda)
  3421. (completion-ignore-case t)
  3422. (org-select-this-todo-keyword
  3423. (if (stringp arg) arg
  3424. (and arg (integerp arg) (> arg 0)
  3425. (nth (1- arg) kwds))))
  3426. rtn rtnall files file pos)
  3427. (when (equal arg '(4))
  3428. (setq org-select-this-todo-keyword
  3429. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3430. (mapcar 'list kwds) nil nil)))
  3431. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3432. (org-set-local 'org-last-arg arg)
  3433. (setq org-agenda-redo-command
  3434. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3435. (setq files (org-agenda-files nil 'ifmode)
  3436. rtnall nil)
  3437. (while (setq file (pop files))
  3438. (catch 'nextfile
  3439. (org-check-agenda-file file)
  3440. (setq rtn (org-agenda-get-day-entries file date :todo))
  3441. (setq rtnall (append rtnall rtn))))
  3442. (if org-agenda-overriding-header
  3443. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3444. nil 'face 'org-agenda-structure) "\n")
  3445. (insert "Global list of TODO items of type: ")
  3446. (add-text-properties (point-min) (1- (point))
  3447. (list 'face 'org-agenda-structure
  3448. 'short-heading
  3449. (concat "ToDo: "
  3450. (or org-select-this-todo-keyword "ALL"))))
  3451. (org-agenda-mark-header-line (point-min))
  3452. (setq pos (point))
  3453. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3454. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3455. (setq pos (point))
  3456. (unless org-agenda-multi
  3457. (insert "Available with `N r': (0)ALL")
  3458. (let ((n 0) s)
  3459. (mapc (lambda (x)
  3460. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3461. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3462. (insert "\n "))
  3463. (insert " " s))
  3464. kwds))
  3465. (insert "\n"))
  3466. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3467. (org-agenda-mark-header-line (point-min))
  3468. (when rtnall
  3469. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3470. (goto-char (point-min))
  3471. (or org-agenda-multi (org-fit-agenda-window))
  3472. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3473. (org-finalize-agenda)
  3474. (setq buffer-read-only t)))
  3475. ;;; Agenda tags match
  3476. ;;;###autoload
  3477. (defun org-tags-view (&optional todo-only match)
  3478. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3479. The prefix arg TODO-ONLY limits the search to TODO entries."
  3480. (interactive "P")
  3481. (org-compile-prefix-format 'tags)
  3482. (org-set-sorting-strategy 'tags)
  3483. (let* ((org-tags-match-list-sublevels
  3484. org-tags-match-list-sublevels)
  3485. (completion-ignore-case t)
  3486. rtn rtnall files file pos matcher
  3487. buffer)
  3488. (when (and (stringp match) (not (string-match "\\S-" match)))
  3489. (setq match nil))
  3490. (setq matcher (org-make-tags-matcher match)
  3491. match (car matcher) matcher (cdr matcher))
  3492. (org-prepare-agenda (concat "TAGS " match))
  3493. (setq org-agenda-query-string match)
  3494. (setq org-agenda-redo-command
  3495. (list 'org-tags-view (list 'quote todo-only)
  3496. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3497. (setq files (org-agenda-files nil 'ifmode)
  3498. rtnall nil)
  3499. (while (setq file (pop files))
  3500. (catch 'nextfile
  3501. (org-check-agenda-file file)
  3502. (setq buffer (if (file-exists-p file)
  3503. (org-get-agenda-file-buffer file)
  3504. (error "No such file %s" file)))
  3505. (if (not buffer)
  3506. ;; If file does not exist, error message to agenda
  3507. (setq rtn (list
  3508. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3509. rtnall (append rtnall rtn))
  3510. (with-current-buffer buffer
  3511. (unless (org-mode-p)
  3512. (error "Agenda file %s is not in `org-mode'" file))
  3513. (save-excursion
  3514. (save-restriction
  3515. (if org-agenda-restrict
  3516. (narrow-to-region org-agenda-restrict-begin
  3517. org-agenda-restrict-end)
  3518. (widen))
  3519. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3520. (setq rtnall (append rtnall rtn))))))))
  3521. (if org-agenda-overriding-header
  3522. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3523. nil 'face 'org-agenda-structure) "\n")
  3524. (insert "Headlines with TAGS match: ")
  3525. (add-text-properties (point-min) (1- (point))
  3526. (list 'face 'org-agenda-structure
  3527. 'short-heading
  3528. (concat "Match: " match)))
  3529. (setq pos (point))
  3530. (insert match "\n")
  3531. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3532. (setq pos (point))
  3533. (unless org-agenda-multi
  3534. (insert "Press `C-u r' to search again with new search string\n"))
  3535. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3536. (org-agenda-mark-header-line (point-min))
  3537. (when rtnall
  3538. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3539. (goto-char (point-min))
  3540. (or org-agenda-multi (org-fit-agenda-window))
  3541. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3542. (org-finalize-agenda)
  3543. (setq buffer-read-only t)))
  3544. ;;; Agenda Finding stuck projects
  3545. (defvar org-agenda-skip-regexp nil
  3546. "Regular expression used in skipping subtrees for the agenda.
  3547. This is basically a temporary global variable that can be set and then
  3548. used by user-defined selections using `org-agenda-skip-function'.")
  3549. (defvar org-agenda-overriding-header nil
  3550. "When this is set during todo and tags searches, will replace header.
  3551. This variable should not be set directly, but custom commands can bind it
  3552. in the options section.")
  3553. (defun org-agenda-skip-entry-when-regexp-matches ()
  3554. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3555. If yes, it returns the end position of this entry, causing agenda commands
  3556. to skip the entry but continuing the search in the subtree. This is a
  3557. function that can be put into `org-agenda-skip-function' for the duration
  3558. of a command."
  3559. (let ((end (save-excursion (org-end-of-subtree t)))
  3560. skip)
  3561. (save-excursion
  3562. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3563. (and skip end)))
  3564. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3565. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3566. If yes, it returns the end position of this tree, causing agenda commands
  3567. to skip this subtree. This is a function that can be put into
  3568. `org-agenda-skip-function' for the duration of a command."
  3569. (let ((end (save-excursion (org-end-of-subtree t)))
  3570. skip)
  3571. (save-excursion
  3572. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3573. (and skip end)))
  3574. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3575. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3576. If yes, it returns the end position of the current entry (NOT the tree),
  3577. causing agenda commands to skip the entry but continuing the search in
  3578. the subtree. This is a function that can be put into
  3579. `org-agenda-skip-function' for the duration of a command. An important
  3580. use of this function is for the stuck project list."
  3581. (let ((end (save-excursion (org-end-of-subtree t)))
  3582. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3583. skip)
  3584. (save-excursion
  3585. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3586. (and skip entry-end)))
  3587. (defun org-agenda-skip-entry-if (&rest conditions)
  3588. "Skip entry if any of CONDITIONS is true.
  3589. See `org-agenda-skip-if' for details."
  3590. (org-agenda-skip-if nil conditions))
  3591. (defun org-agenda-skip-subtree-if (&rest conditions)
  3592. "Skip entry if any of CONDITIONS is true.
  3593. See `org-agenda-skip-if' for details."
  3594. (org-agenda-skip-if t conditions))
  3595. (defun org-agenda-skip-if (subtree conditions)
  3596. "Checks current entity for CONDITIONS.
  3597. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3598. the entry, i.e. the text before the next heading is checked.
  3599. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3600. from different tests. Valid conditions are:
  3601. scheduled Check if there is a scheduled cookie
  3602. notscheduled Check if there is no scheduled cookie
  3603. deadline Check if there is a deadline
  3604. notdeadline Check if there is no deadline
  3605. timestamp Check if there is a timestamp (also deadline or scheduled)
  3606. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3607. regexp Check if regexp matches
  3608. notregexp Check if regexp does not match.
  3609. todo Check if TODO keyword matches
  3610. nottodo Check if TODO keyword does not match
  3611. The regexp is taken from the conditions list, it must come right after
  3612. the `regexp' or `notregexp' element.
  3613. `todo' and `nottodo' accept as an argument a list of todo
  3614. keywords, which may include \"*\" to match any todo keyword.
  3615. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3616. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3617. Instead of a list a keyword class may be given
  3618. (org-agenda-skip-entry-if 'nottodo 'done)
  3619. would skip entries that haven't been marked with any of \"DONE\"
  3620. keywords. Possible classes are: `todo', `done', `any'.
  3621. If any of these conditions is met, this function returns the end point of
  3622. the entity, causing the search to continue from there. This is a function
  3623. that can be put into `org-agenda-skip-function' for the duration of a command."
  3624. (let (beg end m)
  3625. (org-back-to-heading t)
  3626. (setq beg (point)
  3627. end (if subtree
  3628. (progn (org-end-of-subtree t) (point))
  3629. (progn (outline-next-heading) (1- (point)))))
  3630. (goto-char beg)
  3631. (and
  3632. (or
  3633. (and (memq 'scheduled conditions)
  3634. (re-search-forward org-scheduled-time-regexp end t))
  3635. (and (memq 'notscheduled conditions)
  3636. (not (re-search-forward org-scheduled-time-regexp end t)))
  3637. (and (memq 'deadline conditions)
  3638. (re-search-forward org-deadline-time-regexp end t))
  3639. (and (memq 'notdeadline conditions)
  3640. (not (re-search-forward org-deadline-time-regexp end t)))
  3641. (and (memq 'timestamp conditions)
  3642. (re-search-forward org-ts-regexp end t))
  3643. (and (memq 'nottimestamp conditions)
  3644. (not (re-search-forward org-ts-regexp end t)))
  3645. (and (setq m (memq 'regexp conditions))
  3646. (stringp (nth 1 m))
  3647. (re-search-forward (nth 1 m) end t))
  3648. (and (setq m (memq 'notregexp conditions))
  3649. (stringp (nth 1 m))
  3650. (not (re-search-forward (nth 1 m) end t)))
  3651. (and (or
  3652. (setq m (memq 'todo conditions))
  3653. (setq m (memq 'nottodo conditions)))
  3654. (org-agenda-skip-if-todo m end)))
  3655. end)))
  3656. (defun org-agenda-skip-if-todo (args end)
  3657. "Helper function for `org-agenda-skip-if', do not use it directly.
  3658. ARGS is a list with first element either `todo' or `nottodo'.
  3659. The remainder is either a list of TODO keywords, or a state symbol
  3660. `todo' or `done' or `any'."
  3661. (let ((kw (car args))
  3662. (arg (cadr args))
  3663. todo-wds todo-re)
  3664. (setq todo-wds
  3665. (org-uniquify
  3666. (cond
  3667. ((listp arg) ;; list of keywords
  3668. (if (member "*" arg)
  3669. (mapcar 'substring-no-properties org-todo-keywords-1)
  3670. arg))
  3671. ((symbolp arg) ;; keyword class name
  3672. (cond
  3673. ((eq arg 'todo)
  3674. (org-delete-all org-done-keywords
  3675. (mapcar 'substring-no-properties
  3676. org-todo-keywords-1)))
  3677. ((eq arg 'done) org-done-keywords)
  3678. ((eq arg 'any)
  3679. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3680. (setq todo-re
  3681. (concat "^\\*+[ \t]+\\<\\("
  3682. (mapconcat 'identity todo-wds "\\|")
  3683. "\\)\\>"))
  3684. (if (eq kw 'todo)
  3685. (re-search-forward todo-re end t)
  3686. (not (re-search-forward todo-re end t)))))
  3687. ;;;###autoload
  3688. (defun org-agenda-list-stuck-projects (&rest ignore)
  3689. "Create agenda view for projects that are stuck.
  3690. Stuck projects are project that have no next actions. For the definitions
  3691. of what a project is and how to check if it stuck, customize the variable
  3692. `org-stuck-projects'.
  3693. MATCH is being ignored."
  3694. (interactive)
  3695. (let* ((org-agenda-skip-function
  3696. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3697. ;; We could have used org-agenda-skip-if here.
  3698. (org-agenda-overriding-header
  3699. (or org-agenda-overriding-header "List of stuck projects: "))
  3700. (matcher (nth 0 org-stuck-projects))
  3701. (todo (nth 1 org-stuck-projects))
  3702. (todo-wds (if (member "*" todo)
  3703. (progn
  3704. (org-prepare-agenda-buffers (org-agenda-files
  3705. nil 'ifmode))
  3706. (org-delete-all
  3707. org-done-keywords-for-agenda
  3708. (copy-sequence org-todo-keywords-for-agenda)))
  3709. todo))
  3710. (todo-re (concat "^\\*+[ \t]+\\("
  3711. (mapconcat 'identity todo-wds "\\|")
  3712. "\\)\\>"))
  3713. (tags (nth 2 org-stuck-projects))
  3714. (tags-re (if (member "*" tags)
  3715. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3716. (if tags
  3717. (concat "^\\*+ .*:\\("
  3718. (mapconcat 'identity tags "\\|")
  3719. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3720. (gen-re (nth 3 org-stuck-projects))
  3721. (re-list
  3722. (delq nil
  3723. (list
  3724. (if todo todo-re)
  3725. (if tags tags-re)
  3726. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3727. gen-re)))))
  3728. (setq org-agenda-skip-regexp
  3729. (if re-list
  3730. (mapconcat 'identity re-list "\\|")
  3731. (error "No information how to identify unstuck projects")))
  3732. (org-tags-view nil matcher)
  3733. (with-current-buffer org-agenda-buffer-name
  3734. (setq org-agenda-redo-command
  3735. '(org-agenda-list-stuck-projects
  3736. (or current-prefix-arg org-last-arg))))))
  3737. ;;; Diary integration
  3738. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3739. (defvar list-diary-entries-hook)
  3740. (defun org-get-entries-from-diary (date)
  3741. "Get the (Emacs Calendar) diary entries for DATE."
  3742. (require 'diary-lib)
  3743. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3744. (diary-display-hook '(fancy-diary-display))
  3745. (diary-display-function 'fancy-diary-display)
  3746. (pop-up-frames nil)
  3747. (list-diary-entries-hook
  3748. (cons 'org-diary-default-entry list-diary-entries-hook))
  3749. (diary-file-name-prefix-function nil) ; turn this feature off
  3750. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3751. entries
  3752. (org-disable-agenda-to-diary t))
  3753. (save-excursion
  3754. (save-window-excursion
  3755. (funcall (if (fboundp 'diary-list-entries)
  3756. 'diary-list-entries 'list-diary-entries)
  3757. date 1)))
  3758. (if (not (get-buffer diary-fancy-buffer))
  3759. (setq entries nil)
  3760. (with-current-buffer diary-fancy-buffer
  3761. (setq buffer-read-only nil)
  3762. (if (zerop (buffer-size))
  3763. ;; No entries
  3764. (setq entries nil)
  3765. ;; Omit the date and other unnecessary stuff
  3766. (org-agenda-cleanup-fancy-diary)
  3767. ;; Add prefix to each line and extend the text properties
  3768. (if (zerop (buffer-size))
  3769. (setq entries nil)
  3770. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3771. (set-buffer-modified-p nil)
  3772. (kill-buffer diary-fancy-buffer)))
  3773. (when entries
  3774. (setq entries (org-split-string entries "\n"))
  3775. (setq entries
  3776. (mapcar
  3777. (lambda (x)
  3778. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3779. ;; Extend the text properties to the beginning of the line
  3780. (org-add-props x (text-properties-at (1- (length x)) x)
  3781. 'type "diary" 'date date 'face 'org-agenda-diary))
  3782. entries)))))
  3783. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3784. "Hook run when the fancy diary buffer is cleaned up.")
  3785. (defun org-agenda-cleanup-fancy-diary ()
  3786. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3787. This gets rid of the date, the underline under the date, and
  3788. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3789. date. It also removes lines that contain only whitespace."
  3790. (goto-char (point-min))
  3791. (if (looking-at ".*?:[ \t]*")
  3792. (progn
  3793. (replace-match "")
  3794. (re-search-forward "\n=+$" nil t)
  3795. (replace-match "")
  3796. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3797. (re-search-forward "\n=+$" nil t)
  3798. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3799. (goto-char (point-min))
  3800. (while (re-search-forward "^ +\n" nil t)
  3801. (replace-match ""))
  3802. (goto-char (point-min))
  3803. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3804. (replace-match ""))
  3805. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3806. ;; Make sure entries from the diary have the right text properties.
  3807. (eval-after-load "diary-lib"
  3808. '(if (boundp 'diary-modify-entry-list-string-function)
  3809. ;; We can rely on the hook, nothing to do
  3810. nil
  3811. ;; Hook not available, must use advice to make this work
  3812. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3813. "Make the position visible."
  3814. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3815. (stringp string)
  3816. buffer-file-name)
  3817. (setq string (org-modify-diary-entry-string string))))))
  3818. (defun org-modify-diary-entry-string (string)
  3819. "Add text properties to string, allowing org-mode to act on it."
  3820. (org-add-props string nil
  3821. 'mouse-face 'highlight
  3822. 'help-echo (if buffer-file-name
  3823. (format "mouse-2 or RET jump to diary file %s"
  3824. (abbreviate-file-name buffer-file-name))
  3825. "")
  3826. 'org-agenda-diary-link t
  3827. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3828. (defun org-diary-default-entry ()
  3829. "Add a dummy entry to the diary.
  3830. Needed to avoid empty dates which mess up holiday display."
  3831. ;; Catch the error if dealing with the new add-to-diary-alist
  3832. (when org-disable-agenda-to-diary
  3833. (condition-case nil
  3834. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3835. (error
  3836. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3837. (defun org-add-to-diary-list (&rest args)
  3838. (if (fboundp 'diary-add-to-list)
  3839. (apply 'diary-add-to-list args)
  3840. (apply 'add-to-diary-list args)))
  3841. (defvar org-diary-last-run-time nil)
  3842. ;;;###autoload
  3843. (defun org-diary (&rest args)
  3844. "Return diary information from org-files.
  3845. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3846. It accesses org files and extracts information from those files to be
  3847. listed in the diary. The function accepts arguments specifying what
  3848. items should be listed. For a list of arguments allowed here, see the
  3849. variable `org-agenda-entry-types'.
  3850. The call in the diary file should look like this:
  3851. &%%(org-diary) ~/path/to/some/orgfile.org
  3852. Use a separate line for each org file to check. Or, if you omit the file name,
  3853. all files listed in `org-agenda-files' will be checked automatically:
  3854. &%%(org-diary)
  3855. If you don't give any arguments (as in the example above), the default
  3856. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3857. So the example above may also be written as
  3858. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3859. The function expects the lisp variables `entry' and `date' to be provided
  3860. by the caller, because this is how the calendar works. Don't use this
  3861. function from a program - use `org-agenda-get-day-entries' instead."
  3862. (when (> (- (org-float-time)
  3863. org-agenda-last-marker-time)
  3864. 5)
  3865. (org-agenda-reset-markers))
  3866. (org-compile-prefix-format 'agenda)
  3867. (org-set-sorting-strategy 'agenda)
  3868. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3869. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3870. (list entry)
  3871. (org-agenda-files t)))
  3872. (time (org-float-time))
  3873. file rtn results)
  3874. (when (or (not org-diary-last-run-time)
  3875. (> (- time
  3876. org-diary-last-run-time)
  3877. 3))
  3878. (org-prepare-agenda-buffers files))
  3879. (setq org-diary-last-run-time time)
  3880. ;; If this is called during org-agenda, don't return any entries to
  3881. ;; the calendar. Org Agenda will list these entries itself.
  3882. (if org-disable-agenda-to-diary (setq files nil))
  3883. (while (setq file (pop files))
  3884. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3885. (setq results (append results rtn)))
  3886. (if results
  3887. (concat (org-finalize-agenda-entries results) "\n"))))
  3888. ;;; Agenda entry finders
  3889. (defun org-agenda-get-day-entries (file date &rest args)
  3890. "Does the work for `org-diary' and `org-agenda'.
  3891. FILE is the path to a file to be checked for entries. DATE is date like
  3892. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3893. which kind of entries should be extracted. For details about these, see
  3894. the documentation of `org-diary'."
  3895. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3896. (let* ((org-startup-folded nil)
  3897. (org-startup-align-all-tables nil)
  3898. (buffer (if (file-exists-p file)
  3899. (org-get-agenda-file-buffer file)
  3900. (error "No such file %s" file)))
  3901. arg results rtn deadline-results)
  3902. (if (not buffer)
  3903. ;; If file does not exist, make sure an error message ends up in diary
  3904. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3905. (with-current-buffer buffer
  3906. (unless (org-mode-p)
  3907. (error "Agenda file %s is not in `org-mode'" file))
  3908. (let ((case-fold-search nil))
  3909. (save-excursion
  3910. (save-restriction
  3911. (if org-agenda-restrict
  3912. (narrow-to-region org-agenda-restrict-begin
  3913. org-agenda-restrict-end)
  3914. (widen))
  3915. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3916. (while (setq arg (pop args))
  3917. (cond
  3918. ((and (eq arg :todo)
  3919. (equal date (calendar-current-date)))
  3920. (setq rtn (org-agenda-get-todos))
  3921. (setq results (append results rtn)))
  3922. ((eq arg :timestamp)
  3923. (setq rtn (org-agenda-get-blocks))
  3924. (setq results (append results rtn))
  3925. (setq rtn (org-agenda-get-timestamps))
  3926. (setq results (append results rtn)))
  3927. ((eq arg :sexp)
  3928. (setq rtn (org-agenda-get-sexps))
  3929. (setq results (append results rtn)))
  3930. ((eq arg :scheduled)
  3931. (setq rtn (org-agenda-get-scheduled deadline-results))
  3932. (setq results (append results rtn)))
  3933. ((eq arg :closed)
  3934. (setq rtn (org-agenda-get-progress))
  3935. (setq results (append results rtn)))
  3936. ((eq arg :deadline)
  3937. (setq rtn (org-agenda-get-deadlines))
  3938. (setq deadline-results (copy-sequence rtn))
  3939. (setq results (append results rtn))))))))
  3940. results))))
  3941. (defun org-agenda-get-todos ()
  3942. "Return the TODO information for agenda display."
  3943. (let* ((props (list 'face nil
  3944. 'done-face 'org-agenda-done
  3945. 'org-not-done-regexp org-not-done-regexp
  3946. 'org-todo-regexp org-todo-regexp
  3947. 'org-complex-heading-regexp org-complex-heading-regexp
  3948. 'mouse-face 'highlight
  3949. 'help-echo
  3950. (format "mouse-2 or RET jump to org file %s"
  3951. (abbreviate-file-name buffer-file-name))))
  3952. (regexp (concat "^\\*+[ \t]+\\("
  3953. (if org-select-this-todo-keyword
  3954. (if (equal org-select-this-todo-keyword "*")
  3955. org-todo-regexp
  3956. (concat "\\<\\("
  3957. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3958. "\\)\\>"))
  3959. org-not-done-regexp)
  3960. "[^\n\r]*\\)"))
  3961. marker priority category tags todo-state
  3962. ee txt beg end)
  3963. (goto-char (point-min))
  3964. (while (re-search-forward regexp nil t)
  3965. (catch :skip
  3966. (save-match-data
  3967. (beginning-of-line)
  3968. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3969. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3970. (goto-char (1+ beg))
  3971. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3972. (throw :skip nil)))
  3973. (goto-char beg)
  3974. (org-agenda-skip)
  3975. (goto-char (match-beginning 1))
  3976. (setq marker (org-agenda-new-marker (match-beginning 0))
  3977. category (org-get-category)
  3978. txt (match-string 1)
  3979. tags (org-get-tags-at (point))
  3980. txt (org-format-agenda-item "" txt category tags)
  3981. priority (1+ (org-get-priority txt))
  3982. todo-state (org-get-todo-state))
  3983. (org-add-props txt props
  3984. 'org-marker marker 'org-hd-marker marker
  3985. 'priority priority 'org-category category
  3986. 'type "todo" 'todo-state todo-state)
  3987. (push txt ee)
  3988. (if org-agenda-todo-list-sublevels
  3989. (goto-char (match-end 1))
  3990. (org-end-of-subtree 'invisible))))
  3991. (nreverse ee)))
  3992. ;;;###autoload
  3993. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  3994. (&optional end)
  3995. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  3996. (when (or org-agenda-todo-ignore-with-date
  3997. org-agenda-todo-ignore-scheduled
  3998. org-agenda-todo-ignore-deadlines)
  3999. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4000. (save-excursion
  4001. (or (and org-agenda-todo-ignore-with-date
  4002. (re-search-forward org-ts-regexp end t))
  4003. (and org-agenda-todo-ignore-scheduled
  4004. (re-search-forward org-scheduled-time-regexp end t)
  4005. (cond
  4006. ((eq org-agenda-todo-ignore-scheduled 'future)
  4007. (> (org-days-to-time (match-string 1)) 0))
  4008. ((eq org-agenda-todo-ignore-scheduled 'past)
  4009. (<= (org-days-to-time (match-string 1)) 0))
  4010. (t)))
  4011. (and org-agenda-todo-ignore-deadlines
  4012. (re-search-forward org-deadline-time-regexp end t)
  4013. (cond
  4014. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4015. ((eq org-agenda-todo-ignore-deadlines 'far)
  4016. (not (org-deadline-close (match-string 1))))
  4017. ((eq org-agenda-todo-ignore-deadlines 'future)
  4018. (> (org-days-to-time (match-string 1)) 0))
  4019. ((eq org-agenda-todo-ignore-deadlines 'past)
  4020. (<= (org-days-to-time (match-string 1)) 0))
  4021. (t (org-deadline-close (match-string 1)))))))))
  4022. (defconst org-agenda-no-heading-message
  4023. "No heading for this item in buffer or region.")
  4024. (defun org-agenda-get-timestamps ()
  4025. "Return the date stamp information for agenda display."
  4026. (let* ((props (list 'face nil
  4027. 'org-not-done-regexp org-not-done-regexp
  4028. 'org-todo-regexp org-todo-regexp
  4029. 'org-complex-heading-regexp org-complex-heading-regexp
  4030. 'mouse-face 'highlight
  4031. 'help-echo
  4032. (format "mouse-2 or RET jump to org file %s"
  4033. (abbreviate-file-name buffer-file-name))))
  4034. (d1 (calendar-absolute-from-gregorian date))
  4035. (remove-re
  4036. (concat
  4037. (regexp-quote
  4038. (format-time-string
  4039. "<%Y-%m-%d"
  4040. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4041. ".*?>"))
  4042. (regexp
  4043. (concat
  4044. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4045. (regexp-quote
  4046. (substring
  4047. (format-time-string
  4048. (car org-time-stamp-formats)
  4049. (apply 'encode-time ; DATE bound by calendar
  4050. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4051. 1 11))
  4052. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4053. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4054. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4055. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4056. todo-state end-of-match)
  4057. (goto-char (point-min))
  4058. (while (setq end-of-match (re-search-forward regexp nil t))
  4059. (setq b0 (match-beginning 0)
  4060. b3 (match-beginning 3) e3 (match-end 3))
  4061. (catch :skip
  4062. (and (org-at-date-range-p) (throw :skip nil))
  4063. (org-agenda-skip)
  4064. (if (and (match-end 1)
  4065. (not (= d1 (org-time-string-to-absolute
  4066. (match-string 1) d1 nil
  4067. org-agenda-repeating-timestamp-show-all))))
  4068. (throw :skip nil))
  4069. (if (and e3
  4070. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4071. (throw :skip nil))
  4072. (setq tmp (buffer-substring (max (point-min)
  4073. (- b0 org-ds-keyword-length))
  4074. b0)
  4075. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4076. inactivep (= (char-after b0) ?\[)
  4077. deadlinep (string-match org-deadline-regexp tmp)
  4078. scheduledp (string-match org-scheduled-regexp tmp)
  4079. closedp (and org-agenda-include-inactive-timestamps
  4080. (string-match org-closed-string tmp))
  4081. clockp (and org-agenda-include-inactive-timestamps
  4082. (or (string-match org-clock-string tmp)
  4083. (string-match "]-+\\'" tmp)))
  4084. todo-state (ignore-errors (org-get-todo-state))
  4085. donep (member todo-state org-done-keywords))
  4086. (if (or scheduledp deadlinep closedp clockp
  4087. (and donep org-agenda-skip-timestamp-if-done))
  4088. (throw :skip t))
  4089. (if (string-match ">" timestr)
  4090. ;; substring should only run to end of time stamp
  4091. (setq timestr (substring timestr 0 (match-end 0))))
  4092. (setq marker (org-agenda-new-marker b0)
  4093. category (org-get-category b0))
  4094. (save-excursion
  4095. (if (not (re-search-backward "^\\*+ " nil t))
  4096. (setq txt org-agenda-no-heading-message)
  4097. (goto-char (match-beginning 0))
  4098. (setq hdmarker (org-agenda-new-marker)
  4099. tags (org-get-tags-at))
  4100. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4101. (setq head (match-string 1))
  4102. (setq txt (org-format-agenda-item
  4103. (if inactivep org-agenda-inactive-leader nil)
  4104. head category tags timestr nil
  4105. remove-re)))
  4106. (setq priority (org-get-priority txt))
  4107. (org-add-props txt props
  4108. 'org-marker marker 'org-hd-marker hdmarker)
  4109. (org-add-props txt nil 'priority priority
  4110. 'org-category category 'date date
  4111. 'todo-state todo-state
  4112. 'type "timestamp")
  4113. (push txt ee))
  4114. (if org-agenda-skip-additional-timestamps-same-entry
  4115. (outline-next-heading)
  4116. (goto-char end-of-match))))
  4117. (nreverse ee)))
  4118. (defun org-agenda-get-sexps ()
  4119. "Return the sexp information for agenda display."
  4120. (require 'diary-lib)
  4121. (let* ((props (list 'face nil
  4122. 'mouse-face 'highlight
  4123. 'help-echo
  4124. (format "mouse-2 or RET jump to org file %s"
  4125. (abbreviate-file-name buffer-file-name))))
  4126. (regexp "^&?%%(")
  4127. marker category ee txt tags entry result beg b sexp sexp-entry
  4128. todo-state)
  4129. (goto-char (point-min))
  4130. (while (re-search-forward regexp nil t)
  4131. (catch :skip
  4132. (org-agenda-skip)
  4133. (setq beg (match-beginning 0))
  4134. (goto-char (1- (match-end 0)))
  4135. (setq b (point))
  4136. (forward-sexp 1)
  4137. (setq sexp (buffer-substring b (point)))
  4138. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4139. (org-trim (match-string 1))
  4140. ""))
  4141. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4142. (when result
  4143. (setq marker (org-agenda-new-marker beg)
  4144. category (org-get-category beg)
  4145. todo-state (org-get-todo-state))
  4146. (if (string-match "\\S-" result)
  4147. (setq txt result)
  4148. (setq txt "SEXP entry returned empty string"))
  4149. (setq txt (org-format-agenda-item
  4150. "" txt category tags 'time))
  4151. (org-add-props txt props 'org-marker marker)
  4152. (org-add-props txt nil
  4153. 'org-category category 'date date 'todo-state todo-state
  4154. 'type "sexp")
  4155. (push txt ee))))
  4156. (nreverse ee)))
  4157. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4158. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4159. The order of the first 2 times 3 arguments depends on the variable
  4160. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4161. So for American calendars, give this as MONTH DAY YEAR, for European as
  4162. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4163. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4164. is any number of ISO weeks in the block period for which the item should
  4165. be skipped."
  4166. (let* ((date1 (calendar-absolute-from-gregorian
  4167. (org-order-calendar-date-args m1 d1 y1)))
  4168. (date2 (calendar-absolute-from-gregorian
  4169. (org-order-calendar-date-args m2 d2 y2)))
  4170. (d (calendar-absolute-from-gregorian date)))
  4171. (and
  4172. (<= date1 d)
  4173. (<= d date2)
  4174. (= (calendar-day-of-week date) dayname)
  4175. (or (not skip-weeks)
  4176. (progn
  4177. (require 'cal-iso)
  4178. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4179. entry)))
  4180. (defalias 'org-get-closed 'org-agenda-get-progress)
  4181. (defun org-agenda-get-progress ()
  4182. "Return the logged TODO entries for agenda display."
  4183. (let* ((props (list 'mouse-face 'highlight
  4184. 'org-not-done-regexp org-not-done-regexp
  4185. 'org-todo-regexp org-todo-regexp
  4186. 'org-complex-heading-regexp org-complex-heading-regexp
  4187. 'help-echo
  4188. (format "mouse-2 or RET jump to org file %s"
  4189. (abbreviate-file-name buffer-file-name))))
  4190. (items (if (consp org-agenda-show-log)
  4191. org-agenda-show-log
  4192. org-agenda-log-mode-items))
  4193. (parts
  4194. (delq nil
  4195. (list
  4196. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4197. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4198. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4199. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4200. (error "`org-agenda-log-mode-items' is empty")))
  4201. (regexp (concat
  4202. "\\(" parts-re "\\)"
  4203. " *\\["
  4204. (regexp-quote
  4205. (substring
  4206. (format-time-string
  4207. (car org-time-stamp-formats)
  4208. (apply 'encode-time ; DATE bound by calendar
  4209. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4210. 1 11))))
  4211. (org-agenda-search-headline-for-time nil)
  4212. marker hdmarker priority category tags closedp statep clockp state
  4213. ee txt extra timestr rest clocked)
  4214. (goto-char (point-min))
  4215. (while (re-search-forward regexp nil t)
  4216. (catch :skip
  4217. (org-agenda-skip)
  4218. (setq marker (org-agenda-new-marker (match-beginning 0))
  4219. closedp (equal (match-string 1) org-closed-string)
  4220. statep (equal (string-to-char (match-string 1)) ?-)
  4221. clockp (not (or closedp statep))
  4222. state (and statep (match-string 2))
  4223. category (org-get-category (match-beginning 0))
  4224. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4225. )
  4226. (when (string-match "\\]" timestr)
  4227. ;; substring should only run to end of time stamp
  4228. (setq rest (substring timestr (match-end 0))
  4229. timestr (substring timestr 0 (match-end 0)))
  4230. (if (and (not closedp) (not statep)
  4231. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4232. (progn (setq timestr (concat (substring timestr 0 -1)
  4233. "-" (match-string 1 rest) "]"))
  4234. (setq clocked (match-string 2 rest)))
  4235. (setq clocked "-")))
  4236. (save-excursion
  4237. (setq extra nil)
  4238. (cond
  4239. ((not org-agenda-log-mode-add-notes))
  4240. (statep
  4241. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4242. (setq extra (match-string 1))))
  4243. (clockp
  4244. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4245. (setq extra (match-string 1)))))
  4246. (if (not (re-search-backward "^\\*+ " nil t))
  4247. (setq txt org-agenda-no-heading-message)
  4248. (goto-char (match-beginning 0))
  4249. (setq hdmarker (org-agenda-new-marker)
  4250. tags (org-get-tags-at))
  4251. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4252. (setq txt (match-string 1))
  4253. (when extra
  4254. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4255. (setq txt (concat (substring txt 0 (match-beginning 1))
  4256. " - " extra " " (match-string 2 txt)))
  4257. (setq txt (concat txt " - " extra))))
  4258. (setq txt (org-format-agenda-item
  4259. (cond
  4260. (closedp "Closed: ")
  4261. (statep (concat "State: (" state ")"))
  4262. (t (concat "Clocked: (" clocked ")")))
  4263. txt category tags timestr)))
  4264. (setq priority 100000)
  4265. (org-add-props txt props
  4266. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4267. 'priority priority 'org-category category
  4268. 'type "closed" 'date date
  4269. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4270. (push txt ee))
  4271. (goto-char (point-at-eol))))
  4272. (nreverse ee)))
  4273. (defun org-agenda-get-deadlines ()
  4274. "Return the deadline information for agenda display."
  4275. (let* ((props (list 'mouse-face 'highlight
  4276. 'org-not-done-regexp org-not-done-regexp
  4277. 'org-todo-regexp org-todo-regexp
  4278. 'org-complex-heading-regexp org-complex-heading-regexp
  4279. 'help-echo
  4280. (format "mouse-2 or RET jump to org file %s"
  4281. (abbreviate-file-name buffer-file-name))))
  4282. (regexp org-deadline-time-regexp)
  4283. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4284. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4285. d2 diff dfrac wdays pos pos1 category tags
  4286. suppress-prewarning
  4287. ee txt head face s todo-state upcomingp donep timestr)
  4288. (goto-char (point-min))
  4289. (while (re-search-forward regexp nil t)
  4290. (setq suppress-prewarning nil)
  4291. (catch :skip
  4292. (org-agenda-skip)
  4293. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4294. (save-match-data
  4295. (string-match org-scheduled-time-regexp
  4296. (buffer-substring (point-at-bol)
  4297. (point-at-eol)))))
  4298. (setq suppress-prewarning
  4299. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4300. org-agenda-skip-deadline-prewarning-if-scheduled
  4301. 0)))
  4302. (setq s (match-string 1)
  4303. txt nil
  4304. pos (1- (match-beginning 1))
  4305. d2 (org-time-string-to-absolute
  4306. (match-string 1) d1 'past
  4307. org-agenda-repeating-timestamp-show-all)
  4308. diff (- d2 d1)
  4309. wdays (if suppress-prewarning
  4310. (let ((org-deadline-warning-days suppress-prewarning))
  4311. (org-get-wdays s))
  4312. (org-get-wdays s))
  4313. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4314. upcomingp (and todayp (> diff 0)))
  4315. ;; When to show a deadline in the calendar:
  4316. ;; If the expiration is within wdays warning time.
  4317. ;; Past-due deadlines are only shown on the current date
  4318. (if (and (or (and (<= diff wdays)
  4319. (and todayp (not org-agenda-only-exact-dates)))
  4320. (= diff 0)))
  4321. (save-excursion
  4322. (setq todo-state (org-get-todo-state))
  4323. (setq donep (member todo-state org-done-keywords))
  4324. (if (and donep
  4325. (or org-agenda-skip-deadline-if-done
  4326. (not (= diff 0))))
  4327. (setq txt nil)
  4328. (setq category (org-get-category))
  4329. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4330. (setq txt org-agenda-no-heading-message)
  4331. (goto-char (match-end 0))
  4332. (setq pos1 (match-beginning 0))
  4333. (setq tags (org-get-tags-at pos1))
  4334. (setq head (buffer-substring-no-properties
  4335. (point)
  4336. (progn (skip-chars-forward "^\r\n")
  4337. (point))))
  4338. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4339. (setq timestr
  4340. (concat (substring s (match-beginning 1)) " "))
  4341. (setq timestr 'time))
  4342. (setq txt (org-format-agenda-item
  4343. (if (= diff 0)
  4344. (car org-agenda-deadline-leaders)
  4345. (if (functionp
  4346. (nth 1 org-agenda-deadline-leaders))
  4347. (funcall
  4348. (nth 1 org-agenda-deadline-leaders)
  4349. diff date)
  4350. (format (nth 1 org-agenda-deadline-leaders)
  4351. diff)))
  4352. head category tags
  4353. (if (not (= diff 0)) nil timestr)))))
  4354. (when txt
  4355. (setq face (org-agenda-deadline-face dfrac wdays))
  4356. (org-add-props txt props
  4357. 'org-marker (org-agenda-new-marker pos)
  4358. 'org-hd-marker (org-agenda-new-marker pos1)
  4359. 'priority (+ (- diff)
  4360. (org-get-priority txt))
  4361. 'org-category category
  4362. 'todo-state todo-state
  4363. 'type (if upcomingp "upcoming-deadline" "deadline")
  4364. 'date (if upcomingp date d2)
  4365. 'face (if donep 'org-agenda-done face)
  4366. 'undone-face face 'done-face 'org-agenda-done)
  4367. (push txt ee))))))
  4368. (nreverse ee)))
  4369. (defun org-agenda-deadline-face (fraction &optional wdays)
  4370. "Return the face to displaying a deadline item.
  4371. FRACTION is what fraction of the head-warning time has passed."
  4372. (if (equal wdays 0) (setq fraction 1.))
  4373. (let ((faces org-agenda-deadline-faces) f)
  4374. (catch 'exit
  4375. (while (setq f (pop faces))
  4376. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4377. (defun org-agenda-get-scheduled (&optional deadline-results)
  4378. "Return the scheduled information for agenda display."
  4379. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4380. 'org-todo-regexp org-todo-regexp
  4381. 'org-complex-heading-regexp org-complex-heading-regexp
  4382. 'done-face 'org-agenda-done
  4383. 'mouse-face 'highlight
  4384. 'help-echo
  4385. (format "mouse-2 or RET jump to org file %s"
  4386. (abbreviate-file-name buffer-file-name))))
  4387. (regexp org-scheduled-time-regexp)
  4388. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4389. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4390. mm
  4391. (deadline-position-alist
  4392. (mapcar (lambda (a) (and (setq mm (get-text-property
  4393. 0 'org-hd-marker a))
  4394. (cons (marker-position mm) a)))
  4395. deadline-results))
  4396. d2 diff pos pos1 category tags donep
  4397. ee txt head pastschedp todo-state face timestr s habitp)
  4398. (goto-char (point-min))
  4399. (while (re-search-forward regexp nil t)
  4400. (catch :skip
  4401. (org-agenda-skip)
  4402. (setq s (match-string 1)
  4403. txt nil
  4404. pos (1- (match-beginning 1))
  4405. d2 (org-time-string-to-absolute
  4406. (match-string 1) d1 'past
  4407. org-agenda-repeating-timestamp-show-all)
  4408. diff (- d2 d1))
  4409. (setq pastschedp (and todayp (< diff 0)))
  4410. ;; When to show a scheduled item in the calendar:
  4411. ;; If it is on or past the date.
  4412. (when (or (and (< diff 0)
  4413. (< (abs diff) org-scheduled-past-days)
  4414. (and todayp (not org-agenda-only-exact-dates)))
  4415. (= diff 0))
  4416. (save-excursion
  4417. (setq todo-state (org-get-todo-state))
  4418. (setq donep (member todo-state org-done-keywords))
  4419. (setq habitp (and (functionp 'org-is-habit-p)
  4420. (org-is-habit-p)))
  4421. (if (and donep
  4422. (or habitp org-agenda-skip-scheduled-if-done
  4423. (not (= diff 0))))
  4424. (setq txt nil)
  4425. (setq category (org-get-category))
  4426. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4427. (setq txt org-agenda-no-heading-message)
  4428. (goto-char (match-end 0))
  4429. (setq pos1 (match-beginning 0))
  4430. (if habitp
  4431. (if (or (not org-habit-show-habits)
  4432. (and (not todayp)
  4433. org-habit-show-habits-only-for-today))
  4434. (throw :skip nil))
  4435. (if (and
  4436. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4437. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4438. pastschedp))
  4439. (setq mm (assoc pos1 deadline-position-alist)))
  4440. (throw :skip nil)))
  4441. (setq tags (org-get-tags-at))
  4442. (setq head (buffer-substring-no-properties
  4443. (point)
  4444. (progn (skip-chars-forward "^\r\n") (point))))
  4445. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4446. (setq timestr
  4447. (concat (substring s (match-beginning 1)) " "))
  4448. (setq timestr 'time))
  4449. (setq txt (org-format-agenda-item
  4450. (if (= diff 0)
  4451. (car org-agenda-scheduled-leaders)
  4452. (format (nth 1 org-agenda-scheduled-leaders)
  4453. (- 1 diff)))
  4454. head category tags
  4455. (if (not (= diff 0)) nil timestr)
  4456. nil nil habitp))))
  4457. (when txt
  4458. (setq face
  4459. (cond
  4460. ((and (not habitp) pastschedp)
  4461. 'org-scheduled-previously)
  4462. (todayp 'org-scheduled-today)
  4463. (t 'org-scheduled))
  4464. habitp (and habitp (org-habit-parse-todo)))
  4465. (org-add-props txt props
  4466. 'undone-face face
  4467. 'face (if donep 'org-agenda-done face)
  4468. 'org-marker (org-agenda-new-marker pos)
  4469. 'org-hd-marker (org-agenda-new-marker pos1)
  4470. 'type (if pastschedp "past-scheduled" "scheduled")
  4471. 'date (if pastschedp d2 date)
  4472. 'priority (if habitp
  4473. (org-habit-get-priority habitp)
  4474. (+ 94 (- 5 diff) (org-get-priority txt)))
  4475. 'org-category category
  4476. 'org-habit-p habitp
  4477. 'todo-state todo-state)
  4478. (push txt ee))))))
  4479. (nreverse ee)))
  4480. (defun org-agenda-get-blocks ()
  4481. "Return the date-range information for agenda display."
  4482. (let* ((props (list 'face nil
  4483. 'org-not-done-regexp org-not-done-regexp
  4484. 'org-todo-regexp org-todo-regexp
  4485. 'org-complex-heading-regexp org-complex-heading-regexp
  4486. 'mouse-face 'highlight
  4487. 'help-echo
  4488. (format "mouse-2 or RET jump to org file %s"
  4489. (abbreviate-file-name buffer-file-name))))
  4490. (regexp org-tr-regexp)
  4491. (d0 (calendar-absolute-from-gregorian date))
  4492. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4493. head donep)
  4494. (goto-char (point-min))
  4495. (while (re-search-forward regexp nil t)
  4496. (catch :skip
  4497. (org-agenda-skip)
  4498. (setq pos (point))
  4499. (setq timestr (match-string 0)
  4500. s1 (match-string 1)
  4501. s2 (match-string 2)
  4502. d1 (time-to-days (org-time-string-to-time s1))
  4503. d2 (time-to-days (org-time-string-to-time s2)))
  4504. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4505. ;; Only allow days between the limits, because the normal
  4506. ;; date stamps will catch the limits.
  4507. (save-excursion
  4508. (setq todo-state (org-get-todo-state))
  4509. (setq donep (member todo-state org-done-keywords))
  4510. (if (and donep org-agenda-skip-timestamp-if-done)
  4511. (throw :skip t))
  4512. (setq marker (org-agenda-new-marker (point)))
  4513. (setq category (org-get-category))
  4514. (if (not (re-search-backward "^\\*+ " nil t))
  4515. (setq txt org-agenda-no-heading-message)
  4516. (goto-char (match-beginning 0))
  4517. (setq hdmarker (org-agenda-new-marker (point)))
  4518. (setq tags (org-get-tags-at))
  4519. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4520. (setq head (match-string 1))
  4521. (let ((remove-re
  4522. (if org-agenda-remove-timeranges-from-blocks
  4523. (concat
  4524. "<" (regexp-quote s1) ".*?>"
  4525. "--"
  4526. "<" (regexp-quote s2) ".*?>")
  4527. nil)))
  4528. (setq txt (org-format-agenda-item
  4529. (format
  4530. (nth (if (= d1 d2) 0 1)
  4531. org-agenda-timerange-leaders)
  4532. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4533. head category tags
  4534. timestr nil remove-re))))
  4535. (org-add-props txt props
  4536. 'org-marker marker 'org-hd-marker hdmarker
  4537. 'type "block" 'date date
  4538. 'todo-state todo-state
  4539. 'priority (org-get-priority txt) 'org-category category)
  4540. (push txt ee)))
  4541. (goto-char pos)))
  4542. ;; Sort the entries by expiration date.
  4543. (nreverse ee)))
  4544. ;;; Agenda presentation and sorting
  4545. (defvar org-prefix-has-time nil
  4546. "A flag, set by `org-compile-prefix-format'.
  4547. The flag is set if the currently compiled format contains a `%t'.")
  4548. (defvar org-prefix-has-tag nil
  4549. "A flag, set by `org-compile-prefix-format'.
  4550. The flag is set if the currently compiled format contains a `%T'.")
  4551. (defvar org-prefix-has-effort nil
  4552. "A flag, set by `org-compile-prefix-format'.
  4553. The flag is set if the currently compiled format contains a `%e'.")
  4554. (defvar org-prefix-category-length nil
  4555. "Used by `org-compile-prefix-format' to remember the category field width.")
  4556. (defvar org-prefix-category-max-length nil
  4557. "Used by `org-compile-prefix-format' to remember the category field width.")
  4558. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4559. noprefix remove-re habitp)
  4560. "Format TXT to be inserted into the agenda buffer.
  4561. In particular, it adds the prefix and corresponding text properties. EXTRA
  4562. must be a string and replaces the `%s' specifier in the prefix format.
  4563. CATEGORY (string, symbol or nil) may be used to overrule the default
  4564. category taken from local variable or file name. It will replace the `%c'
  4565. specifier in the format. DOTIME, when non-nil, indicates that a
  4566. time-of-day should be extracted from TXT for sorting of this entry, and for
  4567. the `%t' specifier in the format. When DOTIME is a string, this string is
  4568. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4569. only the correctly processes TXT should be returned - this is used by
  4570. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4571. Any match of REMOVE-RE will be removed from TXT."
  4572. (save-match-data
  4573. ;; Diary entries sometimes have extra whitespace at the beginning
  4574. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4575. ;; Fix the tags part in txt
  4576. (setq txt (org-agenda-fix-displayed-tags
  4577. txt tags
  4578. org-agenda-show-inherited-tags
  4579. org-agenda-hide-tags-regexp))
  4580. (let* ((category (or category
  4581. org-category
  4582. (if buffer-file-name
  4583. (file-name-sans-extension
  4584. (file-name-nondirectory buffer-file-name))
  4585. "")))
  4586. ;; time, tag, effort are needed for the eval of the prefix format
  4587. (tag (if tags (nth (1- (length tags)) tags) ""))
  4588. time effort neffort
  4589. (ts (if dotime (concat
  4590. (if (stringp dotime) dotime "")
  4591. (and org-agenda-search-headline-for-time txt))))
  4592. (time-of-day (and dotime (org-get-time-of-day ts)))
  4593. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4594. duration thecategory)
  4595. (and (org-mode-p) buffer-file-name
  4596. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4597. (when (and dotime time-of-day)
  4598. ;; Extract starting and ending time and move them to prefix
  4599. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4600. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4601. (setq s0 (match-string 0 ts)
  4602. srp (and stamp (match-end 3))
  4603. s1 (match-string (if plain 1 2) ts)
  4604. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4605. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4606. ;; them, we might want to remove them there to avoid duplication.
  4607. ;; The user can turn this off with a variable.
  4608. (if (and org-prefix-has-time
  4609. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4610. (string-match (concat (regexp-quote s0) " *") txt)
  4611. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4612. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4613. (= (match-beginning 0) 0)
  4614. t))
  4615. (setq txt (replace-match "" nil nil txt))))
  4616. ;; Normalize the time(s) to 24 hour
  4617. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4618. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4619. ;; Compute the duration
  4620. (when s1
  4621. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4622. (string-to-number (substring s1 3)))
  4623. t2 (cond
  4624. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4625. (string-to-number (substring s2 3))))
  4626. (org-agenda-default-appointment-duration
  4627. (+ t1 org-agenda-default-appointment-duration))
  4628. (t nil)))
  4629. (setq duration (if t2 (- t2 t1)))))
  4630. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4631. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4632. (let ((m (+ (string-to-number (match-string 2 s1))
  4633. (* 60 (string-to-number (match-string 1 s1)))
  4634. org-agenda-default-appointment-duration))
  4635. h)
  4636. (setq h (/ m 60) m (- m (* h 60)))
  4637. (setq s2 (format "%02d:%02d" h m))))
  4638. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4639. txt)
  4640. ;; Tags are in the string
  4641. (if (or (eq org-agenda-remove-tags t)
  4642. (and org-agenda-remove-tags
  4643. org-prefix-has-tag))
  4644. (setq txt (replace-match "" t t txt))
  4645. (setq txt (replace-match
  4646. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4647. (match-string 2 txt))
  4648. t t txt))))
  4649. (when (org-mode-p)
  4650. (setq effort
  4651. (condition-case nil
  4652. (org-get-effort
  4653. (or (get-text-property 0 'org-hd-marker txt)
  4654. (get-text-property 0 'org-marker txt)))
  4655. (error nil)))
  4656. (when effort
  4657. (setq neffort (org-hh:mm-string-to-minutes effort)
  4658. effort (setq effort (concat "[" effort "]" )))))
  4659. (when remove-re
  4660. (while (string-match remove-re txt)
  4661. (setq txt (replace-match "" t t txt))))
  4662. ;; Create the final string
  4663. (if noprefix
  4664. (setq rtn txt)
  4665. ;; Prepare the variables needed in the eval of the compiled format
  4666. (setq time (cond (s2 (concat s1 "-" s2))
  4667. (s1 (concat s1 "......"))
  4668. (t ""))
  4669. extra (or (and (not habitp) extra) "")
  4670. category (if (symbolp category) (symbol-name category) category)
  4671. thecategory (copy-sequence category))
  4672. (if (string-match org-bracket-link-regexp category)
  4673. (progn
  4674. (setq l (if (match-end 3)
  4675. (- (match-end 3) (match-beginning 3))
  4676. (- (match-end 1) (match-beginning 1))))
  4677. (when (< l (or org-prefix-category-length 0))
  4678. (setq category (copy-sequence category))
  4679. (org-add-props category nil
  4680. 'extra-space (make-string
  4681. (- org-prefix-category-length l 1) ?\ ))))
  4682. (if (and org-prefix-category-max-length
  4683. (>= (length category) org-prefix-category-max-length))
  4684. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4685. ;; Evaluate the compiled format
  4686. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4687. ;; And finally add the text properties
  4688. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4689. (org-add-props rtn nil
  4690. 'org-category (if thecategory (downcase thecategory) category)
  4691. 'tags (mapcar 'org-downcase-keep-props tags)
  4692. 'org-highest-priority org-highest-priority
  4693. 'org-lowest-priority org-lowest-priority
  4694. 'prefix-length (- (length rtn) (length txt))
  4695. 'time-of-day time-of-day
  4696. 'duration duration
  4697. 'effort effort
  4698. 'effort-minutes neffort
  4699. 'txt txt
  4700. 'time time
  4701. 'extra extra
  4702. 'dotime dotime))))
  4703. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4704. "Remove tags string from TXT, and add a modified list of tags.
  4705. The modified list may contain inherited tags, and tags matched by
  4706. `org-agenda-hide-tags-regexp' will be removed."
  4707. (when (or add-inherited hide-re)
  4708. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4709. (setq txt (substring txt 0 (match-beginning 0))))
  4710. (setq tags
  4711. (delq nil
  4712. (mapcar (lambda (tg)
  4713. (if (or (and hide-re (string-match hide-re tg))
  4714. (and (not add-inherited)
  4715. (get-text-property 0 'inherited tg)))
  4716. nil
  4717. tg))
  4718. tags)))
  4719. (when tags
  4720. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4721. i)
  4722. (setq txt (concat txt " :"
  4723. (mapconcat
  4724. (lambda (x)
  4725. (setq i (get-text-property 0 'inherited x))
  4726. (if (and have-i (not i))
  4727. (progn
  4728. (setq have-i nil)
  4729. (concat ":" x))
  4730. x))
  4731. tags ":")
  4732. (if have-i "::" ":"))))))
  4733. txt)
  4734. (defun org-downcase-keep-props (s)
  4735. (let ((props (text-properties-at 0 s)))
  4736. (setq s (downcase s))
  4737. (add-text-properties 0 (length s) props s)
  4738. s))
  4739. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4740. (defvar org-agenda-sorting-strategy-selected nil)
  4741. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4742. (catch 'exit
  4743. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4744. ((and todayp (member 'today (car org-agenda-time-grid))))
  4745. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4746. ((member 'weekly (car org-agenda-time-grid)))
  4747. (t (throw 'exit list)))
  4748. (let* ((have (delq nil (mapcar
  4749. (lambda (x) (get-text-property 1 'time-of-day x))
  4750. list)))
  4751. (string (nth 1 org-agenda-time-grid))
  4752. (gridtimes (nth 2 org-agenda-time-grid))
  4753. (req (car org-agenda-time-grid))
  4754. (remove (member 'remove-match req))
  4755. new time)
  4756. (if (and (member 'require-timed req) (not have))
  4757. ;; don't show empty grid
  4758. (throw 'exit list))
  4759. (while (setq time (pop gridtimes))
  4760. (unless (and remove (member time have))
  4761. (setq time (int-to-string time))
  4762. (push (org-format-agenda-item
  4763. nil string "" nil
  4764. (concat (substring time 0 -2) ":" (substring time -2)))
  4765. new)
  4766. (put-text-property
  4767. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4768. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4769. (append new list)
  4770. (append list new)))))
  4771. (defun org-compile-prefix-format (key)
  4772. "Compile the prefix format into a Lisp form that can be evaluated.
  4773. The resulting form is returned and stored in the variable
  4774. `org-prefix-format-compiled'."
  4775. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4776. org-prefix-category-length nil org-prefix-has-effort nil)
  4777. (let ((s (cond
  4778. ((stringp org-agenda-prefix-format)
  4779. org-agenda-prefix-format)
  4780. ((assq key org-agenda-prefix-format)
  4781. (cdr (assq key org-agenda-prefix-format)))
  4782. (t " %-12:c%?-12t% s")))
  4783. (start 0)
  4784. varform vars var e c f opt)
  4785. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4786. s start)
  4787. (setq var (cdr (assoc (match-string 4 s)
  4788. '(("c" . category) ("t" . time) ("s" . extra)
  4789. ("T" . tag) ("e" . effort))))
  4790. c (or (match-string 3 s) "")
  4791. opt (match-beginning 1)
  4792. start (1+ (match-beginning 0)))
  4793. (if (equal var 'time) (setq org-prefix-has-time t))
  4794. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4795. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4796. (setq f (concat "%" (match-string 2 s) "s"))
  4797. (when (equal var 'category)
  4798. (setq org-prefix-category-length
  4799. (floor (abs (string-to-number (match-string 2 s)))))
  4800. (setq org-prefix-category-max-length
  4801. (let ((x (match-string 2 s)))
  4802. (save-match-data
  4803. (if (string-match "\\.[0-9]+" x)
  4804. (string-to-number (substring (match-string 0 x) 1)))))))
  4805. (if opt
  4806. (setq varform
  4807. `(if (equal "" ,var)
  4808. ""
  4809. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4810. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4811. (setq s (replace-match "%s" t nil s))
  4812. (push varform vars))
  4813. (setq vars (nreverse vars))
  4814. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4815. (defun org-set-sorting-strategy (key)
  4816. (if (symbolp (car org-agenda-sorting-strategy))
  4817. ;; the old format
  4818. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4819. (setq org-agenda-sorting-strategy-selected
  4820. (or (cdr (assq key org-agenda-sorting-strategy))
  4821. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4822. '(time-up category-keep priority-down)))))
  4823. (defun org-get-time-of-day (s &optional string mod24)
  4824. "Check string S for a time of day.
  4825. If found, return it as a military time number between 0 and 2400.
  4826. If not found, return nil.
  4827. The optional STRING argument forces conversion into a 5 character wide string
  4828. HH:MM."
  4829. (save-match-data
  4830. (when
  4831. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4832. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4833. (let* ((h (string-to-number (match-string 1 s)))
  4834. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4835. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4836. (am-p (equal ampm "am"))
  4837. (h1 (cond ((not ampm) h)
  4838. ((= h 12) (if am-p 0 12))
  4839. (t (+ h (if am-p 0 12)))))
  4840. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4841. (mod h1 24) h1))
  4842. (t0 (+ (* 100 h2) m))
  4843. (t1 (concat (if (>= h1 24) "+" " ")
  4844. (if (and org-agenda-time-leading-zero
  4845. (< t0 1000)) "0" "")
  4846. (if (< t0 100) "0" "")
  4847. (if (< t0 10) "0" "")
  4848. (int-to-string t0))))
  4849. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4850. (defvar org-agenda-before-sorting-filter-function nil
  4851. "Function to be applied to agenda items prior to sorting.
  4852. Prior to sorting also means just before they are inserted into the agenda.
  4853. To aid sorting, you may revisit the original entries and add more text
  4854. properties which will later be used by the sorting functions.
  4855. The function should take a string argument, an agenda line.
  4856. It has access to the text properties in that line, which contain among
  4857. other things, the property `org-hd-marker' that points to the entry
  4858. where the line comes from. Note that not all lines going into the agenda
  4859. have this property, only most.
  4860. The function should return the modified string. It is probably best
  4861. to ONLY change text properties.
  4862. You can also use this function as a filter, by returning nil for lines
  4863. you don't want to have in the agenda at all. For this application, you
  4864. could bind the variable in the options section of a custom command.")
  4865. (defun org-finalize-agenda-entries (list &optional nosort)
  4866. "Sort and concatenate the agenda items."
  4867. (setq list (mapcar 'org-agenda-highlight-todo list))
  4868. (if nosort
  4869. list
  4870. (when org-agenda-before-sorting-filter-function
  4871. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  4872. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4873. (defun org-agenda-highlight-todo (x)
  4874. (let ((org-done-keywords org-done-keywords-for-agenda)
  4875. (case-fold-search nil)
  4876. re pl)
  4877. (if (eq x 'line)
  4878. (save-excursion
  4879. (beginning-of-line 1)
  4880. (setq re (org-get-at-bol 'org-todo-regexp))
  4881. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4882. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4883. (add-text-properties (match-beginning 0) (match-end 1)
  4884. (list 'face (org-get-todo-face 1)))
  4885. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4886. (delete-region (match-beginning 1) (1- (match-end 0)))
  4887. (goto-char (match-beginning 1))
  4888. (insert (format org-agenda-todo-keyword-format s)))))
  4889. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4890. pl (get-text-property 0 'prefix-length x))
  4891. (when (and re
  4892. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4893. x (or pl 0)) pl))
  4894. (add-text-properties
  4895. (or (match-end 1) (match-end 0)) (match-end 0)
  4896. (list 'face (org-get-todo-face (match-string 2 x)))
  4897. x)
  4898. (when (match-end 1)
  4899. (setq x (concat (substring x 0 (match-end 1))
  4900. (format org-agenda-todo-keyword-format
  4901. (match-string 2 x))
  4902. (org-add-props " " (text-properties-at 0 x))
  4903. (substring x (match-end 3))))))
  4904. x)))
  4905. (defsubst org-cmp-priority (a b)
  4906. "Compare the priorities of string A and B."
  4907. (let ((pa (or (get-text-property 1 'priority a) 0))
  4908. (pb (or (get-text-property 1 'priority b) 0)))
  4909. (cond ((> pa pb) +1)
  4910. ((< pa pb) -1)
  4911. (t nil))))
  4912. (defsubst org-cmp-effort (a b)
  4913. "Compare the priorities of string A and B."
  4914. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4915. (ea (or (get-text-property 1 'effort-minutes a) def))
  4916. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4917. (cond ((> ea eb) +1)
  4918. ((< ea eb) -1)
  4919. (t nil))))
  4920. (defsubst org-cmp-category (a b)
  4921. "Compare the string values of categories of strings A and B."
  4922. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4923. (cb (or (get-text-property 1 'org-category b) "")))
  4924. (cond ((string-lessp ca cb) -1)
  4925. ((string-lessp cb ca) +1)
  4926. (t nil))))
  4927. (defsubst org-cmp-todo-state (a b)
  4928. "Compare the todo states of strings A and B."
  4929. (let* ((ma (or (get-text-property 1 'org-marker a)
  4930. (get-text-property 1 'org-hd-marker a)))
  4931. (mb (or (get-text-property 1 'org-marker b)
  4932. (get-text-property 1 'org-hd-marker b)))
  4933. (fa (and ma (marker-buffer ma)))
  4934. (fb (and mb (marker-buffer mb)))
  4935. (todo-kwds
  4936. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4937. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4938. (ta (or (get-text-property 1 'todo-state a) ""))
  4939. (tb (or (get-text-property 1 'todo-state b) ""))
  4940. (la (- (length (member ta todo-kwds))))
  4941. (lb (- (length (member tb todo-kwds))))
  4942. (donepa (member ta org-done-keywords-for-agenda))
  4943. (donepb (member tb org-done-keywords-for-agenda)))
  4944. (cond ((and donepa (not donepb)) -1)
  4945. ((and (not donepa) donepb) +1)
  4946. ((< la lb) -1)
  4947. ((< lb la) +1)
  4948. (t nil))))
  4949. (defsubst org-cmp-alpha (a b)
  4950. "Compare the headlines, alphabetically."
  4951. (let* ((pla (get-text-property 0 'prefix-length a))
  4952. (plb (get-text-property 0 'prefix-length b))
  4953. (ta (and pla (substring a pla)))
  4954. (tb (and plb (substring b plb))))
  4955. (when pla
  4956. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  4957. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  4958. (setq ta (substring ta (match-end 0))))
  4959. (setq ta (downcase ta)))
  4960. (when plb
  4961. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  4962. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  4963. (setq tb (substring tb (match-end 0))))
  4964. (setq tb (downcase tb)))
  4965. (cond ((not ta) +1)
  4966. ((not tb) -1)
  4967. ((string-lessp ta tb) -1)
  4968. ((string-lessp tb ta) +1)
  4969. (t nil))))
  4970. (defsubst org-cmp-tag (a b)
  4971. "Compare the string values of the first tags of A and B."
  4972. (let ((ta (car (last (get-text-property 1 'tags a))))
  4973. (tb (car (last (get-text-property 1 'tags b)))))
  4974. (cond ((not ta) +1)
  4975. ((not tb) -1)
  4976. ((string-lessp ta tb) -1)
  4977. ((string-lessp tb ta) +1)
  4978. (t nil))))
  4979. (defsubst org-cmp-time (a b)
  4980. "Compare the time-of-day values of strings A and B."
  4981. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4982. (ta (or (get-text-property 1 'time-of-day a) def))
  4983. (tb (or (get-text-property 1 'time-of-day b) def)))
  4984. (cond ((< ta tb) -1)
  4985. ((< tb ta) +1)
  4986. (t nil))))
  4987. (defsubst org-cmp-habit-p (a b)
  4988. "Compare the todo states of strings A and B."
  4989. (let ((ha (get-text-property 1 'org-habit-p a))
  4990. (hb (get-text-property 1 'org-habit-p b)))
  4991. (cond ((and ha (not hb)) -1)
  4992. ((and (not ha) hb) +1)
  4993. (t nil))))
  4994. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  4995. (defun org-entries-lessp (a b)
  4996. "Predicate for sorting agenda entries."
  4997. ;; The following variables will be used when the form is evaluated.
  4998. ;; So even though the compiler complains, keep them.
  4999. (let* ((ss org-agenda-sorting-strategy-selected)
  5000. (time-up (and (org-em 'time-up 'time-down ss)
  5001. (org-cmp-time a b)))
  5002. (time-down (if time-up (- time-up) nil))
  5003. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5004. (org-cmp-priority a b)))
  5005. (priority-down (if priority-up (- priority-up) nil))
  5006. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5007. (org-cmp-effort a b)))
  5008. (effort-down (if effort-up (- effort-up) nil))
  5009. (category-up (and (or (org-em 'category-up 'category-down ss)
  5010. (memq 'category-keep ss))
  5011. (org-cmp-category a b)))
  5012. (category-down (if category-up (- category-up) nil))
  5013. (category-keep (if category-up +1 nil))
  5014. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5015. (org-cmp-tag a b)))
  5016. (tag-down (if tag-up (- tag-up) nil))
  5017. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5018. (org-cmp-todo-state a b)))
  5019. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5020. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5021. (org-cmp-habit-p a b)))
  5022. (habit-down (if habit-up (- habit-up) nil))
  5023. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5024. (org-cmp-alpha a b)))
  5025. (alpha-down (if alpha-up (- alpha-up) nil))
  5026. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5027. user-defined-up user-defined-down)
  5028. (if (and need-user-cmp org-agenda-cmp-user-defined
  5029. (functionp org-agenda-cmp-user-defined))
  5030. (setq user-defined-up
  5031. (funcall org-agenda-cmp-user-defined a b)
  5032. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5033. (cdr (assoc
  5034. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5035. '((-1 . t) (1 . nil) (nil . nil))))))
  5036. ;;; Agenda restriction lock
  5037. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5038. "Overlay to mark the headline to which agenda commands are restricted.")
  5039. (overlay-put org-agenda-restriction-lock-overlay
  5040. 'face 'org-agenda-restriction-lock)
  5041. (overlay-put org-agenda-restriction-lock-overlay
  5042. 'help-echo "Agendas are currently limited to this subtree.")
  5043. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5044. (defun org-agenda-set-restriction-lock (&optional type)
  5045. "Set restriction lock for agenda, to current subtree or file.
  5046. Restriction will be the file if TYPE is `file', or if type is the
  5047. universal prefix '(4), or if the cursor is before the first headline
  5048. in the file. Otherwise, restriction will be to the current subtree."
  5049. (interactive "P")
  5050. (and (equal type '(4)) (setq type 'file))
  5051. (setq type (cond
  5052. (type type)
  5053. ((org-at-heading-p) 'subtree)
  5054. ((condition-case nil (org-back-to-heading t) (error nil))
  5055. 'subtree)
  5056. (t 'file)))
  5057. (if (eq type 'subtree)
  5058. (progn
  5059. (setq org-agenda-restrict t)
  5060. (setq org-agenda-overriding-restriction 'subtree)
  5061. (put 'org-agenda-files 'org-restrict
  5062. (list (buffer-file-name (buffer-base-buffer))))
  5063. (org-back-to-heading t)
  5064. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5065. (move-marker org-agenda-restrict-begin (point))
  5066. (move-marker org-agenda-restrict-end
  5067. (save-excursion (org-end-of-subtree t)))
  5068. (message "Locking agenda restriction to subtree"))
  5069. (put 'org-agenda-files 'org-restrict
  5070. (list (buffer-file-name (buffer-base-buffer))))
  5071. (setq org-agenda-restrict nil)
  5072. (setq org-agenda-overriding-restriction 'file)
  5073. (move-marker org-agenda-restrict-begin nil)
  5074. (move-marker org-agenda-restrict-end nil)
  5075. (message "Locking agenda restriction to file"))
  5076. (setq current-prefix-arg nil)
  5077. (org-agenda-maybe-redo))
  5078. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5079. "Remove the agenda restriction lock."
  5080. (interactive "P")
  5081. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5082. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5083. (setq org-agenda-overriding-restriction nil)
  5084. (setq org-agenda-restrict nil)
  5085. (put 'org-agenda-files 'org-restrict nil)
  5086. (move-marker org-agenda-restrict-begin nil)
  5087. (move-marker org-agenda-restrict-end nil)
  5088. (setq current-prefix-arg nil)
  5089. (message "Agenda restriction lock removed")
  5090. (or noupdate (org-agenda-maybe-redo)))
  5091. (defun org-agenda-maybe-redo ()
  5092. "If there is any window showing the agenda view, update it."
  5093. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5094. (w0 (selected-window)))
  5095. (when w
  5096. (select-window w)
  5097. (org-agenda-redo)
  5098. (select-window w0)
  5099. (if org-agenda-overriding-restriction
  5100. (message "Agenda view shifted to new %s restriction"
  5101. org-agenda-overriding-restriction)
  5102. (message "Agenda restriction lock removed")))))
  5103. ;;; Agenda commands
  5104. (defun org-agenda-check-type (error &rest types)
  5105. "Check if agenda buffer is of allowed type.
  5106. If ERROR is non-nil, throw an error, otherwise just return nil."
  5107. (if (memq org-agenda-type types)
  5108. t
  5109. (if error
  5110. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5111. nil)))
  5112. (defun org-agenda-quit ()
  5113. "Exit agenda by removing the window or the buffer."
  5114. (interactive)
  5115. (if org-agenda-columns-active
  5116. (org-columns-quit)
  5117. (let ((buf (current-buffer)))
  5118. (if (eq org-agenda-window-setup 'other-frame)
  5119. (progn
  5120. (kill-buffer buf)
  5121. (org-agenda-reset-markers)
  5122. (org-columns-remove-overlays)
  5123. (setq org-agenda-archives-mode nil)
  5124. (delete-frame))
  5125. (and (not (eq org-agenda-window-setup 'current-window))
  5126. (not (one-window-p))
  5127. (delete-window))
  5128. (kill-buffer buf)
  5129. (org-agenda-reset-markers)
  5130. (org-columns-remove-overlays)
  5131. (setq org-agenda-archives-mode nil)))
  5132. ;; Maybe restore the pre-agenda window configuration.
  5133. (and org-agenda-restore-windows-after-quit
  5134. (not (eq org-agenda-window-setup 'other-frame))
  5135. org-pre-agenda-window-conf
  5136. (set-window-configuration org-pre-agenda-window-conf))))
  5137. (defun org-agenda-exit ()
  5138. "Exit agenda by removing the window or the buffer.
  5139. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5140. Org-mode buffers visited directly by the user will not be touched."
  5141. (interactive)
  5142. (org-release-buffers org-agenda-new-buffers)
  5143. (setq org-agenda-new-buffers nil)
  5144. (org-agenda-quit))
  5145. (defun org-agenda-execute (arg)
  5146. "Execute another agenda command, keeping same window.
  5147. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5148. in the agenda."
  5149. (interactive "P")
  5150. (let ((org-agenda-window-setup 'current-window))
  5151. (org-agenda arg)))
  5152. (defun org-agenda-redo ()
  5153. "Rebuild Agenda.
  5154. When this is the global TODO list, a prefix argument will be interpreted."
  5155. (interactive)
  5156. (let* ((org-agenda-keep-modes t)
  5157. (filter org-agenda-filter)
  5158. (preset (get 'org-agenda-filter :preset-filter))
  5159. (cols org-agenda-columns-active)
  5160. (line (org-current-line))
  5161. (window-line (- line (org-current-line (window-start))))
  5162. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5163. (put 'org-agenda-filter :preset-filter nil)
  5164. (and cols (org-columns-quit))
  5165. (message "Rebuilding agenda buffer...")
  5166. (org-let lprops '(eval org-agenda-redo-command))
  5167. (setq org-agenda-undo-list nil
  5168. org-agenda-pending-undo-list nil)
  5169. (message "Rebuilding agenda buffer...done")
  5170. (put 'org-agenda-filter :preset-filter preset)
  5171. (and (or filter preset) (org-agenda-filter-apply filter))
  5172. (and cols (interactive-p) (org-agenda-columns))
  5173. (org-goto-line line)
  5174. (recenter window-line)))
  5175. (defvar org-global-tags-completion-table nil)
  5176. (defvar org-agenda-filter-form nil)
  5177. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5178. "Keep only those lines in the agenda buffer that have a specific tag.
  5179. The tag is selected with its fast selection letter, as configured.
  5180. With prefix argument STRIP, remove all lines that do have the tag.
  5181. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5182. used to narrow the search - the interactive user can also press `-' or `+'
  5183. to switch to narrowing."
  5184. (interactive "P")
  5185. (let* ((alist org-tag-alist-for-agenda)
  5186. (tag-chars (mapconcat
  5187. (lambda (x) (if (and (not (symbolp (car x)))
  5188. (cdr x))
  5189. (char-to-string (cdr x))
  5190. ""))
  5191. alist ""))
  5192. (efforts (org-split-string
  5193. (or (cdr (assoc (concat org-effort-property "_ALL")
  5194. org-global-properties))
  5195. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5196. (effort-op org-agenda-filter-effort-default-operator)
  5197. (effort-prompt "")
  5198. (inhibit-read-only t)
  5199. (current org-agenda-filter)
  5200. a n tag)
  5201. (unless char
  5202. (message
  5203. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5204. (if narrow "Narrow" "Filter") tag-chars
  5205. (if org-agenda-auto-exclude-function "[RET], " ""))
  5206. (setq char (read-char)))
  5207. (when (member char '(?+ ?-))
  5208. ;; Narrowing down
  5209. (cond ((equal char ?-) (setq strip t narrow t))
  5210. ((equal char ?+) (setq strip nil narrow t)))
  5211. (message
  5212. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5213. (setq char (read-char)))
  5214. (when (member char '(?< ?> ?= ??))
  5215. ;; An effort operator
  5216. (setq effort-op (char-to-string char))
  5217. (setq alist nil) ; to make sure it will be interpreted as effort.
  5218. (unless (equal char ??)
  5219. (loop for i from 0 to 9 do
  5220. (setq effort-prompt
  5221. (concat
  5222. effort-prompt " ["
  5223. (if (= i 9) "0" (int-to-string (1+ i)))
  5224. "]" (nth i efforts))))
  5225. (message "Effort%s: %s " effort-op effort-prompt)
  5226. (setq char (read-char))
  5227. (when (or (< char ?0) (> char ?9))
  5228. (error "Need 1-9,0 to select effort" ))))
  5229. (when (equal char ?\t)
  5230. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5231. (org-set-local 'org-global-tags-completion-table
  5232. (org-global-tags-completion-table)))
  5233. (let ((completion-ignore-case t))
  5234. (setq tag (org-icompleting-read
  5235. "Tag: " org-global-tags-completion-table))))
  5236. (cond
  5237. ((equal char ?\r)
  5238. (org-agenda-filter-by-tag-show-all)
  5239. (when org-agenda-auto-exclude-function
  5240. (setq org-agenda-filter '())
  5241. (dolist (tag (org-agenda-get-represented-tags))
  5242. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5243. (if modifier
  5244. (push modifier org-agenda-filter))))
  5245. (if (not (null org-agenda-filter))
  5246. (org-agenda-filter-apply org-agenda-filter))))
  5247. ((equal char ?/)
  5248. (org-agenda-filter-by-tag-show-all)
  5249. (when (get 'org-agenda-filter :preset-filter)
  5250. (org-agenda-filter-apply org-agenda-filter)))
  5251. ((or (equal char ?\ )
  5252. (setq a (rassoc char alist))
  5253. (and (>= char ?0) (<= char ?9)
  5254. (setq n (if (= char ?0) 9 (- char ?0 1))
  5255. tag (concat effort-op (nth n efforts))
  5256. a (cons tag nil)))
  5257. (and (= char ??)
  5258. (setq tag "?eff")
  5259. a (cons tag nil))
  5260. (and tag (setq a (cons tag nil))))
  5261. (org-agenda-filter-by-tag-show-all)
  5262. (setq tag (car a))
  5263. (setq org-agenda-filter
  5264. (cons (concat (if strip "-" "+") tag)
  5265. (if narrow current nil)))
  5266. (org-agenda-filter-apply org-agenda-filter))
  5267. (t (error "Invalid tag selection character %c" char)))))
  5268. (defun org-agenda-get-represented-tags ()
  5269. "Get a list of all tags currently represented in the agenda."
  5270. (let (p tags)
  5271. (save-excursion
  5272. (goto-char (point-min))
  5273. (while (setq p (next-single-property-change (point) 'tags))
  5274. (goto-char p)
  5275. (mapc (lambda (x) (add-to-list 'tags x))
  5276. (get-text-property (point) 'tags))))
  5277. tags))
  5278. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5279. "Refine the current filter. See `org-agenda-filter-by-tag."
  5280. (interactive "P")
  5281. (org-agenda-filter-by-tag strip char 'refine))
  5282. (defun org-agenda-filter-make-matcher ()
  5283. "Create the form that tests a line for the agenda filter."
  5284. (let (f f1)
  5285. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5286. org-agenda-filter))
  5287. (if (member x '("-" "+"))
  5288. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5289. (if (string-match "[<=>?]" x)
  5290. (setq f1 (org-agenda-filter-effort-form x))
  5291. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5292. (if (equal (string-to-char x) ?-)
  5293. (setq f1 (list 'not f1))))
  5294. (push f1 f))
  5295. (cons 'and (nreverse f))))
  5296. (defun org-agenda-filter-effort-form (e)
  5297. "Return the form to compare the effort of the current line with what E says.
  5298. E looks like \"+<2:25\"."
  5299. (let (op)
  5300. (setq e (substring e 1))
  5301. (setq op (string-to-char e) e (substring e 1))
  5302. (setq op (cond ((equal op ?<) '<=)
  5303. ((equal op ?>) '>=)
  5304. ((equal op ??) op)
  5305. (t '=)))
  5306. (list 'org-agenda-compare-effort (list 'quote op)
  5307. (org-hh:mm-string-to-minutes e))))
  5308. (defun org-agenda-compare-effort (op value)
  5309. "Compare the effort of the current line with VALUE, using OP.
  5310. If the line does not have an effort defined, return nil."
  5311. (let ((eff (org-get-at-bol 'effort-minutes)))
  5312. (if (equal op ??)
  5313. (not eff)
  5314. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5315. value))))
  5316. (defun org-agenda-filter-apply (filter)
  5317. "Set FILTER as the new agenda filter and apply it."
  5318. (let (tags)
  5319. (setq org-agenda-filter filter
  5320. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5321. (org-agenda-set-mode-name)
  5322. (save-excursion
  5323. (goto-char (point-min))
  5324. (while (not (eobp))
  5325. (if (org-get-at-bol 'org-marker)
  5326. (progn
  5327. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5328. (if (not (eval org-agenda-filter-form))
  5329. (org-agenda-filter-by-tag-hide-line))
  5330. (beginning-of-line 2))
  5331. (beginning-of-line 2))))))
  5332. (defun org-agenda-filter-by-tag-hide-line ()
  5333. (let (ov)
  5334. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5335. (point-at-eol)))
  5336. (overlay-put ov 'invisible t)
  5337. (overlay-put ov 'type 'tags-filter)
  5338. (push ov org-agenda-filter-overlays)))
  5339. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5340. (setq pos (or pos (point)))
  5341. (save-excursion
  5342. (dolist (ov (overlays-at pos))
  5343. (when (and (overlay-get ov 'invisible)
  5344. (eq (overlay-get ov 'type) 'tags-filter))
  5345. (goto-char pos)
  5346. (if (< (overlay-start ov) (point-at-eol))
  5347. (move-overlay ov (point-at-eol)
  5348. (overlay-end ov)))))))
  5349. (defun org-agenda-filter-by-tag-show-all ()
  5350. (mapc 'delete-overlay org-agenda-filter-overlays)
  5351. (setq org-agenda-filter-overlays nil)
  5352. (setq org-agenda-filter nil)
  5353. (setq org-agenda-filter-form nil)
  5354. (org-agenda-set-mode-name))
  5355. (defun org-agenda-manipulate-query-add ()
  5356. "Manipulate the query by adding a search term with positive selection.
  5357. Positive selection means the term must be matched for selection of an entry."
  5358. (interactive)
  5359. (org-agenda-manipulate-query ?\[))
  5360. (defun org-agenda-manipulate-query-subtract ()
  5361. "Manipulate the query by adding a search term with negative selection.
  5362. Negative selection means term must not be matched for selection of an entry."
  5363. (interactive)
  5364. (org-agenda-manipulate-query ?\]))
  5365. (defun org-agenda-manipulate-query-add-re ()
  5366. "Manipulate the query by adding a search regexp with positive selection.
  5367. Positive selection means the regexp must match for selection of an entry."
  5368. (interactive)
  5369. (org-agenda-manipulate-query ?\{))
  5370. (defun org-agenda-manipulate-query-subtract-re ()
  5371. "Manipulate the query by adding a search regexp with negative selection.
  5372. Negative selection means regexp must not match for selection of an entry."
  5373. (interactive)
  5374. (org-agenda-manipulate-query ?\}))
  5375. (defun org-agenda-manipulate-query (char)
  5376. (cond
  5377. ((memq org-agenda-type '(timeline agenda))
  5378. (let ((org-agenda-include-inactive-timestamps t))
  5379. (org-agenda-redo))
  5380. (message "Display now includes inactive timestamps as well"))
  5381. ((eq org-agenda-type 'search)
  5382. (org-add-to-string
  5383. 'org-agenda-query-string
  5384. (if org-agenda-last-search-view-search-was-boolean
  5385. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5386. (?\{ . " +{}") (?\} . " -{}"))))
  5387. " "))
  5388. (setq org-agenda-redo-command
  5389. (list 'org-search-view
  5390. org-todo-only
  5391. org-agenda-query-string
  5392. (+ (length org-agenda-query-string)
  5393. (if (member char '(?\{ ?\})) 0 1))))
  5394. (set-register org-agenda-query-register org-agenda-query-string)
  5395. (org-agenda-redo))
  5396. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5397. org-agenda-type))))
  5398. (defun org-add-to-string (var string)
  5399. (set var (concat (symbol-value var) string)))
  5400. (defun org-agenda-goto-date (date)
  5401. "Jump to DATE in agenda."
  5402. (interactive (list (org-read-date)))
  5403. (org-agenda-list nil date))
  5404. (defun org-agenda-goto-today ()
  5405. "Go to today."
  5406. (interactive)
  5407. (org-agenda-check-type t 'timeline 'agenda)
  5408. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5409. (cond
  5410. (tdpos (goto-char tdpos))
  5411. ((eq org-agenda-type 'agenda)
  5412. (let* ((sd (time-to-days
  5413. (time-subtract (current-time)
  5414. (list 0 (* 3600 org-extend-today-until) 0))))
  5415. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5416. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5417. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5418. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5419. (org-agenda-redo)
  5420. (org-agenda-find-same-or-today-or-agenda)))
  5421. (t (error "Cannot find today")))))
  5422. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5423. (goto-char
  5424. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5425. (text-property-any (point-min) (point-max) 'org-today t)
  5426. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5427. (point-min))))
  5428. (defun org-agenda-later (arg)
  5429. "Go forward in time by thee current span.
  5430. With prefix ARG, go forward that many times the current span."
  5431. (interactive "p")
  5432. (org-agenda-check-type t 'agenda)
  5433. (let* ((span org-agenda-span)
  5434. (sd org-starting-day)
  5435. (greg (calendar-gregorian-from-absolute sd))
  5436. (cnt (org-get-at-bol 'org-day-cnt))
  5437. greg2 nd)
  5438. (cond
  5439. ((eq span 'day)
  5440. (setq sd (+ arg sd) nd 1))
  5441. ((eq span 'week)
  5442. (setq sd (+ (* 7 arg) sd) nd 7))
  5443. ((eq span 'month)
  5444. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5445. sd (calendar-absolute-from-gregorian greg2))
  5446. (setcar greg2 (1+ (car greg2)))
  5447. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5448. ((eq span 'year)
  5449. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5450. sd (calendar-absolute-from-gregorian greg2))
  5451. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5452. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5453. (let ((org-agenda-overriding-arguments
  5454. (list (car org-agenda-last-arguments) sd nd t)))
  5455. (org-agenda-redo)
  5456. (org-agenda-find-same-or-today-or-agenda cnt))))
  5457. (defun org-agenda-earlier (arg)
  5458. "Go backward in time by the current span.
  5459. With prefix ARG, go backward that many times the current span."
  5460. (interactive "p")
  5461. (org-agenda-later (- arg)))
  5462. (defun org-agenda-view-mode-dispatch ()
  5463. "Call one of the view mode commands."
  5464. (interactive)
  5465. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5466. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5467. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5468. (let ((a (read-char-exclusive)))
  5469. (case a
  5470. (?d (call-interactively 'org-agenda-day-view))
  5471. (?w (call-interactively 'org-agenda-week-view))
  5472. (?m (call-interactively 'org-agenda-month-view))
  5473. (?y (call-interactively 'org-agenda-year-view))
  5474. (?l (call-interactively 'org-agenda-log-mode))
  5475. (?L (org-agenda-log-mode '(4)))
  5476. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5477. (?a (call-interactively 'org-agenda-archives-mode))
  5478. (?A (org-agenda-archives-mode 'files))
  5479. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5480. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5481. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5482. (?D (call-interactively 'org-agenda-toggle-diary))
  5483. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5484. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5485. (org-agenda-check-type t 'timeline 'agenda)
  5486. (org-agenda-redo))
  5487. (message "Display now includes inactive timestamps as well"))
  5488. (?q (message "Abort"))
  5489. (otherwise (error "Invalid key" )))))
  5490. (defun org-agenda-day-view (&optional day-of-year)
  5491. "Switch to daily view for agenda.
  5492. With argument DAY-OF-YEAR, switch to that day of the year."
  5493. (interactive "P")
  5494. (setq org-agenda-ndays 1)
  5495. (org-agenda-change-time-span 'day day-of-year))
  5496. (defun org-agenda-week-view (&optional iso-week)
  5497. "Switch to daily view for agenda.
  5498. With argument ISO-WEEK, switch to the corresponding ISO week.
  5499. If ISO-WEEK has more then 2 digits, only the last two encode the
  5500. week. Any digits before this encode a year. So 200712 means
  5501. week 12 of year 2007. Years in the range 1938-2037 can also be
  5502. written as 2-digit years."
  5503. (interactive "P")
  5504. (setq org-agenda-ndays 7)
  5505. (org-agenda-change-time-span 'week iso-week))
  5506. (defun org-agenda-month-view (&optional month)
  5507. "Switch to monthly view for agenda.
  5508. With argument MONTH, switch to that month."
  5509. (interactive "P")
  5510. (org-agenda-change-time-span 'month month))
  5511. (defun org-agenda-year-view (&optional year)
  5512. "Switch to yearly view for agenda.
  5513. With argument YEAR, switch to that year.
  5514. If MONTH has more then 2 digits, only the last two encode the
  5515. month. Any digits before this encode a year. So 200712 means
  5516. December year 2007. Years in the range 1938-2037 can also be
  5517. written as 2-digit years."
  5518. (interactive "P")
  5519. (when year
  5520. (setq year (org-small-year-to-year year)))
  5521. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5522. (org-agenda-change-time-span 'year year)
  5523. (error "Abort")))
  5524. (defun org-agenda-change-time-span (span &optional n)
  5525. "Change the agenda view to SPAN.
  5526. SPAN may be `day', `week', `month', `year'."
  5527. (org-agenda-check-type t 'agenda)
  5528. (if (and (not n) (equal org-agenda-span span))
  5529. (error "Viewing span is already \"%s\"" span))
  5530. (let* ((sd (or (org-get-at-bol 'day)
  5531. org-starting-day))
  5532. (computed (org-agenda-compute-time-span sd span n))
  5533. (org-agenda-overriding-arguments
  5534. (list (car org-agenda-last-arguments)
  5535. (car computed) (cdr computed) t)))
  5536. (org-agenda-redo)
  5537. (org-agenda-find-same-or-today-or-agenda))
  5538. (org-agenda-set-mode-name)
  5539. (message "Switched to %s view" span))
  5540. (defun org-agenda-compute-time-span (sd span &optional n)
  5541. "Compute starting date and number of days for agenda.
  5542. SPAN may be `day', `week', `month', `year'. The return value
  5543. is a cons cell with the starting date and the number of days,
  5544. so that the date SD will be in that range."
  5545. (let* ((greg (calendar-gregorian-from-absolute sd))
  5546. (dg (nth 1 greg))
  5547. (mg (car greg))
  5548. (yg (nth 2 greg))
  5549. nd w1 y1 m1 thisweek)
  5550. (cond
  5551. ((eq span 'day)
  5552. (when n
  5553. (setq sd (+ (calendar-absolute-from-gregorian
  5554. (list mg 1 yg))
  5555. n -1)))
  5556. (setq nd 1))
  5557. ((eq span 'week)
  5558. (let* ((nt (calendar-day-of-week
  5559. (calendar-gregorian-from-absolute sd)))
  5560. (d (if org-agenda-start-on-weekday
  5561. (- nt org-agenda-start-on-weekday)
  5562. 0)))
  5563. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5564. (when n
  5565. (require 'cal-iso)
  5566. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5567. (when (> n 99)
  5568. (setq y1 (org-small-year-to-year (/ n 100))
  5569. n (mod n 100)))
  5570. (setq sd
  5571. (calendar-absolute-from-iso
  5572. (list n 1
  5573. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5574. (setq nd 7)))
  5575. ((eq span 'month)
  5576. (when (and n (> n 99))
  5577. (setq y1 (org-small-year-to-year (/ n 100))
  5578. n (mod n 100)))
  5579. (setq sd (calendar-absolute-from-gregorian
  5580. (list (or n mg) 1 (or y1 yg)))
  5581. nd (- (calendar-absolute-from-gregorian
  5582. (list (1+ (or n mg)) 1 (or y1 yg)))
  5583. sd)))
  5584. ((eq span 'year)
  5585. (setq sd (calendar-absolute-from-gregorian
  5586. (list 1 1 (or n yg)))
  5587. nd (- (calendar-absolute-from-gregorian
  5588. (list 1 1 (1+ (or n yg))))
  5589. sd))))
  5590. (cons sd nd)))
  5591. (defun org-agenda-next-date-line (&optional arg)
  5592. "Jump to the next line indicating a date in agenda buffer."
  5593. (interactive "p")
  5594. (org-agenda-check-type t 'agenda 'timeline)
  5595. (beginning-of-line 1)
  5596. ;; This does not work if user makes date format that starts with a blank
  5597. (if (looking-at "^\\S-") (forward-char 1))
  5598. (if (not (re-search-forward "^\\S-" nil t arg))
  5599. (progn
  5600. (backward-char 1)
  5601. (error "No next date after this line in this buffer")))
  5602. (goto-char (match-beginning 0)))
  5603. (defun org-agenda-previous-date-line (&optional arg)
  5604. "Jump to the previous line indicating a date in agenda buffer."
  5605. (interactive "p")
  5606. (org-agenda-check-type t 'agenda 'timeline)
  5607. (beginning-of-line 1)
  5608. (if (not (re-search-backward "^\\S-" nil t arg))
  5609. (error "No previous date before this line in this buffer")))
  5610. ;; Initialize the highlight
  5611. (defvar org-hl (make-overlay 1 1))
  5612. (overlay-put org-hl 'face 'highlight)
  5613. (defun org-highlight (begin end &optional buffer)
  5614. "Highlight a region with overlay."
  5615. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5616. (defun org-unhighlight ()
  5617. "Detach overlay INDEX."
  5618. (org-detach-overlay org-hl))
  5619. ;; FIXME this is currently not used.
  5620. (defun org-highlight-until-next-command (beg end &optional buffer)
  5621. "Move the highlight overlay to BEG/END, remove it before the next command."
  5622. (org-highlight beg end buffer)
  5623. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5624. (defun org-unhighlight-once ()
  5625. "Remove the highlight from its position, and this function from the hook."
  5626. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5627. (org-unhighlight))
  5628. (defun org-agenda-follow-mode ()
  5629. "Toggle follow mode in an agenda buffer."
  5630. (interactive)
  5631. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5632. (org-agenda-set-mode-name)
  5633. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5634. (org-agenda-show))
  5635. (message "Follow mode is %s"
  5636. (if org-agenda-follow-mode "on" "off")))
  5637. (defun org-agenda-entry-text-mode (&optional arg)
  5638. "Toggle entry text mode in an agenda buffer."
  5639. (interactive "P")
  5640. (setq org-agenda-entry-text-mode (or (integerp arg)
  5641. (not org-agenda-entry-text-mode)))
  5642. (org-agenda-entry-text-hide)
  5643. (and org-agenda-entry-text-mode
  5644. (let ((org-agenda-entry-text-maxlines
  5645. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5646. (org-agenda-entry-text-show)))
  5647. (org-agenda-set-mode-name)
  5648. (message "Entry text mode is %s. Maximum number of lines is %d"
  5649. (if org-agenda-entry-text-mode "on" "off")
  5650. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5651. (defun org-agenda-clockreport-mode ()
  5652. "Toggle clocktable mode in an agenda buffer."
  5653. (interactive)
  5654. (org-agenda-check-type t 'agenda)
  5655. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5656. (org-agenda-set-mode-name)
  5657. (org-agenda-redo)
  5658. (message "Clocktable mode is %s"
  5659. (if org-agenda-clockreport-mode "on" "off")))
  5660. (defun org-agenda-log-mode (&optional special)
  5661. "Toggle log mode in an agenda buffer.
  5662. With argument SPECIAL, show all possible log items, not only the ones
  5663. configured in `org-agenda-log-mode-items'.
  5664. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5665. (interactive "P")
  5666. (org-agenda-check-type t 'agenda 'timeline)
  5667. (setq org-agenda-show-log
  5668. (if (equal special '(16))
  5669. 'only
  5670. (if special '(closed clock state)
  5671. (not org-agenda-show-log))))
  5672. (org-agenda-set-mode-name)
  5673. (org-agenda-redo)
  5674. (message "Log mode is %s"
  5675. (if org-agenda-show-log "on" "off")))
  5676. (defun org-agenda-archives-mode (&optional with-files)
  5677. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5678. When called with a prefix argument, include all archive files as well."
  5679. (interactive "P")
  5680. (setq org-agenda-archives-mode
  5681. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5682. (org-agenda-set-mode-name)
  5683. (org-agenda-redo)
  5684. (message
  5685. "%s"
  5686. (cond
  5687. ((eq org-agenda-archives-mode nil)
  5688. "No archives are included")
  5689. ((eq org-agenda-archives-mode 'trees)
  5690. (format "Trees with :%s: tag are included" org-archive-tag))
  5691. ((eq org-agenda-archives-mode t)
  5692. (format "Trees with :%s: tag and all active archive files are included"
  5693. org-archive-tag)))))
  5694. (defun org-agenda-toggle-diary ()
  5695. "Toggle diary inclusion in an agenda buffer."
  5696. (interactive)
  5697. (org-agenda-check-type t 'agenda)
  5698. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5699. (org-agenda-redo)
  5700. (org-agenda-set-mode-name)
  5701. (message "Diary inclusion turned %s"
  5702. (if org-agenda-include-diary "on" "off")))
  5703. (defun org-agenda-toggle-deadlines ()
  5704. "Toggle diary inclusion in an agenda buffer."
  5705. (interactive)
  5706. (org-agenda-check-type t 'agenda)
  5707. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5708. (org-agenda-redo)
  5709. (org-agenda-set-mode-name)
  5710. (message "Deadlines inclusion turned %s"
  5711. (if org-agenda-include-deadlines "on" "off")))
  5712. (defun org-agenda-toggle-time-grid ()
  5713. "Toggle time grid in an agenda buffer."
  5714. (interactive)
  5715. (org-agenda-check-type t 'agenda)
  5716. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5717. (org-agenda-redo)
  5718. (org-agenda-set-mode-name)
  5719. (message "Time-grid turned %s"
  5720. (if org-agenda-use-time-grid "on" "off")))
  5721. (defun org-agenda-set-mode-name ()
  5722. "Set the mode name to indicate all the small mode settings."
  5723. (setq mode-name
  5724. (concat "Org-Agenda"
  5725. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5726. (if (equal org-agenda-ndays 1) " Day" "")
  5727. (if (equal org-agenda-ndays 7) " Week" "")
  5728. (if org-agenda-follow-mode " Follow" "")
  5729. (if org-agenda-entry-text-mode " ETxt" "")
  5730. (if org-agenda-include-diary " Diary" "")
  5731. (if org-agenda-include-deadlines " Ddl" "")
  5732. (if org-agenda-use-time-grid " Grid" "")
  5733. (if (and (boundp 'org-habit-show-habits)
  5734. org-habit-show-habits) " Habit" "")
  5735. (if (consp org-agenda-show-log) " LogAll"
  5736. (if org-agenda-show-log " Log" ""))
  5737. (if (or org-agenda-filter (get 'org-agenda-filter
  5738. :preset-filter))
  5739. (concat " {" (mapconcat
  5740. 'identity
  5741. (append (get 'org-agenda-filter
  5742. :preset-filter)
  5743. org-agenda-filter) "") "}")
  5744. "")
  5745. (if org-agenda-archives-mode
  5746. (if (eq org-agenda-archives-mode t)
  5747. " Archives"
  5748. (format " :%s:" org-archive-tag))
  5749. "")
  5750. (if org-agenda-clockreport-mode " Clock" "")))
  5751. (force-mode-line-update))
  5752. (defun org-agenda-post-command-hook ()
  5753. (setq org-agenda-type
  5754. (or (get-text-property (point) 'org-agenda-type)
  5755. (get-text-property (max (point-min) (1- (point)))
  5756. 'org-agenda-type))))
  5757. (defun org-agenda-next-line ()
  5758. "Move cursor to the next line, and show if follow mode is active."
  5759. (interactive)
  5760. (call-interactively 'next-line)
  5761. (org-agenda-do-context-action))
  5762. (defun org-agenda-previous-line ()
  5763. "Move cursor to the previous line, and show if follow-mode is active."
  5764. (interactive)
  5765. (call-interactively 'previous-line)
  5766. (org-agenda-do-context-action))
  5767. (defun org-agenda-do-context-action ()
  5768. "Show outline path and, maybe, follow mode window."
  5769. (let ((m (org-get-at-bol 'org-marker)))
  5770. (if (and org-agenda-follow-mode m)
  5771. (org-agenda-show))
  5772. (if (and m org-agenda-show-outline-path)
  5773. (org-with-point-at m
  5774. (org-display-outline-path t)))))
  5775. (defun org-agenda-show-priority ()
  5776. "Show the priority of the current item.
  5777. This priority is composed of the main priority given with the [#A] cookies,
  5778. and by additional input from the age of a schedules or deadline entry."
  5779. (interactive)
  5780. (let* ((pri (org-get-at-bol 'priority)))
  5781. (message "Priority is %d" (if pri pri -1000))))
  5782. (defun org-agenda-show-tags ()
  5783. "Show the tags applicable to the current item."
  5784. (interactive)
  5785. (let* ((tags (org-get-at-bol 'tags)))
  5786. (if tags
  5787. (message "Tags are :%s:"
  5788. (org-no-properties (mapconcat 'identity tags ":")))
  5789. (message "No tags associated with this line"))))
  5790. (defun org-agenda-goto (&optional highlight)
  5791. "Go to the Org-mode file which contains the item at point."
  5792. (interactive)
  5793. (let* ((marker (or (org-get-at-bol 'org-marker)
  5794. (org-agenda-error)))
  5795. (buffer (marker-buffer marker))
  5796. (pos (marker-position marker)))
  5797. (switch-to-buffer-other-window buffer)
  5798. (widen)
  5799. (push-mark)
  5800. (goto-char pos)
  5801. (when (org-mode-p)
  5802. (org-show-context 'agenda)
  5803. (save-excursion
  5804. (and (outline-next-heading)
  5805. (org-flag-heading nil)))) ; show the next heading
  5806. (recenter (/ (window-height) 2))
  5807. (run-hooks 'org-agenda-after-show-hook)
  5808. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5809. (defvar org-agenda-after-show-hook nil
  5810. "Normal hook run after an item has been shown from the agenda.
  5811. Point is in the buffer where the item originated.")
  5812. (defun org-agenda-kill ()
  5813. "Kill the entry or subtree belonging to the current agenda entry."
  5814. (interactive)
  5815. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5816. (let* ((marker (or (org-get-at-bol 'org-marker)
  5817. (org-agenda-error)))
  5818. (buffer (marker-buffer marker))
  5819. (pos (marker-position marker))
  5820. (type (org-get-at-bol 'type))
  5821. dbeg dend (n 0) conf)
  5822. (org-with-remote-undo buffer
  5823. (with-current-buffer buffer
  5824. (save-excursion
  5825. (goto-char pos)
  5826. (if (and (org-mode-p) (not (member type '("sexp"))))
  5827. (setq dbeg (progn (org-back-to-heading t) (point))
  5828. dend (org-end-of-subtree t t))
  5829. (setq dbeg (point-at-bol)
  5830. dend (min (point-max) (1+ (point-at-eol)))))
  5831. (goto-char dbeg)
  5832. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5833. (setq conf (or (eq t org-agenda-confirm-kill)
  5834. (and (numberp org-agenda-confirm-kill)
  5835. (> n org-agenda-confirm-kill))))
  5836. (and conf
  5837. (not (y-or-n-p
  5838. (format "Delete entry with %d lines in buffer \"%s\"? "
  5839. n (buffer-name buffer))))
  5840. (error "Abort"))
  5841. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5842. (with-current-buffer buffer (delete-region dbeg dend))
  5843. (message "Agenda item and source killed"))))
  5844. (defvar org-archive-default-command)
  5845. (defun org-agenda-archive-default ()
  5846. "Archive the entry or subtree belonging to the current agenda entry."
  5847. (interactive)
  5848. (require 'org-archive)
  5849. (org-agenda-archive-with org-archive-default-command))
  5850. (defun org-agenda-archive-default-with-confirmation ()
  5851. "Archive the entry or subtree belonging to the current agenda entry."
  5852. (interactive)
  5853. (require 'org-archive)
  5854. (org-agenda-archive-with org-archive-default-command 'confirm))
  5855. (defun org-agenda-archive ()
  5856. "Archive the entry or subtree belonging to the current agenda entry."
  5857. (interactive)
  5858. (org-agenda-archive-with 'org-archive-subtree))
  5859. (defun org-agenda-archive-to-archive-sibling ()
  5860. "Move the entry to the archive sibling."
  5861. (interactive)
  5862. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5863. (defun org-agenda-archive-with (cmd &optional confirm)
  5864. "Move the entry to the archive sibling."
  5865. (interactive)
  5866. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5867. (let* ((marker (or (org-get-at-bol 'org-marker)
  5868. (org-agenda-error)))
  5869. (buffer (marker-buffer marker))
  5870. (pos (marker-position marker)))
  5871. (org-with-remote-undo buffer
  5872. (with-current-buffer buffer
  5873. (if (org-mode-p)
  5874. (if (and confirm
  5875. (not (y-or-n-p "Archive this subtree or entry? ")))
  5876. (error "Abort")
  5877. (save-excursion
  5878. (goto-char pos)
  5879. (org-remove-subtree-entries-from-agenda)
  5880. (org-back-to-heading t)
  5881. (funcall cmd)))
  5882. (error "Archiving works only in Org-mode files"))))))
  5883. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5884. "Remove all lines in the agenda that correspond to a given subtree.
  5885. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5886. If this information is not given, the function uses the tree at point."
  5887. (let ((buf (or buf (current-buffer))) m p)
  5888. (save-excursion
  5889. (unless (and beg end)
  5890. (org-back-to-heading t)
  5891. (setq beg (point))
  5892. (org-end-of-subtree t)
  5893. (setq end (point)))
  5894. (set-buffer (get-buffer org-agenda-buffer-name))
  5895. (save-excursion
  5896. (goto-char (point-max))
  5897. (beginning-of-line 1)
  5898. (while (not (bobp))
  5899. (when (and (setq m (org-get-at-bol 'org-marker))
  5900. (equal buf (marker-buffer m))
  5901. (setq p (marker-position m))
  5902. (>= p beg)
  5903. (< p end))
  5904. (let ((inhibit-read-only t))
  5905. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5906. (beginning-of-line 0))))))
  5907. (defun org-agenda-refile (&optional goto rfloc no-update)
  5908. "Refile the item at point."
  5909. (interactive "P")
  5910. (if (equal goto '(16))
  5911. (org-refile-goto-last-stored)
  5912. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5913. (org-agenda-error)))
  5914. (buffer (marker-buffer marker))
  5915. (pos (marker-position marker))
  5916. (rfloc (or rfloc
  5917. (org-refile-get-location
  5918. (if goto "Goto: " "Refile to: ") buffer
  5919. org-refile-allow-creating-parent-nodes))))
  5920. (with-current-buffer buffer
  5921. (save-excursion
  5922. (save-restriction
  5923. (widen)
  5924. (goto-char marker)
  5925. (org-remove-subtree-entries-from-agenda)
  5926. (org-refile goto buffer rfloc)))))
  5927. (unless no-update (org-agenda-redo))))
  5928. (defun org-agenda-open-link (&optional arg)
  5929. "Follow the link in the current line, if any.
  5930. This looks for a link in the displayed line in the agenda. It also looks
  5931. at the text of the entry itself."
  5932. (interactive "P")
  5933. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5934. (org-get-at-bol 'org-marker)))
  5935. (buffer (and marker (marker-buffer marker)))
  5936. (prefix (buffer-substring
  5937. (point-at-bol)
  5938. (+ (point-at-bol)
  5939. (or (org-get-at-bol 'prefix-length) 0)))))
  5940. (cond
  5941. (buffer
  5942. (with-current-buffer buffer
  5943. (save-excursion
  5944. (save-restriction
  5945. (widen)
  5946. (goto-char marker)
  5947. (org-offer-links-in-entry arg prefix)))))
  5948. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5949. (save-excursion
  5950. (beginning-of-line 1)
  5951. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5952. (org-open-link-from-string (match-string 1)))
  5953. (t (error "No link to open here")))))
  5954. (defun org-agenda-copy-local-variable (var)
  5955. "Get a variable from a referenced buffer and install it here."
  5956. (let ((m (org-get-at-bol 'org-marker)))
  5957. (when (and m (buffer-live-p (marker-buffer m)))
  5958. (org-set-local var (with-current-buffer (marker-buffer m)
  5959. (symbol-value var))))))
  5960. (defun org-agenda-switch-to (&optional delete-other-windows)
  5961. "Go to the Org-mode file which contains the item at point."
  5962. (interactive)
  5963. (if (and org-return-follows-link
  5964. (not (org-get-at-bol 'org-marker))
  5965. (org-in-regexp org-bracket-link-regexp))
  5966. (org-open-link-from-string (match-string 0))
  5967. (let* ((marker (or (org-get-at-bol 'org-marker)
  5968. (org-agenda-error)))
  5969. (buffer (marker-buffer marker))
  5970. (pos (marker-position marker)))
  5971. (switch-to-buffer buffer)
  5972. (and delete-other-windows (delete-other-windows))
  5973. (widen)
  5974. (goto-char pos)
  5975. (when (org-mode-p)
  5976. (org-show-context 'agenda)
  5977. (save-excursion
  5978. (and (outline-next-heading)
  5979. (org-flag-heading nil))))))) ; show the next heading
  5980. (defun org-agenda-goto-mouse (ev)
  5981. "Go to the Org-mode file which contains the item at the mouse click."
  5982. (interactive "e")
  5983. (mouse-set-point ev)
  5984. (org-agenda-goto))
  5985. (defun org-agenda-show (&optional full-entry)
  5986. "Display the Org-mode file which contains the item at point.
  5987. With prefix argument FULL-ENTRY, make the entire entry visible
  5988. if it was hidden in the outline."
  5989. (interactive "P")
  5990. (let ((win (selected-window)))
  5991. (if full-entry
  5992. (let ((org-show-entry-below t))
  5993. (org-agenda-goto t))
  5994. (org-agenda-goto t))
  5995. (select-window win)))
  5996. (defvar org-agenda-show-window nil)
  5997. (defun org-agenda-show-and-scroll-up ()
  5998. "Display the Org-mode file which contains the item at point.
  5999. When called repeatedly, scroll the window that is displaying the buffer."
  6000. (interactive)
  6001. (let ((win (selected-window)))
  6002. (if (and (window-live-p org-agenda-show-window)
  6003. (eq this-command last-command))
  6004. (progn
  6005. (select-window org-agenda-show-window)
  6006. (ignore-errors (scroll-up)))
  6007. (org-agenda-goto t)
  6008. (show-subtree)
  6009. (setq org-agenda-show-window (selected-window)))
  6010. (select-window win)))
  6011. (defun org-agenda-show-scroll-down ()
  6012. "Scroll down the window showing the agenda."
  6013. (interactive)
  6014. (let ((win (selected-window)))
  6015. (when (window-live-p org-agenda-show-window)
  6016. (select-window org-agenda-show-window)
  6017. (ignore-errors (scroll-down))
  6018. (select-window win))))
  6019. (defun org-agenda-show-1 (&optional more)
  6020. "Display the Org-mode file which contains the item at point.
  6021. The prefix arg selects the amount of information to display:
  6022. 0 hide the subtree
  6023. 1 just show the entry according to defaults.
  6024. 2 show the children view
  6025. 3 show the subtree view
  6026. 4 show the entire subtree and any LOGBOOK drawers
  6027. 5 show the entire subtree and any drawers
  6028. With prefix argument FULL-ENTRY, make the entire entry visible
  6029. if it was hidden in the outline."
  6030. (interactive "p")
  6031. (let ((win (selected-window)))
  6032. (org-agenda-goto t)
  6033. (org-recenter-heading 1)
  6034. (cond
  6035. ((= more 0)
  6036. (hide-subtree)
  6037. (save-excursion
  6038. (org-back-to-heading)
  6039. (run-hook-with-args 'org-cycle-hook 'folded))
  6040. (message "Remote: FOLDED"))
  6041. ((and (interactive-p) (= more 1))
  6042. (message "Remote: show with default settings"))
  6043. ((= more 2)
  6044. (show-entry)
  6045. (show-children)
  6046. (save-excursion
  6047. (org-back-to-heading)
  6048. (run-hook-with-args 'org-cycle-hook 'children))
  6049. (message "Remote: CHILDREN"))
  6050. ((= more 3)
  6051. (show-subtree)
  6052. (save-excursion
  6053. (org-back-to-heading)
  6054. (run-hook-with-args 'org-cycle-hook 'subtree))
  6055. (message "Remote: SUBTREE"))
  6056. ((= more 4)
  6057. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6058. (org-drawer-regexp
  6059. (concat "^[ \t]*:\\("
  6060. (mapconcat 'regexp-quote org-drawers "\\|")
  6061. "\\):[ \t]*$")))
  6062. (show-subtree)
  6063. (save-excursion
  6064. (org-back-to-heading)
  6065. (org-cycle-hide-drawers 'subtree)))
  6066. (message "Remote: SUBTREE AND LOGBOOK"))
  6067. ((> more 4)
  6068. (show-subtree)
  6069. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6070. (select-window win)))
  6071. (defun org-recenter-heading (n)
  6072. (save-excursion
  6073. (org-back-to-heading)
  6074. (recenter n)))
  6075. (defvar org-agenda-cycle-counter nil)
  6076. (defun org-agenda-cycle-show (&optional n)
  6077. "Show the current entry in another window, with default settings.
  6078. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6079. When use repeatedly in immediate succession, the remote entry will cycle
  6080. through visibility
  6081. children -> subtree -> folded
  6082. When called with a numeric prefix arg, that arg will be passed through to
  6083. `org-agenda-show-1'. For the interpretation of that argument, see the
  6084. docstring of `org-agenda-show-1'."
  6085. (interactive "P")
  6086. (if (integerp n)
  6087. (setq org-agenda-cycle-counter n)
  6088. (if (not (eq last-command this-command))
  6089. (setq org-agenda-cycle-counter 1)
  6090. (if (equal org-agenda-cycle-counter 0)
  6091. (setq org-agenda-cycle-counter 2)
  6092. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6093. (if (> org-agenda-cycle-counter 3)
  6094. (setq org-agenda-cycle-counter 0)))))
  6095. (org-agenda-show-1 org-agenda-cycle-counter))
  6096. (defun org-agenda-recenter (arg)
  6097. "Display the Org-mode file which contains the item at point and recenter."
  6098. (interactive "P")
  6099. (let ((win (selected-window)))
  6100. (org-agenda-goto t)
  6101. (recenter arg)
  6102. (select-window win)))
  6103. (defun org-agenda-show-mouse (ev)
  6104. "Display the Org-mode file which contains the item at the mouse click."
  6105. (interactive "e")
  6106. (mouse-set-point ev)
  6107. (org-agenda-show))
  6108. (defun org-agenda-check-no-diary ()
  6109. "Check if the entry is a diary link and abort if yes."
  6110. (if (org-get-at-bol 'org-agenda-diary-link)
  6111. (org-agenda-error)))
  6112. (defun org-agenda-error ()
  6113. (error "Command not allowed in this line"))
  6114. (defun org-agenda-tree-to-indirect-buffer ()
  6115. "Show the subtree corresponding to the current entry in an indirect buffer.
  6116. This calls the command `org-tree-to-indirect-buffer' from the original
  6117. Org-mode buffer.
  6118. With numerical prefix arg ARG, go up to this level and then take that tree.
  6119. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6120. use the dedicated frame)."
  6121. (interactive)
  6122. (org-agenda-check-no-diary)
  6123. (let* ((marker (or (org-get-at-bol 'org-marker)
  6124. (org-agenda-error)))
  6125. (buffer (marker-buffer marker))
  6126. (pos (marker-position marker)))
  6127. (with-current-buffer buffer
  6128. (save-excursion
  6129. (goto-char pos)
  6130. (call-interactively 'org-tree-to-indirect-buffer)))))
  6131. (defvar org-last-heading-marker (make-marker)
  6132. "Marker pointing to the headline that last changed its TODO state
  6133. by a remote command from the agenda.")
  6134. (defun org-agenda-todo-nextset ()
  6135. "Switch TODO entry to next sequence."
  6136. (interactive)
  6137. (org-agenda-todo 'nextset))
  6138. (defun org-agenda-todo-previousset ()
  6139. "Switch TODO entry to previous sequence."
  6140. (interactive)
  6141. (org-agenda-todo 'previousset))
  6142. (defun org-agenda-todo (&optional arg)
  6143. "Cycle TODO state of line at point, also in Org-mode file.
  6144. This changes the line at point, all other lines in the agenda referring to
  6145. the same tree node, and the headline of the tree node in the Org-mode file."
  6146. (interactive "P")
  6147. (org-agenda-check-no-diary)
  6148. (let* ((col (current-column))
  6149. (marker (or (org-get-at-bol 'org-marker)
  6150. (org-agenda-error)))
  6151. (buffer (marker-buffer marker))
  6152. (pos (marker-position marker))
  6153. (hdmarker (org-get-at-bol 'org-hd-marker))
  6154. (todayp (equal (org-get-at-bol 'day)
  6155. (time-to-days (current-time))))
  6156. (inhibit-read-only t)
  6157. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6158. (org-with-remote-undo buffer
  6159. (with-current-buffer buffer
  6160. (widen)
  6161. (goto-char pos)
  6162. (org-show-context 'agenda)
  6163. (save-excursion
  6164. (and (outline-next-heading)
  6165. (org-flag-heading nil))) ; show the next heading
  6166. (let ((current-prefix-arg arg))
  6167. (call-interactively 'org-todo))
  6168. (and (bolp) (forward-char 1))
  6169. (setq newhead (org-get-heading))
  6170. (when (and (org-bound-and-true-p
  6171. org-agenda-headline-snapshot-before-repeat)
  6172. (not (equal org-agenda-headline-snapshot-before-repeat
  6173. newhead))
  6174. todayp)
  6175. (setq newhead org-agenda-headline-snapshot-before-repeat
  6176. just-one t))
  6177. (save-excursion
  6178. (org-back-to-heading)
  6179. (move-marker org-last-heading-marker (point))))
  6180. (beginning-of-line 1)
  6181. (save-excursion
  6182. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6183. (org-move-to-column col))))
  6184. (defun org-agenda-add-note (&optional arg)
  6185. "Add a time-stamped note to the entry at point."
  6186. (interactive "P")
  6187. (org-agenda-check-no-diary)
  6188. (let* ((marker (or (org-get-at-bol 'org-marker)
  6189. (org-agenda-error)))
  6190. (buffer (marker-buffer marker))
  6191. (pos (marker-position marker))
  6192. (hdmarker (org-get-at-bol 'org-hd-marker))
  6193. (inhibit-read-only t))
  6194. (with-current-buffer buffer
  6195. (widen)
  6196. (goto-char pos)
  6197. (org-show-context 'agenda)
  6198. (save-excursion
  6199. (and (outline-next-heading)
  6200. (org-flag-heading nil))) ; show the next heading
  6201. (org-add-note))))
  6202. (defun org-agenda-change-all-lines (newhead hdmarker
  6203. &optional fixface just-this)
  6204. "Change all lines in the agenda buffer which match HDMARKER.
  6205. The new content of the line will be NEWHEAD (as modified by
  6206. `org-format-agenda-item'). HDMARKER is checked with
  6207. `equal' against all `org-hd-marker' text properties in the file.
  6208. If FIXFACE is non-nil, the face of each item is modified according to
  6209. the new TODO state.
  6210. If JUST-THIS is non-nil, change just the current line, not all.
  6211. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6212. (let* ((inhibit-read-only t)
  6213. (line (org-current-line))
  6214. (thetags (with-current-buffer (marker-buffer hdmarker)
  6215. (save-excursion (save-restriction (widen)
  6216. (goto-char hdmarker)
  6217. (org-get-tags-at)))))
  6218. props m pl undone-face done-face finish new dotime cat tags)
  6219. (save-excursion
  6220. (goto-char (point-max))
  6221. (beginning-of-line 1)
  6222. (while (not finish)
  6223. (setq finish (bobp))
  6224. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6225. (or (not just-this) (= (org-current-line) line))
  6226. (equal m hdmarker))
  6227. (setq props (text-properties-at (point))
  6228. dotime (org-get-at-bol 'dotime)
  6229. cat (org-get-at-bol 'org-category)
  6230. tags thetags
  6231. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6232. pl (org-get-at-bol 'prefix-length)
  6233. undone-face (org-get-at-bol 'undone-face)
  6234. done-face (org-get-at-bol 'done-face))
  6235. (goto-char (+ (point) pl))
  6236. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6237. (cond
  6238. ((equal new "")
  6239. (beginning-of-line 1)
  6240. (and (looking-at ".*\n?") (replace-match "")))
  6241. ((looking-at ".*")
  6242. (replace-match new t t)
  6243. (beginning-of-line 1)
  6244. (add-text-properties (point-at-bol) (point-at-eol) props)
  6245. (when fixface
  6246. (add-text-properties
  6247. (point-at-bol) (point-at-eol)
  6248. (list 'face
  6249. (if org-last-todo-state-is-todo
  6250. undone-face done-face))))
  6251. (org-agenda-highlight-todo 'line)
  6252. (beginning-of-line 1))
  6253. (t (error "Line update did not work"))))
  6254. (beginning-of-line 0)))
  6255. (org-finalize-agenda)))
  6256. (defun org-agenda-align-tags (&optional line)
  6257. "Align all tags in agenda items to `org-agenda-tags-column'."
  6258. (let ((inhibit-read-only t) l c)
  6259. (save-excursion
  6260. (goto-char (if line (point-at-bol) (point-min)))
  6261. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6262. (if line (point-at-eol) nil) t)
  6263. (add-text-properties
  6264. (match-beginning 2) (match-end 2)
  6265. (list 'face (delq nil (let ((prop (get-text-property
  6266. (match-beginning 2) 'face)))
  6267. (or (listp prop) (setq prop (list prop)))
  6268. (if (memq 'org-tag prop)
  6269. prop
  6270. (cons 'org-tag prop))))))
  6271. (setq l (- (match-end 2) (match-beginning 2))
  6272. c (if (< org-agenda-tags-column 0)
  6273. (- (abs org-agenda-tags-column) l)
  6274. org-agenda-tags-column))
  6275. (delete-region (match-beginning 1) (match-end 1))
  6276. (goto-char (match-beginning 1))
  6277. (insert (org-add-props
  6278. (make-string (max 1 (- c (current-column))) ?\ )
  6279. (plist-put (copy-sequence (text-properties-at (point)))
  6280. 'face nil))))
  6281. (goto-char (point-min))
  6282. (org-font-lock-add-tag-faces (point-max)))))
  6283. (defun org-agenda-priority-up ()
  6284. "Increase the priority of line at point, also in Org-mode file."
  6285. (interactive)
  6286. (org-agenda-priority 'up))
  6287. (defun org-agenda-priority-down ()
  6288. "Decrease the priority of line at point, also in Org-mode file."
  6289. (interactive)
  6290. (org-agenda-priority 'down))
  6291. (defun org-agenda-priority (&optional force-direction)
  6292. "Set the priority of line at point, also in Org-mode file.
  6293. This changes the line at point, all other lines in the agenda referring to
  6294. the same tree node, and the headline of the tree node in the Org-mode file."
  6295. (interactive)
  6296. (unless org-enable-priority-commands
  6297. (error "Priority commands are disabled"))
  6298. (org-agenda-check-no-diary)
  6299. (let* ((marker (or (org-get-at-bol 'org-marker)
  6300. (org-agenda-error)))
  6301. (hdmarker (org-get-at-bol 'org-hd-marker))
  6302. (buffer (marker-buffer hdmarker))
  6303. (pos (marker-position hdmarker))
  6304. (inhibit-read-only t)
  6305. newhead)
  6306. (org-with-remote-undo buffer
  6307. (with-current-buffer buffer
  6308. (widen)
  6309. (goto-char pos)
  6310. (org-show-context 'agenda)
  6311. (save-excursion
  6312. (and (outline-next-heading)
  6313. (org-flag-heading nil))) ; show the next heading
  6314. (funcall 'org-priority force-direction)
  6315. (end-of-line 1)
  6316. (setq newhead (org-get-heading)))
  6317. (org-agenda-change-all-lines newhead hdmarker)
  6318. (beginning-of-line 1))))
  6319. ;; FIXME: should fix the tags property of the agenda line.
  6320. (defun org-agenda-set-tags (&optional tag onoff)
  6321. "Set tags for the current headline."
  6322. (interactive)
  6323. (org-agenda-check-no-diary)
  6324. (if (and (org-region-active-p) (interactive-p))
  6325. (call-interactively 'org-change-tag-in-region)
  6326. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6327. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6328. (org-agenda-error)))
  6329. (buffer (marker-buffer hdmarker))
  6330. (pos (marker-position hdmarker))
  6331. (inhibit-read-only t)
  6332. newhead)
  6333. (org-with-remote-undo buffer
  6334. (with-current-buffer buffer
  6335. (widen)
  6336. (goto-char pos)
  6337. (save-excursion
  6338. (org-show-context 'agenda))
  6339. (save-excursion
  6340. (and (outline-next-heading)
  6341. (org-flag-heading nil))) ; show the next heading
  6342. (goto-char pos)
  6343. (if tag
  6344. (org-toggle-tag tag onoff)
  6345. (call-interactively 'org-set-tags))
  6346. (end-of-line 1)
  6347. (setq newhead (org-get-heading)))
  6348. (org-agenda-change-all-lines newhead hdmarker)
  6349. (beginning-of-line 1)))))
  6350. (defun org-agenda-set-property ()
  6351. "Set a property for the current headline."
  6352. (interactive)
  6353. (org-agenda-check-no-diary)
  6354. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6355. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6356. (org-agenda-error)))
  6357. (buffer (marker-buffer hdmarker))
  6358. (pos (marker-position hdmarker))
  6359. (inhibit-read-only t)
  6360. newhead)
  6361. (org-with-remote-undo buffer
  6362. (with-current-buffer buffer
  6363. (widen)
  6364. (goto-char pos)
  6365. (save-excursion
  6366. (org-show-context 'agenda))
  6367. (save-excursion
  6368. (and (outline-next-heading)
  6369. (org-flag-heading nil))) ; show the next heading
  6370. (goto-char pos)
  6371. (call-interactively 'org-set-property)))))
  6372. (defun org-agenda-set-effort ()
  6373. "Set the effort property for the current headline."
  6374. (interactive)
  6375. (org-agenda-check-no-diary)
  6376. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6377. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6378. (org-agenda-error)))
  6379. (buffer (marker-buffer hdmarker))
  6380. (pos (marker-position hdmarker))
  6381. (inhibit-read-only t)
  6382. newhead)
  6383. (org-with-remote-undo buffer
  6384. (with-current-buffer buffer
  6385. (widen)
  6386. (goto-char pos)
  6387. (save-excursion
  6388. (org-show-context 'agenda))
  6389. (save-excursion
  6390. (and (outline-next-heading)
  6391. (org-flag-heading nil))) ; show the next heading
  6392. (goto-char pos)
  6393. (call-interactively 'org-set-effort)
  6394. (end-of-line 1)))))
  6395. (defun org-agenda-toggle-archive-tag ()
  6396. "Toggle the archive tag for the current entry."
  6397. (interactive)
  6398. (org-agenda-check-no-diary)
  6399. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6400. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6401. (org-agenda-error)))
  6402. (buffer (marker-buffer hdmarker))
  6403. (pos (marker-position hdmarker))
  6404. (inhibit-read-only t)
  6405. newhead)
  6406. (org-with-remote-undo buffer
  6407. (with-current-buffer buffer
  6408. (widen)
  6409. (goto-char pos)
  6410. (org-show-context 'agenda)
  6411. (save-excursion
  6412. (and (outline-next-heading)
  6413. (org-flag-heading nil))) ; show the next heading
  6414. (call-interactively 'org-toggle-archive-tag)
  6415. (end-of-line 1)
  6416. (setq newhead (org-get-heading)))
  6417. (org-agenda-change-all-lines newhead hdmarker)
  6418. (beginning-of-line 1))))
  6419. (defun org-agenda-do-date-later (arg)
  6420. (interactive "P")
  6421. (cond
  6422. ((or (equal arg '(16))
  6423. (memq last-command
  6424. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6425. (setq this-command 'org-agenda-date-later-minutes)
  6426. (org-agenda-date-later-minutes 1))
  6427. ((or (equal arg '(4))
  6428. (memq last-command
  6429. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6430. (setq this-command 'org-agenda-date-later-hours)
  6431. (org-agenda-date-later-hours 1))
  6432. (t
  6433. (org-agenda-date-later (prefix-numeric-value arg)))))
  6434. (defun org-agenda-do-date-earlier (arg)
  6435. (interactive "P")
  6436. (cond
  6437. ((or (equal arg '(16))
  6438. (memq last-command
  6439. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6440. (setq this-command 'org-agenda-date-earlier-minutes)
  6441. (org-agenda-date-earlier-minutes 1))
  6442. ((or (equal arg '(4))
  6443. (memq last-command
  6444. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6445. (setq this-command 'org-agenda-date-earlier-hours)
  6446. (org-agenda-date-earlier-hours 1))
  6447. (t
  6448. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6449. (defun org-agenda-date-later (arg &optional what)
  6450. "Change the date of this item to one day later."
  6451. (interactive "p")
  6452. (org-agenda-check-type t 'agenda 'timeline)
  6453. (org-agenda-check-no-diary)
  6454. (let* ((marker (or (org-get-at-bol 'org-marker)
  6455. (org-agenda-error)))
  6456. (buffer (marker-buffer marker))
  6457. (pos (marker-position marker)))
  6458. (org-with-remote-undo buffer
  6459. (with-current-buffer buffer
  6460. (widen)
  6461. (goto-char pos)
  6462. (if (not (org-at-timestamp-p))
  6463. (error "Cannot find time stamp"))
  6464. (org-timestamp-change arg (or what 'day)))
  6465. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6466. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6467. (defun org-agenda-date-earlier (arg &optional what)
  6468. "Change the date of this item to one day earlier."
  6469. (interactive "p")
  6470. (org-agenda-date-later (- arg) what))
  6471. (defun org-agenda-date-later-minutes (arg)
  6472. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6473. (interactive "p")
  6474. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6475. (org-agenda-date-later arg 'minute))
  6476. (defun org-agenda-date-earlier-minutes (arg)
  6477. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6478. (interactive "p")
  6479. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6480. (org-agenda-date-earlier arg 'minute))
  6481. (defun org-agenda-date-later-hours (arg)
  6482. "Change the time of this item, in hour steps."
  6483. (interactive "p")
  6484. (org-agenda-date-later arg 'hour))
  6485. (defun org-agenda-date-earlier-hours (arg)
  6486. "Change the time of this item, in hour steps."
  6487. (interactive "p")
  6488. (org-agenda-date-earlier arg 'hour))
  6489. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6490. "Show new date stamp via text properties."
  6491. ;; We use text properties to make this undoable
  6492. (let ((inhibit-read-only t)
  6493. (buffer-invisibility-spec))
  6494. (setq stamp (concat " " prefix " => " stamp))
  6495. (save-excursion
  6496. (goto-char (point-max))
  6497. (while (not (bobp))
  6498. (when (equal marker (org-get-at-bol 'org-marker))
  6499. (org-move-to-column (- (window-width) (length stamp)) t)
  6500. (org-agenda-fix-tags-filter-overlays-at (point))
  6501. (if (featurep 'xemacs)
  6502. ;; Use `duplicable' property to trigger undo recording
  6503. (let ((ex (make-extent nil nil))
  6504. (gl (make-glyph stamp)))
  6505. (set-glyph-face gl 'secondary-selection)
  6506. (set-extent-properties
  6507. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6508. (insert-extent ex (1- (point)) (point-at-eol)))
  6509. (add-text-properties
  6510. (1- (point)) (point-at-eol)
  6511. (list 'display (org-add-props stamp nil
  6512. 'face 'secondary-selection))))
  6513. (beginning-of-line 1))
  6514. (beginning-of-line 0)))))
  6515. (defun org-agenda-date-prompt (arg)
  6516. "Change the date of this item. Date is prompted for, with default today.
  6517. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6518. be used to request time specification in the time stamp."
  6519. (interactive "P")
  6520. (org-agenda-check-type t 'agenda 'timeline)
  6521. (org-agenda-check-no-diary)
  6522. (let* ((marker (or (org-get-at-bol 'org-marker)
  6523. (org-agenda-error)))
  6524. (buffer (marker-buffer marker))
  6525. (pos (marker-position marker)))
  6526. (org-with-remote-undo buffer
  6527. (with-current-buffer buffer
  6528. (widen)
  6529. (goto-char pos)
  6530. (if (not (org-at-timestamp-p t))
  6531. (error "Cannot find time stamp"))
  6532. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6533. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6534. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6535. (defun org-agenda-schedule (arg)
  6536. "Schedule the item at point.
  6537. Arg is passed through to `org-schedule'."
  6538. (interactive "P")
  6539. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6540. (org-agenda-check-no-diary)
  6541. (let* ((marker (or (org-get-at-bol 'org-marker)
  6542. (org-agenda-error)))
  6543. (type (marker-insertion-type marker))
  6544. (buffer (marker-buffer marker))
  6545. (pos (marker-position marker))
  6546. (org-insert-labeled-timestamps-at-point nil)
  6547. ts)
  6548. (set-marker-insertion-type marker t)
  6549. (org-with-remote-undo buffer
  6550. (with-current-buffer buffer
  6551. (widen)
  6552. (goto-char pos)
  6553. (setq ts (org-schedule arg)))
  6554. (org-agenda-show-new-time marker ts "S"))
  6555. (message "Item scheduled for %s" ts)))
  6556. (defun org-agenda-deadline (arg)
  6557. "Schedule the item at point.
  6558. Arg is passed through to `org-deadline'."
  6559. (interactive "P")
  6560. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6561. (org-agenda-check-no-diary)
  6562. (let* ((marker (or (org-get-at-bol 'org-marker)
  6563. (org-agenda-error)))
  6564. (buffer (marker-buffer marker))
  6565. (pos (marker-position marker))
  6566. (org-insert-labeled-timestamps-at-point nil)
  6567. ts)
  6568. (org-with-remote-undo buffer
  6569. (with-current-buffer buffer
  6570. (widen)
  6571. (goto-char pos)
  6572. (setq ts (org-deadline arg)))
  6573. (org-agenda-show-new-time marker ts "D"))
  6574. (message "Deadline for this item set to %s" ts)))
  6575. (defun org-agenda-action ()
  6576. "Select entry for agenda action, or execute an agenda action.
  6577. This command prompts for another letter. Valid inputs are:
  6578. m Mark the entry at point for an agenda action
  6579. s Schedule the marked entry to the date at the cursor
  6580. d Set the deadline of the marked entry to the date at the cursor
  6581. r Call `org-remember' with cursor date as the default date
  6582. c Call `org-capture' with cursor date as the default date
  6583. SPC Show marked entry in other window
  6584. TAB Visit marked entry in other window
  6585. The cursor may be at a date in the calendar, or in the Org agenda."
  6586. (interactive)
  6587. (let (ans)
  6588. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6589. (setq ans (read-char-exclusive))
  6590. (cond
  6591. ((equal ans ?m)
  6592. ;; Mark this entry
  6593. (if (eq major-mode 'org-agenda-mode)
  6594. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6595. (org-get-at-bol 'org-marker))))
  6596. (if m
  6597. (progn
  6598. (move-marker org-agenda-action-marker
  6599. (marker-position m) (marker-buffer m))
  6600. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6601. (error "Don't know which entry to mark")))
  6602. (error "This command works only in the agenda")))
  6603. ((equal ans ?s)
  6604. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6605. ((equal ans ?d)
  6606. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6607. ((equal ans ?r)
  6608. (org-agenda-do-action '(org-remember) t))
  6609. ((equal ans ?c)
  6610. (org-agenda-do-action '(org-capture) t))
  6611. ((equal ans ?\ )
  6612. (let ((cw (selected-window)))
  6613. (org-switch-to-buffer-other-window
  6614. (marker-buffer org-agenda-action-marker))
  6615. (goto-char org-agenda-action-marker)
  6616. (org-show-context 'agenda)
  6617. (select-window cw)))
  6618. ((equal ans ?\C-i)
  6619. (org-switch-to-buffer-other-window
  6620. (marker-buffer org-agenda-action-marker))
  6621. (goto-char org-agenda-action-marker)
  6622. (org-show-context 'agenda))
  6623. (t (error "Invalid agenda action %c" ans)))))
  6624. (defun org-agenda-do-action (form &optional current-buffer)
  6625. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6626. (let ((org-overriding-default-time (org-get-cursor-date)))
  6627. (if current-buffer
  6628. (eval form)
  6629. (if (not (marker-buffer org-agenda-action-marker))
  6630. (error "No entry has been selected for agenda action")
  6631. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6632. (save-excursion
  6633. (save-restriction
  6634. (widen)
  6635. (goto-char org-agenda-action-marker)
  6636. (eval form))))))))
  6637. (defun org-agenda-clock-in (&optional arg)
  6638. "Start the clock on the currently selected item."
  6639. (interactive "P")
  6640. (org-agenda-check-no-diary)
  6641. (if (equal arg '(4))
  6642. (org-clock-in arg)
  6643. (let* ((marker (or (org-get-at-bol 'org-marker)
  6644. (org-agenda-error)))
  6645. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6646. marker))
  6647. (pos (marker-position marker))
  6648. newhead)
  6649. (org-with-remote-undo (marker-buffer marker)
  6650. (with-current-buffer (marker-buffer marker)
  6651. (widen)
  6652. (goto-char pos)
  6653. (org-show-context 'agenda)
  6654. (org-show-entry)
  6655. (org-cycle-hide-drawers 'children)
  6656. (org-clock-in arg)
  6657. (setq newhead (org-get-heading)))
  6658. (org-agenda-change-all-lines newhead hdmarker)))))
  6659. (defun org-agenda-clock-out ()
  6660. "Stop the currently running clock."
  6661. (interactive)
  6662. (unless (marker-buffer org-clock-marker)
  6663. (error "No running clock"))
  6664. (let ((marker (make-marker)) newhead)
  6665. (org-with-remote-undo (marker-buffer org-clock-marker)
  6666. (with-current-buffer (marker-buffer org-clock-marker)
  6667. (save-excursion
  6668. (save-restriction
  6669. (widen)
  6670. (goto-char org-clock-marker)
  6671. (org-back-to-heading t)
  6672. (move-marker marker (point))
  6673. (org-clock-out)
  6674. (setq newhead (org-get-heading))))))
  6675. (org-agenda-change-all-lines newhead marker)
  6676. (move-marker marker nil)))
  6677. (defun org-agenda-clock-cancel (&optional arg)
  6678. "Cancel the currently running clock."
  6679. (interactive "P")
  6680. (unless (marker-buffer org-clock-marker)
  6681. (error "No running clock"))
  6682. (org-with-remote-undo (marker-buffer org-clock-marker)
  6683. (org-clock-cancel)))
  6684. (defun org-agenda-clock-goto ()
  6685. "Jump to the currently clocked in task within the agenda.
  6686. If the currently clocked in task is not listed in the agenda
  6687. buffer, display it in another window."
  6688. (interactive)
  6689. (let (pos)
  6690. (mapc (lambda (o)
  6691. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6692. (setq pos (overlay-start o))))
  6693. (overlays-in (point-min) (point-max)))
  6694. (cond (pos (goto-char pos))
  6695. ;; If the currently clocked entry is not in the agenda
  6696. ;; buffer, we visit it in another window:
  6697. (org-clock-current-task
  6698. (org-switch-to-buffer-other-window (org-clock-goto)))
  6699. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6700. (defun org-agenda-diary-entry-in-org-file ()
  6701. "Make a diary entry in the file `org-agenda-diary-file'."
  6702. (let (d1 d2 char (text "") dp1 dp2)
  6703. (if (equal (buffer-name) "*Calendar*")
  6704. (setq d1 (calendar-cursor-to-date t)
  6705. d2 (car calendar-mark-ring))
  6706. (setq dp1 (get-text-property (point-at-bol) 'day))
  6707. (unless dp1 (error "No date defined in current line"))
  6708. (setq d1 (calendar-gregorian-from-absolute dp1)
  6709. d2 (and (ignore-errors (mark))
  6710. (save-excursion
  6711. (goto-char (mark))
  6712. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6713. (calendar-gregorian-from-absolute dp2))))
  6714. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6715. (setq char (read-char-exclusive))
  6716. (cond
  6717. ((equal char ?d)
  6718. (setq text (read-string "Day entry: "))
  6719. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6720. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6721. ((equal char ?a)
  6722. (setq d1 (list (car d1) (nth 1 d1)
  6723. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6724. (nth 2 d1))))
  6725. (setq text (read-string "Anniversary (use %d to show years): "))
  6726. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6727. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6728. ((equal char ?b)
  6729. (setq text (read-string "Block entry: "))
  6730. (unless (and d1 d2 (not (equal d1 d2)))
  6731. (error "No block of days selected"))
  6732. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6733. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6734. ((equal char ?j)
  6735. (org-switch-to-buffer-other-window
  6736. (find-file-noselect org-agenda-diary-file))
  6737. (require 'org-datetree)
  6738. (org-datetree-find-date-create d1)
  6739. (org-reveal t))
  6740. (t (error "Invalid selection character `%c'" char)))))
  6741. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6742. "Where in `org-agenda-diary-file' should new entries be added?
  6743. Valid values:
  6744. date-tree in the date tree, as child of the date
  6745. top-level as top-level entries at the end of the file."
  6746. :group 'org-agenda
  6747. :type '(choice
  6748. (const :tag "in a date tree" date-tree)
  6749. (const :tag "as top level at end of file" top-level)))
  6750. (defcustom org-agenda-insert-diary-extract-time nil
  6751. "Non-nil means extract any time specification from the diary entry."
  6752. :group 'org-agenda
  6753. :type 'boolean)
  6754. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6755. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6756. If TEXT is not empty, it will become the headline of the new entry, and
  6757. the resulting entry will not be shown. When TEXT is empty, switch to
  6758. `org-agenda-diary-file' and let the user finish the entry there."
  6759. (let ((cw (current-window-configuration)))
  6760. (org-switch-to-buffer-other-window
  6761. (find-file-noselect org-agenda-diary-file))
  6762. (widen)
  6763. (goto-char (point-min))
  6764. (cond
  6765. ((eq type 'anniversary)
  6766. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6767. (progn
  6768. (or (org-on-heading-p t)
  6769. (progn
  6770. (outline-next-heading)
  6771. (insert "* Anniversaries\n\n")
  6772. (beginning-of-line -1)))))
  6773. (outline-next-heading)
  6774. (org-back-over-empty-lines)
  6775. (backward-char 1)
  6776. (insert "\n")
  6777. (require 'diary-lib)
  6778. (let ((calendar-date-display-form
  6779. (if (if (boundp 'calendar-date-style)
  6780. (eq calendar-date-style 'european)
  6781. (org-bound-and-true-p european-calendar-style)) ; Emacs 22
  6782. '(day " " month " " year)
  6783. '(month " " day " " year))))
  6784. (insert (format "%%%%(diary-anniversary %s) %s"
  6785. (calendar-date-string d1 nil t) text))))
  6786. ((eq type 'day)
  6787. (let ((org-prefix-has-time t)
  6788. (org-agenda-time-leading-zero t)
  6789. fmt time time2)
  6790. (if org-agenda-insert-diary-extract-time
  6791. ;; Use org-format-agenda-item to parse text for a time-range and
  6792. ;; remove it. FIXME: This is a hack, we should refactor
  6793. ;; that function to make time extraction available separately
  6794. (setq fmt (org-format-agenda-item nil text nil nil t)
  6795. time (get-text-property 0 'time fmt)
  6796. time2 (if (> (length time) 0)
  6797. ;; split-string removes trailing ...... if
  6798. ;; no end time given. First space
  6799. ;; separates time from date.
  6800. (concat " " (car (split-string time "\\.")))
  6801. nil)
  6802. text (get-text-property 0 'txt fmt)))
  6803. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6804. (org-agenda-insert-diary-as-top-level text)
  6805. (require 'org-datetree)
  6806. (org-datetree-find-date-create d1)
  6807. (org-agenda-insert-diary-make-new-entry text))
  6808. (org-insert-time-stamp (org-time-from-absolute
  6809. (calendar-absolute-from-gregorian d1))
  6810. nil nil nil nil time2))
  6811. (end-of-line 0))
  6812. ((eq type 'block)
  6813. (if (> (calendar-absolute-from-gregorian d1)
  6814. (calendar-absolute-from-gregorian d2))
  6815. (setq d1 (prog1 d2 (setq d2 d1))))
  6816. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6817. (org-agenda-insert-diary-as-top-level text)
  6818. (require 'org-datetree)
  6819. (org-datetree-find-date-create d1)
  6820. (org-agenda-insert-diary-make-new-entry text))
  6821. (org-insert-time-stamp (org-time-from-absolute
  6822. (calendar-absolute-from-gregorian d1)))
  6823. (insert "--")
  6824. (org-insert-time-stamp (org-time-from-absolute
  6825. (calendar-absolute-from-gregorian d2)))
  6826. (end-of-line 0)))
  6827. (if (string-match "\\S-" text)
  6828. (progn
  6829. (set-window-configuration cw)
  6830. (message "%s entry added to %s"
  6831. (capitalize (symbol-name type))
  6832. (abbreviate-file-name org-agenda-diary-file)))
  6833. (org-reveal t)
  6834. (message "Please finish entry here"))))
  6835. (defun org-agenda-insert-diary-as-top-level (text)
  6836. "Make new entry as a top-level entry at the end of the file.
  6837. Add TEXT as headline, and position the cursor in the second line so that
  6838. a timestamp can be added there."
  6839. (widen)
  6840. (goto-char (point-max))
  6841. (or (bolp) (insert "\n"))
  6842. (insert "* " text "\n")
  6843. (if org-adapt-indentation (org-indent-to-column 2)))
  6844. (defun org-agenda-insert-diary-make-new-entry (text)
  6845. "Make new entry as last child of current entry.
  6846. Add TEXT as headline, and position the cursor in the second line so that
  6847. a timestamp can be added there."
  6848. (let ((org-show-following-heading t)
  6849. (org-show-siblings t)
  6850. (org-show-hierarchy-above t)
  6851. (org-show-entry-below t)
  6852. col)
  6853. (outline-next-heading)
  6854. (org-back-over-empty-lines)
  6855. (or (looking-at "[ \t]*$")
  6856. (progn (insert "\n") (backward-char 1)))
  6857. (org-insert-heading nil t)
  6858. (org-do-demote)
  6859. (setq col (current-column))
  6860. (insert text "\n")
  6861. (if org-adapt-indentation (org-indent-to-column col))
  6862. (let ((org-show-following-heading t)
  6863. (org-show-siblings t)
  6864. (org-show-hierarchy-above t)
  6865. (org-show-entry-below t))
  6866. (org-show-context))))
  6867. (defun org-agenda-diary-entry ()
  6868. "Make a diary entry, like the `i' command from the calendar.
  6869. All the standard commands work: block, weekly etc.
  6870. When `org-agenda-diary-file' points to a file,
  6871. `org-agenda-diary-entry-in-org-file' is called instead to create
  6872. entries in that Org-mode file."
  6873. (interactive)
  6874. (org-agenda-check-type t 'agenda 'timeline)
  6875. (if (not (eq org-agenda-diary-file 'diary-file))
  6876. (org-agenda-diary-entry-in-org-file)
  6877. (require 'diary-lib)
  6878. (let* ((char (progn
  6879. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6880. (read-char-exclusive)))
  6881. (cmd (cdr (assoc char
  6882. '((?d . insert-diary-entry)
  6883. (?w . insert-weekly-diary-entry)
  6884. (?m . insert-monthly-diary-entry)
  6885. (?y . insert-yearly-diary-entry)
  6886. (?a . insert-anniversary-diary-entry)
  6887. (?b . insert-block-diary-entry)
  6888. (?c . insert-cyclic-diary-entry)))))
  6889. (oldf (symbol-function 'calendar-cursor-to-date))
  6890. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6891. (point (point))
  6892. (mark (or (mark t) (point))))
  6893. (unless cmd
  6894. (error "No command associated with <%c>" char))
  6895. (unless (and (get-text-property point 'day)
  6896. (or (not (equal ?b char))
  6897. (get-text-property mark 'day)))
  6898. (error "Don't know which date to use for diary entry"))
  6899. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6900. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6901. (let ((calendar-mark-ring
  6902. (list (calendar-gregorian-from-absolute
  6903. (or (get-text-property mark 'day)
  6904. (get-text-property point 'day))))))
  6905. (unwind-protect
  6906. (progn
  6907. (fset 'calendar-cursor-to-date
  6908. (lambda (&optional error dummy)
  6909. (calendar-gregorian-from-absolute
  6910. (get-text-property point 'day))))
  6911. (call-interactively cmd))
  6912. (fset 'calendar-cursor-to-date oldf))))))
  6913. (defun org-agenda-execute-calendar-command (cmd)
  6914. "Execute a calendar command from the agenda, with the date associated to
  6915. the cursor position."
  6916. (org-agenda-check-type t 'agenda 'timeline)
  6917. (require 'diary-lib)
  6918. (unless (get-text-property (point) 'day)
  6919. (error "Don't know which date to use for calendar command"))
  6920. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6921. (point (point))
  6922. (date (calendar-gregorian-from-absolute
  6923. (get-text-property point 'day)))
  6924. ;; the following 2 vars are needed in the calendar
  6925. (displayed-month (car date))
  6926. (displayed-year (nth 2 date)))
  6927. (unwind-protect
  6928. (progn
  6929. (fset 'calendar-cursor-to-date
  6930. (lambda (&optional error dummy)
  6931. (calendar-gregorian-from-absolute
  6932. (get-text-property point 'day))))
  6933. (call-interactively cmd))
  6934. (fset 'calendar-cursor-to-date oldf))))
  6935. (defun org-agenda-phases-of-moon ()
  6936. "Display the phases of the moon for the 3 months around the cursor date."
  6937. (interactive)
  6938. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6939. (defun org-agenda-holidays ()
  6940. "Display the holidays for the 3 months around the cursor date."
  6941. (interactive)
  6942. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6943. (defvar calendar-longitude)
  6944. (defvar calendar-latitude)
  6945. (defvar calendar-location-name)
  6946. (defun org-agenda-sunrise-sunset (arg)
  6947. "Display sunrise and sunset for the cursor date.
  6948. Latitude and longitude can be specified with the variables
  6949. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6950. argument, latitude and longitude will be prompted for."
  6951. (interactive "P")
  6952. (require 'solar)
  6953. (let ((calendar-longitude (if arg nil calendar-longitude))
  6954. (calendar-latitude (if arg nil calendar-latitude))
  6955. (calendar-location-name
  6956. (if arg "the given coordinates" calendar-location-name)))
  6957. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6958. (defun org-agenda-goto-calendar ()
  6959. "Open the Emacs calendar with the date at the cursor."
  6960. (interactive)
  6961. (org-agenda-check-type t 'agenda 'timeline)
  6962. (let* ((day (or (get-text-property (point) 'day)
  6963. (error "Don't know which date to open in calendar")))
  6964. (date (calendar-gregorian-from-absolute day))
  6965. (calendar-move-hook nil)
  6966. (calendar-view-holidays-initially-flag nil)
  6967. (calendar-view-diary-initially-flag nil))
  6968. (calendar)
  6969. (calendar-goto-date date)))
  6970. ;;;###autoload
  6971. (defun org-calendar-goto-agenda ()
  6972. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6973. This is a command that has to be installed in `calendar-mode-map'."
  6974. (interactive)
  6975. (org-agenda-list nil (calendar-absolute-from-gregorian
  6976. (calendar-cursor-to-date))
  6977. nil))
  6978. (defun org-agenda-convert-date ()
  6979. (interactive)
  6980. (org-agenda-check-type t 'agenda 'timeline)
  6981. (let ((day (get-text-property (point) 'day))
  6982. date s)
  6983. (unless day
  6984. (error "Don't know which date to convert"))
  6985. (setq date (calendar-gregorian-from-absolute day))
  6986. (setq s (concat
  6987. "Gregorian: " (calendar-date-string date) "\n"
  6988. "ISO: " (calendar-iso-date-string date) "\n"
  6989. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6990. "Julian: " (calendar-julian-date-string date) "\n"
  6991. "Astron. JD: " (calendar-astro-date-string date)
  6992. " (Julian date number at noon UTC)\n"
  6993. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6994. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6995. "French: " (calendar-french-date-string date) "\n"
  6996. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6997. "Mayan: " (calendar-mayan-date-string date) "\n"
  6998. "Coptic: " (calendar-coptic-date-string date) "\n"
  6999. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7000. "Persian: " (calendar-persian-date-string date) "\n"
  7001. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7002. (with-output-to-temp-buffer "*Dates*"
  7003. (princ s))
  7004. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7005. ;;; Bulk commands
  7006. (defvar org-agenda-bulk-marked-entries nil
  7007. "List of markers that refer to marked entries in the agenda.")
  7008. (defun org-agenda-bulk-marked-p ()
  7009. (eq (get-char-property (point-at-bol) 'type)
  7010. 'org-marked-entry-overlay))
  7011. (defun org-agenda-bulk-mark ()
  7012. "Mark the entry at point for future bulk action."
  7013. (interactive)
  7014. (org-agenda-check-no-diary)
  7015. (let* ((m (org-get-at-bol 'org-hd-marker))
  7016. ov)
  7017. (unless (org-agenda-bulk-marked-p)
  7018. (unless m (error "Nothing to mark at point"))
  7019. (push m org-agenda-bulk-marked-entries)
  7020. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7021. (org-overlay-display ov "> "
  7022. (org-get-todo-face "TODO")
  7023. 'evaporate)
  7024. (overlay-put ov 'type 'org-marked-entry-overlay))
  7025. (beginning-of-line 2)
  7026. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7027. (beginning-of-line 2))
  7028. (message "%d entries marked for bulk action"
  7029. (length org-agenda-bulk-marked-entries))))
  7030. (defun org-agenda-bulk-unmark ()
  7031. "Unmark the entry at point for future bulk action."
  7032. (interactive)
  7033. (when (org-agenda-bulk-marked-p)
  7034. (org-agenda-bulk-remove-overlays
  7035. (point-at-bol) (+ 2 (point-at-bol)))
  7036. (setq org-agenda-bulk-marked-entries
  7037. (delete (org-get-at-bol 'org-hd-marker)
  7038. org-agenda-bulk-marked-entries)))
  7039. (beginning-of-line 2)
  7040. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7041. (beginning-of-line 2))
  7042. (message "%d entries marked for bulk action"
  7043. (length org-agenda-bulk-marked-entries)))
  7044. (defun org-agenda-bulk-toggle ()
  7045. "Toggle marking the entry at point for bulk action."
  7046. (interactive)
  7047. (if (org-agenda-bulk-marked-p)
  7048. (org-agenda-bulk-unmark)
  7049. (org-agenda-bulk-mark)))
  7050. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7051. "Remove the mark overlays between BEG and END in the agenda buffer.
  7052. BEG and END default to the buffer limits.
  7053. This only removes the overlays, it does not remove the markers
  7054. from the list in `org-agenda-bulk-marked-entries'."
  7055. (interactive)
  7056. (mapc (lambda (ov)
  7057. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7058. (delete-overlay ov)))
  7059. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7060. (defun org-agenda-bulk-remove-all-marks ()
  7061. "Remove all marks in the agenda buffer.
  7062. This will remove the markers, and the overlays."
  7063. (interactive)
  7064. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7065. (setq org-agenda-bulk-marked-entries nil)
  7066. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7067. (defun org-agenda-bulk-action (&optional arg)
  7068. "Execute an remote-editing action on all marked entries.
  7069. The prefix arg is passed through to the command if possible."
  7070. (interactive "P")
  7071. (unless org-agenda-bulk-marked-entries
  7072. (error "No entries are marked"))
  7073. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7074. (let* ((action (read-char-exclusive))
  7075. (org-log-refile (if org-log-refile 'time nil))
  7076. (entries (reverse org-agenda-bulk-marked-entries))
  7077. redo-at-end
  7078. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7079. (cond
  7080. ((equal action ?$)
  7081. (setq cmd '(org-agenda-archive)))
  7082. ((equal action ?A)
  7083. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7084. ((member action '(?r ?w))
  7085. (setq rfloc (org-refile-get-location
  7086. "Refile to: "
  7087. (marker-buffer (car org-agenda-bulk-marked-entries))
  7088. org-refile-allow-creating-parent-nodes))
  7089. (if (nth 3 rfloc)
  7090. (setcar (nthcdr 3 rfloc)
  7091. (move-marker (make-marker) (nth 3 rfloc)
  7092. (or (get-file-buffer (nth 1 rfloc))
  7093. (find-buffer-visiting (nth 1 rfloc))
  7094. (error "This should not happen")))))
  7095. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7096. redo-at-end t))
  7097. ((equal action ?t)
  7098. (setq state (org-icompleting-read
  7099. "Todo state: "
  7100. (with-current-buffer (marker-buffer (car entries))
  7101. (mapcar 'list org-todo-keywords-1))))
  7102. (setq cmd `(let ((org-inhibit-blocking t)
  7103. (org-inhibit-logging 'note))
  7104. (org-agenda-todo ,state))))
  7105. ((memq action '(?- ?+))
  7106. (setq tag (org-icompleting-read
  7107. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7108. (with-current-buffer (marker-buffer (car entries))
  7109. (delq nil
  7110. (mapcar (lambda (x)
  7111. (if (stringp (car x)) x)) org-tag-alist)))))
  7112. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7113. ((memq action '(?s ?d))
  7114. (let* ((date (unless arg
  7115. (org-read-date
  7116. nil nil nil
  7117. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7118. (ans (if arg nil org-read-date-final-answer))
  7119. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7120. (setq cmd `(let* ((bound (fboundp 'read-string))
  7121. (old (and bound (symbol-function 'read-string))))
  7122. (unwind-protect
  7123. (progn
  7124. (fset 'read-string (lambda (&rest ignore) ,ans))
  7125. (eval '(,c1 arg)))
  7126. (if bound
  7127. (fset 'read-string old)
  7128. (fmakunbound 'read-string)))))))
  7129. (t (error "Invalid bulk action")))
  7130. ;; Sort the markers, to make sure that parents are handled before children
  7131. (setq entries (sort entries
  7132. (lambda (a b)
  7133. (cond
  7134. ((equal (marker-buffer a) (marker-buffer b))
  7135. (< (marker-position a) (marker-position b)))
  7136. (t
  7137. (string< (buffer-name (marker-buffer a))
  7138. (buffer-name (marker-buffer b))))))))
  7139. ;; Now loop over all markers and apply cmd
  7140. (while (setq e (pop entries))
  7141. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7142. (if (not pos)
  7143. (progn (message "Skipping removed entry at %s" e)
  7144. (setq cntskip (1+ cntskip)))
  7145. (goto-char pos)
  7146. (eval cmd)
  7147. (setq org-agenda-bulk-marked-entries
  7148. (delete e org-agenda-bulk-marked-entries))
  7149. (setq cnt (1+ cnt))))
  7150. (setq org-agenda-bulk-marked-entries nil)
  7151. (org-agenda-bulk-remove-all-marks)
  7152. (when redo-at-end (org-agenda-redo))
  7153. (message "Acted on %d entries%s"
  7154. cnt
  7155. (if (= cntskip 0)
  7156. ""
  7157. (format ", skipped %d (disappeared before their turn)"
  7158. cntskip)))))
  7159. ;;; Flagging notes
  7160. (defun org-agenda-show-the-flagging-note ()
  7161. "Display the flagging note in the other window.
  7162. When called a second time in direct sequence, offer to remove the FLAGGING
  7163. tag and (if present) the flagging note."
  7164. (interactive)
  7165. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7166. (win (selected-window))
  7167. note heading newhead)
  7168. (unless hdmarker
  7169. (error "No linked entry at point"))
  7170. (if (and (eq this-command last-command)
  7171. (y-or-n-p "Unflag and remove any flagging note? "))
  7172. (progn
  7173. (org-agenda-remove-flag hdmarker)
  7174. (let ((win (get-buffer-window "*Flagging Note*")))
  7175. (and win (delete-window win)))
  7176. (message "Entry unflaged"))
  7177. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7178. (unless note
  7179. (error "No flagging note"))
  7180. (org-kill-new note)
  7181. (org-switch-to-buffer-other-window "*Flagging Note*")
  7182. (erase-buffer)
  7183. (insert note)
  7184. (goto-char (point-min))
  7185. (while (re-search-forward "\\\\n" nil t)
  7186. (replace-match "\n" t t))
  7187. (goto-char (point-min))
  7188. (select-window win)
  7189. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7190. (defun org-agenda-remove-flag (marker)
  7191. "Remove the FLAGGED tag and any flagging note in the entry."
  7192. (let (newhead)
  7193. (org-with-point-at marker
  7194. (org-toggle-tag "FLAGGED" 'off)
  7195. (org-entry-delete nil "THEFLAGGINGNOTE")
  7196. (setq newhead (org-get-heading)))
  7197. (org-agenda-change-all-lines newhead marker)
  7198. (message "Entry unflaged")))
  7199. (defun org-agenda-get-any-marker (&optional pos)
  7200. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7201. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7202. ;;; Appointment reminders
  7203. (defvar appt-time-msg-list)
  7204. ;;;###autoload
  7205. (defun org-agenda-to-appt (&optional refresh filter)
  7206. "Activate appointments found in `org-agenda-files'.
  7207. With a \\[universal-argument] prefix, refresh the list of
  7208. appointments.
  7209. If FILTER is t, interactively prompt the user for a regular
  7210. expression, and filter out entries that don't match it.
  7211. If FILTER is a string, use this string as a regular expression
  7212. for filtering entries out.
  7213. FILTER can also be an alist with the car of each cell being
  7214. either 'headline or 'category. For example:
  7215. '((headline \"IMPORTANT\")
  7216. (category \"Work\"))
  7217. will only add headlines containing IMPORTANT or headlines
  7218. belonging to the \"Work\" category."
  7219. (interactive "P")
  7220. (if refresh (setq appt-time-msg-list nil))
  7221. (if (eq filter t)
  7222. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7223. (let* ((cnt 0) ; count added events
  7224. (org-agenda-new-buffers nil)
  7225. (org-deadline-warning-days 0)
  7226. (today (org-date-to-gregorian
  7227. (time-to-days (current-time))))
  7228. (org-agenda-restrict nil)
  7229. (files (org-agenda-files 'unrestricted)) entries file)
  7230. ;; Get all entries which may contain an appt
  7231. (org-prepare-agenda-buffers files)
  7232. (while (setq file (pop files))
  7233. (setq entries
  7234. (append entries
  7235. (org-agenda-get-day-entries
  7236. file today :timestamp :scheduled :deadline))))
  7237. (setq entries (delq nil entries))
  7238. ;; Map thru entries and find if we should filter them out
  7239. (mapc
  7240. (lambda(x)
  7241. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7242. (cat (get-text-property 1 'org-category x))
  7243. (tod (get-text-property 1 'time-of-day x))
  7244. (ok (or (null filter)
  7245. (and (stringp filter) (string-match filter evt))
  7246. (and (listp filter)
  7247. (or (string-match
  7248. (cadr (assoc 'category filter)) cat)
  7249. (string-match
  7250. (cadr (assoc 'headline filter)) evt))))))
  7251. ;; FIXME: Shall we remove text-properties for the appt text?
  7252. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7253. (when (and ok tod)
  7254. (setq tod (concat "00" (number-to-string tod))
  7255. tod (when (string-match
  7256. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7257. (concat (match-string 1 tod) ":"
  7258. (match-string 2 tod))))
  7259. (appt-add tod evt)
  7260. (setq cnt (1+ cnt))))) entries)
  7261. (org-release-buffers org-agenda-new-buffers)
  7262. (if (eq cnt 0)
  7263. (message "No event to add")
  7264. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7265. (defun org-agenda-todayp (date)
  7266. "Does DATE mean today, when considering `org-extend-today-until'?"
  7267. (let (today h)
  7268. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  7269. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  7270. (setq h (nth 2 (decode-time (current-time))))
  7271. (or (and (>= h org-extend-today-until)
  7272. (= date today))
  7273. (and (< h org-extend-today-until)
  7274. (= date (1- today))))))
  7275. (provide 'org-agenda)
  7276. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7277. ;;; org-agenda.el ends here