org-agenda.el 389 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const timestamp-up) (const timestamp-down)
  215. (const scheduled-up) (const scheduled-down)
  216. (const deadline-up) (const deadline-down)
  217. (const ts-up) (const ts-down)
  218. (const tsia-up) (const tsia-down)
  219. (const category-keep) (const category-up) (const category-down)
  220. (const tag-down) (const tag-up)
  221. (const priority-up) (const priority-down)
  222. (const todo-state-up) (const todo-state-down)
  223. (const effort-up) (const effort-down)
  224. (const habit-up) (const habit-down)
  225. (const alpha-up) (const alpha-down)
  226. (const user-defined-up) (const user-defined-down))
  227. "Sorting choices.")
  228. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  229. ;; the new variable `org-agenda-tag-filter-preset'.
  230. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  231. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  232. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  233. "List of types searched for when creating the daily/weekly agenda.
  234. This variable is a list of symbols that controls the types of
  235. items that appear in the daily/weekly agenda. Allowed symbols in this
  236. list are are
  237. :timestamp List items containing a date stamp or date range matching
  238. the selected date. This includes sexp entries in angular
  239. brackets.
  240. :sexp List entries resulting from plain diary-like sexps.
  241. :deadline List deadline due on that date. When the date is today,
  242. also list any deadlines past due, or due within
  243. `org-deadline-warning-days'. `:deadline' must appear before
  244. `:scheduled' if the setting of
  245. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  246. any effect.
  247. :deadline* Same as above, but only include the deadline if it has an
  248. hour specification as [h]h:mm.
  249. :scheduled List all items which are scheduled for the given date.
  250. The diary for *today* also contains items which were
  251. scheduled earlier and are not yet marked DONE.
  252. :scheduled* Same as above, but only include the scheduled item if it
  253. has an hour specification as [h]h:mm.
  254. By default, all four non-starred types are turned on.
  255. When :scheduled* or :deadline* are included, :schedule or :deadline
  256. will be ignored.
  257. Never set this variable globally using `setq', because then it
  258. will apply to all future agenda commands. Instead, bind it with
  259. `let' to scope it dynamically into the agenda-constructing
  260. command. A good way to set it is through options in
  261. `org-agenda-custom-commands'. For a more flexible (though
  262. somewhat less efficient) way of determining what is included in
  263. the daily/weekly agenda, see `org-agenda-skip-function'.")
  264. (defconst org-agenda-custom-commands-local-options
  265. `(repeat :tag "Local settings for this command. Remember to quote values"
  266. (choice :tag "Setting"
  267. (list :tag "Heading for this block"
  268. (const org-agenda-overriding-header)
  269. (string :tag "Headline"))
  270. (list :tag "Files to be searched"
  271. (const org-agenda-files)
  272. (list
  273. (const :format "" quote)
  274. (repeat (file))))
  275. (list :tag "Sorting strategy"
  276. (const org-agenda-sorting-strategy)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. ,org-sorting-choice)))
  281. (list :tag "Prefix format"
  282. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  283. (string))
  284. (list :tag "Number of days in agenda"
  285. (const org-agenda-span)
  286. (choice (const :tag "Day" 'day)
  287. (const :tag "Week" 'week)
  288. (const :tag "Month" 'month)
  289. (const :tag "Year" 'year)
  290. (integer :tag "Custom")))
  291. (list :tag "Fixed starting date"
  292. (const org-agenda-start-day)
  293. (string :value "2007-11-01"))
  294. (list :tag "Start on day of week"
  295. (const org-agenda-start-on-weekday)
  296. (choice :value 1
  297. (const :tag "Today" nil)
  298. (integer :tag "Weekday No.")))
  299. (list :tag "Include data from diary"
  300. (const org-agenda-include-diary)
  301. (boolean))
  302. (list :tag "Deadline Warning days"
  303. (const org-deadline-warning-days)
  304. (integer :value 1))
  305. (list :tag "Category filter preset"
  306. (const org-agenda-category-filter-preset)
  307. (list
  308. (const :format "" quote)
  309. (repeat
  310. (string :tag "+category or -category"))))
  311. (list :tag "Tags filter preset"
  312. (const org-agenda-tag-filter-preset)
  313. (list
  314. (const :format "" quote)
  315. (repeat
  316. (string :tag "+tag or -tag"))))
  317. (list :tag "Regexp filter preset"
  318. (const org-agenda-regexp-filter-preset)
  319. (list
  320. (const :format "" quote)
  321. (repeat
  322. (string :tag "+regexp or -regexp"))))
  323. (list :tag "Set daily/weekly entry types"
  324. (const org-agenda-entry-types)
  325. (list
  326. (const :format "" quote)
  327. (set :greedy t :value ,org-agenda-entry-types
  328. (const :deadline)
  329. (const :scheduled)
  330. (const :deadline*)
  331. (const :scheduled*)
  332. (const :timestamp)
  333. (const :sexp))))
  334. (list :tag "Standard skipping condition"
  335. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  336. (const org-agenda-skip-function)
  337. (list
  338. (const :format "" quote)
  339. (list
  340. (choice
  341. :tag "Skipping range"
  342. (const :tag "Skip entry" org-agenda-skip-entry-if)
  343. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  344. (repeat :inline t :tag "Conditions for skipping"
  345. (choice
  346. :tag "Condition type"
  347. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  348. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  349. (list :tag "TODO state is" :inline t
  350. (const 'todo)
  351. (choice
  352. (const :tag "any not-done state" 'todo)
  353. (const :tag "any done state" 'done)
  354. (const :tag "any state" 'any)
  355. (list :tag "Keyword list"
  356. (const :format "" quote)
  357. (repeat (string :tag "Keyword")))))
  358. (list :tag "TODO state is not" :inline t
  359. (const 'nottodo)
  360. (choice
  361. (const :tag "any not-done state" 'todo)
  362. (const :tag "any done state" 'done)
  363. (const :tag "any state" 'any)
  364. (list :tag "Keyword list"
  365. (const :format "" quote)
  366. (repeat (string :tag "Keyword")))))
  367. (const :tag "scheduled" 'scheduled)
  368. (const :tag "not scheduled" 'notscheduled)
  369. (const :tag "deadline" 'deadline)
  370. (const :tag "no deadline" 'notdeadline)
  371. (const :tag "timestamp" 'timestamp)
  372. (const :tag "no timestamp" 'nottimestamp))))))
  373. (list :tag "Non-standard skipping condition"
  374. :value (org-agenda-skip-function)
  375. (const org-agenda-skip-function)
  376. (sexp :tag "Function or form (quoted!)"))
  377. (list :tag "Any variable"
  378. (variable :tag "Variable")
  379. (sexp :tag "Value (sexp)"))))
  380. "Selection of examples for agenda command settings.
  381. This will be spliced into the custom type of
  382. `org-agenda-custom-commands'.")
  383. (defcustom org-agenda-custom-commands
  384. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  385. "Custom commands for the agenda.
  386. These commands will be offered on the splash screen displayed by the
  387. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  388. (key desc type match settings files)
  389. key The key (one or more characters as a string) to be associated
  390. with the command.
  391. desc A description of the command, when omitted or nil, a default
  392. description is built using MATCH.
  393. type The command type, any of the following symbols:
  394. agenda The daily/weekly agenda.
  395. todo Entries with a specific TODO keyword, in all agenda files.
  396. search Entries containing search words entry or headline.
  397. tags Tags/Property/TODO match in all agenda files.
  398. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  399. todo-tree Sparse tree of specific TODO keyword in *current* file.
  400. tags-tree Sparse tree with all tags matches in *current* file.
  401. occur-tree Occur sparse tree for *current* file.
  402. ... A user-defined function.
  403. match What to search for:
  404. - a single keyword for TODO keyword searches
  405. - a tags match expression for tags searches
  406. - a word search expression for text searches.
  407. - a regular expression for occur searches
  408. For all other commands, this should be the empty string.
  409. settings A list of option settings, similar to that in a let form, so like
  410. this: ((opt1 val1) (opt2 val2) ...). The values will be
  411. evaluated at the moment of execution, so quote them when needed.
  412. files A list of files file to write the produced agenda buffer to
  413. with the command `org-store-agenda-views'.
  414. If a file name ends in \".html\", an HTML version of the buffer
  415. is written out. If it ends in \".ps\", a postscript version is
  416. produced. Otherwise, only the plain text is written to the file.
  417. You can also define a set of commands, to create a composite agenda buffer.
  418. In this case, an entry looks like this:
  419. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  420. where
  421. desc A description string to be displayed in the dispatcher menu.
  422. cmd An agenda command, similar to the above. However, tree commands
  423. are not allowed, but instead you can get agenda and global todo list.
  424. So valid commands for a set are:
  425. (agenda \"\" settings)
  426. (alltodo \"\" settings)
  427. (stuck \"\" settings)
  428. (todo \"match\" settings files)
  429. (search \"match\" settings files)
  430. (tags \"match\" settings files)
  431. (tags-todo \"match\" settings files)
  432. Each command can carry a list of options, and another set of options can be
  433. given for the whole set of commands. Individual command options take
  434. precedence over the general options.
  435. When using several characters as key to a command, the first characters
  436. are prefix commands. For the dispatcher to display useful information, you
  437. should provide a description for the prefix, like
  438. (setq org-agenda-custom-commands
  439. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  440. (\"hl\" tags \"+HOME+Lisa\")
  441. (\"hp\" tags \"+HOME+Peter\")
  442. (\"hk\" tags \"+HOME+Kim\")))"
  443. :group 'org-agenda-custom-commands
  444. :type `(repeat
  445. (choice :value ("x" "Describe command here" tags "" nil)
  446. (list :tag "Single command"
  447. (string :tag "Access Key(s) ")
  448. (option (string :tag "Description"))
  449. (choice
  450. (const :tag "Agenda" agenda)
  451. (const :tag "TODO list" alltodo)
  452. (const :tag "Search words" search)
  453. (const :tag "Stuck projects" stuck)
  454. (const :tag "Tags/Property match (all agenda files)" tags)
  455. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  456. (const :tag "TODO keyword search (all agenda files)" todo)
  457. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  458. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  459. (const :tag "Occur tree (current buffer)" occur-tree)
  460. (sexp :tag "Other, user-defined function"))
  461. (string :tag "Match (only for some commands)")
  462. ,org-agenda-custom-commands-local-options
  463. (option (repeat :tag "Export" (file :tag "Export to"))))
  464. (list :tag "Command series, all agenda files"
  465. (string :tag "Access Key(s)")
  466. (string :tag "Description ")
  467. (repeat :tag "Component"
  468. (choice
  469. (list :tag "Agenda"
  470. (const :format "" agenda)
  471. (const :tag "" :format "" "")
  472. ,org-agenda-custom-commands-local-options)
  473. (list :tag "TODO list (all keywords)"
  474. (const :format "" alltodo)
  475. (const :tag "" :format "" "")
  476. ,org-agenda-custom-commands-local-options)
  477. (list :tag "Search words"
  478. (const :format "" search)
  479. (string :tag "Match")
  480. ,org-agenda-custom-commands-local-options)
  481. (list :tag "Stuck projects"
  482. (const :format "" stuck)
  483. (const :tag "" :format "" "")
  484. ,org-agenda-custom-commands-local-options)
  485. (list :tag "Tags search"
  486. (const :format "" tags)
  487. (string :tag "Match")
  488. ,org-agenda-custom-commands-local-options)
  489. (list :tag "Tags search, TODO entries only"
  490. (const :format "" tags-todo)
  491. (string :tag "Match")
  492. ,org-agenda-custom-commands-local-options)
  493. (list :tag "TODO keyword search"
  494. (const :format "" todo)
  495. (string :tag "Match")
  496. ,org-agenda-custom-commands-local-options)
  497. (list :tag "Other, user-defined function"
  498. (symbol :tag "function")
  499. (string :tag "Match")
  500. ,org-agenda-custom-commands-local-options)))
  501. (repeat :tag "Settings for entire command set"
  502. (list (variable :tag "Any variable")
  503. (sexp :tag "Value")))
  504. (option (repeat :tag "Export" (file :tag "Export to"))))
  505. (cons :tag "Prefix key documentation"
  506. (string :tag "Access Key(s)")
  507. (string :tag "Description ")))))
  508. (defcustom org-agenda-query-register ?o
  509. "The register holding the current query string.
  510. The purpose of this is that if you construct a query string interactively,
  511. you can then use it to define a custom command."
  512. :group 'org-agenda-custom-commands
  513. :type 'character)
  514. (defcustom org-stuck-projects
  515. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  516. "How to identify stuck projects.
  517. This is a list of four items:
  518. 1. A tags/todo/property matcher string that is used to identify a project.
  519. See the manual for a description of tag and property searches.
  520. The entire tree below a headline matched by this is considered one project.
  521. 2. A list of TODO keywords identifying non-stuck projects.
  522. If the project subtree contains any headline with one of these todo
  523. keywords, the project is considered to be not stuck. If you specify
  524. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  525. 3. A list of tags identifying non-stuck projects.
  526. If the project subtree contains any headline with one of these tags,
  527. the project is considered to be not stuck. If you specify \"*\" as
  528. a tag, any tag will mark the project unstuck. Note that this is about
  529. the explicit presence of a tag somewhere in the subtree, inherited
  530. tags do not count here. If inherited tags make a project not stuck,
  531. use \"-TAG\" in the tags part of the matcher under (1.) above.
  532. 4. An arbitrary regular expression matching non-stuck projects.
  533. If the project turns out to be not stuck, search continues also in the
  534. subtree to see if any of the subtasks have project status.
  535. See also the variable `org-tags-match-list-sublevels' which applies
  536. to projects matched by this search as well.
  537. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  538. or `C-c a #' to produce the list."
  539. :group 'org-agenda-custom-commands
  540. :type '(list
  541. (string :tag "Tags/TODO match to identify a project")
  542. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  543. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  544. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  545. (defcustom org-agenda-filter-effort-default-operator "<"
  546. "The default operator for effort estimate filtering.
  547. If you select an effort estimate limit without first pressing an operator,
  548. this one will be used."
  549. :group 'org-agenda-custom-commands
  550. :type '(choice (const :tag "less or equal" "<")
  551. (const :tag "greater or equal"">")
  552. (const :tag "equal" "=")))
  553. (defgroup org-agenda-skip nil
  554. "Options concerning skipping parts of agenda files."
  555. :tag "Org Agenda Skip"
  556. :group 'org-agenda)
  557. (defcustom org-agenda-skip-function-global nil
  558. "Function to be called at each match during agenda construction.
  559. If this function returns nil, the current match should not be skipped.
  560. If the function decided to skip an agenda match, is must return the
  561. buffer position from which the search should be continued.
  562. This may also be a Lisp form, which will be evaluated.
  563. This variable will be applied to every agenda match, including
  564. tags/property searches and TODO lists. So try to make the test function
  565. do its checking as efficiently as possible. To implement a skipping
  566. condition just for specific agenda commands, use the variable
  567. `org-agenda-skip-function' which can be set in the options section
  568. of custom agenda commands."
  569. :group 'org-agenda-skip
  570. :type 'sexp)
  571. (defgroup org-agenda-daily/weekly nil
  572. "Options concerning the daily/weekly agenda."
  573. :tag "Org Agenda Daily/Weekly"
  574. :group 'org-agenda)
  575. (defgroup org-agenda-todo-list nil
  576. "Options concerning the global todo list agenda view."
  577. :tag "Org Agenda Todo List"
  578. :group 'org-agenda)
  579. (defgroup org-agenda-match-view nil
  580. "Options concerning the general tags/property/todo match agenda view."
  581. :tag "Org Agenda Match View"
  582. :group 'org-agenda)
  583. (defgroup org-agenda-search-view nil
  584. "Options concerning the general tags/property/todo match agenda view."
  585. :tag "Org Agenda Match View"
  586. :group 'org-agenda)
  587. (defvar org-agenda-archives-mode nil
  588. "Non-nil means the agenda will include archived items.
  589. If this is the symbol `trees', trees in the selected agenda scope
  590. that are marked with the ARCHIVE tag will be included anyway. When this is
  591. t, also all archive files associated with the current selection of agenda
  592. files will be included.")
  593. (defcustom org-agenda-restriction-lock-highlight-subtree t
  594. "Non-nil means highlight the whole subtree when restriction is active.
  595. Otherwise only highlight the headline. Highlighting the whole subtree is
  596. useful to ensure no edits happen beyond the restricted region."
  597. :group 'org-agenda
  598. :type 'boolean)
  599. (defcustom org-agenda-skip-comment-trees t
  600. "Non-nil means skip trees that start with the COMMENT keyword.
  601. When nil, these trees are also scanned by agenda commands."
  602. :group 'org-agenda-skip
  603. :type 'boolean)
  604. (defcustom org-agenda-todo-list-sublevels t
  605. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  606. When nil, the sublevels of a TODO entry are not checked, resulting in
  607. potentially much shorter TODO lists."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-todo-list
  610. :type 'boolean)
  611. (defcustom org-agenda-todo-ignore-with-date nil
  612. "Non-nil means don't show entries with a date in the global todo list.
  613. You can use this if you prefer to mark mere appointments with a TODO keyword,
  614. but don't want them to show up in the TODO list.
  615. When this is set, it also covers deadlines and scheduled items, the settings
  616. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  617. will be ignored.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  619. :group 'org-agenda-skip
  620. :group 'org-agenda-todo-list
  621. :type 'boolean)
  622. (defcustom org-agenda-todo-ignore-timestamp nil
  623. "Non-nil means don't show entries with a timestamp.
  624. This applies when creating the global todo list.
  625. Valid values are:
  626. past Don't show entries for today or in the past.
  627. future Don't show entries with a timestamp in the future.
  628. The idea behind this is that if it has a future
  629. timestamp, you don't want to think about it until the
  630. date.
  631. all Don't show any entries with a timestamp in the global todo list.
  632. The idea behind this is that by setting a timestamp, you
  633. have already \"taken care\" of this item.
  634. This variable can also have an integer as a value. If positive (N),
  635. todos with a timestamp N or more days in the future will be ignored. If
  636. negative (-N), todos with a timestamp N or more days in the past will be
  637. ignored. If 0, todos with a timestamp either today or in the future will
  638. be ignored. For example, a value of -1 will exclude todos with a
  639. timestamp in the past (yesterday or earlier), while a value of 7 will
  640. exclude todos with a timestamp a week or more in the future.
  641. See also `org-agenda-todo-ignore-with-date'.
  642. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  643. to make his option also apply to the tags-todo list."
  644. :group 'org-agenda-skip
  645. :group 'org-agenda-todo-list
  646. :version "24.1"
  647. :type '(choice
  648. (const :tag "Ignore future timestamp todos" future)
  649. (const :tag "Ignore past or present timestamp todos" past)
  650. (const :tag "Ignore all timestamp todos" all)
  651. (const :tag "Show timestamp todos" nil)
  652. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  653. (defcustom org-agenda-todo-ignore-scheduled nil
  654. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  655. This applies when creating the global todo list.
  656. Valid values are:
  657. past Don't show entries scheduled today or in the past.
  658. future Don't show entries scheduled in the future.
  659. The idea behind this is that by scheduling it, you don't want to
  660. think about it until the scheduled date.
  661. all Don't show any scheduled entries in the global todo list.
  662. The idea behind this is that by scheduling it, you have already
  663. \"taken care\" of this item.
  664. t Same as `all', for backward compatibility.
  665. This variable can also have an integer as a value. See
  666. `org-agenda-todo-ignore-timestamp' for more details.
  667. See also `org-agenda-todo-ignore-with-date'.
  668. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  669. to make his option also apply to the tags-todo list."
  670. :group 'org-agenda-skip
  671. :group 'org-agenda-todo-list
  672. :type '(choice
  673. (const :tag "Ignore future-scheduled todos" future)
  674. (const :tag "Ignore past- or present-scheduled todos" past)
  675. (const :tag "Ignore all scheduled todos" all)
  676. (const :tag "Ignore all scheduled todos (compatibility)" t)
  677. (const :tag "Show scheduled todos" nil)
  678. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  679. (defcustom org-agenda-todo-ignore-deadlines nil
  680. "Non-nil means ignore some deadlined TODO items when making TODO list.
  681. There are different motivations for using different values, please think
  682. carefully when configuring this variable.
  683. This applies when creating the global todo list.
  684. Valid values are:
  685. near Don't show near deadline entries. A deadline is near when it is
  686. closer than `org-deadline-warning-days' days. The idea behind this
  687. is that such items will appear in the agenda anyway.
  688. far Don't show TODO entries where a deadline has been defined, but
  689. the deadline is not near. This is useful if you don't want to
  690. use the todo list to figure out what to do now.
  691. past Don't show entries with a deadline timestamp for today or in the past.
  692. future Don't show entries with a deadline timestamp in the future, not even
  693. when they become `near' ones. Use it with caution.
  694. all Ignore all TODO entries that do have a deadline.
  695. t Same as `near', for backward compatibility.
  696. This variable can also have an integer as a value. See
  697. `org-agenda-todo-ignore-timestamp' for more details.
  698. See also `org-agenda-todo-ignore-with-date'.
  699. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  700. to make his option also apply to the tags-todo list."
  701. :group 'org-agenda-skip
  702. :group 'org-agenda-todo-list
  703. :type '(choice
  704. (const :tag "Ignore near deadlines" near)
  705. (const :tag "Ignore near deadlines (compatibility)" t)
  706. (const :tag "Ignore far deadlines" far)
  707. (const :tag "Ignore all TODOs with a deadlines" all)
  708. (const :tag "Show all TODOs, even if they have a deadline" nil)
  709. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  710. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  711. "Time unit to use when possibly ignoring an agenda item.
  712. See the docstring of various `org-agenda-todo-ignore-*' options.
  713. The default is to compare time stamps using days. An item is thus
  714. considered to be in the future if it is at least one day after today.
  715. Non-nil means to compare time stamps using seconds. An item is then
  716. considered future if it has a time value later than current time."
  717. :group 'org-agenda-skip
  718. :group 'org-agenda-todo-list
  719. :version "24.4"
  720. :package-version '(Org . "8.0")
  721. :type '(choice
  722. (const :tag "Compare time with days" nil)
  723. (const :tag "Compare time with seconds" t)))
  724. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  725. "Non-nil means honor todo-list ignores options also in tags-todo search.
  726. The variables
  727. `org-agenda-todo-ignore-with-date',
  728. `org-agenda-todo-ignore-timestamp',
  729. `org-agenda-todo-ignore-scheduled',
  730. `org-agenda-todo-ignore-deadlines'
  731. make the global TODO list skip entries that have time stamps of certain
  732. kinds. If this option is set, the same options will also apply for the
  733. tags-todo search, which is the general tags/property matcher
  734. restricted to unfinished TODO entries only."
  735. :group 'org-agenda-skip
  736. :group 'org-agenda-todo-list
  737. :group 'org-agenda-match-view
  738. :type 'boolean)
  739. (defcustom org-agenda-skip-scheduled-if-done nil
  740. "Non-nil means don't show scheduled items in agenda when they are done.
  741. This is relevant for the daily/weekly agenda, not for the TODO list. And
  742. it applies only to the actual date of the scheduling. Warnings about
  743. an item with a past scheduling dates are always turned off when the item
  744. is DONE."
  745. :group 'org-agenda-skip
  746. :group 'org-agenda-daily/weekly
  747. :type 'boolean)
  748. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  749. "Non-nil means skip scheduling line if same entry shows because of deadline.
  750. In the agenda of today, an entry can show up multiple times
  751. because it is both scheduled and has a nearby deadline, and maybe
  752. a plain time stamp as well.
  753. When this variable is nil, the entry will be shown several times.
  754. When set to t, then only the deadline is shown and the fact that
  755. the entry is scheduled today or was scheduled previously is not
  756. shown.
  757. When set to the symbol `not-today', skip scheduled previously,
  758. but not scheduled today.
  759. When set to the symbol `repeated-after-deadline', skip scheduled
  760. items if they are repeated beyond the current dealine."
  761. :group 'org-agenda-skip
  762. :group 'org-agenda-daily/weekly
  763. :type '(choice
  764. (const :tag "Never" nil)
  765. (const :tag "Always" t)
  766. (const :tag "Not when scheduled today" not-today)
  767. (const :tag "When repeated past deadline" repeated-after-deadline)))
  768. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  769. "Non-nil means skip timestamp line if same entry shows because of deadline.
  770. In the agenda of today, an entry can show up multiple times
  771. because it has both a plain timestamp and has a nearby deadline.
  772. When this variable is t, then only the deadline is shown and the
  773. fact that the entry has a timestamp for or including today is not
  774. shown. When this variable is nil, the entry will be shown
  775. several times."
  776. :group 'org-agenda-skip
  777. :group 'org-agenda-daily/weekly
  778. :version "24.1"
  779. :type '(choice
  780. (const :tag "Never" nil)
  781. (const :tag "Always" t)))
  782. (defcustom org-agenda-skip-deadline-if-done nil
  783. "Non-nil means don't show deadlines when the corresponding item is done.
  784. When nil, the deadline is still shown and should give you a happy feeling.
  785. This is relevant for the daily/weekly agenda. And it applied only to the
  786. actually date of the deadline. Warnings about approaching and past-due
  787. deadlines are always turned off when the item is DONE."
  788. :group 'org-agenda-skip
  789. :group 'org-agenda-daily/weekly
  790. :type 'boolean)
  791. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  792. "Non-nil means skip deadline prewarning when entry is also scheduled.
  793. This will apply on all days where a prewarning for the deadline would
  794. be shown, but not at the day when the entry is actually due. On that day,
  795. the deadline will be shown anyway.
  796. This variable may be set to nil, t, the symbol `pre-scheduled',
  797. or a number which will then give the number of days before the actual
  798. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  799. eliminates the deadline prewarning only prior to the scheduled date.
  800. This can be used in a workflow where the first showing of the deadline will
  801. trigger you to schedule it, and then you don't want to be reminded of it
  802. because you will take care of it on the day when scheduled."
  803. :group 'org-agenda-skip
  804. :group 'org-agenda-daily/weekly
  805. :version "24.1"
  806. :type '(choice
  807. (const :tag "Always show prewarning" nil)
  808. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  809. (const :tag "Remove prewarning if entry is scheduled" t)
  810. (integer :tag "Restart prewarning N days before deadline")))
  811. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  812. "Non-nil means skip scheduled delay when entry also has a deadline.
  813. This variable may be set to nil, t, the symbol `post-deadline',
  814. or a number which will then give the number of days after the actual
  815. scheduled date when the delay should expire. The symbol `post-deadline'
  816. eliminates the schedule delay when the date is posterior to the deadline."
  817. :group 'org-agenda-skip
  818. :group 'org-agenda-daily/weekly
  819. :version "24.4"
  820. :package-version '(Org . "8.0")
  821. :type '(choice
  822. (const :tag "Always honor delay" nil)
  823. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  824. (const :tag "Ignore delay if entry has a deadline" t)
  825. (integer :tag "Honor delay up until N days after the scheduled date")))
  826. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  827. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  828. When non-nil, after the search for timestamps has matched once in an
  829. entry, the rest of the entry will not be searched."
  830. :group 'org-agenda-skip
  831. :type 'boolean)
  832. (defcustom org-agenda-skip-timestamp-if-done nil
  833. "Non-nil means don't select item by timestamp or -range if it is DONE."
  834. :group 'org-agenda-skip
  835. :group 'org-agenda-daily/weekly
  836. :type 'boolean)
  837. (defcustom org-agenda-dim-blocked-tasks t
  838. "Non-nil means dim blocked tasks in the agenda display.
  839. This causes some overhead during agenda construction, but if you
  840. have turned on `org-enforce-todo-dependencies',
  841. `org-enforce-todo-checkbox-dependencies', or any other blocking
  842. mechanism, this will create useful feedback in the agenda.
  843. Instead of t, this variable can also have the value `invisible'.
  844. Then blocked tasks will be invisible and only become visible when
  845. they become unblocked. An exemption to this behavior is when a task is
  846. blocked because of unchecked checkboxes below it. Since checkboxes do
  847. not show up in the agenda views, making this task invisible you remove any
  848. trace from agenda views that there is something to do. Therefore, a task
  849. that is blocked because of checkboxes will never be made invisible, it
  850. will only be dimmed."
  851. :group 'org-agenda-daily/weekly
  852. :group 'org-agenda-todo-list
  853. :version "24.3"
  854. :type '(choice
  855. (const :tag "Do not dim" nil)
  856. (const :tag "Dim to a gray face" t)
  857. (const :tag "Make invisible" invisible)))
  858. (defcustom org-timeline-show-empty-dates 3
  859. "Non-nil means `org-timeline' also shows dates without an entry.
  860. When nil, only the days which actually have entries are shown.
  861. When t, all days between the first and the last date are shown.
  862. When an integer, show also empty dates, but if there is a gap of more than
  863. N days, just insert a special line indicating the size of the gap."
  864. :group 'org-agenda-skip
  865. :type '(choice
  866. (const :tag "None" nil)
  867. (const :tag "All" t)
  868. (integer :tag "at most")))
  869. (defgroup org-agenda-startup nil
  870. "Options concerning initial settings in the Agenda in Org Mode."
  871. :tag "Org Agenda Startup"
  872. :group 'org-agenda)
  873. (defcustom org-agenda-menu-show-matcher t
  874. "Non-nil means show the match string in the agenda dispatcher menu.
  875. When nil, the matcher string is not shown, but is put into the help-echo
  876. property so than moving the mouse over the command shows it.
  877. Setting it to nil is good if matcher strings are very long and/or if
  878. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  879. :group 'org-agenda
  880. :version "24.1"
  881. :type 'boolean)
  882. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  883. (defcustom org-agenda-menu-two-columns nil
  884. "Non-nil means, use two columns to show custom commands in the dispatcher.
  885. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  886. to nil."
  887. :group 'org-agenda
  888. :version "24.1"
  889. :type 'boolean)
  890. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  891. (defcustom org-agenda-finalize-hook nil
  892. "Hook run just before displaying an agenda buffer.
  893. The buffer is still writable when the hook is called.
  894. You can modify some of the buffer substrings but you should be
  895. extra careful not to modify the text properties of the agenda
  896. headlines as the agenda display heavily relies on them."
  897. :group 'org-agenda-startup
  898. :type 'hook)
  899. (defcustom org-agenda-mouse-1-follows-link nil
  900. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  901. A longer mouse click will still set point. Does not work on XEmacs.
  902. Needs to be set before org.el is loaded."
  903. :group 'org-agenda-startup
  904. :type 'boolean)
  905. (defcustom org-agenda-start-with-follow-mode nil
  906. "The initial value of follow mode in a newly created agenda window."
  907. :group 'org-agenda-startup
  908. :type 'boolean)
  909. (defcustom org-agenda-follow-indirect nil
  910. "Non-nil means `org-agenda-follow-mode' displays only the
  911. current item's tree, in an indirect buffer."
  912. :group 'org-agenda
  913. :version "24.1"
  914. :type 'boolean)
  915. (defcustom org-agenda-show-outline-path t
  916. "Non-nil means show outline path in echo area after line motion."
  917. :group 'org-agenda-startup
  918. :type 'boolean)
  919. (defcustom org-agenda-start-with-entry-text-mode nil
  920. "The initial value of entry-text-mode in a newly created agenda window."
  921. :group 'org-agenda-startup
  922. :type 'boolean)
  923. (defcustom org-agenda-entry-text-maxlines 5
  924. "Number of text lines to be added when `E' is pressed in the agenda.
  925. Note that this variable only used during agenda display. Add add entry text
  926. when exporting the agenda, configure the variable
  927. `org-agenda-add-entry-ext-maxlines'."
  928. :group 'org-agenda
  929. :type 'integer)
  930. (defcustom org-agenda-entry-text-exclude-regexps nil
  931. "List of regular expressions to clean up entry text.
  932. The complete matches of all regular expressions in this list will be
  933. removed from entry text before it is shown in the agenda."
  934. :group 'org-agenda
  935. :type '(repeat (regexp)))
  936. (defcustom org-agenda-entry-text-leaders " > "
  937. "Text prepended to the entry text in agenda buffers."
  938. :version "24.4"
  939. :package-version '(Org . "8.0")
  940. :group 'org-agenda
  941. :type 'string)
  942. (defvar org-agenda-entry-text-cleanup-hook nil
  943. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  944. This cleanup is done in a temporary buffer, so the function may inspect and
  945. change the entire buffer.
  946. Some default stuff like drawers and scheduling/deadline dates will already
  947. have been removed when this is called, as will any matches for regular
  948. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  949. (defvar org-agenda-include-inactive-timestamps nil
  950. "Non-nil means include inactive time stamps in agenda and timeline.
  951. Dynamically scoped.")
  952. (defgroup org-agenda-windows nil
  953. "Options concerning the windows used by the Agenda in Org Mode."
  954. :tag "Org Agenda Windows"
  955. :group 'org-agenda)
  956. (defcustom org-agenda-window-setup 'reorganize-frame
  957. "How the agenda buffer should be displayed.
  958. Possible values for this option are:
  959. current-window Show agenda in the current window, keeping all other windows.
  960. other-window Use `switch-to-buffer-other-window' to display agenda.
  961. reorganize-frame Show only two windows on the current frame, the current
  962. window and the agenda.
  963. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  964. Also, when exiting the agenda, kill that frame.
  965. See also the variable `org-agenda-restore-windows-after-quit'."
  966. :group 'org-agenda-windows
  967. :type '(choice
  968. (const current-window)
  969. (const other-frame)
  970. (const other-window)
  971. (const reorganize-frame)))
  972. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  973. "The min and max height of the agenda window as a fraction of frame height.
  974. The value of the variable is a cons cell with two numbers between 0 and 1.
  975. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  976. :group 'org-agenda-windows
  977. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  978. (defcustom org-agenda-restore-windows-after-quit nil
  979. "Non-nil means restore window configuration upon exiting agenda.
  980. Before the window configuration is changed for displaying the agenda,
  981. the current status is recorded. When the agenda is exited with
  982. `q' or `x' and this option is set, the old state is restored. If
  983. `org-agenda-window-setup' is `other-frame', the value of this
  984. option will be ignored."
  985. :group 'org-agenda-windows
  986. :type 'boolean)
  987. (defcustom org-agenda-ndays nil
  988. "Number of days to include in overview display.
  989. Should be 1 or 7.
  990. Obsolete, see `org-agenda-span'."
  991. :group 'org-agenda-daily/weekly
  992. :type 'integer)
  993. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  994. (defcustom org-agenda-span 'week
  995. "Number of days to include in overview display.
  996. Can be day, week, month, year, or any number of days.
  997. Custom commands can set this variable in the options section."
  998. :group 'org-agenda-daily/weekly
  999. :type '(choice (const :tag "Day" day)
  1000. (const :tag "Week" week)
  1001. (const :tag "Month" month)
  1002. (const :tag "Year" year)
  1003. (integer :tag "Custom")))
  1004. (defcustom org-agenda-start-on-weekday 1
  1005. "Non-nil means start the overview always on the specified weekday.
  1006. 0 denotes Sunday, 1 denotes Monday, etc.
  1007. When nil, always start on the current day.
  1008. Custom commands can set this variable in the options section."
  1009. :group 'org-agenda-daily/weekly
  1010. :type '(choice (const :tag "Today" nil)
  1011. (integer :tag "Weekday No.")))
  1012. (defcustom org-agenda-show-all-dates t
  1013. "Non-nil means `org-agenda' shows every day in the selected range.
  1014. When nil, only the days which actually have entries are shown."
  1015. :group 'org-agenda-daily/weekly
  1016. :type 'boolean)
  1017. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1018. "Format string for displaying dates in the agenda.
  1019. Used by the daily/weekly agenda and by the timeline. This should be
  1020. a format string understood by `format-time-string', or a function returning
  1021. the formatted date as a string. The function must take a single argument,
  1022. a calendar-style date list like (month day year)."
  1023. :group 'org-agenda-daily/weekly
  1024. :type '(choice
  1025. (string :tag "Format string")
  1026. (function :tag "Function")))
  1027. (defun org-agenda-format-date-aligned (date)
  1028. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1029. This function makes sure that dates are aligned for easy reading."
  1030. (require 'cal-iso)
  1031. (let* ((dayname (calendar-day-name date))
  1032. (day (cadr date))
  1033. (day-of-week (calendar-day-of-week date))
  1034. (month (car date))
  1035. (monthname (calendar-month-name month))
  1036. (year (nth 2 date))
  1037. (iso-week (org-days-to-iso-week
  1038. (calendar-absolute-from-gregorian date)))
  1039. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1040. (1- year))
  1041. ((and (= month 12) (<= iso-week 1))
  1042. (1+ year))
  1043. (t year)))
  1044. (weekstring (if (= day-of-week 1)
  1045. (format " W%02d" iso-week)
  1046. "")))
  1047. (format "%-10s %2d %s %4d%s"
  1048. dayname day monthname year weekstring)))
  1049. (defcustom org-agenda-time-leading-zero nil
  1050. "Non-nil means use leading zero for military times in agenda.
  1051. For example, 9:30am would become 09:30 rather than 9:30."
  1052. :group 'org-agenda-daily/weekly
  1053. :version "24.1"
  1054. :type 'boolean)
  1055. (defcustom org-agenda-timegrid-use-ampm nil
  1056. "When set, show AM/PM style timestamps on the timegrid."
  1057. :group 'org-agenda
  1058. :version "24.1"
  1059. :type 'boolean)
  1060. (defun org-agenda-time-of-day-to-ampm (time)
  1061. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1062. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1063. (minute (substring time -2))
  1064. (ampm "am"))
  1065. (cond
  1066. ((equal hour-number 12)
  1067. (setq ampm "pm"))
  1068. ((> hour-number 12)
  1069. (setq ampm "pm")
  1070. (setq hour-number (- hour-number 12))))
  1071. (concat
  1072. (if org-agenda-time-leading-zero
  1073. (format "%02d" hour-number)
  1074. (format "%02s" (number-to-string hour-number)))
  1075. ":" minute ampm)))
  1076. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1077. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1078. (if org-agenda-timegrid-use-ampm
  1079. (org-agenda-time-of-day-to-ampm time)
  1080. time))
  1081. (defcustom org-agenda-weekend-days '(6 0)
  1082. "Which days are weekend?
  1083. These days get the special face `org-agenda-date-weekend' in the agenda
  1084. and timeline buffers."
  1085. :group 'org-agenda-daily/weekly
  1086. :type '(set :greedy t
  1087. (const :tag "Monday" 1)
  1088. (const :tag "Tuesday" 2)
  1089. (const :tag "Wednesday" 3)
  1090. (const :tag "Thursday" 4)
  1091. (const :tag "Friday" 5)
  1092. (const :tag "Saturday" 6)
  1093. (const :tag "Sunday" 0)))
  1094. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1095. "Non-nil means jump to today when moving a past date forward in time.
  1096. When using S-right in the agenda to move a a date forward, and the date
  1097. stamp currently points to the past, the first key press will move it
  1098. to today. WHen nil, just move one day forward even if the date stays
  1099. in the past."
  1100. :group 'org-agenda-daily/weekly
  1101. :version "24.1"
  1102. :type 'boolean)
  1103. (defcustom org-agenda-include-diary nil
  1104. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1105. Custom commands can set this variable in the options section."
  1106. :group 'org-agenda-daily/weekly
  1107. :type 'boolean)
  1108. (defcustom org-agenda-include-deadlines t
  1109. "If non-nil, include entries within their deadline warning period.
  1110. Custom commands can set this variable in the options section."
  1111. :group 'org-agenda-daily/weekly
  1112. :version "24.1"
  1113. :type 'boolean)
  1114. (defcustom org-agenda-repeating-timestamp-show-all t
  1115. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1116. When set to a list of strings, only show occurrences of repeating
  1117. stamps for these TODO keywords. When nil, only one occurrence is
  1118. shown, either today or the nearest into the future."
  1119. :group 'org-agenda-daily/weekly
  1120. :type '(choice
  1121. (const :tag "Show repeating stamps" t)
  1122. (repeat :tag "Show repeating stamps for these TODO keywords"
  1123. (string :tag "TODO Keyword"))
  1124. (const :tag "Don't show repeating stamps" nil)))
  1125. (defcustom org-scheduled-past-days 10000
  1126. "Number of days to continue listing scheduled items not marked DONE.
  1127. When an item is scheduled on a date, it shows up in the agenda on this
  1128. day and will be listed until it is marked done for the number of days
  1129. given here."
  1130. :group 'org-agenda-daily/weekly
  1131. :type 'integer)
  1132. (defcustom org-agenda-log-mode-items '(closed clock)
  1133. "List of items that should be shown in agenda log mode.
  1134. This list may contain the following symbols:
  1135. closed Show entries that have been closed on that day.
  1136. clock Show entries that have received clocked time on that day.
  1137. state Show all logged state changes.
  1138. Note that instead of changing this variable, you can also press `C-u l' in
  1139. the agenda to display all available LOG items temporarily."
  1140. :group 'org-agenda-daily/weekly
  1141. :type '(set :greedy t (const closed) (const clock) (const state)))
  1142. (defcustom org-agenda-clock-consistency-checks
  1143. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1144. :gap-ok-around ("4:00")
  1145. :default-face ((:background "DarkRed") (:foreground "white"))
  1146. :overlap-face nil :gap-face nil :no-end-time-face nil
  1147. :long-face nil :short-face nil)
  1148. "This is a property list, with the following keys:
  1149. :max-duration Mark clocking chunks that are longer than this time.
  1150. This is a time string like \"HH:MM\", or the number
  1151. of minutes as an integer.
  1152. :min-duration Mark clocking chunks that are shorter that this.
  1153. This is a time string like \"HH:MM\", or the number
  1154. of minutes as an integer.
  1155. :max-gap Mark gaps between clocking chunks that are longer than
  1156. this duration. A number of minutes, or a string
  1157. like \"HH:MM\".
  1158. :gap-ok-around List of times during the day which are usually not working
  1159. times. When a gap is detected, but the gap contains any
  1160. of these times, the gap is *not* reported. For example,
  1161. if this is (\"4:00\" \"13:00\") then gaps that contain
  1162. 4:00 in the morning (i.e. the night) and 13:00
  1163. (i.e. a typical lunch time) do not cause a warning.
  1164. You should have at least one time during the night in this
  1165. list, or otherwise the first task each morning will trigger
  1166. a warning because it follows a long gap.
  1167. Furthermore, the following properties can be used to define faces for
  1168. issue display.
  1169. :default-face the default face, if the specific face is undefined
  1170. :overlap-face face for overlapping clocks
  1171. :gap-face face for gaps between clocks
  1172. :no-end-time-face face for incomplete clocks
  1173. :long-face face for clock intervals that are too long
  1174. :short-face face for clock intervals that are too short"
  1175. :group 'org-agenda-daily/weekly
  1176. :group 'org-clock
  1177. :version "24.1"
  1178. :type 'plist)
  1179. (defcustom org-agenda-log-mode-add-notes t
  1180. "Non-nil means add first line of notes to log entries in agenda views.
  1181. If a log item like a state change or a clock entry is associated with
  1182. notes, the first line of these notes will be added to the entry in the
  1183. agenda display."
  1184. :group 'org-agenda-daily/weekly
  1185. :type 'boolean)
  1186. (defcustom org-agenda-start-with-log-mode nil
  1187. "The initial value of log-mode in a newly created agenda window.
  1188. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1189. explanations on the possible values."
  1190. :group 'org-agenda-startup
  1191. :group 'org-agenda-daily/weekly
  1192. :type '(choice (const :tag "Don't show log items" nil)
  1193. (const :tag "Show only log items" 'only)
  1194. (const :tag "Show all possible log items" 'clockcheck)
  1195. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1196. (choice (const :tag "Show closed log items" 'closed)
  1197. (const :tag "Show clocked log items" 'clock)
  1198. (const :tag "Show all logged state changes" 'state)))))
  1199. (defcustom org-agenda-start-with-clockreport-mode nil
  1200. "The initial value of clockreport-mode in a newly created agenda window."
  1201. :group 'org-agenda-startup
  1202. :group 'org-agenda-daily/weekly
  1203. :type 'boolean)
  1204. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1205. "Property list with parameters for the clocktable in clockreport mode.
  1206. This is the display mode that shows a clock table in the daily/weekly
  1207. agenda, the properties for this dynamic block can be set here.
  1208. The usual clocktable parameters are allowed here, but you cannot set
  1209. the properties :name, :tstart, :tend, :block, and :scope - these will
  1210. be overwritten to make sure the content accurately reflects the
  1211. current display in the agenda."
  1212. :group 'org-agenda-daily/weekly
  1213. :type 'plist)
  1214. (defcustom org-agenda-search-view-always-boolean nil
  1215. "Non-nil means the search string is interpreted as individual parts.
  1216. The search string for search view can either be interpreted as a phrase,
  1217. or as a list of snippets that define a boolean search for a number of
  1218. strings.
  1219. When this is non-nil, the string will be split on whitespace, and each
  1220. snippet will be searched individually, and all must match in order to
  1221. select an entry. A snippet is then a single string of non-white
  1222. characters, or a string in double quotes, or a regexp in {} braces.
  1223. If a snippet is preceded by \"-\", the snippet must *not* match.
  1224. \"+\" is syntactic sugar for positive selection. Each snippet may
  1225. be found as a full word or a partial word, but see the variable
  1226. `org-agenda-search-view-force-full-words'.
  1227. When this is nil, search will look for the entire search phrase as one,
  1228. with each space character matching any amount of whitespace, including
  1229. line breaks.
  1230. Even when this is nil, you can still switch to Boolean search dynamically
  1231. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1232. is a regexp marked with braces like \"{abc}\", this will also switch to
  1233. boolean search."
  1234. :group 'org-agenda-search-view
  1235. :version "24.1"
  1236. :type 'boolean)
  1237. (org-defvaralias 'org-agenda-search-view-search-words-only
  1238. 'org-agenda-search-view-always-boolean)
  1239. (defcustom org-agenda-search-view-force-full-words nil
  1240. "Non-nil means, search words must be matches as complete words.
  1241. When nil, they may also match part of a word."
  1242. :group 'org-agenda-search-view
  1243. :version "24.1"
  1244. :type 'boolean)
  1245. (defcustom org-agenda-search-view-max-outline-level nil
  1246. "Maximum outline level to display in search view.
  1247. E.g. when this is set to 1, the search view will only
  1248. show headlines of level 1."
  1249. :group 'org-agenda-search-view
  1250. :version "24.4"
  1251. :package-version '(Org . "8.0")
  1252. :type 'integer)
  1253. (defgroup org-agenda-time-grid nil
  1254. "Options concerning the time grid in the Org-mode Agenda."
  1255. :tag "Org Agenda Time Grid"
  1256. :group 'org-agenda)
  1257. (defcustom org-agenda-search-headline-for-time t
  1258. "Non-nil means search headline for a time-of-day.
  1259. If the headline contains a time-of-day in one format or another, it will
  1260. be used to sort the entry into the time sequence of items for a day.
  1261. Some people have time stamps in the headline that refer to the creation
  1262. time or so, and then this produces an unwanted side effect. If this is
  1263. the case for your, use this variable to turn off searching the headline
  1264. for a time."
  1265. :group 'org-agenda-time-grid
  1266. :type 'boolean)
  1267. (defcustom org-agenda-use-time-grid t
  1268. "Non-nil means show a time grid in the agenda schedule.
  1269. A time grid is a set of lines for specific times (like every two hours between
  1270. 8:00 and 20:00). The items scheduled for a day at specific times are
  1271. sorted in between these lines.
  1272. For details about when the grid will be shown, and what it will look like, see
  1273. the variable `org-agenda-time-grid'."
  1274. :group 'org-agenda-time-grid
  1275. :type 'boolean)
  1276. (defcustom org-agenda-time-grid
  1277. '((daily today require-timed)
  1278. "----------------"
  1279. (800 1000 1200 1400 1600 1800 2000))
  1280. "The settings for time grid for agenda display.
  1281. This is a list of three items. The first item is again a list. It contains
  1282. symbols specifying conditions when the grid should be displayed:
  1283. daily if the agenda shows a single day
  1284. weekly if the agenda shows an entire week
  1285. today show grid on current date, independent of daily/weekly display
  1286. require-timed show grid only if at least one item has a time specification
  1287. The second item is a string which will be placed behind the grid time.
  1288. The third item is a list of integers, indicating the times that should have
  1289. a grid line."
  1290. :group 'org-agenda-time-grid
  1291. :type
  1292. '(list
  1293. (set :greedy t :tag "Grid Display Options"
  1294. (const :tag "Show grid in single day agenda display" daily)
  1295. (const :tag "Show grid in weekly agenda display" weekly)
  1296. (const :tag "Always show grid for today" today)
  1297. (const :tag "Show grid only if any timed entries are present"
  1298. require-timed)
  1299. (const :tag "Skip grid times already present in an entry"
  1300. remove-match))
  1301. (string :tag "Grid String")
  1302. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1303. (defcustom org-agenda-show-current-time-in-grid t
  1304. "Non-nil means show the current time in the time grid."
  1305. :group 'org-agenda-time-grid
  1306. :version "24.1"
  1307. :type 'boolean)
  1308. (defcustom org-agenda-current-time-string
  1309. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1310. "The string for the current time marker in the agenda."
  1311. :group 'org-agenda-time-grid
  1312. :version "24.1"
  1313. :type 'string)
  1314. (defgroup org-agenda-sorting nil
  1315. "Options concerning sorting in the Org-mode Agenda."
  1316. :tag "Org Agenda Sorting"
  1317. :group 'org-agenda)
  1318. (defcustom org-agenda-sorting-strategy
  1319. '((agenda habit-down time-up priority-down category-keep)
  1320. (todo priority-down category-keep)
  1321. (tags priority-down category-keep)
  1322. (search category-keep))
  1323. "Sorting structure for the agenda items of a single day.
  1324. This is a list of symbols which will be used in sequence to determine
  1325. if an entry should be listed before another entry. The following
  1326. symbols are recognized:
  1327. time-up Put entries with time-of-day indications first, early first
  1328. time-down Put entries with time-of-day indications first, late first
  1329. timestamp-up Sort by any timestamp, early first
  1330. timestamp-down Sort by any timestamp, late first
  1331. scheduled-up Sort by scheduled timestamp, early first
  1332. scheduled-down Sort by scheduled timestamp, late first
  1333. deadline-up Sort by deadline timestamp, early first
  1334. deadline-down Sort by deadline timestamp, late first
  1335. ts-up Sort by active timestamp, early first
  1336. ts-down Sort by active timestamp, late first
  1337. tsia-up Sort by inactive timestamp, early first
  1338. tsia-down Sort by inactive timestamp, late first
  1339. category-keep Keep the default order of categories, corresponding to the
  1340. sequence in `org-agenda-files'.
  1341. category-up Sort alphabetically by category, A-Z.
  1342. category-down Sort alphabetically by category, Z-A.
  1343. tag-up Sort alphabetically by last tag, A-Z.
  1344. tag-down Sort alphabetically by last tag, Z-A.
  1345. priority-up Sort numerically by priority, high priority last.
  1346. priority-down Sort numerically by priority, high priority first.
  1347. todo-state-up Sort by todo state, tasks that are done last.
  1348. todo-state-down Sort by todo state, tasks that are done first.
  1349. effort-up Sort numerically by estimated effort, high effort last.
  1350. effort-down Sort numerically by estimated effort, high effort first.
  1351. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1352. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1353. habit-up Put entries that are habits first
  1354. habit-down Put entries that are habits last
  1355. alpha-up Sort headlines alphabetically
  1356. alpha-down Sort headlines alphabetically, reversed
  1357. The different possibilities will be tried in sequence, and testing stops
  1358. if one comparison returns a \"not-equal\". For example, the default
  1359. '(time-up category-keep priority-down)
  1360. means: Pull out all entries having a specified time of day and sort them,
  1361. in order to make a time schedule for the current day the first thing in the
  1362. agenda listing for the day. Of the entries without a time indication, keep
  1363. the grouped in categories, don't sort the categories, but keep them in
  1364. the sequence given in `org-agenda-files'. Within each category sort by
  1365. priority.
  1366. Leaving out `category-keep' would mean that items will be sorted across
  1367. categories by priority.
  1368. Instead of a single list, this can also be a set of list for specific
  1369. contents, with a context symbol in the car of the list, any of
  1370. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1371. Custom commands can bind this variable in the options section."
  1372. :group 'org-agenda-sorting
  1373. :type `(choice
  1374. (repeat :tag "General" ,org-sorting-choice)
  1375. (list :tag "Individually"
  1376. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1377. (repeat ,org-sorting-choice))
  1378. (cons (const :tag "Strategy for TODO lists" todo)
  1379. (repeat ,org-sorting-choice))
  1380. (cons (const :tag "Strategy for Tags matches" tags)
  1381. (repeat ,org-sorting-choice))
  1382. (cons (const :tag "Strategy for search matches" search)
  1383. (repeat ,org-sorting-choice)))))
  1384. (defcustom org-agenda-cmp-user-defined nil
  1385. "A function to define the comparison `user-defined'.
  1386. This function must receive two arguments, agenda entry a and b.
  1387. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1388. the user comparison, return nil.
  1389. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1390. part of an agenda sorting strategy."
  1391. :group 'org-agenda-sorting
  1392. :type 'symbol)
  1393. (defcustom org-sort-agenda-notime-is-late t
  1394. "Non-nil means items without time are considered late.
  1395. This is only relevant for sorting. When t, items which have no explicit
  1396. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1397. do have a time. When nil, the default time is before 0:00. You can use this
  1398. option to decide if the schedule for today should come before or after timeless
  1399. agenda entries."
  1400. :group 'org-agenda-sorting
  1401. :type 'boolean)
  1402. (defcustom org-sort-agenda-noeffort-is-high t
  1403. "Non-nil means items without effort estimate are sorted as high effort.
  1404. This also applies when filtering an agenda view with respect to the
  1405. < or > effort operator. Then, tasks with no effort defined will be treated
  1406. as tasks with high effort.
  1407. When nil, such items are sorted as 0 minutes effort."
  1408. :group 'org-agenda-sorting
  1409. :type 'boolean)
  1410. (defgroup org-agenda-line-format nil
  1411. "Options concerning the entry prefix in the Org-mode agenda display."
  1412. :tag "Org Agenda Line Format"
  1413. :group 'org-agenda)
  1414. (defcustom org-agenda-prefix-format
  1415. '((agenda . " %i %-12:c%?-12t% s")
  1416. (timeline . " % s")
  1417. (todo . " %i %-12:c")
  1418. (tags . " %i %-12:c")
  1419. (search . " %i %-12:c"))
  1420. "Format specifications for the prefix of items in the agenda views.
  1421. An alist with five entries, each for the different agenda types. The
  1422. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1423. The values are format strings.
  1424. This format works similar to a printf format, with the following meaning:
  1425. %c the category of the item, \"Diary\" for entries from the diary,
  1426. or as given by the CATEGORY keyword or derived from the file name
  1427. %e the effort required by the item
  1428. %l the level of the item (insert X space(s) if item is of level X)
  1429. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1430. %T the last tag of the item (ignore inherited tags, which come first)
  1431. %t the HH:MM time-of-day specification if one applies to the entry
  1432. %s Scheduling/Deadline information, a short string
  1433. %b show breadcrumbs, i.e., the names of the higher levels
  1434. %(expression) Eval EXPRESSION and replace the control string
  1435. by the result
  1436. All specifiers work basically like the standard `%s' of printf, but may
  1437. contain two additional characters: a question mark just after the `%'
  1438. and a whitespace/punctuation character just before the final letter.
  1439. If the first character after `%' is a question mark, the entire field
  1440. will only be included if the corresponding value applies to the current
  1441. entry. This is useful for fields which should have fixed width when
  1442. present, but zero width when absent. For example, \"%?-12t\" will
  1443. result in a 12 character time field if a time of the day is specified,
  1444. but will completely disappear in entries which do not contain a time.
  1445. If there is punctuation or whitespace character just before the
  1446. final format letter, this character will be appended to the field
  1447. value if the value is not empty. For example, the format
  1448. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1449. the category is empty, no additional colon is inserted.
  1450. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1451. which means:
  1452. - Indent the line with two space characters
  1453. - Give the category a 12 chars wide field, padded with whitespace on
  1454. the right (because of `-'). Append a colon if there is a category
  1455. (because of `:').
  1456. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1457. time, don't put in an empty field, just skip it (because of '?').
  1458. - Finally, put the scheduling information.
  1459. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1460. `org-agenda-remove-tags'.
  1461. Custom commands can set this variable in the options section."
  1462. :type '(choice
  1463. (string :tag "General format")
  1464. (list :greedy t :tag "View dependent"
  1465. (cons (const agenda) (string :tag "Format"))
  1466. (cons (const timeline) (string :tag "Format"))
  1467. (cons (const todo) (string :tag "Format"))
  1468. (cons (const tags) (string :tag "Format"))
  1469. (cons (const search) (string :tag "Format"))))
  1470. :group 'org-agenda-line-format)
  1471. (defvar org-prefix-format-compiled nil
  1472. "The compiled prefix format and associated variables.
  1473. This is a list where first element is a list of variable bindings, and second
  1474. element is the compiled format expression. See the variable
  1475. `org-agenda-prefix-format'.")
  1476. (defcustom org-agenda-todo-keyword-format "%-1s"
  1477. "Format for the TODO keyword in agenda lines.
  1478. Set this to something like \"%-12s\" if you want all TODO keywords
  1479. to occupy a fixed space in the agenda display."
  1480. :group 'org-agenda-line-format
  1481. :type 'string)
  1482. (defcustom org-agenda-diary-sexp-prefix nil
  1483. "A regexp that matches part of a diary sexp entry
  1484. which should be treated as scheduling/deadline information in
  1485. `org-agenda'.
  1486. For example, you can use this to extract the `diary-remind-message' from
  1487. `diary-remind' entries."
  1488. :group 'org-agenda-line-format
  1489. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1490. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1491. "Text preceding timerange entries in the agenda view.
  1492. This is a list with two strings. The first applies when the range
  1493. is entirely on one day. The second applies if the range spans several days.
  1494. The strings may have two \"%d\" format specifiers which will be filled
  1495. with the sequence number of the days, and the total number of days in the
  1496. range, respectively."
  1497. :group 'org-agenda-line-format
  1498. :type '(list
  1499. (string :tag "Deadline today ")
  1500. (choice :tag "Deadline relative"
  1501. (string :tag "Format string")
  1502. (function))))
  1503. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1504. "Text preceding scheduled items in the agenda view.
  1505. This is a list with two strings. The first applies when the item is
  1506. scheduled on the current day. The second applies when it has been scheduled
  1507. previously, it may contain a %d indicating that this is the nth time that
  1508. this item is scheduled, due to automatic rescheduling of unfinished items
  1509. for the following day. So this number is one larger than the number of days
  1510. that passed since this item was scheduled first."
  1511. :group 'org-agenda-line-format
  1512. :version "24.4"
  1513. :package-version '(Org . "8.0")
  1514. :type '(list
  1515. (string :tag "Scheduled today ")
  1516. (string :tag "Scheduled previously")))
  1517. (defcustom org-agenda-inactive-leader "["
  1518. "Text preceding item pulled into the agenda by inactive time stamps.
  1519. These entries are added to the agenda when pressing \"[\"."
  1520. :group 'org-agenda-line-format
  1521. :version "24.1"
  1522. :type '(list
  1523. (string :tag "Scheduled today ")
  1524. (string :tag "Scheduled previously")))
  1525. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1526. "Text preceding deadline items in the agenda view.
  1527. This is a list with three strings. The first applies when the item has its
  1528. deadline on the current day. The second applies when the deadline is in the
  1529. future, the third one when it is in the past. The strings may contain %d
  1530. to capture the number of days."
  1531. :group 'org-agenda-line-format
  1532. :version "24.4"
  1533. :package-version '(Org . "8.0")
  1534. :type '(list
  1535. (string :tag "Deadline today ")
  1536. (choice :tag "Deadline relative"
  1537. (string :tag "Format string")
  1538. (function))))
  1539. (defcustom org-agenda-remove-times-when-in-prefix t
  1540. "Non-nil means remove duplicate time specifications in agenda items.
  1541. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1542. time-of-day specification in a headline or diary entry is extracted and
  1543. placed into the prefix. If this option is non-nil, the original specification
  1544. \(a timestamp or -range, or just a plain time(range) specification like
  1545. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1546. cluttered.
  1547. The option can be t or nil. It may also be the symbol `beg', indicating
  1548. that the time should only be removed when it is located at the beginning of
  1549. the headline/diary entry."
  1550. :group 'org-agenda-line-format
  1551. :type '(choice
  1552. (const :tag "Always" t)
  1553. (const :tag "Never" nil)
  1554. (const :tag "When at beginning of entry" beg)))
  1555. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1556. "Non-nil means remove time ranges specifications in agenda
  1557. items that span on several days."
  1558. :group 'org-agenda-line-format
  1559. :version "24.1"
  1560. :type 'boolean)
  1561. (defcustom org-agenda-default-appointment-duration nil
  1562. "Default duration for appointments that only have a starting time.
  1563. When nil, no duration is specified in such cases.
  1564. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1565. :group 'org-agenda-line-format
  1566. :type '(choice
  1567. (integer :tag "Minutes")
  1568. (const :tag "No default duration")))
  1569. (defcustom org-agenda-show-inherited-tags t
  1570. "Non-nil means show inherited tags in each agenda line.
  1571. When this option is set to 'always, it take precedences over
  1572. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1573. in every agenda.
  1574. When this option is set to t (the default), inherited tags are
  1575. shown when they are available, i.e. when the value of
  1576. `org-agenda-use-tag-inheritance' has been taken into account.
  1577. This can be set to a list of agenda types in which the agenda
  1578. must display the inherited tags. Available types are 'todo,
  1579. 'agenda, 'search and 'timeline.
  1580. When set to nil, never show inherited tags in agenda lines."
  1581. :group 'org-agenda-line-format
  1582. :group 'org-agenda
  1583. :version "24.3"
  1584. :type '(choice
  1585. (const :tag "Show inherited tags when available" t)
  1586. (const :tag "Always show inherited tags" 'always)
  1587. (repeat :tag "Show inherited tags only in selected agenda types"
  1588. (symbol :tag "Agenda type"))))
  1589. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1590. "List of agenda view types where to use tag inheritance.
  1591. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1592. controlled by `org-use-tag-inheritance'. In other agenda types,
  1593. `org-use-tag-inheritance' is not used for the selection of the
  1594. agenda entries. Still, you may want the agenda to be aware of
  1595. the inherited tags anyway, e.g. for later tag filtering.
  1596. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1597. This variable has no effect if `org-agenda-show-inherited-tags'
  1598. is set to 'always. In that case, the agenda is aware of those
  1599. tags.
  1600. The default value sets tags in every agenda type. Setting this
  1601. option to nil will speed up non-tags agenda view a lot."
  1602. :group 'org-agenda
  1603. :version "24.3"
  1604. :type '(choice
  1605. (const :tag "Use tag inheritance in all agenda types" t)
  1606. (repeat :tag "Use tag inheritance in selected agenda types"
  1607. (symbol :tag "Agenda type"))))
  1608. (defcustom org-agenda-hide-tags-regexp nil
  1609. "Regular expression used to filter away specific tags in agenda views.
  1610. This means that these tags will be present, but not be shown in the agenda
  1611. line. Secondary filtering will still work on the hidden tags.
  1612. Nil means don't hide any tags."
  1613. :group 'org-agenda-line-format
  1614. :type '(choice
  1615. (const :tag "Hide none" nil)
  1616. (string :tag "Regexp ")))
  1617. (defcustom org-agenda-remove-tags nil
  1618. "Non-nil means remove the tags from the headline copy in the agenda.
  1619. When this is the symbol `prefix', only remove tags when
  1620. `org-agenda-prefix-format' contains a `%T' specifier."
  1621. :group 'org-agenda-line-format
  1622. :type '(choice
  1623. (const :tag "Always" t)
  1624. (const :tag "Never" nil)
  1625. (const :tag "When prefix format contains %T" prefix)))
  1626. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1627. 'org-agenda-remove-tags)
  1628. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1629. "Shift tags in agenda items to this column.
  1630. If this number is positive, it specifies the column. If it is negative,
  1631. it means that the tags should be flushright to that column. For example,
  1632. -80 works well for a normal 80 character screen."
  1633. :group 'org-agenda-line-format
  1634. :type 'integer)
  1635. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1636. (defcustom org-agenda-fontify-priorities 'cookies
  1637. "Non-nil means highlight low and high priorities in agenda.
  1638. When t, the highest priority entries are bold, lowest priority italic.
  1639. However, settings in `org-priority-faces' will overrule these faces.
  1640. When this variable is the symbol `cookies', only fontify the
  1641. cookies, not the entire task.
  1642. This may also be an association list of priority faces, whose
  1643. keys are the character values of `org-highest-priority',
  1644. `org-default-priority', and `org-lowest-priority' (the default values
  1645. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1646. color as a string, or a list like `(:background \"Red\")'.
  1647. If it is a color, the variable `org-faces-easy-properties'
  1648. determines if it is a foreground or a background color."
  1649. :group 'org-agenda-line-format
  1650. :type '(choice
  1651. (const :tag "Never" nil)
  1652. (const :tag "Defaults" t)
  1653. (const :tag "Cookies only" cookies)
  1654. (repeat :tag "Specify"
  1655. (list (character :tag "Priority" :value ?A)
  1656. (choice :tag "Face "
  1657. (string :tag "Color")
  1658. (sexp :tag "Face"))))))
  1659. (defcustom org-agenda-day-face-function nil
  1660. "Function called to determine what face should be used to display a day.
  1661. The only argument passed to that function is the day. It should
  1662. returns a face, or nil if does not want to specify a face and let
  1663. the normal rules apply."
  1664. :group 'org-agenda-line-format
  1665. :version "24.1"
  1666. :type 'function)
  1667. (defcustom org-agenda-category-icon-alist nil
  1668. "Alist of category icon to be displayed in agenda views.
  1669. Each entry should have the following format:
  1670. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1671. Where CATEGORY-REGEXP is a regexp matching the categories where
  1672. the icon should be displayed.
  1673. FILE-OR-DATA either a file path or a string containing image data.
  1674. The other fields can be omitted safely if not needed:
  1675. TYPE indicates the image type.
  1676. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1677. image data.
  1678. PROPS are additional image attributes to assign to the image,
  1679. like, e.g. `:ascent center'.
  1680. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1681. If you want to set the display properties yourself, just put a
  1682. list as second element:
  1683. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1684. For example, to display a 16px horizontal space for Emacs
  1685. category, you can use:
  1686. (\"Emacs\" '(space . (:width (16))))"
  1687. :group 'org-agenda-line-format
  1688. :version "24.1"
  1689. :type '(alist :key-type (string :tag "Regexp matching category")
  1690. :value-type (choice (list :tag "Icon"
  1691. (string :tag "File or data")
  1692. (symbol :tag "Type")
  1693. (boolean :tag "Data?")
  1694. (repeat :tag "Extra image properties" :inline t symbol))
  1695. (list :tag "Display properties" sexp))))
  1696. (defgroup org-agenda-column-view nil
  1697. "Options concerning column view in the agenda."
  1698. :tag "Org Agenda Column View"
  1699. :group 'org-agenda)
  1700. (defcustom org-agenda-columns-show-summaries t
  1701. "Non-nil means show summaries for columns displayed in the agenda view."
  1702. :group 'org-agenda-column-view
  1703. :type 'boolean)
  1704. (defcustom org-agenda-columns-compute-summary-properties t
  1705. "Non-nil means recompute all summary properties before column view.
  1706. When column view in the agenda is listing properties that have a summary
  1707. operator, it can go to all relevant buffers and recompute the summaries
  1708. there. This can mean overhead for the agenda column view, but is necessary
  1709. to have thing up to date.
  1710. As a special case, a CLOCKSUM property also makes sure that the clock
  1711. computations are current."
  1712. :group 'org-agenda-column-view
  1713. :type 'boolean)
  1714. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1715. "Non-nil means the duration of an appointment will add to day effort.
  1716. The property to which appointment durations will be added is the one given
  1717. in the option `org-effort-property'. If an appointment does not have
  1718. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1719. is not set, an appointment without end time will not contribute to the time
  1720. estimate."
  1721. :group 'org-agenda-column-view
  1722. :type 'boolean)
  1723. (defcustom org-agenda-auto-exclude-function nil
  1724. "A function called with a tag to decide if it is filtered on '/ RET'.
  1725. The sole argument to the function, which is called once for each
  1726. possible tag, is a string giving the name of the tag. The
  1727. function should return either nil if the tag should be included
  1728. as normal, or \"-<TAG>\" to exclude the tag.
  1729. Note that for the purpose of tag filtering, only the lower-case version of
  1730. all tags will be considered, so that this function will only ever see
  1731. the lower-case version of all tags."
  1732. :group 'org-agenda
  1733. :type 'function)
  1734. (defcustom org-agenda-bulk-custom-functions nil
  1735. "Alist of characters and custom functions for bulk actions.
  1736. For example, this value makes those two functions available:
  1737. '((?R set-category)
  1738. (?C bulk-cut))
  1739. With selected entries in an agenda buffer, `B R' will call
  1740. the custom function `set-category' on the selected entries.
  1741. Note that functions in this alist don't need to be quoted."
  1742. :type 'alist
  1743. :version "24.1"
  1744. :group 'org-agenda)
  1745. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1746. "Execute BODY with point at location given by `org-hd-marker' property.
  1747. If STRING is non-nil, the text property will be fetched from position 0
  1748. in that string. If STRING is nil, it will be fetched from the beginning
  1749. of the current line."
  1750. (org-with-gensyms (marker)
  1751. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1752. 'org-hd-marker ,string)))
  1753. (with-current-buffer (marker-buffer ,marker)
  1754. (save-excursion
  1755. (goto-char ,marker)
  1756. ,@body)))))
  1757. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1758. (defun org-add-agenda-custom-command (entry)
  1759. "Replace or add a command in `org-agenda-custom-commands'.
  1760. This is mostly for hacking and trying a new command - once the command
  1761. works you probably want to add it to `org-agenda-custom-commands' for good."
  1762. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1763. (if ass
  1764. (setcdr ass (cdr entry))
  1765. (push entry org-agenda-custom-commands))))
  1766. ;;; Define the org-agenda-mode
  1767. (defvar org-agenda-mode-map (make-sparse-keymap)
  1768. "Keymap for `org-agenda-mode'.")
  1769. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1770. (defvar org-agenda-menu) ; defined later in this file.
  1771. (defvar org-agenda-restrict nil) ; defined later in this file.
  1772. (defvar org-agenda-follow-mode nil)
  1773. (defvar org-agenda-entry-text-mode nil)
  1774. (defvar org-agenda-clockreport-mode nil)
  1775. (defvar org-agenda-show-log nil)
  1776. (defvar org-agenda-redo-command nil)
  1777. (defvar org-agenda-query-string nil)
  1778. (defvar org-agenda-mode-hook nil
  1779. "Hook run after `org-agenda-mode' is turned on.
  1780. The buffer is still writable when this hook is called.")
  1781. (defvar org-agenda-type nil)
  1782. (defvar org-agenda-force-single-file nil)
  1783. (defvar org-agenda-bulk-marked-entries nil
  1784. "List of markers that refer to marked entries in the agenda.")
  1785. ;;; Multiple agenda buffers support
  1786. (defcustom org-agenda-sticky nil
  1787. "Non-nil means agenda q key will bury agenda buffers.
  1788. Agenda commands will then show existing buffer instead of generating new ones.
  1789. When nil, `q' will kill the single agenda buffer."
  1790. :group 'org-agenda
  1791. :version "24.3"
  1792. :type 'boolean)
  1793. ;;;###autoload
  1794. (defun org-toggle-sticky-agenda (&optional arg)
  1795. "Toggle `org-agenda-sticky'."
  1796. (interactive "P")
  1797. (let ((new-value (if arg
  1798. (> (prefix-numeric-value arg) 0)
  1799. (not org-agenda-sticky))))
  1800. (if (equal new-value org-agenda-sticky)
  1801. (and (org-called-interactively-p 'interactive)
  1802. (message "Sticky agenda was already %s"
  1803. (if org-agenda-sticky "enabled" "disabled")))
  1804. (setq org-agenda-sticky new-value)
  1805. (org-agenda-kill-all-agenda-buffers)
  1806. (and (org-called-interactively-p 'interactive)
  1807. (message "Sticky agenda was %s"
  1808. (if org-agenda-sticky "enabled" "disabled"))))))
  1809. (defvar org-agenda-buffer nil
  1810. "Agenda buffer currently being generated.")
  1811. (defvar org-agenda-last-prefix-arg nil)
  1812. (defvar org-agenda-this-buffer-name nil)
  1813. (defvar org-agenda-doing-sticky-redo nil)
  1814. (defvar org-agenda-this-buffer-is-sticky nil)
  1815. (defconst org-agenda-local-vars
  1816. '(org-agenda-this-buffer-name
  1817. org-agenda-undo-list
  1818. org-agenda-pending-undo-list
  1819. org-agenda-follow-mode
  1820. org-agenda-entry-text-mode
  1821. org-agenda-clockreport-mode
  1822. org-agenda-show-log
  1823. org-agenda-redo-command
  1824. org-agenda-query-string
  1825. org-agenda-type
  1826. org-agenda-bulk-marked-entries
  1827. org-agenda-undo-has-started-in
  1828. org-agenda-info
  1829. org-agenda-pre-window-conf
  1830. org-agenda-columns-active
  1831. org-agenda-tag-filter-overlays
  1832. org-agenda-tag-filter
  1833. org-agenda-cat-filter-overlays
  1834. org-agenda-category-filter
  1835. org-agenda-re-filter-overlays
  1836. org-agenda-regexp-filter
  1837. org-agenda-markers
  1838. org-agenda-last-search-view-search-was-boolean
  1839. org-agenda-filtered-by-category
  1840. org-agenda-filter-form
  1841. org-agenda-cycle-counter
  1842. org-agenda-last-prefix-arg)
  1843. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1844. (defun org-agenda-mode ()
  1845. "Mode for time-sorted view on action items in Org-mode files.
  1846. The following commands are available:
  1847. \\{org-agenda-mode-map}"
  1848. (interactive)
  1849. (cond (org-agenda-doing-sticky-redo
  1850. ;; Refreshing sticky agenda-buffer
  1851. ;;
  1852. ;; Preserve the value of `org-agenda-local-vars' variables,
  1853. ;; while letting `kill-all-local-variables' kill the rest
  1854. (let ((save (buffer-local-variables)))
  1855. (kill-all-local-variables)
  1856. (mapc 'make-local-variable org-agenda-local-vars)
  1857. (dolist (elem save)
  1858. (let ((var (car elem))
  1859. (val (cdr elem)))
  1860. (when (and val
  1861. (member var org-agenda-local-vars))
  1862. (set var val)))))
  1863. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1864. (org-agenda-sticky
  1865. ;; Creating a sticky Agenda buffer for the first time
  1866. (kill-all-local-variables)
  1867. (mapc 'make-local-variable org-agenda-local-vars)
  1868. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1869. (t
  1870. ;; Creating a non-sticky agenda buffer
  1871. (kill-all-local-variables)
  1872. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1873. (setq org-agenda-undo-list nil
  1874. org-agenda-pending-undo-list nil
  1875. org-agenda-bulk-marked-entries nil)
  1876. (setq major-mode 'org-agenda-mode)
  1877. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1878. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1879. (setq mode-name "Org-Agenda")
  1880. (use-local-map org-agenda-mode-map)
  1881. (easy-menu-add org-agenda-menu)
  1882. (if org-startup-truncated (setq truncate-lines t))
  1883. (org-set-local 'line-move-visual nil)
  1884. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1885. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1886. ;; Make sure properties are removed when copying text
  1887. (make-local-variable 'filter-buffer-substring-functions)
  1888. (add-hook 'filter-buffer-substring-functions
  1889. (lambda (fun start end delete)
  1890. (substring-no-properties (funcall fun start end delete))))
  1891. (unless org-agenda-keep-modes
  1892. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1893. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1894. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1895. org-agenda-show-log org-agenda-start-with-log-mode))
  1896. (easy-menu-change
  1897. '("Agenda") "Agenda Files"
  1898. (append
  1899. (list
  1900. (vector
  1901. (if (get 'org-agenda-files 'org-restrict)
  1902. "Restricted to single file"
  1903. "Edit File List")
  1904. '(org-edit-agenda-file-list)
  1905. (not (get 'org-agenda-files 'org-restrict)))
  1906. "--")
  1907. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1908. (org-agenda-set-mode-name)
  1909. (apply
  1910. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1911. (list 'org-agenda-mode-hook)))
  1912. (substitute-key-definition 'undo 'org-agenda-undo
  1913. org-agenda-mode-map global-map)
  1914. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1915. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1916. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1917. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1918. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1919. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1920. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1921. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1922. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1923. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1924. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1925. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1926. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1927. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1928. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1929. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1930. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1931. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1932. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1933. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1934. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1935. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1936. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1937. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1938. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1940. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1941. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1942. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1943. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1944. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1945. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1946. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1947. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1948. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1949. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1950. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1951. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1952. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1953. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1954. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1955. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1956. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1957. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1958. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1959. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1960. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1961. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1962. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1963. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1964. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1965. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1966. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1967. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1968. (while l (org-defkey org-agenda-mode-map
  1969. (int-to-string (pop l)) 'digit-argument)))
  1970. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1971. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1972. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1973. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1974. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1975. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1976. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1977. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1978. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1979. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1980. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1981. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1982. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1983. 'org-clock-modify-effort-estimate)
  1984. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1985. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1986. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1987. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1988. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1989. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1990. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1991. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1992. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1993. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1994. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1995. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1996. (substitute-key-definition 'next-line 'org-agenda-next-line
  1997. org-agenda-mode-map global-map)
  1998. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1999. org-agenda-mode-map global-map)
  2000. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2001. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2002. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2003. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2004. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2005. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2006. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2007. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2008. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2009. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2010. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2011. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2012. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2013. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2014. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2015. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2016. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2017. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2018. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2019. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2020. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2021. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2022. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2023. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2024. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2025. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2026. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2027. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2028. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2029. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2030. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2031. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2032. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2033. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2034. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2035. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2036. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2037. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2038. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2039. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2040. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2041. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2042. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2043. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2044. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2045. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2046. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2047. (when org-agenda-mouse-1-follows-link
  2048. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2049. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2050. '("Agenda"
  2051. ("Agenda Files")
  2052. "--"
  2053. ("Agenda Dates"
  2054. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2055. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2056. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2057. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2058. "--"
  2059. ("View"
  2060. ["Day View" org-agenda-day-view
  2061. :active (org-agenda-check-type nil 'agenda)
  2062. :style radio :selected (eq org-agenda-current-span 'day)
  2063. :keys "v d (or just d)"]
  2064. ["Week View" org-agenda-week-view
  2065. :active (org-agenda-check-type nil 'agenda)
  2066. :style radio :selected (eq org-agenda-current-span 'week)
  2067. :keys "v w (or just w)"]
  2068. ["Month View" org-agenda-month-view
  2069. :active (org-agenda-check-type nil 'agenda)
  2070. :style radio :selected (eq org-agenda-current-span 'month)
  2071. :keys "v m"]
  2072. ["Year View" org-agenda-year-view
  2073. :active (org-agenda-check-type nil 'agenda)
  2074. :style radio :selected (eq org-agenda-current-span 'year)
  2075. :keys "v y"]
  2076. "--"
  2077. ["Include Diary" org-agenda-toggle-diary
  2078. :style toggle :selected org-agenda-include-diary
  2079. :active (org-agenda-check-type nil 'agenda)]
  2080. ["Include Deadlines" org-agenda-toggle-deadlines
  2081. :style toggle :selected org-agenda-include-deadlines
  2082. :active (org-agenda-check-type nil 'agenda)]
  2083. ["Use Time Grid" org-agenda-toggle-time-grid
  2084. :style toggle :selected org-agenda-use-time-grid
  2085. :active (org-agenda-check-type nil 'agenda)]
  2086. "--"
  2087. ["Show clock report" org-agenda-clockreport-mode
  2088. :style toggle :selected org-agenda-clockreport-mode
  2089. :active (org-agenda-check-type nil 'agenda)]
  2090. ["Show some entry text" org-agenda-entry-text-mode
  2091. :style toggle :selected org-agenda-entry-text-mode
  2092. :active t]
  2093. "--"
  2094. ["Show Logbook entries" org-agenda-log-mode
  2095. :style toggle :selected org-agenda-show-log
  2096. :active (org-agenda-check-type nil 'agenda 'timeline)
  2097. :keys "v l (or just l)"]
  2098. ["Include archived trees" org-agenda-archives-mode
  2099. :style toggle :selected org-agenda-archives-mode :active t
  2100. :keys "v a"]
  2101. ["Include archive files" (org-agenda-archives-mode t)
  2102. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2103. :keys "v A"]
  2104. "--"
  2105. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2106. ["Write view to file" org-agenda-write t]
  2107. ["Rebuild buffer" org-agenda-redo t]
  2108. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2109. "--"
  2110. ["Show original entry" org-agenda-show t]
  2111. ["Go To (other window)" org-agenda-goto t]
  2112. ["Go To (this window)" org-agenda-switch-to t]
  2113. ["Capture with cursor date" org-agenda-capture t]
  2114. ["Follow Mode" org-agenda-follow-mode
  2115. :style toggle :selected org-agenda-follow-mode :active t]
  2116. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2117. "--"
  2118. ("TODO"
  2119. ["Cycle TODO" org-agenda-todo t]
  2120. ["Next TODO set" org-agenda-todo-nextset t]
  2121. ["Previous TODO set" org-agenda-todo-previousset t]
  2122. ["Add note" org-agenda-add-note t])
  2123. ("Archive/Refile/Delete"
  2124. ["Archive default" org-agenda-archive-default t]
  2125. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2126. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2127. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2128. ["Archive subtree" org-agenda-archive t]
  2129. "--"
  2130. ["Refile" org-agenda-refile t]
  2131. "--"
  2132. ["Delete subtree" org-agenda-kill t])
  2133. ("Bulk action"
  2134. ["Mark entry" org-agenda-bulk-mark t]
  2135. ["Mark all" org-agenda-bulk-mark-all t]
  2136. ["Unmark entry" org-agenda-bulk-unmark t]
  2137. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2138. ["Toggle mark" org-agenda-bulk-toggle t]
  2139. ["Toggle all" org-agenda-bulk-toggle-all t]
  2140. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2141. ["Act on all marked" org-agenda-bulk-action t]
  2142. "--"
  2143. ("Tags and Properties"
  2144. ["Show all Tags" org-agenda-show-tags t]
  2145. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2146. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2147. "--"
  2148. ["Column View" org-columns t])
  2149. ("Deadline/Schedule"
  2150. ["Schedule" org-agenda-schedule t]
  2151. ["Set Deadline" org-agenda-deadline t]
  2152. "--"
  2153. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2154. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2155. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2156. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2157. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2158. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2159. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2160. ("Clock and Effort"
  2161. ["Clock in" org-agenda-clock-in t]
  2162. ["Clock out" org-agenda-clock-out t]
  2163. ["Clock cancel" org-agenda-clock-cancel t]
  2164. ["Goto running clock" org-clock-goto t]
  2165. "--"
  2166. ["Set Effort" org-agenda-set-effort t]
  2167. ["Change clocked effort" org-clock-modify-effort-estimate
  2168. (org-clock-is-active)])
  2169. ("Priority"
  2170. ["Set Priority" org-agenda-priority t]
  2171. ["Increase Priority" org-agenda-priority-up t]
  2172. ["Decrease Priority" org-agenda-priority-down t]
  2173. ["Show Priority" org-show-priority t])
  2174. ("Calendar/Diary"
  2175. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2176. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2177. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2178. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2179. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2180. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2181. "--"
  2182. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2183. "--"
  2184. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2185. "--"
  2186. ("MobileOrg"
  2187. ["Push Files and Views" org-mobile-push t]
  2188. ["Get Captured and Flagged" org-mobile-pull t]
  2189. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2190. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2191. "--"
  2192. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2193. "--"
  2194. ["Quit" org-agenda-quit t]
  2195. ["Exit and Release Buffers" org-agenda-exit t]
  2196. ))
  2197. ;;; Agenda undo
  2198. (defvar org-agenda-allow-remote-undo t
  2199. "Non-nil means allow remote undo from the agenda buffer.")
  2200. (defvar org-agenda-undo-has-started-in nil
  2201. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2202. (defun org-agenda-undo ()
  2203. "Undo a remote editing step in the agenda.
  2204. This undoes changes both in the agenda buffer and in the remote buffer
  2205. that have been changed along."
  2206. (interactive)
  2207. (or org-agenda-allow-remote-undo
  2208. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2209. (if (not (eq this-command last-command))
  2210. (setq org-agenda-undo-has-started-in nil
  2211. org-agenda-pending-undo-list org-agenda-undo-list))
  2212. (if (not org-agenda-pending-undo-list)
  2213. (user-error "No further undo information"))
  2214. (let* ((entry (pop org-agenda-pending-undo-list))
  2215. buf line cmd rembuf)
  2216. (setq cmd (pop entry) line (pop entry))
  2217. (setq rembuf (nth 2 entry))
  2218. (org-with-remote-undo rembuf
  2219. (while (bufferp (setq buf (pop entry)))
  2220. (if (pop entry)
  2221. (with-current-buffer buf
  2222. (let ((last-undo-buffer buf)
  2223. (inhibit-read-only t))
  2224. (unless (memq buf org-agenda-undo-has-started-in)
  2225. (push buf org-agenda-undo-has-started-in)
  2226. (make-local-variable 'pending-undo-list)
  2227. (undo-start))
  2228. (while (and pending-undo-list
  2229. (listp pending-undo-list)
  2230. (not (car pending-undo-list)))
  2231. (pop pending-undo-list))
  2232. (undo-more 1))))))
  2233. (org-goto-line line)
  2234. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2235. (defun org-verify-change-for-undo (l1 l2)
  2236. "Verify that a real change occurred between the undo lists L1 and L2."
  2237. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2238. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2239. (not (eq l1 l2)))
  2240. ;;; Agenda dispatch
  2241. (defvar org-agenda-restrict-begin (make-marker))
  2242. (defvar org-agenda-restrict-end (make-marker))
  2243. (defvar org-agenda-last-dispatch-buffer nil)
  2244. (defvar org-agenda-overriding-restriction nil)
  2245. (defcustom org-agenda-custom-commands-contexts nil
  2246. "Alist of custom agenda keys and contextual rules.
  2247. For example, if you have a custom agenda command \"p\" and you
  2248. want this command to be accessible only from plain text files,
  2249. use this:
  2250. '((\"p\" ((in-file . \"\\.txt\"))))
  2251. Here are the available contexts definitions:
  2252. in-file: command displayed only in matching files
  2253. in-mode: command displayed only in matching modes
  2254. not-in-file: command not displayed in matching files
  2255. not-in-mode: command not displayed in matching modes
  2256. in-buffer: command displayed only in matching buffers
  2257. not-in-buffer: command not displayed in matching buffers
  2258. [function]: a custom function taking no argument
  2259. If you define several checks, the agenda command will be
  2260. accessible if there is at least one valid check.
  2261. You can also bind a key to another agenda custom command
  2262. depending on contextual rules.
  2263. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2264. Here it means: in .txt files, use \"p\" as the key for the
  2265. agenda command otherwise associated with \"q\". (The command
  2266. originally associated with \"q\" is not displayed to avoid
  2267. duplicates.)"
  2268. :version "24.3"
  2269. :group 'org-agenda-custom-commands
  2270. :type '(repeat (list :tag "Rule"
  2271. (string :tag " Agenda key")
  2272. (string :tag "Replace by command")
  2273. (repeat :tag "Available when"
  2274. (choice
  2275. (cons :tag "Condition"
  2276. (choice
  2277. (const :tag "In file" in-file)
  2278. (const :tag "Not in file" not-in-file)
  2279. (const :tag "In buffer" in-buffer)
  2280. (const :tag "Not in buffer" not-in-buffer)
  2281. (const :tag "In mode" in-mode)
  2282. (const :tag "Not in mode" not-in-mode))
  2283. (regexp))
  2284. (function :tag "Custom function"))))))
  2285. (defcustom org-agenda-max-entries nil
  2286. "Maximum number of entries to display in an agenda.
  2287. This can be nil (no limit) or an integer or an alist of agenda
  2288. types with an associated number of entries to display in this
  2289. type."
  2290. :version "24.4"
  2291. :package-version '(Org . "8.0")
  2292. :group 'org-agenda-custom-commands
  2293. :type '(choice (symbol :tag "No limit" nil)
  2294. (integer :tag "Max number of entries")
  2295. (repeat
  2296. (cons (choice :tag "Agenda type"
  2297. (const agenda)
  2298. (const todo)
  2299. (const tags)
  2300. (const search)
  2301. (const timeline))
  2302. (integer :tag "Max number of entries")))))
  2303. (defcustom org-agenda-max-todos nil
  2304. "Maximum number of TODOs to display in an agenda.
  2305. This can be nil (no limit) or an integer or an alist of agenda
  2306. types with an associated number of entries to display in this
  2307. type."
  2308. :version "24.4"
  2309. :package-version '(Org . "8.0")
  2310. :group 'org-agenda-custom-commands
  2311. :type '(choice (symbol :tag "No limit" nil)
  2312. (integer :tag "Max number of entries")
  2313. (repeat
  2314. (cons (choice :tag "Agenda type"
  2315. (const agenda)
  2316. (const todo)
  2317. (const tags)
  2318. (const search)
  2319. (const timeline))
  2320. (integer :tag "Max number of entries")))))
  2321. (defcustom org-agenda-max-tags nil
  2322. "Maximum number of tagged entries to display in an agenda.
  2323. This can be nil (no limit) or an integer or an alist of agenda
  2324. types with an associated number of entries to display in this
  2325. type."
  2326. :version "24.4"
  2327. :package-version '(Org . "8.0")
  2328. :group 'org-agenda-custom-commands
  2329. :type '(choice (symbol :tag "No limit" nil)
  2330. (integer :tag "Max number of entries")
  2331. (repeat
  2332. (cons (choice :tag "Agenda type"
  2333. (const agenda)
  2334. (const todo)
  2335. (const tags)
  2336. (const search)
  2337. (const timeline))
  2338. (integer :tag "Max number of entries")))))
  2339. (defcustom org-agenda-max-effort nil
  2340. "Maximum cumulated effort duration for the agenda.
  2341. This can be nil (no limit) or a number of minutes (as an integer)
  2342. or an alist of agenda types with an associated number of minutes
  2343. to limit entries to in this type."
  2344. :version "24.4"
  2345. :package-version '(Org . "8.0")
  2346. :group 'org-agenda-custom-commands
  2347. :type '(choice (symbol :tag "No limit" nil)
  2348. (integer :tag "Max number of entries")
  2349. (repeat
  2350. (cons (choice :tag "Agenda type"
  2351. (const agenda)
  2352. (const todo)
  2353. (const tags)
  2354. (const search)
  2355. (const timeline))
  2356. (integer :tag "Max number of entries")))))
  2357. (defvar org-keys nil)
  2358. (defvar org-match nil)
  2359. ;;;###autoload
  2360. (defun org-agenda (&optional arg org-keys restriction)
  2361. "Dispatch agenda commands to collect entries to the agenda buffer.
  2362. Prompts for a command to execute. Any prefix arg will be passed
  2363. on to the selected command. The default selections are:
  2364. a Call `org-agenda-list' to display the agenda for current day or week.
  2365. t Call `org-todo-list' to display the global todo list.
  2366. T Call `org-todo-list' to display the global todo list, select only
  2367. entries with a specific TODO keyword (the user gets a prompt).
  2368. m Call `org-tags-view' to display headlines with tags matching
  2369. a condition (the user is prompted for the condition).
  2370. M Like `m', but select only TODO entries, no ordinary headlines.
  2371. L Create a timeline for the current buffer.
  2372. e Export views to associated files.
  2373. s Search entries for keywords.
  2374. S Search entries for keywords, only with TODO keywords.
  2375. / Multi occur across all agenda files and also files listed
  2376. in `org-agenda-text-search-extra-files'.
  2377. < Restrict agenda commands to buffer, subtree, or region.
  2378. Press several times to get the desired effect.
  2379. > Remove a previous restriction.
  2380. # List \"stuck\" projects.
  2381. ! Configure what \"stuck\" means.
  2382. C Configure custom agenda commands.
  2383. More commands can be added by configuring the variable
  2384. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2385. searches can be pre-defined in this way.
  2386. If the current buffer is in Org-mode and visiting a file, you can also
  2387. first press `<' once to indicate that the agenda should be temporarily
  2388. \(until the next use of \\[org-agenda]) restricted to the current file.
  2389. Pressing `<' twice means to restrict to the current subtree or region
  2390. \(if active)."
  2391. (interactive "P")
  2392. (catch 'exit
  2393. (let* ((prefix-descriptions nil)
  2394. (org-agenda-buffer-name org-agenda-buffer-name)
  2395. (org-agenda-window-setup (if (equal (buffer-name)
  2396. org-agenda-buffer-name)
  2397. 'current-window
  2398. org-agenda-window-setup))
  2399. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2400. (org-agenda-custom-commands
  2401. ;; normalize different versions
  2402. (delq nil
  2403. (mapcar
  2404. (lambda (x)
  2405. (cond ((stringp (cdr x))
  2406. (push x prefix-descriptions)
  2407. nil)
  2408. ((stringp (nth 1 x)) x)
  2409. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2410. (t (cons (car x) (cons "" (cdr x))))))
  2411. org-agenda-custom-commands)))
  2412. (org-agenda-custom-commands
  2413. (org-contextualize-keys
  2414. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2415. (buf (current-buffer))
  2416. (bfn (buffer-file-name (buffer-base-buffer)))
  2417. entry key type org-match lprops ans)
  2418. ;; Turn off restriction unless there is an overriding one,
  2419. (unless org-agenda-overriding-restriction
  2420. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2421. ;; There is a request to keep the file list in place
  2422. (put 'org-agenda-files 'org-restrict nil))
  2423. (setq org-agenda-restrict nil)
  2424. (move-marker org-agenda-restrict-begin nil)
  2425. (move-marker org-agenda-restrict-end nil))
  2426. ;; Delete old local properties
  2427. (put 'org-agenda-redo-command 'org-lprops nil)
  2428. ;; Delete previously set last-arguments
  2429. (put 'org-agenda-redo-command 'last-args nil)
  2430. ;; Remember where this call originated
  2431. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2432. (unless org-keys
  2433. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2434. org-keys (car ans)
  2435. restriction (cdr ans)))
  2436. ;; If we have sticky agenda buffers, set a name for the buffer,
  2437. ;; depending on the invoking keys. The user may still set this
  2438. ;; as a command option, which will overwrite what we do here.
  2439. (if org-agenda-sticky
  2440. (setq org-agenda-buffer-name
  2441. (format "*Org Agenda(%s)*" org-keys)))
  2442. ;; Establish the restriction, if any
  2443. (when (and (not org-agenda-overriding-restriction) restriction)
  2444. (put 'org-agenda-files 'org-restrict (list bfn))
  2445. (cond
  2446. ((eq restriction 'region)
  2447. (setq org-agenda-restrict t)
  2448. (move-marker org-agenda-restrict-begin (region-beginning))
  2449. (move-marker org-agenda-restrict-end (region-end)))
  2450. ((eq restriction 'subtree)
  2451. (save-excursion
  2452. (setq org-agenda-restrict t)
  2453. (org-back-to-heading t)
  2454. (move-marker org-agenda-restrict-begin (point))
  2455. (move-marker org-agenda-restrict-end
  2456. (progn (org-end-of-subtree t)))))))
  2457. ;; For example the todo list should not need it (but does...)
  2458. (cond
  2459. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2460. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2461. (progn
  2462. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2463. lprops (nth 4 entry))
  2464. (if org-agenda-sticky
  2465. (setq org-agenda-buffer-name
  2466. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2467. (format "*Org Agenda(%s)*" org-keys))))
  2468. (put 'org-agenda-redo-command 'org-lprops lprops)
  2469. (cond
  2470. ((eq type 'agenda)
  2471. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2472. ((eq type 'agenda*)
  2473. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2474. ((eq type 'alltodo)
  2475. (org-let lprops '(org-todo-list current-prefix-arg)))
  2476. ((eq type 'search)
  2477. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2478. ((eq type 'stuck)
  2479. (org-let lprops '(org-agenda-list-stuck-projects
  2480. current-prefix-arg)))
  2481. ((eq type 'tags)
  2482. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2483. ((eq type 'tags-todo)
  2484. (org-let lprops '(org-tags-view '(4) org-match)))
  2485. ((eq type 'todo)
  2486. (org-let lprops '(org-todo-list org-match)))
  2487. ((eq type 'tags-tree)
  2488. (org-check-for-org-mode)
  2489. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2490. ((eq type 'todo-tree)
  2491. (org-check-for-org-mode)
  2492. (org-let lprops
  2493. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2494. (regexp-quote org-match) "\\>"))))
  2495. ((eq type 'occur-tree)
  2496. (org-check-for-org-mode)
  2497. (org-let lprops '(org-occur org-match)))
  2498. ((functionp type)
  2499. (org-let lprops '(funcall type org-match)))
  2500. ((fboundp type)
  2501. (org-let lprops '(funcall type org-match)))
  2502. (t (user-error "Invalid custom agenda command type %s" type))))
  2503. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2504. ((equal org-keys "C")
  2505. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2506. (customize-variable 'org-agenda-custom-commands))
  2507. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2508. ((equal org-keys "s") (call-interactively 'org-search-view))
  2509. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2510. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2511. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2512. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2513. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2514. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2515. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2516. (org-add-hook
  2517. 'post-command-hook
  2518. (lambda ()
  2519. (unless (current-message)
  2520. (let* ((m (org-agenda-get-any-marker))
  2521. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2522. (when note
  2523. (message (concat
  2524. "FLAGGING-NOTE ([?] for more info): "
  2525. (org-add-props
  2526. (replace-regexp-in-string
  2527. "\\\\n" "//"
  2528. (copy-sequence note))
  2529. nil 'face 'org-warning)))))))
  2530. t t))
  2531. ((equal org-keys "L")
  2532. (unless (derived-mode-p 'org-mode)
  2533. (user-error "This is not an Org-mode file"))
  2534. (unless restriction
  2535. (put 'org-agenda-files 'org-restrict (list bfn))
  2536. (org-call-with-arg 'org-timeline arg)))
  2537. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2538. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2539. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2540. (t (user-error "Invalid agenda key"))))))
  2541. (defun org-agenda-append-agenda ()
  2542. "Append another agenda view to the current one.
  2543. This function allows interactive building of block agendas.
  2544. Agenda views are separated by `org-agenda-block-separator'."
  2545. (interactive)
  2546. (unless (derived-mode-p 'org-agenda-mode)
  2547. (user-error "Can only append from within agenda buffer"))
  2548. (let ((org-agenda-multi t))
  2549. (org-agenda)
  2550. (widen)
  2551. (org-agenda-finalize)
  2552. (setq buffer-read-only t)
  2553. (org-agenda-fit-window-to-buffer)))
  2554. (defun org-agenda-normalize-custom-commands (cmds)
  2555. "Normalize custom commands CMDS."
  2556. (delq nil
  2557. (mapcar
  2558. (lambda (x)
  2559. (cond ((stringp (cdr x)) nil)
  2560. ((stringp (nth 1 x)) x)
  2561. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2562. (t (cons (car x) (cons "" (cdr x))))))
  2563. cmds)))
  2564. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2565. "The user interface for selecting an agenda command."
  2566. (catch 'exit
  2567. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2568. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2569. (region-p (org-region-active-p))
  2570. (custom org-agenda-custom-commands)
  2571. (selstring "")
  2572. restriction second-time
  2573. c entry key type match prefixes rmheader header-end custom1 desc
  2574. line lines left right n n1)
  2575. (save-window-excursion
  2576. (delete-other-windows)
  2577. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2578. (erase-buffer)
  2579. (insert (eval-when-compile
  2580. (let ((header
  2581. "Press key for an agenda command: < Buffer, subtree/region restriction
  2582. -------------------------------- > Remove restriction
  2583. a Agenda for current week or day e Export agenda views
  2584. t List of all TODO entries T Entries with special TODO kwd
  2585. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2586. s Search for keywords S Like s, but only TODO entries
  2587. L Timeline for current buffer # List stuck projects (!=configure)
  2588. / Multi-occur C Configure custom agenda commands
  2589. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2590. ")
  2591. (start 0))
  2592. (while (string-match
  2593. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2594. header start)
  2595. (setq start (match-end 0))
  2596. (add-text-properties (match-beginning 2) (match-end 2)
  2597. '(face bold) header))
  2598. header)))
  2599. (setq header-end (point-marker))
  2600. (while t
  2601. (setq custom1 custom)
  2602. (when (eq rmheader t)
  2603. (org-goto-line 1)
  2604. (re-search-forward ":" nil t)
  2605. (delete-region (match-end 0) (point-at-eol))
  2606. (forward-char 1)
  2607. (looking-at "-+")
  2608. (delete-region (match-end 0) (point-at-eol))
  2609. (move-marker header-end (match-end 0)))
  2610. (goto-char header-end)
  2611. (delete-region (point) (point-max))
  2612. ;; Produce all the lines that describe custom commands and prefixes
  2613. (setq lines nil)
  2614. (while (setq entry (pop custom1))
  2615. (setq key (car entry) desc (nth 1 entry)
  2616. type (nth 2 entry)
  2617. match (nth 3 entry))
  2618. (if (> (length key) 1)
  2619. (add-to-list 'prefixes (string-to-char key))
  2620. (setq line
  2621. (format
  2622. "%-4s%-14s"
  2623. (org-add-props (copy-sequence key)
  2624. '(face bold))
  2625. (cond
  2626. ((string-match "\\S-" desc) desc)
  2627. ((eq type 'agenda) "Agenda for current week or day")
  2628. ((eq type 'agenda*) "Appointments for current week or day")
  2629. ((eq type 'alltodo) "List of all TODO entries")
  2630. ((eq type 'search) "Word search")
  2631. ((eq type 'stuck) "List of stuck projects")
  2632. ((eq type 'todo) "TODO keyword")
  2633. ((eq type 'tags) "Tags query")
  2634. ((eq type 'tags-todo) "Tags (TODO)")
  2635. ((eq type 'tags-tree) "Tags tree")
  2636. ((eq type 'todo-tree) "TODO kwd tree")
  2637. ((eq type 'occur-tree) "Occur tree")
  2638. ((functionp type) (if (symbolp type)
  2639. (symbol-name type)
  2640. "Lambda expression"))
  2641. (t "???"))))
  2642. (if org-agenda-menu-show-matcher
  2643. (setq line
  2644. (concat line ": "
  2645. (cond
  2646. ((stringp match)
  2647. (setq match (copy-sequence match))
  2648. (org-add-props match nil 'face 'org-warning))
  2649. ((listp type)
  2650. (format "set of %d commands" (length type))))))
  2651. (if (org-string-nw-p match)
  2652. (add-text-properties
  2653. 0 (length line) (list 'help-echo
  2654. (concat "Matcher: " match)) line)))
  2655. (push line lines)))
  2656. (setq lines (nreverse lines))
  2657. (when prefixes
  2658. (mapc (lambda (x)
  2659. (push
  2660. (format "%s %s"
  2661. (org-add-props (char-to-string x)
  2662. nil 'face 'bold)
  2663. (or (cdr (assoc (concat selstring
  2664. (char-to-string x))
  2665. prefix-descriptions))
  2666. "Prefix key"))
  2667. lines))
  2668. prefixes))
  2669. ;; Check if we should display in two columns
  2670. (if org-agenda-menu-two-columns
  2671. (progn
  2672. (setq n (length lines)
  2673. n1 (+ (/ n 2) (mod n 2))
  2674. right (nthcdr n1 lines)
  2675. left (copy-sequence lines))
  2676. (setcdr (nthcdr (1- n1) left) nil))
  2677. (setq left lines right nil))
  2678. (while left
  2679. (insert "\n" (pop left))
  2680. (when right
  2681. (if (< (current-column) 40)
  2682. (move-to-column 40 t)
  2683. (insert " "))
  2684. (insert (pop right))))
  2685. ;; Make the window the right size
  2686. (goto-char (point-min))
  2687. (if second-time
  2688. (if (not (pos-visible-in-window-p (point-max)))
  2689. (org-fit-window-to-buffer))
  2690. (setq second-time t)
  2691. (org-fit-window-to-buffer))
  2692. ;; Ask for selection
  2693. (message "Press key for agenda command%s:"
  2694. (if (or restrict-ok org-agenda-overriding-restriction)
  2695. (if org-agenda-overriding-restriction
  2696. " (restriction lock active)"
  2697. (if restriction
  2698. (format " (restricted to %s)" restriction)
  2699. " (unrestricted)"))
  2700. ""))
  2701. (setq c (read-char-exclusive))
  2702. (message "")
  2703. (cond
  2704. ((assoc (char-to-string c) custom)
  2705. (setq selstring (concat selstring (char-to-string c)))
  2706. (throw 'exit (cons selstring restriction)))
  2707. ((memq c prefixes)
  2708. (setq selstring (concat selstring (char-to-string c))
  2709. prefixes nil
  2710. rmheader (or rmheader t)
  2711. custom (delq nil (mapcar
  2712. (lambda (x)
  2713. (if (or (= (length (car x)) 1)
  2714. (/= (string-to-char (car x)) c))
  2715. nil
  2716. (cons (substring (car x) 1) (cdr x))))
  2717. custom))))
  2718. ((eq c ?*)
  2719. (call-interactively 'org-toggle-sticky-agenda)
  2720. (sit-for 2))
  2721. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2722. (message "Restriction is only possible in Org-mode buffers")
  2723. (ding) (sit-for 1))
  2724. ((eq c ?1)
  2725. (org-agenda-remove-restriction-lock 'noupdate)
  2726. (setq restriction 'buffer))
  2727. ((eq c ?0)
  2728. (org-agenda-remove-restriction-lock 'noupdate)
  2729. (setq restriction (if region-p 'region 'subtree)))
  2730. ((eq c ?<)
  2731. (org-agenda-remove-restriction-lock 'noupdate)
  2732. (setq restriction
  2733. (cond
  2734. ((eq restriction 'buffer)
  2735. (if region-p 'region 'subtree))
  2736. ((memq restriction '(subtree region))
  2737. nil)
  2738. (t 'buffer))))
  2739. ((eq c ?>)
  2740. (org-agenda-remove-restriction-lock 'noupdate)
  2741. (setq restriction nil))
  2742. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2743. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2744. ((and (> (length selstring) 0) (eq c ?\d))
  2745. (delete-window)
  2746. (org-agenda-get-restriction-and-command prefix-descriptions))
  2747. ((equal c ?q) (error "Abort"))
  2748. (t (user-error "Invalid key %c" c))))))))
  2749. (defun org-agenda-fit-window-to-buffer ()
  2750. "Fit the window to the buffer size."
  2751. (and (memq org-agenda-window-setup '(reorganize-frame))
  2752. (fboundp 'fit-window-to-buffer)
  2753. (org-fit-window-to-buffer
  2754. nil
  2755. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2756. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2757. (defvar org-cmd nil)
  2758. (defvar org-agenda-overriding-cmd nil)
  2759. (defvar org-agenda-overriding-arguments nil)
  2760. (defvar org-agenda-overriding-cmd-arguments nil)
  2761. (defun org-agenda-run-series (name series)
  2762. "Run agenda NAME as a SERIES of agenda commands."
  2763. (org-let (nth 1 series) '(org-agenda-prepare name))
  2764. ;; We need to reset agenda markers here, because when constructing a
  2765. ;; block agenda, the individual blocks do not do that.
  2766. (org-agenda-reset-markers)
  2767. (let* ((org-agenda-multi t)
  2768. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2769. (cmds (car series))
  2770. (gprops (nth 1 series))
  2771. match ;; The byte compiler incorrectly complains about this. Keep it!
  2772. org-cmd type lprops)
  2773. (while (setq org-cmd (pop cmds))
  2774. (setq type (car org-cmd)
  2775. match (eval (nth 1 org-cmd))
  2776. lprops (nth 2 org-cmd))
  2777. (let ((org-agenda-overriding-arguments
  2778. (if (eq org-agenda-overriding-cmd org-cmd)
  2779. (or org-agenda-overriding-arguments
  2780. org-agenda-overriding-cmd-arguments))))
  2781. (cond
  2782. ((eq type 'agenda)
  2783. (org-let2 gprops lprops
  2784. '(call-interactively 'org-agenda-list)))
  2785. ((eq type 'agenda*)
  2786. (org-let2 gprops lprops
  2787. '(funcall 'org-agenda-list nil nil t)))
  2788. ((eq type 'alltodo)
  2789. (org-let2 gprops lprops
  2790. '(call-interactively 'org-todo-list)))
  2791. ((eq type 'search)
  2792. (org-let2 gprops lprops
  2793. '(org-search-view current-prefix-arg match nil)))
  2794. ((eq type 'stuck)
  2795. (org-let2 gprops lprops
  2796. '(call-interactively 'org-agenda-list-stuck-projects)))
  2797. ((eq type 'tags)
  2798. (org-let2 gprops lprops
  2799. '(org-tags-view current-prefix-arg match)))
  2800. ((eq type 'tags-todo)
  2801. (org-let2 gprops lprops
  2802. '(org-tags-view '(4) match)))
  2803. ((eq type 'todo)
  2804. (org-let2 gprops lprops
  2805. '(org-todo-list match)))
  2806. ((fboundp type)
  2807. (org-let2 gprops lprops
  2808. '(funcall type match)))
  2809. (t (error "Invalid type in command series")))))
  2810. (widen)
  2811. (let ((inhibit-read-only t))
  2812. (add-text-properties (point-min) (point-max)
  2813. `(org-series t org-series-redo-cmd ,redo)))
  2814. (setq org-agenda-redo-command redo)
  2815. (goto-char (point-min)))
  2816. (org-agenda-fit-window-to-buffer)
  2817. (org-let (nth 1 series) '(org-agenda-finalize)))
  2818. ;;;###autoload
  2819. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2820. "Run an agenda command in batch mode and send the result to STDOUT.
  2821. If CMD-KEY is a string of length 1, it is used as a key in
  2822. `org-agenda-custom-commands' and triggers this command. If it is a
  2823. longer string it is used as a tags/todo match string.
  2824. Parameters are alternating variable names and values that will be bound
  2825. before running the agenda command."
  2826. (org-eval-in-environment (org-make-parameter-alist parameters)
  2827. (if (> (length cmd-key) 2)
  2828. (org-tags-view nil cmd-key)
  2829. (org-agenda nil cmd-key)))
  2830. (set-buffer org-agenda-buffer-name)
  2831. (princ (buffer-string)))
  2832. (defvar org-agenda-info nil)
  2833. ;;;###autoload
  2834. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2835. "Run an agenda command in batch mode and send the result to STDOUT.
  2836. If CMD-KEY is a string of length 1, it is used as a key in
  2837. `org-agenda-custom-commands' and triggers this command. If it is a
  2838. longer string it is used as a tags/todo match string.
  2839. Parameters are alternating variable names and values that will be bound
  2840. before running the agenda command.
  2841. The output gives a line for each selected agenda item. Each
  2842. item is a list of comma-separated values, like this:
  2843. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2844. category The category of the item
  2845. head The headline, without TODO kwd, TAGS and PRIORITY
  2846. type The type of the agenda entry, can be
  2847. todo selected in TODO match
  2848. tagsmatch selected in tags match
  2849. diary imported from diary
  2850. deadline a deadline on given date
  2851. scheduled scheduled on given date
  2852. timestamp entry has timestamp on given date
  2853. closed entry was closed on given date
  2854. upcoming-deadline warning about deadline
  2855. past-scheduled forwarded scheduled item
  2856. block entry has date block including g. date
  2857. todo The todo keyword, if any
  2858. tags All tags including inherited ones, separated by colons
  2859. date The relevant date, like 2007-2-14
  2860. time The time, like 15:00-16:50
  2861. extra Sting with extra planning info
  2862. priority-l The priority letter if any was given
  2863. priority-n The computed numerical priority
  2864. agenda-day The day in the agenda where this is listed"
  2865. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2866. (org-make-parameter-alist parameters))
  2867. (if (> (length cmd-key) 2)
  2868. (org-tags-view nil cmd-key)
  2869. (org-agenda nil cmd-key)))
  2870. (set-buffer org-agenda-buffer-name)
  2871. (let* ((lines (org-split-string (buffer-string) "\n"))
  2872. line)
  2873. (while (setq line (pop lines))
  2874. (catch 'next
  2875. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2876. (setq org-agenda-info
  2877. (org-fix-agenda-info (text-properties-at 0 line)))
  2878. (princ
  2879. (mapconcat 'org-agenda-export-csv-mapper
  2880. '(org-category txt type todo tags date time extra
  2881. priority-letter priority agenda-day)
  2882. ","))
  2883. (princ "\n")))))
  2884. (defun org-fix-agenda-info (props)
  2885. "Make sure all properties on an agenda item have a canonical form.
  2886. This ensures the export commands can easily use it."
  2887. (let (tmp re)
  2888. (when (setq tmp (plist-get props 'tags))
  2889. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2890. (when (setq tmp (plist-get props 'date))
  2891. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2892. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2893. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2894. (setq tmp (calendar-date-string tmp)))
  2895. (setq props (plist-put props 'date tmp)))
  2896. (when (setq tmp (plist-get props 'day))
  2897. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2898. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2899. (setq tmp (calendar-date-string tmp)))
  2900. (setq props (plist-put props 'day tmp))
  2901. (setq props (plist-put props 'agenda-day tmp)))
  2902. (when (setq tmp (plist-get props 'txt))
  2903. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2904. (plist-put props 'priority-letter (match-string 1 tmp))
  2905. (setq tmp (replace-match "" t t tmp)))
  2906. (when (and (setq re (plist-get props 'org-todo-regexp))
  2907. (setq re (concat "\\`\\.*" re " ?"))
  2908. (string-match re tmp))
  2909. (plist-put props 'todo (match-string 1 tmp))
  2910. (setq tmp (replace-match "" t t tmp)))
  2911. (plist-put props 'txt tmp)))
  2912. props)
  2913. (defun org-agenda-export-csv-mapper (prop)
  2914. (let ((res (plist-get org-agenda-info prop)))
  2915. (setq res
  2916. (cond
  2917. ((not res) "")
  2918. ((stringp res) res)
  2919. (t (prin1-to-string res))))
  2920. (while (string-match "," res)
  2921. (setq res (replace-match ";" t t res)))
  2922. (org-trim res)))
  2923. ;;;###autoload
  2924. (defun org-store-agenda-views (&rest parameters)
  2925. "Store agenda views."
  2926. (interactive)
  2927. (eval (list 'org-batch-store-agenda-views)))
  2928. ;;;###autoload
  2929. (defmacro org-batch-store-agenda-views (&rest parameters)
  2930. "Run all custom agenda commands that have a file argument."
  2931. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2932. (pop-up-frames nil)
  2933. (dir default-directory)
  2934. (pars (org-make-parameter-alist parameters))
  2935. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2936. (save-window-excursion
  2937. (while cmds
  2938. (setq cmd (pop cmds)
  2939. thiscmdkey (car cmd)
  2940. thiscmdcmd (cdr cmd)
  2941. match (nth 2 thiscmdcmd)
  2942. bufname (if org-agenda-sticky
  2943. (or (and (stringp match)
  2944. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2945. (format "*Org Agenda(%s)*" thiscmdkey))
  2946. org-agenda-buffer-name)
  2947. cmd-or-set (nth 2 cmd)
  2948. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2949. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2950. (if (stringp files) (setq files (list files)))
  2951. (when files
  2952. (org-eval-in-environment (append org-agenda-exporter-settings
  2953. opts pars)
  2954. (org-agenda nil thiscmdkey))
  2955. (set-buffer bufname)
  2956. (while files
  2957. (org-eval-in-environment (append org-agenda-exporter-settings
  2958. opts pars)
  2959. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2960. (and (get-buffer bufname)
  2961. (kill-buffer bufname)))))))
  2962. (defvar org-agenda-current-span nil
  2963. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2964. (defun org-agenda-mark-header-line (pos)
  2965. "Mark the line at POS as an agenda structure header."
  2966. (save-excursion
  2967. (goto-char pos)
  2968. (put-text-property (point-at-bol) (point-at-eol)
  2969. 'org-agenda-structural-header t)
  2970. (when org-agenda-title-append
  2971. (put-text-property (point-at-bol) (point-at-eol)
  2972. 'org-agenda-title-append org-agenda-title-append))))
  2973. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2974. (defvar org-agenda-write-buffer-name "Agenda View")
  2975. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2976. "Write the current buffer (an agenda view) as a file.
  2977. Depending on the extension of the file name, plain text (.txt),
  2978. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2979. If the extension is .ics, run icalendar export over all files used
  2980. to construct the agenda and limit the export to entries listed in the
  2981. agenda now.
  2982. If the extension is .org, collect all subtrees corresponding to the
  2983. agenda entries and add them in an .org file.
  2984. With prefix argument OPEN, open the new file immediately.
  2985. If NOSETTINGS is given, do not scope the settings of
  2986. `org-agenda-exporter-settings' into the export commands. This is used when
  2987. the settings have already been scoped and we do not wish to overrule other,
  2988. higher priority settings.
  2989. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2990. (interactive "FWrite agenda to file: \nP")
  2991. (if (or (not (file-writable-p file))
  2992. (and (file-exists-p file)
  2993. (if (called-interactively-p 'any)
  2994. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  2995. (user-error "Cannot write agenda to file %s" file))
  2996. (org-let (if nosettings nil org-agenda-exporter-settings)
  2997. '(save-excursion
  2998. (save-window-excursion
  2999. (org-agenda-mark-filtered-text)
  3000. (let ((bs (copy-sequence (buffer-string))) beg content)
  3001. (org-agenda-unmark-filtered-text)
  3002. (with-temp-buffer
  3003. (rename-buffer org-agenda-write-buffer-name t)
  3004. (set-buffer-modified-p nil)
  3005. (insert bs)
  3006. (org-agenda-remove-marked-text 'org-filtered)
  3007. (while (setq beg (text-property-any (point-min) (point-max)
  3008. 'org-filtered t))
  3009. (delete-region
  3010. beg (or (next-single-property-change beg 'org-filtered)
  3011. (point-max))))
  3012. (run-hooks 'org-agenda-before-write-hook)
  3013. (cond
  3014. ((org-bound-and-true-p org-mobile-creating-agendas)
  3015. (org-mobile-write-agenda-for-mobile file))
  3016. ((string-match "\\.org\\'" file)
  3017. (let (content p m message-log-max)
  3018. (goto-char (point-min))
  3019. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3020. (goto-char p)
  3021. (setq m (get-text-property (point) 'org-hd-marker))
  3022. (when m
  3023. (push (save-excursion
  3024. (set-buffer (marker-buffer m))
  3025. (goto-char m)
  3026. (org-copy-subtree 1 nil t t)
  3027. org-subtree-clip)
  3028. content)))
  3029. (find-file file)
  3030. (erase-buffer)
  3031. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3032. (write-file file)
  3033. (kill-buffer (current-buffer))
  3034. (message "Org file written to %s" file)))
  3035. ((string-match "\\.html?\\'" file)
  3036. (require 'htmlize)
  3037. (set-buffer (htmlize-buffer (current-buffer)))
  3038. (when org-agenda-export-html-style
  3039. ;; replace <style> section with org-agenda-export-html-style
  3040. (goto-char (point-min))
  3041. (kill-region (- (search-forward "<style") 6)
  3042. (search-forward "</style>"))
  3043. (insert org-agenda-export-html-style))
  3044. (write-file file)
  3045. (kill-buffer (current-buffer))
  3046. (message "HTML written to %s" file))
  3047. ((string-match "\\.ps\\'" file)
  3048. (require 'ps-print)
  3049. (ps-print-buffer-with-faces file)
  3050. (message "Postscript written to %s" file))
  3051. ((string-match "\\.pdf\\'" file)
  3052. (require 'ps-print)
  3053. (ps-print-buffer-with-faces
  3054. (concat (file-name-sans-extension file) ".ps"))
  3055. (call-process "ps2pdf" nil nil nil
  3056. (expand-file-name
  3057. (concat (file-name-sans-extension file) ".ps"))
  3058. (expand-file-name file))
  3059. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3060. (message "PDF written to %s" file))
  3061. ((string-match "\\.ics\\'" file)
  3062. (require 'ox-icalendar)
  3063. (org-icalendar-export-current-agenda (expand-file-name file)))
  3064. (t
  3065. (let ((bs (buffer-string)))
  3066. (find-file file)
  3067. (erase-buffer)
  3068. (insert bs)
  3069. (save-buffer 0)
  3070. (kill-buffer (current-buffer))
  3071. (message "Plain text written to %s" file))))))))
  3072. (set-buffer (or agenda-bufname
  3073. (and (org-called-interactively-p 'any) (buffer-name))
  3074. org-agenda-buffer-name)))
  3075. (when open (org-open-file file)))
  3076. (defvar org-agenda-tag-filter-overlays nil)
  3077. (defvar org-agenda-cat-filter-overlays nil)
  3078. (defvar org-agenda-re-filter-overlays nil)
  3079. (defun org-agenda-mark-filtered-text ()
  3080. "Mark all text hidden by filtering with a text property."
  3081. (let ((inhibit-read-only t))
  3082. (mapc
  3083. (lambda (o)
  3084. (when (equal (overlay-buffer o) (current-buffer))
  3085. (put-text-property
  3086. (overlay-start o) (overlay-end o)
  3087. 'org-filtered t)))
  3088. (append org-agenda-tag-filter-overlays
  3089. org-agenda-cat-filter-overlays
  3090. org-agenda-re-filter-overlays))))
  3091. (defun org-agenda-unmark-filtered-text ()
  3092. "Remove the filtering text property."
  3093. (let ((inhibit-read-only t))
  3094. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3095. (defun org-agenda-remove-marked-text (property &optional value)
  3096. "Delete all text marked with VALUE of PROPERTY.
  3097. VALUE defaults to t."
  3098. (let (beg)
  3099. (setq value (or value t))
  3100. (while (setq beg (text-property-any (point-min) (point-max)
  3101. property value))
  3102. (delete-region
  3103. beg (or (next-single-property-change beg 'org-filtered)
  3104. (point-max))))))
  3105. (defun org-agenda-add-entry-text ()
  3106. "Add entry text to agenda lines.
  3107. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3108. entry text following headings shown in the agenda.
  3109. Drawers will be excluded, also the line with scheduling/deadline info."
  3110. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3111. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3112. (let (m txt)
  3113. (goto-char (point-min))
  3114. (while (not (eobp))
  3115. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3116. (beginning-of-line 2)
  3117. (setq txt (org-agenda-get-some-entry-text
  3118. m org-agenda-add-entry-text-maxlines " > "))
  3119. (end-of-line 1)
  3120. (if (string-match "\\S-" txt)
  3121. (insert "\n" txt)
  3122. (or (eobp) (forward-char 1))))))))
  3123. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3124. &rest keep)
  3125. "Extract entry text from MARKER, at most N-LINES lines.
  3126. This will ignore drawers etc, just get the text.
  3127. If INDENT is given, prefix every line with this string. If KEEP is
  3128. given, it is a list of symbols, defining stuff that should not be
  3129. removed from the entry content. Currently only `planning' is allowed here."
  3130. (let (txt drawer-re kwd-time-re ind)
  3131. (save-excursion
  3132. (with-current-buffer (marker-buffer marker)
  3133. (if (not (derived-mode-p 'org-mode))
  3134. (setq txt "")
  3135. (save-excursion
  3136. (save-restriction
  3137. (widen)
  3138. (goto-char marker)
  3139. (end-of-line 1)
  3140. (setq txt (buffer-substring
  3141. (min (1+ (point)) (point-max))
  3142. (progn (outline-next-heading) (point)))
  3143. drawer-re org-drawer-regexp
  3144. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3145. ".*\n?"))
  3146. (with-temp-buffer
  3147. (insert txt)
  3148. (when org-agenda-add-entry-text-descriptive-links
  3149. (goto-char (point-min))
  3150. (while (org-activate-bracket-links (point-max))
  3151. (add-text-properties (match-beginning 0) (match-end 0)
  3152. '(face org-link))))
  3153. (goto-char (point-min))
  3154. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3155. (set-text-properties (match-beginning 0) (match-end 0)
  3156. nil))
  3157. (goto-char (point-min))
  3158. (while (re-search-forward drawer-re nil t)
  3159. (delete-region
  3160. (match-beginning 0)
  3161. (progn (re-search-forward
  3162. "^[ \t]*:END:.*\n?" nil 'move)
  3163. (point))))
  3164. (unless (member 'planning keep)
  3165. (goto-char (point-min))
  3166. (while (re-search-forward kwd-time-re nil t)
  3167. (replace-match "")))
  3168. (goto-char (point-min))
  3169. (when org-agenda-entry-text-exclude-regexps
  3170. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3171. (while (setq re (pop re-list))
  3172. (goto-char (point-min))
  3173. (while (re-search-forward re nil t)
  3174. (replace-match "")))))
  3175. (goto-char (point-max))
  3176. (skip-chars-backward " \t\n")
  3177. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3178. ;; find and remove min common indentation
  3179. (goto-char (point-min))
  3180. (untabify (point-min) (point-max))
  3181. (setq ind (org-get-indentation))
  3182. (while (not (eobp))
  3183. (unless (looking-at "[ \t]*$")
  3184. (setq ind (min ind (org-get-indentation))))
  3185. (beginning-of-line 2))
  3186. (goto-char (point-min))
  3187. (while (not (eobp))
  3188. (unless (looking-at "[ \t]*$")
  3189. (move-to-column ind)
  3190. (delete-region (point-at-bol) (point)))
  3191. (beginning-of-line 2))
  3192. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3193. (goto-char (point-min))
  3194. (when indent
  3195. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3196. (replace-match indent t t)))
  3197. (goto-char (point-min))
  3198. (while (looking-at "[ \t]*\n") (replace-match ""))
  3199. (goto-char (point-max))
  3200. (when (> (org-current-line)
  3201. n-lines)
  3202. (org-goto-line (1+ n-lines))
  3203. (backward-char 1))
  3204. (setq txt (buffer-substring (point-min) (point)))))))))
  3205. txt))
  3206. (defun org-check-for-org-mode ()
  3207. "Make sure current buffer is in org-mode. Error if not."
  3208. (or (derived-mode-p 'org-mode)
  3209. (error "Cannot execute org-mode agenda command on buffer in %s"
  3210. major-mode)))
  3211. ;;; Agenda prepare and finalize
  3212. (defvar org-agenda-multi nil) ; dynamically scoped
  3213. (defvar org-agenda-pre-window-conf nil)
  3214. (defvar org-agenda-columns-active nil)
  3215. (defvar org-agenda-name nil)
  3216. (defvar org-agenda-tag-filter nil)
  3217. (defvar org-agenda-category-filter nil)
  3218. (defvar org-agenda-regexp-filter nil)
  3219. (defvar org-agenda-top-headline-filter nil)
  3220. (defvar org-agenda-tag-filter-while-redo nil)
  3221. (defvar org-agenda-tag-filter-preset nil
  3222. "A preset of the tags filter used for secondary agenda filtering.
  3223. This must be a list of strings, each string must be a single tag preceded
  3224. by \"+\" or \"-\".
  3225. This variable should not be set directly, but agenda custom commands can
  3226. bind it in the options section. The preset filter is a global property of
  3227. the entire agenda view. In a block agenda, it will not work reliably to
  3228. define a filter for one of the individual blocks. You need to set it in
  3229. the global options and expect it to be applied to the entire view.")
  3230. (defvar org-agenda-category-filter-preset nil
  3231. "A preset of the category filter used for secondary agenda filtering.
  3232. This must be a list of strings, each string must be a single category
  3233. preceded by \"+\" or \"-\".
  3234. This variable should not be set directly, but agenda custom commands can
  3235. bind it in the options section. The preset filter is a global property of
  3236. the entire agenda view. In a block agenda, it will not work reliably to
  3237. define a filter for one of the individual blocks. You need to set it in
  3238. the global options and expect it to be applied to the entire view.")
  3239. (defvar org-agenda-regexp-filter-preset nil
  3240. "A preset of the regexp filter used for secondary agenda filtering.
  3241. This must be a list of strings, each string must be a single category
  3242. preceded by \"+\" or \"-\".
  3243. This variable should not be set directly, but agenda custom commands can
  3244. bind it in the options section. The preset filter is a global property of
  3245. the entire agenda view. In a block agenda, it will not work reliably to
  3246. define a filter for one of the individual blocks. You need to set it in
  3247. the global options and expect it to be applied to the entire view.")
  3248. (defun org-agenda-use-sticky-p ()
  3249. "Return non-nil if an agenda buffer named
  3250. `org-agenda-buffer-name' exists and should be shown instead of
  3251. generating a new one."
  3252. (and
  3253. ;; turned off by user
  3254. org-agenda-sticky
  3255. ;; For multi-agenda buffer already exists
  3256. (not org-agenda-multi)
  3257. ;; buffer found
  3258. (get-buffer org-agenda-buffer-name)
  3259. ;; C-u parameter is same as last call
  3260. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3261. (and
  3262. (equal current-prefix-arg
  3263. org-agenda-last-prefix-arg)
  3264. ;; In case user turned stickiness on, while having existing
  3265. ;; Agenda buffer active, don't reuse that buffer, because it
  3266. ;; does not have org variables local
  3267. org-agenda-this-buffer-is-sticky))))
  3268. (defun org-agenda-prepare-window (abuf)
  3269. "Setup agenda buffer in the window."
  3270. (let* ((awin (get-buffer-window abuf))
  3271. wconf)
  3272. (cond
  3273. ((equal (current-buffer) abuf) nil)
  3274. (awin (select-window awin))
  3275. ((not (setq wconf (current-window-configuration))))
  3276. ((equal org-agenda-window-setup 'current-window)
  3277. (org-pop-to-buffer-same-window abuf))
  3278. ((equal org-agenda-window-setup 'other-window)
  3279. (org-switch-to-buffer-other-window abuf))
  3280. ((equal org-agenda-window-setup 'other-frame)
  3281. (switch-to-buffer-other-frame abuf))
  3282. ((equal org-agenda-window-setup 'reorganize-frame)
  3283. (delete-other-windows)
  3284. (org-switch-to-buffer-other-window abuf)))
  3285. ;; additional test in case agenda is invoked from within agenda
  3286. ;; buffer via elisp link
  3287. (unless (equal (current-buffer) abuf)
  3288. (org-pop-to-buffer-same-window abuf))
  3289. (setq org-agenda-pre-window-conf
  3290. (or org-agenda-pre-window-conf wconf))))
  3291. (defun org-agenda-prepare (&optional name)
  3292. (if (org-agenda-use-sticky-p)
  3293. (progn
  3294. ;; Popup existing buffer
  3295. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3296. (message "Sticky Agenda buffer, use `r' to refresh")
  3297. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3298. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3299. (setq org-todo-keywords-for-agenda nil)
  3300. (setq org-drawers-for-agenda nil)
  3301. (unless org-agenda-persistent-filter
  3302. (setq org-agenda-tag-filter nil
  3303. org-agenda-category-filter nil
  3304. org-agenda-regexp-filter nil))
  3305. (put 'org-agenda-tag-filter :preset-filter
  3306. org-agenda-tag-filter-preset)
  3307. (put 'org-agenda-category-filter :preset-filter
  3308. org-agenda-category-filter-preset)
  3309. (put 'org-agenda-regexp-filter :preset-filter
  3310. org-agenda-regexp-filter-preset)
  3311. (if org-agenda-multi
  3312. (progn
  3313. (setq buffer-read-only nil)
  3314. (goto-char (point-max))
  3315. (unless (or (bobp) org-agenda-compact-blocks
  3316. (not org-agenda-block-separator))
  3317. (insert "\n"
  3318. (if (stringp org-agenda-block-separator)
  3319. org-agenda-block-separator
  3320. (make-string (window-width) org-agenda-block-separator))
  3321. "\n"))
  3322. (narrow-to-region (point) (point-max)))
  3323. (setq org-done-keywords-for-agenda nil)
  3324. ;; Setting any org variables that are in org-agenda-local-vars
  3325. ;; list need to be done after the prepare call
  3326. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3327. (setq buffer-read-only nil)
  3328. (org-agenda-reset-markers)
  3329. (let ((inhibit-read-only t)) (erase-buffer))
  3330. (org-agenda-mode)
  3331. (setq org-agenda-buffer (current-buffer))
  3332. (setq org-agenda-contributing-files nil)
  3333. (setq org-agenda-columns-active nil)
  3334. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3335. (setq org-todo-keywords-for-agenda
  3336. (org-uniquify org-todo-keywords-for-agenda))
  3337. (setq org-done-keywords-for-agenda
  3338. (org-uniquify org-done-keywords-for-agenda))
  3339. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3340. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3341. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3342. (and name (not org-agenda-name)
  3343. (org-set-local 'org-agenda-name name)))
  3344. (setq buffer-read-only nil)))
  3345. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3346. (defun org-agenda-finalize ()
  3347. "Finishing touch for the agenda buffer, called just before displaying it."
  3348. (unless org-agenda-multi
  3349. (save-excursion
  3350. (let ((inhibit-read-only t))
  3351. (goto-char (point-min))
  3352. (save-excursion
  3353. (while (org-activate-bracket-links (point-max))
  3354. (add-text-properties (match-beginning 0) (match-end 0)
  3355. '(face org-link))))
  3356. (save-excursion
  3357. (while (org-activate-plain-links (point-max))
  3358. (add-text-properties (match-beginning 0) (match-end 0)
  3359. '(face org-link))))
  3360. (unless (eq org-agenda-remove-tags t)
  3361. (org-agenda-align-tags))
  3362. (unless org-agenda-with-colors
  3363. (remove-text-properties (point-min) (point-max) '(face nil)))
  3364. (if (and (boundp 'org-agenda-overriding-columns-format)
  3365. org-agenda-overriding-columns-format)
  3366. (org-set-local 'org-agenda-overriding-columns-format
  3367. org-agenda-overriding-columns-format))
  3368. (if (and (boundp 'org-agenda-view-columns-initially)
  3369. org-agenda-view-columns-initially)
  3370. (org-agenda-columns))
  3371. (when org-agenda-fontify-priorities
  3372. (org-agenda-fontify-priorities))
  3373. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3374. (org-agenda-dim-blocked-tasks))
  3375. ;; We need to widen when `org-agenda-finalize' is called from
  3376. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3377. (when org-clock-current-task
  3378. (save-restriction
  3379. (widen)
  3380. (org-agenda-mark-clocking-task)))
  3381. (when org-agenda-entry-text-mode
  3382. (org-agenda-entry-text-hide)
  3383. (org-agenda-entry-text-show))
  3384. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3385. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3386. (org-habit-insert-consistency-graphs))
  3387. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3388. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3389. (and (listp org-agenda-show-inherited-tags)
  3390. (memq org-agenda-type org-agenda-show-inherited-tags))
  3391. (and (eq org-agenda-show-inherited-tags t)
  3392. (or (eq org-agenda-use-tag-inheritance t)
  3393. (and (listp org-agenda-use-tag-inheritance)
  3394. (not (memq org-agenda-type
  3395. org-agenda-use-tag-inheritance))))))
  3396. (let (mrk)
  3397. (save-excursion
  3398. (goto-char (point-min))
  3399. (while (equal (forward-line) 0)
  3400. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3401. (get-text-property (point) 'org-hd-marker)))
  3402. (put-text-property (point-at-bol) (point-at-eol)
  3403. 'tags (org-with-point-at mrk
  3404. (delete-dups
  3405. (mapcar 'downcase (org-get-tags-at))))))))))
  3406. (run-hooks 'org-agenda-finalize-hook)
  3407. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3408. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3409. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3410. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3411. (when (or org-agenda-regexp-filter (get 'org-agenda-regexp-filter :preset-filter))
  3412. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3413. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3414. (defun org-agenda-mark-clocking-task ()
  3415. "Mark the current clock entry in the agenda if it is present."
  3416. (org-agenda-unmark-clocking-task)
  3417. (when (marker-buffer org-clock-hd-marker)
  3418. (save-excursion
  3419. (goto-char (point-min))
  3420. (let (s ov)
  3421. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3422. (goto-char s)
  3423. (when (equal (org-get-at-bol 'org-hd-marker)
  3424. org-clock-hd-marker)
  3425. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3426. (overlay-put ov 'type 'org-agenda-clocking)
  3427. (overlay-put ov 'face 'org-agenda-clocking)
  3428. (overlay-put ov 'help-echo
  3429. "The clock is running in this item")))))))
  3430. (defun org-agenda-unmark-clocking-task ()
  3431. "Unmark the current clocking task."
  3432. (mapc (lambda (o)
  3433. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3434. (delete-overlay o)))
  3435. (overlays-in (point-min) (point-max))))
  3436. (defun org-agenda-fontify-priorities ()
  3437. "Make highest priority lines bold, and lowest italic."
  3438. (interactive)
  3439. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3440. (delete-overlay o)))
  3441. (overlays-in (point-min) (point-max)))
  3442. (save-excursion
  3443. (let (b e p ov h l)
  3444. (goto-char (point-min))
  3445. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3446. (setq h (or (get-char-property (point) 'org-highest-priority)
  3447. org-highest-priority)
  3448. l (or (get-char-property (point) 'org-lowest-priority)
  3449. org-lowest-priority)
  3450. p (string-to-char (match-string 1))
  3451. b (match-beginning 0)
  3452. e (if (eq org-agenda-fontify-priorities 'cookies)
  3453. (match-end 0)
  3454. (point-at-eol))
  3455. ov (make-overlay b e))
  3456. (overlay-put
  3457. ov 'face
  3458. (cons (cond ((org-face-from-face-or-color
  3459. 'priority nil
  3460. (cdr (assoc p org-priority-faces))))
  3461. ((and (listp org-agenda-fontify-priorities)
  3462. (org-face-from-face-or-color
  3463. 'priority nil
  3464. (cdr (assoc p org-agenda-fontify-priorities)))))
  3465. ((equal p l) 'italic)
  3466. ((equal p h) 'bold))
  3467. 'org-priority))
  3468. (overlay-put ov 'org-type 'org-priority)))))
  3469. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3470. "Dim currently blocked TODO's in the agenda display.
  3471. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3472. dimming them."
  3473. (interactive "P")
  3474. (when (org-called-interactively-p 'interactive)
  3475. (message "Dim or hide blocked tasks..."))
  3476. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3477. (delete-overlay o)))
  3478. (overlays-in (point-min) (point-max)))
  3479. (save-excursion
  3480. (let ((inhibit-read-only t)
  3481. (org-depend-tag-blocked nil)
  3482. (invis (or (not (null invisible))
  3483. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3484. org-blocked-by-checkboxes
  3485. invis1 b e p ov h l)
  3486. (goto-char (point-min))
  3487. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3488. (and pos (goto-char (1+ pos))))
  3489. (setq org-blocked-by-checkboxes nil invis1 invis)
  3490. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3491. (when (and marker
  3492. (with-current-buffer (marker-buffer marker)
  3493. (save-excursion (goto-char marker)
  3494. (org-entry-blocked-p))))
  3495. (if org-blocked-by-checkboxes (setq invis1 nil))
  3496. (setq b (if invis1
  3497. (max (point-min) (1- (point-at-bol)))
  3498. (point-at-bol))
  3499. e (point-at-eol)
  3500. ov (make-overlay b e))
  3501. (if invis1
  3502. (overlay-put ov 'invisible t)
  3503. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3504. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3505. (when (org-called-interactively-p 'interactive)
  3506. (message "Dim or hide blocked tasks...done")))
  3507. (defvar org-agenda-skip-function nil
  3508. "Function to be called at each match during agenda construction.
  3509. If this function returns nil, the current match should not be skipped.
  3510. Otherwise, the function must return a position from where the search
  3511. should be continued.
  3512. This may also be a Lisp form, it will be evaluated.
  3513. Never set this variable using `setq' or so, because then it will apply
  3514. to all future agenda commands. If you do want a global skipping condition,
  3515. use the option `org-agenda-skip-function-global' instead.
  3516. The correct usage for `org-agenda-skip-function' is to bind it with
  3517. `let' to scope it dynamically into the agenda-constructing command.
  3518. A good way to set it is through options in `org-agenda-custom-commands'.")
  3519. (defun org-agenda-skip ()
  3520. "Throw to `:skip' in places that should be skipped.
  3521. Also moves point to the end of the skipped region, so that search can
  3522. continue from there."
  3523. (let ((p (point-at-bol)) to)
  3524. (when (or
  3525. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3526. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3527. (get-text-property p :org-archived)
  3528. (org-end-of-subtree t))
  3529. (and org-agenda-skip-comment-trees
  3530. (get-text-property p :org-comment)
  3531. (org-end-of-subtree t))
  3532. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3533. (org-agenda-skip-eval org-agenda-skip-function)))
  3534. (goto-char to))
  3535. (org-in-src-block-p t))
  3536. (throw :skip t))))
  3537. (defun org-agenda-skip-eval (form)
  3538. "If FORM is a function or a list, call (or eval) is and return result.
  3539. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3540. and match data are returned to the previous state no matter what these
  3541. functions do."
  3542. (let (fp)
  3543. (and form
  3544. (or (setq fp (functionp form))
  3545. (consp form))
  3546. (save-excursion
  3547. (save-match-data
  3548. (if fp
  3549. (funcall form)
  3550. (eval form)))))))
  3551. (defvar org-agenda-markers nil
  3552. "List of all currently active markers created by `org-agenda'.")
  3553. (defvar org-agenda-last-marker-time (org-float-time)
  3554. "Creation time of the last agenda marker.")
  3555. (defun org-agenda-new-marker (&optional pos)
  3556. "Return a new agenda marker.
  3557. Org-mode keeps a list of these markers and resets them when they are
  3558. no longer in use."
  3559. (let ((m (copy-marker (or pos (point)))))
  3560. (setq org-agenda-last-marker-time (org-float-time))
  3561. (if org-agenda-buffer
  3562. (with-current-buffer org-agenda-buffer
  3563. (push m org-agenda-markers))
  3564. (push m org-agenda-markers))
  3565. m))
  3566. (defun org-agenda-reset-markers ()
  3567. "Reset markers created by `org-agenda'."
  3568. (while org-agenda-markers
  3569. (move-marker (pop org-agenda-markers) nil)))
  3570. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3571. "Save relative positions of markers in region.
  3572. This check for agenda markers in all agenda buffers currently active."
  3573. (dolist (buf (buffer-list))
  3574. (with-current-buffer buf
  3575. (when (eq major-mode 'org-agenda-mode)
  3576. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3577. org-agenda-markers)))))
  3578. ;;; Entry text mode
  3579. (defun org-agenda-entry-text-show-here ()
  3580. "Add some text from the entry as context to the current line."
  3581. (let (m txt o)
  3582. (setq m (org-get-at-bol 'org-hd-marker))
  3583. (unless (marker-buffer m)
  3584. (error "No marker points to an entry here"))
  3585. (setq txt (concat "\n" (org-no-properties
  3586. (org-agenda-get-some-entry-text
  3587. m org-agenda-entry-text-maxlines
  3588. org-agenda-entry-text-leaders))))
  3589. (when (string-match "\\S-" txt)
  3590. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3591. (overlay-put o 'evaporate t)
  3592. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3593. (overlay-put o 'after-string txt))))
  3594. (defun org-agenda-entry-text-show ()
  3595. "Add entry context for all agenda lines."
  3596. (interactive)
  3597. (save-excursion
  3598. (goto-char (point-max))
  3599. (beginning-of-line 1)
  3600. (while (not (bobp))
  3601. (when (org-get-at-bol 'org-hd-marker)
  3602. (org-agenda-entry-text-show-here))
  3603. (beginning-of-line 0))))
  3604. (defun org-agenda-entry-text-hide ()
  3605. "Remove any shown entry context."
  3606. (delq nil
  3607. (mapcar (lambda (o)
  3608. (if (eq (overlay-get o 'org-overlay-type)
  3609. 'agenda-entry-content)
  3610. (progn (delete-overlay o) t)))
  3611. (overlays-in (point-min) (point-max)))))
  3612. (defun org-agenda-get-day-face (date)
  3613. "Return the face DATE should be displayed with."
  3614. (or (and (functionp org-agenda-day-face-function)
  3615. (funcall org-agenda-day-face-function date))
  3616. (cond ((org-agenda-todayp date)
  3617. 'org-agenda-date-today)
  3618. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3619. 'org-agenda-date-weekend)
  3620. (t 'org-agenda-date))))
  3621. ;;; Agenda timeline
  3622. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3623. (defun org-timeline (&optional dotodo)
  3624. "Show a time-sorted view of the entries in the current org file.
  3625. Only entries with a time stamp of today or later will be listed. With
  3626. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3627. under the current date.
  3628. If the buffer contains an active region, only check the region for
  3629. dates."
  3630. (interactive "P")
  3631. (let* ((dopast t)
  3632. (org-agenda-show-log-scoped org-agenda-show-log)
  3633. (org-agenda-show-log org-agenda-show-log-scoped)
  3634. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3635. (current-buffer))))
  3636. (date (calendar-current-date))
  3637. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3638. (end (if (org-region-active-p) (region-end) (point-max)))
  3639. (day-numbers (org-get-all-dates
  3640. beg end 'no-ranges
  3641. t org-agenda-show-log-scoped ; always include today
  3642. org-timeline-show-empty-dates))
  3643. (org-deadline-warning-days 0)
  3644. (org-agenda-only-exact-dates t)
  3645. (today (org-today))
  3646. (past t)
  3647. args
  3648. s e rtn d emptyp)
  3649. (setq org-agenda-redo-command
  3650. (list 'let
  3651. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3652. (list 'org-switch-to-buffer-other-window (current-buffer))
  3653. (list 'org-timeline (list 'quote dotodo))))
  3654. (put 'org-agenda-redo-command 'org-lprops nil)
  3655. (if (not dopast)
  3656. ;; Remove past dates from the list of dates.
  3657. (setq day-numbers (delq nil (mapcar (lambda(x)
  3658. (if (>= x today) x nil))
  3659. day-numbers))))
  3660. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3661. (org-compile-prefix-format 'timeline)
  3662. (org-set-sorting-strategy 'timeline)
  3663. (if org-agenda-show-log-scoped (push :closed args))
  3664. (push :timestamp args)
  3665. (push :deadline args)
  3666. (push :scheduled args)
  3667. (push :sexp args)
  3668. (if dotodo (push :todo args))
  3669. (insert "Timeline of file " entry "\n")
  3670. (add-text-properties (point-min) (point)
  3671. (list 'face 'org-agenda-structure))
  3672. (org-agenda-mark-header-line (point-min))
  3673. (while (setq d (pop day-numbers))
  3674. (if (and (listp d) (eq (car d) :omitted))
  3675. (progn
  3676. (setq s (point))
  3677. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3678. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3679. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3680. (if (and (>= d today)
  3681. dopast
  3682. past)
  3683. (progn
  3684. (setq past nil)
  3685. (insert (make-string 79 ?-) "\n")))
  3686. (setq date (calendar-gregorian-from-absolute d))
  3687. (setq s (point))
  3688. (setq rtn (and (not emptyp)
  3689. (apply 'org-agenda-get-day-entries entry
  3690. date args)))
  3691. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3692. (progn
  3693. (insert
  3694. (if (stringp org-agenda-format-date)
  3695. (format-time-string org-agenda-format-date
  3696. (org-time-from-absolute date))
  3697. (funcall org-agenda-format-date date))
  3698. "\n")
  3699. (put-text-property s (1- (point)) 'face
  3700. (org-agenda-get-day-face date))
  3701. (put-text-property s (1- (point)) 'org-date-line t)
  3702. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3703. (if (equal d today)
  3704. (put-text-property s (1- (point)) 'org-today t))
  3705. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3706. (put-text-property s (1- (point)) 'day d)))))
  3707. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3708. (point-min)))
  3709. (add-text-properties
  3710. (point-min) (point-max)
  3711. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3712. (org-agenda-finalize)
  3713. (setq buffer-read-only t)))
  3714. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3715. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3716. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3717. not every single day in the range. If FORCE-TODAY is non-nil, make
  3718. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3719. inactive time stamps (those in square brackets) are included.
  3720. When EMPTY is non-nil, also include days without any entries."
  3721. (let ((re (concat
  3722. (if pre-re pre-re "")
  3723. (if inactive org-ts-regexp-both org-ts-regexp)))
  3724. dates dates1 date day day1 day2 ts1 ts2 pos)
  3725. (if force-today
  3726. (setq dates (list (org-today))))
  3727. (save-excursion
  3728. (goto-char beg)
  3729. (while (re-search-forward re end t)
  3730. (setq day (time-to-days (org-time-string-to-time
  3731. (substring (match-string 1) 0 10)
  3732. (current-buffer) (match-beginning 0))))
  3733. (or (memq day dates) (push day dates)))
  3734. (unless no-ranges
  3735. (goto-char beg)
  3736. (while (re-search-forward org-tr-regexp end t)
  3737. (setq pos (match-beginning 0))
  3738. (setq ts1 (substring (match-string 1) 0 10)
  3739. ts2 (substring (match-string 2) 0 10)
  3740. day1 (time-to-days (org-time-string-to-time
  3741. ts1 (current-buffer) pos))
  3742. day2 (time-to-days (org-time-string-to-time
  3743. ts2 (current-buffer) pos)))
  3744. (while (< (setq day1 (1+ day1)) day2)
  3745. (or (memq day1 dates) (push day1 dates)))))
  3746. (setq dates (sort dates '<))
  3747. (when empty
  3748. (while (setq day (pop dates))
  3749. (setq day2 (car dates))
  3750. (push day dates1)
  3751. (when (and day2 empty)
  3752. (if (or (eq empty t)
  3753. (and (numberp empty) (<= (- day2 day) empty)))
  3754. (while (< (setq day (1+ day)) day2)
  3755. (push (list day) dates1))
  3756. (push (cons :omitted (- day2 day)) dates1))))
  3757. (setq dates (nreverse dates1)))
  3758. dates)))
  3759. ;;; Agenda Daily/Weekly
  3760. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3761. "Start day for the agenda view.
  3762. Custom commands can set this variable in the options section.
  3763. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3764. input allowed when reading a date through the Org calendar.
  3765. See the docstring of `org-read-date' for details.")
  3766. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3767. (defvar org-arg-loc nil) ; local variable
  3768. (defvar org-agenda-buffer-tmp-name nil)
  3769. ;;;###autoload
  3770. (defun org-agenda-list (&optional arg start-day span with-hour)
  3771. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3772. The view will be for the current day or week, but from the overview buffer
  3773. you will be able to go to other days/weeks.
  3774. With a numeric prefix argument in an interactive call, the agenda will
  3775. span ARG days. Lisp programs should instead specify SPAN to change
  3776. the number of days. SPAN defaults to `org-agenda-span'.
  3777. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3778. given in `org-agenda-start-on-weekday'.
  3779. When WITH-HOUR is non-nil, only include scheduled and deadline
  3780. items if they have an hour specification like [h]h:mm."
  3781. (interactive "P")
  3782. (if org-agenda-overriding-arguments
  3783. (setq arg (car org-agenda-overriding-arguments)
  3784. start-day (nth 1 org-agenda-overriding-arguments)
  3785. span (nth 2 org-agenda-overriding-arguments)))
  3786. (if (and (integerp arg) (> arg 0))
  3787. (setq span arg arg nil))
  3788. (catch 'exit
  3789. (setq org-agenda-buffer-name
  3790. (or org-agenda-buffer-tmp-name
  3791. (if org-agenda-sticky
  3792. (cond ((and org-keys (stringp org-match))
  3793. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3794. (org-keys
  3795. (format "*Org Agenda(%s)*" org-keys))
  3796. (t "*Org Agenda(a)*")))
  3797. org-agenda-buffer-name))
  3798. (org-agenda-prepare "Day/Week")
  3799. (setq start-day (or start-day org-agenda-start-day))
  3800. (if (stringp start-day)
  3801. ;; Convert to an absolute day number
  3802. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3803. (org-compile-prefix-format 'agenda)
  3804. (org-set-sorting-strategy 'agenda)
  3805. (let* ((span (org-agenda-ndays-to-span
  3806. (or span org-agenda-ndays org-agenda-span)))
  3807. (today (org-today))
  3808. (sd (or start-day today))
  3809. (ndays (org-agenda-span-to-ndays span sd))
  3810. (org-agenda-start-on-weekday
  3811. (if (eq ndays 7)
  3812. org-agenda-start-on-weekday))
  3813. (thefiles (org-agenda-files nil 'ifmode))
  3814. (files thefiles)
  3815. (start (if (or (null org-agenda-start-on-weekday)
  3816. (< ndays 7))
  3817. sd
  3818. (let* ((nt (calendar-day-of-week
  3819. (calendar-gregorian-from-absolute sd)))
  3820. (n1 org-agenda-start-on-weekday)
  3821. (d (- nt n1)))
  3822. (- sd (+ (if (< d 0) 7 0) d)))))
  3823. (day-numbers (list start))
  3824. (day-cnt 0)
  3825. (inhibit-redisplay (not debug-on-error))
  3826. (org-agenda-show-log-scoped org-agenda-show-log)
  3827. s e rtn rtnall file date d start-pos end-pos todayp
  3828. clocktable-start clocktable-end filter)
  3829. (setq org-agenda-redo-command
  3830. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3831. (dotimes (n (1- ndays))
  3832. (push (1+ (car day-numbers)) day-numbers))
  3833. (setq day-numbers (nreverse day-numbers))
  3834. (setq clocktable-start (car day-numbers)
  3835. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3836. (org-set-local 'org-starting-day (car day-numbers))
  3837. (org-set-local 'org-arg-loc arg)
  3838. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3839. (unless org-agenda-compact-blocks
  3840. (let* ((d1 (car day-numbers))
  3841. (d2 (org-last day-numbers))
  3842. (w1 (org-days-to-iso-week d1))
  3843. (w2 (org-days-to-iso-week d2)))
  3844. (setq s (point))
  3845. (if org-agenda-overriding-header
  3846. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3847. nil 'face 'org-agenda-structure) "\n")
  3848. (insert (org-agenda-span-name span)
  3849. "-agenda"
  3850. (if (< (- d2 d1) 350)
  3851. (if (= w1 w2)
  3852. (format " (W%02d)" w1)
  3853. (format " (W%02d-W%02d)" w1 w2))
  3854. "")
  3855. ":\n")))
  3856. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3857. 'org-date-line t))
  3858. (org-agenda-mark-header-line s))
  3859. (while (setq d (pop day-numbers))
  3860. (setq date (calendar-gregorian-from-absolute d)
  3861. s (point))
  3862. (if (or (setq todayp (= d today))
  3863. (and (not start-pos) (= d sd)))
  3864. (setq start-pos (point))
  3865. (if (and start-pos (not end-pos))
  3866. (setq end-pos (point))))
  3867. (setq files thefiles
  3868. rtnall nil)
  3869. (while (setq file (pop files))
  3870. (catch 'nextfile
  3871. (org-check-agenda-file file)
  3872. (let ((org-agenda-entry-types org-agenda-entry-types))
  3873. ;; Starred types override non-starred equivalents
  3874. (when (member :deadline* org-agenda-entry-types)
  3875. (setq org-agenda-entry-types
  3876. (delq :deadline org-agenda-entry-types)))
  3877. (when (member :scheduled* org-agenda-entry-types)
  3878. (setq org-agenda-entry-types
  3879. (delq :scheduled org-agenda-entry-types)))
  3880. ;; Honor with-hour
  3881. (when with-hour
  3882. (when (member :deadline org-agenda-entry-types)
  3883. (setq org-agenda-entry-types
  3884. (delq :deadline org-agenda-entry-types))
  3885. (push :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. (push :scheduled* org-agenda-entry-types)))
  3890. (unless org-agenda-include-deadlines
  3891. (setq org-agenda-entry-types
  3892. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3893. (cond
  3894. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3895. (setq rtn (org-agenda-get-day-entries
  3896. file date :closed)))
  3897. (org-agenda-show-log-scoped
  3898. (setq rtn (apply 'org-agenda-get-day-entries
  3899. file date
  3900. (append '(:closed) org-agenda-entry-types))))
  3901. (t
  3902. (setq rtn (apply 'org-agenda-get-day-entries
  3903. file date
  3904. org-agenda-entry-types)))))
  3905. (setq rtnall (append rtnall rtn)))) ;; all entries
  3906. (if org-agenda-include-diary
  3907. (let ((org-agenda-search-headline-for-time t))
  3908. (require 'diary-lib)
  3909. (setq rtn (org-get-entries-from-diary date))
  3910. (setq rtnall (append rtnall rtn))))
  3911. (if (or rtnall org-agenda-show-all-dates)
  3912. (progn
  3913. (setq day-cnt (1+ day-cnt))
  3914. (insert
  3915. (if (stringp org-agenda-format-date)
  3916. (format-time-string org-agenda-format-date
  3917. (org-time-from-absolute date))
  3918. (funcall org-agenda-format-date date))
  3919. "\n")
  3920. (put-text-property s (1- (point)) 'face
  3921. (org-agenda-get-day-face date))
  3922. (put-text-property s (1- (point)) 'org-date-line t)
  3923. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3924. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3925. (when todayp
  3926. (put-text-property s (1- (point)) 'org-today t))
  3927. (setq rtnall
  3928. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3929. (if rtnall (insert ;; all entries
  3930. (org-agenda-finalize-entries rtnall 'agenda)
  3931. "\n"))
  3932. (put-text-property s (1- (point)) 'day d)
  3933. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3934. (when (and org-agenda-clockreport-mode clocktable-start)
  3935. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3936. ;; the above line is to ensure the restricted range!
  3937. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3938. tbl)
  3939. (setq p (org-plist-delete p :block))
  3940. (setq p (plist-put p :tstart clocktable-start))
  3941. (setq p (plist-put p :tend clocktable-end))
  3942. (setq p (plist-put p :scope 'agenda))
  3943. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3944. (setq filter (or org-agenda-tag-filter-while-redo
  3945. (get 'org-agenda-tag-filter :preset-filter))))
  3946. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3947. (if (string-match "[<>=]" x)
  3948. ""
  3949. x))
  3950. filter ""))))
  3951. (setq tbl (apply 'org-clock-get-clocktable p))
  3952. (insert tbl)))
  3953. (goto-char (point-min))
  3954. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3955. (unless (and (pos-visible-in-window-p (point-min))
  3956. (pos-visible-in-window-p (point-max)))
  3957. (goto-char (1- (point-max)))
  3958. (recenter -1)
  3959. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3960. (progn
  3961. (goto-char (or start-pos 1))
  3962. (recenter 1))))
  3963. (goto-char (or start-pos 1))
  3964. (add-text-properties (point-min) (point-max)
  3965. `(org-agenda-type agenda
  3966. org-last-args (,arg ,start-day ,span)
  3967. org-redo-cmd ,org-agenda-redo-command
  3968. org-series-cmd ,org-cmd))
  3969. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3970. (org-agenda-show-clocking-issues))
  3971. (org-agenda-finalize)
  3972. (setq buffer-read-only t)
  3973. (message ""))))
  3974. (defun org-agenda-ndays-to-span (n)
  3975. "Return a span symbol for a span of N days, or N if none matches."
  3976. (cond ((symbolp n) n)
  3977. ((= n 1) 'day)
  3978. ((= n 7) 'week)
  3979. (t n)))
  3980. (defun org-agenda-span-to-ndays (span &optional start-day)
  3981. "Return ndays from SPAN, possibly starting at START-DAY.
  3982. START-DAY is an absolute time value."
  3983. (cond ((numberp span) span)
  3984. ((eq span 'day) 1)
  3985. ((eq span 'week) 7)
  3986. ((eq span 'month)
  3987. (let ((date (calendar-gregorian-from-absolute start-day)))
  3988. (calendar-last-day-of-month (car date) (caddr date))))
  3989. ((eq span 'year)
  3990. (let ((date (calendar-gregorian-from-absolute start-day)))
  3991. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3992. (defun org-agenda-span-name (span)
  3993. "Return a SPAN name."
  3994. (if (null span)
  3995. ""
  3996. (if (symbolp span)
  3997. (capitalize (symbol-name span))
  3998. (format "%d days" span))))
  3999. ;;; Agenda word search
  4000. (defvar org-agenda-search-history nil)
  4001. (defvar org-search-syntax-table nil
  4002. "Special syntax table for org-mode search.
  4003. In this table, we have single quotes not as word constituents, to
  4004. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4005. (defvar org-mode-syntax-table) ; From org.el
  4006. (defun org-search-syntax-table ()
  4007. (unless org-search-syntax-table
  4008. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4009. (modify-syntax-entry ?' "." org-search-syntax-table)
  4010. (modify-syntax-entry ?` "." org-search-syntax-table))
  4011. org-search-syntax-table)
  4012. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4013. ;;;###autoload
  4014. (defun org-search-view (&optional todo-only string edit-at)
  4015. "Show all entries that contain a phrase or words or regular expressions.
  4016. With optional prefix argument TODO-ONLY, only consider entries that are
  4017. TODO entries. The argument STRING can be used to pass a default search
  4018. string into this function. If EDIT-AT is non-nil, it means that the
  4019. user should get a chance to edit this string, with cursor at position
  4020. EDIT-AT.
  4021. The search string can be viewed either as a phrase that should be found as
  4022. is, or it can be broken into a number of snippets, each of which must match
  4023. in a Boolean way to select an entry. The default depends on the variable
  4024. `org-agenda-search-view-always-boolean'.
  4025. Even if this is turned off (the default) you can always switch to
  4026. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4027. The default is a direct search of the whole phrase, where each space in
  4028. the search string can expand to an arbitrary amount of whitespace,
  4029. including newlines.
  4030. If using a Boolean search, the search string is split on whitespace and
  4031. each snippet is searched separately, with logical AND to select an entry.
  4032. Words prefixed with a minus must *not* occur in the entry. Words without
  4033. a prefix or prefixed with a plus must occur in the entry. Matching is
  4034. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4035. match whole words, not parts of a word) if
  4036. `org-agenda-search-view-force-full-words' is set (default is nil).
  4037. Boolean search snippets enclosed by curly braces are interpreted as
  4038. regular expressions that must or (when preceded with \"-\") must not
  4039. match in the entry. Snippets enclosed into double quotes will be taken
  4040. as a whole, to include whitespace.
  4041. - If the search string starts with an asterisk, search only in headlines.
  4042. - If (possibly after the leading star) the search string starts with an
  4043. exclamation mark, this also means to look at TODO entries only, an effect
  4044. that can also be achieved with a prefix argument.
  4045. - If (possibly after star and exclamation mark) the search string starts
  4046. with a colon, this will mean that the (non-regexp) snippets of the
  4047. Boolean search must match as full words.
  4048. This command searches the agenda files, and in addition the files listed
  4049. in `org-agenda-text-search-extra-files'."
  4050. (interactive "P")
  4051. (if org-agenda-overriding-arguments
  4052. (setq todo-only (car org-agenda-overriding-arguments)
  4053. string (nth 1 org-agenda-overriding-arguments)
  4054. edit-at (nth 2 org-agenda-overriding-arguments)))
  4055. (let* ((props (list 'face nil
  4056. 'done-face 'org-agenda-done
  4057. 'org-not-done-regexp org-not-done-regexp
  4058. 'org-todo-regexp org-todo-regexp
  4059. 'org-complex-heading-regexp org-complex-heading-regexp
  4060. 'mouse-face 'highlight
  4061. 'help-echo (format "mouse-2 or RET jump to location")))
  4062. (full-words org-agenda-search-view-force-full-words)
  4063. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4064. regexp rtn rtnall files file pos inherited-tags
  4065. marker category category-pos level tags c neg re boolean
  4066. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4067. (unless (and (not edit-at)
  4068. (stringp string)
  4069. (string-match "\\S-" string))
  4070. (setq string (read-string
  4071. (if org-agenda-search-view-always-boolean
  4072. "[+-]Word/{Regexp} ...: "
  4073. "Phrase or [+-]Word/{Regexp} ...: ")
  4074. (cond
  4075. ((integerp edit-at) (cons string edit-at))
  4076. (edit-at string))
  4077. 'org-agenda-search-history)))
  4078. (catch 'exit
  4079. (if org-agenda-sticky
  4080. (setq org-agenda-buffer-name
  4081. (if (stringp string)
  4082. (format "*Org Agenda(%s:%s)*"
  4083. (or org-keys (or (and todo-only "S") "s")) string)
  4084. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4085. (org-agenda-prepare "SEARCH")
  4086. (org-compile-prefix-format 'search)
  4087. (org-set-sorting-strategy 'search)
  4088. (setq org-agenda-redo-command
  4089. (list 'org-search-view (if todo-only t nil)
  4090. (list 'if 'current-prefix-arg nil string)))
  4091. (setq org-agenda-query-string string)
  4092. (if (equal (string-to-char string) ?*)
  4093. (setq hdl-only t
  4094. words (substring string 1))
  4095. (setq words string))
  4096. (when (equal (string-to-char words) ?!)
  4097. (setq todo-only t
  4098. words (substring words 1)))
  4099. (when (equal (string-to-char words) ?:)
  4100. (setq full-words t
  4101. words (substring words 1)))
  4102. (if (or org-agenda-search-view-always-boolean
  4103. (member (string-to-char words) '(?- ?+ ?\{)))
  4104. (setq boolean t))
  4105. (setq words (org-split-string words))
  4106. (let (www w)
  4107. (while (setq w (pop words))
  4108. (while (and (string-match "\\\\\\'" w) words)
  4109. (setq w (concat (substring w 0 -1) " " (pop words))))
  4110. (push w www))
  4111. (setq words (nreverse www) www nil)
  4112. (while (setq w (pop words))
  4113. (when (and (string-match "\\`[-+]?{" w)
  4114. (not (string-match "}\\'" w)))
  4115. (while (and words (not (string-match "}\\'" (car words))))
  4116. (setq w (concat w " " (pop words))))
  4117. (setq w (concat w " " (pop words))))
  4118. (push w www))
  4119. (setq words (nreverse www)))
  4120. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4121. (when boolean
  4122. (let (wds w)
  4123. (while (setq w (pop words))
  4124. (if (or (equal (substring w 0 1) "\"")
  4125. (and (> (length w) 1)
  4126. (member (substring w 0 1) '("+" "-"))
  4127. (equal (substring w 1 2) "\"")))
  4128. (while (and words (not (equal (substring w -1) "\"")))
  4129. (setq w (concat w " " (pop words)))))
  4130. (and (string-match "\\`\\([-+]?\\)\"" w)
  4131. (setq w (replace-match "\\1" nil nil w)))
  4132. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4133. (push w wds))
  4134. (setq words (nreverse wds))))
  4135. (if boolean
  4136. (mapc (lambda (w)
  4137. (setq c (string-to-char w))
  4138. (if (equal c ?-)
  4139. (setq neg t w (substring w 1))
  4140. (if (equal c ?+)
  4141. (setq neg nil w (substring w 1))
  4142. (setq neg nil)))
  4143. (if (string-match "\\`{.*}\\'" w)
  4144. (setq re (substring w 1 -1))
  4145. (if full-words
  4146. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4147. (setq re (regexp-quote (downcase w)))))
  4148. (if neg (push re regexps-) (push re regexps+)))
  4149. words)
  4150. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4151. regexps+))
  4152. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4153. (if (not regexps+)
  4154. (setq regexp org-outline-regexp-bol)
  4155. (setq regexp (pop regexps+))
  4156. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4157. regexp))))
  4158. (setq files (org-agenda-files nil 'ifmode))
  4159. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4160. (pop org-agenda-text-search-extra-files)
  4161. (setq files (org-add-archive-files files)))
  4162. (setq files (append files org-agenda-text-search-extra-files)
  4163. rtnall nil)
  4164. (while (setq file (pop files))
  4165. (setq ee nil)
  4166. (catch 'nextfile
  4167. (org-check-agenda-file file)
  4168. (setq buffer (if (file-exists-p file)
  4169. (org-get-agenda-file-buffer file)
  4170. (error "No such file %s" file)))
  4171. (if (not buffer)
  4172. ;; If file does not exist, make sure an error message is sent
  4173. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4174. file))))
  4175. (with-current-buffer buffer
  4176. (with-syntax-table (org-search-syntax-table)
  4177. (unless (derived-mode-p 'org-mode)
  4178. (error "Agenda file %s is not in `org-mode'" file))
  4179. (let ((case-fold-search t))
  4180. (save-excursion
  4181. (save-restriction
  4182. (if org-agenda-restrict
  4183. (narrow-to-region org-agenda-restrict-begin
  4184. org-agenda-restrict-end)
  4185. (widen))
  4186. (goto-char (point-min))
  4187. (unless (or (org-at-heading-p)
  4188. (outline-next-heading))
  4189. (throw 'nextfile t))
  4190. (goto-char (max (point-min) (1- (point))))
  4191. (while (re-search-forward regexp nil t)
  4192. (org-back-to-heading t)
  4193. (while (and org-agenda-search-view-max-outline-level
  4194. (> (org-reduced-level (org-outline-level))
  4195. org-agenda-search-view-max-outline-level)
  4196. (forward-line -1)
  4197. (outline-back-to-heading t)))
  4198. (skip-chars-forward "* ")
  4199. (setq beg (point-at-bol)
  4200. beg1 (point)
  4201. end (progn
  4202. (outline-next-heading)
  4203. (while (and org-agenda-search-view-max-outline-level
  4204. (> (org-reduced-level (org-outline-level))
  4205. org-agenda-search-view-max-outline-level)
  4206. (forward-line 1)
  4207. (outline-next-heading)))
  4208. (point)))
  4209. (catch :skip
  4210. (goto-char beg)
  4211. (org-agenda-skip)
  4212. (setq str (buffer-substring-no-properties
  4213. (point-at-bol)
  4214. (if hdl-only (point-at-eol) end)))
  4215. (mapc (lambda (wr) (when (string-match wr str)
  4216. (goto-char (1- end))
  4217. (throw :skip t)))
  4218. regexps-)
  4219. (mapc (lambda (wr) (unless (string-match wr str)
  4220. (goto-char (1- end))
  4221. (throw :skip t)))
  4222. (if todo-only
  4223. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4224. regexps+)
  4225. regexps+))
  4226. (goto-char beg)
  4227. (setq marker (org-agenda-new-marker (point))
  4228. category (org-get-category)
  4229. level (make-string (org-reduced-level (org-outline-level)) ? )
  4230. category-pos (get-text-property (point) 'org-category-position)
  4231. inherited-tags
  4232. (or (eq org-agenda-show-inherited-tags 'always)
  4233. (and (listp org-agenda-show-inherited-tags)
  4234. (memq 'todo org-agenda-show-inherited-tags))
  4235. (and (eq org-agenda-show-inherited-tags t)
  4236. (or (eq org-agenda-use-tag-inheritance t)
  4237. (memq 'todo org-agenda-use-tag-inheritance))))
  4238. tags (org-get-tags-at nil (not inherited-tags))
  4239. txt (org-agenda-format-item
  4240. ""
  4241. (buffer-substring-no-properties
  4242. beg1 (point-at-eol))
  4243. level category tags t))
  4244. (org-add-props txt props
  4245. 'org-marker marker 'org-hd-marker marker
  4246. 'org-todo-regexp org-todo-regexp
  4247. 'level level
  4248. 'org-complex-heading-regexp org-complex-heading-regexp
  4249. 'priority 1000 'org-category category
  4250. 'org-category-position category-pos
  4251. 'type "search")
  4252. (push txt ee)
  4253. (goto-char (1- end))))))))))
  4254. (setq rtn (nreverse ee))
  4255. (setq rtnall (append rtnall rtn)))
  4256. (if org-agenda-overriding-header
  4257. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4258. nil 'face 'org-agenda-structure) "\n")
  4259. (insert "Search words: ")
  4260. (add-text-properties (point-min) (1- (point))
  4261. (list 'face 'org-agenda-structure))
  4262. (setq pos (point))
  4263. (insert string "\n")
  4264. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4265. (setq pos (point))
  4266. (unless org-agenda-multi
  4267. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4268. (add-text-properties pos (1- (point))
  4269. (list 'face 'org-agenda-structure))))
  4270. (org-agenda-mark-header-line (point-min))
  4271. (when rtnall
  4272. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4273. (goto-char (point-min))
  4274. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4275. (add-text-properties (point-min) (point-max)
  4276. `(org-agenda-type search
  4277. org-last-args (,todo-only ,string ,edit-at)
  4278. org-redo-cmd ,org-agenda-redo-command
  4279. org-series-cmd ,org-cmd))
  4280. (org-agenda-finalize)
  4281. (setq buffer-read-only t))))
  4282. ;;; Agenda TODO list
  4283. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4284. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4285. (concat
  4286. (if (or (equal keywords "ALL") (not keywords))
  4287. (propertize "ALL" 'face 'warning)
  4288. (mapconcat
  4289. (lambda (kw)
  4290. (propertize kw 'face (org-get-todo-face kw)))
  4291. (org-split-string keywords "|")
  4292. "|"))
  4293. "\n"))
  4294. (defvar org-select-this-todo-keyword nil)
  4295. (defvar org-last-arg nil)
  4296. ;;;###autoload
  4297. (defun org-todo-list (&optional arg)
  4298. "Show all (not done) TODO entries from all agenda file in a single list.
  4299. The prefix arg can be used to select a specific TODO keyword and limit
  4300. the list to these. When using \\[universal-argument], you will be prompted
  4301. for a keyword. A numeric prefix directly selects the Nth keyword in
  4302. `org-todo-keywords-1'."
  4303. (interactive "P")
  4304. (if org-agenda-overriding-arguments
  4305. (setq arg org-agenda-overriding-arguments))
  4306. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4307. (let* ((today (org-today))
  4308. (date (calendar-gregorian-from-absolute today))
  4309. (kwds org-todo-keywords-for-agenda)
  4310. (completion-ignore-case t)
  4311. (org-select-this-todo-keyword
  4312. (if (stringp arg) arg
  4313. (and arg (integerp arg) (> arg 0)
  4314. (nth (1- arg) kwds))))
  4315. rtn rtnall files file pos)
  4316. (when (equal arg '(4))
  4317. (setq org-select-this-todo-keyword
  4318. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4319. (mapcar 'list kwds) nil nil)))
  4320. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4321. (catch 'exit
  4322. (if org-agenda-sticky
  4323. (setq org-agenda-buffer-name
  4324. (if (stringp org-select-this-todo-keyword)
  4325. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4326. org-select-this-todo-keyword)
  4327. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4328. (org-agenda-prepare "TODO")
  4329. (org-compile-prefix-format 'todo)
  4330. (org-set-sorting-strategy 'todo)
  4331. (setq org-agenda-redo-command
  4332. `(org-todo-list (or (and (numberp current-prefix-arg)
  4333. current-prefix-arg)
  4334. ,org-select-this-todo-keyword
  4335. current-prefix-arg ,arg)))
  4336. (setq files (org-agenda-files nil 'ifmode)
  4337. rtnall nil)
  4338. (while (setq file (pop files))
  4339. (catch 'nextfile
  4340. (org-check-agenda-file file)
  4341. (setq rtn (org-agenda-get-day-entries file date :todo))
  4342. (setq rtnall (append rtnall rtn))))
  4343. (if org-agenda-overriding-header
  4344. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4345. nil 'face 'org-agenda-structure) "\n")
  4346. (insert "Global list of TODO items of type: ")
  4347. (add-text-properties (point-min) (1- (point))
  4348. (list 'face 'org-agenda-structure
  4349. 'short-heading
  4350. (concat "ToDo: "
  4351. (or org-select-this-todo-keyword "ALL"))))
  4352. (org-agenda-mark-header-line (point-min))
  4353. (insert (org-agenda-propertize-selected-todo-keywords
  4354. org-select-this-todo-keyword))
  4355. (setq pos (point))
  4356. (unless org-agenda-multi
  4357. (insert "Available with `N r': (0)[ALL]")
  4358. (let ((n 0) s)
  4359. (mapc (lambda (x)
  4360. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4361. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4362. (insert "\n "))
  4363. (insert " " s))
  4364. kwds))
  4365. (insert "\n"))
  4366. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4367. (org-agenda-mark-header-line (point-min))
  4368. (when rtnall
  4369. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4370. (goto-char (point-min))
  4371. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4372. (add-text-properties (point-min) (point-max)
  4373. `(org-agenda-type todo
  4374. org-last-args ,arg
  4375. org-redo-cmd ,org-agenda-redo-command
  4376. org-series-cmd ,org-cmd))
  4377. (org-agenda-finalize)
  4378. (setq buffer-read-only t))))
  4379. ;;; Agenda tags match
  4380. ;;;###autoload
  4381. (defun org-tags-view (&optional todo-only match)
  4382. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4383. The prefix arg TODO-ONLY limits the search to TODO entries."
  4384. (interactive "P")
  4385. (if org-agenda-overriding-arguments
  4386. (setq todo-only (car org-agenda-overriding-arguments)
  4387. match (nth 1 org-agenda-overriding-arguments)))
  4388. (let* ((org-tags-match-list-sublevels
  4389. org-tags-match-list-sublevels)
  4390. (completion-ignore-case t)
  4391. rtn rtnall files file pos matcher
  4392. buffer)
  4393. (when (and (stringp match) (not (string-match "\\S-" match)))
  4394. (setq match nil))
  4395. (catch 'exit
  4396. (if org-agenda-sticky
  4397. (setq org-agenda-buffer-name
  4398. (if (stringp match)
  4399. (format "*Org Agenda(%s:%s)*"
  4400. (or org-keys (or (and todo-only "M") "m")) match)
  4401. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4402. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4403. ;; expanding tags within `org-make-tags-matcher'
  4404. (org-agenda-prepare (concat "TAGS " match))
  4405. (setq matcher (org-make-tags-matcher match)
  4406. match (car matcher) matcher (cdr matcher))
  4407. (org-compile-prefix-format 'tags)
  4408. (org-set-sorting-strategy 'tags)
  4409. (setq org-agenda-query-string match)
  4410. (setq org-agenda-redo-command
  4411. (list 'org-tags-view `(quote ,todo-only)
  4412. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4413. (setq files (org-agenda-files nil 'ifmode)
  4414. rtnall nil)
  4415. (while (setq file (pop files))
  4416. (catch 'nextfile
  4417. (org-check-agenda-file file)
  4418. (setq buffer (if (file-exists-p file)
  4419. (org-get-agenda-file-buffer file)
  4420. (error "No such file %s" file)))
  4421. (if (not buffer)
  4422. ;; If file does not exist, error message to agenda
  4423. (setq rtn (list
  4424. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4425. rtnall (append rtnall rtn))
  4426. (with-current-buffer buffer
  4427. (unless (derived-mode-p 'org-mode)
  4428. (error "Agenda file %s is not in `org-mode'" file))
  4429. (save-excursion
  4430. (save-restriction
  4431. (if org-agenda-restrict
  4432. (narrow-to-region org-agenda-restrict-begin
  4433. org-agenda-restrict-end)
  4434. (widen))
  4435. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4436. (setq rtnall (append rtnall rtn))))))))
  4437. (if org-agenda-overriding-header
  4438. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4439. nil 'face 'org-agenda-structure) "\n")
  4440. (insert "Headlines with TAGS match: ")
  4441. (add-text-properties (point-min) (1- (point))
  4442. (list 'face 'org-agenda-structure
  4443. 'short-heading
  4444. (concat "Match: " match)))
  4445. (setq pos (point))
  4446. (insert match "\n")
  4447. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4448. (setq pos (point))
  4449. (unless org-agenda-multi
  4450. (insert "Press `C-u r' to search again with new search string\n"))
  4451. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4452. (org-agenda-mark-header-line (point-min))
  4453. (when rtnall
  4454. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4455. (goto-char (point-min))
  4456. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4457. (add-text-properties (point-min) (point-max)
  4458. `(org-agenda-type tags
  4459. org-last-args (,todo-only ,match)
  4460. org-redo-cmd ,org-agenda-redo-command
  4461. org-series-cmd ,org-cmd))
  4462. (org-agenda-finalize)
  4463. (setq buffer-read-only t))))
  4464. ;;; Agenda Finding stuck projects
  4465. (defvar org-agenda-skip-regexp nil
  4466. "Regular expression used in skipping subtrees for the agenda.
  4467. This is basically a temporary global variable that can be set and then
  4468. used by user-defined selections using `org-agenda-skip-function'.")
  4469. (defvar org-agenda-overriding-header nil
  4470. "When set during agenda, todo and tags searches it replaces the header.
  4471. This variable should not be set directly, but custom commands can bind it
  4472. in the options section.")
  4473. (defun org-agenda-skip-entry-when-regexp-matches ()
  4474. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4475. If yes, it returns the end position of this entry, causing agenda commands
  4476. to skip the entry but continuing the search in the subtree. This is a
  4477. function that can be put into `org-agenda-skip-function' for the duration
  4478. of a command."
  4479. (let ((end (save-excursion (org-end-of-subtree t)))
  4480. skip)
  4481. (save-excursion
  4482. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4483. (and skip end)))
  4484. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4485. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4486. If yes, it returns the end position of this tree, causing agenda commands
  4487. to skip this subtree. This is a function that can be put into
  4488. `org-agenda-skip-function' for the duration of a command."
  4489. (let ((end (save-excursion (org-end-of-subtree t)))
  4490. skip)
  4491. (save-excursion
  4492. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4493. (and skip end)))
  4494. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4495. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4496. If yes, it returns the end position of the current entry (NOT the tree),
  4497. causing agenda commands to skip the entry but continuing the search in
  4498. the subtree. This is a function that can be put into
  4499. `org-agenda-skip-function' for the duration of a command. An important
  4500. use of this function is for the stuck project list."
  4501. (let ((end (save-excursion (org-end-of-subtree t)))
  4502. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4503. skip)
  4504. (save-excursion
  4505. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4506. (and skip entry-end)))
  4507. (defun org-agenda-skip-entry-if (&rest conditions)
  4508. "Skip entry if any of CONDITIONS is true.
  4509. See `org-agenda-skip-if' for details."
  4510. (org-agenda-skip-if nil conditions))
  4511. (defun org-agenda-skip-subtree-if (&rest conditions)
  4512. "Skip entry if any of CONDITIONS is true.
  4513. See `org-agenda-skip-if' for details."
  4514. (org-agenda-skip-if t conditions))
  4515. (defun org-agenda-skip-if (subtree conditions)
  4516. "Checks current entity for CONDITIONS.
  4517. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4518. the entry (i.e. the text before the next heading) is checked.
  4519. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4520. from different tests. Valid conditions are:
  4521. scheduled Check if there is a scheduled cookie
  4522. notscheduled Check if there is no scheduled cookie
  4523. deadline Check if there is a deadline
  4524. notdeadline Check if there is no deadline
  4525. timestamp Check if there is a timestamp (also deadline or scheduled)
  4526. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4527. regexp Check if regexp matches
  4528. notregexp Check if regexp does not match.
  4529. todo Check if TODO keyword matches
  4530. nottodo Check if TODO keyword does not match
  4531. The regexp is taken from the conditions list, it must come right after
  4532. the `regexp' or `notregexp' element.
  4533. `todo' and `nottodo' accept as an argument a list of todo
  4534. keywords, which may include \"*\" to match any todo keyword.
  4535. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4536. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4537. Instead of a list, a keyword class may be given. For example:
  4538. (org-agenda-skip-entry-if 'nottodo 'done)
  4539. would skip entries that haven't been marked with any of \"DONE\"
  4540. keywords. Possible classes are: `todo', `done', `any'.
  4541. If any of these conditions is met, this function returns the end point of
  4542. the entity, causing the search to continue from there. This is a function
  4543. that can be put into `org-agenda-skip-function' for the duration of a command."
  4544. (let (beg end m)
  4545. (org-back-to-heading t)
  4546. (setq beg (point)
  4547. end (if subtree
  4548. (progn (org-end-of-subtree t) (point))
  4549. (progn (outline-next-heading) (1- (point)))))
  4550. (goto-char beg)
  4551. (and
  4552. (or
  4553. (and (memq 'scheduled conditions)
  4554. (re-search-forward org-scheduled-time-regexp end t))
  4555. (and (memq 'notscheduled conditions)
  4556. (not (re-search-forward org-scheduled-time-regexp end t)))
  4557. (and (memq 'deadline conditions)
  4558. (re-search-forward org-deadline-time-regexp end t))
  4559. (and (memq 'notdeadline conditions)
  4560. (not (re-search-forward org-deadline-time-regexp end t)))
  4561. (and (memq 'timestamp conditions)
  4562. (re-search-forward org-ts-regexp end t))
  4563. (and (memq 'nottimestamp conditions)
  4564. (not (re-search-forward org-ts-regexp end t)))
  4565. (and (setq m (memq 'regexp conditions))
  4566. (stringp (nth 1 m))
  4567. (re-search-forward (nth 1 m) end t))
  4568. (and (setq m (memq 'notregexp conditions))
  4569. (stringp (nth 1 m))
  4570. (not (re-search-forward (nth 1 m) end t)))
  4571. (and (or
  4572. (setq m (memq 'nottodo conditions))
  4573. (setq m (memq 'todo-unblocked conditions))
  4574. (setq m (memq 'nottodo-unblocked conditions))
  4575. (setq m (memq 'todo conditions)))
  4576. (org-agenda-skip-if-todo m end)))
  4577. end)))
  4578. (defun org-agenda-skip-if-todo (args end)
  4579. "Helper function for `org-agenda-skip-if', do not use it directly.
  4580. ARGS is a list with first element either `todo', `nottodo',
  4581. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4582. a list of TODO keywords, or a state symbol `todo' or `done' or
  4583. `any'."
  4584. (let ((kw (car args))
  4585. (arg (cadr args))
  4586. todo-wds todo-re)
  4587. (setq todo-wds
  4588. (org-uniquify
  4589. (cond
  4590. ((listp arg) ;; list of keywords
  4591. (if (member "*" arg)
  4592. (mapcar 'substring-no-properties org-todo-keywords-1)
  4593. arg))
  4594. ((symbolp arg) ;; keyword class name
  4595. (cond
  4596. ((eq arg 'todo)
  4597. (org-delete-all org-done-keywords
  4598. (mapcar 'substring-no-properties
  4599. org-todo-keywords-1)))
  4600. ((eq arg 'done) org-done-keywords)
  4601. ((eq arg 'any)
  4602. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4603. (setq todo-re
  4604. (concat "^\\*+[ \t]+\\<\\("
  4605. (mapconcat 'identity todo-wds "\\|")
  4606. "\\)\\>"))
  4607. (cond
  4608. ((eq kw 'todo) (re-search-forward todo-re end t))
  4609. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4610. ((eq kw 'todo-unblocked)
  4611. (catch 'unblocked
  4612. (while (re-search-forward todo-re end t)
  4613. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4614. nil))
  4615. ((eq kw 'nottodo-unblocked)
  4616. (catch 'unblocked
  4617. (while (re-search-forward todo-re end t)
  4618. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4619. t))
  4620. )))
  4621. ;;;###autoload
  4622. (defun org-agenda-list-stuck-projects (&rest ignore)
  4623. "Create agenda view for projects that are stuck.
  4624. Stuck projects are project that have no next actions. For the definitions
  4625. of what a project is and how to check if it stuck, customize the variable
  4626. `org-stuck-projects'."
  4627. (interactive)
  4628. (let* ((org-agenda-skip-function
  4629. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4630. ;; We could have used org-agenda-skip-if here.
  4631. (org-agenda-overriding-header
  4632. (or org-agenda-overriding-header "List of stuck projects: "))
  4633. (matcher (nth 0 org-stuck-projects))
  4634. (todo (nth 1 org-stuck-projects))
  4635. (todo-wds (if (member "*" todo)
  4636. (progn
  4637. (org-agenda-prepare-buffers (org-agenda-files
  4638. nil 'ifmode))
  4639. (org-delete-all
  4640. org-done-keywords-for-agenda
  4641. (copy-sequence org-todo-keywords-for-agenda)))
  4642. todo))
  4643. (todo-re (concat "^\\*+[ \t]+\\("
  4644. (mapconcat 'identity todo-wds "\\|")
  4645. "\\)\\>"))
  4646. (tags (nth 2 org-stuck-projects))
  4647. (tags-re (if (member "*" tags)
  4648. (concat org-outline-regexp-bol
  4649. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4650. (if tags
  4651. (concat org-outline-regexp-bol
  4652. ".*:\\("
  4653. (mapconcat 'identity tags "\\|")
  4654. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4655. (gen-re (nth 3 org-stuck-projects))
  4656. (re-list
  4657. (delq nil
  4658. (list
  4659. (if todo todo-re)
  4660. (if tags tags-re)
  4661. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4662. gen-re)))))
  4663. (setq org-agenda-skip-regexp
  4664. (if re-list
  4665. (mapconcat 'identity re-list "\\|")
  4666. (error "No information how to identify unstuck projects")))
  4667. (org-tags-view nil matcher)
  4668. (with-current-buffer org-agenda-buffer-name
  4669. (setq org-agenda-redo-command
  4670. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4671. ;;; Diary integration
  4672. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4673. (defvar diary-list-entries-hook)
  4674. (defvar diary-time-regexp)
  4675. (defun org-get-entries-from-diary (date)
  4676. "Get the (Emacs Calendar) diary entries for DATE."
  4677. (require 'diary-lib)
  4678. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4679. (diary-display-hook '(fancy-diary-display))
  4680. (diary-display-function 'fancy-diary-display)
  4681. (pop-up-frames nil)
  4682. (diary-list-entries-hook
  4683. (cons 'org-diary-default-entry diary-list-entries-hook))
  4684. (diary-file-name-prefix nil) ; turn this feature off
  4685. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4686. entries
  4687. (org-disable-agenda-to-diary t))
  4688. (save-excursion
  4689. (save-window-excursion
  4690. (funcall (if (fboundp 'diary-list-entries)
  4691. 'diary-list-entries 'list-diary-entries)
  4692. date 1)))
  4693. (if (not (get-buffer diary-fancy-buffer))
  4694. (setq entries nil)
  4695. (with-current-buffer diary-fancy-buffer
  4696. (setq buffer-read-only nil)
  4697. (if (zerop (buffer-size))
  4698. ;; No entries
  4699. (setq entries nil)
  4700. ;; Omit the date and other unnecessary stuff
  4701. (org-agenda-cleanup-fancy-diary)
  4702. ;; Add prefix to each line and extend the text properties
  4703. (if (zerop (buffer-size))
  4704. (setq entries nil)
  4705. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4706. (setq entries
  4707. (with-temp-buffer
  4708. (insert entries) (goto-char (point-min))
  4709. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4710. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4711. (replace-match (concat "; " (match-string 1)))))
  4712. (buffer-string)))))
  4713. (set-buffer-modified-p nil)
  4714. (kill-buffer diary-fancy-buffer)))
  4715. (when entries
  4716. (setq entries (org-split-string entries "\n"))
  4717. (setq entries
  4718. (mapcar
  4719. (lambda (x)
  4720. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4721. ;; Extend the text properties to the beginning of the line
  4722. (org-add-props x (text-properties-at (1- (length x)) x)
  4723. 'type "diary" 'date date 'face 'org-agenda-diary))
  4724. entries)))))
  4725. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4726. "Hook run when the fancy diary buffer is cleaned up.")
  4727. (defun org-agenda-cleanup-fancy-diary ()
  4728. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4729. This gets rid of the date, the underline under the date, and
  4730. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4731. date. It also removes lines that contain only whitespace."
  4732. (goto-char (point-min))
  4733. (if (looking-at ".*?:[ \t]*")
  4734. (progn
  4735. (replace-match "")
  4736. (re-search-forward "\n=+$" nil t)
  4737. (replace-match "")
  4738. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4739. (re-search-forward "\n=+$" nil t)
  4740. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4741. (goto-char (point-min))
  4742. (while (re-search-forward "^ +\n" nil t)
  4743. (replace-match ""))
  4744. (goto-char (point-min))
  4745. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4746. (replace-match ""))
  4747. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4748. ;; Make sure entries from the diary have the right text properties.
  4749. (eval-after-load "diary-lib"
  4750. '(if (boundp 'diary-modify-entry-list-string-function)
  4751. ;; We can rely on the hook, nothing to do
  4752. nil
  4753. ;; Hook not available, must use advice to make this work
  4754. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4755. "Make the position visible."
  4756. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4757. (stringp string)
  4758. buffer-file-name)
  4759. (setq string (org-modify-diary-entry-string string))))))
  4760. (defun org-modify-diary-entry-string (string)
  4761. "Add text properties to string, allowing org-mode to act on it."
  4762. (org-add-props string nil
  4763. 'mouse-face 'highlight
  4764. 'help-echo (if buffer-file-name
  4765. (format "mouse-2 or RET jump to diary file %s"
  4766. (abbreviate-file-name buffer-file-name))
  4767. "")
  4768. 'org-agenda-diary-link t
  4769. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4770. (defun org-diary-default-entry ()
  4771. "Add a dummy entry to the diary.
  4772. Needed to avoid empty dates which mess up holiday display."
  4773. ;; Catch the error if dealing with the new add-to-diary-alist
  4774. (when org-disable-agenda-to-diary
  4775. (condition-case nil
  4776. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4777. (error
  4778. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4779. (defun org-add-to-diary-list (&rest args)
  4780. (if (fboundp 'diary-add-to-list)
  4781. (apply 'diary-add-to-list args)
  4782. (apply 'add-to-diary-list args)))
  4783. (defvar org-diary-last-run-time nil)
  4784. ;;;###autoload
  4785. (defun org-diary (&rest args)
  4786. "Return diary information from org files.
  4787. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4788. It accesses org files and extracts information from those files to be
  4789. listed in the diary. The function accepts arguments specifying what
  4790. items should be listed. For a list of arguments allowed here, see the
  4791. variable `org-agenda-entry-types'.
  4792. The call in the diary file should look like this:
  4793. &%%(org-diary) ~/path/to/some/orgfile.org
  4794. Use a separate line for each org file to check. Or, if you omit the file name,
  4795. all files listed in `org-agenda-files' will be checked automatically:
  4796. &%%(org-diary)
  4797. If you don't give any arguments (as in the example above), the default value
  4798. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4799. So the example above may also be written as
  4800. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4801. The function expects the lisp variables `entry' and `date' to be provided
  4802. by the caller, because this is how the calendar works. Don't use this
  4803. function from a program - use `org-agenda-get-day-entries' instead."
  4804. (when (> (- (org-float-time)
  4805. org-agenda-last-marker-time)
  4806. 5)
  4807. ;; I am not sure if this works with sticky agendas, because the marker
  4808. ;; list is then no longer a global variable.
  4809. (org-agenda-reset-markers))
  4810. (org-compile-prefix-format 'agenda)
  4811. (org-set-sorting-strategy 'agenda)
  4812. (setq args (or args org-agenda-entry-types))
  4813. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4814. (list entry)
  4815. (org-agenda-files t)))
  4816. (time (org-float-time))
  4817. file rtn results)
  4818. (when (or (not org-diary-last-run-time)
  4819. (> (- time
  4820. org-diary-last-run-time)
  4821. 3))
  4822. (org-agenda-prepare-buffers files))
  4823. (setq org-diary-last-run-time time)
  4824. ;; If this is called during org-agenda, don't return any entries to
  4825. ;; the calendar. Org Agenda will list these entries itself.
  4826. (if org-disable-agenda-to-diary (setq files nil))
  4827. (while (setq file (pop files))
  4828. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4829. (setq results (append results rtn)))
  4830. (when results
  4831. (setq results
  4832. (mapcar (lambda (i) (replace-regexp-in-string
  4833. org-bracket-link-regexp "\\3" i)) results))
  4834. (concat (org-agenda-finalize-entries results) "\n"))))
  4835. ;;; Agenda entry finders
  4836. (defun org-agenda-get-day-entries (file date &rest args)
  4837. "Does the work for `org-diary' and `org-agenda'.
  4838. FILE is the path to a file to be checked for entries. DATE is date like
  4839. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4840. which kind of entries should be extracted. For details about these, see
  4841. the documentation of `org-diary'."
  4842. (setq args (or args org-agenda-entry-types))
  4843. (let* ((org-startup-folded nil)
  4844. (org-startup-align-all-tables nil)
  4845. (buffer (if (file-exists-p file)
  4846. (org-get-agenda-file-buffer file)
  4847. (error "No such file %s" file)))
  4848. arg results rtn deadline-results)
  4849. (if (not buffer)
  4850. ;; If file does not exist, make sure an error message ends up in diary
  4851. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4852. (with-current-buffer buffer
  4853. (unless (derived-mode-p 'org-mode)
  4854. (error "Agenda file %s is not in `org-mode'" file))
  4855. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4856. (let ((case-fold-search nil))
  4857. (save-excursion
  4858. (save-restriction
  4859. (if org-agenda-restrict
  4860. (narrow-to-region org-agenda-restrict-begin
  4861. org-agenda-restrict-end)
  4862. (widen))
  4863. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4864. (while (setq arg (pop args))
  4865. (cond
  4866. ((and (eq arg :todo)
  4867. (equal date (calendar-gregorian-from-absolute
  4868. (org-today))))
  4869. (setq rtn (org-agenda-get-todos))
  4870. (setq results (append results rtn)))
  4871. ((eq arg :timestamp)
  4872. (setq rtn (org-agenda-get-blocks))
  4873. (setq results (append results rtn))
  4874. (setq rtn (org-agenda-get-timestamps deadline-results))
  4875. (setq results (append results rtn)))
  4876. ((eq arg :sexp)
  4877. (setq rtn (org-agenda-get-sexps))
  4878. (setq results (append results rtn)))
  4879. ((eq arg :scheduled)
  4880. (setq rtn (org-agenda-get-scheduled deadline-results))
  4881. (setq results (append results rtn)))
  4882. ((eq arg :scheduled*)
  4883. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4884. (setq results (append results rtn)))
  4885. ((eq arg :closed)
  4886. (setq rtn (org-agenda-get-progress))
  4887. (setq results (append results rtn)))
  4888. ((eq arg :deadline)
  4889. (setq rtn (org-agenda-get-deadlines))
  4890. (setq deadline-results (copy-sequence rtn))
  4891. (setq results (append results rtn)))
  4892. ((eq arg :deadline*)
  4893. (setq rtn (org-agenda-get-deadlines t))
  4894. (setq deadline-results (copy-sequence rtn))
  4895. (setq results (append results rtn))))))))
  4896. results))))
  4897. (defsubst org-em (x y list)
  4898. "Is X or Y a member of LIST?"
  4899. (or (memq x list) (memq y list)))
  4900. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4901. (defvar org-agenda-sorting-strategy-selected nil)
  4902. (defun org-agenda-get-todos ()
  4903. "Return the TODO information for agenda display."
  4904. (let* ((props (list 'face nil
  4905. 'done-face 'org-agenda-done
  4906. 'org-not-done-regexp org-not-done-regexp
  4907. 'org-todo-regexp org-todo-regexp
  4908. 'org-complex-heading-regexp org-complex-heading-regexp
  4909. 'mouse-face 'highlight
  4910. 'help-echo
  4911. (format "mouse-2 or RET jump to org file %s"
  4912. (abbreviate-file-name buffer-file-name))))
  4913. (regexp (format org-heading-keyword-regexp-format
  4914. (cond
  4915. ((and org-select-this-todo-keyword
  4916. (equal org-select-this-todo-keyword "*"))
  4917. org-todo-regexp)
  4918. (org-select-this-todo-keyword
  4919. (concat "\\("
  4920. (mapconcat 'identity
  4921. (org-split-string
  4922. org-select-this-todo-keyword
  4923. "|")
  4924. "\\|") "\\)"))
  4925. (t org-not-done-regexp))))
  4926. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4927. ee txt beg end inherited-tags todo-state-end-pos)
  4928. (goto-char (point-min))
  4929. (while (re-search-forward regexp nil t)
  4930. (catch :skip
  4931. (save-match-data
  4932. (beginning-of-line)
  4933. (org-agenda-skip)
  4934. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4935. (unless (and (setq todo-state (org-get-todo-state))
  4936. (setq todo-state-end-pos (match-end 2)))
  4937. (goto-char end)
  4938. (throw :skip nil))
  4939. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4940. (goto-char (1+ beg))
  4941. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4942. (throw :skip nil)))
  4943. (goto-char (match-beginning 2))
  4944. (setq marker (org-agenda-new-marker (match-beginning 0))
  4945. category (org-get-category)
  4946. ts-date (let (ts)
  4947. (save-match-data
  4948. (cond ((org-em 'scheduled-up 'scheduled-down
  4949. org-agenda-sorting-strategy-selected)
  4950. (setq ts (org-entry-get (point) "SCHEDULED")
  4951. ts-date-type " scheduled"))
  4952. ((org-em 'deadline-up 'deadline-down
  4953. org-agenda-sorting-strategy-selected)
  4954. (setq ts (org-entry-get (point) "DEADLINE")
  4955. ts-date-type " deadline"))
  4956. ((org-em 'ts-up 'ts-down
  4957. org-agenda-sorting-strategy-selected)
  4958. (setq ts (org-entry-get (point) "TIMESTAMP")
  4959. ts-date-type " timestamp"))
  4960. ((org-em 'tsia-up 'tsia-down
  4961. org-agenda-sorting-strategy-selected)
  4962. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4963. ts-date-type " timestamp_ia"))
  4964. ((org-em 'timestamp-up 'timestamp-down
  4965. org-agenda-sorting-strategy-selected)
  4966. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4967. (org-entry-get (point) "DEADLINE")
  4968. (org-entry-get (point) "TIMESTAMP")
  4969. (org-entry-get (point) "TIMESTAMP_IA"))
  4970. ts-date-type ""))
  4971. (t (setq ts-date-type "")))
  4972. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4973. category-pos (get-text-property (point) 'org-category-position)
  4974. txt (org-trim
  4975. (buffer-substring (match-beginning 2) (match-end 0)))
  4976. inherited-tags
  4977. (or (eq org-agenda-show-inherited-tags 'always)
  4978. (and (listp org-agenda-show-inherited-tags)
  4979. (memq 'todo org-agenda-show-inherited-tags))
  4980. (and (eq org-agenda-show-inherited-tags t)
  4981. (or (eq org-agenda-use-tag-inheritance t)
  4982. (memq 'todo org-agenda-use-tag-inheritance))))
  4983. tags (org-get-tags-at nil (not inherited-tags))
  4984. level (make-string (org-reduced-level (org-outline-level)) ? )
  4985. txt (org-agenda-format-item "" txt level category tags t)
  4986. priority (1+ (org-get-priority txt)))
  4987. (org-add-props txt props
  4988. 'org-marker marker 'org-hd-marker marker
  4989. 'priority priority 'org-category category
  4990. 'level level
  4991. 'ts-date ts-date
  4992. 'org-category-position category-pos
  4993. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4994. (push txt ee)
  4995. (if org-agenda-todo-list-sublevels
  4996. (goto-char todo-state-end-pos)
  4997. (org-end-of-subtree 'invisible))))
  4998. (nreverse ee)))
  4999. (defun org-agenda-todo-custom-ignore-p (time n)
  5000. "Check whether timestamp is farther away than n number of days.
  5001. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5002. `org-agenda-todo-ignore-scheduled' or
  5003. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5004. (let ((days (org-time-stamp-to-now
  5005. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5006. (if (>= n 0)
  5007. (>= days n)
  5008. (<= days n))))
  5009. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5010. (&optional end)
  5011. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5012. (when (or org-agenda-todo-ignore-with-date
  5013. org-agenda-todo-ignore-scheduled
  5014. org-agenda-todo-ignore-deadlines
  5015. org-agenda-todo-ignore-timestamp)
  5016. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5017. (save-excursion
  5018. (or (and org-agenda-todo-ignore-with-date
  5019. (re-search-forward org-ts-regexp end t))
  5020. (and org-agenda-todo-ignore-scheduled
  5021. (re-search-forward org-scheduled-time-regexp end t)
  5022. (cond
  5023. ((eq org-agenda-todo-ignore-scheduled 'future)
  5024. (> (org-time-stamp-to-now
  5025. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5026. ((eq org-agenda-todo-ignore-scheduled 'past)
  5027. (<= (org-time-stamp-to-now
  5028. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5029. ((numberp org-agenda-todo-ignore-scheduled)
  5030. (org-agenda-todo-custom-ignore-p
  5031. (match-string 1) org-agenda-todo-ignore-scheduled))
  5032. (t)))
  5033. (and org-agenda-todo-ignore-deadlines
  5034. (re-search-forward org-deadline-time-regexp end t)
  5035. (cond
  5036. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5037. ((eq org-agenda-todo-ignore-deadlines 'far)
  5038. (not (org-deadline-close (match-string 1))))
  5039. ((eq org-agenda-todo-ignore-deadlines 'future)
  5040. (> (org-time-stamp-to-now
  5041. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5042. ((eq org-agenda-todo-ignore-deadlines 'past)
  5043. (<= (org-time-stamp-to-now
  5044. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5045. ((numberp org-agenda-todo-ignore-deadlines)
  5046. (org-agenda-todo-custom-ignore-p
  5047. (match-string 1) org-agenda-todo-ignore-deadlines))
  5048. (t (org-deadline-close (match-string 1)))))
  5049. (and org-agenda-todo-ignore-timestamp
  5050. (let ((buffer (current-buffer))
  5051. (regexp
  5052. (concat
  5053. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5054. (start (point)))
  5055. ;; Copy current buffer into a temporary one
  5056. (with-temp-buffer
  5057. (insert-buffer-substring buffer start end)
  5058. (goto-char (point-min))
  5059. ;; Delete SCHEDULED and DEADLINE items
  5060. (while (re-search-forward regexp end t)
  5061. (delete-region (match-beginning 0) (match-end 0)))
  5062. (goto-char (point-min))
  5063. ;; No search for timestamp left
  5064. (when (re-search-forward org-ts-regexp nil t)
  5065. (cond
  5066. ((eq org-agenda-todo-ignore-timestamp 'future)
  5067. (> (org-time-stamp-to-now
  5068. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5069. ((eq org-agenda-todo-ignore-timestamp 'past)
  5070. (<= (org-time-stamp-to-now
  5071. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5072. ((numberp org-agenda-todo-ignore-timestamp)
  5073. (org-agenda-todo-custom-ignore-p
  5074. (match-string 1) org-agenda-todo-ignore-timestamp))
  5075. (t))))))))))
  5076. (defun org-agenda-get-timestamps (&optional deadline-results)
  5077. "Return the date stamp information for agenda display."
  5078. (let* ((props (list 'face 'org-agenda-calendar-event
  5079. 'org-not-done-regexp org-not-done-regexp
  5080. 'org-todo-regexp org-todo-regexp
  5081. 'org-complex-heading-regexp org-complex-heading-regexp
  5082. 'mouse-face 'highlight
  5083. 'help-echo
  5084. (format "mouse-2 or RET jump to org file %s"
  5085. (abbreviate-file-name buffer-file-name))))
  5086. (d1 (calendar-absolute-from-gregorian date))
  5087. mm
  5088. (deadline-position-alist
  5089. (mapcar (lambda (a) (and (setq mm (get-text-property
  5090. 0 'org-hd-marker a))
  5091. (cons (marker-position mm) a)))
  5092. deadline-results))
  5093. (remove-re org-ts-regexp)
  5094. (regexp
  5095. (concat
  5096. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5097. (regexp-quote
  5098. (substring
  5099. (format-time-string
  5100. (car org-time-stamp-formats)
  5101. (apply 'encode-time ; DATE bound by calendar
  5102. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5103. 1 11))
  5104. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5105. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5106. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5107. donep tmp priority category category-pos level ee txt timestr tags
  5108. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5109. inherited-tags ts-date)
  5110. (goto-char (point-min))
  5111. (while (setq end-of-match (re-search-forward regexp nil t))
  5112. (setq b0 (match-beginning 0)
  5113. b3 (match-beginning 3) e3 (match-end 3)
  5114. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5115. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5116. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5117. (member todo-state
  5118. org-agenda-repeating-timestamp-show-all)))
  5119. (catch :skip
  5120. (and (org-at-date-range-p) (throw :skip nil))
  5121. (org-agenda-skip)
  5122. (if (and (match-end 1)
  5123. (not (= d1 (org-time-string-to-absolute
  5124. (match-string 1) d1 nil show-all
  5125. (current-buffer) b0))))
  5126. (throw :skip nil))
  5127. (if (and e3
  5128. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5129. (throw :skip nil))
  5130. (setq tmp (buffer-substring (max (point-min)
  5131. (- b0 org-ds-keyword-length))
  5132. b0)
  5133. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5134. inactivep (= (char-after b0) ?\[)
  5135. deadlinep (string-match org-deadline-regexp tmp)
  5136. scheduledp (string-match org-scheduled-regexp tmp)
  5137. closedp (and org-agenda-include-inactive-timestamps
  5138. (string-match org-closed-string tmp))
  5139. clockp (and org-agenda-include-inactive-timestamps
  5140. (or (string-match org-clock-string tmp)
  5141. (string-match "]-+\\'" tmp)))
  5142. warntime (get-text-property (point) 'org-appt-warntime)
  5143. donep (member todo-state org-done-keywords))
  5144. (if (or scheduledp deadlinep closedp clockp
  5145. (and donep org-agenda-skip-timestamp-if-done))
  5146. (throw :skip t))
  5147. (if (string-match ">" timestr)
  5148. ;; substring should only run to end of time stamp
  5149. (setq timestr (substring timestr 0 (match-end 0))))
  5150. (setq marker (org-agenda-new-marker b0)
  5151. category (org-get-category b0)
  5152. category-pos (get-text-property b0 'org-category-position))
  5153. (save-excursion
  5154. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5155. (throw :skip nil)
  5156. (goto-char (match-beginning 0))
  5157. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5158. (assoc (point) deadline-position-alist))
  5159. (throw :skip nil))
  5160. (setq hdmarker (org-agenda-new-marker)
  5161. inherited-tags
  5162. (or (eq org-agenda-show-inherited-tags 'always)
  5163. (and (listp org-agenda-show-inherited-tags)
  5164. (memq 'agenda org-agenda-show-inherited-tags))
  5165. (and (eq org-agenda-show-inherited-tags t)
  5166. (or (eq org-agenda-use-tag-inheritance t)
  5167. (memq 'agenda org-agenda-use-tag-inheritance))))
  5168. tags (org-get-tags-at nil (not inherited-tags))
  5169. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5170. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5171. (setq head (or (match-string 1) ""))
  5172. (setq txt (org-agenda-format-item
  5173. (if inactivep org-agenda-inactive-leader nil)
  5174. head level category tags timestr
  5175. remove-re habitp)))
  5176. (setq priority (org-get-priority txt))
  5177. (org-add-props txt props 'priority priority
  5178. 'org-marker marker 'org-hd-marker hdmarker
  5179. 'org-category category 'date date
  5180. 'level level
  5181. 'ts-date
  5182. (ignore-errors (org-time-string-to-absolute timestr))
  5183. 'org-category-position category-pos
  5184. 'todo-state todo-state
  5185. 'warntime warntime
  5186. 'type "timestamp")
  5187. (push txt ee))
  5188. (if org-agenda-skip-additional-timestamps-same-entry
  5189. (outline-next-heading)
  5190. (goto-char end-of-match))))
  5191. (nreverse ee)))
  5192. (defun org-agenda-get-sexps ()
  5193. "Return the sexp information for agenda display."
  5194. (require 'diary-lib)
  5195. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5196. 'mouse-face 'highlight
  5197. 'help-echo
  5198. (format "mouse-2 or RET jump to org file %s"
  5199. (abbreviate-file-name buffer-file-name))))
  5200. (regexp "^&?%%(")
  5201. marker category extra category-pos level ee txt tags entry
  5202. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5203. (goto-char (point-min))
  5204. (while (re-search-forward regexp nil t)
  5205. (catch :skip
  5206. (org-agenda-skip)
  5207. (setq beg (match-beginning 0))
  5208. (goto-char (1- (match-end 0)))
  5209. (setq b (point))
  5210. (forward-sexp 1)
  5211. (setq sexp (buffer-substring b (point)))
  5212. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5213. (org-trim (match-string 1))
  5214. ""))
  5215. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5216. (when result
  5217. (setq marker (org-agenda-new-marker beg)
  5218. level (make-string (org-reduced-level (org-outline-level)) ? )
  5219. category (org-get-category beg)
  5220. category-pos (get-text-property beg 'org-category-position)
  5221. inherited-tags
  5222. (or (eq org-agenda-show-inherited-tags 'always)
  5223. (and (listp org-agenda-show-inherited-tags)
  5224. (memq 'agenda org-agenda-show-inherited-tags))
  5225. (and (eq org-agenda-show-inherited-tags t)
  5226. (or (eq org-agenda-use-tag-inheritance t)
  5227. (memq 'agenda org-agenda-use-tag-inheritance))))
  5228. tags (org-get-tags-at nil (not inherited-tags))
  5229. todo-state (org-get-todo-state)
  5230. warntime (get-text-property (point) 'org-appt-warntime)
  5231. extra nil)
  5232. (dolist (r (if (stringp result)
  5233. (list result)
  5234. result)) ;; we expect a list here
  5235. (when (and org-agenda-diary-sexp-prefix
  5236. (string-match org-agenda-diary-sexp-prefix r))
  5237. (setq extra (match-string 0 r)
  5238. r (replace-match "" nil nil r)))
  5239. (if (string-match "\\S-" r)
  5240. (setq txt r)
  5241. (setq txt "SEXP entry returned empty string"))
  5242. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5243. (org-add-props txt props 'org-marker marker
  5244. 'org-category category 'date date 'todo-state todo-state
  5245. 'org-category-position category-pos 'tags tags
  5246. 'level level
  5247. 'type "sexp" 'warntime warntime)
  5248. (push txt ee)))))
  5249. (nreverse ee)))
  5250. ;; Calendar sanity: define some functions that are independent of
  5251. ;; `calendar-date-style'.
  5252. ;; Normally I would like to use ISO format when calling the diary functions,
  5253. ;; but to make sure we still have Emacs 22 compatibility we bind
  5254. ;; also `european-calendar-style' and use european format
  5255. (defun org-anniversary (year month day &optional mark)
  5256. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5257. (org-no-warnings
  5258. (let ((calendar-date-style 'european) (european-calendar-style t))
  5259. (diary-anniversary day month year mark))))
  5260. (defun org-cyclic (N year month day &optional mark)
  5261. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5262. (org-no-warnings
  5263. (let ((calendar-date-style 'european) (european-calendar-style t))
  5264. (diary-cyclic N day month year mark))))
  5265. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5266. "Like `diary-block', but with fixed (ISO) order of arguments."
  5267. (org-no-warnings
  5268. (let ((calendar-date-style 'european) (european-calendar-style t))
  5269. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5270. (defun org-date (year month day &optional mark)
  5271. "Like `diary-date', but with fixed (ISO) order of arguments."
  5272. (org-no-warnings
  5273. (let ((calendar-date-style 'european) (european-calendar-style t))
  5274. (diary-date day month year mark))))
  5275. ;; Define the` org-class' function
  5276. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5277. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5278. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5279. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5280. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5281. `holidays', then any date that is known by the Emacs calendar to be a
  5282. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5283. then those holidays will be skipped."
  5284. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5285. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5286. (d (calendar-absolute-from-gregorian date))
  5287. (h (when skip-weeks (calendar-check-holidays date))))
  5288. (and
  5289. (<= date1 d)
  5290. (<= d date2)
  5291. (= (calendar-day-of-week date) dayname)
  5292. (or (not skip-weeks)
  5293. (progn
  5294. (require 'cal-iso)
  5295. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5296. (not (or (and h (memq 'holidays skip-weeks))
  5297. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5298. entry)))
  5299. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5300. "Like `org-class', but honor `calendar-date-style'.
  5301. The order of the first 2 times 3 arguments depends on the variable
  5302. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5303. So for American calendars, give this as MONTH DAY YEAR, for European as
  5304. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5305. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5306. is any number of ISO weeks in the block period for which the item should
  5307. be skipped.
  5308. This function is here only for backward compatibility and it is deprecated,
  5309. please use `org-class' instead."
  5310. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5311. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5312. (org-class
  5313. (nth 2 date1) (car date1) (nth 1 date1)
  5314. (nth 2 date2) (car date2) (nth 1 date2)
  5315. dayname skip-weeks)))
  5316. (make-obsolete 'org-diary-class 'org-class "")
  5317. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5318. (defalias 'org-get-closed 'org-agenda-get-progress)
  5319. (defun org-agenda-get-progress ()
  5320. "Return the logged TODO entries for agenda display."
  5321. (let* ((props (list 'mouse-face 'highlight
  5322. 'org-not-done-regexp org-not-done-regexp
  5323. 'org-todo-regexp org-todo-regexp
  5324. 'org-complex-heading-regexp org-complex-heading-regexp
  5325. 'help-echo
  5326. (format "mouse-2 or RET jump to org file %s"
  5327. (abbreviate-file-name buffer-file-name))))
  5328. (items (if (consp org-agenda-show-log-scoped)
  5329. org-agenda-show-log-scoped
  5330. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5331. '(clock)
  5332. org-agenda-log-mode-items)))
  5333. (parts
  5334. (delq nil
  5335. (list
  5336. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5337. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5338. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5339. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5340. (error "`org-agenda-log-mode-items' is empty")))
  5341. (regexp (concat
  5342. "\\(" parts-re "\\)"
  5343. " *\\["
  5344. (regexp-quote
  5345. (substring
  5346. (format-time-string
  5347. (car org-time-stamp-formats)
  5348. (apply 'encode-time ; DATE bound by calendar
  5349. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5350. 1 11))))
  5351. (org-agenda-search-headline-for-time nil)
  5352. marker hdmarker priority category category-pos level tags closedp
  5353. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5354. (goto-char (point-min))
  5355. (while (re-search-forward regexp nil t)
  5356. (catch :skip
  5357. (org-agenda-skip)
  5358. (setq marker (org-agenda-new-marker (match-beginning 0))
  5359. closedp (equal (match-string 1) org-closed-string)
  5360. statep (equal (string-to-char (match-string 1)) ?-)
  5361. clockp (not (or closedp statep))
  5362. state (and statep (match-string 2))
  5363. category (org-get-category (match-beginning 0))
  5364. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5365. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5366. (when (string-match "\\]" timestr)
  5367. ;; substring should only run to end of time stamp
  5368. (setq rest (substring timestr (match-end 0))
  5369. timestr (substring timestr 0 (match-end 0)))
  5370. (if (and (not closedp) (not statep)
  5371. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5372. rest))
  5373. (progn (setq timestr (concat (substring timestr 0 -1)
  5374. "-" (match-string 1 rest) "]"))
  5375. (setq clocked (match-string 2 rest)))
  5376. (setq clocked "-")))
  5377. (save-excursion
  5378. (setq extra
  5379. (cond
  5380. ((not org-agenda-log-mode-add-notes) nil)
  5381. (statep
  5382. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5383. (match-string 1)))
  5384. (clockp
  5385. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5386. (match-string 1)))))
  5387. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5388. (throw :skip nil)
  5389. (goto-char (match-beginning 0))
  5390. (setq hdmarker (org-agenda-new-marker)
  5391. inherited-tags
  5392. (or (eq org-agenda-show-inherited-tags 'always)
  5393. (and (listp org-agenda-show-inherited-tags)
  5394. (memq 'todo org-agenda-show-inherited-tags))
  5395. (and (eq org-agenda-show-inherited-tags t)
  5396. (or (eq org-agenda-use-tag-inheritance t)
  5397. (memq 'todo org-agenda-use-tag-inheritance))))
  5398. tags (org-get-tags-at nil (not inherited-tags))
  5399. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5400. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5401. (setq txt (match-string 1))
  5402. (when extra
  5403. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5404. (setq txt (concat (substring txt 0 (match-beginning 1))
  5405. " - " extra " " (match-string 2 txt)))
  5406. (setq txt (concat txt " - " extra))))
  5407. (setq txt (org-agenda-format-item
  5408. (cond
  5409. (closedp "Closed: ")
  5410. (statep (concat "State: (" state ")"))
  5411. (t (concat "Clocked: (" clocked ")")))
  5412. txt level category tags timestr)))
  5413. (setq priority 100000)
  5414. (org-add-props txt props
  5415. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5416. 'priority priority 'org-category category
  5417. 'org-category-position category-pos
  5418. 'level level
  5419. 'type "closed" 'date date
  5420. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5421. (push txt ee))
  5422. (goto-char (point-at-eol))))
  5423. (nreverse ee)))
  5424. (defun org-agenda-show-clocking-issues ()
  5425. "Add overlays, showing issues with clocking.
  5426. See also the user option `org-agenda-clock-consistency-checks'."
  5427. (interactive)
  5428. (let* ((org-time-clocksum-use-effort-durations nil)
  5429. (pl org-agenda-clock-consistency-checks)
  5430. (re (concat "^[ \t]*"
  5431. org-clock-string
  5432. "[ \t]+"
  5433. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5434. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5435. (tlstart 0.)
  5436. (tlend 0.)
  5437. (maxtime (org-hh:mm-string-to-minutes
  5438. (or (plist-get pl :max-duration) "24:00")))
  5439. (mintime (org-hh:mm-string-to-minutes
  5440. (or (plist-get pl :min-duration) 0)))
  5441. (maxgap (org-hh:mm-string-to-minutes
  5442. ;; default 30:00 means never complain
  5443. (or (plist-get pl :max-gap) "30:00")))
  5444. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5445. (plist-get pl :gap-ok-around)))
  5446. (def-face (or (plist-get pl :default-face)
  5447. '((:background "DarkRed") (:foreground "white"))))
  5448. issue face m te ts dt ov)
  5449. (goto-char (point-min))
  5450. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5451. (setq issue nil face def-face)
  5452. (catch 'next
  5453. (setq m (org-get-at-bol 'org-marker)
  5454. te nil ts nil)
  5455. (unless (and m (markerp m))
  5456. (setq issue "No valid clock line") (throw 'next t))
  5457. (org-with-point-at m
  5458. (save-excursion
  5459. (goto-char (point-at-bol))
  5460. (unless (looking-at re)
  5461. (error "No valid Clock line")
  5462. (throw 'next t))
  5463. (unless (match-end 3)
  5464. (setq issue "No end time"
  5465. face (or (plist-get pl :no-end-time-face) face))
  5466. (throw 'next t))
  5467. (setq ts (match-string 1)
  5468. te (match-string 3)
  5469. ts (org-float-time
  5470. (apply 'encode-time (org-parse-time-string ts)))
  5471. te (org-float-time
  5472. (apply 'encode-time (org-parse-time-string te)))
  5473. dt (- te ts))))
  5474. (cond
  5475. ((> dt (* 60 maxtime))
  5476. ;; a very long clocking chunk
  5477. (setq issue (format "Clocking interval is very long: %s"
  5478. (org-minutes-to-clocksum-string
  5479. (floor (/ (float dt) 60.))))
  5480. face (or (plist-get pl :long-face) face)))
  5481. ((< dt (* 60 mintime))
  5482. ;; a very short clocking chunk
  5483. (setq issue (format "Clocking interval is very short: %s"
  5484. (org-minutes-to-clocksum-string
  5485. (floor (/ (float dt) 60.))))
  5486. face (or (plist-get pl :short-face) face)))
  5487. ((and (> tlend 0) (< ts tlend))
  5488. ;; Two clock entries are overlapping
  5489. (setq issue (format "Clocking overlap: %d minutes"
  5490. (/ (- tlend ts) 60))
  5491. face (or (plist-get pl :overlap-face) face)))
  5492. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5493. ;; There is a gap, lets see if we need to report it
  5494. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5495. (setq issue (format "Clocking gap: %d minutes"
  5496. (/ (- ts tlend) 60))
  5497. face (or (plist-get pl :gap-face) face))))
  5498. (t nil)))
  5499. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5500. (when issue
  5501. ;; OK, there was some issue, add an overlay to show the issue
  5502. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5503. (overlay-put ov 'before-string
  5504. (concat
  5505. (org-add-props
  5506. (format "%-43s" (concat " " issue))
  5507. nil
  5508. 'face face)
  5509. "\n"))
  5510. (overlay-put ov 'evaporate t)))))
  5511. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5512. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5513. (catch 'exit
  5514. (unless ok-list
  5515. ;; there are no OK times for gaps...
  5516. (throw 'exit nil))
  5517. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5518. ;; This is more than 24 hours, so it is OK.
  5519. ;; because we have at least one OK time, that must be in the
  5520. ;; 24 hour interval.
  5521. (throw 'exit t))
  5522. ;; We have a shorter gap.
  5523. ;; Now we have to get the minute of the day when these times are
  5524. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5525. (t2dec (decode-time (seconds-to-time t2)))
  5526. ;; compute the minute on the day
  5527. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5528. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5529. (when (< min2 min1)
  5530. ;; if min2 is smaller than min1, this means it is on the next day.
  5531. ;; Wrap it to after midnight.
  5532. (setq min2 (+ min2 1440)))
  5533. ;; Now check if any of the OK times is in the gap
  5534. (mapc (lambda (x)
  5535. ;; Wrap the time to after midnight if necessary
  5536. (if (< x min1) (setq x (+ x 1440)))
  5537. ;; Check if in interval
  5538. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5539. ok-list)
  5540. ;; Nope, this gap is not OK
  5541. nil)))
  5542. (defun org-agenda-get-deadlines (&optional with-hour)
  5543. "Return the deadline information for agenda display.
  5544. When WITH-HOUR is non-nil, only return deadlines with an hour
  5545. specification like [h]h:mm."
  5546. (let* ((props (list 'mouse-face 'highlight
  5547. 'org-not-done-regexp org-not-done-regexp
  5548. 'org-todo-regexp org-todo-regexp
  5549. 'org-complex-heading-regexp org-complex-heading-regexp
  5550. 'help-echo
  5551. (format "mouse-2 or RET jump to org file %s"
  5552. (abbreviate-file-name buffer-file-name))))
  5553. (regexp (if with-hour
  5554. org-deadline-time-hour-regexp
  5555. org-deadline-time-regexp))
  5556. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5557. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5558. (dl0 (car org-agenda-deadline-leaders))
  5559. (dl1 (nth 1 org-agenda-deadline-leaders))
  5560. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5561. d2 diff dfrac wdays pos pos1 category category-pos level
  5562. tags suppress-prewarning ee txt head face s todo-state
  5563. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5564. (goto-char (point-min))
  5565. (while (re-search-forward regexp nil t)
  5566. (catch :skip
  5567. (org-agenda-skip)
  5568. (setq s (match-string 1)
  5569. txt nil
  5570. pos (1- (match-beginning 1))
  5571. todo-state (save-match-data (org-get-todo-state))
  5572. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5573. (member todo-state
  5574. org-agenda-repeating-timestamp-show-all))
  5575. d2 (org-time-string-to-absolute
  5576. s d1 'past show-all (current-buffer) pos)
  5577. diff (- d2 d1))
  5578. (setq suppress-prewarning
  5579. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5580. (let ((item (buffer-substring (point-at-bol)
  5581. (point-at-eol))))
  5582. (save-match-data
  5583. (and (string-match
  5584. org-scheduled-time-regexp item)
  5585. (match-string 1 item)))))))
  5586. (cond
  5587. ((not ds) nil)
  5588. ;; The current item has a scheduled date (in ds), so
  5589. ;; evaluate its prewarning lead time.
  5590. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5591. ;; Use global prewarning-restart lead time.
  5592. org-agenda-skip-deadline-prewarning-if-scheduled)
  5593. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5594. 'pre-scheduled)
  5595. ;; Set prewarning to no earlier than scheduled.
  5596. (min (- d2 (org-time-string-to-absolute
  5597. ds d1 'past show-all (current-buffer) pos))
  5598. org-deadline-warning-days))
  5599. ;; Set prewarning to deadline.
  5600. (t 0))))
  5601. (setq wdays (if suppress-prewarning
  5602. (let ((org-deadline-warning-days suppress-prewarning))
  5603. (org-get-wdays s))
  5604. (org-get-wdays s))
  5605. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5606. upcomingp (and todayp (> diff 0)))
  5607. ;; When to show a deadline in the calendar:
  5608. ;; If the expiration is within wdays warning time.
  5609. ;; Past-due deadlines are only shown on the current date
  5610. (if (and (or (and (<= diff wdays)
  5611. (and todayp (not org-agenda-only-exact-dates)))
  5612. (= diff 0)))
  5613. (save-excursion
  5614. ;; (setq todo-state (org-get-todo-state))
  5615. (setq donep (member todo-state org-done-keywords))
  5616. (if (and donep
  5617. (or org-agenda-skip-deadline-if-done
  5618. (not (= diff 0))))
  5619. (setq txt nil)
  5620. (setq category (org-get-category)
  5621. warntime (get-text-property (point) 'org-appt-warntime)
  5622. category-pos (get-text-property (point) 'org-category-position))
  5623. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5624. (throw :skip nil)
  5625. (goto-char (match-end 0))
  5626. (setq pos1 (match-beginning 0))
  5627. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5628. (setq inherited-tags
  5629. (or (eq org-agenda-show-inherited-tags 'always)
  5630. (and (listp org-agenda-show-inherited-tags)
  5631. (memq 'agenda org-agenda-show-inherited-tags))
  5632. (and (eq org-agenda-show-inherited-tags t)
  5633. (or (eq org-agenda-use-tag-inheritance t)
  5634. (memq 'agenda org-agenda-use-tag-inheritance))))
  5635. tags (org-get-tags-at pos1 (not inherited-tags)))
  5636. (setq head (buffer-substring
  5637. (point)
  5638. (progn (skip-chars-forward "^\r\n")
  5639. (point))))
  5640. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5641. (setq timestr
  5642. (concat (substring s (match-beginning 1)) " "))
  5643. (setq timestr 'time))
  5644. (setq txt (org-agenda-format-item
  5645. (cond ((= diff 0) dl0)
  5646. ((> diff 0)
  5647. (if (functionp dl1)
  5648. (funcall dl1 diff date)
  5649. (format dl1 diff)))
  5650. (t
  5651. (if (functionp dl2)
  5652. (funcall dl2 diff date)
  5653. (format dl2 (if (string= dl2 dl1)
  5654. diff (abs diff))))))
  5655. head level category tags
  5656. (if (not (= diff 0)) nil timestr)))))
  5657. (when txt
  5658. (setq face (org-agenda-deadline-face dfrac))
  5659. (org-add-props txt props
  5660. 'org-marker (org-agenda-new-marker pos)
  5661. 'warntime warntime
  5662. 'level level
  5663. 'ts-date d2
  5664. 'org-hd-marker (org-agenda-new-marker pos1)
  5665. 'priority (+ (- diff)
  5666. (org-get-priority txt))
  5667. 'org-category category
  5668. 'org-category-position category-pos
  5669. 'todo-state todo-state
  5670. 'type (if upcomingp "upcoming-deadline" "deadline")
  5671. 'date (if upcomingp date d2)
  5672. 'face (if donep 'org-agenda-done face)
  5673. 'undone-face face 'done-face 'org-agenda-done)
  5674. (push txt ee))))))
  5675. (nreverse ee)))
  5676. (defun org-agenda-deadline-face (fraction)
  5677. "Return the face to displaying a deadline item.
  5678. FRACTION is what fraction of the head-warning time has passed."
  5679. (let ((faces org-agenda-deadline-faces) f)
  5680. (catch 'exit
  5681. (while (setq f (pop faces))
  5682. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5683. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5684. "Return the scheduled information for agenda display.
  5685. When WITH-HOUR is non-nil, only return scheduled items with
  5686. an hour specification like [h]h:mm."
  5687. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5688. 'org-todo-regexp org-todo-regexp
  5689. 'org-complex-heading-regexp org-complex-heading-regexp
  5690. 'done-face 'org-agenda-done
  5691. 'mouse-face 'highlight
  5692. 'help-echo
  5693. (format "mouse-2 or RET jump to org file %s"
  5694. (abbreviate-file-name buffer-file-name))))
  5695. (regexp (if with-hour
  5696. org-scheduled-time-hour-regexp
  5697. org-scheduled-time-regexp))
  5698. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5699. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5700. mm
  5701. (deadline-position-alist
  5702. (mapcar (lambda (a) (and (setq mm (get-text-property
  5703. 0 'org-hd-marker a))
  5704. (cons (marker-position mm) a)))
  5705. deadline-results))
  5706. d2 diff pos pos1 category category-pos level tags donep
  5707. ee txt head pastschedp todo-state face timestr s habitp show-all
  5708. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5709. ddays)
  5710. (goto-char (point-min))
  5711. (while (re-search-forward regexp nil t)
  5712. (catch :skip
  5713. (org-agenda-skip)
  5714. (setq s (match-string 1)
  5715. txt nil
  5716. pos (1- (match-beginning 1))
  5717. todo-state (save-match-data (org-get-todo-state))
  5718. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5719. (member todo-state
  5720. org-agenda-repeating-timestamp-show-all))
  5721. d2 (org-time-string-to-absolute
  5722. s d1 'past show-all (current-buffer) pos)
  5723. diff (- d2 d1)
  5724. warntime (get-text-property (point) 'org-appt-warntime))
  5725. (setq pastschedp (and todayp (< diff 0)))
  5726. (setq did-habit-check-p nil)
  5727. (setq suppress-delay
  5728. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5729. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5730. (save-match-data
  5731. (and (string-match
  5732. org-deadline-time-regexp item)
  5733. (match-string 1 item)))))))
  5734. (cond
  5735. ((not ds) nil)
  5736. ;; The current item has a deadline date (in ds), so
  5737. ;; evaluate its delay time.
  5738. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5739. ;; Use global delay time.
  5740. (- org-agenda-skip-scheduled-delay-if-deadline))
  5741. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5742. 'post-deadline)
  5743. ;; Set delay to no later than deadline.
  5744. (min (- d2 (org-time-string-to-absolute
  5745. ds d1 'past show-all (current-buffer) pos))
  5746. org-scheduled-delay-days))
  5747. (t 0))))
  5748. (setq ddays (if suppress-delay
  5749. (let ((org-scheduled-delay-days suppress-delay))
  5750. (org-get-wdays s t t))
  5751. (org-get-wdays s t)))
  5752. ;; Use a delay of 0 when there is a repeater and the delay is
  5753. ;; of the form --3d
  5754. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5755. (< (org-time-string-to-absolute s)
  5756. (org-time-string-to-absolute
  5757. s d2 'past nil (current-buffer) pos)))
  5758. (setq ddays 0))
  5759. ;; When to show a scheduled item in the calendar:
  5760. ;; If it is on or past the date.
  5761. (when (or (and (> ddays 0) (= diff (- ddays)))
  5762. (and (zerop ddays) (= diff 0))
  5763. (and (< (+ diff ddays) 0)
  5764. (< (abs diff) org-scheduled-past-days)
  5765. (and todayp (not org-agenda-only-exact-dates)))
  5766. ;; org-is-habit-p uses org-entry-get, which is expansive
  5767. ;; so we go extra mile to only call it once
  5768. (and todayp
  5769. (boundp 'org-habit-show-all-today)
  5770. org-habit-show-all-today
  5771. (setq did-habit-check-p t)
  5772. (setq habitp (and (functionp 'org-is-habit-p)
  5773. (org-is-habit-p)))))
  5774. (save-excursion
  5775. (setq donep (member todo-state org-done-keywords))
  5776. (if (and donep
  5777. (or org-agenda-skip-scheduled-if-done
  5778. (not (= diff 0))
  5779. (and (functionp 'org-is-habit-p)
  5780. (org-is-habit-p))))
  5781. (setq txt nil)
  5782. (setq habitp (if did-habit-check-p habitp
  5783. (and (functionp 'org-is-habit-p)
  5784. (org-is-habit-p))))
  5785. (setq category (org-get-category)
  5786. category-pos (get-text-property (point) 'org-category-position))
  5787. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5788. 'repeated-after-deadline)
  5789. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5790. (throw :skip nil))
  5791. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5792. (throw :skip nil)
  5793. (goto-char (match-end 0))
  5794. (setq pos1 (match-beginning 0))
  5795. (if habitp
  5796. (if (or (not org-habit-show-habits)
  5797. (and (not todayp)
  5798. (boundp 'org-habit-show-habits-only-for-today)
  5799. org-habit-show-habits-only-for-today))
  5800. (throw :skip nil))
  5801. (if (and
  5802. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5803. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5804. pastschedp))
  5805. (setq mm (assoc pos1 deadline-position-alist)))
  5806. (throw :skip nil)))
  5807. (setq inherited-tags
  5808. (or (eq org-agenda-show-inherited-tags 'always)
  5809. (and (listp org-agenda-show-inherited-tags)
  5810. (memq 'agenda org-agenda-show-inherited-tags))
  5811. (and (eq org-agenda-show-inherited-tags t)
  5812. (or (eq org-agenda-use-tag-inheritance t)
  5813. (memq 'agenda org-agenda-use-tag-inheritance))))
  5814. tags (org-get-tags-at nil (not inherited-tags)))
  5815. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5816. (setq head (buffer-substring
  5817. (point)
  5818. (progn (skip-chars-forward "^\r\n") (point))))
  5819. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5820. (setq timestr
  5821. (concat (substring s (match-beginning 1)) " "))
  5822. (setq timestr 'time))
  5823. (setq txt (org-agenda-format-item
  5824. (if (= diff 0)
  5825. (car org-agenda-scheduled-leaders)
  5826. (format (nth 1 org-agenda-scheduled-leaders)
  5827. (- 1 diff)))
  5828. head level category tags
  5829. (if (not (= diff 0)) nil timestr)
  5830. nil habitp))))
  5831. (when txt
  5832. (setq face
  5833. (cond
  5834. ((and (not habitp) pastschedp)
  5835. 'org-scheduled-previously)
  5836. (todayp 'org-scheduled-today)
  5837. (t 'org-scheduled))
  5838. habitp (and habitp (org-habit-parse-todo)))
  5839. (org-add-props txt props
  5840. 'undone-face face
  5841. 'face (if donep 'org-agenda-done face)
  5842. 'org-marker (org-agenda-new-marker pos)
  5843. 'org-hd-marker (org-agenda-new-marker pos1)
  5844. 'type (if pastschedp "past-scheduled" "scheduled")
  5845. 'date (if pastschedp d2 date)
  5846. 'ts-date d2
  5847. 'warntime warntime
  5848. 'level level
  5849. 'priority (if habitp
  5850. (org-habit-get-priority habitp)
  5851. (+ 94 (- 5 diff) (org-get-priority txt)))
  5852. 'org-category category
  5853. 'category-position category-pos
  5854. 'org-habit-p habitp
  5855. 'todo-state todo-state)
  5856. (push txt ee))))))
  5857. (nreverse ee)))
  5858. (defun org-agenda-get-blocks ()
  5859. "Return the date-range information for agenda display."
  5860. (let* ((props (list 'face nil
  5861. 'org-not-done-regexp org-not-done-regexp
  5862. 'org-todo-regexp org-todo-regexp
  5863. 'org-complex-heading-regexp org-complex-heading-regexp
  5864. 'mouse-face 'highlight
  5865. 'help-echo
  5866. (format "mouse-2 or RET jump to org file %s"
  5867. (abbreviate-file-name buffer-file-name))))
  5868. (regexp org-tr-regexp)
  5869. (d0 (calendar-absolute-from-gregorian date))
  5870. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5871. level todo-state tags pos head donep inherited-tags)
  5872. (goto-char (point-min))
  5873. (while (re-search-forward regexp nil t)
  5874. (catch :skip
  5875. (org-agenda-skip)
  5876. (setq pos (point))
  5877. (let ((start-time (match-string 1))
  5878. (end-time (match-string 2)))
  5879. (setq s1 (match-string 1)
  5880. s2 (match-string 2)
  5881. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5882. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5883. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5884. ;; Only allow days between the limits, because the normal
  5885. ;; date stamps will catch the limits.
  5886. (save-excursion
  5887. (setq todo-state (org-get-todo-state))
  5888. (setq donep (member todo-state org-done-keywords))
  5889. (if (and donep org-agenda-skip-timestamp-if-done)
  5890. (throw :skip t))
  5891. (setq marker (org-agenda-new-marker (point)))
  5892. (setq category (org-get-category)
  5893. category-pos (get-text-property (point) 'org-category-position))
  5894. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5895. (throw :skip nil)
  5896. (goto-char (match-beginning 0))
  5897. (setq hdmarker (org-agenda-new-marker (point))
  5898. inherited-tags
  5899. (or (eq org-agenda-show-inherited-tags 'always)
  5900. (and (listp org-agenda-show-inherited-tags)
  5901. (memq 'agenda org-agenda-show-inherited-tags))
  5902. (and (eq org-agenda-show-inherited-tags t)
  5903. (or (eq org-agenda-use-tag-inheritance t)
  5904. (memq 'agenda org-agenda-use-tag-inheritance))))
  5905. tags (org-get-tags-at nil (not inherited-tags)))
  5906. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5907. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5908. (setq head (match-string 1))
  5909. (let ((remove-re
  5910. (if org-agenda-remove-timeranges-from-blocks
  5911. (concat
  5912. "<" (regexp-quote s1) ".*?>"
  5913. "--"
  5914. "<" (regexp-quote s2) ".*?>")
  5915. nil)))
  5916. (setq txt (org-agenda-format-item
  5917. (format
  5918. (nth (if (= d1 d2) 0 1)
  5919. org-agenda-timerange-leaders)
  5920. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5921. head level category tags
  5922. (cond ((and (= d1 d0) (= d2 d0))
  5923. (concat "<" start-time ">--<" end-time ">"))
  5924. ((= d1 d0)
  5925. (concat "<" start-time ">"))
  5926. ((= d2 d0)
  5927. (concat "<" end-time ">")))
  5928. remove-re))))
  5929. (org-add-props txt props
  5930. 'org-marker marker 'org-hd-marker hdmarker
  5931. 'type "block" 'date date
  5932. 'level level
  5933. 'todo-state todo-state
  5934. 'priority (org-get-priority txt) 'org-category category
  5935. 'org-category-position category-pos)
  5936. (push txt ee))))
  5937. (goto-char pos)))
  5938. ;; Sort the entries by expiration date.
  5939. (nreverse ee)))
  5940. ;;; Agenda presentation and sorting
  5941. (defvar org-prefix-has-time nil
  5942. "A flag, set by `org-compile-prefix-format'.
  5943. The flag is set if the currently compiled format contains a `%t'.")
  5944. (defvar org-prefix-has-tag nil
  5945. "A flag, set by `org-compile-prefix-format'.
  5946. The flag is set if the currently compiled format contains a `%T'.")
  5947. (defvar org-prefix-has-effort nil
  5948. "A flag, set by `org-compile-prefix-format'.
  5949. The flag is set if the currently compiled format contains a `%e'.")
  5950. (defvar org-prefix-has-breadcrumbs nil
  5951. "A flag, set by `org-compile-prefix-format'.
  5952. The flag is set if the currently compiled format contains a `%b'.")
  5953. (defvar org-prefix-category-length nil
  5954. "Used by `org-compile-prefix-format' to remember the category field width.")
  5955. (defvar org-prefix-category-max-length nil
  5956. "Used by `org-compile-prefix-format' to remember the category field width.")
  5957. (defun org-agenda-get-category-icon (category)
  5958. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5959. (dolist (entry org-agenda-category-icon-alist)
  5960. (when (org-string-match-p (car entry) category)
  5961. (if (listp (cadr entry))
  5962. (return (cadr entry))
  5963. (return (apply 'create-image (cdr entry)))))))
  5964. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5965. remove-re habitp)
  5966. "Format TXT to be inserted into the agenda buffer.
  5967. In particular, add the prefix and corresponding text properties.
  5968. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5969. LEVEL may be a string to replace the `%l' specifier.
  5970. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5971. category taken from local variable or file name. It will replace the `%c'
  5972. specifier in the format.
  5973. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5974. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5975. When DOTIME is a string, this string is searched for a time before TXT is.
  5976. TAGS can be the tags of the headline.
  5977. Any match of REMOVE-RE will be removed from TXT."
  5978. ;; We keep the org-prefix-* variable values along with a compiled
  5979. ;; formatter, so that multiple agendas existing at the same time do
  5980. ;; not step on each other toes.
  5981. ;;
  5982. ;; It was inconvenient to make these variables buffer local in
  5983. ;; Agenda buffers, because this function expects to be called with
  5984. ;; the buffer where item comes from being current, and not agenda
  5985. ;; buffer
  5986. (let* ((bindings (car org-prefix-format-compiled))
  5987. (formatter (cadr org-prefix-format-compiled)))
  5988. (loop for (var value) in bindings
  5989. do (set var value))
  5990. (save-match-data
  5991. ;; Diary entries sometimes have extra whitespace at the beginning
  5992. (setq txt (org-trim txt))
  5993. ;; Fix the tags part in txt
  5994. (setq txt (org-agenda-fix-displayed-tags
  5995. txt tags
  5996. org-agenda-show-inherited-tags
  5997. org-agenda-hide-tags-regexp))
  5998. (let* ((category (or category
  5999. (if (stringp org-category)
  6000. org-category
  6001. (and org-category (symbol-name org-category)))
  6002. (if buffer-file-name
  6003. (file-name-sans-extension
  6004. (file-name-nondirectory buffer-file-name))
  6005. "")))
  6006. (category-icon (org-agenda-get-category-icon category))
  6007. (category-icon (if category-icon
  6008. (propertize " " 'display category-icon)
  6009. ""))
  6010. ;; time, tag, effort are needed for the eval of the prefix format
  6011. (tag (if tags (nth (1- (length tags)) tags) ""))
  6012. time effort neffort
  6013. (ts (if dotime (concat
  6014. (if (stringp dotime) dotime "")
  6015. (and org-agenda-search-headline-for-time txt))))
  6016. (time-of-day (and dotime (org-get-time-of-day ts)))
  6017. stamp plain s0 s1 s2 rtn srp l
  6018. duration thecategory breadcrumbs)
  6019. (and (derived-mode-p 'org-mode) buffer-file-name
  6020. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6021. (when (and dotime time-of-day)
  6022. ;; Extract starting and ending time and move them to prefix
  6023. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6024. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6025. (setq s0 (match-string 0 ts)
  6026. srp (and stamp (match-end 3))
  6027. s1 (match-string (if plain 1 2) ts)
  6028. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6029. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6030. ;; them, we might want to remove them there to avoid duplication.
  6031. ;; The user can turn this off with a variable.
  6032. (if (and org-prefix-has-time
  6033. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6034. (string-match (concat (regexp-quote s0) " *") txt)
  6035. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6036. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6037. (= (match-beginning 0) 0)
  6038. t))
  6039. (setq txt (replace-match "" nil nil txt))))
  6040. ;; Normalize the time(s) to 24 hour
  6041. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6042. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6043. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6044. (let (org-time-clocksum-use-effort-durations)
  6045. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6046. (setq s2
  6047. (org-minutes-to-clocksum-string
  6048. (+ (org-hh:mm-string-to-minutes s1)
  6049. org-agenda-default-appointment-duration)))))
  6050. ;; Compute the duration
  6051. (when s2
  6052. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6053. (org-hh:mm-string-to-minutes s1)))))
  6054. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6055. txt)
  6056. ;; Tags are in the string
  6057. (if (or (eq org-agenda-remove-tags t)
  6058. (and org-agenda-remove-tags
  6059. org-prefix-has-tag))
  6060. (setq txt (replace-match "" t t txt))
  6061. (setq txt (replace-match
  6062. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6063. (match-string 2 txt))
  6064. t t txt))))
  6065. (when (derived-mode-p 'org-mode)
  6066. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6067. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6068. ;; current buffer, so move this check outside of above
  6069. (if effort
  6070. (setq neffort (org-duration-string-to-minutes effort)
  6071. effort (setq effort (concat "[" effort "]")))
  6072. ;; prevent erroring out with %e format when there is no effort
  6073. (setq effort ""))
  6074. (when remove-re
  6075. (while (string-match remove-re txt)
  6076. (setq txt (replace-match "" t t txt))))
  6077. ;; Set org-heading property on `txt' to mark the start of the
  6078. ;; heading.
  6079. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6080. ;; Prepare the variables needed in the eval of the compiled format
  6081. (if org-prefix-has-breadcrumbs
  6082. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6083. (let ((s (org-display-outline-path nil nil "->" t)))
  6084. (if (eq "" s) "" (concat s "->"))))))
  6085. (setq time (cond (s2 (concat
  6086. (org-agenda-time-of-day-to-ampm-maybe s1)
  6087. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6088. (if org-agenda-timegrid-use-ampm " ")))
  6089. (s1 (concat
  6090. (org-agenda-time-of-day-to-ampm-maybe s1)
  6091. (if org-agenda-timegrid-use-ampm
  6092. "........ "
  6093. "......")))
  6094. (t ""))
  6095. extra (or (and (not habitp) extra) "")
  6096. category (if (symbolp category) (symbol-name category) category)
  6097. thecategory (copy-sequence category)
  6098. level (or level ""))
  6099. (if (string-match org-bracket-link-regexp category)
  6100. (progn
  6101. (setq l (if (match-end 3)
  6102. (- (match-end 3) (match-beginning 3))
  6103. (- (match-end 1) (match-beginning 1))))
  6104. (when (< l (or org-prefix-category-length 0))
  6105. (setq category (copy-sequence category))
  6106. (org-add-props category nil
  6107. 'extra-space (make-string
  6108. (- org-prefix-category-length l 1) ?\ ))))
  6109. (if (and org-prefix-category-max-length
  6110. (>= (length category) org-prefix-category-max-length))
  6111. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6112. ;; Evaluate the compiled format
  6113. (setq rtn (concat (eval formatter) txt))
  6114. ;; And finally add the text properties
  6115. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6116. (org-add-props rtn nil
  6117. 'org-category (if thecategory (downcase thecategory) category)
  6118. 'tags (mapcar 'org-downcase-keep-props tags)
  6119. 'org-highest-priority org-highest-priority
  6120. 'org-lowest-priority org-lowest-priority
  6121. 'time-of-day time-of-day
  6122. 'duration duration
  6123. 'effort effort
  6124. 'effort-minutes neffort
  6125. 'breadcrumbs breadcrumbs
  6126. 'txt txt
  6127. 'level level
  6128. 'time time
  6129. 'extra extra
  6130. 'format org-prefix-format-compiled
  6131. 'dotime dotime)))))
  6132. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6133. "Remove tags string from TXT, and add a modified list of tags.
  6134. The modified list may contain inherited tags, and tags matched by
  6135. `org-agenda-hide-tags-regexp' will be removed."
  6136. (when (or add-inherited hide-re)
  6137. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6138. (setq txt (substring txt 0 (match-beginning 0))))
  6139. (setq tags
  6140. (delq nil
  6141. (mapcar (lambda (tg)
  6142. (if (or (and hide-re (string-match hide-re tg))
  6143. (and (not add-inherited)
  6144. (get-text-property 0 'inherited tg)))
  6145. nil
  6146. tg))
  6147. tags)))
  6148. (when tags
  6149. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6150. i)
  6151. (setq txt (concat txt " :"
  6152. (mapconcat
  6153. (lambda (x)
  6154. (setq i (get-text-property 0 'inherited x))
  6155. (if (and have-i (not i))
  6156. (progn
  6157. (setq have-i nil)
  6158. (concat ":" x))
  6159. x))
  6160. tags ":")
  6161. (if have-i "::" ":"))))))
  6162. txt)
  6163. (defun org-downcase-keep-props (s)
  6164. (let ((props (text-properties-at 0 s)))
  6165. (setq s (downcase s))
  6166. (add-text-properties 0 (length s) props s)
  6167. s))
  6168. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6169. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6170. "Add a time-grid for agenda items which need it.
  6171. LIST is the list of agenda items formatted by `org-agenda-list'.
  6172. NDAYS is the span of the current agenda view.
  6173. TODAYP is `t' when the current agenda view is on today."
  6174. (catch 'exit
  6175. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6176. ((and todayp (member 'today (car org-agenda-time-grid))))
  6177. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6178. ((member 'weekly (car org-agenda-time-grid)))
  6179. (t (throw 'exit list)))
  6180. (let* ((have (delq nil (mapcar
  6181. (lambda (x) (get-text-property 1 'time-of-day x))
  6182. list)))
  6183. (string (nth 1 org-agenda-time-grid))
  6184. (gridtimes (nth 2 org-agenda-time-grid))
  6185. (req (car org-agenda-time-grid))
  6186. (remove (member 'remove-match req))
  6187. new time)
  6188. (if (and (member 'require-timed req) (not have))
  6189. ;; don't show empty grid
  6190. (throw 'exit list))
  6191. (while (setq time (pop gridtimes))
  6192. (unless (and remove (member time have))
  6193. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6194. (push (org-agenda-format-item
  6195. nil string nil "" nil
  6196. (concat (substring time 0 -2) ":" (substring time -2)))
  6197. new)
  6198. (put-text-property
  6199. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6200. (when (and todayp org-agenda-show-current-time-in-grid)
  6201. (push (org-agenda-format-item
  6202. nil org-agenda-current-time-string nil "" nil
  6203. (format-time-string "%H:%M "))
  6204. new)
  6205. (put-text-property
  6206. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6207. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6208. (append new list)
  6209. (append list new)))))
  6210. (defun org-compile-prefix-format (key)
  6211. "Compile the prefix format into a Lisp form that can be evaluated.
  6212. The resulting form and associated variable bindings is returned
  6213. and stored in the variable `org-prefix-format-compiled'."
  6214. (setq org-prefix-has-time nil
  6215. org-prefix-has-tag nil
  6216. org-prefix-category-length nil
  6217. org-prefix-has-effort nil
  6218. org-prefix-has-breadcrumbs nil)
  6219. (let ((s (cond
  6220. ((stringp org-agenda-prefix-format)
  6221. org-agenda-prefix-format)
  6222. ((assq key org-agenda-prefix-format)
  6223. (cdr (assq key org-agenda-prefix-format)))
  6224. (t " %-12:c%?-12t% s")))
  6225. (start 0)
  6226. varform vars var e c f opt)
  6227. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6228. s start)
  6229. (setq var (or (cdr (assoc (match-string 4 s)
  6230. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6231. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6232. 'eval)
  6233. c (or (match-string 3 s) "")
  6234. opt (match-beginning 1)
  6235. start (1+ (match-beginning 0)))
  6236. (if (equal var 'time) (setq org-prefix-has-time t))
  6237. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6238. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6239. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6240. (setq f (concat "%" (match-string 2 s) "s"))
  6241. (when (equal var 'category)
  6242. (setq org-prefix-category-length
  6243. (floor (abs (string-to-number (match-string 2 s)))))
  6244. (setq org-prefix-category-max-length
  6245. (let ((x (match-string 2 s)))
  6246. (save-match-data
  6247. (if (string-match "\\.[0-9]+" x)
  6248. (string-to-number (substring (match-string 0 x) 1)))))))
  6249. (if (eq var 'eval)
  6250. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6251. (if opt
  6252. (setq varform
  6253. `(if (equal "" ,var)
  6254. ""
  6255. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6256. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6257. (setq s (replace-match "%s" t nil s))
  6258. (push varform vars))
  6259. (setq vars (nreverse vars))
  6260. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6261. (setq org-prefix-format-compiled
  6262. (list
  6263. `((org-prefix-has-time ,org-prefix-has-time)
  6264. (org-prefix-has-tag ,org-prefix-has-tag)
  6265. (org-prefix-category-length ,org-prefix-category-length)
  6266. (org-prefix-has-effort ,org-prefix-has-effort)
  6267. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6268. `(format ,s ,@vars))))))
  6269. (defun org-set-sorting-strategy (key)
  6270. (if (symbolp (car org-agenda-sorting-strategy))
  6271. ;; the old format
  6272. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6273. (setq org-agenda-sorting-strategy-selected
  6274. (or (cdr (assq key org-agenda-sorting-strategy))
  6275. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6276. '(time-up category-keep priority-down)))))
  6277. (defun org-get-time-of-day (s &optional string mod24)
  6278. "Check string S for a time of day.
  6279. If found, return it as a military time number between 0 and 2400.
  6280. If not found, return nil.
  6281. The optional STRING argument forces conversion into a 5 character wide string
  6282. HH:MM."
  6283. (save-match-data
  6284. (when
  6285. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6286. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6287. (let* ((h (string-to-number (match-string 1 s)))
  6288. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6289. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6290. (am-p (equal ampm "am"))
  6291. (h1 (cond ((not ampm) h)
  6292. ((= h 12) (if am-p 0 12))
  6293. (t (+ h (if am-p 0 12)))))
  6294. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6295. (mod h1 24) h1))
  6296. (t0 (+ (* 100 h2) m))
  6297. (t1 (concat (if (>= h1 24) "+" " ")
  6298. (if (and org-agenda-time-leading-zero
  6299. (< t0 1000)) "0" "")
  6300. (if (< t0 100) "0" "")
  6301. (if (< t0 10) "0" "")
  6302. (int-to-string t0))))
  6303. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6304. (defvar org-agenda-before-sorting-filter-function nil
  6305. "Function to be applied to agenda items prior to sorting.
  6306. Prior to sorting also means just before they are inserted into the agenda.
  6307. To aid sorting, you may revisit the original entries and add more text
  6308. properties which will later be used by the sorting functions.
  6309. The function should take a string argument, an agenda line.
  6310. It has access to the text properties in that line, which contain among
  6311. other things, the property `org-hd-marker' that points to the entry
  6312. where the line comes from. Note that not all lines going into the agenda
  6313. have this property, only most.
  6314. The function should return the modified string. It is probably best
  6315. to ONLY change text properties.
  6316. You can also use this function as a filter, by returning nil for lines
  6317. you don't want to have in the agenda at all. For this application, you
  6318. could bind the variable in the options section of a custom command.")
  6319. (defun org-agenda-finalize-entries (list &optional type)
  6320. "Sort, limit and concatenate the LIST of agenda items.
  6321. The optional argument TYPE tells the agenda type."
  6322. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6323. (cdr (assoc type org-agenda-max-effort)))
  6324. (t org-agenda-max-effort)))
  6325. (max-todo (cond ((listp org-agenda-max-todos)
  6326. (cdr (assoc type org-agenda-max-todos)))
  6327. (t org-agenda-max-todos)))
  6328. (max-tags (cond ((listp org-agenda-max-tags)
  6329. (cdr (assoc type org-agenda-max-tags)))
  6330. (t org-agenda-max-tags)))
  6331. (max-entries (cond ((listp org-agenda-max-entries)
  6332. (cdr (assoc type org-agenda-max-entries)))
  6333. (t org-agenda-max-entries))) l)
  6334. (when org-agenda-before-sorting-filter-function
  6335. (setq list
  6336. (delq nil
  6337. (mapcar
  6338. org-agenda-before-sorting-filter-function list))))
  6339. (setq list (mapcar 'org-agenda-highlight-todo list)
  6340. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6341. (when max-effort
  6342. (setq list (org-agenda-limit-entries
  6343. list 'effort-minutes max-effort 'identity)))
  6344. (when max-todo
  6345. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6346. (when max-tags
  6347. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6348. (when max-entries
  6349. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6350. (mapconcat 'identity list "\n")))
  6351. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6352. "Limit the number of agenda entries."
  6353. (let ((include (and limit (< limit 0))))
  6354. (if limit
  6355. (let ((fun (or fn (lambda (p) (if p 1))))
  6356. (lim 0))
  6357. (delq nil
  6358. (mapcar
  6359. (lambda (e)
  6360. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6361. (if pval (setq lim (+ lim pval)))
  6362. (cond ((and pval (<= lim (abs limit))) e)
  6363. ((and include (not pval)) e))))
  6364. list)))
  6365. list)))
  6366. (defun org-agenda-limit-interactively ()
  6367. "In agenda, interactively limit entries to various maximums."
  6368. (interactive)
  6369. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6370. (num (string-to-number (read-from-minibuffer "How many? "))))
  6371. (cond ((equal max ?e)
  6372. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6373. ((equal max ?t)
  6374. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6375. ((equal max ?T)
  6376. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6377. ((equal max ?E)
  6378. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6379. (org-agenda-fit-window-to-buffer))
  6380. (defun org-agenda-highlight-todo (x)
  6381. (let ((org-done-keywords org-done-keywords-for-agenda)
  6382. (case-fold-search nil)
  6383. re)
  6384. (if (eq x 'line)
  6385. (save-excursion
  6386. (beginning-of-line 1)
  6387. (setq re (org-get-at-bol 'org-todo-regexp))
  6388. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6389. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6390. (add-text-properties (match-beginning 0) (match-end 1)
  6391. (list 'face (org-get-todo-face 1)))
  6392. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6393. (delete-region (match-beginning 1) (1- (match-end 0)))
  6394. (goto-char (match-beginning 1))
  6395. (insert (format org-agenda-todo-keyword-format s)))))
  6396. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6397. (setq re (get-text-property 0 'org-todo-regexp x))
  6398. (when (and re
  6399. ;; Test `pl' because if there's no heading content,
  6400. ;; there's no point matching to highlight. Note
  6401. ;; that if we didn't test `pl' first, and there
  6402. ;; happened to be no keyword from `org-todo-regexp'
  6403. ;; on this heading line, then the `equal' comparison
  6404. ;; afterwards would spuriously succeed in the case
  6405. ;; where `pl' is nil -- causing an args-out-of-range
  6406. ;; error when we try to add text properties to text
  6407. ;; that isn't there.
  6408. pl
  6409. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6410. x pl) pl))
  6411. (add-text-properties
  6412. (or (match-end 1) (match-end 0)) (match-end 0)
  6413. (list 'face (org-get-todo-face (match-string 2 x)))
  6414. x)
  6415. (when (match-end 1)
  6416. (setq x (concat (substring x 0 (match-end 1))
  6417. (format org-agenda-todo-keyword-format
  6418. (match-string 2 x))
  6419. (org-add-props " " (text-properties-at 0 x))
  6420. (substring x (match-end 3)))))))
  6421. x)))
  6422. (defsubst org-cmp-priority (a b)
  6423. "Compare the priorities of string A and B."
  6424. (let ((pa (or (get-text-property 1 'priority a) 0))
  6425. (pb (or (get-text-property 1 'priority b) 0)))
  6426. (cond ((> pa pb) +1)
  6427. ((< pa pb) -1))))
  6428. (defsubst org-cmp-effort (a b)
  6429. "Compare the effort values of string A and B."
  6430. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6431. (ea (or (get-text-property 1 'effort-minutes a) def))
  6432. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6433. (cond ((> ea eb) +1)
  6434. ((< ea eb) -1))))
  6435. (defsubst org-cmp-category (a b)
  6436. "Compare the string values of categories of strings A and B."
  6437. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6438. (cb (or (get-text-property 1 'org-category b) "")))
  6439. (cond ((string-lessp ca cb) -1)
  6440. ((string-lessp cb ca) +1))))
  6441. (defsubst org-cmp-todo-state (a b)
  6442. "Compare the todo states of strings A and B."
  6443. (let* ((ma (or (get-text-property 1 'org-marker a)
  6444. (get-text-property 1 'org-hd-marker a)))
  6445. (mb (or (get-text-property 1 'org-marker b)
  6446. (get-text-property 1 'org-hd-marker b)))
  6447. (fa (and ma (marker-buffer ma)))
  6448. (fb (and mb (marker-buffer mb)))
  6449. (todo-kwds
  6450. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6451. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6452. (ta (or (get-text-property 1 'todo-state a) ""))
  6453. (tb (or (get-text-property 1 'todo-state b) ""))
  6454. (la (- (length (member ta todo-kwds))))
  6455. (lb (- (length (member tb todo-kwds))))
  6456. (donepa (member ta org-done-keywords-for-agenda))
  6457. (donepb (member tb org-done-keywords-for-agenda)))
  6458. (cond ((and donepa (not donepb)) -1)
  6459. ((and (not donepa) donepb) +1)
  6460. ((< la lb) -1)
  6461. ((< lb la) +1))))
  6462. (defsubst org-cmp-alpha (a b)
  6463. "Compare the headlines, alphabetically."
  6464. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6465. (plb (text-property-any 0 (length b) 'org-heading t b))
  6466. (ta (and pla (substring a pla)))
  6467. (tb (and plb (substring b plb))))
  6468. (when pla
  6469. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6470. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6471. (setq ta (substring ta (match-end 0))))
  6472. (setq ta (downcase ta)))
  6473. (when plb
  6474. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6475. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6476. (setq tb (substring tb (match-end 0))))
  6477. (setq tb (downcase tb)))
  6478. (cond ((not ta) +1)
  6479. ((not tb) -1)
  6480. ((string-lessp ta tb) -1)
  6481. ((string-lessp tb ta) +1))))
  6482. (defsubst org-cmp-tag (a b)
  6483. "Compare the string values of the first tags of A and B."
  6484. (let ((ta (car (last (get-text-property 1 'tags a))))
  6485. (tb (car (last (get-text-property 1 'tags b)))))
  6486. (cond ((not ta) +1)
  6487. ((not tb) -1)
  6488. ((string-lessp ta tb) -1)
  6489. ((string-lessp tb ta) +1))))
  6490. (defsubst org-cmp-time (a b)
  6491. "Compare the time-of-day values of strings A and B."
  6492. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6493. (ta (or (get-text-property 1 'time-of-day a) def))
  6494. (tb (or (get-text-property 1 'time-of-day b) def)))
  6495. (cond ((< ta tb) -1)
  6496. ((< tb ta) +1))))
  6497. (defsubst org-cmp-ts (a b &optional type)
  6498. "Compare the timestamps values of entries A and B.
  6499. When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
  6500. or \"timestamp_ia\", compare within each of these type.
  6501. When TYPE is the empty string, compare all timestamps
  6502. without respect of their type."
  6503. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6504. (ta (or (and (string-match type (get-text-property 1 'type a))
  6505. (get-text-property 1 'ts-date a)) def))
  6506. (tb (or (and (string-match type (get-text-property 1 'type b))
  6507. (get-text-property 1 'ts-date b)) def)))
  6508. (cond ((< ta tb) -1)
  6509. ((< tb ta) +1))))
  6510. (defsubst org-cmp-habit-p (a b)
  6511. "Compare the todo states of strings A and B."
  6512. (let ((ha (get-text-property 1 'org-habit-p a))
  6513. (hb (get-text-property 1 'org-habit-p b)))
  6514. (cond ((and ha (not hb)) -1)
  6515. ((and (not ha) hb) +1))))
  6516. (defun org-entries-lessp (a b)
  6517. "Predicate for sorting agenda entries."
  6518. ;; The following variables will be used when the form is evaluated.
  6519. ;; So even though the compiler complains, keep them.
  6520. (let* ((ss org-agenda-sorting-strategy-selected)
  6521. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6522. (org-cmp-ts a b "")))
  6523. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6524. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6525. (org-cmp-ts a b "scheduled")))
  6526. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6527. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6528. (org-cmp-ts a b "deadline")))
  6529. (deadline-down (if deadline-up (- deadline-up) nil))
  6530. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6531. (org-cmp-ts a b "iatimestamp_ia")))
  6532. (tsia-down (if tsia-up (- tsia-up) nil))
  6533. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6534. (org-cmp-ts a b "timestamp")))
  6535. (ts-down (if ts-up (- ts-up) nil))
  6536. (time-up (and (org-em 'time-up 'time-down ss)
  6537. (org-cmp-time a b)))
  6538. (time-down (if time-up (- time-up) nil))
  6539. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6540. (org-cmp-priority a b)))
  6541. (priority-down (if priority-up (- priority-up) nil))
  6542. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6543. (org-cmp-effort a b)))
  6544. (effort-down (if effort-up (- effort-up) nil))
  6545. (category-up (and (or (org-em 'category-up 'category-down ss)
  6546. (memq 'category-keep ss))
  6547. (org-cmp-category a b)))
  6548. (category-down (if category-up (- category-up) nil))
  6549. (category-keep (if category-up +1 nil))
  6550. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6551. (org-cmp-tag a b)))
  6552. (tag-down (if tag-up (- tag-up) nil))
  6553. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6554. (org-cmp-todo-state a b)))
  6555. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6556. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6557. (org-cmp-habit-p a b)))
  6558. (habit-down (if habit-up (- habit-up) nil))
  6559. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6560. (org-cmp-alpha a b)))
  6561. (alpha-down (if alpha-up (- alpha-up) nil))
  6562. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6563. user-defined-up user-defined-down)
  6564. (if (and need-user-cmp org-agenda-cmp-user-defined
  6565. (functionp org-agenda-cmp-user-defined))
  6566. (setq user-defined-up
  6567. (funcall org-agenda-cmp-user-defined a b)
  6568. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6569. (cdr (assoc
  6570. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6571. '((-1 . t) (1 . nil) (nil . nil))))))
  6572. ;;; Agenda restriction lock
  6573. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6574. "Overlay to mark the headline to which agenda commands are restricted.")
  6575. (overlay-put org-agenda-restriction-lock-overlay
  6576. 'face 'org-agenda-restriction-lock)
  6577. (overlay-put org-agenda-restriction-lock-overlay
  6578. 'help-echo "Agendas are currently limited to this subtree.")
  6579. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6580. (defun org-agenda-set-restriction-lock (&optional type)
  6581. "Set restriction lock for agenda, to current subtree or file.
  6582. Restriction will be the file if TYPE is `file', or if type is the
  6583. universal prefix '(4), or if the cursor is before the first headline
  6584. in the file. Otherwise, restriction will be to the current subtree."
  6585. (interactive "P")
  6586. (and (equal type '(4)) (setq type 'file))
  6587. (setq type (cond
  6588. (type type)
  6589. ((org-at-heading-p) 'subtree)
  6590. ((condition-case nil (org-back-to-heading t) (error nil))
  6591. 'subtree)
  6592. (t 'file)))
  6593. (if (eq type 'subtree)
  6594. (progn
  6595. (setq org-agenda-restrict t)
  6596. (setq org-agenda-overriding-restriction 'subtree)
  6597. (put 'org-agenda-files 'org-restrict
  6598. (list (buffer-file-name (buffer-base-buffer))))
  6599. (org-back-to-heading t)
  6600. (move-overlay org-agenda-restriction-lock-overlay
  6601. (point)
  6602. (if org-agenda-restriction-lock-highlight-subtree
  6603. (save-excursion (org-end-of-subtree t t) (point))
  6604. (point-at-eol)))
  6605. (move-marker org-agenda-restrict-begin (point))
  6606. (move-marker org-agenda-restrict-end
  6607. (save-excursion (org-end-of-subtree t t)))
  6608. (message "Locking agenda restriction to subtree"))
  6609. (put 'org-agenda-files 'org-restrict
  6610. (list (buffer-file-name (buffer-base-buffer))))
  6611. (setq org-agenda-restrict nil)
  6612. (setq org-agenda-overriding-restriction 'file)
  6613. (move-marker org-agenda-restrict-begin nil)
  6614. (move-marker org-agenda-restrict-end nil)
  6615. (message "Locking agenda restriction to file"))
  6616. (setq current-prefix-arg nil)
  6617. (org-agenda-maybe-redo))
  6618. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6619. "Remove the agenda restriction lock."
  6620. (interactive "P")
  6621. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6622. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6623. (setq org-agenda-overriding-restriction nil)
  6624. (setq org-agenda-restrict nil)
  6625. (put 'org-agenda-files 'org-restrict nil)
  6626. (move-marker org-agenda-restrict-begin nil)
  6627. (move-marker org-agenda-restrict-end nil)
  6628. (setq current-prefix-arg nil)
  6629. (message "Agenda restriction lock removed")
  6630. (or noupdate (org-agenda-maybe-redo)))
  6631. (defun org-agenda-maybe-redo ()
  6632. "If there is any window showing the agenda view, update it."
  6633. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6634. (w0 (selected-window)))
  6635. (when w
  6636. (select-window w)
  6637. (org-agenda-redo)
  6638. (select-window w0)
  6639. (if org-agenda-overriding-restriction
  6640. (message "Agenda view shifted to new %s restriction"
  6641. org-agenda-overriding-restriction)
  6642. (message "Agenda restriction lock removed")))))
  6643. ;;; Agenda commands
  6644. (defun org-agenda-check-type (error &rest types)
  6645. "Check if agenda buffer is of allowed type.
  6646. If ERROR is non-nil, throw an error, otherwise just return nil.
  6647. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6648. (if (not org-agenda-type)
  6649. (error "No Org agenda currently displayed")
  6650. (if (memq org-agenda-type types)
  6651. t
  6652. (if error
  6653. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6654. nil))))
  6655. (defun org-agenda-Quit ()
  6656. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6657. Also restore the window configuration."
  6658. (interactive)
  6659. (if org-agenda-columns-active
  6660. (org-columns-quit)
  6661. (let ((buf (current-buffer)))
  6662. (if (eq org-agenda-window-setup 'other-frame)
  6663. (progn
  6664. (org-agenda-reset-markers)
  6665. (kill-buffer buf)
  6666. (org-columns-remove-overlays)
  6667. (setq org-agenda-archives-mode nil)
  6668. (delete-frame))
  6669. (and (not (eq org-agenda-window-setup 'current-window))
  6670. (not (one-window-p))
  6671. (delete-window))
  6672. (org-agenda-reset-markers)
  6673. (kill-buffer buf)
  6674. (org-columns-remove-overlays)
  6675. (setq org-agenda-archives-mode nil)))
  6676. (setq org-agenda-buffer nil)
  6677. ;; Maybe restore the pre-agenda window configuration.
  6678. (and org-agenda-restore-windows-after-quit
  6679. (not (eq org-agenda-window-setup 'other-frame))
  6680. org-agenda-pre-window-conf
  6681. (set-window-configuration org-agenda-pre-window-conf)
  6682. (setq org-agenda-pre-window-conf nil))))
  6683. (defun org-agenda-quit ()
  6684. "Exit the agenda and restore the window configuration.
  6685. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6686. (interactive)
  6687. (if (and (eq org-indirect-buffer-display 'other-window)
  6688. org-last-indirect-buffer)
  6689. (let ((org-last-indirect-window
  6690. (get-buffer-window org-last-indirect-buffer)))
  6691. (if org-last-indirect-window
  6692. (delete-window org-last-indirect-window))))
  6693. (if org-agenda-columns-active
  6694. (org-columns-quit)
  6695. (if org-agenda-sticky
  6696. (let ((buf (current-buffer)))
  6697. (if (eq org-agenda-window-setup 'other-frame)
  6698. (progn
  6699. (delete-frame))
  6700. (and (not (eq org-agenda-window-setup 'current-window))
  6701. (not (one-window-p))
  6702. (delete-window)))
  6703. (with-current-buffer buf
  6704. (bury-buffer)
  6705. ;; Maybe restore the pre-agenda window configuration.
  6706. (and org-agenda-restore-windows-after-quit
  6707. (not (eq org-agenda-window-setup 'other-frame))
  6708. org-agenda-pre-window-conf
  6709. (set-window-configuration org-agenda-pre-window-conf)
  6710. (setq org-agenda-pre-window-conf nil))))
  6711. (org-agenda-Quit))))
  6712. (defun org-agenda-exit ()
  6713. "Exit the agenda and restore the window configuration.
  6714. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6715. buffers visited directly by the user will not be touched."
  6716. (interactive)
  6717. (org-release-buffers org-agenda-new-buffers)
  6718. (setq org-agenda-new-buffers nil)
  6719. (org-agenda-Quit))
  6720. (defun org-agenda-kill-all-agenda-buffers ()
  6721. "Kill all buffers in `org-agenda-mode'.
  6722. This is used when toggling sticky agendas.
  6723. You can also explicitly invoke it with `C-c a C-k'."
  6724. (interactive)
  6725. (let (blist)
  6726. (dolist (buf (buffer-list))
  6727. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6728. (push buf blist)))
  6729. (mapc 'kill-buffer blist)))
  6730. (defun org-agenda-execute (arg)
  6731. "Execute another agenda command, keeping same window.
  6732. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6733. in the agenda."
  6734. (interactive "P")
  6735. (let ((org-agenda-window-setup 'current-window))
  6736. (org-agenda arg)))
  6737. (defun org-agenda-redo (&optional all)
  6738. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6739. (interactive "P")
  6740. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6741. (cpa (unless (eq all t) current-prefix-arg))
  6742. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6743. (org-agenda-sticky nil)
  6744. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6745. org-agenda-buffer-name))
  6746. (org-agenda-keep-modes t)
  6747. (tag-filter org-agenda-tag-filter)
  6748. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6749. (top-hl-filter org-agenda-top-headline-filter)
  6750. (cat-filter org-agenda-category-filter)
  6751. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6752. (re-filter org-agenda-regexp-filter)
  6753. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6754. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6755. (cols org-agenda-columns-active)
  6756. (line (org-current-line))
  6757. (window-line (- line (org-current-line (window-start))))
  6758. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6759. (redo-cmd (get-text-property p 'org-redo-cmd))
  6760. (last-args (get-text-property p 'org-last-args))
  6761. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6762. (org-agenda-overriding-cmd-arguments
  6763. (unless (eq all t)
  6764. (cond ((listp last-args)
  6765. (cons (or cpa (car last-args)) (cdr last-args)))
  6766. ((stringp last-args)
  6767. last-args))))
  6768. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6769. (put 'org-agenda-tag-filter :preset-filter nil)
  6770. (put 'org-agenda-category-filter :preset-filter nil)
  6771. (put 'org-agenda-regexp-filter :preset-filter nil)
  6772. (and cols (org-columns-quit))
  6773. (message "Rebuilding agenda buffer...")
  6774. (if series-redo-cmd
  6775. (eval series-redo-cmd)
  6776. (org-let lprops redo-cmd))
  6777. (setq org-agenda-undo-list nil
  6778. org-agenda-pending-undo-list nil
  6779. org-agenda-tag-filter tag-filter
  6780. org-agenda-category-filter cat-filter
  6781. org-agenda-regexp-filter re-filter
  6782. org-agenda-top-headline-filter top-hl-filter)
  6783. (message "Rebuilding agenda buffer...done")
  6784. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6785. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6786. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6787. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6788. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6789. (and (or re-filter re-preset) (org-agenda-filter-apply re-filter 'regexp))
  6790. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6791. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6792. (org-goto-line line)
  6793. (recenter window-line)))
  6794. (defvar org-global-tags-completion-table nil)
  6795. (defvar org-agenda-filter-form nil)
  6796. (defvar org-agenda-filtered-by-category nil)
  6797. (defun org-agenda-filter-by-category (strip)
  6798. "Keep only those lines in the agenda buffer that have a specific category.
  6799. The category is that of the current line."
  6800. (interactive "P")
  6801. (if (and org-agenda-filtered-by-category
  6802. org-agenda-category-filter)
  6803. (org-agenda-filter-show-all-cat)
  6804. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6805. (if (and cat (not (string= "" cat)))
  6806. (org-agenda-filter-apply
  6807. (setq org-agenda-category-filter
  6808. (list (concat (if strip "-" "+") cat)))
  6809. 'category)
  6810. (error "No category at point")))))
  6811. (defun org-find-top-headline (&optional pos)
  6812. "Find the topmost parent headline and return it."
  6813. (save-excursion
  6814. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6815. (if pos (goto-char pos))
  6816. ;; Skip up to the topmost parent
  6817. (while (ignore-errors (outline-up-heading 1) t))
  6818. (ignore-errors
  6819. (nth 4 (org-heading-components))))))
  6820. (defvar org-agenda-filtered-by-top-headline nil)
  6821. (defun org-agenda-filter-by-top-headline (strip)
  6822. "Keep only those lines that are descendants from the same top headline.
  6823. The top headline is that of the current line."
  6824. (interactive "P")
  6825. (if org-agenda-filtered-by-top-headline
  6826. (progn
  6827. (setq org-agenda-filtered-by-top-headline nil
  6828. org-agenda-top-headline-filter nil)
  6829. (org-agenda-filter-show-all-cat))
  6830. (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6831. (if cat (org-agenda-filter-top-headline-apply cat strip)
  6832. (error "No top-level category at point")))))
  6833. (defvar org-agenda-regexp-filter nil)
  6834. (defun org-agenda-filter-by-regexp (strip)
  6835. "Filter agenda entries by a regular expression.
  6836. Regexp filters are cumulative.
  6837. With no prefix argument, keep entries matching the regexp.
  6838. With one prefix argument, filter out entries matching the regexp.
  6839. With two prefix arguments, remove the regexp filters."
  6840. (interactive "P")
  6841. (if (not (equal strip '(16)))
  6842. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6843. (read-from-minibuffer
  6844. (if (equal strip '(4))
  6845. "Filter out entries matching regexp: "
  6846. "Narrow to entries matching regexp: ")))))
  6847. (push flt org-agenda-regexp-filter)
  6848. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6849. (org-agenda-filter-show-all-re)
  6850. (message "Regexp filter removed")))
  6851. (defun org-agenda-filter-remove-all ()
  6852. "Remove all filters from the current agenda buffer."
  6853. (interactive)
  6854. (when org-agenda-tag-filter
  6855. (org-agenda-filter-show-all-tag))
  6856. (when org-agenda-category-filter
  6857. (org-agenda-filter-show-all-cat))
  6858. (when org-agenda-regexp-filter
  6859. (org-agenda-filter-show-all-re)))
  6860. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6861. "Keep only those lines in the agenda buffer that have a specific tag.
  6862. The tag is selected with its fast selection letter, as configured.
  6863. With prefix argument STRIP, remove all lines that do have the tag.
  6864. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6865. used to narrow the search - the interactive user can also press `-' or `+'
  6866. to switch to narrowing."
  6867. (interactive "P")
  6868. (let* ((alist org-tag-alist-for-agenda)
  6869. (tag-chars (mapconcat
  6870. (lambda (x) (if (and (not (symbolp (car x)))
  6871. (cdr x))
  6872. (char-to-string (cdr x))
  6873. ""))
  6874. alist ""))
  6875. (efforts (org-split-string
  6876. (or (cdr (assoc (concat org-effort-property "_ALL")
  6877. org-global-properties))
  6878. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6879. "")))
  6880. (effort-op org-agenda-filter-effort-default-operator)
  6881. (effort-prompt "")
  6882. (inhibit-read-only t)
  6883. (current org-agenda-tag-filter)
  6884. maybe-refresh a n tag)
  6885. (unless char
  6886. (message
  6887. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6888. (if narrow "Narrow" "Filter") tag-chars
  6889. (if org-agenda-auto-exclude-function "[RET], " ""))
  6890. (setq char (read-char-exclusive)))
  6891. (when (member char '(?+ ?-))
  6892. ;; Narrowing down
  6893. (cond ((equal char ?-) (setq strip t narrow t))
  6894. ((equal char ?+) (setq strip nil narrow t)))
  6895. (message
  6896. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6897. (setq char (read-char-exclusive)))
  6898. (when (member char '(?< ?> ?= ??))
  6899. ;; An effort operator
  6900. (setq effort-op (char-to-string char))
  6901. (setq alist nil) ; to make sure it will be interpreted as effort.
  6902. (unless (equal char ??)
  6903. (loop for i from 0 to 9 do
  6904. (setq effort-prompt
  6905. (concat
  6906. effort-prompt " ["
  6907. (if (= i 9) "0" (int-to-string (1+ i)))
  6908. "]" (nth i efforts))))
  6909. (message "Effort%s: %s " effort-op effort-prompt)
  6910. (setq char (read-char-exclusive))
  6911. (when (or (< char ?0) (> char ?9))
  6912. (error "Need 1-9,0 to select effort"))))
  6913. (when (equal char ?\t)
  6914. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6915. (org-set-local 'org-global-tags-completion-table
  6916. (org-global-tags-completion-table)))
  6917. (let ((completion-ignore-case t))
  6918. (setq tag (org-icompleting-read
  6919. "Tag: " org-global-tags-completion-table))))
  6920. (cond
  6921. ((equal char ?\r)
  6922. (org-agenda-filter-show-all-tag)
  6923. (when org-agenda-auto-exclude-function
  6924. (setq org-agenda-tag-filter nil)
  6925. (dolist (tag (org-agenda-get-represented-tags))
  6926. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6927. (if modifier
  6928. (push modifier org-agenda-tag-filter))))
  6929. (if (not (null org-agenda-tag-filter))
  6930. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6931. (setq maybe-refresh t))
  6932. ((equal char ?/)
  6933. (org-agenda-filter-show-all-tag)
  6934. (when (get 'org-agenda-tag-filter :preset-filter)
  6935. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6936. (setq maybe-refresh t))
  6937. ((equal char ?. )
  6938. (setq org-agenda-tag-filter
  6939. (mapcar (lambda(tag) (concat "+" tag))
  6940. (org-get-at-bol 'tags)))
  6941. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6942. (setq maybe-refresh t))
  6943. ((or (equal char ?\ )
  6944. (setq a (rassoc char alist))
  6945. (and (>= char ?0) (<= char ?9)
  6946. (setq n (if (= char ?0) 9 (- char ?0 1))
  6947. tag (concat effort-op (nth n efforts))
  6948. a (cons tag nil)))
  6949. (and (= char ??)
  6950. (setq tag "?eff")
  6951. a (cons tag nil))
  6952. (and tag (setq a (cons tag nil))))
  6953. (org-agenda-filter-show-all-tag)
  6954. (setq tag (car a))
  6955. (setq org-agenda-tag-filter
  6956. (cons (concat (if strip "-" "+") tag)
  6957. (if narrow current nil)))
  6958. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6959. (setq maybe-refresh t))
  6960. (t (error "Invalid tag selection character %c" char)))
  6961. (when (and maybe-refresh
  6962. (eq org-agenda-clockreport-mode 'with-filter))
  6963. (org-agenda-redo))))
  6964. (defun org-agenda-get-represented-tags ()
  6965. "Get a list of all tags currently represented in the agenda."
  6966. (let (p tags)
  6967. (save-excursion
  6968. (goto-char (point-min))
  6969. (while (setq p (next-single-property-change (point) 'tags))
  6970. (goto-char p)
  6971. (mapc (lambda (x) (add-to-list 'tags x))
  6972. (get-text-property (point) 'tags))))
  6973. tags))
  6974. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6975. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6976. (interactive "P")
  6977. (org-agenda-filter-by-tag strip char 'refine))
  6978. (defun org-agenda-filter-make-matcher (filter type)
  6979. "Create the form that tests a line for agenda filter."
  6980. (let (f f1)
  6981. (cond
  6982. ;; Tag filter
  6983. ((eq type 'tag)
  6984. (setq filter
  6985. (delete-dups
  6986. (append (get 'org-agenda-tag-filter :preset-filter)
  6987. filter)))
  6988. (dolist (x filter)
  6989. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  6990. (ffunc
  6991. (lambda (nf0 nf01 fltr notgroup op)
  6992. (dolist (x fltr)
  6993. (if (member x '("-" "+"))
  6994. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  6995. (if (string-match "[<=>?]" x)
  6996. (setq nf01 (org-agenda-filter-effort-form x))
  6997. (setq nf01 (list 'member (downcase (substring x 1))
  6998. 'tags)))
  6999. (when (equal (string-to-char x) ?-)
  7000. (setq nf01 (list 'not nf01))
  7001. (when (not notgroup) (setq op 'and))))
  7002. (push nf01 nf0))
  7003. (if notgroup
  7004. (push (cons 'and nf0) f)
  7005. (push (cons (or op 'or) nf0) f)))))
  7006. (if (equal nfilter filter)
  7007. (funcall ffunc f1 f filter t nil)
  7008. (funcall ffunc nf1 nf nfilter nil nil)))))
  7009. ;; Category filter
  7010. ((eq type 'category)
  7011. (setq filter
  7012. (delete-dups
  7013. (append (get 'org-agenda-category-filter :preset-filter)
  7014. filter)))
  7015. (dolist (x filter)
  7016. (if (equal "-" (substring x 0 1))
  7017. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7018. (setq f1 (list 'equal (substring x 1) 'cat)))
  7019. (push f1 f)))
  7020. ;; Regexp filter
  7021. ((eq type 'regexp)
  7022. (setq filter
  7023. (delete-dups
  7024. (append (get 'org-agenda-regexp-filter :preset-filter)
  7025. filter)))
  7026. (dolist (x filter)
  7027. (if (equal "-" (substring x 0 1))
  7028. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7029. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7030. (push f1 f))))
  7031. (cons 'and (nreverse f))))
  7032. (defun org-agenda-filter-effort-form (e)
  7033. "Return the form to compare the effort of the current line with what E says.
  7034. E looks like \"+<2:25\"."
  7035. (let (op)
  7036. (setq e (substring e 1))
  7037. (setq op (string-to-char e) e (substring e 1))
  7038. (setq op (cond ((equal op ?<) '<=)
  7039. ((equal op ?>) '>=)
  7040. ((equal op ??) op)
  7041. (t '=)))
  7042. (list 'org-agenda-compare-effort (list 'quote op)
  7043. (org-duration-string-to-minutes e))))
  7044. (defun org-agenda-compare-effort (op value)
  7045. "Compare the effort of the current line with VALUE, using OP.
  7046. If the line does not have an effort defined, return nil."
  7047. (let ((eff (org-get-at-bol 'effort-minutes)))
  7048. (if (equal op ??)
  7049. (not eff)
  7050. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7051. value))))
  7052. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7053. "Expand group tags in FILTER for the agenda.
  7054. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7055. (if org-group-tags
  7056. (let ((case-fold-search t) rtn)
  7057. (mapc
  7058. (lambda (f)
  7059. (let (f0 dir)
  7060. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7061. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7062. (setq dir (if no-operator "" "+") f0 f))
  7063. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7064. (org-tags-expand f0 t t))
  7065. rtn))))
  7066. filter)
  7067. (reverse rtn))
  7068. filter))
  7069. (defun org-agenda-filter-apply (filter type)
  7070. "Set FILTER as the new agenda filter and apply it."
  7071. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7072. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7073. (let (tags cat txt)
  7074. (setq org-agenda-filter-form
  7075. (org-agenda-filter-make-matcher filter type))
  7076. (if (and (eq type 'category)
  7077. (not (equal (substring (car filter) 0 1) "-")))
  7078. ;; Only set `org-agenda-filtered-by-category' to t
  7079. ;; when a unique category is used as the filter
  7080. (setq org-agenda-filtered-by-category t))
  7081. (org-agenda-set-mode-name)
  7082. (save-excursion
  7083. (goto-char (point-min))
  7084. (while (not (eobp))
  7085. (if (org-get-at-bol 'org-marker)
  7086. (progn
  7087. (setq tags ; used in eval
  7088. (apply 'append
  7089. (mapcar (lambda (f)
  7090. (org-agenda-filter-expand-tags (list f) t))
  7091. (org-get-at-bol 'tags)))
  7092. cat (get-text-property (point) 'org-category)
  7093. txt (get-text-property (point) 'txt))
  7094. (if (not (eval org-agenda-filter-form))
  7095. (org-agenda-filter-hide-line type))
  7096. (beginning-of-line 2))
  7097. (beginning-of-line 2))))
  7098. (if (get-char-property (point) 'invisible)
  7099. (ignore-errors (org-agenda-previous-line)))))
  7100. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7101. "Filter by top headline HL."
  7102. (org-agenda-set-mode-name)
  7103. (save-excursion
  7104. (goto-char (point-min))
  7105. (while (not (eobp))
  7106. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7107. (tophl (and pos (org-find-top-headline pos))))
  7108. (if (and tophl (funcall (if negative 'identity 'not)
  7109. (string= hl tophl)))
  7110. (org-agenda-filter-hide-line 'category)))
  7111. (beginning-of-line 2)))
  7112. (if (get-char-property (point) 'invisible)
  7113. (org-agenda-previous-line))
  7114. (setq org-agenda-top-headline-filter hl
  7115. org-agenda-filtered-by-top-headline t))
  7116. (defun org-agenda-filter-hide-line (type)
  7117. "Hide lines with TYPE in the agenda buffer."
  7118. (let (ov)
  7119. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  7120. (point-at-eol)))
  7121. (overlay-put ov 'invisible t)
  7122. (overlay-put ov 'type type)
  7123. (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays))
  7124. ((eq type 'category) (push ov org-agenda-cat-filter-overlays))
  7125. ((eq type 'regexp) (push ov org-agenda-re-filter-overlays)))))
  7126. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  7127. (setq pos (or pos (point)))
  7128. (save-excursion
  7129. (dolist (ov (overlays-at pos))
  7130. (when (and (overlay-get ov 'invisible)
  7131. (eq (overlay-get ov 'type) 'tag))
  7132. (goto-char pos)
  7133. (if (< (overlay-start ov) (point-at-eol))
  7134. (move-overlay ov (point-at-eol)
  7135. (overlay-end ov)))))))
  7136. (defun org-agenda-filter-show-all-tag nil
  7137. "Remove tag filter overlays from the agenda buffer."
  7138. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  7139. (setq org-agenda-tag-filter-overlays nil
  7140. org-agenda-tag-filter nil
  7141. org-agenda-filter-form nil)
  7142. (org-agenda-set-mode-name))
  7143. (defun org-agenda-filter-show-all-re nil
  7144. "Remove regexp filter overlays from the agenda buffer."
  7145. (mapc 'delete-overlay org-agenda-re-filter-overlays)
  7146. (setq org-agenda-re-filter-overlays nil
  7147. org-agenda-regexp-filter nil
  7148. org-agenda-filter-form nil)
  7149. (org-agenda-set-mode-name))
  7150. (defun org-agenda-filter-show-all-cat nil
  7151. "Remove category filter overlays from the agenda buffer."
  7152. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  7153. (setq org-agenda-cat-filter-overlays nil
  7154. org-agenda-filtered-by-category nil
  7155. org-agenda-category-filter nil
  7156. org-agenda-filter-form nil)
  7157. (org-agenda-set-mode-name))
  7158. (defun org-agenda-manipulate-query-add ()
  7159. "Manipulate the query by adding a search term with positive selection.
  7160. Positive selection means the term must be matched for selection of an entry."
  7161. (interactive)
  7162. (org-agenda-manipulate-query ?\[))
  7163. (defun org-agenda-manipulate-query-subtract ()
  7164. "Manipulate the query by adding a search term with negative selection.
  7165. Negative selection means term must not be matched for selection of an entry."
  7166. (interactive)
  7167. (org-agenda-manipulate-query ?\]))
  7168. (defun org-agenda-manipulate-query-add-re ()
  7169. "Manipulate the query by adding a search regexp with positive selection.
  7170. Positive selection means the regexp must match for selection of an entry."
  7171. (interactive)
  7172. (org-agenda-manipulate-query ?\{))
  7173. (defun org-agenda-manipulate-query-subtract-re ()
  7174. "Manipulate the query by adding a search regexp with negative selection.
  7175. Negative selection means regexp must not match for selection of an entry."
  7176. (interactive)
  7177. (org-agenda-manipulate-query ?\}))
  7178. (defun org-agenda-manipulate-query (char)
  7179. (cond
  7180. ((memq org-agenda-type '(timeline agenda))
  7181. (let ((org-agenda-include-inactive-timestamps t))
  7182. (org-agenda-redo))
  7183. (message "Display now includes inactive timestamps as well"))
  7184. ((eq org-agenda-type 'search)
  7185. (org-add-to-string
  7186. 'org-agenda-query-string
  7187. (if org-agenda-last-search-view-search-was-boolean
  7188. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7189. (?\{ . " +{}") (?\} . " -{}"))))
  7190. " "))
  7191. (setq org-agenda-redo-command
  7192. (list 'org-search-view
  7193. (car (get-text-property (min (1- (point-max)) (point))
  7194. 'org-last-args))
  7195. org-agenda-query-string
  7196. (+ (length org-agenda-query-string)
  7197. (if (member char '(?\{ ?\})) 0 1))))
  7198. (set-register org-agenda-query-register org-agenda-query-string)
  7199. (let ((org-agenda-overriding-arguments
  7200. (cdr org-agenda-redo-command)))
  7201. (org-agenda-redo)))
  7202. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7203. org-agenda-type))))
  7204. (defun org-add-to-string (var string)
  7205. (set var (concat (symbol-value var) string)))
  7206. (defun org-agenda-goto-date (span)
  7207. "Jump to DATE in agenda."
  7208. (interactive "P")
  7209. (let* ((org-read-date-prefer-future
  7210. (eval org-agenda-jump-prefer-future))
  7211. (date (org-read-date))
  7212. (day (time-to-days (org-time-string-to-time date)))
  7213. (org-agenda-sticky-orig org-agenda-sticky)
  7214. (org-agenda-buffer-tmp-name (buffer-name))
  7215. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7216. (0-arg (or current-prefix-arg (car args)))
  7217. (2-arg (nth 2 args))
  7218. (with-hour-p (nth 4 org-agenda-redo-command))
  7219. (newcmd (list 'org-agenda-list 0-arg date
  7220. (org-agenda-span-to-ndays
  7221. 2-arg (org-time-string-to-absolute date))
  7222. with-hour-p))
  7223. (newargs (cdr newcmd))
  7224. (inhibit-read-only t)
  7225. org-agenda-sticky)
  7226. (if (not (org-agenda-check-type t 'agenda))
  7227. (error "Not available in non-agenda views")
  7228. (add-text-properties (point-min) (point-max)
  7229. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7230. (org-agenda-redo)
  7231. (goto-char (point-min))
  7232. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7233. (save-excursion (move-beginning-of-line 2) (eobp))))
  7234. (move-beginning-of-line 2))
  7235. (setq org-agenda-sticky org-agenda-sticky-orig
  7236. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7237. (defun org-agenda-goto-today ()
  7238. "Go to today."
  7239. (interactive)
  7240. (org-agenda-check-type t 'timeline 'agenda)
  7241. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7242. (curspan (nth 2 args))
  7243. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7244. (cond
  7245. (tdpos (goto-char tdpos))
  7246. ((eq org-agenda-type 'agenda)
  7247. (let* ((sd (org-agenda-compute-starting-span
  7248. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7249. (org-agenda-overriding-arguments args))
  7250. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7251. (org-agenda-redo)
  7252. (org-agenda-find-same-or-today-or-agenda)))
  7253. (t (error "Cannot find today")))))
  7254. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7255. (goto-char
  7256. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7257. (text-property-any (point-min) (point-max) 'org-today t)
  7258. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7259. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7260. (org-agenda-goto-block-beginning))
  7261. (point-min))))
  7262. (defun org-agenda-goto-block-beginning ()
  7263. "Go the agenda block beginning."
  7264. (interactive)
  7265. (if (not (derived-mode-p 'org-agenda-mode))
  7266. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7267. (let (dest)
  7268. (save-excursion
  7269. (unless (looking-at "\\'")
  7270. (forward-char))
  7271. (let* ((prop 'org-agenda-structural-header)
  7272. (p (previous-single-property-change (point) prop))
  7273. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7274. (1- (point))) prop)))
  7275. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7276. (if (not dest)
  7277. (error "Cannot find the beginning of the blog")
  7278. (goto-char dest)
  7279. (move-beginning-of-line 1)))))
  7280. (defun org-agenda-later (arg)
  7281. "Go forward in time by the current span.
  7282. With prefix ARG, go forward that many times the current span."
  7283. (interactive "p")
  7284. (org-agenda-check-type t 'agenda)
  7285. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7286. (span (or (nth 2 args) org-agenda-current-span))
  7287. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7288. (greg (calendar-gregorian-from-absolute sd))
  7289. (cnt (org-get-at-bol 'org-day-cnt))
  7290. greg2)
  7291. (cond
  7292. ((numberp span)
  7293. (setq sd (+ (* span arg) sd)))
  7294. ((eq span 'day)
  7295. (setq sd (+ arg sd)))
  7296. ((eq span 'week)
  7297. (setq sd (+ (* 7 arg) sd)))
  7298. ((eq span 'month)
  7299. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7300. sd (calendar-absolute-from-gregorian greg2))
  7301. (setcar greg2 (1+ (car greg2))))
  7302. ((eq span 'year)
  7303. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7304. sd (calendar-absolute-from-gregorian greg2))
  7305. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7306. (t
  7307. (setq sd (+ (* span arg) sd))))
  7308. (let ((org-agenda-overriding-cmd
  7309. ;; `cmd' may have been set by `org-agenda-run-series' which
  7310. ;; uses `org-agenda-overriding-cmd' to decide whether
  7311. ;; overriding is allowed for `cmd'
  7312. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7313. (org-agenda-overriding-arguments
  7314. (list (car args) sd span)))
  7315. (org-agenda-redo)
  7316. (org-agenda-find-same-or-today-or-agenda cnt))))
  7317. (defun org-agenda-earlier (arg)
  7318. "Go backward in time by the current span.
  7319. With prefix ARG, go backward that many times the current span."
  7320. (interactive "p")
  7321. (org-agenda-later (- arg)))
  7322. (defun org-agenda-view-mode-dispatch ()
  7323. "Call one of the view mode commands."
  7324. (interactive)
  7325. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  7326. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7327. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7328. (let ((a (read-char-exclusive)))
  7329. (case a
  7330. (?\ (call-interactively 'org-agenda-reset-view))
  7331. (?d (call-interactively 'org-agenda-day-view))
  7332. (?w (call-interactively 'org-agenda-week-view))
  7333. (?m (call-interactively 'org-agenda-month-view))
  7334. (?y (call-interactively 'org-agenda-year-view))
  7335. (?l (call-interactively 'org-agenda-log-mode))
  7336. (?L (org-agenda-log-mode '(4)))
  7337. (?c (org-agenda-log-mode 'clockcheck))
  7338. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7339. (?a (call-interactively 'org-agenda-archives-mode))
  7340. (?A (org-agenda-archives-mode 'files))
  7341. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7342. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7343. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7344. (?D (call-interactively 'org-agenda-toggle-diary))
  7345. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7346. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7347. (org-agenda-check-type t 'timeline 'agenda)
  7348. (org-agenda-redo))
  7349. (message "Display now includes inactive timestamps as well"))
  7350. (?q (message "Abort"))
  7351. (otherwise (error "Invalid key" )))))
  7352. (defun org-agenda-reset-view ()
  7353. "Switch to default view for agenda."
  7354. (interactive)
  7355. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7356. (defun org-agenda-day-view (&optional day-of-month)
  7357. "Switch to daily view for agenda.
  7358. With argument DAY-OF-MONTH, switch to that day of the month."
  7359. (interactive "P")
  7360. (org-agenda-change-time-span 'day day-of-month))
  7361. (defun org-agenda-week-view (&optional iso-week)
  7362. "Switch to daily view for agenda.
  7363. With argument ISO-WEEK, switch to the corresponding ISO week.
  7364. If ISO-WEEK has more then 2 digits, only the last two encode the
  7365. week. Any digits before this encode a year. So 200712 means
  7366. week 12 of year 2007. Years in the range 1938-2037 can also be
  7367. written as 2-digit years."
  7368. (interactive "P")
  7369. (org-agenda-change-time-span 'week iso-week))
  7370. (defun org-agenda-month-view (&optional month)
  7371. "Switch to monthly view for agenda.
  7372. With argument MONTH, switch to that month."
  7373. (interactive "P")
  7374. (org-agenda-change-time-span 'month month))
  7375. (defun org-agenda-year-view (&optional year)
  7376. "Switch to yearly view for agenda.
  7377. With argument YEAR, switch to that year.
  7378. If MONTH has more then 2 digits, only the last two encode the
  7379. month. Any digits before this encode a year. So 200712 means
  7380. December year 2007. Years in the range 1938-2037 can also be
  7381. written as 2-digit years."
  7382. (interactive "P")
  7383. (when year
  7384. (setq year (org-small-year-to-year year)))
  7385. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7386. (org-agenda-change-time-span 'year year)
  7387. (error "Abort")))
  7388. (defun org-agenda-change-time-span (span &optional n)
  7389. "Change the agenda view to SPAN.
  7390. SPAN may be `day', `week', `month', `year'."
  7391. (org-agenda-check-type t 'agenda)
  7392. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7393. (curspan (nth 2 args)))
  7394. (if (and (not n) (equal curspan span))
  7395. (error "Viewing span is already \"%s\"" span))
  7396. (let* ((sd (or (org-get-at-bol 'day)
  7397. (nth 1 args)
  7398. org-starting-day))
  7399. (sd (org-agenda-compute-starting-span sd span n))
  7400. (org-agenda-overriding-cmd
  7401. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7402. (org-agenda-overriding-arguments
  7403. (list (car args) sd span)))
  7404. (org-agenda-redo)
  7405. (org-agenda-find-same-or-today-or-agenda))
  7406. (org-agenda-set-mode-name)
  7407. (message "Switched to %s view" span)))
  7408. (defun org-agenda-compute-starting-span (sd span &optional n)
  7409. "Compute starting date for agenda.
  7410. SPAN may be `day', `week', `month', `year'. The return value
  7411. is a cons cell with the starting date and the number of days,
  7412. so that the date SD will be in that range."
  7413. (let* ((greg (calendar-gregorian-from-absolute sd))
  7414. (dg (nth 1 greg))
  7415. (mg (car greg))
  7416. (yg (nth 2 greg)))
  7417. (cond
  7418. ((eq span 'day)
  7419. (when n
  7420. (setq sd (+ (calendar-absolute-from-gregorian
  7421. (list mg 1 yg))
  7422. n -1))))
  7423. ((eq span 'week)
  7424. (let* ((nt (calendar-day-of-week
  7425. (calendar-gregorian-from-absolute sd)))
  7426. (d (if org-agenda-start-on-weekday
  7427. (- nt org-agenda-start-on-weekday)
  7428. 0))
  7429. y1)
  7430. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7431. (when n
  7432. (require 'cal-iso)
  7433. (when (> n 99)
  7434. (setq y1 (org-small-year-to-year (/ n 100))
  7435. n (mod n 100)))
  7436. (setq sd
  7437. (calendar-absolute-from-iso
  7438. (list n 1
  7439. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7440. ((eq span 'month)
  7441. (let (y1)
  7442. (when (and n (> n 99))
  7443. (setq y1 (org-small-year-to-year (/ n 100))
  7444. n (mod n 100)))
  7445. (setq sd (calendar-absolute-from-gregorian
  7446. (list (or n mg) 1 (or y1 yg))))))
  7447. ((eq span 'year)
  7448. (setq sd (calendar-absolute-from-gregorian
  7449. (list 1 1 (or n yg))))))
  7450. sd))
  7451. (defun org-agenda-next-date-line (&optional arg)
  7452. "Jump to the next line indicating a date in agenda buffer."
  7453. (interactive "p")
  7454. (org-agenda-check-type t 'agenda 'timeline)
  7455. (beginning-of-line 1)
  7456. ;; This does not work if user makes date format that starts with a blank
  7457. (if (looking-at "^\\S-") (forward-char 1))
  7458. (if (not (re-search-forward "^\\S-" nil t arg))
  7459. (progn
  7460. (backward-char 1)
  7461. (error "No next date after this line in this buffer")))
  7462. (goto-char (match-beginning 0)))
  7463. (defun org-agenda-previous-date-line (&optional arg)
  7464. "Jump to the previous line indicating a date in agenda buffer."
  7465. (interactive "p")
  7466. (org-agenda-check-type t 'agenda 'timeline)
  7467. (beginning-of-line 1)
  7468. (if (not (re-search-backward "^\\S-" nil t arg))
  7469. (error "No previous date before this line in this buffer")))
  7470. ;; Initialize the highlight
  7471. (defvar org-hl (make-overlay 1 1))
  7472. (overlay-put org-hl 'face 'highlight)
  7473. (defun org-highlight (begin end &optional buffer)
  7474. "Highlight a region with overlay."
  7475. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7476. (defun org-unhighlight ()
  7477. "Detach overlay INDEX."
  7478. (org-detach-overlay org-hl))
  7479. (defun org-unhighlight-once ()
  7480. "Remove the highlight from its position, and this function from the hook."
  7481. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7482. (org-unhighlight))
  7483. (defvar org-agenda-pre-follow-window-conf nil)
  7484. (defun org-agenda-follow-mode ()
  7485. "Toggle follow mode in an agenda buffer."
  7486. (interactive)
  7487. (unless org-agenda-follow-mode
  7488. (setq org-agenda-pre-follow-window-conf
  7489. (current-window-configuration)))
  7490. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7491. (unless org-agenda-follow-mode
  7492. (set-window-configuration org-agenda-pre-follow-window-conf))
  7493. (org-agenda-set-mode-name)
  7494. (org-agenda-do-context-action)
  7495. (message "Follow mode is %s"
  7496. (if org-agenda-follow-mode "on" "off")))
  7497. (defun org-agenda-entry-text-mode (&optional arg)
  7498. "Toggle entry text mode in an agenda buffer."
  7499. (interactive "P")
  7500. (if (or org-agenda-tag-filter
  7501. org-agenda-category-filter
  7502. org-agenda-regexp-filter
  7503. org-agenda-top-headline-filter)
  7504. (user-error "Can't show entry text in filtered views")
  7505. (setq org-agenda-entry-text-mode (or (integerp arg)
  7506. (not org-agenda-entry-text-mode)))
  7507. (org-agenda-entry-text-hide)
  7508. (and org-agenda-entry-text-mode
  7509. (let ((org-agenda-entry-text-maxlines
  7510. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7511. (org-agenda-entry-text-show)))
  7512. (org-agenda-set-mode-name)
  7513. (message "Entry text mode is %s%s"
  7514. (if org-agenda-entry-text-mode "on" "off")
  7515. (if (not org-agenda-entry-text-mode) ""
  7516. (format " (maximum number of lines is %d)"
  7517. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7518. (defun org-agenda-clockreport-mode (&optional with-filter)
  7519. "Toggle clocktable mode in an agenda buffer.
  7520. With prefix arg WITH-FILTER, make the clocktable respect the current
  7521. agenda filter."
  7522. (interactive "P")
  7523. (org-agenda-check-type t 'agenda)
  7524. (if with-filter
  7525. (setq org-agenda-clockreport-mode 'with-filter)
  7526. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7527. (org-agenda-set-mode-name)
  7528. (org-agenda-redo)
  7529. (message "Clocktable mode is %s"
  7530. (if org-agenda-clockreport-mode "on" "off")))
  7531. (defun org-agenda-log-mode (&optional special)
  7532. "Toggle log mode in an agenda buffer.
  7533. With argument SPECIAL, show all possible log items, not only the ones
  7534. configured in `org-agenda-log-mode-items'.
  7535. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7536. (interactive "P")
  7537. (org-agenda-check-type t 'agenda 'timeline)
  7538. (setq org-agenda-show-log
  7539. (cond
  7540. ((equal special '(16)) 'only)
  7541. ((eq special 'clockcheck)
  7542. (if (eq org-agenda-show-log 'clockcheck)
  7543. nil 'clockcheck))
  7544. (special '(closed clock state))
  7545. (t (not org-agenda-show-log))))
  7546. (org-agenda-set-mode-name)
  7547. (org-agenda-redo)
  7548. (message "Log mode is %s"
  7549. (if org-agenda-show-log "on" "off")))
  7550. (defun org-agenda-archives-mode (&optional with-files)
  7551. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7552. When called with a prefix argument, include all archive files as well."
  7553. (interactive "P")
  7554. (setq org-agenda-archives-mode
  7555. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7556. (org-agenda-set-mode-name)
  7557. (org-agenda-redo)
  7558. (message
  7559. "%s"
  7560. (cond
  7561. ((eq org-agenda-archives-mode nil)
  7562. "No archives are included")
  7563. ((eq org-agenda-archives-mode 'trees)
  7564. (format "Trees with :%s: tag are included" org-archive-tag))
  7565. ((eq org-agenda-archives-mode t)
  7566. (format "Trees with :%s: tag and all active archive files are included"
  7567. org-archive-tag)))))
  7568. (defun org-agenda-toggle-diary ()
  7569. "Toggle diary inclusion in an agenda buffer."
  7570. (interactive)
  7571. (org-agenda-check-type t 'agenda)
  7572. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7573. (org-agenda-redo)
  7574. (org-agenda-set-mode-name)
  7575. (message "Diary inclusion turned %s"
  7576. (if org-agenda-include-diary "on" "off")))
  7577. (defun org-agenda-toggle-deadlines ()
  7578. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7579. (interactive)
  7580. (org-agenda-check-type t 'agenda)
  7581. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7582. (org-agenda-redo)
  7583. (org-agenda-set-mode-name)
  7584. (message "Deadlines inclusion turned %s"
  7585. (if org-agenda-include-deadlines "on" "off")))
  7586. (defun org-agenda-toggle-time-grid ()
  7587. "Toggle time grid in an agenda buffer."
  7588. (interactive)
  7589. (org-agenda-check-type t 'agenda)
  7590. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7591. (org-agenda-redo)
  7592. (org-agenda-set-mode-name)
  7593. (message "Time-grid turned %s"
  7594. (if org-agenda-use-time-grid "on" "off")))
  7595. (defun org-agenda-set-mode-name ()
  7596. "Set the mode name to indicate all the small mode settings."
  7597. (setq mode-name
  7598. (list "Org-Agenda"
  7599. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7600. " "
  7601. '(:eval (org-agenda-span-name org-agenda-current-span))
  7602. (if org-agenda-follow-mode " Follow" "")
  7603. (if org-agenda-entry-text-mode " ETxt" "")
  7604. (if org-agenda-include-diary " Diary" "")
  7605. (if org-agenda-include-deadlines " Ddl" "")
  7606. (if org-agenda-use-time-grid " Grid" "")
  7607. (if (and (boundp 'org-habit-show-habits)
  7608. org-habit-show-habits) " Habit" "")
  7609. (cond
  7610. ((consp org-agenda-show-log) " LogAll")
  7611. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7612. (org-agenda-show-log " Log")
  7613. (t ""))
  7614. (if (or org-agenda-category-filter
  7615. (get 'org-agenda-category-filter :preset-filter))
  7616. '(:eval (org-propertize
  7617. (concat " <"
  7618. (mapconcat
  7619. 'identity
  7620. (append
  7621. (get 'org-agenda-category-filter :preset-filter)
  7622. org-agenda-category-filter)
  7623. "")
  7624. ">")
  7625. 'face 'org-agenda-filter-category
  7626. 'help-echo "Category used in filtering")) "")
  7627. (if (or org-agenda-tag-filter
  7628. (get 'org-agenda-tag-filter :preset-filter))
  7629. '(:eval (org-propertize
  7630. (concat " {"
  7631. (mapconcat
  7632. 'identity
  7633. (append
  7634. (get 'org-agenda-tag-filter :preset-filter)
  7635. org-agenda-tag-filter)
  7636. "")
  7637. "}")
  7638. 'face 'org-agenda-filter-tags
  7639. 'help-echo "Tags used in filtering")) "")
  7640. (if (or org-agenda-regexp-filter
  7641. (get 'org-agenda-regexp-filter :preset-filter))
  7642. '(:eval (org-propertize
  7643. (concat " ["
  7644. (mapconcat
  7645. 'identity
  7646. (append
  7647. (get 'org-agenda-regexp-filter :preset-filter)
  7648. org-agenda-regexp-filter)
  7649. "")
  7650. "]")
  7651. 'face 'org-agenda-filter-regexp
  7652. 'help-echo "Regexp used in filtering")) "")
  7653. (if org-agenda-archives-mode
  7654. (if (eq org-agenda-archives-mode t)
  7655. " Archives"
  7656. (format " :%s:" org-archive-tag))
  7657. "")
  7658. (if org-agenda-clockreport-mode
  7659. (if (eq org-agenda-clockreport-mode 'with-filter)
  7660. " Clock{}" " Clock")
  7661. "")))
  7662. (force-mode-line-update))
  7663. (define-obsolete-function-alias
  7664. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7665. (defun org-agenda-update-agenda-type ()
  7666. "Update the agenda type after each command."
  7667. (setq org-agenda-type
  7668. (or (get-text-property (point) 'org-agenda-type)
  7669. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7670. (defun org-agenda-next-line ()
  7671. "Move cursor to the next line, and show if follow mode is active."
  7672. (interactive)
  7673. (call-interactively 'next-line)
  7674. (org-agenda-do-context-action))
  7675. (defun org-agenda-previous-line ()
  7676. "Move cursor to the previous line, and show if follow-mode is active."
  7677. (interactive)
  7678. (call-interactively 'previous-line)
  7679. (org-agenda-do-context-action))
  7680. (defun org-agenda-next-item (n)
  7681. "Move cursor to next agenda item."
  7682. (interactive "p")
  7683. (let ((col (current-column)))
  7684. (dotimes (c n)
  7685. (when (next-single-property-change (point-at-eol) 'org-marker)
  7686. (move-end-of-line 1)
  7687. (goto-char (next-single-property-change (point) 'org-marker))))
  7688. (org-move-to-column col))
  7689. (org-agenda-do-context-action))
  7690. (defun org-agenda-previous-item (n)
  7691. "Move cursor to next agenda item."
  7692. (interactive "p")
  7693. (dotimes (c n)
  7694. (let ((col (current-column))
  7695. (goto (save-excursion
  7696. (move-end-of-line 0)
  7697. (previous-single-property-change (point) 'org-marker))))
  7698. (if goto (goto-char goto))
  7699. (org-move-to-column col)))
  7700. (org-agenda-do-context-action))
  7701. (defun org-agenda-do-context-action ()
  7702. "Show outline path and, maybe, follow mode window."
  7703. (let ((m (org-get-at-bol 'org-marker)))
  7704. (when (and (markerp m) (marker-buffer m))
  7705. (and org-agenda-follow-mode
  7706. (if org-agenda-follow-indirect
  7707. (org-agenda-tree-to-indirect-buffer nil)
  7708. (org-agenda-show)))
  7709. (and org-agenda-show-outline-path
  7710. (org-with-point-at m (org-display-outline-path t))))))
  7711. (defun org-agenda-show-tags ()
  7712. "Show the tags applicable to the current item."
  7713. (interactive)
  7714. (let* ((tags (org-get-at-bol 'tags)))
  7715. (if tags
  7716. (message "Tags are :%s:"
  7717. (org-no-properties (mapconcat 'identity tags ":")))
  7718. (message "No tags associated with this line"))))
  7719. (defun org-agenda-goto (&optional highlight)
  7720. "Go to the Org-mode file which contains the item at point."
  7721. (interactive)
  7722. (let* ((marker (or (org-get-at-bol 'org-marker)
  7723. (org-agenda-error)))
  7724. (buffer (marker-buffer marker))
  7725. (pos (marker-position marker)))
  7726. (switch-to-buffer-other-window buffer)
  7727. (widen)
  7728. (push-mark)
  7729. (goto-char pos)
  7730. (when (derived-mode-p 'org-mode)
  7731. (org-show-context 'agenda)
  7732. (save-excursion
  7733. (and (outline-next-heading)
  7734. (org-flag-heading nil)))) ; show the next heading
  7735. (when (outline-invisible-p)
  7736. (show-entry)) ; display invisible text
  7737. (recenter (/ (window-height) 2))
  7738. (run-hooks 'org-agenda-after-show-hook)
  7739. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7740. (defvar org-agenda-after-show-hook nil
  7741. "Normal hook run after an item has been shown from the agenda.
  7742. Point is in the buffer where the item originated.")
  7743. (defun org-agenda-kill ()
  7744. "Kill the entry or subtree belonging to the current agenda entry."
  7745. (interactive)
  7746. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7747. (let* ((bufname-orig (buffer-name))
  7748. (marker (or (org-get-at-bol 'org-marker)
  7749. (org-agenda-error)))
  7750. (buffer (marker-buffer marker))
  7751. (pos (marker-position marker))
  7752. (type (org-get-at-bol 'type))
  7753. dbeg dend (n 0) conf)
  7754. (org-with-remote-undo buffer
  7755. (with-current-buffer buffer
  7756. (save-excursion
  7757. (goto-char pos)
  7758. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7759. (setq dbeg (progn (org-back-to-heading t) (point))
  7760. dend (org-end-of-subtree t t))
  7761. (setq dbeg (point-at-bol)
  7762. dend (min (point-max) (1+ (point-at-eol)))))
  7763. (goto-char dbeg)
  7764. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7765. (setq conf (or (eq t org-agenda-confirm-kill)
  7766. (and (numberp org-agenda-confirm-kill)
  7767. (> n org-agenda-confirm-kill))))
  7768. (and conf
  7769. (not (y-or-n-p
  7770. (format "Delete entry with %d lines in buffer \"%s\"? "
  7771. n (buffer-name buffer))))
  7772. (error "Abort"))
  7773. (let ((org-agenda-buffer-name bufname-orig))
  7774. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7775. (with-current-buffer buffer (delete-region dbeg dend))
  7776. (message "Agenda item and source killed"))))
  7777. (defvar org-archive-default-command) ; defined in org-archive.el
  7778. (defun org-agenda-archive-default ()
  7779. "Archive the entry or subtree belonging to the current agenda entry."
  7780. (interactive)
  7781. (require 'org-archive)
  7782. (org-agenda-archive-with org-archive-default-command))
  7783. (defun org-agenda-archive-default-with-confirmation ()
  7784. "Archive the entry or subtree belonging to the current agenda entry."
  7785. (interactive)
  7786. (require 'org-archive)
  7787. (org-agenda-archive-with org-archive-default-command 'confirm))
  7788. (defun org-agenda-archive ()
  7789. "Archive the entry or subtree belonging to the current agenda entry."
  7790. (interactive)
  7791. (org-agenda-archive-with 'org-archive-subtree))
  7792. (defun org-agenda-archive-to-archive-sibling ()
  7793. "Move the entry to the archive sibling."
  7794. (interactive)
  7795. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7796. (defun org-agenda-archive-with (cmd &optional confirm)
  7797. "Move the entry to the archive sibling."
  7798. (interactive)
  7799. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7800. (let* ((bufname-orig (buffer-name))
  7801. (marker (or (org-get-at-bol 'org-marker)
  7802. (org-agenda-error)))
  7803. (buffer (marker-buffer marker))
  7804. (pos (marker-position marker)))
  7805. (org-with-remote-undo buffer
  7806. (with-current-buffer buffer
  7807. (if (derived-mode-p 'org-mode)
  7808. (if (and confirm
  7809. (not (y-or-n-p "Archive this subtree or entry? ")))
  7810. (error "Abort")
  7811. (save-excursion
  7812. (goto-char pos)
  7813. (let ((org-agenda-buffer-name bufname-orig))
  7814. (org-remove-subtree-entries-from-agenda))
  7815. (org-back-to-heading t)
  7816. (funcall cmd)))
  7817. (error "Archiving works only in Org-mode files"))))))
  7818. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7819. "Remove all lines in the agenda that correspond to a given subtree.
  7820. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7821. If this information is not given, the function uses the tree at point."
  7822. (let ((buf (or buf (current-buffer))) m p)
  7823. (save-excursion
  7824. (unless (and beg end)
  7825. (org-back-to-heading t)
  7826. (setq beg (point))
  7827. (org-end-of-subtree t)
  7828. (setq end (point)))
  7829. (set-buffer (get-buffer org-agenda-buffer-name))
  7830. (save-excursion
  7831. (goto-char (point-max))
  7832. (beginning-of-line 1)
  7833. (while (not (bobp))
  7834. (when (and (setq m (org-get-at-bol 'org-marker))
  7835. (equal buf (marker-buffer m))
  7836. (setq p (marker-position m))
  7837. (>= p beg)
  7838. (< p end))
  7839. (let ((inhibit-read-only t))
  7840. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7841. (beginning-of-line 0))))))
  7842. (defun org-agenda-refile (&optional goto rfloc no-update)
  7843. "Refile the item at point.
  7844. When GOTO is 0 or '(64), clear the refile cache.
  7845. When GOTO is '(16), go to the location of the last refiled item.
  7846. RFLOC can be a refile location obtained in a different way.
  7847. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7848. (interactive "P")
  7849. (cond
  7850. ((member goto '(0 (64)))
  7851. (org-refile-cache-clear))
  7852. ((equal goto '(16))
  7853. (org-refile-goto-last-stored))
  7854. (t
  7855. (let* ((buffer-orig (buffer-name))
  7856. (marker (or (org-get-at-bol 'org-hd-marker)
  7857. (org-agenda-error)))
  7858. (buffer (marker-buffer marker))
  7859. (pos (marker-position marker))
  7860. (rfloc (or rfloc
  7861. (org-refile-get-location
  7862. (if goto "Goto" "Refile to") buffer
  7863. org-refile-allow-creating-parent-nodes))))
  7864. (with-current-buffer buffer
  7865. (save-excursion
  7866. (save-restriction
  7867. (widen)
  7868. (goto-char marker)
  7869. (let ((org-agenda-buffer-name buffer-orig))
  7870. (org-remove-subtree-entries-from-agenda))
  7871. (org-refile goto buffer rfloc)))))
  7872. (unless no-update (org-agenda-redo)))))
  7873. (defun org-agenda-open-link (&optional arg)
  7874. "Open the link(s) in the current entry, if any.
  7875. This looks for a link in the displayed line in the agenda.
  7876. It also looks at the text of the entry itself."
  7877. (interactive "P")
  7878. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7879. (org-get-at-bol 'org-marker)))
  7880. (buffer (and marker (marker-buffer marker)))
  7881. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7882. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7883. (lk0 (car lkall))
  7884. (lk (if (stringp lk0) (list lk0) lk0))
  7885. (lkend (cdr lkall))
  7886. trg)
  7887. (cond
  7888. ((and buffer lk)
  7889. (mapcar (lambda(l)
  7890. (with-current-buffer buffer
  7891. (setq trg (and (string-match org-bracket-link-regexp l)
  7892. (match-string 1 l)))
  7893. (if (or (not trg) (string-match org-any-link-re trg))
  7894. (save-excursion
  7895. (save-restriction
  7896. (widen)
  7897. (goto-char marker)
  7898. (when (search-forward l nil lkend)
  7899. (goto-char (match-beginning 0))
  7900. (org-open-at-point))))
  7901. ;; This is an internal link, widen the buffer
  7902. (switch-to-buffer-other-window buffer)
  7903. (widen)
  7904. (goto-char marker)
  7905. (when (search-forward l nil lkend)
  7906. (goto-char (match-beginning 0))
  7907. (org-open-at-point)))))
  7908. lk))
  7909. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7910. (save-excursion
  7911. (beginning-of-line 1)
  7912. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7913. (org-open-link-from-string (match-string 1)))
  7914. (t (message "No link to open here")))))
  7915. (defun org-agenda-copy-local-variable (var)
  7916. "Get a variable from a referenced buffer and install it here."
  7917. (let ((m (org-get-at-bol 'org-marker)))
  7918. (when (and m (buffer-live-p (marker-buffer m)))
  7919. (org-set-local var (with-current-buffer (marker-buffer m)
  7920. (symbol-value var))))))
  7921. (defun org-agenda-switch-to (&optional delete-other-windows)
  7922. "Go to the Org-mode file which contains the item at point."
  7923. (interactive)
  7924. (if (and org-return-follows-link
  7925. (not (org-get-at-bol 'org-marker))
  7926. (org-in-regexp org-bracket-link-regexp))
  7927. (org-open-link-from-string (match-string 0))
  7928. (let* ((marker (or (org-get-at-bol 'org-marker)
  7929. (org-agenda-error)))
  7930. (buffer (marker-buffer marker))
  7931. (pos (marker-position marker)))
  7932. (org-pop-to-buffer-same-window buffer)
  7933. (and delete-other-windows (delete-other-windows))
  7934. (widen)
  7935. (goto-char pos)
  7936. (when (derived-mode-p 'org-mode)
  7937. (org-show-context 'agenda)
  7938. (save-excursion
  7939. (and (outline-next-heading)
  7940. (org-flag-heading nil))) ; show the next heading
  7941. (when (outline-invisible-p)
  7942. (show-entry)) ; display invisible text
  7943. (run-hooks 'org-agenda-after-show-hook)))))
  7944. (defun org-agenda-goto-mouse (ev)
  7945. "Go to the Org-mode file which contains the item at the mouse click."
  7946. (interactive "e")
  7947. (mouse-set-point ev)
  7948. (org-agenda-goto))
  7949. (defun org-agenda-show (&optional full-entry)
  7950. "Display the Org-mode file which contains the item at point.
  7951. With prefix argument FULL-ENTRY, make the entire entry visible
  7952. if it was hidden in the outline."
  7953. (interactive "P")
  7954. (let ((win (selected-window)))
  7955. (if full-entry
  7956. (let ((org-show-entry-below t))
  7957. (org-agenda-goto t))
  7958. (org-agenda-goto t))
  7959. (select-window win)))
  7960. (defvar org-agenda-show-window nil)
  7961. (defun org-agenda-show-and-scroll-up (&optional arg)
  7962. "Display the Org-mode file which contains the item at point.
  7963. When called repeatedly, scroll the window that is displaying the buffer.
  7964. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7965. `show-subtree' to display the item, so that drawers and logbooks stay
  7966. folded."
  7967. (interactive "P")
  7968. (let ((win (selected-window)))
  7969. (if (and (window-live-p org-agenda-show-window)
  7970. (eq this-command last-command))
  7971. (progn
  7972. (select-window org-agenda-show-window)
  7973. (ignore-errors (scroll-up)))
  7974. (org-agenda-goto t)
  7975. (if arg (org-show-entry) (show-subtree))
  7976. (setq org-agenda-show-window (selected-window)))
  7977. (select-window win)))
  7978. (defun org-agenda-show-scroll-down ()
  7979. "Scroll down the window showing the agenda."
  7980. (interactive)
  7981. (let ((win (selected-window)))
  7982. (when (window-live-p org-agenda-show-window)
  7983. (select-window org-agenda-show-window)
  7984. (ignore-errors (scroll-down))
  7985. (select-window win))))
  7986. (defun org-agenda-show-1 (&optional more)
  7987. "Display the Org-mode file which contains the item at point.
  7988. The prefix arg selects the amount of information to display:
  7989. 0 hide the subtree
  7990. 1 just show the entry according to defaults.
  7991. 2 show the children view
  7992. 3 show the subtree view
  7993. 4 show the entire subtree and any LOGBOOK drawers
  7994. 5 show the entire subtree and any drawers
  7995. With prefix argument FULL-ENTRY, make the entire entry visible
  7996. if it was hidden in the outline."
  7997. (interactive "p")
  7998. (let ((win (selected-window)))
  7999. (org-agenda-goto t)
  8000. (org-recenter-heading 1)
  8001. (cond
  8002. ((= more 0)
  8003. (hide-subtree)
  8004. (save-excursion
  8005. (org-back-to-heading)
  8006. (run-hook-with-args 'org-cycle-hook 'folded))
  8007. (message "Remote: FOLDED"))
  8008. ((and (org-called-interactively-p 'any) (= more 1))
  8009. (message "Remote: show with default settings"))
  8010. ((= more 2)
  8011. (show-entry)
  8012. (show-children)
  8013. (save-excursion
  8014. (org-back-to-heading)
  8015. (run-hook-with-args 'org-cycle-hook 'children))
  8016. (message "Remote: CHILDREN"))
  8017. ((= more 3)
  8018. (show-subtree)
  8019. (save-excursion
  8020. (org-back-to-heading)
  8021. (run-hook-with-args 'org-cycle-hook 'subtree))
  8022. (message "Remote: SUBTREE"))
  8023. ((= more 4)
  8024. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  8025. (org-drawer-regexp
  8026. (concat "^[ \t]*:\\("
  8027. (mapconcat 'regexp-quote org-drawers "\\|")
  8028. "\\):[ \t]*$")))
  8029. (show-subtree)
  8030. (save-excursion
  8031. (org-back-to-heading)
  8032. (org-cycle-hide-drawers 'subtree)))
  8033. (message "Remote: SUBTREE AND LOGBOOK"))
  8034. ((> more 4)
  8035. (show-subtree)
  8036. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8037. (select-window win)))
  8038. (defun org-recenter-heading (n)
  8039. (save-excursion
  8040. (org-back-to-heading)
  8041. (recenter n)))
  8042. (defvar org-agenda-cycle-counter nil)
  8043. (defun org-agenda-cycle-show (&optional n)
  8044. "Show the current entry in another window, with default settings.
  8045. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8046. When use repeatedly in immediate succession, the remote entry will cycle
  8047. through visibility
  8048. children -> subtree -> folded
  8049. When called with a numeric prefix arg, that arg will be passed through to
  8050. `org-agenda-show-1'. For the interpretation of that argument, see the
  8051. docstring of `org-agenda-show-1'."
  8052. (interactive "P")
  8053. (if (integerp n)
  8054. (setq org-agenda-cycle-counter n)
  8055. (if (not (eq last-command this-command))
  8056. (setq org-agenda-cycle-counter 1)
  8057. (if (equal org-agenda-cycle-counter 0)
  8058. (setq org-agenda-cycle-counter 2)
  8059. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8060. (if (> org-agenda-cycle-counter 3)
  8061. (setq org-agenda-cycle-counter 0)))))
  8062. (org-agenda-show-1 org-agenda-cycle-counter))
  8063. (defun org-agenda-recenter (arg)
  8064. "Display the Org-mode file which contains the item at point and recenter."
  8065. (interactive "P")
  8066. (let ((win (selected-window)))
  8067. (org-agenda-goto t)
  8068. (recenter arg)
  8069. (select-window win)))
  8070. (defun org-agenda-show-mouse (ev)
  8071. "Display the Org-mode file which contains the item at the mouse click."
  8072. (interactive "e")
  8073. (mouse-set-point ev)
  8074. (org-agenda-show))
  8075. (defun org-agenda-check-no-diary ()
  8076. "Check if the entry is a diary link and abort if yes."
  8077. (if (org-get-at-bol 'org-agenda-diary-link)
  8078. (org-agenda-error)))
  8079. (defun org-agenda-error ()
  8080. (error "Command not allowed in this line"))
  8081. (defun org-agenda-tree-to-indirect-buffer (arg)
  8082. "Show the subtree corresponding to the current entry in an indirect buffer.
  8083. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8084. With a numerical prefix ARG, go up to this level and then take that tree.
  8085. With a negative numeric ARG, go up by this number of levels.
  8086. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8087. use the dedicated frame)."
  8088. (interactive "P")
  8089. (if current-prefix-arg
  8090. (org-agenda-do-tree-to-indirect-buffer arg)
  8091. (let ((agenda-buffer (buffer-name))
  8092. (agenda-window (selected-window))
  8093. (indirect-window
  8094. (and org-last-indirect-buffer
  8095. (get-buffer-window org-last-indirect-buffer))))
  8096. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8097. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8098. (eq org-indirect-buffer-display 'dedicated-frame))
  8099. (unwind-protect
  8100. (unless (and indirect-window (window-live-p indirect-window))
  8101. (setq indirect-window (split-window agenda-window)))
  8102. (and indirect-window (select-window indirect-window))
  8103. (switch-to-buffer org-last-indirect-buffer :norecord)
  8104. (fit-window-to-buffer indirect-window)))
  8105. (select-window (get-buffer-window agenda-buffer)))))
  8106. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8107. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8108. (org-agenda-check-no-diary)
  8109. (let* ((marker (or (org-get-at-bol 'org-marker)
  8110. (org-agenda-error)))
  8111. (buffer (marker-buffer marker))
  8112. (pos (marker-position marker)))
  8113. (with-current-buffer buffer
  8114. (save-excursion
  8115. (goto-char pos)
  8116. (funcall 'org-tree-to-indirect-buffer arg)))))
  8117. (defvar org-last-heading-marker (make-marker)
  8118. "Marker pointing to the headline that last changed its TODO state
  8119. by a remote command from the agenda.")
  8120. (defun org-agenda-todo-nextset ()
  8121. "Switch TODO entry to next sequence."
  8122. (interactive)
  8123. (org-agenda-todo 'nextset))
  8124. (defun org-agenda-todo-previousset ()
  8125. "Switch TODO entry to previous sequence."
  8126. (interactive)
  8127. (org-agenda-todo 'previousset))
  8128. (defun org-agenda-todo (&optional arg)
  8129. "Cycle TODO state of line at point, also in Org-mode file.
  8130. This changes the line at point, all other lines in the agenda referring to
  8131. the same tree node, and the headline of the tree node in the Org-mode file."
  8132. (interactive "P")
  8133. (org-agenda-check-no-diary)
  8134. (let* ((col (current-column))
  8135. (marker (or (org-get-at-bol 'org-marker)
  8136. (org-agenda-error)))
  8137. (buffer (marker-buffer marker))
  8138. (pos (marker-position marker))
  8139. (hdmarker (org-get-at-bol 'org-hd-marker))
  8140. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8141. (inhibit-read-only t)
  8142. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8143. (org-with-remote-undo buffer
  8144. (with-current-buffer buffer
  8145. (widen)
  8146. (goto-char pos)
  8147. (org-show-context 'agenda)
  8148. (save-excursion
  8149. (and (outline-next-heading)
  8150. (org-flag-heading nil))) ; show the next heading
  8151. (let ((current-prefix-arg arg))
  8152. (call-interactively 'org-todo))
  8153. (and (bolp) (forward-char 1))
  8154. (setq newhead (org-get-heading))
  8155. (when (and (org-bound-and-true-p
  8156. org-agenda-headline-snapshot-before-repeat)
  8157. (not (equal org-agenda-headline-snapshot-before-repeat
  8158. newhead))
  8159. todayp)
  8160. (setq newhead org-agenda-headline-snapshot-before-repeat
  8161. just-one t))
  8162. (save-excursion
  8163. (org-back-to-heading)
  8164. (move-marker org-last-heading-marker (point))))
  8165. (beginning-of-line 1)
  8166. (save-excursion
  8167. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8168. (org-move-to-column col))))
  8169. (defun org-agenda-add-note (&optional arg)
  8170. "Add a time-stamped note to the entry at point."
  8171. (interactive "P")
  8172. (org-agenda-check-no-diary)
  8173. (let* ((marker (or (org-get-at-bol 'org-marker)
  8174. (org-agenda-error)))
  8175. (buffer (marker-buffer marker))
  8176. (pos (marker-position marker))
  8177. (hdmarker (org-get-at-bol 'org-hd-marker))
  8178. (inhibit-read-only t))
  8179. (with-current-buffer buffer
  8180. (widen)
  8181. (goto-char pos)
  8182. (org-show-context 'agenda)
  8183. (save-excursion
  8184. (and (outline-next-heading)
  8185. (org-flag-heading nil))) ; show the next heading
  8186. (org-add-note))))
  8187. (defun org-agenda-change-all-lines (newhead hdmarker
  8188. &optional fixface just-this)
  8189. "Change all lines in the agenda buffer which match HDMARKER.
  8190. The new content of the line will be NEWHEAD (as modified by
  8191. `org-agenda-format-item'). HDMARKER is checked with
  8192. `equal' against all `org-hd-marker' text properties in the file.
  8193. If FIXFACE is non-nil, the face of each item is modified according to
  8194. the new TODO state.
  8195. If JUST-THIS is non-nil, change just the current line, not all.
  8196. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8197. (let* ((inhibit-read-only t)
  8198. (line (org-current-line))
  8199. (org-agenda-buffer (current-buffer))
  8200. (thetags (with-current-buffer (marker-buffer hdmarker)
  8201. (save-excursion (save-restriction (widen)
  8202. (goto-char hdmarker)
  8203. (org-get-tags-at)))))
  8204. props m pl undone-face done-face finish new dotime level cat tags)
  8205. (save-excursion
  8206. (goto-char (point-max))
  8207. (beginning-of-line 1)
  8208. (while (not finish)
  8209. (setq finish (bobp))
  8210. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8211. (or (not just-this) (= (org-current-line) line))
  8212. (equal m hdmarker))
  8213. (setq props (text-properties-at (point))
  8214. dotime (org-get-at-bol 'dotime)
  8215. cat (org-get-at-bol 'org-category)
  8216. level (org-get-at-bol 'level)
  8217. tags thetags
  8218. new
  8219. (let ((org-prefix-format-compiled
  8220. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8221. org-prefix-format-compiled))
  8222. (extra (org-get-at-bol 'extra)))
  8223. (with-current-buffer (marker-buffer hdmarker)
  8224. (save-excursion
  8225. (save-restriction
  8226. (widen)
  8227. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8228. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8229. undone-face (org-get-at-bol 'undone-face)
  8230. done-face (org-get-at-bol 'done-face))
  8231. (beginning-of-line 1)
  8232. (cond
  8233. ((equal new "")
  8234. (and (looking-at ".*\n?") (replace-match "")))
  8235. ((looking-at ".*")
  8236. (replace-match new t t)
  8237. (beginning-of-line 1)
  8238. (add-text-properties (point-at-bol) (point-at-eol) props)
  8239. (when fixface
  8240. (add-text-properties
  8241. (point-at-bol) (point-at-eol)
  8242. (list 'face
  8243. (if org-last-todo-state-is-todo
  8244. undone-face done-face))))
  8245. (org-agenda-highlight-todo 'line)
  8246. (beginning-of-line 1))
  8247. (t (error "Line update did not work")))
  8248. (save-restriction
  8249. (narrow-to-region (point-at-bol) (point-at-eol))
  8250. (org-agenda-finalize)))
  8251. (beginning-of-line 0)))))
  8252. (defun org-agenda-align-tags (&optional line)
  8253. "Align all tags in agenda items to `org-agenda-tags-column'."
  8254. (let ((inhibit-read-only t) l c)
  8255. (save-excursion
  8256. (goto-char (if line (point-at-bol) (point-min)))
  8257. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8258. (if line (point-at-eol) nil) t)
  8259. (add-text-properties
  8260. (match-beginning 2) (match-end 2)
  8261. (list 'face (delq nil (let ((prop (get-text-property
  8262. (match-beginning 2) 'face)))
  8263. (or (listp prop) (setq prop (list prop)))
  8264. (if (memq 'org-tag prop)
  8265. prop
  8266. (cons 'org-tag prop))))))
  8267. (setq l (- (match-end 2) (match-beginning 2))
  8268. c (if (< org-agenda-tags-column 0)
  8269. (- (abs org-agenda-tags-column) l)
  8270. org-agenda-tags-column))
  8271. (delete-region (match-beginning 1) (match-end 1))
  8272. (goto-char (match-beginning 1))
  8273. (insert (org-add-props
  8274. (make-string (max 1 (- c (current-column))) ?\ )
  8275. (plist-put (copy-sequence (text-properties-at (point)))
  8276. 'face nil))))
  8277. (goto-char (point-min))
  8278. (org-font-lock-add-tag-faces (point-max)))))
  8279. (defun org-agenda-priority-up ()
  8280. "Increase the priority of line at point, also in Org-mode file."
  8281. (interactive)
  8282. (org-agenda-priority 'up))
  8283. (defun org-agenda-priority-down ()
  8284. "Decrease the priority of line at point, also in Org-mode file."
  8285. (interactive)
  8286. (org-agenda-priority 'down))
  8287. (defun org-agenda-priority (&optional force-direction)
  8288. "Set the priority of line at point, also in Org-mode file.
  8289. This changes the line at point, all other lines in the agenda referring to
  8290. the same tree node, and the headline of the tree node in the Org-mode file.
  8291. Called with a universal prefix arg, show the priority instead of setting it."
  8292. (interactive "P")
  8293. (if (equal force-direction '(4))
  8294. (org-show-priority)
  8295. (unless org-enable-priority-commands
  8296. (error "Priority commands are disabled"))
  8297. (org-agenda-check-no-diary)
  8298. (let* ((marker (or (org-get-at-bol 'org-marker)
  8299. (org-agenda-error)))
  8300. (hdmarker (org-get-at-bol 'org-hd-marker))
  8301. (buffer (marker-buffer hdmarker))
  8302. (pos (marker-position hdmarker))
  8303. (inhibit-read-only t)
  8304. newhead)
  8305. (org-with-remote-undo buffer
  8306. (with-current-buffer buffer
  8307. (widen)
  8308. (goto-char pos)
  8309. (org-show-context 'agenda)
  8310. (save-excursion
  8311. (and (outline-next-heading)
  8312. (org-flag-heading nil))) ; show the next heading
  8313. (funcall 'org-priority force-direction)
  8314. (end-of-line 1)
  8315. (setq newhead (org-get-heading)))
  8316. (org-agenda-change-all-lines newhead hdmarker)
  8317. (beginning-of-line 1)))))
  8318. ;; FIXME: should fix the tags property of the agenda line.
  8319. (defun org-agenda-set-tags (&optional tag onoff)
  8320. "Set tags for the current headline."
  8321. (interactive)
  8322. (org-agenda-check-no-diary)
  8323. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8324. (call-interactively 'org-change-tag-in-region)
  8325. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8326. (org-agenda-error)))
  8327. (buffer (marker-buffer hdmarker))
  8328. (pos (marker-position hdmarker))
  8329. (inhibit-read-only t)
  8330. newhead)
  8331. (org-with-remote-undo buffer
  8332. (with-current-buffer buffer
  8333. (widen)
  8334. (goto-char pos)
  8335. (save-excursion
  8336. (org-show-context 'agenda))
  8337. (save-excursion
  8338. (and (outline-next-heading)
  8339. (org-flag-heading nil))) ; show the next heading
  8340. (goto-char pos)
  8341. (if tag
  8342. (org-toggle-tag tag onoff)
  8343. (call-interactively 'org-set-tags))
  8344. (end-of-line 1)
  8345. (setq newhead (org-get-heading)))
  8346. (org-agenda-change-all-lines newhead hdmarker)
  8347. (beginning-of-line 1)))))
  8348. (defun org-agenda-set-property ()
  8349. "Set a property for the current headline."
  8350. (interactive)
  8351. (org-agenda-check-no-diary)
  8352. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8353. (org-agenda-error)))
  8354. (buffer (marker-buffer hdmarker))
  8355. (pos (marker-position hdmarker))
  8356. (inhibit-read-only t)
  8357. newhead)
  8358. (org-with-remote-undo buffer
  8359. (with-current-buffer buffer
  8360. (widen)
  8361. (goto-char pos)
  8362. (save-excursion
  8363. (org-show-context 'agenda))
  8364. (save-excursion
  8365. (and (outline-next-heading)
  8366. (org-flag-heading nil))) ; show the next heading
  8367. (goto-char pos)
  8368. (call-interactively 'org-set-property)))))
  8369. (defun org-agenda-set-effort ()
  8370. "Set the effort 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-effort)
  8390. (end-of-line 1)
  8391. (setq newhead (org-get-heading)))
  8392. (org-agenda-change-all-lines newhead hdmarker))))
  8393. (defun org-agenda-toggle-archive-tag ()
  8394. "Toggle the archive tag for the current entry."
  8395. (interactive)
  8396. (org-agenda-check-no-diary)
  8397. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8398. (org-agenda-error)))
  8399. (buffer (marker-buffer hdmarker))
  8400. (pos (marker-position hdmarker))
  8401. (inhibit-read-only t)
  8402. newhead)
  8403. (org-with-remote-undo buffer
  8404. (with-current-buffer buffer
  8405. (widen)
  8406. (goto-char pos)
  8407. (org-show-context 'agenda)
  8408. (save-excursion
  8409. (and (outline-next-heading)
  8410. (org-flag-heading nil))) ; show the next heading
  8411. (call-interactively 'org-toggle-archive-tag)
  8412. (end-of-line 1)
  8413. (setq newhead (org-get-heading)))
  8414. (org-agenda-change-all-lines newhead hdmarker)
  8415. (beginning-of-line 1))))
  8416. (defun org-agenda-do-date-later (arg)
  8417. (interactive "P")
  8418. (cond
  8419. ((or (equal arg '(16))
  8420. (memq last-command
  8421. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8422. (setq this-command 'org-agenda-date-later-minutes)
  8423. (org-agenda-date-later-minutes 1))
  8424. ((or (equal arg '(4))
  8425. (memq last-command
  8426. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8427. (setq this-command 'org-agenda-date-later-hours)
  8428. (org-agenda-date-later-hours 1))
  8429. (t
  8430. (org-agenda-date-later (prefix-numeric-value arg)))))
  8431. (defun org-agenda-do-date-earlier (arg)
  8432. (interactive "P")
  8433. (cond
  8434. ((or (equal arg '(16))
  8435. (memq last-command
  8436. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8437. (setq this-command 'org-agenda-date-earlier-minutes)
  8438. (org-agenda-date-earlier-minutes 1))
  8439. ((or (equal arg '(4))
  8440. (memq last-command
  8441. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8442. (setq this-command 'org-agenda-date-earlier-hours)
  8443. (org-agenda-date-earlier-hours 1))
  8444. (t
  8445. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8446. (defun org-agenda-date-later (arg &optional what)
  8447. "Change the date of this item to ARG day(s) later."
  8448. (interactive "p")
  8449. (org-agenda-check-type t 'agenda 'timeline)
  8450. (org-agenda-check-no-diary)
  8451. (let* ((marker (or (org-get-at-bol 'org-marker)
  8452. (org-agenda-error)))
  8453. (buffer (marker-buffer marker))
  8454. (pos (marker-position marker))
  8455. cdate today)
  8456. (org-with-remote-undo buffer
  8457. (with-current-buffer buffer
  8458. (widen)
  8459. (goto-char pos)
  8460. (if (not (org-at-timestamp-p))
  8461. (error "Cannot find time stamp"))
  8462. (when (and org-agenda-move-date-from-past-immediately-to-today
  8463. (equal arg 1)
  8464. (or (not what) (eq what 'day))
  8465. (not (save-match-data (org-at-date-range-p))))
  8466. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8467. cdate (calendar-absolute-from-gregorian
  8468. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8469. today (org-today))
  8470. (if (> today cdate)
  8471. ;; immediately shift to today
  8472. (setq arg (- today cdate))))
  8473. (org-timestamp-change arg (or what 'day))
  8474. (when (and (org-at-date-range-p)
  8475. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8476. (let ((end org-last-changed-timestamp))
  8477. (org-timestamp-change arg (or what 'day))
  8478. (setq org-last-changed-timestamp
  8479. (concat org-last-changed-timestamp "--" end)))))
  8480. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8481. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8482. (defun org-agenda-date-earlier (arg &optional what)
  8483. "Change the date of this item to ARG day(s) earlier."
  8484. (interactive "p")
  8485. (org-agenda-date-later (- arg) what))
  8486. (defun org-agenda-date-later-minutes (arg)
  8487. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8488. (interactive "p")
  8489. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8490. (org-agenda-date-later arg 'minute))
  8491. (defun org-agenda-date-earlier-minutes (arg)
  8492. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8493. (interactive "p")
  8494. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8495. (org-agenda-date-earlier arg 'minute))
  8496. (defun org-agenda-date-later-hours (arg)
  8497. "Change the time of this item, in hour steps."
  8498. (interactive "p")
  8499. (org-agenda-date-later arg 'hour))
  8500. (defun org-agenda-date-earlier-hours (arg)
  8501. "Change the time of this item, in hour steps."
  8502. (interactive "p")
  8503. (org-agenda-date-earlier arg 'hour))
  8504. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8505. "Show new date stamp via text properties."
  8506. ;; We use text properties to make this undoable
  8507. (let ((inhibit-read-only t))
  8508. (setq stamp (concat prefix " => " stamp " "))
  8509. (save-excursion
  8510. (goto-char (point-max))
  8511. (while (not (bobp))
  8512. (when (equal marker (org-get-at-bol 'org-marker))
  8513. (org-move-to-column (- (window-width) (length stamp)) t)
  8514. (org-agenda-fix-tags-filter-overlays-at (point))
  8515. (if (featurep 'xemacs)
  8516. ;; Use `duplicable' property to trigger undo recording
  8517. (let ((ex (make-extent nil nil))
  8518. (gl (make-glyph stamp)))
  8519. (set-glyph-face gl 'secondary-selection)
  8520. (set-extent-properties
  8521. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8522. (insert-extent ex (1- (point)) (point-at-eol)))
  8523. (add-text-properties
  8524. (1- (point)) (point-at-eol)
  8525. (list 'display (org-add-props stamp nil
  8526. 'face 'secondary-selection))))
  8527. (beginning-of-line 1))
  8528. (beginning-of-line 0)))))
  8529. (defun org-agenda-date-prompt (arg)
  8530. "Change the date of this item. Date is prompted for, with default today.
  8531. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8532. be used to request time specification in the time stamp."
  8533. (interactive "P")
  8534. (org-agenda-check-type t 'agenda 'timeline)
  8535. (org-agenda-check-no-diary)
  8536. (let* ((marker (or (org-get-at-bol 'org-marker)
  8537. (org-agenda-error)))
  8538. (buffer (marker-buffer marker))
  8539. (pos (marker-position marker)))
  8540. (org-with-remote-undo buffer
  8541. (with-current-buffer buffer
  8542. (widen)
  8543. (goto-char pos)
  8544. (if (not (org-at-timestamp-p t))
  8545. (error "Cannot find time stamp"))
  8546. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8547. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8548. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8549. (defun org-agenda-schedule (arg &optional time)
  8550. "Schedule the item at point.
  8551. ARG is passed through to `org-schedule'."
  8552. (interactive "P")
  8553. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8554. (org-agenda-check-no-diary)
  8555. (let* ((marker (or (org-get-at-bol 'org-marker)
  8556. (org-agenda-error)))
  8557. (type (marker-insertion-type marker))
  8558. (buffer (marker-buffer marker))
  8559. (pos (marker-position marker))
  8560. (org-insert-labeled-timestamps-at-point nil)
  8561. ts)
  8562. (set-marker-insertion-type marker t)
  8563. (org-with-remote-undo buffer
  8564. (with-current-buffer buffer
  8565. (widen)
  8566. (goto-char pos)
  8567. (setq ts (org-schedule arg time)))
  8568. (org-agenda-show-new-time marker ts " S"))
  8569. (message "%s" ts)))
  8570. (defun org-agenda-deadline (arg &optional time)
  8571. "Schedule the item at point.
  8572. ARG is passed through to `org-deadline'."
  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. (buffer (marker-buffer marker))
  8579. (pos (marker-position marker))
  8580. (org-insert-labeled-timestamps-at-point nil)
  8581. ts)
  8582. (org-with-remote-undo buffer
  8583. (with-current-buffer buffer
  8584. (widen)
  8585. (goto-char pos)
  8586. (setq ts (org-deadline arg time)))
  8587. (org-agenda-show-new-time marker ts " D"))
  8588. (message "%s" ts)))
  8589. (defun org-agenda-clock-in (&optional arg)
  8590. "Start the clock on the currently selected item."
  8591. (interactive "P")
  8592. (org-agenda-check-no-diary)
  8593. (if (equal arg '(4))
  8594. (org-clock-in arg)
  8595. (let* ((marker (or (org-get-at-bol 'org-marker)
  8596. (org-agenda-error)))
  8597. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8598. (pos (marker-position marker))
  8599. (col (current-column))
  8600. newhead)
  8601. (org-with-remote-undo (marker-buffer marker)
  8602. (with-current-buffer (marker-buffer marker)
  8603. (widen)
  8604. (goto-char pos)
  8605. (org-show-context 'agenda)
  8606. (org-show-entry)
  8607. (org-cycle-hide-drawers 'children)
  8608. (org-clock-in arg)
  8609. (setq newhead (org-get-heading)))
  8610. (org-agenda-change-all-lines newhead hdmarker))
  8611. (org-move-to-column col))))
  8612. (defun org-agenda-clock-out ()
  8613. "Stop the currently running clock."
  8614. (interactive)
  8615. (unless (marker-buffer org-clock-marker)
  8616. (error "No running clock"))
  8617. (let ((marker (make-marker)) (col (current-column)) newhead)
  8618. (org-with-remote-undo (marker-buffer org-clock-marker)
  8619. (with-current-buffer (marker-buffer org-clock-marker)
  8620. (save-excursion
  8621. (save-restriction
  8622. (widen)
  8623. (goto-char org-clock-marker)
  8624. (org-back-to-heading t)
  8625. (move-marker marker (point))
  8626. (org-clock-out)
  8627. (setq newhead (org-get-heading))))))
  8628. (org-agenda-change-all-lines newhead marker)
  8629. (move-marker marker nil)
  8630. (org-move-to-column col)
  8631. (org-agenda-unmark-clocking-task)))
  8632. (defun org-agenda-clock-cancel (&optional arg)
  8633. "Cancel the currently running clock."
  8634. (interactive "P")
  8635. (unless (marker-buffer org-clock-marker)
  8636. (user-error "No running clock"))
  8637. (org-with-remote-undo (marker-buffer org-clock-marker)
  8638. (org-clock-cancel)))
  8639. (defun org-agenda-clock-goto ()
  8640. "Jump to the currently clocked in task within the agenda.
  8641. If the currently clocked in task is not listed in the agenda
  8642. buffer, display it in another window."
  8643. (interactive)
  8644. (let (pos)
  8645. (mapc (lambda (o)
  8646. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8647. (setq pos (overlay-start o))))
  8648. (overlays-in (point-min) (point-max)))
  8649. (cond (pos (goto-char pos))
  8650. ;; If the currently clocked entry is not in the agenda
  8651. ;; buffer, we visit it in another window:
  8652. (org-clock-current-task
  8653. (org-switch-to-buffer-other-window (org-clock-goto)))
  8654. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8655. (defun org-agenda-diary-entry-in-org-file ()
  8656. "Make a diary entry in the file `org-agenda-diary-file'."
  8657. (let (d1 d2 char (text "") dp1 dp2)
  8658. (if (equal (buffer-name) "*Calendar*")
  8659. (setq d1 (calendar-cursor-to-date t)
  8660. d2 (car calendar-mark-ring))
  8661. (setq dp1 (get-text-property (point-at-bol) 'day))
  8662. (unless dp1 (user-error "No date defined in current line"))
  8663. (setq d1 (calendar-gregorian-from-absolute dp1)
  8664. d2 (and (ignore-errors (mark))
  8665. (save-excursion
  8666. (goto-char (mark))
  8667. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8668. (calendar-gregorian-from-absolute dp2))))
  8669. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8670. (setq char (read-char-exclusive))
  8671. (cond
  8672. ((equal char ?d)
  8673. (setq text (read-string "Day entry: "))
  8674. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8675. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8676. ((equal char ?a)
  8677. (setq d1 (list (car d1) (nth 1 d1)
  8678. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8679. (nth 2 d1))))
  8680. (setq text (read-string "Anniversary (use %d to show years): "))
  8681. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8682. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8683. ((equal char ?b)
  8684. (setq text (read-string "Block entry: "))
  8685. (unless (and d1 d2 (not (equal d1 d2)))
  8686. (user-error "No block of days selected"))
  8687. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8688. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8689. ((equal char ?j)
  8690. (org-switch-to-buffer-other-window
  8691. (find-file-noselect org-agenda-diary-file))
  8692. (require 'org-datetree)
  8693. (org-datetree-find-date-create d1)
  8694. (org-reveal t))
  8695. (t (user-error "Invalid selection character `%c'" char)))))
  8696. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8697. "Where in `org-agenda-diary-file' should new entries be added?
  8698. Valid values:
  8699. date-tree in the date tree, as child of the date
  8700. top-level as top-level entries at the end of the file."
  8701. :group 'org-agenda
  8702. :type '(choice
  8703. (const :tag "in a date tree" date-tree)
  8704. (const :tag "as top level at end of file" top-level)))
  8705. (defcustom org-agenda-insert-diary-extract-time nil
  8706. "Non-nil means extract any time specification from the diary entry."
  8707. :group 'org-agenda
  8708. :version "24.1"
  8709. :type 'boolean)
  8710. (defcustom org-agenda-bulk-mark-char ">"
  8711. "A single-character string to be used as the bulk mark."
  8712. :group 'org-agenda
  8713. :version "24.1"
  8714. :type 'string)
  8715. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8716. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8717. If TEXT is not empty, it will become the headline of the new entry, and
  8718. the resulting entry will not be shown. When TEXT is empty, switch to
  8719. `org-agenda-diary-file' and let the user finish the entry there."
  8720. (let ((cw (current-window-configuration)))
  8721. (org-switch-to-buffer-other-window
  8722. (find-file-noselect org-agenda-diary-file))
  8723. (widen)
  8724. (goto-char (point-min))
  8725. (cond
  8726. ((eq type 'anniversary)
  8727. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8728. (progn
  8729. (or (org-at-heading-p t)
  8730. (progn
  8731. (outline-next-heading)
  8732. (insert "* Anniversaries\n\n")
  8733. (beginning-of-line -1)))))
  8734. (outline-next-heading)
  8735. (org-back-over-empty-lines)
  8736. (backward-char 1)
  8737. (insert "\n")
  8738. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8739. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8740. ((eq type 'day)
  8741. (let ((org-prefix-has-time t)
  8742. (org-agenda-time-leading-zero t)
  8743. fmt time time2)
  8744. (if org-agenda-insert-diary-extract-time
  8745. ;; Use org-agenda-format-item to parse text for a time-range and
  8746. ;; remove it. FIXME: This is a hack, we should refactor
  8747. ;; that function to make time extraction available separately
  8748. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8749. time (get-text-property 0 'time fmt)
  8750. time2 (if (> (length time) 0)
  8751. ;; split-string removes trailing ...... if
  8752. ;; no end time given. First space
  8753. ;; separates time from date.
  8754. (concat " " (car (split-string time "\\.")))
  8755. nil)
  8756. text (get-text-property 0 'txt fmt)))
  8757. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8758. (org-agenda-insert-diary-as-top-level text)
  8759. (require 'org-datetree)
  8760. (org-datetree-find-date-create d1)
  8761. (org-agenda-insert-diary-make-new-entry text))
  8762. (org-insert-time-stamp (org-time-from-absolute
  8763. (calendar-absolute-from-gregorian d1))
  8764. nil nil nil nil time2))
  8765. (end-of-line 0))
  8766. ((eq type 'block)
  8767. (if (> (calendar-absolute-from-gregorian d1)
  8768. (calendar-absolute-from-gregorian d2))
  8769. (setq d1 (prog1 d2 (setq d2 d1))))
  8770. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8771. (org-agenda-insert-diary-as-top-level text)
  8772. (require 'org-datetree)
  8773. (org-datetree-find-date-create d1)
  8774. (org-agenda-insert-diary-make-new-entry text))
  8775. (org-insert-time-stamp (org-time-from-absolute
  8776. (calendar-absolute-from-gregorian d1)))
  8777. (insert "--")
  8778. (org-insert-time-stamp (org-time-from-absolute
  8779. (calendar-absolute-from-gregorian d2)))
  8780. (end-of-line 0)))
  8781. (if (string-match "\\S-" text)
  8782. (progn
  8783. (set-window-configuration cw)
  8784. (message "%s entry added to %s"
  8785. (capitalize (symbol-name type))
  8786. (abbreviate-file-name org-agenda-diary-file)))
  8787. (org-reveal t)
  8788. (message "Please finish entry here"))))
  8789. (defun org-agenda-insert-diary-as-top-level (text)
  8790. "Make new entry as a top-level entry at the end of the file.
  8791. Add TEXT as headline, and position the cursor in the second line so that
  8792. a timestamp can be added there."
  8793. (widen)
  8794. (goto-char (point-max))
  8795. (or (bolp) (insert "\n"))
  8796. (insert "* " text "\n")
  8797. (if org-adapt-indentation (org-indent-to-column 2)))
  8798. (defun org-agenda-insert-diary-make-new-entry (text)
  8799. "Make new entry as last child of current entry.
  8800. Add TEXT as headline, and position the cursor in the second line so that
  8801. a timestamp can be added there."
  8802. (let ((org-show-following-heading t)
  8803. (org-show-siblings t)
  8804. (org-show-hierarchy-above t)
  8805. (org-show-entry-below t)
  8806. col)
  8807. (outline-next-heading)
  8808. (org-back-over-empty-lines)
  8809. (or (looking-at "[ \t]*$")
  8810. (progn (insert "\n") (backward-char 1)))
  8811. (org-insert-heading nil t)
  8812. (org-do-demote)
  8813. (setq col (current-column))
  8814. (insert text "\n")
  8815. (if org-adapt-indentation (org-indent-to-column col))
  8816. (let ((org-show-following-heading t)
  8817. (org-show-siblings t)
  8818. (org-show-hierarchy-above t)
  8819. (org-show-entry-below t))
  8820. (org-show-context))))
  8821. (defun org-agenda-diary-entry ()
  8822. "Make a diary entry, like the `i' command from the calendar.
  8823. All the standard commands work: block, weekly etc.
  8824. When `org-agenda-diary-file' points to a file,
  8825. `org-agenda-diary-entry-in-org-file' is called instead to create
  8826. entries in that Org-mode file."
  8827. (interactive)
  8828. (if (not (eq org-agenda-diary-file 'diary-file))
  8829. (org-agenda-diary-entry-in-org-file)
  8830. (require 'diary-lib)
  8831. (let* ((char (progn
  8832. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8833. (read-char-exclusive)))
  8834. (cmd (cdr (assoc char
  8835. '((?d . insert-diary-entry)
  8836. (?w . insert-weekly-diary-entry)
  8837. (?m . insert-monthly-diary-entry)
  8838. (?y . insert-yearly-diary-entry)
  8839. (?a . insert-anniversary-diary-entry)
  8840. (?b . insert-block-diary-entry)
  8841. (?c . insert-cyclic-diary-entry)))))
  8842. (oldf (symbol-function 'calendar-cursor-to-date))
  8843. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8844. (point (point))
  8845. (mark (or (mark t) (point))))
  8846. (unless cmd
  8847. (user-error "No command associated with <%c>" char))
  8848. (unless (and (get-text-property point 'day)
  8849. (or (not (equal ?b char))
  8850. (get-text-property mark 'day)))
  8851. (user-error "Don't know which date to use for diary entry"))
  8852. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8853. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8854. (let ((calendar-mark-ring
  8855. (list (calendar-gregorian-from-absolute
  8856. (or (get-text-property mark 'day)
  8857. (get-text-property point 'day))))))
  8858. (unwind-protect
  8859. (progn
  8860. (fset 'calendar-cursor-to-date
  8861. (lambda (&optional error dummy)
  8862. (calendar-gregorian-from-absolute
  8863. (get-text-property point 'day))))
  8864. (call-interactively cmd))
  8865. (fset 'calendar-cursor-to-date oldf))))))
  8866. (defun org-agenda-execute-calendar-command (cmd)
  8867. "Execute a calendar command from the agenda with date from cursor."
  8868. (org-agenda-check-type t 'agenda 'timeline)
  8869. (require 'diary-lib)
  8870. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8871. (user-error "Don't know which date to use for the calendar command"))
  8872. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8873. (point (point))
  8874. (date (calendar-gregorian-from-absolute
  8875. (get-text-property point 'day)))
  8876. ;; the following 2 vars are needed in the calendar
  8877. (displayed-month (car date))
  8878. (displayed-year (nth 2 date)))
  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-phases-of-moon ()
  8888. "Display the phases of the moon for the 3 months around the cursor date."
  8889. (interactive)
  8890. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8891. (defun org-agenda-holidays ()
  8892. "Display the holidays for the 3 months around the cursor date."
  8893. (interactive)
  8894. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8895. (defvar calendar-longitude) ; defined in calendar.el
  8896. (defvar calendar-latitude) ; defined in calendar.el
  8897. (defvar calendar-location-name) ; defined in calendar.el
  8898. (defun org-agenda-sunrise-sunset (arg)
  8899. "Display sunrise and sunset for the cursor date.
  8900. Latitude and longitude can be specified with the variables
  8901. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8902. argument, latitude and longitude will be prompted for."
  8903. (interactive "P")
  8904. (require 'solar)
  8905. (let ((calendar-longitude (if arg nil calendar-longitude))
  8906. (calendar-latitude (if arg nil calendar-latitude))
  8907. (calendar-location-name
  8908. (if arg "the given coordinates" calendar-location-name)))
  8909. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8910. (defun org-agenda-goto-calendar ()
  8911. "Open the Emacs calendar with the date at the cursor."
  8912. (interactive)
  8913. (org-agenda-check-type t 'agenda 'timeline)
  8914. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8915. (user-error "Don't know which date to open in calendar")))
  8916. (date (calendar-gregorian-from-absolute day))
  8917. (calendar-move-hook nil)
  8918. (calendar-view-holidays-initially-flag nil)
  8919. (calendar-view-diary-initially-flag nil))
  8920. (calendar)
  8921. (calendar-goto-date date)))
  8922. ;;;###autoload
  8923. (defun org-calendar-goto-agenda ()
  8924. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8925. This is a command that has to be installed in `calendar-mode-map'."
  8926. (interactive)
  8927. (org-agenda-list nil (calendar-absolute-from-gregorian
  8928. (calendar-cursor-to-date))
  8929. nil))
  8930. (defun org-agenda-convert-date ()
  8931. (interactive)
  8932. (org-agenda-check-type t 'agenda 'timeline)
  8933. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8934. date s)
  8935. (unless day
  8936. (user-error "Don't know which date to convert"))
  8937. (setq date (calendar-gregorian-from-absolute day))
  8938. (setq s (concat
  8939. "Gregorian: " (calendar-date-string date) "\n"
  8940. "ISO: " (calendar-iso-date-string date) "\n"
  8941. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8942. "Julian: " (calendar-julian-date-string date) "\n"
  8943. "Astron. JD: " (calendar-astro-date-string date)
  8944. " (Julian date number at noon UTC)\n"
  8945. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8946. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8947. "French: " (calendar-french-date-string date) "\n"
  8948. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8949. "Mayan: " (calendar-mayan-date-string date) "\n"
  8950. "Coptic: " (calendar-coptic-date-string date) "\n"
  8951. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8952. "Persian: " (calendar-persian-date-string date) "\n"
  8953. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8954. (with-output-to-temp-buffer "*Dates*"
  8955. (princ s))
  8956. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8957. ;;; Bulk commands
  8958. (defun org-agenda-bulk-marked-p ()
  8959. (eq (get-char-property (point-at-bol) 'type)
  8960. 'org-marked-entry-overlay))
  8961. (defun org-agenda-bulk-mark (&optional arg)
  8962. "Mark the entry at point for future bulk action."
  8963. (interactive "p")
  8964. (dotimes (i (or arg 1))
  8965. (unless (org-get-at-bol 'org-agenda-diary-link)
  8966. (let* ((m (org-get-at-bol 'org-hd-marker))
  8967. ov)
  8968. (unless (org-agenda-bulk-marked-p)
  8969. (unless m (user-error "Nothing to mark at point"))
  8970. (push m org-agenda-bulk-marked-entries)
  8971. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8972. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8973. (org-get-todo-face "TODO")
  8974. 'evaporate)
  8975. (overlay-put ov 'type 'org-marked-entry-overlay))
  8976. (end-of-line 1)
  8977. (or (ignore-errors
  8978. (goto-char (next-single-property-change (point) 'txt)))
  8979. (beginning-of-line 2))
  8980. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8981. (beginning-of-line 2))
  8982. (message "%d entries marked for bulk action"
  8983. (length org-agenda-bulk-marked-entries))))))
  8984. (defun org-agenda-bulk-mark-all ()
  8985. "Mark all entries for future agenda bulk action."
  8986. (interactive)
  8987. (org-agenda-bulk-mark-regexp "."))
  8988. (defun org-agenda-bulk-mark-regexp (regexp)
  8989. "Mark entries matching REGEXP for future agenda bulk action."
  8990. (interactive "sMark entries matching regexp: ")
  8991. (let ((entries-marked 0) txt-at-point)
  8992. (save-excursion
  8993. (goto-char (point-min))
  8994. (goto-char (next-single-property-change (point) 'txt))
  8995. (while (and (re-search-forward regexp nil t)
  8996. (setq txt-at-point (get-text-property (point) 'txt)))
  8997. (when (string-match regexp txt-at-point)
  8998. (setq entries-marked (1+ entries-marked))
  8999. (call-interactively 'org-agenda-bulk-mark))))
  9000. (if (not entries-marked)
  9001. (message "No entry matching this regexp."))))
  9002. (defun org-agenda-bulk-unmark (&optional arg)
  9003. "Unmark the entry at point for future bulk action."
  9004. (interactive "P")
  9005. (if arg
  9006. (org-agenda-bulk-unmark-all)
  9007. (cond ((org-agenda-bulk-marked-p)
  9008. (org-agenda-bulk-remove-overlays
  9009. (point-at-bol) (+ 2 (point-at-bol)))
  9010. (setq org-agenda-bulk-marked-entries
  9011. (delete (org-get-at-bol 'org-hd-marker)
  9012. org-agenda-bulk-marked-entries))
  9013. (end-of-line 1)
  9014. (or (ignore-errors
  9015. (goto-char (next-single-property-change (point) 'txt)))
  9016. (beginning-of-line 2))
  9017. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9018. (beginning-of-line 2))
  9019. (message "%d entries left marked for bulk action"
  9020. (length org-agenda-bulk-marked-entries)))
  9021. (t (message "No entry to unmark here")))))
  9022. (defun org-agenda-bulk-toggle-all ()
  9023. "Toggle all marks for bulk action."
  9024. (interactive)
  9025. (save-excursion
  9026. (goto-char (point-min))
  9027. (while (ignore-errors
  9028. (goto-char (next-single-property-change (point) 'txt)))
  9029. (org-agenda-bulk-toggle))))
  9030. (defun org-agenda-bulk-toggle ()
  9031. "Toggle the mark at point for bulk action."
  9032. (interactive)
  9033. (if (org-agenda-bulk-marked-p)
  9034. (org-agenda-bulk-unmark)
  9035. (org-agenda-bulk-mark)))
  9036. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9037. "Remove the mark overlays between BEG and END in the agenda buffer.
  9038. BEG and END default to the buffer limits.
  9039. This only removes the overlays, it does not remove the markers
  9040. from the list in `org-agenda-bulk-marked-entries'."
  9041. (interactive)
  9042. (mapc (lambda (ov)
  9043. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9044. (delete-overlay ov)))
  9045. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9046. (defun org-agenda-bulk-unmark-all ()
  9047. "Remove all marks in the agenda buffer.
  9048. This will remove the markers and the overlays."
  9049. (interactive)
  9050. (if (null org-agenda-bulk-marked-entries)
  9051. (message "No entry to unmark")
  9052. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9053. (setq org-agenda-bulk-marked-entries nil)
  9054. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9055. (defcustom org-agenda-persistent-marks nil
  9056. "Non-nil means marked items will stay marked after a bulk action.
  9057. You can toggle this interactively by typing `p' when prompted for a
  9058. bulk action."
  9059. :group 'org-agenda
  9060. :version "24.1"
  9061. :type 'boolean)
  9062. (defun org-agenda-bulk-action (&optional arg)
  9063. "Execute an remote-editing action on all marked entries.
  9064. The prefix arg is passed through to the command if possible."
  9065. (interactive "P")
  9066. ;; Make sure we have markers, and only valid ones
  9067. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9068. (mapc
  9069. (lambda (m)
  9070. (unless (and (markerp m)
  9071. (marker-buffer m)
  9072. (buffer-live-p (marker-buffer m))
  9073. (marker-position m))
  9074. (user-error "Marker %s for bulk command is invalid" m)))
  9075. org-agenda-bulk-marked-entries)
  9076. ;; Prompt for the bulk command
  9077. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9078. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9079. "[S]catter [f]unction "
  9080. (when org-agenda-bulk-custom-functions
  9081. (concat " Custom: ["
  9082. (mapconcat (lambda(f) (char-to-string (car f)))
  9083. org-agenda-bulk-custom-functions "")
  9084. "]"))))
  9085. (catch 'exit
  9086. (let* ((action (read-char-exclusive))
  9087. (org-log-refile (if org-log-refile 'time nil))
  9088. (entries (reverse org-agenda-bulk-marked-entries))
  9089. (org-overriding-default-time
  9090. (if (get-text-property (point) 'org-agenda-date-header)
  9091. (org-get-cursor-date)))
  9092. redo-at-end
  9093. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9094. (cond
  9095. ((equal action ?p)
  9096. (let ((org-agenda-persistent-marks
  9097. (not org-agenda-persistent-marks)))
  9098. (org-agenda-bulk-action)
  9099. (throw 'exit nil)))
  9100. ((equal action ?$)
  9101. (setq cmd '(org-agenda-archive)))
  9102. ((equal action ?A)
  9103. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9104. ((member action '(?r ?w))
  9105. (setq rfloc (org-refile-get-location
  9106. "Refile to"
  9107. (marker-buffer (car entries))
  9108. org-refile-allow-creating-parent-nodes))
  9109. (if (nth 3 rfloc)
  9110. (setcar (nthcdr 3 rfloc)
  9111. (move-marker (make-marker) (nth 3 rfloc)
  9112. (or (get-file-buffer (nth 1 rfloc))
  9113. (find-buffer-visiting (nth 1 rfloc))
  9114. (error "This should not happen")))))
  9115. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9116. redo-at-end t))
  9117. ((equal action ?t)
  9118. (setq state (org-icompleting-read
  9119. "Todo state: "
  9120. (with-current-buffer (marker-buffer (car entries))
  9121. (mapcar 'list org-todo-keywords-1))))
  9122. (setq cmd `(let ((org-inhibit-blocking t)
  9123. (org-inhibit-logging 'note))
  9124. (org-agenda-todo ,state))))
  9125. ((memq action '(?- ?+))
  9126. (setq tag (org-icompleting-read
  9127. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9128. (with-current-buffer (marker-buffer (car entries))
  9129. (delq nil
  9130. (mapcar (lambda (x)
  9131. (if (stringp (car x)) x)) org-tag-alist)))))
  9132. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9133. ((memq action '(?s ?d))
  9134. (let* ((time
  9135. (unless arg
  9136. (org-read-date
  9137. nil nil nil
  9138. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9139. org-overriding-default-time)))
  9140. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9141. (setq cmd `(eval '(,c1 arg ,time)))))
  9142. ((equal action ?S)
  9143. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9144. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9145. (let ((days (read-number
  9146. (format "Scatter tasks across how many %sdays: "
  9147. (if arg "week" "")) 7)))
  9148. (setq cmd
  9149. `(let ((distance (1+ (random ,days))))
  9150. (if arg
  9151. (let ((dist distance)
  9152. (day-of-week
  9153. (calendar-day-of-week
  9154. (calendar-gregorian-from-absolute (org-today)))))
  9155. (dotimes (i (1+ dist))
  9156. (while (member day-of-week org-agenda-weekend-days)
  9157. (incf distance)
  9158. (incf day-of-week)
  9159. (if (= day-of-week 7)
  9160. (setq day-of-week 0)))
  9161. (incf day-of-week)
  9162. (if (= day-of-week 7)
  9163. (setq day-of-week 0)))))
  9164. ;; silently fail when try to replan a sexp entry
  9165. (condition-case nil
  9166. (let* ((date (calendar-gregorian-from-absolute
  9167. (+ (org-today) distance)))
  9168. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9169. (nth 2 date))))
  9170. (org-agenda-schedule nil time))
  9171. (error nil)))))))
  9172. ((assoc action org-agenda-bulk-custom-functions)
  9173. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9174. redo-at-end t))
  9175. ((equal action ?f)
  9176. (setq cmd (list (intern
  9177. (org-icompleting-read "Function: "
  9178. obarray 'fboundp t nil nil)))))
  9179. (t (user-error "Invalid bulk action")))
  9180. ;; Sort the markers, to make sure that parents are handled before children
  9181. (setq entries (sort entries
  9182. (lambda (a b)
  9183. (cond
  9184. ((equal (marker-buffer a) (marker-buffer b))
  9185. (< (marker-position a) (marker-position b)))
  9186. (t
  9187. (string< (buffer-name (marker-buffer a))
  9188. (buffer-name (marker-buffer b))))))))
  9189. ;; Now loop over all markers and apply cmd
  9190. (while (setq e (pop entries))
  9191. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9192. (if (not pos)
  9193. (progn (message "Skipping removed entry at %s" e)
  9194. (setq cntskip (1+ cntskip)))
  9195. (goto-char pos)
  9196. (let (org-loop-over-headlines-in-active-region)
  9197. (eval cmd))
  9198. (setq cnt (1+ cnt))))
  9199. (when redo-at-end (org-agenda-redo))
  9200. (unless org-agenda-persistent-marks
  9201. (org-agenda-bulk-unmark-all))
  9202. (message "Acted on %d entries%s%s"
  9203. cnt
  9204. (if (= cntskip 0)
  9205. ""
  9206. (format ", skipped %d (disappeared before their turn)"
  9207. cntskip))
  9208. (if (not org-agenda-persistent-marks)
  9209. "" " (kept marked)"))))))
  9210. (defun org-agenda-capture (&optional with-time)
  9211. "Call `org-capture' with the date at point.
  9212. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9213. current HH:MM time."
  9214. (interactive "P")
  9215. (if (not (eq major-mode 'org-agenda-mode))
  9216. (user-error "You cannot do this outside of agenda buffers")
  9217. (let ((org-overriding-default-time
  9218. (org-get-cursor-date (equal with-time 1))))
  9219. (call-interactively 'org-capture))))
  9220. ;;; Dragging agenda lines forward/backward
  9221. (defun org-agenda-drag-line-forward (arg)
  9222. "Drag an agenda line forward by ARG lines."
  9223. (interactive "p")
  9224. (let ((inhibit-read-only t) lst)
  9225. (if (save-excursion
  9226. (dotimes (n arg)
  9227. (beginning-of-line 2)
  9228. (push (not (get-text-property (point) 'txt)) lst))
  9229. (delq nil lst))
  9230. (message "Cannot move line forward")
  9231. (org-drag-line-forward arg))))
  9232. (defun org-agenda-drag-line-backward (arg)
  9233. "Drag an agenda line backward by ARG lines."
  9234. (interactive "p")
  9235. (let ((inhibit-read-only t) lst)
  9236. (if (save-excursion
  9237. (dotimes (n arg)
  9238. (beginning-of-line 0)
  9239. (push (not (get-text-property (point) 'txt)) lst))
  9240. (delq nil lst))
  9241. (message "Cannot move line backward")
  9242. (org-drag-line-backward arg))))
  9243. ;;; Flagging notes
  9244. (defun org-agenda-show-the-flagging-note ()
  9245. "Display the flagging note in the other window.
  9246. When called a second time in direct sequence, offer to remove the FLAGGING
  9247. tag and (if present) the flagging note."
  9248. (interactive)
  9249. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9250. (win (selected-window))
  9251. note heading newhead)
  9252. (unless hdmarker
  9253. (user-error "No linked entry at point"))
  9254. (if (and (eq this-command last-command)
  9255. (y-or-n-p "Unflag and remove any flagging note? "))
  9256. (progn
  9257. (org-agenda-remove-flag hdmarker)
  9258. (let ((win (get-buffer-window "*Flagging Note*")))
  9259. (and win (delete-window win)))
  9260. (message "Entry unflagged"))
  9261. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9262. (unless note
  9263. (user-error "No flagging note"))
  9264. (org-kill-new note)
  9265. (org-switch-to-buffer-other-window "*Flagging Note*")
  9266. (erase-buffer)
  9267. (insert note)
  9268. (goto-char (point-min))
  9269. (while (re-search-forward "\\\\n" nil t)
  9270. (replace-match "\n" t t))
  9271. (goto-char (point-min))
  9272. (select-window win)
  9273. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9274. (defun org-agenda-remove-flag (marker)
  9275. "Remove the FLAGGED tag and any flagging note in the entry."
  9276. (let (newhead)
  9277. (org-with-point-at marker
  9278. (org-toggle-tag "FLAGGED" 'off)
  9279. (org-entry-delete nil "THEFLAGGINGNOTE")
  9280. (setq newhead (org-get-heading)))
  9281. (org-agenda-change-all-lines newhead marker)
  9282. (message "Entry unflagged")))
  9283. (defun org-agenda-get-any-marker (&optional pos)
  9284. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9285. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9286. ;;; Appointment reminders
  9287. (defvar appt-time-msg-list) ; defined in appt.el
  9288. ;;;###autoload
  9289. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9290. "Activate appointments found in `org-agenda-files'.
  9291. With a \\[universal-argument] prefix, refresh the list of
  9292. appointments.
  9293. If FILTER is t, interactively prompt the user for a regular
  9294. expression, and filter out entries that don't match it.
  9295. If FILTER is a string, use this string as a regular expression
  9296. for filtering entries out.
  9297. If FILTER is a function, filter out entries against which
  9298. calling the function returns nil. This function takes one
  9299. argument: an entry from `org-agenda-get-day-entries'.
  9300. FILTER can also be an alist with the car of each cell being
  9301. either 'headline or 'category. For example:
  9302. '((headline \"IMPORTANT\")
  9303. (category \"Work\"))
  9304. will only add headlines containing IMPORTANT or headlines
  9305. belonging to the \"Work\" category.
  9306. ARGS are symbols indicating what kind of entries to consider.
  9307. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9308. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9309. and :timestamp entries. See the docstring of `org-diary' for
  9310. details and examples.
  9311. If an entry has a APPT_WARNTIME property, its value will be used
  9312. to override `appt-message-warning-time'."
  9313. (interactive "P")
  9314. (if refresh (setq appt-time-msg-list nil))
  9315. (if (eq filter t)
  9316. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9317. (let* ((cnt 0) ; count added events
  9318. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9319. (org-agenda-new-buffers nil)
  9320. (org-deadline-warning-days 0)
  9321. ;; Do not use `org-today' here because appt only takes
  9322. ;; time and without date as argument, so it may pass wrong
  9323. ;; information otherwise
  9324. (today (org-date-to-gregorian
  9325. (time-to-days (current-time))))
  9326. (org-agenda-restrict nil)
  9327. (files (org-agenda-files 'unrestricted)) entries file
  9328. (org-agenda-buffer nil))
  9329. ;; Get all entries which may contain an appt
  9330. (org-agenda-prepare-buffers files)
  9331. (while (setq file (pop files))
  9332. (setq entries
  9333. (delq nil
  9334. (append entries
  9335. (apply 'org-agenda-get-day-entries
  9336. file today scope)))))
  9337. ;; Map thru entries and find if we should filter them out
  9338. (mapc
  9339. (lambda(x)
  9340. (let* ((evt (org-trim
  9341. (replace-regexp-in-string
  9342. org-bracket-link-regexp "\\3"
  9343. (or (get-text-property 1 'txt x) ""))))
  9344. (cat (get-text-property 1 'org-category x))
  9345. (tod (get-text-property 1 'time-of-day x))
  9346. (ok (or (null filter)
  9347. (and (stringp filter) (string-match filter evt))
  9348. (and (functionp filter) (funcall filter x))
  9349. (and (listp filter)
  9350. (let ((cat-filter (cadr (assoc 'category filter)))
  9351. (evt-filter (cadr (assoc 'headline filter))))
  9352. (or (and (stringp cat-filter)
  9353. (string-match cat-filter cat))
  9354. (and (stringp evt-filter)
  9355. (string-match evt-filter evt)))))))
  9356. (wrn (get-text-property 1 'warntime x)))
  9357. ;; FIXME: Shall we remove text-properties for the appt text?
  9358. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9359. (when (and ok tod)
  9360. (setq tod (concat "00" (number-to-string tod))
  9361. tod (when (string-match
  9362. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9363. (concat (match-string 1 tod) ":"
  9364. (match-string 2 tod))))
  9365. (if (version< emacs-version "23.3")
  9366. (appt-add tod evt)
  9367. (appt-add tod evt wrn))
  9368. (setq cnt (1+ cnt))))) entries)
  9369. (org-release-buffers org-agenda-new-buffers)
  9370. (if (eq cnt 0)
  9371. (message "No event to add")
  9372. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9373. (defun org-agenda-todayp (date)
  9374. "Does DATE mean today, when considering `org-extend-today-until'?"
  9375. (let ((today (org-today))
  9376. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9377. date)))
  9378. (eq date today)))
  9379. (defun org-agenda-todo-yesterday (&optional arg)
  9380. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9381. (interactive "P")
  9382. (let* ((hour (third (decode-time
  9383. (org-current-time))))
  9384. (org-extend-today-until (1+ hour)))
  9385. (org-agenda-todo arg)))
  9386. (provide 'org-agenda)
  9387. ;;; org-agenda.el ends here