org-agenda.el 390 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type '(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 general tags/property/todo match agenda view."
  588. :tag "Org Agenda Match 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 deadlined 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 dealine."
  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 nil
  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."
  1254. :group 'org-agenda-search-view
  1255. :version "24.4"
  1256. :package-version '(Org . "8.0")
  1257. :type 'integer)
  1258. (defgroup org-agenda-time-grid nil
  1259. "Options concerning the time grid in the Org-mode Agenda."
  1260. :tag "Org Agenda Time Grid"
  1261. :group 'org-agenda)
  1262. (defcustom org-agenda-search-headline-for-time t
  1263. "Non-nil means search headline for a time-of-day.
  1264. If the headline contains a time-of-day in one format or another, it will
  1265. be used to sort the entry into the time sequence of items for a day.
  1266. Some people have time stamps in the headline that refer to the creation
  1267. time or so, and then this produces an unwanted side effect. If this is
  1268. the case for your, use this variable to turn off searching the headline
  1269. for a time."
  1270. :group 'org-agenda-time-grid
  1271. :type 'boolean)
  1272. (defcustom org-agenda-use-time-grid t
  1273. "Non-nil means show a time grid in the agenda schedule.
  1274. A time grid is a set of lines for specific times (like every two hours between
  1275. 8:00 and 20:00). The items scheduled for a day at specific times are
  1276. sorted in between these lines.
  1277. For details about when the grid will be shown, and what it will look like, see
  1278. the variable `org-agenda-time-grid'."
  1279. :group 'org-agenda-time-grid
  1280. :type 'boolean)
  1281. (defcustom org-agenda-time-grid
  1282. '((daily today require-timed)
  1283. "----------------"
  1284. (800 1000 1200 1400 1600 1800 2000))
  1285. "The settings for time grid for agenda display.
  1286. This is a list of three items. The first item is again a list. It contains
  1287. symbols specifying conditions when the grid should be displayed:
  1288. daily if the agenda shows a single day
  1289. weekly if the agenda shows an entire week
  1290. today show grid on current date, independent of daily/weekly display
  1291. require-timed show grid only if at least one item has a time specification
  1292. The second item is a string which will be placed behind the grid time.
  1293. The third item is a list of integers, indicating the times that should have
  1294. a grid line."
  1295. :group 'org-agenda-time-grid
  1296. :type
  1297. '(list
  1298. (set :greedy t :tag "Grid Display Options"
  1299. (const :tag "Show grid in single day agenda display" daily)
  1300. (const :tag "Show grid in weekly agenda display" weekly)
  1301. (const :tag "Always show grid for today" today)
  1302. (const :tag "Show grid only if any timed entries are present"
  1303. require-timed)
  1304. (const :tag "Skip grid times already present in an entry"
  1305. remove-match))
  1306. (string :tag "Grid String")
  1307. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1308. (defcustom org-agenda-show-current-time-in-grid t
  1309. "Non-nil means show the current time in the time grid."
  1310. :group 'org-agenda-time-grid
  1311. :version "24.1"
  1312. :type 'boolean)
  1313. (defcustom org-agenda-current-time-string
  1314. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1315. "The string for the current time marker in the agenda."
  1316. :group 'org-agenda-time-grid
  1317. :version "24.1"
  1318. :type 'string)
  1319. (defgroup org-agenda-sorting nil
  1320. "Options concerning sorting in the Org-mode Agenda."
  1321. :tag "Org Agenda Sorting"
  1322. :group 'org-agenda)
  1323. (defcustom org-agenda-sorting-strategy
  1324. '((agenda habit-down time-up priority-down category-keep)
  1325. (todo priority-down category-keep)
  1326. (tags priority-down category-keep)
  1327. (search category-keep))
  1328. "Sorting structure for the agenda items of a single day.
  1329. This is a list of symbols which will be used in sequence to determine
  1330. if an entry should be listed before another entry. The following
  1331. symbols are recognized:
  1332. time-up Put entries with time-of-day indications first, early first
  1333. time-down Put entries with time-of-day indications first, late first
  1334. timestamp-up Sort by any timestamp, early first
  1335. timestamp-down Sort by any timestamp, late first
  1336. scheduled-up Sort by scheduled timestamp, early first
  1337. scheduled-down Sort by scheduled timestamp, late first
  1338. deadline-up Sort by deadline timestamp, early first
  1339. deadline-down Sort by deadline timestamp, late first
  1340. ts-up Sort by active timestamp, early first
  1341. ts-down Sort by active timestamp, late first
  1342. tsia-up Sort by inactive timestamp, early first
  1343. tsia-down Sort by inactive timestamp, late first
  1344. category-keep Keep the default order of categories, corresponding to the
  1345. sequence in `org-agenda-files'.
  1346. category-up Sort alphabetically by category, A-Z.
  1347. category-down Sort alphabetically by category, Z-A.
  1348. tag-up Sort alphabetically by last tag, A-Z.
  1349. tag-down Sort alphabetically by last tag, Z-A.
  1350. priority-up Sort numerically by priority, high priority last.
  1351. priority-down Sort numerically by priority, high priority first.
  1352. todo-state-up Sort by todo state, tasks that are done last.
  1353. todo-state-down Sort by todo state, tasks that are done first.
  1354. effort-up Sort numerically by estimated effort, high effort last.
  1355. effort-down Sort numerically by estimated effort, high effort first.
  1356. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1357. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1358. habit-up Put entries that are habits first
  1359. habit-down Put entries that are habits last
  1360. alpha-up Sort headlines alphabetically
  1361. alpha-down Sort headlines alphabetically, reversed
  1362. The different possibilities will be tried in sequence, and testing stops
  1363. if one comparison returns a \"not-equal\". For example, the default
  1364. '(time-up category-keep priority-down)
  1365. means: Pull out all entries having a specified time of day and sort them,
  1366. in order to make a time schedule for the current day the first thing in the
  1367. agenda listing for the day. Of the entries without a time indication, keep
  1368. the grouped in categories, don't sort the categories, but keep them in
  1369. the sequence given in `org-agenda-files'. Within each category sort by
  1370. priority.
  1371. Leaving out `category-keep' would mean that items will be sorted across
  1372. categories by priority.
  1373. Instead of a single list, this can also be a set of list for specific
  1374. contents, with a context symbol in the car of the list, any of
  1375. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1376. Custom commands can bind this variable in the options section."
  1377. :group 'org-agenda-sorting
  1378. :type `(choice
  1379. (repeat :tag "General" ,org-sorting-choice)
  1380. (list :tag "Individually"
  1381. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1382. (repeat ,org-sorting-choice))
  1383. (cons (const :tag "Strategy for TODO lists" todo)
  1384. (repeat ,org-sorting-choice))
  1385. (cons (const :tag "Strategy for Tags matches" tags)
  1386. (repeat ,org-sorting-choice))
  1387. (cons (const :tag "Strategy for search matches" search)
  1388. (repeat ,org-sorting-choice)))))
  1389. (defcustom org-agenda-cmp-user-defined nil
  1390. "A function to define the comparison `user-defined'.
  1391. This function must receive two arguments, agenda entry a and b.
  1392. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1393. the user comparison, return nil.
  1394. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1395. part of an agenda sorting strategy."
  1396. :group 'org-agenda-sorting
  1397. :type 'symbol)
  1398. (defcustom org-sort-agenda-notime-is-late t
  1399. "Non-nil means items without time are considered late.
  1400. This is only relevant for sorting. When t, items which have no explicit
  1401. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1402. do have a time. When nil, the default time is before 0:00. You can use this
  1403. option to decide if the schedule for today should come before or after timeless
  1404. agenda entries."
  1405. :group 'org-agenda-sorting
  1406. :type 'boolean)
  1407. (defcustom org-sort-agenda-noeffort-is-high t
  1408. "Non-nil means items without effort estimate are sorted as high effort.
  1409. This also applies when filtering an agenda view with respect to the
  1410. < or > effort operator. Then, tasks with no effort defined will be treated
  1411. as tasks with high effort.
  1412. When nil, such items are sorted as 0 minutes effort."
  1413. :group 'org-agenda-sorting
  1414. :type 'boolean)
  1415. (defgroup org-agenda-line-format nil
  1416. "Options concerning the entry prefix in the Org-mode agenda display."
  1417. :tag "Org Agenda Line Format"
  1418. :group 'org-agenda)
  1419. (defcustom org-agenda-prefix-format
  1420. '((agenda . " %i %-12:c%?-12t% s")
  1421. (timeline . " % s")
  1422. (todo . " %i %-12:c")
  1423. (tags . " %i %-12:c")
  1424. (search . " %i %-12:c"))
  1425. "Format specifications for the prefix of items in the agenda views.
  1426. An alist with five entries, each for the different agenda types. The
  1427. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1428. The values are format strings.
  1429. This format works similar to a printf format, with the following meaning:
  1430. %c the category of the item, \"Diary\" for entries from the diary,
  1431. or as given by the CATEGORY keyword or derived from the file name
  1432. %e the effort required by the item
  1433. %l the level of the item (insert X space(s) if item is of level X)
  1434. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1435. %T the last tag of the item (ignore inherited tags, which come first)
  1436. %t the HH:MM time-of-day specification if one applies to the entry
  1437. %s Scheduling/Deadline information, a short string
  1438. %b show breadcrumbs, i.e., the names of the higher levels
  1439. %(expression) Eval EXPRESSION and replace the control string
  1440. by the result
  1441. All specifiers work basically like the standard `%s' of printf, but may
  1442. contain two additional characters: a question mark just after the `%'
  1443. and a whitespace/punctuation character just before the final letter.
  1444. If the first character after `%' is a question mark, the entire field
  1445. will only be included if the corresponding value applies to the current
  1446. entry. This is useful for fields which should have fixed width when
  1447. present, but zero width when absent. For example, \"%?-12t\" will
  1448. result in a 12 character time field if a time of the day is specified,
  1449. but will completely disappear in entries which do not contain a time.
  1450. If there is punctuation or whitespace character just before the
  1451. final format letter, this character will be appended to the field
  1452. value if the value is not empty. For example, the format
  1453. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1454. the category is empty, no additional colon is inserted.
  1455. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1456. which means:
  1457. - Indent the line with two space characters
  1458. - Give the category a 12 chars wide field, padded with whitespace on
  1459. the right (because of `-'). Append a colon if there is a category
  1460. (because of `:').
  1461. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1462. time, don't put in an empty field, just skip it (because of '?').
  1463. - Finally, put the scheduling information.
  1464. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1465. `org-agenda-remove-tags'.
  1466. Custom commands can set this variable in the options section."
  1467. :type '(choice
  1468. (string :tag "General format")
  1469. (list :greedy t :tag "View dependent"
  1470. (cons (const agenda) (string :tag "Format"))
  1471. (cons (const timeline) (string :tag "Format"))
  1472. (cons (const todo) (string :tag "Format"))
  1473. (cons (const tags) (string :tag "Format"))
  1474. (cons (const search) (string :tag "Format"))))
  1475. :group 'org-agenda-line-format)
  1476. (defvar org-prefix-format-compiled nil
  1477. "The compiled prefix format and associated variables.
  1478. This is a list where first element is a list of variable bindings, and second
  1479. element is the compiled format expression. See the variable
  1480. `org-agenda-prefix-format'.")
  1481. (defcustom org-agenda-todo-keyword-format "%-1s"
  1482. "Format for the TODO keyword in agenda lines.
  1483. Set this to something like \"%-12s\" if you want all TODO keywords
  1484. to occupy a fixed space in the agenda display."
  1485. :group 'org-agenda-line-format
  1486. :type 'string)
  1487. (defcustom org-agenda-diary-sexp-prefix nil
  1488. "A regexp that matches part of a diary sexp entry
  1489. which should be treated as scheduling/deadline information in
  1490. `org-agenda'.
  1491. For example, you can use this to extract the `diary-remind-message' from
  1492. `diary-remind' entries."
  1493. :group 'org-agenda-line-format
  1494. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1495. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1496. "Text preceding timerange entries in the agenda view.
  1497. This is a list with two strings. The first applies when the range
  1498. is entirely on one day. The second applies if the range spans several days.
  1499. The strings may have two \"%d\" format specifiers which will be filled
  1500. with the sequence number of the days, and the total number of days in the
  1501. range, respectively."
  1502. :group 'org-agenda-line-format
  1503. :type '(list
  1504. (string :tag "Deadline today ")
  1505. (choice :tag "Deadline relative"
  1506. (string :tag "Format string")
  1507. (function))))
  1508. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1509. "Text preceding scheduled items in the agenda view.
  1510. This is a list with two strings. The first applies when the item is
  1511. scheduled on the current day. The second applies when it has been scheduled
  1512. previously, it may contain a %d indicating that this is the nth time that
  1513. this item is scheduled, due to automatic rescheduling of unfinished items
  1514. for the following day. So this number is one larger than the number of days
  1515. that passed since this item was scheduled first."
  1516. :group 'org-agenda-line-format
  1517. :version "24.4"
  1518. :package-version '(Org . "8.0")
  1519. :type '(list
  1520. (string :tag "Scheduled today ")
  1521. (string :tag "Scheduled previously")))
  1522. (defcustom org-agenda-inactive-leader "["
  1523. "Text preceding item pulled into the agenda by inactive time stamps.
  1524. These entries are added to the agenda when pressing \"[\"."
  1525. :group 'org-agenda-line-format
  1526. :version "24.1"
  1527. :type 'string)
  1528. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1529. "Text preceding deadline items in the agenda view.
  1530. This is a list with three strings. The first applies when the item has its
  1531. deadline on the current day. The second applies when the deadline is in the
  1532. future, the third one when it is in the past. The strings may contain %d
  1533. to capture the number of days."
  1534. :group 'org-agenda-line-format
  1535. :version "24.4"
  1536. :package-version '(Org . "8.0")
  1537. :type '(list
  1538. (string :tag "Deadline today ")
  1539. (choice :tag "Deadline relative"
  1540. (string :tag "Format string")
  1541. (function))))
  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. (use-local-map org-agenda-mode-map)
  1884. (easy-menu-add org-agenda-menu)
  1885. (if org-startup-truncated (setq truncate-lines t))
  1886. (org-set-local 'line-move-visual nil)
  1887. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1888. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1889. ;; Make sure properties are removed when copying text
  1890. (org-add-hook 'filter-buffer-substring-functions
  1891. (lambda (fun start end delete)
  1892. (substring-no-properties (funcall fun start end delete)))
  1893. nil t)
  1894. (unless org-agenda-keep-modes
  1895. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1896. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1897. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1898. org-agenda-show-log org-agenda-start-with-log-mode))
  1899. (easy-menu-change
  1900. '("Agenda") "Agenda Files"
  1901. (append
  1902. (list
  1903. (vector
  1904. (if (get 'org-agenda-files 'org-restrict)
  1905. "Restricted to single file"
  1906. "Edit File List")
  1907. '(org-edit-agenda-file-list)
  1908. (not (get 'org-agenda-files 'org-restrict)))
  1909. "--")
  1910. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1911. (org-agenda-set-mode-name)
  1912. (apply
  1913. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1914. (list 'org-agenda-mode-hook)))
  1915. (substitute-key-definition 'undo 'org-agenda-undo
  1916. org-agenda-mode-map global-map)
  1917. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1918. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1919. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1920. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1921. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1922. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1923. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1924. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1925. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1926. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1927. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1928. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1929. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1930. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1931. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1932. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1933. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1934. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1935. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1936. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1940. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1941. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1942. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1943. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1944. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1945. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1946. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1947. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1948. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1949. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1950. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1951. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1952. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1953. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1954. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1955. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1956. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1957. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1958. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1959. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1960. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1961. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1962. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1963. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1964. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1965. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1966. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1967. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1968. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1969. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1970. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1971. (while l (org-defkey org-agenda-mode-map
  1972. (int-to-string (pop l)) 'digit-argument)))
  1973. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1974. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1975. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1976. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1977. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1978. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1979. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1980. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1981. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1982. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1983. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1984. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1985. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1986. 'org-clock-modify-effort-estimate)
  1987. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1988. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1989. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1990. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1991. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1992. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1993. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1994. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1995. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1996. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1997. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1998. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1999. (substitute-key-definition 'next-line 'org-agenda-next-line
  2000. org-agenda-mode-map global-map)
  2001. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2002. org-agenda-mode-map global-map)
  2003. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2004. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2005. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2006. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2007. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2008. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2009. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2010. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2011. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2012. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2013. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2014. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2015. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2016. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2017. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2018. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2019. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2020. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2021. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2022. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2023. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2024. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2025. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2026. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2027. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2028. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2029. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2030. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2031. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2033. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2034. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2035. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2036. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2037. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2038. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2039. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2040. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2041. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2042. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2043. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2044. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2045. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2046. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2048. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2049. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2050. (when org-agenda-mouse-1-follows-link
  2051. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2052. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2053. '("Agenda"
  2054. ("Agenda Files")
  2055. "--"
  2056. ("Agenda Dates"
  2057. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2058. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2059. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2060. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2061. "--"
  2062. ("View"
  2063. ["Day View" org-agenda-day-view
  2064. :active (org-agenda-check-type nil 'agenda)
  2065. :style radio :selected (eq org-agenda-current-span 'day)
  2066. :keys "v d (or just d)"]
  2067. ["Week View" org-agenda-week-view
  2068. :active (org-agenda-check-type nil 'agenda)
  2069. :style radio :selected (eq org-agenda-current-span 'week)
  2070. :keys "v w"]
  2071. ["Fortnight View" org-agenda-fortnight-view
  2072. :active (org-agenda-check-type nil 'agenda)
  2073. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2074. :keys "v f"]
  2075. ["Month View" org-agenda-month-view
  2076. :active (org-agenda-check-type nil 'agenda)
  2077. :style radio :selected (eq org-agenda-current-span 'month)
  2078. :keys "v m"]
  2079. ["Year View" org-agenda-year-view
  2080. :active (org-agenda-check-type nil 'agenda)
  2081. :style radio :selected (eq org-agenda-current-span 'year)
  2082. :keys "v y"]
  2083. "--"
  2084. ["Include Diary" org-agenda-toggle-diary
  2085. :style toggle :selected org-agenda-include-diary
  2086. :active (org-agenda-check-type nil 'agenda)]
  2087. ["Include Deadlines" org-agenda-toggle-deadlines
  2088. :style toggle :selected org-agenda-include-deadlines
  2089. :active (org-agenda-check-type nil 'agenda)]
  2090. ["Use Time Grid" org-agenda-toggle-time-grid
  2091. :style toggle :selected org-agenda-use-time-grid
  2092. :active (org-agenda-check-type nil 'agenda)]
  2093. "--"
  2094. ["Show clock report" org-agenda-clockreport-mode
  2095. :style toggle :selected org-agenda-clockreport-mode
  2096. :active (org-agenda-check-type nil 'agenda)]
  2097. ["Show some entry text" org-agenda-entry-text-mode
  2098. :style toggle :selected org-agenda-entry-text-mode
  2099. :active t]
  2100. "--"
  2101. ["Show Logbook entries" org-agenda-log-mode
  2102. :style toggle :selected org-agenda-show-log
  2103. :active (org-agenda-check-type nil 'agenda 'timeline)
  2104. :keys "v l (or just l)"]
  2105. ["Include archived trees" org-agenda-archives-mode
  2106. :style toggle :selected org-agenda-archives-mode :active t
  2107. :keys "v a"]
  2108. ["Include archive files" (org-agenda-archives-mode t)
  2109. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2110. :keys "v A"]
  2111. "--"
  2112. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2113. ["Write view to file" org-agenda-write t]
  2114. ["Rebuild buffer" org-agenda-redo t]
  2115. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2116. "--"
  2117. ["Show original entry" org-agenda-show t]
  2118. ["Go To (other window)" org-agenda-goto t]
  2119. ["Go To (this window)" org-agenda-switch-to t]
  2120. ["Capture with cursor date" org-agenda-capture t]
  2121. ["Follow Mode" org-agenda-follow-mode
  2122. :style toggle :selected org-agenda-follow-mode :active t]
  2123. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2124. "--"
  2125. ("TODO"
  2126. ["Cycle TODO" org-agenda-todo t]
  2127. ["Next TODO set" org-agenda-todo-nextset t]
  2128. ["Previous TODO set" org-agenda-todo-previousset t]
  2129. ["Add note" org-agenda-add-note t])
  2130. ("Archive/Refile/Delete"
  2131. ["Archive default" org-agenda-archive-default t]
  2132. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2133. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2134. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2135. ["Archive subtree" org-agenda-archive t]
  2136. "--"
  2137. ["Refile" org-agenda-refile t]
  2138. "--"
  2139. ["Delete subtree" org-agenda-kill t])
  2140. ("Bulk action"
  2141. ["Mark entry" org-agenda-bulk-mark t]
  2142. ["Mark all" org-agenda-bulk-mark-all t]
  2143. ["Unmark entry" org-agenda-bulk-unmark t]
  2144. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2145. ["Toggle mark" org-agenda-bulk-toggle t]
  2146. ["Toggle all" org-agenda-bulk-toggle-all t]
  2147. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2148. ["Act on all marked" org-agenda-bulk-action t]
  2149. "--"
  2150. ("Tags and Properties"
  2151. ["Show all Tags" org-agenda-show-tags t]
  2152. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2153. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2154. "--"
  2155. ["Column View" org-columns t])
  2156. ("Deadline/Schedule"
  2157. ["Schedule" org-agenda-schedule t]
  2158. ["Set Deadline" org-agenda-deadline t]
  2159. "--"
  2160. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2161. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2162. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2163. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2164. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2165. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2166. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2167. ("Clock and Effort"
  2168. ["Clock in" org-agenda-clock-in t]
  2169. ["Clock out" org-agenda-clock-out t]
  2170. ["Clock cancel" org-agenda-clock-cancel t]
  2171. ["Goto running clock" org-clock-goto t]
  2172. "--"
  2173. ["Set Effort" org-agenda-set-effort t]
  2174. ["Change clocked effort" org-clock-modify-effort-estimate
  2175. (org-clock-is-active)])
  2176. ("Priority"
  2177. ["Set Priority" org-agenda-priority t]
  2178. ["Increase Priority" org-agenda-priority-up t]
  2179. ["Decrease Priority" org-agenda-priority-down t]
  2180. ["Show Priority" org-show-priority t])
  2181. ("Calendar/Diary"
  2182. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2183. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2184. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2185. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2186. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2188. "--"
  2189. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2190. "--"
  2191. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2192. "--"
  2193. ("MobileOrg"
  2194. ["Push Files and Views" org-mobile-push t]
  2195. ["Get Captured and Flagged" org-mobile-pull t]
  2196. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2197. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2198. "--"
  2199. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2200. "--"
  2201. ["Quit" org-agenda-quit t]
  2202. ["Exit and Release Buffers" org-agenda-exit t]
  2203. ))
  2204. ;;; Agenda undo
  2205. (defvar org-agenda-allow-remote-undo t
  2206. "Non-nil means allow remote undo from the agenda buffer.")
  2207. (defvar org-agenda-undo-has-started-in nil
  2208. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2209. (defun org-agenda-undo ()
  2210. "Undo a remote editing step in the agenda.
  2211. This undoes changes both in the agenda buffer and in the remote buffer
  2212. that have been changed along."
  2213. (interactive)
  2214. (or org-agenda-allow-remote-undo
  2215. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2216. (if (not (eq this-command last-command))
  2217. (setq org-agenda-undo-has-started-in nil
  2218. org-agenda-pending-undo-list org-agenda-undo-list))
  2219. (if (not org-agenda-pending-undo-list)
  2220. (user-error "No further undo information"))
  2221. (let* ((entry (pop org-agenda-pending-undo-list))
  2222. buf line cmd rembuf)
  2223. (setq cmd (pop entry) line (pop entry))
  2224. (setq rembuf (nth 2 entry))
  2225. (org-with-remote-undo rembuf
  2226. (while (bufferp (setq buf (pop entry)))
  2227. (if (pop entry)
  2228. (with-current-buffer buf
  2229. (let ((last-undo-buffer buf)
  2230. (inhibit-read-only t))
  2231. (unless (memq buf org-agenda-undo-has-started-in)
  2232. (push buf org-agenda-undo-has-started-in)
  2233. (make-local-variable 'pending-undo-list)
  2234. (undo-start))
  2235. (while (and pending-undo-list
  2236. (listp pending-undo-list)
  2237. (not (car pending-undo-list)))
  2238. (pop pending-undo-list))
  2239. (undo-more 1))))))
  2240. (org-goto-line line)
  2241. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2242. (defun org-verify-change-for-undo (l1 l2)
  2243. "Verify that a real change occurred between the undo lists L1 and L2."
  2244. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2245. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2246. (not (eq l1 l2)))
  2247. ;;; Agenda dispatch
  2248. (defvar org-agenda-restrict-begin (make-marker))
  2249. (defvar org-agenda-restrict-end (make-marker))
  2250. (defvar org-agenda-last-dispatch-buffer nil)
  2251. (defvar org-agenda-overriding-restriction nil)
  2252. (defcustom org-agenda-custom-commands-contexts nil
  2253. "Alist of custom agenda keys and contextual rules.
  2254. For example, if you have a custom agenda command \"p\" and you
  2255. want this command to be accessible only from plain text files,
  2256. use this:
  2257. '((\"p\" ((in-file . \"\\.txt\"))))
  2258. Here are the available contexts definitions:
  2259. in-file: command displayed only in matching files
  2260. in-mode: command displayed only in matching modes
  2261. not-in-file: command not displayed in matching files
  2262. not-in-mode: command not displayed in matching modes
  2263. in-buffer: command displayed only in matching buffers
  2264. not-in-buffer: command not displayed in matching buffers
  2265. [function]: a custom function taking no argument
  2266. If you define several checks, the agenda command will be
  2267. accessible if there is at least one valid check.
  2268. You can also bind a key to another agenda custom command
  2269. depending on contextual rules.
  2270. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2271. Here it means: in .txt files, use \"p\" as the key for the
  2272. agenda command otherwise associated with \"q\". (The command
  2273. originally associated with \"q\" is not displayed to avoid
  2274. duplicates.)"
  2275. :version "24.3"
  2276. :group 'org-agenda-custom-commands
  2277. :type '(repeat (list :tag "Rule"
  2278. (string :tag " Agenda key")
  2279. (string :tag "Replace by command")
  2280. (repeat :tag "Available when"
  2281. (choice
  2282. (cons :tag "Condition"
  2283. (choice
  2284. (const :tag "In file" in-file)
  2285. (const :tag "Not in file" not-in-file)
  2286. (const :tag "In buffer" in-buffer)
  2287. (const :tag "Not in buffer" not-in-buffer)
  2288. (const :tag "In mode" in-mode)
  2289. (const :tag "Not in mode" not-in-mode))
  2290. (regexp))
  2291. (function :tag "Custom function"))))))
  2292. (defcustom org-agenda-max-entries nil
  2293. "Maximum number of entries to display in an agenda.
  2294. This can be nil (no limit) or an integer or an alist of agenda
  2295. types with an associated number of entries to display in this
  2296. type."
  2297. :version "24.4"
  2298. :package-version '(Org . "8.0")
  2299. :group 'org-agenda-custom-commands
  2300. :type '(choice (symbol :tag "No limit" nil)
  2301. (integer :tag "Max number of entries")
  2302. (repeat
  2303. (cons (choice :tag "Agenda type"
  2304. (const agenda)
  2305. (const todo)
  2306. (const tags)
  2307. (const search)
  2308. (const timeline))
  2309. (integer :tag "Max number of entries")))))
  2310. (defcustom org-agenda-max-todos nil
  2311. "Maximum number of TODOs to display in an agenda.
  2312. This can be nil (no limit) or an integer or an alist of agenda
  2313. types with an associated number of entries to display in this
  2314. type."
  2315. :version "24.4"
  2316. :package-version '(Org . "8.0")
  2317. :group 'org-agenda-custom-commands
  2318. :type '(choice (symbol :tag "No limit" nil)
  2319. (integer :tag "Max number of entries")
  2320. (repeat
  2321. (cons (choice :tag "Agenda type"
  2322. (const agenda)
  2323. (const todo)
  2324. (const tags)
  2325. (const search)
  2326. (const timeline))
  2327. (integer :tag "Max number of entries")))))
  2328. (defcustom org-agenda-max-tags nil
  2329. "Maximum number of tagged entries to display in an agenda.
  2330. This can be nil (no limit) or an integer or an alist of agenda
  2331. types with an associated number of entries to display in this
  2332. type."
  2333. :version "24.4"
  2334. :package-version '(Org . "8.0")
  2335. :group 'org-agenda-custom-commands
  2336. :type '(choice (symbol :tag "No limit" nil)
  2337. (integer :tag "Max number of entries")
  2338. (repeat
  2339. (cons (choice :tag "Agenda type"
  2340. (const agenda)
  2341. (const todo)
  2342. (const tags)
  2343. (const search)
  2344. (const timeline))
  2345. (integer :tag "Max number of entries")))))
  2346. (defcustom org-agenda-max-effort nil
  2347. "Maximum cumulated effort duration for the agenda.
  2348. This can be nil (no limit) or a number of minutes (as an integer)
  2349. or an alist of agenda types with an associated number of minutes
  2350. to limit entries to in this type."
  2351. :version "24.4"
  2352. :package-version '(Org . "8.0")
  2353. :group 'org-agenda-custom-commands
  2354. :type '(choice (symbol :tag "No limit" nil)
  2355. (integer :tag "Max number of entries")
  2356. (repeat
  2357. (cons (choice :tag "Agenda type"
  2358. (const agenda)
  2359. (const todo)
  2360. (const tags)
  2361. (const search)
  2362. (const timeline))
  2363. (integer :tag "Max number of entries")))))
  2364. (defvar org-keys nil)
  2365. (defvar org-match nil)
  2366. ;;;###autoload
  2367. (defun org-agenda (&optional arg org-keys restriction)
  2368. "Dispatch agenda commands to collect entries to the agenda buffer.
  2369. Prompts for a command to execute. Any prefix arg will be passed
  2370. on to the selected command. The default selections are:
  2371. a Call `org-agenda-list' to display the agenda for current day or week.
  2372. t Call `org-todo-list' to display the global todo list.
  2373. T Call `org-todo-list' to display the global todo list, select only
  2374. entries with a specific TODO keyword (the user gets a prompt).
  2375. m Call `org-tags-view' to display headlines with tags matching
  2376. a condition (the user is prompted for the condition).
  2377. M Like `m', but select only TODO entries, no ordinary headlines.
  2378. L Create a timeline for the current buffer.
  2379. e Export views to associated files.
  2380. s Search entries for keywords.
  2381. S Search entries for keywords, only with TODO keywords.
  2382. / Multi occur across all agenda files and also files listed
  2383. in `org-agenda-text-search-extra-files'.
  2384. < Restrict agenda commands to buffer, subtree, or region.
  2385. Press several times to get the desired effect.
  2386. > Remove a previous restriction.
  2387. # List \"stuck\" projects.
  2388. ! Configure what \"stuck\" means.
  2389. C Configure custom agenda commands.
  2390. More commands can be added by configuring the variable
  2391. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2392. searches can be pre-defined in this way.
  2393. If the current buffer is in Org-mode and visiting a file, you can also
  2394. first press `<' once to indicate that the agenda should be temporarily
  2395. \(until the next use of \\[org-agenda]) restricted to the current file.
  2396. Pressing `<' twice means to restrict to the current subtree or region
  2397. \(if active)."
  2398. (interactive "P")
  2399. (catch 'exit
  2400. (let* ((prefix-descriptions nil)
  2401. (org-agenda-buffer-name org-agenda-buffer-name)
  2402. (org-agenda-window-setup (if (equal (buffer-name)
  2403. org-agenda-buffer-name)
  2404. 'current-window
  2405. org-agenda-window-setup))
  2406. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2407. (org-agenda-custom-commands
  2408. ;; normalize different versions
  2409. (delq nil
  2410. (mapcar
  2411. (lambda (x)
  2412. (cond ((stringp (cdr x))
  2413. (push x prefix-descriptions)
  2414. nil)
  2415. ((stringp (nth 1 x)) x)
  2416. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2417. (t (cons (car x) (cons "" (cdr x))))))
  2418. org-agenda-custom-commands)))
  2419. (org-agenda-custom-commands
  2420. (org-contextualize-keys
  2421. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2422. (buf (current-buffer))
  2423. (bfn (buffer-file-name (buffer-base-buffer)))
  2424. entry key type org-match lprops ans)
  2425. ;; Turn off restriction unless there is an overriding one,
  2426. (unless org-agenda-overriding-restriction
  2427. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2428. ;; There is a request to keep the file list in place
  2429. (put 'org-agenda-files 'org-restrict nil))
  2430. (setq org-agenda-restrict nil)
  2431. (move-marker org-agenda-restrict-begin nil)
  2432. (move-marker org-agenda-restrict-end nil))
  2433. ;; Delete old local properties
  2434. (put 'org-agenda-redo-command 'org-lprops nil)
  2435. ;; Delete previously set last-arguments
  2436. (put 'org-agenda-redo-command 'last-args nil)
  2437. ;; Remember where this call originated
  2438. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2439. (unless org-keys
  2440. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2441. org-keys (car ans)
  2442. restriction (cdr ans)))
  2443. ;; If we have sticky agenda buffers, set a name for the buffer,
  2444. ;; depending on the invoking keys. The user may still set this
  2445. ;; as a command option, which will overwrite what we do here.
  2446. (if org-agenda-sticky
  2447. (setq org-agenda-buffer-name
  2448. (format "*Org Agenda(%s)*" org-keys)))
  2449. ;; Establish the restriction, if any
  2450. (when (and (not org-agenda-overriding-restriction) restriction)
  2451. (put 'org-agenda-files 'org-restrict (list bfn))
  2452. (cond
  2453. ((eq restriction 'region)
  2454. (setq org-agenda-restrict (current-buffer))
  2455. (move-marker org-agenda-restrict-begin (region-beginning))
  2456. (move-marker org-agenda-restrict-end (region-end)))
  2457. ((eq restriction 'subtree)
  2458. (save-excursion
  2459. (setq org-agenda-restrict (current-buffer))
  2460. (org-back-to-heading t)
  2461. (move-marker org-agenda-restrict-begin (point))
  2462. (move-marker org-agenda-restrict-end
  2463. (progn (org-end-of-subtree t)))))))
  2464. ;; For example the todo list should not need it (but does...)
  2465. (cond
  2466. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2467. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2468. (progn
  2469. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2470. lprops (nth 4 entry))
  2471. (if org-agenda-sticky
  2472. (setq org-agenda-buffer-name
  2473. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2474. (format "*Org Agenda(%s)*" org-keys))))
  2475. (put 'org-agenda-redo-command 'org-lprops lprops)
  2476. (cond
  2477. ((eq type 'agenda)
  2478. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2479. ((eq type 'agenda*)
  2480. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2481. ((eq type 'alltodo)
  2482. (org-let lprops '(org-todo-list current-prefix-arg)))
  2483. ((eq type 'search)
  2484. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2485. ((eq type 'stuck)
  2486. (org-let lprops '(org-agenda-list-stuck-projects
  2487. current-prefix-arg)))
  2488. ((eq type 'tags)
  2489. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2490. ((eq type 'tags-todo)
  2491. (org-let lprops '(org-tags-view '(4) org-match)))
  2492. ((eq type 'todo)
  2493. (org-let lprops '(org-todo-list org-match)))
  2494. ((eq type 'tags-tree)
  2495. (org-check-for-org-mode)
  2496. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2497. ((eq type 'todo-tree)
  2498. (org-check-for-org-mode)
  2499. (org-let lprops
  2500. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2501. (regexp-quote org-match) "\\>"))))
  2502. ((eq type 'occur-tree)
  2503. (org-check-for-org-mode)
  2504. (org-let lprops '(org-occur org-match)))
  2505. ((functionp type)
  2506. (org-let lprops '(funcall type org-match)))
  2507. ((fboundp type)
  2508. (org-let lprops '(funcall type org-match)))
  2509. (t (user-error "Invalid custom agenda command type %s" type))))
  2510. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2511. ((equal org-keys "C")
  2512. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2513. (customize-variable 'org-agenda-custom-commands))
  2514. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2515. ((equal org-keys "s") (call-interactively 'org-search-view))
  2516. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2517. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2518. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2519. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2520. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2521. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2522. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2523. (org-add-hook
  2524. 'post-command-hook
  2525. (lambda ()
  2526. (unless (current-message)
  2527. (let* ((m (org-agenda-get-any-marker))
  2528. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2529. (when note
  2530. (message (concat
  2531. "FLAGGING-NOTE ([?] for more info): "
  2532. (org-add-props
  2533. (replace-regexp-in-string
  2534. "\\\\n" "//"
  2535. (copy-sequence note))
  2536. nil 'face 'org-warning)))))))
  2537. t t))
  2538. ((equal org-keys "L")
  2539. (unless (derived-mode-p 'org-mode)
  2540. (user-error "This is not an Org-mode file"))
  2541. (unless restriction
  2542. (put 'org-agenda-files 'org-restrict (list bfn))
  2543. (org-call-with-arg 'org-timeline arg)))
  2544. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2545. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2546. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2547. (t (user-error "Invalid agenda key"))))))
  2548. (defun org-agenda-append-agenda ()
  2549. "Append another agenda view to the current one.
  2550. This function allows interactive building of block agendas.
  2551. Agenda views are separated by `org-agenda-block-separator'."
  2552. (interactive)
  2553. (unless (derived-mode-p 'org-agenda-mode)
  2554. (user-error "Can only append from within agenda buffer"))
  2555. (let ((org-agenda-multi t))
  2556. (org-agenda)
  2557. (widen)
  2558. (org-agenda-finalize)
  2559. (setq buffer-read-only t)
  2560. (org-agenda-fit-window-to-buffer)))
  2561. (defun org-agenda-normalize-custom-commands (cmds)
  2562. "Normalize custom commands CMDS."
  2563. (delq nil
  2564. (mapcar
  2565. (lambda (x)
  2566. (cond ((stringp (cdr x)) nil)
  2567. ((stringp (nth 1 x)) x)
  2568. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2569. (t (cons (car x) (cons "" (cdr x))))))
  2570. cmds)))
  2571. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2572. "The user interface for selecting an agenda command."
  2573. (catch 'exit
  2574. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2575. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2576. (region-p (org-region-active-p))
  2577. (custom org-agenda-custom-commands)
  2578. (selstring "")
  2579. restriction second-time
  2580. c entry key type match prefixes rmheader header-end custom1 desc
  2581. line lines left right n n1)
  2582. (save-window-excursion
  2583. (delete-other-windows)
  2584. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2585. (erase-buffer)
  2586. (insert (eval-when-compile
  2587. (let ((header
  2588. "Press key for an agenda command: < Buffer, subtree/region restriction
  2589. -------------------------------- > Remove restriction
  2590. a Agenda for current week or day e Export agenda views
  2591. t List of all TODO entries T Entries with special TODO kwd
  2592. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2593. s Search for keywords S Like s, but only TODO entries
  2594. L Timeline for current buffer # List stuck projects (!=configure)
  2595. / Multi-occur C Configure custom agenda commands
  2596. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2597. ")
  2598. (start 0))
  2599. (while (string-match
  2600. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2601. header start)
  2602. (setq start (match-end 0))
  2603. (add-text-properties (match-beginning 2) (match-end 2)
  2604. '(face bold) header))
  2605. header)))
  2606. (setq header-end (point-marker))
  2607. (while t
  2608. (setq custom1 custom)
  2609. (when (eq rmheader t)
  2610. (org-goto-line 1)
  2611. (re-search-forward ":" nil t)
  2612. (delete-region (match-end 0) (point-at-eol))
  2613. (forward-char 1)
  2614. (looking-at "-+")
  2615. (delete-region (match-end 0) (point-at-eol))
  2616. (move-marker header-end (match-end 0)))
  2617. (goto-char header-end)
  2618. (delete-region (point) (point-max))
  2619. ;; Produce all the lines that describe custom commands and prefixes
  2620. (setq lines nil)
  2621. (while (setq entry (pop custom1))
  2622. (setq key (car entry) desc (nth 1 entry)
  2623. type (nth 2 entry)
  2624. match (nth 3 entry))
  2625. (if (> (length key) 1)
  2626. (add-to-list 'prefixes (string-to-char key))
  2627. (setq line
  2628. (format
  2629. "%-4s%-14s"
  2630. (org-add-props (copy-sequence key)
  2631. '(face bold))
  2632. (cond
  2633. ((string-match "\\S-" desc) desc)
  2634. ((eq type 'agenda) "Agenda for current week or day")
  2635. ((eq type 'agenda*) "Appointments for current week or day")
  2636. ((eq type 'alltodo) "List of all TODO entries")
  2637. ((eq type 'search) "Word search")
  2638. ((eq type 'stuck) "List of stuck projects")
  2639. ((eq type 'todo) "TODO keyword")
  2640. ((eq type 'tags) "Tags query")
  2641. ((eq type 'tags-todo) "Tags (TODO)")
  2642. ((eq type 'tags-tree) "Tags tree")
  2643. ((eq type 'todo-tree) "TODO kwd tree")
  2644. ((eq type 'occur-tree) "Occur tree")
  2645. ((functionp type) (if (symbolp type)
  2646. (symbol-name type)
  2647. "Lambda expression"))
  2648. (t "???"))))
  2649. (if org-agenda-menu-show-matcher
  2650. (setq line
  2651. (concat line ": "
  2652. (cond
  2653. ((stringp match)
  2654. (setq match (copy-sequence match))
  2655. (org-add-props match nil 'face 'org-warning))
  2656. ((listp type)
  2657. (format "set of %d commands" (length type))))))
  2658. (if (org-string-nw-p match)
  2659. (add-text-properties
  2660. 0 (length line) (list 'help-echo
  2661. (concat "Matcher: " match)) line)))
  2662. (push line lines)))
  2663. (setq lines (nreverse lines))
  2664. (when prefixes
  2665. (mapc (lambda (x)
  2666. (push
  2667. (format "%s %s"
  2668. (org-add-props (char-to-string x)
  2669. nil 'face 'bold)
  2670. (or (cdr (assoc (concat selstring
  2671. (char-to-string x))
  2672. prefix-descriptions))
  2673. "Prefix key"))
  2674. lines))
  2675. prefixes))
  2676. ;; Check if we should display in two columns
  2677. (if org-agenda-menu-two-columns
  2678. (progn
  2679. (setq n (length lines)
  2680. n1 (+ (/ n 2) (mod n 2))
  2681. right (nthcdr n1 lines)
  2682. left (copy-sequence lines))
  2683. (setcdr (nthcdr (1- n1) left) nil))
  2684. (setq left lines right nil))
  2685. (while left
  2686. (insert "\n" (pop left))
  2687. (when right
  2688. (if (< (current-column) 40)
  2689. (move-to-column 40 t)
  2690. (insert " "))
  2691. (insert (pop right))))
  2692. ;; Make the window the right size
  2693. (goto-char (point-min))
  2694. (if second-time
  2695. (if (not (pos-visible-in-window-p (point-max)))
  2696. (org-fit-window-to-buffer))
  2697. (setq second-time t)
  2698. (org-fit-window-to-buffer))
  2699. ;; Ask for selection
  2700. (message "Press key for agenda command%s:"
  2701. (if (or restrict-ok org-agenda-overriding-restriction)
  2702. (if org-agenda-overriding-restriction
  2703. " (restriction lock active)"
  2704. (if restriction
  2705. (format " (restricted to %s)" restriction)
  2706. " (unrestricted)"))
  2707. ""))
  2708. (setq c (read-char-exclusive))
  2709. (message "")
  2710. (cond
  2711. ((assoc (char-to-string c) custom)
  2712. (setq selstring (concat selstring (char-to-string c)))
  2713. (throw 'exit (cons selstring restriction)))
  2714. ((memq c prefixes)
  2715. (setq selstring (concat selstring (char-to-string c))
  2716. prefixes nil
  2717. rmheader (or rmheader t)
  2718. custom (delq nil (mapcar
  2719. (lambda (x)
  2720. (if (or (= (length (car x)) 1)
  2721. (/= (string-to-char (car x)) c))
  2722. nil
  2723. (cons (substring (car x) 1) (cdr x))))
  2724. custom))))
  2725. ((eq c ?*)
  2726. (call-interactively 'org-toggle-sticky-agenda)
  2727. (sit-for 2))
  2728. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2729. (message "Restriction is only possible in Org-mode buffers")
  2730. (ding) (sit-for 1))
  2731. ((eq c ?1)
  2732. (org-agenda-remove-restriction-lock 'noupdate)
  2733. (setq restriction 'buffer))
  2734. ((eq c ?0)
  2735. (org-agenda-remove-restriction-lock 'noupdate)
  2736. (setq restriction (if region-p 'region 'subtree)))
  2737. ((eq c ?<)
  2738. (org-agenda-remove-restriction-lock 'noupdate)
  2739. (setq restriction
  2740. (cond
  2741. ((eq restriction 'buffer)
  2742. (if region-p 'region 'subtree))
  2743. ((memq restriction '(subtree region))
  2744. nil)
  2745. (t 'buffer))))
  2746. ((eq c ?>)
  2747. (org-agenda-remove-restriction-lock 'noupdate)
  2748. (setq restriction nil))
  2749. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2750. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2751. ((and (> (length selstring) 0) (eq c ?\d))
  2752. (delete-window)
  2753. (org-agenda-get-restriction-and-command prefix-descriptions))
  2754. ((equal c ?q) (error "Abort"))
  2755. (t (user-error "Invalid key %c" c))))))))
  2756. (defun org-agenda-fit-window-to-buffer ()
  2757. "Fit the window to the buffer size."
  2758. (and (memq org-agenda-window-setup '(reorganize-frame))
  2759. (fboundp 'fit-window-to-buffer)
  2760. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2761. (= (car org-agenda-window-frame-fractions) 1.0))
  2762. (delete-other-windows)
  2763. (org-fit-window-to-buffer
  2764. nil
  2765. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2766. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2767. (defvar org-cmd nil)
  2768. (defvar org-agenda-overriding-cmd nil)
  2769. (defvar org-agenda-overriding-arguments nil)
  2770. (defvar org-agenda-overriding-cmd-arguments nil)
  2771. (defun org-agenda-run-series (name series)
  2772. "Run agenda NAME as a SERIES of agenda commands."
  2773. (org-let (nth 1 series) '(org-agenda-prepare name))
  2774. ;; We need to reset agenda markers here, because when constructing a
  2775. ;; block agenda, the individual blocks do not do that.
  2776. (org-agenda-reset-markers)
  2777. (let* ((org-agenda-multi t)
  2778. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2779. (cmds (car series))
  2780. (gprops (nth 1 series))
  2781. match ;; The byte compiler incorrectly complains about this. Keep it!
  2782. org-cmd type lprops)
  2783. (while (setq org-cmd (pop cmds))
  2784. (setq type (car org-cmd)
  2785. match (eval (nth 1 org-cmd))
  2786. lprops (nth 2 org-cmd))
  2787. (let ((org-agenda-overriding-arguments
  2788. (if (eq org-agenda-overriding-cmd org-cmd)
  2789. (or org-agenda-overriding-arguments
  2790. org-agenda-overriding-cmd-arguments))))
  2791. (cond
  2792. ((eq type 'agenda)
  2793. (org-let2 gprops lprops
  2794. '(call-interactively 'org-agenda-list)))
  2795. ((eq type 'agenda*)
  2796. (org-let2 gprops lprops
  2797. '(funcall 'org-agenda-list nil nil t)))
  2798. ((eq type 'alltodo)
  2799. (org-let2 gprops lprops
  2800. '(call-interactively 'org-todo-list)))
  2801. ((eq type 'search)
  2802. (org-let2 gprops lprops
  2803. '(org-search-view current-prefix-arg match nil)))
  2804. ((eq type 'stuck)
  2805. (org-let2 gprops lprops
  2806. '(call-interactively 'org-agenda-list-stuck-projects)))
  2807. ((eq type 'tags)
  2808. (org-let2 gprops lprops
  2809. '(org-tags-view current-prefix-arg match)))
  2810. ((eq type 'tags-todo)
  2811. (org-let2 gprops lprops
  2812. '(org-tags-view '(4) match)))
  2813. ((eq type 'todo)
  2814. (org-let2 gprops lprops
  2815. '(org-todo-list match)))
  2816. ((fboundp type)
  2817. (org-let2 gprops lprops
  2818. '(funcall type match)))
  2819. (t (error "Invalid type in command series")))))
  2820. (widen)
  2821. (let ((inhibit-read-only t))
  2822. (add-text-properties (point-min) (point-max)
  2823. `(org-series t org-series-redo-cmd ,redo)))
  2824. (setq org-agenda-redo-command redo)
  2825. (goto-char (point-min)))
  2826. (org-agenda-fit-window-to-buffer)
  2827. (org-let (nth 1 series) '(org-agenda-finalize)))
  2828. ;;;###autoload
  2829. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2830. "Run an agenda command in batch mode and send the result to STDOUT.
  2831. If CMD-KEY is a string of length 1, it is used as a key in
  2832. `org-agenda-custom-commands' and triggers this command. If it is a
  2833. longer string it is used as a tags/todo match string.
  2834. Parameters are alternating variable names and values that will be bound
  2835. before running the agenda command."
  2836. (org-eval-in-environment (org-make-parameter-alist parameters)
  2837. (let (org-agenda-sticky)
  2838. (if (> (length cmd-key) 2)
  2839. (org-tags-view nil cmd-key)
  2840. (org-agenda nil cmd-key))))
  2841. (set-buffer org-agenda-buffer-name)
  2842. (princ (buffer-string)))
  2843. (defvar org-agenda-info nil)
  2844. ;;;###autoload
  2845. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2846. "Run an agenda command in batch mode and send the result to STDOUT.
  2847. If CMD-KEY is a string of length 1, it is used as a key in
  2848. `org-agenda-custom-commands' and triggers this command. If it is a
  2849. longer string it is used as a tags/todo match string.
  2850. Parameters are alternating variable names and values that will be bound
  2851. before running the agenda command.
  2852. The output gives a line for each selected agenda item. Each
  2853. item is a list of comma-separated values, like this:
  2854. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2855. category The category of the item
  2856. head The headline, without TODO kwd, TAGS and PRIORITY
  2857. type The type of the agenda entry, can be
  2858. todo selected in TODO match
  2859. tagsmatch selected in tags match
  2860. diary imported from diary
  2861. deadline a deadline on given date
  2862. scheduled scheduled on given date
  2863. timestamp entry has timestamp on given date
  2864. closed entry was closed on given date
  2865. upcoming-deadline warning about deadline
  2866. past-scheduled forwarded scheduled item
  2867. block entry has date block including g. date
  2868. todo The todo keyword, if any
  2869. tags All tags including inherited ones, separated by colons
  2870. date The relevant date, like 2007-2-14
  2871. time The time, like 15:00-16:50
  2872. extra Sting with extra planning info
  2873. priority-l The priority letter if any was given
  2874. priority-n The computed numerical priority
  2875. agenda-day The day in the agenda where this is listed"
  2876. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2877. (org-make-parameter-alist parameters))
  2878. (if (> (length cmd-key) 2)
  2879. (org-tags-view nil cmd-key)
  2880. (org-agenda nil cmd-key)))
  2881. (set-buffer org-agenda-buffer-name)
  2882. (let* ((lines (org-split-string (buffer-string) "\n"))
  2883. line)
  2884. (while (setq line (pop lines))
  2885. (catch 'next
  2886. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2887. (setq org-agenda-info
  2888. (org-fix-agenda-info (text-properties-at 0 line)))
  2889. (princ
  2890. (mapconcat 'org-agenda-export-csv-mapper
  2891. '(org-category txt type todo tags date time extra
  2892. priority-letter priority agenda-day)
  2893. ","))
  2894. (princ "\n")))))
  2895. (defun org-fix-agenda-info (props)
  2896. "Make sure all properties on an agenda item have a canonical form.
  2897. This ensures the export commands can easily use it."
  2898. (let (tmp re)
  2899. (when (setq tmp (plist-get props 'tags))
  2900. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2901. (when (setq tmp (plist-get props 'date))
  2902. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2903. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2904. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2905. (setq tmp (calendar-date-string tmp)))
  2906. (setq props (plist-put props 'date tmp)))
  2907. (when (setq tmp (plist-get props 'day))
  2908. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2909. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2910. (setq tmp (calendar-date-string tmp)))
  2911. (setq props (plist-put props 'day tmp))
  2912. (setq props (plist-put props 'agenda-day tmp)))
  2913. (when (setq tmp (plist-get props 'txt))
  2914. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2915. (plist-put props 'priority-letter (match-string 1 tmp))
  2916. (setq tmp (replace-match "" t t tmp)))
  2917. (when (and (setq re (plist-get props 'org-todo-regexp))
  2918. (setq re (concat "\\`\\.*" re " ?"))
  2919. (string-match re tmp))
  2920. (plist-put props 'todo (match-string 1 tmp))
  2921. (setq tmp (replace-match "" t t tmp)))
  2922. (plist-put props 'txt tmp)))
  2923. props)
  2924. (defun org-agenda-export-csv-mapper (prop)
  2925. (let ((res (plist-get org-agenda-info prop)))
  2926. (setq res
  2927. (cond
  2928. ((not res) "")
  2929. ((stringp res) res)
  2930. (t (prin1-to-string res))))
  2931. (while (string-match "," res)
  2932. (setq res (replace-match ";" t t res)))
  2933. (org-trim res)))
  2934. ;;;###autoload
  2935. (defun org-store-agenda-views (&rest parameters)
  2936. "Store agenda views."
  2937. (interactive)
  2938. (eval (list 'org-batch-store-agenda-views)))
  2939. ;;;###autoload
  2940. (defmacro org-batch-store-agenda-views (&rest parameters)
  2941. "Run all custom agenda commands that have a file argument."
  2942. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2943. (pop-up-frames nil)
  2944. (dir default-directory)
  2945. (pars (org-make-parameter-alist parameters))
  2946. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2947. (save-window-excursion
  2948. (while cmds
  2949. (setq cmd (pop cmds)
  2950. thiscmdkey (car cmd)
  2951. thiscmdcmd (cdr cmd)
  2952. match (nth 2 thiscmdcmd)
  2953. bufname (if org-agenda-sticky
  2954. (or (and (stringp match)
  2955. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2956. (format "*Org Agenda(%s)*" thiscmdkey))
  2957. org-agenda-buffer-name)
  2958. cmd-or-set (nth 2 cmd)
  2959. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2960. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2961. (if (stringp files) (setq files (list files)))
  2962. (when files
  2963. (org-eval-in-environment (append org-agenda-exporter-settings
  2964. opts pars)
  2965. (org-agenda nil thiscmdkey))
  2966. (set-buffer bufname)
  2967. (while files
  2968. (org-eval-in-environment (append org-agenda-exporter-settings
  2969. opts pars)
  2970. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2971. (and (get-buffer bufname)
  2972. (kill-buffer bufname)))))))
  2973. (defvar org-agenda-current-span nil
  2974. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2975. (defun org-agenda-mark-header-line (pos)
  2976. "Mark the line at POS as an agenda structure header."
  2977. (save-excursion
  2978. (goto-char pos)
  2979. (put-text-property (point-at-bol) (point-at-eol)
  2980. 'org-agenda-structural-header t)
  2981. (when org-agenda-title-append
  2982. (put-text-property (point-at-bol) (point-at-eol)
  2983. 'org-agenda-title-append org-agenda-title-append))))
  2984. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2985. (defvar org-agenda-write-buffer-name "Agenda View")
  2986. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2987. "Write the current buffer (an agenda view) as a file.
  2988. Depending on the extension of the file name, plain text (.txt),
  2989. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2990. If the extension is .ics, run icalendar export over all files used
  2991. to construct the agenda and limit the export to entries listed in the
  2992. agenda now.
  2993. If the extension is .org, collect all subtrees corresponding to the
  2994. agenda entries and add them in an .org file.
  2995. With prefix argument OPEN, open the new file immediately.
  2996. If NOSETTINGS is given, do not scope the settings of
  2997. `org-agenda-exporter-settings' into the export commands. This is used when
  2998. the settings have already been scoped and we do not wish to overrule other,
  2999. higher priority settings.
  3000. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3001. (interactive "FWrite agenda to file: \nP")
  3002. (if (or (not (file-writable-p file))
  3003. (and (file-exists-p file)
  3004. (if (org-called-interactively-p 'any)
  3005. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3006. (user-error "Cannot write agenda to file %s" file))
  3007. (org-let (if nosettings nil org-agenda-exporter-settings)
  3008. '(save-excursion
  3009. (save-window-excursion
  3010. (org-agenda-mark-filtered-text)
  3011. (let ((bs (copy-sequence (buffer-string))) beg content)
  3012. (org-agenda-unmark-filtered-text)
  3013. (with-temp-buffer
  3014. (rename-buffer org-agenda-write-buffer-name t)
  3015. (set-buffer-modified-p nil)
  3016. (insert bs)
  3017. (org-agenda-remove-marked-text 'org-filtered)
  3018. (while (setq beg (text-property-any (point-min) (point-max)
  3019. 'org-filtered t))
  3020. (delete-region
  3021. beg (or (next-single-property-change beg 'org-filtered)
  3022. (point-max))))
  3023. (run-hooks 'org-agenda-before-write-hook)
  3024. (cond
  3025. ((org-bound-and-true-p org-mobile-creating-agendas)
  3026. (org-mobile-write-agenda-for-mobile file))
  3027. ((string-match "\\.org\\'" file)
  3028. (let (content p m message-log-max)
  3029. (goto-char (point-min))
  3030. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3031. (goto-char p)
  3032. (setq m (get-text-property (point) 'org-hd-marker))
  3033. (when m
  3034. (push (save-excursion
  3035. (set-buffer (marker-buffer m))
  3036. (goto-char m)
  3037. (org-copy-subtree 1 nil t t)
  3038. org-subtree-clip)
  3039. content)))
  3040. (find-file file)
  3041. (erase-buffer)
  3042. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3043. (write-file file)
  3044. (kill-buffer (current-buffer))
  3045. (message "Org file written to %s" file)))
  3046. ((string-match "\\.html?\\'" file)
  3047. (require 'htmlize)
  3048. (set-buffer (htmlize-buffer (current-buffer)))
  3049. (when org-agenda-export-html-style
  3050. ;; replace <style> section with org-agenda-export-html-style
  3051. (goto-char (point-min))
  3052. (kill-region (- (search-forward "<style") 6)
  3053. (search-forward "</style>"))
  3054. (insert org-agenda-export-html-style))
  3055. (write-file file)
  3056. (kill-buffer (current-buffer))
  3057. (message "HTML written to %s" file))
  3058. ((string-match "\\.ps\\'" file)
  3059. (require 'ps-print)
  3060. (ps-print-buffer-with-faces file)
  3061. (message "Postscript written to %s" file))
  3062. ((string-match "\\.pdf\\'" file)
  3063. (require 'ps-print)
  3064. (ps-print-buffer-with-faces
  3065. (concat (file-name-sans-extension file) ".ps"))
  3066. (call-process "ps2pdf" nil nil nil
  3067. (expand-file-name
  3068. (concat (file-name-sans-extension file) ".ps"))
  3069. (expand-file-name file))
  3070. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3071. (message "PDF written to %s" file))
  3072. ((string-match "\\.ics\\'" file)
  3073. (require 'ox-icalendar)
  3074. (org-icalendar-export-current-agenda (expand-file-name file)))
  3075. (t
  3076. (let ((bs (buffer-string)))
  3077. (find-file file)
  3078. (erase-buffer)
  3079. (insert bs)
  3080. (save-buffer 0)
  3081. (kill-buffer (current-buffer))
  3082. (message "Plain text written to %s" file))))))))
  3083. (set-buffer (or agenda-bufname
  3084. (and (org-called-interactively-p 'any) (buffer-name))
  3085. org-agenda-buffer-name)))
  3086. (when open (org-open-file file)))
  3087. (defvar org-agenda-tag-filter-overlays nil)
  3088. (defvar org-agenda-cat-filter-overlays nil)
  3089. (defvar org-agenda-re-filter-overlays nil)
  3090. (defun org-agenda-mark-filtered-text ()
  3091. "Mark all text hidden by filtering with a text property."
  3092. (let ((inhibit-read-only t))
  3093. (mapc
  3094. (lambda (o)
  3095. (when (equal (overlay-buffer o) (current-buffer))
  3096. (put-text-property
  3097. (overlay-start o) (overlay-end o)
  3098. 'org-filtered t)))
  3099. (append org-agenda-tag-filter-overlays
  3100. org-agenda-cat-filter-overlays
  3101. org-agenda-re-filter-overlays))))
  3102. (defun org-agenda-unmark-filtered-text ()
  3103. "Remove the filtering text property."
  3104. (let ((inhibit-read-only t))
  3105. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3106. (defun org-agenda-remove-marked-text (property &optional value)
  3107. "Delete all text marked with VALUE of PROPERTY.
  3108. VALUE defaults to t."
  3109. (let (beg)
  3110. (setq value (or value t))
  3111. (while (setq beg (text-property-any (point-min) (point-max)
  3112. property value))
  3113. (delete-region
  3114. beg (or (next-single-property-change beg 'org-filtered)
  3115. (point-max))))))
  3116. (defun org-agenda-add-entry-text ()
  3117. "Add entry text to agenda lines.
  3118. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3119. entry text following headings shown in the agenda.
  3120. Drawers will be excluded, also the line with scheduling/deadline info."
  3121. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3122. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3123. (let (m txt)
  3124. (goto-char (point-min))
  3125. (while (not (eobp))
  3126. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3127. (beginning-of-line 2)
  3128. (setq txt (org-agenda-get-some-entry-text
  3129. m org-agenda-add-entry-text-maxlines " > "))
  3130. (end-of-line 1)
  3131. (if (string-match "\\S-" txt)
  3132. (insert "\n" txt)
  3133. (or (eobp) (forward-char 1))))))))
  3134. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3135. &rest keep)
  3136. "Extract entry text from MARKER, at most N-LINES lines.
  3137. This will ignore drawers etc, just get the text.
  3138. If INDENT is given, prefix every line with this string. If KEEP is
  3139. given, it is a list of symbols, defining stuff that should not be
  3140. removed from the entry content. Currently only `planning' is allowed here."
  3141. (let (txt drawer-re kwd-time-re ind)
  3142. (save-excursion
  3143. (with-current-buffer (marker-buffer marker)
  3144. (if (not (derived-mode-p 'org-mode))
  3145. (setq txt "")
  3146. (save-excursion
  3147. (save-restriction
  3148. (widen)
  3149. (goto-char marker)
  3150. (end-of-line 1)
  3151. (setq txt (buffer-substring
  3152. (min (1+ (point)) (point-max))
  3153. (progn (outline-next-heading) (point)))
  3154. drawer-re org-drawer-regexp
  3155. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3156. ".*\n?"))
  3157. (with-temp-buffer
  3158. (insert txt)
  3159. (when org-agenda-add-entry-text-descriptive-links
  3160. (goto-char (point-min))
  3161. (while (org-activate-bracket-links (point-max))
  3162. (add-text-properties (match-beginning 0) (match-end 0)
  3163. '(face org-link))))
  3164. (goto-char (point-min))
  3165. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3166. (set-text-properties (match-beginning 0) (match-end 0)
  3167. nil))
  3168. (goto-char (point-min))
  3169. (while (re-search-forward drawer-re nil t)
  3170. (delete-region
  3171. (match-beginning 0)
  3172. (progn (re-search-forward
  3173. "^[ \t]*:END:.*\n?" nil 'move)
  3174. (point))))
  3175. (unless (member 'planning keep)
  3176. (goto-char (point-min))
  3177. (while (re-search-forward kwd-time-re nil t)
  3178. (replace-match "")))
  3179. (goto-char (point-min))
  3180. (when org-agenda-entry-text-exclude-regexps
  3181. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3182. (while (setq re (pop re-list))
  3183. (goto-char (point-min))
  3184. (while (re-search-forward re nil t)
  3185. (replace-match "")))))
  3186. (goto-char (point-max))
  3187. (skip-chars-backward " \t\n")
  3188. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3189. ;; find and remove min common indentation
  3190. (goto-char (point-min))
  3191. (untabify (point-min) (point-max))
  3192. (setq ind (org-get-indentation))
  3193. (while (not (eobp))
  3194. (unless (looking-at "[ \t]*$")
  3195. (setq ind (min ind (org-get-indentation))))
  3196. (beginning-of-line 2))
  3197. (goto-char (point-min))
  3198. (while (not (eobp))
  3199. (unless (looking-at "[ \t]*$")
  3200. (move-to-column ind)
  3201. (delete-region (point-at-bol) (point)))
  3202. (beginning-of-line 2))
  3203. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3204. (goto-char (point-min))
  3205. (when indent
  3206. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3207. (replace-match indent t t)))
  3208. (goto-char (point-min))
  3209. (while (looking-at "[ \t]*\n") (replace-match ""))
  3210. (goto-char (point-max))
  3211. (when (> (org-current-line)
  3212. n-lines)
  3213. (org-goto-line (1+ n-lines))
  3214. (backward-char 1))
  3215. (setq txt (buffer-substring (point-min) (point)))))))))
  3216. txt))
  3217. (defun org-check-for-org-mode ()
  3218. "Make sure current buffer is in org-mode. Error if not."
  3219. (or (derived-mode-p 'org-mode)
  3220. (error "Cannot execute org-mode agenda command on buffer in %s"
  3221. major-mode)))
  3222. ;;; Agenda prepare and finalize
  3223. (defvar org-agenda-multi nil) ; dynamically scoped
  3224. (defvar org-agenda-pre-window-conf nil)
  3225. (defvar org-agenda-columns-active nil)
  3226. (defvar org-agenda-name nil)
  3227. (defvar org-agenda-tag-filter nil)
  3228. (defvar org-agenda-category-filter nil)
  3229. (defvar org-agenda-regexp-filter nil)
  3230. (defvar org-agenda-top-headline-filter nil)
  3231. (defvar org-agenda-tag-filter-while-redo nil)
  3232. (defvar org-agenda-tag-filter-preset nil
  3233. "A preset of the tags filter used for secondary agenda filtering.
  3234. This must be a list of strings, each string must be a single tag preceded
  3235. by \"+\" or \"-\".
  3236. This variable should not be set directly, but agenda custom commands can
  3237. bind it in the options section. The preset filter is a global property of
  3238. the entire agenda view. In a block agenda, it will not work reliably to
  3239. define a filter for one of the individual blocks. You need to set it in
  3240. the global options and expect it to be applied to the entire view.")
  3241. (defvar org-agenda-category-filter-preset nil
  3242. "A preset of the category filter used for secondary agenda filtering.
  3243. This must be a list of strings, each string must be a single category
  3244. preceded by \"+\" or \"-\".
  3245. This variable should not be set directly, but agenda custom commands can
  3246. bind it in the options section. The preset filter is a global property of
  3247. the entire agenda view. In a block agenda, it will not work reliably to
  3248. define a filter for one of the individual blocks. You need to set it in
  3249. the global options and expect it to be applied to the entire view.")
  3250. (defvar org-agenda-regexp-filter-preset nil
  3251. "A preset of the regexp filter used for secondary agenda filtering.
  3252. This must be a list of strings, each string must be a single category
  3253. preceded by \"+\" or \"-\".
  3254. This variable should not be set directly, but agenda custom commands can
  3255. bind it in the options section. The preset filter is a global property of
  3256. the entire agenda view. In a block agenda, it will not work reliably to
  3257. define a filter for one of the individual blocks. You need to set it in
  3258. the global options and expect it to be applied to the entire view.")
  3259. (defun org-agenda-use-sticky-p ()
  3260. "Return non-nil if an agenda buffer named
  3261. `org-agenda-buffer-name' exists and should be shown instead of
  3262. generating a new one."
  3263. (and
  3264. ;; turned off by user
  3265. org-agenda-sticky
  3266. ;; For multi-agenda buffer already exists
  3267. (not org-agenda-multi)
  3268. ;; buffer found
  3269. (get-buffer org-agenda-buffer-name)
  3270. ;; C-u parameter is same as last call
  3271. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3272. (and
  3273. (equal current-prefix-arg
  3274. org-agenda-last-prefix-arg)
  3275. ;; In case user turned stickiness on, while having existing
  3276. ;; Agenda buffer active, don't reuse that buffer, because it
  3277. ;; does not have org variables local
  3278. org-agenda-this-buffer-is-sticky))))
  3279. (defun org-agenda-prepare-window (abuf)
  3280. "Setup agenda buffer in the window."
  3281. (let* ((awin (get-buffer-window abuf))
  3282. wconf)
  3283. (cond
  3284. ((equal (current-buffer) abuf) nil)
  3285. (awin (select-window awin))
  3286. ((not (setq wconf (current-window-configuration))))
  3287. ((equal org-agenda-window-setup 'current-window)
  3288. (org-pop-to-buffer-same-window abuf))
  3289. ((equal org-agenda-window-setup 'other-window)
  3290. (org-switch-to-buffer-other-window abuf))
  3291. ((equal org-agenda-window-setup 'other-frame)
  3292. (switch-to-buffer-other-frame abuf))
  3293. ((equal org-agenda-window-setup 'reorganize-frame)
  3294. (delete-other-windows)
  3295. (org-switch-to-buffer-other-window abuf)))
  3296. ;; additional test in case agenda is invoked from within agenda
  3297. ;; buffer via elisp link
  3298. (unless (equal (current-buffer) abuf)
  3299. (org-pop-to-buffer-same-window abuf))
  3300. (setq org-agenda-pre-window-conf
  3301. (or org-agenda-pre-window-conf wconf))))
  3302. (defun org-agenda-prepare (&optional name)
  3303. (if (org-agenda-use-sticky-p)
  3304. (progn
  3305. ;; Popup existing buffer
  3306. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3307. (message "Sticky Agenda buffer, use `r' to refresh")
  3308. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3309. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3310. (setq org-todo-keywords-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-agenda-last-prefix-arg current-prefix-arg)
  3350. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3351. (and name (not org-agenda-name)
  3352. (org-set-local 'org-agenda-name name)))
  3353. (setq buffer-read-only nil)))
  3354. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3355. (defun org-agenda-finalize ()
  3356. "Finishing touch for the agenda buffer, called just before displaying it."
  3357. (unless org-agenda-multi
  3358. (save-excursion
  3359. (let ((inhibit-read-only t))
  3360. (goto-char (point-min))
  3361. (save-excursion
  3362. (while (org-activate-bracket-links (point-max))
  3363. (add-text-properties (match-beginning 0) (match-end 0)
  3364. '(face org-link))))
  3365. (save-excursion
  3366. (while (org-activate-plain-links (point-max))
  3367. (add-text-properties (match-beginning 0) (match-end 0)
  3368. '(face org-link))))
  3369. (unless (eq org-agenda-remove-tags t)
  3370. (org-agenda-align-tags))
  3371. (unless org-agenda-with-colors
  3372. (remove-text-properties (point-min) (point-max) '(face nil)))
  3373. (if (and (boundp 'org-agenda-overriding-columns-format)
  3374. org-agenda-overriding-columns-format)
  3375. (org-set-local 'org-agenda-overriding-columns-format
  3376. org-agenda-overriding-columns-format))
  3377. (if (and (boundp 'org-agenda-view-columns-initially)
  3378. org-agenda-view-columns-initially)
  3379. (org-agenda-columns))
  3380. (when org-agenda-fontify-priorities
  3381. (org-agenda-fontify-priorities))
  3382. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3383. (org-agenda-dim-blocked-tasks))
  3384. ;; We need to widen when `org-agenda-finalize' is called from
  3385. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3386. (when org-clock-current-task
  3387. (save-restriction
  3388. (widen)
  3389. (org-agenda-mark-clocking-task)))
  3390. (when org-agenda-entry-text-mode
  3391. (org-agenda-entry-text-hide)
  3392. (org-agenda-entry-text-show))
  3393. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3394. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3395. (org-habit-insert-consistency-graphs))
  3396. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3397. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3398. (and (listp org-agenda-show-inherited-tags)
  3399. (memq org-agenda-type org-agenda-show-inherited-tags))
  3400. (and (eq org-agenda-show-inherited-tags t)
  3401. (or (eq org-agenda-use-tag-inheritance t)
  3402. (and (listp org-agenda-use-tag-inheritance)
  3403. (not (memq org-agenda-type
  3404. org-agenda-use-tag-inheritance))))))
  3405. (let (mrk)
  3406. (save-excursion
  3407. (goto-char (point-min))
  3408. (while (equal (forward-line) 0)
  3409. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3410. (get-text-property (point) 'org-hd-marker)))
  3411. (put-text-property (point-at-bol) (point-at-eol)
  3412. 'tags (org-with-point-at mrk
  3413. (delete-dups
  3414. (mapcar 'downcase (org-get-tags-at))))))))))
  3415. (run-hooks 'org-agenda-finalize-hook)
  3416. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3417. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3418. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3419. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3420. (when (or org-agenda-regexp-filter (get 'org-agenda-regexp-filter :preset-filter))
  3421. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3422. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3423. (defun org-agenda-mark-clocking-task ()
  3424. "Mark the current clock entry in the agenda if it is present."
  3425. (org-agenda-unmark-clocking-task)
  3426. (when (marker-buffer org-clock-hd-marker)
  3427. (save-excursion
  3428. (goto-char (point-min))
  3429. (let (s ov)
  3430. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3431. (goto-char s)
  3432. (when (equal (org-get-at-bol 'org-hd-marker)
  3433. org-clock-hd-marker)
  3434. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3435. (overlay-put ov 'type 'org-agenda-clocking)
  3436. (overlay-put ov 'face 'org-agenda-clocking)
  3437. (overlay-put ov 'help-echo
  3438. "The clock is running in this item")))))))
  3439. (defun org-agenda-unmark-clocking-task ()
  3440. "Unmark the current clocking task."
  3441. (mapc (lambda (o)
  3442. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3443. (delete-overlay o)))
  3444. (overlays-in (point-min) (point-max))))
  3445. (defun org-agenda-fontify-priorities ()
  3446. "Make highest priority lines bold, and lowest italic."
  3447. (interactive)
  3448. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3449. (delete-overlay o)))
  3450. (overlays-in (point-min) (point-max)))
  3451. (save-excursion
  3452. (let (b e p ov h l)
  3453. (goto-char (point-min))
  3454. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3455. (setq h (or (get-char-property (point) 'org-highest-priority)
  3456. org-highest-priority)
  3457. l (or (get-char-property (point) 'org-lowest-priority)
  3458. org-lowest-priority)
  3459. p (string-to-char (match-string 1))
  3460. b (match-beginning 0)
  3461. e (if (eq org-agenda-fontify-priorities 'cookies)
  3462. (match-end 0)
  3463. (point-at-eol))
  3464. ov (make-overlay b e))
  3465. (overlay-put
  3466. ov 'face
  3467. (cons (cond ((org-face-from-face-or-color
  3468. 'priority nil
  3469. (cdr (assoc p org-priority-faces))))
  3470. ((and (listp org-agenda-fontify-priorities)
  3471. (org-face-from-face-or-color
  3472. 'priority nil
  3473. (cdr (assoc p org-agenda-fontify-priorities)))))
  3474. ((equal p l) 'italic)
  3475. ((equal p h) 'bold))
  3476. 'org-priority))
  3477. (overlay-put ov 'org-type 'org-priority)))))
  3478. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3479. "Dim currently blocked TODO's in the agenda display.
  3480. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3481. dimming them."
  3482. (interactive "P")
  3483. (when (org-called-interactively-p 'interactive)
  3484. (message "Dim or hide blocked tasks..."))
  3485. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3486. (delete-overlay o)))
  3487. (overlays-in (point-min) (point-max)))
  3488. (save-excursion
  3489. (let ((inhibit-read-only t)
  3490. (org-depend-tag-blocked nil)
  3491. (invis (or (not (null invisible))
  3492. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3493. org-blocked-by-checkboxes
  3494. invis1 b e p ov h l)
  3495. (goto-char (point-min))
  3496. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3497. (and pos (goto-char (1+ pos))))
  3498. (setq org-blocked-by-checkboxes nil invis1 invis)
  3499. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3500. (when (and marker
  3501. (with-current-buffer (marker-buffer marker)
  3502. (save-excursion (goto-char marker)
  3503. (org-entry-blocked-p))))
  3504. (if org-blocked-by-checkboxes (setq invis1 nil))
  3505. (setq b (if invis1
  3506. (max (point-min) (1- (point-at-bol)))
  3507. (point-at-bol))
  3508. e (point-at-eol)
  3509. ov (make-overlay b e))
  3510. (if invis1
  3511. (overlay-put ov 'invisible t)
  3512. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3513. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3514. (when (org-called-interactively-p 'interactive)
  3515. (message "Dim or hide blocked tasks...done")))
  3516. (defvar org-agenda-skip-function nil
  3517. "Function to be called at each match during agenda construction.
  3518. If this function returns nil, the current match should not be skipped.
  3519. Otherwise, the function must return a position from where the search
  3520. should be continued.
  3521. This may also be a Lisp form, it will be evaluated.
  3522. Never set this variable using `setq' or so, because then it will apply
  3523. to all future agenda commands. If you do want a global skipping condition,
  3524. use the option `org-agenda-skip-function-global' instead.
  3525. The correct usage for `org-agenda-skip-function' is to bind it with
  3526. `let' to scope it dynamically into the agenda-constructing command.
  3527. A good way to set it is through options in `org-agenda-custom-commands'.")
  3528. (defun org-agenda-skip ()
  3529. "Throw to `:skip' in places that should be skipped.
  3530. Also moves point to the end of the skipped region, so that search can
  3531. continue from there."
  3532. (let ((p (point-at-bol)) to)
  3533. (when (or
  3534. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3535. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3536. (get-text-property p :org-archived)
  3537. (org-end-of-subtree t))
  3538. (and org-agenda-skip-comment-trees
  3539. (get-text-property p :org-comment)
  3540. (org-end-of-subtree t))
  3541. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3542. (org-agenda-skip-eval org-agenda-skip-function)))
  3543. (goto-char to))
  3544. (org-in-src-block-p t))
  3545. (throw :skip t))))
  3546. (defun org-agenda-skip-eval (form)
  3547. "If FORM is a function or a list, call (or eval) it and return the result.
  3548. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3549. and match data are returned to the previous state no matter what these
  3550. functions do."
  3551. (let (fp)
  3552. (and form
  3553. (or (setq fp (functionp form))
  3554. (consp form))
  3555. (save-excursion
  3556. (save-match-data
  3557. (if fp
  3558. (funcall form)
  3559. (eval form)))))))
  3560. (defvar org-agenda-markers nil
  3561. "List of all currently active markers created by `org-agenda'.")
  3562. (defvar org-agenda-last-marker-time (org-float-time)
  3563. "Creation time of the last agenda marker.")
  3564. (defun org-agenda-new-marker (&optional pos)
  3565. "Return a new agenda marker.
  3566. Org-mode keeps a list of these markers and resets them when they are
  3567. no longer in use."
  3568. (let ((m (copy-marker (or pos (point)))))
  3569. (setq org-agenda-last-marker-time (org-float-time))
  3570. (if org-agenda-buffer
  3571. (with-current-buffer org-agenda-buffer
  3572. (push m org-agenda-markers))
  3573. (push m org-agenda-markers))
  3574. m))
  3575. (defun org-agenda-reset-markers ()
  3576. "Reset markers created by `org-agenda'."
  3577. (while org-agenda-markers
  3578. (move-marker (pop org-agenda-markers) nil)))
  3579. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3580. "Save relative positions of markers in region.
  3581. This check for agenda markers in all agenda buffers currently active."
  3582. (dolist (buf (buffer-list))
  3583. (with-current-buffer buf
  3584. (when (eq major-mode 'org-agenda-mode)
  3585. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3586. org-agenda-markers)))))
  3587. ;;; Entry text mode
  3588. (defun org-agenda-entry-text-show-here ()
  3589. "Add some text from the entry as context to the current line."
  3590. (let (m txt o)
  3591. (setq m (org-get-at-bol 'org-hd-marker))
  3592. (unless (marker-buffer m)
  3593. (error "No marker points to an entry here"))
  3594. (setq txt (concat "\n" (org-no-properties
  3595. (org-agenda-get-some-entry-text
  3596. m org-agenda-entry-text-maxlines
  3597. org-agenda-entry-text-leaders))))
  3598. (when (string-match "\\S-" txt)
  3599. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3600. (overlay-put o 'evaporate t)
  3601. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3602. (overlay-put o 'after-string txt))))
  3603. (defun org-agenda-entry-text-show ()
  3604. "Add entry context for all agenda lines."
  3605. (interactive)
  3606. (save-excursion
  3607. (goto-char (point-max))
  3608. (beginning-of-line 1)
  3609. (while (not (bobp))
  3610. (when (org-get-at-bol 'org-hd-marker)
  3611. (org-agenda-entry-text-show-here))
  3612. (beginning-of-line 0))))
  3613. (defun org-agenda-entry-text-hide ()
  3614. "Remove any shown entry context."
  3615. (delq nil
  3616. (mapcar (lambda (o)
  3617. (if (eq (overlay-get o 'org-overlay-type)
  3618. 'agenda-entry-content)
  3619. (progn (delete-overlay o) t)))
  3620. (overlays-in (point-min) (point-max)))))
  3621. (defun org-agenda-get-day-face (date)
  3622. "Return the face DATE should be displayed with."
  3623. (or (and (functionp org-agenda-day-face-function)
  3624. (funcall org-agenda-day-face-function date))
  3625. (cond ((org-agenda-todayp date)
  3626. 'org-agenda-date-today)
  3627. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3628. 'org-agenda-date-weekend)
  3629. (t 'org-agenda-date))))
  3630. ;;; Agenda timeline
  3631. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3632. (defun org-timeline (&optional dotodo)
  3633. "Show a time-sorted view of the entries in the current org file.
  3634. Only entries with a time stamp of today or later will be listed. With
  3635. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3636. under the current date.
  3637. If the buffer contains an active region, only check the region for
  3638. dates."
  3639. (interactive "P")
  3640. (let* ((dopast t)
  3641. (org-agenda-show-log-scoped org-agenda-show-log)
  3642. (org-agenda-show-log org-agenda-show-log-scoped)
  3643. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3644. (current-buffer))))
  3645. (date (calendar-current-date))
  3646. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3647. (end (if (org-region-active-p) (region-end) (point-max)))
  3648. (day-numbers (org-get-all-dates
  3649. beg end 'no-ranges
  3650. t org-agenda-show-log-scoped ; always include today
  3651. org-timeline-show-empty-dates))
  3652. (org-deadline-warning-days 0)
  3653. (org-agenda-only-exact-dates t)
  3654. (today (org-today))
  3655. (past t)
  3656. args
  3657. s e rtn d emptyp)
  3658. (setq org-agenda-redo-command
  3659. (list 'let
  3660. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3661. (list 'org-switch-to-buffer-other-window (current-buffer))
  3662. (list 'org-timeline (list 'quote dotodo))))
  3663. (put 'org-agenda-redo-command 'org-lprops nil)
  3664. (if (not dopast)
  3665. ;; Remove past dates from the list of dates.
  3666. (setq day-numbers (delq nil (mapcar (lambda(x)
  3667. (if (>= x today) x nil))
  3668. day-numbers))))
  3669. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3670. (org-compile-prefix-format 'timeline)
  3671. (org-set-sorting-strategy 'timeline)
  3672. (if org-agenda-show-log-scoped (push :closed args))
  3673. (push :timestamp args)
  3674. (push :deadline args)
  3675. (push :scheduled args)
  3676. (push :sexp args)
  3677. (if dotodo (push :todo args))
  3678. (insert "Timeline of file " entry "\n")
  3679. (add-text-properties (point-min) (point)
  3680. (list 'face 'org-agenda-structure))
  3681. (org-agenda-mark-header-line (point-min))
  3682. (while (setq d (pop day-numbers))
  3683. (if (and (listp d) (eq (car d) :omitted))
  3684. (progn
  3685. (setq s (point))
  3686. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3687. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3688. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3689. (if (and (>= d today)
  3690. dopast
  3691. past)
  3692. (progn
  3693. (setq past nil)
  3694. (insert (make-string 79 ?-) "\n")))
  3695. (setq date (calendar-gregorian-from-absolute d))
  3696. (setq s (point))
  3697. (setq rtn (and (not emptyp)
  3698. (apply 'org-agenda-get-day-entries entry
  3699. date args)))
  3700. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3701. (progn
  3702. (insert
  3703. (if (stringp org-agenda-format-date)
  3704. (format-time-string org-agenda-format-date
  3705. (org-time-from-absolute date))
  3706. (funcall org-agenda-format-date date))
  3707. "\n")
  3708. (put-text-property s (1- (point)) 'face
  3709. (org-agenda-get-day-face date))
  3710. (put-text-property s (1- (point)) 'org-date-line t)
  3711. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3712. (if (equal d today)
  3713. (put-text-property s (1- (point)) 'org-today t))
  3714. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3715. (put-text-property s (1- (point)) 'day d)))))
  3716. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3717. (point-min)))
  3718. (add-text-properties
  3719. (point-min) (point-max)
  3720. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3721. (org-agenda-finalize)
  3722. (setq buffer-read-only t)))
  3723. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3724. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3725. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3726. not every single day in the range. If FORCE-TODAY is non-nil, make
  3727. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3728. inactive time stamps (those in square brackets) are included.
  3729. When EMPTY is non-nil, also include days without any entries."
  3730. (let ((re (concat
  3731. (if pre-re pre-re "")
  3732. (if inactive org-ts-regexp-both org-ts-regexp)))
  3733. dates dates1 date day day1 day2 ts1 ts2 pos)
  3734. (if force-today
  3735. (setq dates (list (org-today))))
  3736. (save-excursion
  3737. (goto-char beg)
  3738. (while (re-search-forward re end t)
  3739. (setq day (time-to-days (org-time-string-to-time
  3740. (substring (match-string 1) 0 10)
  3741. (current-buffer) (match-beginning 0))))
  3742. (or (memq day dates) (push day dates)))
  3743. (unless no-ranges
  3744. (goto-char beg)
  3745. (while (re-search-forward org-tr-regexp end t)
  3746. (setq pos (match-beginning 0))
  3747. (setq ts1 (substring (match-string 1) 0 10)
  3748. ts2 (substring (match-string 2) 0 10)
  3749. day1 (time-to-days (org-time-string-to-time
  3750. ts1 (current-buffer) pos))
  3751. day2 (time-to-days (org-time-string-to-time
  3752. ts2 (current-buffer) pos)))
  3753. (while (< (setq day1 (1+ day1)) day2)
  3754. (or (memq day1 dates) (push day1 dates)))))
  3755. (setq dates (sort dates '<))
  3756. (when empty
  3757. (while (setq day (pop dates))
  3758. (setq day2 (car dates))
  3759. (push day dates1)
  3760. (when (and day2 empty)
  3761. (if (or (eq empty t)
  3762. (and (numberp empty) (<= (- day2 day) empty)))
  3763. (while (< (setq day (1+ day)) day2)
  3764. (push (list day) dates1))
  3765. (push (cons :omitted (- day2 day)) dates1))))
  3766. (setq dates (nreverse dates1)))
  3767. dates)))
  3768. ;;; Agenda Daily/Weekly
  3769. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3770. "Start day for the agenda view.
  3771. Custom commands can set this variable in the options section.
  3772. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3773. input allowed when reading a date through the Org calendar.
  3774. See the docstring of `org-read-date' for details.")
  3775. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3776. (defvar org-arg-loc nil) ; local variable
  3777. (defvar org-agenda-buffer-tmp-name nil)
  3778. ;;;###autoload
  3779. (defun org-agenda-list (&optional arg start-day span with-hour)
  3780. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3781. The view will be for the current day or week, but from the overview buffer
  3782. you will be able to go to other days/weeks.
  3783. With a numeric prefix argument in an interactive call, the agenda will
  3784. span ARG days. Lisp programs should instead specify SPAN to change
  3785. the number of days. SPAN defaults to `org-agenda-span'.
  3786. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3787. given in `org-agenda-start-on-weekday'.
  3788. When WITH-HOUR is non-nil, only include scheduled and deadline
  3789. items if they have an hour specification like [h]h:mm."
  3790. (interactive "P")
  3791. (if org-agenda-overriding-arguments
  3792. (setq arg (car org-agenda-overriding-arguments)
  3793. start-day (nth 1 org-agenda-overriding-arguments)
  3794. span (nth 2 org-agenda-overriding-arguments)))
  3795. (if (and (integerp arg) (> arg 0))
  3796. (setq span arg arg nil))
  3797. (catch 'exit
  3798. (setq org-agenda-buffer-name
  3799. (or org-agenda-buffer-tmp-name
  3800. (if org-agenda-sticky
  3801. (cond ((and org-keys (stringp org-match))
  3802. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3803. (org-keys
  3804. (format "*Org Agenda(%s)*" org-keys))
  3805. (t "*Org Agenda(a)*")))
  3806. org-agenda-buffer-name))
  3807. (org-agenda-prepare "Day/Week")
  3808. (setq start-day (or start-day org-agenda-start-day))
  3809. (if (stringp start-day)
  3810. ;; Convert to an absolute day number
  3811. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3812. (org-compile-prefix-format 'agenda)
  3813. (org-set-sorting-strategy 'agenda)
  3814. (let* ((span (org-agenda-ndays-to-span
  3815. (or span org-agenda-ndays org-agenda-span)))
  3816. (today (org-today))
  3817. (sd (or start-day today))
  3818. (ndays (org-agenda-span-to-ndays span sd))
  3819. (org-agenda-start-on-weekday
  3820. (if (or (eq ndays 7) (eq ndays 14))
  3821. org-agenda-start-on-weekday))
  3822. (thefiles (org-agenda-files nil 'ifmode))
  3823. (files thefiles)
  3824. (start (if (or (null org-agenda-start-on-weekday)
  3825. (< ndays 7))
  3826. sd
  3827. (let* ((nt (calendar-day-of-week
  3828. (calendar-gregorian-from-absolute sd)))
  3829. (n1 org-agenda-start-on-weekday)
  3830. (d (- nt n1)))
  3831. (- sd (+ (if (< d 0) 7 0) d)))))
  3832. (day-numbers (list start))
  3833. (day-cnt 0)
  3834. (inhibit-redisplay (not debug-on-error))
  3835. (org-agenda-show-log-scoped org-agenda-show-log)
  3836. s e rtn rtnall file date d start-pos end-pos todayp
  3837. clocktable-start clocktable-end filter)
  3838. (setq org-agenda-redo-command
  3839. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3840. (dotimes (n (1- ndays))
  3841. (push (1+ (car day-numbers)) day-numbers))
  3842. (setq day-numbers (nreverse day-numbers))
  3843. (setq clocktable-start (car day-numbers)
  3844. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3845. (org-set-local 'org-starting-day (car day-numbers))
  3846. (org-set-local 'org-arg-loc arg)
  3847. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3848. (unless org-agenda-compact-blocks
  3849. (let* ((d1 (car day-numbers))
  3850. (d2 (org-last day-numbers))
  3851. (w1 (org-days-to-iso-week d1))
  3852. (w2 (org-days-to-iso-week d2)))
  3853. (setq s (point))
  3854. (if org-agenda-overriding-header
  3855. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3856. nil 'face 'org-agenda-structure) "\n")
  3857. (insert (org-agenda-span-name span)
  3858. "-agenda"
  3859. (if (< (- d2 d1) 350)
  3860. (if (= w1 w2)
  3861. (format " (W%02d)" w1)
  3862. (format " (W%02d-W%02d)" w1 w2))
  3863. "")
  3864. ":\n")))
  3865. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3866. 'org-date-line t))
  3867. (org-agenda-mark-header-line s))
  3868. (while (setq d (pop day-numbers))
  3869. (setq date (calendar-gregorian-from-absolute d)
  3870. s (point))
  3871. (if (or (setq todayp (= d today))
  3872. (and (not start-pos) (= d sd)))
  3873. (setq start-pos (point))
  3874. (if (and start-pos (not end-pos))
  3875. (setq end-pos (point))))
  3876. (setq files thefiles
  3877. rtnall nil)
  3878. (while (setq file (pop files))
  3879. (catch 'nextfile
  3880. (org-check-agenda-file file)
  3881. (let ((org-agenda-entry-types org-agenda-entry-types))
  3882. ;; Starred types override non-starred equivalents
  3883. (when (member :deadline* org-agenda-entry-types)
  3884. (setq org-agenda-entry-types
  3885. (delq :deadline org-agenda-entry-types)))
  3886. (when (member :scheduled* org-agenda-entry-types)
  3887. (setq org-agenda-entry-types
  3888. (delq :scheduled org-agenda-entry-types)))
  3889. ;; Honor with-hour
  3890. (when with-hour
  3891. (when (member :deadline org-agenda-entry-types)
  3892. (setq org-agenda-entry-types
  3893. (delq :deadline org-agenda-entry-types))
  3894. (push :deadline* org-agenda-entry-types))
  3895. (when (member :scheduled org-agenda-entry-types)
  3896. (setq org-agenda-entry-types
  3897. (delq :scheduled org-agenda-entry-types))
  3898. (push :scheduled* org-agenda-entry-types)))
  3899. (unless org-agenda-include-deadlines
  3900. (setq org-agenda-entry-types
  3901. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3902. (cond
  3903. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3904. (setq rtn (org-agenda-get-day-entries
  3905. file date :closed)))
  3906. (org-agenda-show-log-scoped
  3907. (setq rtn (apply 'org-agenda-get-day-entries
  3908. file date
  3909. (append '(:closed) org-agenda-entry-types))))
  3910. (t
  3911. (setq rtn (apply 'org-agenda-get-day-entries
  3912. file date
  3913. org-agenda-entry-types)))))
  3914. (setq rtnall (append rtnall rtn)))) ;; all entries
  3915. (if org-agenda-include-diary
  3916. (let ((org-agenda-search-headline-for-time t))
  3917. (require 'diary-lib)
  3918. (setq rtn (org-get-entries-from-diary date))
  3919. (setq rtnall (append rtnall rtn))))
  3920. (if (or rtnall org-agenda-show-all-dates)
  3921. (progn
  3922. (setq day-cnt (1+ day-cnt))
  3923. (insert
  3924. (if (stringp org-agenda-format-date)
  3925. (format-time-string org-agenda-format-date
  3926. (org-time-from-absolute date))
  3927. (funcall org-agenda-format-date date))
  3928. "\n")
  3929. (put-text-property s (1- (point)) 'face
  3930. (org-agenda-get-day-face date))
  3931. (put-text-property s (1- (point)) 'org-date-line t)
  3932. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3933. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3934. (when todayp
  3935. (put-text-property s (1- (point)) 'org-today t))
  3936. (setq rtnall
  3937. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3938. (if rtnall (insert ;; all entries
  3939. (org-agenda-finalize-entries rtnall 'agenda)
  3940. "\n"))
  3941. (put-text-property s (1- (point)) 'day d)
  3942. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3943. (when (and org-agenda-clockreport-mode clocktable-start)
  3944. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3945. ;; the above line is to ensure the restricted range!
  3946. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3947. tbl)
  3948. (setq p (org-plist-delete p :block))
  3949. (setq p (plist-put p :tstart clocktable-start))
  3950. (setq p (plist-put p :tend clocktable-end))
  3951. (setq p (plist-put p :scope 'agenda))
  3952. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3953. (setq filter (or org-agenda-tag-filter-while-redo
  3954. (get 'org-agenda-tag-filter :preset-filter))))
  3955. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3956. (if (string-match "[<>=]" x)
  3957. ""
  3958. x))
  3959. filter ""))))
  3960. (setq tbl (apply 'org-clock-get-clocktable p))
  3961. (insert tbl)))
  3962. (goto-char (point-min))
  3963. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3964. (unless (and (pos-visible-in-window-p (point-min))
  3965. (pos-visible-in-window-p (point-max)))
  3966. (goto-char (1- (point-max)))
  3967. (recenter -1)
  3968. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3969. (progn
  3970. (goto-char (or start-pos 1))
  3971. (recenter 1))))
  3972. (goto-char (or start-pos 1))
  3973. (add-text-properties (point-min) (point-max)
  3974. `(org-agenda-type agenda
  3975. org-last-args (,arg ,start-day ,span)
  3976. org-redo-cmd ,org-agenda-redo-command
  3977. org-series-cmd ,org-cmd))
  3978. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3979. (org-agenda-show-clocking-issues))
  3980. (org-agenda-finalize)
  3981. (setq buffer-read-only t)
  3982. (message ""))))
  3983. (defun org-agenda-ndays-to-span (n)
  3984. "Return a span symbol for a span of N days, or N if none matches."
  3985. (cond ((symbolp n) n)
  3986. ((= n 1) 'day)
  3987. ((= n 7) 'week)
  3988. ((= n 14) 'fortnight)
  3989. (t n)))
  3990. (defun org-agenda-span-to-ndays (span &optional start-day)
  3991. "Return ndays from SPAN, possibly starting at START-DAY.
  3992. START-DAY is an absolute time value."
  3993. (cond ((numberp span) span)
  3994. ((eq span 'day) 1)
  3995. ((eq span 'week) 7)
  3996. ((eq span 'fortnight) 14)
  3997. ((eq span 'month)
  3998. (let ((date (calendar-gregorian-from-absolute start-day)))
  3999. (calendar-last-day-of-month (car date) (caddr date))))
  4000. ((eq span 'year)
  4001. (let ((date (calendar-gregorian-from-absolute start-day)))
  4002. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  4003. (defun org-agenda-span-name (span)
  4004. "Return a SPAN name."
  4005. (if (null span)
  4006. ""
  4007. (if (symbolp span)
  4008. (capitalize (symbol-name span))
  4009. (format "%d days" span))))
  4010. ;;; Agenda word search
  4011. (defvar org-agenda-search-history nil)
  4012. (defvar org-search-syntax-table nil
  4013. "Special syntax table for org-mode search.
  4014. In this table, we have single quotes not as word constituents, to
  4015. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4016. (defvar org-mode-syntax-table) ; From org.el
  4017. (defun org-search-syntax-table ()
  4018. (unless org-search-syntax-table
  4019. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4020. (modify-syntax-entry ?' "." org-search-syntax-table)
  4021. (modify-syntax-entry ?` "." org-search-syntax-table))
  4022. org-search-syntax-table)
  4023. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4024. ;;;###autoload
  4025. (defun org-search-view (&optional todo-only string edit-at)
  4026. "Show all entries that contain a phrase or words or regular expressions.
  4027. With optional prefix argument TODO-ONLY, only consider entries that are
  4028. TODO entries. The argument STRING can be used to pass a default search
  4029. string into this function. If EDIT-AT is non-nil, it means that the
  4030. user should get a chance to edit this string, with cursor at position
  4031. EDIT-AT.
  4032. The search string can be viewed either as a phrase that should be found as
  4033. is, or it can be broken into a number of snippets, each of which must match
  4034. in a Boolean way to select an entry. The default depends on the variable
  4035. `org-agenda-search-view-always-boolean'.
  4036. Even if this is turned off (the default) you can always switch to
  4037. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4038. The default is a direct search of the whole phrase, where each space in
  4039. the search string can expand to an arbitrary amount of whitespace,
  4040. including newlines.
  4041. If using a Boolean search, the search string is split on whitespace and
  4042. each snippet is searched separately, with logical AND to select an entry.
  4043. Words prefixed with a minus must *not* occur in the entry. Words without
  4044. a prefix or prefixed with a plus must occur in the entry. Matching is
  4045. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4046. match whole words, not parts of a word) if
  4047. `org-agenda-search-view-force-full-words' is set (default is nil).
  4048. Boolean search snippets enclosed by curly braces are interpreted as
  4049. regular expressions that must or (when preceded with \"-\") must not
  4050. match in the entry. Snippets enclosed into double quotes will be taken
  4051. as a whole, to include whitespace.
  4052. - If the search string starts with an asterisk, search only in headlines.
  4053. - If (possibly after the leading star) the search string starts with an
  4054. exclamation mark, this also means to look at TODO entries only, an effect
  4055. that can also be achieved with a prefix argument.
  4056. - If (possibly after star and exclamation mark) the search string starts
  4057. with a colon, this will mean that the (non-regexp) snippets of the
  4058. Boolean search must match as full words.
  4059. This command searches the agenda files, and in addition the files listed
  4060. in `org-agenda-text-search-extra-files'."
  4061. (interactive "P")
  4062. (if org-agenda-overriding-arguments
  4063. (setq todo-only (car org-agenda-overriding-arguments)
  4064. string (nth 1 org-agenda-overriding-arguments)
  4065. edit-at (nth 2 org-agenda-overriding-arguments)))
  4066. (let* ((props (list 'face nil
  4067. 'done-face 'org-agenda-done
  4068. 'org-not-done-regexp org-not-done-regexp
  4069. 'org-todo-regexp org-todo-regexp
  4070. 'org-complex-heading-regexp org-complex-heading-regexp
  4071. 'mouse-face 'highlight
  4072. 'help-echo (format "mouse-2 or RET jump to location")))
  4073. (full-words org-agenda-search-view-force-full-words)
  4074. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4075. regexp rtn rtnall files file pos inherited-tags
  4076. marker category category-pos level tags c neg re boolean
  4077. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4078. (unless (and (not edit-at)
  4079. (stringp string)
  4080. (string-match "\\S-" string))
  4081. (setq string (read-string
  4082. (if org-agenda-search-view-always-boolean
  4083. "[+-]Word/{Regexp} ...: "
  4084. "Phrase or [+-]Word/{Regexp} ...: ")
  4085. (cond
  4086. ((integerp edit-at) (cons string edit-at))
  4087. (edit-at string))
  4088. 'org-agenda-search-history)))
  4089. (catch 'exit
  4090. (if org-agenda-sticky
  4091. (setq org-agenda-buffer-name
  4092. (if (stringp string)
  4093. (format "*Org Agenda(%s:%s)*"
  4094. (or org-keys (or (and todo-only "S") "s")) string)
  4095. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4096. (org-agenda-prepare "SEARCH")
  4097. (org-compile-prefix-format 'search)
  4098. (org-set-sorting-strategy 'search)
  4099. (setq org-agenda-redo-command
  4100. (list 'org-search-view (if todo-only t nil)
  4101. (list 'if 'current-prefix-arg nil string)))
  4102. (setq org-agenda-query-string string)
  4103. (if (equal (string-to-char string) ?*)
  4104. (setq hdl-only t
  4105. words (substring string 1))
  4106. (setq words string))
  4107. (when (equal (string-to-char words) ?!)
  4108. (setq todo-only t
  4109. words (substring words 1)))
  4110. (when (equal (string-to-char words) ?:)
  4111. (setq full-words t
  4112. words (substring words 1)))
  4113. (if (or org-agenda-search-view-always-boolean
  4114. (member (string-to-char words) '(?- ?+ ?\{)))
  4115. (setq boolean t))
  4116. (setq words (org-split-string words))
  4117. (let (www w)
  4118. (while (setq w (pop words))
  4119. (while (and (string-match "\\\\\\'" w) words)
  4120. (setq w (concat (substring w 0 -1) " " (pop words))))
  4121. (push w www))
  4122. (setq words (nreverse www) www nil)
  4123. (while (setq w (pop words))
  4124. (when (and (string-match "\\`[-+]?{" w)
  4125. (not (string-match "}\\'" w)))
  4126. (while (and words (not (string-match "}\\'" (car words))))
  4127. (setq w (concat w " " (pop words))))
  4128. (setq w (concat w " " (pop words))))
  4129. (push w www))
  4130. (setq words (nreverse www)))
  4131. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4132. (when boolean
  4133. (let (wds w)
  4134. (while (setq w (pop words))
  4135. (if (or (equal (substring w 0 1) "\"")
  4136. (and (> (length w) 1)
  4137. (member (substring w 0 1) '("+" "-"))
  4138. (equal (substring w 1 2) "\"")))
  4139. (while (and words (not (equal (substring w -1) "\"")))
  4140. (setq w (concat w " " (pop words)))))
  4141. (and (string-match "\\`\\([-+]?\\)\"" w)
  4142. (setq w (replace-match "\\1" nil nil w)))
  4143. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4144. (push w wds))
  4145. (setq words (nreverse wds))))
  4146. (if boolean
  4147. (mapc (lambda (w)
  4148. (setq c (string-to-char w))
  4149. (if (equal c ?-)
  4150. (setq neg t w (substring w 1))
  4151. (if (equal c ?+)
  4152. (setq neg nil w (substring w 1))
  4153. (setq neg nil)))
  4154. (if (string-match "\\`{.*}\\'" w)
  4155. (setq re (substring w 1 -1))
  4156. (if full-words
  4157. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4158. (setq re (regexp-quote (downcase w)))))
  4159. (if neg (push re regexps-) (push re regexps+)))
  4160. words)
  4161. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4162. regexps+))
  4163. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4164. (if (not regexps+)
  4165. (setq regexp org-outline-regexp-bol)
  4166. (setq regexp (pop regexps+))
  4167. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4168. regexp))))
  4169. (setq files (org-agenda-files nil 'ifmode))
  4170. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4171. (pop org-agenda-text-search-extra-files)
  4172. (setq files (org-add-archive-files files)))
  4173. (setq files (append files org-agenda-text-search-extra-files)
  4174. rtnall nil)
  4175. (while (setq file (pop files))
  4176. (setq ee nil)
  4177. (catch 'nextfile
  4178. (org-check-agenda-file file)
  4179. (setq buffer (if (file-exists-p file)
  4180. (org-get-agenda-file-buffer file)
  4181. (error "No such file %s" file)))
  4182. (if (not buffer)
  4183. ;; If file does not exist, make sure an error message is sent
  4184. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4185. file))))
  4186. (with-current-buffer buffer
  4187. (with-syntax-table (org-search-syntax-table)
  4188. (unless (derived-mode-p 'org-mode)
  4189. (error "Agenda file %s is not in `org-mode'" file))
  4190. (let ((case-fold-search t))
  4191. (save-excursion
  4192. (save-restriction
  4193. (if (eq buffer org-agenda-restrict)
  4194. (narrow-to-region org-agenda-restrict-begin
  4195. org-agenda-restrict-end)
  4196. (widen))
  4197. (goto-char (point-min))
  4198. (unless (or (org-at-heading-p)
  4199. (outline-next-heading))
  4200. (throw 'nextfile t))
  4201. (goto-char (max (point-min) (1- (point))))
  4202. (while (re-search-forward regexp nil t)
  4203. (org-back-to-heading t)
  4204. (while (and org-agenda-search-view-max-outline-level
  4205. (> (org-reduced-level (org-outline-level))
  4206. org-agenda-search-view-max-outline-level)
  4207. (forward-line -1)
  4208. (outline-back-to-heading t)))
  4209. (skip-chars-forward "* ")
  4210. (setq beg (point-at-bol)
  4211. beg1 (point)
  4212. end (progn
  4213. (outline-next-heading)
  4214. (while (and org-agenda-search-view-max-outline-level
  4215. (> (org-reduced-level (org-outline-level))
  4216. org-agenda-search-view-max-outline-level)
  4217. (forward-line 1)
  4218. (outline-next-heading)))
  4219. (point)))
  4220. (catch :skip
  4221. (goto-char beg)
  4222. (org-agenda-skip)
  4223. (setq str (buffer-substring-no-properties
  4224. (point-at-bol)
  4225. (if hdl-only (point-at-eol) end)))
  4226. (mapc (lambda (wr) (when (string-match wr str)
  4227. (goto-char (1- end))
  4228. (throw :skip t)))
  4229. regexps-)
  4230. (mapc (lambda (wr) (unless (string-match wr str)
  4231. (goto-char (1- end))
  4232. (throw :skip t)))
  4233. (if todo-only
  4234. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4235. regexps+)
  4236. regexps+))
  4237. (goto-char beg)
  4238. (setq marker (org-agenda-new-marker (point))
  4239. category (org-get-category)
  4240. level (make-string (org-reduced-level (org-outline-level)) ? )
  4241. category-pos (get-text-property (point) 'org-category-position)
  4242. inherited-tags
  4243. (or (eq org-agenda-show-inherited-tags 'always)
  4244. (and (listp org-agenda-show-inherited-tags)
  4245. (memq 'todo org-agenda-show-inherited-tags))
  4246. (and (eq org-agenda-show-inherited-tags t)
  4247. (or (eq org-agenda-use-tag-inheritance t)
  4248. (memq 'todo org-agenda-use-tag-inheritance))))
  4249. tags (org-get-tags-at nil (not inherited-tags))
  4250. txt (org-agenda-format-item
  4251. ""
  4252. (buffer-substring-no-properties
  4253. beg1 (point-at-eol))
  4254. level category tags t))
  4255. (org-add-props txt props
  4256. 'org-marker marker 'org-hd-marker marker
  4257. 'org-todo-regexp org-todo-regexp
  4258. 'level level
  4259. 'org-complex-heading-regexp org-complex-heading-regexp
  4260. 'priority 1000 'org-category category
  4261. 'org-category-position category-pos
  4262. 'type "search")
  4263. (push txt ee)
  4264. (goto-char (1- end))))))))))
  4265. (setq rtn (nreverse ee))
  4266. (setq rtnall (append rtnall rtn)))
  4267. (if org-agenda-overriding-header
  4268. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4269. nil 'face 'org-agenda-structure) "\n")
  4270. (insert "Search words: ")
  4271. (add-text-properties (point-min) (1- (point))
  4272. (list 'face 'org-agenda-structure))
  4273. (setq pos (point))
  4274. (insert string "\n")
  4275. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4276. (setq pos (point))
  4277. (unless org-agenda-multi
  4278. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4279. (add-text-properties pos (1- (point))
  4280. (list 'face 'org-agenda-structure))))
  4281. (org-agenda-mark-header-line (point-min))
  4282. (when rtnall
  4283. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4284. (goto-char (point-min))
  4285. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4286. (add-text-properties (point-min) (point-max)
  4287. `(org-agenda-type search
  4288. org-last-args (,todo-only ,string ,edit-at)
  4289. org-redo-cmd ,org-agenda-redo-command
  4290. org-series-cmd ,org-cmd))
  4291. (org-agenda-finalize)
  4292. (setq buffer-read-only t))))
  4293. ;;; Agenda TODO list
  4294. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4295. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4296. (concat
  4297. (if (or (equal keywords "ALL") (not keywords))
  4298. (propertize "ALL" 'face 'warning)
  4299. (mapconcat
  4300. (lambda (kw)
  4301. (propertize kw 'face (org-get-todo-face kw)))
  4302. (org-split-string keywords "|")
  4303. "|"))
  4304. "\n"))
  4305. (defvar org-select-this-todo-keyword nil)
  4306. (defvar org-last-arg nil)
  4307. ;;;###autoload
  4308. (defun org-todo-list (&optional arg)
  4309. "Show all (not done) TODO entries from all agenda file in a single list.
  4310. The prefix arg can be used to select a specific TODO keyword and limit
  4311. the list to these. When using \\[universal-argument], you will be prompted
  4312. for a keyword. A numeric prefix directly selects the Nth keyword in
  4313. `org-todo-keywords-1'."
  4314. (interactive "P")
  4315. (if org-agenda-overriding-arguments
  4316. (setq arg org-agenda-overriding-arguments))
  4317. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4318. (let* ((today (org-today))
  4319. (date (calendar-gregorian-from-absolute today))
  4320. (kwds org-todo-keywords-for-agenda)
  4321. (completion-ignore-case t)
  4322. (org-select-this-todo-keyword
  4323. (if (stringp arg) arg
  4324. (and arg (integerp arg) (> arg 0)
  4325. (nth (1- arg) kwds))))
  4326. rtn rtnall files file pos)
  4327. (when (equal arg '(4))
  4328. (setq org-select-this-todo-keyword
  4329. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4330. (mapcar 'list kwds) nil nil)))
  4331. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4332. (catch 'exit
  4333. (if org-agenda-sticky
  4334. (setq org-agenda-buffer-name
  4335. (if (stringp org-select-this-todo-keyword)
  4336. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4337. org-select-this-todo-keyword)
  4338. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4339. (org-agenda-prepare "TODO")
  4340. (org-compile-prefix-format 'todo)
  4341. (org-set-sorting-strategy 'todo)
  4342. (setq org-agenda-redo-command
  4343. `(org-todo-list (or (and (numberp current-prefix-arg)
  4344. current-prefix-arg)
  4345. ,org-select-this-todo-keyword
  4346. current-prefix-arg ,arg)))
  4347. (setq files (org-agenda-files nil 'ifmode)
  4348. rtnall nil)
  4349. (while (setq file (pop files))
  4350. (catch 'nextfile
  4351. (org-check-agenda-file file)
  4352. (setq rtn (org-agenda-get-day-entries file date :todo))
  4353. (setq rtnall (append rtnall rtn))))
  4354. (if org-agenda-overriding-header
  4355. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4356. nil 'face 'org-agenda-structure) "\n")
  4357. (insert "Global list of TODO items of type: ")
  4358. (add-text-properties (point-min) (1- (point))
  4359. (list 'face 'org-agenda-structure
  4360. 'short-heading
  4361. (concat "ToDo: "
  4362. (or org-select-this-todo-keyword "ALL"))))
  4363. (org-agenda-mark-header-line (point-min))
  4364. (insert (org-agenda-propertize-selected-todo-keywords
  4365. org-select-this-todo-keyword))
  4366. (setq pos (point))
  4367. (unless org-agenda-multi
  4368. (insert "Available with `N r': (0)[ALL]")
  4369. (let ((n 0) s)
  4370. (mapc (lambda (x)
  4371. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4372. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4373. (insert "\n "))
  4374. (insert " " s))
  4375. kwds))
  4376. (insert "\n"))
  4377. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4378. (org-agenda-mark-header-line (point-min))
  4379. (when rtnall
  4380. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4381. (goto-char (point-min))
  4382. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4383. (add-text-properties (point-min) (point-max)
  4384. `(org-agenda-type todo
  4385. org-last-args ,arg
  4386. org-redo-cmd ,org-agenda-redo-command
  4387. org-series-cmd ,org-cmd))
  4388. (org-agenda-finalize)
  4389. (setq buffer-read-only t))))
  4390. ;;; Agenda tags match
  4391. ;;;###autoload
  4392. (defun org-tags-view (&optional todo-only match)
  4393. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4394. The prefix arg TODO-ONLY limits the search to TODO entries."
  4395. (interactive "P")
  4396. (if org-agenda-overriding-arguments
  4397. (setq todo-only (car org-agenda-overriding-arguments)
  4398. match (nth 1 org-agenda-overriding-arguments)))
  4399. (let* ((org-tags-match-list-sublevels
  4400. org-tags-match-list-sublevels)
  4401. (completion-ignore-case t)
  4402. rtn rtnall files file pos matcher
  4403. buffer)
  4404. (when (and (stringp match) (not (string-match "\\S-" match)))
  4405. (setq match nil))
  4406. (catch 'exit
  4407. (if org-agenda-sticky
  4408. (setq org-agenda-buffer-name
  4409. (if (stringp match)
  4410. (format "*Org Agenda(%s:%s)*"
  4411. (or org-keys (or (and todo-only "M") "m")) match)
  4412. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4413. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4414. ;; expanding tags within `org-make-tags-matcher'
  4415. (org-agenda-prepare (concat "TAGS " match))
  4416. (setq matcher (org-make-tags-matcher match)
  4417. match (car matcher) matcher (cdr matcher))
  4418. (org-compile-prefix-format 'tags)
  4419. (org-set-sorting-strategy 'tags)
  4420. (setq org-agenda-query-string match)
  4421. (setq org-agenda-redo-command
  4422. (list 'org-tags-view `(quote ,todo-only)
  4423. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4424. (setq files (org-agenda-files nil 'ifmode)
  4425. rtnall nil)
  4426. (while (setq file (pop files))
  4427. (catch 'nextfile
  4428. (org-check-agenda-file file)
  4429. (setq buffer (if (file-exists-p file)
  4430. (org-get-agenda-file-buffer file)
  4431. (error "No such file %s" file)))
  4432. (if (not buffer)
  4433. ;; If file does not exist, error message to agenda
  4434. (setq rtn (list
  4435. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4436. rtnall (append rtnall rtn))
  4437. (with-current-buffer buffer
  4438. (unless (derived-mode-p 'org-mode)
  4439. (error "Agenda file %s is not in `org-mode'" file))
  4440. (save-excursion
  4441. (save-restriction
  4442. (if (eq buffer org-agenda-restrict)
  4443. (narrow-to-region org-agenda-restrict-begin
  4444. org-agenda-restrict-end)
  4445. (widen))
  4446. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4447. (setq rtnall (append rtnall rtn))))))))
  4448. (if org-agenda-overriding-header
  4449. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4450. nil 'face 'org-agenda-structure) "\n")
  4451. (insert "Headlines with TAGS match: ")
  4452. (add-text-properties (point-min) (1- (point))
  4453. (list 'face 'org-agenda-structure
  4454. 'short-heading
  4455. (concat "Match: " match)))
  4456. (setq pos (point))
  4457. (insert match "\n")
  4458. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4459. (setq pos (point))
  4460. (unless org-agenda-multi
  4461. (insert "Press `C-u r' to search again with new search string\n"))
  4462. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4463. (org-agenda-mark-header-line (point-min))
  4464. (when rtnall
  4465. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4466. (goto-char (point-min))
  4467. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4468. (add-text-properties (point-min) (point-max)
  4469. `(org-agenda-type tags
  4470. org-last-args (,todo-only ,match)
  4471. org-redo-cmd ,org-agenda-redo-command
  4472. org-series-cmd ,org-cmd))
  4473. (org-agenda-finalize)
  4474. (setq buffer-read-only t))))
  4475. ;;; Agenda Finding stuck projects
  4476. (defvar org-agenda-skip-regexp nil
  4477. "Regular expression used in skipping subtrees for the agenda.
  4478. This is basically a temporary global variable that can be set and then
  4479. used by user-defined selections using `org-agenda-skip-function'.")
  4480. (defvar org-agenda-overriding-header nil
  4481. "When set during agenda, todo and tags searches it replaces the header.
  4482. This variable should not be set directly, but custom commands can bind it
  4483. in the options section.")
  4484. (defun org-agenda-skip-entry-when-regexp-matches ()
  4485. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4486. If yes, it returns the end position of this entry, causing agenda commands
  4487. to skip the entry but continuing the search in the subtree. This is a
  4488. function that can be put into `org-agenda-skip-function' for the duration
  4489. of a command."
  4490. (let ((end (save-excursion (org-end-of-subtree t)))
  4491. skip)
  4492. (save-excursion
  4493. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4494. (and skip end)))
  4495. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4496. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4497. If yes, it returns the end position of this tree, causing agenda commands
  4498. to skip this subtree. This is a function that can be put into
  4499. `org-agenda-skip-function' for the duration of a command."
  4500. (let ((end (save-excursion (org-end-of-subtree t)))
  4501. skip)
  4502. (save-excursion
  4503. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4504. (and skip end)))
  4505. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4506. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4507. If yes, it returns the end position of the current entry (NOT the tree),
  4508. causing agenda commands to skip the entry but continuing the search in
  4509. the subtree. This is a function that can be put into
  4510. `org-agenda-skip-function' for the duration of a command. An important
  4511. use of this function is for the stuck project list."
  4512. (let ((end (save-excursion (org-end-of-subtree t)))
  4513. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4514. skip)
  4515. (save-excursion
  4516. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4517. (and skip entry-end)))
  4518. (defun org-agenda-skip-entry-if (&rest conditions)
  4519. "Skip entry if any of CONDITIONS is true.
  4520. See `org-agenda-skip-if' for details."
  4521. (org-agenda-skip-if nil conditions))
  4522. (defun org-agenda-skip-subtree-if (&rest conditions)
  4523. "Skip entry if any of CONDITIONS is true.
  4524. See `org-agenda-skip-if' for details."
  4525. (org-agenda-skip-if t conditions))
  4526. (defun org-agenda-skip-if (subtree conditions)
  4527. "Checks current entity for CONDITIONS.
  4528. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4529. the entry (i.e. the text before the next heading) is checked.
  4530. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4531. from different tests. Valid conditions are:
  4532. scheduled Check if there is a scheduled cookie
  4533. notscheduled Check if there is no scheduled cookie
  4534. deadline Check if there is a deadline
  4535. notdeadline Check if there is no deadline
  4536. timestamp Check if there is a timestamp (also deadline or scheduled)
  4537. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4538. regexp Check if regexp matches
  4539. notregexp Check if regexp does not match.
  4540. todo Check if TODO keyword matches
  4541. nottodo Check if TODO keyword does not match
  4542. The regexp is taken from the conditions list, it must come right after
  4543. the `regexp' or `notregexp' element.
  4544. `todo' and `nottodo' accept as an argument a list of todo
  4545. keywords, which may include \"*\" to match any todo keyword.
  4546. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4547. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4548. Instead of a list, a keyword class may be given. For example:
  4549. (org-agenda-skip-entry-if 'nottodo 'done)
  4550. would skip entries that haven't been marked with any of \"DONE\"
  4551. keywords. Possible classes are: `todo', `done', `any'.
  4552. If any of these conditions is met, this function returns the end point of
  4553. the entity, causing the search to continue from there. This is a function
  4554. that can be put into `org-agenda-skip-function' for the duration of a command."
  4555. (let (beg end m)
  4556. (org-back-to-heading t)
  4557. (setq beg (point)
  4558. end (if subtree
  4559. (progn (org-end-of-subtree t) (point))
  4560. (progn (outline-next-heading) (1- (point)))))
  4561. (goto-char beg)
  4562. (and
  4563. (or
  4564. (and (memq 'scheduled conditions)
  4565. (re-search-forward org-scheduled-time-regexp end t))
  4566. (and (memq 'notscheduled conditions)
  4567. (not (re-search-forward org-scheduled-time-regexp end t)))
  4568. (and (memq 'deadline conditions)
  4569. (re-search-forward org-deadline-time-regexp end t))
  4570. (and (memq 'notdeadline conditions)
  4571. (not (re-search-forward org-deadline-time-regexp end t)))
  4572. (and (memq 'timestamp conditions)
  4573. (re-search-forward org-ts-regexp end t))
  4574. (and (memq 'nottimestamp conditions)
  4575. (not (re-search-forward org-ts-regexp end t)))
  4576. (and (setq m (memq 'regexp conditions))
  4577. (stringp (nth 1 m))
  4578. (re-search-forward (nth 1 m) end t))
  4579. (and (setq m (memq 'notregexp conditions))
  4580. (stringp (nth 1 m))
  4581. (not (re-search-forward (nth 1 m) end t)))
  4582. (and (or
  4583. (setq m (memq 'nottodo conditions))
  4584. (setq m (memq 'todo-unblocked conditions))
  4585. (setq m (memq 'nottodo-unblocked conditions))
  4586. (setq m (memq 'todo conditions)))
  4587. (org-agenda-skip-if-todo m end)))
  4588. end)))
  4589. (defun org-agenda-skip-if-todo (args end)
  4590. "Helper function for `org-agenda-skip-if', do not use it directly.
  4591. ARGS is a list with first element either `todo', `nottodo',
  4592. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4593. a list of TODO keywords, or a state symbol `todo' or `done' or
  4594. `any'."
  4595. (let ((kw (car args))
  4596. (arg (cadr args))
  4597. todo-wds todo-re)
  4598. (setq todo-wds
  4599. (org-uniquify
  4600. (cond
  4601. ((listp arg) ;; list of keywords
  4602. (if (member "*" arg)
  4603. (mapcar 'substring-no-properties org-todo-keywords-1)
  4604. arg))
  4605. ((symbolp arg) ;; keyword class name
  4606. (cond
  4607. ((eq arg 'todo)
  4608. (org-delete-all org-done-keywords
  4609. (mapcar 'substring-no-properties
  4610. org-todo-keywords-1)))
  4611. ((eq arg 'done) org-done-keywords)
  4612. ((eq arg 'any)
  4613. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4614. (setq todo-re
  4615. (concat "^\\*+[ \t]+\\<\\("
  4616. (mapconcat 'identity todo-wds "\\|")
  4617. "\\)\\>"))
  4618. (cond
  4619. ((eq kw 'todo) (re-search-forward todo-re end t))
  4620. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4621. ((eq kw 'todo-unblocked)
  4622. (catch 'unblocked
  4623. (while (re-search-forward todo-re end t)
  4624. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4625. nil))
  4626. ((eq kw 'nottodo-unblocked)
  4627. (catch 'unblocked
  4628. (while (re-search-forward todo-re end t)
  4629. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4630. t))
  4631. )))
  4632. ;;;###autoload
  4633. (defun org-agenda-list-stuck-projects (&rest ignore)
  4634. "Create agenda view for projects that are stuck.
  4635. Stuck projects are project that have no next actions. For the definitions
  4636. of what a project is and how to check if it stuck, customize the variable
  4637. `org-stuck-projects'."
  4638. (interactive)
  4639. (let* ((org-agenda-skip-function
  4640. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4641. ;; We could have used org-agenda-skip-if here.
  4642. (org-agenda-overriding-header
  4643. (or org-agenda-overriding-header "List of stuck projects: "))
  4644. (matcher (nth 0 org-stuck-projects))
  4645. (todo (nth 1 org-stuck-projects))
  4646. (todo-wds (if (member "*" todo)
  4647. (progn
  4648. (org-agenda-prepare-buffers (org-agenda-files
  4649. nil 'ifmode))
  4650. (org-delete-all
  4651. org-done-keywords-for-agenda
  4652. (copy-sequence org-todo-keywords-for-agenda)))
  4653. todo))
  4654. (todo-re (concat "^\\*+[ \t]+\\("
  4655. (mapconcat 'identity todo-wds "\\|")
  4656. "\\)\\>"))
  4657. (tags (nth 2 org-stuck-projects))
  4658. (tags-re (if (member "*" tags)
  4659. (concat org-outline-regexp-bol
  4660. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4661. (if tags
  4662. (concat org-outline-regexp-bol
  4663. ".*:\\("
  4664. (mapconcat 'identity tags "\\|")
  4665. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4666. (gen-re (nth 3 org-stuck-projects))
  4667. (re-list
  4668. (delq nil
  4669. (list
  4670. (if todo todo-re)
  4671. (if tags tags-re)
  4672. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4673. gen-re)))))
  4674. (setq org-agenda-skip-regexp
  4675. (if re-list
  4676. (mapconcat 'identity re-list "\\|")
  4677. (error "No information how to identify unstuck projects")))
  4678. (org-tags-view nil matcher)
  4679. (with-current-buffer org-agenda-buffer-name
  4680. (setq org-agenda-redo-command
  4681. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4682. ;;; Diary integration
  4683. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4684. (defvar diary-list-entries-hook)
  4685. (defvar diary-time-regexp)
  4686. (defun org-get-entries-from-diary (date)
  4687. "Get the (Emacs Calendar) diary entries for DATE."
  4688. (require 'diary-lib)
  4689. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4690. (diary-display-hook '(fancy-diary-display))
  4691. (diary-display-function 'fancy-diary-display)
  4692. (pop-up-frames nil)
  4693. (diary-list-entries-hook
  4694. (cons 'org-diary-default-entry diary-list-entries-hook))
  4695. (diary-file-name-prefix nil) ; turn this feature off
  4696. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4697. entries
  4698. (org-disable-agenda-to-diary t))
  4699. (save-excursion
  4700. (save-window-excursion
  4701. (funcall (if (fboundp 'diary-list-entries)
  4702. 'diary-list-entries 'list-diary-entries)
  4703. date 1)))
  4704. (if (not (get-buffer diary-fancy-buffer))
  4705. (setq entries nil)
  4706. (with-current-buffer diary-fancy-buffer
  4707. (setq buffer-read-only nil)
  4708. (if (zerop (buffer-size))
  4709. ;; No entries
  4710. (setq entries nil)
  4711. ;; Omit the date and other unnecessary stuff
  4712. (org-agenda-cleanup-fancy-diary)
  4713. ;; Add prefix to each line and extend the text properties
  4714. (if (zerop (buffer-size))
  4715. (setq entries nil)
  4716. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4717. (setq entries
  4718. (with-temp-buffer
  4719. (insert entries) (goto-char (point-min))
  4720. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4721. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4722. (replace-match (concat "; " (match-string 1)))))
  4723. (buffer-string)))))
  4724. (set-buffer-modified-p nil)
  4725. (kill-buffer diary-fancy-buffer)))
  4726. (when entries
  4727. (setq entries (org-split-string entries "\n"))
  4728. (setq entries
  4729. (mapcar
  4730. (lambda (x)
  4731. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4732. ;; Extend the text properties to the beginning of the line
  4733. (org-add-props x (text-properties-at (1- (length x)) x)
  4734. 'type "diary" 'date date 'face 'org-agenda-diary))
  4735. entries)))))
  4736. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4737. "Hook run when the fancy diary buffer is cleaned up.")
  4738. (defun org-agenda-cleanup-fancy-diary ()
  4739. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4740. This gets rid of the date, the underline under the date, and
  4741. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4742. date. It also removes lines that contain only whitespace."
  4743. (goto-char (point-min))
  4744. (if (looking-at ".*?:[ \t]*")
  4745. (progn
  4746. (replace-match "")
  4747. (re-search-forward "\n=+$" nil t)
  4748. (replace-match "")
  4749. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4750. (re-search-forward "\n=+$" nil t)
  4751. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4752. (goto-char (point-min))
  4753. (while (re-search-forward "^ +\n" nil t)
  4754. (replace-match ""))
  4755. (goto-char (point-min))
  4756. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4757. (replace-match ""))
  4758. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4759. ;; Make sure entries from the diary have the right text properties.
  4760. (eval-after-load "diary-lib"
  4761. '(if (boundp 'diary-modify-entry-list-string-function)
  4762. ;; We can rely on the hook, nothing to do
  4763. nil
  4764. ;; Hook not available, must use advice to make this work
  4765. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4766. "Make the position visible."
  4767. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4768. (stringp string)
  4769. buffer-file-name)
  4770. (setq string (org-modify-diary-entry-string string))))))
  4771. (defun org-modify-diary-entry-string (string)
  4772. "Add text properties to string, allowing org-mode to act on it."
  4773. (org-add-props string nil
  4774. 'mouse-face 'highlight
  4775. 'help-echo (if buffer-file-name
  4776. (format "mouse-2 or RET jump to diary file %s"
  4777. (abbreviate-file-name buffer-file-name))
  4778. "")
  4779. 'org-agenda-diary-link t
  4780. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4781. (defun org-diary-default-entry ()
  4782. "Add a dummy entry to the diary.
  4783. Needed to avoid empty dates which mess up holiday display."
  4784. ;; Catch the error if dealing with the new add-to-diary-alist
  4785. (when org-disable-agenda-to-diary
  4786. (condition-case nil
  4787. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4788. (error
  4789. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4790. (defun org-add-to-diary-list (&rest args)
  4791. (if (fboundp 'diary-add-to-list)
  4792. (apply 'diary-add-to-list args)
  4793. (apply 'add-to-diary-list args)))
  4794. (defvar org-diary-last-run-time nil)
  4795. ;;;###autoload
  4796. (defun org-diary (&rest args)
  4797. "Return diary information from org files.
  4798. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4799. It accesses org files and extracts information from those files to be
  4800. listed in the diary. The function accepts arguments specifying what
  4801. items should be listed. For a list of arguments allowed here, see the
  4802. variable `org-agenda-entry-types'.
  4803. The call in the diary file should look like this:
  4804. &%%(org-diary) ~/path/to/some/orgfile.org
  4805. Use a separate line for each org file to check. Or, if you omit the file name,
  4806. all files listed in `org-agenda-files' will be checked automatically:
  4807. &%%(org-diary)
  4808. If you don't give any arguments (as in the example above), the default value
  4809. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4810. So the example above may also be written as
  4811. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4812. The function expects the lisp variables `entry' and `date' to be provided
  4813. by the caller, because this is how the calendar works. Don't use this
  4814. function from a program - use `org-agenda-get-day-entries' instead."
  4815. (when (> (- (org-float-time)
  4816. org-agenda-last-marker-time)
  4817. 5)
  4818. ;; I am not sure if this works with sticky agendas, because the marker
  4819. ;; list is then no longer a global variable.
  4820. (org-agenda-reset-markers))
  4821. (org-compile-prefix-format 'agenda)
  4822. (org-set-sorting-strategy 'agenda)
  4823. (setq args (or args org-agenda-entry-types))
  4824. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4825. (list entry)
  4826. (org-agenda-files t)))
  4827. (time (org-float-time))
  4828. file rtn results)
  4829. (when (or (not org-diary-last-run-time)
  4830. (> (- time
  4831. org-diary-last-run-time)
  4832. 3))
  4833. (org-agenda-prepare-buffers files))
  4834. (setq org-diary-last-run-time time)
  4835. ;; If this is called during org-agenda, don't return any entries to
  4836. ;; the calendar. Org Agenda will list these entries itself.
  4837. (if org-disable-agenda-to-diary (setq files nil))
  4838. (while (setq file (pop files))
  4839. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4840. (setq results (append results rtn)))
  4841. (when results
  4842. (setq results
  4843. (mapcar (lambda (i) (replace-regexp-in-string
  4844. org-bracket-link-regexp "\\3" i)) results))
  4845. (concat (org-agenda-finalize-entries results) "\n"))))
  4846. ;;; Agenda entry finders
  4847. (defun org-agenda-get-day-entries (file date &rest args)
  4848. "Does the work for `org-diary' and `org-agenda'.
  4849. FILE is the path to a file to be checked for entries. DATE is date like
  4850. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4851. which kind of entries should be extracted. For details about these, see
  4852. the documentation of `org-diary'."
  4853. (setq args (or args org-agenda-entry-types))
  4854. (let* ((org-startup-folded nil)
  4855. (org-startup-align-all-tables nil)
  4856. (buffer (if (file-exists-p file)
  4857. (org-get-agenda-file-buffer file)
  4858. (error "No such file %s" file)))
  4859. arg results rtn deadline-results)
  4860. (if (not buffer)
  4861. ;; If file does not exist, make sure an error message ends up in diary
  4862. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4863. (with-current-buffer buffer
  4864. (unless (derived-mode-p 'org-mode)
  4865. (error "Agenda file %s is not in `org-mode'" file))
  4866. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4867. (let ((case-fold-search nil))
  4868. (save-excursion
  4869. (save-restriction
  4870. (if (eq buffer org-agenda-restrict)
  4871. (narrow-to-region org-agenda-restrict-begin
  4872. org-agenda-restrict-end)
  4873. (widen))
  4874. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4875. (while (setq arg (pop args))
  4876. (cond
  4877. ((and (eq arg :todo)
  4878. (equal date (calendar-gregorian-from-absolute
  4879. (org-today))))
  4880. (setq rtn (org-agenda-get-todos))
  4881. (setq results (append results rtn)))
  4882. ((eq arg :timestamp)
  4883. (setq rtn (org-agenda-get-blocks))
  4884. (setq results (append results rtn))
  4885. (setq rtn (org-agenda-get-timestamps deadline-results))
  4886. (setq results (append results rtn)))
  4887. ((eq arg :sexp)
  4888. (setq rtn (org-agenda-get-sexps))
  4889. (setq results (append results rtn)))
  4890. ((eq arg :scheduled)
  4891. (setq rtn (org-agenda-get-scheduled deadline-results))
  4892. (setq results (append results rtn)))
  4893. ((eq arg :scheduled*)
  4894. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4895. (setq results (append results rtn)))
  4896. ((eq arg :closed)
  4897. (setq rtn (org-agenda-get-progress))
  4898. (setq results (append results rtn)))
  4899. ((eq arg :deadline)
  4900. (setq rtn (org-agenda-get-deadlines))
  4901. (setq deadline-results (copy-sequence rtn))
  4902. (setq results (append results rtn)))
  4903. ((eq arg :deadline*)
  4904. (setq rtn (org-agenda-get-deadlines t))
  4905. (setq deadline-results (copy-sequence rtn))
  4906. (setq results (append results rtn))))))))
  4907. results))))
  4908. (defsubst org-em (x y list)
  4909. "Is X or Y a member of LIST?"
  4910. (or (memq x list) (memq y list)))
  4911. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4912. (defvar org-agenda-sorting-strategy-selected nil)
  4913. (defun org-agenda-get-todos ()
  4914. "Return the TODO information for agenda display."
  4915. (let* ((props (list 'face nil
  4916. 'done-face 'org-agenda-done
  4917. 'org-not-done-regexp org-not-done-regexp
  4918. 'org-todo-regexp org-todo-regexp
  4919. 'org-complex-heading-regexp org-complex-heading-regexp
  4920. 'mouse-face 'highlight
  4921. 'help-echo
  4922. (format "mouse-2 or RET jump to org file %s"
  4923. (abbreviate-file-name buffer-file-name))))
  4924. (regexp (format org-heading-keyword-regexp-format
  4925. (cond
  4926. ((and org-select-this-todo-keyword
  4927. (equal org-select-this-todo-keyword "*"))
  4928. org-todo-regexp)
  4929. (org-select-this-todo-keyword
  4930. (concat "\\("
  4931. (mapconcat 'identity
  4932. (org-split-string
  4933. org-select-this-todo-keyword
  4934. "|")
  4935. "\\|") "\\)"))
  4936. (t org-not-done-regexp))))
  4937. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4938. ee txt beg end inherited-tags todo-state-end-pos)
  4939. (goto-char (point-min))
  4940. (while (re-search-forward regexp nil t)
  4941. (catch :skip
  4942. (save-match-data
  4943. (beginning-of-line)
  4944. (org-agenda-skip)
  4945. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4946. (unless (and (setq todo-state (org-get-todo-state))
  4947. (setq todo-state-end-pos (match-end 2)))
  4948. (goto-char end)
  4949. (throw :skip nil))
  4950. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4951. (goto-char (1+ beg))
  4952. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4953. (throw :skip nil)))
  4954. (goto-char (match-beginning 2))
  4955. (setq marker (org-agenda-new-marker (match-beginning 0))
  4956. category (org-get-category)
  4957. ts-date (let (ts)
  4958. (save-match-data
  4959. (cond ((org-em 'scheduled-up 'scheduled-down
  4960. org-agenda-sorting-strategy-selected)
  4961. (setq ts (org-entry-get (point) "SCHEDULED")
  4962. ts-date-type " scheduled"))
  4963. ((org-em 'deadline-up 'deadline-down
  4964. org-agenda-sorting-strategy-selected)
  4965. (setq ts (org-entry-get (point) "DEADLINE")
  4966. ts-date-type " deadline"))
  4967. ((org-em 'ts-up 'ts-down
  4968. org-agenda-sorting-strategy-selected)
  4969. (setq ts (org-entry-get (point) "TIMESTAMP")
  4970. ts-date-type " timestamp"))
  4971. ((org-em 'tsia-up 'tsia-down
  4972. org-agenda-sorting-strategy-selected)
  4973. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4974. ts-date-type " timestamp_ia"))
  4975. ((org-em 'timestamp-up 'timestamp-down
  4976. org-agenda-sorting-strategy-selected)
  4977. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4978. (org-entry-get (point) "DEADLINE")
  4979. (org-entry-get (point) "TIMESTAMP")
  4980. (org-entry-get (point) "TIMESTAMP_IA"))
  4981. ts-date-type ""))
  4982. (t (setq ts-date-type "")))
  4983. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4984. category-pos (get-text-property (point) 'org-category-position)
  4985. txt (org-trim
  4986. (buffer-substring (match-beginning 2) (match-end 0)))
  4987. inherited-tags
  4988. (or (eq org-agenda-show-inherited-tags 'always)
  4989. (and (listp org-agenda-show-inherited-tags)
  4990. (memq 'todo org-agenda-show-inherited-tags))
  4991. (and (eq org-agenda-show-inherited-tags t)
  4992. (or (eq org-agenda-use-tag-inheritance t)
  4993. (memq 'todo org-agenda-use-tag-inheritance))))
  4994. tags (org-get-tags-at nil (not inherited-tags))
  4995. level (make-string (org-reduced-level (org-outline-level)) ? )
  4996. txt (org-agenda-format-item "" txt level category tags t)
  4997. priority (1+ (org-get-priority txt)))
  4998. (org-add-props txt props
  4999. 'org-marker marker 'org-hd-marker marker
  5000. 'priority priority 'org-category category
  5001. 'level level
  5002. 'ts-date ts-date
  5003. 'org-category-position category-pos
  5004. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5005. (push txt ee)
  5006. (if org-agenda-todo-list-sublevels
  5007. (goto-char todo-state-end-pos)
  5008. (org-end-of-subtree 'invisible))))
  5009. (nreverse ee)))
  5010. (defun org-agenda-todo-custom-ignore-p (time n)
  5011. "Check whether timestamp is farther away than n number of days.
  5012. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5013. `org-agenda-todo-ignore-scheduled' or
  5014. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5015. (let ((days (org-time-stamp-to-now
  5016. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5017. (if (>= n 0)
  5018. (>= days n)
  5019. (<= days n))))
  5020. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5021. (&optional end)
  5022. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5023. (when (or org-agenda-todo-ignore-with-date
  5024. org-agenda-todo-ignore-scheduled
  5025. org-agenda-todo-ignore-deadlines
  5026. org-agenda-todo-ignore-timestamp)
  5027. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5028. (save-excursion
  5029. (or (and org-agenda-todo-ignore-with-date
  5030. (re-search-forward org-ts-regexp end t))
  5031. (and org-agenda-todo-ignore-scheduled
  5032. (re-search-forward org-scheduled-time-regexp end t)
  5033. (cond
  5034. ((eq org-agenda-todo-ignore-scheduled 'future)
  5035. (> (org-time-stamp-to-now
  5036. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5037. ((eq org-agenda-todo-ignore-scheduled 'past)
  5038. (<= (org-time-stamp-to-now
  5039. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5040. ((numberp org-agenda-todo-ignore-scheduled)
  5041. (org-agenda-todo-custom-ignore-p
  5042. (match-string 1) org-agenda-todo-ignore-scheduled))
  5043. (t)))
  5044. (and org-agenda-todo-ignore-deadlines
  5045. (re-search-forward org-deadline-time-regexp end t)
  5046. (cond
  5047. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5048. ((eq org-agenda-todo-ignore-deadlines 'far)
  5049. (not (org-deadline-close (match-string 1))))
  5050. ((eq org-agenda-todo-ignore-deadlines 'future)
  5051. (> (org-time-stamp-to-now
  5052. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5053. ((eq org-agenda-todo-ignore-deadlines 'past)
  5054. (<= (org-time-stamp-to-now
  5055. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5056. ((numberp org-agenda-todo-ignore-deadlines)
  5057. (org-agenda-todo-custom-ignore-p
  5058. (match-string 1) org-agenda-todo-ignore-deadlines))
  5059. (t (org-deadline-close (match-string 1)))))
  5060. (and org-agenda-todo-ignore-timestamp
  5061. (let ((buffer (current-buffer))
  5062. (regexp
  5063. (concat
  5064. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5065. (start (point)))
  5066. ;; Copy current buffer into a temporary one
  5067. (with-temp-buffer
  5068. (insert-buffer-substring buffer start end)
  5069. (goto-char (point-min))
  5070. ;; Delete SCHEDULED and DEADLINE items
  5071. (while (re-search-forward regexp end t)
  5072. (delete-region (match-beginning 0) (match-end 0)))
  5073. (goto-char (point-min))
  5074. ;; No search for timestamp left
  5075. (when (re-search-forward org-ts-regexp nil t)
  5076. (cond
  5077. ((eq org-agenda-todo-ignore-timestamp 'future)
  5078. (> (org-time-stamp-to-now
  5079. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5080. ((eq org-agenda-todo-ignore-timestamp 'past)
  5081. (<= (org-time-stamp-to-now
  5082. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5083. ((numberp org-agenda-todo-ignore-timestamp)
  5084. (org-agenda-todo-custom-ignore-p
  5085. (match-string 1) org-agenda-todo-ignore-timestamp))
  5086. (t))))))))))
  5087. (defun org-agenda-get-timestamps (&optional deadline-results)
  5088. "Return the date stamp information for agenda display."
  5089. (let* ((props (list 'face 'org-agenda-calendar-event
  5090. 'org-not-done-regexp org-not-done-regexp
  5091. 'org-todo-regexp org-todo-regexp
  5092. 'org-complex-heading-regexp org-complex-heading-regexp
  5093. 'mouse-face 'highlight
  5094. 'help-echo
  5095. (format "mouse-2 or RET jump to org file %s"
  5096. (abbreviate-file-name buffer-file-name))))
  5097. (d1 (calendar-absolute-from-gregorian date))
  5098. mm
  5099. (deadline-position-alist
  5100. (mapcar (lambda (a) (and (setq mm (get-text-property
  5101. 0 'org-hd-marker a))
  5102. (cons (marker-position mm) a)))
  5103. deadline-results))
  5104. (remove-re org-ts-regexp)
  5105. (regexp
  5106. (concat
  5107. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5108. (regexp-quote
  5109. (substring
  5110. (format-time-string
  5111. (car org-time-stamp-formats)
  5112. (apply 'encode-time ; DATE bound by calendar
  5113. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5114. 1 11))
  5115. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5116. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5117. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5118. donep tmp priority category category-pos level ee txt timestr tags
  5119. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5120. inherited-tags ts-date)
  5121. (goto-char (point-min))
  5122. (while (setq end-of-match (re-search-forward regexp nil t))
  5123. (setq b0 (match-beginning 0)
  5124. b3 (match-beginning 3) e3 (match-end 3)
  5125. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5126. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5127. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5128. (member todo-state
  5129. org-agenda-repeating-timestamp-show-all)))
  5130. (catch :skip
  5131. (and (org-at-date-range-p) (throw :skip nil))
  5132. (org-agenda-skip)
  5133. (if (and (match-end 1)
  5134. (not (= d1 (org-time-string-to-absolute
  5135. (match-string 1) d1 nil show-all
  5136. (current-buffer) b0))))
  5137. (throw :skip nil))
  5138. (if (and e3
  5139. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5140. (throw :skip nil))
  5141. (setq tmp (buffer-substring (max (point-min)
  5142. (- b0 org-ds-keyword-length))
  5143. b0)
  5144. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5145. inactivep (= (char-after b0) ?\[)
  5146. deadlinep (string-match org-deadline-regexp tmp)
  5147. scheduledp (string-match org-scheduled-regexp tmp)
  5148. closedp (and org-agenda-include-inactive-timestamps
  5149. (string-match org-closed-string tmp))
  5150. clockp (and org-agenda-include-inactive-timestamps
  5151. (or (string-match org-clock-string tmp)
  5152. (string-match "]-+\\'" tmp)))
  5153. warntime (get-text-property (point) 'org-appt-warntime)
  5154. donep (member todo-state org-done-keywords))
  5155. (if (or scheduledp deadlinep closedp clockp
  5156. (and donep org-agenda-skip-timestamp-if-done))
  5157. (throw :skip t))
  5158. (if (string-match ">" timestr)
  5159. ;; substring should only run to end of time stamp
  5160. (setq timestr (substring timestr 0 (match-end 0))))
  5161. (setq marker (org-agenda-new-marker b0)
  5162. category (org-get-category b0)
  5163. category-pos (get-text-property b0 'org-category-position))
  5164. (save-excursion
  5165. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5166. (throw :skip nil)
  5167. (goto-char (match-beginning 0))
  5168. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5169. (assoc (point) deadline-position-alist))
  5170. (throw :skip nil))
  5171. (setq hdmarker (org-agenda-new-marker)
  5172. inherited-tags
  5173. (or (eq org-agenda-show-inherited-tags 'always)
  5174. (and (listp org-agenda-show-inherited-tags)
  5175. (memq 'agenda org-agenda-show-inherited-tags))
  5176. (and (eq org-agenda-show-inherited-tags t)
  5177. (or (eq org-agenda-use-tag-inheritance t)
  5178. (memq 'agenda org-agenda-use-tag-inheritance))))
  5179. tags (org-get-tags-at nil (not inherited-tags))
  5180. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5181. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5182. (setq head (or (match-string 1) ""))
  5183. (setq txt (org-agenda-format-item
  5184. (if inactivep org-agenda-inactive-leader nil)
  5185. head level category tags timestr
  5186. remove-re habitp)))
  5187. (setq priority (org-get-priority txt))
  5188. (org-add-props txt props 'priority priority
  5189. 'org-marker marker 'org-hd-marker hdmarker
  5190. 'org-category category 'date date
  5191. 'level level
  5192. 'ts-date
  5193. (ignore-errors (org-time-string-to-absolute timestr))
  5194. 'org-category-position category-pos
  5195. 'todo-state todo-state
  5196. 'warntime warntime
  5197. 'type "timestamp")
  5198. (push txt ee))
  5199. (if org-agenda-skip-additional-timestamps-same-entry
  5200. (outline-next-heading)
  5201. (goto-char end-of-match))))
  5202. (nreverse ee)))
  5203. (defun org-agenda-get-sexps ()
  5204. "Return the sexp information for agenda display."
  5205. (require 'diary-lib)
  5206. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5207. 'mouse-face 'highlight
  5208. 'help-echo
  5209. (format "mouse-2 or RET jump to org file %s"
  5210. (abbreviate-file-name buffer-file-name))))
  5211. (regexp "^&?%%(")
  5212. marker category extra category-pos level ee txt tags entry
  5213. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5214. (goto-char (point-min))
  5215. (while (re-search-forward regexp nil t)
  5216. (catch :skip
  5217. (org-agenda-skip)
  5218. (setq beg (match-beginning 0))
  5219. (goto-char (1- (match-end 0)))
  5220. (setq b (point))
  5221. (forward-sexp 1)
  5222. (setq sexp (buffer-substring b (point)))
  5223. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5224. (org-trim (match-string 1))
  5225. ""))
  5226. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5227. (when result
  5228. (setq marker (org-agenda-new-marker beg)
  5229. level (make-string (org-reduced-level (org-outline-level)) ? )
  5230. category (org-get-category beg)
  5231. category-pos (get-text-property beg 'org-category-position)
  5232. inherited-tags
  5233. (or (eq org-agenda-show-inherited-tags 'always)
  5234. (and (listp org-agenda-show-inherited-tags)
  5235. (memq 'agenda org-agenda-show-inherited-tags))
  5236. (and (eq org-agenda-show-inherited-tags t)
  5237. (or (eq org-agenda-use-tag-inheritance t)
  5238. (memq 'agenda org-agenda-use-tag-inheritance))))
  5239. tags (org-get-tags-at nil (not inherited-tags))
  5240. todo-state (org-get-todo-state)
  5241. warntime (get-text-property (point) 'org-appt-warntime)
  5242. extra nil)
  5243. (dolist (r (if (stringp result)
  5244. (list result)
  5245. result)) ;; we expect a list here
  5246. (when (and org-agenda-diary-sexp-prefix
  5247. (string-match org-agenda-diary-sexp-prefix r))
  5248. (setq extra (match-string 0 r)
  5249. r (replace-match "" nil nil r)))
  5250. (if (string-match "\\S-" r)
  5251. (setq txt r)
  5252. (setq txt "SEXP entry returned empty string"))
  5253. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5254. (org-add-props txt props 'org-marker marker
  5255. 'org-category category 'date date 'todo-state todo-state
  5256. 'org-category-position category-pos 'tags tags
  5257. 'level level
  5258. 'type "sexp" 'warntime warntime)
  5259. (push txt ee)))))
  5260. (nreverse ee)))
  5261. ;; Calendar sanity: define some functions that are independent of
  5262. ;; `calendar-date-style'.
  5263. ;; Normally I would like to use ISO format when calling the diary functions,
  5264. ;; but to make sure we still have Emacs 22 compatibility we bind
  5265. ;; also `european-calendar-style' and use european format
  5266. (defun org-anniversary (year month day &optional mark)
  5267. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5268. (org-no-warnings
  5269. (let ((calendar-date-style 'european) (european-calendar-style t))
  5270. (diary-anniversary day month year mark))))
  5271. (defun org-cyclic (N year month day &optional mark)
  5272. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5273. (org-no-warnings
  5274. (let ((calendar-date-style 'european) (european-calendar-style t))
  5275. (diary-cyclic N day month year mark))))
  5276. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5277. "Like `diary-block', but with fixed (ISO) order of arguments."
  5278. (org-no-warnings
  5279. (let ((calendar-date-style 'european) (european-calendar-style t))
  5280. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5281. (defun org-date (year month day &optional mark)
  5282. "Like `diary-date', but with fixed (ISO) order of arguments."
  5283. (org-no-warnings
  5284. (let ((calendar-date-style 'european) (european-calendar-style t))
  5285. (diary-date day month year mark))))
  5286. ;; Define the` org-class' function
  5287. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5288. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5289. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5290. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5291. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5292. `holidays', then any date that is known by the Emacs calendar to be a
  5293. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5294. then those holidays will be skipped."
  5295. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5296. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5297. (d (calendar-absolute-from-gregorian date))
  5298. (h (when skip-weeks (calendar-check-holidays date))))
  5299. (and
  5300. (<= date1 d)
  5301. (<= d date2)
  5302. (= (calendar-day-of-week date) dayname)
  5303. (or (not skip-weeks)
  5304. (progn
  5305. (require 'cal-iso)
  5306. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5307. (not (or (and h (memq 'holidays skip-weeks))
  5308. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5309. entry)))
  5310. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5311. "Like `org-class', but honor `calendar-date-style'.
  5312. The order of the first 2 times 3 arguments depends on the variable
  5313. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5314. So for American calendars, give this as MONTH DAY YEAR, for European as
  5315. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5316. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5317. is any number of ISO weeks in the block period for which the item should
  5318. be skipped.
  5319. This function is here only for backward compatibility and it is deprecated,
  5320. please use `org-class' instead."
  5321. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5322. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5323. (org-class
  5324. (nth 2 date1) (car date1) (nth 1 date1)
  5325. (nth 2 date2) (car date2) (nth 1 date2)
  5326. dayname skip-weeks)))
  5327. (make-obsolete 'org-diary-class 'org-class "")
  5328. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5329. (defalias 'org-get-closed 'org-agenda-get-progress)
  5330. (defun org-agenda-get-progress ()
  5331. "Return the logged TODO entries for agenda display."
  5332. (let* ((props (list 'mouse-face 'highlight
  5333. 'org-not-done-regexp org-not-done-regexp
  5334. 'org-todo-regexp org-todo-regexp
  5335. 'org-complex-heading-regexp org-complex-heading-regexp
  5336. 'help-echo
  5337. (format "mouse-2 or RET jump to org file %s"
  5338. (abbreviate-file-name buffer-file-name))))
  5339. (items (if (consp org-agenda-show-log-scoped)
  5340. org-agenda-show-log-scoped
  5341. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5342. '(clock)
  5343. org-agenda-log-mode-items)))
  5344. (parts
  5345. (delq nil
  5346. (list
  5347. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5348. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5349. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5350. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5351. (error "`org-agenda-log-mode-items' is empty")))
  5352. (regexp (concat
  5353. "\\(" parts-re "\\)"
  5354. " *\\["
  5355. (regexp-quote
  5356. (substring
  5357. (format-time-string
  5358. (car org-time-stamp-formats)
  5359. (apply 'encode-time ; DATE bound by calendar
  5360. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5361. 1 11))))
  5362. (org-agenda-search-headline-for-time nil)
  5363. marker hdmarker priority category category-pos level tags closedp
  5364. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5365. (goto-char (point-min))
  5366. (while (re-search-forward regexp nil t)
  5367. (catch :skip
  5368. (org-agenda-skip)
  5369. (setq marker (org-agenda-new-marker (match-beginning 0))
  5370. closedp (equal (match-string 1) org-closed-string)
  5371. statep (equal (string-to-char (match-string 1)) ?-)
  5372. clockp (not (or closedp statep))
  5373. state (and statep (match-string 2))
  5374. category (org-get-category (match-beginning 0))
  5375. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5376. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5377. (when (string-match "\\]" timestr)
  5378. ;; substring should only run to end of time stamp
  5379. (setq rest (substring timestr (match-end 0))
  5380. timestr (substring timestr 0 (match-end 0)))
  5381. (if (and (not closedp) (not statep)
  5382. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5383. rest))
  5384. (progn (setq timestr (concat (substring timestr 0 -1)
  5385. "-" (match-string 1 rest) "]"))
  5386. (setq clocked (match-string 2 rest)))
  5387. (setq clocked "-")))
  5388. (save-excursion
  5389. (setq extra
  5390. (cond
  5391. ((not org-agenda-log-mode-add-notes) nil)
  5392. (statep
  5393. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5394. (match-string 1)))
  5395. (clockp
  5396. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5397. (match-string 1)))))
  5398. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5399. (throw :skip nil)
  5400. (goto-char (match-beginning 0))
  5401. (setq hdmarker (org-agenda-new-marker)
  5402. inherited-tags
  5403. (or (eq org-agenda-show-inherited-tags 'always)
  5404. (and (listp org-agenda-show-inherited-tags)
  5405. (memq 'todo org-agenda-show-inherited-tags))
  5406. (and (eq org-agenda-show-inherited-tags t)
  5407. (or (eq org-agenda-use-tag-inheritance t)
  5408. (memq 'todo org-agenda-use-tag-inheritance))))
  5409. tags (org-get-tags-at nil (not inherited-tags))
  5410. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5411. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5412. (setq txt (match-string 1))
  5413. (when extra
  5414. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5415. (setq txt (concat (substring txt 0 (match-beginning 1))
  5416. " - " extra " " (match-string 2 txt)))
  5417. (setq txt (concat txt " - " extra))))
  5418. (setq txt (org-agenda-format-item
  5419. (cond
  5420. (closedp "Closed: ")
  5421. (statep (concat "State: (" state ")"))
  5422. (t (concat "Clocked: (" clocked ")")))
  5423. txt level category tags timestr)))
  5424. (setq priority 100000)
  5425. (org-add-props txt props
  5426. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5427. 'priority priority 'org-category category
  5428. 'org-category-position category-pos
  5429. 'level level
  5430. 'type "closed" 'date date
  5431. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5432. (push txt ee))
  5433. (goto-char (point-at-eol))))
  5434. (nreverse ee)))
  5435. (defun org-agenda-show-clocking-issues ()
  5436. "Add overlays, showing issues with clocking.
  5437. See also the user option `org-agenda-clock-consistency-checks'."
  5438. (interactive)
  5439. (let* ((org-time-clocksum-use-effort-durations nil)
  5440. (pl org-agenda-clock-consistency-checks)
  5441. (re (concat "^[ \t]*"
  5442. org-clock-string
  5443. "[ \t]+"
  5444. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5445. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5446. (tlstart 0.)
  5447. (tlend 0.)
  5448. (maxtime (org-hh:mm-string-to-minutes
  5449. (or (plist-get pl :max-duration) "24:00")))
  5450. (mintime (org-hh:mm-string-to-minutes
  5451. (or (plist-get pl :min-duration) 0)))
  5452. (maxgap (org-hh:mm-string-to-minutes
  5453. ;; default 30:00 means never complain
  5454. (or (plist-get pl :max-gap) "30:00")))
  5455. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5456. (plist-get pl :gap-ok-around)))
  5457. (def-face (or (plist-get pl :default-face)
  5458. '((:background "DarkRed") (:foreground "white"))))
  5459. issue face m te ts dt ov)
  5460. (goto-char (point-min))
  5461. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5462. (setq issue nil face def-face)
  5463. (catch 'next
  5464. (setq m (org-get-at-bol 'org-marker)
  5465. te nil ts nil)
  5466. (unless (and m (markerp m))
  5467. (setq issue "No valid clock line") (throw 'next t))
  5468. (org-with-point-at m
  5469. (save-excursion
  5470. (goto-char (point-at-bol))
  5471. (unless (looking-at re)
  5472. (error "No valid Clock line")
  5473. (throw 'next t))
  5474. (unless (match-end 3)
  5475. (setq issue "No end time"
  5476. face (or (plist-get pl :no-end-time-face) face))
  5477. (throw 'next t))
  5478. (setq ts (match-string 1)
  5479. te (match-string 3)
  5480. ts (org-float-time
  5481. (apply 'encode-time (org-parse-time-string ts)))
  5482. te (org-float-time
  5483. (apply 'encode-time (org-parse-time-string te)))
  5484. dt (- te ts))))
  5485. (cond
  5486. ((> dt (* 60 maxtime))
  5487. ;; a very long clocking chunk
  5488. (setq issue (format "Clocking interval is very long: %s"
  5489. (org-minutes-to-clocksum-string
  5490. (floor (/ (float dt) 60.))))
  5491. face (or (plist-get pl :long-face) face)))
  5492. ((< dt (* 60 mintime))
  5493. ;; a very short clocking chunk
  5494. (setq issue (format "Clocking interval is very short: %s"
  5495. (org-minutes-to-clocksum-string
  5496. (floor (/ (float dt) 60.))))
  5497. face (or (plist-get pl :short-face) face)))
  5498. ((and (> tlend 0) (< ts tlend))
  5499. ;; Two clock entries are overlapping
  5500. (setq issue (format "Clocking overlap: %d minutes"
  5501. (/ (- tlend ts) 60))
  5502. face (or (plist-get pl :overlap-face) face)))
  5503. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5504. ;; There is a gap, lets see if we need to report it
  5505. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5506. (setq issue (format "Clocking gap: %d minutes"
  5507. (/ (- ts tlend) 60))
  5508. face (or (plist-get pl :gap-face) face))))
  5509. (t nil)))
  5510. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5511. (when issue
  5512. ;; OK, there was some issue, add an overlay to show the issue
  5513. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5514. (overlay-put ov 'before-string
  5515. (concat
  5516. (org-add-props
  5517. (format "%-43s" (concat " " issue))
  5518. nil
  5519. 'face face)
  5520. "\n"))
  5521. (overlay-put ov 'evaporate t)))))
  5522. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5523. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5524. (catch 'exit
  5525. (unless ok-list
  5526. ;; there are no OK times for gaps...
  5527. (throw 'exit nil))
  5528. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5529. ;; This is more than 24 hours, so it is OK.
  5530. ;; because we have at least one OK time, that must be in the
  5531. ;; 24 hour interval.
  5532. (throw 'exit t))
  5533. ;; We have a shorter gap.
  5534. ;; Now we have to get the minute of the day when these times are
  5535. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5536. (t2dec (decode-time (seconds-to-time t2)))
  5537. ;; compute the minute on the day
  5538. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5539. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5540. (when (< min2 min1)
  5541. ;; if min2 is smaller than min1, this means it is on the next day.
  5542. ;; Wrap it to after midnight.
  5543. (setq min2 (+ min2 1440)))
  5544. ;; Now check if any of the OK times is in the gap
  5545. (mapc (lambda (x)
  5546. ;; Wrap the time to after midnight if necessary
  5547. (if (< x min1) (setq x (+ x 1440)))
  5548. ;; Check if in interval
  5549. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5550. ok-list)
  5551. ;; Nope, this gap is not OK
  5552. nil)))
  5553. (defun org-agenda-get-deadlines (&optional with-hour)
  5554. "Return the deadline information for agenda display.
  5555. When WITH-HOUR is non-nil, only return deadlines with an hour
  5556. specification like [h]h:mm."
  5557. (let* ((props (list 'mouse-face 'highlight
  5558. 'org-not-done-regexp org-not-done-regexp
  5559. 'org-todo-regexp org-todo-regexp
  5560. 'org-complex-heading-regexp org-complex-heading-regexp
  5561. 'help-echo
  5562. (format "mouse-2 or RET jump to org file %s"
  5563. (abbreviate-file-name buffer-file-name))))
  5564. (regexp (if with-hour
  5565. org-deadline-time-hour-regexp
  5566. org-deadline-time-regexp))
  5567. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5568. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5569. (dl0 (car org-agenda-deadline-leaders))
  5570. (dl1 (nth 1 org-agenda-deadline-leaders))
  5571. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5572. d2 diff dfrac wdays pos pos1 category category-pos level
  5573. tags suppress-prewarning ee txt head face s todo-state
  5574. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5575. (goto-char (point-min))
  5576. (while (re-search-forward regexp nil t)
  5577. (catch :skip
  5578. (org-agenda-skip)
  5579. (setq s (match-string 1)
  5580. txt nil
  5581. pos (1- (match-beginning 1))
  5582. todo-state (save-match-data (org-get-todo-state))
  5583. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5584. (member todo-state
  5585. org-agenda-repeating-timestamp-show-all))
  5586. d2 (org-time-string-to-absolute
  5587. s d1 'past show-all (current-buffer) pos)
  5588. diff (- d2 d1))
  5589. (setq suppress-prewarning
  5590. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5591. (let ((item (buffer-substring (point-at-bol)
  5592. (point-at-eol))))
  5593. (save-match-data
  5594. (and (string-match
  5595. org-scheduled-time-regexp item)
  5596. (match-string 1 item)))))))
  5597. (cond
  5598. ((not ds) nil)
  5599. ;; The current item has a scheduled date (in ds), so
  5600. ;; evaluate its prewarning lead time.
  5601. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5602. ;; Use global prewarning-restart lead time.
  5603. org-agenda-skip-deadline-prewarning-if-scheduled)
  5604. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5605. 'pre-scheduled)
  5606. ;; Set prewarning to no earlier than scheduled.
  5607. (min (- d2 (org-time-string-to-absolute
  5608. ds d1 'past show-all (current-buffer) pos))
  5609. org-deadline-warning-days))
  5610. ;; Set prewarning to deadline.
  5611. (t 0))))
  5612. (setq wdays (if suppress-prewarning
  5613. (let ((org-deadline-warning-days suppress-prewarning))
  5614. (org-get-wdays s))
  5615. (org-get-wdays s))
  5616. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5617. upcomingp (and todayp (> diff 0)))
  5618. ;; When to show a deadline in the calendar:
  5619. ;; If the expiration is within wdays warning time.
  5620. ;; Past-due deadlines are only shown on the current date
  5621. (if (and (or (and (<= diff wdays)
  5622. (and todayp (not org-agenda-only-exact-dates)))
  5623. (= diff 0)))
  5624. (save-excursion
  5625. ;; (setq todo-state (org-get-todo-state))
  5626. (setq donep (member todo-state org-done-keywords))
  5627. (if (and donep
  5628. (or org-agenda-skip-deadline-if-done
  5629. (not (= diff 0))))
  5630. (setq txt nil)
  5631. (setq category (org-get-category)
  5632. warntime (get-text-property (point) 'org-appt-warntime)
  5633. category-pos (get-text-property (point) 'org-category-position))
  5634. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5635. (throw :skip nil)
  5636. (goto-char (match-end 0))
  5637. (setq pos1 (match-beginning 0))
  5638. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5639. (setq inherited-tags
  5640. (or (eq org-agenda-show-inherited-tags 'always)
  5641. (and (listp org-agenda-show-inherited-tags)
  5642. (memq 'agenda org-agenda-show-inherited-tags))
  5643. (and (eq org-agenda-show-inherited-tags t)
  5644. (or (eq org-agenda-use-tag-inheritance t)
  5645. (memq 'agenda org-agenda-use-tag-inheritance))))
  5646. tags (org-get-tags-at pos1 (not inherited-tags)))
  5647. (setq head (buffer-substring
  5648. (point)
  5649. (progn (skip-chars-forward "^\r\n")
  5650. (point))))
  5651. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5652. (setq timestr
  5653. (concat (substring s (match-beginning 1)) " "))
  5654. (setq timestr 'time))
  5655. (setq txt (org-agenda-format-item
  5656. (cond ((= diff 0) dl0)
  5657. ((> diff 0)
  5658. (if (functionp dl1)
  5659. (funcall dl1 diff date)
  5660. (format dl1 diff)))
  5661. (t
  5662. (if (functionp dl2)
  5663. (funcall dl2 diff date)
  5664. (format dl2 (if (string= dl2 dl1)
  5665. diff (abs diff))))))
  5666. head level category tags
  5667. (if (not (= diff 0)) nil timestr)))))
  5668. (when txt
  5669. (setq face (org-agenda-deadline-face dfrac))
  5670. (org-add-props txt props
  5671. 'org-marker (org-agenda-new-marker pos)
  5672. 'warntime warntime
  5673. 'level level
  5674. 'ts-date d2
  5675. 'org-hd-marker (org-agenda-new-marker pos1)
  5676. 'priority (+ (- diff)
  5677. (org-get-priority txt))
  5678. 'org-category category
  5679. 'org-category-position category-pos
  5680. 'todo-state todo-state
  5681. 'type (if upcomingp "upcoming-deadline" "deadline")
  5682. 'date (if upcomingp date d2)
  5683. 'face (if donep 'org-agenda-done face)
  5684. 'undone-face face 'done-face 'org-agenda-done)
  5685. (push txt ee))))))
  5686. (nreverse ee)))
  5687. (defun org-agenda-deadline-face (fraction)
  5688. "Return the face to displaying a deadline item.
  5689. FRACTION is what fraction of the head-warning time has passed."
  5690. (let ((faces org-agenda-deadline-faces) f)
  5691. (catch 'exit
  5692. (while (setq f (pop faces))
  5693. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5694. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5695. "Return the scheduled information for agenda display.
  5696. When WITH-HOUR is non-nil, only return scheduled items with
  5697. an hour specification like [h]h:mm."
  5698. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5699. 'org-todo-regexp org-todo-regexp
  5700. 'org-complex-heading-regexp org-complex-heading-regexp
  5701. 'done-face 'org-agenda-done
  5702. 'mouse-face 'highlight
  5703. 'help-echo
  5704. (format "mouse-2 or RET jump to org file %s"
  5705. (abbreviate-file-name buffer-file-name))))
  5706. (regexp (if with-hour
  5707. org-scheduled-time-hour-regexp
  5708. org-scheduled-time-regexp))
  5709. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5710. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5711. mm
  5712. (deadline-position-alist
  5713. (mapcar (lambda (a) (and (setq mm (get-text-property
  5714. 0 'org-hd-marker a))
  5715. (cons (marker-position mm) a)))
  5716. deadline-results))
  5717. d2 diff pos pos1 category category-pos level tags donep
  5718. ee txt head pastschedp todo-state face timestr s habitp show-all
  5719. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5720. ddays)
  5721. (goto-char (point-min))
  5722. (while (re-search-forward regexp nil t)
  5723. (catch :skip
  5724. (org-agenda-skip)
  5725. (setq s (match-string 1)
  5726. txt nil
  5727. pos (1- (match-beginning 1))
  5728. todo-state (save-match-data (org-get-todo-state))
  5729. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5730. (member todo-state
  5731. org-agenda-repeating-timestamp-show-all))
  5732. d2 (org-time-string-to-absolute
  5733. s d1 'past show-all (current-buffer) pos)
  5734. diff (- d2 d1)
  5735. warntime (get-text-property (point) 'org-appt-warntime))
  5736. (setq pastschedp (and todayp (< diff 0)))
  5737. (setq did-habit-check-p nil)
  5738. (setq suppress-delay
  5739. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5740. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5741. (save-match-data
  5742. (and (string-match
  5743. org-deadline-time-regexp item)
  5744. (match-string 1 item)))))))
  5745. (cond
  5746. ((not ds) nil)
  5747. ;; The current item has a deadline date (in ds), so
  5748. ;; evaluate its delay time.
  5749. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5750. ;; Use global delay time.
  5751. (- org-agenda-skip-scheduled-delay-if-deadline))
  5752. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5753. 'post-deadline)
  5754. ;; Set delay to no later than deadline.
  5755. (min (- d2 (org-time-string-to-absolute
  5756. ds d1 'past show-all (current-buffer) pos))
  5757. org-scheduled-delay-days))
  5758. (t 0))))
  5759. (setq ddays (if suppress-delay
  5760. (let ((org-scheduled-delay-days suppress-delay))
  5761. (org-get-wdays s t t))
  5762. (org-get-wdays s t)))
  5763. ;; Use a delay of 0 when there is a repeater and the delay is
  5764. ;; of the form --3d
  5765. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5766. (< (org-time-string-to-absolute s)
  5767. (org-time-string-to-absolute
  5768. s d2 'past nil (current-buffer) pos)))
  5769. (setq ddays 0))
  5770. ;; When to show a scheduled item in the calendar:
  5771. ;; If it is on or past the date.
  5772. (when (or (and (> ddays 0) (= diff (- ddays)))
  5773. (and (zerop ddays) (= diff 0))
  5774. (and (< (+ diff ddays) 0)
  5775. (< (abs diff) org-scheduled-past-days)
  5776. (and todayp (not org-agenda-only-exact-dates)))
  5777. ;; org-is-habit-p uses org-entry-get, which is expansive
  5778. ;; so we go extra mile to only call it once
  5779. (and todayp
  5780. (boundp 'org-habit-show-all-today)
  5781. org-habit-show-all-today
  5782. (setq did-habit-check-p t)
  5783. (setq habitp (and (functionp 'org-is-habit-p)
  5784. (org-is-habit-p)))))
  5785. (save-excursion
  5786. (setq donep (member todo-state org-done-keywords))
  5787. (if (and donep
  5788. (or org-agenda-skip-scheduled-if-done
  5789. (not (= diff 0))
  5790. (and (functionp 'org-is-habit-p)
  5791. (org-is-habit-p))))
  5792. (setq txt nil)
  5793. (setq habitp (if did-habit-check-p habitp
  5794. (and (functionp 'org-is-habit-p)
  5795. (org-is-habit-p))))
  5796. (setq category (org-get-category)
  5797. category-pos (get-text-property (point) 'org-category-position))
  5798. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5799. 'repeated-after-deadline)
  5800. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5801. (throw :skip nil))
  5802. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5803. (throw :skip nil)
  5804. (goto-char (match-end 0))
  5805. (setq pos1 (match-beginning 0))
  5806. (if habitp
  5807. (if (or (not org-habit-show-habits)
  5808. (and (not todayp)
  5809. (boundp 'org-habit-show-habits-only-for-today)
  5810. org-habit-show-habits-only-for-today))
  5811. (throw :skip nil))
  5812. (if (and
  5813. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5814. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5815. pastschedp))
  5816. (setq mm (assoc pos1 deadline-position-alist)))
  5817. (throw :skip nil)))
  5818. (setq inherited-tags
  5819. (or (eq org-agenda-show-inherited-tags 'always)
  5820. (and (listp org-agenda-show-inherited-tags)
  5821. (memq 'agenda org-agenda-show-inherited-tags))
  5822. (and (eq org-agenda-show-inherited-tags t)
  5823. (or (eq org-agenda-use-tag-inheritance t)
  5824. (memq 'agenda org-agenda-use-tag-inheritance))))
  5825. tags (org-get-tags-at nil (not inherited-tags)))
  5826. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5827. (setq head (buffer-substring
  5828. (point)
  5829. (progn (skip-chars-forward "^\r\n") (point))))
  5830. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5831. (setq timestr
  5832. (concat (substring s (match-beginning 1)) " "))
  5833. (setq timestr 'time))
  5834. (setq txt (org-agenda-format-item
  5835. (if (= diff 0)
  5836. (car org-agenda-scheduled-leaders)
  5837. (format (nth 1 org-agenda-scheduled-leaders)
  5838. (- 1 diff)))
  5839. head level category tags
  5840. (if (not (= diff 0)) nil timestr)
  5841. nil habitp))))
  5842. (when txt
  5843. (setq face
  5844. (cond
  5845. ((and (not habitp) pastschedp)
  5846. 'org-scheduled-previously)
  5847. (todayp 'org-scheduled-today)
  5848. (t 'org-scheduled))
  5849. habitp (and habitp (org-habit-parse-todo)))
  5850. (org-add-props txt props
  5851. 'undone-face face
  5852. 'face (if donep 'org-agenda-done face)
  5853. 'org-marker (org-agenda-new-marker pos)
  5854. 'org-hd-marker (org-agenda-new-marker pos1)
  5855. 'type (if pastschedp "past-scheduled" "scheduled")
  5856. 'date (if pastschedp d2 date)
  5857. 'ts-date d2
  5858. 'warntime warntime
  5859. 'level level
  5860. 'priority (if habitp
  5861. (org-habit-get-priority habitp)
  5862. (+ 94 (- 5 diff) (org-get-priority txt)))
  5863. 'org-category category
  5864. 'category-position category-pos
  5865. 'org-habit-p habitp
  5866. 'todo-state todo-state)
  5867. (push txt ee))))))
  5868. (nreverse ee)))
  5869. (defun org-agenda-get-blocks ()
  5870. "Return the date-range information for agenda display."
  5871. (let* ((props (list 'face nil
  5872. 'org-not-done-regexp org-not-done-regexp
  5873. 'org-todo-regexp org-todo-regexp
  5874. 'org-complex-heading-regexp org-complex-heading-regexp
  5875. 'mouse-face 'highlight
  5876. 'help-echo
  5877. (format "mouse-2 or RET jump to org file %s"
  5878. (abbreviate-file-name buffer-file-name))))
  5879. (regexp org-tr-regexp)
  5880. (d0 (calendar-absolute-from-gregorian date))
  5881. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5882. level todo-state tags pos head donep inherited-tags)
  5883. (goto-char (point-min))
  5884. (while (re-search-forward regexp nil t)
  5885. (catch :skip
  5886. (org-agenda-skip)
  5887. (setq pos (point))
  5888. (let ((start-time (match-string 1))
  5889. (end-time (match-string 2)))
  5890. (setq s1 (match-string 1)
  5891. s2 (match-string 2)
  5892. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5893. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5894. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5895. ;; Only allow days between the limits, because the normal
  5896. ;; date stamps will catch the limits.
  5897. (save-excursion
  5898. (setq todo-state (org-get-todo-state))
  5899. (setq donep (member todo-state org-done-keywords))
  5900. (if (and donep org-agenda-skip-timestamp-if-done)
  5901. (throw :skip t))
  5902. (setq marker (org-agenda-new-marker (point)))
  5903. (setq category (org-get-category)
  5904. category-pos (get-text-property (point) 'org-category-position))
  5905. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5906. (throw :skip nil)
  5907. (goto-char (match-beginning 0))
  5908. (setq hdmarker (org-agenda-new-marker (point))
  5909. inherited-tags
  5910. (or (eq org-agenda-show-inherited-tags 'always)
  5911. (and (listp org-agenda-show-inherited-tags)
  5912. (memq 'agenda org-agenda-show-inherited-tags))
  5913. (and (eq org-agenda-show-inherited-tags t)
  5914. (or (eq org-agenda-use-tag-inheritance t)
  5915. (memq 'agenda org-agenda-use-tag-inheritance))))
  5916. tags (org-get-tags-at nil (not inherited-tags)))
  5917. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5918. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5919. (setq head (match-string 1))
  5920. (let ((remove-re
  5921. (if org-agenda-remove-timeranges-from-blocks
  5922. (concat
  5923. "<" (regexp-quote s1) ".*?>"
  5924. "--"
  5925. "<" (regexp-quote s2) ".*?>")
  5926. nil)))
  5927. (setq txt (org-agenda-format-item
  5928. (format
  5929. (nth (if (= d1 d2) 0 1)
  5930. org-agenda-timerange-leaders)
  5931. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5932. head level category tags
  5933. (cond ((and (= d1 d0) (= d2 d0))
  5934. (concat "<" start-time ">--<" end-time ">"))
  5935. ((= d1 d0)
  5936. (concat "<" start-time ">"))
  5937. ((= d2 d0)
  5938. (concat "<" end-time ">")))
  5939. remove-re))))
  5940. (org-add-props txt props
  5941. 'org-marker marker 'org-hd-marker hdmarker
  5942. 'type "block" 'date date
  5943. 'level level
  5944. 'todo-state todo-state
  5945. 'priority (org-get-priority txt) 'org-category category
  5946. 'org-category-position category-pos)
  5947. (push txt ee))))
  5948. (goto-char pos)))
  5949. ;; Sort the entries by expiration date.
  5950. (nreverse ee)))
  5951. ;;; Agenda presentation and sorting
  5952. (defvar org-prefix-has-time nil
  5953. "A flag, set by `org-compile-prefix-format'.
  5954. The flag is set if the currently compiled format contains a `%t'.")
  5955. (defvar org-prefix-has-tag nil
  5956. "A flag, set by `org-compile-prefix-format'.
  5957. The flag is set if the currently compiled format contains a `%T'.")
  5958. (defvar org-prefix-has-effort nil
  5959. "A flag, set by `org-compile-prefix-format'.
  5960. The flag is set if the currently compiled format contains a `%e'.")
  5961. (defvar org-prefix-has-breadcrumbs nil
  5962. "A flag, set by `org-compile-prefix-format'.
  5963. The flag is set if the currently compiled format contains a `%b'.")
  5964. (defvar org-prefix-category-length nil
  5965. "Used by `org-compile-prefix-format' to remember the category field width.")
  5966. (defvar org-prefix-category-max-length nil
  5967. "Used by `org-compile-prefix-format' to remember the category field width.")
  5968. (defun org-agenda-get-category-icon (category)
  5969. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5970. (dolist (entry org-agenda-category-icon-alist)
  5971. (when (org-string-match-p (car entry) category)
  5972. (if (listp (cadr entry))
  5973. (return (cadr entry))
  5974. (return (apply 'create-image (cdr entry)))))))
  5975. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5976. remove-re habitp)
  5977. "Format TXT to be inserted into the agenda buffer.
  5978. In particular, add the prefix and corresponding text properties.
  5979. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5980. LEVEL may be a string to replace the `%l' specifier.
  5981. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5982. category taken from local variable or file name. It will replace the `%c'
  5983. specifier in the format.
  5984. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5985. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5986. When DOTIME is a string, this string is searched for a time before TXT is.
  5987. TAGS can be the tags of the headline.
  5988. Any match of REMOVE-RE will be removed from TXT."
  5989. ;; We keep the org-prefix-* variable values along with a compiled
  5990. ;; formatter, so that multiple agendas existing at the same time do
  5991. ;; not step on each other toes.
  5992. ;;
  5993. ;; It was inconvenient to make these variables buffer local in
  5994. ;; Agenda buffers, because this function expects to be called with
  5995. ;; the buffer where item comes from being current, and not agenda
  5996. ;; buffer
  5997. (let* ((bindings (car org-prefix-format-compiled))
  5998. (formatter (cadr org-prefix-format-compiled)))
  5999. (loop for (var value) in bindings
  6000. do (set var value))
  6001. (save-match-data
  6002. ;; Diary entries sometimes have extra whitespace at the beginning
  6003. (setq txt (org-trim txt))
  6004. ;; Fix the tags part in txt
  6005. (setq txt (org-agenda-fix-displayed-tags
  6006. txt tags
  6007. org-agenda-show-inherited-tags
  6008. org-agenda-hide-tags-regexp))
  6009. (let* ((category (or category
  6010. (if (stringp org-category)
  6011. org-category
  6012. (and org-category (symbol-name org-category)))
  6013. (if buffer-file-name
  6014. (file-name-sans-extension
  6015. (file-name-nondirectory buffer-file-name))
  6016. "")))
  6017. (category-icon (org-agenda-get-category-icon category))
  6018. (category-icon (if category-icon
  6019. (propertize " " 'display category-icon)
  6020. ""))
  6021. ;; time, tag, effort are needed for the eval of the prefix format
  6022. (tag (if tags (nth (1- (length tags)) tags) ""))
  6023. time effort neffort
  6024. (ts (if dotime (concat
  6025. (if (stringp dotime) dotime "")
  6026. (and org-agenda-search-headline-for-time txt))))
  6027. (time-of-day (and dotime (org-get-time-of-day ts)))
  6028. stamp plain s0 s1 s2 rtn srp l
  6029. duration thecategory breadcrumbs)
  6030. (and (derived-mode-p 'org-mode) buffer-file-name
  6031. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6032. (when (and dotime time-of-day)
  6033. ;; Extract starting and ending time and move them to prefix
  6034. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6035. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6036. (setq s0 (match-string 0 ts)
  6037. srp (and stamp (match-end 3))
  6038. s1 (match-string (if plain 1 2) ts)
  6039. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6040. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6041. ;; them, we might want to remove them there to avoid duplication.
  6042. ;; The user can turn this off with a variable.
  6043. (if (and org-prefix-has-time
  6044. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6045. (string-match (concat (regexp-quote s0) " *") txt)
  6046. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6047. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6048. (= (match-beginning 0) 0)
  6049. t))
  6050. (setq txt (replace-match "" nil nil txt))))
  6051. ;; Normalize the time(s) to 24 hour
  6052. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6053. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6054. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6055. (let (org-time-clocksum-use-effort-durations)
  6056. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6057. (setq s2
  6058. (org-minutes-to-clocksum-string
  6059. (+ (org-hh:mm-string-to-minutes s1)
  6060. org-agenda-default-appointment-duration)))))
  6061. ;; Compute the duration
  6062. (when s2
  6063. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6064. (org-hh:mm-string-to-minutes s1)))))
  6065. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6066. txt)
  6067. ;; Tags are in the string
  6068. (if (or (eq org-agenda-remove-tags t)
  6069. (and org-agenda-remove-tags
  6070. org-prefix-has-tag))
  6071. (setq txt (replace-match "" t t txt))
  6072. (setq txt (replace-match
  6073. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6074. (match-string 2 txt))
  6075. t t txt))))
  6076. (when (derived-mode-p 'org-mode)
  6077. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6078. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6079. ;; current buffer, so move this check outside of above
  6080. (if effort
  6081. (setq neffort (org-duration-string-to-minutes effort)
  6082. effort (setq effort (concat "[" effort "]")))
  6083. ;; prevent erroring out with %e format when there is no effort
  6084. (setq effort ""))
  6085. (when remove-re
  6086. (while (string-match remove-re txt)
  6087. (setq txt (replace-match "" t t txt))))
  6088. ;; Set org-heading property on `txt' to mark the start of the
  6089. ;; heading.
  6090. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6091. ;; Prepare the variables needed in the eval of the compiled format
  6092. (if org-prefix-has-breadcrumbs
  6093. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6094. (let ((s (org-display-outline-path nil nil "->" t)))
  6095. (if (eq "" s) "" (concat s "->"))))))
  6096. (setq time (cond (s2 (concat
  6097. (org-agenda-time-of-day-to-ampm-maybe s1)
  6098. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6099. (if org-agenda-timegrid-use-ampm " ")))
  6100. (s1 (concat
  6101. (org-agenda-time-of-day-to-ampm-maybe s1)
  6102. (if org-agenda-timegrid-use-ampm
  6103. "........ "
  6104. "......")))
  6105. (t ""))
  6106. extra (or (and (not habitp) extra) "")
  6107. category (if (symbolp category) (symbol-name category) category)
  6108. thecategory (copy-sequence category)
  6109. level (or level ""))
  6110. (if (string-match org-bracket-link-regexp category)
  6111. (progn
  6112. (setq l (if (match-end 3)
  6113. (- (match-end 3) (match-beginning 3))
  6114. (- (match-end 1) (match-beginning 1))))
  6115. (when (< l (or org-prefix-category-length 0))
  6116. (setq category (copy-sequence category))
  6117. (org-add-props category nil
  6118. 'extra-space (make-string
  6119. (- org-prefix-category-length l 1) ?\ ))))
  6120. (if (and org-prefix-category-max-length
  6121. (>= (length category) org-prefix-category-max-length))
  6122. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6123. ;; Evaluate the compiled format
  6124. (setq rtn (concat (eval formatter) txt))
  6125. ;; And finally add the text properties
  6126. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6127. (org-add-props rtn nil
  6128. 'org-category (if thecategory (downcase thecategory) category)
  6129. 'tags (mapcar 'org-downcase-keep-props tags)
  6130. 'org-highest-priority org-highest-priority
  6131. 'org-lowest-priority org-lowest-priority
  6132. 'time-of-day time-of-day
  6133. 'duration duration
  6134. 'effort effort
  6135. 'effort-minutes neffort
  6136. 'breadcrumbs breadcrumbs
  6137. 'txt txt
  6138. 'level level
  6139. 'time time
  6140. 'extra extra
  6141. 'format org-prefix-format-compiled
  6142. 'dotime dotime)))))
  6143. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6144. "Remove tags string from TXT, and add a modified list of tags.
  6145. The modified list may contain inherited tags, and tags matched by
  6146. `org-agenda-hide-tags-regexp' will be removed."
  6147. (when (or add-inherited hide-re)
  6148. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6149. (setq txt (substring txt 0 (match-beginning 0))))
  6150. (setq tags
  6151. (delq nil
  6152. (mapcar (lambda (tg)
  6153. (if (or (and hide-re (string-match hide-re tg))
  6154. (and (not add-inherited)
  6155. (get-text-property 0 'inherited tg)))
  6156. nil
  6157. tg))
  6158. tags)))
  6159. (when tags
  6160. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6161. i)
  6162. (setq txt (concat txt " :"
  6163. (mapconcat
  6164. (lambda (x)
  6165. (setq i (get-text-property 0 'inherited x))
  6166. (if (and have-i (not i))
  6167. (progn
  6168. (setq have-i nil)
  6169. (concat ":" x))
  6170. x))
  6171. tags ":")
  6172. (if have-i "::" ":"))))))
  6173. txt)
  6174. (defun org-downcase-keep-props (s)
  6175. (let ((props (text-properties-at 0 s)))
  6176. (setq s (downcase s))
  6177. (add-text-properties 0 (length s) props s)
  6178. s))
  6179. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6180. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6181. "Add a time-grid for agenda items which need it.
  6182. LIST is the list of agenda items formatted by `org-agenda-list'.
  6183. NDAYS is the span of the current agenda view.
  6184. TODAYP is `t' when the current agenda view is on today."
  6185. (catch 'exit
  6186. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6187. ((and todayp (member 'today (car org-agenda-time-grid))))
  6188. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6189. ((member 'weekly (car org-agenda-time-grid)))
  6190. (t (throw 'exit list)))
  6191. (let* ((have (delq nil (mapcar
  6192. (lambda (x) (get-text-property 1 'time-of-day x))
  6193. list)))
  6194. (string (nth 1 org-agenda-time-grid))
  6195. (gridtimes (nth 2 org-agenda-time-grid))
  6196. (req (car org-agenda-time-grid))
  6197. (remove (member 'remove-match req))
  6198. new time)
  6199. (if (and (member 'require-timed req) (not have))
  6200. ;; don't show empty grid
  6201. (throw 'exit list))
  6202. (while (setq time (pop gridtimes))
  6203. (unless (and remove (member time have))
  6204. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6205. (push (org-agenda-format-item
  6206. nil string nil "" nil
  6207. (concat (substring time 0 -2) ":" (substring time -2)))
  6208. new)
  6209. (put-text-property
  6210. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6211. (when (and todayp org-agenda-show-current-time-in-grid)
  6212. (push (org-agenda-format-item
  6213. nil org-agenda-current-time-string nil "" nil
  6214. (format-time-string "%H:%M "))
  6215. new)
  6216. (put-text-property
  6217. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6218. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6219. (append new list)
  6220. (append list new)))))
  6221. (defun org-compile-prefix-format (key)
  6222. "Compile the prefix format into a Lisp form that can be evaluated.
  6223. The resulting form and associated variable bindings is returned
  6224. and stored in the variable `org-prefix-format-compiled'."
  6225. (setq org-prefix-has-time nil
  6226. org-prefix-has-tag nil
  6227. org-prefix-category-length nil
  6228. org-prefix-has-effort nil
  6229. org-prefix-has-breadcrumbs nil)
  6230. (let ((s (cond
  6231. ((stringp org-agenda-prefix-format)
  6232. org-agenda-prefix-format)
  6233. ((assq key org-agenda-prefix-format)
  6234. (cdr (assq key org-agenda-prefix-format)))
  6235. (t " %-12:c%?-12t% s")))
  6236. (start 0)
  6237. varform vars var e c f opt)
  6238. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6239. s start)
  6240. (setq var (or (cdr (assoc (match-string 4 s)
  6241. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6242. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6243. 'eval)
  6244. c (or (match-string 3 s) "")
  6245. opt (match-beginning 1)
  6246. start (1+ (match-beginning 0)))
  6247. (if (equal var 'time) (setq org-prefix-has-time t))
  6248. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6249. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6250. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6251. (setq f (concat "%" (match-string 2 s) "s"))
  6252. (when (equal var 'category)
  6253. (setq org-prefix-category-length
  6254. (floor (abs (string-to-number (match-string 2 s)))))
  6255. (setq org-prefix-category-max-length
  6256. (let ((x (match-string 2 s)))
  6257. (save-match-data
  6258. (if (string-match "\\.[0-9]+" x)
  6259. (string-to-number (substring (match-string 0 x) 1)))))))
  6260. (if (eq var 'eval)
  6261. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6262. (if opt
  6263. (setq varform
  6264. `(if (equal "" ,var)
  6265. ""
  6266. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6267. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6268. (setq s (replace-match "%s" t nil s))
  6269. (push varform vars))
  6270. (setq vars (nreverse vars))
  6271. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6272. (setq org-prefix-format-compiled
  6273. (list
  6274. `((org-prefix-has-time ,org-prefix-has-time)
  6275. (org-prefix-has-tag ,org-prefix-has-tag)
  6276. (org-prefix-category-length ,org-prefix-category-length)
  6277. (org-prefix-has-effort ,org-prefix-has-effort)
  6278. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6279. `(format ,s ,@vars))))))
  6280. (defun org-set-sorting-strategy (key)
  6281. (if (symbolp (car org-agenda-sorting-strategy))
  6282. ;; the old format
  6283. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6284. (setq org-agenda-sorting-strategy-selected
  6285. (or (cdr (assq key org-agenda-sorting-strategy))
  6286. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6287. '(time-up category-keep priority-down)))))
  6288. (defun org-get-time-of-day (s &optional string mod24)
  6289. "Check string S for a time of day.
  6290. If found, return it as a military time number between 0 and 2400.
  6291. If not found, return nil.
  6292. The optional STRING argument forces conversion into a 5 character wide string
  6293. HH:MM."
  6294. (save-match-data
  6295. (when
  6296. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6297. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6298. (let* ((h (string-to-number (match-string 1 s)))
  6299. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6300. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6301. (am-p (equal ampm "am"))
  6302. (h1 (cond ((not ampm) h)
  6303. ((= h 12) (if am-p 0 12))
  6304. (t (+ h (if am-p 0 12)))))
  6305. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6306. (mod h1 24) h1))
  6307. (t0 (+ (* 100 h2) m))
  6308. (t1 (concat (if (>= h1 24) "+" " ")
  6309. (if (and org-agenda-time-leading-zero
  6310. (< t0 1000)) "0" "")
  6311. (if (< t0 100) "0" "")
  6312. (if (< t0 10) "0" "")
  6313. (int-to-string t0))))
  6314. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6315. (defvar org-agenda-before-sorting-filter-function nil
  6316. "Function to be applied to agenda items prior to sorting.
  6317. Prior to sorting also means just before they are inserted into the agenda.
  6318. To aid sorting, you may revisit the original entries and add more text
  6319. properties which will later be used by the sorting functions.
  6320. The function should take a string argument, an agenda line.
  6321. It has access to the text properties in that line, which contain among
  6322. other things, the property `org-hd-marker' that points to the entry
  6323. where the line comes from. Note that not all lines going into the agenda
  6324. have this property, only most.
  6325. The function should return the modified string. It is probably best
  6326. to ONLY change text properties.
  6327. You can also use this function as a filter, by returning nil for lines
  6328. you don't want to have in the agenda at all. For this application, you
  6329. could bind the variable in the options section of a custom command.")
  6330. (defun org-agenda-finalize-entries (list &optional type)
  6331. "Sort, limit and concatenate the LIST of agenda items.
  6332. The optional argument TYPE tells the agenda type."
  6333. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6334. (cdr (assoc type org-agenda-max-effort)))
  6335. (t org-agenda-max-effort)))
  6336. (max-todo (cond ((listp org-agenda-max-todos)
  6337. (cdr (assoc type org-agenda-max-todos)))
  6338. (t org-agenda-max-todos)))
  6339. (max-tags (cond ((listp org-agenda-max-tags)
  6340. (cdr (assoc type org-agenda-max-tags)))
  6341. (t org-agenda-max-tags)))
  6342. (max-entries (cond ((listp org-agenda-max-entries)
  6343. (cdr (assoc type org-agenda-max-entries)))
  6344. (t org-agenda-max-entries))) l)
  6345. (when org-agenda-before-sorting-filter-function
  6346. (setq list
  6347. (delq nil
  6348. (mapcar
  6349. org-agenda-before-sorting-filter-function list))))
  6350. (setq list (mapcar 'org-agenda-highlight-todo list)
  6351. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6352. (when max-effort
  6353. (setq list (org-agenda-limit-entries
  6354. list 'effort-minutes max-effort 'identity)))
  6355. (when max-todo
  6356. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6357. (when max-tags
  6358. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6359. (when max-entries
  6360. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6361. (mapconcat 'identity list "\n")))
  6362. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6363. "Limit the number of agenda entries."
  6364. (let ((include (and limit (< limit 0))))
  6365. (if limit
  6366. (let ((fun (or fn (lambda (p) (if p 1))))
  6367. (lim 0))
  6368. (delq nil
  6369. (mapcar
  6370. (lambda (e)
  6371. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6372. (if pval (setq lim (+ lim pval)))
  6373. (cond ((and pval (<= lim (abs limit))) e)
  6374. ((and include (not pval)) e))))
  6375. list)))
  6376. list)))
  6377. (defun org-agenda-limit-interactively ()
  6378. "In agenda, interactively limit entries to various maximums."
  6379. (interactive)
  6380. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6381. (num (string-to-number (read-from-minibuffer "How many? "))))
  6382. (cond ((equal max ?e)
  6383. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6384. ((equal max ?t)
  6385. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6386. ((equal max ?T)
  6387. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6388. ((equal max ?E)
  6389. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6390. (org-agenda-fit-window-to-buffer))
  6391. (defun org-agenda-highlight-todo (x)
  6392. (let ((org-done-keywords org-done-keywords-for-agenda)
  6393. (case-fold-search nil)
  6394. re)
  6395. (if (eq x 'line)
  6396. (save-excursion
  6397. (beginning-of-line 1)
  6398. (setq re (org-get-at-bol 'org-todo-regexp))
  6399. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6400. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6401. (add-text-properties (match-beginning 0) (match-end 1)
  6402. (list 'face (org-get-todo-face 1)))
  6403. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6404. (delete-region (match-beginning 1) (1- (match-end 0)))
  6405. (goto-char (match-beginning 1))
  6406. (insert (format org-agenda-todo-keyword-format s)))))
  6407. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6408. (setq re (get-text-property 0 'org-todo-regexp x))
  6409. (when (and re
  6410. ;; Test `pl' because if there's no heading content,
  6411. ;; there's no point matching to highlight. Note
  6412. ;; that if we didn't test `pl' first, and there
  6413. ;; happened to be no keyword from `org-todo-regexp'
  6414. ;; on this heading line, then the `equal' comparison
  6415. ;; afterwards would spuriously succeed in the case
  6416. ;; where `pl' is nil -- causing an args-out-of-range
  6417. ;; error when we try to add text properties to text
  6418. ;; that isn't there.
  6419. pl
  6420. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6421. x pl) pl))
  6422. (add-text-properties
  6423. (or (match-end 1) (match-end 0)) (match-end 0)
  6424. (list 'face (org-get-todo-face (match-string 2 x)))
  6425. x)
  6426. (when (match-end 1)
  6427. (setq x (concat (substring x 0 (match-end 1))
  6428. (format org-agenda-todo-keyword-format
  6429. (match-string 2 x))
  6430. (org-add-props " " (text-properties-at 0 x))
  6431. (substring x (match-end 3)))))))
  6432. x)))
  6433. (defsubst org-cmp-priority (a b)
  6434. "Compare the priorities of string A and B."
  6435. (let ((pa (or (get-text-property 1 'priority a) 0))
  6436. (pb (or (get-text-property 1 'priority b) 0)))
  6437. (cond ((> pa pb) +1)
  6438. ((< pa pb) -1))))
  6439. (defsubst org-cmp-effort (a b)
  6440. "Compare the effort values of string A and B."
  6441. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6442. (ea (or (get-text-property 1 'effort-minutes a) def))
  6443. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6444. (cond ((> ea eb) +1)
  6445. ((< ea eb) -1))))
  6446. (defsubst org-cmp-category (a b)
  6447. "Compare the string values of categories of strings A and B."
  6448. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6449. (cb (or (get-text-property 1 'org-category b) "")))
  6450. (cond ((string-lessp ca cb) -1)
  6451. ((string-lessp cb ca) +1))))
  6452. (defsubst org-cmp-todo-state (a b)
  6453. "Compare the todo states of strings A and B."
  6454. (let* ((ma (or (get-text-property 1 'org-marker a)
  6455. (get-text-property 1 'org-hd-marker a)))
  6456. (mb (or (get-text-property 1 'org-marker b)
  6457. (get-text-property 1 'org-hd-marker b)))
  6458. (fa (and ma (marker-buffer ma)))
  6459. (fb (and mb (marker-buffer mb)))
  6460. (todo-kwds
  6461. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6462. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6463. (ta (or (get-text-property 1 'todo-state a) ""))
  6464. (tb (or (get-text-property 1 'todo-state b) ""))
  6465. (la (- (length (member ta todo-kwds))))
  6466. (lb (- (length (member tb todo-kwds))))
  6467. (donepa (member ta org-done-keywords-for-agenda))
  6468. (donepb (member tb org-done-keywords-for-agenda)))
  6469. (cond ((and donepa (not donepb)) -1)
  6470. ((and (not donepa) donepb) +1)
  6471. ((< la lb) -1)
  6472. ((< lb la) +1))))
  6473. (defsubst org-cmp-alpha (a b)
  6474. "Compare the headlines, alphabetically."
  6475. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6476. (plb (text-property-any 0 (length b) 'org-heading t b))
  6477. (ta (and pla (substring a pla)))
  6478. (tb (and plb (substring b plb))))
  6479. (when pla
  6480. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6481. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6482. (setq ta (substring ta (match-end 0))))
  6483. (setq ta (downcase ta)))
  6484. (when plb
  6485. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6486. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6487. (setq tb (substring tb (match-end 0))))
  6488. (setq tb (downcase tb)))
  6489. (cond ((not ta) +1)
  6490. ((not tb) -1)
  6491. ((string-lessp ta tb) -1)
  6492. ((string-lessp tb ta) +1))))
  6493. (defsubst org-cmp-tag (a b)
  6494. "Compare the string values of the first tags of A and B."
  6495. (let ((ta (car (last (get-text-property 1 'tags a))))
  6496. (tb (car (last (get-text-property 1 'tags b)))))
  6497. (cond ((not ta) +1)
  6498. ((not tb) -1)
  6499. ((string-lessp ta tb) -1)
  6500. ((string-lessp tb ta) +1))))
  6501. (defsubst org-cmp-time (a b)
  6502. "Compare the time-of-day values of strings A and B."
  6503. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6504. (ta (or (get-text-property 1 'time-of-day a) def))
  6505. (tb (or (get-text-property 1 'time-of-day b) def)))
  6506. (cond ((< ta tb) -1)
  6507. ((< tb ta) +1))))
  6508. (defsubst org-cmp-ts (a b &optional type)
  6509. "Compare the timestamps values of entries A and B.
  6510. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6511. \"timestamp_ia\", compare within each of these type. When TYPE
  6512. is the empty string, compare all timestamps without respect of
  6513. their type."
  6514. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6515. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6516. (get-text-property 1 'ts-date a)) def))
  6517. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6518. (get-text-property 1 'ts-date b)) def)))
  6519. (cond ((< ta tb) -1)
  6520. ((< tb ta) +1))))
  6521. (defsubst org-cmp-habit-p (a b)
  6522. "Compare the todo states of strings A and B."
  6523. (let ((ha (get-text-property 1 'org-habit-p a))
  6524. (hb (get-text-property 1 'org-habit-p b)))
  6525. (cond ((and ha (not hb)) -1)
  6526. ((and (not ha) hb) +1))))
  6527. (defun org-entries-lessp (a b)
  6528. "Predicate for sorting agenda entries."
  6529. ;; The following variables will be used when the form is evaluated.
  6530. ;; So even though the compiler complains, keep them.
  6531. (let* ((ss org-agenda-sorting-strategy-selected)
  6532. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6533. (org-cmp-ts a b "")))
  6534. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6535. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6536. (org-cmp-ts a b "scheduled")))
  6537. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6538. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6539. (org-cmp-ts a b "deadline")))
  6540. (deadline-down (if deadline-up (- deadline-up) nil))
  6541. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6542. (org-cmp-ts a b "iatimestamp_ia")))
  6543. (tsia-down (if tsia-up (- tsia-up) nil))
  6544. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6545. (org-cmp-ts a b "timestamp")))
  6546. (ts-down (if ts-up (- ts-up) nil))
  6547. (time-up (and (org-em 'time-up 'time-down ss)
  6548. (org-cmp-time a b)))
  6549. (time-down (if time-up (- time-up) nil))
  6550. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6551. (org-cmp-priority a b)))
  6552. (priority-down (if priority-up (- priority-up) nil))
  6553. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6554. (org-cmp-effort a b)))
  6555. (effort-down (if effort-up (- effort-up) nil))
  6556. (category-up (and (or (org-em 'category-up 'category-down ss)
  6557. (memq 'category-keep ss))
  6558. (org-cmp-category a b)))
  6559. (category-down (if category-up (- category-up) nil))
  6560. (category-keep (if category-up +1 nil))
  6561. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6562. (org-cmp-tag a b)))
  6563. (tag-down (if tag-up (- tag-up) nil))
  6564. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6565. (org-cmp-todo-state a b)))
  6566. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6567. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6568. (org-cmp-habit-p a b)))
  6569. (habit-down (if habit-up (- habit-up) nil))
  6570. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6571. (org-cmp-alpha a b)))
  6572. (alpha-down (if alpha-up (- alpha-up) nil))
  6573. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6574. user-defined-up user-defined-down)
  6575. (if (and need-user-cmp org-agenda-cmp-user-defined
  6576. (functionp org-agenda-cmp-user-defined))
  6577. (setq user-defined-up
  6578. (funcall org-agenda-cmp-user-defined a b)
  6579. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6580. (cdr (assoc
  6581. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6582. '((-1 . t) (1 . nil) (nil . nil))))))
  6583. ;;; Agenda restriction lock
  6584. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6585. "Overlay to mark the headline to which agenda commands are restricted.")
  6586. (overlay-put org-agenda-restriction-lock-overlay
  6587. 'face 'org-agenda-restriction-lock)
  6588. (overlay-put org-agenda-restriction-lock-overlay
  6589. 'help-echo "Agendas are currently limited to this subtree.")
  6590. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6591. (defun org-agenda-set-restriction-lock (&optional type)
  6592. "Set restriction lock for agenda, to current subtree or file.
  6593. Restriction will be the file if TYPE is `file', or if type is the
  6594. universal prefix '(4), or if the cursor is before the first headline
  6595. in the file. Otherwise, restriction will be to the current subtree."
  6596. (interactive "P")
  6597. (and (equal type '(4)) (setq type 'file))
  6598. (setq type (cond
  6599. (type type)
  6600. ((org-at-heading-p) 'subtree)
  6601. ((condition-case nil (org-back-to-heading t) (error nil))
  6602. 'subtree)
  6603. (t 'file)))
  6604. (if (eq type 'subtree)
  6605. (progn
  6606. (setq org-agenda-restrict (current-buffer))
  6607. (setq org-agenda-overriding-restriction 'subtree)
  6608. (put 'org-agenda-files 'org-restrict
  6609. (list (buffer-file-name (buffer-base-buffer))))
  6610. (org-back-to-heading t)
  6611. (move-overlay org-agenda-restriction-lock-overlay
  6612. (point)
  6613. (if org-agenda-restriction-lock-highlight-subtree
  6614. (save-excursion (org-end-of-subtree t t) (point))
  6615. (point-at-eol)))
  6616. (move-marker org-agenda-restrict-begin (point))
  6617. (move-marker org-agenda-restrict-end
  6618. (save-excursion (org-end-of-subtree t t)))
  6619. (message "Locking agenda restriction to subtree"))
  6620. (put 'org-agenda-files 'org-restrict
  6621. (list (buffer-file-name (buffer-base-buffer))))
  6622. (setq org-agenda-restrict nil)
  6623. (setq org-agenda-overriding-restriction 'file)
  6624. (move-marker org-agenda-restrict-begin nil)
  6625. (move-marker org-agenda-restrict-end nil)
  6626. (message "Locking agenda restriction to file"))
  6627. (setq current-prefix-arg nil)
  6628. (org-agenda-maybe-redo))
  6629. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6630. "Remove the agenda restriction lock."
  6631. (interactive "P")
  6632. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6633. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6634. (setq org-agenda-overriding-restriction nil)
  6635. (setq org-agenda-restrict nil)
  6636. (put 'org-agenda-files 'org-restrict nil)
  6637. (move-marker org-agenda-restrict-begin nil)
  6638. (move-marker org-agenda-restrict-end nil)
  6639. (setq current-prefix-arg nil)
  6640. (message "Agenda restriction lock removed")
  6641. (or noupdate (org-agenda-maybe-redo)))
  6642. (defun org-agenda-maybe-redo ()
  6643. "If there is any window showing the agenda view, update it."
  6644. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6645. (w0 (selected-window)))
  6646. (when w
  6647. (select-window w)
  6648. (org-agenda-redo)
  6649. (select-window w0)
  6650. (if org-agenda-overriding-restriction
  6651. (message "Agenda view shifted to new %s restriction"
  6652. org-agenda-overriding-restriction)
  6653. (message "Agenda restriction lock removed")))))
  6654. ;;; Agenda commands
  6655. (defun org-agenda-check-type (error &rest types)
  6656. "Check if agenda buffer is of allowed type.
  6657. If ERROR is non-nil, throw an error, otherwise just return nil.
  6658. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6659. (if (not org-agenda-type)
  6660. (error "No Org agenda currently displayed")
  6661. (if (memq org-agenda-type types)
  6662. t
  6663. (if error
  6664. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6665. nil))))
  6666. (defun org-agenda-Quit ()
  6667. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6668. Also restore the window configuration."
  6669. (interactive)
  6670. (if org-agenda-columns-active
  6671. (org-columns-quit)
  6672. (let ((buf (current-buffer)))
  6673. (if (eq org-agenda-window-setup 'other-frame)
  6674. (progn
  6675. (org-agenda-reset-markers)
  6676. (kill-buffer buf)
  6677. (org-columns-remove-overlays)
  6678. (setq org-agenda-archives-mode nil)
  6679. (delete-frame))
  6680. (and (not (eq org-agenda-window-setup 'current-window))
  6681. (not (one-window-p))
  6682. (delete-window))
  6683. (org-agenda-reset-markers)
  6684. (kill-buffer buf)
  6685. (org-columns-remove-overlays)
  6686. (setq org-agenda-archives-mode nil)))
  6687. (setq org-agenda-buffer nil)
  6688. ;; Maybe restore the pre-agenda window configuration.
  6689. (and org-agenda-restore-windows-after-quit
  6690. (not (eq org-agenda-window-setup 'other-frame))
  6691. org-agenda-pre-window-conf
  6692. (set-window-configuration org-agenda-pre-window-conf)
  6693. (setq org-agenda-pre-window-conf nil))))
  6694. (defun org-agenda-quit ()
  6695. "Exit the agenda and restore the window configuration.
  6696. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6697. (interactive)
  6698. (if (and (eq org-indirect-buffer-display 'other-window)
  6699. org-last-indirect-buffer)
  6700. (let ((org-last-indirect-window
  6701. (get-buffer-window org-last-indirect-buffer)))
  6702. (if org-last-indirect-window
  6703. (delete-window org-last-indirect-window))))
  6704. (if org-agenda-columns-active
  6705. (org-columns-quit)
  6706. (if org-agenda-sticky
  6707. (let ((buf (current-buffer)))
  6708. (if (eq org-agenda-window-setup 'other-frame)
  6709. (progn
  6710. (delete-frame))
  6711. (and (not (eq org-agenda-window-setup 'current-window))
  6712. (not (one-window-p))
  6713. (delete-window)))
  6714. (with-current-buffer buf
  6715. (bury-buffer)
  6716. ;; Maybe restore the pre-agenda window configuration.
  6717. (and org-agenda-restore-windows-after-quit
  6718. (not (eq org-agenda-window-setup 'other-frame))
  6719. org-agenda-pre-window-conf
  6720. (set-window-configuration org-agenda-pre-window-conf)
  6721. (setq org-agenda-pre-window-conf nil))))
  6722. (org-agenda-Quit))))
  6723. (defun org-agenda-exit ()
  6724. "Exit the agenda and restore the window configuration.
  6725. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6726. buffers visited directly by the user will not be touched."
  6727. (interactive)
  6728. (org-release-buffers org-agenda-new-buffers)
  6729. (setq org-agenda-new-buffers nil)
  6730. (org-agenda-Quit))
  6731. (defun org-agenda-kill-all-agenda-buffers ()
  6732. "Kill all buffers in `org-agenda-mode'.
  6733. This is used when toggling sticky agendas.
  6734. You can also explicitly invoke it with `C-c a C-k'."
  6735. (interactive)
  6736. (let (blist)
  6737. (dolist (buf (buffer-list))
  6738. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6739. (push buf blist)))
  6740. (mapc 'kill-buffer blist)))
  6741. (defun org-agenda-execute (arg)
  6742. "Execute another agenda command, keeping same window.
  6743. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6744. in the agenda."
  6745. (interactive "P")
  6746. (let ((org-agenda-window-setup 'current-window))
  6747. (org-agenda arg)))
  6748. (defun org-agenda-redo (&optional all)
  6749. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6750. (interactive "P")
  6751. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6752. (cpa (unless (eq all t) current-prefix-arg))
  6753. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6754. (org-agenda-sticky nil)
  6755. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6756. org-agenda-buffer-name))
  6757. (org-agenda-keep-modes t)
  6758. (tag-filter org-agenda-tag-filter)
  6759. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6760. (top-hl-filter org-agenda-top-headline-filter)
  6761. (cat-filter org-agenda-category-filter)
  6762. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6763. (re-filter org-agenda-regexp-filter)
  6764. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6765. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6766. (cols org-agenda-columns-active)
  6767. (line (org-current-line))
  6768. (window-line (- line (org-current-line (window-start))))
  6769. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6770. (redo-cmd (get-text-property p 'org-redo-cmd))
  6771. (last-args (get-text-property p 'org-last-args))
  6772. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6773. (org-agenda-overriding-cmd-arguments
  6774. (unless (eq all t)
  6775. (cond ((listp last-args)
  6776. (cons (or cpa (car last-args)) (cdr last-args)))
  6777. ((stringp last-args)
  6778. last-args))))
  6779. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6780. (put 'org-agenda-tag-filter :preset-filter nil)
  6781. (put 'org-agenda-category-filter :preset-filter nil)
  6782. (put 'org-agenda-regexp-filter :preset-filter nil)
  6783. (and cols (org-columns-quit))
  6784. (message "Rebuilding agenda buffer...")
  6785. (if series-redo-cmd
  6786. (eval series-redo-cmd)
  6787. (org-let lprops redo-cmd))
  6788. (setq org-agenda-undo-list nil
  6789. org-agenda-pending-undo-list nil
  6790. org-agenda-tag-filter tag-filter
  6791. org-agenda-category-filter cat-filter
  6792. org-agenda-regexp-filter re-filter
  6793. org-agenda-top-headline-filter top-hl-filter)
  6794. (message "Rebuilding agenda buffer...done")
  6795. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6796. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6797. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6798. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6799. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6800. (and (or re-filter re-preset) (org-agenda-filter-apply re-filter 'regexp))
  6801. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6802. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6803. (org-goto-line line)
  6804. (recenter window-line)))
  6805. (defvar org-global-tags-completion-table nil)
  6806. (defvar org-agenda-filter-form nil)
  6807. (defvar org-agenda-filtered-by-category nil)
  6808. (defun org-agenda-filter-by-category (strip)
  6809. "Keep only those lines in the agenda buffer that have a specific category.
  6810. The category is that of the current line."
  6811. (interactive "P")
  6812. (if (and org-agenda-filtered-by-category
  6813. org-agenda-category-filter)
  6814. (org-agenda-filter-show-all-cat)
  6815. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6816. (cond
  6817. ((and cat strip)
  6818. (org-agenda-filter-apply
  6819. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6820. ((and cat)
  6821. (org-agenda-filter-apply
  6822. (setq org-agenda-category-filter
  6823. (list (concat "+" cat))) 'category))
  6824. ((error "No category at point"))))))
  6825. (defun org-find-top-headline (&optional pos)
  6826. "Find the topmost parent headline and return it."
  6827. (save-excursion
  6828. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6829. (if pos (goto-char pos))
  6830. ;; Skip up to the topmost parent
  6831. (while (ignore-errors (outline-up-heading 1) t))
  6832. (ignore-errors
  6833. (nth 4 (org-heading-components))))))
  6834. (defvar org-agenda-filtered-by-top-headline nil)
  6835. (defun org-agenda-filter-by-top-headline (strip)
  6836. "Keep only those lines that are descendants from the same top headline.
  6837. The top headline is that of the current line."
  6838. (interactive "P")
  6839. (if org-agenda-filtered-by-top-headline
  6840. (progn
  6841. (setq org-agenda-filtered-by-top-headline nil
  6842. org-agenda-top-headline-filter nil)
  6843. (org-agenda-filter-show-all-cat))
  6844. (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6845. (if cat (org-agenda-filter-top-headline-apply cat strip)
  6846. (error "No top-level category at point")))))
  6847. (defvar org-agenda-regexp-filter nil)
  6848. (defun org-agenda-filter-by-regexp (strip)
  6849. "Filter agenda entries by a regular expression.
  6850. Regexp filters are cumulative.
  6851. With no prefix argument, keep entries matching the regexp.
  6852. With one prefix argument, filter out entries matching the regexp.
  6853. With two prefix arguments, remove the regexp filters."
  6854. (interactive "P")
  6855. (if (not (equal strip '(16)))
  6856. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6857. (read-from-minibuffer
  6858. (if (equal strip '(4))
  6859. "Filter out entries matching regexp: "
  6860. "Narrow to entries matching regexp: ")))))
  6861. (push flt org-agenda-regexp-filter)
  6862. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6863. (org-agenda-filter-show-all-re)
  6864. (message "Regexp filter removed")))
  6865. (defun org-agenda-filter-remove-all ()
  6866. "Remove all filters from the current agenda buffer."
  6867. (interactive)
  6868. (when org-agenda-tag-filter
  6869. (org-agenda-filter-show-all-tag))
  6870. (when org-agenda-category-filter
  6871. (org-agenda-filter-show-all-cat))
  6872. (when org-agenda-regexp-filter
  6873. (org-agenda-filter-show-all-re)))
  6874. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6875. "Keep only those lines in the agenda buffer that have a specific tag.
  6876. The tag is selected with its fast selection letter, as configured.
  6877. With prefix argument STRIP, remove all lines that do have the tag.
  6878. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6879. used to narrow the search - the interactive user can also press `-' or `+'
  6880. to switch to narrowing."
  6881. (interactive "P")
  6882. (let* ((alist org-tag-alist-for-agenda)
  6883. (tag-chars (mapconcat
  6884. (lambda (x) (if (and (not (symbolp (car x)))
  6885. (cdr x))
  6886. (char-to-string (cdr x))
  6887. ""))
  6888. alist ""))
  6889. (efforts (org-split-string
  6890. (or (cdr (assoc (concat org-effort-property "_ALL")
  6891. org-global-properties))
  6892. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6893. "")))
  6894. (effort-op org-agenda-filter-effort-default-operator)
  6895. (effort-prompt "")
  6896. (inhibit-read-only t)
  6897. (current org-agenda-tag-filter)
  6898. maybe-refresh a n tag)
  6899. (unless char
  6900. (message
  6901. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6902. (if narrow "Narrow" "Filter") tag-chars
  6903. (if org-agenda-auto-exclude-function "[RET], " ""))
  6904. (setq char (read-char-exclusive)))
  6905. (when (member char '(?+ ?-))
  6906. ;; Narrowing down
  6907. (cond ((equal char ?-) (setq strip t narrow t))
  6908. ((equal char ?+) (setq strip nil narrow t)))
  6909. (message
  6910. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6911. (setq char (read-char-exclusive)))
  6912. (when (member char '(?< ?> ?= ??))
  6913. ;; An effort operator
  6914. (setq effort-op (char-to-string char))
  6915. (setq alist nil) ; to make sure it will be interpreted as effort.
  6916. (unless (equal char ??)
  6917. (loop for i from 0 to 9 do
  6918. (setq effort-prompt
  6919. (concat
  6920. effort-prompt " ["
  6921. (if (= i 9) "0" (int-to-string (1+ i)))
  6922. "]" (nth i efforts))))
  6923. (message "Effort%s: %s " effort-op effort-prompt)
  6924. (setq char (read-char-exclusive))
  6925. (when (or (< char ?0) (> char ?9))
  6926. (error "Need 1-9,0 to select effort"))))
  6927. (when (equal char ?\t)
  6928. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6929. (org-set-local 'org-global-tags-completion-table
  6930. (org-global-tags-completion-table)))
  6931. (let ((completion-ignore-case t))
  6932. (setq tag (org-icompleting-read
  6933. "Tag: " org-global-tags-completion-table))))
  6934. (cond
  6935. ((equal char ?\r)
  6936. (org-agenda-filter-show-all-tag)
  6937. (when org-agenda-auto-exclude-function
  6938. (setq org-agenda-tag-filter nil)
  6939. (dolist (tag (org-agenda-get-represented-tags))
  6940. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6941. (if modifier
  6942. (push modifier org-agenda-tag-filter))))
  6943. (if (not (null org-agenda-tag-filter))
  6944. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6945. (setq maybe-refresh t))
  6946. ((equal char ?/)
  6947. (org-agenda-filter-show-all-tag)
  6948. (when (get 'org-agenda-tag-filter :preset-filter)
  6949. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6950. (setq maybe-refresh t))
  6951. ((equal char ?. )
  6952. (setq org-agenda-tag-filter
  6953. (mapcar (lambda(tag) (concat "+" tag))
  6954. (org-get-at-bol 'tags)))
  6955. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6956. (setq maybe-refresh t))
  6957. ((or (equal char ?\ )
  6958. (setq a (rassoc char alist))
  6959. (and (>= char ?0) (<= char ?9)
  6960. (setq n (if (= char ?0) 9 (- char ?0 1))
  6961. tag (concat effort-op (nth n efforts))
  6962. a (cons tag nil)))
  6963. (and (= char ??)
  6964. (setq tag "?eff")
  6965. a (cons tag nil))
  6966. (and tag (setq a (cons tag nil))))
  6967. (org-agenda-filter-show-all-tag)
  6968. (setq tag (car a))
  6969. (setq org-agenda-tag-filter
  6970. (cons (concat (if strip "-" "+") tag)
  6971. (if narrow current nil)))
  6972. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6973. (setq maybe-refresh t))
  6974. (t (error "Invalid tag selection character %c" char)))
  6975. (when (and maybe-refresh
  6976. (eq org-agenda-clockreport-mode 'with-filter))
  6977. (org-agenda-redo))))
  6978. (defun org-agenda-get-represented-tags ()
  6979. "Get a list of all tags currently represented in the agenda."
  6980. (let (p tags)
  6981. (save-excursion
  6982. (goto-char (point-min))
  6983. (while (setq p (next-single-property-change (point) 'tags))
  6984. (goto-char p)
  6985. (mapc (lambda (x) (add-to-list 'tags x))
  6986. (get-text-property (point) 'tags))))
  6987. tags))
  6988. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6989. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6990. (interactive "P")
  6991. (org-agenda-filter-by-tag strip char 'refine))
  6992. (defun org-agenda-filter-make-matcher (filter type)
  6993. "Create the form that tests a line for agenda filter."
  6994. (let (f f1)
  6995. (cond
  6996. ;; Tag filter
  6997. ((eq type 'tag)
  6998. (setq filter
  6999. (delete-dups
  7000. (append (get 'org-agenda-tag-filter :preset-filter)
  7001. filter)))
  7002. (dolist (x filter)
  7003. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  7004. (ffunc
  7005. (lambda (nf0 nf01 fltr notgroup op)
  7006. (dolist (x fltr)
  7007. (if (member x '("-" "+"))
  7008. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  7009. (if (string-match "[<=>?]" x)
  7010. (setq nf01 (org-agenda-filter-effort-form x))
  7011. (setq nf01 (list 'member (downcase (substring x 1))
  7012. 'tags)))
  7013. (when (equal (string-to-char x) ?-)
  7014. (setq nf01 (list 'not nf01))
  7015. (when (not notgroup) (setq op 'and))))
  7016. (push nf01 nf0))
  7017. (if notgroup
  7018. (push (cons 'and nf0) f)
  7019. (push (cons (or op 'or) nf0) f)))))
  7020. (if (equal nfilter filter)
  7021. (funcall ffunc f1 f filter t nil)
  7022. (funcall ffunc nf1 nf nfilter nil nil)))))
  7023. ;; Category filter
  7024. ((eq type 'category)
  7025. (setq filter
  7026. (delete-dups
  7027. (append (get 'org-agenda-category-filter :preset-filter)
  7028. filter)))
  7029. (dolist (x filter)
  7030. (if (equal "-" (substring x 0 1))
  7031. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7032. (setq f1 (list 'equal (substring x 1) 'cat)))
  7033. (push f1 f)))
  7034. ;; Regexp filter
  7035. ((eq type 'regexp)
  7036. (setq filter
  7037. (delete-dups
  7038. (append (get 'org-agenda-regexp-filter :preset-filter)
  7039. filter)))
  7040. (dolist (x filter)
  7041. (if (equal "-" (substring x 0 1))
  7042. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7043. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7044. (push f1 f))))
  7045. (cons 'and (nreverse f))))
  7046. (defun org-agenda-filter-effort-form (e)
  7047. "Return the form to compare the effort of the current line with what E says.
  7048. E looks like \"+<2:25\"."
  7049. (let (op)
  7050. (setq e (substring e 1))
  7051. (setq op (string-to-char e) e (substring e 1))
  7052. (setq op (cond ((equal op ?<) '<=)
  7053. ((equal op ?>) '>=)
  7054. ((equal op ??) op)
  7055. (t '=)))
  7056. (list 'org-agenda-compare-effort (list 'quote op)
  7057. (org-duration-string-to-minutes e))))
  7058. (defun org-agenda-compare-effort (op value)
  7059. "Compare the effort of the current line with VALUE, using OP.
  7060. If the line does not have an effort defined, return nil."
  7061. (let ((eff (org-get-at-bol 'effort-minutes)))
  7062. (if (equal op ??)
  7063. (not eff)
  7064. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7065. value))))
  7066. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7067. "Expand group tags in FILTER for the agenda.
  7068. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7069. (if org-group-tags
  7070. (let ((case-fold-search t) rtn)
  7071. (mapc
  7072. (lambda (f)
  7073. (let (f0 dir)
  7074. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7075. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7076. (setq dir (if no-operator "" "+") f0 f))
  7077. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7078. (org-tags-expand f0 t t))
  7079. rtn))))
  7080. filter)
  7081. (reverse rtn))
  7082. filter))
  7083. (defun org-agenda-filter-apply (filter type)
  7084. "Set FILTER as the new agenda filter and apply it."
  7085. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7086. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7087. (let (tags cat txt)
  7088. (setq org-agenda-filter-form
  7089. (org-agenda-filter-make-matcher filter type))
  7090. (if (and (eq type 'category)
  7091. (not (equal (substring (car filter) 0 1) "-")))
  7092. ;; Only set `org-agenda-filtered-by-category' to t
  7093. ;; when a unique category is used as the filter
  7094. (setq org-agenda-filtered-by-category t))
  7095. (org-agenda-set-mode-name)
  7096. (save-excursion
  7097. (goto-char (point-min))
  7098. (while (not (eobp))
  7099. (if (org-get-at-bol 'org-marker)
  7100. (progn
  7101. (setq tags ; used in eval
  7102. (apply 'append
  7103. (mapcar (lambda (f)
  7104. (org-agenda-filter-expand-tags (list f) t))
  7105. (org-get-at-bol 'tags)))
  7106. cat (get-text-property (point) 'org-category)
  7107. txt (get-text-property (point) 'txt))
  7108. (if (not (eval org-agenda-filter-form))
  7109. (org-agenda-filter-hide-line type))
  7110. (beginning-of-line 2))
  7111. (beginning-of-line 2))))
  7112. (if (get-char-property (point) 'invisible)
  7113. (ignore-errors (org-agenda-previous-line)))))
  7114. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7115. "Filter by top headline HL."
  7116. (org-agenda-set-mode-name)
  7117. (save-excursion
  7118. (goto-char (point-min))
  7119. (while (not (eobp))
  7120. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7121. (tophl (and pos (org-find-top-headline pos))))
  7122. (if (and tophl (funcall (if negative 'identity 'not)
  7123. (string= hl tophl)))
  7124. (org-agenda-filter-hide-line 'category)))
  7125. (beginning-of-line 2)))
  7126. (if (get-char-property (point) 'invisible)
  7127. (org-agenda-previous-line))
  7128. (setq org-agenda-top-headline-filter hl
  7129. org-agenda-filtered-by-top-headline t))
  7130. (defun org-agenda-filter-hide-line (type)
  7131. "Hide lines with TYPE in the agenda buffer."
  7132. (let (ov)
  7133. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  7134. (point-at-eol)))
  7135. (overlay-put ov 'invisible t)
  7136. (overlay-put ov 'type type)
  7137. (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays))
  7138. ((eq type 'category) (push ov org-agenda-cat-filter-overlays))
  7139. ((eq type 'regexp) (push ov org-agenda-re-filter-overlays)))))
  7140. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  7141. (setq pos (or pos (point)))
  7142. (save-excursion
  7143. (dolist (ov (overlays-at pos))
  7144. (when (and (overlay-get ov 'invisible)
  7145. (eq (overlay-get ov 'type) 'tag))
  7146. (goto-char pos)
  7147. (if (< (overlay-start ov) (point-at-eol))
  7148. (move-overlay ov (point-at-eol)
  7149. (overlay-end ov)))))))
  7150. (defun org-agenda-filter-show-all-tag nil
  7151. "Remove tag filter overlays from the agenda buffer."
  7152. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  7153. (setq org-agenda-tag-filter-overlays nil
  7154. org-agenda-tag-filter nil
  7155. org-agenda-filter-form nil)
  7156. (org-agenda-set-mode-name))
  7157. (defun org-agenda-filter-show-all-re nil
  7158. "Remove regexp filter overlays from the agenda buffer."
  7159. (mapc 'delete-overlay org-agenda-re-filter-overlays)
  7160. (setq org-agenda-re-filter-overlays nil
  7161. org-agenda-regexp-filter nil
  7162. org-agenda-filter-form nil)
  7163. (org-agenda-set-mode-name))
  7164. (defun org-agenda-filter-show-all-cat nil
  7165. "Remove category filter overlays from the agenda buffer."
  7166. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  7167. (setq org-agenda-cat-filter-overlays nil
  7168. org-agenda-filtered-by-category nil
  7169. org-agenda-category-filter nil
  7170. org-agenda-filter-form nil)
  7171. (org-agenda-set-mode-name))
  7172. (defun org-agenda-manipulate-query-add ()
  7173. "Manipulate the query by adding a search term with positive selection.
  7174. Positive selection means the term must be matched for selection of an entry."
  7175. (interactive)
  7176. (org-agenda-manipulate-query ?\[))
  7177. (defun org-agenda-manipulate-query-subtract ()
  7178. "Manipulate the query by adding a search term with negative selection.
  7179. Negative selection means term must not be matched for selection of an entry."
  7180. (interactive)
  7181. (org-agenda-manipulate-query ?\]))
  7182. (defun org-agenda-manipulate-query-add-re ()
  7183. "Manipulate the query by adding a search regexp with positive selection.
  7184. Positive selection means the regexp must match for selection of an entry."
  7185. (interactive)
  7186. (org-agenda-manipulate-query ?\{))
  7187. (defun org-agenda-manipulate-query-subtract-re ()
  7188. "Manipulate the query by adding a search regexp with negative selection.
  7189. Negative selection means regexp must not match for selection of an entry."
  7190. (interactive)
  7191. (org-agenda-manipulate-query ?\}))
  7192. (defun org-agenda-manipulate-query (char)
  7193. (cond
  7194. ((memq org-agenda-type '(timeline agenda))
  7195. (let ((org-agenda-include-inactive-timestamps t))
  7196. (org-agenda-redo))
  7197. (message "Display now includes inactive timestamps as well"))
  7198. ((eq org-agenda-type 'search)
  7199. (org-add-to-string
  7200. 'org-agenda-query-string
  7201. (if org-agenda-last-search-view-search-was-boolean
  7202. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7203. (?\{ . " +{}") (?\} . " -{}"))))
  7204. " "))
  7205. (setq org-agenda-redo-command
  7206. (list 'org-search-view
  7207. (car (get-text-property (min (1- (point-max)) (point))
  7208. 'org-last-args))
  7209. org-agenda-query-string
  7210. (+ (length org-agenda-query-string)
  7211. (if (member char '(?\{ ?\})) 0 1))))
  7212. (set-register org-agenda-query-register org-agenda-query-string)
  7213. (let ((org-agenda-overriding-arguments
  7214. (cdr org-agenda-redo-command)))
  7215. (org-agenda-redo)))
  7216. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7217. org-agenda-type))))
  7218. (defun org-add-to-string (var string)
  7219. (set var (concat (symbol-value var) string)))
  7220. (defun org-agenda-goto-date (span)
  7221. "Jump to DATE in agenda."
  7222. (interactive "P")
  7223. (let* ((org-read-date-prefer-future
  7224. (eval org-agenda-jump-prefer-future))
  7225. (date (org-read-date))
  7226. (day (time-to-days (org-time-string-to-time date)))
  7227. (org-agenda-sticky-orig org-agenda-sticky)
  7228. (org-agenda-buffer-tmp-name (buffer-name))
  7229. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7230. (0-arg (or current-prefix-arg (car args)))
  7231. (2-arg (nth 2 args))
  7232. (with-hour-p (nth 4 org-agenda-redo-command))
  7233. (newcmd (list 'org-agenda-list 0-arg date
  7234. (org-agenda-span-to-ndays
  7235. 2-arg (org-time-string-to-absolute date))
  7236. with-hour-p))
  7237. (newargs (cdr newcmd))
  7238. (inhibit-read-only t)
  7239. org-agenda-sticky)
  7240. (if (not (org-agenda-check-type t 'agenda))
  7241. (error "Not available in non-agenda views")
  7242. (add-text-properties (point-min) (point-max)
  7243. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7244. (org-agenda-redo)
  7245. (goto-char (point-min))
  7246. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7247. (save-excursion (move-beginning-of-line 2) (eobp))))
  7248. (move-beginning-of-line 2))
  7249. (setq org-agenda-sticky org-agenda-sticky-orig
  7250. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7251. (defun org-agenda-goto-today ()
  7252. "Go to today."
  7253. (interactive)
  7254. (org-agenda-check-type t 'timeline 'agenda)
  7255. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7256. (curspan (nth 2 args))
  7257. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7258. (cond
  7259. (tdpos (goto-char tdpos))
  7260. ((eq org-agenda-type 'agenda)
  7261. (let* ((sd (org-agenda-compute-starting-span
  7262. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7263. (org-agenda-overriding-arguments args))
  7264. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7265. (org-agenda-redo)
  7266. (org-agenda-find-same-or-today-or-agenda)))
  7267. (t (error "Cannot find today")))))
  7268. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7269. (goto-char
  7270. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7271. (text-property-any (point-min) (point-max) 'org-today t)
  7272. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7273. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7274. (org-agenda-goto-block-beginning))
  7275. (point-min))))
  7276. (defun org-agenda-goto-block-beginning ()
  7277. "Go the agenda block beginning."
  7278. (interactive)
  7279. (if (not (derived-mode-p 'org-agenda-mode))
  7280. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7281. (let (dest)
  7282. (save-excursion
  7283. (unless (looking-at "\\'")
  7284. (forward-char))
  7285. (let* ((prop 'org-agenda-structural-header)
  7286. (p (previous-single-property-change (point) prop))
  7287. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7288. (1- (point))) prop)))
  7289. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7290. (if (not dest)
  7291. (error "Cannot find the beginning of the blog")
  7292. (goto-char dest)
  7293. (move-beginning-of-line 1)))))
  7294. (defun org-agenda-later (arg)
  7295. "Go forward in time by the current span.
  7296. With prefix ARG, go forward that many times the current span."
  7297. (interactive "p")
  7298. (org-agenda-check-type t 'agenda)
  7299. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7300. (span (or (nth 2 args) org-agenda-current-span))
  7301. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7302. (greg (calendar-gregorian-from-absolute sd))
  7303. (cnt (org-get-at-bol 'org-day-cnt))
  7304. greg2)
  7305. (cond
  7306. ((numberp span)
  7307. (setq sd (+ (* span arg) sd)))
  7308. ((eq span 'day)
  7309. (setq sd (+ arg sd)))
  7310. ((eq span 'week)
  7311. (setq sd (+ (* 7 arg) sd)))
  7312. ((eq span 'fortnight)
  7313. (setq sd (+ (* 14 arg) sd)))
  7314. ((eq span 'month)
  7315. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7316. sd (calendar-absolute-from-gregorian greg2))
  7317. (setcar greg2 (1+ (car greg2))))
  7318. ((eq span 'year)
  7319. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7320. sd (calendar-absolute-from-gregorian greg2))
  7321. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7322. (t
  7323. (setq sd (+ (* span arg) sd))))
  7324. (let ((org-agenda-overriding-cmd
  7325. ;; `cmd' may have been set by `org-agenda-run-series' which
  7326. ;; uses `org-agenda-overriding-cmd' to decide whether
  7327. ;; overriding is allowed for `cmd'
  7328. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7329. (org-agenda-overriding-arguments
  7330. (list (car args) sd span)))
  7331. (org-agenda-redo)
  7332. (org-agenda-find-same-or-today-or-agenda cnt))))
  7333. (defun org-agenda-earlier (arg)
  7334. "Go backward in time by the current span.
  7335. With prefix ARG, go backward that many times the current span."
  7336. (interactive "p")
  7337. (org-agenda-later (- arg)))
  7338. (defun org-agenda-view-mode-dispatch ()
  7339. "Call one of the view mode commands."
  7340. (interactive)
  7341. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7342. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7343. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7344. (let ((a (read-char-exclusive)))
  7345. (case a
  7346. (?\ (call-interactively 'org-agenda-reset-view))
  7347. (?d (call-interactively 'org-agenda-day-view))
  7348. (?w (call-interactively 'org-agenda-week-view))
  7349. (?t (call-interactively 'org-agenda-fortnight-view))
  7350. (?m (call-interactively 'org-agenda-month-view))
  7351. (?y (call-interactively 'org-agenda-year-view))
  7352. (?l (call-interactively 'org-agenda-log-mode))
  7353. (?L (org-agenda-log-mode '(4)))
  7354. (?c (org-agenda-log-mode 'clockcheck))
  7355. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7356. (?a (call-interactively 'org-agenda-archives-mode))
  7357. (?A (org-agenda-archives-mode 'files))
  7358. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7359. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7360. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7361. (?D (call-interactively 'org-agenda-toggle-diary))
  7362. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7363. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7364. (org-agenda-check-type t 'timeline 'agenda)
  7365. (org-agenda-redo))
  7366. (message "Display now includes inactive timestamps as well"))
  7367. (?q (message "Abort"))
  7368. (otherwise (error "Invalid key" )))))
  7369. (defun org-agenda-reset-view ()
  7370. "Switch to default view for agenda."
  7371. (interactive)
  7372. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7373. (defun org-agenda-day-view (&optional day-of-month)
  7374. "Switch to daily view for agenda.
  7375. With argument DAY-OF-MONTH, switch to that day of the month."
  7376. (interactive "P")
  7377. (org-agenda-change-time-span 'day day-of-month))
  7378. (defun org-agenda-week-view (&optional iso-week)
  7379. "Switch to daily view for agenda.
  7380. With argument ISO-WEEK, switch to the corresponding ISO week.
  7381. If ISO-WEEK has more then 2 digits, only the last two encode the
  7382. week. Any digits before this encode a year. So 200712 means
  7383. week 12 of year 2007. Years in the range 1938-2037 can also be
  7384. written as 2-digit years."
  7385. (interactive "P")
  7386. (org-agenda-change-time-span 'week iso-week))
  7387. (defun org-agenda-fortnight-view (&optional iso-week)
  7388. "Switch to daily view for agenda.
  7389. With argument ISO-WEEK, switch to the corresponding ISO week.
  7390. If ISO-WEEK has more then 2 digits, only the last two encode the
  7391. week. Any digits before this encode a year. So 200712 means
  7392. week 12 of year 2007. Years in the range 1938-2037 can also be
  7393. written as 2-digit years."
  7394. (interactive "P")
  7395. (org-agenda-change-time-span 'fortnight iso-week))
  7396. (defun org-agenda-month-view (&optional month)
  7397. "Switch to monthly view for agenda.
  7398. With argument MONTH, switch to that month."
  7399. (interactive "P")
  7400. (org-agenda-change-time-span 'month month))
  7401. (defun org-agenda-year-view (&optional year)
  7402. "Switch to yearly view for agenda.
  7403. With argument YEAR, switch to that year.
  7404. If MONTH has more then 2 digits, only the last two encode the
  7405. month. Any digits before this encode a year. So 200712 means
  7406. December year 2007. Years in the range 1938-2037 can also be
  7407. written as 2-digit years."
  7408. (interactive "P")
  7409. (when year
  7410. (setq year (org-small-year-to-year year)))
  7411. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7412. (org-agenda-change-time-span 'year year)
  7413. (error "Abort")))
  7414. (defun org-agenda-change-time-span (span &optional n)
  7415. "Change the agenda view to SPAN.
  7416. SPAN may be `day', `week', `fortnight', `month', `year'."
  7417. (org-agenda-check-type t 'agenda)
  7418. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7419. (curspan (nth 2 args)))
  7420. (if (and (not n) (equal curspan span))
  7421. (error "Viewing span is already \"%s\"" span))
  7422. (let* ((sd (or (org-get-at-bol 'day)
  7423. (nth 1 args)
  7424. org-starting-day))
  7425. (sd (org-agenda-compute-starting-span sd span n))
  7426. (org-agenda-overriding-cmd
  7427. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7428. (org-agenda-overriding-arguments
  7429. (list (car args) sd span)))
  7430. (org-agenda-redo)
  7431. (org-agenda-find-same-or-today-or-agenda))
  7432. (org-agenda-set-mode-name)
  7433. (message "Switched to %s view" span)))
  7434. (defun org-agenda-compute-starting-span (sd span &optional n)
  7435. "Compute starting date for agenda.
  7436. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7437. is a cons cell with the starting date and the number of days,
  7438. so that the date SD will be in that range."
  7439. (let* ((greg (calendar-gregorian-from-absolute sd))
  7440. (dg (nth 1 greg))
  7441. (mg (car greg))
  7442. (yg (nth 2 greg)))
  7443. (cond
  7444. ((eq span 'day)
  7445. (when n
  7446. (setq sd (+ (calendar-absolute-from-gregorian
  7447. (list mg 1 yg))
  7448. n -1))))
  7449. ((or (eq span 'week) (eq span 'fortnight))
  7450. (let* ((nt (calendar-day-of-week
  7451. (calendar-gregorian-from-absolute sd)))
  7452. (d (if org-agenda-start-on-weekday
  7453. (- nt org-agenda-start-on-weekday)
  7454. 0))
  7455. y1)
  7456. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7457. (when n
  7458. (require 'cal-iso)
  7459. (when (> n 99)
  7460. (setq y1 (org-small-year-to-year (/ n 100))
  7461. n (mod n 100)))
  7462. (setq sd
  7463. (calendar-absolute-from-iso
  7464. (list n 1
  7465. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7466. ((eq span 'month)
  7467. (let (y1)
  7468. (when (and n (> n 99))
  7469. (setq y1 (org-small-year-to-year (/ n 100))
  7470. n (mod n 100)))
  7471. (setq sd (calendar-absolute-from-gregorian
  7472. (list (or n mg) 1 (or y1 yg))))))
  7473. ((eq span 'year)
  7474. (setq sd (calendar-absolute-from-gregorian
  7475. (list 1 1 (or n yg))))))
  7476. sd))
  7477. (defun org-agenda-next-date-line (&optional arg)
  7478. "Jump to the next line indicating a date in agenda buffer."
  7479. (interactive "p")
  7480. (org-agenda-check-type t 'agenda 'timeline)
  7481. (beginning-of-line 1)
  7482. ;; This does not work if user makes date format that starts with a blank
  7483. (if (looking-at "^\\S-") (forward-char 1))
  7484. (if (not (re-search-forward "^\\S-" nil t arg))
  7485. (progn
  7486. (backward-char 1)
  7487. (error "No next date after this line in this buffer")))
  7488. (goto-char (match-beginning 0)))
  7489. (defun org-agenda-previous-date-line (&optional arg)
  7490. "Jump to the previous line indicating a date in agenda buffer."
  7491. (interactive "p")
  7492. (org-agenda-check-type t 'agenda 'timeline)
  7493. (beginning-of-line 1)
  7494. (if (not (re-search-backward "^\\S-" nil t arg))
  7495. (error "No previous date before this line in this buffer")))
  7496. ;; Initialize the highlight
  7497. (defvar org-hl (make-overlay 1 1))
  7498. (overlay-put org-hl 'face 'highlight)
  7499. (defun org-highlight (begin end &optional buffer)
  7500. "Highlight a region with overlay."
  7501. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7502. (defun org-unhighlight ()
  7503. "Detach overlay INDEX."
  7504. (org-detach-overlay org-hl))
  7505. (defun org-unhighlight-once ()
  7506. "Remove the highlight from its position, and this function from the hook."
  7507. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7508. (org-unhighlight))
  7509. (defvar org-agenda-pre-follow-window-conf nil)
  7510. (defun org-agenda-follow-mode ()
  7511. "Toggle follow mode in an agenda buffer."
  7512. (interactive)
  7513. (unless org-agenda-follow-mode
  7514. (setq org-agenda-pre-follow-window-conf
  7515. (current-window-configuration)))
  7516. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7517. (unless org-agenda-follow-mode
  7518. (set-window-configuration org-agenda-pre-follow-window-conf))
  7519. (org-agenda-set-mode-name)
  7520. (org-agenda-do-context-action)
  7521. (message "Follow mode is %s"
  7522. (if org-agenda-follow-mode "on" "off")))
  7523. (defun org-agenda-entry-text-mode (&optional arg)
  7524. "Toggle entry text mode in an agenda buffer."
  7525. (interactive "P")
  7526. (if (or org-agenda-tag-filter
  7527. org-agenda-category-filter
  7528. org-agenda-regexp-filter
  7529. org-agenda-top-headline-filter)
  7530. (user-error "Can't show entry text in filtered views")
  7531. (setq org-agenda-entry-text-mode (or (integerp arg)
  7532. (not org-agenda-entry-text-mode)))
  7533. (org-agenda-entry-text-hide)
  7534. (and org-agenda-entry-text-mode
  7535. (let ((org-agenda-entry-text-maxlines
  7536. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7537. (org-agenda-entry-text-show)))
  7538. (org-agenda-set-mode-name)
  7539. (message "Entry text mode is %s%s"
  7540. (if org-agenda-entry-text-mode "on" "off")
  7541. (if (not org-agenda-entry-text-mode) ""
  7542. (format " (maximum number of lines is %d)"
  7543. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7544. (defun org-agenda-clockreport-mode (&optional with-filter)
  7545. "Toggle clocktable mode in an agenda buffer.
  7546. With prefix arg WITH-FILTER, make the clocktable respect the current
  7547. agenda filter."
  7548. (interactive "P")
  7549. (org-agenda-check-type t 'agenda)
  7550. (if with-filter
  7551. (setq org-agenda-clockreport-mode 'with-filter)
  7552. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7553. (org-agenda-set-mode-name)
  7554. (org-agenda-redo)
  7555. (message "Clocktable mode is %s"
  7556. (if org-agenda-clockreport-mode "on" "off")))
  7557. (defun org-agenda-log-mode (&optional special)
  7558. "Toggle log mode in an agenda buffer.
  7559. With argument SPECIAL, show all possible log items, not only the ones
  7560. configured in `org-agenda-log-mode-items'.
  7561. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7562. (interactive "P")
  7563. (org-agenda-check-type t 'agenda 'timeline)
  7564. (setq org-agenda-show-log
  7565. (cond
  7566. ((equal special '(16)) 'only)
  7567. ((eq special 'clockcheck)
  7568. (if (eq org-agenda-show-log 'clockcheck)
  7569. nil 'clockcheck))
  7570. (special '(closed clock state))
  7571. (t (not org-agenda-show-log))))
  7572. (org-agenda-set-mode-name)
  7573. (org-agenda-redo)
  7574. (message "Log mode is %s"
  7575. (if org-agenda-show-log "on" "off")))
  7576. (defun org-agenda-archives-mode (&optional with-files)
  7577. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7578. When called with a prefix argument, include all archive files as well."
  7579. (interactive "P")
  7580. (setq org-agenda-archives-mode
  7581. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7582. (org-agenda-set-mode-name)
  7583. (org-agenda-redo)
  7584. (message
  7585. "%s"
  7586. (cond
  7587. ((eq org-agenda-archives-mode nil)
  7588. "No archives are included")
  7589. ((eq org-agenda-archives-mode 'trees)
  7590. (format "Trees with :%s: tag are included" org-archive-tag))
  7591. ((eq org-agenda-archives-mode t)
  7592. (format "Trees with :%s: tag and all active archive files are included"
  7593. org-archive-tag)))))
  7594. (defun org-agenda-toggle-diary ()
  7595. "Toggle diary inclusion in an agenda buffer."
  7596. (interactive)
  7597. (org-agenda-check-type t 'agenda)
  7598. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7599. (org-agenda-redo)
  7600. (org-agenda-set-mode-name)
  7601. (message "Diary inclusion turned %s"
  7602. (if org-agenda-include-diary "on" "off")))
  7603. (defun org-agenda-toggle-deadlines ()
  7604. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7605. (interactive)
  7606. (org-agenda-check-type t 'agenda)
  7607. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7608. (org-agenda-redo)
  7609. (org-agenda-set-mode-name)
  7610. (message "Deadlines inclusion turned %s"
  7611. (if org-agenda-include-deadlines "on" "off")))
  7612. (defun org-agenda-toggle-time-grid ()
  7613. "Toggle time grid in an agenda buffer."
  7614. (interactive)
  7615. (org-agenda-check-type t 'agenda)
  7616. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7617. (org-agenda-redo)
  7618. (org-agenda-set-mode-name)
  7619. (message "Time-grid turned %s"
  7620. (if org-agenda-use-time-grid "on" "off")))
  7621. (defun org-agenda-set-mode-name ()
  7622. "Set the mode name to indicate all the small mode settings."
  7623. (setq mode-name
  7624. (list "Org-Agenda"
  7625. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7626. " "
  7627. '(:eval (org-agenda-span-name org-agenda-current-span))
  7628. (if org-agenda-follow-mode " Follow" "")
  7629. (if org-agenda-entry-text-mode " ETxt" "")
  7630. (if org-agenda-include-diary " Diary" "")
  7631. (if org-agenda-include-deadlines " Ddl" "")
  7632. (if org-agenda-use-time-grid " Grid" "")
  7633. (if (and (boundp 'org-habit-show-habits)
  7634. org-habit-show-habits) " Habit" "")
  7635. (cond
  7636. ((consp org-agenda-show-log) " LogAll")
  7637. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7638. (org-agenda-show-log " Log")
  7639. (t ""))
  7640. (if (or org-agenda-category-filter
  7641. (get 'org-agenda-category-filter :preset-filter))
  7642. '(:eval (org-propertize
  7643. (concat " <"
  7644. (mapconcat
  7645. 'identity
  7646. (append
  7647. (get 'org-agenda-category-filter :preset-filter)
  7648. org-agenda-category-filter)
  7649. "")
  7650. ">")
  7651. 'face 'org-agenda-filter-category
  7652. 'help-echo "Category used in filtering")) "")
  7653. (if (or org-agenda-tag-filter
  7654. (get 'org-agenda-tag-filter :preset-filter))
  7655. '(:eval (org-propertize
  7656. (concat " {"
  7657. (mapconcat
  7658. 'identity
  7659. (append
  7660. (get 'org-agenda-tag-filter :preset-filter)
  7661. org-agenda-tag-filter)
  7662. "")
  7663. "}")
  7664. 'face 'org-agenda-filter-tags
  7665. 'help-echo "Tags used in filtering")) "")
  7666. (if (or org-agenda-regexp-filter
  7667. (get 'org-agenda-regexp-filter :preset-filter))
  7668. '(:eval (org-propertize
  7669. (concat " ["
  7670. (mapconcat
  7671. 'identity
  7672. (append
  7673. (get 'org-agenda-regexp-filter :preset-filter)
  7674. org-agenda-regexp-filter)
  7675. "")
  7676. "]")
  7677. 'face 'org-agenda-filter-regexp
  7678. 'help-echo "Regexp used in filtering")) "")
  7679. (if org-agenda-archives-mode
  7680. (if (eq org-agenda-archives-mode t)
  7681. " Archives"
  7682. (format " :%s:" org-archive-tag))
  7683. "")
  7684. (if org-agenda-clockreport-mode
  7685. (if (eq org-agenda-clockreport-mode 'with-filter)
  7686. " Clock{}" " Clock")
  7687. "")))
  7688. (force-mode-line-update))
  7689. (define-obsolete-function-alias
  7690. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7691. (defun org-agenda-update-agenda-type ()
  7692. "Update the agenda type after each command."
  7693. (setq org-agenda-type
  7694. (or (get-text-property (point) 'org-agenda-type)
  7695. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7696. (defun org-agenda-next-line ()
  7697. "Move cursor to the next line, and show if follow mode is active."
  7698. (interactive)
  7699. (call-interactively 'next-line)
  7700. (org-agenda-do-context-action))
  7701. (defun org-agenda-previous-line ()
  7702. "Move cursor to the previous line, and show if follow-mode is active."
  7703. (interactive)
  7704. (call-interactively 'previous-line)
  7705. (org-agenda-do-context-action))
  7706. (defun org-agenda-next-item (n)
  7707. "Move cursor to next agenda item."
  7708. (interactive "p")
  7709. (let ((col (current-column)))
  7710. (dotimes (c n)
  7711. (when (next-single-property-change (point-at-eol) 'org-marker)
  7712. (move-end-of-line 1)
  7713. (goto-char (next-single-property-change (point) 'org-marker))))
  7714. (org-move-to-column col))
  7715. (org-agenda-do-context-action))
  7716. (defun org-agenda-previous-item (n)
  7717. "Move cursor to next agenda item."
  7718. (interactive "p")
  7719. (dotimes (c n)
  7720. (let ((col (current-column))
  7721. (goto (save-excursion
  7722. (move-end-of-line 0)
  7723. (previous-single-property-change (point) 'org-marker))))
  7724. (if goto (goto-char goto))
  7725. (org-move-to-column col)))
  7726. (org-agenda-do-context-action))
  7727. (defun org-agenda-do-context-action ()
  7728. "Show outline path and, maybe, follow mode window."
  7729. (let ((m (org-get-at-bol 'org-marker)))
  7730. (when (and (markerp m) (marker-buffer m))
  7731. (and org-agenda-follow-mode
  7732. (if org-agenda-follow-indirect
  7733. (org-agenda-tree-to-indirect-buffer nil)
  7734. (org-agenda-show)))
  7735. (and org-agenda-show-outline-path
  7736. (org-with-point-at m (org-display-outline-path t))))))
  7737. (defun org-agenda-show-tags ()
  7738. "Show the tags applicable to the current item."
  7739. (interactive)
  7740. (let* ((tags (org-get-at-bol 'tags)))
  7741. (if tags
  7742. (message "Tags are :%s:"
  7743. (org-no-properties (mapconcat 'identity tags ":")))
  7744. (message "No tags associated with this line"))))
  7745. (defun org-agenda-goto (&optional highlight)
  7746. "Go to the Org-mode file which contains the item at point."
  7747. (interactive)
  7748. (let* ((marker (or (org-get-at-bol 'org-marker)
  7749. (org-agenda-error)))
  7750. (buffer (marker-buffer marker))
  7751. (pos (marker-position marker)))
  7752. (switch-to-buffer-other-window buffer)
  7753. (widen)
  7754. (push-mark)
  7755. (goto-char pos)
  7756. (when (derived-mode-p 'org-mode)
  7757. (org-show-context 'agenda)
  7758. (save-excursion
  7759. (and (outline-next-heading)
  7760. (org-flag-heading nil)))) ; show the next heading
  7761. (when (outline-invisible-p)
  7762. (show-entry)) ; display invisible text
  7763. (recenter (/ (window-height) 2))
  7764. (run-hooks 'org-agenda-after-show-hook)
  7765. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7766. (defvar org-agenda-after-show-hook nil
  7767. "Normal hook run after an item has been shown from the agenda.
  7768. Point is in the buffer where the item originated.")
  7769. (defun org-agenda-kill ()
  7770. "Kill the entry or subtree belonging to the current agenda entry."
  7771. (interactive)
  7772. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7773. (let* ((bufname-orig (buffer-name))
  7774. (marker (or (org-get-at-bol 'org-marker)
  7775. (org-agenda-error)))
  7776. (buffer (marker-buffer marker))
  7777. (pos (marker-position marker))
  7778. (type (org-get-at-bol 'type))
  7779. dbeg dend (n 0) conf)
  7780. (org-with-remote-undo buffer
  7781. (with-current-buffer buffer
  7782. (save-excursion
  7783. (goto-char pos)
  7784. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7785. (setq dbeg (progn (org-back-to-heading t) (point))
  7786. dend (org-end-of-subtree t t))
  7787. (setq dbeg (point-at-bol)
  7788. dend (min (point-max) (1+ (point-at-eol)))))
  7789. (goto-char dbeg)
  7790. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7791. (setq conf (or (eq t org-agenda-confirm-kill)
  7792. (and (numberp org-agenda-confirm-kill)
  7793. (> n org-agenda-confirm-kill))))
  7794. (and conf
  7795. (not (y-or-n-p
  7796. (format "Delete entry with %d lines in buffer \"%s\"? "
  7797. n (buffer-name buffer))))
  7798. (error "Abort"))
  7799. (let ((org-agenda-buffer-name bufname-orig))
  7800. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7801. (with-current-buffer buffer (delete-region dbeg dend))
  7802. (message "Agenda item and source killed"))))
  7803. (defvar org-archive-default-command) ; defined in org-archive.el
  7804. (defun org-agenda-archive-default ()
  7805. "Archive the entry or subtree belonging to the current agenda entry."
  7806. (interactive)
  7807. (require 'org-archive)
  7808. (org-agenda-archive-with org-archive-default-command))
  7809. (defun org-agenda-archive-default-with-confirmation ()
  7810. "Archive the entry or subtree belonging to the current agenda entry."
  7811. (interactive)
  7812. (require 'org-archive)
  7813. (org-agenda-archive-with org-archive-default-command 'confirm))
  7814. (defun org-agenda-archive ()
  7815. "Archive the entry or subtree belonging to the current agenda entry."
  7816. (interactive)
  7817. (org-agenda-archive-with 'org-archive-subtree))
  7818. (defun org-agenda-archive-to-archive-sibling ()
  7819. "Move the entry to the archive sibling."
  7820. (interactive)
  7821. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7822. (defun org-agenda-archive-with (cmd &optional confirm)
  7823. "Move the entry to the archive sibling."
  7824. (interactive)
  7825. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7826. (let* ((bufname-orig (buffer-name))
  7827. (marker (or (org-get-at-bol 'org-marker)
  7828. (org-agenda-error)))
  7829. (buffer (marker-buffer marker))
  7830. (pos (marker-position marker)))
  7831. (org-with-remote-undo buffer
  7832. (with-current-buffer buffer
  7833. (if (derived-mode-p 'org-mode)
  7834. (if (and confirm
  7835. (not (y-or-n-p "Archive this subtree or entry? ")))
  7836. (error "Abort")
  7837. (save-window-excursion
  7838. (goto-char pos)
  7839. (let ((org-agenda-buffer-name bufname-orig))
  7840. (org-remove-subtree-entries-from-agenda))
  7841. (org-back-to-heading t)
  7842. (funcall cmd)))
  7843. (error "Archiving works only in Org-mode files"))))))
  7844. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7845. "Remove all lines in the agenda that correspond to a given subtree.
  7846. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7847. If this information is not given, the function uses the tree at point."
  7848. (let ((buf (or buf (current-buffer))) m p)
  7849. (save-excursion
  7850. (unless (and beg end)
  7851. (org-back-to-heading t)
  7852. (setq beg (point))
  7853. (org-end-of-subtree t)
  7854. (setq end (point)))
  7855. (set-buffer (get-buffer org-agenda-buffer-name))
  7856. (save-excursion
  7857. (goto-char (point-max))
  7858. (beginning-of-line 1)
  7859. (while (not (bobp))
  7860. (when (and (setq m (org-get-at-bol 'org-marker))
  7861. (equal buf (marker-buffer m))
  7862. (setq p (marker-position m))
  7863. (>= p beg)
  7864. (< p end))
  7865. (let ((inhibit-read-only t))
  7866. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7867. (beginning-of-line 0))))))
  7868. (defun org-agenda-refile (&optional goto rfloc no-update)
  7869. "Refile the item at point.
  7870. When GOTO is 0 or '(64), clear the refile cache.
  7871. When GOTO is '(16), go to the location of the last refiled item.
  7872. RFLOC can be a refile location obtained in a different way.
  7873. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7874. (interactive "P")
  7875. (cond
  7876. ((member goto '(0 (64)))
  7877. (org-refile-cache-clear))
  7878. ((equal goto '(16))
  7879. (org-refile-goto-last-stored))
  7880. (t
  7881. (let* ((buffer-orig (buffer-name))
  7882. (marker (or (org-get-at-bol 'org-hd-marker)
  7883. (org-agenda-error)))
  7884. (buffer (marker-buffer marker))
  7885. (pos (marker-position marker))
  7886. (rfloc (or rfloc
  7887. (org-refile-get-location
  7888. (if goto "Goto" "Refile to") buffer
  7889. org-refile-allow-creating-parent-nodes))))
  7890. (with-current-buffer buffer
  7891. (save-excursion
  7892. (save-restriction
  7893. (widen)
  7894. (goto-char marker)
  7895. (let ((org-agenda-buffer-name buffer-orig))
  7896. (org-remove-subtree-entries-from-agenda))
  7897. (org-refile goto buffer rfloc)))))
  7898. (unless no-update (org-agenda-redo)))))
  7899. (defun org-agenda-open-link (&optional arg)
  7900. "Open the link(s) in the current entry, if any.
  7901. This looks for a link in the displayed line in the agenda.
  7902. It also looks at the text of the entry itself."
  7903. (interactive "P")
  7904. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7905. (org-get-at-bol 'org-marker)))
  7906. (buffer (and marker (marker-buffer marker)))
  7907. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7908. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7909. (lk0 (car lkall))
  7910. (lk (if (stringp lk0) (list lk0) lk0))
  7911. (lkend (cdr lkall))
  7912. trg)
  7913. (cond
  7914. ((and buffer lk)
  7915. (mapcar (lambda(l)
  7916. (with-current-buffer buffer
  7917. (setq trg (and (string-match org-bracket-link-regexp l)
  7918. (match-string 1 l)))
  7919. (if (or (not trg) (string-match org-any-link-re trg))
  7920. (save-excursion
  7921. (save-restriction
  7922. (widen)
  7923. (goto-char marker)
  7924. (when (search-forward l nil lkend)
  7925. (goto-char (match-beginning 0))
  7926. (org-open-at-point))))
  7927. ;; This is an internal link, widen the buffer
  7928. (switch-to-buffer-other-window buffer)
  7929. (widen)
  7930. (goto-char marker)
  7931. (when (search-forward l nil lkend)
  7932. (goto-char (match-beginning 0))
  7933. (org-open-at-point)))))
  7934. lk))
  7935. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7936. (save-excursion
  7937. (beginning-of-line 1)
  7938. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7939. (org-open-link-from-string (match-string 1)))
  7940. (t (message "No link to open here")))))
  7941. (defun org-agenda-copy-local-variable (var)
  7942. "Get a variable from a referenced buffer and install it here."
  7943. (let ((m (org-get-at-bol 'org-marker)))
  7944. (when (and m (buffer-live-p (marker-buffer m)))
  7945. (org-set-local var (with-current-buffer (marker-buffer m)
  7946. (symbol-value var))))))
  7947. (defun org-agenda-switch-to (&optional delete-other-windows)
  7948. "Go to the Org-mode file which contains the item at point."
  7949. (interactive)
  7950. (if (and org-return-follows-link
  7951. (not (org-get-at-bol 'org-marker))
  7952. (org-in-regexp org-bracket-link-regexp))
  7953. (org-open-link-from-string (match-string 0))
  7954. (let* ((marker (or (org-get-at-bol 'org-marker)
  7955. (org-agenda-error)))
  7956. (buffer (marker-buffer marker))
  7957. (pos (marker-position marker)))
  7958. (org-pop-to-buffer-same-window buffer)
  7959. (and delete-other-windows (delete-other-windows))
  7960. (widen)
  7961. (goto-char pos)
  7962. (when (derived-mode-p 'org-mode)
  7963. (org-show-context 'agenda)
  7964. (save-excursion
  7965. (and (outline-next-heading)
  7966. (org-flag-heading nil))) ; show the next heading
  7967. (when (outline-invisible-p)
  7968. (show-entry)) ; display invisible text
  7969. (run-hooks 'org-agenda-after-show-hook)))))
  7970. (defun org-agenda-goto-mouse (ev)
  7971. "Go to the Org-mode file which contains the item at the mouse click."
  7972. (interactive "e")
  7973. (mouse-set-point ev)
  7974. (org-agenda-goto))
  7975. (defun org-agenda-show (&optional full-entry)
  7976. "Display the Org-mode file which contains the item at point.
  7977. With prefix argument FULL-ENTRY, make the entire entry visible
  7978. if it was hidden in the outline."
  7979. (interactive "P")
  7980. (let ((win (selected-window)))
  7981. (if full-entry
  7982. (let ((org-show-entry-below t))
  7983. (org-agenda-goto t))
  7984. (org-agenda-goto t))
  7985. (select-window win)))
  7986. (defvar org-agenda-show-window nil)
  7987. (defun org-agenda-show-and-scroll-up (&optional arg)
  7988. "Display the Org-mode file which contains the item at point.
  7989. When called repeatedly, scroll the window that is displaying the buffer.
  7990. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7991. `show-subtree' to display the item, so that drawers and logbooks stay
  7992. folded."
  7993. (interactive "P")
  7994. (let ((win (selected-window)))
  7995. (if (and (window-live-p org-agenda-show-window)
  7996. (eq this-command last-command))
  7997. (progn
  7998. (select-window org-agenda-show-window)
  7999. (ignore-errors (scroll-up)))
  8000. (org-agenda-goto t)
  8001. (if arg (org-show-entry) (show-subtree))
  8002. (setq org-agenda-show-window (selected-window)))
  8003. (select-window win)))
  8004. (defun org-agenda-show-scroll-down ()
  8005. "Scroll down the window showing the agenda."
  8006. (interactive)
  8007. (let ((win (selected-window)))
  8008. (when (window-live-p org-agenda-show-window)
  8009. (select-window org-agenda-show-window)
  8010. (ignore-errors (scroll-down))
  8011. (select-window win))))
  8012. (defun org-agenda-show-1 (&optional more)
  8013. "Display the Org-mode file which contains the item at point.
  8014. The prefix arg selects the amount of information to display:
  8015. 0 hide the subtree
  8016. 1 just show the entry according to defaults.
  8017. 2 show the children view
  8018. 3 show the subtree view
  8019. 4 show the entire subtree and any LOGBOOK drawers
  8020. 5 show the entire subtree and any drawers
  8021. With prefix argument FULL-ENTRY, make the entire entry visible
  8022. if it was hidden in the outline."
  8023. (interactive "p")
  8024. (let ((win (selected-window)))
  8025. (org-agenda-goto t)
  8026. (org-recenter-heading 1)
  8027. (cond
  8028. ((= more 0)
  8029. (hide-subtree)
  8030. (save-excursion
  8031. (org-back-to-heading)
  8032. (run-hook-with-args 'org-cycle-hook 'folded))
  8033. (message "Remote: FOLDED"))
  8034. ((and (org-called-interactively-p 'any) (= more 1))
  8035. (message "Remote: show with default settings"))
  8036. ((= more 2)
  8037. (show-entry)
  8038. (show-children)
  8039. (save-excursion
  8040. (org-back-to-heading)
  8041. (run-hook-with-args 'org-cycle-hook 'children))
  8042. (message "Remote: CHILDREN"))
  8043. ((= more 3)
  8044. (show-subtree)
  8045. (save-excursion
  8046. (org-back-to-heading)
  8047. (run-hook-with-args 'org-cycle-hook 'subtree))
  8048. (message "Remote: SUBTREE"))
  8049. ((= more 4)
  8050. (show-subtree)
  8051. (save-excursion
  8052. (org-back-to-heading)
  8053. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8054. (message "Remote: SUBTREE AND LOGBOOK"))
  8055. ((> more 4)
  8056. (show-subtree)
  8057. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8058. (select-window win)))
  8059. (defun org-recenter-heading (n)
  8060. (save-excursion
  8061. (org-back-to-heading)
  8062. (recenter n)))
  8063. (defvar org-agenda-cycle-counter nil)
  8064. (defun org-agenda-cycle-show (&optional n)
  8065. "Show the current entry in another window, with default settings.
  8066. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8067. When use repeatedly in immediate succession, the remote entry will cycle
  8068. through visibility
  8069. children -> subtree -> folded
  8070. When called with a numeric prefix arg, that arg will be passed through to
  8071. `org-agenda-show-1'. For the interpretation of that argument, see the
  8072. docstring of `org-agenda-show-1'."
  8073. (interactive "P")
  8074. (if (integerp n)
  8075. (setq org-agenda-cycle-counter n)
  8076. (if (not (eq last-command this-command))
  8077. (setq org-agenda-cycle-counter 1)
  8078. (if (equal org-agenda-cycle-counter 0)
  8079. (setq org-agenda-cycle-counter 2)
  8080. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8081. (if (> org-agenda-cycle-counter 3)
  8082. (setq org-agenda-cycle-counter 0)))))
  8083. (org-agenda-show-1 org-agenda-cycle-counter))
  8084. (defun org-agenda-recenter (arg)
  8085. "Display the Org-mode file which contains the item at point and recenter."
  8086. (interactive "P")
  8087. (let ((win (selected-window)))
  8088. (org-agenda-goto t)
  8089. (recenter arg)
  8090. (select-window win)))
  8091. (defun org-agenda-show-mouse (ev)
  8092. "Display the Org-mode file which contains the item at the mouse click."
  8093. (interactive "e")
  8094. (mouse-set-point ev)
  8095. (org-agenda-show))
  8096. (defun org-agenda-check-no-diary ()
  8097. "Check if the entry is a diary link and abort if yes."
  8098. (if (org-get-at-bol 'org-agenda-diary-link)
  8099. (org-agenda-error)))
  8100. (defun org-agenda-error ()
  8101. (error "Command not allowed in this line"))
  8102. (defun org-agenda-tree-to-indirect-buffer (arg)
  8103. "Show the subtree corresponding to the current entry in an indirect buffer.
  8104. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8105. With a numerical prefix ARG, go up to this level and then take that tree.
  8106. With a negative numeric ARG, go up by this number of levels.
  8107. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8108. use the dedicated frame)."
  8109. (interactive "P")
  8110. (if current-prefix-arg
  8111. (org-agenda-do-tree-to-indirect-buffer arg)
  8112. (let ((agenda-buffer (buffer-name))
  8113. (agenda-window (selected-window))
  8114. (indirect-window
  8115. (and org-last-indirect-buffer
  8116. (get-buffer-window org-last-indirect-buffer))))
  8117. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8118. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8119. (eq org-indirect-buffer-display 'dedicated-frame))
  8120. (unwind-protect
  8121. (unless (and indirect-window (window-live-p indirect-window))
  8122. (setq indirect-window (split-window agenda-window)))
  8123. (and indirect-window (select-window indirect-window))
  8124. (switch-to-buffer org-last-indirect-buffer :norecord)
  8125. (fit-window-to-buffer indirect-window)))
  8126. (select-window (get-buffer-window agenda-buffer)))))
  8127. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8128. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8129. (org-agenda-check-no-diary)
  8130. (let* ((marker (or (org-get-at-bol 'org-marker)
  8131. (org-agenda-error)))
  8132. (buffer (marker-buffer marker))
  8133. (pos (marker-position marker)))
  8134. (with-current-buffer buffer
  8135. (save-excursion
  8136. (goto-char pos)
  8137. (funcall 'org-tree-to-indirect-buffer arg)))))
  8138. (defvar org-last-heading-marker (make-marker)
  8139. "Marker pointing to the headline that last changed its TODO state
  8140. by a remote command from the agenda.")
  8141. (defun org-agenda-todo-nextset ()
  8142. "Switch TODO entry to next sequence."
  8143. (interactive)
  8144. (org-agenda-todo 'nextset))
  8145. (defun org-agenda-todo-previousset ()
  8146. "Switch TODO entry to previous sequence."
  8147. (interactive)
  8148. (org-agenda-todo 'previousset))
  8149. (defun org-agenda-todo (&optional arg)
  8150. "Cycle TODO state of line at point, also in Org-mode file.
  8151. This changes the line at point, all other lines in the agenda referring to
  8152. the same tree node, and the headline of the tree node in the Org-mode file."
  8153. (interactive "P")
  8154. (org-agenda-check-no-diary)
  8155. (let* ((col (current-column))
  8156. (marker (or (org-get-at-bol 'org-marker)
  8157. (org-agenda-error)))
  8158. (buffer (marker-buffer marker))
  8159. (pos (marker-position marker))
  8160. (hdmarker (org-get-at-bol 'org-hd-marker))
  8161. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8162. (inhibit-read-only t)
  8163. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8164. (org-with-remote-undo buffer
  8165. (with-current-buffer buffer
  8166. (widen)
  8167. (goto-char pos)
  8168. (org-show-context 'agenda)
  8169. (save-excursion
  8170. (and (outline-next-heading)
  8171. (org-flag-heading nil))) ; show the next heading
  8172. (let ((current-prefix-arg arg))
  8173. (call-interactively 'org-todo))
  8174. (and (bolp) (forward-char 1))
  8175. (setq newhead (org-get-heading))
  8176. (when (and (org-bound-and-true-p
  8177. org-agenda-headline-snapshot-before-repeat)
  8178. (not (equal org-agenda-headline-snapshot-before-repeat
  8179. newhead))
  8180. todayp)
  8181. (setq newhead org-agenda-headline-snapshot-before-repeat
  8182. just-one t))
  8183. (save-excursion
  8184. (org-back-to-heading)
  8185. (move-marker org-last-heading-marker (point))))
  8186. (beginning-of-line 1)
  8187. (save-excursion
  8188. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8189. (org-move-to-column col))))
  8190. (defun org-agenda-add-note (&optional arg)
  8191. "Add a time-stamped note to the entry at point."
  8192. (interactive "P")
  8193. (org-agenda-check-no-diary)
  8194. (let* ((marker (or (org-get-at-bol 'org-marker)
  8195. (org-agenda-error)))
  8196. (buffer (marker-buffer marker))
  8197. (pos (marker-position marker))
  8198. (hdmarker (org-get-at-bol 'org-hd-marker))
  8199. (inhibit-read-only t))
  8200. (with-current-buffer buffer
  8201. (widen)
  8202. (goto-char pos)
  8203. (org-show-context 'agenda)
  8204. (save-excursion
  8205. (and (outline-next-heading)
  8206. (org-flag-heading nil))) ; show the next heading
  8207. (org-add-note))))
  8208. (defun org-agenda-change-all-lines (newhead hdmarker
  8209. &optional fixface just-this)
  8210. "Change all lines in the agenda buffer which match HDMARKER.
  8211. The new content of the line will be NEWHEAD (as modified by
  8212. `org-agenda-format-item'). HDMARKER is checked with
  8213. `equal' against all `org-hd-marker' text properties in the file.
  8214. If FIXFACE is non-nil, the face of each item is modified according to
  8215. the new TODO state.
  8216. If JUST-THIS is non-nil, change just the current line, not all.
  8217. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8218. (let* ((inhibit-read-only t)
  8219. (line (org-current-line))
  8220. (org-agenda-buffer (current-buffer))
  8221. (thetags (with-current-buffer (marker-buffer hdmarker)
  8222. (save-excursion (save-restriction (widen)
  8223. (goto-char hdmarker)
  8224. (org-get-tags-at)))))
  8225. props m pl undone-face done-face finish new dotime level cat tags)
  8226. (save-excursion
  8227. (goto-char (point-max))
  8228. (beginning-of-line 1)
  8229. (while (not finish)
  8230. (setq finish (bobp))
  8231. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8232. (or (not just-this) (= (org-current-line) line))
  8233. (equal m hdmarker))
  8234. (setq props (text-properties-at (point))
  8235. dotime (org-get-at-bol 'dotime)
  8236. cat (org-get-at-bol 'org-category)
  8237. level (org-get-at-bol 'level)
  8238. tags thetags
  8239. new
  8240. (let ((org-prefix-format-compiled
  8241. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8242. org-prefix-format-compiled))
  8243. (extra (org-get-at-bol 'extra)))
  8244. (with-current-buffer (marker-buffer hdmarker)
  8245. (save-excursion
  8246. (save-restriction
  8247. (widen)
  8248. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8249. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8250. undone-face (org-get-at-bol 'undone-face)
  8251. done-face (org-get-at-bol 'done-face))
  8252. (beginning-of-line 1)
  8253. (cond
  8254. ((equal new "")
  8255. (and (looking-at ".*\n?") (replace-match "")))
  8256. ((looking-at ".*")
  8257. (replace-match new t t)
  8258. (beginning-of-line 1)
  8259. (add-text-properties (point-at-bol) (point-at-eol) props)
  8260. (when fixface
  8261. (add-text-properties
  8262. (point-at-bol) (point-at-eol)
  8263. (list 'face
  8264. (if org-last-todo-state-is-todo
  8265. undone-face done-face))))
  8266. (org-agenda-highlight-todo 'line)
  8267. (beginning-of-line 1))
  8268. (t (error "Line update did not work")))
  8269. (save-restriction
  8270. (narrow-to-region (point-at-bol) (point-at-eol))
  8271. (org-agenda-finalize)))
  8272. (beginning-of-line 0)))))
  8273. (defun org-agenda-align-tags (&optional line)
  8274. "Align all tags in agenda items to `org-agenda-tags-column'."
  8275. (let ((inhibit-read-only t) l c)
  8276. (save-excursion
  8277. (goto-char (if line (point-at-bol) (point-min)))
  8278. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8279. (if line (point-at-eol) nil) t)
  8280. (add-text-properties
  8281. (match-beginning 2) (match-end 2)
  8282. (list 'face (delq nil (let ((prop (get-text-property
  8283. (match-beginning 2) 'face)))
  8284. (or (listp prop) (setq prop (list prop)))
  8285. (if (memq 'org-tag prop)
  8286. prop
  8287. (cons 'org-tag prop))))))
  8288. (setq l (- (match-end 2) (match-beginning 2))
  8289. c (if (< org-agenda-tags-column 0)
  8290. (- (abs org-agenda-tags-column) l)
  8291. org-agenda-tags-column))
  8292. (delete-region (match-beginning 1) (match-end 1))
  8293. (goto-char (match-beginning 1))
  8294. (insert (org-add-props
  8295. (make-string (max 1 (- c (current-column))) ?\ )
  8296. (plist-put (copy-sequence (text-properties-at (point)))
  8297. 'face nil))))
  8298. (goto-char (point-min))
  8299. (org-font-lock-add-tag-faces (point-max)))))
  8300. (defun org-agenda-priority-up ()
  8301. "Increase the priority of line at point, also in Org-mode file."
  8302. (interactive)
  8303. (org-agenda-priority 'up))
  8304. (defun org-agenda-priority-down ()
  8305. "Decrease the priority of line at point, also in Org-mode file."
  8306. (interactive)
  8307. (org-agenda-priority 'down))
  8308. (defun org-agenda-priority (&optional force-direction)
  8309. "Set the priority of line at point, also in Org-mode file.
  8310. This changes the line at point, all other lines in the agenda referring to
  8311. the same tree node, and the headline of the tree node in the Org-mode file.
  8312. Called with a universal prefix arg, show the priority instead of setting it."
  8313. (interactive "P")
  8314. (if (equal force-direction '(4))
  8315. (org-show-priority)
  8316. (unless org-enable-priority-commands
  8317. (error "Priority commands are disabled"))
  8318. (org-agenda-check-no-diary)
  8319. (let* ((marker (or (org-get-at-bol 'org-marker)
  8320. (org-agenda-error)))
  8321. (hdmarker (org-get-at-bol 'org-hd-marker))
  8322. (buffer (marker-buffer hdmarker))
  8323. (pos (marker-position hdmarker))
  8324. (inhibit-read-only t)
  8325. newhead)
  8326. (org-with-remote-undo buffer
  8327. (with-current-buffer buffer
  8328. (widen)
  8329. (goto-char pos)
  8330. (org-show-context 'agenda)
  8331. (save-excursion
  8332. (and (outline-next-heading)
  8333. (org-flag-heading nil))) ; show the next heading
  8334. (funcall 'org-priority force-direction)
  8335. (end-of-line 1)
  8336. (setq newhead (org-get-heading)))
  8337. (org-agenda-change-all-lines newhead hdmarker)
  8338. (beginning-of-line 1)))))
  8339. ;; FIXME: should fix the tags property of the agenda line.
  8340. (defun org-agenda-set-tags (&optional tag onoff)
  8341. "Set tags for the current headline."
  8342. (interactive)
  8343. (org-agenda-check-no-diary)
  8344. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8345. (call-interactively 'org-change-tag-in-region)
  8346. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8347. (org-agenda-error)))
  8348. (buffer (marker-buffer hdmarker))
  8349. (pos (marker-position hdmarker))
  8350. (inhibit-read-only t)
  8351. newhead)
  8352. (org-with-remote-undo buffer
  8353. (with-current-buffer buffer
  8354. (widen)
  8355. (goto-char pos)
  8356. (save-excursion
  8357. (org-show-context 'agenda))
  8358. (save-excursion
  8359. (and (outline-next-heading)
  8360. (org-flag-heading nil))) ; show the next heading
  8361. (goto-char pos)
  8362. (if tag
  8363. (org-toggle-tag tag onoff)
  8364. (call-interactively 'org-set-tags))
  8365. (end-of-line 1)
  8366. (setq newhead (org-get-heading)))
  8367. (org-agenda-change-all-lines newhead hdmarker)
  8368. (beginning-of-line 1)))))
  8369. (defun org-agenda-set-property ()
  8370. "Set a property for the current headline."
  8371. (interactive)
  8372. (org-agenda-check-no-diary)
  8373. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8374. (org-agenda-error)))
  8375. (buffer (marker-buffer hdmarker))
  8376. (pos (marker-position hdmarker))
  8377. (inhibit-read-only t)
  8378. newhead)
  8379. (org-with-remote-undo buffer
  8380. (with-current-buffer buffer
  8381. (widen)
  8382. (goto-char pos)
  8383. (save-excursion
  8384. (org-show-context 'agenda))
  8385. (save-excursion
  8386. (and (outline-next-heading)
  8387. (org-flag-heading nil))) ; show the next heading
  8388. (goto-char pos)
  8389. (call-interactively 'org-set-property)))))
  8390. (defun org-agenda-set-effort ()
  8391. "Set the effort property for the current headline."
  8392. (interactive)
  8393. (org-agenda-check-no-diary)
  8394. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8395. (org-agenda-error)))
  8396. (buffer (marker-buffer hdmarker))
  8397. (pos (marker-position hdmarker))
  8398. (inhibit-read-only t)
  8399. newhead)
  8400. (org-with-remote-undo buffer
  8401. (with-current-buffer buffer
  8402. (widen)
  8403. (goto-char pos)
  8404. (save-excursion
  8405. (org-show-context 'agenda))
  8406. (save-excursion
  8407. (and (outline-next-heading)
  8408. (org-flag-heading nil))) ; show the next heading
  8409. (goto-char pos)
  8410. (call-interactively 'org-set-effort)
  8411. (end-of-line 1)
  8412. (setq newhead (org-get-heading)))
  8413. (org-agenda-change-all-lines newhead hdmarker))))
  8414. (defun org-agenda-toggle-archive-tag ()
  8415. "Toggle the archive tag for the current entry."
  8416. (interactive)
  8417. (org-agenda-check-no-diary)
  8418. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8419. (org-agenda-error)))
  8420. (buffer (marker-buffer hdmarker))
  8421. (pos (marker-position hdmarker))
  8422. (inhibit-read-only t)
  8423. newhead)
  8424. (org-with-remote-undo buffer
  8425. (with-current-buffer buffer
  8426. (widen)
  8427. (goto-char pos)
  8428. (org-show-context 'agenda)
  8429. (save-excursion
  8430. (and (outline-next-heading)
  8431. (org-flag-heading nil))) ; show the next heading
  8432. (call-interactively 'org-toggle-archive-tag)
  8433. (end-of-line 1)
  8434. (setq newhead (org-get-heading)))
  8435. (org-agenda-change-all-lines newhead hdmarker)
  8436. (beginning-of-line 1))))
  8437. (defun org-agenda-do-date-later (arg)
  8438. (interactive "P")
  8439. (cond
  8440. ((or (equal arg '(16))
  8441. (memq last-command
  8442. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8443. (setq this-command 'org-agenda-date-later-minutes)
  8444. (org-agenda-date-later-minutes 1))
  8445. ((or (equal arg '(4))
  8446. (memq last-command
  8447. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8448. (setq this-command 'org-agenda-date-later-hours)
  8449. (org-agenda-date-later-hours 1))
  8450. (t
  8451. (org-agenda-date-later (prefix-numeric-value arg)))))
  8452. (defun org-agenda-do-date-earlier (arg)
  8453. (interactive "P")
  8454. (cond
  8455. ((or (equal arg '(16))
  8456. (memq last-command
  8457. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8458. (setq this-command 'org-agenda-date-earlier-minutes)
  8459. (org-agenda-date-earlier-minutes 1))
  8460. ((or (equal arg '(4))
  8461. (memq last-command
  8462. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8463. (setq this-command 'org-agenda-date-earlier-hours)
  8464. (org-agenda-date-earlier-hours 1))
  8465. (t
  8466. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8467. (defun org-agenda-date-later (arg &optional what)
  8468. "Change the date of this item to ARG day(s) later."
  8469. (interactive "p")
  8470. (org-agenda-check-type t 'agenda 'timeline)
  8471. (org-agenda-check-no-diary)
  8472. (let* ((marker (or (org-get-at-bol 'org-marker)
  8473. (org-agenda-error)))
  8474. (buffer (marker-buffer marker))
  8475. (pos (marker-position marker))
  8476. cdate today)
  8477. (org-with-remote-undo buffer
  8478. (with-current-buffer buffer
  8479. (widen)
  8480. (goto-char pos)
  8481. (if (not (org-at-timestamp-p))
  8482. (error "Cannot find time stamp"))
  8483. (when (and org-agenda-move-date-from-past-immediately-to-today
  8484. (equal arg 1)
  8485. (or (not what) (eq what 'day))
  8486. (not (save-match-data (org-at-date-range-p))))
  8487. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8488. cdate (calendar-absolute-from-gregorian
  8489. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8490. today (org-today))
  8491. (if (> today cdate)
  8492. ;; immediately shift to today
  8493. (setq arg (- today cdate))))
  8494. (org-timestamp-change arg (or what 'day))
  8495. (when (and (org-at-date-range-p)
  8496. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8497. (let ((end org-last-changed-timestamp))
  8498. (org-timestamp-change arg (or what 'day))
  8499. (setq org-last-changed-timestamp
  8500. (concat org-last-changed-timestamp "--" end)))))
  8501. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8502. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8503. (defun org-agenda-date-earlier (arg &optional what)
  8504. "Change the date of this item to ARG day(s) earlier."
  8505. (interactive "p")
  8506. (org-agenda-date-later (- arg) what))
  8507. (defun org-agenda-date-later-minutes (arg)
  8508. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8509. (interactive "p")
  8510. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8511. (org-agenda-date-later arg 'minute))
  8512. (defun org-agenda-date-earlier-minutes (arg)
  8513. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8514. (interactive "p")
  8515. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8516. (org-agenda-date-earlier arg 'minute))
  8517. (defun org-agenda-date-later-hours (arg)
  8518. "Change the time of this item, in hour steps."
  8519. (interactive "p")
  8520. (org-agenda-date-later arg 'hour))
  8521. (defun org-agenda-date-earlier-hours (arg)
  8522. "Change the time of this item, in hour steps."
  8523. (interactive "p")
  8524. (org-agenda-date-earlier arg 'hour))
  8525. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8526. "Show new date stamp via text properties."
  8527. ;; We use text properties to make this undoable
  8528. (let ((inhibit-read-only t))
  8529. (setq stamp (concat prefix " => " stamp " "))
  8530. (save-excursion
  8531. (goto-char (point-max))
  8532. (while (not (bobp))
  8533. (when (equal marker (org-get-at-bol 'org-marker))
  8534. (org-move-to-column (- (window-width) (length stamp)) t)
  8535. (org-agenda-fix-tags-filter-overlays-at (point))
  8536. (if (featurep 'xemacs)
  8537. ;; Use `duplicable' property to trigger undo recording
  8538. (let ((ex (make-extent nil nil))
  8539. (gl (make-glyph stamp)))
  8540. (set-glyph-face gl 'secondary-selection)
  8541. (set-extent-properties
  8542. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8543. (insert-extent ex (1- (point)) (point-at-eol)))
  8544. (add-text-properties
  8545. (1- (point)) (point-at-eol)
  8546. (list 'display (org-add-props stamp nil
  8547. 'face 'secondary-selection))))
  8548. (beginning-of-line 1))
  8549. (beginning-of-line 0)))))
  8550. (defun org-agenda-date-prompt (arg)
  8551. "Change the date of this item. Date is prompted for, with default today.
  8552. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8553. be used to request time specification in the time stamp."
  8554. (interactive "P")
  8555. (org-agenda-check-type t 'agenda 'timeline)
  8556. (org-agenda-check-no-diary)
  8557. (let* ((marker (or (org-get-at-bol 'org-marker)
  8558. (org-agenda-error)))
  8559. (buffer (marker-buffer marker))
  8560. (pos (marker-position marker)))
  8561. (org-with-remote-undo buffer
  8562. (with-current-buffer buffer
  8563. (widen)
  8564. (goto-char pos)
  8565. (if (not (org-at-timestamp-p t))
  8566. (error "Cannot find time stamp"))
  8567. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8568. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8569. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8570. (defun org-agenda-schedule (arg &optional time)
  8571. "Schedule the item at point.
  8572. ARG is passed through to `org-schedule'."
  8573. (interactive "P")
  8574. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8575. (org-agenda-check-no-diary)
  8576. (let* ((marker (or (org-get-at-bol 'org-marker)
  8577. (org-agenda-error)))
  8578. (type (marker-insertion-type marker))
  8579. (buffer (marker-buffer marker))
  8580. (pos (marker-position marker))
  8581. (org-insert-labeled-timestamps-at-point nil)
  8582. ts)
  8583. (set-marker-insertion-type marker t)
  8584. (org-with-remote-undo buffer
  8585. (with-current-buffer buffer
  8586. (widen)
  8587. (goto-char pos)
  8588. (setq ts (org-schedule arg time)))
  8589. (org-agenda-show-new-time marker ts " S"))
  8590. (message "%s" ts)))
  8591. (defun org-agenda-deadline (arg &optional time)
  8592. "Schedule the item at point.
  8593. ARG is passed through to `org-deadline'."
  8594. (interactive "P")
  8595. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8596. (org-agenda-check-no-diary)
  8597. (let* ((marker (or (org-get-at-bol 'org-marker)
  8598. (org-agenda-error)))
  8599. (buffer (marker-buffer marker))
  8600. (pos (marker-position marker))
  8601. (org-insert-labeled-timestamps-at-point nil)
  8602. ts)
  8603. (org-with-remote-undo buffer
  8604. (with-current-buffer buffer
  8605. (widen)
  8606. (goto-char pos)
  8607. (setq ts (org-deadline arg time)))
  8608. (org-agenda-show-new-time marker ts " D"))
  8609. (message "%s" ts)))
  8610. (defun org-agenda-clock-in (&optional arg)
  8611. "Start the clock on the currently selected item."
  8612. (interactive "P")
  8613. (org-agenda-check-no-diary)
  8614. (if (equal arg '(4))
  8615. (org-clock-in arg)
  8616. (let* ((marker (or (org-get-at-bol 'org-marker)
  8617. (org-agenda-error)))
  8618. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8619. (pos (marker-position marker))
  8620. (col (current-column))
  8621. newhead)
  8622. (org-with-remote-undo (marker-buffer marker)
  8623. (with-current-buffer (marker-buffer marker)
  8624. (widen)
  8625. (goto-char pos)
  8626. (org-show-context 'agenda)
  8627. (org-show-entry)
  8628. (org-cycle-hide-drawers 'children)
  8629. (org-clock-in arg)
  8630. (setq newhead (org-get-heading)))
  8631. (org-agenda-change-all-lines newhead hdmarker))
  8632. (org-move-to-column col))))
  8633. (defun org-agenda-clock-out ()
  8634. "Stop the currently running clock."
  8635. (interactive)
  8636. (unless (marker-buffer org-clock-marker)
  8637. (error "No running clock"))
  8638. (let ((marker (make-marker)) (col (current-column)) newhead)
  8639. (org-with-remote-undo (marker-buffer org-clock-marker)
  8640. (with-current-buffer (marker-buffer org-clock-marker)
  8641. (save-excursion
  8642. (save-restriction
  8643. (widen)
  8644. (goto-char org-clock-marker)
  8645. (org-back-to-heading t)
  8646. (move-marker marker (point))
  8647. (org-clock-out)
  8648. (setq newhead (org-get-heading))))))
  8649. (org-agenda-change-all-lines newhead marker)
  8650. (move-marker marker nil)
  8651. (org-move-to-column col)
  8652. (org-agenda-unmark-clocking-task)))
  8653. (defun org-agenda-clock-cancel (&optional arg)
  8654. "Cancel the currently running clock."
  8655. (interactive "P")
  8656. (unless (marker-buffer org-clock-marker)
  8657. (user-error "No running clock"))
  8658. (org-with-remote-undo (marker-buffer org-clock-marker)
  8659. (org-clock-cancel)))
  8660. (defun org-agenda-clock-goto ()
  8661. "Jump to the currently clocked in task within the agenda.
  8662. If the currently clocked in task is not listed in the agenda
  8663. buffer, display it in another window."
  8664. (interactive)
  8665. (let (pos)
  8666. (mapc (lambda (o)
  8667. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8668. (setq pos (overlay-start o))))
  8669. (overlays-in (point-min) (point-max)))
  8670. (cond (pos (goto-char pos))
  8671. ;; If the currently clocked entry is not in the agenda
  8672. ;; buffer, we visit it in another window:
  8673. (org-clock-current-task
  8674. (org-switch-to-buffer-other-window (org-clock-goto)))
  8675. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8676. (defun org-agenda-diary-entry-in-org-file ()
  8677. "Make a diary entry in the file `org-agenda-diary-file'."
  8678. (let (d1 d2 char (text "") dp1 dp2)
  8679. (if (equal (buffer-name) "*Calendar*")
  8680. (setq d1 (calendar-cursor-to-date t)
  8681. d2 (car calendar-mark-ring))
  8682. (setq dp1 (get-text-property (point-at-bol) 'day))
  8683. (unless dp1 (user-error "No date defined in current line"))
  8684. (setq d1 (calendar-gregorian-from-absolute dp1)
  8685. d2 (and (ignore-errors (mark))
  8686. (save-excursion
  8687. (goto-char (mark))
  8688. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8689. (calendar-gregorian-from-absolute dp2))))
  8690. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8691. (setq char (read-char-exclusive))
  8692. (cond
  8693. ((equal char ?d)
  8694. (setq text (read-string "Day entry: "))
  8695. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8696. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8697. ((equal char ?a)
  8698. (setq d1 (list (car d1) (nth 1 d1)
  8699. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8700. (nth 2 d1))))
  8701. (setq text (read-string "Anniversary (use %d to show years): "))
  8702. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8703. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8704. ((equal char ?b)
  8705. (setq text (read-string "Block entry: "))
  8706. (unless (and d1 d2 (not (equal d1 d2)))
  8707. (user-error "No block of days selected"))
  8708. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8709. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8710. ((equal char ?j)
  8711. (org-switch-to-buffer-other-window
  8712. (find-file-noselect org-agenda-diary-file))
  8713. (require 'org-datetree)
  8714. (org-datetree-find-date-create d1)
  8715. (org-reveal t))
  8716. (t (user-error "Invalid selection character `%c'" char)))))
  8717. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8718. "Where in `org-agenda-diary-file' should new entries be added?
  8719. Valid values:
  8720. date-tree in the date tree, as child of the date
  8721. top-level as top-level entries at the end of the file."
  8722. :group 'org-agenda
  8723. :type '(choice
  8724. (const :tag "in a date tree" date-tree)
  8725. (const :tag "as top level at end of file" top-level)))
  8726. (defcustom org-agenda-insert-diary-extract-time nil
  8727. "Non-nil means extract any time specification from the diary entry."
  8728. :group 'org-agenda
  8729. :version "24.1"
  8730. :type 'boolean)
  8731. (defcustom org-agenda-bulk-mark-char ">"
  8732. "A single-character string to be used as the bulk mark."
  8733. :group 'org-agenda
  8734. :version "24.1"
  8735. :type 'string)
  8736. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8737. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8738. If TEXT is not empty, it will become the headline of the new entry, and
  8739. the resulting entry will not be shown. When TEXT is empty, switch to
  8740. `org-agenda-diary-file' and let the user finish the entry there."
  8741. (let ((cw (current-window-configuration)))
  8742. (org-switch-to-buffer-other-window
  8743. (find-file-noselect org-agenda-diary-file))
  8744. (widen)
  8745. (goto-char (point-min))
  8746. (cond
  8747. ((eq type 'anniversary)
  8748. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8749. (progn
  8750. (or (org-at-heading-p t)
  8751. (progn
  8752. (outline-next-heading)
  8753. (insert "* Anniversaries\n\n")
  8754. (beginning-of-line -1)))))
  8755. (outline-next-heading)
  8756. (org-back-over-empty-lines)
  8757. (backward-char 1)
  8758. (insert "\n")
  8759. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8760. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8761. ((eq type 'day)
  8762. (let ((org-prefix-has-time t)
  8763. (org-agenda-time-leading-zero t)
  8764. fmt time time2)
  8765. (if org-agenda-insert-diary-extract-time
  8766. ;; Use org-agenda-format-item to parse text for a time-range and
  8767. ;; remove it. FIXME: This is a hack, we should refactor
  8768. ;; that function to make time extraction available separately
  8769. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8770. time (get-text-property 0 'time fmt)
  8771. time2 (if (> (length time) 0)
  8772. ;; split-string removes trailing ...... if
  8773. ;; no end time given. First space
  8774. ;; separates time from date.
  8775. (concat " " (car (split-string time "\\.")))
  8776. nil)
  8777. text (get-text-property 0 'txt fmt)))
  8778. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8779. (org-agenda-insert-diary-as-top-level text)
  8780. (require 'org-datetree)
  8781. (org-datetree-find-date-create d1)
  8782. (org-agenda-insert-diary-make-new-entry text))
  8783. (org-insert-time-stamp (org-time-from-absolute
  8784. (calendar-absolute-from-gregorian d1))
  8785. nil nil nil nil time2))
  8786. (end-of-line 0))
  8787. ((eq type 'block)
  8788. (if (> (calendar-absolute-from-gregorian d1)
  8789. (calendar-absolute-from-gregorian d2))
  8790. (setq d1 (prog1 d2 (setq d2 d1))))
  8791. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8792. (org-agenda-insert-diary-as-top-level text)
  8793. (require 'org-datetree)
  8794. (org-datetree-find-date-create d1)
  8795. (org-agenda-insert-diary-make-new-entry text))
  8796. (org-insert-time-stamp (org-time-from-absolute
  8797. (calendar-absolute-from-gregorian d1)))
  8798. (insert "--")
  8799. (org-insert-time-stamp (org-time-from-absolute
  8800. (calendar-absolute-from-gregorian d2)))
  8801. (end-of-line 0)))
  8802. (if (string-match "\\S-" text)
  8803. (progn
  8804. (set-window-configuration cw)
  8805. (message "%s entry added to %s"
  8806. (capitalize (symbol-name type))
  8807. (abbreviate-file-name org-agenda-diary-file)))
  8808. (org-reveal t)
  8809. (message "Please finish entry here"))))
  8810. (defun org-agenda-insert-diary-as-top-level (text)
  8811. "Make new entry as a top-level entry at the end of the file.
  8812. Add TEXT as headline, and position the cursor in the second line so that
  8813. a timestamp can be added there."
  8814. (widen)
  8815. (goto-char (point-max))
  8816. (or (bolp) (insert "\n"))
  8817. (insert "* " text "\n")
  8818. (if org-adapt-indentation (org-indent-to-column 2)))
  8819. (defun org-agenda-insert-diary-make-new-entry (text)
  8820. "Make new entry as last child of current entry.
  8821. Add TEXT as headline, and position the cursor in the second line so that
  8822. a timestamp can be added there."
  8823. (let ((org-show-following-heading t)
  8824. (org-show-siblings t)
  8825. (org-show-hierarchy-above t)
  8826. (org-show-entry-below t)
  8827. col)
  8828. (outline-next-heading)
  8829. (org-back-over-empty-lines)
  8830. (or (looking-at "[ \t]*$")
  8831. (progn (insert "\n") (backward-char 1)))
  8832. (org-insert-heading nil t)
  8833. (org-do-demote)
  8834. (setq col (current-column))
  8835. (insert text "\n")
  8836. (if org-adapt-indentation (org-indent-to-column col))
  8837. (let ((org-show-following-heading t)
  8838. (org-show-siblings t)
  8839. (org-show-hierarchy-above t)
  8840. (org-show-entry-below t))
  8841. (org-show-context))))
  8842. (defun org-agenda-diary-entry ()
  8843. "Make a diary entry, like the `i' command from the calendar.
  8844. All the standard commands work: block, weekly etc.
  8845. When `org-agenda-diary-file' points to a file,
  8846. `org-agenda-diary-entry-in-org-file' is called instead to create
  8847. entries in that Org-mode file."
  8848. (interactive)
  8849. (if (not (eq org-agenda-diary-file 'diary-file))
  8850. (org-agenda-diary-entry-in-org-file)
  8851. (require 'diary-lib)
  8852. (let* ((char (progn
  8853. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8854. (read-char-exclusive)))
  8855. (cmd (cdr (assoc char
  8856. '((?d . insert-diary-entry)
  8857. (?w . insert-weekly-diary-entry)
  8858. (?m . insert-monthly-diary-entry)
  8859. (?y . insert-yearly-diary-entry)
  8860. (?a . insert-anniversary-diary-entry)
  8861. (?b . insert-block-diary-entry)
  8862. (?c . insert-cyclic-diary-entry)))))
  8863. (oldf (symbol-function 'calendar-cursor-to-date))
  8864. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8865. (point (point))
  8866. (mark (or (mark t) (point))))
  8867. (unless cmd
  8868. (user-error "No command associated with <%c>" char))
  8869. (unless (and (get-text-property point 'day)
  8870. (or (not (equal ?b char))
  8871. (get-text-property mark 'day)))
  8872. (user-error "Don't know which date to use for diary entry"))
  8873. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8874. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8875. (let ((calendar-mark-ring
  8876. (list (calendar-gregorian-from-absolute
  8877. (or (get-text-property mark 'day)
  8878. (get-text-property point 'day))))))
  8879. (unwind-protect
  8880. (progn
  8881. (fset 'calendar-cursor-to-date
  8882. (lambda (&optional error dummy)
  8883. (calendar-gregorian-from-absolute
  8884. (get-text-property point 'day))))
  8885. (call-interactively cmd))
  8886. (fset 'calendar-cursor-to-date oldf))))))
  8887. (defun org-agenda-execute-calendar-command (cmd)
  8888. "Execute a calendar command from the agenda with date from cursor."
  8889. (org-agenda-check-type t 'agenda 'timeline)
  8890. (require 'diary-lib)
  8891. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8892. (user-error "Don't know which date to use for the calendar command"))
  8893. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8894. (point (point))
  8895. (date (calendar-gregorian-from-absolute
  8896. (get-text-property point 'day)))
  8897. ;; the following 2 vars are needed in the calendar
  8898. (displayed-month (car date))
  8899. (displayed-year (nth 2 date)))
  8900. (unwind-protect
  8901. (progn
  8902. (fset 'calendar-cursor-to-date
  8903. (lambda (&optional error dummy)
  8904. (calendar-gregorian-from-absolute
  8905. (get-text-property point 'day))))
  8906. (call-interactively cmd))
  8907. (fset 'calendar-cursor-to-date oldf))))
  8908. (defun org-agenda-phases-of-moon ()
  8909. "Display the phases of the moon for the 3 months around the cursor date."
  8910. (interactive)
  8911. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8912. (defun org-agenda-holidays ()
  8913. "Display the holidays for the 3 months around the cursor date."
  8914. (interactive)
  8915. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8916. (defvar calendar-longitude) ; defined in calendar.el
  8917. (defvar calendar-latitude) ; defined in calendar.el
  8918. (defvar calendar-location-name) ; defined in calendar.el
  8919. (defun org-agenda-sunrise-sunset (arg)
  8920. "Display sunrise and sunset for the cursor date.
  8921. Latitude and longitude can be specified with the variables
  8922. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8923. argument, latitude and longitude will be prompted for."
  8924. (interactive "P")
  8925. (require 'solar)
  8926. (let ((calendar-longitude (if arg nil calendar-longitude))
  8927. (calendar-latitude (if arg nil calendar-latitude))
  8928. (calendar-location-name
  8929. (if arg "the given coordinates" calendar-location-name)))
  8930. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8931. (defun org-agenda-goto-calendar ()
  8932. "Open the Emacs calendar with the date at the cursor."
  8933. (interactive)
  8934. (org-agenda-check-type t 'agenda 'timeline)
  8935. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8936. (user-error "Don't know which date to open in calendar")))
  8937. (date (calendar-gregorian-from-absolute day))
  8938. (calendar-move-hook nil)
  8939. (calendar-view-holidays-initially-flag nil)
  8940. (calendar-view-diary-initially-flag nil))
  8941. (calendar)
  8942. (calendar-goto-date date)))
  8943. ;;;###autoload
  8944. (defun org-calendar-goto-agenda ()
  8945. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8946. This is a command that has to be installed in `calendar-mode-map'."
  8947. (interactive)
  8948. (org-agenda-list nil (calendar-absolute-from-gregorian
  8949. (calendar-cursor-to-date))
  8950. nil))
  8951. (defun org-agenda-convert-date ()
  8952. (interactive)
  8953. (org-agenda-check-type t 'agenda 'timeline)
  8954. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8955. date s)
  8956. (unless day
  8957. (user-error "Don't know which date to convert"))
  8958. (setq date (calendar-gregorian-from-absolute day))
  8959. (setq s (concat
  8960. "Gregorian: " (calendar-date-string date) "\n"
  8961. "ISO: " (calendar-iso-date-string date) "\n"
  8962. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8963. "Julian: " (calendar-julian-date-string date) "\n"
  8964. "Astron. JD: " (calendar-astro-date-string date)
  8965. " (Julian date number at noon UTC)\n"
  8966. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8967. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8968. "French: " (calendar-french-date-string date) "\n"
  8969. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8970. "Mayan: " (calendar-mayan-date-string date) "\n"
  8971. "Coptic: " (calendar-coptic-date-string date) "\n"
  8972. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8973. "Persian: " (calendar-persian-date-string date) "\n"
  8974. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8975. (with-output-to-temp-buffer "*Dates*"
  8976. (princ s))
  8977. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8978. ;;; Bulk commands
  8979. (defun org-agenda-bulk-marked-p ()
  8980. (eq (get-char-property (point-at-bol) 'type)
  8981. 'org-marked-entry-overlay))
  8982. (defun org-agenda-bulk-mark (&optional arg)
  8983. "Mark the entry at point for future bulk action."
  8984. (interactive "p")
  8985. (dotimes (i (or arg 1))
  8986. (unless (org-get-at-bol 'org-agenda-diary-link)
  8987. (let* ((m (org-get-at-bol 'org-hd-marker))
  8988. ov)
  8989. (unless (org-agenda-bulk-marked-p)
  8990. (unless m (user-error "Nothing to mark at point"))
  8991. (push m org-agenda-bulk-marked-entries)
  8992. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8993. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8994. (org-get-todo-face "TODO")
  8995. 'evaporate)
  8996. (overlay-put ov 'type 'org-marked-entry-overlay))
  8997. (end-of-line 1)
  8998. (or (ignore-errors
  8999. (goto-char (next-single-property-change (point) 'txt)))
  9000. (beginning-of-line 2))
  9001. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9002. (beginning-of-line 2))
  9003. (message "%d entries marked for bulk action"
  9004. (length org-agenda-bulk-marked-entries))))))
  9005. (defun org-agenda-bulk-mark-all ()
  9006. "Mark all entries for future agenda bulk action."
  9007. (interactive)
  9008. (org-agenda-bulk-mark-regexp "."))
  9009. (defun org-agenda-bulk-mark-regexp (regexp)
  9010. "Mark entries matching REGEXP for future agenda bulk action."
  9011. (interactive "sMark entries matching regexp: ")
  9012. (let ((entries-marked 0) txt-at-point)
  9013. (save-excursion
  9014. (goto-char (point-min))
  9015. (goto-char (next-single-property-change (point) 'txt))
  9016. (while (and (re-search-forward regexp nil t)
  9017. (setq txt-at-point (get-text-property (point) 'txt)))
  9018. (when (string-match regexp txt-at-point)
  9019. (setq entries-marked (1+ entries-marked))
  9020. (call-interactively 'org-agenda-bulk-mark))))
  9021. (if (not entries-marked)
  9022. (message "No entry matching this regexp."))))
  9023. (defun org-agenda-bulk-unmark (&optional arg)
  9024. "Unmark the entry at point for future bulk action."
  9025. (interactive "P")
  9026. (if arg
  9027. (org-agenda-bulk-unmark-all)
  9028. (cond ((org-agenda-bulk-marked-p)
  9029. (org-agenda-bulk-remove-overlays
  9030. (point-at-bol) (+ 2 (point-at-bol)))
  9031. (setq org-agenda-bulk-marked-entries
  9032. (delete (org-get-at-bol 'org-hd-marker)
  9033. org-agenda-bulk-marked-entries))
  9034. (end-of-line 1)
  9035. (or (ignore-errors
  9036. (goto-char (next-single-property-change (point) 'txt)))
  9037. (beginning-of-line 2))
  9038. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9039. (beginning-of-line 2))
  9040. (message "%d entries left marked for bulk action"
  9041. (length org-agenda-bulk-marked-entries)))
  9042. (t (message "No entry to unmark here")))))
  9043. (defun org-agenda-bulk-toggle-all ()
  9044. "Toggle all marks for bulk action."
  9045. (interactive)
  9046. (save-excursion
  9047. (goto-char (point-min))
  9048. (while (ignore-errors
  9049. (goto-char (next-single-property-change (point) 'txt)))
  9050. (org-agenda-bulk-toggle))))
  9051. (defun org-agenda-bulk-toggle ()
  9052. "Toggle the mark at point for bulk action."
  9053. (interactive)
  9054. (if (org-agenda-bulk-marked-p)
  9055. (org-agenda-bulk-unmark)
  9056. (org-agenda-bulk-mark)))
  9057. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9058. "Remove the mark overlays between BEG and END in the agenda buffer.
  9059. BEG and END default to the buffer limits.
  9060. This only removes the overlays, it does not remove the markers
  9061. from the list in `org-agenda-bulk-marked-entries'."
  9062. (interactive)
  9063. (mapc (lambda (ov)
  9064. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9065. (delete-overlay ov)))
  9066. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9067. (defun org-agenda-bulk-unmark-all ()
  9068. "Remove all marks in the agenda buffer.
  9069. This will remove the markers and the overlays."
  9070. (interactive)
  9071. (if (null org-agenda-bulk-marked-entries)
  9072. (message "No entry to unmark")
  9073. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9074. (setq org-agenda-bulk-marked-entries nil)
  9075. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9076. (defcustom org-agenda-persistent-marks nil
  9077. "Non-nil means marked items will stay marked after a bulk action.
  9078. You can toggle this interactively by typing `p' when prompted for a
  9079. bulk action."
  9080. :group 'org-agenda
  9081. :version "24.1"
  9082. :type 'boolean)
  9083. (defun org-agenda-bulk-action (&optional arg)
  9084. "Execute an remote-editing action on all marked entries.
  9085. The prefix arg is passed through to the command if possible."
  9086. (interactive "P")
  9087. ;; Make sure we have markers, and only valid ones
  9088. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9089. (mapc
  9090. (lambda (m)
  9091. (unless (and (markerp m)
  9092. (marker-buffer m)
  9093. (buffer-live-p (marker-buffer m))
  9094. (marker-position m))
  9095. (user-error "Marker %s for bulk command is invalid" m)))
  9096. org-agenda-bulk-marked-entries)
  9097. ;; Prompt for the bulk command
  9098. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9099. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9100. "[S]catter [f]unction "
  9101. (when org-agenda-bulk-custom-functions
  9102. (concat " Custom: ["
  9103. (mapconcat (lambda(f) (char-to-string (car f)))
  9104. org-agenda-bulk-custom-functions "")
  9105. "]"))))
  9106. (catch 'exit
  9107. (let* ((action (read-char-exclusive))
  9108. (org-log-refile (if org-log-refile 'time nil))
  9109. (entries (reverse org-agenda-bulk-marked-entries))
  9110. (org-overriding-default-time
  9111. (if (get-text-property (point) 'org-agenda-date-header)
  9112. (org-get-cursor-date)))
  9113. redo-at-end
  9114. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9115. (cond
  9116. ((equal action ?p)
  9117. (let ((org-agenda-persistent-marks
  9118. (not org-agenda-persistent-marks)))
  9119. (org-agenda-bulk-action)
  9120. (throw 'exit nil)))
  9121. ((equal action ?$)
  9122. (setq cmd '(org-agenda-archive)))
  9123. ((equal action ?A)
  9124. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9125. ((member action '(?r ?w))
  9126. (setq rfloc (org-refile-get-location
  9127. "Refile to"
  9128. (marker-buffer (car entries))
  9129. org-refile-allow-creating-parent-nodes))
  9130. (if (nth 3 rfloc)
  9131. (setcar (nthcdr 3 rfloc)
  9132. (move-marker (make-marker) (nth 3 rfloc)
  9133. (or (get-file-buffer (nth 1 rfloc))
  9134. (find-buffer-visiting (nth 1 rfloc))
  9135. (error "This should not happen")))))
  9136. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9137. redo-at-end t))
  9138. ((equal action ?t)
  9139. (setq state (org-icompleting-read
  9140. "Todo state: "
  9141. (with-current-buffer (marker-buffer (car entries))
  9142. (mapcar 'list org-todo-keywords-1))))
  9143. (setq cmd `(let ((org-inhibit-blocking t)
  9144. (org-inhibit-logging 'note))
  9145. (org-agenda-todo ,state))))
  9146. ((memq action '(?- ?+))
  9147. (setq tag (org-icompleting-read
  9148. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9149. (with-current-buffer (marker-buffer (car entries))
  9150. (delq nil
  9151. (mapcar (lambda (x)
  9152. (if (stringp (car x)) x)) org-tag-alist)))))
  9153. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9154. ((memq action '(?s ?d))
  9155. (let* ((time
  9156. (unless arg
  9157. (org-read-date
  9158. nil nil nil
  9159. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9160. org-overriding-default-time)))
  9161. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9162. (setq cmd `(eval '(,c1 arg ,time)))))
  9163. ((equal action ?S)
  9164. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9165. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9166. (let ((days (read-number
  9167. (format "Scatter tasks across how many %sdays: "
  9168. (if arg "week" "")) 7)))
  9169. (setq cmd
  9170. `(let ((distance (1+ (random ,days))))
  9171. (if arg
  9172. (let ((dist distance)
  9173. (day-of-week
  9174. (calendar-day-of-week
  9175. (calendar-gregorian-from-absolute (org-today)))))
  9176. (dotimes (i (1+ dist))
  9177. (while (member day-of-week org-agenda-weekend-days)
  9178. (incf distance)
  9179. (incf day-of-week)
  9180. (if (= day-of-week 7)
  9181. (setq day-of-week 0)))
  9182. (incf day-of-week)
  9183. (if (= day-of-week 7)
  9184. (setq day-of-week 0)))))
  9185. ;; silently fail when try to replan a sexp entry
  9186. (condition-case nil
  9187. (let* ((date (calendar-gregorian-from-absolute
  9188. (+ (org-today) distance)))
  9189. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9190. (nth 2 date))))
  9191. (org-agenda-schedule nil time))
  9192. (error nil)))))))
  9193. ((assoc action org-agenda-bulk-custom-functions)
  9194. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9195. redo-at-end t))
  9196. ((equal action ?f)
  9197. (setq cmd (list (intern
  9198. (org-icompleting-read "Function: "
  9199. obarray 'fboundp t nil nil)))))
  9200. (t (user-error "Invalid bulk action")))
  9201. ;; Sort the markers, to make sure that parents are handled before children
  9202. (setq entries (sort entries
  9203. (lambda (a b)
  9204. (cond
  9205. ((equal (marker-buffer a) (marker-buffer b))
  9206. (< (marker-position a) (marker-position b)))
  9207. (t
  9208. (string< (buffer-name (marker-buffer a))
  9209. (buffer-name (marker-buffer b))))))))
  9210. ;; Now loop over all markers and apply cmd
  9211. (while (setq e (pop entries))
  9212. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9213. (if (not pos)
  9214. (progn (message "Skipping removed entry at %s" e)
  9215. (setq cntskip (1+ cntskip)))
  9216. (goto-char pos)
  9217. (let (org-loop-over-headlines-in-active-region)
  9218. (eval cmd))
  9219. (setq cnt (1+ cnt))))
  9220. (when redo-at-end (org-agenda-redo))
  9221. (unless org-agenda-persistent-marks
  9222. (org-agenda-bulk-unmark-all))
  9223. (message "Acted on %d entries%s%s"
  9224. cnt
  9225. (if (= cntskip 0)
  9226. ""
  9227. (format ", skipped %d (disappeared before their turn)"
  9228. cntskip))
  9229. (if (not org-agenda-persistent-marks)
  9230. "" " (kept marked)"))))))
  9231. (defun org-agenda-capture (&optional with-time)
  9232. "Call `org-capture' with the date at point.
  9233. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9234. current HH:MM time."
  9235. (interactive "P")
  9236. (if (not (eq major-mode 'org-agenda-mode))
  9237. (user-error "You cannot do this outside of agenda buffers")
  9238. (let ((org-overriding-default-time
  9239. (org-get-cursor-date (equal with-time 1))))
  9240. (call-interactively 'org-capture))))
  9241. ;;; Dragging agenda lines forward/backward
  9242. (defun org-agenda-drag-line-forward (arg)
  9243. "Drag an agenda line forward by ARG lines."
  9244. (interactive "p")
  9245. (let ((inhibit-read-only t) lst)
  9246. (if (save-excursion
  9247. (dotimes (n arg)
  9248. (beginning-of-line 2)
  9249. (push (not (get-text-property (point) 'txt)) lst))
  9250. (delq nil lst))
  9251. (message "Cannot move line forward")
  9252. (org-drag-line-forward arg))))
  9253. (defun org-agenda-drag-line-backward (arg)
  9254. "Drag an agenda line backward by ARG lines."
  9255. (interactive "p")
  9256. (let ((inhibit-read-only t) lst)
  9257. (if (save-excursion
  9258. (dotimes (n arg)
  9259. (beginning-of-line 0)
  9260. (push (not (get-text-property (point) 'txt)) lst))
  9261. (delq nil lst))
  9262. (message "Cannot move line backward")
  9263. (org-drag-line-backward arg))))
  9264. ;;; Flagging notes
  9265. (defun org-agenda-show-the-flagging-note ()
  9266. "Display the flagging note in the other window.
  9267. When called a second time in direct sequence, offer to remove the FLAGGING
  9268. tag and (if present) the flagging note."
  9269. (interactive)
  9270. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9271. (win (selected-window))
  9272. note heading newhead)
  9273. (unless hdmarker
  9274. (user-error "No linked entry at point"))
  9275. (if (and (eq this-command last-command)
  9276. (y-or-n-p "Unflag and remove any flagging note? "))
  9277. (progn
  9278. (org-agenda-remove-flag hdmarker)
  9279. (let ((win (get-buffer-window "*Flagging Note*")))
  9280. (and win (delete-window win)))
  9281. (message "Entry unflagged"))
  9282. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9283. (unless note
  9284. (user-error "No flagging note"))
  9285. (org-kill-new note)
  9286. (org-switch-to-buffer-other-window "*Flagging Note*")
  9287. (erase-buffer)
  9288. (insert note)
  9289. (goto-char (point-min))
  9290. (while (re-search-forward "\\\\n" nil t)
  9291. (replace-match "\n" t t))
  9292. (goto-char (point-min))
  9293. (select-window win)
  9294. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9295. (defun org-agenda-remove-flag (marker)
  9296. "Remove the FLAGGED tag and any flagging note in the entry."
  9297. (let (newhead)
  9298. (org-with-point-at marker
  9299. (org-toggle-tag "FLAGGED" 'off)
  9300. (org-entry-delete nil "THEFLAGGINGNOTE")
  9301. (setq newhead (org-get-heading)))
  9302. (org-agenda-change-all-lines newhead marker)
  9303. (message "Entry unflagged")))
  9304. (defun org-agenda-get-any-marker (&optional pos)
  9305. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9306. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9307. ;;; Appointment reminders
  9308. (defvar appt-time-msg-list) ; defined in appt.el
  9309. ;;;###autoload
  9310. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9311. "Activate appointments found in `org-agenda-files'.
  9312. With a \\[universal-argument] prefix, refresh the list of
  9313. appointments.
  9314. If FILTER is t, interactively prompt the user for a regular
  9315. expression, and filter out entries that don't match it.
  9316. If FILTER is a string, use this string as a regular expression
  9317. for filtering entries out.
  9318. If FILTER is a function, filter out entries against which
  9319. calling the function returns nil. This function takes one
  9320. argument: an entry from `org-agenda-get-day-entries'.
  9321. FILTER can also be an alist with the car of each cell being
  9322. either 'headline or 'category. For example:
  9323. '((headline \"IMPORTANT\")
  9324. (category \"Work\"))
  9325. will only add headlines containing IMPORTANT or headlines
  9326. belonging to the \"Work\" category.
  9327. ARGS are symbols indicating what kind of entries to consider.
  9328. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9329. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9330. and :timestamp entries. See the docstring of `org-diary' for
  9331. details and examples.
  9332. If an entry has a APPT_WARNTIME property, its value will be used
  9333. to override `appt-message-warning-time'."
  9334. (interactive "P")
  9335. (if refresh (setq appt-time-msg-list nil))
  9336. (if (eq filter t)
  9337. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9338. (let* ((cnt 0) ; count added events
  9339. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9340. (org-agenda-new-buffers nil)
  9341. (org-deadline-warning-days 0)
  9342. ;; Do not use `org-today' here because appt only takes
  9343. ;; time and without date as argument, so it may pass wrong
  9344. ;; information otherwise
  9345. (today (org-date-to-gregorian
  9346. (time-to-days (current-time))))
  9347. (org-agenda-restrict nil)
  9348. (files (org-agenda-files 'unrestricted)) entries file
  9349. (org-agenda-buffer nil))
  9350. ;; Get all entries which may contain an appt
  9351. (org-agenda-prepare-buffers files)
  9352. (while (setq file (pop files))
  9353. (setq entries
  9354. (delq nil
  9355. (append entries
  9356. (apply 'org-agenda-get-day-entries
  9357. file today scope)))))
  9358. ;; Map thru entries and find if we should filter them out
  9359. (mapc
  9360. (lambda(x)
  9361. (let* ((evt (org-trim
  9362. (replace-regexp-in-string
  9363. org-bracket-link-regexp "\\3"
  9364. (or (get-text-property 1 'txt x) ""))))
  9365. (cat (get-text-property 1 'org-category x))
  9366. (tod (get-text-property 1 'time-of-day x))
  9367. (ok (or (null filter)
  9368. (and (stringp filter) (string-match filter evt))
  9369. (and (functionp filter) (funcall filter x))
  9370. (and (listp filter)
  9371. (let ((cat-filter (cadr (assoc 'category filter)))
  9372. (evt-filter (cadr (assoc 'headline filter))))
  9373. (or (and (stringp cat-filter)
  9374. (string-match cat-filter cat))
  9375. (and (stringp evt-filter)
  9376. (string-match evt-filter evt)))))))
  9377. (wrn (get-text-property 1 'warntime x)))
  9378. ;; FIXME: Shall we remove text-properties for the appt text?
  9379. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9380. (when (and ok tod)
  9381. (setq tod (concat "00" (number-to-string tod))
  9382. tod (when (string-match
  9383. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9384. (concat (match-string 1 tod) ":"
  9385. (match-string 2 tod))))
  9386. (if (version< emacs-version "23.3")
  9387. (appt-add tod evt)
  9388. (appt-add tod evt wrn))
  9389. (setq cnt (1+ cnt))))) entries)
  9390. (org-release-buffers org-agenda-new-buffers)
  9391. (if (eq cnt 0)
  9392. (message "No event to add")
  9393. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9394. (defun org-agenda-todayp (date)
  9395. "Does DATE mean today, when considering `org-extend-today-until'?"
  9396. (let ((today (org-today))
  9397. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9398. date)))
  9399. (eq date today)))
  9400. (defun org-agenda-todo-yesterday (&optional arg)
  9401. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9402. (interactive "P")
  9403. (let* ((hour (third (decode-time
  9404. (org-current-time))))
  9405. (org-extend-today-until (1+ hour)))
  9406. (org-agenda-todo arg)))
  9407. (provide 'org-agenda)
  9408. ;;; org-agenda.el ends here