org-agenda.el 392 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139
  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 general tags/property/todo match agenda view."
  589. :tag "Org Agenda Match 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-overlays
  1836. org-agenda-tag-filter
  1837. org-agenda-cat-filter-overlays
  1838. org-agenda-category-filter
  1839. org-agenda-re-filter-overlays
  1840. org-agenda-regexp-filter
  1841. org-agenda-markers
  1842. org-agenda-last-search-view-search-was-boolean
  1843. org-agenda-filtered-by-category
  1844. org-agenda-filter-form
  1845. org-agenda-cycle-counter
  1846. org-agenda-last-prefix-arg)
  1847. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1848. (defun org-agenda-mode ()
  1849. "Mode for time-sorted view on action items in Org-mode files.
  1850. The following commands are available:
  1851. \\{org-agenda-mode-map}"
  1852. (interactive)
  1853. (cond (org-agenda-doing-sticky-redo
  1854. ;; Refreshing sticky agenda-buffer
  1855. ;;
  1856. ;; Preserve the value of `org-agenda-local-vars' variables,
  1857. ;; while letting `kill-all-local-variables' kill the rest
  1858. (let ((save (buffer-local-variables)))
  1859. (kill-all-local-variables)
  1860. (mapc 'make-local-variable org-agenda-local-vars)
  1861. (dolist (elem save)
  1862. (let ((var (car elem))
  1863. (val (cdr elem)))
  1864. (when (and val
  1865. (member var org-agenda-local-vars))
  1866. (set var val)))))
  1867. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1868. (org-agenda-sticky
  1869. ;; Creating a sticky Agenda buffer for the first time
  1870. (kill-all-local-variables)
  1871. (mapc 'make-local-variable org-agenda-local-vars)
  1872. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1873. (t
  1874. ;; Creating a non-sticky agenda buffer
  1875. (kill-all-local-variables)
  1876. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1877. (setq org-agenda-undo-list nil
  1878. org-agenda-pending-undo-list nil
  1879. org-agenda-bulk-marked-entries nil)
  1880. (setq major-mode 'org-agenda-mode)
  1881. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1882. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1883. (setq mode-name "Org-Agenda")
  1884. (use-local-map org-agenda-mode-map)
  1885. (easy-menu-add org-agenda-menu)
  1886. (if org-startup-truncated (setq truncate-lines t))
  1887. (org-set-local 'line-move-visual nil)
  1888. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1889. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1890. ;; Make sure properties are removed when copying text
  1891. (org-add-hook 'filter-buffer-substring-functions
  1892. (lambda (fun start end delete)
  1893. (substring-no-properties (funcall fun start end delete)))
  1894. nil t)
  1895. (unless org-agenda-keep-modes
  1896. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1897. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1898. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1899. org-agenda-show-log org-agenda-start-with-log-mode))
  1900. (easy-menu-change
  1901. '("Agenda") "Agenda Files"
  1902. (append
  1903. (list
  1904. (vector
  1905. (if (get 'org-agenda-files 'org-restrict)
  1906. "Restricted to single file"
  1907. "Edit File List")
  1908. '(org-edit-agenda-file-list)
  1909. (not (get 'org-agenda-files 'org-restrict)))
  1910. "--")
  1911. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1912. (org-agenda-set-mode-name)
  1913. (apply
  1914. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1915. (list 'org-agenda-mode-hook)))
  1916. (substitute-key-definition 'undo 'org-agenda-undo
  1917. org-agenda-mode-map global-map)
  1918. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1919. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1920. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1921. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1922. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1923. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1924. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1925. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1926. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1927. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1928. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1929. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1930. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1931. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1932. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1933. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1934. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1935. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1936. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1937. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1938. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1939. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1940. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1941. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1942. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1943. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1944. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1945. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1946. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1947. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1948. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1949. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1950. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1951. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1952. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1953. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1954. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1955. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1956. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1957. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1958. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1959. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1960. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1961. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1962. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1963. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1964. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1965. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1966. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1967. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1968. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1969. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1970. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1971. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1972. (while l (org-defkey org-agenda-mode-map
  1973. (int-to-string (pop l)) 'digit-argument)))
  1974. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1975. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1976. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1977. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1978. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1979. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1980. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1981. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1982. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1983. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1984. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1985. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1986. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1987. 'org-clock-modify-effort-estimate)
  1988. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1989. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1990. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1991. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1992. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1993. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1994. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1995. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1996. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1997. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1998. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1999. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2000. (substitute-key-definition 'next-line 'org-agenda-next-line
  2001. org-agenda-mode-map global-map)
  2002. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2003. org-agenda-mode-map global-map)
  2004. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2005. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2006. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2007. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2008. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2009. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2010. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2011. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2012. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2013. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2014. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2015. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2016. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2017. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2018. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2019. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2021. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2022. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2023. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2024. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2025. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2026. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2027. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2028. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2029. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2030. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2031. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2032. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2033. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2034. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2035. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2036. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2037. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2038. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2039. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2040. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2041. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2042. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2043. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2044. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2045. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2046. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2047. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2048. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2049. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2050. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2051. (define-key org-agenda-mode-map [remap forward-paragraph] 'org-agenda-forward-block)
  2052. (define-key org-agenda-mode-map [remap backward-paragraph] 'org-agenda-backward-block)
  2053. (when org-agenda-mouse-1-follows-link
  2054. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2055. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2056. '("Agenda"
  2057. ("Agenda Files")
  2058. "--"
  2059. ("Agenda Dates"
  2060. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2061. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2062. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2063. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2064. "--"
  2065. ("View"
  2066. ["Day View" org-agenda-day-view
  2067. :active (org-agenda-check-type nil 'agenda)
  2068. :style radio :selected (eq org-agenda-current-span 'day)
  2069. :keys "v d (or just d)"]
  2070. ["Week View" org-agenda-week-view
  2071. :active (org-agenda-check-type nil 'agenda)
  2072. :style radio :selected (eq org-agenda-current-span 'week)
  2073. :keys "v w"]
  2074. ["Fortnight View" org-agenda-fortnight-view
  2075. :active (org-agenda-check-type nil 'agenda)
  2076. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2077. :keys "v f"]
  2078. ["Month View" org-agenda-month-view
  2079. :active (org-agenda-check-type nil 'agenda)
  2080. :style radio :selected (eq org-agenda-current-span 'month)
  2081. :keys "v m"]
  2082. ["Year View" org-agenda-year-view
  2083. :active (org-agenda-check-type nil 'agenda)
  2084. :style radio :selected (eq org-agenda-current-span 'year)
  2085. :keys "v y"]
  2086. "--"
  2087. ["Include Diary" org-agenda-toggle-diary
  2088. :style toggle :selected org-agenda-include-diary
  2089. :active (org-agenda-check-type nil 'agenda)]
  2090. ["Include Deadlines" org-agenda-toggle-deadlines
  2091. :style toggle :selected org-agenda-include-deadlines
  2092. :active (org-agenda-check-type nil 'agenda)]
  2093. ["Use Time Grid" org-agenda-toggle-time-grid
  2094. :style toggle :selected org-agenda-use-time-grid
  2095. :active (org-agenda-check-type nil 'agenda)]
  2096. "--"
  2097. ["Show clock report" org-agenda-clockreport-mode
  2098. :style toggle :selected org-agenda-clockreport-mode
  2099. :active (org-agenda-check-type nil 'agenda)]
  2100. ["Show some entry text" org-agenda-entry-text-mode
  2101. :style toggle :selected org-agenda-entry-text-mode
  2102. :active t]
  2103. "--"
  2104. ["Show Logbook entries" org-agenda-log-mode
  2105. :style toggle :selected org-agenda-show-log
  2106. :active (org-agenda-check-type nil 'agenda 'timeline)
  2107. :keys "v l (or just l)"]
  2108. ["Include archived trees" org-agenda-archives-mode
  2109. :style toggle :selected org-agenda-archives-mode :active t
  2110. :keys "v a"]
  2111. ["Include archive files" (org-agenda-archives-mode t)
  2112. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2113. :keys "v A"]
  2114. "--"
  2115. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2116. ["Write view to file" org-agenda-write t]
  2117. ["Rebuild buffer" org-agenda-redo t]
  2118. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2119. "--"
  2120. ["Show original entry" org-agenda-show t]
  2121. ["Go To (other window)" org-agenda-goto t]
  2122. ["Go To (this window)" org-agenda-switch-to t]
  2123. ["Capture with cursor date" org-agenda-capture t]
  2124. ["Follow Mode" org-agenda-follow-mode
  2125. :style toggle :selected org-agenda-follow-mode :active t]
  2126. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2127. "--"
  2128. ("TODO"
  2129. ["Cycle TODO" org-agenda-todo t]
  2130. ["Next TODO set" org-agenda-todo-nextset t]
  2131. ["Previous TODO set" org-agenda-todo-previousset t]
  2132. ["Add note" org-agenda-add-note t])
  2133. ("Archive/Refile/Delete"
  2134. ["Archive default" org-agenda-archive-default t]
  2135. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2136. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2137. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2138. ["Archive subtree" org-agenda-archive t]
  2139. "--"
  2140. ["Refile" org-agenda-refile t]
  2141. "--"
  2142. ["Delete subtree" org-agenda-kill t])
  2143. ("Bulk action"
  2144. ["Mark entry" org-agenda-bulk-mark t]
  2145. ["Mark all" org-agenda-bulk-mark-all t]
  2146. ["Unmark entry" org-agenda-bulk-unmark t]
  2147. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2148. ["Toggle mark" org-agenda-bulk-toggle t]
  2149. ["Toggle all" org-agenda-bulk-toggle-all t]
  2150. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2151. ["Act on all marked" org-agenda-bulk-action t]
  2152. "--"
  2153. ("Tags and Properties"
  2154. ["Show all Tags" org-agenda-show-tags t]
  2155. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2156. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2157. "--"
  2158. ["Column View" org-columns t])
  2159. ("Deadline/Schedule"
  2160. ["Schedule" org-agenda-schedule t]
  2161. ["Set Deadline" org-agenda-deadline t]
  2162. "--"
  2163. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2164. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2165. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2166. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2167. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2168. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2169. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2170. ("Clock and Effort"
  2171. ["Clock in" org-agenda-clock-in t]
  2172. ["Clock out" org-agenda-clock-out t]
  2173. ["Clock cancel" org-agenda-clock-cancel t]
  2174. ["Goto running clock" org-clock-goto t]
  2175. "--"
  2176. ["Set Effort" org-agenda-set-effort t]
  2177. ["Change clocked effort" org-clock-modify-effort-estimate
  2178. (org-clock-is-active)])
  2179. ("Priority"
  2180. ["Set Priority" org-agenda-priority t]
  2181. ["Increase Priority" org-agenda-priority-up t]
  2182. ["Decrease Priority" org-agenda-priority-down t]
  2183. ["Show Priority" org-show-priority t])
  2184. ("Calendar/Diary"
  2185. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2186. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2187. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2188. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2189. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2190. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2191. "--"
  2192. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2193. "--"
  2194. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2195. "--"
  2196. ("MobileOrg"
  2197. ["Push Files and Views" org-mobile-push t]
  2198. ["Get Captured and Flagged" org-mobile-pull t]
  2199. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2200. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2201. "--"
  2202. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2203. "--"
  2204. ["Quit" org-agenda-quit t]
  2205. ["Exit and Release Buffers" org-agenda-exit t]
  2206. ))
  2207. ;;; Agenda undo
  2208. (defvar org-agenda-allow-remote-undo t
  2209. "Non-nil means allow remote undo from the agenda buffer.")
  2210. (defvar org-agenda-undo-has-started-in nil
  2211. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2212. (defun org-agenda-undo ()
  2213. "Undo a remote editing step in the agenda.
  2214. This undoes changes both in the agenda buffer and in the remote buffer
  2215. that have been changed along."
  2216. (interactive)
  2217. (or org-agenda-allow-remote-undo
  2218. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2219. (if (not (eq this-command last-command))
  2220. (setq org-agenda-undo-has-started-in nil
  2221. org-agenda-pending-undo-list org-agenda-undo-list))
  2222. (if (not org-agenda-pending-undo-list)
  2223. (user-error "No further undo information"))
  2224. (let* ((entry (pop org-agenda-pending-undo-list))
  2225. buf line cmd rembuf)
  2226. (setq cmd (pop entry) line (pop entry))
  2227. (setq rembuf (nth 2 entry))
  2228. (org-with-remote-undo rembuf
  2229. (while (bufferp (setq buf (pop entry)))
  2230. (if (pop entry)
  2231. (with-current-buffer buf
  2232. (let ((last-undo-buffer buf)
  2233. (inhibit-read-only t))
  2234. (unless (memq buf org-agenda-undo-has-started-in)
  2235. (push buf org-agenda-undo-has-started-in)
  2236. (make-local-variable 'pending-undo-list)
  2237. (undo-start))
  2238. (while (and pending-undo-list
  2239. (listp pending-undo-list)
  2240. (not (car pending-undo-list)))
  2241. (pop pending-undo-list))
  2242. (undo-more 1))))))
  2243. (org-goto-line line)
  2244. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2245. (defun org-verify-change-for-undo (l1 l2)
  2246. "Verify that a real change occurred between the undo lists L1 and L2."
  2247. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2248. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2249. (not (eq l1 l2)))
  2250. ;;; Agenda dispatch
  2251. (defvar org-agenda-restrict-begin (make-marker))
  2252. (defvar org-agenda-restrict-end (make-marker))
  2253. (defvar org-agenda-last-dispatch-buffer nil)
  2254. (defvar org-agenda-overriding-restriction nil)
  2255. (defcustom org-agenda-custom-commands-contexts nil
  2256. "Alist of custom agenda keys and contextual rules.
  2257. For example, if you have a custom agenda command \"p\" and you
  2258. want this command to be accessible only from plain text files,
  2259. use this:
  2260. '((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2261. Here are the available contexts definitions:
  2262. in-file: command displayed only in matching files
  2263. in-mode: command displayed only in matching modes
  2264. not-in-file: command not displayed in matching files
  2265. not-in-mode: command not displayed in matching modes
  2266. in-buffer: command displayed only in matching buffers
  2267. not-in-buffer: command not displayed in matching buffers
  2268. [function]: a custom function taking no argument
  2269. If you define several checks, the agenda command will be
  2270. accessible if there is at least one valid check.
  2271. You can also bind a key to another agenda custom command
  2272. depending on contextual rules.
  2273. '((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2274. Here it means: in .txt files, use \"p\" as the key for the
  2275. agenda command otherwise associated with \"q\". (The command
  2276. originally associated with \"q\" is not displayed to avoid
  2277. duplicates.)"
  2278. :version "24.3"
  2279. :group 'org-agenda-custom-commands
  2280. :type '(repeat (list :tag "Rule"
  2281. (string :tag " Agenda key")
  2282. (string :tag "Replace by command")
  2283. (repeat :tag "Available when"
  2284. (choice
  2285. (cons :tag "Condition"
  2286. (choice
  2287. (const :tag "In file" in-file)
  2288. (const :tag "Not in file" not-in-file)
  2289. (const :tag "In buffer" in-buffer)
  2290. (const :tag "Not in buffer" not-in-buffer)
  2291. (const :tag "In mode" in-mode)
  2292. (const :tag "Not in mode" not-in-mode))
  2293. (regexp))
  2294. (function :tag "Custom function"))))))
  2295. (defcustom org-agenda-max-entries nil
  2296. "Maximum number of entries to display in an agenda.
  2297. This can be nil (no limit) or an integer or an alist of agenda
  2298. types with an associated number of entries to display in this
  2299. type."
  2300. :version "24.4"
  2301. :package-version '(Org . "8.0")
  2302. :group 'org-agenda-custom-commands
  2303. :type '(choice (symbol :tag "No limit" nil)
  2304. (integer :tag "Max number of entries")
  2305. (repeat
  2306. (cons (choice :tag "Agenda type"
  2307. (const agenda)
  2308. (const todo)
  2309. (const tags)
  2310. (const search)
  2311. (const timeline))
  2312. (integer :tag "Max number of entries")))))
  2313. (defcustom org-agenda-max-todos nil
  2314. "Maximum number of TODOs to display in an agenda.
  2315. This can be nil (no limit) or an integer or an alist of agenda
  2316. types with an associated number of entries to display in this
  2317. type."
  2318. :version "24.4"
  2319. :package-version '(Org . "8.0")
  2320. :group 'org-agenda-custom-commands
  2321. :type '(choice (symbol :tag "No limit" nil)
  2322. (integer :tag "Max number of entries")
  2323. (repeat
  2324. (cons (choice :tag "Agenda type"
  2325. (const agenda)
  2326. (const todo)
  2327. (const tags)
  2328. (const search)
  2329. (const timeline))
  2330. (integer :tag "Max number of entries")))))
  2331. (defcustom org-agenda-max-tags nil
  2332. "Maximum number of tagged entries to display in an agenda.
  2333. This can be nil (no limit) or an integer or an alist of agenda
  2334. types with an associated number of entries to display in this
  2335. type."
  2336. :version "24.4"
  2337. :package-version '(Org . "8.0")
  2338. :group 'org-agenda-custom-commands
  2339. :type '(choice (symbol :tag "No limit" nil)
  2340. (integer :tag "Max number of entries")
  2341. (repeat
  2342. (cons (choice :tag "Agenda type"
  2343. (const agenda)
  2344. (const todo)
  2345. (const tags)
  2346. (const search)
  2347. (const timeline))
  2348. (integer :tag "Max number of entries")))))
  2349. (defcustom org-agenda-max-effort nil
  2350. "Maximum cumulated effort duration for the agenda.
  2351. This can be nil (no limit) or a number of minutes (as an integer)
  2352. or an alist of agenda types with an associated number of minutes
  2353. to limit entries to in this type."
  2354. :version "24.4"
  2355. :package-version '(Org . "8.0")
  2356. :group 'org-agenda-custom-commands
  2357. :type '(choice (symbol :tag "No limit" nil)
  2358. (integer :tag "Max number of entries")
  2359. (repeat
  2360. (cons (choice :tag "Agenda type"
  2361. (const agenda)
  2362. (const todo)
  2363. (const tags)
  2364. (const search)
  2365. (const timeline))
  2366. (integer :tag "Max number of entries")))))
  2367. (defvar org-keys nil)
  2368. (defvar org-match nil)
  2369. ;;;###autoload
  2370. (defun org-agenda (&optional arg org-keys restriction)
  2371. "Dispatch agenda commands to collect entries to the agenda buffer.
  2372. Prompts for a command to execute. Any prefix arg will be passed
  2373. on to the selected command. The default selections are:
  2374. a Call `org-agenda-list' to display the agenda for current day or week.
  2375. t Call `org-todo-list' to display the global todo list.
  2376. T Call `org-todo-list' to display the global todo list, select only
  2377. entries with a specific TODO keyword (the user gets a prompt).
  2378. m Call `org-tags-view' to display headlines with tags matching
  2379. a condition (the user is prompted for the condition).
  2380. M Like `m', but select only TODO entries, no ordinary headlines.
  2381. L Create a timeline for the current buffer.
  2382. e Export views to associated files.
  2383. s Search entries for keywords.
  2384. S Search entries for keywords, only with TODO keywords.
  2385. / Multi occur across all agenda files and also files listed
  2386. in `org-agenda-text-search-extra-files'.
  2387. < Restrict agenda commands to buffer, subtree, or region.
  2388. Press several times to get the desired effect.
  2389. > Remove a previous restriction.
  2390. # List \"stuck\" projects.
  2391. ! Configure what \"stuck\" means.
  2392. C Configure custom agenda commands.
  2393. More commands can be added by configuring the variable
  2394. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2395. searches can be pre-defined in this way.
  2396. If the current buffer is in Org-mode and visiting a file, you can also
  2397. first press `<' once to indicate that the agenda should be temporarily
  2398. \(until the next use of \\[org-agenda]) restricted to the current file.
  2399. Pressing `<' twice means to restrict to the current subtree or region
  2400. \(if active)."
  2401. (interactive "P")
  2402. (catch 'exit
  2403. (let* ((prefix-descriptions nil)
  2404. (org-agenda-buffer-name org-agenda-buffer-name)
  2405. (org-agenda-window-setup (if (equal (buffer-name)
  2406. org-agenda-buffer-name)
  2407. 'current-window
  2408. org-agenda-window-setup))
  2409. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2410. (org-agenda-custom-commands
  2411. ;; normalize different versions
  2412. (delq nil
  2413. (mapcar
  2414. (lambda (x)
  2415. (cond ((stringp (cdr x))
  2416. (push x prefix-descriptions)
  2417. nil)
  2418. ((stringp (nth 1 x)) x)
  2419. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2420. (t (cons (car x) (cons "" (cdr x))))))
  2421. org-agenda-custom-commands)))
  2422. (org-agenda-custom-commands
  2423. (org-contextualize-keys
  2424. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2425. (buf (current-buffer))
  2426. (bfn (buffer-file-name (buffer-base-buffer)))
  2427. entry key type org-match lprops ans)
  2428. ;; Turn off restriction unless there is an overriding one,
  2429. (unless org-agenda-overriding-restriction
  2430. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2431. ;; There is a request to keep the file list in place
  2432. (put 'org-agenda-files 'org-restrict nil))
  2433. (setq org-agenda-restrict nil)
  2434. (move-marker org-agenda-restrict-begin nil)
  2435. (move-marker org-agenda-restrict-end nil))
  2436. ;; Delete old local properties
  2437. (put 'org-agenda-redo-command 'org-lprops nil)
  2438. ;; Delete previously set last-arguments
  2439. (put 'org-agenda-redo-command 'last-args nil)
  2440. ;; Remember where this call originated
  2441. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2442. (unless org-keys
  2443. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2444. org-keys (car ans)
  2445. restriction (cdr ans)))
  2446. ;; If we have sticky agenda buffers, set a name for the buffer,
  2447. ;; depending on the invoking keys. The user may still set this
  2448. ;; as a command option, which will overwrite what we do here.
  2449. (if org-agenda-sticky
  2450. (setq org-agenda-buffer-name
  2451. (format "*Org Agenda(%s)*" org-keys)))
  2452. ;; Establish the restriction, if any
  2453. (when (and (not org-agenda-overriding-restriction) restriction)
  2454. (put 'org-agenda-files 'org-restrict (list bfn))
  2455. (cond
  2456. ((eq restriction 'region)
  2457. (setq org-agenda-restrict (current-buffer))
  2458. (move-marker org-agenda-restrict-begin (region-beginning))
  2459. (move-marker org-agenda-restrict-end (region-end)))
  2460. ((eq restriction 'subtree)
  2461. (save-excursion
  2462. (setq org-agenda-restrict (current-buffer))
  2463. (org-back-to-heading t)
  2464. (move-marker org-agenda-restrict-begin (point))
  2465. (move-marker org-agenda-restrict-end
  2466. (progn (org-end-of-subtree t)))))))
  2467. ;; For example the todo list should not need it (but does...)
  2468. (cond
  2469. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2470. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2471. (progn
  2472. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2473. lprops (nth 4 entry))
  2474. (if org-agenda-sticky
  2475. (setq org-agenda-buffer-name
  2476. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2477. (format "*Org Agenda(%s)*" org-keys))))
  2478. (put 'org-agenda-redo-command 'org-lprops lprops)
  2479. (cond
  2480. ((eq type 'agenda)
  2481. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2482. ((eq type 'agenda*)
  2483. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2484. ((eq type 'alltodo)
  2485. (org-let lprops '(org-todo-list current-prefix-arg)))
  2486. ((eq type 'search)
  2487. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2488. ((eq type 'stuck)
  2489. (org-let lprops '(org-agenda-list-stuck-projects
  2490. current-prefix-arg)))
  2491. ((eq type 'tags)
  2492. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2493. ((eq type 'tags-todo)
  2494. (org-let lprops '(org-tags-view '(4) org-match)))
  2495. ((eq type 'todo)
  2496. (org-let lprops '(org-todo-list org-match)))
  2497. ((eq type 'tags-tree)
  2498. (org-check-for-org-mode)
  2499. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2500. ((eq type 'todo-tree)
  2501. (org-check-for-org-mode)
  2502. (org-let lprops
  2503. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2504. (regexp-quote org-match) "\\>"))))
  2505. ((eq type 'occur-tree)
  2506. (org-check-for-org-mode)
  2507. (org-let lprops '(org-occur org-match)))
  2508. ((functionp type)
  2509. (org-let lprops '(funcall type org-match)))
  2510. ((fboundp type)
  2511. (org-let lprops '(funcall type org-match)))
  2512. (t (user-error "Invalid custom agenda command type %s" type))))
  2513. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2514. ((equal org-keys "C")
  2515. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2516. (customize-variable 'org-agenda-custom-commands))
  2517. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2518. ((equal org-keys "s") (call-interactively 'org-search-view))
  2519. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2520. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2521. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2522. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2523. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2524. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2525. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2526. (org-add-hook
  2527. 'post-command-hook
  2528. (lambda ()
  2529. (unless (current-message)
  2530. (let* ((m (org-agenda-get-any-marker))
  2531. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2532. (when note
  2533. (message (concat
  2534. "FLAGGING-NOTE ([?] for more info): "
  2535. (org-add-props
  2536. (replace-regexp-in-string
  2537. "\\\\n" "//"
  2538. (copy-sequence note))
  2539. nil 'face 'org-warning)))))))
  2540. t t))
  2541. ((equal org-keys "L")
  2542. (unless (derived-mode-p 'org-mode)
  2543. (user-error "This is not an Org-mode file"))
  2544. (unless restriction
  2545. (put 'org-agenda-files 'org-restrict (list bfn))
  2546. (org-call-with-arg 'org-timeline arg)))
  2547. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2548. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2549. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2550. (t (user-error "Invalid agenda key"))))))
  2551. (defvar org-agenda-multi)
  2552. (defun org-agenda-append-agenda ()
  2553. "Append another agenda view to the current one.
  2554. This function allows interactive building of block agendas.
  2555. Agenda views are separated by `org-agenda-block-separator'."
  2556. (interactive)
  2557. (unless (derived-mode-p 'org-agenda-mode)
  2558. (user-error "Can only append from within agenda buffer"))
  2559. (let ((org-agenda-multi t))
  2560. (org-agenda)
  2561. (widen)
  2562. (org-agenda-finalize)
  2563. (setq buffer-read-only t)
  2564. (org-agenda-fit-window-to-buffer)))
  2565. (defun org-agenda-normalize-custom-commands (cmds)
  2566. "Normalize custom commands CMDS."
  2567. (delq nil
  2568. (mapcar
  2569. (lambda (x)
  2570. (cond ((stringp (cdr x)) nil)
  2571. ((stringp (nth 1 x)) x)
  2572. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2573. (t (cons (car x) (cons "" (cdr x))))))
  2574. cmds)))
  2575. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2576. "The user interface for selecting an agenda command."
  2577. (catch 'exit
  2578. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2579. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2580. (region-p (org-region-active-p))
  2581. (custom org-agenda-custom-commands)
  2582. (selstring "")
  2583. restriction second-time
  2584. c entry key type match prefixes rmheader header-end custom1 desc
  2585. line lines left right n n1)
  2586. (save-window-excursion
  2587. (delete-other-windows)
  2588. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2589. (erase-buffer)
  2590. (insert (eval-when-compile
  2591. (let ((header
  2592. "Press key for an agenda command: < Buffer, subtree/region restriction
  2593. -------------------------------- > Remove restriction
  2594. a Agenda for current week or day e Export agenda views
  2595. t List of all TODO entries T Entries with special TODO kwd
  2596. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2597. s Search for keywords S Like s, but only TODO entries
  2598. L Timeline for current buffer # List stuck projects (!=configure)
  2599. / Multi-occur C Configure custom agenda commands
  2600. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2601. ")
  2602. (start 0))
  2603. (while (string-match
  2604. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2605. header start)
  2606. (setq start (match-end 0))
  2607. (add-text-properties (match-beginning 2) (match-end 2)
  2608. '(face bold) header))
  2609. header)))
  2610. (setq header-end (point-marker))
  2611. (while t
  2612. (setq custom1 custom)
  2613. (when (eq rmheader t)
  2614. (org-goto-line 1)
  2615. (re-search-forward ":" nil t)
  2616. (delete-region (match-end 0) (point-at-eol))
  2617. (forward-char 1)
  2618. (looking-at "-+")
  2619. (delete-region (match-end 0) (point-at-eol))
  2620. (move-marker header-end (match-end 0)))
  2621. (goto-char header-end)
  2622. (delete-region (point) (point-max))
  2623. ;; Produce all the lines that describe custom commands and prefixes
  2624. (setq lines nil)
  2625. (while (setq entry (pop custom1))
  2626. (setq key (car entry) desc (nth 1 entry)
  2627. type (nth 2 entry)
  2628. match (nth 3 entry))
  2629. (if (> (length key) 1)
  2630. (add-to-list 'prefixes (string-to-char key))
  2631. (setq line
  2632. (format
  2633. "%-4s%-14s"
  2634. (org-add-props (copy-sequence key)
  2635. '(face bold))
  2636. (cond
  2637. ((string-match "\\S-" desc) desc)
  2638. ((eq type 'agenda) "Agenda for current week or day")
  2639. ((eq type 'agenda*) "Appointments for current week or day")
  2640. ((eq type 'alltodo) "List of all TODO entries")
  2641. ((eq type 'search) "Word search")
  2642. ((eq type 'stuck) "List of stuck projects")
  2643. ((eq type 'todo) "TODO keyword")
  2644. ((eq type 'tags) "Tags query")
  2645. ((eq type 'tags-todo) "Tags (TODO)")
  2646. ((eq type 'tags-tree) "Tags tree")
  2647. ((eq type 'todo-tree) "TODO kwd tree")
  2648. ((eq type 'occur-tree) "Occur tree")
  2649. ((functionp type) (if (symbolp type)
  2650. (symbol-name type)
  2651. "Lambda expression"))
  2652. (t "???"))))
  2653. (if org-agenda-menu-show-matcher
  2654. (setq line
  2655. (concat line ": "
  2656. (cond
  2657. ((stringp match)
  2658. (setq match (copy-sequence match))
  2659. (org-add-props match nil 'face 'org-warning))
  2660. ((listp type)
  2661. (format "set of %d commands" (length type))))))
  2662. (if (org-string-nw-p match)
  2663. (add-text-properties
  2664. 0 (length line) (list 'help-echo
  2665. (concat "Matcher: " match)) line)))
  2666. (push line lines)))
  2667. (setq lines (nreverse lines))
  2668. (when prefixes
  2669. (mapc (lambda (x)
  2670. (push
  2671. (format "%s %s"
  2672. (org-add-props (char-to-string x)
  2673. nil 'face 'bold)
  2674. (or (cdr (assoc (concat selstring
  2675. (char-to-string x))
  2676. prefix-descriptions))
  2677. "Prefix key"))
  2678. lines))
  2679. prefixes))
  2680. ;; Check if we should display in two columns
  2681. (if org-agenda-menu-two-columns
  2682. (progn
  2683. (setq n (length lines)
  2684. n1 (+ (/ n 2) (mod n 2))
  2685. right (nthcdr n1 lines)
  2686. left (copy-sequence lines))
  2687. (setcdr (nthcdr (1- n1) left) nil))
  2688. (setq left lines right nil))
  2689. (while left
  2690. (insert "\n" (pop left))
  2691. (when right
  2692. (if (< (current-column) 40)
  2693. (move-to-column 40 t)
  2694. (insert " "))
  2695. (insert (pop right))))
  2696. ;; Make the window the right size
  2697. (goto-char (point-min))
  2698. (if second-time
  2699. (if (not (pos-visible-in-window-p (point-max)))
  2700. (org-fit-window-to-buffer))
  2701. (setq second-time t)
  2702. (org-fit-window-to-buffer))
  2703. ;; Ask for selection
  2704. (message "Press key for agenda command%s:"
  2705. (if (or restrict-ok org-agenda-overriding-restriction)
  2706. (if org-agenda-overriding-restriction
  2707. " (restriction lock active)"
  2708. (if restriction
  2709. (format " (restricted to %s)" restriction)
  2710. " (unrestricted)"))
  2711. ""))
  2712. (setq c (read-char-exclusive))
  2713. (message "")
  2714. (cond
  2715. ((assoc (char-to-string c) custom)
  2716. (setq selstring (concat selstring (char-to-string c)))
  2717. (throw 'exit (cons selstring restriction)))
  2718. ((memq c prefixes)
  2719. (setq selstring (concat selstring (char-to-string c))
  2720. prefixes nil
  2721. rmheader (or rmheader t)
  2722. custom (delq nil (mapcar
  2723. (lambda (x)
  2724. (if (or (= (length (car x)) 1)
  2725. (/= (string-to-char (car x)) c))
  2726. nil
  2727. (cons (substring (car x) 1) (cdr x))))
  2728. custom))))
  2729. ((eq c ?*)
  2730. (call-interactively 'org-toggle-sticky-agenda)
  2731. (sit-for 2))
  2732. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2733. (message "Restriction is only possible in Org-mode buffers")
  2734. (ding) (sit-for 1))
  2735. ((eq c ?1)
  2736. (org-agenda-remove-restriction-lock 'noupdate)
  2737. (setq restriction 'buffer))
  2738. ((eq c ?0)
  2739. (org-agenda-remove-restriction-lock 'noupdate)
  2740. (setq restriction (if region-p 'region 'subtree)))
  2741. ((eq c ?<)
  2742. (org-agenda-remove-restriction-lock 'noupdate)
  2743. (setq restriction
  2744. (cond
  2745. ((eq restriction 'buffer)
  2746. (if region-p 'region 'subtree))
  2747. ((memq restriction '(subtree region))
  2748. nil)
  2749. (t 'buffer))))
  2750. ((eq c ?>)
  2751. (org-agenda-remove-restriction-lock 'noupdate)
  2752. (setq restriction nil))
  2753. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2754. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2755. ((and (> (length selstring) 0) (eq c ?\d))
  2756. (delete-window)
  2757. (org-agenda-get-restriction-and-command prefix-descriptions))
  2758. ((equal c ?q) (error "Abort"))
  2759. (t (user-error "Invalid key %c" c))))))))
  2760. (defun org-agenda-fit-window-to-buffer ()
  2761. "Fit the window to the buffer size."
  2762. (and (memq org-agenda-window-setup '(reorganize-frame))
  2763. (fboundp 'fit-window-to-buffer)
  2764. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2765. (= (car org-agenda-window-frame-fractions) 1.0))
  2766. (delete-other-windows)
  2767. (org-fit-window-to-buffer
  2768. nil
  2769. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2770. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2771. (defvar org-cmd nil)
  2772. (defvar org-agenda-overriding-cmd nil)
  2773. (defvar org-agenda-overriding-arguments nil)
  2774. (defvar org-agenda-overriding-cmd-arguments nil)
  2775. (defun org-agenda-run-series (name series)
  2776. "Run agenda NAME as a SERIES of agenda commands."
  2777. (org-let (nth 1 series) '(org-agenda-prepare name))
  2778. ;; We need to reset agenda markers here, because when constructing a
  2779. ;; block agenda, the individual blocks do not do that.
  2780. (org-agenda-reset-markers)
  2781. (let* ((org-agenda-multi t)
  2782. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2783. (cmds (car series))
  2784. (gprops (nth 1 series))
  2785. match ;; The byte compiler incorrectly complains about this. Keep it!
  2786. org-cmd type lprops)
  2787. (while (setq org-cmd (pop cmds))
  2788. (setq type (car org-cmd)
  2789. match (eval (nth 1 org-cmd))
  2790. lprops (nth 2 org-cmd))
  2791. (let ((org-agenda-overriding-arguments
  2792. (if (eq org-agenda-overriding-cmd org-cmd)
  2793. (or org-agenda-overriding-arguments
  2794. org-agenda-overriding-cmd-arguments))))
  2795. (cond
  2796. ((eq type 'agenda)
  2797. (org-let2 gprops lprops
  2798. '(call-interactively 'org-agenda-list)))
  2799. ((eq type 'agenda*)
  2800. (org-let2 gprops lprops
  2801. '(funcall 'org-agenda-list nil nil t)))
  2802. ((eq type 'alltodo)
  2803. (org-let2 gprops lprops
  2804. '(call-interactively 'org-todo-list)))
  2805. ((eq type 'search)
  2806. (org-let2 gprops lprops
  2807. '(org-search-view current-prefix-arg match nil)))
  2808. ((eq type 'stuck)
  2809. (org-let2 gprops lprops
  2810. '(call-interactively 'org-agenda-list-stuck-projects)))
  2811. ((eq type 'tags)
  2812. (org-let2 gprops lprops
  2813. '(org-tags-view current-prefix-arg match)))
  2814. ((eq type 'tags-todo)
  2815. (org-let2 gprops lprops
  2816. '(org-tags-view '(4) match)))
  2817. ((eq type 'todo)
  2818. (org-let2 gprops lprops
  2819. '(org-todo-list match)))
  2820. ((fboundp type)
  2821. (org-let2 gprops lprops
  2822. '(funcall type match)))
  2823. (t (error "Invalid type in command series")))))
  2824. (widen)
  2825. (let ((inhibit-read-only t))
  2826. (add-text-properties (point-min) (point-max)
  2827. `(org-series t org-series-redo-cmd ,redo)))
  2828. (setq org-agenda-redo-command redo)
  2829. (goto-char (point-min)))
  2830. (org-agenda-fit-window-to-buffer)
  2831. (org-let (nth 1 series) '(org-agenda-finalize)))
  2832. ;;;###autoload
  2833. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2834. "Run an agenda command in batch mode and send the result to STDOUT.
  2835. If CMD-KEY is a string of length 1, it is used as a key in
  2836. `org-agenda-custom-commands' and triggers this command. If it is a
  2837. longer string it is used as a tags/todo match string.
  2838. Parameters are alternating variable names and values that will be bound
  2839. before running the agenda command."
  2840. (org-eval-in-environment (org-make-parameter-alist parameters)
  2841. (let (org-agenda-sticky)
  2842. (if (> (length cmd-key) 2)
  2843. (org-tags-view nil cmd-key)
  2844. (org-agenda nil cmd-key))))
  2845. (set-buffer org-agenda-buffer-name)
  2846. (princ (buffer-string)))
  2847. (defvar org-agenda-info nil)
  2848. ;;;###autoload
  2849. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2850. "Run an agenda command in batch mode and send the result to STDOUT.
  2851. If CMD-KEY is a string of length 1, it is used as a key in
  2852. `org-agenda-custom-commands' and triggers this command. If it is a
  2853. longer string it is used as a tags/todo match string.
  2854. Parameters are alternating variable names and values that will be bound
  2855. before running the agenda command.
  2856. The output gives a line for each selected agenda item. Each
  2857. item is a list of comma-separated values, like this:
  2858. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2859. category The category of the item
  2860. head The headline, without TODO kwd, TAGS and PRIORITY
  2861. type The type of the agenda entry, can be
  2862. todo selected in TODO match
  2863. tagsmatch selected in tags match
  2864. diary imported from diary
  2865. deadline a deadline on given date
  2866. scheduled scheduled on given date
  2867. timestamp entry has timestamp on given date
  2868. closed entry was closed on given date
  2869. upcoming-deadline warning about deadline
  2870. past-scheduled forwarded scheduled item
  2871. block entry has date block including g. date
  2872. todo The todo keyword, if any
  2873. tags All tags including inherited ones, separated by colons
  2874. date The relevant date, like 2007-2-14
  2875. time The time, like 15:00-16:50
  2876. extra Sting with extra planning info
  2877. priority-l The priority letter if any was given
  2878. priority-n The computed numerical priority
  2879. agenda-day The day in the agenda where this is listed"
  2880. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2881. (org-make-parameter-alist parameters))
  2882. (if (> (length cmd-key) 2)
  2883. (org-tags-view nil cmd-key)
  2884. (org-agenda nil cmd-key)))
  2885. (set-buffer org-agenda-buffer-name)
  2886. (let* ((lines (org-split-string (buffer-string) "\n"))
  2887. line)
  2888. (while (setq line (pop lines))
  2889. (catch 'next
  2890. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2891. (setq org-agenda-info
  2892. (org-fix-agenda-info (text-properties-at 0 line)))
  2893. (princ
  2894. (mapconcat 'org-agenda-export-csv-mapper
  2895. '(org-category txt type todo tags date time extra
  2896. priority-letter priority agenda-day)
  2897. ","))
  2898. (princ "\n")))))
  2899. (defun org-fix-agenda-info (props)
  2900. "Make sure all properties on an agenda item have a canonical form.
  2901. This ensures the export commands can easily use it."
  2902. (let (tmp re)
  2903. (when (setq tmp (plist-get props 'tags))
  2904. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2905. (when (setq tmp (plist-get props 'date))
  2906. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2907. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2908. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2909. (setq tmp (calendar-date-string tmp)))
  2910. (setq props (plist-put props 'date tmp)))
  2911. (when (setq tmp (plist-get props 'day))
  2912. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2913. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2914. (setq tmp (calendar-date-string tmp)))
  2915. (setq props (plist-put props 'day tmp))
  2916. (setq props (plist-put props 'agenda-day tmp)))
  2917. (when (setq tmp (plist-get props 'txt))
  2918. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2919. (plist-put props 'priority-letter (match-string 1 tmp))
  2920. (setq tmp (replace-match "" t t tmp)))
  2921. (when (and (setq re (plist-get props 'org-todo-regexp))
  2922. (setq re (concat "\\`\\.*" re " ?"))
  2923. (string-match re tmp))
  2924. (plist-put props 'todo (match-string 1 tmp))
  2925. (setq tmp (replace-match "" t t tmp)))
  2926. (plist-put props 'txt tmp)))
  2927. props)
  2928. (defun org-agenda-export-csv-mapper (prop)
  2929. (let ((res (plist-get org-agenda-info prop)))
  2930. (setq res
  2931. (cond
  2932. ((not res) "")
  2933. ((stringp res) res)
  2934. (t (prin1-to-string res))))
  2935. (while (string-match "," res)
  2936. (setq res (replace-match ";" t t res)))
  2937. (org-trim res)))
  2938. ;;;###autoload
  2939. (defun org-store-agenda-views (&rest parameters)
  2940. "Store agenda views."
  2941. (interactive)
  2942. (eval (list 'org-batch-store-agenda-views)))
  2943. ;;;###autoload
  2944. (defmacro org-batch-store-agenda-views (&rest parameters)
  2945. "Run all custom agenda commands that have a file argument."
  2946. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2947. (pop-up-frames nil)
  2948. (dir default-directory)
  2949. (pars (org-make-parameter-alist parameters))
  2950. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2951. (save-window-excursion
  2952. (while cmds
  2953. (setq cmd (pop cmds)
  2954. thiscmdkey (car cmd)
  2955. thiscmdcmd (cdr cmd)
  2956. match (nth 2 thiscmdcmd)
  2957. bufname (if org-agenda-sticky
  2958. (or (and (stringp match)
  2959. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2960. (format "*Org Agenda(%s)*" thiscmdkey))
  2961. org-agenda-buffer-name)
  2962. cmd-or-set (nth 2 cmd)
  2963. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2964. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2965. (if (stringp files) (setq files (list files)))
  2966. (when files
  2967. (org-eval-in-environment (append org-agenda-exporter-settings
  2968. opts pars)
  2969. (org-agenda nil thiscmdkey))
  2970. (set-buffer bufname)
  2971. (while files
  2972. (org-eval-in-environment (append org-agenda-exporter-settings
  2973. opts pars)
  2974. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2975. (and (get-buffer bufname)
  2976. (kill-buffer bufname)))))))
  2977. (defvar org-agenda-current-span nil
  2978. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2979. (defun org-agenda-mark-header-line (pos)
  2980. "Mark the line at POS as an agenda structure header."
  2981. (save-excursion
  2982. (goto-char pos)
  2983. (put-text-property (point-at-bol) (point-at-eol)
  2984. 'org-agenda-structural-header t)
  2985. (when org-agenda-title-append
  2986. (put-text-property (point-at-bol) (point-at-eol)
  2987. 'org-agenda-title-append org-agenda-title-append))))
  2988. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2989. (defvar org-agenda-write-buffer-name "Agenda View")
  2990. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2991. "Write the current buffer (an agenda view) as a file.
  2992. Depending on the extension of the file name, plain text (.txt),
  2993. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2994. If the extension is .ics, run icalendar export over all files used
  2995. to construct the agenda and limit the export to entries listed in the
  2996. agenda now.
  2997. If the extension is .org, collect all subtrees corresponding to the
  2998. agenda entries and add them in an .org file.
  2999. With prefix argument OPEN, open the new file immediately.
  3000. If NOSETTINGS is given, do not scope the settings of
  3001. `org-agenda-exporter-settings' into the export commands. This is used when
  3002. the settings have already been scoped and we do not wish to overrule other,
  3003. higher priority settings.
  3004. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3005. (interactive "FWrite agenda to file: \nP")
  3006. (if (or (not (file-writable-p file))
  3007. (and (file-exists-p file)
  3008. (if (org-called-interactively-p 'any)
  3009. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3010. (user-error "Cannot write agenda to file %s" file))
  3011. (org-let (if nosettings nil org-agenda-exporter-settings)
  3012. '(save-excursion
  3013. (save-window-excursion
  3014. (org-agenda-mark-filtered-text)
  3015. (let ((bs (copy-sequence (buffer-string))) beg content)
  3016. (org-agenda-unmark-filtered-text)
  3017. (with-temp-buffer
  3018. (rename-buffer org-agenda-write-buffer-name t)
  3019. (set-buffer-modified-p nil)
  3020. (insert bs)
  3021. (org-agenda-remove-marked-text 'org-filtered)
  3022. (while (setq beg (text-property-any (point-min) (point-max)
  3023. 'org-filtered t))
  3024. (delete-region
  3025. beg (or (next-single-property-change beg 'org-filtered)
  3026. (point-max))))
  3027. (run-hooks 'org-agenda-before-write-hook)
  3028. (cond
  3029. ((org-bound-and-true-p org-mobile-creating-agendas)
  3030. (org-mobile-write-agenda-for-mobile file))
  3031. ((string-match "\\.org\\'" file)
  3032. (let (content p m message-log-max)
  3033. (goto-char (point-min))
  3034. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3035. (goto-char p)
  3036. (setq m (get-text-property (point) 'org-hd-marker))
  3037. (when m
  3038. (push (save-excursion
  3039. (set-buffer (marker-buffer m))
  3040. (goto-char m)
  3041. (org-copy-subtree 1 nil t t)
  3042. org-subtree-clip)
  3043. content)))
  3044. (find-file file)
  3045. (erase-buffer)
  3046. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3047. (write-file file)
  3048. (kill-buffer (current-buffer))
  3049. (message "Org file written to %s" file)))
  3050. ((string-match "\\.html?\\'" file)
  3051. (require 'htmlize)
  3052. (set-buffer (htmlize-buffer (current-buffer)))
  3053. (when org-agenda-export-html-style
  3054. ;; replace <style> section with org-agenda-export-html-style
  3055. (goto-char (point-min))
  3056. (kill-region (- (search-forward "<style") 6)
  3057. (search-forward "</style>"))
  3058. (insert org-agenda-export-html-style))
  3059. (write-file file)
  3060. (kill-buffer (current-buffer))
  3061. (message "HTML written to %s" file))
  3062. ((string-match "\\.ps\\'" file)
  3063. (require 'ps-print)
  3064. (ps-print-buffer-with-faces file)
  3065. (message "Postscript written to %s" file))
  3066. ((string-match "\\.pdf\\'" file)
  3067. (require 'ps-print)
  3068. (ps-print-buffer-with-faces
  3069. (concat (file-name-sans-extension file) ".ps"))
  3070. (call-process "ps2pdf" nil nil nil
  3071. (expand-file-name
  3072. (concat (file-name-sans-extension file) ".ps"))
  3073. (expand-file-name file))
  3074. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3075. (message "PDF written to %s" file))
  3076. ((string-match "\\.ics\\'" file)
  3077. (require 'ox-icalendar)
  3078. (org-icalendar-export-current-agenda (expand-file-name file)))
  3079. (t
  3080. (let ((bs (buffer-string)))
  3081. (find-file file)
  3082. (erase-buffer)
  3083. (insert bs)
  3084. (save-buffer 0)
  3085. (kill-buffer (current-buffer))
  3086. (message "Plain text written to %s" file))))))))
  3087. (set-buffer (or agenda-bufname
  3088. (and (org-called-interactively-p 'any) (buffer-name))
  3089. org-agenda-buffer-name)))
  3090. (when open (org-open-file file)))
  3091. (defvar org-agenda-tag-filter-overlays nil)
  3092. (defvar org-agenda-cat-filter-overlays nil)
  3093. (defvar org-agenda-re-filter-overlays nil)
  3094. (defun org-agenda-mark-filtered-text ()
  3095. "Mark all text hidden by filtering with a text property."
  3096. (let ((inhibit-read-only t))
  3097. (mapc
  3098. (lambda (o)
  3099. (when (equal (overlay-buffer o) (current-buffer))
  3100. (put-text-property
  3101. (overlay-start o) (overlay-end o)
  3102. 'org-filtered t)))
  3103. (append org-agenda-tag-filter-overlays
  3104. org-agenda-cat-filter-overlays
  3105. org-agenda-re-filter-overlays))))
  3106. (defun org-agenda-unmark-filtered-text ()
  3107. "Remove the filtering text property."
  3108. (let ((inhibit-read-only t))
  3109. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3110. (defun org-agenda-remove-marked-text (property &optional value)
  3111. "Delete all text marked with VALUE of PROPERTY.
  3112. VALUE defaults to t."
  3113. (let (beg)
  3114. (setq value (or value t))
  3115. (while (setq beg (text-property-any (point-min) (point-max)
  3116. property value))
  3117. (delete-region
  3118. beg (or (next-single-property-change beg 'org-filtered)
  3119. (point-max))))))
  3120. (defun org-agenda-add-entry-text ()
  3121. "Add entry text to agenda lines.
  3122. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3123. entry text following headings shown in the agenda.
  3124. Drawers will be excluded, also the line with scheduling/deadline info."
  3125. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3126. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3127. (let (m txt)
  3128. (goto-char (point-min))
  3129. (while (not (eobp))
  3130. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3131. (beginning-of-line 2)
  3132. (setq txt (org-agenda-get-some-entry-text
  3133. m org-agenda-add-entry-text-maxlines " > "))
  3134. (end-of-line 1)
  3135. (if (string-match "\\S-" txt)
  3136. (insert "\n" txt)
  3137. (or (eobp) (forward-char 1))))))))
  3138. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3139. &rest keep)
  3140. "Extract entry text from MARKER, at most N-LINES lines.
  3141. This will ignore drawers etc, just get the text.
  3142. If INDENT is given, prefix every line with this string. If KEEP is
  3143. given, it is a list of symbols, defining stuff that should not be
  3144. removed from the entry content. Currently only `planning' is allowed here."
  3145. (let (txt drawer-re kwd-time-re ind)
  3146. (save-excursion
  3147. (with-current-buffer (marker-buffer marker)
  3148. (if (not (derived-mode-p 'org-mode))
  3149. (setq txt "")
  3150. (save-excursion
  3151. (save-restriction
  3152. (widen)
  3153. (goto-char marker)
  3154. (end-of-line 1)
  3155. (setq txt (buffer-substring
  3156. (min (1+ (point)) (point-max))
  3157. (progn (outline-next-heading) (point)))
  3158. drawer-re org-drawer-regexp
  3159. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3160. ".*\n?"))
  3161. (with-temp-buffer
  3162. (insert txt)
  3163. (when org-agenda-add-entry-text-descriptive-links
  3164. (goto-char (point-min))
  3165. (while (org-activate-bracket-links (point-max))
  3166. (add-text-properties (match-beginning 0) (match-end 0)
  3167. '(face org-link))))
  3168. (goto-char (point-min))
  3169. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3170. (set-text-properties (match-beginning 0) (match-end 0)
  3171. nil))
  3172. (goto-char (point-min))
  3173. (while (re-search-forward drawer-re nil t)
  3174. (delete-region
  3175. (match-beginning 0)
  3176. (progn (re-search-forward
  3177. "^[ \t]*:END:.*\n?" nil 'move)
  3178. (point))))
  3179. (unless (member 'planning keep)
  3180. (goto-char (point-min))
  3181. (while (re-search-forward kwd-time-re nil t)
  3182. (replace-match "")))
  3183. (goto-char (point-min))
  3184. (when org-agenda-entry-text-exclude-regexps
  3185. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3186. (while (setq re (pop re-list))
  3187. (goto-char (point-min))
  3188. (while (re-search-forward re nil t)
  3189. (replace-match "")))))
  3190. (goto-char (point-max))
  3191. (skip-chars-backward " \t\n")
  3192. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3193. ;; find and remove min common indentation
  3194. (goto-char (point-min))
  3195. (untabify (point-min) (point-max))
  3196. (setq ind (org-get-indentation))
  3197. (while (not (eobp))
  3198. (unless (looking-at "[ \t]*$")
  3199. (setq ind (min ind (org-get-indentation))))
  3200. (beginning-of-line 2))
  3201. (goto-char (point-min))
  3202. (while (not (eobp))
  3203. (unless (looking-at "[ \t]*$")
  3204. (move-to-column ind)
  3205. (delete-region (point-at-bol) (point)))
  3206. (beginning-of-line 2))
  3207. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3208. (goto-char (point-min))
  3209. (when indent
  3210. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3211. (replace-match indent t t)))
  3212. (goto-char (point-min))
  3213. (while (looking-at "[ \t]*\n") (replace-match ""))
  3214. (goto-char (point-max))
  3215. (when (> (org-current-line)
  3216. n-lines)
  3217. (org-goto-line (1+ n-lines))
  3218. (backward-char 1))
  3219. (setq txt (buffer-substring (point-min) (point)))))))))
  3220. txt))
  3221. (defun org-check-for-org-mode ()
  3222. "Make sure current buffer is in org-mode. Error if not."
  3223. (or (derived-mode-p 'org-mode)
  3224. (error "Cannot execute org-mode agenda command on buffer in %s"
  3225. major-mode)))
  3226. ;;; Agenda prepare and finalize
  3227. (defvar org-agenda-multi nil) ; dynamically scoped
  3228. (defvar org-agenda-pre-window-conf nil)
  3229. (defvar org-agenda-columns-active nil)
  3230. (defvar org-agenda-name nil)
  3231. (defvar org-agenda-tag-filter nil)
  3232. (defvar org-agenda-category-filter nil)
  3233. (defvar org-agenda-regexp-filter nil)
  3234. (defvar org-agenda-top-headline-filter nil)
  3235. (defvar org-agenda-tag-filter-while-redo nil)
  3236. (defvar org-agenda-tag-filter-preset nil
  3237. "A preset of the tags filter used for secondary agenda filtering.
  3238. This must be a list of strings, each string must be a single tag preceded
  3239. by \"+\" or \"-\".
  3240. This variable should not be set directly, but agenda custom commands can
  3241. bind it in the options section. The preset filter is a global property of
  3242. the entire agenda view. In a block agenda, it will not work reliably to
  3243. define a filter for one of the individual blocks. You need to set it in
  3244. the global options and expect it to be applied to the entire view.")
  3245. (defvar org-agenda-category-filter-preset nil
  3246. "A preset of the category filter used for secondary agenda filtering.
  3247. This must be a list of strings, each string must be a single category
  3248. preceded by \"+\" or \"-\".
  3249. This variable should not be set directly, but agenda custom commands can
  3250. bind it in the options section. The preset filter is a global property of
  3251. the entire agenda view. In a block agenda, it will not work reliably to
  3252. define a filter for one of the individual blocks. You need to set it in
  3253. the global options and expect it to be applied to the entire view.")
  3254. (defvar org-agenda-regexp-filter-preset nil
  3255. "A preset of the regexp filter used for secondary agenda filtering.
  3256. This must be a list of strings, each string must be a single regexp
  3257. preceded by \"+\" or \"-\".
  3258. This variable should not be set directly, but agenda custom commands can
  3259. bind it in the options section. The preset filter is a global property of
  3260. the entire agenda view. In a block agenda, it will not work reliably to
  3261. define a filter for one of the individual blocks. You need to set it in
  3262. the global options and expect it to be applied to the entire view.")
  3263. (defun org-agenda-use-sticky-p ()
  3264. "Return non-nil if an agenda buffer named
  3265. `org-agenda-buffer-name' exists and should be shown instead of
  3266. generating a new one."
  3267. (and
  3268. ;; turned off by user
  3269. org-agenda-sticky
  3270. ;; For multi-agenda buffer already exists
  3271. (not org-agenda-multi)
  3272. ;; buffer found
  3273. (get-buffer org-agenda-buffer-name)
  3274. ;; C-u parameter is same as last call
  3275. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3276. (and
  3277. (equal current-prefix-arg
  3278. org-agenda-last-prefix-arg)
  3279. ;; In case user turned stickiness on, while having existing
  3280. ;; Agenda buffer active, don't reuse that buffer, because it
  3281. ;; does not have org variables local
  3282. org-agenda-this-buffer-is-sticky))))
  3283. (defun org-agenda-prepare-window (abuf)
  3284. "Setup agenda buffer in the window."
  3285. (let* ((awin (get-buffer-window abuf))
  3286. wconf)
  3287. (cond
  3288. ((equal (current-buffer) abuf) nil)
  3289. (awin (select-window awin))
  3290. ((not (setq wconf (current-window-configuration))))
  3291. ((equal org-agenda-window-setup 'current-window)
  3292. (org-pop-to-buffer-same-window abuf))
  3293. ((equal org-agenda-window-setup 'other-window)
  3294. (org-switch-to-buffer-other-window abuf))
  3295. ((equal org-agenda-window-setup 'other-frame)
  3296. (switch-to-buffer-other-frame abuf))
  3297. ((equal org-agenda-window-setup 'reorganize-frame)
  3298. (delete-other-windows)
  3299. (org-switch-to-buffer-other-window abuf)))
  3300. ;; additional test in case agenda is invoked from within agenda
  3301. ;; buffer via elisp link
  3302. (unless (equal (current-buffer) abuf)
  3303. (org-pop-to-buffer-same-window abuf))
  3304. (setq org-agenda-pre-window-conf
  3305. (or org-agenda-pre-window-conf wconf))))
  3306. (defun org-agenda-prepare (&optional name)
  3307. (if (org-agenda-use-sticky-p)
  3308. (progn
  3309. ;; Popup existing buffer
  3310. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3311. (message "Sticky Agenda buffer, use `r' to refresh")
  3312. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3313. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3314. (setq org-todo-keywords-for-agenda nil)
  3315. (unless org-agenda-persistent-filter
  3316. (setq org-agenda-tag-filter nil
  3317. org-agenda-category-filter nil
  3318. org-agenda-regexp-filter nil))
  3319. (put 'org-agenda-tag-filter :preset-filter
  3320. org-agenda-tag-filter-preset)
  3321. (put 'org-agenda-category-filter :preset-filter
  3322. org-agenda-category-filter-preset)
  3323. (put 'org-agenda-regexp-filter :preset-filter
  3324. org-agenda-regexp-filter-preset)
  3325. (if org-agenda-multi
  3326. (progn
  3327. (setq buffer-read-only nil)
  3328. (goto-char (point-max))
  3329. (unless (or (bobp) org-agenda-compact-blocks
  3330. (not org-agenda-block-separator))
  3331. (insert "\n"
  3332. (if (stringp org-agenda-block-separator)
  3333. org-agenda-block-separator
  3334. (make-string (window-width) org-agenda-block-separator))
  3335. "\n"))
  3336. (narrow-to-region (point) (point-max)))
  3337. (setq org-done-keywords-for-agenda nil)
  3338. ;; Setting any org variables that are in org-agenda-local-vars
  3339. ;; list need to be done after the prepare call
  3340. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3341. (setq buffer-read-only nil)
  3342. (org-agenda-reset-markers)
  3343. (let ((inhibit-read-only t)) (erase-buffer))
  3344. (org-agenda-mode)
  3345. (setq org-agenda-buffer (current-buffer))
  3346. (setq org-agenda-contributing-files nil)
  3347. (setq org-agenda-columns-active nil)
  3348. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3349. (setq org-todo-keywords-for-agenda
  3350. (org-uniquify org-todo-keywords-for-agenda))
  3351. (setq org-done-keywords-for-agenda
  3352. (org-uniquify org-done-keywords-for-agenda))
  3353. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3354. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3355. (and name (not org-agenda-name)
  3356. (org-set-local 'org-agenda-name name)))
  3357. (setq buffer-read-only nil)))
  3358. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3359. (defun org-agenda-finalize ()
  3360. "Finishing touch for the agenda buffer, called just before displaying it."
  3361. (unless org-agenda-multi
  3362. (save-excursion
  3363. (let ((inhibit-read-only t))
  3364. (goto-char (point-min))
  3365. (save-excursion
  3366. (while (org-activate-bracket-links (point-max))
  3367. (add-text-properties (match-beginning 0) (match-end 0)
  3368. '(face org-link))))
  3369. (save-excursion
  3370. (while (org-activate-plain-links (point-max))
  3371. (add-text-properties (match-beginning 0) (match-end 0)
  3372. '(face org-link))))
  3373. (unless (eq org-agenda-remove-tags t)
  3374. (org-agenda-align-tags))
  3375. (unless org-agenda-with-colors
  3376. (remove-text-properties (point-min) (point-max) '(face nil)))
  3377. (if (and (boundp 'org-agenda-overriding-columns-format)
  3378. org-agenda-overriding-columns-format)
  3379. (org-set-local 'org-agenda-overriding-columns-format
  3380. org-agenda-overriding-columns-format))
  3381. (if (and (boundp 'org-agenda-view-columns-initially)
  3382. org-agenda-view-columns-initially)
  3383. (org-agenda-columns))
  3384. (when org-agenda-fontify-priorities
  3385. (org-agenda-fontify-priorities))
  3386. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3387. (org-agenda-dim-blocked-tasks))
  3388. (org-agenda-mark-clocking-task)
  3389. (when org-agenda-entry-text-mode
  3390. (org-agenda-entry-text-hide)
  3391. (org-agenda-entry-text-show))
  3392. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3393. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3394. (org-habit-insert-consistency-graphs))
  3395. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3396. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3397. (and (listp org-agenda-show-inherited-tags)
  3398. (memq org-agenda-type org-agenda-show-inherited-tags))
  3399. (and (eq org-agenda-show-inherited-tags t)
  3400. (or (eq org-agenda-use-tag-inheritance t)
  3401. (and (listp org-agenda-use-tag-inheritance)
  3402. (not (memq org-agenda-type
  3403. org-agenda-use-tag-inheritance))))))
  3404. (let (mrk)
  3405. (save-excursion
  3406. (goto-char (point-min))
  3407. (while (equal (forward-line) 0)
  3408. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3409. (get-text-property (point) 'org-hd-marker)))
  3410. (put-text-property (point-at-bol) (point-at-eol)
  3411. 'tags (org-with-point-at mrk
  3412. (delete-dups
  3413. (mapcar 'downcase (org-get-tags-at))))))))))
  3414. (run-hooks 'org-agenda-finalize-hook)
  3415. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3416. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3417. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3418. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3419. (when (or org-agenda-regexp-filter (get 'org-agenda-regexp-filter :preset-filter))
  3420. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3421. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3422. (defun org-agenda-mark-clocking-task ()
  3423. "Mark the current clock entry in the agenda if it is present."
  3424. ;; We need to widen when `org-agenda-finalize' is called from
  3425. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3426. (when org-clock-current-task
  3427. (save-restriction
  3428. (widen)
  3429. (org-agenda-unmark-clocking-task)
  3430. (when (marker-buffer org-clock-hd-marker)
  3431. (save-excursion
  3432. (goto-char (point-min))
  3433. (let (s ov)
  3434. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3435. (goto-char s)
  3436. (when (equal (org-get-at-bol 'org-hd-marker)
  3437. org-clock-hd-marker)
  3438. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3439. (overlay-put ov 'type 'org-agenda-clocking)
  3440. (overlay-put ov 'face 'org-agenda-clocking)
  3441. (overlay-put ov 'help-echo
  3442. "The clock is running in this item")))))))))
  3443. (defun org-agenda-unmark-clocking-task ()
  3444. "Unmark the current clocking task."
  3445. (mapc (lambda (o)
  3446. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3447. (delete-overlay o)))
  3448. (overlays-in (point-min) (point-max))))
  3449. (defun org-agenda-fontify-priorities ()
  3450. "Make highest priority lines bold, and lowest italic."
  3451. (interactive)
  3452. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3453. (delete-overlay o)))
  3454. (overlays-in (point-min) (point-max)))
  3455. (save-excursion
  3456. (let (b e p ov h l)
  3457. (goto-char (point-min))
  3458. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3459. (setq h (or (get-char-property (point) 'org-highest-priority)
  3460. org-highest-priority)
  3461. l (or (get-char-property (point) 'org-lowest-priority)
  3462. org-lowest-priority)
  3463. p (string-to-char (match-string 1))
  3464. b (match-beginning 0)
  3465. e (if (eq org-agenda-fontify-priorities 'cookies)
  3466. (match-end 0)
  3467. (point-at-eol))
  3468. ov (make-overlay b e))
  3469. (overlay-put
  3470. ov 'face
  3471. (cons (cond ((org-face-from-face-or-color
  3472. 'priority nil
  3473. (cdr (assoc p org-priority-faces))))
  3474. ((and (listp org-agenda-fontify-priorities)
  3475. (org-face-from-face-or-color
  3476. 'priority nil
  3477. (cdr (assoc p org-agenda-fontify-priorities)))))
  3478. ((equal p l) 'italic)
  3479. ((equal p h) 'bold))
  3480. 'org-priority))
  3481. (overlay-put ov 'org-type 'org-priority)))))
  3482. (defvar org-depend-tag-blocked)
  3483. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3484. "Dim currently blocked TODO's in the agenda display.
  3485. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3486. dimming them."
  3487. (interactive "P")
  3488. (when (org-called-interactively-p 'interactive)
  3489. (message "Dim or hide blocked tasks..."))
  3490. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3491. (delete-overlay o)))
  3492. (overlays-in (point-min) (point-max)))
  3493. (save-excursion
  3494. (let ((inhibit-read-only t)
  3495. (org-depend-tag-blocked nil)
  3496. (invis (or (not (null invisible))
  3497. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3498. org-blocked-by-checkboxes
  3499. invis1 b e p ov h l)
  3500. (goto-char (point-min))
  3501. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3502. (and pos (goto-char (1+ pos))))
  3503. (setq org-blocked-by-checkboxes nil invis1 invis)
  3504. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3505. (when (and marker
  3506. (with-current-buffer (marker-buffer marker)
  3507. (save-excursion (goto-char marker)
  3508. (org-entry-blocked-p))))
  3509. (if org-blocked-by-checkboxes (setq invis1 nil))
  3510. (setq b (if invis1
  3511. (max (point-min) (1- (point-at-bol)))
  3512. (point-at-bol))
  3513. e (point-at-eol)
  3514. ov (make-overlay b e))
  3515. (if invis1
  3516. (overlay-put ov 'invisible t)
  3517. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3518. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3519. (when (org-called-interactively-p 'interactive)
  3520. (message "Dim or hide blocked tasks...done")))
  3521. (defvar org-agenda-skip-function nil
  3522. "Function to be called at each match during agenda construction.
  3523. If this function returns nil, the current match should not be skipped.
  3524. Otherwise, the function must return a position from where the search
  3525. should be continued.
  3526. This may also be a Lisp form, it will be evaluated.
  3527. Never set this variable using `setq' or so, because then it will apply
  3528. to all future agenda commands. If you do want a global skipping condition,
  3529. use the option `org-agenda-skip-function-global' instead.
  3530. The correct usage for `org-agenda-skip-function' is to bind it with
  3531. `let' to scope it dynamically into the agenda-constructing command.
  3532. A good way to set it is through options in `org-agenda-custom-commands'.")
  3533. (defun org-agenda-skip ()
  3534. "Throw to `:skip' in places that should be skipped.
  3535. Also moves point to the end of the skipped region, so that search can
  3536. continue from there."
  3537. (let ((p (point-at-bol)) to)
  3538. (when (or
  3539. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3540. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3541. (get-text-property p :org-archived)
  3542. (org-end-of-subtree t))
  3543. (and org-agenda-skip-comment-trees
  3544. (get-text-property p :org-comment)
  3545. (org-end-of-subtree t))
  3546. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3547. (org-agenda-skip-eval org-agenda-skip-function)))
  3548. (goto-char to))
  3549. (org-in-src-block-p t))
  3550. (throw :skip t))))
  3551. (defun org-agenda-skip-eval (form)
  3552. "If FORM is a function or a list, call (or eval) it and return the result.
  3553. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3554. and match data are returned to the previous state no matter what these
  3555. functions do."
  3556. (let (fp)
  3557. (and form
  3558. (or (setq fp (functionp form))
  3559. (consp form))
  3560. (save-excursion
  3561. (save-match-data
  3562. (if fp
  3563. (funcall form)
  3564. (eval form)))))))
  3565. (defvar org-agenda-markers nil
  3566. "List of all currently active markers created by `org-agenda'.")
  3567. (defvar org-agenda-last-marker-time (org-float-time)
  3568. "Creation time of the last agenda marker.")
  3569. (defun org-agenda-new-marker (&optional pos)
  3570. "Return a new agenda marker.
  3571. Org-mode keeps a list of these markers and resets them when they are
  3572. no longer in use."
  3573. (let ((m (copy-marker (or pos (point)))))
  3574. (setq org-agenda-last-marker-time (org-float-time))
  3575. (if org-agenda-buffer
  3576. (with-current-buffer org-agenda-buffer
  3577. (push m org-agenda-markers))
  3578. (push m org-agenda-markers))
  3579. m))
  3580. (defun org-agenda-reset-markers ()
  3581. "Reset markers created by `org-agenda'."
  3582. (while org-agenda-markers
  3583. (move-marker (pop org-agenda-markers) nil)))
  3584. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3585. "Save relative positions of markers in region.
  3586. This check for agenda markers in all agenda buffers currently active."
  3587. (dolist (buf (buffer-list))
  3588. (with-current-buffer buf
  3589. (when (eq major-mode 'org-agenda-mode)
  3590. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3591. org-agenda-markers)))))
  3592. ;;; Entry text mode
  3593. (defun org-agenda-entry-text-show-here ()
  3594. "Add some text from the entry as context to the current line."
  3595. (let (m txt o)
  3596. (setq m (org-get-at-bol 'org-hd-marker))
  3597. (unless (marker-buffer m)
  3598. (error "No marker points to an entry here"))
  3599. (setq txt (concat "\n" (org-no-properties
  3600. (org-agenda-get-some-entry-text
  3601. m org-agenda-entry-text-maxlines
  3602. org-agenda-entry-text-leaders))))
  3603. (when (string-match "\\S-" txt)
  3604. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3605. (overlay-put o 'evaporate t)
  3606. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3607. (overlay-put o 'after-string txt))))
  3608. (defun org-agenda-entry-text-show ()
  3609. "Add entry context for all agenda lines."
  3610. (interactive)
  3611. (save-excursion
  3612. (goto-char (point-max))
  3613. (beginning-of-line 1)
  3614. (while (not (bobp))
  3615. (when (org-get-at-bol 'org-hd-marker)
  3616. (org-agenda-entry-text-show-here))
  3617. (beginning-of-line 0))))
  3618. (defun org-agenda-entry-text-hide ()
  3619. "Remove any shown entry context."
  3620. (delq nil
  3621. (mapcar (lambda (o)
  3622. (if (eq (overlay-get o 'org-overlay-type)
  3623. 'agenda-entry-content)
  3624. (progn (delete-overlay o) t)))
  3625. (overlays-in (point-min) (point-max)))))
  3626. (defun org-agenda-get-day-face (date)
  3627. "Return the face DATE should be displayed with."
  3628. (or (and (functionp org-agenda-day-face-function)
  3629. (funcall org-agenda-day-face-function date))
  3630. (cond ((org-agenda-todayp date)
  3631. 'org-agenda-date-today)
  3632. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3633. 'org-agenda-date-weekend)
  3634. (t 'org-agenda-date))))
  3635. ;;; Agenda timeline
  3636. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3637. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3638. (defun org-timeline (&optional dotodo)
  3639. "Show a time-sorted view of the entries in the current org file.
  3640. Only entries with a time stamp of today or later will be listed. With
  3641. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3642. under the current date.
  3643. If the buffer contains an active region, only check the region for
  3644. dates."
  3645. (interactive "P")
  3646. (let* ((dopast t)
  3647. (org-agenda-show-log-scoped org-agenda-show-log)
  3648. (org-agenda-show-log org-agenda-show-log-scoped)
  3649. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3650. (current-buffer))))
  3651. (date (calendar-current-date))
  3652. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3653. (end (if (org-region-active-p) (region-end) (point-max)))
  3654. (day-numbers (org-get-all-dates
  3655. beg end 'no-ranges
  3656. t org-agenda-show-log-scoped ; always include today
  3657. org-timeline-show-empty-dates))
  3658. (org-deadline-warning-days 0)
  3659. (org-agenda-only-exact-dates t)
  3660. (today (org-today))
  3661. (past t)
  3662. args
  3663. s e rtn d emptyp)
  3664. (setq org-agenda-redo-command
  3665. (list 'let
  3666. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3667. (list 'org-switch-to-buffer-other-window (current-buffer))
  3668. (list 'org-timeline (list 'quote dotodo))))
  3669. (put 'org-agenda-redo-command 'org-lprops nil)
  3670. (if (not dopast)
  3671. ;; Remove past dates from the list of dates.
  3672. (setq day-numbers (delq nil (mapcar (lambda(x)
  3673. (if (>= x today) x nil))
  3674. day-numbers))))
  3675. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3676. (org-compile-prefix-format 'timeline)
  3677. (org-set-sorting-strategy 'timeline)
  3678. (if org-agenda-show-log-scoped (push :closed args))
  3679. (push :timestamp args)
  3680. (push :deadline args)
  3681. (push :scheduled args)
  3682. (push :sexp args)
  3683. (if dotodo (push :todo args))
  3684. (insert "Timeline of file " entry "\n")
  3685. (add-text-properties (point-min) (point)
  3686. (list 'face 'org-agenda-structure))
  3687. (org-agenda-mark-header-line (point-min))
  3688. (while (setq d (pop day-numbers))
  3689. (if (and (listp d) (eq (car d) :omitted))
  3690. (progn
  3691. (setq s (point))
  3692. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3693. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3694. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3695. (if (and (>= d today)
  3696. dopast
  3697. past)
  3698. (progn
  3699. (setq past nil)
  3700. (insert (make-string 79 ?-) "\n")))
  3701. (setq date (calendar-gregorian-from-absolute d))
  3702. (setq s (point))
  3703. (setq rtn (and (not emptyp)
  3704. (apply 'org-agenda-get-day-entries entry
  3705. date args)))
  3706. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3707. (progn
  3708. (insert
  3709. (if (stringp org-agenda-format-date)
  3710. (format-time-string org-agenda-format-date
  3711. (org-time-from-absolute date))
  3712. (funcall org-agenda-format-date date))
  3713. "\n")
  3714. (put-text-property s (1- (point)) 'face
  3715. (org-agenda-get-day-face date))
  3716. (put-text-property s (1- (point)) 'org-date-line t)
  3717. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3718. (if (equal d today)
  3719. (put-text-property s (1- (point)) 'org-today t))
  3720. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3721. (put-text-property s (1- (point)) 'day d)))))
  3722. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3723. (point-min)))
  3724. (add-text-properties
  3725. (point-min) (point-max)
  3726. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3727. (org-agenda-finalize)
  3728. (setq buffer-read-only t)))
  3729. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3730. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3731. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3732. not every single day in the range. If FORCE-TODAY is non-nil, make
  3733. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3734. inactive time stamps (those in square brackets) are included.
  3735. When EMPTY is non-nil, also include days without any entries."
  3736. (let ((re (concat
  3737. (if pre-re pre-re "")
  3738. (if inactive org-ts-regexp-both org-ts-regexp)))
  3739. dates dates1 date day day1 day2 ts1 ts2 pos)
  3740. (if force-today
  3741. (setq dates (list (org-today))))
  3742. (save-excursion
  3743. (goto-char beg)
  3744. (while (re-search-forward re end t)
  3745. (setq day (time-to-days (org-time-string-to-time
  3746. (substring (match-string 1) 0 10)
  3747. (current-buffer) (match-beginning 0))))
  3748. (or (memq day dates) (push day dates)))
  3749. (unless no-ranges
  3750. (goto-char beg)
  3751. (while (re-search-forward org-tr-regexp end t)
  3752. (setq pos (match-beginning 0))
  3753. (setq ts1 (substring (match-string 1) 0 10)
  3754. ts2 (substring (match-string 2) 0 10)
  3755. day1 (time-to-days (org-time-string-to-time
  3756. ts1 (current-buffer) pos))
  3757. day2 (time-to-days (org-time-string-to-time
  3758. ts2 (current-buffer) pos)))
  3759. (while (< (setq day1 (1+ day1)) day2)
  3760. (or (memq day1 dates) (push day1 dates)))))
  3761. (setq dates (sort dates '<))
  3762. (when empty
  3763. (while (setq day (pop dates))
  3764. (setq day2 (car dates))
  3765. (push day dates1)
  3766. (when (and day2 empty)
  3767. (if (or (eq empty t)
  3768. (and (numberp empty) (<= (- day2 day) empty)))
  3769. (while (< (setq day (1+ day)) day2)
  3770. (push (list day) dates1))
  3771. (push (cons :omitted (- day2 day)) dates1))))
  3772. (setq dates (nreverse dates1)))
  3773. dates)))
  3774. ;;; Agenda Daily/Weekly
  3775. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3776. "Start day for the agenda view.
  3777. Custom commands can set this variable in the options section.
  3778. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3779. input allowed when reading a date through the Org calendar.
  3780. See the docstring of `org-read-date' for details.")
  3781. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3782. (defvar org-arg-loc nil) ; local variable
  3783. (defvar org-agenda-buffer-tmp-name nil)
  3784. ;;;###autoload
  3785. (defun org-agenda-list (&optional arg start-day span with-hour)
  3786. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3787. The view will be for the current day or week, but from the overview buffer
  3788. you will be able to go to other days/weeks.
  3789. With a numeric prefix argument in an interactive call, the agenda will
  3790. span ARG days. Lisp programs should instead specify SPAN to change
  3791. the number of days. SPAN defaults to `org-agenda-span'.
  3792. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3793. given in `org-agenda-start-on-weekday'.
  3794. When WITH-HOUR is non-nil, only include scheduled and deadline
  3795. items if they have an hour specification like [h]h:mm."
  3796. (interactive "P")
  3797. (if org-agenda-overriding-arguments
  3798. (setq arg (car org-agenda-overriding-arguments)
  3799. start-day (nth 1 org-agenda-overriding-arguments)
  3800. span (nth 2 org-agenda-overriding-arguments)))
  3801. (if (and (integerp arg) (> arg 0))
  3802. (setq span arg arg nil))
  3803. (catch 'exit
  3804. (setq org-agenda-buffer-name
  3805. (or org-agenda-buffer-tmp-name
  3806. (if org-agenda-sticky
  3807. (cond ((and org-keys (stringp org-match))
  3808. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3809. (org-keys
  3810. (format "*Org Agenda(%s)*" org-keys))
  3811. (t "*Org Agenda(a)*")))
  3812. org-agenda-buffer-name))
  3813. (org-agenda-prepare "Day/Week")
  3814. (setq start-day (or start-day org-agenda-start-day))
  3815. (if (stringp start-day)
  3816. ;; Convert to an absolute day number
  3817. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3818. (org-compile-prefix-format 'agenda)
  3819. (org-set-sorting-strategy 'agenda)
  3820. (let* ((span (org-agenda-ndays-to-span
  3821. (or span org-agenda-ndays org-agenda-span)))
  3822. (today (org-today))
  3823. (sd (or start-day today))
  3824. (ndays (org-agenda-span-to-ndays span sd))
  3825. (org-agenda-start-on-weekday
  3826. (if (or (eq ndays 7) (eq ndays 14))
  3827. org-agenda-start-on-weekday))
  3828. (thefiles (org-agenda-files nil 'ifmode))
  3829. (files thefiles)
  3830. (start (if (or (null org-agenda-start-on-weekday)
  3831. (< ndays 7))
  3832. sd
  3833. (let* ((nt (calendar-day-of-week
  3834. (calendar-gregorian-from-absolute sd)))
  3835. (n1 org-agenda-start-on-weekday)
  3836. (d (- nt n1)))
  3837. (- sd (+ (if (< d 0) 7 0) d)))))
  3838. (day-numbers (list start))
  3839. (day-cnt 0)
  3840. (inhibit-redisplay (not debug-on-error))
  3841. (org-agenda-show-log-scoped org-agenda-show-log)
  3842. s e rtn rtnall file date d start-pos end-pos todayp
  3843. clocktable-start clocktable-end filter)
  3844. (setq org-agenda-redo-command
  3845. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3846. (dotimes (n (1- ndays))
  3847. (push (1+ (car day-numbers)) day-numbers))
  3848. (setq day-numbers (nreverse day-numbers))
  3849. (setq clocktable-start (car day-numbers)
  3850. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3851. (org-set-local 'org-starting-day (car day-numbers))
  3852. (org-set-local 'org-arg-loc arg)
  3853. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3854. (unless org-agenda-compact-blocks
  3855. (let* ((d1 (car day-numbers))
  3856. (d2 (org-last day-numbers))
  3857. (w1 (org-days-to-iso-week d1))
  3858. (w2 (org-days-to-iso-week d2)))
  3859. (setq s (point))
  3860. (if org-agenda-overriding-header
  3861. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3862. nil 'face 'org-agenda-structure) "\n")
  3863. (insert (org-agenda-span-name span)
  3864. "-agenda"
  3865. (if (< (- d2 d1) 350)
  3866. (if (= w1 w2)
  3867. (format " (W%02d)" w1)
  3868. (format " (W%02d-W%02d)" w1 w2))
  3869. "")
  3870. ":\n")))
  3871. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3872. 'org-date-line t))
  3873. (org-agenda-mark-header-line s))
  3874. (while (setq d (pop day-numbers))
  3875. (setq date (calendar-gregorian-from-absolute d)
  3876. s (point))
  3877. (if (or (setq todayp (= d today))
  3878. (and (not start-pos) (= d sd)))
  3879. (setq start-pos (point))
  3880. (if (and start-pos (not end-pos))
  3881. (setq end-pos (point))))
  3882. (setq files thefiles
  3883. rtnall nil)
  3884. (while (setq file (pop files))
  3885. (catch 'nextfile
  3886. (org-check-agenda-file file)
  3887. (let ((org-agenda-entry-types org-agenda-entry-types))
  3888. ;; Starred types override non-starred equivalents
  3889. (when (member :deadline* org-agenda-entry-types)
  3890. (setq org-agenda-entry-types
  3891. (delq :deadline org-agenda-entry-types)))
  3892. (when (member :scheduled* org-agenda-entry-types)
  3893. (setq org-agenda-entry-types
  3894. (delq :scheduled org-agenda-entry-types)))
  3895. ;; Honor with-hour
  3896. (when with-hour
  3897. (when (member :deadline org-agenda-entry-types)
  3898. (setq org-agenda-entry-types
  3899. (delq :deadline org-agenda-entry-types))
  3900. (push :deadline* org-agenda-entry-types))
  3901. (when (member :scheduled org-agenda-entry-types)
  3902. (setq org-agenda-entry-types
  3903. (delq :scheduled org-agenda-entry-types))
  3904. (push :scheduled* org-agenda-entry-types)))
  3905. (unless org-agenda-include-deadlines
  3906. (setq org-agenda-entry-types
  3907. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3908. (cond
  3909. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3910. (setq rtn (org-agenda-get-day-entries
  3911. file date :closed)))
  3912. (org-agenda-show-log-scoped
  3913. (setq rtn (apply 'org-agenda-get-day-entries
  3914. file date
  3915. (append '(:closed) org-agenda-entry-types))))
  3916. (t
  3917. (setq rtn (apply 'org-agenda-get-day-entries
  3918. file date
  3919. org-agenda-entry-types)))))
  3920. (setq rtnall (append rtnall rtn)))) ;; all entries
  3921. (if org-agenda-include-diary
  3922. (let ((org-agenda-search-headline-for-time t))
  3923. (require 'diary-lib)
  3924. (setq rtn (org-get-entries-from-diary date))
  3925. (setq rtnall (append rtnall rtn))))
  3926. (if (or rtnall org-agenda-show-all-dates)
  3927. (progn
  3928. (setq day-cnt (1+ day-cnt))
  3929. (insert
  3930. (if (stringp org-agenda-format-date)
  3931. (format-time-string org-agenda-format-date
  3932. (org-time-from-absolute date))
  3933. (funcall org-agenda-format-date date))
  3934. "\n")
  3935. (put-text-property s (1- (point)) 'face
  3936. (org-agenda-get-day-face date))
  3937. (put-text-property s (1- (point)) 'org-date-line t)
  3938. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3939. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3940. (when todayp
  3941. (put-text-property s (1- (point)) 'org-today t))
  3942. (setq rtnall
  3943. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3944. (if rtnall (insert ;; all entries
  3945. (org-agenda-finalize-entries rtnall 'agenda)
  3946. "\n"))
  3947. (put-text-property s (1- (point)) 'day d)
  3948. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3949. (when (and org-agenda-clockreport-mode clocktable-start)
  3950. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3951. ;; the above line is to ensure the restricted range!
  3952. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3953. tbl)
  3954. (setq p (org-plist-delete p :block))
  3955. (setq p (plist-put p :tstart clocktable-start))
  3956. (setq p (plist-put p :tend clocktable-end))
  3957. (setq p (plist-put p :scope 'agenda))
  3958. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3959. (setq filter (or org-agenda-tag-filter-while-redo
  3960. (get 'org-agenda-tag-filter :preset-filter))))
  3961. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3962. (if (string-match "[<>=]" x)
  3963. ""
  3964. x))
  3965. filter ""))))
  3966. (setq tbl (apply 'org-clock-get-clocktable p))
  3967. (insert tbl)))
  3968. (goto-char (point-min))
  3969. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3970. (unless (and (pos-visible-in-window-p (point-min))
  3971. (pos-visible-in-window-p (point-max)))
  3972. (goto-char (1- (point-max)))
  3973. (recenter -1)
  3974. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3975. (progn
  3976. (goto-char (or start-pos 1))
  3977. (recenter 1))))
  3978. (goto-char (or start-pos 1))
  3979. (add-text-properties (point-min) (point-max)
  3980. `(org-agenda-type agenda
  3981. org-last-args (,arg ,start-day ,span)
  3982. org-redo-cmd ,org-agenda-redo-command
  3983. org-series-cmd ,org-cmd))
  3984. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3985. (org-agenda-show-clocking-issues))
  3986. (org-agenda-finalize)
  3987. (setq buffer-read-only t)
  3988. (message ""))))
  3989. (defun org-agenda-ndays-to-span (n)
  3990. "Return a span symbol for a span of N days, or N if none matches."
  3991. (cond ((symbolp n) n)
  3992. ((= n 1) 'day)
  3993. ((= n 7) 'week)
  3994. ((= n 14) 'fortnight)
  3995. (t n)))
  3996. (defun org-agenda-span-to-ndays (span &optional start-day)
  3997. "Return ndays from SPAN, possibly starting at START-DAY.
  3998. START-DAY is an absolute time value."
  3999. (cond ((numberp span) span)
  4000. ((eq span 'day) 1)
  4001. ((eq span 'week) 7)
  4002. ((eq span 'fortnight) 14)
  4003. ((eq span 'month)
  4004. (let ((date (calendar-gregorian-from-absolute start-day)))
  4005. (calendar-last-day-of-month (car date) (caddr date))))
  4006. ((eq span 'year)
  4007. (let ((date (calendar-gregorian-from-absolute start-day)))
  4008. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  4009. (defun org-agenda-span-name (span)
  4010. "Return a SPAN name."
  4011. (if (null span)
  4012. ""
  4013. (if (symbolp span)
  4014. (capitalize (symbol-name span))
  4015. (format "%d days" span))))
  4016. ;;; Agenda word search
  4017. (defvar org-agenda-search-history nil)
  4018. (defvar org-search-syntax-table nil
  4019. "Special syntax table for org-mode search.
  4020. In this table, we have single quotes not as word constituents, to
  4021. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4022. (defvar org-mode-syntax-table) ; From org.el
  4023. (defun org-search-syntax-table ()
  4024. (unless org-search-syntax-table
  4025. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4026. (modify-syntax-entry ?' "." org-search-syntax-table)
  4027. (modify-syntax-entry ?` "." org-search-syntax-table))
  4028. org-search-syntax-table)
  4029. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4030. ;;;###autoload
  4031. (defun org-search-view (&optional todo-only string edit-at)
  4032. "Show all entries that contain a phrase or words or regular expressions.
  4033. With optional prefix argument TODO-ONLY, only consider entries that are
  4034. TODO entries. The argument STRING can be used to pass a default search
  4035. string into this function. If EDIT-AT is non-nil, it means that the
  4036. user should get a chance to edit this string, with cursor at position
  4037. EDIT-AT.
  4038. The search string can be viewed either as a phrase that should be found as
  4039. is, or it can be broken into a number of snippets, each of which must match
  4040. in a Boolean way to select an entry. The default depends on the variable
  4041. `org-agenda-search-view-always-boolean'.
  4042. Even if this is turned off (the default) you can always switch to
  4043. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4044. The default is a direct search of the whole phrase, where each space in
  4045. the search string can expand to an arbitrary amount of whitespace,
  4046. including newlines.
  4047. If using a Boolean search, the search string is split on whitespace and
  4048. each snippet is searched separately, with logical AND to select an entry.
  4049. Words prefixed with a minus must *not* occur in the entry. Words without
  4050. a prefix or prefixed with a plus must occur in the entry. Matching is
  4051. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4052. match whole words, not parts of a word) if
  4053. `org-agenda-search-view-force-full-words' is set (default is nil).
  4054. Boolean search snippets enclosed by curly braces are interpreted as
  4055. regular expressions that must or (when preceded with \"-\") must not
  4056. match in the entry. Snippets enclosed into double quotes will be taken
  4057. as a whole, to include whitespace.
  4058. - If the search string starts with an asterisk, search only in headlines.
  4059. - If (possibly after the leading star) the search string starts with an
  4060. exclamation mark, this also means to look at TODO entries only, an effect
  4061. that can also be achieved with a prefix argument.
  4062. - If (possibly after star and exclamation mark) the search string starts
  4063. with a colon, this will mean that the (non-regexp) snippets of the
  4064. Boolean search must match as full words.
  4065. This command searches the agenda files, and in addition the files listed
  4066. in `org-agenda-text-search-extra-files'."
  4067. (interactive "P")
  4068. (if org-agenda-overriding-arguments
  4069. (setq todo-only (car org-agenda-overriding-arguments)
  4070. string (nth 1 org-agenda-overriding-arguments)
  4071. edit-at (nth 2 org-agenda-overriding-arguments)))
  4072. (let* ((props (list 'face nil
  4073. 'done-face 'org-agenda-done
  4074. 'org-not-done-regexp org-not-done-regexp
  4075. 'org-todo-regexp org-todo-regexp
  4076. 'org-complex-heading-regexp org-complex-heading-regexp
  4077. 'mouse-face 'highlight
  4078. 'help-echo (format "mouse-2 or RET jump to location")))
  4079. (full-words org-agenda-search-view-force-full-words)
  4080. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4081. regexp rtn rtnall files file pos inherited-tags
  4082. marker category category-pos level tags c neg re boolean
  4083. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4084. (unless (and (not edit-at)
  4085. (stringp string)
  4086. (string-match "\\S-" string))
  4087. (setq string (read-string
  4088. (if org-agenda-search-view-always-boolean
  4089. "[+-]Word/{Regexp} ...: "
  4090. "Phrase or [+-]Word/{Regexp} ...: ")
  4091. (cond
  4092. ((integerp edit-at) (cons string edit-at))
  4093. (edit-at string))
  4094. 'org-agenda-search-history)))
  4095. (catch 'exit
  4096. (if org-agenda-sticky
  4097. (setq org-agenda-buffer-name
  4098. (if (stringp string)
  4099. (format "*Org Agenda(%s:%s)*"
  4100. (or org-keys (or (and todo-only "S") "s")) string)
  4101. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4102. (org-agenda-prepare "SEARCH")
  4103. (org-compile-prefix-format 'search)
  4104. (org-set-sorting-strategy 'search)
  4105. (setq org-agenda-redo-command
  4106. (list 'org-search-view (if todo-only t nil)
  4107. (list 'if 'current-prefix-arg nil string)))
  4108. (setq org-agenda-query-string string)
  4109. (if (equal (string-to-char string) ?*)
  4110. (setq hdl-only t
  4111. words (substring string 1))
  4112. (setq words string))
  4113. (when (equal (string-to-char words) ?!)
  4114. (setq todo-only t
  4115. words (substring words 1)))
  4116. (when (equal (string-to-char words) ?:)
  4117. (setq full-words t
  4118. words (substring words 1)))
  4119. (if (or org-agenda-search-view-always-boolean
  4120. (member (string-to-char words) '(?- ?+ ?\{)))
  4121. (setq boolean t))
  4122. (setq words (org-split-string words))
  4123. (let (www w)
  4124. (while (setq w (pop words))
  4125. (while (and (string-match "\\\\\\'" w) words)
  4126. (setq w (concat (substring w 0 -1) " " (pop words))))
  4127. (push w www))
  4128. (setq words (nreverse www) www nil)
  4129. (while (setq w (pop words))
  4130. (when (and (string-match "\\`[-+]?{" w)
  4131. (not (string-match "}\\'" w)))
  4132. (while (and words (not (string-match "}\\'" (car words))))
  4133. (setq w (concat w " " (pop words))))
  4134. (setq w (concat w " " (pop words))))
  4135. (push w www))
  4136. (setq words (nreverse www)))
  4137. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4138. (when boolean
  4139. (let (wds w)
  4140. (while (setq w (pop words))
  4141. (if (or (equal (substring w 0 1) "\"")
  4142. (and (> (length w) 1)
  4143. (member (substring w 0 1) '("+" "-"))
  4144. (equal (substring w 1 2) "\"")))
  4145. (while (and words (not (equal (substring w -1) "\"")))
  4146. (setq w (concat w " " (pop words)))))
  4147. (and (string-match "\\`\\([-+]?\\)\"" w)
  4148. (setq w (replace-match "\\1" nil nil w)))
  4149. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4150. (push w wds))
  4151. (setq words (nreverse wds))))
  4152. (if boolean
  4153. (mapc (lambda (w)
  4154. (setq c (string-to-char w))
  4155. (if (equal c ?-)
  4156. (setq neg t w (substring w 1))
  4157. (if (equal c ?+)
  4158. (setq neg nil w (substring w 1))
  4159. (setq neg nil)))
  4160. (if (string-match "\\`{.*}\\'" w)
  4161. (setq re (substring w 1 -1))
  4162. (if full-words
  4163. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4164. (setq re (regexp-quote (downcase w)))))
  4165. (if neg (push re regexps-) (push re regexps+)))
  4166. words)
  4167. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4168. regexps+))
  4169. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4170. (if (not regexps+)
  4171. (setq regexp org-outline-regexp-bol)
  4172. (setq regexp (pop regexps+))
  4173. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4174. regexp))))
  4175. (setq files (org-agenda-files nil 'ifmode))
  4176. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4177. (pop org-agenda-text-search-extra-files)
  4178. (setq files (org-add-archive-files files)))
  4179. (setq files (append files org-agenda-text-search-extra-files)
  4180. rtnall nil)
  4181. (while (setq file (pop files))
  4182. (setq ee nil)
  4183. (catch 'nextfile
  4184. (org-check-agenda-file file)
  4185. (setq buffer (if (file-exists-p file)
  4186. (org-get-agenda-file-buffer file)
  4187. (error "No such file %s" file)))
  4188. (if (not buffer)
  4189. ;; If file does not exist, make sure an error message is sent
  4190. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4191. file))))
  4192. (with-current-buffer buffer
  4193. (with-syntax-table (org-search-syntax-table)
  4194. (unless (derived-mode-p 'org-mode)
  4195. (error "Agenda file %s is not in `org-mode'" file))
  4196. (let ((case-fold-search t))
  4197. (save-excursion
  4198. (save-restriction
  4199. (if (eq buffer org-agenda-restrict)
  4200. (narrow-to-region org-agenda-restrict-begin
  4201. org-agenda-restrict-end)
  4202. (widen))
  4203. (goto-char (point-min))
  4204. (unless (or (org-at-heading-p)
  4205. (outline-next-heading))
  4206. (throw 'nextfile t))
  4207. (goto-char (max (point-min) (1- (point))))
  4208. (while (re-search-forward regexp nil t)
  4209. (org-back-to-heading t)
  4210. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4211. (> (org-reduced-level (org-outline-level))
  4212. org-agenda-search-view-max-outline-level)
  4213. (forward-line -1)
  4214. (outline-back-to-heading t)))
  4215. (skip-chars-forward "* ")
  4216. (setq beg (point-at-bol)
  4217. beg1 (point)
  4218. end (progn
  4219. (outline-next-heading)
  4220. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4221. (> (org-reduced-level (org-outline-level))
  4222. org-agenda-search-view-max-outline-level)
  4223. (forward-line 1)
  4224. (outline-next-heading)))
  4225. (point)))
  4226. (catch :skip
  4227. (goto-char beg)
  4228. (org-agenda-skip)
  4229. (setq str (buffer-substring-no-properties
  4230. (point-at-bol)
  4231. (if hdl-only (point-at-eol) end)))
  4232. (mapc (lambda (wr) (when (string-match wr str)
  4233. (goto-char (1- end))
  4234. (throw :skip t)))
  4235. regexps-)
  4236. (mapc (lambda (wr) (unless (string-match wr str)
  4237. (goto-char (1- end))
  4238. (throw :skip t)))
  4239. (if todo-only
  4240. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4241. regexps+)
  4242. regexps+))
  4243. (goto-char beg)
  4244. (setq marker (org-agenda-new-marker (point))
  4245. category (org-get-category)
  4246. level (make-string (org-reduced-level (org-outline-level)) ? )
  4247. category-pos (get-text-property (point) 'org-category-position)
  4248. inherited-tags
  4249. (or (eq org-agenda-show-inherited-tags 'always)
  4250. (and (listp org-agenda-show-inherited-tags)
  4251. (memq 'todo org-agenda-show-inherited-tags))
  4252. (and (eq org-agenda-show-inherited-tags t)
  4253. (or (eq org-agenda-use-tag-inheritance t)
  4254. (memq 'todo org-agenda-use-tag-inheritance))))
  4255. tags (org-get-tags-at nil (not inherited-tags))
  4256. txt (org-agenda-format-item
  4257. ""
  4258. (buffer-substring-no-properties
  4259. beg1 (point-at-eol))
  4260. level category tags t))
  4261. (org-add-props txt props
  4262. 'org-marker marker 'org-hd-marker marker
  4263. 'org-todo-regexp org-todo-regexp
  4264. 'level level
  4265. 'org-complex-heading-regexp org-complex-heading-regexp
  4266. 'priority 1000 'org-category category
  4267. 'org-category-position category-pos
  4268. 'type "search")
  4269. (push txt ee)
  4270. (goto-char (1- end))))))))))
  4271. (setq rtn (nreverse ee))
  4272. (setq rtnall (append rtnall rtn)))
  4273. (if org-agenda-overriding-header
  4274. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4275. nil 'face 'org-agenda-structure) "\n")
  4276. (insert "Search words: ")
  4277. (add-text-properties (point-min) (1- (point))
  4278. (list 'face 'org-agenda-structure))
  4279. (setq pos (point))
  4280. (insert string "\n")
  4281. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4282. (setq pos (point))
  4283. (unless org-agenda-multi
  4284. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4285. (add-text-properties pos (1- (point))
  4286. (list 'face 'org-agenda-structure))))
  4287. (org-agenda-mark-header-line (point-min))
  4288. (when rtnall
  4289. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4290. (goto-char (point-min))
  4291. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4292. (add-text-properties (point-min) (point-max)
  4293. `(org-agenda-type search
  4294. org-last-args (,todo-only ,string ,edit-at)
  4295. org-redo-cmd ,org-agenda-redo-command
  4296. org-series-cmd ,org-cmd))
  4297. (org-agenda-finalize)
  4298. (setq buffer-read-only t))))
  4299. ;;; Agenda TODO list
  4300. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4301. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4302. (concat
  4303. (if (or (equal keywords "ALL") (not keywords))
  4304. (propertize "ALL" 'face 'warning)
  4305. (mapconcat
  4306. (lambda (kw)
  4307. (propertize kw 'face (org-get-todo-face kw)))
  4308. (org-split-string keywords "|")
  4309. "|"))
  4310. "\n"))
  4311. (defvar org-select-this-todo-keyword nil)
  4312. (defvar org-last-arg nil)
  4313. ;;;###autoload
  4314. (defun org-todo-list (&optional arg)
  4315. "Show all (not done) TODO entries from all agenda file in a single list.
  4316. The prefix arg can be used to select a specific TODO keyword and limit
  4317. the list to these. When using \\[universal-argument], you will be prompted
  4318. for a keyword. A numeric prefix directly selects the Nth keyword in
  4319. `org-todo-keywords-1'."
  4320. (interactive "P")
  4321. (if org-agenda-overriding-arguments
  4322. (setq arg org-agenda-overriding-arguments))
  4323. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4324. (let* ((today (org-today))
  4325. (date (calendar-gregorian-from-absolute today))
  4326. (kwds org-todo-keywords-for-agenda)
  4327. (completion-ignore-case t)
  4328. (org-select-this-todo-keyword
  4329. (if (stringp arg) arg
  4330. (and arg (integerp arg) (> arg 0)
  4331. (nth (1- arg) kwds))))
  4332. rtn rtnall files file pos)
  4333. (when (equal arg '(4))
  4334. (setq org-select-this-todo-keyword
  4335. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4336. (mapcar 'list kwds) nil nil)))
  4337. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4338. (catch 'exit
  4339. (if org-agenda-sticky
  4340. (setq org-agenda-buffer-name
  4341. (if (stringp org-select-this-todo-keyword)
  4342. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4343. org-select-this-todo-keyword)
  4344. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4345. (org-agenda-prepare "TODO")
  4346. (org-compile-prefix-format 'todo)
  4347. (org-set-sorting-strategy 'todo)
  4348. (setq org-agenda-redo-command
  4349. `(org-todo-list (or (and (numberp current-prefix-arg)
  4350. current-prefix-arg)
  4351. ,org-select-this-todo-keyword
  4352. current-prefix-arg ,arg)))
  4353. (setq files (org-agenda-files nil 'ifmode)
  4354. rtnall nil)
  4355. (while (setq file (pop files))
  4356. (catch 'nextfile
  4357. (org-check-agenda-file file)
  4358. (setq rtn (org-agenda-get-day-entries file date :todo))
  4359. (setq rtnall (append rtnall rtn))))
  4360. (if org-agenda-overriding-header
  4361. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4362. nil 'face 'org-agenda-structure) "\n")
  4363. (insert "Global list of TODO items of type: ")
  4364. (add-text-properties (point-min) (1- (point))
  4365. (list 'face 'org-agenda-structure
  4366. 'short-heading
  4367. (concat "ToDo: "
  4368. (or org-select-this-todo-keyword "ALL"))))
  4369. (org-agenda-mark-header-line (point-min))
  4370. (insert (org-agenda-propertize-selected-todo-keywords
  4371. org-select-this-todo-keyword))
  4372. (setq pos (point))
  4373. (unless org-agenda-multi
  4374. (insert "Available with `N r': (0)[ALL]")
  4375. (let ((n 0) s)
  4376. (mapc (lambda (x)
  4377. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4378. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4379. (insert "\n "))
  4380. (insert " " s))
  4381. kwds))
  4382. (insert "\n"))
  4383. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4384. (org-agenda-mark-header-line (point-min))
  4385. (when rtnall
  4386. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4387. (goto-char (point-min))
  4388. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4389. (add-text-properties (point-min) (point-max)
  4390. `(org-agenda-type todo
  4391. org-last-args ,arg
  4392. org-redo-cmd ,org-agenda-redo-command
  4393. org-series-cmd ,org-cmd))
  4394. (org-agenda-finalize)
  4395. (setq buffer-read-only t))))
  4396. ;;; Agenda tags match
  4397. ;;;###autoload
  4398. (defun org-tags-view (&optional todo-only match)
  4399. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4400. The prefix arg TODO-ONLY limits the search to TODO entries."
  4401. (interactive "P")
  4402. (if org-agenda-overriding-arguments
  4403. (setq todo-only (car org-agenda-overriding-arguments)
  4404. match (nth 1 org-agenda-overriding-arguments)))
  4405. (let* ((org-tags-match-list-sublevels
  4406. org-tags-match-list-sublevels)
  4407. (completion-ignore-case t)
  4408. rtn rtnall files file pos matcher
  4409. buffer)
  4410. (when (and (stringp match) (not (string-match "\\S-" match)))
  4411. (setq match nil))
  4412. (catch 'exit
  4413. (if org-agenda-sticky
  4414. (setq org-agenda-buffer-name
  4415. (if (stringp match)
  4416. (format "*Org Agenda(%s:%s)*"
  4417. (or org-keys (or (and todo-only "M") "m")) match)
  4418. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4419. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4420. ;; expanding tags within `org-make-tags-matcher'
  4421. (org-agenda-prepare (concat "TAGS " match))
  4422. (setq matcher (org-make-tags-matcher match)
  4423. match (car matcher) matcher (cdr matcher))
  4424. (org-compile-prefix-format 'tags)
  4425. (org-set-sorting-strategy 'tags)
  4426. (setq org-agenda-query-string match)
  4427. (setq org-agenda-redo-command
  4428. (list 'org-tags-view `(quote ,todo-only)
  4429. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4430. (setq files (org-agenda-files nil 'ifmode)
  4431. rtnall nil)
  4432. (while (setq file (pop files))
  4433. (catch 'nextfile
  4434. (org-check-agenda-file file)
  4435. (setq buffer (if (file-exists-p file)
  4436. (org-get-agenda-file-buffer file)
  4437. (error "No such file %s" file)))
  4438. (if (not buffer)
  4439. ;; If file does not exist, error message to agenda
  4440. (setq rtn (list
  4441. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4442. rtnall (append rtnall rtn))
  4443. (with-current-buffer buffer
  4444. (unless (derived-mode-p 'org-mode)
  4445. (error "Agenda file %s is not in `org-mode'" file))
  4446. (save-excursion
  4447. (save-restriction
  4448. (if (eq buffer org-agenda-restrict)
  4449. (narrow-to-region org-agenda-restrict-begin
  4450. org-agenda-restrict-end)
  4451. (widen))
  4452. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4453. (setq rtnall (append rtnall rtn))))))))
  4454. (if org-agenda-overriding-header
  4455. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4456. nil 'face 'org-agenda-structure) "\n")
  4457. (insert "Headlines with TAGS match: ")
  4458. (add-text-properties (point-min) (1- (point))
  4459. (list 'face 'org-agenda-structure
  4460. 'short-heading
  4461. (concat "Match: " match)))
  4462. (setq pos (point))
  4463. (insert match "\n")
  4464. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4465. (setq pos (point))
  4466. (unless org-agenda-multi
  4467. (insert "Press `C-u r' to search again with new search string\n"))
  4468. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4469. (org-agenda-mark-header-line (point-min))
  4470. (when rtnall
  4471. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4472. (goto-char (point-min))
  4473. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4474. (add-text-properties (point-min) (point-max)
  4475. `(org-agenda-type tags
  4476. org-last-args (,todo-only ,match)
  4477. org-redo-cmd ,org-agenda-redo-command
  4478. org-series-cmd ,org-cmd))
  4479. (org-agenda-finalize)
  4480. (setq buffer-read-only t))))
  4481. ;;; Agenda Finding stuck projects
  4482. (defvar org-agenda-skip-regexp nil
  4483. "Regular expression used in skipping subtrees for the agenda.
  4484. This is basically a temporary global variable that can be set and then
  4485. used by user-defined selections using `org-agenda-skip-function'.")
  4486. (defvar org-agenda-overriding-header nil
  4487. "When set during agenda, todo and tags searches it replaces the header.
  4488. This variable should not be set directly, but custom commands can bind it
  4489. in the options section.")
  4490. (defun org-agenda-skip-entry-when-regexp-matches ()
  4491. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4492. If yes, it returns the end position of this entry, causing agenda commands
  4493. to skip the entry but continuing the search in the subtree. This is a
  4494. function that can be put into `org-agenda-skip-function' for the duration
  4495. of a command."
  4496. (let ((end (save-excursion (org-end-of-subtree t)))
  4497. skip)
  4498. (save-excursion
  4499. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4500. (and skip end)))
  4501. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4502. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4503. If yes, it returns the end position of this tree, causing agenda commands
  4504. to skip this subtree. This is a function that can be put into
  4505. `org-agenda-skip-function' for the duration of a command."
  4506. (let ((end (save-excursion (org-end-of-subtree t)))
  4507. skip)
  4508. (save-excursion
  4509. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4510. (and skip end)))
  4511. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4512. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4513. If yes, it returns the end position of the current entry (NOT the tree),
  4514. causing agenda commands to skip the entry but continuing the search in
  4515. the subtree. This is a function that can be put into
  4516. `org-agenda-skip-function' for the duration of a command. An important
  4517. use of this function is for the stuck project list."
  4518. (let ((end (save-excursion (org-end-of-subtree t)))
  4519. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4520. skip)
  4521. (save-excursion
  4522. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4523. (and skip entry-end)))
  4524. (defun org-agenda-skip-entry-if (&rest conditions)
  4525. "Skip entry if any of CONDITIONS is true.
  4526. See `org-agenda-skip-if' for details."
  4527. (org-agenda-skip-if nil conditions))
  4528. (defun org-agenda-skip-subtree-if (&rest conditions)
  4529. "Skip subtree if any of CONDITIONS is true.
  4530. See `org-agenda-skip-if' for details."
  4531. (org-agenda-skip-if t conditions))
  4532. (defun org-agenda-skip-if (subtree conditions)
  4533. "Checks current entity for CONDITIONS.
  4534. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4535. the entry (i.e. the text before the next heading) is checked.
  4536. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4537. from different tests. Valid conditions are:
  4538. scheduled Check if there is a scheduled cookie
  4539. notscheduled Check if there is no scheduled cookie
  4540. deadline Check if there is a deadline
  4541. notdeadline Check if there is no deadline
  4542. timestamp Check if there is a timestamp (also deadline or scheduled)
  4543. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4544. regexp Check if regexp matches
  4545. notregexp Check if regexp does not match.
  4546. todo Check if TODO keyword matches
  4547. nottodo Check if TODO keyword does not match
  4548. The regexp is taken from the conditions list, it must come right after
  4549. the `regexp' or `notregexp' element.
  4550. `todo' and `nottodo' accept as an argument a list of todo
  4551. keywords, which may include \"*\" to match any todo keyword.
  4552. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4553. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4554. Instead of a list, a keyword class may be given. For example:
  4555. (org-agenda-skip-entry-if 'nottodo 'done)
  4556. would skip entries that haven't been marked with any of \"DONE\"
  4557. keywords. Possible classes are: `todo', `done', `any'.
  4558. If any of these conditions is met, this function returns the end point of
  4559. the entity, causing the search to continue from there. This is a function
  4560. that can be put into `org-agenda-skip-function' for the duration of a command."
  4561. (let (beg end m)
  4562. (org-back-to-heading t)
  4563. (setq beg (point)
  4564. end (if subtree
  4565. (progn (org-end-of-subtree t) (point))
  4566. (progn (outline-next-heading) (1- (point)))))
  4567. (goto-char beg)
  4568. (and
  4569. (or
  4570. (and (memq 'scheduled conditions)
  4571. (re-search-forward org-scheduled-time-regexp end t))
  4572. (and (memq 'notscheduled conditions)
  4573. (not (re-search-forward org-scheduled-time-regexp end t)))
  4574. (and (memq 'deadline conditions)
  4575. (re-search-forward org-deadline-time-regexp end t))
  4576. (and (memq 'notdeadline conditions)
  4577. (not (re-search-forward org-deadline-time-regexp end t)))
  4578. (and (memq 'timestamp conditions)
  4579. (re-search-forward org-ts-regexp end t))
  4580. (and (memq 'nottimestamp conditions)
  4581. (not (re-search-forward org-ts-regexp end t)))
  4582. (and (setq m (memq 'regexp conditions))
  4583. (stringp (nth 1 m))
  4584. (re-search-forward (nth 1 m) end t))
  4585. (and (setq m (memq 'notregexp conditions))
  4586. (stringp (nth 1 m))
  4587. (not (re-search-forward (nth 1 m) end t)))
  4588. (and (or
  4589. (setq m (memq 'nottodo conditions))
  4590. (setq m (memq 'todo-unblocked conditions))
  4591. (setq m (memq 'nottodo-unblocked conditions))
  4592. (setq m (memq 'todo conditions)))
  4593. (org-agenda-skip-if-todo m end)))
  4594. end)))
  4595. (defun org-agenda-skip-if-todo (args end)
  4596. "Helper function for `org-agenda-skip-if', do not use it directly.
  4597. ARGS is a list with first element either `todo', `nottodo',
  4598. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4599. a list of TODO keywords, or a state symbol `todo' or `done' or
  4600. `any'."
  4601. (let ((kw (car args))
  4602. (arg (cadr args))
  4603. todo-wds todo-re)
  4604. (setq todo-wds
  4605. (org-uniquify
  4606. (cond
  4607. ((listp arg) ;; list of keywords
  4608. (if (member "*" arg)
  4609. (mapcar 'substring-no-properties org-todo-keywords-1)
  4610. arg))
  4611. ((symbolp arg) ;; keyword class name
  4612. (cond
  4613. ((eq arg 'todo)
  4614. (org-delete-all org-done-keywords
  4615. (mapcar 'substring-no-properties
  4616. org-todo-keywords-1)))
  4617. ((eq arg 'done) org-done-keywords)
  4618. ((eq arg 'any)
  4619. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4620. (setq todo-re
  4621. (concat "^\\*+[ \t]+\\<\\("
  4622. (mapconcat 'identity todo-wds "\\|")
  4623. "\\)\\>"))
  4624. (cond
  4625. ((eq kw 'todo) (re-search-forward todo-re end t))
  4626. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4627. ((eq kw 'todo-unblocked)
  4628. (catch 'unblocked
  4629. (while (re-search-forward todo-re end t)
  4630. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4631. nil))
  4632. ((eq kw 'nottodo-unblocked)
  4633. (catch 'unblocked
  4634. (while (re-search-forward todo-re end t)
  4635. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4636. t))
  4637. )))
  4638. ;;;###autoload
  4639. (defun org-agenda-list-stuck-projects (&rest ignore)
  4640. "Create agenda view for projects that are stuck.
  4641. Stuck projects are project that have no next actions. For the definitions
  4642. of what a project is and how to check if it stuck, customize the variable
  4643. `org-stuck-projects'."
  4644. (interactive)
  4645. (let* ((org-agenda-skip-function
  4646. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4647. ;; We could have used org-agenda-skip-if here.
  4648. (org-agenda-overriding-header
  4649. (or org-agenda-overriding-header "List of stuck projects: "))
  4650. (matcher (nth 0 org-stuck-projects))
  4651. (todo (nth 1 org-stuck-projects))
  4652. (todo-wds (if (member "*" todo)
  4653. (progn
  4654. (org-agenda-prepare-buffers (org-agenda-files
  4655. nil 'ifmode))
  4656. (org-delete-all
  4657. org-done-keywords-for-agenda
  4658. (copy-sequence org-todo-keywords-for-agenda)))
  4659. todo))
  4660. (todo-re (concat "^\\*+[ \t]+\\("
  4661. (mapconcat 'identity todo-wds "\\|")
  4662. "\\)\\>"))
  4663. (tags (nth 2 org-stuck-projects))
  4664. (tags-re (if (member "*" tags)
  4665. (concat org-outline-regexp-bol
  4666. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4667. (if tags
  4668. (concat org-outline-regexp-bol
  4669. ".*:\\("
  4670. (mapconcat 'identity tags "\\|")
  4671. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4672. (gen-re (nth 3 org-stuck-projects))
  4673. (re-list
  4674. (delq nil
  4675. (list
  4676. (if todo todo-re)
  4677. (if tags tags-re)
  4678. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4679. gen-re)))))
  4680. (setq org-agenda-skip-regexp
  4681. (if re-list
  4682. (mapconcat 'identity re-list "\\|")
  4683. (error "No information how to identify unstuck projects")))
  4684. (org-tags-view nil matcher)
  4685. (with-current-buffer org-agenda-buffer-name
  4686. (setq org-agenda-redo-command
  4687. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4688. ;;; Diary integration
  4689. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4690. (defvar diary-list-entries-hook)
  4691. (defvar diary-time-regexp)
  4692. (defun org-get-entries-from-diary (date)
  4693. "Get the (Emacs Calendar) diary entries for DATE."
  4694. (require 'diary-lib)
  4695. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4696. (diary-display-hook '(fancy-diary-display))
  4697. (diary-display-function 'fancy-diary-display)
  4698. (pop-up-frames nil)
  4699. (diary-list-entries-hook
  4700. (cons 'org-diary-default-entry diary-list-entries-hook))
  4701. (diary-file-name-prefix nil) ; turn this feature off
  4702. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4703. entries
  4704. (org-disable-agenda-to-diary t))
  4705. (save-excursion
  4706. (save-window-excursion
  4707. (funcall (if (fboundp 'diary-list-entries)
  4708. 'diary-list-entries 'list-diary-entries)
  4709. date 1)))
  4710. (if (not (get-buffer diary-fancy-buffer))
  4711. (setq entries nil)
  4712. (with-current-buffer diary-fancy-buffer
  4713. (setq buffer-read-only nil)
  4714. (if (zerop (buffer-size))
  4715. ;; No entries
  4716. (setq entries nil)
  4717. ;; Omit the date and other unnecessary stuff
  4718. (org-agenda-cleanup-fancy-diary)
  4719. ;; Add prefix to each line and extend the text properties
  4720. (if (zerop (buffer-size))
  4721. (setq entries nil)
  4722. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4723. (setq entries
  4724. (with-temp-buffer
  4725. (insert entries) (goto-char (point-min))
  4726. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4727. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4728. (replace-match (concat "; " (match-string 1)))))
  4729. (buffer-string)))))
  4730. (set-buffer-modified-p nil)
  4731. (kill-buffer diary-fancy-buffer)))
  4732. (when entries
  4733. (setq entries (org-split-string entries "\n"))
  4734. (setq entries
  4735. (mapcar
  4736. (lambda (x)
  4737. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4738. ;; Extend the text properties to the beginning of the line
  4739. (org-add-props x (text-properties-at (1- (length x)) x)
  4740. 'type "diary" 'date date 'face 'org-agenda-diary))
  4741. entries)))))
  4742. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4743. "Hook run when the fancy diary buffer is cleaned up.")
  4744. (defun org-agenda-cleanup-fancy-diary ()
  4745. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4746. This gets rid of the date, the underline under the date, and
  4747. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4748. date. It also removes lines that contain only whitespace."
  4749. (goto-char (point-min))
  4750. (if (looking-at ".*?:[ \t]*")
  4751. (progn
  4752. (replace-match "")
  4753. (re-search-forward "\n=+$" nil t)
  4754. (replace-match "")
  4755. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4756. (re-search-forward "\n=+$" nil t)
  4757. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4758. (goto-char (point-min))
  4759. (while (re-search-forward "^ +\n" nil t)
  4760. (replace-match ""))
  4761. (goto-char (point-min))
  4762. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4763. (replace-match ""))
  4764. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4765. ;; Make sure entries from the diary have the right text properties.
  4766. (eval-after-load "diary-lib"
  4767. '(if (boundp 'diary-modify-entry-list-string-function)
  4768. ;; We can rely on the hook, nothing to do
  4769. nil
  4770. ;; Hook not available, must use advice to make this work
  4771. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4772. "Make the position visible."
  4773. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4774. (stringp string)
  4775. buffer-file-name)
  4776. (setq string (org-modify-diary-entry-string string))))))
  4777. (defun org-modify-diary-entry-string (string)
  4778. "Add text properties to string, allowing org-mode to act on it."
  4779. (org-add-props string nil
  4780. 'mouse-face 'highlight
  4781. 'help-echo (if buffer-file-name
  4782. (format "mouse-2 or RET jump to diary file %s"
  4783. (abbreviate-file-name buffer-file-name))
  4784. "")
  4785. 'org-agenda-diary-link t
  4786. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4787. (defun org-diary-default-entry ()
  4788. "Add a dummy entry to the diary.
  4789. Needed to avoid empty dates which mess up holiday display."
  4790. ;; Catch the error if dealing with the new add-to-diary-alist
  4791. (when org-disable-agenda-to-diary
  4792. (condition-case nil
  4793. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4794. (error
  4795. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4796. (defun org-add-to-diary-list (&rest args)
  4797. (if (fboundp 'diary-add-to-list)
  4798. (apply 'diary-add-to-list args)
  4799. (apply 'add-to-diary-list args)))
  4800. (defvar org-diary-last-run-time nil)
  4801. ;;;###autoload
  4802. (defun org-diary (&rest args)
  4803. "Return diary information from org files.
  4804. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4805. It accesses org files and extracts information from those files to be
  4806. listed in the diary. The function accepts arguments specifying what
  4807. items should be listed. For a list of arguments allowed here, see the
  4808. variable `org-agenda-entry-types'.
  4809. The call in the diary file should look like this:
  4810. &%%(org-diary) ~/path/to/some/orgfile.org
  4811. Use a separate line for each org file to check. Or, if you omit the file name,
  4812. all files listed in `org-agenda-files' will be checked automatically:
  4813. &%%(org-diary)
  4814. If you don't give any arguments (as in the example above), the default value
  4815. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4816. So the example above may also be written as
  4817. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4818. The function expects the lisp variables `entry' and `date' to be provided
  4819. by the caller, because this is how the calendar works. Don't use this
  4820. function from a program - use `org-agenda-get-day-entries' instead."
  4821. (when (> (- (org-float-time)
  4822. org-agenda-last-marker-time)
  4823. 5)
  4824. ;; I am not sure if this works with sticky agendas, because the marker
  4825. ;; list is then no longer a global variable.
  4826. (org-agenda-reset-markers))
  4827. (org-compile-prefix-format 'agenda)
  4828. (org-set-sorting-strategy 'agenda)
  4829. (setq args (or args org-agenda-entry-types))
  4830. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4831. (list entry)
  4832. (org-agenda-files t)))
  4833. (time (org-float-time))
  4834. file rtn results)
  4835. (when (or (not org-diary-last-run-time)
  4836. (> (- time
  4837. org-diary-last-run-time)
  4838. 3))
  4839. (org-agenda-prepare-buffers files))
  4840. (setq org-diary-last-run-time time)
  4841. ;; If this is called during org-agenda, don't return any entries to
  4842. ;; the calendar. Org Agenda will list these entries itself.
  4843. (if org-disable-agenda-to-diary (setq files nil))
  4844. (while (setq file (pop files))
  4845. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4846. (setq results (append results rtn)))
  4847. (when results
  4848. (setq results
  4849. (mapcar (lambda (i) (replace-regexp-in-string
  4850. org-bracket-link-regexp "\\3" i)) results))
  4851. (concat (org-agenda-finalize-entries results) "\n"))))
  4852. ;;; Agenda entry finders
  4853. (defun org-agenda-get-day-entries (file date &rest args)
  4854. "Does the work for `org-diary' and `org-agenda'.
  4855. FILE is the path to a file to be checked for entries. DATE is date like
  4856. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4857. which kind of entries should be extracted. For details about these, see
  4858. the documentation of `org-diary'."
  4859. (setq args (or args org-agenda-entry-types))
  4860. (let* ((org-startup-folded nil)
  4861. (org-startup-align-all-tables nil)
  4862. (buffer (if (file-exists-p file)
  4863. (org-get-agenda-file-buffer file)
  4864. (error "No such file %s" file)))
  4865. arg results rtn deadline-results)
  4866. (if (not buffer)
  4867. ;; If file does not exist, make sure an error message ends up in diary
  4868. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4869. (with-current-buffer buffer
  4870. (unless (derived-mode-p 'org-mode)
  4871. (error "Agenda file %s is not in `org-mode'" file))
  4872. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4873. (let ((case-fold-search nil))
  4874. (save-excursion
  4875. (save-restriction
  4876. (if (eq buffer org-agenda-restrict)
  4877. (narrow-to-region org-agenda-restrict-begin
  4878. org-agenda-restrict-end)
  4879. (widen))
  4880. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4881. (while (setq arg (pop args))
  4882. (cond
  4883. ((and (eq arg :todo)
  4884. (equal date (calendar-gregorian-from-absolute
  4885. (org-today))))
  4886. (setq rtn (org-agenda-get-todos))
  4887. (setq results (append results rtn)))
  4888. ((eq arg :timestamp)
  4889. (setq rtn (org-agenda-get-blocks))
  4890. (setq results (append results rtn))
  4891. (setq rtn (org-agenda-get-timestamps deadline-results))
  4892. (setq results (append results rtn)))
  4893. ((eq arg :sexp)
  4894. (setq rtn (org-agenda-get-sexps))
  4895. (setq results (append results rtn)))
  4896. ((eq arg :scheduled)
  4897. (setq rtn (org-agenda-get-scheduled deadline-results))
  4898. (setq results (append results rtn)))
  4899. ((eq arg :scheduled*)
  4900. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4901. (setq results (append results rtn)))
  4902. ((eq arg :closed)
  4903. (setq rtn (org-agenda-get-progress))
  4904. (setq results (append results rtn)))
  4905. ((eq arg :deadline)
  4906. (setq rtn (org-agenda-get-deadlines))
  4907. (setq deadline-results (copy-sequence rtn))
  4908. (setq results (append results rtn)))
  4909. ((eq arg :deadline*)
  4910. (setq rtn (org-agenda-get-deadlines t))
  4911. (setq deadline-results (copy-sequence rtn))
  4912. (setq results (append results rtn))))))))
  4913. results))))
  4914. (defsubst org-em (x y list)
  4915. "Is X or Y a member of LIST?"
  4916. (or (memq x list) (memq y list)))
  4917. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4918. (defvar org-agenda-sorting-strategy-selected nil)
  4919. (defun org-agenda-get-todos ()
  4920. "Return the TODO information for agenda display."
  4921. (let* ((props (list 'face nil
  4922. 'done-face 'org-agenda-done
  4923. 'org-not-done-regexp org-not-done-regexp
  4924. 'org-todo-regexp org-todo-regexp
  4925. 'org-complex-heading-regexp org-complex-heading-regexp
  4926. 'mouse-face 'highlight
  4927. 'help-echo
  4928. (format "mouse-2 or RET jump to org file %s"
  4929. (abbreviate-file-name buffer-file-name))))
  4930. (regexp (format org-heading-keyword-regexp-format
  4931. (cond
  4932. ((and org-select-this-todo-keyword
  4933. (equal org-select-this-todo-keyword "*"))
  4934. org-todo-regexp)
  4935. (org-select-this-todo-keyword
  4936. (concat "\\("
  4937. (mapconcat 'identity
  4938. (org-split-string
  4939. org-select-this-todo-keyword
  4940. "|")
  4941. "\\|") "\\)"))
  4942. (t org-not-done-regexp))))
  4943. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4944. ee txt beg end inherited-tags todo-state-end-pos)
  4945. (goto-char (point-min))
  4946. (while (re-search-forward regexp nil t)
  4947. (catch :skip
  4948. (save-match-data
  4949. (beginning-of-line)
  4950. (org-agenda-skip)
  4951. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4952. (unless (and (setq todo-state (org-get-todo-state))
  4953. (setq todo-state-end-pos (match-end 2)))
  4954. (goto-char end)
  4955. (throw :skip nil))
  4956. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4957. (goto-char (1+ beg))
  4958. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4959. (throw :skip nil)))
  4960. (goto-char (match-beginning 2))
  4961. (setq marker (org-agenda-new-marker (match-beginning 0))
  4962. category (org-get-category)
  4963. ts-date (let (ts)
  4964. (save-match-data
  4965. (cond ((org-em 'scheduled-up 'scheduled-down
  4966. org-agenda-sorting-strategy-selected)
  4967. (setq ts (org-entry-get (point) "SCHEDULED")
  4968. ts-date-type " scheduled"))
  4969. ((org-em 'deadline-up 'deadline-down
  4970. org-agenda-sorting-strategy-selected)
  4971. (setq ts (org-entry-get (point) "DEADLINE")
  4972. ts-date-type " deadline"))
  4973. ((org-em 'ts-up 'ts-down
  4974. org-agenda-sorting-strategy-selected)
  4975. (setq ts (org-entry-get (point) "TIMESTAMP")
  4976. ts-date-type " timestamp"))
  4977. ((org-em 'tsia-up 'tsia-down
  4978. org-agenda-sorting-strategy-selected)
  4979. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4980. ts-date-type " timestamp_ia"))
  4981. ((org-em 'timestamp-up 'timestamp-down
  4982. org-agenda-sorting-strategy-selected)
  4983. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4984. (org-entry-get (point) "DEADLINE")
  4985. (org-entry-get (point) "TIMESTAMP")
  4986. (org-entry-get (point) "TIMESTAMP_IA"))
  4987. ts-date-type ""))
  4988. (t (setq ts-date-type "")))
  4989. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4990. category-pos (get-text-property (point) 'org-category-position)
  4991. txt (org-trim
  4992. (buffer-substring (match-beginning 2) (match-end 0)))
  4993. inherited-tags
  4994. (or (eq org-agenda-show-inherited-tags 'always)
  4995. (and (listp org-agenda-show-inherited-tags)
  4996. (memq 'todo org-agenda-show-inherited-tags))
  4997. (and (eq org-agenda-show-inherited-tags t)
  4998. (or (eq org-agenda-use-tag-inheritance t)
  4999. (memq 'todo org-agenda-use-tag-inheritance))))
  5000. tags (org-get-tags-at nil (not inherited-tags))
  5001. level (make-string (org-reduced-level (org-outline-level)) ? )
  5002. txt (org-agenda-format-item "" txt level category tags t)
  5003. priority (1+ (org-get-priority txt)))
  5004. (org-add-props txt props
  5005. 'org-marker marker 'org-hd-marker marker
  5006. 'priority priority 'org-category category
  5007. 'level level
  5008. 'ts-date ts-date
  5009. 'org-category-position category-pos
  5010. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5011. (push txt ee)
  5012. (if org-agenda-todo-list-sublevels
  5013. (goto-char todo-state-end-pos)
  5014. (org-end-of-subtree 'invisible))))
  5015. (nreverse ee)))
  5016. (defun org-agenda-todo-custom-ignore-p (time n)
  5017. "Check whether timestamp is farther away than n number of days.
  5018. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5019. `org-agenda-todo-ignore-scheduled' or
  5020. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5021. (let ((days (org-time-stamp-to-now
  5022. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5023. (if (>= n 0)
  5024. (>= days n)
  5025. (<= days n))))
  5026. ;;;###autoload
  5027. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5028. (&optional end)
  5029. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5030. (when (or org-agenda-todo-ignore-with-date
  5031. org-agenda-todo-ignore-scheduled
  5032. org-agenda-todo-ignore-deadlines
  5033. org-agenda-todo-ignore-timestamp)
  5034. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5035. (save-excursion
  5036. (or (and org-agenda-todo-ignore-with-date
  5037. (re-search-forward org-ts-regexp end t))
  5038. (and org-agenda-todo-ignore-scheduled
  5039. (re-search-forward org-scheduled-time-regexp end t)
  5040. (cond
  5041. ((eq org-agenda-todo-ignore-scheduled 'future)
  5042. (> (org-time-stamp-to-now
  5043. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5044. ((eq org-agenda-todo-ignore-scheduled 'past)
  5045. (<= (org-time-stamp-to-now
  5046. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5047. ((numberp org-agenda-todo-ignore-scheduled)
  5048. (org-agenda-todo-custom-ignore-p
  5049. (match-string 1) org-agenda-todo-ignore-scheduled))
  5050. (t)))
  5051. (and org-agenda-todo-ignore-deadlines
  5052. (re-search-forward org-deadline-time-regexp end t)
  5053. (cond
  5054. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5055. ((eq org-agenda-todo-ignore-deadlines 'far)
  5056. (not (org-deadline-close (match-string 1))))
  5057. ((eq org-agenda-todo-ignore-deadlines 'future)
  5058. (> (org-time-stamp-to-now
  5059. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5060. ((eq org-agenda-todo-ignore-deadlines 'past)
  5061. (<= (org-time-stamp-to-now
  5062. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5063. ((numberp org-agenda-todo-ignore-deadlines)
  5064. (org-agenda-todo-custom-ignore-p
  5065. (match-string 1) org-agenda-todo-ignore-deadlines))
  5066. (t (org-deadline-close (match-string 1)))))
  5067. (and org-agenda-todo-ignore-timestamp
  5068. (let ((buffer (current-buffer))
  5069. (regexp
  5070. (concat
  5071. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5072. (start (point)))
  5073. ;; Copy current buffer into a temporary one
  5074. (with-temp-buffer
  5075. (insert-buffer-substring buffer start end)
  5076. (goto-char (point-min))
  5077. ;; Delete SCHEDULED and DEADLINE items
  5078. (while (re-search-forward regexp end t)
  5079. (delete-region (match-beginning 0) (match-end 0)))
  5080. (goto-char (point-min))
  5081. ;; No search for timestamp left
  5082. (when (re-search-forward org-ts-regexp nil t)
  5083. (cond
  5084. ((eq org-agenda-todo-ignore-timestamp 'future)
  5085. (> (org-time-stamp-to-now
  5086. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5087. ((eq org-agenda-todo-ignore-timestamp 'past)
  5088. (<= (org-time-stamp-to-now
  5089. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5090. ((numberp org-agenda-todo-ignore-timestamp)
  5091. (org-agenda-todo-custom-ignore-p
  5092. (match-string 1) org-agenda-todo-ignore-timestamp))
  5093. (t))))))))))
  5094. (defun org-agenda-get-timestamps (&optional deadline-results)
  5095. "Return the date stamp information for agenda display."
  5096. (let* ((props (list 'face 'org-agenda-calendar-event
  5097. 'org-not-done-regexp org-not-done-regexp
  5098. 'org-todo-regexp org-todo-regexp
  5099. 'org-complex-heading-regexp org-complex-heading-regexp
  5100. 'mouse-face 'highlight
  5101. 'help-echo
  5102. (format "mouse-2 or RET jump to org file %s"
  5103. (abbreviate-file-name buffer-file-name))))
  5104. (d1 (calendar-absolute-from-gregorian date))
  5105. mm
  5106. (deadline-position-alist
  5107. (mapcar (lambda (a) (and (setq mm (get-text-property
  5108. 0 'org-hd-marker a))
  5109. (cons (marker-position mm) a)))
  5110. deadline-results))
  5111. (remove-re org-ts-regexp)
  5112. (regexp
  5113. (concat
  5114. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5115. (regexp-quote
  5116. (substring
  5117. (format-time-string
  5118. (car org-time-stamp-formats)
  5119. (apply 'encode-time ; DATE bound by calendar
  5120. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5121. 1 11))
  5122. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5123. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5124. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5125. donep tmp priority category category-pos level ee txt timestr tags
  5126. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5127. inherited-tags ts-date)
  5128. (goto-char (point-min))
  5129. (while (setq end-of-match (re-search-forward regexp nil t))
  5130. (setq b0 (match-beginning 0)
  5131. b3 (match-beginning 3) e3 (match-end 3)
  5132. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5133. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5134. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5135. (member todo-state
  5136. org-agenda-repeating-timestamp-show-all)))
  5137. (catch :skip
  5138. (and (org-at-date-range-p) (throw :skip nil))
  5139. (org-agenda-skip)
  5140. (if (and (match-end 1)
  5141. (not (= d1 (org-time-string-to-absolute
  5142. (match-string 1) d1 nil show-all
  5143. (current-buffer) b0))))
  5144. (throw :skip nil))
  5145. (if (and e3
  5146. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5147. (throw :skip nil))
  5148. (setq tmp (buffer-substring (max (point-min)
  5149. (- b0 org-ds-keyword-length))
  5150. b0)
  5151. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5152. inactivep (= (char-after b0) ?\[)
  5153. deadlinep (string-match org-deadline-regexp tmp)
  5154. scheduledp (string-match org-scheduled-regexp tmp)
  5155. closedp (and org-agenda-include-inactive-timestamps
  5156. (string-match org-closed-string tmp))
  5157. clockp (and org-agenda-include-inactive-timestamps
  5158. (or (string-match org-clock-string tmp)
  5159. (string-match "]-+\\'" tmp)))
  5160. warntime (get-text-property (point) 'org-appt-warntime)
  5161. donep (member todo-state org-done-keywords))
  5162. (if (or scheduledp deadlinep closedp clockp
  5163. (and donep org-agenda-skip-timestamp-if-done))
  5164. (throw :skip t))
  5165. (if (string-match ">" timestr)
  5166. ;; substring should only run to end of time stamp
  5167. (setq timestr (substring timestr 0 (match-end 0))))
  5168. (setq marker (org-agenda-new-marker b0)
  5169. category (org-get-category b0)
  5170. category-pos (get-text-property b0 'org-category-position))
  5171. (save-excursion
  5172. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5173. (throw :skip nil)
  5174. (goto-char (match-beginning 0))
  5175. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5176. (assoc (point) deadline-position-alist))
  5177. (throw :skip nil))
  5178. (setq hdmarker (org-agenda-new-marker)
  5179. inherited-tags
  5180. (or (eq org-agenda-show-inherited-tags 'always)
  5181. (and (listp org-agenda-show-inherited-tags)
  5182. (memq 'agenda org-agenda-show-inherited-tags))
  5183. (and (eq org-agenda-show-inherited-tags t)
  5184. (or (eq org-agenda-use-tag-inheritance t)
  5185. (memq 'agenda org-agenda-use-tag-inheritance))))
  5186. tags (org-get-tags-at nil (not inherited-tags))
  5187. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5188. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5189. (setq head (or (match-string 1) ""))
  5190. (setq txt (org-agenda-format-item
  5191. (if inactivep org-agenda-inactive-leader nil)
  5192. head level category tags timestr
  5193. remove-re habitp)))
  5194. (setq priority (org-get-priority txt))
  5195. (org-add-props txt props 'priority priority
  5196. 'org-marker marker 'org-hd-marker hdmarker
  5197. 'org-category category 'date date
  5198. 'level level
  5199. 'ts-date
  5200. (ignore-errors (org-time-string-to-absolute timestr))
  5201. 'org-category-position category-pos
  5202. 'todo-state todo-state
  5203. 'warntime warntime
  5204. 'type "timestamp")
  5205. (push txt ee))
  5206. (if org-agenda-skip-additional-timestamps-same-entry
  5207. (outline-next-heading)
  5208. (goto-char end-of-match))))
  5209. (nreverse ee)))
  5210. (defun org-agenda-get-sexps ()
  5211. "Return the sexp information for agenda display."
  5212. (require 'diary-lib)
  5213. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5214. 'mouse-face 'highlight
  5215. 'help-echo
  5216. (format "mouse-2 or RET jump to org file %s"
  5217. (abbreviate-file-name buffer-file-name))))
  5218. (regexp "^&?%%(")
  5219. marker category extra category-pos level ee txt tags entry
  5220. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5221. (goto-char (point-min))
  5222. (while (re-search-forward regexp nil t)
  5223. (catch :skip
  5224. (org-agenda-skip)
  5225. (setq beg (match-beginning 0))
  5226. (goto-char (1- (match-end 0)))
  5227. (setq b (point))
  5228. (forward-sexp 1)
  5229. (setq sexp (buffer-substring b (point)))
  5230. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5231. (org-trim (match-string 1))
  5232. ""))
  5233. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5234. (when result
  5235. (setq marker (org-agenda-new-marker beg)
  5236. level (make-string (org-reduced-level (org-outline-level)) ? )
  5237. category (org-get-category beg)
  5238. category-pos (get-text-property beg 'org-category-position)
  5239. inherited-tags
  5240. (or (eq org-agenda-show-inherited-tags 'always)
  5241. (and (listp org-agenda-show-inherited-tags)
  5242. (memq 'agenda org-agenda-show-inherited-tags))
  5243. (and (eq org-agenda-show-inherited-tags t)
  5244. (or (eq org-agenda-use-tag-inheritance t)
  5245. (memq 'agenda org-agenda-use-tag-inheritance))))
  5246. tags (org-get-tags-at nil (not inherited-tags))
  5247. todo-state (org-get-todo-state)
  5248. warntime (get-text-property (point) 'org-appt-warntime)
  5249. extra nil)
  5250. (dolist (r (if (stringp result)
  5251. (list result)
  5252. result)) ;; we expect a list here
  5253. (when (and org-agenda-diary-sexp-prefix
  5254. (string-match org-agenda-diary-sexp-prefix r))
  5255. (setq extra (match-string 0 r)
  5256. r (replace-match "" nil nil r)))
  5257. (if (string-match "\\S-" r)
  5258. (setq txt r)
  5259. (setq txt "SEXP entry returned empty string"))
  5260. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5261. (org-add-props txt props 'org-marker marker
  5262. 'org-category category 'date date 'todo-state todo-state
  5263. 'org-category-position category-pos 'tags tags
  5264. 'level level
  5265. 'type "sexp" 'warntime warntime)
  5266. (push txt ee)))))
  5267. (nreverse ee)))
  5268. ;; Calendar sanity: define some functions that are independent of
  5269. ;; `calendar-date-style'.
  5270. ;; Normally I would like to use ISO format when calling the diary functions,
  5271. ;; but to make sure we still have Emacs 22 compatibility we bind
  5272. ;; also `european-calendar-style' and use european format
  5273. (defun org-anniversary (year month day &optional mark)
  5274. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5275. (org-no-warnings
  5276. (let ((calendar-date-style 'european) (european-calendar-style t))
  5277. (diary-anniversary day month year mark))))
  5278. (defun org-cyclic (N year month day &optional mark)
  5279. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5280. (org-no-warnings
  5281. (let ((calendar-date-style 'european) (european-calendar-style t))
  5282. (diary-cyclic N day month year mark))))
  5283. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5284. "Like `diary-block', but with fixed (ISO) order of arguments."
  5285. (org-no-warnings
  5286. (let ((calendar-date-style 'european) (european-calendar-style t))
  5287. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5288. (defun org-date (year month day &optional mark)
  5289. "Like `diary-date', but with fixed (ISO) order of arguments."
  5290. (org-no-warnings
  5291. (let ((calendar-date-style 'european) (european-calendar-style t))
  5292. (diary-date day month year mark))))
  5293. ;; Define the` org-class' function
  5294. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5295. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5296. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5297. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5298. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5299. `holidays', then any date that is known by the Emacs calendar to be a
  5300. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5301. then those holidays will be skipped."
  5302. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5303. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5304. (d (calendar-absolute-from-gregorian date))
  5305. (h (when skip-weeks (calendar-check-holidays date))))
  5306. (and
  5307. (<= date1 d)
  5308. (<= d date2)
  5309. (= (calendar-day-of-week date) dayname)
  5310. (or (not skip-weeks)
  5311. (progn
  5312. (require 'cal-iso)
  5313. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5314. (not (or (and h (memq 'holidays skip-weeks))
  5315. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5316. entry)))
  5317. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5318. "Like `org-class', but honor `calendar-date-style'.
  5319. The order of the first 2 times 3 arguments depends on the variable
  5320. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5321. So for American calendars, give this as MONTH DAY YEAR, for European as
  5322. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5323. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5324. is any number of ISO weeks in the block period for which the item should
  5325. be skipped.
  5326. This function is here only for backward compatibility and it is deprecated,
  5327. please use `org-class' instead."
  5328. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5329. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5330. (org-class
  5331. (nth 2 date1) (car date1) (nth 1 date1)
  5332. (nth 2 date2) (car date2) (nth 1 date2)
  5333. dayname skip-weeks)))
  5334. (make-obsolete 'org-diary-class 'org-class "")
  5335. (defalias 'org-get-closed 'org-agenda-get-progress)
  5336. (defun org-agenda-get-progress ()
  5337. "Return the logged TODO entries for agenda display."
  5338. (let* ((props (list 'mouse-face 'highlight
  5339. 'org-not-done-regexp org-not-done-regexp
  5340. 'org-todo-regexp org-todo-regexp
  5341. 'org-complex-heading-regexp org-complex-heading-regexp
  5342. 'help-echo
  5343. (format "mouse-2 or RET jump to org file %s"
  5344. (abbreviate-file-name buffer-file-name))))
  5345. (items (if (consp org-agenda-show-log-scoped)
  5346. org-agenda-show-log-scoped
  5347. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5348. '(clock)
  5349. org-agenda-log-mode-items)))
  5350. (parts
  5351. (delq nil
  5352. (list
  5353. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5354. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5355. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5356. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5357. (error "`org-agenda-log-mode-items' is empty")))
  5358. (regexp (concat
  5359. "\\(" parts-re "\\)"
  5360. " *\\["
  5361. (regexp-quote
  5362. (substring
  5363. (format-time-string
  5364. (car org-time-stamp-formats)
  5365. (apply 'encode-time ; DATE bound by calendar
  5366. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5367. 1 11))))
  5368. (org-agenda-search-headline-for-time nil)
  5369. marker hdmarker priority category category-pos level tags closedp
  5370. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5371. (goto-char (point-min))
  5372. (while (re-search-forward regexp nil t)
  5373. (catch :skip
  5374. (org-agenda-skip)
  5375. (setq marker (org-agenda-new-marker (match-beginning 0))
  5376. closedp (equal (match-string 1) org-closed-string)
  5377. statep (equal (string-to-char (match-string 1)) ?-)
  5378. clockp (not (or closedp statep))
  5379. state (and statep (match-string 2))
  5380. category (org-get-category (match-beginning 0))
  5381. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5382. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5383. (when (string-match "\\]" timestr)
  5384. ;; substring should only run to end of time stamp
  5385. (setq rest (substring timestr (match-end 0))
  5386. timestr (substring timestr 0 (match-end 0)))
  5387. (if (and (not closedp) (not statep)
  5388. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5389. rest))
  5390. (progn (setq timestr (concat (substring timestr 0 -1)
  5391. "-" (match-string 1 rest) "]"))
  5392. (setq clocked (match-string 2 rest)))
  5393. (setq clocked "-")))
  5394. (save-excursion
  5395. (setq extra
  5396. (cond
  5397. ((not org-agenda-log-mode-add-notes) nil)
  5398. (statep
  5399. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5400. (match-string 1)))
  5401. (clockp
  5402. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5403. (match-string 1)))))
  5404. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5405. (throw :skip nil)
  5406. (goto-char (match-beginning 0))
  5407. (setq hdmarker (org-agenda-new-marker)
  5408. inherited-tags
  5409. (or (eq org-agenda-show-inherited-tags 'always)
  5410. (and (listp org-agenda-show-inherited-tags)
  5411. (memq 'todo org-agenda-show-inherited-tags))
  5412. (and (eq org-agenda-show-inherited-tags t)
  5413. (or (eq org-agenda-use-tag-inheritance t)
  5414. (memq 'todo org-agenda-use-tag-inheritance))))
  5415. tags (org-get-tags-at nil (not inherited-tags))
  5416. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5417. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5418. (setq txt (match-string 1))
  5419. (when extra
  5420. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5421. (setq txt (concat (substring txt 0 (match-beginning 1))
  5422. " - " extra " " (match-string 2 txt)))
  5423. (setq txt (concat txt " - " extra))))
  5424. (setq txt (org-agenda-format-item
  5425. (cond
  5426. (closedp "Closed: ")
  5427. (statep (concat "State: (" state ")"))
  5428. (t (concat "Clocked: (" clocked ")")))
  5429. txt level category tags timestr)))
  5430. (setq priority 100000)
  5431. (org-add-props txt props
  5432. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5433. 'priority priority 'org-category category
  5434. 'org-category-position category-pos
  5435. 'level level
  5436. 'type "closed" 'date date
  5437. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5438. (push txt ee))
  5439. (goto-char (point-at-eol))))
  5440. (nreverse ee)))
  5441. (defun org-agenda-show-clocking-issues ()
  5442. "Add overlays, showing issues with clocking.
  5443. See also the user option `org-agenda-clock-consistency-checks'."
  5444. (interactive)
  5445. (let* ((org-time-clocksum-use-effort-durations nil)
  5446. (pl org-agenda-clock-consistency-checks)
  5447. (re (concat "^[ \t]*"
  5448. org-clock-string
  5449. "[ \t]+"
  5450. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5451. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5452. (tlstart 0.)
  5453. (tlend 0.)
  5454. (maxtime (org-hh:mm-string-to-minutes
  5455. (or (plist-get pl :max-duration) "24:00")))
  5456. (mintime (org-hh:mm-string-to-minutes
  5457. (or (plist-get pl :min-duration) 0)))
  5458. (maxgap (org-hh:mm-string-to-minutes
  5459. ;; default 30:00 means never complain
  5460. (or (plist-get pl :max-gap) "30:00")))
  5461. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5462. (plist-get pl :gap-ok-around)))
  5463. (def-face (or (plist-get pl :default-face)
  5464. '((:background "DarkRed") (:foreground "white"))))
  5465. issue face m te ts dt ov)
  5466. (goto-char (point-min))
  5467. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5468. (setq issue nil face def-face)
  5469. (catch 'next
  5470. (setq m (org-get-at-bol 'org-marker)
  5471. te nil ts nil)
  5472. (unless (and m (markerp m))
  5473. (setq issue "No valid clock line") (throw 'next t))
  5474. (org-with-point-at m
  5475. (save-excursion
  5476. (goto-char (point-at-bol))
  5477. (unless (looking-at re)
  5478. (error "No valid Clock line")
  5479. (throw 'next t))
  5480. (unless (match-end 3)
  5481. (setq issue "No end time"
  5482. face (or (plist-get pl :no-end-time-face) face))
  5483. (throw 'next t))
  5484. (setq ts (match-string 1)
  5485. te (match-string 3)
  5486. ts (org-float-time
  5487. (apply 'encode-time (org-parse-time-string ts)))
  5488. te (org-float-time
  5489. (apply 'encode-time (org-parse-time-string te)))
  5490. dt (- te ts))))
  5491. (cond
  5492. ((> dt (* 60 maxtime))
  5493. ;; a very long clocking chunk
  5494. (setq issue (format "Clocking interval is very long: %s"
  5495. (org-minutes-to-clocksum-string
  5496. (floor (/ (float dt) 60.))))
  5497. face (or (plist-get pl :long-face) face)))
  5498. ((< dt (* 60 mintime))
  5499. ;; a very short clocking chunk
  5500. (setq issue (format "Clocking interval is very short: %s"
  5501. (org-minutes-to-clocksum-string
  5502. (floor (/ (float dt) 60.))))
  5503. face (or (plist-get pl :short-face) face)))
  5504. ((and (> tlend 0) (< ts tlend))
  5505. ;; Two clock entries are overlapping
  5506. (setq issue (format "Clocking overlap: %d minutes"
  5507. (/ (- tlend ts) 60))
  5508. face (or (plist-get pl :overlap-face) face)))
  5509. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5510. ;; There is a gap, lets see if we need to report it
  5511. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5512. (setq issue (format "Clocking gap: %d minutes"
  5513. (/ (- ts tlend) 60))
  5514. face (or (plist-get pl :gap-face) face))))
  5515. (t nil)))
  5516. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5517. (when issue
  5518. ;; OK, there was some issue, add an overlay to show the issue
  5519. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5520. (overlay-put ov 'before-string
  5521. (concat
  5522. (org-add-props
  5523. (format "%-43s" (concat " " issue))
  5524. nil
  5525. 'face face)
  5526. "\n"))
  5527. (overlay-put ov 'evaporate t)))))
  5528. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5529. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5530. (catch 'exit
  5531. (unless ok-list
  5532. ;; there are no OK times for gaps...
  5533. (throw 'exit nil))
  5534. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5535. ;; This is more than 24 hours, so it is OK.
  5536. ;; because we have at least one OK time, that must be in the
  5537. ;; 24 hour interval.
  5538. (throw 'exit t))
  5539. ;; We have a shorter gap.
  5540. ;; Now we have to get the minute of the day when these times are
  5541. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5542. (t2dec (decode-time (seconds-to-time t2)))
  5543. ;; compute the minute on the day
  5544. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5545. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5546. (when (< min2 min1)
  5547. ;; if min2 is smaller than min1, this means it is on the next day.
  5548. ;; Wrap it to after midnight.
  5549. (setq min2 (+ min2 1440)))
  5550. ;; Now check if any of the OK times is in the gap
  5551. (mapc (lambda (x)
  5552. ;; Wrap the time to after midnight if necessary
  5553. (if (< x min1) (setq x (+ x 1440)))
  5554. ;; Check if in interval
  5555. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5556. ok-list)
  5557. ;; Nope, this gap is not OK
  5558. nil)))
  5559. (defun org-agenda-get-deadlines (&optional with-hour)
  5560. "Return the deadline information for agenda display.
  5561. When WITH-HOUR is non-nil, only return deadlines with an hour
  5562. specification like [h]h:mm."
  5563. (let* ((props (list 'mouse-face 'highlight
  5564. 'org-not-done-regexp org-not-done-regexp
  5565. 'org-todo-regexp org-todo-regexp
  5566. 'org-complex-heading-regexp org-complex-heading-regexp
  5567. 'help-echo
  5568. (format "mouse-2 or RET jump to org file %s"
  5569. (abbreviate-file-name buffer-file-name))))
  5570. (regexp (if with-hour
  5571. org-deadline-time-hour-regexp
  5572. org-deadline-time-regexp))
  5573. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5574. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5575. (dl0 (car org-agenda-deadline-leaders))
  5576. (dl1 (nth 1 org-agenda-deadline-leaders))
  5577. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5578. d2 diff dfrac wdays pos pos1 category category-pos level
  5579. tags suppress-prewarning ee txt head face s todo-state
  5580. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5581. (goto-char (point-min))
  5582. (while (re-search-forward regexp nil t)
  5583. (catch :skip
  5584. (org-agenda-skip)
  5585. (setq s (match-string 1)
  5586. txt nil
  5587. pos (1- (match-beginning 1))
  5588. todo-state (save-match-data (org-get-todo-state))
  5589. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5590. (member todo-state
  5591. org-agenda-repeating-timestamp-show-all))
  5592. d2 (org-time-string-to-absolute
  5593. s d1 'past show-all (current-buffer) pos)
  5594. diff (- d2 d1))
  5595. (setq suppress-prewarning
  5596. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5597. (let ((item (buffer-substring (point-at-bol)
  5598. (point-at-eol))))
  5599. (save-match-data
  5600. (and (string-match
  5601. org-scheduled-time-regexp item)
  5602. (match-string 1 item)))))))
  5603. (cond
  5604. ((not ds) nil)
  5605. ;; The current item has a scheduled date (in ds), so
  5606. ;; evaluate its prewarning lead time.
  5607. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5608. ;; Use global prewarning-restart lead time.
  5609. org-agenda-skip-deadline-prewarning-if-scheduled)
  5610. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5611. 'pre-scheduled)
  5612. ;; Set prewarning to no earlier than scheduled.
  5613. (min (- d2 (org-time-string-to-absolute
  5614. ds d1 'past show-all (current-buffer) pos))
  5615. org-deadline-warning-days))
  5616. ;; Set prewarning to deadline.
  5617. (t 0))))
  5618. (setq wdays (if suppress-prewarning
  5619. (let ((org-deadline-warning-days suppress-prewarning))
  5620. (org-get-wdays s))
  5621. (org-get-wdays s))
  5622. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5623. upcomingp (and todayp (> diff 0)))
  5624. ;; When to show a deadline in the calendar:
  5625. ;; If the expiration is within wdays warning time.
  5626. ;; Past-due deadlines are only shown on the current date
  5627. (if (and (or (and (<= diff wdays)
  5628. (and todayp (not org-agenda-only-exact-dates)))
  5629. (= diff 0)))
  5630. (save-excursion
  5631. ;; (setq todo-state (org-get-todo-state))
  5632. (setq donep (member todo-state org-done-keywords))
  5633. (if (and donep
  5634. (or org-agenda-skip-deadline-if-done
  5635. (not (= diff 0))))
  5636. (setq txt nil)
  5637. (setq category (org-get-category)
  5638. warntime (get-text-property (point) 'org-appt-warntime)
  5639. category-pos (get-text-property (point) 'org-category-position))
  5640. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5641. (throw :skip nil)
  5642. (goto-char (match-end 0))
  5643. (setq pos1 (match-beginning 0))
  5644. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5645. (setq inherited-tags
  5646. (or (eq org-agenda-show-inherited-tags 'always)
  5647. (and (listp org-agenda-show-inherited-tags)
  5648. (memq 'agenda org-agenda-show-inherited-tags))
  5649. (and (eq org-agenda-show-inherited-tags t)
  5650. (or (eq org-agenda-use-tag-inheritance t)
  5651. (memq 'agenda org-agenda-use-tag-inheritance))))
  5652. tags (org-get-tags-at pos1 (not inherited-tags)))
  5653. (setq head (buffer-substring
  5654. (point)
  5655. (progn (skip-chars-forward "^\r\n")
  5656. (point))))
  5657. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5658. (setq timestr
  5659. (concat (substring s (match-beginning 1)) " "))
  5660. (setq timestr 'time))
  5661. (setq txt (org-agenda-format-item
  5662. (cond ((= diff 0) dl0)
  5663. ((> diff 0)
  5664. (if (functionp dl1)
  5665. (funcall dl1 diff date)
  5666. (format dl1 diff)))
  5667. (t
  5668. (if (functionp dl2)
  5669. (funcall dl2 diff date)
  5670. (format dl2 (if (string= dl2 dl1)
  5671. diff (abs diff))))))
  5672. head level category tags
  5673. (if (not (= diff 0)) nil timestr)))))
  5674. (when txt
  5675. (setq face (org-agenda-deadline-face dfrac))
  5676. (org-add-props txt props
  5677. 'org-marker (org-agenda-new-marker pos)
  5678. 'warntime warntime
  5679. 'level level
  5680. 'ts-date d2
  5681. 'org-hd-marker (org-agenda-new-marker pos1)
  5682. 'priority (+ (- diff)
  5683. (org-get-priority txt))
  5684. 'org-category category
  5685. 'org-category-position category-pos
  5686. 'todo-state todo-state
  5687. 'type (if upcomingp "upcoming-deadline" "deadline")
  5688. 'date (if upcomingp date d2)
  5689. 'face (if donep 'org-agenda-done face)
  5690. 'undone-face face 'done-face 'org-agenda-done)
  5691. (push txt ee))))))
  5692. (nreverse ee)))
  5693. (defun org-agenda-deadline-face (fraction)
  5694. "Return the face to displaying a deadline item.
  5695. FRACTION is what fraction of the head-warning time has passed."
  5696. (let ((faces org-agenda-deadline-faces) f)
  5697. (catch 'exit
  5698. (while (setq f (pop faces))
  5699. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5700. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5701. "Return the scheduled information for agenda display.
  5702. When WITH-HOUR is non-nil, only return scheduled items with
  5703. an hour specification like [h]h:mm."
  5704. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5705. 'org-todo-regexp org-todo-regexp
  5706. 'org-complex-heading-regexp org-complex-heading-regexp
  5707. 'done-face 'org-agenda-done
  5708. 'mouse-face 'highlight
  5709. 'help-echo
  5710. (format "mouse-2 or RET jump to org file %s"
  5711. (abbreviate-file-name buffer-file-name))))
  5712. (regexp (if with-hour
  5713. org-scheduled-time-hour-regexp
  5714. org-scheduled-time-regexp))
  5715. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5716. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5717. mm
  5718. (deadline-position-alist
  5719. (mapcar (lambda (a) (and (setq mm (get-text-property
  5720. 0 'org-hd-marker a))
  5721. (cons (marker-position mm) a)))
  5722. deadline-results))
  5723. d2 diff pos pos1 category category-pos level tags donep
  5724. ee txt head pastschedp todo-state face timestr s habitp show-all
  5725. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5726. ddays)
  5727. (goto-char (point-min))
  5728. (while (re-search-forward regexp nil t)
  5729. (catch :skip
  5730. (org-agenda-skip)
  5731. (setq s (match-string 1)
  5732. txt nil
  5733. pos (1- (match-beginning 1))
  5734. todo-state (save-match-data (org-get-todo-state))
  5735. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5736. (member todo-state
  5737. org-agenda-repeating-timestamp-show-all))
  5738. d2 (org-time-string-to-absolute
  5739. s d1 'past show-all (current-buffer) pos)
  5740. diff (- d2 d1)
  5741. warntime (get-text-property (point) 'org-appt-warntime))
  5742. (setq pastschedp (and todayp (< diff 0)))
  5743. (setq did-habit-check-p nil)
  5744. (setq suppress-delay
  5745. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5746. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5747. (save-match-data
  5748. (and (string-match
  5749. org-deadline-time-regexp item)
  5750. (match-string 1 item)))))))
  5751. (cond
  5752. ((not ds) nil)
  5753. ;; The current item has a deadline date (in ds), so
  5754. ;; evaluate its delay time.
  5755. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5756. ;; Use global delay time.
  5757. (- org-agenda-skip-scheduled-delay-if-deadline))
  5758. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5759. 'post-deadline)
  5760. ;; Set delay to no later than deadline.
  5761. (min (- d2 (org-time-string-to-absolute
  5762. ds d1 'past show-all (current-buffer) pos))
  5763. org-scheduled-delay-days))
  5764. (t 0))))
  5765. (setq ddays (if suppress-delay
  5766. (let ((org-scheduled-delay-days suppress-delay))
  5767. (org-get-wdays s t t))
  5768. (org-get-wdays s t)))
  5769. ;; Use a delay of 0 when there is a repeater and the delay is
  5770. ;; of the form --3d
  5771. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5772. (< (org-time-string-to-absolute s)
  5773. (org-time-string-to-absolute
  5774. s d2 'past nil (current-buffer) pos)))
  5775. (setq ddays 0))
  5776. ;; When to show a scheduled item in the calendar:
  5777. ;; If it is on or past the date.
  5778. (when (or (and (> ddays 0) (= diff (- ddays)))
  5779. (and (zerop ddays) (= diff 0))
  5780. (and (< (+ diff ddays) 0)
  5781. (< (abs diff) org-scheduled-past-days)
  5782. (and todayp (not org-agenda-only-exact-dates)))
  5783. ;; org-is-habit-p uses org-entry-get, which is expansive
  5784. ;; so we go extra mile to only call it once
  5785. (and todayp
  5786. (boundp 'org-habit-show-all-today)
  5787. org-habit-show-all-today
  5788. (setq did-habit-check-p t)
  5789. (setq habitp (and (functionp 'org-is-habit-p)
  5790. (org-is-habit-p)))))
  5791. (save-excursion
  5792. (setq donep (member todo-state org-done-keywords))
  5793. (if (and donep
  5794. (or org-agenda-skip-scheduled-if-done
  5795. (not (= diff 0))
  5796. (and (functionp 'org-is-habit-p)
  5797. (org-is-habit-p))))
  5798. (setq txt nil)
  5799. (setq habitp (if did-habit-check-p habitp
  5800. (and (functionp 'org-is-habit-p)
  5801. (org-is-habit-p))))
  5802. (setq category (org-get-category)
  5803. category-pos (get-text-property (point) 'org-category-position))
  5804. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5805. 'repeated-after-deadline)
  5806. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5807. (throw :skip nil))
  5808. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5809. (throw :skip nil)
  5810. (goto-char (match-end 0))
  5811. (setq pos1 (match-beginning 0))
  5812. (if habitp
  5813. (if (or (not org-habit-show-habits)
  5814. (and (not todayp)
  5815. (boundp 'org-habit-show-habits-only-for-today)
  5816. org-habit-show-habits-only-for-today))
  5817. (throw :skip nil))
  5818. (if (and
  5819. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5820. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5821. pastschedp))
  5822. (setq mm (assoc pos1 deadline-position-alist)))
  5823. (throw :skip nil)))
  5824. (setq inherited-tags
  5825. (or (eq org-agenda-show-inherited-tags 'always)
  5826. (and (listp org-agenda-show-inherited-tags)
  5827. (memq 'agenda org-agenda-show-inherited-tags))
  5828. (and (eq org-agenda-show-inherited-tags t)
  5829. (or (eq org-agenda-use-tag-inheritance t)
  5830. (memq 'agenda org-agenda-use-tag-inheritance))))
  5831. tags (org-get-tags-at nil (not inherited-tags)))
  5832. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5833. (setq head (buffer-substring
  5834. (point)
  5835. (progn (skip-chars-forward "^\r\n") (point))))
  5836. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5837. (setq timestr
  5838. (concat (substring s (match-beginning 1)) " "))
  5839. (setq timestr 'time))
  5840. (setq txt (org-agenda-format-item
  5841. (if (= diff 0)
  5842. (car org-agenda-scheduled-leaders)
  5843. (format (nth 1 org-agenda-scheduled-leaders)
  5844. (- 1 diff)))
  5845. head level category tags
  5846. (if (not (= diff 0)) nil timestr)
  5847. nil habitp))))
  5848. (when txt
  5849. (setq face
  5850. (cond
  5851. ((and (not habitp) pastschedp)
  5852. 'org-scheduled-previously)
  5853. (todayp 'org-scheduled-today)
  5854. (t 'org-scheduled))
  5855. habitp (and habitp (org-habit-parse-todo)))
  5856. (org-add-props txt props
  5857. 'undone-face face
  5858. 'face (if donep 'org-agenda-done face)
  5859. 'org-marker (org-agenda-new-marker pos)
  5860. 'org-hd-marker (org-agenda-new-marker pos1)
  5861. 'type (if pastschedp "past-scheduled" "scheduled")
  5862. 'date (if pastschedp d2 date)
  5863. 'ts-date d2
  5864. 'warntime warntime
  5865. 'level level
  5866. 'priority (if habitp
  5867. (org-habit-get-priority habitp)
  5868. (+ 94 (- 5 diff) (org-get-priority txt)))
  5869. 'org-category category
  5870. 'category-position category-pos
  5871. 'org-habit-p habitp
  5872. 'todo-state todo-state)
  5873. (push txt ee))))))
  5874. (nreverse ee)))
  5875. (defun org-agenda-get-blocks ()
  5876. "Return the date-range information for agenda display."
  5877. (let* ((props (list 'face nil
  5878. 'org-not-done-regexp org-not-done-regexp
  5879. 'org-todo-regexp org-todo-regexp
  5880. 'org-complex-heading-regexp org-complex-heading-regexp
  5881. 'mouse-face 'highlight
  5882. 'help-echo
  5883. (format "mouse-2 or RET jump to org file %s"
  5884. (abbreviate-file-name buffer-file-name))))
  5885. (regexp org-tr-regexp)
  5886. (d0 (calendar-absolute-from-gregorian date))
  5887. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5888. level todo-state tags pos head donep inherited-tags)
  5889. (goto-char (point-min))
  5890. (while (re-search-forward regexp nil t)
  5891. (catch :skip
  5892. (org-agenda-skip)
  5893. (setq pos (point))
  5894. (let ((start-time (match-string 1))
  5895. (end-time (match-string 2)))
  5896. (setq s1 (match-string 1)
  5897. s2 (match-string 2)
  5898. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5899. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5900. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5901. ;; Only allow days between the limits, because the normal
  5902. ;; date stamps will catch the limits.
  5903. (save-excursion
  5904. (setq todo-state (org-get-todo-state))
  5905. (setq donep (member todo-state org-done-keywords))
  5906. (if (and donep org-agenda-skip-timestamp-if-done)
  5907. (throw :skip t))
  5908. (setq marker (org-agenda-new-marker (point)))
  5909. (setq category (org-get-category)
  5910. category-pos (get-text-property (point) 'org-category-position))
  5911. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5912. (throw :skip nil)
  5913. (goto-char (match-beginning 0))
  5914. (setq hdmarker (org-agenda-new-marker (point))
  5915. inherited-tags
  5916. (or (eq org-agenda-show-inherited-tags 'always)
  5917. (and (listp org-agenda-show-inherited-tags)
  5918. (memq 'agenda org-agenda-show-inherited-tags))
  5919. (and (eq org-agenda-show-inherited-tags t)
  5920. (or (eq org-agenda-use-tag-inheritance t)
  5921. (memq 'agenda org-agenda-use-tag-inheritance))))
  5922. tags (org-get-tags-at nil (not inherited-tags)))
  5923. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5924. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5925. (setq head (match-string 1))
  5926. (let ((remove-re
  5927. (if org-agenda-remove-timeranges-from-blocks
  5928. (concat
  5929. "<" (regexp-quote s1) ".*?>"
  5930. "--"
  5931. "<" (regexp-quote s2) ".*?>")
  5932. nil)))
  5933. (setq txt (org-agenda-format-item
  5934. (format
  5935. (nth (if (= d1 d2) 0 1)
  5936. org-agenda-timerange-leaders)
  5937. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5938. head level category tags
  5939. (cond ((and (= d1 d0) (= d2 d0))
  5940. (concat "<" start-time ">--<" end-time ">"))
  5941. ((= d1 d0)
  5942. (concat "<" start-time ">"))
  5943. ((= d2 d0)
  5944. (concat "<" end-time ">")))
  5945. remove-re))))
  5946. (org-add-props txt props
  5947. 'org-marker marker 'org-hd-marker hdmarker
  5948. 'type "block" 'date date
  5949. 'level level
  5950. 'todo-state todo-state
  5951. 'priority (org-get-priority txt) 'org-category category
  5952. 'org-category-position category-pos)
  5953. (push txt ee))))
  5954. (goto-char pos)))
  5955. ;; Sort the entries by expiration date.
  5956. (nreverse ee)))
  5957. ;;; Agenda presentation and sorting
  5958. (defvar org-prefix-has-time nil
  5959. "A flag, set by `org-compile-prefix-format'.
  5960. The flag is set if the currently compiled format contains a `%t'.")
  5961. (defvar org-prefix-has-tag nil
  5962. "A flag, set by `org-compile-prefix-format'.
  5963. The flag is set if the currently compiled format contains a `%T'.")
  5964. (defvar org-prefix-has-effort nil
  5965. "A flag, set by `org-compile-prefix-format'.
  5966. The flag is set if the currently compiled format contains a `%e'.")
  5967. (defvar org-prefix-has-breadcrumbs nil
  5968. "A flag, set by `org-compile-prefix-format'.
  5969. The flag is set if the currently compiled format contains a `%b'.")
  5970. (defvar org-prefix-category-length nil
  5971. "Used by `org-compile-prefix-format' to remember the category field width.")
  5972. (defvar org-prefix-category-max-length nil
  5973. "Used by `org-compile-prefix-format' to remember the category field width.")
  5974. (defun org-agenda-get-category-icon (category)
  5975. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5976. (dolist (entry org-agenda-category-icon-alist)
  5977. (when (org-string-match-p (car entry) category)
  5978. (if (listp (cadr entry))
  5979. (return (cadr entry))
  5980. (return (apply 'create-image (cdr entry)))))))
  5981. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5982. remove-re habitp)
  5983. "Format TXT to be inserted into the agenda buffer.
  5984. In particular, add the prefix and corresponding text properties.
  5985. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5986. LEVEL may be a string to replace the `%l' specifier.
  5987. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5988. category taken from local variable or file name. It will replace the `%c'
  5989. specifier in the format.
  5990. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5991. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5992. When DOTIME is a string, this string is searched for a time before TXT is.
  5993. TAGS can be the tags of the headline.
  5994. Any match of REMOVE-RE will be removed from TXT."
  5995. ;; We keep the org-prefix-* variable values along with a compiled
  5996. ;; formatter, so that multiple agendas existing at the same time do
  5997. ;; not step on each other toes.
  5998. ;;
  5999. ;; It was inconvenient to make these variables buffer local in
  6000. ;; Agenda buffers, because this function expects to be called with
  6001. ;; the buffer where item comes from being current, and not agenda
  6002. ;; buffer
  6003. (let* ((bindings (car org-prefix-format-compiled))
  6004. (formatter (cadr org-prefix-format-compiled)))
  6005. (loop for (var value) in bindings
  6006. do (set var value))
  6007. (save-match-data
  6008. ;; Diary entries sometimes have extra whitespace at the beginning
  6009. (setq txt (org-trim txt))
  6010. ;; Fix the tags part in txt
  6011. (setq txt (org-agenda-fix-displayed-tags
  6012. txt tags
  6013. org-agenda-show-inherited-tags
  6014. org-agenda-hide-tags-regexp))
  6015. (let* ((category (or category
  6016. (if (stringp org-category)
  6017. org-category
  6018. (and org-category (symbol-name org-category)))
  6019. (if buffer-file-name
  6020. (file-name-sans-extension
  6021. (file-name-nondirectory buffer-file-name))
  6022. "")))
  6023. (category-icon (org-agenda-get-category-icon category))
  6024. (category-icon (if category-icon
  6025. (propertize " " 'display category-icon)
  6026. ""))
  6027. ;; time, tag, effort are needed for the eval of the prefix format
  6028. (tag (if tags (nth (1- (length tags)) tags) ""))
  6029. time effort neffort
  6030. (ts (if dotime (concat
  6031. (if (stringp dotime) dotime "")
  6032. (and org-agenda-search-headline-for-time txt))))
  6033. (time-of-day (and dotime (org-get-time-of-day ts)))
  6034. stamp plain s0 s1 s2 rtn srp l
  6035. duration thecategory breadcrumbs)
  6036. (and (derived-mode-p 'org-mode) buffer-file-name
  6037. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6038. (when (and dotime time-of-day)
  6039. ;; Extract starting and ending time and move them to prefix
  6040. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6041. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6042. (setq s0 (match-string 0 ts)
  6043. srp (and stamp (match-end 3))
  6044. s1 (match-string (if plain 1 2) ts)
  6045. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6046. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6047. ;; them, we might want to remove them there to avoid duplication.
  6048. ;; The user can turn this off with a variable.
  6049. (if (and org-prefix-has-time
  6050. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6051. (string-match (concat (regexp-quote s0) " *") txt)
  6052. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6053. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6054. (= (match-beginning 0) 0)
  6055. t))
  6056. (setq txt (replace-match "" nil nil txt))))
  6057. ;; Normalize the time(s) to 24 hour
  6058. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6059. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6060. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6061. (let (org-time-clocksum-use-effort-durations)
  6062. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6063. (setq s2
  6064. (org-minutes-to-clocksum-string
  6065. (+ (org-hh:mm-string-to-minutes s1)
  6066. org-agenda-default-appointment-duration)))))
  6067. ;; Compute the duration
  6068. (when s2
  6069. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6070. (org-hh:mm-string-to-minutes s1)))))
  6071. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6072. txt)
  6073. ;; Tags are in the string
  6074. (if (or (eq org-agenda-remove-tags t)
  6075. (and org-agenda-remove-tags
  6076. org-prefix-has-tag))
  6077. (setq txt (replace-match "" t t txt))
  6078. (setq txt (replace-match
  6079. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6080. (match-string 2 txt))
  6081. t t txt))))
  6082. (when (derived-mode-p 'org-mode)
  6083. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6084. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6085. ;; current buffer, so move this check outside of above
  6086. (if effort
  6087. (setq neffort (org-duration-string-to-minutes effort)
  6088. effort (setq effort (concat "[" effort "]")))
  6089. ;; prevent erroring out with %e format when there is no effort
  6090. (setq effort ""))
  6091. (when remove-re
  6092. (while (string-match remove-re txt)
  6093. (setq txt (replace-match "" t t txt))))
  6094. ;; Set org-heading property on `txt' to mark the start of the
  6095. ;; heading.
  6096. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6097. ;; Prepare the variables needed in the eval of the compiled format
  6098. (if org-prefix-has-breadcrumbs
  6099. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6100. (let ((s (org-display-outline-path nil nil "->" t)))
  6101. (if (eq "" s) "" (concat s "->"))))))
  6102. (setq time (cond (s2 (concat
  6103. (org-agenda-time-of-day-to-ampm-maybe s1)
  6104. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6105. (if org-agenda-timegrid-use-ampm " ")))
  6106. (s1 (concat
  6107. (org-agenda-time-of-day-to-ampm-maybe s1)
  6108. (if org-agenda-timegrid-use-ampm
  6109. "........ "
  6110. "......")))
  6111. (t ""))
  6112. extra (or (and (not habitp) extra) "")
  6113. category (if (symbolp category) (symbol-name category) category)
  6114. thecategory (copy-sequence category)
  6115. level (or level ""))
  6116. (if (string-match org-bracket-link-regexp category)
  6117. (progn
  6118. (setq l (if (match-end 3)
  6119. (- (match-end 3) (match-beginning 3))
  6120. (- (match-end 1) (match-beginning 1))))
  6121. (when (< l (or org-prefix-category-length 0))
  6122. (setq category (copy-sequence category))
  6123. (org-add-props category nil
  6124. 'extra-space (make-string
  6125. (- org-prefix-category-length l 1) ?\ ))))
  6126. (if (and org-prefix-category-max-length
  6127. (>= (length category) org-prefix-category-max-length))
  6128. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6129. ;; Evaluate the compiled format
  6130. (setq rtn (concat (eval formatter) txt))
  6131. ;; And finally add the text properties
  6132. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6133. (org-add-props rtn nil
  6134. 'org-category (if thecategory (downcase thecategory) category)
  6135. 'tags (mapcar 'org-downcase-keep-props tags)
  6136. 'org-highest-priority org-highest-priority
  6137. 'org-lowest-priority org-lowest-priority
  6138. 'time-of-day time-of-day
  6139. 'duration duration
  6140. 'effort effort
  6141. 'effort-minutes neffort
  6142. 'breadcrumbs breadcrumbs
  6143. 'txt txt
  6144. 'level level
  6145. 'time time
  6146. 'extra extra
  6147. 'format org-prefix-format-compiled
  6148. 'dotime dotime)))))
  6149. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6150. "Remove tags string from TXT, and add a modified list of tags.
  6151. The modified list may contain inherited tags, and tags matched by
  6152. `org-agenda-hide-tags-regexp' will be removed."
  6153. (when (or add-inherited hide-re)
  6154. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6155. (setq txt (substring txt 0 (match-beginning 0))))
  6156. (setq tags
  6157. (delq nil
  6158. (mapcar (lambda (tg)
  6159. (if (or (and hide-re (string-match hide-re tg))
  6160. (and (not add-inherited)
  6161. (get-text-property 0 'inherited tg)))
  6162. nil
  6163. tg))
  6164. tags)))
  6165. (when tags
  6166. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6167. i)
  6168. (setq txt (concat txt " :"
  6169. (mapconcat
  6170. (lambda (x)
  6171. (setq i (get-text-property 0 'inherited x))
  6172. (if (and have-i (not i))
  6173. (progn
  6174. (setq have-i nil)
  6175. (concat ":" x))
  6176. x))
  6177. tags ":")
  6178. (if have-i "::" ":"))))))
  6179. txt)
  6180. (defun org-downcase-keep-props (s)
  6181. (let ((props (text-properties-at 0 s)))
  6182. (setq s (downcase s))
  6183. (add-text-properties 0 (length s) props s)
  6184. s))
  6185. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6186. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6187. "Add a time-grid for agenda items which need it.
  6188. LIST is the list of agenda items formatted by `org-agenda-list'.
  6189. NDAYS is the span of the current agenda view.
  6190. TODAYP is `t' when the current agenda view is on today."
  6191. (catch 'exit
  6192. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6193. ((and todayp (member 'today (car org-agenda-time-grid))))
  6194. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6195. ((member 'weekly (car org-agenda-time-grid)))
  6196. (t (throw 'exit list)))
  6197. (let* ((have (delq nil (mapcar
  6198. (lambda (x) (get-text-property 1 'time-of-day x))
  6199. list)))
  6200. (string (nth 1 org-agenda-time-grid))
  6201. (gridtimes (nth 2 org-agenda-time-grid))
  6202. (req (car org-agenda-time-grid))
  6203. (remove (member 'remove-match req))
  6204. new time)
  6205. (if (and (member 'require-timed req) (not have))
  6206. ;; don't show empty grid
  6207. (throw 'exit list))
  6208. (while (setq time (pop gridtimes))
  6209. (unless (and remove (member time have))
  6210. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6211. (push (org-agenda-format-item
  6212. nil string nil "" nil
  6213. (concat (substring time 0 -2) ":" (substring time -2)))
  6214. new)
  6215. (put-text-property
  6216. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6217. (when (and todayp org-agenda-show-current-time-in-grid)
  6218. (push (org-agenda-format-item
  6219. nil org-agenda-current-time-string nil "" nil
  6220. (format-time-string "%H:%M "))
  6221. new)
  6222. (put-text-property
  6223. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6224. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6225. (append new list)
  6226. (append list new)))))
  6227. (defun org-compile-prefix-format (key)
  6228. "Compile the prefix format into a Lisp form that can be evaluated.
  6229. The resulting form and associated variable bindings is returned
  6230. and stored in the variable `org-prefix-format-compiled'."
  6231. (setq org-prefix-has-time nil
  6232. org-prefix-has-tag nil
  6233. org-prefix-category-length nil
  6234. org-prefix-has-effort nil
  6235. org-prefix-has-breadcrumbs nil)
  6236. (let ((s (cond
  6237. ((stringp org-agenda-prefix-format)
  6238. org-agenda-prefix-format)
  6239. ((assq key org-agenda-prefix-format)
  6240. (cdr (assq key org-agenda-prefix-format)))
  6241. (t " %-12:c%?-12t% s")))
  6242. (start 0)
  6243. varform vars var e c f opt)
  6244. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6245. s start)
  6246. (setq var (or (cdr (assoc (match-string 4 s)
  6247. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6248. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6249. 'eval)
  6250. c (or (match-string 3 s) "")
  6251. opt (match-beginning 1)
  6252. start (1+ (match-beginning 0)))
  6253. (if (equal var 'time) (setq org-prefix-has-time t))
  6254. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6255. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6256. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6257. (setq f (concat "%" (match-string 2 s) "s"))
  6258. (when (equal var 'category)
  6259. (setq org-prefix-category-length
  6260. (floor (abs (string-to-number (match-string 2 s)))))
  6261. (setq org-prefix-category-max-length
  6262. (let ((x (match-string 2 s)))
  6263. (save-match-data
  6264. (if (string-match "\\.[0-9]+" x)
  6265. (string-to-number (substring (match-string 0 x) 1)))))))
  6266. (if (eq var 'eval)
  6267. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6268. (if opt
  6269. (setq varform
  6270. `(if (equal "" ,var)
  6271. ""
  6272. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6273. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6274. (setq s (replace-match "%s" t nil s))
  6275. (push varform vars))
  6276. (setq vars (nreverse vars))
  6277. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6278. (setq org-prefix-format-compiled
  6279. (list
  6280. `((org-prefix-has-time ,org-prefix-has-time)
  6281. (org-prefix-has-tag ,org-prefix-has-tag)
  6282. (org-prefix-category-length ,org-prefix-category-length)
  6283. (org-prefix-has-effort ,org-prefix-has-effort)
  6284. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6285. `(format ,s ,@vars))))))
  6286. (defun org-set-sorting-strategy (key)
  6287. (if (symbolp (car org-agenda-sorting-strategy))
  6288. ;; the old format
  6289. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6290. (setq org-agenda-sorting-strategy-selected
  6291. (or (cdr (assq key org-agenda-sorting-strategy))
  6292. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6293. '(time-up category-keep priority-down)))))
  6294. (defun org-get-time-of-day (s &optional string mod24)
  6295. "Check string S for a time of day.
  6296. If found, return it as a military time number between 0 and 2400.
  6297. If not found, return nil.
  6298. The optional STRING argument forces conversion into a 5 character wide string
  6299. HH:MM."
  6300. (save-match-data
  6301. (when
  6302. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6303. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6304. (let* ((h (string-to-number (match-string 1 s)))
  6305. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6306. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6307. (am-p (equal ampm "am"))
  6308. (h1 (cond ((not ampm) h)
  6309. ((= h 12) (if am-p 0 12))
  6310. (t (+ h (if am-p 0 12)))))
  6311. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6312. (mod h1 24) h1))
  6313. (t0 (+ (* 100 h2) m))
  6314. (t1 (concat (if (>= h1 24) "+" " ")
  6315. (if (and org-agenda-time-leading-zero
  6316. (< t0 1000)) "0" "")
  6317. (if (< t0 100) "0" "")
  6318. (if (< t0 10) "0" "")
  6319. (int-to-string t0))))
  6320. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6321. (defvar org-agenda-before-sorting-filter-function nil
  6322. "Function to be applied to agenda items prior to sorting.
  6323. Prior to sorting also means just before they are inserted into the agenda.
  6324. To aid sorting, you may revisit the original entries and add more text
  6325. properties which will later be used by the sorting functions.
  6326. The function should take a string argument, an agenda line.
  6327. It has access to the text properties in that line, which contain among
  6328. other things, the property `org-hd-marker' that points to the entry
  6329. where the line comes from. Note that not all lines going into the agenda
  6330. have this property, only most.
  6331. The function should return the modified string. It is probably best
  6332. to ONLY change text properties.
  6333. You can also use this function as a filter, by returning nil for lines
  6334. you don't want to have in the agenda at all. For this application, you
  6335. could bind the variable in the options section of a custom command.")
  6336. (defun org-agenda-finalize-entries (list &optional type)
  6337. "Sort, limit and concatenate the LIST of agenda items.
  6338. The optional argument TYPE tells the agenda type."
  6339. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6340. (cdr (assoc type org-agenda-max-effort)))
  6341. (t org-agenda-max-effort)))
  6342. (max-todo (cond ((listp org-agenda-max-todos)
  6343. (cdr (assoc type org-agenda-max-todos)))
  6344. (t org-agenda-max-todos)))
  6345. (max-tags (cond ((listp org-agenda-max-tags)
  6346. (cdr (assoc type org-agenda-max-tags)))
  6347. (t org-agenda-max-tags)))
  6348. (max-entries (cond ((listp org-agenda-max-entries)
  6349. (cdr (assoc type org-agenda-max-entries)))
  6350. (t org-agenda-max-entries))) l)
  6351. (when org-agenda-before-sorting-filter-function
  6352. (setq list
  6353. (delq nil
  6354. (mapcar
  6355. org-agenda-before-sorting-filter-function list))))
  6356. (setq list (mapcar 'org-agenda-highlight-todo list)
  6357. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6358. (when max-effort
  6359. (setq list (org-agenda-limit-entries
  6360. list 'effort-minutes max-effort 'identity)))
  6361. (when max-todo
  6362. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6363. (when max-tags
  6364. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6365. (when max-entries
  6366. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6367. (mapconcat 'identity list "\n")))
  6368. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6369. "Limit the number of agenda entries."
  6370. (let ((include (and limit (< limit 0))))
  6371. (if limit
  6372. (let ((fun (or fn (lambda (p) (if p 1))))
  6373. (lim 0))
  6374. (delq nil
  6375. (mapcar
  6376. (lambda (e)
  6377. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6378. (if pval (setq lim (+ lim pval)))
  6379. (cond ((and pval (<= lim (abs limit))) e)
  6380. ((and include (not pval)) e))))
  6381. list)))
  6382. list)))
  6383. (defun org-agenda-limit-interactively ()
  6384. "In agenda, interactively limit entries to various maximums."
  6385. (interactive)
  6386. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6387. (num (string-to-number (read-from-minibuffer "How many? "))))
  6388. (cond ((equal max ?e)
  6389. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6390. ((equal max ?t)
  6391. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6392. ((equal max ?T)
  6393. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6394. ((equal max ?E)
  6395. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6396. (org-agenda-fit-window-to-buffer))
  6397. (defun org-agenda-highlight-todo (x)
  6398. (let ((org-done-keywords org-done-keywords-for-agenda)
  6399. (case-fold-search nil)
  6400. re)
  6401. (if (eq x 'line)
  6402. (save-excursion
  6403. (beginning-of-line 1)
  6404. (setq re (org-get-at-bol 'org-todo-regexp))
  6405. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6406. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6407. (add-text-properties (match-beginning 0) (match-end 1)
  6408. (list 'face (org-get-todo-face 1)))
  6409. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6410. (delete-region (match-beginning 1) (1- (match-end 0)))
  6411. (goto-char (match-beginning 1))
  6412. (insert (format org-agenda-todo-keyword-format s)))))
  6413. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6414. (setq re (get-text-property 0 'org-todo-regexp x))
  6415. (when (and re
  6416. ;; Test `pl' because if there's no heading content,
  6417. ;; there's no point matching to highlight. Note
  6418. ;; that if we didn't test `pl' first, and there
  6419. ;; happened to be no keyword from `org-todo-regexp'
  6420. ;; on this heading line, then the `equal' comparison
  6421. ;; afterwards would spuriously succeed in the case
  6422. ;; where `pl' is nil -- causing an args-out-of-range
  6423. ;; error when we try to add text properties to text
  6424. ;; that isn't there.
  6425. pl
  6426. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6427. x pl) pl))
  6428. (add-text-properties
  6429. (or (match-end 1) (match-end 0)) (match-end 0)
  6430. (list 'face (org-get-todo-face (match-string 2 x)))
  6431. x)
  6432. (when (match-end 1)
  6433. (setq x (concat (substring x 0 (match-end 1))
  6434. (format org-agenda-todo-keyword-format
  6435. (match-string 2 x))
  6436. (org-add-props " " (text-properties-at 0 x))
  6437. (substring x (match-end 3)))))))
  6438. x)))
  6439. (defsubst org-cmp-priority (a b)
  6440. "Compare the priorities of string A and B."
  6441. (let ((pa (or (get-text-property 1 'priority a) 0))
  6442. (pb (or (get-text-property 1 'priority b) 0)))
  6443. (cond ((> pa pb) +1)
  6444. ((< pa pb) -1))))
  6445. (defsubst org-cmp-effort (a b)
  6446. "Compare the effort values of string A and B."
  6447. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6448. (ea (or (get-text-property 1 'effort-minutes a) def))
  6449. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6450. (cond ((> ea eb) +1)
  6451. ((< ea eb) -1))))
  6452. (defsubst org-cmp-category (a b)
  6453. "Compare the string values of categories of strings A and B."
  6454. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6455. (cb (or (get-text-property 1 'org-category b) "")))
  6456. (cond ((string-lessp ca cb) -1)
  6457. ((string-lessp cb ca) +1))))
  6458. (defsubst org-cmp-todo-state (a b)
  6459. "Compare the todo states of strings A and B."
  6460. (let* ((ma (or (get-text-property 1 'org-marker a)
  6461. (get-text-property 1 'org-hd-marker a)))
  6462. (mb (or (get-text-property 1 'org-marker b)
  6463. (get-text-property 1 'org-hd-marker b)))
  6464. (fa (and ma (marker-buffer ma)))
  6465. (fb (and mb (marker-buffer mb)))
  6466. (todo-kwds
  6467. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6468. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6469. (ta (or (get-text-property 1 'todo-state a) ""))
  6470. (tb (or (get-text-property 1 'todo-state b) ""))
  6471. (la (- (length (member ta todo-kwds))))
  6472. (lb (- (length (member tb todo-kwds))))
  6473. (donepa (member ta org-done-keywords-for-agenda))
  6474. (donepb (member tb org-done-keywords-for-agenda)))
  6475. (cond ((and donepa (not donepb)) -1)
  6476. ((and (not donepa) donepb) +1)
  6477. ((< la lb) -1)
  6478. ((< lb la) +1))))
  6479. (defsubst org-cmp-alpha (a b)
  6480. "Compare the headlines, alphabetically."
  6481. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6482. (plb (text-property-any 0 (length b) 'org-heading t b))
  6483. (ta (and pla (substring a pla)))
  6484. (tb (and plb (substring b plb))))
  6485. (when pla
  6486. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6487. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6488. (setq ta (substring ta (match-end 0))))
  6489. (setq ta (downcase ta)))
  6490. (when plb
  6491. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6492. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6493. (setq tb (substring tb (match-end 0))))
  6494. (setq tb (downcase tb)))
  6495. (cond ((not ta) +1)
  6496. ((not tb) -1)
  6497. ((string-lessp ta tb) -1)
  6498. ((string-lessp tb ta) +1))))
  6499. (defsubst org-cmp-tag (a b)
  6500. "Compare the string values of the first tags of A and B."
  6501. (let ((ta (car (last (get-text-property 1 'tags a))))
  6502. (tb (car (last (get-text-property 1 'tags b)))))
  6503. (cond ((not ta) +1)
  6504. ((not tb) -1)
  6505. ((string-lessp ta tb) -1)
  6506. ((string-lessp tb ta) +1))))
  6507. (defsubst org-cmp-time (a b)
  6508. "Compare the time-of-day values of strings A and B."
  6509. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6510. (ta (or (get-text-property 1 'time-of-day a) def))
  6511. (tb (or (get-text-property 1 'time-of-day b) def)))
  6512. (cond ((< ta tb) -1)
  6513. ((< tb ta) +1))))
  6514. (defsubst org-cmp-ts (a b &optional type)
  6515. "Compare the timestamps values of entries A and B.
  6516. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6517. \"timestamp_ia\", compare within each of these type. When TYPE
  6518. is the empty string, compare all timestamps without respect of
  6519. their type."
  6520. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6521. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  6522. (get-text-property 1 'ts-date a)) def))
  6523. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  6524. (get-text-property 1 'ts-date b)) def)))
  6525. (cond ((< ta tb) -1)
  6526. ((< tb ta) +1))))
  6527. (defsubst org-cmp-habit-p (a b)
  6528. "Compare the todo states of strings A and B."
  6529. (let ((ha (get-text-property 1 'org-habit-p a))
  6530. (hb (get-text-property 1 'org-habit-p b)))
  6531. (cond ((and ha (not hb)) -1)
  6532. ((and (not ha) hb) +1))))
  6533. (defun org-entries-lessp (a b)
  6534. "Predicate for sorting agenda entries."
  6535. ;; The following variables will be used when the form is evaluated.
  6536. ;; So even though the compiler complains, keep them.
  6537. (let* ((ss org-agenda-sorting-strategy-selected)
  6538. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6539. (org-cmp-ts a b "")))
  6540. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6541. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6542. (org-cmp-ts a b "scheduled")))
  6543. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6544. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6545. (org-cmp-ts a b "deadline")))
  6546. (deadline-down (if deadline-up (- deadline-up) nil))
  6547. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6548. (org-cmp-ts a b "iatimestamp_ia")))
  6549. (tsia-down (if tsia-up (- tsia-up) nil))
  6550. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6551. (org-cmp-ts a b "timestamp")))
  6552. (ts-down (if ts-up (- ts-up) nil))
  6553. (time-up (and (org-em 'time-up 'time-down ss)
  6554. (org-cmp-time a b)))
  6555. (time-down (if time-up (- time-up) nil))
  6556. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6557. (org-cmp-priority a b)))
  6558. (priority-down (if priority-up (- priority-up) nil))
  6559. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6560. (org-cmp-effort a b)))
  6561. (effort-down (if effort-up (- effort-up) nil))
  6562. (category-up (and (or (org-em 'category-up 'category-down ss)
  6563. (memq 'category-keep ss))
  6564. (org-cmp-category a b)))
  6565. (category-down (if category-up (- category-up) nil))
  6566. (category-keep (if category-up +1 nil))
  6567. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6568. (org-cmp-tag a b)))
  6569. (tag-down (if tag-up (- tag-up) nil))
  6570. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6571. (org-cmp-todo-state a b)))
  6572. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6573. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6574. (org-cmp-habit-p a b)))
  6575. (habit-down (if habit-up (- habit-up) nil))
  6576. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6577. (org-cmp-alpha a b)))
  6578. (alpha-down (if alpha-up (- alpha-up) nil))
  6579. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6580. user-defined-up user-defined-down)
  6581. (if (and need-user-cmp org-agenda-cmp-user-defined
  6582. (functionp org-agenda-cmp-user-defined))
  6583. (setq user-defined-up
  6584. (funcall org-agenda-cmp-user-defined a b)
  6585. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6586. (cdr (assoc
  6587. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6588. '((-1 . t) (1 . nil) (nil . nil))))))
  6589. ;;; Agenda restriction lock
  6590. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6591. "Overlay to mark the headline to which agenda commands are restricted.")
  6592. (overlay-put org-agenda-restriction-lock-overlay
  6593. 'face 'org-agenda-restriction-lock)
  6594. (overlay-put org-agenda-restriction-lock-overlay
  6595. 'help-echo "Agendas are currently limited to this subtree.")
  6596. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6597. ;;;###autoload
  6598. (defun org-agenda-set-restriction-lock (&optional type)
  6599. "Set restriction lock for agenda, to current subtree or file.
  6600. Restriction will be the file if TYPE is `file', or if type is the
  6601. universal prefix '(4), or if the cursor is before the first headline
  6602. in the file. Otherwise, restriction will be to the current subtree."
  6603. (interactive "P")
  6604. (and (equal type '(4)) (setq type 'file))
  6605. (setq type (cond
  6606. (type type)
  6607. ((org-at-heading-p) 'subtree)
  6608. ((condition-case nil (org-back-to-heading t) (error nil))
  6609. 'subtree)
  6610. (t 'file)))
  6611. (if (eq type 'subtree)
  6612. (progn
  6613. (setq org-agenda-restrict (current-buffer))
  6614. (setq org-agenda-overriding-restriction 'subtree)
  6615. (put 'org-agenda-files 'org-restrict
  6616. (list (buffer-file-name (buffer-base-buffer))))
  6617. (org-back-to-heading t)
  6618. (move-overlay org-agenda-restriction-lock-overlay
  6619. (point)
  6620. (if org-agenda-restriction-lock-highlight-subtree
  6621. (save-excursion (org-end-of-subtree t t) (point))
  6622. (point-at-eol)))
  6623. (move-marker org-agenda-restrict-begin (point))
  6624. (move-marker org-agenda-restrict-end
  6625. (save-excursion (org-end-of-subtree t t)))
  6626. (message "Locking agenda restriction to subtree"))
  6627. (put 'org-agenda-files 'org-restrict
  6628. (list (buffer-file-name (buffer-base-buffer))))
  6629. (setq org-agenda-restrict nil)
  6630. (setq org-agenda-overriding-restriction 'file)
  6631. (move-marker org-agenda-restrict-begin nil)
  6632. (move-marker org-agenda-restrict-end nil)
  6633. (message "Locking agenda restriction to file"))
  6634. (setq current-prefix-arg nil)
  6635. (org-agenda-maybe-redo))
  6636. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6637. "Remove the agenda restriction lock."
  6638. (interactive "P")
  6639. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6640. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6641. (setq org-agenda-overriding-restriction nil)
  6642. (setq org-agenda-restrict nil)
  6643. (put 'org-agenda-files 'org-restrict nil)
  6644. (move-marker org-agenda-restrict-begin nil)
  6645. (move-marker org-agenda-restrict-end nil)
  6646. (setq current-prefix-arg nil)
  6647. (message "Agenda restriction lock removed")
  6648. (or noupdate (org-agenda-maybe-redo)))
  6649. (defun org-agenda-maybe-redo ()
  6650. "If there is any window showing the agenda view, update it."
  6651. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6652. (w0 (selected-window)))
  6653. (when w
  6654. (select-window w)
  6655. (org-agenda-redo)
  6656. (select-window w0)
  6657. (if org-agenda-overriding-restriction
  6658. (message "Agenda view shifted to new %s restriction"
  6659. org-agenda-overriding-restriction)
  6660. (message "Agenda restriction lock removed")))))
  6661. ;;; Agenda commands
  6662. (defun org-agenda-check-type (error &rest types)
  6663. "Check if agenda buffer is of allowed type.
  6664. If ERROR is non-nil, throw an error, otherwise just return nil.
  6665. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6666. (if (not org-agenda-type)
  6667. (error "No Org agenda currently displayed")
  6668. (if (memq org-agenda-type types)
  6669. t
  6670. (if error
  6671. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6672. nil))))
  6673. (defun org-agenda-Quit ()
  6674. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6675. Also restore the window configuration."
  6676. (interactive)
  6677. (if org-agenda-columns-active
  6678. (org-columns-quit)
  6679. (let ((buf (current-buffer)))
  6680. (if (eq org-agenda-window-setup 'other-frame)
  6681. (progn
  6682. (org-agenda-reset-markers)
  6683. (kill-buffer buf)
  6684. (org-columns-remove-overlays)
  6685. (setq org-agenda-archives-mode nil)
  6686. (delete-frame))
  6687. (and (not (eq org-agenda-window-setup 'current-window))
  6688. (not (one-window-p))
  6689. (delete-window))
  6690. (org-agenda-reset-markers)
  6691. (kill-buffer buf)
  6692. (org-columns-remove-overlays)
  6693. (setq org-agenda-archives-mode nil)))
  6694. (setq org-agenda-buffer nil)
  6695. ;; Maybe restore the pre-agenda window configuration.
  6696. (and org-agenda-restore-windows-after-quit
  6697. (not (eq org-agenda-window-setup 'other-frame))
  6698. org-agenda-pre-window-conf
  6699. (set-window-configuration org-agenda-pre-window-conf)
  6700. (setq org-agenda-pre-window-conf nil))))
  6701. (defun org-agenda-quit ()
  6702. "Exit the agenda and restore the window configuration.
  6703. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6704. (interactive)
  6705. (if (and (eq org-indirect-buffer-display 'other-window)
  6706. org-last-indirect-buffer)
  6707. (let ((org-last-indirect-window
  6708. (get-buffer-window org-last-indirect-buffer)))
  6709. (if org-last-indirect-window
  6710. (delete-window org-last-indirect-window))))
  6711. (if org-agenda-columns-active
  6712. (org-columns-quit)
  6713. (if org-agenda-sticky
  6714. (let ((buf (current-buffer)))
  6715. (if (eq org-agenda-window-setup 'other-frame)
  6716. (progn
  6717. (delete-frame))
  6718. (and (not (eq org-agenda-window-setup 'current-window))
  6719. (not (one-window-p))
  6720. (delete-window)))
  6721. (with-current-buffer buf
  6722. (bury-buffer)
  6723. ;; Maybe restore the pre-agenda window configuration.
  6724. (and org-agenda-restore-windows-after-quit
  6725. (not (eq org-agenda-window-setup 'other-frame))
  6726. org-agenda-pre-window-conf
  6727. (set-window-configuration org-agenda-pre-window-conf)
  6728. (setq org-agenda-pre-window-conf nil))))
  6729. (org-agenda-Quit))))
  6730. (defun org-agenda-exit ()
  6731. "Exit the agenda and restore the window configuration.
  6732. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6733. buffers visited directly by the user will not be touched."
  6734. (interactive)
  6735. (org-release-buffers org-agenda-new-buffers)
  6736. (setq org-agenda-new-buffers nil)
  6737. (org-agenda-Quit))
  6738. (defun org-agenda-kill-all-agenda-buffers ()
  6739. "Kill all buffers in `org-agenda-mode'.
  6740. This is used when toggling sticky agendas.
  6741. You can also explicitly invoke it with `C-c a C-k'."
  6742. (interactive)
  6743. (let (blist)
  6744. (dolist (buf (buffer-list))
  6745. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6746. (push buf blist)))
  6747. (mapc 'kill-buffer blist)))
  6748. (defun org-agenda-execute (arg)
  6749. "Execute another agenda command, keeping same window.
  6750. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6751. in the agenda."
  6752. (interactive "P")
  6753. (let ((org-agenda-window-setup 'current-window))
  6754. (org-agenda arg)))
  6755. (defun org-agenda-redo (&optional all)
  6756. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6757. (interactive "P")
  6758. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6759. (cpa (unless (eq all t) current-prefix-arg))
  6760. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6761. (org-agenda-sticky nil)
  6762. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6763. org-agenda-buffer-name))
  6764. (org-agenda-keep-modes t)
  6765. (tag-filter org-agenda-tag-filter)
  6766. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6767. (top-hl-filter org-agenda-top-headline-filter)
  6768. (cat-filter org-agenda-category-filter)
  6769. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6770. (re-filter org-agenda-regexp-filter)
  6771. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6772. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6773. (cols org-agenda-columns-active)
  6774. (line (org-current-line))
  6775. (window-line (- line (org-current-line (window-start))))
  6776. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6777. (redo-cmd (get-text-property p 'org-redo-cmd))
  6778. (last-args (get-text-property p 'org-last-args))
  6779. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6780. (org-agenda-overriding-cmd-arguments
  6781. (unless (eq all t)
  6782. (cond ((listp last-args)
  6783. (cons (or cpa (car last-args)) (cdr last-args)))
  6784. ((stringp last-args)
  6785. last-args))))
  6786. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6787. (put 'org-agenda-tag-filter :preset-filter nil)
  6788. (put 'org-agenda-category-filter :preset-filter nil)
  6789. (put 'org-agenda-regexp-filter :preset-filter nil)
  6790. (and cols (org-columns-quit))
  6791. (message "Rebuilding agenda buffer...")
  6792. (if series-redo-cmd
  6793. (eval series-redo-cmd)
  6794. (org-let lprops redo-cmd))
  6795. (setq org-agenda-undo-list nil
  6796. org-agenda-pending-undo-list nil
  6797. org-agenda-tag-filter tag-filter
  6798. org-agenda-category-filter cat-filter
  6799. org-agenda-regexp-filter re-filter
  6800. org-agenda-top-headline-filter top-hl-filter)
  6801. (message "Rebuilding agenda buffer...done")
  6802. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6803. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6804. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6805. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6806. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6807. (and (or re-filter re-preset) (org-agenda-filter-apply re-filter 'regexp))
  6808. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6809. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6810. (org-goto-line line)
  6811. (recenter window-line)))
  6812. (defvar org-global-tags-completion-table nil)
  6813. (defvar org-agenda-filter-form nil)
  6814. (defvar org-agenda-filtered-by-category nil)
  6815. (defun org-agenda-filter-by-category (strip)
  6816. "Keep only those lines in the agenda buffer that have a specific category.
  6817. The category is that of the current line."
  6818. (interactive "P")
  6819. (if (and org-agenda-filtered-by-category
  6820. org-agenda-category-filter)
  6821. (org-agenda-filter-show-all-cat)
  6822. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6823. (cond
  6824. ((and cat strip)
  6825. (org-agenda-filter-apply
  6826. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6827. ((and cat)
  6828. (org-agenda-filter-apply
  6829. (setq org-agenda-category-filter
  6830. (list (concat "+" cat))) 'category))
  6831. ((error "No category at point"))))))
  6832. (defun org-find-top-headline (&optional pos)
  6833. "Find the topmost parent headline and return it."
  6834. (save-excursion
  6835. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6836. (if pos (goto-char pos))
  6837. ;; Skip up to the topmost parent
  6838. (while (ignore-errors (outline-up-heading 1) t))
  6839. (ignore-errors
  6840. (nth 4 (org-heading-components))))))
  6841. (defvar org-agenda-filtered-by-top-headline nil)
  6842. (defun org-agenda-filter-by-top-headline (strip)
  6843. "Keep only those lines that are descendants from the same top headline.
  6844. The top headline is that of the current line."
  6845. (interactive "P")
  6846. (if org-agenda-filtered-by-top-headline
  6847. (progn
  6848. (setq org-agenda-filtered-by-top-headline nil
  6849. org-agenda-top-headline-filter nil)
  6850. (org-agenda-filter-show-all-cat))
  6851. (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6852. (if cat (org-agenda-filter-top-headline-apply cat strip)
  6853. (error "No top-level category at point")))))
  6854. (defvar org-agenda-regexp-filter nil)
  6855. (defun org-agenda-filter-by-regexp (strip)
  6856. "Filter agenda entries by a regular expression.
  6857. Regexp filters are cumulative.
  6858. With no prefix argument, keep entries matching the regexp.
  6859. With one prefix argument, filter out entries matching the regexp.
  6860. With two prefix arguments, remove the regexp filters."
  6861. (interactive "P")
  6862. (if (not (equal strip '(16)))
  6863. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6864. (read-from-minibuffer
  6865. (if (equal strip '(4))
  6866. "Filter out entries matching regexp: "
  6867. "Narrow to entries matching regexp: ")))))
  6868. (push flt org-agenda-regexp-filter)
  6869. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6870. (org-agenda-filter-show-all-re)
  6871. (message "Regexp filter removed")))
  6872. (defun org-agenda-filter-remove-all ()
  6873. "Remove all filters from the current agenda buffer."
  6874. (interactive)
  6875. (when org-agenda-tag-filter
  6876. (org-agenda-filter-show-all-tag))
  6877. (when org-agenda-category-filter
  6878. (org-agenda-filter-show-all-cat))
  6879. (when org-agenda-regexp-filter
  6880. (org-agenda-filter-show-all-re)))
  6881. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6882. "Keep only those lines in the agenda buffer that have a specific tag.
  6883. The tag is selected with its fast selection letter, as configured.
  6884. With prefix argument STRIP, remove all lines that do have the tag.
  6885. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6886. used to narrow the search - the interactive user can also press `-' or `+'
  6887. to switch to narrowing."
  6888. (interactive "P")
  6889. (let* ((alist org-tag-alist-for-agenda)
  6890. (tag-chars (mapconcat
  6891. (lambda (x) (if (and (not (symbolp (car x)))
  6892. (cdr x))
  6893. (char-to-string (cdr x))
  6894. ""))
  6895. alist ""))
  6896. (efforts (org-split-string
  6897. (or (cdr (assoc (concat org-effort-property "_ALL")
  6898. org-global-properties))
  6899. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6900. "")))
  6901. (effort-op org-agenda-filter-effort-default-operator)
  6902. (effort-prompt "")
  6903. (inhibit-read-only t)
  6904. (current org-agenda-tag-filter)
  6905. maybe-refresh a n tag)
  6906. (unless char
  6907. (message
  6908. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6909. (if narrow "Narrow" "Filter") tag-chars
  6910. (if org-agenda-auto-exclude-function "[RET], " ""))
  6911. (setq char (read-char-exclusive)))
  6912. (when (member char '(?+ ?-))
  6913. ;; Narrowing down
  6914. (cond ((equal char ?-) (setq strip t narrow t))
  6915. ((equal char ?+) (setq strip nil narrow t)))
  6916. (message
  6917. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6918. (setq char (read-char-exclusive)))
  6919. (when (member char '(?< ?> ?= ??))
  6920. ;; An effort operator
  6921. (setq effort-op (char-to-string char))
  6922. (setq alist nil) ; to make sure it will be interpreted as effort.
  6923. (unless (equal char ??)
  6924. (loop for i from 0 to 9 do
  6925. (setq effort-prompt
  6926. (concat
  6927. effort-prompt " ["
  6928. (if (= i 9) "0" (int-to-string (1+ i)))
  6929. "]" (nth i efforts))))
  6930. (message "Effort%s: %s " effort-op effort-prompt)
  6931. (setq char (read-char-exclusive))
  6932. (when (or (< char ?0) (> char ?9))
  6933. (error "Need 1-9,0 to select effort"))))
  6934. (when (equal char ?\t)
  6935. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6936. (org-set-local 'org-global-tags-completion-table
  6937. (org-global-tags-completion-table)))
  6938. (let ((completion-ignore-case t))
  6939. (setq tag (org-icompleting-read
  6940. "Tag: " org-global-tags-completion-table))))
  6941. (cond
  6942. ((equal char ?\r)
  6943. (org-agenda-filter-show-all-tag)
  6944. (when org-agenda-auto-exclude-function
  6945. (setq org-agenda-tag-filter nil)
  6946. (dolist (tag (org-agenda-get-represented-tags))
  6947. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6948. (if modifier
  6949. (push modifier org-agenda-tag-filter))))
  6950. (if (not (null org-agenda-tag-filter))
  6951. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6952. (setq maybe-refresh t))
  6953. ((equal char ?/)
  6954. (org-agenda-filter-show-all-tag)
  6955. (when (get 'org-agenda-tag-filter :preset-filter)
  6956. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6957. (setq maybe-refresh t))
  6958. ((equal char ?. )
  6959. (setq org-agenda-tag-filter
  6960. (mapcar (lambda(tag) (concat "+" tag))
  6961. (org-get-at-bol 'tags)))
  6962. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6963. (setq maybe-refresh t))
  6964. ((or (equal char ?\ )
  6965. (setq a (rassoc char alist))
  6966. (and (>= char ?0) (<= char ?9)
  6967. (setq n (if (= char ?0) 9 (- char ?0 1))
  6968. tag (concat effort-op (nth n efforts))
  6969. a (cons tag nil)))
  6970. (and (= char ??)
  6971. (setq tag "?eff")
  6972. a (cons tag nil))
  6973. (and tag (setq a (cons tag nil))))
  6974. (org-agenda-filter-show-all-tag)
  6975. (setq tag (car a))
  6976. (setq org-agenda-tag-filter
  6977. (cons (concat (if strip "-" "+") tag)
  6978. (if narrow current nil)))
  6979. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6980. (setq maybe-refresh t))
  6981. (t (error "Invalid tag selection character %c" char)))
  6982. (when (and maybe-refresh
  6983. (eq org-agenda-clockreport-mode 'with-filter))
  6984. (org-agenda-redo))))
  6985. (defun org-agenda-get-represented-tags ()
  6986. "Get a list of all tags currently represented in the agenda."
  6987. (let (p tags)
  6988. (save-excursion
  6989. (goto-char (point-min))
  6990. (while (setq p (next-single-property-change (point) 'tags))
  6991. (goto-char p)
  6992. (mapc (lambda (x) (add-to-list 'tags x))
  6993. (get-text-property (point) 'tags))))
  6994. tags))
  6995. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6996. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6997. (interactive "P")
  6998. (org-agenda-filter-by-tag strip char 'refine))
  6999. (defun org-agenda-filter-make-matcher (filter type)
  7000. "Create the form that tests a line for agenda filter."
  7001. (let (f f1)
  7002. (cond
  7003. ;; Tag filter
  7004. ((eq type 'tag)
  7005. (setq filter
  7006. (delete-dups
  7007. (append (get 'org-agenda-tag-filter :preset-filter)
  7008. filter)))
  7009. (dolist (x filter)
  7010. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  7011. (ffunc
  7012. (lambda (nf0 nf01 fltr notgroup op)
  7013. (dolist (x fltr)
  7014. (if (member x '("-" "+"))
  7015. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  7016. (if (string-match "[<=>?]" x)
  7017. (setq nf01 (org-agenda-filter-effort-form x))
  7018. (setq nf01 (list 'member (downcase (substring x 1))
  7019. 'tags)))
  7020. (when (equal (string-to-char x) ?-)
  7021. (setq nf01 (list 'not nf01))
  7022. (when (not notgroup) (setq op 'and))))
  7023. (push nf01 nf0))
  7024. (if notgroup
  7025. (push (cons 'and nf0) f)
  7026. (push (cons (or op 'or) nf0) f)))))
  7027. (cond ((equal filter '("+"))
  7028. (setq f (list (list 'not 'tags))))
  7029. ((equal nfilter filter)
  7030. (funcall ffunc f1 f filter t nil))
  7031. (t (funcall ffunc nf1 nf nfilter nil nil))))))
  7032. ;; Category filter
  7033. ((eq type 'category)
  7034. (setq filter
  7035. (delete-dups
  7036. (append (get 'org-agenda-category-filter :preset-filter)
  7037. filter)))
  7038. (dolist (x filter)
  7039. (if (equal "-" (substring x 0 1))
  7040. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7041. (setq f1 (list 'equal (substring x 1) 'cat)))
  7042. (push f1 f)))
  7043. ;; Regexp filter
  7044. ((eq type 'regexp)
  7045. (setq filter
  7046. (delete-dups
  7047. (append (get 'org-agenda-regexp-filter :preset-filter)
  7048. filter)))
  7049. (dolist (x filter)
  7050. (if (equal "-" (substring x 0 1))
  7051. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7052. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7053. (push f1 f))))
  7054. (cons 'and (nreverse f))))
  7055. (defun org-agenda-filter-effort-form (e)
  7056. "Return the form to compare the effort of the current line with what E says.
  7057. E looks like \"+<2:25\"."
  7058. (let (op)
  7059. (setq e (substring e 1))
  7060. (setq op (string-to-char e) e (substring e 1))
  7061. (setq op (cond ((equal op ?<) '<=)
  7062. ((equal op ?>) '>=)
  7063. ((equal op ??) op)
  7064. (t '=)))
  7065. (list 'org-agenda-compare-effort (list 'quote op)
  7066. (org-duration-string-to-minutes e))))
  7067. (defun org-agenda-compare-effort (op value)
  7068. "Compare the effort of the current line with VALUE, using OP.
  7069. If the line does not have an effort defined, return nil."
  7070. (let ((eff (org-get-at-bol 'effort-minutes)))
  7071. (if (equal op ??)
  7072. (not eff)
  7073. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7074. value))))
  7075. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7076. "Expand group tags in FILTER for the agenda.
  7077. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7078. (if org-group-tags
  7079. (let ((case-fold-search t) rtn)
  7080. (mapc
  7081. (lambda (f)
  7082. (let (f0 dir)
  7083. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7084. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7085. (setq dir (if no-operator "" "+") f0 f))
  7086. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7087. (org-tags-expand f0 t t))
  7088. rtn))))
  7089. filter)
  7090. (reverse rtn))
  7091. filter))
  7092. (defun org-agenda-filter-apply (filter type)
  7093. "Set FILTER as the new agenda filter and apply it."
  7094. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7095. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7096. (let (tags cat txt)
  7097. (setq org-agenda-filter-form
  7098. (org-agenda-filter-make-matcher filter type))
  7099. (if (and (eq type 'category)
  7100. (not (equal (substring (car filter) 0 1) "-")))
  7101. ;; Only set `org-agenda-filtered-by-category' to t
  7102. ;; when a unique category is used as the filter
  7103. (setq org-agenda-filtered-by-category t))
  7104. (org-agenda-set-mode-name)
  7105. (save-excursion
  7106. (goto-char (point-min))
  7107. (while (not (eobp))
  7108. (if (org-get-at-bol 'org-marker)
  7109. (progn
  7110. (setq tags ; used in eval
  7111. (apply 'append
  7112. (mapcar (lambda (f)
  7113. (org-agenda-filter-expand-tags (list f) t))
  7114. (org-get-at-bol 'tags)))
  7115. cat (get-text-property (point) 'org-category)
  7116. txt (get-text-property (point) 'txt))
  7117. (if (not (eval org-agenda-filter-form))
  7118. (org-agenda-filter-hide-line type))
  7119. (beginning-of-line 2))
  7120. (beginning-of-line 2))))
  7121. (if (get-char-property (point) 'invisible)
  7122. (ignore-errors (org-agenda-previous-line)))))
  7123. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7124. "Filter by top headline HL."
  7125. (org-agenda-set-mode-name)
  7126. (save-excursion
  7127. (goto-char (point-min))
  7128. (while (not (eobp))
  7129. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7130. (tophl (and pos (org-find-top-headline pos))))
  7131. (if (and tophl (funcall (if negative 'identity 'not)
  7132. (string= hl tophl)))
  7133. (org-agenda-filter-hide-line 'category)))
  7134. (beginning-of-line 2)))
  7135. (if (get-char-property (point) 'invisible)
  7136. (org-agenda-previous-line))
  7137. (setq org-agenda-top-headline-filter hl
  7138. org-agenda-filtered-by-top-headline t))
  7139. (defun org-agenda-filter-hide-line (type)
  7140. "Hide lines with TYPE in the agenda buffer."
  7141. (let (ov)
  7142. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  7143. (point-at-eol)))
  7144. (overlay-put ov 'invisible t)
  7145. (overlay-put ov 'type type)
  7146. (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays))
  7147. ((eq type 'category) (push ov org-agenda-cat-filter-overlays))
  7148. ((eq type 'regexp) (push ov org-agenda-re-filter-overlays)))))
  7149. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  7150. (setq pos (or pos (point)))
  7151. (save-excursion
  7152. (dolist (ov (overlays-at pos))
  7153. (when (and (overlay-get ov 'invisible)
  7154. (eq (overlay-get ov 'type) 'tag))
  7155. (goto-char pos)
  7156. (if (< (overlay-start ov) (point-at-eol))
  7157. (move-overlay ov (point-at-eol)
  7158. (overlay-end ov)))))))
  7159. (defun org-agenda-filter-show-all-tag nil
  7160. "Remove tag filter overlays from the agenda buffer."
  7161. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  7162. (setq org-agenda-tag-filter-overlays nil
  7163. org-agenda-tag-filter nil
  7164. org-agenda-filter-form nil)
  7165. (org-agenda-set-mode-name))
  7166. (defun org-agenda-filter-show-all-re nil
  7167. "Remove regexp filter overlays from the agenda buffer."
  7168. (mapc 'delete-overlay org-agenda-re-filter-overlays)
  7169. (setq org-agenda-re-filter-overlays nil
  7170. org-agenda-regexp-filter nil
  7171. org-agenda-filter-form nil)
  7172. (org-agenda-set-mode-name))
  7173. (defun org-agenda-filter-show-all-cat nil
  7174. "Remove category filter overlays from the agenda buffer."
  7175. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  7176. (setq org-agenda-cat-filter-overlays nil
  7177. org-agenda-filtered-by-category nil
  7178. org-agenda-category-filter nil
  7179. org-agenda-filter-form nil)
  7180. (org-agenda-set-mode-name))
  7181. (defun org-agenda-manipulate-query-add ()
  7182. "Manipulate the query by adding a search term with positive selection.
  7183. Positive selection means the term must be matched for selection of an entry."
  7184. (interactive)
  7185. (org-agenda-manipulate-query ?\[))
  7186. (defun org-agenda-manipulate-query-subtract ()
  7187. "Manipulate the query by adding a search term with negative selection.
  7188. Negative selection means term must not be matched for selection of an entry."
  7189. (interactive)
  7190. (org-agenda-manipulate-query ?\]))
  7191. (defun org-agenda-manipulate-query-add-re ()
  7192. "Manipulate the query by adding a search regexp with positive selection.
  7193. Positive selection means the regexp must match for selection of an entry."
  7194. (interactive)
  7195. (org-agenda-manipulate-query ?\{))
  7196. (defun org-agenda-manipulate-query-subtract-re ()
  7197. "Manipulate the query by adding a search regexp with negative selection.
  7198. Negative selection means regexp must not match for selection of an entry."
  7199. (interactive)
  7200. (org-agenda-manipulate-query ?\}))
  7201. (defun org-agenda-manipulate-query (char)
  7202. (cond
  7203. ((memq org-agenda-type '(timeline agenda))
  7204. (let ((org-agenda-include-inactive-timestamps t))
  7205. (org-agenda-redo))
  7206. (message "Display now includes inactive timestamps as well"))
  7207. ((eq org-agenda-type 'search)
  7208. (org-add-to-string
  7209. 'org-agenda-query-string
  7210. (if org-agenda-last-search-view-search-was-boolean
  7211. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7212. (?\{ . " +{}") (?\} . " -{}"))))
  7213. " "))
  7214. (setq org-agenda-redo-command
  7215. (list 'org-search-view
  7216. (car (get-text-property (min (1- (point-max)) (point))
  7217. 'org-last-args))
  7218. org-agenda-query-string
  7219. (+ (length org-agenda-query-string)
  7220. (if (member char '(?\{ ?\})) 0 1))))
  7221. (set-register org-agenda-query-register org-agenda-query-string)
  7222. (let ((org-agenda-overriding-arguments
  7223. (cdr org-agenda-redo-command)))
  7224. (org-agenda-redo)))
  7225. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7226. org-agenda-type))))
  7227. (defun org-add-to-string (var string)
  7228. (set var (concat (symbol-value var) string)))
  7229. (defun org-agenda-goto-date (span)
  7230. "Jump to DATE in agenda."
  7231. (interactive "P")
  7232. (let* ((org-read-date-prefer-future
  7233. (eval org-agenda-jump-prefer-future))
  7234. (date (org-read-date))
  7235. (day (time-to-days (org-time-string-to-time date)))
  7236. (org-agenda-sticky-orig org-agenda-sticky)
  7237. (org-agenda-buffer-tmp-name (buffer-name))
  7238. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7239. (0-arg (or current-prefix-arg (car args)))
  7240. (2-arg (nth 2 args))
  7241. (with-hour-p (nth 4 org-agenda-redo-command))
  7242. (newcmd (list 'org-agenda-list 0-arg date
  7243. (org-agenda-span-to-ndays
  7244. 2-arg (org-time-string-to-absolute date))
  7245. with-hour-p))
  7246. (newargs (cdr newcmd))
  7247. (inhibit-read-only t)
  7248. org-agenda-sticky)
  7249. (if (not (org-agenda-check-type t 'agenda))
  7250. (error "Not available in non-agenda views")
  7251. (add-text-properties (point-min) (point-max)
  7252. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7253. (org-agenda-redo)
  7254. (goto-char (point-min))
  7255. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7256. (save-excursion (move-beginning-of-line 2) (eobp))))
  7257. (move-beginning-of-line 2))
  7258. (setq org-agenda-sticky org-agenda-sticky-orig
  7259. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7260. (defun org-agenda-goto-today ()
  7261. "Go to today."
  7262. (interactive)
  7263. (org-agenda-check-type t 'timeline 'agenda)
  7264. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7265. (curspan (nth 2 args))
  7266. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7267. (cond
  7268. (tdpos (goto-char tdpos))
  7269. ((eq org-agenda-type 'agenda)
  7270. (let* ((sd (org-agenda-compute-starting-span
  7271. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7272. (org-agenda-overriding-arguments args))
  7273. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7274. (org-agenda-redo)
  7275. (org-agenda-find-same-or-today-or-agenda)))
  7276. (t (error "Cannot find today")))))
  7277. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7278. (goto-char
  7279. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7280. (text-property-any (point-min) (point-max) 'org-today t)
  7281. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7282. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7283. (org-agenda-backward-block))
  7284. (point-min))))
  7285. (defun org-agenda-backward-block ()
  7286. "Move backward by one agenda block."
  7287. (interactive)
  7288. (org-agenda-forward-block 'backward))
  7289. (defun org-agenda-forward-block (&optional backward)
  7290. "Move forward by one agenda block.
  7291. When optional argument BACKWARD is set, go backward"
  7292. (interactive)
  7293. (cond ((not (derived-mode-p 'org-agenda-mode))
  7294. (user-error
  7295. "Cannot execute this command outside of org-agenda-mode buffers"))
  7296. ((looking-at (if backward "\\`" "\\'"))
  7297. (message "Already at the %s block" (if backward "first" "last")))
  7298. (t (let ((pos (prog1 (point)
  7299. (ignore-errors (if backward (backward-char 1)
  7300. (move-end-of-line 1)))))
  7301. (f (if backward
  7302. 'previous-single-property-change
  7303. 'next-single-property-change))
  7304. moved dest)
  7305. (while (and (setq dest (funcall
  7306. f (point) 'org-agenda-structural-header))
  7307. (not (get-text-property
  7308. (point) 'org-agenda-structural-header)))
  7309. (setq moved t)
  7310. (goto-char dest))
  7311. (if moved (move-beginning-of-line 1)
  7312. (goto-char (if backward (point-min) (point-max)))
  7313. (move-beginning-of-line 1)
  7314. (message "No %s block" (if backward "previous" "further")))))))
  7315. (defun org-agenda-later (arg)
  7316. "Go forward in time by the current span.
  7317. With prefix ARG, go forward that many times the current span."
  7318. (interactive "p")
  7319. (org-agenda-check-type t 'agenda)
  7320. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7321. (span (or (nth 2 args) org-agenda-current-span))
  7322. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7323. (greg (calendar-gregorian-from-absolute sd))
  7324. (cnt (org-get-at-bol 'org-day-cnt))
  7325. greg2)
  7326. (cond
  7327. ((numberp span)
  7328. (setq sd (+ (* span arg) sd)))
  7329. ((eq span 'day)
  7330. (setq sd (+ arg sd)))
  7331. ((eq span 'week)
  7332. (setq sd (+ (* 7 arg) sd)))
  7333. ((eq span 'fortnight)
  7334. (setq sd (+ (* 14 arg) sd)))
  7335. ((eq span 'month)
  7336. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7337. sd (calendar-absolute-from-gregorian greg2))
  7338. (setcar greg2 (1+ (car greg2))))
  7339. ((eq span 'year)
  7340. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7341. sd (calendar-absolute-from-gregorian greg2))
  7342. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7343. (t
  7344. (setq sd (+ (* span arg) sd))))
  7345. (let ((org-agenda-overriding-cmd
  7346. ;; `cmd' may have been set by `org-agenda-run-series' which
  7347. ;; uses `org-agenda-overriding-cmd' to decide whether
  7348. ;; overriding is allowed for `cmd'
  7349. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7350. (org-agenda-overriding-arguments
  7351. (list (car args) sd span)))
  7352. (org-agenda-redo)
  7353. (org-agenda-find-same-or-today-or-agenda cnt))))
  7354. (defun org-agenda-earlier (arg)
  7355. "Go backward in time by the current span.
  7356. With prefix ARG, go backward that many times the current span."
  7357. (interactive "p")
  7358. (org-agenda-later (- arg)))
  7359. (defun org-agenda-view-mode-dispatch ()
  7360. "Call one of the view mode commands."
  7361. (interactive)
  7362. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7363. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7364. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7365. (let ((a (read-char-exclusive)))
  7366. (case a
  7367. (?\ (call-interactively 'org-agenda-reset-view))
  7368. (?d (call-interactively 'org-agenda-day-view))
  7369. (?w (call-interactively 'org-agenda-week-view))
  7370. (?t (call-interactively 'org-agenda-fortnight-view))
  7371. (?m (call-interactively 'org-agenda-month-view))
  7372. (?y (call-interactively 'org-agenda-year-view))
  7373. (?l (call-interactively 'org-agenda-log-mode))
  7374. (?L (org-agenda-log-mode '(4)))
  7375. (?c (org-agenda-log-mode 'clockcheck))
  7376. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7377. (?a (call-interactively 'org-agenda-archives-mode))
  7378. (?A (org-agenda-archives-mode 'files))
  7379. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7380. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7381. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7382. (?D (call-interactively 'org-agenda-toggle-diary))
  7383. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7384. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7385. (org-agenda-check-type t 'timeline 'agenda)
  7386. (org-agenda-redo))
  7387. (message "Display now includes inactive timestamps as well"))
  7388. (?q (message "Abort"))
  7389. (otherwise (error "Invalid key" )))))
  7390. (defun org-agenda-reset-view ()
  7391. "Switch to default view for agenda."
  7392. (interactive)
  7393. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7394. (defun org-agenda-day-view (&optional day-of-month)
  7395. "Switch to daily view for agenda.
  7396. With argument DAY-OF-MONTH, switch to that day of the month."
  7397. (interactive "P")
  7398. (org-agenda-change-time-span 'day day-of-month))
  7399. (defun org-agenda-week-view (&optional iso-week)
  7400. "Switch to daily view for agenda.
  7401. With argument ISO-WEEK, switch to the corresponding ISO week.
  7402. If ISO-WEEK has more then 2 digits, only the last two encode the
  7403. week. Any digits before this encode a year. So 200712 means
  7404. week 12 of year 2007. Years in the range 1938-2037 can also be
  7405. written as 2-digit years."
  7406. (interactive "P")
  7407. (org-agenda-change-time-span 'week iso-week))
  7408. (defun org-agenda-fortnight-view (&optional iso-week)
  7409. "Switch to daily view for agenda.
  7410. With argument ISO-WEEK, switch to the corresponding ISO week.
  7411. If ISO-WEEK has more then 2 digits, only the last two encode the
  7412. week. Any digits before this encode a year. So 200712 means
  7413. week 12 of year 2007. Years in the range 1938-2037 can also be
  7414. written as 2-digit years."
  7415. (interactive "P")
  7416. (org-agenda-change-time-span 'fortnight iso-week))
  7417. (defun org-agenda-month-view (&optional month)
  7418. "Switch to monthly view for agenda.
  7419. With argument MONTH, switch to that month."
  7420. (interactive "P")
  7421. (org-agenda-change-time-span 'month month))
  7422. (defun org-agenda-year-view (&optional year)
  7423. "Switch to yearly view for agenda.
  7424. With argument YEAR, switch to that year.
  7425. If MONTH has more then 2 digits, only the last two encode the
  7426. month. Any digits before this encode a year. So 200712 means
  7427. December year 2007. Years in the range 1938-2037 can also be
  7428. written as 2-digit years."
  7429. (interactive "P")
  7430. (when year
  7431. (setq year (org-small-year-to-year year)))
  7432. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7433. (org-agenda-change-time-span 'year year)
  7434. (error "Abort")))
  7435. (defun org-agenda-change-time-span (span &optional n)
  7436. "Change the agenda view to SPAN.
  7437. SPAN may be `day', `week', `fortnight', `month', `year'."
  7438. (org-agenda-check-type t 'agenda)
  7439. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7440. (curspan (nth 2 args)))
  7441. (if (and (not n) (equal curspan span))
  7442. (error "Viewing span is already \"%s\"" span))
  7443. (let* ((sd (or (org-get-at-bol 'day)
  7444. (nth 1 args)
  7445. org-starting-day))
  7446. (sd (org-agenda-compute-starting-span sd span n))
  7447. (org-agenda-overriding-cmd
  7448. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7449. (org-agenda-overriding-arguments
  7450. (list (car args) sd span)))
  7451. (org-agenda-redo)
  7452. (org-agenda-find-same-or-today-or-agenda))
  7453. (org-agenda-set-mode-name)
  7454. (message "Switched to %s view" span)))
  7455. (defun org-agenda-compute-starting-span (sd span &optional n)
  7456. "Compute starting date for agenda.
  7457. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7458. is a cons cell with the starting date and the number of days,
  7459. so that the date SD will be in that range."
  7460. (let* ((greg (calendar-gregorian-from-absolute sd))
  7461. (dg (nth 1 greg))
  7462. (mg (car greg))
  7463. (yg (nth 2 greg)))
  7464. (cond
  7465. ((eq span 'day)
  7466. (when n
  7467. (setq sd (+ (calendar-absolute-from-gregorian
  7468. (list mg 1 yg))
  7469. n -1))))
  7470. ((or (eq span 'week) (eq span 'fortnight))
  7471. (let* ((nt (calendar-day-of-week
  7472. (calendar-gregorian-from-absolute sd)))
  7473. (d (if org-agenda-start-on-weekday
  7474. (- nt org-agenda-start-on-weekday)
  7475. 0))
  7476. y1)
  7477. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7478. (when n
  7479. (require 'cal-iso)
  7480. (when (> n 99)
  7481. (setq y1 (org-small-year-to-year (/ n 100))
  7482. n (mod n 100)))
  7483. (setq sd
  7484. (calendar-absolute-from-iso
  7485. (list n 1
  7486. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7487. ((eq span 'month)
  7488. (let (y1)
  7489. (when (and n (> n 99))
  7490. (setq y1 (org-small-year-to-year (/ n 100))
  7491. n (mod n 100)))
  7492. (setq sd (calendar-absolute-from-gregorian
  7493. (list (or n mg) 1 (or y1 yg))))))
  7494. ((eq span 'year)
  7495. (setq sd (calendar-absolute-from-gregorian
  7496. (list 1 1 (or n yg))))))
  7497. sd))
  7498. (defun org-agenda-next-date-line (&optional arg)
  7499. "Jump to the next line indicating a date in agenda buffer."
  7500. (interactive "p")
  7501. (org-agenda-check-type t 'agenda 'timeline)
  7502. (beginning-of-line 1)
  7503. ;; This does not work if user makes date format that starts with a blank
  7504. (if (looking-at "^\\S-") (forward-char 1))
  7505. (if (not (re-search-forward "^\\S-" nil t arg))
  7506. (progn
  7507. (backward-char 1)
  7508. (error "No next date after this line in this buffer")))
  7509. (goto-char (match-beginning 0)))
  7510. (defun org-agenda-previous-date-line (&optional arg)
  7511. "Jump to the previous line indicating a date in agenda buffer."
  7512. (interactive "p")
  7513. (org-agenda-check-type t 'agenda 'timeline)
  7514. (beginning-of-line 1)
  7515. (if (not (re-search-backward "^\\S-" nil t arg))
  7516. (error "No previous date before this line in this buffer")))
  7517. ;; Initialize the highlight
  7518. (defvar org-hl (make-overlay 1 1))
  7519. (overlay-put org-hl 'face 'highlight)
  7520. (defun org-highlight (begin end &optional buffer)
  7521. "Highlight a region with overlay."
  7522. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7523. (defun org-unhighlight ()
  7524. "Detach overlay INDEX."
  7525. (org-detach-overlay org-hl))
  7526. (defun org-unhighlight-once ()
  7527. "Remove the highlight from its position, and this function from the hook."
  7528. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7529. (org-unhighlight))
  7530. (defvar org-agenda-pre-follow-window-conf nil)
  7531. (defun org-agenda-follow-mode ()
  7532. "Toggle follow mode in an agenda buffer."
  7533. (interactive)
  7534. (unless org-agenda-follow-mode
  7535. (setq org-agenda-pre-follow-window-conf
  7536. (current-window-configuration)))
  7537. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7538. (unless org-agenda-follow-mode
  7539. (set-window-configuration org-agenda-pre-follow-window-conf))
  7540. (org-agenda-set-mode-name)
  7541. (org-agenda-do-context-action)
  7542. (message "Follow mode is %s"
  7543. (if org-agenda-follow-mode "on" "off")))
  7544. (defun org-agenda-entry-text-mode (&optional arg)
  7545. "Toggle entry text mode in an agenda buffer."
  7546. (interactive "P")
  7547. (if (or org-agenda-tag-filter
  7548. org-agenda-category-filter
  7549. org-agenda-regexp-filter
  7550. org-agenda-top-headline-filter)
  7551. (user-error "Can't show entry text in filtered views")
  7552. (setq org-agenda-entry-text-mode (or (integerp arg)
  7553. (not org-agenda-entry-text-mode)))
  7554. (org-agenda-entry-text-hide)
  7555. (and org-agenda-entry-text-mode
  7556. (let ((org-agenda-entry-text-maxlines
  7557. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7558. (org-agenda-entry-text-show)))
  7559. (org-agenda-set-mode-name)
  7560. (message "Entry text mode is %s%s"
  7561. (if org-agenda-entry-text-mode "on" "off")
  7562. (if (not org-agenda-entry-text-mode) ""
  7563. (format " (maximum number of lines is %d)"
  7564. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7565. (defun org-agenda-clockreport-mode (&optional with-filter)
  7566. "Toggle clocktable mode in an agenda buffer.
  7567. With prefix arg WITH-FILTER, make the clocktable respect the current
  7568. agenda filter."
  7569. (interactive "P")
  7570. (org-agenda-check-type t 'agenda)
  7571. (if with-filter
  7572. (setq org-agenda-clockreport-mode 'with-filter)
  7573. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7574. (org-agenda-set-mode-name)
  7575. (org-agenda-redo)
  7576. (message "Clocktable mode is %s"
  7577. (if org-agenda-clockreport-mode "on" "off")))
  7578. (defun org-agenda-log-mode (&optional special)
  7579. "Toggle log mode in an agenda buffer.
  7580. With argument SPECIAL, show all possible log items, not only the ones
  7581. configured in `org-agenda-log-mode-items'.
  7582. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7583. (interactive "P")
  7584. (org-agenda-check-type t 'agenda 'timeline)
  7585. (setq org-agenda-show-log
  7586. (cond
  7587. ((equal special '(16)) 'only)
  7588. ((eq special 'clockcheck)
  7589. (if (eq org-agenda-show-log 'clockcheck)
  7590. nil 'clockcheck))
  7591. (special '(closed clock state))
  7592. (t (not org-agenda-show-log))))
  7593. (org-agenda-set-mode-name)
  7594. (org-agenda-redo)
  7595. (message "Log mode is %s"
  7596. (if org-agenda-show-log "on" "off")))
  7597. (defun org-agenda-archives-mode (&optional with-files)
  7598. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7599. When called with a prefix argument, include all archive files as well."
  7600. (interactive "P")
  7601. (setq org-agenda-archives-mode
  7602. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7603. (org-agenda-set-mode-name)
  7604. (org-agenda-redo)
  7605. (message
  7606. "%s"
  7607. (cond
  7608. ((eq org-agenda-archives-mode nil)
  7609. "No archives are included")
  7610. ((eq org-agenda-archives-mode 'trees)
  7611. (format "Trees with :%s: tag are included" org-archive-tag))
  7612. ((eq org-agenda-archives-mode t)
  7613. (format "Trees with :%s: tag and all active archive files are included"
  7614. org-archive-tag)))))
  7615. (defun org-agenda-toggle-diary ()
  7616. "Toggle diary inclusion in an agenda buffer."
  7617. (interactive)
  7618. (org-agenda-check-type t 'agenda)
  7619. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7620. (org-agenda-redo)
  7621. (org-agenda-set-mode-name)
  7622. (message "Diary inclusion turned %s"
  7623. (if org-agenda-include-diary "on" "off")))
  7624. (defun org-agenda-toggle-deadlines ()
  7625. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7626. (interactive)
  7627. (org-agenda-check-type t 'agenda)
  7628. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7629. (org-agenda-redo)
  7630. (org-agenda-set-mode-name)
  7631. (message "Deadlines inclusion turned %s"
  7632. (if org-agenda-include-deadlines "on" "off")))
  7633. (defun org-agenda-toggle-time-grid ()
  7634. "Toggle time grid in an agenda buffer."
  7635. (interactive)
  7636. (org-agenda-check-type t 'agenda)
  7637. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7638. (org-agenda-redo)
  7639. (org-agenda-set-mode-name)
  7640. (message "Time-grid turned %s"
  7641. (if org-agenda-use-time-grid "on" "off")))
  7642. (defun org-agenda-set-mode-name ()
  7643. "Set the mode name to indicate all the small mode settings."
  7644. (setq mode-name
  7645. (list "Org-Agenda"
  7646. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7647. " "
  7648. '(:eval (org-agenda-span-name org-agenda-current-span))
  7649. (if org-agenda-follow-mode " Follow" "")
  7650. (if org-agenda-entry-text-mode " ETxt" "")
  7651. (if org-agenda-include-diary " Diary" "")
  7652. (if org-agenda-include-deadlines " Ddl" "")
  7653. (if org-agenda-use-time-grid " Grid" "")
  7654. (if (and (boundp 'org-habit-show-habits)
  7655. org-habit-show-habits) " Habit" "")
  7656. (cond
  7657. ((consp org-agenda-show-log) " LogAll")
  7658. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7659. (org-agenda-show-log " Log")
  7660. (t ""))
  7661. (if (or org-agenda-category-filter
  7662. (get 'org-agenda-category-filter :preset-filter))
  7663. '(:eval (org-propertize
  7664. (concat " <"
  7665. (mapconcat
  7666. 'identity
  7667. (append
  7668. (get 'org-agenda-category-filter :preset-filter)
  7669. org-agenda-category-filter)
  7670. "")
  7671. ">")
  7672. 'face 'org-agenda-filter-category
  7673. 'help-echo "Category used in filtering")) "")
  7674. (if (or org-agenda-tag-filter
  7675. (get 'org-agenda-tag-filter :preset-filter))
  7676. '(:eval (org-propertize
  7677. (concat " {"
  7678. (mapconcat
  7679. 'identity
  7680. (append
  7681. (get 'org-agenda-tag-filter :preset-filter)
  7682. org-agenda-tag-filter)
  7683. "")
  7684. "}")
  7685. 'face 'org-agenda-filter-tags
  7686. 'help-echo "Tags used in filtering")) "")
  7687. (if (or org-agenda-regexp-filter
  7688. (get 'org-agenda-regexp-filter :preset-filter))
  7689. '(:eval (org-propertize
  7690. (concat " ["
  7691. (mapconcat
  7692. 'identity
  7693. (append
  7694. (get 'org-agenda-regexp-filter :preset-filter)
  7695. org-agenda-regexp-filter)
  7696. "")
  7697. "]")
  7698. 'face 'org-agenda-filter-regexp
  7699. 'help-echo "Regexp used in filtering")) "")
  7700. (if org-agenda-archives-mode
  7701. (if (eq org-agenda-archives-mode t)
  7702. " Archives"
  7703. (format " :%s:" org-archive-tag))
  7704. "")
  7705. (if org-agenda-clockreport-mode
  7706. (if (eq org-agenda-clockreport-mode 'with-filter)
  7707. " Clock{}" " Clock")
  7708. "")))
  7709. (force-mode-line-update))
  7710. (define-obsolete-function-alias
  7711. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7712. (defun org-agenda-update-agenda-type ()
  7713. "Update the agenda type after each command."
  7714. (setq org-agenda-type
  7715. (or (get-text-property (point) 'org-agenda-type)
  7716. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7717. (defun org-agenda-next-line ()
  7718. "Move cursor to the next line, and show if follow mode is active."
  7719. (interactive)
  7720. (call-interactively 'next-line)
  7721. (org-agenda-do-context-action))
  7722. (defun org-agenda-previous-line ()
  7723. "Move cursor to the previous line, and show if follow-mode is active."
  7724. (interactive)
  7725. (call-interactively 'previous-line)
  7726. (org-agenda-do-context-action))
  7727. (defun org-agenda-next-item (n)
  7728. "Move cursor to next agenda item."
  7729. (interactive "p")
  7730. (let ((col (current-column)))
  7731. (dotimes (c n)
  7732. (when (next-single-property-change (point-at-eol) 'org-marker)
  7733. (move-end-of-line 1)
  7734. (goto-char (next-single-property-change (point) 'org-marker))))
  7735. (org-move-to-column col nil nil t))
  7736. (org-agenda-do-context-action))
  7737. (defun org-agenda-previous-item (n)
  7738. "Move cursor to next agenda item."
  7739. (interactive "p")
  7740. (dotimes (c n)
  7741. (let ((col (current-column))
  7742. (goto (save-excursion
  7743. (move-end-of-line 0)
  7744. (previous-single-property-change (point) 'org-marker))))
  7745. (if goto (goto-char goto))
  7746. (org-move-to-column col nil nil t)))
  7747. (org-agenda-do-context-action))
  7748. (defun org-agenda-do-context-action ()
  7749. "Show outline path and, maybe, follow mode window."
  7750. (let ((m (org-get-at-bol 'org-marker)))
  7751. (when (and (markerp m) (marker-buffer m))
  7752. (and org-agenda-follow-mode
  7753. (if org-agenda-follow-indirect
  7754. (org-agenda-tree-to-indirect-buffer nil)
  7755. (org-agenda-show)))
  7756. (and org-agenda-show-outline-path
  7757. (org-with-point-at m (org-display-outline-path t))))))
  7758. (defun org-agenda-show-tags ()
  7759. "Show the tags applicable to the current item."
  7760. (interactive)
  7761. (let* ((tags (org-get-at-bol 'tags)))
  7762. (if tags
  7763. (message "Tags are :%s:"
  7764. (org-no-properties (mapconcat 'identity tags ":")))
  7765. (message "No tags associated with this line"))))
  7766. (defun org-agenda-goto (&optional highlight)
  7767. "Go to the Org-mode file which contains the item at point."
  7768. (interactive)
  7769. (let* ((marker (or (org-get-at-bol 'org-marker)
  7770. (org-agenda-error)))
  7771. (buffer (marker-buffer marker))
  7772. (pos (marker-position marker)))
  7773. (switch-to-buffer-other-window buffer)
  7774. (widen)
  7775. (push-mark)
  7776. (goto-char pos)
  7777. (when (derived-mode-p 'org-mode)
  7778. (org-show-context 'agenda)
  7779. (save-excursion
  7780. (and (outline-next-heading)
  7781. (org-flag-heading nil)))) ; show the next heading
  7782. (when (outline-invisible-p)
  7783. (show-entry)) ; display invisible text
  7784. (recenter (/ (window-height) 2))
  7785. (run-hooks 'org-agenda-after-show-hook)
  7786. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7787. (defvar org-agenda-after-show-hook nil
  7788. "Normal hook run after an item has been shown from the agenda.
  7789. Point is in the buffer where the item originated.")
  7790. (defun org-agenda-kill ()
  7791. "Kill the entry or subtree belonging to the current agenda entry."
  7792. (interactive)
  7793. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7794. (let* ((bufname-orig (buffer-name))
  7795. (marker (or (org-get-at-bol 'org-marker)
  7796. (org-agenda-error)))
  7797. (buffer (marker-buffer marker))
  7798. (pos (marker-position marker))
  7799. (type (org-get-at-bol 'type))
  7800. dbeg dend (n 0) conf)
  7801. (org-with-remote-undo buffer
  7802. (with-current-buffer buffer
  7803. (save-excursion
  7804. (goto-char pos)
  7805. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7806. (setq dbeg (progn (org-back-to-heading t) (point))
  7807. dend (org-end-of-subtree t t))
  7808. (setq dbeg (point-at-bol)
  7809. dend (min (point-max) (1+ (point-at-eol)))))
  7810. (goto-char dbeg)
  7811. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7812. (setq conf (or (eq t org-agenda-confirm-kill)
  7813. (and (numberp org-agenda-confirm-kill)
  7814. (> n org-agenda-confirm-kill))))
  7815. (and conf
  7816. (not (y-or-n-p
  7817. (format "Delete entry with %d lines in buffer \"%s\"? "
  7818. n (buffer-name buffer))))
  7819. (error "Abort"))
  7820. (let ((org-agenda-buffer-name bufname-orig))
  7821. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7822. (with-current-buffer buffer (delete-region dbeg dend))
  7823. (message "Agenda item and source killed"))))
  7824. (defvar org-archive-default-command) ; defined in org-archive.el
  7825. (defun org-agenda-archive-default ()
  7826. "Archive the entry or subtree belonging to the current agenda entry."
  7827. (interactive)
  7828. (require 'org-archive)
  7829. (org-agenda-archive-with org-archive-default-command))
  7830. (defun org-agenda-archive-default-with-confirmation ()
  7831. "Archive the entry or subtree belonging to the current agenda entry."
  7832. (interactive)
  7833. (require 'org-archive)
  7834. (org-agenda-archive-with org-archive-default-command 'confirm))
  7835. (defun org-agenda-archive ()
  7836. "Archive the entry or subtree belonging to the current agenda entry."
  7837. (interactive)
  7838. (org-agenda-archive-with 'org-archive-subtree))
  7839. (defun org-agenda-archive-to-archive-sibling ()
  7840. "Move the entry to the archive sibling."
  7841. (interactive)
  7842. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7843. (defun org-agenda-archive-with (cmd &optional confirm)
  7844. "Move the entry to the archive sibling."
  7845. (interactive)
  7846. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7847. (let* ((bufname-orig (buffer-name))
  7848. (marker (or (org-get-at-bol 'org-marker)
  7849. (org-agenda-error)))
  7850. (buffer (marker-buffer marker))
  7851. (pos (marker-position marker)))
  7852. (org-with-remote-undo buffer
  7853. (with-current-buffer buffer
  7854. (if (derived-mode-p 'org-mode)
  7855. (if (and confirm
  7856. (not (y-or-n-p "Archive this subtree or entry? ")))
  7857. (error "Abort")
  7858. (save-window-excursion
  7859. (goto-char pos)
  7860. (let ((org-agenda-buffer-name bufname-orig))
  7861. (org-remove-subtree-entries-from-agenda))
  7862. (org-back-to-heading t)
  7863. (funcall cmd)))
  7864. (error "Archiving works only in Org-mode files"))))))
  7865. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7866. "Remove all lines in the agenda that correspond to a given subtree.
  7867. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7868. If this information is not given, the function uses the tree at point."
  7869. (let ((buf (or buf (current-buffer))) m p)
  7870. (save-excursion
  7871. (unless (and beg end)
  7872. (org-back-to-heading t)
  7873. (setq beg (point))
  7874. (org-end-of-subtree t)
  7875. (setq end (point)))
  7876. (set-buffer (get-buffer org-agenda-buffer-name))
  7877. (save-excursion
  7878. (goto-char (point-max))
  7879. (beginning-of-line 1)
  7880. (while (not (bobp))
  7881. (when (and (setq m (org-get-at-bol 'org-marker))
  7882. (equal buf (marker-buffer m))
  7883. (setq p (marker-position m))
  7884. (>= p beg)
  7885. (< p end))
  7886. (let ((inhibit-read-only t))
  7887. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7888. (beginning-of-line 0))))))
  7889. (defun org-agenda-refile (&optional goto rfloc no-update)
  7890. "Refile the item at point.
  7891. When GOTO is 0 or '(64), clear the refile cache.
  7892. When GOTO is '(16), go to the location of the last refiled item.
  7893. RFLOC can be a refile location obtained in a different way.
  7894. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7895. (interactive "P")
  7896. (cond
  7897. ((member goto '(0 (64)))
  7898. (org-refile-cache-clear))
  7899. ((equal goto '(16))
  7900. (org-refile-goto-last-stored))
  7901. (t
  7902. (let* ((buffer-orig (buffer-name))
  7903. (marker (or (org-get-at-bol 'org-hd-marker)
  7904. (org-agenda-error)))
  7905. (buffer (marker-buffer marker))
  7906. (pos (marker-position marker))
  7907. (rfloc (or rfloc
  7908. (org-refile-get-location
  7909. (if goto "Goto" "Refile to") buffer
  7910. org-refile-allow-creating-parent-nodes))))
  7911. (with-current-buffer buffer
  7912. (save-excursion
  7913. (save-restriction
  7914. (widen)
  7915. (goto-char marker)
  7916. (let ((org-agenda-buffer-name buffer-orig))
  7917. (org-remove-subtree-entries-from-agenda))
  7918. (org-refile goto buffer rfloc)))))
  7919. (unless no-update (org-agenda-redo)))))
  7920. (defun org-agenda-open-link (&optional arg)
  7921. "Open the link(s) in the current entry, if any.
  7922. This looks for a link in the displayed line in the agenda.
  7923. It also looks at the text of the entry itself."
  7924. (interactive "P")
  7925. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7926. (org-get-at-bol 'org-marker)))
  7927. (buffer (and marker (marker-buffer marker)))
  7928. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7929. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7930. (lk0 (car lkall))
  7931. (lk (if (stringp lk0) (list lk0) lk0))
  7932. (lkend (cdr lkall))
  7933. trg)
  7934. (cond
  7935. ((and buffer lk)
  7936. (mapcar (lambda(l)
  7937. (with-current-buffer buffer
  7938. (setq trg (and (string-match org-bracket-link-regexp l)
  7939. (match-string 1 l)))
  7940. (if (or (not trg) (string-match org-any-link-re trg))
  7941. (save-excursion
  7942. (save-restriction
  7943. (widen)
  7944. (goto-char marker)
  7945. (when (search-forward l nil lkend)
  7946. (goto-char (match-beginning 0))
  7947. (org-open-at-point))))
  7948. ;; This is an internal link, widen the buffer
  7949. (switch-to-buffer-other-window buffer)
  7950. (widen)
  7951. (goto-char marker)
  7952. (when (search-forward l nil lkend)
  7953. (goto-char (match-beginning 0))
  7954. (org-open-at-point)))))
  7955. lk))
  7956. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7957. (save-excursion
  7958. (beginning-of-line 1)
  7959. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7960. (org-open-link-from-string (match-string 1)))
  7961. (t (message "No link to open here")))))
  7962. (defun org-agenda-copy-local-variable (var)
  7963. "Get a variable from a referenced buffer and install it here."
  7964. (let ((m (org-get-at-bol 'org-marker)))
  7965. (when (and m (buffer-live-p (marker-buffer m)))
  7966. (org-set-local var (with-current-buffer (marker-buffer m)
  7967. (symbol-value var))))))
  7968. (defun org-agenda-switch-to (&optional delete-other-windows)
  7969. "Go to the Org-mode file which contains the item at point."
  7970. (interactive)
  7971. (if (and org-return-follows-link
  7972. (not (org-get-at-bol 'org-marker))
  7973. (org-in-regexp org-bracket-link-regexp))
  7974. (org-open-link-from-string (match-string 0))
  7975. (let* ((marker (or (org-get-at-bol 'org-marker)
  7976. (org-agenda-error)))
  7977. (buffer (marker-buffer marker))
  7978. (pos (marker-position marker)))
  7979. (org-pop-to-buffer-same-window buffer)
  7980. (and delete-other-windows (delete-other-windows))
  7981. (widen)
  7982. (goto-char pos)
  7983. (when (derived-mode-p 'org-mode)
  7984. (org-show-context 'agenda)
  7985. (save-excursion
  7986. (and (outline-next-heading)
  7987. (org-flag-heading nil))) ; show the next heading
  7988. (when (outline-invisible-p)
  7989. (show-entry)) ; display invisible text
  7990. (run-hooks 'org-agenda-after-show-hook)))))
  7991. (defun org-agenda-goto-mouse (ev)
  7992. "Go to the Org-mode file which contains the item at the mouse click."
  7993. (interactive "e")
  7994. (mouse-set-point ev)
  7995. (org-agenda-goto))
  7996. (defun org-agenda-show (&optional full-entry)
  7997. "Display the Org-mode file which contains the item at point.
  7998. With prefix argument FULL-ENTRY, make the entire entry visible
  7999. if it was hidden in the outline."
  8000. (interactive "P")
  8001. (let ((win (selected-window)))
  8002. (if full-entry
  8003. (let ((org-show-entry-below t))
  8004. (org-agenda-goto t))
  8005. (org-agenda-goto t))
  8006. (select-window win)))
  8007. (defvar org-agenda-show-window nil)
  8008. (defun org-agenda-show-and-scroll-up (&optional arg)
  8009. "Display the Org-mode file which contains the item at point.
  8010. When called repeatedly, scroll the window that is displaying the buffer.
  8011. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  8012. `show-subtree' to display the item, so that drawers and logbooks stay
  8013. folded."
  8014. (interactive "P")
  8015. (let ((win (selected-window)))
  8016. (if (and (window-live-p org-agenda-show-window)
  8017. (eq this-command last-command))
  8018. (progn
  8019. (select-window org-agenda-show-window)
  8020. (ignore-errors (scroll-up)))
  8021. (org-agenda-goto t)
  8022. (if arg (org-show-entry) (show-subtree))
  8023. (setq org-agenda-show-window (selected-window)))
  8024. (select-window win)))
  8025. (defun org-agenda-show-scroll-down ()
  8026. "Scroll down the window showing the agenda."
  8027. (interactive)
  8028. (let ((win (selected-window)))
  8029. (when (window-live-p org-agenda-show-window)
  8030. (select-window org-agenda-show-window)
  8031. (ignore-errors (scroll-down))
  8032. (select-window win))))
  8033. (defun org-agenda-show-1 (&optional more)
  8034. "Display the Org-mode file which contains the item at point.
  8035. The prefix arg selects the amount of information to display:
  8036. 0 hide the subtree
  8037. 1 just show the entry according to defaults.
  8038. 2 show the children view
  8039. 3 show the subtree view
  8040. 4 show the entire subtree and any LOGBOOK drawers
  8041. 5 show the entire subtree and any drawers
  8042. With prefix argument FULL-ENTRY, make the entire entry visible
  8043. if it was hidden in the outline."
  8044. (interactive "p")
  8045. (let ((win (selected-window)))
  8046. (org-agenda-goto t)
  8047. (org-recenter-heading 1)
  8048. (cond
  8049. ((= more 0)
  8050. (hide-subtree)
  8051. (save-excursion
  8052. (org-back-to-heading)
  8053. (run-hook-with-args 'org-cycle-hook 'folded))
  8054. (message "Remote: FOLDED"))
  8055. ((and (org-called-interactively-p 'any) (= more 1))
  8056. (message "Remote: show with default settings"))
  8057. ((= more 2)
  8058. (show-entry)
  8059. (show-children)
  8060. (save-excursion
  8061. (org-back-to-heading)
  8062. (run-hook-with-args 'org-cycle-hook 'children))
  8063. (message "Remote: CHILDREN"))
  8064. ((= more 3)
  8065. (show-subtree)
  8066. (save-excursion
  8067. (org-back-to-heading)
  8068. (run-hook-with-args 'org-cycle-hook 'subtree))
  8069. (message "Remote: SUBTREE"))
  8070. ((= more 4)
  8071. (show-subtree)
  8072. (save-excursion
  8073. (org-back-to-heading)
  8074. (org-cycle-hide-drawers 'subtree '("LOGBOOK")))
  8075. (message "Remote: SUBTREE AND LOGBOOK"))
  8076. ((> more 4)
  8077. (show-subtree)
  8078. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8079. (select-window win)))
  8080. (defun org-recenter-heading (n)
  8081. (save-excursion
  8082. (org-back-to-heading)
  8083. (recenter n)))
  8084. (defvar org-agenda-cycle-counter nil)
  8085. (defun org-agenda-cycle-show (&optional n)
  8086. "Show the current entry in another window, with default settings.
  8087. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8088. When use repeatedly in immediate succession, the remote entry will cycle
  8089. through visibility
  8090. children -> subtree -> folded
  8091. When called with a numeric prefix arg, that arg will be passed through to
  8092. `org-agenda-show-1'. For the interpretation of that argument, see the
  8093. docstring of `org-agenda-show-1'."
  8094. (interactive "P")
  8095. (if (integerp n)
  8096. (setq org-agenda-cycle-counter n)
  8097. (if (not (eq last-command this-command))
  8098. (setq org-agenda-cycle-counter 1)
  8099. (if (equal org-agenda-cycle-counter 0)
  8100. (setq org-agenda-cycle-counter 2)
  8101. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8102. (if (> org-agenda-cycle-counter 3)
  8103. (setq org-agenda-cycle-counter 0)))))
  8104. (org-agenda-show-1 org-agenda-cycle-counter))
  8105. (defun org-agenda-recenter (arg)
  8106. "Display the Org-mode file which contains the item at point and recenter."
  8107. (interactive "P")
  8108. (let ((win (selected-window)))
  8109. (org-agenda-goto t)
  8110. (recenter arg)
  8111. (select-window win)))
  8112. (defun org-agenda-show-mouse (ev)
  8113. "Display the Org-mode file which contains the item at the mouse click."
  8114. (interactive "e")
  8115. (mouse-set-point ev)
  8116. (org-agenda-show))
  8117. (defun org-agenda-check-no-diary ()
  8118. "Check if the entry is a diary link and abort if yes."
  8119. (if (org-get-at-bol 'org-agenda-diary-link)
  8120. (org-agenda-error)))
  8121. (defun org-agenda-error ()
  8122. (error "Command not allowed in this line"))
  8123. (defun org-agenda-tree-to-indirect-buffer (arg)
  8124. "Show the subtree corresponding to the current entry in an indirect buffer.
  8125. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8126. With a numerical prefix ARG, go up to this level and then take that tree.
  8127. With a negative numeric ARG, go up by this number of levels.
  8128. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8129. use the dedicated frame)."
  8130. (interactive "P")
  8131. (if current-prefix-arg
  8132. (org-agenda-do-tree-to-indirect-buffer arg)
  8133. (let ((agenda-buffer (buffer-name))
  8134. (agenda-window (selected-window))
  8135. (indirect-window
  8136. (and org-last-indirect-buffer
  8137. (get-buffer-window org-last-indirect-buffer))))
  8138. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8139. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8140. (eq org-indirect-buffer-display 'dedicated-frame))
  8141. (unwind-protect
  8142. (unless (and indirect-window (window-live-p indirect-window))
  8143. (setq indirect-window (split-window agenda-window)))
  8144. (and indirect-window (select-window indirect-window))
  8145. (switch-to-buffer org-last-indirect-buffer :norecord)
  8146. (fit-window-to-buffer indirect-window)))
  8147. (select-window (get-buffer-window agenda-buffer)))))
  8148. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8149. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8150. (org-agenda-check-no-diary)
  8151. (let* ((marker (or (org-get-at-bol 'org-marker)
  8152. (org-agenda-error)))
  8153. (buffer (marker-buffer marker))
  8154. (pos (marker-position marker)))
  8155. (with-current-buffer buffer
  8156. (save-excursion
  8157. (goto-char pos)
  8158. (funcall 'org-tree-to-indirect-buffer arg)))))
  8159. (defvar org-last-heading-marker (make-marker)
  8160. "Marker pointing to the headline that last changed its TODO state
  8161. by a remote command from the agenda.")
  8162. (defun org-agenda-todo-nextset ()
  8163. "Switch TODO entry to next sequence."
  8164. (interactive)
  8165. (org-agenda-todo 'nextset))
  8166. (defun org-agenda-todo-previousset ()
  8167. "Switch TODO entry to previous sequence."
  8168. (interactive)
  8169. (org-agenda-todo 'previousset))
  8170. (defun org-agenda-todo (&optional arg)
  8171. "Cycle TODO state of line at point, also in Org-mode file.
  8172. This changes the line at point, all other lines in the agenda referring to
  8173. the same tree node, and the headline of the tree node in the Org-mode file."
  8174. (interactive "P")
  8175. (org-agenda-check-no-diary)
  8176. (let* ((col (current-column))
  8177. (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. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8183. (inhibit-read-only t)
  8184. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8185. (org-with-remote-undo buffer
  8186. (with-current-buffer buffer
  8187. (widen)
  8188. (goto-char pos)
  8189. (org-show-context 'agenda)
  8190. (save-excursion
  8191. (and (outline-next-heading)
  8192. (org-flag-heading nil))) ; show the next heading
  8193. (let ((current-prefix-arg arg))
  8194. (call-interactively 'org-todo))
  8195. (and (bolp) (forward-char 1))
  8196. (setq newhead (org-get-heading))
  8197. (when (and (org-bound-and-true-p
  8198. org-agenda-headline-snapshot-before-repeat)
  8199. (not (equal org-agenda-headline-snapshot-before-repeat
  8200. newhead))
  8201. todayp)
  8202. (setq newhead org-agenda-headline-snapshot-before-repeat
  8203. just-one t))
  8204. (save-excursion
  8205. (org-back-to-heading)
  8206. (move-marker org-last-heading-marker (point))))
  8207. (beginning-of-line 1)
  8208. (save-excursion
  8209. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8210. (when (org-bound-and-true-p org-clock-out-when-done)
  8211. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8212. newhead)
  8213. (org-agenda-unmark-clocking-task))
  8214. (org-move-to-column col nil nil t))))
  8215. (defun org-agenda-add-note (&optional arg)
  8216. "Add a time-stamped note to the entry at point."
  8217. (interactive "P")
  8218. (org-agenda-check-no-diary)
  8219. (let* ((marker (or (org-get-at-bol 'org-marker)
  8220. (org-agenda-error)))
  8221. (buffer (marker-buffer marker))
  8222. (pos (marker-position marker))
  8223. (hdmarker (org-get-at-bol 'org-hd-marker))
  8224. (inhibit-read-only t))
  8225. (with-current-buffer buffer
  8226. (widen)
  8227. (goto-char pos)
  8228. (org-show-context 'agenda)
  8229. (save-excursion
  8230. (and (outline-next-heading)
  8231. (org-flag-heading nil))) ; show the next heading
  8232. (org-add-note))))
  8233. (defun org-agenda-change-all-lines (newhead hdmarker
  8234. &optional fixface just-this)
  8235. "Change all lines in the agenda buffer which match HDMARKER.
  8236. The new content of the line will be NEWHEAD (as modified by
  8237. `org-agenda-format-item'). HDMARKER is checked with
  8238. `equal' against all `org-hd-marker' text properties in the file.
  8239. If FIXFACE is non-nil, the face of each item is modified according to
  8240. the new TODO state.
  8241. If JUST-THIS is non-nil, change just the current line, not all.
  8242. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8243. (let* ((inhibit-read-only t)
  8244. (line (org-current-line))
  8245. (org-agenda-buffer (current-buffer))
  8246. (thetags (with-current-buffer (marker-buffer hdmarker)
  8247. (save-excursion (save-restriction (widen)
  8248. (goto-char hdmarker)
  8249. (org-get-tags-at)))))
  8250. props m pl undone-face done-face finish new dotime level cat tags)
  8251. (save-excursion
  8252. (goto-char (point-max))
  8253. (beginning-of-line 1)
  8254. (while (not finish)
  8255. (setq finish (bobp))
  8256. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8257. (or (not just-this) (= (org-current-line) line))
  8258. (equal m hdmarker))
  8259. (setq props (text-properties-at (point))
  8260. dotime (org-get-at-bol 'dotime)
  8261. cat (org-get-at-bol 'org-category)
  8262. level (org-get-at-bol 'level)
  8263. tags thetags
  8264. new
  8265. (let ((org-prefix-format-compiled
  8266. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8267. org-prefix-format-compiled))
  8268. (extra (org-get-at-bol 'extra)))
  8269. (with-current-buffer (marker-buffer hdmarker)
  8270. (save-excursion
  8271. (save-restriction
  8272. (widen)
  8273. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8274. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8275. undone-face (org-get-at-bol 'undone-face)
  8276. done-face (org-get-at-bol 'done-face))
  8277. (beginning-of-line 1)
  8278. (cond
  8279. ((equal new "")
  8280. (and (looking-at ".*\n?") (replace-match "")))
  8281. ((looking-at ".*")
  8282. (replace-match new t t)
  8283. (beginning-of-line 1)
  8284. (add-text-properties (point-at-bol) (point-at-eol) props)
  8285. (when fixface
  8286. (add-text-properties
  8287. (point-at-bol) (point-at-eol)
  8288. (list 'face
  8289. (if org-last-todo-state-is-todo
  8290. undone-face done-face))))
  8291. (org-agenda-highlight-todo 'line)
  8292. (beginning-of-line 1))
  8293. (t (error "Line update did not work")))
  8294. (save-restriction
  8295. (narrow-to-region (point-at-bol) (point-at-eol))
  8296. (org-agenda-finalize)))
  8297. (beginning-of-line 0)))))
  8298. (defun org-agenda-align-tags (&optional line)
  8299. "Align all tags in agenda items to `org-agenda-tags-column'."
  8300. (let ((inhibit-read-only t) l c)
  8301. (save-excursion
  8302. (goto-char (if line (point-at-bol) (point-min)))
  8303. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8304. (if line (point-at-eol) nil) t)
  8305. (add-text-properties
  8306. (match-beginning 2) (match-end 2)
  8307. (list 'face (delq nil (let ((prop (get-text-property
  8308. (match-beginning 2) 'face)))
  8309. (or (listp prop) (setq prop (list prop)))
  8310. (if (memq 'org-tag prop)
  8311. prop
  8312. (cons 'org-tag prop))))))
  8313. (setq l (- (match-end 2) (match-beginning 2))
  8314. c (if (< org-agenda-tags-column 0)
  8315. (- (abs org-agenda-tags-column) l)
  8316. org-agenda-tags-column))
  8317. (delete-region (match-beginning 1) (match-end 1))
  8318. (goto-char (match-beginning 1))
  8319. (insert (org-add-props
  8320. (make-string (max 1 (- c (current-column))) ?\ )
  8321. (plist-put (copy-sequence (text-properties-at (point)))
  8322. 'face nil))))
  8323. (goto-char (point-min))
  8324. (org-font-lock-add-tag-faces (point-max)))))
  8325. (defun org-agenda-priority-up ()
  8326. "Increase the priority of line at point, also in Org-mode file."
  8327. (interactive)
  8328. (org-agenda-priority 'up))
  8329. (defun org-agenda-priority-down ()
  8330. "Decrease the priority of line at point, also in Org-mode file."
  8331. (interactive)
  8332. (org-agenda-priority 'down))
  8333. (defun org-agenda-priority (&optional force-direction)
  8334. "Set the priority of line at point, also in Org-mode file.
  8335. This changes the line at point, all other lines in the agenda referring to
  8336. the same tree node, and the headline of the tree node in the Org-mode file.
  8337. Called with a universal prefix arg, show the priority instead of setting it."
  8338. (interactive "P")
  8339. (if (equal force-direction '(4))
  8340. (org-show-priority)
  8341. (unless org-enable-priority-commands
  8342. (error "Priority commands are disabled"))
  8343. (org-agenda-check-no-diary)
  8344. (let* ((col (current-column))
  8345. (marker (or (org-get-at-bol 'org-marker)
  8346. (org-agenda-error)))
  8347. (hdmarker (org-get-at-bol 'org-hd-marker))
  8348. (buffer (marker-buffer hdmarker))
  8349. (pos (marker-position hdmarker))
  8350. (inhibit-read-only t)
  8351. newhead)
  8352. (org-with-remote-undo buffer
  8353. (with-current-buffer buffer
  8354. (widen)
  8355. (goto-char pos)
  8356. (org-show-context 'agenda)
  8357. (save-excursion
  8358. (and (outline-next-heading)
  8359. (org-flag-heading nil))) ; show the next heading
  8360. (funcall 'org-priority force-direction)
  8361. (end-of-line 1)
  8362. (setq newhead (org-get-heading)))
  8363. (org-agenda-change-all-lines newhead hdmarker)
  8364. (org-move-to-column col nil nil t)))))
  8365. ;; FIXME: should fix the tags property of the agenda line.
  8366. (defun org-agenda-set-tags (&optional tag onoff)
  8367. "Set tags for the current headline."
  8368. (interactive)
  8369. (org-agenda-check-no-diary)
  8370. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8371. (call-interactively 'org-change-tag-in-region)
  8372. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8373. (org-agenda-error)))
  8374. (buffer (marker-buffer hdmarker))
  8375. (pos (marker-position hdmarker))
  8376. (inhibit-read-only t)
  8377. newhead)
  8378. (org-with-remote-undo buffer
  8379. (with-current-buffer buffer
  8380. (widen)
  8381. (goto-char pos)
  8382. (save-excursion
  8383. (org-show-context 'agenda))
  8384. (save-excursion
  8385. (and (outline-next-heading)
  8386. (org-flag-heading nil))) ; show the next heading
  8387. (goto-char pos)
  8388. (if tag
  8389. (org-toggle-tag tag onoff)
  8390. (call-interactively 'org-set-tags))
  8391. (end-of-line 1)
  8392. (setq newhead (org-get-heading)))
  8393. (org-agenda-change-all-lines newhead hdmarker)
  8394. (beginning-of-line 1)))))
  8395. (defun org-agenda-set-property ()
  8396. "Set a property for the current headline."
  8397. (interactive)
  8398. (org-agenda-check-no-diary)
  8399. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8400. (org-agenda-error)))
  8401. (buffer (marker-buffer hdmarker))
  8402. (pos (marker-position hdmarker))
  8403. (inhibit-read-only t)
  8404. newhead)
  8405. (org-with-remote-undo buffer
  8406. (with-current-buffer buffer
  8407. (widen)
  8408. (goto-char pos)
  8409. (save-excursion
  8410. (org-show-context 'agenda))
  8411. (save-excursion
  8412. (and (outline-next-heading)
  8413. (org-flag-heading nil))) ; show the next heading
  8414. (goto-char pos)
  8415. (call-interactively 'org-set-property)))))
  8416. (defun org-agenda-set-effort ()
  8417. "Set the effort property for the current headline."
  8418. (interactive)
  8419. (org-agenda-check-no-diary)
  8420. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8421. (org-agenda-error)))
  8422. (buffer (marker-buffer hdmarker))
  8423. (pos (marker-position hdmarker))
  8424. (inhibit-read-only t)
  8425. newhead)
  8426. (org-with-remote-undo buffer
  8427. (with-current-buffer buffer
  8428. (widen)
  8429. (goto-char pos)
  8430. (save-excursion
  8431. (org-show-context 'agenda))
  8432. (save-excursion
  8433. (and (outline-next-heading)
  8434. (org-flag-heading nil))) ; show the next heading
  8435. (goto-char pos)
  8436. (call-interactively 'org-set-effort)
  8437. (end-of-line 1)
  8438. (setq newhead (org-get-heading)))
  8439. (org-agenda-change-all-lines newhead hdmarker))))
  8440. (defun org-agenda-toggle-archive-tag ()
  8441. "Toggle the archive tag for the current entry."
  8442. (interactive)
  8443. (org-agenda-check-no-diary)
  8444. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8445. (org-agenda-error)))
  8446. (buffer (marker-buffer hdmarker))
  8447. (pos (marker-position hdmarker))
  8448. (inhibit-read-only t)
  8449. newhead)
  8450. (org-with-remote-undo buffer
  8451. (with-current-buffer buffer
  8452. (widen)
  8453. (goto-char pos)
  8454. (org-show-context 'agenda)
  8455. (save-excursion
  8456. (and (outline-next-heading)
  8457. (org-flag-heading nil))) ; show the next heading
  8458. (call-interactively 'org-toggle-archive-tag)
  8459. (end-of-line 1)
  8460. (setq newhead (org-get-heading)))
  8461. (org-agenda-change-all-lines newhead hdmarker)
  8462. (beginning-of-line 1))))
  8463. (defun org-agenda-do-date-later (arg)
  8464. (interactive "P")
  8465. (cond
  8466. ((or (equal arg '(16))
  8467. (memq last-command
  8468. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8469. (setq this-command 'org-agenda-date-later-minutes)
  8470. (org-agenda-date-later-minutes 1))
  8471. ((or (equal arg '(4))
  8472. (memq last-command
  8473. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8474. (setq this-command 'org-agenda-date-later-hours)
  8475. (org-agenda-date-later-hours 1))
  8476. (t
  8477. (org-agenda-date-later (prefix-numeric-value arg)))))
  8478. (defun org-agenda-do-date-earlier (arg)
  8479. (interactive "P")
  8480. (cond
  8481. ((or (equal arg '(16))
  8482. (memq last-command
  8483. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8484. (setq this-command 'org-agenda-date-earlier-minutes)
  8485. (org-agenda-date-earlier-minutes 1))
  8486. ((or (equal arg '(4))
  8487. (memq last-command
  8488. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8489. (setq this-command 'org-agenda-date-earlier-hours)
  8490. (org-agenda-date-earlier-hours 1))
  8491. (t
  8492. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8493. (defun org-agenda-date-later (arg &optional what)
  8494. "Change the date of this item to ARG day(s) later."
  8495. (interactive "p")
  8496. (org-agenda-check-type t 'agenda 'timeline)
  8497. (org-agenda-check-no-diary)
  8498. (let* ((marker (or (org-get-at-bol 'org-marker)
  8499. (org-agenda-error)))
  8500. (buffer (marker-buffer marker))
  8501. (pos (marker-position marker))
  8502. cdate today)
  8503. (org-with-remote-undo buffer
  8504. (with-current-buffer buffer
  8505. (widen)
  8506. (goto-char pos)
  8507. (if (not (org-at-timestamp-p))
  8508. (error "Cannot find time stamp"))
  8509. (when (and org-agenda-move-date-from-past-immediately-to-today
  8510. (equal arg 1)
  8511. (or (not what) (eq what 'day))
  8512. (not (save-match-data (org-at-date-range-p))))
  8513. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8514. cdate (calendar-absolute-from-gregorian
  8515. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8516. today (org-today))
  8517. (if (> today cdate)
  8518. ;; immediately shift to today
  8519. (setq arg (- today cdate))))
  8520. (org-timestamp-change arg (or what 'day))
  8521. (when (and (org-at-date-range-p)
  8522. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8523. (let ((end org-last-changed-timestamp))
  8524. (org-timestamp-change arg (or what 'day))
  8525. (setq org-last-changed-timestamp
  8526. (concat org-last-changed-timestamp "--" end)))))
  8527. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8528. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8529. (defun org-agenda-date-earlier (arg &optional what)
  8530. "Change the date of this item to ARG day(s) earlier."
  8531. (interactive "p")
  8532. (org-agenda-date-later (- arg) what))
  8533. (defun org-agenda-date-later-minutes (arg)
  8534. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8535. (interactive "p")
  8536. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8537. (org-agenda-date-later arg 'minute))
  8538. (defun org-agenda-date-earlier-minutes (arg)
  8539. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8540. (interactive "p")
  8541. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8542. (org-agenda-date-earlier arg 'minute))
  8543. (defun org-agenda-date-later-hours (arg)
  8544. "Change the time of this item, in hour steps."
  8545. (interactive "p")
  8546. (org-agenda-date-later arg 'hour))
  8547. (defun org-agenda-date-earlier-hours (arg)
  8548. "Change the time of this item, in hour steps."
  8549. (interactive "p")
  8550. (org-agenda-date-earlier arg 'hour))
  8551. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8552. "Show new date stamp via text properties."
  8553. ;; We use text properties to make this undoable
  8554. (let ((inhibit-read-only t))
  8555. (setq stamp (concat prefix " => " stamp " "))
  8556. (save-excursion
  8557. (goto-char (point-max))
  8558. (while (not (bobp))
  8559. (when (equal marker (org-get-at-bol 'org-marker))
  8560. (org-move-to-column (- (window-width) (length stamp)) t nil t)
  8561. (org-agenda-fix-tags-filter-overlays-at (point))
  8562. (if (featurep 'xemacs)
  8563. ;; Use `duplicable' property to trigger undo recording
  8564. (let ((ex (make-extent nil nil))
  8565. (gl (make-glyph stamp)))
  8566. (set-glyph-face gl 'secondary-selection)
  8567. (set-extent-properties
  8568. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8569. (insert-extent ex (1- (point)) (point-at-eol)))
  8570. (add-text-properties
  8571. (1- (point)) (point-at-eol)
  8572. (list 'display (org-add-props stamp nil
  8573. 'face 'secondary-selection))))
  8574. (beginning-of-line 1))
  8575. (beginning-of-line 0)))))
  8576. (defun org-agenda-date-prompt (arg)
  8577. "Change the date of this item. Date is prompted for, with default today.
  8578. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8579. be used to request time specification in the time stamp."
  8580. (interactive "P")
  8581. (org-agenda-check-type t 'agenda 'timeline)
  8582. (org-agenda-check-no-diary)
  8583. (let* ((marker (or (org-get-at-bol 'org-marker)
  8584. (org-agenda-error)))
  8585. (buffer (marker-buffer marker))
  8586. (pos (marker-position marker)))
  8587. (org-with-remote-undo buffer
  8588. (with-current-buffer buffer
  8589. (widen)
  8590. (goto-char pos)
  8591. (if (not (org-at-timestamp-p t))
  8592. (error "Cannot find time stamp"))
  8593. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8594. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8595. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8596. (defun org-agenda-schedule (arg &optional time)
  8597. "Schedule the item at point.
  8598. ARG is passed through to `org-schedule'."
  8599. (interactive "P")
  8600. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8601. (org-agenda-check-no-diary)
  8602. (let* ((marker (or (org-get-at-bol 'org-marker)
  8603. (org-agenda-error)))
  8604. (type (marker-insertion-type marker))
  8605. (buffer (marker-buffer marker))
  8606. (pos (marker-position marker))
  8607. (org-insert-labeled-timestamps-at-point nil)
  8608. ts)
  8609. (set-marker-insertion-type marker t)
  8610. (org-with-remote-undo buffer
  8611. (with-current-buffer buffer
  8612. (widen)
  8613. (goto-char pos)
  8614. (setq ts (org-schedule arg time)))
  8615. (org-agenda-show-new-time marker ts " S"))
  8616. (message "%s" ts)))
  8617. (defun org-agenda-deadline (arg &optional time)
  8618. "Schedule the item at point.
  8619. ARG is passed through to `org-deadline'."
  8620. (interactive "P")
  8621. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8622. (org-agenda-check-no-diary)
  8623. (let* ((marker (or (org-get-at-bol 'org-marker)
  8624. (org-agenda-error)))
  8625. (buffer (marker-buffer marker))
  8626. (pos (marker-position marker))
  8627. (org-insert-labeled-timestamps-at-point nil)
  8628. ts)
  8629. (org-with-remote-undo buffer
  8630. (with-current-buffer buffer
  8631. (widen)
  8632. (goto-char pos)
  8633. (setq ts (org-deadline arg time)))
  8634. (org-agenda-show-new-time marker ts " D"))
  8635. (message "%s" ts)))
  8636. (defun org-agenda-clock-in (&optional arg)
  8637. "Start the clock on the currently selected item."
  8638. (interactive "P")
  8639. (org-agenda-check-no-diary)
  8640. (if (equal arg '(4))
  8641. (org-clock-in arg)
  8642. (let* ((marker (or (org-get-at-bol 'org-marker)
  8643. (org-agenda-error)))
  8644. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8645. (pos (marker-position marker))
  8646. (col (current-column))
  8647. newhead)
  8648. (org-with-remote-undo (marker-buffer marker)
  8649. (with-current-buffer (marker-buffer marker)
  8650. (widen)
  8651. (goto-char pos)
  8652. (org-show-context 'agenda)
  8653. (org-show-entry)
  8654. (org-cycle-hide-drawers 'children)
  8655. (org-clock-in arg)
  8656. (setq newhead (org-get-heading)))
  8657. (org-agenda-change-all-lines newhead hdmarker))
  8658. (org-move-to-column col nil nil t))))
  8659. (defun org-agenda-clock-out ()
  8660. "Stop the currently running clock."
  8661. (interactive)
  8662. (unless (marker-buffer org-clock-marker)
  8663. (error "No running clock"))
  8664. (let ((marker (make-marker)) (col (current-column)) newhead)
  8665. (org-with-remote-undo (marker-buffer org-clock-marker)
  8666. (with-current-buffer (marker-buffer org-clock-marker)
  8667. (save-excursion
  8668. (save-restriction
  8669. (widen)
  8670. (goto-char org-clock-marker)
  8671. (org-back-to-heading t)
  8672. (move-marker marker (point))
  8673. (org-clock-out)
  8674. (setq newhead (org-get-heading))))))
  8675. (org-agenda-change-all-lines newhead marker)
  8676. (move-marker marker nil)
  8677. (org-move-to-column col nil nil t)
  8678. (org-agenda-unmark-clocking-task)))
  8679. (defun org-agenda-clock-cancel (&optional arg)
  8680. "Cancel the currently running clock."
  8681. (interactive "P")
  8682. (unless (marker-buffer org-clock-marker)
  8683. (user-error "No running clock"))
  8684. (org-with-remote-undo (marker-buffer org-clock-marker)
  8685. (org-clock-cancel)))
  8686. (defun org-agenda-clock-goto ()
  8687. "Jump to the currently clocked in task within the agenda.
  8688. If the currently clocked in task is not listed in the agenda
  8689. buffer, display it in another window."
  8690. (interactive)
  8691. (let (pos)
  8692. (mapc (lambda (o)
  8693. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8694. (setq pos (overlay-start o))))
  8695. (overlays-in (point-min) (point-max)))
  8696. (cond (pos (goto-char pos))
  8697. ;; If the currently clocked entry is not in the agenda
  8698. ;; buffer, we visit it in another window:
  8699. (org-clock-current-task
  8700. (org-switch-to-buffer-other-window (org-clock-goto)))
  8701. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8702. (defun org-agenda-diary-entry-in-org-file ()
  8703. "Make a diary entry in the file `org-agenda-diary-file'."
  8704. (let (d1 d2 char (text "") dp1 dp2)
  8705. (if (equal (buffer-name) "*Calendar*")
  8706. (setq d1 (calendar-cursor-to-date t)
  8707. d2 (car calendar-mark-ring))
  8708. (setq dp1 (get-text-property (point-at-bol) 'day))
  8709. (unless dp1 (user-error "No date defined in current line"))
  8710. (setq d1 (calendar-gregorian-from-absolute dp1)
  8711. d2 (and (ignore-errors (mark))
  8712. (save-excursion
  8713. (goto-char (mark))
  8714. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8715. (calendar-gregorian-from-absolute dp2))))
  8716. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8717. (setq char (read-char-exclusive))
  8718. (cond
  8719. ((equal char ?d)
  8720. (setq text (read-string "Day entry: "))
  8721. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8722. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8723. ((equal char ?a)
  8724. (setq d1 (list (car d1) (nth 1 d1)
  8725. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8726. (nth 2 d1))))
  8727. (setq text (read-string "Anniversary (use %d to show years): "))
  8728. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8729. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8730. ((equal char ?b)
  8731. (setq text (read-string "Block entry: "))
  8732. (unless (and d1 d2 (not (equal d1 d2)))
  8733. (user-error "No block of days selected"))
  8734. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8735. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8736. ((equal char ?j)
  8737. (org-switch-to-buffer-other-window
  8738. (find-file-noselect org-agenda-diary-file))
  8739. (require 'org-datetree)
  8740. (org-datetree-find-date-create d1)
  8741. (org-reveal t))
  8742. (t (user-error "Invalid selection character `%c'" char)))))
  8743. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8744. "Where in `org-agenda-diary-file' should new entries be added?
  8745. Valid values:
  8746. date-tree in the date tree, as child of the date
  8747. top-level as top-level entries at the end of the file."
  8748. :group 'org-agenda
  8749. :type '(choice
  8750. (const :tag "in a date tree" date-tree)
  8751. (const :tag "as top level at end of file" top-level)))
  8752. (defcustom org-agenda-insert-diary-extract-time nil
  8753. "Non-nil means extract any time specification from the diary entry."
  8754. :group 'org-agenda
  8755. :version "24.1"
  8756. :type 'boolean)
  8757. (defcustom org-agenda-bulk-mark-char ">"
  8758. "A single-character string to be used as the bulk mark."
  8759. :group 'org-agenda
  8760. :version "24.1"
  8761. :type 'string)
  8762. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8763. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8764. If TEXT is not empty, it will become the headline of the new entry, and
  8765. the resulting entry will not be shown. When TEXT is empty, switch to
  8766. `org-agenda-diary-file' and let the user finish the entry there."
  8767. (let ((cw (current-window-configuration)))
  8768. (org-switch-to-buffer-other-window
  8769. (find-file-noselect org-agenda-diary-file))
  8770. (widen)
  8771. (goto-char (point-min))
  8772. (cond
  8773. ((eq type 'anniversary)
  8774. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8775. (progn
  8776. (or (org-at-heading-p t)
  8777. (progn
  8778. (outline-next-heading)
  8779. (insert "* Anniversaries\n\n")
  8780. (beginning-of-line -1)))))
  8781. (outline-next-heading)
  8782. (org-back-over-empty-lines)
  8783. (backward-char 1)
  8784. (insert "\n")
  8785. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8786. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8787. ((eq type 'day)
  8788. (let ((org-prefix-has-time t)
  8789. (org-agenda-time-leading-zero t)
  8790. fmt time time2)
  8791. (if org-agenda-insert-diary-extract-time
  8792. ;; Use org-agenda-format-item to parse text for a time-range and
  8793. ;; remove it. FIXME: This is a hack, we should refactor
  8794. ;; that function to make time extraction available separately
  8795. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8796. time (get-text-property 0 'time fmt)
  8797. time2 (if (> (length time) 0)
  8798. ;; split-string removes trailing ...... if
  8799. ;; no end time given. First space
  8800. ;; separates time from date.
  8801. (concat " " (car (split-string time "\\.")))
  8802. nil)
  8803. text (get-text-property 0 'txt fmt)))
  8804. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8805. (org-agenda-insert-diary-as-top-level text)
  8806. (require 'org-datetree)
  8807. (org-datetree-find-date-create d1)
  8808. (org-agenda-insert-diary-make-new-entry text))
  8809. (org-insert-time-stamp (org-time-from-absolute
  8810. (calendar-absolute-from-gregorian d1))
  8811. nil nil nil nil time2))
  8812. (end-of-line 0))
  8813. ((eq type 'block)
  8814. (if (> (calendar-absolute-from-gregorian d1)
  8815. (calendar-absolute-from-gregorian d2))
  8816. (setq d1 (prog1 d2 (setq d2 d1))))
  8817. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8818. (org-agenda-insert-diary-as-top-level text)
  8819. (require 'org-datetree)
  8820. (org-datetree-find-date-create d1)
  8821. (org-agenda-insert-diary-make-new-entry text))
  8822. (org-insert-time-stamp (org-time-from-absolute
  8823. (calendar-absolute-from-gregorian d1)))
  8824. (insert "--")
  8825. (org-insert-time-stamp (org-time-from-absolute
  8826. (calendar-absolute-from-gregorian d2)))
  8827. (end-of-line 0)))
  8828. (if (string-match "\\S-" text)
  8829. (progn
  8830. (set-window-configuration cw)
  8831. (message "%s entry added to %s"
  8832. (capitalize (symbol-name type))
  8833. (abbreviate-file-name org-agenda-diary-file)))
  8834. (org-reveal t)
  8835. (message "Please finish entry here"))))
  8836. (defun org-agenda-insert-diary-as-top-level (text)
  8837. "Make new entry as a top-level entry at the end of the file.
  8838. Add TEXT as headline, and position the cursor in the second line so that
  8839. a timestamp can be added there."
  8840. (widen)
  8841. (goto-char (point-max))
  8842. (or (bolp) (insert "\n"))
  8843. (insert "* " text "\n")
  8844. (if org-adapt-indentation (org-indent-to-column 2)))
  8845. (defun org-agenda-insert-diary-make-new-entry (text)
  8846. "Make new entry as last child of current entry.
  8847. Add TEXT as headline, and position the cursor in the second line so that
  8848. a timestamp can be added there."
  8849. (let ((org-show-following-heading t)
  8850. (org-show-siblings t)
  8851. (org-show-hierarchy-above t)
  8852. (org-show-entry-below t)
  8853. col)
  8854. (outline-next-heading)
  8855. (org-back-over-empty-lines)
  8856. (or (looking-at "[ \t]*$")
  8857. (progn (insert "\n") (backward-char 1)))
  8858. (org-insert-heading nil t)
  8859. (org-do-demote)
  8860. (setq col (current-column))
  8861. (insert text "\n")
  8862. (if org-adapt-indentation (org-indent-to-column col))
  8863. (let ((org-show-following-heading t)
  8864. (org-show-siblings t)
  8865. (org-show-hierarchy-above t)
  8866. (org-show-entry-below t))
  8867. (org-show-context))))
  8868. (defun org-agenda-diary-entry ()
  8869. "Make a diary entry, like the `i' command from the calendar.
  8870. All the standard commands work: block, weekly etc.
  8871. When `org-agenda-diary-file' points to a file,
  8872. `org-agenda-diary-entry-in-org-file' is called instead to create
  8873. entries in that Org-mode file."
  8874. (interactive)
  8875. (if (not (eq org-agenda-diary-file 'diary-file))
  8876. (org-agenda-diary-entry-in-org-file)
  8877. (require 'diary-lib)
  8878. (let* ((char (progn
  8879. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8880. (read-char-exclusive)))
  8881. (cmd (cdr (assoc char
  8882. '((?d . insert-diary-entry)
  8883. (?w . insert-weekly-diary-entry)
  8884. (?m . insert-monthly-diary-entry)
  8885. (?y . insert-yearly-diary-entry)
  8886. (?a . insert-anniversary-diary-entry)
  8887. (?b . insert-block-diary-entry)
  8888. (?c . insert-cyclic-diary-entry)))))
  8889. (oldf (symbol-function 'calendar-cursor-to-date))
  8890. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8891. (point (point))
  8892. (mark (or (mark t) (point))))
  8893. (unless cmd
  8894. (user-error "No command associated with <%c>" char))
  8895. (unless (and (get-text-property point 'day)
  8896. (or (not (equal ?b char))
  8897. (get-text-property mark 'day)))
  8898. (user-error "Don't know which date to use for diary entry"))
  8899. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8900. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8901. (let ((calendar-mark-ring
  8902. (list (calendar-gregorian-from-absolute
  8903. (or (get-text-property mark 'day)
  8904. (get-text-property point 'day))))))
  8905. (unwind-protect
  8906. (progn
  8907. (fset 'calendar-cursor-to-date
  8908. (lambda (&optional error dummy)
  8909. (calendar-gregorian-from-absolute
  8910. (get-text-property point 'day))))
  8911. (call-interactively cmd))
  8912. (fset 'calendar-cursor-to-date oldf))))))
  8913. (defun org-agenda-execute-calendar-command (cmd)
  8914. "Execute a calendar command from the agenda with date from cursor."
  8915. (org-agenda-check-type t 'agenda 'timeline)
  8916. (require 'diary-lib)
  8917. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8918. (user-error "Don't know which date to use for the calendar command"))
  8919. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8920. (point (point))
  8921. (date (calendar-gregorian-from-absolute
  8922. (get-text-property point 'day)))
  8923. ;; the following 2 vars are needed in the calendar
  8924. (displayed-month (car date))
  8925. (displayed-year (nth 2 date)))
  8926. (unwind-protect
  8927. (progn
  8928. (fset 'calendar-cursor-to-date
  8929. (lambda (&optional error dummy)
  8930. (calendar-gregorian-from-absolute
  8931. (get-text-property point 'day))))
  8932. (call-interactively cmd))
  8933. (fset 'calendar-cursor-to-date oldf))))
  8934. (defun org-agenda-phases-of-moon ()
  8935. "Display the phases of the moon for the 3 months around the cursor date."
  8936. (interactive)
  8937. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8938. (defun org-agenda-holidays ()
  8939. "Display the holidays for the 3 months around the cursor date."
  8940. (interactive)
  8941. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8942. (defvar calendar-longitude) ; defined in calendar.el
  8943. (defvar calendar-latitude) ; defined in calendar.el
  8944. (defvar calendar-location-name) ; defined in calendar.el
  8945. (defun org-agenda-sunrise-sunset (arg)
  8946. "Display sunrise and sunset for the cursor date.
  8947. Latitude and longitude can be specified with the variables
  8948. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8949. argument, latitude and longitude will be prompted for."
  8950. (interactive "P")
  8951. (require 'solar)
  8952. (let ((calendar-longitude (if arg nil calendar-longitude))
  8953. (calendar-latitude (if arg nil calendar-latitude))
  8954. (calendar-location-name
  8955. (if arg "the given coordinates" calendar-location-name)))
  8956. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8957. (defun org-agenda-goto-calendar ()
  8958. "Open the Emacs calendar with the date at the cursor."
  8959. (interactive)
  8960. (org-agenda-check-type t 'agenda 'timeline)
  8961. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8962. (user-error "Don't know which date to open in calendar")))
  8963. (date (calendar-gregorian-from-absolute day))
  8964. (calendar-move-hook nil)
  8965. (calendar-view-holidays-initially-flag nil)
  8966. (calendar-view-diary-initially-flag nil))
  8967. (calendar)
  8968. (calendar-goto-date date)))
  8969. ;;;###autoload
  8970. (defun org-calendar-goto-agenda ()
  8971. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8972. This is a command that has to be installed in `calendar-mode-map'."
  8973. (interactive)
  8974. (org-agenda-list nil (calendar-absolute-from-gregorian
  8975. (calendar-cursor-to-date))
  8976. nil))
  8977. (defun org-agenda-convert-date ()
  8978. (interactive)
  8979. (org-agenda-check-type t 'agenda 'timeline)
  8980. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8981. date s)
  8982. (unless day
  8983. (user-error "Don't know which date to convert"))
  8984. (setq date (calendar-gregorian-from-absolute day))
  8985. (setq s (concat
  8986. "Gregorian: " (calendar-date-string date) "\n"
  8987. "ISO: " (calendar-iso-date-string date) "\n"
  8988. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8989. "Julian: " (calendar-julian-date-string date) "\n"
  8990. "Astron. JD: " (calendar-astro-date-string date)
  8991. " (Julian date number at noon UTC)\n"
  8992. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8993. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8994. "French: " (calendar-french-date-string date) "\n"
  8995. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8996. "Mayan: " (calendar-mayan-date-string date) "\n"
  8997. "Coptic: " (calendar-coptic-date-string date) "\n"
  8998. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8999. "Persian: " (calendar-persian-date-string date) "\n"
  9000. "Chinese: " (calendar-chinese-date-string date) "\n"))
  9001. (with-output-to-temp-buffer "*Dates*"
  9002. (princ s))
  9003. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  9004. ;;; Bulk commands
  9005. (defun org-agenda-bulk-marked-p ()
  9006. (eq (get-char-property (point-at-bol) 'type)
  9007. 'org-marked-entry-overlay))
  9008. (defun org-agenda-bulk-mark (&optional arg)
  9009. "Mark the entry at point for future bulk action."
  9010. (interactive "p")
  9011. (dotimes (i (or arg 1))
  9012. (unless (org-get-at-bol 'org-agenda-diary-link)
  9013. (let* ((m (org-get-at-bol 'org-hd-marker))
  9014. ov)
  9015. (unless (org-agenda-bulk-marked-p)
  9016. (unless m (user-error "Nothing to mark at point"))
  9017. (push m org-agenda-bulk-marked-entries)
  9018. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  9019. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  9020. (org-get-todo-face "TODO")
  9021. 'evaporate)
  9022. (overlay-put ov 'type 'org-marked-entry-overlay))
  9023. (end-of-line 1)
  9024. (or (ignore-errors
  9025. (goto-char (next-single-property-change (point) 'txt)))
  9026. (beginning-of-line 2))
  9027. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9028. (beginning-of-line 2))
  9029. (message "%d entries marked for bulk action"
  9030. (length org-agenda-bulk-marked-entries))))))
  9031. (defun org-agenda-bulk-mark-all ()
  9032. "Mark all entries for future agenda bulk action."
  9033. (interactive)
  9034. (org-agenda-bulk-mark-regexp "."))
  9035. (defun org-agenda-bulk-mark-regexp (regexp)
  9036. "Mark entries matching REGEXP for future agenda bulk action."
  9037. (interactive "sMark entries matching regexp: ")
  9038. (let ((entries-marked 0) txt-at-point)
  9039. (save-excursion
  9040. (goto-char (point-min))
  9041. (goto-char (next-single-property-change (point) 'txt))
  9042. (while (and (re-search-forward regexp nil t)
  9043. (setq txt-at-point (get-text-property (point) 'txt)))
  9044. (when (string-match regexp txt-at-point)
  9045. (setq entries-marked (1+ entries-marked))
  9046. (call-interactively 'org-agenda-bulk-mark))))
  9047. (if (not entries-marked)
  9048. (message "No entry matching this regexp."))))
  9049. (defun org-agenda-bulk-unmark (&optional arg)
  9050. "Unmark the entry at point for future bulk action."
  9051. (interactive "P")
  9052. (if arg
  9053. (org-agenda-bulk-unmark-all)
  9054. (cond ((org-agenda-bulk-marked-p)
  9055. (org-agenda-bulk-remove-overlays
  9056. (point-at-bol) (+ 2 (point-at-bol)))
  9057. (setq org-agenda-bulk-marked-entries
  9058. (delete (org-get-at-bol 'org-hd-marker)
  9059. org-agenda-bulk-marked-entries))
  9060. (end-of-line 1)
  9061. (or (ignore-errors
  9062. (goto-char (next-single-property-change (point) 'txt)))
  9063. (beginning-of-line 2))
  9064. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9065. (beginning-of-line 2))
  9066. (message "%d entries left marked for bulk action"
  9067. (length org-agenda-bulk-marked-entries)))
  9068. (t (message "No entry to unmark here")))))
  9069. (defun org-agenda-bulk-toggle-all ()
  9070. "Toggle all marks for bulk action."
  9071. (interactive)
  9072. (save-excursion
  9073. (goto-char (point-min))
  9074. (while (ignore-errors
  9075. (goto-char (next-single-property-change (point) 'txt)))
  9076. (org-agenda-bulk-toggle))))
  9077. (defun org-agenda-bulk-toggle ()
  9078. "Toggle the mark at point for bulk action."
  9079. (interactive)
  9080. (if (org-agenda-bulk-marked-p)
  9081. (org-agenda-bulk-unmark)
  9082. (org-agenda-bulk-mark)))
  9083. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9084. "Remove the mark overlays between BEG and END in the agenda buffer.
  9085. BEG and END default to the buffer limits.
  9086. This only removes the overlays, it does not remove the markers
  9087. from the list in `org-agenda-bulk-marked-entries'."
  9088. (interactive)
  9089. (mapc (lambda (ov)
  9090. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9091. (delete-overlay ov)))
  9092. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9093. (defun org-agenda-bulk-unmark-all ()
  9094. "Remove all marks in the agenda buffer.
  9095. This will remove the markers and the overlays."
  9096. (interactive)
  9097. (if (null org-agenda-bulk-marked-entries)
  9098. (message "No entry to unmark")
  9099. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9100. (setq org-agenda-bulk-marked-entries nil)
  9101. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9102. (defcustom org-agenda-persistent-marks nil
  9103. "Non-nil means marked items will stay marked after a bulk action.
  9104. You can toggle this interactively by typing `p' when prompted for a
  9105. bulk action."
  9106. :group 'org-agenda
  9107. :version "24.1"
  9108. :type 'boolean)
  9109. (defun org-agenda-bulk-action (&optional arg)
  9110. "Execute an remote-editing action on all marked entries.
  9111. The prefix arg is passed through to the command if possible."
  9112. (interactive "P")
  9113. ;; Make sure we have markers, and only valid ones
  9114. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9115. (mapc
  9116. (lambda (m)
  9117. (unless (and (markerp m)
  9118. (marker-buffer m)
  9119. (buffer-live-p (marker-buffer m))
  9120. (marker-position m))
  9121. (user-error "Marker %s for bulk command is invalid" m)))
  9122. org-agenda-bulk-marked-entries)
  9123. ;; Prompt for the bulk command
  9124. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9125. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9126. "[S]catter [f]unction "
  9127. (when org-agenda-bulk-custom-functions
  9128. (concat " Custom: ["
  9129. (mapconcat (lambda(f) (char-to-string (car f)))
  9130. org-agenda-bulk-custom-functions "")
  9131. "]"))))
  9132. (catch 'exit
  9133. (let* ((action (read-char-exclusive))
  9134. (org-log-refile (if org-log-refile 'time nil))
  9135. (entries (reverse org-agenda-bulk-marked-entries))
  9136. (org-overriding-default-time
  9137. (if (get-text-property (point) 'org-agenda-date-header)
  9138. (org-get-cursor-date)))
  9139. redo-at-end
  9140. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9141. (cond
  9142. ((equal action ?p)
  9143. (let ((org-agenda-persistent-marks
  9144. (not org-agenda-persistent-marks)))
  9145. (org-agenda-bulk-action)
  9146. (throw 'exit nil)))
  9147. ((equal action ?$)
  9148. (setq cmd '(org-agenda-archive)))
  9149. ((equal action ?A)
  9150. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9151. ((member action '(?r ?w))
  9152. (setq rfloc (org-refile-get-location
  9153. "Refile to"
  9154. (marker-buffer (car entries))
  9155. org-refile-allow-creating-parent-nodes))
  9156. (if (nth 3 rfloc)
  9157. (setcar (nthcdr 3 rfloc)
  9158. (move-marker (make-marker) (nth 3 rfloc)
  9159. (or (get-file-buffer (nth 1 rfloc))
  9160. (find-buffer-visiting (nth 1 rfloc))
  9161. (error "This should not happen")))))
  9162. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9163. redo-at-end t))
  9164. ((equal action ?t)
  9165. (setq state (org-icompleting-read
  9166. "Todo state: "
  9167. (with-current-buffer (marker-buffer (car entries))
  9168. (mapcar 'list org-todo-keywords-1))))
  9169. (setq cmd `(let ((org-inhibit-blocking t)
  9170. (org-inhibit-logging 'note))
  9171. (org-agenda-todo ,state))))
  9172. ((memq action '(?- ?+))
  9173. (setq tag (org-icompleting-read
  9174. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9175. (with-current-buffer (marker-buffer (car entries))
  9176. (delq nil
  9177. (mapcar (lambda (x)
  9178. (if (stringp (car x)) x)) org-tag-alist)))))
  9179. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9180. ((memq action '(?s ?d))
  9181. (let* ((time
  9182. (unless arg
  9183. (org-read-date
  9184. nil nil nil
  9185. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9186. org-overriding-default-time)))
  9187. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9188. (setq cmd `(eval '(,c1 arg ,time)))))
  9189. ((equal action ?S)
  9190. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9191. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9192. (let ((days (read-number
  9193. (format "Scatter tasks across how many %sdays: "
  9194. (if arg "week" "")) 7)))
  9195. (setq cmd
  9196. `(let ((distance (1+ (random ,days))))
  9197. (if arg
  9198. (let ((dist distance)
  9199. (day-of-week
  9200. (calendar-day-of-week
  9201. (calendar-gregorian-from-absolute (org-today)))))
  9202. (dotimes (i (1+ dist))
  9203. (while (member day-of-week org-agenda-weekend-days)
  9204. (incf distance)
  9205. (incf day-of-week)
  9206. (if (= day-of-week 7)
  9207. (setq day-of-week 0)))
  9208. (incf day-of-week)
  9209. (if (= day-of-week 7)
  9210. (setq day-of-week 0)))))
  9211. ;; silently fail when try to replan a sexp entry
  9212. (condition-case nil
  9213. (let* ((date (calendar-gregorian-from-absolute
  9214. (+ (org-today) distance)))
  9215. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9216. (nth 2 date))))
  9217. (org-agenda-schedule nil time))
  9218. (error nil)))))))
  9219. ((assoc action org-agenda-bulk-custom-functions)
  9220. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9221. redo-at-end t))
  9222. ((equal action ?f)
  9223. (setq cmd (list (intern
  9224. (org-icompleting-read "Function: "
  9225. obarray 'fboundp t nil nil)))))
  9226. (t (user-error "Invalid bulk action")))
  9227. ;; Sort the markers, to make sure that parents are handled before children
  9228. (setq entries (sort entries
  9229. (lambda (a b)
  9230. (cond
  9231. ((equal (marker-buffer a) (marker-buffer b))
  9232. (< (marker-position a) (marker-position b)))
  9233. (t
  9234. (string< (buffer-name (marker-buffer a))
  9235. (buffer-name (marker-buffer b))))))))
  9236. ;; Now loop over all markers and apply cmd
  9237. (while (setq e (pop entries))
  9238. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9239. (if (not pos)
  9240. (progn (message "Skipping removed entry at %s" e)
  9241. (setq cntskip (1+ cntskip)))
  9242. (goto-char pos)
  9243. (let (org-loop-over-headlines-in-active-region)
  9244. (eval cmd))
  9245. (setq cnt (1+ cnt))))
  9246. (when redo-at-end (org-agenda-redo))
  9247. (unless org-agenda-persistent-marks
  9248. (org-agenda-bulk-unmark-all))
  9249. (message "Acted on %d entries%s%s"
  9250. cnt
  9251. (if (= cntskip 0)
  9252. ""
  9253. (format ", skipped %d (disappeared before their turn)"
  9254. cntskip))
  9255. (if (not org-agenda-persistent-marks)
  9256. "" " (kept marked)"))))))
  9257. (defun org-agenda-capture (&optional with-time)
  9258. "Call `org-capture' with the date at point.
  9259. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9260. current HH:MM time."
  9261. (interactive "P")
  9262. (if (not (eq major-mode 'org-agenda-mode))
  9263. (user-error "You cannot do this outside of agenda buffers")
  9264. (let ((org-overriding-default-time
  9265. (org-get-cursor-date (equal with-time 1))))
  9266. (call-interactively 'org-capture))))
  9267. ;;; Dragging agenda lines forward/backward
  9268. (defun org-agenda-reapply-filters ()
  9269. "Re-apply all agenda filters."
  9270. (mapcar
  9271. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f))))
  9272. `((,org-agenda-tag-filter tag)
  9273. (,org-agenda-category-filter category)
  9274. (,org-agenda-regexp-filter regexp)
  9275. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9276. (,(get 'org-agenda-category-filter :preset-filter) category)
  9277. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9278. (defun org-agenda-drag-line-forward (arg &optional backward)
  9279. "Drag an agenda line forward by ARG lines.
  9280. When the optional argument `backward' is non-nil, move backward."
  9281. (interactive "p")
  9282. (let ((inhibit-read-only t) lst line)
  9283. (if (or (not (get-text-property (point) 'txt))
  9284. (save-excursion
  9285. (dotimes (n arg)
  9286. (move-beginning-of-line (if backward 0 2))
  9287. (push (not (get-text-property (point) 'txt)) lst))
  9288. (delq nil lst)))
  9289. (message "Cannot move line forward")
  9290. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9291. (move-beginning-of-line 1)
  9292. (setq line (buffer-substring (point) end))
  9293. (delete-region (point) end)
  9294. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9295. (insert line)
  9296. (org-agenda-reapply-filters)
  9297. (org-agenda-mark-clocking-task)
  9298. (move-beginning-of-line 0)))))
  9299. (defun org-agenda-drag-line-backward (arg)
  9300. "Drag an agenda line backward by ARG lines."
  9301. (interactive "p")
  9302. (org-agenda-drag-line-forward arg t))
  9303. ;;; Flagging notes
  9304. (defun org-agenda-show-the-flagging-note ()
  9305. "Display the flagging note in the other window.
  9306. When called a second time in direct sequence, offer to remove the FLAGGING
  9307. tag and (if present) the flagging note."
  9308. (interactive)
  9309. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9310. (win (selected-window))
  9311. note heading newhead)
  9312. (unless hdmarker
  9313. (user-error "No linked entry at point"))
  9314. (if (and (eq this-command last-command)
  9315. (y-or-n-p "Unflag and remove any flagging note? "))
  9316. (progn
  9317. (org-agenda-remove-flag hdmarker)
  9318. (let ((win (get-buffer-window "*Flagging Note*")))
  9319. (and win (delete-window win)))
  9320. (message "Entry unflagged"))
  9321. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9322. (unless note
  9323. (user-error "No flagging note"))
  9324. (org-kill-new note)
  9325. (org-switch-to-buffer-other-window "*Flagging Note*")
  9326. (erase-buffer)
  9327. (insert note)
  9328. (goto-char (point-min))
  9329. (while (re-search-forward "\\\\n" nil t)
  9330. (replace-match "\n" t t))
  9331. (goto-char (point-min))
  9332. (select-window win)
  9333. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9334. (defun org-agenda-remove-flag (marker)
  9335. "Remove the FLAGGED tag and any flagging note in the entry."
  9336. (let (newhead)
  9337. (org-with-point-at marker
  9338. (org-toggle-tag "FLAGGED" 'off)
  9339. (org-entry-delete nil "THEFLAGGINGNOTE")
  9340. (setq newhead (org-get-heading)))
  9341. (org-agenda-change-all-lines newhead marker)
  9342. (message "Entry unflagged")))
  9343. (defun org-agenda-get-any-marker (&optional pos)
  9344. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9345. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9346. ;;; Appointment reminders
  9347. (defvar appt-time-msg-list) ; defined in appt.el
  9348. ;;;###autoload
  9349. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9350. "Activate appointments found in `org-agenda-files'.
  9351. With a \\[universal-argument] prefix, refresh the list of
  9352. appointments.
  9353. If FILTER is t, interactively prompt the user for a regular
  9354. expression, and filter out entries that don't match it.
  9355. If FILTER is a string, use this string as a regular expression
  9356. for filtering entries out.
  9357. If FILTER is a function, filter out entries against which
  9358. calling the function returns nil. This function takes one
  9359. argument: an entry from `org-agenda-get-day-entries'.
  9360. FILTER can also be an alist with the car of each cell being
  9361. either 'headline or 'category. For example:
  9362. '((headline \"IMPORTANT\")
  9363. (category \"Work\"))
  9364. will only add headlines containing IMPORTANT or headlines
  9365. belonging to the \"Work\" category.
  9366. ARGS are symbols indicating what kind of entries to consider.
  9367. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9368. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9369. and :timestamp entries. See the docstring of `org-diary' for
  9370. details and examples.
  9371. If an entry has a APPT_WARNTIME property, its value will be used
  9372. to override `appt-message-warning-time'."
  9373. (interactive "P")
  9374. (if refresh (setq appt-time-msg-list nil))
  9375. (if (eq filter t)
  9376. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9377. (let* ((cnt 0) ; count added events
  9378. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9379. (org-agenda-new-buffers nil)
  9380. (org-deadline-warning-days 0)
  9381. ;; Do not use `org-today' here because appt only takes
  9382. ;; time and without date as argument, so it may pass wrong
  9383. ;; information otherwise
  9384. (today (org-date-to-gregorian
  9385. (time-to-days (current-time))))
  9386. (org-agenda-restrict nil)
  9387. (files (org-agenda-files 'unrestricted)) entries file
  9388. (org-agenda-buffer nil))
  9389. ;; Get all entries which may contain an appt
  9390. (org-agenda-prepare-buffers files)
  9391. (while (setq file (pop files))
  9392. (setq entries
  9393. (delq nil
  9394. (append entries
  9395. (apply 'org-agenda-get-day-entries
  9396. file today scope)))))
  9397. ;; Map thru entries and find if we should filter them out
  9398. (mapc
  9399. (lambda(x)
  9400. (let* ((evt (org-trim
  9401. (replace-regexp-in-string
  9402. org-bracket-link-regexp "\\3"
  9403. (or (get-text-property 1 'txt x) ""))))
  9404. (cat (get-text-property 1 'org-category x))
  9405. (tod (get-text-property 1 'time-of-day x))
  9406. (ok (or (null filter)
  9407. (and (stringp filter) (string-match filter evt))
  9408. (and (functionp filter) (funcall filter x))
  9409. (and (listp filter)
  9410. (let ((cat-filter (cadr (assoc 'category filter)))
  9411. (evt-filter (cadr (assoc 'headline filter))))
  9412. (or (and (stringp cat-filter)
  9413. (string-match cat-filter cat))
  9414. (and (stringp evt-filter)
  9415. (string-match evt-filter evt)))))))
  9416. (wrn (get-text-property 1 'warntime x)))
  9417. ;; FIXME: Shall we remove text-properties for the appt text?
  9418. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9419. (when (and ok tod)
  9420. (setq tod (concat "00" (number-to-string tod))
  9421. tod (when (string-match
  9422. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9423. (concat (match-string 1 tod) ":"
  9424. (match-string 2 tod))))
  9425. (if (version< emacs-version "23.3")
  9426. (appt-add tod evt)
  9427. (appt-add tod evt wrn))
  9428. (setq cnt (1+ cnt))))) entries)
  9429. (org-release-buffers org-agenda-new-buffers)
  9430. (if (eq cnt 0)
  9431. (message "No event to add")
  9432. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9433. (defun org-agenda-todayp (date)
  9434. "Does DATE mean today, when considering `org-extend-today-until'?"
  9435. (let ((today (org-today))
  9436. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9437. date)))
  9438. (eq date today)))
  9439. (defun org-agenda-todo-yesterday (&optional arg)
  9440. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9441. (interactive "P")
  9442. (let* ((hour (third (decode-time
  9443. (org-current-time))))
  9444. (org-extend-today-until (1+ hour)))
  9445. (org-agenda-todo arg)))
  9446. (provide 'org-agenda)
  9447. ;;; org-agenda.el ends here