org-agenda.el 377 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 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. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags do not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  661. "Time unit to use when possibly ignoring an agenda item.
  662. See the docstring of various `org-agenda-todo-ignore-*' options.
  663. The default is to compare time stamps using days. An item is thus
  664. considered to be in the future if it is at least one day after today.
  665. Non-nil means to compare time stamps using seconds. An item is then
  666. considered future if it has a time value later than current time."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-todo-list
  669. :type '(choice
  670. (const :tag "Compare time with days" nil)
  671. (const :tag "Compare time with seconds" t)))
  672. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  673. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  674. The variables
  675. `org-agenda-todo-ignore-with-date',
  676. `org-agenda-todo-ignore-timestamp',
  677. `org-agenda-todo-ignore-scheduled',
  678. `org-agenda-todo-ignore-deadlines'
  679. make the global TODO list skip entries that have time stamps of certain
  680. kinds. If this option is set, the same options will also apply for the
  681. tags-todo search, which is the general tags/property matcher
  682. restricted to unfinished TODO entries only."
  683. :group 'org-agenda-skip
  684. :group 'org-agenda-todo-list
  685. :group 'org-agenda-match-view
  686. :type 'boolean)
  687. (defcustom org-agenda-skip-scheduled-if-done nil
  688. "Non-nil means don't show scheduled items in agenda when they are done.
  689. This is relevant for the daily/weekly agenda, not for the TODO list. And
  690. it applies only to the actual date of the scheduling. Warnings about
  691. an item with a past scheduling dates are always turned off when the item
  692. is DONE."
  693. :group 'org-agenda-skip
  694. :group 'org-agenda-daily/weekly
  695. :type 'boolean)
  696. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  697. "Non-nil means skip scheduling line if same entry shows because of deadline.
  698. In the agenda of today, an entry can show up multiple times because
  699. it is both scheduled and has a nearby deadline, and maybe a plain time
  700. stamp as well.
  701. When this variable is t, then only the deadline is shown and the fact that
  702. the entry is scheduled today or was scheduled previously is not shown.
  703. When this variable is nil, the entry will be shown several times. When
  704. the variable is the symbol `not-today', then skip scheduled previously,
  705. but not scheduled today."
  706. :group 'org-agenda-skip
  707. :group 'org-agenda-daily/weekly
  708. :type '(choice
  709. (const :tag "Never" nil)
  710. (const :tag "Always" t)
  711. (const :tag "Not when scheduled today" not-today)))
  712. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  713. "Non-nil means skip timestamp line if same entry shows because of deadline.
  714. In the agenda of today, an entry can show up multiple times
  715. because it has both a plain timestamp and has a nearby deadline.
  716. When this variable is t, then only the deadline is shown and the
  717. fact that the entry has a timestamp for or including today is not
  718. shown. When this variable is nil, the entry will be shown
  719. several times."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :version "24.1"
  723. :type '(choice
  724. (const :tag "Never" nil)
  725. (const :tag "Always" t)))
  726. (defcustom org-agenda-skip-deadline-if-done nil
  727. "Non-nil means don't show deadlines when the corresponding item is done.
  728. When nil, the deadline is still shown and should give you a happy feeling.
  729. This is relevant for the daily/weekly agenda. And it applied only to the
  730. actually date of the deadline. Warnings about approaching and past-due
  731. deadlines are always turned off when the item is DONE."
  732. :group 'org-agenda-skip
  733. :group 'org-agenda-daily/weekly
  734. :type 'boolean)
  735. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  736. "Non-nil means skip deadline prewarning when entry is also scheduled.
  737. This will apply on all days where a prewarning for the deadline would
  738. be shown, but not at the day when the entry is actually due. On that day,
  739. the deadline will be shown anyway.
  740. This variable may be set to nil, t, the symbol `pre-scheduled',
  741. or a number which will then give the number of days before the actual
  742. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  743. eliminates the deadline prewarning only prior to the scheduled date.
  744. This can be used in a workflow where the first showing of the deadline will
  745. trigger you to schedule it, and then you don't want to be reminded of it
  746. because you will take care of it on the day when scheduled."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-daily/weekly
  749. :version "24.1"
  750. :type '(choice
  751. (const :tag "Always show prewarning" nil)
  752. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  753. (const :tag "Remove prewarning if entry is scheduled" t)
  754. (integer :tag "Restart prewarning N days before deadline")))
  755. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  756. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  757. When non-nil, after the search for timestamps has matched once in an
  758. entry, the rest of the entry will not be searched."
  759. :group 'org-agenda-skip
  760. :type 'boolean)
  761. (defcustom org-agenda-skip-timestamp-if-done nil
  762. "Non-nil means don't select item by timestamp or -range if it is DONE."
  763. :group 'org-agenda-skip
  764. :group 'org-agenda-daily/weekly
  765. :type 'boolean)
  766. (defcustom org-agenda-dim-blocked-tasks nil
  767. "Non-nil means dim blocked tasks in the agenda display.
  768. This causes some overhead during agenda construction, but if you
  769. have turned on `org-enforce-todo-dependencies',
  770. `org-enforce-todo-checkbox-dependencies', or any other blocking
  771. mechanism, this will create useful feedback in the agenda.
  772. Instead of t, this variable can also have the value `invisible'.
  773. Then blocked tasks will be invisible and only become visible when
  774. they become unblocked. An exemption to this behavior is when a task is
  775. blocked because of unchecked checkboxes below it. Since checkboxes do
  776. not show up in the agenda views, making this task invisible you remove any
  777. trace from agenda views that there is something to do. Therefore, a task
  778. that is blocked because of checkboxes will never be made invisible, it
  779. will only be dimmed."
  780. :group 'org-agenda-daily/weekly
  781. :group 'org-agenda-todo-list
  782. :version "24.3"
  783. :type '(choice
  784. (const :tag "Do not dim" nil)
  785. (const :tag "Dim to a gray face" t)
  786. (const :tag "Make invisible" invisible)))
  787. (defcustom org-timeline-show-empty-dates 3
  788. "Non-nil means `org-timeline' also shows dates without an entry.
  789. When nil, only the days which actually have entries are shown.
  790. When t, all days between the first and the last date are shown.
  791. When an integer, show also empty dates, but if there is a gap of more than
  792. N days, just insert a special line indicating the size of the gap."
  793. :group 'org-agenda-skip
  794. :type '(choice
  795. (const :tag "None" nil)
  796. (const :tag "All" t)
  797. (integer :tag "at most")))
  798. (defgroup org-agenda-startup nil
  799. "Options concerning initial settings in the Agenda in Org Mode."
  800. :tag "Org Agenda Startup"
  801. :group 'org-agenda)
  802. (defcustom org-agenda-menu-show-matcher t
  803. "Non-nil means show the match string in the agenda dispatcher menu.
  804. When nil, the matcher string is not shown, but is put into the help-echo
  805. property so than moving the mouse over the command shows it.
  806. Setting it to nil is good if matcher strings are very long and/or if
  807. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  808. :group 'org-agenda
  809. :version "24.1"
  810. :type 'boolean)
  811. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  812. (defcustom org-agenda-menu-two-columns nil
  813. "Non-nil means, use two columns to show custom commands in the dispatcher.
  814. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  815. to nil."
  816. :group 'org-agenda
  817. :version "24.1"
  818. :type 'boolean)
  819. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  820. (defcustom org-agenda-finalize-hook nil
  821. "Hook run just before displaying an agenda buffer.
  822. The buffer is still writable when the hook is called.
  823. You can modify some of the buffer substrings but you should be
  824. extra careful not to modify the text properties of the agenda
  825. headlines as the agenda display heavily relies on them."
  826. :group 'org-agenda-startup
  827. :type 'hook)
  828. (defcustom org-agenda-mouse-1-follows-link nil
  829. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  830. A longer mouse click will still set point. Does not work on XEmacs.
  831. Needs to be set before org.el is loaded."
  832. :group 'org-agenda-startup
  833. :type 'boolean)
  834. (defcustom org-agenda-start-with-follow-mode nil
  835. "The initial value of follow mode in a newly created agenda window."
  836. :group 'org-agenda-startup
  837. :type 'boolean)
  838. (defcustom org-agenda-follow-indirect nil
  839. "Non-nil means `org-agenda-follow-mode' displays only the
  840. current item's tree, in an indirect buffer."
  841. :group 'org-agenda
  842. :version "24.1"
  843. :type 'boolean)
  844. (defcustom org-agenda-show-outline-path t
  845. "Non-nil means show outline path in echo area after line motion."
  846. :group 'org-agenda-startup
  847. :type 'boolean)
  848. (defcustom org-agenda-start-with-entry-text-mode nil
  849. "The initial value of entry-text-mode in a newly created agenda window."
  850. :group 'org-agenda-startup
  851. :type 'boolean)
  852. (defcustom org-agenda-entry-text-maxlines 5
  853. "Number of text lines to be added when `E' is pressed in the agenda.
  854. Note that this variable only used during agenda display. Add add entry text
  855. when exporting the agenda, configure the variable
  856. `org-agenda-add-entry-ext-maxlines'."
  857. :group 'org-agenda
  858. :type 'integer)
  859. (defcustom org-agenda-entry-text-exclude-regexps nil
  860. "List of regular expressions to clean up entry text.
  861. The complete matches of all regular expressions in this list will be
  862. removed from entry text before it is shown in the agenda."
  863. :group 'org-agenda
  864. :type '(repeat (regexp)))
  865. (defvar org-agenda-entry-text-cleanup-hook nil
  866. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  867. This cleanup is done in a temporary buffer, so the function may inspect and
  868. change the entire buffer.
  869. Some default stuff like drawers and scheduling/deadline dates will already
  870. have been removed when this is called, as will any matches for regular
  871. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  872. (defvar org-agenda-include-inactive-timestamps nil
  873. "Non-nil means include inactive time stamps in agenda and timeline.
  874. Dynamically scoped.")
  875. (defgroup org-agenda-windows nil
  876. "Options concerning the windows used by the Agenda in Org Mode."
  877. :tag "Org Agenda Windows"
  878. :group 'org-agenda)
  879. (defcustom org-agenda-window-setup 'reorganize-frame
  880. "How the agenda buffer should be displayed.
  881. Possible values for this option are:
  882. current-window Show agenda in the current window, keeping all other windows.
  883. other-window Use `switch-to-buffer-other-window' to display agenda.
  884. reorganize-frame Show only two windows on the current frame, the current
  885. window and the agenda.
  886. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  887. Also, when exiting the agenda, kill that frame.
  888. See also the variable `org-agenda-restore-windows-after-quit'."
  889. :group 'org-agenda-windows
  890. :type '(choice
  891. (const current-window)
  892. (const other-frame)
  893. (const other-window)
  894. (const reorganize-frame)))
  895. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  896. "The min and max height of the agenda window as a fraction of frame height.
  897. The value of the variable is a cons cell with two numbers between 0 and 1.
  898. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  899. :group 'org-agenda-windows
  900. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  901. (defcustom org-agenda-restore-windows-after-quit nil
  902. "Non-nil means restore window configuration upon exiting agenda.
  903. Before the window configuration is changed for displaying the agenda,
  904. the current status is recorded. When the agenda is exited with
  905. `q' or `x' and this option is set, the old state is restored. If
  906. `org-agenda-window-setup' is `other-frame', the value of this
  907. option will be ignored."
  908. :group 'org-agenda-windows
  909. :type 'boolean)
  910. (defcustom org-agenda-ndays nil
  911. "Number of days to include in overview display.
  912. Should be 1 or 7.
  913. Obsolete, see `org-agenda-span'."
  914. :group 'org-agenda-daily/weekly
  915. :type 'integer)
  916. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  917. (defcustom org-agenda-span 'week
  918. "Number of days to include in overview display.
  919. Can be day, week, month, year, or any number of days.
  920. Custom commands can set this variable in the options section."
  921. :group 'org-agenda-daily/weekly
  922. :type '(choice (const :tag "Day" day)
  923. (const :tag "Week" week)
  924. (const :tag "Month" month)
  925. (const :tag "Year" year)
  926. (integer :tag "Custom")))
  927. (defcustom org-agenda-start-on-weekday 1
  928. "Non-nil means start the overview always on the specified weekday.
  929. 0 denotes Sunday, 1 denotes Monday etc.
  930. When nil, always start on the current day.
  931. Custom commands can set this variable in the options section."
  932. :group 'org-agenda-daily/weekly
  933. :type '(choice (const :tag "Today" nil)
  934. (integer :tag "Weekday No.")))
  935. (defcustom org-agenda-show-all-dates t
  936. "Non-nil means `org-agenda' shows every day in the selected range.
  937. When nil, only the days which actually have entries are shown."
  938. :group 'org-agenda-daily/weekly
  939. :type 'boolean)
  940. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  941. "Format string for displaying dates in the agenda.
  942. Used by the daily/weekly agenda and by the timeline. This should be
  943. a format string understood by `format-time-string', or a function returning
  944. the formatted date as a string. The function must take a single argument,
  945. a calendar-style date list like (month day year)."
  946. :group 'org-agenda-daily/weekly
  947. :type '(choice
  948. (string :tag "Format string")
  949. (function :tag "Function")))
  950. (defun org-agenda-format-date-aligned (date)
  951. "Format a date string for display in the daily/weekly agenda, or timeline.
  952. This function makes sure that dates are aligned for easy reading."
  953. (require 'cal-iso)
  954. (let* ((dayname (calendar-day-name date))
  955. (day (cadr date))
  956. (day-of-week (calendar-day-of-week date))
  957. (month (car date))
  958. (monthname (calendar-month-name month))
  959. (year (nth 2 date))
  960. (iso-week (org-days-to-iso-week
  961. (calendar-absolute-from-gregorian date)))
  962. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  963. (1- year))
  964. ((and (= month 12) (<= iso-week 1))
  965. (1+ year))
  966. (t year)))
  967. (weekstring (if (= day-of-week 1)
  968. (format " W%02d" iso-week)
  969. "")))
  970. (format "%-10s %2d %s %4d%s"
  971. dayname day monthname year weekstring)))
  972. (defcustom org-agenda-time-leading-zero nil
  973. "Non-nil means use leading zero for military times in agenda.
  974. For example, 9:30am would become 09:30 rather than 9:30."
  975. :group 'org-agenda-daily/weekly
  976. :version "24.1"
  977. :type 'boolean)
  978. (defcustom org-agenda-timegrid-use-ampm nil
  979. "When set, show AM/PM style timestamps on the timegrid."
  980. :group 'org-agenda
  981. :version "24.1"
  982. :type 'boolean)
  983. (defun org-agenda-time-of-day-to-ampm (time)
  984. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  985. (let* ((hour-number (string-to-number (substring time 0 -3)))
  986. (minute (substring time -2))
  987. (ampm "am"))
  988. (cond
  989. ((equal hour-number 12)
  990. (setq ampm "pm"))
  991. ((> hour-number 12)
  992. (setq ampm "pm")
  993. (setq hour-number (- hour-number 12))))
  994. (concat
  995. (if org-agenda-time-leading-zero
  996. (format "%02d" hour-number)
  997. (format "%02s" (number-to-string hour-number)))
  998. ":" minute ampm)))
  999. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1000. "Conditionally convert TIME to AM/PM format
  1001. based on `org-agenda-timegrid-use-ampm'"
  1002. (if org-agenda-timegrid-use-ampm
  1003. (org-agenda-time-of-day-to-ampm time)
  1004. time))
  1005. (defcustom org-agenda-weekend-days '(6 0)
  1006. "Which days are weekend?
  1007. These days get the special face `org-agenda-date-weekend' in the agenda
  1008. and timeline buffers."
  1009. :group 'org-agenda-daily/weekly
  1010. :type '(set :greedy t
  1011. (const :tag "Monday" 1)
  1012. (const :tag "Tuesday" 2)
  1013. (const :tag "Wednesday" 3)
  1014. (const :tag "Thursday" 4)
  1015. (const :tag "Friday" 5)
  1016. (const :tag "Saturday" 6)
  1017. (const :tag "Sunday" 0)))
  1018. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1019. "Non-nil means jump to today when moving a past date forward in time.
  1020. When using S-right in the agenda to move a a date forward, and the date
  1021. stamp currently points to the past, the first key press will move it
  1022. to today. WHen nil, just move one day forward even if the date stays
  1023. in the past."
  1024. :group 'org-agenda-daily/weekly
  1025. :version "24.1"
  1026. :type 'boolean)
  1027. (defcustom org-agenda-include-diary nil
  1028. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1029. Custom commands can set this variable in the options section."
  1030. :group 'org-agenda-daily/weekly
  1031. :type 'boolean)
  1032. (defcustom org-agenda-include-deadlines t
  1033. "If non-nil, include entries within their deadline warning period.
  1034. Custom commands can set this variable in the options section."
  1035. :group 'org-agenda-daily/weekly
  1036. :version "24.1"
  1037. :type 'boolean)
  1038. (defcustom org-agenda-repeating-timestamp-show-all t
  1039. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1040. When set to a list of strings, only show occurrences of repeating
  1041. stamps for these TODO keywords. When nil, only one occurrence is
  1042. shown, either today or the nearest into the future."
  1043. :group 'org-agenda-daily/weekly
  1044. :type '(choice
  1045. (const :tag "Show repeating stamps" t)
  1046. (repeat :tag "Show repeating stamps for these TODO keywords"
  1047. (string :tag "TODO Keyword"))
  1048. (const :tag "Don't show repeating stamps" nil)))
  1049. (defcustom org-scheduled-past-days 10000
  1050. "No. of days to continue listing scheduled items that are not marked DONE.
  1051. When an item is scheduled on a date, it shows up in the agenda on this
  1052. day and will be listed until it is marked done for the number of days
  1053. given here."
  1054. :group 'org-agenda-daily/weekly
  1055. :type 'integer)
  1056. (defcustom org-agenda-log-mode-items '(closed clock)
  1057. "List of items that should be shown in agenda log mode.
  1058. This list may contain the following symbols:
  1059. closed Show entries that have been closed on that day.
  1060. clock Show entries that have received clocked time on that day.
  1061. state Show all logged state changes.
  1062. Note that instead of changing this variable, you can also press `C-u l' in
  1063. the agenda to display all available LOG items temporarily."
  1064. :group 'org-agenda-daily/weekly
  1065. :type '(set :greedy t (const closed) (const clock) (const state)))
  1066. (defcustom org-agenda-clock-consistency-checks
  1067. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1068. :gap-ok-around ("4:00")
  1069. :default-face ((:background "DarkRed") (:foreground "white"))
  1070. :overlap-face nil :gap-face nil :no-end-time-face nil
  1071. :long-face nil :short-face nil)
  1072. "This is a property list, with the following keys:
  1073. :max-duration Mark clocking chunks that are longer than this time.
  1074. This is a time string like \"HH:MM\", or the number
  1075. of minutes as an integer.
  1076. :min-duration Mark clocking chunks that are shorter that this.
  1077. This is a time string like \"HH:MM\", or the number
  1078. of minutes as an integer.
  1079. :max-gap Mark gaps between clocking chunks that are longer than
  1080. this duration. A number of minutes, or a string
  1081. like \"HH:MM\".
  1082. :gap-ok-around List of times during the day which are usually not working
  1083. times. When a gap is detected, but the gap contains any
  1084. of these times, the gap is *not* reported. For example,
  1085. if this is (\"4:00\" \"13:00\") then gaps that contain
  1086. 4:00 in the morning (i.e. the night) and 13:00
  1087. (i.e. a typical lunch time) do not cause a warning.
  1088. You should have at least one time during the night in this
  1089. list, or otherwise the first task each morning will trigger
  1090. a warning because it follows a long gap.
  1091. Furthermore, the following properties can be used to define faces for
  1092. issue display.
  1093. :default-face the default face, if the specific face is undefined
  1094. :overlap-face face for overlapping clocks
  1095. :gap-face face for gaps between clocks
  1096. :no-end-time-face face for incomplete clocks
  1097. :long-face face for clock intervals that are too long
  1098. :short-face face for clock intervals that are too short"
  1099. :group 'org-agenda-daily/weekly
  1100. :group 'org-clock
  1101. :version "24.1"
  1102. :type 'plist)
  1103. (defcustom org-agenda-log-mode-add-notes t
  1104. "Non-nil means add first line of notes to log entries in agenda views.
  1105. If a log item like a state change or a clock entry is associated with
  1106. notes, the first line of these notes will be added to the entry in the
  1107. agenda display."
  1108. :group 'org-agenda-daily/weekly
  1109. :type 'boolean)
  1110. (defcustom org-agenda-start-with-log-mode nil
  1111. "The initial value of log-mode in a newly created agenda window.
  1112. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1113. explanations on the possible values."
  1114. :group 'org-agenda-startup
  1115. :group 'org-agenda-daily/weekly
  1116. :type '(choice (const :tag "Don't show log items" nil)
  1117. (const :tag "Show only log items" 'only)
  1118. (const :tag "Show all possible log items" 'clockcheck)
  1119. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1120. (choice (const :tag "Show closed log items" 'closed)
  1121. (const :tag "Show clocked log items" 'clock)
  1122. (const :tag "Show all logged state changes" 'state)))))
  1123. (defcustom org-agenda-start-with-clockreport-mode nil
  1124. "The initial value of clockreport-mode in a newly created agenda window."
  1125. :group 'org-agenda-startup
  1126. :group 'org-agenda-daily/weekly
  1127. :type 'boolean)
  1128. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1129. "Property list with parameters for the clocktable in clockreport mode.
  1130. This is the display mode that shows a clock table in the daily/weekly
  1131. agenda, the properties for this dynamic block can be set here.
  1132. The usual clocktable parameters are allowed here, but you cannot set
  1133. the properties :name, :tstart, :tend, :block, and :scope - these will
  1134. be overwritten to make sure the content accurately reflects the
  1135. current display in the agenda."
  1136. :group 'org-agenda-daily/weekly
  1137. :type 'plist)
  1138. (defcustom org-agenda-search-view-always-boolean nil
  1139. "Non-nil means the search string is interpreted as individual parts.
  1140. The search string for search view can either be interpreted as a phrase,
  1141. or as a list of snippets that define a boolean search for a number of
  1142. strings.
  1143. When this is non-nil, the string will be split on whitespace, and each
  1144. snippet will be searched individually, and all must match in order to
  1145. select an entry. A snippet is then a single string of non-white
  1146. characters, or a string in double quotes, or a regexp in {} braces.
  1147. If a snippet is preceded by \"-\", the snippet must *not* match.
  1148. \"+\" is syntactic sugar for positive selection. Each snippet may
  1149. be found as a full word or a partial word, but see the variable
  1150. `org-agenda-search-view-force-full-words'.
  1151. When this is nil, search will look for the entire search phrase as one,
  1152. with each space character matching any amount of whitespace, including
  1153. line breaks.
  1154. Even when this is nil, you can still switch to Boolean search dynamically
  1155. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1156. is a regexp marked with braces like \"{abc}\", this will also switch to
  1157. boolean search."
  1158. :group 'org-agenda-search-view
  1159. :version "24.1"
  1160. :type 'boolean)
  1161. (if (fboundp 'defvaralias)
  1162. (defvaralias 'org-agenda-search-view-search-words-only
  1163. 'org-agenda-search-view-always-boolean))
  1164. (defcustom org-agenda-search-view-force-full-words nil
  1165. "Non-nil means, search words must be matches as complete words.
  1166. When nil, they may also match part of a word."
  1167. :group 'org-agenda-search-view
  1168. :version "24.1"
  1169. :type 'boolean)
  1170. (defcustom org-agenda-search-view-max-outline-level nil
  1171. "Maximum outline level to display in search view.
  1172. E.g. when this is set to 1, the search view will only
  1173. show headlines of level 1."
  1174. :group 'org-agenda-search-view
  1175. :version "24.3"
  1176. :type 'integer)
  1177. (defgroup org-agenda-time-grid nil
  1178. "Options concerning the time grid in the Org-mode Agenda."
  1179. :tag "Org Agenda Time Grid"
  1180. :group 'org-agenda)
  1181. (defcustom org-agenda-search-headline-for-time t
  1182. "Non-nil means search headline for a time-of-day.
  1183. If the headline contains a time-of-day in one format or another, it will
  1184. be used to sort the entry into the time sequence of items for a day.
  1185. Some people have time stamps in the headline that refer to the creation
  1186. time or so, and then this produces an unwanted side effect. If this is
  1187. the case for your, use this variable to turn off searching the headline
  1188. for a time."
  1189. :group 'org-agenda-time-grid
  1190. :type 'boolean)
  1191. (defcustom org-agenda-use-time-grid t
  1192. "Non-nil means show a time grid in the agenda schedule.
  1193. A time grid is a set of lines for specific times (like every two hours between
  1194. 8:00 and 20:00). The items scheduled for a day at specific times are
  1195. sorted in between these lines.
  1196. For details about when the grid will be shown, and what it will look like, see
  1197. the variable `org-agenda-time-grid'."
  1198. :group 'org-agenda-time-grid
  1199. :type 'boolean)
  1200. (defcustom org-agenda-time-grid
  1201. '((daily today require-timed)
  1202. "----------------"
  1203. (800 1000 1200 1400 1600 1800 2000))
  1204. "The settings for time grid for agenda display.
  1205. This is a list of three items. The first item is again a list. It contains
  1206. symbols specifying conditions when the grid should be displayed:
  1207. daily if the agenda shows a single day
  1208. weekly if the agenda shows an entire week
  1209. today show grid on current date, independent of daily/weekly display
  1210. require-timed show grid only if at least one item has a time specification
  1211. The second item is a string which will be placed behind the grid time.
  1212. The third item is a list of integers, indicating the times that should have
  1213. a grid line."
  1214. :group 'org-agenda-time-grid
  1215. :type
  1216. '(list
  1217. (set :greedy t :tag "Grid Display Options"
  1218. (const :tag "Show grid in single day agenda display" daily)
  1219. (const :tag "Show grid in weekly agenda display" weekly)
  1220. (const :tag "Always show grid for today" today)
  1221. (const :tag "Show grid only if any timed entries are present"
  1222. require-timed)
  1223. (const :tag "Skip grid times already present in an entry"
  1224. remove-match))
  1225. (string :tag "Grid String")
  1226. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1227. (defcustom org-agenda-show-current-time-in-grid t
  1228. "Non-nil means show the current time in the time grid."
  1229. :group 'org-agenda-time-grid
  1230. :version "24.1"
  1231. :type 'boolean)
  1232. (defcustom org-agenda-current-time-string
  1233. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1234. "The string for the current time marker in the agenda."
  1235. :group 'org-agenda-time-grid
  1236. :version "24.1"
  1237. :type 'string)
  1238. (defgroup org-agenda-sorting nil
  1239. "Options concerning sorting in the Org-mode Agenda."
  1240. :tag "Org Agenda Sorting"
  1241. :group 'org-agenda)
  1242. (defcustom org-agenda-sorting-strategy
  1243. '((agenda habit-down time-up priority-down category-keep)
  1244. (todo priority-down category-keep)
  1245. (tags priority-down category-keep)
  1246. (search category-keep))
  1247. "Sorting structure for the agenda items of a single day.
  1248. This is a list of symbols which will be used in sequence to determine
  1249. if an entry should be listed before another entry. The following
  1250. symbols are recognized:
  1251. time-up Put entries with time-of-day indications first, early first
  1252. time-down Put entries with time-of-day indications first, late first
  1253. category-keep Keep the default order of categories, corresponding to the
  1254. sequence in `org-agenda-files'.
  1255. category-up Sort alphabetically by category, A-Z.
  1256. category-down Sort alphabetically by category, Z-A.
  1257. tag-up Sort alphabetically by last tag, A-Z.
  1258. tag-down Sort alphabetically by last tag, Z-A.
  1259. priority-up Sort numerically by priority, high priority last.
  1260. priority-down Sort numerically by priority, high priority first.
  1261. todo-state-up Sort by todo state, tasks that are done last.
  1262. todo-state-down Sort by todo state, tasks that are done first.
  1263. effort-up Sort numerically by estimated effort, high effort last.
  1264. effort-down Sort numerically by estimated effort, high effort first.
  1265. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1266. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1267. habit-up Put entries that are habits first
  1268. habit-down Put entries that are habits last
  1269. alpha-up Sort headlines alphabetically
  1270. alpha-down Sort headlines alphabetically, reversed
  1271. The different possibilities will be tried in sequence, and testing stops
  1272. if one comparison returns a \"not-equal\". For example, the default
  1273. '(time-up category-keep priority-down)
  1274. means: Pull out all entries having a specified time of day and sort them,
  1275. in order to make a time schedule for the current day the first thing in the
  1276. agenda listing for the day. Of the entries without a time indication, keep
  1277. the grouped in categories, don't sort the categories, but keep them in
  1278. the sequence given in `org-agenda-files'. Within each category sort by
  1279. priority.
  1280. Leaving out `category-keep' would mean that items will be sorted across
  1281. categories by priority.
  1282. Instead of a single list, this can also be a set of list for specific
  1283. contents, with a context symbol in the car of the list, any of
  1284. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1285. Custom commands can bind this variable in the options section."
  1286. :group 'org-agenda-sorting
  1287. :type `(choice
  1288. (repeat :tag "General" ,org-sorting-choice)
  1289. (list :tag "Individually"
  1290. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1291. (repeat ,org-sorting-choice))
  1292. (cons (const :tag "Strategy for TODO lists" todo)
  1293. (repeat ,org-sorting-choice))
  1294. (cons (const :tag "Strategy for Tags matches" tags)
  1295. (repeat ,org-sorting-choice))
  1296. (cons (const :tag "Strategy for search matches" search)
  1297. (repeat ,org-sorting-choice)))))
  1298. (defcustom org-agenda-cmp-user-defined nil
  1299. "A function to define the comparison `user-defined'.
  1300. This function must receive two arguments, agenda entry a and b.
  1301. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1302. the user comparison, return nil.
  1303. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1304. part of an agenda sorting strategy."
  1305. :group 'org-agenda-sorting
  1306. :type 'symbol)
  1307. (defcustom org-sort-agenda-notime-is-late t
  1308. "Non-nil means items without time are considered late.
  1309. This is only relevant for sorting. When t, items which have no explicit
  1310. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1311. do have a time. When nil, the default time is before 0:00. You can use this
  1312. option to decide if the schedule for today should come before or after timeless
  1313. agenda entries."
  1314. :group 'org-agenda-sorting
  1315. :type 'boolean)
  1316. (defcustom org-sort-agenda-noeffort-is-high t
  1317. "Non-nil means items without effort estimate are sorted as high effort.
  1318. This also applies when filtering an agenda view with respect to the
  1319. < or > effort operator. Then, tasks with no effort defined will be treated
  1320. as tasks with high effort.
  1321. When nil, such items are sorted as 0 minutes effort."
  1322. :group 'org-agenda-sorting
  1323. :type 'boolean)
  1324. (defgroup org-agenda-line-format nil
  1325. "Options concerning the entry prefix in the Org-mode agenda display."
  1326. :tag "Org Agenda Line Format"
  1327. :group 'org-agenda)
  1328. (defcustom org-agenda-prefix-format
  1329. '((agenda . " %i %-12:c%?-12t% s")
  1330. (timeline . " % s")
  1331. (todo . " %i %-12:c")
  1332. (tags . " %i %-12:c")
  1333. (search . " %i %-12:c"))
  1334. "Format specifications for the prefix of items in the agenda views.
  1335. An alist with five entries, each for the different agenda types. The
  1336. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1337. The values are format strings.
  1338. This format works similar to a printf format, with the following meaning:
  1339. %c the category of the item, \"Diary\" for entries from the diary,
  1340. or as given by the CATEGORY keyword or derived from the file name
  1341. %e the effort required by the item
  1342. %l the level of the item (insert X space(s) if item is of level X)
  1343. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1344. %T the last tag of the item (ignore inherited tags, which come first)
  1345. %t the HH:MM time-of-day specification if one applies to the entry
  1346. %s Scheduling/Deadline information, a short string
  1347. %(expression) Eval EXPRESSION and replace the control string
  1348. by the result
  1349. All specifiers work basically like the standard `%s' of printf, but may
  1350. contain two additional characters: a question mark just after the `%'
  1351. and a whitespace/punctuation character just before the final letter.
  1352. If the first character after `%' is a question mark, the entire field
  1353. will only be included if the corresponding value applies to the current
  1354. entry. This is useful for fields which should have fixed width when
  1355. present, but zero width when absent. For example, \"%?-12t\" will
  1356. result in a 12 character time field if a time of the day is specified,
  1357. but will completely disappear in entries which do not contain a time.
  1358. If there is punctuation or whitespace character just before the final
  1359. format letter, this character will be appended to the field value if
  1360. the value is not empty. For example, the format \"%-12:c\" leads to
  1361. \"Diary: \" if the category is \"Diary\". If the category were be
  1362. empty, no additional colon would be inserted.
  1363. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1364. which means:
  1365. - Indent the line with two space characters
  1366. - Give the category a 12 chars wide field, padded with whitespace on
  1367. the right (because of `-'). Append a colon if there is a category
  1368. (because of `:').
  1369. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1370. time, don't put in an empty field, just skip it (because of '?').
  1371. - Finally, put the scheduling information.
  1372. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1373. `org-agenda-remove-tags'.
  1374. Custom commands can set this variable in the options section."
  1375. :type '(choice
  1376. (string :tag "General format")
  1377. (list :greedy t :tag "View dependent"
  1378. (cons (const agenda) (string :tag "Format"))
  1379. (cons (const timeline) (string :tag "Format"))
  1380. (cons (const todo) (string :tag "Format"))
  1381. (cons (const tags) (string :tag "Format"))
  1382. (cons (const search) (string :tag "Format"))))
  1383. :group 'org-agenda-line-format)
  1384. (defvar org-prefix-format-compiled nil
  1385. "The compiled prefix format and associated variables.
  1386. This is a list where first element is a list of variable bindings, and second
  1387. element is the compiled format expression. See the variable
  1388. `org-agenda-prefix-format'.")
  1389. (defcustom org-agenda-todo-keyword-format "%-1s"
  1390. "Format for the TODO keyword in agenda lines.
  1391. Set this to something like \"%-12s\" if you want all TODO keywords
  1392. to occupy a fixed space in the agenda display."
  1393. :group 'org-agenda-line-format
  1394. :type 'string)
  1395. (defcustom org-agenda-diary-sexp-prefix nil
  1396. "A regexp that matches part of a diary sexp entry
  1397. which should be treated as scheduling/deadline information in
  1398. `org-agenda'.
  1399. For example, you can use this to extract the `diary-remind-message' from
  1400. `diary-remind' entries."
  1401. :group 'org-agenda-line-format
  1402. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1403. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1404. "Text preceding timerange entries in the agenda view.
  1405. This is a list with two strings. The first applies when the range
  1406. is entirely on one day. The second applies if the range spans several days.
  1407. The strings may have two \"%d\" format specifiers which will be filled
  1408. with the sequence number of the days, and the total number of days in the
  1409. range, respectively."
  1410. :group 'org-agenda-line-format
  1411. :type '(list
  1412. (string :tag "Deadline today ")
  1413. (choice :tag "Deadline relative"
  1414. (string :tag "Format string")
  1415. (function))))
  1416. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1417. "Text preceding scheduled items in the agenda view.
  1418. This is a list with two strings. The first applies when the item is
  1419. scheduled on the current day. The second applies when it has been scheduled
  1420. previously, it may contain a %d indicating that this is the nth time that
  1421. this item is scheduled, due to automatic rescheduling of unfinished items
  1422. for the following day. So this number is one larger than the number of days
  1423. that passed since this item was scheduled first."
  1424. :group 'org-agenda-line-format
  1425. :type '(list
  1426. (string :tag "Scheduled today ")
  1427. (string :tag "Scheduled previously")))
  1428. (defcustom org-agenda-inactive-leader "["
  1429. "Text preceding item pulled into the agenda by inactive time stamps.
  1430. These entries are added to the agenda when pressing \"[\"."
  1431. :group 'org-agenda-line-format
  1432. :version "24.1"
  1433. :type '(list
  1434. (string :tag "Scheduled today ")
  1435. (string :tag "Scheduled previously")))
  1436. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1437. "Text preceding deadline items in the agenda view.
  1438. This is a list with two strings. The first applies when the item has its
  1439. deadline on the current day. The second applies when it is in the past or
  1440. in the future, it may contain %d to capture how many days away the deadline
  1441. is (was)."
  1442. :group 'org-agenda-line-format
  1443. :type '(list
  1444. (string :tag "Deadline today ")
  1445. (choice :tag "Deadline relative"
  1446. (string :tag "Format string")
  1447. (function))))
  1448. (defcustom org-agenda-remove-times-when-in-prefix t
  1449. "Non-nil means remove duplicate time specifications in agenda items.
  1450. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1451. time-of-day specification in a headline or diary entry is extracted and
  1452. placed into the prefix. If this option is non-nil, the original specification
  1453. \(a timestamp or -range, or just a plain time(range) specification like
  1454. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1455. cluttered.
  1456. The option can be t or nil. It may also be the symbol `beg', indicating
  1457. that the time should only be removed when it is located at the beginning of
  1458. the headline/diary entry."
  1459. :group 'org-agenda-line-format
  1460. :type '(choice
  1461. (const :tag "Always" t)
  1462. (const :tag "Never" nil)
  1463. (const :tag "When at beginning of entry" beg)))
  1464. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1465. "Non-nil means remove time ranges specifications in agenda
  1466. items that span on several days."
  1467. :group 'org-agenda-line-format
  1468. :version "24.1"
  1469. :type 'boolean)
  1470. (defcustom org-agenda-default-appointment-duration nil
  1471. "Default duration for appointments that only have a starting time.
  1472. When nil, no duration is specified in such cases.
  1473. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1474. :group 'org-agenda-line-format
  1475. :type '(choice
  1476. (integer :tag "Minutes")
  1477. (const :tag "No default duration")))
  1478. (defcustom org-agenda-show-inherited-tags t
  1479. "Non-nil means show inherited tags in each agenda line.
  1480. When this option is set to 'always, it take precedences over
  1481. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1482. in every agenda.
  1483. When this option is set to t (the default), inherited tags are
  1484. shown when they are available, i.e. when the value of
  1485. `org-agenda-use-tag-inheritance' has been taken into account.
  1486. This can be set to a list of agenda types in which the agenda
  1487. must display the inherited tags. Available types are 'todo,
  1488. 'agenda, 'search and 'timeline.
  1489. When set to nil, never show inherited tags in agenda lines."
  1490. :group 'org-agenda-line-format
  1491. :group 'org-agenda
  1492. :version "24.3"
  1493. :type '(choice
  1494. (const :tag "Show inherited tags when available" t)
  1495. (const :tag "Always show inherited tags" 'always)
  1496. (repeat :tag "Show inherited tags only in selected agenda types"
  1497. (symbol :tag "Agenda type"))))
  1498. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1499. "List of agenda view types where to use tag inheritance.
  1500. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1501. controlled by `org-use-tag-inheritance'. In other agenda types,
  1502. `org-use-tag-inheritance' is not used for the selection of the
  1503. agenda entries. Still, you may want the agenda to be aware of
  1504. the inherited tags anyway, e.g. for later tag filtering.
  1505. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1506. This variable has no effect if `org-agenda-show-inherited-tags'
  1507. is set to 'always. In that case, the agenda is aware of those
  1508. tags.
  1509. The default value sets tags in every agenda type. Setting this
  1510. option to nil will speed up non-tags agenda view a lot."
  1511. :group 'org-agenda
  1512. :version "24.3"
  1513. :type '(choice
  1514. (const :tag "Use tag inheritance in all agenda types" t)
  1515. (repeat :tag "Use tag inheritance in selected agenda types"
  1516. (symbol :tag "Agenda type"))))
  1517. (defcustom org-agenda-hide-tags-regexp nil
  1518. "Regular expression used to filter away specific tags in agenda views.
  1519. This means that these tags will be present, but not be shown in the agenda
  1520. line. Secondary filtering will still work on the hidden tags.
  1521. Nil means don't hide any tags."
  1522. :group 'org-agenda-line-format
  1523. :type '(choice
  1524. (const :tag "Hide none" nil)
  1525. (string :tag "Regexp ")))
  1526. (defcustom org-agenda-remove-tags nil
  1527. "Non-nil means remove the tags from the headline copy in the agenda.
  1528. When this is the symbol `prefix', only remove tags when
  1529. `org-agenda-prefix-format' contains a `%T' specifier."
  1530. :group 'org-agenda-line-format
  1531. :type '(choice
  1532. (const :tag "Always" t)
  1533. (const :tag "Never" nil)
  1534. (const :tag "When prefix format contains %T" prefix)))
  1535. (if (fboundp 'defvaralias)
  1536. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1537. 'org-agenda-remove-tags))
  1538. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1539. "Shift tags in agenda items to this column.
  1540. If this number is positive, it specifies the column. If it is negative,
  1541. it means that the tags should be flushright to that column. For example,
  1542. -80 works well for a normal 80 character screen."
  1543. :group 'org-agenda-line-format
  1544. :type 'integer)
  1545. (if (fboundp 'defvaralias)
  1546. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1547. (defcustom org-agenda-fontify-priorities 'cookies
  1548. "Non-nil means highlight low and high priorities in agenda.
  1549. When t, the highest priority entries are bold, lowest priority italic.
  1550. However, settings in `org-priority-faces' will overrule these faces.
  1551. When this variable is the symbol `cookies', only fontify the
  1552. cookies, not the entire task.
  1553. This may also be an association list of priority faces, whose
  1554. keys are the character values of `org-highest-priority',
  1555. `org-default-priority', and `org-lowest-priority' (the default values
  1556. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1557. color as a string, or a list like `(:background \"Red\")'.
  1558. If it is a color, the variable `org-faces-easy-properties'
  1559. determines if it is a foreground or a background color."
  1560. :group 'org-agenda-line-format
  1561. :type '(choice
  1562. (const :tag "Never" nil)
  1563. (const :tag "Defaults" t)
  1564. (const :tag "Cookies only" cookies)
  1565. (repeat :tag "Specify"
  1566. (list (character :tag "Priority" :value ?A)
  1567. (choice :tag "Face "
  1568. (string :tag "Color")
  1569. (sexp :tag "Face"))))))
  1570. (defcustom org-agenda-day-face-function nil
  1571. "Function called to determine what face should be used to display a day.
  1572. The only argument passed to that function is the day. It should
  1573. returns a face, or nil if does not want to specify a face and let
  1574. the normal rules apply."
  1575. :group 'org-agenda-line-format
  1576. :version "24.1"
  1577. :type 'function)
  1578. (defcustom org-agenda-category-icon-alist nil
  1579. "Alist of category icon to be displayed in agenda views.
  1580. Each entry should have the following format:
  1581. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1582. Where CATEGORY-REGEXP is a regexp matching the categories where
  1583. the icon should be displayed.
  1584. FILE-OR-DATA either a file path or a string containing image data.
  1585. The other fields can be omitted safely if not needed:
  1586. TYPE indicates the image type.
  1587. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1588. image data.
  1589. PROPS are additional image attributes to assign to the image,
  1590. like, e.g. `:ascent center'.
  1591. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1592. If you want to set the display properties yourself, just put a
  1593. list as second element:
  1594. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1595. For example, to display a 16px horizontal space for Emacs
  1596. category, you can use:
  1597. (\"Emacs\" '(space . (:width (16))))"
  1598. :group 'org-agenda-line-format
  1599. :version "24.1"
  1600. :type '(alist :key-type (string :tag "Regexp matching category")
  1601. :value-type (choice (list :tag "Icon"
  1602. (string :tag "File or data")
  1603. (symbol :tag "Type")
  1604. (boolean :tag "Data?")
  1605. (repeat :tag "Extra image properties" :inline t symbol))
  1606. (list :tag "Display properties" sexp))))
  1607. (defgroup org-agenda-column-view nil
  1608. "Options concerning column view in the agenda."
  1609. :tag "Org Agenda Column View"
  1610. :group 'org-agenda)
  1611. (defcustom org-agenda-columns-show-summaries t
  1612. "Non-nil means show summaries for columns displayed in the agenda view."
  1613. :group 'org-agenda-column-view
  1614. :type 'boolean)
  1615. (defcustom org-agenda-columns-compute-summary-properties t
  1616. "Non-nil means recompute all summary properties before column view.
  1617. When column view in the agenda is listing properties that have a summary
  1618. operator, it can go to all relevant buffers and recompute the summaries
  1619. there. This can mean overhead for the agenda column view, but is necessary
  1620. to have thing up to date.
  1621. As a special case, a CLOCKSUM property also makes sure that the clock
  1622. computations are current."
  1623. :group 'org-agenda-column-view
  1624. :type 'boolean)
  1625. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1626. "Non-nil means the duration of an appointment will add to day effort.
  1627. The property to which appointment durations will be added is the one given
  1628. in the option `org-effort-property'. If an appointment does not have
  1629. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1630. is not set, an appointment without end time will not contribute to the time
  1631. estimate."
  1632. :group 'org-agenda-column-view
  1633. :type 'boolean)
  1634. (defcustom org-agenda-auto-exclude-function nil
  1635. "A function called with a tag to decide if it is filtered on '/ RET'.
  1636. The sole argument to the function, which is called once for each
  1637. possible tag, is a string giving the name of the tag. The
  1638. function should return either nil if the tag should be included
  1639. as normal, or \"-<TAG>\" to exclude the tag.
  1640. Note that for the purpose of tag filtering, only the lower-case version of
  1641. all tags will be considered, so that this function will only ever see
  1642. the lower-case version of all tags."
  1643. :group 'org-agenda
  1644. :type 'function)
  1645. (defcustom org-agenda-bulk-custom-functions nil
  1646. "Alist of characters and custom functions for bulk actions.
  1647. For example, this value makes those two functions available:
  1648. '((?R set-category)
  1649. (?C bulk-cut))
  1650. With selected entries in an agenda buffer, `B R' will call
  1651. the custom function `set-category' on the selected entries.
  1652. Note that functions in this alist don't need to be quoted."
  1653. :type 'alist
  1654. :version "24.1"
  1655. :group 'org-agenda)
  1656. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1657. "Execute BODY with point at location given by `org-hd-marker' property.
  1658. If STRING is non-nil, the text property will be fetched from position 0
  1659. in that string. If STRING is nil, it will be fetched from the beginning
  1660. of the current line."
  1661. (org-with-gensyms (marker)
  1662. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1663. 'org-hd-marker ,string)))
  1664. (with-current-buffer (marker-buffer ,marker)
  1665. (save-excursion
  1666. (goto-char ,marker)
  1667. ,@body)))))
  1668. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1669. (defun org-add-agenda-custom-command (entry)
  1670. "Replace or add a command in `org-agenda-custom-commands'.
  1671. This is mostly for hacking and trying a new command - once the command
  1672. works you probably want to add it to `org-agenda-custom-commands' for good."
  1673. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1674. (if ass
  1675. (setcdr ass (cdr entry))
  1676. (push entry org-agenda-custom-commands))))
  1677. ;;; Define the org-agenda-mode
  1678. (defvar org-agenda-mode-map (make-sparse-keymap)
  1679. "Keymap for `org-agenda-mode'.")
  1680. (if (fboundp 'defvaralias)
  1681. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1682. (defvar org-agenda-menu) ; defined later in this file.
  1683. (defvar org-agenda-restrict nil) ; defined later in this file.
  1684. (defvar org-agenda-follow-mode nil)
  1685. (defvar org-agenda-entry-text-mode nil)
  1686. (defvar org-agenda-clockreport-mode nil)
  1687. (defvar org-agenda-show-log nil)
  1688. (defvar org-agenda-redo-command nil)
  1689. (defvar org-agenda-query-string nil)
  1690. (defvar org-agenda-mode-hook nil
  1691. "Hook run after `org-agenda-mode' is turned on.
  1692. The buffer is still writable when this hook is called.")
  1693. (defvar org-agenda-type nil)
  1694. (defvar org-agenda-force-single-file nil)
  1695. (defvar org-agenda-bulk-marked-entries nil
  1696. "List of markers that refer to marked entries in the agenda.")
  1697. ;;; Multiple agenda buffers support
  1698. (defcustom org-agenda-sticky nil
  1699. "Non-nil means agenda q key will bury agenda buffers.
  1700. Agenda commands will then show existing buffer instead of generating new ones.
  1701. When nil, `q' will kill the single agenda buffer."
  1702. :group 'org-agenda
  1703. :version "24.3"
  1704. :type 'boolean)
  1705. ;;;###autoload
  1706. (defun org-toggle-sticky-agenda (&optional arg)
  1707. "Toggle `org-agenda-sticky'."
  1708. (interactive "P")
  1709. (let ((new-value (if arg
  1710. (> (prefix-numeric-value arg) 0)
  1711. (not org-agenda-sticky))))
  1712. (if (equal new-value org-agenda-sticky)
  1713. (and (org-called-interactively-p 'interactive)
  1714. (message "Sticky agenda was already %s"
  1715. (if org-agenda-sticky "enabled" "disabled")))
  1716. (setq org-agenda-sticky new-value)
  1717. (org-agenda-kill-all-agenda-buffers)
  1718. (and (org-called-interactively-p 'interactive)
  1719. (message "Sticky agenda was %s"
  1720. (if org-agenda-sticky "enabled" "disabled"))))))
  1721. (autoload 'org-toggle-sticky-agenda "org-agenda" "\
  1722. Toggle `org-agenda-sticky'.
  1723. \(fn &optional ARG)" t nil)
  1724. (defvar org-agenda-buffer nil
  1725. "Agenda buffer currently being generated.")
  1726. (defvar org-agenda-last-prefix-arg nil)
  1727. (defvar org-agenda-this-buffer-name nil)
  1728. (defvar org-agenda-doing-sticky-redo nil)
  1729. (defvar org-agenda-this-buffer-is-sticky nil)
  1730. (defconst org-agenda-local-vars
  1731. '(org-agenda-this-buffer-name
  1732. org-agenda-undo-list
  1733. org-agenda-pending-undo-list
  1734. org-agenda-follow-mode
  1735. org-agenda-entry-text-mode
  1736. org-agenda-clockreport-mode
  1737. org-agenda-show-log
  1738. org-agenda-redo-command
  1739. org-agenda-query-string
  1740. org-agenda-type
  1741. org-agenda-bulk-marked-entries
  1742. org-agenda-undo-has-started-in
  1743. org-agenda-info
  1744. org-agenda-tag-filter-overlays
  1745. org-agenda-cat-filter-overlays
  1746. org-agenda-pre-window-conf
  1747. org-agenda-columns-active
  1748. org-agenda-tag-filter
  1749. org-agenda-category-filter
  1750. org-agenda-markers
  1751. org-agenda-last-search-view-search-was-boolean
  1752. org-agenda-filtered-by-category
  1753. org-agenda-filter-form
  1754. org-agenda-show-window
  1755. org-agenda-cycle-counter
  1756. org-agenda-last-prefix-arg)
  1757. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1758. (defun org-agenda-mode ()
  1759. "Mode for time-sorted view on action items in Org-mode files.
  1760. The following commands are available:
  1761. \\{org-agenda-mode-map}"
  1762. (interactive)
  1763. (cond (org-agenda-doing-sticky-redo
  1764. ;; Refreshing sticky agenda-buffer
  1765. ;;
  1766. ;; Preserve the value of `org-agenda-local-vars' variables,
  1767. ;; while letting `kill-all-local-variables' kill the rest
  1768. (let ((save (buffer-local-variables)))
  1769. (kill-all-local-variables)
  1770. (mapc 'make-local-variable org-agenda-local-vars)
  1771. (dolist (elem save)
  1772. (let ((var (car elem))
  1773. (val (cdr elem)))
  1774. (when (and val
  1775. (member var org-agenda-local-vars))
  1776. (set var val)))))
  1777. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1778. (org-agenda-sticky
  1779. ;; Creating a sticky Agenda buffer for the first time
  1780. (kill-all-local-variables)
  1781. (mapc 'make-local-variable org-agenda-local-vars)
  1782. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1783. (t
  1784. ;; Creating a non-sticky agenda buffer
  1785. (kill-all-local-variables)
  1786. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1787. (setq org-agenda-undo-list nil
  1788. org-agenda-pending-undo-list nil
  1789. org-agenda-bulk-marked-entries nil)
  1790. (setq major-mode 'org-agenda-mode)
  1791. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1792. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1793. (setq mode-name "Org-Agenda")
  1794. (use-local-map org-agenda-mode-map)
  1795. (easy-menu-add org-agenda-menu)
  1796. (if org-startup-truncated (setq truncate-lines t))
  1797. (org-set-local 'line-move-visual nil)
  1798. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1799. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1800. ;; Make sure properties are removed when copying text
  1801. (make-local-variable 'filter-buffer-substring-functions)
  1802. (add-hook 'filter-buffer-substring-functions
  1803. (lambda (fun start end delete)
  1804. (substring-no-properties (funcall fun start end delete))))
  1805. (unless org-agenda-keep-modes
  1806. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1807. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1808. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1809. org-agenda-show-log org-agenda-start-with-log-mode))
  1810. (easy-menu-change
  1811. '("Agenda") "Agenda Files"
  1812. (append
  1813. (list
  1814. (vector
  1815. (if (get 'org-agenda-files 'org-restrict)
  1816. "Restricted to single file"
  1817. "Edit File List")
  1818. '(org-edit-agenda-file-list)
  1819. (not (get 'org-agenda-files 'org-restrict)))
  1820. "--")
  1821. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1822. (org-agenda-set-mode-name)
  1823. (apply
  1824. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1825. (list 'org-agenda-mode-hook)))
  1826. (substitute-key-definition 'undo 'org-agenda-undo
  1827. org-agenda-mode-map global-map)
  1828. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1829. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1830. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1831. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1833. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1834. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1835. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1836. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1837. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1838. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1839. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1840. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1841. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1842. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1843. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1844. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1845. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1846. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1847. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1848. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1849. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1850. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1851. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1852. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1853. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1854. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1855. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1856. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1857. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1858. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1859. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1860. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1861. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1862. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1863. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1864. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1865. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1866. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1867. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1868. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1869. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1870. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1871. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1872. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1873. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1874. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1875. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1877. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1878. (while l (org-defkey org-agenda-mode-map
  1879. (int-to-string (pop l)) 'digit-argument)))
  1880. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1881. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1882. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1883. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1884. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1885. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1886. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1887. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1888. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1889. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1890. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1891. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1892. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1893. 'org-clock-modify-effort-estimate)
  1894. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1895. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1896. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1897. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1898. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1899. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1900. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1901. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1902. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1903. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1904. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1905. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1906. (substitute-key-definition 'next-line 'org-agenda-next-line
  1907. org-agenda-mode-map global-map)
  1908. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1909. org-agenda-mode-map global-map)
  1910. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1911. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1912. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1913. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1914. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1915. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1916. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1917. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1918. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1919. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1920. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1921. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1922. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1923. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1924. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1925. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1926. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1927. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1928. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1929. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1930. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1931. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1932. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1933. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1934. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1935. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1936. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1937. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1940. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1941. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1942. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1943. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1944. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1945. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1946. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1947. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1948. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1949. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1950. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1951. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1952. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1953. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1954. (when org-agenda-mouse-1-follows-link
  1955. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1956. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1957. '("Agenda"
  1958. ("Agenda Files")
  1959. "--"
  1960. ("Agenda Dates"
  1961. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1962. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1963. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1964. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1965. "--"
  1966. ("View"
  1967. ["Day View" org-agenda-day-view
  1968. :active (org-agenda-check-type nil 'agenda)
  1969. :style radio :selected (eq org-agenda-current-span 'day)
  1970. :keys "v d (or just d)"]
  1971. ["Week View" org-agenda-week-view
  1972. :active (org-agenda-check-type nil 'agenda)
  1973. :style radio :selected (eq org-agenda-current-span 'week)
  1974. :keys "v w (or just w)"]
  1975. ["Month View" org-agenda-month-view
  1976. :active (org-agenda-check-type nil 'agenda)
  1977. :style radio :selected (eq org-agenda-current-span 'month)
  1978. :keys "v m"]
  1979. ["Year View" org-agenda-year-view
  1980. :active (org-agenda-check-type nil 'agenda)
  1981. :style radio :selected (eq org-agenda-current-span 'year)
  1982. :keys "v y"]
  1983. "--"
  1984. ["Include Diary" org-agenda-toggle-diary
  1985. :style toggle :selected org-agenda-include-diary
  1986. :active (org-agenda-check-type nil 'agenda)]
  1987. ["Include Deadlines" org-agenda-toggle-deadlines
  1988. :style toggle :selected org-agenda-include-deadlines
  1989. :active (org-agenda-check-type nil 'agenda)]
  1990. ["Use Time Grid" org-agenda-toggle-time-grid
  1991. :style toggle :selected org-agenda-use-time-grid
  1992. :active (org-agenda-check-type nil 'agenda)]
  1993. "--"
  1994. ["Show clock report" org-agenda-clockreport-mode
  1995. :style toggle :selected org-agenda-clockreport-mode
  1996. :active (org-agenda-check-type nil 'agenda)]
  1997. ["Show some entry text" org-agenda-entry-text-mode
  1998. :style toggle :selected org-agenda-entry-text-mode
  1999. :active t]
  2000. "--"
  2001. ["Show Logbook entries" org-agenda-log-mode
  2002. :style toggle :selected org-agenda-show-log
  2003. :active (org-agenda-check-type nil 'agenda 'timeline)
  2004. :keys "v l (or just l)"]
  2005. ["Include archived trees" org-agenda-archives-mode
  2006. :style toggle :selected org-agenda-archives-mode :active t
  2007. :keys "v a"]
  2008. ["Include archive files" (org-agenda-archives-mode t)
  2009. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2010. :keys "v A"]
  2011. "--"
  2012. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2013. ["Write view to file" org-agenda-write t]
  2014. ["Rebuild buffer" org-agenda-redo t]
  2015. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2016. "--"
  2017. ["Show original entry" org-agenda-show t]
  2018. ["Go To (other window)" org-agenda-goto t]
  2019. ["Go To (this window)" org-agenda-switch-to t]
  2020. ["Capture with cursor date" org-agenda-capture t]
  2021. ["Follow Mode" org-agenda-follow-mode
  2022. :style toggle :selected org-agenda-follow-mode :active t]
  2023. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2024. "--"
  2025. ("TODO"
  2026. ["Cycle TODO" org-agenda-todo t]
  2027. ["Next TODO set" org-agenda-todo-nextset t]
  2028. ["Previous TODO set" org-agenda-todo-previousset t]
  2029. ["Add note" org-agenda-add-note t])
  2030. ("Archive/Refile/Delete"
  2031. ["Archive default" org-agenda-archive-default t]
  2032. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2033. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2034. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2035. ["Archive subtree" org-agenda-archive t]
  2036. "--"
  2037. ["Refile" org-agenda-refile t]
  2038. "--"
  2039. ["Delete subtree" org-agenda-kill t])
  2040. ("Bulk action"
  2041. ["Mark entry" org-agenda-bulk-mark t]
  2042. ["Mark all" org-agenda-bulk-mark-all t]
  2043. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2044. ["Unmark entry" org-agenda-bulk-unmark t]
  2045. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2046. ["Act on all marked" org-agenda-bulk-action t]
  2047. "--"
  2048. ("Tags and Properties"
  2049. ["Show all Tags" org-agenda-show-tags t]
  2050. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2051. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2052. "--"
  2053. ["Column View" org-columns t])
  2054. ("Deadline/Schedule"
  2055. ["Schedule" org-agenda-schedule t]
  2056. ["Set Deadline" org-agenda-deadline t]
  2057. "--"
  2058. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2059. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2060. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2061. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2062. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2063. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2064. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2065. ("Clock and Effort"
  2066. ["Clock in" org-agenda-clock-in t]
  2067. ["Clock out" org-agenda-clock-out t]
  2068. ["Clock cancel" org-agenda-clock-cancel t]
  2069. ["Goto running clock" org-clock-goto t]
  2070. "--"
  2071. ["Set Effort" org-agenda-set-effort t]
  2072. ["Change clocked effort" org-clock-modify-effort-estimate
  2073. (org-clock-is-active)])
  2074. ("Priority"
  2075. ["Set Priority" org-agenda-priority t]
  2076. ["Increase Priority" org-agenda-priority-up t]
  2077. ["Decrease Priority" org-agenda-priority-down t]
  2078. ["Show Priority" org-show-priority t])
  2079. ("Calendar/Diary"
  2080. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2081. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2082. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2083. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2084. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2085. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2086. "--"
  2087. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2088. "--"
  2089. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2090. "--"
  2091. ("MobileOrg"
  2092. ["Push Files and Views" org-mobile-push t]
  2093. ["Get Captured and Flagged" org-mobile-pull t]
  2094. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2095. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2096. "--"
  2097. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2098. "--"
  2099. ["Quit" org-agenda-quit t]
  2100. ["Exit and Release Buffers" org-agenda-exit t]
  2101. ))
  2102. ;;; Agenda undo
  2103. (defvar org-agenda-allow-remote-undo t
  2104. "Non-nil means allow remote undo from the agenda buffer.")
  2105. (defvar org-agenda-undo-has-started-in nil
  2106. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2107. (defun org-agenda-undo ()
  2108. "Undo a remote editing step in the agenda.
  2109. This undoes changes both in the agenda buffer and in the remote buffer
  2110. that have been changed along."
  2111. (interactive)
  2112. (or org-agenda-allow-remote-undo
  2113. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2114. (if (not (eq this-command last-command))
  2115. (setq org-agenda-undo-has-started-in nil
  2116. org-agenda-pending-undo-list org-agenda-undo-list))
  2117. (if (not org-agenda-pending-undo-list)
  2118. (error "No further undo information"))
  2119. (let* ((entry (pop org-agenda-pending-undo-list))
  2120. buf line cmd rembuf)
  2121. (setq cmd (pop entry) line (pop entry))
  2122. (setq rembuf (nth 2 entry))
  2123. (org-with-remote-undo rembuf
  2124. (while (bufferp (setq buf (pop entry)))
  2125. (if (pop entry)
  2126. (with-current-buffer buf
  2127. (let ((last-undo-buffer buf)
  2128. (inhibit-read-only t))
  2129. (unless (memq buf org-agenda-undo-has-started-in)
  2130. (push buf org-agenda-undo-has-started-in)
  2131. (make-local-variable 'pending-undo-list)
  2132. (undo-start))
  2133. (while (and pending-undo-list
  2134. (listp pending-undo-list)
  2135. (not (car pending-undo-list)))
  2136. (pop pending-undo-list))
  2137. (undo-more 1))))))
  2138. (org-goto-line line)
  2139. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2140. (defun org-verify-change-for-undo (l1 l2)
  2141. "Verify that a real change occurred between the undo lists L1 and L2."
  2142. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2143. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2144. (not (eq l1 l2)))
  2145. ;;; Agenda dispatch
  2146. (defvar org-agenda-restrict-begin (make-marker))
  2147. (defvar org-agenda-restrict-end (make-marker))
  2148. (defvar org-agenda-last-dispatch-buffer nil)
  2149. (defvar org-agenda-overriding-restriction nil)
  2150. (defcustom org-agenda-custom-commands-contexts nil
  2151. "Alist of custom agenda keys and contextual rules.
  2152. For example, if you have a custom agenda command \"p\" and you
  2153. want this command to be accessible only from plain text files,
  2154. use this:
  2155. '((\"p\" ((in-file . \"\\.txt\"))))
  2156. Here are the available contexts definitions:
  2157. in-file: command displayed only in matching files
  2158. in-mode: command displayed only in matching modes
  2159. not-in-file: command not displayed in matching files
  2160. not-in-mode: command not displayed in matching modes
  2161. in-buffer: command displayed only in matching buffers
  2162. not-in-buffer: command not displayed in matching buffers
  2163. [function]: a custom function taking no argument
  2164. If you define several checks, the agenda command will be
  2165. accessible if there is at least one valid check.
  2166. You can also bind a key to another agenda custom command
  2167. depending on contextual rules.
  2168. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2169. Here it means: in .txt files, use \"p\" as the key for the
  2170. agenda command otherwise associated with \"q\". (The command
  2171. originally associated with \"q\" is not displayed to avoid
  2172. duplicates.)"
  2173. :version "24.3"
  2174. :group 'org-agenda-custom-commands
  2175. :type '(repeat (list :tag "Rule"
  2176. (string :tag " Agenda key")
  2177. (string :tag "Replace by command")
  2178. (repeat :tag "Available when"
  2179. (choice
  2180. (cons :tag "Condition"
  2181. (choice
  2182. (const :tag "In file" in-file)
  2183. (const :tag "Not in file" not-in-file)
  2184. (const :tag "In buffer" in-buffer)
  2185. (const :tag "Not in buffer" not-in-buffer)
  2186. (const :tag "In mode" in-mode)
  2187. (const :tag "Not in mode" not-in-mode))
  2188. (regexp))
  2189. (function :tag "Custom function"))))))
  2190. (defvar org-keys nil)
  2191. (defvar org-match nil)
  2192. ;;;###autoload
  2193. (defun org-agenda (&optional arg org-keys restriction)
  2194. "Dispatch agenda commands to collect entries to the agenda buffer.
  2195. Prompts for a command to execute. Any prefix arg will be passed
  2196. on to the selected command. The default selections are:
  2197. a Call `org-agenda-list' to display the agenda for current day or week.
  2198. t Call `org-todo-list' to display the global todo list.
  2199. T Call `org-todo-list' to display the global todo list, select only
  2200. entries with a specific TODO keyword (the user gets a prompt).
  2201. m Call `org-tags-view' to display headlines with tags matching
  2202. a condition (the user is prompted for the condition).
  2203. M Like `m', but select only TODO entries, no ordinary headlines.
  2204. L Create a timeline for the current buffer.
  2205. e Export views to associated files.
  2206. s Search entries for keywords.
  2207. S Search entries for keywords, only with TODO keywords.
  2208. / Multi occur across all agenda files and also files listed
  2209. in `org-agenda-text-search-extra-files'.
  2210. < Restrict agenda commands to buffer, subtree, or region.
  2211. Press several times to get the desired effect.
  2212. > Remove a previous restriction.
  2213. # List \"stuck\" projects.
  2214. ! Configure what \"stuck\" means.
  2215. C Configure custom agenda commands.
  2216. More commands can be added by configuring the variable
  2217. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2218. searches can be pre-defined in this way.
  2219. If the current buffer is in Org-mode and visiting a file, you can also
  2220. first press `<' once to indicate that the agenda should be temporarily
  2221. \(until the next use of \\[org-agenda]) restricted to the current file.
  2222. Pressing `<' twice means to restrict to the current subtree or region
  2223. \(if active)."
  2224. (interactive "P")
  2225. (catch 'exit
  2226. (let* ((prefix-descriptions nil)
  2227. (org-agenda-buffer-name org-agenda-buffer-name)
  2228. (org-agenda-window-setup (if (equal (buffer-name)
  2229. org-agenda-buffer-name)
  2230. 'current-window
  2231. org-agenda-window-setup))
  2232. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2233. (org-agenda-custom-commands
  2234. ;; normalize different versions
  2235. (delq nil
  2236. (mapcar
  2237. (lambda (x)
  2238. (cond ((stringp (cdr x))
  2239. (push x prefix-descriptions)
  2240. nil)
  2241. ((stringp (nth 1 x)) x)
  2242. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2243. (t (cons (car x) (cons "" (cdr x))))))
  2244. org-agenda-custom-commands)))
  2245. (org-agenda-custom-commands
  2246. (org-contextualize-keys
  2247. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2248. (buf (current-buffer))
  2249. (bfn (buffer-file-name (buffer-base-buffer)))
  2250. entry key type org-match lprops ans)
  2251. ;; Turn off restriction unless there is an overriding one,
  2252. (unless org-agenda-overriding-restriction
  2253. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2254. ;; There is a request to keep the file list in place
  2255. (put 'org-agenda-files 'org-restrict nil))
  2256. (setq org-agenda-restrict nil)
  2257. (move-marker org-agenda-restrict-begin nil)
  2258. (move-marker org-agenda-restrict-end nil))
  2259. ;; Delete old local properties
  2260. (put 'org-agenda-redo-command 'org-lprops nil)
  2261. ;; Delete previously set last-arguments
  2262. (put 'org-agenda-redo-command 'last-args nil)
  2263. ;; Remember where this call originated
  2264. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2265. (unless org-keys
  2266. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2267. org-keys (car ans)
  2268. restriction (cdr ans)))
  2269. ;; If we have sticky agenda buffers, set a name for the buffer,
  2270. ;; depending on the invoking keys. The user may still set this
  2271. ;; as a command option, which will overwrite what we do here.
  2272. (if org-agenda-sticky
  2273. (setq org-agenda-buffer-name
  2274. (format "*Org Agenda(%s)*" org-keys)))
  2275. ;; Establish the restriction, if any
  2276. (when (and (not org-agenda-overriding-restriction) restriction)
  2277. (put 'org-agenda-files 'org-restrict (list bfn))
  2278. (cond
  2279. ((eq restriction 'region)
  2280. (setq org-agenda-restrict t)
  2281. (move-marker org-agenda-restrict-begin (region-beginning))
  2282. (move-marker org-agenda-restrict-end (region-end)))
  2283. ((eq restriction 'subtree)
  2284. (save-excursion
  2285. (setq org-agenda-restrict t)
  2286. (org-back-to-heading t)
  2287. (move-marker org-agenda-restrict-begin (point))
  2288. (move-marker org-agenda-restrict-end
  2289. (progn (org-end-of-subtree t)))))))
  2290. ;; For example the todo list should not need it (but does...)
  2291. (cond
  2292. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2293. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2294. (progn
  2295. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2296. lprops (nth 4 entry))
  2297. (if org-agenda-sticky
  2298. (setq org-agenda-buffer-name
  2299. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2300. (format "*Org Agenda(%s)*" org-keys))))
  2301. (put 'org-agenda-redo-command 'org-lprops lprops)
  2302. (cond
  2303. ((eq type 'agenda)
  2304. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2305. ((eq type 'alltodo)
  2306. (org-let lprops '(org-todo-list current-prefix-arg)))
  2307. ((eq type 'search)
  2308. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2309. ((eq type 'stuck)
  2310. (org-let lprops '(org-agenda-list-stuck-projects
  2311. current-prefix-arg)))
  2312. ((eq type 'tags)
  2313. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2314. ((eq type 'tags-todo)
  2315. (org-let lprops '(org-tags-view '(4) org-match)))
  2316. ((eq type 'todo)
  2317. (org-let lprops '(org-todo-list org-match)))
  2318. ((eq type 'tags-tree)
  2319. (org-check-for-org-mode)
  2320. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2321. ((eq type 'todo-tree)
  2322. (org-check-for-org-mode)
  2323. (org-let lprops
  2324. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2325. (regexp-quote org-match) "\\>"))))
  2326. ((eq type 'occur-tree)
  2327. (org-check-for-org-mode)
  2328. (org-let lprops '(org-occur org-match)))
  2329. ((functionp type)
  2330. (org-let lprops '(funcall type org-match)))
  2331. ((fboundp type)
  2332. (org-let lprops '(funcall type org-match)))
  2333. (t (error "Invalid custom agenda command type %s" type))))
  2334. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2335. ((equal org-keys "C")
  2336. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2337. (customize-variable 'org-agenda-custom-commands))
  2338. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2339. ((equal org-keys "s") (call-interactively 'org-search-view))
  2340. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2341. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2342. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2343. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2344. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2345. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2346. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2347. (org-add-hook
  2348. 'post-command-hook
  2349. (lambda ()
  2350. (unless (current-message)
  2351. (let* ((m (org-agenda-get-any-marker))
  2352. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2353. (when note
  2354. (message (concat
  2355. "FLAGGING-NOTE ([?] for more info): "
  2356. (org-add-props
  2357. (replace-regexp-in-string
  2358. "\\\\n" "//"
  2359. (copy-sequence note))
  2360. nil 'face 'org-warning)))))))
  2361. t t))
  2362. ((equal org-keys "L")
  2363. (unless (derived-mode-p 'org-mode)
  2364. (error "This is not an Org-mode file"))
  2365. (unless restriction
  2366. (put 'org-agenda-files 'org-restrict (list bfn))
  2367. (org-call-with-arg 'org-timeline arg)))
  2368. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2369. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2370. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2371. (t (error "Invalid agenda key"))))))
  2372. (autoload 'org-agenda "org-agenda" "\
  2373. Dispatch agenda commands to collect entries to the agenda buffer.
  2374. Prompts for a command to execute. Any prefix arg will be passed
  2375. on to the selected command. The default selections are:
  2376. a Call `org-agenda-list' to display the agenda for current day or week.
  2377. t Call `org-todo-list' to display the global todo list.
  2378. T Call `org-todo-list' to display the global todo list, select only
  2379. entries with a specific TODO keyword (the user gets a prompt).
  2380. m Call `org-tags-view' to display headlines with tags matching
  2381. a condition (the user is prompted for the condition).
  2382. M Like `m', but select only TODO entries, no ordinary headlines.
  2383. L Create a timeline for the current buffer.
  2384. e Export views to associated files.
  2385. s Search entries for keywords.
  2386. S Search entries for keywords, only with TODO keywords.
  2387. / Multi occur across all agenda files and also files listed
  2388. in `org-agenda-text-search-extra-files'.
  2389. < Restrict agenda commands to buffer, subtree, or region.
  2390. Press several times to get the desired effect.
  2391. > Remove a previous restriction.
  2392. # List \"stuck\" projects.
  2393. ! Configure what \"stuck\" means.
  2394. C Configure custom agenda commands.
  2395. More commands can be added by configuring the variable
  2396. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2397. searches can be pre-defined in this way.
  2398. If the current buffer is in Org-mode and visiting a file, you can also
  2399. first press `<' once to indicate that the agenda should be temporarily
  2400. \(until the next use of \\[org-agenda]) restricted to the current file.
  2401. Pressing `<' twice means to restrict to the current subtree or region
  2402. \(if active).
  2403. \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
  2404. (defun org-agenda-append-agenda ()
  2405. "Append another agenda view to the current one.
  2406. This function allows interactive building of block agendas.
  2407. Agenda views are separated by `org-agenda-block-separator'."
  2408. (interactive)
  2409. (unless (derived-mode-p 'org-agenda-mode)
  2410. (error "Can only append from within agenda buffer"))
  2411. (let ((org-agenda-multi t))
  2412. (org-agenda)
  2413. (widen)
  2414. (org-agenda-finalize)
  2415. (org-agenda-fit-window-to-buffer)))
  2416. (defun org-agenda-normalize-custom-commands (cmds)
  2417. (delq nil
  2418. (mapcar
  2419. (lambda (x)
  2420. (cond ((stringp (cdr x)) nil)
  2421. ((stringp (nth 1 x)) x)
  2422. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2423. (t (cons (car x) (cons "" (cdr x))))))
  2424. cmds)))
  2425. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2426. "The user interface for selecting an agenda command."
  2427. (catch 'exit
  2428. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2429. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2430. (region-p (org-region-active-p))
  2431. (custom org-agenda-custom-commands)
  2432. (selstring "")
  2433. restriction second-time
  2434. c entry key type match prefixes rmheader header-end custom1 desc
  2435. line lines left right n n1)
  2436. (save-window-excursion
  2437. (delete-other-windows)
  2438. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2439. (erase-buffer)
  2440. (insert (eval-when-compile
  2441. (let ((header
  2442. "Press key for an agenda command: < Buffer, subtree/region restriction
  2443. -------------------------------- > Remove restriction
  2444. a Agenda for current week or day e Export agenda views
  2445. t List of all TODO entries T Entries with special TODO kwd
  2446. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2447. s Search for keywords S Like s, but only TODO entries
  2448. L Timeline for current buffer # List stuck projects (!=configure)
  2449. / Multi-occur C Configure custom agenda commands
  2450. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2451. ")
  2452. (start 0))
  2453. (while (string-match
  2454. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2455. header start)
  2456. (setq start (match-end 0))
  2457. (add-text-properties (match-beginning 2) (match-end 2)
  2458. '(face bold) header))
  2459. header)))
  2460. (setq header-end (point-marker))
  2461. (while t
  2462. (setq custom1 custom)
  2463. (when (eq rmheader t)
  2464. (org-goto-line 1)
  2465. (re-search-forward ":" nil t)
  2466. (delete-region (match-end 0) (point-at-eol))
  2467. (forward-char 1)
  2468. (looking-at "-+")
  2469. (delete-region (match-end 0) (point-at-eol))
  2470. (move-marker header-end (match-end 0)))
  2471. (goto-char header-end)
  2472. (delete-region (point) (point-max))
  2473. ;; Produce all the lines that describe custom commands and prefixes
  2474. (setq lines nil)
  2475. (while (setq entry (pop custom1))
  2476. (setq key (car entry) desc (nth 1 entry)
  2477. type (nth 2 entry)
  2478. match (nth 3 entry))
  2479. (if (> (length key) 1)
  2480. (add-to-list 'prefixes (string-to-char key))
  2481. (setq line
  2482. (format
  2483. "%-4s%-14s"
  2484. (org-add-props (copy-sequence key)
  2485. '(face bold))
  2486. (cond
  2487. ((string-match "\\S-" desc) desc)
  2488. ((eq type 'agenda) "Agenda for current week or day")
  2489. ((eq type 'alltodo) "List of all TODO entries")
  2490. ((eq type 'search) "Word search")
  2491. ((eq type 'stuck) "List of stuck projects")
  2492. ((eq type 'todo) "TODO keyword")
  2493. ((eq type 'tags) "Tags query")
  2494. ((eq type 'tags-todo) "Tags (TODO)")
  2495. ((eq type 'tags-tree) "Tags tree")
  2496. ((eq type 'todo-tree) "TODO kwd tree")
  2497. ((eq type 'occur-tree) "Occur tree")
  2498. ((functionp type) (if (symbolp type)
  2499. (symbol-name type)
  2500. "Lambda expression"))
  2501. (t "???"))))
  2502. (if org-agenda-menu-show-matcher
  2503. (setq line
  2504. (concat line ": "
  2505. (cond
  2506. ((stringp match)
  2507. (setq match (copy-sequence match))
  2508. (org-add-props match nil 'face 'org-warning))
  2509. ((listp type)
  2510. (format "set of %d commands" (length type))))))
  2511. (if (org-string-nw-p match)
  2512. (add-text-properties
  2513. 0 (length line) (list 'help-echo
  2514. (concat "Matcher: " match)) line)))
  2515. (push line lines)))
  2516. (setq lines (nreverse lines))
  2517. (when prefixes
  2518. (mapc (lambda (x)
  2519. (push
  2520. (format "%s %s"
  2521. (org-add-props (char-to-string x)
  2522. nil 'face 'bold)
  2523. (or (cdr (assoc (concat selstring
  2524. (char-to-string x))
  2525. prefix-descriptions))
  2526. "Prefix key"))
  2527. lines))
  2528. prefixes))
  2529. ;; Check if we should display in two columns
  2530. (if org-agenda-menu-two-columns
  2531. (progn
  2532. (setq n (length lines)
  2533. n1 (+ (/ n 2) (mod n 2))
  2534. right (nthcdr n1 lines)
  2535. left (copy-sequence lines))
  2536. (setcdr (nthcdr (1- n1) left) nil))
  2537. (setq left lines right nil))
  2538. (while left
  2539. (insert "\n" (pop left))
  2540. (when right
  2541. (if (< (current-column) 40)
  2542. (move-to-column 40 t)
  2543. (insert " "))
  2544. (insert (pop right))))
  2545. ;; Make the window the right size
  2546. (goto-char (point-min))
  2547. (if second-time
  2548. (if (not (pos-visible-in-window-p (point-max)))
  2549. (org-fit-window-to-buffer))
  2550. (setq second-time t)
  2551. (org-fit-window-to-buffer))
  2552. ;; Ask for selection
  2553. (message "Press key for agenda command%s:"
  2554. (if (or restrict-ok org-agenda-overriding-restriction)
  2555. (if org-agenda-overriding-restriction
  2556. " (restriction lock active)"
  2557. (if restriction
  2558. (format " (restricted to %s)" restriction)
  2559. " (unrestricted)"))
  2560. ""))
  2561. (setq c (read-char-exclusive))
  2562. (message "")
  2563. (cond
  2564. ((assoc (char-to-string c) custom)
  2565. (setq selstring (concat selstring (char-to-string c)))
  2566. (throw 'exit (cons selstring restriction)))
  2567. ((memq c prefixes)
  2568. (setq selstring (concat selstring (char-to-string c))
  2569. prefixes nil
  2570. rmheader (or rmheader t)
  2571. custom (delq nil (mapcar
  2572. (lambda (x)
  2573. (if (or (= (length (car x)) 1)
  2574. (/= (string-to-char (car x)) c))
  2575. nil
  2576. (cons (substring (car x) 1) (cdr x))))
  2577. custom))))
  2578. ((eq c ?*)
  2579. (call-interactively 'org-toggle-sticky-agenda)
  2580. (sit-for 2))
  2581. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2582. (message "Restriction is only possible in Org-mode buffers")
  2583. (ding) (sit-for 1))
  2584. ((eq c ?1)
  2585. (org-agenda-remove-restriction-lock 'noupdate)
  2586. (setq restriction 'buffer))
  2587. ((eq c ?0)
  2588. (org-agenda-remove-restriction-lock 'noupdate)
  2589. (setq restriction (if region-p 'region 'subtree)))
  2590. ((eq c ?<)
  2591. (org-agenda-remove-restriction-lock 'noupdate)
  2592. (setq restriction
  2593. (cond
  2594. ((eq restriction 'buffer)
  2595. (if region-p 'region 'subtree))
  2596. ((memq restriction '(subtree region))
  2597. nil)
  2598. (t 'buffer))))
  2599. ((eq c ?>)
  2600. (org-agenda-remove-restriction-lock 'noupdate)
  2601. (setq restriction nil))
  2602. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2603. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2604. ((and (> (length selstring) 0) (eq c ?\d))
  2605. (delete-window)
  2606. (org-agenda-get-restriction-and-command prefix-descriptions))
  2607. ((equal c ?q) (error "Abort"))
  2608. (t (error "Invalid key %c" c))))))))
  2609. (defun org-agenda-fit-window-to-buffer ()
  2610. "Fit the window to the buffer size."
  2611. (and (memq org-agenda-window-setup '(reorganize-frame))
  2612. (fboundp 'fit-window-to-buffer)
  2613. (org-fit-window-to-buffer
  2614. nil
  2615. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2616. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2617. (defvar org-cmd nil)
  2618. (defvar org-agenda-overriding-cmd nil)
  2619. (defvar org-agenda-overriding-arguments nil)
  2620. (defvar org-agenda-overriding-cmd-arguments nil)
  2621. (defun org-agenda-run-series (name series)
  2622. (org-let (nth 1 series) '(org-agenda-prepare name))
  2623. ;; We need to reset agenda markers here, because when constructing a
  2624. ;; block agenda, the individual blocks do not do that.
  2625. (org-agenda-reset-markers)
  2626. (let* ((org-agenda-multi t)
  2627. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2628. (cmds (car series))
  2629. (gprops (nth 1 series))
  2630. match ;; The byte compiler incorrectly complains about this. Keep it!
  2631. org-cmd type lprops)
  2632. (while (setq org-cmd (pop cmds))
  2633. (setq type (car org-cmd)
  2634. match (eval (nth 1 org-cmd))
  2635. lprops (nth 2 org-cmd))
  2636. (let ((org-agenda-overriding-arguments
  2637. (if (eq org-agenda-overriding-cmd org-cmd)
  2638. (or org-agenda-overriding-arguments
  2639. org-agenda-overriding-cmd-arguments))))
  2640. (cond
  2641. ((eq type 'agenda)
  2642. (org-let2 gprops lprops
  2643. '(call-interactively 'org-agenda-list)))
  2644. ((eq type 'alltodo)
  2645. (org-let2 gprops lprops
  2646. '(call-interactively 'org-todo-list)))
  2647. ((eq type 'search)
  2648. (org-let2 gprops lprops
  2649. '(org-search-view current-prefix-arg match nil)))
  2650. ((eq type 'stuck)
  2651. (org-let2 gprops lprops
  2652. '(call-interactively 'org-agenda-list-stuck-projects)))
  2653. ((eq type 'tags)
  2654. (org-let2 gprops lprops
  2655. '(org-tags-view current-prefix-arg match)))
  2656. ((eq type 'tags-todo)
  2657. (org-let2 gprops lprops
  2658. '(org-tags-view '(4) match)))
  2659. ((eq type 'todo)
  2660. (org-let2 gprops lprops
  2661. '(org-todo-list match)))
  2662. ((fboundp type)
  2663. (org-let2 gprops lprops
  2664. '(funcall type match)))
  2665. (t (error "Invalid type in command series")))))
  2666. (widen)
  2667. (let ((inhibit-read-only t))
  2668. (add-text-properties (point-min) (point-max)
  2669. `(org-series t org-series-redo-cmd ,redo)))
  2670. (setq org-agenda-redo-command redo)
  2671. (goto-char (point-min)))
  2672. (org-agenda-fit-window-to-buffer)
  2673. (org-let (nth 1 series) '(org-agenda-finalize)))
  2674. ;;;###autoload
  2675. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2676. "Run an agenda command in batch mode and send the result to STDOUT.
  2677. If CMD-KEY is a string of length 1, it is used as a key in
  2678. `org-agenda-custom-commands' and triggers this command. If it is a
  2679. longer string it is used as a tags/todo match string.
  2680. Parameters are alternating variable names and values that will be bound
  2681. before running the agenda command."
  2682. (org-eval-in-environment (org-make-parameter-alist parameters)
  2683. (if (> (length cmd-key) 2)
  2684. (org-tags-view nil cmd-key)
  2685. (org-agenda nil cmd-key)))
  2686. (set-buffer org-agenda-buffer-name)
  2687. (princ (buffer-string)))
  2688. (autoload 'org-batch-agenda "org-agenda" "\
  2689. Run an agenda command in batch mode and send the result to STDOUT.
  2690. If CMD-KEY is a string of length 1, it is used as a key in
  2691. `org-agenda-custom-commands' and triggers this command. If it is a
  2692. longer string it is used as a tags/todo match string.
  2693. Parameters are alternating variable names and values that will be bound
  2694. before running the agenda command.
  2695. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2696. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2697. (defvar org-agenda-info nil)
  2698. ;;;###autoload
  2699. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2700. "Run an agenda command in batch mode and send the result to STDOUT.
  2701. If CMD-KEY is a string of length 1, it is used as a key in
  2702. `org-agenda-custom-commands' and triggers this command. If it is a
  2703. longer string it is used as a tags/todo match string.
  2704. Parameters are alternating variable names and values that will be bound
  2705. before running the agenda command.
  2706. The output gives a line for each selected agenda item. Each
  2707. item is a list of comma-separated values, like this:
  2708. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2709. category The category of the item
  2710. head The headline, without TODO kwd, TAGS and PRIORITY
  2711. type The type of the agenda entry, can be
  2712. todo selected in TODO match
  2713. tagsmatch selected in tags match
  2714. diary imported from diary
  2715. deadline a deadline on given date
  2716. scheduled scheduled on given date
  2717. timestamp entry has timestamp on given date
  2718. closed entry was closed on given date
  2719. upcoming-deadline warning about deadline
  2720. past-scheduled forwarded scheduled item
  2721. block entry has date block including g. date
  2722. todo The todo keyword, if any
  2723. tags All tags including inherited ones, separated by colons
  2724. date The relevant date, like 2007-2-14
  2725. time The time, like 15:00-16:50
  2726. extra Sting with extra planning info
  2727. priority-l The priority letter if any was given
  2728. priority-n The computed numerical priority
  2729. agenda-day The day in the agenda where this is listed"
  2730. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2731. (org-make-parameter-alist parameters))
  2732. (if (> (length cmd-key) 2)
  2733. (org-tags-view nil cmd-key)
  2734. (org-agenda nil cmd-key)))
  2735. (set-buffer org-agenda-buffer-name)
  2736. (let* ((lines (org-split-string (buffer-string) "\n"))
  2737. line)
  2738. (while (setq line (pop lines))
  2739. (catch 'next
  2740. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2741. (setq org-agenda-info
  2742. (org-fix-agenda-info (text-properties-at 0 line)))
  2743. (princ
  2744. (mapconcat 'org-agenda-export-csv-mapper
  2745. '(org-category txt type todo tags date time extra
  2746. priority-letter priority agenda-day)
  2747. ","))
  2748. (princ "\n")))))
  2749. (autoload 'org-batch-agenda-csv "org-agenda" "\
  2750. Run an agenda command in batch mode and send the result to STDOUT.
  2751. If CMD-KEY is a string of length 1, it is used as a key in
  2752. `org-agenda-custom-commands' and triggers this command. If it is a
  2753. longer string it is used as a tags/todo match string.
  2754. Parameters are alternating variable names and values that will be bound
  2755. before running the agenda command.
  2756. The output gives a line for each selected agenda item. Each
  2757. item is a list of comma-separated values, like this:
  2758. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2759. category The category of the item
  2760. head The headline, without TODO kwd, TAGS and PRIORITY
  2761. type The type of the agenda entry, can be
  2762. todo selected in TODO match
  2763. tagsmatch selected in tags match
  2764. diary imported from diary
  2765. deadline a deadline on given date
  2766. scheduled scheduled on given date
  2767. timestamp entry has timestamp on given date
  2768. closed entry was closed on given date
  2769. upcoming-deadline warning about deadline
  2770. past-scheduled forwarded scheduled item
  2771. block entry has date block including g. date
  2772. todo The todo keyword, if any
  2773. tags All tags including inherited ones, separated by colons
  2774. date The relevant date, like 2007-2-14
  2775. time The time, like 15:00-16:50
  2776. extra Sting with extra planning info
  2777. priority-l The priority letter if any was given
  2778. priority-n The computed numerical priority
  2779. agenda-day The day in the agenda where this is listed
  2780. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2781. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2782. (defun org-fix-agenda-info (props)
  2783. "Make sure all properties on an agenda item have a canonical form.
  2784. This ensures the export commands can easily use it."
  2785. (let (tmp re)
  2786. (when (setq tmp (plist-get props 'tags))
  2787. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2788. (when (setq tmp (plist-get props 'date))
  2789. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2790. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2791. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2792. (setq tmp (calendar-date-string tmp)))
  2793. (setq props (plist-put props 'date tmp)))
  2794. (when (setq tmp (plist-get props 'day))
  2795. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2796. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2797. (setq tmp (calendar-date-string tmp)))
  2798. (setq props (plist-put props 'day tmp))
  2799. (setq props (plist-put props 'agenda-day tmp)))
  2800. (when (setq tmp (plist-get props 'txt))
  2801. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2802. (plist-put props 'priority-letter (match-string 1 tmp))
  2803. (setq tmp (replace-match "" t t tmp)))
  2804. (when (and (setq re (plist-get props 'org-todo-regexp))
  2805. (setq re (concat "\\`\\.*" re " ?"))
  2806. (string-match re tmp))
  2807. (plist-put props 'todo (match-string 1 tmp))
  2808. (setq tmp (replace-match "" t t tmp)))
  2809. (plist-put props 'txt tmp)))
  2810. props)
  2811. (defun org-agenda-export-csv-mapper (prop)
  2812. (let ((res (plist-get org-agenda-info prop)))
  2813. (setq res
  2814. (cond
  2815. ((not res) "")
  2816. ((stringp res) res)
  2817. (t (prin1-to-string res))))
  2818. (while (string-match "," res)
  2819. (setq res (replace-match ";" t t res)))
  2820. (org-trim res)))
  2821. ;;;###autoload
  2822. (defun org-store-agenda-views (&rest parameters)
  2823. (interactive)
  2824. (eval (list 'org-batch-store-agenda-views)))
  2825. (autoload 'org-store-agenda-views "org-agenda" "\
  2826. \(fn &rest PARAMETERS)" t nil)
  2827. ;;;###autoload
  2828. (defmacro org-batch-store-agenda-views (&rest parameters)
  2829. "Run all custom agenda commands that have a file argument."
  2830. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2831. (pop-up-frames nil)
  2832. (dir default-directory)
  2833. (pars (org-make-parameter-alist parameters))
  2834. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2835. (save-window-excursion
  2836. (while cmds
  2837. (setq cmd (pop cmds)
  2838. thiscmdkey (car cmd)
  2839. thiscmdcmd (cdr cmd)
  2840. match (nth 2 thiscmdcmd)
  2841. bufname (if org-agenda-sticky
  2842. (or (and (stringp match)
  2843. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2844. (format "*Org Agenda(%s)*" thiscmdkey))
  2845. org-agenda-buffer-name)
  2846. cmd-or-set (nth 2 cmd)
  2847. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2848. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2849. (if (stringp files) (setq files (list files)))
  2850. (when files
  2851. (org-eval-in-environment (append org-agenda-exporter-settings
  2852. opts pars)
  2853. (org-agenda nil thiscmdkey))
  2854. (set-buffer bufname)
  2855. (while files
  2856. (org-eval-in-environment (append org-agenda-exporter-settings
  2857. opts pars)
  2858. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2859. (and (get-buffer bufname)
  2860. (kill-buffer bufname)))))))
  2861. (autoload 'org-batch-store-agenda-views "org-agenda" "\
  2862. Run all custom agenda commands that have a file argument.
  2863. \(fn &rest PARAMETERS)" nil t)
  2864. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2865. (defvar org-agenda-current-span nil
  2866. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2867. (defun org-agenda-mark-header-line (pos)
  2868. "Mark the line at POS as an agenda structure header."
  2869. (save-excursion
  2870. (goto-char pos)
  2871. (put-text-property (point-at-bol) (point-at-eol)
  2872. 'org-agenda-structural-header t)
  2873. (when org-agenda-title-append
  2874. (put-text-property (point-at-bol) (point-at-eol)
  2875. 'org-agenda-title-append org-agenda-title-append))))
  2876. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2877. (defvar org-agenda-write-buffer-name "Agenda View")
  2878. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2879. "Write the current buffer (an agenda view) as a file.
  2880. Depending on the extension of the file name, plain text (.txt),
  2881. HTML (.html or .htm) or Postscript (.ps) is produced.
  2882. If the extension is .ics, run icalendar export over all files used
  2883. to construct the agenda and limit the export to entries listed in the
  2884. agenda now.
  2885. With prefix argument OPEN, open the new file immediately.
  2886. If NOSETTINGS is given, do not scope the settings of
  2887. `org-agenda-exporter-settings' into the export commands. This is used when
  2888. the settings have already been scoped and we do not wish to overrule other,
  2889. higher priority settings.
  2890. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2891. (interactive "FWrite agenda to file: \nP")
  2892. (if (not (file-writable-p file))
  2893. (error "Cannot write agenda to file %s" file))
  2894. (org-let (if nosettings nil org-agenda-exporter-settings)
  2895. '(save-excursion
  2896. (save-window-excursion
  2897. (org-agenda-mark-filtered-text)
  2898. (let ((bs (copy-sequence (buffer-string))) beg)
  2899. (org-agenda-unmark-filtered-text)
  2900. (with-temp-buffer
  2901. (rename-buffer org-agenda-write-buffer-name t)
  2902. (set-buffer-modified-p nil)
  2903. (insert bs)
  2904. (org-agenda-remove-marked-text 'org-filtered)
  2905. (while (setq beg (text-property-any (point-min) (point-max)
  2906. 'org-filtered t))
  2907. (delete-region
  2908. beg (or (next-single-property-change beg 'org-filtered)
  2909. (point-max))))
  2910. (run-hooks 'org-agenda-before-write-hook)
  2911. (cond
  2912. ((org-bound-and-true-p org-mobile-creating-agendas)
  2913. (org-mobile-write-agenda-for-mobile file))
  2914. ((string-match "\\.html?\\'" file)
  2915. (require 'htmlize)
  2916. (set-buffer (htmlize-buffer (current-buffer)))
  2917. (when org-agenda-export-html-style
  2918. ;; replace <style> section with org-agenda-export-html-style
  2919. (goto-char (point-min))
  2920. (kill-region (- (search-forward "<style") 6)
  2921. (search-forward "</style>"))
  2922. (insert org-agenda-export-html-style))
  2923. (write-file file)
  2924. (kill-buffer (current-buffer))
  2925. (message "HTML written to %s" file))
  2926. ((string-match "\\.ps\\'" file)
  2927. (require 'ps-print)
  2928. (ps-print-buffer-with-faces file)
  2929. (message "Postscript written to %s" file))
  2930. ((string-match "\\.pdf\\'" file)
  2931. (require 'ps-print)
  2932. (ps-print-buffer-with-faces
  2933. (concat (file-name-sans-extension file) ".ps"))
  2934. (call-process "ps2pdf" nil nil nil
  2935. (expand-file-name
  2936. (concat (file-name-sans-extension file) ".ps"))
  2937. (expand-file-name file))
  2938. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2939. (message "PDF written to %s" file))
  2940. ((string-match "\\.ics\\'" file)
  2941. (require 'org-icalendar)
  2942. (let ((org-agenda-marker-table
  2943. (org-create-marker-find-array
  2944. (org-agenda-collect-markers)))
  2945. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2946. (org-combined-agenda-icalendar-file file))
  2947. (apply 'org-export-icalendar 'combine
  2948. (org-agenda-files nil 'ifmode))))
  2949. (t
  2950. (let ((bs (buffer-string)))
  2951. (find-file file)
  2952. (erase-buffer)
  2953. (insert bs)
  2954. (save-buffer 0)
  2955. (kill-buffer (current-buffer))
  2956. (message "Plain text written to %s" file))))))))
  2957. (set-buffer (or agenda-bufname
  2958. (and (org-called-interactively-p 'any) (buffer-name))
  2959. org-agenda-buffer-name)))
  2960. (when open (org-open-file file)))
  2961. (defvar org-agenda-tag-filter-overlays nil)
  2962. (defvar org-agenda-cat-filter-overlays nil)
  2963. (defun org-agenda-mark-filtered-text ()
  2964. "Mark all text hidden by filtering with a text property."
  2965. (let ((inhibit-read-only t))
  2966. (mapc
  2967. (lambda (o)
  2968. (when (equal (overlay-buffer o) (current-buffer))
  2969. (put-text-property
  2970. (overlay-start o) (overlay-end o)
  2971. 'org-filtered t)))
  2972. (append org-agenda-tag-filter-overlays
  2973. org-agenda-cat-filter-overlays))))
  2974. (defun org-agenda-unmark-filtered-text ()
  2975. "Remove the filtering text property."
  2976. (let ((inhibit-read-only t))
  2977. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2978. (defun org-agenda-remove-marked-text (property &optional value)
  2979. "Delete all text marked with VALUE of PROPERTY.
  2980. VALUE defaults to t."
  2981. (let (beg)
  2982. (setq value (or value t))
  2983. (while (setq beg (text-property-any (point-min) (point-max)
  2984. property value))
  2985. (delete-region
  2986. beg (or (next-single-property-change beg 'org-filtered)
  2987. (point-max))))))
  2988. (defun org-agenda-add-entry-text ()
  2989. "Add entry text to agenda lines.
  2990. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2991. entry text following headings shown in the agenda.
  2992. Drawers will be excluded, also the line with scheduling/deadline info."
  2993. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2994. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2995. (let (m txt)
  2996. (goto-char (point-min))
  2997. (while (not (eobp))
  2998. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2999. (beginning-of-line 2)
  3000. (setq txt (org-agenda-get-some-entry-text
  3001. m org-agenda-add-entry-text-maxlines " > "))
  3002. (end-of-line 1)
  3003. (if (string-match "\\S-" txt)
  3004. (insert "\n" txt)
  3005. (or (eobp) (forward-char 1))))))))
  3006. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3007. &rest keep)
  3008. "Extract entry text from MARKER, at most N-LINES lines.
  3009. This will ignore drawers etc, just get the text.
  3010. If INDENT is given, prefix every line with this string. If KEEP is
  3011. given, it is a list of symbols, defining stuff that should not be
  3012. removed from the entry content. Currently only `planning' is allowed here."
  3013. (let (txt drawer-re kwd-time-re ind)
  3014. (save-excursion
  3015. (with-current-buffer (marker-buffer marker)
  3016. (if (not (derived-mode-p 'org-mode))
  3017. (setq txt "")
  3018. (save-excursion
  3019. (save-restriction
  3020. (widen)
  3021. (goto-char marker)
  3022. (end-of-line 1)
  3023. (setq txt (buffer-substring
  3024. (min (1+ (point)) (point-max))
  3025. (progn (outline-next-heading) (point)))
  3026. drawer-re org-drawer-regexp
  3027. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3028. ".*\n?"))
  3029. (with-temp-buffer
  3030. (insert txt)
  3031. (when org-agenda-add-entry-text-descriptive-links
  3032. (goto-char (point-min))
  3033. (while (org-activate-bracket-links (point-max))
  3034. (add-text-properties (match-beginning 0) (match-end 0)
  3035. '(face org-link))))
  3036. (goto-char (point-min))
  3037. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3038. (set-text-properties (match-beginning 0) (match-end 0)
  3039. nil))
  3040. (goto-char (point-min))
  3041. (while (re-search-forward drawer-re nil t)
  3042. (delete-region
  3043. (match-beginning 0)
  3044. (progn (re-search-forward
  3045. "^[ \t]*:END:.*\n?" nil 'move)
  3046. (point))))
  3047. (unless (member 'planning keep)
  3048. (goto-char (point-min))
  3049. (while (re-search-forward kwd-time-re nil t)
  3050. (replace-match "")))
  3051. (goto-char (point-min))
  3052. (when org-agenda-entry-text-exclude-regexps
  3053. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3054. (while (setq re (pop re-list))
  3055. (goto-char (point-min))
  3056. (while (re-search-forward re nil t)
  3057. (replace-match "")))))
  3058. (goto-char (point-max))
  3059. (skip-chars-backward " \t\n")
  3060. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3061. ;; find and remove min common indentation
  3062. (goto-char (point-min))
  3063. (untabify (point-min) (point-max))
  3064. (setq ind (org-get-indentation))
  3065. (while (not (eobp))
  3066. (unless (looking-at "[ \t]*$")
  3067. (setq ind (min ind (org-get-indentation))))
  3068. (beginning-of-line 2))
  3069. (goto-char (point-min))
  3070. (while (not (eobp))
  3071. (unless (looking-at "[ \t]*$")
  3072. (move-to-column ind)
  3073. (delete-region (point-at-bol) (point)))
  3074. (beginning-of-line 2))
  3075. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3076. (goto-char (point-min))
  3077. (when indent
  3078. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3079. (replace-match indent t t)))
  3080. (goto-char (point-min))
  3081. (while (looking-at "[ \t]*\n") (replace-match ""))
  3082. (goto-char (point-max))
  3083. (when (> (org-current-line)
  3084. n-lines)
  3085. (org-goto-line (1+ n-lines))
  3086. (backward-char 1))
  3087. (setq txt (buffer-substring (point-min) (point)))))))))
  3088. txt))
  3089. (defun org-agenda-collect-markers ()
  3090. "Collect the markers pointing to entries in the agenda buffer."
  3091. (let (m markers)
  3092. (save-excursion
  3093. (goto-char (point-min))
  3094. (while (not (eobp))
  3095. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3096. (org-get-at-bol 'org-marker)))
  3097. (push m markers))
  3098. (beginning-of-line 2)))
  3099. (nreverse markers)))
  3100. (defun org-create-marker-find-array (marker-list)
  3101. "Create a alist of files names with all marker positions in that file."
  3102. (let (f tbl m a p)
  3103. (while (setq m (pop marker-list))
  3104. (setq p (marker-position m)
  3105. f (buffer-file-name (or (buffer-base-buffer
  3106. (marker-buffer m))
  3107. (marker-buffer m))))
  3108. (if (setq a (assoc f tbl))
  3109. (push (marker-position m) (cdr a))
  3110. (push (list f p) tbl)))
  3111. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3112. tbl)))
  3113. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3114. (defun org-check-agenda-marker-table ()
  3115. "Check of the current entry is on the marker list."
  3116. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3117. a)
  3118. (and (setq a (assoc file org-agenda-marker-table))
  3119. (save-match-data
  3120. (save-excursion
  3121. (org-back-to-heading t)
  3122. (member (point) (cdr a)))))))
  3123. (defun org-check-for-org-mode ()
  3124. "Make sure current buffer is in org-mode. Error if not."
  3125. (or (derived-mode-p 'org-mode)
  3126. (error "Cannot execute org-mode agenda command on buffer in %s"
  3127. major-mode)))
  3128. ;;; Agenda prepare and finalize
  3129. (defvar org-agenda-multi nil) ; dynamically scoped
  3130. (defvar org-agenda-pre-window-conf nil)
  3131. (defvar org-agenda-columns-active nil)
  3132. (defvar org-agenda-name nil)
  3133. (defvar org-agenda-tag-filter nil)
  3134. (defvar org-agenda-category-filter nil)
  3135. (defvar org-agenda-top-category-filter nil)
  3136. (defvar org-agenda-tag-filter-while-redo nil)
  3137. (defvar org-agenda-tag-filter-preset nil
  3138. "A preset of the tags filter used for secondary agenda filtering.
  3139. This must be a list of strings, each string must be a single tag preceded
  3140. by \"+\" or \"-\".
  3141. This variable should not be set directly, but agenda custom commands can
  3142. bind it in the options section. The preset filter is a global property of
  3143. the entire agenda view. In a block agenda, it will not work reliably to
  3144. define a filter for one of the individual blocks. You need to set it in
  3145. the global options and expect it to be applied to the entire view.")
  3146. (defvar org-agenda-category-filter-preset nil
  3147. "A preset of the category filter used for secondary agenda filtering.
  3148. This must be a list of strings, each string must be a single category
  3149. preceded by \"+\" or \"-\".
  3150. This variable should not be set directly, but agenda custom commands can
  3151. bind it in the options section. The preset filter is a global property of
  3152. the entire agenda view. In a block agenda, it will not work reliably to
  3153. define a filter for one of the individual blocks. You need to set it in
  3154. the global options and expect it to be applied to the entire view.")
  3155. (defun org-agenda-use-sticky-p ()
  3156. "Return non-nil if an agenda buffer named
  3157. `org-agenda-buffer-name' exists and should be shown instead of
  3158. generating a new one."
  3159. (and
  3160. ;; turned off by user
  3161. org-agenda-sticky
  3162. ;; For multi-agenda buffer already exists
  3163. (not org-agenda-multi)
  3164. ;; buffer found
  3165. (get-buffer org-agenda-buffer-name)
  3166. ;; C-u parameter is same as last call
  3167. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3168. (and
  3169. (equal current-prefix-arg
  3170. org-agenda-last-prefix-arg)
  3171. ;; In case user turned stickiness on, while having existing
  3172. ;; Agenda buffer active, don't reuse that buffer, because it
  3173. ;; does not have org variables local
  3174. org-agenda-this-buffer-is-sticky))))
  3175. (defun org-agenda-prepare-window (abuf)
  3176. "Setup agenda buffer in the window."
  3177. (let* ((awin (get-buffer-window abuf))
  3178. wconf)
  3179. (cond
  3180. ((equal (current-buffer) abuf) nil)
  3181. (awin (select-window awin))
  3182. ((not (setq wconf (current-window-configuration))))
  3183. ((equal org-agenda-window-setup 'current-window)
  3184. (org-pop-to-buffer-same-window abuf))
  3185. ((equal org-agenda-window-setup 'other-window)
  3186. (org-switch-to-buffer-other-window abuf))
  3187. ((equal org-agenda-window-setup 'other-frame)
  3188. (switch-to-buffer-other-frame abuf))
  3189. ((equal org-agenda-window-setup 'reorganize-frame)
  3190. (delete-other-windows)
  3191. (org-switch-to-buffer-other-window abuf)))
  3192. ;; additional test in case agenda is invoked from within agenda
  3193. ;; buffer via elisp link
  3194. (unless (equal (current-buffer) abuf)
  3195. (org-pop-to-buffer-same-window abuf))
  3196. (setq org-agenda-pre-window-conf
  3197. (or org-agenda-pre-window-conf wconf))))
  3198. (defun org-agenda-prepare (&optional name)
  3199. (if (org-agenda-use-sticky-p)
  3200. (progn
  3201. ;; Popup existing buffer
  3202. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3203. (message "Sticky Agenda buffer, use `r' to refresh")
  3204. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3205. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3206. (setq org-todo-keywords-for-agenda nil)
  3207. (setq org-drawers-for-agenda nil)
  3208. (unless org-agenda-persistent-filter
  3209. (setq org-agenda-tag-filter nil
  3210. org-agenda-category-filter nil))
  3211. (put 'org-agenda-tag-filter :preset-filter
  3212. org-agenda-tag-filter-preset)
  3213. (put 'org-agenda-category-filter :preset-filter
  3214. org-agenda-category-filter-preset)
  3215. (if org-agenda-multi
  3216. (progn
  3217. (setq buffer-read-only nil)
  3218. (goto-char (point-max))
  3219. (unless (or (bobp) org-agenda-compact-blocks
  3220. (not org-agenda-block-separator))
  3221. (insert "\n"
  3222. (if (stringp org-agenda-block-separator)
  3223. org-agenda-block-separator
  3224. (make-string (window-width) org-agenda-block-separator))
  3225. "\n"))
  3226. (narrow-to-region (point) (point-max)))
  3227. (setq org-done-keywords-for-agenda nil)
  3228. ;; Setting any org variables that are in org-agenda-local-vars
  3229. ;; list need to be done after the prepare call
  3230. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3231. (setq buffer-read-only nil)
  3232. (org-agenda-reset-markers)
  3233. (let ((inhibit-read-only t)) (erase-buffer))
  3234. (org-agenda-mode)
  3235. (setq org-agenda-buffer (current-buffer))
  3236. (setq org-agenda-contributing-files nil)
  3237. (setq org-agenda-columns-active nil)
  3238. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3239. (setq org-todo-keywords-for-agenda
  3240. (org-uniquify org-todo-keywords-for-agenda))
  3241. (setq org-done-keywords-for-agenda
  3242. (org-uniquify org-done-keywords-for-agenda))
  3243. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3244. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3245. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3246. (and name (not org-agenda-name)
  3247. (org-set-local 'org-agenda-name name)))
  3248. (setq buffer-read-only nil)))
  3249. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3250. (defun org-agenda-finalize ()
  3251. "Finishing touch for the agenda buffer, called just before displaying it."
  3252. (unless org-agenda-multi
  3253. (save-excursion
  3254. (let ((inhibit-read-only t))
  3255. (goto-char (point-min))
  3256. (save-excursion
  3257. (while (org-activate-bracket-links (point-max))
  3258. (add-text-properties (match-beginning 0) (match-end 0)
  3259. '(face org-link))))
  3260. (save-excursion
  3261. (while (org-activate-plain-links (point-max))
  3262. (add-text-properties (match-beginning 0) (match-end 0)
  3263. '(face org-link))))
  3264. (unless (eq org-agenda-remove-tags t)
  3265. (org-agenda-align-tags))
  3266. (unless org-agenda-with-colors
  3267. (remove-text-properties (point-min) (point-max) '(face nil)))
  3268. (if (and (boundp 'org-agenda-overriding-columns-format)
  3269. org-agenda-overriding-columns-format)
  3270. (org-set-local 'org-agenda-overriding-columns-format
  3271. org-agenda-overriding-columns-format))
  3272. (if (and (boundp 'org-agenda-view-columns-initially)
  3273. org-agenda-view-columns-initially)
  3274. (org-agenda-columns))
  3275. (when org-agenda-fontify-priorities
  3276. (org-agenda-fontify-priorities))
  3277. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3278. (org-agenda-dim-blocked-tasks))
  3279. ;; We need to widen when `org-agenda-finalize' is called from
  3280. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3281. (when org-clock-current-task
  3282. (save-restriction
  3283. (widen)
  3284. (org-agenda-mark-clocking-task)))
  3285. (when org-agenda-entry-text-mode
  3286. (org-agenda-entry-text-hide)
  3287. (org-agenda-entry-text-show))
  3288. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3289. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3290. (org-habit-insert-consistency-graphs))
  3291. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3292. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3293. (and (listp org-agenda-show-inherited-tags)
  3294. (memq org-agenda-type org-agenda-show-inherited-tags))
  3295. (and (eq org-agenda-show-inherited-tags t)
  3296. (or (eq org-agenda-use-tag-inheritance t)
  3297. (and (listp org-agenda-use-tag-inheritance)
  3298. (not (memq org-agenda-type
  3299. org-agenda-use-tag-inheritance))))))
  3300. (let (mrk)
  3301. (save-excursion
  3302. (goto-char (point-min))
  3303. (while (equal (forward-line) 0)
  3304. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3305. (get-text-property (point) 'org-hd-marker)))
  3306. (put-text-property (point-at-bol) (point-at-eol)
  3307. 'tags (org-with-point-at mrk
  3308. (delete-dups
  3309. (mapcar 'downcase (org-get-tags-at))))))))))
  3310. (run-hooks 'org-agenda-finalize-hook)
  3311. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3312. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3313. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3314. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3315. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3316. (defun org-agenda-mark-clocking-task ()
  3317. "Mark the current clock entry in the agenda if it is present."
  3318. (mapc (lambda (o)
  3319. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3320. (delete-overlay o)))
  3321. (overlays-in (point-min) (point-max)))
  3322. (when (marker-buffer org-clock-hd-marker)
  3323. (save-excursion
  3324. (goto-char (point-min))
  3325. (let (s ov)
  3326. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3327. (goto-char s)
  3328. (when (equal (org-get-at-bol 'org-hd-marker)
  3329. org-clock-hd-marker)
  3330. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3331. (overlay-put ov 'type 'org-agenda-clocking)
  3332. (overlay-put ov 'face 'org-agenda-clocking)
  3333. (overlay-put ov 'help-echo
  3334. "The clock is running in this item")))))))
  3335. (defun org-agenda-fontify-priorities ()
  3336. "Make highest priority lines bold, and lowest italic."
  3337. (interactive)
  3338. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3339. (delete-overlay o)))
  3340. (overlays-in (point-min) (point-max)))
  3341. (save-excursion
  3342. (let (b e p ov h l)
  3343. (goto-char (point-min))
  3344. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3345. (setq h (or (get-char-property (point) 'org-highest-priority)
  3346. org-highest-priority)
  3347. l (or (get-char-property (point) 'org-lowest-priority)
  3348. org-lowest-priority)
  3349. p (string-to-char (match-string 1))
  3350. b (match-beginning 0)
  3351. e (if (eq org-agenda-fontify-priorities 'cookies)
  3352. (match-end 0)
  3353. (point-at-eol))
  3354. ov (make-overlay b e))
  3355. (overlay-put
  3356. ov 'face
  3357. (cons (cond ((org-face-from-face-or-color
  3358. 'priority nil
  3359. (cdr (assoc p org-priority-faces))))
  3360. ((and (listp org-agenda-fontify-priorities)
  3361. (org-face-from-face-or-color
  3362. 'priority nil
  3363. (cdr (assoc p org-agenda-fontify-priorities)))))
  3364. ((equal p l) 'italic)
  3365. ((equal p h) 'bold))
  3366. 'org-priority))
  3367. (overlay-put ov 'org-type 'org-priority)))))
  3368. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3369. (interactive "P")
  3370. "Dim currently blocked TODO's in the agenda display."
  3371. (message "Dim or hide blocked tasks...")
  3372. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3373. (delete-overlay o)))
  3374. (overlays-in (point-min) (point-max)))
  3375. (save-excursion
  3376. (let ((inhibit-read-only t)
  3377. (org-depend-tag-blocked nil)
  3378. (invis (or (not (null invisible))
  3379. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3380. org-blocked-by-checkboxes
  3381. invis1 b e p ov h l)
  3382. (goto-char (point-min))
  3383. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3384. (and pos (goto-char (1+ pos))))
  3385. (setq org-blocked-by-checkboxes nil invis1 invis)
  3386. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3387. (when (and marker
  3388. (with-current-buffer (marker-buffer marker)
  3389. (save-excursion (goto-char marker)
  3390. (org-entry-blocked-p))))
  3391. (if org-blocked-by-checkboxes (setq invis1 nil))
  3392. (setq b (if invis1
  3393. (max (point-min) (1- (point-at-bol)))
  3394. (point-at-bol))
  3395. e (point-at-eol)
  3396. ov (make-overlay b e))
  3397. (if invis1
  3398. (overlay-put ov 'invisible t)
  3399. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3400. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3401. (message "Dim or hide blocked tasks...done"))
  3402. (defvar org-agenda-skip-function nil
  3403. "Function to be called at each match during agenda construction.
  3404. If this function returns nil, the current match should not be skipped.
  3405. Otherwise, the function must return a position from where the search
  3406. should be continued.
  3407. This may also be a Lisp form, it will be evaluated.
  3408. Never set this variable using `setq' or so, because then it will apply
  3409. to all future agenda commands. If you do want a global skipping condition,
  3410. use the option `org-agenda-skip-function-global' instead.
  3411. The correct usage for `org-agenda-skip-function' is to bind it with
  3412. `let' to scope it dynamically into the agenda-constructing command.
  3413. A good way to set it is through options in `org-agenda-custom-commands'.")
  3414. (defun org-agenda-skip ()
  3415. "Throw to `:skip' in places that should be skipped.
  3416. Also moves point to the end of the skipped region, so that search can
  3417. continue from there."
  3418. (let ((p (point-at-bol)) to)
  3419. (when (or
  3420. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3421. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3422. (get-text-property p :org-archived)
  3423. (org-end-of-subtree t))
  3424. (and org-agenda-skip-comment-trees
  3425. (get-text-property p :org-comment)
  3426. (org-end-of-subtree t))
  3427. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3428. (org-agenda-skip-eval org-agenda-skip-function)))
  3429. (goto-char to))
  3430. (org-in-src-block-p t))
  3431. (throw :skip t))))
  3432. (defun org-agenda-skip-eval (form)
  3433. "If FORM is a function or a list, call (or eval) is and return result.
  3434. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3435. and match data are returned to the previous state no matter what these
  3436. functions do."
  3437. (let (fp)
  3438. (and form
  3439. (or (setq fp (functionp form))
  3440. (consp form))
  3441. (save-excursion
  3442. (save-match-data
  3443. (if fp
  3444. (funcall form)
  3445. (eval form)))))))
  3446. (defvar org-agenda-markers nil
  3447. "List of all currently active markers created by `org-agenda'.")
  3448. (defvar org-agenda-last-marker-time (org-float-time)
  3449. "Creation time of the last agenda marker.")
  3450. (defun org-agenda-new-marker (&optional pos)
  3451. "Return a new agenda marker.
  3452. Org-mode keeps a list of these markers and resets them when they are
  3453. no longer in use."
  3454. (let ((m (copy-marker (or pos (point)))))
  3455. (setq org-agenda-last-marker-time (org-float-time))
  3456. (if org-agenda-buffer
  3457. (with-current-buffer org-agenda-buffer
  3458. (push m org-agenda-markers))
  3459. (push m org-agenda-markers))
  3460. m))
  3461. (defun org-agenda-reset-markers ()
  3462. "Reset markers created by `org-agenda'."
  3463. (while org-agenda-markers
  3464. (move-marker (pop org-agenda-markers) nil)))
  3465. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3466. "Save relative positions of markers in region.
  3467. This check for agenda markers in all agenda buffers currently active."
  3468. (dolist (buf (buffer-list))
  3469. (with-current-buffer buf
  3470. (when (eq major-mode 'org-agenda-mode)
  3471. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3472. org-agenda-markers)))))
  3473. ;;; Entry text mode
  3474. (defun org-agenda-entry-text-show-here ()
  3475. "Add some text from the entry as context to the current line."
  3476. (let (m txt o)
  3477. (setq m (org-get-at-bol 'org-hd-marker))
  3478. (unless (marker-buffer m)
  3479. (error "No marker points to an entry here"))
  3480. (setq txt (concat "\n" (org-no-properties
  3481. (org-agenda-get-some-entry-text
  3482. m org-agenda-entry-text-maxlines " > "))))
  3483. (when (string-match "\\S-" txt)
  3484. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3485. (overlay-put o 'evaporate t)
  3486. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3487. (overlay-put o 'after-string txt))))
  3488. (defun org-agenda-entry-text-show ()
  3489. "Add entry context for all agenda lines."
  3490. (interactive)
  3491. (save-excursion
  3492. (goto-char (point-max))
  3493. (beginning-of-line 1)
  3494. (while (not (bobp))
  3495. (when (org-get-at-bol 'org-hd-marker)
  3496. (org-agenda-entry-text-show-here))
  3497. (beginning-of-line 0))))
  3498. (defun org-agenda-entry-text-hide ()
  3499. "Remove any shown entry context."
  3500. (delq nil
  3501. (mapcar (lambda (o)
  3502. (if (eq (overlay-get o 'org-overlay-type)
  3503. 'agenda-entry-content)
  3504. (progn (delete-overlay o) t)))
  3505. (overlays-in (point-min) (point-max)))))
  3506. (defun org-agenda-get-day-face (date)
  3507. "Return the face DATE should be displayed with."
  3508. (or (and (functionp org-agenda-day-face-function)
  3509. (funcall org-agenda-day-face-function date))
  3510. (cond ((org-agenda-todayp date)
  3511. 'org-agenda-date-today)
  3512. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3513. 'org-agenda-date-weekend)
  3514. (t 'org-agenda-date))))
  3515. ;;; Agenda timeline
  3516. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3517. (defun org-timeline (&optional dotodo)
  3518. "Show a time-sorted view of the entries in the current org file.
  3519. Only entries with a time stamp of today or later will be listed. With
  3520. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3521. under the current date.
  3522. If the buffer contains an active region, only check the region for
  3523. dates."
  3524. (interactive "P")
  3525. (let* ((dopast t)
  3526. (org-agenda-show-log-scoped org-agenda-show-log)
  3527. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3528. (current-buffer))))
  3529. (date (calendar-current-date))
  3530. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3531. (end (if (org-region-active-p) (region-end) (point-max)))
  3532. (day-numbers (org-get-all-dates
  3533. beg end 'no-ranges
  3534. t org-agenda-show-log-scoped ; always include today
  3535. org-timeline-show-empty-dates))
  3536. (org-deadline-warning-days 0)
  3537. (org-agenda-only-exact-dates t)
  3538. (today (org-today))
  3539. (past t)
  3540. args
  3541. s e rtn d emptyp)
  3542. (setq org-agenda-redo-command
  3543. (list 'progn
  3544. (list 'org-switch-to-buffer-other-window (current-buffer))
  3545. (list 'org-timeline (list 'quote dotodo))))
  3546. (if (not dopast)
  3547. ;; Remove past dates from the list of dates.
  3548. (setq day-numbers (delq nil (mapcar (lambda(x)
  3549. (if (>= x today) x nil))
  3550. day-numbers))))
  3551. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3552. (org-compile-prefix-format 'timeline)
  3553. (org-set-sorting-strategy 'timeline)
  3554. (if org-agenda-show-log-scoped (push :closed args))
  3555. (push :timestamp args)
  3556. (push :deadline args)
  3557. (push :scheduled args)
  3558. (push :sexp args)
  3559. (if dotodo (push :todo args))
  3560. (insert "Timeline of file " entry "\n")
  3561. (add-text-properties (point-min) (point)
  3562. (list 'face 'org-agenda-structure))
  3563. (org-agenda-mark-header-line (point-min))
  3564. (while (setq d (pop day-numbers))
  3565. (if (and (listp d) (eq (car d) :omitted))
  3566. (progn
  3567. (setq s (point))
  3568. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3569. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3570. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3571. (if (and (>= d today)
  3572. dopast
  3573. past)
  3574. (progn
  3575. (setq past nil)
  3576. (insert (make-string 79 ?-) "\n")))
  3577. (setq date (calendar-gregorian-from-absolute d))
  3578. (setq s (point))
  3579. (setq rtn (and (not emptyp)
  3580. (apply 'org-agenda-get-day-entries entry
  3581. date args)))
  3582. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3583. (progn
  3584. (insert
  3585. (if (stringp org-agenda-format-date)
  3586. (format-time-string org-agenda-format-date
  3587. (org-time-from-absolute date))
  3588. (funcall org-agenda-format-date date))
  3589. "\n")
  3590. (put-text-property s (1- (point)) 'face
  3591. (org-agenda-get-day-face date))
  3592. (put-text-property s (1- (point)) 'org-date-line t)
  3593. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3594. (if (equal d today)
  3595. (put-text-property s (1- (point)) 'org-today t))
  3596. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3597. (put-text-property s (1- (point)) 'day d)))))
  3598. (goto-char (point-min))
  3599. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3600. (point-min)))
  3601. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3602. (org-agenda-finalize)
  3603. (setq buffer-read-only t)))
  3604. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3605. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3606. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3607. not every single day in the range. If FORCE-TODAY is non-nil, make
  3608. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3609. inactive time stamps (those in square brackets) are included.
  3610. When EMPTY is non-nil, also include days without any entries."
  3611. (let ((re (concat
  3612. (if pre-re pre-re "")
  3613. (if inactive org-ts-regexp-both org-ts-regexp)))
  3614. dates dates1 date day day1 day2 ts1 ts2 pos)
  3615. (if force-today
  3616. (setq dates (list (org-today))))
  3617. (save-excursion
  3618. (goto-char beg)
  3619. (while (re-search-forward re end t)
  3620. (setq day (time-to-days (org-time-string-to-time
  3621. (substring (match-string 1) 0 10)
  3622. (current-buffer) (match-beginning 0))))
  3623. (or (memq day dates) (push day dates)))
  3624. (unless no-ranges
  3625. (goto-char beg)
  3626. (while (re-search-forward org-tr-regexp end t)
  3627. (setq pos (match-beginning 0))
  3628. (setq ts1 (substring (match-string 1) 0 10)
  3629. ts2 (substring (match-string 2) 0 10)
  3630. day1 (time-to-days (org-time-string-to-time
  3631. ts1 (current-buffer) pos))
  3632. day2 (time-to-days (org-time-string-to-time
  3633. ts2 (current-buffer) pos)))
  3634. (while (< (setq day1 (1+ day1)) day2)
  3635. (or (memq day1 dates) (push day1 dates)))))
  3636. (setq dates (sort dates '<))
  3637. (when empty
  3638. (while (setq day (pop dates))
  3639. (setq day2 (car dates))
  3640. (push day dates1)
  3641. (when (and day2 empty)
  3642. (if (or (eq empty t)
  3643. (and (numberp empty) (<= (- day2 day) empty)))
  3644. (while (< (setq day (1+ day)) day2)
  3645. (push (list day) dates1))
  3646. (push (cons :omitted (- day2 day)) dates1))))
  3647. (setq dates (nreverse dates1)))
  3648. dates)))
  3649. ;;; Agenda Daily/Weekly
  3650. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3651. "Start day for the agenda view.
  3652. Custom commands can set this variable in the options section.")
  3653. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3654. (defvar org-arg-loc nil) ; local variable
  3655. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3656. "List of types searched for when creating the daily/weekly agenda.
  3657. This variable is a list of symbols that controls the types of
  3658. items that appear in the daily/weekly agenda. Allowed symbols in this
  3659. list are are
  3660. :timestamp List items containing a date stamp or date range matching
  3661. the selected date. This includes sexp entries in
  3662. angular brackets.
  3663. :sexp List entries resulting from plain diary-like sexps.
  3664. :deadline List deadline due on that date. When the date is today,
  3665. also list any deadlines past due, or due within
  3666. `org-deadline-warning-days'. `:deadline' must appear before
  3667. `:scheduled' if the setting of
  3668. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3669. any effect.
  3670. :scheduled List all items which are scheduled for the given date.
  3671. The diary for *today* also contains items which were
  3672. scheduled earlier and are not yet marked DONE.
  3673. By default, all four types are turned on.
  3674. Never set this variable globally using `setq', because then it
  3675. will apply to all future agenda commands. Instead, bind it with
  3676. `let' to scope it dynamically into the agenda-constructing
  3677. command. A good way to set it is through options in
  3678. `org-agenda-custom-commands'. For a more flexible (though
  3679. somewhat less efficient) way of determining what is included in
  3680. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3681. (defvar org-agenda-buffer-tmp-name nil)
  3682. ;;;###autoload
  3683. (defun org-agenda-list (&optional arg start-day span)
  3684. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3685. The view will be for the current day or week, but from the overview buffer
  3686. you will be able to go to other days/weeks.
  3687. With a numeric prefix argument in an interactive call, the agenda will
  3688. span ARG days. Lisp programs should instead specify SPAN to change
  3689. the number of days. SPAN defaults to `org-agenda-span'.
  3690. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3691. given in `org-agenda-start-on-weekday'."
  3692. (interactive "P")
  3693. (if org-agenda-overriding-arguments
  3694. (setq arg (car org-agenda-overriding-arguments)
  3695. start-day (nth 1 org-agenda-overriding-arguments)
  3696. span (nth 2 org-agenda-overriding-arguments)))
  3697. (if (and (integerp arg) (> arg 0))
  3698. (setq span arg arg nil))
  3699. (catch 'exit
  3700. (setq org-agenda-buffer-name
  3701. (or org-agenda-buffer-tmp-name
  3702. (if org-agenda-sticky
  3703. (cond ((and org-keys (stringp org-match))
  3704. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3705. (org-keys
  3706. (format "*Org Agenda(%s)*" org-keys))
  3707. (t "*Org Agenda(a)*")))
  3708. org-agenda-buffer-name))
  3709. (org-agenda-prepare "Day/Week")
  3710. (setq start-day (or start-day org-agenda-start-day))
  3711. (if (stringp start-day)
  3712. ;; Convert to an absolute day number
  3713. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3714. (org-compile-prefix-format 'agenda)
  3715. (org-set-sorting-strategy 'agenda)
  3716. (let* ((span (org-agenda-ndays-to-span
  3717. (or span org-agenda-ndays org-agenda-span)))
  3718. (today (org-today))
  3719. (sd (or start-day today))
  3720. (ndays (org-agenda-span-to-ndays span sd))
  3721. (org-agenda-start-on-weekday
  3722. (if (eq ndays 7)
  3723. org-agenda-start-on-weekday))
  3724. (thefiles (org-agenda-files nil 'ifmode))
  3725. (files thefiles)
  3726. (start (if (or (null org-agenda-start-on-weekday)
  3727. (< ndays 7))
  3728. sd
  3729. (let* ((nt (calendar-day-of-week
  3730. (calendar-gregorian-from-absolute sd)))
  3731. (n1 org-agenda-start-on-weekday)
  3732. (d (- nt n1)))
  3733. (- sd (+ (if (< d 0) 7 0) d)))))
  3734. (day-numbers (list start))
  3735. (day-cnt 0)
  3736. (inhibit-redisplay (not debug-on-error))
  3737. (org-agenda-show-log-scoped org-agenda-show-log)
  3738. s e rtn rtnall file date d start-pos end-pos todayp
  3739. clocktable-start clocktable-end filter)
  3740. (setq org-agenda-redo-command
  3741. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3742. (dotimes (n (1- ndays))
  3743. (push (1+ (car day-numbers)) day-numbers))
  3744. (setq day-numbers (nreverse day-numbers))
  3745. (setq clocktable-start (car day-numbers)
  3746. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3747. (org-set-local 'org-starting-day (car day-numbers))
  3748. (org-set-local 'org-arg-loc arg)
  3749. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3750. (unless org-agenda-compact-blocks
  3751. (let* ((d1 (car day-numbers))
  3752. (d2 (org-last day-numbers))
  3753. (w1 (org-days-to-iso-week d1))
  3754. (w2 (org-days-to-iso-week d2)))
  3755. (setq s (point))
  3756. (if org-agenda-overriding-header
  3757. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3758. nil 'face 'org-agenda-structure) "\n")
  3759. (insert (org-agenda-span-name span)
  3760. "-agenda"
  3761. (if (< (- d2 d1) 350)
  3762. (if (= w1 w2)
  3763. (format " (W%02d)" w1)
  3764. (format " (W%02d-W%02d)" w1 w2))
  3765. "")
  3766. ":\n")))
  3767. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3768. 'org-date-line t))
  3769. (org-agenda-mark-header-line s))
  3770. (while (setq d (pop day-numbers))
  3771. (setq date (calendar-gregorian-from-absolute d)
  3772. s (point))
  3773. (if (or (setq todayp (= d today))
  3774. (and (not start-pos) (= d sd)))
  3775. (setq start-pos (point))
  3776. (if (and start-pos (not end-pos))
  3777. (setq end-pos (point))))
  3778. (setq files thefiles
  3779. rtnall nil)
  3780. (while (setq file (pop files))
  3781. (catch 'nextfile
  3782. (org-check-agenda-file file)
  3783. (let ((org-agenda-entry-types org-agenda-entry-types))
  3784. (unless org-agenda-include-deadlines
  3785. (setq org-agenda-entry-types
  3786. (delq :deadline org-agenda-entry-types)))
  3787. (cond
  3788. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3789. (setq rtn (org-agenda-get-day-entries
  3790. file date :closed)))
  3791. (org-agenda-show-log-scoped
  3792. (setq rtn (apply 'org-agenda-get-day-entries
  3793. file date
  3794. (append '(:closed) org-agenda-entry-types))))
  3795. (t
  3796. (setq rtn (apply 'org-agenda-get-day-entries
  3797. file date
  3798. org-agenda-entry-types)))))
  3799. (setq rtnall (append rtnall rtn)))) ;; all entries
  3800. (if org-agenda-include-diary
  3801. (let ((org-agenda-search-headline-for-time t))
  3802. (require 'diary-lib)
  3803. (setq rtn (org-get-entries-from-diary date))
  3804. (setq rtnall (append rtnall rtn))))
  3805. (if (or rtnall org-agenda-show-all-dates)
  3806. (progn
  3807. (setq day-cnt (1+ day-cnt))
  3808. (insert
  3809. (if (stringp org-agenda-format-date)
  3810. (format-time-string org-agenda-format-date
  3811. (org-time-from-absolute date))
  3812. (funcall org-agenda-format-date date))
  3813. "\n")
  3814. (put-text-property s (1- (point)) 'face
  3815. (org-agenda-get-day-face date))
  3816. (put-text-property s (1- (point)) 'org-date-line t)
  3817. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3818. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3819. (when todayp
  3820. (put-text-property s (1- (point)) 'org-today t))
  3821. (setq rtnall
  3822. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3823. (if rtnall (insert ;; all entries
  3824. (org-agenda-finalize-entries rtnall)
  3825. "\n"))
  3826. (put-text-property s (1- (point)) 'day d)
  3827. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3828. (when (and org-agenda-clockreport-mode clocktable-start)
  3829. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3830. ;; the above line is to ensure the restricted range!
  3831. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3832. tbl)
  3833. (setq p (org-plist-delete p :block))
  3834. (setq p (plist-put p :tstart clocktable-start))
  3835. (setq p (plist-put p :tend clocktable-end))
  3836. (setq p (plist-put p :scope 'agenda))
  3837. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3838. (setq filter (or org-agenda-tag-filter-while-redo
  3839. (get 'org-agenda-tag-filter :preset-filter))))
  3840. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3841. (if (string-match "[<>=]" x)
  3842. ""
  3843. x))
  3844. filter ""))))
  3845. (setq tbl (apply 'org-clock-get-clocktable p))
  3846. (insert tbl)))
  3847. (goto-char (point-min))
  3848. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3849. (unless (and (pos-visible-in-window-p (point-min))
  3850. (pos-visible-in-window-p (point-max)))
  3851. (goto-char (1- (point-max)))
  3852. (recenter -1)
  3853. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3854. (progn
  3855. (goto-char (or start-pos 1))
  3856. (recenter 1))))
  3857. (goto-char (or start-pos 1))
  3858. (add-text-properties (point-min) (point-max)
  3859. `(org-agenda-type agenda
  3860. org-last-args (,arg ,start-day ,span)
  3861. org-redo-cmd ,org-agenda-redo-command
  3862. org-series-cmd ,org-cmd))
  3863. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3864. (org-agenda-show-clocking-issues))
  3865. (org-agenda-finalize)
  3866. (setq buffer-read-only t)
  3867. (message ""))))
  3868. (autoload 'org-agenda-list "org-agenda" "\
  3869. Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3870. The view will be for the current day or week, but from the overview buffer
  3871. you will be able to go to other days/weeks.
  3872. With a numeric prefix argument in an interactive call, the agenda will
  3873. span ARG days. Lisp programs should instead specify SPAN to change
  3874. the number of days. SPAN defaults to `org-agenda-span'.
  3875. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3876. given in `org-agenda-start-on-weekday'.
  3877. \(fn &optional ARG START-DAY SPAN)" t nil)
  3878. (defun org-agenda-ndays-to-span (n)
  3879. "Return a span symbol for a span of N days, or N if none matches."
  3880. (cond ((symbolp n) n)
  3881. ((= n 1) 'day)
  3882. ((= n 7) 'week)
  3883. (t n)))
  3884. (defun org-agenda-span-to-ndays (span &optional start-day)
  3885. "Return ndays from SPAN, possibly starting at START-DAY."
  3886. (cond ((numberp span) span)
  3887. ((eq span 'day) 1)
  3888. ((eq span 'week) 7)
  3889. ((eq span 'month)
  3890. (let ((date (calendar-gregorian-from-absolute start-day)))
  3891. (calendar-last-day-of-month (car date) (caddr date))))
  3892. ((eq span 'year)
  3893. (let ((date (calendar-gregorian-from-absolute start-day)))
  3894. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3895. (defun org-agenda-span-name (span)
  3896. "Return a SPAN name."
  3897. (if (null span)
  3898. ""
  3899. (if (symbolp span)
  3900. (capitalize (symbol-name span))
  3901. (format "%d days" span))))
  3902. ;;; Agenda word search
  3903. (defvar org-agenda-search-history nil)
  3904. (defvar org-search-syntax-table nil
  3905. "Special syntax table for org-mode search.
  3906. In this table, we have single quotes not as word constituents, to
  3907. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3908. (defvar org-mode-syntax-table) ; From org.el
  3909. (defun org-search-syntax-table ()
  3910. (unless org-search-syntax-table
  3911. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3912. (modify-syntax-entry ?' "." org-search-syntax-table)
  3913. (modify-syntax-entry ?` "." org-search-syntax-table))
  3914. org-search-syntax-table)
  3915. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3916. ;;;###autoload
  3917. (defun org-search-view (&optional todo-only string edit-at)
  3918. "Show all entries that contain a phrase or words or regular expressions.
  3919. With optional prefix argument TODO-ONLY, only consider entries that are
  3920. TODO entries. The argument STRING can be used to pass a default search
  3921. string into this function. If EDIT-AT is non-nil, it means that the
  3922. user should get a chance to edit this string, with cursor at position
  3923. EDIT-AT.
  3924. The search string can be viewed either as a phrase that should be found as
  3925. is, or it can be broken into a number of snippets, each of which must match
  3926. in a Boolean way to select an entry. The default depends on the variable
  3927. `org-agenda-search-view-always-boolean'.
  3928. Even if this is turned off (the default) you can always switch to
  3929. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3930. The default is a direct search of the whole phrase, where each space in
  3931. the search string can expand to an arbitrary amount of whitespace,
  3932. including newlines.
  3933. If using a Boolean search, the search string is split on whitespace and
  3934. each snippet is searched separately, with logical AND to select an entry.
  3935. Words prefixed with a minus must *not* occur in the entry. Words without
  3936. a prefix or prefixed with a plus must occur in the entry. Matching is
  3937. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3938. match whole words, not parts of a word) if
  3939. `org-agenda-search-view-force-full-words' is set (default is nil).
  3940. Boolean search snippets enclosed by curly braces are interpreted as
  3941. regular expressions that must or (when preceded with \"-\") must not
  3942. match in the entry. Snippets enclosed into double quotes will be taken
  3943. as a whole, to include whitespace.
  3944. - If the search string starts with an asterisk, search only in headlines.
  3945. - If (possibly after the leading star) the search string starts with an
  3946. exclamation mark, this also means to look at TODO entries only, an effect
  3947. that can also be achieved with a prefix argument.
  3948. - If (possibly after star and exclamation mark) the search string starts
  3949. with a colon, this will mean that the (non-regexp) snippets of the
  3950. Boolean search must match as full words.
  3951. This command searches the agenda files, and in addition the files listed
  3952. in `org-agenda-text-search-extra-files'."
  3953. (interactive "P")
  3954. (if org-agenda-overriding-arguments
  3955. (setq todo-only (car org-agenda-overriding-arguments)
  3956. string (nth 1 org-agenda-overriding-arguments)
  3957. edit-at (nth 2 org-agenda-overriding-arguments)))
  3958. (let* ((props (list 'face nil
  3959. 'done-face 'org-agenda-done
  3960. 'org-not-done-regexp org-not-done-regexp
  3961. 'org-todo-regexp org-todo-regexp
  3962. 'org-complex-heading-regexp org-complex-heading-regexp
  3963. 'mouse-face 'highlight
  3964. 'help-echo (format "mouse-2 or RET jump to location")))
  3965. (full-words org-agenda-search-view-force-full-words)
  3966. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3967. regexp rtn rtnall files file pos inherited-tags
  3968. marker category category-pos level tags c neg re boolean
  3969. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3970. (unless (and (not edit-at)
  3971. (stringp string)
  3972. (string-match "\\S-" string))
  3973. (setq string (read-string
  3974. (if org-agenda-search-view-always-boolean
  3975. "[+-]Word/{Regexp} ...: "
  3976. "Phrase or [+-]Word/{Regexp} ...: ")
  3977. (cond
  3978. ((integerp edit-at) (cons string edit-at))
  3979. (edit-at string))
  3980. 'org-agenda-search-history)))
  3981. (catch 'exit
  3982. (if org-agenda-sticky
  3983. (setq org-agenda-buffer-name
  3984. (if (stringp string)
  3985. (format "*Org Agenda(%s:%s)*"
  3986. (or org-keys (or (and todo-only "S") "s")) string)
  3987. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3988. (org-agenda-prepare "SEARCH")
  3989. (org-compile-prefix-format 'search)
  3990. (org-set-sorting-strategy 'search)
  3991. (setq org-agenda-redo-command
  3992. (list 'org-search-view (if todo-only t nil)
  3993. (list 'if 'current-prefix-arg nil string)))
  3994. (setq org-agenda-query-string string)
  3995. (if (equal (string-to-char string) ?*)
  3996. (setq hdl-only t
  3997. words (substring string 1))
  3998. (setq words string))
  3999. (when (equal (string-to-char words) ?!)
  4000. (setq todo-only t
  4001. words (substring words 1)))
  4002. (when (equal (string-to-char words) ?:)
  4003. (setq full-words t
  4004. words (substring words 1)))
  4005. (if (or org-agenda-search-view-always-boolean
  4006. (member (string-to-char words) '(?- ?+ ?\{)))
  4007. (setq boolean t))
  4008. (setq words (org-split-string words))
  4009. (let (www w)
  4010. (while (setq w (pop words))
  4011. (while (and (string-match "\\\\\\'" w) words)
  4012. (setq w (concat (substring w 0 -1) " " (pop words))))
  4013. (push w www))
  4014. (setq words (nreverse www) www nil)
  4015. (while (setq w (pop words))
  4016. (when (and (string-match "\\`[-+]?{" w)
  4017. (not (string-match "}\\'" w)))
  4018. (while (and words (not (string-match "}\\'" (car words))))
  4019. (setq w (concat w " " (pop words))))
  4020. (setq w (concat w " " (pop words))))
  4021. (push w www))
  4022. (setq words (nreverse www)))
  4023. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4024. (when boolean
  4025. (let (wds w)
  4026. (while (setq w (pop words))
  4027. (if (or (equal (substring w 0 1) "\"")
  4028. (and (> (length w) 1)
  4029. (member (substring w 0 1) '("+" "-"))
  4030. (equal (substring w 1 2) "\"")))
  4031. (while (and words (not (equal (substring w -1) "\"")))
  4032. (setq w (concat w " " (pop words)))))
  4033. (and (string-match "\\`\\([-+]?\\)\"" w)
  4034. (setq w (replace-match "\\1" nil nil w)))
  4035. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4036. (push w wds))
  4037. (setq words (nreverse wds))))
  4038. (if boolean
  4039. (mapc (lambda (w)
  4040. (setq c (string-to-char w))
  4041. (if (equal c ?-)
  4042. (setq neg t w (substring w 1))
  4043. (if (equal c ?+)
  4044. (setq neg nil w (substring w 1))
  4045. (setq neg nil)))
  4046. (if (string-match "\\`{.*}\\'" w)
  4047. (setq re (substring w 1 -1))
  4048. (if full-words
  4049. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4050. (setq re (regexp-quote (downcase w)))))
  4051. (if neg (push re regexps-) (push re regexps+)))
  4052. words)
  4053. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4054. regexps+))
  4055. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4056. (if (not regexps+)
  4057. (setq regexp org-outline-regexp-bol)
  4058. (setq regexp (pop regexps+))
  4059. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4060. regexp))))
  4061. (setq files (org-agenda-files nil 'ifmode))
  4062. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4063. (pop org-agenda-text-search-extra-files)
  4064. (setq files (org-add-archive-files files)))
  4065. (setq files (append files org-agenda-text-search-extra-files)
  4066. rtnall nil)
  4067. (while (setq file (pop files))
  4068. (setq ee nil)
  4069. (catch 'nextfile
  4070. (org-check-agenda-file file)
  4071. (setq buffer (if (file-exists-p file)
  4072. (org-get-agenda-file-buffer file)
  4073. (error "No such file %s" file)))
  4074. (if (not buffer)
  4075. ;; If file does not exist, make sure an error message is sent
  4076. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4077. file))))
  4078. (with-current-buffer buffer
  4079. (with-syntax-table (org-search-syntax-table)
  4080. (unless (derived-mode-p 'org-mode)
  4081. (error "Agenda file %s is not in `org-mode'" file))
  4082. (let ((case-fold-search t))
  4083. (save-excursion
  4084. (save-restriction
  4085. (if org-agenda-restrict
  4086. (narrow-to-region org-agenda-restrict-begin
  4087. org-agenda-restrict-end)
  4088. (widen))
  4089. (goto-char (point-min))
  4090. (unless (or (org-at-heading-p)
  4091. (outline-next-heading))
  4092. (throw 'nextfile t))
  4093. (goto-char (max (point-min) (1- (point))))
  4094. (while (re-search-forward regexp nil t)
  4095. (org-back-to-heading t)
  4096. (while (and org-agenda-search-view-max-outline-level
  4097. (> (org-reduced-level (org-outline-level))
  4098. org-agenda-search-view-max-outline-level)
  4099. (forward-line -1)
  4100. (outline-back-to-heading t)))
  4101. (skip-chars-forward "* ")
  4102. (setq beg (point-at-bol)
  4103. beg1 (point)
  4104. end (progn
  4105. (outline-next-heading)
  4106. (while (and org-agenda-search-view-max-outline-level
  4107. (> (org-reduced-level (org-outline-level))
  4108. org-agenda-search-view-max-outline-level)
  4109. (forward-line 1)
  4110. (outline-next-heading)))
  4111. (point)))
  4112. (catch :skip
  4113. (goto-char beg)
  4114. (org-agenda-skip)
  4115. (setq str (buffer-substring-no-properties
  4116. (point-at-bol)
  4117. (if hdl-only (point-at-eol) end)))
  4118. (mapc (lambda (wr) (when (string-match wr str)
  4119. (goto-char (1- end))
  4120. (throw :skip t)))
  4121. regexps-)
  4122. (mapc (lambda (wr) (unless (string-match wr str)
  4123. (goto-char (1- end))
  4124. (throw :skip t)))
  4125. (if todo-only
  4126. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4127. regexps+)
  4128. regexps+))
  4129. (goto-char beg)
  4130. (setq marker (org-agenda-new-marker (point))
  4131. category (org-get-category)
  4132. level (make-string (org-reduced-level (org-outline-level)) ? )
  4133. category-pos (get-text-property (point) 'org-category-position)
  4134. inherited-tags
  4135. (or (eq org-agenda-show-inherited-tags 'always)
  4136. (and (listp org-agenda-show-inherited-tags)
  4137. (memq 'todo org-agenda-show-inherited-tags))
  4138. (and (eq org-agenda-show-inherited-tags t)
  4139. (or (eq org-agenda-use-tag-inheritance t)
  4140. (memq 'todo org-agenda-use-tag-inheritance))))
  4141. tags (org-get-tags-at nil (not inherited-tags))
  4142. txt (org-agenda-format-item
  4143. ""
  4144. (buffer-substring-no-properties
  4145. beg1 (point-at-eol))
  4146. level category tags t))
  4147. (org-add-props txt props
  4148. 'org-marker marker 'org-hd-marker marker
  4149. 'org-todo-regexp org-todo-regexp
  4150. 'level level
  4151. 'org-complex-heading-regexp org-complex-heading-regexp
  4152. 'priority 1000 'org-category category
  4153. 'org-category-position category-pos
  4154. 'type "search")
  4155. (push txt ee)
  4156. (goto-char (1- end))))))))))
  4157. (setq rtn (nreverse ee))
  4158. (setq rtnall (append rtnall rtn)))
  4159. (if org-agenda-overriding-header
  4160. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4161. nil 'face 'org-agenda-structure) "\n")
  4162. (insert "Search words: ")
  4163. (add-text-properties (point-min) (1- (point))
  4164. (list 'face 'org-agenda-structure))
  4165. (setq pos (point))
  4166. (insert string "\n")
  4167. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4168. (setq pos (point))
  4169. (unless org-agenda-multi
  4170. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4171. (add-text-properties pos (1- (point))
  4172. (list 'face 'org-agenda-structure))))
  4173. (org-agenda-mark-header-line (point-min))
  4174. (when rtnall
  4175. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4176. (goto-char (point-min))
  4177. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4178. (add-text-properties (point-min) (point-max)
  4179. `(org-agenda-type search
  4180. org-last-args (,todo-only ,string ,edit-at)
  4181. org-redo-cmd ,org-agenda-redo-command
  4182. org-series-cmd ,org-cmd))
  4183. (org-agenda-finalize)
  4184. (setq buffer-read-only t))))
  4185. (autoload 'org-search-view "org-agenda" "\
  4186. Show all entries that contain a phrase or words or regular expressions.
  4187. With optional prefix argument TODO-ONLY, only consider entries that are
  4188. TODO entries. The argument STRING can be used to pass a default search
  4189. string into this function. If EDIT-AT is non-nil, it means that the
  4190. user should get a chance to edit this string, with cursor at position
  4191. EDIT-AT.
  4192. The search string can be viewed either as a phrase that should be found as
  4193. is, or it can be broken into a number of snippets, each of which must match
  4194. in a Boolean way to select an entry. The default depends on the variable
  4195. `org-agenda-search-view-always-boolean'.
  4196. Even if this is turned off (the default) you can always switch to
  4197. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4198. The default is a direct search of the whole phrase, where each space in
  4199. the search string can expand to an arbitrary amount of whitespace,
  4200. including newlines.
  4201. If using a Boolean search, the search string is split on whitespace and
  4202. each snippet is searched separately, with logical AND to select an entry.
  4203. Words prefixed with a minus must *not* occur in the entry. Words without
  4204. a prefix or prefixed with a plus must occur in the entry. Matching is
  4205. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4206. match whole words, not parts of a word) if
  4207. `org-agenda-search-view-force-full-words' is set (default is nil).
  4208. Boolean search snippets enclosed by curly braces are interpreted as
  4209. regular expressions that must or (when preceded with \"-\") must not
  4210. match in the entry. Snippets enclosed into double quotes will be taken
  4211. as a whole, to include whitespace.
  4212. - If the search string starts with an asterisk, search only in headlines.
  4213. - If (possibly after the leading star) the search string starts with an
  4214. exclamation mark, this also means to look at TODO entries only, an effect
  4215. that can also be achieved with a prefix argument.
  4216. - If (possibly after star and exclamation mark) the search string starts
  4217. with a colon, this will mean that the (non-regexp) snippets of the
  4218. Boolean search must match as full words.
  4219. This command searches the agenda files, and in addition the files listed
  4220. in `org-agenda-text-search-extra-files'.
  4221. \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
  4222. ;;; Agenda TODO list
  4223. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4224. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4225. (concat
  4226. (if (or (equal keywords "ALL") (not keywords))
  4227. (propertize "ALL" 'face 'warning)
  4228. (mapconcat
  4229. (lambda (kw)
  4230. (propertize kw 'face (org-get-todo-face kw)))
  4231. (org-split-string keywords "|")
  4232. "|"))
  4233. "\n"))
  4234. (defvar org-select-this-todo-keyword nil)
  4235. (defvar org-last-arg nil)
  4236. ;;;###autoload
  4237. (defun org-todo-list (&optional arg)
  4238. "Show all (not done) TODO entries from all agenda file in a single list.
  4239. The prefix arg can be used to select a specific TODO keyword and limit
  4240. the list to these. When using \\[universal-argument], you will be prompted
  4241. for a keyword. A numeric prefix directly selects the Nth keyword in
  4242. `org-todo-keywords-1'."
  4243. (interactive "P")
  4244. (if org-agenda-overriding-arguments
  4245. (setq arg org-agenda-overriding-arguments))
  4246. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4247. (let* ((today (org-today))
  4248. (date (calendar-gregorian-from-absolute today))
  4249. (kwds org-todo-keywords-for-agenda)
  4250. (completion-ignore-case t)
  4251. (org-select-this-todo-keyword
  4252. (if (stringp arg) arg
  4253. (and arg (integerp arg) (> arg 0)
  4254. (nth (1- arg) kwds))))
  4255. rtn rtnall files file pos)
  4256. (when (equal arg '(4))
  4257. (setq org-select-this-todo-keyword
  4258. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4259. (mapcar 'list kwds) nil nil)))
  4260. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4261. (catch 'exit
  4262. (if org-agenda-sticky
  4263. (setq org-agenda-buffer-name
  4264. (if (stringp org-select-this-todo-keyword)
  4265. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4266. org-select-this-todo-keyword)
  4267. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4268. (org-agenda-prepare "TODO")
  4269. (org-compile-prefix-format 'todo)
  4270. (org-set-sorting-strategy 'todo)
  4271. (setq org-agenda-redo-command
  4272. `(org-todo-list (or (and (numberp current-prefix-arg)
  4273. current-prefix-arg)
  4274. ,org-select-this-todo-keyword
  4275. current-prefix-arg ,arg)))
  4276. (setq files (org-agenda-files nil 'ifmode)
  4277. rtnall nil)
  4278. (while (setq file (pop files))
  4279. (catch 'nextfile
  4280. (org-check-agenda-file file)
  4281. (setq rtn (org-agenda-get-day-entries file date :todo))
  4282. (setq rtnall (append rtnall rtn))))
  4283. (if org-agenda-overriding-header
  4284. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4285. nil 'face 'org-agenda-structure) "\n")
  4286. (insert "Global list of TODO items of type: ")
  4287. (add-text-properties (point-min) (1- (point))
  4288. (list 'face 'org-agenda-structure
  4289. 'short-heading
  4290. (concat "ToDo: "
  4291. (or org-select-this-todo-keyword "ALL"))))
  4292. (org-agenda-mark-header-line (point-min))
  4293. (insert (org-agenda-propertize-selected-todo-keywords
  4294. org-select-this-todo-keyword))
  4295. (setq pos (point))
  4296. (unless org-agenda-multi
  4297. (insert "Available with `N r': (0)[ALL]")
  4298. (let ((n 0) s)
  4299. (mapc (lambda (x)
  4300. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4301. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4302. (insert "\n "))
  4303. (insert " " s))
  4304. kwds))
  4305. (insert "\n"))
  4306. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4307. (org-agenda-mark-header-line (point-min))
  4308. (when rtnall
  4309. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4310. (goto-char (point-min))
  4311. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4312. (add-text-properties (point-min) (point-max)
  4313. `(org-agenda-type todo
  4314. org-last-args ,arg
  4315. org-redo-cmd ,org-agenda-redo-command
  4316. org-series-cmd ,org-cmd))
  4317. (org-agenda-finalize)
  4318. (setq buffer-read-only t))))
  4319. (autoload 'org-todo-list "org-agenda" "\
  4320. Show all (not done) TODO entries from all agenda file in a single list.
  4321. The prefix arg can be used to select a specific TODO keyword and limit
  4322. the list to these. When using \\[universal-argument], you will be prompted
  4323. for a keyword. A numeric prefix directly selects the Nth keyword in
  4324. `org-todo-keywords-1'.
  4325. \(fn &optional ARG)" t nil)
  4326. ;;; Agenda tags match
  4327. ;;;###autoload
  4328. (defun org-tags-view (&optional todo-only match)
  4329. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4330. The prefix arg TODO-ONLY limits the search to TODO entries."
  4331. (interactive "P")
  4332. (if org-agenda-overriding-arguments
  4333. (setq todo-only (car org-agenda-overriding-arguments)
  4334. match (nth 1 org-agenda-overriding-arguments)))
  4335. (let* ((org-tags-match-list-sublevels
  4336. org-tags-match-list-sublevels)
  4337. (completion-ignore-case t)
  4338. rtn rtnall files file pos matcher
  4339. buffer)
  4340. (when (and (stringp match) (not (string-match "\\S-" match)))
  4341. (setq match nil))
  4342. (setq matcher (org-make-tags-matcher match)
  4343. match (car matcher) matcher (cdr matcher))
  4344. (catch 'exit
  4345. (if org-agenda-sticky
  4346. (setq org-agenda-buffer-name
  4347. (if (stringp match)
  4348. (format "*Org Agenda(%s:%s)*"
  4349. (or org-keys (or (and todo-only "M") "m")) match)
  4350. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4351. (org-agenda-prepare (concat "TAGS " match))
  4352. (org-compile-prefix-format 'tags)
  4353. (org-set-sorting-strategy 'tags)
  4354. (setq org-agenda-query-string match)
  4355. (setq org-agenda-redo-command
  4356. (list 'org-tags-view `(quote ,todo-only)
  4357. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4358. (setq files (org-agenda-files nil 'ifmode)
  4359. rtnall nil)
  4360. (while (setq file (pop files))
  4361. (catch 'nextfile
  4362. (org-check-agenda-file file)
  4363. (setq buffer (if (file-exists-p file)
  4364. (org-get-agenda-file-buffer file)
  4365. (error "No such file %s" file)))
  4366. (if (not buffer)
  4367. ;; If file does not exist, error message to agenda
  4368. (setq rtn (list
  4369. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4370. rtnall (append rtnall rtn))
  4371. (with-current-buffer buffer
  4372. (unless (derived-mode-p 'org-mode)
  4373. (error "Agenda file %s is not in `org-mode'" file))
  4374. (save-excursion
  4375. (save-restriction
  4376. (if org-agenda-restrict
  4377. (narrow-to-region org-agenda-restrict-begin
  4378. org-agenda-restrict-end)
  4379. (widen))
  4380. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4381. (setq rtnall (append rtnall rtn))))))))
  4382. (if org-agenda-overriding-header
  4383. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4384. nil 'face 'org-agenda-structure) "\n")
  4385. (insert "Headlines with TAGS match: ")
  4386. (add-text-properties (point-min) (1- (point))
  4387. (list 'face 'org-agenda-structure
  4388. 'short-heading
  4389. (concat "Match: " match)))
  4390. (setq pos (point))
  4391. (insert match "\n")
  4392. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4393. (setq pos (point))
  4394. (unless org-agenda-multi
  4395. (insert "Press `C-u r' to search again with new search string\n"))
  4396. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4397. (org-agenda-mark-header-line (point-min))
  4398. (when rtnall
  4399. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4400. (goto-char (point-min))
  4401. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4402. (add-text-properties (point-min) (point-max)
  4403. `(org-agenda-type tags
  4404. org-last-args (,todo-only ,match)
  4405. org-redo-cmd ,org-agenda-redo-command
  4406. org-series-cmd ,org-cmd))
  4407. (org-agenda-finalize)
  4408. (setq buffer-read-only t))))
  4409. (autoload 'org-tags-view "org-agenda" "\
  4410. Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4411. The prefix arg TODO-ONLY limits the search to TODO entries.
  4412. \(fn &optional TODO-ONLY MATCH)" t nil)
  4413. ;;; Agenda Finding stuck projects
  4414. (defvar org-agenda-skip-regexp nil
  4415. "Regular expression used in skipping subtrees for the agenda.
  4416. This is basically a temporary global variable that can be set and then
  4417. used by user-defined selections using `org-agenda-skip-function'.")
  4418. (defvar org-agenda-overriding-header nil
  4419. "When set during agenda, todo and tags searches it replaces the header.
  4420. This variable should not be set directly, but custom commands can bind it
  4421. in the options section.")
  4422. (defun org-agenda-skip-entry-when-regexp-matches ()
  4423. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4424. If yes, it returns the end position of this entry, causing agenda commands
  4425. to skip the entry but continuing the search in the subtree. This is a
  4426. function that can be put into `org-agenda-skip-function' for the duration
  4427. of a command."
  4428. (let ((end (save-excursion (org-end-of-subtree t)))
  4429. skip)
  4430. (save-excursion
  4431. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4432. (and skip end)))
  4433. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4434. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4435. If yes, it returns the end position of this tree, causing agenda commands
  4436. to skip this subtree. This is a function that can be put into
  4437. `org-agenda-skip-function' for the duration of a command."
  4438. (let ((end (save-excursion (org-end-of-subtree t)))
  4439. skip)
  4440. (save-excursion
  4441. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4442. (and skip end)))
  4443. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4444. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4445. If yes, it returns the end position of the current entry (NOT the tree),
  4446. causing agenda commands to skip the entry but continuing the search in
  4447. the subtree. This is a function that can be put into
  4448. `org-agenda-skip-function' for the duration of a command. An important
  4449. use of this function is for the stuck project list."
  4450. (let ((end (save-excursion (org-end-of-subtree t)))
  4451. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4452. skip)
  4453. (save-excursion
  4454. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4455. (and skip entry-end)))
  4456. (defun org-agenda-skip-entry-if (&rest conditions)
  4457. "Skip entry if any of CONDITIONS is true.
  4458. See `org-agenda-skip-if' for details."
  4459. (org-agenda-skip-if nil conditions))
  4460. (defun org-agenda-skip-subtree-if (&rest conditions)
  4461. "Skip entry if any of CONDITIONS is true.
  4462. See `org-agenda-skip-if' for details."
  4463. (org-agenda-skip-if t conditions))
  4464. (defun org-agenda-skip-if (subtree conditions)
  4465. "Checks current entity for CONDITIONS.
  4466. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4467. the entry (i.e. the text before the next heading) is checked.
  4468. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4469. from different tests. Valid conditions are:
  4470. scheduled Check if there is a scheduled cookie
  4471. notscheduled Check if there is no scheduled cookie
  4472. deadline Check if there is a deadline
  4473. notdeadline Check if there is no deadline
  4474. timestamp Check if there is a timestamp (also deadline or scheduled)
  4475. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4476. regexp Check if regexp matches
  4477. notregexp Check if regexp does not match.
  4478. todo Check if TODO keyword matches
  4479. nottodo Check if TODO keyword does not match
  4480. The regexp is taken from the conditions list, it must come right after
  4481. the `regexp' or `notregexp' element.
  4482. `todo' and `nottodo' accept as an argument a list of todo
  4483. keywords, which may include \"*\" to match any todo keyword.
  4484. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4485. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4486. Instead of a list, a keyword class may be given. For example:
  4487. (org-agenda-skip-entry-if 'nottodo 'done)
  4488. would skip entries that haven't been marked with any of \"DONE\"
  4489. keywords. Possible classes are: `todo', `done', `any'.
  4490. If any of these conditions is met, this function returns the end point of
  4491. the entity, causing the search to continue from there. This is a function
  4492. that can be put into `org-agenda-skip-function' for the duration of a command."
  4493. (let (beg end m)
  4494. (org-back-to-heading t)
  4495. (setq beg (point)
  4496. end (if subtree
  4497. (progn (org-end-of-subtree t) (point))
  4498. (progn (outline-next-heading) (1- (point)))))
  4499. (goto-char beg)
  4500. (and
  4501. (or
  4502. (and (memq 'scheduled conditions)
  4503. (re-search-forward org-scheduled-time-regexp end t))
  4504. (and (memq 'notscheduled conditions)
  4505. (not (re-search-forward org-scheduled-time-regexp end t)))
  4506. (and (memq 'deadline conditions)
  4507. (re-search-forward org-deadline-time-regexp end t))
  4508. (and (memq 'notdeadline conditions)
  4509. (not (re-search-forward org-deadline-time-regexp end t)))
  4510. (and (memq 'timestamp conditions)
  4511. (re-search-forward org-ts-regexp end t))
  4512. (and (memq 'nottimestamp conditions)
  4513. (not (re-search-forward org-ts-regexp end t)))
  4514. (and (setq m (memq 'regexp conditions))
  4515. (stringp (nth 1 m))
  4516. (re-search-forward (nth 1 m) end t))
  4517. (and (setq m (memq 'notregexp conditions))
  4518. (stringp (nth 1 m))
  4519. (not (re-search-forward (nth 1 m) end t)))
  4520. (and (or
  4521. (setq m (memq 'nottodo conditions))
  4522. (setq m (memq 'todo-unblocked conditions))
  4523. (setq m (memq 'nottodo-unblocked conditions))
  4524. (setq m (memq 'todo conditions)))
  4525. (org-agenda-skip-if-todo m end)))
  4526. end)))
  4527. (defun org-agenda-skip-if-todo (args end)
  4528. "Helper function for `org-agenda-skip-if', do not use it directly.
  4529. ARGS is a list with first element either `todo', `nottodo',
  4530. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4531. a list of TODO keywords, or a state symbol `todo' or `done' or
  4532. `any'."
  4533. (let ((kw (car args))
  4534. (arg (cadr args))
  4535. todo-wds todo-re)
  4536. (setq todo-wds
  4537. (org-uniquify
  4538. (cond
  4539. ((listp arg) ;; list of keywords
  4540. (if (member "*" arg)
  4541. (mapcar 'substring-no-properties org-todo-keywords-1)
  4542. arg))
  4543. ((symbolp arg) ;; keyword class name
  4544. (cond
  4545. ((eq arg 'todo)
  4546. (org-delete-all org-done-keywords
  4547. (mapcar 'substring-no-properties
  4548. org-todo-keywords-1)))
  4549. ((eq arg 'done) org-done-keywords)
  4550. ((eq arg 'any)
  4551. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4552. (setq todo-re
  4553. (concat "^\\*+[ \t]+\\<\\("
  4554. (mapconcat 'identity todo-wds "\\|")
  4555. "\\)\\>"))
  4556. (cond
  4557. ((eq kw 'todo) (re-search-forward todo-re end t))
  4558. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4559. ((eq kw 'todo-unblocked)
  4560. (catch 'unblocked
  4561. (while (re-search-forward todo-re end t)
  4562. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4563. nil))
  4564. ((eq kw 'nottodo-unblocked)
  4565. (catch 'unblocked
  4566. (while (re-search-forward todo-re end t)
  4567. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4568. t))
  4569. )))
  4570. ;;;###autoload
  4571. (defun org-agenda-list-stuck-projects (&rest ignore)
  4572. "Create agenda view for projects that are stuck.
  4573. Stuck projects are project that have no next actions. For the definitions
  4574. of what a project is and how to check if it stuck, customize the variable
  4575. `org-stuck-projects'."
  4576. (interactive)
  4577. (let* ((org-agenda-skip-function
  4578. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4579. ;; We could have used org-agenda-skip-if here.
  4580. (org-agenda-overriding-header
  4581. (or org-agenda-overriding-header "List of stuck projects: "))
  4582. (matcher (nth 0 org-stuck-projects))
  4583. (todo (nth 1 org-stuck-projects))
  4584. (todo-wds (if (member "*" todo)
  4585. (progn
  4586. (org-agenda-prepare-buffers (org-agenda-files
  4587. nil 'ifmode))
  4588. (org-delete-all
  4589. org-done-keywords-for-agenda
  4590. (copy-sequence org-todo-keywords-for-agenda)))
  4591. todo))
  4592. (todo-re (concat "^\\*+[ \t]+\\("
  4593. (mapconcat 'identity todo-wds "\\|")
  4594. "\\)\\>"))
  4595. (tags (nth 2 org-stuck-projects))
  4596. (tags-re (if (member "*" tags)
  4597. (concat org-outline-regexp-bol
  4598. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4599. (if tags
  4600. (concat org-outline-regexp-bol
  4601. ".*:\\("
  4602. (mapconcat 'identity tags "\\|")
  4603. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4604. (gen-re (nth 3 org-stuck-projects))
  4605. (re-list
  4606. (delq nil
  4607. (list
  4608. (if todo todo-re)
  4609. (if tags tags-re)
  4610. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4611. gen-re)))))
  4612. (setq org-agenda-skip-regexp
  4613. (if re-list
  4614. (mapconcat 'identity re-list "\\|")
  4615. (error "No information how to identify unstuck projects")))
  4616. (org-tags-view nil matcher)
  4617. (with-current-buffer org-agenda-buffer-name
  4618. (setq org-agenda-redo-command
  4619. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4620. (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
  4621. Create agenda view for projects that are stuck.
  4622. Stuck projects are project that have no next actions. For the definitions
  4623. of what a project is and how to check if it stuck, customize the variable
  4624. `org-stuck-projects'.
  4625. \(fn &rest IGNORE)" t nil)
  4626. ;;; Diary integration
  4627. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4628. (defvar diary-list-entries-hook)
  4629. (defvar diary-time-regexp)
  4630. (defun org-get-entries-from-diary (date)
  4631. "Get the (Emacs Calendar) diary entries for DATE."
  4632. (require 'diary-lib)
  4633. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4634. (diary-display-hook '(fancy-diary-display))
  4635. (diary-display-function 'fancy-diary-display)
  4636. (pop-up-frames nil)
  4637. (diary-list-entries-hook
  4638. (cons 'org-diary-default-entry diary-list-entries-hook))
  4639. (diary-file-name-prefix nil) ; turn this feature off
  4640. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4641. entries
  4642. (org-disable-agenda-to-diary t))
  4643. (save-excursion
  4644. (save-window-excursion
  4645. (funcall (if (fboundp 'diary-list-entries)
  4646. 'diary-list-entries 'list-diary-entries)
  4647. date 1)))
  4648. (if (not (get-buffer diary-fancy-buffer))
  4649. (setq entries nil)
  4650. (with-current-buffer diary-fancy-buffer
  4651. (setq buffer-read-only nil)
  4652. (if (zerop (buffer-size))
  4653. ;; No entries
  4654. (setq entries nil)
  4655. ;; Omit the date and other unnecessary stuff
  4656. (org-agenda-cleanup-fancy-diary)
  4657. ;; Add prefix to each line and extend the text properties
  4658. (if (zerop (buffer-size))
  4659. (setq entries nil)
  4660. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4661. (setq entries
  4662. (with-temp-buffer
  4663. (insert entries) (goto-char (point-min))
  4664. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4665. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4666. (replace-match (concat "; " (match-string 1)))))
  4667. (buffer-string)))))
  4668. (set-buffer-modified-p nil)
  4669. (kill-buffer diary-fancy-buffer)))
  4670. (when entries
  4671. (setq entries (org-split-string entries "\n"))
  4672. (setq entries
  4673. (mapcar
  4674. (lambda (x)
  4675. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4676. ;; Extend the text properties to the beginning of the line
  4677. (org-add-props x (text-properties-at (1- (length x)) x)
  4678. 'type "diary" 'date date 'face 'org-agenda-diary))
  4679. entries)))))
  4680. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4681. "Hook run when the fancy diary buffer is cleaned up.")
  4682. (defun org-agenda-cleanup-fancy-diary ()
  4683. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4684. This gets rid of the date, the underline under the date, and
  4685. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4686. date. It also removes lines that contain only whitespace."
  4687. (goto-char (point-min))
  4688. (if (looking-at ".*?:[ \t]*")
  4689. (progn
  4690. (replace-match "")
  4691. (re-search-forward "\n=+$" nil t)
  4692. (replace-match "")
  4693. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4694. (re-search-forward "\n=+$" nil t)
  4695. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4696. (goto-char (point-min))
  4697. (while (re-search-forward "^ +\n" nil t)
  4698. (replace-match ""))
  4699. (goto-char (point-min))
  4700. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4701. (replace-match ""))
  4702. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4703. ;; Make sure entries from the diary have the right text properties.
  4704. (eval-after-load "diary-lib"
  4705. '(if (boundp 'diary-modify-entry-list-string-function)
  4706. ;; We can rely on the hook, nothing to do
  4707. nil
  4708. ;; Hook not available, must use advice to make this work
  4709. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4710. "Make the position visible."
  4711. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4712. (stringp string)
  4713. buffer-file-name)
  4714. (setq string (org-modify-diary-entry-string string))))))
  4715. (defun org-modify-diary-entry-string (string)
  4716. "Add text properties to string, allowing org-mode to act on it."
  4717. (org-add-props string nil
  4718. 'mouse-face 'highlight
  4719. 'help-echo (if buffer-file-name
  4720. (format "mouse-2 or RET jump to diary file %s"
  4721. (abbreviate-file-name buffer-file-name))
  4722. "")
  4723. 'org-agenda-diary-link t
  4724. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4725. (defun org-diary-default-entry ()
  4726. "Add a dummy entry to the diary.
  4727. Needed to avoid empty dates which mess up holiday display."
  4728. ;; Catch the error if dealing with the new add-to-diary-alist
  4729. (when org-disable-agenda-to-diary
  4730. (condition-case nil
  4731. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4732. (error
  4733. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4734. (defun org-add-to-diary-list (&rest args)
  4735. (if (fboundp 'diary-add-to-list)
  4736. (apply 'diary-add-to-list args)
  4737. (apply 'add-to-diary-list args)))
  4738. (defvar org-diary-last-run-time nil)
  4739. ;;;###autoload
  4740. (defun org-diary (&rest args)
  4741. "Return diary information from org files.
  4742. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4743. It accesses org files and extracts information from those files to be
  4744. listed in the diary. The function accepts arguments specifying what
  4745. items should be listed. For a list of arguments allowed here, see the
  4746. variable `org-agenda-entry-types'.
  4747. The call in the diary file should look like this:
  4748. &%%(org-diary) ~/path/to/some/orgfile.org
  4749. Use a separate line for each org file to check. Or, if you omit the file name,
  4750. all files listed in `org-agenda-files' will be checked automatically:
  4751. &%%(org-diary)
  4752. If you don't give any arguments (as in the example above), the default
  4753. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4754. So the example above may also be written as
  4755. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4756. The function expects the lisp variables `entry' and `date' to be provided
  4757. by the caller, because this is how the calendar works. Don't use this
  4758. function from a program - use `org-agenda-get-day-entries' instead."
  4759. (when (> (- (org-float-time)
  4760. org-agenda-last-marker-time)
  4761. 5)
  4762. ;; I am not sure if this works with sticky agendas, because the marker
  4763. ;; list is then no longer a global variable.
  4764. (org-agenda-reset-markers))
  4765. (org-compile-prefix-format 'agenda)
  4766. (org-set-sorting-strategy 'agenda)
  4767. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4768. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4769. (list entry)
  4770. (org-agenda-files t)))
  4771. (time (org-float-time))
  4772. file rtn results)
  4773. (when (or (not org-diary-last-run-time)
  4774. (> (- time
  4775. org-diary-last-run-time)
  4776. 3))
  4777. (org-agenda-prepare-buffers files))
  4778. (setq org-diary-last-run-time time)
  4779. ;; If this is called during org-agenda, don't return any entries to
  4780. ;; the calendar. Org Agenda will list these entries itself.
  4781. (if org-disable-agenda-to-diary (setq files nil))
  4782. (while (setq file (pop files))
  4783. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4784. (setq results (append results rtn)))
  4785. (when results
  4786. (setq results
  4787. (mapcar (lambda (i) (replace-regexp-in-string
  4788. org-bracket-link-regexp "\\3" i)) results))
  4789. (concat (org-agenda-finalize-entries results) "\n"))))
  4790. (autoload 'org-diary "org-agenda" "\
  4791. Return diary information from org files.
  4792. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4793. It accesses org files and extracts information from those files to be
  4794. listed in the diary. The function accepts arguments specifying what
  4795. items should be listed. For a list of arguments allowed here, see the
  4796. variable `org-agenda-entry-types'.
  4797. The call in the diary file should look like this:
  4798. &%%(org-diary) ~/path/to/some/orgfile.org
  4799. Use a separate line for each org file to check. Or, if you omit the file name,
  4800. all files listed in `org-agenda-files' will be checked automatically:
  4801. &%%(org-diary)
  4802. If you don't give any arguments (as in the example above), the default
  4803. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4804. So the example above may also be written as
  4805. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4806. The function expects the lisp variables `entry' and `date' to be provided
  4807. by the caller, because this is how the calendar works. Don't use this
  4808. function from a program - use `org-agenda-get-day-entries' instead.
  4809. \(fn &rest ARGS)" nil nil)
  4810. ;;; Agenda entry finders
  4811. (defun org-agenda-get-day-entries (file date &rest args)
  4812. "Does the work for `org-diary' and `org-agenda'.
  4813. FILE is the path to a file to be checked for entries. DATE is date like
  4814. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4815. which kind of entries should be extracted. For details about these, see
  4816. the documentation of `org-diary'."
  4817. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4818. (let* ((org-startup-folded nil)
  4819. (org-startup-align-all-tables nil)
  4820. (buffer (if (file-exists-p file)
  4821. (org-get-agenda-file-buffer file)
  4822. (error "No such file %s" file)))
  4823. arg results rtn deadline-results)
  4824. (if (not buffer)
  4825. ;; If file does not exist, make sure an error message ends up in diary
  4826. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4827. (with-current-buffer buffer
  4828. (unless (derived-mode-p 'org-mode)
  4829. (error "Agenda file %s is not in `org-mode'" file))
  4830. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4831. (let ((case-fold-search nil))
  4832. (save-excursion
  4833. (save-restriction
  4834. (if org-agenda-restrict
  4835. (narrow-to-region org-agenda-restrict-begin
  4836. org-agenda-restrict-end)
  4837. (widen))
  4838. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4839. (while (setq arg (pop args))
  4840. (cond
  4841. ((and (eq arg :todo)
  4842. (equal date (calendar-gregorian-from-absolute
  4843. (org-today))))
  4844. (setq rtn (org-agenda-get-todos))
  4845. (setq results (append results rtn)))
  4846. ((eq arg :timestamp)
  4847. (setq rtn (org-agenda-get-blocks))
  4848. (setq results (append results rtn))
  4849. (setq rtn (org-agenda-get-timestamps deadline-results))
  4850. (setq results (append results rtn)))
  4851. ((eq arg :sexp)
  4852. (setq rtn (org-agenda-get-sexps))
  4853. (setq results (append results rtn)))
  4854. ((eq arg :scheduled)
  4855. (setq rtn (org-agenda-get-scheduled deadline-results))
  4856. (setq results (append results rtn)))
  4857. ((eq arg :closed)
  4858. (setq rtn (org-agenda-get-progress))
  4859. (setq results (append results rtn)))
  4860. ((eq arg :deadline)
  4861. (setq rtn (org-agenda-get-deadlines))
  4862. (setq deadline-results (copy-sequence rtn))
  4863. (setq results (append results rtn))))))))
  4864. results))))
  4865. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4866. (defun org-agenda-get-todos ()
  4867. "Return the TODO information for agenda display."
  4868. (let* ((props (list 'face nil
  4869. 'done-face 'org-agenda-done
  4870. 'org-not-done-regexp org-not-done-regexp
  4871. 'org-todo-regexp org-todo-regexp
  4872. 'org-complex-heading-regexp org-complex-heading-regexp
  4873. 'mouse-face 'highlight
  4874. 'help-echo
  4875. (format "mouse-2 or RET jump to org file %s"
  4876. (abbreviate-file-name buffer-file-name))))
  4877. (regexp (format org-heading-keyword-regexp-format
  4878. (cond
  4879. ((and org-select-this-todo-keyword
  4880. (equal org-select-this-todo-keyword "*"))
  4881. org-todo-regexp)
  4882. (org-select-this-todo-keyword
  4883. (concat "\\("
  4884. (mapconcat 'identity
  4885. (org-split-string
  4886. org-select-this-todo-keyword
  4887. "|")
  4888. "\\|") "\\)"))
  4889. (t org-not-done-regexp))))
  4890. marker priority category category-pos level tags todo-state
  4891. ee txt beg end inherited-tags)
  4892. (goto-char (point-min))
  4893. (while (re-search-forward regexp nil t)
  4894. (catch :skip
  4895. (save-match-data
  4896. (beginning-of-line)
  4897. (org-agenda-skip)
  4898. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4899. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4900. (goto-char (1+ beg))
  4901. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4902. (throw :skip nil)))
  4903. (goto-char (match-beginning 2))
  4904. (setq marker (org-agenda-new-marker (match-beginning 0))
  4905. category (org-get-category)
  4906. category-pos (get-text-property (point) 'org-category-position)
  4907. txt (org-trim
  4908. (buffer-substring (match-beginning 2) (match-end 0)))
  4909. inherited-tags
  4910. (or (eq org-agenda-show-inherited-tags 'always)
  4911. (and (listp org-agenda-show-inherited-tags)
  4912. (memq 'todo org-agenda-show-inherited-tags))
  4913. (and (eq org-agenda-show-inherited-tags t)
  4914. (or (eq org-agenda-use-tag-inheritance t)
  4915. (memq 'todo org-agenda-use-tag-inheritance))))
  4916. tags (org-get-tags-at nil (not inherited-tags))
  4917. level (make-string (org-reduced-level (org-outline-level)) ? )
  4918. txt (org-agenda-format-item "" txt level category tags t)
  4919. priority (1+ (org-get-priority txt))
  4920. todo-state (org-get-todo-state))
  4921. (org-add-props txt props
  4922. 'org-marker marker 'org-hd-marker marker
  4923. 'priority priority 'org-category category
  4924. 'level level
  4925. 'org-category-position category-pos
  4926. 'type "todo" 'todo-state todo-state)
  4927. (push txt ee)
  4928. (if org-agenda-todo-list-sublevels
  4929. (goto-char (match-end 2))
  4930. (org-end-of-subtree 'invisible))))
  4931. (nreverse ee)))
  4932. (defun org-agenda-todo-custom-ignore-p (time n)
  4933. "Check whether timestamp is farther away than n number of days.
  4934. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4935. `org-agenda-todo-ignore-scheduled' or
  4936. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4937. (let ((days (org-time-stamp-to-now
  4938. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4939. (if (>= n 0)
  4940. (>= days n)
  4941. (<= days n))))
  4942. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4943. (&optional end)
  4944. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4945. (when (or org-agenda-todo-ignore-with-date
  4946. org-agenda-todo-ignore-scheduled
  4947. org-agenda-todo-ignore-deadlines
  4948. org-agenda-todo-ignore-timestamp)
  4949. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4950. (save-excursion
  4951. (or (and org-agenda-todo-ignore-with-date
  4952. (re-search-forward org-ts-regexp end t))
  4953. (and org-agenda-todo-ignore-scheduled
  4954. (re-search-forward org-scheduled-time-regexp end t)
  4955. (cond
  4956. ((eq org-agenda-todo-ignore-scheduled 'future)
  4957. (> (org-time-stamp-to-now
  4958. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4959. ((eq org-agenda-todo-ignore-scheduled 'past)
  4960. (<= (org-time-stamp-to-now
  4961. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4962. ((numberp org-agenda-todo-ignore-scheduled)
  4963. (org-agenda-todo-custom-ignore-p
  4964. (match-string 1) org-agenda-todo-ignore-scheduled))
  4965. (t)))
  4966. (and org-agenda-todo-ignore-deadlines
  4967. (re-search-forward org-deadline-time-regexp end t)
  4968. (cond
  4969. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4970. ((eq org-agenda-todo-ignore-deadlines 'far)
  4971. (not (org-deadline-close (match-string 1))))
  4972. ((eq org-agenda-todo-ignore-deadlines 'future)
  4973. (> (org-time-stamp-to-now
  4974. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4975. ((eq org-agenda-todo-ignore-deadlines 'past)
  4976. (<= (org-time-stamp-to-now
  4977. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4978. ((numberp org-agenda-todo-ignore-deadlines)
  4979. (org-agenda-todo-custom-ignore-p
  4980. (match-string 1) org-agenda-todo-ignore-deadlines))
  4981. (t (org-deadline-close (match-string 1)))))
  4982. (and org-agenda-todo-ignore-timestamp
  4983. (let ((buffer (current-buffer))
  4984. (regexp
  4985. (concat
  4986. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4987. (start (point)))
  4988. ;; Copy current buffer into a temporary one
  4989. (with-temp-buffer
  4990. (insert-buffer-substring buffer start end)
  4991. (goto-char (point-min))
  4992. ;; Delete SCHEDULED and DEADLINE items
  4993. (while (re-search-forward regexp end t)
  4994. (delete-region (match-beginning 0) (match-end 0)))
  4995. (goto-char (point-min))
  4996. ;; No search for timestamp left
  4997. (when (re-search-forward org-ts-regexp nil t)
  4998. (cond
  4999. ((eq org-agenda-todo-ignore-timestamp 'future)
  5000. (> (org-time-stamp-to-now
  5001. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5002. ((eq org-agenda-todo-ignore-timestamp 'past)
  5003. (<= (org-time-stamp-to-now
  5004. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5005. ((numberp org-agenda-todo-ignore-timestamp)
  5006. (org-agenda-todo-custom-ignore-p
  5007. (match-string 1) org-agenda-todo-ignore-timestamp))
  5008. (t))))))))))
  5009. (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
  5010. Do we have a reason to ignore this TODO entry because it has a time stamp?
  5011. \(fn &optional END)" nil nil)
  5012. (defun org-agenda-get-timestamps (&optional deadline-results)
  5013. "Return the date stamp information for agenda display."
  5014. (let* ((props (list 'face 'org-agenda-calendar-event
  5015. 'org-not-done-regexp org-not-done-regexp
  5016. 'org-todo-regexp org-todo-regexp
  5017. 'org-complex-heading-regexp org-complex-heading-regexp
  5018. 'mouse-face 'highlight
  5019. 'help-echo
  5020. (format "mouse-2 or RET jump to org file %s"
  5021. (abbreviate-file-name buffer-file-name))))
  5022. (d1 (calendar-absolute-from-gregorian date))
  5023. mm
  5024. (deadline-position-alist
  5025. (mapcar (lambda (a) (and (setq mm (get-text-property
  5026. 0 'org-hd-marker a))
  5027. (cons (marker-position mm) a)))
  5028. deadline-results))
  5029. (remove-re org-ts-regexp)
  5030. (regexp
  5031. (concat
  5032. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5033. (regexp-quote
  5034. (substring
  5035. (format-time-string
  5036. (car org-time-stamp-formats)
  5037. (apply 'encode-time ; DATE bound by calendar
  5038. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5039. 1 11))
  5040. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5041. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5042. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5043. donep tmp priority category category-pos level ee txt timestr tags
  5044. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5045. inherited-tags)
  5046. (goto-char (point-min))
  5047. (while (setq end-of-match (re-search-forward regexp nil t))
  5048. (setq b0 (match-beginning 0)
  5049. b3 (match-beginning 3) e3 (match-end 3)
  5050. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5051. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5052. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5053. (member todo-state
  5054. org-agenda-repeating-timestamp-show-all)))
  5055. (catch :skip
  5056. (and (org-at-date-range-p) (throw :skip nil))
  5057. (org-agenda-skip)
  5058. (if (and (match-end 1)
  5059. (not (= d1 (org-time-string-to-absolute
  5060. (match-string 1) d1 nil show-all
  5061. (current-buffer) b0))))
  5062. (throw :skip nil))
  5063. (if (and e3
  5064. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5065. (throw :skip nil))
  5066. (setq tmp (buffer-substring (max (point-min)
  5067. (- b0 org-ds-keyword-length))
  5068. b0)
  5069. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5070. inactivep (= (char-after b0) ?\[)
  5071. deadlinep (string-match org-deadline-regexp tmp)
  5072. scheduledp (string-match org-scheduled-regexp tmp)
  5073. closedp (and org-agenda-include-inactive-timestamps
  5074. (string-match org-closed-string tmp))
  5075. clockp (and org-agenda-include-inactive-timestamps
  5076. (or (string-match org-clock-string tmp)
  5077. (string-match "]-+\\'" tmp)))
  5078. warntime (get-text-property (point) 'org-appt-warntime)
  5079. donep (member todo-state org-done-keywords))
  5080. (if (or scheduledp deadlinep closedp clockp
  5081. (and donep org-agenda-skip-timestamp-if-done))
  5082. (throw :skip t))
  5083. (if (string-match ">" timestr)
  5084. ;; substring should only run to end of time stamp
  5085. (setq timestr (substring timestr 0 (match-end 0))))
  5086. (setq marker (org-agenda-new-marker b0)
  5087. category (org-get-category b0)
  5088. category-pos (get-text-property b0 'org-category-position))
  5089. (save-excursion
  5090. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5091. (throw :skip nil)
  5092. (goto-char (match-beginning 0))
  5093. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5094. (assoc (point) deadline-position-alist))
  5095. (throw :skip nil))
  5096. (setq hdmarker (org-agenda-new-marker)
  5097. inherited-tags
  5098. (or (eq org-agenda-show-inherited-tags 'always)
  5099. (and (listp org-agenda-show-inherited-tags)
  5100. (memq 'agenda org-agenda-show-inherited-tags))
  5101. (and (eq org-agenda-show-inherited-tags t)
  5102. (or (eq org-agenda-use-tag-inheritance t)
  5103. (memq 'agenda org-agenda-use-tag-inheritance))))
  5104. tags (org-get-tags-at nil (not inherited-tags))
  5105. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5106. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5107. (setq head (or (match-string 1) ""))
  5108. (setq txt (org-agenda-format-item
  5109. (if inactivep org-agenda-inactive-leader nil)
  5110. head level category tags timestr
  5111. remove-re habitp)))
  5112. (setq priority (org-get-priority txt))
  5113. (org-add-props txt props 'priority priority
  5114. 'org-marker marker 'org-hd-marker hdmarker
  5115. 'org-category category 'date date
  5116. 'level level
  5117. 'org-category-position category-pos
  5118. 'todo-state todo-state
  5119. 'warntime warntime
  5120. 'type "timestamp")
  5121. (push txt ee))
  5122. (if org-agenda-skip-additional-timestamps-same-entry
  5123. (outline-next-heading)
  5124. (goto-char end-of-match))))
  5125. (nreverse ee)))
  5126. (defun org-agenda-get-sexps ()
  5127. "Return the sexp information for agenda display."
  5128. (require 'diary-lib)
  5129. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5130. 'mouse-face 'highlight
  5131. 'help-echo
  5132. (format "mouse-2 or RET jump to org file %s"
  5133. (abbreviate-file-name buffer-file-name))))
  5134. (regexp "^&?%%(")
  5135. marker category extra category-pos level ee txt tags entry
  5136. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5137. (goto-char (point-min))
  5138. (while (re-search-forward regexp nil t)
  5139. (catch :skip
  5140. (org-agenda-skip)
  5141. (setq beg (match-beginning 0))
  5142. (goto-char (1- (match-end 0)))
  5143. (setq b (point))
  5144. (forward-sexp 1)
  5145. (setq sexp (buffer-substring b (point)))
  5146. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5147. (org-trim (match-string 1))
  5148. ""))
  5149. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5150. (when result
  5151. (setq marker (org-agenda-new-marker beg)
  5152. level (make-string (org-reduced-level (org-outline-level)) ? )
  5153. category (org-get-category beg)
  5154. category-pos (get-text-property beg 'org-category-position)
  5155. inherited-tags
  5156. (or (eq org-agenda-show-inherited-tags 'always)
  5157. (and (listp org-agenda-show-inherited-tags)
  5158. (memq 'agenda org-agenda-show-inherited-tags))
  5159. (and (eq org-agenda-show-inherited-tags t)
  5160. (or (eq org-agenda-use-tag-inheritance t)
  5161. (memq 'agenda org-agenda-use-tag-inheritance))))
  5162. tags (org-get-tags-at nil (not inherited-tags))
  5163. todo-state (org-get-todo-state)
  5164. warntime (get-text-property (point) 'org-appt-warntime)
  5165. extra nil)
  5166. (dolist (r (if (stringp result)
  5167. (list result)
  5168. result)) ;; we expect a list here
  5169. (when (and org-agenda-diary-sexp-prefix
  5170. (string-match org-agenda-diary-sexp-prefix r))
  5171. (setq extra (match-string 0 r)
  5172. r (replace-match "" nil nil r)))
  5173. (if (string-match "\\S-" r)
  5174. (setq txt r)
  5175. (setq txt "SEXP entry returned empty string"))
  5176. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5177. (org-add-props txt props 'org-marker marker
  5178. 'org-category category 'date date 'todo-state todo-state
  5179. 'org-category-position category-pos 'tags tags
  5180. 'level level
  5181. 'type "sexp" 'warntime warntime)
  5182. (push txt ee)))))
  5183. (nreverse ee)))
  5184. ;; Calendar sanity: define some functions that are independent of
  5185. ;; `calendar-date-style'.
  5186. ;; Normally I would like to use ISO format when calling the diary functions,
  5187. ;; but to make sure we still have Emacs 22 compatibility we bind
  5188. ;; also `european-calendar-style' and use european format
  5189. (defun org-anniversary (year month day &optional mark)
  5190. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5191. (org-no-warnings
  5192. (let ((calendar-date-style 'european) (european-calendar-style t))
  5193. (diary-anniversary day month year mark))))
  5194. (defun org-cyclic (N year month day &optional mark)
  5195. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5196. (org-no-warnings
  5197. (let ((calendar-date-style 'european) (european-calendar-style t))
  5198. (diary-cyclic N day month year mark))))
  5199. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5200. "Like `diary-block', but with fixed (ISO) order of arguments."
  5201. (org-no-warnings
  5202. (let ((calendar-date-style 'european) (european-calendar-style t))
  5203. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5204. (defun org-date (year month day &optional mark)
  5205. "Like `diary-date', but with fixed (ISO) order of arguments."
  5206. (org-no-warnings
  5207. (let ((calendar-date-style 'european) (european-calendar-style t))
  5208. (diary-date day month year mark))))
  5209. ;; Define the` org-class' function
  5210. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5211. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5212. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5213. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5214. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5215. `holidays', then any date that is known by the Emacs calendar to be a
  5216. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5217. then those holidays will be skipped."
  5218. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5219. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5220. (d (calendar-absolute-from-gregorian date))
  5221. (h (when skip-weeks (calendar-check-holidays date))))
  5222. (and
  5223. (<= date1 d)
  5224. (<= d date2)
  5225. (= (calendar-day-of-week date) dayname)
  5226. (or (not skip-weeks)
  5227. (progn
  5228. (require 'cal-iso)
  5229. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5230. (not (or (and h (memq 'holidays skip-weeks))
  5231. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5232. entry)))
  5233. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5234. "Like `org-class', but honor `calendar-date-style'.
  5235. The order of the first 2 times 3 arguments depends on the variable
  5236. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5237. So for American calendars, give this as MONTH DAY YEAR, for European as
  5238. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5239. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5240. is any number of ISO weeks in the block period for which the item should
  5241. be skipped.
  5242. This function is here only for backward compatibility and it is deprecated,
  5243. please use `org-class' instead."
  5244. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5245. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5246. (org-class
  5247. (nth 2 date1) (car date1) (nth 1 date1)
  5248. (nth 2 date2) (car date2) (nth 1 date2)
  5249. dayname skip-weeks)))
  5250. (make-obsolete 'org-diary-class 'org-class "")
  5251. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5252. (defalias 'org-get-closed 'org-agenda-get-progress)
  5253. (defun org-agenda-get-progress ()
  5254. "Return the logged TODO entries for agenda display."
  5255. (let* ((props (list 'mouse-face 'highlight
  5256. 'org-not-done-regexp org-not-done-regexp
  5257. 'org-todo-regexp org-todo-regexp
  5258. 'org-complex-heading-regexp org-complex-heading-regexp
  5259. 'help-echo
  5260. (format "mouse-2 or RET jump to org file %s"
  5261. (abbreviate-file-name buffer-file-name))))
  5262. (items (if (consp org-agenda-show-log-scoped)
  5263. org-agenda-show-log-scoped
  5264. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5265. '(clock)
  5266. org-agenda-log-mode-items)))
  5267. (parts
  5268. (delq nil
  5269. (list
  5270. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5271. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5272. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5273. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5274. (error "`org-agenda-log-mode-items' is empty")))
  5275. (regexp (concat
  5276. "\\(" parts-re "\\)"
  5277. " *\\["
  5278. (regexp-quote
  5279. (substring
  5280. (format-time-string
  5281. (car org-time-stamp-formats)
  5282. (apply 'encode-time ; DATE bound by calendar
  5283. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5284. 1 11))))
  5285. (org-agenda-search-headline-for-time nil)
  5286. marker hdmarker priority category category-pos level tags closedp
  5287. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5288. (goto-char (point-min))
  5289. (while (re-search-forward regexp nil t)
  5290. (catch :skip
  5291. (org-agenda-skip)
  5292. (setq marker (org-agenda-new-marker (match-beginning 0))
  5293. closedp (equal (match-string 1) org-closed-string)
  5294. statep (equal (string-to-char (match-string 1)) ?-)
  5295. clockp (not (or closedp statep))
  5296. state (and statep (match-string 2))
  5297. category (org-get-category (match-beginning 0))
  5298. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5299. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5300. (when (string-match "\\]" timestr)
  5301. ;; substring should only run to end of time stamp
  5302. (setq rest (substring timestr (match-end 0))
  5303. timestr (substring timestr 0 (match-end 0)))
  5304. (if (and (not closedp) (not statep)
  5305. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5306. rest))
  5307. (progn (setq timestr (concat (substring timestr 0 -1)
  5308. "-" (match-string 1 rest) "]"))
  5309. (setq clocked (match-string 2 rest)))
  5310. (setq clocked "-")))
  5311. (save-excursion
  5312. (setq extra
  5313. (cond
  5314. ((not org-agenda-log-mode-add-notes) nil)
  5315. (statep
  5316. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5317. (match-string 1)))
  5318. (clockp
  5319. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5320. (match-string 1)))))
  5321. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5322. (throw :skip nil)
  5323. (goto-char (match-beginning 0))
  5324. (setq hdmarker (org-agenda-new-marker)
  5325. inherited-tags
  5326. (or (eq org-agenda-show-inherited-tags 'always)
  5327. (and (listp org-agenda-show-inherited-tags)
  5328. (memq 'todo org-agenda-show-inherited-tags))
  5329. (and (eq org-agenda-show-inherited-tags t)
  5330. (or (eq org-agenda-use-tag-inheritance t)
  5331. (memq 'todo org-agenda-use-tag-inheritance))))
  5332. tags (org-get-tags-at nil (not inherited-tags))
  5333. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5334. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5335. (setq txt (match-string 1))
  5336. (when extra
  5337. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5338. (setq txt (concat (substring txt 0 (match-beginning 1))
  5339. " - " extra " " (match-string 2 txt)))
  5340. (setq txt (concat txt " - " extra))))
  5341. (setq txt (org-agenda-format-item
  5342. (cond
  5343. (closedp "Closed: ")
  5344. (statep (concat "State: (" state ")"))
  5345. (t (concat "Clocked: (" clocked ")")))
  5346. txt level category tags timestr)))
  5347. (setq priority 100000)
  5348. (org-add-props txt props
  5349. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5350. 'priority priority 'org-category category
  5351. 'org-category-position category-pos
  5352. 'level level
  5353. 'type "closed" 'date date
  5354. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5355. (push txt ee))
  5356. (goto-char (point-at-eol))))
  5357. (nreverse ee)))
  5358. (defun org-agenda-show-clocking-issues ()
  5359. "Add overlays, showing issues with clocking.
  5360. See also the user option `org-agenda-clock-consistency-checks'."
  5361. (interactive)
  5362. (let* ((org-time-clocksum-use-effort-durations nil)
  5363. (pl org-agenda-clock-consistency-checks)
  5364. (re (concat "^[ \t]*"
  5365. org-clock-string
  5366. "[ \t]+"
  5367. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5368. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5369. (tlstart 0.)
  5370. (tlend 0.)
  5371. (maxtime (org-hh:mm-string-to-minutes
  5372. (or (plist-get pl :max-duration) "24:00")))
  5373. (mintime (org-hh:mm-string-to-minutes
  5374. (or (plist-get pl :min-duration) 0)))
  5375. (maxgap (org-hh:mm-string-to-minutes
  5376. ;; default 30:00 means never complain
  5377. (or (plist-get pl :max-gap) "30:00")))
  5378. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5379. (plist-get pl :gap-ok-around)))
  5380. (def-face (or (plist-get pl :default-face)
  5381. '((:background "DarkRed") (:foreground "white"))))
  5382. issue face m te ts dt ov)
  5383. (goto-char (point-min))
  5384. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5385. (setq issue nil face def-face)
  5386. (catch 'next
  5387. (setq m (org-get-at-bol 'org-marker)
  5388. te nil ts nil)
  5389. (unless (and m (markerp m))
  5390. (setq issue "No valid clock line") (throw 'next t))
  5391. (org-with-point-at m
  5392. (save-excursion
  5393. (goto-char (point-at-bol))
  5394. (unless (looking-at re)
  5395. (error "No valid Clock line")
  5396. (throw 'next t))
  5397. (unless (match-end 3)
  5398. (setq issue "No end time"
  5399. face (or (plist-get pl :no-end-time-face) face))
  5400. (throw 'next t))
  5401. (setq ts (match-string 1)
  5402. te (match-string 3)
  5403. ts (org-float-time
  5404. (apply 'encode-time (org-parse-time-string ts)))
  5405. te (org-float-time
  5406. (apply 'encode-time (org-parse-time-string te)))
  5407. dt (- te ts))))
  5408. (cond
  5409. ((> dt (* 60 maxtime))
  5410. ;; a very long clocking chunk
  5411. (setq issue (format "Clocking interval is very long: %s"
  5412. (org-minutes-to-clocksum-string
  5413. (floor (/ (float dt) 60.))))
  5414. face (or (plist-get pl :long-face) face)))
  5415. ((< dt (* 60 mintime))
  5416. ;; a very short clocking chunk
  5417. (setq issue (format "Clocking interval is very short: %s"
  5418. (org-minutes-to-clocksum-string
  5419. (floor (/ (float dt) 60.))))
  5420. face (or (plist-get pl :short-face) face)))
  5421. ((and (> tlend 0) (< ts tlend))
  5422. ;; Two clock entries are overlapping
  5423. (setq issue (format "Clocking overlap: %d minutes"
  5424. (/ (- tlend ts) 60))
  5425. face (or (plist-get pl :overlap-face) face)))
  5426. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5427. ;; There is a gap, lets see if we need to report it
  5428. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5429. (setq issue (format "Clocking gap: %d minutes"
  5430. (/ (- ts tlend) 60))
  5431. face (or (plist-get pl :gap-face) face))))
  5432. (t nil)))
  5433. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5434. (when issue
  5435. ;; OK, there was some issue, add an overlay to show the issue
  5436. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5437. (overlay-put ov 'before-string
  5438. (concat
  5439. (org-add-props
  5440. (format "%-43s" (concat " " issue))
  5441. nil
  5442. 'face face)
  5443. "\n"))
  5444. (overlay-put ov 'evaporate t)))))
  5445. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5446. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5447. (catch 'exit
  5448. (unless ok-list
  5449. ;; there are no OK times for gaps...
  5450. (throw 'exit nil))
  5451. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5452. ;; This is more than 24 hours, so it is OK.
  5453. ;; because we have at least one OK time, that must be in the
  5454. ;; 24 hour interval.
  5455. (throw 'exit t))
  5456. ;; We have a shorter gap.
  5457. ;; Now we have to get the minute of the day when these times are
  5458. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5459. (t2dec (decode-time (seconds-to-time t2)))
  5460. ;; compute the minute on the day
  5461. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5462. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5463. (when (< min2 min1)
  5464. ;; if min2 is smaller than min1, this means it is on the next day.
  5465. ;; Wrap it to after midnight.
  5466. (setq min2 (+ min2 1440)))
  5467. ;; Now check if any of the OK times is in the gap
  5468. (mapc (lambda (x)
  5469. ;; Wrap the time to after midnight if necessary
  5470. (if (< x min1) (setq x (+ x 1440)))
  5471. ;; Check if in interval
  5472. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5473. ok-list)
  5474. ;; Nope, this gap is not OK
  5475. nil)))
  5476. (defun org-agenda-get-deadlines ()
  5477. "Return the deadline information for agenda display."
  5478. (let* ((props (list 'mouse-face 'highlight
  5479. 'org-not-done-regexp org-not-done-regexp
  5480. 'org-todo-regexp org-todo-regexp
  5481. 'org-complex-heading-regexp org-complex-heading-regexp
  5482. 'help-echo
  5483. (format "mouse-2 or RET jump to org file %s"
  5484. (abbreviate-file-name buffer-file-name))))
  5485. (regexp org-deadline-time-regexp)
  5486. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5487. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5488. d2 diff dfrac wdays pos pos1 category category-pos level
  5489. tags suppress-prewarning ee txt head face s todo-state
  5490. show-all upcomingp donep timestr warntime inherited-tags)
  5491. (goto-char (point-min))
  5492. (while (re-search-forward regexp nil t)
  5493. (catch :skip
  5494. (org-agenda-skip)
  5495. (setq s (match-string 1)
  5496. txt nil
  5497. pos (1- (match-beginning 1))
  5498. todo-state (save-match-data (org-get-todo-state))
  5499. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5500. (member todo-state
  5501. org-agenda-repeating-timestamp-show-all))
  5502. d2 (org-time-string-to-absolute
  5503. (match-string 1) d1 'past show-all
  5504. (current-buffer) pos)
  5505. diff (- d2 d1))
  5506. (setq suppress-prewarning
  5507. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5508. (let ((item (buffer-substring (point-at-bol)
  5509. (point-at-eol))))
  5510. (save-match-data
  5511. (and (string-match
  5512. org-scheduled-time-regexp item)
  5513. (match-string 1 item)))))))
  5514. (cond
  5515. ((not ds) nil)
  5516. ;; The current item has a scheduled date (in ds), so
  5517. ;; evaluate its prewarning lead time.
  5518. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5519. ;; Use global prewarning-restart lead time.
  5520. org-agenda-skip-deadline-prewarning-if-scheduled)
  5521. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5522. 'pre-scheduled)
  5523. ;; Set prewarning to no earlier than scheduled.
  5524. (min (- d2 (org-time-string-to-absolute
  5525. ds d1 'past show-all (current-buffer) pos))
  5526. org-deadline-warning-days))
  5527. ;; Set prewarning to deadline.
  5528. (t 0))))
  5529. (setq wdays (if suppress-prewarning
  5530. (let ((org-deadline-warning-days suppress-prewarning))
  5531. (org-get-wdays s))
  5532. (org-get-wdays s))
  5533. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5534. upcomingp (and todayp (> diff 0)))
  5535. ;; When to show a deadline in the calendar:
  5536. ;; If the expiration is within wdays warning time.
  5537. ;; Past-due deadlines are only shown on the current date
  5538. (if (and (or (and (<= diff wdays)
  5539. (and todayp (not org-agenda-only-exact-dates)))
  5540. (= diff 0)))
  5541. (save-excursion
  5542. ;; (setq todo-state (org-get-todo-state))
  5543. (setq donep (member todo-state org-done-keywords))
  5544. (if (and donep
  5545. (or org-agenda-skip-deadline-if-done
  5546. (not (= diff 0))))
  5547. (setq txt nil)
  5548. (setq category (org-get-category)
  5549. warntime (get-text-property (point) 'org-appt-warntime)
  5550. category-pos (get-text-property (point) 'org-category-position))
  5551. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5552. (throw :skip nil)
  5553. (goto-char (match-end 0))
  5554. (setq pos1 (match-beginning 0))
  5555. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5556. (setq inherited-tags
  5557. (or (eq org-agenda-show-inherited-tags 'always)
  5558. (and (listp org-agenda-show-inherited-tags)
  5559. (memq 'agenda org-agenda-show-inherited-tags))
  5560. (and (eq org-agenda-show-inherited-tags t)
  5561. (or (eq org-agenda-use-tag-inheritance t)
  5562. (memq 'agenda org-agenda-use-tag-inheritance))))
  5563. tags (org-get-tags-at pos1 (not inherited-tags)))
  5564. (setq head (buffer-substring-no-properties
  5565. (point)
  5566. (progn (skip-chars-forward "^\r\n")
  5567. (point))))
  5568. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5569. (setq timestr
  5570. (concat (substring s (match-beginning 1)) " "))
  5571. (setq timestr 'time))
  5572. (setq txt (org-agenda-format-item
  5573. (if (= diff 0)
  5574. (car org-agenda-deadline-leaders)
  5575. (if (functionp
  5576. (nth 1 org-agenda-deadline-leaders))
  5577. (funcall
  5578. (nth 1 org-agenda-deadline-leaders)
  5579. diff date)
  5580. (format (nth 1 org-agenda-deadline-leaders)
  5581. diff)))
  5582. head level category tags
  5583. (if (not (= diff 0)) nil timestr)))))
  5584. (when txt
  5585. (setq face (org-agenda-deadline-face dfrac))
  5586. (org-add-props txt props
  5587. 'org-marker (org-agenda-new-marker pos)
  5588. 'warntime warntime
  5589. 'level level
  5590. 'org-hd-marker (org-agenda-new-marker pos1)
  5591. 'priority (+ (- diff)
  5592. (org-get-priority txt))
  5593. 'org-category category
  5594. 'org-category-position category-pos
  5595. 'todo-state todo-state
  5596. 'type (if upcomingp "upcoming-deadline" "deadline")
  5597. 'date (if upcomingp date d2)
  5598. 'face (if donep 'org-agenda-done face)
  5599. 'undone-face face 'done-face 'org-agenda-done)
  5600. (push txt ee))))))
  5601. (nreverse ee)))
  5602. (defun org-agenda-deadline-face (fraction)
  5603. "Return the face to displaying a deadline item.
  5604. FRACTION is what fraction of the head-warning time has passed."
  5605. (let ((faces org-agenda-deadline-faces) f)
  5606. (catch 'exit
  5607. (while (setq f (pop faces))
  5608. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5609. (defun org-agenda-get-scheduled (&optional deadline-results)
  5610. "Return the scheduled information for agenda display."
  5611. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5612. 'org-todo-regexp org-todo-regexp
  5613. 'org-complex-heading-regexp org-complex-heading-regexp
  5614. 'done-face 'org-agenda-done
  5615. 'mouse-face 'highlight
  5616. 'help-echo
  5617. (format "mouse-2 or RET jump to org file %s"
  5618. (abbreviate-file-name buffer-file-name))))
  5619. (regexp org-scheduled-time-regexp)
  5620. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5621. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5622. mm
  5623. (deadline-position-alist
  5624. (mapcar (lambda (a) (and (setq mm (get-text-property
  5625. 0 'org-hd-marker a))
  5626. (cons (marker-position mm) a)))
  5627. deadline-results))
  5628. d2 diff pos pos1 category category-pos level tags donep
  5629. ee txt head pastschedp todo-state face timestr s habitp show-all
  5630. did-habit-check-p warntime inherited-tags)
  5631. (goto-char (point-min))
  5632. (while (re-search-forward regexp nil t)
  5633. (catch :skip
  5634. (org-agenda-skip)
  5635. (setq s (match-string 1)
  5636. txt nil
  5637. pos (1- (match-beginning 1))
  5638. todo-state (save-match-data (org-get-todo-state))
  5639. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5640. (member todo-state
  5641. org-agenda-repeating-timestamp-show-all))
  5642. d2 (org-time-string-to-absolute
  5643. (match-string 1) d1 'past show-all
  5644. (current-buffer) pos)
  5645. diff (- d2 d1)
  5646. warntime (get-text-property (point) 'org-appt-warntime))
  5647. (setq pastschedp (and todayp (< diff 0)))
  5648. (setq did-habit-check-p nil)
  5649. ;; When to show a scheduled item in the calendar:
  5650. ;; If it is on or past the date.
  5651. (when (or (and (< diff 0)
  5652. (< (abs diff) org-scheduled-past-days)
  5653. (and todayp (not org-agenda-only-exact-dates)))
  5654. (= diff 0)
  5655. ;; org-is-habit-p uses org-entry-get, which is expansive
  5656. ;; so we go extra mile to only call it once
  5657. (and todayp
  5658. (boundp 'org-habit-show-all-today)
  5659. org-habit-show-all-today
  5660. (setq did-habit-check-p t)
  5661. (setq habitp (and (functionp 'org-is-habit-p)
  5662. (org-is-habit-p)))))
  5663. (save-excursion
  5664. (setq donep (member todo-state org-done-keywords))
  5665. (if (and donep
  5666. (or org-agenda-skip-scheduled-if-done
  5667. (not (= diff 0))
  5668. (and (functionp 'org-is-habit-p)
  5669. (org-is-habit-p))))
  5670. (setq txt nil)
  5671. (setq habitp (if did-habit-check-p habitp
  5672. (and (functionp 'org-is-habit-p)
  5673. (org-is-habit-p))))
  5674. (setq category (org-get-category)
  5675. category-pos (get-text-property (point) 'org-category-position))
  5676. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5677. (throw :skip nil)
  5678. (goto-char (match-end 0))
  5679. (setq pos1 (match-beginning 0))
  5680. (if habitp
  5681. (if (or (not org-habit-show-habits)
  5682. (and (not todayp)
  5683. (boundp 'org-habit-show-habits-only-for-today)
  5684. org-habit-show-habits-only-for-today))
  5685. (throw :skip nil))
  5686. (if (and
  5687. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5688. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5689. pastschedp))
  5690. (setq mm (assoc pos1 deadline-position-alist)))
  5691. (throw :skip nil)))
  5692. (setq inherited-tags
  5693. (or (eq org-agenda-show-inherited-tags 'always)
  5694. (and (listp org-agenda-show-inherited-tags)
  5695. (memq 'agenda org-agenda-show-inherited-tags))
  5696. (and (eq org-agenda-show-inherited-tags t)
  5697. (or (eq org-agenda-use-tag-inheritance t)
  5698. (memq 'agenda org-agenda-use-tag-inheritance))))
  5699. tags (org-get-tags-at nil (not inherited-tags)))
  5700. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5701. (setq head (buffer-substring-no-properties
  5702. (point)
  5703. (progn (skip-chars-forward "^\r\n") (point))))
  5704. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5705. (setq timestr
  5706. (concat (substring s (match-beginning 1)) " "))
  5707. (setq timestr 'time))
  5708. (setq txt (org-agenda-format-item
  5709. (if (= diff 0)
  5710. (car org-agenda-scheduled-leaders)
  5711. (format (nth 1 org-agenda-scheduled-leaders)
  5712. (- 1 diff)))
  5713. head level category tags
  5714. (if (not (= diff 0)) nil timestr)
  5715. nil habitp))))
  5716. (when txt
  5717. (setq face
  5718. (cond
  5719. ((and (not habitp) pastschedp)
  5720. 'org-scheduled-previously)
  5721. (todayp 'org-scheduled-today)
  5722. (t 'org-scheduled))
  5723. habitp (and habitp (org-habit-parse-todo)))
  5724. (org-add-props txt props
  5725. 'undone-face face
  5726. 'face (if donep 'org-agenda-done face)
  5727. 'org-marker (org-agenda-new-marker pos)
  5728. 'org-hd-marker (org-agenda-new-marker pos1)
  5729. 'type (if pastschedp "past-scheduled" "scheduled")
  5730. 'date (if pastschedp d2 date)
  5731. 'warntime warntime
  5732. 'level level
  5733. 'priority (if habitp
  5734. (org-habit-get-priority habitp)
  5735. (+ 94 (- 5 diff) (org-get-priority txt)))
  5736. 'org-category category
  5737. 'category-position category-pos
  5738. 'org-habit-p habitp
  5739. 'todo-state todo-state)
  5740. (push txt ee))))))
  5741. (nreverse ee)))
  5742. (defun org-agenda-get-blocks ()
  5743. "Return the date-range information for agenda display."
  5744. (let* ((props (list 'face nil
  5745. 'org-not-done-regexp org-not-done-regexp
  5746. 'org-todo-regexp org-todo-regexp
  5747. 'org-complex-heading-regexp org-complex-heading-regexp
  5748. 'mouse-face 'highlight
  5749. 'help-echo
  5750. (format "mouse-2 or RET jump to org file %s"
  5751. (abbreviate-file-name buffer-file-name))))
  5752. (regexp org-tr-regexp)
  5753. (d0 (calendar-absolute-from-gregorian date))
  5754. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5755. level todo-state tags pos head donep inherited-tags)
  5756. (goto-char (point-min))
  5757. (while (re-search-forward regexp nil t)
  5758. (catch :skip
  5759. (org-agenda-skip)
  5760. (setq pos (point))
  5761. (let ((start-time (match-string 1))
  5762. (end-time (match-string 2)))
  5763. (setq s1 (match-string 1)
  5764. s2 (match-string 2)
  5765. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5766. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5767. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5768. ;; Only allow days between the limits, because the normal
  5769. ;; date stamps will catch the limits.
  5770. (save-excursion
  5771. (setq todo-state (org-get-todo-state))
  5772. (setq donep (member todo-state org-done-keywords))
  5773. (if (and donep org-agenda-skip-timestamp-if-done)
  5774. (throw :skip t))
  5775. (setq marker (org-agenda-new-marker (point)))
  5776. (setq category (org-get-category)
  5777. category-pos (get-text-property (point) 'org-category-position))
  5778. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5779. (throw :skip nil)
  5780. (goto-char (match-beginning 0))
  5781. (setq hdmarker (org-agenda-new-marker (point))
  5782. inherited-tags
  5783. (or (eq org-agenda-show-inherited-tags 'always)
  5784. (and (listp org-agenda-show-inherited-tags)
  5785. (memq 'agenda org-agenda-show-inherited-tags))
  5786. (and (eq org-agenda-show-inherited-tags t)
  5787. (or (eq org-agenda-use-tag-inheritance t)
  5788. (memq 'agenda org-agenda-use-tag-inheritance))))
  5789. tags (org-get-tags-at nil (not inherited-tags)))
  5790. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5791. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5792. (setq head (match-string 1))
  5793. (let ((remove-re
  5794. (if org-agenda-remove-timeranges-from-blocks
  5795. (concat
  5796. "<" (regexp-quote s1) ".*?>"
  5797. "--"
  5798. "<" (regexp-quote s2) ".*?>")
  5799. nil)))
  5800. (setq txt (org-agenda-format-item
  5801. (format
  5802. (nth (if (= d1 d2) 0 1)
  5803. org-agenda-timerange-leaders)
  5804. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5805. head level category tags
  5806. (cond ((and (= d1 d0) (= d2 d0))
  5807. (concat "<" start-time ">--<" end-time ">"))
  5808. ((= d1 d0)
  5809. (concat "<" start-time ">"))
  5810. ((= d2 d0)
  5811. (concat "<" end-time ">")))
  5812. remove-re))))
  5813. (org-add-props txt props
  5814. 'org-marker marker 'org-hd-marker hdmarker
  5815. 'type "block" 'date date
  5816. 'level level
  5817. 'todo-state todo-state
  5818. 'priority (org-get-priority txt) 'org-category category
  5819. 'org-category-position category-pos)
  5820. (push txt ee))))
  5821. (goto-char pos)))
  5822. ;; Sort the entries by expiration date.
  5823. (nreverse ee)))
  5824. ;;; Agenda presentation and sorting
  5825. (defvar org-prefix-has-time nil
  5826. "A flag, set by `org-compile-prefix-format'.
  5827. The flag is set if the currently compiled format contains a `%t'.")
  5828. (defvar org-prefix-has-tag nil
  5829. "A flag, set by `org-compile-prefix-format'.
  5830. The flag is set if the currently compiled format contains a `%T'.")
  5831. (defvar org-prefix-has-effort nil
  5832. "A flag, set by `org-compile-prefix-format'.
  5833. The flag is set if the currently compiled format contains a `%e'.")
  5834. (defvar org-prefix-category-length nil
  5835. "Used by `org-compile-prefix-format' to remember the category field width.")
  5836. (defvar org-prefix-category-max-length nil
  5837. "Used by `org-compile-prefix-format' to remember the category field width.")
  5838. (defun org-agenda-get-category-icon (category)
  5839. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5840. (dolist (entry org-agenda-category-icon-alist)
  5841. (when (org-string-match-p (car entry) category)
  5842. (if (listp (cadr entry))
  5843. (return (cadr entry))
  5844. (return (apply 'create-image (cdr entry)))))))
  5845. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5846. remove-re habitp)
  5847. "Format TXT to be inserted into the agenda buffer.
  5848. In particular, add the prefix and corresponding text properties.
  5849. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5850. LEVEL may be a string to replace the `%l' specifier.
  5851. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5852. category taken from local variable or file name. It will replace the `%c'
  5853. specifier in the format.
  5854. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5855. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5856. When DOTIME is a string, this string is searched for a time before TXT is.
  5857. TAGS can be the tags of the headline.
  5858. Any match of REMOVE-RE will be removed from TXT."
  5859. ;; We keep the org-prefix-* variable values along with a compiled
  5860. ;; formatter, so that multiple agendas existing at the same time do
  5861. ;; not step on each other toes.
  5862. ;;
  5863. ;; It was inconvenient to make these variables buffer local in
  5864. ;; Agenda buffers, because this function expects to be called with
  5865. ;; the buffer where item comes from being current, and not agenda
  5866. ;; buffer
  5867. (let* ((bindings (car org-prefix-format-compiled))
  5868. (formatter (cadr org-prefix-format-compiled)))
  5869. (loop for (var value) in bindings
  5870. do (set var value))
  5871. (save-match-data
  5872. ;; Diary entries sometimes have extra whitespace at the beginning
  5873. (setq txt (org-trim txt))
  5874. ;; Fix the tags part in txt
  5875. (setq txt (org-agenda-fix-displayed-tags
  5876. txt tags
  5877. org-agenda-show-inherited-tags
  5878. org-agenda-hide-tags-regexp))
  5879. (let* ((category (or category
  5880. (if (stringp org-category)
  5881. org-category
  5882. (and org-category (symbol-name org-category)))
  5883. (if buffer-file-name
  5884. (file-name-sans-extension
  5885. (file-name-nondirectory buffer-file-name))
  5886. "")))
  5887. (category-icon (org-agenda-get-category-icon category))
  5888. (category-icon (if category-icon
  5889. (propertize " " 'display category-icon)
  5890. ""))
  5891. ;; time, tag, effort are needed for the eval of the prefix format
  5892. (tag (if tags (nth (1- (length tags)) tags) ""))
  5893. time effort neffort
  5894. (ts (if dotime (concat
  5895. (if (stringp dotime) dotime "")
  5896. (and org-agenda-search-headline-for-time txt))))
  5897. (time-of-day (and dotime (org-get-time-of-day ts)))
  5898. stamp plain s0 s1 s2 rtn srp l
  5899. duration thecategory)
  5900. (and (derived-mode-p 'org-mode) buffer-file-name
  5901. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5902. (when (and dotime time-of-day)
  5903. ;; Extract starting and ending time and move them to prefix
  5904. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5905. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5906. (setq s0 (match-string 0 ts)
  5907. srp (and stamp (match-end 3))
  5908. s1 (match-string (if plain 1 2) ts)
  5909. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5910. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5911. ;; them, we might want to remove them there to avoid duplication.
  5912. ;; The user can turn this off with a variable.
  5913. (if (and org-prefix-has-time
  5914. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5915. (string-match (concat (regexp-quote s0) " *") txt)
  5916. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5917. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5918. (= (match-beginning 0) 0)
  5919. t))
  5920. (setq txt (replace-match "" nil nil txt))))
  5921. ;; Normalize the time(s) to 24 hour
  5922. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5923. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5924. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5925. (let (org-time-clocksum-use-effort-durations)
  5926. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5927. (setq s2
  5928. (org-minutes-to-clocksum-string
  5929. (+ (org-hh:mm-string-to-minutes s1)
  5930. org-agenda-default-appointment-duration)))))
  5931. ;; Compute the duration
  5932. (when s2
  5933. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5934. (org-hh:mm-string-to-minutes s1)))))
  5935. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5936. txt)
  5937. ;; Tags are in the string
  5938. (if (or (eq org-agenda-remove-tags t)
  5939. (and org-agenda-remove-tags
  5940. org-prefix-has-tag))
  5941. (setq txt (replace-match "" t t txt))
  5942. (setq txt (replace-match
  5943. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5944. (match-string 2 txt))
  5945. t t txt))))
  5946. (when (derived-mode-p 'org-mode)
  5947. (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
  5948. (when effort
  5949. (setq neffort (org-duration-string-to-minutes effort)
  5950. effort (setq effort (concat "[" effort "]")))))
  5951. ;; prevent erroring out with %e format when there is no effort
  5952. (or effort (setq effort ""))
  5953. (when remove-re
  5954. (while (string-match remove-re txt)
  5955. (setq txt (replace-match "" t t txt))))
  5956. ;; Set org-heading property on `txt' to mark the start of the
  5957. ;; heading.
  5958. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5959. ;; Prepare the variables needed in the eval of the compiled format
  5960. (setq time (cond (s2 (concat
  5961. (org-agenda-time-of-day-to-ampm-maybe s1)
  5962. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5963. (if org-agenda-timegrid-use-ampm " ")))
  5964. (s1 (concat
  5965. (org-agenda-time-of-day-to-ampm-maybe s1)
  5966. (if org-agenda-timegrid-use-ampm
  5967. "........ "
  5968. "......")))
  5969. (t ""))
  5970. extra (or (and (not habitp) extra) "")
  5971. category (if (symbolp category) (symbol-name category) category)
  5972. thecategory (copy-sequence category)
  5973. level (or level ""))
  5974. (if (string-match org-bracket-link-regexp category)
  5975. (progn
  5976. (setq l (if (match-end 3)
  5977. (- (match-end 3) (match-beginning 3))
  5978. (- (match-end 1) (match-beginning 1))))
  5979. (when (< l (or org-prefix-category-length 0))
  5980. (setq category (copy-sequence category))
  5981. (org-add-props category nil
  5982. 'extra-space (make-string
  5983. (- org-prefix-category-length l 1) ?\ ))))
  5984. (if (and org-prefix-category-max-length
  5985. (>= (length category) org-prefix-category-max-length))
  5986. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5987. ;; Evaluate the compiled format
  5988. (setq rtn (concat (eval formatter) txt))
  5989. ;; And finally add the text properties
  5990. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5991. (org-add-props rtn nil
  5992. 'org-category (if thecategory (downcase thecategory) category)
  5993. 'tags (mapcar 'org-downcase-keep-props tags)
  5994. 'org-highest-priority org-highest-priority
  5995. 'org-lowest-priority org-lowest-priority
  5996. 'time-of-day time-of-day
  5997. 'duration duration
  5998. 'effort effort
  5999. 'effort-minutes neffort
  6000. 'txt txt
  6001. 'level level
  6002. 'time time
  6003. 'extra extra
  6004. 'format org-prefix-format-compiled
  6005. 'dotime dotime)))))
  6006. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6007. "Remove tags string from TXT, and add a modified list of tags.
  6008. The modified list may contain inherited tags, and tags matched by
  6009. `org-agenda-hide-tags-regexp' will be removed."
  6010. (when (or add-inherited hide-re)
  6011. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6012. (setq txt (substring txt 0 (match-beginning 0))))
  6013. (setq tags
  6014. (delq nil
  6015. (mapcar (lambda (tg)
  6016. (if (or (and hide-re (string-match hide-re tg))
  6017. (and (not add-inherited)
  6018. (get-text-property 0 'inherited tg)))
  6019. nil
  6020. tg))
  6021. tags)))
  6022. (when tags
  6023. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6024. i)
  6025. (setq txt (concat txt " :"
  6026. (mapconcat
  6027. (lambda (x)
  6028. (setq i (get-text-property 0 'inherited x))
  6029. (if (and have-i (not i))
  6030. (progn
  6031. (setq have-i nil)
  6032. (concat ":" x))
  6033. x))
  6034. tags ":")
  6035. (if have-i "::" ":"))))))
  6036. txt)
  6037. (defun org-downcase-keep-props (s)
  6038. (let ((props (text-properties-at 0 s)))
  6039. (setq s (downcase s))
  6040. (add-text-properties 0 (length s) props s)
  6041. s))
  6042. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6043. (defvar org-agenda-sorting-strategy-selected nil)
  6044. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6045. "Add a time-grid for agenda items which need it.
  6046. LIST is the list of agenda items formatted by `org-agenda-list'.
  6047. NDAYS is the span of the current agenda view.
  6048. TODAYP is `t' when the current agenda view is on today."
  6049. (catch 'exit
  6050. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6051. ((and todayp (member 'today (car org-agenda-time-grid))))
  6052. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6053. ((member 'weekly (car org-agenda-time-grid)))
  6054. (t (throw 'exit list)))
  6055. (let* ((have (delq nil (mapcar
  6056. (lambda (x) (get-text-property 1 'time-of-day x))
  6057. list)))
  6058. (string (nth 1 org-agenda-time-grid))
  6059. (gridtimes (nth 2 org-agenda-time-grid))
  6060. (req (car org-agenda-time-grid))
  6061. (remove (member 'remove-match req))
  6062. new time)
  6063. (if (and (member 'require-timed req) (not have))
  6064. ;; don't show empty grid
  6065. (throw 'exit list))
  6066. (while (setq time (pop gridtimes))
  6067. (unless (and remove (member time have))
  6068. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6069. (push (org-agenda-format-item
  6070. nil string nil "" nil
  6071. (concat (substring time 0 -2) ":" (substring time -2)))
  6072. new)
  6073. (put-text-property
  6074. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6075. (when (and todayp org-agenda-show-current-time-in-grid)
  6076. (push (org-agenda-format-item
  6077. nil org-agenda-current-time-string nil "" nil
  6078. (format-time-string "%H:%M "))
  6079. new)
  6080. (put-text-property
  6081. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6082. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6083. (append new list)
  6084. (append list new)))))
  6085. (defun org-compile-prefix-format (key)
  6086. "Compile the prefix format into a Lisp form that can be evaluated.
  6087. The resulting form and associated variable bindings is returned
  6088. and stored in the variable `org-prefix-format-compiled'."
  6089. (setq org-prefix-has-time nil
  6090. org-prefix-has-tag nil
  6091. org-prefix-category-length nil
  6092. org-prefix-has-effort nil)
  6093. (let ((s (cond
  6094. ((stringp org-agenda-prefix-format)
  6095. org-agenda-prefix-format)
  6096. ((assq key org-agenda-prefix-format)
  6097. (cdr (assq key org-agenda-prefix-format)))
  6098. (t " %-12:c%?-12t% s")))
  6099. (start 0)
  6100. varform vars var e c f opt)
  6101. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
  6102. s start)
  6103. (setq var (or (cdr (assoc (match-string 4 s)
  6104. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6105. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  6106. 'eval)
  6107. c (or (match-string 3 s) "")
  6108. opt (match-beginning 1)
  6109. start (1+ (match-beginning 0)))
  6110. (if (equal var 'time) (setq org-prefix-has-time t))
  6111. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6112. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6113. (setq f (concat "%" (match-string 2 s) "s"))
  6114. (when (equal var 'category)
  6115. (setq org-prefix-category-length
  6116. (floor (abs (string-to-number (match-string 2 s)))))
  6117. (setq org-prefix-category-max-length
  6118. (let ((x (match-string 2 s)))
  6119. (save-match-data
  6120. (if (string-match "\\.[0-9]+" x)
  6121. (string-to-number (substring (match-string 0 x) 1)))))))
  6122. (if (eq var 'eval)
  6123. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6124. (if opt
  6125. (setq varform
  6126. `(if (equal "" ,var)
  6127. ""
  6128. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6129. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6130. (setq s (replace-match "%s" t nil s))
  6131. (push varform vars))
  6132. (setq vars (nreverse vars))
  6133. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6134. (setq org-prefix-format-compiled
  6135. (list
  6136. `((org-prefix-has-time ,org-prefix-has-time)
  6137. (org-prefix-has-tag ,org-prefix-has-tag)
  6138. (org-prefix-category-length ,org-prefix-category-length)
  6139. (org-prefix-has-effort ,org-prefix-has-effort))
  6140. `(format ,s ,@vars))))))
  6141. (defun org-set-sorting-strategy (key)
  6142. (if (symbolp (car org-agenda-sorting-strategy))
  6143. ;; the old format
  6144. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6145. (setq org-agenda-sorting-strategy-selected
  6146. (or (cdr (assq key org-agenda-sorting-strategy))
  6147. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6148. '(time-up category-keep priority-down)))))
  6149. (defun org-get-time-of-day (s &optional string mod24)
  6150. "Check string S for a time of day.
  6151. If found, return it as a military time number between 0 and 2400.
  6152. If not found, return nil.
  6153. The optional STRING argument forces conversion into a 5 character wide string
  6154. HH:MM."
  6155. (save-match-data
  6156. (when
  6157. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6158. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6159. (let* ((h (string-to-number (match-string 1 s)))
  6160. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6161. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6162. (am-p (equal ampm "am"))
  6163. (h1 (cond ((not ampm) h)
  6164. ((= h 12) (if am-p 0 12))
  6165. (t (+ h (if am-p 0 12)))))
  6166. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6167. (mod h1 24) h1))
  6168. (t0 (+ (* 100 h2) m))
  6169. (t1 (concat (if (>= h1 24) "+" " ")
  6170. (if (and org-agenda-time-leading-zero
  6171. (< t0 1000)) "0" "")
  6172. (if (< t0 100) "0" "")
  6173. (if (< t0 10) "0" "")
  6174. (int-to-string t0))))
  6175. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6176. (defvar org-agenda-before-sorting-filter-function nil
  6177. "Function to be applied to agenda items prior to sorting.
  6178. Prior to sorting also means just before they are inserted into the agenda.
  6179. To aid sorting, you may revisit the original entries and add more text
  6180. properties which will later be used by the sorting functions.
  6181. The function should take a string argument, an agenda line.
  6182. It has access to the text properties in that line, which contain among
  6183. other things, the property `org-hd-marker' that points to the entry
  6184. where the line comes from. Note that not all lines going into the agenda
  6185. have this property, only most.
  6186. The function should return the modified string. It is probably best
  6187. to ONLY change text properties.
  6188. You can also use this function as a filter, by returning nil for lines
  6189. you don't want to have in the agenda at all. For this application, you
  6190. could bind the variable in the options section of a custom command.")
  6191. (defun org-agenda-finalize-entries (list &optional nosort)
  6192. "Sort and concatenate the agenda items."
  6193. (setq list (mapcar 'org-agenda-highlight-todo list))
  6194. (if nosort
  6195. list
  6196. (when org-agenda-before-sorting-filter-function
  6197. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  6198. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  6199. (defun org-agenda-highlight-todo (x)
  6200. (let ((org-done-keywords org-done-keywords-for-agenda)
  6201. (case-fold-search nil)
  6202. re)
  6203. (if (eq x 'line)
  6204. (save-excursion
  6205. (beginning-of-line 1)
  6206. (setq re (org-get-at-bol 'org-todo-regexp))
  6207. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6208. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6209. (add-text-properties (match-beginning 0) (match-end 1)
  6210. (list 'face (org-get-todo-face 1)))
  6211. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6212. (delete-region (match-beginning 1) (1- (match-end 0)))
  6213. (goto-char (match-beginning 1))
  6214. (insert (format org-agenda-todo-keyword-format s)))))
  6215. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6216. (setq re (get-text-property 0 'org-todo-regexp x))
  6217. (when (and re
  6218. ;; Test `pl' because if there's no heading content,
  6219. ;; there's no point matching to highlight. Note
  6220. ;; that if we didn't test `pl' first, and there
  6221. ;; happened to be no keyword from `org-todo-regexp'
  6222. ;; on this heading line, then the `equal' comparison
  6223. ;; afterwards would spuriously succeed in the case
  6224. ;; where `pl' is nil -- causing an args-out-of-range
  6225. ;; error when we try to add text properties to text
  6226. ;; that isn't there.
  6227. pl
  6228. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6229. x pl) pl))
  6230. (add-text-properties
  6231. (or (match-end 1) (match-end 0)) (match-end 0)
  6232. (list 'face (org-get-todo-face (match-string 2 x)))
  6233. x)
  6234. (when (match-end 1)
  6235. (setq x (concat (substring x 0 (match-end 1))
  6236. (format org-agenda-todo-keyword-format
  6237. (match-string 2 x))
  6238. (org-add-props " " (text-properties-at 0 x))
  6239. (substring x (match-end 3)))))))
  6240. x)))
  6241. (defsubst org-cmp-priority (a b)
  6242. "Compare the priorities of string A and B."
  6243. (let ((pa (or (get-text-property 1 'priority a) 0))
  6244. (pb (or (get-text-property 1 'priority b) 0)))
  6245. (cond ((> pa pb) +1)
  6246. ((< pa pb) -1))))
  6247. (defsubst org-cmp-effort (a b)
  6248. "Compare the effort values of string A and B."
  6249. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6250. (ea (or (get-text-property 1 'effort-minutes a) def))
  6251. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6252. (cond ((> ea eb) +1)
  6253. ((< ea eb) -1))))
  6254. (defsubst org-cmp-category (a b)
  6255. "Compare the string values of categories of strings A and B."
  6256. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6257. (cb (or (get-text-property 1 'org-category b) "")))
  6258. (cond ((string-lessp ca cb) -1)
  6259. ((string-lessp cb ca) +1))))
  6260. (defsubst org-cmp-todo-state (a b)
  6261. "Compare the todo states of strings A and B."
  6262. (let* ((ma (or (get-text-property 1 'org-marker a)
  6263. (get-text-property 1 'org-hd-marker a)))
  6264. (mb (or (get-text-property 1 'org-marker b)
  6265. (get-text-property 1 'org-hd-marker b)))
  6266. (fa (and ma (marker-buffer ma)))
  6267. (fb (and mb (marker-buffer mb)))
  6268. (todo-kwds
  6269. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6270. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6271. (ta (or (get-text-property 1 'todo-state a) ""))
  6272. (tb (or (get-text-property 1 'todo-state b) ""))
  6273. (la (- (length (member ta todo-kwds))))
  6274. (lb (- (length (member tb todo-kwds))))
  6275. (donepa (member ta org-done-keywords-for-agenda))
  6276. (donepb (member tb org-done-keywords-for-agenda)))
  6277. (cond ((and donepa (not donepb)) -1)
  6278. ((and (not donepa) donepb) +1)
  6279. ((< la lb) -1)
  6280. ((< lb la) +1))))
  6281. (defsubst org-cmp-alpha (a b)
  6282. "Compare the headlines, alphabetically."
  6283. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6284. (plb (text-property-any 0 (length b) 'org-heading t b))
  6285. (ta (and pla (substring a pla)))
  6286. (tb (and plb (substring b plb))))
  6287. (when pla
  6288. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6289. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6290. (setq ta (substring ta (match-end 0))))
  6291. (setq ta (downcase ta)))
  6292. (when plb
  6293. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6294. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6295. (setq tb (substring tb (match-end 0))))
  6296. (setq tb (downcase tb)))
  6297. (cond ((not ta) +1)
  6298. ((not tb) -1)
  6299. ((string-lessp ta tb) -1)
  6300. ((string-lessp tb ta) +1))))
  6301. (defsubst org-cmp-tag (a b)
  6302. "Compare the string values of the first tags of A and B."
  6303. (let ((ta (car (last (get-text-property 1 'tags a))))
  6304. (tb (car (last (get-text-property 1 'tags b)))))
  6305. (cond ((not ta) +1)
  6306. ((not tb) -1)
  6307. ((string-lessp ta tb) -1)
  6308. ((string-lessp tb ta) +1))))
  6309. (defsubst org-cmp-time (a b)
  6310. "Compare the time-of-day values of strings A and B."
  6311. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6312. (ta (or (get-text-property 1 'time-of-day a) def))
  6313. (tb (or (get-text-property 1 'time-of-day b) def)))
  6314. (cond ((< ta tb) -1)
  6315. ((< tb ta) +1))))
  6316. (defsubst org-cmp-habit-p (a b)
  6317. "Compare the todo states of strings A and B."
  6318. (let ((ha (get-text-property 1 'org-habit-p a))
  6319. (hb (get-text-property 1 'org-habit-p b)))
  6320. (cond ((and ha (not hb)) -1)
  6321. ((and (not ha) hb) +1))))
  6322. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  6323. (defun org-entries-lessp (a b)
  6324. "Predicate for sorting agenda entries."
  6325. ;; The following variables will be used when the form is evaluated.
  6326. ;; So even though the compiler complains, keep them.
  6327. (let* ((ss org-agenda-sorting-strategy-selected)
  6328. (time-up (and (org-em 'time-up 'time-down ss)
  6329. (org-cmp-time a b)))
  6330. (time-down (if time-up (- time-up) nil))
  6331. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6332. (org-cmp-priority a b)))
  6333. (priority-down (if priority-up (- priority-up) nil))
  6334. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6335. (org-cmp-effort a b)))
  6336. (effort-down (if effort-up (- effort-up) nil))
  6337. (category-up (and (or (org-em 'category-up 'category-down ss)
  6338. (memq 'category-keep ss))
  6339. (org-cmp-category a b)))
  6340. (category-down (if category-up (- category-up) nil))
  6341. (category-keep (if category-up +1 nil))
  6342. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6343. (org-cmp-tag a b)))
  6344. (tag-down (if tag-up (- tag-up) nil))
  6345. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6346. (org-cmp-todo-state a b)))
  6347. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6348. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6349. (org-cmp-habit-p a b)))
  6350. (habit-down (if habit-up (- habit-up) nil))
  6351. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6352. (org-cmp-alpha a b)))
  6353. (alpha-down (if alpha-up (- alpha-up) nil))
  6354. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6355. user-defined-up user-defined-down)
  6356. (if (and need-user-cmp org-agenda-cmp-user-defined
  6357. (functionp org-agenda-cmp-user-defined))
  6358. (setq user-defined-up
  6359. (funcall org-agenda-cmp-user-defined a b)
  6360. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6361. (cdr (assoc
  6362. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6363. '((-1 . t) (1 . nil) (nil . nil))))))
  6364. ;;; Agenda restriction lock
  6365. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6366. "Overlay to mark the headline to which agenda commands are restricted.")
  6367. (overlay-put org-agenda-restriction-lock-overlay
  6368. 'face 'org-agenda-restriction-lock)
  6369. (overlay-put org-agenda-restriction-lock-overlay
  6370. 'help-echo "Agendas are currently limited to this subtree.")
  6371. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6372. (defun org-agenda-set-restriction-lock (&optional type)
  6373. "Set restriction lock for agenda, to current subtree or file.
  6374. Restriction will be the file if TYPE is `file', or if type is the
  6375. universal prefix '(4), or if the cursor is before the first headline
  6376. in the file. Otherwise, restriction will be to the current subtree."
  6377. (interactive "P")
  6378. (and (equal type '(4)) (setq type 'file))
  6379. (setq type (cond
  6380. (type type)
  6381. ((org-at-heading-p) 'subtree)
  6382. ((condition-case nil (org-back-to-heading t) (error nil))
  6383. 'subtree)
  6384. (t 'file)))
  6385. (if (eq type 'subtree)
  6386. (progn
  6387. (setq org-agenda-restrict t)
  6388. (setq org-agenda-overriding-restriction 'subtree)
  6389. (put 'org-agenda-files 'org-restrict
  6390. (list (buffer-file-name (buffer-base-buffer))))
  6391. (org-back-to-heading t)
  6392. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6393. (move-marker org-agenda-restrict-begin (point))
  6394. (move-marker org-agenda-restrict-end
  6395. (save-excursion (org-end-of-subtree t)))
  6396. (message "Locking agenda restriction to subtree"))
  6397. (put 'org-agenda-files 'org-restrict
  6398. (list (buffer-file-name (buffer-base-buffer))))
  6399. (setq org-agenda-restrict nil)
  6400. (setq org-agenda-overriding-restriction 'file)
  6401. (move-marker org-agenda-restrict-begin nil)
  6402. (move-marker org-agenda-restrict-end nil)
  6403. (message "Locking agenda restriction to file"))
  6404. (setq current-prefix-arg nil)
  6405. (org-agenda-maybe-redo))
  6406. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6407. "Remove the agenda restriction lock."
  6408. (interactive "P")
  6409. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6410. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6411. (setq org-agenda-overriding-restriction nil)
  6412. (setq org-agenda-restrict nil)
  6413. (put 'org-agenda-files 'org-restrict nil)
  6414. (move-marker org-agenda-restrict-begin nil)
  6415. (move-marker org-agenda-restrict-end nil)
  6416. (setq current-prefix-arg nil)
  6417. (message "Agenda restriction lock removed")
  6418. (or noupdate (org-agenda-maybe-redo)))
  6419. (defun org-agenda-maybe-redo ()
  6420. "If there is any window showing the agenda view, update it."
  6421. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6422. (w0 (selected-window)))
  6423. (when w
  6424. (select-window w)
  6425. (org-agenda-redo)
  6426. (select-window w0)
  6427. (if org-agenda-overriding-restriction
  6428. (message "Agenda view shifted to new %s restriction"
  6429. org-agenda-overriding-restriction)
  6430. (message "Agenda restriction lock removed")))))
  6431. ;;; Agenda commands
  6432. (defun org-agenda-check-type (error &rest types)
  6433. "Check if agenda buffer is of allowed type.
  6434. If ERROR is non-nil, throw an error, otherwise just return nil.
  6435. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6436. (if (not org-agenda-type)
  6437. (error "No Org agenda currently displayed")
  6438. (if (memq org-agenda-type types)
  6439. t
  6440. (if error
  6441. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6442. nil))))
  6443. (defun org-agenda-Quit ()
  6444. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6445. Also restore the window configuration."
  6446. (interactive)
  6447. (if org-agenda-columns-active
  6448. (org-columns-quit)
  6449. (let ((buf (current-buffer)))
  6450. (if (eq org-agenda-window-setup 'other-frame)
  6451. (progn
  6452. (org-agenda-reset-markers)
  6453. (kill-buffer buf)
  6454. (org-columns-remove-overlays)
  6455. (setq org-agenda-archives-mode nil)
  6456. (delete-frame))
  6457. (and (not (eq org-agenda-window-setup 'current-window))
  6458. (not (one-window-p))
  6459. (delete-window))
  6460. (org-agenda-reset-markers)
  6461. (kill-buffer buf)
  6462. (org-columns-remove-overlays)
  6463. (setq org-agenda-archives-mode nil)))
  6464. ;; Maybe restore the pre-agenda window configuration.
  6465. (and org-agenda-restore-windows-after-quit
  6466. (not (eq org-agenda-window-setup 'other-frame))
  6467. org-agenda-pre-window-conf
  6468. (set-window-configuration org-agenda-pre-window-conf)
  6469. (setq org-agenda-pre-window-conf nil))))
  6470. (defun org-agenda-quit ()
  6471. "Exit the agenda and restore the window configuration.
  6472. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6473. (interactive)
  6474. (if (and (eq org-indirect-buffer-display 'other-window)
  6475. org-last-indirect-buffer)
  6476. (let ((org-last-indirect-window
  6477. (get-buffer-window org-last-indirect-buffer)))
  6478. (if org-last-indirect-window
  6479. (delete-window org-last-indirect-window))))
  6480. (if org-agenda-columns-active
  6481. (org-columns-quit)
  6482. (if org-agenda-sticky
  6483. (let ((buf (current-buffer)))
  6484. (if (eq org-agenda-window-setup 'other-frame)
  6485. (progn
  6486. (delete-frame))
  6487. (and (not (eq org-agenda-window-setup 'current-window))
  6488. (not (one-window-p))
  6489. (delete-window)))
  6490. (with-current-buffer buf
  6491. (bury-buffer)
  6492. ;; Maybe restore the pre-agenda window configuration.
  6493. (and org-agenda-restore-windows-after-quit
  6494. (not (eq org-agenda-window-setup 'other-frame))
  6495. org-agenda-pre-window-conf
  6496. (set-window-configuration org-agenda-pre-window-conf)
  6497. (setq org-agenda-pre-window-conf nil))))
  6498. (org-agenda-Quit))))
  6499. (defun org-agenda-exit ()
  6500. "Exit the agenda and restore the window configuration.
  6501. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6502. buffers visited directly by the user will not be touched."
  6503. (interactive)
  6504. (org-release-buffers org-agenda-new-buffers)
  6505. (setq org-agenda-new-buffers nil)
  6506. (org-agenda-Quit))
  6507. (defun org-agenda-kill-all-agenda-buffers ()
  6508. "Kill all buffers in `org-agenda-mode'.
  6509. This is used when toggling sticky agendas.
  6510. You can also explicitly invoke it with `C-c a C-k'."
  6511. (interactive)
  6512. (let (blist)
  6513. (dolist (buf (buffer-list))
  6514. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6515. (push buf blist)))
  6516. (mapc 'kill-buffer blist)))
  6517. (defun org-agenda-execute (arg)
  6518. "Execute another agenda command, keeping same window.
  6519. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6520. in the agenda."
  6521. (interactive "P")
  6522. (let ((org-agenda-window-setup 'current-window))
  6523. (org-agenda arg)))
  6524. (defun org-agenda-redo (&optional all)
  6525. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6526. (interactive "P")
  6527. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6528. (cpa (unless (eq all t) current-prefix-arg))
  6529. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6530. (org-agenda-sticky nil)
  6531. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6532. org-agenda-buffer-name))
  6533. (org-agenda-keep-modes t)
  6534. (tag-filter org-agenda-tag-filter)
  6535. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6536. (top-cat-filter org-agenda-top-category-filter)
  6537. (cat-filter org-agenda-category-filter)
  6538. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6539. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6540. (cols org-agenda-columns-active)
  6541. (line (org-current-line))
  6542. (window-line (- line (org-current-line (window-start))))
  6543. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6544. (redo-cmd (get-text-property p 'org-redo-cmd))
  6545. (last-args (get-text-property p 'org-last-args))
  6546. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6547. (org-agenda-overriding-cmd-arguments
  6548. (unless (eq all t)
  6549. (cond ((listp last-args)
  6550. (cons (or cpa (car last-args)) (cdr last-args)))
  6551. ((stringp last-args)
  6552. last-args))))
  6553. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6554. (put 'org-agenda-tag-filter :preset-filter nil)
  6555. (put 'org-agenda-category-filter :preset-filter nil)
  6556. (and cols (org-columns-quit))
  6557. (message "Rebuilding agenda buffer...")
  6558. (if series-redo-cmd
  6559. (eval series-redo-cmd)
  6560. (org-let lprops '(eval redo-cmd)))
  6561. (setq org-agenda-undo-list nil
  6562. org-agenda-pending-undo-list nil)
  6563. (message "Rebuilding agenda buffer...done")
  6564. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6565. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6566. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6567. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6568. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6569. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6570. (org-goto-line line)
  6571. (recenter window-line)))
  6572. (defvar org-global-tags-completion-table nil)
  6573. (defvar org-agenda-filter-form nil)
  6574. (defvar org-agenda-filtered-by-category nil)
  6575. (defun org-agenda-filter-by-category (strip)
  6576. "Keep only those lines in the agenda buffer that have a specific category.
  6577. The category is that of the current line."
  6578. (interactive "P")
  6579. (if (and org-agenda-filtered-by-category
  6580. org-agenda-category-filter)
  6581. (org-agenda-filter-show-all-cat)
  6582. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6583. (if cat (org-agenda-filter-apply
  6584. (list (concat (if strip "-" "+") cat)) 'category)
  6585. (error "No category at point")))))
  6586. (defun org-find-top-category (&optional pos)
  6587. (save-excursion
  6588. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6589. (if pos (goto-char pos))
  6590. ;; Skip up to the topmost parent
  6591. (while (ignore-errors (outline-up-heading 1) t))
  6592. (ignore-errors
  6593. (nth 4 (org-heading-components))))))
  6594. (defvar org-agenda-filtered-by-top-category nil)
  6595. (defun org-agenda-filter-by-top-category (strip)
  6596. "Keep only those lines in the agenda buffer that have a specific category.
  6597. The category is that of the current line."
  6598. (interactive "P")
  6599. (if org-agenda-filtered-by-top-category
  6600. (progn
  6601. (setq org-agenda-filtered-by-top-category nil
  6602. org-agenda-top-category-filter nil)
  6603. (org-agenda-filter-show-all-cat))
  6604. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6605. (if cat (org-agenda-filter-top-category-apply cat strip)
  6606. (error "No top-level category at point")))))
  6607. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6608. "Keep only those lines in the agenda buffer that have a specific tag.
  6609. The tag is selected with its fast selection letter, as configured.
  6610. With prefix argument STRIP, remove all lines that do have the tag.
  6611. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6612. used to narrow the search - the interactive user can also press `-' or `+'
  6613. to switch to narrowing."
  6614. (interactive "P")
  6615. (let* ((alist org-tag-alist-for-agenda)
  6616. (tag-chars (mapconcat
  6617. (lambda (x) (if (and (not (symbolp (car x)))
  6618. (cdr x))
  6619. (char-to-string (cdr x))
  6620. ""))
  6621. alist ""))
  6622. (efforts (org-split-string
  6623. (or (cdr (assoc (concat org-effort-property "_ALL")
  6624. org-global-properties))
  6625. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6626. "")))
  6627. (effort-op org-agenda-filter-effort-default-operator)
  6628. (effort-prompt "")
  6629. (inhibit-read-only t)
  6630. (current org-agenda-tag-filter)
  6631. maybe-refresh a n tag)
  6632. (unless char
  6633. (message
  6634. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6635. (if narrow "Narrow" "Filter") tag-chars
  6636. (if org-agenda-auto-exclude-function "[RET], " ""))
  6637. (setq char (read-char-exclusive)))
  6638. (when (member char '(?+ ?-))
  6639. ;; Narrowing down
  6640. (cond ((equal char ?-) (setq strip t narrow t))
  6641. ((equal char ?+) (setq strip nil narrow t)))
  6642. (message
  6643. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6644. (setq char (read-char-exclusive)))
  6645. (when (member char '(?< ?> ?= ??))
  6646. ;; An effort operator
  6647. (setq effort-op (char-to-string char))
  6648. (setq alist nil) ; to make sure it will be interpreted as effort.
  6649. (unless (equal char ??)
  6650. (loop for i from 0 to 9 do
  6651. (setq effort-prompt
  6652. (concat
  6653. effort-prompt " ["
  6654. (if (= i 9) "0" (int-to-string (1+ i)))
  6655. "]" (nth i efforts))))
  6656. (message "Effort%s: %s " effort-op effort-prompt)
  6657. (setq char (read-char-exclusive))
  6658. (when (or (< char ?0) (> char ?9))
  6659. (error "Need 1-9,0 to select effort"))))
  6660. (when (equal char ?\t)
  6661. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6662. (org-set-local 'org-global-tags-completion-table
  6663. (org-global-tags-completion-table)))
  6664. (let ((completion-ignore-case t))
  6665. (setq tag (org-icompleting-read
  6666. "Tag: " org-global-tags-completion-table))))
  6667. (cond
  6668. ((equal char ?\r)
  6669. (org-agenda-filter-show-all-tag)
  6670. (when org-agenda-auto-exclude-function
  6671. (setq org-agenda-tag-filter '())
  6672. (dolist (tag (org-agenda-get-represented-tags))
  6673. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6674. (if modifier
  6675. (push modifier org-agenda-tag-filter))))
  6676. (if (not (null org-agenda-tag-filter))
  6677. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6678. (setq maybe-refresh t))
  6679. ((equal char ?/)
  6680. (org-agenda-filter-show-all-tag)
  6681. (when (get 'org-agenda-tag-filter :preset-filter)
  6682. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6683. (setq maybe-refresh t))
  6684. ((equal char ?. )
  6685. (setq org-agenda-tag-filter
  6686. (mapcar (lambda(tag) (concat "+" tag))
  6687. (org-get-at-bol 'tags)))
  6688. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6689. (setq maybe-refresh t))
  6690. ((or (equal char ?\ )
  6691. (setq a (rassoc char alist))
  6692. (and (>= char ?0) (<= char ?9)
  6693. (setq n (if (= char ?0) 9 (- char ?0 1))
  6694. tag (concat effort-op (nth n efforts))
  6695. a (cons tag nil)))
  6696. (and (= char ??)
  6697. (setq tag "?eff")
  6698. a (cons tag nil))
  6699. (and tag (setq a (cons tag nil))))
  6700. (org-agenda-filter-show-all-tag)
  6701. (setq tag (car a))
  6702. (setq org-agenda-tag-filter
  6703. (cons (concat (if strip "-" "+") tag)
  6704. (if narrow current nil)))
  6705. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6706. (setq maybe-refresh t))
  6707. (t (error "Invalid tag selection character %c" char)))
  6708. (when (and maybe-refresh
  6709. (eq org-agenda-clockreport-mode 'with-filter))
  6710. (org-agenda-redo))))
  6711. (defun org-agenda-get-represented-tags ()
  6712. "Get a list of all tags currently represented in the agenda."
  6713. (let (p tags)
  6714. (save-excursion
  6715. (goto-char (point-min))
  6716. (while (setq p (next-single-property-change (point) 'tags))
  6717. (goto-char p)
  6718. (mapc (lambda (x) (add-to-list 'tags x))
  6719. (get-text-property (point) 'tags))))
  6720. tags))
  6721. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6722. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6723. (interactive "P")
  6724. (org-agenda-filter-by-tag strip char 'refine))
  6725. (defun org-agenda-filter-make-matcher ()
  6726. "Create the form that tests a line for agenda filter."
  6727. (let (f f1)
  6728. ;; first compute the tag-filter matcher
  6729. (dolist (x (delete-dups
  6730. (append (get 'org-agenda-tag-filter
  6731. :preset-filter) org-agenda-tag-filter)))
  6732. (if (member x '("-" "+"))
  6733. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6734. (if (string-match "[<=>?]" x)
  6735. (setq f1 (org-agenda-filter-effort-form x))
  6736. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6737. (if (equal (string-to-char x) ?-)
  6738. (setq f1 (list 'not f1))))
  6739. (push f1 f))
  6740. ;; then compute the category-filter matcher
  6741. (dolist (x (delete-dups
  6742. (append (get 'org-agenda-category-filter
  6743. :preset-filter) org-agenda-category-filter)))
  6744. (if (equal "-" (substring x 0 1))
  6745. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6746. (setq f1 (list 'equal (substring x 1) 'cat)))
  6747. (push f1 f))
  6748. (cons 'and (nreverse f))))
  6749. (defun org-agenda-filter-effort-form (e)
  6750. "Return the form to compare the effort of the current line with what E says.
  6751. E looks like \"+<2:25\"."
  6752. (let (op)
  6753. (setq e (substring e 1))
  6754. (setq op (string-to-char e) e (substring e 1))
  6755. (setq op (cond ((equal op ?<) '<=)
  6756. ((equal op ?>) '>=)
  6757. ((equal op ??) op)
  6758. (t '=)))
  6759. (list 'org-agenda-compare-effort (list 'quote op)
  6760. (org-duration-string-to-minutes e))))
  6761. (defun org-agenda-compare-effort (op value)
  6762. "Compare the effort of the current line with VALUE, using OP.
  6763. If the line does not have an effort defined, return nil."
  6764. (let ((eff (org-get-at-bol 'effort-minutes)))
  6765. (if (equal op ??)
  6766. (not eff)
  6767. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6768. value))))
  6769. (defun org-agenda-filter-apply (filter type)
  6770. "Set FILTER as the new agenda filter and apply it."
  6771. (let (tags cat)
  6772. (if (eq type 'tag)
  6773. (setq org-agenda-tag-filter filter)
  6774. (setq org-agenda-category-filter filter))
  6775. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6776. (if (and (eq type 'category)
  6777. (not (equal (substring (car filter) 0 1) "-")))
  6778. ;; Only set `org-agenda-filtered-by-category' to t
  6779. ;; when a unique category is used as the filter
  6780. (setq org-agenda-filtered-by-category t))
  6781. (org-agenda-set-mode-name)
  6782. (save-excursion
  6783. (goto-char (point-min))
  6784. (while (not (eobp))
  6785. (if (org-get-at-bol 'org-marker)
  6786. (progn
  6787. (setq tags (org-get-at-bol 'tags) ; used in eval
  6788. cat (get-text-property (point) 'org-category))
  6789. (if (not (eval org-agenda-filter-form))
  6790. (org-agenda-filter-hide-line type))
  6791. (beginning-of-line 2))
  6792. (beginning-of-line 2))))
  6793. (if (get-char-property (point) 'invisible)
  6794. (ignore-errors (org-agenda-previous-line)))))
  6795. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6796. "Set FILTER as the new agenda filter and apply it."
  6797. (org-agenda-set-mode-name)
  6798. (save-excursion
  6799. (goto-char (point-min))
  6800. (while (not (eobp))
  6801. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6802. (topcat (and pos (org-find-top-category pos))))
  6803. (if (and topcat (funcall (if negative 'identity 'not)
  6804. (string= category topcat)))
  6805. (org-agenda-filter-hide-line 'category)))
  6806. (beginning-of-line 2)))
  6807. (if (get-char-property (point) 'invisible)
  6808. (org-agenda-previous-line))
  6809. (setq org-agenda-top-category-filter category
  6810. org-agenda-filtered-by-top-category t))
  6811. (defun org-agenda-filter-hide-line (type)
  6812. (let (ov)
  6813. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6814. (point-at-eol)))
  6815. (overlay-put ov 'invisible t)
  6816. (overlay-put ov 'type type)
  6817. (if (eq type 'tag)
  6818. (push ov org-agenda-tag-filter-overlays)
  6819. (push ov org-agenda-cat-filter-overlays))))
  6820. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6821. (setq pos (or pos (point)))
  6822. (save-excursion
  6823. (dolist (ov (overlays-at pos))
  6824. (when (and (overlay-get ov 'invisible)
  6825. (eq (overlay-get ov 'type) 'tag))
  6826. (goto-char pos)
  6827. (if (< (overlay-start ov) (point-at-eol))
  6828. (move-overlay ov (point-at-eol)
  6829. (overlay-end ov)))))))
  6830. (defun org-agenda-filter-show-all-tag nil
  6831. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6832. (setq org-agenda-tag-filter-overlays nil
  6833. org-agenda-tag-filter nil
  6834. org-agenda-filter-form nil)
  6835. (org-agenda-set-mode-name))
  6836. (defun org-agenda-filter-show-all-cat nil
  6837. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6838. (setq org-agenda-cat-filter-overlays nil
  6839. org-agenda-filtered-by-category nil
  6840. org-agenda-category-filter nil
  6841. org-agenda-filter-form nil)
  6842. (org-agenda-set-mode-name))
  6843. (defun org-agenda-manipulate-query-add ()
  6844. "Manipulate the query by adding a search term with positive selection.
  6845. Positive selection means the term must be matched for selection of an entry."
  6846. (interactive)
  6847. (org-agenda-manipulate-query ?\[))
  6848. (defun org-agenda-manipulate-query-subtract ()
  6849. "Manipulate the query by adding a search term with negative selection.
  6850. Negative selection means term must not be matched for selection of an entry."
  6851. (interactive)
  6852. (org-agenda-manipulate-query ?\]))
  6853. (defun org-agenda-manipulate-query-add-re ()
  6854. "Manipulate the query by adding a search regexp with positive selection.
  6855. Positive selection means the regexp must match for selection of an entry."
  6856. (interactive)
  6857. (org-agenda-manipulate-query ?\{))
  6858. (defun org-agenda-manipulate-query-subtract-re ()
  6859. "Manipulate the query by adding a search regexp with negative selection.
  6860. Negative selection means regexp must not match for selection of an entry."
  6861. (interactive)
  6862. (org-agenda-manipulate-query ?\}))
  6863. (defun org-agenda-manipulate-query (char)
  6864. (cond
  6865. ((memq org-agenda-type '(timeline agenda))
  6866. (let ((org-agenda-include-inactive-timestamps t))
  6867. (org-agenda-redo))
  6868. (message "Display now includes inactive timestamps as well"))
  6869. ((eq org-agenda-type 'search)
  6870. (org-add-to-string
  6871. 'org-agenda-query-string
  6872. (if org-agenda-last-search-view-search-was-boolean
  6873. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6874. (?\{ . " +{}") (?\} . " -{}"))))
  6875. " "))
  6876. (setq org-agenda-redo-command
  6877. (list 'org-search-view
  6878. (car (get-text-property (min (1- (point-max)) (point))
  6879. 'org-last-args))
  6880. org-agenda-query-string
  6881. (+ (length org-agenda-query-string)
  6882. (if (member char '(?\{ ?\})) 0 1))))
  6883. (set-register org-agenda-query-register org-agenda-query-string)
  6884. (let ((org-agenda-overriding-arguments
  6885. (cdr org-agenda-redo-command)))
  6886. (org-agenda-redo)))
  6887. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6888. org-agenda-type))))
  6889. (defun org-add-to-string (var string)
  6890. (set var (concat (symbol-value var) string)))
  6891. (defun org-agenda-goto-date (span)
  6892. "Jump to DATE in agenda."
  6893. (interactive "P")
  6894. (let* ((org-read-date-prefer-future
  6895. (eval org-agenda-jump-prefer-future))
  6896. (date (org-read-date))
  6897. (org-agenda-sticky-orig org-agenda-sticky)
  6898. (org-agenda-buffer-tmp-name (buffer-name))
  6899. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6900. (0-arg (or current-prefix-arg (car args)))
  6901. (2-arg (nth 2 args))
  6902. (newcmd (list 'org-agenda-list 0-arg date
  6903. (org-agenda-span-to-ndays 2-arg)))
  6904. (newargs (cdr newcmd))
  6905. (inhibit-read-only t)
  6906. org-agenda-sticky)
  6907. (if (not (org-agenda-check-type t 'agenda))
  6908. (error "Not available in non-agenda blocks")
  6909. (add-text-properties (point-min) (point-max)
  6910. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6911. (org-agenda-redo)
  6912. (setq org-agenda-sticky org-agenda-sticky-orig
  6913. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6914. (defun org-agenda-goto-today ()
  6915. "Go to today."
  6916. (interactive)
  6917. (org-agenda-check-type t 'timeline 'agenda)
  6918. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6919. (curspan (nth 2 args))
  6920. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6921. (cond
  6922. (tdpos (goto-char tdpos))
  6923. ((eq org-agenda-type 'agenda)
  6924. (let* ((sd (org-agenda-compute-starting-span
  6925. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6926. (org-agenda-overriding-arguments args))
  6927. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6928. (org-agenda-redo)
  6929. (org-agenda-find-same-or-today-or-agenda)))
  6930. (t (error "Cannot find today")))))
  6931. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6932. (goto-char
  6933. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6934. (text-property-any (point-min) (point-max) 'org-today t)
  6935. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6936. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  6937. (org-agenda-goto-block-beginning))
  6938. (point-min))))
  6939. (defun org-agenda-goto-block-beginning ()
  6940. "Go the agenda block beginning."
  6941. (interactive)
  6942. (if (not (derived-mode-p 'org-agenda-mode))
  6943. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6944. (let (dest)
  6945. (save-excursion
  6946. (unless (looking-at "\\'")
  6947. (forward-char))
  6948. (let* ((prop 'org-agenda-structural-header)
  6949. (p (previous-single-property-change (point) prop))
  6950. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6951. (1- (point))) prop)))
  6952. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6953. (if (not dest)
  6954. (error "Cannot find the beginning of the blog")
  6955. (goto-char dest)
  6956. (move-beginning-of-line 1)))))
  6957. (defun org-agenda-later (arg)
  6958. "Go forward in time by the current span.
  6959. With prefix ARG, go forward that many times the current span."
  6960. (interactive "p")
  6961. (org-agenda-check-type t 'agenda)
  6962. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6963. (span (or (nth 2 args) org-agenda-current-span))
  6964. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6965. (greg (calendar-gregorian-from-absolute sd))
  6966. (cnt (org-get-at-bol 'org-day-cnt))
  6967. greg2)
  6968. (cond
  6969. ((numberp span)
  6970. (setq sd (+ (* span arg) sd)))
  6971. ((eq span 'day)
  6972. (setq sd (+ arg sd)))
  6973. ((eq span 'week)
  6974. (setq sd (+ (* 7 arg) sd)))
  6975. ((eq span 'month)
  6976. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6977. sd (calendar-absolute-from-gregorian greg2))
  6978. (setcar greg2 (1+ (car greg2))))
  6979. ((eq span 'year)
  6980. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6981. sd (calendar-absolute-from-gregorian greg2))
  6982. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6983. (t
  6984. (setq sd (+ (* span arg) sd))))
  6985. (let ((org-agenda-overriding-cmd
  6986. ;; `cmd' may have been set by `org-agenda-run-series' which
  6987. ;; uses `org-agenda-overriding-cmd' to decide whether
  6988. ;; overriding is allowed for `cmd'
  6989. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  6990. (org-agenda-overriding-arguments
  6991. (list (car args) sd span)))
  6992. (org-agenda-redo)
  6993. (org-agenda-find-same-or-today-or-agenda cnt))))
  6994. (defun org-agenda-earlier (arg)
  6995. "Go backward in time by the current span.
  6996. With prefix ARG, go backward that many times the current span."
  6997. (interactive "p")
  6998. (org-agenda-later (- arg)))
  6999. (defun org-agenda-view-mode-dispatch ()
  7000. "Call one of the view mode commands."
  7001. (interactive)
  7002. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  7003. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7004. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7005. (let ((a (read-char-exclusive)))
  7006. (case a
  7007. (?\ (call-interactively 'org-agenda-reset-view))
  7008. (?d (call-interactively 'org-agenda-day-view))
  7009. (?w (call-interactively 'org-agenda-week-view))
  7010. (?m (call-interactively 'org-agenda-month-view))
  7011. (?y (call-interactively 'org-agenda-year-view))
  7012. (?l (call-interactively 'org-agenda-log-mode))
  7013. (?L (org-agenda-log-mode '(4)))
  7014. (?c (org-agenda-log-mode 'clockcheck))
  7015. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7016. (?a (call-interactively 'org-agenda-archives-mode))
  7017. (?A (org-agenda-archives-mode 'files))
  7018. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7019. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7020. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7021. (?D (call-interactively 'org-agenda-toggle-diary))
  7022. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7023. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7024. (org-agenda-check-type t 'timeline 'agenda)
  7025. (org-agenda-redo))
  7026. (message "Display now includes inactive timestamps as well"))
  7027. (?q (message "Abort"))
  7028. (otherwise (error "Invalid key" )))))
  7029. (defun org-agenda-reset-view ()
  7030. "Switch to default view for agenda."
  7031. (interactive)
  7032. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7033. (defun org-agenda-day-view (&optional day-of-year)
  7034. "Switch to daily view for agenda.
  7035. With argument DAY-OF-YEAR, switch to that day of the year."
  7036. (interactive "P")
  7037. (org-agenda-change-time-span 'day day-of-year))
  7038. (defun org-agenda-week-view (&optional iso-week)
  7039. "Switch to daily view for agenda.
  7040. With argument ISO-WEEK, switch to the corresponding ISO week.
  7041. If ISO-WEEK has more then 2 digits, only the last two encode the
  7042. week. Any digits before this encode a year. So 200712 means
  7043. week 12 of year 2007. Years in the range 1938-2037 can also be
  7044. written as 2-digit years."
  7045. (interactive "P")
  7046. (org-agenda-change-time-span 'week iso-week))
  7047. (defun org-agenda-month-view (&optional month)
  7048. "Switch to monthly view for agenda.
  7049. With argument MONTH, switch to that month."
  7050. (interactive "P")
  7051. (org-agenda-change-time-span 'month month))
  7052. (defun org-agenda-year-view (&optional year)
  7053. "Switch to yearly view for agenda.
  7054. With argument YEAR, switch to that year.
  7055. If MONTH has more then 2 digits, only the last two encode the
  7056. month. Any digits before this encode a year. So 200712 means
  7057. December year 2007. Years in the range 1938-2037 can also be
  7058. written as 2-digit years."
  7059. (interactive "P")
  7060. (when year
  7061. (setq year (org-small-year-to-year year)))
  7062. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7063. (org-agenda-change-time-span 'year year)
  7064. (error "Abort")))
  7065. (defun org-agenda-change-time-span (span &optional n)
  7066. "Change the agenda view to SPAN.
  7067. SPAN may be `day', `week', `month', `year'."
  7068. (org-agenda-check-type t 'agenda)
  7069. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7070. (curspan (nth 2 args)))
  7071. (if (and (not n) (equal curspan span))
  7072. (error "Viewing span is already \"%s\"" span))
  7073. (let* ((sd (or (org-get-at-bol 'day)
  7074. (nth 1 args)
  7075. org-starting-day))
  7076. (sd (org-agenda-compute-starting-span sd span n))
  7077. (org-agenda-overriding-cmd
  7078. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7079. (org-agenda-overriding-arguments
  7080. (list (car args) sd span)))
  7081. (org-agenda-redo)
  7082. (org-agenda-find-same-or-today-or-agenda))
  7083. (org-agenda-set-mode-name)
  7084. (message "Switched to %s view" span)))
  7085. (defun org-agenda-compute-starting-span (sd span &optional n)
  7086. "Compute starting date for agenda.
  7087. SPAN may be `day', `week', `month', `year'. The return value
  7088. is a cons cell with the starting date and the number of days,
  7089. so that the date SD will be in that range."
  7090. (let* ((greg (calendar-gregorian-from-absolute sd))
  7091. (dg (nth 1 greg))
  7092. (mg (car greg))
  7093. (yg (nth 2 greg)))
  7094. (cond
  7095. ((eq span 'day)
  7096. (when n
  7097. (setq sd (+ (calendar-absolute-from-gregorian
  7098. (list mg 1 yg))
  7099. n -1))))
  7100. ((eq span 'week)
  7101. (let* ((nt (calendar-day-of-week
  7102. (calendar-gregorian-from-absolute sd)))
  7103. (d (if org-agenda-start-on-weekday
  7104. (- nt org-agenda-start-on-weekday)
  7105. 0))
  7106. y1)
  7107. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7108. (when n
  7109. (require 'cal-iso)
  7110. (when (> n 99)
  7111. (setq y1 (org-small-year-to-year (/ n 100))
  7112. n (mod n 100)))
  7113. (setq sd
  7114. (calendar-absolute-from-iso
  7115. (list n 1
  7116. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7117. ((eq span 'month)
  7118. (let (y1)
  7119. (when (and n (> n 99))
  7120. (setq y1 (org-small-year-to-year (/ n 100))
  7121. n (mod n 100)))
  7122. (setq sd (calendar-absolute-from-gregorian
  7123. (list (or n mg) 1 (or y1 yg))))))
  7124. ((eq span 'year)
  7125. (setq sd (calendar-absolute-from-gregorian
  7126. (list 1 1 (or n yg))))))
  7127. sd))
  7128. (defun org-agenda-next-date-line (&optional arg)
  7129. "Jump to the next line indicating a date in agenda buffer."
  7130. (interactive "p")
  7131. (org-agenda-check-type t 'agenda 'timeline)
  7132. (beginning-of-line 1)
  7133. ;; This does not work if user makes date format that starts with a blank
  7134. (if (looking-at "^\\S-") (forward-char 1))
  7135. (if (not (re-search-forward "^\\S-" nil t arg))
  7136. (progn
  7137. (backward-char 1)
  7138. (error "No next date after this line in this buffer")))
  7139. (goto-char (match-beginning 0)))
  7140. (defun org-agenda-previous-date-line (&optional arg)
  7141. "Jump to the previous line indicating a date in agenda buffer."
  7142. (interactive "p")
  7143. (org-agenda-check-type t 'agenda 'timeline)
  7144. (beginning-of-line 1)
  7145. (if (not (re-search-backward "^\\S-" nil t arg))
  7146. (error "No previous date before this line in this buffer")))
  7147. ;; Initialize the highlight
  7148. (defvar org-hl (make-overlay 1 1))
  7149. (overlay-put org-hl 'face 'highlight)
  7150. (defun org-highlight (begin end &optional buffer)
  7151. "Highlight a region with overlay."
  7152. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7153. (defun org-unhighlight ()
  7154. "Detach overlay INDEX."
  7155. (org-detach-overlay org-hl))
  7156. (defun org-unhighlight-once ()
  7157. "Remove the highlight from its position, and this function from the hook."
  7158. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7159. (org-unhighlight))
  7160. (defvar org-agenda-pre-follow-window-conf nil)
  7161. (defun org-agenda-follow-mode ()
  7162. "Toggle follow mode in an agenda buffer."
  7163. (interactive)
  7164. (unless org-agenda-follow-mode
  7165. (setq org-agenda-pre-follow-window-conf
  7166. (current-window-configuration)))
  7167. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7168. (unless org-agenda-follow-mode
  7169. (set-window-configuration org-agenda-pre-follow-window-conf))
  7170. (org-agenda-set-mode-name)
  7171. (org-agenda-do-context-action)
  7172. (message "Follow mode is %s"
  7173. (if org-agenda-follow-mode "on" "off")))
  7174. (defun org-agenda-entry-text-mode (&optional arg)
  7175. "Toggle entry text mode in an agenda buffer."
  7176. (interactive "P")
  7177. (setq org-agenda-entry-text-mode (or (integerp arg)
  7178. (not org-agenda-entry-text-mode)))
  7179. (org-agenda-entry-text-hide)
  7180. (and org-agenda-entry-text-mode
  7181. (let ((org-agenda-entry-text-maxlines
  7182. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7183. (org-agenda-entry-text-show)))
  7184. (org-agenda-set-mode-name)
  7185. (message "Entry text mode is %s. Maximum number of lines is %d"
  7186. (if org-agenda-entry-text-mode "on" "off")
  7187. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7188. (defun org-agenda-clockreport-mode (&optional with-filter)
  7189. "Toggle clocktable mode in an agenda buffer.
  7190. With prefix arg WITH-FILTER, make the clocktable respect the current
  7191. agenda filter."
  7192. (interactive "P")
  7193. (org-agenda-check-type t 'agenda)
  7194. (if with-filter
  7195. (setq org-agenda-clockreport-mode 'with-filter)
  7196. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7197. (org-agenda-set-mode-name)
  7198. (org-agenda-redo)
  7199. (message "Clocktable mode is %s"
  7200. (if org-agenda-clockreport-mode "on" "off")))
  7201. (defun org-agenda-log-mode (&optional special)
  7202. "Toggle log mode in an agenda buffer.
  7203. With argument SPECIAL, show all possible log items, not only the ones
  7204. configured in `org-agenda-log-mode-items'.
  7205. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7206. (interactive "P")
  7207. (org-agenda-check-type t 'agenda 'timeline)
  7208. (setq org-agenda-show-log
  7209. (cond
  7210. ((equal special '(16)) 'only)
  7211. ((eq special 'clockcheck)
  7212. (if (eq org-agenda-show-log 'clockcheck)
  7213. nil 'clockcheck))
  7214. (special '(closed clock state))
  7215. (t (not org-agenda-show-log))))
  7216. (org-agenda-set-mode-name)
  7217. (org-agenda-redo)
  7218. (message "Log mode is %s"
  7219. (if org-agenda-show-log "on" "off")))
  7220. (defun org-agenda-archives-mode (&optional with-files)
  7221. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7222. When called with a prefix argument, include all archive files as well."
  7223. (interactive "P")
  7224. (setq org-agenda-archives-mode
  7225. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7226. (org-agenda-set-mode-name)
  7227. (org-agenda-redo)
  7228. (message
  7229. "%s"
  7230. (cond
  7231. ((eq org-agenda-archives-mode nil)
  7232. "No archives are included")
  7233. ((eq org-agenda-archives-mode 'trees)
  7234. (format "Trees with :%s: tag are included" org-archive-tag))
  7235. ((eq org-agenda-archives-mode t)
  7236. (format "Trees with :%s: tag and all active archive files are included"
  7237. org-archive-tag)))))
  7238. (defun org-agenda-toggle-diary ()
  7239. "Toggle diary inclusion in an agenda buffer."
  7240. (interactive)
  7241. (org-agenda-check-type t 'agenda)
  7242. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7243. (org-agenda-redo)
  7244. (org-agenda-set-mode-name)
  7245. (message "Diary inclusion turned %s"
  7246. (if org-agenda-include-diary "on" "off")))
  7247. (defun org-agenda-toggle-deadlines ()
  7248. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7249. (interactive)
  7250. (org-agenda-check-type t 'agenda)
  7251. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7252. (org-agenda-redo)
  7253. (org-agenda-set-mode-name)
  7254. (message "Deadlines inclusion turned %s"
  7255. (if org-agenda-include-deadlines "on" "off")))
  7256. (defun org-agenda-toggle-time-grid ()
  7257. "Toggle time grid in an agenda buffer."
  7258. (interactive)
  7259. (org-agenda-check-type t 'agenda)
  7260. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7261. (org-agenda-redo)
  7262. (org-agenda-set-mode-name)
  7263. (message "Time-grid turned %s"
  7264. (if org-agenda-use-time-grid "on" "off")))
  7265. (defun org-agenda-set-mode-name ()
  7266. "Set the mode name to indicate all the small mode settings."
  7267. (setq mode-name
  7268. (list "Org-Agenda"
  7269. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7270. " "
  7271. '(:eval (org-agenda-span-name org-agenda-current-span))
  7272. (if org-agenda-follow-mode " Follow" "")
  7273. (if org-agenda-entry-text-mode " ETxt" "")
  7274. (if org-agenda-include-diary " Diary" "")
  7275. (if org-agenda-include-deadlines " Ddl" "")
  7276. (if org-agenda-use-time-grid " Grid" "")
  7277. (if (and (boundp 'org-habit-show-habits)
  7278. org-habit-show-habits) " Habit" "")
  7279. (cond
  7280. ((consp org-agenda-show-log) " LogAll")
  7281. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7282. (org-agenda-show-log " Log")
  7283. (t ""))
  7284. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7285. :preset-filter))
  7286. '(:eval (org-propertize
  7287. (concat " <"
  7288. (mapconcat
  7289. 'identity
  7290. (append
  7291. (get 'org-agenda-category-filter :preset-filter)
  7292. org-agenda-category-filter)
  7293. "")
  7294. ">")
  7295. 'face 'org-agenda-filter-category
  7296. 'help-echo "Category used in filtering"))
  7297. "")
  7298. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7299. :preset-filter))
  7300. '(:eval (org-propertize
  7301. (concat " {"
  7302. (mapconcat
  7303. 'identity
  7304. (append
  7305. (get 'org-agenda-tag-filter :preset-filter)
  7306. org-agenda-tag-filter)
  7307. "")
  7308. "}")
  7309. 'face 'org-agenda-filter-tags
  7310. 'help-echo "Tags used in filtering"))
  7311. "")
  7312. (if org-agenda-archives-mode
  7313. (if (eq org-agenda-archives-mode t)
  7314. " Archives"
  7315. (format " :%s:" org-archive-tag))
  7316. "")
  7317. (if org-agenda-clockreport-mode
  7318. (if (eq org-agenda-clockreport-mode 'with-filter)
  7319. " Clock{}" " Clock")
  7320. "")))
  7321. (force-mode-line-update))
  7322. (define-obsolete-function-alias
  7323. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7324. (defun org-agenda-update-agenda-type ()
  7325. "Update the agenda type after each command."
  7326. (setq org-agenda-type
  7327. (or (get-text-property (point) 'org-agenda-type)
  7328. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7329. (defun org-agenda-next-line ()
  7330. "Move cursor to the next line, and show if follow mode is active."
  7331. (interactive)
  7332. (call-interactively 'next-line)
  7333. (org-agenda-do-context-action))
  7334. (defun org-agenda-previous-line ()
  7335. "Move cursor to the previous line, and show if follow-mode is active."
  7336. (interactive)
  7337. (call-interactively 'previous-line)
  7338. (org-agenda-do-context-action))
  7339. (defun org-agenda-next-item (n)
  7340. "Move cursor to next agenda item."
  7341. (interactive "p")
  7342. (let ((col (current-column)))
  7343. (dotimes (c n)
  7344. (when (next-single-property-change (point-at-eol) 'org-marker)
  7345. (move-end-of-line 1)
  7346. (goto-char (next-single-property-change (point) 'org-marker))))
  7347. (org-move-to-column col))
  7348. (org-agenda-do-context-action))
  7349. (defun org-agenda-previous-item (n)
  7350. "Move cursor to next agenda item."
  7351. (interactive "p")
  7352. (dotimes (c n)
  7353. (let ((col (current-column))
  7354. (goto (save-excursion
  7355. (move-end-of-line 0)
  7356. (previous-single-property-change (point) 'org-marker))))
  7357. (if goto (goto-char goto))
  7358. (org-move-to-column col)))
  7359. (org-agenda-do-context-action))
  7360. (defun org-agenda-do-context-action ()
  7361. "Show outline path and, maybe, follow mode window."
  7362. (let ((m (org-get-at-bol 'org-marker)))
  7363. (when (and (markerp m) (marker-buffer m))
  7364. (and org-agenda-follow-mode
  7365. (if org-agenda-follow-indirect
  7366. (org-agenda-tree-to-indirect-buffer nil)
  7367. (org-agenda-show)))
  7368. (and org-agenda-show-outline-path
  7369. (org-with-point-at m (org-display-outline-path t))))))
  7370. (defun org-agenda-show-tags ()
  7371. "Show the tags applicable to the current item."
  7372. (interactive)
  7373. (let* ((tags (org-get-at-bol 'tags)))
  7374. (if tags
  7375. (message "Tags are :%s:"
  7376. (org-no-properties (mapconcat 'identity tags ":")))
  7377. (message "No tags associated with this line"))))
  7378. (defun org-agenda-goto (&optional highlight)
  7379. "Go to the Org-mode file which contains the item at point."
  7380. (interactive)
  7381. (let* ((marker (or (org-get-at-bol 'org-marker)
  7382. (org-agenda-error)))
  7383. (buffer (marker-buffer marker))
  7384. (pos (marker-position marker)))
  7385. (switch-to-buffer-other-window buffer)
  7386. (widen)
  7387. (push-mark)
  7388. (goto-char pos)
  7389. (when (derived-mode-p 'org-mode)
  7390. (org-show-context 'agenda)
  7391. (save-excursion
  7392. (and (outline-next-heading)
  7393. (org-flag-heading nil)))) ; show the next heading
  7394. (when (outline-invisible-p)
  7395. (show-entry)) ; display invisible text
  7396. (recenter (/ (window-height) 2))
  7397. (run-hooks 'org-agenda-after-show-hook)
  7398. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7399. (defvar org-agenda-after-show-hook nil
  7400. "Normal hook run after an item has been shown from the agenda.
  7401. Point is in the buffer where the item originated.")
  7402. (defun org-agenda-kill ()
  7403. "Kill the entry or subtree belonging to the current agenda entry."
  7404. (interactive)
  7405. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7406. (let* ((bufname-orig (buffer-name))
  7407. (marker (or (org-get-at-bol 'org-marker)
  7408. (org-agenda-error)))
  7409. (buffer (marker-buffer marker))
  7410. (pos (marker-position marker))
  7411. (type (org-get-at-bol 'type))
  7412. dbeg dend (n 0) conf)
  7413. (org-with-remote-undo buffer
  7414. (with-current-buffer buffer
  7415. (save-excursion
  7416. (goto-char pos)
  7417. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7418. (setq dbeg (progn (org-back-to-heading t) (point))
  7419. dend (org-end-of-subtree t t))
  7420. (setq dbeg (point-at-bol)
  7421. dend (min (point-max) (1+ (point-at-eol)))))
  7422. (goto-char dbeg)
  7423. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7424. (setq conf (or (eq t org-agenda-confirm-kill)
  7425. (and (numberp org-agenda-confirm-kill)
  7426. (> n org-agenda-confirm-kill))))
  7427. (and conf
  7428. (not (y-or-n-p
  7429. (format "Delete entry with %d lines in buffer \"%s\"? "
  7430. n (buffer-name buffer))))
  7431. (error "Abort"))
  7432. (let ((org-agenda-buffer-name bufname-orig))
  7433. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7434. (with-current-buffer buffer (delete-region dbeg dend))
  7435. (message "Agenda item and source killed"))))
  7436. (defvar org-archive-default-command) ; defined in org-archive.el
  7437. (defun org-agenda-archive-default ()
  7438. "Archive the entry or subtree belonging to the current agenda entry."
  7439. (interactive)
  7440. (require 'org-archive)
  7441. (org-agenda-archive-with org-archive-default-command))
  7442. (defun org-agenda-archive-default-with-confirmation ()
  7443. "Archive the entry or subtree belonging to the current agenda entry."
  7444. (interactive)
  7445. (require 'org-archive)
  7446. (org-agenda-archive-with org-archive-default-command 'confirm))
  7447. (defun org-agenda-archive ()
  7448. "Archive the entry or subtree belonging to the current agenda entry."
  7449. (interactive)
  7450. (org-agenda-archive-with 'org-archive-subtree))
  7451. (defun org-agenda-archive-to-archive-sibling ()
  7452. "Move the entry to the archive sibling."
  7453. (interactive)
  7454. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7455. (defun org-agenda-archive-with (cmd &optional confirm)
  7456. "Move the entry to the archive sibling."
  7457. (interactive)
  7458. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7459. (let* ((bufname-orig (buffer-name))
  7460. (marker (or (org-get-at-bol 'org-marker)
  7461. (org-agenda-error)))
  7462. (buffer (marker-buffer marker))
  7463. (pos (marker-position marker)))
  7464. (org-with-remote-undo buffer
  7465. (with-current-buffer buffer
  7466. (if (derived-mode-p 'org-mode)
  7467. (if (and confirm
  7468. (not (y-or-n-p "Archive this subtree or entry? ")))
  7469. (error "Abort")
  7470. (save-excursion
  7471. (goto-char pos)
  7472. (let ((org-agenda-buffer-name bufname-orig))
  7473. (org-remove-subtree-entries-from-agenda))
  7474. (org-back-to-heading t)
  7475. (funcall cmd)))
  7476. (error "Archiving works only in Org-mode files"))))))
  7477. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7478. "Remove all lines in the agenda that correspond to a given subtree.
  7479. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7480. If this information is not given, the function uses the tree at point."
  7481. (let ((buf (or buf (current-buffer))) m p)
  7482. (save-excursion
  7483. (unless (and beg end)
  7484. (org-back-to-heading t)
  7485. (setq beg (point))
  7486. (org-end-of-subtree t)
  7487. (setq end (point)))
  7488. (set-buffer (get-buffer org-agenda-buffer-name))
  7489. (save-excursion
  7490. (goto-char (point-max))
  7491. (beginning-of-line 1)
  7492. (while (not (bobp))
  7493. (when (and (setq m (org-get-at-bol 'org-marker))
  7494. (equal buf (marker-buffer m))
  7495. (setq p (marker-position m))
  7496. (>= p beg)
  7497. (< p end))
  7498. (let ((inhibit-read-only t))
  7499. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7500. (beginning-of-line 0))))))
  7501. (defun org-agenda-refile (&optional goto rfloc no-update)
  7502. "Refile the item at point."
  7503. (interactive "P")
  7504. (if (equal goto '(16))
  7505. (org-refile-goto-last-stored)
  7506. (let* ((buffer-orig (buffer-name))
  7507. (marker (or (org-get-at-bol 'org-hd-marker)
  7508. (org-agenda-error)))
  7509. (buffer (marker-buffer marker))
  7510. (pos (marker-position marker))
  7511. (rfloc (or rfloc
  7512. (org-refile-get-location
  7513. (if goto "Goto" "Refile to") buffer
  7514. org-refile-allow-creating-parent-nodes))))
  7515. (with-current-buffer buffer
  7516. (save-excursion
  7517. (save-restriction
  7518. (widen)
  7519. (goto-char marker)
  7520. (let ((org-agenda-buffer-name buffer-orig))
  7521. (org-remove-subtree-entries-from-agenda))
  7522. (org-refile goto buffer rfloc)))))
  7523. (unless no-update (org-agenda-redo))))
  7524. (defun org-agenda-open-link (&optional arg)
  7525. "Open the link(s) in the current entry, if any.
  7526. This looks for a link in the displayed line in the agenda.
  7527. It also looks at the text of the entry itself."
  7528. (interactive "P")
  7529. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7530. (org-get-at-bol 'org-marker)))
  7531. (buffer (and marker (marker-buffer marker)))
  7532. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7533. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7534. (lk0 (car lkall))
  7535. (lk (if (stringp lk0) (list lk0) lk0))
  7536. (lkend (cdr lkall))
  7537. trg)
  7538. (cond
  7539. ((and buffer lk)
  7540. (mapcar (lambda(l)
  7541. (with-current-buffer buffer
  7542. (setq trg (and (string-match org-bracket-link-regexp l)
  7543. (match-string 1 l)))
  7544. (if (or (not trg) (string-match org-any-link-re trg))
  7545. (save-excursion
  7546. (save-restriction
  7547. (widen)
  7548. (goto-char marker)
  7549. (when (search-forward l nil lkend)
  7550. (goto-char (match-beginning 0))
  7551. (org-open-at-point))))
  7552. ;; This is an internal link, widen the buffer
  7553. (switch-to-buffer-other-window buffer)
  7554. (widen)
  7555. (goto-char marker)
  7556. (when (search-forward l nil lkend)
  7557. (goto-char (match-beginning 0))
  7558. (org-open-at-point)))))
  7559. lk))
  7560. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7561. (save-excursion
  7562. (beginning-of-line 1)
  7563. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7564. (org-open-link-from-string (match-string 1)))
  7565. (t (message "No link to open here")))))
  7566. (defun org-agenda-copy-local-variable (var)
  7567. "Get a variable from a referenced buffer and install it here."
  7568. (let ((m (org-get-at-bol 'org-marker)))
  7569. (when (and m (buffer-live-p (marker-buffer m)))
  7570. (org-set-local var (with-current-buffer (marker-buffer m)
  7571. (symbol-value var))))))
  7572. (defun org-agenda-switch-to (&optional delete-other-windows)
  7573. "Go to the Org-mode file which contains the item at point."
  7574. (interactive)
  7575. (if (and org-return-follows-link
  7576. (not (org-get-at-bol 'org-marker))
  7577. (org-in-regexp org-bracket-link-regexp))
  7578. (org-open-link-from-string (match-string 0))
  7579. (let* ((marker (or (org-get-at-bol 'org-marker)
  7580. (org-agenda-error)))
  7581. (buffer (marker-buffer marker))
  7582. (pos (marker-position marker)))
  7583. (org-pop-to-buffer-same-window buffer)
  7584. (and delete-other-windows (delete-other-windows))
  7585. (widen)
  7586. (goto-char pos)
  7587. (when (derived-mode-p 'org-mode)
  7588. (org-show-context 'agenda)
  7589. (save-excursion
  7590. (and (outline-next-heading)
  7591. (org-flag-heading nil))) ; show the next heading
  7592. (when (outline-invisible-p)
  7593. (show-entry)) ; display invisible text
  7594. (run-hooks 'org-agenda-after-show-hook)))))
  7595. (defun org-agenda-goto-mouse (ev)
  7596. "Go to the Org-mode file which contains the item at the mouse click."
  7597. (interactive "e")
  7598. (mouse-set-point ev)
  7599. (org-agenda-goto))
  7600. (defun org-agenda-show (&optional full-entry)
  7601. "Display the Org-mode file which contains the item at point.
  7602. With prefix argument FULL-ENTRY, make the entire entry visible
  7603. if it was hidden in the outline."
  7604. (interactive "P")
  7605. (let ((win (selected-window)))
  7606. (if full-entry
  7607. (let ((org-show-entry-below t))
  7608. (org-agenda-goto t))
  7609. (org-agenda-goto t))
  7610. (select-window win)))
  7611. (defvar org-agenda-show-window nil)
  7612. (defun org-agenda-show-and-scroll-up (&optional arg)
  7613. "Display the Org-mode file which contains the item at point.
  7614. When called repeatedly, scroll the window that is displaying the buffer.
  7615. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7616. `show-subtree' to display the item, so that drawers and logbooks stay
  7617. folded."
  7618. (interactive "P")
  7619. (let ((win (selected-window)))
  7620. (if (and (window-live-p org-agenda-show-window)
  7621. (eq this-command last-command))
  7622. (progn
  7623. (select-window org-agenda-show-window)
  7624. (ignore-errors (scroll-up)))
  7625. (org-agenda-goto t)
  7626. (if arg (org-show-entry) (show-subtree))
  7627. (setq org-agenda-show-window (selected-window)))
  7628. (select-window win)))
  7629. (defun org-agenda-show-scroll-down ()
  7630. "Scroll down the window showing the agenda."
  7631. (interactive)
  7632. (let ((win (selected-window)))
  7633. (when (window-live-p org-agenda-show-window)
  7634. (select-window org-agenda-show-window)
  7635. (ignore-errors (scroll-down))
  7636. (select-window win))))
  7637. (defun org-agenda-show-1 (&optional more)
  7638. "Display the Org-mode file which contains the item at point.
  7639. The prefix arg selects the amount of information to display:
  7640. 0 hide the subtree
  7641. 1 just show the entry according to defaults.
  7642. 2 show the children view
  7643. 3 show the subtree view
  7644. 4 show the entire subtree and any LOGBOOK drawers
  7645. 5 show the entire subtree and any drawers
  7646. With prefix argument FULL-ENTRY, make the entire entry visible
  7647. if it was hidden in the outline."
  7648. (interactive "p")
  7649. (let ((win (selected-window)))
  7650. (org-agenda-goto t)
  7651. (org-recenter-heading 1)
  7652. (cond
  7653. ((= more 0)
  7654. (hide-subtree)
  7655. (save-excursion
  7656. (org-back-to-heading)
  7657. (run-hook-with-args 'org-cycle-hook 'folded))
  7658. (message "Remote: FOLDED"))
  7659. ((and (org-called-interactively-p 'any) (= more 1))
  7660. (message "Remote: show with default settings"))
  7661. ((= more 2)
  7662. (show-entry)
  7663. (show-children)
  7664. (save-excursion
  7665. (org-back-to-heading)
  7666. (run-hook-with-args 'org-cycle-hook 'children))
  7667. (message "Remote: CHILDREN"))
  7668. ((= more 3)
  7669. (show-subtree)
  7670. (save-excursion
  7671. (org-back-to-heading)
  7672. (run-hook-with-args 'org-cycle-hook 'subtree))
  7673. (message "Remote: SUBTREE"))
  7674. ((= more 4)
  7675. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7676. (org-drawer-regexp
  7677. (concat "^[ \t]*:\\("
  7678. (mapconcat 'regexp-quote org-drawers "\\|")
  7679. "\\):[ \t]*$")))
  7680. (show-subtree)
  7681. (save-excursion
  7682. (org-back-to-heading)
  7683. (org-cycle-hide-drawers 'subtree)))
  7684. (message "Remote: SUBTREE AND LOGBOOK"))
  7685. ((> more 4)
  7686. (show-subtree)
  7687. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7688. (select-window win)))
  7689. (defun org-recenter-heading (n)
  7690. (save-excursion
  7691. (org-back-to-heading)
  7692. (recenter n)))
  7693. (defvar org-agenda-cycle-counter nil)
  7694. (defun org-agenda-cycle-show (&optional n)
  7695. "Show the current entry in another window, with default settings.
  7696. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7697. When use repeatedly in immediate succession, the remote entry will cycle
  7698. through visibility
  7699. children -> subtree -> folded
  7700. When called with a numeric prefix arg, that arg will be passed through to
  7701. `org-agenda-show-1'. For the interpretation of that argument, see the
  7702. docstring of `org-agenda-show-1'."
  7703. (interactive "P")
  7704. (if (integerp n)
  7705. (setq org-agenda-cycle-counter n)
  7706. (if (not (eq last-command this-command))
  7707. (setq org-agenda-cycle-counter 1)
  7708. (if (equal org-agenda-cycle-counter 0)
  7709. (setq org-agenda-cycle-counter 2)
  7710. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7711. (if (> org-agenda-cycle-counter 3)
  7712. (setq org-agenda-cycle-counter 0)))))
  7713. (org-agenda-show-1 org-agenda-cycle-counter))
  7714. (defun org-agenda-recenter (arg)
  7715. "Display the Org-mode file which contains the item at point and recenter."
  7716. (interactive "P")
  7717. (let ((win (selected-window)))
  7718. (org-agenda-goto t)
  7719. (recenter arg)
  7720. (select-window win)))
  7721. (defun org-agenda-show-mouse (ev)
  7722. "Display the Org-mode file which contains the item at the mouse click."
  7723. (interactive "e")
  7724. (mouse-set-point ev)
  7725. (org-agenda-show))
  7726. (defun org-agenda-check-no-diary ()
  7727. "Check if the entry is a diary link and abort if yes."
  7728. (if (org-get-at-bol 'org-agenda-diary-link)
  7729. (org-agenda-error)))
  7730. (defun org-agenda-error ()
  7731. (error "Command not allowed in this line"))
  7732. (defun org-agenda-tree-to-indirect-buffer (arg)
  7733. "Show the subtree corresponding to the current entry in an indirect buffer.
  7734. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7735. With a numerical prefix ARG, go up to this level and then take that tree.
  7736. With a negative numeric ARG, go up by this number of levels.
  7737. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7738. use the dedicated frame)."
  7739. (interactive "P")
  7740. (if current-prefix-arg
  7741. (org-agenda-do-tree-to-indirect-buffer arg)
  7742. (let ((agenda-buffer (buffer-name))
  7743. (agenda-window (selected-window))
  7744. (indirect-window
  7745. (and org-last-indirect-buffer
  7746. (get-buffer-window org-last-indirect-buffer))))
  7747. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7748. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7749. (eq org-indirect-buffer-display 'dedicated-frame))
  7750. (unwind-protect
  7751. (unless (and indirect-window (window-live-p indirect-window))
  7752. (setq indirect-window (split-window agenda-window)))
  7753. (and indirect-window (select-window indirect-window))
  7754. (switch-to-buffer org-last-indirect-buffer :norecord)
  7755. (fit-window-to-buffer indirect-window)))
  7756. (select-window (get-buffer-window agenda-buffer)))))
  7757. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7758. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7759. (org-agenda-check-no-diary)
  7760. (let* ((marker (or (org-get-at-bol 'org-marker)
  7761. (org-agenda-error)))
  7762. (buffer (marker-buffer marker))
  7763. (pos (marker-position marker)))
  7764. (with-current-buffer buffer
  7765. (save-excursion
  7766. (goto-char pos)
  7767. (funcall 'org-tree-to-indirect-buffer arg)))))
  7768. (defvar org-last-heading-marker (make-marker)
  7769. "Marker pointing to the headline that last changed its TODO state
  7770. by a remote command from the agenda.")
  7771. (defun org-agenda-todo-nextset ()
  7772. "Switch TODO entry to next sequence."
  7773. (interactive)
  7774. (org-agenda-todo 'nextset))
  7775. (defun org-agenda-todo-previousset ()
  7776. "Switch TODO entry to previous sequence."
  7777. (interactive)
  7778. (org-agenda-todo 'previousset))
  7779. (defun org-agenda-todo (&optional arg)
  7780. "Cycle TODO state of line at point, also in Org-mode file.
  7781. This changes the line at point, all other lines in the agenda referring to
  7782. the same tree node, and the headline of the tree node in the Org-mode file."
  7783. (interactive "P")
  7784. (org-agenda-check-no-diary)
  7785. (let* ((col (current-column))
  7786. (marker (or (org-get-at-bol 'org-marker)
  7787. (org-agenda-error)))
  7788. (buffer (marker-buffer marker))
  7789. (pos (marker-position marker))
  7790. (hdmarker (org-get-at-bol 'org-hd-marker))
  7791. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7792. (inhibit-read-only t)
  7793. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7794. (org-with-remote-undo buffer
  7795. (with-current-buffer buffer
  7796. (widen)
  7797. (goto-char pos)
  7798. (org-show-context 'agenda)
  7799. (save-excursion
  7800. (and (outline-next-heading)
  7801. (org-flag-heading nil))) ; show the next heading
  7802. (let ((current-prefix-arg arg))
  7803. (call-interactively 'org-todo))
  7804. (and (bolp) (forward-char 1))
  7805. (setq newhead (org-get-heading))
  7806. (when (and (org-bound-and-true-p
  7807. org-agenda-headline-snapshot-before-repeat)
  7808. (not (equal org-agenda-headline-snapshot-before-repeat
  7809. newhead))
  7810. todayp)
  7811. (setq newhead org-agenda-headline-snapshot-before-repeat
  7812. just-one t))
  7813. (save-excursion
  7814. (org-back-to-heading)
  7815. (move-marker org-last-heading-marker (point))))
  7816. (beginning-of-line 1)
  7817. (save-excursion
  7818. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7819. (org-move-to-column col))))
  7820. (defun org-agenda-add-note (&optional arg)
  7821. "Add a time-stamped note to the entry at point."
  7822. (interactive "P")
  7823. (org-agenda-check-no-diary)
  7824. (let* ((marker (or (org-get-at-bol 'org-marker)
  7825. (org-agenda-error)))
  7826. (buffer (marker-buffer marker))
  7827. (pos (marker-position marker))
  7828. (hdmarker (org-get-at-bol 'org-hd-marker))
  7829. (inhibit-read-only t))
  7830. (with-current-buffer buffer
  7831. (widen)
  7832. (goto-char pos)
  7833. (org-show-context 'agenda)
  7834. (save-excursion
  7835. (and (outline-next-heading)
  7836. (org-flag-heading nil))) ; show the next heading
  7837. (org-add-note))))
  7838. (defun org-agenda-change-all-lines (newhead hdmarker
  7839. &optional fixface just-this)
  7840. "Change all lines in the agenda buffer which match HDMARKER.
  7841. The new content of the line will be NEWHEAD (as modified by
  7842. `org-agenda-format-item'). HDMARKER is checked with
  7843. `equal' against all `org-hd-marker' text properties in the file.
  7844. If FIXFACE is non-nil, the face of each item is modified according to
  7845. the new TODO state.
  7846. If JUST-THIS is non-nil, change just the current line, not all.
  7847. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7848. (let* ((inhibit-read-only t)
  7849. (line (org-current-line))
  7850. (org-agenda-buffer (current-buffer))
  7851. (thetags (with-current-buffer (marker-buffer hdmarker)
  7852. (save-excursion (save-restriction (widen)
  7853. (goto-char hdmarker)
  7854. (org-get-tags-at)))))
  7855. props m pl undone-face done-face finish new dotime level cat tags)
  7856. (save-excursion
  7857. (goto-char (point-max))
  7858. (beginning-of-line 1)
  7859. (while (not finish)
  7860. (setq finish (bobp))
  7861. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7862. (or (not just-this) (= (org-current-line) line))
  7863. (equal m hdmarker))
  7864. (setq props (text-properties-at (point))
  7865. dotime (org-get-at-bol 'dotime)
  7866. cat (org-get-at-bol 'org-category)
  7867. level (org-get-at-bol 'level)
  7868. tags thetags
  7869. new
  7870. (let ((org-prefix-format-compiled
  7871. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7872. org-prefix-format-compiled))
  7873. (extra (org-get-at-bol 'extra)))
  7874. (with-current-buffer (marker-buffer hdmarker)
  7875. (save-excursion
  7876. (save-restriction
  7877. (widen)
  7878. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7879. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7880. undone-face (org-get-at-bol 'undone-face)
  7881. done-face (org-get-at-bol 'done-face))
  7882. (beginning-of-line 1)
  7883. (cond
  7884. ((equal new "")
  7885. (and (looking-at ".*\n?") (replace-match "")))
  7886. ((looking-at ".*")
  7887. (replace-match new t t)
  7888. (beginning-of-line 1)
  7889. (add-text-properties (point-at-bol) (point-at-eol) props)
  7890. (when fixface
  7891. (add-text-properties
  7892. (point-at-bol) (point-at-eol)
  7893. (list 'face
  7894. (if org-last-todo-state-is-todo
  7895. undone-face done-face))))
  7896. (org-agenda-highlight-todo 'line)
  7897. (beginning-of-line 1))
  7898. (t (error "Line update did not work")))
  7899. (save-restriction
  7900. (narrow-to-region (point-at-bol) (point-at-eol))
  7901. (org-agenda-finalize)))
  7902. (beginning-of-line 0)))))
  7903. (defun org-agenda-align-tags (&optional line)
  7904. "Align all tags in agenda items to `org-agenda-tags-column'."
  7905. (let ((inhibit-read-only t) l c)
  7906. (save-excursion
  7907. (goto-char (if line (point-at-bol) (point-min)))
  7908. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7909. (if line (point-at-eol) nil) t)
  7910. (add-text-properties
  7911. (match-beginning 2) (match-end 2)
  7912. (list 'face (delq nil (let ((prop (get-text-property
  7913. (match-beginning 2) 'face)))
  7914. (or (listp prop) (setq prop (list prop)))
  7915. (if (memq 'org-tag prop)
  7916. prop
  7917. (cons 'org-tag prop))))))
  7918. (setq l (- (match-end 2) (match-beginning 2))
  7919. c (if (< org-agenda-tags-column 0)
  7920. (- (abs org-agenda-tags-column) l)
  7921. org-agenda-tags-column))
  7922. (delete-region (match-beginning 1) (match-end 1))
  7923. (goto-char (match-beginning 1))
  7924. (insert (org-add-props
  7925. (make-string (max 1 (- c (current-column))) ?\ )
  7926. (plist-put (copy-sequence (text-properties-at (point)))
  7927. 'face nil))))
  7928. (goto-char (point-min))
  7929. (org-font-lock-add-tag-faces (point-max)))))
  7930. (defun org-agenda-priority-up ()
  7931. "Increase the priority of line at point, also in Org-mode file."
  7932. (interactive)
  7933. (org-agenda-priority 'up))
  7934. (defun org-agenda-priority-down ()
  7935. "Decrease the priority of line at point, also in Org-mode file."
  7936. (interactive)
  7937. (org-agenda-priority 'down))
  7938. (defun org-agenda-priority (&optional force-direction)
  7939. "Set the priority of line at point, also in Org-mode file.
  7940. This changes the line at point, all other lines in the agenda referring to
  7941. the same tree node, and the headline of the tree node in the Org-mode file.
  7942. Called with a universal prefix arg, show the priority instead of setting it."
  7943. (interactive "P")
  7944. (if (equal force-direction '(4))
  7945. (org-show-priority)
  7946. (unless org-enable-priority-commands
  7947. (error "Priority commands are disabled"))
  7948. (org-agenda-check-no-diary)
  7949. (let* ((marker (or (org-get-at-bol 'org-marker)
  7950. (org-agenda-error)))
  7951. (hdmarker (org-get-at-bol 'org-hd-marker))
  7952. (buffer (marker-buffer hdmarker))
  7953. (pos (marker-position hdmarker))
  7954. (inhibit-read-only t)
  7955. newhead)
  7956. (org-with-remote-undo buffer
  7957. (with-current-buffer buffer
  7958. (widen)
  7959. (goto-char pos)
  7960. (org-show-context 'agenda)
  7961. (save-excursion
  7962. (and (outline-next-heading)
  7963. (org-flag-heading nil))) ; show the next heading
  7964. (funcall 'org-priority force-direction)
  7965. (end-of-line 1)
  7966. (setq newhead (org-get-heading)))
  7967. (org-agenda-change-all-lines newhead hdmarker)
  7968. (beginning-of-line 1)))))
  7969. ;; FIXME: should fix the tags property of the agenda line.
  7970. (defun org-agenda-set-tags (&optional tag onoff)
  7971. "Set tags for the current headline."
  7972. (interactive)
  7973. (org-agenda-check-no-diary)
  7974. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7975. (call-interactively 'org-change-tag-in-region)
  7976. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7977. (org-agenda-error)))
  7978. (buffer (marker-buffer hdmarker))
  7979. (pos (marker-position hdmarker))
  7980. (inhibit-read-only t)
  7981. newhead)
  7982. (org-with-remote-undo buffer
  7983. (with-current-buffer buffer
  7984. (widen)
  7985. (goto-char pos)
  7986. (save-excursion
  7987. (org-show-context 'agenda))
  7988. (save-excursion
  7989. (and (outline-next-heading)
  7990. (org-flag-heading nil))) ; show the next heading
  7991. (goto-char pos)
  7992. (if tag
  7993. (org-toggle-tag tag onoff)
  7994. (call-interactively 'org-set-tags))
  7995. (end-of-line 1)
  7996. (setq newhead (org-get-heading)))
  7997. (org-agenda-change-all-lines newhead hdmarker)
  7998. (beginning-of-line 1)))))
  7999. (defun org-agenda-set-property ()
  8000. "Set a property for the current headline."
  8001. (interactive)
  8002. (org-agenda-check-no-diary)
  8003. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8004. (org-agenda-error)))
  8005. (buffer (marker-buffer hdmarker))
  8006. (pos (marker-position hdmarker))
  8007. (inhibit-read-only t)
  8008. newhead)
  8009. (org-with-remote-undo buffer
  8010. (with-current-buffer buffer
  8011. (widen)
  8012. (goto-char pos)
  8013. (save-excursion
  8014. (org-show-context 'agenda))
  8015. (save-excursion
  8016. (and (outline-next-heading)
  8017. (org-flag-heading nil))) ; show the next heading
  8018. (goto-char pos)
  8019. (call-interactively 'org-set-property)))))
  8020. (defun org-agenda-set-effort ()
  8021. "Set the effort property for the current headline."
  8022. (interactive)
  8023. (org-agenda-check-no-diary)
  8024. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8025. (org-agenda-error)))
  8026. (buffer (marker-buffer hdmarker))
  8027. (pos (marker-position hdmarker))
  8028. (inhibit-read-only t)
  8029. newhead)
  8030. (org-with-remote-undo buffer
  8031. (with-current-buffer buffer
  8032. (widen)
  8033. (goto-char pos)
  8034. (save-excursion
  8035. (org-show-context 'agenda))
  8036. (save-excursion
  8037. (and (outline-next-heading)
  8038. (org-flag-heading nil))) ; show the next heading
  8039. (goto-char pos)
  8040. (call-interactively 'org-set-effort)
  8041. (end-of-line 1)
  8042. (setq newhead (org-get-heading)))
  8043. (org-agenda-change-all-lines newhead hdmarker))))
  8044. (defun org-agenda-toggle-archive-tag ()
  8045. "Toggle the archive tag for the current entry."
  8046. (interactive)
  8047. (org-agenda-check-no-diary)
  8048. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8049. (org-agenda-error)))
  8050. (buffer (marker-buffer hdmarker))
  8051. (pos (marker-position hdmarker))
  8052. (inhibit-read-only t)
  8053. newhead)
  8054. (org-with-remote-undo buffer
  8055. (with-current-buffer buffer
  8056. (widen)
  8057. (goto-char pos)
  8058. (org-show-context 'agenda)
  8059. (save-excursion
  8060. (and (outline-next-heading)
  8061. (org-flag-heading nil))) ; show the next heading
  8062. (call-interactively 'org-toggle-archive-tag)
  8063. (end-of-line 1)
  8064. (setq newhead (org-get-heading)))
  8065. (org-agenda-change-all-lines newhead hdmarker)
  8066. (beginning-of-line 1))))
  8067. (defun org-agenda-do-date-later (arg)
  8068. (interactive "P")
  8069. (cond
  8070. ((or (equal arg '(16))
  8071. (memq last-command
  8072. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8073. (setq this-command 'org-agenda-date-later-minutes)
  8074. (org-agenda-date-later-minutes 1))
  8075. ((or (equal arg '(4))
  8076. (memq last-command
  8077. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8078. (setq this-command 'org-agenda-date-later-hours)
  8079. (org-agenda-date-later-hours 1))
  8080. (t
  8081. (org-agenda-date-later (prefix-numeric-value arg)))))
  8082. (defun org-agenda-do-date-earlier (arg)
  8083. (interactive "P")
  8084. (cond
  8085. ((or (equal arg '(16))
  8086. (memq last-command
  8087. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8088. (setq this-command 'org-agenda-date-earlier-minutes)
  8089. (org-agenda-date-earlier-minutes 1))
  8090. ((or (equal arg '(4))
  8091. (memq last-command
  8092. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8093. (setq this-command 'org-agenda-date-earlier-hours)
  8094. (org-agenda-date-earlier-hours 1))
  8095. (t
  8096. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8097. (defun org-agenda-date-later (arg &optional what)
  8098. "Change the date of this item to ARG day(s) later."
  8099. (interactive "p")
  8100. (org-agenda-check-type t 'agenda 'timeline)
  8101. (org-agenda-check-no-diary)
  8102. (let* ((marker (or (org-get-at-bol 'org-marker)
  8103. (org-agenda-error)))
  8104. (buffer (marker-buffer marker))
  8105. (pos (marker-position marker))
  8106. cdate today)
  8107. (org-with-remote-undo buffer
  8108. (with-current-buffer buffer
  8109. (widen)
  8110. (goto-char pos)
  8111. (if (not (org-at-timestamp-p))
  8112. (error "Cannot find time stamp"))
  8113. (when (and org-agenda-move-date-from-past-immediately-to-today
  8114. (equal arg 1)
  8115. (or (not what) (eq what 'day))
  8116. (not (save-match-data (org-at-date-range-p))))
  8117. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8118. cdate (calendar-absolute-from-gregorian
  8119. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8120. today (org-today))
  8121. (if (> today cdate)
  8122. ;; immediately shift to today
  8123. (setq arg (- today cdate))))
  8124. (org-timestamp-change arg (or what 'day))
  8125. (when (and (org-at-date-range-p)
  8126. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8127. (let ((end org-last-changed-timestamp))
  8128. (org-timestamp-change arg (or what 'day))
  8129. (setq org-last-changed-timestamp
  8130. (concat org-last-changed-timestamp "--" end)))))
  8131. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8132. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8133. (defun org-agenda-date-earlier (arg &optional what)
  8134. "Change the date of this item to ARG day(s) earlier."
  8135. (interactive "p")
  8136. (org-agenda-date-later (- arg) what))
  8137. (defun org-agenda-date-later-minutes (arg)
  8138. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8139. (interactive "p")
  8140. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8141. (org-agenda-date-later arg 'minute))
  8142. (defun org-agenda-date-earlier-minutes (arg)
  8143. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8144. (interactive "p")
  8145. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8146. (org-agenda-date-earlier arg 'minute))
  8147. (defun org-agenda-date-later-hours (arg)
  8148. "Change the time of this item, in hour steps."
  8149. (interactive "p")
  8150. (org-agenda-date-later arg 'hour))
  8151. (defun org-agenda-date-earlier-hours (arg)
  8152. "Change the time of this item, in hour steps."
  8153. (interactive "p")
  8154. (org-agenda-date-earlier arg 'hour))
  8155. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8156. "Show new date stamp via text properties."
  8157. ;; We use text properties to make this undoable
  8158. (let ((inhibit-read-only t)
  8159. (buffer-invisibility-spec))
  8160. (setq stamp (concat " " prefix " => " stamp))
  8161. (save-excursion
  8162. (goto-char (point-max))
  8163. (while (not (bobp))
  8164. (when (equal marker (org-get-at-bol 'org-marker))
  8165. (org-move-to-column (- (window-width) (length stamp)) t)
  8166. (org-agenda-fix-tags-filter-overlays-at (point))
  8167. (if (featurep 'xemacs)
  8168. ;; Use `duplicable' property to trigger undo recording
  8169. (let ((ex (make-extent nil nil))
  8170. (gl (make-glyph stamp)))
  8171. (set-glyph-face gl 'secondary-selection)
  8172. (set-extent-properties
  8173. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8174. (insert-extent ex (1- (point)) (point-at-eol)))
  8175. (add-text-properties
  8176. (1- (point)) (point-at-eol)
  8177. (list 'display (org-add-props stamp nil
  8178. 'face 'secondary-selection))))
  8179. (beginning-of-line 1))
  8180. (beginning-of-line 0)))))
  8181. (defun org-agenda-date-prompt (arg)
  8182. "Change the date of this item. Date is prompted for, with default today.
  8183. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8184. be used to request time specification in the time stamp."
  8185. (interactive "P")
  8186. (org-agenda-check-type t 'agenda 'timeline)
  8187. (org-agenda-check-no-diary)
  8188. (let* ((marker (or (org-get-at-bol 'org-marker)
  8189. (org-agenda-error)))
  8190. (buffer (marker-buffer marker))
  8191. (pos (marker-position marker)))
  8192. (org-with-remote-undo buffer
  8193. (with-current-buffer buffer
  8194. (widen)
  8195. (goto-char pos)
  8196. (if (not (org-at-timestamp-p t))
  8197. (error "Cannot find time stamp"))
  8198. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8199. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8200. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8201. (defun org-agenda-schedule (arg &optional time)
  8202. "Schedule the item at point.
  8203. ARG is passed through to `org-schedule'."
  8204. (interactive "P")
  8205. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8206. (org-agenda-check-no-diary)
  8207. (let* ((marker (or (org-get-at-bol 'org-marker)
  8208. (org-agenda-error)))
  8209. (type (marker-insertion-type marker))
  8210. (buffer (marker-buffer marker))
  8211. (pos (marker-position marker))
  8212. (org-insert-labeled-timestamps-at-point nil)
  8213. ts)
  8214. (set-marker-insertion-type marker t)
  8215. (org-with-remote-undo buffer
  8216. (with-current-buffer buffer
  8217. (widen)
  8218. (goto-char pos)
  8219. (setq ts (org-schedule arg time)))
  8220. (org-agenda-show-new-time marker ts "S"))
  8221. (message "%s" ts)))
  8222. (defun org-agenda-deadline (arg &optional time)
  8223. "Schedule the item at point.
  8224. ARG is passed through to `org-deadline'."
  8225. (interactive "P")
  8226. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8227. (org-agenda-check-no-diary)
  8228. (let* ((marker (or (org-get-at-bol 'org-marker)
  8229. (org-agenda-error)))
  8230. (buffer (marker-buffer marker))
  8231. (pos (marker-position marker))
  8232. (org-insert-labeled-timestamps-at-point nil)
  8233. ts)
  8234. (org-with-remote-undo buffer
  8235. (with-current-buffer buffer
  8236. (widen)
  8237. (goto-char pos)
  8238. (setq ts (org-deadline arg time)))
  8239. (org-agenda-show-new-time marker ts "D"))
  8240. (message "%s" ts)))
  8241. (defun org-agenda-clock-in (&optional arg)
  8242. "Start the clock on the currently selected item."
  8243. (interactive "P")
  8244. (org-agenda-check-no-diary)
  8245. (if (equal arg '(4))
  8246. (org-clock-in arg)
  8247. (let* ((marker (or (org-get-at-bol 'org-marker)
  8248. (org-agenda-error)))
  8249. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  8250. marker))
  8251. (pos (marker-position marker))
  8252. newhead)
  8253. (org-with-remote-undo (marker-buffer marker)
  8254. (with-current-buffer (marker-buffer marker)
  8255. (widen)
  8256. (goto-char pos)
  8257. (org-show-context 'agenda)
  8258. (org-show-entry)
  8259. (org-cycle-hide-drawers 'children)
  8260. (org-clock-in arg)
  8261. (setq newhead (org-get-heading)))
  8262. (org-agenda-change-all-lines newhead hdmarker)))))
  8263. (defun org-agenda-clock-out ()
  8264. "Stop the currently running clock."
  8265. (interactive)
  8266. (unless (marker-buffer org-clock-marker)
  8267. (error "No running clock"))
  8268. (let ((marker (make-marker)) newhead)
  8269. (org-with-remote-undo (marker-buffer org-clock-marker)
  8270. (with-current-buffer (marker-buffer org-clock-marker)
  8271. (save-excursion
  8272. (save-restriction
  8273. (widen)
  8274. (goto-char org-clock-marker)
  8275. (org-back-to-heading t)
  8276. (move-marker marker (point))
  8277. (org-clock-out)
  8278. (setq newhead (org-get-heading))))))
  8279. (org-agenda-change-all-lines newhead marker)
  8280. (move-marker marker nil)))
  8281. (defun org-agenda-clock-cancel (&optional arg)
  8282. "Cancel the currently running clock."
  8283. (interactive "P")
  8284. (unless (marker-buffer org-clock-marker)
  8285. (error "No running clock"))
  8286. (org-with-remote-undo (marker-buffer org-clock-marker)
  8287. (org-clock-cancel)))
  8288. (defun org-agenda-clock-goto ()
  8289. "Jump to the currently clocked in task within the agenda.
  8290. If the currently clocked in task is not listed in the agenda
  8291. buffer, display it in another window."
  8292. (interactive)
  8293. (let (pos)
  8294. (mapc (lambda (o)
  8295. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8296. (setq pos (overlay-start o))))
  8297. (overlays-in (point-min) (point-max)))
  8298. (cond (pos (goto-char pos))
  8299. ;; If the currently clocked entry is not in the agenda
  8300. ;; buffer, we visit it in another window:
  8301. (org-clock-current-task
  8302. (org-switch-to-buffer-other-window (org-clock-goto)))
  8303. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8304. (defun org-agenda-diary-entry-in-org-file ()
  8305. "Make a diary entry in the file `org-agenda-diary-file'."
  8306. (let (d1 d2 char (text "") dp1 dp2)
  8307. (if (equal (buffer-name) "*Calendar*")
  8308. (setq d1 (calendar-cursor-to-date t)
  8309. d2 (car calendar-mark-ring))
  8310. (setq dp1 (get-text-property (point-at-bol) 'day))
  8311. (unless dp1 (error "No date defined in current line"))
  8312. (setq d1 (calendar-gregorian-from-absolute dp1)
  8313. d2 (and (ignore-errors (mark))
  8314. (save-excursion
  8315. (goto-char (mark))
  8316. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8317. (calendar-gregorian-from-absolute dp2))))
  8318. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8319. (setq char (read-char-exclusive))
  8320. (cond
  8321. ((equal char ?d)
  8322. (setq text (read-string "Day entry: "))
  8323. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8324. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8325. ((equal char ?a)
  8326. (setq d1 (list (car d1) (nth 1 d1)
  8327. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8328. (nth 2 d1))))
  8329. (setq text (read-string "Anniversary (use %d to show years): "))
  8330. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8331. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8332. ((equal char ?b)
  8333. (setq text (read-string "Block entry: "))
  8334. (unless (and d1 d2 (not (equal d1 d2)))
  8335. (error "No block of days selected"))
  8336. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8337. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8338. ((equal char ?j)
  8339. (org-switch-to-buffer-other-window
  8340. (find-file-noselect org-agenda-diary-file))
  8341. (require 'org-datetree)
  8342. (org-datetree-find-date-create d1)
  8343. (org-reveal t))
  8344. (t (error "Invalid selection character `%c'" char)))))
  8345. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8346. "Where in `org-agenda-diary-file' should new entries be added?
  8347. Valid values:
  8348. date-tree in the date tree, as child of the date
  8349. top-level as top-level entries at the end of the file."
  8350. :group 'org-agenda
  8351. :type '(choice
  8352. (const :tag "in a date tree" date-tree)
  8353. (const :tag "as top level at end of file" top-level)))
  8354. (defcustom org-agenda-insert-diary-extract-time nil
  8355. "Non-nil means extract any time specification from the diary entry."
  8356. :group 'org-agenda
  8357. :version "24.1"
  8358. :type 'boolean)
  8359. (defcustom org-agenda-bulk-mark-char ">"
  8360. "A single-character string to be used as the bulk mark."
  8361. :group 'org-agenda
  8362. :version "24.1"
  8363. :type 'string)
  8364. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8365. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8366. If TEXT is not empty, it will become the headline of the new entry, and
  8367. the resulting entry will not be shown. When TEXT is empty, switch to
  8368. `org-agenda-diary-file' and let the user finish the entry there."
  8369. (let ((cw (current-window-configuration)))
  8370. (org-switch-to-buffer-other-window
  8371. (find-file-noselect org-agenda-diary-file))
  8372. (widen)
  8373. (goto-char (point-min))
  8374. (cond
  8375. ((eq type 'anniversary)
  8376. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8377. (progn
  8378. (or (org-at-heading-p t)
  8379. (progn
  8380. (outline-next-heading)
  8381. (insert "* Anniversaries\n\n")
  8382. (beginning-of-line -1)))))
  8383. (outline-next-heading)
  8384. (org-back-over-empty-lines)
  8385. (backward-char 1)
  8386. (insert "\n")
  8387. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8388. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8389. ((eq type 'day)
  8390. (let ((org-prefix-has-time t)
  8391. (org-agenda-time-leading-zero t)
  8392. fmt time time2)
  8393. (if org-agenda-insert-diary-extract-time
  8394. ;; Use org-agenda-format-item to parse text for a time-range and
  8395. ;; remove it. FIXME: This is a hack, we should refactor
  8396. ;; that function to make time extraction available separately
  8397. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8398. time (get-text-property 0 'time fmt)
  8399. time2 (if (> (length time) 0)
  8400. ;; split-string removes trailing ...... if
  8401. ;; no end time given. First space
  8402. ;; separates time from date.
  8403. (concat " " (car (split-string time "\\.")))
  8404. nil)
  8405. text (get-text-property 0 'txt fmt)))
  8406. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8407. (org-agenda-insert-diary-as-top-level text)
  8408. (require 'org-datetree)
  8409. (org-datetree-find-date-create d1)
  8410. (org-agenda-insert-diary-make-new-entry text))
  8411. (org-insert-time-stamp (org-time-from-absolute
  8412. (calendar-absolute-from-gregorian d1))
  8413. nil nil nil nil time2))
  8414. (end-of-line 0))
  8415. ((eq type 'block)
  8416. (if (> (calendar-absolute-from-gregorian d1)
  8417. (calendar-absolute-from-gregorian d2))
  8418. (setq d1 (prog1 d2 (setq d2 d1))))
  8419. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8420. (org-agenda-insert-diary-as-top-level text)
  8421. (require 'org-datetree)
  8422. (org-datetree-find-date-create d1)
  8423. (org-agenda-insert-diary-make-new-entry text))
  8424. (org-insert-time-stamp (org-time-from-absolute
  8425. (calendar-absolute-from-gregorian d1)))
  8426. (insert "--")
  8427. (org-insert-time-stamp (org-time-from-absolute
  8428. (calendar-absolute-from-gregorian d2)))
  8429. (end-of-line 0)))
  8430. (if (string-match "\\S-" text)
  8431. (progn
  8432. (set-window-configuration cw)
  8433. (message "%s entry added to %s"
  8434. (capitalize (symbol-name type))
  8435. (abbreviate-file-name org-agenda-diary-file)))
  8436. (org-reveal t)
  8437. (message "Please finish entry here"))))
  8438. (defun org-agenda-insert-diary-as-top-level (text)
  8439. "Make new entry as a top-level entry at the end of the file.
  8440. Add TEXT as headline, and position the cursor in the second line so that
  8441. a timestamp can be added there."
  8442. (widen)
  8443. (goto-char (point-max))
  8444. (or (bolp) (insert "\n"))
  8445. (insert "* " text "\n")
  8446. (if org-adapt-indentation (org-indent-to-column 2)))
  8447. (defun org-agenda-insert-diary-make-new-entry (text)
  8448. "Make new entry as last child of current entry.
  8449. Add TEXT as headline, and position the cursor in the second line so that
  8450. a timestamp can be added there."
  8451. (let ((org-show-following-heading t)
  8452. (org-show-siblings t)
  8453. (org-show-hierarchy-above t)
  8454. (org-show-entry-below t)
  8455. col)
  8456. (outline-next-heading)
  8457. (org-back-over-empty-lines)
  8458. (or (looking-at "[ \t]*$")
  8459. (progn (insert "\n") (backward-char 1)))
  8460. (org-insert-heading nil t)
  8461. (org-do-demote)
  8462. (setq col (current-column))
  8463. (insert text "\n")
  8464. (if org-adapt-indentation (org-indent-to-column col))
  8465. (let ((org-show-following-heading t)
  8466. (org-show-siblings t)
  8467. (org-show-hierarchy-above t)
  8468. (org-show-entry-below t))
  8469. (org-show-context))))
  8470. (defun org-agenda-diary-entry ()
  8471. "Make a diary entry, like the `i' command from the calendar.
  8472. All the standard commands work: block, weekly etc.
  8473. When `org-agenda-diary-file' points to a file,
  8474. `org-agenda-diary-entry-in-org-file' is called instead to create
  8475. entries in that Org-mode file."
  8476. (interactive)
  8477. (if (not (eq org-agenda-diary-file 'diary-file))
  8478. (org-agenda-diary-entry-in-org-file)
  8479. (require 'diary-lib)
  8480. (let* ((char (progn
  8481. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8482. (read-char-exclusive)))
  8483. (cmd (cdr (assoc char
  8484. '((?d . insert-diary-entry)
  8485. (?w . insert-weekly-diary-entry)
  8486. (?m . insert-monthly-diary-entry)
  8487. (?y . insert-yearly-diary-entry)
  8488. (?a . insert-anniversary-diary-entry)
  8489. (?b . insert-block-diary-entry)
  8490. (?c . insert-cyclic-diary-entry)))))
  8491. (oldf (symbol-function 'calendar-cursor-to-date))
  8492. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8493. (point (point))
  8494. (mark (or (mark t) (point))))
  8495. (unless cmd
  8496. (error "No command associated with <%c>" char))
  8497. (unless (and (get-text-property point 'day)
  8498. (or (not (equal ?b char))
  8499. (get-text-property mark 'day)))
  8500. (error "Don't know which date to use for diary entry"))
  8501. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8502. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8503. (let ((calendar-mark-ring
  8504. (list (calendar-gregorian-from-absolute
  8505. (or (get-text-property mark 'day)
  8506. (get-text-property point 'day))))))
  8507. (unwind-protect
  8508. (progn
  8509. (fset 'calendar-cursor-to-date
  8510. (lambda (&optional error dummy)
  8511. (calendar-gregorian-from-absolute
  8512. (get-text-property point 'day))))
  8513. (call-interactively cmd))
  8514. (fset 'calendar-cursor-to-date oldf))))))
  8515. (defun org-agenda-execute-calendar-command (cmd)
  8516. "Execute a calendar command from the agenda with date from cursor."
  8517. (org-agenda-check-type t 'agenda 'timeline)
  8518. (require 'diary-lib)
  8519. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8520. (error "Don't know which date to use for the calendar command"))
  8521. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8522. (point (point))
  8523. (date (calendar-gregorian-from-absolute
  8524. (get-text-property point 'day)))
  8525. ;; the following 2 vars are needed in the calendar
  8526. (displayed-month (car date))
  8527. (displayed-year (nth 2 date)))
  8528. (unwind-protect
  8529. (progn
  8530. (fset 'calendar-cursor-to-date
  8531. (lambda (&optional error dummy)
  8532. (calendar-gregorian-from-absolute
  8533. (get-text-property point 'day))))
  8534. (call-interactively cmd))
  8535. (fset 'calendar-cursor-to-date oldf))))
  8536. (defun org-agenda-phases-of-moon ()
  8537. "Display the phases of the moon for the 3 months around the cursor date."
  8538. (interactive)
  8539. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8540. (defun org-agenda-holidays ()
  8541. "Display the holidays for the 3 months around the cursor date."
  8542. (interactive)
  8543. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8544. (defvar calendar-longitude) ; defined in calendar.el
  8545. (defvar calendar-latitude) ; defined in calendar.el
  8546. (defvar calendar-location-name) ; defined in calendar.el
  8547. (defun org-agenda-sunrise-sunset (arg)
  8548. "Display sunrise and sunset for the cursor date.
  8549. Latitude and longitude can be specified with the variables
  8550. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8551. argument, latitude and longitude will be prompted for."
  8552. (interactive "P")
  8553. (require 'solar)
  8554. (let ((calendar-longitude (if arg nil calendar-longitude))
  8555. (calendar-latitude (if arg nil calendar-latitude))
  8556. (calendar-location-name
  8557. (if arg "the given coordinates" calendar-location-name)))
  8558. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8559. (defun org-agenda-goto-calendar ()
  8560. "Open the Emacs calendar with the date at the cursor."
  8561. (interactive)
  8562. (org-agenda-check-type t 'agenda 'timeline)
  8563. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8564. (error "Don't know which date to open in calendar")))
  8565. (date (calendar-gregorian-from-absolute day))
  8566. (calendar-move-hook nil)
  8567. (calendar-view-holidays-initially-flag nil)
  8568. (calendar-view-diary-initially-flag nil))
  8569. (calendar)
  8570. (calendar-goto-date date)))
  8571. ;;;###autoload
  8572. (defun org-calendar-goto-agenda ()
  8573. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8574. This is a command that has to be installed in `calendar-mode-map'."
  8575. (interactive)
  8576. (org-agenda-list nil (calendar-absolute-from-gregorian
  8577. (calendar-cursor-to-date))
  8578. nil))
  8579. (autoload 'org-calendar-goto-agenda "org-agenda" "\
  8580. Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8581. This is a command that has to be installed in `calendar-mode-map'.
  8582. \(fn)" t nil)
  8583. (defun org-agenda-convert-date ()
  8584. (interactive)
  8585. (org-agenda-check-type t 'agenda 'timeline)
  8586. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8587. date s)
  8588. (unless day
  8589. (error "Don't know which date to convert"))
  8590. (setq date (calendar-gregorian-from-absolute day))
  8591. (setq s (concat
  8592. "Gregorian: " (calendar-date-string date) "\n"
  8593. "ISO: " (calendar-iso-date-string date) "\n"
  8594. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8595. "Julian: " (calendar-julian-date-string date) "\n"
  8596. "Astron. JD: " (calendar-astro-date-string date)
  8597. " (Julian date number at noon UTC)\n"
  8598. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8599. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8600. "French: " (calendar-french-date-string date) "\n"
  8601. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8602. "Mayan: " (calendar-mayan-date-string date) "\n"
  8603. "Coptic: " (calendar-coptic-date-string date) "\n"
  8604. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8605. "Persian: " (calendar-persian-date-string date) "\n"
  8606. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8607. (with-output-to-temp-buffer "*Dates*"
  8608. (princ s))
  8609. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8610. ;;; Bulk commands
  8611. (defun org-agenda-bulk-marked-p ()
  8612. (eq (get-char-property (point-at-bol) 'type)
  8613. 'org-marked-entry-overlay))
  8614. (defun org-agenda-bulk-mark (&optional arg)
  8615. "Mark the entry at point for future bulk action."
  8616. (interactive "p")
  8617. (dotimes (i (or arg 1))
  8618. (unless (org-get-at-bol 'org-agenda-diary-link)
  8619. (let* ((m (org-get-at-bol 'org-hd-marker))
  8620. ov)
  8621. (unless (org-agenda-bulk-marked-p)
  8622. (unless m (error "Nothing to mark at point"))
  8623. (push m org-agenda-bulk-marked-entries)
  8624. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8625. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8626. (org-get-todo-face "TODO")
  8627. 'evaporate)
  8628. (overlay-put ov 'type 'org-marked-entry-overlay))
  8629. (beginning-of-line 2)
  8630. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8631. (beginning-of-line 2))
  8632. (message "%d entries marked for bulk action"
  8633. (length org-agenda-bulk-marked-entries))))))
  8634. (defun org-agenda-bulk-mark-all ()
  8635. "Mark all entries for future agenda bulk action."
  8636. (interactive)
  8637. (org-agenda-bulk-mark-regexp "."))
  8638. (defun org-agenda-bulk-mark-regexp (regexp)
  8639. "Mark entries matching REGEXP for future agenda bulk action."
  8640. (interactive "sMark entries matching regexp: ")
  8641. (let ((entries-marked 0))
  8642. (save-excursion
  8643. (goto-char (point-min))
  8644. (goto-char (next-single-property-change (point) 'txt))
  8645. (while (re-search-forward regexp nil t)
  8646. (when (string-match regexp (get-text-property (point) 'txt))
  8647. (setq entries-marked (1+ entries-marked))
  8648. (call-interactively 'org-agenda-bulk-mark))))
  8649. (if (not entries-marked)
  8650. (message "No entry matching this regexp."))))
  8651. (defun org-agenda-bulk-unmark (&optional arg)
  8652. "Unmark the entry at point for future bulk action."
  8653. (interactive "P")
  8654. (if arg
  8655. (org-agenda-bulk-unmark-all)
  8656. (cond ((org-agenda-bulk-marked-p)
  8657. (org-agenda-bulk-remove-overlays
  8658. (point-at-bol) (+ 2 (point-at-bol)))
  8659. (setq org-agenda-bulk-marked-entries
  8660. (delete (org-get-at-bol 'org-hd-marker)
  8661. org-agenda-bulk-marked-entries))
  8662. (beginning-of-line 2)
  8663. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8664. (beginning-of-line 2))
  8665. (message "%d entries left marked for bulk action"
  8666. (length org-agenda-bulk-marked-entries)))
  8667. (t (message "No entry to unmark here")))))
  8668. (defun org-agenda-bulk-toggle ()
  8669. "Toggle marking the entry at point for bulk action."
  8670. (interactive)
  8671. (if (org-agenda-bulk-marked-p)
  8672. (org-agenda-bulk-unmark)
  8673. (org-agenda-bulk-mark)))
  8674. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8675. "Remove the mark overlays between BEG and END in the agenda buffer.
  8676. BEG and END default to the buffer limits.
  8677. This only removes the overlays, it does not remove the markers
  8678. from the list in `org-agenda-bulk-marked-entries'."
  8679. (interactive)
  8680. (mapc (lambda (ov)
  8681. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8682. (delete-overlay ov)))
  8683. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8684. (defun org-agenda-bulk-unmark-all ()
  8685. "Remove all marks in the agenda buffer.
  8686. This will remove the markers and the overlays."
  8687. (interactive)
  8688. (if (null org-agenda-bulk-marked-entries)
  8689. (message "No entry to unmark")
  8690. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8691. (setq org-agenda-bulk-marked-entries nil)
  8692. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8693. (defcustom org-agenda-persistent-marks nil
  8694. "Non-nil means marked items will stay marked after a bulk action.
  8695. You can toggle this interactively by typing `p' when prompted for a
  8696. bulk action."
  8697. :group 'org-agenda
  8698. :version "24.1"
  8699. :type 'boolean)
  8700. (defun org-agenda-bulk-action (&optional arg)
  8701. "Execute an remote-editing action on all marked entries.
  8702. The prefix arg is passed through to the command if possible."
  8703. (interactive "P")
  8704. ;; Make sure we have markers, and only valid ones
  8705. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8706. (mapc
  8707. (lambda (m)
  8708. (unless (and (markerp m)
  8709. (marker-buffer m)
  8710. (buffer-live-p (marker-buffer m))
  8711. (marker-position m))
  8712. (error "Marker %s for bulk command is invalid" m)))
  8713. org-agenda-bulk-marked-entries)
  8714. ;; Prompt for the bulk command
  8715. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8716. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8717. "[S]catter [f]unction "
  8718. (when org-agenda-bulk-custom-functions
  8719. (concat " Custom: ["
  8720. (mapconcat (lambda(f) (char-to-string (car f)))
  8721. org-agenda-bulk-custom-functions "")
  8722. "]"))))
  8723. (catch 'exit
  8724. (let* ((action (read-char-exclusive))
  8725. (org-log-refile (if org-log-refile 'time nil))
  8726. (entries (reverse org-agenda-bulk-marked-entries))
  8727. (org-overriding-default-time
  8728. (if (get-text-property (point) 'org-agenda-date-header)
  8729. (org-get-cursor-date)))
  8730. redo-at-end
  8731. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8732. (cond
  8733. ((equal action ?p)
  8734. (let ((org-agenda-persistent-marks
  8735. (not org-agenda-persistent-marks)))
  8736. (org-agenda-bulk-action)
  8737. (throw 'exit nil)))
  8738. ((equal action ?$)
  8739. (setq cmd '(org-agenda-archive)))
  8740. ((equal action ?A)
  8741. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8742. ((member action '(?r ?w))
  8743. (setq rfloc (org-refile-get-location
  8744. "Refile to"
  8745. (marker-buffer (car entries))
  8746. org-refile-allow-creating-parent-nodes))
  8747. (if (nth 3 rfloc)
  8748. (setcar (nthcdr 3 rfloc)
  8749. (move-marker (make-marker) (nth 3 rfloc)
  8750. (or (get-file-buffer (nth 1 rfloc))
  8751. (find-buffer-visiting (nth 1 rfloc))
  8752. (error "This should not happen")))))
  8753. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8754. redo-at-end t))
  8755. ((equal action ?t)
  8756. (setq state (org-icompleting-read
  8757. "Todo state: "
  8758. (with-current-buffer (marker-buffer (car entries))
  8759. (mapcar 'list org-todo-keywords-1))))
  8760. (setq cmd `(let ((org-inhibit-blocking t)
  8761. (org-inhibit-logging 'note))
  8762. (org-agenda-todo ,state))))
  8763. ((memq action '(?- ?+))
  8764. (setq tag (org-icompleting-read
  8765. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8766. (with-current-buffer (marker-buffer (car entries))
  8767. (delq nil
  8768. (mapcar (lambda (x)
  8769. (if (stringp (car x)) x)) org-tag-alist)))))
  8770. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8771. ((memq action '(?s ?d))
  8772. (let* ((time
  8773. (unless arg
  8774. (org-read-date
  8775. nil nil nil
  8776. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8777. org-overriding-default-time)))
  8778. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8779. (setq cmd `(eval '(,c1 arg ,time)))))
  8780. ((equal action ?S)
  8781. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8782. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8783. (let ((days (read-number
  8784. (format "Scatter tasks across how many %sdays: "
  8785. (if arg "week" "")) 7)))
  8786. (setq cmd
  8787. `(let ((distance (1+ (random ,days))))
  8788. (if arg
  8789. (let ((dist distance)
  8790. (day-of-week
  8791. (calendar-day-of-week
  8792. (calendar-gregorian-from-absolute (org-today)))))
  8793. (dotimes (i (1+ dist))
  8794. (while (member day-of-week org-agenda-weekend-days)
  8795. (incf distance)
  8796. (incf day-of-week)
  8797. (if (= day-of-week 7)
  8798. (setq day-of-week 0)))
  8799. (incf day-of-week)
  8800. (if (= day-of-week 7)
  8801. (setq day-of-week 0)))))
  8802. ;; silently fail when try to replan a sexp entry
  8803. (condition-case nil
  8804. (let* ((date (calendar-gregorian-from-absolute
  8805. (+ (org-today) distance)))
  8806. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8807. (nth 2 date))))
  8808. (org-agenda-schedule nil time))
  8809. (error nil)))))))
  8810. ((assoc action org-agenda-bulk-custom-functions)
  8811. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8812. redo-at-end t))
  8813. ((equal action ?f)
  8814. (setq cmd (list (intern
  8815. (org-icompleting-read "Function: "
  8816. obarray 'fboundp t nil nil)))))
  8817. (t (error "Invalid bulk action")))
  8818. ;; Sort the markers, to make sure that parents are handled before children
  8819. (setq entries (sort entries
  8820. (lambda (a b)
  8821. (cond
  8822. ((equal (marker-buffer a) (marker-buffer b))
  8823. (< (marker-position a) (marker-position b)))
  8824. (t
  8825. (string< (buffer-name (marker-buffer a))
  8826. (buffer-name (marker-buffer b))))))))
  8827. ;; Now loop over all markers and apply cmd
  8828. (while (setq e (pop entries))
  8829. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8830. (if (not pos)
  8831. (progn (message "Skipping removed entry at %s" e)
  8832. (setq cntskip (1+ cntskip)))
  8833. (goto-char pos)
  8834. (let (org-loop-over-headlines-in-active-region)
  8835. (eval cmd))
  8836. (setq cnt (1+ cnt))))
  8837. (when redo-at-end (org-agenda-redo))
  8838. (unless org-agenda-persistent-marks
  8839. (org-agenda-bulk-unmark-all))
  8840. (message "Acted on %d entries%s%s"
  8841. cnt
  8842. (if (= cntskip 0)
  8843. ""
  8844. (format ", skipped %d (disappeared before their turn)"
  8845. cntskip))
  8846. (if (not org-agenda-persistent-marks)
  8847. "" " (kept marked)"))))))
  8848. (defun org-agenda-capture (&optional with-time)
  8849. "Call `org-capture' with the date at point.
  8850. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  8851. current HH:MM time."
  8852. (interactive "P")
  8853. (if (not (eq major-mode 'org-agenda-mode))
  8854. (user-error "You cannot do this outside of agenda buffers")
  8855. (let ((org-overriding-default-time
  8856. (org-get-cursor-date (equal with-time 1))))
  8857. (call-interactively 'org-capture))))
  8858. ;;; Flagging notes
  8859. (defun org-agenda-show-the-flagging-note ()
  8860. "Display the flagging note in the other window.
  8861. When called a second time in direct sequence, offer to remove the FLAGGING
  8862. tag and (if present) the flagging note."
  8863. (interactive)
  8864. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8865. (win (selected-window))
  8866. note heading newhead)
  8867. (unless hdmarker
  8868. (error "No linked entry at point"))
  8869. (if (and (eq this-command last-command)
  8870. (y-or-n-p "Unflag and remove any flagging note? "))
  8871. (progn
  8872. (org-agenda-remove-flag hdmarker)
  8873. (let ((win (get-buffer-window "*Flagging Note*")))
  8874. (and win (delete-window win)))
  8875. (message "Entry unflagged"))
  8876. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8877. (unless note
  8878. (error "No flagging note"))
  8879. (org-kill-new note)
  8880. (org-switch-to-buffer-other-window "*Flagging Note*")
  8881. (erase-buffer)
  8882. (insert note)
  8883. (goto-char (point-min))
  8884. (while (re-search-forward "\\\\n" nil t)
  8885. (replace-match "\n" t t))
  8886. (goto-char (point-min))
  8887. (select-window win)
  8888. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8889. (defun org-agenda-remove-flag (marker)
  8890. "Remove the FLAGGED tag and any flagging note in the entry."
  8891. (let (newhead)
  8892. (org-with-point-at marker
  8893. (org-toggle-tag "FLAGGED" 'off)
  8894. (org-entry-delete nil "THEFLAGGINGNOTE")
  8895. (setq newhead (org-get-heading)))
  8896. (org-agenda-change-all-lines newhead marker)
  8897. (message "Entry unflagged")))
  8898. (defun org-agenda-get-any-marker (&optional pos)
  8899. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8900. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8901. ;;; Appointment reminders
  8902. (defvar appt-time-msg-list) ; defined in appt.el
  8903. ;;;###autoload
  8904. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8905. "Activate appointments found in `org-agenda-files'.
  8906. With a \\[universal-argument] prefix, refresh the list of
  8907. appointments.
  8908. If FILTER is t, interactively prompt the user for a regular
  8909. expression, and filter out entries that don't match it.
  8910. If FILTER is a string, use this string as a regular expression
  8911. for filtering entries out.
  8912. If FILTER is a function, filter out entries against which
  8913. calling the function returns nil. This function takes one
  8914. argument: an entry from `org-agenda-get-day-entries'.
  8915. FILTER can also be an alist with the car of each cell being
  8916. either 'headline or 'category. For example:
  8917. '((headline \"IMPORTANT\")
  8918. (category \"Work\"))
  8919. will only add headlines containing IMPORTANT or headlines
  8920. belonging to the \"Work\" category.
  8921. ARGS are symbols indicating what kind of entries to consider.
  8922. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8923. and :timestamp entries. See the docstring of `org-diary' for
  8924. details and examples.
  8925. If an entry as a APPT_WARNTIME property, its value will be used
  8926. to override `appt-message-warning-time'."
  8927. (interactive "P")
  8928. (if refresh (setq appt-time-msg-list nil))
  8929. (if (eq filter t)
  8930. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8931. (let* ((cnt 0) ; count added events
  8932. (scope (or args '(:deadline :scheduled :timestamp)))
  8933. (org-agenda-new-buffers nil)
  8934. (org-deadline-warning-days 0)
  8935. ;; Do not use `org-today' here because appt only takes
  8936. ;; time and without date as argument, so it may pass wrong
  8937. ;; information otherwise
  8938. (today (org-date-to-gregorian
  8939. (time-to-days (current-time))))
  8940. (org-agenda-restrict nil)
  8941. (files (org-agenda-files 'unrestricted)) entries file
  8942. (org-agenda-buffer nil))
  8943. ;; Get all entries which may contain an appt
  8944. (org-agenda-prepare-buffers files)
  8945. (while (setq file (pop files))
  8946. (setq entries
  8947. (delq nil
  8948. (append entries
  8949. (apply 'org-agenda-get-day-entries
  8950. file today scope)))))
  8951. ;; Map thru entries and find if we should filter them out
  8952. (mapc
  8953. (lambda(x)
  8954. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8955. (cat (get-text-property 1 'org-category x))
  8956. (tod (get-text-property 1 'time-of-day x))
  8957. (ok (or (null filter)
  8958. (and (stringp filter) (string-match filter evt))
  8959. (and (functionp filter) (funcall filter x))
  8960. (and (listp filter)
  8961. (let ((cat-filter (cadr (assoc 'category filter)))
  8962. (evt-filter (cadr (assoc 'headline filter))))
  8963. (or (and (stringp cat-filter)
  8964. (string-match cat-filter cat))
  8965. (and (stringp evt-filter)
  8966. (string-match evt-filter evt)))))))
  8967. (wrn (get-text-property 1 'warntime x)))
  8968. ;; FIXME: Shall we remove text-properties for the appt text?
  8969. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8970. (when (and ok tod)
  8971. (setq tod (concat "00" (number-to-string tod))
  8972. tod (when (string-match
  8973. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8974. (concat (match-string 1 tod) ":"
  8975. (match-string 2 tod))))
  8976. (if (version< emacs-version "23.3")
  8977. (appt-add tod evt)
  8978. (appt-add tod evt wrn))
  8979. (setq cnt (1+ cnt))))) entries)
  8980. (org-release-buffers org-agenda-new-buffers)
  8981. (if (eq cnt 0)
  8982. (message "No event to add")
  8983. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8984. (autoload 'org-agenda-to-appt "org-agenda" "\
  8985. Activate appointments found in `org-agenda-files'.
  8986. With a \\[universal-argument] prefix, refresh the list of
  8987. appointments.
  8988. If FILTER is t, interactively prompt the user for a regular
  8989. expression, and filter out entries that don't match it.
  8990. If FILTER is a string, use this string as a regular expression
  8991. for filtering entries out.
  8992. If FILTER is a function, filter out entries against which
  8993. calling the function returns nil. This function takes one
  8994. argument: an entry from `org-agenda-get-day-entries'.
  8995. FILTER can also be an alist with the car of each cell being
  8996. either 'headline or 'category. For example:
  8997. '((headline \"IMPORTANT\")
  8998. (category \"Work\"))
  8999. will only add headlines containing IMPORTANT or headlines
  9000. belonging to the \"Work\" category.
  9001. ARGS are symbols indicating what kind of entries to consider.
  9002. By default `org-agenda-to-appt' will use :deadline, :scheduled
  9003. and :timestamp entries. See the docstring of `org-diary' for
  9004. details and examples.
  9005. If an entry as a APPT_WARNTIME property, its value will be used
  9006. to override `appt-message-warning-time'.
  9007. \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
  9008. (defun org-agenda-todayp (date)
  9009. "Does DATE mean today, when considering `org-extend-today-until'?"
  9010. (let ((today (org-today))
  9011. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9012. date)))
  9013. (eq date today)))
  9014. (defun org-agenda-todo-yesterday (&optional arg)
  9015. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9016. (interactive "P")
  9017. (let* ((hour (third (decode-time
  9018. (org-current-time))))
  9019. (org-extend-today-until (1+ hour)))
  9020. (org-agenda-todo arg)))
  9021. (provide 'org-agenda)
  9022. ;;; org-agenda.el ends here