org-agenda.el 392 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2014 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 '(choice
  203. (const nil)
  204. (string)))
  205. (defcustom org-agenda-persistent-filter nil
  206. "When set, keep filters from one agenda view to the next."
  207. :group 'org-agenda
  208. :type 'boolean)
  209. (defgroup org-agenda-custom-commands nil
  210. "Options concerning agenda views in Org-mode."
  211. :tag "Org Agenda Custom Commands"
  212. :group 'org-agenda)
  213. (defconst org-sorting-choice
  214. '(choice
  215. (const time-up) (const time-down)
  216. (const timestamp-up) (const timestamp-down)
  217. (const scheduled-up) (const scheduled-down)
  218. (const deadline-up) (const deadline-down)
  219. (const ts-up) (const ts-down)
  220. (const tsia-up) (const tsia-down)
  221. (const category-keep) (const category-up) (const category-down)
  222. (const tag-down) (const tag-up)
  223. (const priority-up) (const priority-down)
  224. (const todo-state-up) (const todo-state-down)
  225. (const effort-up) (const effort-down)
  226. (const habit-up) (const habit-down)
  227. (const alpha-up) (const alpha-down)
  228. (const user-defined-up) (const user-defined-down))
  229. "Sorting choices.")
  230. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  231. ;; the new variable `org-agenda-tag-filter-preset'.
  232. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  233. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  234. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  235. "List of types searched for when creating the daily/weekly agenda.
  236. This variable is a list of symbols that controls the types of
  237. items that appear in the daily/weekly agenda. Allowed symbols in this
  238. list are are
  239. :timestamp List items containing a date stamp or date range matching
  240. the selected date. This includes sexp entries in angular
  241. brackets.
  242. :sexp List entries resulting from plain diary-like sexps.
  243. :deadline List deadline due on that date. When the date is today,
  244. also list any deadlines past due, or due within
  245. `org-deadline-warning-days'. `:deadline' must appear before
  246. `:scheduled' if the setting of
  247. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  248. any effect.
  249. :deadline* Same as above, but only include the deadline if it has an
  250. hour specification as [h]h:mm.
  251. :scheduled List all items which are scheduled for the given date.
  252. The diary for *today* also contains items which were
  253. scheduled earlier and are not yet marked DONE.
  254. :scheduled* Same as above, but only include the scheduled item if it
  255. has an hour specification as [h]h:mm.
  256. By default, all four non-starred types are turned on.
  257. When :scheduled* or :deadline* are included, :schedule or :deadline
  258. will be ignored.
  259. Never set this variable globally using `setq', because then it
  260. will apply to all future agenda commands. Instead, bind it with
  261. `let' to scope it dynamically into the agenda-constructing
  262. command. A good way to set it is through options in
  263. `org-agenda-custom-commands'. For a more flexible (though
  264. somewhat less efficient) way of determining what is included in
  265. the daily/weekly agenda, see `org-agenda-skip-function'.")
  266. (defconst org-agenda-custom-commands-local-options
  267. `(repeat :tag "Local settings for this command. Remember to quote values"
  268. (choice :tag "Setting"
  269. (list :tag "Heading for this block"
  270. (const org-agenda-overriding-header)
  271. (string :tag "Headline"))
  272. (list :tag "Files to be searched"
  273. (const org-agenda-files)
  274. (list
  275. (const :format "" quote)
  276. (repeat (file))))
  277. (list :tag "Sorting strategy"
  278. (const org-agenda-sorting-strategy)
  279. (list
  280. (const :format "" quote)
  281. (repeat
  282. ,org-sorting-choice)))
  283. (list :tag "Prefix format"
  284. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  285. (string))
  286. (list :tag "Number of days in agenda"
  287. (const org-agenda-span)
  288. (choice (const :tag "Day" day)
  289. (const :tag "Week" week)
  290. (const :tag "Fortnight" fortnight)
  291. (const :tag "Month" month)
  292. (const :tag "Year" year)
  293. (integer :tag "Custom")))
  294. (list :tag "Fixed starting date"
  295. (const org-agenda-start-day)
  296. (string :value "2007-11-01"))
  297. (list :tag "Start on day of week"
  298. (const org-agenda-start-on-weekday)
  299. (choice :value 1
  300. (const :tag "Today" nil)
  301. (integer :tag "Weekday No.")))
  302. (list :tag "Include data from diary"
  303. (const org-agenda-include-diary)
  304. (boolean))
  305. (list :tag "Deadline Warning days"
  306. (const org-deadline-warning-days)
  307. (integer :value 1))
  308. (list :tag "Category filter preset"
  309. (const org-agenda-category-filter-preset)
  310. (list
  311. (const :format "" quote)
  312. (repeat
  313. (string :tag "+category or -category"))))
  314. (list :tag "Tags filter preset"
  315. (const org-agenda-tag-filter-preset)
  316. (list
  317. (const :format "" quote)
  318. (repeat
  319. (string :tag "+tag or -tag"))))
  320. (list :tag "Regexp filter preset"
  321. (const org-agenda-regexp-filter-preset)
  322. (list
  323. (const :format "" quote)
  324. (repeat
  325. (string :tag "+regexp or -regexp"))))
  326. (list :tag "Set daily/weekly entry types"
  327. (const org-agenda-entry-types)
  328. (list
  329. (const :format "" quote)
  330. (set :greedy t :value ,org-agenda-entry-types
  331. (const :deadline)
  332. (const :scheduled)
  333. (const :deadline*)
  334. (const :scheduled*)
  335. (const :timestamp)
  336. (const :sexp))))
  337. (list :tag "Standard skipping condition"
  338. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  339. (const org-agenda-skip-function)
  340. (list
  341. (const :format "" quote)
  342. (list
  343. (choice
  344. :tag "Skipping range"
  345. (const :tag "Skip entry" org-agenda-skip-entry-if)
  346. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  347. (repeat :inline t :tag "Conditions for skipping"
  348. (choice
  349. :tag "Condition type"
  350. (list :tag "Regexp matches" :inline t (const :format "" regexp) (regexp))
  351. (list :tag "Regexp does not match" :inline t (const :format "" notregexp) (regexp))
  352. (list :tag "TODO state is" :inline t
  353. (const todo)
  354. (choice
  355. (const :tag "any not-done state" todo)
  356. (const :tag "any done state" done)
  357. (const :tag "any state" any)
  358. (list :tag "Keyword list"
  359. (const :format "" quote)
  360. (repeat (string :tag "Keyword")))))
  361. (list :tag "TODO state is not" :inline t
  362. (const nottodo)
  363. (choice
  364. (const :tag "any not-done state" todo)
  365. (const :tag "any done state" done)
  366. (const :tag "any state" any)
  367. (list :tag "Keyword list"
  368. (const :format "" quote)
  369. (repeat (string :tag "Keyword")))))
  370. (const :tag "scheduled" scheduled)
  371. (const :tag "not scheduled" notscheduled)
  372. (const :tag "deadline" deadline)
  373. (const :tag "no deadline" notdeadline)
  374. (const :tag "timestamp" timestamp)
  375. (const :tag "no timestamp" nottimestamp))))))
  376. (list :tag "Non-standard skipping condition"
  377. :value (org-agenda-skip-function)
  378. (const org-agenda-skip-function)
  379. (sexp :tag "Function or form (quoted!)"))
  380. (list :tag "Any variable"
  381. (variable :tag "Variable")
  382. (sexp :tag "Value (sexp)"))))
  383. "Selection of examples for agenda command settings.
  384. This will be spliced into the custom type of
  385. `org-agenda-custom-commands'.")
  386. (defcustom org-agenda-custom-commands
  387. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  388. "Custom commands for the agenda.
  389. These commands will be offered on the splash screen displayed by the
  390. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  391. (key desc type match settings files)
  392. key The key (one or more characters as a string) to be associated
  393. with the command.
  394. desc A description of the command, when omitted or nil, a default
  395. description is built using MATCH.
  396. type The command type, any of the following symbols:
  397. agenda The daily/weekly agenda.
  398. todo Entries with a specific TODO keyword, in all agenda files.
  399. search Entries containing search words entry or headline.
  400. tags Tags/Property/TODO match in all agenda files.
  401. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  402. todo-tree Sparse tree of specific TODO keyword in *current* file.
  403. tags-tree Sparse tree with all tags matches in *current* file.
  404. occur-tree Occur sparse tree for *current* file.
  405. ... A user-defined function.
  406. match What to search for:
  407. - a single keyword for TODO keyword searches
  408. - a tags match expression for tags searches
  409. - a word search expression for text searches.
  410. - a regular expression for occur searches
  411. For all other commands, this should be the empty string.
  412. settings A list of option settings, similar to that in a let form, so like
  413. this: ((opt1 val1) (opt2 val2) ...). The values will be
  414. evaluated at the moment of execution, so quote them when needed.
  415. files A list of files file to write the produced agenda buffer to
  416. with the command `org-store-agenda-views'.
  417. If a file name ends in \".html\", an HTML version of the buffer
  418. is written out. If it ends in \".ps\", a postscript version is
  419. produced. Otherwise, only the plain text is written to the file.
  420. You can also define a set of commands, to create a composite agenda buffer.
  421. In this case, an entry looks like this:
  422. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  423. where
  424. desc A description string to be displayed in the dispatcher menu.
  425. cmd An agenda command, similar to the above. However, tree commands
  426. are not allowed, but instead you can get agenda and global todo list.
  427. So valid commands for a set are:
  428. (agenda \"\" settings)
  429. (alltodo \"\" settings)
  430. (stuck \"\" settings)
  431. (todo \"match\" settings files)
  432. (search \"match\" settings files)
  433. (tags \"match\" settings files)
  434. (tags-todo \"match\" settings files)
  435. Each command can carry a list of options, and another set of options can be
  436. given for the whole set of commands. Individual command options take
  437. precedence over the general options.
  438. When using several characters as key to a command, the first characters
  439. are prefix commands. For the dispatcher to display useful information, you
  440. should provide a description for the prefix, like
  441. (setq org-agenda-custom-commands
  442. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  443. (\"hl\" tags \"+HOME+Lisa\")
  444. (\"hp\" tags \"+HOME+Peter\")
  445. (\"hk\" tags \"+HOME+Kim\")))"
  446. :group 'org-agenda-custom-commands
  447. :type `(repeat
  448. (choice :value ("x" "Describe command here" tags "" nil)
  449. (list :tag "Single command"
  450. (string :tag "Access Key(s) ")
  451. (option (string :tag "Description"))
  452. (choice
  453. (const :tag "Agenda" agenda)
  454. (const :tag "TODO list" alltodo)
  455. (const :tag "Search words" search)
  456. (const :tag "Stuck projects" stuck)
  457. (const :tag "Tags/Property match (all agenda files)" tags)
  458. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  459. (const :tag "TODO keyword search (all agenda files)" todo)
  460. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  461. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  462. (const :tag "Occur tree (current buffer)" occur-tree)
  463. (sexp :tag "Other, user-defined function"))
  464. (string :tag "Match (only for some commands)")
  465. ,org-agenda-custom-commands-local-options
  466. (option (repeat :tag "Export" (file :tag "Export to"))))
  467. (list :tag "Command series, all agenda files"
  468. (string :tag "Access Key(s)")
  469. (string :tag "Description ")
  470. (repeat :tag "Component"
  471. (choice
  472. (list :tag "Agenda"
  473. (const :format "" agenda)
  474. (const :tag "" :format "" "")
  475. ,org-agenda-custom-commands-local-options)
  476. (list :tag "TODO list (all keywords)"
  477. (const :format "" alltodo)
  478. (const :tag "" :format "" "")
  479. ,org-agenda-custom-commands-local-options)
  480. (list :tag "Search words"
  481. (const :format "" search)
  482. (string :tag "Match")
  483. ,org-agenda-custom-commands-local-options)
  484. (list :tag "Stuck projects"
  485. (const :format "" stuck)
  486. (const :tag "" :format "" "")
  487. ,org-agenda-custom-commands-local-options)
  488. (list :tag "Tags search"
  489. (const :format "" tags)
  490. (string :tag "Match")
  491. ,org-agenda-custom-commands-local-options)
  492. (list :tag "Tags search, TODO entries only"
  493. (const :format "" tags-todo)
  494. (string :tag "Match")
  495. ,org-agenda-custom-commands-local-options)
  496. (list :tag "TODO keyword search"
  497. (const :format "" todo)
  498. (string :tag "Match")
  499. ,org-agenda-custom-commands-local-options)
  500. (list :tag "Other, user-defined function"
  501. (symbol :tag "function")
  502. (string :tag "Match")
  503. ,org-agenda-custom-commands-local-options)))
  504. (repeat :tag "Settings for entire command set"
  505. (list (variable :tag "Any variable")
  506. (sexp :tag "Value")))
  507. (option (repeat :tag "Export" (file :tag "Export to"))))
  508. (cons :tag "Prefix key documentation"
  509. (string :tag "Access Key(s)")
  510. (string :tag "Description ")))))
  511. (defcustom org-agenda-query-register ?o
  512. "The register holding the current query string.
  513. The purpose of this is that if you construct a query string interactively,
  514. you can then use it to define a custom command."
  515. :group 'org-agenda-custom-commands
  516. :type 'character)
  517. (defcustom org-stuck-projects
  518. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  519. "How to identify stuck projects.
  520. This is a list of four items:
  521. 1. A tags/todo/property matcher string that is used to identify a project.
  522. See the manual for a description of tag and property searches.
  523. The entire tree below a headline matched by this is considered one project.
  524. 2. A list of TODO keywords identifying non-stuck projects.
  525. If the project subtree contains any headline with one of these todo
  526. keywords, the project is considered to be not stuck. If you specify
  527. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  528. 3. A list of tags identifying non-stuck projects.
  529. If the project subtree contains any headline with one of these tags,
  530. the project is considered to be not stuck. If you specify \"*\" as
  531. a tag, any tag will mark the project unstuck. Note that this is about
  532. the explicit presence of a tag somewhere in the subtree, inherited
  533. tags do not count here. If inherited tags make a project not stuck,
  534. use \"-TAG\" in the tags part of the matcher under (1.) above.
  535. 4. An arbitrary regular expression matching non-stuck projects.
  536. If the project turns out to be not stuck, search continues also in the
  537. subtree to see if any of the subtasks have project status.
  538. See also the variable `org-tags-match-list-sublevels' which applies
  539. to projects matched by this search as well.
  540. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  541. or `C-c a #' to produce the list."
  542. :group 'org-agenda-custom-commands
  543. :type '(list
  544. (string :tag "Tags/TODO match to identify a project")
  545. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  546. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  547. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  548. (defcustom org-agenda-filter-effort-default-operator "<"
  549. "The default operator for effort estimate filtering.
  550. If you select an effort estimate limit without first pressing an operator,
  551. this one will be used."
  552. :group 'org-agenda-custom-commands
  553. :type '(choice (const :tag "less or equal" "<")
  554. (const :tag "greater or equal"">")
  555. (const :tag "equal" "=")))
  556. (defgroup org-agenda-skip nil
  557. "Options concerning skipping parts of agenda files."
  558. :tag "Org Agenda Skip"
  559. :group 'org-agenda)
  560. (defcustom org-agenda-skip-function-global nil
  561. "Function to be called at each match during agenda construction.
  562. If this function returns nil, the current match should not be skipped.
  563. If the function decided to skip an agenda match, is must return the
  564. buffer position from which the search should be continued.
  565. This may also be a Lisp form, which will be evaluated.
  566. This variable will be applied to every agenda match, including
  567. tags/property searches and TODO lists. So try to make the test function
  568. do its checking as efficiently as possible. To implement a skipping
  569. condition just for specific agenda commands, use the variable
  570. `org-agenda-skip-function' which can be set in the options section
  571. of custom agenda commands."
  572. :group 'org-agenda-skip
  573. :type 'sexp)
  574. (defgroup org-agenda-daily/weekly nil
  575. "Options concerning the daily/weekly agenda."
  576. :tag "Org Agenda Daily/Weekly"
  577. :group 'org-agenda)
  578. (defgroup org-agenda-todo-list nil
  579. "Options concerning the global todo list agenda view."
  580. :tag "Org Agenda Todo List"
  581. :group 'org-agenda)
  582. (defgroup org-agenda-match-view nil
  583. "Options concerning the general tags/property/todo match agenda view."
  584. :tag "Org Agenda Match View"
  585. :group 'org-agenda)
  586. (defgroup org-agenda-search-view nil
  587. "Options concerning the search agenda view."
  588. :tag "Org Agenda Search View"
  589. :group 'org-agenda)
  590. (defvar org-agenda-archives-mode nil
  591. "Non-nil means the agenda will include archived items.
  592. If this is the symbol `trees', trees in the selected agenda scope
  593. that are marked with the ARCHIVE tag will be included anyway. When this is
  594. t, also all archive files associated with the current selection of agenda
  595. files will be included.")
  596. (defcustom org-agenda-restriction-lock-highlight-subtree t
  597. "Non-nil means highlight the whole subtree when restriction is active.
  598. Otherwise only highlight the headline. Highlighting the whole subtree is
  599. useful to ensure no edits happen beyond the restricted region."
  600. :group 'org-agenda
  601. :type 'boolean)
  602. (defcustom org-agenda-skip-comment-trees t
  603. "Non-nil means skip trees that start with the COMMENT keyword.
  604. When nil, these trees are also scanned by agenda commands."
  605. :group 'org-agenda-skip
  606. :type 'boolean)
  607. (defcustom org-agenda-todo-list-sublevels t
  608. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  609. When nil, the sublevels of a TODO entry are not checked, resulting in
  610. potentially much shorter TODO lists."
  611. :group 'org-agenda-skip
  612. :group 'org-agenda-todo-list
  613. :type 'boolean)
  614. (defcustom org-agenda-todo-ignore-with-date nil
  615. "Non-nil means don't show entries with a date in the global todo list.
  616. You can use this if you prefer to mark mere appointments with a TODO keyword,
  617. but don't want them to show up in the TODO list.
  618. When this is set, it also covers deadlines and scheduled items, the settings
  619. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  620. will be ignored.
  621. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  622. :group 'org-agenda-skip
  623. :group 'org-agenda-todo-list
  624. :type 'boolean)
  625. (defcustom org-agenda-todo-ignore-timestamp nil
  626. "Non-nil means don't show entries with a timestamp.
  627. This applies when creating the global todo list.
  628. Valid values are:
  629. past Don't show entries for today or in the past.
  630. future Don't show entries with a timestamp in the future.
  631. The idea behind this is that if it has a future
  632. timestamp, you don't want to think about it until the
  633. date.
  634. all Don't show any entries with a timestamp in the global todo list.
  635. The idea behind this is that by setting a timestamp, you
  636. have already \"taken care\" of this item.
  637. This variable can also have an integer as a value. If positive (N),
  638. todos with a timestamp N or more days in the future will be ignored. If
  639. negative (-N), todos with a timestamp N or more days in the past will be
  640. ignored. If 0, todos with a timestamp either today or in the future will
  641. be ignored. For example, a value of -1 will exclude todos with a
  642. timestamp in the past (yesterday or earlier), while a value of 7 will
  643. exclude todos with a timestamp a week or more in the future.
  644. See also `org-agenda-todo-ignore-with-date'.
  645. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  646. to make his option also apply to the tags-todo list."
  647. :group 'org-agenda-skip
  648. :group 'org-agenda-todo-list
  649. :version "24.1"
  650. :type '(choice
  651. (const :tag "Ignore future timestamp todos" future)
  652. (const :tag "Ignore past or present timestamp todos" past)
  653. (const :tag "Ignore all timestamp todos" all)
  654. (const :tag "Show timestamp todos" nil)
  655. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  656. (defcustom org-agenda-todo-ignore-scheduled nil
  657. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  658. This applies when creating the global todo list.
  659. Valid values are:
  660. past Don't show entries scheduled today or in the past.
  661. future Don't show entries scheduled in the future.
  662. The idea behind this is that by scheduling it, you don't want to
  663. think about it until the scheduled date.
  664. all Don't show any scheduled entries in the global todo list.
  665. The idea behind this is that by scheduling it, you have already
  666. \"taken care\" of this item.
  667. t Same as `all', for backward compatibility.
  668. This variable can also have an integer as a value. See
  669. `org-agenda-todo-ignore-timestamp' for more details.
  670. See also `org-agenda-todo-ignore-with-date'.
  671. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  672. to make his option also apply to the tags-todo list."
  673. :group 'org-agenda-skip
  674. :group 'org-agenda-todo-list
  675. :type '(choice
  676. (const :tag "Ignore future-scheduled todos" future)
  677. (const :tag "Ignore past- or present-scheduled todos" past)
  678. (const :tag "Ignore all scheduled todos" all)
  679. (const :tag "Ignore all scheduled todos (compatibility)" t)
  680. (const :tag "Show scheduled todos" nil)
  681. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  682. (defcustom org-agenda-todo-ignore-deadlines nil
  683. "Non-nil means ignore some deadline TODO items when making TODO list.
  684. There are different motivations for using different values, please think
  685. carefully when configuring this variable.
  686. This applies when creating the global todo list.
  687. Valid values are:
  688. near Don't show near deadline entries. A deadline is near when it is
  689. closer than `org-deadline-warning-days' days. The idea behind this
  690. is that such items will appear in the agenda anyway.
  691. far Don't show TODO entries where a deadline has been defined, but
  692. the deadline is not near. This is useful if you don't want to
  693. use the todo list to figure out what to do now.
  694. past Don't show entries with a deadline timestamp for today or in the past.
  695. future Don't show entries with a deadline timestamp in the future, not even
  696. when they become `near' ones. Use it with caution.
  697. all Ignore all TODO entries that do have a deadline.
  698. t Same as `near', for backward compatibility.
  699. This variable can also have an integer as a value. See
  700. `org-agenda-todo-ignore-timestamp' for more details.
  701. See also `org-agenda-todo-ignore-with-date'.
  702. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  703. to make his option also apply to the tags-todo list."
  704. :group 'org-agenda-skip
  705. :group 'org-agenda-todo-list
  706. :type '(choice
  707. (const :tag "Ignore near deadlines" near)
  708. (const :tag "Ignore near deadlines (compatibility)" t)
  709. (const :tag "Ignore far deadlines" far)
  710. (const :tag "Ignore all TODOs with a deadlines" all)
  711. (const :tag "Show all TODOs, even if they have a deadline" nil)
  712. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  713. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  714. "Time unit to use when possibly ignoring an agenda item.
  715. See the docstring of various `org-agenda-todo-ignore-*' options.
  716. The default is to compare time stamps using days. An item is thus
  717. considered to be in the future if it is at least one day after today.
  718. Non-nil means to compare time stamps using seconds. An item is then
  719. considered future if it has a time value later than current time."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-todo-list
  722. :version "24.4"
  723. :package-version '(Org . "8.0")
  724. :type '(choice
  725. (const :tag "Compare time with days" nil)
  726. (const :tag "Compare time with seconds" t)))
  727. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  728. "Non-nil means honor todo-list ignores options also in tags-todo search.
  729. The variables
  730. `org-agenda-todo-ignore-with-date',
  731. `org-agenda-todo-ignore-timestamp',
  732. `org-agenda-todo-ignore-scheduled',
  733. `org-agenda-todo-ignore-deadlines'
  734. make the global TODO list skip entries that have time stamps of certain
  735. kinds. If this option is set, the same options will also apply for the
  736. tags-todo search, which is the general tags/property matcher
  737. restricted to unfinished TODO entries only."
  738. :group 'org-agenda-skip
  739. :group 'org-agenda-todo-list
  740. :group 'org-agenda-match-view
  741. :type 'boolean)
  742. (defcustom org-agenda-skip-scheduled-if-done nil
  743. "Non-nil means don't show scheduled items in agenda when they are done.
  744. This is relevant for the daily/weekly agenda, not for the TODO list. And
  745. it applies only to the actual date of the scheduling. Warnings about
  746. an item with a past scheduling dates are always turned off when the item
  747. is DONE."
  748. :group 'org-agenda-skip
  749. :group 'org-agenda-daily/weekly
  750. :type 'boolean)
  751. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  752. "Non-nil means skip scheduling line if same entry shows because of deadline.
  753. In the agenda of today, an entry can show up multiple times
  754. because it is both scheduled and has a nearby deadline, and maybe
  755. a plain time stamp as well.
  756. When this variable is nil, the entry will be shown several times.
  757. When set to t, then only the deadline is shown and the fact that
  758. the entry is scheduled today or was scheduled previously is not
  759. shown.
  760. When set to the symbol `not-today', skip scheduled previously,
  761. but not scheduled today.
  762. When set to the symbol `repeated-after-deadline', skip scheduled
  763. items if they are repeated beyond the current deadline."
  764. :group 'org-agenda-skip
  765. :group 'org-agenda-daily/weekly
  766. :type '(choice
  767. (const :tag "Never" nil)
  768. (const :tag "Always" t)
  769. (const :tag "Not when scheduled today" not-today)
  770. (const :tag "When repeated past deadline" repeated-after-deadline)))
  771. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  772. "Non-nil means skip timestamp line if same entry shows because of deadline.
  773. In the agenda of today, an entry can show up multiple times
  774. because it has both a plain timestamp and has a nearby deadline.
  775. When this variable is t, then only the deadline is shown and the
  776. fact that the entry has a timestamp for or including today is not
  777. shown. When this variable is nil, the entry will be shown
  778. several times."
  779. :group 'org-agenda-skip
  780. :group 'org-agenda-daily/weekly
  781. :version "24.1"
  782. :type '(choice
  783. (const :tag "Never" nil)
  784. (const :tag "Always" t)))
  785. (defcustom org-agenda-skip-deadline-if-done nil
  786. "Non-nil means don't show deadlines when the corresponding item is done.
  787. When nil, the deadline is still shown and should give you a happy feeling.
  788. This is relevant for the daily/weekly agenda. And it applied only to the
  789. actually date of the deadline. Warnings about approaching and past-due
  790. deadlines are always turned off when the item is DONE."
  791. :group 'org-agenda-skip
  792. :group 'org-agenda-daily/weekly
  793. :type 'boolean)
  794. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  795. "Non-nil means skip deadline prewarning when entry is also scheduled.
  796. This will apply on all days where a prewarning for the deadline would
  797. be shown, but not at the day when the entry is actually due. On that day,
  798. the deadline will be shown anyway.
  799. This variable may be set to nil, t, the symbol `pre-scheduled',
  800. or a number which will then give the number of days before the actual
  801. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  802. eliminates the deadline prewarning only prior to the scheduled date.
  803. This can be used in a workflow where the first showing of the deadline will
  804. trigger you to schedule it, and then you don't want to be reminded of it
  805. because you will take care of it on the day when scheduled."
  806. :group 'org-agenda-skip
  807. :group 'org-agenda-daily/weekly
  808. :version "24.1"
  809. :type '(choice
  810. (const :tag "Always show prewarning" nil)
  811. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  812. (const :tag "Remove prewarning if entry is scheduled" t)
  813. (integer :tag "Restart prewarning N days before deadline")))
  814. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  815. "Non-nil means skip scheduled delay when entry also has a deadline.
  816. This variable may be set to nil, t, the symbol `post-deadline',
  817. or a number which will then give the number of days after the actual
  818. scheduled date when the delay should expire. The symbol `post-deadline'
  819. eliminates the schedule delay when the date is posterior to the deadline."
  820. :group 'org-agenda-skip
  821. :group 'org-agenda-daily/weekly
  822. :version "24.4"
  823. :package-version '(Org . "8.0")
  824. :type '(choice
  825. (const :tag "Always honor delay" nil)
  826. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  827. (const :tag "Ignore delay if entry has a deadline" t)
  828. (integer :tag "Honor delay up until N days after the scheduled date")))
  829. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  830. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  831. When non-nil, after the search for timestamps has matched once in an
  832. entry, the rest of the entry will not be searched."
  833. :group 'org-agenda-skip
  834. :type 'boolean)
  835. (defcustom org-agenda-skip-timestamp-if-done nil
  836. "Non-nil means don't select item by timestamp or -range if it is DONE."
  837. :group 'org-agenda-skip
  838. :group 'org-agenda-daily/weekly
  839. :type 'boolean)
  840. (defcustom org-agenda-dim-blocked-tasks t
  841. "Non-nil means dim blocked tasks in the agenda display.
  842. This causes some overhead during agenda construction, but if you
  843. have turned on `org-enforce-todo-dependencies',
  844. `org-enforce-todo-checkbox-dependencies', or any other blocking
  845. mechanism, this will create useful feedback in the agenda.
  846. Instead of t, this variable can also have the value `invisible'.
  847. Then blocked tasks will be invisible and only become visible when
  848. they become unblocked. An exemption to this behavior is when a task is
  849. blocked because of unchecked checkboxes below it. Since checkboxes do
  850. not show up in the agenda views, making this task invisible you remove any
  851. trace from agenda views that there is something to do. Therefore, a task
  852. that is blocked because of checkboxes will never be made invisible, it
  853. will only be dimmed."
  854. :group 'org-agenda-daily/weekly
  855. :group 'org-agenda-todo-list
  856. :version "24.3"
  857. :type '(choice
  858. (const :tag "Do not dim" nil)
  859. (const :tag "Dim to a gray face" t)
  860. (const :tag "Make invisible" invisible)))
  861. (defcustom org-timeline-show-empty-dates 3
  862. "Non-nil means `org-timeline' also shows dates without an entry.
  863. When nil, only the days which actually have entries are shown.
  864. When t, all days between the first and the last date are shown.
  865. When an integer, show also empty dates, but if there is a gap of more than
  866. N days, just insert a special line indicating the size of the gap."
  867. :group 'org-agenda-skip
  868. :type '(choice
  869. (const :tag "None" nil)
  870. (const :tag "All" t)
  871. (integer :tag "at most")))
  872. (defgroup org-agenda-startup nil
  873. "Options concerning initial settings in the Agenda in Org Mode."
  874. :tag "Org Agenda Startup"
  875. :group 'org-agenda)
  876. (defcustom org-agenda-menu-show-matcher t
  877. "Non-nil means show the match string in the agenda dispatcher menu.
  878. When nil, the matcher string is not shown, but is put into the help-echo
  879. property so than moving the mouse over the command shows it.
  880. Setting it to nil is good if matcher strings are very long and/or if
  881. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  882. :group 'org-agenda
  883. :version "24.1"
  884. :type 'boolean)
  885. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  886. (defcustom org-agenda-menu-two-columns nil
  887. "Non-nil means, use two columns to show custom commands in the dispatcher.
  888. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  889. to nil."
  890. :group 'org-agenda
  891. :version "24.1"
  892. :type 'boolean)
  893. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  894. (defcustom org-agenda-finalize-hook nil
  895. "Hook run just before displaying an agenda buffer.
  896. The buffer is still writable when the hook is called.
  897. You can modify some of the buffer substrings but you should be
  898. extra careful not to modify the text properties of the agenda
  899. headlines as the agenda display heavily relies on them."
  900. :group 'org-agenda-startup
  901. :type 'hook)
  902. (defcustom org-agenda-mouse-1-follows-link nil
  903. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  904. A longer mouse click will still set point. Does not work on XEmacs.
  905. Needs to be set before org.el is loaded."
  906. :group 'org-agenda-startup
  907. :type 'boolean)
  908. (defcustom org-agenda-start-with-follow-mode nil
  909. "The initial value of follow mode in a newly created agenda window."
  910. :group 'org-agenda-startup
  911. :type 'boolean)
  912. (defcustom org-agenda-follow-indirect nil
  913. "Non-nil means `org-agenda-follow-mode' displays only the
  914. current item's tree, in an indirect buffer."
  915. :group 'org-agenda
  916. :version "24.1"
  917. :type 'boolean)
  918. (defcustom org-agenda-show-outline-path t
  919. "Non-nil means show outline path in echo area after line motion."
  920. :group 'org-agenda-startup
  921. :type 'boolean)
  922. (defcustom org-agenda-start-with-entry-text-mode nil
  923. "The initial value of entry-text-mode in a newly created agenda window."
  924. :group 'org-agenda-startup
  925. :type 'boolean)
  926. (defcustom org-agenda-entry-text-maxlines 5
  927. "Number of text lines to be added when `E' is pressed in the agenda.
  928. Note that this variable only used during agenda display. Add add entry text
  929. when exporting the agenda, configure the variable
  930. `org-agenda-add-entry-ext-maxlines'."
  931. :group 'org-agenda
  932. :type 'integer)
  933. (defcustom org-agenda-entry-text-exclude-regexps nil
  934. "List of regular expressions to clean up entry text.
  935. The complete matches of all regular expressions in this list will be
  936. removed from entry text before it is shown in the agenda."
  937. :group 'org-agenda
  938. :type '(repeat (regexp)))
  939. (defcustom org-agenda-entry-text-leaders " > "
  940. "Text prepended to the entry text in agenda buffers."
  941. :version "24.4"
  942. :package-version '(Org . "8.0")
  943. :group 'org-agenda
  944. :type 'string)
  945. (defvar org-agenda-entry-text-cleanup-hook nil
  946. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  947. This cleanup is done in a temporary buffer, so the function may inspect and
  948. change the entire buffer.
  949. Some default stuff like drawers and scheduling/deadline dates will already
  950. have been removed when this is called, as will any matches for regular
  951. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  952. (defvar org-agenda-include-inactive-timestamps nil
  953. "Non-nil means include inactive time stamps in agenda and timeline.
  954. Dynamically scoped.")
  955. (defgroup org-agenda-windows nil
  956. "Options concerning the windows used by the Agenda in Org Mode."
  957. :tag "Org Agenda Windows"
  958. :group 'org-agenda)
  959. (defcustom org-agenda-window-setup 'reorganize-frame
  960. "How the agenda buffer should be displayed.
  961. Possible values for this option are:
  962. current-window Show agenda in the current window, keeping all other windows.
  963. other-window Use `switch-to-buffer-other-window' to display agenda.
  964. reorganize-frame Show only two windows on the current frame, the current
  965. window and the agenda.
  966. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  967. Also, when exiting the agenda, kill that frame.
  968. See also the variable `org-agenda-restore-windows-after-quit'."
  969. :group 'org-agenda-windows
  970. :type '(choice
  971. (const current-window)
  972. (const other-frame)
  973. (const other-window)
  974. (const reorganize-frame)))
  975. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  976. "The min and max height of the agenda window as a fraction of frame height.
  977. The value of the variable is a cons cell with two numbers between 0 and 1.
  978. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  979. :group 'org-agenda-windows
  980. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  981. (defcustom org-agenda-restore-windows-after-quit nil
  982. "Non-nil means restore window configuration upon exiting agenda.
  983. Before the window configuration is changed for displaying the agenda,
  984. the current status is recorded. When the agenda is exited with
  985. `q' or `x' and this option is set, the old state is restored. If
  986. `org-agenda-window-setup' is `other-frame', the value of this
  987. option will be ignored."
  988. :group 'org-agenda-windows
  989. :type 'boolean)
  990. (defcustom org-agenda-ndays nil
  991. "Number of days to include in overview display.
  992. Should be 1 or 7.
  993. Obsolete, see `org-agenda-span'."
  994. :group 'org-agenda-daily/weekly
  995. :type '(choice (const nil)
  996. (integer)))
  997. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  998. (defcustom org-agenda-span 'week
  999. "Number of days to include in overview display.
  1000. Can be day, week, month, year, or any number of days.
  1001. Custom commands can set this variable in the options section."
  1002. :group 'org-agenda-daily/weekly
  1003. :type '(choice (const :tag "Day" day)
  1004. (const :tag "Week" week)
  1005. (const :tag "Fortnight" fortnight)
  1006. (const :tag "Month" month)
  1007. (const :tag "Year" year)
  1008. (integer :tag "Custom")))
  1009. (defcustom org-agenda-start-on-weekday 1
  1010. "Non-nil means start the overview always on the specified weekday.
  1011. 0 denotes Sunday, 1 denotes Monday, etc.
  1012. When nil, always start on the current day.
  1013. Custom commands can set this variable in the options section."
  1014. :group 'org-agenda-daily/weekly
  1015. :type '(choice (const :tag "Today" nil)
  1016. (integer :tag "Weekday No.")))
  1017. (defcustom org-agenda-show-all-dates t
  1018. "Non-nil means `org-agenda' shows every day in the selected range.
  1019. When nil, only the days which actually have entries are shown."
  1020. :group 'org-agenda-daily/weekly
  1021. :type 'boolean)
  1022. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1023. "Format string for displaying dates in the agenda.
  1024. Used by the daily/weekly agenda and by the timeline. This should be
  1025. a format string understood by `format-time-string', or a function returning
  1026. the formatted date as a string. The function must take a single argument,
  1027. a calendar-style date list like (month day year)."
  1028. :group 'org-agenda-daily/weekly
  1029. :type '(choice
  1030. (string :tag "Format string")
  1031. (function :tag "Function")))
  1032. (defun org-agenda-format-date-aligned (date)
  1033. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1034. This function makes sure that dates are aligned for easy reading."
  1035. (require 'cal-iso)
  1036. (let* ((dayname (calendar-day-name date))
  1037. (day (cadr date))
  1038. (day-of-week (calendar-day-of-week date))
  1039. (month (car date))
  1040. (monthname (calendar-month-name month))
  1041. (year (nth 2 date))
  1042. (iso-week (org-days-to-iso-week
  1043. (calendar-absolute-from-gregorian date)))
  1044. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1045. (1- year))
  1046. ((and (= month 12) (<= iso-week 1))
  1047. (1+ year))
  1048. (t year)))
  1049. (weekstring (if (= day-of-week 1)
  1050. (format " W%02d" iso-week)
  1051. "")))
  1052. (format "%-10s %2d %s %4d%s"
  1053. dayname day monthname year weekstring)))
  1054. (defcustom org-agenda-time-leading-zero nil
  1055. "Non-nil means use leading zero for military times in agenda.
  1056. For example, 9:30am would become 09:30 rather than 9:30."
  1057. :group 'org-agenda-daily/weekly
  1058. :version "24.1"
  1059. :type 'boolean)
  1060. (defcustom org-agenda-timegrid-use-ampm nil
  1061. "When set, show AM/PM style timestamps on the timegrid."
  1062. :group 'org-agenda
  1063. :version "24.1"
  1064. :type 'boolean)
  1065. (defun org-agenda-time-of-day-to-ampm (time)
  1066. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1067. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1068. (minute (substring time -2))
  1069. (ampm "am"))
  1070. (cond
  1071. ((equal hour-number 12)
  1072. (setq ampm "pm"))
  1073. ((> hour-number 12)
  1074. (setq ampm "pm")
  1075. (setq hour-number (- hour-number 12))))
  1076. (concat
  1077. (if org-agenda-time-leading-zero
  1078. (format "%02d" hour-number)
  1079. (format "%02s" (number-to-string hour-number)))
  1080. ":" minute ampm)))
  1081. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1082. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1083. (if org-agenda-timegrid-use-ampm
  1084. (org-agenda-time-of-day-to-ampm time)
  1085. time))
  1086. (defcustom org-agenda-weekend-days '(6 0)
  1087. "Which days are weekend?
  1088. These days get the special face `org-agenda-date-weekend' in the agenda
  1089. and timeline buffers."
  1090. :group 'org-agenda-daily/weekly
  1091. :type '(set :greedy t
  1092. (const :tag "Monday" 1)
  1093. (const :tag "Tuesday" 2)
  1094. (const :tag "Wednesday" 3)
  1095. (const :tag "Thursday" 4)
  1096. (const :tag "Friday" 5)
  1097. (const :tag "Saturday" 6)
  1098. (const :tag "Sunday" 0)))
  1099. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1100. "Non-nil means jump to today when moving a past date forward in time.
  1101. When using S-right in the agenda to move a a date forward, and the date
  1102. stamp currently points to the past, the first key press will move it
  1103. to today. WHen nil, just move one day forward even if the date stays
  1104. in the past."
  1105. :group 'org-agenda-daily/weekly
  1106. :version "24.1"
  1107. :type 'boolean)
  1108. (defcustom org-agenda-include-diary nil
  1109. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1110. Custom commands can set this variable in the options section."
  1111. :group 'org-agenda-daily/weekly
  1112. :type 'boolean)
  1113. (defcustom org-agenda-include-deadlines t
  1114. "If non-nil, include entries within their deadline warning period.
  1115. Custom commands can set this variable in the options section."
  1116. :group 'org-agenda-daily/weekly
  1117. :version "24.1"
  1118. :type 'boolean)
  1119. (defcustom org-agenda-repeating-timestamp-show-all t
  1120. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1121. When set to a list of strings, only show occurrences of repeating
  1122. stamps for these TODO keywords. When nil, only one occurrence is
  1123. shown, either today or the nearest into the future."
  1124. :group 'org-agenda-daily/weekly
  1125. :type '(choice
  1126. (const :tag "Show repeating stamps" t)
  1127. (repeat :tag "Show repeating stamps for these TODO keywords"
  1128. (string :tag "TODO Keyword"))
  1129. (const :tag "Don't show repeating stamps" nil)))
  1130. (defcustom org-scheduled-past-days 10000
  1131. "Number of days to continue listing scheduled items not marked DONE.
  1132. When an item is scheduled on a date, it shows up in the agenda on this
  1133. day and will be listed until it is marked done for the number of days
  1134. given here."
  1135. :group 'org-agenda-daily/weekly
  1136. :type 'integer)
  1137. (defcustom org-agenda-log-mode-items '(closed clock)
  1138. "List of items that should be shown in agenda log mode.
  1139. This list may contain the following symbols:
  1140. closed Show entries that have been closed on that day.
  1141. clock Show entries that have received clocked time on that day.
  1142. state Show all logged state changes.
  1143. Note that instead of changing this variable, you can also press `C-u l' in
  1144. the agenda to display all available LOG items temporarily."
  1145. :group 'org-agenda-daily/weekly
  1146. :type '(set :greedy t (const closed) (const clock) (const state)))
  1147. (defcustom org-agenda-clock-consistency-checks
  1148. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1149. :gap-ok-around ("4:00")
  1150. :default-face ((:background "DarkRed") (:foreground "white"))
  1151. :overlap-face nil :gap-face nil :no-end-time-face nil
  1152. :long-face nil :short-face nil)
  1153. "This is a property list, with the following keys:
  1154. :max-duration Mark clocking chunks that are longer than this time.
  1155. This is a time string like \"HH:MM\", or the number
  1156. of minutes as an integer.
  1157. :min-duration Mark clocking chunks that are shorter that this.
  1158. This is a time string like \"HH:MM\", or the number
  1159. of minutes as an integer.
  1160. :max-gap Mark gaps between clocking chunks that are longer than
  1161. this duration. A number of minutes, or a string
  1162. like \"HH:MM\".
  1163. :gap-ok-around List of times during the day which are usually not working
  1164. times. When a gap is detected, but the gap contains any
  1165. of these times, the gap is *not* reported. For example,
  1166. if this is (\"4:00\" \"13:00\") then gaps that contain
  1167. 4:00 in the morning (i.e. the night) and 13:00
  1168. (i.e. a typical lunch time) do not cause a warning.
  1169. You should have at least one time during the night in this
  1170. list, or otherwise the first task each morning will trigger
  1171. a warning because it follows a long gap.
  1172. Furthermore, the following properties can be used to define faces for
  1173. issue display.
  1174. :default-face the default face, if the specific face is undefined
  1175. :overlap-face face for overlapping clocks
  1176. :gap-face face for gaps between clocks
  1177. :no-end-time-face face for incomplete clocks
  1178. :long-face face for clock intervals that are too long
  1179. :short-face face for clock intervals that are too short"
  1180. :group 'org-agenda-daily/weekly
  1181. :group 'org-clock
  1182. :version "24.1"
  1183. :type 'plist)
  1184. (defcustom org-agenda-log-mode-add-notes t
  1185. "Non-nil means add first line of notes to log entries in agenda views.
  1186. If a log item like a state change or a clock entry is associated with
  1187. notes, the first line of these notes will be added to the entry in the
  1188. agenda display."
  1189. :group 'org-agenda-daily/weekly
  1190. :type 'boolean)
  1191. (defcustom org-agenda-start-with-log-mode nil
  1192. "The initial value of log-mode in a newly created agenda window.
  1193. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1194. explanations on the possible values."
  1195. :group 'org-agenda-startup
  1196. :group 'org-agenda-daily/weekly
  1197. :type '(choice (const :tag "Don't show log items" nil)
  1198. (const :tag "Show only log items" only)
  1199. (const :tag "Show all possible log items" clockcheck)
  1200. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1201. (choice (const :tag "Show closed log items" closed)
  1202. (const :tag "Show clocked log items" clock)
  1203. (const :tag "Show all logged state changes" state)))))
  1204. (defcustom org-agenda-start-with-clockreport-mode nil
  1205. "The initial value of clockreport-mode in a newly created agenda window."
  1206. :group 'org-agenda-startup
  1207. :group 'org-agenda-daily/weekly
  1208. :type 'boolean)
  1209. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1210. "Property list with parameters for the clocktable in clockreport mode.
  1211. This is the display mode that shows a clock table in the daily/weekly
  1212. agenda, the properties for this dynamic block can be set here.
  1213. The usual clocktable parameters are allowed here, but you cannot set
  1214. the properties :name, :tstart, :tend, :block, and :scope - these will
  1215. be overwritten to make sure the content accurately reflects the
  1216. current display in the agenda."
  1217. :group 'org-agenda-daily/weekly
  1218. :type 'plist)
  1219. (defcustom org-agenda-search-view-always-boolean nil
  1220. "Non-nil means the search string is interpreted as individual parts.
  1221. The search string for search view can either be interpreted as a phrase,
  1222. or as a list of snippets that define a boolean search for a number of
  1223. strings.
  1224. When this is non-nil, the string will be split on whitespace, and each
  1225. snippet will be searched individually, and all must match in order to
  1226. select an entry. A snippet is then a single string of non-white
  1227. characters, or a string in double quotes, or a regexp in {} braces.
  1228. If a snippet is preceded by \"-\", the snippet must *not* match.
  1229. \"+\" is syntactic sugar for positive selection. Each snippet may
  1230. be found as a full word or a partial word, but see the variable
  1231. `org-agenda-search-view-force-full-words'.
  1232. When this is nil, search will look for the entire search phrase as one,
  1233. with each space character matching any amount of whitespace, including
  1234. line breaks.
  1235. Even when this is nil, you can still switch to Boolean search dynamically
  1236. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1237. is a regexp marked with braces like \"{abc}\", this will also switch to
  1238. boolean search."
  1239. :group 'org-agenda-search-view
  1240. :version "24.1"
  1241. :type 'boolean)
  1242. (org-defvaralias 'org-agenda-search-view-search-words-only
  1243. 'org-agenda-search-view-always-boolean)
  1244. (defcustom org-agenda-search-view-force-full-words nil
  1245. "Non-nil means, search words must be matches as complete words.
  1246. When nil, they may also match part of a word."
  1247. :group 'org-agenda-search-view
  1248. :version "24.1"
  1249. :type 'boolean)
  1250. (defcustom org-agenda-search-view-max-outline-level 0
  1251. "Maximum outline level to display in search view.
  1252. E.g. when this is set to 1, the search view will only
  1253. show headlines of level 1. When set to 0, the default
  1254. value, don't limit agenda view by outline level."
  1255. :group 'org-agenda-search-view
  1256. :version "24.4"
  1257. :package-version '(Org . "8.3")
  1258. :type 'integer)
  1259. (defgroup org-agenda-time-grid nil
  1260. "Options concerning the time grid in the Org-mode Agenda."
  1261. :tag "Org Agenda Time Grid"
  1262. :group 'org-agenda)
  1263. (defcustom org-agenda-search-headline-for-time t
  1264. "Non-nil means search headline for a time-of-day.
  1265. If the headline contains a time-of-day in one format or another, it will
  1266. be used to sort the entry into the time sequence of items for a day.
  1267. Some people have time stamps in the headline that refer to the creation
  1268. time or so, and then this produces an unwanted side effect. If this is
  1269. the case for your, use this variable to turn off searching the headline
  1270. for a time."
  1271. :group 'org-agenda-time-grid
  1272. :type 'boolean)
  1273. (defcustom org-agenda-use-time-grid t
  1274. "Non-nil means show a time grid in the agenda schedule.
  1275. A time grid is a set of lines for specific times (like every two hours between
  1276. 8:00 and 20:00). The items scheduled for a day at specific times are
  1277. sorted in between these lines.
  1278. For details about when the grid will be shown, and what it will look like, see
  1279. the variable `org-agenda-time-grid'."
  1280. :group 'org-agenda-time-grid
  1281. :type 'boolean)
  1282. (defcustom org-agenda-time-grid
  1283. '((daily today require-timed)
  1284. "----------------"
  1285. (800 1000 1200 1400 1600 1800 2000))
  1286. "The settings for time grid for agenda display.
  1287. This is a list of three items. The first item is again a list. It contains
  1288. symbols specifying conditions when the grid should be displayed:
  1289. daily if the agenda shows a single day
  1290. weekly if the agenda shows an entire week
  1291. today show grid on current date, independent of daily/weekly display
  1292. require-timed show grid only if at least one item has a time specification
  1293. The second item is a string which will be placed behind the grid time.
  1294. The third item is a list of integers, indicating the times that should have
  1295. a grid line."
  1296. :group 'org-agenda-time-grid
  1297. :type
  1298. '(list
  1299. (set :greedy t :tag "Grid Display Options"
  1300. (const :tag "Show grid in single day agenda display" daily)
  1301. (const :tag "Show grid in weekly agenda display" weekly)
  1302. (const :tag "Always show grid for today" today)
  1303. (const :tag "Show grid only if any timed entries are present"
  1304. require-timed)
  1305. (const :tag "Skip grid times already present in an entry"
  1306. remove-match))
  1307. (string :tag "Grid String")
  1308. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1309. (defcustom org-agenda-show-current-time-in-grid t
  1310. "Non-nil means show the current time in the time grid."
  1311. :group 'org-agenda-time-grid
  1312. :version "24.1"
  1313. :type 'boolean)
  1314. (defcustom org-agenda-current-time-string
  1315. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1316. "The string for the current time marker in the agenda."
  1317. :group 'org-agenda-time-grid
  1318. :version "24.1"
  1319. :type 'string)
  1320. (defgroup org-agenda-sorting nil
  1321. "Options concerning sorting in the Org-mode Agenda."
  1322. :tag "Org Agenda Sorting"
  1323. :group 'org-agenda)
  1324. (defcustom org-agenda-sorting-strategy
  1325. '((agenda habit-down time-up priority-down category-keep)
  1326. (todo priority-down category-keep)
  1327. (tags priority-down category-keep)
  1328. (search category-keep))
  1329. "Sorting structure for the agenda items of a single day.
  1330. This is a list of symbols which will be used in sequence to determine
  1331. if an entry should be listed before another entry. The following
  1332. symbols are recognized:
  1333. time-up Put entries with time-of-day indications first, early first
  1334. time-down Put entries with time-of-day indications first, late first
  1335. timestamp-up Sort by any timestamp, early first
  1336. timestamp-down Sort by any timestamp, late first
  1337. scheduled-up Sort by scheduled timestamp, early first
  1338. scheduled-down Sort by scheduled timestamp, late first
  1339. deadline-up Sort by deadline timestamp, early first
  1340. deadline-down Sort by deadline timestamp, late first
  1341. ts-up Sort by active timestamp, early first
  1342. ts-down Sort by active timestamp, late first
  1343. tsia-up Sort by inactive timestamp, early first
  1344. tsia-down Sort by inactive timestamp, late first
  1345. category-keep Keep the default order of categories, corresponding to the
  1346. sequence in `org-agenda-files'.
  1347. category-up Sort alphabetically by category, A-Z.
  1348. category-down Sort alphabetically by category, Z-A.
  1349. tag-up Sort alphabetically by last tag, A-Z.
  1350. tag-down Sort alphabetically by last tag, Z-A.
  1351. priority-up Sort numerically by priority, high priority last.
  1352. priority-down Sort numerically by priority, high priority first.
  1353. todo-state-up Sort by todo state, tasks that are done last.
  1354. todo-state-down Sort by todo state, tasks that are done first.
  1355. effort-up Sort numerically by estimated effort, high effort last.
  1356. effort-down Sort numerically by estimated effort, high effort first.
  1357. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1358. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1359. habit-up Put entries that are habits first
  1360. habit-down Put entries that are habits last
  1361. alpha-up Sort headlines alphabetically
  1362. alpha-down Sort headlines alphabetically, reversed
  1363. The different possibilities will be tried in sequence, and testing stops
  1364. if one comparison returns a \"not-equal\". For example, the default
  1365. '(time-up category-keep priority-down)
  1366. means: Pull out all entries having a specified time of day and sort them,
  1367. in order to make a time schedule for the current day the first thing in the
  1368. agenda listing for the day. Of the entries without a time indication, keep
  1369. the grouped in categories, don't sort the categories, but keep them in
  1370. the sequence given in `org-agenda-files'. Within each category sort by
  1371. priority.
  1372. Leaving out `category-keep' would mean that items will be sorted across
  1373. categories by priority.
  1374. Instead of a single list, this can also be a set of list for specific
  1375. contents, with a context symbol in the car of the list, any of
  1376. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1377. Custom commands can bind this variable in the options section."
  1378. :group 'org-agenda-sorting
  1379. :type `(choice
  1380. (repeat :tag "General" ,org-sorting-choice)
  1381. (list :tag "Individually"
  1382. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1383. (repeat ,org-sorting-choice))
  1384. (cons (const :tag "Strategy for TODO lists" todo)
  1385. (repeat ,org-sorting-choice))
  1386. (cons (const :tag "Strategy for Tags matches" tags)
  1387. (repeat ,org-sorting-choice))
  1388. (cons (const :tag "Strategy for search matches" search)
  1389. (repeat ,org-sorting-choice)))))
  1390. (defcustom org-agenda-cmp-user-defined nil
  1391. "A function to define the comparison `user-defined'.
  1392. This function must receive two arguments, agenda entry a and b.
  1393. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1394. the user comparison, return nil.
  1395. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1396. part of an agenda sorting strategy."
  1397. :group 'org-agenda-sorting
  1398. :type 'symbol)
  1399. (defcustom org-sort-agenda-notime-is-late t
  1400. "Non-nil means items without time are considered late.
  1401. This is only relevant for sorting. When t, items which have no explicit
  1402. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1403. do have a time. When nil, the default time is before 0:00. You can use this
  1404. option to decide if the schedule for today should come before or after timeless
  1405. agenda entries."
  1406. :group 'org-agenda-sorting
  1407. :type 'boolean)
  1408. (defcustom org-sort-agenda-noeffort-is-high t
  1409. "Non-nil means items without effort estimate are sorted as high effort.
  1410. This also applies when filtering an agenda view with respect to the
  1411. < or > effort operator. Then, tasks with no effort defined will be treated
  1412. as tasks with high effort.
  1413. When nil, such items are sorted as 0 minutes effort."
  1414. :group 'org-agenda-sorting
  1415. :type 'boolean)
  1416. (defgroup org-agenda-line-format nil
  1417. "Options concerning the entry prefix in the Org-mode agenda display."
  1418. :tag "Org Agenda Line Format"
  1419. :group 'org-agenda)
  1420. (defcustom org-agenda-prefix-format
  1421. '((agenda . " %i %-12:c%?-12t% s")
  1422. (timeline . " % s")
  1423. (todo . " %i %-12:c")
  1424. (tags . " %i %-12:c")
  1425. (search . " %i %-12:c"))
  1426. "Format specifications for the prefix of items in the agenda views.
  1427. An alist with five entries, each for the different agenda types. The
  1428. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1429. The values are format strings.
  1430. This format works similar to a printf format, with the following meaning:
  1431. %c the category of the item, \"Diary\" for entries from the diary,
  1432. or as given by the CATEGORY keyword or derived from the file name
  1433. %e the effort required by the item
  1434. %l the level of the item (insert X space(s) if item is of level X)
  1435. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1436. %T the last tag of the item (ignore inherited tags, which come first)
  1437. %t the HH:MM time-of-day specification if one applies to the entry
  1438. %s Scheduling/Deadline information, a short string
  1439. %b show breadcrumbs, i.e., the names of the higher levels
  1440. %(expression) Eval EXPRESSION and replace the control string
  1441. by the result
  1442. All specifiers work basically like the standard `%s' of printf, but may
  1443. contain two additional characters: a question mark just after the `%'
  1444. and a whitespace/punctuation character just before the final letter.
  1445. If the first character after `%' is a question mark, the entire field
  1446. will only be included if the corresponding value applies to the current
  1447. entry. This is useful for fields which should have fixed width when
  1448. present, but zero width when absent. For example, \"%?-12t\" will
  1449. result in a 12 character time field if a time of the day is specified,
  1450. but will completely disappear in entries which do not contain a time.
  1451. If there is punctuation or whitespace character just before the
  1452. final format letter, this character will be appended to the field
  1453. value if the value is not empty. For example, the format
  1454. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1455. the category is empty, no additional colon is inserted.
  1456. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1457. which means:
  1458. - Indent the line with two space characters
  1459. - Give the category a 12 chars wide field, padded with whitespace on
  1460. the right (because of `-'). Append a colon if there is a category
  1461. (because of `:').
  1462. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1463. time, don't put in an empty field, just skip it (because of '?').
  1464. - Finally, put the scheduling information.
  1465. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1466. `org-agenda-remove-tags'.
  1467. Custom commands can set this variable in the options section."
  1468. :type '(choice
  1469. (string :tag "General format")
  1470. (list :greedy t :tag "View dependent"
  1471. (cons (const agenda) (string :tag "Format"))
  1472. (cons (const timeline) (string :tag "Format"))
  1473. (cons (const todo) (string :tag "Format"))
  1474. (cons (const tags) (string :tag "Format"))
  1475. (cons (const search) (string :tag "Format"))))
  1476. :group 'org-agenda-line-format)
  1477. (defvar org-prefix-format-compiled nil
  1478. "The compiled prefix format and associated variables.
  1479. This is a list where first element is a list of variable bindings, and second
  1480. element is the compiled format expression. See the variable
  1481. `org-agenda-prefix-format'.")
  1482. (defcustom org-agenda-todo-keyword-format "%-1s"
  1483. "Format for the TODO keyword in agenda lines.
  1484. Set this to something like \"%-12s\" if you want all TODO keywords
  1485. to occupy a fixed space in the agenda display."
  1486. :group 'org-agenda-line-format
  1487. :type 'string)
  1488. (defcustom org-agenda-diary-sexp-prefix nil
  1489. "A regexp that matches part of a diary sexp entry
  1490. which should be treated as scheduling/deadline information in
  1491. `org-agenda'.
  1492. For example, you can use this to extract the `diary-remind-message' from
  1493. `diary-remind' entries."
  1494. :group 'org-agenda-line-format
  1495. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1496. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1497. "Text preceding timerange entries in the agenda view.
  1498. This is a list with two strings. The first applies when the range
  1499. is entirely on one day. The second applies if the range spans several days.
  1500. The strings may have two \"%d\" format specifiers which will be filled
  1501. with the sequence number of the days, and the total number of days in the
  1502. range, respectively."
  1503. :group 'org-agenda-line-format
  1504. :type '(list
  1505. (string :tag "Deadline today ")
  1506. (choice :tag "Deadline relative"
  1507. (string :tag "Format string")
  1508. (function))))
  1509. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1510. "Text preceding scheduled items in the agenda view.
  1511. This is a list with two strings. The first applies when the item is
  1512. scheduled on the current day. The second applies when it has been scheduled
  1513. previously, it may contain a %d indicating that this is the nth time that
  1514. this item is scheduled, due to automatic rescheduling of unfinished items
  1515. for the following day. So this number is one larger than the number of days
  1516. that passed since this item was scheduled first."
  1517. :group 'org-agenda-line-format
  1518. :version "24.4"
  1519. :package-version '(Org . "8.0")
  1520. :type '(list
  1521. (string :tag "Scheduled today ")
  1522. (string :tag "Scheduled previously")))
  1523. (defcustom org-agenda-inactive-leader "["
  1524. "Text preceding item pulled into the agenda by inactive time stamps.
  1525. These entries are added to the agenda when pressing \"[\"."
  1526. :group 'org-agenda-line-format
  1527. :version "24.1"
  1528. :type 'string)
  1529. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1530. "Text preceding deadline items in the agenda view.
  1531. This is a list with three strings. The first applies when the item has its
  1532. deadline on the current day. The second applies when the deadline is in the
  1533. future, the third one when it is in the past. The strings may contain %d
  1534. to capture the number of days."
  1535. :group 'org-agenda-line-format
  1536. :version "24.4"
  1537. :package-version '(Org . "8.0")
  1538. :type '(list
  1539. (string :tag "Deadline today ")
  1540. (string :tag "Deadline in the future ")
  1541. (string :tag "Deadline in the past ")))
  1542. (defcustom org-agenda-remove-times-when-in-prefix t
  1543. "Non-nil means remove duplicate time specifications in agenda items.
  1544. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1545. time-of-day specification in a headline or diary entry is extracted and
  1546. placed into the prefix. If this option is non-nil, the original specification
  1547. \(a timestamp or -range, or just a plain time(range) specification like
  1548. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1549. cluttered.
  1550. The option can be t or nil. It may also be the symbol `beg', indicating
  1551. that the time should only be removed when it is located at the beginning of
  1552. the headline/diary entry."
  1553. :group 'org-agenda-line-format
  1554. :type '(choice
  1555. (const :tag "Always" t)
  1556. (const :tag "Never" nil)
  1557. (const :tag "When at beginning of entry" beg)))
  1558. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1559. "Non-nil means remove time ranges specifications in agenda
  1560. items that span on several days."
  1561. :group 'org-agenda-line-format
  1562. :version "24.1"
  1563. :type 'boolean)
  1564. (defcustom org-agenda-default-appointment-duration nil
  1565. "Default duration for appointments that only have a starting time.
  1566. When nil, no duration is specified in such cases.
  1567. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1568. :group 'org-agenda-line-format
  1569. :type '(choice
  1570. (integer :tag "Minutes")
  1571. (const :tag "No default duration")))
  1572. (defcustom org-agenda-show-inherited-tags t
  1573. "Non-nil means show inherited tags in each agenda line.
  1574. When this option is set to 'always, it take precedences over
  1575. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1576. in every agenda.
  1577. When this option is set to t (the default), inherited tags are
  1578. shown when they are available, i.e. when the value of
  1579. `org-agenda-use-tag-inheritance' has been taken into account.
  1580. This can be set to a list of agenda types in which the agenda
  1581. must display the inherited tags. Available types are 'todo,
  1582. 'agenda, 'search and 'timeline.
  1583. When set to nil, never show inherited tags in agenda lines."
  1584. :group 'org-agenda-line-format
  1585. :group 'org-agenda
  1586. :version "24.3"
  1587. :type '(choice
  1588. (const :tag "Show inherited tags when available" t)
  1589. (const :tag "Always show inherited tags" always)
  1590. (repeat :tag "Show inherited tags only in selected agenda types"
  1591. (symbol :tag "Agenda type"))))
  1592. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1593. "List of agenda view types where to use tag inheritance.
  1594. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1595. controlled by `org-use-tag-inheritance'. In other agenda types,
  1596. `org-use-tag-inheritance' is not used for the selection of the
  1597. agenda entries. Still, you may want the agenda to be aware of
  1598. the inherited tags anyway, e.g. for later tag filtering.
  1599. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1600. This variable has no effect if `org-agenda-show-inherited-tags'
  1601. is set to 'always. In that case, the agenda is aware of those
  1602. tags.
  1603. The default value sets tags in every agenda type. Setting this
  1604. option to nil will speed up non-tags agenda view a lot."
  1605. :group 'org-agenda
  1606. :version "24.3"
  1607. :type '(choice
  1608. (const :tag "Use tag inheritance in all agenda types" t)
  1609. (repeat :tag "Use tag inheritance in selected agenda types"
  1610. (symbol :tag "Agenda type"))))
  1611. (defcustom org-agenda-hide-tags-regexp nil
  1612. "Regular expression used to filter away specific tags in agenda views.
  1613. This means that these tags will be present, but not be shown in the agenda
  1614. line. Secondary filtering will still work on the hidden tags.
  1615. Nil means don't hide any tags."
  1616. :group 'org-agenda-line-format
  1617. :type '(choice
  1618. (const :tag "Hide none" nil)
  1619. (string :tag "Regexp ")))
  1620. (defcustom org-agenda-remove-tags nil
  1621. "Non-nil means remove the tags from the headline copy in the agenda.
  1622. When this is the symbol `prefix', only remove tags when
  1623. `org-agenda-prefix-format' contains a `%T' specifier."
  1624. :group 'org-agenda-line-format
  1625. :type '(choice
  1626. (const :tag "Always" t)
  1627. (const :tag "Never" nil)
  1628. (const :tag "When prefix format contains %T" prefix)))
  1629. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1630. 'org-agenda-remove-tags)
  1631. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1632. "Shift tags in agenda items to this column.
  1633. If this number is positive, it specifies the column. If it is negative,
  1634. it means that the tags should be flushright to that column. For example,
  1635. -80 works well for a normal 80 character screen."
  1636. :group 'org-agenda-line-format
  1637. :type 'integer)
  1638. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1639. (defcustom org-agenda-fontify-priorities 'cookies
  1640. "Non-nil means highlight low and high priorities in agenda.
  1641. When t, the highest priority entries are bold, lowest priority italic.
  1642. However, settings in `org-priority-faces' will overrule these faces.
  1643. When this variable is the symbol `cookies', only fontify the
  1644. cookies, not the entire task.
  1645. This may also be an association list of priority faces, whose
  1646. keys are the character values of `org-highest-priority',
  1647. `org-default-priority', and `org-lowest-priority' (the default values
  1648. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1649. color as a string, or a list like `(:background \"Red\")'.
  1650. If it is a color, the variable `org-faces-easy-properties'
  1651. determines if it is a foreground or a background color."
  1652. :group 'org-agenda-line-format
  1653. :type '(choice
  1654. (const :tag "Never" nil)
  1655. (const :tag "Defaults" t)
  1656. (const :tag "Cookies only" cookies)
  1657. (repeat :tag "Specify"
  1658. (list (character :tag "Priority" :value ?A)
  1659. (choice :tag "Face "
  1660. (string :tag "Color")
  1661. (sexp :tag "Face"))))))
  1662. (defcustom org-agenda-day-face-function nil
  1663. "Function called to determine what face should be used to display a day.
  1664. The only argument passed to that function is the day. It should
  1665. returns a face, or nil if does not want to specify a face and let
  1666. the normal rules apply."
  1667. :group 'org-agenda-line-format
  1668. :version "24.1"
  1669. :type '(choice (const nil) (function)))
  1670. (defcustom org-agenda-category-icon-alist nil
  1671. "Alist of category icon to be displayed in agenda views.
  1672. Each entry should have the following format:
  1673. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1674. Where CATEGORY-REGEXP is a regexp matching the categories where
  1675. the icon should be displayed.
  1676. FILE-OR-DATA either a file path or a string containing image data.
  1677. The other fields can be omitted safely if not needed:
  1678. TYPE indicates the image type.
  1679. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1680. image data.
  1681. PROPS are additional image attributes to assign to the image,
  1682. like, e.g. `:ascent center'.
  1683. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1684. If you want to set the display properties yourself, just put a
  1685. list as second element:
  1686. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1687. For example, to display a 16px horizontal space for Emacs
  1688. category, you can use:
  1689. (\"Emacs\" '(space . (:width (16))))"
  1690. :group 'org-agenda-line-format
  1691. :version "24.1"
  1692. :type '(alist :key-type (string :tag "Regexp matching category")
  1693. :value-type (choice (list :tag "Icon"
  1694. (string :tag "File or data")
  1695. (symbol :tag "Type")
  1696. (boolean :tag "Data?")
  1697. (repeat :tag "Extra image properties" :inline t symbol))
  1698. (list :tag "Display properties" sexp))))
  1699. (defgroup org-agenda-column-view nil
  1700. "Options concerning column view in the agenda."
  1701. :tag "Org Agenda Column View"
  1702. :group 'org-agenda)
  1703. (defcustom org-agenda-columns-show-summaries t
  1704. "Non-nil means show summaries for columns displayed in the agenda view."
  1705. :group 'org-agenda-column-view
  1706. :type 'boolean)
  1707. (defcustom org-agenda-columns-compute-summary-properties t
  1708. "Non-nil means recompute all summary properties before column view.
  1709. When column view in the agenda is listing properties that have a summary
  1710. operator, it can go to all relevant buffers and recompute the summaries
  1711. there. This can mean overhead for the agenda column view, but is necessary
  1712. to have thing up to date.
  1713. As a special case, a CLOCKSUM property also makes sure that the clock
  1714. computations are current."
  1715. :group 'org-agenda-column-view
  1716. :type 'boolean)
  1717. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1718. "Non-nil means the duration of an appointment will add to day effort.
  1719. The property to which appointment durations will be added is the one given
  1720. in the option `org-effort-property'. If an appointment does not have
  1721. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1722. is not set, an appointment without end time will not contribute to the time
  1723. estimate."
  1724. :group 'org-agenda-column-view
  1725. :type 'boolean)
  1726. (defcustom org-agenda-auto-exclude-function nil
  1727. "A function called with a tag to decide if it is filtered on '/ RET'.
  1728. The sole argument to the function, which is called once for each
  1729. possible tag, is a string giving the name of the tag. The
  1730. function should return either nil if the tag should be included
  1731. as normal, or \"-<TAG>\" to exclude the tag.
  1732. Note that for the purpose of tag filtering, only the lower-case version of
  1733. all tags will be considered, so that this function will only ever see
  1734. the lower-case version of all tags."
  1735. :group 'org-agenda
  1736. :type '(choice (const nil) (function)))
  1737. (defcustom org-agenda-bulk-custom-functions nil
  1738. "Alist of characters and custom functions for bulk actions.
  1739. For example, this value makes those two functions available:
  1740. '((?R set-category)
  1741. (?C bulk-cut))
  1742. With selected entries in an agenda buffer, `B R' will call
  1743. the custom function `set-category' on the selected entries.
  1744. Note that functions in this alist don't need to be quoted."
  1745. :type 'alist
  1746. :version "24.1"
  1747. :group 'org-agenda)
  1748. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1749. "Execute BODY with point at location given by `org-hd-marker' property.
  1750. If STRING is non-nil, the text property will be fetched from position 0
  1751. in that string. If STRING is nil, it will be fetched from the beginning
  1752. of the current line."
  1753. (org-with-gensyms (marker)
  1754. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1755. 'org-hd-marker ,string)))
  1756. (with-current-buffer (marker-buffer ,marker)
  1757. (save-excursion
  1758. (goto-char ,marker)
  1759. ,@body)))))
  1760. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1761. (defun org-add-agenda-custom-command (entry)
  1762. "Replace or add a command in `org-agenda-custom-commands'.
  1763. This is mostly for hacking and trying a new command - once the command
  1764. works you probably want to add it to `org-agenda-custom-commands' for good."
  1765. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1766. (if ass
  1767. (setcdr ass (cdr entry))
  1768. (push entry org-agenda-custom-commands))))
  1769. ;;; Define the org-agenda-mode
  1770. (defvar org-agenda-mode-map (make-sparse-keymap)
  1771. "Keymap for `org-agenda-mode'.")
  1772. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1773. (defvar org-agenda-menu) ; defined later in this file.
  1774. (defvar org-agenda-restrict nil) ; defined later in this file.
  1775. (defvar org-agenda-follow-mode nil)
  1776. (defvar org-agenda-entry-text-mode nil)
  1777. (defvar org-agenda-clockreport-mode nil)
  1778. (defvar org-agenda-show-log nil)
  1779. (defvar org-agenda-redo-command nil)
  1780. (defvar org-agenda-query-string nil)
  1781. (defvar org-agenda-mode-hook nil
  1782. "Hook run after `org-agenda-mode' is turned on.
  1783. The buffer is still writable when this hook is called.")
  1784. (defvar org-agenda-type nil)
  1785. (defvar org-agenda-force-single-file nil)
  1786. (defvar org-agenda-bulk-marked-entries nil
  1787. "List of markers that refer to marked entries in the agenda.")
  1788. ;;; Multiple agenda buffers support
  1789. (defcustom org-agenda-sticky nil
  1790. "Non-nil means agenda q key will bury agenda buffers.
  1791. Agenda commands will then show existing buffer instead of generating new ones.
  1792. When nil, `q' will kill the single agenda buffer."
  1793. :group 'org-agenda
  1794. :version "24.3"
  1795. :type 'boolean)
  1796. ;;;###autoload
  1797. (defun org-toggle-sticky-agenda (&optional arg)
  1798. "Toggle `org-agenda-sticky'."
  1799. (interactive "P")
  1800. (let ((new-value (if arg
  1801. (> (prefix-numeric-value arg) 0)
  1802. (not org-agenda-sticky))))
  1803. (if (equal new-value org-agenda-sticky)
  1804. (and (org-called-interactively-p 'interactive)
  1805. (message "Sticky agenda was already %s"
  1806. (if org-agenda-sticky "enabled" "disabled")))
  1807. (setq org-agenda-sticky new-value)
  1808. (org-agenda-kill-all-agenda-buffers)
  1809. (and (org-called-interactively-p 'interactive)
  1810. (message "Sticky agenda was %s"
  1811. (if org-agenda-sticky "enabled" "disabled"))))))
  1812. (defvar org-agenda-buffer nil
  1813. "Agenda buffer currently being generated.")
  1814. (defvar org-agenda-last-prefix-arg nil)
  1815. (defvar org-agenda-this-buffer-name nil)
  1816. (defvar org-agenda-doing-sticky-redo nil)
  1817. (defvar org-agenda-this-buffer-is-sticky nil)
  1818. (defconst org-agenda-local-vars
  1819. '(org-agenda-this-buffer-name
  1820. org-agenda-undo-list
  1821. org-agenda-pending-undo-list
  1822. org-agenda-follow-mode
  1823. org-agenda-entry-text-mode
  1824. org-agenda-clockreport-mode
  1825. org-agenda-show-log
  1826. org-agenda-redo-command
  1827. org-agenda-query-string
  1828. org-agenda-type
  1829. org-agenda-bulk-marked-entries
  1830. org-agenda-undo-has-started-in
  1831. org-agenda-info
  1832. org-agenda-pre-window-conf
  1833. org-agenda-columns-active
  1834. org-agenda-tag-filter-overlays
  1835. org-agenda-tag-filter
  1836. org-agenda-cat-filter-overlays
  1837. org-agenda-category-filter
  1838. org-agenda-re-filter-overlays
  1839. org-agenda-regexp-filter
  1840. org-agenda-markers
  1841. org-agenda-last-search-view-search-was-boolean
  1842. org-agenda-filtered-by-category
  1843. org-agenda-filter-form
  1844. org-agenda-cycle-counter
  1845. org-agenda-last-prefix-arg)
  1846. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1847. (defun org-agenda-mode ()
  1848. "Mode for time-sorted view on action items in Org-mode files.
  1849. The following commands are available:
  1850. \\{org-agenda-mode-map}"
  1851. (interactive)
  1852. (cond (org-agenda-doing-sticky-redo
  1853. ;; Refreshing sticky agenda-buffer
  1854. ;;
  1855. ;; Preserve the value of `org-agenda-local-vars' variables,
  1856. ;; while letting `kill-all-local-variables' kill the rest
  1857. (let ((save (buffer-local-variables)))
  1858. (kill-all-local-variables)
  1859. (mapc 'make-local-variable org-agenda-local-vars)
  1860. (dolist (elem save)
  1861. (let ((var (car elem))
  1862. (val (cdr elem)))
  1863. (when (and val
  1864. (member var org-agenda-local-vars))
  1865. (set var val)))))
  1866. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1867. (org-agenda-sticky
  1868. ;; Creating a sticky Agenda buffer for the first time
  1869. (kill-all-local-variables)
  1870. (mapc 'make-local-variable org-agenda-local-vars)
  1871. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1872. (t
  1873. ;; Creating a non-sticky agenda buffer
  1874. (kill-all-local-variables)
  1875. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1876. (setq org-agenda-undo-list nil
  1877. org-agenda-pending-undo-list nil
  1878. org-agenda-bulk-marked-entries nil)
  1879. (setq major-mode 'org-agenda-mode)
  1880. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1881. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1882. (setq mode-name "Org-Agenda")
  1883. (setq indent-tabs-mode nil)
  1884. (use-local-map org-agenda-mode-map)
  1885. (easy-menu-add org-agenda-menu)
  1886. (if org-startup-truncated (setq truncate-lines t))
  1887. (org-set-local 'line-move-visual nil)
  1888. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1889. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1890. ;; Make sure properties are removed when copying text
  1891. (org-add-hook 'filter-buffer-substring-functions
  1892. (lambda (fun start end delete)
  1893. (substring-no-properties (funcall fun start end delete)))
  1894. nil t)
  1895. (unless org-agenda-keep-modes
  1896. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1897. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1898. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1899. org-agenda-show-log org-agenda-start-with-log-mode))
  1900. (easy-menu-change
  1901. '("Agenda") "Agenda Files"
  1902. (append
  1903. (list
  1904. (vector
  1905. (if (get 'org-agenda-files 'org-restrict)
  1906. "Restricted to single file"
  1907. "Edit File List")
  1908. '(org-edit-agenda-file-list)
  1909. (not (get 'org-agenda-files 'org-restrict)))
  1910. "--")
  1911. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1912. (org-agenda-set-mode-name)
  1913. (apply
  1914. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1915. (list 'org-agenda-mode-hook)))
  1916. (substitute-key-definition 'undo 'org-agenda-undo
  1917. org-agenda-mode-map global-map)
  1918. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1919. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1920. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1921. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1922. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1923. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1924. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1925. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1926. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1927. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1928. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1929. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1930. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1931. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1932. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1933. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1934. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1935. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1936. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1940. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1941. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1942. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1943. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1944. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1945. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1946. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1947. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1948. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1949. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1950. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1951. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1952. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1953. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1954. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1955. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1956. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1957. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1958. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1959. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1960. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1961. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1962. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1963. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1964. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1965. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1966. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1967. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1968. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1969. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1970. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1971. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1972. (while l (org-defkey org-agenda-mode-map
  1973. (int-to-string (pop l)) 'digit-argument)))
  1974. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1975. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1976. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1977. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1978. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1979. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1980. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1981. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1982. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1983. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1984. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1985. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1986. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1987. 'org-clock-modify-effort-estimate)
  1988. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1989. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1990. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1991. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1992. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1993. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1994. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1995. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1996. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1997. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1998. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1999. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2000. (substitute-key-definition 'next-line 'org-agenda-next-line
  2001. org-agenda-mode-map global-map)
  2002. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2003. org-agenda-mode-map global-map)
  2004. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2005. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2006. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2007. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2008. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2009. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2010. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2011. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2012. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2013. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2014. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2015. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2016. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2017. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2018. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2019. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2021. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2022. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2023. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2024. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2025. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2026. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2027. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2028. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2029. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2030. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2031. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2033. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2034. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2035. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2036. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2037. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2038. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2039. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2040. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2041. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2042. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2043. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2044. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2045. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2046. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2048. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2049. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2050. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2051. (when org-agenda-mouse-1-follows-link
  2052. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2053. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2054. '("Agenda"
  2055. ("Agenda Files")
  2056. "--"
  2057. ("Agenda Dates"
  2058. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2059. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2060. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2061. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2062. "--"
  2063. ("View"
  2064. ["Day View" org-agenda-day-view
  2065. :active (org-agenda-check-type nil 'agenda)
  2066. :style radio :selected (eq org-agenda-current-span 'day)
  2067. :keys "v d (or just d)"]
  2068. ["Week View" org-agenda-week-view
  2069. :active (org-agenda-check-type nil 'agenda)
  2070. :style radio :selected (eq org-agenda-current-span 'week)
  2071. :keys "v w"]
  2072. ["Fortnight View" org-agenda-fortnight-view
  2073. :active (org-agenda-check-type nil 'agenda)
  2074. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2075. :keys "v f"]
  2076. ["Month View" org-agenda-month-view
  2077. :active (org-agenda-check-type nil 'agenda)
  2078. :style radio :selected (eq org-agenda-current-span 'month)
  2079. :keys "v m"]
  2080. ["Year View" org-agenda-year-view
  2081. :active (org-agenda-check-type nil 'agenda)
  2082. :style radio :selected (eq org-agenda-current-span 'year)
  2083. :keys "v y"]
  2084. "--"
  2085. ["Include Diary" org-agenda-toggle-diary
  2086. :style toggle :selected org-agenda-include-diary
  2087. :active (org-agenda-check-type nil 'agenda)]
  2088. ["Include Deadlines" org-agenda-toggle-deadlines
  2089. :style toggle :selected org-agenda-include-deadlines
  2090. :active (org-agenda-check-type nil 'agenda)]
  2091. ["Use Time Grid" org-agenda-toggle-time-grid
  2092. :style toggle :selected org-agenda-use-time-grid
  2093. :active (org-agenda-check-type nil 'agenda)]
  2094. "--"
  2095. ["Show clock report" org-agenda-clockreport-mode
  2096. :style toggle :selected org-agenda-clockreport-mode
  2097. :active (org-agenda-check-type nil 'agenda)]
  2098. ["Show some entry text" org-agenda-entry-text-mode
  2099. :style toggle :selected org-agenda-entry-text-mode
  2100. :active t]
  2101. "--"
  2102. ["Show Logbook entries" org-agenda-log-mode
  2103. :style toggle :selected org-agenda-show-log
  2104. :active (org-agenda-check-type nil 'agenda 'timeline)
  2105. :keys "v l (or just l)"]
  2106. ["Include archived trees" org-agenda-archives-mode
  2107. :style toggle :selected org-agenda-archives-mode :active t
  2108. :keys "v a"]
  2109. ["Include archive files" (org-agenda-archives-mode t)
  2110. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2111. :keys "v A"]
  2112. "--"
  2113. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2114. ["Write view to file" org-agenda-write t]
  2115. ["Rebuild buffer" org-agenda-redo t]
  2116. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2117. "--"
  2118. ["Show original entry" org-agenda-show t]
  2119. ["Go To (other window)" org-agenda-goto t]
  2120. ["Go To (this window)" org-agenda-switch-to t]
  2121. ["Capture with cursor date" org-agenda-capture t]
  2122. ["Follow Mode" org-agenda-follow-mode
  2123. :style toggle :selected org-agenda-follow-mode :active t]
  2124. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2125. "--"
  2126. ("TODO"
  2127. ["Cycle TODO" org-agenda-todo t]
  2128. ["Next TODO set" org-agenda-todo-nextset t]
  2129. ["Previous TODO set" org-agenda-todo-previousset t]
  2130. ["Add note" org-agenda-add-note t])
  2131. ("Archive/Refile/Delete"
  2132. ["Archive default" org-agenda-archive-default t]
  2133. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2134. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2135. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2136. ["Archive subtree" org-agenda-archive t]
  2137. "--"
  2138. ["Refile" org-agenda-refile t]
  2139. "--"
  2140. ["Delete subtree" org-agenda-kill t])
  2141. ("Bulk action"
  2142. ["Mark entry" org-agenda-bulk-mark t]
  2143. ["Mark all" org-agenda-bulk-mark-all t]
  2144. ["Unmark entry" org-agenda-bulk-unmark t]
  2145. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2146. ["Toggle mark" org-agenda-bulk-toggle t]
  2147. ["Toggle all" org-agenda-bulk-toggle-all t]
  2148. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2149. ["Act on all marked" org-agenda-bulk-action t]
  2150. "--"
  2151. ("Tags and Properties"
  2152. ["Show all Tags" org-agenda-show-tags t]
  2153. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2154. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2155. "--"
  2156. ["Column View" org-columns t])
  2157. ("Deadline/Schedule"
  2158. ["Schedule" org-agenda-schedule t]
  2159. ["Set Deadline" org-agenda-deadline t]
  2160. "--"
  2161. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2162. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2163. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2164. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2165. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2166. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2167. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2168. ("Clock and Effort"
  2169. ["Clock in" org-agenda-clock-in t]
  2170. ["Clock out" org-agenda-clock-out t]
  2171. ["Clock cancel" org-agenda-clock-cancel t]
  2172. ["Goto running clock" org-clock-goto t]
  2173. "--"
  2174. ["Set Effort" org-agenda-set-effort t]
  2175. ["Change clocked effort" org-clock-modify-effort-estimate
  2176. (org-clock-is-active)])
  2177. ("Priority"
  2178. ["Set Priority" org-agenda-priority t]
  2179. ["Increase Priority" org-agenda-priority-up t]
  2180. ["Decrease Priority" org-agenda-priority-down t]
  2181. ["Show Priority" org-show-priority t])
  2182. ("Calendar/Diary"
  2183. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2184. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2185. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2186. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2188. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2189. "--"
  2190. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2191. "--"
  2192. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2193. "--"
  2194. ("MobileOrg"
  2195. ["Push Files and Views" org-mobile-push t]
  2196. ["Get Captured and Flagged" org-mobile-pull t]
  2197. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2198. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2199. "--"
  2200. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2201. "--"
  2202. ["Quit" org-agenda-quit t]
  2203. ["Exit and Release Buffers" org-agenda-exit t]
  2204. ))
  2205. ;;; Agenda undo
  2206. (defvar org-agenda-allow-remote-undo t
  2207. "Non-nil means allow remote undo from the agenda buffer.")
  2208. (defvar org-agenda-undo-has-started-in nil
  2209. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2210. (defun org-agenda-undo ()
  2211. "Undo a remote editing step in the agenda.
  2212. This undoes changes both in the agenda buffer and in the remote buffer
  2213. that have been changed along."
  2214. (interactive)
  2215. (or org-agenda-allow-remote-undo
  2216. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2217. (if (not (eq this-command last-command))
  2218. (setq org-agenda-undo-has-started-in nil
  2219. org-agenda-pending-undo-list org-agenda-undo-list))
  2220. (if (not org-agenda-pending-undo-list)
  2221. (user-error "No further undo information"))
  2222. (let* ((entry (pop org-agenda-pending-undo-list))
  2223. buf line cmd rembuf)
  2224. (setq cmd (pop entry) line (pop entry))
  2225. (setq rembuf (nth 2 entry))
  2226. (org-with-remote-undo rembuf
  2227. (while (bufferp (setq buf (pop entry)))
  2228. (if (pop entry)
  2229. (with-current-buffer buf
  2230. (let ((last-undo-buffer buf)
  2231. (inhibit-read-only t))
  2232. (unless (memq buf org-agenda-undo-has-started-in)
  2233. (push buf org-agenda-undo-has-started-in)
  2234. (make-local-variable 'pending-undo-list)
  2235. (undo-start))
  2236. (while (and pending-undo-list
  2237. (listp pending-undo-list)
  2238. (not (car pending-undo-list)))
  2239. (pop pending-undo-list))
  2240. (undo-more 1))))))
  2241. (org-goto-line line)
  2242. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2243. (defun org-verify-change-for-undo (l1 l2)
  2244. "Verify that a real change occurred between the undo lists L1 and L2."
  2245. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2246. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2247. (not (eq l1 l2)))
  2248. ;;; Agenda dispatch
  2249. (defvar org-agenda-restrict-begin (make-marker))
  2250. (defvar org-agenda-restrict-end (make-marker))
  2251. (defvar org-agenda-last-dispatch-buffer nil)
  2252. (defvar org-agenda-overriding-restriction nil)
  2253. (defcustom org-agenda-custom-commands-contexts nil
  2254. "Alist of custom agenda keys and contextual rules.
  2255. For example, if you have a custom agenda command \"p\" and you
  2256. want this command to be accessible only from plain text files,
  2257. use this:
  2258. '((\"p\" ((in-file . \"\\.txt\"))))
  2259. Here are the available contexts definitions:
  2260. in-file: command displayed only in matching files
  2261. in-mode: command displayed only in matching modes
  2262. not-in-file: command not displayed in matching files
  2263. not-in-mode: command not displayed in matching modes
  2264. in-buffer: command displayed only in matching buffers
  2265. not-in-buffer: command not displayed in matching buffers
  2266. [function]: a custom function taking no argument
  2267. If you define several checks, the agenda command will be
  2268. accessible if there is at least one valid check.
  2269. You can also bind a key to another agenda custom command
  2270. depending on contextual rules.
  2271. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2272. Here it means: in .txt files, use \"p\" as the key for the
  2273. agenda command otherwise associated with \"q\". (The command
  2274. originally associated with \"q\" is not displayed to avoid
  2275. duplicates.)"
  2276. :version "24.3"
  2277. :group 'org-agenda-custom-commands
  2278. :type '(repeat (list :tag "Rule"
  2279. (string :tag " Agenda key")
  2280. (string :tag "Replace by command")
  2281. (repeat :tag "Available when"
  2282. (choice
  2283. (cons :tag "Condition"
  2284. (choice
  2285. (const :tag "In file" in-file)
  2286. (const :tag "Not in file" not-in-file)
  2287. (const :tag "In buffer" in-buffer)
  2288. (const :tag "Not in buffer" not-in-buffer)
  2289. (const :tag "In mode" in-mode)
  2290. (const :tag "Not in mode" not-in-mode))
  2291. (regexp))
  2292. (function :tag "Custom function"))))))
  2293. (defcustom org-agenda-max-entries nil
  2294. "Maximum number of entries to display in an agenda.
  2295. This can be nil (no limit) or an integer or an alist of agenda
  2296. types with an associated number of entries to display in this
  2297. type."
  2298. :version "24.4"
  2299. :package-version '(Org . "8.0")
  2300. :group 'org-agenda-custom-commands
  2301. :type '(choice (symbol :tag "No limit" nil)
  2302. (integer :tag "Max number of entries")
  2303. (repeat
  2304. (cons (choice :tag "Agenda type"
  2305. (const agenda)
  2306. (const todo)
  2307. (const tags)
  2308. (const search)
  2309. (const timeline))
  2310. (integer :tag "Max number of entries")))))
  2311. (defcustom org-agenda-max-todos nil
  2312. "Maximum number of TODOs to display in an agenda.
  2313. This can be nil (no limit) or an integer or an alist of agenda
  2314. types with an associated number of entries to display in this
  2315. type."
  2316. :version "24.4"
  2317. :package-version '(Org . "8.0")
  2318. :group 'org-agenda-custom-commands
  2319. :type '(choice (symbol :tag "No limit" nil)
  2320. (integer :tag "Max number of TODOs")
  2321. (repeat
  2322. (cons (choice :tag "Agenda type"
  2323. (const agenda)
  2324. (const todo)
  2325. (const tags)
  2326. (const search)
  2327. (const timeline))
  2328. (integer :tag "Max number of TODOs")))))
  2329. (defcustom org-agenda-max-tags nil
  2330. "Maximum number of tagged entries to display in an agenda.
  2331. This can be nil (no limit) or an integer or an alist of agenda
  2332. types with an associated number of entries to display in this
  2333. type."
  2334. :version "24.4"
  2335. :package-version '(Org . "8.0")
  2336. :group 'org-agenda-custom-commands
  2337. :type '(choice (symbol :tag "No limit" nil)
  2338. (integer :tag "Max number of tagged entries")
  2339. (repeat
  2340. (cons (choice :tag "Agenda type"
  2341. (const agenda)
  2342. (const todo)
  2343. (const tags)
  2344. (const search)
  2345. (const timeline))
  2346. (integer :tag "Max number of tagged entries")))))
  2347. (defcustom org-agenda-max-effort nil
  2348. "Maximum cumulated effort duration for the agenda.
  2349. This can be nil (no limit) or a number of minutes (as an integer)
  2350. or an alist of agenda types with an associated number of minutes
  2351. to limit entries to in this type."
  2352. :version "24.4"
  2353. :package-version '(Org . "8.0")
  2354. :group 'org-agenda-custom-commands
  2355. :type '(choice (symbol :tag "No limit" nil)
  2356. (integer :tag "Max number of minutes")
  2357. (repeat
  2358. (cons (choice :tag "Agenda type"
  2359. (const agenda)
  2360. (const todo)
  2361. (const tags)
  2362. (const search)
  2363. (const timeline))
  2364. (integer :tag "Max number of minutes")))))
  2365. (defvar org-keys nil)
  2366. (defvar org-match nil)
  2367. ;;;###autoload
  2368. (defun org-agenda (&optional arg org-keys restriction)
  2369. "Dispatch agenda commands to collect entries to the agenda buffer.
  2370. Prompts for a command to execute. Any prefix arg will be passed
  2371. on to the selected command. The default selections are:
  2372. a Call `org-agenda-list' to display the agenda for current day or week.
  2373. t Call `org-todo-list' to display the global todo list.
  2374. T Call `org-todo-list' to display the global todo list, select only
  2375. entries with a specific TODO keyword (the user gets a prompt).
  2376. m Call `org-tags-view' to display headlines with tags matching
  2377. a condition (the user is prompted for the condition).
  2378. M Like `m', but select only TODO entries, no ordinary headlines.
  2379. L Create a timeline for the current buffer.
  2380. e Export views to associated files.
  2381. s Search entries for keywords.
  2382. S Search entries for keywords, only with TODO keywords.
  2383. / Multi occur across all agenda files and also files listed
  2384. in `org-agenda-text-search-extra-files'.
  2385. < Restrict agenda commands to buffer, subtree, or region.
  2386. Press several times to get the desired effect.
  2387. > Remove a previous restriction.
  2388. # List \"stuck\" projects.
  2389. ! Configure what \"stuck\" means.
  2390. C Configure custom agenda commands.
  2391. More commands can be added by configuring the variable
  2392. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2393. searches can be pre-defined in this way.
  2394. If the current buffer is in Org-mode and visiting a file, you can also
  2395. first press `<' once to indicate that the agenda should be temporarily
  2396. \(until the next use of \\[org-agenda]) restricted to the current file.
  2397. Pressing `<' twice means to restrict to the current subtree or region
  2398. \(if active)."
  2399. (interactive "P")
  2400. (catch 'exit
  2401. (let* ((prefix-descriptions nil)
  2402. (org-agenda-buffer-name org-agenda-buffer-name)
  2403. (org-agenda-window-setup (if (equal (buffer-name)
  2404. org-agenda-buffer-name)
  2405. 'current-window
  2406. org-agenda-window-setup))
  2407. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2408. (org-agenda-custom-commands
  2409. ;; normalize different versions
  2410. (delq nil
  2411. (mapcar
  2412. (lambda (x)
  2413. (cond ((stringp (cdr x))
  2414. (push x prefix-descriptions)
  2415. nil)
  2416. ((stringp (nth 1 x)) x)
  2417. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2418. (t (cons (car x) (cons "" (cdr x))))))
  2419. org-agenda-custom-commands)))
  2420. (org-agenda-custom-commands
  2421. (org-contextualize-keys
  2422. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2423. (buf (current-buffer))
  2424. (bfn (buffer-file-name (buffer-base-buffer)))
  2425. entry key type org-match lprops ans)
  2426. ;; Turn off restriction unless there is an overriding one,
  2427. (unless org-agenda-overriding-restriction
  2428. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2429. ;; There is a request to keep the file list in place
  2430. (put 'org-agenda-files 'org-restrict nil))
  2431. (setq org-agenda-restrict nil)
  2432. (move-marker org-agenda-restrict-begin nil)
  2433. (move-marker org-agenda-restrict-end nil))
  2434. ;; Delete old local properties
  2435. (put 'org-agenda-redo-command 'org-lprops nil)
  2436. ;; Delete previously set last-arguments
  2437. (put 'org-agenda-redo-command 'last-args nil)
  2438. ;; Remember where this call originated
  2439. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2440. (unless org-keys
  2441. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2442. org-keys (car ans)
  2443. restriction (cdr ans)))
  2444. ;; If we have sticky agenda buffers, set a name for the buffer,
  2445. ;; depending on the invoking keys. The user may still set this
  2446. ;; as a command option, which will overwrite what we do here.
  2447. (if org-agenda-sticky
  2448. (setq org-agenda-buffer-name
  2449. (format "*Org Agenda(%s)*" org-keys)))
  2450. ;; Establish the restriction, if any
  2451. (when (and (not org-agenda-overriding-restriction) restriction)
  2452. (put 'org-agenda-files 'org-restrict (list bfn))
  2453. (cond
  2454. ((eq restriction 'region)
  2455. (setq org-agenda-restrict (current-buffer))
  2456. (move-marker org-agenda-restrict-begin (region-beginning))
  2457. (move-marker org-agenda-restrict-end (region-end)))
  2458. ((eq restriction 'subtree)
  2459. (save-excursion
  2460. (setq org-agenda-restrict (current-buffer))
  2461. (org-back-to-heading t)
  2462. (move-marker org-agenda-restrict-begin (point))
  2463. (move-marker org-agenda-restrict-end
  2464. (progn (org-end-of-subtree t)))))))
  2465. ;; For example the todo list should not need it (but does...)
  2466. (cond
  2467. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2468. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2469. (progn
  2470. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2471. lprops (nth 4 entry))
  2472. (if org-agenda-sticky
  2473. (setq org-agenda-buffer-name
  2474. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2475. (format "*Org Agenda(%s)*" org-keys))))
  2476. (put 'org-agenda-redo-command 'org-lprops lprops)
  2477. (cond
  2478. ((eq type 'agenda)
  2479. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2480. ((eq type 'agenda*)
  2481. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2482. ((eq type 'alltodo)
  2483. (org-let lprops '(org-todo-list current-prefix-arg)))
  2484. ((eq type 'search)
  2485. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2486. ((eq type 'stuck)
  2487. (org-let lprops '(org-agenda-list-stuck-projects
  2488. current-prefix-arg)))
  2489. ((eq type 'tags)
  2490. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2491. ((eq type 'tags-todo)
  2492. (org-let lprops '(org-tags-view '(4) org-match)))
  2493. ((eq type 'todo)
  2494. (org-let lprops '(org-todo-list org-match)))
  2495. ((eq type 'tags-tree)
  2496. (org-check-for-org-mode)
  2497. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2498. ((eq type 'todo-tree)
  2499. (org-check-for-org-mode)
  2500. (org-let lprops
  2501. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2502. (regexp-quote org-match) "\\>"))))
  2503. ((eq type 'occur-tree)
  2504. (org-check-for-org-mode)
  2505. (org-let lprops '(org-occur org-match)))
  2506. ((functionp type)
  2507. (org-let lprops '(funcall type org-match)))
  2508. ((fboundp type)
  2509. (org-let lprops '(funcall type org-match)))
  2510. (t (user-error "Invalid custom agenda command type %s" type))))
  2511. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2512. ((equal org-keys "C")
  2513. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2514. (customize-variable 'org-agenda-custom-commands))
  2515. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2516. ((equal org-keys "s") (call-interactively 'org-search-view))
  2517. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2518. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2519. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2520. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2521. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2522. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2523. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2524. (org-add-hook
  2525. 'post-command-hook
  2526. (lambda ()
  2527. (unless (current-message)
  2528. (let* ((m (org-agenda-get-any-marker))
  2529. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2530. (when note
  2531. (message (concat
  2532. "FLAGGING-NOTE ([?] for more info): "
  2533. (org-add-props
  2534. (replace-regexp-in-string
  2535. "\\\\n" "//"
  2536. (copy-sequence note))
  2537. nil 'face 'org-warning)))))))
  2538. t t))
  2539. ((equal org-keys "L")
  2540. (unless (derived-mode-p 'org-mode)
  2541. (user-error "This is not an Org-mode file"))
  2542. (unless restriction
  2543. (put 'org-agenda-files 'org-restrict (list bfn))
  2544. (org-call-with-arg 'org-timeline arg)))
  2545. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2546. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2547. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2548. (t (user-error "Invalid agenda key"))))))
  2549. (defvar org-agenda-multi)
  2550. (defun org-agenda-append-agenda ()
  2551. "Append another agenda view to the current one.
  2552. This function allows interactive building of block agendas.
  2553. Agenda views are separated by `org-agenda-block-separator'."
  2554. (interactive)
  2555. (unless (derived-mode-p 'org-agenda-mode)
  2556. (user-error "Can only append from within agenda buffer"))
  2557. (let ((org-agenda-multi t))
  2558. (org-agenda)
  2559. (widen)
  2560. (org-agenda-finalize)
  2561. (setq buffer-read-only t)
  2562. (org-agenda-fit-window-to-buffer)))
  2563. (defun org-agenda-normalize-custom-commands (cmds)
  2564. "Normalize custom commands CMDS."
  2565. (delq nil
  2566. (mapcar
  2567. (lambda (x)
  2568. (cond ((stringp (cdr x)) nil)
  2569. ((stringp (nth 1 x)) x)
  2570. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2571. (t (cons (car x) (cons "" (cdr x))))))
  2572. cmds)))
  2573. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2574. "The user interface for selecting an agenda command."
  2575. (catch 'exit
  2576. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2577. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2578. (region-p (org-region-active-p))
  2579. (custom org-agenda-custom-commands)
  2580. (selstring "")
  2581. restriction second-time
  2582. c entry key type match prefixes rmheader header-end custom1 desc
  2583. line lines left right n n1)
  2584. (save-window-excursion
  2585. (delete-other-windows)
  2586. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2587. (erase-buffer)
  2588. (insert (eval-when-compile
  2589. (let ((header
  2590. "Press key for an agenda command: < Buffer, subtree/region restriction
  2591. -------------------------------- > Remove restriction
  2592. a Agenda for current week or day e Export agenda views
  2593. t List of all TODO entries T Entries with special TODO kwd
  2594. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2595. s Search for keywords S Like s, but only TODO entries
  2596. L Timeline for current buffer # List stuck projects (!=configure)
  2597. / Multi-occur C Configure custom agenda commands
  2598. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2599. ")
  2600. (start 0))
  2601. (while (string-match
  2602. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2603. header start)
  2604. (setq start (match-end 0))
  2605. (add-text-properties (match-beginning 2) (match-end 2)
  2606. '(face bold) header))
  2607. header)))
  2608. (setq header-end (point-marker))
  2609. (while t
  2610. (setq custom1 custom)
  2611. (when (eq rmheader t)
  2612. (org-goto-line 1)
  2613. (re-search-forward ":" nil t)
  2614. (delete-region (match-end 0) (point-at-eol))
  2615. (forward-char 1)
  2616. (looking-at "-+")
  2617. (delete-region (match-end 0) (point-at-eol))
  2618. (move-marker header-end (match-end 0)))
  2619. (goto-char header-end)
  2620. (delete-region (point) (point-max))
  2621. ;; Produce all the lines that describe custom commands and prefixes
  2622. (setq lines nil)
  2623. (while (setq entry (pop custom1))
  2624. (setq key (car entry) desc (nth 1 entry)
  2625. type (nth 2 entry)
  2626. match (nth 3 entry))
  2627. (if (> (length key) 1)
  2628. (add-to-list 'prefixes (string-to-char key))
  2629. (setq line
  2630. (format
  2631. "%-4s%-14s"
  2632. (org-add-props (copy-sequence key)
  2633. '(face bold))
  2634. (cond
  2635. ((string-match "\\S-" desc) desc)
  2636. ((eq type 'agenda) "Agenda for current week or day")
  2637. ((eq type 'agenda*) "Appointments for current week or day")
  2638. ((eq type 'alltodo) "List of all TODO entries")
  2639. ((eq type 'search) "Word search")
  2640. ((eq type 'stuck) "List of stuck projects")
  2641. ((eq type 'todo) "TODO keyword")
  2642. ((eq type 'tags) "Tags query")
  2643. ((eq type 'tags-todo) "Tags (TODO)")
  2644. ((eq type 'tags-tree) "Tags tree")
  2645. ((eq type 'todo-tree) "TODO kwd tree")
  2646. ((eq type 'occur-tree) "Occur tree")
  2647. ((functionp type) (if (symbolp type)
  2648. (symbol-name type)
  2649. "Lambda expression"))
  2650. (t "???"))))
  2651. (if org-agenda-menu-show-matcher
  2652. (setq line
  2653. (concat line ": "
  2654. (cond
  2655. ((stringp match)
  2656. (setq match (copy-sequence match))
  2657. (org-add-props match nil 'face 'org-warning))
  2658. ((listp type)
  2659. (format "set of %d commands" (length type))))))
  2660. (if (org-string-nw-p match)
  2661. (add-text-properties
  2662. 0 (length line) (list 'help-echo
  2663. (concat "Matcher: " match)) line)))
  2664. (push line lines)))
  2665. (setq lines (nreverse lines))
  2666. (when prefixes
  2667. (mapc (lambda (x)
  2668. (push
  2669. (format "%s %s"
  2670. (org-add-props (char-to-string x)
  2671. nil 'face 'bold)
  2672. (or (cdr (assoc (concat selstring
  2673. (char-to-string x))
  2674. prefix-descriptions))
  2675. "Prefix key"))
  2676. lines))
  2677. prefixes))
  2678. ;; Check if we should display in two columns
  2679. (if org-agenda-menu-two-columns
  2680. (progn
  2681. (setq n (length lines)
  2682. n1 (+ (/ n 2) (mod n 2))
  2683. right (nthcdr n1 lines)
  2684. left (copy-sequence lines))
  2685. (setcdr (nthcdr (1- n1) left) nil))
  2686. (setq left lines right nil))
  2687. (while left
  2688. (insert "\n" (pop left))
  2689. (when right
  2690. (if (< (current-column) 40)
  2691. (move-to-column 40 t)
  2692. (insert " "))
  2693. (insert (pop right))))
  2694. ;; Make the window the right size
  2695. (goto-char (point-min))
  2696. (if second-time
  2697. (if (not (pos-visible-in-window-p (point-max)))
  2698. (org-fit-window-to-buffer))
  2699. (setq second-time t)
  2700. (org-fit-window-to-buffer))
  2701. ;; Ask for selection
  2702. (message "Press key for agenda command%s:"
  2703. (if (or restrict-ok org-agenda-overriding-restriction)
  2704. (if org-agenda-overriding-restriction
  2705. " (restriction lock active)"
  2706. (if restriction
  2707. (format " (restricted to %s)" restriction)
  2708. " (unrestricted)"))
  2709. ""))
  2710. (setq c (read-char-exclusive))
  2711. (message "")
  2712. (cond
  2713. ((assoc (char-to-string c) custom)
  2714. (setq selstring (concat selstring (char-to-string c)))
  2715. (throw 'exit (cons selstring restriction)))
  2716. ((memq c prefixes)
  2717. (setq selstring (concat selstring (char-to-string c))
  2718. prefixes nil
  2719. rmheader (or rmheader t)
  2720. custom (delq nil (mapcar
  2721. (lambda (x)
  2722. (if (or (= (length (car x)) 1)
  2723. (/= (string-to-char (car x)) c))
  2724. nil
  2725. (cons (substring (car x) 1) (cdr x))))
  2726. custom))))
  2727. ((eq c ?*)
  2728. (call-interactively 'org-toggle-sticky-agenda)
  2729. (sit-for 2))
  2730. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2731. (message "Restriction is only possible in Org-mode buffers")
  2732. (ding) (sit-for 1))
  2733. ((eq c ?1)
  2734. (org-agenda-remove-restriction-lock 'noupdate)
  2735. (setq restriction 'buffer))
  2736. ((eq c ?0)
  2737. (org-agenda-remove-restriction-lock 'noupdate)
  2738. (setq restriction (if region-p 'region 'subtree)))
  2739. ((eq c ?<)
  2740. (org-agenda-remove-restriction-lock 'noupdate)
  2741. (setq restriction
  2742. (cond
  2743. ((eq restriction 'buffer)
  2744. (if region-p 'region 'subtree))
  2745. ((memq restriction '(subtree region))
  2746. nil)
  2747. (t 'buffer))))
  2748. ((eq c ?>)
  2749. (org-agenda-remove-restriction-lock 'noupdate)
  2750. (setq restriction nil))
  2751. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2752. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2753. ((and (> (length selstring) 0) (eq c ?\d))
  2754. (delete-window)
  2755. (org-agenda-get-restriction-and-command prefix-descriptions))
  2756. ((equal c ?q) (error "Abort"))
  2757. (t (user-error "Invalid key %c" c))))))))
  2758. (defun org-agenda-fit-window-to-buffer ()
  2759. "Fit the window to the buffer size."
  2760. (and (memq org-agenda-window-setup '(reorganize-frame))
  2761. (fboundp 'fit-window-to-buffer)
  2762. (org-fit-window-to-buffer
  2763. nil
  2764. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2765. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2766. (defvar org-cmd nil)
  2767. (defvar org-agenda-overriding-cmd nil)
  2768. (defvar org-agenda-overriding-arguments nil)
  2769. (defvar org-agenda-overriding-cmd-arguments nil)
  2770. (defun org-agenda-run-series (name series)
  2771. "Run agenda NAME as a SERIES of agenda commands."
  2772. (org-let (nth 1 series) '(org-agenda-prepare name))
  2773. ;; We need to reset agenda markers here, because when constructing a
  2774. ;; block agenda, the individual blocks do not do that.
  2775. (org-agenda-reset-markers)
  2776. (let* ((org-agenda-multi t)
  2777. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2778. (cmds (car series))
  2779. (gprops (nth 1 series))
  2780. match ;; The byte compiler incorrectly complains about this. Keep it!
  2781. org-cmd type lprops)
  2782. (while (setq org-cmd (pop cmds))
  2783. (setq type (car org-cmd)
  2784. match (eval (nth 1 org-cmd))
  2785. lprops (nth 2 org-cmd))
  2786. (let ((org-agenda-overriding-arguments
  2787. (if (eq org-agenda-overriding-cmd org-cmd)
  2788. (or org-agenda-overriding-arguments
  2789. org-agenda-overriding-cmd-arguments))))
  2790. (cond
  2791. ((eq type 'agenda)
  2792. (org-let2 gprops lprops
  2793. '(call-interactively 'org-agenda-list)))
  2794. ((eq type 'agenda*)
  2795. (org-let2 gprops lprops
  2796. '(funcall 'org-agenda-list nil nil t)))
  2797. ((eq type 'alltodo)
  2798. (org-let2 gprops lprops
  2799. '(call-interactively 'org-todo-list)))
  2800. ((eq type 'search)
  2801. (org-let2 gprops lprops
  2802. '(org-search-view current-prefix-arg match nil)))
  2803. ((eq type 'stuck)
  2804. (org-let2 gprops lprops
  2805. '(call-interactively 'org-agenda-list-stuck-projects)))
  2806. ((eq type 'tags)
  2807. (org-let2 gprops lprops
  2808. '(org-tags-view current-prefix-arg match)))
  2809. ((eq type 'tags-todo)
  2810. (org-let2 gprops lprops
  2811. '(org-tags-view '(4) match)))
  2812. ((eq type 'todo)
  2813. (org-let2 gprops lprops
  2814. '(org-todo-list match)))
  2815. ((fboundp type)
  2816. (org-let2 gprops lprops
  2817. '(funcall type match)))
  2818. (t (error "Invalid type in command series")))))
  2819. (widen)
  2820. (let ((inhibit-read-only t))
  2821. (add-text-properties (point-min) (point-max)
  2822. `(org-series t org-series-redo-cmd ,redo)))
  2823. (setq org-agenda-redo-command redo)
  2824. (goto-char (point-min)))
  2825. (org-agenda-fit-window-to-buffer)
  2826. (org-let (nth 1 series) '(org-agenda-finalize)))
  2827. ;;;###autoload
  2828. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2829. "Run an agenda command in batch mode and send the result to STDOUT.
  2830. If CMD-KEY is a string of length 1, it is used as a key in
  2831. `org-agenda-custom-commands' and triggers this command. If it is a
  2832. longer string it is used as a tags/todo match string.
  2833. Parameters are alternating variable names and values that will be bound
  2834. before running the agenda command."
  2835. (org-eval-in-environment (org-make-parameter-alist parameters)
  2836. (let (org-agenda-sticky)
  2837. (if (> (length cmd-key) 2)
  2838. (org-tags-view nil cmd-key)
  2839. (org-agenda nil cmd-key))))
  2840. (set-buffer org-agenda-buffer-name)
  2841. (princ (buffer-string)))
  2842. (defvar org-agenda-info nil)
  2843. ;;;###autoload
  2844. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2845. "Run an agenda command in batch mode and send the result to STDOUT.
  2846. If CMD-KEY is a string of length 1, it is used as a key in
  2847. `org-agenda-custom-commands' and triggers this command. If it is a
  2848. longer string it is used as a tags/todo match string.
  2849. Parameters are alternating variable names and values that will be bound
  2850. before running the agenda command.
  2851. The output gives a line for each selected agenda item. Each
  2852. item is a list of comma-separated values, like this:
  2853. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2854. category The category of the item
  2855. head The headline, without TODO kwd, TAGS and PRIORITY
  2856. type The type of the agenda entry, can be
  2857. todo selected in TODO match
  2858. tagsmatch selected in tags match
  2859. diary imported from diary
  2860. deadline a deadline on given date
  2861. scheduled scheduled on given date
  2862. timestamp entry has timestamp on given date
  2863. closed entry was closed on given date
  2864. upcoming-deadline warning about deadline
  2865. past-scheduled forwarded scheduled item
  2866. block entry has date block including g. date
  2867. todo The todo keyword, if any
  2868. tags All tags including inherited ones, separated by colons
  2869. date The relevant date, like 2007-2-14
  2870. time The time, like 15:00-16:50
  2871. extra Sting with extra planning info
  2872. priority-l The priority letter if any was given
  2873. priority-n The computed numerical priority
  2874. agenda-day The day in the agenda where this is listed"
  2875. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2876. (org-make-parameter-alist parameters))
  2877. (if (> (length cmd-key) 2)
  2878. (org-tags-view nil cmd-key)
  2879. (org-agenda nil cmd-key)))
  2880. (set-buffer org-agenda-buffer-name)
  2881. (let* ((lines (org-split-string (buffer-string) "\n"))
  2882. line)
  2883. (while (setq line (pop lines))
  2884. (catch 'next
  2885. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2886. (setq org-agenda-info
  2887. (org-fix-agenda-info (text-properties-at 0 line)))
  2888. (princ
  2889. (mapconcat 'org-agenda-export-csv-mapper
  2890. '(org-category txt type todo tags date time extra
  2891. priority-letter priority agenda-day)
  2892. ","))
  2893. (princ "\n")))))
  2894. (defun org-fix-agenda-info (props)
  2895. "Make sure all properties on an agenda item have a canonical form.
  2896. This ensures the export commands can easily use it."
  2897. (let (tmp re)
  2898. (when (setq tmp (plist-get props 'tags))
  2899. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2900. (when (setq tmp (plist-get props 'date))
  2901. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2902. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2903. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2904. (setq tmp (calendar-date-string tmp)))
  2905. (setq props (plist-put props 'date tmp)))
  2906. (when (setq tmp (plist-get props 'day))
  2907. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2908. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2909. (setq tmp (calendar-date-string tmp)))
  2910. (setq props (plist-put props 'day tmp))
  2911. (setq props (plist-put props 'agenda-day tmp)))
  2912. (when (setq tmp (plist-get props 'txt))
  2913. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2914. (plist-put props 'priority-letter (match-string 1 tmp))
  2915. (setq tmp (replace-match "" t t tmp)))
  2916. (when (and (setq re (plist-get props 'org-todo-regexp))
  2917. (setq re (concat "\\`\\.*" re " ?"))
  2918. (string-match re tmp))
  2919. (plist-put props 'todo (match-string 1 tmp))
  2920. (setq tmp (replace-match "" t t tmp)))
  2921. (plist-put props 'txt tmp)))
  2922. props)
  2923. (defun org-agenda-export-csv-mapper (prop)
  2924. (let ((res (plist-get org-agenda-info prop)))
  2925. (setq res
  2926. (cond
  2927. ((not res) "")
  2928. ((stringp res) res)
  2929. (t (prin1-to-string res))))
  2930. (while (string-match "," res)
  2931. (setq res (replace-match ";" t t res)))
  2932. (org-trim res)))
  2933. ;;;###autoload
  2934. (defun org-store-agenda-views (&rest parameters)
  2935. "Store agenda views."
  2936. (interactive)
  2937. (eval (list 'org-batch-store-agenda-views)))
  2938. ;;;###autoload
  2939. (defmacro org-batch-store-agenda-views (&rest parameters)
  2940. "Run all custom agenda commands that have a file argument."
  2941. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2942. (pop-up-frames nil)
  2943. (dir default-directory)
  2944. (pars (org-make-parameter-alist parameters))
  2945. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2946. (save-window-excursion
  2947. (while cmds
  2948. (setq cmd (pop cmds)
  2949. thiscmdkey (car cmd)
  2950. thiscmdcmd (cdr cmd)
  2951. match (nth 2 thiscmdcmd)
  2952. bufname (if org-agenda-sticky
  2953. (or (and (stringp match)
  2954. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2955. (format "*Org Agenda(%s)*" thiscmdkey))
  2956. org-agenda-buffer-name)
  2957. cmd-or-set (nth 2 cmd)
  2958. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2959. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2960. (if (stringp files) (setq files (list files)))
  2961. (when files
  2962. (org-eval-in-environment (append org-agenda-exporter-settings
  2963. opts pars)
  2964. (org-agenda nil thiscmdkey))
  2965. (set-buffer bufname)
  2966. (while files
  2967. (org-eval-in-environment (append org-agenda-exporter-settings
  2968. opts pars)
  2969. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2970. (and (get-buffer bufname)
  2971. (kill-buffer bufname)))))))
  2972. (defvar org-agenda-current-span nil
  2973. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2974. (defun org-agenda-mark-header-line (pos)
  2975. "Mark the line at POS as an agenda structure header."
  2976. (save-excursion
  2977. (goto-char pos)
  2978. (put-text-property (point-at-bol) (point-at-eol)
  2979. 'org-agenda-structural-header t)
  2980. (when org-agenda-title-append
  2981. (put-text-property (point-at-bol) (point-at-eol)
  2982. 'org-agenda-title-append org-agenda-title-append))))
  2983. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2984. (defvar org-agenda-write-buffer-name "Agenda View")
  2985. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2986. "Write the current buffer (an agenda view) as a file.
  2987. Depending on the extension of the file name, plain text (.txt),
  2988. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2989. If the extension is .ics, run icalendar export over all files used
  2990. to construct the agenda and limit the export to entries listed in the
  2991. agenda now.
  2992. If the extension is .org, collect all subtrees corresponding to the
  2993. agenda entries and add them in an .org file.
  2994. With prefix argument OPEN, open the new file immediately.
  2995. If NOSETTINGS is given, do not scope the settings of
  2996. `org-agenda-exporter-settings' into the export commands. This is used when
  2997. the settings have already been scoped and we do not wish to overrule other,
  2998. higher priority settings.
  2999. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3000. (interactive "FWrite agenda to file: \nP")
  3001. (if (or (not (file-writable-p file))
  3002. (and (file-exists-p file)
  3003. (if (org-called-interactively-p 'any)
  3004. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3005. (user-error "Cannot write agenda to file %s" file))
  3006. (org-let (if nosettings nil org-agenda-exporter-settings)
  3007. '(save-excursion
  3008. (save-window-excursion
  3009. (org-agenda-mark-filtered-text)
  3010. (let ((bs (copy-sequence (buffer-string))) beg content)
  3011. (org-agenda-unmark-filtered-text)
  3012. (with-temp-buffer
  3013. (rename-buffer org-agenda-write-buffer-name t)
  3014. (set-buffer-modified-p nil)
  3015. (insert bs)
  3016. (org-agenda-remove-marked-text 'org-filtered)
  3017. (while (setq beg (text-property-any (point-min) (point-max)
  3018. 'org-filtered t))
  3019. (delete-region
  3020. beg (or (next-single-property-change beg 'org-filtered)
  3021. (point-max))))
  3022. (run-hooks 'org-agenda-before-write-hook)
  3023. (cond
  3024. ((org-bound-and-true-p org-mobile-creating-agendas)
  3025. (org-mobile-write-agenda-for-mobile file))
  3026. ((string-match "\\.org\\'" file)
  3027. (let (content p m message-log-max)
  3028. (goto-char (point-min))
  3029. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3030. (goto-char p)
  3031. (setq m (get-text-property (point) 'org-hd-marker))
  3032. (when m
  3033. (push (save-excursion
  3034. (set-buffer (marker-buffer m))
  3035. (goto-char m)
  3036. (org-copy-subtree 1 nil t t)
  3037. org-subtree-clip)
  3038. content)))
  3039. (find-file file)
  3040. (erase-buffer)
  3041. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3042. (write-file file)
  3043. (kill-buffer (current-buffer))
  3044. (message "Org file written to %s" file)))
  3045. ((string-match "\\.html?\\'" file)
  3046. (require 'htmlize)
  3047. (set-buffer (htmlize-buffer (current-buffer)))
  3048. (when org-agenda-export-html-style
  3049. ;; replace <style> section with org-agenda-export-html-style
  3050. (goto-char (point-min))
  3051. (kill-region (- (search-forward "<style") 6)
  3052. (search-forward "</style>"))
  3053. (insert org-agenda-export-html-style))
  3054. (write-file file)
  3055. (kill-buffer (current-buffer))
  3056. (message "HTML written to %s" file))
  3057. ((string-match "\\.ps\\'" file)
  3058. (require 'ps-print)
  3059. (ps-print-buffer-with-faces file)
  3060. (message "Postscript written to %s" file))
  3061. ((string-match "\\.pdf\\'" file)
  3062. (require 'ps-print)
  3063. (ps-print-buffer-with-faces
  3064. (concat (file-name-sans-extension file) ".ps"))
  3065. (call-process "ps2pdf" nil nil nil
  3066. (expand-file-name
  3067. (concat (file-name-sans-extension file) ".ps"))
  3068. (expand-file-name file))
  3069. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3070. (message "PDF written to %s" file))
  3071. ((string-match "\\.ics\\'" file)
  3072. (require 'ox-icalendar)
  3073. (org-icalendar-export-current-agenda (expand-file-name file)))
  3074. (t
  3075. (let ((bs (buffer-string)))
  3076. (find-file file)
  3077. (erase-buffer)
  3078. (insert bs)
  3079. (save-buffer 0)
  3080. (kill-buffer (current-buffer))
  3081. (message "Plain text written to %s" file))))))))
  3082. (set-buffer (or agenda-bufname
  3083. (and (org-called-interactively-p 'any) (buffer-name))
  3084. org-agenda-buffer-name)))
  3085. (when open (org-open-file file)))
  3086. (defvar org-agenda-tag-filter-overlays nil)
  3087. (defvar org-agenda-cat-filter-overlays nil)
  3088. (defvar org-agenda-re-filter-overlays nil)
  3089. (defun org-agenda-mark-filtered-text ()
  3090. "Mark all text hidden by filtering with a text property."
  3091. (let ((inhibit-read-only t))
  3092. (mapc
  3093. (lambda (o)
  3094. (when (equal (overlay-buffer o) (current-buffer))
  3095. (put-text-property
  3096. (overlay-start o) (overlay-end o)
  3097. 'org-filtered t)))
  3098. (append org-agenda-tag-filter-overlays
  3099. org-agenda-cat-filter-overlays
  3100. org-agenda-re-filter-overlays))))
  3101. (defun org-agenda-unmark-filtered-text ()
  3102. "Remove the filtering text property."
  3103. (let ((inhibit-read-only t))
  3104. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3105. (defun org-agenda-remove-marked-text (property &optional value)
  3106. "Delete all text marked with VALUE of PROPERTY.
  3107. VALUE defaults to t."
  3108. (let (beg)
  3109. (setq value (or value t))
  3110. (while (setq beg (text-property-any (point-min) (point-max)
  3111. property value))
  3112. (delete-region
  3113. beg (or (next-single-property-change beg 'org-filtered)
  3114. (point-max))))))
  3115. (defun org-agenda-add-entry-text ()
  3116. "Add entry text to agenda lines.
  3117. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3118. entry text following headings shown in the agenda.
  3119. Drawers will be excluded, also the line with scheduling/deadline info."
  3120. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3121. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3122. (let (m txt)
  3123. (goto-char (point-min))
  3124. (while (not (eobp))
  3125. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3126. (beginning-of-line 2)
  3127. (setq txt (org-agenda-get-some-entry-text
  3128. m org-agenda-add-entry-text-maxlines " > "))
  3129. (end-of-line 1)
  3130. (if (string-match "\\S-" txt)
  3131. (insert "\n" txt)
  3132. (or (eobp) (forward-char 1))))))))
  3133. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3134. &rest keep)
  3135. "Extract entry text from MARKER, at most N-LINES lines.
  3136. This will ignore drawers etc, just get the text.
  3137. If INDENT is given, prefix every line with this string. If KEEP is
  3138. given, it is a list of symbols, defining stuff that should not be
  3139. removed from the entry content. Currently only `planning' is allowed here."
  3140. (let (txt drawer-re kwd-time-re ind)
  3141. (save-excursion
  3142. (with-current-buffer (marker-buffer marker)
  3143. (if (not (derived-mode-p 'org-mode))
  3144. (setq txt "")
  3145. (save-excursion
  3146. (save-restriction
  3147. (widen)
  3148. (goto-char marker)
  3149. (end-of-line 1)
  3150. (setq txt (buffer-substring
  3151. (min (1+ (point)) (point-max))
  3152. (progn (outline-next-heading) (point)))
  3153. drawer-re org-drawer-regexp
  3154. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3155. ".*\n?"))
  3156. (with-temp-buffer
  3157. (insert txt)
  3158. (when org-agenda-add-entry-text-descriptive-links
  3159. (goto-char (point-min))
  3160. (while (org-activate-bracket-links (point-max))
  3161. (add-text-properties (match-beginning 0) (match-end 0)
  3162. '(face org-link))))
  3163. (goto-char (point-min))
  3164. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3165. (set-text-properties (match-beginning 0) (match-end 0)
  3166. nil))
  3167. (goto-char (point-min))
  3168. (while (re-search-forward drawer-re nil t)
  3169. (delete-region
  3170. (match-beginning 0)
  3171. (progn (re-search-forward
  3172. "^[ \t]*:END:.*\n?" nil 'move)
  3173. (point))))
  3174. (unless (member 'planning keep)
  3175. (goto-char (point-min))
  3176. (while (re-search-forward kwd-time-re nil t)
  3177. (replace-match "")))
  3178. (goto-char (point-min))
  3179. (when org-agenda-entry-text-exclude-regexps
  3180. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3181. (while (setq re (pop re-list))
  3182. (goto-char (point-min))
  3183. (while (re-search-forward re nil t)
  3184. (replace-match "")))))
  3185. (goto-char (point-max))
  3186. (skip-chars-backward " \t\n")
  3187. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3188. ;; find and remove min common indentation
  3189. (goto-char (point-min))
  3190. (untabify (point-min) (point-max))
  3191. (setq ind (org-get-indentation))
  3192. (while (not (eobp))
  3193. (unless (looking-at "[ \t]*$")
  3194. (setq ind (min ind (org-get-indentation))))
  3195. (beginning-of-line 2))
  3196. (goto-char (point-min))
  3197. (while (not (eobp))
  3198. (unless (looking-at "[ \t]*$")
  3199. (move-to-column ind)
  3200. (delete-region (point-at-bol) (point)))
  3201. (beginning-of-line 2))
  3202. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3203. (goto-char (point-min))
  3204. (when indent
  3205. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3206. (replace-match indent t t)))
  3207. (goto-char (point-min))
  3208. (while (looking-at "[ \t]*\n") (replace-match ""))
  3209. (goto-char (point-max))
  3210. (when (> (org-current-line)
  3211. n-lines)
  3212. (org-goto-line (1+ n-lines))
  3213. (backward-char 1))
  3214. (setq txt (buffer-substring (point-min) (point)))))))))
  3215. txt))
  3216. (defun org-check-for-org-mode ()
  3217. "Make sure current buffer is in org-mode. Error if not."
  3218. (or (derived-mode-p 'org-mode)
  3219. (error "Cannot execute org-mode agenda command on buffer in %s"
  3220. major-mode)))
  3221. ;;; Agenda prepare and finalize
  3222. (defvar org-agenda-multi nil) ; dynamically scoped
  3223. (defvar org-agenda-pre-window-conf nil)
  3224. (defvar org-agenda-columns-active nil)
  3225. (defvar org-agenda-name nil)
  3226. (defvar org-agenda-tag-filter nil)
  3227. (defvar org-agenda-category-filter nil)
  3228. (defvar org-agenda-regexp-filter nil)
  3229. (defvar org-agenda-top-headline-filter nil)
  3230. (defvar org-agenda-tag-filter-while-redo nil)
  3231. (defvar org-agenda-tag-filter-preset nil
  3232. "A preset of the tags filter used for secondary agenda filtering.
  3233. This must be a list of strings, each string must be a single tag preceded
  3234. by \"+\" or \"-\".
  3235. This variable should not be set directly, but agenda custom commands can
  3236. bind it in the options section. The preset filter is a global property of
  3237. the entire agenda view. In a block agenda, it will not work reliably to
  3238. define a filter for one of the individual blocks. You need to set it in
  3239. the global options and expect it to be applied to the entire view.")
  3240. (defvar org-agenda-category-filter-preset nil
  3241. "A preset of the category filter used for secondary agenda filtering.
  3242. This must be a list of strings, each string must be a single category
  3243. preceded by \"+\" or \"-\".
  3244. This variable should not be set directly, but agenda custom commands can
  3245. bind it in the options section. The preset filter is a global property of
  3246. the entire agenda view. In a block agenda, it will not work reliably to
  3247. define a filter for one of the individual blocks. You need to set it in
  3248. the global options and expect it to be applied to the entire view.")
  3249. (defvar org-agenda-regexp-filter-preset nil
  3250. "A preset of the regexp filter used for secondary agenda filtering.
  3251. This must be a list of strings, each string must be a single regexp
  3252. preceded by \"+\" or \"-\".
  3253. This variable should not be set directly, but agenda custom commands can
  3254. bind it in the options section. The preset filter is a global property of
  3255. the entire agenda view. In a block agenda, it will not work reliably to
  3256. define a filter for one of the individual blocks. You need to set it in
  3257. the global options and expect it to be applied to the entire view.")
  3258. (defun org-agenda-use-sticky-p ()
  3259. "Return non-nil if an agenda buffer named
  3260. `org-agenda-buffer-name' exists and should be shown instead of
  3261. generating a new one."
  3262. (and
  3263. ;; turned off by user
  3264. org-agenda-sticky
  3265. ;; For multi-agenda buffer already exists
  3266. (not org-agenda-multi)
  3267. ;; buffer found
  3268. (get-buffer org-agenda-buffer-name)
  3269. ;; C-u parameter is same as last call
  3270. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3271. (and
  3272. (equal current-prefix-arg
  3273. org-agenda-last-prefix-arg)
  3274. ;; In case user turned stickiness on, while having existing
  3275. ;; Agenda buffer active, don't reuse that buffer, because it
  3276. ;; does not have org variables local
  3277. org-agenda-this-buffer-is-sticky))))
  3278. (defun org-agenda-prepare-window (abuf)
  3279. "Setup agenda buffer in the window."
  3280. (let* ((awin (get-buffer-window abuf))
  3281. wconf)
  3282. (cond
  3283. ((equal (current-buffer) abuf) nil)
  3284. (awin (select-window awin))
  3285. ((not (setq wconf (current-window-configuration))))
  3286. ((equal org-agenda-window-setup 'current-window)
  3287. (org-pop-to-buffer-same-window abuf))
  3288. ((equal org-agenda-window-setup 'other-window)
  3289. (org-switch-to-buffer-other-window abuf))
  3290. ((equal org-agenda-window-setup 'other-frame)
  3291. (switch-to-buffer-other-frame abuf))
  3292. ((equal org-agenda-window-setup 'reorganize-frame)
  3293. (delete-other-windows)
  3294. (org-switch-to-buffer-other-window abuf)))
  3295. ;; additional test in case agenda is invoked from within agenda
  3296. ;; buffer via elisp link
  3297. (unless (equal (current-buffer) abuf)
  3298. (org-pop-to-buffer-same-window abuf))
  3299. (setq org-agenda-pre-window-conf
  3300. (or org-agenda-pre-window-conf wconf))))
  3301. (defun org-agenda-prepare (&optional name)
  3302. (if (org-agenda-use-sticky-p)
  3303. (progn
  3304. ;; Popup existing buffer
  3305. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3306. (message "Sticky Agenda buffer, use `r' to refresh")
  3307. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3308. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3309. (setq org-todo-keywords-for-agenda nil)
  3310. (setq org-drawers-for-agenda nil)
  3311. (unless org-agenda-persistent-filter
  3312. (setq org-agenda-tag-filter nil
  3313. org-agenda-category-filter nil
  3314. org-agenda-regexp-filter nil))
  3315. (put 'org-agenda-tag-filter :preset-filter
  3316. org-agenda-tag-filter-preset)
  3317. (put 'org-agenda-category-filter :preset-filter
  3318. org-agenda-category-filter-preset)
  3319. (put 'org-agenda-regexp-filter :preset-filter
  3320. org-agenda-regexp-filter-preset)
  3321. (if org-agenda-multi
  3322. (progn
  3323. (setq buffer-read-only nil)
  3324. (goto-char (point-max))
  3325. (unless (or (bobp) org-agenda-compact-blocks
  3326. (not org-agenda-block-separator))
  3327. (insert "\n"
  3328. (if (stringp org-agenda-block-separator)
  3329. org-agenda-block-separator
  3330. (make-string (window-width) org-agenda-block-separator))
  3331. "\n"))
  3332. (narrow-to-region (point) (point-max)))
  3333. (setq org-done-keywords-for-agenda nil)
  3334. ;; Setting any org variables that are in org-agenda-local-vars
  3335. ;; list need to be done after the prepare call
  3336. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3337. (setq buffer-read-only nil)
  3338. (org-agenda-reset-markers)
  3339. (let ((inhibit-read-only t)) (erase-buffer))
  3340. (org-agenda-mode)
  3341. (setq org-agenda-buffer (current-buffer))
  3342. (setq org-agenda-contributing-files nil)
  3343. (setq org-agenda-columns-active nil)
  3344. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3345. (setq org-todo-keywords-for-agenda
  3346. (org-uniquify org-todo-keywords-for-agenda))
  3347. (setq org-done-keywords-for-agenda
  3348. (org-uniquify org-done-keywords-for-agenda))
  3349. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3350. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3351. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3352. (and name (not org-agenda-name)
  3353. (org-set-local 'org-agenda-name name)))
  3354. (setq buffer-read-only nil)))
  3355. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3356. (defun org-agenda-finalize ()
  3357. "Finishing touch for the agenda buffer, called just before displaying it."
  3358. (unless org-agenda-multi
  3359. (save-excursion
  3360. (let ((inhibit-read-only t))
  3361. (goto-char (point-min))
  3362. (save-excursion
  3363. (while (org-activate-bracket-links (point-max))
  3364. (add-text-properties (match-beginning 0) (match-end 0)
  3365. '(face org-link))))
  3366. (save-excursion
  3367. (while (org-activate-plain-links (point-max))
  3368. (add-text-properties (match-beginning 0) (match-end 0)
  3369. '(face org-link))))
  3370. (unless (eq org-agenda-remove-tags t)
  3371. (org-agenda-align-tags))
  3372. (unless org-agenda-with-colors
  3373. (remove-text-properties (point-min) (point-max) '(face nil)))
  3374. (if (and (boundp 'org-agenda-overriding-columns-format)
  3375. org-agenda-overriding-columns-format)
  3376. (org-set-local 'org-agenda-overriding-columns-format
  3377. org-agenda-overriding-columns-format))
  3378. (if (and (boundp 'org-agenda-view-columns-initially)
  3379. org-agenda-view-columns-initially)
  3380. (org-agenda-columns))
  3381. (when org-agenda-fontify-priorities
  3382. (org-agenda-fontify-priorities))
  3383. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3384. (org-agenda-dim-blocked-tasks))
  3385. (org-agenda-mark-clocking-task)
  3386. (when org-agenda-entry-text-mode
  3387. (org-agenda-entry-text-hide)
  3388. (org-agenda-entry-text-show))
  3389. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3390. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3391. (org-habit-insert-consistency-graphs))
  3392. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3393. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3394. (and (listp org-agenda-show-inherited-tags)
  3395. (memq org-agenda-type org-agenda-show-inherited-tags))
  3396. (and (eq org-agenda-show-inherited-tags t)
  3397. (or (eq org-agenda-use-tag-inheritance t)
  3398. (and (listp org-agenda-use-tag-inheritance)
  3399. (not (memq org-agenda-type
  3400. org-agenda-use-tag-inheritance))))))
  3401. (let (mrk)
  3402. (save-excursion
  3403. (goto-char (point-min))
  3404. (while (equal (forward-line) 0)
  3405. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3406. (get-text-property (point) 'org-hd-marker)))
  3407. (put-text-property (point-at-bol) (point-at-eol)
  3408. 'tags (org-with-point-at mrk
  3409. (delete-dups
  3410. (mapcar 'downcase (org-get-tags-at))))))))))
  3411. (run-hooks 'org-agenda-finalize-hook)
  3412. (when org-agenda-top-headline-filter
  3413. (org-agenda-filter-top-headline-apply
  3414. org-agenda-top-headline-filter))
  3415. (when org-agenda-tag-filter
  3416. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3417. (when (get 'org-agenda-tag-filter :preset-filter)
  3418. (org-agenda-filter-apply
  3419. (get 'org-agenda-tag-filter :preset-filter) 'tag))
  3420. (when org-agenda-category-filter
  3421. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3422. (when (get 'org-agenda-category-filter :preset-filter)
  3423. (org-agenda-filter-apply
  3424. (get 'org-agenda-category-filter :preset-filter) 'category))
  3425. (when org-agenda-regexp-filter
  3426. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3427. (when (get 'org-agenda-regexp-filter :preset-filter)
  3428. (org-agenda-filter-apply
  3429. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3430. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3431. (defun org-agenda-mark-clocking-task ()
  3432. "Mark the current clock entry in the agenda if it is present."
  3433. ;; We need to widen when `org-agenda-finalize' is called from
  3434. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3435. (when org-clock-current-task
  3436. (save-restriction
  3437. (widen)
  3438. (org-agenda-unmark-clocking-task)
  3439. (when (marker-buffer org-clock-hd-marker)
  3440. (save-excursion
  3441. (goto-char (point-min))
  3442. (let (s ov)
  3443. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3444. (goto-char s)
  3445. (when (equal (org-get-at-bol 'org-hd-marker)
  3446. org-clock-hd-marker)
  3447. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3448. (overlay-put ov 'type 'org-agenda-clocking)
  3449. (overlay-put ov 'face 'org-agenda-clocking)
  3450. (overlay-put ov 'help-echo
  3451. "The clock is running in this item")))))))))
  3452. (defun org-agenda-unmark-clocking-task ()
  3453. "Unmark the current clocking task."
  3454. (mapc (lambda (o)
  3455. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3456. (delete-overlay o)))
  3457. (overlays-in (point-min) (point-max))))
  3458. (defun org-agenda-fontify-priorities ()
  3459. "Make highest priority lines bold, and lowest italic."
  3460. (interactive)
  3461. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3462. (delete-overlay o)))
  3463. (overlays-in (point-min) (point-max)))
  3464. (save-excursion
  3465. (let (b e p ov h l)
  3466. (goto-char (point-min))
  3467. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3468. (setq h (or (get-char-property (point) 'org-highest-priority)
  3469. org-highest-priority)
  3470. l (or (get-char-property (point) 'org-lowest-priority)
  3471. org-lowest-priority)
  3472. p (string-to-char (match-string 1))
  3473. b (match-beginning 0)
  3474. e (if (eq org-agenda-fontify-priorities 'cookies)
  3475. (match-end 0)
  3476. (point-at-eol))
  3477. ov (make-overlay b e))
  3478. (overlay-put
  3479. ov 'face
  3480. (cons (cond ((org-face-from-face-or-color
  3481. 'priority nil
  3482. (cdr (assoc p org-priority-faces))))
  3483. ((and (listp org-agenda-fontify-priorities)
  3484. (org-face-from-face-or-color
  3485. 'priority nil
  3486. (cdr (assoc p org-agenda-fontify-priorities)))))
  3487. ((equal p l) 'italic)
  3488. ((equal p h) 'bold))
  3489. 'org-priority))
  3490. (overlay-put ov 'org-type 'org-priority)))))
  3491. (defvar org-depend-tag-blocked)
  3492. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3493. "Dim currently blocked TODO's in the agenda display.
  3494. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3495. dimming them."
  3496. (interactive "P")
  3497. (when (org-called-interactively-p 'interactive)
  3498. (message "Dim or hide blocked tasks..."))
  3499. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3500. (delete-overlay o)))
  3501. (overlays-in (point-min) (point-max)))
  3502. (save-excursion
  3503. (let ((inhibit-read-only t)
  3504. (org-depend-tag-blocked nil)
  3505. (invis (or (not (null invisible))
  3506. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3507. org-blocked-by-checkboxes
  3508. invis1 b e p ov h l)
  3509. (goto-char (point-min))
  3510. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3511. (and pos (goto-char (1+ pos))))
  3512. (setq org-blocked-by-checkboxes nil invis1 invis)
  3513. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3514. (when (and marker
  3515. (with-current-buffer (marker-buffer marker)
  3516. (save-excursion (goto-char marker)
  3517. (org-entry-blocked-p))))
  3518. (if org-blocked-by-checkboxes (setq invis1 nil))
  3519. (setq b (if invis1
  3520. (max (point-min) (1- (point-at-bol)))
  3521. (point-at-bol))
  3522. e (point-at-eol)
  3523. ov (make-overlay b e))
  3524. (if invis1
  3525. (progn (overlay-put ov 'invisible t)
  3526. (overlay-put ov 'intangible t))
  3527. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3528. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3529. (when (org-called-interactively-p 'interactive)
  3530. (message "Dim or hide blocked tasks...done")))
  3531. (defvar org-agenda-skip-function nil
  3532. "Function to be called at each match during agenda construction.
  3533. If this function returns nil, the current match should not be skipped.
  3534. Otherwise, the function must return a position from where the search
  3535. should be continued.
  3536. This may also be a Lisp form, it will be evaluated.
  3537. Never set this variable using `setq' or so, because then it will apply
  3538. to all future agenda commands. If you do want a global skipping condition,
  3539. use the option `org-agenda-skip-function-global' instead.
  3540. The correct usage for `org-agenda-skip-function' is to bind it with
  3541. `let' to scope it dynamically into the agenda-constructing command.
  3542. A good way to set it is through options in `org-agenda-custom-commands'.")
  3543. (defun org-agenda-skip ()
  3544. "Throw to `:skip' in places that should be skipped.
  3545. Also moves point to the end of the skipped region, so that search can
  3546. continue from there."
  3547. (let ((p (point-at-bol)) to)
  3548. (when (or
  3549. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3550. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3551. (get-text-property p :org-archived)
  3552. (org-end-of-subtree t))
  3553. (and org-agenda-skip-comment-trees
  3554. (get-text-property p :org-comment)
  3555. (org-end-of-subtree t))
  3556. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3557. (org-agenda-skip-eval org-agenda-skip-function)))
  3558. (goto-char to))
  3559. (org-in-src-block-p t))
  3560. (throw :skip t))))
  3561. (defun org-agenda-skip-eval (form)
  3562. "If FORM is a function or a list, call (or eval) it and return the result.
  3563. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3564. and match data are returned to the previous state no matter what these
  3565. functions do."
  3566. (let (fp)
  3567. (and form
  3568. (or (setq fp (functionp form))
  3569. (consp form))
  3570. (save-excursion
  3571. (save-match-data
  3572. (if fp
  3573. (funcall form)
  3574. (eval form)))))))
  3575. (defvar org-agenda-markers nil
  3576. "List of all currently active markers created by `org-agenda'.")
  3577. (defvar org-agenda-last-marker-time (org-float-time)
  3578. "Creation time of the last agenda marker.")
  3579. (defun org-agenda-new-marker (&optional pos)
  3580. "Return a new agenda marker.
  3581. Org-mode keeps a list of these markers and resets them when they are
  3582. no longer in use."
  3583. (let ((m (copy-marker (or pos (point)))))
  3584. (setq org-agenda-last-marker-time (org-float-time))
  3585. (if org-agenda-buffer
  3586. (with-current-buffer org-agenda-buffer
  3587. (push m org-agenda-markers))
  3588. (push m org-agenda-markers))
  3589. m))
  3590. (defun org-agenda-reset-markers ()
  3591. "Reset markers created by `org-agenda'."
  3592. (while org-agenda-markers
  3593. (move-marker (pop org-agenda-markers) nil)))
  3594. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3595. "Save relative positions of markers in region.
  3596. This check for agenda markers in all agenda buffers currently active."
  3597. (dolist (buf (buffer-list))
  3598. (with-current-buffer buf
  3599. (when (eq major-mode 'org-agenda-mode)
  3600. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3601. org-agenda-markers)))))
  3602. ;;; Entry text mode
  3603. (defun org-agenda-entry-text-show-here ()
  3604. "Add some text from the entry as context to the current line."
  3605. (let (m txt o)
  3606. (setq m (org-get-at-bol 'org-hd-marker))
  3607. (unless (marker-buffer m)
  3608. (error "No marker points to an entry here"))
  3609. (setq txt (concat "\n" (org-no-properties
  3610. (org-agenda-get-some-entry-text
  3611. m org-agenda-entry-text-maxlines
  3612. org-agenda-entry-text-leaders))))
  3613. (when (string-match "\\S-" txt)
  3614. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3615. (overlay-put o 'evaporate t)
  3616. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3617. (overlay-put o 'after-string txt))))
  3618. (defun org-agenda-entry-text-show ()
  3619. "Add entry context for all agenda lines."
  3620. (interactive)
  3621. (save-excursion
  3622. (goto-char (point-max))
  3623. (beginning-of-line 1)
  3624. (while (not (bobp))
  3625. (when (org-get-at-bol 'org-hd-marker)
  3626. (org-agenda-entry-text-show-here))
  3627. (beginning-of-line 0))))
  3628. (defun org-agenda-entry-text-hide ()
  3629. "Remove any shown entry context."
  3630. (delq nil
  3631. (mapcar (lambda (o)
  3632. (if (eq (overlay-get o 'org-overlay-type)
  3633. 'agenda-entry-content)
  3634. (progn (delete-overlay o) t)))
  3635. (overlays-in (point-min) (point-max)))))
  3636. (defun org-agenda-get-day-face (date)
  3637. "Return the face DATE should be displayed with."
  3638. (or (and (functionp org-agenda-day-face-function)
  3639. (funcall org-agenda-day-face-function date))
  3640. (cond ((org-agenda-todayp date)
  3641. 'org-agenda-date-today)
  3642. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3643. 'org-agenda-date-weekend)
  3644. (t 'org-agenda-date))))
  3645. ;;; Agenda timeline
  3646. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3647. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3648. (defun org-timeline (&optional dotodo)
  3649. "Show a time-sorted view of the entries in the current org file.
  3650. Only entries with a time stamp of today or later will be listed. With
  3651. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3652. under the current date.
  3653. If the buffer contains an active region, only check the region for
  3654. dates."
  3655. (interactive "P")
  3656. (let* ((dopast t)
  3657. (org-agenda-show-log-scoped org-agenda-show-log)
  3658. (org-agenda-show-log org-agenda-show-log-scoped)
  3659. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3660. (current-buffer))))
  3661. (date (calendar-current-date))
  3662. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3663. (end (if (org-region-active-p) (region-end) (point-max)))
  3664. (day-numbers (org-get-all-dates
  3665. beg end 'no-ranges
  3666. t org-agenda-show-log-scoped ; always include today
  3667. org-timeline-show-empty-dates))
  3668. (org-deadline-warning-days 0)
  3669. (org-agenda-only-exact-dates t)
  3670. (today (org-today))
  3671. (past t)
  3672. args
  3673. s e rtn d emptyp)
  3674. (setq org-agenda-redo-command
  3675. (list 'let
  3676. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3677. (list 'org-switch-to-buffer-other-window (current-buffer))
  3678. (list 'org-timeline (list 'quote dotodo))))
  3679. (put 'org-agenda-redo-command 'org-lprops nil)
  3680. (if (not dopast)
  3681. ;; Remove past dates from the list of dates.
  3682. (setq day-numbers (delq nil (mapcar (lambda(x)
  3683. (if (>= x today) x nil))
  3684. day-numbers))))
  3685. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3686. (org-compile-prefix-format 'timeline)
  3687. (org-set-sorting-strategy 'timeline)
  3688. (if org-agenda-show-log-scoped (push :closed args))
  3689. (push :timestamp args)
  3690. (push :deadline args)
  3691. (push :scheduled args)
  3692. (push :sexp args)
  3693. (if dotodo (push :todo args))
  3694. (insert "Timeline of file " entry "\n")
  3695. (add-text-properties (point-min) (point)
  3696. (list 'face 'org-agenda-structure))
  3697. (org-agenda-mark-header-line (point-min))
  3698. (while (setq d (pop day-numbers))
  3699. (if (and (listp d) (eq (car d) :omitted))
  3700. (progn
  3701. (setq s (point))
  3702. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3703. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3704. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3705. (if (and (>= d today)
  3706. dopast
  3707. past)
  3708. (progn
  3709. (setq past nil)
  3710. (insert (make-string 79 ?-) "\n")))
  3711. (setq date (calendar-gregorian-from-absolute d))
  3712. (setq s (point))
  3713. (setq rtn (and (not emptyp)
  3714. (apply 'org-agenda-get-day-entries entry
  3715. date args)))
  3716. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3717. (progn
  3718. (insert
  3719. (if (stringp org-agenda-format-date)
  3720. (format-time-string org-agenda-format-date
  3721. (org-time-from-absolute date))
  3722. (funcall org-agenda-format-date date))
  3723. "\n")
  3724. (put-text-property s (1- (point)) 'face
  3725. (org-agenda-get-day-face date))
  3726. (put-text-property s (1- (point)) 'org-date-line t)
  3727. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3728. (if (equal d today)
  3729. (put-text-property s (1- (point)) 'org-today t))
  3730. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3731. (put-text-property s (1- (point)) 'day d)))))
  3732. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3733. (point-min)))
  3734. (add-text-properties
  3735. (point-min) (point-max)
  3736. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3737. (org-agenda-finalize)
  3738. (setq buffer-read-only t)))
  3739. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3740. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3741. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3742. not every single day in the range. If FORCE-TODAY is non-nil, make
  3743. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3744. inactive time stamps (those in square brackets) are included.
  3745. When EMPTY is non-nil, also include days without any entries."
  3746. (let ((re (concat
  3747. (if pre-re pre-re "")
  3748. (if inactive org-ts-regexp-both org-ts-regexp)))
  3749. dates dates1 date day day1 day2 ts1 ts2 pos)
  3750. (if force-today
  3751. (setq dates (list (org-today))))
  3752. (save-excursion
  3753. (goto-char beg)
  3754. (while (re-search-forward re end t)
  3755. (setq day (time-to-days (org-time-string-to-time
  3756. (substring (match-string 1) 0 10)
  3757. (current-buffer) (match-beginning 0))))
  3758. (or (memq day dates) (push day dates)))
  3759. (unless no-ranges
  3760. (goto-char beg)
  3761. (while (re-search-forward org-tr-regexp end t)
  3762. (setq pos (match-beginning 0))
  3763. (setq ts1 (substring (match-string 1) 0 10)
  3764. ts2 (substring (match-string 2) 0 10)
  3765. day1 (time-to-days (org-time-string-to-time
  3766. ts1 (current-buffer) pos))
  3767. day2 (time-to-days (org-time-string-to-time
  3768. ts2 (current-buffer) pos)))
  3769. (while (< (setq day1 (1+ day1)) day2)
  3770. (or (memq day1 dates) (push day1 dates)))))
  3771. (setq dates (sort dates '<))
  3772. (when empty
  3773. (while (setq day (pop dates))
  3774. (setq day2 (car dates))
  3775. (push day dates1)
  3776. (when (and day2 empty)
  3777. (if (or (eq empty t)
  3778. (and (numberp empty) (<= (- day2 day) empty)))
  3779. (while (< (setq day (1+ day)) day2)
  3780. (push (list day) dates1))
  3781. (push (cons :omitted (- day2 day)) dates1))))
  3782. (setq dates (nreverse dates1)))
  3783. dates)))
  3784. ;;; Agenda Daily/Weekly
  3785. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3786. "Start day for the agenda view.
  3787. Custom commands can set this variable in the options section.
  3788. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3789. input allowed when reading a date through the Org calendar.
  3790. See the docstring of `org-read-date' for details.")
  3791. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3792. (defvar org-arg-loc nil) ; local variable
  3793. (defvar org-agenda-buffer-tmp-name nil)
  3794. ;;;###autoload
  3795. (defun org-agenda-list (&optional arg start-day span with-hour)
  3796. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3797. The view will be for the current day or week, but from the overview buffer
  3798. you will be able to go to other days/weeks.
  3799. With a numeric prefix argument in an interactive call, the agenda will
  3800. span ARG days. Lisp programs should instead specify SPAN to change
  3801. the number of days. SPAN defaults to `org-agenda-span'.
  3802. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3803. given in `org-agenda-start-on-weekday'.
  3804. When WITH-HOUR is non-nil, only include scheduled and deadline
  3805. items if they have an hour specification like [h]h:mm."
  3806. (interactive "P")
  3807. (if org-agenda-overriding-arguments
  3808. (setq arg (car org-agenda-overriding-arguments)
  3809. start-day (nth 1 org-agenda-overriding-arguments)
  3810. span (nth 2 org-agenda-overriding-arguments)))
  3811. (if (and (integerp arg) (> arg 0))
  3812. (setq span arg arg nil))
  3813. (catch 'exit
  3814. (setq org-agenda-buffer-name
  3815. (or org-agenda-buffer-tmp-name
  3816. (if org-agenda-sticky
  3817. (cond ((and org-keys (stringp org-match))
  3818. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3819. (org-keys
  3820. (format "*Org Agenda(%s)*" org-keys))
  3821. (t "*Org Agenda(a)*")))
  3822. org-agenda-buffer-name))
  3823. (org-agenda-prepare "Day/Week")
  3824. (setq start-day (or start-day org-agenda-start-day))
  3825. (if (stringp start-day)
  3826. ;; Convert to an absolute day number
  3827. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3828. (org-compile-prefix-format 'agenda)
  3829. (org-set-sorting-strategy 'agenda)
  3830. (let* ((span (org-agenda-ndays-to-span
  3831. (or span org-agenda-ndays org-agenda-span)))
  3832. (today (org-today))
  3833. (sd (or start-day today))
  3834. (ndays (org-agenda-span-to-ndays span sd))
  3835. (org-agenda-start-on-weekday
  3836. (if (or (eq ndays 7) (eq ndays 14))
  3837. org-agenda-start-on-weekday))
  3838. (thefiles (org-agenda-files nil 'ifmode))
  3839. (files thefiles)
  3840. (start (if (or (null org-agenda-start-on-weekday)
  3841. (< ndays 7))
  3842. sd
  3843. (let* ((nt (calendar-day-of-week
  3844. (calendar-gregorian-from-absolute sd)))
  3845. (n1 org-agenda-start-on-weekday)
  3846. (d (- nt n1)))
  3847. (- sd (+ (if (< d 0) 7 0) d)))))
  3848. (day-numbers (list start))
  3849. (day-cnt 0)
  3850. (inhibit-redisplay (not debug-on-error))
  3851. (org-agenda-show-log-scoped org-agenda-show-log)
  3852. s e rtn rtnall file date d start-pos end-pos todayp
  3853. clocktable-start clocktable-end filter)
  3854. (setq org-agenda-redo-command
  3855. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3856. (dotimes (n (1- ndays))
  3857. (push (1+ (car day-numbers)) day-numbers))
  3858. (setq day-numbers (nreverse day-numbers))
  3859. (setq clocktable-start (car day-numbers)
  3860. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3861. (org-set-local 'org-starting-day (car day-numbers))
  3862. (org-set-local 'org-arg-loc arg)
  3863. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3864. (unless org-agenda-compact-blocks
  3865. (let* ((d1 (car day-numbers))
  3866. (d2 (org-last day-numbers))
  3867. (w1 (org-days-to-iso-week d1))
  3868. (w2 (org-days-to-iso-week d2)))
  3869. (setq s (point))
  3870. (if org-agenda-overriding-header
  3871. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3872. nil 'face 'org-agenda-structure) "\n")
  3873. (insert (org-agenda-span-name span)
  3874. "-agenda"
  3875. (if (< (- d2 d1) 350)
  3876. (if (= w1 w2)
  3877. (format " (W%02d)" w1)
  3878. (format " (W%02d-W%02d)" w1 w2))
  3879. "")
  3880. ":\n")))
  3881. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3882. 'org-date-line t))
  3883. (org-agenda-mark-header-line s))
  3884. (while (setq d (pop day-numbers))
  3885. (setq date (calendar-gregorian-from-absolute d)
  3886. s (point))
  3887. (if (or (setq todayp (= d today))
  3888. (and (not start-pos) (= d sd)))
  3889. (setq start-pos (point))
  3890. (if (and start-pos (not end-pos))
  3891. (setq end-pos (point))))
  3892. (setq files thefiles
  3893. rtnall nil)
  3894. (while (setq file (pop files))
  3895. (catch 'nextfile
  3896. (org-check-agenda-file file)
  3897. (let ((org-agenda-entry-types org-agenda-entry-types))
  3898. ;; Starred types override non-starred equivalents
  3899. (when (member :deadline* org-agenda-entry-types)
  3900. (setq org-agenda-entry-types
  3901. (delq :deadline org-agenda-entry-types)))
  3902. (when (member :scheduled* org-agenda-entry-types)
  3903. (setq org-agenda-entry-types
  3904. (delq :scheduled org-agenda-entry-types)))
  3905. ;; Honor with-hour
  3906. (when with-hour
  3907. (when (member :deadline org-agenda-entry-types)
  3908. (setq org-agenda-entry-types
  3909. (delq :deadline org-agenda-entry-types))
  3910. (push :deadline* org-agenda-entry-types))
  3911. (when (member :scheduled org-agenda-entry-types)
  3912. (setq org-agenda-entry-types
  3913. (delq :scheduled org-agenda-entry-types))
  3914. (push :scheduled* org-agenda-entry-types)))
  3915. (unless org-agenda-include-deadlines
  3916. (setq org-agenda-entry-types
  3917. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3918. (cond
  3919. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3920. (setq rtn (org-agenda-get-day-entries
  3921. file date :closed)))
  3922. (org-agenda-show-log-scoped
  3923. (setq rtn (apply 'org-agenda-get-day-entries
  3924. file date
  3925. (append '(:closed) org-agenda-entry-types))))
  3926. (t
  3927. (setq rtn (apply 'org-agenda-get-day-entries
  3928. file date
  3929. org-agenda-entry-types)))))
  3930. (setq rtnall (append rtnall rtn)))) ;; all entries
  3931. (if org-agenda-include-diary
  3932. (let ((org-agenda-search-headline-for-time t))
  3933. (require 'diary-lib)
  3934. (setq rtn (org-get-entries-from-diary date))
  3935. (setq rtnall (append rtnall rtn))))
  3936. (if (or rtnall org-agenda-show-all-dates)
  3937. (progn
  3938. (setq day-cnt (1+ day-cnt))
  3939. (insert
  3940. (if (stringp org-agenda-format-date)
  3941. (format-time-string org-agenda-format-date
  3942. (org-time-from-absolute date))
  3943. (funcall org-agenda-format-date date))
  3944. "\n")
  3945. (put-text-property s (1- (point)) 'face
  3946. (org-agenda-get-day-face date))
  3947. (put-text-property s (1- (point)) 'org-date-line t)
  3948. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3949. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3950. (when todayp
  3951. (put-text-property s (1- (point)) 'org-today t))
  3952. (setq rtnall
  3953. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3954. (if rtnall (insert ;; all entries
  3955. (org-agenda-finalize-entries rtnall 'agenda)
  3956. "\n"))
  3957. (put-text-property s (1- (point)) 'day d)
  3958. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3959. (when (and org-agenda-clockreport-mode clocktable-start)
  3960. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3961. ;; the above line is to ensure the restricted range!
  3962. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3963. tbl)
  3964. (setq p (org-plist-delete p :block))
  3965. (setq p (plist-put p :tstart clocktable-start))
  3966. (setq p (plist-put p :tend clocktable-end))
  3967. (setq p (plist-put p :scope 'agenda))
  3968. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3969. (setq filter (or org-agenda-tag-filter-while-redo
  3970. (get 'org-agenda-tag-filter :preset-filter))))
  3971. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3972. (if (string-match "[<>=]" x)
  3973. ""
  3974. x))
  3975. filter ""))))
  3976. (setq tbl (apply 'org-clock-get-clocktable p))
  3977. (insert tbl)))
  3978. (goto-char (point-min))
  3979. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3980. (unless (and (pos-visible-in-window-p (point-min))
  3981. (pos-visible-in-window-p (point-max)))
  3982. (goto-char (1- (point-max)))
  3983. (recenter -1)
  3984. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3985. (progn
  3986. (goto-char (or start-pos 1))
  3987. (recenter 1))))
  3988. (goto-char (or start-pos 1))
  3989. (add-text-properties (point-min) (point-max)
  3990. `(org-agenda-type agenda
  3991. org-last-args (,arg ,start-day ,span)
  3992. org-redo-cmd ,org-agenda-redo-command
  3993. org-series-cmd ,org-cmd))
  3994. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3995. (org-agenda-show-clocking-issues))
  3996. (org-agenda-finalize)
  3997. (setq buffer-read-only t)
  3998. (message ""))))
  3999. (defun org-agenda-ndays-to-span (n)
  4000. "Return a span symbol for a span of N days, or N if none matches."
  4001. (cond ((symbolp n) n)
  4002. ((= n 1) 'day)
  4003. ((= n 7) 'week)
  4004. ((= n 14) 'fortnight)
  4005. (t n)))
  4006. (defun org-agenda-span-to-ndays (span &optional start-day)
  4007. "Return ndays from SPAN, possibly starting at START-DAY.
  4008. START-DAY is an absolute time value."
  4009. (cond ((numberp span) span)
  4010. ((eq span 'day) 1)
  4011. ((eq span 'week) 7)
  4012. ((eq span 'fortnight) 14)
  4013. ((eq span 'month)
  4014. (let ((date (calendar-gregorian-from-absolute start-day)))
  4015. (calendar-last-day-of-month (car date) (caddr date))))
  4016. ((eq span 'year)
  4017. (let ((date (calendar-gregorian-from-absolute start-day)))
  4018. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  4019. (defun org-agenda-span-name (span)
  4020. "Return a SPAN name."
  4021. (if (null span)
  4022. ""
  4023. (if (symbolp span)
  4024. (capitalize (symbol-name span))
  4025. (format "%d days" span))))
  4026. ;;; Agenda word search
  4027. (defvar org-agenda-search-history nil)
  4028. (defvar org-search-syntax-table nil
  4029. "Special syntax table for org-mode search.
  4030. In this table, we have single quotes not as word constituents, to
  4031. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4032. (defvar org-mode-syntax-table) ; From org.el
  4033. (defun org-search-syntax-table ()
  4034. (unless org-search-syntax-table
  4035. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4036. (modify-syntax-entry ?' "." org-search-syntax-table)
  4037. (modify-syntax-entry ?` "." org-search-syntax-table))
  4038. org-search-syntax-table)
  4039. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4040. ;;;###autoload
  4041. (defun org-search-view (&optional todo-only string edit-at)
  4042. "Show all entries that contain a phrase or words or regular expressions.
  4043. With optional prefix argument TODO-ONLY, only consider entries that are
  4044. TODO entries. The argument STRING can be used to pass a default search
  4045. string into this function. If EDIT-AT is non-nil, it means that the
  4046. user should get a chance to edit this string, with cursor at position
  4047. EDIT-AT.
  4048. The search string can be viewed either as a phrase that should be found as
  4049. is, or it can be broken into a number of snippets, each of which must match
  4050. in a Boolean way to select an entry. The default depends on the variable
  4051. `org-agenda-search-view-always-boolean'.
  4052. Even if this is turned off (the default) you can always switch to
  4053. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4054. The default is a direct search of the whole phrase, where each space in
  4055. the search string can expand to an arbitrary amount of whitespace,
  4056. including newlines.
  4057. If using a Boolean search, the search string is split on whitespace and
  4058. each snippet is searched separately, with logical AND to select an entry.
  4059. Words prefixed with a minus must *not* occur in the entry. Words without
  4060. a prefix or prefixed with a plus must occur in the entry. Matching is
  4061. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4062. match whole words, not parts of a word) if
  4063. `org-agenda-search-view-force-full-words' is set (default is nil).
  4064. Boolean search snippets enclosed by curly braces are interpreted as
  4065. regular expressions that must or (when preceded with \"-\") must not
  4066. match in the entry. Snippets enclosed into double quotes will be taken
  4067. as a whole, to include whitespace.
  4068. - If the search string starts with an asterisk, search only in headlines.
  4069. - If (possibly after the leading star) the search string starts with an
  4070. exclamation mark, this also means to look at TODO entries only, an effect
  4071. that can also be achieved with a prefix argument.
  4072. - If (possibly after star and exclamation mark) the search string starts
  4073. with a colon, this will mean that the (non-regexp) snippets of the
  4074. Boolean search must match as full words.
  4075. This command searches the agenda files, and in addition the files listed
  4076. in `org-agenda-text-search-extra-files'."
  4077. (interactive "P")
  4078. (if org-agenda-overriding-arguments
  4079. (setq todo-only (car org-agenda-overriding-arguments)
  4080. string (nth 1 org-agenda-overriding-arguments)
  4081. edit-at (nth 2 org-agenda-overriding-arguments)))
  4082. (let* ((props (list 'face nil
  4083. 'done-face 'org-agenda-done
  4084. 'org-not-done-regexp org-not-done-regexp
  4085. 'org-todo-regexp org-todo-regexp
  4086. 'org-complex-heading-regexp org-complex-heading-regexp
  4087. 'mouse-face 'highlight
  4088. 'help-echo (format "mouse-2 or RET jump to location")))
  4089. (full-words org-agenda-search-view-force-full-words)
  4090. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4091. regexp rtn rtnall files file pos inherited-tags
  4092. marker category category-pos level tags c neg re boolean
  4093. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4094. (unless (and (not edit-at)
  4095. (stringp string)
  4096. (string-match "\\S-" string))
  4097. (setq string (read-string
  4098. (if org-agenda-search-view-always-boolean
  4099. "[+-]Word/{Regexp} ...: "
  4100. "Phrase or [+-]Word/{Regexp} ...: ")
  4101. (cond
  4102. ((integerp edit-at) (cons string edit-at))
  4103. (edit-at string))
  4104. 'org-agenda-search-history)))
  4105. (catch 'exit
  4106. (if org-agenda-sticky
  4107. (setq org-agenda-buffer-name
  4108. (if (stringp string)
  4109. (format "*Org Agenda(%s:%s)*"
  4110. (or org-keys (or (and todo-only "S") "s")) string)
  4111. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4112. (org-agenda-prepare "SEARCH")
  4113. (org-compile-prefix-format 'search)
  4114. (org-set-sorting-strategy 'search)
  4115. (setq org-agenda-redo-command
  4116. (list 'org-search-view (if todo-only t nil)
  4117. (list 'if 'current-prefix-arg nil string)))
  4118. (setq org-agenda-query-string string)
  4119. (if (equal (string-to-char string) ?*)
  4120. (setq hdl-only t
  4121. words (substring string 1))
  4122. (setq words string))
  4123. (when (equal (string-to-char words) ?!)
  4124. (setq todo-only t
  4125. words (substring words 1)))
  4126. (when (equal (string-to-char words) ?:)
  4127. (setq full-words t
  4128. words (substring words 1)))
  4129. (if (or org-agenda-search-view-always-boolean
  4130. (member (string-to-char words) '(?- ?+ ?\{)))
  4131. (setq boolean t))
  4132. (setq words (org-split-string words))
  4133. (let (www w)
  4134. (while (setq w (pop words))
  4135. (while (and (string-match "\\\\\\'" w) words)
  4136. (setq w (concat (substring w 0 -1) " " (pop words))))
  4137. (push w www))
  4138. (setq words (nreverse www) www nil)
  4139. (while (setq w (pop words))
  4140. (when (and (string-match "\\`[-+]?{" w)
  4141. (not (string-match "}\\'" w)))
  4142. (while (and words (not (string-match "}\\'" (car words))))
  4143. (setq w (concat w " " (pop words))))
  4144. (setq w (concat w " " (pop words))))
  4145. (push w www))
  4146. (setq words (nreverse www)))
  4147. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4148. (when boolean
  4149. (let (wds w)
  4150. (while (setq w (pop words))
  4151. (if (or (equal (substring w 0 1) "\"")
  4152. (and (> (length w) 1)
  4153. (member (substring w 0 1) '("+" "-"))
  4154. (equal (substring w 1 2) "\"")))
  4155. (while (and words (not (equal (substring w -1) "\"")))
  4156. (setq w (concat w " " (pop words)))))
  4157. (and (string-match "\\`\\([-+]?\\)\"" w)
  4158. (setq w (replace-match "\\1" nil nil w)))
  4159. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4160. (push w wds))
  4161. (setq words (nreverse wds))))
  4162. (if boolean
  4163. (mapc (lambda (w)
  4164. (setq c (string-to-char w))
  4165. (if (equal c ?-)
  4166. (setq neg t w (substring w 1))
  4167. (if (equal c ?+)
  4168. (setq neg nil w (substring w 1))
  4169. (setq neg nil)))
  4170. (if (string-match "\\`{.*}\\'" w)
  4171. (setq re (substring w 1 -1))
  4172. (if full-words
  4173. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4174. (setq re (regexp-quote (downcase w)))))
  4175. (if neg (push re regexps-) (push re regexps+)))
  4176. words)
  4177. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4178. regexps+))
  4179. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4180. (if (not regexps+)
  4181. (setq regexp org-outline-regexp-bol)
  4182. (setq regexp (pop regexps+))
  4183. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4184. regexp))))
  4185. (setq files (org-agenda-files nil 'ifmode))
  4186. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4187. (pop org-agenda-text-search-extra-files)
  4188. (setq files (org-add-archive-files files)))
  4189. (setq files (append files org-agenda-text-search-extra-files)
  4190. rtnall nil)
  4191. (while (setq file (pop files))
  4192. (setq ee nil)
  4193. (catch 'nextfile
  4194. (org-check-agenda-file file)
  4195. (setq buffer (if (file-exists-p file)
  4196. (org-get-agenda-file-buffer file)
  4197. (error "No such file %s" file)))
  4198. (if (not buffer)
  4199. ;; If file does not exist, make sure an error message is sent
  4200. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4201. file))))
  4202. (with-current-buffer buffer
  4203. (with-syntax-table (org-search-syntax-table)
  4204. (unless (derived-mode-p 'org-mode)
  4205. (error "Agenda file %s is not in `org-mode'" file))
  4206. (let ((case-fold-search t))
  4207. (save-excursion
  4208. (save-restriction
  4209. (if (eq buffer org-agenda-restrict)
  4210. (narrow-to-region org-agenda-restrict-begin
  4211. org-agenda-restrict-end)
  4212. (widen))
  4213. (goto-char (point-min))
  4214. (unless (or (org-at-heading-p)
  4215. (outline-next-heading))
  4216. (throw 'nextfile t))
  4217. (goto-char (max (point-min) (1- (point))))
  4218. (while (re-search-forward regexp nil t)
  4219. (org-back-to-heading t)
  4220. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4221. (> (org-reduced-level (org-outline-level))
  4222. org-agenda-search-view-max-outline-level)
  4223. (forward-line -1)
  4224. (outline-back-to-heading t)))
  4225. (skip-chars-forward "* ")
  4226. (setq beg (point-at-bol)
  4227. beg1 (point)
  4228. end (progn
  4229. (outline-next-heading)
  4230. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4231. (> (org-reduced-level (org-outline-level))
  4232. org-agenda-search-view-max-outline-level)
  4233. (forward-line 1)
  4234. (outline-next-heading)))
  4235. (point)))
  4236. (catch :skip
  4237. (goto-char beg)
  4238. (org-agenda-skip)
  4239. (setq str (buffer-substring-no-properties
  4240. (point-at-bol)
  4241. (if hdl-only (point-at-eol) end)))
  4242. (mapc (lambda (wr) (when (string-match wr str)
  4243. (goto-char (1- end))
  4244. (throw :skip t)))
  4245. regexps-)
  4246. (mapc (lambda (wr) (unless (string-match wr str)
  4247. (goto-char (1- end))
  4248. (throw :skip t)))
  4249. (if todo-only
  4250. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4251. regexps+)
  4252. regexps+))
  4253. (goto-char beg)
  4254. (setq marker (org-agenda-new-marker (point))
  4255. category (org-get-category)
  4256. level (make-string (org-reduced-level (org-outline-level)) ? )
  4257. category-pos (get-text-property (point) 'org-category-position)
  4258. inherited-tags
  4259. (or (eq org-agenda-show-inherited-tags 'always)
  4260. (and (listp org-agenda-show-inherited-tags)
  4261. (memq 'todo org-agenda-show-inherited-tags))
  4262. (and (eq org-agenda-show-inherited-tags t)
  4263. (or (eq org-agenda-use-tag-inheritance t)
  4264. (memq 'todo org-agenda-use-tag-inheritance))))
  4265. tags (org-get-tags-at nil (not inherited-tags))
  4266. txt (org-agenda-format-item
  4267. ""
  4268. (buffer-substring-no-properties
  4269. beg1 (point-at-eol))
  4270. level category tags t))
  4271. (org-add-props txt props
  4272. 'org-marker marker 'org-hd-marker marker
  4273. 'org-todo-regexp org-todo-regexp
  4274. 'level level
  4275. 'org-complex-heading-regexp org-complex-heading-regexp
  4276. 'priority 1000 'org-category category
  4277. 'org-category-position category-pos
  4278. 'type "search")
  4279. (push txt ee)
  4280. (goto-char (1- end))))))))))
  4281. (setq rtn (nreverse ee))
  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 "Search words: ")
  4287. (add-text-properties (point-min) (1- (point))
  4288. (list 'face 'org-agenda-structure))
  4289. (setq pos (point))
  4290. (insert string "\n")
  4291. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4292. (setq pos (point))
  4293. (unless org-agenda-multi
  4294. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4295. (add-text-properties pos (1- (point))
  4296. (list 'face 'org-agenda-structure))))
  4297. (org-agenda-mark-header-line (point-min))
  4298. (when rtnall
  4299. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4300. (goto-char (point-min))
  4301. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4302. (add-text-properties (point-min) (point-max)
  4303. `(org-agenda-type search
  4304. org-last-args (,todo-only ,string ,edit-at)
  4305. org-redo-cmd ,org-agenda-redo-command
  4306. org-series-cmd ,org-cmd))
  4307. (org-agenda-finalize)
  4308. (setq buffer-read-only t))))
  4309. ;;; Agenda TODO list
  4310. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4311. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4312. (concat
  4313. (if (or (equal keywords "ALL") (not keywords))
  4314. (propertize "ALL" 'face 'warning)
  4315. (mapconcat
  4316. (lambda (kw)
  4317. (propertize kw 'face (org-get-todo-face kw)))
  4318. (org-split-string keywords "|")
  4319. "|"))
  4320. "\n"))
  4321. (defvar org-select-this-todo-keyword nil)
  4322. (defvar org-last-arg nil)
  4323. ;;;###autoload
  4324. (defun org-todo-list (&optional arg)
  4325. "Show all (not done) TODO entries from all agenda file in a single list.
  4326. The prefix arg can be used to select a specific TODO keyword and limit
  4327. the list to these. When using \\[universal-argument], you will be prompted
  4328. for a keyword. A numeric prefix directly selects the Nth keyword in
  4329. `org-todo-keywords-1'."
  4330. (interactive "P")
  4331. (if org-agenda-overriding-arguments
  4332. (setq arg org-agenda-overriding-arguments))
  4333. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4334. (let* ((today (org-today))
  4335. (date (calendar-gregorian-from-absolute today))
  4336. (kwds org-todo-keywords-for-agenda)
  4337. (completion-ignore-case t)
  4338. (org-select-this-todo-keyword
  4339. (if (stringp arg) arg
  4340. (and arg (integerp arg) (> arg 0)
  4341. (nth (1- arg) kwds))))
  4342. rtn rtnall files file pos)
  4343. (when (equal arg '(4))
  4344. (setq org-select-this-todo-keyword
  4345. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4346. (mapcar 'list kwds) nil nil)))
  4347. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4348. (catch 'exit
  4349. (if org-agenda-sticky
  4350. (setq org-agenda-buffer-name
  4351. (if (stringp org-select-this-todo-keyword)
  4352. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4353. org-select-this-todo-keyword)
  4354. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4355. (org-agenda-prepare "TODO")
  4356. (org-compile-prefix-format 'todo)
  4357. (org-set-sorting-strategy 'todo)
  4358. (setq org-agenda-redo-command
  4359. `(org-todo-list (or (and (numberp current-prefix-arg)
  4360. current-prefix-arg)
  4361. ,org-select-this-todo-keyword
  4362. current-prefix-arg ,arg)))
  4363. (setq files (org-agenda-files nil 'ifmode)
  4364. rtnall nil)
  4365. (while (setq file (pop files))
  4366. (catch 'nextfile
  4367. (org-check-agenda-file file)
  4368. (setq rtn (org-agenda-get-day-entries file date :todo))
  4369. (setq rtnall (append rtnall rtn))))
  4370. (if org-agenda-overriding-header
  4371. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4372. nil 'face 'org-agenda-structure) "\n")
  4373. (insert "Global list of TODO items of type: ")
  4374. (add-text-properties (point-min) (1- (point))
  4375. (list 'face 'org-agenda-structure
  4376. 'short-heading
  4377. (concat "ToDo: "
  4378. (or org-select-this-todo-keyword "ALL"))))
  4379. (org-agenda-mark-header-line (point-min))
  4380. (insert (org-agenda-propertize-selected-todo-keywords
  4381. org-select-this-todo-keyword))
  4382. (setq pos (point))
  4383. (unless org-agenda-multi
  4384. (insert "Available with `N r': (0)[ALL]")
  4385. (let ((n 0) s)
  4386. (mapc (lambda (x)
  4387. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4388. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4389. (insert "\n "))
  4390. (insert " " s))
  4391. kwds))
  4392. (insert "\n"))
  4393. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4394. (org-agenda-mark-header-line (point-min))
  4395. (when rtnall
  4396. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4397. (goto-char (point-min))
  4398. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4399. (add-text-properties (point-min) (point-max)
  4400. `(org-agenda-type todo
  4401. org-last-args ,arg
  4402. org-redo-cmd ,org-agenda-redo-command
  4403. org-series-cmd ,org-cmd))
  4404. (org-agenda-finalize)
  4405. (setq buffer-read-only t))))
  4406. ;;; Agenda tags match
  4407. ;;;###autoload
  4408. (defun org-tags-view (&optional todo-only match)
  4409. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4410. The prefix arg TODO-ONLY limits the search to TODO entries."
  4411. (interactive "P")
  4412. (if org-agenda-overriding-arguments
  4413. (setq todo-only (car org-agenda-overriding-arguments)
  4414. match (nth 1 org-agenda-overriding-arguments)))
  4415. (let* ((org-tags-match-list-sublevels
  4416. org-tags-match-list-sublevels)
  4417. (completion-ignore-case t)
  4418. rtn rtnall files file pos matcher
  4419. buffer)
  4420. (when (and (stringp match) (not (string-match "\\S-" match)))
  4421. (setq match nil))
  4422. (catch 'exit
  4423. (if org-agenda-sticky
  4424. (setq org-agenda-buffer-name
  4425. (if (stringp match)
  4426. (format "*Org Agenda(%s:%s)*"
  4427. (or org-keys (or (and todo-only "M") "m")) match)
  4428. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4429. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4430. ;; expanding tags within `org-make-tags-matcher'
  4431. (org-agenda-prepare (concat "TAGS " match))
  4432. (setq matcher (org-make-tags-matcher match)
  4433. match (car matcher) matcher (cdr matcher))
  4434. (org-compile-prefix-format 'tags)
  4435. (org-set-sorting-strategy 'tags)
  4436. (setq org-agenda-query-string match)
  4437. (setq org-agenda-redo-command
  4438. (list 'org-tags-view `(quote ,todo-only)
  4439. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4440. (setq files (org-agenda-files nil 'ifmode)
  4441. rtnall nil)
  4442. (while (setq file (pop files))
  4443. (catch 'nextfile
  4444. (org-check-agenda-file file)
  4445. (setq buffer (if (file-exists-p file)
  4446. (org-get-agenda-file-buffer file)
  4447. (error "No such file %s" file)))
  4448. (if (not buffer)
  4449. ;; If file does not exist, error message to agenda
  4450. (setq rtn (list
  4451. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4452. rtnall (append rtnall rtn))
  4453. (with-current-buffer buffer
  4454. (unless (derived-mode-p 'org-mode)
  4455. (error "Agenda file %s is not in `org-mode'" file))
  4456. (save-excursion
  4457. (save-restriction
  4458. (if (eq buffer org-agenda-restrict)
  4459. (narrow-to-region org-agenda-restrict-begin
  4460. org-agenda-restrict-end)
  4461. (widen))
  4462. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4463. (setq rtnall (append rtnall rtn))))))))
  4464. (if org-agenda-overriding-header
  4465. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4466. nil 'face 'org-agenda-structure) "\n")
  4467. (insert "Headlines with TAGS match: ")
  4468. (add-text-properties (point-min) (1- (point))
  4469. (list 'face 'org-agenda-structure
  4470. 'short-heading
  4471. (concat "Match: " match)))
  4472. (setq pos (point))
  4473. (insert match "\n")
  4474. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4475. (setq pos (point))
  4476. (unless org-agenda-multi
  4477. (insert "Press `C-u r' to search again with new search string\n"))
  4478. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4479. (org-agenda-mark-header-line (point-min))
  4480. (when rtnall
  4481. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4482. (goto-char (point-min))
  4483. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4484. (add-text-properties (point-min) (point-max)
  4485. `(org-agenda-type tags
  4486. org-last-args (,todo-only ,match)
  4487. org-redo-cmd ,org-agenda-redo-command
  4488. org-series-cmd ,org-cmd))
  4489. (org-agenda-finalize)
  4490. (setq buffer-read-only t))))
  4491. ;;; Agenda Finding stuck projects
  4492. (defvar org-agenda-skip-regexp nil
  4493. "Regular expression used in skipping subtrees for the agenda.
  4494. This is basically a temporary global variable that can be set and then
  4495. used by user-defined selections using `org-agenda-skip-function'.")
  4496. (defvar org-agenda-overriding-header nil
  4497. "When set during agenda, todo and tags searches it replaces the header.
  4498. This variable should not be set directly, but custom commands can bind it
  4499. in the options section.")
  4500. (defun org-agenda-skip-entry-when-regexp-matches ()
  4501. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4502. If yes, it returns the end position of this entry, causing agenda commands
  4503. to skip the entry but continuing the search in the subtree. This is a
  4504. function that can be put into `org-agenda-skip-function' for the duration
  4505. of a command."
  4506. (let ((end (save-excursion (org-end-of-subtree t)))
  4507. skip)
  4508. (save-excursion
  4509. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4510. (and skip end)))
  4511. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4512. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4513. If yes, it returns the end position of this tree, causing agenda commands
  4514. to skip this subtree. This is a function that can be put into
  4515. `org-agenda-skip-function' for the duration of a command."
  4516. (let ((end (save-excursion (org-end-of-subtree t)))
  4517. skip)
  4518. (save-excursion
  4519. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4520. (and skip end)))
  4521. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4522. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4523. If yes, it returns the end position of the current entry (NOT the tree),
  4524. causing agenda commands to skip the entry but continuing the search in
  4525. the subtree. This is a function that can be put into
  4526. `org-agenda-skip-function' for the duration of a command. An important
  4527. use of this function is for the stuck project list."
  4528. (let ((end (save-excursion (org-end-of-subtree t)))
  4529. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4530. skip)
  4531. (save-excursion
  4532. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4533. (and skip entry-end)))
  4534. (defun org-agenda-skip-entry-if (&rest conditions)
  4535. "Skip entry if any of CONDITIONS is true.
  4536. See `org-agenda-skip-if' for details."
  4537. (org-agenda-skip-if nil conditions))
  4538. (defun org-agenda-skip-subtree-if (&rest conditions)
  4539. "Skip subtree if any of CONDITIONS is true.
  4540. See `org-agenda-skip-if' for details."
  4541. (org-agenda-skip-if t conditions))
  4542. (defun org-agenda-skip-if (subtree conditions)
  4543. "Checks current entity for CONDITIONS.
  4544. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4545. the entry (i.e. the text before the next heading) is checked.
  4546. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4547. from different tests. Valid conditions are:
  4548. scheduled Check if there is a scheduled cookie
  4549. notscheduled Check if there is no scheduled cookie
  4550. deadline Check if there is a deadline
  4551. notdeadline Check if there is no deadline
  4552. timestamp Check if there is a timestamp (also deadline or scheduled)
  4553. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4554. regexp Check if regexp matches
  4555. notregexp Check if regexp does not match.
  4556. todo Check if TODO keyword matches
  4557. nottodo Check if TODO keyword does not match
  4558. The regexp is taken from the conditions list, it must come right after
  4559. the `regexp' or `notregexp' element.
  4560. `todo' and `nottodo' accept as an argument a list of todo
  4561. keywords, which may include \"*\" to match any todo keyword.
  4562. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4563. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4564. Instead of a list, a keyword class may be given. For example:
  4565. (org-agenda-skip-entry-if 'nottodo 'done)
  4566. would skip entries that haven't been marked with any of \"DONE\"
  4567. keywords. Possible classes are: `todo', `done', `any'.
  4568. If any of these conditions is met, this function returns the end point of
  4569. the entity, causing the search to continue from there. This is a function
  4570. that can be put into `org-agenda-skip-function' for the duration of a command."
  4571. (let (beg end m)
  4572. (org-back-to-heading t)
  4573. (setq beg (point)
  4574. end (if subtree
  4575. (progn (org-end-of-subtree t) (point))
  4576. (progn (outline-next-heading) (1- (point)))))
  4577. (goto-char beg)
  4578. (and
  4579. (or
  4580. (and (memq 'scheduled conditions)
  4581. (re-search-forward org-scheduled-time-regexp end t))
  4582. (and (memq 'notscheduled conditions)
  4583. (not (re-search-forward org-scheduled-time-regexp end t)))
  4584. (and (memq 'deadline conditions)
  4585. (re-search-forward org-deadline-time-regexp end t))
  4586. (and (memq 'notdeadline conditions)
  4587. (not (re-search-forward org-deadline-time-regexp end t)))
  4588. (and (memq 'timestamp conditions)
  4589. (re-search-forward org-ts-regexp end t))
  4590. (and (memq 'nottimestamp conditions)
  4591. (not (re-search-forward org-ts-regexp end t)))
  4592. (and (setq m (memq 'regexp conditions))
  4593. (stringp (nth 1 m))
  4594. (re-search-forward (nth 1 m) end t))
  4595. (and (setq m (memq 'notregexp conditions))
  4596. (stringp (nth 1 m))
  4597. (not (re-search-forward (nth 1 m) end t)))
  4598. (and (or
  4599. (setq m (memq 'nottodo conditions))
  4600. (setq m (memq 'todo-unblocked conditions))
  4601. (setq m (memq 'nottodo-unblocked conditions))
  4602. (setq m (memq 'todo conditions)))
  4603. (org-agenda-skip-if-todo m end)))
  4604. end)))
  4605. (defun org-agenda-skip-if-todo (args end)
  4606. "Helper function for `org-agenda-skip-if', do not use it directly.
  4607. ARGS is a list with first element either `todo', `nottodo',
  4608. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4609. a list of TODO keywords, or a state symbol `todo' or `done' or
  4610. `any'."
  4611. (let ((kw (car args))
  4612. (arg (cadr args))
  4613. todo-wds todo-re)
  4614. (setq todo-wds
  4615. (org-uniquify
  4616. (cond
  4617. ((listp arg) ;; list of keywords
  4618. (if (member "*" arg)
  4619. (mapcar 'substring-no-properties org-todo-keywords-1)
  4620. arg))
  4621. ((symbolp arg) ;; keyword class name
  4622. (cond
  4623. ((eq arg 'todo)
  4624. (org-delete-all org-done-keywords
  4625. (mapcar 'substring-no-properties
  4626. org-todo-keywords-1)))
  4627. ((eq arg 'done) org-done-keywords)
  4628. ((eq arg 'any)
  4629. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4630. (setq todo-re
  4631. (concat "^\\*+[ \t]+\\<\\("
  4632. (mapconcat 'identity todo-wds "\\|")
  4633. "\\)\\>"))
  4634. (cond
  4635. ((eq kw 'todo) (re-search-forward todo-re end t))
  4636. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4637. ((eq kw 'todo-unblocked)
  4638. (catch 'unblocked
  4639. (while (re-search-forward todo-re end t)
  4640. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4641. nil))
  4642. ((eq kw 'nottodo-unblocked)
  4643. (catch 'unblocked
  4644. (while (re-search-forward todo-re end t)
  4645. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4646. t))
  4647. )))
  4648. ;;;###autoload
  4649. (defun org-agenda-list-stuck-projects (&rest ignore)
  4650. "Create agenda view for projects that are stuck.
  4651. Stuck projects are project that have no next actions. For the definitions
  4652. of what a project is and how to check if it stuck, customize the variable
  4653. `org-stuck-projects'."
  4654. (interactive)
  4655. (let* ((org-agenda-skip-function
  4656. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4657. ;; We could have used org-agenda-skip-if here.
  4658. (org-agenda-overriding-header
  4659. (or org-agenda-overriding-header "List of stuck projects: "))
  4660. (matcher (nth 0 org-stuck-projects))
  4661. (todo (nth 1 org-stuck-projects))
  4662. (todo-wds (if (member "*" todo)
  4663. (progn
  4664. (org-agenda-prepare-buffers (org-agenda-files
  4665. nil 'ifmode))
  4666. (org-delete-all
  4667. org-done-keywords-for-agenda
  4668. (copy-sequence org-todo-keywords-for-agenda)))
  4669. todo))
  4670. (todo-re (concat "^\\*+[ \t]+\\("
  4671. (mapconcat 'identity todo-wds "\\|")
  4672. "\\)\\>"))
  4673. (tags (nth 2 org-stuck-projects))
  4674. (tags-re (if (member "*" tags)
  4675. (concat org-outline-regexp-bol
  4676. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4677. (if tags
  4678. (concat org-outline-regexp-bol
  4679. ".*:\\("
  4680. (mapconcat 'identity tags "\\|")
  4681. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4682. (gen-re (nth 3 org-stuck-projects))
  4683. (re-list
  4684. (delq nil
  4685. (list
  4686. (if todo todo-re)
  4687. (if tags tags-re)
  4688. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4689. gen-re)))))
  4690. (setq org-agenda-skip-regexp
  4691. (if re-list
  4692. (mapconcat 'identity re-list "\\|")
  4693. (error "No information how to identify unstuck projects")))
  4694. (org-tags-view nil matcher)
  4695. (setq org-agenda-buffer-name (buffer-name))
  4696. (with-current-buffer org-agenda-buffer-name
  4697. (setq org-agenda-redo-command
  4698. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4699. ;;; Diary integration
  4700. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4701. (defvar diary-list-entries-hook)
  4702. (defvar diary-time-regexp)
  4703. (defun org-get-entries-from-diary (date)
  4704. "Get the (Emacs Calendar) diary entries for DATE."
  4705. (require 'diary-lib)
  4706. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4707. (diary-display-hook '(fancy-diary-display))
  4708. (diary-display-function 'fancy-diary-display)
  4709. (pop-up-frames nil)
  4710. (diary-list-entries-hook
  4711. (cons 'org-diary-default-entry diary-list-entries-hook))
  4712. (diary-file-name-prefix nil) ; turn this feature off
  4713. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4714. entries
  4715. (org-disable-agenda-to-diary t))
  4716. (save-excursion
  4717. (save-window-excursion
  4718. (funcall (if (fboundp 'diary-list-entries)
  4719. 'diary-list-entries 'list-diary-entries)
  4720. date 1)))
  4721. (if (not (get-buffer diary-fancy-buffer))
  4722. (setq entries nil)
  4723. (with-current-buffer diary-fancy-buffer
  4724. (setq buffer-read-only nil)
  4725. (if (zerop (buffer-size))
  4726. ;; No entries
  4727. (setq entries nil)
  4728. ;; Omit the date and other unnecessary stuff
  4729. (org-agenda-cleanup-fancy-diary)
  4730. ;; Add prefix to each line and extend the text properties
  4731. (if (zerop (buffer-size))
  4732. (setq entries nil)
  4733. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4734. (setq entries
  4735. (with-temp-buffer
  4736. (insert entries) (goto-char (point-min))
  4737. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4738. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4739. (replace-match (concat "; " (match-string 1)))))
  4740. (buffer-string)))))
  4741. (set-buffer-modified-p nil)
  4742. (kill-buffer diary-fancy-buffer)))
  4743. (when entries
  4744. (setq entries (org-split-string entries "\n"))
  4745. (setq entries
  4746. (mapcar
  4747. (lambda (x)
  4748. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4749. ;; Extend the text properties to the beginning of the line
  4750. (org-add-props x (text-properties-at (1- (length x)) x)
  4751. 'type "diary" 'date date 'face 'org-agenda-diary))
  4752. entries)))))
  4753. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4754. "Hook run when the fancy diary buffer is cleaned up.")
  4755. (defun org-agenda-cleanup-fancy-diary ()
  4756. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4757. This gets rid of the date, the underline under the date, and
  4758. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4759. date. It also removes lines that contain only whitespace."
  4760. (goto-char (point-min))
  4761. (if (looking-at ".*?:[ \t]*")
  4762. (progn
  4763. (replace-match "")
  4764. (re-search-forward "\n=+$" nil t)
  4765. (replace-match "")
  4766. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4767. (re-search-forward "\n=+$" nil t)
  4768. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4769. (goto-char (point-min))
  4770. (while (re-search-forward "^ +\n" nil t)
  4771. (replace-match ""))
  4772. (goto-char (point-min))
  4773. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4774. (replace-match ""))
  4775. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4776. ;; Make sure entries from the diary have the right text properties.
  4777. (eval-after-load "diary-lib"
  4778. '(if (boundp 'diary-modify-entry-list-string-function)
  4779. ;; We can rely on the hook, nothing to do
  4780. nil
  4781. ;; Hook not available, must use advice to make this work
  4782. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4783. "Make the position visible."
  4784. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4785. (stringp string)
  4786. buffer-file-name)
  4787. (setq string (org-modify-diary-entry-string string))))))
  4788. (defun org-modify-diary-entry-string (string)
  4789. "Add text properties to string, allowing org-mode to act on it."
  4790. (org-add-props string nil
  4791. 'mouse-face 'highlight
  4792. 'help-echo (if buffer-file-name
  4793. (format "mouse-2 or RET jump to diary file %s"
  4794. (abbreviate-file-name buffer-file-name))
  4795. "")
  4796. 'org-agenda-diary-link t
  4797. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4798. (defun org-diary-default-entry ()
  4799. "Add a dummy entry to the diary.
  4800. Needed to avoid empty dates which mess up holiday display."
  4801. ;; Catch the error if dealing with the new add-to-diary-alist
  4802. (when org-disable-agenda-to-diary
  4803. (condition-case nil
  4804. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4805. (error
  4806. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4807. (defun org-add-to-diary-list (&rest args)
  4808. (if (fboundp 'diary-add-to-list)
  4809. (apply 'diary-add-to-list args)
  4810. (apply 'add-to-diary-list args)))
  4811. (defvar org-diary-last-run-time nil)
  4812. ;;;###autoload
  4813. (defun org-diary (&rest args)
  4814. "Return diary information from org files.
  4815. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4816. It accesses org files and extracts information from those files to be
  4817. listed in the diary. The function accepts arguments specifying what
  4818. items should be listed. For a list of arguments allowed here, see the
  4819. variable `org-agenda-entry-types'.
  4820. The call in the diary file should look like this:
  4821. &%%(org-diary) ~/path/to/some/orgfile.org
  4822. Use a separate line for each org file to check. Or, if you omit the file name,
  4823. all files listed in `org-agenda-files' will be checked automatically:
  4824. &%%(org-diary)
  4825. If you don't give any arguments (as in the example above), the default value
  4826. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4827. So the example above may also be written as
  4828. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4829. The function expects the lisp variables `entry' and `date' to be provided
  4830. by the caller, because this is how the calendar works. Don't use this
  4831. function from a program - use `org-agenda-get-day-entries' instead."
  4832. (when (> (- (org-float-time)
  4833. org-agenda-last-marker-time)
  4834. 5)
  4835. ;; I am not sure if this works with sticky agendas, because the marker
  4836. ;; list is then no longer a global variable.
  4837. (org-agenda-reset-markers))
  4838. (org-compile-prefix-format 'agenda)
  4839. (org-set-sorting-strategy 'agenda)
  4840. (setq args (or args org-agenda-entry-types))
  4841. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4842. (list entry)
  4843. (org-agenda-files t)))
  4844. (time (org-float-time))
  4845. file rtn results)
  4846. (when (or (not org-diary-last-run-time)
  4847. (> (- time
  4848. org-diary-last-run-time)
  4849. 3))
  4850. (org-agenda-prepare-buffers files))
  4851. (setq org-diary-last-run-time time)
  4852. ;; If this is called during org-agenda, don't return any entries to
  4853. ;; the calendar. Org Agenda will list these entries itself.
  4854. (if org-disable-agenda-to-diary (setq files nil))
  4855. (while (setq file (pop files))
  4856. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4857. (setq results (append results rtn)))
  4858. (when results
  4859. (setq results
  4860. (mapcar (lambda (i) (replace-regexp-in-string
  4861. org-bracket-link-regexp "\\3" i)) results))
  4862. (concat (org-agenda-finalize-entries results) "\n"))))
  4863. ;;; Agenda entry finders
  4864. (defun org-agenda-get-day-entries (file date &rest args)
  4865. "Does the work for `org-diary' and `org-agenda'.
  4866. FILE is the path to a file to be checked for entries. DATE is date like
  4867. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4868. which kind of entries should be extracted. For details about these, see
  4869. the documentation of `org-diary'."
  4870. (setq args (or args org-agenda-entry-types))
  4871. (let* ((org-startup-folded nil)
  4872. (org-startup-align-all-tables nil)
  4873. (buffer (if (file-exists-p file)
  4874. (org-get-agenda-file-buffer file)
  4875. (error "No such file %s" file)))
  4876. arg results rtn deadline-results)
  4877. (if (not buffer)
  4878. ;; If file does not exist, make sure an error message ends up in diary
  4879. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4880. (with-current-buffer buffer
  4881. (unless (derived-mode-p 'org-mode)
  4882. (error "Agenda file %s is not in `org-mode'" file))
  4883. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4884. (let ((case-fold-search nil))
  4885. (save-excursion
  4886. (save-restriction
  4887. (if (eq buffer org-agenda-restrict)
  4888. (narrow-to-region org-agenda-restrict-begin
  4889. org-agenda-restrict-end)
  4890. (widen))
  4891. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4892. (while (setq arg (pop args))
  4893. (cond
  4894. ((and (eq arg :todo)
  4895. (equal date (calendar-gregorian-from-absolute
  4896. (org-today))))
  4897. (setq rtn (org-agenda-get-todos))
  4898. (setq results (append results rtn)))
  4899. ((eq arg :timestamp)
  4900. (setq rtn (org-agenda-get-blocks))
  4901. (setq results (append results rtn))
  4902. (setq rtn (org-agenda-get-timestamps deadline-results))
  4903. (setq results (append results rtn)))
  4904. ((eq arg :sexp)
  4905. (setq rtn (org-agenda-get-sexps))
  4906. (setq results (append results rtn)))
  4907. ((eq arg :scheduled)
  4908. (setq rtn (org-agenda-get-scheduled deadline-results))
  4909. (setq results (append results rtn)))
  4910. ((eq arg :scheduled*)
  4911. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4912. (setq results (append results rtn)))
  4913. ((eq arg :closed)
  4914. (setq rtn (org-agenda-get-progress))
  4915. (setq results (append results rtn)))
  4916. ((eq arg :deadline)
  4917. (setq rtn (org-agenda-get-deadlines))
  4918. (setq deadline-results (copy-sequence rtn))
  4919. (setq results (append results rtn)))
  4920. ((eq arg :deadline*)
  4921. (setq rtn (org-agenda-get-deadlines t))
  4922. (setq deadline-results (copy-sequence rtn))
  4923. (setq results (append results rtn))))))))
  4924. results))))
  4925. (defsubst org-em (x y list)
  4926. "Is X or Y a member of LIST?"
  4927. (or (memq x list) (memq y list)))
  4928. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4929. (defvar org-agenda-sorting-strategy-selected nil)
  4930. (defun org-agenda-get-todos ()
  4931. "Return the TODO information for agenda display."
  4932. (let* ((props (list 'face nil
  4933. 'done-face 'org-agenda-done
  4934. 'org-not-done-regexp org-not-done-regexp
  4935. 'org-todo-regexp org-todo-regexp
  4936. 'org-complex-heading-regexp org-complex-heading-regexp
  4937. 'mouse-face 'highlight
  4938. 'help-echo
  4939. (format "mouse-2 or RET jump to org file %s"
  4940. (abbreviate-file-name buffer-file-name))))
  4941. (regexp (format org-heading-keyword-regexp-format
  4942. (cond
  4943. ((and org-select-this-todo-keyword
  4944. (equal org-select-this-todo-keyword "*"))
  4945. org-todo-regexp)
  4946. (org-select-this-todo-keyword
  4947. (concat "\\("
  4948. (mapconcat 'identity
  4949. (org-split-string
  4950. org-select-this-todo-keyword
  4951. "|")
  4952. "\\|") "\\)"))
  4953. (t org-not-done-regexp))))
  4954. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4955. ee txt beg end inherited-tags todo-state-end-pos)
  4956. (goto-char (point-min))
  4957. (while (re-search-forward regexp nil t)
  4958. (catch :skip
  4959. (save-match-data
  4960. (beginning-of-line)
  4961. (org-agenda-skip)
  4962. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4963. (unless (and (setq todo-state (org-get-todo-state))
  4964. (setq todo-state-end-pos (match-end 2)))
  4965. (goto-char end)
  4966. (throw :skip nil))
  4967. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4968. (goto-char (1+ beg))
  4969. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4970. (throw :skip nil)))
  4971. (goto-char (match-beginning 2))
  4972. (setq marker (org-agenda-new-marker (match-beginning 0))
  4973. category (org-get-category)
  4974. ts-date (let (ts)
  4975. (save-match-data
  4976. (cond ((org-em 'scheduled-up 'scheduled-down
  4977. org-agenda-sorting-strategy-selected)
  4978. (setq ts (org-entry-get (point) "SCHEDULED")
  4979. ts-date-type " scheduled"))
  4980. ((org-em 'deadline-up 'deadline-down
  4981. org-agenda-sorting-strategy-selected)
  4982. (setq ts (org-entry-get (point) "DEADLINE")
  4983. ts-date-type " deadline"))
  4984. ((org-em 'ts-up 'ts-down
  4985. org-agenda-sorting-strategy-selected)
  4986. (setq ts (org-entry-get (point) "TIMESTAMP")
  4987. ts-date-type " timestamp"))
  4988. ((org-em 'tsia-up 'tsia-down
  4989. org-agenda-sorting-strategy-selected)
  4990. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4991. ts-date-type " timestamp_ia"))
  4992. ((org-em 'timestamp-up 'timestamp-down
  4993. org-agenda-sorting-strategy-selected)
  4994. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4995. (org-entry-get (point) "DEADLINE")
  4996. (org-entry-get (point) "TIMESTAMP")
  4997. (org-entry-get (point) "TIMESTAMP_IA"))
  4998. ts-date-type ""))
  4999. (t (setq ts-date-type "")))
  5000. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  5001. category-pos (get-text-property (point) 'org-category-position)
  5002. txt (org-trim
  5003. (buffer-substring (match-beginning 2) (match-end 0)))
  5004. inherited-tags
  5005. (or (eq org-agenda-show-inherited-tags 'always)
  5006. (and (listp org-agenda-show-inherited-tags)
  5007. (memq 'todo org-agenda-show-inherited-tags))
  5008. (and (eq org-agenda-show-inherited-tags t)
  5009. (or (eq org-agenda-use-tag-inheritance t)
  5010. (memq 'todo org-agenda-use-tag-inheritance))))
  5011. tags (org-get-tags-at nil (not inherited-tags))
  5012. level (make-string (org-reduced-level (org-outline-level)) ? )
  5013. txt (org-agenda-format-item "" txt level category tags t)
  5014. priority (1+ (org-get-priority txt)))
  5015. (org-add-props txt props
  5016. 'org-marker marker 'org-hd-marker marker
  5017. 'priority priority 'org-category category
  5018. 'level level
  5019. 'ts-date ts-date
  5020. 'org-category-position category-pos
  5021. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5022. (push txt ee)
  5023. (if org-agenda-todo-list-sublevels
  5024. (goto-char todo-state-end-pos)
  5025. (org-end-of-subtree 'invisible))))
  5026. (nreverse ee)))
  5027. (defun org-agenda-todo-custom-ignore-p (time n)
  5028. "Check whether timestamp is farther away than n number of days.
  5029. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5030. `org-agenda-todo-ignore-scheduled' or
  5031. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5032. (let ((days (org-time-stamp-to-now
  5033. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5034. (if (>= n 0)
  5035. (>= days n)
  5036. (<= days n))))
  5037. ;;;###autoload
  5038. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5039. (&optional end)
  5040. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5041. (when (or org-agenda-todo-ignore-with-date
  5042. org-agenda-todo-ignore-scheduled
  5043. org-agenda-todo-ignore-deadlines
  5044. org-agenda-todo-ignore-timestamp)
  5045. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5046. (save-excursion
  5047. (or (and org-agenda-todo-ignore-with-date
  5048. (re-search-forward org-ts-regexp end t))
  5049. (and org-agenda-todo-ignore-scheduled
  5050. (re-search-forward org-scheduled-time-regexp end t)
  5051. (cond
  5052. ((eq org-agenda-todo-ignore-scheduled 'future)
  5053. (> (org-time-stamp-to-now
  5054. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5055. ((eq org-agenda-todo-ignore-scheduled 'past)
  5056. (<= (org-time-stamp-to-now
  5057. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5058. ((numberp org-agenda-todo-ignore-scheduled)
  5059. (org-agenda-todo-custom-ignore-p
  5060. (match-string 1) org-agenda-todo-ignore-scheduled))
  5061. (t)))
  5062. (and org-agenda-todo-ignore-deadlines
  5063. (re-search-forward org-deadline-time-regexp end t)
  5064. (cond
  5065. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5066. ((eq org-agenda-todo-ignore-deadlines 'far)
  5067. (not (org-deadline-close (match-string 1))))
  5068. ((eq org-agenda-todo-ignore-deadlines 'future)
  5069. (> (org-time-stamp-to-now
  5070. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5071. ((eq org-agenda-todo-ignore-deadlines 'past)
  5072. (<= (org-time-stamp-to-now
  5073. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5074. ((numberp org-agenda-todo-ignore-deadlines)
  5075. (org-agenda-todo-custom-ignore-p
  5076. (match-string 1) org-agenda-todo-ignore-deadlines))
  5077. (t (org-deadline-close (match-string 1)))))
  5078. (and org-agenda-todo-ignore-timestamp
  5079. (let ((buffer (current-buffer))
  5080. (regexp
  5081. (concat
  5082. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5083. (start (point)))
  5084. ;; Copy current buffer into a temporary one
  5085. (with-temp-buffer
  5086. (insert-buffer-substring buffer start end)
  5087. (goto-char (point-min))
  5088. ;; Delete SCHEDULED and DEADLINE items
  5089. (while (re-search-forward regexp end t)
  5090. (delete-region (match-beginning 0) (match-end 0)))
  5091. (goto-char (point-min))
  5092. ;; No search for timestamp left
  5093. (when (re-search-forward org-ts-regexp nil t)
  5094. (cond
  5095. ((eq org-agenda-todo-ignore-timestamp 'future)
  5096. (> (org-time-stamp-to-now
  5097. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5098. ((eq org-agenda-todo-ignore-timestamp 'past)
  5099. (<= (org-time-stamp-to-now
  5100. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5101. ((numberp org-agenda-todo-ignore-timestamp)
  5102. (org-agenda-todo-custom-ignore-p
  5103. (match-string 1) org-agenda-todo-ignore-timestamp))
  5104. (t))))))))))
  5105. (defun org-agenda-get-timestamps (&optional deadline-results)
  5106. "Return the date stamp information for agenda display."
  5107. (let* ((props (list 'face 'org-agenda-calendar-event
  5108. 'org-not-done-regexp org-not-done-regexp
  5109. 'org-todo-regexp org-todo-regexp
  5110. 'org-complex-heading-regexp org-complex-heading-regexp
  5111. 'mouse-face 'highlight
  5112. 'help-echo
  5113. (format "mouse-2 or RET jump to org file %s"
  5114. (abbreviate-file-name buffer-file-name))))
  5115. (d1 (calendar-absolute-from-gregorian date))
  5116. mm
  5117. (deadline-position-alist
  5118. (mapcar (lambda (a) (and (setq mm (get-text-property
  5119. 0 'org-hd-marker a))
  5120. (cons (marker-position mm) a)))
  5121. deadline-results))
  5122. (remove-re org-ts-regexp)
  5123. (regexp
  5124. (concat
  5125. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5126. (regexp-quote
  5127. (substring
  5128. (format-time-string
  5129. (car org-time-stamp-formats)
  5130. (apply 'encode-time ; DATE bound by calendar
  5131. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5132. 1 11))
  5133. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5134. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5135. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5136. donep tmp priority category category-pos level ee txt timestr tags
  5137. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5138. inherited-tags ts-date)
  5139. (goto-char (point-min))
  5140. (while (setq end-of-match (re-search-forward regexp nil t))
  5141. (setq b0 (match-beginning 0)
  5142. b3 (match-beginning 3) e3 (match-end 3)
  5143. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5144. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5145. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5146. (member todo-state
  5147. org-agenda-repeating-timestamp-show-all)))
  5148. (catch :skip
  5149. (and (org-at-date-range-p) (throw :skip nil))
  5150. (org-agenda-skip)
  5151. (if (and (match-end 1)
  5152. (not (= d1 (org-time-string-to-absolute
  5153. (match-string 1) d1 nil show-all
  5154. (current-buffer) b0))))
  5155. (throw :skip nil))
  5156. (if (and e3
  5157. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5158. (throw :skip nil))
  5159. (setq tmp (buffer-substring (max (point-min)
  5160. (- b0 org-ds-keyword-length))
  5161. b0)
  5162. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5163. inactivep (= (char-after b0) ?\[)
  5164. deadlinep (string-match org-deadline-regexp tmp)
  5165. scheduledp (string-match org-scheduled-regexp tmp)
  5166. closedp (and org-agenda-include-inactive-timestamps
  5167. (string-match org-closed-string tmp))
  5168. clockp (and org-agenda-include-inactive-timestamps
  5169. (or (string-match org-clock-string tmp)
  5170. (string-match "]-+\\'" tmp)))
  5171. warntime (get-text-property (point) 'org-appt-warntime)
  5172. donep (member todo-state org-done-keywords))
  5173. (if (or scheduledp deadlinep closedp clockp
  5174. (and donep org-agenda-skip-timestamp-if-done))
  5175. (throw :skip t))
  5176. (if (string-match ">" timestr)
  5177. ;; substring should only run to end of time stamp
  5178. (setq timestr (substring timestr 0 (match-end 0))))
  5179. (setq marker (org-agenda-new-marker b0)
  5180. category (org-get-category b0)
  5181. category-pos (get-text-property b0 'org-category-position))
  5182. (save-excursion
  5183. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5184. (throw :skip nil)
  5185. (goto-char (match-beginning 0))
  5186. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5187. (assoc (point) deadline-position-alist))
  5188. (throw :skip nil))
  5189. (setq hdmarker (org-agenda-new-marker)
  5190. inherited-tags
  5191. (or (eq org-agenda-show-inherited-tags 'always)
  5192. (and (listp org-agenda-show-inherited-tags)
  5193. (memq 'agenda org-agenda-show-inherited-tags))
  5194. (and (eq org-agenda-show-inherited-tags t)
  5195. (or (eq org-agenda-use-tag-inheritance t)
  5196. (memq 'agenda org-agenda-use-tag-inheritance))))
  5197. tags (org-get-tags-at nil (not inherited-tags))
  5198. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5199. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5200. (setq head (or (match-string 1) ""))
  5201. (setq txt (org-agenda-format-item
  5202. (if inactivep org-agenda-inactive-leader nil)
  5203. head level category tags timestr
  5204. remove-re habitp)))
  5205. (setq priority (org-get-priority txt))
  5206. (org-add-props txt props 'priority priority
  5207. 'org-marker marker 'org-hd-marker hdmarker
  5208. 'org-category category 'date date
  5209. 'level level
  5210. 'ts-date
  5211. (ignore-errors (org-time-string-to-absolute timestr))
  5212. 'org-category-position category-pos
  5213. 'todo-state todo-state
  5214. 'warntime warntime
  5215. 'type "timestamp")
  5216. (push txt ee))
  5217. (if org-agenda-skip-additional-timestamps-same-entry
  5218. (outline-next-heading)
  5219. (goto-char end-of-match))))
  5220. (nreverse ee)))
  5221. (defun org-agenda-get-sexps ()
  5222. "Return the sexp information for agenda display."
  5223. (require 'diary-lib)
  5224. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5225. 'mouse-face 'highlight
  5226. 'help-echo
  5227. (format "mouse-2 or RET jump to org file %s"
  5228. (abbreviate-file-name buffer-file-name))))
  5229. (regexp "^&?%%(")
  5230. marker category extra category-pos level ee txt tags entry
  5231. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5232. (goto-char (point-min))
  5233. (while (re-search-forward regexp nil t)
  5234. (catch :skip
  5235. (org-agenda-skip)
  5236. (setq beg (match-beginning 0))
  5237. (goto-char (1- (match-end 0)))
  5238. (setq b (point))
  5239. (forward-sexp 1)
  5240. (setq sexp (buffer-substring b (point)))
  5241. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5242. (org-trim (match-string 1))
  5243. ""))
  5244. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5245. (when result
  5246. (setq marker (org-agenda-new-marker beg)
  5247. level (make-string (org-reduced-level (org-outline-level)) ? )
  5248. category (org-get-category beg)
  5249. category-pos (get-text-property beg 'org-category-position)
  5250. inherited-tags
  5251. (or (eq org-agenda-show-inherited-tags 'always)
  5252. (and (listp org-agenda-show-inherited-tags)
  5253. (memq 'agenda org-agenda-show-inherited-tags))
  5254. (and (eq org-agenda-show-inherited-tags t)
  5255. (or (eq org-agenda-use-tag-inheritance t)
  5256. (memq 'agenda org-agenda-use-tag-inheritance))))
  5257. tags (org-get-tags-at nil (not inherited-tags))
  5258. todo-state (org-get-todo-state)
  5259. warntime (get-text-property (point) 'org-appt-warntime)
  5260. extra nil)
  5261. (dolist (r (if (stringp result)
  5262. (list result)
  5263. result)) ;; we expect a list here
  5264. (when (and org-agenda-diary-sexp-prefix
  5265. (string-match org-agenda-diary-sexp-prefix r))
  5266. (setq extra (match-string 0 r)
  5267. r (replace-match "" nil nil r)))
  5268. (if (string-match "\\S-" r)
  5269. (setq txt r)
  5270. (setq txt "SEXP entry returned empty string"))
  5271. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5272. (org-add-props txt props 'org-marker marker
  5273. 'org-category category 'date date 'todo-state todo-state
  5274. 'org-category-position category-pos 'tags tags
  5275. 'level level
  5276. 'type "sexp" 'warntime warntime)
  5277. (push txt ee)))))
  5278. (nreverse ee)))
  5279. ;; Calendar sanity: define some functions that are independent of
  5280. ;; `calendar-date-style'.
  5281. ;; Normally I would like to use ISO format when calling the diary functions,
  5282. ;; but to make sure we still have Emacs 22 compatibility we bind
  5283. ;; also `european-calendar-style' and use european format
  5284. (defun org-anniversary (year month day &optional mark)
  5285. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5286. (org-no-warnings
  5287. (let ((calendar-date-style 'european) (european-calendar-style t))
  5288. (diary-anniversary day month year mark))))
  5289. (defun org-cyclic (N year month day &optional mark)
  5290. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5291. (org-no-warnings
  5292. (let ((calendar-date-style 'european) (european-calendar-style t))
  5293. (diary-cyclic N day month year mark))))
  5294. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5295. "Like `diary-block', but with fixed (ISO) order of arguments."
  5296. (org-no-warnings
  5297. (let ((calendar-date-style 'european) (european-calendar-style t))
  5298. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5299. (defun org-date (year month day &optional mark)
  5300. "Like `diary-date', but with fixed (ISO) order of arguments."
  5301. (org-no-warnings
  5302. (let ((calendar-date-style 'european) (european-calendar-style t))
  5303. (diary-date day month year mark))))
  5304. ;; Define the` org-class' function
  5305. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5306. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5307. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5308. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5309. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5310. `holidays', then any date that is known by the Emacs calendar to be a
  5311. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5312. then those holidays will be skipped."
  5313. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5314. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5315. (d (calendar-absolute-from-gregorian date))
  5316. (h (when skip-weeks (calendar-check-holidays date))))
  5317. (and
  5318. (<= date1 d)
  5319. (<= d date2)
  5320. (= (calendar-day-of-week date) dayname)
  5321. (or (not skip-weeks)
  5322. (progn
  5323. (require 'cal-iso)
  5324. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5325. (not (or (and h (memq 'holidays skip-weeks))
  5326. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5327. entry)))
  5328. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5329. "Like `org-class', but honor `calendar-date-style'.
  5330. The order of the first 2 times 3 arguments depends on the variable
  5331. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5332. So for American calendars, give this as MONTH DAY YEAR, for European as
  5333. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5334. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5335. is any number of ISO weeks in the block period for which the item should
  5336. be skipped.
  5337. This function is here only for backward compatibility and it is deprecated,
  5338. please use `org-class' instead."
  5339. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5340. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5341. (org-class
  5342. (nth 2 date1) (car date1) (nth 1 date1)
  5343. (nth 2 date2) (car date2) (nth 1 date2)
  5344. dayname skip-weeks)))
  5345. (make-obsolete 'org-diary-class 'org-class "")
  5346. (defalias 'org-get-closed 'org-agenda-get-progress)
  5347. (defun org-agenda-get-progress ()
  5348. "Return the logged TODO entries for agenda display."
  5349. (let* ((props (list 'mouse-face 'highlight
  5350. 'org-not-done-regexp org-not-done-regexp
  5351. 'org-todo-regexp org-todo-regexp
  5352. 'org-complex-heading-regexp org-complex-heading-regexp
  5353. 'help-echo
  5354. (format "mouse-2 or RET jump to org file %s"
  5355. (abbreviate-file-name buffer-file-name))))
  5356. (items (if (consp org-agenda-show-log-scoped)
  5357. org-agenda-show-log-scoped
  5358. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5359. '(clock)
  5360. org-agenda-log-mode-items)))
  5361. (parts
  5362. (delq nil
  5363. (list
  5364. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5365. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5366. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5367. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5368. (error "`org-agenda-log-mode-items' is empty")))
  5369. (regexp (concat
  5370. "\\(" parts-re "\\)"
  5371. " *\\["
  5372. (regexp-quote
  5373. (substring
  5374. (format-time-string
  5375. (car org-time-stamp-formats)
  5376. (apply 'encode-time ; DATE bound by calendar
  5377. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5378. 1 11))))
  5379. (org-agenda-search-headline-for-time nil)
  5380. marker hdmarker priority category category-pos level tags closedp
  5381. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5382. (goto-char (point-min))
  5383. (while (re-search-forward regexp nil t)
  5384. (catch :skip
  5385. (org-agenda-skip)
  5386. (setq marker (org-agenda-new-marker (match-beginning 0))
  5387. closedp (equal (match-string 1) org-closed-string)
  5388. statep (equal (string-to-char (match-string 1)) ?-)
  5389. clockp (not (or closedp statep))
  5390. state (and statep (match-string 2))
  5391. category (org-get-category (match-beginning 0))
  5392. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5393. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5394. (when (string-match "\\]" timestr)
  5395. ;; substring should only run to end of time stamp
  5396. (setq rest (substring timestr (match-end 0))
  5397. timestr (substring timestr 0 (match-end 0)))
  5398. (if (and (not closedp) (not statep)
  5399. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5400. rest))
  5401. (progn (setq timestr (concat (substring timestr 0 -1)
  5402. "-" (match-string 1 rest) "]"))
  5403. (setq clocked (match-string 2 rest)))
  5404. (setq clocked "-")))
  5405. (save-excursion
  5406. (setq extra
  5407. (cond
  5408. ((not org-agenda-log-mode-add-notes) nil)
  5409. (statep
  5410. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5411. (match-string 1)))
  5412. (clockp
  5413. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5414. (match-string 1)))))
  5415. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5416. (throw :skip nil)
  5417. (goto-char (match-beginning 0))
  5418. (setq hdmarker (org-agenda-new-marker)
  5419. inherited-tags
  5420. (or (eq org-agenda-show-inherited-tags 'always)
  5421. (and (listp org-agenda-show-inherited-tags)
  5422. (memq 'todo org-agenda-show-inherited-tags))
  5423. (and (eq org-agenda-show-inherited-tags t)
  5424. (or (eq org-agenda-use-tag-inheritance t)
  5425. (memq 'todo org-agenda-use-tag-inheritance))))
  5426. tags (org-get-tags-at nil (not inherited-tags))
  5427. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5428. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5429. (setq txt (match-string 1))
  5430. (when extra
  5431. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5432. (setq txt (concat (substring txt 0 (match-beginning 1))
  5433. " - " extra " " (match-string 2 txt)))
  5434. (setq txt (concat txt " - " extra))))
  5435. (setq txt (org-agenda-format-item
  5436. (cond
  5437. (closedp "Closed: ")
  5438. (statep (concat "State: (" state ")"))
  5439. (t (concat "Clocked: (" clocked ")")))
  5440. txt level category tags timestr)))
  5441. (setq priority 100000)
  5442. (org-add-props txt props
  5443. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5444. 'priority priority 'org-category category
  5445. 'org-category-position category-pos
  5446. 'level level
  5447. 'type "closed" 'date date
  5448. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5449. (push txt ee))
  5450. (goto-char (point-at-eol))))
  5451. (nreverse ee)))
  5452. (defun org-agenda-show-clocking-issues ()
  5453. "Add overlays, showing issues with clocking.
  5454. See also the user option `org-agenda-clock-consistency-checks'."
  5455. (interactive)
  5456. (let* ((org-time-clocksum-use-effort-durations nil)
  5457. (pl org-agenda-clock-consistency-checks)
  5458. (re (concat "^[ \t]*"
  5459. org-clock-string
  5460. "[ \t]+"
  5461. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5462. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5463. (tlstart 0.)
  5464. (tlend 0.)
  5465. (maxtime (org-hh:mm-string-to-minutes
  5466. (or (plist-get pl :max-duration) "24:00")))
  5467. (mintime (org-hh:mm-string-to-minutes
  5468. (or (plist-get pl :min-duration) 0)))
  5469. (maxgap (org-hh:mm-string-to-minutes
  5470. ;; default 30:00 means never complain
  5471. (or (plist-get pl :max-gap) "30:00")))
  5472. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5473. (plist-get pl :gap-ok-around)))
  5474. (def-face (or (plist-get pl :default-face)
  5475. '((:background "DarkRed") (:foreground "white"))))
  5476. issue face m te ts dt ov)
  5477. (goto-char (point-min))
  5478. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5479. (setq issue nil face def-face)
  5480. (catch 'next
  5481. (setq m (org-get-at-bol 'org-marker)
  5482. te nil ts nil)
  5483. (unless (and m (markerp m))
  5484. (setq issue "No valid clock line") (throw 'next t))
  5485. (org-with-point-at m
  5486. (save-excursion
  5487. (goto-char (point-at-bol))
  5488. (unless (looking-at re)
  5489. (error "No valid Clock line")
  5490. (throw 'next t))
  5491. (unless (match-end 3)
  5492. (setq issue "No end time"
  5493. face (or (plist-get pl :no-end-time-face) face))
  5494. (throw 'next t))
  5495. (setq ts (match-string 1)
  5496. te (match-string 3)
  5497. ts (org-float-time
  5498. (apply 'encode-time (org-parse-time-string ts)))
  5499. te (org-float-time
  5500. (apply 'encode-time (org-parse-time-string te)))
  5501. dt (- te ts))))
  5502. (cond
  5503. ((> dt (* 60 maxtime))
  5504. ;; a very long clocking chunk
  5505. (setq issue (format "Clocking interval is very long: %s"
  5506. (org-minutes-to-clocksum-string
  5507. (floor (/ (float dt) 60.))))
  5508. face (or (plist-get pl :long-face) face)))
  5509. ((< dt (* 60 mintime))
  5510. ;; a very short clocking chunk
  5511. (setq issue (format "Clocking interval is very short: %s"
  5512. (org-minutes-to-clocksum-string
  5513. (floor (/ (float dt) 60.))))
  5514. face (or (plist-get pl :short-face) face)))
  5515. ((and (> tlend 0) (< ts tlend))
  5516. ;; Two clock entries are overlapping
  5517. (setq issue (format "Clocking overlap: %d minutes"
  5518. (/ (- tlend ts) 60))
  5519. face (or (plist-get pl :overlap-face) face)))
  5520. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5521. ;; There is a gap, lets see if we need to report it
  5522. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5523. (setq issue (format "Clocking gap: %d minutes"
  5524. (/ (- ts tlend) 60))
  5525. face (or (plist-get pl :gap-face) face))))
  5526. (t nil)))
  5527. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5528. (when issue
  5529. ;; OK, there was some issue, add an overlay to show the issue
  5530. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5531. (overlay-put ov 'before-string
  5532. (concat
  5533. (org-add-props
  5534. (format "%-43s" (concat " " issue))
  5535. nil
  5536. 'face face)
  5537. "\n"))
  5538. (overlay-put ov 'evaporate t)))))
  5539. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5540. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5541. (catch 'exit
  5542. (unless ok-list
  5543. ;; there are no OK times for gaps...
  5544. (throw 'exit nil))
  5545. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5546. ;; This is more than 24 hours, so it is OK.
  5547. ;; because we have at least one OK time, that must be in the
  5548. ;; 24 hour interval.
  5549. (throw 'exit t))
  5550. ;; We have a shorter gap.
  5551. ;; Now we have to get the minute of the day when these times are
  5552. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5553. (t2dec (decode-time (seconds-to-time t2)))
  5554. ;; compute the minute on the day
  5555. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5556. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5557. (when (< min2 min1)
  5558. ;; if min2 is smaller than min1, this means it is on the next day.
  5559. ;; Wrap it to after midnight.
  5560. (setq min2 (+ min2 1440)))
  5561. ;; Now check if any of the OK times is in the gap
  5562. (mapc (lambda (x)
  5563. ;; Wrap the time to after midnight if necessary
  5564. (if (< x min1) (setq x (+ x 1440)))
  5565. ;; Check if in interval
  5566. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5567. ok-list)
  5568. ;; Nope, this gap is not OK
  5569. nil)))
  5570. (defun org-agenda-get-deadlines (&optional with-hour)
  5571. "Return the deadline information for agenda display.
  5572. When WITH-HOUR is non-nil, only return deadlines with an hour
  5573. specification like [h]h:mm."
  5574. (let* ((props (list 'mouse-face 'highlight
  5575. 'org-not-done-regexp org-not-done-regexp
  5576. 'org-todo-regexp org-todo-regexp
  5577. 'org-complex-heading-regexp org-complex-heading-regexp
  5578. 'help-echo
  5579. (format "mouse-2 or RET jump to org file %s"
  5580. (abbreviate-file-name buffer-file-name))))
  5581. (regexp (if with-hour
  5582. org-deadline-time-hour-regexp
  5583. org-deadline-time-regexp))
  5584. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5585. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5586. (dl0 (car org-agenda-deadline-leaders))
  5587. (dl1 (nth 1 org-agenda-deadline-leaders))
  5588. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5589. d2 diff dfrac wdays pos pos1 category category-pos level
  5590. tags suppress-prewarning ee txt head face s todo-state
  5591. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5592. (goto-char (point-min))
  5593. (while (re-search-forward regexp nil t)
  5594. (catch :skip
  5595. (org-agenda-skip)
  5596. (setq s (match-string 1)
  5597. txt nil
  5598. pos (1- (match-beginning 1))
  5599. todo-state (save-match-data (org-get-todo-state))
  5600. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5601. (member todo-state
  5602. org-agenda-repeating-timestamp-show-all))
  5603. d2 (org-time-string-to-absolute
  5604. s d1 'past show-all (current-buffer) pos)
  5605. diff (- d2 d1))
  5606. (setq suppress-prewarning
  5607. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5608. (let ((item (buffer-substring (point-at-bol)
  5609. (point-at-eol))))
  5610. (save-match-data
  5611. (and (string-match
  5612. org-scheduled-time-regexp item)
  5613. (match-string 1 item)))))))
  5614. (cond
  5615. ((not ds) nil)
  5616. ;; The current item has a scheduled date (in ds), so
  5617. ;; evaluate its prewarning lead time.
  5618. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5619. ;; Use global prewarning-restart lead time.
  5620. org-agenda-skip-deadline-prewarning-if-scheduled)
  5621. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5622. 'pre-scheduled)
  5623. ;; Set prewarning to no earlier than scheduled.
  5624. (min (- d2 (org-time-string-to-absolute
  5625. ds d1 'past show-all (current-buffer) pos))
  5626. org-deadline-warning-days))
  5627. ;; Set prewarning to deadline.
  5628. (t 0))))
  5629. (setq wdays (if suppress-prewarning
  5630. (let ((org-deadline-warning-days suppress-prewarning))
  5631. (org-get-wdays s))
  5632. (org-get-wdays s))
  5633. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5634. upcomingp (and todayp (> diff 0)))
  5635. ;; When to show a deadline in the calendar:
  5636. ;; If the expiration is within wdays warning time.
  5637. ;; Past-due deadlines are only shown on the current date
  5638. (if (and (or (and (<= diff wdays)
  5639. (and todayp (not org-agenda-only-exact-dates)))
  5640. (= diff 0)))
  5641. (save-excursion
  5642. ;; (setq todo-state (org-get-todo-state))
  5643. (setq donep (member todo-state org-done-keywords))
  5644. (if (and donep
  5645. (or org-agenda-skip-deadline-if-done
  5646. (not (= diff 0))))
  5647. (setq txt nil)
  5648. (setq category (org-get-category)
  5649. warntime (get-text-property (point) 'org-appt-warntime)
  5650. category-pos (get-text-property (point) 'org-category-position))
  5651. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5652. (throw :skip nil)
  5653. (goto-char (match-end 0))
  5654. (setq pos1 (match-beginning 0))
  5655. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5656. (setq inherited-tags
  5657. (or (eq org-agenda-show-inherited-tags 'always)
  5658. (and (listp org-agenda-show-inherited-tags)
  5659. (memq 'agenda org-agenda-show-inherited-tags))
  5660. (and (eq org-agenda-show-inherited-tags t)
  5661. (or (eq org-agenda-use-tag-inheritance t)
  5662. (memq 'agenda org-agenda-use-tag-inheritance))))
  5663. tags (org-get-tags-at pos1 (not inherited-tags)))
  5664. (setq head (buffer-substring
  5665. (point)
  5666. (progn (skip-chars-forward "^\r\n")
  5667. (point))))
  5668. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5669. (setq timestr
  5670. (concat (substring s (match-beginning 1)) " "))
  5671. (setq timestr 'time))
  5672. (setq txt (org-agenda-format-item
  5673. (cond ((= diff 0) dl0)
  5674. ((> diff 0)
  5675. (if (functionp dl1)
  5676. (funcall dl1 diff date)
  5677. (format dl1 diff)))
  5678. (t
  5679. (if (functionp dl2)
  5680. (funcall dl2 diff date)
  5681. (format dl2 (if (string= dl2 dl1)
  5682. diff (abs diff))))))
  5683. head level category tags
  5684. (if (not (= diff 0)) nil timestr)))))
  5685. (when txt
  5686. (setq face (org-agenda-deadline-face dfrac))
  5687. (org-add-props txt props
  5688. 'org-marker (org-agenda-new-marker pos)
  5689. 'warntime warntime
  5690. 'level level
  5691. 'ts-date d2
  5692. 'org-hd-marker (org-agenda-new-marker pos1)
  5693. 'priority (+ (- diff)
  5694. (org-get-priority txt))
  5695. 'org-category category
  5696. 'org-category-position category-pos
  5697. 'todo-state todo-state
  5698. 'type (if upcomingp "upcoming-deadline" "deadline")
  5699. 'date (if upcomingp date d2)
  5700. 'face (if donep 'org-agenda-done face)
  5701. 'undone-face face 'done-face 'org-agenda-done)
  5702. (push txt ee))))))
  5703. (nreverse ee)))
  5704. (defun org-agenda-deadline-face (fraction)
  5705. "Return the face to displaying a deadline item.
  5706. FRACTION is what fraction of the head-warning time has passed."
  5707. (let ((faces org-agenda-deadline-faces) f)
  5708. (catch 'exit
  5709. (while (setq f (pop faces))
  5710. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5711. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5712. "Return the scheduled information for agenda display.
  5713. When WITH-HOUR is non-nil, only return scheduled items with
  5714. an hour specification like [h]h:mm."
  5715. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5716. 'org-todo-regexp org-todo-regexp
  5717. 'org-complex-heading-regexp org-complex-heading-regexp
  5718. 'done-face 'org-agenda-done
  5719. 'mouse-face 'highlight
  5720. 'help-echo
  5721. (format "mouse-2 or RET jump to org file %s"
  5722. (abbreviate-file-name buffer-file-name))))
  5723. (regexp (if with-hour
  5724. org-scheduled-time-hour-regexp
  5725. org-scheduled-time-regexp))
  5726. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5727. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5728. mm
  5729. (deadline-position-alist
  5730. (mapcar (lambda (a) (and (setq mm (get-text-property
  5731. 0 'org-hd-marker a))
  5732. (cons (marker-position mm) a)))
  5733. deadline-results))
  5734. d2 diff pos pos1 category category-pos level tags donep
  5735. ee txt head pastschedp todo-state face timestr s habitp show-all
  5736. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5737. ddays)
  5738. (goto-char (point-min))
  5739. (while (re-search-forward regexp nil t)
  5740. (catch :skip
  5741. (org-agenda-skip)
  5742. (setq s (match-string 1)
  5743. txt nil
  5744. pos (1- (match-beginning 1))
  5745. todo-state (save-match-data (org-get-todo-state))
  5746. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5747. (member todo-state
  5748. org-agenda-repeating-timestamp-show-all))
  5749. d2 (org-time-string-to-absolute
  5750. s d1 'past show-all (current-buffer) pos)
  5751. diff (- d2 d1)
  5752. warntime (get-text-property (point) 'org-appt-warntime))
  5753. (setq pastschedp (and todayp (< diff 0)))
  5754. (setq did-habit-check-p nil)
  5755. (setq suppress-delay
  5756. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5757. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5758. (save-match-data
  5759. (and (string-match
  5760. org-deadline-time-regexp item)
  5761. (match-string 1 item)))))))
  5762. (cond
  5763. ((not ds) nil)
  5764. ;; The current item has a deadline date (in ds), so
  5765. ;; evaluate its delay time.
  5766. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5767. ;; Use global delay time.
  5768. (- org-agenda-skip-scheduled-delay-if-deadline))
  5769. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5770. 'post-deadline)
  5771. ;; Set delay to no later than deadline.
  5772. (min (- d2 (org-time-string-to-absolute
  5773. ds d1 'past show-all (current-buffer) pos))
  5774. org-scheduled-delay-days))
  5775. (t 0))))
  5776. (setq ddays (if suppress-delay
  5777. (let ((org-scheduled-delay-days suppress-delay))
  5778. (org-get-wdays s t t))
  5779. (org-get-wdays s t)))
  5780. ;; Use a delay of 0 when there is a repeater and the delay is
  5781. ;; of the form --3d
  5782. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5783. (< (org-time-string-to-absolute s)
  5784. (org-time-string-to-absolute
  5785. s d2 'past nil (current-buffer) pos)))
  5786. (setq ddays 0))
  5787. ;; When to show a scheduled item in the calendar:
  5788. ;; If it is on or past the date.
  5789. (when (or (and (> ddays 0) (= diff (- ddays)))
  5790. (and (zerop ddays) (= diff 0))
  5791. (and (< (+ diff ddays) 0)
  5792. (< (abs diff) org-scheduled-past-days)
  5793. (and todayp (not org-agenda-only-exact-dates)))
  5794. ;; org-is-habit-p uses org-entry-get, which is expansive
  5795. ;; so we go extra mile to only call it once
  5796. (and todayp
  5797. (boundp 'org-habit-show-all-today)
  5798. org-habit-show-all-today
  5799. (setq did-habit-check-p t)
  5800. (setq habitp (and (functionp 'org-is-habit-p)
  5801. (org-is-habit-p)))))
  5802. (save-excursion
  5803. (setq donep (member todo-state org-done-keywords))
  5804. (if (and donep
  5805. (or org-agenda-skip-scheduled-if-done
  5806. (not (= diff 0))
  5807. (and (functionp 'org-is-habit-p)
  5808. (org-is-habit-p))))
  5809. (setq txt nil)
  5810. (setq habitp (if did-habit-check-p habitp
  5811. (and (functionp 'org-is-habit-p)
  5812. (org-is-habit-p))))
  5813. (setq category (org-get-category)
  5814. category-pos (get-text-property (point) 'org-category-position))
  5815. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5816. 'repeated-after-deadline)
  5817. (org-get-deadline-time (point))
  5818. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5819. (throw :skip nil))
  5820. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5821. (throw :skip nil)
  5822. (goto-char (match-end 0))
  5823. (setq pos1 (match-beginning 0))
  5824. (if habitp
  5825. (if (or (not org-habit-show-habits)
  5826. (and (not todayp)
  5827. (boundp 'org-habit-show-habits-only-for-today)
  5828. org-habit-show-habits-only-for-today))
  5829. (throw :skip nil))
  5830. (if (and
  5831. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5832. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5833. pastschedp))
  5834. (setq mm (assoc pos1 deadline-position-alist)))
  5835. (throw :skip nil)))
  5836. (setq inherited-tags
  5837. (or (eq org-agenda-show-inherited-tags 'always)
  5838. (and (listp org-agenda-show-inherited-tags)
  5839. (memq 'agenda org-agenda-show-inherited-tags))
  5840. (and (eq org-agenda-show-inherited-tags t)
  5841. (or (eq org-agenda-use-tag-inheritance t)
  5842. (memq 'agenda org-agenda-use-tag-inheritance))))
  5843. tags (org-get-tags-at nil (not inherited-tags)))
  5844. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5845. (setq head (buffer-substring
  5846. (point)
  5847. (progn (skip-chars-forward "^\r\n") (point))))
  5848. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5849. (setq timestr
  5850. (concat (substring s (match-beginning 1)) " "))
  5851. (setq timestr 'time))
  5852. (setq txt (org-agenda-format-item
  5853. (if (= diff 0)
  5854. (car org-agenda-scheduled-leaders)
  5855. (format (nth 1 org-agenda-scheduled-leaders)
  5856. (- 1 diff)))
  5857. head level category tags
  5858. (if (not (= diff 0)) nil timestr)
  5859. nil habitp))))
  5860. (when txt
  5861. (setq face
  5862. (cond
  5863. ((and (not habitp) pastschedp)
  5864. 'org-scheduled-previously)
  5865. (todayp 'org-scheduled-today)
  5866. (t 'org-scheduled))
  5867. habitp (and habitp (org-habit-parse-todo)))
  5868. (org-add-props txt props
  5869. 'undone-face face
  5870. 'face (if donep 'org-agenda-done face)
  5871. 'org-marker (org-agenda-new-marker pos)
  5872. 'org-hd-marker (org-agenda-new-marker pos1)
  5873. 'type (if pastschedp "past-scheduled" "scheduled")
  5874. 'date (if pastschedp d2 date)
  5875. 'ts-date d2
  5876. 'warntime warntime
  5877. 'level level
  5878. 'priority (if habitp
  5879. (org-habit-get-priority habitp)
  5880. (+ 94 (- 5 diff) (org-get-priority txt)))
  5881. 'org-category category
  5882. 'category-position category-pos
  5883. 'org-habit-p habitp
  5884. 'todo-state todo-state)
  5885. (push txt ee))))))
  5886. (nreverse ee)))
  5887. (defun org-agenda-get-blocks ()
  5888. "Return the date-range information for agenda display."
  5889. (let* ((props (list 'face nil
  5890. 'org-not-done-regexp org-not-done-regexp
  5891. 'org-todo-regexp org-todo-regexp
  5892. 'org-complex-heading-regexp org-complex-heading-regexp
  5893. 'mouse-face 'highlight
  5894. 'help-echo
  5895. (format "mouse-2 or RET jump to org file %s"
  5896. (abbreviate-file-name buffer-file-name))))
  5897. (regexp org-tr-regexp)
  5898. (d0 (calendar-absolute-from-gregorian date))
  5899. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5900. level todo-state tags pos head donep inherited-tags)
  5901. (goto-char (point-min))
  5902. (while (re-search-forward regexp nil t)
  5903. (catch :skip
  5904. (org-agenda-skip)
  5905. (setq pos (point))
  5906. (let ((start-time (match-string 1))
  5907. (end-time (match-string 2)))
  5908. (setq s1 (match-string 1)
  5909. s2 (match-string 2)
  5910. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5911. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5912. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5913. ;; Only allow days between the limits, because the normal
  5914. ;; date stamps will catch the limits.
  5915. (save-excursion
  5916. (setq todo-state (org-get-todo-state))
  5917. (setq donep (member todo-state org-done-keywords))
  5918. (if (and donep org-agenda-skip-timestamp-if-done)
  5919. (throw :skip t))
  5920. (setq marker (org-agenda-new-marker (point)))
  5921. (setq category (org-get-category)
  5922. category-pos (get-text-property (point) 'org-category-position))
  5923. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5924. (throw :skip nil)
  5925. (goto-char (match-beginning 0))
  5926. (setq hdmarker (org-agenda-new-marker (point))
  5927. inherited-tags
  5928. (or (eq org-agenda-show-inherited-tags 'always)
  5929. (and (listp org-agenda-show-inherited-tags)
  5930. (memq 'agenda org-agenda-show-inherited-tags))
  5931. (and (eq org-agenda-show-inherited-tags t)
  5932. (or (eq org-agenda-use-tag-inheritance t)
  5933. (memq 'agenda org-agenda-use-tag-inheritance))))
  5934. tags (org-get-tags-at nil (not inherited-tags)))
  5935. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5936. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5937. (setq head (match-string 1))
  5938. (let ((remove-re
  5939. (if org-agenda-remove-timeranges-from-blocks
  5940. (concat
  5941. "<" (regexp-quote s1) ".*?>"
  5942. "--"
  5943. "<" (regexp-quote s2) ".*?>")
  5944. nil)))
  5945. (setq txt (org-agenda-format-item
  5946. (format
  5947. (nth (if (= d1 d2) 0 1)
  5948. org-agenda-timerange-leaders)
  5949. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5950. head level category tags
  5951. (cond ((and (= d1 d0) (= d2 d0))
  5952. (concat "<" start-time ">--<" end-time ">"))
  5953. ((= d1 d0)
  5954. (concat "<" start-time ">"))
  5955. ((= d2 d0)
  5956. (concat "<" end-time ">")))
  5957. remove-re))))
  5958. (org-add-props txt props
  5959. 'org-marker marker 'org-hd-marker hdmarker
  5960. 'type "block" 'date date
  5961. 'level level
  5962. 'todo-state todo-state
  5963. 'priority (org-get-priority txt) 'org-category category
  5964. 'org-category-position category-pos)
  5965. (push txt ee))))
  5966. (goto-char pos)))
  5967. ;; Sort the entries by expiration date.
  5968. (nreverse ee)))
  5969. ;;; Agenda presentation and sorting
  5970. (defvar org-prefix-has-time nil
  5971. "A flag, set by `org-compile-prefix-format'.
  5972. The flag is set if the currently compiled format contains a `%t'.")
  5973. (defvar org-prefix-has-tag nil
  5974. "A flag, set by `org-compile-prefix-format'.
  5975. The flag is set if the currently compiled format contains a `%T'.")
  5976. (defvar org-prefix-has-effort nil
  5977. "A flag, set by `org-compile-prefix-format'.
  5978. The flag is set if the currently compiled format contains a `%e'.")
  5979. (defvar org-prefix-has-breadcrumbs nil
  5980. "A flag, set by `org-compile-prefix-format'.
  5981. The flag is set if the currently compiled format contains a `%b'.")
  5982. (defvar org-prefix-category-length nil
  5983. "Used by `org-compile-prefix-format' to remember the category field width.")
  5984. (defvar org-prefix-category-max-length nil
  5985. "Used by `org-compile-prefix-format' to remember the category field width.")
  5986. (defun org-agenda-get-category-icon (category)
  5987. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5988. (dolist (entry org-agenda-category-icon-alist)
  5989. (when (org-string-match-p (car entry) category)
  5990. (if (listp (cadr entry))
  5991. (return (cadr entry))
  5992. (return (apply 'create-image (cdr entry)))))))
  5993. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5994. remove-re habitp)
  5995. "Format TXT to be inserted into the agenda buffer.
  5996. In particular, add the prefix and corresponding text properties.
  5997. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5998. LEVEL may be a string to replace the `%l' specifier.
  5999. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6000. category taken from local variable or file name. It will replace the `%c'
  6001. specifier in the format.
  6002. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6003. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6004. When DOTIME is a string, this string is searched for a time before TXT is.
  6005. TAGS can be the tags of the headline.
  6006. Any match of REMOVE-RE will be removed from TXT."
  6007. ;; We keep the org-prefix-* variable values along with a compiled
  6008. ;; formatter, so that multiple agendas existing at the same time do
  6009. ;; not step on each other toes.
  6010. ;;
  6011. ;; It was inconvenient to make these variables buffer local in
  6012. ;; Agenda buffers, because this function expects to be called with
  6013. ;; the buffer where item comes from being current, and not agenda
  6014. ;; buffer
  6015. (let* ((bindings (car org-prefix-format-compiled))
  6016. (formatter (cadr org-prefix-format-compiled)))
  6017. (loop for (var value) in bindings
  6018. do (set var value))
  6019. (save-match-data
  6020. ;; Diary entries sometimes have extra whitespace at the beginning
  6021. (setq txt (org-trim txt))
  6022. ;; Fix the tags part in txt
  6023. (setq txt (org-agenda-fix-displayed-tags
  6024. txt tags
  6025. org-agenda-show-inherited-tags
  6026. org-agenda-hide-tags-regexp))
  6027. (let* ((category (or category
  6028. (if (stringp org-category)
  6029. org-category
  6030. (and org-category (symbol-name org-category)))
  6031. (if buffer-file-name
  6032. (file-name-sans-extension
  6033. (file-name-nondirectory buffer-file-name))
  6034. "")))
  6035. (category-icon (org-agenda-get-category-icon category))
  6036. (category-icon (if category-icon
  6037. (propertize " " 'display category-icon)
  6038. ""))
  6039. ;; time, tag, effort are needed for the eval of the prefix format
  6040. (tag (if tags (nth (1- (length tags)) tags) ""))
  6041. time effort neffort
  6042. (ts (if dotime (concat
  6043. (if (stringp dotime) dotime "")
  6044. (and org-agenda-search-headline-for-time txt))))
  6045. (time-of-day (and dotime (org-get-time-of-day ts)))
  6046. stamp plain s0 s1 s2 rtn srp l
  6047. duration thecategory breadcrumbs)
  6048. (and (derived-mode-p 'org-mode) buffer-file-name
  6049. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6050. (when (and dotime time-of-day)
  6051. ;; Extract starting and ending time and move them to prefix
  6052. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6053. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6054. (setq s0 (match-string 0 ts)
  6055. srp (and stamp (match-end 3))
  6056. s1 (match-string (if plain 1 2) ts)
  6057. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6058. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6059. ;; them, we might want to remove them there to avoid duplication.
  6060. ;; The user can turn this off with a variable.
  6061. (if (and org-prefix-has-time
  6062. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6063. (string-match (concat (regexp-quote s0) " *") txt)
  6064. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6065. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6066. (= (match-beginning 0) 0)
  6067. t))
  6068. (setq txt (replace-match "" nil nil txt))))
  6069. ;; Normalize the time(s) to 24 hour
  6070. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6071. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6072. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6073. (let (org-time-clocksum-use-effort-durations)
  6074. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6075. (setq s2
  6076. (org-minutes-to-clocksum-string
  6077. (+ (org-hh:mm-string-to-minutes s1)
  6078. org-agenda-default-appointment-duration)))))
  6079. ;; Compute the duration
  6080. (when s2
  6081. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6082. (org-hh:mm-string-to-minutes s1)))))
  6083. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6084. txt)
  6085. ;; Tags are in the string
  6086. (if (or (eq org-agenda-remove-tags t)
  6087. (and org-agenda-remove-tags
  6088. org-prefix-has-tag))
  6089. (setq txt (replace-match "" t t txt))
  6090. (setq txt (replace-match
  6091. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6092. (match-string 2 txt))
  6093. t t txt))))
  6094. (when (derived-mode-p 'org-mode)
  6095. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6096. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6097. ;; current buffer, so move this check outside of above
  6098. (if effort
  6099. (setq neffort (org-duration-string-to-minutes effort)
  6100. effort (setq effort (concat "[" effort "]")))
  6101. ;; prevent erroring out with %e format when there is no effort
  6102. (setq effort ""))
  6103. (when remove-re
  6104. (while (string-match remove-re txt)
  6105. (setq txt (replace-match "" t t txt))))
  6106. ;; Set org-heading property on `txt' to mark the start of the
  6107. ;; heading.
  6108. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6109. ;; Prepare the variables needed in the eval of the compiled format
  6110. (if org-prefix-has-breadcrumbs
  6111. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6112. (let ((s (org-display-outline-path nil nil "->" t)))
  6113. (if (eq "" s) "" (concat s "->"))))))
  6114. (setq time (cond (s2 (concat
  6115. (org-agenda-time-of-day-to-ampm-maybe s1)
  6116. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6117. (if org-agenda-timegrid-use-ampm " ")))
  6118. (s1 (concat
  6119. (org-agenda-time-of-day-to-ampm-maybe s1)
  6120. (if org-agenda-timegrid-use-ampm
  6121. "........ "
  6122. "......")))
  6123. (t ""))
  6124. extra (or (and (not habitp) extra) "")
  6125. category (if (symbolp category) (symbol-name category) category)
  6126. thecategory (copy-sequence category)
  6127. level (or level ""))
  6128. (if (string-match org-bracket-link-regexp category)
  6129. (progn
  6130. (setq l (if (match-end 3)
  6131. (- (match-end 3) (match-beginning 3))
  6132. (- (match-end 1) (match-beginning 1))))
  6133. (when (< l (or org-prefix-category-length 0))
  6134. (setq category (copy-sequence category))
  6135. (org-add-props category nil
  6136. 'extra-space (make-string
  6137. (- org-prefix-category-length l 1) ?\ ))))
  6138. (if (and org-prefix-category-max-length
  6139. (>= (length category) org-prefix-category-max-length))
  6140. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6141. ;; Evaluate the compiled format
  6142. (setq rtn (concat (eval formatter) txt))
  6143. ;; And finally add the text properties
  6144. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6145. (org-add-props rtn nil
  6146. 'org-category (if thecategory (downcase thecategory) category)
  6147. 'tags (mapcar 'org-downcase-keep-props tags)
  6148. 'org-highest-priority org-highest-priority
  6149. 'org-lowest-priority org-lowest-priority
  6150. 'time-of-day time-of-day
  6151. 'duration duration
  6152. 'effort effort
  6153. 'effort-minutes neffort
  6154. 'breadcrumbs breadcrumbs
  6155. 'txt txt
  6156. 'level level
  6157. 'time time
  6158. 'extra extra
  6159. 'format org-prefix-format-compiled
  6160. 'dotime dotime)))))
  6161. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6162. "Remove tags string from TXT, and add a modified list of tags.
  6163. The modified list may contain inherited tags, and tags matched by
  6164. `org-agenda-hide-tags-regexp' will be removed."
  6165. (when (or add-inherited hide-re)
  6166. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6167. (setq txt (substring txt 0 (match-beginning 0))))
  6168. (setq tags
  6169. (delq nil
  6170. (mapcar (lambda (tg)
  6171. (if (or (and hide-re (string-match hide-re tg))
  6172. (and (not add-inherited)
  6173. (get-text-property 0 'inherited tg)))
  6174. nil
  6175. tg))
  6176. tags)))
  6177. (when tags
  6178. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6179. i)
  6180. (setq txt (concat txt " :"
  6181. (mapconcat
  6182. (lambda (x)
  6183. (setq i (get-text-property 0 'inherited x))
  6184. (if (and have-i (not i))
  6185. (progn
  6186. (setq have-i nil)
  6187. (concat ":" x))
  6188. x))
  6189. tags ":")
  6190. (if have-i "::" ":"))))))
  6191. txt)
  6192. (defun org-downcase-keep-props (s)
  6193. (let ((props (text-properties-at 0 s)))
  6194. (setq s (downcase s))
  6195. (add-text-properties 0 (length s) props s)
  6196. s))
  6197. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6198. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6199. "Add a time-grid for agenda items which need it.
  6200. LIST is the list of agenda items formatted by `org-agenda-list'.
  6201. NDAYS is the span of the current agenda view.
  6202. TODAYP is `t' when the current agenda view is on today."
  6203. (catch 'exit
  6204. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6205. ((and todayp (member 'today (car org-agenda-time-grid))))
  6206. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6207. ((member 'weekly (car org-agenda-time-grid)))
  6208. (t (throw 'exit list)))
  6209. (let* ((have (delq nil (mapcar
  6210. (lambda (x) (get-text-property 1 'time-of-day x))
  6211. list)))
  6212. (string (nth 1 org-agenda-time-grid))
  6213. (gridtimes (nth 2 org-agenda-time-grid))
  6214. (req (car org-agenda-time-grid))
  6215. (remove (member 'remove-match req))
  6216. new time)
  6217. (if (and (member 'require-timed req) (not have))
  6218. ;; don't show empty grid
  6219. (throw 'exit list))
  6220. (while (setq time (pop gridtimes))
  6221. (unless (and remove (member time have))
  6222. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6223. (push (org-agenda-format-item
  6224. nil string nil "" nil
  6225. (concat (substring time 0 -2) ":" (substring time -2)))
  6226. new)
  6227. (put-text-property
  6228. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6229. (when (and todayp org-agenda-show-current-time-in-grid)
  6230. (push (org-agenda-format-item
  6231. nil org-agenda-current-time-string nil "" nil
  6232. (format-time-string "%H:%M "))
  6233. new)
  6234. (put-text-property
  6235. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6236. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6237. (append new list)
  6238. (append list new)))))
  6239. (defun org-compile-prefix-format (key)
  6240. "Compile the prefix format into a Lisp form that can be evaluated.
  6241. The resulting form and associated variable bindings is returned
  6242. and stored in the variable `org-prefix-format-compiled'."
  6243. (setq org-prefix-has-time nil
  6244. org-prefix-has-tag nil
  6245. org-prefix-category-length nil
  6246. org-prefix-has-effort nil
  6247. org-prefix-has-breadcrumbs nil)
  6248. (let ((s (cond
  6249. ((stringp org-agenda-prefix-format)
  6250. org-agenda-prefix-format)
  6251. ((assq key org-agenda-prefix-format)
  6252. (cdr (assq key org-agenda-prefix-format)))
  6253. (t " %-12:c%?-12t% s")))
  6254. (start 0)
  6255. varform vars var e c f opt)
  6256. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6257. s start)
  6258. (setq var (or (cdr (assoc (match-string 4 s)
  6259. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6260. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6261. 'eval)
  6262. c (or (match-string 3 s) "")
  6263. opt (match-beginning 1)
  6264. start (1+ (match-beginning 0)))
  6265. (if (equal var 'time) (setq org-prefix-has-time t))
  6266. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6267. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6268. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6269. (setq f (concat "%" (match-string 2 s) "s"))
  6270. (when (equal var 'category)
  6271. (setq org-prefix-category-length
  6272. (floor (abs (string-to-number (match-string 2 s)))))
  6273. (setq org-prefix-category-max-length
  6274. (let ((x (match-string 2 s)))
  6275. (save-match-data
  6276. (if (string-match "\\.[0-9]+" x)
  6277. (string-to-number (substring (match-string 0 x) 1)))))))
  6278. (if (eq var 'eval)
  6279. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6280. (if opt
  6281. (setq varform
  6282. `(if (equal "" ,var)
  6283. ""
  6284. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6285. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6286. (setq s (replace-match "%s" t nil s))
  6287. (push varform vars))
  6288. (setq vars (nreverse vars))
  6289. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6290. (setq org-prefix-format-compiled
  6291. (list
  6292. `((org-prefix-has-time ,org-prefix-has-time)
  6293. (org-prefix-has-tag ,org-prefix-has-tag)
  6294. (org-prefix-category-length ,org-prefix-category-length)
  6295. (org-prefix-has-effort ,org-prefix-has-effort)
  6296. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6297. `(format ,s ,@vars))))))
  6298. (defun org-set-sorting-strategy (key)
  6299. (if (symbolp (car org-agenda-sorting-strategy))
  6300. ;; the old format
  6301. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6302. (setq org-agenda-sorting-strategy-selected
  6303. (or (cdr (assq key org-agenda-sorting-strategy))
  6304. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6305. '(time-up category-keep priority-down)))))
  6306. (defun org-get-time-of-day (s &optional string mod24)
  6307. "Check string S for a time of day.
  6308. If found, return it as a military time number between 0 and 2400.
  6309. If not found, return nil.
  6310. The optional STRING argument forces conversion into a 5 character wide string
  6311. HH:MM."
  6312. (save-match-data
  6313. (when
  6314. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6315. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6316. (let* ((h (string-to-number (match-string 1 s)))
  6317. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6318. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6319. (am-p (equal ampm "am"))
  6320. (h1 (cond ((not ampm) h)
  6321. ((= h 12) (if am-p 0 12))
  6322. (t (+ h (if am-p 0 12)))))
  6323. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6324. (mod h1 24) h1))
  6325. (t0 (+ (* 100 h2) m))
  6326. (t1 (concat (if (>= h1 24) "+" " ")
  6327. (if (and org-agenda-time-leading-zero
  6328. (< t0 1000)) "0" "")
  6329. (if (< t0 100) "0" "")
  6330. (if (< t0 10) "0" "")
  6331. (int-to-string t0))))
  6332. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6333. (defvar org-agenda-before-sorting-filter-function nil
  6334. "Function to be applied to agenda items prior to sorting.
  6335. Prior to sorting also means just before they are inserted into the agenda.
  6336. To aid sorting, you may revisit the original entries and add more text
  6337. properties which will later be used by the sorting functions.
  6338. The function should take a string argument, an agenda line.
  6339. It has access to the text properties in that line, which contain among
  6340. other things, the property `org-hd-marker' that points to the entry
  6341. where the line comes from. Note that not all lines going into the agenda
  6342. have this property, only most.
  6343. The function should return the modified string. It is probably best
  6344. to ONLY change text properties.
  6345. You can also use this function as a filter, by returning nil for lines
  6346. you don't want to have in the agenda at all. For this application, you
  6347. could bind the variable in the options section of a custom command.")
  6348. (defun org-agenda-finalize-entries (list &optional type)
  6349. "Sort, limit and concatenate the LIST of agenda items.
  6350. The optional argument TYPE tells the agenda type."
  6351. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6352. (cdr (assoc type org-agenda-max-effort)))
  6353. (t org-agenda-max-effort)))
  6354. (max-todo (cond ((listp org-agenda-max-todos)
  6355. (cdr (assoc type org-agenda-max-todos)))
  6356. (t org-agenda-max-todos)))
  6357. (max-tags (cond ((listp org-agenda-max-tags)
  6358. (cdr (assoc type org-agenda-max-tags)))
  6359. (t org-agenda-max-tags)))
  6360. (max-entries (cond ((listp org-agenda-max-entries)
  6361. (cdr (assoc type org-agenda-max-entries)))
  6362. (t org-agenda-max-entries))) l)
  6363. (when org-agenda-before-sorting-filter-function
  6364. (setq list
  6365. (delq nil
  6366. (mapcar
  6367. org-agenda-before-sorting-filter-function list))))
  6368. (setq list (mapcar 'org-agenda-highlight-todo list)
  6369. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6370. (when max-effort
  6371. (setq list (org-agenda-limit-entries
  6372. list 'effort-minutes max-effort 'identity)))
  6373. (when max-todo
  6374. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6375. (when max-tags
  6376. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6377. (when max-entries
  6378. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6379. (mapconcat 'identity list "\n")))
  6380. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6381. "Limit the number of agenda entries."
  6382. (let ((include (and limit (< limit 0))))
  6383. (if limit
  6384. (let ((fun (or fn (lambda (p) (if p 1))))
  6385. (lim 0))
  6386. (delq nil
  6387. (mapcar
  6388. (lambda (e)
  6389. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6390. (if pval (setq lim (+ lim pval)))
  6391. (cond ((and pval (<= lim (abs limit))) e)
  6392. ((and include (not pval)) e))))
  6393. list)))
  6394. list)))
  6395. (defun org-agenda-limit-interactively ()
  6396. "In agenda, interactively limit entries to various maximums."
  6397. (interactive)
  6398. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6399. (num (string-to-number (read-from-minibuffer "How many? "))))
  6400. (cond ((equal max ?e)
  6401. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6402. ((equal max ?t)
  6403. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6404. ((equal max ?T)
  6405. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6406. ((equal max ?E)
  6407. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6408. (org-agenda-fit-window-to-buffer))
  6409. (defun org-agenda-highlight-todo (x)
  6410. (let ((org-done-keywords org-done-keywords-for-agenda)
  6411. (case-fold-search nil)
  6412. re)
  6413. (if (eq x 'line)
  6414. (save-excursion
  6415. (beginning-of-line 1)
  6416. (setq re (org-get-at-bol 'org-todo-regexp))
  6417. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6418. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6419. (add-text-properties (match-beginning 0) (match-end 1)
  6420. (list 'face (org-get-todo-face 1)))
  6421. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6422. (delete-region (match-beginning 1) (1- (match-end 0)))
  6423. (goto-char (match-beginning 1))
  6424. (insert (format org-agenda-todo-keyword-format s)))))
  6425. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6426. (setq re (get-text-property 0 'org-todo-regexp x))
  6427. (when (and re
  6428. ;; Test `pl' because if there's no heading content,
  6429. ;; there's no point matching to highlight. Note
  6430. ;; that if we didn't test `pl' first, and there
  6431. ;; happened to be no keyword from `org-todo-regexp'
  6432. ;; on this heading line, then the `equal' comparison
  6433. ;; afterwards would spuriously succeed in the case
  6434. ;; where `pl' is nil -- causing an args-out-of-range
  6435. ;; error when we try to add text properties to text
  6436. ;; that isn't there.
  6437. pl
  6438. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6439. x pl) pl))
  6440. (add-text-properties
  6441. (or (match-end 1) (match-end 0)) (match-end 0)
  6442. (list 'face (org-get-todo-face (match-string 2 x)))
  6443. x)
  6444. (when (match-end 1)
  6445. (setq x (concat (substring x 0 (match-end 1))
  6446. (format org-agenda-todo-keyword-format
  6447. (match-string 2 x))
  6448. (org-add-props " " (text-properties-at 0 x))
  6449. (substring x (match-end 3)))))))
  6450. x)))
  6451. (defsubst org-cmp-priority (a b)
  6452. "Compare the priorities of string A and B."
  6453. (let ((pa (or (get-text-property 1 'priority a) 0))
  6454. (pb (or (get-text-property 1 'priority b) 0)))
  6455. (cond ((> pa pb) +1)
  6456. ((< pa pb) -1))))
  6457. (defsubst org-cmp-effort (a b)
  6458. "Compare the effort values of string A and B."
  6459. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6460. (ea (or (get-text-property 1 'effort-minutes a) def))
  6461. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6462. (cond ((> ea eb) +1)
  6463. ((< ea eb) -1))))
  6464. (defsubst org-cmp-category (a b)
  6465. "Compare the string values of categories of strings A and B."
  6466. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6467. (cb (or (get-text-property 1 'org-category b) "")))
  6468. (cond ((string-lessp ca cb) -1)
  6469. ((string-lessp cb ca) +1))))
  6470. (defsubst org-cmp-todo-state (a b)
  6471. "Compare the todo states of strings A and B."
  6472. (let* ((ma (or (get-text-property 1 'org-marker a)
  6473. (get-text-property 1 'org-hd-marker a)))
  6474. (mb (or (get-text-property 1 'org-marker b)
  6475. (get-text-property 1 'org-hd-marker b)))
  6476. (fa (and ma (marker-buffer ma)))
  6477. (fb (and mb (marker-buffer mb)))
  6478. (todo-kwds
  6479. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6480. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6481. (ta (or (get-text-property 1 'todo-state a) ""))
  6482. (tb (or (get-text-property 1 'todo-state b) ""))
  6483. (la (- (length (member ta todo-kwds))))
  6484. (lb (- (length (member tb todo-kwds))))
  6485. (donepa (member ta org-done-keywords-for-agenda))
  6486. (donepb (member tb org-done-keywords-for-agenda)))
  6487. (cond ((and donepa (not donepb)) -1)
  6488. ((and (not donepa) donepb) +1)
  6489. ((< la lb) -1)
  6490. ((< lb la) +1))))
  6491. (defsubst org-cmp-alpha (a b)
  6492. "Compare the headlines, alphabetically."
  6493. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6494. (plb (text-property-any 0 (length b) 'org-heading t b))
  6495. (ta (and pla (substring a pla)))
  6496. (tb (and plb (substring b plb))))
  6497. (when pla
  6498. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6499. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6500. (setq ta (substring ta (match-end 0))))
  6501. (setq ta (downcase ta)))
  6502. (when plb
  6503. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6504. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6505. (setq tb (substring tb (match-end 0))))
  6506. (setq tb (downcase tb)))
  6507. (cond ((not ta) +1)
  6508. ((not tb) -1)
  6509. ((string-lessp ta tb) -1)
  6510. ((string-lessp tb ta) +1))))
  6511. (defsubst org-cmp-tag (a b)
  6512. "Compare the string values of the first tags of A and B."
  6513. (let ((ta (car (last (get-text-property 1 'tags a))))
  6514. (tb (car (last (get-text-property 1 'tags b)))))
  6515. (cond ((not ta) +1)
  6516. ((not tb) -1)
  6517. ((string-lessp ta tb) -1)
  6518. ((string-lessp tb ta) +1))))
  6519. (defsubst org-cmp-time (a b)
  6520. "Compare the time-of-day values of strings A and B."
  6521. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6522. (ta (or (get-text-property 1 'time-of-day a) def))
  6523. (tb (or (get-text-property 1 'time-of-day b) def)))
  6524. (cond ((< ta tb) -1)
  6525. ((< tb ta) +1))))
  6526. (defsubst org-cmp-ts (a b &optional type)
  6527. "Compare the timestamps values of entries A and B.
  6528. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6529. \"timestamp_ia\", compare within each of these type. When TYPE
  6530. is the empty string, compare all timestamps without respect of
  6531. their type."
  6532. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6533. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6534. (get-text-property 1 'ts-date a)) def))
  6535. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6536. (get-text-property 1 'ts-date b)) def)))
  6537. (cond ((< ta tb) -1)
  6538. ((< tb ta) +1))))
  6539. (defsubst org-cmp-habit-p (a b)
  6540. "Compare the todo states of strings A and B."
  6541. (let ((ha (get-text-property 1 'org-habit-p a))
  6542. (hb (get-text-property 1 'org-habit-p b)))
  6543. (cond ((and ha (not hb)) -1)
  6544. ((and (not ha) hb) +1))))
  6545. (defun org-entries-lessp (a b)
  6546. "Predicate for sorting agenda entries."
  6547. ;; The following variables will be used when the form is evaluated.
  6548. ;; So even though the compiler complains, keep them.
  6549. (let* ((ss org-agenda-sorting-strategy-selected)
  6550. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6551. (org-cmp-ts a b "")))
  6552. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6553. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6554. (org-cmp-ts a b "scheduled")))
  6555. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6556. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6557. (org-cmp-ts a b "deadline")))
  6558. (deadline-down (if deadline-up (- deadline-up) nil))
  6559. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6560. (org-cmp-ts a b "iatimestamp_ia")))
  6561. (tsia-down (if tsia-up (- tsia-up) nil))
  6562. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6563. (org-cmp-ts a b "timestamp")))
  6564. (ts-down (if ts-up (- ts-up) nil))
  6565. (time-up (and (org-em 'time-up 'time-down ss)
  6566. (org-cmp-time a b)))
  6567. (time-down (if time-up (- time-up) nil))
  6568. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6569. (org-cmp-priority a b)))
  6570. (priority-down (if priority-up (- priority-up) nil))
  6571. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6572. (org-cmp-effort a b)))
  6573. (effort-down (if effort-up (- effort-up) nil))
  6574. (category-up (and (or (org-em 'category-up 'category-down ss)
  6575. (memq 'category-keep ss))
  6576. (org-cmp-category a b)))
  6577. (category-down (if category-up (- category-up) nil))
  6578. (category-keep (if category-up +1 nil))
  6579. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6580. (org-cmp-tag a b)))
  6581. (tag-down (if tag-up (- tag-up) nil))
  6582. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6583. (org-cmp-todo-state a b)))
  6584. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6585. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6586. (org-cmp-habit-p a b)))
  6587. (habit-down (if habit-up (- habit-up) nil))
  6588. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6589. (org-cmp-alpha a b)))
  6590. (alpha-down (if alpha-up (- alpha-up) nil))
  6591. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6592. user-defined-up user-defined-down)
  6593. (if (and need-user-cmp org-agenda-cmp-user-defined
  6594. (functionp org-agenda-cmp-user-defined))
  6595. (setq user-defined-up
  6596. (funcall org-agenda-cmp-user-defined a b)
  6597. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6598. (cdr (assoc
  6599. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6600. '((-1 . t) (1 . nil) (nil . nil))))))
  6601. ;;; Agenda restriction lock
  6602. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6603. "Overlay to mark the headline to which agenda commands are restricted.")
  6604. (overlay-put org-agenda-restriction-lock-overlay
  6605. 'face 'org-agenda-restriction-lock)
  6606. (overlay-put org-agenda-restriction-lock-overlay
  6607. 'help-echo "Agendas are currently limited to this subtree.")
  6608. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6609. ;;;###autoload
  6610. (defun org-agenda-set-restriction-lock (&optional type)
  6611. "Set restriction lock for agenda, to current subtree or file.
  6612. Restriction will be the file if TYPE is `file', or if type is the
  6613. universal prefix '(4), or if the cursor is before the first headline
  6614. in the file. Otherwise, restriction will be to the current subtree."
  6615. (interactive "P")
  6616. (and (equal type '(4)) (setq type 'file))
  6617. (setq type (cond
  6618. (type type)
  6619. ((org-at-heading-p) 'subtree)
  6620. ((condition-case nil (org-back-to-heading t) (error nil))
  6621. 'subtree)
  6622. (t 'file)))
  6623. (if (eq type 'subtree)
  6624. (progn
  6625. (setq org-agenda-restrict (current-buffer))
  6626. (setq org-agenda-overriding-restriction 'subtree)
  6627. (put 'org-agenda-files 'org-restrict
  6628. (list (buffer-file-name (buffer-base-buffer))))
  6629. (org-back-to-heading t)
  6630. (move-overlay org-agenda-restriction-lock-overlay
  6631. (point)
  6632. (if org-agenda-restriction-lock-highlight-subtree
  6633. (save-excursion (org-end-of-subtree t t) (point))
  6634. (point-at-eol)))
  6635. (move-marker org-agenda-restrict-begin (point))
  6636. (move-marker org-agenda-restrict-end
  6637. (save-excursion (org-end-of-subtree t t)))
  6638. (message "Locking agenda restriction to subtree"))
  6639. (put 'org-agenda-files 'org-restrict
  6640. (list (buffer-file-name (buffer-base-buffer))))
  6641. (setq org-agenda-restrict nil)
  6642. (setq org-agenda-overriding-restriction 'file)
  6643. (move-marker org-agenda-restrict-begin nil)
  6644. (move-marker org-agenda-restrict-end nil)
  6645. (message "Locking agenda restriction to file"))
  6646. (setq current-prefix-arg nil)
  6647. (org-agenda-maybe-redo))
  6648. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6649. "Remove the agenda restriction lock."
  6650. (interactive "P")
  6651. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6652. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6653. (setq org-agenda-overriding-restriction nil)
  6654. (setq org-agenda-restrict nil)
  6655. (put 'org-agenda-files 'org-restrict nil)
  6656. (move-marker org-agenda-restrict-begin nil)
  6657. (move-marker org-agenda-restrict-end nil)
  6658. (setq current-prefix-arg nil)
  6659. (message "Agenda restriction lock removed")
  6660. (or noupdate (org-agenda-maybe-redo)))
  6661. (defun org-agenda-maybe-redo ()
  6662. "If there is any window showing the agenda view, update it."
  6663. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6664. (w0 (selected-window)))
  6665. (when w
  6666. (select-window w)
  6667. (org-agenda-redo)
  6668. (select-window w0)
  6669. (if org-agenda-overriding-restriction
  6670. (message "Agenda view shifted to new %s restriction"
  6671. org-agenda-overriding-restriction)
  6672. (message "Agenda restriction lock removed")))))
  6673. ;;; Agenda commands
  6674. (defun org-agenda-check-type (error &rest types)
  6675. "Check if agenda buffer is of allowed type.
  6676. If ERROR is non-nil, throw an error, otherwise just return nil.
  6677. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6678. (if (not org-agenda-type)
  6679. (error "No Org agenda currently displayed")
  6680. (if (memq org-agenda-type types)
  6681. t
  6682. (if error
  6683. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6684. nil))))
  6685. (defun org-agenda-Quit ()
  6686. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6687. Also restore the window configuration."
  6688. (interactive)
  6689. (if org-agenda-columns-active
  6690. (org-columns-quit)
  6691. (let ((buf (current-buffer)))
  6692. (if (eq org-agenda-window-setup 'other-frame)
  6693. (progn
  6694. (org-agenda-reset-markers)
  6695. (kill-buffer buf)
  6696. (org-columns-remove-overlays)
  6697. (setq org-agenda-archives-mode nil)
  6698. (delete-frame))
  6699. (and (not (eq org-agenda-window-setup 'current-window))
  6700. (not (one-window-p))
  6701. (delete-window))
  6702. (org-agenda-reset-markers)
  6703. (kill-buffer buf)
  6704. (org-columns-remove-overlays)
  6705. (setq org-agenda-archives-mode nil)))
  6706. (setq org-agenda-buffer nil)
  6707. ;; Maybe restore the pre-agenda window configuration.
  6708. (and org-agenda-restore-windows-after-quit
  6709. (not (eq org-agenda-window-setup 'other-frame))
  6710. org-agenda-pre-window-conf
  6711. (set-window-configuration org-agenda-pre-window-conf)
  6712. (setq org-agenda-pre-window-conf nil))))
  6713. (defun org-agenda-quit ()
  6714. "Exit the agenda and restore the window configuration.
  6715. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6716. (interactive)
  6717. (if (and (eq org-indirect-buffer-display 'other-window)
  6718. org-last-indirect-buffer)
  6719. (let ((org-last-indirect-window
  6720. (get-buffer-window org-last-indirect-buffer)))
  6721. (if org-last-indirect-window
  6722. (delete-window org-last-indirect-window))))
  6723. (if org-agenda-columns-active
  6724. (org-columns-quit)
  6725. (if org-agenda-sticky
  6726. (let ((buf (current-buffer)))
  6727. (if (eq org-agenda-window-setup 'other-frame)
  6728. (progn
  6729. (delete-frame))
  6730. (and (not (eq org-agenda-window-setup 'current-window))
  6731. (not (one-window-p))
  6732. (delete-window)))
  6733. (with-current-buffer buf
  6734. (bury-buffer)
  6735. ;; Maybe restore the pre-agenda window configuration.
  6736. (and org-agenda-restore-windows-after-quit
  6737. (not (eq org-agenda-window-setup 'other-frame))
  6738. org-agenda-pre-window-conf
  6739. (set-window-configuration org-agenda-pre-window-conf)
  6740. (setq org-agenda-pre-window-conf nil))))
  6741. (org-agenda-Quit))))
  6742. (defun org-agenda-exit ()
  6743. "Exit the agenda and restore the window configuration.
  6744. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6745. buffers visited directly by the user will not be touched."
  6746. (interactive)
  6747. (org-release-buffers org-agenda-new-buffers)
  6748. (setq org-agenda-new-buffers nil)
  6749. (org-agenda-Quit))
  6750. (defun org-agenda-kill-all-agenda-buffers ()
  6751. "Kill all buffers in `org-agenda-mode'.
  6752. This is used when toggling sticky agendas.
  6753. You can also explicitly invoke it with `C-c a C-k'."
  6754. (interactive)
  6755. (let (blist)
  6756. (dolist (buf (buffer-list))
  6757. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6758. (push buf blist)))
  6759. (mapc 'kill-buffer blist)))
  6760. (defun org-agenda-execute (arg)
  6761. "Execute another agenda command, keeping same window.
  6762. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6763. in the agenda."
  6764. (interactive "P")
  6765. (let ((org-agenda-window-setup 'current-window))
  6766. (org-agenda arg)))
  6767. (defun org-agenda-redo (&optional all)
  6768. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6769. (interactive "P")
  6770. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6771. (cpa (unless (eq all t) current-prefix-arg))
  6772. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6773. (org-agenda-sticky nil)
  6774. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6775. org-agenda-buffer-name))
  6776. (org-agenda-keep-modes t)
  6777. (tag-filter org-agenda-tag-filter)
  6778. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6779. (top-hl-filter org-agenda-top-headline-filter)
  6780. (cat-filter org-agenda-category-filter)
  6781. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6782. (re-filter org-agenda-regexp-filter)
  6783. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6784. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6785. (cols org-agenda-columns-active)
  6786. (line (org-current-line))
  6787. (window-line (- line (org-current-line (window-start))))
  6788. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6789. (redo-cmd (get-text-property p 'org-redo-cmd))
  6790. (last-args (get-text-property p 'org-last-args))
  6791. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6792. (org-agenda-overriding-cmd-arguments
  6793. (unless (eq all t)
  6794. (cond ((listp last-args)
  6795. (cons (or cpa (car last-args)) (cdr last-args)))
  6796. ((stringp last-args)
  6797. last-args))))
  6798. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6799. (put 'org-agenda-tag-filter :preset-filter nil)
  6800. (put 'org-agenda-category-filter :preset-filter nil)
  6801. (put 'org-agenda-regexp-filter :preset-filter nil)
  6802. (and cols (org-columns-quit))
  6803. (message "Rebuilding agenda buffer...")
  6804. (if series-redo-cmd
  6805. (eval series-redo-cmd)
  6806. (org-let lprops redo-cmd))
  6807. (setq org-agenda-undo-list nil
  6808. org-agenda-pending-undo-list nil
  6809. org-agenda-tag-filter tag-filter
  6810. org-agenda-category-filter cat-filter
  6811. org-agenda-regexp-filter re-filter
  6812. org-agenda-top-headline-filter top-hl-filter)
  6813. (message "Rebuilding agenda buffer...done")
  6814. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6815. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6816. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6817. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6818. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6819. (and (or re-filter re-preset) (org-agenda-filter-apply re-filter 'regexp))
  6820. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6821. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6822. (org-goto-line line)
  6823. (recenter window-line)))
  6824. (defvar org-global-tags-completion-table nil)
  6825. (defvar org-agenda-filter-form nil)
  6826. (defvar org-agenda-filtered-by-category nil)
  6827. (defun org-agenda-filter-by-category (strip)
  6828. "Keep only those lines in the agenda buffer that have a specific category.
  6829. The category is that of the current line."
  6830. (interactive "P")
  6831. (if (and org-agenda-filtered-by-category
  6832. org-agenda-category-filter)
  6833. (org-agenda-filter-show-all-cat)
  6834. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6835. (cond
  6836. ((and cat strip)
  6837. (org-agenda-filter-apply
  6838. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6839. ((and cat)
  6840. (org-agenda-filter-apply
  6841. (setq org-agenda-category-filter
  6842. (list (concat "+" cat))) 'category))
  6843. ((error "No category at point"))))))
  6844. (defun org-find-top-headline (&optional pos)
  6845. "Find the topmost parent headline and return it."
  6846. (save-excursion
  6847. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6848. (if pos (goto-char pos))
  6849. ;; Skip up to the topmost parent
  6850. (while (ignore-errors (outline-up-heading 1) t))
  6851. (ignore-errors
  6852. (nth 4 (org-heading-components))))))
  6853. (defvar org-agenda-filtered-by-top-headline nil)
  6854. (defun org-agenda-filter-by-top-headline (strip)
  6855. "Keep only those lines that are descendants from the same top headline.
  6856. The top headline is that of the current line."
  6857. (interactive "P")
  6858. (if org-agenda-filtered-by-top-headline
  6859. (progn
  6860. (setq org-agenda-filtered-by-top-headline nil
  6861. org-agenda-top-headline-filter nil)
  6862. (org-agenda-filter-show-all-cat))
  6863. (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6864. (if cat (org-agenda-filter-top-headline-apply cat strip)
  6865. (error "No top-level category at point")))))
  6866. (defvar org-agenda-regexp-filter nil)
  6867. (defun org-agenda-filter-by-regexp (strip)
  6868. "Filter agenda entries by a regular expression.
  6869. Regexp filters are cumulative.
  6870. With no prefix argument, keep entries matching the regexp.
  6871. With one prefix argument, filter out entries matching the regexp.
  6872. With two prefix arguments, remove the regexp filters."
  6873. (interactive "P")
  6874. (if (not (equal strip '(16)))
  6875. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6876. (read-from-minibuffer
  6877. (if (equal strip '(4))
  6878. "Filter out entries matching regexp: "
  6879. "Narrow to entries matching regexp: ")))))
  6880. (push flt org-agenda-regexp-filter)
  6881. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6882. (org-agenda-filter-show-all-re)
  6883. (message "Regexp filter removed")))
  6884. (defun org-agenda-filter-remove-all ()
  6885. "Remove all filters from the current agenda buffer."
  6886. (interactive)
  6887. (when org-agenda-tag-filter
  6888. (org-agenda-filter-show-all-tag))
  6889. (when org-agenda-category-filter
  6890. (org-agenda-filter-show-all-cat))
  6891. (when org-agenda-regexp-filter
  6892. (org-agenda-filter-show-all-re)))
  6893. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6894. "Keep only those lines in the agenda buffer that have a specific tag.
  6895. The tag is selected with its fast selection letter, as configured.
  6896. With prefix argument STRIP, remove all lines that do have the tag.
  6897. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6898. used to narrow the search - the interactive user can also press `-' or `+'
  6899. to switch to narrowing."
  6900. (interactive "P")
  6901. (let* ((alist org-tag-alist-for-agenda)
  6902. (tag-chars (mapconcat
  6903. (lambda (x) (if (and (not (symbolp (car x)))
  6904. (cdr x))
  6905. (char-to-string (cdr x))
  6906. ""))
  6907. alist ""))
  6908. (efforts (org-split-string
  6909. (or (cdr (assoc (concat org-effort-property "_ALL")
  6910. org-global-properties))
  6911. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6912. "")))
  6913. (effort-op org-agenda-filter-effort-default-operator)
  6914. (effort-prompt "")
  6915. (inhibit-read-only t)
  6916. (current org-agenda-tag-filter)
  6917. maybe-refresh a n tag)
  6918. (unless char
  6919. (message
  6920. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6921. (if narrow "Narrow" "Filter") tag-chars
  6922. (if org-agenda-auto-exclude-function "[RET], " ""))
  6923. (setq char (read-char-exclusive)))
  6924. (when (member char '(?+ ?-))
  6925. ;; Narrowing down
  6926. (cond ((equal char ?-) (setq strip t narrow t))
  6927. ((equal char ?+) (setq strip nil narrow t)))
  6928. (message
  6929. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6930. (setq char (read-char-exclusive)))
  6931. (when (member char '(?< ?> ?= ??))
  6932. ;; An effort operator
  6933. (setq effort-op (char-to-string char))
  6934. (setq alist nil) ; to make sure it will be interpreted as effort.
  6935. (unless (equal char ??)
  6936. (loop for i from 0 to 9 do
  6937. (setq effort-prompt
  6938. (concat
  6939. effort-prompt " ["
  6940. (if (= i 9) "0" (int-to-string (1+ i)))
  6941. "]" (nth i efforts))))
  6942. (message "Effort%s: %s " effort-op effort-prompt)
  6943. (setq char (read-char-exclusive))
  6944. (when (or (< char ?0) (> char ?9))
  6945. (error "Need 1-9,0 to select effort"))))
  6946. (when (equal char ?\t)
  6947. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6948. (org-set-local 'org-global-tags-completion-table
  6949. (org-global-tags-completion-table)))
  6950. (let ((completion-ignore-case t))
  6951. (setq tag (org-icompleting-read
  6952. "Tag: " org-global-tags-completion-table))))
  6953. (cond
  6954. ((equal char ?\r)
  6955. (org-agenda-filter-show-all-tag)
  6956. (when org-agenda-auto-exclude-function
  6957. (setq org-agenda-tag-filter nil)
  6958. (dolist (tag (org-agenda-get-represented-tags))
  6959. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6960. (if modifier
  6961. (push modifier org-agenda-tag-filter))))
  6962. (if (not (null org-agenda-tag-filter))
  6963. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6964. (setq maybe-refresh t))
  6965. ((equal char ?/)
  6966. (org-agenda-filter-show-all-tag)
  6967. (when (get 'org-agenda-tag-filter :preset-filter)
  6968. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6969. (setq maybe-refresh t))
  6970. ((equal char ?. )
  6971. (setq org-agenda-tag-filter
  6972. (mapcar (lambda(tag) (concat "+" tag))
  6973. (org-get-at-bol 'tags)))
  6974. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6975. (setq maybe-refresh t))
  6976. ((or (equal char ?\ )
  6977. (setq a (rassoc char alist))
  6978. (and (>= char ?0) (<= char ?9)
  6979. (setq n (if (= char ?0) 9 (- char ?0 1))
  6980. tag (concat effort-op (nth n efforts))
  6981. a (cons tag nil)))
  6982. (and (= char ??)
  6983. (setq tag "?eff")
  6984. a (cons tag nil))
  6985. (and tag (setq a (cons tag nil))))
  6986. (org-agenda-filter-show-all-tag)
  6987. (setq tag (car a))
  6988. (setq org-agenda-tag-filter
  6989. (cons (concat (if strip "-" "+") tag)
  6990. (if narrow current nil)))
  6991. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6992. (setq maybe-refresh t))
  6993. (t (error "Invalid tag selection character %c" char)))
  6994. (when (and maybe-refresh
  6995. (eq org-agenda-clockreport-mode 'with-filter))
  6996. (org-agenda-redo))))
  6997. (defun org-agenda-get-represented-tags ()
  6998. "Get a list of all tags currently represented in the agenda."
  6999. (let (p tags)
  7000. (save-excursion
  7001. (goto-char (point-min))
  7002. (while (setq p (next-single-property-change (point) 'tags))
  7003. (goto-char p)
  7004. (mapc (lambda (x) (add-to-list 'tags x))
  7005. (get-text-property (point) 'tags))))
  7006. tags))
  7007. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  7008. "Refine the current filter. See `org-agenda-filter-by-tag'."
  7009. (interactive "P")
  7010. (org-agenda-filter-by-tag strip char 'refine))
  7011. (defun org-agenda-filter-make-matcher (filter type)
  7012. "Create the form that tests a line for agenda filter."
  7013. (let (f f1)
  7014. (cond
  7015. ;; Tag filter
  7016. ((eq type 'tag)
  7017. (setq filter
  7018. (delete-dups
  7019. (append (get 'org-agenda-tag-filter :preset-filter)
  7020. filter)))
  7021. (dolist (x filter)
  7022. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  7023. (ffunc
  7024. (lambda (nf0 nf01 fltr notgroup op)
  7025. (dolist (x fltr)
  7026. (if (member x '("-" "+"))
  7027. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  7028. (if (string-match "[<=>?]" x)
  7029. (setq nf01 (org-agenda-filter-effort-form x))
  7030. (setq nf01 (list 'member (downcase (substring x 1))
  7031. 'tags)))
  7032. (when (equal (string-to-char x) ?-)
  7033. (setq nf01 (list 'not nf01))
  7034. (when (not notgroup) (setq op 'and))))
  7035. (push nf01 nf0))
  7036. (if notgroup
  7037. (push (cons 'and nf0) f)
  7038. (push (cons (or op 'or) nf0) f)))))
  7039. (cond ((equal filter '("+"))
  7040. (setq f (list (list 'not 'tags))))
  7041. ((equal nfilter filter)
  7042. (funcall ffunc f1 f filter t nil))
  7043. (t (funcall ffunc nf1 nf nfilter nil nil))))))
  7044. ;; Category filter
  7045. ((eq type 'category)
  7046. (setq filter
  7047. (delete-dups
  7048. (append (get 'org-agenda-category-filter :preset-filter)
  7049. filter)))
  7050. (dolist (x filter)
  7051. (if (equal "-" (substring x 0 1))
  7052. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7053. (setq f1 (list 'equal (substring x 1) 'cat)))
  7054. (push f1 f)))
  7055. ;; Regexp filter
  7056. ((eq type 'regexp)
  7057. (setq filter
  7058. (delete-dups
  7059. (append (get 'org-agenda-regexp-filter :preset-filter)
  7060. filter)))
  7061. (dolist (x filter)
  7062. (if (equal "-" (substring x 0 1))
  7063. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7064. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7065. (push f1 f))))
  7066. (cons 'and (nreverse f))))
  7067. (defun org-agenda-filter-effort-form (e)
  7068. "Return the form to compare the effort of the current line with what E says.
  7069. E looks like \"+<2:25\"."
  7070. (let (op)
  7071. (setq e (substring e 1))
  7072. (setq op (string-to-char e) e (substring e 1))
  7073. (setq op (cond ((equal op ?<) '<=)
  7074. ((equal op ?>) '>=)
  7075. ((equal op ??) op)
  7076. (t '=)))
  7077. (list 'org-agenda-compare-effort (list 'quote op)
  7078. (org-duration-string-to-minutes e))))
  7079. (defun org-agenda-compare-effort (op value)
  7080. "Compare the effort of the current line with VALUE, using OP.
  7081. If the line does not have an effort defined, return nil."
  7082. (let ((eff (org-get-at-bol 'effort-minutes)))
  7083. (if (equal op ??)
  7084. (not eff)
  7085. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7086. value))))
  7087. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7088. "Expand group tags in FILTER for the agenda.
  7089. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7090. (if org-group-tags
  7091. (let ((case-fold-search t) rtn)
  7092. (mapc
  7093. (lambda (f)
  7094. (let (f0 dir)
  7095. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7096. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7097. (setq dir (if no-operator "" "+") f0 f))
  7098. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7099. (org-tags-expand f0 t t))
  7100. rtn))))
  7101. filter)
  7102. (reverse rtn))
  7103. filter))
  7104. (defun org-agenda-filter-apply (filter type)
  7105. "Set FILTER as the new agenda filter and apply it."
  7106. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7107. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7108. (let (tags cat txt)
  7109. (setq org-agenda-filter-form
  7110. (org-agenda-filter-make-matcher filter type))
  7111. (if (and (eq type 'category)
  7112. (not (equal (substring (car filter) 0 1) "-")))
  7113. ;; Only set `org-agenda-filtered-by-category' to t
  7114. ;; when a unique category is used as the filter
  7115. (setq org-agenda-filtered-by-category t))
  7116. (org-agenda-set-mode-name)
  7117. (save-excursion
  7118. (goto-char (point-min))
  7119. (while (not (eobp))
  7120. (if (org-get-at-bol 'org-marker)
  7121. (progn
  7122. (setq tags ; used in eval
  7123. (apply 'append
  7124. (mapcar (lambda (f)
  7125. (org-agenda-filter-expand-tags (list f) t))
  7126. (org-get-at-bol 'tags)))
  7127. cat (get-text-property (point) 'org-category)
  7128. txt (get-text-property (point) 'txt))
  7129. (if (not (eval org-agenda-filter-form))
  7130. (org-agenda-filter-hide-line type))
  7131. (beginning-of-line 2))
  7132. (beginning-of-line 2))))
  7133. (if (get-char-property (point) 'invisible)
  7134. (ignore-errors (org-agenda-previous-line)))))
  7135. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7136. "Filter by top headline HL."
  7137. (org-agenda-set-mode-name)
  7138. (save-excursion
  7139. (goto-char (point-min))
  7140. (while (not (eobp))
  7141. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7142. (tophl (and pos (org-find-top-headline pos))))
  7143. (if (and tophl (funcall (if negative 'identity 'not)
  7144. (string= hl tophl)))
  7145. (org-agenda-filter-hide-line 'category)))
  7146. (beginning-of-line 2)))
  7147. (if (get-char-property (point) 'invisible)
  7148. (org-agenda-previous-line))
  7149. (setq org-agenda-top-headline-filter hl
  7150. org-agenda-filtered-by-top-headline t))
  7151. (defun org-agenda-filter-hide-line (type)
  7152. "Hide lines with TYPE in the agenda buffer."
  7153. (let* ((b (max (point-min) (1- (point-at-bol))))
  7154. (e (point-at-eol))
  7155. (ov (make-overlay b e)))
  7156. (overlay-put ov 'invisible t)
  7157. (overlay-put ov 'intangible t)
  7158. (overlay-put ov 'type type)
  7159. (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays))
  7160. ((eq type 'category) (push ov org-agenda-cat-filter-overlays))
  7161. ((eq type 'regexp) (push ov org-agenda-re-filter-overlays)))))
  7162. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  7163. (setq pos (or pos (point)))
  7164. (save-excursion
  7165. (dolist (ov (overlays-at pos))
  7166. (when (and (overlay-get ov 'invisible)
  7167. (eq (overlay-get ov 'type) 'tag))
  7168. (goto-char pos)
  7169. (if (< (overlay-start ov) (point-at-eol))
  7170. (move-overlay ov (point-at-eol)
  7171. (overlay-end ov)))))))
  7172. (defun org-agenda-filter-show-all-tag nil
  7173. "Remove tag filter overlays from the agenda buffer."
  7174. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  7175. (setq org-agenda-tag-filter-overlays nil
  7176. org-agenda-tag-filter nil
  7177. org-agenda-filter-form nil)
  7178. (org-agenda-set-mode-name))
  7179. (defun org-agenda-filter-show-all-re nil
  7180. "Remove regexp filter overlays from the agenda buffer."
  7181. (mapc 'delete-overlay org-agenda-re-filter-overlays)
  7182. (setq org-agenda-re-filter-overlays nil
  7183. org-agenda-regexp-filter nil
  7184. org-agenda-filter-form nil)
  7185. (org-agenda-set-mode-name))
  7186. (defun org-agenda-filter-show-all-cat nil
  7187. "Remove category filter overlays from the agenda buffer."
  7188. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  7189. (setq org-agenda-cat-filter-overlays nil
  7190. org-agenda-filtered-by-category nil
  7191. org-agenda-category-filter nil
  7192. org-agenda-filter-form nil)
  7193. (org-agenda-set-mode-name))
  7194. (defun org-agenda-manipulate-query-add ()
  7195. "Manipulate the query by adding a search term with positive selection.
  7196. Positive selection means the term must be matched for selection of an entry."
  7197. (interactive)
  7198. (org-agenda-manipulate-query ?\[))
  7199. (defun org-agenda-manipulate-query-subtract ()
  7200. "Manipulate the query by adding a search term with negative selection.
  7201. Negative selection means term must not be matched for selection of an entry."
  7202. (interactive)
  7203. (org-agenda-manipulate-query ?\]))
  7204. (defun org-agenda-manipulate-query-add-re ()
  7205. "Manipulate the query by adding a search regexp with positive selection.
  7206. Positive selection means the regexp must match for selection of an entry."
  7207. (interactive)
  7208. (org-agenda-manipulate-query ?\{))
  7209. (defun org-agenda-manipulate-query-subtract-re ()
  7210. "Manipulate the query by adding a search regexp with negative selection.
  7211. Negative selection means regexp must not match for selection of an entry."
  7212. (interactive)
  7213. (org-agenda-manipulate-query ?\}))
  7214. (defun org-agenda-manipulate-query (char)
  7215. (cond
  7216. ((memq org-agenda-type '(timeline agenda))
  7217. (let ((org-agenda-include-inactive-timestamps t))
  7218. (org-agenda-redo))
  7219. (message "Display now includes inactive timestamps as well"))
  7220. ((eq org-agenda-type 'search)
  7221. (org-add-to-string
  7222. 'org-agenda-query-string
  7223. (if org-agenda-last-search-view-search-was-boolean
  7224. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7225. (?\{ . " +{}") (?\} . " -{}"))))
  7226. " "))
  7227. (setq org-agenda-redo-command
  7228. (list 'org-search-view
  7229. (car (get-text-property (min (1- (point-max)) (point))
  7230. 'org-last-args))
  7231. org-agenda-query-string
  7232. (+ (length org-agenda-query-string)
  7233. (if (member char '(?\{ ?\})) 0 1))))
  7234. (set-register org-agenda-query-register org-agenda-query-string)
  7235. (let ((org-agenda-overriding-arguments
  7236. (cdr org-agenda-redo-command)))
  7237. (org-agenda-redo)))
  7238. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7239. org-agenda-type))))
  7240. (defun org-add-to-string (var string)
  7241. (set var (concat (symbol-value var) string)))
  7242. (defun org-agenda-goto-date (span)
  7243. "Jump to DATE in agenda."
  7244. (interactive "P")
  7245. (let* ((org-read-date-prefer-future
  7246. (eval org-agenda-jump-prefer-future))
  7247. (date (org-read-date))
  7248. (day (time-to-days (org-time-string-to-time date)))
  7249. (org-agenda-sticky-orig org-agenda-sticky)
  7250. (org-agenda-buffer-tmp-name (buffer-name))
  7251. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7252. (0-arg (or current-prefix-arg (car args)))
  7253. (2-arg (nth 2 args))
  7254. (with-hour-p (nth 4 org-agenda-redo-command))
  7255. (newcmd (list 'org-agenda-list 0-arg date
  7256. (org-agenda-span-to-ndays
  7257. 2-arg (org-time-string-to-absolute date))
  7258. with-hour-p))
  7259. (newargs (cdr newcmd))
  7260. (inhibit-read-only t)
  7261. org-agenda-sticky)
  7262. (if (not (org-agenda-check-type t 'agenda))
  7263. (error "Not available in non-agenda views")
  7264. (add-text-properties (point-min) (point-max)
  7265. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7266. (org-agenda-redo)
  7267. (goto-char (point-min))
  7268. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7269. (save-excursion (move-beginning-of-line 2) (eobp))))
  7270. (move-beginning-of-line 2))
  7271. (setq org-agenda-sticky org-agenda-sticky-orig
  7272. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7273. (defun org-agenda-goto-today ()
  7274. "Go to today."
  7275. (interactive)
  7276. (org-agenda-check-type t 'timeline 'agenda)
  7277. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7278. (curspan (nth 2 args))
  7279. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7280. (cond
  7281. (tdpos (goto-char tdpos))
  7282. ((eq org-agenda-type 'agenda)
  7283. (let* ((sd (org-agenda-compute-starting-span
  7284. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7285. (org-agenda-overriding-arguments args))
  7286. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7287. (org-agenda-redo)
  7288. (org-agenda-find-same-or-today-or-agenda)))
  7289. (t (error "Cannot find today")))))
  7290. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7291. (goto-char
  7292. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7293. (text-property-any (point-min) (point-max) 'org-today t)
  7294. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7295. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7296. (org-agenda-goto-block-beginning))
  7297. (point-min))))
  7298. (defun org-agenda-goto-block-beginning ()
  7299. "Go the agenda block beginning."
  7300. (interactive)
  7301. (if (not (derived-mode-p 'org-agenda-mode))
  7302. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7303. (let (dest)
  7304. (save-excursion
  7305. (unless (looking-at "\\'")
  7306. (forward-char))
  7307. (let* ((prop 'org-agenda-structural-header)
  7308. (p (previous-single-property-change (point) prop))
  7309. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7310. (1- (point))) prop)))
  7311. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7312. (if (not dest)
  7313. (error "Cannot find the beginning of the blog")
  7314. (goto-char dest)
  7315. (move-beginning-of-line 1)))))
  7316. (defun org-agenda-later (arg)
  7317. "Go forward in time by the current span.
  7318. With prefix ARG, go forward that many times the current span."
  7319. (interactive "p")
  7320. (org-agenda-check-type t 'agenda)
  7321. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7322. (span (or (nth 2 args) org-agenda-current-span))
  7323. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7324. (greg (calendar-gregorian-from-absolute sd))
  7325. (cnt (org-get-at-bol 'org-day-cnt))
  7326. greg2)
  7327. (cond
  7328. ((numberp span)
  7329. (setq sd (+ (* span arg) sd)))
  7330. ((eq span 'day)
  7331. (setq sd (+ arg sd)))
  7332. ((eq span 'week)
  7333. (setq sd (+ (* 7 arg) sd)))
  7334. ((eq span 'fortnight)
  7335. (setq sd (+ (* 14 arg) sd)))
  7336. ((eq span 'month)
  7337. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7338. sd (calendar-absolute-from-gregorian greg2))
  7339. (setcar greg2 (1+ (car greg2))))
  7340. ((eq span 'year)
  7341. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7342. sd (calendar-absolute-from-gregorian greg2))
  7343. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7344. (t
  7345. (setq sd (+ (* span arg) sd))))
  7346. (let ((org-agenda-overriding-cmd
  7347. ;; `cmd' may have been set by `org-agenda-run-series' which
  7348. ;; uses `org-agenda-overriding-cmd' to decide whether
  7349. ;; overriding is allowed for `cmd'
  7350. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7351. (org-agenda-overriding-arguments
  7352. (list (car args) sd span)))
  7353. (org-agenda-redo)
  7354. (org-agenda-find-same-or-today-or-agenda cnt))))
  7355. (defun org-agenda-earlier (arg)
  7356. "Go backward in time by the current span.
  7357. With prefix ARG, go backward that many times the current span."
  7358. (interactive "p")
  7359. (org-agenda-later (- arg)))
  7360. (defun org-agenda-view-mode-dispatch ()
  7361. "Call one of the view mode commands."
  7362. (interactive)
  7363. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7364. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7365. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7366. (let ((a (read-char-exclusive)))
  7367. (case a
  7368. (?\ (call-interactively 'org-agenda-reset-view))
  7369. (?d (call-interactively 'org-agenda-day-view))
  7370. (?w (call-interactively 'org-agenda-week-view))
  7371. (?t (call-interactively 'org-agenda-fortnight-view))
  7372. (?m (call-interactively 'org-agenda-month-view))
  7373. (?y (call-interactively 'org-agenda-year-view))
  7374. (?l (call-interactively 'org-agenda-log-mode))
  7375. (?L (org-agenda-log-mode '(4)))
  7376. (?c (org-agenda-log-mode 'clockcheck))
  7377. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7378. (?a (call-interactively 'org-agenda-archives-mode))
  7379. (?A (org-agenda-archives-mode 'files))
  7380. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7381. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7382. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7383. (?D (call-interactively 'org-agenda-toggle-diary))
  7384. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7385. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7386. (org-agenda-check-type t 'timeline 'agenda)
  7387. (org-agenda-redo))
  7388. (message "Display now includes inactive timestamps as well"))
  7389. (?q (message "Abort"))
  7390. (otherwise (error "Invalid key" )))))
  7391. (defun org-agenda-reset-view ()
  7392. "Switch to default view for agenda."
  7393. (interactive)
  7394. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7395. (defun org-agenda-day-view (&optional day-of-month)
  7396. "Switch to daily view for agenda.
  7397. With argument DAY-OF-MONTH, switch to that day of the month."
  7398. (interactive "P")
  7399. (org-agenda-change-time-span 'day day-of-month))
  7400. (defun org-agenda-week-view (&optional iso-week)
  7401. "Switch to daily view for agenda.
  7402. With argument ISO-WEEK, switch to the corresponding ISO week.
  7403. If ISO-WEEK has more then 2 digits, only the last two encode the
  7404. week. Any digits before this encode a year. So 200712 means
  7405. week 12 of year 2007. Years in the range 1938-2037 can also be
  7406. written as 2-digit years."
  7407. (interactive "P")
  7408. (org-agenda-change-time-span 'week iso-week))
  7409. (defun org-agenda-fortnight-view (&optional iso-week)
  7410. "Switch to daily view for agenda.
  7411. With argument ISO-WEEK, switch to the corresponding ISO week.
  7412. If ISO-WEEK has more then 2 digits, only the last two encode the
  7413. week. Any digits before this encode a year. So 200712 means
  7414. week 12 of year 2007. Years in the range 1938-2037 can also be
  7415. written as 2-digit years."
  7416. (interactive "P")
  7417. (org-agenda-change-time-span 'fortnight iso-week))
  7418. (defun org-agenda-month-view (&optional month)
  7419. "Switch to monthly view for agenda.
  7420. With argument MONTH, switch to that month."
  7421. (interactive "P")
  7422. (org-agenda-change-time-span 'month month))
  7423. (defun org-agenda-year-view (&optional year)
  7424. "Switch to yearly view for agenda.
  7425. With argument YEAR, switch to that year.
  7426. If MONTH has more then 2 digits, only the last two encode the
  7427. month. Any digits before this encode a year. So 200712 means
  7428. December year 2007. Years in the range 1938-2037 can also be
  7429. written as 2-digit years."
  7430. (interactive "P")
  7431. (when year
  7432. (setq year (org-small-year-to-year year)))
  7433. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7434. (org-agenda-change-time-span 'year year)
  7435. (error "Abort")))
  7436. (defun org-agenda-change-time-span (span &optional n)
  7437. "Change the agenda view to SPAN.
  7438. SPAN may be `day', `week', `fortnight', `month', `year'."
  7439. (org-agenda-check-type t 'agenda)
  7440. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7441. (curspan (nth 2 args)))
  7442. (if (and (not n) (equal curspan span))
  7443. (error "Viewing span is already \"%s\"" span))
  7444. (let* ((sd (or (org-get-at-bol 'day)
  7445. (nth 1 args)
  7446. org-starting-day))
  7447. (sd (org-agenda-compute-starting-span sd span n))
  7448. (org-agenda-overriding-cmd
  7449. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7450. (org-agenda-overriding-arguments
  7451. (list (car args) sd span)))
  7452. (org-agenda-redo)
  7453. (org-agenda-find-same-or-today-or-agenda))
  7454. (org-agenda-set-mode-name)
  7455. (message "Switched to %s view" span)))
  7456. (defun org-agenda-compute-starting-span (sd span &optional n)
  7457. "Compute starting date for agenda.
  7458. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7459. is a cons cell with the starting date and the number of days,
  7460. so that the date SD will be in that range."
  7461. (let* ((greg (calendar-gregorian-from-absolute sd))
  7462. (dg (nth 1 greg))
  7463. (mg (car greg))
  7464. (yg (nth 2 greg)))
  7465. (cond
  7466. ((eq span 'day)
  7467. (when n
  7468. (setq sd (+ (calendar-absolute-from-gregorian
  7469. (list mg 1 yg))
  7470. n -1))))
  7471. ((or (eq span 'week) (eq span 'fortnight))
  7472. (let* ((nt (calendar-day-of-week
  7473. (calendar-gregorian-from-absolute sd)))
  7474. (d (if org-agenda-start-on-weekday
  7475. (- nt org-agenda-start-on-weekday)
  7476. 0))
  7477. y1)
  7478. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7479. (when n
  7480. (require 'cal-iso)
  7481. (when (> n 99)
  7482. (setq y1 (org-small-year-to-year (/ n 100))
  7483. n (mod n 100)))
  7484. (setq sd
  7485. (calendar-absolute-from-iso
  7486. (list n 1
  7487. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7488. ((eq span 'month)
  7489. (let (y1)
  7490. (when (and n (> n 99))
  7491. (setq y1 (org-small-year-to-year (/ n 100))
  7492. n (mod n 100)))
  7493. (setq sd (calendar-absolute-from-gregorian
  7494. (list (or n mg) 1 (or y1 yg))))))
  7495. ((eq span 'year)
  7496. (setq sd (calendar-absolute-from-gregorian
  7497. (list 1 1 (or n yg))))))
  7498. sd))
  7499. (defun org-agenda-next-date-line (&optional arg)
  7500. "Jump to the next line indicating a date in agenda buffer."
  7501. (interactive "p")
  7502. (org-agenda-check-type t 'agenda 'timeline)
  7503. (beginning-of-line 1)
  7504. ;; This does not work if user makes date format that starts with a blank
  7505. (if (looking-at "^\\S-") (forward-char 1))
  7506. (if (not (re-search-forward "^\\S-" nil t arg))
  7507. (progn
  7508. (backward-char 1)
  7509. (error "No next date after this line in this buffer")))
  7510. (goto-char (match-beginning 0)))
  7511. (defun org-agenda-previous-date-line (&optional arg)
  7512. "Jump to the previous line indicating a date in agenda buffer."
  7513. (interactive "p")
  7514. (org-agenda-check-type t 'agenda 'timeline)
  7515. (beginning-of-line 1)
  7516. (if (not (re-search-backward "^\\S-" nil t arg))
  7517. (error "No previous date before this line in this buffer")))
  7518. ;; Initialize the highlight
  7519. (defvar org-hl (make-overlay 1 1))
  7520. (overlay-put org-hl 'face 'highlight)
  7521. (defun org-highlight (begin end &optional buffer)
  7522. "Highlight a region with overlay."
  7523. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7524. (defun org-unhighlight ()
  7525. "Detach overlay INDEX."
  7526. (org-detach-overlay org-hl))
  7527. (defun org-unhighlight-once ()
  7528. "Remove the highlight from its position, and this function from the hook."
  7529. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7530. (org-unhighlight))
  7531. (defvar org-agenda-pre-follow-window-conf nil)
  7532. (defun org-agenda-follow-mode ()
  7533. "Toggle follow mode in an agenda buffer."
  7534. (interactive)
  7535. (unless org-agenda-follow-mode
  7536. (setq org-agenda-pre-follow-window-conf
  7537. (current-window-configuration)))
  7538. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7539. (unless org-agenda-follow-mode
  7540. (set-window-configuration org-agenda-pre-follow-window-conf))
  7541. (org-agenda-set-mode-name)
  7542. (org-agenda-do-context-action)
  7543. (message "Follow mode is %s"
  7544. (if org-agenda-follow-mode "on" "off")))
  7545. (defun org-agenda-entry-text-mode (&optional arg)
  7546. "Toggle entry text mode in an agenda buffer."
  7547. (interactive "P")
  7548. (if (or org-agenda-tag-filter
  7549. org-agenda-category-filter
  7550. org-agenda-regexp-filter
  7551. org-agenda-top-headline-filter)
  7552. (user-error "Can't show entry text in filtered views")
  7553. (setq org-agenda-entry-text-mode (or (integerp arg)
  7554. (not org-agenda-entry-text-mode)))
  7555. (org-agenda-entry-text-hide)
  7556. (and org-agenda-entry-text-mode
  7557. (let ((org-agenda-entry-text-maxlines
  7558. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7559. (org-agenda-entry-text-show)))
  7560. (org-agenda-set-mode-name)
  7561. (message "Entry text mode is %s%s"
  7562. (if org-agenda-entry-text-mode "on" "off")
  7563. (if (not org-agenda-entry-text-mode) ""
  7564. (format " (maximum number of lines is %d)"
  7565. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7566. (defun org-agenda-clockreport-mode (&optional with-filter)
  7567. "Toggle clocktable mode in an agenda buffer.
  7568. With prefix arg WITH-FILTER, make the clocktable respect the current
  7569. agenda filter."
  7570. (interactive "P")
  7571. (org-agenda-check-type t 'agenda)
  7572. (if with-filter
  7573. (setq org-agenda-clockreport-mode 'with-filter)
  7574. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7575. (org-agenda-set-mode-name)
  7576. (org-agenda-redo)
  7577. (message "Clocktable mode is %s"
  7578. (if org-agenda-clockreport-mode "on" "off")))
  7579. (defun org-agenda-log-mode (&optional special)
  7580. "Toggle log mode in an agenda buffer.
  7581. With argument SPECIAL, show all possible log items, not only the ones
  7582. configured in `org-agenda-log-mode-items'.
  7583. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7584. (interactive "P")
  7585. (org-agenda-check-type t 'agenda 'timeline)
  7586. (setq org-agenda-show-log
  7587. (cond
  7588. ((equal special '(16)) 'only)
  7589. ((eq special 'clockcheck)
  7590. (if (eq org-agenda-show-log 'clockcheck)
  7591. nil 'clockcheck))
  7592. (special '(closed clock state))
  7593. (t (not org-agenda-show-log))))
  7594. (org-agenda-set-mode-name)
  7595. (org-agenda-redo)
  7596. (message "Log mode is %s"
  7597. (if org-agenda-show-log "on" "off")))
  7598. (defun org-agenda-archives-mode (&optional with-files)
  7599. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7600. When called with a prefix argument, include all archive files as well."
  7601. (interactive "P")
  7602. (setq org-agenda-archives-mode
  7603. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7604. (org-agenda-set-mode-name)
  7605. (org-agenda-redo)
  7606. (message
  7607. "%s"
  7608. (cond
  7609. ((eq org-agenda-archives-mode nil)
  7610. "No archives are included")
  7611. ((eq org-agenda-archives-mode 'trees)
  7612. (format "Trees with :%s: tag are included" org-archive-tag))
  7613. ((eq org-agenda-archives-mode t)
  7614. (format "Trees with :%s: tag and all active archive files are included"
  7615. org-archive-tag)))))
  7616. (defun org-agenda-toggle-diary ()
  7617. "Toggle diary inclusion in an agenda buffer."
  7618. (interactive)
  7619. (org-agenda-check-type t 'agenda)
  7620. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7621. (org-agenda-redo)
  7622. (org-agenda-set-mode-name)
  7623. (message "Diary inclusion turned %s"
  7624. (if org-agenda-include-diary "on" "off")))
  7625. (defun org-agenda-toggle-deadlines ()
  7626. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7627. (interactive)
  7628. (org-agenda-check-type t 'agenda)
  7629. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7630. (org-agenda-redo)
  7631. (org-agenda-set-mode-name)
  7632. (message "Deadlines inclusion turned %s"
  7633. (if org-agenda-include-deadlines "on" "off")))
  7634. (defun org-agenda-toggle-time-grid ()
  7635. "Toggle time grid in an agenda buffer."
  7636. (interactive)
  7637. (org-agenda-check-type t 'agenda)
  7638. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7639. (org-agenda-redo)
  7640. (org-agenda-set-mode-name)
  7641. (message "Time-grid turned %s"
  7642. (if org-agenda-use-time-grid "on" "off")))
  7643. (defun org-agenda-set-mode-name ()
  7644. "Set the mode name to indicate all the small mode settings."
  7645. (setq mode-name
  7646. (list "Org-Agenda"
  7647. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7648. " "
  7649. '(:eval (org-agenda-span-name org-agenda-current-span))
  7650. (if org-agenda-follow-mode " Follow" "")
  7651. (if org-agenda-entry-text-mode " ETxt" "")
  7652. (if org-agenda-include-diary " Diary" "")
  7653. (if org-agenda-include-deadlines " Ddl" "")
  7654. (if org-agenda-use-time-grid " Grid" "")
  7655. (if (and (boundp 'org-habit-show-habits)
  7656. org-habit-show-habits) " Habit" "")
  7657. (cond
  7658. ((consp org-agenda-show-log) " LogAll")
  7659. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7660. (org-agenda-show-log " Log")
  7661. (t ""))
  7662. (if (or org-agenda-category-filter
  7663. (get 'org-agenda-category-filter :preset-filter))
  7664. '(:eval (org-propertize
  7665. (concat " <"
  7666. (mapconcat
  7667. 'identity
  7668. (append
  7669. (get 'org-agenda-category-filter :preset-filter)
  7670. org-agenda-category-filter)
  7671. "")
  7672. ">")
  7673. 'face 'org-agenda-filter-category
  7674. 'help-echo "Category used in filtering")) "")
  7675. (if (or org-agenda-tag-filter
  7676. (get 'org-agenda-tag-filter :preset-filter))
  7677. '(:eval (org-propertize
  7678. (concat " {"
  7679. (mapconcat
  7680. 'identity
  7681. (append
  7682. (get 'org-agenda-tag-filter :preset-filter)
  7683. org-agenda-tag-filter)
  7684. "")
  7685. "}")
  7686. 'face 'org-agenda-filter-tags
  7687. 'help-echo "Tags used in filtering")) "")
  7688. (if (or org-agenda-regexp-filter
  7689. (get 'org-agenda-regexp-filter :preset-filter))
  7690. '(:eval (org-propertize
  7691. (concat " ["
  7692. (mapconcat
  7693. 'identity
  7694. (append
  7695. (get 'org-agenda-regexp-filter :preset-filter)
  7696. org-agenda-regexp-filter)
  7697. "")
  7698. "]")
  7699. 'face 'org-agenda-filter-regexp
  7700. 'help-echo "Regexp used in filtering")) "")
  7701. (if org-agenda-archives-mode
  7702. (if (eq org-agenda-archives-mode t)
  7703. " Archives"
  7704. (format " :%s:" org-archive-tag))
  7705. "")
  7706. (if org-agenda-clockreport-mode
  7707. (if (eq org-agenda-clockreport-mode 'with-filter)
  7708. " Clock{}" " Clock")
  7709. "")))
  7710. (force-mode-line-update))
  7711. (define-obsolete-function-alias
  7712. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7713. (defun org-agenda-update-agenda-type ()
  7714. "Update the agenda type after each command."
  7715. (setq org-agenda-type
  7716. (or (get-text-property (point) 'org-agenda-type)
  7717. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7718. (defun org-agenda-next-line ()
  7719. "Move cursor to the next line, and show if follow mode is active."
  7720. (interactive)
  7721. (call-interactively 'next-line)
  7722. (org-agenda-do-context-action))
  7723. (defun org-agenda-previous-line ()
  7724. "Move cursor to the previous line, and show if follow-mode is active."
  7725. (interactive)
  7726. (call-interactively 'previous-line)
  7727. (org-agenda-do-context-action))
  7728. (defun org-agenda-next-item (n)
  7729. "Move cursor to next agenda item."
  7730. (interactive "p")
  7731. (let ((col (current-column)))
  7732. (dotimes (c n)
  7733. (when (next-single-property-change (point-at-eol) 'org-marker)
  7734. (move-end-of-line 1)
  7735. (goto-char (next-single-property-change (point) 'org-marker))))
  7736. (org-move-to-column col))
  7737. (org-agenda-do-context-action))
  7738. (defun org-agenda-previous-item (n)
  7739. "Move cursor to next agenda item."
  7740. (interactive "p")
  7741. (dotimes (c n)
  7742. (let ((col (current-column))
  7743. (goto (save-excursion
  7744. (move-end-of-line 0)
  7745. (previous-single-property-change (point) 'org-marker))))
  7746. (if goto (goto-char goto))
  7747. (org-move-to-column col)))
  7748. (org-agenda-do-context-action))
  7749. (defun org-agenda-do-context-action ()
  7750. "Show outline path and, maybe, follow mode window."
  7751. (let ((m (org-get-at-bol 'org-marker)))
  7752. (when (and (markerp m) (marker-buffer m))
  7753. (and org-agenda-follow-mode
  7754. (if org-agenda-follow-indirect
  7755. (org-agenda-tree-to-indirect-buffer nil)
  7756. (org-agenda-show)))
  7757. (and org-agenda-show-outline-path
  7758. (org-with-point-at m (org-display-outline-path t))))))
  7759. (defun org-agenda-show-tags ()
  7760. "Show the tags applicable to the current item."
  7761. (interactive)
  7762. (let* ((tags (org-get-at-bol 'tags)))
  7763. (if tags
  7764. (message "Tags are :%s:"
  7765. (org-no-properties (mapconcat 'identity tags ":")))
  7766. (message "No tags associated with this line"))))
  7767. (defun org-agenda-goto (&optional highlight)
  7768. "Go to the Org-mode file which contains the item at point."
  7769. (interactive)
  7770. (let* ((marker (or (org-get-at-bol 'org-marker)
  7771. (org-agenda-error)))
  7772. (buffer (marker-buffer marker))
  7773. (pos (marker-position marker)))
  7774. (switch-to-buffer-other-window buffer)
  7775. (widen)
  7776. (push-mark)
  7777. (goto-char pos)
  7778. (when (derived-mode-p 'org-mode)
  7779. (org-show-context 'agenda)
  7780. (save-excursion
  7781. (and (outline-next-heading)
  7782. (org-flag-heading nil)))) ; show the next heading
  7783. (when (outline-invisible-p)
  7784. (show-entry)) ; display invisible text
  7785. (recenter (/ (window-height) 2))
  7786. (run-hooks 'org-agenda-after-show-hook)
  7787. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7788. (defvar org-agenda-after-show-hook nil
  7789. "Normal hook run after an item has been shown from the agenda.
  7790. Point is in the buffer where the item originated.")
  7791. (defun org-agenda-kill ()
  7792. "Kill the entry or subtree belonging to the current agenda entry."
  7793. (interactive)
  7794. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7795. (let* ((bufname-orig (buffer-name))
  7796. (marker (or (org-get-at-bol 'org-marker)
  7797. (org-agenda-error)))
  7798. (buffer (marker-buffer marker))
  7799. (pos (marker-position marker))
  7800. (type (org-get-at-bol 'type))
  7801. dbeg dend (n 0) conf)
  7802. (org-with-remote-undo buffer
  7803. (with-current-buffer buffer
  7804. (save-excursion
  7805. (goto-char pos)
  7806. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7807. (setq dbeg (progn (org-back-to-heading t) (point))
  7808. dend (org-end-of-subtree t t))
  7809. (setq dbeg (point-at-bol)
  7810. dend (min (point-max) (1+ (point-at-eol)))))
  7811. (goto-char dbeg)
  7812. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7813. (setq conf (or (eq t org-agenda-confirm-kill)
  7814. (and (numberp org-agenda-confirm-kill)
  7815. (> n org-agenda-confirm-kill))))
  7816. (and conf
  7817. (not (y-or-n-p
  7818. (format "Delete entry with %d lines in buffer \"%s\"? "
  7819. n (buffer-name buffer))))
  7820. (error "Abort"))
  7821. (let ((org-agenda-buffer-name bufname-orig))
  7822. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7823. (with-current-buffer buffer (delete-region dbeg dend))
  7824. (message "Agenda item and source killed"))))
  7825. (defvar org-archive-default-command) ; defined in org-archive.el
  7826. (defun org-agenda-archive-default ()
  7827. "Archive the entry or subtree belonging to the current agenda entry."
  7828. (interactive)
  7829. (require 'org-archive)
  7830. (org-agenda-archive-with org-archive-default-command))
  7831. (defun org-agenda-archive-default-with-confirmation ()
  7832. "Archive the entry or subtree belonging to the current agenda entry."
  7833. (interactive)
  7834. (require 'org-archive)
  7835. (org-agenda-archive-with org-archive-default-command 'confirm))
  7836. (defun org-agenda-archive ()
  7837. "Archive the entry or subtree belonging to the current agenda entry."
  7838. (interactive)
  7839. (org-agenda-archive-with 'org-archive-subtree))
  7840. (defun org-agenda-archive-to-archive-sibling ()
  7841. "Move the entry to the archive sibling."
  7842. (interactive)
  7843. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7844. (defun org-agenda-archive-with (cmd &optional confirm)
  7845. "Move the entry to the archive sibling."
  7846. (interactive)
  7847. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7848. (let* ((bufname-orig (buffer-name))
  7849. (marker (or (org-get-at-bol 'org-marker)
  7850. (org-agenda-error)))
  7851. (buffer (marker-buffer marker))
  7852. (pos (marker-position marker)))
  7853. (org-with-remote-undo buffer
  7854. (with-current-buffer buffer
  7855. (if (derived-mode-p 'org-mode)
  7856. (if (and confirm
  7857. (not (y-or-n-p "Archive this subtree or entry? ")))
  7858. (error "Abort")
  7859. (save-window-excursion
  7860. (goto-char pos)
  7861. (let ((org-agenda-buffer-name bufname-orig))
  7862. (org-remove-subtree-entries-from-agenda))
  7863. (org-back-to-heading t)
  7864. (funcall cmd)))
  7865. (error "Archiving works only in Org-mode files"))))))
  7866. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7867. "Remove all lines in the agenda that correspond to a given subtree.
  7868. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7869. If this information is not given, the function uses the tree at point."
  7870. (let ((buf (or buf (current-buffer))) m p)
  7871. (save-excursion
  7872. (unless (and beg end)
  7873. (org-back-to-heading t)
  7874. (setq beg (point))
  7875. (org-end-of-subtree t)
  7876. (setq end (point)))
  7877. (set-buffer (get-buffer org-agenda-buffer-name))
  7878. (save-excursion
  7879. (goto-char (point-max))
  7880. (beginning-of-line 1)
  7881. (while (not (bobp))
  7882. (when (and (setq m (org-get-at-bol 'org-marker))
  7883. (equal buf (marker-buffer m))
  7884. (setq p (marker-position m))
  7885. (>= p beg)
  7886. (< p end))
  7887. (let ((inhibit-read-only t))
  7888. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7889. (beginning-of-line 0))))))
  7890. (defun org-agenda-refile (&optional goto rfloc no-update)
  7891. "Refile the item at point.
  7892. When GOTO is 0 or '(64), clear the refile cache.
  7893. When GOTO is '(16), go to the location of the last refiled item.
  7894. RFLOC can be a refile location obtained in a different way.
  7895. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7896. (interactive "P")
  7897. (cond
  7898. ((member goto '(0 (64)))
  7899. (org-refile-cache-clear))
  7900. ((equal goto '(16))
  7901. (org-refile-goto-last-stored))
  7902. (t
  7903. (let* ((buffer-orig (buffer-name))
  7904. (marker (or (org-get-at-bol 'org-hd-marker)
  7905. (org-agenda-error)))
  7906. (buffer (marker-buffer marker))
  7907. (pos (marker-position marker))
  7908. (rfloc (or rfloc
  7909. (org-refile-get-location
  7910. (if goto "Goto" "Refile to") buffer
  7911. org-refile-allow-creating-parent-nodes))))
  7912. (with-current-buffer buffer
  7913. (save-excursion
  7914. (save-restriction
  7915. (widen)
  7916. (goto-char marker)
  7917. (let ((org-agenda-buffer-name buffer-orig))
  7918. (org-remove-subtree-entries-from-agenda))
  7919. (org-refile goto buffer rfloc)))))
  7920. (unless no-update (org-agenda-redo)))))
  7921. (defun org-agenda-open-link (&optional arg)
  7922. "Open the link(s) in the current entry, if any.
  7923. This looks for a link in the displayed line in the agenda.
  7924. It also looks at the text of the entry itself."
  7925. (interactive "P")
  7926. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7927. (org-get-at-bol 'org-marker)))
  7928. (buffer (and marker (marker-buffer marker)))
  7929. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7930. (lkall (and buffer (org-offer-links-in-entry
  7931. buffer marker arg prefix)))
  7932. (lk0 (car lkall))
  7933. (lk (if (stringp lk0) (list lk0) lk0))
  7934. (lkend (cdr lkall))
  7935. trg)
  7936. (cond
  7937. ((and buffer lk)
  7938. (mapcar (lambda(l)
  7939. (with-current-buffer buffer
  7940. (setq trg (and (string-match org-bracket-link-regexp l)
  7941. (match-string 1 l)))
  7942. (if (or (not trg) (string-match org-any-link-re trg))
  7943. (save-excursion
  7944. (save-restriction
  7945. (widen)
  7946. (goto-char marker)
  7947. (when (search-forward l nil lkend)
  7948. (goto-char (match-beginning 0))
  7949. (org-open-at-point))))
  7950. ;; This is an internal link, widen the buffer
  7951. (switch-to-buffer-other-window buffer)
  7952. (widen)
  7953. (goto-char marker)
  7954. (when (search-forward l nil lkend)
  7955. (goto-char (match-beginning 0))
  7956. (org-open-at-point)))))
  7957. lk))
  7958. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7959. (save-excursion
  7960. (beginning-of-line 1)
  7961. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7962. (org-open-link-from-string (match-string 1)))
  7963. (t (message "No link to open here")))))
  7964. (defun org-agenda-copy-local-variable (var)
  7965. "Get a variable from a referenced buffer and install it here."
  7966. (let ((m (org-get-at-bol 'org-marker)))
  7967. (when (and m (buffer-live-p (marker-buffer m)))
  7968. (org-set-local var (with-current-buffer (marker-buffer m)
  7969. (symbol-value var))))))
  7970. (defun org-agenda-switch-to (&optional delete-other-windows)
  7971. "Go to the Org-mode file which contains the item at point."
  7972. (interactive)
  7973. (if (and org-return-follows-link
  7974. (not (org-get-at-bol 'org-marker))
  7975. (org-in-regexp org-bracket-link-regexp))
  7976. (org-open-link-from-string (match-string 0))
  7977. (let* ((marker (or (org-get-at-bol 'org-marker)
  7978. (org-agenda-error)))
  7979. (buffer (marker-buffer marker))
  7980. (pos (marker-position marker)))
  7981. (org-pop-to-buffer-same-window buffer)
  7982. (and delete-other-windows (delete-other-windows))
  7983. (widen)
  7984. (goto-char pos)
  7985. (when (derived-mode-p 'org-mode)
  7986. (org-show-context 'agenda)
  7987. (save-excursion
  7988. (and (outline-next-heading)
  7989. (org-flag-heading nil))) ; show the next heading
  7990. (when (outline-invisible-p)
  7991. (show-entry)) ; display invisible text
  7992. (run-hooks 'org-agenda-after-show-hook)))))
  7993. (defun org-agenda-goto-mouse (ev)
  7994. "Go to the Org-mode file which contains the item at the mouse click."
  7995. (interactive "e")
  7996. (mouse-set-point ev)
  7997. (org-agenda-goto))
  7998. (defun org-agenda-show (&optional full-entry)
  7999. "Display the Org-mode file which contains the item at point.
  8000. With prefix argument FULL-ENTRY, make the entire entry visible
  8001. if it was hidden in the outline."
  8002. (interactive "P")
  8003. (let ((win (selected-window)))
  8004. (if full-entry
  8005. (let ((org-show-entry-below t))
  8006. (org-agenda-goto t))
  8007. (org-agenda-goto t))
  8008. (select-window win)))
  8009. (defvar org-agenda-show-window nil)
  8010. (defun org-agenda-show-and-scroll-up (&optional arg)
  8011. "Display the Org-mode file which contains the item at point.
  8012. When called repeatedly, scroll the window that is displaying the buffer.
  8013. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  8014. `show-subtree' to display the item, so that drawers and logbooks stay
  8015. folded."
  8016. (interactive "P")
  8017. (let ((win (selected-window)))
  8018. (if (and (window-live-p org-agenda-show-window)
  8019. (eq this-command last-command))
  8020. (progn
  8021. (select-window org-agenda-show-window)
  8022. (ignore-errors (scroll-up)))
  8023. (org-agenda-goto t)
  8024. (if arg (org-show-entry) (show-subtree))
  8025. (setq org-agenda-show-window (selected-window)))
  8026. (select-window win)))
  8027. (defun org-agenda-show-scroll-down ()
  8028. "Scroll down the window showing the agenda."
  8029. (interactive)
  8030. (let ((win (selected-window)))
  8031. (when (window-live-p org-agenda-show-window)
  8032. (select-window org-agenda-show-window)
  8033. (ignore-errors (scroll-down))
  8034. (select-window win))))
  8035. (defun org-agenda-show-1 (&optional more)
  8036. "Display the Org-mode file which contains the item at point.
  8037. The prefix arg selects the amount of information to display:
  8038. 0 hide the subtree
  8039. 1 just show the entry according to defaults.
  8040. 2 show the children view
  8041. 3 show the subtree view
  8042. 4 show the entire subtree and any LOGBOOK drawers
  8043. 5 show the entire subtree and any drawers
  8044. With prefix argument FULL-ENTRY, make the entire entry visible
  8045. if it was hidden in the outline."
  8046. (interactive "p")
  8047. (let ((win (selected-window)))
  8048. (org-agenda-goto t)
  8049. (org-recenter-heading 1)
  8050. (cond
  8051. ((= more 0)
  8052. (hide-subtree)
  8053. (save-excursion
  8054. (org-back-to-heading)
  8055. (run-hook-with-args 'org-cycle-hook 'folded))
  8056. (message "Remote: FOLDED"))
  8057. ((and (org-called-interactively-p 'any) (= more 1))
  8058. (message "Remote: show with default settings"))
  8059. ((= more 2)
  8060. (show-entry)
  8061. (show-children)
  8062. (save-excursion
  8063. (org-back-to-heading)
  8064. (run-hook-with-args 'org-cycle-hook 'children))
  8065. (message "Remote: CHILDREN"))
  8066. ((= more 3)
  8067. (show-subtree)
  8068. (save-excursion
  8069. (org-back-to-heading)
  8070. (run-hook-with-args 'org-cycle-hook 'subtree))
  8071. (message "Remote: SUBTREE"))
  8072. ((= more 4)
  8073. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  8074. (org-drawer-regexp
  8075. (concat "^[ \t]*:\\("
  8076. (mapconcat 'regexp-quote org-drawers "\\|")
  8077. "\\):[ \t]*$")))
  8078. (show-subtree)
  8079. (save-excursion
  8080. (org-back-to-heading)
  8081. (org-cycle-hide-drawers 'subtree)))
  8082. (message "Remote: SUBTREE AND LOGBOOK"))
  8083. ((> more 4)
  8084. (show-subtree)
  8085. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8086. (select-window win)))
  8087. (defun org-recenter-heading (n)
  8088. (save-excursion
  8089. (org-back-to-heading)
  8090. (recenter n)))
  8091. (defvar org-agenda-cycle-counter nil)
  8092. (defun org-agenda-cycle-show (&optional n)
  8093. "Show the current entry in another window, with default settings.
  8094. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8095. When use repeatedly in immediate succession, the remote entry will cycle
  8096. through visibility
  8097. children -> subtree -> folded
  8098. When called with a numeric prefix arg, that arg will be passed through to
  8099. `org-agenda-show-1'. For the interpretation of that argument, see the
  8100. docstring of `org-agenda-show-1'."
  8101. (interactive "P")
  8102. (if (integerp n)
  8103. (setq org-agenda-cycle-counter n)
  8104. (if (not (eq last-command this-command))
  8105. (setq org-agenda-cycle-counter 1)
  8106. (if (equal org-agenda-cycle-counter 0)
  8107. (setq org-agenda-cycle-counter 2)
  8108. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8109. (if (> org-agenda-cycle-counter 3)
  8110. (setq org-agenda-cycle-counter 0)))))
  8111. (org-agenda-show-1 org-agenda-cycle-counter))
  8112. (defun org-agenda-recenter (arg)
  8113. "Display the Org-mode file which contains the item at point and recenter."
  8114. (interactive "P")
  8115. (let ((win (selected-window)))
  8116. (org-agenda-goto t)
  8117. (recenter arg)
  8118. (select-window win)))
  8119. (defun org-agenda-show-mouse (ev)
  8120. "Display the Org-mode file which contains the item at the mouse click."
  8121. (interactive "e")
  8122. (mouse-set-point ev)
  8123. (org-agenda-show))
  8124. (defun org-agenda-check-no-diary ()
  8125. "Check if the entry is a diary link and abort if yes."
  8126. (if (org-get-at-bol 'org-agenda-diary-link)
  8127. (org-agenda-error)))
  8128. (defun org-agenda-error ()
  8129. (error "Command not allowed in this line"))
  8130. (defun org-agenda-tree-to-indirect-buffer (arg)
  8131. "Show the subtree corresponding to the current entry in an indirect buffer.
  8132. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8133. With a numerical prefix ARG, go up to this level and then take that tree.
  8134. With a negative numeric ARG, go up by this number of levels.
  8135. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8136. use the dedicated frame)."
  8137. (interactive "P")
  8138. (if current-prefix-arg
  8139. (org-agenda-do-tree-to-indirect-buffer arg)
  8140. (let ((agenda-buffer (buffer-name))
  8141. (agenda-window (selected-window))
  8142. (indirect-window
  8143. (and org-last-indirect-buffer
  8144. (get-buffer-window org-last-indirect-buffer))))
  8145. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8146. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8147. (eq org-indirect-buffer-display 'dedicated-frame))
  8148. (unwind-protect
  8149. (unless (and indirect-window (window-live-p indirect-window))
  8150. (setq indirect-window (split-window agenda-window)))
  8151. (and indirect-window (select-window indirect-window))
  8152. (switch-to-buffer org-last-indirect-buffer :norecord)
  8153. (fit-window-to-buffer indirect-window)))
  8154. (select-window (get-buffer-window agenda-buffer)))))
  8155. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8156. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8157. (org-agenda-check-no-diary)
  8158. (let* ((marker (or (org-get-at-bol 'org-marker)
  8159. (org-agenda-error)))
  8160. (buffer (marker-buffer marker))
  8161. (pos (marker-position marker)))
  8162. (with-current-buffer buffer
  8163. (save-excursion
  8164. (goto-char pos)
  8165. (funcall 'org-tree-to-indirect-buffer arg)))))
  8166. (defvar org-last-heading-marker (make-marker)
  8167. "Marker pointing to the headline that last changed its TODO state
  8168. by a remote command from the agenda.")
  8169. (defun org-agenda-todo-nextset ()
  8170. "Switch TODO entry to next sequence."
  8171. (interactive)
  8172. (org-agenda-todo 'nextset))
  8173. (defun org-agenda-todo-previousset ()
  8174. "Switch TODO entry to previous sequence."
  8175. (interactive)
  8176. (org-agenda-todo 'previousset))
  8177. (defun org-agenda-todo (&optional arg)
  8178. "Cycle TODO state of line at point, also in Org-mode file.
  8179. This changes the line at point, all other lines in the agenda referring to
  8180. the same tree node, and the headline of the tree node in the Org-mode file."
  8181. (interactive "P")
  8182. (org-agenda-check-no-diary)
  8183. (let* ((col (current-column))
  8184. (marker (or (org-get-at-bol 'org-marker)
  8185. (org-agenda-error)))
  8186. (buffer (marker-buffer marker))
  8187. (pos (marker-position marker))
  8188. (hdmarker (org-get-at-bol 'org-hd-marker))
  8189. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8190. (inhibit-read-only t)
  8191. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8192. (org-with-remote-undo buffer
  8193. (with-current-buffer buffer
  8194. (widen)
  8195. (goto-char pos)
  8196. (org-show-context 'agenda)
  8197. (save-excursion
  8198. (and (outline-next-heading)
  8199. (org-flag-heading nil))) ; show the next heading
  8200. (let ((current-prefix-arg arg))
  8201. (call-interactively 'org-todo))
  8202. (and (bolp) (forward-char 1))
  8203. (setq newhead (org-get-heading))
  8204. (when (and (org-bound-and-true-p
  8205. org-agenda-headline-snapshot-before-repeat)
  8206. (not (equal org-agenda-headline-snapshot-before-repeat
  8207. newhead))
  8208. todayp)
  8209. (setq newhead org-agenda-headline-snapshot-before-repeat
  8210. just-one t))
  8211. (save-excursion
  8212. (org-back-to-heading)
  8213. (move-marker org-last-heading-marker (point))))
  8214. (beginning-of-line 1)
  8215. (save-window-excursion
  8216. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8217. (when (org-bound-and-true-p org-clock-out-when-done)
  8218. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8219. newhead)
  8220. (org-agenda-unmark-clocking-task))
  8221. (org-move-to-column col))))
  8222. (defun org-agenda-add-note (&optional arg)
  8223. "Add a time-stamped note to the entry at point."
  8224. (interactive "P")
  8225. (org-agenda-check-no-diary)
  8226. (let* ((marker (or (org-get-at-bol 'org-marker)
  8227. (org-agenda-error)))
  8228. (buffer (marker-buffer marker))
  8229. (pos (marker-position marker))
  8230. (hdmarker (org-get-at-bol 'org-hd-marker))
  8231. (inhibit-read-only t))
  8232. (with-current-buffer buffer
  8233. (widen)
  8234. (goto-char pos)
  8235. (org-show-context 'agenda)
  8236. (save-excursion
  8237. (and (outline-next-heading)
  8238. (org-flag-heading nil))) ; show the next heading
  8239. (org-add-note))))
  8240. (defun org-agenda-change-all-lines (newhead hdmarker
  8241. &optional fixface just-this)
  8242. "Change all lines in the agenda buffer which match HDMARKER.
  8243. The new content of the line will be NEWHEAD (as modified by
  8244. `org-agenda-format-item'). HDMARKER is checked with
  8245. `equal' against all `org-hd-marker' text properties in the file.
  8246. If FIXFACE is non-nil, the face of each item is modified according to
  8247. the new TODO state.
  8248. If JUST-THIS is non-nil, change just the current line, not all.
  8249. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8250. (let* ((inhibit-read-only t)
  8251. (line (org-current-line))
  8252. (org-agenda-buffer (current-buffer))
  8253. (thetags (with-current-buffer (marker-buffer hdmarker)
  8254. (save-excursion (save-restriction (widen)
  8255. (goto-char hdmarker)
  8256. (org-get-tags-at)))))
  8257. props m pl undone-face done-face finish new dotime level cat tags)
  8258. (save-excursion
  8259. (goto-char (point-max))
  8260. (beginning-of-line 1)
  8261. (while (not finish)
  8262. (setq finish (bobp))
  8263. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8264. (or (not just-this) (= (org-current-line) line))
  8265. (equal m hdmarker))
  8266. (setq props (text-properties-at (point))
  8267. dotime (org-get-at-bol 'dotime)
  8268. cat (org-get-at-bol 'org-category)
  8269. level (org-get-at-bol 'level)
  8270. tags thetags
  8271. new
  8272. (let ((org-prefix-format-compiled
  8273. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8274. org-prefix-format-compiled))
  8275. (extra (org-get-at-bol 'extra)))
  8276. (with-current-buffer (marker-buffer hdmarker)
  8277. (save-excursion
  8278. (save-restriction
  8279. (widen)
  8280. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8281. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8282. undone-face (org-get-at-bol 'undone-face)
  8283. done-face (org-get-at-bol 'done-face))
  8284. (beginning-of-line 1)
  8285. (cond
  8286. ((equal new "")
  8287. (and (looking-at ".*\n?") (replace-match "")))
  8288. ((looking-at ".*")
  8289. (replace-match new t t)
  8290. (beginning-of-line 1)
  8291. (add-text-properties (point-at-bol) (point-at-eol) props)
  8292. (when fixface
  8293. (add-text-properties
  8294. (point-at-bol) (point-at-eol)
  8295. (list 'face
  8296. (if org-last-todo-state-is-todo
  8297. undone-face done-face))))
  8298. (org-agenda-highlight-todo 'line)
  8299. (beginning-of-line 1))
  8300. (t (error "Line update did not work")))
  8301. (save-restriction
  8302. (narrow-to-region (point-at-bol) (point-at-eol))
  8303. (org-agenda-finalize)))
  8304. (beginning-of-line 0)))))
  8305. (defun org-agenda-align-tags (&optional line)
  8306. "Align all tags in agenda items to `org-agenda-tags-column'."
  8307. (let ((inhibit-read-only t) l c)
  8308. (save-excursion
  8309. (goto-char (if line (point-at-bol) (point-min)))
  8310. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8311. (if line (point-at-eol) nil) t)
  8312. (add-text-properties
  8313. (match-beginning 2) (match-end 2)
  8314. (list 'face (delq nil (let ((prop (get-text-property
  8315. (match-beginning 2) 'face)))
  8316. (or (listp prop) (setq prop (list prop)))
  8317. (if (memq 'org-tag prop)
  8318. prop
  8319. (cons 'org-tag prop))))))
  8320. (setq l (- (match-end 2) (match-beginning 2))
  8321. c (if (< org-agenda-tags-column 0)
  8322. (- (abs org-agenda-tags-column) l)
  8323. org-agenda-tags-column))
  8324. (delete-region (match-beginning 1) (match-end 1))
  8325. (goto-char (match-beginning 1))
  8326. (insert (org-add-props
  8327. (make-string (max 1 (- c (current-column))) ?\ )
  8328. (plist-put (copy-sequence (text-properties-at (point)))
  8329. 'face nil))))
  8330. (goto-char (point-min))
  8331. (org-font-lock-add-tag-faces (point-max)))))
  8332. (defun org-agenda-priority-up ()
  8333. "Increase the priority of line at point, also in Org-mode file."
  8334. (interactive)
  8335. (org-agenda-priority 'up))
  8336. (defun org-agenda-priority-down ()
  8337. "Decrease the priority of line at point, also in Org-mode file."
  8338. (interactive)
  8339. (org-agenda-priority 'down))
  8340. (defun org-agenda-priority (&optional force-direction)
  8341. "Set the priority of line at point, also in Org-mode file.
  8342. This changes the line at point, all other lines in the agenda referring to
  8343. the same tree node, and the headline of the tree node in the Org-mode file.
  8344. Called with a universal prefix arg, show the priority instead of setting it."
  8345. (interactive "P")
  8346. (if (equal force-direction '(4))
  8347. (org-show-priority)
  8348. (unless org-enable-priority-commands
  8349. (error "Priority commands are disabled"))
  8350. (org-agenda-check-no-diary)
  8351. (let* ((col (current-column))
  8352. (marker (or (org-get-at-bol 'org-marker)
  8353. (org-agenda-error)))
  8354. (hdmarker (org-get-at-bol 'org-hd-marker))
  8355. (buffer (marker-buffer hdmarker))
  8356. (pos (marker-position hdmarker))
  8357. (inhibit-read-only t)
  8358. newhead)
  8359. (org-with-remote-undo buffer
  8360. (with-current-buffer buffer
  8361. (widen)
  8362. (goto-char pos)
  8363. (org-show-context 'agenda)
  8364. (save-excursion
  8365. (and (outline-next-heading)
  8366. (org-flag-heading nil))) ; show the next heading
  8367. (funcall 'org-priority force-direction)
  8368. (end-of-line 1)
  8369. (setq newhead (org-get-heading)))
  8370. (org-agenda-change-all-lines newhead hdmarker)
  8371. (org-move-to-column col)))))
  8372. ;; FIXME: should fix the tags property of the agenda line.
  8373. (defun org-agenda-set-tags (&optional tag onoff)
  8374. "Set tags for the current headline."
  8375. (interactive)
  8376. (org-agenda-check-no-diary)
  8377. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8378. (call-interactively 'org-change-tag-in-region)
  8379. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8380. (org-agenda-error)))
  8381. (buffer (marker-buffer hdmarker))
  8382. (pos (marker-position hdmarker))
  8383. (inhibit-read-only t)
  8384. newhead)
  8385. (org-with-remote-undo buffer
  8386. (with-current-buffer buffer
  8387. (widen)
  8388. (goto-char pos)
  8389. (save-excursion
  8390. (org-show-context 'agenda))
  8391. (save-excursion
  8392. (and (outline-next-heading)
  8393. (org-flag-heading nil))) ; show the next heading
  8394. (goto-char pos)
  8395. (if tag
  8396. (org-toggle-tag tag onoff)
  8397. (call-interactively 'org-set-tags))
  8398. (end-of-line 1)
  8399. (setq newhead (org-get-heading)))
  8400. (org-agenda-change-all-lines newhead hdmarker)
  8401. (beginning-of-line 1)))))
  8402. (defun org-agenda-set-property ()
  8403. "Set a property for the current headline."
  8404. (interactive)
  8405. (org-agenda-check-no-diary)
  8406. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8407. (org-agenda-error)))
  8408. (buffer (marker-buffer hdmarker))
  8409. (pos (marker-position hdmarker))
  8410. (inhibit-read-only t)
  8411. newhead)
  8412. (org-with-remote-undo buffer
  8413. (with-current-buffer buffer
  8414. (widen)
  8415. (goto-char pos)
  8416. (save-excursion
  8417. (org-show-context 'agenda))
  8418. (save-excursion
  8419. (and (outline-next-heading)
  8420. (org-flag-heading nil))) ; show the next heading
  8421. (goto-char pos)
  8422. (call-interactively 'org-set-property)))))
  8423. (defun org-agenda-set-effort ()
  8424. "Set the effort property for the current headline."
  8425. (interactive)
  8426. (org-agenda-check-no-diary)
  8427. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8428. (org-agenda-error)))
  8429. (buffer (marker-buffer hdmarker))
  8430. (pos (marker-position hdmarker))
  8431. (inhibit-read-only t)
  8432. newhead)
  8433. (org-with-remote-undo buffer
  8434. (with-current-buffer buffer
  8435. (widen)
  8436. (goto-char pos)
  8437. (save-excursion
  8438. (org-show-context 'agenda))
  8439. (save-excursion
  8440. (and (outline-next-heading)
  8441. (org-flag-heading nil))) ; show the next heading
  8442. (goto-char pos)
  8443. (call-interactively 'org-set-effort)
  8444. (end-of-line 1)
  8445. (setq newhead (org-get-heading)))
  8446. (org-agenda-change-all-lines newhead hdmarker))))
  8447. (defun org-agenda-toggle-archive-tag ()
  8448. "Toggle the archive tag for the current entry."
  8449. (interactive)
  8450. (org-agenda-check-no-diary)
  8451. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8452. (org-agenda-error)))
  8453. (buffer (marker-buffer hdmarker))
  8454. (pos (marker-position hdmarker))
  8455. (inhibit-read-only t)
  8456. newhead)
  8457. (org-with-remote-undo buffer
  8458. (with-current-buffer buffer
  8459. (widen)
  8460. (goto-char pos)
  8461. (org-show-context 'agenda)
  8462. (save-excursion
  8463. (and (outline-next-heading)
  8464. (org-flag-heading nil))) ; show the next heading
  8465. (call-interactively 'org-toggle-archive-tag)
  8466. (end-of-line 1)
  8467. (setq newhead (org-get-heading)))
  8468. (org-agenda-change-all-lines newhead hdmarker)
  8469. (beginning-of-line 1))))
  8470. (defun org-agenda-do-date-later (arg)
  8471. (interactive "P")
  8472. (cond
  8473. ((or (equal arg '(16))
  8474. (memq last-command
  8475. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8476. (setq this-command 'org-agenda-date-later-minutes)
  8477. (org-agenda-date-later-minutes 1))
  8478. ((or (equal arg '(4))
  8479. (memq last-command
  8480. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8481. (setq this-command 'org-agenda-date-later-hours)
  8482. (org-agenda-date-later-hours 1))
  8483. (t
  8484. (org-agenda-date-later (prefix-numeric-value arg)))))
  8485. (defun org-agenda-do-date-earlier (arg)
  8486. (interactive "P")
  8487. (cond
  8488. ((or (equal arg '(16))
  8489. (memq last-command
  8490. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8491. (setq this-command 'org-agenda-date-earlier-minutes)
  8492. (org-agenda-date-earlier-minutes 1))
  8493. ((or (equal arg '(4))
  8494. (memq last-command
  8495. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8496. (setq this-command 'org-agenda-date-earlier-hours)
  8497. (org-agenda-date-earlier-hours 1))
  8498. (t
  8499. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8500. (defun org-agenda-date-later (arg &optional what)
  8501. "Change the date of this item to ARG day(s) later."
  8502. (interactive "p")
  8503. (org-agenda-check-type t 'agenda 'timeline)
  8504. (org-agenda-check-no-diary)
  8505. (let* ((marker (or (org-get-at-bol 'org-marker)
  8506. (org-agenda-error)))
  8507. (buffer (marker-buffer marker))
  8508. (pos (marker-position marker))
  8509. cdate today)
  8510. (org-with-remote-undo buffer
  8511. (with-current-buffer buffer
  8512. (widen)
  8513. (goto-char pos)
  8514. (if (not (org-at-timestamp-p))
  8515. (error "Cannot find time stamp"))
  8516. (when (and org-agenda-move-date-from-past-immediately-to-today
  8517. (equal arg 1)
  8518. (or (not what) (eq what 'day))
  8519. (not (save-match-data (org-at-date-range-p))))
  8520. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8521. cdate (calendar-absolute-from-gregorian
  8522. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8523. today (org-today))
  8524. (if (> today cdate)
  8525. ;; immediately shift to today
  8526. (setq arg (- today cdate))))
  8527. (org-timestamp-change arg (or what 'day))
  8528. (when (and (org-at-date-range-p)
  8529. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8530. (let ((end org-last-changed-timestamp))
  8531. (org-timestamp-change arg (or what 'day))
  8532. (setq org-last-changed-timestamp
  8533. (concat org-last-changed-timestamp "--" end)))))
  8534. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8535. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8536. (defun org-agenda-date-earlier (arg &optional what)
  8537. "Change the date of this item to ARG day(s) earlier."
  8538. (interactive "p")
  8539. (org-agenda-date-later (- arg) what))
  8540. (defun org-agenda-date-later-minutes (arg)
  8541. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8542. (interactive "p")
  8543. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8544. (org-agenda-date-later arg 'minute))
  8545. (defun org-agenda-date-earlier-minutes (arg)
  8546. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8547. (interactive "p")
  8548. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8549. (org-agenda-date-earlier arg 'minute))
  8550. (defun org-agenda-date-later-hours (arg)
  8551. "Change the time of this item, in hour steps."
  8552. (interactive "p")
  8553. (org-agenda-date-later arg 'hour))
  8554. (defun org-agenda-date-earlier-hours (arg)
  8555. "Change the time of this item, in hour steps."
  8556. (interactive "p")
  8557. (org-agenda-date-earlier arg 'hour))
  8558. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8559. "Show new date stamp via text properties."
  8560. ;; We use text properties to make this undoable
  8561. (let ((inhibit-read-only t))
  8562. (setq stamp (concat prefix " => " stamp " "))
  8563. (save-excursion
  8564. (goto-char (point-max))
  8565. (while (not (bobp))
  8566. (when (equal marker (org-get-at-bol 'org-marker))
  8567. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8568. (org-move-to-column (- (window-width) (length stamp)) t)
  8569. (org-agenda-fix-tags-filter-overlays-at (point))
  8570. (if (featurep 'xemacs)
  8571. ;; Use `duplicable' property to trigger undo recording
  8572. (let ((ex (make-extent nil nil))
  8573. (gl (make-glyph stamp)))
  8574. (set-glyph-face gl 'secondary-selection)
  8575. (set-extent-properties
  8576. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8577. (insert-extent ex (1- (point)) (point-at-eol)))
  8578. (add-text-properties
  8579. (1- (point)) (point-at-eol)
  8580. (list 'display (org-add-props stamp nil
  8581. 'face 'secondary-selection))))
  8582. (beginning-of-line 1))
  8583. (beginning-of-line 0)))))
  8584. (defun org-agenda-date-prompt (arg)
  8585. "Change the date of this item. Date is prompted for, with default today.
  8586. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8587. be used to request time specification in the time stamp."
  8588. (interactive "P")
  8589. (org-agenda-check-type t 'agenda 'timeline)
  8590. (org-agenda-check-no-diary)
  8591. (let* ((marker (or (org-get-at-bol 'org-marker)
  8592. (org-agenda-error)))
  8593. (buffer (marker-buffer marker))
  8594. (pos (marker-position marker)))
  8595. (org-with-remote-undo buffer
  8596. (with-current-buffer buffer
  8597. (widen)
  8598. (goto-char pos)
  8599. (if (not (org-at-timestamp-p t))
  8600. (error "Cannot find time stamp"))
  8601. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8602. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8603. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8604. (defun org-agenda-schedule (arg &optional time)
  8605. "Schedule the item at point.
  8606. ARG is passed through to `org-schedule'."
  8607. (interactive "P")
  8608. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8609. (org-agenda-check-no-diary)
  8610. (let* ((marker (or (org-get-at-bol 'org-marker)
  8611. (org-agenda-error)))
  8612. (type (marker-insertion-type marker))
  8613. (buffer (marker-buffer marker))
  8614. (pos (marker-position marker))
  8615. (org-insert-labeled-timestamps-at-point nil)
  8616. ts)
  8617. (set-marker-insertion-type marker t)
  8618. (org-with-remote-undo buffer
  8619. (with-current-buffer buffer
  8620. (widen)
  8621. (goto-char pos)
  8622. (setq ts (org-schedule arg time)))
  8623. (org-agenda-show-new-time marker ts " S"))
  8624. (message "%s" ts)))
  8625. (defun org-agenda-deadline (arg &optional time)
  8626. "Schedule the item at point.
  8627. ARG is passed through to `org-deadline'."
  8628. (interactive "P")
  8629. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8630. (org-agenda-check-no-diary)
  8631. (let* ((marker (or (org-get-at-bol 'org-marker)
  8632. (org-agenda-error)))
  8633. (buffer (marker-buffer marker))
  8634. (pos (marker-position marker))
  8635. (org-insert-labeled-timestamps-at-point nil)
  8636. ts)
  8637. (org-with-remote-undo buffer
  8638. (with-current-buffer buffer
  8639. (widen)
  8640. (goto-char pos)
  8641. (setq ts (org-deadline arg time)))
  8642. (org-agenda-show-new-time marker ts " D"))
  8643. (message "%s" ts)))
  8644. (defun org-agenda-clock-in (&optional arg)
  8645. "Start the clock on the currently selected item."
  8646. (interactive "P")
  8647. (org-agenda-check-no-diary)
  8648. (if (equal arg '(4))
  8649. (org-clock-in arg)
  8650. (let* ((marker (or (org-get-at-bol 'org-marker)
  8651. (org-agenda-error)))
  8652. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8653. (pos (marker-position marker))
  8654. (col (current-column))
  8655. newhead)
  8656. (org-with-remote-undo (marker-buffer marker)
  8657. (with-current-buffer (marker-buffer marker)
  8658. (widen)
  8659. (goto-char pos)
  8660. (org-show-context 'agenda)
  8661. (org-show-entry)
  8662. (org-cycle-hide-drawers 'children)
  8663. (org-clock-in arg)
  8664. (setq newhead (org-get-heading)))
  8665. (org-agenda-change-all-lines newhead hdmarker))
  8666. (org-move-to-column col))))
  8667. (defun org-agenda-clock-out ()
  8668. "Stop the currently running clock."
  8669. (interactive)
  8670. (unless (marker-buffer org-clock-marker)
  8671. (error "No running clock"))
  8672. (let ((marker (make-marker)) (col (current-column)) newhead)
  8673. (org-with-remote-undo (marker-buffer org-clock-marker)
  8674. (with-current-buffer (marker-buffer org-clock-marker)
  8675. (save-excursion
  8676. (save-restriction
  8677. (widen)
  8678. (goto-char org-clock-marker)
  8679. (org-back-to-heading t)
  8680. (move-marker marker (point))
  8681. (org-clock-out)
  8682. (setq newhead (org-get-heading))))))
  8683. (org-agenda-change-all-lines newhead marker)
  8684. (move-marker marker nil)
  8685. (org-move-to-column col)
  8686. (org-agenda-unmark-clocking-task)))
  8687. (defun org-agenda-clock-cancel (&optional arg)
  8688. "Cancel the currently running clock."
  8689. (interactive "P")
  8690. (unless (marker-buffer org-clock-marker)
  8691. (user-error "No running clock"))
  8692. (org-with-remote-undo (marker-buffer org-clock-marker)
  8693. (org-clock-cancel)))
  8694. (defun org-agenda-clock-goto ()
  8695. "Jump to the currently clocked in task within the agenda.
  8696. If the currently clocked in task is not listed in the agenda
  8697. buffer, display it in another window."
  8698. (interactive)
  8699. (let (pos)
  8700. (mapc (lambda (o)
  8701. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8702. (setq pos (overlay-start o))))
  8703. (overlays-in (point-min) (point-max)))
  8704. (cond (pos (goto-char pos))
  8705. ;; If the currently clocked entry is not in the agenda
  8706. ;; buffer, we visit it in another window:
  8707. (org-clock-current-task
  8708. (org-switch-to-buffer-other-window (org-clock-goto)))
  8709. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8710. (defun org-agenda-diary-entry-in-org-file ()
  8711. "Make a diary entry in the file `org-agenda-diary-file'."
  8712. (let (d1 d2 char (text "") dp1 dp2)
  8713. (if (equal (buffer-name) "*Calendar*")
  8714. (setq d1 (calendar-cursor-to-date t)
  8715. d2 (car calendar-mark-ring))
  8716. (setq dp1 (get-text-property (point-at-bol) 'day))
  8717. (unless dp1 (user-error "No date defined in current line"))
  8718. (setq d1 (calendar-gregorian-from-absolute dp1)
  8719. d2 (and (ignore-errors (mark))
  8720. (save-excursion
  8721. (goto-char (mark))
  8722. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8723. (calendar-gregorian-from-absolute dp2))))
  8724. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8725. (setq char (read-char-exclusive))
  8726. (cond
  8727. ((equal char ?d)
  8728. (setq text (read-string "Day entry: "))
  8729. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8730. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8731. ((equal char ?a)
  8732. (setq d1 (list (car d1) (nth 1 d1)
  8733. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8734. (nth 2 d1))))
  8735. (setq text (read-string "Anniversary (use %d to show years): "))
  8736. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8737. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8738. ((equal char ?b)
  8739. (setq text (read-string "Block entry: "))
  8740. (unless (and d1 d2 (not (equal d1 d2)))
  8741. (user-error "No block of days selected"))
  8742. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8743. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8744. ((equal char ?j)
  8745. (org-switch-to-buffer-other-window
  8746. (find-file-noselect org-agenda-diary-file))
  8747. (require 'org-datetree)
  8748. (org-datetree-find-date-create d1)
  8749. (org-reveal t))
  8750. (t (user-error "Invalid selection character `%c'" char)))))
  8751. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8752. "Where in `org-agenda-diary-file' should new entries be added?
  8753. Valid values:
  8754. date-tree in the date tree, as child of the date
  8755. top-level as top-level entries at the end of the file."
  8756. :group 'org-agenda
  8757. :type '(choice
  8758. (const :tag "in a date tree" date-tree)
  8759. (const :tag "as top level at end of file" top-level)))
  8760. (defcustom org-agenda-insert-diary-extract-time nil
  8761. "Non-nil means extract any time specification from the diary entry."
  8762. :group 'org-agenda
  8763. :version "24.1"
  8764. :type 'boolean)
  8765. (defcustom org-agenda-bulk-mark-char ">"
  8766. "A single-character string to be used as the bulk mark."
  8767. :group 'org-agenda
  8768. :version "24.1"
  8769. :type 'string)
  8770. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8771. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8772. If TEXT is not empty, it will become the headline of the new entry, and
  8773. the resulting entry will not be shown. When TEXT is empty, switch to
  8774. `org-agenda-diary-file' and let the user finish the entry there."
  8775. (let ((cw (current-window-configuration)))
  8776. (org-switch-to-buffer-other-window
  8777. (find-file-noselect org-agenda-diary-file))
  8778. (widen)
  8779. (goto-char (point-min))
  8780. (cond
  8781. ((eq type 'anniversary)
  8782. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8783. (progn
  8784. (or (org-at-heading-p t)
  8785. (progn
  8786. (outline-next-heading)
  8787. (insert "* Anniversaries\n\n")
  8788. (beginning-of-line -1)))))
  8789. (outline-next-heading)
  8790. (org-back-over-empty-lines)
  8791. (backward-char 1)
  8792. (insert "\n")
  8793. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8794. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8795. ((eq type 'day)
  8796. (let ((org-prefix-has-time t)
  8797. (org-agenda-time-leading-zero t)
  8798. fmt time time2)
  8799. (if org-agenda-insert-diary-extract-time
  8800. ;; Use org-agenda-format-item to parse text for a time-range and
  8801. ;; remove it. FIXME: This is a hack, we should refactor
  8802. ;; that function to make time extraction available separately
  8803. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8804. time (get-text-property 0 'time fmt)
  8805. time2 (if (> (length time) 0)
  8806. ;; split-string removes trailing ...... if
  8807. ;; no end time given. First space
  8808. ;; separates time from date.
  8809. (concat " " (car (split-string time "\\.")))
  8810. nil)
  8811. text (get-text-property 0 'txt fmt)))
  8812. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8813. (org-agenda-insert-diary-as-top-level text)
  8814. (require 'org-datetree)
  8815. (org-datetree-find-date-create d1)
  8816. (org-agenda-insert-diary-make-new-entry text))
  8817. (org-insert-time-stamp (org-time-from-absolute
  8818. (calendar-absolute-from-gregorian d1))
  8819. nil nil nil nil time2))
  8820. (end-of-line 0))
  8821. ((eq type 'block)
  8822. (if (> (calendar-absolute-from-gregorian d1)
  8823. (calendar-absolute-from-gregorian d2))
  8824. (setq d1 (prog1 d2 (setq d2 d1))))
  8825. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8826. (org-agenda-insert-diary-as-top-level text)
  8827. (require 'org-datetree)
  8828. (org-datetree-find-date-create d1)
  8829. (org-agenda-insert-diary-make-new-entry text))
  8830. (org-insert-time-stamp (org-time-from-absolute
  8831. (calendar-absolute-from-gregorian d1)))
  8832. (insert "--")
  8833. (org-insert-time-stamp (org-time-from-absolute
  8834. (calendar-absolute-from-gregorian d2)))
  8835. (end-of-line 0)))
  8836. (if (string-match "\\S-" text)
  8837. (progn
  8838. (set-window-configuration cw)
  8839. (message "%s entry added to %s"
  8840. (capitalize (symbol-name type))
  8841. (abbreviate-file-name org-agenda-diary-file)))
  8842. (org-reveal t)
  8843. (message "Please finish entry here"))))
  8844. (defun org-agenda-insert-diary-as-top-level (text)
  8845. "Make new entry as a top-level entry at the end of the file.
  8846. Add TEXT as headline, and position the cursor in the second line so that
  8847. a timestamp can be added there."
  8848. (widen)
  8849. (goto-char (point-max))
  8850. (or (bolp) (insert "\n"))
  8851. (insert "* " text "\n")
  8852. (if org-adapt-indentation (org-indent-to-column 2)))
  8853. (defun org-agenda-insert-diary-make-new-entry (text)
  8854. "Make new entry as last child of current entry.
  8855. Add TEXT as headline, and position the cursor in the second line so that
  8856. a timestamp can be added there."
  8857. (let ((org-show-following-heading t)
  8858. (org-show-siblings t)
  8859. (org-show-hierarchy-above t)
  8860. (org-show-entry-below t)
  8861. col)
  8862. (outline-next-heading)
  8863. (org-back-over-empty-lines)
  8864. (or (looking-at "[ \t]*$")
  8865. (progn (insert "\n") (backward-char 1)))
  8866. (org-insert-heading nil t)
  8867. (org-do-demote)
  8868. (setq col (current-column))
  8869. (insert text "\n")
  8870. (if org-adapt-indentation (org-indent-to-column col))
  8871. (let ((org-show-following-heading t)
  8872. (org-show-siblings t)
  8873. (org-show-hierarchy-above t)
  8874. (org-show-entry-below t))
  8875. (org-show-context))))
  8876. (defun org-agenda-diary-entry ()
  8877. "Make a diary entry, like the `i' command from the calendar.
  8878. All the standard commands work: block, weekly etc.
  8879. When `org-agenda-diary-file' points to a file,
  8880. `org-agenda-diary-entry-in-org-file' is called instead to create
  8881. entries in that Org-mode file."
  8882. (interactive)
  8883. (if (not (eq org-agenda-diary-file 'diary-file))
  8884. (org-agenda-diary-entry-in-org-file)
  8885. (require 'diary-lib)
  8886. (let* ((char (progn
  8887. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8888. (read-char-exclusive)))
  8889. (cmd (cdr (assoc char
  8890. '((?d . insert-diary-entry)
  8891. (?w . insert-weekly-diary-entry)
  8892. (?m . insert-monthly-diary-entry)
  8893. (?y . insert-yearly-diary-entry)
  8894. (?a . insert-anniversary-diary-entry)
  8895. (?b . insert-block-diary-entry)
  8896. (?c . insert-cyclic-diary-entry)))))
  8897. (oldf (symbol-function 'calendar-cursor-to-date))
  8898. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8899. (point (point))
  8900. (mark (or (mark t) (point))))
  8901. (unless cmd
  8902. (user-error "No command associated with <%c>" char))
  8903. (unless (and (get-text-property point 'day)
  8904. (or (not (equal ?b char))
  8905. (get-text-property mark 'day)))
  8906. (user-error "Don't know which date to use for diary entry"))
  8907. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8908. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8909. (let ((calendar-mark-ring
  8910. (list (calendar-gregorian-from-absolute
  8911. (or (get-text-property mark 'day)
  8912. (get-text-property point 'day))))))
  8913. (unwind-protect
  8914. (progn
  8915. (fset 'calendar-cursor-to-date
  8916. (lambda (&optional error dummy)
  8917. (calendar-gregorian-from-absolute
  8918. (get-text-property point 'day))))
  8919. (call-interactively cmd))
  8920. (fset 'calendar-cursor-to-date oldf))))))
  8921. (defun org-agenda-execute-calendar-command (cmd)
  8922. "Execute a calendar command from the agenda with date from cursor."
  8923. (org-agenda-check-type t 'agenda 'timeline)
  8924. (require 'diary-lib)
  8925. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8926. (user-error "Don't know which date to use for the calendar command"))
  8927. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8928. (point (point))
  8929. (date (calendar-gregorian-from-absolute
  8930. (get-text-property point 'day)))
  8931. ;; the following 2 vars are needed in the calendar
  8932. (displayed-month (car date))
  8933. (displayed-year (nth 2 date)))
  8934. (unwind-protect
  8935. (progn
  8936. (fset 'calendar-cursor-to-date
  8937. (lambda (&optional error dummy)
  8938. (calendar-gregorian-from-absolute
  8939. (get-text-property point 'day))))
  8940. (call-interactively cmd))
  8941. (fset 'calendar-cursor-to-date oldf))))
  8942. (defun org-agenda-phases-of-moon ()
  8943. "Display the phases of the moon for the 3 months around the cursor date."
  8944. (interactive)
  8945. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8946. (defun org-agenda-holidays ()
  8947. "Display the holidays for the 3 months around the cursor date."
  8948. (interactive)
  8949. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8950. (defvar calendar-longitude) ; defined in calendar.el
  8951. (defvar calendar-latitude) ; defined in calendar.el
  8952. (defvar calendar-location-name) ; defined in calendar.el
  8953. (defun org-agenda-sunrise-sunset (arg)
  8954. "Display sunrise and sunset for the cursor date.
  8955. Latitude and longitude can be specified with the variables
  8956. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8957. argument, latitude and longitude will be prompted for."
  8958. (interactive "P")
  8959. (require 'solar)
  8960. (let ((calendar-longitude (if arg nil calendar-longitude))
  8961. (calendar-latitude (if arg nil calendar-latitude))
  8962. (calendar-location-name
  8963. (if arg "the given coordinates" calendar-location-name)))
  8964. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8965. (defun org-agenda-goto-calendar ()
  8966. "Open the Emacs calendar with the date at the cursor."
  8967. (interactive)
  8968. (org-agenda-check-type t 'agenda 'timeline)
  8969. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8970. (user-error "Don't know which date to open in calendar")))
  8971. (date (calendar-gregorian-from-absolute day))
  8972. (calendar-move-hook nil)
  8973. (calendar-view-holidays-initially-flag nil)
  8974. (calendar-view-diary-initially-flag nil))
  8975. (calendar)
  8976. (calendar-goto-date date)))
  8977. ;;;###autoload
  8978. (defun org-calendar-goto-agenda ()
  8979. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8980. This is a command that has to be installed in `calendar-mode-map'."
  8981. (interactive)
  8982. (org-agenda-list nil (calendar-absolute-from-gregorian
  8983. (calendar-cursor-to-date))
  8984. nil))
  8985. (defun org-agenda-convert-date ()
  8986. (interactive)
  8987. (org-agenda-check-type t 'agenda 'timeline)
  8988. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8989. date s)
  8990. (unless day
  8991. (user-error "Don't know which date to convert"))
  8992. (setq date (calendar-gregorian-from-absolute day))
  8993. (setq s (concat
  8994. "Gregorian: " (calendar-date-string date) "\n"
  8995. "ISO: " (calendar-iso-date-string date) "\n"
  8996. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8997. "Julian: " (calendar-julian-date-string date) "\n"
  8998. "Astron. JD: " (calendar-astro-date-string date)
  8999. " (Julian date number at noon UTC)\n"
  9000. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  9001. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  9002. "French: " (calendar-french-date-string date) "\n"
  9003. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  9004. "Mayan: " (calendar-mayan-date-string date) "\n"
  9005. "Coptic: " (calendar-coptic-date-string date) "\n"
  9006. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  9007. "Persian: " (calendar-persian-date-string date) "\n"
  9008. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9009. (with-output-to-temp-buffer "*Dates*"
  9010. (princ s))
  9011. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9012. ;;; Bulk commands
  9013. (defun org-agenda-bulk-marked-p ()
  9014. (eq (get-char-property (point-at-bol) 'type)
  9015. 'org-marked-entry-overlay))
  9016. (defun org-agenda-bulk-mark (&optional arg)
  9017. "Mark the entry at point for future bulk action."
  9018. (interactive "p")
  9019. (dotimes (i (or arg 1))
  9020. (unless (org-get-at-bol 'org-agenda-diary-link)
  9021. (let* ((m (org-get-at-bol 'org-hd-marker))
  9022. ov)
  9023. (unless (org-agenda-bulk-marked-p)
  9024. (unless m (user-error "Nothing to mark at point"))
  9025. (push m org-agenda-bulk-marked-entries)
  9026. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9027. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9028. (org-get-todo-face "TODO")
  9029. 'evaporate)
  9030. (overlay-put ov 'type 'org-marked-entry-overlay))
  9031. (end-of-line 1)
  9032. (or (ignore-errors
  9033. (goto-char (next-single-property-change (point) 'txt)))
  9034. (beginning-of-line 2))
  9035. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9036. (beginning-of-line 2))
  9037. (message "%d entries marked for bulk action"
  9038. (length org-agenda-bulk-marked-entries))))))
  9039. (defun org-agenda-bulk-mark-all ()
  9040. "Mark all entries for future agenda bulk action."
  9041. (interactive)
  9042. (org-agenda-bulk-mark-regexp "."))
  9043. (defun org-agenda-bulk-mark-regexp (regexp)
  9044. "Mark entries matching REGEXP for future agenda bulk action."
  9045. (interactive "sMark entries matching regexp: ")
  9046. (let ((entries-marked 0) txt-at-point)
  9047. (save-excursion
  9048. (goto-char (point-min))
  9049. (goto-char (next-single-property-change (point) 'txt))
  9050. (while (and (re-search-forward regexp nil t)
  9051. (setq txt-at-point (get-text-property (point) 'txt)))
  9052. (when (string-match regexp txt-at-point)
  9053. (setq entries-marked (1+ entries-marked))
  9054. (call-interactively 'org-agenda-bulk-mark))))
  9055. (if (not entries-marked)
  9056. (message "No entry matching this regexp."))))
  9057. (defun org-agenda-bulk-unmark (&optional arg)
  9058. "Unmark the entry at point for future bulk action."
  9059. (interactive "P")
  9060. (if arg
  9061. (org-agenda-bulk-unmark-all)
  9062. (cond ((org-agenda-bulk-marked-p)
  9063. (org-agenda-bulk-remove-overlays
  9064. (point-at-bol) (+ 2 (point-at-bol)))
  9065. (setq org-agenda-bulk-marked-entries
  9066. (delete (org-get-at-bol 'org-hd-marker)
  9067. org-agenda-bulk-marked-entries))
  9068. (end-of-line 1)
  9069. (or (ignore-errors
  9070. (goto-char (next-single-property-change (point) 'txt)))
  9071. (beginning-of-line 2))
  9072. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9073. (beginning-of-line 2))
  9074. (message "%d entries left marked for bulk action"
  9075. (length org-agenda-bulk-marked-entries)))
  9076. (t (message "No entry to unmark here")))))
  9077. (defun org-agenda-bulk-toggle-all ()
  9078. "Toggle all marks for bulk action."
  9079. (interactive)
  9080. (save-excursion
  9081. (goto-char (point-min))
  9082. (while (ignore-errors
  9083. (goto-char (next-single-property-change (point) 'txt)))
  9084. (org-agenda-bulk-toggle))))
  9085. (defun org-agenda-bulk-toggle ()
  9086. "Toggle the mark at point for bulk action."
  9087. (interactive)
  9088. (if (org-agenda-bulk-marked-p)
  9089. (org-agenda-bulk-unmark)
  9090. (org-agenda-bulk-mark)))
  9091. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9092. "Remove the mark overlays between BEG and END in the agenda buffer.
  9093. BEG and END default to the buffer limits.
  9094. This only removes the overlays, it does not remove the markers
  9095. from the list in `org-agenda-bulk-marked-entries'."
  9096. (interactive)
  9097. (mapc (lambda (ov)
  9098. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9099. (delete-overlay ov)))
  9100. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9101. (defun org-agenda-bulk-unmark-all ()
  9102. "Remove all marks in the agenda buffer.
  9103. This will remove the markers and the overlays."
  9104. (interactive)
  9105. (if (null org-agenda-bulk-marked-entries)
  9106. (message "No entry to unmark")
  9107. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9108. (setq org-agenda-bulk-marked-entries nil)
  9109. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9110. (defcustom org-agenda-persistent-marks nil
  9111. "Non-nil means marked items will stay marked after a bulk action.
  9112. You can toggle this interactively by typing `p' when prompted for a
  9113. bulk action."
  9114. :group 'org-agenda
  9115. :version "24.1"
  9116. :type 'boolean)
  9117. (defun org-agenda-bulk-action (&optional arg)
  9118. "Execute an remote-editing action on all marked entries.
  9119. The prefix arg is passed through to the command if possible."
  9120. (interactive "P")
  9121. ;; Make sure we have markers, and only valid ones
  9122. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9123. (mapc
  9124. (lambda (m)
  9125. (unless (and (markerp m)
  9126. (marker-buffer m)
  9127. (buffer-live-p (marker-buffer m))
  9128. (marker-position m))
  9129. (user-error "Marker %s for bulk command is invalid" m)))
  9130. org-agenda-bulk-marked-entries)
  9131. ;; Prompt for the bulk command
  9132. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9133. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9134. "[S]catter [f]unction "
  9135. (when org-agenda-bulk-custom-functions
  9136. (concat " Custom: ["
  9137. (mapconcat (lambda(f) (char-to-string (car f)))
  9138. org-agenda-bulk-custom-functions "")
  9139. "]"))))
  9140. (catch 'exit
  9141. (let* ((action (read-char-exclusive))
  9142. (org-log-refile (if org-log-refile 'time nil))
  9143. (entries (reverse org-agenda-bulk-marked-entries))
  9144. (org-overriding-default-time
  9145. (if (get-text-property (point) 'org-agenda-date-header)
  9146. (org-get-cursor-date)))
  9147. redo-at-end
  9148. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9149. (cond
  9150. ((equal action ?p)
  9151. (let ((org-agenda-persistent-marks
  9152. (not org-agenda-persistent-marks)))
  9153. (org-agenda-bulk-action)
  9154. (throw 'exit nil)))
  9155. ((equal action ?$)
  9156. (setq cmd '(org-agenda-archive)))
  9157. ((equal action ?A)
  9158. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9159. ((member action '(?r ?w))
  9160. (setq rfloc (org-refile-get-location
  9161. "Refile to"
  9162. (marker-buffer (car entries))
  9163. org-refile-allow-creating-parent-nodes))
  9164. (if (nth 3 rfloc)
  9165. (setcar (nthcdr 3 rfloc)
  9166. (move-marker (make-marker) (nth 3 rfloc)
  9167. (or (get-file-buffer (nth 1 rfloc))
  9168. (find-buffer-visiting (nth 1 rfloc))
  9169. (error "This should not happen")))))
  9170. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9171. redo-at-end t))
  9172. ((equal action ?t)
  9173. (setq state (org-icompleting-read
  9174. "Todo state: "
  9175. (with-current-buffer (marker-buffer (car entries))
  9176. (mapcar 'list org-todo-keywords-1))))
  9177. (setq cmd `(let ((org-inhibit-blocking t)
  9178. (org-inhibit-logging 'note))
  9179. (org-agenda-todo ,state))))
  9180. ((memq action '(?- ?+))
  9181. (setq tag (org-icompleting-read
  9182. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9183. (with-current-buffer (marker-buffer (car entries))
  9184. (delq nil
  9185. (mapcar (lambda (x)
  9186. (if (stringp (car x)) x)) org-tag-alist)))))
  9187. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9188. ((memq action '(?s ?d))
  9189. (let* ((time
  9190. (unless arg
  9191. (org-read-date
  9192. nil nil nil
  9193. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9194. org-overriding-default-time)))
  9195. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9196. (setq cmd `(eval '(,c1 arg ,time)))))
  9197. ((equal action ?S)
  9198. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9199. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9200. (let ((days (read-number
  9201. (format "Scatter tasks across how many %sdays: "
  9202. (if arg "week" "")) 7)))
  9203. (setq cmd
  9204. `(let ((distance (1+ (random ,days))))
  9205. (if arg
  9206. (let ((dist distance)
  9207. (day-of-week
  9208. (calendar-day-of-week
  9209. (calendar-gregorian-from-absolute (org-today)))))
  9210. (dotimes (i (1+ dist))
  9211. (while (member day-of-week org-agenda-weekend-days)
  9212. (incf distance)
  9213. (incf day-of-week)
  9214. (if (= day-of-week 7)
  9215. (setq day-of-week 0)))
  9216. (incf day-of-week)
  9217. (if (= day-of-week 7)
  9218. (setq day-of-week 0)))))
  9219. ;; silently fail when try to replan a sexp entry
  9220. (condition-case nil
  9221. (let* ((date (calendar-gregorian-from-absolute
  9222. (+ (org-today) distance)))
  9223. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9224. (nth 2 date))))
  9225. (org-agenda-schedule nil time))
  9226. (error nil)))))))
  9227. ((assoc action org-agenda-bulk-custom-functions)
  9228. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9229. redo-at-end t))
  9230. ((equal action ?f)
  9231. (setq cmd (list (intern
  9232. (org-icompleting-read "Function: "
  9233. obarray 'fboundp t nil nil)))))
  9234. (t (user-error "Invalid bulk action")))
  9235. ;; Sort the markers, to make sure that parents are handled before children
  9236. (setq entries (sort entries
  9237. (lambda (a b)
  9238. (cond
  9239. ((equal (marker-buffer a) (marker-buffer b))
  9240. (< (marker-position a) (marker-position b)))
  9241. (t
  9242. (string< (buffer-name (marker-buffer a))
  9243. (buffer-name (marker-buffer b))))))))
  9244. ;; Now loop over all markers and apply cmd
  9245. (while (setq e (pop entries))
  9246. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9247. (if (not pos)
  9248. (progn (message "Skipping removed entry at %s" e)
  9249. (setq cntskip (1+ cntskip)))
  9250. (goto-char pos)
  9251. (let (org-loop-over-headlines-in-active-region)
  9252. (eval cmd))
  9253. (setq cnt (1+ cnt))))
  9254. (when redo-at-end (org-agenda-redo))
  9255. (unless org-agenda-persistent-marks
  9256. (org-agenda-bulk-unmark-all))
  9257. (message "Acted on %d entries%s%s"
  9258. cnt
  9259. (if (= cntskip 0)
  9260. ""
  9261. (format ", skipped %d (disappeared before their turn)"
  9262. cntskip))
  9263. (if (not org-agenda-persistent-marks)
  9264. "" " (kept marked)"))))))
  9265. (defun org-agenda-capture (&optional with-time)
  9266. "Call `org-capture' with the date at point.
  9267. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9268. current HH:MM time."
  9269. (interactive "P")
  9270. (if (not (eq major-mode 'org-agenda-mode))
  9271. (user-error "You cannot do this outside of agenda buffers")
  9272. (let ((org-overriding-default-time
  9273. (org-get-cursor-date (equal with-time 1))))
  9274. (call-interactively 'org-capture))))
  9275. ;;; Dragging agenda lines forward/backward
  9276. (defun org-agenda-reapply-filters ()
  9277. "Re-apply all agenda filters."
  9278. (mapcar
  9279. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f))))
  9280. `((,org-agenda-tag-filter tag)
  9281. (,org-agenda-category-filter category)
  9282. (,org-agenda-regexp-filter regexp)
  9283. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9284. (,(get 'org-agenda-category-filter :preset-filter) category)
  9285. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9286. (defun org-agenda-drag-line-forward (arg &optional backward)
  9287. "Drag an agenda line forward by ARG lines.
  9288. When the optional argument `backward' is non-nil, move backward."
  9289. (interactive "p")
  9290. (let ((inhibit-read-only t) lst line)
  9291. (if (or (not (get-text-property (point) 'txt))
  9292. (save-excursion
  9293. (dotimes (n arg)
  9294. (move-beginning-of-line (if backward 0 2))
  9295. (push (not (get-text-property (point) 'txt)) lst))
  9296. (delq nil lst)))
  9297. (message "Cannot move line forward")
  9298. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9299. (move-beginning-of-line 1)
  9300. (setq line (buffer-substring (point) end))
  9301. (delete-region (point) end)
  9302. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9303. (insert line)
  9304. (org-agenda-reapply-filters)
  9305. (org-agenda-mark-clocking-task)
  9306. (move-beginning-of-line 0)))))
  9307. (defun org-agenda-drag-line-backward (arg)
  9308. "Drag an agenda line backward by ARG lines."
  9309. (interactive "p")
  9310. (org-agenda-drag-line-forward arg t))
  9311. ;;; Flagging notes
  9312. (defun org-agenda-show-the-flagging-note ()
  9313. "Display the flagging note in the other window.
  9314. When called a second time in direct sequence, offer to remove the FLAGGING
  9315. tag and (if present) the flagging note."
  9316. (interactive)
  9317. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9318. (win (selected-window))
  9319. note heading newhead)
  9320. (unless hdmarker
  9321. (user-error "No linked entry at point"))
  9322. (if (and (eq this-command last-command)
  9323. (y-or-n-p "Unflag and remove any flagging note? "))
  9324. (progn
  9325. (org-agenda-remove-flag hdmarker)
  9326. (let ((win (get-buffer-window "*Flagging Note*")))
  9327. (and win (delete-window win)))
  9328. (message "Entry unflagged"))
  9329. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9330. (unless note
  9331. (user-error "No flagging note"))
  9332. (org-kill-new note)
  9333. (org-switch-to-buffer-other-window "*Flagging Note*")
  9334. (erase-buffer)
  9335. (insert note)
  9336. (goto-char (point-min))
  9337. (while (re-search-forward "\\\\n" nil t)
  9338. (replace-match "\n" t t))
  9339. (goto-char (point-min))
  9340. (select-window win)
  9341. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9342. (defun org-agenda-remove-flag (marker)
  9343. "Remove the FLAGGED tag and any flagging note in the entry."
  9344. (let (newhead)
  9345. (org-with-point-at marker
  9346. (org-toggle-tag "FLAGGED" 'off)
  9347. (org-entry-delete nil "THEFLAGGINGNOTE")
  9348. (setq newhead (org-get-heading)))
  9349. (org-agenda-change-all-lines newhead marker)
  9350. (message "Entry unflagged")))
  9351. (defun org-agenda-get-any-marker (&optional pos)
  9352. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9353. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9354. ;;; Appointment reminders
  9355. (defvar appt-time-msg-list) ; defined in appt.el
  9356. ;;;###autoload
  9357. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9358. "Activate appointments found in `org-agenda-files'.
  9359. With a \\[universal-argument] prefix, refresh the list of
  9360. appointments.
  9361. If FILTER is t, interactively prompt the user for a regular
  9362. expression, and filter out entries that don't match it.
  9363. If FILTER is a string, use this string as a regular expression
  9364. for filtering entries out.
  9365. If FILTER is a function, filter out entries against which
  9366. calling the function returns nil. This function takes one
  9367. argument: an entry from `org-agenda-get-day-entries'.
  9368. FILTER can also be an alist with the car of each cell being
  9369. either 'headline or 'category. For example:
  9370. '((headline \"IMPORTANT\")
  9371. (category \"Work\"))
  9372. will only add headlines containing IMPORTANT or headlines
  9373. belonging to the \"Work\" category.
  9374. ARGS are symbols indicating what kind of entries to consider.
  9375. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9376. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9377. and :timestamp entries. See the docstring of `org-diary' for
  9378. details and examples.
  9379. If an entry has a APPT_WARNTIME property, its value will be used
  9380. to override `appt-message-warning-time'."
  9381. (interactive "P")
  9382. (if refresh (setq appt-time-msg-list nil))
  9383. (if (eq filter t)
  9384. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9385. (let* ((cnt 0) ; count added events
  9386. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9387. (org-agenda-new-buffers nil)
  9388. (org-deadline-warning-days 0)
  9389. ;; Do not use `org-today' here because appt only takes
  9390. ;; time and without date as argument, so it may pass wrong
  9391. ;; information otherwise
  9392. (today (org-date-to-gregorian
  9393. (time-to-days (current-time))))
  9394. (org-agenda-restrict nil)
  9395. (files (org-agenda-files 'unrestricted)) entries file
  9396. (org-agenda-buffer nil))
  9397. ;; Get all entries which may contain an appt
  9398. (org-agenda-prepare-buffers files)
  9399. (while (setq file (pop files))
  9400. (setq entries
  9401. (delq nil
  9402. (append entries
  9403. (apply 'org-agenda-get-day-entries
  9404. file today scope)))))
  9405. ;; Map thru entries and find if we should filter them out
  9406. (mapc
  9407. (lambda(x)
  9408. (let* ((evt (org-trim
  9409. (replace-regexp-in-string
  9410. org-bracket-link-regexp "\\3"
  9411. (or (get-text-property 1 'txt x) ""))))
  9412. (cat (get-text-property 1 'org-category x))
  9413. (tod (get-text-property 1 'time-of-day x))
  9414. (ok (or (null filter)
  9415. (and (stringp filter) (string-match filter evt))
  9416. (and (functionp filter) (funcall filter x))
  9417. (and (listp filter)
  9418. (let ((cat-filter (cadr (assoc 'category filter)))
  9419. (evt-filter (cadr (assoc 'headline filter))))
  9420. (or (and (stringp cat-filter)
  9421. (string-match cat-filter cat))
  9422. (and (stringp evt-filter)
  9423. (string-match evt-filter evt)))))))
  9424. (wrn (get-text-property 1 'warntime x)))
  9425. ;; FIXME: Shall we remove text-properties for the appt text?
  9426. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9427. (when (and ok tod)
  9428. (setq tod (concat "00" (number-to-string tod))
  9429. tod (when (string-match
  9430. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9431. (concat (match-string 1 tod) ":"
  9432. (match-string 2 tod))))
  9433. (if (version< emacs-version "23.3")
  9434. (appt-add tod evt)
  9435. (appt-add tod evt wrn))
  9436. (setq cnt (1+ cnt))))) entries)
  9437. (org-release-buffers org-agenda-new-buffers)
  9438. (if (eq cnt 0)
  9439. (message "No event to add")
  9440. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9441. (defun org-agenda-todayp (date)
  9442. "Does DATE mean today, when considering `org-extend-today-until'?"
  9443. (let ((today (org-today))
  9444. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9445. date)))
  9446. (eq date today)))
  9447. (defun org-agenda-todo-yesterday (&optional arg)
  9448. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9449. (interactive "P")
  9450. (let* ((hour (third (decode-time
  9451. (org-current-time))))
  9452. (org-extend-today-until (1+ hour)))
  9453. (org-agenda-todo arg)))
  9454. (provide 'org-agenda)
  9455. ;;; org-agenda.el ends here