org-agenda.el 356 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (defvar calendar-mode-map)
  78. (defvar org-clock-current-task) ; defined in org-clock.el
  79. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  80. (defvar org-habit-show-habits)
  81. (defvar org-habit-show-habits-only-for-today)
  82. (defvar org-habit-show-all-today nil)
  83. ;; Defined somewhere in this file, but used before definition.
  84. (defvar org-agenda-buffer-name)
  85. (defvar org-agenda-overriding-header)
  86. (defvar org-agenda-title-append nil)
  87. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  88. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  89. (defvar org-agenda-undo-list)
  90. (defvar org-agenda-pending-undo-list)
  91. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  92. (defcustom org-agenda-confirm-kill 1
  93. "When set, remote killing from the agenda buffer needs confirmation.
  94. When t, a confirmation is always needed. When a number N, confirmation is
  95. only needed when the text to be killed contains more than N non-white lines."
  96. :group 'org-agenda
  97. :type '(choice
  98. (const :tag "Never" nil)
  99. (const :tag "Always" t)
  100. (integer :tag "When more than N lines")))
  101. (defcustom org-agenda-compact-blocks nil
  102. "Non-nil means make the block agenda more compact.
  103. This is done globally by leaving out lines like the agenda span
  104. name and week number or the separator lines."
  105. :group 'org-agenda
  106. :type 'boolean)
  107. (defcustom org-agenda-block-separator ?=
  108. "The separator between blocks in the agenda.
  109. If this is a string, it will be used as the separator, with a newline added.
  110. If it is a character, it will be repeated to fill the window width.
  111. If nil the separator is disabled. In `org-agenda-custom-commands' this
  112. addresses the separator between the current and the previous block."
  113. :group 'org-agenda
  114. :type '(choice
  115. (const :tag "Disabled" nil)
  116. (character)
  117. (string)))
  118. (defgroup org-agenda-export nil
  119. "Options concerning exporting agenda views in Org-mode."
  120. :tag "Org Agenda Export"
  121. :group 'org-agenda)
  122. (defcustom org-agenda-with-colors t
  123. "Non-nil means use colors in agenda views."
  124. :group 'org-agenda-export
  125. :type 'boolean)
  126. (defcustom org-agenda-exporter-settings nil
  127. "Alist of variable/value pairs that should be active during agenda export.
  128. This is a good place to set options for ps-print and for htmlize.
  129. Note that the way this is implemented, the values will be evaluated
  130. before assigned to the variables. So make sure to quote values you do
  131. *not* want evaluated, for example
  132. (setq org-agenda-exporter-settings
  133. '((ps-print-color-p 'black-white)))"
  134. :group 'org-agenda-export
  135. :type '(repeat
  136. (list
  137. (variable)
  138. (sexp :tag "Value"))))
  139. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  140. "Hook run in temporary buffer before writing it to an export file.
  141. A useful function is `org-agenda-add-entry-text'."
  142. :group 'org-agenda-export
  143. :type 'hook
  144. :options '(org-agenda-add-entry-text))
  145. (defcustom org-agenda-add-entry-text-maxlines 0
  146. "Maximum number of entry text lines to be added to agenda.
  147. This is only relevant when `org-agenda-add-entry-text' is part of
  148. `org-agenda-before-write-hook', which it is by default.
  149. When this is 0, nothing will happen. When it is greater than 0, it
  150. specifies the maximum number of lines that will be added for each entry
  151. that is listed in the agenda view.
  152. Note that this variable is not used during display, only when exporting
  153. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  154. and `org-agenda-entry-text-maxlines'."
  155. :group 'org-agenda
  156. :type 'integer)
  157. (defcustom org-agenda-add-entry-text-descriptive-links t
  158. "Non-nil means export org-links as descriptive links in agenda added text.
  159. This variable applies to the text added to the agenda when
  160. `org-agenda-add-entry-text-maxlines' is larger than 0.
  161. When this variable nil, the URL will (also) be shown."
  162. :group 'org-agenda
  163. :type 'boolean)
  164. (defcustom org-agenda-export-html-style ""
  165. "The style specification for exported HTML Agenda files.
  166. If this variable contains a string, it will replace the default <style>
  167. section as produced by `htmlize'.
  168. Since there are different ways of setting style information, this variable
  169. needs to contain the full HTML structure to provide a style, including the
  170. surrounding HTML tags. The style specifications should include definitions
  171. the fonts used by the agenda, here is an example:
  172. <style type=\"text/css\">
  173. p { font-weight: normal; color: gray; }
  174. .org-agenda-structure {
  175. font-size: 110%;
  176. color: #003399;
  177. font-weight: 600;
  178. }
  179. .org-todo {
  180. color: #cc6666;
  181. font-weight: bold;
  182. }
  183. .org-agenda-done {
  184. color: #339933;
  185. }
  186. .org-done {
  187. color: #339933;
  188. }
  189. .title { text-align: center; }
  190. .todo, .deadline { color: red; }
  191. .done { color: green; }
  192. </style>
  193. or, if you want to keep the style in a file,
  194. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  195. As the value of this option simply gets inserted into the HTML <head> header,
  196. you can \"misuse\" it to also add other text to the header. However,
  197. <style>...</style> is required, if not present the variable will be ignored."
  198. :group 'org-agenda-export
  199. :group 'org-export-html
  200. :type 'string)
  201. (defcustom org-agenda-persistent-filter nil
  202. "When set, keep filters from one agenda view to the next."
  203. :group 'org-agenda
  204. :type 'boolean)
  205. (defgroup org-agenda-custom-commands nil
  206. "Options concerning agenda views in Org-mode."
  207. :tag "Org Agenda Custom Commands"
  208. :group 'org-agenda)
  209. (defconst org-sorting-choice
  210. '(choice
  211. (const time-up) (const time-down)
  212. (const category-keep) (const category-up) (const category-down)
  213. (const tag-down) (const tag-up)
  214. (const priority-up) (const priority-down)
  215. (const todo-state-up) (const todo-state-down)
  216. (const effort-up) (const effort-down)
  217. (const habit-up) (const habit-down)
  218. (const alpha-up) (const alpha-down)
  219. (const user-defined-up) (const user-defined-down))
  220. "Sorting choices.")
  221. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  222. ;; the new variable `org-agenda-tag-filter-preset'.
  223. (if (fboundp 'defvaralias)
  224. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  225. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  226. (defconst org-agenda-custom-commands-local-options
  227. `(repeat :tag "Local settings for this command. Remember to quote values"
  228. (choice :tag "Setting"
  229. (list :tag "Heading for this block"
  230. (const org-agenda-overriding-header)
  231. (string :tag "Headline"))
  232. (list :tag "Files to be searched"
  233. (const org-agenda-files)
  234. (list
  235. (const :format "" quote)
  236. (repeat (file))))
  237. (list :tag "Sorting strategy"
  238. (const org-agenda-sorting-strategy)
  239. (list
  240. (const :format "" quote)
  241. (repeat
  242. ,org-sorting-choice)))
  243. (list :tag "Prefix format"
  244. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  245. (string))
  246. (list :tag "Number of days in agenda"
  247. (const org-agenda-span)
  248. (choice (const :tag "Day" 'day)
  249. (const :tag "Week" 'week)
  250. (const :tag "Month" 'month)
  251. (const :tag "Year" 'year)
  252. (integer :tag "Custom")))
  253. (list :tag "Fixed starting date"
  254. (const org-agenda-start-day)
  255. (string :value "2007-11-01"))
  256. (list :tag "Start on day of week"
  257. (const org-agenda-start-on-weekday)
  258. (choice :value 1
  259. (const :tag "Today" nil)
  260. (integer :tag "Weekday No.")))
  261. (list :tag "Include data from diary"
  262. (const org-agenda-include-diary)
  263. (boolean))
  264. (list :tag "Deadline Warning days"
  265. (const org-deadline-warning-days)
  266. (integer :value 1))
  267. (list :tag "Category filter preset"
  268. (const org-agenda-category-filter-preset)
  269. (list
  270. (const :format "" quote)
  271. (repeat
  272. (string :tag "+category or -category"))))
  273. (list :tag "Tags filter preset"
  274. (const org-agenda-tag-filter-preset)
  275. (list
  276. (const :format "" quote)
  277. (repeat
  278. (string :tag "+tag or -tag"))))
  279. (list :tag "Set daily/weekly entry types"
  280. (const org-agenda-entry-types)
  281. (list
  282. (const :format "" quote)
  283. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  284. (const :deadline)
  285. (const :scheduled)
  286. (const :timestamp)
  287. (const :sexp))))
  288. (list :tag "Standard skipping condition"
  289. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  290. (const org-agenda-skip-function)
  291. (list
  292. (const :format "" quote)
  293. (list
  294. (choice
  295. :tag "Skipping range"
  296. (const :tag "Skip entry" org-agenda-skip-entry-if)
  297. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  298. (repeat :inline t :tag "Conditions for skipping"
  299. (choice
  300. :tag "Condition type"
  301. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  302. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  303. (list :tag "TODO state is" :inline t
  304. (const 'todo)
  305. (choice
  306. (const :tag "any not-done state" 'todo)
  307. (const :tag "any done state" 'done)
  308. (const :tag "any state" 'any)
  309. (list :tag "Keyword list"
  310. (const :format "" quote)
  311. (repeat (string :tag "Keyword")))))
  312. (list :tag "TODO state is not" :inline t
  313. (const 'nottodo)
  314. (choice
  315. (const :tag "any not-done state" 'todo)
  316. (const :tag "any done state" 'done)
  317. (const :tag "any state" 'any)
  318. (list :tag "Keyword list"
  319. (const :format "" quote)
  320. (repeat (string :tag "Keyword")))))
  321. (const :tag "scheduled" 'scheduled)
  322. (const :tag "not scheduled" 'notscheduled)
  323. (const :tag "deadline" 'deadline)
  324. (const :tag "no deadline" 'notdeadline)
  325. (const :tag "timestamp" 'timestamp)
  326. (const :tag "no timestamp" 'nottimestamp))))))
  327. (list :tag "Non-standard skipping condition"
  328. :value (org-agenda-skip-function)
  329. (const org-agenda-skip-function)
  330. (sexp :tag "Function or form (quoted!)"))
  331. (list :tag "Any variable"
  332. (variable :tag "Variable")
  333. (sexp :tag "Value (sexp)"))))
  334. "Selection of examples for agenda command settings.
  335. This will be spliced into the custom type of
  336. `org-agenda-custom-commands'.")
  337. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  338. ((agenda "") (alltodo))))
  339. "Custom commands for the agenda.
  340. These commands will be offered on the splash screen displayed by the
  341. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  342. (key desc type match settings files)
  343. key The key (one or more characters as a string) to be associated
  344. with the command.
  345. desc A description of the command, when omitted or nil, a default
  346. description is built using MATCH.
  347. type The command type, any of the following symbols:
  348. agenda The daily/weekly agenda.
  349. todo Entries with a specific TODO keyword, in all agenda files.
  350. search Entries containing search words entry or headline.
  351. tags Tags/Property/TODO match in all agenda files.
  352. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  353. todo-tree Sparse tree of specific TODO keyword in *current* file.
  354. tags-tree Sparse tree with all tags matches in *current* file.
  355. occur-tree Occur sparse tree for *current* file.
  356. ... A user-defined function.
  357. match What to search for:
  358. - a single keyword for TODO keyword searches
  359. - a tags match expression for tags searches
  360. - a word search expression for text searches.
  361. - a regular expression for occur searches
  362. For all other commands, this should be the empty string.
  363. settings A list of option settings, similar to that in a let form, so like
  364. this: ((opt1 val1) (opt2 val2) ...). The values will be
  365. evaluated at the moment of execution, so quote them when needed.
  366. files A list of files file to write the produced agenda buffer to
  367. with the command `org-store-agenda-views'.
  368. If a file name ends in \".html\", an HTML version of the buffer
  369. is written out. If it ends in \".ps\", a postscript version is
  370. produced. Otherwise, only the plain text is written to the file.
  371. You can also define a set of commands, to create a composite agenda buffer.
  372. In this case, an entry looks like this:
  373. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  374. where
  375. desc A description string to be displayed in the dispatcher menu.
  376. cmd An agenda command, similar to the above. However, tree commands
  377. are not allowed, but instead you can get agenda and global todo list.
  378. So valid commands for a set are:
  379. (agenda \"\" settings)
  380. (alltodo \"\" settings)
  381. (stuck \"\" settings)
  382. (todo \"match\" settings files)
  383. (search \"match\" settings files)
  384. (tags \"match\" settings files)
  385. (tags-todo \"match\" settings files)
  386. Each command can carry a list of options, and another set of options can be
  387. given for the whole set of commands. Individual command options take
  388. precedence over the general options.
  389. When using several characters as key to a command, the first characters
  390. are prefix commands. For the dispatcher to display useful information, you
  391. should provide a description for the prefix, like
  392. (setq org-agenda-custom-commands
  393. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  394. (\"hl\" tags \"+HOME+Lisa\")
  395. (\"hp\" tags \"+HOME+Peter\")
  396. (\"hk\" tags \"+HOME+Kim\")))"
  397. :group 'org-agenda-custom-commands
  398. :type `(repeat
  399. (choice :value ("x" "Describe command here" tags "" nil)
  400. (list :tag "Single command"
  401. (string :tag "Access Key(s) ")
  402. (option (string :tag "Description"))
  403. (choice
  404. (const :tag "Agenda" agenda)
  405. (const :tag "TODO list" alltodo)
  406. (const :tag "Search words" search)
  407. (const :tag "Stuck projects" stuck)
  408. (const :tag "Tags/Property match (all agenda files)" tags)
  409. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  410. (const :tag "TODO keyword search (all agenda files)" todo)
  411. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  412. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  413. (const :tag "Occur tree (current buffer)" occur-tree)
  414. (sexp :tag "Other, user-defined function"))
  415. (string :tag "Match (only for some commands)")
  416. ,org-agenda-custom-commands-local-options
  417. (option (repeat :tag "Export" (file :tag "Export to"))))
  418. (list :tag "Command series, all agenda files"
  419. (string :tag "Access Key(s)")
  420. (string :tag "Description ")
  421. (repeat :tag "Component"
  422. (choice
  423. (list :tag "Agenda"
  424. (const :format "" agenda)
  425. (const :tag "" :format "" "")
  426. ,org-agenda-custom-commands-local-options)
  427. (list :tag "TODO list (all keywords)"
  428. (const :format "" alltodo)
  429. (const :tag "" :format "" "")
  430. ,org-agenda-custom-commands-local-options)
  431. (list :tag "Search words"
  432. (const :format "" search)
  433. (string :tag "Match")
  434. ,org-agenda-custom-commands-local-options)
  435. (list :tag "Stuck projects"
  436. (const :format "" stuck)
  437. (const :tag "" :format "" "")
  438. ,org-agenda-custom-commands-local-options)
  439. (list :tag "Tags search"
  440. (const :format "" tags)
  441. (string :tag "Match")
  442. ,org-agenda-custom-commands-local-options)
  443. (list :tag "Tags search, TODO entries only"
  444. (const :format "" tags-todo)
  445. (string :tag "Match")
  446. ,org-agenda-custom-commands-local-options)
  447. (list :tag "TODO keyword search"
  448. (const :format "" todo)
  449. (string :tag "Match")
  450. ,org-agenda-custom-commands-local-options)
  451. (list :tag "Other, user-defined function"
  452. (symbol :tag "function")
  453. (string :tag "Match")
  454. ,org-agenda-custom-commands-local-options)))
  455. (repeat :tag "Settings for entire command set"
  456. (list (variable :tag "Any variable")
  457. (sexp :tag "Value")))
  458. (option (repeat :tag "Export" (file :tag "Export to"))))
  459. (cons :tag "Prefix key documentation"
  460. (string :tag "Access Key(s)")
  461. (string :tag "Description ")))))
  462. (defcustom org-agenda-query-register ?o
  463. "The register holding the current query string.
  464. The purpose of this is that if you construct a query string interactively,
  465. you can then use it to define a custom command."
  466. :group 'org-agenda-custom-commands
  467. :type 'character)
  468. (defcustom org-stuck-projects
  469. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  470. "How to identify stuck projects.
  471. This is a list of four items:
  472. 1. A tags/todo/property matcher string that is used to identify a project.
  473. See the manual for a description of tag and property searches.
  474. The entire tree below a headline matched by this is considered one project.
  475. 2. A list of TODO keywords identifying non-stuck projects.
  476. If the project subtree contains any headline with one of these todo
  477. keywords, the project is considered to be not stuck. If you specify
  478. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  479. 3. A list of tags identifying non-stuck projects.
  480. If the project subtree contains any headline with one of these tags,
  481. the project is considered to be not stuck. If you specify \"*\" as
  482. a tag, any tag will mark the project unstuck. Note that this is about
  483. the explicit presence of a tag somewhere in the subtree, inherited
  484. tags to not count here. If inherited tags make a project not stuck,
  485. use \"-TAG\" in the tags part of the matcher under (1.) above.
  486. 4. An arbitrary regular expression matching non-stuck projects.
  487. If the project turns out to be not stuck, search continues also in the
  488. subtree to see if any of the subtasks have project status.
  489. See also the variable `org-tags-match-list-sublevels' which applies
  490. to projects matched by this search as well.
  491. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  492. or `C-c a #' to produce the list."
  493. :group 'org-agenda-custom-commands
  494. :type '(list
  495. (string :tag "Tags/TODO match to identify a project")
  496. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  497. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  498. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  499. (defcustom org-agenda-filter-effort-default-operator "<"
  500. "The default operator for effort estimate filtering.
  501. If you select an effort estimate limit without first pressing an operator,
  502. this one will be used."
  503. :group 'org-agenda-custom-commands
  504. :type '(choice (const :tag "less or equal" "<")
  505. (const :tag "greater or equal"">")
  506. (const :tag "equal" "=")))
  507. (defgroup org-agenda-skip nil
  508. "Options concerning skipping parts of agenda files."
  509. :tag "Org Agenda Skip"
  510. :group 'org-agenda)
  511. (defcustom org-agenda-skip-function-global nil
  512. "Function to be called at each match during agenda construction.
  513. If this function returns nil, the current match should not be skipped.
  514. If the function decided to skip an agenda match, is must return the
  515. buffer position from which the search should be continued.
  516. This may also be a Lisp form, which will be evaluated.
  517. This variable will be applied to every agenda match, including
  518. tags/property searches and TODO lists. So try to make the test function
  519. do its checking as efficiently as possible. To implement a skipping
  520. condition just for specific agenda commands, use the variable
  521. `org-agenda-skip-function' which can be set in the options section
  522. of custom agenda commands."
  523. :group 'org-agenda-skip
  524. :type 'sexp)
  525. (defgroup org-agenda-daily/weekly nil
  526. "Options concerning the daily/weekly agenda."
  527. :tag "Org Agenda Daily/Weekly"
  528. :group 'org-agenda)
  529. (defgroup org-agenda-todo-list nil
  530. "Options concerning the global todo list agenda view."
  531. :tag "Org Agenda Todo List"
  532. :group 'org-agenda)
  533. (defgroup org-agenda-match-view nil
  534. "Options concerning the general tags/property/todo match agenda view."
  535. :tag "Org Agenda Match View"
  536. :group 'org-agenda)
  537. (defgroup org-agenda-search-view nil
  538. "Options concerning the general tags/property/todo match agenda view."
  539. :tag "Org Agenda Match View"
  540. :group 'org-agenda)
  541. (defvar org-agenda-archives-mode nil
  542. "Non-nil means the agenda will include archived items.
  543. If this is the symbol `trees', trees in the selected agenda scope
  544. that are marked with the ARCHIVE tag will be included anyway. When this is
  545. t, also all archive files associated with the current selection of agenda
  546. files will be included.")
  547. (defcustom org-agenda-skip-comment-trees t
  548. "Non-nil means skip trees that start with the COMMENT keyword.
  549. When nil, these trees are also scanned by agenda commands."
  550. :group 'org-agenda-skip
  551. :type 'boolean)
  552. (defcustom org-agenda-todo-list-sublevels t
  553. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  554. When nil, the sublevels of a TODO entry are not checked, resulting in
  555. potentially much shorter TODO lists."
  556. :group 'org-agenda-skip
  557. :group 'org-agenda-todo-list
  558. :type 'boolean)
  559. (defcustom org-agenda-todo-ignore-with-date nil
  560. "Non-nil means don't show entries with a date in the global todo list.
  561. You can use this if you prefer to mark mere appointments with a TODO keyword,
  562. but don't want them to show up in the TODO list.
  563. When this is set, it also covers deadlines and scheduled items, the settings
  564. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  565. will be ignored.
  566. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  567. :group 'org-agenda-skip
  568. :group 'org-agenda-todo-list
  569. :type 'boolean)
  570. (defcustom org-agenda-todo-ignore-timestamp nil
  571. "Non-nil means don't show entries with a timestamp.
  572. This applies when creating the global todo list.
  573. Valid values are:
  574. past Don't show entries for today or in the past.
  575. future Don't show entries with a timestamp in the future.
  576. The idea behind this is that if it has a future
  577. timestamp, you don't want to think about it until the
  578. date.
  579. all Don't show any entries with a timestamp in the global todo list.
  580. The idea behind this is that by setting a timestamp, you
  581. have already \"taken care\" of this item.
  582. This variable can also have an integer as a value. If positive (N),
  583. todos with a timestamp N or more days in the future will be ignored. If
  584. negative (-N), todos with a timestamp N or more days in the past will be
  585. ignored. If 0, todos with a timestamp either today or in the future will
  586. be ignored. For example, a value of -1 will exclude todos with a
  587. timestamp in the past (yesterday or earlier), while a value of 7 will
  588. exclude todos with a timestamp a week or more in the future.
  589. See also `org-agenda-todo-ignore-with-date'.
  590. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  591. to make his option also apply to the tags-todo list."
  592. :group 'org-agenda-skip
  593. :group 'org-agenda-todo-list
  594. :version "24.1"
  595. :type '(choice
  596. (const :tag "Ignore future timestamp todos" future)
  597. (const :tag "Ignore past or present timestamp todos" past)
  598. (const :tag "Ignore all timestamp todos" all)
  599. (const :tag "Show timestamp todos" nil)
  600. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  601. (defcustom org-agenda-todo-ignore-scheduled nil
  602. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  603. This applies when creating the global todo list.
  604. Valid values are:
  605. past Don't show entries scheduled today or in the past.
  606. future Don't show entries scheduled in the future.
  607. The idea behind this is that by scheduling it, you don't want to
  608. think about it until the scheduled date.
  609. all Don't show any scheduled entries in the global todo list.
  610. The idea behind this is that by scheduling it, you have already
  611. \"taken care\" of this item.
  612. t Same as `all', for backward compatibility.
  613. This variable can also have an integer as a value. See
  614. `org-agenda-todo-ignore-timestamp' for more details.
  615. See also `org-agenda-todo-ignore-with-date'.
  616. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  617. to make his option also apply to the tags-todo list."
  618. :group 'org-agenda-skip
  619. :group 'org-agenda-todo-list
  620. :type '(choice
  621. (const :tag "Ignore future-scheduled todos" future)
  622. (const :tag "Ignore past- or present-scheduled todos" past)
  623. (const :tag "Ignore all scheduled todos" all)
  624. (const :tag "Ignore all scheduled todos (compatibility)" t)
  625. (const :tag "Show scheduled todos" nil)
  626. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  627. (defcustom org-agenda-todo-ignore-deadlines nil
  628. "Non-nil means ignore some deadlined TODO items when making TODO list.
  629. There are different motivations for using different values, please think
  630. carefully when configuring this variable.
  631. This applies when creating the global todo list.
  632. Valid values are:
  633. near Don't show near deadline entries. A deadline is near when it is
  634. closer than `org-deadline-warning-days' days. The idea behind this
  635. is that such items will appear in the agenda anyway.
  636. far Don't show TODO entries where a deadline has been defined, but
  637. the deadline is not near. This is useful if you don't want to
  638. use the todo list to figure out what to do now.
  639. past Don't show entries with a deadline timestamp for today or in the past.
  640. future Don't show entries with a deadline timestamp in the future, not even
  641. when they become `near' ones. Use it with caution.
  642. all Ignore all TODO entries that do have a deadline.
  643. t Same as `near', for backward compatibility.
  644. This variable can also have an integer as a value. See
  645. `org-agenda-todo-ignore-timestamp' for more details.
  646. See also `org-agenda-todo-ignore-with-date'.
  647. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  648. to make his option also apply to the tags-todo list."
  649. :group 'org-agenda-skip
  650. :group 'org-agenda-todo-list
  651. :type '(choice
  652. (const :tag "Ignore near deadlines" near)
  653. (const :tag "Ignore near deadlines (compatibility)" t)
  654. (const :tag "Ignore far deadlines" far)
  655. (const :tag "Ignore all TODOs with a deadlines" all)
  656. (const :tag "Show all TODOs, even if they have a deadline" nil)
  657. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  658. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  659. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  660. The variables
  661. `org-agenda-todo-ignore-with-date',
  662. `org-agenda-todo-ignore-timestamp',
  663. `org-agenda-todo-ignore-scheduled',
  664. `org-agenda-todo-ignore-deadlines'
  665. make the global TODO list skip entries that have time stamps of certain
  666. kinds. If this option is set, the same options will also apply for the
  667. tags-todo search, which is the general tags/property matcher
  668. restricted to unfinished TODO entries only."
  669. :group 'org-agenda-skip
  670. :group 'org-agenda-todo-list
  671. :group 'org-agenda-match-view
  672. :type 'boolean)
  673. (defcustom org-agenda-skip-scheduled-if-done nil
  674. "Non-nil means don't show scheduled items in agenda when they are done.
  675. This is relevant for the daily/weekly agenda, not for the TODO list. And
  676. it applies only to the actual date of the scheduling. Warnings about
  677. an item with a past scheduling dates are always turned off when the item
  678. is DONE."
  679. :group 'org-agenda-skip
  680. :group 'org-agenda-daily/weekly
  681. :type 'boolean)
  682. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  683. "Non-nil means skip scheduling line if same entry shows because of deadline.
  684. In the agenda of today, an entry can show up multiple times because
  685. it is both scheduled and has a nearby deadline, and maybe a plain time
  686. stamp as well.
  687. When this variable is t, then only the deadline is shown and the fact that
  688. the entry is scheduled today or was scheduled previously is not shown.
  689. When this variable is nil, the entry will be shown several times. When
  690. the variable is the symbol `not-today', then skip scheduled previously,
  691. but not scheduled today."
  692. :group 'org-agenda-skip
  693. :group 'org-agenda-daily/weekly
  694. :type '(choice
  695. (const :tag "Never" nil)
  696. (const :tag "Always" t)
  697. (const :tag "Not when scheduled today" not-today)))
  698. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  699. "Non-nil means skip timestamp line if same entry shows because of deadline.
  700. In the agenda of today, an entry can show up multiple times
  701. because it has both a plain timestamp and has a nearby deadline.
  702. When this variable is t, then only the deadline is shown and the
  703. fact that the entry has a timestamp for or including today is not
  704. shown. When this variable is nil, the entry will be shown
  705. several times."
  706. :group 'org-agenda-skip
  707. :group 'org-agenda-daily/weekly
  708. :version "24.1"
  709. :type '(choice
  710. (const :tag "Never" nil)
  711. (const :tag "Always" t)))
  712. (defcustom org-agenda-skip-deadline-if-done nil
  713. "Non-nil means don't show deadlines when the corresponding item is done.
  714. When nil, the deadline is still shown and should give you a happy feeling.
  715. This is relevant for the daily/weekly agenda. And it applied only to the
  716. actually date of the deadline. Warnings about approaching and past-due
  717. deadlines are always turned off when the item is DONE."
  718. :group 'org-agenda-skip
  719. :group 'org-agenda-daily/weekly
  720. :type 'boolean)
  721. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  722. "Non-nil means skip deadline prewarning when entry is also scheduled.
  723. This will apply on all days where a prewarning for the deadline would
  724. be shown, but not at the day when the entry is actually due. On that day,
  725. the deadline will be shown anyway.
  726. This variable may be set to nil, t, or a number which will then give
  727. the number of days before the actual deadline when the prewarnings
  728. should resume.
  729. This can be used in a workflow where the first showing of the deadline will
  730. trigger you to schedule it, and then you don't want to be reminded of it
  731. because you will take care of it on the day when scheduled."
  732. :group 'org-agenda-skip
  733. :group 'org-agenda-daily/weekly
  734. :version "24.1"
  735. :type '(choice
  736. (const :tag "Alwas show prewarning" nil)
  737. (const :tag "Remove prewarning if entry is scheduled" t)
  738. (integer :tag "Restart prewarning N days before deadline")))
  739. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  740. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  741. When non-nil, after the search for timestamps has matched once in an
  742. entry, the rest of the entry will not be searched."
  743. :group 'org-agenda-skip
  744. :type 'boolean)
  745. (defcustom org-agenda-skip-timestamp-if-done nil
  746. "Non-nil means don't select item by timestamp or -range if it is DONE."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-daily/weekly
  749. :type 'boolean)
  750. (defcustom org-agenda-dim-blocked-tasks t
  751. "Non-nil means dim blocked tasks in the agenda display.
  752. This causes some overhead during agenda construction, but if you
  753. have turned on `org-enforce-todo-dependencies',
  754. `org-enforce-todo-checkbox-dependencies', or any other blocking
  755. mechanism, this will create useful feedback in the agenda.
  756. Instead of t, this variable can also have the value `invisible'.
  757. Then blocked tasks will be invisible and only become visible when
  758. they become unblocked. An exemption to this behavior is when a task is
  759. blocked because of unchecked checkboxes below it. Since checkboxes do
  760. not show up in the agenda views, making this task invisible you remove any
  761. trace from agenda views that there is something to do. Therefore, a task
  762. that is blocked because of checkboxes will never be made invisible, it
  763. will only be dimmed."
  764. :group 'org-agenda-daily/weekly
  765. :group 'org-agenda-todo-list
  766. :type '(choice
  767. (const :tag "Do not dim" nil)
  768. (const :tag "Dim to a gray face" t)
  769. (const :tag "Make invisible" invisible)))
  770. (defcustom org-timeline-show-empty-dates 3
  771. "Non-nil means `org-timeline' also shows dates without an entry.
  772. When nil, only the days which actually have entries are shown.
  773. When t, all days between the first and the last date are shown.
  774. When an integer, show also empty dates, but if there is a gap of more than
  775. N days, just insert a special line indicating the size of the gap."
  776. :group 'org-agenda-skip
  777. :type '(choice
  778. (const :tag "None" nil)
  779. (const :tag "All" t)
  780. (integer :tag "at most")))
  781. (defgroup org-agenda-startup nil
  782. "Options concerning initial settings in the Agenda in Org Mode."
  783. :tag "Org Agenda Startup"
  784. :group 'org-agenda)
  785. (defcustom org-agenda-menu-show-matcher t
  786. "Non-nil means show the match string in the agenda dispatcher menu.
  787. When nil, the matcher string is not shown, but is put into the help-echo
  788. property so than moving the mouse over the command shows it.
  789. Setting it to nil is good if matcher strings are very long and/or if
  790. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  791. :group 'org-agenda
  792. :version "24.1"
  793. :type 'boolean)
  794. (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  795. (defcustom org-agenda-menu-two-columns nil
  796. "Non-nil means, use two columns to show custom commands in the dispatcher.
  797. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  798. to nil."
  799. :group 'org-agenda
  800. :version "24.1"
  801. :type 'boolean)
  802. (make-obsolete-variable 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  803. (defcustom org-agenda-finalize-hook nil
  804. "Hook run just before displaying an agenda buffer."
  805. :group 'org-agenda-startup
  806. :type 'hook)
  807. (defcustom org-agenda-mouse-1-follows-link nil
  808. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  809. A longer mouse click will still set point. Does not work on XEmacs.
  810. Needs to be set before org.el is loaded."
  811. :group 'org-agenda-startup
  812. :type 'boolean)
  813. (defcustom org-agenda-start-with-follow-mode nil
  814. "The initial value of follow mode in a newly created agenda window."
  815. :group 'org-agenda-startup
  816. :type 'boolean)
  817. (defcustom org-agenda-follow-indirect nil
  818. "Non-nil means `org-agenda-follow-mode' displays only the
  819. current item's tree, in an indirect buffer."
  820. :group 'org-agenda
  821. :version "24.1"
  822. :type 'boolean)
  823. (defcustom org-agenda-show-outline-path t
  824. "Non-nil means show outline path in echo area after line motion."
  825. :group 'org-agenda-startup
  826. :type 'boolean)
  827. (defcustom org-agenda-start-with-entry-text-mode nil
  828. "The initial value of entry-text-mode in a newly created agenda window."
  829. :group 'org-agenda-startup
  830. :type 'boolean)
  831. (defcustom org-agenda-entry-text-maxlines 5
  832. "Number of text lines to be added when `E' is pressed in the agenda.
  833. Note that this variable only used during agenda display. Add add entry text
  834. when exporting the agenda, configure the variable
  835. `org-agenda-add-entry-ext-maxlines'."
  836. :group 'org-agenda
  837. :type 'integer)
  838. (defcustom org-agenda-entry-text-exclude-regexps nil
  839. "List of regular expressions to clean up entry text.
  840. The complete matches of all regular expressions in this list will be
  841. removed from entry text before it is shown in the agenda."
  842. :group 'org-agenda
  843. :type '(repeat (regexp)))
  844. (defvar org-agenda-entry-text-cleanup-hook nil
  845. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  846. This cleanup is done in a temporary buffer, so the function may inspect and
  847. change the entire buffer.
  848. Some default stuff like drawers and scheduling/deadline dates will already
  849. have been removed when this is called, as will any matches for regular
  850. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  851. (defvar org-agenda-include-inactive-timestamps nil
  852. "Non-nil means include inactive time stamps in agenda and timeline.
  853. Dynamically scoped.")
  854. (defgroup org-agenda-windows nil
  855. "Options concerning the windows used by the Agenda in Org Mode."
  856. :tag "Org Agenda Windows"
  857. :group 'org-agenda)
  858. (defcustom org-agenda-window-setup 'reorganize-frame
  859. "How the agenda buffer should be displayed.
  860. Possible values for this option are:
  861. current-window Show agenda in the current window, keeping all other windows.
  862. other-window Use `switch-to-buffer-other-window' to display agenda.
  863. reorganize-frame Show only two windows on the current frame, the current
  864. window and the agenda.
  865. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  866. Also, when exiting the agenda, kill that frame.
  867. See also the variable `org-agenda-restore-windows-after-quit'."
  868. :group 'org-agenda-windows
  869. :type '(choice
  870. (const current-window)
  871. (const other-frame)
  872. (const other-window)
  873. (const reorganize-frame)))
  874. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  875. "The min and max height of the agenda window as a fraction of frame height.
  876. The value of the variable is a cons cell with two numbers between 0 and 1.
  877. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  878. :group 'org-agenda-windows
  879. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  880. (defcustom org-agenda-restore-windows-after-quit nil
  881. "Non-nil means restore window configuration upon exiting agenda.
  882. Before the window configuration is changed for displaying the agenda,
  883. the current status is recorded. When the agenda is exited with
  884. `q' or `x' and this option is set, the old state is restored. If
  885. `org-agenda-window-setup' is `other-frame', the value of this
  886. option will be ignored."
  887. :group 'org-agenda-windows
  888. :type 'boolean)
  889. (defcustom org-agenda-ndays nil
  890. "Number of days to include in overview display.
  891. Should be 1 or 7.
  892. Obsolete, see `org-agenda-span'."
  893. :group 'org-agenda-daily/weekly
  894. :type 'integer)
  895. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  896. (defcustom org-agenda-span 'week
  897. "Number of days to include in overview display.
  898. Can be day, week, month, year, or any number of days.
  899. Custom commands can set this variable in the options section."
  900. :group 'org-agenda-daily/weekly
  901. :type '(choice (const :tag "Day" day)
  902. (const :tag "Week" week)
  903. (const :tag "Month" month)
  904. (const :tag "Year" year)
  905. (integer :tag "Custom")))
  906. (defcustom org-agenda-start-on-weekday 1
  907. "Non-nil means start the overview always on the specified weekday.
  908. 0 denotes Sunday, 1 denotes Monday etc.
  909. When nil, always start on the current day.
  910. Custom commands can set this variable in the options section."
  911. :group 'org-agenda-daily/weekly
  912. :type '(choice (const :tag "Today" nil)
  913. (integer :tag "Weekday No.")))
  914. (defcustom org-agenda-show-all-dates t
  915. "Non-nil means `org-agenda' shows every day in the selected range.
  916. When nil, only the days which actually have entries are shown."
  917. :group 'org-agenda-daily/weekly
  918. :type 'boolean)
  919. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  920. "Format string for displaying dates in the agenda.
  921. Used by the daily/weekly agenda and by the timeline. This should be
  922. a format string understood by `format-time-string', or a function returning
  923. the formatted date as a string. The function must take a single argument,
  924. a calendar-style date list like (month day year)."
  925. :group 'org-agenda-daily/weekly
  926. :type '(choice
  927. (string :tag "Format string")
  928. (function :tag "Function")))
  929. (defun org-agenda-format-date-aligned (date)
  930. "Format a date string for display in the daily/weekly agenda, or timeline.
  931. This function makes sure that dates are aligned for easy reading."
  932. (require 'cal-iso)
  933. (let* ((dayname (calendar-day-name date))
  934. (day (cadr date))
  935. (day-of-week (calendar-day-of-week date))
  936. (month (car date))
  937. (monthname (calendar-month-name month))
  938. (year (nth 2 date))
  939. (iso-week (org-days-to-iso-week
  940. (calendar-absolute-from-gregorian date)))
  941. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  942. (1- year))
  943. ((and (= month 12) (<= iso-week 1))
  944. (1+ year))
  945. (t year)))
  946. (weekstring (if (= day-of-week 1)
  947. (format " W%02d" iso-week)
  948. "")))
  949. (format "%-10s %2d %s %4d%s"
  950. dayname day monthname year weekstring)))
  951. (defcustom org-agenda-time-leading-zero nil
  952. "Non-nil means use leading zero for military times in agenda.
  953. For example, 9:30am would become 09:30 rather than 9:30."
  954. :group 'org-agenda-daily/weekly
  955. :version "24.1"
  956. :type 'boolean)
  957. (defcustom org-agenda-timegrid-use-ampm nil
  958. "When set, show AM/PM style timestamps on the timegrid."
  959. :group 'org-agenda
  960. :version "24.1"
  961. :type 'boolean)
  962. (defun org-agenda-time-of-day-to-ampm (time)
  963. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  964. (let* ((hour-number (string-to-number (substring time 0 -3)))
  965. (minute (substring time -2))
  966. (ampm "am"))
  967. (cond
  968. ((equal hour-number 12)
  969. (setq ampm "pm"))
  970. ((> hour-number 12)
  971. (setq ampm "pm")
  972. (setq hour-number (- hour-number 12))))
  973. (concat
  974. (if org-agenda-time-leading-zero
  975. (format "%02d" hour-number)
  976. (format "%02s" (number-to-string hour-number)))
  977. ":" minute ampm)))
  978. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  979. "Conditionally convert TIME to AM/PM format
  980. based on `org-agenda-timegrid-use-ampm'"
  981. (if org-agenda-timegrid-use-ampm
  982. (org-agenda-time-of-day-to-ampm time)
  983. time))
  984. (defcustom org-agenda-weekend-days '(6 0)
  985. "Which days are weekend?
  986. These days get the special face `org-agenda-date-weekend' in the agenda
  987. and timeline buffers."
  988. :group 'org-agenda-daily/weekly
  989. :type '(set :greedy t
  990. (const :tag "Monday" 1)
  991. (const :tag "Tuesday" 2)
  992. (const :tag "Wednesday" 3)
  993. (const :tag "Thursday" 4)
  994. (const :tag "Friday" 5)
  995. (const :tag "Saturday" 6)
  996. (const :tag "Sunday" 0)))
  997. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  998. "Non-nil means jump to today when moving a past date forward in time.
  999. When using S-right in the agenda to move a a date forward, and the date
  1000. stamp currently points to the past, the first key press will move it
  1001. to today. WHen nil, just move one day forward even if the date stays
  1002. in the past."
  1003. :group 'org-agenda-daily/weekly
  1004. :version "24.1"
  1005. :type 'boolean)
  1006. (defcustom org-agenda-include-diary nil
  1007. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1008. Custom commands can set this variable in the options section."
  1009. :group 'org-agenda-daily/weekly
  1010. :type 'boolean)
  1011. (defcustom org-agenda-include-deadlines t
  1012. "If non-nil, include entries within their deadline warning period.
  1013. Custom commands can set this variable in the options section."
  1014. :group 'org-agenda-daily/weekly
  1015. :version "24.1"
  1016. :type 'boolean)
  1017. (defcustom org-agenda-repeating-timestamp-show-all t
  1018. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1019. When set to a list of strings, only show occurrences of repeating
  1020. stamps for these TODO keywords. When nil, only one occurrence is
  1021. shown, either today or the nearest into the future."
  1022. :group 'org-agenda-daily/weekly
  1023. :type '(choice
  1024. (const :tag "Show repeating stamps" t)
  1025. (repeat :tag "Show repeating stamps for these TODO keywords"
  1026. (string :tag "TODO Keyword"))
  1027. (const :tag "Don't show repeating stamps" nil)))
  1028. (defcustom org-scheduled-past-days 10000
  1029. "No. of days to continue listing scheduled items that are not marked DONE.
  1030. When an item is scheduled on a date, it shows up in the agenda on this
  1031. day and will be listed until it is marked done for the number of days
  1032. given here."
  1033. :group 'org-agenda-daily/weekly
  1034. :type 'integer)
  1035. (defcustom org-agenda-log-mode-items '(closed clock)
  1036. "List of items that should be shown in agenda log mode.
  1037. This list may contain the following symbols:
  1038. closed Show entries that have been closed on that day.
  1039. clock Show entries that have received clocked time on that day.
  1040. state Show all logged state changes.
  1041. Note that instead of changing this variable, you can also press `C-u l' in
  1042. the agenda to display all available LOG items temporarily."
  1043. :group 'org-agenda-daily/weekly
  1044. :type '(set :greedy t (const closed) (const clock) (const state)))
  1045. (defcustom org-agenda-clock-consistency-checks
  1046. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1047. :gap-ok-around ("4:00")
  1048. :default-face ((:background "DarkRed") (:foreground "white"))
  1049. :overlap-face nil :gap-face nil :no-end-time-face nil
  1050. :long-face nil :short-face nil)
  1051. "This is a property list, with the following keys:
  1052. :max-duration Mark clocking chunks that are longer than this time.
  1053. This is a time string like \"HH:MM\", or the number
  1054. of minutes as an integer.
  1055. :min-duration Mark clocking chunks that are shorter that this.
  1056. This is a time string like \"HH:MM\", or the number
  1057. of minutes as an integer.
  1058. :max-gap Mark gaps between clocking chunks that are longer than
  1059. this duration. A number of minutes, or a string
  1060. like \"HH:MM\".
  1061. :gap-ok-around List of times during the day which are usually not working
  1062. times. When a gap is detected, but the gap contains any
  1063. of these times, the gap is *not* reported. For example,
  1064. if this is (\"4:00\" \"13:00\") then gaps that contain
  1065. 4:00 in the morning (i.e. the night) and 13:00
  1066. (i.e. a typical lunch time) do not cause a warning.
  1067. You should have at least one time during the night in this
  1068. list, or otherwise the first task each morning will trigger
  1069. a warning because it follows a long gap.
  1070. Furthermore, the following properties can be used to define faces for
  1071. issue display.
  1072. :default-face the default face, if the specific face is undefined
  1073. :overlap-face face for overlapping clocks
  1074. :gap-face face for gaps between clocks
  1075. :no-end-time-face face for incomplete clocks
  1076. :long-face face for clock intervals that are too long
  1077. :short-face face for clock intervals that are too short"
  1078. :group 'org-agenda-daily/weekly
  1079. :group 'org-clock
  1080. :version "24.1"
  1081. :type 'plist)
  1082. (defcustom org-agenda-log-mode-add-notes t
  1083. "Non-nil means add first line of notes to log entries in agenda views.
  1084. If a log item like a state change or a clock entry is associated with
  1085. notes, the first line of these notes will be added to the entry in the
  1086. agenda display."
  1087. :group 'org-agenda-daily/weekly
  1088. :type 'boolean)
  1089. (defcustom org-agenda-start-with-log-mode nil
  1090. "The initial value of log-mode in a newly created agenda window.
  1091. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1092. explanations on the possible values."
  1093. :group 'org-agenda-startup
  1094. :group 'org-agenda-daily/weekly
  1095. :type '(choice (const :tag "Don't show log items" nil)
  1096. (const :tag "Show only log items" 'only)
  1097. (const :tag "Show all possible log items" 'clockcheck)
  1098. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1099. (choice (const :tag "Show closed log items" 'closed)
  1100. (const :tag "Show clocked log items" 'clock)
  1101. (const :tag "Show all logged state changes" 'state)))))
  1102. (defcustom org-agenda-start-with-clockreport-mode nil
  1103. "The initial value of clockreport-mode in a newly created agenda window."
  1104. :group 'org-agenda-startup
  1105. :group 'org-agenda-daily/weekly
  1106. :type 'boolean)
  1107. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1108. "Property list with parameters for the clocktable in clockreport mode.
  1109. This is the display mode that shows a clock table in the daily/weekly
  1110. agenda, the properties for this dynamic block can be set here.
  1111. The usual clocktable parameters are allowed here, but you cannot set
  1112. the properties :name, :tstart, :tend, :block, and :scope - these will
  1113. be overwritten to make sure the content accurately reflects the
  1114. current display in the agenda."
  1115. :group 'org-agenda-daily/weekly
  1116. :type 'plist)
  1117. (defcustom org-agenda-search-view-always-boolean nil
  1118. "Non-nil means the search string is interpreted as individual parts.
  1119. The search string for search view can either be interpreted as a phrase,
  1120. or as a list of snippets that define a boolean search for a number of
  1121. strings.
  1122. When this is non-nil, the string will be split on whitespace, and each
  1123. snippet will be searched individually, and all must match in order to
  1124. select an entry. A snippet is then a single string of non-white
  1125. characters, or a string in double quotes, or a regexp in {} braces.
  1126. If a snippet is preceded by \"-\", the snippet must *not* match.
  1127. \"+\" is syntactic sugar for positive selection. Each snippet may
  1128. be found as a full word or a partial word, but see the variable
  1129. `org-agenda-search-view-force-full-words'.
  1130. When this is nil, search will look for the entire search phrase as one,
  1131. with each space character matching any amount of whitespace, including
  1132. line breaks.
  1133. Even when this is nil, you can still switch to Boolean search dynamically
  1134. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1135. is a regexp marked with braces like \"{abc}\", this will also switch to
  1136. boolean search."
  1137. :group 'org-agenda-search-view
  1138. :version "24.1"
  1139. :type 'boolean)
  1140. (if (fboundp 'defvaralias)
  1141. (defvaralias 'org-agenda-search-view-search-words-only
  1142. 'org-agenda-search-view-always-boolean))
  1143. (defcustom org-agenda-search-view-force-full-words nil
  1144. "Non-nil means, search words must be matches as complete words.
  1145. When nil, they may also match part of a word."
  1146. :group 'org-agenda-search-view
  1147. :version "24.1"
  1148. :type 'boolean)
  1149. (defgroup org-agenda-time-grid nil
  1150. "Options concerning the time grid in the Org-mode Agenda."
  1151. :tag "Org Agenda Time Grid"
  1152. :group 'org-agenda)
  1153. (defcustom org-agenda-search-headline-for-time t
  1154. "Non-nil means search headline for a time-of-day.
  1155. If the headline contains a time-of-day in one format or another, it will
  1156. be used to sort the entry into the time sequence of items for a day.
  1157. Some people have time stamps in the headline that refer to the creation
  1158. time or so, and then this produces an unwanted side effect. If this is
  1159. the case for your, use this variable to turn off searching the headline
  1160. for a time."
  1161. :group 'org-agenda-time-grid
  1162. :type 'boolean)
  1163. (defcustom org-agenda-use-time-grid t
  1164. "Non-nil means show a time grid in the agenda schedule.
  1165. A time grid is a set of lines for specific times (like every two hours between
  1166. 8:00 and 20:00). The items scheduled for a day at specific times are
  1167. sorted in between these lines.
  1168. For details about when the grid will be shown, and what it will look like, see
  1169. the variable `org-agenda-time-grid'."
  1170. :group 'org-agenda-time-grid
  1171. :type 'boolean)
  1172. (defcustom org-agenda-time-grid
  1173. '((daily today require-timed)
  1174. "----------------"
  1175. (800 1000 1200 1400 1600 1800 2000))
  1176. "The settings for time grid for agenda display.
  1177. This is a list of three items. The first item is again a list. It contains
  1178. symbols specifying conditions when the grid should be displayed:
  1179. daily if the agenda shows a single day
  1180. weekly if the agenda shows an entire week
  1181. today show grid on current date, independent of daily/weekly display
  1182. require-timed show grid only if at least one item has a time specification
  1183. The second item is a string which will be placed behind the grid time.
  1184. The third item is a list of integers, indicating the times that should have
  1185. a grid line."
  1186. :group 'org-agenda-time-grid
  1187. :type
  1188. '(list
  1189. (set :greedy t :tag "Grid Display Options"
  1190. (const :tag "Show grid in single day agenda display" daily)
  1191. (const :tag "Show grid in weekly agenda display" weekly)
  1192. (const :tag "Always show grid for today" today)
  1193. (const :tag "Show grid only if any timed entries are present"
  1194. require-timed)
  1195. (const :tag "Skip grid times already present in an entry"
  1196. remove-match))
  1197. (string :tag "Grid String")
  1198. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1199. (defcustom org-agenda-show-current-time-in-grid t
  1200. "Non-nil means show the current time in the time grid."
  1201. :group 'org-agenda-time-grid
  1202. :version "24.1"
  1203. :type 'boolean)
  1204. (defcustom org-agenda-current-time-string
  1205. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1206. "The string for the current time marker in the agenda."
  1207. :group 'org-agenda-time-grid
  1208. :version "24.1"
  1209. :type 'string)
  1210. (defgroup org-agenda-sorting nil
  1211. "Options concerning sorting in the Org-mode Agenda."
  1212. :tag "Org Agenda Sorting"
  1213. :group 'org-agenda)
  1214. (defcustom org-agenda-sorting-strategy
  1215. '((agenda habit-down time-up priority-down category-keep)
  1216. (todo priority-down category-keep)
  1217. (tags priority-down category-keep)
  1218. (search category-keep))
  1219. "Sorting structure for the agenda items of a single day.
  1220. This is a list of symbols which will be used in sequence to determine
  1221. if an entry should be listed before another entry. The following
  1222. symbols are recognized:
  1223. time-up Put entries with time-of-day indications first, early first
  1224. time-down Put entries with time-of-day indications first, late first
  1225. category-keep Keep the default order of categories, corresponding to the
  1226. sequence in `org-agenda-files'.
  1227. category-up Sort alphabetically by category, A-Z.
  1228. category-down Sort alphabetically by category, Z-A.
  1229. tag-up Sort alphabetically by last tag, A-Z.
  1230. tag-down Sort alphabetically by last tag, Z-A.
  1231. priority-up Sort numerically by priority, high priority last.
  1232. priority-down Sort numerically by priority, high priority first.
  1233. todo-state-up Sort by todo state, tasks that are done last.
  1234. todo-state-down Sort by todo state, tasks that are done first.
  1235. effort-up Sort numerically by estimated effort, high effort last.
  1236. effort-down Sort numerically by estimated effort, high effort first.
  1237. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1238. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1239. habit-up Put entries that are habits first
  1240. habit-down Put entries that are habits last
  1241. alpha-up Sort headlines alphabetically
  1242. alpha-down Sort headlines alphabetically, reversed
  1243. The different possibilities will be tried in sequence, and testing stops
  1244. if one comparison returns a \"not-equal\". For example, the default
  1245. '(time-up category-keep priority-down)
  1246. means: Pull out all entries having a specified time of day and sort them,
  1247. in order to make a time schedule for the current day the first thing in the
  1248. agenda listing for the day. Of the entries without a time indication, keep
  1249. the grouped in categories, don't sort the categories, but keep them in
  1250. the sequence given in `org-agenda-files'. Within each category sort by
  1251. priority.
  1252. Leaving out `category-keep' would mean that items will be sorted across
  1253. categories by priority.
  1254. Instead of a single list, this can also be a set of list for specific
  1255. contents, with a context symbol in the car of the list, any of
  1256. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1257. Custom commands can bind this variable in the options section."
  1258. :group 'org-agenda-sorting
  1259. :type `(choice
  1260. (repeat :tag "General" ,org-sorting-choice)
  1261. (list :tag "Individually"
  1262. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1263. (repeat ,org-sorting-choice))
  1264. (cons (const :tag "Strategy for TODO lists" todo)
  1265. (repeat ,org-sorting-choice))
  1266. (cons (const :tag "Strategy for Tags matches" tags)
  1267. (repeat ,org-sorting-choice))
  1268. (cons (const :tag "Strategy for search matches" search)
  1269. (repeat ,org-sorting-choice)))))
  1270. (defcustom org-agenda-cmp-user-defined nil
  1271. "A function to define the comparison `user-defined'.
  1272. This function must receive two arguments, agenda entry a and b.
  1273. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1274. the user comparison, return nil.
  1275. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1276. part of an agenda sorting strategy."
  1277. :group 'org-agenda-sorting
  1278. :type 'symbol)
  1279. (defcustom org-sort-agenda-notime-is-late t
  1280. "Non-nil means items without time are considered late.
  1281. This is only relevant for sorting. When t, items which have no explicit
  1282. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1283. do have a time. When nil, the default time is before 0:00. You can use this
  1284. option to decide if the schedule for today should come before or after timeless
  1285. agenda entries."
  1286. :group 'org-agenda-sorting
  1287. :type 'boolean)
  1288. (defcustom org-sort-agenda-noeffort-is-high t
  1289. "Non-nil means items without effort estimate are sorted as high effort.
  1290. This also applies when filtering an agenda view with respect to the
  1291. < or > effort operator. Then, tasks with no effort defined will be treated
  1292. as tasks with high effort.
  1293. When nil, such items are sorted as 0 minutes effort."
  1294. :group 'org-agenda-sorting
  1295. :type 'boolean)
  1296. (defgroup org-agenda-line-format nil
  1297. "Options concerning the entry prefix in the Org-mode agenda display."
  1298. :tag "Org Agenda Line Format"
  1299. :group 'org-agenda)
  1300. (defcustom org-agenda-prefix-format
  1301. '((agenda . " %i %-12:c%?-12t% s")
  1302. (timeline . " % s")
  1303. (todo . " %i %-12:c")
  1304. (tags . " %i %-12:c")
  1305. (search . " %i %-12:c"))
  1306. "Format specifications for the prefix of items in the agenda views.
  1307. An alist with five entries, each for the different agenda types. The
  1308. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1309. The values are format strings.
  1310. This format works similar to a printf format, with the following meaning:
  1311. %c the category of the item, \"Diary\" for entries from the diary,
  1312. or as given by the CATEGORY keyword or derived from the file name
  1313. %e the effort required by the item
  1314. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1315. %T the last tag of the item (ignore inherited tags, which come first)
  1316. %t the HH:MM time-of-day specification if one applies to the entry
  1317. %s Scheduling/Deadline information, a short string
  1318. %(expression) Eval EXPRESSION and replace the control string
  1319. by the result
  1320. All specifiers work basically like the standard `%s' of printf, but may
  1321. contain two additional characters: a question mark just after the `%'
  1322. and a whitespace/punctuation character just before the final letter.
  1323. If the first character after `%' is a question mark, the entire field
  1324. will only be included if the corresponding value applies to the current
  1325. entry. This is useful for fields which should have fixed width when
  1326. present, but zero width when absent. For example, \"%?-12t\" will
  1327. result in a 12 character time field if a time of the day is specified,
  1328. but will completely disappear in entries which do not contain a time.
  1329. If there is punctuation or whitespace character just before the final
  1330. format letter, this character will be appended to the field value if
  1331. the value is not empty. For example, the format \"%-12:c\" leads to
  1332. \"Diary: \" if the category is \"Diary\". If the category were be
  1333. empty, no additional colon would be inserted.
  1334. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1335. which means:
  1336. - Indent the line with two space characters
  1337. - Give the category a 12 chars wide field, padded with whitespace on
  1338. the right (because of `-'). Append a colon if there is a category
  1339. (because of `:').
  1340. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1341. time, don't put in an empty field, just skip it (because of '?').
  1342. - Finally, put the scheduling information.
  1343. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1344. `org-agenda-remove-tags'.
  1345. Custom commands can set this variable in the options section."
  1346. :type '(choice
  1347. (string :tag "General format")
  1348. (list :greedy t :tag "View dependent"
  1349. (cons (const agenda) (string :tag "Format"))
  1350. (cons (const timeline) (string :tag "Format"))
  1351. (cons (const todo) (string :tag "Format"))
  1352. (cons (const tags) (string :tag "Format"))
  1353. (cons (const search) (string :tag "Format"))))
  1354. :group 'org-agenda-line-format)
  1355. (defvar org-prefix-format-compiled nil
  1356. "The compiled prefix format and associated variables.
  1357. This is a list where first element is a list of variable bindings, and second
  1358. element is the compiled format expression. See the variable
  1359. `org-agenda-prefix-format'.")
  1360. (defcustom org-agenda-todo-keyword-format "%-1s"
  1361. "Format for the TODO keyword in agenda lines.
  1362. Set this to something like \"%-12s\" if you want all TODO keywords
  1363. to occupy a fixed space in the agenda display."
  1364. :group 'org-agenda-line-format
  1365. :type 'string)
  1366. (defcustom org-agenda-diary-sexp-prefix nil
  1367. "A regexp that matches part of a diary sexp entry
  1368. which should be treated as scheduling/deadline information in
  1369. `org-agenda'.
  1370. For example, you can use this to extract the `diary-remind-message' from
  1371. `diary-remind' entries."
  1372. :group 'org-agenda-line-format
  1373. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1374. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1375. "Text preceding timerange entries in the agenda view.
  1376. This is a list with two strings. The first applies when the range
  1377. is entirely on one day. The second applies if the range spans several days.
  1378. The strings may have two \"%d\" format specifiers which will be filled
  1379. with the sequence number of the days, and the total number of days in the
  1380. range, respectively."
  1381. :group 'org-agenda-line-format
  1382. :type '(list
  1383. (string :tag "Deadline today ")
  1384. (choice :tag "Deadline relative"
  1385. (string :tag "Format string")
  1386. (function))))
  1387. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1388. "Text preceding scheduled items in the agenda view.
  1389. This is a list with two strings. The first applies when the item is
  1390. scheduled on the current day. The second applies when it has been scheduled
  1391. previously, it may contain a %d indicating that this is the nth time that
  1392. this item is scheduled, due to automatic rescheduling of unfinished items
  1393. for the following day. So this number is one larger than the number of days
  1394. that passed since this item was scheduled first."
  1395. :group 'org-agenda-line-format
  1396. :type '(list
  1397. (string :tag "Scheduled today ")
  1398. (string :tag "Scheduled previously")))
  1399. (defcustom org-agenda-inactive-leader "["
  1400. "Text preceding item pulled into the agenda by inactive time stamps.
  1401. These entries are added to the agenda when pressing \"[\"."
  1402. :group 'org-agenda-line-format
  1403. :version "24.1"
  1404. :type '(list
  1405. (string :tag "Scheduled today ")
  1406. (string :tag "Scheduled previously")))
  1407. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1408. "Text preceding deadline items in the agenda view.
  1409. This is a list with two strings. The first applies when the item has its
  1410. deadline on the current day. The second applies when it is in the past or
  1411. in the future, it may contain %d to capture how many days away the deadline
  1412. is (was)."
  1413. :group 'org-agenda-line-format
  1414. :type '(list
  1415. (string :tag "Deadline today ")
  1416. (choice :tag "Deadline relative"
  1417. (string :tag "Format string")
  1418. (function))))
  1419. (defcustom org-agenda-remove-times-when-in-prefix t
  1420. "Non-nil means remove duplicate time specifications in agenda items.
  1421. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1422. time-of-day specification in a headline or diary entry is extracted and
  1423. placed into the prefix. If this option is non-nil, the original specification
  1424. \(a timestamp or -range, or just a plain time(range) specification like
  1425. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1426. cluttered.
  1427. The option can be t or nil. It may also be the symbol `beg', indicating
  1428. that the time should only be removed when it is located at the beginning of
  1429. the headline/diary entry."
  1430. :group 'org-agenda-line-format
  1431. :type '(choice
  1432. (const :tag "Always" t)
  1433. (const :tag "Never" nil)
  1434. (const :tag "When at beginning of entry" beg)))
  1435. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1436. "Non-nil means remove time ranges specifications in agenda
  1437. items that span on several days."
  1438. :group 'org-agenda-line-format
  1439. :version "24.1"
  1440. :type 'boolean)
  1441. (defcustom org-agenda-default-appointment-duration nil
  1442. "Default duration for appointments that only have a starting time.
  1443. When nil, no duration is specified in such cases.
  1444. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1445. :group 'org-agenda-line-format
  1446. :type '(choice
  1447. (integer :tag "Minutes")
  1448. (const :tag "No default duration")))
  1449. (defcustom org-agenda-show-inherited-tags t
  1450. "Non-nil means show inherited tags in each agenda line."
  1451. :group 'org-agenda-line-format
  1452. :type 'boolean)
  1453. (defcustom org-agenda-hide-tags-regexp nil
  1454. "Regular expression used to filter away specific tags in agenda views.
  1455. This means that these tags will be present, but not be shown in the agenda
  1456. line. Secondary filtering will still work on the hidden tags.
  1457. Nil means don't hide any tags."
  1458. :group 'org-agenda-line-format
  1459. :type '(choice
  1460. (const :tag "Hide none" nil)
  1461. (string :tag "Regexp ")))
  1462. (defcustom org-agenda-remove-tags nil
  1463. "Non-nil means remove the tags from the headline copy in the agenda.
  1464. When this is the symbol `prefix', only remove tags when
  1465. `org-agenda-prefix-format' contains a `%T' specifier."
  1466. :group 'org-agenda-line-format
  1467. :type '(choice
  1468. (const :tag "Always" t)
  1469. (const :tag "Never" nil)
  1470. (const :tag "When prefix format contains %T" prefix)))
  1471. (if (fboundp 'defvaralias)
  1472. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1473. 'org-agenda-remove-tags))
  1474. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1475. "Shift tags in agenda items to this column.
  1476. If this number is positive, it specifies the column. If it is negative,
  1477. it means that the tags should be flushright to that column. For example,
  1478. -80 works well for a normal 80 character screen."
  1479. :group 'org-agenda-line-format
  1480. :type 'integer)
  1481. (if (fboundp 'defvaralias)
  1482. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1483. (defcustom org-agenda-fontify-priorities 'cookies
  1484. "Non-nil means highlight low and high priorities in agenda.
  1485. When t, the highest priority entries are bold, lowest priority italic.
  1486. However, settings in `org-priority-faces' will overrule these faces.
  1487. When this variable is the symbol `cookies', only fontify the
  1488. cookies, not the entire task.
  1489. This may also be an association list of priority faces, whose
  1490. keys are the character values of `org-highest-priority',
  1491. `org-default-priority', and `org-lowest-priority' (the default values
  1492. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1493. color as a string, or a list like `(:background \"Red\")'.
  1494. If it is a color, the variable `org-faces-easy-properties'
  1495. determines if it is a foreground or a background color."
  1496. :group 'org-agenda-line-format
  1497. :type '(choice
  1498. (const :tag "Never" nil)
  1499. (const :tag "Defaults" t)
  1500. (const :tag "Cookies only" cookies)
  1501. (repeat :tag "Specify"
  1502. (list (character :tag "Priority" :value ?A)
  1503. (choice :tag "Face "
  1504. (string :tag "Color")
  1505. (sexp :tag "Face"))))))
  1506. (defcustom org-agenda-day-face-function nil
  1507. "Function called to determine what face should be used to display a day.
  1508. The only argument passed to that function is the day. It should
  1509. returns a face, or nil if does not want to specify a face and let
  1510. the normal rules apply."
  1511. :group 'org-agenda-line-format
  1512. :version "24.1"
  1513. :type 'function)
  1514. (defcustom org-agenda-category-icon-alist nil
  1515. "Alist of category icon to be displayed in agenda views.
  1516. Each entry should have the following format:
  1517. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1518. Where CATEGORY-REGEXP is a regexp matching the categories where
  1519. the icon should be displayed.
  1520. FILE-OR-DATA either a file path or a string containing image data.
  1521. The other fields can be omitted safely if not needed:
  1522. TYPE indicates the image type.
  1523. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1524. image data.
  1525. PROPS are additional image attributes to assign to the image,
  1526. like, e.g. `:ascent center'.
  1527. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1528. If you want to set the display properties yourself, just put a
  1529. list as second element:
  1530. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1531. For example, to display a 16px horizontal space for Emacs
  1532. category, you can use:
  1533. (\"Emacs\" '(space . (:width (16))))"
  1534. :group 'org-agenda-line-format
  1535. :version "24.1"
  1536. :type '(alist :key-type (string :tag "Regexp matching category")
  1537. :value-type (choice (list :tag "Icon"
  1538. (string :tag "File or data")
  1539. (symbol :tag "Type")
  1540. (boolean :tag "Data?")
  1541. (repeat :tag "Extra image properties" :inline t symbol))
  1542. (list :tag "Display properties" sexp))))
  1543. (defgroup org-agenda-column-view nil
  1544. "Options concerning column view in the agenda."
  1545. :tag "Org Agenda Column View"
  1546. :group 'org-agenda)
  1547. (defcustom org-agenda-columns-show-summaries t
  1548. "Non-nil means show summaries for columns displayed in the agenda view."
  1549. :group 'org-agenda-column-view
  1550. :type 'boolean)
  1551. (defcustom org-agenda-columns-compute-summary-properties t
  1552. "Non-nil means recompute all summary properties before column view.
  1553. When column view in the agenda is listing properties that have a summary
  1554. operator, it can go to all relevant buffers and recompute the summaries
  1555. there. This can mean overhead for the agenda column view, but is necessary
  1556. to have thing up to date.
  1557. As a special case, a CLOCKSUM property also makes sure that the clock
  1558. computations are current."
  1559. :group 'org-agenda-column-view
  1560. :type 'boolean)
  1561. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1562. "Non-nil means the duration of an appointment will add to day effort.
  1563. The property to which appointment durations will be added is the one given
  1564. in the option `org-effort-property'. If an appointment does not have
  1565. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1566. is not set, an appointment without end time will not contribute to the time
  1567. estimate."
  1568. :group 'org-agenda-column-view
  1569. :type 'boolean)
  1570. (defcustom org-agenda-auto-exclude-function nil
  1571. "A function called with a tag to decide if it is filtered on '/ RET'.
  1572. The sole argument to the function, which is called once for each
  1573. possible tag, is a string giving the name of the tag. The
  1574. function should return either nil if the tag should be included
  1575. as normal, or \"-<TAG>\" to exclude the tag.
  1576. Note that for the purpose of tag filtering, only the lower-case version of
  1577. all tags will be considered, so that this function will only ever see
  1578. the lower-case version of all tags."
  1579. :group 'org-agenda
  1580. :type 'function)
  1581. (defcustom org-agenda-bulk-custom-functions nil
  1582. "Alist of characters and custom functions for bulk actions.
  1583. For example, this value makes those two functions available:
  1584. '((?R set-category)
  1585. (?C bulk-cut))
  1586. With selected entries in an agenda buffer, `B R' will call
  1587. the custom function `set-category' on the selected entries.
  1588. Note that functions in this alist don't need to be quoted."
  1589. :type 'alist
  1590. :version "24.1"
  1591. :group 'org-agenda)
  1592. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1593. "Execute BODY with point at location given by `org-hd-marker' property.
  1594. If STRING is non-nil, the text property will be fetched from position 0
  1595. in that string. If STRING is nil, it will be fetched from the beginning
  1596. of the current line."
  1597. (org-with-gensyms (marker)
  1598. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1599. 'org-hd-marker ,string)))
  1600. (with-current-buffer (marker-buffer ,marker)
  1601. (save-excursion
  1602. (goto-char ,marker)
  1603. ,@body)))))
  1604. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1605. (defun org-add-agenda-custom-command (entry)
  1606. "Replace or add a command in `org-agenda-custom-commands'.
  1607. This is mostly for hacking and trying a new command - once the command
  1608. works you probably want to add it to `org-agenda-custom-commands' for good."
  1609. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1610. (if ass
  1611. (setcdr ass (cdr entry))
  1612. (push entry org-agenda-custom-commands))))
  1613. ;;; Define the org-agenda-mode
  1614. (defvar org-agenda-mode-map (make-sparse-keymap)
  1615. "Keymap for `org-agenda-mode'.")
  1616. (if (fboundp 'defvaralias)
  1617. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1618. (defvar org-agenda-menu) ; defined later in this file.
  1619. (defvar org-agenda-restrict) ; defined later in this file.
  1620. (defvar org-agenda-follow-mode nil)
  1621. (defvar org-agenda-entry-text-mode nil)
  1622. (defvar org-agenda-clockreport-mode nil)
  1623. (defvar org-agenda-show-log nil)
  1624. (defvar org-agenda-redo-command nil)
  1625. (defvar org-agenda-query-string nil)
  1626. (defvar org-agenda-mode-hook nil
  1627. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1628. (defvar org-agenda-type nil)
  1629. (defvar org-agenda-force-single-file nil)
  1630. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1631. ;;; Multiple agenda buffers support
  1632. (defcustom org-agenda-sticky nil
  1633. "Non-nil means agenda q key will bury agenda buffers.
  1634. Agenda commands will then show existing buffer instead of generating new ones.
  1635. When nil, `q' will kill the single agenda buffer."
  1636. :group 'org-agenda
  1637. :type 'boolean
  1638. :set (lambda (var val)
  1639. (if (boundp var)
  1640. (org-toggle-sticky-agenda (if val 1 0))
  1641. (set var val))))
  1642. ;;;###autoload
  1643. (defun org-toggle-sticky-agenda (&optional arg)
  1644. "Toggle `org-agenda-sticky'."
  1645. (interactive "P")
  1646. (let ((new-value (if arg
  1647. (> (prefix-numeric-value arg) 0)
  1648. (not org-agenda-sticky))))
  1649. (if (equal new-value org-agenda-sticky)
  1650. (and (org-called-interactively-p 'interactive)
  1651. (message "Sticky agenda was already %s"
  1652. (if org-agenda-sticky "enabled" "disabled")))
  1653. (setq org-agenda-sticky new-value)
  1654. (org-agenda-kill-all-agenda-buffers)
  1655. (and (org-called-interactively-p 'interactive)
  1656. (message "Sticky agenda was %s"
  1657. (if org-agenda-sticky "enabled" "disabled"))))))
  1658. (defvar org-agenda-buffer nil
  1659. "Agenda buffer currently being generated.")
  1660. (defvar org-agenda-last-prefix-arg nil)
  1661. (defvar org-agenda-this-buffer-name nil)
  1662. (defvar org-agenda-doing-sticky-redo nil)
  1663. (defvar org-agenda-this-buffer-is-sticky nil)
  1664. (defconst org-agenda-local-vars
  1665. '(org-agenda-this-buffer-name
  1666. org-agenda-undo-list
  1667. org-agenda-pending-undo-list
  1668. org-agenda-follow-mode
  1669. org-agenda-entry-text-mode
  1670. org-agenda-clockreport-mode
  1671. org-agenda-show-log
  1672. org-agenda-redo-command
  1673. org-agenda-query-string
  1674. org-agenda-type
  1675. org-agenda-bulk-marked-entries
  1676. org-agenda-undo-has-started-in
  1677. org-agenda-info
  1678. org-agenda-tag-filter-overlays
  1679. org-agenda-cat-filter-overlays
  1680. org-agenda-pre-window-conf
  1681. org-agenda-columns-active
  1682. org-agenda-tag-filter
  1683. org-agenda-category-filter
  1684. org-agenda-markers
  1685. org-agenda-last-search-view-search-was-boolean
  1686. org-agenda-filtered-by-category
  1687. org-agenda-filter-form
  1688. org-agenda-show-window
  1689. org-agenda-cycle-counter
  1690. org-agenda-last-prefix-arg)
  1691. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1692. (defun org-agenda-mode ()
  1693. "Mode for time-sorted view on action items in Org-mode files.
  1694. The following commands are available:
  1695. \\{org-agenda-mode-map}"
  1696. (interactive)
  1697. (cond (org-agenda-doing-sticky-redo
  1698. ;; Refreshing sticky agenda-buffer
  1699. ;;
  1700. ;; Preserve the value of `org-agenda-local-vars' variables,
  1701. ;; while letting `kill-all-local-variables' kill the rest
  1702. (let ((save (buffer-local-variables)))
  1703. (kill-all-local-variables)
  1704. (mapc 'make-local-variable org-agenda-local-vars)
  1705. (dolist (elem save)
  1706. (let ((var (car elem))
  1707. (val (cdr elem)))
  1708. (when (and val
  1709. (member var org-agenda-local-vars))
  1710. (set var val)))))
  1711. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1712. (org-agenda-sticky
  1713. ;; Creating a sticky Agenda buffer for the first time
  1714. (kill-all-local-variables)
  1715. (mapc 'make-local-variable org-agenda-local-vars)
  1716. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1717. (t
  1718. ;; Creating a non-sticky agenda buffer
  1719. (kill-all-local-variables)
  1720. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1721. (setq org-agenda-undo-list nil
  1722. org-agenda-pending-undo-list nil
  1723. org-agenda-bulk-marked-entries nil)
  1724. (setq major-mode 'org-agenda-mode)
  1725. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1726. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1727. (setq mode-name "Org-Agenda")
  1728. (use-local-map org-agenda-mode-map)
  1729. (easy-menu-add org-agenda-menu)
  1730. (if org-startup-truncated (setq truncate-lines t))
  1731. (org-set-local 'line-move-visual nil)
  1732. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1733. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1734. ;; Make sure properties are removed when copying text
  1735. (make-local-variable 'filter-buffer-substring-functions)
  1736. (add-hook 'filter-buffer-substring-functions
  1737. (lambda (fun start end delete)
  1738. (substring-no-properties (funcall fun start end delete))))
  1739. (unless org-agenda-keep-modes
  1740. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1741. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1742. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1743. org-agenda-show-log org-agenda-start-with-log-mode))
  1744. (easy-menu-change
  1745. '("Agenda") "Agenda Files"
  1746. (append
  1747. (list
  1748. (vector
  1749. (if (get 'org-agenda-files 'org-restrict)
  1750. "Restricted to single file"
  1751. "Edit File List")
  1752. '(org-edit-agenda-file-list)
  1753. (not (get 'org-agenda-files 'org-restrict)))
  1754. "--")
  1755. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1756. (org-agenda-set-mode-name)
  1757. (apply
  1758. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1759. (list 'org-agenda-mode-hook)))
  1760. (substitute-key-definition 'undo 'org-agenda-undo
  1761. org-agenda-mode-map global-map)
  1762. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1763. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1764. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1765. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1766. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1767. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1768. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1769. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1770. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1771. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1772. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1773. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1774. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1775. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1776. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1777. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1778. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1779. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1780. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1781. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1782. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1783. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1784. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1785. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1786. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1787. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1788. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1789. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1791. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1792. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1793. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1794. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1795. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1796. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1797. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1798. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1799. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1800. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1801. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1802. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1803. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1804. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1805. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1806. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1807. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1808. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1809. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1810. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1811. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1812. (while l (org-defkey org-agenda-mode-map
  1813. (int-to-string (pop l)) 'digit-argument)))
  1814. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1815. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1816. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1817. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1818. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1819. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1820. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1821. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1822. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1823. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1824. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1825. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1826. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1827. 'org-clock-modify-effort-estimate)
  1828. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1829. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1830. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1831. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1832. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1833. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1834. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1835. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1836. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1837. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1838. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1839. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1840. (substitute-key-definition 'next-line 'org-agenda-next-line
  1841. org-agenda-mode-map global-map)
  1842. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1843. org-agenda-mode-map global-map)
  1844. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1845. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1846. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1847. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1848. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
  1849. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1850. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1851. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1852. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1853. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1854. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1855. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1856. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1857. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1858. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1859. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1860. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1861. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1862. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1863. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1864. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1865. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1866. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1867. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1868. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1869. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1870. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1871. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1872. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1873. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1874. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1875. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1876. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1877. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1878. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1879. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1880. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1881. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1882. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1883. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1884. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1885. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1886. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1887. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1888. (when org-agenda-mouse-1-follows-link
  1889. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1890. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1891. '("Agenda"
  1892. ("Agenda Files")
  1893. "--"
  1894. ("Agenda Dates"
  1895. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1896. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1897. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1898. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1899. "--"
  1900. ("View"
  1901. ["Day View" org-agenda-day-view
  1902. :active (org-agenda-check-type nil 'agenda)
  1903. :style radio :selected (eq org-agenda-current-span 'day)
  1904. :keys "v d (or just d)"]
  1905. ["Week View" org-agenda-week-view
  1906. :active (org-agenda-check-type nil 'agenda)
  1907. :style radio :selected (eq org-agenda-current-span 'week)
  1908. :keys "v w (or just w)"]
  1909. ["Month View" org-agenda-month-view
  1910. :active (org-agenda-check-type nil 'agenda)
  1911. :style radio :selected (eq org-agenda-current-span 'month)
  1912. :keys "v m"]
  1913. ["Year View" org-agenda-year-view
  1914. :active (org-agenda-check-type nil 'agenda)
  1915. :style radio :selected (eq org-agenda-current-span 'year)
  1916. :keys "v y"]
  1917. "--"
  1918. ["Include Diary" org-agenda-toggle-diary
  1919. :style toggle :selected org-agenda-include-diary
  1920. :active (org-agenda-check-type nil 'agenda)]
  1921. ["Include Deadlines" org-agenda-toggle-deadlines
  1922. :style toggle :selected org-agenda-include-deadlines
  1923. :active (org-agenda-check-type nil 'agenda)]
  1924. ["Use Time Grid" org-agenda-toggle-time-grid
  1925. :style toggle :selected org-agenda-use-time-grid
  1926. :active (org-agenda-check-type nil 'agenda)]
  1927. "--"
  1928. ["Show clock report" org-agenda-clockreport-mode
  1929. :style toggle :selected org-agenda-clockreport-mode
  1930. :active (org-agenda-check-type nil 'agenda)]
  1931. ["Show some entry text" org-agenda-entry-text-mode
  1932. :style toggle :selected org-agenda-entry-text-mode
  1933. :active t]
  1934. "--"
  1935. ["Show Logbook entries" org-agenda-log-mode
  1936. :style toggle :selected org-agenda-show-log
  1937. :active (org-agenda-check-type nil 'agenda 'timeline)
  1938. :keys "v l (or just l)"]
  1939. ["Include archived trees" org-agenda-archives-mode
  1940. :style toggle :selected org-agenda-archives-mode :active t
  1941. :keys "v a"]
  1942. ["Include archive files" (org-agenda-archives-mode t)
  1943. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1944. :keys "v A"]
  1945. "--"
  1946. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1947. ["Write view to file" org-agenda-write t]
  1948. ["Rebuild buffer" org-agenda-redo t]
  1949. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1950. "--"
  1951. ["Show original entry" org-agenda-show t]
  1952. ["Go To (other window)" org-agenda-goto t]
  1953. ["Go To (this window)" org-agenda-switch-to t]
  1954. ["Follow Mode" org-agenda-follow-mode
  1955. :style toggle :selected org-agenda-follow-mode :active t]
  1956. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1957. "--"
  1958. ("TODO"
  1959. ["Cycle TODO" org-agenda-todo t]
  1960. ["Next TODO set" org-agenda-todo-nextset t]
  1961. ["Previous TODO set" org-agenda-todo-previousset t]
  1962. ["Add note" org-agenda-add-note t])
  1963. ("Archive/Refile/Delete"
  1964. ["Archive default" org-agenda-archive-default t]
  1965. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1966. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1967. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1968. ["Archive subtree" org-agenda-archive t]
  1969. "--"
  1970. ["Refile" org-agenda-refile t]
  1971. "--"
  1972. ["Delete subtree" org-agenda-kill t])
  1973. ("Bulk action"
  1974. ["Mark entry" org-agenda-bulk-mark t]
  1975. ["Mark all" org-agenda-bulk-mark-all t]
  1976. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1977. ["Unmark entry" org-agenda-bulk-unmark t]
  1978. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
  1979. ["Act on all marked" org-agenda-bulk-action t]
  1980. "--"
  1981. ("Tags and Properties"
  1982. ["Show all Tags" org-agenda-show-tags t]
  1983. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1984. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1985. "--"
  1986. ["Column View" org-columns t])
  1987. ("Deadline/Schedule"
  1988. ["Schedule" org-agenda-schedule t]
  1989. ["Set Deadline" org-agenda-deadline t]
  1990. "--"
  1991. ["Mark item" org-agenda-action :active t :keys "k m"]
  1992. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1993. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1994. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1995. "--"
  1996. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1997. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1998. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1999. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2000. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2001. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2002. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2003. ("Clock and Effort"
  2004. ["Clock in" org-agenda-clock-in t]
  2005. ["Clock out" org-agenda-clock-out t]
  2006. ["Clock cancel" org-agenda-clock-cancel t]
  2007. ["Goto running clock" org-clock-goto t]
  2008. "--"
  2009. ["Set Effort" org-agenda-set-effort t]
  2010. ["Change clocked effort" org-clock-modify-effort-estimate
  2011. (org-clock-is-active)])
  2012. ("Priority"
  2013. ["Set Priority" org-agenda-priority t]
  2014. ["Increase Priority" org-agenda-priority-up t]
  2015. ["Decrease Priority" org-agenda-priority-down t]
  2016. ["Show Priority" org-agenda-show-priority t])
  2017. ("Calendar/Diary"
  2018. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2019. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2020. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2021. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2022. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2023. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2024. "--"
  2025. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2026. "--"
  2027. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2028. "--"
  2029. ("MobileOrg"
  2030. ["Push Files and Views" org-mobile-push t]
  2031. ["Get Captured and Flagged" org-mobile-pull t]
  2032. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2033. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2034. "--"
  2035. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2036. "--"
  2037. ["Quit" org-agenda-quit t]
  2038. ["Exit and Release Buffers" org-agenda-exit t]
  2039. ))
  2040. ;;; Agenda undo
  2041. (defvar org-agenda-allow-remote-undo t
  2042. "Non-nil means allow remote undo from the agenda buffer.")
  2043. (defvar org-agenda-undo-list nil
  2044. "List of undoable operations in the agenda since last refresh.")
  2045. (defvar org-agenda-undo-has-started-in nil
  2046. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2047. (defvar org-agenda-pending-undo-list nil
  2048. "In a series of undo commands, this is the list of remaining undo items.")
  2049. (defun org-agenda-undo ()
  2050. "Undo a remote editing step in the agenda.
  2051. This undoes changes both in the agenda buffer and in the remote buffer
  2052. that have been changed along."
  2053. (interactive)
  2054. (or org-agenda-allow-remote-undo
  2055. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2056. (if (not (eq this-command last-command))
  2057. (setq org-agenda-undo-has-started-in nil
  2058. org-agenda-pending-undo-list org-agenda-undo-list))
  2059. (if (not org-agenda-pending-undo-list)
  2060. (error "No further undo information"))
  2061. (let* ((entry (pop org-agenda-pending-undo-list))
  2062. buf line cmd rembuf)
  2063. (setq cmd (pop entry) line (pop entry))
  2064. (setq rembuf (nth 2 entry))
  2065. (org-with-remote-undo rembuf
  2066. (while (bufferp (setq buf (pop entry)))
  2067. (if (pop entry)
  2068. (with-current-buffer buf
  2069. (let ((last-undo-buffer buf)
  2070. (inhibit-read-only t))
  2071. (unless (memq buf org-agenda-undo-has-started-in)
  2072. (push buf org-agenda-undo-has-started-in)
  2073. (make-local-variable 'pending-undo-list)
  2074. (undo-start))
  2075. (while (and pending-undo-list
  2076. (listp pending-undo-list)
  2077. (not (car pending-undo-list)))
  2078. (pop pending-undo-list))
  2079. (undo-more 1))))))
  2080. (org-goto-line line)
  2081. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2082. (defun org-verify-change-for-undo (l1 l2)
  2083. "Verify that a real change occurred between the undo lists L1 and L2."
  2084. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2085. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2086. (not (eq l1 l2)))
  2087. ;;; Agenda dispatch
  2088. (defvar org-agenda-restrict nil)
  2089. (defvar org-agenda-restrict-begin (make-marker))
  2090. (defvar org-agenda-restrict-end (make-marker))
  2091. (defvar org-agenda-last-dispatch-buffer nil)
  2092. (defvar org-agenda-overriding-restriction nil)
  2093. (defcustom org-agenda-custom-commands-contexts nil
  2094. "Alist of custom agenda keys and contextual rules.
  2095. For example, if you have a custom agenda command \"p\" and you
  2096. want this command to be accessible only from plain text files,
  2097. use this:
  2098. '((\"p\" (in-file . \"\\.txt\")))
  2099. Here are the available contexts definitions:
  2100. in-file: command displayed only in matching files
  2101. in-mode: command displayed only in matching modes
  2102. not-in-file: command not displayed in matching files
  2103. not-in-mode: command not displayed in matching modes
  2104. [function]: a custom function taking no argument
  2105. If you define several checks, the agenda command will be
  2106. accessible if there is at least one valid check.
  2107. You can also bind a key to another agenda custom command
  2108. depending on contextual rules.
  2109. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2110. Here it means: in .txt files, use \"p\" as the key for the
  2111. agenda command otherwise associated with \"q\". (The command
  2112. originally associated with \"q\" is not displayed to avoid
  2113. duplicates.)"
  2114. ;; :version "24.3"
  2115. :group 'org-agenda-custom-commands
  2116. :type '(repeat (list :tag "Rule"
  2117. (string :tag " Agenda key")
  2118. (string :tag "Replace by command")
  2119. (repeat :tag "Available when"
  2120. (choice
  2121. (cons :tag "Condition"
  2122. (choice
  2123. (const :tag "In file" in-file)
  2124. (const :tag "Not in file" not-in-file)
  2125. (const :tag "In mode" in-mode)
  2126. (const :tag "Not in mode" not-in-mode))
  2127. (regexp))
  2128. (function :tag "Custom function"))))))
  2129. (defvar org-keys)
  2130. (defvar org-match)
  2131. ;;;###autoload
  2132. (defun org-agenda (&optional arg org-keys restriction)
  2133. "Dispatch agenda commands to collect entries to the agenda buffer.
  2134. Prompts for a command to execute. Any prefix arg will be passed
  2135. on to the selected command. The default selections are:
  2136. a Call `org-agenda-list' to display the agenda for current day or week.
  2137. t Call `org-todo-list' to display the global todo list.
  2138. T Call `org-todo-list' to display the global todo list, select only
  2139. entries with a specific TODO keyword (the user gets a prompt).
  2140. m Call `org-tags-view' to display headlines with tags matching
  2141. a condition (the user is prompted for the condition).
  2142. M Like `m', but select only TODO entries, no ordinary headlines.
  2143. L Create a timeline for the current buffer.
  2144. e Export views to associated files.
  2145. s Search entries for keywords.
  2146. S Search entries for keywords, only with TODO keywords.
  2147. / Multi occur across all agenda files and also files listed
  2148. in `org-agenda-text-search-extra-files'.
  2149. < Restrict agenda commands to buffer, subtree, or region.
  2150. Press several times to get the desired effect.
  2151. > Remove a previous restriction.
  2152. # List \"stuck\" projects.
  2153. ! Configure what \"stuck\" means.
  2154. C Configure custom agenda commands.
  2155. More commands can be added by configuring the variable
  2156. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2157. searches can be pre-defined in this way.
  2158. If the current buffer is in Org-mode and visiting a file, you can also
  2159. first press `<' once to indicate that the agenda should be temporarily
  2160. \(until the next use of \\[org-agenda]) restricted to the current file.
  2161. Pressing `<' twice means to restrict to the current subtree or region
  2162. \(if active)."
  2163. (interactive "P")
  2164. (catch 'exit
  2165. (let* ((prefix-descriptions nil)
  2166. (org-agenda-buffer-name org-agenda-buffer-name)
  2167. (org-agenda-window-setup (if (equal (buffer-name)
  2168. org-agenda-buffer-name)
  2169. 'current-window
  2170. org-agenda-window-setup))
  2171. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2172. (org-agenda-custom-commands
  2173. ;; normalize different versions
  2174. (delq nil
  2175. (mapcar
  2176. (lambda (x)
  2177. (cond ((stringp (cdr x))
  2178. (push x prefix-descriptions)
  2179. nil)
  2180. ((stringp (nth 1 x)) x)
  2181. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2182. (t (cons (car x) (cons "" (cdr x))))))
  2183. org-agenda-custom-commands)))
  2184. (org-agenda-custom-commands
  2185. (org-contextualize-keys
  2186. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2187. (buf (current-buffer))
  2188. (bfn (buffer-file-name (buffer-base-buffer)))
  2189. entry key type org-match lprops ans)
  2190. ;; Turn off restriction unless there is an overriding one,
  2191. (unless org-agenda-overriding-restriction
  2192. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2193. ;; There is a request to keep the file list in place
  2194. (put 'org-agenda-files 'org-restrict nil))
  2195. (setq org-agenda-restrict nil)
  2196. (move-marker org-agenda-restrict-begin nil)
  2197. (move-marker org-agenda-restrict-end nil))
  2198. ;; Delete old local properties
  2199. (put 'org-agenda-redo-command 'org-lprops nil)
  2200. ;; Delete previously set last-arguments
  2201. (put 'org-agenda-redo-command 'last-args nil)
  2202. ;; Remember where this call originated
  2203. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2204. (unless org-keys
  2205. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2206. org-keys (car ans)
  2207. restriction (cdr ans)))
  2208. ;; If we have sticky agenda buffers, set a name for the buffer,
  2209. ;; depending on the invoking keys. The user may still set this
  2210. ;; as a command option, which will overwrite what we do here.
  2211. (if org-agenda-sticky
  2212. (setq org-agenda-buffer-name
  2213. (format "*Org Agenda(%s)*" org-keys)))
  2214. ;; Establish the restriction, if any
  2215. (when (and (not org-agenda-overriding-restriction) restriction)
  2216. (put 'org-agenda-files 'org-restrict (list bfn))
  2217. (cond
  2218. ((eq restriction 'region)
  2219. (setq org-agenda-restrict t)
  2220. (move-marker org-agenda-restrict-begin (region-beginning))
  2221. (move-marker org-agenda-restrict-end (region-end)))
  2222. ((eq restriction 'subtree)
  2223. (save-excursion
  2224. (setq org-agenda-restrict t)
  2225. (org-back-to-heading t)
  2226. (move-marker org-agenda-restrict-begin (point))
  2227. (move-marker org-agenda-restrict-end
  2228. (progn (org-end-of-subtree t)))))))
  2229. ;; For example the todo list should not need it (but does...)
  2230. (cond
  2231. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2232. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2233. (progn
  2234. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2235. lprops (nth 4 entry))
  2236. (if org-agenda-sticky
  2237. (setq org-agenda-buffer-name
  2238. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2239. (format "*Org Agenda(%s)*" org-keys))))
  2240. (put 'org-agenda-redo-command 'org-lprops lprops)
  2241. (cond
  2242. ((eq type 'agenda)
  2243. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2244. ((eq type 'alltodo)
  2245. (org-let lprops '(org-todo-list current-prefix-arg)))
  2246. ((eq type 'search)
  2247. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2248. ((eq type 'stuck)
  2249. (org-let lprops '(org-agenda-list-stuck-projects
  2250. current-prefix-arg)))
  2251. ((eq type 'tags)
  2252. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2253. ((eq type 'tags-todo)
  2254. (org-let lprops '(org-tags-view '(4) org-match)))
  2255. ((eq type 'todo)
  2256. (org-let lprops '(org-todo-list org-match)))
  2257. ((eq type 'tags-tree)
  2258. (org-check-for-org-mode)
  2259. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2260. ((eq type 'todo-tree)
  2261. (org-check-for-org-mode)
  2262. (org-let lprops
  2263. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2264. (regexp-quote org-match) "\\>"))))
  2265. ((eq type 'occur-tree)
  2266. (org-check-for-org-mode)
  2267. (org-let lprops '(org-occur org-match)))
  2268. ((functionp type)
  2269. (org-let lprops '(funcall type org-match)))
  2270. ((fboundp type)
  2271. (org-let lprops '(funcall type org-match)))
  2272. (t (error "Invalid custom agenda command type %s" type))))
  2273. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2274. ((equal org-keys "C")
  2275. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2276. (customize-variable 'org-agenda-custom-commands))
  2277. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2278. ((equal org-keys "s") (call-interactively 'org-search-view))
  2279. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2280. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2281. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2282. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2283. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2284. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2285. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2286. (org-add-hook
  2287. 'post-command-hook
  2288. (lambda ()
  2289. (unless (current-message)
  2290. (let* ((m (org-agenda-get-any-marker))
  2291. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2292. (when note
  2293. (message (concat
  2294. "FLAGGING-NOTE ([?] for more info): "
  2295. (org-add-props
  2296. (replace-regexp-in-string
  2297. "\\\\n" "//"
  2298. (copy-sequence note))
  2299. nil 'face 'org-warning)))))))
  2300. t t))
  2301. ((equal org-keys "L")
  2302. (unless (derived-mode-p 'org-mode)
  2303. (error "This is not an Org-mode file"))
  2304. (unless restriction
  2305. (put 'org-agenda-files 'org-restrict (list bfn))
  2306. (org-call-with-arg 'org-timeline arg)))
  2307. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2308. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2309. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2310. (t (error "Invalid agenda key"))))))
  2311. (defun org-agenda-append-agenda ()
  2312. "Append another agenda view to the current one.
  2313. This function allows interactive building of block agendas.
  2314. Agenda views are separated by `org-agenda-block-separator'."
  2315. (interactive)
  2316. (unless (derived-mode-p 'org-agenda-mode)
  2317. (error "Can only append from within agenda buffer"))
  2318. (let ((org-agenda-multi t))
  2319. (org-agenda)
  2320. (widen)
  2321. (org-agenda-finalize)
  2322. (org-agenda-fit-window-to-buffer)))
  2323. (defun org-agenda-normalize-custom-commands (cmds)
  2324. (delq nil
  2325. (mapcar
  2326. (lambda (x)
  2327. (cond ((stringp (cdr x)) nil)
  2328. ((stringp (nth 1 x)) x)
  2329. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2330. (t (cons (car x) (cons "" (cdr x))))))
  2331. cmds)))
  2332. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2333. "The user interface for selecting an agenda command."
  2334. (catch 'exit
  2335. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2336. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2337. (region-p (org-region-active-p))
  2338. (custom org-agenda-custom-commands)
  2339. (selstring "")
  2340. restriction second-time
  2341. c entry key type match prefixes rmheader header-end custom1 desc
  2342. line lines left right n n1)
  2343. (save-window-excursion
  2344. (delete-other-windows)
  2345. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2346. (erase-buffer)
  2347. (insert (eval-when-compile
  2348. (let ((header
  2349. "Press key for an agenda command: < Buffer, subtree/region restriction
  2350. -------------------------------- > Remove restriction
  2351. a Agenda for current week or day e Export agenda views
  2352. t List of all TODO entries T Entries with special TODO kwd
  2353. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2354. s Search for keywords S Like s, but only TODO entries
  2355. L Timeline for current buffer # List stuck projects (!=configure)
  2356. / Multi-occur C Configure custom agenda commands
  2357. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2358. ")
  2359. (start 0))
  2360. (while (string-match
  2361. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2362. header start)
  2363. (setq start (match-end 0))
  2364. (add-text-properties (match-beginning 2) (match-end 2)
  2365. '(face bold) header))
  2366. header)))
  2367. (setq header-end (move-marker (make-marker) (point)))
  2368. (while t
  2369. (setq custom1 custom)
  2370. (when (eq rmheader t)
  2371. (org-goto-line 1)
  2372. (re-search-forward ":" nil t)
  2373. (delete-region (match-end 0) (point-at-eol))
  2374. (forward-char 1)
  2375. (looking-at "-+")
  2376. (delete-region (match-end 0) (point-at-eol))
  2377. (move-marker header-end (match-end 0)))
  2378. (goto-char header-end)
  2379. (delete-region (point) (point-max))
  2380. ;; Produce all the lines that describe custom commands and prefixes
  2381. (setq lines nil)
  2382. (while (setq entry (pop custom1))
  2383. (setq key (car entry) desc (nth 1 entry)
  2384. type (nth 2 entry)
  2385. match (nth 3 entry))
  2386. (if (> (length key) 1)
  2387. (add-to-list 'prefixes (string-to-char key))
  2388. (setq line
  2389. (format
  2390. "%-4s%-14s"
  2391. (org-add-props (copy-sequence key)
  2392. '(face bold))
  2393. (cond
  2394. ((string-match "\\S-" desc) desc)
  2395. ((eq type 'agenda) "Agenda for current week or day")
  2396. ((eq type 'alltodo) "List of all TODO entries")
  2397. ((eq type 'search) "Word search")
  2398. ((eq type 'stuck) "List of stuck projects")
  2399. ((eq type 'todo) "TODO keyword")
  2400. ((eq type 'tags) "Tags query")
  2401. ((eq type 'tags-todo) "Tags (TODO)")
  2402. ((eq type 'tags-tree) "Tags tree")
  2403. ((eq type 'todo-tree) "TODO kwd tree")
  2404. ((eq type 'occur-tree) "Occur tree")
  2405. ((functionp type) (if (symbolp type)
  2406. (symbol-name type)
  2407. "Lambda expression"))
  2408. (t "???"))))
  2409. (if org-agenda-menu-show-matcher
  2410. (setq line
  2411. (concat line ": "
  2412. (cond
  2413. ((stringp match)
  2414. (setq match (copy-sequence match))
  2415. (org-add-props match nil 'face 'org-warning))
  2416. (match
  2417. (format "set of %d commands" (length match)))
  2418. (t ""))))
  2419. (if (org-string-nw-p match)
  2420. (add-text-properties
  2421. 0 (length line) (list 'help-echo
  2422. (concat "Matcher: "match)) line)))
  2423. (push line lines)))
  2424. (setq lines (nreverse lines))
  2425. (when prefixes
  2426. (mapc (lambda (x)
  2427. (push
  2428. (format "%s %s"
  2429. (org-add-props (char-to-string x)
  2430. nil 'face 'bold)
  2431. (or (cdr (assoc (concat selstring
  2432. (char-to-string x))
  2433. prefix-descriptions))
  2434. "Prefix key"))
  2435. lines))
  2436. prefixes))
  2437. ;; Check if we should display in two columns
  2438. (if org-agenda-menu-two-columns
  2439. (progn
  2440. (setq n (length lines)
  2441. n1 (+ (/ n 2) (mod n 2))
  2442. right (nthcdr n1 lines)
  2443. left (copy-sequence lines))
  2444. (setcdr (nthcdr (1- n1) left) nil))
  2445. (setq left lines right nil))
  2446. (while left
  2447. (insert "\n" (pop left))
  2448. (when right
  2449. (if (< (current-column) 40)
  2450. (move-to-column 40 t)
  2451. (insert " "))
  2452. (insert (pop right))))
  2453. ;; Make the window the right size
  2454. (goto-char (point-min))
  2455. (if second-time
  2456. (if (not (pos-visible-in-window-p (point-max)))
  2457. (org-fit-window-to-buffer))
  2458. (setq second-time t)
  2459. (org-fit-window-to-buffer))
  2460. ;; Ask for selection
  2461. (message "Press key for agenda command%s:"
  2462. (if (or restrict-ok org-agenda-overriding-restriction)
  2463. (if org-agenda-overriding-restriction
  2464. " (restriction lock active)"
  2465. (if restriction
  2466. (format " (restricted to %s)" restriction)
  2467. " (unrestricted)"))
  2468. ""))
  2469. (setq c (read-char-exclusive))
  2470. (message "")
  2471. (cond
  2472. ((assoc (char-to-string c) custom)
  2473. (setq selstring (concat selstring (char-to-string c)))
  2474. (throw 'exit (cons selstring restriction)))
  2475. ((memq c prefixes)
  2476. (setq selstring (concat selstring (char-to-string c))
  2477. prefixes nil
  2478. rmheader (or rmheader t)
  2479. custom (delq nil (mapcar
  2480. (lambda (x)
  2481. (if (or (= (length (car x)) 1)
  2482. (/= (string-to-char (car x)) c))
  2483. nil
  2484. (cons (substring (car x) 1) (cdr x))))
  2485. custom))))
  2486. ((eq c ?*)
  2487. (call-interactively 'org-toggle-sticky-agenda)
  2488. (sit-for 2))
  2489. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2490. (message "Restriction is only possible in Org-mode buffers")
  2491. (ding) (sit-for 1))
  2492. ((eq c ?1)
  2493. (org-agenda-remove-restriction-lock 'noupdate)
  2494. (setq restriction 'buffer))
  2495. ((eq c ?0)
  2496. (org-agenda-remove-restriction-lock 'noupdate)
  2497. (setq restriction (if region-p 'region 'subtree)))
  2498. ((eq c ?<)
  2499. (org-agenda-remove-restriction-lock 'noupdate)
  2500. (setq restriction
  2501. (cond
  2502. ((eq restriction 'buffer)
  2503. (if region-p 'region 'subtree))
  2504. ((memq restriction '(subtree region))
  2505. nil)
  2506. (t 'buffer))))
  2507. ((eq c ?>)
  2508. (org-agenda-remove-restriction-lock 'noupdate)
  2509. (setq restriction nil))
  2510. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2511. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2512. ((and (> (length selstring) 0) (eq c ?\d))
  2513. (delete-window)
  2514. (org-agenda-get-restriction-and-command prefix-descriptions))
  2515. ((equal c ?q) (error "Abort"))
  2516. (t (error "Invalid key %c" c))))))))
  2517. (defun org-agenda-fit-window-to-buffer ()
  2518. "Fit the window to the buffer size."
  2519. (and (memq org-agenda-window-setup '(reorganize-frame))
  2520. (fboundp 'fit-window-to-buffer)
  2521. (org-fit-window-to-buffer
  2522. nil
  2523. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2524. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2525. (defvar org-cmd nil)
  2526. (defvar org-agenda-overriding-cmd nil)
  2527. (defvar org-agenda-overriding-arguments nil)
  2528. (defvar org-agenda-overriding-cmd-arguments nil)
  2529. (defun org-agenda-run-series (name series)
  2530. (org-let (nth 1 series) '(org-agenda-prepare name))
  2531. ;; We need to reset agenda markers here, because when constructing a
  2532. ;; block agenda, the individual blocks do not do that.
  2533. (org-agenda-reset-markers)
  2534. (let* ((org-agenda-multi t)
  2535. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2536. (cmds (car series))
  2537. (gprops (nth 1 series))
  2538. match ;; The byte compiler incorrectly complains about this. Keep it!
  2539. org-cmd type lprops)
  2540. (while (setq org-cmd (pop cmds))
  2541. (setq type (car org-cmd)
  2542. match (eval (nth 1 org-cmd))
  2543. lprops (nth 2 org-cmd))
  2544. (let ((org-agenda-overriding-arguments
  2545. (if (eq org-agenda-overriding-cmd org-cmd)
  2546. (or org-agenda-overriding-arguments
  2547. org-agenda-overriding-cmd-arguments))))
  2548. (cond
  2549. ((eq type 'agenda)
  2550. (org-let2 gprops lprops
  2551. '(call-interactively 'org-agenda-list)))
  2552. ((eq type 'alltodo)
  2553. (org-let2 gprops lprops
  2554. '(call-interactively 'org-todo-list)))
  2555. ((eq type 'search)
  2556. (org-let2 gprops lprops
  2557. '(org-search-view current-prefix-arg match nil)))
  2558. ((eq type 'stuck)
  2559. (org-let2 gprops lprops
  2560. '(call-interactively 'org-agenda-list-stuck-projects)))
  2561. ((eq type 'tags)
  2562. (org-let2 gprops lprops
  2563. '(org-tags-view current-prefix-arg match)))
  2564. ((eq type 'tags-todo)
  2565. (org-let2 gprops lprops
  2566. '(org-tags-view '(4) match)))
  2567. ((eq type 'todo)
  2568. (org-let2 gprops lprops
  2569. '(org-todo-list match)))
  2570. ((fboundp type)
  2571. (org-let2 gprops lprops
  2572. '(funcall type match)))
  2573. (t (error "Invalid type in command series")))))
  2574. (widen)
  2575. (let ((inhibit-read-only t))
  2576. (add-text-properties (point-min) (point-max)
  2577. `(org-serie t org-serie-redo-cmd ,redo)))
  2578. (setq org-agenda-redo-command redo)
  2579. (goto-char (point-min)))
  2580. (org-agenda-fit-window-to-buffer)
  2581. (org-let (nth 1 series) '(org-agenda-finalize)))
  2582. ;;;###autoload
  2583. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2584. "Run an agenda command in batch mode and send the result to STDOUT.
  2585. If CMD-KEY is a string of length 1, it is used as a key in
  2586. `org-agenda-custom-commands' and triggers this command. If it is a
  2587. longer string it is used as a tags/todo match string.
  2588. Parameters are alternating variable names and values that will be bound
  2589. before running the agenda command."
  2590. (org-eval-in-environment (org-make-parameter-alist parameters)
  2591. (if (> (length cmd-key) 2)
  2592. (org-tags-view nil cmd-key)
  2593. (org-agenda nil cmd-key)))
  2594. (set-buffer org-agenda-buffer-name)
  2595. (princ (buffer-string)))
  2596. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2597. (defvar org-agenda-info nil)
  2598. ;;;###autoload
  2599. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2600. "Run an agenda command in batch mode and send the result to STDOUT.
  2601. If CMD-KEY is a string of length 1, it is used as a key in
  2602. `org-agenda-custom-commands' and triggers this command. If it is a
  2603. longer string it is used as a tags/todo match string.
  2604. Parameters are alternating variable names and values that will be bound
  2605. before running the agenda command.
  2606. The output gives a line for each selected agenda item. Each
  2607. item is a list of comma-separated values, like this:
  2608. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2609. category The category of the item
  2610. head The headline, without TODO kwd, TAGS and PRIORITY
  2611. type The type of the agenda entry, can be
  2612. todo selected in TODO match
  2613. tagsmatch selected in tags match
  2614. diary imported from diary
  2615. deadline a deadline on given date
  2616. scheduled scheduled on given date
  2617. timestamp entry has timestamp on given date
  2618. closed entry was closed on given date
  2619. upcoming-deadline warning about deadline
  2620. past-scheduled forwarded scheduled item
  2621. block entry has date block including g. date
  2622. todo The todo keyword, if any
  2623. tags All tags including inherited ones, separated by colons
  2624. date The relevant date, like 2007-2-14
  2625. time The time, like 15:00-16:50
  2626. extra Sting with extra planning info
  2627. priority-l The priority letter if any was given
  2628. priority-n The computed numerical priority
  2629. agenda-day The day in the agenda where this is listed"
  2630. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2631. (org-make-parameter-alist parameters))
  2632. (if (> (length cmd-key) 2)
  2633. (org-tags-view nil cmd-key)
  2634. (org-agenda nil cmd-key)))
  2635. (set-buffer org-agenda-buffer-name)
  2636. (let* ((lines (org-split-string (buffer-string) "\n"))
  2637. line)
  2638. (while (setq line (pop lines))
  2639. (catch 'next
  2640. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2641. (setq org-agenda-info
  2642. (org-fix-agenda-info (text-properties-at 0 line)))
  2643. (princ
  2644. (mapconcat 'org-agenda-export-csv-mapper
  2645. '(org-category txt type todo tags date time extra
  2646. priority-letter priority agenda-day)
  2647. ","))
  2648. (princ "\n")))))
  2649. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2650. (defun org-fix-agenda-info (props)
  2651. "Make sure all properties on an agenda item have a canonical form.
  2652. This ensures the export commands can easily use it."
  2653. (let (tmp re)
  2654. (when (setq tmp (plist-get props 'tags))
  2655. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2656. (when (setq tmp (plist-get props 'date))
  2657. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2658. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2659. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2660. (setq tmp (calendar-date-string tmp)))
  2661. (setq props (plist-put props 'date tmp)))
  2662. (when (setq tmp (plist-get props 'day))
  2663. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2664. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2665. (setq tmp (calendar-date-string tmp)))
  2666. (setq props (plist-put props 'day tmp))
  2667. (setq props (plist-put props 'agenda-day tmp)))
  2668. (when (setq tmp (plist-get props 'txt))
  2669. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2670. (plist-put props 'priority-letter (match-string 1 tmp))
  2671. (setq tmp (replace-match "" t t tmp)))
  2672. (when (and (setq re (plist-get props 'org-todo-regexp))
  2673. (setq re (concat "\\`\\.*" re " ?"))
  2674. (string-match re tmp))
  2675. (plist-put props 'todo (match-string 1 tmp))
  2676. (setq tmp (replace-match "" t t tmp)))
  2677. (plist-put props 'txt tmp)))
  2678. props)
  2679. (defun org-agenda-export-csv-mapper (prop)
  2680. (let ((res (plist-get org-agenda-info prop)))
  2681. (setq res
  2682. (cond
  2683. ((not res) "")
  2684. ((stringp res) res)
  2685. (t (prin1-to-string res))))
  2686. (while (string-match "," res)
  2687. (setq res (replace-match ";" t t res)))
  2688. (org-trim res)))
  2689. ;;;###autoload
  2690. (defun org-store-agenda-views (&rest parameters)
  2691. (interactive)
  2692. (eval (list 'org-batch-store-agenda-views)))
  2693. ;;;###autoload
  2694. (defmacro org-batch-store-agenda-views (&rest parameters)
  2695. "Run all custom agenda commands that have a file argument."
  2696. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2697. (pop-up-frames nil)
  2698. (dir default-directory)
  2699. (pars (org-make-parameter-alist parameters))
  2700. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2701. (save-window-excursion
  2702. (while cmds
  2703. (setq cmd (pop cmds)
  2704. thiscmdkey (car cmd)
  2705. thiscmdcmd (cdr cmd)
  2706. match (nth 2 thiscmdcmd)
  2707. bufname (if org-agenda-sticky
  2708. (or (and (stringp match)
  2709. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2710. (format "*Org Agenda(%s)*" thiscmdkey))
  2711. org-agenda-buffer-name)
  2712. cmd-or-set (nth 2 cmd)
  2713. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2714. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2715. (if (stringp files) (setq files (list files)))
  2716. (when files
  2717. (org-eval-in-environment (append org-agenda-exporter-settings
  2718. opts pars)
  2719. (org-agenda nil thiscmdkey))
  2720. (set-buffer bufname)
  2721. (while files
  2722. (org-eval-in-environment (append org-agenda-exporter-settings
  2723. opts pars)
  2724. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2725. (and (get-buffer bufname)
  2726. (kill-buffer bufname)))))))
  2727. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2728. (defvar org-agenda-current-span nil
  2729. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2730. (defun org-agenda-mark-header-line (pos)
  2731. "Mark the line at POS as an agenda structure header."
  2732. (save-excursion
  2733. (goto-char pos)
  2734. (put-text-property (point-at-bol) (point-at-eol)
  2735. 'org-agenda-structural-header t)
  2736. (when org-agenda-title-append
  2737. (put-text-property (point-at-bol) (point-at-eol)
  2738. 'org-agenda-title-append org-agenda-title-append))))
  2739. (defvar org-mobile-creating-agendas)
  2740. (defvar org-agenda-write-buffer-name "Agenda View")
  2741. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2742. "Write the current buffer (an agenda view) as a file.
  2743. Depending on the extension of the file name, plain text (.txt),
  2744. HTML (.html or .htm) or Postscript (.ps) is produced.
  2745. If the extension is .ics, run icalendar export over all files used
  2746. to construct the agenda and limit the export to entries listed in the
  2747. agenda now.
  2748. With prefix argument OPEN, open the new file immediately.
  2749. If NOSETTINGS is given, do not scope the settings of
  2750. `org-agenda-exporter-settings' into the export commands. This is used when
  2751. the settings have already been scoped and we do not wish to overrule other,
  2752. higher priority settings.
  2753. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2754. (interactive "FWrite agenda to file: \nP")
  2755. (if (not (file-writable-p file))
  2756. (error "Cannot write agenda to file %s" file))
  2757. (org-let (if nosettings nil org-agenda-exporter-settings)
  2758. '(save-excursion
  2759. (save-window-excursion
  2760. (org-agenda-mark-filtered-text)
  2761. (let ((bs (copy-sequence (buffer-string))) beg)
  2762. (org-agenda-unmark-filtered-text)
  2763. (with-temp-buffer
  2764. (rename-buffer org-agenda-write-buffer-name t)
  2765. (set-buffer-modified-p nil)
  2766. (insert bs)
  2767. (org-agenda-remove-marked-text 'org-filtered)
  2768. (while (setq beg (text-property-any (point-min) (point-max)
  2769. 'org-filtered t))
  2770. (delete-region
  2771. beg (or (next-single-property-change beg 'org-filtered)
  2772. (point-max))))
  2773. (run-hooks 'org-agenda-before-write-hook)
  2774. (cond
  2775. ((org-bound-and-true-p org-mobile-creating-agendas)
  2776. (org-mobile-write-agenda-for-mobile file))
  2777. ((string-match "\\.html?\\'" file)
  2778. (require 'htmlize)
  2779. (set-buffer (htmlize-buffer (current-buffer)))
  2780. (when (and org-agenda-export-html-style
  2781. (string-match "<style>" org-agenda-export-html-style))
  2782. ;; replace <style> section with org-agenda-export-html-style
  2783. (goto-char (point-min))
  2784. (kill-region (- (search-forward "<style") 6)
  2785. (search-forward "</style>"))
  2786. (insert org-agenda-export-html-style))
  2787. (write-file file)
  2788. (kill-buffer (current-buffer))
  2789. (message "HTML written to %s" file))
  2790. ((string-match "\\.ps\\'" file)
  2791. (require 'ps-print)
  2792. (ps-print-buffer-with-faces file)
  2793. (message "Postscript written to %s" file))
  2794. ((string-match "\\.pdf\\'" file)
  2795. (require 'ps-print)
  2796. (ps-print-buffer-with-faces
  2797. (concat (file-name-sans-extension file) ".ps"))
  2798. (call-process "ps2pdf" nil nil nil
  2799. (expand-file-name
  2800. (concat (file-name-sans-extension file) ".ps"))
  2801. (expand-file-name file))
  2802. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2803. (message "PDF written to %s" file))
  2804. ((string-match "\\.ics\\'" file)
  2805. (require 'org-icalendar)
  2806. (let ((org-agenda-marker-table
  2807. (org-create-marker-find-array
  2808. (org-agenda-collect-markers)))
  2809. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2810. (org-combined-agenda-icalendar-file file))
  2811. (apply 'org-export-icalendar 'combine
  2812. (org-agenda-files nil 'ifmode))))
  2813. (t
  2814. (let ((bs (buffer-string)))
  2815. (find-file file)
  2816. (erase-buffer)
  2817. (insert bs)
  2818. (save-buffer 0)
  2819. (kill-buffer (current-buffer))
  2820. (message "Plain text written to %s" file))))))))
  2821. (set-buffer (or agenda-bufname
  2822. (and (called-interactively-p 'any) (buffer-name))
  2823. org-agenda-buffer-name)))
  2824. (when open (org-open-file file)))
  2825. (defvar org-agenda-tag-filter-overlays nil)
  2826. (defvar org-agenda-cat-filter-overlays nil)
  2827. (defun org-agenda-mark-filtered-text ()
  2828. "Mark all text hidden by filtering with a text property."
  2829. (let ((inhibit-read-only t))
  2830. (mapc
  2831. (lambda (o)
  2832. (when (equal (overlay-buffer o) (current-buffer))
  2833. (put-text-property
  2834. (overlay-start o) (overlay-end o)
  2835. 'org-filtered t)))
  2836. (append org-agenda-tag-filter-overlays
  2837. org-agenda-cat-filter-overlays))))
  2838. (defun org-agenda-unmark-filtered-text ()
  2839. "Remove the filtering text property."
  2840. (let ((inhibit-read-only t))
  2841. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2842. (defun org-agenda-remove-marked-text (property &optional value)
  2843. "Delete all text marked with VALUE of PROPERTY.
  2844. VALUE defaults to t."
  2845. (let (beg)
  2846. (setq value (or value t))
  2847. (while (setq beg (text-property-any (point-min) (point-max)
  2848. property value))
  2849. (delete-region
  2850. beg (or (next-single-property-change beg 'org-filtered)
  2851. (point-max))))))
  2852. (defun org-agenda-add-entry-text ()
  2853. "Add entry text to agenda lines.
  2854. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2855. entry text following headings shown in the agenda.
  2856. Drawers will be excluded, also the line with scheduling/deadline info."
  2857. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2858. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2859. (let (m txt)
  2860. (goto-char (point-min))
  2861. (while (not (eobp))
  2862. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2863. (beginning-of-line 2)
  2864. (setq txt (org-agenda-get-some-entry-text
  2865. m org-agenda-add-entry-text-maxlines " > "))
  2866. (end-of-line 1)
  2867. (if (string-match "\\S-" txt)
  2868. (insert "\n" txt)
  2869. (or (eobp) (forward-char 1))))))))
  2870. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2871. &rest keep)
  2872. "Extract entry text from MARKER, at most N-LINES lines.
  2873. This will ignore drawers etc, just get the text.
  2874. If INDENT is given, prefix every line with this string. If KEEP is
  2875. given, it is a list of symbols, defining stuff that should not be
  2876. removed from the entry content. Currently only `planning' is allowed here."
  2877. (let (txt drawer-re kwd-time-re ind)
  2878. (save-excursion
  2879. (with-current-buffer (marker-buffer marker)
  2880. (if (not (derived-mode-p 'org-mode))
  2881. (setq txt "")
  2882. (save-excursion
  2883. (save-restriction
  2884. (widen)
  2885. (goto-char marker)
  2886. (end-of-line 1)
  2887. (setq txt (buffer-substring
  2888. (min (1+ (point)) (point-max))
  2889. (progn (outline-next-heading) (point)))
  2890. drawer-re org-drawer-regexp
  2891. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2892. ".*\n?"))
  2893. (with-temp-buffer
  2894. (insert txt)
  2895. (when org-agenda-add-entry-text-descriptive-links
  2896. (goto-char (point-min))
  2897. (while (org-activate-bracket-links (point-max))
  2898. (add-text-properties (match-beginning 0) (match-end 0)
  2899. '(face org-link))))
  2900. (goto-char (point-min))
  2901. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2902. (set-text-properties (match-beginning 0) (match-end 0)
  2903. nil))
  2904. (goto-char (point-min))
  2905. (while (re-search-forward drawer-re nil t)
  2906. (delete-region
  2907. (match-beginning 0)
  2908. (progn (re-search-forward
  2909. "^[ \t]*:END:.*\n?" nil 'move)
  2910. (point))))
  2911. (unless (member 'planning keep)
  2912. (goto-char (point-min))
  2913. (while (re-search-forward kwd-time-re nil t)
  2914. (replace-match "")))
  2915. (goto-char (point-min))
  2916. (when org-agenda-entry-text-exclude-regexps
  2917. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2918. (while (setq re (pop re-list))
  2919. (goto-char (point-min))
  2920. (while (re-search-forward re nil t)
  2921. (replace-match "")))))
  2922. (goto-char (point-max))
  2923. (skip-chars-backward " \t\n")
  2924. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2925. ;; find and remove min common indentation
  2926. (goto-char (point-min))
  2927. (untabify (point-min) (point-max))
  2928. (setq ind (org-get-indentation))
  2929. (while (not (eobp))
  2930. (unless (looking-at "[ \t]*$")
  2931. (setq ind (min ind (org-get-indentation))))
  2932. (beginning-of-line 2))
  2933. (goto-char (point-min))
  2934. (while (not (eobp))
  2935. (unless (looking-at "[ \t]*$")
  2936. (move-to-column ind)
  2937. (delete-region (point-at-bol) (point)))
  2938. (beginning-of-line 2))
  2939. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2940. (goto-char (point-min))
  2941. (when indent
  2942. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2943. (replace-match indent t t)))
  2944. (goto-char (point-min))
  2945. (while (looking-at "[ \t]*\n") (replace-match ""))
  2946. (goto-char (point-max))
  2947. (when (> (org-current-line)
  2948. n-lines)
  2949. (org-goto-line (1+ n-lines))
  2950. (backward-char 1))
  2951. (setq txt (buffer-substring (point-min) (point)))))))))
  2952. txt))
  2953. (defun org-agenda-collect-markers ()
  2954. "Collect the markers pointing to entries in the agenda buffer."
  2955. (let (m markers)
  2956. (save-excursion
  2957. (goto-char (point-min))
  2958. (while (not (eobp))
  2959. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2960. (org-get-at-bol 'org-marker)))
  2961. (push m markers))
  2962. (beginning-of-line 2)))
  2963. (nreverse markers)))
  2964. (defun org-create-marker-find-array (marker-list)
  2965. "Create a alist of files names with all marker positions in that file."
  2966. (let (f tbl m a p)
  2967. (while (setq m (pop marker-list))
  2968. (setq p (marker-position m)
  2969. f (buffer-file-name (or (buffer-base-buffer
  2970. (marker-buffer m))
  2971. (marker-buffer m))))
  2972. (if (setq a (assoc f tbl))
  2973. (push (marker-position m) (cdr a))
  2974. (push (list f p) tbl)))
  2975. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2976. tbl)))
  2977. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2978. (defun org-check-agenda-marker-table ()
  2979. "Check of the current entry is on the marker list."
  2980. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2981. a)
  2982. (and (setq a (assoc file org-agenda-marker-table))
  2983. (save-match-data
  2984. (save-excursion
  2985. (org-back-to-heading t)
  2986. (member (point) (cdr a)))))))
  2987. (defun org-check-for-org-mode ()
  2988. "Make sure current buffer is in org-mode. Error if not."
  2989. (or (derived-mode-p 'org-mode)
  2990. (error "Cannot execute org-mode agenda command on buffer in %s"
  2991. major-mode)))
  2992. ;;; Agenda prepare and finalize
  2993. (defvar org-agenda-multi nil) ; dynamically scoped
  2994. (defvar org-agenda-buffer-name "*Org Agenda*")
  2995. (defvar org-agenda-pre-window-conf nil)
  2996. (defvar org-agenda-columns-active nil)
  2997. (defvar org-agenda-name nil)
  2998. (defvar org-agenda-tag-filter nil)
  2999. (defvar org-agenda-category-filter nil)
  3000. (defvar org-agenda-top-category-filter nil)
  3001. (defvar org-agenda-tag-filter-while-redo nil)
  3002. (defvar org-agenda-tag-filter-preset nil
  3003. "A preset of the tags filter used for secondary agenda filtering.
  3004. This must be a list of strings, each string must be a single tag preceded
  3005. by \"+\" or \"-\".
  3006. This variable should not be set directly, but agenda custom commands can
  3007. bind it in the options section. The preset filter is a global property of
  3008. the entire agenda view. In a block agenda, it will not work reliably to
  3009. define a filter for one of the individual blocks. You need to set it in
  3010. the global options and expect it to be applied to the entire view.")
  3011. (defvar org-agenda-category-filter-preset nil
  3012. "A preset of the category filter used for secondary agenda filtering.
  3013. This must be a list of strings, each string must be a single category
  3014. preceded by \"+\" or \"-\".
  3015. This variable should not be set directly, but agenda custom commands can
  3016. bind it in the options section. The preset filter is a global property of
  3017. the entire agenda view. In a block agenda, it will not work reliably to
  3018. define a filter for one of the individual blocks. You need to set it in
  3019. the global options and expect it to be applied to the entire view.")
  3020. (defun org-agenda-use-sticky-p ()
  3021. "Return non-nil if an agenda buffer named
  3022. `org-agenda-buffer-name' exists and should be shown instead of
  3023. generating a new one."
  3024. (and
  3025. ;; turned off by user
  3026. org-agenda-sticky
  3027. ;; For multi-agenda buffer already exists
  3028. (not org-agenda-multi)
  3029. ;; buffer found
  3030. (get-buffer org-agenda-buffer-name)
  3031. ;; C-u parameter is same as last call
  3032. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3033. (and
  3034. (equal current-prefix-arg
  3035. org-agenda-last-prefix-arg)
  3036. ;; In case user turned stickiness on, while having existing
  3037. ;; Agenda buffer active, don't reuse that buffer, because it
  3038. ;; does not have org variables local
  3039. org-agenda-this-buffer-is-sticky))))
  3040. (defun org-agenda-prepare-window (abuf)
  3041. "Setup agenda buffer in the window."
  3042. (let* ((awin (get-buffer-window abuf))
  3043. wconf)
  3044. (cond
  3045. ((equal (current-buffer) abuf) nil)
  3046. (awin (select-window awin))
  3047. ((not (setq wconf (current-window-configuration))))
  3048. ((equal org-agenda-window-setup 'current-window)
  3049. (org-pop-to-buffer-same-window abuf))
  3050. ((equal org-agenda-window-setup 'other-window)
  3051. (org-switch-to-buffer-other-window abuf))
  3052. ((equal org-agenda-window-setup 'other-frame)
  3053. (switch-to-buffer-other-frame abuf))
  3054. ((equal org-agenda-window-setup 'reorganize-frame)
  3055. (delete-other-windows)
  3056. (org-switch-to-buffer-other-window abuf)))
  3057. ;; additional test in case agenda is invoked from within agenda
  3058. ;; buffer via elisp link
  3059. (unless (equal (current-buffer) abuf)
  3060. (org-pop-to-buffer-same-window abuf))
  3061. (setq org-agenda-pre-window-conf
  3062. (or org-agenda-pre-window-conf wconf))))
  3063. (defun org-agenda-prepare (&optional name)
  3064. (if (org-agenda-use-sticky-p)
  3065. (progn
  3066. ;; Popup existing buffer
  3067. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3068. (message "Sticky Agenda buffer, use `r' to refresh")
  3069. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3070. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3071. (setq org-todo-keywords-for-agenda nil)
  3072. (setq org-drawers-for-agenda nil)
  3073. (unless org-agenda-persistent-filter
  3074. (setq org-agenda-tag-filter nil
  3075. org-agenda-category-filter nil))
  3076. (put 'org-agenda-tag-filter :preset-filter
  3077. org-agenda-tag-filter-preset)
  3078. (put 'org-agenda-category-filter :preset-filter
  3079. org-agenda-category-filter-preset)
  3080. (if org-agenda-multi
  3081. (progn
  3082. (setq buffer-read-only nil)
  3083. (goto-char (point-max))
  3084. (unless (or (bobp) org-agenda-compact-blocks
  3085. (not org-agenda-block-separator))
  3086. (insert "\n"
  3087. (if (stringp org-agenda-block-separator)
  3088. org-agenda-block-separator
  3089. (make-string (window-width) org-agenda-block-separator))
  3090. "\n"))
  3091. (narrow-to-region (point) (point-max)))
  3092. (setq org-done-keywords-for-agenda nil)
  3093. ;; Setting any org variables that are in org-agenda-local-vars
  3094. ;; list need to be done after the prepare call
  3095. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3096. (setq buffer-read-only nil)
  3097. (org-agenda-reset-markers)
  3098. (let ((inhibit-read-only t)) (erase-buffer))
  3099. (org-agenda-mode)
  3100. (setq org-agenda-buffer (current-buffer))
  3101. (setq org-agenda-contributing-files nil)
  3102. (setq org-agenda-columns-active nil)
  3103. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3104. (setq org-todo-keywords-for-agenda
  3105. (org-uniquify org-todo-keywords-for-agenda))
  3106. (setq org-done-keywords-for-agenda
  3107. (org-uniquify org-done-keywords-for-agenda))
  3108. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3109. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3110. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3111. (and name (not org-agenda-name)
  3112. (org-set-local 'org-agenda-name name)))
  3113. (setq buffer-read-only nil)))
  3114. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3115. (defun org-agenda-finalize ()
  3116. "Finishing touch for the agenda buffer, called just before displaying it."
  3117. (unless org-agenda-multi
  3118. (save-excursion
  3119. (let ((inhibit-read-only t))
  3120. (goto-char (point-min))
  3121. (while (org-activate-bracket-links (point-max))
  3122. (add-text-properties (match-beginning 0) (match-end 0)
  3123. '(face org-link)))
  3124. (org-agenda-align-tags)
  3125. (unless org-agenda-with-colors
  3126. (remove-text-properties (point-min) (point-max) '(face nil))))
  3127. (if (and (boundp 'org-agenda-overriding-columns-format)
  3128. org-agenda-overriding-columns-format)
  3129. (org-set-local 'org-agenda-overriding-columns-format
  3130. org-agenda-overriding-columns-format))
  3131. (if (and (boundp 'org-agenda-view-columns-initially)
  3132. org-agenda-view-columns-initially)
  3133. (org-agenda-columns))
  3134. (when org-agenda-fontify-priorities
  3135. (org-agenda-fontify-priorities))
  3136. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3137. (org-agenda-dim-blocked-tasks))
  3138. (org-agenda-mark-clocking-task)
  3139. (when org-agenda-entry-text-mode
  3140. (org-agenda-entry-text-hide)
  3141. (org-agenda-entry-text-show))
  3142. (if (functionp 'org-habit-insert-consistency-graphs)
  3143. (org-habit-insert-consistency-graphs))
  3144. (run-hooks 'org-agenda-finalize-hook)
  3145. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3146. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3147. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3148. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3149. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3150. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3151. )))
  3152. (defun org-agenda-mark-clocking-task ()
  3153. "Mark the current clock entry in the agenda if it is present."
  3154. (mapc (lambda (o)
  3155. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3156. (delete-overlay o)))
  3157. (overlays-in (point-min) (point-max)))
  3158. (when (marker-buffer org-clock-hd-marker)
  3159. (save-excursion
  3160. (goto-char (point-min))
  3161. (let (s ov)
  3162. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3163. (goto-char s)
  3164. (when (equal (org-get-at-bol 'org-hd-marker)
  3165. org-clock-hd-marker)
  3166. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3167. (overlay-put ov 'type 'org-agenda-clocking)
  3168. (overlay-put ov 'face 'org-agenda-clocking)
  3169. (overlay-put ov 'help-echo
  3170. "The clock is running in this item")))))))
  3171. (defun org-agenda-fontify-priorities ()
  3172. "Make highest priority lines bold, and lowest italic."
  3173. (interactive)
  3174. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3175. (delete-overlay o)))
  3176. (overlays-in (point-min) (point-max)))
  3177. (save-excursion
  3178. (let ((inhibit-read-only t)
  3179. b e p ov h l)
  3180. (goto-char (point-min))
  3181. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3182. (setq h (or (get-char-property (point) 'org-highest-priority)
  3183. org-highest-priority)
  3184. l (or (get-char-property (point) 'org-lowest-priority)
  3185. org-lowest-priority)
  3186. p (string-to-char (match-string 1))
  3187. b (match-beginning 0)
  3188. e (if (eq org-agenda-fontify-priorities 'cookies)
  3189. (match-end 0)
  3190. (point-at-eol))
  3191. ov (make-overlay b e))
  3192. (overlay-put
  3193. ov 'face
  3194. (cond ((org-face-from-face-or-color
  3195. 'priority nil
  3196. (cdr (assoc p org-priority-faces))))
  3197. ((and (listp org-agenda-fontify-priorities)
  3198. (org-face-from-face-or-color
  3199. 'priority nil
  3200. (cdr (assoc p org-agenda-fontify-priorities)))))
  3201. ((equal p l) 'italic)
  3202. ((equal p h) 'bold)))
  3203. (overlay-put ov 'org-type 'org-priority)))))
  3204. (defun org-agenda-dim-blocked-tasks ()
  3205. "Dim currently blocked TODO's in the agenda display."
  3206. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3207. (delete-overlay o)))
  3208. (overlays-in (point-min) (point-max)))
  3209. (save-excursion
  3210. (let ((inhibit-read-only t)
  3211. (org-depend-tag-blocked nil)
  3212. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3213. org-blocked-by-checkboxes
  3214. invis1 b e p ov h l)
  3215. (goto-char (point-min))
  3216. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3217. (and pos (goto-char (1+ pos))))
  3218. (setq org-blocked-by-checkboxes nil invis1 invis)
  3219. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3220. (when (and marker
  3221. (with-current-buffer (marker-buffer marker)
  3222. (save-excursion (goto-char marker)
  3223. (org-entry-blocked-p))))
  3224. (if org-blocked-by-checkboxes (setq invis1 nil))
  3225. (setq b (if invis1
  3226. (max (point-min) (1- (point-at-bol)))
  3227. (point-at-bol))
  3228. e (point-at-eol)
  3229. ov (make-overlay b e))
  3230. (if invis1
  3231. (overlay-put ov 'invisible t)
  3232. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3233. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3234. (defvar org-agenda-skip-function nil
  3235. "Function to be called at each match during agenda construction.
  3236. If this function returns nil, the current match should not be skipped.
  3237. Otherwise, the function must return a position from where the search
  3238. should be continued.
  3239. This may also be a Lisp form, it will be evaluated.
  3240. Never set this variable using `setq' or so, because then it will apply
  3241. to all future agenda commands. If you do want a global skipping condition,
  3242. use the option `org-agenda-skip-function-global' instead.
  3243. The correct usage for `org-agenda-skip-function' is to bind it with
  3244. `let' to scope it dynamically into the agenda-constructing command.
  3245. A good way to set it is through options in `org-agenda-custom-commands'.")
  3246. (defun org-agenda-skip ()
  3247. "Throw to `:skip' in places that should be skipped.
  3248. Also moves point to the end of the skipped region, so that search can
  3249. continue from there."
  3250. (let ((p (point-at-bol)) to)
  3251. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3252. (get-text-property p :org-archived)
  3253. (org-end-of-subtree t)
  3254. (throw :skip t))
  3255. (and org-agenda-skip-comment-trees
  3256. (get-text-property p :org-comment)
  3257. (org-end-of-subtree t)
  3258. (throw :skip t))
  3259. (if (equal (char-after p) ?#) (throw :skip t))
  3260. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3261. (org-agenda-skip-eval org-agenda-skip-function)))
  3262. (goto-char to)
  3263. (throw :skip t))))
  3264. (defun org-agenda-skip-eval (form)
  3265. "If FORM is a function or a list, call (or eval) is and return result.
  3266. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3267. and match data are returned to the previous state no matter what these
  3268. functions do."
  3269. (let (fp)
  3270. (and form
  3271. (or (setq fp (functionp form))
  3272. (consp form))
  3273. (save-excursion
  3274. (save-match-data
  3275. (if fp
  3276. (funcall form)
  3277. (eval form)))))))
  3278. (defvar org-agenda-markers nil
  3279. "List of all currently active markers created by `org-agenda'.")
  3280. (defvar org-agenda-last-marker-time (org-float-time)
  3281. "Creation time of the last agenda marker.")
  3282. (defun org-agenda-new-marker (&optional pos)
  3283. "Return a new agenda marker.
  3284. Org-mode keeps a list of these markers and resets them when they are
  3285. no longer in use."
  3286. (let ((m (copy-marker (or pos (point)))))
  3287. (setq org-agenda-last-marker-time (org-float-time))
  3288. (if org-agenda-buffer
  3289. (with-current-buffer org-agenda-buffer
  3290. (push m org-agenda-markers))
  3291. (push m org-agenda-markers))
  3292. m))
  3293. (defun org-agenda-reset-markers ()
  3294. "Reset markers created by `org-agenda'."
  3295. (while org-agenda-markers
  3296. (move-marker (pop org-agenda-markers) nil)))
  3297. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3298. "Save relative positions of markers in region.
  3299. This check for agenda markers in all agenda buffers currently active."
  3300. (dolist (buf (buffer-list))
  3301. (with-current-buffer buf
  3302. (when (eq major-mode 'org-agenda-mode)
  3303. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3304. org-agenda-markers)))))
  3305. ;;; Entry text mode
  3306. (defun org-agenda-entry-text-show-here ()
  3307. "Add some text from the entry as context to the current line."
  3308. (let (m txt o)
  3309. (setq m (org-get-at-bol 'org-hd-marker))
  3310. (unless (marker-buffer m)
  3311. (error "No marker points to an entry here"))
  3312. (setq txt (concat "\n" (org-no-properties
  3313. (org-agenda-get-some-entry-text
  3314. m org-agenda-entry-text-maxlines " > "))))
  3315. (when (string-match "\\S-" txt)
  3316. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3317. (overlay-put o 'evaporate t)
  3318. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3319. (overlay-put o 'after-string txt))))
  3320. (defun org-agenda-entry-text-show ()
  3321. "Add entry context for all agenda lines."
  3322. (interactive)
  3323. (save-excursion
  3324. (goto-char (point-max))
  3325. (beginning-of-line 1)
  3326. (while (not (bobp))
  3327. (when (org-get-at-bol 'org-hd-marker)
  3328. (org-agenda-entry-text-show-here))
  3329. (beginning-of-line 0))))
  3330. (defun org-agenda-entry-text-hide ()
  3331. "Remove any shown entry context."
  3332. (delq nil
  3333. (mapcar (lambda (o)
  3334. (if (eq (overlay-get o 'org-overlay-type)
  3335. 'agenda-entry-content)
  3336. (progn (delete-overlay o) t)))
  3337. (overlays-in (point-min) (point-max)))))
  3338. (defun org-agenda-get-day-face (date)
  3339. "Return the face DATE should be displayed with."
  3340. (or (and (functionp org-agenda-day-face-function)
  3341. (funcall org-agenda-day-face-function date))
  3342. (cond ((org-agenda-todayp date)
  3343. 'org-agenda-date-today)
  3344. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3345. 'org-agenda-date-weekend)
  3346. (t 'org-agenda-date))))
  3347. ;;; Agenda timeline
  3348. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3349. (defun org-timeline (&optional dotodo)
  3350. "Show a time-sorted view of the entries in the current org file.
  3351. Only entries with a time stamp of today or later will be listed. With
  3352. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3353. under the current date.
  3354. If the buffer contains an active region, only check the region for
  3355. dates."
  3356. (interactive "P")
  3357. (let* ((dopast t)
  3358. (org-agenda-show-log-scoped org-agenda-show-log)
  3359. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3360. (current-buffer))))
  3361. (date (calendar-current-date))
  3362. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3363. (end (if (org-region-active-p) (region-end) (point-max)))
  3364. (day-numbers (org-get-all-dates
  3365. beg end 'no-ranges
  3366. t org-agenda-show-log-scoped ; always include today
  3367. org-timeline-show-empty-dates))
  3368. (org-deadline-warning-days 0)
  3369. (org-agenda-only-exact-dates t)
  3370. (today (org-today))
  3371. (past t)
  3372. args
  3373. s e rtn d emptyp)
  3374. (setq org-agenda-redo-command
  3375. (list 'progn
  3376. (list 'org-switch-to-buffer-other-window (current-buffer))
  3377. (list 'org-timeline (list 'quote dotodo))))
  3378. (if (not dopast)
  3379. ;; Remove past dates from the list of dates.
  3380. (setq day-numbers (delq nil (mapcar (lambda(x)
  3381. (if (>= x today) x nil))
  3382. day-numbers))))
  3383. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3384. (org-compile-prefix-format 'timeline)
  3385. (org-set-sorting-strategy 'timeline)
  3386. (if org-agenda-show-log-scoped (push :closed args))
  3387. (push :timestamp args)
  3388. (push :deadline args)
  3389. (push :scheduled args)
  3390. (push :sexp args)
  3391. (if dotodo (push :todo args))
  3392. (insert "Timeline of file " entry "\n")
  3393. (add-text-properties (point-min) (point)
  3394. (list 'face 'org-agenda-structure))
  3395. (org-agenda-mark-header-line (point-min))
  3396. (while (setq d (pop day-numbers))
  3397. (if (and (listp d) (eq (car d) :omitted))
  3398. (progn
  3399. (setq s (point))
  3400. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3401. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3402. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3403. (if (and (>= d today)
  3404. dopast
  3405. past)
  3406. (progn
  3407. (setq past nil)
  3408. (insert (make-string 79 ?-) "\n")))
  3409. (setq date (calendar-gregorian-from-absolute d))
  3410. (setq s (point))
  3411. (setq rtn (and (not emptyp)
  3412. (apply 'org-agenda-get-day-entries entry
  3413. date args)))
  3414. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3415. (progn
  3416. (insert
  3417. (if (stringp org-agenda-format-date)
  3418. (format-time-string org-agenda-format-date
  3419. (org-time-from-absolute date))
  3420. (funcall org-agenda-format-date date))
  3421. "\n")
  3422. (put-text-property s (1- (point)) 'face
  3423. (org-agenda-get-day-face date))
  3424. (put-text-property s (1- (point)) 'org-date-line t)
  3425. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3426. (if (equal d today)
  3427. (put-text-property s (1- (point)) 'org-today t))
  3428. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3429. (put-text-property s (1- (point)) 'day d)))))
  3430. (goto-char (point-min))
  3431. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3432. (point-min)))
  3433. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3434. (org-agenda-finalize)
  3435. (setq buffer-read-only t)))
  3436. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3437. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3438. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3439. not every single day in the range. If FORCE-TODAY is non-nil, make
  3440. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3441. inactive time stamps (those in square brackets) are included.
  3442. When EMPTY is non-nil, also include days without any entries."
  3443. (let ((re (concat
  3444. (if pre-re pre-re "")
  3445. (if inactive org-ts-regexp-both org-ts-regexp)))
  3446. dates dates1 date day day1 day2 ts1 ts2 pos)
  3447. (if force-today
  3448. (setq dates (list (org-today))))
  3449. (save-excursion
  3450. (goto-char beg)
  3451. (while (re-search-forward re end t)
  3452. (setq day (time-to-days (org-time-string-to-time
  3453. (substring (match-string 1) 0 10)
  3454. (current-buffer) (match-beginning 0))))
  3455. (or (memq day dates) (push day dates)))
  3456. (unless no-ranges
  3457. (goto-char beg)
  3458. (while (re-search-forward org-tr-regexp end t)
  3459. (setq pos (match-beginning 0))
  3460. (setq ts1 (substring (match-string 1) 0 10)
  3461. ts2 (substring (match-string 2) 0 10)
  3462. day1 (time-to-days (org-time-string-to-time
  3463. ts1 (current-buffer) pos))
  3464. day2 (time-to-days (org-time-string-to-time
  3465. ts2 (current-buffer) pos)))
  3466. (while (< (setq day1 (1+ day1)) day2)
  3467. (or (memq day1 dates) (push day1 dates)))))
  3468. (setq dates (sort dates '<))
  3469. (when empty
  3470. (while (setq day (pop dates))
  3471. (setq day2 (car dates))
  3472. (push day dates1)
  3473. (when (and day2 empty)
  3474. (if (or (eq empty t)
  3475. (and (numberp empty) (<= (- day2 day) empty)))
  3476. (while (< (setq day (1+ day)) day2)
  3477. (push (list day) dates1))
  3478. (push (cons :omitted (- day2 day)) dates1))))
  3479. (setq dates (nreverse dates1)))
  3480. dates)))
  3481. ;;; Agenda Daily/Weekly
  3482. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3483. "Start day for the agenda view.
  3484. Custom commands can set this variable in the options section.")
  3485. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3486. (defvar org-arg-loc nil) ; local variable
  3487. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3488. "List of types searched for when creating the daily/weekly agenda.
  3489. This variable is a list of symbols that controls the types of
  3490. items that appear in the daily/weekly agenda. Allowed symbols in this
  3491. list are are
  3492. :timestamp List items containing a date stamp or date range matching
  3493. the selected date. This includes sexp entries in
  3494. angular brackets.
  3495. :sexp List entries resulting from plain diary-like sexps.
  3496. :deadline List deadline due on that date. When the date is today,
  3497. also list any deadlines past due, or due within
  3498. `org-deadline-warning-days'. `:deadline' must appear before
  3499. `:scheduled' if the setting of
  3500. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3501. any effect.
  3502. :scheduled List all items which are scheduled for the given date.
  3503. The diary for *today* also contains items which were
  3504. scheduled earlier and are not yet marked DONE.
  3505. By default, all four types are turned on.
  3506. Never set this variable globally using `setq', because then it
  3507. will apply to all future agenda commands. Instead, bind it with
  3508. `let' to scope it dynamically into the agenda-constructing
  3509. command. A good way to set it is through options in
  3510. `org-agenda-custom-commands'. For a more flexible (though
  3511. somewhat less efficient) way of determining what is included in
  3512. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3513. ;;;###autoload
  3514. (defun org-agenda-list (&optional arg start-day span)
  3515. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3516. The view will be for the current day or week, but from the overview buffer
  3517. you will be able to go to other days/weeks.
  3518. With a numeric prefix argument in an interactive call, the agenda will
  3519. span ARG days. Lisp programs should instead specify SPAN to change
  3520. the number of days. SPAN defaults to `org-agenda-span'.
  3521. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3522. given in `org-agenda-start-on-weekday'."
  3523. (interactive "P")
  3524. (if org-agenda-overriding-arguments
  3525. (setq arg (car org-agenda-overriding-arguments)
  3526. start-day (nth 1 org-agenda-overriding-arguments)
  3527. span (nth 2 org-agenda-overriding-arguments)))
  3528. (if (and (integerp arg) (> arg 0))
  3529. (setq span arg arg nil))
  3530. (catch 'exit
  3531. (if org-agenda-sticky
  3532. (setq org-agenda-buffer-name
  3533. (cond ((and org-keys (stringp org-match))
  3534. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3535. (org-keys
  3536. (format "*Org Agenda(%s)*" org-keys))
  3537. (t "*Org Agenda(a)*"))))
  3538. (org-agenda-prepare "Day/Week")
  3539. (setq start-day (or start-day org-agenda-start-day))
  3540. (if (stringp start-day)
  3541. ;; Convert to an absolute day number
  3542. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3543. (org-compile-prefix-format 'agenda)
  3544. (org-set-sorting-strategy 'agenda)
  3545. (let* ((span (org-agenda-ndays-to-span
  3546. (or span org-agenda-ndays org-agenda-span)))
  3547. (today (org-today))
  3548. (sd (or start-day today))
  3549. (ndays (org-agenda-span-to-ndays span sd))
  3550. (org-agenda-start-on-weekday
  3551. (if (eq ndays 7)
  3552. org-agenda-start-on-weekday))
  3553. (thefiles (org-agenda-files nil 'ifmode))
  3554. (files thefiles)
  3555. (start (if (or (null org-agenda-start-on-weekday)
  3556. (< ndays 7))
  3557. sd
  3558. (let* ((nt (calendar-day-of-week
  3559. (calendar-gregorian-from-absolute sd)))
  3560. (n1 org-agenda-start-on-weekday)
  3561. (d (- nt n1)))
  3562. (- sd (+ (if (< d 0) 7 0) d)))))
  3563. (day-numbers (list start))
  3564. (day-cnt 0)
  3565. (inhibit-redisplay (not debug-on-error))
  3566. (org-agenda-show-log-scoped org-agenda-show-log)
  3567. s e rtn rtnall file date d start-pos end-pos todayp
  3568. clocktable-start clocktable-end filter)
  3569. (setq org-agenda-redo-command
  3570. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3571. (dotimes (n (1- ndays))
  3572. (push (1+ (car day-numbers)) day-numbers))
  3573. (setq day-numbers (nreverse day-numbers))
  3574. (setq clocktable-start (car day-numbers)
  3575. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3576. (org-set-local 'org-starting-day (car day-numbers))
  3577. (org-set-local 'org-arg-loc arg)
  3578. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3579. (unless org-agenda-compact-blocks
  3580. (let* ((d1 (car day-numbers))
  3581. (d2 (org-last day-numbers))
  3582. (w1 (org-days-to-iso-week d1))
  3583. (w2 (org-days-to-iso-week d2)))
  3584. (setq s (point))
  3585. (if org-agenda-overriding-header
  3586. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3587. nil 'face 'org-agenda-structure) "\n")
  3588. (insert (org-agenda-span-name span)
  3589. "-agenda"
  3590. (if (< (- d2 d1) 350)
  3591. (if (= w1 w2)
  3592. (format " (W%02d)" w1)
  3593. (format " (W%02d-W%02d)" w1 w2))
  3594. "")
  3595. ":\n")))
  3596. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3597. 'org-date-line t))
  3598. (org-agenda-mark-header-line s))
  3599. (while (setq d (pop day-numbers))
  3600. (setq date (calendar-gregorian-from-absolute d)
  3601. s (point))
  3602. (if (or (setq todayp (= d today))
  3603. (and (not start-pos) (= d sd)))
  3604. (setq start-pos (point))
  3605. (if (and start-pos (not end-pos))
  3606. (setq end-pos (point))))
  3607. (setq files thefiles
  3608. rtnall nil)
  3609. (while (setq file (pop files))
  3610. (catch 'nextfile
  3611. (org-check-agenda-file file)
  3612. (let ((org-agenda-entry-types org-agenda-entry-types))
  3613. (unless org-agenda-include-deadlines
  3614. (setq org-agenda-entry-types
  3615. (delq :deadline org-agenda-entry-types)))
  3616. (cond
  3617. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3618. (setq rtn (org-agenda-get-day-entries
  3619. file date :closed)))
  3620. (org-agenda-show-log-scoped
  3621. (setq rtn (apply 'org-agenda-get-day-entries
  3622. file date
  3623. (append '(:closed) org-agenda-entry-types))))
  3624. (t
  3625. (setq rtn (apply 'org-agenda-get-day-entries
  3626. file date
  3627. org-agenda-entry-types)))))
  3628. (setq rtnall (append rtnall rtn)))) ;; all entries
  3629. (if org-agenda-include-diary
  3630. (let ((org-agenda-search-headline-for-time t))
  3631. (require 'diary-lib)
  3632. (setq rtn (org-get-entries-from-diary date))
  3633. (setq rtnall (append rtnall rtn))))
  3634. (if (or rtnall org-agenda-show-all-dates)
  3635. (progn
  3636. (setq day-cnt (1+ day-cnt))
  3637. (insert
  3638. (if (stringp org-agenda-format-date)
  3639. (format-time-string org-agenda-format-date
  3640. (org-time-from-absolute date))
  3641. (funcall org-agenda-format-date date))
  3642. "\n")
  3643. (put-text-property s (1- (point)) 'face
  3644. (org-agenda-get-day-face date))
  3645. (put-text-property s (1- (point)) 'org-date-line t)
  3646. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3647. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3648. (when todayp
  3649. (put-text-property s (1- (point)) 'org-today t))
  3650. (setq rtnall
  3651. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3652. (if rtnall (insert ;; all entries
  3653. (org-agenda-finalize-entries rtnall)
  3654. "\n"))
  3655. (put-text-property s (1- (point)) 'day d)
  3656. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3657. (when (and org-agenda-clockreport-mode clocktable-start)
  3658. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3659. ;; the above line is to ensure the restricted range!
  3660. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3661. tbl)
  3662. (setq p (org-plist-delete p :block))
  3663. (setq p (plist-put p :tstart clocktable-start))
  3664. (setq p (plist-put p :tend clocktable-end))
  3665. (setq p (plist-put p :scope 'agenda))
  3666. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3667. (setq filter (or org-agenda-tag-filter-while-redo
  3668. (get 'org-agenda-tag-filter :preset-filter))))
  3669. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3670. (if (string-match "[<>=]" x)
  3671. ""
  3672. x))
  3673. filter ""))))
  3674. (setq tbl (apply 'org-get-clocktable p))
  3675. (insert tbl)))
  3676. (goto-char (point-min))
  3677. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3678. (unless (and (pos-visible-in-window-p (point-min))
  3679. (pos-visible-in-window-p (point-max)))
  3680. (goto-char (1- (point-max)))
  3681. (recenter -1)
  3682. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3683. (progn
  3684. (goto-char (or start-pos 1))
  3685. (recenter 1))))
  3686. (goto-char (or start-pos 1))
  3687. (add-text-properties (point-min) (point-max)
  3688. `(org-agenda-type agenda
  3689. org-last-args (,arg ,start-day ,span)
  3690. org-redo-cmd ,org-agenda-redo-command
  3691. org-serie-cmd ,org-cmd))
  3692. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3693. (org-agenda-show-clocking-issues))
  3694. (org-agenda-finalize)
  3695. (setq buffer-read-only t)
  3696. (message ""))))
  3697. (defun org-agenda-ndays-to-span (n)
  3698. "Return a span symbol for a span of N days, or N if none matches."
  3699. (cond ((symbolp n) n)
  3700. ((= n 1) 'day)
  3701. ((= n 7) 'week)
  3702. (t n)))
  3703. (defun org-agenda-span-to-ndays (span start-day)
  3704. "Return ndays from SPAN starting at START-DAY."
  3705. (cond ((numberp span) span)
  3706. ((eq span 'day) 1)
  3707. ((eq span 'week) 7)
  3708. ((eq span 'month)
  3709. (let ((date (calendar-gregorian-from-absolute start-day)))
  3710. (calendar-last-day-of-month (car date) (caddr date))))
  3711. ((eq span 'year)
  3712. (let ((date (calendar-gregorian-from-absolute start-day)))
  3713. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3714. (defun org-agenda-span-name (span)
  3715. "Return a SPAN name."
  3716. (if (null span)
  3717. ""
  3718. (if (symbolp span)
  3719. (capitalize (symbol-name span))
  3720. (format "%d days" span))))
  3721. ;;; Agenda word search
  3722. (defvar org-agenda-search-history nil)
  3723. (defvar org-search-syntax-table nil
  3724. "Special syntax table for org-mode search.
  3725. In this table, we have single quotes not as word constituents, to
  3726. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3727. (defvar org-mode-syntax-table) ; From org.el
  3728. (defun org-search-syntax-table ()
  3729. (unless org-search-syntax-table
  3730. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3731. (modify-syntax-entry ?' "." org-search-syntax-table)
  3732. (modify-syntax-entry ?` "." org-search-syntax-table))
  3733. org-search-syntax-table)
  3734. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3735. ;;;###autoload
  3736. (defun org-search-view (&optional todo-only string edit-at)
  3737. "Show all entries that contain a phrase or words or regular expressions.
  3738. With optional prefix argument TODO-ONLY, only consider entries that are
  3739. TODO entries. The argument STRING can be used to pass a default search
  3740. string into this function. If EDIT-AT is non-nil, it means that the
  3741. user should get a chance to edit this string, with cursor at position
  3742. EDIT-AT.
  3743. The search string can be viewed either as a phrase that should be found as
  3744. is, or it can be broken into a number of snippets, each of which must match
  3745. in a Boolean way to select an entry. The default depends on the variable
  3746. `org-agenda-search-view-always-boolean'.
  3747. Even if this is turned off (the default) you can always switch to
  3748. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3749. The default is a direct search of the whole phrase, where each space in
  3750. the search string can expand to an arbitrary amount of whitespace,
  3751. including newlines.
  3752. If using a Boolean search, the search string is split on whitespace and
  3753. each snippet is searched separately, with logical AND to select an entry.
  3754. Words prefixed with a minus must *not* occur in the entry. Words without
  3755. a prefix or prefixed with a plus must occur in the entry. Matching is
  3756. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3757. match whole words, not parts of a word) if
  3758. `org-agenda-search-view-force-full-words' is set (default is nil).
  3759. Boolean search snippets enclosed by curly braces are interpreted as
  3760. regular expressions that must or (when preceded with \"-\") must not
  3761. match in the entry. Snippets enclosed into double quotes will be taken
  3762. as a whole, to include whitespace.
  3763. - If the search string starts with an asterisk, search only in headlines.
  3764. - If (possibly after the leading star) the search string starts with an
  3765. exclamation mark, this also means to look at TODO entries only, an effect
  3766. that can also be achieved with a prefix argument.
  3767. - If (possibly after star and exclamation mark) the search string starts
  3768. with a colon, this will mean that the (non-regexp) snippets of the
  3769. Boolean search must match as full words.
  3770. This command searches the agenda files, and in addition the files listed
  3771. in `org-agenda-text-search-extra-files'."
  3772. (interactive "P")
  3773. (if org-agenda-overriding-arguments
  3774. (setq todo-only (car org-agenda-overriding-arguments)
  3775. string (nth 1 org-agenda-overriding-arguments)
  3776. edit-at (nth 2 org-agenda-overriding-arguments)))
  3777. (let* ((props (list 'face nil
  3778. 'done-face 'org-agenda-done
  3779. 'org-not-done-regexp org-not-done-regexp
  3780. 'org-todo-regexp org-todo-regexp
  3781. 'org-complex-heading-regexp org-complex-heading-regexp
  3782. 'mouse-face 'highlight
  3783. 'help-echo (format "mouse-2 or RET jump to location")))
  3784. (full-words org-agenda-search-view-force-full-words)
  3785. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3786. regexp rtn rtnall files file pos
  3787. marker category category-pos tags c neg re boolean
  3788. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3789. (unless (and (not edit-at)
  3790. (stringp string)
  3791. (string-match "\\S-" string))
  3792. (setq string (read-string
  3793. (if org-agenda-search-view-always-boolean
  3794. "[+-]Word/{Regexp} ...: "
  3795. "Phrase or [+-]Word/{Regexp} ...: ")
  3796. (cond
  3797. ((integerp edit-at) (cons string edit-at))
  3798. (edit-at string))
  3799. 'org-agenda-search-history)))
  3800. (catch 'exit
  3801. (if org-agenda-sticky
  3802. (setq org-agenda-buffer-name
  3803. (if (stringp string)
  3804. (format "*Org Agenda(%s:%s)*"
  3805. (or org-keys (or (and todo-only "S") "s")) string)
  3806. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3807. (org-agenda-prepare "SEARCH")
  3808. (org-compile-prefix-format 'search)
  3809. (org-set-sorting-strategy 'search)
  3810. (setq org-agenda-redo-command
  3811. (list 'org-search-view (if todo-only t nil)
  3812. (list 'if 'current-prefix-arg nil string)))
  3813. (setq org-agenda-query-string string)
  3814. (if (equal (string-to-char string) ?*)
  3815. (setq hdl-only t
  3816. words (substring string 1))
  3817. (setq words string))
  3818. (when (equal (string-to-char words) ?!)
  3819. (setq todo-only t
  3820. words (substring words 1)))
  3821. (when (equal (string-to-char words) ?:)
  3822. (setq full-words t
  3823. words (substring words 1)))
  3824. (if (or org-agenda-search-view-always-boolean
  3825. (member (string-to-char words) '(?- ?+ ?\{)))
  3826. (setq boolean t))
  3827. (setq words (org-split-string words))
  3828. (let (www w)
  3829. (while (setq w (pop words))
  3830. (while (and (string-match "\\\\\\'" w) words)
  3831. (setq w (concat (substring w 0 -1) " " (pop words))))
  3832. (push w www))
  3833. (setq words (nreverse www) www nil)
  3834. (while (setq w (pop words))
  3835. (when (and (string-match "\\`[-+]?{" w)
  3836. (not (string-match "}\\'" w)))
  3837. (while (and words (not (string-match "}\\'" (car words))))
  3838. (setq w (concat w " " (pop words))))
  3839. (setq w (concat w " " (pop words))))
  3840. (push w www))
  3841. (setq words (nreverse www)))
  3842. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3843. (when boolean
  3844. (let (wds w)
  3845. (while (setq w (pop words))
  3846. (if (or (equal (substring w 0 1) "\"")
  3847. (and (> (length w) 1)
  3848. (member (substring w 0 1) '("+" "-"))
  3849. (equal (substring w 1 2) "\"")))
  3850. (while (and words (not (equal (substring w -1) "\"")))
  3851. (setq w (concat w " " (pop words)))))
  3852. (and (string-match "\\`\\([-+]?\\)\"" w)
  3853. (setq w (replace-match "\\1" nil nil w)))
  3854. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3855. (push w wds))
  3856. (setq words (nreverse wds))))
  3857. (if boolean
  3858. (mapc (lambda (w)
  3859. (setq c (string-to-char w))
  3860. (if (equal c ?-)
  3861. (setq neg t w (substring w 1))
  3862. (if (equal c ?+)
  3863. (setq neg nil w (substring w 1))
  3864. (setq neg nil)))
  3865. (if (string-match "\\`{.*}\\'" w)
  3866. (setq re (substring w 1 -1))
  3867. (if full-words
  3868. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3869. (setq re (regexp-quote (downcase w)))))
  3870. (if neg (push re regexps-) (push re regexps+)))
  3871. words)
  3872. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3873. regexps+))
  3874. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3875. (if (not regexps+)
  3876. (setq regexp org-outline-regexp-bol)
  3877. (setq regexp (pop regexps+))
  3878. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3879. regexp))))
  3880. (setq files (org-agenda-files nil 'ifmode))
  3881. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3882. (pop org-agenda-text-search-extra-files)
  3883. (setq files (org-add-archive-files files)))
  3884. (setq files (append files org-agenda-text-search-extra-files)
  3885. rtnall nil)
  3886. (while (setq file (pop files))
  3887. (setq ee nil)
  3888. (catch 'nextfile
  3889. (org-check-agenda-file file)
  3890. (setq buffer (if (file-exists-p file)
  3891. (org-get-agenda-file-buffer file)
  3892. (error "No such file %s" file)))
  3893. (if (not buffer)
  3894. ;; If file does not exist, make sure an error message is sent
  3895. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3896. file))))
  3897. (with-current-buffer buffer
  3898. (with-syntax-table (org-search-syntax-table)
  3899. (unless (derived-mode-p 'org-mode)
  3900. (error "Agenda file %s is not in `org-mode'" file))
  3901. (let ((case-fold-search t))
  3902. (save-excursion
  3903. (save-restriction
  3904. (if org-agenda-restrict
  3905. (narrow-to-region org-agenda-restrict-begin
  3906. org-agenda-restrict-end)
  3907. (widen))
  3908. (goto-char (point-min))
  3909. (unless (or (org-at-heading-p)
  3910. (outline-next-heading))
  3911. (throw 'nextfile t))
  3912. (goto-char (max (point-min) (1- (point))))
  3913. (while (re-search-forward regexp nil t)
  3914. (org-back-to-heading t)
  3915. (skip-chars-forward "* ")
  3916. (setq beg (point-at-bol)
  3917. beg1 (point)
  3918. end (progn (outline-next-heading) (point)))
  3919. (catch :skip
  3920. (goto-char beg)
  3921. (org-agenda-skip)
  3922. (setq str (buffer-substring-no-properties
  3923. (point-at-bol)
  3924. (if hdl-only (point-at-eol) end)))
  3925. (mapc (lambda (wr) (when (string-match wr str)
  3926. (goto-char (1- end))
  3927. (throw :skip t)))
  3928. regexps-)
  3929. (mapc (lambda (wr) (unless (string-match wr str)
  3930. (goto-char (1- end))
  3931. (throw :skip t)))
  3932. (if todo-only
  3933. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3934. regexps+)
  3935. regexps+))
  3936. (goto-char beg)
  3937. (setq marker (org-agenda-new-marker (point))
  3938. category (org-get-category)
  3939. category-pos (get-text-property (point) 'org-category-position)
  3940. tags (org-get-tags-at (point))
  3941. txt (org-agenda-format-item
  3942. ""
  3943. (buffer-substring-no-properties
  3944. beg1 (point-at-eol))
  3945. category tags))
  3946. (org-add-props txt props
  3947. 'org-marker marker 'org-hd-marker marker
  3948. 'org-todo-regexp org-todo-regexp
  3949. 'org-complex-heading-regexp org-complex-heading-regexp
  3950. 'priority 1000 'org-category category
  3951. 'org-category-position category-pos
  3952. 'type "search")
  3953. (push txt ee)
  3954. (goto-char (1- end))))))))))
  3955. (setq rtn (nreverse ee))
  3956. (setq rtnall (append rtnall rtn)))
  3957. (if org-agenda-overriding-header
  3958. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3959. nil 'face 'org-agenda-structure) "\n")
  3960. (insert "Search words: ")
  3961. (add-text-properties (point-min) (1- (point))
  3962. (list 'face 'org-agenda-structure))
  3963. (setq pos (point))
  3964. (insert string "\n")
  3965. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3966. (setq pos (point))
  3967. (unless org-agenda-multi
  3968. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3969. (add-text-properties pos (1- (point))
  3970. (list 'face 'org-agenda-structure))))
  3971. (org-agenda-mark-header-line (point-min))
  3972. (when rtnall
  3973. (insert (org-agenda-finalize-entries rtnall) "\n"))
  3974. (goto-char (point-min))
  3975. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3976. (add-text-properties (point-min) (point-max)
  3977. `(org-agenda-type search
  3978. org-last-args (,todo-only ,string ,edit-at)
  3979. org-redo-cmd ,org-agenda-redo-command
  3980. org-serie-cmd ,org-cmd))
  3981. (org-agenda-finalize)
  3982. (setq buffer-read-only t))))
  3983. ;;; Agenda TODO list
  3984. (defvar org-select-this-todo-keyword nil)
  3985. (defvar org-last-arg nil)
  3986. ;;;###autoload
  3987. (defun org-todo-list (&optional arg)
  3988. "Show all (not done) TODO entries from all agenda file in a single list.
  3989. The prefix arg can be used to select a specific TODO keyword and limit
  3990. the list to these. When using \\[universal-argument], you will be prompted
  3991. for a keyword. A numeric prefix directly selects the Nth keyword in
  3992. `org-todo-keywords-1'."
  3993. (interactive "P")
  3994. (if org-agenda-overriding-arguments
  3995. (setq arg org-agenda-overriding-arguments))
  3996. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3997. (let* ((today (org-today))
  3998. (date (calendar-gregorian-from-absolute today))
  3999. (kwds org-todo-keywords-for-agenda)
  4000. (completion-ignore-case t)
  4001. (org-select-this-todo-keyword
  4002. (if (stringp arg) arg
  4003. (and arg (integerp arg) (> arg 0)
  4004. (nth (1- arg) kwds))))
  4005. rtn rtnall files file pos)
  4006. (when (equal arg '(4))
  4007. (setq org-select-this-todo-keyword
  4008. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4009. (mapcar 'list kwds) nil nil)))
  4010. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4011. (catch 'exit
  4012. (if org-agenda-sticky
  4013. (setq org-agenda-buffer-name
  4014. (if (stringp org-select-this-todo-keyword)
  4015. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4016. org-select-this-todo-keyword)
  4017. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4018. (org-agenda-prepare "TODO")
  4019. (org-compile-prefix-format 'todo)
  4020. (org-set-sorting-strategy 'todo)
  4021. (setq org-agenda-redo-command
  4022. `(org-todo-list (or current-prefix-arg (quote ,arg))))
  4023. (setq files (org-agenda-files nil 'ifmode)
  4024. rtnall nil)
  4025. (while (setq file (pop files))
  4026. (catch 'nextfile
  4027. (org-check-agenda-file file)
  4028. (setq rtn (org-agenda-get-day-entries file date :todo))
  4029. (setq rtnall (append rtnall rtn))))
  4030. (if org-agenda-overriding-header
  4031. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4032. nil 'face 'org-agenda-structure) "\n")
  4033. (insert "Global list of TODO items of type: ")
  4034. (add-text-properties (point-min) (1- (point))
  4035. (list 'face 'org-agenda-structure
  4036. 'short-heading
  4037. (concat "ToDo: "
  4038. (or org-select-this-todo-keyword "ALL"))))
  4039. (org-agenda-mark-header-line (point-min))
  4040. (setq pos (point))
  4041. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4042. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4043. (setq pos (point))
  4044. (unless org-agenda-multi
  4045. (insert "Available with `N r': (0)[ALL]")
  4046. (let ((n 0) s)
  4047. (mapc (lambda (x)
  4048. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4049. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4050. (insert "\n "))
  4051. (insert " " s))
  4052. kwds))
  4053. (insert "\n"))
  4054. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4055. (org-agenda-mark-header-line (point-min))
  4056. (when rtnall
  4057. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4058. (goto-char (point-min))
  4059. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4060. (add-text-properties (point-min) (point-max)
  4061. `(org-agenda-type todo
  4062. org-last-args ,arg
  4063. org-redo-cmd ,org-agenda-redo-command
  4064. org-serie-cmd ,org-cmd))
  4065. (org-agenda-finalize)
  4066. (setq buffer-read-only t))))
  4067. ;;; Agenda tags match
  4068. ;;;###autoload
  4069. (defun org-tags-view (&optional todo-only match)
  4070. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4071. The prefix arg TODO-ONLY limits the search to TODO entries."
  4072. (interactive "P")
  4073. (if org-agenda-overriding-arguments
  4074. (setq todo-only (car org-agenda-overriding-arguments)
  4075. match (nth 1 org-agenda-overriding-arguments)))
  4076. (let* ((org-tags-match-list-sublevels
  4077. org-tags-match-list-sublevels)
  4078. (completion-ignore-case t)
  4079. rtn rtnall files file pos matcher
  4080. buffer)
  4081. (when (and (stringp match) (not (string-match "\\S-" match)))
  4082. (setq match nil))
  4083. (setq matcher (org-make-tags-matcher match)
  4084. match (car matcher) matcher (cdr matcher))
  4085. (catch 'exit
  4086. (if org-agenda-sticky
  4087. (setq org-agenda-buffer-name
  4088. (if (stringp match)
  4089. (format "*Org Agenda(%s:%s)*"
  4090. (or org-keys (or (and todo-only "M") "m")) match)
  4091. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4092. (org-agenda-prepare (concat "TAGS " match))
  4093. (org-compile-prefix-format 'tags)
  4094. (org-set-sorting-strategy 'tags)
  4095. (setq org-agenda-query-string match)
  4096. (setq org-agenda-redo-command
  4097. (list 'org-tags-view `(quote ,todo-only)
  4098. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4099. (setq files (org-agenda-files nil 'ifmode)
  4100. rtnall nil)
  4101. (while (setq file (pop files))
  4102. (catch 'nextfile
  4103. (org-check-agenda-file file)
  4104. (setq buffer (if (file-exists-p file)
  4105. (org-get-agenda-file-buffer file)
  4106. (error "No such file %s" file)))
  4107. (if (not buffer)
  4108. ;; If file does not exist, error message to agenda
  4109. (setq rtn (list
  4110. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4111. rtnall (append rtnall rtn))
  4112. (with-current-buffer buffer
  4113. (unless (derived-mode-p 'org-mode)
  4114. (error "Agenda file %s is not in `org-mode'" file))
  4115. (save-excursion
  4116. (save-restriction
  4117. (if org-agenda-restrict
  4118. (narrow-to-region org-agenda-restrict-begin
  4119. org-agenda-restrict-end)
  4120. (widen))
  4121. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4122. (setq rtnall (append rtnall rtn))))))))
  4123. (if org-agenda-overriding-header
  4124. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4125. nil 'face 'org-agenda-structure) "\n")
  4126. (insert "Headlines with TAGS match: ")
  4127. (add-text-properties (point-min) (1- (point))
  4128. (list 'face 'org-agenda-structure
  4129. 'short-heading
  4130. (concat "Match: " match)))
  4131. (setq pos (point))
  4132. (insert match "\n")
  4133. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4134. (setq pos (point))
  4135. (unless org-agenda-multi
  4136. (insert "Press `C-u r' to search again with new search string\n"))
  4137. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4138. (org-agenda-mark-header-line (point-min))
  4139. (when rtnall
  4140. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4141. (goto-char (point-min))
  4142. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4143. (add-text-properties (point-min) (point-max)
  4144. `(org-agenda-type tags
  4145. org-last-args (,todo-only ,match)
  4146. org-redo-cmd ,org-agenda-redo-command
  4147. org-serie-cmd ,org-cmd))
  4148. (org-agenda-finalize)
  4149. (setq buffer-read-only t))))
  4150. ;;; Agenda Finding stuck projects
  4151. (defvar org-agenda-skip-regexp nil
  4152. "Regular expression used in skipping subtrees for the agenda.
  4153. This is basically a temporary global variable that can be set and then
  4154. used by user-defined selections using `org-agenda-skip-function'.")
  4155. (defvar org-agenda-overriding-header nil
  4156. "When set during agenda, todo and tags searches it replaces the header.
  4157. This variable should not be set directly, but custom commands can bind it
  4158. in the options section.")
  4159. (defun org-agenda-skip-entry-when-regexp-matches ()
  4160. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4161. If yes, it returns the end position of this entry, causing agenda commands
  4162. to skip the entry but continuing the search in the subtree. This is a
  4163. function that can be put into `org-agenda-skip-function' for the duration
  4164. of a command."
  4165. (let ((end (save-excursion (org-end-of-subtree t)))
  4166. skip)
  4167. (save-excursion
  4168. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4169. (and skip end)))
  4170. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4171. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4172. If yes, it returns the end position of this tree, causing agenda commands
  4173. to skip this subtree. This is a function that can be put into
  4174. `org-agenda-skip-function' for the duration of a command."
  4175. (let ((end (save-excursion (org-end-of-subtree t)))
  4176. skip)
  4177. (save-excursion
  4178. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4179. (and skip end)))
  4180. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4181. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4182. If yes, it returns the end position of the current entry (NOT the tree),
  4183. causing agenda commands to skip the entry but continuing the search in
  4184. the subtree. This is a function that can be put into
  4185. `org-agenda-skip-function' for the duration of a command. An important
  4186. use of this function is for the stuck project list."
  4187. (let ((end (save-excursion (org-end-of-subtree t)))
  4188. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4189. skip)
  4190. (save-excursion
  4191. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4192. (and skip entry-end)))
  4193. (defun org-agenda-skip-entry-if (&rest conditions)
  4194. "Skip entry if any of CONDITIONS is true.
  4195. See `org-agenda-skip-if' for details."
  4196. (org-agenda-skip-if nil conditions))
  4197. (defun org-agenda-skip-subtree-if (&rest conditions)
  4198. "Skip entry if any of CONDITIONS is true.
  4199. See `org-agenda-skip-if' for details."
  4200. (org-agenda-skip-if t conditions))
  4201. (defun org-agenda-skip-if (subtree conditions)
  4202. "Checks current entity for CONDITIONS.
  4203. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4204. the entry (i.e. the text before the next heading) is checked.
  4205. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4206. from different tests. Valid conditions are:
  4207. scheduled Check if there is a scheduled cookie
  4208. notscheduled Check if there is no scheduled cookie
  4209. deadline Check if there is a deadline
  4210. notdeadline Check if there is no deadline
  4211. timestamp Check if there is a timestamp (also deadline or scheduled)
  4212. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4213. regexp Check if regexp matches
  4214. notregexp Check if regexp does not match.
  4215. todo Check if TODO keyword matches
  4216. nottodo Check if TODO keyword does not match
  4217. The regexp is taken from the conditions list, it must come right after
  4218. the `regexp' or `notregexp' element.
  4219. `todo' and `nottodo' accept as an argument a list of todo
  4220. keywords, which may include \"*\" to match any todo keyword.
  4221. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4222. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4223. Instead of a list, a keyword class may be given. For example:
  4224. (org-agenda-skip-entry-if 'nottodo 'done)
  4225. would skip entries that haven't been marked with any of \"DONE\"
  4226. keywords. Possible classes are: `todo', `done', `any'.
  4227. If any of these conditions is met, this function returns the end point of
  4228. the entity, causing the search to continue from there. This is a function
  4229. that can be put into `org-agenda-skip-function' for the duration of a command."
  4230. (let (beg end m)
  4231. (org-back-to-heading t)
  4232. (setq beg (point)
  4233. end (if subtree
  4234. (progn (org-end-of-subtree t) (point))
  4235. (progn (outline-next-heading) (1- (point)))))
  4236. (goto-char beg)
  4237. (and
  4238. (or
  4239. (and (memq 'scheduled conditions)
  4240. (re-search-forward org-scheduled-time-regexp end t))
  4241. (and (memq 'notscheduled conditions)
  4242. (not (re-search-forward org-scheduled-time-regexp end t)))
  4243. (and (memq 'deadline conditions)
  4244. (re-search-forward org-deadline-time-regexp end t))
  4245. (and (memq 'notdeadline conditions)
  4246. (not (re-search-forward org-deadline-time-regexp end t)))
  4247. (and (memq 'timestamp conditions)
  4248. (re-search-forward org-ts-regexp end t))
  4249. (and (memq 'nottimestamp conditions)
  4250. (not (re-search-forward org-ts-regexp end t)))
  4251. (and (setq m (memq 'regexp conditions))
  4252. (stringp (nth 1 m))
  4253. (re-search-forward (nth 1 m) end t))
  4254. (and (setq m (memq 'notregexp conditions))
  4255. (stringp (nth 1 m))
  4256. (not (re-search-forward (nth 1 m) end t)))
  4257. (and (or
  4258. (setq m (memq 'nottodo conditions))
  4259. (setq m (memq 'todo-unblocked conditions))
  4260. (setq m (memq 'nottodo-unblocked conditions))
  4261. (setq m (memq 'todo conditions)))
  4262. (org-agenda-skip-if-todo m end)))
  4263. end)))
  4264. (defun org-agenda-skip-if-todo (args end)
  4265. "Helper function for `org-agenda-skip-if', do not use it directly.
  4266. ARGS is a list with first element either `todo', `nottodo',
  4267. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4268. a list of TODO keywords, or a state symbol `todo' or `done' or
  4269. `any'."
  4270. (let ((kw (car args))
  4271. (arg (cadr args))
  4272. todo-wds todo-re)
  4273. (setq todo-wds
  4274. (org-uniquify
  4275. (cond
  4276. ((listp arg) ;; list of keywords
  4277. (if (member "*" arg)
  4278. (mapcar 'substring-no-properties org-todo-keywords-1)
  4279. arg))
  4280. ((symbolp arg) ;; keyword class name
  4281. (cond
  4282. ((eq arg 'todo)
  4283. (org-delete-all org-done-keywords
  4284. (mapcar 'substring-no-properties
  4285. org-todo-keywords-1)))
  4286. ((eq arg 'done) org-done-keywords)
  4287. ((eq arg 'any)
  4288. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4289. (setq todo-re
  4290. (concat "^\\*+[ \t]+\\<\\("
  4291. (mapconcat 'identity todo-wds "\\|")
  4292. "\\)\\>"))
  4293. (cond
  4294. ((eq kw 'todo) (re-search-forward todo-re end t))
  4295. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4296. ((eq kw 'todo-unblocked)
  4297. (catch 'unblocked
  4298. (while (re-search-forward todo-re end t)
  4299. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4300. nil))
  4301. ((eq kw 'nottodo-unblocked)
  4302. (catch 'unblocked
  4303. (while (re-search-forward todo-re end t)
  4304. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4305. t))
  4306. )))
  4307. ;;;###autoload
  4308. (defun org-agenda-list-stuck-projects (&rest ignore)
  4309. "Create agenda view for projects that are stuck.
  4310. Stuck projects are project that have no next actions. For the definitions
  4311. of what a project is and how to check if it stuck, customize the variable
  4312. `org-stuck-projects'."
  4313. (interactive)
  4314. (let* ((org-agenda-skip-function
  4315. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4316. ;; We could have used org-agenda-skip-if here.
  4317. (org-agenda-overriding-header
  4318. (or org-agenda-overriding-header "List of stuck projects: "))
  4319. (matcher (nth 0 org-stuck-projects))
  4320. (todo (nth 1 org-stuck-projects))
  4321. (todo-wds (if (member "*" todo)
  4322. (progn
  4323. (org-agenda-prepare-buffers (org-agenda-files
  4324. nil 'ifmode))
  4325. (org-delete-all
  4326. org-done-keywords-for-agenda
  4327. (copy-sequence org-todo-keywords-for-agenda)))
  4328. todo))
  4329. (todo-re (concat "^\\*+[ \t]+\\("
  4330. (mapconcat 'identity todo-wds "\\|")
  4331. "\\)\\>"))
  4332. (tags (nth 2 org-stuck-projects))
  4333. (tags-re (if (member "*" tags)
  4334. (concat org-outline-regexp-bol
  4335. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4336. (if tags
  4337. (concat org-outline-regexp-bol
  4338. ".*:\\("
  4339. (mapconcat 'identity tags "\\|")
  4340. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4341. (gen-re (nth 3 org-stuck-projects))
  4342. (re-list
  4343. (delq nil
  4344. (list
  4345. (if todo todo-re)
  4346. (if tags tags-re)
  4347. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4348. gen-re)))))
  4349. (setq org-agenda-skip-regexp
  4350. (if re-list
  4351. (mapconcat 'identity re-list "\\|")
  4352. (error "No information how to identify unstuck projects")))
  4353. (org-tags-view nil matcher)
  4354. (with-current-buffer org-agenda-buffer-name
  4355. (setq org-agenda-redo-command
  4356. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4357. ;;; Diary integration
  4358. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4359. (defvar diary-list-entries-hook)
  4360. (defvar diary-time-regexp)
  4361. (defun org-get-entries-from-diary (date)
  4362. "Get the (Emacs Calendar) diary entries for DATE."
  4363. (require 'diary-lib)
  4364. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4365. (diary-display-hook '(fancy-diary-display))
  4366. (diary-display-function 'fancy-diary-display)
  4367. (pop-up-frames nil)
  4368. (diary-list-entries-hook
  4369. (cons 'org-diary-default-entry diary-list-entries-hook))
  4370. (diary-file-name-prefix-function nil) ; turn this feature off
  4371. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4372. entries
  4373. (org-disable-agenda-to-diary t))
  4374. (save-excursion
  4375. (save-window-excursion
  4376. (funcall (if (fboundp 'diary-list-entries)
  4377. 'diary-list-entries 'list-diary-entries)
  4378. date 1)))
  4379. (if (not (get-buffer diary-fancy-buffer))
  4380. (setq entries nil)
  4381. (with-current-buffer diary-fancy-buffer
  4382. (setq buffer-read-only nil)
  4383. (if (zerop (buffer-size))
  4384. ;; No entries
  4385. (setq entries nil)
  4386. ;; Omit the date and other unnecessary stuff
  4387. (org-agenda-cleanup-fancy-diary)
  4388. ;; Add prefix to each line and extend the text properties
  4389. (if (zerop (buffer-size))
  4390. (setq entries nil)
  4391. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4392. (setq entries
  4393. (with-temp-buffer
  4394. (insert entries) (goto-char (point-min))
  4395. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4396. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4397. (replace-match (concat "; " (match-string 1)))))
  4398. (buffer-string)))))
  4399. (set-buffer-modified-p nil)
  4400. (kill-buffer diary-fancy-buffer)))
  4401. (when entries
  4402. (setq entries (org-split-string entries "\n"))
  4403. (setq entries
  4404. (mapcar
  4405. (lambda (x)
  4406. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4407. ;; Extend the text properties to the beginning of the line
  4408. (org-add-props x (text-properties-at (1- (length x)) x)
  4409. 'type "diary" 'date date 'face 'org-agenda-diary))
  4410. entries)))))
  4411. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4412. "Hook run when the fancy diary buffer is cleaned up.")
  4413. (defun org-agenda-cleanup-fancy-diary ()
  4414. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4415. This gets rid of the date, the underline under the date, and
  4416. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4417. date. It also removes lines that contain only whitespace."
  4418. (goto-char (point-min))
  4419. (if (looking-at ".*?:[ \t]*")
  4420. (progn
  4421. (replace-match "")
  4422. (re-search-forward "\n=+$" nil t)
  4423. (replace-match "")
  4424. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4425. (re-search-forward "\n=+$" nil t)
  4426. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4427. (goto-char (point-min))
  4428. (while (re-search-forward "^ +\n" nil t)
  4429. (replace-match ""))
  4430. (goto-char (point-min))
  4431. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4432. (replace-match ""))
  4433. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4434. ;; Make sure entries from the diary have the right text properties.
  4435. (eval-after-load "diary-lib"
  4436. '(if (boundp 'diary-modify-entry-list-string-function)
  4437. ;; We can rely on the hook, nothing to do
  4438. nil
  4439. ;; Hook not available, must use advice to make this work
  4440. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4441. "Make the position visible."
  4442. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4443. (stringp string)
  4444. buffer-file-name)
  4445. (setq string (org-modify-diary-entry-string string))))))
  4446. (defun org-modify-diary-entry-string (string)
  4447. "Add text properties to string, allowing org-mode to act on it."
  4448. (org-add-props string nil
  4449. 'mouse-face 'highlight
  4450. 'help-echo (if buffer-file-name
  4451. (format "mouse-2 or RET jump to diary file %s"
  4452. (abbreviate-file-name buffer-file-name))
  4453. "")
  4454. 'org-agenda-diary-link t
  4455. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4456. (defun org-diary-default-entry ()
  4457. "Add a dummy entry to the diary.
  4458. Needed to avoid empty dates which mess up holiday display."
  4459. ;; Catch the error if dealing with the new add-to-diary-alist
  4460. (when org-disable-agenda-to-diary
  4461. (condition-case nil
  4462. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4463. (error
  4464. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4465. (defun org-add-to-diary-list (&rest args)
  4466. (if (fboundp 'diary-add-to-list)
  4467. (apply 'diary-add-to-list args)
  4468. (apply 'add-to-diary-list args)))
  4469. (defvar org-diary-last-run-time nil)
  4470. ;;;###autoload
  4471. (defun org-diary (&rest args)
  4472. "Return diary information from org files.
  4473. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4474. It accesses org files and extracts information from those files to be
  4475. listed in the diary. The function accepts arguments specifying what
  4476. items should be listed. For a list of arguments allowed here, see the
  4477. variable `org-agenda-entry-types'.
  4478. The call in the diary file should look like this:
  4479. &%%(org-diary) ~/path/to/some/orgfile.org
  4480. Use a separate line for each org file to check. Or, if you omit the file name,
  4481. all files listed in `org-agenda-files' will be checked automatically:
  4482. &%%(org-diary)
  4483. If you don't give any arguments (as in the example above), the default
  4484. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4485. So the example above may also be written as
  4486. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4487. The function expects the lisp variables `entry' and `date' to be provided
  4488. by the caller, because this is how the calendar works. Don't use this
  4489. function from a program - use `org-agenda-get-day-entries' instead."
  4490. (when (> (- (org-float-time)
  4491. org-agenda-last-marker-time)
  4492. 5)
  4493. ;; I am not sure if this works with sticky agendas, because the marker
  4494. ;; list is then no longer a global variable.
  4495. (org-agenda-reset-markers))
  4496. ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
  4497. (when (buffer-live-p org-agenda-buffer)
  4498. (org-compile-prefix-format 'agenda))
  4499. (org-set-sorting-strategy 'agenda)
  4500. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4501. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4502. (list entry)
  4503. (org-agenda-files t)))
  4504. (time (org-float-time))
  4505. file rtn results)
  4506. (when (or (not org-diary-last-run-time)
  4507. (> (- time
  4508. org-diary-last-run-time)
  4509. 3))
  4510. (org-agenda-prepare-buffers files))
  4511. (setq org-diary-last-run-time time)
  4512. ;; If this is called during org-agenda, don't return any entries to
  4513. ;; the calendar. Org Agenda will list these entries itself.
  4514. (if org-disable-agenda-to-diary (setq files nil))
  4515. (while (setq file (pop files))
  4516. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4517. (setq results (append results rtn)))
  4518. (if results
  4519. (concat (org-agenda-finalize-entries results) "\n"))))
  4520. ;;; Agenda entry finders
  4521. (defun org-agenda-get-day-entries (file date &rest args)
  4522. "Does the work for `org-diary' and `org-agenda'.
  4523. FILE is the path to a file to be checked for entries. DATE is date like
  4524. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4525. which kind of entries should be extracted. For details about these, see
  4526. the documentation of `org-diary'."
  4527. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4528. (let* ((org-startup-folded nil)
  4529. (org-startup-align-all-tables nil)
  4530. (buffer (if (file-exists-p file)
  4531. (org-get-agenda-file-buffer file)
  4532. (error "No such file %s" file)))
  4533. arg results rtn deadline-results)
  4534. (if (not buffer)
  4535. ;; If file does not exist, make sure an error message ends up in diary
  4536. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4537. (with-current-buffer buffer
  4538. (unless (derived-mode-p 'org-mode)
  4539. (error "Agenda file %s is not in `org-mode'" file))
  4540. (let ((case-fold-search nil))
  4541. (save-excursion
  4542. (save-restriction
  4543. (if org-agenda-restrict
  4544. (narrow-to-region org-agenda-restrict-begin
  4545. org-agenda-restrict-end)
  4546. (widen))
  4547. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4548. (while (setq arg (pop args))
  4549. (cond
  4550. ((and (eq arg :todo)
  4551. (equal date (calendar-gregorian-from-absolute
  4552. (org-today))))
  4553. (setq rtn (org-agenda-get-todos))
  4554. (setq results (append results rtn)))
  4555. ((eq arg :timestamp)
  4556. (setq rtn (org-agenda-get-blocks))
  4557. (setq results (append results rtn))
  4558. (setq rtn (org-agenda-get-timestamps deadline-results))
  4559. (setq results (append results rtn)))
  4560. ((eq arg :sexp)
  4561. (setq rtn (org-agenda-get-sexps))
  4562. (setq results (append results rtn)))
  4563. ((eq arg :scheduled)
  4564. (setq rtn (org-agenda-get-scheduled deadline-results))
  4565. (setq results (append results rtn)))
  4566. ((eq arg :closed)
  4567. (setq rtn (org-agenda-get-progress))
  4568. (setq results (append results rtn)))
  4569. ((eq arg :deadline)
  4570. (setq rtn (org-agenda-get-deadlines))
  4571. (setq deadline-results (copy-sequence rtn))
  4572. (setq results (append results rtn))))))))
  4573. results))))
  4574. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4575. (defun org-agenda-get-todos ()
  4576. "Return the TODO information for agenda display."
  4577. (let* ((props (list 'face nil
  4578. 'done-face 'org-agenda-done
  4579. 'org-not-done-regexp org-not-done-regexp
  4580. 'org-todo-regexp org-todo-regexp
  4581. 'org-complex-heading-regexp org-complex-heading-regexp
  4582. 'mouse-face 'highlight
  4583. 'help-echo
  4584. (format "mouse-2 or RET jump to org file %s"
  4585. (abbreviate-file-name buffer-file-name))))
  4586. (regexp (format org-heading-keyword-regexp-format
  4587. (cond
  4588. ((and org-select-this-todo-keyword
  4589. (equal org-select-this-todo-keyword "*"))
  4590. org-todo-regexp)
  4591. (org-select-this-todo-keyword
  4592. (concat "\\("
  4593. (mapconcat 'identity
  4594. (org-split-string
  4595. org-select-this-todo-keyword
  4596. "|")
  4597. "\\|") "\\)"))
  4598. (t org-not-done-regexp))))
  4599. marker priority category category-pos tags todo-state
  4600. ee txt beg end)
  4601. (goto-char (point-min))
  4602. (while (re-search-forward regexp nil t)
  4603. (catch :skip
  4604. (save-match-data
  4605. (beginning-of-line)
  4606. (org-agenda-skip)
  4607. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4608. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4609. (goto-char (1+ beg))
  4610. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4611. (throw :skip nil)))
  4612. (goto-char (match-beginning 2))
  4613. (setq marker (org-agenda-new-marker (match-beginning 0))
  4614. category (org-get-category)
  4615. category-pos (get-text-property (point) 'org-category-position)
  4616. txt (org-trim
  4617. (buffer-substring (match-beginning 2) (match-end 0)))
  4618. tags (org-get-tags-at (point))
  4619. txt (org-agenda-format-item "" txt category tags)
  4620. priority (1+ (org-get-priority txt))
  4621. todo-state (org-get-todo-state))
  4622. (org-add-props txt props
  4623. 'org-marker marker 'org-hd-marker marker
  4624. 'priority priority 'org-category category
  4625. 'org-category-position category-pos
  4626. 'type "todo" 'todo-state todo-state)
  4627. (push txt ee)
  4628. (if org-agenda-todo-list-sublevels
  4629. (goto-char (match-end 2))
  4630. (org-end-of-subtree 'invisible))))
  4631. (nreverse ee)))
  4632. (defun org-agenda-todo-custom-ignore-p (time n)
  4633. "Check whether timestamp is farther away then n number of days.
  4634. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4635. `org-agenda-todo-ignore-scheduled' or
  4636. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4637. (let ((days (org-days-to-time time)))
  4638. (if (>= n 0)
  4639. (>= days n)
  4640. (<= days n))))
  4641. ;;;###autoload
  4642. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4643. (&optional end)
  4644. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4645. (when (or org-agenda-todo-ignore-with-date
  4646. org-agenda-todo-ignore-scheduled
  4647. org-agenda-todo-ignore-deadlines
  4648. org-agenda-todo-ignore-timestamp)
  4649. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4650. (save-excursion
  4651. (or (and org-agenda-todo-ignore-with-date
  4652. (re-search-forward org-ts-regexp end t))
  4653. (and org-agenda-todo-ignore-scheduled
  4654. (re-search-forward org-scheduled-time-regexp end t)
  4655. (cond
  4656. ((eq org-agenda-todo-ignore-scheduled 'future)
  4657. (> (org-days-to-time (match-string 1)) 0))
  4658. ((eq org-agenda-todo-ignore-scheduled 'past)
  4659. (<= (org-days-to-time (match-string 1)) 0))
  4660. ((numberp org-agenda-todo-ignore-scheduled)
  4661. (org-agenda-todo-custom-ignore-p
  4662. (match-string 1) org-agenda-todo-ignore-scheduled))
  4663. (t)))
  4664. (and org-agenda-todo-ignore-deadlines
  4665. (re-search-forward org-deadline-time-regexp end t)
  4666. (cond
  4667. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4668. ((eq org-agenda-todo-ignore-deadlines 'far)
  4669. (not (org-deadline-close (match-string 1))))
  4670. ((eq org-agenda-todo-ignore-deadlines 'future)
  4671. (> (org-days-to-time (match-string 1)) 0))
  4672. ((eq org-agenda-todo-ignore-deadlines 'past)
  4673. (<= (org-days-to-time (match-string 1)) 0))
  4674. ((numberp org-agenda-todo-ignore-deadlines)
  4675. (org-agenda-todo-custom-ignore-p
  4676. (match-string 1) org-agenda-todo-ignore-deadlines))
  4677. (t (org-deadline-close (match-string 1)))))
  4678. (and org-agenda-todo-ignore-timestamp
  4679. (let ((buffer (current-buffer))
  4680. (regexp
  4681. (concat
  4682. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4683. (start (point)))
  4684. ;; Copy current buffer into a temporary one
  4685. (with-temp-buffer
  4686. (insert-buffer-substring buffer start end)
  4687. (goto-char (point-min))
  4688. ;; Delete SCHEDULED and DEADLINE items
  4689. (while (re-search-forward regexp end t)
  4690. (delete-region (match-beginning 0) (match-end 0)))
  4691. (goto-char (point-min))
  4692. ;; No search for timestamp left
  4693. (when (re-search-forward org-ts-regexp nil t)
  4694. (cond
  4695. ((eq org-agenda-todo-ignore-timestamp 'future)
  4696. (> (org-days-to-time (match-string 1)) 0))
  4697. ((eq org-agenda-todo-ignore-timestamp 'past)
  4698. (<= (org-days-to-time (match-string 1)) 0))
  4699. ((numberp org-agenda-todo-ignore-timestamp)
  4700. (org-agenda-todo-custom-ignore-p
  4701. (match-string 1) org-agenda-todo-ignore-timestamp))
  4702. (t))))))))))
  4703. (defconst org-agenda-no-heading-message
  4704. "No heading for this item in buffer or region.")
  4705. (defun org-agenda-get-timestamps (&optional deadline-results)
  4706. "Return the date stamp information for agenda display."
  4707. (let* ((props (list 'face 'org-agenda-calendar-event
  4708. 'org-not-done-regexp org-not-done-regexp
  4709. 'org-todo-regexp org-todo-regexp
  4710. 'org-complex-heading-regexp org-complex-heading-regexp
  4711. 'mouse-face 'highlight
  4712. 'help-echo
  4713. (format "mouse-2 or RET jump to org file %s"
  4714. (abbreviate-file-name buffer-file-name))))
  4715. (d1 (calendar-absolute-from-gregorian date))
  4716. mm
  4717. (deadline-position-alist
  4718. (mapcar (lambda (a) (and (setq mm (get-text-property
  4719. 0 'org-hd-marker a))
  4720. (cons (marker-position mm) a)))
  4721. deadline-results))
  4722. (remove-re org-ts-regexp)
  4723. (regexp
  4724. (concat
  4725. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4726. (regexp-quote
  4727. (substring
  4728. (format-time-string
  4729. (car org-time-stamp-formats)
  4730. (apply 'encode-time ; DATE bound by calendar
  4731. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4732. 1 11))
  4733. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4734. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4735. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4736. donep tmp priority category category-pos ee txt timestr tags
  4737. b0 b3 e3 head todo-state end-of-match show-all warntime)
  4738. (goto-char (point-min))
  4739. (while (setq end-of-match (re-search-forward regexp nil t))
  4740. (setq b0 (match-beginning 0)
  4741. b3 (match-beginning 3) e3 (match-end 3)
  4742. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4743. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4744. (member todo-state
  4745. org-agenda-repeating-timestamp-show-all)))
  4746. (catch :skip
  4747. (and (org-at-date-range-p) (throw :skip nil))
  4748. (org-agenda-skip)
  4749. (if (and (match-end 1)
  4750. (not (= d1 (org-time-string-to-absolute
  4751. (match-string 1) d1 nil show-all
  4752. (current-buffer) b0))))
  4753. (throw :skip nil))
  4754. (if (and e3
  4755. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4756. (throw :skip nil))
  4757. (setq tmp (buffer-substring (max (point-min)
  4758. (- b0 org-ds-keyword-length))
  4759. b0)
  4760. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4761. inactivep (= (char-after b0) ?\[)
  4762. deadlinep (string-match org-deadline-regexp tmp)
  4763. scheduledp (string-match org-scheduled-regexp tmp)
  4764. closedp (and org-agenda-include-inactive-timestamps
  4765. (string-match org-closed-string tmp))
  4766. clockp (and org-agenda-include-inactive-timestamps
  4767. (or (string-match org-clock-string tmp)
  4768. (string-match "]-+\\'" tmp)))
  4769. warntime (org-entry-get (point) "APPT_WARNTIME")
  4770. donep (member todo-state org-done-keywords))
  4771. (if (or scheduledp deadlinep closedp clockp
  4772. (and donep org-agenda-skip-timestamp-if-done))
  4773. (throw :skip t))
  4774. (if (string-match ">" timestr)
  4775. ;; substring should only run to end of time stamp
  4776. (setq timestr (substring timestr 0 (match-end 0))))
  4777. (setq marker (org-agenda-new-marker b0)
  4778. category (org-get-category b0)
  4779. category-pos (get-text-property b0 'org-category-position))
  4780. (save-excursion
  4781. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4782. (setq txt org-agenda-no-heading-message)
  4783. (goto-char (match-beginning 0))
  4784. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4785. (assoc (point) deadline-position-alist))
  4786. (throw :skip nil))
  4787. (setq hdmarker (org-agenda-new-marker)
  4788. tags (org-get-tags-at))
  4789. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4790. (setq head (or (match-string 1) ""))
  4791. (setq txt (org-agenda-format-item
  4792. (if inactivep org-agenda-inactive-leader nil)
  4793. head category tags timestr
  4794. remove-re)))
  4795. (setq priority (org-get-priority txt))
  4796. (org-add-props txt props
  4797. 'org-marker marker 'org-hd-marker hdmarker)
  4798. (org-add-props txt nil 'priority priority
  4799. 'org-category category 'date date
  4800. 'org-category-position category-pos
  4801. 'todo-state todo-state
  4802. 'warntime warntime
  4803. 'type "timestamp")
  4804. (push txt ee))
  4805. (if org-agenda-skip-additional-timestamps-same-entry
  4806. (outline-next-heading)
  4807. (goto-char end-of-match))))
  4808. (nreverse ee)))
  4809. (defun org-agenda-get-sexps ()
  4810. "Return the sexp information for agenda display."
  4811. (require 'diary-lib)
  4812. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4813. 'mouse-face 'highlight
  4814. 'help-echo
  4815. (format "mouse-2 or RET jump to org file %s"
  4816. (abbreviate-file-name buffer-file-name))))
  4817. (regexp "^&?%%(")
  4818. marker category extra category-pos ee txt tags entry
  4819. result beg b sexp sexp-entry todo-state warntime)
  4820. (goto-char (point-min))
  4821. (while (re-search-forward regexp nil t)
  4822. (catch :skip
  4823. (org-agenda-skip)
  4824. (setq beg (match-beginning 0))
  4825. (goto-char (1- (match-end 0)))
  4826. (setq b (point))
  4827. (forward-sexp 1)
  4828. (setq sexp (buffer-substring b (point)))
  4829. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4830. (org-trim (match-string 1))
  4831. ""))
  4832. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4833. (when result
  4834. (setq marker (org-agenda-new-marker beg)
  4835. category (org-get-category beg)
  4836. category-pos (get-text-property beg 'org-category-position)
  4837. tags (save-excursion (org-backward-heading-same-level 0)
  4838. (org-get-tags-at))
  4839. todo-state (org-get-todo-state)
  4840. warntime (org-entry-get (point) "APPT_WARNTIME"))
  4841. (dolist (r (if (stringp result)
  4842. (list result)
  4843. result)) ;; we expect a list here
  4844. (when (and org-agenda-diary-sexp-prefix
  4845. (string-match org-agenda-diary-sexp-prefix r))
  4846. (setq extra (match-string 0 r)
  4847. r (replace-match "" nil nil r)))
  4848. (if (string-match "\\S-" r)
  4849. (setq txt r)
  4850. (setq txt "SEXP entry returned empty string"))
  4851. (setq txt (org-agenda-format-item
  4852. extra txt category tags 'time))
  4853. (org-add-props txt props 'org-marker marker)
  4854. (org-add-props txt nil
  4855. 'org-category category 'date date 'todo-state todo-state
  4856. 'org-category-position category-pos 'tags tags
  4857. 'type "sexp" 'warntime warntime)
  4858. (push txt ee)))))
  4859. (nreverse ee)))
  4860. ;; Calendar sanity: define some functions that are independent of
  4861. ;; `calendar-date-style'.
  4862. ;; Normally I would like to use ISO format when calling the diary functions,
  4863. ;; but to make sure we still have Emacs 22 compatibility we bind
  4864. ;; also `european-calendar-style' and use european format
  4865. (defun org-anniversary (year month day &optional mark)
  4866. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4867. (org-no-warnings
  4868. (let ((calendar-date-style 'european) (european-calendar-style t))
  4869. (diary-anniversary day month year mark))))
  4870. (defun org-cyclic (N year month day &optional mark)
  4871. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4872. (org-no-warnings
  4873. (let ((calendar-date-style 'european) (european-calendar-style t))
  4874. (diary-cyclic N day month year mark))))
  4875. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4876. "Like `diary-block', but with fixed (ISO) order of arguments."
  4877. (org-no-warnings
  4878. (let ((calendar-date-style 'european) (european-calendar-style t))
  4879. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4880. (defun org-date (year month day &optional mark)
  4881. "Like `diary-date', but with fixed (ISO) order of arguments."
  4882. (org-no-warnings
  4883. (let ((calendar-date-style 'european) (european-calendar-style t))
  4884. (diary-date day month year mark))))
  4885. (defalias 'org-float 'diary-float)
  4886. ;; Define the` org-class' function
  4887. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4888. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4889. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4890. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4891. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4892. `holidays', then any date that is known by the Emacs calendar to be a
  4893. holiday will also be skipped."
  4894. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4895. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4896. (d (calendar-absolute-from-gregorian date)))
  4897. (and
  4898. (<= date1 d)
  4899. (<= d date2)
  4900. (= (calendar-day-of-week date) dayname)
  4901. (or (not skip-weeks)
  4902. (progn
  4903. (require 'cal-iso)
  4904. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4905. (not (and (memq 'holidays skip-weeks)
  4906. (calendar-check-holidays date)))
  4907. entry)))
  4908. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4909. "Like `org-class', but honor `calendar-date-style'.
  4910. The order of the first 2 times 3 arguments depends on the variable
  4911. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4912. So for American calendars, give this as MONTH DAY YEAR, for European as
  4913. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4914. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4915. is any number of ISO weeks in the block period for which the item should
  4916. be skipped.
  4917. This function is here only for backward compatibility and it is deprecated,
  4918. please use `org-class' instead."
  4919. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4920. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4921. (org-class
  4922. (nth 2 date1) (car date1) (nth 1 date1)
  4923. (nth 2 date2) (car date2) (nth 1 date2)
  4924. dayname skip-weeks)))
  4925. (make-obsolete 'org-diary-class 'org-class "")
  4926. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4927. (defalias 'org-get-closed 'org-agenda-get-progress)
  4928. (defun org-agenda-get-progress ()
  4929. "Return the logged TODO entries for agenda display."
  4930. (let* ((props (list 'mouse-face 'highlight
  4931. 'org-not-done-regexp org-not-done-regexp
  4932. 'org-todo-regexp org-todo-regexp
  4933. 'org-complex-heading-regexp org-complex-heading-regexp
  4934. 'help-echo
  4935. (format "mouse-2 or RET jump to org file %s"
  4936. (abbreviate-file-name buffer-file-name))))
  4937. (items (if (consp org-agenda-show-log-scoped)
  4938. org-agenda-show-log-scoped
  4939. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4940. '(clock)
  4941. org-agenda-log-mode-items)))
  4942. (parts
  4943. (delq nil
  4944. (list
  4945. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4946. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4947. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4948. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4949. (error "`org-agenda-log-mode-items' is empty")))
  4950. (regexp (concat
  4951. "\\(" parts-re "\\)"
  4952. " *\\["
  4953. (regexp-quote
  4954. (substring
  4955. (format-time-string
  4956. (car org-time-stamp-formats)
  4957. (apply 'encode-time ; DATE bound by calendar
  4958. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4959. 1 11))))
  4960. (org-agenda-search-headline-for-time nil)
  4961. marker hdmarker priority category category-pos tags closedp
  4962. statep clockp state ee txt extra timestr rest clocked)
  4963. (goto-char (point-min))
  4964. (while (re-search-forward regexp nil t)
  4965. (catch :skip
  4966. (org-agenda-skip)
  4967. (setq marker (org-agenda-new-marker (match-beginning 0))
  4968. closedp (equal (match-string 1) org-closed-string)
  4969. statep (equal (string-to-char (match-string 1)) ?-)
  4970. clockp (not (or closedp statep))
  4971. state (and statep (match-string 2))
  4972. category (org-get-category (match-beginning 0))
  4973. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4974. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4975. (when (string-match "\\]" timestr)
  4976. ;; substring should only run to end of time stamp
  4977. (setq rest (substring timestr (match-end 0))
  4978. timestr (substring timestr 0 (match-end 0)))
  4979. (if (and (not closedp) (not statep)
  4980. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4981. rest))
  4982. (progn (setq timestr (concat (substring timestr 0 -1)
  4983. "-" (match-string 1 rest) "]"))
  4984. (setq clocked (match-string 2 rest)))
  4985. (setq clocked "-")))
  4986. (save-excursion
  4987. (setq extra
  4988. (cond
  4989. ((not org-agenda-log-mode-add-notes) nil)
  4990. (statep
  4991. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4992. (match-string 1)))
  4993. (clockp
  4994. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4995. (match-string 1)))))
  4996. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4997. (setq txt org-agenda-no-heading-message)
  4998. (goto-char (match-beginning 0))
  4999. (setq hdmarker (org-agenda-new-marker)
  5000. tags (org-get-tags-at))
  5001. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5002. (setq txt (match-string 1))
  5003. (when extra
  5004. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5005. (setq txt (concat (substring txt 0 (match-beginning 1))
  5006. " - " extra " " (match-string 2 txt)))
  5007. (setq txt (concat txt " - " extra))))
  5008. (setq txt (org-agenda-format-item
  5009. (cond
  5010. (closedp "Closed: ")
  5011. (statep (concat "State: (" state ")"))
  5012. (t (concat "Clocked: (" clocked ")")))
  5013. txt category tags timestr)))
  5014. (setq priority 100000)
  5015. (org-add-props txt props
  5016. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5017. 'priority priority 'org-category category
  5018. 'org-category-position category-pos
  5019. 'type "closed" 'date date
  5020. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5021. (push txt ee))
  5022. (goto-char (point-at-eol))))
  5023. (nreverse ee)))
  5024. (defun org-agenda-show-clocking-issues ()
  5025. "Add overlays, showing issues with clocking.
  5026. See also the user option `org-agenda-clock-consistency-checks'."
  5027. (interactive)
  5028. (let* ((pl org-agenda-clock-consistency-checks)
  5029. (re (concat "^[ \t]*"
  5030. org-clock-string
  5031. "[ \t]+"
  5032. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5033. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5034. (tlstart 0.)
  5035. (tlend 0.)
  5036. (maxtime (org-hh:mm-string-to-minutes
  5037. (or (plist-get pl :max-duration) "24:00")))
  5038. (mintime (org-hh:mm-string-to-minutes
  5039. (or (plist-get pl :min-duration) 0)))
  5040. (maxgap (org-hh:mm-string-to-minutes
  5041. ;; default 30:00 means never complain
  5042. (or (plist-get pl :max-gap) "30:00")))
  5043. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5044. (plist-get pl :gap-ok-around)))
  5045. (def-face (or (plist-get pl :default-face)
  5046. '((:background "DarkRed") (:foreground "white"))))
  5047. issue face m te ts dt ov)
  5048. (goto-char (point-min))
  5049. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5050. (setq issue nil face def-face)
  5051. (catch 'next
  5052. (setq m (org-get-at-bol 'org-marker)
  5053. te nil ts nil)
  5054. (unless (and m (markerp m))
  5055. (setq issue "No valid clock line") (throw 'next t))
  5056. (org-with-point-at m
  5057. (save-excursion
  5058. (goto-char (point-at-bol))
  5059. (unless (looking-at re)
  5060. (error "No valid Clock line")
  5061. (throw 'next t))
  5062. (unless (match-end 3)
  5063. (setq issue "No end time"
  5064. face (or (plist-get pl :no-end-time-face) face))
  5065. (throw 'next t))
  5066. (setq ts (match-string 1)
  5067. te (match-string 3)
  5068. ts (org-float-time
  5069. (apply 'encode-time (org-parse-time-string ts)))
  5070. te (org-float-time
  5071. (apply 'encode-time (org-parse-time-string te)))
  5072. dt (- te ts))))
  5073. (cond
  5074. ((> dt (* 60 maxtime))
  5075. ;; a very long clocking chunk
  5076. (setq issue (format "Clocking interval is very long: %s"
  5077. (org-minutes-to-hh:mm-string
  5078. (floor (/ (float dt) 60.))))
  5079. face (or (plist-get pl :long-face) face)))
  5080. ((< dt (* 60 mintime))
  5081. ;; a very short clocking chunk
  5082. (setq issue (format "Clocking interval is very short: %s"
  5083. (org-minutes-to-hh:mm-string
  5084. (floor (/ (float dt) 60.))))
  5085. face (or (plist-get pl :short-face) face)))
  5086. ((and (> tlend 0) (< ts tlend))
  5087. ;; Two clock entries are overlapping
  5088. (setq issue (format "Clocking overlap: %d minutes"
  5089. (/ (- tlend ts) 60))
  5090. face (or (plist-get pl :overlap-face) face)))
  5091. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5092. ;; There is a gap, lets see if we need to report it
  5093. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5094. (setq issue (format "Clocking gap: %d minutes"
  5095. (/ (- ts tlend) 60))
  5096. face (or (plist-get pl :gap-face) face))))
  5097. (t nil)))
  5098. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5099. (when issue
  5100. ;; OK, there was some issue, add an overlay to show the issue
  5101. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5102. (overlay-put ov 'before-string
  5103. (concat
  5104. (org-add-props
  5105. (format "%-43s" (concat " " issue))
  5106. nil
  5107. 'face face)
  5108. "\n"))
  5109. (overlay-put ov 'evaporate t)))))
  5110. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5111. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5112. (catch 'exit
  5113. (unless ok-list
  5114. ;; there are no OK times for gaps...
  5115. (throw 'exit nil))
  5116. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5117. ;; This is more than 24 hours, so it is OK.
  5118. ;; because we have at least one OK time, that must be in the
  5119. ;; 24 hour interval.
  5120. (throw 'exit t))
  5121. ;; We have a shorter gap.
  5122. ;; Now we have to get the minute of the day when these times are
  5123. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5124. (t2dec (decode-time (seconds-to-time t2)))
  5125. ;; compute the minute on the day
  5126. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5127. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5128. (when (< min2 min1)
  5129. ;; if min2 is smaller than min1, this means it is on the next day.
  5130. ;; Wrap it to after midnight.
  5131. (setq min2 (+ min2 1440)))
  5132. ;; Now check if any of the OK times is in the gap
  5133. (mapc (lambda (x)
  5134. ;; Wrap the time to after midnight if necessary
  5135. (if (< x min1) (setq x (+ x 1440)))
  5136. ;; Check if in interval
  5137. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5138. ok-list)
  5139. ;; Nope, this gap is not OK
  5140. nil)))
  5141. (defun org-agenda-get-deadlines ()
  5142. "Return the deadline information for agenda display."
  5143. (let* ((props (list 'mouse-face 'highlight
  5144. 'org-not-done-regexp org-not-done-regexp
  5145. 'org-todo-regexp org-todo-regexp
  5146. 'org-complex-heading-regexp org-complex-heading-regexp
  5147. 'help-echo
  5148. (format "mouse-2 or RET jump to org file %s"
  5149. (abbreviate-file-name buffer-file-name))))
  5150. (regexp org-deadline-time-regexp)
  5151. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5152. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5153. d2 diff dfrac wdays pos pos1 category category-pos
  5154. tags suppress-prewarning ee txt head face s todo-state
  5155. show-all upcomingp donep timestr warntime)
  5156. (goto-char (point-min))
  5157. (while (re-search-forward regexp nil t)
  5158. (setq suppress-prewarning nil)
  5159. (catch :skip
  5160. (org-agenda-skip)
  5161. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5162. (save-match-data
  5163. (string-match org-scheduled-time-regexp
  5164. (buffer-substring (point-at-bol)
  5165. (point-at-eol)))))
  5166. (setq suppress-prewarning
  5167. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5168. org-agenda-skip-deadline-prewarning-if-scheduled
  5169. 0)))
  5170. (setq s (match-string 1)
  5171. txt nil
  5172. pos (1- (match-beginning 1))
  5173. todo-state (save-match-data (org-get-todo-state))
  5174. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5175. (member todo-state
  5176. org-agenda-repeating-timestamp-show-all))
  5177. d2 (org-time-string-to-absolute
  5178. (match-string 1) d1 'past show-all
  5179. (current-buffer) pos)
  5180. diff (- d2 d1)
  5181. wdays (if suppress-prewarning
  5182. (let ((org-deadline-warning-days suppress-prewarning))
  5183. (org-get-wdays s))
  5184. (org-get-wdays s))
  5185. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5186. upcomingp (and todayp (> diff 0)))
  5187. ;; When to show a deadline in the calendar:
  5188. ;; If the expiration is within wdays warning time.
  5189. ;; Past-due deadlines are only shown on the current date
  5190. (if (and (or (and (<= diff wdays)
  5191. (and todayp (not org-agenda-only-exact-dates)))
  5192. (= diff 0)))
  5193. (save-excursion
  5194. ;; (setq todo-state (org-get-todo-state))
  5195. (setq donep (member todo-state org-done-keywords))
  5196. (if (and donep
  5197. (or org-agenda-skip-deadline-if-done
  5198. (not (= diff 0))))
  5199. (setq txt nil)
  5200. (setq category (org-get-category)
  5201. warntime (org-entry-get (point) "APPT_WARNTIME")
  5202. category-pos (get-text-property (point) 'org-category-position))
  5203. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5204. (setq txt org-agenda-no-heading-message)
  5205. (goto-char (match-end 0))
  5206. (setq pos1 (match-beginning 0))
  5207. (setq tags (org-get-tags-at pos1))
  5208. (setq head (buffer-substring-no-properties
  5209. (point)
  5210. (progn (skip-chars-forward "^\r\n")
  5211. (point))))
  5212. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5213. (setq timestr
  5214. (concat (substring s (match-beginning 1)) " "))
  5215. (setq timestr 'time))
  5216. (setq txt (org-agenda-format-item
  5217. (if (= diff 0)
  5218. (car org-agenda-deadline-leaders)
  5219. (if (functionp
  5220. (nth 1 org-agenda-deadline-leaders))
  5221. (funcall
  5222. (nth 1 org-agenda-deadline-leaders)
  5223. diff date)
  5224. (format (nth 1 org-agenda-deadline-leaders)
  5225. diff)))
  5226. head category tags
  5227. (if (not (= diff 0)) nil timestr)))))
  5228. (when txt
  5229. (setq face (org-agenda-deadline-face dfrac))
  5230. (org-add-props txt props
  5231. 'org-marker (org-agenda-new-marker pos)
  5232. 'warntime warntime
  5233. 'org-hd-marker (org-agenda-new-marker pos1)
  5234. 'priority (+ (- diff)
  5235. (org-get-priority txt))
  5236. 'org-category category
  5237. 'org-category-position category-pos
  5238. 'todo-state todo-state
  5239. 'type (if upcomingp "upcoming-deadline" "deadline")
  5240. 'date (if upcomingp date d2)
  5241. 'face (if donep 'org-agenda-done face)
  5242. 'undone-face face 'done-face 'org-agenda-done)
  5243. (push txt ee))))))
  5244. (nreverse ee)))
  5245. (defun org-agenda-deadline-face (fraction)
  5246. "Return the face to displaying a deadline item.
  5247. FRACTION is what fraction of the head-warning time has passed."
  5248. (let ((faces org-agenda-deadline-faces) f)
  5249. (catch 'exit
  5250. (while (setq f (pop faces))
  5251. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5252. (defun org-agenda-get-scheduled (&optional deadline-results)
  5253. "Return the scheduled information for agenda display."
  5254. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5255. 'org-todo-regexp org-todo-regexp
  5256. 'org-complex-heading-regexp org-complex-heading-regexp
  5257. 'done-face 'org-agenda-done
  5258. 'mouse-face 'highlight
  5259. 'help-echo
  5260. (format "mouse-2 or RET jump to org file %s"
  5261. (abbreviate-file-name buffer-file-name))))
  5262. (regexp org-scheduled-time-regexp)
  5263. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5264. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5265. mm
  5266. (deadline-position-alist
  5267. (mapcar (lambda (a) (and (setq mm (get-text-property
  5268. 0 'org-hd-marker a))
  5269. (cons (marker-position mm) a)))
  5270. deadline-results))
  5271. d2 diff pos pos1 category category-pos tags donep
  5272. ee txt head pastschedp todo-state face timestr s habitp show-all
  5273. did-habit-check-p warntime)
  5274. (goto-char (point-min))
  5275. (while (re-search-forward regexp nil t)
  5276. (catch :skip
  5277. (org-agenda-skip)
  5278. (setq s (match-string 1)
  5279. txt nil
  5280. pos (1- (match-beginning 1))
  5281. todo-state (save-match-data (org-get-todo-state))
  5282. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5283. (member todo-state
  5284. org-agenda-repeating-timestamp-show-all))
  5285. d2 (org-time-string-to-absolute
  5286. (match-string 1) d1 'past show-all
  5287. (current-buffer) pos)
  5288. diff (- d2 d1)
  5289. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5290. (setq pastschedp (and todayp (< diff 0)))
  5291. (setq did-habit-check-p nil)
  5292. ;; When to show a scheduled item in the calendar:
  5293. ;; If it is on or past the date.
  5294. (when (or (and (< diff 0)
  5295. (< (abs diff) org-scheduled-past-days)
  5296. (and todayp (not org-agenda-only-exact-dates)))
  5297. (= diff 0)
  5298. ;; org-is-habit-p uses org-entry-get, which is expansive
  5299. ;; so we go extra mile to only call it once
  5300. (and todayp
  5301. org-habit-show-all-today
  5302. (setq did-habit-check-p t)
  5303. (setq habitp (and (functionp 'org-is-habit-p)
  5304. (org-is-habit-p)))))
  5305. (save-excursion
  5306. (setq donep (member todo-state org-done-keywords))
  5307. (if (and donep
  5308. (or org-agenda-skip-scheduled-if-done
  5309. (not (= diff 0))
  5310. (and (functionp 'org-is-habit-p)
  5311. (org-is-habit-p))))
  5312. (setq txt nil)
  5313. (setq habitp (if did-habit-check-p habitp
  5314. (and (functionp 'org-is-habit-p)
  5315. (org-is-habit-p))))
  5316. (setq category (org-get-category)
  5317. category-pos (get-text-property (point) 'org-category-position))
  5318. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5319. (setq txt org-agenda-no-heading-message)
  5320. (goto-char (match-end 0))
  5321. (setq pos1 (match-beginning 0))
  5322. (if habitp
  5323. (if (or (not org-habit-show-habits)
  5324. (and (not todayp)
  5325. org-habit-show-habits-only-for-today))
  5326. (throw :skip nil))
  5327. (if (and
  5328. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5329. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5330. pastschedp))
  5331. (setq mm (assoc pos1 deadline-position-alist)))
  5332. (throw :skip nil)))
  5333. (setq tags (org-get-tags-at))
  5334. (setq head (buffer-substring-no-properties
  5335. (point)
  5336. (progn (skip-chars-forward "^\r\n") (point))))
  5337. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5338. (setq timestr
  5339. (concat (substring s (match-beginning 1)) " "))
  5340. (setq timestr 'time))
  5341. (setq txt (org-agenda-format-item
  5342. (if (= diff 0)
  5343. (car org-agenda-scheduled-leaders)
  5344. (format (nth 1 org-agenda-scheduled-leaders)
  5345. (- 1 diff)))
  5346. head category tags
  5347. (if (not (= diff 0)) nil timestr)
  5348. nil habitp))))
  5349. (when txt
  5350. (setq face
  5351. (cond
  5352. ((and (not habitp) pastschedp)
  5353. 'org-scheduled-previously)
  5354. (todayp 'org-scheduled-today)
  5355. (t 'org-scheduled))
  5356. habitp (and habitp (org-habit-parse-todo)))
  5357. (org-add-props txt props
  5358. 'undone-face face
  5359. 'face (if donep 'org-agenda-done face)
  5360. 'org-marker (org-agenda-new-marker pos)
  5361. 'org-hd-marker (org-agenda-new-marker pos1)
  5362. 'type (if pastschedp "past-scheduled" "scheduled")
  5363. 'date (if pastschedp d2 date)
  5364. 'warntime warntime
  5365. 'priority (if habitp
  5366. (org-habit-get-priority habitp)
  5367. (+ 94 (- 5 diff) (org-get-priority txt)))
  5368. 'org-category category
  5369. 'category-position category-pos
  5370. 'org-habit-p habitp
  5371. 'todo-state todo-state)
  5372. (push txt ee))))))
  5373. (nreverse ee)))
  5374. (defun org-agenda-get-blocks ()
  5375. "Return the date-range information for agenda display."
  5376. (let* ((props (list 'face nil
  5377. 'org-not-done-regexp org-not-done-regexp
  5378. 'org-todo-regexp org-todo-regexp
  5379. 'org-complex-heading-regexp org-complex-heading-regexp
  5380. 'mouse-face 'highlight
  5381. 'help-echo
  5382. (format "mouse-2 or RET jump to org file %s"
  5383. (abbreviate-file-name buffer-file-name))))
  5384. (regexp org-tr-regexp)
  5385. (d0 (calendar-absolute-from-gregorian date))
  5386. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5387. todo-state tags pos head donep)
  5388. (goto-char (point-min))
  5389. (while (re-search-forward regexp nil t)
  5390. (catch :skip
  5391. (org-agenda-skip)
  5392. (setq pos (point))
  5393. (let ((start-time (match-string 1))
  5394. (end-time (match-string 2)))
  5395. (setq s1 (match-string 1)
  5396. s2 (match-string 2)
  5397. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5398. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5399. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5400. ;; Only allow days between the limits, because the normal
  5401. ;; date stamps will catch the limits.
  5402. (save-excursion
  5403. (setq todo-state (org-get-todo-state))
  5404. (setq donep (member todo-state org-done-keywords))
  5405. (if (and donep org-agenda-skip-timestamp-if-done)
  5406. (throw :skip t))
  5407. (setq marker (org-agenda-new-marker (point)))
  5408. (setq category (org-get-category)
  5409. category-pos (get-text-property (point) 'org-category-position))
  5410. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5411. (setq txt org-agenda-no-heading-message)
  5412. (goto-char (match-beginning 0))
  5413. (setq hdmarker (org-agenda-new-marker (point)))
  5414. (setq tags (org-get-tags-at))
  5415. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5416. (setq head (match-string 1))
  5417. (let ((remove-re
  5418. (if org-agenda-remove-timeranges-from-blocks
  5419. (concat
  5420. "<" (regexp-quote s1) ".*?>"
  5421. "--"
  5422. "<" (regexp-quote s2) ".*?>")
  5423. nil)))
  5424. (setq txt (org-agenda-format-item
  5425. (format
  5426. (nth (if (= d1 d2) 0 1)
  5427. org-agenda-timerange-leaders)
  5428. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5429. head category tags
  5430. (cond ((and (= d1 d0) (= d2 d0))
  5431. (concat "<" start-time ">--<" end-time ">"))
  5432. ((= d1 d0)
  5433. (concat "<" start-time ">"))
  5434. ((= d2 d0)
  5435. (concat "<" end-time ">")))
  5436. remove-re))))
  5437. (org-add-props txt props
  5438. 'org-marker marker 'org-hd-marker hdmarker
  5439. 'type "block" 'date date
  5440. 'todo-state todo-state
  5441. 'priority (org-get-priority txt) 'org-category category
  5442. 'org-category-position category-pos)
  5443. (push txt ee))))
  5444. (goto-char pos)))
  5445. ;; Sort the entries by expiration date.
  5446. (nreverse ee)))
  5447. ;;; Agenda presentation and sorting
  5448. (defvar org-prefix-has-time nil
  5449. "A flag, set by `org-compile-prefix-format'.
  5450. The flag is set if the currently compiled format contains a `%t'.")
  5451. (defvar org-prefix-has-tag nil
  5452. "A flag, set by `org-compile-prefix-format'.
  5453. The flag is set if the currently compiled format contains a `%T'.")
  5454. (defvar org-prefix-has-effort nil
  5455. "A flag, set by `org-compile-prefix-format'.
  5456. The flag is set if the currently compiled format contains a `%e'.")
  5457. (defvar org-prefix-category-length nil
  5458. "Used by `org-compile-prefix-format' to remember the category field width.")
  5459. (defvar org-prefix-category-max-length nil
  5460. "Used by `org-compile-prefix-format' to remember the category field width.")
  5461. (defun org-agenda-get-category-icon (category)
  5462. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5463. (dolist (entry org-agenda-category-icon-alist)
  5464. (when (org-string-match-p (car entry) category)
  5465. (if (listp (cadr entry))
  5466. (return (cadr entry))
  5467. (return (apply 'create-image (cdr entry)))))))
  5468. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5469. remove-re habitp)
  5470. "Format TXT to be inserted into the agenda buffer.
  5471. In particular, it adds the prefix and corresponding text properties. EXTRA
  5472. must be a string and replaces the `%s' specifier in the prefix format.
  5473. CATEGORY (string, symbol or nil) may be used to overrule the default
  5474. category taken from local variable or file name. It will replace the `%c'
  5475. specifier in the format. DOTIME, when non-nil, indicates that a
  5476. time-of-day should be extracted from TXT for sorting of this entry, and for
  5477. the `%t' specifier in the format. When DOTIME is a string, this string is
  5478. searched for a time before TXT is. TAGS can be the tags of the headline.
  5479. Any match of REMOVE-RE will be removed from TXT."
  5480. ;; We keep the org-prefix-* variable values along with a compiled
  5481. ;; formatter, so that multiple agendas existing at the same time, do
  5482. ;; not step on each other toes.
  5483. ;;
  5484. ;; It was inconvenient to make these variables buffer local in
  5485. ;; Agenda buffers, because this function expects to be called with
  5486. ;; the buffer where item comes from being current, and not agenda
  5487. ;; buffer
  5488. (let* ((bindings (car org-prefix-format-compiled))
  5489. (formatter (cadr org-prefix-format-compiled)))
  5490. (loop for (var value) in bindings
  5491. do (set var value))
  5492. (save-match-data
  5493. ;; Diary entries sometimes have extra whitespace at the beginning
  5494. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5495. ;; Fix the tags part in txt
  5496. (setq txt (org-agenda-fix-displayed-tags
  5497. txt tags
  5498. org-agenda-show-inherited-tags
  5499. org-agenda-hide-tags-regexp))
  5500. (let* ((category (or category
  5501. (if (stringp org-category)
  5502. org-category
  5503. (and org-category (symbol-name org-category)))
  5504. (if buffer-file-name
  5505. (file-name-sans-extension
  5506. (file-name-nondirectory buffer-file-name))
  5507. "")))
  5508. (category-icon (org-agenda-get-category-icon category))
  5509. (category-icon (if category-icon
  5510. (propertize " " 'display category-icon)
  5511. ""))
  5512. ;; time, tag, effort are needed for the eval of the prefix format
  5513. (tag (if tags (nth (1- (length tags)) tags) ""))
  5514. time effort neffort
  5515. (ts (if dotime (concat
  5516. (if (stringp dotime) dotime "")
  5517. (and org-agenda-search-headline-for-time txt))))
  5518. (time-of-day (and dotime (org-get-time-of-day ts)))
  5519. stamp plain s0 s1 s2 rtn srp l
  5520. duration thecategory)
  5521. (and (derived-mode-p 'org-mode) buffer-file-name
  5522. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5523. (when (and dotime time-of-day)
  5524. ;; Extract starting and ending time and move them to prefix
  5525. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5526. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5527. (setq s0 (match-string 0 ts)
  5528. srp (and stamp (match-end 3))
  5529. s1 (match-string (if plain 1 2) ts)
  5530. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5531. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5532. ;; them, we might want to remove them there to avoid duplication.
  5533. ;; The user can turn this off with a variable.
  5534. (if (and org-prefix-has-time
  5535. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5536. (string-match (concat (regexp-quote s0) " *") txt)
  5537. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5538. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5539. (= (match-beginning 0) 0)
  5540. t))
  5541. (setq txt (replace-match "" nil nil txt))))
  5542. ;; Normalize the time(s) to 24 hour
  5543. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5544. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5545. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5546. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5547. (setq s2
  5548. (org-minutes-to-hh:mm-string
  5549. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5550. ;; Compute the duration
  5551. (when s2
  5552. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5553. (org-hh:mm-string-to-minutes s1)))))
  5554. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5555. txt)
  5556. ;; Tags are in the string
  5557. (if (or (eq org-agenda-remove-tags t)
  5558. (and org-agenda-remove-tags
  5559. org-prefix-has-tag))
  5560. (setq txt (replace-match "" t t txt))
  5561. (setq txt (replace-match
  5562. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5563. (match-string 2 txt))
  5564. t t txt))))
  5565. (when (derived-mode-p 'org-mode)
  5566. (setq effort
  5567. (condition-case nil
  5568. (org-get-effort
  5569. (or (get-text-property 0 'org-hd-marker txt)
  5570. (get-text-property 0 'org-marker txt)))
  5571. (error nil)))
  5572. (when effort
  5573. (setq neffort (org-duration-string-to-minutes effort)
  5574. effort (setq effort (concat "[" effort "]")))))
  5575. ;; prevent erroring out with %e format when there is no effort
  5576. (or effort (setq effort ""))
  5577. (when remove-re
  5578. (while (string-match remove-re txt)
  5579. (setq txt (replace-match "" t t txt))))
  5580. ;; Set org-heading property on `txt' to mark the start of the
  5581. ;; heading.
  5582. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5583. ;; Prepare the variables needed in the eval of the compiled format
  5584. (setq time (cond (s2 (concat
  5585. (org-agenda-time-of-day-to-ampm-maybe s1)
  5586. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5587. (if org-agenda-timegrid-use-ampm " ")))
  5588. (s1 (concat
  5589. (org-agenda-time-of-day-to-ampm-maybe s1)
  5590. (if org-agenda-timegrid-use-ampm
  5591. "........ "
  5592. "......")))
  5593. (t ""))
  5594. extra (or (and (not habitp) extra) "")
  5595. category (if (symbolp category) (symbol-name category) category)
  5596. thecategory (copy-sequence category))
  5597. (if (string-match org-bracket-link-regexp category)
  5598. (progn
  5599. (setq l (if (match-end 3)
  5600. (- (match-end 3) (match-beginning 3))
  5601. (- (match-end 1) (match-beginning 1))))
  5602. (when (< l (or org-prefix-category-length 0))
  5603. (setq category (copy-sequence category))
  5604. (org-add-props category nil
  5605. 'extra-space (make-string
  5606. (- org-prefix-category-length l 1) ?\ ))))
  5607. (if (and org-prefix-category-max-length
  5608. (>= (length category) org-prefix-category-max-length))
  5609. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5610. ;; Evaluate the compiled format
  5611. (setq rtn (concat (eval formatter) txt))
  5612. ;; And finally add the text properties
  5613. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5614. (org-add-props rtn nil
  5615. 'org-category (if thecategory (downcase thecategory) category)
  5616. 'tags (mapcar 'org-downcase-keep-props tags)
  5617. 'org-highest-priority org-highest-priority
  5618. 'org-lowest-priority org-lowest-priority
  5619. 'time-of-day time-of-day
  5620. 'duration duration
  5621. 'effort effort
  5622. 'effort-minutes neffort
  5623. 'txt txt
  5624. 'time time
  5625. 'extra extra
  5626. 'format org-prefix-format-compiled
  5627. 'dotime dotime)))))
  5628. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5629. "Remove tags string from TXT, and add a modified list of tags.
  5630. The modified list may contain inherited tags, and tags matched by
  5631. `org-agenda-hide-tags-regexp' will be removed."
  5632. (when (or add-inherited hide-re)
  5633. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5634. (setq txt (substring txt 0 (match-beginning 0))))
  5635. (setq tags
  5636. (delq nil
  5637. (mapcar (lambda (tg)
  5638. (if (or (and hide-re (string-match hide-re tg))
  5639. (and (not add-inherited)
  5640. (get-text-property 0 'inherited tg)))
  5641. nil
  5642. tg))
  5643. tags)))
  5644. (when tags
  5645. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5646. i)
  5647. (setq txt (concat txt " :"
  5648. (mapconcat
  5649. (lambda (x)
  5650. (setq i (get-text-property 0 'inherited x))
  5651. (if (and have-i (not i))
  5652. (progn
  5653. (setq have-i nil)
  5654. (concat ":" x))
  5655. x))
  5656. tags ":")
  5657. (if have-i "::" ":"))))))
  5658. txt)
  5659. (defun org-downcase-keep-props (s)
  5660. (let ((props (text-properties-at 0 s)))
  5661. (setq s (downcase s))
  5662. (add-text-properties 0 (length s) props s)
  5663. s))
  5664. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5665. (defvar org-agenda-sorting-strategy-selected nil)
  5666. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5667. (catch 'exit
  5668. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5669. ((and todayp (member 'today (car org-agenda-time-grid))))
  5670. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5671. ((member 'weekly (car org-agenda-time-grid)))
  5672. (t (throw 'exit list)))
  5673. (let* ((have (delq nil (mapcar
  5674. (lambda (x) (get-text-property 1 'time-of-day x))
  5675. list)))
  5676. (string (nth 1 org-agenda-time-grid))
  5677. (gridtimes (nth 2 org-agenda-time-grid))
  5678. (req (car org-agenda-time-grid))
  5679. (remove (member 'remove-match req))
  5680. new time)
  5681. (if (and (member 'require-timed req) (not have))
  5682. ;; don't show empty grid
  5683. (throw 'exit list))
  5684. (while (setq time (pop gridtimes))
  5685. (unless (and remove (member time have))
  5686. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5687. (push (org-agenda-format-item
  5688. nil string "" nil
  5689. (concat (substring time 0 -2) ":" (substring time -2)))
  5690. new)
  5691. (put-text-property
  5692. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5693. (when (and todayp org-agenda-show-current-time-in-grid)
  5694. (push (org-agenda-format-item
  5695. nil
  5696. org-agenda-current-time-string
  5697. "" nil
  5698. (format-time-string "%H:%M "))
  5699. new)
  5700. (put-text-property
  5701. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5702. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5703. (append new list)
  5704. (append list new)))))
  5705. (defun org-compile-prefix-format (key)
  5706. "Compile the prefix format into a Lisp form that can be evaluated.
  5707. The resulting form and associated variable bindings is returned
  5708. and stored in the variable `org-prefix-format-compiled'."
  5709. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5710. org-prefix-category-length nil
  5711. org-prefix-has-effort nil)
  5712. (let ((s (cond
  5713. ((stringp org-agenda-prefix-format)
  5714. org-agenda-prefix-format)
  5715. ((assq key org-agenda-prefix-format)
  5716. (cdr (assq key org-agenda-prefix-format)))
  5717. (t " %-12:c%?-12t% s")))
  5718. (start 0)
  5719. varform vars var e c f opt)
  5720. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5721. s start)
  5722. (setq var (or (cdr (assoc (match-string 4 s)
  5723. '(("c" . category) ("t" . time) ("s" . extra)
  5724. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5725. 'eval)
  5726. c (or (match-string 3 s) "")
  5727. opt (match-beginning 1)
  5728. start (1+ (match-beginning 0)))
  5729. (if (equal var 'time) (setq org-prefix-has-time t))
  5730. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5731. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5732. (setq f (concat "%" (match-string 2 s) "s"))
  5733. (when (equal var 'category)
  5734. (setq org-prefix-category-length
  5735. (floor (abs (string-to-number (match-string 2 s)))))
  5736. (setq org-prefix-category-max-length
  5737. (let ((x (match-string 2 s)))
  5738. (save-match-data
  5739. (if (string-match "\\.[0-9]+" x)
  5740. (string-to-number (substring (match-string 0 x) 1)))))))
  5741. (if (eq var 'eval)
  5742. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5743. (if opt
  5744. (setq varform
  5745. `(if (equal "" ,var)
  5746. ""
  5747. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5748. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5749. (setq s (replace-match "%s" t nil s))
  5750. (push varform vars))
  5751. (setq vars (nreverse vars))
  5752. (with-current-buffer org-agenda-buffer
  5753. (setq org-prefix-format-compiled
  5754. (list
  5755. `((org-prefix-has-time ,org-prefix-has-time)
  5756. (org-prefix-has-tag ,org-prefix-has-tag)
  5757. (org-prefix-category-length ,org-prefix-category-length)
  5758. (org-prefix-has-effort ,org-prefix-has-effort))
  5759. `(format ,s ,@vars))))))
  5760. (defun org-set-sorting-strategy (key)
  5761. (if (symbolp (car org-agenda-sorting-strategy))
  5762. ;; the old format
  5763. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5764. (setq org-agenda-sorting-strategy-selected
  5765. (or (cdr (assq key org-agenda-sorting-strategy))
  5766. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5767. '(time-up category-keep priority-down)))))
  5768. (defun org-get-time-of-day (s &optional string mod24)
  5769. "Check string S for a time of day.
  5770. If found, return it as a military time number between 0 and 2400.
  5771. If not found, return nil.
  5772. The optional STRING argument forces conversion into a 5 character wide string
  5773. HH:MM."
  5774. (save-match-data
  5775. (when
  5776. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5777. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5778. (let* ((h (string-to-number (match-string 1 s)))
  5779. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5780. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5781. (am-p (equal ampm "am"))
  5782. (h1 (cond ((not ampm) h)
  5783. ((= h 12) (if am-p 0 12))
  5784. (t (+ h (if am-p 0 12)))))
  5785. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5786. (mod h1 24) h1))
  5787. (t0 (+ (* 100 h2) m))
  5788. (t1 (concat (if (>= h1 24) "+" " ")
  5789. (if (and org-agenda-time-leading-zero
  5790. (< t0 1000)) "0" "")
  5791. (if (< t0 100) "0" "")
  5792. (if (< t0 10) "0" "")
  5793. (int-to-string t0))))
  5794. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5795. (defvar org-agenda-before-sorting-filter-function nil
  5796. "Function to be applied to agenda items prior to sorting.
  5797. Prior to sorting also means just before they are inserted into the agenda.
  5798. To aid sorting, you may revisit the original entries and add more text
  5799. properties which will later be used by the sorting functions.
  5800. The function should take a string argument, an agenda line.
  5801. It has access to the text properties in that line, which contain among
  5802. other things, the property `org-hd-marker' that points to the entry
  5803. where the line comes from. Note that not all lines going into the agenda
  5804. have this property, only most.
  5805. The function should return the modified string. It is probably best
  5806. to ONLY change text properties.
  5807. You can also use this function as a filter, by returning nil for lines
  5808. you don't want to have in the agenda at all. For this application, you
  5809. could bind the variable in the options section of a custom command.")
  5810. (defun org-agenda-finalize-entries (list &optional nosort)
  5811. "Sort and concatenate the agenda items."
  5812. (setq list (mapcar 'org-agenda-highlight-todo list))
  5813. (if nosort
  5814. list
  5815. (when org-agenda-before-sorting-filter-function
  5816. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5817. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5818. (defun org-agenda-highlight-todo (x)
  5819. (let ((org-done-keywords org-done-keywords-for-agenda)
  5820. (case-fold-search nil)
  5821. re)
  5822. (if (eq x 'line)
  5823. (save-excursion
  5824. (beginning-of-line 1)
  5825. (setq re (org-get-at-bol 'org-todo-regexp))
  5826. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5827. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5828. (add-text-properties (match-beginning 0) (match-end 1)
  5829. (list 'face (org-get-todo-face 1)))
  5830. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5831. (delete-region (match-beginning 1) (1- (match-end 0)))
  5832. (goto-char (match-beginning 1))
  5833. (insert (format org-agenda-todo-keyword-format s)))))
  5834. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5835. (setq re (get-text-property 0 'org-todo-regexp x))
  5836. (when (and re
  5837. ;; Test `pl' because if there's no heading content,
  5838. ;; there's no point matching to highlight. Note
  5839. ;; that if we didn't test `pl' first, and there
  5840. ;; happened to be no keyword from `org-todo-regexp'
  5841. ;; on this heading line, then the `equal' comparison
  5842. ;; afterwards would spuriously succeed in the case
  5843. ;; where `pl' is nil -- causing an args-out-of-range
  5844. ;; error when we try to add text properties to text
  5845. ;; that isn't there.
  5846. pl
  5847. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5848. x pl) pl))
  5849. (add-text-properties
  5850. (or (match-end 1) (match-end 0)) (match-end 0)
  5851. (list 'face (org-get-todo-face (match-string 2 x)))
  5852. x)
  5853. (when (match-end 1)
  5854. (setq x (concat (substring x 0 (match-end 1))
  5855. (format org-agenda-todo-keyword-format
  5856. (match-string 2 x))
  5857. (org-add-props " " (text-properties-at 0 x))
  5858. (substring x (match-end 3)))))))
  5859. x)))
  5860. (defsubst org-cmp-priority (a b)
  5861. "Compare the priorities of string A and B."
  5862. (let ((pa (or (get-text-property 1 'priority a) 0))
  5863. (pb (or (get-text-property 1 'priority b) 0)))
  5864. (cond ((> pa pb) +1)
  5865. ((< pa pb) -1))))
  5866. (defsubst org-cmp-effort (a b)
  5867. "Compare the effort values of string A and B."
  5868. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5869. (ea (or (get-text-property 1 'effort-minutes a) def))
  5870. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5871. (cond ((> ea eb) +1)
  5872. ((< ea eb) -1))))
  5873. (defsubst org-cmp-category (a b)
  5874. "Compare the string values of categories of strings A and B."
  5875. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5876. (cb (or (get-text-property 1 'org-category b) "")))
  5877. (cond ((string-lessp ca cb) -1)
  5878. ((string-lessp cb ca) +1))))
  5879. (defsubst org-cmp-todo-state (a b)
  5880. "Compare the todo states of strings A and B."
  5881. (let* ((ma (or (get-text-property 1 'org-marker a)
  5882. (get-text-property 1 'org-hd-marker a)))
  5883. (mb (or (get-text-property 1 'org-marker b)
  5884. (get-text-property 1 'org-hd-marker b)))
  5885. (fa (and ma (marker-buffer ma)))
  5886. (fb (and mb (marker-buffer mb)))
  5887. (todo-kwds
  5888. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5889. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5890. (ta (or (get-text-property 1 'todo-state a) ""))
  5891. (tb (or (get-text-property 1 'todo-state b) ""))
  5892. (la (- (length (member ta todo-kwds))))
  5893. (lb (- (length (member tb todo-kwds))))
  5894. (donepa (member ta org-done-keywords-for-agenda))
  5895. (donepb (member tb org-done-keywords-for-agenda)))
  5896. (cond ((and donepa (not donepb)) -1)
  5897. ((and (not donepa) donepb) +1)
  5898. ((< la lb) -1)
  5899. ((< lb la) +1))))
  5900. (defsubst org-cmp-alpha (a b)
  5901. "Compare the headlines, alphabetically."
  5902. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5903. (plb (text-property-any 0 (length b) 'org-heading t b))
  5904. (ta (and pla (substring a pla)))
  5905. (tb (and plb (substring b plb))))
  5906. (when pla
  5907. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5908. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5909. (setq ta (substring ta (match-end 0))))
  5910. (setq ta (downcase ta)))
  5911. (when plb
  5912. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5913. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5914. (setq tb (substring tb (match-end 0))))
  5915. (setq tb (downcase tb)))
  5916. (cond ((not ta) +1)
  5917. ((not tb) -1)
  5918. ((string-lessp ta tb) -1)
  5919. ((string-lessp tb ta) +1))))
  5920. (defsubst org-cmp-tag (a b)
  5921. "Compare the string values of the first tags of A and B."
  5922. (let ((ta (car (last (get-text-property 1 'tags a))))
  5923. (tb (car (last (get-text-property 1 'tags b)))))
  5924. (cond ((not ta) +1)
  5925. ((not tb) -1)
  5926. ((string-lessp ta tb) -1)
  5927. ((string-lessp tb ta) +1))))
  5928. (defsubst org-cmp-time (a b)
  5929. "Compare the time-of-day values of strings A and B."
  5930. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5931. (ta (or (get-text-property 1 'time-of-day a) def))
  5932. (tb (or (get-text-property 1 'time-of-day b) def)))
  5933. (cond ((< ta tb) -1)
  5934. ((< tb ta) +1))))
  5935. (defsubst org-cmp-habit-p (a b)
  5936. "Compare the todo states of strings A and B."
  5937. (let ((ha (get-text-property 1 'org-habit-p a))
  5938. (hb (get-text-property 1 'org-habit-p b)))
  5939. (cond ((and ha (not hb)) -1)
  5940. ((and (not ha) hb) +1))))
  5941. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5942. (defun org-entries-lessp (a b)
  5943. "Predicate for sorting agenda entries."
  5944. ;; The following variables will be used when the form is evaluated.
  5945. ;; So even though the compiler complains, keep them.
  5946. (let* ((ss org-agenda-sorting-strategy-selected)
  5947. (time-up (and (org-em 'time-up 'time-down ss)
  5948. (org-cmp-time a b)))
  5949. (time-down (if time-up (- time-up) nil))
  5950. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5951. (org-cmp-priority a b)))
  5952. (priority-down (if priority-up (- priority-up) nil))
  5953. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5954. (org-cmp-effort a b)))
  5955. (effort-down (if effort-up (- effort-up) nil))
  5956. (category-up (and (or (org-em 'category-up 'category-down ss)
  5957. (memq 'category-keep ss))
  5958. (org-cmp-category a b)))
  5959. (category-down (if category-up (- category-up) nil))
  5960. (category-keep (if category-up +1 nil))
  5961. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5962. (org-cmp-tag a b)))
  5963. (tag-down (if tag-up (- tag-up) nil))
  5964. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5965. (org-cmp-todo-state a b)))
  5966. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5967. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5968. (org-cmp-habit-p a b)))
  5969. (habit-down (if habit-up (- habit-up) nil))
  5970. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5971. (org-cmp-alpha a b)))
  5972. (alpha-down (if alpha-up (- alpha-up) nil))
  5973. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5974. user-defined-up user-defined-down)
  5975. (if (and need-user-cmp org-agenda-cmp-user-defined
  5976. (functionp org-agenda-cmp-user-defined))
  5977. (setq user-defined-up
  5978. (funcall org-agenda-cmp-user-defined a b)
  5979. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5980. (cdr (assoc
  5981. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5982. '((-1 . t) (1 . nil) (nil . nil))))))
  5983. ;;; Agenda restriction lock
  5984. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5985. "Overlay to mark the headline to which agenda commands are restricted.")
  5986. (overlay-put org-agenda-restriction-lock-overlay
  5987. 'face 'org-agenda-restriction-lock)
  5988. (overlay-put org-agenda-restriction-lock-overlay
  5989. 'help-echo "Agendas are currently limited to this subtree.")
  5990. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5991. (defun org-agenda-set-restriction-lock (&optional type)
  5992. "Set restriction lock for agenda, to current subtree or file.
  5993. Restriction will be the file if TYPE is `file', or if type is the
  5994. universal prefix '(4), or if the cursor is before the first headline
  5995. in the file. Otherwise, restriction will be to the current subtree."
  5996. (interactive "P")
  5997. (and (equal type '(4)) (setq type 'file))
  5998. (setq type (cond
  5999. (type type)
  6000. ((org-at-heading-p) 'subtree)
  6001. ((condition-case nil (org-back-to-heading t) (error nil))
  6002. 'subtree)
  6003. (t 'file)))
  6004. (if (eq type 'subtree)
  6005. (progn
  6006. (setq org-agenda-restrict t)
  6007. (setq org-agenda-overriding-restriction 'subtree)
  6008. (put 'org-agenda-files 'org-restrict
  6009. (list (buffer-file-name (buffer-base-buffer))))
  6010. (org-back-to-heading t)
  6011. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6012. (move-marker org-agenda-restrict-begin (point))
  6013. (move-marker org-agenda-restrict-end
  6014. (save-excursion (org-end-of-subtree t)))
  6015. (message "Locking agenda restriction to subtree"))
  6016. (put 'org-agenda-files 'org-restrict
  6017. (list (buffer-file-name (buffer-base-buffer))))
  6018. (setq org-agenda-restrict nil)
  6019. (setq org-agenda-overriding-restriction 'file)
  6020. (move-marker org-agenda-restrict-begin nil)
  6021. (move-marker org-agenda-restrict-end nil)
  6022. (message "Locking agenda restriction to file"))
  6023. (setq current-prefix-arg nil)
  6024. (org-agenda-maybe-redo))
  6025. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6026. "Remove the agenda restriction lock."
  6027. (interactive "P")
  6028. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6029. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6030. (setq org-agenda-overriding-restriction nil)
  6031. (setq org-agenda-restrict nil)
  6032. (put 'org-agenda-files 'org-restrict nil)
  6033. (move-marker org-agenda-restrict-begin nil)
  6034. (move-marker org-agenda-restrict-end nil)
  6035. (setq current-prefix-arg nil)
  6036. (message "Agenda restriction lock removed")
  6037. (or noupdate (org-agenda-maybe-redo)))
  6038. (defun org-agenda-maybe-redo ()
  6039. "If there is any window showing the agenda view, update it."
  6040. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6041. (w0 (selected-window)))
  6042. (when w
  6043. (select-window w)
  6044. (org-agenda-redo)
  6045. (select-window w0)
  6046. (if org-agenda-overriding-restriction
  6047. (message "Agenda view shifted to new %s restriction"
  6048. org-agenda-overriding-restriction)
  6049. (message "Agenda restriction lock removed")))))
  6050. ;;; Agenda commands
  6051. (defun org-agenda-check-type (error &rest types)
  6052. "Check if agenda buffer is of allowed type.
  6053. If ERROR is non-nil, throw an error, otherwise just return nil."
  6054. (if (not org-agenda-type)
  6055. (error "No Org agenda currently displayed")
  6056. (if (memq org-agenda-type types)
  6057. t
  6058. (if error
  6059. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6060. nil))))
  6061. (defun org-agenda-Quit (&optional arg)
  6062. "Exit agenda by removing the window or the buffer."
  6063. (interactive)
  6064. (if org-agenda-columns-active
  6065. (org-columns-quit)
  6066. (let ((buf (current-buffer)))
  6067. (if (eq org-agenda-window-setup 'other-frame)
  6068. (progn
  6069. (org-agenda-reset-markers)
  6070. (kill-buffer buf)
  6071. (org-columns-remove-overlays)
  6072. (setq org-agenda-archives-mode nil)
  6073. (delete-frame))
  6074. (and (not (eq org-agenda-window-setup 'current-window))
  6075. (not (one-window-p))
  6076. (delete-window))
  6077. (org-agenda-reset-markers)
  6078. (kill-buffer buf)
  6079. (org-columns-remove-overlays)
  6080. (setq org-agenda-archives-mode nil)))
  6081. ;; Maybe restore the pre-agenda window configuration.
  6082. (and org-agenda-restore-windows-after-quit
  6083. (not (eq org-agenda-window-setup 'other-frame))
  6084. org-agenda-pre-window-conf
  6085. (set-window-configuration org-agenda-pre-window-conf)
  6086. (setq org-agenda-pre-window-conf nil))))
  6087. (defun org-agenda-quit ()
  6088. "Exit agenda by killing agenda buffer or burying it when
  6089. `org-agenda-sticky' is non-NIL"
  6090. (interactive)
  6091. (if org-agenda-columns-active
  6092. (org-columns-quit)
  6093. (if org-agenda-sticky
  6094. (let ((buf (current-buffer)))
  6095. (if (eq org-agenda-window-setup 'other-frame)
  6096. (progn
  6097. (delete-frame))
  6098. (and (not (eq org-agenda-window-setup 'current-window))
  6099. (not (one-window-p))
  6100. (delete-window)))
  6101. (with-current-buffer buf
  6102. (bury-buffer)
  6103. ;; Maybe restore the pre-agenda window configuration.
  6104. (and org-agenda-restore-windows-after-quit
  6105. (not (eq org-agenda-window-setup 'other-frame))
  6106. org-agenda-pre-window-conf
  6107. (set-window-configuration org-agenda-pre-window-conf)
  6108. (setq org-agenda-pre-window-conf nil))))
  6109. (org-agenda-Quit))))
  6110. (defun org-agenda-exit ()
  6111. "Exit agenda by removing the window or the buffer.
  6112. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6113. Org-mode buffers visited directly by the user will not be touched."
  6114. (interactive)
  6115. (org-release-buffers org-agenda-new-buffers)
  6116. (setq org-agenda-new-buffers nil)
  6117. (org-agenda-Quit))
  6118. (defun org-agenda-kill-all-agenda-buffers ()
  6119. "Kill all buffers in `org-agena-mode'.
  6120. This is used when toggling sticky agendas. You can also explicitly invoke it
  6121. with `C-c a C-k'."
  6122. (interactive)
  6123. (let (blist)
  6124. (dolist (buf (buffer-list))
  6125. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6126. (push buf blist)))
  6127. (mapc 'kill-buffer blist)))
  6128. (defun org-agenda-execute (arg)
  6129. "Execute another agenda command, keeping same window.
  6130. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6131. in the agenda."
  6132. (interactive "P")
  6133. (let ((org-agenda-window-setup 'current-window))
  6134. (org-agenda arg)))
  6135. (defun org-agenda-redo (&optional all)
  6136. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6137. (interactive "P")
  6138. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6139. (cpa (unless (eq all t) current-prefix-arg))
  6140. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6141. (org-agenda-sticky nil)
  6142. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6143. org-agenda-buffer-name))
  6144. (org-agenda-keep-modes t)
  6145. (tag-filter org-agenda-tag-filter)
  6146. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6147. (top-cat-filter org-agenda-top-category-filter)
  6148. (cat-filter org-agenda-category-filter)
  6149. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6150. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6151. (cols org-agenda-columns-active)
  6152. (line (org-current-line))
  6153. (window-line (- line (org-current-line (window-start))))
  6154. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6155. (redo-cmd (get-text-property p 'org-redo-cmd))
  6156. (last-args (get-text-property p 'org-last-args))
  6157. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6158. (org-agenda-overriding-cmd-arguments
  6159. (unless (eq all t)
  6160. (cond ((listp last-args)
  6161. (cons (or cpa (car last-args)) (cdr last-args)))
  6162. ((stringp last-args)
  6163. last-args))))
  6164. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6165. (put 'org-agenda-tag-filter :preset-filter nil)
  6166. (put 'org-agenda-category-filter :preset-filter nil)
  6167. (and cols (org-columns-quit))
  6168. (message "Rebuilding agenda buffer...")
  6169. (if serie-redo-cmd
  6170. (eval serie-redo-cmd)
  6171. (org-let lprops '(eval redo-cmd)))
  6172. (setq org-agenda-undo-list nil
  6173. org-agenda-pending-undo-list nil)
  6174. (message "Rebuilding agenda buffer...done")
  6175. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6176. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6177. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6178. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6179. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6180. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6181. (org-goto-line line)
  6182. (recenter window-line)))
  6183. (defvar org-global-tags-completion-table nil)
  6184. (defvar org-agenda-filter-form nil)
  6185. (defvar org-agenda-filtered-by-category nil)
  6186. (defun org-agenda-filter-by-category (strip)
  6187. "Keep only those lines in the agenda buffer that have a specific category.
  6188. The category is that of the current line."
  6189. (interactive "P")
  6190. (if (and org-agenda-filtered-by-category
  6191. org-agenda-category-filter)
  6192. (org-agenda-filter-show-all-cat)
  6193. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6194. (if cat (org-agenda-filter-apply
  6195. (list (concat (if strip "-" "+") cat)) 'category)
  6196. (error "No category at point")))))
  6197. (defun org-find-top-category (&optional pos)
  6198. (save-excursion
  6199. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6200. (if pos (goto-char pos))
  6201. ;; Skip up to the topmost parent
  6202. (while (ignore-errors (outline-up-heading 1) t))
  6203. (ignore-errors
  6204. (nth 4 (org-heading-components))))))
  6205. (defvar org-agenda-filtered-by-top-category nil)
  6206. (defun org-agenda-filter-by-top-category (strip)
  6207. "Keep only those lines in the agenda buffer that have a specific category.
  6208. The category is that of the current line."
  6209. (interactive "P")
  6210. (if org-agenda-filtered-by-top-category
  6211. (progn
  6212. (setq org-agenda-filtered-by-top-category nil
  6213. org-agenda-top-category-filter nil)
  6214. (org-agenda-filter-show-all-cat))
  6215. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6216. (if cat (org-agenda-filter-top-category-apply cat strip)
  6217. (error "No top-level category at point")))))
  6218. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6219. "Keep only those lines in the agenda buffer that have a specific tag.
  6220. The tag is selected with its fast selection letter, as configured.
  6221. With prefix argument STRIP, remove all lines that do have the tag.
  6222. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6223. used to narrow the search - the interactive user can also press `-' or `+'
  6224. to switch to narrowing."
  6225. (interactive "P")
  6226. (let* ((alist org-tag-alist-for-agenda)
  6227. (tag-chars (mapconcat
  6228. (lambda (x) (if (and (not (symbolp (car x)))
  6229. (cdr x))
  6230. (char-to-string (cdr x))
  6231. ""))
  6232. alist ""))
  6233. (efforts (org-split-string
  6234. (or (cdr (assoc (concat org-effort-property "_ALL")
  6235. org-global-properties))
  6236. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6237. "")))
  6238. (effort-op org-agenda-filter-effort-default-operator)
  6239. (effort-prompt "")
  6240. (inhibit-read-only t)
  6241. (current org-agenda-tag-filter)
  6242. maybe-refresh a n tag)
  6243. (unless char
  6244. (message
  6245. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6246. (if narrow "Narrow" "Filter") tag-chars
  6247. (if org-agenda-auto-exclude-function "[RET], " ""))
  6248. (setq char (read-char-exclusive)))
  6249. (when (member char '(?+ ?-))
  6250. ;; Narrowing down
  6251. (cond ((equal char ?-) (setq strip t narrow t))
  6252. ((equal char ?+) (setq strip nil narrow t)))
  6253. (message
  6254. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6255. (setq char (read-char-exclusive)))
  6256. (when (member char '(?< ?> ?= ??))
  6257. ;; An effort operator
  6258. (setq effort-op (char-to-string char))
  6259. (setq alist nil) ; to make sure it will be interpreted as effort.
  6260. (unless (equal char ??)
  6261. (loop for i from 0 to 9 do
  6262. (setq effort-prompt
  6263. (concat
  6264. effort-prompt " ["
  6265. (if (= i 9) "0" (int-to-string (1+ i)))
  6266. "]" (nth i efforts))))
  6267. (message "Effort%s: %s " effort-op effort-prompt)
  6268. (setq char (read-char-exclusive))
  6269. (when (or (< char ?0) (> char ?9))
  6270. (error "Need 1-9,0 to select effort"))))
  6271. (when (equal char ?\t)
  6272. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6273. (org-set-local 'org-global-tags-completion-table
  6274. (org-global-tags-completion-table)))
  6275. (let ((completion-ignore-case t))
  6276. (setq tag (org-icompleting-read
  6277. "Tag: " org-global-tags-completion-table))))
  6278. (cond
  6279. ((equal char ?\r)
  6280. (org-agenda-filter-show-all-tag)
  6281. (when org-agenda-auto-exclude-function
  6282. (setq org-agenda-tag-filter '())
  6283. (dolist (tag (org-agenda-get-represented-tags))
  6284. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6285. (if modifier
  6286. (push modifier org-agenda-tag-filter))))
  6287. (if (not (null org-agenda-tag-filter))
  6288. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6289. (setq maybe-refresh t))
  6290. ((equal char ?/)
  6291. (org-agenda-filter-show-all-tag)
  6292. (when (get 'org-agenda-tag-filter :preset-filter)
  6293. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6294. (setq maybe-refresh t))
  6295. ((equal char ?. )
  6296. (setq org-agenda-tag-filter
  6297. (mapcar (lambda(tag) (concat "+" tag))
  6298. (org-get-at-bol 'tags)))
  6299. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6300. (setq maybe-refresh t))
  6301. ((or (equal char ?\ )
  6302. (setq a (rassoc char alist))
  6303. (and (>= char ?0) (<= char ?9)
  6304. (setq n (if (= char ?0) 9 (- char ?0 1))
  6305. tag (concat effort-op (nth n efforts))
  6306. a (cons tag nil)))
  6307. (and (= char ??)
  6308. (setq tag "?eff")
  6309. a (cons tag nil))
  6310. (and tag (setq a (cons tag nil))))
  6311. (org-agenda-filter-show-all-tag)
  6312. (setq tag (car a))
  6313. (setq org-agenda-tag-filter
  6314. (cons (concat (if strip "-" "+") tag)
  6315. (if narrow current nil)))
  6316. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6317. (setq maybe-refresh t))
  6318. (t (error "Invalid tag selection character %c" char)))
  6319. (when (and maybe-refresh
  6320. (eq org-agenda-clockreport-mode 'with-filter))
  6321. (org-agenda-redo))))
  6322. (defun org-agenda-get-represented-tags ()
  6323. "Get a list of all tags currently represented in the agenda."
  6324. (let (p tags)
  6325. (save-excursion
  6326. (goto-char (point-min))
  6327. (while (setq p (next-single-property-change (point) 'tags))
  6328. (goto-char p)
  6329. (mapc (lambda (x) (add-to-list 'tags x))
  6330. (get-text-property (point) 'tags))))
  6331. tags))
  6332. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6333. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6334. (interactive "P")
  6335. (org-agenda-filter-by-tag strip char 'refine))
  6336. (defun org-agenda-filter-make-matcher ()
  6337. "Create the form that tests a line for agenda filter."
  6338. (let (f f1)
  6339. ;; first compute the tag-filter matcher
  6340. (dolist (x (delete-dups
  6341. (append (get 'org-agenda-tag-filter
  6342. :preset-filter) org-agenda-tag-filter)))
  6343. (if (member x '("-" "+"))
  6344. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6345. (if (string-match "[<=>?]" x)
  6346. (setq f1 (org-agenda-filter-effort-form x))
  6347. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6348. (if (equal (string-to-char x) ?-)
  6349. (setq f1 (list 'not f1))))
  6350. (push f1 f))
  6351. ;; then compute the category-filter matcher
  6352. (dolist (x (delete-dups
  6353. (append (get 'org-agenda-category-filter
  6354. :preset-filter) org-agenda-category-filter)))
  6355. (if (equal "-" (substring x 0 1))
  6356. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6357. (setq f1 (list 'equal (substring x 1) 'cat)))
  6358. (push f1 f))
  6359. (cons 'and (nreverse f))))
  6360. (defun org-agenda-filter-effort-form (e)
  6361. "Return the form to compare the effort of the current line with what E says.
  6362. E looks like \"+<2:25\"."
  6363. (let (op)
  6364. (setq e (substring e 1))
  6365. (setq op (string-to-char e) e (substring e 1))
  6366. (setq op (cond ((equal op ?<) '<=)
  6367. ((equal op ?>) '>=)
  6368. ((equal op ??) op)
  6369. (t '=)))
  6370. (list 'org-agenda-compare-effort (list 'quote op)
  6371. (org-duration-string-to-minutes e))))
  6372. (defun org-agenda-compare-effort (op value)
  6373. "Compare the effort of the current line with VALUE, using OP.
  6374. If the line does not have an effort defined, return nil."
  6375. (let ((eff (org-get-at-bol 'effort-minutes)))
  6376. (if (equal op ??)
  6377. (not eff)
  6378. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6379. value))))
  6380. (defun org-agenda-filter-apply (filter type)
  6381. "Set FILTER as the new agenda filter and apply it."
  6382. (let (tags cat)
  6383. (if (eq type 'tag)
  6384. (setq org-agenda-tag-filter filter)
  6385. (setq org-agenda-category-filter filter))
  6386. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6387. (if (and (eq type 'category)
  6388. (not (equal (substring (car filter) 0 1) "-")))
  6389. ;; Only set `org-agenda-filtered-by-category' to t
  6390. ;; when a unique category is used as the filter
  6391. (setq org-agenda-filtered-by-category t))
  6392. (org-agenda-set-mode-name)
  6393. (save-excursion
  6394. (goto-char (point-min))
  6395. (while (not (eobp))
  6396. (if (org-get-at-bol 'org-marker)
  6397. (progn
  6398. (setq tags (org-get-at-bol 'tags) ; used in eval
  6399. cat (get-text-property (point) 'org-category))
  6400. (if (not (eval org-agenda-filter-form))
  6401. (org-agenda-filter-hide-line type))
  6402. (beginning-of-line 2))
  6403. (beginning-of-line 2))))
  6404. (if (get-char-property (point) 'invisible)
  6405. (ignore-errors (org-agenda-previous-line)))))
  6406. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6407. "Set FILTER as the new agenda filter and apply it."
  6408. (org-agenda-set-mode-name)
  6409. (save-excursion
  6410. (goto-char (point-min))
  6411. (while (not (eobp))
  6412. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6413. (topcat (and pos (org-find-top-category pos))))
  6414. (if (and topcat (funcall (if negative 'identity 'not)
  6415. (string= category topcat)))
  6416. (org-agenda-filter-hide-line 'category)))
  6417. (beginning-of-line 2)))
  6418. (if (get-char-property (point) 'invisible)
  6419. (org-agenda-previous-line))
  6420. (setq org-agenda-top-category-filter category
  6421. org-agenda-filtered-by-top-category t))
  6422. (defun org-agenda-filter-hide-line (type)
  6423. (let (ov)
  6424. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6425. (point-at-eol)))
  6426. (overlay-put ov 'invisible t)
  6427. (overlay-put ov 'type type)
  6428. (if (eq type 'tag)
  6429. (push ov org-agenda-tag-filter-overlays)
  6430. (push ov org-agenda-cat-filter-overlays))))
  6431. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6432. (setq pos (or pos (point)))
  6433. (save-excursion
  6434. (dolist (ov (overlays-at pos))
  6435. (when (and (overlay-get ov 'invisible)
  6436. (eq (overlay-get ov 'type) 'tag))
  6437. (goto-char pos)
  6438. (if (< (overlay-start ov) (point-at-eol))
  6439. (move-overlay ov (point-at-eol)
  6440. (overlay-end ov)))))))
  6441. (defun org-agenda-filter-show-all-tag nil
  6442. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6443. (setq org-agenda-tag-filter-overlays nil
  6444. org-agenda-tag-filter nil
  6445. org-agenda-filter-form nil)
  6446. (org-agenda-set-mode-name))
  6447. (defun org-agenda-filter-show-all-cat nil
  6448. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6449. (setq org-agenda-cat-filter-overlays nil
  6450. org-agenda-filtered-by-category nil
  6451. org-agenda-category-filter nil
  6452. org-agenda-filter-form nil)
  6453. (org-agenda-set-mode-name))
  6454. (defun org-agenda-manipulate-query-add ()
  6455. "Manipulate the query by adding a search term with positive selection.
  6456. Positive selection means the term must be matched for selection of an entry."
  6457. (interactive)
  6458. (org-agenda-manipulate-query ?\[))
  6459. (defun org-agenda-manipulate-query-subtract ()
  6460. "Manipulate the query by adding a search term with negative selection.
  6461. Negative selection means term must not be matched for selection of an entry."
  6462. (interactive)
  6463. (org-agenda-manipulate-query ?\]))
  6464. (defun org-agenda-manipulate-query-add-re ()
  6465. "Manipulate the query by adding a search regexp with positive selection.
  6466. Positive selection means the regexp must match for selection of an entry."
  6467. (interactive)
  6468. (org-agenda-manipulate-query ?\{))
  6469. (defun org-agenda-manipulate-query-subtract-re ()
  6470. "Manipulate the query by adding a search regexp with negative selection.
  6471. Negative selection means regexp must not match for selection of an entry."
  6472. (interactive)
  6473. (org-agenda-manipulate-query ?\}))
  6474. (defun org-agenda-manipulate-query (char)
  6475. (cond
  6476. ((memq org-agenda-type '(timeline agenda))
  6477. (let ((org-agenda-include-inactive-timestamps t))
  6478. (org-agenda-redo))
  6479. (message "Display now includes inactive timestamps as well"))
  6480. ((eq org-agenda-type 'search)
  6481. (org-add-to-string
  6482. 'org-agenda-query-string
  6483. (if org-agenda-last-search-view-search-was-boolean
  6484. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6485. (?\{ . " +{}") (?\} . " -{}"))))
  6486. " "))
  6487. (setq org-agenda-redo-command
  6488. (list 'org-search-view
  6489. (car (get-text-property (point) 'org-last-args))
  6490. org-agenda-query-string
  6491. (+ (length org-agenda-query-string)
  6492. (if (member char '(?\{ ?\})) 0 1))))
  6493. (set-register org-agenda-query-register org-agenda-query-string)
  6494. (let ((org-agenda-overriding-arguments
  6495. (cdr org-agenda-redo-command)))
  6496. (org-agenda-redo)))
  6497. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6498. org-agenda-type))))
  6499. (defun org-add-to-string (var string)
  6500. (set var (concat (symbol-value var) string)))
  6501. (defun org-agenda-goto-date (date)
  6502. "Jump to DATE in agenda."
  6503. (interactive (list (let ((org-read-date-prefer-future
  6504. (eval org-agenda-jump-prefer-future)))
  6505. (org-read-date))))
  6506. (org-agenda-list nil date))
  6507. (defun org-agenda-goto-today ()
  6508. "Go to today."
  6509. (interactive)
  6510. (org-agenda-check-type t 'timeline 'agenda)
  6511. (let* ((args (get-text-property (point) 'org-last-args))
  6512. (curspan (nth 2 args))
  6513. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6514. (cond
  6515. (tdpos (goto-char tdpos))
  6516. ((eq org-agenda-type 'agenda)
  6517. (let* ((sd (org-agenda-compute-starting-span
  6518. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6519. (org-agenda-overriding-arguments args))
  6520. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6521. (org-agenda-redo)
  6522. (org-agenda-find-same-or-today-or-agenda)))
  6523. (t (error "Cannot find today")))))
  6524. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6525. (goto-char
  6526. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6527. (text-property-any (point-min) (point-max) 'org-today t)
  6528. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6529. (and (get-text-property (point) 'org-serie)
  6530. (org-agenda-goto-block-beginning))
  6531. (point-min))))
  6532. (defun org-agenda-goto-block-beginning ()
  6533. "Go the agenda block beginning."
  6534. (interactive)
  6535. (if (not (derived-mode-p 'org-agenda-mode))
  6536. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6537. (let (dest)
  6538. (save-excursion
  6539. (unless (looking-at "\\'")
  6540. (forward-char))
  6541. (let* ((prop 'org-agenda-structural-header)
  6542. (p (previous-single-property-change (point) prop))
  6543. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6544. (1- (point))) prop)))
  6545. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6546. (if (not dest)
  6547. (error "Cannot find the beginning of the blog")
  6548. (goto-char dest)
  6549. (move-beginning-of-line 1)))))
  6550. (defun org-agenda-later (arg)
  6551. "Go forward in time by thee current span.
  6552. With prefix ARG, go forward that many times the current span."
  6553. (interactive "p")
  6554. (org-agenda-check-type t 'agenda)
  6555. (let* ((args (get-text-property (point) 'org-last-args))
  6556. (span (or (nth 2 args) org-agenda-current-span))
  6557. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6558. (greg (calendar-gregorian-from-absolute sd))
  6559. (cnt (org-get-at-bol 'org-day-cnt))
  6560. greg2)
  6561. (cond
  6562. ((numberp span)
  6563. (setq sd (+ span sd)))
  6564. ((eq span 'day)
  6565. (setq sd (+ arg sd)))
  6566. ((eq span 'week)
  6567. (setq sd (+ (* 7 arg) sd)))
  6568. ((eq span 'month)
  6569. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6570. sd (calendar-absolute-from-gregorian greg2))
  6571. (setcar greg2 (1+ (car greg2))))
  6572. ((eq span 'year)
  6573. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6574. sd (calendar-absolute-from-gregorian greg2))
  6575. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6576. (t
  6577. (setq sd (+ (* span arg) sd))))
  6578. (let ((org-agenda-overriding-cmd
  6579. ;; `cmd' may have been set by `org-agenda-run-series' which
  6580. ;; uses `org-agenda-overriding-cmd' to decide whether
  6581. ;; overriding is allowed for `cmd'
  6582. (get-text-property (point) 'org-serie-cmd))
  6583. (org-agenda-overriding-arguments
  6584. (list (car args) sd span)))
  6585. (org-agenda-redo)
  6586. (org-agenda-find-same-or-today-or-agenda cnt))))
  6587. (defun org-agenda-earlier (arg)
  6588. "Go backward in time by the current span.
  6589. With prefix ARG, go backward that many times the current span."
  6590. (interactive "p")
  6591. (org-agenda-later (- arg)))
  6592. (defun org-agenda-view-mode-dispatch ()
  6593. "Call one of the view mode commands."
  6594. (interactive)
  6595. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6596. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6597. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6598. (let ((a (read-char-exclusive)))
  6599. (case a
  6600. (?\ (call-interactively 'org-agenda-reset-view))
  6601. (?d (call-interactively 'org-agenda-day-view))
  6602. (?w (call-interactively 'org-agenda-week-view))
  6603. (?m (call-interactively 'org-agenda-month-view))
  6604. (?y (call-interactively 'org-agenda-year-view))
  6605. (?l (call-interactively 'org-agenda-log-mode))
  6606. (?L (org-agenda-log-mode '(4)))
  6607. (?c (org-agenda-log-mode 'clockcheck))
  6608. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6609. (?a (call-interactively 'org-agenda-archives-mode))
  6610. (?A (org-agenda-archives-mode 'files))
  6611. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6612. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6613. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6614. (?D (call-interactively 'org-agenda-toggle-diary))
  6615. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6616. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6617. (org-agenda-check-type t 'timeline 'agenda)
  6618. (org-agenda-redo))
  6619. (message "Display now includes inactive timestamps as well"))
  6620. (?q (message "Abort"))
  6621. (otherwise (error "Invalid key" )))))
  6622. (defun org-agenda-reset-view ()
  6623. "Switch to default view for agenda."
  6624. (interactive)
  6625. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6626. (defun org-agenda-day-view (&optional day-of-year)
  6627. "Switch to daily view for agenda.
  6628. With argument DAY-OF-YEAR, switch to that day of the year."
  6629. (interactive "P")
  6630. (org-agenda-change-time-span 'day day-of-year))
  6631. (defun org-agenda-week-view (&optional iso-week)
  6632. "Switch to daily view for agenda.
  6633. With argument ISO-WEEK, switch to the corresponding ISO week.
  6634. If ISO-WEEK has more then 2 digits, only the last two encode the
  6635. week. Any digits before this encode a year. So 200712 means
  6636. week 12 of year 2007. Years in the range 1938-2037 can also be
  6637. written as 2-digit years."
  6638. (interactive "P")
  6639. (org-agenda-change-time-span 'week iso-week))
  6640. (defun org-agenda-month-view (&optional month)
  6641. "Switch to monthly view for agenda.
  6642. With argument MONTH, switch to that month."
  6643. (interactive "P")
  6644. (org-agenda-change-time-span 'month month))
  6645. (defun org-agenda-year-view (&optional year)
  6646. "Switch to yearly view for agenda.
  6647. With argument YEAR, switch to that year.
  6648. If MONTH has more then 2 digits, only the last two encode the
  6649. month. Any digits before this encode a year. So 200712 means
  6650. December year 2007. Years in the range 1938-2037 can also be
  6651. written as 2-digit years."
  6652. (interactive "P")
  6653. (when year
  6654. (setq year (org-small-year-to-year year)))
  6655. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6656. (org-agenda-change-time-span 'year year)
  6657. (error "Abort")))
  6658. (defun org-agenda-change-time-span (span &optional n)
  6659. "Change the agenda view to SPAN.
  6660. SPAN may be `day', `week', `month', `year'."
  6661. (org-agenda-check-type t 'agenda)
  6662. (let* ((args (get-text-property (point) 'org-last-args))
  6663. (curspan (nth 2 args)))
  6664. (if (and (not n) (equal curspan span))
  6665. (error "Viewing span is already \"%s\"" span))
  6666. (let* ((sd (or (org-get-at-bol 'day)
  6667. (nth 1 args)
  6668. org-starting-day))
  6669. (sd (org-agenda-compute-starting-span sd span n))
  6670. (org-agenda-overriding-cmd
  6671. (get-text-property (point) 'org-serie-cmd))
  6672. (org-agenda-overriding-arguments
  6673. (list (car args) sd span)))
  6674. (org-agenda-redo)
  6675. (org-agenda-find-same-or-today-or-agenda))
  6676. (org-agenda-set-mode-name)
  6677. (message "Switched to %s view" span)))
  6678. (defun org-agenda-compute-starting-span (sd span &optional n)
  6679. "Compute starting date for agenda.
  6680. SPAN may be `day', `week', `month', `year'. The return value
  6681. is a cons cell with the starting date and the number of days,
  6682. so that the date SD will be in that range."
  6683. (let* ((greg (calendar-gregorian-from-absolute sd))
  6684. (dg (nth 1 greg))
  6685. (mg (car greg))
  6686. (yg (nth 2 greg)))
  6687. (cond
  6688. ((eq span 'day)
  6689. (when n
  6690. (setq sd (+ (calendar-absolute-from-gregorian
  6691. (list mg 1 yg))
  6692. n -1))))
  6693. ((eq span 'week)
  6694. (let* ((nt (calendar-day-of-week
  6695. (calendar-gregorian-from-absolute sd)))
  6696. (d (if org-agenda-start-on-weekday
  6697. (- nt org-agenda-start-on-weekday)
  6698. 0))
  6699. y1)
  6700. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6701. (when n
  6702. (require 'cal-iso)
  6703. (when (> n 99)
  6704. (setq y1 (org-small-year-to-year (/ n 100))
  6705. n (mod n 100)))
  6706. (setq sd
  6707. (calendar-absolute-from-iso
  6708. (list n 1
  6709. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6710. ((eq span 'month)
  6711. (let (y1)
  6712. (when (and n (> n 99))
  6713. (setq y1 (org-small-year-to-year (/ n 100))
  6714. n (mod n 100)))
  6715. (setq sd (calendar-absolute-from-gregorian
  6716. (list (or n mg) 1 (or y1 yg))))))
  6717. ((eq span 'year)
  6718. (setq sd (calendar-absolute-from-gregorian
  6719. (list 1 1 (or n yg))))))
  6720. sd))
  6721. (defun org-agenda-next-date-line (&optional arg)
  6722. "Jump to the next line indicating a date in agenda buffer."
  6723. (interactive "p")
  6724. (org-agenda-check-type t 'agenda 'timeline)
  6725. (beginning-of-line 1)
  6726. ;; This does not work if user makes date format that starts with a blank
  6727. (if (looking-at "^\\S-") (forward-char 1))
  6728. (if (not (re-search-forward "^\\S-" nil t arg))
  6729. (progn
  6730. (backward-char 1)
  6731. (error "No next date after this line in this buffer")))
  6732. (goto-char (match-beginning 0)))
  6733. (defun org-agenda-previous-date-line (&optional arg)
  6734. "Jump to the previous line indicating a date in agenda buffer."
  6735. (interactive "p")
  6736. (org-agenda-check-type t 'agenda 'timeline)
  6737. (beginning-of-line 1)
  6738. (if (not (re-search-backward "^\\S-" nil t arg))
  6739. (error "No previous date before this line in this buffer")))
  6740. ;; Initialize the highlight
  6741. (defvar org-hl (make-overlay 1 1))
  6742. (overlay-put org-hl 'face 'highlight)
  6743. (defun org-highlight (begin end &optional buffer)
  6744. "Highlight a region with overlay."
  6745. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6746. (defun org-unhighlight ()
  6747. "Detach overlay INDEX."
  6748. (org-detach-overlay org-hl))
  6749. (defun org-unhighlight-once ()
  6750. "Remove the highlight from its position, and this function from the hook."
  6751. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6752. (org-unhighlight))
  6753. (defun org-agenda-follow-mode ()
  6754. "Toggle follow mode in an agenda buffer."
  6755. (interactive)
  6756. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6757. (org-agenda-set-mode-name)
  6758. (org-agenda-do-context-action)
  6759. (message "Follow mode is %s"
  6760. (if org-agenda-follow-mode "on" "off")))
  6761. (defun org-agenda-entry-text-mode (&optional arg)
  6762. "Toggle entry text mode in an agenda buffer."
  6763. (interactive "P")
  6764. (setq org-agenda-entry-text-mode (or (integerp arg)
  6765. (not org-agenda-entry-text-mode)))
  6766. (org-agenda-entry-text-hide)
  6767. (and org-agenda-entry-text-mode
  6768. (let ((org-agenda-entry-text-maxlines
  6769. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6770. (org-agenda-entry-text-show)))
  6771. (org-agenda-set-mode-name)
  6772. (message "Entry text mode is %s. Maximum number of lines is %d"
  6773. (if org-agenda-entry-text-mode "on" "off")
  6774. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6775. (defun org-agenda-clockreport-mode (&optional with-filter)
  6776. "Toggle clocktable mode in an agenda buffer.
  6777. With prefix arg WITH-FILTER, make the clocktable respect the current
  6778. agenda filter."
  6779. (interactive "P")
  6780. (org-agenda-check-type t 'agenda)
  6781. (if with-filter
  6782. (setq org-agenda-clockreport-mode 'with-filter)
  6783. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6784. (org-agenda-set-mode-name)
  6785. (org-agenda-redo)
  6786. (message "Clocktable mode is %s"
  6787. (if org-agenda-clockreport-mode "on" "off")))
  6788. (defun org-agenda-log-mode (&optional special)
  6789. "Toggle log mode in an agenda buffer.
  6790. With argument SPECIAL, show all possible log items, not only the ones
  6791. configured in `org-agenda-log-mode-items'.
  6792. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6793. (interactive "P")
  6794. (org-agenda-check-type t 'agenda 'timeline)
  6795. (setq org-agenda-show-log
  6796. (cond
  6797. ((equal special '(16)) 'only)
  6798. ((eq special 'clockcheck)
  6799. (if (eq org-agenda-show-log 'clockcheck)
  6800. nil 'clockcheck))
  6801. (special '(closed clock state))
  6802. (t (not org-agenda-show-log))))
  6803. (org-agenda-set-mode-name)
  6804. (org-agenda-redo)
  6805. (message "Log mode is %s"
  6806. (if org-agenda-show-log "on" "off")))
  6807. (defun org-agenda-archives-mode (&optional with-files)
  6808. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6809. When called with a prefix argument, include all archive files as well."
  6810. (interactive "P")
  6811. (setq org-agenda-archives-mode
  6812. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6813. (org-agenda-set-mode-name)
  6814. (org-agenda-redo)
  6815. (message
  6816. "%s"
  6817. (cond
  6818. ((eq org-agenda-archives-mode nil)
  6819. "No archives are included")
  6820. ((eq org-agenda-archives-mode 'trees)
  6821. (format "Trees with :%s: tag are included" org-archive-tag))
  6822. ((eq org-agenda-archives-mode t)
  6823. (format "Trees with :%s: tag and all active archive files are included"
  6824. org-archive-tag)))))
  6825. (defun org-agenda-toggle-diary ()
  6826. "Toggle diary inclusion in an agenda buffer."
  6827. (interactive)
  6828. (org-agenda-check-type t 'agenda)
  6829. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6830. (org-agenda-redo)
  6831. (org-agenda-set-mode-name)
  6832. (message "Diary inclusion turned %s"
  6833. (if org-agenda-include-diary "on" "off")))
  6834. (defun org-agenda-toggle-deadlines ()
  6835. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6836. (interactive)
  6837. (org-agenda-check-type t 'agenda)
  6838. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6839. (org-agenda-redo)
  6840. (org-agenda-set-mode-name)
  6841. (message "Deadlines inclusion turned %s"
  6842. (if org-agenda-include-deadlines "on" "off")))
  6843. (defun org-agenda-toggle-time-grid ()
  6844. "Toggle time grid in an agenda buffer."
  6845. (interactive)
  6846. (org-agenda-check-type t 'agenda)
  6847. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6848. (org-agenda-redo)
  6849. (org-agenda-set-mode-name)
  6850. (message "Time-grid turned %s"
  6851. (if org-agenda-use-time-grid "on" "off")))
  6852. (defun org-agenda-set-mode-name ()
  6853. "Set the mode name to indicate all the small mode settings."
  6854. (setq mode-name
  6855. (list "Org-Agenda"
  6856. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6857. " "
  6858. '(:eval (org-agenda-span-name org-agenda-current-span))
  6859. (if org-agenda-follow-mode " Follow" "")
  6860. (if org-agenda-entry-text-mode " ETxt" "")
  6861. (if org-agenda-include-diary " Diary" "")
  6862. (if org-agenda-include-deadlines " Ddl" "")
  6863. (if org-agenda-use-time-grid " Grid" "")
  6864. (if (and (boundp 'org-habit-show-habits)
  6865. org-habit-show-habits) " Habit" "")
  6866. (cond
  6867. ((consp org-agenda-show-log) " LogAll")
  6868. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6869. (org-agenda-show-log " Log")
  6870. (t ""))
  6871. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6872. :preset-filter))
  6873. '(:eval (org-propertize
  6874. (concat " <"
  6875. (mapconcat
  6876. 'identity
  6877. (append
  6878. (get 'org-agenda-category-filter :preset-filter)
  6879. org-agenda-category-filter)
  6880. "")
  6881. ">")
  6882. 'face 'org-agenda-filter-category
  6883. 'help-echo "Category used in filtering"))
  6884. "")
  6885. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6886. :preset-filter))
  6887. '(:eval (org-propertize
  6888. (concat " {"
  6889. (mapconcat
  6890. 'identity
  6891. (append
  6892. (get 'org-agenda-tag-filter :preset-filter)
  6893. org-agenda-tag-filter)
  6894. "")
  6895. "}")
  6896. 'face 'org-agenda-filter-tags
  6897. 'help-echo "Tags used in filtering"))
  6898. "")
  6899. (if org-agenda-archives-mode
  6900. (if (eq org-agenda-archives-mode t)
  6901. " Archives"
  6902. (format " :%s:" org-archive-tag))
  6903. "")
  6904. (if org-agenda-clockreport-mode
  6905. (if (eq org-agenda-clockreport-mode 'with-filter)
  6906. " Clock{}" " Clock")
  6907. "")))
  6908. (force-mode-line-update))
  6909. (defun org-agenda-post-command-hook ()
  6910. (setq org-agenda-type
  6911. (or (get-text-property (point) 'org-agenda-type)
  6912. (get-text-property (max (point-min) (1- (point)))
  6913. 'org-agenda-type))))
  6914. (defun org-agenda-next-line ()
  6915. "Move cursor to the next line, and show if follow mode is active."
  6916. (interactive)
  6917. (call-interactively 'next-line)
  6918. (org-agenda-do-context-action))
  6919. (defun org-agenda-previous-line ()
  6920. "Move cursor to the previous line, and show if follow-mode is active."
  6921. (interactive)
  6922. (call-interactively 'previous-line)
  6923. (org-agenda-do-context-action))
  6924. (defun org-agenda-next-item (n)
  6925. "Move cursor to next agenda item."
  6926. (interactive "p")
  6927. (let ((col (current-column)))
  6928. (dotimes (c n)
  6929. (when (next-single-property-change (point-at-eol) 'org-marker)
  6930. (move-end-of-line 1)
  6931. (goto-char (next-single-property-change (point) 'org-marker))))
  6932. (org-move-to-column col))
  6933. (org-agenda-do-context-action))
  6934. (defun org-agenda-previous-item (n)
  6935. "Move cursor to next agenda item."
  6936. (interactive "p")
  6937. (dotimes (c n)
  6938. (let ((col (current-column))
  6939. (goto (save-excursion
  6940. (move-end-of-line 0)
  6941. (previous-single-property-change (point) 'org-marker))))
  6942. (if goto (goto-char goto))
  6943. (org-move-to-column col)))
  6944. (org-agenda-do-context-action))
  6945. (defun org-agenda-do-context-action ()
  6946. "Show outline path and, maybe, follow mode window."
  6947. (let ((m (org-get-at-bol 'org-marker)))
  6948. (when (and (markerp m) (marker-buffer m))
  6949. (and org-agenda-follow-mode
  6950. (if org-agenda-follow-indirect
  6951. (org-agenda-tree-to-indirect-buffer)
  6952. (org-agenda-show)))
  6953. (and org-agenda-show-outline-path
  6954. (org-with-point-at m (org-display-outline-path t))))))
  6955. (defun org-agenda-show-priority ()
  6956. "Show the priority of the current item.
  6957. This priority is composed of the main priority given with the [#A] cookies,
  6958. and by additional input from the age of a schedules or deadline entry."
  6959. (interactive)
  6960. (let* ((pri (org-get-at-bol 'priority)))
  6961. (message "Priority is %d" (if pri pri -1000))))
  6962. (defun org-agenda-show-tags ()
  6963. "Show the tags applicable to the current item."
  6964. (interactive)
  6965. (let* ((tags (org-get-at-bol 'tags)))
  6966. (if tags
  6967. (message "Tags are :%s:"
  6968. (org-no-properties (mapconcat 'identity tags ":")))
  6969. (message "No tags associated with this line"))))
  6970. (defun org-agenda-goto (&optional highlight)
  6971. "Go to the Org-mode file which contains the item at point."
  6972. (interactive)
  6973. (let* ((marker (or (org-get-at-bol 'org-marker)
  6974. (org-agenda-error)))
  6975. (buffer (marker-buffer marker))
  6976. (pos (marker-position marker)))
  6977. (switch-to-buffer-other-window buffer)
  6978. (widen)
  6979. (push-mark)
  6980. (goto-char pos)
  6981. (when (derived-mode-p 'org-mode)
  6982. (org-show-context 'agenda)
  6983. (save-excursion
  6984. (and (outline-next-heading)
  6985. (org-flag-heading nil)))) ; show the next heading
  6986. (when (outline-invisible-p)
  6987. (show-entry)) ; display invisible text
  6988. (recenter (/ (window-height) 2))
  6989. (run-hooks 'org-agenda-after-show-hook)
  6990. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6991. (defvar org-agenda-after-show-hook nil
  6992. "Normal hook run after an item has been shown from the agenda.
  6993. Point is in the buffer where the item originated.")
  6994. (defun org-agenda-kill ()
  6995. "Kill the entry or subtree belonging to the current agenda entry."
  6996. (interactive)
  6997. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6998. (let* ((bufname-orig (buffer-name))
  6999. (marker (or (org-get-at-bol 'org-marker)
  7000. (org-agenda-error)))
  7001. (buffer (marker-buffer marker))
  7002. (pos (marker-position marker))
  7003. (type (org-get-at-bol 'type))
  7004. dbeg dend (n 0) conf)
  7005. (org-with-remote-undo buffer
  7006. (with-current-buffer buffer
  7007. (save-excursion
  7008. (goto-char pos)
  7009. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7010. (setq dbeg (progn (org-back-to-heading t) (point))
  7011. dend (org-end-of-subtree t t))
  7012. (setq dbeg (point-at-bol)
  7013. dend (min (point-max) (1+ (point-at-eol)))))
  7014. (goto-char dbeg)
  7015. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7016. (setq conf (or (eq t org-agenda-confirm-kill)
  7017. (and (numberp org-agenda-confirm-kill)
  7018. (> n org-agenda-confirm-kill))))
  7019. (and conf
  7020. (not (y-or-n-p
  7021. (format "Delete entry with %d lines in buffer \"%s\"? "
  7022. n (buffer-name buffer))))
  7023. (error "Abort"))
  7024. (let ((org-agenda-buffer-name bufname-orig))
  7025. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7026. (with-current-buffer buffer (delete-region dbeg dend))
  7027. (message "Agenda item and source killed"))))
  7028. (defvar org-archive-default-command)
  7029. (defun org-agenda-archive-default ()
  7030. "Archive the entry or subtree belonging to the current agenda entry."
  7031. (interactive)
  7032. (require 'org-archive)
  7033. (org-agenda-archive-with org-archive-default-command))
  7034. (defun org-agenda-archive-default-with-confirmation ()
  7035. "Archive the entry or subtree belonging to the current agenda entry."
  7036. (interactive)
  7037. (require 'org-archive)
  7038. (org-agenda-archive-with org-archive-default-command 'confirm))
  7039. (defun org-agenda-archive ()
  7040. "Archive the entry or subtree belonging to the current agenda entry."
  7041. (interactive)
  7042. (org-agenda-archive-with 'org-archive-subtree))
  7043. (defun org-agenda-archive-to-archive-sibling ()
  7044. "Move the entry to the archive sibling."
  7045. (interactive)
  7046. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7047. (defun org-agenda-archive-with (cmd &optional confirm)
  7048. "Move the entry to the archive sibling."
  7049. (interactive)
  7050. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7051. (let* ((bufname-orig (buffer-name))
  7052. (marker (or (org-get-at-bol 'org-marker)
  7053. (org-agenda-error)))
  7054. (buffer (marker-buffer marker))
  7055. (pos (marker-position marker)))
  7056. (org-with-remote-undo buffer
  7057. (with-current-buffer buffer
  7058. (if (derived-mode-p 'org-mode)
  7059. (if (and confirm
  7060. (not (y-or-n-p "Archive this subtree or entry? ")))
  7061. (error "Abort")
  7062. (save-excursion
  7063. (goto-char pos)
  7064. (let ((org-agenda-buffer-name bufname-orig))
  7065. (org-remove-subtree-entries-from-agenda))
  7066. (org-back-to-heading t)
  7067. (funcall cmd)))
  7068. (error "Archiving works only in Org-mode files"))))))
  7069. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7070. "Remove all lines in the agenda that correspond to a given subtree.
  7071. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7072. If this information is not given, the function uses the tree at point."
  7073. (let ((buf (or buf (current-buffer))) m p)
  7074. (save-excursion
  7075. (unless (and beg end)
  7076. (org-back-to-heading t)
  7077. (setq beg (point))
  7078. (org-end-of-subtree t)
  7079. (setq end (point)))
  7080. (set-buffer (get-buffer org-agenda-buffer-name))
  7081. (save-excursion
  7082. (goto-char (point-max))
  7083. (beginning-of-line 1)
  7084. (while (not (bobp))
  7085. (when (and (setq m (org-get-at-bol 'org-marker))
  7086. (equal buf (marker-buffer m))
  7087. (setq p (marker-position m))
  7088. (>= p beg)
  7089. (< p end))
  7090. (let ((inhibit-read-only t))
  7091. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7092. (beginning-of-line 0))))))
  7093. (defun org-agenda-refile (&optional goto rfloc no-update)
  7094. "Refile the item at point."
  7095. (interactive "P")
  7096. (if (equal goto '(16))
  7097. (org-refile-goto-last-stored)
  7098. (let* ((buffer-orig (buffer-name))
  7099. (marker (or (org-get-at-bol 'org-hd-marker)
  7100. (org-agenda-error)))
  7101. (buffer (marker-buffer marker))
  7102. (pos (marker-position marker))
  7103. (rfloc (or rfloc
  7104. (org-refile-get-location
  7105. (if goto "Goto" "Refile to") buffer
  7106. org-refile-allow-creating-parent-nodes))))
  7107. (with-current-buffer buffer
  7108. (save-excursion
  7109. (save-restriction
  7110. (widen)
  7111. (goto-char marker)
  7112. (let ((org-agenda-buffer-name buffer-orig))
  7113. (org-remove-subtree-entries-from-agenda))
  7114. (org-refile goto buffer rfloc)))))
  7115. (unless no-update (org-agenda-redo))))
  7116. (defun org-agenda-open-link (&optional arg)
  7117. "Follow the link in the current line, if any.
  7118. This looks for a link in the displayed line in the agenda. It also looks
  7119. at the text of the entry itself."
  7120. (interactive "P")
  7121. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7122. (org-get-at-bol 'org-marker)))
  7123. (buffer (and marker (marker-buffer marker)))
  7124. (prefix (buffer-substring
  7125. (point-at-bol) (point-at-eol))))
  7126. (cond
  7127. (buffer
  7128. (with-current-buffer buffer
  7129. (save-excursion
  7130. (save-restriction
  7131. (widen)
  7132. (goto-char marker)
  7133. (org-offer-links-in-entry arg prefix)))))
  7134. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7135. (save-excursion
  7136. (beginning-of-line 1)
  7137. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7138. (org-open-link-from-string (match-string 1)))
  7139. (t (error "No link to open here")))))
  7140. (defun org-agenda-copy-local-variable (var)
  7141. "Get a variable from a referenced buffer and install it here."
  7142. (let ((m (org-get-at-bol 'org-marker)))
  7143. (when (and m (buffer-live-p (marker-buffer m)))
  7144. (org-set-local var (with-current-buffer (marker-buffer m)
  7145. (symbol-value var))))))
  7146. (defun org-agenda-switch-to (&optional delete-other-windows)
  7147. "Go to the Org-mode file which contains the item at point."
  7148. (interactive)
  7149. (if (and org-return-follows-link
  7150. (not (org-get-at-bol 'org-marker))
  7151. (org-in-regexp org-bracket-link-regexp))
  7152. (org-open-link-from-string (match-string 0))
  7153. (let* ((marker (or (org-get-at-bol 'org-marker)
  7154. (org-agenda-error)))
  7155. (buffer (marker-buffer marker))
  7156. (pos (marker-position marker)))
  7157. (org-pop-to-buffer-same-window buffer)
  7158. (and delete-other-windows (delete-other-windows))
  7159. (widen)
  7160. (goto-char pos)
  7161. (when (derived-mode-p 'org-mode)
  7162. (org-show-context 'agenda)
  7163. (save-excursion
  7164. (and (outline-next-heading)
  7165. (org-flag-heading nil))) ; show the next heading
  7166. (when (outline-invisible-p)
  7167. (show-entry)) ; display invisible text
  7168. (run-hooks 'org-agenda-after-show-hook)))))
  7169. (defun org-agenda-goto-mouse (ev)
  7170. "Go to the Org-mode file which contains the item at the mouse click."
  7171. (interactive "e")
  7172. (mouse-set-point ev)
  7173. (org-agenda-goto))
  7174. (defun org-agenda-show (&optional full-entry)
  7175. "Display the Org-mode file which contains the item at point.
  7176. With prefix argument FULL-ENTRY, make the entire entry visible
  7177. if it was hidden in the outline."
  7178. (interactive "P")
  7179. (let ((win (selected-window)))
  7180. (if full-entry
  7181. (let ((org-show-entry-below t))
  7182. (org-agenda-goto t))
  7183. (org-agenda-goto t))
  7184. (select-window win)))
  7185. (defvar org-agenda-show-window nil)
  7186. (defun org-agenda-show-and-scroll-up (&optional arg)
  7187. "Display the Org-mode file which contains the item at point.
  7188. When called repeatedly, scroll the window that is displaying the buffer.
  7189. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7190. `show-subtree' to display the item, so that drawers and logbooks stay
  7191. folded."
  7192. (interactive "P")
  7193. (let ((win (selected-window)))
  7194. (if (and (window-live-p org-agenda-show-window)
  7195. (eq this-command last-command))
  7196. (progn
  7197. (select-window org-agenda-show-window)
  7198. (ignore-errors (scroll-up)))
  7199. (org-agenda-goto t)
  7200. (if arg (org-show-entry) (show-subtree))
  7201. (setq org-agenda-show-window (selected-window)))
  7202. (select-window win)))
  7203. (defun org-agenda-show-scroll-down ()
  7204. "Scroll down the window showing the agenda."
  7205. (interactive)
  7206. (let ((win (selected-window)))
  7207. (when (window-live-p org-agenda-show-window)
  7208. (select-window org-agenda-show-window)
  7209. (ignore-errors (scroll-down))
  7210. (select-window win))))
  7211. (defun org-agenda-show-1 (&optional more)
  7212. "Display the Org-mode file which contains the item at point.
  7213. The prefix arg selects the amount of information to display:
  7214. 0 hide the subtree
  7215. 1 just show the entry according to defaults.
  7216. 2 show the children view
  7217. 3 show the subtree view
  7218. 4 show the entire subtree and any LOGBOOK drawers
  7219. 5 show the entire subtree and any drawers
  7220. With prefix argument FULL-ENTRY, make the entire entry visible
  7221. if it was hidden in the outline."
  7222. (interactive "p")
  7223. (let ((win (selected-window)))
  7224. (org-agenda-goto t)
  7225. (org-recenter-heading 1)
  7226. (cond
  7227. ((= more 0)
  7228. (hide-subtree)
  7229. (save-excursion
  7230. (org-back-to-heading)
  7231. (run-hook-with-args 'org-cycle-hook 'folded))
  7232. (message "Remote: FOLDED"))
  7233. ((and (org-called-interactively-p 'any) (= more 1))
  7234. (message "Remote: show with default settings"))
  7235. ((= more 2)
  7236. (show-entry)
  7237. (show-children)
  7238. (save-excursion
  7239. (org-back-to-heading)
  7240. (run-hook-with-args 'org-cycle-hook 'children))
  7241. (message "Remote: CHILDREN"))
  7242. ((= more 3)
  7243. (show-subtree)
  7244. (save-excursion
  7245. (org-back-to-heading)
  7246. (run-hook-with-args 'org-cycle-hook 'subtree))
  7247. (message "Remote: SUBTREE"))
  7248. ((= more 4)
  7249. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7250. (org-drawer-regexp
  7251. (concat "^[ \t]*:\\("
  7252. (mapconcat 'regexp-quote org-drawers "\\|")
  7253. "\\):[ \t]*$")))
  7254. (show-subtree)
  7255. (save-excursion
  7256. (org-back-to-heading)
  7257. (org-cycle-hide-drawers 'subtree)))
  7258. (message "Remote: SUBTREE AND LOGBOOK"))
  7259. ((> more 4)
  7260. (show-subtree)
  7261. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7262. (select-window win)))
  7263. (defun org-recenter-heading (n)
  7264. (save-excursion
  7265. (org-back-to-heading)
  7266. (recenter n)))
  7267. (defvar org-agenda-cycle-counter nil)
  7268. (defun org-agenda-cycle-show (&optional n)
  7269. "Show the current entry in another window, with default settings.
  7270. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7271. When use repeatedly in immediate succession, the remote entry will cycle
  7272. through visibility
  7273. children -> subtree -> folded
  7274. When called with a numeric prefix arg, that arg will be passed through to
  7275. `org-agenda-show-1'. For the interpretation of that argument, see the
  7276. docstring of `org-agenda-show-1'."
  7277. (interactive "P")
  7278. (if (integerp n)
  7279. (setq org-agenda-cycle-counter n)
  7280. (if (not (eq last-command this-command))
  7281. (setq org-agenda-cycle-counter 1)
  7282. (if (equal org-agenda-cycle-counter 0)
  7283. (setq org-agenda-cycle-counter 2)
  7284. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7285. (if (> org-agenda-cycle-counter 3)
  7286. (setq org-agenda-cycle-counter 0)))))
  7287. (org-agenda-show-1 org-agenda-cycle-counter))
  7288. (defun org-agenda-recenter (arg)
  7289. "Display the Org-mode file which contains the item at point and recenter."
  7290. (interactive "P")
  7291. (let ((win (selected-window)))
  7292. (org-agenda-goto t)
  7293. (recenter arg)
  7294. (select-window win)))
  7295. (defun org-agenda-show-mouse (ev)
  7296. "Display the Org-mode file which contains the item at the mouse click."
  7297. (interactive "e")
  7298. (mouse-set-point ev)
  7299. (org-agenda-show))
  7300. (defun org-agenda-check-no-diary ()
  7301. "Check if the entry is a diary link and abort if yes."
  7302. (if (org-get-at-bol 'org-agenda-diary-link)
  7303. (org-agenda-error)))
  7304. (defun org-agenda-error ()
  7305. (error "Command not allowed in this line"))
  7306. (defun org-agenda-tree-to-indirect-buffer ()
  7307. "Show the subtree corresponding to the current entry in an indirect buffer.
  7308. This calls the command `org-tree-to-indirect-buffer' from the original
  7309. Org-mode buffer.
  7310. With numerical prefix arg ARG, go up to this level and then take that tree.
  7311. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7312. use the dedicated frame)."
  7313. (interactive)
  7314. (if (and current-prefix-arg (listp current-prefix-arg))
  7315. (org-agenda-do-tree-to-indirect-buffer)
  7316. (let ((agenda-window (selected-window))
  7317. (indirect-window
  7318. (and org-last-indirect-buffer
  7319. (get-buffer-window org-last-indirect-buffer))))
  7320. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7321. (unwind-protect
  7322. (progn
  7323. (unless (and indirect-window (window-live-p indirect-window))
  7324. (setq indirect-window (split-window agenda-window)))
  7325. (select-window indirect-window)
  7326. (switch-to-buffer org-last-indirect-buffer :norecord)
  7327. (fit-window-to-buffer indirect-window))
  7328. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7329. (defun org-agenda-do-tree-to-indirect-buffer ()
  7330. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7331. (org-agenda-check-no-diary)
  7332. (let* ((marker (or (org-get-at-bol 'org-marker)
  7333. (org-agenda-error)))
  7334. (buffer (marker-buffer marker))
  7335. (pos (marker-position marker)))
  7336. (with-current-buffer buffer
  7337. (save-excursion
  7338. (goto-char pos)
  7339. (call-interactively 'org-tree-to-indirect-buffer)))))
  7340. (defvar org-last-heading-marker (make-marker)
  7341. "Marker pointing to the headline that last changed its TODO state
  7342. by a remote command from the agenda.")
  7343. (defun org-agenda-todo-nextset ()
  7344. "Switch TODO entry to next sequence."
  7345. (interactive)
  7346. (org-agenda-todo 'nextset))
  7347. (defun org-agenda-todo-previousset ()
  7348. "Switch TODO entry to previous sequence."
  7349. (interactive)
  7350. (org-agenda-todo 'previousset))
  7351. (defun org-agenda-todo (&optional arg)
  7352. "Cycle TODO state of line at point, also in Org-mode file.
  7353. This changes the line at point, all other lines in the agenda referring to
  7354. the same tree node, and the headline of the tree node in the Org-mode file."
  7355. (interactive "P")
  7356. (org-agenda-check-no-diary)
  7357. (let* ((col (current-column))
  7358. (marker (or (org-get-at-bol 'org-marker)
  7359. (org-agenda-error)))
  7360. (buffer (marker-buffer marker))
  7361. (pos (marker-position marker))
  7362. (hdmarker (org-get-at-bol 'org-hd-marker))
  7363. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7364. (inhibit-read-only t)
  7365. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7366. (org-with-remote-undo buffer
  7367. (with-current-buffer buffer
  7368. (widen)
  7369. (goto-char pos)
  7370. (org-show-context 'agenda)
  7371. (save-excursion
  7372. (and (outline-next-heading)
  7373. (org-flag-heading nil))) ; show the next heading
  7374. (let ((current-prefix-arg arg))
  7375. (call-interactively 'org-todo))
  7376. (and (bolp) (forward-char 1))
  7377. (setq newhead (org-get-heading))
  7378. (when (and (org-bound-and-true-p
  7379. org-agenda-headline-snapshot-before-repeat)
  7380. (not (equal org-agenda-headline-snapshot-before-repeat
  7381. newhead))
  7382. todayp)
  7383. (setq newhead org-agenda-headline-snapshot-before-repeat
  7384. just-one t))
  7385. (save-excursion
  7386. (org-back-to-heading)
  7387. (move-marker org-last-heading-marker (point))))
  7388. (beginning-of-line 1)
  7389. (save-excursion
  7390. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7391. (org-move-to-column col))))
  7392. (defun org-agenda-add-note (&optional arg)
  7393. "Add a time-stamped note to the entry at point."
  7394. (interactive "P")
  7395. (org-agenda-check-no-diary)
  7396. (let* ((marker (or (org-get-at-bol 'org-marker)
  7397. (org-agenda-error)))
  7398. (buffer (marker-buffer marker))
  7399. (pos (marker-position marker))
  7400. (hdmarker (org-get-at-bol 'org-hd-marker))
  7401. (inhibit-read-only t))
  7402. (with-current-buffer buffer
  7403. (widen)
  7404. (goto-char pos)
  7405. (org-show-context 'agenda)
  7406. (save-excursion
  7407. (and (outline-next-heading)
  7408. (org-flag-heading nil))) ; show the next heading
  7409. (org-add-note))))
  7410. (defun org-agenda-change-all-lines (newhead hdmarker
  7411. &optional fixface just-this)
  7412. "Change all lines in the agenda buffer which match HDMARKER.
  7413. The new content of the line will be NEWHEAD (as modified by
  7414. `org-agenda-format-item'). HDMARKER is checked with
  7415. `equal' against all `org-hd-marker' text properties in the file.
  7416. If FIXFACE is non-nil, the face of each item is modified according to
  7417. the new TODO state.
  7418. If JUST-THIS is non-nil, change just the current line, not all.
  7419. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7420. (let* ((inhibit-read-only t)
  7421. (line (org-current-line))
  7422. (org-agenda-buffer (current-buffer))
  7423. (thetags (with-current-buffer (marker-buffer hdmarker)
  7424. (save-excursion (save-restriction (widen)
  7425. (goto-char hdmarker)
  7426. (org-get-tags-at)))))
  7427. props m pl undone-face done-face finish new dotime cat tags)
  7428. (save-excursion
  7429. (goto-char (point-max))
  7430. (beginning-of-line 1)
  7431. (while (not finish)
  7432. (setq finish (bobp))
  7433. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7434. (or (not just-this) (= (org-current-line) line))
  7435. (equal m hdmarker))
  7436. (setq props (text-properties-at (point))
  7437. dotime (org-get-at-bol 'dotime)
  7438. cat (org-get-at-bol 'org-category)
  7439. tags thetags
  7440. new
  7441. (let ((org-prefix-format-compiled
  7442. (or (get-text-property (point) 'format)
  7443. org-prefix-format-compiled))
  7444. (extra (org-get-at-bol 'extra)))
  7445. (with-current-buffer (marker-buffer hdmarker)
  7446. (save-excursion
  7447. (save-restriction
  7448. (widen)
  7449. (org-agenda-format-item extra newhead cat tags dotime)))))
  7450. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7451. undone-face (org-get-at-bol 'undone-face)
  7452. done-face (org-get-at-bol 'done-face))
  7453. (beginning-of-line 1)
  7454. (cond
  7455. ((equal new "")
  7456. (and (looking-at ".*\n?") (replace-match "")))
  7457. ((looking-at ".*")
  7458. (replace-match new t t)
  7459. (beginning-of-line 1)
  7460. (add-text-properties (point-at-bol) (point-at-eol) props)
  7461. (when fixface
  7462. (add-text-properties
  7463. (point-at-bol) (point-at-eol)
  7464. (list 'face
  7465. (if org-last-todo-state-is-todo
  7466. undone-face done-face))))
  7467. (org-agenda-highlight-todo 'line)
  7468. (beginning-of-line 1))
  7469. (t (error "Line update did not work"))))
  7470. (beginning-of-line 0)))
  7471. (org-agenda-finalize)))
  7472. (defun org-agenda-align-tags (&optional line)
  7473. "Align all tags in agenda items to `org-agenda-tags-column'."
  7474. (let ((inhibit-read-only t) l c)
  7475. (save-excursion
  7476. (goto-char (if line (point-at-bol) (point-min)))
  7477. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7478. (if line (point-at-eol) nil) t)
  7479. (add-text-properties
  7480. (match-beginning 2) (match-end 2)
  7481. (list 'face (delq nil (let ((prop (get-text-property
  7482. (match-beginning 2) 'face)))
  7483. (or (listp prop) (setq prop (list prop)))
  7484. (if (memq 'org-tag prop)
  7485. prop
  7486. (cons 'org-tag prop))))))
  7487. (setq l (- (match-end 2) (match-beginning 2))
  7488. c (if (< org-agenda-tags-column 0)
  7489. (- (abs org-agenda-tags-column) l)
  7490. org-agenda-tags-column))
  7491. (delete-region (match-beginning 1) (match-end 1))
  7492. (goto-char (match-beginning 1))
  7493. (insert (org-add-props
  7494. (make-string (max 1 (- c (current-column))) ?\ )
  7495. (plist-put (copy-sequence (text-properties-at (point)))
  7496. 'face nil))))
  7497. (goto-char (point-min))
  7498. (org-font-lock-add-tag-faces (point-max)))))
  7499. (defun org-agenda-priority-up ()
  7500. "Increase the priority of line at point, also in Org-mode file."
  7501. (interactive)
  7502. (org-agenda-priority 'up))
  7503. (defun org-agenda-priority-down ()
  7504. "Decrease the priority of line at point, also in Org-mode file."
  7505. (interactive)
  7506. (org-agenda-priority 'down))
  7507. (defun org-agenda-priority (&optional force-direction)
  7508. "Set the priority of line at point, also in Org-mode file.
  7509. This changes the line at point, all other lines in the agenda referring to
  7510. the same tree node, and the headline of the tree node in the Org-mode file."
  7511. (interactive)
  7512. (unless org-enable-priority-commands
  7513. (error "Priority commands are disabled"))
  7514. (org-agenda-check-no-diary)
  7515. (let* ((marker (or (org-get-at-bol 'org-marker)
  7516. (org-agenda-error)))
  7517. (hdmarker (org-get-at-bol 'org-hd-marker))
  7518. (buffer (marker-buffer hdmarker))
  7519. (pos (marker-position hdmarker))
  7520. (inhibit-read-only t)
  7521. newhead)
  7522. (org-with-remote-undo buffer
  7523. (with-current-buffer buffer
  7524. (widen)
  7525. (goto-char pos)
  7526. (org-show-context 'agenda)
  7527. (save-excursion
  7528. (and (outline-next-heading)
  7529. (org-flag-heading nil))) ; show the next heading
  7530. (funcall 'org-priority force-direction)
  7531. (end-of-line 1)
  7532. (setq newhead (org-get-heading)))
  7533. (org-agenda-change-all-lines newhead hdmarker)
  7534. (beginning-of-line 1))))
  7535. ;; FIXME: should fix the tags property of the agenda line.
  7536. (defun org-agenda-set-tags (&optional tag onoff)
  7537. "Set tags for the current headline."
  7538. (interactive)
  7539. (org-agenda-check-no-diary)
  7540. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7541. (call-interactively 'org-change-tag-in-region)
  7542. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7543. (org-agenda-error)))
  7544. (buffer (marker-buffer hdmarker))
  7545. (pos (marker-position hdmarker))
  7546. (inhibit-read-only t)
  7547. newhead)
  7548. (org-with-remote-undo buffer
  7549. (with-current-buffer buffer
  7550. (widen)
  7551. (goto-char pos)
  7552. (save-excursion
  7553. (org-show-context 'agenda))
  7554. (save-excursion
  7555. (and (outline-next-heading)
  7556. (org-flag-heading nil))) ; show the next heading
  7557. (goto-char pos)
  7558. (if tag
  7559. (org-toggle-tag tag onoff)
  7560. (call-interactively 'org-set-tags))
  7561. (end-of-line 1)
  7562. (setq newhead (org-get-heading)))
  7563. (org-agenda-change-all-lines newhead hdmarker)
  7564. (beginning-of-line 1)))))
  7565. (defun org-agenda-set-property ()
  7566. "Set a property for the current headline."
  7567. (interactive)
  7568. (org-agenda-check-no-diary)
  7569. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7570. (org-agenda-error)))
  7571. (buffer (marker-buffer hdmarker))
  7572. (pos (marker-position hdmarker))
  7573. (inhibit-read-only t)
  7574. newhead)
  7575. (org-with-remote-undo buffer
  7576. (with-current-buffer buffer
  7577. (widen)
  7578. (goto-char pos)
  7579. (save-excursion
  7580. (org-show-context 'agenda))
  7581. (save-excursion
  7582. (and (outline-next-heading)
  7583. (org-flag-heading nil))) ; show the next heading
  7584. (goto-char pos)
  7585. (call-interactively 'org-set-property)))))
  7586. (defun org-agenda-set-effort ()
  7587. "Set the effort property for the current headline."
  7588. (interactive)
  7589. (org-agenda-check-no-diary)
  7590. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7591. (org-agenda-error)))
  7592. (buffer (marker-buffer hdmarker))
  7593. (pos (marker-position hdmarker))
  7594. (inhibit-read-only t)
  7595. newhead)
  7596. (org-with-remote-undo buffer
  7597. (with-current-buffer buffer
  7598. (widen)
  7599. (goto-char pos)
  7600. (save-excursion
  7601. (org-show-context 'agenda))
  7602. (save-excursion
  7603. (and (outline-next-heading)
  7604. (org-flag-heading nil))) ; show the next heading
  7605. (goto-char pos)
  7606. (call-interactively 'org-set-effort)
  7607. (end-of-line 1)
  7608. (setq newhead (org-get-heading)))
  7609. (org-agenda-change-all-lines newhead hdmarker))))
  7610. (defun org-agenda-toggle-archive-tag ()
  7611. "Toggle the archive tag for the current entry."
  7612. (interactive)
  7613. (org-agenda-check-no-diary)
  7614. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7615. (org-agenda-error)))
  7616. (buffer (marker-buffer hdmarker))
  7617. (pos (marker-position hdmarker))
  7618. (inhibit-read-only t)
  7619. newhead)
  7620. (org-with-remote-undo buffer
  7621. (with-current-buffer buffer
  7622. (widen)
  7623. (goto-char pos)
  7624. (org-show-context 'agenda)
  7625. (save-excursion
  7626. (and (outline-next-heading)
  7627. (org-flag-heading nil))) ; show the next heading
  7628. (call-interactively 'org-toggle-archive-tag)
  7629. (end-of-line 1)
  7630. (setq newhead (org-get-heading)))
  7631. (org-agenda-change-all-lines newhead hdmarker)
  7632. (beginning-of-line 1))))
  7633. (defun org-agenda-do-date-later (arg)
  7634. (interactive "P")
  7635. (cond
  7636. ((or (equal arg '(16))
  7637. (memq last-command
  7638. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7639. (setq this-command 'org-agenda-date-later-minutes)
  7640. (org-agenda-date-later-minutes 1))
  7641. ((or (equal arg '(4))
  7642. (memq last-command
  7643. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7644. (setq this-command 'org-agenda-date-later-hours)
  7645. (org-agenda-date-later-hours 1))
  7646. (t
  7647. (org-agenda-date-later (prefix-numeric-value arg)))))
  7648. (defun org-agenda-do-date-earlier (arg)
  7649. (interactive "P")
  7650. (cond
  7651. ((or (equal arg '(16))
  7652. (memq last-command
  7653. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7654. (setq this-command 'org-agenda-date-earlier-minutes)
  7655. (org-agenda-date-earlier-minutes 1))
  7656. ((or (equal arg '(4))
  7657. (memq last-command
  7658. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7659. (setq this-command 'org-agenda-date-earlier-hours)
  7660. (org-agenda-date-earlier-hours 1))
  7661. (t
  7662. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7663. (defun org-agenda-date-later (arg &optional what)
  7664. "Change the date of this item to ARG day(s) later."
  7665. (interactive "p")
  7666. (org-agenda-check-type t 'agenda 'timeline)
  7667. (org-agenda-check-no-diary)
  7668. (let* ((marker (or (org-get-at-bol 'org-marker)
  7669. (org-agenda-error)))
  7670. (buffer (marker-buffer marker))
  7671. (pos (marker-position marker))
  7672. cdate today)
  7673. (org-with-remote-undo buffer
  7674. (with-current-buffer buffer
  7675. (widen)
  7676. (goto-char pos)
  7677. (if (not (org-at-timestamp-p))
  7678. (error "Cannot find time stamp"))
  7679. (when (and org-agenda-move-date-from-past-immediately-to-today
  7680. (equal arg 1)
  7681. (or (not what) (eq what 'day))
  7682. (not (save-match-data (org-at-date-range-p))))
  7683. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7684. cdate (calendar-absolute-from-gregorian
  7685. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7686. today (org-today))
  7687. (if (> today cdate)
  7688. ;; immediately shift to today
  7689. (setq arg (- today cdate))))
  7690. (org-timestamp-change arg (or what 'day))
  7691. (when (and (org-at-date-range-p)
  7692. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7693. (let ((end org-last-changed-timestamp))
  7694. (org-timestamp-change arg (or what 'day))
  7695. (setq org-last-changed-timestamp
  7696. (concat org-last-changed-timestamp "--" end)))))
  7697. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7698. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7699. (defun org-agenda-date-earlier (arg &optional what)
  7700. "Change the date of this item to ARG day(s) earlier."
  7701. (interactive "p")
  7702. (org-agenda-date-later (- arg) what))
  7703. (defun org-agenda-date-later-minutes (arg)
  7704. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7705. (interactive "p")
  7706. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7707. (org-agenda-date-later arg 'minute))
  7708. (defun org-agenda-date-earlier-minutes (arg)
  7709. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7710. (interactive "p")
  7711. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7712. (org-agenda-date-earlier arg 'minute))
  7713. (defun org-agenda-date-later-hours (arg)
  7714. "Change the time of this item, in hour steps."
  7715. (interactive "p")
  7716. (org-agenda-date-later arg 'hour))
  7717. (defun org-agenda-date-earlier-hours (arg)
  7718. "Change the time of this item, in hour steps."
  7719. (interactive "p")
  7720. (org-agenda-date-earlier arg 'hour))
  7721. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7722. "Show new date stamp via text properties."
  7723. ;; We use text properties to make this undoable
  7724. (let ((inhibit-read-only t)
  7725. (buffer-invisibility-spec))
  7726. (setq stamp (concat " " prefix " => " stamp))
  7727. (save-excursion
  7728. (goto-char (point-max))
  7729. (while (not (bobp))
  7730. (when (equal marker (org-get-at-bol 'org-marker))
  7731. (org-move-to-column (- (window-width) (length stamp)) t)
  7732. (org-agenda-fix-tags-filter-overlays-at (point))
  7733. (if (featurep 'xemacs)
  7734. ;; Use `duplicable' property to trigger undo recording
  7735. (let ((ex (make-extent nil nil))
  7736. (gl (make-glyph stamp)))
  7737. (set-glyph-face gl 'secondary-selection)
  7738. (set-extent-properties
  7739. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7740. (insert-extent ex (1- (point)) (point-at-eol)))
  7741. (add-text-properties
  7742. (1- (point)) (point-at-eol)
  7743. (list 'display (org-add-props stamp nil
  7744. 'face 'secondary-selection))))
  7745. (beginning-of-line 1))
  7746. (beginning-of-line 0)))))
  7747. (defun org-agenda-date-prompt (arg)
  7748. "Change the date of this item. Date is prompted for, with default today.
  7749. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7750. be used to request time specification in the time stamp."
  7751. (interactive "P")
  7752. (org-agenda-check-type t 'agenda 'timeline)
  7753. (org-agenda-check-no-diary)
  7754. (let* ((marker (or (org-get-at-bol 'org-marker)
  7755. (org-agenda-error)))
  7756. (buffer (marker-buffer marker))
  7757. (pos (marker-position marker)))
  7758. (org-with-remote-undo buffer
  7759. (with-current-buffer buffer
  7760. (widen)
  7761. (goto-char pos)
  7762. (if (not (org-at-timestamp-p t))
  7763. (error "Cannot find time stamp"))
  7764. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7765. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7766. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7767. (defun org-agenda-schedule (arg &optional time)
  7768. "Schedule the item at point.
  7769. ARG is passed through to `org-schedule'."
  7770. (interactive "P")
  7771. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7772. (org-agenda-check-no-diary)
  7773. (let* ((marker (or (org-get-at-bol 'org-marker)
  7774. (org-agenda-error)))
  7775. (type (marker-insertion-type marker))
  7776. (buffer (marker-buffer marker))
  7777. (pos (marker-position marker))
  7778. (org-insert-labeled-timestamps-at-point nil)
  7779. ts)
  7780. (set-marker-insertion-type marker t)
  7781. (org-with-remote-undo buffer
  7782. (with-current-buffer buffer
  7783. (widen)
  7784. (goto-char pos)
  7785. (setq ts (org-schedule arg time)))
  7786. (org-agenda-show-new-time marker ts "S"))
  7787. (message "Item scheduled for %s" ts)))
  7788. (defun org-agenda-deadline (arg &optional time)
  7789. "Schedule the item at point.
  7790. ARG is passed through to `org-deadline'."
  7791. (interactive "P")
  7792. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7793. (org-agenda-check-no-diary)
  7794. (let* ((marker (or (org-get-at-bol 'org-marker)
  7795. (org-agenda-error)))
  7796. (buffer (marker-buffer marker))
  7797. (pos (marker-position marker))
  7798. (org-insert-labeled-timestamps-at-point nil)
  7799. ts)
  7800. (org-with-remote-undo buffer
  7801. (with-current-buffer buffer
  7802. (widen)
  7803. (goto-char pos)
  7804. (setq ts (org-deadline arg time)))
  7805. (org-agenda-show-new-time marker ts "D"))
  7806. (message "Deadline for this item set to %s" ts)))
  7807. (defun org-agenda-action ()
  7808. "Select entry for agenda action, or execute an agenda action.
  7809. This command prompts for another letter. Valid inputs are:
  7810. m Mark the entry at point for an agenda action
  7811. s Schedule the marked entry to the date at the cursor
  7812. d Set the deadline of the marked entry to the date at the cursor
  7813. r Call `org-remember' with cursor date as the default date
  7814. c Call `org-capture' with cursor date as the default date
  7815. SPC Show marked entry in other window
  7816. TAB Visit marked entry in other window
  7817. The cursor may be at a date in the calendar, or in the Org agenda."
  7818. (interactive)
  7819. (let (ans)
  7820. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7821. (setq ans (read-char-exclusive))
  7822. (cond
  7823. ((equal ans ?m)
  7824. ;; Mark this entry
  7825. (if (eq major-mode 'org-agenda-mode)
  7826. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7827. (org-get-at-bol 'org-marker))))
  7828. (if m
  7829. (progn
  7830. (move-marker org-agenda-action-marker
  7831. (marker-position m) (marker-buffer m))
  7832. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7833. (error "Don't know which entry to mark")))
  7834. (error "This command works only in the agenda")))
  7835. ((equal ans ?s)
  7836. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7837. ((equal ans ?d)
  7838. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7839. ((equal ans ?r)
  7840. (org-agenda-do-action '(org-remember) t))
  7841. ((equal ans ?c)
  7842. (org-agenda-do-action '(org-capture) t))
  7843. ((equal ans ?\ )
  7844. (let ((cw (selected-window)))
  7845. (org-switch-to-buffer-other-window
  7846. (marker-buffer org-agenda-action-marker))
  7847. (goto-char org-agenda-action-marker)
  7848. (org-show-context 'agenda)
  7849. (select-window cw)))
  7850. ((equal ans ?\C-i)
  7851. (org-switch-to-buffer-other-window
  7852. (marker-buffer org-agenda-action-marker))
  7853. (goto-char org-agenda-action-marker)
  7854. (org-show-context 'agenda))
  7855. (t (error "Invalid agenda action %c" ans)))))
  7856. (defun org-agenda-do-action (form &optional current-buffer)
  7857. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7858. (let ((org-overriding-default-time (org-get-cursor-date)))
  7859. (if current-buffer
  7860. (eval form)
  7861. (if (not (marker-buffer org-agenda-action-marker))
  7862. (error "No entry has been selected for agenda action")
  7863. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7864. (save-excursion
  7865. (save-restriction
  7866. (widen)
  7867. (goto-char org-agenda-action-marker)
  7868. (eval form))))))))
  7869. (defun org-agenda-clock-in (&optional arg)
  7870. "Start the clock on the currently selected item."
  7871. (interactive "P")
  7872. (org-agenda-check-no-diary)
  7873. (if (equal arg '(4))
  7874. (org-clock-in arg)
  7875. (let* ((marker (or (org-get-at-bol 'org-marker)
  7876. (org-agenda-error)))
  7877. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7878. marker))
  7879. (pos (marker-position marker))
  7880. newhead)
  7881. (org-with-remote-undo (marker-buffer marker)
  7882. (with-current-buffer (marker-buffer marker)
  7883. (widen)
  7884. (goto-char pos)
  7885. (org-show-context 'agenda)
  7886. (org-show-entry)
  7887. (org-cycle-hide-drawers 'children)
  7888. (org-clock-in arg)
  7889. (setq newhead (org-get-heading)))
  7890. (org-agenda-change-all-lines newhead hdmarker)))))
  7891. (defun org-agenda-clock-out ()
  7892. "Stop the currently running clock."
  7893. (interactive)
  7894. (unless (marker-buffer org-clock-marker)
  7895. (error "No running clock"))
  7896. (let ((marker (make-marker)) newhead)
  7897. (org-with-remote-undo (marker-buffer org-clock-marker)
  7898. (with-current-buffer (marker-buffer org-clock-marker)
  7899. (save-excursion
  7900. (save-restriction
  7901. (widen)
  7902. (goto-char org-clock-marker)
  7903. (org-back-to-heading t)
  7904. (move-marker marker (point))
  7905. (org-clock-out)
  7906. (setq newhead (org-get-heading))))))
  7907. (org-agenda-change-all-lines newhead marker)
  7908. (move-marker marker nil)))
  7909. (defun org-agenda-clock-cancel (&optional arg)
  7910. "Cancel the currently running clock."
  7911. (interactive "P")
  7912. (unless (marker-buffer org-clock-marker)
  7913. (error "No running clock"))
  7914. (org-with-remote-undo (marker-buffer org-clock-marker)
  7915. (org-clock-cancel)))
  7916. (defun org-agenda-clock-goto ()
  7917. "Jump to the currently clocked in task within the agenda.
  7918. If the currently clocked in task is not listed in the agenda
  7919. buffer, display it in another window."
  7920. (interactive)
  7921. (let (pos)
  7922. (mapc (lambda (o)
  7923. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7924. (setq pos (overlay-start o))))
  7925. (overlays-in (point-min) (point-max)))
  7926. (cond (pos (goto-char pos))
  7927. ;; If the currently clocked entry is not in the agenda
  7928. ;; buffer, we visit it in another window:
  7929. (org-clock-current-task
  7930. (org-switch-to-buffer-other-window (org-clock-goto)))
  7931. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7932. (defun org-agenda-diary-entry-in-org-file ()
  7933. "Make a diary entry in the file `org-agenda-diary-file'."
  7934. (let (d1 d2 char (text "") dp1 dp2)
  7935. (if (equal (buffer-name) "*Calendar*")
  7936. (setq d1 (calendar-cursor-to-date t)
  7937. d2 (car calendar-mark-ring))
  7938. (setq dp1 (get-text-property (point-at-bol) 'day))
  7939. (unless dp1 (error "No date defined in current line"))
  7940. (setq d1 (calendar-gregorian-from-absolute dp1)
  7941. d2 (and (ignore-errors (mark))
  7942. (save-excursion
  7943. (goto-char (mark))
  7944. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7945. (calendar-gregorian-from-absolute dp2))))
  7946. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7947. (setq char (read-char-exclusive))
  7948. (cond
  7949. ((equal char ?d)
  7950. (setq text (read-string "Day entry: "))
  7951. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7952. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7953. ((equal char ?a)
  7954. (setq d1 (list (car d1) (nth 1 d1)
  7955. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7956. (nth 2 d1))))
  7957. (setq text (read-string "Anniversary (use %d to show years): "))
  7958. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7959. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7960. ((equal char ?b)
  7961. (setq text (read-string "Block entry: "))
  7962. (unless (and d1 d2 (not (equal d1 d2)))
  7963. (error "No block of days selected"))
  7964. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7965. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7966. ((equal char ?j)
  7967. (org-switch-to-buffer-other-window
  7968. (find-file-noselect org-agenda-diary-file))
  7969. (require 'org-datetree)
  7970. (org-datetree-find-date-create d1)
  7971. (org-reveal t))
  7972. (t (error "Invalid selection character `%c'" char)))))
  7973. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7974. "Where in `org-agenda-diary-file' should new entries be added?
  7975. Valid values:
  7976. date-tree in the date tree, as child of the date
  7977. top-level as top-level entries at the end of the file."
  7978. :group 'org-agenda
  7979. :type '(choice
  7980. (const :tag "in a date tree" date-tree)
  7981. (const :tag "as top level at end of file" top-level)))
  7982. (defcustom org-agenda-insert-diary-extract-time nil
  7983. "Non-nil means extract any time specification from the diary entry."
  7984. :group 'org-agenda
  7985. :version "24.1"
  7986. :type 'boolean)
  7987. (defcustom org-agenda-bulk-mark-char ">"
  7988. "A single-character string to be used as the bulk mark."
  7989. :group 'org-agenda
  7990. :version "24.1"
  7991. :type 'string)
  7992. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7993. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7994. If TEXT is not empty, it will become the headline of the new entry, and
  7995. the resulting entry will not be shown. When TEXT is empty, switch to
  7996. `org-agenda-diary-file' and let the user finish the entry there."
  7997. (let ((cw (current-window-configuration)))
  7998. (org-switch-to-buffer-other-window
  7999. (find-file-noselect org-agenda-diary-file))
  8000. (widen)
  8001. (goto-char (point-min))
  8002. (cond
  8003. ((eq type 'anniversary)
  8004. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8005. (progn
  8006. (or (org-at-heading-p t)
  8007. (progn
  8008. (outline-next-heading)
  8009. (insert "* Anniversaries\n\n")
  8010. (beginning-of-line -1)))))
  8011. (outline-next-heading)
  8012. (org-back-over-empty-lines)
  8013. (backward-char 1)
  8014. (insert "\n")
  8015. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8016. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8017. ((eq type 'day)
  8018. (let ((org-prefix-has-time t)
  8019. (org-agenda-time-leading-zero t)
  8020. fmt time time2)
  8021. (if org-agenda-insert-diary-extract-time
  8022. ;; Use org-agenda-format-item to parse text for a time-range and
  8023. ;; remove it. FIXME: This is a hack, we should refactor
  8024. ;; that function to make time extraction available separately
  8025. (setq fmt (org-agenda-format-item nil text nil nil t)
  8026. time (get-text-property 0 'time fmt)
  8027. time2 (if (> (length time) 0)
  8028. ;; split-string removes trailing ...... if
  8029. ;; no end time given. First space
  8030. ;; separates time from date.
  8031. (concat " " (car (split-string time "\\.")))
  8032. nil)
  8033. text (get-text-property 0 'txt fmt)))
  8034. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8035. (org-agenda-insert-diary-as-top-level text)
  8036. (require 'org-datetree)
  8037. (org-datetree-find-date-create d1)
  8038. (org-agenda-insert-diary-make-new-entry text))
  8039. (org-insert-time-stamp (org-time-from-absolute
  8040. (calendar-absolute-from-gregorian d1))
  8041. nil nil nil nil time2))
  8042. (end-of-line 0))
  8043. ((eq type 'block)
  8044. (if (> (calendar-absolute-from-gregorian d1)
  8045. (calendar-absolute-from-gregorian d2))
  8046. (setq d1 (prog1 d2 (setq d2 d1))))
  8047. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8048. (org-agenda-insert-diary-as-top-level text)
  8049. (require 'org-datetree)
  8050. (org-datetree-find-date-create d1)
  8051. (org-agenda-insert-diary-make-new-entry text))
  8052. (org-insert-time-stamp (org-time-from-absolute
  8053. (calendar-absolute-from-gregorian d1)))
  8054. (insert "--")
  8055. (org-insert-time-stamp (org-time-from-absolute
  8056. (calendar-absolute-from-gregorian d2)))
  8057. (end-of-line 0)))
  8058. (if (string-match "\\S-" text)
  8059. (progn
  8060. (set-window-configuration cw)
  8061. (message "%s entry added to %s"
  8062. (capitalize (symbol-name type))
  8063. (abbreviate-file-name org-agenda-diary-file)))
  8064. (org-reveal t)
  8065. (message "Please finish entry here"))))
  8066. (defun org-agenda-insert-diary-as-top-level (text)
  8067. "Make new entry as a top-level entry at the end of the file.
  8068. Add TEXT as headline, and position the cursor in the second line so that
  8069. a timestamp can be added there."
  8070. (widen)
  8071. (goto-char (point-max))
  8072. (or (bolp) (insert "\n"))
  8073. (insert "* " text "\n")
  8074. (if org-adapt-indentation (org-indent-to-column 2)))
  8075. (defun org-agenda-insert-diary-make-new-entry (text)
  8076. "Make new entry as last child of current entry.
  8077. Add TEXT as headline, and position the cursor in the second line so that
  8078. a timestamp can be added there."
  8079. (let ((org-show-following-heading t)
  8080. (org-show-siblings t)
  8081. (org-show-hierarchy-above t)
  8082. (org-show-entry-below t)
  8083. col)
  8084. (outline-next-heading)
  8085. (org-back-over-empty-lines)
  8086. (or (looking-at "[ \t]*$")
  8087. (progn (insert "\n") (backward-char 1)))
  8088. (org-insert-heading nil t)
  8089. (org-do-demote)
  8090. (setq col (current-column))
  8091. (insert text "\n")
  8092. (if org-adapt-indentation (org-indent-to-column col))
  8093. (let ((org-show-following-heading t)
  8094. (org-show-siblings t)
  8095. (org-show-hierarchy-above t)
  8096. (org-show-entry-below t))
  8097. (org-show-context))))
  8098. (defun org-agenda-diary-entry ()
  8099. "Make a diary entry, like the `i' command from the calendar.
  8100. All the standard commands work: block, weekly etc.
  8101. When `org-agenda-diary-file' points to a file,
  8102. `org-agenda-diary-entry-in-org-file' is called instead to create
  8103. entries in that Org-mode file."
  8104. (interactive)
  8105. (org-agenda-check-type t 'agenda 'timeline)
  8106. (if (not (eq org-agenda-diary-file 'diary-file))
  8107. (org-agenda-diary-entry-in-org-file)
  8108. (require 'diary-lib)
  8109. (let* ((char (progn
  8110. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8111. (read-char-exclusive)))
  8112. (cmd (cdr (assoc char
  8113. '((?d . insert-diary-entry)
  8114. (?w . insert-weekly-diary-entry)
  8115. (?m . insert-monthly-diary-entry)
  8116. (?y . insert-yearly-diary-entry)
  8117. (?a . insert-anniversary-diary-entry)
  8118. (?b . insert-block-diary-entry)
  8119. (?c . insert-cyclic-diary-entry)))))
  8120. (oldf (symbol-function 'calendar-cursor-to-date))
  8121. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8122. (point (point))
  8123. (mark (or (mark t) (point))))
  8124. (unless cmd
  8125. (error "No command associated with <%c>" char))
  8126. (unless (and (get-text-property point 'day)
  8127. (or (not (equal ?b char))
  8128. (get-text-property mark 'day)))
  8129. (error "Don't know which date to use for diary entry"))
  8130. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8131. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8132. (let ((calendar-mark-ring
  8133. (list (calendar-gregorian-from-absolute
  8134. (or (get-text-property mark 'day)
  8135. (get-text-property point 'day))))))
  8136. (unwind-protect
  8137. (progn
  8138. (fset 'calendar-cursor-to-date
  8139. (lambda (&optional error dummy)
  8140. (calendar-gregorian-from-absolute
  8141. (get-text-property point 'day))))
  8142. (call-interactively cmd))
  8143. (fset 'calendar-cursor-to-date oldf))))))
  8144. (defun org-agenda-execute-calendar-command (cmd)
  8145. "Execute a calendar command from the agenda, with the date associated to
  8146. the cursor position."
  8147. (org-agenda-check-type t 'agenda 'timeline)
  8148. (require 'diary-lib)
  8149. (unless (get-text-property (point) 'day)
  8150. (error "Don't know which date to use for calendar command"))
  8151. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8152. (point (point))
  8153. (date (calendar-gregorian-from-absolute
  8154. (get-text-property point 'day)))
  8155. ;; the following 2 vars are needed in the calendar
  8156. (displayed-month (car date))
  8157. (displayed-year (nth 2 date)))
  8158. (unwind-protect
  8159. (progn
  8160. (fset 'calendar-cursor-to-date
  8161. (lambda (&optional error dummy)
  8162. (calendar-gregorian-from-absolute
  8163. (get-text-property point 'day))))
  8164. (call-interactively cmd))
  8165. (fset 'calendar-cursor-to-date oldf))))
  8166. (defun org-agenda-phases-of-moon ()
  8167. "Display the phases of the moon for the 3 months around the cursor date."
  8168. (interactive)
  8169. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8170. (defun org-agenda-holidays ()
  8171. "Display the holidays for the 3 months around the cursor date."
  8172. (interactive)
  8173. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8174. (defvar calendar-longitude)
  8175. (defvar calendar-latitude)
  8176. (defvar calendar-location-name)
  8177. (defun org-agenda-sunrise-sunset (arg)
  8178. "Display sunrise and sunset for the cursor date.
  8179. Latitude and longitude can be specified with the variables
  8180. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8181. argument, latitude and longitude will be prompted for."
  8182. (interactive "P")
  8183. (require 'solar)
  8184. (let ((calendar-longitude (if arg nil calendar-longitude))
  8185. (calendar-latitude (if arg nil calendar-latitude))
  8186. (calendar-location-name
  8187. (if arg "the given coordinates" calendar-location-name)))
  8188. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8189. (defun org-agenda-goto-calendar ()
  8190. "Open the Emacs calendar with the date at the cursor."
  8191. (interactive)
  8192. (org-agenda-check-type t 'agenda 'timeline)
  8193. (let* ((day (or (get-text-property (point) 'day)
  8194. (error "Don't know which date to open in calendar")))
  8195. (date (calendar-gregorian-from-absolute day))
  8196. (calendar-move-hook nil)
  8197. (calendar-view-holidays-initially-flag nil)
  8198. (calendar-view-diary-initially-flag nil))
  8199. (calendar)
  8200. (calendar-goto-date date)))
  8201. ;;;###autoload
  8202. (defun org-calendar-goto-agenda ()
  8203. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8204. This is a command that has to be installed in `calendar-mode-map'."
  8205. (interactive)
  8206. (org-agenda-list nil (calendar-absolute-from-gregorian
  8207. (calendar-cursor-to-date))
  8208. nil))
  8209. (defun org-agenda-convert-date ()
  8210. (interactive)
  8211. (org-agenda-check-type t 'agenda 'timeline)
  8212. (let ((day (get-text-property (point) 'day))
  8213. date s)
  8214. (unless day
  8215. (error "Don't know which date to convert"))
  8216. (setq date (calendar-gregorian-from-absolute day))
  8217. (setq s (concat
  8218. "Gregorian: " (calendar-date-string date) "\n"
  8219. "ISO: " (calendar-iso-date-string date) "\n"
  8220. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8221. "Julian: " (calendar-julian-date-string date) "\n"
  8222. "Astron. JD: " (calendar-astro-date-string date)
  8223. " (Julian date number at noon UTC)\n"
  8224. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8225. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8226. "French: " (calendar-french-date-string date) "\n"
  8227. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8228. "Mayan: " (calendar-mayan-date-string date) "\n"
  8229. "Coptic: " (calendar-coptic-date-string date) "\n"
  8230. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8231. "Persian: " (calendar-persian-date-string date) "\n"
  8232. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8233. (with-output-to-temp-buffer "*Dates*"
  8234. (princ s))
  8235. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8236. ;;; Bulk commands
  8237. (defvar org-agenda-bulk-marked-entries nil
  8238. "List of markers that refer to marked entries in the agenda.")
  8239. (defun org-agenda-bulk-marked-p ()
  8240. (eq (get-char-property (point-at-bol) 'type)
  8241. 'org-marked-entry-overlay))
  8242. (defun org-agenda-bulk-mark (&optional arg)
  8243. "Mark the entry at point for future bulk action."
  8244. (interactive "p")
  8245. (dotimes (i (or arg 1))
  8246. (unless (org-get-at-bol 'org-agenda-diary-link)
  8247. (let* ((m (org-get-at-bol 'org-hd-marker))
  8248. ov)
  8249. (unless (org-agenda-bulk-marked-p)
  8250. (unless m (error "Nothing to mark at point"))
  8251. (push m org-agenda-bulk-marked-entries)
  8252. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8253. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8254. (org-get-todo-face "TODO")
  8255. 'evaporate)
  8256. (overlay-put ov 'type 'org-marked-entry-overlay))
  8257. (beginning-of-line 2)
  8258. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8259. (beginning-of-line 2))
  8260. (message "%d entries marked for bulk action"
  8261. (length org-agenda-bulk-marked-entries))))))
  8262. (defun org-agenda-bulk-mark-all ()
  8263. "Mark all entries for future agenda bulk action."
  8264. (interactive)
  8265. (org-agenda-bulk-mark-regexp "."))
  8266. (defun org-agenda-bulk-mark-regexp (regexp)
  8267. "Mark entries matching REGEXP for future agenda bulk action."
  8268. (interactive "sMark entries matching regexp: ")
  8269. (let ((entries-marked 0))
  8270. (save-excursion
  8271. (goto-char (point-min))
  8272. (goto-char (next-single-property-change (point) 'txt))
  8273. (while (re-search-forward regexp nil t)
  8274. (when (string-match regexp (get-text-property (point) 'txt))
  8275. (setq entries-marked (1+ entries-marked))
  8276. (call-interactively 'org-agenda-bulk-mark))))
  8277. (if (not entries-marked)
  8278. (message "No entry matching this regexp."))))
  8279. (defun org-agenda-bulk-unmark (&optional arg)
  8280. "Unmark the entry at point for future bulk action."
  8281. (interactive "P")
  8282. (if arg
  8283. (org-agenda-bulk-unmark-all)
  8284. (cond ((org-agenda-bulk-marked-p)
  8285. (org-agenda-bulk-remove-overlays
  8286. (point-at-bol) (+ 2 (point-at-bol)))
  8287. (setq org-agenda-bulk-marked-entries
  8288. (delete (org-get-at-bol 'org-hd-marker)
  8289. org-agenda-bulk-marked-entries))
  8290. (beginning-of-line 2)
  8291. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8292. (beginning-of-line 2))
  8293. (message "%d entries left marked for bulk action"
  8294. (length org-agenda-bulk-marked-entries)))
  8295. (t (message "No entry to unmark here")))))
  8296. (defun org-agenda-bulk-toggle ()
  8297. "Toggle marking the entry at point for bulk action."
  8298. (interactive)
  8299. (if (org-agenda-bulk-marked-p)
  8300. (org-agenda-bulk-unmark)
  8301. (org-agenda-bulk-mark)))
  8302. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8303. "Remove the mark overlays between BEG and END in the agenda buffer.
  8304. BEG and END default to the buffer limits.
  8305. This only removes the overlays, it does not remove the markers
  8306. from the list in `org-agenda-bulk-marked-entries'."
  8307. (interactive)
  8308. (mapc (lambda (ov)
  8309. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8310. (delete-overlay ov)))
  8311. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8312. (defun org-agenda-bulk-unmark-all ()
  8313. "Remove all marks in the agenda buffer.
  8314. This will remove the markers and the overlays."
  8315. (interactive)
  8316. (if (null org-agenda-bulk-marked-entries)
  8317. (message "No entry to unmark")
  8318. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8319. (setq org-agenda-bulk-marked-entries nil)
  8320. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8321. (defcustom org-agenda-persistent-marks nil
  8322. "Non-nil means marked items will stay marked after a bulk action.
  8323. You can toggle this interactively by typing `p' when prompted for a
  8324. bulk action."
  8325. :group 'org-agenda
  8326. :version "24.1"
  8327. :type 'boolean)
  8328. (defun org-agenda-bulk-action (&optional arg)
  8329. "Execute an remote-editing action on all marked entries.
  8330. The prefix arg is passed through to the command if possible."
  8331. (interactive "P")
  8332. ;; Make sure we have markers, and only valid ones
  8333. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8334. (mapc
  8335. (lambda (m)
  8336. (unless (and (markerp m)
  8337. (marker-buffer m)
  8338. (buffer-live-p (marker-buffer m))
  8339. (marker-position m))
  8340. (error "Marker %s for bulk command is invalid" m)))
  8341. org-agenda-bulk-marked-entries)
  8342. ;; Prompt for the bulk command
  8343. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8344. (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
  8345. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
  8346. (when org-agenda-bulk-custom-functions
  8347. (concat " Custom: ["
  8348. (mapconcat (lambda(f) (char-to-string (car f)))
  8349. org-agenda-bulk-custom-functions "")
  8350. "]"))))
  8351. (catch 'exit
  8352. (let* ((action (read-char-exclusive))
  8353. (org-log-refile (if org-log-refile 'time nil))
  8354. (entries (reverse org-agenda-bulk-marked-entries))
  8355. redo-at-end
  8356. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8357. (cond
  8358. ((equal action ?p)
  8359. (let ((org-agenda-persistent-marks
  8360. (not org-agenda-persistent-marks)))
  8361. (org-agenda-bulk-action)
  8362. (throw 'exit nil)))
  8363. ((equal action ?$)
  8364. (setq cmd '(org-agenda-archive)))
  8365. ((equal action ?A)
  8366. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8367. ((member action '(?r ?w))
  8368. (setq rfloc (org-refile-get-location
  8369. "Refile to"
  8370. (marker-buffer (car org-agenda-bulk-marked-entries))
  8371. org-refile-allow-creating-parent-nodes))
  8372. (if (nth 3 rfloc)
  8373. (setcar (nthcdr 3 rfloc)
  8374. (move-marker (make-marker) (nth 3 rfloc)
  8375. (or (get-file-buffer (nth 1 rfloc))
  8376. (find-buffer-visiting (nth 1 rfloc))
  8377. (error "This should not happen")))))
  8378. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8379. redo-at-end t))
  8380. ((equal action ?t)
  8381. (setq state (org-icompleting-read
  8382. "Todo state: "
  8383. (with-current-buffer (marker-buffer (car entries))
  8384. (mapcar 'list org-todo-keywords-1))))
  8385. (setq cmd `(let ((org-inhibit-blocking t)
  8386. (org-inhibit-logging 'note))
  8387. (org-agenda-todo ,state))))
  8388. ((memq action '(?- ?+))
  8389. (setq tag (org-icompleting-read
  8390. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8391. (with-current-buffer (marker-buffer (car entries))
  8392. (delq nil
  8393. (mapcar (lambda (x)
  8394. (if (stringp (car x)) x)) org-tag-alist)))))
  8395. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8396. ((memq action '(?s ?d))
  8397. (let* ((date (unless arg
  8398. (org-read-date
  8399. nil nil nil
  8400. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8401. (ans (if arg nil org-read-date-final-answer))
  8402. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8403. (setq cmd `(let* ((bound (fboundp 'read-string))
  8404. (old (and bound (symbol-function 'read-string))))
  8405. (unwind-protect
  8406. (progn
  8407. (fset 'read-string (lambda (&rest ignore) ,ans))
  8408. (eval '(,c1 arg)))
  8409. (if bound
  8410. (fset 'read-string old)
  8411. (fmakunbound 'read-string)))))))
  8412. ((equal action ?S)
  8413. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8414. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8415. (let ((days (read-number
  8416. (format "Scatter tasks across how many %sdays: "
  8417. (if arg "week" "")) 7)))
  8418. (setq cmd
  8419. `(let ((distance (1+ (random ,days))))
  8420. (if arg
  8421. (let ((dist distance)
  8422. (day-of-week
  8423. (calendar-day-of-week
  8424. (calendar-gregorian-from-absolute (org-today)))))
  8425. (dotimes (i (1+ dist))
  8426. (while (member day-of-week org-agenda-weekend-days)
  8427. (incf distance)
  8428. (incf day-of-week)
  8429. (if (= day-of-week 7)
  8430. (setq day-of-week 0)))
  8431. (incf day-of-week)
  8432. (if (= day-of-week 7)
  8433. (setq day-of-week 0)))))
  8434. ;; silently fail when try to replan a sexp entry
  8435. (condition-case nil
  8436. (let* ((date (calendar-gregorian-from-absolute
  8437. (+ (org-today) distance)))
  8438. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8439. (nth 2 date))))
  8440. (org-agenda-schedule nil time))
  8441. (error nil)))))))
  8442. ((assoc action org-agenda-bulk-custom-functions)
  8443. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8444. redo-at-end t))
  8445. ((equal action ?f)
  8446. (setq cmd (list (intern
  8447. (org-icompleting-read "Function: "
  8448. obarray 'fboundp t nil nil)))))
  8449. (t (error "Invalid bulk action")))
  8450. ;; Sort the markers, to make sure that parents are handled before children
  8451. (setq entries (sort entries
  8452. (lambda (a b)
  8453. (cond
  8454. ((equal (marker-buffer a) (marker-buffer b))
  8455. (< (marker-position a) (marker-position b)))
  8456. (t
  8457. (string< (buffer-name (marker-buffer a))
  8458. (buffer-name (marker-buffer b))))))))
  8459. ;; Now loop over all markers and apply cmd
  8460. (while (setq e (pop entries))
  8461. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8462. (if (not pos)
  8463. (progn (message "Skipping removed entry at %s" e)
  8464. (setq cntskip (1+ cntskip)))
  8465. (goto-char pos)
  8466. (let (org-loop-over-headlines-in-active-region)
  8467. (eval cmd))
  8468. (when (not org-agenda-persistent-marks)
  8469. (setq org-agenda-bulk-marked-entries
  8470. (delete e org-agenda-bulk-marked-entries)))
  8471. (setq cnt (1+ cnt))))
  8472. (when (not org-agenda-persistent-marks)
  8473. (org-agenda-bulk-unmark-all))
  8474. (when redo-at-end (org-agenda-redo))
  8475. (message "Acted on %d entries%s%s"
  8476. cnt
  8477. (if (= cntskip 0)
  8478. ""
  8479. (format ", skipped %d (disappeared before their turn)"
  8480. cntskip))
  8481. (if (not org-agenda-persistent-marks)
  8482. "" " (kept marked)"))))))
  8483. ;;; Flagging notes
  8484. (defun org-agenda-show-the-flagging-note ()
  8485. "Display the flagging note in the other window.
  8486. When called a second time in direct sequence, offer to remove the FLAGGING
  8487. tag and (if present) the flagging note."
  8488. (interactive)
  8489. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8490. (win (selected-window))
  8491. note heading newhead)
  8492. (unless hdmarker
  8493. (error "No linked entry at point"))
  8494. (if (and (eq this-command last-command)
  8495. (y-or-n-p "Unflag and remove any flagging note? "))
  8496. (progn
  8497. (org-agenda-remove-flag hdmarker)
  8498. (let ((win (get-buffer-window "*Flagging Note*")))
  8499. (and win (delete-window win)))
  8500. (message "Entry unflagged"))
  8501. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8502. (unless note
  8503. (error "No flagging note"))
  8504. (org-kill-new note)
  8505. (org-switch-to-buffer-other-window "*Flagging Note*")
  8506. (erase-buffer)
  8507. (insert note)
  8508. (goto-char (point-min))
  8509. (while (re-search-forward "\\\\n" nil t)
  8510. (replace-match "\n" t t))
  8511. (goto-char (point-min))
  8512. (select-window win)
  8513. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8514. (defun org-agenda-remove-flag (marker)
  8515. "Remove the FLAGGED tag and any flagging note in the entry."
  8516. (let (newhead)
  8517. (org-with-point-at marker
  8518. (org-toggle-tag "FLAGGED" 'off)
  8519. (org-entry-delete nil "THEFLAGGINGNOTE")
  8520. (setq newhead (org-get-heading)))
  8521. (org-agenda-change-all-lines newhead marker)
  8522. (message "Entry unflagged")))
  8523. (defun org-agenda-get-any-marker (&optional pos)
  8524. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8525. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8526. ;;; Appointment reminders
  8527. (defvar appt-time-msg-list)
  8528. ;;;###autoload
  8529. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8530. "Activate appointments found in `org-agenda-files'.
  8531. With a \\[universal-argument] prefix, refresh the list of
  8532. appointments.
  8533. If FILTER is t, interactively prompt the user for a regular
  8534. expression, and filter out entries that don't match it.
  8535. If FILTER is a string, use this string as a regular expression
  8536. for filtering entries out.
  8537. If FILTER is a function, filter out entries against which
  8538. calling the function returns nil. This function takes one
  8539. argument: an entry from `org-agenda-get-day-entries'.
  8540. FILTER can also be an alist with the car of each cell being
  8541. either 'headline or 'category. For example:
  8542. '((headline \"IMPORTANT\")
  8543. (category \"Work\"))
  8544. will only add headlines containing IMPORTANT or headlines
  8545. belonging to the \"Work\" category.
  8546. ARGS are symbols indicating what kind of entries to consider.
  8547. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8548. and :timestamp entries. See the docstring of `org-diary' for
  8549. details and examples.
  8550. If an entry as a APPT_WARNTIME property, its value will be used
  8551. to override `appt-message-warning-time'."
  8552. (interactive "P")
  8553. (if refresh (setq appt-time-msg-list nil))
  8554. (if (eq filter t)
  8555. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8556. (let* ((cnt 0) ; count added events
  8557. (scope (or args '(:deadline :scheduled :timestamp)))
  8558. (org-agenda-new-buffers nil)
  8559. (org-deadline-warning-days 0)
  8560. ;; Do not use `org-today' here because appt only takes
  8561. ;; time and without date as argument, so it may pass wrong
  8562. ;; information otherwise
  8563. (today (org-date-to-gregorian
  8564. (time-to-days (current-time))))
  8565. (org-agenda-restrict nil)
  8566. (files (org-agenda-files 'unrestricted)) entries file
  8567. (org-agenda-buffer nil))
  8568. ;; Get all entries which may contain an appt
  8569. (org-agenda-prepare-buffers files)
  8570. (while (setq file (pop files))
  8571. (setq entries
  8572. (delq nil
  8573. (append entries
  8574. (apply 'org-agenda-get-day-entries
  8575. file today scope)))))
  8576. ;; Map thru entries and find if we should filter them out
  8577. (mapc
  8578. (lambda(x)
  8579. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8580. (cat (get-text-property 1 'org-category x))
  8581. (tod (get-text-property 1 'time-of-day x))
  8582. (ok (or (null filter)
  8583. (and (stringp filter) (string-match filter evt))
  8584. (and (functionp filter) (funcall filter x))
  8585. (and (listp filter)
  8586. (let ((cat-filter (cadr (assoc 'category filter)))
  8587. (evt-filter (cadr (assoc 'headline filter))))
  8588. (or (and (stringp cat-filter)
  8589. (string-match cat-filter cat))
  8590. (and (stringp evt-filter)
  8591. (string-match evt-filter evt)))))))
  8592. (wrn (get-text-property 1 'warntime x)))
  8593. ;; FIXME: Shall we remove text-properties for the appt text?
  8594. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8595. (when (and ok tod)
  8596. (setq tod (concat "00" (number-to-string tod))
  8597. tod (when (string-match
  8598. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8599. (concat (match-string 1 tod) ":"
  8600. (match-string 2 tod))))
  8601. (if (version< emacs-version "23.3")
  8602. (appt-add tod evt)
  8603. (appt-add tod evt wrn))
  8604. (setq cnt (1+ cnt))))) entries)
  8605. (org-release-buffers org-agenda-new-buffers)
  8606. (if (eq cnt 0)
  8607. (message "No event to add")
  8608. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8609. (defun org-agenda-todayp (date)
  8610. "Does DATE mean today, when considering `org-extend-today-until'?"
  8611. (let ((today (org-today))
  8612. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8613. date)))
  8614. (eq date today)))
  8615. (defun org-agenda-todo-yesterday (&optional arg)
  8616. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8617. (interactive "P")
  8618. (let* ((hour (third (decode-time
  8619. (org-current-time))))
  8620. (org-extend-today-until (1+ hour)))
  8621. (org-agenda-todo arg)))
  8622. (provide 'org-agenda)
  8623. ;;; org-agenda.el ends here