org-agenda.el 389 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2014 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-columns-remove-overlays "org-colview" ())
  64. (declare-function org-datetree-find-date-create "org-datetree"
  65. (date &optional keep-restriction))
  66. (declare-function org-columns-quit "org-colview" ())
  67. (declare-function diary-date-display-form "diary-lib" (&optional type))
  68. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  69. (declare-function org-habit-insert-consistency-graphs
  70. "org-habit" (&optional line))
  71. (declare-function org-is-habit-p "org-habit" (&optional pom))
  72. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  73. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  74. (declare-function org-pop-to-buffer-same-window "org-compat"
  75. (&optional buffer-or-name norecord label))
  76. (declare-function org-agenda-columns "org-colview" ())
  77. (declare-function org-add-archive-files "org-archive" (files))
  78. (declare-function org-capture "org-capture" (&optional goto keys))
  79. (defvar calendar-mode-map) ; defined in calendar.el
  80. (defvar org-clock-current-task nil) ; defined in org-clock.el
  81. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  82. (defvar org-habit-show-habits) ; defined in org-habit.el
  83. (defvar org-habit-show-habits-only-for-today)
  84. (defvar org-habit-show-all-today)
  85. ;; Defined somewhere in this file, but used before definition.
  86. (defvar org-agenda-buffer-name "*Org Agenda*")
  87. (defvar org-agenda-overriding-header nil)
  88. (defvar org-agenda-title-append nil)
  89. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  90. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  91. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  92. (defvar org-agenda-undo-list nil
  93. "List of undoable operations in the agenda since last refresh.")
  94. (defvar org-agenda-pending-undo-list nil
  95. "In a series of undo commands, this is the list of remaining undo items.")
  96. (defcustom org-agenda-confirm-kill 1
  97. "When set, remote killing from the agenda buffer needs confirmation.
  98. When t, a confirmation is always needed. When a number N, confirmation is
  99. only needed when the text to be killed contains more than N non-white lines."
  100. :group 'org-agenda
  101. :type '(choice
  102. (const :tag "Never" nil)
  103. (const :tag "Always" t)
  104. (integer :tag "When more than N lines")))
  105. (defcustom org-agenda-compact-blocks nil
  106. "Non-nil means make the block agenda more compact.
  107. This is done globally by leaving out lines like the agenda span
  108. name and week number or the separator lines."
  109. :group 'org-agenda
  110. :type 'boolean)
  111. (defcustom org-agenda-block-separator ?=
  112. "The separator between blocks in the agenda.
  113. If this is a string, it will be used as the separator, with a newline added.
  114. If it is a character, it will be repeated to fill the window width.
  115. If nil the separator is disabled. In `org-agenda-custom-commands' this
  116. addresses the separator between the current and the previous block."
  117. :group 'org-agenda
  118. :type '(choice
  119. (const :tag "Disabled" nil)
  120. (character)
  121. (string)))
  122. (defgroup org-agenda-export nil
  123. "Options concerning exporting agenda views in Org-mode."
  124. :tag "Org Agenda Export"
  125. :group 'org-agenda)
  126. (defcustom org-agenda-with-colors t
  127. "Non-nil means use colors in agenda views."
  128. :group 'org-agenda-export
  129. :type 'boolean)
  130. (defcustom org-agenda-exporter-settings nil
  131. "Alist of variable/value pairs that should be active during agenda export.
  132. This is a good place to set options for ps-print and for htmlize.
  133. Note that the way this is implemented, the values will be evaluated
  134. before assigned to the variables. So make sure to quote values you do
  135. *not* want evaluated, for example
  136. (setq org-agenda-exporter-settings
  137. '((ps-print-color-p 'black-white)))"
  138. :group 'org-agenda-export
  139. :type '(repeat
  140. (list
  141. (variable)
  142. (sexp :tag "Value"))))
  143. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  144. "Hook run in a temporary buffer before writing the agenda to an export file.
  145. A useful function for this hook is `org-agenda-add-entry-text'."
  146. :group 'org-agenda-export
  147. :type 'hook
  148. :options '(org-agenda-add-entry-text))
  149. (defcustom org-agenda-add-entry-text-maxlines 0
  150. "Maximum number of entry text lines to be added to agenda.
  151. This is only relevant when `org-agenda-add-entry-text' is part of
  152. `org-agenda-before-write-hook', which is the default.
  153. When this is 0, nothing will happen. When it is greater than 0, it
  154. specifies the maximum number of lines that will be added for each entry
  155. that is listed in the agenda view.
  156. Note that this variable is not used during display, only when exporting
  157. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  158. and `org-agenda-entry-text-maxlines'."
  159. :group 'org-agenda
  160. :type 'integer)
  161. (defcustom org-agenda-add-entry-text-descriptive-links t
  162. "Non-nil means export org-links as descriptive links in agenda added text.
  163. This variable applies to the text added to the agenda when
  164. `org-agenda-add-entry-text-maxlines' is larger than 0.
  165. When this variable nil, the URL will (also) be shown."
  166. :group 'org-agenda
  167. :type 'boolean)
  168. (defcustom org-agenda-export-html-style nil
  169. "The style specification for exported HTML Agenda files.
  170. If this variable contains a string, it will replace the default <style>
  171. section as produced by `htmlize'.
  172. Since there are different ways of setting style information, this variable
  173. needs to contain the full HTML structure to provide a style, including the
  174. surrounding HTML tags. The style specifications should include definitions
  175. the fonts used by the agenda, here is an example:
  176. <style type=\"text/css\">
  177. p { font-weight: normal; color: gray; }
  178. .org-agenda-structure {
  179. font-size: 110%;
  180. color: #003399;
  181. font-weight: 600;
  182. }
  183. .org-todo {
  184. color: #cc6666;
  185. font-weight: bold;
  186. }
  187. .org-agenda-done {
  188. color: #339933;
  189. }
  190. .org-done {
  191. color: #339933;
  192. }
  193. .title { text-align: center; }
  194. .todo, .deadline { color: red; }
  195. .done { color: green; }
  196. </style>
  197. or, if you want to keep the style in a file,
  198. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  199. As the value of this option simply gets inserted into the HTML <head> header,
  200. you can \"misuse\" it to also add other text to the header."
  201. :group 'org-agenda-export
  202. :group 'org-export-html
  203. :type '(choice
  204. (const nil)
  205. (string)))
  206. (defcustom org-agenda-persistent-filter nil
  207. "When set, keep filters from one agenda view to the next."
  208. :group 'org-agenda
  209. :type 'boolean)
  210. (defgroup org-agenda-custom-commands nil
  211. "Options concerning agenda views in Org-mode."
  212. :tag "Org Agenda Custom Commands"
  213. :group 'org-agenda)
  214. (defconst org-sorting-choice
  215. '(choice
  216. (const time-up) (const time-down)
  217. (const timestamp-up) (const timestamp-down)
  218. (const scheduled-up) (const scheduled-down)
  219. (const deadline-up) (const deadline-down)
  220. (const ts-up) (const ts-down)
  221. (const tsia-up) (const tsia-down)
  222. (const category-keep) (const category-up) (const category-down)
  223. (const tag-down) (const tag-up)
  224. (const priority-up) (const priority-down)
  225. (const todo-state-up) (const todo-state-down)
  226. (const effort-up) (const effort-down)
  227. (const habit-up) (const habit-down)
  228. (const alpha-up) (const alpha-down)
  229. (const user-defined-up) (const user-defined-down))
  230. "Sorting choices.")
  231. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  232. ;; the new variable `org-agenda-tag-filter-preset'.
  233. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  234. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  235. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  236. "List of types searched for when creating the daily/weekly agenda.
  237. This variable is a list of symbols that controls the types of
  238. items that appear in the daily/weekly agenda. Allowed symbols in this
  239. list are are
  240. :timestamp List items containing a date stamp or date range matching
  241. the selected date. This includes sexp entries in angular
  242. brackets.
  243. :sexp List entries resulting from plain diary-like sexps.
  244. :deadline List deadline due on that date. When the date is today,
  245. also list any deadlines past due, or due within
  246. `org-deadline-warning-days'. `:deadline' must appear before
  247. `:scheduled' if the setting of
  248. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  249. any effect.
  250. :deadline* Same as above, but only include the deadline if it has an
  251. hour specification as [h]h:mm.
  252. :scheduled List all items which are scheduled for the given date.
  253. The diary for *today* also contains items which were
  254. scheduled earlier and are not yet marked DONE.
  255. :scheduled* Same as above, but only include the scheduled item if it
  256. has an hour specification as [h]h:mm.
  257. By default, all four non-starred types are turned on.
  258. When :scheduled* or :deadline* are included, :schedule or :deadline
  259. will be ignored.
  260. Never set this variable globally using `setq', because then it
  261. will apply to all future agenda commands. Instead, bind it with
  262. `let' to scope it dynamically into the agenda-constructing
  263. command. A good way to set it is through options in
  264. `org-agenda-custom-commands'. For a more flexible (though
  265. somewhat less efficient) way of determining what is included in
  266. the daily/weekly agenda, see `org-agenda-skip-function'.")
  267. (defconst org-agenda-custom-commands-local-options
  268. `(repeat :tag "Local settings for this command. Remember to quote values"
  269. (choice :tag "Setting"
  270. (list :tag "Heading for this block"
  271. (const org-agenda-overriding-header)
  272. (string :tag "Headline"))
  273. (list :tag "Files to be searched"
  274. (const org-agenda-files)
  275. (list
  276. (const :format "" quote)
  277. (repeat (file))))
  278. (list :tag "Sorting strategy"
  279. (const org-agenda-sorting-strategy)
  280. (list
  281. (const :format "" quote)
  282. (repeat
  283. ,org-sorting-choice)))
  284. (list :tag "Prefix format"
  285. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  286. (string))
  287. (list :tag "Number of days in agenda"
  288. (const org-agenda-span)
  289. (choice (const :tag "Day" day)
  290. (const :tag "Week" week)
  291. (const :tag "Fortnight" fortnight)
  292. (const :tag "Month" month)
  293. (const :tag "Year" year)
  294. (integer :tag "Custom")))
  295. (list :tag "Fixed starting date"
  296. (const org-agenda-start-day)
  297. (string :value "2007-11-01"))
  298. (list :tag "Start on day of week"
  299. (const org-agenda-start-on-weekday)
  300. (choice :value 1
  301. (const :tag "Today" nil)
  302. (integer :tag "Weekday No.")))
  303. (list :tag "Include data from diary"
  304. (const org-agenda-include-diary)
  305. (boolean))
  306. (list :tag "Deadline Warning days"
  307. (const org-deadline-warning-days)
  308. (integer :value 1))
  309. (list :tag "Category filter preset"
  310. (const org-agenda-category-filter-preset)
  311. (list
  312. (const :format "" quote)
  313. (repeat
  314. (string :tag "+category or -category"))))
  315. (list :tag "Tags filter preset"
  316. (const org-agenda-tag-filter-preset)
  317. (list
  318. (const :format "" quote)
  319. (repeat
  320. (string :tag "+tag or -tag"))))
  321. (list :tag "Regexp filter preset"
  322. (const org-agenda-regexp-filter-preset)
  323. (list
  324. (const :format "" quote)
  325. (repeat
  326. (string :tag "+regexp or -regexp"))))
  327. (list :tag "Set daily/weekly entry types"
  328. (const org-agenda-entry-types)
  329. (list
  330. (const :format "" quote)
  331. (set :greedy t :value ,org-agenda-entry-types
  332. (const :deadline)
  333. (const :scheduled)
  334. (const :deadline*)
  335. (const :scheduled*)
  336. (const :timestamp)
  337. (const :sexp))))
  338. (list :tag "Standard skipping condition"
  339. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  340. (const org-agenda-skip-function)
  341. (list
  342. (const :format "" quote)
  343. (list
  344. (choice
  345. :tag "Skipping range"
  346. (const :tag "Skip entry" org-agenda-skip-entry-if)
  347. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  348. (repeat :inline t :tag "Conditions for skipping"
  349. (choice
  350. :tag "Condition type"
  351. (list :tag "Regexp matches" :inline t (const :format "" regexp) (regexp))
  352. (list :tag "Regexp does not match" :inline t (const :format "" notregexp) (regexp))
  353. (list :tag "TODO state is" :inline t
  354. (const todo)
  355. (choice
  356. (const :tag "any not-done state" todo)
  357. (const :tag "any done state" done)
  358. (const :tag "any state" any)
  359. (list :tag "Keyword list"
  360. (const :format "" quote)
  361. (repeat (string :tag "Keyword")))))
  362. (list :tag "TODO state is not" :inline t
  363. (const nottodo)
  364. (choice
  365. (const :tag "any not-done state" todo)
  366. (const :tag "any done state" done)
  367. (const :tag "any state" any)
  368. (list :tag "Keyword list"
  369. (const :format "" quote)
  370. (repeat (string :tag "Keyword")))))
  371. (const :tag "scheduled" scheduled)
  372. (const :tag "not scheduled" notscheduled)
  373. (const :tag "deadline" deadline)
  374. (const :tag "no deadline" notdeadline)
  375. (const :tag "timestamp" timestamp)
  376. (const :tag "no timestamp" nottimestamp))))))
  377. (list :tag "Non-standard skipping condition"
  378. :value (org-agenda-skip-function)
  379. (const org-agenda-skip-function)
  380. (sexp :tag "Function or form (quoted!)"))
  381. (list :tag "Any variable"
  382. (variable :tag "Variable")
  383. (sexp :tag "Value (sexp)"))))
  384. "Selection of examples for agenda command settings.
  385. This will be spliced into the custom type of
  386. `org-agenda-custom-commands'.")
  387. (defcustom org-agenda-custom-commands
  388. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  389. "Custom commands for the agenda.
  390. These commands will be offered on the splash screen displayed by the
  391. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  392. (key desc type match settings files)
  393. key The key (one or more characters as a string) to be associated
  394. with the command.
  395. desc A description of the command, when omitted or nil, a default
  396. description is built using MATCH.
  397. type The command type, any of the following symbols:
  398. agenda The daily/weekly agenda.
  399. todo Entries with a specific TODO keyword, in all agenda files.
  400. search Entries containing search words entry or headline.
  401. tags Tags/Property/TODO match in all agenda files.
  402. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  403. todo-tree Sparse tree of specific TODO keyword in *current* file.
  404. tags-tree Sparse tree with all tags matches in *current* file.
  405. occur-tree Occur sparse tree for *current* file.
  406. ... A user-defined function.
  407. match What to search for:
  408. - a single keyword for TODO keyword searches
  409. - a tags match expression for tags searches
  410. - a word search expression for text searches.
  411. - a regular expression for occur searches
  412. For all other commands, this should be the empty string.
  413. settings A list of option settings, similar to that in a let form, so like
  414. this: ((opt1 val1) (opt2 val2) ...). The values will be
  415. evaluated at the moment of execution, so quote them when needed.
  416. files A list of files file to write the produced agenda buffer to
  417. with the command `org-store-agenda-views'.
  418. If a file name ends in \".html\", an HTML version of the buffer
  419. is written out. If it ends in \".ps\", a postscript version is
  420. produced. Otherwise, only the plain text is written to the file.
  421. You can also define a set of commands, to create a composite agenda buffer.
  422. In this case, an entry looks like this:
  423. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  424. where
  425. desc A description string to be displayed in the dispatcher menu.
  426. cmd An agenda command, similar to the above. However, tree commands
  427. are not allowed, but instead you can get agenda and global todo list.
  428. So valid commands for a set are:
  429. (agenda \"\" settings)
  430. (alltodo \"\" settings)
  431. (stuck \"\" settings)
  432. (todo \"match\" settings files)
  433. (search \"match\" settings files)
  434. (tags \"match\" settings files)
  435. (tags-todo \"match\" settings files)
  436. Each command can carry a list of options, and another set of options can be
  437. given for the whole set of commands. Individual command options take
  438. precedence over the general options.
  439. When using several characters as key to a command, the first characters
  440. are prefix commands. For the dispatcher to display useful information, you
  441. should provide a description for the prefix, like
  442. (setq org-agenda-custom-commands
  443. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  444. (\"hl\" tags \"+HOME+Lisa\")
  445. (\"hp\" tags \"+HOME+Peter\")
  446. (\"hk\" tags \"+HOME+Kim\")))"
  447. :group 'org-agenda-custom-commands
  448. :type `(repeat
  449. (choice :value ("x" "Describe command here" tags "" nil)
  450. (list :tag "Single command"
  451. (string :tag "Access Key(s) ")
  452. (option (string :tag "Description"))
  453. (choice
  454. (const :tag "Agenda" agenda)
  455. (const :tag "TODO list" alltodo)
  456. (const :tag "Search words" search)
  457. (const :tag "Stuck projects" stuck)
  458. (const :tag "Tags/Property match (all agenda files)" tags)
  459. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  460. (const :tag "TODO keyword search (all agenda files)" todo)
  461. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  462. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  463. (const :tag "Occur tree (current buffer)" occur-tree)
  464. (sexp :tag "Other, user-defined function"))
  465. (string :tag "Match (only for some commands)")
  466. ,org-agenda-custom-commands-local-options
  467. (option (repeat :tag "Export" (file :tag "Export to"))))
  468. (list :tag "Command series, all agenda files"
  469. (string :tag "Access Key(s)")
  470. (string :tag "Description ")
  471. (repeat :tag "Component"
  472. (choice
  473. (list :tag "Agenda"
  474. (const :format "" agenda)
  475. (const :tag "" :format "" "")
  476. ,org-agenda-custom-commands-local-options)
  477. (list :tag "TODO list (all keywords)"
  478. (const :format "" alltodo)
  479. (const :tag "" :format "" "")
  480. ,org-agenda-custom-commands-local-options)
  481. (list :tag "Search words"
  482. (const :format "" search)
  483. (string :tag "Match")
  484. ,org-agenda-custom-commands-local-options)
  485. (list :tag "Stuck projects"
  486. (const :format "" stuck)
  487. (const :tag "" :format "" "")
  488. ,org-agenda-custom-commands-local-options)
  489. (list :tag "Tags search"
  490. (const :format "" tags)
  491. (string :tag "Match")
  492. ,org-agenda-custom-commands-local-options)
  493. (list :tag "Tags search, TODO entries only"
  494. (const :format "" tags-todo)
  495. (string :tag "Match")
  496. ,org-agenda-custom-commands-local-options)
  497. (list :tag "TODO keyword search"
  498. (const :format "" todo)
  499. (string :tag "Match")
  500. ,org-agenda-custom-commands-local-options)
  501. (list :tag "Other, user-defined function"
  502. (symbol :tag "function")
  503. (string :tag "Match")
  504. ,org-agenda-custom-commands-local-options)))
  505. (repeat :tag "Settings for entire command set"
  506. (list (variable :tag "Any variable")
  507. (sexp :tag "Value")))
  508. (option (repeat :tag "Export" (file :tag "Export to"))))
  509. (cons :tag "Prefix key documentation"
  510. (string :tag "Access Key(s)")
  511. (string :tag "Description ")))))
  512. (defcustom org-agenda-query-register ?o
  513. "The register holding the current query string.
  514. The purpose of this is that if you construct a query string interactively,
  515. you can then use it to define a custom command."
  516. :group 'org-agenda-custom-commands
  517. :type 'character)
  518. (defcustom org-stuck-projects
  519. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  520. "How to identify stuck projects.
  521. This is a list of four items:
  522. 1. A tags/todo/property matcher string that is used to identify a project.
  523. See the manual for a description of tag and property searches.
  524. The entire tree below a headline matched by this is considered one project.
  525. 2. A list of TODO keywords identifying non-stuck projects.
  526. If the project subtree contains any headline with one of these todo
  527. keywords, the project is considered to be not stuck. If you specify
  528. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  529. 3. A list of tags identifying non-stuck projects.
  530. If the project subtree contains any headline with one of these tags,
  531. the project is considered to be not stuck. If you specify \"*\" as
  532. a tag, any tag will mark the project unstuck. Note that this is about
  533. the explicit presence of a tag somewhere in the subtree, inherited
  534. tags do not count here. If inherited tags make a project not stuck,
  535. use \"-TAG\" in the tags part of the matcher under (1.) above.
  536. 4. An arbitrary regular expression matching non-stuck projects.
  537. If the project turns out to be not stuck, search continues also in the
  538. subtree to see if any of the subtasks have project status.
  539. See also the variable `org-tags-match-list-sublevels' which applies
  540. to projects matched by this search as well.
  541. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  542. or `C-c a #' to produce the list."
  543. :group 'org-agenda-custom-commands
  544. :type '(list
  545. (string :tag "Tags/TODO match to identify a project")
  546. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  547. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  548. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  549. (defcustom org-agenda-filter-effort-default-operator "<"
  550. "The default operator for effort estimate filtering.
  551. If you select an effort estimate limit without first pressing an operator,
  552. this one will be used."
  553. :group 'org-agenda-custom-commands
  554. :type '(choice (const :tag "less or equal" "<")
  555. (const :tag "greater or equal"">")
  556. (const :tag "equal" "=")))
  557. (defgroup org-agenda-skip nil
  558. "Options concerning skipping parts of agenda files."
  559. :tag "Org Agenda Skip"
  560. :group 'org-agenda)
  561. (defcustom org-agenda-skip-function-global nil
  562. "Function to be called at each match during agenda construction.
  563. If this function returns nil, the current match should not be skipped.
  564. If the function decided to skip an agenda match, is must return the
  565. buffer position from which the search should be continued.
  566. This may also be a Lisp form, which will be evaluated.
  567. This variable will be applied to every agenda match, including
  568. tags/property searches and TODO lists. So try to make the test function
  569. do its checking as efficiently as possible. To implement a skipping
  570. condition just for specific agenda commands, use the variable
  571. `org-agenda-skip-function' which can be set in the options section
  572. of custom agenda commands."
  573. :group 'org-agenda-skip
  574. :type 'sexp)
  575. (defgroup org-agenda-daily/weekly nil
  576. "Options concerning the daily/weekly agenda."
  577. :tag "Org Agenda Daily/Weekly"
  578. :group 'org-agenda)
  579. (defgroup org-agenda-todo-list nil
  580. "Options concerning the global todo list agenda view."
  581. :tag "Org Agenda Todo List"
  582. :group 'org-agenda)
  583. (defgroup org-agenda-match-view nil
  584. "Options concerning the general tags/property/todo match agenda view."
  585. :tag "Org Agenda Match View"
  586. :group 'org-agenda)
  587. (defgroup org-agenda-search-view nil
  588. "Options concerning the search agenda view."
  589. :tag "Org Agenda Search View"
  590. :group 'org-agenda)
  591. (defvar org-agenda-archives-mode nil
  592. "Non-nil means the agenda will include archived items.
  593. If this is the symbol `trees', trees in the selected agenda scope
  594. that are marked with the ARCHIVE tag will be included anyway. When this is
  595. t, also all archive files associated with the current selection of agenda
  596. files will be included.")
  597. (defcustom org-agenda-restriction-lock-highlight-subtree t
  598. "Non-nil means highlight the whole subtree when restriction is active.
  599. Otherwise only highlight the headline. Highlighting the whole subtree is
  600. useful to ensure no edits happen beyond the restricted region."
  601. :group 'org-agenda
  602. :type 'boolean)
  603. (defcustom org-agenda-skip-comment-trees t
  604. "Non-nil means skip trees that start with the COMMENT keyword.
  605. When nil, these trees are also scanned by agenda commands."
  606. :group 'org-agenda-skip
  607. :type 'boolean)
  608. (defcustom org-agenda-todo-list-sublevels t
  609. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  610. When nil, the sublevels of a TODO entry are not checked, resulting in
  611. potentially much shorter TODO lists."
  612. :group 'org-agenda-skip
  613. :group 'org-agenda-todo-list
  614. :type 'boolean)
  615. (defcustom org-agenda-todo-ignore-with-date nil
  616. "Non-nil means don't show entries with a date in the global todo list.
  617. You can use this if you prefer to mark mere appointments with a TODO keyword,
  618. but don't want them to show up in the TODO list.
  619. When this is set, it also covers deadlines and scheduled items, the settings
  620. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  621. will be ignored.
  622. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  623. :group 'org-agenda-skip
  624. :group 'org-agenda-todo-list
  625. :type 'boolean)
  626. (defcustom org-agenda-todo-ignore-timestamp nil
  627. "Non-nil means don't show entries with a timestamp.
  628. This applies when creating the global todo list.
  629. Valid values are:
  630. past Don't show entries for today or in the past.
  631. future Don't show entries with a timestamp in the future.
  632. The idea behind this is that if it has a future
  633. timestamp, you don't want to think about it until the
  634. date.
  635. all Don't show any entries with a timestamp in the global todo list.
  636. The idea behind this is that by setting a timestamp, you
  637. have already \"taken care\" of this item.
  638. This variable can also have an integer as a value. If positive (N),
  639. todos with a timestamp N or more days in the future will be ignored. If
  640. negative (-N), todos with a timestamp N or more days in the past will be
  641. ignored. If 0, todos with a timestamp either today or in the future will
  642. be ignored. For example, a value of -1 will exclude todos with a
  643. timestamp in the past (yesterday or earlier), while a value of 7 will
  644. exclude todos with a timestamp a week or more in the future.
  645. See also `org-agenda-todo-ignore-with-date'.
  646. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  647. to make his option also apply to the tags-todo list."
  648. :group 'org-agenda-skip
  649. :group 'org-agenda-todo-list
  650. :version "24.1"
  651. :type '(choice
  652. (const :tag "Ignore future timestamp todos" future)
  653. (const :tag "Ignore past or present timestamp todos" past)
  654. (const :tag "Ignore all timestamp todos" all)
  655. (const :tag "Show timestamp todos" nil)
  656. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  657. (defcustom org-agenda-todo-ignore-scheduled nil
  658. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  659. This applies when creating the global todo list.
  660. Valid values are:
  661. past Don't show entries scheduled today or in the past.
  662. future Don't show entries scheduled in the future.
  663. The idea behind this is that by scheduling it, you don't want to
  664. think about it until the scheduled date.
  665. all Don't show any scheduled entries in the global todo list.
  666. The idea behind this is that by scheduling it, you have already
  667. \"taken care\" of this item.
  668. t Same as `all', for backward compatibility.
  669. This variable can also have an integer as a value. See
  670. `org-agenda-todo-ignore-timestamp' for more details.
  671. See also `org-agenda-todo-ignore-with-date'.
  672. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  673. to make his option also apply to the tags-todo list."
  674. :group 'org-agenda-skip
  675. :group 'org-agenda-todo-list
  676. :type '(choice
  677. (const :tag "Ignore future-scheduled todos" future)
  678. (const :tag "Ignore past- or present-scheduled todos" past)
  679. (const :tag "Ignore all scheduled todos" all)
  680. (const :tag "Ignore all scheduled todos (compatibility)" t)
  681. (const :tag "Show scheduled todos" nil)
  682. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  683. (defcustom org-agenda-todo-ignore-deadlines nil
  684. "Non-nil means ignore some deadline TODO items when making TODO list.
  685. There are different motivations for using different values, please think
  686. carefully when configuring this variable.
  687. This applies when creating the global todo list.
  688. Valid values are:
  689. near Don't show near deadline entries. A deadline is near when it is
  690. closer than `org-deadline-warning-days' days. The idea behind this
  691. is that such items will appear in the agenda anyway.
  692. far Don't show TODO entries where a deadline has been defined, but
  693. the deadline is not near. This is useful if you don't want to
  694. use the todo list to figure out what to do now.
  695. past Don't show entries with a deadline timestamp for today or in the past.
  696. future Don't show entries with a deadline timestamp in the future, not even
  697. when they become `near' ones. Use it with caution.
  698. all Ignore all TODO entries that do have a deadline.
  699. t Same as `near', for backward compatibility.
  700. This variable can also have an integer as a value. See
  701. `org-agenda-todo-ignore-timestamp' for more details.
  702. See also `org-agenda-todo-ignore-with-date'.
  703. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  704. to make his option also apply to the tags-todo list."
  705. :group 'org-agenda-skip
  706. :group 'org-agenda-todo-list
  707. :type '(choice
  708. (const :tag "Ignore near deadlines" near)
  709. (const :tag "Ignore near deadlines (compatibility)" t)
  710. (const :tag "Ignore far deadlines" far)
  711. (const :tag "Ignore all TODOs with a deadlines" all)
  712. (const :tag "Show all TODOs, even if they have a deadline" nil)
  713. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  714. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  715. "Time unit to use when possibly ignoring an agenda item.
  716. See the docstring of various `org-agenda-todo-ignore-*' options.
  717. The default is to compare time stamps using days. An item is thus
  718. considered to be in the future if it is at least one day after today.
  719. Non-nil means to compare time stamps using seconds. An item is then
  720. considered future if it has a time value later than current time."
  721. :group 'org-agenda-skip
  722. :group 'org-agenda-todo-list
  723. :version "24.4"
  724. :package-version '(Org . "8.0")
  725. :type '(choice
  726. (const :tag "Compare time with days" nil)
  727. (const :tag "Compare time with seconds" t)))
  728. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  729. "Non-nil means honor todo-list ignores options also in tags-todo search.
  730. The variables
  731. `org-agenda-todo-ignore-with-date',
  732. `org-agenda-todo-ignore-timestamp',
  733. `org-agenda-todo-ignore-scheduled',
  734. `org-agenda-todo-ignore-deadlines'
  735. make the global TODO list skip entries that have time stamps of certain
  736. kinds. If this option is set, the same options will also apply for the
  737. tags-todo search, which is the general tags/property matcher
  738. restricted to unfinished TODO entries only."
  739. :group 'org-agenda-skip
  740. :group 'org-agenda-todo-list
  741. :group 'org-agenda-match-view
  742. :type 'boolean)
  743. (defcustom org-agenda-skip-scheduled-if-done nil
  744. "Non-nil means don't show scheduled items in agenda when they are done.
  745. This is relevant for the daily/weekly agenda, not for the TODO list. And
  746. it applies only to the actual date of the scheduling. Warnings about
  747. an item with a past scheduling dates are always turned off when the item
  748. is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  753. "Non-nil means skip scheduling line if same entry shows because of deadline.
  754. In the agenda of today, an entry can show up multiple times
  755. because it is both scheduled and has a nearby deadline, and maybe
  756. a plain time stamp as well.
  757. When this variable is nil, the entry will be shown several times.
  758. When set to t, then only the deadline is shown and the fact that
  759. the entry is scheduled today or was scheduled previously is not
  760. shown.
  761. When set to the symbol `not-today', skip scheduled previously,
  762. but not scheduled today.
  763. When set to the symbol `repeated-after-deadline', skip scheduled
  764. items if they are repeated beyond the current deadline."
  765. :group 'org-agenda-skip
  766. :group 'org-agenda-daily/weekly
  767. :type '(choice
  768. (const :tag "Never" nil)
  769. (const :tag "Always" t)
  770. (const :tag "Not when scheduled today" not-today)
  771. (const :tag "When repeated past deadline" repeated-after-deadline)))
  772. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  773. "Non-nil means skip timestamp line if same entry shows because of deadline.
  774. In the agenda of today, an entry can show up multiple times
  775. because it has both a plain timestamp and has a nearby deadline.
  776. When this variable is t, then only the deadline is shown and the
  777. fact that the entry has a timestamp for or including today is not
  778. shown. When this variable is nil, the entry will be shown
  779. several times."
  780. :group 'org-agenda-skip
  781. :group 'org-agenda-daily/weekly
  782. :version "24.1"
  783. :type '(choice
  784. (const :tag "Never" nil)
  785. (const :tag "Always" t)))
  786. (defcustom org-agenda-skip-deadline-if-done nil
  787. "Non-nil means don't show deadlines when the corresponding item is done.
  788. When nil, the deadline is still shown and should give you a happy feeling.
  789. This is relevant for the daily/weekly agenda. And it applied only to the
  790. actually date of the deadline. Warnings about approaching and past-due
  791. deadlines are always turned off when the item is DONE."
  792. :group 'org-agenda-skip
  793. :group 'org-agenda-daily/weekly
  794. :type 'boolean)
  795. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  796. "Non-nil means skip deadline prewarning when entry is also scheduled.
  797. This will apply on all days where a prewarning for the deadline would
  798. be shown, but not at the day when the entry is actually due. On that day,
  799. the deadline will be shown anyway.
  800. This variable may be set to nil, t, the symbol `pre-scheduled',
  801. or a number which will then give the number of days before the actual
  802. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  803. eliminates the deadline prewarning only prior to the scheduled date.
  804. This can be used in a workflow where the first showing of the deadline will
  805. trigger you to schedule it, and then you don't want to be reminded of it
  806. because you will take care of it on the day when scheduled."
  807. :group 'org-agenda-skip
  808. :group 'org-agenda-daily/weekly
  809. :version "24.1"
  810. :type '(choice
  811. (const :tag "Always show prewarning" nil)
  812. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  813. (const :tag "Remove prewarning if entry is scheduled" t)
  814. (integer :tag "Restart prewarning N days before deadline")))
  815. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  816. "Non-nil means skip scheduled delay when entry also has a deadline.
  817. This variable may be set to nil, t, the symbol `post-deadline',
  818. or a number which will then give the number of days after the actual
  819. scheduled date when the delay should expire. The symbol `post-deadline'
  820. eliminates the schedule delay when the date is posterior to the deadline."
  821. :group 'org-agenda-skip
  822. :group 'org-agenda-daily/weekly
  823. :version "24.4"
  824. :package-version '(Org . "8.0")
  825. :type '(choice
  826. (const :tag "Always honor delay" nil)
  827. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  828. (const :tag "Ignore delay if entry has a deadline" t)
  829. (integer :tag "Honor delay up until N days after the scheduled date")))
  830. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  831. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  832. When non-nil, after the search for timestamps has matched once in an
  833. entry, the rest of the entry will not be searched."
  834. :group 'org-agenda-skip
  835. :type 'boolean)
  836. (defcustom org-agenda-skip-timestamp-if-done nil
  837. "Non-nil means don't select item by timestamp or -range if it is DONE."
  838. :group 'org-agenda-skip
  839. :group 'org-agenda-daily/weekly
  840. :type 'boolean)
  841. (defcustom org-agenda-dim-blocked-tasks t
  842. "Non-nil means dim blocked tasks in the agenda display.
  843. This causes some overhead during agenda construction, but if you
  844. have turned on `org-enforce-todo-dependencies',
  845. `org-enforce-todo-checkbox-dependencies', or any other blocking
  846. mechanism, this will create useful feedback in the agenda.
  847. Instead of t, this variable can also have the value `invisible'.
  848. Then blocked tasks will be invisible and only become visible when
  849. they become unblocked. An exemption to this behavior is when a task is
  850. blocked because of unchecked checkboxes below it. Since checkboxes do
  851. not show up in the agenda views, making this task invisible you remove any
  852. trace from agenda views that there is something to do. Therefore, a task
  853. that is blocked because of checkboxes will never be made invisible, it
  854. will only be dimmed."
  855. :group 'org-agenda-daily/weekly
  856. :group 'org-agenda-todo-list
  857. :version "24.3"
  858. :type '(choice
  859. (const :tag "Do not dim" nil)
  860. (const :tag "Dim to a gray face" t)
  861. (const :tag "Make invisible" invisible)))
  862. (defcustom org-timeline-show-empty-dates 3
  863. "Non-nil means `org-timeline' also shows dates without an entry.
  864. When nil, only the days which actually have entries are shown.
  865. When t, all days between the first and the last date are shown.
  866. When an integer, show also empty dates, but if there is a gap of more than
  867. N days, just insert a special line indicating the size of the gap."
  868. :group 'org-agenda-skip
  869. :type '(choice
  870. (const :tag "None" nil)
  871. (const :tag "All" t)
  872. (integer :tag "at most")))
  873. (defgroup org-agenda-startup nil
  874. "Options concerning initial settings in the Agenda in Org Mode."
  875. :tag "Org Agenda Startup"
  876. :group 'org-agenda)
  877. (defcustom org-agenda-menu-show-matcher t
  878. "Non-nil means show the match string in the agenda dispatcher menu.
  879. When nil, the matcher string is not shown, but is put into the help-echo
  880. property so than moving the mouse over the command shows it.
  881. Setting it to nil is good if matcher strings are very long and/or if
  882. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  883. :group 'org-agenda
  884. :version "24.1"
  885. :type 'boolean)
  886. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  887. (defcustom org-agenda-menu-two-columns nil
  888. "Non-nil means, use two columns to show custom commands in the dispatcher.
  889. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  890. to nil."
  891. :group 'org-agenda
  892. :version "24.1"
  893. :type 'boolean)
  894. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  895. (defcustom org-agenda-finalize-hook nil
  896. "Hook run just before displaying an agenda buffer.
  897. The buffer is still writable when the hook is called.
  898. You can modify some of the buffer substrings but you should be
  899. extra careful not to modify the text properties of the agenda
  900. headlines as the agenda display heavily relies on them."
  901. :group 'org-agenda-startup
  902. :type 'hook)
  903. (defcustom org-agenda-mouse-1-follows-link nil
  904. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  905. A longer mouse click will still set point. Does not work on XEmacs.
  906. Needs to be set before org.el is loaded."
  907. :group 'org-agenda-startup
  908. :type 'boolean)
  909. (defcustom org-agenda-start-with-follow-mode nil
  910. "The initial value of follow mode in a newly created agenda window."
  911. :group 'org-agenda-startup
  912. :type 'boolean)
  913. (defcustom org-agenda-follow-indirect nil
  914. "Non-nil means `org-agenda-follow-mode' displays only the
  915. current item's tree, in an indirect buffer."
  916. :group 'org-agenda
  917. :version "24.1"
  918. :type 'boolean)
  919. (defcustom org-agenda-show-outline-path t
  920. "Non-nil means show outline path in echo area after line motion."
  921. :group 'org-agenda-startup
  922. :type 'boolean)
  923. (defcustom org-agenda-start-with-entry-text-mode nil
  924. "The initial value of entry-text-mode in a newly created agenda window."
  925. :group 'org-agenda-startup
  926. :type 'boolean)
  927. (defcustom org-agenda-entry-text-maxlines 5
  928. "Number of text lines to be added when `E' is pressed in the agenda.
  929. Note that this variable only used during agenda display. Add add entry text
  930. when exporting the agenda, configure the variable
  931. `org-agenda-add-entry-ext-maxlines'."
  932. :group 'org-agenda
  933. :type 'integer)
  934. (defcustom org-agenda-entry-text-exclude-regexps nil
  935. "List of regular expressions to clean up entry text.
  936. The complete matches of all regular expressions in this list will be
  937. removed from entry text before it is shown in the agenda."
  938. :group 'org-agenda
  939. :type '(repeat (regexp)))
  940. (defcustom org-agenda-entry-text-leaders " > "
  941. "Text prepended to the entry text in agenda buffers."
  942. :version "24.4"
  943. :package-version '(Org . "8.0")
  944. :group 'org-agenda
  945. :type 'string)
  946. (defvar org-agenda-entry-text-cleanup-hook nil
  947. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  948. This cleanup is done in a temporary buffer, so the function may inspect and
  949. change the entire buffer.
  950. Some default stuff like drawers and scheduling/deadline dates will already
  951. have been removed when this is called, as will any matches for regular
  952. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  953. (defvar org-agenda-include-inactive-timestamps nil
  954. "Non-nil means include inactive time stamps in agenda and timeline.
  955. Dynamically scoped.")
  956. (defgroup org-agenda-windows nil
  957. "Options concerning the windows used by the Agenda in Org Mode."
  958. :tag "Org Agenda Windows"
  959. :group 'org-agenda)
  960. (defcustom org-agenda-window-setup 'reorganize-frame
  961. "How the agenda buffer should be displayed.
  962. Possible values for this option are:
  963. current-window Show agenda in the current window, keeping all other windows.
  964. other-window Use `switch-to-buffer-other-window' to display agenda.
  965. reorganize-frame Show only two windows on the current frame, the current
  966. window and the agenda.
  967. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  968. Also, when exiting the agenda, kill that frame.
  969. See also the variable `org-agenda-restore-windows-after-quit'."
  970. :group 'org-agenda-windows
  971. :type '(choice
  972. (const current-window)
  973. (const other-frame)
  974. (const other-window)
  975. (const reorganize-frame)))
  976. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  977. "The min and max height of the agenda window as a fraction of frame height.
  978. The value of the variable is a cons cell with two numbers between 0 and 1.
  979. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  980. :group 'org-agenda-windows
  981. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  982. (defcustom org-agenda-restore-windows-after-quit nil
  983. "Non-nil means restore window configuration upon exiting agenda.
  984. Before the window configuration is changed for displaying the agenda,
  985. the current status is recorded. When the agenda is exited with
  986. `q' or `x' and this option is set, the old state is restored. If
  987. `org-agenda-window-setup' is `other-frame', the value of this
  988. option will be ignored."
  989. :group 'org-agenda-windows
  990. :type 'boolean)
  991. (defcustom org-agenda-ndays nil
  992. "Number of days to include in overview display.
  993. Should be 1 or 7.
  994. Obsolete, see `org-agenda-span'."
  995. :group 'org-agenda-daily/weekly
  996. :type '(choice (const nil)
  997. (integer)))
  998. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  999. (defcustom org-agenda-span 'week
  1000. "Number of days to include in overview display.
  1001. Can be day, week, month, year, or any number of days.
  1002. Custom commands can set this variable in the options section."
  1003. :group 'org-agenda-daily/weekly
  1004. :type '(choice (const :tag "Day" day)
  1005. (const :tag "Week" week)
  1006. (const :tag "Fortnight" fortnight)
  1007. (const :tag "Month" month)
  1008. (const :tag "Year" year)
  1009. (integer :tag "Custom")))
  1010. (defcustom org-agenda-start-on-weekday 1
  1011. "Non-nil means start the overview always on the specified weekday.
  1012. 0 denotes Sunday, 1 denotes Monday, etc.
  1013. When nil, always start on the current day.
  1014. Custom commands can set this variable in the options section."
  1015. :group 'org-agenda-daily/weekly
  1016. :type '(choice (const :tag "Today" nil)
  1017. (integer :tag "Weekday No.")))
  1018. (defcustom org-agenda-show-all-dates t
  1019. "Non-nil means `org-agenda' shows every day in the selected range.
  1020. When nil, only the days which actually have entries are shown."
  1021. :group 'org-agenda-daily/weekly
  1022. :type 'boolean)
  1023. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1024. "Format string for displaying dates in the agenda.
  1025. Used by the daily/weekly agenda and by the timeline. This should be
  1026. a format string understood by `format-time-string', or a function returning
  1027. the formatted date as a string. The function must take a single argument,
  1028. a calendar-style date list like (month day year)."
  1029. :group 'org-agenda-daily/weekly
  1030. :type '(choice
  1031. (string :tag "Format string")
  1032. (function :tag "Function")))
  1033. (defun org-agenda-format-date-aligned (date)
  1034. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1035. This function makes sure that dates are aligned for easy reading."
  1036. (require 'cal-iso)
  1037. (let* ((dayname (calendar-day-name date))
  1038. (day (cadr date))
  1039. (day-of-week (calendar-day-of-week date))
  1040. (month (car date))
  1041. (monthname (calendar-month-name month))
  1042. (year (nth 2 date))
  1043. (iso-week (org-days-to-iso-week
  1044. (calendar-absolute-from-gregorian date)))
  1045. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1046. (1- year))
  1047. ((and (= month 12) (<= iso-week 1))
  1048. (1+ year))
  1049. (t year)))
  1050. (weekstring (if (= day-of-week 1)
  1051. (format " W%02d" iso-week)
  1052. "")))
  1053. (format "%-10s %2d %s %4d%s"
  1054. dayname day monthname year weekstring)))
  1055. (defcustom org-agenda-time-leading-zero nil
  1056. "Non-nil means use leading zero for military times in agenda.
  1057. For example, 9:30am would become 09:30 rather than 9:30."
  1058. :group 'org-agenda-daily/weekly
  1059. :version "24.1"
  1060. :type 'boolean)
  1061. (defcustom org-agenda-timegrid-use-ampm nil
  1062. "When set, show AM/PM style timestamps on the timegrid."
  1063. :group 'org-agenda
  1064. :version "24.1"
  1065. :type 'boolean)
  1066. (defun org-agenda-time-of-day-to-ampm (time)
  1067. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1068. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1069. (minute (substring time -2))
  1070. (ampm "am"))
  1071. (cond
  1072. ((equal hour-number 12)
  1073. (setq ampm "pm"))
  1074. ((> hour-number 12)
  1075. (setq ampm "pm")
  1076. (setq hour-number (- hour-number 12))))
  1077. (concat
  1078. (if org-agenda-time-leading-zero
  1079. (format "%02d" hour-number)
  1080. (format "%02s" (number-to-string hour-number)))
  1081. ":" minute ampm)))
  1082. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1083. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1084. (if org-agenda-timegrid-use-ampm
  1085. (org-agenda-time-of-day-to-ampm time)
  1086. time))
  1087. (defcustom org-agenda-weekend-days '(6 0)
  1088. "Which days are weekend?
  1089. These days get the special face `org-agenda-date-weekend' in the agenda
  1090. and timeline buffers."
  1091. :group 'org-agenda-daily/weekly
  1092. :type '(set :greedy t
  1093. (const :tag "Monday" 1)
  1094. (const :tag "Tuesday" 2)
  1095. (const :tag "Wednesday" 3)
  1096. (const :tag "Thursday" 4)
  1097. (const :tag "Friday" 5)
  1098. (const :tag "Saturday" 6)
  1099. (const :tag "Sunday" 0)))
  1100. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1101. "Non-nil means jump to today when moving a past date forward in time.
  1102. When using S-right in the agenda to move a a date forward, and the date
  1103. stamp currently points to the past, the first key press will move it
  1104. to today. WHen nil, just move one day forward even if the date stays
  1105. in the past."
  1106. :group 'org-agenda-daily/weekly
  1107. :version "24.1"
  1108. :type 'boolean)
  1109. (defcustom org-agenda-include-diary nil
  1110. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1111. Custom commands can set this variable in the options section."
  1112. :group 'org-agenda-daily/weekly
  1113. :type 'boolean)
  1114. (defcustom org-agenda-include-deadlines t
  1115. "If non-nil, include entries within their deadline warning period.
  1116. Custom commands can set this variable in the options section."
  1117. :group 'org-agenda-daily/weekly
  1118. :version "24.1"
  1119. :type 'boolean)
  1120. (defcustom org-agenda-repeating-timestamp-show-all t
  1121. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1122. When set to a list of strings, only show occurrences of repeating
  1123. stamps for these TODO keywords. When nil, only one occurrence is
  1124. shown, either today or the nearest into the future."
  1125. :group 'org-agenda-daily/weekly
  1126. :type '(choice
  1127. (const :tag "Show repeating stamps" t)
  1128. (repeat :tag "Show repeating stamps for these TODO keywords"
  1129. (string :tag "TODO Keyword"))
  1130. (const :tag "Don't show repeating stamps" nil)))
  1131. (defcustom org-scheduled-past-days 10000
  1132. "Number of days to continue listing scheduled items not marked DONE.
  1133. When an item is scheduled on a date, it shows up in the agenda on this
  1134. day and will be listed until it is marked done for the number of days
  1135. given here."
  1136. :group 'org-agenda-daily/weekly
  1137. :type 'integer)
  1138. (defcustom org-agenda-log-mode-items '(closed clock)
  1139. "List of items that should be shown in agenda log mode.
  1140. This list may contain the following symbols:
  1141. closed Show entries that have been closed on that day.
  1142. clock Show entries that have received clocked time on that day.
  1143. state Show all logged state changes.
  1144. Note that instead of changing this variable, you can also press `C-u l' in
  1145. the agenda to display all available LOG items temporarily."
  1146. :group 'org-agenda-daily/weekly
  1147. :type '(set :greedy t (const closed) (const clock) (const state)))
  1148. (defcustom org-agenda-clock-consistency-checks
  1149. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1150. :gap-ok-around ("4:00")
  1151. :default-face ((:background "DarkRed") (:foreground "white"))
  1152. :overlap-face nil :gap-face nil :no-end-time-face nil
  1153. :long-face nil :short-face nil)
  1154. "This is a property list, with the following keys:
  1155. :max-duration Mark clocking chunks that are longer than this time.
  1156. This is a time string like \"HH:MM\", or the number
  1157. of minutes as an integer.
  1158. :min-duration Mark clocking chunks that are shorter that this.
  1159. This is a time string like \"HH:MM\", or the number
  1160. of minutes as an integer.
  1161. :max-gap Mark gaps between clocking chunks that are longer than
  1162. this duration. A number of minutes, or a string
  1163. like \"HH:MM\".
  1164. :gap-ok-around List of times during the day which are usually not working
  1165. times. When a gap is detected, but the gap contains any
  1166. of these times, the gap is *not* reported. For example,
  1167. if this is (\"4:00\" \"13:00\") then gaps that contain
  1168. 4:00 in the morning (i.e. the night) and 13:00
  1169. (i.e. a typical lunch time) do not cause a warning.
  1170. You should have at least one time during the night in this
  1171. list, or otherwise the first task each morning will trigger
  1172. a warning because it follows a long gap.
  1173. Furthermore, the following properties can be used to define faces for
  1174. issue display.
  1175. :default-face the default face, if the specific face is undefined
  1176. :overlap-face face for overlapping clocks
  1177. :gap-face face for gaps between clocks
  1178. :no-end-time-face face for incomplete clocks
  1179. :long-face face for clock intervals that are too long
  1180. :short-face face for clock intervals that are too short"
  1181. :group 'org-agenda-daily/weekly
  1182. :group 'org-clock
  1183. :version "24.1"
  1184. :type 'plist)
  1185. (defcustom org-agenda-log-mode-add-notes t
  1186. "Non-nil means add first line of notes to log entries in agenda views.
  1187. If a log item like a state change or a clock entry is associated with
  1188. notes, the first line of these notes will be added to the entry in the
  1189. agenda display."
  1190. :group 'org-agenda-daily/weekly
  1191. :type 'boolean)
  1192. (defcustom org-agenda-start-with-log-mode nil
  1193. "The initial value of log-mode in a newly created agenda window.
  1194. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1195. explanations on the possible values."
  1196. :group 'org-agenda-startup
  1197. :group 'org-agenda-daily/weekly
  1198. :type '(choice (const :tag "Don't show log items" nil)
  1199. (const :tag "Show only log items" only)
  1200. (const :tag "Show all possible log items" clockcheck)
  1201. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1202. (choice (const :tag "Show closed log items" closed)
  1203. (const :tag "Show clocked log items" clock)
  1204. (const :tag "Show all logged state changes" state)))))
  1205. (defcustom org-agenda-start-with-clockreport-mode nil
  1206. "The initial value of clockreport-mode in a newly created agenda window."
  1207. :group 'org-agenda-startup
  1208. :group 'org-agenda-daily/weekly
  1209. :type 'boolean)
  1210. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1211. "Property list with parameters for the clocktable in clockreport mode.
  1212. This is the display mode that shows a clock table in the daily/weekly
  1213. agenda, the properties for this dynamic block can be set here.
  1214. The usual clocktable parameters are allowed here, but you cannot set
  1215. the properties :name, :tstart, :tend, :block, and :scope - these will
  1216. be overwritten to make sure the content accurately reflects the
  1217. current display in the agenda."
  1218. :group 'org-agenda-daily/weekly
  1219. :type 'plist)
  1220. (defcustom org-agenda-search-view-always-boolean nil
  1221. "Non-nil means the search string is interpreted as individual parts.
  1222. The search string for search view can either be interpreted as a phrase,
  1223. or as a list of snippets that define a boolean search for a number of
  1224. strings.
  1225. When this is non-nil, the string will be split on whitespace, and each
  1226. snippet will be searched individually, and all must match in order to
  1227. select an entry. A snippet is then a single string of non-white
  1228. characters, or a string in double quotes, or a regexp in {} braces.
  1229. If a snippet is preceded by \"-\", the snippet must *not* match.
  1230. \"+\" is syntactic sugar for positive selection. Each snippet may
  1231. be found as a full word or a partial word, but see the variable
  1232. `org-agenda-search-view-force-full-words'.
  1233. When this is nil, search will look for the entire search phrase as one,
  1234. with each space character matching any amount of whitespace, including
  1235. line breaks.
  1236. Even when this is nil, you can still switch to Boolean search dynamically
  1237. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1238. is a regexp marked with braces like \"{abc}\", this will also switch to
  1239. boolean search."
  1240. :group 'org-agenda-search-view
  1241. :version "24.1"
  1242. :type 'boolean)
  1243. (org-defvaralias 'org-agenda-search-view-search-words-only
  1244. 'org-agenda-search-view-always-boolean)
  1245. (defcustom org-agenda-search-view-force-full-words nil
  1246. "Non-nil means, search words must be matches as complete words.
  1247. When nil, they may also match part of a word."
  1248. :group 'org-agenda-search-view
  1249. :version "24.1"
  1250. :type 'boolean)
  1251. (defcustom org-agenda-search-view-max-outline-level 0
  1252. "Maximum outline level to display in search view.
  1253. E.g. when this is set to 1, the search view will only
  1254. show headlines of level 1. When set to 0, the default
  1255. value, don't limit agenda view by outline level."
  1256. :group 'org-agenda-search-view
  1257. :version "24.4"
  1258. :package-version '(Org . "8.3")
  1259. :type 'integer)
  1260. (defgroup org-agenda-time-grid nil
  1261. "Options concerning the time grid in the Org-mode Agenda."
  1262. :tag "Org Agenda Time Grid"
  1263. :group 'org-agenda)
  1264. (defcustom org-agenda-search-headline-for-time t
  1265. "Non-nil means search headline for a time-of-day.
  1266. If the headline contains a time-of-day in one format or another, it will
  1267. be used to sort the entry into the time sequence of items for a day.
  1268. Some people have time stamps in the headline that refer to the creation
  1269. time or so, and then this produces an unwanted side effect. If this is
  1270. the case for your, use this variable to turn off searching the headline
  1271. for a time."
  1272. :group 'org-agenda-time-grid
  1273. :type 'boolean)
  1274. (defcustom org-agenda-use-time-grid t
  1275. "Non-nil means show a time grid in the agenda schedule.
  1276. A time grid is a set of lines for specific times (like every two hours between
  1277. 8:00 and 20:00). The items scheduled for a day at specific times are
  1278. sorted in between these lines.
  1279. For details about when the grid will be shown, and what it will look like, see
  1280. the variable `org-agenda-time-grid'."
  1281. :group 'org-agenda-time-grid
  1282. :type 'boolean)
  1283. (defcustom org-agenda-time-grid
  1284. '((daily today require-timed)
  1285. "----------------"
  1286. (800 1000 1200 1400 1600 1800 2000))
  1287. "The settings for time grid for agenda display.
  1288. This is a list of three items. The first item is again a list. It contains
  1289. symbols specifying conditions when the grid should be displayed:
  1290. daily if the agenda shows a single day
  1291. weekly if the agenda shows an entire week
  1292. today show grid on current date, independent of daily/weekly display
  1293. require-timed show grid only if at least one item has a time specification
  1294. The second item is a string which will be placed behind the grid time.
  1295. The third item is a list of integers, indicating the times that should have
  1296. a grid line."
  1297. :group 'org-agenda-time-grid
  1298. :type
  1299. '(list
  1300. (set :greedy t :tag "Grid Display Options"
  1301. (const :tag "Show grid in single day agenda display" daily)
  1302. (const :tag "Show grid in weekly agenda display" weekly)
  1303. (const :tag "Always show grid for today" today)
  1304. (const :tag "Show grid only if any timed entries are present"
  1305. require-timed)
  1306. (const :tag "Skip grid times already present in an entry"
  1307. remove-match))
  1308. (string :tag "Grid String")
  1309. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1310. (defcustom org-agenda-show-current-time-in-grid t
  1311. "Non-nil means show the current time in the time grid."
  1312. :group 'org-agenda-time-grid
  1313. :version "24.1"
  1314. :type 'boolean)
  1315. (defcustom org-agenda-current-time-string
  1316. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1317. "The string for the current time marker in the agenda."
  1318. :group 'org-agenda-time-grid
  1319. :version "24.1"
  1320. :type 'string)
  1321. (defgroup org-agenda-sorting nil
  1322. "Options concerning sorting in the Org-mode Agenda."
  1323. :tag "Org Agenda Sorting"
  1324. :group 'org-agenda)
  1325. (defcustom org-agenda-sorting-strategy
  1326. '((agenda habit-down time-up priority-down category-keep)
  1327. (todo priority-down category-keep)
  1328. (tags priority-down category-keep)
  1329. (search category-keep))
  1330. "Sorting structure for the agenda items of a single day.
  1331. This is a list of symbols which will be used in sequence to determine
  1332. if an entry should be listed before another entry. The following
  1333. symbols are recognized:
  1334. time-up Put entries with time-of-day indications first, early first
  1335. time-down Put entries with time-of-day indications first, late first
  1336. timestamp-up Sort by any timestamp, early first
  1337. timestamp-down Sort by any timestamp, late first
  1338. scheduled-up Sort by scheduled timestamp, early first
  1339. scheduled-down Sort by scheduled timestamp, late first
  1340. deadline-up Sort by deadline timestamp, early first
  1341. deadline-down Sort by deadline timestamp, late first
  1342. ts-up Sort by active timestamp, early first
  1343. ts-down Sort by active timestamp, late first
  1344. tsia-up Sort by inactive timestamp, early first
  1345. tsia-down Sort by inactive timestamp, late first
  1346. category-keep Keep the default order of categories, corresponding to the
  1347. sequence in `org-agenda-files'.
  1348. category-up Sort alphabetically by category, A-Z.
  1349. category-down Sort alphabetically by category, Z-A.
  1350. tag-up Sort alphabetically by last tag, A-Z.
  1351. tag-down Sort alphabetically by last tag, Z-A.
  1352. priority-up Sort numerically by priority, high priority last.
  1353. priority-down Sort numerically by priority, high priority first.
  1354. todo-state-up Sort by todo state, tasks that are done last.
  1355. todo-state-down Sort by todo state, tasks that are done first.
  1356. effort-up Sort numerically by estimated effort, high effort last.
  1357. effort-down Sort numerically by estimated effort, high effort first.
  1358. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1359. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1360. habit-up Put entries that are habits first
  1361. habit-down Put entries that are habits last
  1362. alpha-up Sort headlines alphabetically
  1363. alpha-down Sort headlines alphabetically, reversed
  1364. The different possibilities will be tried in sequence, and testing stops
  1365. if one comparison returns a \"not-equal\". For example, the default
  1366. '(time-up category-keep priority-down)
  1367. means: Pull out all entries having a specified time of day and sort them,
  1368. in order to make a time schedule for the current day the first thing in the
  1369. agenda listing for the day. Of the entries without a time indication, keep
  1370. the grouped in categories, don't sort the categories, but keep them in
  1371. the sequence given in `org-agenda-files'. Within each category sort by
  1372. priority.
  1373. Leaving out `category-keep' would mean that items will be sorted across
  1374. categories by priority.
  1375. Instead of a single list, this can also be a set of list for specific
  1376. contents, with a context symbol in the car of the list, any of
  1377. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1378. Custom commands can bind this variable in the options section."
  1379. :group 'org-agenda-sorting
  1380. :type `(choice
  1381. (repeat :tag "General" ,org-sorting-choice)
  1382. (list :tag "Individually"
  1383. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1384. (repeat ,org-sorting-choice))
  1385. (cons (const :tag "Strategy for TODO lists" todo)
  1386. (repeat ,org-sorting-choice))
  1387. (cons (const :tag "Strategy for Tags matches" tags)
  1388. (repeat ,org-sorting-choice))
  1389. (cons (const :tag "Strategy for search matches" search)
  1390. (repeat ,org-sorting-choice)))))
  1391. (defcustom org-agenda-cmp-user-defined nil
  1392. "A function to define the comparison `user-defined'.
  1393. This function must receive two arguments, agenda entry a and b.
  1394. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1395. the user comparison, return nil.
  1396. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1397. part of an agenda sorting strategy."
  1398. :group 'org-agenda-sorting
  1399. :type 'symbol)
  1400. (defcustom org-sort-agenda-notime-is-late t
  1401. "Non-nil means items without time are considered late.
  1402. This is only relevant for sorting. When t, items which have no explicit
  1403. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1404. do have a time. When nil, the default time is before 0:00. You can use this
  1405. option to decide if the schedule for today should come before or after timeless
  1406. agenda entries."
  1407. :group 'org-agenda-sorting
  1408. :type 'boolean)
  1409. (defcustom org-sort-agenda-noeffort-is-high t
  1410. "Non-nil means items without effort estimate are sorted as high effort.
  1411. This also applies when filtering an agenda view with respect to the
  1412. < or > effort operator. Then, tasks with no effort defined will be treated
  1413. as tasks with high effort.
  1414. When nil, such items are sorted as 0 minutes effort."
  1415. :group 'org-agenda-sorting
  1416. :type 'boolean)
  1417. (defgroup org-agenda-line-format nil
  1418. "Options concerning the entry prefix in the Org-mode agenda display."
  1419. :tag "Org Agenda Line Format"
  1420. :group 'org-agenda)
  1421. (defcustom org-agenda-prefix-format
  1422. '((agenda . " %i %-12:c%?-12t% s")
  1423. (timeline . " % s")
  1424. (todo . " %i %-12:c")
  1425. (tags . " %i %-12:c")
  1426. (search . " %i %-12:c"))
  1427. "Format specifications for the prefix of items in the agenda views.
  1428. An alist with five entries, each for the different agenda types. The
  1429. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1430. The values are format strings.
  1431. This format works similar to a printf format, with the following meaning:
  1432. %c the category of the item, \"Diary\" for entries from the diary,
  1433. or as given by the CATEGORY keyword or derived from the file name
  1434. %e the effort required by the item
  1435. %l the level of the item (insert X space(s) if item is of level X)
  1436. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1437. %T the last tag of the item (ignore inherited tags, which come first)
  1438. %t the HH:MM time-of-day specification if one applies to the entry
  1439. %s Scheduling/Deadline information, a short string
  1440. %b show breadcrumbs, i.e., the names of the higher levels
  1441. %(expression) Eval EXPRESSION and replace the control string
  1442. by the result
  1443. All specifiers work basically like the standard `%s' of printf, but may
  1444. contain two additional characters: a question mark just after the `%'
  1445. and a whitespace/punctuation character just before the final letter.
  1446. If the first character after `%' is a question mark, the entire field
  1447. will only be included if the corresponding value applies to the current
  1448. entry. This is useful for fields which should have fixed width when
  1449. present, but zero width when absent. For example, \"%?-12t\" will
  1450. result in a 12 character time field if a time of the day is specified,
  1451. but will completely disappear in entries which do not contain a time.
  1452. If there is punctuation or whitespace character just before the
  1453. final format letter, this character will be appended to the field
  1454. value if the value is not empty. For example, the format
  1455. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1456. the category is empty, no additional colon is inserted.
  1457. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1458. which means:
  1459. - Indent the line with two space characters
  1460. - Give the category a 12 chars wide field, padded with whitespace on
  1461. the right (because of `-'). Append a colon if there is a category
  1462. (because of `:').
  1463. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1464. time, don't put in an empty field, just skip it (because of '?').
  1465. - Finally, put the scheduling information.
  1466. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1467. `org-agenda-remove-tags'.
  1468. Custom commands can set this variable in the options section."
  1469. :type '(choice
  1470. (string :tag "General format")
  1471. (list :greedy t :tag "View dependent"
  1472. (cons (const agenda) (string :tag "Format"))
  1473. (cons (const timeline) (string :tag "Format"))
  1474. (cons (const todo) (string :tag "Format"))
  1475. (cons (const tags) (string :tag "Format"))
  1476. (cons (const search) (string :tag "Format"))))
  1477. :group 'org-agenda-line-format)
  1478. (defvar org-prefix-format-compiled nil
  1479. "The compiled prefix format and associated variables.
  1480. This is a list where first element is a list of variable bindings, and second
  1481. element is the compiled format expression. See the variable
  1482. `org-agenda-prefix-format'.")
  1483. (defcustom org-agenda-todo-keyword-format "%-1s"
  1484. "Format for the TODO keyword in agenda lines.
  1485. Set this to something like \"%-12s\" if you want all TODO keywords
  1486. to occupy a fixed space in the agenda display."
  1487. :group 'org-agenda-line-format
  1488. :type 'string)
  1489. (defcustom org-agenda-diary-sexp-prefix nil
  1490. "A regexp that matches part of a diary sexp entry
  1491. which should be treated as scheduling/deadline information in
  1492. `org-agenda'.
  1493. For example, you can use this to extract the `diary-remind-message' from
  1494. `diary-remind' entries."
  1495. :group 'org-agenda-line-format
  1496. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1497. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1498. "Text preceding timerange entries in the agenda view.
  1499. This is a list with two strings. The first applies when the range
  1500. is entirely on one day. The second applies if the range spans several days.
  1501. The strings may have two \"%d\" format specifiers which will be filled
  1502. with the sequence number of the days, and the total number of days in the
  1503. range, respectively."
  1504. :group 'org-agenda-line-format
  1505. :type '(list
  1506. (string :tag "Deadline today ")
  1507. (choice :tag "Deadline relative"
  1508. (string :tag "Format string")
  1509. (function))))
  1510. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1511. "Text preceding scheduled items in the agenda view.
  1512. This is a list with two strings. The first applies when the item is
  1513. scheduled on the current day. The second applies when it has been scheduled
  1514. previously, it may contain a %d indicating that this is the nth time that
  1515. this item is scheduled, due to automatic rescheduling of unfinished items
  1516. for the following day. So this number is one larger than the number of days
  1517. that passed since this item was scheduled first."
  1518. :group 'org-agenda-line-format
  1519. :version "24.4"
  1520. :package-version '(Org . "8.0")
  1521. :type '(list
  1522. (string :tag "Scheduled today ")
  1523. (string :tag "Scheduled previously")))
  1524. (defcustom org-agenda-inactive-leader "["
  1525. "Text preceding item pulled into the agenda by inactive time stamps.
  1526. These entries are added to the agenda when pressing \"[\"."
  1527. :group 'org-agenda-line-format
  1528. :version "24.1"
  1529. :type 'string)
  1530. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1531. "Text preceding deadline items in the agenda view.
  1532. This is a list with three strings. The first applies when the item has its
  1533. deadline on the current day. The second applies when the deadline is in the
  1534. future, the third one when it is in the past. The strings may contain %d
  1535. to capture the number of days."
  1536. :group 'org-agenda-line-format
  1537. :version "24.4"
  1538. :package-version '(Org . "8.0")
  1539. :type '(list
  1540. (string :tag "Deadline today ")
  1541. (string :tag "Deadline in the future ")
  1542. (string :tag "Deadline in the past ")))
  1543. (defcustom org-agenda-remove-times-when-in-prefix t
  1544. "Non-nil means remove duplicate time specifications in agenda items.
  1545. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1546. time-of-day specification in a headline or diary entry is extracted and
  1547. placed into the prefix. If this option is non-nil, the original specification
  1548. \(a timestamp or -range, or just a plain time(range) specification like
  1549. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1550. cluttered.
  1551. The option can be t or nil. It may also be the symbol `beg', indicating
  1552. that the time should only be removed when it is located at the beginning of
  1553. the headline/diary entry."
  1554. :group 'org-agenda-line-format
  1555. :type '(choice
  1556. (const :tag "Always" t)
  1557. (const :tag "Never" nil)
  1558. (const :tag "When at beginning of entry" beg)))
  1559. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1560. "Non-nil means remove time ranges specifications in agenda
  1561. items that span on several days."
  1562. :group 'org-agenda-line-format
  1563. :version "24.1"
  1564. :type 'boolean)
  1565. (defcustom org-agenda-default-appointment-duration nil
  1566. "Default duration for appointments that only have a starting time.
  1567. When nil, no duration is specified in such cases.
  1568. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1569. :group 'org-agenda-line-format
  1570. :type '(choice
  1571. (integer :tag "Minutes")
  1572. (const :tag "No default duration")))
  1573. (defcustom org-agenda-show-inherited-tags t
  1574. "Non-nil means show inherited tags in each agenda line.
  1575. When this option is set to 'always, it take precedences over
  1576. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1577. in every agenda.
  1578. When this option is set to t (the default), inherited tags are
  1579. shown when they are available, i.e. when the value of
  1580. `org-agenda-use-tag-inheritance' has been taken into account.
  1581. This can be set to a list of agenda types in which the agenda
  1582. must display the inherited tags. Available types are 'todo,
  1583. 'agenda, 'search and 'timeline.
  1584. When set to nil, never show inherited tags in agenda lines."
  1585. :group 'org-agenda-line-format
  1586. :group 'org-agenda
  1587. :version "24.3"
  1588. :type '(choice
  1589. (const :tag "Show inherited tags when available" t)
  1590. (const :tag "Always show inherited tags" always)
  1591. (repeat :tag "Show inherited tags only in selected agenda types"
  1592. (symbol :tag "Agenda type"))))
  1593. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1594. "List of agenda view types where to use tag inheritance.
  1595. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1596. controlled by `org-use-tag-inheritance'. In other agenda types,
  1597. `org-use-tag-inheritance' is not used for the selection of the
  1598. agenda entries. Still, you may want the agenda to be aware of
  1599. the inherited tags anyway, e.g. for later tag filtering.
  1600. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1601. This variable has no effect if `org-agenda-show-inherited-tags'
  1602. is set to 'always. In that case, the agenda is aware of those
  1603. tags.
  1604. The default value sets tags in every agenda type. Setting this
  1605. option to nil will speed up non-tags agenda view a lot."
  1606. :group 'org-agenda
  1607. :version "24.3"
  1608. :type '(choice
  1609. (const :tag "Use tag inheritance in all agenda types" t)
  1610. (repeat :tag "Use tag inheritance in selected agenda types"
  1611. (symbol :tag "Agenda type"))))
  1612. (defcustom org-agenda-hide-tags-regexp nil
  1613. "Regular expression used to filter away specific tags in agenda views.
  1614. This means that these tags will be present, but not be shown in the agenda
  1615. line. Secondary filtering will still work on the hidden tags.
  1616. Nil means don't hide any tags."
  1617. :group 'org-agenda-line-format
  1618. :type '(choice
  1619. (const :tag "Hide none" nil)
  1620. (string :tag "Regexp ")))
  1621. (defcustom org-agenda-remove-tags nil
  1622. "Non-nil means remove the tags from the headline copy in the agenda.
  1623. When this is the symbol `prefix', only remove tags when
  1624. `org-agenda-prefix-format' contains a `%T' specifier."
  1625. :group 'org-agenda-line-format
  1626. :type '(choice
  1627. (const :tag "Always" t)
  1628. (const :tag "Never" nil)
  1629. (const :tag "When prefix format contains %T" prefix)))
  1630. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1631. 'org-agenda-remove-tags)
  1632. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1633. "Shift tags in agenda items to this column.
  1634. If this number is positive, it specifies the column. If it is negative,
  1635. it means that the tags should be flushright to that column. For example,
  1636. -80 works well for a normal 80 character screen."
  1637. :group 'org-agenda-line-format
  1638. :type 'integer)
  1639. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1640. (defcustom org-agenda-fontify-priorities 'cookies
  1641. "Non-nil means highlight low and high priorities in agenda.
  1642. When t, the highest priority entries are bold, lowest priority italic.
  1643. However, settings in `org-priority-faces' will overrule these faces.
  1644. When this variable is the symbol `cookies', only fontify the
  1645. cookies, not the entire task.
  1646. This may also be an association list of priority faces, whose
  1647. keys are the character values of `org-highest-priority',
  1648. `org-default-priority', and `org-lowest-priority' (the default values
  1649. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1650. color as a string, or a list like `(:background \"Red\")'.
  1651. If it is a color, the variable `org-faces-easy-properties'
  1652. determines if it is a foreground or a background color."
  1653. :group 'org-agenda-line-format
  1654. :type '(choice
  1655. (const :tag "Never" nil)
  1656. (const :tag "Defaults" t)
  1657. (const :tag "Cookies only" cookies)
  1658. (repeat :tag "Specify"
  1659. (list (character :tag "Priority" :value ?A)
  1660. (choice :tag "Face "
  1661. (string :tag "Color")
  1662. (sexp :tag "Face"))))))
  1663. (defcustom org-agenda-day-face-function nil
  1664. "Function called to determine what face should be used to display a day.
  1665. The only argument passed to that function is the day. It should
  1666. returns a face, or nil if does not want to specify a face and let
  1667. the normal rules apply."
  1668. :group 'org-agenda-line-format
  1669. :version "24.1"
  1670. :type '(choice (const nil) (function)))
  1671. (defcustom org-agenda-category-icon-alist nil
  1672. "Alist of category icon to be displayed in agenda views.
  1673. Each entry should have the following format:
  1674. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1675. Where CATEGORY-REGEXP is a regexp matching the categories where
  1676. the icon should be displayed.
  1677. FILE-OR-DATA either a file path or a string containing image data.
  1678. The other fields can be omitted safely if not needed:
  1679. TYPE indicates the image type.
  1680. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1681. image data.
  1682. PROPS are additional image attributes to assign to the image,
  1683. like, e.g. `:ascent center'.
  1684. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1685. If you want to set the display properties yourself, just put a
  1686. list as second element:
  1687. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1688. For example, to display a 16px horizontal space for Emacs
  1689. category, you can use:
  1690. (\"Emacs\" '(space . (:width (16))))"
  1691. :group 'org-agenda-line-format
  1692. :version "24.1"
  1693. :type '(alist :key-type (string :tag "Regexp matching category")
  1694. :value-type (choice (list :tag "Icon"
  1695. (string :tag "File or data")
  1696. (symbol :tag "Type")
  1697. (boolean :tag "Data?")
  1698. (repeat :tag "Extra image properties" :inline t symbol))
  1699. (list :tag "Display properties" sexp))))
  1700. (defgroup org-agenda-column-view nil
  1701. "Options concerning column view in the agenda."
  1702. :tag "Org Agenda Column View"
  1703. :group 'org-agenda)
  1704. (defcustom org-agenda-columns-show-summaries t
  1705. "Non-nil means show summaries for columns displayed in the agenda view."
  1706. :group 'org-agenda-column-view
  1707. :type 'boolean)
  1708. (defcustom org-agenda-columns-compute-summary-properties t
  1709. "Non-nil means recompute all summary properties before column view.
  1710. When column view in the agenda is listing properties that have a summary
  1711. operator, it can go to all relevant buffers and recompute the summaries
  1712. there. This can mean overhead for the agenda column view, but is necessary
  1713. to have thing up to date.
  1714. As a special case, a CLOCKSUM property also makes sure that the clock
  1715. computations are current."
  1716. :group 'org-agenda-column-view
  1717. :type 'boolean)
  1718. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1719. "Non-nil means the duration of an appointment will add to day effort.
  1720. The property to which appointment durations will be added is the one given
  1721. in the option `org-effort-property'. If an appointment does not have
  1722. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1723. is not set, an appointment without end time will not contribute to the time
  1724. estimate."
  1725. :group 'org-agenda-column-view
  1726. :type 'boolean)
  1727. (defcustom org-agenda-auto-exclude-function nil
  1728. "A function called with a tag to decide if it is filtered on '/ RET'.
  1729. The sole argument to the function, which is called once for each
  1730. possible tag, is a string giving the name of the tag. The
  1731. function should return either nil if the tag should be included
  1732. as normal, or \"-<TAG>\" to exclude the tag.
  1733. Note that for the purpose of tag filtering, only the lower-case version of
  1734. all tags will be considered, so that this function will only ever see
  1735. the lower-case version of all tags."
  1736. :group 'org-agenda
  1737. :type '(choice (const nil) (function)))
  1738. (defcustom org-agenda-bulk-custom-functions nil
  1739. "Alist of characters and custom functions for bulk actions.
  1740. For example, this value makes those two functions available:
  1741. '((?R set-category)
  1742. (?C bulk-cut))
  1743. With selected entries in an agenda buffer, `B R' will call
  1744. the custom function `set-category' on the selected entries.
  1745. Note that functions in this alist don't need to be quoted."
  1746. :type 'alist
  1747. :version "24.1"
  1748. :group 'org-agenda)
  1749. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1750. "Execute BODY with point at location given by `org-hd-marker' property.
  1751. If STRING is non-nil, the text property will be fetched from position 0
  1752. in that string. If STRING is nil, it will be fetched from the beginning
  1753. of the current line."
  1754. (org-with-gensyms (marker)
  1755. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1756. 'org-hd-marker ,string)))
  1757. (with-current-buffer (marker-buffer ,marker)
  1758. (save-excursion
  1759. (goto-char ,marker)
  1760. ,@body)))))
  1761. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1762. (defun org-add-agenda-custom-command (entry)
  1763. "Replace or add a command in `org-agenda-custom-commands'.
  1764. This is mostly for hacking and trying a new command - once the command
  1765. works you probably want to add it to `org-agenda-custom-commands' for good."
  1766. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1767. (if ass
  1768. (setcdr ass (cdr entry))
  1769. (push entry org-agenda-custom-commands))))
  1770. ;;; Define the org-agenda-mode
  1771. (defvar org-agenda-mode-map (make-sparse-keymap)
  1772. "Keymap for `org-agenda-mode'.")
  1773. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1774. (defvar org-agenda-menu) ; defined later in this file.
  1775. (defvar org-agenda-restrict nil) ; defined later in this file.
  1776. (defvar org-agenda-follow-mode nil)
  1777. (defvar org-agenda-entry-text-mode nil)
  1778. (defvar org-agenda-clockreport-mode nil)
  1779. (defvar org-agenda-show-log nil)
  1780. (defvar org-agenda-redo-command nil)
  1781. (defvar org-agenda-query-string nil)
  1782. (defvar org-agenda-mode-hook nil
  1783. "Hook run after `org-agenda-mode' is turned on.
  1784. The buffer is still writable when this hook is called.")
  1785. (defvar org-agenda-type nil)
  1786. (defvar org-agenda-force-single-file nil)
  1787. (defvar org-agenda-bulk-marked-entries nil
  1788. "List of markers that refer to marked entries in the agenda.")
  1789. ;;; Multiple agenda buffers support
  1790. (defcustom org-agenda-sticky nil
  1791. "Non-nil means agenda q key will bury agenda buffers.
  1792. Agenda commands will then show existing buffer instead of generating new ones.
  1793. When nil, `q' will kill the single agenda buffer."
  1794. :group 'org-agenda
  1795. :version "24.3"
  1796. :type 'boolean)
  1797. ;;;###autoload
  1798. (defun org-toggle-sticky-agenda (&optional arg)
  1799. "Toggle `org-agenda-sticky'."
  1800. (interactive "P")
  1801. (let ((new-value (if arg
  1802. (> (prefix-numeric-value arg) 0)
  1803. (not org-agenda-sticky))))
  1804. (if (equal new-value org-agenda-sticky)
  1805. (and (org-called-interactively-p 'interactive)
  1806. (message "Sticky agenda was already %s"
  1807. (if org-agenda-sticky "enabled" "disabled")))
  1808. (setq org-agenda-sticky new-value)
  1809. (org-agenda-kill-all-agenda-buffers)
  1810. (and (org-called-interactively-p 'interactive)
  1811. (message "Sticky agenda was %s"
  1812. (if org-agenda-sticky "enabled" "disabled"))))))
  1813. (defvar org-agenda-buffer nil
  1814. "Agenda buffer currently being generated.")
  1815. (defvar org-agenda-last-prefix-arg nil)
  1816. (defvar org-agenda-this-buffer-name nil)
  1817. (defvar org-agenda-doing-sticky-redo nil)
  1818. (defvar org-agenda-this-buffer-is-sticky nil)
  1819. (defconst org-agenda-local-vars
  1820. '(org-agenda-this-buffer-name
  1821. org-agenda-undo-list
  1822. org-agenda-pending-undo-list
  1823. org-agenda-follow-mode
  1824. org-agenda-entry-text-mode
  1825. org-agenda-clockreport-mode
  1826. org-agenda-show-log
  1827. org-agenda-redo-command
  1828. org-agenda-query-string
  1829. org-agenda-type
  1830. org-agenda-bulk-marked-entries
  1831. org-agenda-undo-has-started-in
  1832. org-agenda-info
  1833. org-agenda-pre-window-conf
  1834. org-agenda-columns-active
  1835. org-agenda-tag-filter
  1836. org-agenda-category-filter
  1837. org-agenda-top-headline-filter
  1838. org-agenda-regexp-filter
  1839. org-agenda-markers
  1840. org-agenda-last-search-view-search-was-boolean
  1841. org-agenda-filtered-by-category
  1842. org-agenda-filter-form
  1843. org-agenda-cycle-counter
  1844. org-agenda-last-prefix-arg)
  1845. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1846. (defun org-agenda-mode ()
  1847. "Mode for time-sorted view on action items in Org-mode files.
  1848. The following commands are available:
  1849. \\{org-agenda-mode-map}"
  1850. (interactive)
  1851. (cond (org-agenda-doing-sticky-redo
  1852. ;; Refreshing sticky agenda-buffer
  1853. ;;
  1854. ;; Preserve the value of `org-agenda-local-vars' variables,
  1855. ;; while letting `kill-all-local-variables' kill the rest
  1856. (let ((save (buffer-local-variables)))
  1857. (kill-all-local-variables)
  1858. (mapc 'make-local-variable org-agenda-local-vars)
  1859. (dolist (elem save)
  1860. (let ((var (car elem))
  1861. (val (cdr elem)))
  1862. (when (and val
  1863. (member var org-agenda-local-vars))
  1864. (set var val)))))
  1865. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1866. (org-agenda-sticky
  1867. ;; Creating a sticky Agenda buffer for the first time
  1868. (kill-all-local-variables)
  1869. (mapc 'make-local-variable org-agenda-local-vars)
  1870. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1871. (t
  1872. ;; Creating a non-sticky agenda buffer
  1873. (kill-all-local-variables)
  1874. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1875. (setq org-agenda-undo-list nil
  1876. org-agenda-pending-undo-list nil
  1877. org-agenda-bulk-marked-entries nil)
  1878. (setq major-mode 'org-agenda-mode)
  1879. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1880. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1881. (setq mode-name "Org-Agenda")
  1882. (setq indent-tabs-mode nil)
  1883. (use-local-map org-agenda-mode-map)
  1884. (easy-menu-add org-agenda-menu)
  1885. (if org-startup-truncated (setq truncate-lines t))
  1886. (org-set-local 'line-move-visual nil)
  1887. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1888. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1889. ;; Make sure properties are removed when copying text
  1890. (org-add-hook 'filter-buffer-substring-functions
  1891. (lambda (fun start end delete)
  1892. (substring-no-properties (funcall fun start end delete)))
  1893. nil t)
  1894. (unless org-agenda-keep-modes
  1895. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1896. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1897. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1898. org-agenda-show-log org-agenda-start-with-log-mode))
  1899. (easy-menu-change
  1900. '("Agenda") "Agenda Files"
  1901. (append
  1902. (list
  1903. (vector
  1904. (if (get 'org-agenda-files 'org-restrict)
  1905. "Restricted to single file"
  1906. "Edit File List")
  1907. '(org-edit-agenda-file-list)
  1908. (not (get 'org-agenda-files 'org-restrict)))
  1909. "--")
  1910. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1911. (org-agenda-set-mode-name)
  1912. (apply
  1913. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1914. (list 'org-agenda-mode-hook)))
  1915. (substitute-key-definition 'undo 'org-agenda-undo
  1916. org-agenda-mode-map global-map)
  1917. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1918. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1919. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1920. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1921. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1922. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1923. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1924. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1925. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1926. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1927. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1928. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1929. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1930. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1931. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1932. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1933. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1934. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1935. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1936. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1940. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1941. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1942. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1943. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1944. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1945. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1946. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1947. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1948. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1949. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1950. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1951. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1952. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1953. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1954. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1955. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1956. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1957. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1958. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1959. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1960. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1961. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1962. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1963. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1964. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1965. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1966. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1967. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1968. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1969. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1970. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1971. (while l (org-defkey org-agenda-mode-map
  1972. (int-to-string (pop l)) 'digit-argument)))
  1973. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1974. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1975. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1976. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1977. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1978. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1979. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1980. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1981. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1982. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1983. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1984. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1985. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1986. 'org-clock-modify-effort-estimate)
  1987. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1988. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1989. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1990. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1991. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1992. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1993. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1994. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1995. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1996. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1997. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1998. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1999. (substitute-key-definition 'next-line 'org-agenda-next-line
  2000. org-agenda-mode-map global-map)
  2001. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2002. org-agenda-mode-map global-map)
  2003. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2004. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2005. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2006. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2007. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2008. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2009. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2010. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2011. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2012. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2013. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2014. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2015. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2016. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2017. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2018. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2019. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2020. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2021. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2022. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2023. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2024. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2025. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2026. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2027. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2028. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2029. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2030. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2031. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2033. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2034. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2035. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2036. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2037. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2038. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2039. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2040. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2041. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2042. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2043. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2044. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2045. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2046. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2048. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2049. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2050. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2051. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2052. (when org-agenda-mouse-1-follows-link
  2053. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2054. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2055. '("Agenda"
  2056. ("Agenda Files")
  2057. "--"
  2058. ("Agenda Dates"
  2059. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2060. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2061. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2062. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2063. "--"
  2064. ("View"
  2065. ["Day View" org-agenda-day-view
  2066. :active (org-agenda-check-type nil 'agenda)
  2067. :style radio :selected (eq org-agenda-current-span 'day)
  2068. :keys "v d (or just d)"]
  2069. ["Week View" org-agenda-week-view
  2070. :active (org-agenda-check-type nil 'agenda)
  2071. :style radio :selected (eq org-agenda-current-span 'week)
  2072. :keys "v w"]
  2073. ["Fortnight View" org-agenda-fortnight-view
  2074. :active (org-agenda-check-type nil 'agenda)
  2075. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2076. :keys "v f"]
  2077. ["Month View" org-agenda-month-view
  2078. :active (org-agenda-check-type nil 'agenda)
  2079. :style radio :selected (eq org-agenda-current-span 'month)
  2080. :keys "v m"]
  2081. ["Year View" org-agenda-year-view
  2082. :active (org-agenda-check-type nil 'agenda)
  2083. :style radio :selected (eq org-agenda-current-span 'year)
  2084. :keys "v y"]
  2085. "--"
  2086. ["Include Diary" org-agenda-toggle-diary
  2087. :style toggle :selected org-agenda-include-diary
  2088. :active (org-agenda-check-type nil 'agenda)]
  2089. ["Include Deadlines" org-agenda-toggle-deadlines
  2090. :style toggle :selected org-agenda-include-deadlines
  2091. :active (org-agenda-check-type nil 'agenda)]
  2092. ["Use Time Grid" org-agenda-toggle-time-grid
  2093. :style toggle :selected org-agenda-use-time-grid
  2094. :active (org-agenda-check-type nil 'agenda)]
  2095. "--"
  2096. ["Show clock report" org-agenda-clockreport-mode
  2097. :style toggle :selected org-agenda-clockreport-mode
  2098. :active (org-agenda-check-type nil 'agenda)]
  2099. ["Show some entry text" org-agenda-entry-text-mode
  2100. :style toggle :selected org-agenda-entry-text-mode
  2101. :active t]
  2102. "--"
  2103. ["Show Logbook entries" org-agenda-log-mode
  2104. :style toggle :selected org-agenda-show-log
  2105. :active (org-agenda-check-type nil 'agenda 'timeline)
  2106. :keys "v l (or just l)"]
  2107. ["Include archived trees" org-agenda-archives-mode
  2108. :style toggle :selected org-agenda-archives-mode :active t
  2109. :keys "v a"]
  2110. ["Include archive files" (org-agenda-archives-mode t)
  2111. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2112. :keys "v A"]
  2113. "--"
  2114. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2115. ["Write view to file" org-agenda-write t]
  2116. ["Rebuild buffer" org-agenda-redo t]
  2117. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2118. "--"
  2119. ["Show original entry" org-agenda-show t]
  2120. ["Go To (other window)" org-agenda-goto t]
  2121. ["Go To (this window)" org-agenda-switch-to t]
  2122. ["Capture with cursor date" org-agenda-capture t]
  2123. ["Follow Mode" org-agenda-follow-mode
  2124. :style toggle :selected org-agenda-follow-mode :active t]
  2125. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2126. "--"
  2127. ("TODO"
  2128. ["Cycle TODO" org-agenda-todo t]
  2129. ["Next TODO set" org-agenda-todo-nextset t]
  2130. ["Previous TODO set" org-agenda-todo-previousset t]
  2131. ["Add note" org-agenda-add-note t])
  2132. ("Archive/Refile/Delete"
  2133. ["Archive default" org-agenda-archive-default t]
  2134. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2135. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2136. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2137. ["Archive subtree" org-agenda-archive t]
  2138. "--"
  2139. ["Refile" org-agenda-refile t]
  2140. "--"
  2141. ["Delete subtree" org-agenda-kill t])
  2142. ("Bulk action"
  2143. ["Mark entry" org-agenda-bulk-mark t]
  2144. ["Mark all" org-agenda-bulk-mark-all t]
  2145. ["Unmark entry" org-agenda-bulk-unmark t]
  2146. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2147. ["Toggle mark" org-agenda-bulk-toggle t]
  2148. ["Toggle all" org-agenda-bulk-toggle-all t]
  2149. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2150. ["Act on all marked" org-agenda-bulk-action t]
  2151. "--"
  2152. ("Tags and Properties"
  2153. ["Show all Tags" org-agenda-show-tags t]
  2154. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2155. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2156. "--"
  2157. ["Column View" org-columns t])
  2158. ("Deadline/Schedule"
  2159. ["Schedule" org-agenda-schedule t]
  2160. ["Set Deadline" org-agenda-deadline t]
  2161. "--"
  2162. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2163. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2164. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2165. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2166. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2167. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2168. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2169. ("Clock and Effort"
  2170. ["Clock in" org-agenda-clock-in t]
  2171. ["Clock out" org-agenda-clock-out t]
  2172. ["Clock cancel" org-agenda-clock-cancel t]
  2173. ["Goto running clock" org-clock-goto t]
  2174. "--"
  2175. ["Set Effort" org-agenda-set-effort t]
  2176. ["Change clocked effort" org-clock-modify-effort-estimate
  2177. (org-clock-is-active)])
  2178. ("Priority"
  2179. ["Set Priority" org-agenda-priority t]
  2180. ["Increase Priority" org-agenda-priority-up t]
  2181. ["Decrease Priority" org-agenda-priority-down t]
  2182. ["Show Priority" org-show-priority t])
  2183. ("Calendar/Diary"
  2184. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2185. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2186. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2188. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2189. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2190. "--"
  2191. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2192. "--"
  2193. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2194. "--"
  2195. ("MobileOrg"
  2196. ["Push Files and Views" org-mobile-push t]
  2197. ["Get Captured and Flagged" org-mobile-pull t]
  2198. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2199. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2200. "--"
  2201. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2202. "--"
  2203. ["Quit" org-agenda-quit t]
  2204. ["Exit and Release Buffers" org-agenda-exit t]
  2205. ))
  2206. ;;; Agenda undo
  2207. (defvar org-agenda-allow-remote-undo t
  2208. "Non-nil means allow remote undo from the agenda buffer.")
  2209. (defvar org-agenda-undo-has-started-in nil
  2210. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2211. (defun org-agenda-undo ()
  2212. "Undo a remote editing step in the agenda.
  2213. This undoes changes both in the agenda buffer and in the remote buffer
  2214. that have been changed along."
  2215. (interactive)
  2216. (or org-agenda-allow-remote-undo
  2217. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2218. (if (not (eq this-command last-command))
  2219. (setq org-agenda-undo-has-started-in nil
  2220. org-agenda-pending-undo-list org-agenda-undo-list))
  2221. (if (not org-agenda-pending-undo-list)
  2222. (user-error "No further undo information"))
  2223. (let* ((entry (pop org-agenda-pending-undo-list))
  2224. buf line cmd rembuf)
  2225. (setq cmd (pop entry) line (pop entry))
  2226. (setq rembuf (nth 2 entry))
  2227. (org-with-remote-undo rembuf
  2228. (while (bufferp (setq buf (pop entry)))
  2229. (if (pop entry)
  2230. (with-current-buffer buf
  2231. (let ((last-undo-buffer buf)
  2232. (inhibit-read-only t))
  2233. (unless (memq buf org-agenda-undo-has-started-in)
  2234. (push buf org-agenda-undo-has-started-in)
  2235. (make-local-variable 'pending-undo-list)
  2236. (undo-start))
  2237. (while (and pending-undo-list
  2238. (listp pending-undo-list)
  2239. (not (car pending-undo-list)))
  2240. (pop pending-undo-list))
  2241. (undo-more 1))))))
  2242. (org-goto-line line)
  2243. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2244. (defun org-verify-change-for-undo (l1 l2)
  2245. "Verify that a real change occurred between the undo lists L1 and L2."
  2246. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2247. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2248. (not (eq l1 l2)))
  2249. ;;; Agenda dispatch
  2250. (defvar org-agenda-restrict-begin (make-marker))
  2251. (defvar org-agenda-restrict-end (make-marker))
  2252. (defvar org-agenda-last-dispatch-buffer nil)
  2253. (defvar org-agenda-overriding-restriction nil)
  2254. (defcustom org-agenda-custom-commands-contexts nil
  2255. "Alist of custom agenda keys and contextual rules.
  2256. For example, if you have a custom agenda command \"p\" and you
  2257. want this command to be accessible only from plain text files,
  2258. use this:
  2259. '((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2260. Here are the available contexts definitions:
  2261. in-file: command displayed only in matching files
  2262. in-mode: command displayed only in matching modes
  2263. not-in-file: command not displayed in matching files
  2264. not-in-mode: command not displayed in matching modes
  2265. in-buffer: command displayed only in matching buffers
  2266. not-in-buffer: command not displayed in matching buffers
  2267. [function]: a custom function taking no argument
  2268. If you define several checks, the agenda command will be
  2269. accessible if there is at least one valid check.
  2270. You can also bind a key to another agenda custom command
  2271. depending on contextual rules.
  2272. '((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2273. Here it means: in .txt files, use \"p\" as the key for the
  2274. agenda command otherwise associated with \"q\". (The command
  2275. originally associated with \"q\" is not displayed to avoid
  2276. duplicates.)"
  2277. :version "24.3"
  2278. :group 'org-agenda-custom-commands
  2279. :type '(repeat (list :tag "Rule"
  2280. (string :tag " Agenda key")
  2281. (string :tag "Replace by command")
  2282. (repeat :tag "Available when"
  2283. (choice
  2284. (cons :tag "Condition"
  2285. (choice
  2286. (const :tag "In file" in-file)
  2287. (const :tag "Not in file" not-in-file)
  2288. (const :tag "In buffer" in-buffer)
  2289. (const :tag "Not in buffer" not-in-buffer)
  2290. (const :tag "In mode" in-mode)
  2291. (const :tag "Not in mode" not-in-mode))
  2292. (regexp))
  2293. (function :tag "Custom function"))))))
  2294. (defcustom org-agenda-max-entries nil
  2295. "Maximum number of entries to display in an agenda.
  2296. This can be nil (no limit) or an integer or an alist of agenda
  2297. types with an associated number of entries to display in this
  2298. type."
  2299. :version "24.4"
  2300. :package-version '(Org . "8.0")
  2301. :group 'org-agenda-custom-commands
  2302. :type '(choice (symbol :tag "No limit" nil)
  2303. (integer :tag "Max number of entries")
  2304. (repeat
  2305. (cons (choice :tag "Agenda type"
  2306. (const agenda)
  2307. (const todo)
  2308. (const tags)
  2309. (const search)
  2310. (const timeline))
  2311. (integer :tag "Max number of entries")))))
  2312. (defcustom org-agenda-max-todos nil
  2313. "Maximum number of TODOs to display in an agenda.
  2314. This can be nil (no limit) or an integer or an alist of agenda
  2315. types with an associated number of entries to display in this
  2316. type."
  2317. :version "24.4"
  2318. :package-version '(Org . "8.0")
  2319. :group 'org-agenda-custom-commands
  2320. :type '(choice (symbol :tag "No limit" nil)
  2321. (integer :tag "Max number of TODOs")
  2322. (repeat
  2323. (cons (choice :tag "Agenda type"
  2324. (const agenda)
  2325. (const todo)
  2326. (const tags)
  2327. (const search)
  2328. (const timeline))
  2329. (integer :tag "Max number of TODOs")))))
  2330. (defcustom org-agenda-max-tags nil
  2331. "Maximum number of tagged entries to display in an agenda.
  2332. This can be nil (no limit) or an integer or an alist of agenda
  2333. types with an associated number of entries to display in this
  2334. type."
  2335. :version "24.4"
  2336. :package-version '(Org . "8.0")
  2337. :group 'org-agenda-custom-commands
  2338. :type '(choice (symbol :tag "No limit" nil)
  2339. (integer :tag "Max number of tagged entries")
  2340. (repeat
  2341. (cons (choice :tag "Agenda type"
  2342. (const agenda)
  2343. (const todo)
  2344. (const tags)
  2345. (const search)
  2346. (const timeline))
  2347. (integer :tag "Max number of tagged entries")))))
  2348. (defcustom org-agenda-max-effort nil
  2349. "Maximum cumulated effort duration for the agenda.
  2350. This can be nil (no limit) or a number of minutes (as an integer)
  2351. or an alist of agenda types with an associated number of minutes
  2352. to limit entries to in this type."
  2353. :version "24.4"
  2354. :package-version '(Org . "8.0")
  2355. :group 'org-agenda-custom-commands
  2356. :type '(choice (symbol :tag "No limit" nil)
  2357. (integer :tag "Max number of minutes")
  2358. (repeat
  2359. (cons (choice :tag "Agenda type"
  2360. (const agenda)
  2361. (const todo)
  2362. (const tags)
  2363. (const search)
  2364. (const timeline))
  2365. (integer :tag "Max number of minutes")))))
  2366. (defvar org-keys nil)
  2367. (defvar org-match nil)
  2368. ;;;###autoload
  2369. (defun org-agenda (&optional arg org-keys restriction)
  2370. "Dispatch agenda commands to collect entries to the agenda buffer.
  2371. Prompts for a command to execute. Any prefix arg will be passed
  2372. on to the selected command. The default selections are:
  2373. a Call `org-agenda-list' to display the agenda for current day or week.
  2374. t Call `org-todo-list' to display the global todo list.
  2375. T Call `org-todo-list' to display the global todo list, select only
  2376. entries with a specific TODO keyword (the user gets a prompt).
  2377. m Call `org-tags-view' to display headlines with tags matching
  2378. a condition (the user is prompted for the condition).
  2379. M Like `m', but select only TODO entries, no ordinary headlines.
  2380. L Create a timeline for the current buffer.
  2381. e Export views to associated files.
  2382. s Search entries for keywords.
  2383. S Search entries for keywords, only with TODO keywords.
  2384. / Multi occur across all agenda files and also files listed
  2385. in `org-agenda-text-search-extra-files'.
  2386. < Restrict agenda commands to buffer, subtree, or region.
  2387. Press several times to get the desired effect.
  2388. > Remove a previous restriction.
  2389. # List \"stuck\" projects.
  2390. ! Configure what \"stuck\" means.
  2391. C Configure custom agenda commands.
  2392. More commands can be added by configuring the variable
  2393. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2394. searches can be pre-defined in this way.
  2395. If the current buffer is in Org-mode and visiting a file, you can also
  2396. first press `<' once to indicate that the agenda should be temporarily
  2397. \(until the next use of \\[org-agenda]) restricted to the current file.
  2398. Pressing `<' twice means to restrict to the current subtree or region
  2399. \(if active)."
  2400. (interactive "P")
  2401. (catch 'exit
  2402. (let* ((prefix-descriptions nil)
  2403. (org-agenda-buffer-name org-agenda-buffer-name)
  2404. (org-agenda-window-setup (if (equal (buffer-name)
  2405. org-agenda-buffer-name)
  2406. 'current-window
  2407. org-agenda-window-setup))
  2408. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2409. (org-agenda-custom-commands
  2410. ;; normalize different versions
  2411. (delq nil
  2412. (mapcar
  2413. (lambda (x)
  2414. (cond ((stringp (cdr x))
  2415. (push x prefix-descriptions)
  2416. nil)
  2417. ((stringp (nth 1 x)) x)
  2418. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2419. (t (cons (car x) (cons "" (cdr x))))))
  2420. org-agenda-custom-commands)))
  2421. (org-agenda-custom-commands
  2422. (org-contextualize-keys
  2423. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2424. (buf (current-buffer))
  2425. (bfn (buffer-file-name (buffer-base-buffer)))
  2426. entry key type org-match lprops ans)
  2427. ;; Turn off restriction unless there is an overriding one,
  2428. (unless org-agenda-overriding-restriction
  2429. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2430. ;; There is a request to keep the file list in place
  2431. (put 'org-agenda-files 'org-restrict nil))
  2432. (setq org-agenda-restrict nil)
  2433. (move-marker org-agenda-restrict-begin nil)
  2434. (move-marker org-agenda-restrict-end nil))
  2435. ;; Delete old local properties
  2436. (put 'org-agenda-redo-command 'org-lprops nil)
  2437. ;; Delete previously set last-arguments
  2438. (put 'org-agenda-redo-command 'last-args nil)
  2439. ;; Remember where this call originated
  2440. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2441. (unless org-keys
  2442. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2443. org-keys (car ans)
  2444. restriction (cdr ans)))
  2445. ;; If we have sticky agenda buffers, set a name for the buffer,
  2446. ;; depending on the invoking keys. The user may still set this
  2447. ;; as a command option, which will overwrite what we do here.
  2448. (if org-agenda-sticky
  2449. (setq org-agenda-buffer-name
  2450. (format "*Org Agenda(%s)*" org-keys)))
  2451. ;; Establish the restriction, if any
  2452. (when (and (not org-agenda-overriding-restriction) restriction)
  2453. (put 'org-agenda-files 'org-restrict (list bfn))
  2454. (cond
  2455. ((eq restriction 'region)
  2456. (setq org-agenda-restrict (current-buffer))
  2457. (move-marker org-agenda-restrict-begin (region-beginning))
  2458. (move-marker org-agenda-restrict-end (region-end)))
  2459. ((eq restriction 'subtree)
  2460. (save-excursion
  2461. (setq org-agenda-restrict (current-buffer))
  2462. (org-back-to-heading t)
  2463. (move-marker org-agenda-restrict-begin (point))
  2464. (move-marker org-agenda-restrict-end
  2465. (progn (org-end-of-subtree t)))))))
  2466. ;; For example the todo list should not need it (but does...)
  2467. (cond
  2468. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2469. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2470. (progn
  2471. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2472. lprops (nth 4 entry))
  2473. (if org-agenda-sticky
  2474. (setq org-agenda-buffer-name
  2475. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2476. (format "*Org Agenda(%s)*" org-keys))))
  2477. (put 'org-agenda-redo-command 'org-lprops lprops)
  2478. (cond
  2479. ((eq type 'agenda)
  2480. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2481. ((eq type 'agenda*)
  2482. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2483. ((eq type 'alltodo)
  2484. (org-let lprops '(org-todo-list current-prefix-arg)))
  2485. ((eq type 'search)
  2486. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2487. ((eq type 'stuck)
  2488. (org-let lprops '(org-agenda-list-stuck-projects
  2489. current-prefix-arg)))
  2490. ((eq type 'tags)
  2491. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2492. ((eq type 'tags-todo)
  2493. (org-let lprops '(org-tags-view '(4) org-match)))
  2494. ((eq type 'todo)
  2495. (org-let lprops '(org-todo-list org-match)))
  2496. ((eq type 'tags-tree)
  2497. (org-check-for-org-mode)
  2498. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2499. ((eq type 'todo-tree)
  2500. (org-check-for-org-mode)
  2501. (org-let lprops
  2502. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2503. (regexp-quote org-match) "\\>"))))
  2504. ((eq type 'occur-tree)
  2505. (org-check-for-org-mode)
  2506. (org-let lprops '(org-occur org-match)))
  2507. ((functionp type)
  2508. (org-let lprops '(funcall type org-match)))
  2509. ((fboundp type)
  2510. (org-let lprops '(funcall type org-match)))
  2511. (t (user-error "Invalid custom agenda command type %s" type))))
  2512. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2513. ((equal org-keys "C")
  2514. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2515. (customize-variable 'org-agenda-custom-commands))
  2516. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2517. ((equal org-keys "s") (call-interactively 'org-search-view))
  2518. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2519. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2520. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2521. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2522. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2523. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2524. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2525. (org-add-hook
  2526. 'post-command-hook
  2527. (lambda ()
  2528. (unless (current-message)
  2529. (let* ((m (org-agenda-get-any-marker))
  2530. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2531. (when note
  2532. (message (concat
  2533. "FLAGGING-NOTE ([?] for more info): "
  2534. (org-add-props
  2535. (replace-regexp-in-string
  2536. "\\\\n" "//"
  2537. (copy-sequence note))
  2538. nil 'face 'org-warning)))))))
  2539. t t))
  2540. ((equal org-keys "L")
  2541. (unless (derived-mode-p 'org-mode)
  2542. (user-error "This is not an Org-mode file"))
  2543. (unless restriction
  2544. (put 'org-agenda-files 'org-restrict (list bfn))
  2545. (org-call-with-arg 'org-timeline arg)))
  2546. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2547. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2548. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2549. (t (user-error "Invalid agenda key"))))))
  2550. (defvar org-agenda-multi)
  2551. (defun org-agenda-append-agenda ()
  2552. "Append another agenda view to the current one.
  2553. This function allows interactive building of block agendas.
  2554. Agenda views are separated by `org-agenda-block-separator'."
  2555. (interactive)
  2556. (unless (derived-mode-p 'org-agenda-mode)
  2557. (user-error "Can only append from within agenda buffer"))
  2558. (let ((org-agenda-multi t))
  2559. (org-agenda)
  2560. (widen)
  2561. (org-agenda-finalize)
  2562. (setq buffer-read-only t)
  2563. (org-agenda-fit-window-to-buffer)))
  2564. (defun org-agenda-normalize-custom-commands (cmds)
  2565. "Normalize custom commands CMDS."
  2566. (delq nil
  2567. (mapcar
  2568. (lambda (x)
  2569. (cond ((stringp (cdr x)) nil)
  2570. ((stringp (nth 1 x)) x)
  2571. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2572. (t (cons (car x) (cons "" (cdr x))))))
  2573. cmds)))
  2574. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2575. "The user interface for selecting an agenda command."
  2576. (catch 'exit
  2577. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2578. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2579. (region-p (org-region-active-p))
  2580. (custom org-agenda-custom-commands)
  2581. (selstring "")
  2582. restriction second-time
  2583. c entry key type match prefixes rmheader header-end custom1 desc
  2584. line lines left right n n1)
  2585. (save-window-excursion
  2586. (delete-other-windows)
  2587. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2588. (erase-buffer)
  2589. (insert (eval-when-compile
  2590. (let ((header
  2591. "Press key for an agenda command: < Buffer, subtree/region restriction
  2592. -------------------------------- > Remove restriction
  2593. a Agenda for current week or day e Export agenda views
  2594. t List of all TODO entries T Entries with special TODO kwd
  2595. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2596. s Search for keywords S Like s, but only TODO entries
  2597. L Timeline for current buffer # List stuck projects (!=configure)
  2598. / Multi-occur C Configure custom agenda commands
  2599. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2600. ")
  2601. (start 0))
  2602. (while (string-match
  2603. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2604. header start)
  2605. (setq start (match-end 0))
  2606. (add-text-properties (match-beginning 2) (match-end 2)
  2607. '(face bold) header))
  2608. header)))
  2609. (setq header-end (point-marker))
  2610. (while t
  2611. (setq custom1 custom)
  2612. (when (eq rmheader t)
  2613. (org-goto-line 1)
  2614. (re-search-forward ":" nil t)
  2615. (delete-region (match-end 0) (point-at-eol))
  2616. (forward-char 1)
  2617. (looking-at "-+")
  2618. (delete-region (match-end 0) (point-at-eol))
  2619. (move-marker header-end (match-end 0)))
  2620. (goto-char header-end)
  2621. (delete-region (point) (point-max))
  2622. ;; Produce all the lines that describe custom commands and prefixes
  2623. (setq lines nil)
  2624. (while (setq entry (pop custom1))
  2625. (setq key (car entry) desc (nth 1 entry)
  2626. type (nth 2 entry)
  2627. match (nth 3 entry))
  2628. (if (> (length key) 1)
  2629. (add-to-list 'prefixes (string-to-char key))
  2630. (setq line
  2631. (format
  2632. "%-4s%-14s"
  2633. (org-add-props (copy-sequence key)
  2634. '(face bold))
  2635. (cond
  2636. ((string-match "\\S-" desc) desc)
  2637. ((eq type 'agenda) "Agenda for current week or day")
  2638. ((eq type 'agenda*) "Appointments for current week or day")
  2639. ((eq type 'alltodo) "List of all TODO entries")
  2640. ((eq type 'search) "Word search")
  2641. ((eq type 'stuck) "List of stuck projects")
  2642. ((eq type 'todo) "TODO keyword")
  2643. ((eq type 'tags) "Tags query")
  2644. ((eq type 'tags-todo) "Tags (TODO)")
  2645. ((eq type 'tags-tree) "Tags tree")
  2646. ((eq type 'todo-tree) "TODO kwd tree")
  2647. ((eq type 'occur-tree) "Occur tree")
  2648. ((functionp type) (if (symbolp type)
  2649. (symbol-name type)
  2650. "Lambda expression"))
  2651. (t "???"))))
  2652. (if org-agenda-menu-show-matcher
  2653. (setq line
  2654. (concat line ": "
  2655. (cond
  2656. ((stringp match)
  2657. (setq match (copy-sequence match))
  2658. (org-add-props match nil 'face 'org-warning))
  2659. ((listp type)
  2660. (format "set of %d commands" (length type))))))
  2661. (if (org-string-nw-p match)
  2662. (add-text-properties
  2663. 0 (length line) (list 'help-echo
  2664. (concat "Matcher: " match)) line)))
  2665. (push line lines)))
  2666. (setq lines (nreverse lines))
  2667. (when prefixes
  2668. (mapc (lambda (x)
  2669. (push
  2670. (format "%s %s"
  2671. (org-add-props (char-to-string x)
  2672. nil 'face 'bold)
  2673. (or (cdr (assoc (concat selstring
  2674. (char-to-string x))
  2675. prefix-descriptions))
  2676. "Prefix key"))
  2677. lines))
  2678. prefixes))
  2679. ;; Check if we should display in two columns
  2680. (if org-agenda-menu-two-columns
  2681. (progn
  2682. (setq n (length lines)
  2683. n1 (+ (/ n 2) (mod n 2))
  2684. right (nthcdr n1 lines)
  2685. left (copy-sequence lines))
  2686. (setcdr (nthcdr (1- n1) left) nil))
  2687. (setq left lines right nil))
  2688. (while left
  2689. (insert "\n" (pop left))
  2690. (when right
  2691. (if (< (current-column) 40)
  2692. (move-to-column 40 t)
  2693. (insert " "))
  2694. (insert (pop right))))
  2695. ;; Make the window the right size
  2696. (goto-char (point-min))
  2697. (if second-time
  2698. (if (not (pos-visible-in-window-p (point-max)))
  2699. (org-fit-window-to-buffer))
  2700. (setq second-time t)
  2701. (org-fit-window-to-buffer))
  2702. ;; Ask for selection
  2703. (message "Press key for agenda command%s:"
  2704. (if (or restrict-ok org-agenda-overriding-restriction)
  2705. (if org-agenda-overriding-restriction
  2706. " (restriction lock active)"
  2707. (if restriction
  2708. (format " (restricted to %s)" restriction)
  2709. " (unrestricted)"))
  2710. ""))
  2711. (setq c (read-char-exclusive))
  2712. (message "")
  2713. (cond
  2714. ((assoc (char-to-string c) custom)
  2715. (setq selstring (concat selstring (char-to-string c)))
  2716. (throw 'exit (cons selstring restriction)))
  2717. ((memq c prefixes)
  2718. (setq selstring (concat selstring (char-to-string c))
  2719. prefixes nil
  2720. rmheader (or rmheader t)
  2721. custom (delq nil (mapcar
  2722. (lambda (x)
  2723. (if (or (= (length (car x)) 1)
  2724. (/= (string-to-char (car x)) c))
  2725. nil
  2726. (cons (substring (car x) 1) (cdr x))))
  2727. custom))))
  2728. ((eq c ?*)
  2729. (call-interactively 'org-toggle-sticky-agenda)
  2730. (sit-for 2))
  2731. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2732. (message "Restriction is only possible in Org-mode buffers")
  2733. (ding) (sit-for 1))
  2734. ((eq c ?1)
  2735. (org-agenda-remove-restriction-lock 'noupdate)
  2736. (setq restriction 'buffer))
  2737. ((eq c ?0)
  2738. (org-agenda-remove-restriction-lock 'noupdate)
  2739. (setq restriction (if region-p 'region 'subtree)))
  2740. ((eq c ?<)
  2741. (org-agenda-remove-restriction-lock 'noupdate)
  2742. (setq restriction
  2743. (cond
  2744. ((eq restriction 'buffer)
  2745. (if region-p 'region 'subtree))
  2746. ((memq restriction '(subtree region))
  2747. nil)
  2748. (t 'buffer))))
  2749. ((eq c ?>)
  2750. (org-agenda-remove-restriction-lock 'noupdate)
  2751. (setq restriction nil))
  2752. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2753. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2754. ((and (> (length selstring) 0) (eq c ?\d))
  2755. (delete-window)
  2756. (org-agenda-get-restriction-and-command prefix-descriptions))
  2757. ((equal c ?q) (error "Abort"))
  2758. (t (user-error "Invalid key %c" c))))))))
  2759. (defun org-agenda-fit-window-to-buffer ()
  2760. "Fit the window to the buffer size."
  2761. (and (memq org-agenda-window-setup '(reorganize-frame))
  2762. (fboundp 'fit-window-to-buffer)
  2763. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2764. (= (car org-agenda-window-frame-fractions) 1.0))
  2765. (delete-other-windows)
  2766. (org-fit-window-to-buffer
  2767. nil
  2768. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2769. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2770. (defvar org-cmd nil)
  2771. (defvar org-agenda-overriding-cmd nil)
  2772. (defvar org-agenda-overriding-arguments nil)
  2773. (defvar org-agenda-overriding-cmd-arguments nil)
  2774. (defun org-agenda-run-series (name series)
  2775. "Run agenda NAME as a SERIES of agenda commands."
  2776. (org-let (nth 1 series) '(org-agenda-prepare name))
  2777. ;; We need to reset agenda markers here, because when constructing a
  2778. ;; block agenda, the individual blocks do not do that.
  2779. (org-agenda-reset-markers)
  2780. (let* ((org-agenda-multi t)
  2781. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2782. (cmds (car series))
  2783. (gprops (nth 1 series))
  2784. match ;; The byte compiler incorrectly complains about this. Keep it!
  2785. org-cmd type lprops)
  2786. (while (setq org-cmd (pop cmds))
  2787. (setq type (car org-cmd)
  2788. match (eval (nth 1 org-cmd))
  2789. lprops (nth 2 org-cmd))
  2790. (let ((org-agenda-overriding-arguments
  2791. (if (eq org-agenda-overriding-cmd org-cmd)
  2792. (or org-agenda-overriding-arguments
  2793. org-agenda-overriding-cmd-arguments))))
  2794. (cond
  2795. ((eq type 'agenda)
  2796. (org-let2 gprops lprops
  2797. '(call-interactively 'org-agenda-list)))
  2798. ((eq type 'agenda*)
  2799. (org-let2 gprops lprops
  2800. '(funcall 'org-agenda-list nil nil t)))
  2801. ((eq type 'alltodo)
  2802. (org-let2 gprops lprops
  2803. '(call-interactively 'org-todo-list)))
  2804. ((eq type 'search)
  2805. (org-let2 gprops lprops
  2806. '(org-search-view current-prefix-arg match nil)))
  2807. ((eq type 'stuck)
  2808. (org-let2 gprops lprops
  2809. '(call-interactively 'org-agenda-list-stuck-projects)))
  2810. ((eq type 'tags)
  2811. (org-let2 gprops lprops
  2812. '(org-tags-view current-prefix-arg match)))
  2813. ((eq type 'tags-todo)
  2814. (org-let2 gprops lprops
  2815. '(org-tags-view '(4) match)))
  2816. ((eq type 'todo)
  2817. (org-let2 gprops lprops
  2818. '(org-todo-list match)))
  2819. ((fboundp type)
  2820. (org-let2 gprops lprops
  2821. '(funcall type match)))
  2822. (t (error "Invalid type in command series")))))
  2823. (widen)
  2824. (let ((inhibit-read-only t))
  2825. (add-text-properties (point-min) (point-max)
  2826. `(org-series t org-series-redo-cmd ,redo)))
  2827. (setq org-agenda-redo-command redo)
  2828. (goto-char (point-min)))
  2829. (org-agenda-fit-window-to-buffer)
  2830. (org-let (nth 1 series) '(org-agenda-finalize)))
  2831. ;;;###autoload
  2832. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2833. "Run an agenda command in batch mode and send the result to STDOUT.
  2834. If CMD-KEY is a string of length 1, it is used as a key in
  2835. `org-agenda-custom-commands' and triggers this command. If it is a
  2836. longer string it is used as a tags/todo match string.
  2837. Parameters are alternating variable names and values that will be bound
  2838. before running the agenda command."
  2839. (org-eval-in-environment (org-make-parameter-alist parameters)
  2840. (let (org-agenda-sticky)
  2841. (if (> (length cmd-key) 2)
  2842. (org-tags-view nil cmd-key)
  2843. (org-agenda nil cmd-key))))
  2844. (set-buffer org-agenda-buffer-name)
  2845. (princ (buffer-string)))
  2846. (defvar org-agenda-info nil)
  2847. ;;;###autoload
  2848. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2849. "Run an agenda command in batch mode and send the result to STDOUT.
  2850. If CMD-KEY is a string of length 1, it is used as a key in
  2851. `org-agenda-custom-commands' and triggers this command. If it is a
  2852. longer string it is used as a tags/todo match string.
  2853. Parameters are alternating variable names and values that will be bound
  2854. before running the agenda command.
  2855. The output gives a line for each selected agenda item. Each
  2856. item is a list of comma-separated values, like this:
  2857. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2858. category The category of the item
  2859. head The headline, without TODO kwd, TAGS and PRIORITY
  2860. type The type of the agenda entry, can be
  2861. todo selected in TODO match
  2862. tagsmatch selected in tags match
  2863. diary imported from diary
  2864. deadline a deadline on given date
  2865. scheduled scheduled on given date
  2866. timestamp entry has timestamp on given date
  2867. closed entry was closed on given date
  2868. upcoming-deadline warning about deadline
  2869. past-scheduled forwarded scheduled item
  2870. block entry has date block including g. date
  2871. todo The todo keyword, if any
  2872. tags All tags including inherited ones, separated by colons
  2873. date The relevant date, like 2007-2-14
  2874. time The time, like 15:00-16:50
  2875. extra Sting with extra planning info
  2876. priority-l The priority letter if any was given
  2877. priority-n The computed numerical priority
  2878. agenda-day The day in the agenda where this is listed"
  2879. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2880. (org-make-parameter-alist parameters))
  2881. (if (> (length cmd-key) 2)
  2882. (org-tags-view nil cmd-key)
  2883. (org-agenda nil cmd-key)))
  2884. (set-buffer org-agenda-buffer-name)
  2885. (let* ((lines (org-split-string (buffer-string) "\n"))
  2886. line)
  2887. (while (setq line (pop lines))
  2888. (catch 'next
  2889. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2890. (setq org-agenda-info
  2891. (org-fix-agenda-info (text-properties-at 0 line)))
  2892. (princ
  2893. (mapconcat 'org-agenda-export-csv-mapper
  2894. '(org-category txt type todo tags date time extra
  2895. priority-letter priority agenda-day)
  2896. ","))
  2897. (princ "\n")))))
  2898. (defun org-fix-agenda-info (props)
  2899. "Make sure all properties on an agenda item have a canonical form.
  2900. This ensures the export commands can easily use it."
  2901. (let (tmp re)
  2902. (when (setq tmp (plist-get props 'tags))
  2903. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2904. (when (setq tmp (plist-get props 'date))
  2905. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2906. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2907. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2908. (setq tmp (calendar-date-string tmp)))
  2909. (setq props (plist-put props 'date tmp)))
  2910. (when (setq tmp (plist-get props 'day))
  2911. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2912. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2913. (setq tmp (calendar-date-string tmp)))
  2914. (setq props (plist-put props 'day tmp))
  2915. (setq props (plist-put props 'agenda-day tmp)))
  2916. (when (setq tmp (plist-get props 'txt))
  2917. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2918. (plist-put props 'priority-letter (match-string 1 tmp))
  2919. (setq tmp (replace-match "" t t tmp)))
  2920. (when (and (setq re (plist-get props 'org-todo-regexp))
  2921. (setq re (concat "\\`\\.*" re " ?"))
  2922. (string-match re tmp))
  2923. (plist-put props 'todo (match-string 1 tmp))
  2924. (setq tmp (replace-match "" t t tmp)))
  2925. (plist-put props 'txt tmp)))
  2926. props)
  2927. (defun org-agenda-export-csv-mapper (prop)
  2928. (let ((res (plist-get org-agenda-info prop)))
  2929. (setq res
  2930. (cond
  2931. ((not res) "")
  2932. ((stringp res) res)
  2933. (t (prin1-to-string res))))
  2934. (while (string-match "," res)
  2935. (setq res (replace-match ";" t t res)))
  2936. (org-trim res)))
  2937. ;;;###autoload
  2938. (defun org-store-agenda-views (&rest parameters)
  2939. "Store agenda views."
  2940. (interactive)
  2941. (eval (list 'org-batch-store-agenda-views)))
  2942. ;;;###autoload
  2943. (defmacro org-batch-store-agenda-views (&rest parameters)
  2944. "Run all custom agenda commands that have a file argument."
  2945. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2946. (pop-up-frames nil)
  2947. (dir default-directory)
  2948. (pars (org-make-parameter-alist parameters))
  2949. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2950. (save-window-excursion
  2951. (while cmds
  2952. (setq cmd (pop cmds)
  2953. thiscmdkey (car cmd)
  2954. thiscmdcmd (cdr cmd)
  2955. match (nth 2 thiscmdcmd)
  2956. bufname (if org-agenda-sticky
  2957. (or (and (stringp match)
  2958. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2959. (format "*Org Agenda(%s)*" thiscmdkey))
  2960. org-agenda-buffer-name)
  2961. cmd-or-set (nth 2 cmd)
  2962. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2963. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2964. (if (stringp files) (setq files (list files)))
  2965. (when files
  2966. (org-eval-in-environment (append org-agenda-exporter-settings
  2967. opts pars)
  2968. (org-agenda nil thiscmdkey))
  2969. (set-buffer bufname)
  2970. (while files
  2971. (org-eval-in-environment (append org-agenda-exporter-settings
  2972. opts pars)
  2973. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2974. (and (get-buffer bufname)
  2975. (kill-buffer bufname)))))))
  2976. (defvar org-agenda-current-span nil
  2977. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2978. (defun org-agenda-mark-header-line (pos)
  2979. "Mark the line at POS as an agenda structure header."
  2980. (save-excursion
  2981. (goto-char pos)
  2982. (put-text-property (point-at-bol) (point-at-eol)
  2983. 'org-agenda-structural-header t)
  2984. (when org-agenda-title-append
  2985. (put-text-property (point-at-bol) (point-at-eol)
  2986. 'org-agenda-title-append org-agenda-title-append))))
  2987. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2988. (defvar org-agenda-write-buffer-name "Agenda View")
  2989. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2990. "Write the current buffer (an agenda view) as a file.
  2991. Depending on the extension of the file name, plain text (.txt),
  2992. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2993. If the extension is .ics, run icalendar export over all files used
  2994. to construct the agenda and limit the export to entries listed in the
  2995. agenda now.
  2996. If the extension is .org, collect all subtrees corresponding to the
  2997. agenda entries and add them in an .org file.
  2998. With prefix argument OPEN, open the new file immediately.
  2999. If NOSETTINGS is given, do not scope the settings of
  3000. `org-agenda-exporter-settings' into the export commands. This is used when
  3001. the settings have already been scoped and we do not wish to overrule other,
  3002. higher priority settings.
  3003. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3004. (interactive "FWrite agenda to file: \nP")
  3005. (if (or (not (file-writable-p file))
  3006. (and (file-exists-p file)
  3007. (if (org-called-interactively-p 'any)
  3008. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3009. (user-error "Cannot write agenda to file %s" file))
  3010. (org-let (if nosettings nil org-agenda-exporter-settings)
  3011. '(save-excursion
  3012. (save-window-excursion
  3013. (let ((bs (copy-sequence (buffer-string))) beg content)
  3014. (with-temp-buffer
  3015. (rename-buffer org-agenda-write-buffer-name t)
  3016. (set-buffer-modified-p nil)
  3017. (insert bs)
  3018. (org-agenda-remove-marked-text 'org-filtered)
  3019. (run-hooks 'org-agenda-before-write-hook)
  3020. (cond
  3021. ((org-bound-and-true-p org-mobile-creating-agendas)
  3022. (org-mobile-write-agenda-for-mobile file))
  3023. ((string-match "\\.org\\'" file)
  3024. (let (content p m message-log-max)
  3025. (goto-char (point-min))
  3026. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3027. (goto-char p)
  3028. (setq m (get-text-property (point) 'org-hd-marker))
  3029. (when m
  3030. (push (save-excursion
  3031. (set-buffer (marker-buffer m))
  3032. (goto-char m)
  3033. (org-copy-subtree 1 nil t t)
  3034. org-subtree-clip)
  3035. content)))
  3036. (find-file file)
  3037. (erase-buffer)
  3038. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3039. (write-file file)
  3040. (kill-buffer (current-buffer))
  3041. (message "Org file written to %s" file)))
  3042. ((string-match "\\.html?\\'" file)
  3043. (require 'htmlize)
  3044. (set-buffer (htmlize-buffer (current-buffer)))
  3045. (when org-agenda-export-html-style
  3046. ;; replace <style> section with org-agenda-export-html-style
  3047. (goto-char (point-min))
  3048. (kill-region (- (search-forward "<style") 6)
  3049. (search-forward "</style>"))
  3050. (insert org-agenda-export-html-style))
  3051. (write-file file)
  3052. (kill-buffer (current-buffer))
  3053. (message "HTML written to %s" file))
  3054. ((string-match "\\.ps\\'" file)
  3055. (require 'ps-print)
  3056. (ps-print-buffer-with-faces file)
  3057. (message "Postscript written to %s" file))
  3058. ((string-match "\\.pdf\\'" file)
  3059. (require 'ps-print)
  3060. (ps-print-buffer-with-faces
  3061. (concat (file-name-sans-extension file) ".ps"))
  3062. (call-process "ps2pdf" nil nil nil
  3063. (expand-file-name
  3064. (concat (file-name-sans-extension file) ".ps"))
  3065. (expand-file-name file))
  3066. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3067. (message "PDF written to %s" file))
  3068. ((string-match "\\.ics\\'" file)
  3069. (require 'ox-icalendar)
  3070. (org-icalendar-export-current-agenda (expand-file-name file)))
  3071. (t
  3072. (let ((bs (buffer-string)))
  3073. (find-file file)
  3074. (erase-buffer)
  3075. (insert bs)
  3076. (save-buffer 0)
  3077. (kill-buffer (current-buffer))
  3078. (message "Plain text written to %s" file))))))))
  3079. (set-buffer (or agenda-bufname
  3080. (and (org-called-interactively-p 'any) (buffer-name))
  3081. org-agenda-buffer-name)))
  3082. (when open (org-open-file file)))
  3083. (defun org-agenda-remove-marked-text (property &optional value)
  3084. "Delete all text marked with VALUE of PROPERTY.
  3085. VALUE defaults to t."
  3086. (let (beg)
  3087. (setq value (or value t))
  3088. (while (setq beg (text-property-any (point-min) (point-max)
  3089. property value))
  3090. (delete-region
  3091. beg (or (next-single-property-change beg property)
  3092. (point-max))))))
  3093. (defun org-agenda-add-entry-text ()
  3094. "Add entry text to agenda lines.
  3095. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3096. entry text following headings shown in the agenda.
  3097. Drawers will be excluded, also the line with scheduling/deadline info."
  3098. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3099. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3100. (let (m txt)
  3101. (goto-char (point-min))
  3102. (while (not (eobp))
  3103. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3104. (beginning-of-line 2)
  3105. (setq txt (org-agenda-get-some-entry-text
  3106. m org-agenda-add-entry-text-maxlines " > "))
  3107. (end-of-line 1)
  3108. (if (string-match "\\S-" txt)
  3109. (insert "\n" txt)
  3110. (or (eobp) (forward-char 1))))))))
  3111. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3112. &rest keep)
  3113. "Extract entry text from MARKER, at most N-LINES lines.
  3114. This will ignore drawers etc, just get the text.
  3115. If INDENT is given, prefix every line with this string. If KEEP is
  3116. given, it is a list of symbols, defining stuff that should not be
  3117. removed from the entry content. Currently only `planning' is allowed here."
  3118. (let (txt drawer-re kwd-time-re ind)
  3119. (save-excursion
  3120. (with-current-buffer (marker-buffer marker)
  3121. (if (not (derived-mode-p 'org-mode))
  3122. (setq txt "")
  3123. (save-excursion
  3124. (save-restriction
  3125. (widen)
  3126. (goto-char marker)
  3127. (end-of-line 1)
  3128. (setq txt (buffer-substring
  3129. (min (1+ (point)) (point-max))
  3130. (progn (outline-next-heading) (point)))
  3131. drawer-re org-drawer-regexp
  3132. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3133. ".*\n?"))
  3134. (with-temp-buffer
  3135. (insert txt)
  3136. (when org-agenda-add-entry-text-descriptive-links
  3137. (goto-char (point-min))
  3138. (while (org-activate-bracket-links (point-max))
  3139. (add-text-properties (match-beginning 0) (match-end 0)
  3140. '(face org-link))))
  3141. (goto-char (point-min))
  3142. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3143. (set-text-properties (match-beginning 0) (match-end 0)
  3144. nil))
  3145. (goto-char (point-min))
  3146. (while (re-search-forward drawer-re nil t)
  3147. (delete-region
  3148. (match-beginning 0)
  3149. (progn (re-search-forward
  3150. "^[ \t]*:END:.*\n?" nil 'move)
  3151. (point))))
  3152. (unless (member 'planning keep)
  3153. (goto-char (point-min))
  3154. (while (re-search-forward kwd-time-re nil t)
  3155. (replace-match "")))
  3156. (goto-char (point-min))
  3157. (when org-agenda-entry-text-exclude-regexps
  3158. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3159. (while (setq re (pop re-list))
  3160. (goto-char (point-min))
  3161. (while (re-search-forward re nil t)
  3162. (replace-match "")))))
  3163. (goto-char (point-max))
  3164. (skip-chars-backward " \t\n")
  3165. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3166. ;; find and remove min common indentation
  3167. (goto-char (point-min))
  3168. (untabify (point-min) (point-max))
  3169. (setq ind (org-get-indentation))
  3170. (while (not (eobp))
  3171. (unless (looking-at "[ \t]*$")
  3172. (setq ind (min ind (org-get-indentation))))
  3173. (beginning-of-line 2))
  3174. (goto-char (point-min))
  3175. (while (not (eobp))
  3176. (unless (looking-at "[ \t]*$")
  3177. (move-to-column ind)
  3178. (delete-region (point-at-bol) (point)))
  3179. (beginning-of-line 2))
  3180. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3181. (goto-char (point-min))
  3182. (when indent
  3183. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3184. (replace-match indent t t)))
  3185. (goto-char (point-min))
  3186. (while (looking-at "[ \t]*\n") (replace-match ""))
  3187. (goto-char (point-max))
  3188. (when (> (org-current-line)
  3189. n-lines)
  3190. (org-goto-line (1+ n-lines))
  3191. (backward-char 1))
  3192. (setq txt (buffer-substring (point-min) (point)))))))))
  3193. txt))
  3194. (defun org-check-for-org-mode ()
  3195. "Make sure current buffer is in org-mode. Error if not."
  3196. (or (derived-mode-p 'org-mode)
  3197. (error "Cannot execute org-mode agenda command on buffer in %s"
  3198. major-mode)))
  3199. ;;; Agenda prepare and finalize
  3200. (defvar org-agenda-multi nil) ; dynamically scoped
  3201. (defvar org-agenda-pre-window-conf nil)
  3202. (defvar org-agenda-columns-active nil)
  3203. (defvar org-agenda-name nil)
  3204. (defvar org-agenda-tag-filter nil)
  3205. (defvar org-agenda-category-filter nil)
  3206. (defvar org-agenda-regexp-filter nil)
  3207. (defvar org-agenda-top-headline-filter nil)
  3208. (defvar org-agenda-tag-filter-while-redo nil)
  3209. (defvar org-agenda-tag-filter-preset nil
  3210. "A preset of the tags filter used for secondary agenda filtering.
  3211. This must be a list of strings, each string must be a single tag preceded
  3212. by \"+\" or \"-\".
  3213. This variable should not be set directly, but agenda custom commands can
  3214. bind it in the options section. The preset filter is a global property of
  3215. the entire agenda view. In a block agenda, it will not work reliably to
  3216. define a filter for one of the individual blocks. You need to set it in
  3217. the global options and expect it to be applied to the entire view.")
  3218. (defvar org-agenda-category-filter-preset nil
  3219. "A preset of the category filter used for secondary agenda filtering.
  3220. This must be a list of strings, each string must be a single category
  3221. preceded by \"+\" or \"-\".
  3222. This variable should not be set directly, but agenda custom commands can
  3223. bind it in the options section. The preset filter is a global property of
  3224. the entire agenda view. In a block agenda, it will not work reliably to
  3225. define a filter for one of the individual blocks. You need to set it in
  3226. the global options and expect it to be applied to the entire view.")
  3227. (defvar org-agenda-regexp-filter-preset nil
  3228. "A preset of the regexp filter used for secondary agenda filtering.
  3229. This must be a list of strings, each string must be a single regexp
  3230. preceded by \"+\" or \"-\".
  3231. This variable should not be set directly, but agenda custom commands can
  3232. bind it in the options section. The preset filter is a global property of
  3233. the entire agenda view. In a block agenda, it will not work reliably to
  3234. define a filter for one of the individual blocks. You need to set it in
  3235. the global options and expect it to be applied to the entire view.")
  3236. (defun org-agenda-use-sticky-p ()
  3237. "Return non-nil if an agenda buffer named
  3238. `org-agenda-buffer-name' exists and should be shown instead of
  3239. generating a new one."
  3240. (and
  3241. ;; turned off by user
  3242. org-agenda-sticky
  3243. ;; For multi-agenda buffer already exists
  3244. (not org-agenda-multi)
  3245. ;; buffer found
  3246. (get-buffer org-agenda-buffer-name)
  3247. ;; C-u parameter is same as last call
  3248. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3249. (and
  3250. (equal current-prefix-arg
  3251. org-agenda-last-prefix-arg)
  3252. ;; In case user turned stickiness on, while having existing
  3253. ;; Agenda buffer active, don't reuse that buffer, because it
  3254. ;; does not have org variables local
  3255. org-agenda-this-buffer-is-sticky))))
  3256. (defun org-agenda-prepare-window (abuf)
  3257. "Setup agenda buffer in the window."
  3258. (let* ((awin (get-buffer-window abuf))
  3259. wconf)
  3260. (cond
  3261. ((equal (current-buffer) abuf) nil)
  3262. (awin (select-window awin))
  3263. ((not (setq wconf (current-window-configuration))))
  3264. ((equal org-agenda-window-setup 'current-window)
  3265. (org-pop-to-buffer-same-window abuf))
  3266. ((equal org-agenda-window-setup 'other-window)
  3267. (org-switch-to-buffer-other-window abuf))
  3268. ((equal org-agenda-window-setup 'other-frame)
  3269. (switch-to-buffer-other-frame abuf))
  3270. ((equal org-agenda-window-setup 'reorganize-frame)
  3271. (delete-other-windows)
  3272. (org-switch-to-buffer-other-window abuf)))
  3273. ;; additional test in case agenda is invoked from within agenda
  3274. ;; buffer via elisp link
  3275. (unless (equal (current-buffer) abuf)
  3276. (org-pop-to-buffer-same-window abuf))
  3277. (setq org-agenda-pre-window-conf
  3278. (or org-agenda-pre-window-conf wconf))))
  3279. (defun org-agenda-prepare (&optional name)
  3280. (if (org-agenda-use-sticky-p)
  3281. (progn
  3282. ;; Popup existing buffer
  3283. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3284. (message "Sticky Agenda buffer, use `r' to refresh")
  3285. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3286. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3287. (setq org-todo-keywords-for-agenda nil)
  3288. (unless org-agenda-persistent-filter
  3289. (setq org-agenda-tag-filter nil
  3290. org-agenda-category-filter nil
  3291. org-agenda-regexp-filter nil))
  3292. (put 'org-agenda-tag-filter :preset-filter
  3293. org-agenda-tag-filter-preset)
  3294. (put 'org-agenda-category-filter :preset-filter
  3295. org-agenda-category-filter-preset)
  3296. (put 'org-agenda-regexp-filter :preset-filter
  3297. org-agenda-regexp-filter-preset)
  3298. (if org-agenda-multi
  3299. (progn
  3300. (setq buffer-read-only nil)
  3301. (goto-char (point-max))
  3302. (unless (or (bobp) org-agenda-compact-blocks
  3303. (not org-agenda-block-separator))
  3304. (insert "\n"
  3305. (if (stringp org-agenda-block-separator)
  3306. org-agenda-block-separator
  3307. (make-string (window-width) org-agenda-block-separator))
  3308. "\n"))
  3309. (narrow-to-region (point) (point-max)))
  3310. (setq org-done-keywords-for-agenda nil)
  3311. ;; Setting any org variables that are in org-agenda-local-vars
  3312. ;; list need to be done after the prepare call
  3313. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3314. (setq buffer-read-only nil)
  3315. (org-agenda-reset-markers)
  3316. (let ((inhibit-read-only t)) (erase-buffer))
  3317. (org-agenda-mode)
  3318. (setq org-agenda-buffer (current-buffer))
  3319. (setq org-agenda-contributing-files nil)
  3320. (setq org-agenda-columns-active nil)
  3321. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3322. (setq org-todo-keywords-for-agenda
  3323. (org-uniquify org-todo-keywords-for-agenda))
  3324. (setq org-done-keywords-for-agenda
  3325. (org-uniquify org-done-keywords-for-agenda))
  3326. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3327. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3328. (and name (not org-agenda-name)
  3329. (org-set-local 'org-agenda-name name)))
  3330. (setq buffer-read-only nil)))
  3331. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3332. (defun org-agenda-finalize ()
  3333. "Finishing touch for the agenda buffer, called just before displaying it."
  3334. (unless org-agenda-multi
  3335. (save-excursion
  3336. (let ((inhibit-read-only t))
  3337. (goto-char (point-min))
  3338. (save-excursion
  3339. (while (org-activate-bracket-links (point-max))
  3340. (add-text-properties (match-beginning 0) (match-end 0)
  3341. '(face org-link))))
  3342. (save-excursion
  3343. (while (org-activate-plain-links (point-max))
  3344. (add-text-properties (match-beginning 0) (match-end 0)
  3345. '(face org-link))))
  3346. (unless (eq org-agenda-remove-tags t)
  3347. (org-agenda-align-tags))
  3348. (unless org-agenda-with-colors
  3349. (remove-text-properties (point-min) (point-max) '(face nil)))
  3350. (if (and (boundp 'org-agenda-overriding-columns-format)
  3351. org-agenda-overriding-columns-format)
  3352. (org-set-local 'org-agenda-overriding-columns-format
  3353. org-agenda-overriding-columns-format))
  3354. (if (and (boundp 'org-agenda-view-columns-initially)
  3355. org-agenda-view-columns-initially)
  3356. (org-agenda-columns))
  3357. (when org-agenda-fontify-priorities
  3358. (org-agenda-fontify-priorities))
  3359. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3360. (org-agenda-dim-blocked-tasks))
  3361. (org-agenda-mark-clocking-task)
  3362. (when org-agenda-entry-text-mode
  3363. (org-agenda-entry-text-hide)
  3364. (org-agenda-entry-text-show))
  3365. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3366. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3367. (org-habit-insert-consistency-graphs))
  3368. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3369. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3370. (and (listp org-agenda-show-inherited-tags)
  3371. (memq org-agenda-type org-agenda-show-inherited-tags))
  3372. (and (eq org-agenda-show-inherited-tags t)
  3373. (or (eq org-agenda-use-tag-inheritance t)
  3374. (and (listp org-agenda-use-tag-inheritance)
  3375. (not (memq org-agenda-type
  3376. org-agenda-use-tag-inheritance))))))
  3377. (let (mrk)
  3378. (save-excursion
  3379. (goto-char (point-min))
  3380. (while (equal (forward-line) 0)
  3381. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3382. (get-text-property (point) 'org-hd-marker)))
  3383. (put-text-property (point-at-bol) (point-at-eol)
  3384. 'tags (org-with-point-at mrk
  3385. (delete-dups
  3386. (mapcar 'downcase (org-get-tags-at))))))))))
  3387. (run-hooks 'org-agenda-finalize-hook)
  3388. (when org-agenda-top-headline-filter
  3389. (org-agenda-filter-top-headline-apply
  3390. org-agenda-top-headline-filter))
  3391. (when org-agenda-tag-filter
  3392. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3393. (when (get 'org-agenda-tag-filter :preset-filter)
  3394. (org-agenda-filter-apply
  3395. (get 'org-agenda-tag-filter :preset-filter) 'tag))
  3396. (when org-agenda-category-filter
  3397. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3398. (when (get 'org-agenda-category-filter :preset-filter)
  3399. (org-agenda-filter-apply
  3400. (get 'org-agenda-category-filter :preset-filter) 'category))
  3401. (when org-agenda-regexp-filter
  3402. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3403. (when (get 'org-agenda-regexp-filter :preset-filter)
  3404. (org-agenda-filter-apply
  3405. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3406. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3407. (defun org-agenda-mark-clocking-task ()
  3408. "Mark the current clock entry in the agenda if it is present."
  3409. ;; We need to widen when `org-agenda-finalize' is called from
  3410. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3411. (when org-clock-current-task
  3412. (save-restriction
  3413. (widen)
  3414. (org-agenda-unmark-clocking-task)
  3415. (when (marker-buffer org-clock-hd-marker)
  3416. (save-excursion
  3417. (goto-char (point-min))
  3418. (let (s ov)
  3419. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3420. (goto-char s)
  3421. (when (equal (org-get-at-bol 'org-hd-marker)
  3422. org-clock-hd-marker)
  3423. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3424. (overlay-put ov 'type 'org-agenda-clocking)
  3425. (overlay-put ov 'face 'org-agenda-clocking)
  3426. (overlay-put ov 'help-echo
  3427. "The clock is running in this item")))))))))
  3428. (defun org-agenda-unmark-clocking-task ()
  3429. "Unmark the current clocking task."
  3430. (mapc (lambda (o)
  3431. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3432. (delete-overlay o)))
  3433. (overlays-in (point-min) (point-max))))
  3434. (defun org-agenda-fontify-priorities ()
  3435. "Make highest priority lines bold, and lowest italic."
  3436. (interactive)
  3437. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3438. (delete-overlay o)))
  3439. (overlays-in (point-min) (point-max)))
  3440. (save-excursion
  3441. (let (b e p ov h l)
  3442. (goto-char (point-min))
  3443. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3444. (setq h (or (get-char-property (point) 'org-highest-priority)
  3445. org-highest-priority)
  3446. l (or (get-char-property (point) 'org-lowest-priority)
  3447. org-lowest-priority)
  3448. p (string-to-char (match-string 1))
  3449. b (match-beginning 0)
  3450. e (if (eq org-agenda-fontify-priorities 'cookies)
  3451. (match-end 0)
  3452. (point-at-eol))
  3453. ov (make-overlay b e))
  3454. (overlay-put
  3455. ov 'face
  3456. (cons (cond ((org-face-from-face-or-color
  3457. 'priority nil
  3458. (cdr (assoc p org-priority-faces))))
  3459. ((and (listp org-agenda-fontify-priorities)
  3460. (org-face-from-face-or-color
  3461. 'priority nil
  3462. (cdr (assoc p org-agenda-fontify-priorities)))))
  3463. ((equal p l) 'italic)
  3464. ((equal p h) 'bold))
  3465. 'org-priority))
  3466. (overlay-put ov 'org-type 'org-priority)))))
  3467. (defvar org-depend-tag-blocked)
  3468. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3469. "Dim currently blocked TODO's in the agenda display.
  3470. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3471. dimming them."
  3472. (interactive "P")
  3473. (when (org-called-interactively-p 'interactive)
  3474. (message "Dim or hide blocked tasks..."))
  3475. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3476. (delete-overlay o)))
  3477. (overlays-in (point-min) (point-max)))
  3478. (save-excursion
  3479. (let ((inhibit-read-only t)
  3480. (org-depend-tag-blocked nil)
  3481. (invis (or (not (null invisible))
  3482. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3483. org-blocked-by-checkboxes
  3484. invis1 b e p ov h l)
  3485. (goto-char (point-min))
  3486. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3487. (and pos (goto-char (1+ pos))))
  3488. (setq org-blocked-by-checkboxes nil invis1 invis)
  3489. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3490. (when (and marker
  3491. (with-current-buffer (marker-buffer marker)
  3492. (save-excursion (goto-char marker)
  3493. (org-entry-blocked-p))))
  3494. (if org-blocked-by-checkboxes (setq invis1 nil))
  3495. (setq b (if invis1
  3496. (max (point-min) (1- (point-at-bol)))
  3497. (point-at-bol))
  3498. e (point-at-eol)
  3499. ov (make-overlay b e))
  3500. (if invis1
  3501. (progn (overlay-put ov 'invisible t)
  3502. (overlay-put ov 'intangible 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) it and return the 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. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3624. (defun org-timeline (&optional dotodo)
  3625. "Show a time-sorted view of the entries in the current org file.
  3626. Only entries with a time stamp of today or later will be listed. With
  3627. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3628. under the current date.
  3629. If the buffer contains an active region, only check the region for
  3630. dates."
  3631. (interactive "P")
  3632. (let* ((dopast t)
  3633. (org-agenda-show-log-scoped org-agenda-show-log)
  3634. (org-agenda-show-log org-agenda-show-log-scoped)
  3635. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3636. (current-buffer))))
  3637. (date (calendar-current-date))
  3638. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3639. (end (if (org-region-active-p) (region-end) (point-max)))
  3640. (day-numbers (org-get-all-dates
  3641. beg end 'no-ranges
  3642. t org-agenda-show-log-scoped ; always include today
  3643. org-timeline-show-empty-dates))
  3644. (org-deadline-warning-days 0)
  3645. (org-agenda-only-exact-dates t)
  3646. (today (org-today))
  3647. (past t)
  3648. args
  3649. s e rtn d emptyp)
  3650. (setq org-agenda-redo-command
  3651. (list 'let
  3652. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3653. (list 'org-switch-to-buffer-other-window (current-buffer))
  3654. (list 'org-timeline (list 'quote dotodo))))
  3655. (put 'org-agenda-redo-command 'org-lprops nil)
  3656. (if (not dopast)
  3657. ;; Remove past dates from the list of dates.
  3658. (setq day-numbers (delq nil (mapcar (lambda(x)
  3659. (if (>= x today) x nil))
  3660. day-numbers))))
  3661. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3662. (org-compile-prefix-format 'timeline)
  3663. (org-set-sorting-strategy 'timeline)
  3664. (if org-agenda-show-log-scoped (push :closed args))
  3665. (push :timestamp args)
  3666. (push :deadline args)
  3667. (push :scheduled args)
  3668. (push :sexp args)
  3669. (if dotodo (push :todo args))
  3670. (insert "Timeline of file " entry "\n")
  3671. (add-text-properties (point-min) (point)
  3672. (list 'face 'org-agenda-structure))
  3673. (org-agenda-mark-header-line (point-min))
  3674. (while (setq d (pop day-numbers))
  3675. (if (and (listp d) (eq (car d) :omitted))
  3676. (progn
  3677. (setq s (point))
  3678. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3679. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3680. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3681. (if (and (>= d today)
  3682. dopast
  3683. past)
  3684. (progn
  3685. (setq past nil)
  3686. (insert (make-string 79 ?-) "\n")))
  3687. (setq date (calendar-gregorian-from-absolute d))
  3688. (setq s (point))
  3689. (setq rtn (and (not emptyp)
  3690. (apply 'org-agenda-get-day-entries entry
  3691. date args)))
  3692. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3693. (progn
  3694. (insert
  3695. (if (stringp org-agenda-format-date)
  3696. (format-time-string org-agenda-format-date
  3697. (org-time-from-absolute date))
  3698. (funcall org-agenda-format-date date))
  3699. "\n")
  3700. (put-text-property s (1- (point)) 'face
  3701. (org-agenda-get-day-face date))
  3702. (put-text-property s (1- (point)) 'org-date-line t)
  3703. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3704. (if (equal d today)
  3705. (put-text-property s (1- (point)) 'org-today t))
  3706. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3707. (put-text-property s (1- (point)) 'day d)))))
  3708. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3709. (point-min)))
  3710. (add-text-properties
  3711. (point-min) (point-max)
  3712. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3713. (org-agenda-finalize)
  3714. (setq buffer-read-only t)))
  3715. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3716. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3717. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3718. not every single day in the range. If FORCE-TODAY is non-nil, make
  3719. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3720. inactive time stamps (those in square brackets) are included.
  3721. When EMPTY is non-nil, also include days without any entries."
  3722. (let ((re (concat
  3723. (if pre-re pre-re "")
  3724. (if inactive org-ts-regexp-both org-ts-regexp)))
  3725. dates dates1 date day day1 day2 ts1 ts2 pos)
  3726. (if force-today
  3727. (setq dates (list (org-today))))
  3728. (save-excursion
  3729. (goto-char beg)
  3730. (while (re-search-forward re end t)
  3731. (setq day (time-to-days (org-time-string-to-time
  3732. (substring (match-string 1) 0 10)
  3733. (current-buffer) (match-beginning 0))))
  3734. (or (memq day dates) (push day dates)))
  3735. (unless no-ranges
  3736. (goto-char beg)
  3737. (while (re-search-forward org-tr-regexp end t)
  3738. (setq pos (match-beginning 0))
  3739. (setq ts1 (substring (match-string 1) 0 10)
  3740. ts2 (substring (match-string 2) 0 10)
  3741. day1 (time-to-days (org-time-string-to-time
  3742. ts1 (current-buffer) pos))
  3743. day2 (time-to-days (org-time-string-to-time
  3744. ts2 (current-buffer) pos)))
  3745. (while (< (setq day1 (1+ day1)) day2)
  3746. (or (memq day1 dates) (push day1 dates)))))
  3747. (setq dates (sort dates '<))
  3748. (when empty
  3749. (while (setq day (pop dates))
  3750. (setq day2 (car dates))
  3751. (push day dates1)
  3752. (when (and day2 empty)
  3753. (if (or (eq empty t)
  3754. (and (numberp empty) (<= (- day2 day) empty)))
  3755. (while (< (setq day (1+ day)) day2)
  3756. (push (list day) dates1))
  3757. (push (cons :omitted (- day2 day)) dates1))))
  3758. (setq dates (nreverse dates1)))
  3759. dates)))
  3760. ;;; Agenda Daily/Weekly
  3761. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3762. "Start day for the agenda view.
  3763. Custom commands can set this variable in the options section.
  3764. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3765. input allowed when reading a date through the Org calendar.
  3766. See the docstring of `org-read-date' for details.")
  3767. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3768. (defvar org-arg-loc nil) ; local variable
  3769. (defvar org-agenda-buffer-tmp-name nil)
  3770. ;;;###autoload
  3771. (defun org-agenda-list (&optional arg start-day span with-hour)
  3772. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3773. The view will be for the current day or week, but from the overview buffer
  3774. you will be able to go to other days/weeks.
  3775. With a numeric prefix argument in an interactive call, the agenda will
  3776. span ARG days. Lisp programs should instead specify SPAN to change
  3777. the number of days. SPAN defaults to `org-agenda-span'.
  3778. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3779. given in `org-agenda-start-on-weekday'.
  3780. When WITH-HOUR is non-nil, only include scheduled and deadline
  3781. items if they have an hour specification like [h]h:mm."
  3782. (interactive "P")
  3783. (if org-agenda-overriding-arguments
  3784. (setq arg (car org-agenda-overriding-arguments)
  3785. start-day (nth 1 org-agenda-overriding-arguments)
  3786. span (nth 2 org-agenda-overriding-arguments)))
  3787. (if (and (integerp arg) (> arg 0))
  3788. (setq span arg arg nil))
  3789. (catch 'exit
  3790. (setq org-agenda-buffer-name
  3791. (or org-agenda-buffer-tmp-name
  3792. (if org-agenda-sticky
  3793. (cond ((and org-keys (stringp org-match))
  3794. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3795. (org-keys
  3796. (format "*Org Agenda(%s)*" org-keys))
  3797. (t "*Org Agenda(a)*")))
  3798. org-agenda-buffer-name))
  3799. (org-agenda-prepare "Day/Week")
  3800. (setq start-day (or start-day org-agenda-start-day))
  3801. (if (stringp start-day)
  3802. ;; Convert to an absolute day number
  3803. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3804. (org-compile-prefix-format 'agenda)
  3805. (org-set-sorting-strategy 'agenda)
  3806. (let* ((span (org-agenda-ndays-to-span
  3807. (or span org-agenda-ndays org-agenda-span)))
  3808. (today (org-today))
  3809. (sd (or start-day today))
  3810. (ndays (org-agenda-span-to-ndays span sd))
  3811. (org-agenda-start-on-weekday
  3812. (if (or (eq ndays 7) (eq ndays 14))
  3813. org-agenda-start-on-weekday))
  3814. (thefiles (org-agenda-files nil 'ifmode))
  3815. (files thefiles)
  3816. (start (if (or (null org-agenda-start-on-weekday)
  3817. (< ndays 7))
  3818. sd
  3819. (let* ((nt (calendar-day-of-week
  3820. (calendar-gregorian-from-absolute sd)))
  3821. (n1 org-agenda-start-on-weekday)
  3822. (d (- nt n1)))
  3823. (- sd (+ (if (< d 0) 7 0) d)))))
  3824. (day-numbers (list start))
  3825. (day-cnt 0)
  3826. (inhibit-redisplay (not debug-on-error))
  3827. (org-agenda-show-log-scoped org-agenda-show-log)
  3828. s e rtn rtnall file date d start-pos end-pos todayp
  3829. clocktable-start clocktable-end filter)
  3830. (setq org-agenda-redo-command
  3831. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3832. (dotimes (n (1- ndays))
  3833. (push (1+ (car day-numbers)) day-numbers))
  3834. (setq day-numbers (nreverse day-numbers))
  3835. (setq clocktable-start (car day-numbers)
  3836. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3837. (org-set-local 'org-starting-day (car day-numbers))
  3838. (org-set-local 'org-arg-loc arg)
  3839. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3840. (unless org-agenda-compact-blocks
  3841. (let* ((d1 (car day-numbers))
  3842. (d2 (org-last day-numbers))
  3843. (w1 (org-days-to-iso-week d1))
  3844. (w2 (org-days-to-iso-week d2)))
  3845. (setq s (point))
  3846. (if org-agenda-overriding-header
  3847. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3848. nil 'face 'org-agenda-structure) "\n")
  3849. (insert (org-agenda-span-name span)
  3850. "-agenda"
  3851. (if (< (- d2 d1) 350)
  3852. (if (= w1 w2)
  3853. (format " (W%02d)" w1)
  3854. (format " (W%02d-W%02d)" w1 w2))
  3855. "")
  3856. ":\n")))
  3857. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3858. 'org-date-line t))
  3859. (org-agenda-mark-header-line s))
  3860. (while (setq d (pop day-numbers))
  3861. (setq date (calendar-gregorian-from-absolute d)
  3862. s (point))
  3863. (if (or (setq todayp (= d today))
  3864. (and (not start-pos) (= d sd)))
  3865. (setq start-pos (point))
  3866. (if (and start-pos (not end-pos))
  3867. (setq end-pos (point))))
  3868. (setq files thefiles
  3869. rtnall nil)
  3870. (while (setq file (pop files))
  3871. (catch 'nextfile
  3872. (org-check-agenda-file file)
  3873. (let ((org-agenda-entry-types org-agenda-entry-types))
  3874. ;; Starred types override non-starred equivalents
  3875. (when (member :deadline* org-agenda-entry-types)
  3876. (setq org-agenda-entry-types
  3877. (delq :deadline org-agenda-entry-types)))
  3878. (when (member :scheduled* org-agenda-entry-types)
  3879. (setq org-agenda-entry-types
  3880. (delq :scheduled org-agenda-entry-types)))
  3881. ;; Honor with-hour
  3882. (when with-hour
  3883. (when (member :deadline org-agenda-entry-types)
  3884. (setq org-agenda-entry-types
  3885. (delq :deadline org-agenda-entry-types))
  3886. (push :deadline* org-agenda-entry-types))
  3887. (when (member :scheduled org-agenda-entry-types)
  3888. (setq org-agenda-entry-types
  3889. (delq :scheduled org-agenda-entry-types))
  3890. (push :scheduled* org-agenda-entry-types)))
  3891. (unless org-agenda-include-deadlines
  3892. (setq org-agenda-entry-types
  3893. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3894. (cond
  3895. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3896. (setq rtn (org-agenda-get-day-entries
  3897. file date :closed)))
  3898. (org-agenda-show-log-scoped
  3899. (setq rtn (apply 'org-agenda-get-day-entries
  3900. file date
  3901. (append '(:closed) org-agenda-entry-types))))
  3902. (t
  3903. (setq rtn (apply 'org-agenda-get-day-entries
  3904. file date
  3905. org-agenda-entry-types)))))
  3906. (setq rtnall (append rtnall rtn)))) ;; all entries
  3907. (if org-agenda-include-diary
  3908. (let ((org-agenda-search-headline-for-time t))
  3909. (require 'diary-lib)
  3910. (setq rtn (org-get-entries-from-diary date))
  3911. (setq rtnall (append rtnall rtn))))
  3912. (if (or rtnall org-agenda-show-all-dates)
  3913. (progn
  3914. (setq day-cnt (1+ day-cnt))
  3915. (insert
  3916. (if (stringp org-agenda-format-date)
  3917. (format-time-string org-agenda-format-date
  3918. (org-time-from-absolute date))
  3919. (funcall org-agenda-format-date date))
  3920. "\n")
  3921. (put-text-property s (1- (point)) 'face
  3922. (org-agenda-get-day-face date))
  3923. (put-text-property s (1- (point)) 'org-date-line t)
  3924. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3925. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3926. (when todayp
  3927. (put-text-property s (1- (point)) 'org-today t))
  3928. (setq rtnall
  3929. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3930. (if rtnall (insert ;; all entries
  3931. (org-agenda-finalize-entries rtnall 'agenda)
  3932. "\n"))
  3933. (put-text-property s (1- (point)) 'day d)
  3934. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3935. (when (and org-agenda-clockreport-mode clocktable-start)
  3936. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3937. ;; the above line is to ensure the restricted range!
  3938. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3939. tbl)
  3940. (setq p (org-plist-delete p :block))
  3941. (setq p (plist-put p :tstart clocktable-start))
  3942. (setq p (plist-put p :tend clocktable-end))
  3943. (setq p (plist-put p :scope 'agenda))
  3944. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3945. (setq filter (or org-agenda-tag-filter-while-redo
  3946. (get 'org-agenda-tag-filter :preset-filter))))
  3947. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3948. (if (string-match "[<>=]" x)
  3949. ""
  3950. x))
  3951. filter ""))))
  3952. (setq tbl (apply 'org-clock-get-clocktable p))
  3953. (insert tbl)))
  3954. (goto-char (point-min))
  3955. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3956. (unless (and (pos-visible-in-window-p (point-min))
  3957. (pos-visible-in-window-p (point-max)))
  3958. (goto-char (1- (point-max)))
  3959. (recenter -1)
  3960. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3961. (progn
  3962. (goto-char (or start-pos 1))
  3963. (recenter 1))))
  3964. (goto-char (or start-pos 1))
  3965. (add-text-properties (point-min) (point-max)
  3966. `(org-agenda-type agenda
  3967. org-last-args (,arg ,start-day ,span)
  3968. org-redo-cmd ,org-agenda-redo-command
  3969. org-series-cmd ,org-cmd))
  3970. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3971. (org-agenda-show-clocking-issues))
  3972. (org-agenda-finalize)
  3973. (setq buffer-read-only t)
  3974. (message ""))))
  3975. (defun org-agenda-ndays-to-span (n)
  3976. "Return a span symbol for a span of N days, or N if none matches."
  3977. (cond ((symbolp n) n)
  3978. ((= n 1) 'day)
  3979. ((= n 7) 'week)
  3980. ((= n 14) 'fortnight)
  3981. (t n)))
  3982. (defun org-agenda-span-to-ndays (span &optional start-day)
  3983. "Return ndays from SPAN, possibly starting at START-DAY.
  3984. START-DAY is an absolute time value."
  3985. (cond ((numberp span) span)
  3986. ((eq span 'day) 1)
  3987. ((eq span 'week) 7)
  3988. ((eq span 'fortnight) 14)
  3989. ((eq span 'month)
  3990. (let ((date (calendar-gregorian-from-absolute start-day)))
  3991. (calendar-last-day-of-month (car date) (caddr date))))
  3992. ((eq span 'year)
  3993. (let ((date (calendar-gregorian-from-absolute start-day)))
  3994. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3995. (defun org-agenda-span-name (span)
  3996. "Return a SPAN name."
  3997. (if (null span)
  3998. ""
  3999. (if (symbolp span)
  4000. (capitalize (symbol-name span))
  4001. (format "%d days" span))))
  4002. ;;; Agenda word search
  4003. (defvar org-agenda-search-history nil)
  4004. (defvar org-search-syntax-table nil
  4005. "Special syntax table for org-mode search.
  4006. In this table, we have single quotes not as word constituents, to
  4007. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4008. (defvar org-mode-syntax-table) ; From org.el
  4009. (defun org-search-syntax-table ()
  4010. (unless org-search-syntax-table
  4011. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4012. (modify-syntax-entry ?' "." org-search-syntax-table)
  4013. (modify-syntax-entry ?` "." org-search-syntax-table))
  4014. org-search-syntax-table)
  4015. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4016. ;;;###autoload
  4017. (defun org-search-view (&optional todo-only string edit-at)
  4018. "Show all entries that contain a phrase or words or regular expressions.
  4019. With optional prefix argument TODO-ONLY, only consider entries that are
  4020. TODO entries. The argument STRING can be used to pass a default search
  4021. string into this function. If EDIT-AT is non-nil, it means that the
  4022. user should get a chance to edit this string, with cursor at position
  4023. EDIT-AT.
  4024. The search string can be viewed either as a phrase that should be found as
  4025. is, or it can be broken into a number of snippets, each of which must match
  4026. in a Boolean way to select an entry. The default depends on the variable
  4027. `org-agenda-search-view-always-boolean'.
  4028. Even if this is turned off (the default) you can always switch to
  4029. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4030. The default is a direct search of the whole phrase, where each space in
  4031. the search string can expand to an arbitrary amount of whitespace,
  4032. including newlines.
  4033. If using a Boolean search, the search string is split on whitespace and
  4034. each snippet is searched separately, with logical AND to select an entry.
  4035. Words prefixed with a minus must *not* occur in the entry. Words without
  4036. a prefix or prefixed with a plus must occur in the entry. Matching is
  4037. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4038. match whole words, not parts of a word) if
  4039. `org-agenda-search-view-force-full-words' is set (default is nil).
  4040. Boolean search snippets enclosed by curly braces are interpreted as
  4041. regular expressions that must or (when preceded with \"-\") must not
  4042. match in the entry. Snippets enclosed into double quotes will be taken
  4043. as a whole, to include whitespace.
  4044. - If the search string starts with an asterisk, search only in headlines.
  4045. - If (possibly after the leading star) the search string starts with an
  4046. exclamation mark, this also means to look at TODO entries only, an effect
  4047. that can also be achieved with a prefix argument.
  4048. - If (possibly after star and exclamation mark) the search string starts
  4049. with a colon, this will mean that the (non-regexp) snippets of the
  4050. Boolean search must match as full words.
  4051. This command searches the agenda files, and in addition the files listed
  4052. in `org-agenda-text-search-extra-files'."
  4053. (interactive "P")
  4054. (if org-agenda-overriding-arguments
  4055. (setq todo-only (car org-agenda-overriding-arguments)
  4056. string (nth 1 org-agenda-overriding-arguments)
  4057. edit-at (nth 2 org-agenda-overriding-arguments)))
  4058. (let* ((props (list 'face nil
  4059. 'done-face 'org-agenda-done
  4060. 'org-not-done-regexp org-not-done-regexp
  4061. 'org-todo-regexp org-todo-regexp
  4062. 'org-complex-heading-regexp org-complex-heading-regexp
  4063. 'mouse-face 'highlight
  4064. 'help-echo (format "mouse-2 or RET jump to location")))
  4065. (full-words org-agenda-search-view-force-full-words)
  4066. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4067. regexp rtn rtnall files file pos inherited-tags
  4068. marker category level tags c neg re boolean
  4069. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4070. (unless (and (not edit-at)
  4071. (stringp string)
  4072. (string-match "\\S-" string))
  4073. (setq string (read-string
  4074. (if org-agenda-search-view-always-boolean
  4075. "[+-]Word/{Regexp} ...: "
  4076. "Phrase or [+-]Word/{Regexp} ...: ")
  4077. (cond
  4078. ((integerp edit-at) (cons string edit-at))
  4079. (edit-at string))
  4080. 'org-agenda-search-history)))
  4081. (catch 'exit
  4082. (if org-agenda-sticky
  4083. (setq org-agenda-buffer-name
  4084. (if (stringp string)
  4085. (format "*Org Agenda(%s:%s)*"
  4086. (or org-keys (or (and todo-only "S") "s")) string)
  4087. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4088. (org-agenda-prepare "SEARCH")
  4089. (org-compile-prefix-format 'search)
  4090. (org-set-sorting-strategy 'search)
  4091. (setq org-agenda-redo-command
  4092. (list 'org-search-view (if todo-only t nil)
  4093. (list 'if 'current-prefix-arg nil string)))
  4094. (setq org-agenda-query-string string)
  4095. (if (equal (string-to-char string) ?*)
  4096. (setq hdl-only t
  4097. words (substring string 1))
  4098. (setq words string))
  4099. (when (equal (string-to-char words) ?!)
  4100. (setq todo-only t
  4101. words (substring words 1)))
  4102. (when (equal (string-to-char words) ?:)
  4103. (setq full-words t
  4104. words (substring words 1)))
  4105. (if (or org-agenda-search-view-always-boolean
  4106. (member (string-to-char words) '(?- ?+ ?\{)))
  4107. (setq boolean t))
  4108. (setq words (org-split-string words))
  4109. (let (www w)
  4110. (while (setq w (pop words))
  4111. (while (and (string-match "\\\\\\'" w) words)
  4112. (setq w (concat (substring w 0 -1) " " (pop words))))
  4113. (push w www))
  4114. (setq words (nreverse www) www nil)
  4115. (while (setq w (pop words))
  4116. (when (and (string-match "\\`[-+]?{" w)
  4117. (not (string-match "}\\'" w)))
  4118. (while (and words (not (string-match "}\\'" (car words))))
  4119. (setq w (concat w " " (pop words))))
  4120. (setq w (concat w " " (pop words))))
  4121. (push w www))
  4122. (setq words (nreverse www)))
  4123. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4124. (when boolean
  4125. (let (wds w)
  4126. (while (setq w (pop words))
  4127. (if (or (equal (substring w 0 1) "\"")
  4128. (and (> (length w) 1)
  4129. (member (substring w 0 1) '("+" "-"))
  4130. (equal (substring w 1 2) "\"")))
  4131. (while (and words (not (equal (substring w -1) "\"")))
  4132. (setq w (concat w " " (pop words)))))
  4133. (and (string-match "\\`\\([-+]?\\)\"" w)
  4134. (setq w (replace-match "\\1" nil nil w)))
  4135. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4136. (push w wds))
  4137. (setq words (nreverse wds))))
  4138. (if boolean
  4139. (mapc (lambda (w)
  4140. (setq c (string-to-char w))
  4141. (if (equal c ?-)
  4142. (setq neg t w (substring w 1))
  4143. (if (equal c ?+)
  4144. (setq neg nil w (substring w 1))
  4145. (setq neg nil)))
  4146. (if (string-match "\\`{.*}\\'" w)
  4147. (setq re (substring w 1 -1))
  4148. (if full-words
  4149. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4150. (setq re (regexp-quote (downcase w)))))
  4151. (if neg (push re regexps-) (push re regexps+)))
  4152. words)
  4153. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4154. regexps+))
  4155. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4156. (if (not regexps+)
  4157. (setq regexp org-outline-regexp-bol)
  4158. (setq regexp (pop regexps+))
  4159. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4160. regexp))))
  4161. (setq files (org-agenda-files nil 'ifmode))
  4162. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4163. (pop org-agenda-text-search-extra-files)
  4164. (setq files (org-add-archive-files files)))
  4165. (setq files (append files org-agenda-text-search-extra-files)
  4166. rtnall nil)
  4167. (while (setq file (pop files))
  4168. (setq ee nil)
  4169. (catch 'nextfile
  4170. (org-check-agenda-file file)
  4171. (setq buffer (if (file-exists-p file)
  4172. (org-get-agenda-file-buffer file)
  4173. (error "No such file %s" file)))
  4174. (if (not buffer)
  4175. ;; If file does not exist, make sure an error message is sent
  4176. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4177. file))))
  4178. (with-current-buffer buffer
  4179. (with-syntax-table (org-search-syntax-table)
  4180. (unless (derived-mode-p 'org-mode)
  4181. (error "Agenda file %s is not in `org-mode'" file))
  4182. (let ((case-fold-search t))
  4183. (save-excursion
  4184. (save-restriction
  4185. (if (eq buffer org-agenda-restrict)
  4186. (narrow-to-region org-agenda-restrict-begin
  4187. org-agenda-restrict-end)
  4188. (widen))
  4189. (goto-char (point-min))
  4190. (unless (or (org-at-heading-p)
  4191. (outline-next-heading))
  4192. (throw 'nextfile t))
  4193. (goto-char (max (point-min) (1- (point))))
  4194. (while (re-search-forward regexp nil t)
  4195. (org-back-to-heading t)
  4196. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4197. (> (org-reduced-level (org-outline-level))
  4198. org-agenda-search-view-max-outline-level)
  4199. (forward-line -1)
  4200. (outline-back-to-heading t)))
  4201. (skip-chars-forward "* ")
  4202. (setq beg (point-at-bol)
  4203. beg1 (point)
  4204. end (progn
  4205. (outline-next-heading)
  4206. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4207. (> (org-reduced-level (org-outline-level))
  4208. org-agenda-search-view-max-outline-level)
  4209. (forward-line 1)
  4210. (outline-next-heading)))
  4211. (point)))
  4212. (catch :skip
  4213. (goto-char beg)
  4214. (org-agenda-skip)
  4215. (setq str (buffer-substring-no-properties
  4216. (point-at-bol)
  4217. (if hdl-only (point-at-eol) end)))
  4218. (mapc (lambda (wr) (when (string-match wr str)
  4219. (goto-char (1- end))
  4220. (throw :skip t)))
  4221. regexps-)
  4222. (mapc (lambda (wr) (unless (string-match wr str)
  4223. (goto-char (1- end))
  4224. (throw :skip t)))
  4225. (if todo-only
  4226. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4227. regexps+)
  4228. regexps+))
  4229. (goto-char beg)
  4230. (setq marker (org-agenda-new-marker (point))
  4231. category (org-get-category)
  4232. level (make-string (org-reduced-level (org-outline-level)) ? )
  4233. inherited-tags
  4234. (or (eq org-agenda-show-inherited-tags 'always)
  4235. (and (listp org-agenda-show-inherited-tags)
  4236. (memq 'todo org-agenda-show-inherited-tags))
  4237. (and (eq org-agenda-show-inherited-tags t)
  4238. (or (eq org-agenda-use-tag-inheritance t)
  4239. (memq 'todo org-agenda-use-tag-inheritance))))
  4240. tags (org-get-tags-at nil (not inherited-tags))
  4241. txt (org-agenda-format-item
  4242. ""
  4243. (buffer-substring-no-properties
  4244. beg1 (point-at-eol))
  4245. level category tags t))
  4246. (org-add-props txt props
  4247. 'org-marker marker 'org-hd-marker marker
  4248. 'org-todo-regexp org-todo-regexp
  4249. 'level level
  4250. 'org-complex-heading-regexp org-complex-heading-regexp
  4251. 'priority 1000
  4252. 'type "search")
  4253. (push txt ee)
  4254. (goto-char (1- end))))))))))
  4255. (setq rtn (nreverse ee))
  4256. (setq rtnall (append rtnall rtn)))
  4257. (if org-agenda-overriding-header
  4258. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4259. nil 'face 'org-agenda-structure) "\n")
  4260. (insert "Search words: ")
  4261. (add-text-properties (point-min) (1- (point))
  4262. (list 'face 'org-agenda-structure))
  4263. (setq pos (point))
  4264. (insert string "\n")
  4265. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4266. (setq pos (point))
  4267. (unless org-agenda-multi
  4268. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4269. (add-text-properties pos (1- (point))
  4270. (list 'face 'org-agenda-structure))))
  4271. (org-agenda-mark-header-line (point-min))
  4272. (when rtnall
  4273. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4274. (goto-char (point-min))
  4275. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4276. (add-text-properties (point-min) (point-max)
  4277. `(org-agenda-type search
  4278. org-last-args (,todo-only ,string ,edit-at)
  4279. org-redo-cmd ,org-agenda-redo-command
  4280. org-series-cmd ,org-cmd))
  4281. (org-agenda-finalize)
  4282. (setq buffer-read-only t))))
  4283. ;;; Agenda TODO list
  4284. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4285. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4286. (concat
  4287. (if (or (equal keywords "ALL") (not keywords))
  4288. (propertize "ALL" 'face 'warning)
  4289. (mapconcat
  4290. (lambda (kw)
  4291. (propertize kw 'face (org-get-todo-face kw)))
  4292. (org-split-string keywords "|")
  4293. "|"))
  4294. "\n"))
  4295. (defvar org-select-this-todo-keyword nil)
  4296. (defvar org-last-arg nil)
  4297. ;;;###autoload
  4298. (defun org-todo-list (&optional arg)
  4299. "Show all (not done) TODO entries from all agenda file in a single list.
  4300. The prefix arg can be used to select a specific TODO keyword and limit
  4301. the list to these. When using \\[universal-argument], you will be prompted
  4302. for a keyword. A numeric prefix directly selects the Nth keyword in
  4303. `org-todo-keywords-1'."
  4304. (interactive "P")
  4305. (if org-agenda-overriding-arguments
  4306. (setq arg org-agenda-overriding-arguments))
  4307. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4308. (let* ((today (org-today))
  4309. (date (calendar-gregorian-from-absolute today))
  4310. (kwds org-todo-keywords-for-agenda)
  4311. (completion-ignore-case t)
  4312. (org-select-this-todo-keyword
  4313. (if (stringp arg) arg
  4314. (and arg (integerp arg) (> arg 0)
  4315. (nth (1- arg) kwds))))
  4316. rtn rtnall files file pos)
  4317. (when (equal arg '(4))
  4318. (setq org-select-this-todo-keyword
  4319. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4320. (mapcar 'list kwds) nil nil)))
  4321. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4322. (catch 'exit
  4323. (if org-agenda-sticky
  4324. (setq org-agenda-buffer-name
  4325. (if (stringp org-select-this-todo-keyword)
  4326. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4327. org-select-this-todo-keyword)
  4328. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4329. (org-agenda-prepare "TODO")
  4330. (org-compile-prefix-format 'todo)
  4331. (org-set-sorting-strategy 'todo)
  4332. (setq org-agenda-redo-command
  4333. `(org-todo-list (or (and (numberp current-prefix-arg)
  4334. current-prefix-arg)
  4335. ,org-select-this-todo-keyword
  4336. current-prefix-arg ,arg)))
  4337. (setq files (org-agenda-files nil 'ifmode)
  4338. rtnall nil)
  4339. (while (setq file (pop files))
  4340. (catch 'nextfile
  4341. (org-check-agenda-file file)
  4342. (setq rtn (org-agenda-get-day-entries file date :todo))
  4343. (setq rtnall (append rtnall rtn))))
  4344. (if org-agenda-overriding-header
  4345. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4346. nil 'face 'org-agenda-structure) "\n")
  4347. (insert "Global list of TODO items of type: ")
  4348. (add-text-properties (point-min) (1- (point))
  4349. (list 'face 'org-agenda-structure
  4350. 'short-heading
  4351. (concat "ToDo: "
  4352. (or org-select-this-todo-keyword "ALL"))))
  4353. (org-agenda-mark-header-line (point-min))
  4354. (insert (org-agenda-propertize-selected-todo-keywords
  4355. org-select-this-todo-keyword))
  4356. (setq pos (point))
  4357. (unless org-agenda-multi
  4358. (insert "Available with `N r': (0)[ALL]")
  4359. (let ((n 0) s)
  4360. (mapc (lambda (x)
  4361. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4362. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4363. (insert "\n "))
  4364. (insert " " s))
  4365. kwds))
  4366. (insert "\n"))
  4367. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4368. (org-agenda-mark-header-line (point-min))
  4369. (when rtnall
  4370. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4371. (goto-char (point-min))
  4372. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4373. (add-text-properties (point-min) (point-max)
  4374. `(org-agenda-type todo
  4375. org-last-args ,arg
  4376. org-redo-cmd ,org-agenda-redo-command
  4377. org-series-cmd ,org-cmd))
  4378. (org-agenda-finalize)
  4379. (setq buffer-read-only t))))
  4380. ;;; Agenda tags match
  4381. ;;;###autoload
  4382. (defun org-tags-view (&optional todo-only match)
  4383. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4384. The prefix arg TODO-ONLY limits the search to TODO entries."
  4385. (interactive "P")
  4386. (if org-agenda-overriding-arguments
  4387. (setq todo-only (car org-agenda-overriding-arguments)
  4388. match (nth 1 org-agenda-overriding-arguments)))
  4389. (let* ((org-tags-match-list-sublevels
  4390. org-tags-match-list-sublevels)
  4391. (completion-ignore-case t)
  4392. rtn rtnall files file pos matcher
  4393. buffer)
  4394. (when (and (stringp match) (not (string-match "\\S-" match)))
  4395. (setq match nil))
  4396. (catch 'exit
  4397. (if org-agenda-sticky
  4398. (setq org-agenda-buffer-name
  4399. (if (stringp match)
  4400. (format "*Org Agenda(%s:%s)*"
  4401. (or org-keys (or (and todo-only "M") "m")) match)
  4402. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4403. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4404. ;; expanding tags within `org-make-tags-matcher'
  4405. (org-agenda-prepare (concat "TAGS " match))
  4406. (setq matcher (org-make-tags-matcher match)
  4407. match (car matcher) matcher (cdr matcher))
  4408. (org-compile-prefix-format 'tags)
  4409. (org-set-sorting-strategy 'tags)
  4410. (setq org-agenda-query-string match)
  4411. (setq org-agenda-redo-command
  4412. (list 'org-tags-view `(quote ,todo-only)
  4413. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4414. (setq files (org-agenda-files nil 'ifmode)
  4415. rtnall nil)
  4416. (while (setq file (pop files))
  4417. (catch 'nextfile
  4418. (org-check-agenda-file file)
  4419. (setq buffer (if (file-exists-p file)
  4420. (org-get-agenda-file-buffer file)
  4421. (error "No such file %s" file)))
  4422. (if (not buffer)
  4423. ;; If file does not exist, error message to agenda
  4424. (setq rtn (list
  4425. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4426. rtnall (append rtnall rtn))
  4427. (with-current-buffer buffer
  4428. (unless (derived-mode-p 'org-mode)
  4429. (error "Agenda file %s is not in `org-mode'" file))
  4430. (save-excursion
  4431. (save-restriction
  4432. (if (eq buffer org-agenda-restrict)
  4433. (narrow-to-region org-agenda-restrict-begin
  4434. org-agenda-restrict-end)
  4435. (widen))
  4436. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4437. (setq rtnall (append rtnall rtn))))))))
  4438. (if org-agenda-overriding-header
  4439. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4440. nil 'face 'org-agenda-structure) "\n")
  4441. (insert "Headlines with TAGS match: ")
  4442. (add-text-properties (point-min) (1- (point))
  4443. (list 'face 'org-agenda-structure
  4444. 'short-heading
  4445. (concat "Match: " match)))
  4446. (setq pos (point))
  4447. (insert match "\n")
  4448. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4449. (setq pos (point))
  4450. (unless org-agenda-multi
  4451. (insert "Press `C-u r' to search again with new search string\n"))
  4452. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4453. (org-agenda-mark-header-line (point-min))
  4454. (when rtnall
  4455. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4456. (goto-char (point-min))
  4457. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4458. (add-text-properties (point-min) (point-max)
  4459. `(org-agenda-type tags
  4460. org-last-args (,todo-only ,match)
  4461. org-redo-cmd ,org-agenda-redo-command
  4462. org-series-cmd ,org-cmd))
  4463. (org-agenda-finalize)
  4464. (setq buffer-read-only t))))
  4465. ;;; Agenda Finding stuck projects
  4466. (defvar org-agenda-skip-regexp nil
  4467. "Regular expression used in skipping subtrees for the agenda.
  4468. This is basically a temporary global variable that can be set and then
  4469. used by user-defined selections using `org-agenda-skip-function'.")
  4470. (defvar org-agenda-overriding-header nil
  4471. "When set during agenda, todo and tags searches it replaces the header.
  4472. This variable should not be set directly, but custom commands can bind it
  4473. in the options section.")
  4474. (defun org-agenda-skip-entry-when-regexp-matches ()
  4475. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4476. If yes, it returns the end position of this entry, causing agenda commands
  4477. to skip the entry but continuing the search in the subtree. This is a
  4478. function that can be put into `org-agenda-skip-function' for the duration
  4479. of a command."
  4480. (let ((end (save-excursion (org-end-of-subtree t)))
  4481. skip)
  4482. (save-excursion
  4483. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4484. (and skip end)))
  4485. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4486. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4487. If yes, it returns the end position of this tree, causing agenda commands
  4488. to skip this subtree. This is a function that can be put into
  4489. `org-agenda-skip-function' for the duration of a command."
  4490. (let ((end (save-excursion (org-end-of-subtree t)))
  4491. skip)
  4492. (save-excursion
  4493. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4494. (and skip end)))
  4495. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4496. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4497. If yes, it returns the end position of the current entry (NOT the tree),
  4498. causing agenda commands to skip the entry but continuing the search in
  4499. the subtree. This is a function that can be put into
  4500. `org-agenda-skip-function' for the duration of a command. An important
  4501. use of this function is for the stuck project list."
  4502. (let ((end (save-excursion (org-end-of-subtree t)))
  4503. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4504. skip)
  4505. (save-excursion
  4506. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4507. (and skip entry-end)))
  4508. (defun org-agenda-skip-entry-if (&rest conditions)
  4509. "Skip entry if any of CONDITIONS is true.
  4510. See `org-agenda-skip-if' for details."
  4511. (org-agenda-skip-if nil conditions))
  4512. (defun org-agenda-skip-subtree-if (&rest conditions)
  4513. "Skip subtree if any of CONDITIONS is true.
  4514. See `org-agenda-skip-if' for details."
  4515. (org-agenda-skip-if t conditions))
  4516. (defun org-agenda-skip-if (subtree conditions)
  4517. "Checks current entity for CONDITIONS.
  4518. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4519. the entry (i.e. the text before the next heading) is checked.
  4520. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4521. from different tests. Valid conditions are:
  4522. scheduled Check if there is a scheduled cookie
  4523. notscheduled Check if there is no scheduled cookie
  4524. deadline Check if there is a deadline
  4525. notdeadline Check if there is no deadline
  4526. timestamp Check if there is a timestamp (also deadline or scheduled)
  4527. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4528. regexp Check if regexp matches
  4529. notregexp Check if regexp does not match.
  4530. todo Check if TODO keyword matches
  4531. nottodo Check if TODO keyword does not match
  4532. The regexp is taken from the conditions list, it must come right after
  4533. the `regexp' or `notregexp' element.
  4534. `todo' and `nottodo' accept as an argument a list of todo
  4535. keywords, which may include \"*\" to match any todo keyword.
  4536. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4537. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4538. Instead of a list, a keyword class may be given. For example:
  4539. (org-agenda-skip-entry-if 'nottodo 'done)
  4540. would skip entries that haven't been marked with any of \"DONE\"
  4541. keywords. Possible classes are: `todo', `done', `any'.
  4542. If any of these conditions is met, this function returns the end point of
  4543. the entity, causing the search to continue from there. This is a function
  4544. that can be put into `org-agenda-skip-function' for the duration of a command."
  4545. (let (beg end m)
  4546. (org-back-to-heading t)
  4547. (setq beg (point)
  4548. end (if subtree
  4549. (progn (org-end-of-subtree t) (point))
  4550. (progn (outline-next-heading) (1- (point)))))
  4551. (goto-char beg)
  4552. (and
  4553. (or
  4554. (and (memq 'scheduled conditions)
  4555. (re-search-forward org-scheduled-time-regexp end t))
  4556. (and (memq 'notscheduled conditions)
  4557. (not (re-search-forward org-scheduled-time-regexp end t)))
  4558. (and (memq 'deadline conditions)
  4559. (re-search-forward org-deadline-time-regexp end t))
  4560. (and (memq 'notdeadline conditions)
  4561. (not (re-search-forward org-deadline-time-regexp end t)))
  4562. (and (memq 'timestamp conditions)
  4563. (re-search-forward org-ts-regexp end t))
  4564. (and (memq 'nottimestamp conditions)
  4565. (not (re-search-forward org-ts-regexp end t)))
  4566. (and (setq m (memq 'regexp conditions))
  4567. (stringp (nth 1 m))
  4568. (re-search-forward (nth 1 m) end t))
  4569. (and (setq m (memq 'notregexp conditions))
  4570. (stringp (nth 1 m))
  4571. (not (re-search-forward (nth 1 m) end t)))
  4572. (and (or
  4573. (setq m (memq 'nottodo conditions))
  4574. (setq m (memq 'todo-unblocked conditions))
  4575. (setq m (memq 'nottodo-unblocked conditions))
  4576. (setq m (memq 'todo conditions)))
  4577. (org-agenda-skip-if-todo m end)))
  4578. end)))
  4579. (defun org-agenda-skip-if-todo (args end)
  4580. "Helper function for `org-agenda-skip-if', do not use it directly.
  4581. ARGS is a list with first element either `todo', `nottodo',
  4582. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4583. a list of TODO keywords, or a state symbol `todo' or `done' or
  4584. `any'."
  4585. (let ((kw (car args))
  4586. (arg (cadr args))
  4587. todo-wds todo-re)
  4588. (setq todo-wds
  4589. (org-uniquify
  4590. (cond
  4591. ((listp arg) ;; list of keywords
  4592. (if (member "*" arg)
  4593. (mapcar 'substring-no-properties org-todo-keywords-1)
  4594. arg))
  4595. ((symbolp arg) ;; keyword class name
  4596. (cond
  4597. ((eq arg 'todo)
  4598. (org-delete-all org-done-keywords
  4599. (mapcar 'substring-no-properties
  4600. org-todo-keywords-1)))
  4601. ((eq arg 'done) org-done-keywords)
  4602. ((eq arg 'any)
  4603. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4604. (setq todo-re
  4605. (concat "^\\*+[ \t]+\\<\\("
  4606. (mapconcat 'identity todo-wds "\\|")
  4607. "\\)\\>"))
  4608. (cond
  4609. ((eq kw 'todo) (re-search-forward todo-re end t))
  4610. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4611. ((eq kw 'todo-unblocked)
  4612. (catch 'unblocked
  4613. (while (re-search-forward todo-re end t)
  4614. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4615. nil))
  4616. ((eq kw 'nottodo-unblocked)
  4617. (catch 'unblocked
  4618. (while (re-search-forward todo-re end t)
  4619. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4620. t))
  4621. )))
  4622. ;;;###autoload
  4623. (defun org-agenda-list-stuck-projects (&rest ignore)
  4624. "Create agenda view for projects that are stuck.
  4625. Stuck projects are project that have no next actions. For the definitions
  4626. of what a project is and how to check if it stuck, customize the variable
  4627. `org-stuck-projects'."
  4628. (interactive)
  4629. (let* ((org-agenda-skip-function
  4630. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4631. ;; We could have used org-agenda-skip-if here.
  4632. (org-agenda-overriding-header
  4633. (or org-agenda-overriding-header "List of stuck projects: "))
  4634. (matcher (nth 0 org-stuck-projects))
  4635. (todo (nth 1 org-stuck-projects))
  4636. (todo-wds (if (member "*" todo)
  4637. (progn
  4638. (org-agenda-prepare-buffers (org-agenda-files
  4639. nil 'ifmode))
  4640. (org-delete-all
  4641. org-done-keywords-for-agenda
  4642. (copy-sequence org-todo-keywords-for-agenda)))
  4643. todo))
  4644. (todo-re (concat "^\\*+[ \t]+\\("
  4645. (mapconcat 'identity todo-wds "\\|")
  4646. "\\)\\>"))
  4647. (tags (nth 2 org-stuck-projects))
  4648. (tags-re (if (member "*" tags)
  4649. (concat org-outline-regexp-bol
  4650. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4651. (if tags
  4652. (concat org-outline-regexp-bol
  4653. ".*:\\("
  4654. (mapconcat 'identity tags "\\|")
  4655. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4656. (gen-re (nth 3 org-stuck-projects))
  4657. (re-list
  4658. (delq nil
  4659. (list
  4660. (if todo todo-re)
  4661. (if tags tags-re)
  4662. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4663. gen-re)))))
  4664. (setq org-agenda-skip-regexp
  4665. (if re-list
  4666. (mapconcat 'identity re-list "\\|")
  4667. (error "No information how to identify unstuck projects")))
  4668. (org-tags-view nil matcher)
  4669. (setq org-agenda-buffer-name (buffer-name))
  4670. (with-current-buffer org-agenda-buffer-name
  4671. (setq org-agenda-redo-command
  4672. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4673. ;;; Diary integration
  4674. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4675. (defvar diary-list-entries-hook)
  4676. (defvar diary-time-regexp)
  4677. (defun org-get-entries-from-diary (date)
  4678. "Get the (Emacs Calendar) diary entries for DATE."
  4679. (require 'diary-lib)
  4680. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4681. (diary-display-hook '(fancy-diary-display))
  4682. (diary-display-function 'fancy-diary-display)
  4683. (pop-up-frames nil)
  4684. (diary-list-entries-hook
  4685. (cons 'org-diary-default-entry diary-list-entries-hook))
  4686. (diary-file-name-prefix nil) ; turn this feature off
  4687. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4688. entries
  4689. (org-disable-agenda-to-diary t))
  4690. (save-excursion
  4691. (save-window-excursion
  4692. (funcall (if (fboundp 'diary-list-entries)
  4693. 'diary-list-entries 'list-diary-entries)
  4694. date 1)))
  4695. (if (not (get-buffer diary-fancy-buffer))
  4696. (setq entries nil)
  4697. (with-current-buffer diary-fancy-buffer
  4698. (setq buffer-read-only nil)
  4699. (if (zerop (buffer-size))
  4700. ;; No entries
  4701. (setq entries nil)
  4702. ;; Omit the date and other unnecessary stuff
  4703. (org-agenda-cleanup-fancy-diary)
  4704. ;; Add prefix to each line and extend the text properties
  4705. (if (zerop (buffer-size))
  4706. (setq entries nil)
  4707. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4708. (setq entries
  4709. (with-temp-buffer
  4710. (insert entries) (goto-char (point-min))
  4711. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4712. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4713. (replace-match (concat "; " (match-string 1)))))
  4714. (buffer-string)))))
  4715. (set-buffer-modified-p nil)
  4716. (kill-buffer diary-fancy-buffer)))
  4717. (when entries
  4718. (setq entries (org-split-string entries "\n"))
  4719. (setq entries
  4720. (mapcar
  4721. (lambda (x)
  4722. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4723. ;; Extend the text properties to the beginning of the line
  4724. (org-add-props x (text-properties-at (1- (length x)) x)
  4725. 'type "diary" 'date date 'face 'org-agenda-diary))
  4726. entries)))))
  4727. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4728. "Hook run when the fancy diary buffer is cleaned up.")
  4729. (defun org-agenda-cleanup-fancy-diary ()
  4730. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4731. This gets rid of the date, the underline under the date, and
  4732. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4733. date. It also removes lines that contain only whitespace."
  4734. (goto-char (point-min))
  4735. (if (looking-at ".*?:[ \t]*")
  4736. (progn
  4737. (replace-match "")
  4738. (re-search-forward "\n=+$" nil t)
  4739. (replace-match "")
  4740. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4741. (re-search-forward "\n=+$" nil t)
  4742. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4743. (goto-char (point-min))
  4744. (while (re-search-forward "^ +\n" nil t)
  4745. (replace-match ""))
  4746. (goto-char (point-min))
  4747. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4748. (replace-match ""))
  4749. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4750. ;; Make sure entries from the diary have the right text properties.
  4751. (eval-after-load "diary-lib"
  4752. '(if (boundp 'diary-modify-entry-list-string-function)
  4753. ;; We can rely on the hook, nothing to do
  4754. nil
  4755. ;; Hook not available, must use advice to make this work
  4756. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4757. "Make the position visible."
  4758. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4759. (stringp string)
  4760. buffer-file-name)
  4761. (setq string (org-modify-diary-entry-string string))))))
  4762. (defun org-modify-diary-entry-string (string)
  4763. "Add text properties to string, allowing org-mode to act on it."
  4764. (org-add-props string nil
  4765. 'mouse-face 'highlight
  4766. 'help-echo (if buffer-file-name
  4767. (format "mouse-2 or RET jump to diary file %s"
  4768. (abbreviate-file-name buffer-file-name))
  4769. "")
  4770. 'org-agenda-diary-link t
  4771. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4772. (defun org-diary-default-entry ()
  4773. "Add a dummy entry to the diary.
  4774. Needed to avoid empty dates which mess up holiday display."
  4775. ;; Catch the error if dealing with the new add-to-diary-alist
  4776. (when org-disable-agenda-to-diary
  4777. (condition-case nil
  4778. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4779. (error
  4780. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4781. (defun org-add-to-diary-list (&rest args)
  4782. (if (fboundp 'diary-add-to-list)
  4783. (apply 'diary-add-to-list args)
  4784. (apply 'add-to-diary-list args)))
  4785. (defvar org-diary-last-run-time nil)
  4786. ;;;###autoload
  4787. (defun org-diary (&rest args)
  4788. "Return diary information from org files.
  4789. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4790. It accesses org files and extracts information from those files to be
  4791. listed in the diary. The function accepts arguments specifying what
  4792. items should be listed. For a list of arguments allowed here, see the
  4793. variable `org-agenda-entry-types'.
  4794. The call in the diary file should look like this:
  4795. &%%(org-diary) ~/path/to/some/orgfile.org
  4796. Use a separate line for each org file to check. Or, if you omit the file name,
  4797. all files listed in `org-agenda-files' will be checked automatically:
  4798. &%%(org-diary)
  4799. If you don't give any arguments (as in the example above), the default value
  4800. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4801. So the example above may also be written as
  4802. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4803. The function expects the lisp variables `entry' and `date' to be provided
  4804. by the caller, because this is how the calendar works. Don't use this
  4805. function from a program - use `org-agenda-get-day-entries' instead."
  4806. (when (> (- (org-float-time)
  4807. org-agenda-last-marker-time)
  4808. 5)
  4809. ;; I am not sure if this works with sticky agendas, because the marker
  4810. ;; list is then no longer a global variable.
  4811. (org-agenda-reset-markers))
  4812. (org-compile-prefix-format 'agenda)
  4813. (org-set-sorting-strategy 'agenda)
  4814. (setq args (or args org-agenda-entry-types))
  4815. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4816. (list entry)
  4817. (org-agenda-files t)))
  4818. (time (org-float-time))
  4819. file rtn results)
  4820. (when (or (not org-diary-last-run-time)
  4821. (> (- time
  4822. org-diary-last-run-time)
  4823. 3))
  4824. (org-agenda-prepare-buffers files))
  4825. (setq org-diary-last-run-time time)
  4826. ;; If this is called during org-agenda, don't return any entries to
  4827. ;; the calendar. Org Agenda will list these entries itself.
  4828. (if org-disable-agenda-to-diary (setq files nil))
  4829. (while (setq file (pop files))
  4830. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4831. (setq results (append results rtn)))
  4832. (when results
  4833. (setq results
  4834. (mapcar (lambda (i) (replace-regexp-in-string
  4835. org-bracket-link-regexp "\\3" i)) results))
  4836. (concat (org-agenda-finalize-entries results) "\n"))))
  4837. ;;; Agenda entry finders
  4838. (defun org-agenda-get-day-entries (file date &rest args)
  4839. "Does the work for `org-diary' and `org-agenda'.
  4840. FILE is the path to a file to be checked for entries. DATE is date like
  4841. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4842. which kind of entries should be extracted. For details about these, see
  4843. the documentation of `org-diary'."
  4844. (setq args (or args org-agenda-entry-types))
  4845. (let* ((org-startup-folded nil)
  4846. (org-startup-align-all-tables nil)
  4847. (buffer (if (file-exists-p file)
  4848. (org-get-agenda-file-buffer file)
  4849. (error "No such file %s" file)))
  4850. arg results rtn deadline-results)
  4851. (if (not buffer)
  4852. ;; If file does not exist, make sure an error message ends up in diary
  4853. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4854. (with-current-buffer buffer
  4855. (unless (derived-mode-p 'org-mode)
  4856. (error "Agenda file %s is not in `org-mode'" file))
  4857. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4858. (let ((case-fold-search nil))
  4859. (save-excursion
  4860. (save-restriction
  4861. (if (eq buffer org-agenda-restrict)
  4862. (narrow-to-region org-agenda-restrict-begin
  4863. org-agenda-restrict-end)
  4864. (widen))
  4865. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4866. (while (setq arg (pop args))
  4867. (cond
  4868. ((and (eq arg :todo)
  4869. (equal date (calendar-gregorian-from-absolute
  4870. (org-today))))
  4871. (setq rtn (org-agenda-get-todos))
  4872. (setq results (append results rtn)))
  4873. ((eq arg :timestamp)
  4874. (setq rtn (org-agenda-get-blocks))
  4875. (setq results (append results rtn))
  4876. (setq rtn (org-agenda-get-timestamps deadline-results))
  4877. (setq results (append results rtn)))
  4878. ((eq arg :sexp)
  4879. (setq rtn (org-agenda-get-sexps))
  4880. (setq results (append results rtn)))
  4881. ((eq arg :scheduled)
  4882. (setq rtn (org-agenda-get-scheduled deadline-results))
  4883. (setq results (append results rtn)))
  4884. ((eq arg :scheduled*)
  4885. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4886. (setq results (append results rtn)))
  4887. ((eq arg :closed)
  4888. (setq rtn (org-agenda-get-progress))
  4889. (setq results (append results rtn)))
  4890. ((eq arg :deadline)
  4891. (setq rtn (org-agenda-get-deadlines))
  4892. (setq deadline-results (copy-sequence rtn))
  4893. (setq results (append results rtn)))
  4894. ((eq arg :deadline*)
  4895. (setq rtn (org-agenda-get-deadlines t))
  4896. (setq deadline-results (copy-sequence rtn))
  4897. (setq results (append results rtn))))))))
  4898. results))))
  4899. (defsubst org-em (x y list)
  4900. "Is X or Y a member of LIST?"
  4901. (or (memq x list) (memq y list)))
  4902. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4903. (defvar org-agenda-sorting-strategy-selected nil)
  4904. (defun org-agenda-get-todos ()
  4905. "Return the TODO information for agenda display."
  4906. (let* ((props (list 'face nil
  4907. 'done-face 'org-agenda-done
  4908. 'org-not-done-regexp org-not-done-regexp
  4909. 'org-todo-regexp org-todo-regexp
  4910. 'org-complex-heading-regexp org-complex-heading-regexp
  4911. 'mouse-face 'highlight
  4912. 'help-echo
  4913. (format "mouse-2 or RET jump to org file %s"
  4914. (abbreviate-file-name buffer-file-name))))
  4915. (regexp (format org-heading-keyword-regexp-format
  4916. (cond
  4917. ((and org-select-this-todo-keyword
  4918. (equal org-select-this-todo-keyword "*"))
  4919. org-todo-regexp)
  4920. (org-select-this-todo-keyword
  4921. (concat "\\("
  4922. (mapconcat 'identity
  4923. (org-split-string
  4924. org-select-this-todo-keyword
  4925. "|")
  4926. "\\|") "\\)"))
  4927. (t org-not-done-regexp))))
  4928. marker priority category level tags todo-state ts-date ts-date-type
  4929. ee txt beg end inherited-tags todo-state-end-pos)
  4930. (goto-char (point-min))
  4931. (while (re-search-forward regexp nil t)
  4932. (catch :skip
  4933. (save-match-data
  4934. (beginning-of-line)
  4935. (org-agenda-skip)
  4936. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4937. (unless (and (setq todo-state (org-get-todo-state))
  4938. (setq todo-state-end-pos (match-end 2)))
  4939. (goto-char end)
  4940. (throw :skip nil))
  4941. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4942. (goto-char (1+ beg))
  4943. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4944. (throw :skip nil)))
  4945. (goto-char (match-beginning 2))
  4946. (setq marker (org-agenda-new-marker (match-beginning 0))
  4947. category (org-get-category)
  4948. ts-date (let (ts)
  4949. (save-match-data
  4950. (cond ((org-em 'scheduled-up 'scheduled-down
  4951. org-agenda-sorting-strategy-selected)
  4952. (setq ts (org-entry-get (point) "SCHEDULED")
  4953. ts-date-type " scheduled"))
  4954. ((org-em 'deadline-up 'deadline-down
  4955. org-agenda-sorting-strategy-selected)
  4956. (setq ts (org-entry-get (point) "DEADLINE")
  4957. ts-date-type " deadline"))
  4958. ((org-em 'ts-up 'ts-down
  4959. org-agenda-sorting-strategy-selected)
  4960. (setq ts (org-entry-get (point) "TIMESTAMP")
  4961. ts-date-type " timestamp"))
  4962. ((org-em 'tsia-up 'tsia-down
  4963. org-agenda-sorting-strategy-selected)
  4964. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4965. ts-date-type " timestamp_ia"))
  4966. ((org-em 'timestamp-up 'timestamp-down
  4967. org-agenda-sorting-strategy-selected)
  4968. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4969. (org-entry-get (point) "DEADLINE")
  4970. (org-entry-get (point) "TIMESTAMP")
  4971. (org-entry-get (point) "TIMESTAMP_IA"))
  4972. ts-date-type ""))
  4973. (t (setq ts-date-type "")))
  4974. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4975. txt (org-trim (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
  4990. 'level level
  4991. 'ts-date ts-date
  4992. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4993. (push txt ee)
  4994. (if org-agenda-todo-list-sublevels
  4995. (goto-char todo-state-end-pos)
  4996. (org-end-of-subtree 'invisible))))
  4997. (nreverse ee)))
  4998. (defun org-agenda-todo-custom-ignore-p (time n)
  4999. "Check whether timestamp is farther away than n number of days.
  5000. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5001. `org-agenda-todo-ignore-scheduled' or
  5002. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5003. (let ((days (org-time-stamp-to-now
  5004. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5005. (if (>= n 0)
  5006. (>= days n)
  5007. (<= days n))))
  5008. ;;;###autoload
  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 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. (save-excursion
  5153. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5154. (throw :skip nil)
  5155. (goto-char (match-beginning 0))
  5156. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5157. (assoc (point) deadline-position-alist))
  5158. (throw :skip nil))
  5159. (setq hdmarker (org-agenda-new-marker)
  5160. inherited-tags
  5161. (or (eq org-agenda-show-inherited-tags 'always)
  5162. (and (listp org-agenda-show-inherited-tags)
  5163. (memq 'agenda org-agenda-show-inherited-tags))
  5164. (and (eq org-agenda-show-inherited-tags t)
  5165. (or (eq org-agenda-use-tag-inheritance t)
  5166. (memq 'agenda org-agenda-use-tag-inheritance))))
  5167. tags (org-get-tags-at nil (not inherited-tags))
  5168. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5169. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5170. (setq head (or (match-string 1) ""))
  5171. (setq txt (org-agenda-format-item
  5172. (if inactivep org-agenda-inactive-leader nil)
  5173. head level category tags timestr
  5174. remove-re habitp)))
  5175. (setq priority (org-get-priority txt))
  5176. (org-add-props txt props 'priority priority
  5177. 'org-marker marker 'org-hd-marker hdmarker
  5178. 'date date
  5179. 'level level
  5180. 'ts-date
  5181. (ignore-errors (org-time-string-to-absolute timestr))
  5182. 'todo-state todo-state
  5183. 'warntime warntime
  5184. 'type "timestamp")
  5185. (push txt ee))
  5186. (if org-agenda-skip-additional-timestamps-same-entry
  5187. (outline-next-heading)
  5188. (goto-char end-of-match))))
  5189. (nreverse ee)))
  5190. (defun org-agenda-get-sexps ()
  5191. "Return the sexp information for agenda display."
  5192. (require 'diary-lib)
  5193. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5194. 'mouse-face 'highlight
  5195. 'help-echo
  5196. (format "mouse-2 or RET jump to org file %s"
  5197. (abbreviate-file-name buffer-file-name))))
  5198. (regexp "^&?%%(")
  5199. marker category extra level ee txt tags entry
  5200. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5201. (goto-char (point-min))
  5202. (while (re-search-forward regexp nil t)
  5203. (catch :skip
  5204. (org-agenda-skip)
  5205. (setq beg (match-beginning 0))
  5206. (goto-char (1- (match-end 0)))
  5207. (setq b (point))
  5208. (forward-sexp 1)
  5209. (setq sexp (buffer-substring b (point)))
  5210. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5211. (org-trim (match-string 1))
  5212. ""))
  5213. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5214. (when result
  5215. (setq marker (org-agenda-new-marker beg)
  5216. level (make-string (org-reduced-level (org-outline-level)) ? )
  5217. category (org-get-category beg)
  5218. inherited-tags
  5219. (or (eq org-agenda-show-inherited-tags 'always)
  5220. (and (listp org-agenda-show-inherited-tags)
  5221. (memq 'agenda org-agenda-show-inherited-tags))
  5222. (and (eq org-agenda-show-inherited-tags t)
  5223. (or (eq org-agenda-use-tag-inheritance t)
  5224. (memq 'agenda org-agenda-use-tag-inheritance))))
  5225. tags (org-get-tags-at nil (not inherited-tags))
  5226. todo-state (org-get-todo-state)
  5227. warntime (get-text-property (point) 'org-appt-warntime)
  5228. extra nil)
  5229. (dolist (r (if (stringp result)
  5230. (list result)
  5231. result)) ;; we expect a list here
  5232. (when (and org-agenda-diary-sexp-prefix
  5233. (string-match org-agenda-diary-sexp-prefix r))
  5234. (setq extra (match-string 0 r)
  5235. r (replace-match "" nil nil r)))
  5236. (if (string-match "\\S-" r)
  5237. (setq txt r)
  5238. (setq txt "SEXP entry returned empty string"))
  5239. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5240. (org-add-props txt props 'org-marker marker
  5241. 'date date 'todo-state todo-state
  5242. 'tags tags 'level level
  5243. 'type "sexp" 'warntime warntime)
  5244. (push txt ee)))))
  5245. (nreverse ee)))
  5246. ;; Calendar sanity: define some functions that are independent of
  5247. ;; `calendar-date-style'.
  5248. ;; Normally I would like to use ISO format when calling the diary functions,
  5249. ;; but to make sure we still have Emacs 22 compatibility we bind
  5250. ;; also `european-calendar-style' and use european format
  5251. (defun org-anniversary (year month day &optional mark)
  5252. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5253. (org-no-warnings
  5254. (let ((calendar-date-style 'european) (european-calendar-style t))
  5255. (diary-anniversary day month year mark))))
  5256. (defun org-cyclic (N year month day &optional mark)
  5257. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5258. (org-no-warnings
  5259. (let ((calendar-date-style 'european) (european-calendar-style t))
  5260. (diary-cyclic N day month year mark))))
  5261. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5262. "Like `diary-block', but with fixed (ISO) order of arguments."
  5263. (org-no-warnings
  5264. (let ((calendar-date-style 'european) (european-calendar-style t))
  5265. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5266. (defun org-date (year month day &optional mark)
  5267. "Like `diary-date', but with fixed (ISO) order of arguments."
  5268. (org-no-warnings
  5269. (let ((calendar-date-style 'european) (european-calendar-style t))
  5270. (diary-date day month year mark))))
  5271. ;; Define the` org-class' function
  5272. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5273. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5274. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5275. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5276. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5277. `holidays', then any date that is known by the Emacs calendar to be a
  5278. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5279. then those holidays will be skipped."
  5280. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5281. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5282. (d (calendar-absolute-from-gregorian date))
  5283. (h (when skip-weeks (calendar-check-holidays date))))
  5284. (and
  5285. (<= date1 d)
  5286. (<= d date2)
  5287. (= (calendar-day-of-week date) dayname)
  5288. (or (not skip-weeks)
  5289. (progn
  5290. (require 'cal-iso)
  5291. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5292. (not (or (and h (memq 'holidays skip-weeks))
  5293. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5294. entry)))
  5295. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5296. "Like `org-class', but honor `calendar-date-style'.
  5297. The order of the first 2 times 3 arguments depends on the variable
  5298. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5299. So for American calendars, give this as MONTH DAY YEAR, for European as
  5300. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5301. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5302. is any number of ISO weeks in the block period for which the item should
  5303. be skipped.
  5304. This function is here only for backward compatibility and it is deprecated,
  5305. please use `org-class' instead."
  5306. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5307. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5308. (org-class
  5309. (nth 2 date1) (car date1) (nth 1 date1)
  5310. (nth 2 date2) (car date2) (nth 1 date2)
  5311. dayname skip-weeks)))
  5312. (make-obsolete 'org-diary-class 'org-class "")
  5313. (defalias 'org-get-closed 'org-agenda-get-progress)
  5314. (defun org-agenda-get-progress ()
  5315. "Return the logged TODO entries for agenda display."
  5316. (let* ((props (list 'mouse-face 'highlight
  5317. 'org-not-done-regexp org-not-done-regexp
  5318. 'org-todo-regexp org-todo-regexp
  5319. 'org-complex-heading-regexp org-complex-heading-regexp
  5320. 'help-echo
  5321. (format "mouse-2 or RET jump to org file %s"
  5322. (abbreviate-file-name buffer-file-name))))
  5323. (items (if (consp org-agenda-show-log-scoped)
  5324. org-agenda-show-log-scoped
  5325. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5326. '(clock)
  5327. org-agenda-log-mode-items)))
  5328. (parts
  5329. (delq nil
  5330. (list
  5331. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5332. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5333. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5334. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5335. (error "`org-agenda-log-mode-items' is empty")))
  5336. (regexp (concat
  5337. "\\(" parts-re "\\)"
  5338. " *\\["
  5339. (regexp-quote
  5340. (substring
  5341. (format-time-string
  5342. (car org-time-stamp-formats)
  5343. (apply 'encode-time ; DATE bound by calendar
  5344. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5345. 1 11))))
  5346. (org-agenda-search-headline-for-time nil)
  5347. marker hdmarker priority category level tags closedp
  5348. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5349. (goto-char (point-min))
  5350. (while (re-search-forward regexp nil t)
  5351. (catch :skip
  5352. (org-agenda-skip)
  5353. (setq marker (org-agenda-new-marker (match-beginning 0))
  5354. closedp (equal (match-string 1) org-closed-string)
  5355. statep (equal (string-to-char (match-string 1)) ?-)
  5356. clockp (not (or closedp statep))
  5357. state (and statep (match-string 2))
  5358. category (org-get-category (match-beginning 0))
  5359. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5360. (when (string-match "\\]" timestr)
  5361. ;; substring should only run to end of time stamp
  5362. (setq rest (substring timestr (match-end 0))
  5363. timestr (substring timestr 0 (match-end 0)))
  5364. (if (and (not closedp) (not statep)
  5365. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5366. rest))
  5367. (progn (setq timestr (concat (substring timestr 0 -1)
  5368. "-" (match-string 1 rest) "]"))
  5369. (setq clocked (match-string 2 rest)))
  5370. (setq clocked "-")))
  5371. (save-excursion
  5372. (setq extra
  5373. (cond
  5374. ((not org-agenda-log-mode-add-notes) nil)
  5375. (statep
  5376. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5377. (match-string 1)))
  5378. (clockp
  5379. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5380. (match-string 1)))))
  5381. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5382. (throw :skip nil)
  5383. (goto-char (match-beginning 0))
  5384. (setq hdmarker (org-agenda-new-marker)
  5385. inherited-tags
  5386. (or (eq org-agenda-show-inherited-tags 'always)
  5387. (and (listp org-agenda-show-inherited-tags)
  5388. (memq 'todo org-agenda-show-inherited-tags))
  5389. (and (eq org-agenda-show-inherited-tags t)
  5390. (or (eq org-agenda-use-tag-inheritance t)
  5391. (memq 'todo org-agenda-use-tag-inheritance))))
  5392. tags (org-get-tags-at nil (not inherited-tags))
  5393. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5394. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5395. (setq txt (match-string 1))
  5396. (when extra
  5397. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5398. (setq txt (concat (substring txt 0 (match-beginning 1))
  5399. " - " extra " " (match-string 2 txt)))
  5400. (setq txt (concat txt " - " extra))))
  5401. (setq txt (org-agenda-format-item
  5402. (cond
  5403. (closedp "Closed: ")
  5404. (statep (concat "State: (" state ")"))
  5405. (t (concat "Clocked: (" clocked ")")))
  5406. txt level category tags timestr)))
  5407. (setq priority 100000)
  5408. (org-add-props txt props
  5409. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5410. 'priority priority 'level level
  5411. 'type "closed" 'date date
  5412. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5413. (push txt ee))
  5414. (goto-char (point-at-eol))))
  5415. (nreverse ee)))
  5416. (defun org-agenda-show-clocking-issues ()
  5417. "Add overlays, showing issues with clocking.
  5418. See also the user option `org-agenda-clock-consistency-checks'."
  5419. (interactive)
  5420. (let* ((org-time-clocksum-use-effort-durations nil)
  5421. (pl org-agenda-clock-consistency-checks)
  5422. (re (concat "^[ \t]*"
  5423. org-clock-string
  5424. "[ \t]+"
  5425. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5426. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5427. (tlstart 0.)
  5428. (tlend 0.)
  5429. (maxtime (org-hh:mm-string-to-minutes
  5430. (or (plist-get pl :max-duration) "24:00")))
  5431. (mintime (org-hh:mm-string-to-minutes
  5432. (or (plist-get pl :min-duration) 0)))
  5433. (maxgap (org-hh:mm-string-to-minutes
  5434. ;; default 30:00 means never complain
  5435. (or (plist-get pl :max-gap) "30:00")))
  5436. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5437. (plist-get pl :gap-ok-around)))
  5438. (def-face (or (plist-get pl :default-face)
  5439. '((:background "DarkRed") (:foreground "white"))))
  5440. issue face m te ts dt ov)
  5441. (goto-char (point-min))
  5442. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5443. (setq issue nil face def-face)
  5444. (catch 'next
  5445. (setq m (org-get-at-bol 'org-marker)
  5446. te nil ts nil)
  5447. (unless (and m (markerp m))
  5448. (setq issue "No valid clock line") (throw 'next t))
  5449. (org-with-point-at m
  5450. (save-excursion
  5451. (goto-char (point-at-bol))
  5452. (unless (looking-at re)
  5453. (error "No valid Clock line")
  5454. (throw 'next t))
  5455. (unless (match-end 3)
  5456. (setq issue "No end time"
  5457. face (or (plist-get pl :no-end-time-face) face))
  5458. (throw 'next t))
  5459. (setq ts (match-string 1)
  5460. te (match-string 3)
  5461. ts (org-float-time
  5462. (apply 'encode-time (org-parse-time-string ts)))
  5463. te (org-float-time
  5464. (apply 'encode-time (org-parse-time-string te)))
  5465. dt (- te ts))))
  5466. (cond
  5467. ((> dt (* 60 maxtime))
  5468. ;; a very long clocking chunk
  5469. (setq issue (format "Clocking interval is very long: %s"
  5470. (org-minutes-to-clocksum-string
  5471. (floor (/ (float dt) 60.))))
  5472. face (or (plist-get pl :long-face) face)))
  5473. ((< dt (* 60 mintime))
  5474. ;; a very short clocking chunk
  5475. (setq issue (format "Clocking interval is very short: %s"
  5476. (org-minutes-to-clocksum-string
  5477. (floor (/ (float dt) 60.))))
  5478. face (or (plist-get pl :short-face) face)))
  5479. ((and (> tlend 0) (< ts tlend))
  5480. ;; Two clock entries are overlapping
  5481. (setq issue (format "Clocking overlap: %d minutes"
  5482. (/ (- tlend ts) 60))
  5483. face (or (plist-get pl :overlap-face) face)))
  5484. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5485. ;; There is a gap, lets see if we need to report it
  5486. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5487. (setq issue (format "Clocking gap: %d minutes"
  5488. (/ (- ts tlend) 60))
  5489. face (or (plist-get pl :gap-face) face))))
  5490. (t nil)))
  5491. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5492. (when issue
  5493. ;; OK, there was some issue, add an overlay to show the issue
  5494. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5495. (overlay-put ov 'before-string
  5496. (concat
  5497. (org-add-props
  5498. (format "%-43s" (concat " " issue))
  5499. nil
  5500. 'face face)
  5501. "\n"))
  5502. (overlay-put ov 'evaporate t)))))
  5503. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5504. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5505. (catch 'exit
  5506. (unless ok-list
  5507. ;; there are no OK times for gaps...
  5508. (throw 'exit nil))
  5509. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5510. ;; This is more than 24 hours, so it is OK.
  5511. ;; because we have at least one OK time, that must be in the
  5512. ;; 24 hour interval.
  5513. (throw 'exit t))
  5514. ;; We have a shorter gap.
  5515. ;; Now we have to get the minute of the day when these times are
  5516. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5517. (t2dec (decode-time (seconds-to-time t2)))
  5518. ;; compute the minute on the day
  5519. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5520. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5521. (when (< min2 min1)
  5522. ;; if min2 is smaller than min1, this means it is on the next day.
  5523. ;; Wrap it to after midnight.
  5524. (setq min2 (+ min2 1440)))
  5525. ;; Now check if any of the OK times is in the gap
  5526. (mapc (lambda (x)
  5527. ;; Wrap the time to after midnight if necessary
  5528. (if (< x min1) (setq x (+ x 1440)))
  5529. ;; Check if in interval
  5530. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5531. ok-list)
  5532. ;; Nope, this gap is not OK
  5533. nil)))
  5534. (defun org-agenda-get-deadlines (&optional with-hour)
  5535. "Return the deadline information for agenda display.
  5536. When WITH-HOUR is non-nil, only return deadlines with an hour
  5537. specification like [h]h:mm."
  5538. (let* ((props (list 'mouse-face 'highlight
  5539. 'org-not-done-regexp org-not-done-regexp
  5540. 'org-todo-regexp org-todo-regexp
  5541. 'org-complex-heading-regexp org-complex-heading-regexp
  5542. 'help-echo
  5543. (format "mouse-2 or RET jump to org file %s"
  5544. (abbreviate-file-name buffer-file-name))))
  5545. (regexp (if with-hour
  5546. org-deadline-time-hour-regexp
  5547. org-deadline-time-regexp))
  5548. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5549. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5550. (dl0 (car org-agenda-deadline-leaders))
  5551. (dl1 (nth 1 org-agenda-deadline-leaders))
  5552. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5553. d2 diff dfrac wdays pos pos1 category level
  5554. tags suppress-prewarning ee txt head face s todo-state
  5555. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5556. (goto-char (point-min))
  5557. (while (re-search-forward regexp nil t)
  5558. (catch :skip
  5559. (org-agenda-skip)
  5560. (setq s (match-string 1)
  5561. txt nil
  5562. pos (1- (match-beginning 1))
  5563. todo-state (save-match-data (org-get-todo-state))
  5564. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5565. (member todo-state
  5566. org-agenda-repeating-timestamp-show-all))
  5567. d2 (org-time-string-to-absolute
  5568. s d1 'past show-all (current-buffer) pos)
  5569. diff (- d2 d1))
  5570. (setq suppress-prewarning
  5571. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5572. (let ((item (buffer-substring (point-at-bol)
  5573. (point-at-eol))))
  5574. (save-match-data
  5575. (and (string-match
  5576. org-scheduled-time-regexp item)
  5577. (match-string 1 item)))))))
  5578. (cond
  5579. ((not ds) nil)
  5580. ;; The current item has a scheduled date (in ds), so
  5581. ;; evaluate its prewarning lead time.
  5582. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5583. ;; Use global prewarning-restart lead time.
  5584. org-agenda-skip-deadline-prewarning-if-scheduled)
  5585. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5586. 'pre-scheduled)
  5587. ;; Set prewarning to no earlier than scheduled.
  5588. (min (- d2 (org-time-string-to-absolute
  5589. ds d1 'past show-all (current-buffer) pos))
  5590. org-deadline-warning-days))
  5591. ;; Set prewarning to deadline.
  5592. (t 0))))
  5593. (setq wdays (if suppress-prewarning
  5594. (let ((org-deadline-warning-days suppress-prewarning))
  5595. (org-get-wdays s))
  5596. (org-get-wdays s))
  5597. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5598. upcomingp (and todayp (> diff 0)))
  5599. ;; When to show a deadline in the calendar:
  5600. ;; If the expiration is within wdays warning time.
  5601. ;; Past-due deadlines are only shown on the current date
  5602. (if (and (or (and (<= diff wdays)
  5603. (and todayp (not org-agenda-only-exact-dates)))
  5604. (= diff 0)))
  5605. (save-excursion
  5606. ;; (setq todo-state (org-get-todo-state))
  5607. (setq donep (member todo-state org-done-keywords))
  5608. (if (and donep
  5609. (or org-agenda-skip-deadline-if-done
  5610. (not (= diff 0))))
  5611. (setq txt nil)
  5612. (setq category (org-get-category)
  5613. warntime (get-text-property (point) 'org-appt-warntime))
  5614. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5615. (throw :skip nil)
  5616. (goto-char (match-end 0))
  5617. (setq pos1 (match-beginning 0))
  5618. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5619. (setq inherited-tags
  5620. (or (eq org-agenda-show-inherited-tags 'always)
  5621. (and (listp org-agenda-show-inherited-tags)
  5622. (memq 'agenda org-agenda-show-inherited-tags))
  5623. (and (eq org-agenda-show-inherited-tags t)
  5624. (or (eq org-agenda-use-tag-inheritance t)
  5625. (memq 'agenda org-agenda-use-tag-inheritance))))
  5626. tags (org-get-tags-at pos1 (not inherited-tags)))
  5627. (setq head (buffer-substring
  5628. (point)
  5629. (progn (skip-chars-forward "^\r\n")
  5630. (point))))
  5631. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5632. (setq timestr
  5633. (concat (substring s (match-beginning 1)) " "))
  5634. (setq timestr 'time))
  5635. (setq txt (org-agenda-format-item
  5636. (cond ((= diff 0) dl0)
  5637. ((> diff 0)
  5638. (if (functionp dl1)
  5639. (funcall dl1 diff date)
  5640. (format dl1 diff)))
  5641. (t
  5642. (if (functionp dl2)
  5643. (funcall dl2 diff date)
  5644. (format dl2 (if (string= dl2 dl1)
  5645. diff (abs diff))))))
  5646. head level category tags
  5647. (if (not (= diff 0)) nil timestr)))))
  5648. (when txt
  5649. (setq face (org-agenda-deadline-face dfrac))
  5650. (org-add-props txt props
  5651. 'org-marker (org-agenda-new-marker pos)
  5652. 'warntime warntime
  5653. 'level level
  5654. 'ts-date d2
  5655. 'org-hd-marker (org-agenda-new-marker pos1)
  5656. 'priority (+ (- diff)
  5657. (org-get-priority txt))
  5658. 'todo-state todo-state
  5659. 'type (if upcomingp "upcoming-deadline" "deadline")
  5660. 'date (if upcomingp date d2)
  5661. 'face (if donep 'org-agenda-done face)
  5662. 'undone-face face 'done-face 'org-agenda-done)
  5663. (push txt ee))))))
  5664. (nreverse ee)))
  5665. (defun org-agenda-deadline-face (fraction)
  5666. "Return the face to displaying a deadline item.
  5667. FRACTION is what fraction of the head-warning time has passed."
  5668. (let ((faces org-agenda-deadline-faces) f)
  5669. (catch 'exit
  5670. (while (setq f (pop faces))
  5671. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5672. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5673. "Return the scheduled information for agenda display.
  5674. When WITH-HOUR is non-nil, only return scheduled items with
  5675. an hour specification like [h]h:mm."
  5676. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5677. 'org-todo-regexp org-todo-regexp
  5678. 'org-complex-heading-regexp org-complex-heading-regexp
  5679. 'done-face 'org-agenda-done
  5680. 'mouse-face 'highlight
  5681. 'help-echo
  5682. (format "mouse-2 or RET jump to org file %s"
  5683. (abbreviate-file-name buffer-file-name))))
  5684. (regexp (if with-hour
  5685. org-scheduled-time-hour-regexp
  5686. org-scheduled-time-regexp))
  5687. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5688. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5689. mm
  5690. (deadline-position-alist
  5691. (mapcar (lambda (a) (and (setq mm (get-text-property
  5692. 0 'org-hd-marker a))
  5693. (cons (marker-position mm) a)))
  5694. deadline-results))
  5695. d2 diff pos pos1 category level tags donep
  5696. ee txt head pastschedp todo-state face timestr s habitp show-all
  5697. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5698. ddays)
  5699. (goto-char (point-min))
  5700. (while (re-search-forward regexp nil t)
  5701. (catch :skip
  5702. (org-agenda-skip)
  5703. (setq s (match-string 1)
  5704. txt nil
  5705. pos (1- (match-beginning 1))
  5706. todo-state (save-match-data (org-get-todo-state))
  5707. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5708. (member todo-state
  5709. org-agenda-repeating-timestamp-show-all))
  5710. d2 (org-time-string-to-absolute
  5711. s d1 'past show-all (current-buffer) pos)
  5712. diff (- d2 d1)
  5713. warntime (get-text-property (point) 'org-appt-warntime))
  5714. (setq pastschedp (and todayp (< diff 0)))
  5715. (setq did-habit-check-p nil)
  5716. (setq suppress-delay
  5717. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5718. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5719. (save-match-data
  5720. (and (string-match
  5721. org-deadline-time-regexp item)
  5722. (match-string 1 item)))))))
  5723. (cond
  5724. ((not ds) nil)
  5725. ;; The current item has a deadline date (in ds), so
  5726. ;; evaluate its delay time.
  5727. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5728. ;; Use global delay time.
  5729. (- org-agenda-skip-scheduled-delay-if-deadline))
  5730. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5731. 'post-deadline)
  5732. ;; Set delay to no later than deadline.
  5733. (min (- d2 (org-time-string-to-absolute
  5734. ds d1 'past show-all (current-buffer) pos))
  5735. org-scheduled-delay-days))
  5736. (t 0))))
  5737. (setq ddays (if suppress-delay
  5738. (let ((org-scheduled-delay-days suppress-delay))
  5739. (org-get-wdays s t t))
  5740. (org-get-wdays s t)))
  5741. ;; Use a delay of 0 when there is a repeater and the delay is
  5742. ;; of the form --3d
  5743. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5744. (< (org-time-string-to-absolute s)
  5745. (org-time-string-to-absolute
  5746. s d2 'past nil (current-buffer) pos)))
  5747. (setq ddays 0))
  5748. ;; When to show a scheduled item in the calendar:
  5749. ;; If it is on or past the date.
  5750. (when (or (and (> ddays 0) (= diff (- ddays)))
  5751. (and (zerop ddays) (= diff 0))
  5752. (and (< (+ diff ddays) 0)
  5753. (< (abs diff) org-scheduled-past-days)
  5754. (and todayp (not org-agenda-only-exact-dates)))
  5755. ;; org-is-habit-p uses org-entry-get, which is expansive
  5756. ;; so we go extra mile to only call it once
  5757. (and todayp
  5758. (boundp 'org-habit-show-all-today)
  5759. org-habit-show-all-today
  5760. (setq did-habit-check-p t)
  5761. (setq habitp (and (functionp 'org-is-habit-p)
  5762. (org-is-habit-p)))))
  5763. (save-excursion
  5764. (setq donep (member todo-state org-done-keywords))
  5765. (if (and donep
  5766. (or org-agenda-skip-scheduled-if-done
  5767. (not (= diff 0))
  5768. (and (functionp 'org-is-habit-p)
  5769. (org-is-habit-p))))
  5770. (setq txt nil)
  5771. (setq habitp (if did-habit-check-p habitp
  5772. (and (functionp 'org-is-habit-p)
  5773. (org-is-habit-p))))
  5774. (setq category (org-get-category))
  5775. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5776. 'repeated-after-deadline)
  5777. (org-get-deadline-time (point))
  5778. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5779. (throw :skip nil))
  5780. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5781. (throw :skip nil)
  5782. (goto-char (match-end 0))
  5783. (setq pos1 (match-beginning 0))
  5784. (if habitp
  5785. (if (or (not org-habit-show-habits)
  5786. (and (not todayp)
  5787. (boundp 'org-habit-show-habits-only-for-today)
  5788. org-habit-show-habits-only-for-today))
  5789. (throw :skip nil))
  5790. (if (and
  5791. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5792. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5793. pastschedp))
  5794. (setq mm (assoc pos1 deadline-position-alist)))
  5795. (throw :skip nil)))
  5796. (setq inherited-tags
  5797. (or (eq org-agenda-show-inherited-tags 'always)
  5798. (and (listp org-agenda-show-inherited-tags)
  5799. (memq 'agenda org-agenda-show-inherited-tags))
  5800. (and (eq org-agenda-show-inherited-tags t)
  5801. (or (eq org-agenda-use-tag-inheritance t)
  5802. (memq 'agenda org-agenda-use-tag-inheritance))))
  5803. tags (org-get-tags-at nil (not inherited-tags)))
  5804. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5805. (setq head (buffer-substring
  5806. (point)
  5807. (progn (skip-chars-forward "^\r\n") (point))))
  5808. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5809. (setq timestr
  5810. (concat (substring s (match-beginning 1)) " "))
  5811. (setq timestr 'time))
  5812. (setq txt (org-agenda-format-item
  5813. (if (= diff 0)
  5814. (car org-agenda-scheduled-leaders)
  5815. (format (nth 1 org-agenda-scheduled-leaders)
  5816. (- 1 diff)))
  5817. head level category tags
  5818. (if (not (= diff 0)) nil timestr)
  5819. nil habitp))))
  5820. (when txt
  5821. (setq face
  5822. (cond
  5823. ((and (not habitp) pastschedp)
  5824. 'org-scheduled-previously)
  5825. (todayp 'org-scheduled-today)
  5826. (t 'org-scheduled))
  5827. habitp (and habitp (org-habit-parse-todo)))
  5828. (org-add-props txt props
  5829. 'undone-face face
  5830. 'face (if donep 'org-agenda-done face)
  5831. 'org-marker (org-agenda-new-marker pos)
  5832. 'org-hd-marker (org-agenda-new-marker pos1)
  5833. 'type (if pastschedp "past-scheduled" "scheduled")
  5834. 'date (if pastschedp d2 date)
  5835. 'ts-date d2
  5836. 'warntime warntime
  5837. 'level level
  5838. 'priority (if habitp
  5839. (org-habit-get-priority habitp)
  5840. (+ 94 (- 5 diff) (org-get-priority txt)))
  5841. 'org-habit-p habitp
  5842. 'todo-state todo-state)
  5843. (push txt ee))))))
  5844. (nreverse ee)))
  5845. (defun org-agenda-get-blocks ()
  5846. "Return the date-range information for agenda display."
  5847. (let* ((props (list 'face nil
  5848. 'org-not-done-regexp org-not-done-regexp
  5849. 'org-todo-regexp org-todo-regexp
  5850. 'org-complex-heading-regexp org-complex-heading-regexp
  5851. 'mouse-face 'highlight
  5852. 'help-echo
  5853. (format "mouse-2 or RET jump to org file %s"
  5854. (abbreviate-file-name buffer-file-name))))
  5855. (regexp org-tr-regexp)
  5856. (d0 (calendar-absolute-from-gregorian date))
  5857. marker hdmarker ee txt d1 d2 s1 s2 category
  5858. level todo-state tags pos head donep inherited-tags)
  5859. (goto-char (point-min))
  5860. (while (re-search-forward regexp nil t)
  5861. (catch :skip
  5862. (org-agenda-skip)
  5863. (setq pos (point))
  5864. (let ((start-time (match-string 1))
  5865. (end-time (match-string 2)))
  5866. (setq s1 (match-string 1)
  5867. s2 (match-string 2)
  5868. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5869. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5870. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5871. ;; Only allow days between the limits, because the normal
  5872. ;; date stamps will catch the limits.
  5873. (save-excursion
  5874. (setq todo-state (org-get-todo-state))
  5875. (setq donep (member todo-state org-done-keywords))
  5876. (if (and donep org-agenda-skip-timestamp-if-done)
  5877. (throw :skip t))
  5878. (setq marker (org-agenda-new-marker (point))
  5879. category (org-get-category))
  5880. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5881. (throw :skip nil)
  5882. (goto-char (match-beginning 0))
  5883. (setq hdmarker (org-agenda-new-marker (point))
  5884. inherited-tags
  5885. (or (eq org-agenda-show-inherited-tags 'always)
  5886. (and (listp org-agenda-show-inherited-tags)
  5887. (memq 'agenda org-agenda-show-inherited-tags))
  5888. (and (eq org-agenda-show-inherited-tags t)
  5889. (or (eq org-agenda-use-tag-inheritance t)
  5890. (memq 'agenda org-agenda-use-tag-inheritance))))
  5891. tags (org-get-tags-at nil (not inherited-tags)))
  5892. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5893. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5894. (setq head (match-string 1))
  5895. (let ((remove-re
  5896. (if org-agenda-remove-timeranges-from-blocks
  5897. (concat
  5898. "<" (regexp-quote s1) ".*?>"
  5899. "--"
  5900. "<" (regexp-quote s2) ".*?>")
  5901. nil)))
  5902. (setq txt (org-agenda-format-item
  5903. (format
  5904. (nth (if (= d1 d2) 0 1)
  5905. org-agenda-timerange-leaders)
  5906. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5907. head level category tags
  5908. (cond ((and (= d1 d0) (= d2 d0))
  5909. (concat "<" start-time ">--<" end-time ">"))
  5910. ((= d1 d0)
  5911. (concat "<" start-time ">"))
  5912. ((= d2 d0)
  5913. (concat "<" end-time ">")))
  5914. remove-re))))
  5915. (org-add-props txt props
  5916. 'org-marker marker 'org-hd-marker hdmarker
  5917. 'type "block" 'date date
  5918. 'level level
  5919. 'todo-state todo-state
  5920. 'priority (org-get-priority txt))
  5921. (push txt ee))))
  5922. (goto-char pos)))
  5923. ;; Sort the entries by expiration date.
  5924. (nreverse ee)))
  5925. ;;; Agenda presentation and sorting
  5926. (defvar org-prefix-has-time nil
  5927. "A flag, set by `org-compile-prefix-format'.
  5928. The flag is set if the currently compiled format contains a `%t'.")
  5929. (defvar org-prefix-has-tag nil
  5930. "A flag, set by `org-compile-prefix-format'.
  5931. The flag is set if the currently compiled format contains a `%T'.")
  5932. (defvar org-prefix-has-effort nil
  5933. "A flag, set by `org-compile-prefix-format'.
  5934. The flag is set if the currently compiled format contains a `%e'.")
  5935. (defvar org-prefix-has-breadcrumbs nil
  5936. "A flag, set by `org-compile-prefix-format'.
  5937. The flag is set if the currently compiled format contains a `%b'.")
  5938. (defvar org-prefix-category-length nil
  5939. "Used by `org-compile-prefix-format' to remember the category field width.")
  5940. (defvar org-prefix-category-max-length nil
  5941. "Used by `org-compile-prefix-format' to remember the category field width.")
  5942. (defun org-agenda-get-category-icon (category)
  5943. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5944. (dolist (entry org-agenda-category-icon-alist)
  5945. (when (org-string-match-p (car entry) category)
  5946. (if (listp (cadr entry))
  5947. (return (cadr entry))
  5948. (return (apply 'create-image (cdr entry)))))))
  5949. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5950. remove-re habitp)
  5951. "Format TXT to be inserted into the agenda buffer.
  5952. In particular, add the prefix and corresponding text properties.
  5953. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5954. LEVEL may be a string to replace the `%l' specifier.
  5955. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5956. category taken from local variable or file name. It will replace the `%c'
  5957. specifier in the format.
  5958. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5959. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5960. When DOTIME is a string, this string is searched for a time before TXT is.
  5961. TAGS can be the tags of the headline.
  5962. Any match of REMOVE-RE will be removed from TXT."
  5963. ;; We keep the org-prefix-* variable values along with a compiled
  5964. ;; formatter, so that multiple agendas existing at the same time do
  5965. ;; not step on each other toes.
  5966. ;;
  5967. ;; It was inconvenient to make these variables buffer local in
  5968. ;; Agenda buffers, because this function expects to be called with
  5969. ;; the buffer where item comes from being current, and not agenda
  5970. ;; buffer
  5971. (let* ((bindings (car org-prefix-format-compiled))
  5972. (formatter (cadr org-prefix-format-compiled)))
  5973. (loop for (var value) in bindings
  5974. do (set var value))
  5975. (save-match-data
  5976. ;; Diary entries sometimes have extra whitespace at the beginning
  5977. (setq txt (org-trim txt))
  5978. ;; Fix the tags part in txt
  5979. (setq txt (org-agenda-fix-displayed-tags
  5980. txt tags
  5981. org-agenda-show-inherited-tags
  5982. org-agenda-hide-tags-regexp))
  5983. (let* ((category (or category
  5984. (if buffer-file-name
  5985. (file-name-sans-extension
  5986. (file-name-nondirectory buffer-file-name))
  5987. "")))
  5988. (category-icon (org-agenda-get-category-icon category))
  5989. (category-icon (if category-icon
  5990. (propertize " " 'display category-icon)
  5991. ""))
  5992. (effort (get-text-property 1 'effort txt))
  5993. ;; time, tag, effort are needed for the eval of the prefix format
  5994. (tag (if tags (nth (1- (length tags)) tags) ""))
  5995. time
  5996. (ts (if dotime (concat
  5997. (if (stringp dotime) dotime "")
  5998. (and org-agenda-search-headline-for-time txt))))
  5999. (time-of-day (and dotime (org-get-time-of-day ts)))
  6000. stamp plain s0 s1 s2 rtn srp l
  6001. duration breadcrumbs)
  6002. (and (derived-mode-p 'org-mode) buffer-file-name
  6003. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6004. (when (and dotime time-of-day)
  6005. ;; Extract starting and ending time and move them to prefix
  6006. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6007. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6008. (setq s0 (match-string 0 ts)
  6009. srp (and stamp (match-end 3))
  6010. s1 (match-string (if plain 1 2) ts)
  6011. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6012. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6013. ;; them, we might want to remove them there to avoid duplication.
  6014. ;; The user can turn this off with a variable.
  6015. (if (and org-prefix-has-time
  6016. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6017. (string-match (concat (regexp-quote s0) " *") txt)
  6018. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6019. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6020. (= (match-beginning 0) 0)
  6021. t))
  6022. (setq txt (replace-match "" nil nil txt))))
  6023. ;; Normalize the time(s) to 24 hour
  6024. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6025. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6026. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6027. (let (org-time-clocksum-use-effort-durations)
  6028. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6029. (setq s2
  6030. (org-minutes-to-clocksum-string
  6031. (+ (org-hh:mm-string-to-minutes s1)
  6032. org-agenda-default-appointment-duration)))))
  6033. ;; Compute the duration
  6034. (when s2
  6035. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6036. (org-hh:mm-string-to-minutes s1)))))
  6037. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6038. txt)
  6039. ;; Tags are in the string
  6040. (if (or (eq org-agenda-remove-tags t)
  6041. (and org-agenda-remove-tags
  6042. org-prefix-has-tag))
  6043. (setq txt (replace-match "" t t txt))
  6044. (setq txt (replace-match
  6045. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6046. (match-string 2 txt))
  6047. t t txt))))
  6048. (when remove-re
  6049. (while (string-match remove-re txt)
  6050. (setq txt (replace-match "" t t txt))))
  6051. ;; Set org-heading property on `txt' to mark the start of the
  6052. ;; heading.
  6053. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6054. ;; Prepare the variables needed in the eval of the compiled format
  6055. (if org-prefix-has-breadcrumbs
  6056. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6057. (let ((s (org-display-outline-path nil nil "->" t)))
  6058. (if (eq "" s) "" (concat s "->"))))))
  6059. (setq time (cond (s2 (concat
  6060. (org-agenda-time-of-day-to-ampm-maybe s1)
  6061. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6062. (if org-agenda-timegrid-use-ampm " ")))
  6063. (s1 (concat
  6064. (org-agenda-time-of-day-to-ampm-maybe s1)
  6065. (if org-agenda-timegrid-use-ampm
  6066. "........ "
  6067. "......")))
  6068. (t ""))
  6069. extra (or (and (not habitp) extra) "")
  6070. category (if (symbolp category) (symbol-name category) category)
  6071. level (or level ""))
  6072. (if (string-match org-bracket-link-regexp category)
  6073. (progn
  6074. (setq l (if (match-end 3)
  6075. (- (match-end 3) (match-beginning 3))
  6076. (- (match-end 1) (match-beginning 1))))
  6077. (when (< l (or org-prefix-category-length 0))
  6078. (setq category (copy-sequence category))
  6079. (org-add-props category nil
  6080. 'extra-space (make-string
  6081. (- org-prefix-category-length l 1) ?\ ))))
  6082. (if (and org-prefix-category-max-length
  6083. (>= (length category) org-prefix-category-max-length))
  6084. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6085. ;; Evaluate the compiled format
  6086. (setq rtn (concat (eval formatter) txt))
  6087. ;; And finally add the text properties
  6088. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6089. (org-add-props rtn nil
  6090. 'org-category category
  6091. 'tags (mapcar 'org-downcase-keep-props tags)
  6092. 'org-highest-priority org-highest-priority
  6093. 'org-lowest-priority org-lowest-priority
  6094. 'time-of-day time-of-day
  6095. 'duration duration
  6096. 'breadcrumbs breadcrumbs
  6097. 'txt txt
  6098. 'level level
  6099. 'time time
  6100. 'extra extra
  6101. 'format org-prefix-format-compiled
  6102. 'dotime dotime)))))
  6103. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6104. "Remove tags string from TXT, and add a modified list of tags.
  6105. The modified list may contain inherited tags, and tags matched by
  6106. `org-agenda-hide-tags-regexp' will be removed."
  6107. (when (or add-inherited hide-re)
  6108. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6109. (setq txt (substring txt 0 (match-beginning 0))))
  6110. (setq tags
  6111. (delq nil
  6112. (mapcar (lambda (tg)
  6113. (if (or (and hide-re (string-match hide-re tg))
  6114. (and (not add-inherited)
  6115. (get-text-property 0 'inherited tg)))
  6116. nil
  6117. tg))
  6118. tags)))
  6119. (when tags
  6120. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6121. i)
  6122. (setq txt (concat txt " :"
  6123. (mapconcat
  6124. (lambda (x)
  6125. (setq i (get-text-property 0 'inherited x))
  6126. (if (and have-i (not i))
  6127. (progn
  6128. (setq have-i nil)
  6129. (concat ":" x))
  6130. x))
  6131. tags ":")
  6132. (if have-i "::" ":"))))))
  6133. txt)
  6134. (defun org-downcase-keep-props (s)
  6135. (let ((props (text-properties-at 0 s)))
  6136. (setq s (downcase s))
  6137. (add-text-properties 0 (length s) props s)
  6138. s))
  6139. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6140. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6141. "Add a time-grid for agenda items which need it.
  6142. LIST is the list of agenda items formatted by `org-agenda-list'.
  6143. NDAYS is the span of the current agenda view.
  6144. TODAYP is `t' when the current agenda view is on today."
  6145. (catch 'exit
  6146. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6147. ((and todayp (member 'today (car org-agenda-time-grid))))
  6148. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6149. ((member 'weekly (car org-agenda-time-grid)))
  6150. (t (throw 'exit list)))
  6151. (let* ((have (delq nil (mapcar
  6152. (lambda (x) (get-text-property 1 'time-of-day x))
  6153. list)))
  6154. (string (nth 1 org-agenda-time-grid))
  6155. (gridtimes (nth 2 org-agenda-time-grid))
  6156. (req (car org-agenda-time-grid))
  6157. (remove (member 'remove-match req))
  6158. new time)
  6159. (if (and (member 'require-timed req) (not have))
  6160. ;; don't show empty grid
  6161. (throw 'exit list))
  6162. (while (setq time (pop gridtimes))
  6163. (unless (and remove (member time have))
  6164. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6165. (push (org-agenda-format-item
  6166. nil string nil "" nil
  6167. (concat (substring time 0 -2) ":" (substring time -2)))
  6168. new)
  6169. (put-text-property
  6170. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6171. (when (and todayp org-agenda-show-current-time-in-grid)
  6172. (push (org-agenda-format-item
  6173. nil org-agenda-current-time-string nil "" nil
  6174. (format-time-string "%H:%M "))
  6175. new)
  6176. (put-text-property
  6177. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6178. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6179. (append new list)
  6180. (append list new)))))
  6181. (defun org-compile-prefix-format (key)
  6182. "Compile the prefix format into a Lisp form that can be evaluated.
  6183. The resulting form and associated variable bindings is returned
  6184. and stored in the variable `org-prefix-format-compiled'."
  6185. (setq org-prefix-has-time nil
  6186. org-prefix-has-tag nil
  6187. org-prefix-category-length nil
  6188. org-prefix-has-effort nil
  6189. org-prefix-has-breadcrumbs nil)
  6190. (let ((s (cond
  6191. ((stringp org-agenda-prefix-format)
  6192. org-agenda-prefix-format)
  6193. ((assq key org-agenda-prefix-format)
  6194. (cdr (assq key org-agenda-prefix-format)))
  6195. (t " %-12:c%?-12t% s")))
  6196. (start 0)
  6197. varform vars var e c f opt)
  6198. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6199. s start)
  6200. (setq var (or (cdr (assoc (match-string 4 s)
  6201. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6202. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6203. 'eval)
  6204. c (or (match-string 3 s) "")
  6205. opt (match-beginning 1)
  6206. start (1+ (match-beginning 0)))
  6207. (if (equal var 'time) (setq org-prefix-has-time t))
  6208. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6209. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6210. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6211. (setq f (concat "%" (match-string 2 s) "s"))
  6212. (when (equal var 'category)
  6213. (setq org-prefix-category-length
  6214. (floor (abs (string-to-number (match-string 2 s)))))
  6215. (setq org-prefix-category-max-length
  6216. (let ((x (match-string 2 s)))
  6217. (save-match-data
  6218. (if (string-match "\\.[0-9]+" x)
  6219. (string-to-number (substring (match-string 0 x) 1)))))))
  6220. (if (eq var 'eval)
  6221. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6222. (if opt
  6223. (setq varform
  6224. `(if (or (equal "" ,var) (equal nil ,var))
  6225. ""
  6226. (format ,f (concat ,var ,c))))
  6227. (setq varform
  6228. `(format ,f (if (or (equal ,var "")
  6229. (equal ,var nil)) ""
  6230. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6231. (setq s (replace-match "%s" t nil s))
  6232. (push varform vars))
  6233. (setq vars (nreverse vars))
  6234. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6235. (setq org-prefix-format-compiled
  6236. (list
  6237. `((org-prefix-has-time ,org-prefix-has-time)
  6238. (org-prefix-has-tag ,org-prefix-has-tag)
  6239. (org-prefix-category-length ,org-prefix-category-length)
  6240. (org-prefix-has-effort ,org-prefix-has-effort)
  6241. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6242. `(format ,s ,@vars))))))
  6243. (defun org-set-sorting-strategy (key)
  6244. (if (symbolp (car org-agenda-sorting-strategy))
  6245. ;; the old format
  6246. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6247. (setq org-agenda-sorting-strategy-selected
  6248. (or (cdr (assq key org-agenda-sorting-strategy))
  6249. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6250. '(time-up category-keep priority-down)))))
  6251. (defun org-get-time-of-day (s &optional string mod24)
  6252. "Check string S for a time of day.
  6253. If found, return it as a military time number between 0 and 2400.
  6254. If not found, return nil.
  6255. The optional STRING argument forces conversion into a 5 character wide string
  6256. HH:MM."
  6257. (save-match-data
  6258. (when
  6259. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6260. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6261. (let* ((h (string-to-number (match-string 1 s)))
  6262. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6263. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6264. (am-p (equal ampm "am"))
  6265. (h1 (cond ((not ampm) h)
  6266. ((= h 12) (if am-p 0 12))
  6267. (t (+ h (if am-p 0 12)))))
  6268. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6269. (mod h1 24) h1))
  6270. (t0 (+ (* 100 h2) m))
  6271. (t1 (concat (if (>= h1 24) "+" " ")
  6272. (if (and org-agenda-time-leading-zero
  6273. (< t0 1000)) "0" "")
  6274. (if (< t0 100) "0" "")
  6275. (if (< t0 10) "0" "")
  6276. (int-to-string t0))))
  6277. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6278. (defvar org-agenda-before-sorting-filter-function nil
  6279. "Function to be applied to agenda items prior to sorting.
  6280. Prior to sorting also means just before they are inserted into the agenda.
  6281. To aid sorting, you may revisit the original entries and add more text
  6282. properties which will later be used by the sorting functions.
  6283. The function should take a string argument, an agenda line.
  6284. It has access to the text properties in that line, which contain among
  6285. other things, the property `org-hd-marker' that points to the entry
  6286. where the line comes from. Note that not all lines going into the agenda
  6287. have this property, only most.
  6288. The function should return the modified string. It is probably best
  6289. to ONLY change text properties.
  6290. You can also use this function as a filter, by returning nil for lines
  6291. you don't want to have in the agenda at all. For this application, you
  6292. could bind the variable in the options section of a custom command.")
  6293. (defun org-agenda-finalize-entries (list &optional type)
  6294. "Sort, limit and concatenate the LIST of agenda items.
  6295. The optional argument TYPE tells the agenda type."
  6296. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6297. (cdr (assoc type org-agenda-max-effort)))
  6298. (t org-agenda-max-effort)))
  6299. (max-todo (cond ((listp org-agenda-max-todos)
  6300. (cdr (assoc type org-agenda-max-todos)))
  6301. (t org-agenda-max-todos)))
  6302. (max-tags (cond ((listp org-agenda-max-tags)
  6303. (cdr (assoc type org-agenda-max-tags)))
  6304. (t org-agenda-max-tags)))
  6305. (max-entries (cond ((listp org-agenda-max-entries)
  6306. (cdr (assoc type org-agenda-max-entries)))
  6307. (t org-agenda-max-entries))) l)
  6308. (when org-agenda-before-sorting-filter-function
  6309. (setq list
  6310. (delq nil
  6311. (mapcar
  6312. org-agenda-before-sorting-filter-function list))))
  6313. (setq list (mapcar 'org-agenda-highlight-todo list)
  6314. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6315. (when max-effort
  6316. (setq list (org-agenda-limit-entries
  6317. list 'effort-minutes max-effort 'identity)))
  6318. (when max-todo
  6319. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6320. (when max-tags
  6321. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6322. (when max-entries
  6323. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6324. (mapconcat 'identity list "\n")))
  6325. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6326. "Limit the number of agenda entries."
  6327. (let ((include (and limit (< limit 0))))
  6328. (if limit
  6329. (let ((fun (or fn (lambda (p) (if p 1))))
  6330. (lim 0))
  6331. (delq nil
  6332. (mapcar
  6333. (lambda (e)
  6334. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6335. (if pval (setq lim (+ lim pval)))
  6336. (cond ((and pval (<= lim (abs limit))) e)
  6337. ((and include (not pval)) e))))
  6338. list)))
  6339. list)))
  6340. (defun org-agenda-limit-interactively ()
  6341. "In agenda, interactively limit entries to various maximums."
  6342. (interactive)
  6343. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6344. (num (string-to-number (read-from-minibuffer "How many? "))))
  6345. (cond ((equal max ?e)
  6346. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6347. ((equal max ?t)
  6348. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6349. ((equal max ?T)
  6350. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6351. ((equal max ?E)
  6352. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6353. (org-agenda-fit-window-to-buffer))
  6354. (defun org-agenda-highlight-todo (x)
  6355. (let ((org-done-keywords org-done-keywords-for-agenda)
  6356. (case-fold-search nil)
  6357. re)
  6358. (if (eq x 'line)
  6359. (save-excursion
  6360. (beginning-of-line 1)
  6361. (setq re (org-get-at-bol 'org-todo-regexp))
  6362. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6363. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6364. (add-text-properties (match-beginning 0) (match-end 1)
  6365. (list 'face (org-get-todo-face 1)))
  6366. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6367. (delete-region (match-beginning 1) (1- (match-end 0)))
  6368. (goto-char (match-beginning 1))
  6369. (insert (format org-agenda-todo-keyword-format s)))))
  6370. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6371. (setq re (get-text-property 0 'org-todo-regexp x))
  6372. (when (and re
  6373. ;; Test `pl' because if there's no heading content,
  6374. ;; there's no point matching to highlight. Note
  6375. ;; that if we didn't test `pl' first, and there
  6376. ;; happened to be no keyword from `org-todo-regexp'
  6377. ;; on this heading line, then the `equal' comparison
  6378. ;; afterwards would spuriously succeed in the case
  6379. ;; where `pl' is nil -- causing an args-out-of-range
  6380. ;; error when we try to add text properties to text
  6381. ;; that isn't there.
  6382. pl
  6383. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6384. x pl) pl))
  6385. (add-text-properties
  6386. (or (match-end 1) (match-end 0)) (match-end 0)
  6387. (list 'face (org-get-todo-face (match-string 2 x)))
  6388. x)
  6389. (when (match-end 1)
  6390. (setq x (concat (substring x 0 (match-end 1))
  6391. (format org-agenda-todo-keyword-format
  6392. (match-string 2 x))
  6393. (org-add-props " " (text-properties-at 0 x))
  6394. (substring x (match-end 3)))))))
  6395. x)))
  6396. (defsubst org-cmp-values (a b property)
  6397. "Compare the numeric value of text PROPERTY for string A and B."
  6398. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  6399. (pb (or (get-text-property (1- (length b)) property b) 0)))
  6400. (cond ((> pa pb) +1)
  6401. ((< pa pb) -1))))
  6402. (defsubst org-cmp-effort (a b)
  6403. "Compare the effort values of string A and B."
  6404. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6405. (ea (or (get-text-property (1- (length a)) 'effort-minutes a) def))
  6406. (eb (or (get-text-property (1- (length b)) 'effort-minutes b) def)))
  6407. (cond ((> ea eb) +1)
  6408. ((< ea eb) -1))))
  6409. (defsubst org-cmp-category (a b)
  6410. "Compare the string values of categories of strings A and B."
  6411. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  6412. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  6413. (cond ((string-lessp ca cb) -1)
  6414. ((string-lessp cb ca) +1))))
  6415. (defsubst org-cmp-todo-state (a b)
  6416. "Compare the todo states of strings A and B."
  6417. (let* ((ma (or (get-text-property 1 'org-marker a)
  6418. (get-text-property 1 'org-hd-marker a)))
  6419. (mb (or (get-text-property 1 'org-marker b)
  6420. (get-text-property 1 'org-hd-marker b)))
  6421. (fa (and ma (marker-buffer ma)))
  6422. (fb (and mb (marker-buffer mb)))
  6423. (todo-kwds
  6424. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6425. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6426. (ta (or (get-text-property 1 'todo-state a) ""))
  6427. (tb (or (get-text-property 1 'todo-state b) ""))
  6428. (la (- (length (member ta todo-kwds))))
  6429. (lb (- (length (member tb todo-kwds))))
  6430. (donepa (member ta org-done-keywords-for-agenda))
  6431. (donepb (member tb org-done-keywords-for-agenda)))
  6432. (cond ((and donepa (not donepb)) -1)
  6433. ((and (not donepa) donepb) +1)
  6434. ((< la lb) -1)
  6435. ((< lb la) +1))))
  6436. (defsubst org-cmp-alpha (a b)
  6437. "Compare the headlines, alphabetically."
  6438. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6439. (plb (text-property-any 0 (length b) 'org-heading t b))
  6440. (ta (and pla (substring a pla)))
  6441. (tb (and plb (substring b plb))))
  6442. (when pla
  6443. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6444. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6445. (setq ta (substring ta (match-end 0))))
  6446. (setq ta (downcase ta)))
  6447. (when plb
  6448. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6449. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6450. (setq tb (substring tb (match-end 0))))
  6451. (setq tb (downcase tb)))
  6452. (cond ((not ta) +1)
  6453. ((not tb) -1)
  6454. ((string-lessp ta tb) -1)
  6455. ((string-lessp tb ta) +1))))
  6456. (defsubst org-cmp-tag (a b)
  6457. "Compare the string values of the first tags of A and B."
  6458. (let ((ta (car (last (get-text-property 1 'tags a))))
  6459. (tb (car (last (get-text-property 1 'tags b)))))
  6460. (cond ((not ta) +1)
  6461. ((not tb) -1)
  6462. ((string-lessp ta tb) -1)
  6463. ((string-lessp tb ta) +1))))
  6464. (defsubst org-cmp-time (a b)
  6465. "Compare the time-of-day values of strings A and B."
  6466. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6467. (ta (or (get-text-property 1 'time-of-day a) def))
  6468. (tb (or (get-text-property 1 'time-of-day b) def)))
  6469. (cond ((< ta tb) -1)
  6470. ((< tb ta) +1))))
  6471. (defsubst org-cmp-ts (a b type)
  6472. "Compare the timestamps values of entries A and B.
  6473. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6474. \"timestamp_ia\", compare within each of these type. When TYPE
  6475. is the empty string, compare all timestamps without respect of
  6476. their type."
  6477. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6478. (ta (or (and (string-match type (or (get-text-property 1 type a) ""))
  6479. (get-text-property 1 'ts-date a)) def))
  6480. (tb (or (and (string-match type (or (get-text-property 1 type b) ""))
  6481. (get-text-property 1 'ts-date b)) def)))
  6482. (cond ((< ta tb) -1)
  6483. ((< tb ta) +1))))
  6484. (defsubst org-cmp-habit-p (a b)
  6485. "Compare the todo states of strings A and B."
  6486. (let ((ha (get-text-property 1 'org-habit-p a))
  6487. (hb (get-text-property 1 'org-habit-p b)))
  6488. (cond ((and ha (not hb)) -1)
  6489. ((and (not ha) hb) +1))))
  6490. (defun org-entries-lessp (a b)
  6491. "Predicate for sorting agenda entries."
  6492. ;; The following variables will be used when the form is evaluated.
  6493. ;; So even though the compiler complains, keep them.
  6494. (let* ((ss org-agenda-sorting-strategy-selected)
  6495. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6496. (org-cmp-ts a b "")))
  6497. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6498. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6499. (org-cmp-ts a b "scheduled")))
  6500. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6501. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6502. (org-cmp-ts a b "deadline")))
  6503. (deadline-down (if deadline-up (- deadline-up) nil))
  6504. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6505. (org-cmp-ts a b "iatimestamp_ia")))
  6506. (tsia-down (if tsia-up (- tsia-up) nil))
  6507. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6508. (org-cmp-ts a b "timestamp")))
  6509. (ts-down (if ts-up (- ts-up) nil))
  6510. (time-up (and (org-em 'time-up 'time-down ss)
  6511. (org-cmp-time a b)))
  6512. (time-down (if time-up (- time-up) nil))
  6513. (stats-up (and (org-em 'stats-up 'stats-down ss)
  6514. (org-cmp-values a b 'org-stats)))
  6515. (stats-down (if stats-up (- stats-up) nil))
  6516. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6517. (org-cmp-values a b 'priority)))
  6518. (priority-down (if priority-up (- priority-up) nil))
  6519. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6520. (org-cmp-effort a b)))
  6521. (effort-down (if effort-up (- effort-up) nil))
  6522. (category-up (and (or (org-em 'category-up 'category-down ss)
  6523. (memq 'category-keep ss))
  6524. (org-cmp-category a b)))
  6525. (category-down (if category-up (- category-up) nil))
  6526. (category-keep (if category-up +1 nil))
  6527. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6528. (org-cmp-tag a b)))
  6529. (tag-down (if tag-up (- tag-up) nil))
  6530. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6531. (org-cmp-todo-state a b)))
  6532. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6533. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6534. (org-cmp-habit-p a b)))
  6535. (habit-down (if habit-up (- habit-up) nil))
  6536. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6537. (org-cmp-alpha a b)))
  6538. (alpha-down (if alpha-up (- alpha-up) nil))
  6539. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6540. user-defined-up user-defined-down)
  6541. (if (and need-user-cmp org-agenda-cmp-user-defined
  6542. (functionp org-agenda-cmp-user-defined))
  6543. (setq user-defined-up
  6544. (funcall org-agenda-cmp-user-defined a b)
  6545. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6546. (cdr (assoc
  6547. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6548. '((-1 . t) (1 . nil) (nil . nil))))))
  6549. ;;; Agenda restriction lock
  6550. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6551. "Overlay to mark the headline to which agenda commands are restricted.")
  6552. (overlay-put org-agenda-restriction-lock-overlay
  6553. 'face 'org-agenda-restriction-lock)
  6554. (overlay-put org-agenda-restriction-lock-overlay
  6555. 'help-echo "Agendas are currently limited to this subtree.")
  6556. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6557. ;;;###autoload
  6558. (defun org-agenda-set-restriction-lock (&optional type)
  6559. "Set restriction lock for agenda, to current subtree or file.
  6560. Restriction will be the file if TYPE is `file', or if type is the
  6561. universal prefix '(4), or if the cursor is before the first headline
  6562. in the file. Otherwise, restriction will be to the current subtree."
  6563. (interactive "P")
  6564. (org-agenda-remove-restriction-lock 'noupdate)
  6565. (and (equal type '(4)) (setq type 'file))
  6566. (setq type (cond
  6567. (type type)
  6568. ((org-at-heading-p) 'subtree)
  6569. ((condition-case nil (org-back-to-heading t) (error nil))
  6570. 'subtree)
  6571. (t 'file)))
  6572. (if (eq type 'subtree)
  6573. (progn
  6574. (setq org-agenda-restrict (current-buffer))
  6575. (setq org-agenda-overriding-restriction 'subtree)
  6576. (put 'org-agenda-files 'org-restrict
  6577. (list (buffer-file-name (buffer-base-buffer))))
  6578. (org-back-to-heading t)
  6579. (move-overlay org-agenda-restriction-lock-overlay
  6580. (point)
  6581. (if org-agenda-restriction-lock-highlight-subtree
  6582. (save-excursion (org-end-of-subtree t t) (point))
  6583. (point-at-eol)))
  6584. (move-marker org-agenda-restrict-begin (point))
  6585. (move-marker org-agenda-restrict-end
  6586. (save-excursion (org-end-of-subtree t t)))
  6587. (message "Locking agenda restriction to subtree"))
  6588. (put 'org-agenda-files 'org-restrict
  6589. (list (buffer-file-name (buffer-base-buffer))))
  6590. (setq org-agenda-restrict nil)
  6591. (setq org-agenda-overriding-restriction 'file)
  6592. (move-marker org-agenda-restrict-begin nil)
  6593. (move-marker org-agenda-restrict-end nil)
  6594. (message "Locking agenda restriction to file"))
  6595. (setq current-prefix-arg nil)
  6596. (org-agenda-maybe-redo))
  6597. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6598. "Remove the agenda restriction lock."
  6599. (interactive "P")
  6600. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6601. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6602. (setq org-agenda-overriding-restriction nil)
  6603. (setq org-agenda-restrict nil)
  6604. (put 'org-agenda-files 'org-restrict nil)
  6605. (move-marker org-agenda-restrict-begin nil)
  6606. (move-marker org-agenda-restrict-end nil)
  6607. (setq current-prefix-arg nil)
  6608. (message "Agenda restriction lock removed")
  6609. (or noupdate (org-agenda-maybe-redo)))
  6610. (defun org-agenda-maybe-redo ()
  6611. "If there is any window showing the agenda view, update it."
  6612. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6613. (w0 (selected-window)))
  6614. (when w
  6615. (select-window w)
  6616. (org-agenda-redo)
  6617. (select-window w0)
  6618. (if org-agenda-overriding-restriction
  6619. (message "Agenda view shifted to new %s restriction"
  6620. org-agenda-overriding-restriction)
  6621. (message "Agenda restriction lock removed")))))
  6622. ;;; Agenda commands
  6623. (defun org-agenda-check-type (error &rest types)
  6624. "Check if agenda buffer is of allowed type.
  6625. If ERROR is non-nil, throw an error, otherwise just return nil.
  6626. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6627. (if (not org-agenda-type)
  6628. (error "No Org agenda currently displayed")
  6629. (if (memq org-agenda-type types)
  6630. t
  6631. (if error
  6632. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6633. nil))))
  6634. (defun org-agenda-Quit ()
  6635. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6636. Also restore the window configuration."
  6637. (interactive)
  6638. (if org-agenda-columns-active
  6639. (org-columns-quit)
  6640. (let ((buf (current-buffer)))
  6641. (if (eq org-agenda-window-setup 'other-frame)
  6642. (progn
  6643. (org-agenda-reset-markers)
  6644. (kill-buffer buf)
  6645. (org-columns-remove-overlays)
  6646. (setq org-agenda-archives-mode nil)
  6647. (delete-frame))
  6648. (and (not (eq org-agenda-window-setup 'current-window))
  6649. (not (one-window-p))
  6650. (delete-window))
  6651. (org-agenda-reset-markers)
  6652. (kill-buffer buf)
  6653. (org-columns-remove-overlays)
  6654. (setq org-agenda-archives-mode nil)))
  6655. (setq org-agenda-buffer nil)
  6656. ;; Maybe restore the pre-agenda window configuration.
  6657. (and org-agenda-restore-windows-after-quit
  6658. (not (eq org-agenda-window-setup 'other-frame))
  6659. org-agenda-pre-window-conf
  6660. (set-window-configuration org-agenda-pre-window-conf)
  6661. (setq org-agenda-pre-window-conf nil))))
  6662. (defun org-agenda-quit ()
  6663. "Exit the agenda and restore the window configuration.
  6664. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6665. (interactive)
  6666. (if (and (eq org-indirect-buffer-display 'other-window)
  6667. org-last-indirect-buffer)
  6668. (let ((org-last-indirect-window
  6669. (get-buffer-window org-last-indirect-buffer)))
  6670. (if org-last-indirect-window
  6671. (delete-window org-last-indirect-window))))
  6672. (if org-agenda-columns-active
  6673. (org-columns-quit)
  6674. (if org-agenda-sticky
  6675. (let ((buf (current-buffer)))
  6676. (if (eq org-agenda-window-setup 'other-frame)
  6677. (progn
  6678. (delete-frame))
  6679. (and (not (eq org-agenda-window-setup 'current-window))
  6680. (not (one-window-p))
  6681. (delete-window)))
  6682. (with-current-buffer buf
  6683. (bury-buffer)
  6684. ;; Maybe restore the pre-agenda window configuration.
  6685. (and org-agenda-restore-windows-after-quit
  6686. (not (eq org-agenda-window-setup 'other-frame))
  6687. org-agenda-pre-window-conf
  6688. (set-window-configuration org-agenda-pre-window-conf)
  6689. (setq org-agenda-pre-window-conf nil))))
  6690. (org-agenda-Quit))))
  6691. (defun org-agenda-exit ()
  6692. "Exit the agenda and restore the window configuration.
  6693. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6694. buffers visited directly by the user will not be touched."
  6695. (interactive)
  6696. (org-release-buffers org-agenda-new-buffers)
  6697. (setq org-agenda-new-buffers nil)
  6698. (org-agenda-Quit))
  6699. (defun org-agenda-kill-all-agenda-buffers ()
  6700. "Kill all buffers in `org-agenda-mode'.
  6701. This is used when toggling sticky agendas.
  6702. You can also explicitly invoke it with `C-c a C-k'."
  6703. (interactive)
  6704. (let (blist)
  6705. (dolist (buf (buffer-list))
  6706. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6707. (push buf blist)))
  6708. (mapc 'kill-buffer blist)))
  6709. (defun org-agenda-execute (arg)
  6710. "Execute another agenda command, keeping same window.
  6711. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6712. in the agenda."
  6713. (interactive "P")
  6714. (let ((org-agenda-window-setup 'current-window))
  6715. (org-agenda arg)))
  6716. (defun org-agenda-redo (&optional all)
  6717. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6718. (interactive "P")
  6719. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6720. (cpa (unless (eq all t) current-prefix-arg))
  6721. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6722. (org-agenda-sticky nil)
  6723. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6724. org-agenda-buffer-name))
  6725. (org-agenda-keep-modes t)
  6726. (tag-filter org-agenda-tag-filter)
  6727. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6728. (top-hl-filter org-agenda-top-headline-filter)
  6729. (cat-filter org-agenda-category-filter)
  6730. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6731. (re-filter org-agenda-regexp-filter)
  6732. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6733. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6734. (cols org-agenda-columns-active)
  6735. (line (org-current-line))
  6736. (window-line (- line (org-current-line (window-start))))
  6737. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6738. (redo-cmd (get-text-property p 'org-redo-cmd))
  6739. (last-args (get-text-property p 'org-last-args))
  6740. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6741. (org-agenda-overriding-cmd-arguments
  6742. (unless (eq all t)
  6743. (cond ((listp last-args)
  6744. (cons (or cpa (car last-args)) (cdr last-args)))
  6745. ((stringp last-args)
  6746. last-args))))
  6747. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6748. (put 'org-agenda-tag-filter :preset-filter nil)
  6749. (put 'org-agenda-category-filter :preset-filter nil)
  6750. (put 'org-agenda-regexp-filter :preset-filter nil)
  6751. (and cols (org-columns-quit))
  6752. (message "Rebuilding agenda buffer...")
  6753. (if series-redo-cmd
  6754. (eval series-redo-cmd)
  6755. (org-let lprops redo-cmd))
  6756. (setq org-agenda-undo-list nil
  6757. org-agenda-pending-undo-list nil
  6758. org-agenda-tag-filter tag-filter
  6759. org-agenda-category-filter cat-filter
  6760. org-agenda-regexp-filter re-filter
  6761. org-agenda-top-headline-filter top-hl-filter)
  6762. (message "Rebuilding agenda buffer...done")
  6763. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6764. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6765. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6766. (let ((tag (or tag-filter tag-preset))
  6767. (cat (or cat-filter cat-preset))
  6768. (re (or re-filter re-preset)))
  6769. (when tag (org-agenda-filter-apply tag 'tag))
  6770. (when cat (org-agenda-filter-apply cat 'category))
  6771. (when re (org-agenda-filter-apply re 'regexp)))
  6772. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6773. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6774. (org-goto-line line)
  6775. (recenter window-line)))
  6776. (defvar org-global-tags-completion-table nil)
  6777. (defvar org-agenda-filter-form nil)
  6778. (defvar org-agenda-filtered-by-category nil)
  6779. (defun org-agenda-filter-by-category (strip)
  6780. "Keep only those lines in the agenda buffer that have a specific category.
  6781. The category is that of the current line."
  6782. (interactive "P")
  6783. (if (and org-agenda-filtered-by-category
  6784. org-agenda-category-filter)
  6785. (org-agenda-filter-show-all-cat)
  6786. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  6787. (cond
  6788. ((and cat strip)
  6789. (org-agenda-filter-apply
  6790. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6791. ((and cat)
  6792. (org-agenda-filter-apply
  6793. (setq org-agenda-category-filter
  6794. (list (concat "+" cat))) 'category))
  6795. (t (error "No category at point"))))))
  6796. (defun org-find-top-headline (&optional pos)
  6797. "Find the topmost parent headline and return it."
  6798. (save-excursion
  6799. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6800. (if pos (goto-char pos))
  6801. ;; Skip up to the topmost parent
  6802. (while (ignore-errors (outline-up-heading 1) t))
  6803. (ignore-errors
  6804. (nth 4 (org-heading-components))))))
  6805. (defvar org-agenda-filtered-by-top-headline nil)
  6806. (defun org-agenda-filter-by-top-headline (strip)
  6807. "Keep only those lines that are descendants from the same top headline.
  6808. The top headline is that of the current line."
  6809. (interactive "P")
  6810. (if org-agenda-filtered-by-top-headline
  6811. (progn
  6812. (setq org-agenda-filtered-by-top-headline nil
  6813. org-agenda-top-headline-filter nil)
  6814. (org-agenda-filter-show-all-top-filter))
  6815. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6816. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6817. (error "No top-level headline at point")))))
  6818. (defvar org-agenda-regexp-filter nil)
  6819. (defun org-agenda-filter-by-regexp (strip)
  6820. "Filter agenda entries by a regular expression.
  6821. Regexp filters are cumulative.
  6822. With no prefix argument, keep entries matching the regexp.
  6823. With one prefix argument, filter out entries matching the regexp.
  6824. With two prefix arguments, remove the regexp filters."
  6825. (interactive "P")
  6826. (if (not (equal strip '(16)))
  6827. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6828. (read-from-minibuffer
  6829. (if (equal strip '(4))
  6830. "Filter out entries matching regexp: "
  6831. "Narrow to entries matching regexp: ")))))
  6832. (push flt org-agenda-regexp-filter)
  6833. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6834. (org-agenda-filter-show-all-re)
  6835. (message "Regexp filter removed")))
  6836. (defun org-agenda-filter-remove-all ()
  6837. "Remove all filters from the current agenda buffer."
  6838. (interactive)
  6839. (when org-agenda-tag-filter
  6840. (org-agenda-filter-show-all-tag))
  6841. (when org-agenda-category-filter
  6842. (org-agenda-filter-show-all-cat))
  6843. (when org-agenda-regexp-filter
  6844. (org-agenda-filter-show-all-re))
  6845. (when org-agenda-top-headline-filter
  6846. (org-agenda-filter-show-all-top-filter))
  6847. (org-agenda-finalize))
  6848. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6849. "Keep only those lines in the agenda buffer that have a specific tag.
  6850. The tag is selected with its fast selection letter, as configured.
  6851. With prefix argument STRIP, remove all lines that do have the tag.
  6852. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6853. used to narrow the search - the interactive user can also press `-' or `+'
  6854. to switch to narrowing."
  6855. (interactive "P")
  6856. (let* ((alist org-tag-alist-for-agenda)
  6857. (tag-chars (mapconcat
  6858. (lambda (x) (if (and (not (symbolp (car x)))
  6859. (cdr x))
  6860. (char-to-string (cdr x))
  6861. ""))
  6862. alist ""))
  6863. (efforts (org-split-string
  6864. (or (cdr (assoc (concat org-effort-property "_ALL")
  6865. org-global-properties))
  6866. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6867. "")))
  6868. (effort-op org-agenda-filter-effort-default-operator)
  6869. (effort-prompt "")
  6870. (inhibit-read-only t)
  6871. (current org-agenda-tag-filter)
  6872. maybe-refresh a n tag)
  6873. (unless char
  6874. (message
  6875. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6876. (if narrow "Narrow" "Filter") tag-chars
  6877. (if org-agenda-auto-exclude-function "[RET], " ""))
  6878. (setq char (read-char-exclusive)))
  6879. (when (member char '(?+ ?-))
  6880. ;; Narrowing down
  6881. (cond ((equal char ?-) (setq strip t narrow t))
  6882. ((equal char ?+) (setq strip nil narrow t)))
  6883. (message
  6884. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6885. (setq char (read-char-exclusive)))
  6886. (when (member char '(?< ?> ?= ??))
  6887. ;; An effort operator
  6888. (setq effort-op (char-to-string char))
  6889. (setq alist nil) ; to make sure it will be interpreted as effort.
  6890. (unless (equal char ??)
  6891. (loop for i from 0 to 9 do
  6892. (setq effort-prompt
  6893. (concat
  6894. effort-prompt " ["
  6895. (if (= i 9) "0" (int-to-string (1+ i)))
  6896. "]" (nth i efforts))))
  6897. (message "Effort%s: %s " effort-op effort-prompt)
  6898. (setq char (read-char-exclusive))
  6899. (when (or (< char ?0) (> char ?9))
  6900. (error "Need 1-9,0 to select effort"))))
  6901. (when (equal char ?\t)
  6902. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6903. (org-set-local 'org-global-tags-completion-table
  6904. (org-global-tags-completion-table)))
  6905. (let ((completion-ignore-case t))
  6906. (setq tag (org-icompleting-read
  6907. "Tag: " org-global-tags-completion-table))))
  6908. (cond
  6909. ((equal char ?\r)
  6910. (org-agenda-filter-show-all-tag)
  6911. (when org-agenda-auto-exclude-function
  6912. (setq org-agenda-tag-filter nil)
  6913. (dolist (tag (org-agenda-get-represented-tags))
  6914. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6915. (if modifier
  6916. (push modifier org-agenda-tag-filter))))
  6917. (if (not (null org-agenda-tag-filter))
  6918. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6919. (setq maybe-refresh t))
  6920. ((equal char ?/)
  6921. (org-agenda-filter-show-all-tag)
  6922. (when (get 'org-agenda-tag-filter :preset-filter)
  6923. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6924. (setq maybe-refresh t))
  6925. ((equal char ?. )
  6926. (setq org-agenda-tag-filter
  6927. (mapcar (lambda(tag) (concat "+" tag))
  6928. (org-get-at-bol 'tags)))
  6929. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6930. (setq maybe-refresh t))
  6931. ((or (equal char ?\ )
  6932. (setq a (rassoc char alist))
  6933. (and (>= char ?0) (<= char ?9)
  6934. (setq n (if (= char ?0) 9 (- char ?0 1))
  6935. tag (concat effort-op (nth n efforts))
  6936. a (cons tag nil)))
  6937. (and (= char ??)
  6938. (setq tag "?eff")
  6939. a (cons tag nil))
  6940. (and tag (setq a (cons tag nil))))
  6941. (org-agenda-filter-show-all-tag)
  6942. (setq tag (car a))
  6943. (setq org-agenda-tag-filter
  6944. (cons (concat (if strip "-" "+") tag)
  6945. (if narrow current nil)))
  6946. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6947. (setq maybe-refresh t))
  6948. (t (error "Invalid tag selection character %c" char)))
  6949. (when (and maybe-refresh
  6950. (eq org-agenda-clockreport-mode 'with-filter))
  6951. (org-agenda-redo))))
  6952. (defun org-agenda-get-represented-tags ()
  6953. "Get a list of all tags currently represented in the agenda."
  6954. (let (p tags)
  6955. (save-excursion
  6956. (goto-char (point-min))
  6957. (while (setq p (next-single-property-change (point) 'tags))
  6958. (goto-char p)
  6959. (mapc (lambda (x) (add-to-list 'tags x))
  6960. (get-text-property (point) 'tags))))
  6961. tags))
  6962. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6963. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6964. (interactive "P")
  6965. (org-agenda-filter-by-tag strip char 'refine))
  6966. (defun org-agenda-filter-make-matcher (filter type)
  6967. "Create the form that tests a line for agenda filter."
  6968. (let (f f1)
  6969. (cond
  6970. ;; Tag filter
  6971. ((eq type 'tag)
  6972. (setq filter
  6973. (delete-dups
  6974. (append (get 'org-agenda-tag-filter :preset-filter)
  6975. filter)))
  6976. (dolist (x filter)
  6977. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  6978. (ffunc
  6979. (lambda (nf0 nf01 fltr notgroup op)
  6980. (dolist (x fltr)
  6981. (if (member x '("-" "+"))
  6982. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  6983. (if (string-match "[<=>?]" x)
  6984. (setq nf01 (org-agenda-filter-effort-form x))
  6985. (setq nf01 (list 'member (downcase (substring x 1))
  6986. 'tags)))
  6987. (when (equal (string-to-char x) ?-)
  6988. (setq nf01 (list 'not nf01))
  6989. (when (not notgroup) (setq op 'and))))
  6990. (push nf01 nf0))
  6991. (if notgroup
  6992. (push (cons 'and nf0) f)
  6993. (push (cons (or op 'or) nf0) f)))))
  6994. (cond ((equal filter '("+"))
  6995. (setq f (list (list 'not 'tags))))
  6996. ((equal nfilter filter)
  6997. (funcall ffunc f1 f filter t nil))
  6998. (t (funcall ffunc nf1 nf nfilter nil nil))))))
  6999. ;; Category filter
  7000. ((eq type 'category)
  7001. (setq filter
  7002. (delete-dups
  7003. (append (get 'org-agenda-category-filter :preset-filter)
  7004. filter)))
  7005. (dolist (x filter)
  7006. (if (equal "-" (substring x 0 1))
  7007. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7008. (setq f1 (list 'equal (substring x 1) 'cat)))
  7009. (push f1 f)))
  7010. ;; Regexp filter
  7011. ((eq type 'regexp)
  7012. (setq filter
  7013. (delete-dups
  7014. (append (get 'org-agenda-regexp-filter :preset-filter)
  7015. filter)))
  7016. (dolist (x filter)
  7017. (if (equal "-" (substring x 0 1))
  7018. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7019. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7020. (push f1 f))))
  7021. (cons 'and (nreverse f))))
  7022. (defun org-agenda-filter-effort-form (e)
  7023. "Return the form to compare the effort of the current line with what E says.
  7024. E looks like \"+<2:25\"."
  7025. (let (op)
  7026. (setq e (substring e 1))
  7027. (setq op (string-to-char e) e (substring e 1))
  7028. (setq op (cond ((equal op ?<) '<=)
  7029. ((equal op ?>) '>=)
  7030. ((equal op ??) op)
  7031. (t '=)))
  7032. (list 'org-agenda-compare-effort (list 'quote op)
  7033. (org-duration-string-to-minutes e))))
  7034. (defun org-agenda-compare-effort (op value)
  7035. "Compare the effort of the current line with VALUE, using OP.
  7036. If the line does not have an effort defined, return nil."
  7037. (let ((eff (org-get-at-eol 'effort-minutes 1)))
  7038. (if (equal op ??)
  7039. (not eff)
  7040. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7041. value))))
  7042. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7043. "Expand group tags in FILTER for the agenda.
  7044. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7045. (if org-group-tags
  7046. (let ((case-fold-search t) rtn)
  7047. (mapc
  7048. (lambda (f)
  7049. (let (f0 dir)
  7050. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7051. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7052. (setq dir (if no-operator "" "+") f0 f))
  7053. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7054. (org-tags-expand f0 t t))
  7055. rtn))))
  7056. filter)
  7057. (reverse rtn))
  7058. filter))
  7059. (defun org-agenda-filter-apply (filter type)
  7060. "Set FILTER as the new agenda filter and apply it."
  7061. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7062. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7063. (let (tags cat txt)
  7064. (setq org-agenda-filter-form
  7065. (org-agenda-filter-make-matcher filter type))
  7066. (if (and (eq type 'category)
  7067. (not (equal (substring (car filter) 0 1) "-")))
  7068. ;; Only set `org-agenda-filtered-by-category' to t
  7069. ;; when a unique category is used as the filter
  7070. (setq org-agenda-filtered-by-category t))
  7071. (org-agenda-set-mode-name)
  7072. (save-excursion
  7073. (goto-char (point-min))
  7074. (while (not (eobp))
  7075. (if (org-get-at-bol 'org-marker)
  7076. (progn
  7077. (setq tags ; used in eval
  7078. (apply 'append
  7079. (mapcar (lambda (f)
  7080. (org-agenda-filter-expand-tags (list f) t))
  7081. (org-get-at-bol 'tags)))
  7082. cat (org-get-at-eol 'org-category 1)
  7083. txt (get-text-property (point) 'txt))
  7084. (if (not (eval org-agenda-filter-form))
  7085. (org-agenda-filter-hide-line type))
  7086. (beginning-of-line 2))
  7087. (beginning-of-line 2))))
  7088. (if (get-char-property (point) 'invisible)
  7089. (ignore-errors (org-agenda-previous-line)))))
  7090. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7091. "Filter by top headline HL."
  7092. (org-agenda-set-mode-name)
  7093. (save-excursion
  7094. (goto-char (point-min))
  7095. (while (not (eobp))
  7096. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7097. (tophl (and pos (org-find-top-headline pos))))
  7098. (if (and tophl (funcall (if negative 'identity 'not)
  7099. (string= hl tophl)))
  7100. (org-agenda-filter-hide-line 'top-headline)))
  7101. (beginning-of-line 2)))
  7102. (if (get-char-property (point) 'invisible)
  7103. (org-agenda-previous-line))
  7104. (setq org-agenda-top-headline-filter hl
  7105. org-agenda-filtered-by-top-headline t))
  7106. (defun org-agenda-filter-hide-line (type)
  7107. "Hide lines with TYPE in the agenda buffer."
  7108. (let* ((b (max (point-min) (1- (point-at-bol))))
  7109. (e (point-at-eol)))
  7110. (let ((inhibit-read-only t))
  7111. (add-text-properties
  7112. b e `(invisible t org-filtered t org-filter-type ,type)))))
  7113. (defun org-agenda-remove-filter (type)
  7114. (interactive)
  7115. "Remove filter of type TYPE from the agenda buffer."
  7116. (save-excursion
  7117. (goto-char (point-min))
  7118. (let ((inhibit-read-only t) pos)
  7119. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7120. (goto-char pos)
  7121. (remove-text-properties
  7122. (point) (next-single-property-change (point) 'org-filter-type)
  7123. `(invisible t org-filter-type ,type))))
  7124. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7125. (setq org-agenda-filter-form nil)
  7126. (org-agenda-set-mode-name)
  7127. (org-agenda-finalize)))
  7128. (defun org-agenda-filter-show-all-tag nil
  7129. (org-agenda-remove-filter 'tag))
  7130. (defun org-agenda-filter-show-all-re nil
  7131. (org-agenda-remove-filter 'regexp))
  7132. (defun org-agenda-filter-show-all-cat nil
  7133. (org-agenda-remove-filter 'category))
  7134. (defun org-agenda-filter-show-all-top-filter nil
  7135. (org-agenda-remove-filter 'top-headline))
  7136. (defun org-agenda-manipulate-query-add ()
  7137. "Manipulate the query by adding a search term with positive selection.
  7138. Positive selection means the term must be matched for selection of an entry."
  7139. (interactive)
  7140. (org-agenda-manipulate-query ?\[))
  7141. (defun org-agenda-manipulate-query-subtract ()
  7142. "Manipulate the query by adding a search term with negative selection.
  7143. Negative selection means term must not be matched for selection of an entry."
  7144. (interactive)
  7145. (org-agenda-manipulate-query ?\]))
  7146. (defun org-agenda-manipulate-query-add-re ()
  7147. "Manipulate the query by adding a search regexp with positive selection.
  7148. Positive selection means the regexp must match for selection of an entry."
  7149. (interactive)
  7150. (org-agenda-manipulate-query ?\{))
  7151. (defun org-agenda-manipulate-query-subtract-re ()
  7152. "Manipulate the query by adding a search regexp with negative selection.
  7153. Negative selection means regexp must not match for selection of an entry."
  7154. (interactive)
  7155. (org-agenda-manipulate-query ?\}))
  7156. (defun org-agenda-manipulate-query (char)
  7157. (cond
  7158. ((memq org-agenda-type '(timeline agenda))
  7159. (let ((org-agenda-include-inactive-timestamps t))
  7160. (org-agenda-redo))
  7161. (message "Display now includes inactive timestamps as well"))
  7162. ((eq org-agenda-type 'search)
  7163. (org-add-to-string
  7164. 'org-agenda-query-string
  7165. (if org-agenda-last-search-view-search-was-boolean
  7166. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7167. (?\{ . " +{}") (?\} . " -{}"))))
  7168. " "))
  7169. (setq org-agenda-redo-command
  7170. (list 'org-search-view
  7171. (car (get-text-property (min (1- (point-max)) (point))
  7172. 'org-last-args))
  7173. org-agenda-query-string
  7174. (+ (length org-agenda-query-string)
  7175. (if (member char '(?\{ ?\})) 0 1))))
  7176. (set-register org-agenda-query-register org-agenda-query-string)
  7177. (let ((org-agenda-overriding-arguments
  7178. (cdr org-agenda-redo-command)))
  7179. (org-agenda-redo)))
  7180. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7181. org-agenda-type))))
  7182. (defun org-add-to-string (var string)
  7183. (set var (concat (symbol-value var) string)))
  7184. (defun org-agenda-goto-date (span)
  7185. "Jump to DATE in agenda."
  7186. (interactive "P")
  7187. (let* ((org-read-date-prefer-future
  7188. (eval org-agenda-jump-prefer-future))
  7189. (date (org-read-date))
  7190. (day (time-to-days (org-time-string-to-time date)))
  7191. (org-agenda-sticky-orig org-agenda-sticky)
  7192. (org-agenda-buffer-tmp-name (buffer-name))
  7193. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7194. (0-arg (or current-prefix-arg (car args)))
  7195. (2-arg (nth 2 args))
  7196. (with-hour-p (nth 4 org-agenda-redo-command))
  7197. (newcmd (list 'org-agenda-list 0-arg date
  7198. (org-agenda-span-to-ndays
  7199. 2-arg (org-time-string-to-absolute date))
  7200. with-hour-p))
  7201. (newargs (cdr newcmd))
  7202. (inhibit-read-only t)
  7203. org-agenda-sticky)
  7204. (if (not (org-agenda-check-type t 'agenda))
  7205. (error "Not available in non-agenda views")
  7206. (add-text-properties (point-min) (point-max)
  7207. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7208. (org-agenda-redo)
  7209. (goto-char (point-min))
  7210. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7211. (save-excursion (move-beginning-of-line 2) (eobp))))
  7212. (move-beginning-of-line 2))
  7213. (setq org-agenda-sticky org-agenda-sticky-orig
  7214. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7215. (defun org-agenda-goto-today ()
  7216. "Go to today."
  7217. (interactive)
  7218. (org-agenda-check-type t 'timeline 'agenda)
  7219. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7220. (curspan (nth 2 args))
  7221. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7222. (cond
  7223. (tdpos (goto-char tdpos))
  7224. ((eq org-agenda-type 'agenda)
  7225. (let* ((sd (org-agenda-compute-starting-span
  7226. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7227. (org-agenda-overriding-arguments args))
  7228. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7229. (org-agenda-redo)
  7230. (org-agenda-find-same-or-today-or-agenda)))
  7231. (t (error "Cannot find today")))))
  7232. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7233. (goto-char
  7234. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7235. (text-property-any (point-min) (point-max) 'org-today t)
  7236. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7237. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7238. (org-agenda-backward-block))
  7239. (point-min))))
  7240. (defun org-agenda-backward-block ()
  7241. "Move backward by one agenda block."
  7242. (interactive)
  7243. (org-agenda-forward-block 'backward))
  7244. (defun org-agenda-forward-block (&optional backward)
  7245. "Move forward by one agenda block.
  7246. When optional argument BACKWARD is set, go backward"
  7247. (interactive)
  7248. (cond ((not (derived-mode-p 'org-agenda-mode))
  7249. (user-error
  7250. "Cannot execute this command outside of org-agenda-mode buffers"))
  7251. ((looking-at (if backward "\\`" "\\'"))
  7252. (message "Already at the %s block" (if backward "first" "last")))
  7253. (t (let ((pos (prog1 (point)
  7254. (ignore-errors (if backward (backward-char 1)
  7255. (move-end-of-line 1)))))
  7256. (f (if backward
  7257. 'previous-single-property-change
  7258. 'next-single-property-change))
  7259. moved dest)
  7260. (while (and (setq dest (funcall
  7261. f (point) 'org-agenda-structural-header))
  7262. (not (get-text-property
  7263. (point) 'org-agenda-structural-header)))
  7264. (setq moved t)
  7265. (goto-char dest))
  7266. (if moved (move-beginning-of-line 1)
  7267. (goto-char (if backward (point-min) (point-max)))
  7268. (move-beginning-of-line 1)
  7269. (message "No %s block" (if backward "previous" "further")))))))
  7270. (defun org-agenda-later (arg)
  7271. "Go forward in time by the current span.
  7272. With prefix ARG, go forward that many times the current span."
  7273. (interactive "p")
  7274. (org-agenda-check-type t 'agenda)
  7275. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7276. (span (or (nth 2 args) org-agenda-current-span))
  7277. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7278. (greg (calendar-gregorian-from-absolute sd))
  7279. (cnt (org-get-at-bol 'org-day-cnt))
  7280. greg2)
  7281. (cond
  7282. ((numberp span)
  7283. (setq sd (+ (* span arg) sd)))
  7284. ((eq span 'day)
  7285. (setq sd (+ arg sd)))
  7286. ((eq span 'week)
  7287. (setq sd (+ (* 7 arg) sd)))
  7288. ((eq span 'fortnight)
  7289. (setq sd (+ (* 14 arg) sd)))
  7290. ((eq span 'month)
  7291. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7292. sd (calendar-absolute-from-gregorian greg2))
  7293. (setcar greg2 (1+ (car greg2))))
  7294. ((eq span 'year)
  7295. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7296. sd (calendar-absolute-from-gregorian greg2))
  7297. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7298. (t
  7299. (setq sd (+ (* span arg) sd))))
  7300. (let ((org-agenda-overriding-cmd
  7301. ;; `cmd' may have been set by `org-agenda-run-series' which
  7302. ;; uses `org-agenda-overriding-cmd' to decide whether
  7303. ;; overriding is allowed for `cmd'
  7304. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7305. (org-agenda-overriding-arguments
  7306. (list (car args) sd span)))
  7307. (org-agenda-redo)
  7308. (org-agenda-find-same-or-today-or-agenda cnt))))
  7309. (defun org-agenda-earlier (arg)
  7310. "Go backward in time by the current span.
  7311. With prefix ARG, go backward that many times the current span."
  7312. (interactive "p")
  7313. (org-agenda-later (- arg)))
  7314. (defun org-agenda-view-mode-dispatch ()
  7315. "Call one of the view mode commands."
  7316. (interactive)
  7317. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7318. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7319. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7320. (let ((a (read-char-exclusive)))
  7321. (case a
  7322. (?\ (call-interactively 'org-agenda-reset-view))
  7323. (?d (call-interactively 'org-agenda-day-view))
  7324. (?w (call-interactively 'org-agenda-week-view))
  7325. (?t (call-interactively 'org-agenda-fortnight-view))
  7326. (?m (call-interactively 'org-agenda-month-view))
  7327. (?y (call-interactively 'org-agenda-year-view))
  7328. (?l (call-interactively 'org-agenda-log-mode))
  7329. (?L (org-agenda-log-mode '(4)))
  7330. (?c (org-agenda-log-mode 'clockcheck))
  7331. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7332. (?a (call-interactively 'org-agenda-archives-mode))
  7333. (?A (org-agenda-archives-mode 'files))
  7334. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7335. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7336. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7337. (?D (call-interactively 'org-agenda-toggle-diary))
  7338. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7339. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7340. (org-agenda-check-type t 'timeline 'agenda)
  7341. (org-agenda-redo))
  7342. (message "Display now includes inactive timestamps as well"))
  7343. (?q (message "Abort"))
  7344. (otherwise (error "Invalid key" )))))
  7345. (defun org-agenda-reset-view ()
  7346. "Switch to default view for agenda."
  7347. (interactive)
  7348. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7349. (defun org-agenda-day-view (&optional day-of-month)
  7350. "Switch to daily view for agenda.
  7351. With argument DAY-OF-MONTH, switch to that day of the month."
  7352. (interactive "P")
  7353. (org-agenda-change-time-span 'day day-of-month))
  7354. (defun org-agenda-week-view (&optional iso-week)
  7355. "Switch to daily view for agenda.
  7356. With argument ISO-WEEK, switch to the corresponding ISO week.
  7357. If ISO-WEEK has more then 2 digits, only the last two encode the
  7358. week. Any digits before this encode a year. So 200712 means
  7359. week 12 of year 2007. Years in the range 1938-2037 can also be
  7360. written as 2-digit years."
  7361. (interactive "P")
  7362. (org-agenda-change-time-span 'week iso-week))
  7363. (defun org-agenda-fortnight-view (&optional iso-week)
  7364. "Switch to daily view for agenda.
  7365. With argument ISO-WEEK, switch to the corresponding ISO week.
  7366. If ISO-WEEK has more then 2 digits, only the last two encode the
  7367. week. Any digits before this encode a year. So 200712 means
  7368. week 12 of year 2007. Years in the range 1938-2037 can also be
  7369. written as 2-digit years."
  7370. (interactive "P")
  7371. (org-agenda-change-time-span 'fortnight iso-week))
  7372. (defun org-agenda-month-view (&optional month)
  7373. "Switch to monthly view for agenda.
  7374. With argument MONTH, switch to that month."
  7375. (interactive "P")
  7376. (org-agenda-change-time-span 'month month))
  7377. (defun org-agenda-year-view (&optional year)
  7378. "Switch to yearly view for agenda.
  7379. With argument YEAR, switch to that year.
  7380. If MONTH has more then 2 digits, only the last two encode the
  7381. month. Any digits before this encode a year. So 200712 means
  7382. December year 2007. Years in the range 1938-2037 can also be
  7383. written as 2-digit years."
  7384. (interactive "P")
  7385. (when year
  7386. (setq year (org-small-year-to-year year)))
  7387. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7388. (org-agenda-change-time-span 'year year)
  7389. (error "Abort")))
  7390. (defun org-agenda-change-time-span (span &optional n)
  7391. "Change the agenda view to SPAN.
  7392. SPAN may be `day', `week', `fortnight', `month', `year'."
  7393. (org-agenda-check-type t 'agenda)
  7394. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7395. (curspan (nth 2 args)))
  7396. (if (and (not n) (equal curspan span))
  7397. (error "Viewing span is already \"%s\"" span))
  7398. (let* ((sd (or (org-get-at-bol 'day)
  7399. (nth 1 args)
  7400. org-starting-day))
  7401. (sd (org-agenda-compute-starting-span sd span n))
  7402. (org-agenda-overriding-cmd
  7403. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7404. (org-agenda-overriding-arguments
  7405. (list (car args) sd span)))
  7406. (org-agenda-redo)
  7407. (org-agenda-find-same-or-today-or-agenda))
  7408. (org-agenda-set-mode-name)
  7409. (message "Switched to %s view" span)))
  7410. (defun org-agenda-compute-starting-span (sd span &optional n)
  7411. "Compute starting date for agenda.
  7412. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7413. is a cons cell with the starting date and the number of days,
  7414. so that the date SD will be in that range."
  7415. (let* ((greg (calendar-gregorian-from-absolute sd))
  7416. (dg (nth 1 greg))
  7417. (mg (car greg))
  7418. (yg (nth 2 greg)))
  7419. (cond
  7420. ((eq span 'day)
  7421. (when n
  7422. (setq sd (+ (calendar-absolute-from-gregorian
  7423. (list mg 1 yg))
  7424. n -1))))
  7425. ((or (eq span 'week) (eq span 'fortnight))
  7426. (let* ((nt (calendar-day-of-week
  7427. (calendar-gregorian-from-absolute sd)))
  7428. (d (if org-agenda-start-on-weekday
  7429. (- nt org-agenda-start-on-weekday)
  7430. 0))
  7431. y1)
  7432. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7433. (when n
  7434. (require 'cal-iso)
  7435. (when (> n 99)
  7436. (setq y1 (org-small-year-to-year (/ n 100))
  7437. n (mod n 100)))
  7438. (setq sd
  7439. (calendar-absolute-from-iso
  7440. (list n 1
  7441. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7442. ((eq span 'month)
  7443. (let (y1)
  7444. (when (and n (> n 99))
  7445. (setq y1 (org-small-year-to-year (/ n 100))
  7446. n (mod n 100)))
  7447. (setq sd (calendar-absolute-from-gregorian
  7448. (list (or n mg) 1 (or y1 yg))))))
  7449. ((eq span 'year)
  7450. (setq sd (calendar-absolute-from-gregorian
  7451. (list 1 1 (or n yg))))))
  7452. sd))
  7453. (defun org-agenda-next-date-line (&optional arg)
  7454. "Jump to the next line indicating a date in agenda buffer."
  7455. (interactive "p")
  7456. (org-agenda-check-type t 'agenda 'timeline)
  7457. (beginning-of-line 1)
  7458. ;; This does not work if user makes date format that starts with a blank
  7459. (if (looking-at "^\\S-") (forward-char 1))
  7460. (if (not (re-search-forward "^\\S-" nil t arg))
  7461. (progn
  7462. (backward-char 1)
  7463. (error "No next date after this line in this buffer")))
  7464. (goto-char (match-beginning 0)))
  7465. (defun org-agenda-previous-date-line (&optional arg)
  7466. "Jump to the previous line indicating a date in agenda buffer."
  7467. (interactive "p")
  7468. (org-agenda-check-type t 'agenda 'timeline)
  7469. (beginning-of-line 1)
  7470. (if (not (re-search-backward "^\\S-" nil t arg))
  7471. (error "No previous date before this line in this buffer")))
  7472. ;; Initialize the highlight
  7473. (defvar org-hl (make-overlay 1 1))
  7474. (overlay-put org-hl 'face 'highlight)
  7475. (defun org-highlight (begin end &optional buffer)
  7476. "Highlight a region with overlay."
  7477. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7478. (defun org-unhighlight ()
  7479. "Detach overlay INDEX."
  7480. (org-detach-overlay org-hl))
  7481. (defun org-unhighlight-once ()
  7482. "Remove the highlight from its position, and this function from the hook."
  7483. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7484. (org-unhighlight))
  7485. (defvar org-agenda-pre-follow-window-conf nil)
  7486. (defun org-agenda-follow-mode ()
  7487. "Toggle follow mode in an agenda buffer."
  7488. (interactive)
  7489. (unless org-agenda-follow-mode
  7490. (setq org-agenda-pre-follow-window-conf
  7491. (current-window-configuration)))
  7492. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7493. (unless org-agenda-follow-mode
  7494. (set-window-configuration org-agenda-pre-follow-window-conf))
  7495. (org-agenda-set-mode-name)
  7496. (org-agenda-do-context-action)
  7497. (message "Follow mode is %s"
  7498. (if org-agenda-follow-mode "on" "off")))
  7499. (defun org-agenda-entry-text-mode (&optional arg)
  7500. "Toggle entry text mode in an agenda buffer."
  7501. (interactive "P")
  7502. (if (or org-agenda-tag-filter
  7503. org-agenda-category-filter
  7504. org-agenda-regexp-filter
  7505. org-agenda-top-headline-filter)
  7506. (user-error "Can't show entry text in filtered views")
  7507. (setq org-agenda-entry-text-mode (or (integerp arg)
  7508. (not org-agenda-entry-text-mode)))
  7509. (org-agenda-entry-text-hide)
  7510. (and org-agenda-entry-text-mode
  7511. (let ((org-agenda-entry-text-maxlines
  7512. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7513. (org-agenda-entry-text-show)))
  7514. (org-agenda-set-mode-name)
  7515. (message "Entry text mode is %s%s"
  7516. (if org-agenda-entry-text-mode "on" "off")
  7517. (if (not org-agenda-entry-text-mode) ""
  7518. (format " (maximum number of lines is %d)"
  7519. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7520. (defun org-agenda-clockreport-mode (&optional with-filter)
  7521. "Toggle clocktable mode in an agenda buffer.
  7522. With prefix arg WITH-FILTER, make the clocktable respect the current
  7523. agenda filter."
  7524. (interactive "P")
  7525. (org-agenda-check-type t 'agenda)
  7526. (if with-filter
  7527. (setq org-agenda-clockreport-mode 'with-filter)
  7528. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7529. (org-agenda-set-mode-name)
  7530. (org-agenda-redo)
  7531. (message "Clocktable mode is %s"
  7532. (if org-agenda-clockreport-mode "on" "off")))
  7533. (defun org-agenda-log-mode (&optional special)
  7534. "Toggle log mode in an agenda buffer.
  7535. With argument SPECIAL, show all possible log items, not only the ones
  7536. configured in `org-agenda-log-mode-items'.
  7537. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7538. (interactive "P")
  7539. (org-agenda-check-type t 'agenda 'timeline)
  7540. (setq org-agenda-show-log
  7541. (cond
  7542. ((equal special '(16)) 'only)
  7543. ((eq special 'clockcheck)
  7544. (if (eq org-agenda-show-log 'clockcheck)
  7545. nil 'clockcheck))
  7546. (special '(closed clock state))
  7547. (t (not org-agenda-show-log))))
  7548. (org-agenda-set-mode-name)
  7549. (org-agenda-redo)
  7550. (message "Log mode is %s"
  7551. (if org-agenda-show-log "on" "off")))
  7552. (defun org-agenda-archives-mode (&optional with-files)
  7553. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7554. When called with a prefix argument, include all archive files as well."
  7555. (interactive "P")
  7556. (setq org-agenda-archives-mode
  7557. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7558. (org-agenda-set-mode-name)
  7559. (org-agenda-redo)
  7560. (message
  7561. "%s"
  7562. (cond
  7563. ((eq org-agenda-archives-mode nil)
  7564. "No archives are included")
  7565. ((eq org-agenda-archives-mode 'trees)
  7566. (format "Trees with :%s: tag are included" org-archive-tag))
  7567. ((eq org-agenda-archives-mode t)
  7568. (format "Trees with :%s: tag and all active archive files are included"
  7569. org-archive-tag)))))
  7570. (defun org-agenda-toggle-diary ()
  7571. "Toggle diary inclusion in an agenda buffer."
  7572. (interactive)
  7573. (org-agenda-check-type t 'agenda)
  7574. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7575. (org-agenda-redo)
  7576. (org-agenda-set-mode-name)
  7577. (message "Diary inclusion turned %s"
  7578. (if org-agenda-include-diary "on" "off")))
  7579. (defun org-agenda-toggle-deadlines ()
  7580. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7581. (interactive)
  7582. (org-agenda-check-type t 'agenda)
  7583. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7584. (org-agenda-redo)
  7585. (org-agenda-set-mode-name)
  7586. (message "Deadlines inclusion turned %s"
  7587. (if org-agenda-include-deadlines "on" "off")))
  7588. (defun org-agenda-toggle-time-grid ()
  7589. "Toggle time grid in an agenda buffer."
  7590. (interactive)
  7591. (org-agenda-check-type t 'agenda)
  7592. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7593. (org-agenda-redo)
  7594. (org-agenda-set-mode-name)
  7595. (message "Time-grid turned %s"
  7596. (if org-agenda-use-time-grid "on" "off")))
  7597. (defun org-agenda-set-mode-name ()
  7598. "Set the mode name to indicate all the small mode settings."
  7599. (setq mode-name
  7600. (list "Org-Agenda"
  7601. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7602. " "
  7603. '(:eval (org-agenda-span-name org-agenda-current-span))
  7604. (if org-agenda-follow-mode " Follow" "")
  7605. (if org-agenda-entry-text-mode " ETxt" "")
  7606. (if org-agenda-include-diary " Diary" "")
  7607. (if org-agenda-include-deadlines " Ddl" "")
  7608. (if org-agenda-use-time-grid " Grid" "")
  7609. (if (and (boundp 'org-habit-show-habits)
  7610. org-habit-show-habits) " Habit" "")
  7611. (cond
  7612. ((consp org-agenda-show-log) " LogAll")
  7613. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7614. (org-agenda-show-log " Log")
  7615. (t ""))
  7616. (if (or org-agenda-category-filter
  7617. (get 'org-agenda-category-filter :preset-filter))
  7618. '(:eval (org-propertize
  7619. (concat " <"
  7620. (mapconcat
  7621. 'identity
  7622. (append
  7623. (get 'org-agenda-category-filter :preset-filter)
  7624. org-agenda-category-filter)
  7625. "")
  7626. ">")
  7627. 'face 'org-agenda-filter-category
  7628. 'help-echo "Category used in filtering")) "")
  7629. (if (or org-agenda-tag-filter
  7630. (get 'org-agenda-tag-filter :preset-filter))
  7631. '(:eval (org-propertize
  7632. (concat " {"
  7633. (mapconcat
  7634. 'identity
  7635. (append
  7636. (get 'org-agenda-tag-filter :preset-filter)
  7637. org-agenda-tag-filter)
  7638. "")
  7639. "}")
  7640. 'face 'org-agenda-filter-tags
  7641. 'help-echo "Tags used in filtering")) "")
  7642. (if (or org-agenda-regexp-filter
  7643. (get 'org-agenda-regexp-filter :preset-filter))
  7644. '(:eval (org-propertize
  7645. (concat " ["
  7646. (mapconcat
  7647. 'identity
  7648. (append
  7649. (get 'org-agenda-regexp-filter :preset-filter)
  7650. org-agenda-regexp-filter)
  7651. "")
  7652. "]")
  7653. 'face 'org-agenda-filter-regexp
  7654. 'help-echo "Regexp used in filtering")) "")
  7655. (if org-agenda-archives-mode
  7656. (if (eq org-agenda-archives-mode t)
  7657. " Archives"
  7658. (format " :%s:" org-archive-tag))
  7659. "")
  7660. (if org-agenda-clockreport-mode
  7661. (if (eq org-agenda-clockreport-mode 'with-filter)
  7662. " Clock{}" " Clock")
  7663. "")))
  7664. (force-mode-line-update))
  7665. (define-obsolete-function-alias
  7666. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7667. (defun org-agenda-update-agenda-type ()
  7668. "Update the agenda type after each command."
  7669. (setq org-agenda-type
  7670. (or (get-text-property (point) 'org-agenda-type)
  7671. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7672. (defun org-agenda-next-line ()
  7673. "Move cursor to the next line, and show if follow mode is active."
  7674. (interactive)
  7675. (call-interactively 'next-line)
  7676. (org-agenda-do-context-action))
  7677. (defun org-agenda-previous-line ()
  7678. "Move cursor to the previous line, and show if follow-mode is active."
  7679. (interactive)
  7680. (call-interactively 'previous-line)
  7681. (org-agenda-do-context-action))
  7682. (defun org-agenda-next-item (n)
  7683. "Move cursor to next agenda item."
  7684. (interactive "p")
  7685. (let ((col (current-column)))
  7686. (dotimes (c n)
  7687. (when (next-single-property-change (point-at-eol) 'org-marker)
  7688. (move-end-of-line 1)
  7689. (goto-char (next-single-property-change (point) 'org-marker))))
  7690. (org-move-to-column col))
  7691. (org-agenda-do-context-action))
  7692. (defun org-agenda-previous-item (n)
  7693. "Move cursor to next agenda item."
  7694. (interactive "p")
  7695. (dotimes (c n)
  7696. (let ((col (current-column))
  7697. (goto (save-excursion
  7698. (move-end-of-line 0)
  7699. (previous-single-property-change (point) 'org-marker))))
  7700. (if goto (goto-char goto))
  7701. (org-move-to-column col)))
  7702. (org-agenda-do-context-action))
  7703. (defun org-agenda-do-context-action ()
  7704. "Show outline path and, maybe, follow mode window."
  7705. (let ((m (org-get-at-bol 'org-marker)))
  7706. (when (and (markerp m) (marker-buffer m))
  7707. (and org-agenda-follow-mode
  7708. (if org-agenda-follow-indirect
  7709. (org-agenda-tree-to-indirect-buffer nil)
  7710. (org-agenda-show)))
  7711. (and org-agenda-show-outline-path
  7712. (org-with-point-at m (org-display-outline-path t))))))
  7713. (defun org-agenda-show-tags ()
  7714. "Show the tags applicable to the current item."
  7715. (interactive)
  7716. (let* ((tags (org-get-at-bol 'tags)))
  7717. (if tags
  7718. (message "Tags are :%s:"
  7719. (org-no-properties (mapconcat 'identity tags ":")))
  7720. (message "No tags associated with this line"))))
  7721. (defun org-agenda-goto (&optional highlight)
  7722. "Go to the Org-mode file which contains the item at point."
  7723. (interactive)
  7724. (let* ((marker (or (org-get-at-bol 'org-marker)
  7725. (org-agenda-error)))
  7726. (buffer (marker-buffer marker))
  7727. (pos (marker-position marker)))
  7728. (switch-to-buffer-other-window buffer)
  7729. (widen)
  7730. (push-mark)
  7731. (goto-char pos)
  7732. (when (derived-mode-p 'org-mode)
  7733. (org-show-context 'agenda)
  7734. (save-excursion
  7735. (and (outline-next-heading)
  7736. (org-flag-heading nil)))) ; show the next heading
  7737. (when (outline-invisible-p)
  7738. (show-entry)) ; display invisible text
  7739. (recenter (/ (window-height) 2))
  7740. (run-hooks 'org-agenda-after-show-hook)
  7741. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7742. (defvar org-agenda-after-show-hook nil
  7743. "Normal hook run after an item has been shown from the agenda.
  7744. Point is in the buffer where the item originated.")
  7745. (defun org-agenda-kill ()
  7746. "Kill the entry or subtree belonging to the current agenda entry."
  7747. (interactive)
  7748. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7749. (let* ((bufname-orig (buffer-name))
  7750. (marker (or (org-get-at-bol 'org-marker)
  7751. (org-agenda-error)))
  7752. (buffer (marker-buffer marker))
  7753. (pos (marker-position marker))
  7754. (type (org-get-at-bol 'type))
  7755. dbeg dend (n 0) conf)
  7756. (org-with-remote-undo buffer
  7757. (with-current-buffer buffer
  7758. (save-excursion
  7759. (goto-char pos)
  7760. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7761. (setq dbeg (progn (org-back-to-heading t) (point))
  7762. dend (org-end-of-subtree t t))
  7763. (setq dbeg (point-at-bol)
  7764. dend (min (point-max) (1+ (point-at-eol)))))
  7765. (goto-char dbeg)
  7766. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7767. (setq conf (or (eq t org-agenda-confirm-kill)
  7768. (and (numberp org-agenda-confirm-kill)
  7769. (> n org-agenda-confirm-kill))))
  7770. (and conf
  7771. (not (y-or-n-p
  7772. (format "Delete entry with %d lines in buffer \"%s\"? "
  7773. n (buffer-name buffer))))
  7774. (error "Abort"))
  7775. (let ((org-agenda-buffer-name bufname-orig))
  7776. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7777. (with-current-buffer buffer (delete-region dbeg dend))
  7778. (message "Agenda item and source killed"))))
  7779. (defvar org-archive-default-command) ; defined in org-archive.el
  7780. (defun org-agenda-archive-default ()
  7781. "Archive the entry or subtree belonging to the current agenda entry."
  7782. (interactive)
  7783. (require 'org-archive)
  7784. (org-agenda-archive-with org-archive-default-command))
  7785. (defun org-agenda-archive-default-with-confirmation ()
  7786. "Archive the entry or subtree belonging to the current agenda entry."
  7787. (interactive)
  7788. (require 'org-archive)
  7789. (org-agenda-archive-with org-archive-default-command 'confirm))
  7790. (defun org-agenda-archive ()
  7791. "Archive the entry or subtree belonging to the current agenda entry."
  7792. (interactive)
  7793. (org-agenda-archive-with 'org-archive-subtree))
  7794. (defun org-agenda-archive-to-archive-sibling ()
  7795. "Move the entry to the archive sibling."
  7796. (interactive)
  7797. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7798. (defun org-agenda-archive-with (cmd &optional confirm)
  7799. "Move the entry to the archive sibling."
  7800. (interactive)
  7801. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7802. (let* ((bufname-orig (buffer-name))
  7803. (marker (or (org-get-at-bol 'org-marker)
  7804. (org-agenda-error)))
  7805. (buffer (marker-buffer marker))
  7806. (pos (marker-position marker)))
  7807. (org-with-remote-undo buffer
  7808. (with-current-buffer buffer
  7809. (if (derived-mode-p 'org-mode)
  7810. (if (and confirm
  7811. (not (y-or-n-p "Archive this subtree or entry? ")))
  7812. (error "Abort")
  7813. (save-window-excursion
  7814. (goto-char pos)
  7815. (let ((org-agenda-buffer-name bufname-orig))
  7816. (org-remove-subtree-entries-from-agenda))
  7817. (org-back-to-heading t)
  7818. (funcall cmd)))
  7819. (error "Archiving works only in Org-mode files"))))))
  7820. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7821. "Remove all lines in the agenda that correspond to a given subtree.
  7822. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7823. If this information is not given, the function uses the tree at point."
  7824. (let ((buf (or buf (current-buffer))) m p)
  7825. (save-excursion
  7826. (unless (and beg end)
  7827. (org-back-to-heading t)
  7828. (setq beg (point))
  7829. (org-end-of-subtree t)
  7830. (setq end (point)))
  7831. (set-buffer (get-buffer org-agenda-buffer-name))
  7832. (save-excursion
  7833. (goto-char (point-max))
  7834. (beginning-of-line 1)
  7835. (while (not (bobp))
  7836. (when (and (setq m (org-get-at-bol 'org-marker))
  7837. (equal buf (marker-buffer m))
  7838. (setq p (marker-position m))
  7839. (>= p beg)
  7840. (< p end))
  7841. (let ((inhibit-read-only t))
  7842. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7843. (beginning-of-line 0))))))
  7844. (defun org-agenda-refile (&optional goto rfloc no-update)
  7845. "Refile the item at point.
  7846. When GOTO is 0 or '(64), clear the refile cache.
  7847. When GOTO is '(16), go to the location of the last refiled item.
  7848. RFLOC can be a refile location obtained in a different way.
  7849. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7850. (interactive "P")
  7851. (cond
  7852. ((member goto '(0 (64)))
  7853. (org-refile-cache-clear))
  7854. ((equal goto '(16))
  7855. (org-refile-goto-last-stored))
  7856. (t
  7857. (let* ((buffer-orig (buffer-name))
  7858. (marker (or (org-get-at-bol 'org-hd-marker)
  7859. (org-agenda-error)))
  7860. (buffer (marker-buffer marker))
  7861. (pos (marker-position marker))
  7862. (rfloc (or rfloc
  7863. (org-refile-get-location
  7864. (if goto "Goto" "Refile to") buffer
  7865. org-refile-allow-creating-parent-nodes))))
  7866. (with-current-buffer buffer
  7867. (save-excursion
  7868. (save-restriction
  7869. (widen)
  7870. (goto-char marker)
  7871. (let ((org-agenda-buffer-name buffer-orig))
  7872. (org-remove-subtree-entries-from-agenda))
  7873. (org-refile goto buffer rfloc)))))
  7874. (unless no-update (org-agenda-redo)))))
  7875. (defun org-agenda-open-link (&optional arg)
  7876. "Open the link(s) in the current entry, if any.
  7877. This looks for a link in the displayed line in the agenda.
  7878. It also looks at the text of the entry itself."
  7879. (interactive "P")
  7880. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7881. (org-get-at-bol 'org-marker)))
  7882. (buffer (and marker (marker-buffer marker)))
  7883. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7884. (lkall (and buffer (org-offer-links-in-entry
  7885. buffer marker arg prefix)))
  7886. (lk0 (car lkall))
  7887. (lk (if (stringp lk0) (list lk0) lk0))
  7888. (lkend (cdr lkall))
  7889. trg)
  7890. (cond
  7891. ((and buffer lk)
  7892. (mapcar (lambda(l)
  7893. (with-current-buffer buffer
  7894. (setq trg (and (string-match org-bracket-link-regexp l)
  7895. (match-string 1 l)))
  7896. (if (or (not trg) (string-match org-any-link-re trg))
  7897. (save-excursion
  7898. (save-restriction
  7899. (widen)
  7900. (goto-char marker)
  7901. (when (search-forward l nil lkend)
  7902. (goto-char (match-beginning 0))
  7903. (org-open-at-point))))
  7904. ;; This is an internal link, widen the buffer
  7905. (switch-to-buffer-other-window buffer)
  7906. (widen)
  7907. (goto-char marker)
  7908. (when (search-forward l nil lkend)
  7909. (goto-char (match-beginning 0))
  7910. (org-open-at-point)))))
  7911. lk))
  7912. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7913. (save-excursion
  7914. (beginning-of-line 1)
  7915. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7916. (org-open-link-from-string (match-string 1)))
  7917. (t (message "No link to open here")))))
  7918. (defun org-agenda-copy-local-variable (var)
  7919. "Get a variable from a referenced buffer and install it here."
  7920. (let ((m (org-get-at-bol 'org-marker)))
  7921. (when (and m (buffer-live-p (marker-buffer m)))
  7922. (org-set-local var (with-current-buffer (marker-buffer m)
  7923. (symbol-value var))))))
  7924. (defun org-agenda-switch-to (&optional delete-other-windows)
  7925. "Go to the Org-mode file which contains the item at point."
  7926. (interactive)
  7927. (if (and org-return-follows-link
  7928. (not (org-get-at-bol 'org-marker))
  7929. (org-in-regexp org-bracket-link-regexp))
  7930. (org-open-link-from-string (match-string 0))
  7931. (let* ((marker (or (org-get-at-bol 'org-marker)
  7932. (org-agenda-error)))
  7933. (buffer (marker-buffer marker))
  7934. (pos (marker-position marker)))
  7935. (org-pop-to-buffer-same-window buffer)
  7936. (and delete-other-windows (delete-other-windows))
  7937. (widen)
  7938. (goto-char pos)
  7939. (org-back-to-heading t)
  7940. (when (derived-mode-p 'org-mode)
  7941. (org-show-context 'agenda)
  7942. (save-excursion
  7943. (and (outline-next-heading)
  7944. (org-flag-heading nil))) ; show the next heading
  7945. (when (outline-invisible-p)
  7946. (show-entry)) ; display invisible text
  7947. (run-hooks 'org-agenda-after-show-hook)))))
  7948. (defun org-agenda-goto-mouse (ev)
  7949. "Go to the Org-mode file which contains the item at the mouse click."
  7950. (interactive "e")
  7951. (mouse-set-point ev)
  7952. (org-agenda-goto))
  7953. (defun org-agenda-show (&optional full-entry)
  7954. "Display the Org-mode file which contains the item at point.
  7955. With prefix argument FULL-ENTRY, make the entire entry visible
  7956. if it was hidden in the outline."
  7957. (interactive "P")
  7958. (let ((win (selected-window)))
  7959. (if full-entry
  7960. (let ((org-show-entry-below t))
  7961. (org-agenda-goto t))
  7962. (org-agenda-goto t))
  7963. (select-window win)))
  7964. (defvar org-agenda-show-window nil)
  7965. (defun org-agenda-show-and-scroll-up (&optional arg)
  7966. "Display the Org-mode file which contains the item at point.
  7967. When called repeatedly, scroll the window that is displaying the buffer.
  7968. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7969. `show-subtree' to display the item, so that drawers and logbooks stay
  7970. folded."
  7971. (interactive "P")
  7972. (let ((win (selected-window)))
  7973. (if (and (window-live-p org-agenda-show-window)
  7974. (eq this-command last-command))
  7975. (progn
  7976. (select-window org-agenda-show-window)
  7977. (ignore-errors (scroll-up)))
  7978. (org-agenda-goto t)
  7979. (if arg (org-show-entry) (show-subtree))
  7980. (setq org-agenda-show-window (selected-window)))
  7981. (select-window win)))
  7982. (defun org-agenda-show-scroll-down ()
  7983. "Scroll down the window showing the agenda."
  7984. (interactive)
  7985. (let ((win (selected-window)))
  7986. (when (window-live-p org-agenda-show-window)
  7987. (select-window org-agenda-show-window)
  7988. (ignore-errors (scroll-down))
  7989. (select-window win))))
  7990. (defun org-agenda-show-1 (&optional more)
  7991. "Display the Org-mode file which contains the item at point.
  7992. The prefix arg selects the amount of information to display:
  7993. 0 hide the subtree
  7994. 1 just show the entry according to defaults.
  7995. 2 show the children view
  7996. 3 show the subtree view
  7997. 4 show the entire subtree and any LOGBOOK drawers
  7998. 5 show the entire subtree and any drawers
  7999. With prefix argument FULL-ENTRY, make the entire entry visible
  8000. if it was hidden in the outline."
  8001. (interactive "p")
  8002. (let ((win (selected-window)))
  8003. (org-agenda-goto t)
  8004. (org-recenter-heading 1)
  8005. (cond
  8006. ((= more 0)
  8007. (hide-subtree)
  8008. (save-excursion
  8009. (org-back-to-heading)
  8010. (run-hook-with-args 'org-cycle-hook 'folded))
  8011. (message "Remote: FOLDED"))
  8012. ((and (org-called-interactively-p 'any) (= more 1))
  8013. (message "Remote: show with default settings"))
  8014. ((= more 2)
  8015. (show-entry)
  8016. (show-children)
  8017. (save-excursion
  8018. (org-back-to-heading)
  8019. (run-hook-with-args 'org-cycle-hook 'children))
  8020. (message "Remote: CHILDREN"))
  8021. ((= more 3)
  8022. (show-subtree)
  8023. (save-excursion
  8024. (org-back-to-heading)
  8025. (run-hook-with-args 'org-cycle-hook 'subtree))
  8026. (message "Remote: SUBTREE"))
  8027. ((= more 4)
  8028. (show-subtree)
  8029. (save-excursion
  8030. (org-back-to-heading)
  8031. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8032. (message "Remote: SUBTREE AND LOGBOOK"))
  8033. ((> more 4)
  8034. (show-subtree)
  8035. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8036. (select-window win)))
  8037. (defun org-recenter-heading (n)
  8038. (save-excursion
  8039. (org-back-to-heading)
  8040. (recenter n)))
  8041. (defvar org-agenda-cycle-counter nil)
  8042. (defun org-agenda-cycle-show (&optional n)
  8043. "Show the current entry in another window, with default settings.
  8044. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8045. When use repeatedly in immediate succession, the remote entry will cycle
  8046. through visibility
  8047. children -> subtree -> folded
  8048. When called with a numeric prefix arg, that arg will be passed through to
  8049. `org-agenda-show-1'. For the interpretation of that argument, see the
  8050. docstring of `org-agenda-show-1'."
  8051. (interactive "P")
  8052. (if (integerp n)
  8053. (setq org-agenda-cycle-counter n)
  8054. (if (not (eq last-command this-command))
  8055. (setq org-agenda-cycle-counter 1)
  8056. (if (equal org-agenda-cycle-counter 0)
  8057. (setq org-agenda-cycle-counter 2)
  8058. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8059. (if (> org-agenda-cycle-counter 3)
  8060. (setq org-agenda-cycle-counter 0)))))
  8061. (org-agenda-show-1 org-agenda-cycle-counter))
  8062. (defun org-agenda-recenter (arg)
  8063. "Display the Org-mode file which contains the item at point and recenter."
  8064. (interactive "P")
  8065. (let ((win (selected-window)))
  8066. (org-agenda-goto t)
  8067. (recenter arg)
  8068. (select-window win)))
  8069. (defun org-agenda-show-mouse (ev)
  8070. "Display the Org-mode file which contains the item at the mouse click."
  8071. (interactive "e")
  8072. (mouse-set-point ev)
  8073. (org-agenda-show))
  8074. (defun org-agenda-check-no-diary ()
  8075. "Check if the entry is a diary link and abort if yes."
  8076. (if (org-get-at-bol 'org-agenda-diary-link)
  8077. (org-agenda-error)))
  8078. (defun org-agenda-error ()
  8079. "Throw an error when a command is not allowed in the agenda."
  8080. (user-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-window-excursion
  8167. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8168. (when (org-bound-and-true-p org-clock-out-when-done)
  8169. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8170. newhead)
  8171. (org-agenda-unmark-clocking-task))
  8172. (org-move-to-column col))))
  8173. (defun org-agenda-add-note (&optional arg)
  8174. "Add a time-stamped note to the entry at point."
  8175. (interactive "P")
  8176. (org-agenda-check-no-diary)
  8177. (let* ((marker (or (org-get-at-bol 'org-marker)
  8178. (org-agenda-error)))
  8179. (buffer (marker-buffer marker))
  8180. (pos (marker-position marker))
  8181. (hdmarker (org-get-at-bol 'org-hd-marker))
  8182. (inhibit-read-only t))
  8183. (with-current-buffer buffer
  8184. (widen)
  8185. (goto-char pos)
  8186. (org-show-context 'agenda)
  8187. (save-excursion
  8188. (and (outline-next-heading)
  8189. (org-flag-heading nil))) ; show the next heading
  8190. (org-add-note))))
  8191. (defun org-agenda-change-all-lines (newhead hdmarker
  8192. &optional fixface just-this)
  8193. "Change all lines in the agenda buffer which match HDMARKER.
  8194. The new content of the line will be NEWHEAD (as modified by
  8195. `org-agenda-format-item'). HDMARKER is checked with
  8196. `equal' against all `org-hd-marker' text properties in the file.
  8197. If FIXFACE is non-nil, the face of each item is modified according to
  8198. the new TODO state.
  8199. If JUST-THIS is non-nil, change just the current line, not all.
  8200. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8201. (let* ((inhibit-read-only t)
  8202. (line (org-current-line))
  8203. (org-agenda-buffer (current-buffer))
  8204. (thetags (with-current-buffer (marker-buffer hdmarker)
  8205. (save-excursion (save-restriction (widen)
  8206. (goto-char hdmarker)
  8207. (org-get-tags-at)))))
  8208. props m pl undone-face done-face finish new dotime level cat tags)
  8209. (save-excursion
  8210. (goto-char (point-max))
  8211. (beginning-of-line 1)
  8212. (while (not finish)
  8213. (setq finish (bobp))
  8214. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8215. (or (not just-this) (= (org-current-line) line))
  8216. (equal m hdmarker))
  8217. (setq props (text-properties-at (point))
  8218. dotime (org-get-at-bol 'dotime)
  8219. cat (org-get-at-eol 'org-category 1)
  8220. level (org-get-at-bol 'level)
  8221. tags thetags
  8222. new
  8223. (let ((org-prefix-format-compiled
  8224. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8225. org-prefix-format-compiled))
  8226. (extra (org-get-at-bol 'extra)))
  8227. (with-current-buffer (marker-buffer hdmarker)
  8228. (save-excursion
  8229. (save-restriction
  8230. (widen)
  8231. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8232. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8233. undone-face (org-get-at-bol 'undone-face)
  8234. done-face (org-get-at-bol 'done-face))
  8235. (beginning-of-line 1)
  8236. (cond
  8237. ((equal new "")
  8238. (and (looking-at ".*\n?") (replace-match "")))
  8239. ((looking-at ".*")
  8240. (replace-match new t t)
  8241. (beginning-of-line 1)
  8242. (add-text-properties (point-at-bol) (point-at-eol) props)
  8243. (when fixface
  8244. (add-text-properties
  8245. (point-at-bol) (point-at-eol)
  8246. (list 'face
  8247. (if org-last-todo-state-is-todo
  8248. undone-face done-face))))
  8249. (org-agenda-highlight-todo 'line)
  8250. (beginning-of-line 1))
  8251. (t (error "Line update did not work")))
  8252. (save-restriction
  8253. (narrow-to-region (point-at-bol) (point-at-eol))
  8254. (org-agenda-finalize)))
  8255. (beginning-of-line 0)))))
  8256. (defun org-agenda-align-tags (&optional line)
  8257. "Align all tags in agenda items to `org-agenda-tags-column'."
  8258. (let ((inhibit-read-only t) l c)
  8259. (save-excursion
  8260. (goto-char (if line (point-at-bol) (point-min)))
  8261. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8262. (if line (point-at-eol) nil) t)
  8263. (add-text-properties
  8264. (match-beginning 2) (match-end 2)
  8265. (list 'face (delq nil (let ((prop (get-text-property
  8266. (match-beginning 2) 'face)))
  8267. (or (listp prop) (setq prop (list prop)))
  8268. (if (memq 'org-tag prop)
  8269. prop
  8270. (cons 'org-tag prop))))))
  8271. (setq l (- (match-end 2) (match-beginning 2))
  8272. c (if (< org-agenda-tags-column 0)
  8273. (- (abs org-agenda-tags-column) l)
  8274. org-agenda-tags-column))
  8275. (delete-region (match-beginning 1) (match-end 1))
  8276. (goto-char (match-beginning 1))
  8277. (insert (org-add-props
  8278. (make-string (max 1 (- c (current-column))) ?\ )
  8279. (plist-put (copy-sequence (text-properties-at (point)))
  8280. 'face nil))))
  8281. (goto-char (point-min))
  8282. (org-font-lock-add-tag-faces (point-max)))))
  8283. (defun org-agenda-priority-up ()
  8284. "Increase the priority of line at point, also in Org-mode file."
  8285. (interactive)
  8286. (org-agenda-priority 'up))
  8287. (defun org-agenda-priority-down ()
  8288. "Decrease the priority of line at point, also in Org-mode file."
  8289. (interactive)
  8290. (org-agenda-priority 'down))
  8291. (defun org-agenda-priority (&optional force-direction)
  8292. "Set the priority of line at point, also in Org-mode file.
  8293. This changes the line at point, all other lines in the agenda referring to
  8294. the same tree node, and the headline of the tree node in the Org-mode file.
  8295. Called with a universal prefix arg, show the priority instead of setting it."
  8296. (interactive "P")
  8297. (if (equal force-direction '(4))
  8298. (org-show-priority)
  8299. (unless org-enable-priority-commands
  8300. (error "Priority commands are disabled"))
  8301. (org-agenda-check-no-diary)
  8302. (let* ((col (current-column))
  8303. (marker (or (org-get-at-bol 'org-marker)
  8304. (org-agenda-error)))
  8305. (hdmarker (org-get-at-bol 'org-hd-marker))
  8306. (buffer (marker-buffer hdmarker))
  8307. (pos (marker-position hdmarker))
  8308. (inhibit-read-only t)
  8309. newhead)
  8310. (org-with-remote-undo buffer
  8311. (with-current-buffer buffer
  8312. (widen)
  8313. (goto-char pos)
  8314. (org-show-context 'agenda)
  8315. (save-excursion
  8316. (and (outline-next-heading)
  8317. (org-flag-heading nil))) ; show the next heading
  8318. (funcall 'org-priority force-direction)
  8319. (end-of-line 1)
  8320. (setq newhead (org-get-heading)))
  8321. (org-agenda-change-all-lines newhead hdmarker)
  8322. (org-move-to-column col)))))
  8323. ;; FIXME: should fix the tags property of the agenda line.
  8324. (defun org-agenda-set-tags (&optional tag onoff)
  8325. "Set tags for the current headline."
  8326. (interactive)
  8327. (org-agenda-check-no-diary)
  8328. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8329. (call-interactively 'org-change-tag-in-region)
  8330. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8331. (org-agenda-error)))
  8332. (buffer (marker-buffer hdmarker))
  8333. (pos (marker-position hdmarker))
  8334. (inhibit-read-only t)
  8335. newhead)
  8336. (org-with-remote-undo buffer
  8337. (with-current-buffer buffer
  8338. (widen)
  8339. (goto-char pos)
  8340. (save-excursion
  8341. (org-show-context 'agenda))
  8342. (save-excursion
  8343. (and (outline-next-heading)
  8344. (org-flag-heading nil))) ; show the next heading
  8345. (goto-char pos)
  8346. (if tag
  8347. (org-toggle-tag tag onoff)
  8348. (call-interactively 'org-set-tags))
  8349. (end-of-line 1)
  8350. (setq newhead (org-get-heading)))
  8351. (org-agenda-change-all-lines newhead hdmarker)
  8352. (beginning-of-line 1)))))
  8353. (defun org-agenda-set-property ()
  8354. "Set a property for the current headline."
  8355. (interactive)
  8356. (org-agenda-check-no-diary)
  8357. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8358. (org-agenda-error)))
  8359. (buffer (marker-buffer hdmarker))
  8360. (pos (marker-position hdmarker))
  8361. (inhibit-read-only t)
  8362. newhead)
  8363. (org-with-remote-undo buffer
  8364. (with-current-buffer buffer
  8365. (widen)
  8366. (goto-char pos)
  8367. (save-excursion
  8368. (org-show-context 'agenda))
  8369. (save-excursion
  8370. (and (outline-next-heading)
  8371. (org-flag-heading nil))) ; show the next heading
  8372. (goto-char pos)
  8373. (call-interactively 'org-set-property)))))
  8374. (defun org-agenda-set-effort ()
  8375. "Set the effort property for the current headline."
  8376. (interactive)
  8377. (org-agenda-check-no-diary)
  8378. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8379. (org-agenda-error)))
  8380. (buffer (marker-buffer hdmarker))
  8381. (pos (marker-position hdmarker))
  8382. (inhibit-read-only t)
  8383. newhead)
  8384. (org-with-remote-undo buffer
  8385. (with-current-buffer buffer
  8386. (widen)
  8387. (goto-char pos)
  8388. (save-excursion
  8389. (org-show-context 'agenda))
  8390. (save-excursion
  8391. (and (outline-next-heading)
  8392. (org-flag-heading nil))) ; show the next heading
  8393. (goto-char pos)
  8394. (call-interactively 'org-set-effort)
  8395. (end-of-line 1)
  8396. (setq newhead (org-get-heading)))
  8397. (org-agenda-change-all-lines newhead hdmarker))))
  8398. (defun org-agenda-toggle-archive-tag ()
  8399. "Toggle the archive tag for the current entry."
  8400. (interactive)
  8401. (org-agenda-check-no-diary)
  8402. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8403. (org-agenda-error)))
  8404. (buffer (marker-buffer hdmarker))
  8405. (pos (marker-position hdmarker))
  8406. (inhibit-read-only t)
  8407. newhead)
  8408. (org-with-remote-undo buffer
  8409. (with-current-buffer buffer
  8410. (widen)
  8411. (goto-char pos)
  8412. (org-show-context 'agenda)
  8413. (save-excursion
  8414. (and (outline-next-heading)
  8415. (org-flag-heading nil))) ; show the next heading
  8416. (call-interactively 'org-toggle-archive-tag)
  8417. (end-of-line 1)
  8418. (setq newhead (org-get-heading)))
  8419. (org-agenda-change-all-lines newhead hdmarker)
  8420. (beginning-of-line 1))))
  8421. (defun org-agenda-do-date-later (arg)
  8422. (interactive "P")
  8423. (cond
  8424. ((or (equal arg '(16))
  8425. (memq last-command
  8426. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8427. (setq this-command 'org-agenda-date-later-minutes)
  8428. (org-agenda-date-later-minutes 1))
  8429. ((or (equal arg '(4))
  8430. (memq last-command
  8431. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8432. (setq this-command 'org-agenda-date-later-hours)
  8433. (org-agenda-date-later-hours 1))
  8434. (t
  8435. (org-agenda-date-later (prefix-numeric-value arg)))))
  8436. (defun org-agenda-do-date-earlier (arg)
  8437. (interactive "P")
  8438. (cond
  8439. ((or (equal arg '(16))
  8440. (memq last-command
  8441. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8442. (setq this-command 'org-agenda-date-earlier-minutes)
  8443. (org-agenda-date-earlier-minutes 1))
  8444. ((or (equal arg '(4))
  8445. (memq last-command
  8446. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8447. (setq this-command 'org-agenda-date-earlier-hours)
  8448. (org-agenda-date-earlier-hours 1))
  8449. (t
  8450. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8451. (defun org-agenda-date-later (arg &optional what)
  8452. "Change the date of this item to ARG day(s) later."
  8453. (interactive "p")
  8454. (org-agenda-check-type t 'agenda 'timeline)
  8455. (org-agenda-check-no-diary)
  8456. (let* ((marker (or (org-get-at-bol 'org-marker)
  8457. (org-agenda-error)))
  8458. (buffer (marker-buffer marker))
  8459. (pos (marker-position marker))
  8460. cdate today)
  8461. (org-with-remote-undo buffer
  8462. (with-current-buffer buffer
  8463. (widen)
  8464. (goto-char pos)
  8465. (if (not (org-at-timestamp-p))
  8466. (error "Cannot find time stamp"))
  8467. (when (and org-agenda-move-date-from-past-immediately-to-today
  8468. (equal arg 1)
  8469. (or (not what) (eq what 'day))
  8470. (not (save-match-data (org-at-date-range-p))))
  8471. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8472. cdate (calendar-absolute-from-gregorian
  8473. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8474. today (org-today))
  8475. (if (> today cdate)
  8476. ;; immediately shift to today
  8477. (setq arg (- today cdate))))
  8478. (org-timestamp-change arg (or what 'day))
  8479. (when (and (org-at-date-range-p)
  8480. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8481. (let ((end org-last-changed-timestamp))
  8482. (org-timestamp-change arg (or what 'day))
  8483. (setq org-last-changed-timestamp
  8484. (concat org-last-changed-timestamp "--" end)))))
  8485. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8486. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8487. (defun org-agenda-date-earlier (arg &optional what)
  8488. "Change the date of this item to ARG day(s) earlier."
  8489. (interactive "p")
  8490. (org-agenda-date-later (- arg) what))
  8491. (defun org-agenda-date-later-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-later arg 'minute))
  8496. (defun org-agenda-date-earlier-minutes (arg)
  8497. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8498. (interactive "p")
  8499. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8500. (org-agenda-date-earlier arg 'minute))
  8501. (defun org-agenda-date-later-hours (arg)
  8502. "Change the time of this item, in hour steps."
  8503. (interactive "p")
  8504. (org-agenda-date-later arg 'hour))
  8505. (defun org-agenda-date-earlier-hours (arg)
  8506. "Change the time of this item, in hour steps."
  8507. (interactive "p")
  8508. (org-agenda-date-earlier arg 'hour))
  8509. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8510. "Show new date stamp via text properties."
  8511. ;; We use text properties to make this undoable
  8512. (let ((inhibit-read-only t))
  8513. (setq stamp (concat prefix " => " stamp " "))
  8514. (save-excursion
  8515. (goto-char (point-max))
  8516. (while (not (bobp))
  8517. (when (equal marker (org-get-at-bol 'org-marker))
  8518. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8519. (org-move-to-column (- (window-width) (length stamp)) t)
  8520. (if (featurep 'xemacs)
  8521. ;; Use `duplicable' property to trigger undo recording
  8522. (let ((ex (make-extent nil nil))
  8523. (gl (make-glyph stamp)))
  8524. (set-glyph-face gl 'secondary-selection)
  8525. (set-extent-properties
  8526. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8527. (insert-extent ex (1- (point)) (point-at-eol)))
  8528. (add-text-properties
  8529. (1- (point)) (point-at-eol)
  8530. (list 'display (org-add-props stamp nil
  8531. 'face 'secondary-selection))))
  8532. (beginning-of-line 1))
  8533. (beginning-of-line 0)))))
  8534. (defun org-agenda-date-prompt (arg)
  8535. "Change the date of this item. Date is prompted for, with default today.
  8536. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8537. be used to request time specification in the time stamp."
  8538. (interactive "P")
  8539. (org-agenda-check-type t 'agenda 'timeline)
  8540. (org-agenda-check-no-diary)
  8541. (let* ((marker (or (org-get-at-bol 'org-marker)
  8542. (org-agenda-error)))
  8543. (buffer (marker-buffer marker))
  8544. (pos (marker-position marker)))
  8545. (org-with-remote-undo buffer
  8546. (with-current-buffer buffer
  8547. (widen)
  8548. (goto-char pos)
  8549. (if (not (org-at-timestamp-p t))
  8550. (error "Cannot find time stamp"))
  8551. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8552. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8553. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8554. (defun org-agenda-schedule (arg &optional time)
  8555. "Schedule the item at point.
  8556. ARG is passed through to `org-schedule'."
  8557. (interactive "P")
  8558. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8559. (org-agenda-check-no-diary)
  8560. (let* ((marker (or (org-get-at-bol 'org-marker)
  8561. (org-agenda-error)))
  8562. (type (marker-insertion-type marker))
  8563. (buffer (marker-buffer marker))
  8564. (pos (marker-position marker))
  8565. (org-insert-labeled-timestamps-at-point nil)
  8566. ts)
  8567. (set-marker-insertion-type marker t)
  8568. (org-with-remote-undo buffer
  8569. (with-current-buffer buffer
  8570. (widen)
  8571. (goto-char pos)
  8572. (setq ts (org-schedule arg time)))
  8573. (org-agenda-show-new-time marker ts " S"))
  8574. (message "%s" ts)))
  8575. (defun org-agenda-deadline (arg &optional time)
  8576. "Schedule the item at point.
  8577. ARG is passed through to `org-deadline'."
  8578. (interactive "P")
  8579. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8580. (org-agenda-check-no-diary)
  8581. (let* ((marker (or (org-get-at-bol 'org-marker)
  8582. (org-agenda-error)))
  8583. (buffer (marker-buffer marker))
  8584. (pos (marker-position marker))
  8585. (org-insert-labeled-timestamps-at-point nil)
  8586. ts)
  8587. (org-with-remote-undo buffer
  8588. (with-current-buffer buffer
  8589. (widen)
  8590. (goto-char pos)
  8591. (setq ts (org-deadline arg time)))
  8592. (org-agenda-show-new-time marker ts " D"))
  8593. (message "%s" ts)))
  8594. (defun org-agenda-clock-in (&optional arg)
  8595. "Start the clock on the currently selected item."
  8596. (interactive "P")
  8597. (org-agenda-check-no-diary)
  8598. (if (equal arg '(4))
  8599. (org-clock-in arg)
  8600. (let* ((marker (or (org-get-at-bol 'org-marker)
  8601. (org-agenda-error)))
  8602. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8603. (pos (marker-position marker))
  8604. (col (current-column))
  8605. newhead)
  8606. (org-with-remote-undo (marker-buffer marker)
  8607. (with-current-buffer (marker-buffer marker)
  8608. (widen)
  8609. (goto-char pos)
  8610. (org-show-context 'agenda)
  8611. (org-show-entry)
  8612. (org-cycle-hide-drawers 'children)
  8613. (org-clock-in arg)
  8614. (setq newhead (org-get-heading)))
  8615. (org-agenda-change-all-lines newhead hdmarker))
  8616. (org-move-to-column col))))
  8617. (defun org-agenda-clock-out ()
  8618. "Stop the currently running clock."
  8619. (interactive)
  8620. (unless (marker-buffer org-clock-marker)
  8621. (error "No running clock"))
  8622. (let ((marker (make-marker)) (col (current-column)) newhead)
  8623. (org-with-remote-undo (marker-buffer org-clock-marker)
  8624. (with-current-buffer (marker-buffer org-clock-marker)
  8625. (save-excursion
  8626. (save-restriction
  8627. (widen)
  8628. (goto-char org-clock-marker)
  8629. (org-back-to-heading t)
  8630. (move-marker marker (point))
  8631. (org-clock-out)
  8632. (setq newhead (org-get-heading))))))
  8633. (org-agenda-change-all-lines newhead marker)
  8634. (move-marker marker nil)
  8635. (org-move-to-column col)
  8636. (org-agenda-unmark-clocking-task)))
  8637. (defun org-agenda-clock-cancel (&optional arg)
  8638. "Cancel the currently running clock."
  8639. (interactive "P")
  8640. (unless (marker-buffer org-clock-marker)
  8641. (user-error "No running clock"))
  8642. (org-with-remote-undo (marker-buffer org-clock-marker)
  8643. (org-clock-cancel)))
  8644. (defun org-agenda-clock-goto ()
  8645. "Jump to the currently clocked in task within the agenda.
  8646. If the currently clocked in task is not listed in the agenda
  8647. buffer, display it in another window."
  8648. (interactive)
  8649. (let (pos)
  8650. (mapc (lambda (o)
  8651. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8652. (setq pos (overlay-start o))))
  8653. (overlays-in (point-min) (point-max)))
  8654. (cond (pos (goto-char pos))
  8655. ;; If the currently clocked entry is not in the agenda
  8656. ;; buffer, we visit it in another window:
  8657. (org-clock-current-task
  8658. (org-switch-to-buffer-other-window (org-clock-goto)))
  8659. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8660. (defun org-agenda-diary-entry-in-org-file ()
  8661. "Make a diary entry in the file `org-agenda-diary-file'."
  8662. (let (d1 d2 char (text "") dp1 dp2)</